home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Snippets / SplatMaster / BalloonMaker.p < prev    next >
Encoding:
Text File  |  1992-03-10  |  18.1 KB  |  189 lines  |  [TEXT/PJMM]

  1. thetaEndDegrees := 24.0;
  2.         aBalloonRec.theta := 0.0;
  3.         aBalloonRec.iterations := 12;
  4.  
  5.         SetRect(aBalloonRec.statsBox, 1, 1, 120, 40);
  6.         if RealFont(helvetica, 9) then    {decide which font to use}
  7.             aBalloonRec.statsFont := helvetica
  8.         else if RealFont(times, 9) then
  9.             aBalloonRec.statsFont := times
  10.         else
  11.             aBalloonRec.statsFont := 0;    {use System font}
  12.  
  13.         aBalloonRec.maxPtsAllowed := kArraySiz;
  14.         aBalloonRec.numPtsSoFar := 0;
  15.         error := MakeArray(aBalloonRec.myBigArray);
  16.  
  17.     end;    {InitBalloon}
  18.  
  19.  
  20. {======================================================================================= }
  21.     function NewBlnFltr (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  22.         label
  23.             10;
  24.         var
  25.             theRect: Rect;
  26.             aHandle: handle;
  27.             tipe, i: integer;
  28.             myPt: point;
  29.             KeyCh: Char;
  30.     begin
  31.         NewBlnFltr := FALSE;
  32.         ItemHit := 0;
  33.  
  34.         GetMouse(myPt);
  35. {Let's see if we're over any of the ET rects}
  36.         for i := 3 to name_ET do
  37.             begin
  38.                 GetDItem(theDialog, i, tipe, aHandle, theRect);         {get the handle}
  39.                 if PtInRect(myPt, theRect) then
  40.                     if tipe = EditText then
  41.                         begin
  42.                             SetCursor(gIbeam^^);
  43.                             goto 10;
  44.                         end;
  45.             end;{for i}
  46.         InitCursor;                                    {make cursor Arrow if not over any ET rect}
  47. 10:
  48.         case theEvent.what of
  49.             keydown, autoKey: 
  50.                 begin    { trap key down events }
  51.                     KeyCh := Chr(BitAnd(theEvent.message, charCodeMask));
  52.                     if BitAnd(theEvent.modIFiers, CmdKey) <> 0 then    {Cmd key is down}
  53.                         begin
  54.                             ItemHit := -1;    {so the 'v','c', or 'x' won't be 'typed' into text box}
  55.                             if theEvent.what <> AutoKey then    {we don't want to auto-key cmd-key equivs}
  56.                                 case KeyCh of
  57.                                     'x', 'X': 
  58.                                         DlgCut(theDialog);
  59.                                     'c', 'C': 
  60.                                         DlgCopy(theDialog);
  61.                                     'v', 'V': 
  62.                                         DlgPaste(theDialog);
  63.                                     '.': 
  64.                                         begin
  65.                                             itemHit := 2;
  66.                                             ClickButton(theDialog, Cancel);
  67.                                         end;
  68.                                     otherwise
  69.                                         SysBeep(1);    {not a valid Cmd-Key}
  70.                                 end;    {case KeyCh of}
  71.                         end    {if Cmd-key is down}
  72.                     else
  73.                         begin
  74.                             ItemHit := 0;
  75.                             if KeyCh in [char(k_CR), char(k_Enter)] then
  76.                                 ItemHit := Okay;                                { Button equivalents }
  77.                         end;
  78.                 end;{keydown, autokey}
  79.             otherwise
  80.                 ;
  81.         end;{case theEvent.what of}
  82.  
  83.         if ItemHit <> 0 then
  84.             NewBlnFltr := True;           { don't pass back to modal }
  85.  
  86.         if ItemHit = Okay then       { Simulate clicking of the OK button }
  87.             ClickButton(theDialog, Okay);
  88.  
  89.     end;
  90. {===========================================================================}
  91. {    procedure NewBalloon (var aBalloonRec: BalloonRec);}
  92.     procedure NewBalloon;
  93.         var
  94.             OldPort: GrafPtr;
  95.             NewBaloonDLOGPtr: dialogPtr;
  96.             itemHit, Tipe, anInt: integer;
  97.             hdl: Handle;
  98.             theRect: rect;
  99.             aStr: Str255;
  100.             aReal: Real;
  101.             finished: boolean;
  102.  
  103.     begin
  104.         if aBalloonRec.myBigArray <> nil then
  105.             DisposeHandle(Handle(aBalloonRec.myBigArray));
  106.         InitBalloon(aBalloonRec);
  107.         SetCursor(gwatch^^);
  108.         GetPort(OldPort);
  109.         NewBaloonDLOGPtr := GetNewDialog(NewBlnDLOG_ID, nil, Pointer(-1));
  110.  
  111.         CenterWindow(NewBaloonDLOGPtr);
  112.         SetPort(NewBaloonDLOGPtr);
  113.  
  114.         GetDItem(NewBaloonDLOGPtr, innerRad_ET, tipe, hdl, theRect);         {get the handle}
  115.         aStr := Int2String(aBalloonRec.innerRadius);
  116.         SetIText(hdl, aStr);
  117.  
  118.         GetDItem(NewBaloonDLOGPtr, outerRad_ET, tipe, hdl, theRect);         {get the handle}
  119.         aStr := Int2String(aBalloonRec.outerRadius);
  120.         SetIText(hdl, aStr);
  121.  
  122.         GetDItem(NewBaloonDLOGPtr, divisions_ET, tipe, hdl, theRect);         {get the handle}
  123.         aStr := Int2String(aBalloonRec.divisions);
  124.         SetIText(hdl, aStr);
  125.  
  126.         GetDItem(NewBaloonDLOGPtr, name_ET, tipe, hdl, theRect);         {get the handle}
  127.         SetIText(hdl, aBalloonRec.name);
  128.  
  129.         CheckABox(NewBaloonDLOGPtr, autoDraw_Chk, prefs.def_alwaysDraw);
  130.         CheckABox(NewBaloonDLOGPtr, groBox_Chk, prefs.def_alwaysGrowBox);
  131.         CheckABox(NewBaloonDLOGPtr, statsBox_Chk, prefs.def_alwaysStatBox);
  132.  
  133.         InitCursor;
  134.         ShowWindow(NewBaloonDLOGPtr);
  135.         DrawDefaultBtn(Okay, NewBaloonDLOGPtr);    {Outline Default Button}
  136.         SelIText(NewBaloonDLOGPtr, name_ET, 0, 32767);    {pre-doubleclick the item}
  137.  
  138.         finished := FALSE;
  139.  
  140.         repeat
  141.             begin
  142.                 ModalDialog(@NewBlnFltr, itemHit);{Wait until an item is hit}
  143.                 case itemHit of
  144.                     Okay: 
  145.                         begin
  146.                             GetDItem(NewBaloonDLOGPtr, innerRad_ET, tipe, hdl, theRect);         {get the handle}
  147.                             GetIText(hdl, aStr);
  148.                             aBalloonRec.innerRadius := String2Int(aStr);
  149.                             GetDItem(NewBaloonDLOGPtr, outerRad_ET, tipe, hdl, theRect);         {get the handle}
  150.                             GetIText(hdl, aStr);
  151.                             aBalloonRec.outerRadius := String2Int(aStr);
  152.                             GetDItem(NewBaloonDLOGPtr, divisions_ET, tipe, hdl, theRect);         {get the handle}
  153.                             GetIText(hdl, aStr);
  154.                             aBalloonRec.divisions := String2Int(aStr);
  155.                             GetDItem(NewBaloonDLOGPtr, name_ET, tipe, hdl, theRect);         {get the handle}
  156.                             GetIText(hdl, aStr);
  157.                             aBalloonRec.name := aStr;
  158.                             finished := TRUE;
  159.                         end;
  160.                     Cancel: 
  161.                         begin
  162.                             finished := TRUE;
  163.                         end;
  164.                     autoDraw_Chk: 
  165.                         begin
  166.                             prefs.def_alwaysDraw := not prefs.def_alwaysDraw;
  167.                             CheckABox(NewBaloonDLOGPtr, autoDraw_Chk, prefs.def_alwaysDraw);
  168.                         end;
  169.                     groBox_Chk: 
  170.                         begin
  171.                             prefs.def_alwaysGrowBox := not prefs.def_alwaysGrowBox;
  172.                             CheckABox(NewBaloonDLOGPtr, groBox_Chk, prefs.def_alwaysGrowBox);
  173.                         end;
  174.                     statsBox_Chk: 
  175.                         begin
  176.                             prefs.def_alwaysStatBox := not prefs.def_alwaysStatBox;
  177.                             CheckABox(NewBaloonDLOGPtr, statsBox_Chk, prefs.def_alwaysStatBox);
  178.                         end;
  179.                     otherwise
  180.                         ;
  181.                 end{case}
  182.             end;{begin}
  183.         until finished;
  184.  
  185.         DisposDialog(NewBaloonDLOGPtr);{Flush the dialog out of memory}
  186.         setPort(oldPort);
  187.  
  188.     end;    {NewBalloon}
  189. end.    {BMaker}