home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / pufferfish / source / bsclass.c next >
C/C++ Source or Header  |  1994-02-13  |  5KB  |  197 lines

  1. /*
  2.  * BoxedStringClass.c
  3.  *
  4.  * Thanks to Mike Stark for this code!
  5.  *
  6.  * NOTE: I've renamed MakeMyBoopsiClasses and FreeMyBoopsiClasses to
  7.  *       MakeBoxedStringClass and FreeBoxedStringClass, respectively.
  8.  *
  9.  * Also, from the message I received from Mike:
  10.  * > It doesn't handle resetting the gadget shape after creation but
  11.  * > other than that it works fine.
  12.  * ...
  13.  * > Actually, I discovered a new problem.  The box won't draw right if
  14.  * > the gadget was defined with GA_RelRight, GA_RelBottom, GA_RelWidth
  15.  * > or GA_RelHeight.
  16.  *
  17.  * Neither of these are used, so I haven't bothered with them.  Users
  18.  * modifying this code should be aware of these issues, though.
  19.  *
  20.  */
  21. #include <exec/types.h>
  22.  
  23. #include <intuition/intuition.h>
  24. #include <intuition/classes.h>
  25. #include <intuition/cghooks.h>
  26. #include <intuition/gadgetclass.h>
  27.  
  28. #include <clib/alib_protos.h>
  29. #include <clib/graphics_protos.h>
  30. #include <clib/intuition_protos.h>
  31.  
  32. #include "PufferFish.h"
  33.  
  34. /*
  35.  *  Function prototypes for this module.
  36.  */
  37. ULONG __saveds DispatchBoxedString(Class *, Object *, Msg);
  38. ULONG BSC_New(Class *cl, Object *o, struct opSet *ops);
  39. ULONG BSC_Update(Class *cl, Object *o, struct opUpdate *opu);
  40. ULONG BSC_Render(Class *cl, struct Gadget *Gad, struct gpRender *msg);
  41. void MyDrawBox(struct RastPort *RPort, WORD LeftEdge, WORD TopEdge, WORD Width,
  42.     WORD Height, WORD shine, WORD shadow);
  43.  
  44. /*
  45.  *  The class definitions contained inthis module.
  46.  */
  47.  
  48. Class *BoxedStringClass = NULL;
  49.  
  50. ULONG __saveds DispatchBoxedString(Class *cl, Object *o, Msg msg)
  51. /*************************\
  52. *   DispatchBoxedString   *
  53. *   ------------------    *
  54. *      The dispatcher for the BoxedStringClass gadget,
  55. \*************************/
  56. {
  57.     ULONG Answer = FALSE;
  58.     
  59.     switch(msg->MethodID)
  60.     {
  61.         case OM_NEW:
  62.             Answer = BSC_New(cl, o, (struct opSet *)msg);
  63.             break;
  64.         case OM_UPDATE:
  65.             Answer = BSC_Update(cl, o, (struct opUpdate *)msg);
  66.             break;
  67.         case GM_RENDER:
  68.             Answer = BSC_Render(cl, (struct Gadget *)o, (struct gpRender *)msg);
  69.             break;
  70.         default:
  71.             Answer = DoSuperMethodA(cl, o, msg);
  72.             break;
  73.     }
  74.     return Answer;
  75. }
  76.  
  77. ULONG BSC_New(Class *cl, Object *o, struct opSet *ops)
  78.  
  79. {
  80.     struct Gadget *gad;
  81.     
  82.     if (gad = (struct Gadget *)DoSuperMethodA(cl, o, (Msg)ops))
  83.     {
  84.         gad->LeftEdge += 4;
  85.         gad->TopEdge += 2;
  86.         gad->Width -= 8;
  87.         gad->Height -= 4;
  88.     }
  89.     return (ULONG)gad;
  90. }
  91.  
  92. ULONG BSC_Render(Class *cl, struct Gadget *Gad, struct gpRender *msg)
  93. {
  94.     struct RastPort *RPort;
  95.     UWORD *pens, shine, shadow;
  96.     ULONG Answer;
  97.     
  98.     Answer = DoSuperMethodA(cl, (Object *)Gad, (Msg)msg);
  99.     if (msg->gpr_Redraw == GREDRAW_REDRAW)
  100.     {
  101.         if (msg->MethodID == GM_RENDER)
  102.         {
  103.             RPort = msg->gpr_RPort;
  104.         }
  105.         else
  106.         {
  107.             RPort = ObtainGIRPort(msg->gpr_GInfo);
  108.         }
  109.         if (msg)
  110.         {
  111.             if (msg->gpr_GInfo)
  112.             {
  113.                 if (msg->gpr_GInfo->gi_DrInfo)
  114.                 {
  115.                     pens = (UWORD *)msg->gpr_GInfo->gi_DrInfo->dri_Pens;
  116.                 }
  117.             }
  118.         }
  119.         if (RPort)
  120.         {
  121.             shine = pens[SHINEPEN];
  122.             shadow = pens[SHADOWPEN];
  123.             MyDrawBox(RPort, Gad->LeftEdge - 4, Gad->TopEdge - 2, Gad->Width + 8,
  124.                 Gad->Height + 4, shine, shadow);
  125.             MyDrawBox(RPort, Gad->LeftEdge - 2, Gad->TopEdge - 1, Gad->Width + 4,
  126.                 Gad->Height + 2, shadow, shine);
  127.             if (msg->MethodID != GM_RENDER)
  128.             {
  129.                 ReleaseGIRPort(RPort);
  130.             }
  131.         }
  132.     }
  133.     return Answer;
  134. }
  135.  
  136. ULONG BSC_Update(Class *cl, Object *o, struct opUpdate *opu)
  137. {
  138.     struct RastPort *RPort;
  139.     ULONG Answer;
  140.     
  141.     Answer = DoSuperMethodA(cl, o, (Msg)opu);
  142.     if (RPort = ObtainGIRPort(opu->opu_GInfo))
  143.     {
  144.         (void)DoMethod(o, GM_RENDER, opu->opu_GInfo, RPort,
  145.             GREDRAW_UPDATE, 0);
  146.         ReleaseGIRPort(RPort);
  147.     }
  148.     return Answer;
  149. }
  150.  
  151. void MakeBoxedStringClass(void)
  152. /*************************\
  153. *   MakeBoxedStringClass  *
  154. *   -------------------   *
  155. *      Creates the boopsi classes defined in this file.
  156. \*************************/
  157. {
  158.     ULONG __saveds DispatchBoxedString();
  159.     ULONG HookEntry();
  160.     
  161.     if (BoxedStringClass = MakeClass(NULL, (UBYTE *)"strgclass", NULL, 0, 0))
  162.     {
  163.         BoxedStringClass->cl_Dispatcher.h_Entry = HookEntry;
  164.         BoxedStringClass->cl_Dispatcher.h_SubEntry = DispatchBoxedString;
  165.     }
  166. }
  167.  
  168. void FreeBoxedStringClass(void)
  169. /*************************\
  170. *   FreeBoxedStringClass  *
  171. *   -------------------   *
  172. *      Deletes the boopsi classes defined in this file.
  173. \*************************/
  174. {
  175.     if (BoxedStringClass)
  176.     {
  177.         FreeClass(BoxedStringClass);
  178.     }
  179. }
  180.  
  181. void MyDrawBox(struct RastPort *RPort, WORD LeftEdge, WORD TopEdge, WORD Width,
  182.       WORD Height, WORD shine, WORD shadow)
  183. {
  184.     SetAPen(RPort, shine);
  185.     Move(RPort, LeftEdge, TopEdge + Height - 1);
  186.     Draw(RPort, LeftEdge, TopEdge);
  187.     Draw(RPort, LeftEdge + Width - 2, TopEdge);
  188.     Move(RPort, LeftEdge + 1, TopEdge + 1);
  189.     Draw(RPort, LeftEdge + 1, TopEdge + Height - 2);
  190.     SetAPen(RPort, shadow);
  191.     Move(RPort, LeftEdge + 1, TopEdge + Height - 1);
  192.     Draw(RPort, LeftEdge + Width - 1, TopEdge + Height - 1);
  193.     Draw(RPort, LeftEdge + Width - 1, TopEdge);
  194.     Move(RPort, LeftEdge + Width - 2, TopEdge + Height - 2);
  195.     Draw(RPort, LeftEdge + Width - 2, TopEdge + 1);
  196. }
  197.