April 5, 2008
WikiDrawing
#wiki
Drawing
To create a basic QuickDraw drawing environment, you generally
- initialize QuickDraw
- create one or more graphics ports—typically, by using the Window Manager or the NewGWorld function
- set a current graphics port whenever your application has multiple graphics ports into which it can draw
- use the coordinate system—local or global—appropriate for the QuickDraw or Macintosh Toolbox routine you wish to use next
- move the document’s bit image in relation to the port rectangle of the graphics port when scrolling through a document in a window All graphics operations are performed in graphics ports. Before a basic graphics port can be used, it must be allocated and initialized with the OpenPort procedure. Normally, you don’t call OpenPort yourself. In most cases your application draws into a window you’ve created with the GetNewWindow or NewWindow function (or, for color windows, GetNewCWindow or NewCWindow), or it draws into an offscreen graphics world created with the NewGWorld function.
These Window Manager functions or the NewGWorld function call OpenPort to create a basic graphics port. The GetNewWindow function returns a window pointer, which is defined to be a pointer to graphics port. You can allow GetNewWindow to allocate the memory for your window record and its associated basic graphics port. You can maintain more control over memory use, however, by allocating the memory yourself from a block allocated for such purposes during your own initialization routine, and then passing the pointer to GetNewWindow.
Likewise:
// first creating a rect and then passing its address to the newCWindow function. NewCWindow return a pointer.
SetRect(&windRect,100,100,740,580);
InitCursor();
ourWindow = NewCWindow( 0L, &windRect, "\pAdjust Brightness", true, noGrowDocProc,(WindowPtr)-1L, true, 0L );
if ( ourWindow == nil ) ExitToShell();
ShowWindow( ourWindow ); // showing our window.
SetPortWindowPort( ourWindow );
SetRect(&windRect,0,0,640,480);
error =NewGWorld(&ourBuffer, 32, &windRect, nil, nil,0 ); // creating our offscreen worlds
Continue Reading
Back to Archive