Draw with Quartz Primitives

In general, you should be able to use the classes and functions in Cocoa for your application’s drawing needs. If you find there is some functionality that you require that isn’t provided by Cocoa, you can use the Core Graphics APIs directly. For the most part, the Cocoa drawing functions and objects have very little overhead compared with the overhead of the actual screen drawing operations. If, as a result of performance measurements, you find that the overhead is significant, this may also be reason to use the Core Graphics APIs.

Note that the Cocoa functions and objects will interact with the Cocoa display machinery more smoothly than with the Core Graphics calls. For instance, changing the current transformation matrix using Core Graphics may cause Cocoa objects in that context to be rendered incorrectly (rotated text, for instance, when drawn by the text subsystem). If you change the current transformation matrix using NSView, everything will work as expected.

This section shows you how to modify the Simple Draw application from the previous sections to use Core Graphics drawing primitives in an NSView. The new version of the program will draw a multicolored spiral pattern in the upper-righthand corner of MyView.

  1. In Project Builder, open the Simple Draw project if it is not already open.

  2. Select the Add Frameworks command in the Project menu and add the Core Services framework to the Simple Draw project. The Core Services framework is an umbrella ...

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.