Strategies

The QuickDraw to Quartz imaging models are different enough that rewriting your application so that is uses only Quartz is not trivial. Your hard work will be worthwhile. Making the transition opens a world of possibilities for tasks that you can perform with Quartz but could not dream of accomplishing with QuickDraw. Just as QuickDraw was revolutionary in its time, Quartz is today. In Mac OS X v10.4, Quartz introduces a wealth of new features that makes the switchover even more compelling. Quartz has many more convenience functions, improved performance, and a lot of new documentation. What’s more, Quartz is fully integrated with other Mac OS X v10.4 technologies, such as Core Image, which makes image processing a snap. There is no better time than now to roll up your sleeves and get to work removing that old QuickDraw code!

This chapter provides overall strategies for revising your code to use only Quartz, while the remaining chapters in the book show how to accomplish specific tasks using Quartz. Where appropriate, the strategies in this chapter cross-reference specific tasks so you can get ideas (and perhaps some code) for how to modify your own application.

Before You Start

Make sure you are using a development environment that supports Quartz, such as Xcode.

Gather up the latest Quartz documentation so that it is readily accessible to you.

Locate the Carbon Sketch application and familiarize yourself with the code and what the application does. By looking at the code, you can get ideas on how to rearchitect your application to use only Quartz for drawing. You can find Carbon Sketch on the ADC Reference Library site:

http://developer.apple.com/samplecode/GraphicsImaging/idxQuartz-title.html#doclist

The application performs many tasks needed in a drawing application. For example, it:

Analyze Your Code

Analyze your QuickDraw code so that you can understand what needs to change. Then develop a plan before you start reworking your code. Keep in mind that many things have changed in Mac OS X, and especially in Mac OS X v10.4. Technologies other than QuickDraw are deprecated in Mac OS X v10.4, including QuickDraw Text, Display Manager, and Draw Sprockets.

If, after analyzing your code, you plan to stick with the C APIs in the Carbon framework, you may want to use HIView along with Quartz. The HIToolbox offers many technologies that are complementary to Quartz (such as HIShape) and that will ensure that your application is updated for the 21st century.

If you decide to completely rewrite your application in all respects, you might want to think about moving to Cocoa. You can use the Quartz API in any framework outside of the kernel. When you use Cocoa, you can call Quartz directly and you can also use Cocoa drawing methods, which are built on top of Quartz.

As you analyze your code, take a careful look at how you use QuickDraw. Sometimes you’ll find that Quartz provides functional equivalents for your QuickDraw code, but more often than not you’ll need to think differently. Your application will benefit most if you can think beyond QuickDraw. That is, don’t just look for ways to accomplish the same task in Quartz. Take some time to think about how your application currently works and how you might be able to leverage the new capabilities that Mac OS X provides to improve the user experience of your application, not just maintain parity with your QuickDraw version.

General Strategies

The following strategies are useful for revising QuickDraw applications to use Quartz:

  1. Think differently, especially for those items that don’t have equivalent functionality in Quartz—such as arithmetic transfer modes, SeedCFill, SearchProcs—but that you still need to find a substitute for.

  2. Focus on functionality, not functions. The approach of translating QuickDraw idioms into Quartz won’t work in most cases, especially for calls to CopyBits and the regions functions.

  3. Analyze your use of regions to see what functionality each use provides. Then revise the code accordingly. You may have used regions for a variety of purposes; you’ll find alternative strategies throughout this guide. See Regions Replacement Strategies.

  4. Analyze your CopyBits calls to see what functionality each call provides. Then revise the code accordingly. You probably used CopyBits and related functions to achieve a number of tasks in QuickDraw; you’ll find alternative strategies throughout this guide. See CopyBits Replacement Strategies.

  5. Account for differences between the QuickDraw and Quartz coordinate systems. If you use HIView along with Quartz, make sure you are familiar with how HIView handles coordinates. See Coordinate Space.

  6. Use alpha. It’s fully supported in Quartz. See The Alpha Value in Quartz 2D Programming Guide.

  7. Convert PICT data to PDF and provide conversion support in your application to handle legacy PICT files that your users may need to open. See Converting PICT Data.

  8. Support PDF data for Copy and Paste actions. Only PDF content fully captures Quartz drawing, and you’ll want to ensure fidelity of content. See Converting PICT Data.

  9. Save and restore graphics states appropriately. See Graphics State and Global Effects.

  10. Revise your hit testing code. See Hit Testing.

  11. Think device independence and resolution independence. See Drawing Destinations.

  12. Identify the shortcomings of your QuickDraw application to see where you can use new features of Quartz to improve your application.

  13. Remove code that compensates for QuickDraw shortcomings. For example, XOR drawing isn’t needed by most applications that use Quartz. The GrafProcs bottleneck tricks simply don’t apply in Quartz.

  14. Optimize your code to ensure that your application performs at its best. See Performance.

Regions Replacement Strategies

Regions served many purposes in QuickDraw. You’ll want to analyze your code to see what purpose each use of regions serves.

If you use QuickDraw regions for:

If you want to:

CopyBits Replacement Strategies

Many years of development and optimization made the QuickDraw function CopyBits an exceptionally fast, general-purpose blitter. QuickDraw is based on bitmap graphics, and CopyBits makes perfect sense in that environment. The Quartz imaging model does not provide for pixel drawing operations or bit copying functionality. The fact that Quartz is not based on bits gives rise to its many cool features, including its ability to maintain device and resolution independence. Quartz does have the capability for you to draw bits, should you need to do so, but most of the time you’ll want to adopt strategies for replacing CopyBits, CopyMask, and CopyDeepMask—strategies that leverage Quartz rather than seek parity with QuickDraw.

The functions CopyBits, CopyMask, and CopyDeepMask were used to achieve so many results in QuickDraw that you’ll want to read all the replacement strategies before you decide which course of action to take. If you use the QuickDraw functions CopyBits, CopyMask, or CopyDeepMask for: