home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap12-demo / QuickDraw.c < prev    next >
C/C++ Source or Header  |  2001-05-22  |  43KB  |  1,621 lines

  1. // *******************************************************************************************
  2. // QuickDraw.c                                                             CLASSIC EVENT MODEL
  3. // *******************************************************************************************
  4. // 
  5. // This program opens a window in which the results of various QuickDraw drawing operations 
  6. // are displayed.  Individual line and text drawing, framing, painting, filling, erasing,
  7. // inverting, copying, etc., operations are chosen from a Demonstration pull-down menu.
  8. //
  9. // To keep the non-QuickDraw code to a minimum, the program contains no functions for
  10. // updating the window or for responding to activate and operating system events.
  11. //
  12. // The program utilises the following resources:
  13. //
  14. // •    A 'plst' resource.
  15. //
  16. // •    'WIND' resources for the main window, and a small window used for the CopyBits
  17. //        demonstration (purgeable) (initially visible).
  18. //
  19. // •    An 'MBAR' resource and associated 'MENU' resources (preload, non-purgeable).
  20. //
  21. // •    Two 'ICON' resources (purgeable) used for the boolean source modes demonstration. 
  22. //
  23. // •    Two 'PICT' resources (purgeable) used in the arithmetic source modes demonstration.
  24. //
  25. // •    'STR#' resources (purgeable) containing strings used in the source modes and text
  26. //        drawing demonstrations.
  27. //
  28. // •    Three 'ppat' resources (purgeable), two of which are used in various drawing, 
  29. //        framing, painting, filling, and erasing demonstrations.  The third is used in the
  30. //        drawing with mouse demonstration.
  31. //
  32. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  33. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  34. //
  35. // *******************************************************************************************
  36.  
  37. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  38.  
  39. #include <Carbon.h>
  40.  
  41. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  42.  
  43. #define rMenubar                                128
  44. #define mAppleApplication                128
  45. #define  iAbout                                    1
  46. #define mFile                                        129
  47. #define  iQuit                                    12
  48. #define mDemonstration                    131
  49. #define  iLine                                    1
  50. #define  iFrameAndPaint                    2
  51. #define  iFillEraseInvert                3
  52. #define  iPolygonRegion                    4
  53. #define  iText                                    5
  54. #define  iScrolling                            6
  55. #define  iBooleanSourceModes        7
  56. #define  iArithmeticSourceModes    8
  57. #define  iHighlighting                    9
  58. #define  iDrawWithMouse                     10
  59. #define  iDrawingState                    11
  60. #define rWindow                                    128
  61. #define rPixelPattern1                    128
  62. #define rPixelPattern2                    129
  63. #define rPixelPattern3                    130
  64. #define rDestinationIcon                128
  65. #define rSourceIcon                            129
  66. #define rFontsStringList                128
  67. #define rBooleanStringList            129
  68. #define rArithmeticStringList        130
  69. #define rPicture                                128
  70. #define MAX_UINT32                            0xFFFFFFFF
  71.  
  72. // …………………………………………………………………………………………………………………………………………………………………………………………………… global variables
  73.  
  74. Boolean        gRunningOnX            = false;
  75. Boolean        gDone;
  76. WindowRef    gWindowRef;
  77. Boolean        gDrawWithMouseActivated;
  78. SInt16        gPixelDepth;    
  79. Boolean        gIsColourDevice    = false;
  80. RGBColor     gWhiteColour        = { 0xFFFF, 0xFFFF, 0xFFFF };
  81. RGBColor     gBlackColour        = { 0x0000, 0x0000, 0x0000 };
  82. RGBColor     gRedColour            = { 0xAAAA, 0x0000, 0x0000 };
  83. RGBColor     gYellowColour        = { 0xFFFF, 0xCCCC, 0x0000 };
  84. RGBColor    gGreenColour        = { 0x0000, 0x9999, 0x0000 };
  85. RGBColor     gBlueColour            = { 0x6666, 0x6666, 0x9999 };
  86.  
  87. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  88.  
  89. void        main                                        (void);
  90. void        doPreliminaries                    (void);
  91. OSErr        quitAppEventHandler            (AppleEvent *,AppleEvent *,SInt32);
  92. void        doEvents                                (EventRecord *);
  93. void        doDemonstrationMenu            (MenuItemIndex);
  94. void        doLines                                    (void);
  95. void        doFrameAndPaint                    (void);
  96. void        doFillEraseInvert                (void);
  97. void        doPolygonAndRegion            (void);
  98. void        doScrolling                            (void);
  99. void        doText                                    (void);
  100. void        doBooleanSourceModes        (void);
  101. void        doArithmeticSourceModes    (void);
  102. void        doHighlighting                    (void);
  103. void        doDrawWithMouse                    (void);
  104. void        doDrawingState                    (void);
  105. void        doDrawingStateProof            (SInt16);
  106. void        doGetDepthAndDevice            (void);
  107. UInt16    doRandomNumber                    (UInt16,UInt16);
  108.  
  109. // ************************************************************************************** main
  110.  
  111. void  main(void)
  112. {
  113.     UInt32                seconds;
  114.     MenuBarHandle    menubarHdl;
  115.     SInt32                response;
  116.     MenuRef                menuRef;
  117.     EventRecord        eventStructure;
  118.     Boolean                gotEvent;        
  119.  
  120.     // ………………………………………………………………………………………………………………………………………………………………………………………………… do prelimiaries
  121.  
  122.     doPreliminaries();
  123.  
  124.     // ……………………………………………………………………………………………………………………………………………………………… seed random number generator
  125.  
  126.     GetDateTime(&seconds);
  127.     SetQDGlobalsRandomSeed(seconds);
  128.  
  129.     // ……………………………………………………………………………………………………………………………………………………………………… set up menu bar and menus
  130.  
  131.     menubarHdl = GetNewMBar(rMenubar);
  132.     if(menubarHdl == NULL)
  133.         ExitToShell();
  134.     SetMenuBar(menubarHdl);
  135.     DrawMenuBar();
  136.  
  137.     Gestalt(gestaltMenuMgrAttr,&response);
  138.     if(response & gestaltMenuMgrAquaLayoutMask)
  139.     {
  140.         menuRef = GetMenuRef(mFile);
  141.         if(menuRef != NULL)
  142.         {
  143.             DeleteMenuItem(menuRef,iQuit);
  144.             DeleteMenuItem(menuRef,iQuit - 1);
  145.             DisableMenuItem(menuRef,0);
  146.         }
  147.  
  148.         gRunningOnX = true;
  149.     }
  150.  
  151.     // …………………………………………………………………………………………………………………………………………………………………………………………………………… open window
  152.  
  153.     if(!(gWindowRef = GetNewCWindow(rWindow,NULL,(WindowRef)-1)))
  154.         ExitToShell();
  155.  
  156.     SetPortWindowPort(gWindowRef);
  157.     UseThemeFont(kThemeSmallSystemFont,smSystemScript);
  158.  
  159.     // ……………… get pixel depth and whether colour device for certain Appearance Manager functions
  160.     
  161.     doGetDepthAndDevice();
  162.  
  163.     // ………………………………………………………………………………………………………………………………………………………………………………………………………………… eventLoop
  164.  
  165.     gDone = false;
  166.  
  167.     while(!gDone)
  168.     {
  169.         gotEvent = WaitNextEvent(everyEvent,&eventStructure,MAX_UINT32,NULL);
  170.         if(gotEvent)
  171.             doEvents(&eventStructure);
  172.     }
  173. }
  174.  
  175. // *************************************************************************** doPreliminaries
  176.  
  177. void  doPreliminaries(void)
  178. {
  179.     OSErr    osError;
  180.  
  181.     MoreMasterPointers(32);
  182.     InitCursor();
  183.     FlushEvents(everyEvent,0);
  184.  
  185.     osError = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
  186.                                                         NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
  187.                                                         0L,false);
  188.     if(osError != noErr)
  189.         ExitToShell();    
  190. }
  191.  
  192. // **************************************************************************** doQuitAppEvent
  193.  
  194. OSErr  quitAppEventHandler(AppleEvent *appEvent,AppleEvent *reply,SInt32 handlerRefcon)
  195. {
  196.     OSErr            osError;
  197.     DescType    returnedType;
  198.     Size            actualSize;
  199.  
  200.     osError = AEGetAttributePtr(appEvent,keyMissedKeywordAttr,typeWildCard,&returnedType,NULL,0,
  201.                                                             &actualSize);
  202.  
  203.     if(osError == errAEDescNotFound)
  204.     {
  205.         gDone = true;
  206.         osError = noErr;
  207.     } 
  208.     else if(osError == noErr)
  209.         osError = errAEParamMissed;
  210.  
  211.     return osError;
  212. }
  213.  
  214. // ********************************************************************************** doEvents
  215.  
  216. void    doEvents(EventRecord *eventStrucPtr)
  217. {
  218.     SInt32                    menuChoice;
  219.     MenuID                    menuID;
  220.     MenuItemIndex        menuItem;
  221.     WindowPartCode    partCode;
  222.     WindowRef                windowRef;
  223.     
  224.     switch(eventStrucPtr->what)
  225.     {
  226.         case kHighLevelEvent:
  227.             AEProcessAppleEvent(eventStrucPtr);
  228.             break;
  229.  
  230.         case keyDown:
  231.             if((eventStrucPtr->modifiers & cmdKey) != 0)
  232.             {
  233.                 menuChoice = MenuEvent(eventStrucPtr);
  234.                 menuID = HiWord(menuChoice);
  235.                 menuItem = LoWord(menuChoice);
  236.                 if(menuID == mFile && menuItem  == iQuit)
  237.                     gDone = true;
  238.             }
  239.             break;
  240.  
  241.         case mouseDown:
  242.             if(partCode = FindWindow(eventStrucPtr->where,&windowRef))
  243.             {
  244.                 switch(partCode)
  245.                 {
  246.                     case inMenuBar:
  247.                         menuChoice = MenuSelect(eventStrucPtr->where);
  248.                         menuID = HiWord(menuChoice);
  249.                         menuItem = LoWord(menuChoice);
  250.  
  251.                         if(menuID == 0)
  252.                             return;
  253.  
  254.                         switch(menuID)
  255.                         {
  256.                             case mAppleApplication:
  257.                                 if(menuItem == iAbout)
  258.                                     SysBeep(10);
  259.                                 break;
  260.  
  261.                             case mFile:
  262.                                 if(menuItem == iQuit)
  263.                                     gDone = true;
  264.                                 break;
  265.                                 
  266.                             case mDemonstration:
  267.                                 doDemonstrationMenu(menuItem);
  268.                                 break;
  269.                         }
  270.                         break;
  271.  
  272.                     case inDrag:
  273.                         DragWindow(windowRef,eventStrucPtr->where,NULL);
  274.                         break;
  275.  
  276.                     case inContent:
  277.                         if(windowRef != FrontWindow())
  278.                             SelectWindow(windowRef);
  279.                         else
  280.                             if(gDrawWithMouseActivated)
  281.                                 doDrawWithMouse();
  282.                         break;
  283.                 }
  284.             }
  285.             break;
  286.  
  287.         case updateEvt:
  288.             windowRef = (WindowRef) eventStrucPtr->message;
  289.             BeginUpdate(windowRef);
  290.             EndUpdate(windowRef);
  291.             break;
  292.     }
  293. }
  294.  
  295. // *********************************************************************** doDemonstrationMenu
  296.  
  297. void    doDemonstrationMenu(MenuItemIndex menuItem)
  298. {
  299.     Rect        portRect;
  300.     Pattern    whitePattern;
  301.     
  302.     gDrawWithMouseActivated = false;
  303.  
  304.     switch(menuItem)
  305.     {
  306.         case iLine:
  307.             doLines();
  308.             break;
  309.  
  310.         case iFrameAndPaint:
  311.             doFrameAndPaint();
  312.             break;            
  313.  
  314.         case iFillEraseInvert:
  315.             doFillEraseInvert();
  316.             break;
  317.  
  318.         case iPolygonRegion:
  319.             doPolygonAndRegion();
  320.             break;
  321.  
  322.         case iText:
  323.             doText();
  324.             break;
  325.  
  326.         case iScrolling:
  327.             doScrolling();
  328.             break;
  329.  
  330.         case iBooleanSourceModes:
  331.             doBooleanSourceModes();
  332.             break;
  333.     
  334.         case iArithmeticSourceModes:
  335.             doArithmeticSourceModes();
  336.             break;
  337.  
  338.         case iHighlighting:
  339.             doHighlighting();
  340.             break;
  341.  
  342.         case iDrawWithMouse:
  343.             SetWTitle(gWindowRef,"\pDrawing with the mouse");
  344.             RGBBackColor(&gWhiteColour);
  345.             GetWindowPortBounds(gWindowRef,&portRect);
  346.             FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  347.             gDrawWithMouseActivated = true;
  348.             break;
  349.  
  350.         case iDrawingState:
  351.             doDrawingState();
  352.             break;
  353.     }
  354.  
  355.     HiliteMenu(0);
  356. }
  357.  
  358. // *********************************************************************************** doLines
  359.  
  360. void  doLines(void)
  361. {
  362.     Rect                    portRect, newClipRect;
  363.     Pattern                whitePattern, systemPattern, blackPattern;
  364.     RgnHandle            oldClipRgn;
  365.     SInt16                a, b, c;
  366.     RGBColor             theColour;
  367.     UInt32                finalTicks;
  368.     PixPatHandle    pixpatHdl;    
  369.  
  370.     PenNormal();
  371.  
  372.     RGBBackColor(&gBlueColour);
  373.     GetWindowPortBounds(gWindowRef,&portRect);
  374.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  375.  
  376.     newClipRect = portRect;
  377.     InsetRect(&newClipRect,10,10);
  378.     oldClipRgn = NewRgn();
  379.     GetClip(oldClipRgn);
  380.     ClipRect(&newClipRect);
  381.  
  382.     // …………………………………………………………………………………… lines drawn with foreground colour and black pen pattern
  383.  
  384.     SetWTitle(gWindowRef,"\pDrawing lines with colours");
  385.     RGBBackColor(&gWhiteColour);
  386.     FillRect(&portRect,&whitePattern);
  387.  
  388.     if(!gRunningOnX)
  389.         SetThemeCursor(kThemeWatchCursor);
  390.  
  391.     for(a=1;a<60;a++)
  392.     {
  393.         b = doRandomNumber(0,portRect.right - portRect.left);
  394.         c = doRandomNumber(0,portRect.right - portRect.left);
  395.  
  396.         theColour.red   = doRandomNumber(0,65535);
  397.         theColour.green = doRandomNumber(0,65535);
  398.         theColour.blue  = doRandomNumber(0,65535);
  399.         RGBForeColor(&theColour);
  400.     
  401.         PenSize(a * 2,1);        
  402.  
  403.         MoveTo(b,portRect.top);
  404.         LineTo(c,portRect.bottom);
  405.  
  406.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  407.         Delay(2,&finalTicks);
  408.     }
  409.  
  410.     if(!gRunningOnX)
  411.         SetThemeCursor(kThemeArrowCursor);
  412.  
  413.     // ………………………………………………………………………………………………………………… lines drawn with system-supplied bit patterns
  414.  
  415.     SetWTitle(gWindowRef,"\pClick mouse for more lines");
  416.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  417.     while(!Button()) ;    
  418.     SetWTitle(gWindowRef,"\pDrawing lines with system-supplied bit patterns");
  419.     FillRect(&portRect,&whitePattern);
  420.  
  421.     if(!gRunningOnX)
  422.         SetThemeCursor(kThemeWatchCursor);
  423.  
  424.     for(a=1;a<39;a++)
  425.     {
  426.         b = doRandomNumber(0,portRect.bottom - portRect.top);
  427.         c = doRandomNumber(0,portRect.bottom - portRect.top);
  428.  
  429.         theColour.red   = doRandomNumber(0,32767);
  430.         theColour.green = doRandomNumber(0,32767);
  431.         theColour.blue  = doRandomNumber(0,32767);
  432.         RGBForeColor(&theColour);
  433.     
  434.         GetIndPattern(&systemPattern,sysPatListID,a);
  435.         PenPat(&systemPattern);
  436.  
  437.         PenSize(1, a * 2);        
  438.  
  439.         MoveTo(portRect.left,b);
  440.         LineTo(portRect.right,c);
  441.  
  442.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  443.         Delay(5,&finalTicks);
  444.     }
  445.  
  446.     if(!gRunningOnX)
  447.         SetThemeCursor(kThemeArrowCursor);
  448.  
  449.     // …………………………………………………………………………………………………………………………………………………… lines drawn with a pixel pattern
  450.  
  451.     SetWTitle(gWindowRef,"\pClick mouse for more lines");
  452.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  453.     while(!Button()) ;    
  454.     SetWTitle(gWindowRef,"\pDrawing lines with a pixel pattern");
  455.     FillRect(&portRect,&whitePattern);
  456.  
  457.     if(!gRunningOnX)
  458.         SetThemeCursor(kThemeWatchCursor);
  459.  
  460.     if(!(pixpatHdl = GetPixPat(rPixelPattern1)))
  461.         ExitToShell();
  462.     PenPixPat(pixpatHdl);
  463.  
  464.  
  465.     for(a=1;a<60;a++)
  466.     {
  467.         b = doRandomNumber(0,portRect.right - portRect.left);
  468.         c = doRandomNumber(0,portRect.right - portRect.left);
  469.  
  470.         PenSize(a * 2,1);        
  471.  
  472.         MoveTo(b,portRect.top);
  473.         LineTo(c,portRect.bottom);
  474.  
  475.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  476.         Delay(5,&finalTicks);
  477.     }
  478.  
  479.     DisposePixPat(pixpatHdl);
  480.  
  481.     SetClip(oldClipRgn);
  482.     DisposeRgn(oldClipRgn);
  483.  
  484.     if(!gRunningOnX)
  485.         SetThemeCursor(kThemeArrowCursor);
  486.  
  487.     // ………………………………………………………………………………………………………………………………………… lines drawn with pattern mode patXor
  488.  
  489.     SetWTitle(gWindowRef,"\pClick mouse for more lines");
  490.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  491.     while(!Button()) ;
  492.     SetWTitle(gWindowRef,"\pDrawing lines using pattern mode patXor");
  493.  
  494.     if(!gRunningOnX)
  495.         SetThemeCursor(kThemeWatchCursor);
  496.  
  497.     RGBBackColor(&gRedColour);
  498.     FillRect(&portRect,&whitePattern);
  499.  
  500.     PenSize(1,1);        
  501.     PenPat(GetQDGlobalsBlack(&blackPattern));
  502.     PenMode(patXor);
  503.  
  504.     InsetRect(&portRect,10,10);
  505.  
  506.     for(a = portRect.left,b = portRect.right;a < portRect.right + 1;a++,b--)
  507.     {
  508.         MoveTo(a,portRect.top);
  509.         LineTo(b,portRect.bottom);
  510.  
  511.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  512.     }
  513.  
  514.     for(a = portRect.bottom,b = portRect.top;b < portRect.bottom + 1;a--,b++)
  515.     {
  516.         MoveTo(portRect.left,a);
  517.         LineTo(portRect.right,b);
  518.  
  519.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  520.     }
  521.  
  522.     if(!gRunningOnX)
  523.         SetThemeCursor(kThemeArrowCursor);
  524. }
  525.  
  526. // *************************************************************************** doFrameAndPaint
  527.  
  528. void  doFrameAndPaint(void)
  529. {
  530.     SInt16                a;
  531.     Rect                    portRect, theRect;
  532.     Pattern                whitePattern;
  533.     UInt32                finalTicks;
  534.     Pattern                systemPattern;
  535.     PixPatHandle    pixpatHdl;    
  536.  
  537.     PenNormal();
  538.     PenSize(30,20);
  539.     
  540.     for(a=0;a<3;a++)
  541.     {
  542.         RGBBackColor(&gWhiteColour);
  543.         GetWindowPortBounds(gWindowRef,&portRect);
  544.         FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  545.  
  546.         if(!gRunningOnX)
  547.             SetThemeCursor(kThemeWatchCursor);
  548.  
  549.         // ……………………………………………………………………………………………………………………………………………………………………………………………………… preparation
  550.  
  551.         if(a == 0)
  552.         {
  553.             SetWTitle(gWindowRef,"\pFraming and painting with a colour");
  554.             RGBForeColor(&gRedColour);                                                             // set foreground colour to red
  555.         }
  556.         else if(a == 1)
  557.         {
  558.             SetWTitle(gWindowRef,"\pFraming and painting with a bit pattern");
  559.  
  560.             RGBForeColor(&gBlueColour);                                                            // set foreground colour to blue
  561.             RGBBackColor(&gYellowColour);                                                    // set foreground colour to yellow
  562.             GetIndPattern(&systemPattern,sysPatListID,16);                                // get bit pattern for pen
  563.             PenPat(&systemPattern);                                                                                        // set pen bit pattern
  564.         }
  565.         else if (a == 2)
  566.         {
  567.             SetWTitle(gWindowRef,"\pFraming and painting with a pixel pattern");
  568.  
  569.             if(!(pixpatHdl = GetPixPat(rPixelPattern1)))                                // get pixel pattern for pen
  570.                 ExitToShell();
  571.             PenPixPat(pixpatHdl);                                                                                        // set pen pixel pattern
  572.         }
  573.  
  574.         // ……………………………………………………………………………………………………………………………………………………………………………… framing and painting
  575.     
  576.         SetRect(&theRect,30,32,151,191);        
  577.         FrameRect(&theRect);                                                                                                                    // FrameRect
  578.         MoveTo(30,29);
  579.         DrawString("\pFrameRect");    
  580.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  581.         Delay(30,&finalTicks);
  582.  
  583.         OffsetRect(&theRect,140,0);
  584.         FrameRoundRect(&theRect,30,50);                                                                                     // FrameRoundRect
  585.         MoveTo(170,29);
  586.         DrawString("\pFrameRoundRect");    
  587.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  588.         Delay(30,&finalTicks);
  589.  
  590.         OffsetRect(&theRect,140,0);
  591.         FrameOval(&theRect);                                                                                                                    // FrameOval
  592.         MoveTo(310,29);
  593.         DrawString("\pFrameOval");    
  594.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  595.         Delay(30,&finalTicks);
  596.  
  597.         OffsetRect(&theRect,140,0);
  598.         FrameArc(&theRect,330,300);                                                                                                         // FrameArc
  599.         MoveTo(450,29);
  600.         DrawString("\pFrameArc");    
  601.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  602.         Delay(30,&finalTicks);
  603.     
  604.         OffsetRect(&theRect,-420,186);
  605.         PaintRect(&theRect);                                                                                                                    // PaintRect
  606.         MoveTo(30,214);
  607.         DrawString("\pPaintRect");    
  608.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  609.         Delay(30,&finalTicks);
  610.  
  611.         OffsetRect(&theRect,140,0);
  612.         PaintRoundRect(&theRect,30,50);                                                                                     // PaintRoundRect
  613.         MoveTo(170,214);
  614.         DrawString("\pPaintRoundRect");    
  615.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  616.         Delay(30,&finalTicks);
  617.  
  618.         OffsetRect(&theRect,140,0);
  619.         PaintOval(&theRect);                                                                                                                    // PaintOval
  620.         MoveTo(310,214);
  621.         DrawString("\pPaintOval");    
  622.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  623.         Delay(30,&finalTicks);
  624.  
  625.         OffsetRect(&theRect,140,0);
  626.         PaintArc(&theRect,330,300);                                                                                                         // PaintArc
  627.         MoveTo(450,214);
  628.         DrawString("\pPaintArc");    
  629.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  630.         Delay(30,&finalTicks);
  631.     
  632.         if(!gRunningOnX)
  633.             SetThemeCursor(kThemeArrowCursor);
  634.  
  635.         if(a < 2)
  636.         {
  637.             SetWTitle(gWindowRef,"\pClick mouse for more");
  638.             QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  639.             while(!Button()) ;
  640.         }    
  641.     }
  642.  
  643.     DisposePixPat(pixpatHdl);
  644. }
  645.  
  646. // ************************************************************************* doFillEraseInvert
  647.  
  648. void  doFillEraseInvert(void)
  649. {
  650.     SInt16                a;
  651.     Rect                    portRect, theRect;
  652.     Pattern                whitePattern, fillPat, backPat;
  653.     PixPatHandle    fillPixpatHdl, backPixpatHdl;    
  654.     UInt32                finalTicks;
  655.  
  656.     PenNormal();
  657.     PenSize(30,20);
  658.  
  659.     for(a=0;a<4;a++)
  660.     {
  661.         if(a < 3)
  662.         {
  663.             RGBBackColor(&gWhiteColour);
  664.             GetWindowPortBounds(gWindowRef,&portRect);
  665.             FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  666.         }
  667.  
  668.         if(!gRunningOnX)
  669.             SetThemeCursor(kThemeWatchCursor);
  670.  
  671.         // ……………………………………………………………………………………………………………………………………………………………………………………………………… preparation
  672.  
  673.         if(a == 0)
  674.         {
  675.             SetWTitle(gWindowRef,"\pFilling and erasing with colours");
  676.  
  677.             RGBForeColor(&gBlueColour);                                                         // set blue colour for foreground
  678.             RGBBackColor(&gRedColour);                                                            // set red colour for background
  679.             GetIndPattern(&fillPat,sysPatListID,1);             // get black bit pattern for fill functions
  680.             BackPat(&whitePattern);                                                     // set white bit pattern for background
  681.         }
  682.         else if(a == 1)
  683.         {
  684.             SetWTitle(gWindowRef,"\pFilling and erasing with bit patterns");
  685.  
  686.             RGBForeColor(&gBlueColour);                                                         // set blue colour for foreground
  687.             RGBBackColor(&gYellowColour);                                                 // set yellow colour for background
  688.             GetIndPattern(&fillPat,sysPatListID,37);                     // get bit pattern for fill functions
  689.             GetIndPattern(&backPat,sysPatListID,19);                             // get bit pattern for background
  690.             BackPat(&backPat);                                                                         // set bit pattern for background
  691.         }
  692.         else if (a == 2)
  693.         {
  694.             SetWTitle(gWindowRef,"\pFilling and erasing with pixel patterns");
  695.  
  696.             if(!(fillPixpatHdl = GetPixPat(rPixelPattern1)))            // get pixel patt - fill functions
  697.                 ExitToShell();
  698.             if(!(backPixpatHdl = GetPixPat(rPixelPattern2)))             // get pixel pattern - background
  699.                 ExitToShell();
  700.             BackPixPat(backPixpatHdl);                                                         // set pixel pattern - background
  701.         }
  702.         else if(a == 3)
  703.         {
  704.             SetWTitle(gWindowRef,"\pInverting");
  705.  
  706.             BackPat(&whitePattern);
  707.             SetRect(&theRect,30,15,570,29);
  708.             EraseRect(&theRect);
  709.             SetRect(&theRect,30,200,570,214);
  710.             EraseRect(&theRect);
  711.         }
  712.  
  713.         // ………………………………………………………………………………………………………………………………………………… filling, erasing, and inverting
  714.         
  715.         SetRect(&theRect,30,32,151,191);        
  716.         MoveTo(30,29);
  717.         if(a < 2)
  718.         {
  719.             FillRect(&theRect,&fillPat);                                                                                                 // FillRect
  720.             DrawString("\pFillRect");    
  721.         }
  722.         else if(a == 2)
  723.         {
  724.             FillCRect(&theRect,fillPixpatHdl);                                                                                    // FillCRect
  725.             DrawString("\pFillCRect");    
  726.         }
  727.         else if(a == 3)
  728.         {
  729.             InvertRect(&theRect);                                                                                                             // InvertRect
  730.             DrawString("\pInvertRect");    
  731.         }        
  732.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  733.         Delay(30,&finalTicks);
  734.  
  735.         OffsetRect(&theRect,140,0);
  736.         MoveTo(170,29);
  737.         if(a < 2)
  738.         {
  739.             FillRoundRect(&theRect,30,50,&fillPat);                                                                    // FillRoundRect
  740.             DrawString("\pFillRoundRect");    
  741.         }
  742.         else if(a == 2)
  743.         {
  744.             FillCRoundRect(&theRect,30,50,fillPixpatHdl);                                                     // FillCRoundRect
  745.             DrawString("\pFillCRoundRect");    
  746.         }
  747.         else if(a == 3)
  748.         {
  749.             InvertRoundRect(&theRect,30,50);                                                                            // InvertRoundRect
  750.             DrawString("\pInvertRoundRect");    
  751.         }        
  752.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  753.         Delay(30,&finalTicks);
  754.  
  755.         OffsetRect(&theRect,140,0);
  756.         MoveTo(310,29);
  757.         if(a < 2)
  758.         {
  759.             FillOval(&theRect,&fillPat);                                                                                                 // FillOval
  760.             DrawString("\pFillOval");    
  761.         }
  762.         else if(a == 2)
  763.         {
  764.             FillCOval(&theRect,fillPixpatHdl);                                                                                    // FillCOval
  765.             DrawString("\pFillCOval");    
  766.         }
  767.         else if(a == 3)
  768.         {
  769.             InvertOval(&theRect);                                                                                                             // InvertOval
  770.             DrawString("\pInvertOval");    
  771.         }        
  772.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  773.         Delay(30,&finalTicks);
  774.  
  775.         OffsetRect(&theRect,140,0);
  776.         MoveTo(450,29);
  777.         if(a < 2)
  778.         {
  779.             FillArc(&theRect,330,300,&fillPat);                                                                                        // FillArc
  780.             DrawString("\pFillArc");    
  781.         }
  782.         else if(a == 2)
  783.         {
  784.             FillCArc(&theRect,330,300,fillPixpatHdl);                                                                         // FillCArc
  785.             DrawString("\pFillCArc");    
  786.         }
  787.         else if(a == 3)
  788.         {
  789.             InvertArc(&theRect,330,300);                                                                                                // InvertArc
  790.             DrawString("\pInvertArc");    
  791.         }        
  792.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  793.         Delay(30,&finalTicks);
  794.     
  795.         OffsetRect(&theRect,-420,186);
  796.         MoveTo(30,214);
  797.         if(a < 3)
  798.         {
  799.             EraseRect(&theRect);                                                                                                                // EraseRect
  800.             DrawString("\pEraseRect");    
  801.         }
  802.         else
  803.         {
  804.             InvertRect(&theRect);                                                                                                             // InvertRect
  805.             DrawString("\pInvertRect");    
  806.         }
  807.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  808.         Delay(30,&finalTicks);
  809.  
  810.         OffsetRect(&theRect,140,0);
  811.         MoveTo(170,214);
  812.         if(a < 3)
  813.         {
  814.             EraseRoundRect(&theRect,30,50);                                                                                 // EraseRoundRect
  815.             DrawString("\pEraseRoundRect");    
  816.         }
  817.         else
  818.         {
  819.             InvertRoundRect(&theRect,30,50);                                                                            // InvertRoundRect
  820.             DrawString("\pInvertRoundRect");    
  821.         }
  822.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  823.         Delay(30,&finalTicks);
  824.  
  825.         OffsetRect(&theRect,140,0);
  826.         MoveTo(310,214);
  827.         if(a < 3)
  828.         {    
  829.             EraseOval(&theRect);                                                                                                                // EraseOval
  830.             DrawString("\pEraseOval");    
  831.         }
  832.         else
  833.         {
  834.             InvertOval(&theRect);                                                                                                             // InvertOval
  835.             DrawString("\pInvertOval");    
  836.         }
  837.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  838.         Delay(30,&finalTicks);
  839.  
  840.         OffsetRect(&theRect,140,0);
  841.         MoveTo(450,214);
  842.         if(a < 3)
  843.         {
  844.             EraseArc(&theRect,330,300);                                                                                                     // EraseArc
  845.             DrawString("\pEraseArc");    
  846.         }
  847.         else
  848.         {
  849.             InvertArc(&theRect,330,300);                                                                                                // InvertArc
  850.             DrawString("\pInvertArc");    
  851.         }
  852.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  853.         Delay(30,&finalTicks);
  854.  
  855.         if(!gRunningOnX)
  856.             SetThemeCursor(kThemeArrowCursor);
  857.  
  858.         if(a < 3)
  859.         {
  860.             SetWTitle(gWindowRef,"\pClick mouse for more");
  861.             QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  862.             while(!Button()) ;
  863.         }    
  864.     }
  865.  
  866.     DisposePixPat(fillPixpatHdl);
  867.     DisposePixPat(backPixpatHdl);
  868. }
  869.  
  870. // ************************************************************************ doPolygonAndRegion
  871.  
  872. void  doPolygonAndRegion(void)
  873. {
  874.     Rect                    portRect, theRect;
  875.     Pattern                whitePattern, backPat;
  876.     PixPatHandle    fillPixpatHdl;    
  877.     PolyHandle        polygonHdl;
  878.     RgnHandle            regionHdl;
  879.     UInt32                finalTicks;
  880.  
  881.     SetWTitle(gWindowRef,"\pFraming, painting, filling, and erasing polygons and regions");
  882.  
  883.     RGBBackColor(&gWhiteColour);
  884.     GetWindowPortBounds(gWindowRef,&portRect);
  885.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  886.  
  887.     if(!gRunningOnX)
  888.         SetThemeCursor(kThemeWatchCursor);
  889.  
  890.     // …………………………………………………………………………………………………………………………………………………………………………………………………………… preparation
  891.  
  892.     GetIndPattern(&backPat,sysPatListID,17);                                     // get bit pattern for background
  893.     BackPat(&backPat);                                                                                 // set bit pattern for background
  894.     if(!(fillPixpatHdl = GetPixPat(rPixelPattern2)))         // get pixel pattern for fill functions
  895.         ExitToShell();
  896.     RGBForeColor(&gRedColour);                                                                    // set red colour for foreground
  897.     RGBBackColor(&gYellowColour);                                                         // set yellow colour for background
  898.     PenNormal();    
  899.  
  900.     polygonHdl = OpenPoly();                                                                                                     // define polygon
  901.     MoveTo(30,32);
  902.     LineTo(151,32);
  903.     LineTo(96,103);
  904.     LineTo(151,134);    
  905.     LineTo(151,191);
  906.     LineTo(30,191);
  907.     LineTo(66,75);
  908.     ClosePoly();
  909.  
  910.     regionHdl = NewRgn();                                                                                                                // define region
  911.     OpenRgn();
  912.     SetRect(&theRect,30,218,151,279);
  913.     FrameRect(&theRect);
  914.     SetRect(&theRect,30,316,151,377);
  915.     FrameRect(&theRect);
  916.     SetRect(&theRect,39,248,142,341);
  917.     FrameOval(&theRect);
  918.     CloseRgn(regionHdl);
  919.  
  920.     // ………………………………………………………………………………………………………………………………… framing, painting, filling, and erasing
  921.  
  922.     FramePoly(polygonHdl);                                                                                                                    // FramePoly
  923.     MoveTo(30,29);
  924.     DrawString("\pFramePoly (colour)");    
  925.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  926.     Delay(30,&finalTicks);
  927.  
  928.     OffsetPoly(polygonHdl,140,0);
  929.     PaintPoly(polygonHdl);                                                                                                                    // PaintPoly
  930.     MoveTo(170,29);
  931.     DrawString("\pPaintPoly (colour)");    
  932.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  933.     Delay(30,&finalTicks);
  934.  
  935.     OffsetPoly(polygonHdl,140,0);
  936.     FillCPoly(polygonHdl,fillPixpatHdl);                                                                                        // FillCPoly
  937.     MoveTo(310,29);
  938.     DrawString("\pFillCPoly (pixel pattern)");    
  939.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  940.     Delay(30,&finalTicks);
  941.  
  942.     OffsetPoly(polygonHdl,140,0);
  943.     ErasePoly(polygonHdl);                                                                                                                    // ErasePoly
  944.     MoveTo(450,29);
  945.     DrawString("\pErasePoly (bit pattern)");    
  946.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  947.     Delay(30,&finalTicks);
  948.     
  949.     FrameRgn(regionHdl);                                                                                                                         // FrameRgn
  950.     MoveTo(30,214);
  951.     DrawString("\pFrameRgn (colour)");    
  952.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  953.     Delay(30,&finalTicks);
  954.  
  955.     OffsetRgn(regionHdl,140,0);
  956.     PaintRgn(regionHdl);                                                                                                                         // PaintRgn
  957.     MoveTo(170,214);
  958.     DrawString("\pPaintRgn (colour)");    
  959.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  960.     Delay(30,&finalTicks);
  961.  
  962.     OffsetRgn(regionHdl,140,0);
  963.     FillCRgn(regionHdl,fillPixpatHdl);                                                                                             // FillCRgn
  964.     MoveTo(310,214);
  965.     DrawString("\pFillCRgn (pixel pattern)");    
  966.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  967.     Delay(30,&finalTicks);
  968.  
  969.     OffsetRgn(regionHdl,140,0);
  970.     EraseRgn(regionHdl);                                                                                                                         // EraseRgn
  971.     MoveTo(450,214);
  972.     DrawString("\pEraseRgn (bit pattern)");    
  973.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  974.     Delay(30,&finalTicks);
  975.  
  976.     KillPoly(polygonHdl);
  977.     DisposeRgn(regionHdl);
  978.     DisposePixPat(fillPixpatHdl);
  979.     BackPat(&whitePattern);    
  980.  
  981.     if(!gRunningOnX)
  982.         SetThemeCursor(kThemeArrowCursor);
  983. }
  984.  
  985. // ************************************************************************************ doText
  986.  
  987. void  doText(void)
  988. {
  989.     Rect        portRect, theRect;
  990.     Pattern    whitePattern;
  991.     SInt16    windowCentre, a, fontNum, stringWidth;
  992.     Str255    textString;
  993.     UInt32    finalTicks;
  994.         
  995.     RGBBackColor(&gWhiteColour);
  996.     GetWindowPortBounds(gWindowRef,&portRect);
  997.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));               
  998.  
  999.     SetWTitle(gWindowRef,"\pDrawing text with default source mode (srcOr)");
  1000.     
  1001.     windowCentre = (portRect.right - portRect.left) / 2;
  1002.     SetRect(&theRect,windowCentre,portRect.top,portRect.right,portRect.bottom);
  1003.     RGBBackColor(&gBlueColour);
  1004.     FillRect(&theRect,&whitePattern);
  1005.  
  1006.     if(!gRunningOnX)
  1007.         SetThemeCursor(kThemeWatchCursor);
  1008.  
  1009.     for(a=1;a<9;a++)
  1010.     {
  1011.         // ……………………………………………………………………… set various text fonts, text styles, and foreground colours
  1012.  
  1013.         if(a == 1)
  1014.         {
  1015.             GetFNum("\pGeneva",&fontNum);
  1016.             TextFont(fontNum);
  1017.             TextFace(normal);
  1018.             RGBForeColor(&gRedColour);
  1019.         }
  1020.         else if(a == 2)
  1021.             TextFace(bold);
  1022.         else if(a == 3)
  1023.         {
  1024.             GetFNum("\pTimes",&fontNum);
  1025.             TextFont(fontNum);
  1026.             TextFace(italic);
  1027.             RGBForeColor(&gYellowColour);
  1028.         }
  1029.         else if(a == 4)
  1030.             TextFace(underline);
  1031.         else if(a == 5)
  1032.         {
  1033.             GetFNum("\pHelvetica",&fontNum);
  1034.             TextFont(fontNum);
  1035.             TextFace(normal);
  1036.             RGBForeColor(&gGreenColour);
  1037.         }
  1038.         else if(a == 6)
  1039.             TextFace(bold + italic);
  1040.         else if(a == 7)
  1041.         {
  1042.             GetFNum("\pCharcoal",&fontNum);
  1043.             TextFont(fontNum);
  1044.             TextFace(condense);
  1045.             RGBForeColor(&gBlackColour);
  1046.         }
  1047.         else if(a == 8)
  1048.         {
  1049.             TextFace(extend);
  1050.         }
  1051.  
  1052.         // ………………………………………………………………………………………………………………………………………………………………………………………………… set text size
  1053.  
  1054.         if(a < 7)
  1055.             TextSize(a * 2 + 15);
  1056.         else
  1057.             TextSize(12);
  1058.             
  1059.         // ………………………… get a string and draw it in the set font, style, size, and foreground colour
  1060.  
  1061.         GetIndString(textString,rFontsStringList,a);
  1062.         stringWidth = StringWidth(textString);
  1063.         MoveTo(windowCentre - (stringWidth / 2),a * 46 - 10);
  1064.         DrawString(textString);
  1065.  
  1066.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1067.         Delay(30,&finalTicks);
  1068.     }
  1069.  
  1070.     // ………………………………………………………………………………………………………………………………………………………………… reset to Geneva 10pt normal
  1071.  
  1072.     GetFNum("\pGeneva",&fontNum);
  1073.     TextFont(fontNum);
  1074.     TextSize(10);
  1075.     TextFace(normal);
  1076.  
  1077.     // ……………………………… erase a rectangle, get a string, and use TETextBox to draw it left justified
  1078.  
  1079.     SetRect(&theRect,portRect.left + 5,portRect.bottom - 55,portRect.left + 118,
  1080.                     portRect.bottom - 5);
  1081.     EraseRect(&theRect);
  1082.     InsetRect(&theRect,5,5);
  1083.     GetIndString(textString,rFontsStringList,9);
  1084.     RGBForeColor(&gWhiteColour);
  1085.     TETextBox(&textString[1],textString[0],&theRect,teFlushLeft);
  1086.  
  1087.     if(!gRunningOnX)
  1088.         SetThemeCursor(kThemeArrowCursor);
  1089. }
  1090.  
  1091. // ******************************************************************************* doScrolling
  1092.  
  1093. void  doScrolling(void)
  1094. {
  1095.     Rect                    portRect, theRect;
  1096.     Pattern                whitePattern;
  1097.     PixPatHandle    pixpat1Hdl, pixpat2Hdl;
  1098.     RgnHandle            oldClipHdl, regionAHdl, regionBHdl, regionCHdl, scrollRegionHdl;
  1099.     SInt16                a;
  1100.     UInt32                finalTicks;
  1101.  
  1102.     SetWTitle(gWindowRef,"\pScrolling pixels");
  1103.  
  1104.     RGBBackColor(&gWhiteColour);
  1105.     GetWindowPortBounds(gWindowRef,&portRect);
  1106.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1107.  
  1108.     if(!gRunningOnX)
  1109.         SetThemeCursor(kThemeWatchCursor);
  1110.  
  1111.     if(!(pixpat1Hdl = GetPixPat(rPixelPattern1)))
  1112.         ExitToShell();
  1113.     PenPixPat(pixpat1Hdl);
  1114.     PenSize(50,0);
  1115.     SetRect(&theRect,30,30,286,371);
  1116.     FrameRect(&theRect);
  1117.     SetRect(&theRect,315,30,571,371);
  1118.     FillCRect(&theRect,pixpat1Hdl);
  1119.  
  1120.     if(!(pixpat2Hdl = GetPixPat(rPixelPattern2)))
  1121.         ExitToShell();    
  1122.     BackPixPat(pixpat2Hdl);
  1123.  
  1124.     regionAHdl = NewRgn();
  1125.     regionBHdl = NewRgn();
  1126.     regionCHdl = NewRgn();
  1127.     SetRect(&theRect,80,30,236,371);
  1128.     RectRgn(regionAHdl,&theRect);
  1129.     SetRect(&theRect,315,30,571,371);
  1130.     RectRgn(regionBHdl,&theRect);
  1131.     UnionRgn(regionAHdl,regionBHdl,regionCHdl);
  1132.  
  1133.     oldClipHdl = NewRgn();
  1134.     GetClip(oldClipHdl);
  1135.     SetClip(regionCHdl);
  1136.  
  1137.     SetRect(&theRect,80,30,571,371);
  1138.  
  1139.     scrollRegionHdl = NewRgn();
  1140.  
  1141.     for(a=0;a<371;a++)
  1142.     {
  1143.         ScrollRect(&theRect,0,1,scrollRegionHdl);
  1144.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1145.         theRect.top ++;
  1146.         Delay(1,&finalTicks);
  1147.     }
  1148.  
  1149.     SetRect(&theRect,80,30,571,371);
  1150.     BackPixPat(pixpat1Hdl);
  1151.  
  1152.     for(a=0;a<371;a++)
  1153.     {
  1154.         ScrollRect(&theRect,0,-1,scrollRegionHdl);
  1155.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1156.         theRect.bottom --;
  1157.         Delay(1,&finalTicks);
  1158.     }
  1159.  
  1160.     SetClip(oldClipHdl);
  1161.  
  1162.     DisposePixPat(pixpat1Hdl);
  1163.     DisposePixPat(pixpat2Hdl);
  1164.     DisposeRgn(oldClipHdl);
  1165.     DisposeRgn(regionAHdl);
  1166.     DisposeRgn(regionBHdl);
  1167.     DisposeRgn(regionCHdl);
  1168.     DisposeRgn(scrollRegionHdl);
  1169.  
  1170.     if(!gRunningOnX)
  1171.         SetThemeCursor(kThemeArrowCursor);
  1172. }
  1173.  
  1174. // ********************************************************************** doBooleanSourceModes
  1175.  
  1176. void  doBooleanSourceModes(void)
  1177. {
  1178.     Rect                    portRect, theRect;
  1179.     Pattern                whitePattern;
  1180.     Handle                destIconHdl, sourceIconHdl;
  1181.     SInt16                a, b;
  1182.     UInt32                finalTicks;
  1183.     BitMap                sourceIconMap;
  1184.     Str255                sourceString;
  1185.     PixMapHandle    destinationPixMapHdl;
  1186.  
  1187.     SetWTitle(gWindowRef,"\pBoolean source modes");
  1188.  
  1189.     RGBForeColor(&gBlackColour);
  1190.     RGBBackColor(&gGreenColour);
  1191.     GetWindowPortBounds(gWindowRef,&portRect);
  1192.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1193.     SetRect(&theRect,portRect.left,portRect.top,portRect.right,
  1194.                     (portRect.bottom - portRect.top) / 2);
  1195.     RGBBackColor(&gWhiteColour);
  1196.     FillRect(&theRect,&whitePattern);
  1197.     
  1198.     if(!gRunningOnX)
  1199.         SetThemeCursor(kThemeWatchCursor);
  1200.  
  1201.     destIconHdl = GetIcon(rDestinationIcon);
  1202.     sourceIconHdl = GetIcon(rSourceIcon);
  1203.  
  1204.     for(a=0;a<2;a++)
  1205.     {
  1206.         if(a == 1)
  1207.         {
  1208.             RGBForeColor(&gYellowColour);
  1209.             RGBBackColor(&gRedColour);
  1210.         }
  1211.  
  1212.         SetRect(&theRect,235,a * 191 + 30,299,a * 191 + 94);
  1213.         PlotIcon(&theRect,destIconHdl);
  1214.         MoveTo(235,a * 191 + 27);
  1215.         DrawString("\pDestination");
  1216.  
  1217.         SetRect(&theRect,304,a * 191 + 30,368,a * 191 + 94);
  1218.         PlotIcon(&theRect,sourceIconHdl);
  1219.         MoveTo(304,a * 191 + 27);
  1220.         DrawString("\pSource");
  1221.     }
  1222.  
  1223.     RGBForeColor(&gBlackColour);
  1224.     RGBBackColor(&gWhiteColour);
  1225.  
  1226.     for(a=0;a<2;a++)
  1227.     {
  1228.         if(a == 1)
  1229.         {
  1230.             RGBForeColor(&gYellowColour);
  1231.             RGBBackColor(&gRedColour);
  1232.         }
  1233.         
  1234.         for(b=0;b<8;b++)
  1235.         {
  1236.             SetRect(&theRect,b * 69 + 28,a * 191 + 121,b * 69 + 92,a * 191 + 185);
  1237.             PlotIcon(&theRect,destIconHdl);
  1238.         }
  1239.     }
  1240.  
  1241.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1242.  
  1243.     RGBForeColor(&gBlackColour);
  1244.     RGBBackColor(&gWhiteColour);
  1245.  
  1246.     HLock(sourceIconHdl);
  1247.     sourceIconMap.baseAddr = *sourceIconHdl;
  1248.     sourceIconMap.rowBytes = 4;
  1249.     SetRect(&sourceIconMap.bounds,0,0,32,32);
  1250.  
  1251.     destinationPixMapHdl = GetPortPixMap(GetQDGlobalsThePort());
  1252.  
  1253.     for(a=0;a<2;a++)
  1254.     {
  1255.         if(a == 1)
  1256.         {
  1257.             RGBForeColor(&gYellowColour);
  1258.             RGBBackColor(&gRedColour);
  1259.         }
  1260.         
  1261.         for(b=0;b<8;b++)
  1262.         {
  1263.             Delay(30,&finalTicks);
  1264.             SetRect(&theRect,b * 69 + 28,a * 191 + 121,b * 69 + 92,a * 191 + 185);
  1265.             CopyBits(&sourceIconMap,
  1266.                              (BitMap *) *destinationPixMapHdl,
  1267.                              &sourceIconMap.bounds,
  1268.                              &theRect,
  1269.                              b,NULL);
  1270.             GetIndString(sourceString,rBooleanStringList,b + 1);
  1271.             MoveTo(b * 69 + 28,a * 191 + 118);
  1272.             DrawString(sourceString);
  1273.  
  1274.             QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1275.         }
  1276.     }
  1277.  
  1278.     HUnlock(sourceIconHdl);
  1279.  
  1280.     if(!gRunningOnX)
  1281.         SetThemeCursor(kThemeArrowCursor);
  1282. }
  1283.  
  1284. // ******************************************************************* doArithmeticSourceModes
  1285.  
  1286. void  doArithmeticSourceModes(void)
  1287. {
  1288.     Rect                    portRect, sourceRect, destRect;
  1289.     Pattern                whitePattern;
  1290.     PicHandle            sourceHdl, destinationHdl;
  1291.     SInt16                a, b, arithmeticMode = 32;
  1292.     PixMapHandle    currentPixMapHdl;
  1293.     Str255                modeString;
  1294.     UInt32                finalTicks;
  1295.  
  1296.     SetWTitle(gWindowRef,"\pCopyBits with arithmetic source modes");
  1297.  
  1298.     RGBForeColor(&gBlackColour);
  1299.     RGBBackColor(&gWhiteColour);
  1300.     GetWindowPortBounds(gWindowRef,&portRect);
  1301.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1302.  
  1303.     if(!gRunningOnX)
  1304.         SetThemeCursor(kThemeWatchCursor);
  1305.  
  1306.     if(!(sourceHdl = GetPicture(rPicture)))
  1307.         ExitToShell();
  1308.     SetRect(&sourceRect,44,21,201,133);
  1309.     HNoPurge((Handle) sourceHdl);
  1310.     DrawPicture(sourceHdl,&sourceRect);
  1311.     HPurge((Handle) sourceHdl);
  1312.     MoveTo(44,19);
  1313.     DrawString("\pSOURCE IMAGE");
  1314.  
  1315.     if(!(destinationHdl = GetPicture(rPicture + 1)))
  1316.         ExitToShell();
  1317.     HNoPurge((Handle) destinationHdl);
  1318.     for(a=44;a<403;a+=179)
  1319.     {
  1320.         for(b=21;b<274;b+=126)
  1321.         {
  1322.             if(a == 44 && b == 21)
  1323.              continue;
  1324.             SetRect(&destRect,a,b,a+157,b+112);
  1325.             DrawPicture(destinationHdl,&destRect);
  1326.         }
  1327.     }
  1328.     HPurge((Handle) destinationHdl);
  1329.  
  1330.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1331.  
  1332.     currentPixMapHdl = GetPortPixMap(GetWindowPort(gWindowRef));
  1333.  
  1334.     for(a=44;a<403;a+=179)
  1335.     {
  1336.         for(b=21;b<274;b+=126)
  1337.         {
  1338.             if(a == 44 && b == 21)
  1339.              continue;
  1340.         
  1341.             Delay(60,&finalTicks);
  1342.  
  1343.             GetIndString(modeString,rArithmeticStringList,arithmeticMode - 31);
  1344.             MoveTo(a,b - 2);
  1345.             DrawString(modeString);
  1346.  
  1347.             SetRect(&destRect,a,b,a+157,b+112);
  1348.  
  1349.             CopyBits((BitMap *) *currentPixMapHdl,
  1350.                              (BitMap *) *currentPixMapHdl,
  1351.                              &sourceRect,&destRect,
  1352.                              arithmeticMode + ditherCopy,NULL);
  1353.  
  1354.             arithmeticMode ++;
  1355.  
  1356.             QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1357.         }
  1358.  
  1359.     }
  1360.  
  1361.     ReleaseResource((Handle) sourceHdl);
  1362.     ReleaseResource((Handle) destinationHdl);    
  1363.  
  1364.     if(!gRunningOnX)
  1365.         SetThemeCursor(kThemeArrowCursor);
  1366. }
  1367.  
  1368. // **************************************************************************** doHighlighting
  1369.  
  1370. void  doHighlighting(void)
  1371. {
  1372.     Rect            portRect, theRect;
  1373.     Pattern        whitePattern;
  1374.     RGBColor    oldHighlightColour;
  1375.     SInt16        a;
  1376.     UInt8            hiliteVal;
  1377.     UInt32        finalTicks;
  1378.  
  1379.     SetWTitle(gWindowRef,"\pHighlighting");
  1380.  
  1381.     RGBForeColor(&gBlackColour);
  1382.     RGBBackColor(&gWhiteColour);
  1383.     GetWindowPortBounds(gWindowRef,&portRect);
  1384.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1385.  
  1386.     LMGetHiliteRGB(&oldHighlightColour);
  1387.  
  1388.     for(a=0;a<3;a++)
  1389.     {
  1390.         MoveTo(50,a * 100 + 60);
  1391.         DrawString("\pClearing the highlight bit and calling InvertRect.");
  1392.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1393.         Delay(60,&finalTicks);
  1394.         SetRect(&theRect,44,a * 100 + 44,557,a * 100 + 104);
  1395.  
  1396.         hiliteVal = LMGetHiliteMode();
  1397.         BitClr(&hiliteVal,pHiliteBit);
  1398.         LMSetHiliteMode(hiliteVal);
  1399.  
  1400.         if(a == 1)
  1401.             HiliteColor(&gYellowColour);
  1402.         else if(a == 2)
  1403.             HiliteColor(&gGreenColour);
  1404.  
  1405.         InvertRect(&theRect);
  1406.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1407.  
  1408.         MoveTo(50,a * 100 + 75);
  1409.         Delay(60,&finalTicks);
  1410.         DrawString("\pClick mouse to unhighlight.  ");
  1411.         DrawString("\p(Note:  The call to InvertRect reset the highlight bit ...");
  1412.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1413.  
  1414.         while(!Button()) ;
  1415.  
  1416.         MoveTo(45,a * 100 + 90);
  1417.         DrawString("\p... so we clear the highlight bit again before calling InvertRect.)");
  1418.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1419.         Delay(60,&finalTicks);
  1420.  
  1421.         LMSetHiliteMode(hiliteVal);
  1422.  
  1423.         InvertRect(&theRect);    
  1424.         QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1425.     }
  1426.  
  1427.     HiliteColor(&oldHighlightColour);
  1428.  
  1429.     Delay(60,&finalTicks);
  1430.     MoveTo(50,350);
  1431.     DrawString("\pOriginal highlight colour has been reset.");
  1432.  
  1433.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1434. }
  1435.  
  1436. // *************************************************************************** doDrawWithMouse
  1437.  
  1438. void  doDrawWithMouse(void)
  1439. {
  1440.     Rect                    portRect, drawRect;
  1441.     Pattern                whitePattern, blackPattern;
  1442.     PixPatHandle    pixpatHdl;
  1443.     Point                    initialMouse, previousMouse, currentMouse;
  1444.     UInt16                randomNumber;
  1445.     RGBColor            theColour;
  1446.  
  1447.     RGBBackColor(&gWhiteColour);
  1448.     GetWindowPortBounds(gWindowRef,&portRect);
  1449.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1450.  
  1451.     if(!(pixpatHdl = GetPixPat(rPixelPattern3)))
  1452.         ExitToShell();
  1453.     PenPixPat(pixpatHdl);
  1454.     PenSize(1,1);
  1455.     PenMode(patXor);
  1456.  
  1457.     GetMouse(&initialMouse);                     
  1458.     drawRect.left = drawRect.right  = initialMouse.h;
  1459.     drawRect.top  = drawRect.bottom = initialMouse.v;
  1460.  
  1461.     GetMouse(&previousMouse);
  1462.  
  1463.     while(StillDown())
  1464.     {
  1465.         GetMouse(¤tMouse);
  1466.  
  1467.         if(currentMouse.v != previousMouse.v || currentMouse.h != previousMouse.h)
  1468.         {
  1469.             FrameRect(&drawRect);
  1470.  
  1471.             if(currentMouse.h >= initialMouse.h)
  1472.                 drawRect.right = currentMouse.h;
  1473.             if(currentMouse.v >= initialMouse.v)
  1474.                 drawRect.bottom = currentMouse.v;
  1475.             if(currentMouse.h <= initialMouse.h)
  1476.                 drawRect.left = currentMouse.h;
  1477.             if(currentMouse.v <= initialMouse.v)
  1478.                 drawRect.top = currentMouse.v;
  1479.             
  1480.             FrameRect(&drawRect);
  1481.         }
  1482.  
  1483.         previousMouse.v = currentMouse.v;
  1484.         previousMouse.h = currentMouse.h;
  1485.     }
  1486.  
  1487.     FrameRect(&drawRect);
  1488.  
  1489.     theColour.red   = doRandomNumber(0,65535);
  1490.     theColour.green = doRandomNumber(0,65535);
  1491.     theColour.blue  = doRandomNumber(0,65535);
  1492.     RGBForeColor(&theColour);
  1493.  
  1494.     PenMode(patCopy);
  1495.     PenPat(GetQDGlobalsBlack(&blackPattern));
  1496.     BackPixPat(pixpatHdl);
  1497.  
  1498.     randomNumber = doRandomNumber(0,3);
  1499.  
  1500.     if(randomNumber == 0)
  1501.         PaintRect(&drawRect);
  1502.     else if(randomNumber == 1)
  1503.         EraseRoundRect(&drawRect,50,50);    
  1504.     else if(randomNumber == 2)
  1505.         PaintOval(&drawRect);    
  1506.     else if(randomNumber == 3)
  1507.         PaintArc(&drawRect,0,doRandomNumber(0,360));    
  1508.  
  1509.     BackPat(&whitePattern);
  1510. }      
  1511.  
  1512. // *************************************************************************** doDrawingState
  1513.  
  1514. void  doDrawingState(void)
  1515. {
  1516.     Rect                            portRect, theRect;
  1517.     Pattern                        whitePattern;
  1518.     ThemeDrawingState    themeDrawingState;
  1519.     SInt16                        a;
  1520.     UInt32                        finalTicks;
  1521.     
  1522.     RGBBackColor(&gBlueColour);
  1523.     GetWindowPortBounds(gWindowRef,&portRect);
  1524.     FillRect(&portRect,GetQDGlobalsWhite(&whitePattern));
  1525.     SetWTitle(gWindowRef,"\pSaving and restoring the graphics port drawing state");
  1526.  
  1527.     if(!gRunningOnX)
  1528.         SetThemeCursor(kThemeWatchCursor);
  1529.  
  1530.     NormalizeThemeDrawingState();
  1531.  
  1532.     doDrawingStateProof(0);
  1533.     Delay(120,&finalTicks);
  1534.  
  1535.     GetThemeDrawingState(&themeDrawingState);
  1536.  
  1537.     theRect = portRect;
  1538.     theRect.right -= 300;
  1539.  
  1540.     SetThemeBackground(kThemeBrushListViewBackground,gPixelDepth,gIsColourDevice);
  1541.     EraseRect(&theRect);
  1542.  
  1543.     theRect.left += 150;
  1544.  
  1545.     SetThemeBackground(kThemeBrushListViewSortColumnBackground,gPixelDepth,gIsColourDevice);
  1546.     EraseRect(&theRect);
  1547.  
  1548.     SetThemePen(kThemeBrushListViewSeparator,gPixelDepth,gIsColourDevice);
  1549.  
  1550.     theRect.left -= 150;
  1551.     for(a=theRect.top;a<=theRect.bottom;a+=18)
  1552.     {
  1553.         MoveTo(theRect.left,a);
  1554.         LineTo(theRect.right - 1,a);
  1555.     }
  1556.  
  1557.     Delay(120,&finalTicks);    
  1558.     doDrawingStateProof(1);
  1559.     Delay(120,&finalTicks);    
  1560.  
  1561.     SetThemeDrawingState(themeDrawingState,true);
  1562.  
  1563.     doDrawingStateProof(2);
  1564.  
  1565.     if(!gRunningOnX)
  1566.         SetThemeCursor(kThemeArrowCursor);
  1567. }
  1568.  
  1569. // ********************************************************************** doDrawingStateProof
  1570.  
  1571. void  doDrawingStateProof(SInt16 phase)
  1572. {
  1573.     Rect    theRect;
  1574.  
  1575.     MoveTo(324,phase * 117 + 41);
  1576.     if(phase == 0)
  1577.         DrawString("\pBefore calls to SetThemePen and SetThemeBackground");
  1578.     else if(phase == 1)
  1579.         DrawString("\pAfter calls to SetThemePen and SetThemeBackground");
  1580.     else if(phase == 2)
  1581.         DrawString("\pAfter restoration of graphics port drawing state");
  1582.  
  1583.     MoveTo(324,phase * 117 + 54);
  1584.     DrawString("\pPen pattern/colour");
  1585.     MoveTo(462,phase * 117 + 54);
  1586.     DrawString("\pBackgrd pattern/colour");
  1587.  
  1588.     SetRect(&theRect,324,phase * 117 + 58,438,phase * 117 + 132);        
  1589.     PaintRect(&theRect);
  1590.     SetRect(&theRect,462,phase * 117 + 58,576,phase * 117 + 132);        
  1591.     EraseRect(&theRect);    
  1592.  
  1593.     QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
  1594. }
  1595.  
  1596. // *********************************************************************** doGetDepthAndDevice
  1597.  
  1598. void doGetDepthAndDevice(void)
  1599. {
  1600.     GDHandle    deviceHdl;
  1601.  
  1602.     deviceHdl = GetMainDevice();
  1603.     gPixelDepth = (*(*deviceHdl)->gdPMap)->pixelSize;
  1604.     if(((1 << gdDevType) & (*deviceHdl)->gdFlags) != 0)
  1605.         gIsColourDevice = true;
  1606. }
  1607.  
  1608. // **************************************************************************** doRandomNumber
  1609.  
  1610. UInt16  doRandomNumber(UInt16 minimum,UInt16 maximum)
  1611. {
  1612.     UInt16    randomNumber;
  1613.     SInt32    range, t;
  1614.  
  1615.     randomNumber = Random();
  1616.     range = maximum - minimum + 1;
  1617.     t = (randomNumber * range) / 65536;
  1618.     return (t + minimum);
  1619. }
  1620.  
  1621. // *******************************************************************************************