Appendix A. Drawing in Cocoa

Cocoa’s Application Kit provides you with a wide array of ready-made user interface objects. However, most complex applications will require at least a few custom interface elements. In addition, many applications need to perform custom drawing in order to display data. This appendix explains the basics of Cocoa’s imaging model and shows you how to create custom graphics.

In order to use the drawing facilities of Cocoa to their maximum potential, it is important to learn about Quartz, the imaging model underlying all graphics in Mac OS X. Quartz is based on Adobe’s Portable Document Format (PDF), which is in turn based on the Adobe PostScript imaging model. A complete description of Quartz, PostScript, and PDF is beyond the scope of this appendix. Look to the many excellent third-party books that are available, such as the PostScript Language Reference from Adobe (known as the “Red Book”) and the PDF 1.3 specification (http://www.pdfzone.com/resources/pdfspec13.html).

Coordinate Systems

The screen coordinate system is the basis for all other coordinate systems used for positioning, sizing, drawing, and event handling. You can think of the entire screen as occupying the upper-right quadrant of a two-dimensional coordinate grid as shown in Figure 1.1. The other three quadrants, which are invisible to users, take negative values along their x-axis, their y-axis, or both axes. The screen’s quadrant has its origin in the lower-left corner; the positive ...

Get Learning Cocoa now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.