Re: Summary of drawing routines?
Re: Summary of drawing routines?
- Subject: Re: Summary of drawing routines?
- From: "Dennis C. De Mars" <email@hidden>
- Date: Thu, 7 Jun 2001 19:59:34 -0000
Clyde McQueen <email@hidden> said:
>
I keep looking in the online docs for a summary of all the methods used
>
to draw (text, images, etc.). Am I missing something?
I know what you mean. When I was first looking into this last year, I kept looking for
a top level explanation of drawing, and didn't find one. It turns out all of the
classes you need to draw just about everything is documented, but there isn't a top
level summary pulling all of that together.
There _will_ be. If you look at the bottom of Apple's Cocoa documentation web page,
there are a set of links to an organized presentation of drawing in Cocoa.
Unfortunately, the links don't point to anything yet! At some point, obviously, they
will be filled in. In the meantime, they at least have links to the docs for the
classes you'll need to use.
Other helpful sources would include:
The Stepwise site <
http://www.stepwise.com> recently posted an article with links to
all of the relevant classes. Look for the title with the phrase "Mining for Quartz".
The new book "Learning Cocoa" has an appendix that covers drawing.
Also, here's a real quick outline of what you would need to read in the online docs to
get most of what you need to know.
First of all, read the documentation for NSView. Basically all drawing is done in an
NSView object or an NSView subclass, and you need to be fairly familiar with it.
After you read that, you know all about the canvas you will draw on, so you just need
to know how to actually do the drawing.
In Cocoa, you don't call procedures to draw a line or a string or whatever. You create
objects that represent these graphical objects and tell them to draw themselves (you
can do things procedurally through the "Quartz 2D interface" but that's a more advanced
topic, and most people won't need to use that.
So here are the main classes you would use:
For any geometric drawing: (lines, rectangles, ovals, arbitrary curved paths, filled or
not) use NSBezierPath
For any bitmap image, use NSImage and its subclasses (actually drawing is done by the
subclasses of NSImageRep, which is attached to an NSImage, but read NSImage for
details).
For any text: NSText can be used. For simple text used as tables or whatnot, you
actually don't need to use this, you can use the string classes NSString or
NSAttributedString. These have methods to draw themselves in an NSView.
If you read the docs for those classes in that order, I think you will then realize you
can draw pretty much anything you need, as far as 2D drawing goes. There are several
other classes used for specialized purposes: for 3D drawing there is a view for using
OpenGL, for using Quartz2D rendering directly I think there is a view for that, there's
another for drawing directly to the screen (for games that want to take over the
screen) etc. But for garden variety drawing into a document window I think the classes
mentioned above are all you need.
- Dennis D.