home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / HexThing 1.0.1 / HexThing.c < prev    next >
Encoding:
Text File  |  1995-12-01  |  15.7 KB  |  763 lines  |  [TEXT/CWIE]

  1. // HexThing
  2. // version 1.0.1
  3. // by Ken Long <kenlong@netcom.com>
  4. // updated for CW7 and THINK 7 on 951201
  5. #include <stdio.h>
  6. #include <Math.h>
  7.  
  8. #define words "\pAnother itty bitty bytes™ public domain source code demo, by kenlong @netcom. com."
  9. enum    {
  10.     appleID = 1,
  11.     fileID,
  12.     editID
  13. };
  14.  
  15. enum    {
  16.     quitItem = 1
  17. };
  18.  
  19. short thing;
  20.  
  21. MenuHandle    appleMenu, fileMenu, editMenu;
  22. EventRecord mainEvent;
  23.  
  24. Boolean weBeHued;
  25.  
  26. WindowPtr    hexWindow;
  27.  
  28. Rect hexOneRect, hexTwoRect, hexTriRect, hexQuaRect,
  29.      hexOneDataRect, hexTwoDataRect, hexTriDataRect, hexQuaDataRect,
  30.      controlWindowRect, decRect, hexRect, bitRect;
  31. Rect bitOneDataRect, bitTwoDataRect, bitTriDataRect, bitQuaDataRect,
  32.      aboutRect, ctlBoxRect;
  33.  
  34. ControlHandle hexOne, hexTwo, hexTri, hexQua;
  35.  
  36. void SetForeColor (short red, short green, short blue);
  37. void SetBackColor (short red, short green, short blue);
  38. void ShowScrlValue (ControlHandle theControl);
  39. void OneTimeStrings ();
  40. void ControlsUpdate ();
  41. pascal void Track (ControlHandle Control, short partCode);
  42. void MakeHex (short thing);
  43. void MakeBits (short thing);
  44. void ControlMouse (Point thePoint);
  45. void EmbossString (Str255 string, short h, short v);
  46. void EmbossFrame (Rect someRect);
  47. void ShadowBox (Rect someRect);
  48. void InitHexThing (void);
  49. void DrawStuff ();
  50. void SetUpRects (void);
  51. void WindowClicks (WindowPtr theWindow, Point where);
  52. void Updates (void);
  53. void MenuPicks (long mSelect);
  54. void MouseClicks (EventRecord *event);
  55. void Events (void);
  56. void SetUpMenus (void);
  57. void SetUpMac (void);
  58. void main (void);
  59.  
  60. pascal void TETextBox(const void *text, long length, const Rect *box, short just)
  61.  =(0xA9CE);
  62.  
  63. //• --------------------------------------------------------------- •//
  64. DoAbout ()
  65. {
  66.     long ticks;
  67.     
  68.     EmbossFrame (aboutRect);
  69.     InsetRect (&aboutRect, 1, 1);
  70.     TETextBox(&words [1], words[0], &aboutRect, 0);
  71.     Delay (240L, &ticks);
  72.     SetForeColor(0xeeee, 0xeeee, 0xeeee);
  73.     InsetRect (&aboutRect, -2, -2);
  74.     PaintRect (&aboutRect);
  75.     SetForeColor(0, 0, 0);
  76. }
  77.  
  78. //• --------------------------------------------------------------- •//
  79. void SetForeColor(short red, short green, short blue)
  80. {
  81.     RGBColor hue;
  82.  
  83.     hue.red = red;
  84.     hue.green = green;
  85.     hue.blue = blue;
  86.  
  87.     RGBForeColor (&hue);
  88. }
  89.  
  90. //• --------------------------------------------------------------- •//
  91. void SetBackColor(short red, short green, short blue)
  92. {
  93.     RGBColor hue;
  94.  
  95.     hue.red = red;
  96.     hue.green = green;
  97.     hue.blue = blue;
  98.  
  99.     RGBBackColor (&hue);
  100. }
  101.  
  102. //• --------------------------------------------------------------- •//
  103. void ShowScrlValue (ControlHandle theControl)
  104. {
  105.     Rect aRect;
  106.     Str255 aStr;
  107.     short anInt;
  108.  
  109.     TextFont (helvetica);
  110.     TextSize (9);
  111.  
  112.     aRect = theControl[0]->contrlRect;
  113.     aRect.top = aRect.bottom + 4;
  114.     aRect.bottom = aRect.top + 15;
  115.     aRect.left = aRect.left;
  116.     aRect.right = aRect.right;
  117.  
  118.     FrameRect (&aRect);
  119.     InsetRect (&aRect, 1, 1);
  120.     EraseRect (&aRect);
  121.  
  122.     anInt = GetCtlValue (theControl);
  123.     NumToString (anInt, aStr);
  124.     anInt = StringWidth (aStr) / 2;
  125.     MoveTo (aRect.left + ((aRect.right - aRect.left) / 2 - anInt), 
  126.             aRect.top + 10);
  127.     DrawString (aStr);
  128.     TextFont (0);
  129.     TextSize (12);
  130. }
  131.  
  132. //• --------------------------------------------------------------- •//
  133. void OneTimeStrings ()
  134. {
  135.     char    s[64];
  136.     short val1, val2, val3, val4;
  137.     unsigned short decValue;
  138.     Str255 aString;
  139.     
  140.     MoveTo (24, 248);
  141.     DrawString ("\p0x0000");
  142.  
  143.     MoveTo (24, 292);
  144.     DrawString ("\p0000000000000000");
  145. }
  146.  
  147. //• --------------------------------------------------------------- •//
  148. void ControlsUpdate ()
  149. {
  150.     GrafPtr    thePort;
  151.  
  152.     GetPort (&thePort);
  153.     SetPort (hexWindow);
  154.     DrawControls (thePort);
  155.     ShowScrlValue (hexOne);
  156.     ShowScrlValue (hexTwo);
  157.     ShowScrlValue (hexTri);
  158.     ShowScrlValue (hexQua);
  159.  
  160.     OneTimeStrings ();
  161. }
  162.  
  163. //• --------------------------------------------------------------- •//
  164. pascal void Track (ControlHandle Control, short partCode)
  165. {
  166.     short        i, step, val1, val2, val3, val4;
  167.     unsigned short decValue;
  168.     long    waited;
  169.     char    s[128];
  170.     Str255 aString;
  171.     
  172.     if (partCode == 0)
  173.         return;
  174.  
  175.     switch (partCode)
  176.     {
  177.         case inUpButton:
  178.             step = -1;
  179.         break;
  180.         
  181.         case inDownButton:
  182.             step = 1;
  183.         break;
  184.         
  185.         case inPageUp:
  186.             step = -1;
  187.         break;
  188.         
  189.         case inPageDown:
  190.             step = 1;
  191.         break;
  192.     }
  193.  
  194.     i = GetCtlValue (Control) + step;
  195.  
  196.     if (*Control == *hexOne)
  197.     {
  198.         if (i > 15)
  199.             i = 15;
  200.         if (i < 0)
  201.             i = 0;
  202.  
  203.         SetCtlValue (Control, i);
  204.  
  205.         EraseRect (&hexOneDataRect);
  206.         EraseRect (&bitOneDataRect);
  207.         MoveTo (41, 248);
  208.         thing = GetCtlValue (hexOne);
  209.         MakeHex(thing);
  210.         MoveTo (24, 292);
  211.         MakeBits(thing);
  212.         ShowScrlValue (hexOne);
  213.     }
  214.  
  215.     if (*Control == *hexTwo)
  216.     {
  217.         if (i > 15)
  218.             i = 15;
  219.         if (i <  0)
  220.             i = 0;
  221.  
  222.         SetCtlValue (Control, i);
  223.  
  224.         EraseRect (&hexTwoDataRect);
  225.         EraseRect (&bitTwoDataRect);
  226.         MoveTo (49, 248);
  227.         thing = GetCtlValue (hexTwo);
  228.         MakeHex(thing);
  229.         MoveTo (56, 292);
  230.         MakeBits(thing);
  231.         ShowScrlValue (hexTwo);
  232.     }
  233.  
  234.     if (*Control == *hexTri)
  235.     {
  236.         if (i > 15)
  237.             i = 15;
  238.         if (i <  0)
  239.             i = 0;
  240.  
  241.         SetCtlValue (Control, i);
  242.  
  243.         EraseRect (&hexTriDataRect);
  244.         EraseRect (&bitTriDataRect);
  245.         MoveTo (57, 248);
  246.         thing = GetCtlValue (hexTri);
  247.         MakeHex(thing);
  248.         MoveTo (88, 292);
  249.         MakeBits(thing);
  250.         ShowScrlValue (hexTri);
  251.     }
  252.     if (*Control == *hexQua)
  253.     {
  254.         if (i > 15)
  255.         {
  256.             i = 15;
  257.             return;
  258.         }
  259.         if (i <  0)
  260.         {
  261.             i = 0;
  262.             return;
  263.         }
  264.  
  265.         SetCtlValue (Control, i);
  266.  
  267.         EraseRect (&hexQuaDataRect);
  268.         EraseRect (&bitQuaDataRect);
  269.         MoveTo (65, 248);
  270.         thing = GetCtlValue (hexQua);
  271.         MakeHex(thing);
  272.         MoveTo (120, 292);
  273.         MakeBits(thing);
  274.         ShowScrlValue (hexQua);
  275.     }
  276.     val1 = GetCtlValue (hexOne) * 16 * 16 * 16;
  277.     val2 = GetCtlValue (hexTwo) * 16 * 16;
  278.     val3 = GetCtlValue (hexTri) * 16;
  279.     val4 = GetCtlValue (hexQua);
  280.     decValue = val1 + val2 + val3 + val4;
  281.     NumToString (decValue, aString);
  282.     EraseRect (&decRect);
  283.     MoveTo ((decRect.right-5) - StringWidth (aString), 270);
  284.     DrawString (aString);
  285. }
  286.  
  287. //• --------------------------------------------------------------- •//
  288. void MakeHex (short thing)        //• One way to fake it.
  289. {    
  290.     switch (thing)
  291.     {
  292.         case 0:
  293.             DrawString ("\p0");
  294.         break;
  295.         
  296.         case 1:
  297.             DrawString ("\p1");
  298.         break;
  299.         
  300.         case 2:
  301.             DrawString ("\p2");
  302.         break;
  303.         
  304.         case 3:
  305.             DrawString ("\p3");
  306.         break;
  307.         
  308.         case 4:
  309.             DrawString ("\p4");
  310.         break;
  311.         
  312.         case 5:
  313.             DrawString ("\p5");
  314.         break;
  315.         
  316.         case 6:
  317.             DrawString ("\p6");
  318.         break;
  319.         
  320.         case 7:
  321.             DrawString ("\p7");
  322.         break;
  323.         
  324.         case 8:
  325.             DrawString ("\p8");
  326.         break;
  327.         
  328.         case 9:
  329.             DrawString ("\p9");
  330.         break;
  331.         
  332.         case 10:
  333.             DrawString ("\pA");
  334.         break;
  335.         
  336.         case 11:
  337.             DrawString ("\pB");
  338.         break;
  339.         
  340.         case 12:
  341.             DrawString ("\pC");
  342.         break;
  343.         
  344.         case 13:
  345.             DrawString ("\pD");
  346.         break;
  347.         
  348.         case 14:
  349.             DrawString ("\pE");
  350.         break;
  351.         
  352.         case 15:
  353.             DrawString ("\pF");
  354.         break;
  355.     }
  356. }
  357.  
  358. //• --------------------------------------------------------------- •//
  359. void MakeBits (short thing)            //• Faking bits the same way.
  360. {    
  361.     switch (thing)
  362.     {
  363.         case 0:
  364.             DrawString ("\p0000");
  365.         break;
  366.         
  367.         case 1:
  368.             DrawString ("\p0001");
  369.         break;
  370.         
  371.         case 2:
  372.             DrawString ("\p0010");
  373.         break;
  374.         
  375.         case 3:
  376.             DrawString ("\p0011");
  377.         break;
  378.         
  379.         case 4:
  380.             DrawString ("\p0100");
  381.         break;
  382.         
  383.         case 5:
  384.             DrawString ("\p0101");
  385.         break;
  386.         
  387.         case 6:
  388.             DrawString ("\p0110");
  389.         break;
  390.         
  391.         case 7:
  392.             DrawString ("\p0111");
  393.         break;
  394.         
  395.         case 8:
  396.             DrawString ("\p1000");
  397.         break;
  398.         
  399.         case 9:
  400.             DrawString ("\p1001");
  401.         break;
  402.         
  403.         case 10:
  404.             DrawString ("\p1010");
  405.         break;
  406.         
  407.         case 11:
  408.             DrawString ("\p1011");
  409.         break;
  410.         
  411.         case 12:
  412.             DrawString ("\p1100");
  413.         break;
  414.         
  415.         case 13:
  416.             DrawString ("\p1101");
  417.         break;
  418.         
  419.         case 14:
  420.             DrawString ("\p1110");
  421.         break;
  422.         
  423.         case 15:
  424.             DrawString ("\p1111");
  425.         break;
  426.     }
  427. }
  428.  
  429. //• --------------------------------------------------------------- •//
  430. void ControlMouse (Point thePoint)        //• Leftover from Earthplot.
  431. {
  432.     ControlHandle    theControl;
  433.     short                partCode;
  434.     char            s[100];
  435.  
  436.     partCode = FindControl (thePoint, hexWindow, &theControl);
  437.  
  438.     if (partCode)
  439.     {
  440.         switch (partCode)
  441.         {
  442.             case inUpButton:
  443.             case inDownButton:
  444.             case inPageUp:
  445.             case inPageDown:
  446.                 partCode = TrackControl (theControl, thePoint, Track);
  447.             break;
  448.             case inThumb:
  449.             break;
  450.         }
  451.     }
  452. }
  453.  
  454. //• --------------------------------------------------------------- •//
  455. void EmbossString (Str255 string, short h, short v)
  456. {
  457.     MoveTo (h - 1, v - 1);                    //• Passed loc. minus 1.
  458.     SetForeColor (0xffff, 0xffff, 0xffff);    //• White.
  459.     DrawString (string);                    //• First string.
  460.     MoveTo (h + 1, v + 1);                    //• passed loc. plus 1.
  461.     SetForeColor (0xaaaa, 0xaaaa, 0xaaaa);    //• A medium gray.
  462.     DrawString (string);                    //• Second string.
  463.     MoveTo (h, v);                            //• Passed location.
  464.     SetForeColor (0, 0, 0);                    //• Black.
  465.     DrawString (string);                    //• Final string.
  466. }
  467.  
  468. //• --------------------------------------------------------------- •//
  469. void EmbossFrame (Rect someRect)
  470. {
  471.     OffsetRect (&someRect, 1, 1);
  472.     SetForeColor (0xaaaa, 0xaaaa, 0xaaaa);    //• A medium gray.
  473.     FrameRect (&someRect);
  474.     OffsetRect (&someRect, -2, -2);
  475.     SetForeColor (0xffff, 0xffff, 0xffff);    //• White.
  476.     FrameRect (&someRect);
  477.     OffsetRect (&someRect, 1, 1);
  478.     SetForeColor (0, 0, 0);                    //• Black
  479.     FrameRect (&someRect);
  480. }
  481.  
  482. //• --------------------------------------------------------------- •//
  483. void ShadowBox (Rect someRect)                //• Receive rect to be done.
  484. {
  485.     OffsetRect (&someRect, 2, 2);        //• Bop it down, right, 2.
  486.     SetForeColor (40960, 40960, 40960);    //• Using  1/3 gray...
  487.     FrameRect (&someRect);                //• ...frame it.
  488.     OffsetRect (&someRect, -1, -1);        //• Bring it up, left, 1.
  489.     SetForeColor (20480, 20480, 20480);    //• Using  2/3 gray...
  490.     FrameRect (&someRect);                //• ...frame it.
  491.     OffsetRect (&someRect, -1, -1);        //• Bring it up, left, 1 more.
  492.     SetForeColor (0, 0, 0);                //• Using 100% gray...
  493.     FrameRect (&someRect);                //• ...frame it.
  494.     InsetRect (&someRect, 1, 1);        //• Shrink it by 1, all sides.
  495.     EraseRect (&someRect);                //• Clean out the in'ards.
  496. }
  497.  
  498. //• --------------------------------------------------------------- •//
  499. void InitHexThing ()
  500. {
  501.     SetRect (&controlWindowRect, 20, 40, 220, 350);
  502.  
  503.     hexWindow = NewCWindow (nil, &controlWindowRect, "\pitty bitty bytes™",
  504.                             true, documentProc, (WindowPtr)-1L, true, 0L);
  505.  
  506.     SetPort (hexWindow);
  507.     
  508.     SetUpRects ();
  509.     DrawStuff ();
  510. }
  511.  
  512. //• --------------------------------------------------------------- •//
  513. void DrawStuff ()
  514. {
  515.     SetBackColor (0xeeee, 0xeeee, 0xeeee);
  516.     EraseRect (&hexWindow->portRect);
  517.     SetBackColor (0xffff, 0xffff, 0xffff);
  518.     
  519.     hexOne = NewControl(hexWindow, &hexOneRect, "\p", true, 0, 0, 15, 16, 0L);
  520.     hexTwo = NewControl(hexWindow, &hexTwoRect, "\p", true, 0, 0, 15, 16, 0L);
  521.     hexTri = NewControl(hexWindow, &hexTriRect, "\p", true, 0, 0, 15, 16, 0L);
  522.     hexQua = NewControl(hexWindow, &hexQuaRect, "\p", true, 0, 0, 15, 16, 0L);
  523.  
  524.     ShadowBox (hexRect);
  525.     ShadowBox (decRect);
  526.     ShadowBox (bitRect);
  527.     InsetRect (&decRect, 1, 1);    //• No wipe rect so must do this.
  528.  
  529.     EmbossFrame (ctlBoxRect);
  530.     
  531.      EmbossString ("\pCtl. Value", hexRect.right + 22, 224);
  532.     EmbossString ("\pHex. Value", hexRect.right + 22, 248);
  533.     EmbossString ("\pDec. Value", hexRect.right + 22, 270);
  534.     EmbossString ("\pBits", bitRect.right + 10, 292);
  535. //    EmbossString ("\p(No Thumb)", 23, 15);
  536.  
  537.     ControlsUpdate ();
  538. }
  539.  
  540. //• --------------------------------------------------------------- •//
  541. void SetUpRects ()
  542. {
  543.     SetRect (&aboutRect, 110, 20, 190, 190);
  544.  
  545.     SetRect (&ctlBoxRect, 16, 16, 100, 231);
  546.     SetRect (&hexOneRect, 20, 20, 36, 208);
  547.     SetRect (&hexTwoRect, 40, 20, 56, 208);
  548.     SetRect (&hexTriRect, 60, 20, 76, 208);
  549.     SetRect (&hexQuaRect, 80, 20, 96, 208);
  550.  
  551.     SetRect (&hexRect, 20, 235, 80, 252);
  552.     SetRect (&hexOneDataRect, 41, 238, 49, 248);
  553.     SetRect (&hexTwoDataRect, 41 + 8, 238, 49 + 8, 248);
  554.     SetRect (&hexTriDataRect, 41 + 8 + 8, 238, 49 + 8 + 8, 248);
  555.     SetRect (&hexQuaDataRect, 41 + 8 + 8 + 8, 238, 49 + 8 + 8 + 8, 248);
  556.  
  557.     SetRect (&decRect, 20, 256, 70, 274);
  558.  
  559.     SetRect (&bitRect, 20, 278, 156, 296);
  560.     SetRect (&bitOneDataRect, 24, 281, 56, 292);
  561.     SetRect (&bitTwoDataRect, 24 + 32, 281, 56 + 32, 292);
  562.     SetRect (&bitTriDataRect, 24 + 32 + 32, 281, 56 + 32 + 32, 292);
  563.     SetRect (&bitQuaDataRect, 24 + 32 + 32 + 32, 281, 56 + 32 + 32 + 32, 292);
  564. }
  565.  
  566. //• --------------------------------------------------------------- •//
  567. void WindowClicks (WindowPtr theWindow, Point where)
  568. {
  569.         if (theWindow == hexWindow)
  570.         {
  571.             SelectWindow (hexWindow);
  572.             SetPort (hexWindow);
  573.             GlobalToLocal (&where);
  574.             ControlMouse (where);
  575.         }
  576. }
  577.  
  578. //• --------------------------------------------------------------- •//
  579. void Updates ()
  580. {
  581.     WindowPtr ActivePort, whichWindow;
  582.     short x, width;
  583.  
  584.     //• Save the current port in 'activeport', set the port to the
  585.     //• window needing updating, redraw the contents of the window,
  586.     //• restore the port to the original 'activeport'.
  587.     GetPort(&ActivePort);
  588.     whichWindow = (WindowPtr) mainEvent.message;
  589.  
  590.     if (whichWindow == hexWindow)        //• Control window.
  591.     {
  592.         BeginUpdate (hexWindow);
  593.         SelectWindow (hexWindow);
  594.         SetPort (hexWindow);
  595.         ControlsUpdate ();
  596. //        OneTimeStrings ();
  597.         EndUpdate (hexWindow);
  598.     }
  599.     SetPort (ActivePort);
  600. }
  601.  
  602. //• --------------------------------------------------------------- •//
  603. void MenuPicks (long mSelect)
  604. {
  605.     short menuID = HiWord(mSelect);
  606.     short menuItem = LoWord(mSelect);
  607.     Str255 name;
  608.     GrafPtr savePort;
  609.     WindowPeek frontWindow;
  610.     switch (menuID)
  611.     {
  612.         case appleID:
  613.             if (menuItem == 1)
  614.                 DoAbout ();
  615.             else
  616.                 {
  617.                     GetPort(&savePort);
  618.                     GetItem(appleMenu, menuItem, name);
  619.                     OpenDeskAcc(name);
  620.                     SetPort(savePort);
  621.             }
  622.         break;
  623.         
  624.         case fileID:
  625.             switch (menuItem)
  626.             {
  627.                 case quitItem:
  628.                     ExitToShell();
  629.                 break;
  630.             }
  631.         break;
  632.         
  633.         case editID:
  634.             if (!SystemEdit(menuItem-1))
  635.                 SysBeep(5);
  636.         break;
  637.     }
  638. }
  639.  
  640. //• --------------------------------------------------------------- •//
  641. void MouseClicks (EventRecord *event)
  642. {
  643.     WindowPtr theWindow;
  644.     Point thePoint;
  645.     
  646.     short windowCode = FindWindow (event->where, &theWindow);
  647.     switch (windowCode)
  648.     {
  649.         case inSysWindow:
  650.             SystemClick (event, theWindow);
  651.         break;
  652.         
  653.         case inMenuBar:
  654.             MenuPicks (MenuSelect (event->where));
  655.         break;
  656.         
  657.         case inDrag:
  658.             DragWindow (theWindow, event->where, &qd.screenBits.bounds);
  659.         break;
  660.         
  661.         case inContent:
  662.             WindowClicks (theWindow, event->where);
  663.         break;
  664.         
  665.         case inGoAway:
  666.             if (theWindow == theWindow &&
  667.               TrackGoAway (theWindow, event->where))
  668.                 ExitToShell ();
  669.         break;
  670.     }
  671. }
  672.  
  673. void Events(void)
  674. {
  675.     int            ok;
  676.     EventRecord    theEvent;
  677.  
  678.     HiliteMenu(0);
  679.     SystemTask ();        /* Handle desk accessories */
  680.     
  681.     ok = GetNextEvent (everyEvent, &theEvent);
  682.     if (ok)
  683.         switch (theEvent.what)
  684.         {
  685.             case mouseDown:
  686.                 MouseClicks(&theEvent);
  687.             break;
  688.                 
  689.             case keyDown: 
  690.             case autoKey:
  691.                 if ((theEvent.modifiers & cmdKey) != 0)
  692.                 {
  693.                     MenuPicks(MenuKey((char) (theEvent.message & charCodeMask)));
  694.                 }
  695.             break;
  696.                 
  697.             case updateEvt:
  698.                 BeginUpdate(hexWindow);
  699.                 EndUpdate(hexWindow);
  700.             break;
  701.                     
  702.             case activateEvt:
  703.                 InvalRect(&hexWindow->portRect);
  704.             break;
  705.         }
  706. }
  707.  
  708. //• --------------------------------------------------------------- •//
  709. void SetUpMenus ()
  710. {
  711.     InsertMenu (appleMenu = NewMenu (appleID, "\p\024"), 0);
  712.     InsertMenu (fileMenu = NewMenu (fileID, "\pFile"), 0);
  713.     InsertMenu (editMenu = NewMenu (editID, "\pEdit"), 0);
  714.     DrawMenuBar ();
  715.     AppendMenu (appleMenu, "\pNeed I Say More?");
  716.     AddResMenu (appleMenu, 'DRVR');
  717.     AppendMenu (fileMenu, "\pQuit/Q");
  718.     AppendMenu (editMenu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
  719. }
  720.  
  721. //• --------------------------------------------------------------- •//
  722. Boolean CheckForColor ()
  723. {
  724.     SysEnvRec theMac;
  725.     
  726.     if (theMac.hasColorQD)
  727.         weBeHued = true;
  728.     else
  729.         weBeHued = false;
  730. }
  731.  
  732. //• --------------------------------------------------------------- •//
  733. void SetUpMac ()
  734. {
  735.     EventRecord myevent;
  736.  
  737.     MaxApplZone ();
  738.     InitGraf (&qd.thePort);
  739.     InitFonts ();
  740.     FlushEvents (everyEvent, 0);
  741.     InitWindows ();
  742.     InitMenus ();
  743.     TEInit ();
  744.     InitDialogs (0L);
  745.     InitCursor ();
  746. }
  747.  
  748. //• --------------------------------------------------------------- •//
  749. void main ()
  750. {    
  751.     SetUpMac ();
  752.     CheckForColor ();
  753.     if (weBeHued)
  754.     {
  755.         SetUpMenus ();
  756.         InitHexThing ();
  757.  
  758.         for (;;)
  759.             Events ();        /* loop 'til Quit selected */
  760.     }
  761. }
  762.  
  763.