home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-10 | 11.5 KB | 282 lines | [TEXT/PJMM] |
- unit Tools; {Tool palette stuff goes here}
- interface
- uses
- Quickdraw, Picker, Palettes, WindowStuff, Globs, DlogStuff, BMaker;
-
- const
- drawBtnName = 'Draw a Splat';
- clearBtnName = 'Clear Splats';
-
- procedure RefreshToolWind;
- procedure PutUpToolWIND;
- procedure HandleToolContent (where: Point);
- procedure ShowHideTools;
-
- implementation
-
- {===========================================================================}
- procedure DrawChkBox (chkBoxRect: rect; onOff: Boolean);
- var
- aRect: rect;
- begin
- aRect := chkBoxRect;
- { InsetRect(aRect, 2, 2);}
-
- EraseRect(aRect);
- FrameRect(aRect);
- if onOff then {if it's 'on', hilite it}
- begin
- MoveTo(aRect.left, aRect.top);
- LineTo(aRect.right - 1, aRect.bottom - 1);
- MoveTo(aRect.right - 1, aRect.top);
- LineTo(aRect.left, aRect.bottom - 1);
- end;
-
- MoveTo(chkBoxRect.right + 2, chkBoxRect.bottom);
- DrawString('AutoDraw');
- end; {DrawChkBox}
-
-
- {===========================================================================}
- procedure HandleChkBox (chkBoxRect: rect; var onOff: Boolean);
- var
- mouse: point;
- theRect: rect;
- mouseInBtn: boolean;
- begin
- mouseInBtn := FALSE;
-
- theRect := chkBoxRect;
- GetMouse(mouse);
-
- if not PtInRect(mouse, theRect) then
- exit(HandleChkBox);
-
- while StillDown do
- begin
- GetMouse(mouse);
- if PtInRect(mouse, theRect) then
- begin
- if (not mouseInBtn) then
- begin
- mouseInBtn := TRUE;
- onOff := not onOff;
- DrawChkBox(theRect, onOff);
- end
- end
- else
- begin
- if (mouseInBtn) then
- begin
- mouseInBtn := FALSE;
- onOff := not onOff;
- DrawChkBox(theRect, onOff);
- end;
- end;
-
- end;{while}
-
- end; {HandleChkBox}
-
-
- {===========================================================================}
- procedure VerticalLabel (aRect: Rect; aStr: str255);
- const
- center = 5; {center of label is 'center' pixels from left of rect}
- var
- numChars, leading, stringCenter, x, curVert: integer;
- fInfo: fontInfo;
- begin
- TextFont(helvetica);
- TextSize(9);
- TextFace([]);
- GetFontInfo(fInfo);
- leading := fInfo.ascent + fInfo.descent + fInfo.leading;
- stringCenter := aRect.left - center;
-
- foreColor(redColor); {oldStyle color}
- curVert := aRect.top + leading; {primed for first character}
- numChars := Length(aStr);
- for x := 1 to numChars do
- begin
- MoveTo(stringCenter - (CharWidth(aStr[x]) div 2), curVert);
- DrawChar(char(aStr[x]));
- curVert := curVert + leading;
- end;
- foreColor(blackColor); {oldStyle color}
- end; {VerticalLabel}
-
-
- {===========================================================================}
- function TrackButtonRect (therect: rect): boolean;
- {This function will hilite and unhilite the rectangle you pass it as the user moves}
- {the mouse in and out of the rectangle, and returns TRUE if the user released the}
- {mouse button while the mouse was inside the rectangle, and FALSE if he/she did}
- {not. This simulates the effect you get when you click on a standard button, and}
- {is useful to simulate "icon buttons". Make sure your GrafPtr is set first!}
- var
- mouseloc: point;
- wasin, check: boolean;
-
- begin
- TrackButtonRect := false;
- invertroundrect(therect, 8, 8);
- wasin := true;
- repeat
- getmouse(mouseLoc);
- check := ptinrect(mouseloc, therect);
- if check <> wasin then
- begin
- wasin := check;
- invertroundrect(therect, 8, 8);
- end;
- until not stilldown;
- if wasin = true then
- begin
- invertroundrect(therect, 8, 8);
- TrackButtonRect := true;
- end;
- end; {TrackButtonRect}
-
- {===========================================================================}
- procedure ShowScrlValue (theControl: ControlHandle);
- var
- aRect: Rect;
- aStr: Str255;
- anInt: integer;
- begin
- aRect := theControl^^.contrlRect;
- aRect.top := aRect.bottom + 2;
- aRect.bottom := aRect.top + 11;
- aRect.left := aRect.left - 4;
- aRect.right := aRect.right + 4;
-
- EraseRect(aRect);
- anInt := GetCtlValue(theControl);
- aStr := Int2String(anInt);
- anInt := StringWidth(aStr) div 2;
- MoveTo(aRect.left + ((aRect.right - aRect.left) div 2 - anInt), aRect.top + 11);
- DrawString(aStr);
-
- end; {ShowScrlValue}
-
-
- {===========================================================================}
- procedure TrackRadScroll (theControl: ControlHandle; partCode: Integer);
- var
- min, max, amount, startValue: Integer;
- up: Boolean;
- begin
- up := partcode in [inUpButton, inPageUp];
- min := GetCtlMin(theControl);
- max := GetCtlMax(theControl);
- startValue := GetCtlValue(theControl);
- if ((up and (startValue uterRadScrl^^.contrlRect;
- VerticalLabel(aRect, 'Radius 2');
-
- ShowScrlValue(divsScrl);
- aRect := divsScrl^^.contrlRect;
- VerticalLabel(aRect, 'Divisions');
-
- anInt := StringWidth(drawBtnName) div 2;
- ClipRect(drawBtnRect);
- MoveTo(drawBtnRect.left + ((drawBtnRect.right - drawBtnRect.left) div 2 - anInt), drawBtnRect.top + 11);
- DrawString(drawBtnName);
- PenSize(1, 1);
- FrameRoundRect(drawBtnRect, 8, 8);
- if curBalloon.autoRedraw then
- begin
- PenPat(gray);
- PenMode(patBic);
- PaintRoundRect(drawBtnRect, 8, 8);
- PenNormal;
- end;
-
- anInt := StringWidth(clearBtnName) div 2;
- ClipRect(clearBtnRect);
- MoveTo(clearBtnRect.left + ((clearBtnRect.right - clearBtnRect.left) div 2 - anInt), clearBtnRect.top + 11);
- DrawString(clearBtnName);
- PenSize(1, 1);
- FrameRoundRect(clearBtnRect, 8, 8);
-
- PenNormal;
- ClipRect(thePort^.portRect);
-
- DrawChkBox(autoDrawChkBox, curBalloon.autoRedraw);
-
- end; {RefreshToolWind}
-
- {===========================================================================}
- procedure PutUpToolWIND;
- const
- scrollOffset = 12;
- var
- offSet: point;
- x: integer;
- begin
- if hasColorQD then
- begin
- toolWindPtr := GetNewCWindow(1001, @toolWindowStorage, pointer(-1));
- end
- else
- toolWindPtr := GetNewWindow(1001, @toolWindowStorage, WindowPtr(-1));
-
- showToolWind := TRUE;
-
- SetPort(DrawWindPtr);
- offSet.h := DrawWindPtr^.portRect.left;
- offSet.v := DrawWindPtr^.portRect.top;
- LocalToGlobal(offSet);
-
- SetPort(toolWindPtr);
-
- MoveWindow(toolWindPtr, offSet.h - thePort^.portRect.right - 8, offSet.v - 8, TRUE);
-
- clippingRect := toolWindPtr^.portRect;
- InsetRect(clippingRect, 1, 1);
- ClipRect(clippingRect);
-
- TextFont(helvetica);
- TextSize(9);
-
-
- innerRadScrl := GetNewControl(400, toolWindPtr);
- SizeControl(innerRadScrl, 16, 200);
- MoveControl(innerRadScrl, scrollOffset, 20);
- SetCtlValue(innerRadScrl, curBalloon.innerRadius);
-
- x := innerRadScrl^^.contrlRect.right;
- outerRadScrl := GetNewControl(400, toolWindPtr);
- SizeControl(outerRadScrl, 16, 200);
- MoveControl(outerRadScrl, x + scrollOffset, 20);
- SetCtlValue(outerRadScrl, curBalloon.outerRadius);
-
- x := outerRadScrl^^.contrlRect.right;
- divsScrl := GetNewControl(401, toolWindPtr);
- SizeControl(divsScrl, 16, 200);
- MoveControl(divsScrl, x + scrollOffset, 20);
- SetCtlValue(divsScrl, curBalloon.divisions);
-
- {Let's put together our button's rectangle}
- drawBtnRect.left := 16;
- drawBtnRect.top := outerRadScrl^^.contrlRect.bottom + 18;
- drawBtnRect.right := drawBtnRect.left + StringWidth(drawBtnName) + 16;
- drawBtnRect.bottom := drawBtnRect.top + 16;
-
- autoDrawChkBox.left := drawBtnRect.left;
- autoDrawChkBox.top := drawBtnRect.bottom + 4;
- autoDrawChkBox.right := autoDrawChkBox.left + 8;
- autoDrawChkBox.bottom := autoDrawChkBox.top + 8;
-
- clearBtnRect := drawBtnRect;
- OffSetRect(clearBtnRect, 0, drawBtnRect.bottom - drawBtnRect.top + 16);
-
- ShowControl(innerRadScrl); {allow controls to be seen in public}
- ShowControl(outerRadScrl);
- ShowControl(divsScrl);
-
- ShowWindow(toolWindPtr);
- end;
-
-
- end. {Tools}