Code Warrior has a suite of predefined functions for graphics that we will
be using in future programs. It is important to note that these functions
are not part of standard C++ but are specific only to
Code Warrior are are only for the Mac. The
prototypes for these QuickDraw functions are
automatically included and do not need #include
statements. There are
however some functions in macStuff.h that will be needed. To do this we
add the following statement to our programs:
#include "macStuff.h" // Quotes mean get the file from our files,
// not Code Warrior's!!
The screen is composed of pixels. The term comes from "picture element".
|
The easiest way to do this is imagine that you have a pen. QuickDraw provides functions to allow your pen to do certain things:
Note: All the above parameters are of type short. So when programming declare these of type short and you will make your friend the compiler much happier!!
Code Warrior has predefined types Rect and Point. Notice the case!!! If the wrong case is used you will find yourself in heaps of trouble. Also keep in mind that there is no notion of a pen here. We will be using boundary frames instead.
To set up a Rect:
Rect r;
...
SetRect(&r, left, top, right, bottom);
Notice the "&" before the first argument. It may look quite mysterious at first but it is quite common. We will be getting to it later, but for now humor the function and put it in. The types are also all short so please declare them as such. This call just sets up the frame for the rectangle. It actually doesn't draw it. To do this we need more function calls.
There are other functions for ovals, rectangles with rounded corners, strings, arcs, etc.
openDrawing();before you use any of the graphics!! This function call will open a graphics window for you where your graphics will be displayed.