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

  1. unit Tools;        {Tool palette stuff goes here}
  2. interface
  3.     uses
  4.         Quickdraw, Picker, Palettes, WindowStuff, Globs, DlogStuff, BMaker;
  5.  
  6.     const
  7.         drawBtnName = 'Draw a Splat';
  8.         clearBtnName = 'Clear Splats';
  9.  
  10.     procedure RefreshToolWind;
  11.     procedure PutUpToolWIND;
  12.     procedure HandleToolContent (where: Point);
  13.     procedure ShowHideTools;
  14.  
  15. implementation
  16.  
  17. {===========================================================================}
  18.     procedure DrawChkBox (chkBoxRect: rect; onOff: Boolean);
  19.         var
  20.             aRect: rect;
  21.     begin
  22.         aRect := chkBoxRect;
  23. {    InsetRect(aRect, 2, 2);}
  24.  
  25.         EraseRect(aRect);
  26.         FrameRect(aRect);
  27.         if onOff then    {if it's 'on', hilite it}
  28.             begin
  29.                 MoveTo(aRect.left, aRect.top);
  30.                 LineTo(aRect.right - 1, aRect.bottom - 1);
  31.                 MoveTo(aRect.right - 1, aRect.top);
  32.                 LineTo(aRect.left, aRect.bottom - 1);
  33.             end;
  34.  
  35.         MoveTo(chkBoxRect.right + 2, chkBoxRect.bottom);
  36.         DrawString('AutoDraw');
  37.     end;    {DrawChkBox}
  38.  
  39.  
  40. {===========================================================================}
  41.     procedure HandleChkBox (chkBoxRect: rect; var onOff: Boolean);
  42.         var
  43.             mouse: point;
  44.             theRect: rect;
  45.             mouseInBtn: boolean;
  46.     begin
  47.         mouseInBtn := FALSE;
  48.  
  49.         theRect := chkBoxRect;
  50.         GetMouse(mouse);
  51.  
  52.         if not PtInRect(mouse, theRect) then
  53.             exit(HandleChkBox);
  54.  
  55.         while StillDown do
  56.             begin
  57.                 GetMouse(mouse);
  58.                 if PtInRect(mouse, theRect) then
  59.                     begin
  60.                         if (not mouseInBtn) then
  61.                             begin
  62.                                 mouseInBtn := TRUE;
  63.                                 onOff := not onOff;
  64.                                 DrawChkBox(theRect, onOff);
  65.                             end
  66.                     end
  67.                 else
  68.                     begin
  69.                         if (mouseInBtn) then
  70.                             begin
  71.                                 mouseInBtn := FALSE;
  72.                                 onOff := not onOff;
  73.                                 DrawChkBox(theRect, onOff);
  74.                             end;
  75.                     end;
  76.  
  77.             end;{while}
  78.  
  79.     end;    {HandleChkBox}
  80.  
  81.  
  82. {===========================================================================}
  83.     procedure VerticalLabel (aRect: Rect; aStr: str255);
  84.         const
  85.             center = 5;    {center of label is 'center' pixels from left of rect}
  86.         var
  87.             numChars, leading, stringCenter, x, curVert: integer;
  88.             fInfo: fontInfo;
  89.     begin
  90.         TextFont(helvetica);
  91.         TextSize(9);
  92.         TextFace([]);
  93.         GetFontInfo(fInfo);
  94.         leading := fInfo.ascent + fInfo.descent + fInfo.leading;
  95.         stringCenter := aRect.left - center;
  96.  
  97.         foreColor(redColor);    {oldStyle color}
  98.         curVert := aRect.top + leading;    {primed for first character}
  99.         numChars := Length(aStr);
  100.         for x := 1 to numChars do
  101.             begin
  102.                 MoveTo(stringCenter - (CharWidth(aStr[x]) div 2), curVert);
  103.                 DrawChar(char(aStr[x]));
  104.                 curVert := curVert + leading;
  105.             end;
  106.         foreColor(blackColor);    {oldStyle color}
  107.     end;    {VerticalLabel}
  108.  
  109.  
  110. {===========================================================================}
  111.     function TrackButtonRect (therect: rect): boolean;
  112. {This function will hilite and unhilite the rectangle you pass it as the user moves}
  113. {the mouse in and out of the rectangle, and returns TRUE if the user released the}
  114. {mouse button while the mouse was inside the rectangle, and FALSE if he/she did}
  115. {not.  This simulates the effect you get when you click on a standard button, and}
  116. {is useful to simulate "icon buttons".  Make sure your GrafPtr is set first!}
  117.         var
  118.             mouseloc: point;
  119.             wasin, check: boolean;
  120.  
  121.     begin
  122.         TrackButtonRect := false;
  123.         invertroundrect(therect, 8, 8);
  124.         wasin := true;
  125.         repeat
  126.             getmouse(mouseLoc);
  127.             check := ptinrect(mouseloc, therect);
  128.             if check <> wasin then
  129.                 begin
  130.                     wasin := check;
  131.                     invertroundrect(therect, 8, 8);
  132.                 end;
  133.         until not stilldown;
  134.         if wasin = true then
  135.             begin
  136.                 invertroundrect(therect, 8, 8);
  137.                 TrackButtonRect := true;
  138.             end;
  139.     end;    {TrackButtonRect}
  140.  
  141. {===========================================================================}
  142.     procedure ShowScrlValue (theControl: ControlHandle);
  143.         var
  144.             aRect: Rect;
  145.             aStr: Str255;
  146.             anInt: integer;
  147.     begin
  148.         aRect := theControl^^.contrlRect;
  149.         aRect.top := aRect.bottom + 2;
  150.         aRect.bottom := aRect.top + 11;
  151.         aRect.left := aRect.left - 4;
  152.         aRect.right := aRect.right + 4;
  153.  
  154.         EraseRect(aRect);
  155.         anInt := GetCtlValue(theControl);
  156.         aStr := Int2String(anInt);
  157.         anInt := StringWidth(aStr) div 2;
  158.         MoveTo(aRect.left + ((aRect.right - aRect.left) div 2 - anInt), aRect.top + 11);
  159.         DrawString(aStr);
  160.  
  161.     end;    {ShowScrlValue}
  162.  
  163.  
  164. {===========================================================================}
  165.     procedure TrackRadScroll (theControl: ControlHandle; partCode: Integer);
  166.         var
  167.             min, max, amount, startValue: Integer;
  168.             up: Boolean;
  169.     begin
  170.         up := partcode in [inUpButton, inPageUp];
  171.         min := GetCtlMin(theControl);
  172.         max := GetCtlMax(theControl);
  173.         startValue := GetCtlValue(theControl);
  174.         if ((up and (startValueuterRadScrl^^.contrlRect;
  175.         VerticalLabel(aRect, 'Radius 2');
  176.  
  177.         ShowScrlValue(divsScrl);
  178.         aRect := divsScrl^^.contrlRect;
  179.         VerticalLabel(aRect, 'Divisions');
  180.  
  181.         anInt := StringWidth(drawBtnName) div 2;
  182.         ClipRect(drawBtnRect);
  183.         MoveTo(drawBtnRect.left + ((drawBtnRect.right - drawBtnRect.left) div 2 - anInt), drawBtnRect.top + 11);
  184.         DrawString(drawBtnName);
  185.         PenSize(1, 1);
  186.         FrameRoundRect(drawBtnRect, 8, 8);
  187.         if curBalloon.autoRedraw then
  188.             begin
  189.                 PenPat(gray);
  190.                 PenMode(patBic);
  191.                 PaintRoundRect(drawBtnRect, 8, 8);
  192.                 PenNormal;
  193.             end;
  194.  
  195.         anInt := StringWidth(clearBtnName) div 2;
  196.         ClipRect(clearBtnRect);
  197.         MoveTo(clearBtnRect.left + ((clearBtnRect.right - clearBtnRect.left) div 2 - anInt), clearBtnRect.top + 11);
  198.         DrawString(clearBtnName);
  199.         PenSize(1, 1);
  200.         FrameRoundRect(clearBtnRect, 8, 8);
  201.  
  202.         PenNormal;
  203.         ClipRect(thePort^.portRect);
  204.  
  205.         DrawChkBox(autoDrawChkBox, curBalloon.autoRedraw);
  206.  
  207.     end;    {RefreshToolWind}
  208.  
  209. {===========================================================================}
  210.     procedure PutUpToolWIND;
  211.         const
  212.             scrollOffset = 12;
  213.         var
  214.             offSet: point;
  215.             x: integer;
  216.     begin
  217.         if hasColorQD then
  218.             begin
  219.                 toolWindPtr := GetNewCWindow(1001, @toolWindowStorage, pointer(-1));
  220.             end
  221.         else
  222.             toolWindPtr := GetNewWindow(1001, @toolWindowStorage, WindowPtr(-1));
  223.  
  224.         showToolWind := TRUE;
  225.  
  226.         SetPort(DrawWindPtr);
  227.         offSet.h := DrawWindPtr^.portRect.left;
  228.         offSet.v := DrawWindPtr^.portRect.top;
  229.         LocalToGlobal(offSet);
  230.  
  231.         SetPort(toolWindPtr);
  232.  
  233.         MoveWindow(toolWindPtr, offSet.h - thePort^.portRect.right - 8, offSet.v - 8, TRUE);
  234.  
  235.         clippingRect := toolWindPtr^.portRect;
  236.         InsetRect(clippingRect, 1, 1);
  237.         ClipRect(clippingRect);
  238.  
  239.         TextFont(helvetica);
  240.         TextSize(9);
  241.  
  242.  
  243.         innerRadScrl := GetNewControl(400, toolWindPtr);
  244.         SizeControl(innerRadScrl, 16, 200);
  245.         MoveControl(innerRadScrl, scrollOffset, 20);
  246.         SetCtlValue(innerRadScrl, curBalloon.innerRadius);
  247.  
  248.         x := innerRadScrl^^.contrlRect.right;
  249.         outerRadScrl := GetNewControl(400, toolWindPtr);
  250.         SizeControl(outerRadScrl, 16, 200);
  251.         MoveControl(outerRadScrl, x + scrollOffset, 20);
  252.         SetCtlValue(outerRadScrl, curBalloon.outerRadius);
  253.  
  254.         x := outerRadScrl^^.contrlRect.right;
  255.         divsScrl := GetNewControl(401, toolWindPtr);
  256.         SizeControl(divsScrl, 16, 200);
  257.         MoveControl(divsScrl, x + scrollOffset, 20);
  258.         SetCtlValue(divsScrl, curBalloon.divisions);
  259.  
  260. {Let's put together our button's rectangle}
  261.         drawBtnRect.left := 16;
  262.         drawBtnRect.top := outerRadScrl^^.contrlRect.bottom + 18;
  263.         drawBtnRect.right := drawBtnRect.left + StringWidth(drawBtnName) + 16;
  264.         drawBtnRect.bottom := drawBtnRect.top + 16;
  265.  
  266.         autoDrawChkBox.left := drawBtnRect.left;
  267.         autoDrawChkBox.top := drawBtnRect.bottom + 4;
  268.         autoDrawChkBox.right := autoDrawChkBox.left + 8;
  269.         autoDrawChkBox.bottom := autoDrawChkBox.top + 8;
  270.  
  271.         clearBtnRect := drawBtnRect;
  272.         OffSetRect(clearBtnRect, 0, drawBtnRect.bottom - drawBtnRect.top + 16);
  273.  
  274.         ShowControl(innerRadScrl);    {allow controls to be seen in public}
  275.         ShowControl(outerRadScrl);
  276.         ShowControl(divsScrl);
  277.  
  278.         ShowWindow(toolWindPtr);
  279.     end;
  280.  
  281.  
  282. end. {Tools}