home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-pascal / macintoshp-1.2-demos.sit.hqx / chap12pascal_demo / GWorldPicCursIconPascal.p < prev    next >
Text File  |  1999-04-05  |  20KB  |  879 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // GWorldPicCursIconPascal.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. // 
  5. // This program:
  6. //
  7. // •   Opens a window in which the results of various drawing operations are displayed, 
  8. //       and in which regions are established for a cursor shape change demonstration.
  9. //
  10. // •   Demonstrates offscreen graphics world, picture, cursor, animated cursor, and icon
  11. //       operations as a result of the user choosing items from a Demonstration menu.
  12. //
  13. // •   Quits when the user chooses Quit or clicks the window's close box.
  14. //
  15. // The program utilizes the following resources:
  16. //
  17. // •   'MBAR' resource and associated 'MENU' resources (preload, non-purgeable).
  18. //
  19. // •   A 'WIND' resource (purgeable) (initially visible). 
  20. //
  21. // •   An 'acur' resource (purgeable).
  22. //
  23. // •   'CURS' resources associated with the 'acur' resource (purgeable).
  24. //
  25. // •   An 'ALRT' resource (purgeable) and associated 'DITL' resource (purgeable) for an
  26. //       About GWorldPicCursIcon… alert box, which is used to demonstrate the display of
  27. //       icons in alert boxes.
  28. //
  29. // •   'ICON', 'cicn', and 'SICN' resources (purgeable) for the display of icons in menu
  30. //       items and the About GWorldPicCursIcon… alert box.
  31. //
  32. // •   A 'SIZE' resource with the acceptSuspendResumeEvents & is32BitCompatible flags set.
  33. //
  34. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  35.  
  36. program GWorldPicCursIconPascal(input, output);
  37.  
  38. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  39.  
  40. uses
  41.  
  42.     Windows, Fonts, Menus, TextEdit, Quickdraw, Dialogs, QuickdrawText, Processes, Types, 
  43.     Memory, Events, TextUtils, ToolUtils, OSUtils, Devices, QDOffscreen, Resources, Icons,
  44.     GestaltEqu, PictUtils, SegLoad, Sound;
  45.  
  46. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  47.  
  48. const
  49.  
  50. mApple = 128;
  51.     iAbout = 1;
  52. mFile = 129;
  53.     iQuit = 11;
  54. mDemonstration = 131;
  55.     iWithoutOffScreenGWorld = 1;
  56.     iWithOffScreenGWorld = 2;
  57.     iPicture = 3;
  58.     iCursor = 4;
  59.     iAnimatedCursor = 5;
  60.     iIcon = 6;
  61.  
  62. rAlert = 128;
  63. rMenubar = 128;
  64. rWindow = 128;
  65. rBeachBallCursor = 128;
  66. rIcon = 257;
  67.  
  68. kBeachBallTickInterval = 5;
  69.  
  70. kMaxLong = $7FFFFFFF;
  71.  
  72. { ……………………………………………………………………………………………………………………………………………………………………………………… type definitions }
  73.  
  74. type
  75.  
  76. animCurs = record
  77.     numberOfFrames : integer;
  78.     whichFrame : integer;
  79.     frame : array [0..8] of CursHandle;
  80.     end;
  81. animCursPtr = ^animCurs;
  82. animCursHandle = ^animCursPtr;
  83.  
  84. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  85.  
  86. var
  87.  
  88. gDone : boolean;
  89. gWindowPtr : WindowPtr;
  90. gSleepTime : longint;
  91. gCursorRegion : RgnHandle;
  92. gInBackground : boolean;
  93. gCursorRegionsActive : boolean;
  94. gAnimCursHdl : animCursHandle;
  95. gAnimCursActive : boolean;
  96. gAnimCursTickInterval : integer;
  97. gAnimCursLastTick : longint;
  98. menubarHdl : Handle;
  99. menuHdl : MenuHandle;
  100.  
  101. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  102.  
  103. procedure DoInitManagers;
  104.  
  105.     begin
  106.     MaxApplZone;
  107.     MoreMasters;
  108.  
  109.     InitGraf(@qd.thePort);
  110.     InitFonts;
  111.     InitWindows;
  112.     InitMenus;
  113.     TEInit;
  114.     InitDialogs(nil);
  115.  
  116.     InitCursor;    
  117.     FlushEvents(everyEvent, 0);
  118.     end;
  119.         {of procedure DoInitManagers}
  120.  
  121. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoIcon }
  122.  
  123. procedure DoIcon;
  124.  
  125.     var
  126.     theErr : OSErr;
  127.     response : longint;
  128.     finalTicks : UInt32;
  129.     a : integer;
  130.     theRect : Rect;
  131.     iconHdl : Handle;
  132.     cIconHdl : CIconHandle;
  133.  
  134.     begin
  135.     BackColor(whiteColor);
  136.     FillRect(gWindowPtr^.portRect, qd.white);
  137.  
  138.     SetRect(theRect, 2, 130, 34, 162);
  139.     
  140.     theErr := Gestalt(gestaltQuickdrawVersion, response);
  141.     if (response < gestalt8BitQD)
  142.         then    begin
  143.                 iconHdl := GetIcon(257);
  144.                 for a := 1 to 19 do
  145.                     begin
  146.                     PlotIcon(theRect, iconHdl);    
  147.                     InsetRect(theRect, a*(-1), a*(-2));
  148.                     OffsetRect(theRect, a*4, 0);
  149.                     Delay(20, finalTicks);
  150.                     end
  151.                 end
  152.         else    begin
  153.                 cIconHdl := GetCIcon(257);
  154.                 for a := 1 to 19 do
  155.                     begin
  156.                     PlotCIcon(theRect, cIconHdl);    
  157.                     InsetRect(theRect, a*(-1), a*(-2));
  158.                     OffsetRect(theRect, a*4, 0);
  159.                     Delay(20, finalTicks);
  160.                     end;
  161.                 DisposeCIcon(cIconHdl);
  162.                 end;
  163.     end;
  164.         {of procedure DoIcon}
  165.  
  166. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ ReleaseAnimCursor }
  167.  
  168. procedure ReleaseAnimCursor;
  169.  
  170.     var
  171.     a : integer;
  172.  
  173.     begin
  174.     for a := 0 to (gAnimCursHdl^^.numberOfFrames - 1) do 
  175.         ReleaseResource(Handle(gAnimCursHdl^^.frame[a]));
  176.  
  177.     ReleaseResource(Handle(gAnimCursHdl));
  178.     end;
  179.         {of procedure ReleaseAnimCursor}
  180.  
  181. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SpinAnimCursor }
  182.  
  183. procedure SpinAnimCursor;
  184.  
  185.     var
  186.     newTick : longint;
  187.  
  188.     begin
  189.     newTick := TickCount;
  190.     if (newTick < (gAnimCursLastTick + gAnimCursTickInterval)) then
  191.         Exit(SpinAnimCursor);
  192.  
  193.     SetCursor(gAnimCursHdl^^.frame[gAnimCursHdl^^.whichFrame]^^);
  194.     gAnimCursHdl^^.whichFrame := gAnimCursHdl^^.whichFrame + 1;
  195.     if (gAnimCursHdl^^.whichFrame = gAnimCursHdl^^.numberOfFrames) then
  196.         gAnimCursHdl^^.whichFrame := 0;
  197.  
  198.     gAnimCursLastTick := newTick;
  199.     end;
  200.         {of procedure SpinAnimCursor}
  201.  
  202. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetAnimCursor }
  203.  
  204. function GetAnimCursor(resourceID, tickInterval : integer) : boolean;
  205.  
  206.     var
  207.     cursorID, a : integer;
  208.     noError : boolean;
  209.  
  210.     begin
  211.     noError := false;
  212.     a := 0;
  213.     
  214.     gAnimCursHdl := animCursHandle(GetResource('acur', resourceID));
  215.     if (gAnimCursHdl <> nil) then
  216.         begin
  217.         noError := true;
  218.         while ((a < gAnimCursHdl^^.numberOfFrames)  and noError) do
  219.             begin
  220.             cursorID := integer(HiWord(longint(gAnimCursHdl^^.frame[a])));
  221.             gAnimCursHdl^^.frame[a] := GetCursor(cursorID);
  222.             if (gAnimCursHdl^^.frame[a] <> nil)
  223.                 then a := a + 1
  224.                 else noError := false;
  225.             end;
  226.         end;
  227.  
  228.     if (noError) then
  229.         begin
  230.         gAnimCursTickInterval := tickInterval;
  231.         gAnimCursLastTick := TickCount;
  232.         gAnimCursHdl^^.whichFrame := 0;
  233.         end;
  234.  
  235.     GetAnimCursor := noError;
  236.     end;
  237.         {of function GetAnimCursor}
  238.  
  239. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAnimCursor }
  240.  
  241. procedure DoAnimCursor;
  242.  
  243.     var
  244.     animCursResourceID, animCursTickInterval : integer;
  245.  
  246.     begin
  247.     BackColor(whiteColor);
  248.     FillRect(gWindowPtr^.portRect, qd.white);
  249.  
  250.     animCursResourceID     := rBeachBallCursor;
  251.     animCursTickInterval := kBeachBallTickInterval;
  252.  
  253.     if (GetAnimCursor(animCursResourceID, animCursTickInterval))
  254.         then    begin
  255.                 gAnimCursActive := true;
  256.                 gSleepTime := animCursTickInterval;
  257.                 end    
  258.         else    SysBeep(10);
  259.     end;
  260.         {of procedure DoAnimCursor}
  261.  
  262. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ ChangeCursor }
  263.  
  264. procedure ChangeCursor(gWindowPtr : WindowPtr; cursorRegion : RgnHandle);
  265.  
  266.     var
  267.     cursorRect : Rect;
  268.     arrowCursorRgn : RgnHandle;
  269.     ibeamCursorRgn : RgnHandle;
  270.     crossCursorRgn : RgnHandle;
  271.     plusCursorRgn : RgnHandle;
  272.     mousePosition : Point;
  273.  
  274.     begin
  275.     arrowCursorRgn := NewRgn;
  276.     ibeamCursorRgn := NewRgn;    
  277.     crossCursorRgn := NewRgn;
  278.     plusCursorRgn     := NewRgn;
  279.  
  280.     SetRectRgn(arrowCursorRgn, -32768, -32768, 32766, 32766);
  281.  
  282.     cursorRect := gWindowPtr^.portRect;
  283.     LocalToGlobal(cursorRect.topLeft);
  284.     LocalToGlobal(cursorRect.botRight);    
  285.  
  286.     InsetRect(cursorRect, 40, 40);
  287.     RectRgn(ibeamCursorRgn, cursorRect);
  288.     DiffRgn(arrowCursorRgn, ibeamCursorRgn, arrowCursorRgn);
  289.  
  290.     InsetRect(cursorRect, 40, 40);
  291.     RectRgn(crossCursorRgn, cursorRect);
  292.     DiffRgn(ibeamCursorRgn, crossCursorRgn, ibeamCursorRgn);
  293.     
  294.     InsetRect(cursorRect, 40, 40);
  295.     RectRgn(plusCursorRgn, cursorRect);
  296.     DiffRgn(crossCursorRgn, plusCursorRgn, crossCursorRgn);
  297.  
  298.     GetMouse(mousePosition);
  299.     LocalToGlobal(mousePosition);
  300.  
  301.     if (PtInRgn(mousePosition, ibeamCursorRgn)) then
  302.         begin
  303.         SetCursor(GetCursor(iBeamCursor)^^);
  304.         CopyRgn(ibeamCursorRgn, cursorRegion);
  305.         end
  306.     else if (PtInRgn(mousePosition, crossCursorRgn)) then
  307.         begin
  308.         SetCursor(GetCursor(crossCursor)^^);
  309.         CopyRgn(crossCursorRgn, cursorRegion);
  310.         end
  311.     else if (PtInRgn(mousePosition, plusCursorRgn)) then
  312.         begin
  313.         SetCursor(GetCursor(plusCursor)^^);
  314.         CopyRgn(plusCursorRgn, cursorRegion);
  315.         end
  316.     else
  317.         begin
  318.         SetCursor(qd.arrow);
  319.         CopyRgn(arrowCursorRgn, cursorRegion);
  320.         end;
  321.  
  322.     DisposeRgn(arrowCursorRgn);
  323.     DisposeRgn(ibeamCursorRgn);
  324.     DisposeRgn(crossCursorRgn);
  325.     DisposeRgn(plusCursorRgn);
  326.     end;
  327.         {of procedure ChangeCursor}
  328.  
  329. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCursor }
  330.  
  331. procedure DoCursor;
  332.  
  333.     var
  334.     cursorRect : Rect;
  335.     a : integer;
  336.  
  337.     begin
  338.     BackColor(whiteColor);
  339.     FillRect(gWindowPtr^.portRect, qd.white);
  340.  
  341.     cursorRect := gWindowPtr^.portRect;
  342.     PenPat(qd.gray);
  343.     PenSize(1, 1);
  344.     ForeColor(redColor);
  345.  
  346.     for a := 0 to 2 do
  347.         begin
  348.         InsetRect(cursorRect, 40, 40);
  349.         FrameRect(cursorRect);
  350.         end;
  351.  
  352.     MoveTo(10, 20);
  353.     DrawString('Arrow cursor region');
  354.     MoveTo(50, 60);
  355.     DrawString('IBeam cursor region');
  356.     MoveTo(90, 100);
  357.     DrawString('Cross cursor region');
  358.     MoveTo(130, 140);
  359.     DrawString('Plus cursor region');
  360.  
  361.     gCursorRegionsActive := true;
  362.     gCursorRegion := NewRgn;
  363.     end;
  364.         {of procedure DoCursor}
  365.  
  366. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPicture }
  367.  
  368. procedure DoPicture;
  369.  
  370.     var
  371.     pictureRect : Rect;    
  372.     picParams : OpenCPicParams;
  373.     pictureHdl : PicHandle;
  374.     trianglePoly : PolyHandle;
  375.     pictureInfo : PictInfo;
  376.     pictInfoString : string;
  377.     ignored : OSErr;
  378.  
  379.     begin
  380.     BackColor(whiteColor);
  381.     FillRect(gWindowPtr^.portRect, qd.white);
  382.  
  383.     pictureRect := gWindowPtr^.portRect;
  384.     InsetRect(pictureRect, 50, 50);
  385.  
  386.     picParams.srcRect := pictureRect;
  387.     picParams.hRes := $00480000;
  388.     picParams.vRes := $00480000;
  389.     picParams.version := -2;
  390.  
  391.     pictureHdl := OpenCPicture(picParams);
  392.  
  393.     ClipRect(gWindowPtr^.portRect);
  394.  
  395.     ForeColor(blueColor);
  396.     FillRect(pictureRect, qd.dkGray);    
  397.     ForeColor(yellowColor);
  398.     FillOval(pictureRect, qd.gray);
  399.  
  400.     trianglePoly := OpenPoly;
  401.     MoveTo(pictureRect.left, pictureRect.bottom);
  402.     LineTo(trunc(pictureRect.left + ((pictureRect.right - pictureRect.left) / 2)),
  403.                      pictureRect.top);
  404.     LineTo(pictureRect.right, pictureRect.bottom);
  405.     ClosePoly;
  406.  
  407.     PenPat(qd.black);
  408.     ForeColor(redColor);
  409.     PaintPoly(trianglePoly);
  410.     KillPoly(trianglePoly);
  411.  
  412.     ForeColor(blackColor);
  413.     TextSize(30);
  414.     TextFont(systemFont);
  415.     MoveTo(115, 230);
  416.     DrawString('Recorded Picture');
  417.     ForeColor(whiteColor);
  418.     MoveTo(112, 227);
  419.     DrawString('Recorded Picture');
  420.  
  421.     ClosePicture;
  422.  
  423.     DrawPicture(pictureHdl, pictureRect);
  424.  
  425.     SetWTitle(gWindowPtr, 'Click Mouse for Picture Information');
  426.  
  427.     while not (Button) do ;
  428.  
  429.     FillRect(gWindowPtr^.portRect, qd.white);
  430.     SetWTitle(gWindowPtr, 'Offscreen Graphics Worlds, Pictures and Cursors');
  431.  
  432.     TextFont(1);
  433.     TextSize(10);
  434.  
  435.     ignored := GetPictInfo(pictureHdl, pictureInfo, returnPalette, 8, systemMethod, 0);
  436.     ForeColor(blackColor);
  437.     MoveTo(180, 50);
  438.     DrawString('Some Picture Information:');
  439.  
  440.     MoveTo(180, 80);
  441.     DrawString('TextStrings: ');
  442.     NumToString(pictureInfo.textCount, pictInfoString);
  443.     DrawString(pictInfoString);
  444.  
  445.     MoveTo(180, 95);
  446.     DrawString('Rectangles: ');
  447.     NumToString(pictureInfo.rectCount, pictInfoString);
  448.     DrawString(pictInfoString);
  449.  
  450.     MoveTo(180, 110);
  451.     DrawString('Round Rectangles: ');
  452.     NumToString(pictureInfo.rRectCount, pictInfoString);
  453.     DrawString(pictInfoString);
  454.  
  455.     MoveTo(180, 125);
  456.     DrawString('Ovals: ');
  457.     NumToString(pictureInfo.ovalCount, pictInfoString);
  458.     DrawString(pictInfoString);
  459.  
  460.     MoveTo(180, 140);
  461.     DrawString('Arcs: ');
  462.     NumToString(pictureInfo.arcCount, pictInfoString);
  463.     DrawString(pictInfoString);
  464.  
  465.     MoveTo(180, 155);
  466.     DrawString('Polygons: ');
  467.     NumToString(pictureInfo.polyCount, pictInfoString);
  468.     DrawString(pictInfoString);
  469.  
  470.     MoveTo(180, 170);
  471.     DrawString('Unique Fonts: ');
  472.     NumToString(pictureInfo.uniqueFonts, pictInfoString);
  473.     DrawString(pictInfoString);
  474.  
  475.     KillPicture(pictureHdl);
  476.  
  477.     TextFont(1);
  478.     TextSize(10);
  479.     
  480.     end;
  481.         {of procedure DoPicture}
  482.  
  483. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoGWorldDrawing }
  484.  
  485. procedure DoGWorldDrawing;
  486.  
  487.     var
  488.     a, b, c, i, j : integer;
  489.     theRect : Rect;
  490.  
  491.     begin
  492.     PenPat(qd.black);
  493.     PenSize(1, 1);
  494.  
  495.     for a := 0 to 7 do
  496.         for i := 0 to 15 do
  497.             begin
  498.             b := i * 30 + 12;
  499.             for j := 0 to 15 do
  500.                 begin
  501.                 c := j * 18 + 5;
  502.                 SetRect(theRect, b+a, c+a, b+28-a, c+16-a);
  503.                 if (a < 3)
  504.                     then     ForeColor(redColor)
  505.                     else     if ((a > 2) and (a < 6)) 
  506.                                 then     ForeColor(greenColor)
  507.                                 else     if(a > 5) then
  508.                                             ForeColor(blueColor);
  509.                 FrameRect(theRect);
  510.                 end;
  511.                     {of j-for loop}
  512.             end;
  513.                 {of i-for loop}
  514.     end;
  515.         {of procedure DoGWorldDrawing}
  516.  
  517. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoWithoutOffScreenGWorld }
  518.  
  519. procedure DoWithoutOffScreenGWorld;
  520.  
  521.     begin
  522.     BackColor(whiteColor);
  523.     FillRect(gWindowPtr^.portRect, qd.white);
  524.  
  525.     DoGWorldDrawing;
  526.     end;
  527.         {of procedure DoWithoutOffScreenGWorld}
  528.  
  529. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoWithOffScreenGWorld }
  530.  
  531. procedure DoWithOffScreenGWorld;
  532.  
  533.     var
  534.     windowPortPtr : CGrafPtr;
  535.     deviceHdl : GDHandle;
  536.     quickDrawErr : QDErr;
  537.     gworldPortPtr : GWorldPtr;
  538.     gworldPixMapHdl : PixMapHandle;
  539.     lockPixResult : boolean;
  540.     sourceRect, destRect : Rect;    
  541.  
  542.     begin
  543.     BackColor(whiteColor);
  544.     FillRect(gWindowPtr^.portRect, qd.white);
  545.  
  546.     ForeColor(blackColor);
  547.     MoveTo(130, 140);
  548.     DrawString('Please Wait.  Drawing in offscreen graphics port.');    
  549.  
  550.     SetCursor(GetCursor(watchCursor)^^);
  551.  
  552.     GetGWorld(windowPortPtr, deviceHdl);
  553.  
  554.     quickDrawErr := NewGWorld(gworldPortPtr, 0, gWindowPtr^.portRect, nil, nil, 0);
  555.     if ((gworldPortPtr = nil) or (quickDrawErr <> noErr)) then
  556.         begin
  557.         SysBeep(10);
  558.         Exit(DoWithOffScreenGWorld);
  559.         end;
  560.  
  561.     SetGWorld(gworldPortPtr, nil);
  562.  
  563.     gworldPixMapHdl := GetGWorldPixMap(gworldPortPtr);
  564.     
  565.     lockPixResult := LockPixels(gworldPixMapHdl);
  566.     if not (lockPixResult) then
  567.         begin
  568.         SysBeep(10);
  569.         Exit(DoWithOffScreenGWorld);
  570.         end;
  571.  
  572.     EraseRect(gworldPortPtr^.portRect);    
  573.  
  574.     DoGWorldDrawing;
  575.  
  576.     SetGWorld(windowPortPtr, deviceHdl);
  577.  
  578.     sourceRect := gworldPortPtr^.portRect;
  579.     destRect := windowPortPtr^.portRect;
  580.  
  581.     CopyBits(GrafPtr(gworldPortPtr)^.portBits, GrafPtr(windowPortPtr)^.portBits, 
  582.                      sourceRect, destRect, srcCopy, nil);
  583.  
  584.     if (QDError <> noErr) then
  585.         SysBeep(10);
  586.  
  587.     UnlockPixels(gworldPixMapHdl);
  588.     DisposeGWorld(gworldPortPtr);    
  589.  
  590.     SetCursor(qd.arrow);
  591.     
  592.     end;
  593.         {of procedure DoWithOffScreenGWorld}
  594.  
  595. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoIdle }
  596.  
  597. procedure DoIdle;
  598.  
  599.     begin
  600.     if (gAnimCursActive = true) then
  601.         SpinAnimCursor;
  602.     end;
  603.         {of procedure DoIdle}
  604.  
  605. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDemonstrationMenu }
  606.  
  607. procedure DoDemonstrationMenu(menuItem : integer);
  608.  
  609.     begin
  610.     case (menuItem) of
  611.     
  612.         iWithoutOffScreenGWorld:
  613.             begin
  614.             DoWithoutOffScreenGWorld;
  615.             end;            
  616.  
  617.         iWithOffScreenGWorld:
  618.             begin
  619.             DoWithOffScreenGWorld;
  620.             end;
  621.  
  622.         iPicture:
  623.             begin
  624.             DoPicture;
  625.             end;
  626.  
  627.         iCursor:
  628.             begin
  629.             DoCursor;
  630.             end;
  631.  
  632.         iAnimatedCursor:
  633.             begin
  634.             DoAnimCursor;
  635.             end;
  636.  
  637.         iIcon:
  638.             begin
  639.             DoIcon;
  640.             end;
  641.         end;
  642.             {of case statement}
  643.     end;
  644.          {of procedure DoDemonstrationMenu}
  645.  
  646. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  647.  
  648. procedure DoMenuChoice(menuChoice : longint);
  649.  
  650.     var
  651.     menuID, menuItem : integer;
  652.     itemName : string;
  653.     daDriverRefNum : integer;
  654.     ignored : OSErr;
  655.  
  656.     begin
  657.     menuID := HiWord(menuChoice);
  658.     menuItem := LoWord(menuChoice);
  659.  
  660.     if (menuID = 0) then
  661.         Exit(DoMenuChoice);
  662.  
  663.     if (gAnimCursActive = true) then
  664.         begin
  665.         gAnimCursActive := false;
  666.         SetCursor(qd.arrow);
  667.         ReleaseAnimCursor;
  668.         gSleepTime := kMaxLong;
  669.         end;
  670.         
  671.     if (gCursorRegionsActive = true) then
  672.         begin
  673.         gCursorRegionsActive := false;
  674.         DisposeRgn(gCursorRegion);
  675.         gCursorRegion := nil;
  676.         end;
  677.  
  678.     case (menuID) of
  679.     
  680.         mApple:
  681.             begin
  682.             if (menuItem = iAbout)
  683.                 then     ignored := Alert(rAlert, nil)
  684.                 else     begin
  685.                         GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  686.                         daDriverRefNum := OpenDeskAcc(itemName);
  687.                         end;
  688.             end;
  689.  
  690.         mFile:
  691.             begin
  692.             if (menuItem = iQuit) then
  693.                 gDone := true;
  694.             end;
  695.  
  696.         mDemonstration:
  697.             begin
  698.             DoDemonstrationMenu(menuItem);
  699.             end;
  700.         end;
  701.             {of case statement}
  702.     
  703.     HiliteMenu(0);
  704.     end;
  705.         {of procedure DoMenuChoice}
  706.  
  707. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
  708.  
  709. procedure DoOSEvent(var eventRec : EventRecord);
  710.  
  711.     begin
  712.     case (BAnd(BSR(eventRec.message, 24), $000000FF)) of
  713.  
  714.         suspendResumeMessage:
  715.             begin
  716.             if (BAnd(eventRec.message, resumeFlag) = 1)
  717.                 then gInBackground := false
  718.                 else gInBackground := true;
  719.             end;
  720.                 
  721.         mouseMovedMessage:
  722.             begin
  723.             if (gCursorRegionsActive) then
  724.                 ChangeCursor(gWindowPtr, gCursorRegion);
  725.             end;
  726.         end;
  727.             {of case statement}
  728.     end;
  729.         {of procedure DoOSEvent}
  730.  
  731. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  732.  
  733. procedure DoMouseDown(var eventRec : EventRecord);
  734.  
  735.     var
  736.     theWindowPtr : WindowPtr;
  737.     partCode : integer;
  738.  
  739.     begin
  740.     partCode := FindWindow(eventRec.where, theWindowPtr);
  741.  
  742.     case (partCode) of
  743.  
  744.         inMenuBar:
  745.             begin
  746.             DoMenuChoice(MenuSelect(eventRec.where));
  747.             end;
  748.  
  749.         inSysWindow:
  750.             begin
  751.             SystemClick(eventRec, theWindowPtr);
  752.             end;
  753.  
  754.         inContent:
  755.             begin
  756.             if (theWindowPtr <> FrontWindow) then
  757.                 SelectWindow(theWindowPtr);
  758.             end;
  759.  
  760.         inDrag:
  761.             begin
  762.             DragWindow(theWindowPtr, eventRec.where, qd.screenBits.bounds);
  763.             end;
  764.  
  765.         inGoAway:
  766.             begin
  767.             if (TrackGoAway(theWindowPtr, eventRec.where)) then
  768.                 gDone := true;
  769.             end;
  770.         end;
  771.             {of case statement}
  772.     end;
  773.         {of procedure DoMouseDown}
  774.  
  775. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  776.  
  777. procedure DoEvents(var eventRec : EventRecord);
  778.  
  779.     var        
  780.     theWindowPtr : WindowPtr;
  781.     charCode : char;
  782.  
  783.     begin
  784.     theWindowPtr := WindowPtr(eventRec.message);
  785.     
  786.     case (eventRec.what) of
  787.     
  788.         mouseDown:
  789.             begin
  790.             DoMouseDown(eventRec);
  791.             end;
  792.  
  793.         keyDown, autoKey:
  794.             begin
  795.             charCode := chr(BAnd(eventRec.message, charCodeMask));
  796.             if (BAnd(eventRec.modifiers, cmdKey) <> 0) then
  797.                 DoMenuChoice(MenuKey(charCode));
  798.             end;
  799.         
  800.         updateEvt:
  801.             begin
  802.             BeginUpdate(theWindowPtr);
  803.             EndUpdate(theWindowPtr);
  804.             end;
  805.  
  806.         osEvt:
  807.             begin
  808.             DoOSEvent(eventRec);
  809.             end;
  810.             
  811.         end;
  812.             {of case statement}
  813.     end;
  814.         {of procedure DoEvents}
  815.     
  816. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ EventLoop }
  817.  
  818. procedure EventLoop;
  819.  
  820.     var
  821.     eventRec : EventRecord;
  822.     gotEvent : boolean;
  823.  
  824.     begin
  825.     gDone := false;
  826.     gSleepTime := kMaxLong;
  827.     gCursorRegion := nil;
  828.     
  829.     while not (gDone) do
  830.         begin
  831.         gotEvent := WaitNextEvent(everyEvent, eventRec, gSleepTime, gCursorRegion);
  832.         if (gotEvent)
  833.             then DoEvents(eventRec)
  834.             else DoIdle;
  835.         end;
  836.     end;
  837.         {of procedure EventLoop}
  838.  
  839. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  840.  
  841. begin
  842.  
  843. gCursorRegionsActive := false;
  844. gAnimCursActive := false;
  845.  
  846.     { …………………………………………………………………………………………………………………………………………………………………… initialize managers }
  847.  
  848.     DoInitManagers;
  849.  
  850.     { …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
  851.     
  852.     menubarHdl := GetNewMBar(rMenubar);
  853.     if (menubarHdl = nil) then
  854.         ExitToShell;
  855.     SetMenuBar(menubarHdl);
  856.     DrawMenuBar;
  857.     menuHdl := GetMenuHandle(mApple);
  858.     if (menuHdl = nil) 
  859.         then ExitToShell
  860.         else AppendResMenu(menuHdl, 'DRVR');
  861.  
  862.     { ………………………………………………………………………………………………………………………………………………………………………………………… open window }
  863.  
  864.     gWindowPtr := GetNewWindow(rWindow, nil, WindowPtr(-1));
  865.     if (gWindowPtr = nil) then
  866.         ExitToShell;
  867.  
  868.     SetPort(gWindowPtr);
  869.     TextSize(10);
  870.  
  871.     { …………………………………………………………………………………………………………………………………………………………………………… enter event loop }
  872.  
  873.     EventLoop;
  874.  
  875. end.
  876.     {of main program}
  877.     
  878. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  879.