Graphics Chapter 8 Contents

About this chapter

This chapter describes the Mops classes and words that provide an interface to the Macintosh QuickDraw graphics package. This part of the Toolbox is responsible for all of the basic graphics management underlying windows, controls, dialogs and menus, and can also be called directly to accomplish various drawing tasks. Because QuickDraw is so pervasive in the Macintosh, you should read the Inside Macintosh chapter on QuickDraw as a first step in learning how to use the rest of the User Interface Toolbox. While Mops provides an easy interface to much of the QuickDraw package, it is very useful to try and get an understanding of the basic philosophy behind QuickDraw graphics by reading Inside Macintosh before you attempt to do any sophisticated graphics programming. Other Toolbox modules, such as the Window Manager and the Control Manager, rely heavily upon QuickDraw to do much of their actual work.

Recommended reading

Inside Macintosh QuickDraw
Window Manager
Toolbox Utilities

Source files

QD

Using the Graphics Classes

Class Rect is the most widely used QuickDraw class, describing an extensive set of behaviors appropriate to basic rectangles. Rectangles are used for a variety of operations in the Toolbox, such as sizing windows, controls and dialogs, drawing rectangular frames, filling with a pattern, and clipping. Class GrafPort is the superclass of window, and describes the graphics structure that QuickDraw uses as its foundation for windowed behavior.

The Mops word Cursor serves as a defining word to associate names with cursor resource definitions. For instance:

1 cursor IBeamCurs

associates the name IBeamCurs with the cursor data whose resource ID in the system is 1. This happens to be the cursor used for editing text. After this declaration, you can change the current cursor to this image by simply executing the word IBeamCurs. Mops predefines four cursor images for you: IBeamCurs, crossCurs, plusCurs, and watchCurs.

Mops provides access to the system pattern list via the word sysPat. For instance, the phrase:

3 SysPat get: **

leaves a pointer to the system pattern with ID 3. This can be used to send a Fill: message to various graphics objects, or set the pattern for the current pen, for example.

 

Point

Point provides a building block for Rect. A Rect is composed of two Points, each consisting of two Ints, Y and X. Point's methods are useful in providing more advantageous access to a rectangle's data. QuickDraw stores Y before X in Rectangles, but Mops always represents Points on the stack as ( X Y -- ).

Superclass Object
Source file QD
Status Core
Instance variables
int Y The Point's Y coordinate
int X The Point's X coordinate
Indexed data None
System objects None

Object

Methods

accessing
get: ( -- x y ) Returns the values in Y and X
getX: ( -- x ) Returns the value in X
getY: ( -- y ) Returns the value in Y
int: ( -- x:y ) Returns a single longword with x and y packed into the high and low words, as was required for a number of Toolbox calls before SYSCALL
put: ( x y -- ) Stores new values in Y and X
putX: ( x -- ) Stores a new value in X
putY: ( y -- ) Stores a new value in Y.

Error messages

None

 

Rect

Rect is a widely used class that describes various properties of Rectangles.

Superclass Object
Source file QD
Status Core
Point TopL Point describing top left corner
Point BotR Point describing bottom right corner
Instance variables
Indexed data None
System objects
tempRect A scratch rectangle
fpRect Used for scrolling within fWind
 

Object

Methods

accessing
get: ( -- l t r b ) Returns the values in the Rect's two Points in (X Y X Y) format. The first pair is the topLeft Point, and the pair on top of the stack is the bottomRight Point
getTop: ( -- x y )
topInt: ( -- x:y ) Returns the point TopL with x and y packed into a longword
getTopX: ( -- x )
getTopY: ( -- y )
getBot: ( -- x y )
botInt: ( -- x:y )
getBotX: ( -- x )
getBotY: ( -- y )
put: ( l t r b -- ) Stores new coordinates in the Rectangle
putTop: ( x y -- )
putTopX: ( x -- )
putTopY: ( y -- )
putBot: ( x y -- )
putBotX: ( x -- )
putBotY: ( y -- )
size: ( -- w h ) Returns the size of the rectangle in pixels as width and height
setSize: ( w h -- ) Sets the width and height of the rectangle according to w and h, by setting the BotR point
getCenter: ( -- x y ) Returns the center point of the rectangle in the local coordinates of the current GrafPort
inset: ( dx dy -- ) Causes the rectangle to be grown or shrunk around the center point. The left and right sides are moved in by the amount specified by dx; the top and bottom are moved towards the center by the amount specified by dy. If dh or dv is negative, the appropriate pair of sides is moved outwards instead of inwards. Does not redraw the Rect. If either the width or height would become negative, the rectangle is reset to the empty rectangle (0 0 0 0)
shift: ( dx dy -- ) Moves the rectangle the given distance. Does not redraw the Rect
offset: ( dx dy -- ) A synonym for shift:
stretch: ( dx dy -- ) Shifts the BotR point by the given distance
->: ( ^rect -- ) Copies the Rect whose address is passed in to this Rect.
drawing
draw: ( -- ) Draws the rectangle's frame
dropShadow: ( -- ) As for draw:, but adds a standard Mac drop shadow
disp: ( l t r b -- ) Combines the actions of put: and draw:
clear: ( -- ) Fills the rectangle's frame with the current GrafPort's background pattern and color
paint: ( -- ) Fills the rectangle's frame with the current GrafPort's foreground pattern and colour
fill: ( pattern -- ) Given a pointer to a QuickDraw Pattern, fills the Rect's frame with the Pattern. For example, 3 sysPat get: ** fill: myRect would fill the rectangle with the system pattern #3
invert: ( -- ) Inverts the pixels bounded by the rectangle
clip: ( -- ) Clips all subsequent drawing to the area bounded by the rectangle
update: ( -- ) Causes an update event to occur for the current window that will redraw everything inside the rectangle

Error messages

None

 

GrafPort

This class maps the record structure for a GrafPort. A QuickDraw GrafPort defines a local drawing environ-ment with its own coordinate system and pen characteristics, and provides the basic functionality necessary for windowing. A Window record incorporates a GrafPort as the first part of its data. Note that although a basic (B&W) GrafPort and a (color) CGrafPort are the same length, the allocation of individual bytes to different functions is not identical; this is one reason why we do not assign names to each field in the GrafPort record.

Superclass Object
Source file QD
16 bytes graf1 Allocates the first 16 bytes of the GrafPort
rect PortRect The port rectangle defining the GrafPort's limits
44 bytes graf2 Allocates the last 84 bytes of the GrafPort
var Text1 font, face, mode, size
var Text2
32 bytes graf3
Status Core
Instance variables
Indexed data None
System objects None

Object

Methods

accessing
getRect: ( -- l t r b ) Returns the coordinates of the GrafPort's PortRect
putRect: ( l t r b -- ) Sets the coordinates of the GrafPort's PortRect
drawing
set: ( -- ) Causes this to be the current GrafPort for subsequent drawing.

Error messages

None

 

Previous Chapter Contents Next Chapter
This page online:  http://PowerMops.com/MopsManual/Classes/Chapter8.html