home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / c_bmug4.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  6.0 KB  |  299 lines

  1. 18-Jun-88 14:24:47-MDT,6409;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:24:39 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22091; Sat, 18 Jun 88 14:24:42 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24499; Sat, 18 Jun 88 14:24:39 MDT
  8. Date: Sat, 18 Jun 88 14:24:39 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182024.AA24499@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: BMUG4.c
  13.  
  14. /*  Sample evolving program for BMUG Developers Group  */
  15.  
  16. /*  Code to demonstrate Events                F.A. Huxham      2/20/85  */
  17. /*  Code to demonstrate Windows                D.J. Burnard     3/6/85   */
  18. /*  Code to demonstrate Menus                    J.Y. Takatsuka 3/20/85  */
  19. /*  Code to demonstrate QuickDraw & DA's     F.A. Huxham    4/3/85   */
  20.  
  21. #include "Events.h"
  22. #include "Window.h"
  23. #include "Menu.h"
  24. #include "QuickDraw.h"
  25.  
  26. #define    TRUE        1
  27. #define    FALSE    0
  28. #define    NIL        0
  29.  
  30. /*  Menu Stuff  */
  31. #define    Desk_ID        100
  32. #define    Shape_ID        101
  33. #define    Cursor_ID    102
  34. #define    Special_ID    103
  35.  
  36. struct P_Str
  37.   {
  38.   char count;
  39.   char contents[255];
  40.   };
  41.  
  42. MenuHandle    DeskMenu;
  43. MenuHandle    shapeMenu;
  44. MenuHandle    cursorMenu;
  45. MenuHandle    SpecialMenu;
  46.  
  47. EventRecord theEvent;
  48. WindowPtr     whichWindow;
  49. Rect            screen,theRect,PictureRect,icon1;
  50. short            windowcode,i;
  51. CursHandle    theCursor;
  52. PatHandle    thePattern;
  53. PicHandle    thePicture;
  54. PolyHandle    thePolygon;
  55. Handle        saucer1;
  56. long            newSize,tempCurs;
  57.  
  58. struct P_Str    *DAName;
  59.  
  60. struct P_Str *CtoPstr();
  61.     int strlen(str)char *str;
  62.     {int i=0;while (str[i++]);return i-1;}
  63.  
  64. SetUpMenus()
  65. {
  66. /*  Desk Accessory Menu  */
  67. DeskMenu = NewMenu (Desk_ID,CtoPstr("\24"));
  68. AddResMenu (DeskMenu, 'DRVR');
  69. InsertMenu (DeskMenu, 0);
  70.  
  71. /*  shape menu  */
  72. shapeMenu = NewMenu (Shape_ID, CtoPstr("Shapes"));
  73. AppendMenu (shapeMenu, CtoPstr("Clear Screen;(-;Frame Rect;Paint Rect"));
  74. AppendMenu (shapeMenu, CtoPstr("Erase Rect;Invert Rect;Fill Rect"));
  75. AppendMenu (shapeMenu, CtoPstr("(-;Frame Oval;Paint Oval;Erase Oval"));
  76. AppendMenu (shapeMenu, CtoPstr("Invert Oval;Fill Oval;(-;Quit"));
  77. InsertMenu (shapeMenu,0);
  78. DisableItem(shapeMenu,2);
  79. DisableItem(shapeMenu,8);
  80. DisableItem(shapeMenu,14);
  81.  
  82. /*  Cursors Menu  */
  83. cursorMenu = NewMenu (Cursor_ID, CtoPstr("Cursors"));
  84. AppendMenu (cursorMenu, CtoPstr("I-Beam;Cross;Plus;Watch;Arrow"));
  85. InsertMenu (cursorMenu, 0);
  86.  
  87. /*  Special Menu  */
  88. SpecialMenu = NewMenu (Special_ID, CtoPstr("Special"));
  89. AppendMenu (SpecialMenu, CtoPstr("Draw Picture;Draw Polygon;Animation"));
  90. InsertMenu (SpecialMenu, 0);
  91.  
  92. DrawMenuBar();
  93. }
  94.  
  95. main()                                          /* main() */
  96. {
  97.  
  98. InitWindows();
  99. InitCursor();
  100. InitFonts();
  101. FlushEvents(everyEvent);
  102. InitMenus();
  103. SetUpMenus();
  104. SetRect(&screen,0,20,512,342);
  105. SetRect(&theRect,150,100,362,242);
  106. SetRect(&PictureRect,48,51,464,291);
  107.  
  108.  
  109. while (TRUE) {
  110.     SystemTask();
  111.     if (GetNextEvent(everyEvent,&theEvent))  { 
  112.         switch (theEvent.what)  { 
  113.         
  114.             case keyDown:
  115.                 break;
  116.                 
  117.             case mouseDown: 
  118.                 windowcode=FindWindow(&theEvent.where,&whichWindow);
  119.                 switch (windowcode) {
  120.                     case inDesk:
  121.                         break;
  122.                         
  123.                     case inMenuBar:
  124.                         DoWhatTheMenuSays(MenuSelect(&theEvent.where));
  125.                         break;
  126.                         
  127.                     case inSysWindow:
  128.                         SystemClick(&theEvent,whichWindow);
  129.                         break;
  130.                         
  131.                     case inContent:
  132.                         break;
  133.                         
  134.                     case inDrag:
  135.                         break;
  136.                         
  137.                     case inGrow:
  138.                         break;
  139.                         
  140.                     case inGoAway:
  141.                         break;
  142.                         
  143.                 }   /* end of switch(windowcode) */
  144.                 break;
  145.     
  146.             default:
  147.                 break;
  148.         }    /* end of switch(theEvent.what) */
  149.     }    /* end of if(GetNext...) */
  150. }    /* end of while(True) */
  151. }    /* end of procedure main() */
  152.  
  153.  
  154. DoWhatTheMenuSays(menuResult,)
  155.     long    menuResult;
  156.     {
  157.     short    menuID, itemNumber;
  158.     menuID = HiWord (menuResult);
  159.     itemNumber = LoWord (menuResult);
  160.     
  161.     switch (menuID)
  162.         {
  163.         case Shape_ID:
  164.             switch (itemNumber)
  165.                 {
  166.                 case 1:
  167.                     EraseRect(&screen);
  168.                     break;
  169.                 
  170.                 case 3:
  171.                     FrameRect(&theRect);
  172.                     break;
  173.                 
  174.                 case 4:
  175.                     PaintRect(&theRect);
  176.                     break;
  177.                     
  178.                 case 5:
  179.                     EraseRect(&theRect);
  180.                     break;
  181.                     
  182.                 case 6:
  183.                     InvertRect(&theRect);
  184.                     break;
  185.                 
  186.                 case 7:
  187.                     thePattern = GetPattern(4);
  188.                     FillRect(&theRect,*thePattern);
  189.                     break;
  190.                     
  191.                 case 9:
  192.                     FrameOval(&theRect);
  193.                     break;
  194.                     
  195.                 case 10:
  196.                     PaintOval(&theRect);
  197.                     break;
  198.                     
  199.                 case 11:
  200.                     EraseOval(&theRect);
  201.                     break;
  202.                 
  203.                 case 12:
  204.                     InvertOval(&theRect);
  205.                     break;
  206.                     
  207.                 case 13:
  208.                     thePattern = GetPattern(3);
  209.                     FillOval(&theRect,*thePattern);
  210.                     break;
  211.                 
  212.                 case 15:
  213.                     ExitToShell();
  214.                     break;
  215.                     
  216.             }  /*  end of case shapeMenu  */
  217.             break;  /*  case Shape_ID  */
  218.                     
  219.         case Cursor_ID:
  220.             switch (itemNumber) {
  221.                 case 1:
  222.                     theCursor = GetCursor(1);
  223.                     SetCursor(*theCursor);
  224.                     break;
  225.                         
  226.                 case 2:
  227.                     theCursor = GetCursor(2);
  228.                     SetCursor(*theCursor);
  229.                     break;
  230.                     
  231.                 case 3:
  232.                     theCursor = GetCursor(3);
  233.                     SetCursor(*theCursor);
  234.                     break;
  235.                 
  236.                 case 4:
  237.                     theCursor = GetCursor(4);
  238.                     SetCursor(*theCursor);
  239.                     break;
  240.                 
  241.                 case 5:
  242.                     InitCursor();
  243.                     break;
  244.                     
  245.             }  /*  end of menu CursorMenu  */
  246.             break;
  247.             
  248.         case Desk_ID:
  249.             GetItem(DeskMenu,itemNumber,&DAName);
  250.             OpenDeskAcc(&DAName);
  251.             break;
  252.             
  253.         case Special_ID:
  254.             switch (itemNumber) {
  255.             
  256.                 case 1:
  257.                     thePicture = GetPicture(1);
  258.                     DrawPicture(thePicture,&PictureRect);
  259.                     break;
  260.                     
  261.                 case 2:
  262.                     thePolygon = OpenPoly();
  263.                         MoveTo(300,100);
  264.                         LineTo(400,200);
  265.                         LineTo(200,200);
  266.                         LineTo(300,100);
  267.                     ClosePoly();
  268.                     thePattern = GetPattern(11);
  269.                     FillPoly(thePolygon,*thePattern);
  270.                     FramePoly(thePolygon);
  271.                     KillPoly(thePolygon);
  272.                     break;
  273.                     
  274.                 case 3: 
  275.                     i = 0;
  276.                     HideCursor();
  277.                     EraseRect(&screen);
  278.                     SetRect(&icon1,-33,50,-1,82);
  279.                     saucer1 = GetIcon(1);
  280.                     PlotIcon(&icon1,saucer1);
  281.                     while (i<544)
  282.                     {
  283.                     OffsetRect(&icon1,1,0);
  284.                     PlotIcon(&icon1,saucer1);
  285.                     i++;
  286.                     }
  287.                     ShowCursor();
  288.                     break;
  289.                     
  290.             }  /* end of menu SpecialMenu */
  291.         }  /*  end of switch (menuID)  */
  292.         HiliteMenu(0);
  293.         
  294.     }  /*  end of procedure DoWhatTheMenuSays()  */
  295.  
  296.  
  297.  
  298.  
  299.