Important: The information in this document is obsolete and should not be used for new development.
Installing and Removing the Translator
If you want to capture QuickDraw commands as they are executed, convert them, and either draw them immediately or save them, you need to install the QuickDraw-to-QuickDraw GX translator in the graphics port to which the QuickDraw drawing commands will be sent.You install the translator with the
GXInstallQDTranslator
function. Once installed, the translator intercepts all QuickDraw drawing commands to that port, converts them to QuickDraw GX shapes, and sends them to a callback function (that you supply) for drawing or saving. When you are finished capturing QuickDraw commands, you remove the translator with theGXRemoveQDTranslator
function.
Listing 1-5 is a sample that uses the functions
- Note
- There is not necessarily a one-to-one match between a QuickDraw function call and the generation of a QuickDraw GX shape.
GXInstallQDTranslator
andGXRemoveQDTranslator
to convert the bounded QuickDraw commands. The application-defined callback function,aShapeProc
, sets the view port and draws each translated shape. TheaShapeProc
function is shown in Listing 1-6 on page 1-22.Listing 1-5 Installing and removing the translator
/* first, install the translator */ GXInstallQDTranslator(window, gxDefaultOptionsTranslation, &theRect, &theRect, theStyleStretch, aShapeProc, (void *) &theWindViewPort); /* now, make QuickDraw calls */ PenSize(20, 10); MoveTo(100, 100); LineTo(200, 100); MoveTo(100, 150); LineTo(200, 250); /* when finished drawing, remove the translator */ GXRemoveQDTranslator(window, nil);When using theGXInstallQDTranslator
function, you must supply an application-defined function that gives you control over what is to be done with the QuickDraw GX shapes resulting from the translation. For example, you may want to draw each shape as it is translated, or you may want to spool multiple shapes and draw after you have completed the picture.Listing 1-6 is the sample shape-spooling function used by the code in Listing 1-5. This function sets the view port, which is passed to it in the
reference
parameter, and then draws the shape passed to it in the parametertheShape
.Listing 1-6 Sample application-defined shape-spooling function
OSErr aShapeProc( gxShape theShape, void *reference) { GXSetShapeViewPorts(theShape, 1, (gxViewPort *) &reference); GXDrawShape(theShape); GXDisposeShape(theShape); return(GXGetGraphicsError(nil)); }The prototype for the shape-spooling function, and how to use it, are described in the section "Handling Translated QuickDraw Data" beginning on page 1-41.