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 / chap23pascal_demo / chap19pascal_demoPPC / CDEFandVBLPascalPPC.p < prev    next >
Text File  |  1997-01-21  |  18KB  |  714 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // CDEFandVBLPascal.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. //
  5. // This program opens a window containing a slider control panel.  The slider control
  6. // panel contains two radio button controls and a slider control.  The radio buttons
  7. // activate and deactivate the slider control.  
  8. //
  9. // The slider control uses a custom control definition function (CDEF).  The CDEF 
  10. // utilises a VBL task to delay the drawing of a moved indicator in the graphics port 
  11. // until the vertical blank period is entered.  The radio buttons also use a custom CDEF.
  12. // On colour or grayscale displays, the appearance of the controls conforms to that 
  13. // specified in the document Apple Grayscale Appearance for System 7.5 published by Apple
  14. // Computer, Inc.
  15. //
  16. // This program also includes a demonstration of an animated cursor which utilises a 
  17. // system-based VBL task to increment the frames of the animation.  This demonstration
  18. // is invoked by choosing the VBL Task Animated Cursor item in the Demonstration menu.
  19. //
  20. // The program utilises the following resources:
  21. //
  22. // •   An 'MBAR' resource, and 'MENU' resources for Apple, File, Edit and Demonstration
  23. //       menus (preload, non-purgeable).
  24. //
  25. // •   A 'WIND' resource (purgeable) (initially visible) and a 'wctb' resource (purgeable)
  26. //       for the window containing the slider control panel.  
  27. //
  28. // •   'CNTL' resources  (purgeable) for the radio button and slider controls.
  29. //
  30. // •   The 'CDEF' code resources (non-purgeable).
  31. //
  32. // •   An 'acur' resource (purgeable) and 'CURS' resources (purgeable) for the animated
  33. //       cursor.
  34. //
  35. // •   A 'SIZE' resource with the acceptSuspendResumeEvents and doesActivateOnFGcase
  36. //       flags set.
  37. //
  38. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  39.  
  40. program CDEFandVBLPascal(input, output);
  41.  
  42. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  43.  
  44. uses
  45.  
  46.     Windows, Fonts, Menus, TextEdit, Quickdraw, Dialogs, QuickdrawText, Processes, Types, 
  47.     Memory, Events, TextUtils, ToolUtils, OSUtils, Devices, GestaltEqu, Retrace, LowMem, 
  48.     Palettes, SegLoad;
  49.  
  50. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  51.  
  52. const
  53.  
  54. mApple = 128;
  55.  iAbout = 1;
  56. mFile = 129;
  57.  iQuit = 11;
  58. mDemonstration = 131;
  59.  iVBLAnimCursor = 1;
  60. rMenubar = 128;
  61. rWindow = 128;
  62. rFingersCursor = 128;
  63. rStartRadioButton = 128;
  64. rStopRadioButton = 129;
  65. rSliderControl = 130;
  66. kMaxLong = $7FFFFFFF;
  67.  
  68. { ………………………………………………………………………………………………………………………………………………………………………………… user-defined types }
  69.  
  70. type
  71.  
  72. AnimCurs = record
  73.     numberOfFrames : integer;
  74.     whichFrame : integer;
  75.     frame : array [0..0] of CursHandle;
  76.     end;
  77. AnimCursPtr = ^AnimCurs;
  78. AnimCursHandle = ^AnimCursPtr;
  79.  
  80. VBLRec = record
  81.     vblTaskRec : VBLTask;
  82.     thisApplicationsA5 : longint;
  83.     end;
  84. VBLRecPtr = ^VBLRec;
  85.  
  86. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  87.  
  88. var
  89.  
  90. gColorQuickDrawPresent : boolean;
  91. gColorDisplay : boolean;
  92. gDone : boolean;
  93. gSleepTime : longint;
  94. gInBackground : boolean;
  95. gWindowPtr : WindowPtr;
  96. gAnimCursHdl : AnimCursHandle;
  97. gVBLRec : VBLRec;
  98. gVBLCount : integer;
  99. gAnimatedCursorActive : boolean;
  100. gWindowColour : RGBColor;
  101. gSliderControlHdl : ControlHandle;
  102. gStartControlHdl : ControlHandle;
  103. gStopControlHdl : ControlHandle;
  104.  
  105. theErr : OSErr;
  106. response : longint;
  107. mainDeviceHdl : GDHandle;
  108. bitsPerPixel : integer;
  109. menubarHdl : Handle;
  110. menuHdl : MenuHandle;
  111. eventRec : EventRecord;
  112.  
  113. animCursVBLTaskRD : VBLUPP;                                                { For PowerPC }
  114.  
  115. { …………………………………………………………………………………………………………………………………………………………… in-line glue for GetVBLRec }
  116.  
  117. {$IFC GENERATING68K}                                                       { For PowerPC }
  118. function GetVBLRec : longint;
  119.     {$IFC NOT GENERATINGCFM}
  120.     inline $2E88;
  121.     {$ENDC}
  122. {$ENDC}                                                                    { For PowerPC }
  123.  
  124. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  125.  
  126. procedure DoInitManagers;
  127.  
  128.     begin
  129.     MaxApplZone;
  130.     MoreMasters;
  131.  
  132.     InitGraf(@qd.thePort);
  133.     InitFonts;
  134.     InitWindows;
  135.     InitMenus;
  136.     TEInit;
  137.     InitDialogs(nil);
  138.  
  139.     InitCursor;    
  140.     FlushEvents(everyEvent, 0);
  141.     end;
  142.         {of procedure DoInitManagers}
  143.  
  144. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoStopAnimCursor }
  145.  
  146. procedure DoStopAnimCursor;
  147.  
  148.     var
  149.     a : integer;
  150.     theRect : Rect;
  151.     ignored : OSErr;
  152.  
  153.     begin
  154.     ignored := VRemove(QElemPtr(@gVBLRec.vblTaskRec));
  155.     
  156.     for a := 0 to (gAnimCursHdl^^.numberOfFrames - 1) do
  157.         ReleaseResource(Handle(gAnimCursHdl^^.frame[a]));
  158.  
  159.     ReleaseResource(Handle(gAnimCursHdl));
  160.  
  161.     gAnimatedCursorActive := false;
  162.     gSleepTime := kMaxLong;
  163.  
  164.     SetCursor(qd.arrow);
  165.  
  166.     SetRect(theRect, 30, 100, 150, 130);
  167.     RGBBackColor(gWindowColour);
  168.     FillRect(theRect, qd.white);
  169.     end;
  170.         {of procedure DoStopAnimCursor}
  171.  
  172. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ AnimCursVBLTask }
  173.  
  174. procedure AnimCursVBLTask;
  175.  
  176.     {$IFC GENERATING68K}                                                     { For PowerPC }
  177.     var
  178.     theVBLRecPtr : VBLRecPtr;
  179.     currentA5 : longint;
  180.     {$ENDC}                                                                  { For PowerPC }
  181.  
  182.     begin
  183.     {$IFC GENERATING68K}                                                     { For PowerPC }
  184.     theVBLRecPtr := VBLRecPtr(GetVBLRec);
  185.     currentA5 := SetA5(theVBLRecPtr^.thisApplicationsA5);    
  186.     {$ENDC}                                                                  { For PowerPC }
  187.  
  188.     SetCursor(gAnimCursHdl^^.frame[gAnimCursHdl^^.whichFrame]^^);
  189.     gAnimCursHdl^^.whichFrame := gAnimCursHdl^^.whichFrame + 1;
  190.     
  191.     if (gAnimCursHdl^^.whichFrame = gAnimCursHdl^^.numberOfFrames) then
  192.         gAnimCursHdl^^.whichFrame := 0;
  193.  
  194.     {$IFC GENERATING68K}                                                     { For PowerPC }
  195.     theVBLRecPtr^.vblTaskRec.vblCount := gVBLCount;
  196.     {$ELSEC}                                                                 { For PowerPC }
  197.     gVBLRec.vblTaskRec.vblCount := gVBLCount;                                { For PowerPC }
  198.     {$ENDC}                                                                  { For PowerPC }
  199.  
  200.     {$IFC GENERATING68K}                                                     { For PowerPC }
  201.     currentA5 := SetA5(currentA5);
  202.     {$ENDC}                                                                  { For PowerPC }
  203.     end;
  204.         {of procedure AnimCursVBLTask}
  205.  
  206. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInstallSystemVBLTask }
  207.  
  208. procedure DoInstallSystemVBLTask;
  209.  
  210.     var
  211.     ignored : OSErr;
  212.     
  213.     begin
  214.     gVBLRec.vblTaskRec.qType := vType;    
  215.     gVBLRec.vblTaskRec.vblAddr := animCursVBLTaskRD;                         { For PowerPC }
  216.     gVBLRec.vblTaskRec.vblCount := gVBLCount;    
  217.     gVBLRec.vblTaskRec.vblPhase := 0;
  218.  
  219.     {$IFC GENERATING68K}                                                     { For PowerPC }
  220.     gVBLRec.thisApplicationsA5 := SetCurrentA5;
  221.     {$ENDC}                                                                  { For PowerPC }
  222.  
  223.     ignored := VInstall(QElemPtr(@gVBLRec.vblTaskRec));
  224.     end;
  225.         {of procedure DoInstallSystemVBLTask}
  226.  
  227. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoGetAnimCursor }
  228.  
  229. function DoGetAnimCursor(resourceID : integer) : boolean;
  230.  
  231.     var
  232.     cursorID, a : integer;
  233.     noError : boolean;
  234.  
  235.     begin
  236.     a := 0;
  237.     noError := false;
  238.     
  239.     gAnimCursHdl := AnimCursHandle(GetResource('acur', resourceID));
  240.     if (gAnimCursHdl <> nil) then
  241.         begin
  242.         noError := true;
  243.         while ((a < gAnimCursHdl^^.numberOfFrames) and noError) do
  244.             begin
  245.             cursorID := integer(HiWord(longint(gAnimCursHdl^^.frame[a])));
  246.  
  247.             gAnimCursHdl^^.frame[a] := GetCursor(cursorID);
  248.             if (gAnimCursHdl^^.frame[a] <> nil) then
  249.                 a := a + 1
  250.             else
  251.                 noError := false;
  252.             end;
  253.         end;
  254.  
  255.     if (noError) then
  256.         gAnimCursHdl^^.whichFrame := 0;
  257.  
  258.     DoGetAnimCursor := noError;
  259.     end;
  260.         {of procedure DoGetAnimCursor}
  261.  
  262. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoStartAnimCursor }
  263.  
  264. procedure DoStartAnimCursor;
  265.  
  266.     begin
  267.     gVBLCount := 30;
  268.     gSleepTime := 0;
  269.  
  270.     if (DoGetAnimCursor(rFingersCursor) = false) then
  271.         ExitToShell;
  272.  
  273.     DoInstallSystemVBLTask;
  274.  
  275.     gAnimatedCursorActive := true;
  276.  
  277.     MoveTo(40, 110);
  278.     DrawString('Press any key to');
  279.     MoveTo(30, 125);
  280.     DrawString('stop animated cursor');
  281.     end;
  282.         {of procedure DoInitManagers}
  283.  
  284. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDrawControlsPanel }
  285.  
  286. procedure DoDrawControlsPanel;
  287.  
  288.     var
  289.     mainDeviceHdl : GDHandle;
  290.     bitsPerPixel : integer;
  291.     fontNum, a : integer;
  292.     gray8 : RGBColor;
  293.  
  294.     begin
  295.     gray8.red := $7777;
  296.     gray8.blue := $7777;
  297.     gray8.green := $7777;
  298.     
  299.     GetFNum('Chicago', fontNum);
  300.     TextFont(fontNum);
  301.     TextSize(12);
  302.         
  303.     mainDeviceHdl := LMGetMainDevice;
  304.     bitsPerPixel := mainDeviceHdl^^.gdPMap^^.pixelSize;
  305.     if (bitsPerPixel > 1) then
  306.         gColorDisplay := true
  307.     else
  308.         gColorDisplay := false;
  309.  
  310.     for a := 0 to 1 do
  311.         begin
  312.         if (a = 0) then
  313.             ForeColor(whiteColor)
  314.         else begin
  315.             if not (gInBackground) then
  316.                 begin
  317.                 if (gColorQuickDrawPresent and gColorDisplay) then
  318.                     ForeColor(blackColor)
  319.                 else begin
  320.                     ForeColor(blackColor);
  321.                     PenPat(qd.black);
  322.                     TextMode(srcOr);
  323.                     end;
  324.                 end
  325.             else begin
  326.                 if (gColorQuickDrawPresent and gColorDisplay) then
  327.                     RGBForeColor(gray8)
  328.                 else begin
  329.                     ForeColor(blackColor);
  330.                     PenPat(qd.gray);
  331.                     TextMode(grayishTextOr);
  332.                     end;
  333.                 end;
  334.             end;
  335.         
  336.         if not ((a = 0) and not gColorDisplay) then
  337.             begin
  338.             MoveTo(156-a, 22-a);
  339.             LineTo(152-a, 22-a);
  340.             LineTo(152-a, 230-a);    
  341.             LineTo(246-a, 230-a);    
  342.             LineTo(246-a, 22-a);    
  343.             LineTo(242-a, 22-a);    
  344.  
  345.             MoveTo(163-a, 26-a);
  346.             DrawString('Engine RPM');
  347.             end;
  348.         end;
  349.  
  350.     ForeColor(blackColor);
  351.  
  352.     GetFNum('Geneva', fontNum);
  353.     TextFont(fontNum);
  354.     TextSize(10);
  355.  
  356.     PenPat(qd.black);
  357.     TextMode(srcOr);
  358.     end;
  359.         {of procedure DoDrawControlsPanel}
  360.  
  361. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoGetSliderControlSuite }
  362.  
  363. procedure DoGetSliderControlSuite;
  364.  
  365.     begin
  366.     gSliderControlHdl := GetNewControl(rSliderControl, gWindowPtr);
  367.     HiliteControl(gSliderControlHdl, 255);
  368.  
  369.     gStartControlHdl := GetNewControl(rStartRadioButton, gWindowPtr);
  370.     gStopControlHdl := GetNewControl(rStopRadioButton, gWindowPtr);
  371.  
  372.     DoDrawControlsPanel;
  373.     end;
  374.         {of procedure DoGetSliderControlSuite}
  375.  
  376. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  377.  
  378. procedure DoMenuChoice(menuChoice : longint);
  379.  
  380.     var
  381.     menuID, menuItem : integer;
  382.     itemName : string;
  383.     daDriverRefNum : integer;
  384.  
  385.     begin
  386.     menuID := HiWord(menuChoice);
  387.     menuItem := LoWord(menuChoice);
  388.  
  389.     if (menuID = 0) then
  390.         Exit(DoMenuChoice);
  391.  
  392.     case (menuID) of
  393.  
  394.         mApple: begin
  395.             if (menuItem = iAbout) then
  396.                 SysBeep(10)
  397.             else begin
  398.                 GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  399.                 daDriverRefNum := OpenDeskAcc(itemName);
  400.                 end;
  401.             end;
  402.  
  403.         mFile: begin
  404.             if (menuItem = iQuit) then
  405.                 begin
  406.                 ExitToShell;
  407.                 DisposeWindow(gWindowPtr);
  408.                 gDone := true;
  409.                 end;
  410.             end;
  411.  
  412.         mDemonstration: begin
  413.             if (menuItem = iVBLAnimCursor) then
  414.                 DoStartAnimCursor;
  415.             end;
  416.         end;
  417.             {of case statement}
  418.  
  419.     HiliteMenu(0);
  420.     end;
  421.         {of procedure DoMenuChoice}
  422.  
  423. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInContent }
  424.  
  425. procedure DoInContent(var theEvent : EventRecord; theWindowPtr : WindowPtr);
  426.  
  427.     var
  428.     controlHdl : ControlHandle;
  429.     partCode : integer;
  430.     theRect : Rect;
  431.     theString : string;
  432.     ignored : ControlPartCode;
  433.     
  434.     begin
  435.     GlobalToLocal(theEvent.where);
  436.  
  437.     partCode := FindControl(theEvent.where, theWindowPtr, controlHdl);
  438.  
  439.     if (controlHdl = gSliderControlHdl) then
  440.         begin
  441.         if (partCode = kControlIndicatorPart) then
  442.             ignored := TrackControl(controlHdl, theEvent.where, nil);
  443.  
  444.         RGBBackColor(gWindowColour);
  445.         SetRect(theRect, 253, 107, 390, 119);
  446.         FillRect(theRect, qd.white);
  447.         MoveTo(255, 117);
  448.         DrawString('Slider Control Value: ');
  449.         NumToString(longint(GetControlValue(controlHdl)), theString);
  450.         DrawString(theString);
  451.         end
  452.     else if ((controlHdl = gStartControlHdl) or (controlHdl = gStopControlHdl)) then
  453.         begin
  454.         if (TrackControl(controlHdl, theEvent.where, nil) <> 0) then
  455.             begin
  456.             if (controlHdl = gStartControlHdl) then
  457.                 begin
  458.                 HiliteControl(gSliderControlHdl, 0);
  459.                 SetControlValue(gStartControlHdl, 1);    
  460.                 SetControlValue(gStopControlHdl, 0);        
  461.                 end
  462.             else if (controlHdl = gStopControlHdl) then
  463.                 begin
  464.                 SetControlValue(gSliderControlHdl, 0);
  465.                 HiliteControl(gSliderControlHdl, 255);
  466.                 SetControlValue(gStartControlHdl, 0);    
  467.                 SetControlValue(gStopControlHdl, 1);
  468.  
  469.                 RGBBackColor(gWindowColour);
  470.                 SetRect(theRect, 253, 107, 390, 119);
  471.                 FillRect(theRect, qd.white);
  472.                 end;        
  473.             end;
  474.         end;
  475.     end;
  476.         {of procedure DoInContent}
  477.  
  478. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateWindow }
  479.  
  480. procedure DoActivateWindow(becomingActive : boolean);
  481.  
  482.     var    
  483.     controlVal : integer;
  484.  
  485.     begin
  486.     if (becomingActive) then
  487.         begin
  488.         controlVal := GetControlValue(gStartControlHdl);
  489.         if (controlVal = 1) then
  490.             HiliteControl(gSliderControlHdl, 0);
  491.         HiliteControl(gStartControlHdl, 0);
  492.         HiliteControl(gStopControlHdl, 0);
  493.         end
  494.     else begin
  495.         HiliteControl(gSliderControlHdl, 255);
  496.         HiliteControl(gStartControlHdl, 255);
  497.         HiliteControl(gStopControlHdl, 255);
  498.         end;
  499.     
  500.     DoDrawControlsPanel;
  501.     end;
  502.         {of procedure DoActivateWindow}
  503.  
  504. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
  505.  
  506. procedure DoOSEvent(var theEvent : EventRecord);
  507.  
  508.     begin
  509.     case BAnd(BSR(theEvent.message, 24), $000000FF) of
  510.  
  511.         suspendResumeMessage: begin
  512.             gInBackground := BAnd(theEvent.message, resumeFlag) = 0;
  513.             DoActivateWindow(not gInBackground);
  514.             end;
  515.  
  516.         mouseMovedMessage: begin
  517.             end;
  518.         end;
  519.             {of case statement}
  520.     end;
  521.         {of procedure DoOSEvent}
  522.  
  523. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdate }
  524.  
  525. procedure DoUpdate(var theEvent : EventRecord);
  526.  
  527.     var
  528.     theWindowPtr : WindowPtr;
  529.     
  530.     begin
  531.     theWindowPtr := WindowPtr(theEvent.message);
  532.  
  533.     BeginUpdate(theWindowPtr);
  534.  
  535.     SetPort(theWindowPtr);
  536.     UpdateControls(theWindowPtr, theWindowPtr^.visRgn);
  537.     DoDrawControlsPanel;
  538.  
  539.     EndUpdate(theWindowPtr);
  540.     end;
  541.         {of procedure DoUpdate}
  542.  
  543. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivate }
  544.  
  545. procedure DoActivate(var theEvent : EventRecord);
  546.  
  547.     var
  548.     theWindowPtr : WindowPtr;
  549.     becomingActive : boolean;
  550.  
  551.     begin
  552.     theWindowPtr := WindowPtr(theEvent.message);
  553.  
  554.     becomingActive := (BAnd(theEvent.modifiers, activeFlag) = activeFlag);
  555.     DoActivateWindow(becomingActive);
  556.     end;
  557.         {of procedure DoActivate}
  558.  
  559. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  560.  
  561. procedure DoMouseDown(var theEvent : EventRecord);
  562.  
  563.     var
  564.     partCode : integer;
  565.     theWindowPtr : WindowPtr;
  566.     menuHdl : MenuHandle;
  567.  
  568.     begin
  569.     partCode := FindWindow(theEvent.where, theWindowPtr);
  570.     menuHdl := GetMenuHandle(mDemonstration);
  571.  
  572.     case (partCode) of
  573.  
  574.         inMenuBar: begin
  575.             if (gAnimatedCursorActive) then
  576.                 DisableItem(menuHdl, iVBLAnimCursor)
  577.             else
  578.                 EnableItem(menuHdl, iVBLAnimCursor);
  579.             DoMenuChoice(MenuSelect(theEvent.where));
  580.             end;
  581.  
  582.         inSysWindow: begin
  583.             SystemClick(theEvent, theWindowPtr);
  584.             end;
  585.  
  586.         inContent: begin
  587.             if (theWindowPtr <> FrontWindow) then
  588.                 SelectWindow(theWindowPtr)
  589.             else
  590.                 DoInContent(theEvent, theWindowPtr);
  591.             end;
  592.             
  593.         inDrag: begin
  594.             DragWindow(theWindowPtr, theEvent.where, qd.screenBits.bounds);
  595.             end;
  596.         end;
  597.             {of case statement}
  598.     end;
  599.         {of procedure DoMouseDown}
  600.  
  601. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  602.  
  603. procedure DoEvents(var theEvent : EventRecord);
  604.  
  605.     begin
  606.     case (theEvent.what) of
  607.  
  608.         mouseDown: begin
  609.             DoMouseDown(theEvent);
  610.             end;
  611.  
  612.         keyDown, autoKey: begin
  613.             if (gAnimatedCursorActive) then
  614.                 DoStopAnimCursor;
  615.             end;
  616.  
  617.         updateEvt: begin
  618.             DoUpdate(theEvent);
  619.             end;
  620.  
  621.         activateEvt: begin
  622.             DoActivate(theEvent);
  623.             end;
  624.  
  625.         osEvt: begin
  626.             DoOSEvent(theEvent);
  627.             HiliteMenu(0);
  628.             end;
  629.         end;
  630.             {of case statement}
  631.     end;
  632.         {of procedure DoEvents}
  633.     
  634. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  635.  
  636. begin
  637.  
  638. gColorQuickDrawPresent := false;
  639. gColorDisplay := false;
  640. gAnimatedCursorActive := false;
  641. gWindowColour.red := $DDDD;
  642. gWindowColour.green := $DDDD;
  643. gWindowColour.blue := $DDDD;
  644.  
  645.     { …………………………………………………………………………………………………………………………………………………………………… initialise managers }
  646.  
  647.     DoInitManagers;
  648.         
  649.     { …………………………………………………………………………………………………………………………………………………… create routine descriptor }
  650.  
  651.     animCursVBLTaskRD := NewVBLProc(ProcPtr(@AnimCursVBLTask));            { For PowerPC }
  652.     
  653.     { …………………………………………………………………………………………………………………………………………………… check for Color QuickDraw }
  654.  
  655.     theErr := Gestalt(gestaltQuickdrawVersion, response);
  656.     if (response >= gestalt8BitQD) then
  657.         begin
  658.         gColorQuickDrawPresent := true;
  659.  
  660.         mainDeviceHdl := LMGetMainDevice;
  661.         bitsPerPixel := mainDeviceHdl^^.gdPMap^^.pixelSize;
  662.         if (bitsPerPixel > 1) then
  663.             gColorDisplay := true;
  664.         end;
  665.  
  666.     { …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
  667.  
  668.     menubarHdl := GetNewMBar(rMenubar);
  669.     if (menubarHdl = nil) then
  670.         ExitToShell;
  671.     SetMenuBar(menubarHdl);
  672.     DrawMenuBar;
  673.  
  674.     menuHdl := GetMenuHandle(mApple);
  675.     if (menuHdl = nil) then
  676.         ExitToShell
  677.     else
  678.         AppendResMenu(menuHdl, 'DRVR');
  679.  
  680.     { ………………………………………………………………………………………………………………………………………………………………………………………… open window } 
  681.  
  682.     if (gColorQuickDrawPresent) then
  683.         begin
  684.         gWindowPtr := GetNewCWindow(rWindow, nil, WindowPtr(-1));
  685.         if (gWindowPtr = nil) then
  686.             ExitToShell;
  687.         end
  688.     else begin
  689.         gWindowPtr := GetNewWindow(rWindow, nil, WindowPtr(-1));
  690.         if (gWindowPtr = nil) then
  691.             ExitToShell;
  692.         end;
  693.  
  694.     SetPort(gWindowPtr);
  695.         
  696.     { ……………………………………………………………………………………………………………………………………………………… get slider control suite }
  697.  
  698.     DoGetSliderControlSuite;
  699.  
  700.     { ……………………………………………………………………………………………………………………………………………………………………………… enter eventLoop }
  701.  
  702.     gDone := false;
  703.     gSleepTime := kMaxLong;
  704.  
  705.     while not (gDone) do
  706.         begin
  707.         if (WaitNextEvent(everyEvent, eventRec, gSleepTime, nil)) then
  708.             DoEvents(eventRec);
  709.         end;
  710.  
  711. end.
  712.     {of main program block}
  713.     
  714. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }