home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Simple Slideshow / ThreeDEffects.c < prev   
Encoding:
C/C++ Source or Header  |  1996-10-29  |  4.5 KB  |  234 lines  |  [TEXT/CWIE]

  1. /************************************************************************************************
  2. *
  3. *
  4. *        ThreeDEffects.c        - 3D shading effects for user interfaces
  5. *
  6. *
  7. *        15/7/94        ©1994 by Graham Cox
  8. *
  9. *
  10. *************************************************************************************************/
  11.  
  12.  
  13. #include    "ThreeDEffects.h"
  14. #include    <Palettes.h>
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. void    Frame3DRect(Rect *bounds,Boolean zEffectFlag)
  23. {
  24.     /* creates a subtle 3D shade effect by framing the given rect. For best results, the
  25.         background should be set to very very light gray- all components = 0xEEEE
  26.         Works in current port */
  27.     
  28.     GDHandle    mainScreen;
  29.     RGBColor    back,fore;
  30.     RGBColor    white = {0xFFFF,0xFFFF,0xFFFF},black = {0,0,0};
  31.  
  32.     ForeColor(blackColor);
  33.     
  34.     GetForeColor(&fore);
  35.     GetBackColor(&back);
  36.     mainScreen = GetMainDevice();
  37.     GetGray(mainScreen,&back,&fore);
  38.     
  39.     GetGray(mainScreen,&white,&back);
  40.     
  41.     if (zEffectFlag)
  42.         //RGBForeColor(&back);
  43.         ForeColor(whiteColor);
  44.     else
  45.         RGBForeColor(&fore);
  46.     
  47.     MoveTo(bounds->right,bounds->top - 1);
  48.     LineTo(bounds->left - 1,bounds->top - 1);
  49.     LineTo(bounds->left - 1,bounds->bottom);
  50.     
  51.     if (zEffectFlag)
  52.         RGBForeColor(&fore);
  53.     else
  54.         //RGBForeColor(&back);
  55.         ForeColor(whiteColor);
  56.     Move(1,0);
  57.     LineTo(bounds->right,bounds->bottom);
  58.     LineTo(bounds->right,bounds->top);
  59.     ForeColor(blackColor);
  60. }
  61.  
  62.  
  63. void    Frame3DRoundRect(Rect *bounds,short hRadius,short vRadius,Boolean zEffectFlag)
  64. {
  65.     // ditto for roundrects
  66.     GDHandle    mainScreen;
  67.     RGBColor    back,fore;
  68.     RGBColor    white = {0xFFFF,0xFFFF,0xFFFF},black = {0,0,0};
  69.     RgnHandle    saveClip,dClip,bClip;
  70.  
  71.     GetClip(saveClip = NewRgn());
  72.     dClip = NewRgn();
  73.     OpenRgn();
  74.     FrameRoundRect(bounds,hRadius,vRadius);
  75.     CloseRgn(dClip);
  76.     bClip = NewRgn();
  77.     OpenRgn();
  78.     MoveTo(bounds->left,bounds->top);
  79.     LineTo(bounds->right - 1,bounds->bottom -1);
  80.     LineTo(bounds->right - 1,bounds->top);
  81.     LineTo(bounds->left,bounds->top);
  82.     CloseRgn(bClip);
  83.     
  84.     ForeColor(blackColor);
  85.     
  86.     GetForeColor(&fore);
  87.     GetBackColor(&back);
  88.     mainScreen = GetMainDevice();
  89.     GetGray(mainScreen,&back,&fore);
  90.     
  91.     GetGray(mainScreen,&white,&back);
  92.     
  93.     if (zEffectFlag)
  94.         RGBForeColor(&back);
  95.     else
  96.         RGBForeColor(&fore);
  97.     
  98.     SetClip(bClip);
  99.     FrameRoundRect(bounds,hRadius,vRadius);
  100.     if (zEffectFlag)
  101.         RGBForeColor(&fore);
  102.     else
  103.         RGBForeColor(&back);
  104.     
  105.     DiffRgn(dClip,bClip,bClip);
  106.     SetClip(bClip);
  107.     FrameRoundRect(bounds,hRadius,vRadius);
  108.     
  109.     DisposeRgn(dClip);
  110.     DisposeRgn(bClip);    
  111.     
  112.     ForeColor(blackColor);
  113.     SetClip(saveClip);
  114.     DisposeRgn(saveClip);
  115. }
  116.  
  117.  
  118. void    ThreeDLineTo(short h, short v,Boolean zEffectFlag)
  119. {
  120.     // draws a line from the current pen location to h,v. This always draws a 2-pixel wide line
  121.     // with two colours. The effect flag determines which colour is drawn uppermost, to give
  122.     // a 3D effect. Note- works best for horizontal or vertical lines (not angled).
  123.  
  124.     RGBColor    fore,back;
  125.     GDHandle    mainGD;
  126.     Point        pnp;
  127.     Boolean        isVert;
  128.     
  129.     ForeColor(blackColor);
  130.     PenNormal();
  131.     pnp = qd.thePort->pnLoc;
  132.     
  133.     isVert = (h - pnp.h) < (v - pnp.v);
  134.     
  135.     GetForeColor(&fore);
  136.     GetBackColor(&back);
  137.     mainGD = GetMainDevice();
  138.     
  139.     GetGray(mainGD,&back,&fore);
  140.     
  141.     RGBForeColor(&fore);
  142.     
  143.     if (zEffectFlag == kRecessedEmbossed)
  144.         LineTo(h,v);
  145.     else
  146.     {
  147.         if (isVert)
  148.         {
  149.             Move(1,0);
  150.             LineTo(h + 1,v);
  151.         }
  152.         else
  153.         {
  154.             Move(0,1);
  155.             LineTo(h,v + 1);
  156.         }
  157.     }
  158.     
  159.     ForeColor(whiteColor);
  160.     /*
  161.     GetForeColor(&fore);
  162.     GetGray(mainGD,&back,&fore);
  163.     
  164.     RGBForeColor(&fore);
  165.     */
  166.     if (zEffectFlag == kRecessedEmbossed)
  167.     {
  168.         if (isVert)
  169.         {
  170.             Move(1,0);
  171.             LineTo(pnp.h + 1,pnp.v);
  172.         }
  173.         else
  174.         {
  175.             Move(0,1);
  176.             LineTo(pnp.h,pnp.v + 1);
  177.         }
  178.     }
  179.     else
  180.     {
  181.         if (isVert)
  182.             Move(-1,0);
  183.         else
  184.             Move(0,-1);
  185.         LineTo(pnp.h,pnp.v);
  186.     }
  187.     ForeColor(blackColor);
  188.  
  189.  
  190. pascal void    Line3DUserItem(DialogPtr theDialog,short item)
  191. {
  192.     short    itemType;
  193.     Handle    itemHand;
  194.     Rect    itemBox;
  195.     
  196.     GetDItem(theDialog,item,&itemType,&itemHand,&itemBox);
  197.     MoveTo(itemBox.left,itemBox.top);
  198.     ThreeDLineTo(itemBox.right,itemBox.top,kRecessedEmbossed);
  199. }
  200.  
  201.  
  202. void    EngraveRect(Rect* aRect)
  203. {
  204.     // draws a 2-pixel line around the rect, shaded so that it looks like a recessed "engraved"
  205.     // line in the background. The shading is drawn both inside and outside the rect, 1 pix each.
  206.     
  207.     RGBColor    fore,back;
  208.     GDHandle    mainGD;
  209.     
  210.     ForeColor(blackColor);
  211.     
  212.     GetForeColor(&fore);
  213.     GetBackColor(&back);
  214.     mainGD = GetMainDevice();
  215.     GetGray(mainGD,&back,&fore);
  216.     
  217.     ForeColor(whiteColor);
  218.     OffsetRect(aRect,1,1);
  219.     FrameRect(aRect);
  220.     OffsetRect(aRect,-1,-1);
  221.     MoveTo(aRect->right,aRect->top);
  222.     LineTo(aRect->right,aRect->top);
  223.     MoveTo(aRect->left,aRect->bottom);
  224.     LineTo(aRect->left,aRect->bottom);
  225.  
  226.     RGBForeColor(&fore);
  227.     
  228.     FrameRect(aRect);
  229.     ForeColor(blackColor);
  230. }
  231.  
  232.  
  233.