SUNY Geneseo, Department of Computer Science
QuickDraw is the two-dimensional graphics library on Macintosh computers. This document introduces some of the basic features of QuickDraw. These features are enough to draw basic pictures, but there's a lot of QuickDraw I don't discuss. For the full truth, see Apple Computer's Inside Macintosh series, particularly the volume entitled Imaging with QuickDraw. (The whole Inside Macintosh series is available on the World-Wide Web, the anchors above lead to the introductory page for the series, and the introductory page for Imaging with QuickDraw.)
QuickDraw consists of a collection of functions (for drawing things) and data types (for describing the things you want to draw). Any good Macintosh compiler will have declarations of these functions and types built in to it, so that you can use them in your programs without needing to write your own declarations for them, include special header files, etc. In the following, I introduce key types and functions through C++ declarations -- such declarations are a concise way to give you the information you need to use the functions and types, but they are not things that you will type directly into your own code. Note that many of the data types are described in C++ as "structs". Recall that a "struct" is basically an object with no messages, whose data members are all public for you to access as you wish.
To draw anything, you need to say where in your window you want it to appear. QuickDraw describes positions in windows as points in a two-dimensional coordinate system. All coordinates are measured in pixels (a pixel being a single dot on your display). The first dimension specifies horizontal positions, starting at 0 at the left side of the window and increasing as you move right. The second dimension specifies vertical position, starting at 0 at the top of the window and increasing as you move down (note that this is the opposite of how mathematicians traditionally think of Y coordinates). So, for example, the upper left corner of a window has coordinates (0,0). (I've left out lots of "fine print" about QuickDraw's coordinate system and how points, which are infinitesimally small, correspond to pixels, which aren't. You won't need to know this information at first, but if you ever do it is in the section of Imaging with QuickDraw entitled "QuickDraw's Coordinate Plane".)
At any given time, QuickDraw has two colors "at its fingertips": the "foreground" color and the "background" color. QuickDraw uses these colors just about as their names suggest. The foreground color is for drawing things that should be visible against the window's background, and the background color is for drawing that background. But beware that changing these colors does not change images or background already drawn, it just changes the colors that will be used for future operations.
You draw lines by moving an imaginary pen to the place where you want the line to start, then dragging the pen to the place where you want the line to end.
Ovals, oddly enough, are defined by rectangles. The idea is that any oval can be defined by the rectangle that just fits around it (the oval's so-called "bounding rectangle"). Using bounding rectangles to define ovals means that you don't have to learn about a special data type just for defining ovals.
Technically, QuickDraw displays graphics but doesn't do anything about graphical input from the user (e.g., mouse clicks or movement). You will find documentation on input of all sorts in the "Event Manager" chapter of Inside Macintosh. Macintosh input is fairly complex in its full generality, but some common kinds of input are surprisingly easy. In particular, the section of Inside Macintosh entitled "Reading the Mouse" explains how to do simple mouse input. Here are a couple of the most commonly used mouse input functions and data types:
For examples of how to use these functions and data types, there is a "QuickDraw Demo" program in my CSci 219 folder, on the "CS Mac Server" file server.