Shapes in Quickdraw
Volume Number: 2
Issue Number: 12
Column Tag: ABC's of C
Drawing Shapes with Quickdraw 
By Bob Gordon , Contributing Editor
One problem with writing software is that friends often want to know what it
does. With most of these columns, frankly, there has not been much to show. This
time, though, you can use the mouse to draw some simple shapes on the screen. Of
course your friends will point out that MacDraw does everything we're going to do, and
much better, too. But this one, we did ourselves, and that makes all the difference!
QuickDraw Shapes and Operations
QuickDraw can draw a number of shapes. This month we are going to cover only
the simple shapes. (I define simple shapes as those that can be drawn directly without
first defining what the shape is.) The simple shapes are:
Rectangles
Ovals (ellipses and circles)
Round-cornered rectangles
Arcs and wedges
To this list we could also add lines. The functions to draw these shapes are built
into the Mac's ROM.
In drawing the shape, QuickDraw can do a number of different operations:
Frame draws a hollow outline
Paint fills the shape with the current grafPort's pen pattern and mode.
Erase fills the shape with the background pattern
Invert inverts all pixels within the shape: black becomes white and white
becomes black
Fill fills the shapes with a specified pattern.
In general, these operations work identically for all the shapes. The shape is
drawn, and the pen's location is not changed. Except for Fill, the operations require
only the information needed to define the shape. Fill also needs to know the pattern to
use. Since we have no easy way to select a pattern (we haven't done custom menus yet,
so we haven't made a pattern selection menu), this operation will not be used.
The Toolbox supplies a separate function for each shape and operation. There
are, for example, five functions to draw rectangles:FrameRect(), PaintRect(),
EraseRect(), InvertRect(), and FillRect(). I wanted to select the shape and operation
from menus and then draw with the mouse as with MacDraw.
Fig. 1 Our Drawing Program
Alternative Designs
One way to do this (assuming we had the menus built) would be to use a switch
(case) statement based on the shape and operation:
switch (shape)
case rect:
switch (operation)
case Frame:
case Paint:
case Erase:
case Invert:
case Fill: