home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************
- *
- *
- * ThreeDEffects.c - 3D shading effects for user interfaces
- *
- *
- * 15/7/94 ©1994 by Graham Cox
- *
- *
- *************************************************************************************************/
-
-
- #include "ThreeDEffects.h"
- #include <Palettes.h>
-
-
-
-
-
-
-
- void Frame3DRect(Rect *bounds,Boolean zEffectFlag)
- {
- /* creates a subtle 3D shade effect by framing the given rect. For best results, the
- background should be set to very very light gray- all components = 0xEEEE
- Works in current port */
-
- GDHandle mainScreen;
- RGBColor back,fore;
- RGBColor white = {0xFFFF,0xFFFF,0xFFFF},black = {0,0,0};
-
- ForeColor(blackColor);
-
- GetForeColor(&fore);
- GetBackColor(&back);
- mainScreen = GetMainDevice();
- GetGray(mainScreen,&back,&fore);
-
- GetGray(mainScreen,&white,&back);
-
- if (zEffectFlag)
- //RGBForeColor(&back);
- ForeColor(whiteColor);
- else
- RGBForeColor(&fore);
-
- MoveTo(bounds->right,bounds->top - 1);
- LineTo(bounds->left - 1,bounds->top - 1);
- LineTo(bounds->left - 1,bounds->bottom);
-
- if (zEffectFlag)
- RGBForeColor(&fore);
- else
- //RGBForeColor(&back);
- ForeColor(whiteColor);
- Move(1,0);
- LineTo(bounds->right,bounds->bottom);
- LineTo(bounds->right,bounds->top);
- ForeColor(blackColor);
- }
-
-
- void Frame3DRoundRect(Rect *bounds,short hRadius,short vRadius,Boolean zEffectFlag)
- {
- // ditto for roundrects
- GDHandle mainScreen;
- RGBColor back,fore;
- RGBColor white = {0xFFFF,0xFFFF,0xFFFF},black = {0,0,0};
- RgnHandle saveClip,dClip,bClip;
-
- GetClip(saveClip = NewRgn());
- dClip = NewRgn();
- OpenRgn();
- FrameRoundRect(bounds,hRadius,vRadius);
- CloseRgn(dClip);
- bClip = NewRgn();
- OpenRgn();
- MoveTo(bounds->left,bounds->top);
- LineTo(bounds->right - 1,bounds->bottom -1);
- LineTo(bounds->right - 1,bounds->top);
- LineTo(bounds->left,bounds->top);
- CloseRgn(bClip);
-
- ForeColor(blackColor);
-
- GetForeColor(&fore);
- GetBackColor(&back);
- mainScreen = GetMainDevice();
- GetGray(mainScreen,&back,&fore);
-
- GetGray(mainScreen,&white,&back);
-
- if (zEffectFlag)
- RGBForeColor(&back);
- else
- RGBForeColor(&fore);
-
- SetClip(bClip);
- FrameRoundRect(bounds,hRadius,vRadius);
- if (zEffectFlag)
- RGBForeColor(&fore);
- else
- RGBForeColor(&back);
-
- DiffRgn(dClip,bClip,bClip);
- SetClip(bClip);
- FrameRoundRect(bounds,hRadius,vRadius);
-
- DisposeRgn(dClip);
- DisposeRgn(bClip);
-
- ForeColor(blackColor);
- SetClip(saveClip);
- DisposeRgn(saveClip);
- }
-
-
- void ThreeDLineTo(short h, short v,Boolean zEffectFlag)
- {
- // draws a line from the current pen location to h,v. This always draws a 2-pixel wide line
- // with two colours. The effect flag determines which colour is drawn uppermost, to give
- // a 3D effect. Note- works best for horizontal or vertical lines (not angled).
-
- RGBColor fore,back;
- GDHandle mainGD;
- Point pnp;
- Boolean isVert;
-
- ForeColor(blackColor);
- PenNormal();
- pnp = qd.thePort->pnLoc;
-
- isVert = (h - pnp.h) < (v - pnp.v);
-
- GetForeColor(&fore);
- GetBackColor(&back);
- mainGD = GetMainDevice();
-
- GetGray(mainGD,&back,&fore);
-
- RGBForeColor(&fore);
-
- if (zEffectFlag == kRecessedEmbossed)
- LineTo(h,v);
- else
- {
- if (isVert)
- {
- Move(1,0);
- LineTo(h + 1,v);
- }
- else
- {
- Move(0,1);
- LineTo(h,v + 1);
- }
- }
-
- ForeColor(whiteColor);
- /*
- GetForeColor(&fore);
- GetGray(mainGD,&back,&fore);
-
- RGBForeColor(&fore);
- */
- if (zEffectFlag == kRecessedEmbossed)
- {
- if (isVert)
- {
- Move(1,0);
- LineTo(pnp.h + 1,pnp.v);
- }
- else
- {
- Move(0,1);
- LineTo(pnp.h,pnp.v + 1);
- }
- }
- else
- {
- if (isVert)
- Move(-1,0);
- else
- Move(0,-1);
- LineTo(pnp.h,pnp.v);
- }
- ForeColor(blackColor);
- }
-
-
- pascal void Line3DUserItem(DialogPtr theDialog,short item)
- {
- short itemType;
- Handle itemHand;
- Rect itemBox;
-
- GetDItem(theDialog,item,&itemType,&itemHand,&itemBox);
- MoveTo(itemBox.left,itemBox.top);
- ThreeDLineTo(itemBox.right,itemBox.top,kRecessedEmbossed);
- }
-
-
- void EngraveRect(Rect* aRect)
- {
- // draws a 2-pixel line around the rect, shaded so that it looks like a recessed "engraved"
- // line in the background. The shading is drawn both inside and outside the rect, 1 pix each.
-
- RGBColor fore,back;
- GDHandle mainGD;
-
- ForeColor(blackColor);
-
- GetForeColor(&fore);
- GetBackColor(&back);
- mainGD = GetMainDevice();
- GetGray(mainGD,&back,&fore);
-
- ForeColor(whiteColor);
- OffsetRect(aRect,1,1);
- FrameRect(aRect);
- OffsetRect(aRect,-1,-1);
- MoveTo(aRect->right,aRect->top);
- LineTo(aRect->right,aRect->top);
- MoveTo(aRect->left,aRect->bottom);
- LineTo(aRect->left,aRect->bottom);
-
- RGBForeColor(&fore);
-
- FrameRect(aRect);
- ForeColor(blackColor);
- }
-
-
-