Cocoa in a Nutshell: A Desktop Quick Reference (In a Nutshell (O'Reilly))
|
| List Price: | £34.50 |
| Price: | £29.33 & eligible for FREE Super Saver Delivery on orders over £5. Details |
Availability: Usually dispatched within 24 hours
Dispatched from and sold by Amazon.co.uk
Product Description
Cocoa is more than just a collection of classes, and is certainly more than a simple framework. Cocoa is a complete API set, class library, framework, and development environment for building applications and tools to run on Mac OSX. With over 240 classes, Cocoa is divided into two essential frameworks: Foundation and Application Kit. Above all else, Cocoa is a toolkit for creating Mac OS X application interfaces, and it provides access to all of the standard Aqua interface components such as menus, toolbars, windows, buttons, to name a few. The book begins with a complete overview of Cocoa's object classes. It provides developers who may be experienced with other application toolkits the grounding they'll need to start developing Cocoa applications. Common programming tasks are described, and many chapters focus on the larger patterns in the frameworks so developers can understand the larger relationships between the classes in Cocoa, which is essential to using the framework effectively. It is divided into two parts, with the first part providing a series of overview chapters that describe specific features of the Cocoa frameworks. Information found in Part I includes: an overview of the Objective-C language; coverage of the Foundation and Application Kit frameworks; overviews of Cocoa's drawing and text handling classes; network services such as hosts, Rendezvous URL services, sockets, and file handling; distributed notifications and distributed objects for interapplication communication; and extending Cocoa applications with other frameworks, including the Address Book, DiscRecording, and Messaging frameworks. The second half of the book is a detailed quick reference to Cocoa's Foundation and Application Kit (AppKit) classes. A complement to Apple's documentation, "Cocoa in a Nutshell" is the only reference to the classes, functions, types, constants, protocols, and methods that make up Cocoa's Foundation and Application Kit frameworks, based on the Jaguar release (Mac OS X 10.2).
Product Details
- Amazon Sales Rank: #157570 in Books
- Published on: 2003-05-19
- Original language: English
- Number of items: 1
- Binding: Paperback
- 566 pages
Editorial Reviews
About the Author
James Duncan Davidson is a freelance author, software developer, and consultant focusing on Mac OS X, Java, XML, and open source technologies. He is the author of Learning Cocoa with Objective-C (published by O'Reilly & Associates) and is a frequent contributor to the O'Reilly Network online website as well as publisher of his own website, x180 (http://www.x180.net), where he keeps his popular weblog. Duncan was the creator of Apache Tomcat and Apache Ant and was instrumental in their donation to the Apache Software Foundation by Sun Microsystems . While working at Sun, he authored two versions of the Java Servlet API specification as well as the Java API for XML Processing. Duncan regularly presents at conferences all over the world on topics ranging from open source and collaborative development to programming Java more effectively. He didn't graduate with a Computer Science degree, but sees that as a benefit in helping explain how software works. His educational background is in Architecture (the bricks and mortar kind), the essence of which he applies to every software problem that finds him. He currently resides in San Francisco, California.
Excerpted from Cocoa in a Nutshell by Michael Beam, James Duncan Davidson. Copyright © 2003. Reprinted by permission. All rights reserved.
Chapter 4 - Drawing and Imaging
The Application Kit has a diverse set of graphics classes. These classes range from NSQuickDrawView, which lets developers use legacy graphics code based on the QuickDraw APIs in their Cocoa application, to NSOpenGLView, which provides a way to display OpenGL-based 3D graphics. The focus of this chapter, however, is on the 2D drawing and imaging classes that provide a high-level interface to Mac OS X’s graphics system, Quartz. Table 4-1 enumerates the classes discussed in this chapter.
The Role of Quartz
Quartz is the foundation of Cocoa’s 2D graphics capabilities. It provides many advanced graphics capabilities, including color management, path-based drawing, transparency, and anti-aliasing. It uses the same fundamental model of drawing as Adobe’s Portable Document Format (PDF).
Quartz is actually two individual pieces of software in Mac OS X—Quartz Compositor and Quartz 2D. The Quartz Compositor is the underlying system service responsible for drawing the graphical user interface to screen from sources such as Quartz 2D, QuickTime, OpenGL, and QuickDraw. Quartz 2D, on the other hand, is an Application Programming Interface (API) for drawing and manipulating 2D graphics. This chapter concentrates on Quartz 2D’s drawing functionality.
You can access the Quartz 2D API directly through the CoreGraphics framework, but it is far more convenient to use the Cocoa classes that provide an easy-to-use interface to Quartz, including NSBezierPath, NSView, NSImage, and NSGraphicsContext. These classes provide the functionality to render paths, text, and images to screen or to the printed page.
Coordinate Systems
All drawing is performed within an instance of NSView. Each view defines its own coordinate system. By default, the origin (0, 0) is in the lower-left corner of the view with positive y-values extending up from, and positive x-values extending to the right of, the origin. Figure 4-1 illustrates this system. These coordinates are not tied to expressed in terms of points (a unit that is 1/72 of an inch). When Quartz renders graphics, it maps what is drawn in the device-independent coordinate system into the coordinate system of the device. One point is equivalent to one screen pixel.
As covered in Chapter 3, views are arranged in a nested hierarchy, with subviews contained within a superview. Two rectangles characterize a view. The size and position of a view within its superview is determined by its frame rectangle. The bounds rectangle defines the coordinate system within the view itself. By default, the origin of the bounds rectangle is at (0, 0), and it has the same height and width as the view’s frame rectangle. You can access a view’s frame using the methods frame and setFrame:, and access the bounds rectangle with bounds and setBounds:. Figure 4-2 shows how the frame and bounds rectangles are related. Resizing the bounds rectangle independently of the frame rectangle lets developers define coordinate systems that are natural for their application, instead of being forced to work in screen coordinates. Additionally, coordinate systems within a view may be translated and rotated independent of other coordinate systems.
Graphics Contexts
A graphics context is a low-level component of the drawing system representing a destination for drawing commands that will be executed and rendered. Instances of the NSGraphicsContext class represent these contexts. The graphics context also provides an interface to manage graphics states and configure a number of rendering options, such as anti-aliasing, image interpolation, and various settings for drawing paths such as line width and join styles.
At any time in the execution of an application, a current context defines the graphics context for all graphics operations. You can obtain this object using the class method currentContext. Multiple graphics contexts are stored on a stack, so that different parts of an application may configure a context specific to their needs. To push a new context onto the stack, use the method saveGraphicsState.
Contexts lower in the stack are restored by invoking restoreGraphicsState, which pulls the current context off the stack, making the next lower one current. You can use a graphics context to determine whether or not the screen is the current drawing destination. This is useful if you have to handle onscreen and offscreen drawing differently (e.g., to a printer). The isDrawingToScreen method returns YES if drawing is done onscreen, and NO otherwise. The convenience class method currentContextDrawingToScreen does the same thing, saving you the step of first invoking currentContext.




