home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / ClassFree_src.lha / ClassFree_src / CFglyphiclass / class.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-28  |  5.7 KB  |  201 lines

  1. /* Sample class  for StormC*/
  2.  
  3. //#include <proto/alib.h>
  4. #include <proto/exec.h>
  5. #include <proto/intuition.h>
  6. #include <proto/graphics.h>
  7. #include <proto/utility.h>
  8. #include <exec/libraries.h>
  9. #include <exec/memory.h>
  10. #include <graphics/gfxmacros.h>
  11. #include <intuition/classes.h>
  12. #include <dos/dos.h>
  13. #include "class.h"
  14. #include "CFglyphi.h"
  15. #ifdef DEBUG
  16.  #include "debug_protos.h"
  17.  extern APTR console;
  18. #endif
  19.  
  20. Class *initclass(struct classbase *base)
  21. {
  22.   Class *cl;
  23.  
  24.   if(cl = MakeClass(CFglyphiClassName,IMAGECLASS,NULL,
  25.           sizeof(struct objectdata),NULL))
  26.   {
  27.     cl->cl_Dispatcher.h_Entry = hookEntry;
  28.     cl->cl_Dispatcher.h_SubEntry = dispatcher;
  29.     AddClass(cl);
  30.   }
  31.   base->cl = cl;
  32.  
  33.   return(cl);
  34. }
  35.  
  36. BOOL removeclass(struct classbase *base)
  37. {
  38.   BOOL result;
  39.  
  40.   if(result = FreeClass(base->cl)) base->cl = NULL;
  41.  
  42.   return(result);
  43. }
  44.  
  45. ULONG dispatcher(Class *cl,Object *o,Msg msg)
  46. {
  47.   switch(msg->MethodID)
  48.   {
  49.     case OM_NEW:
  50.       return(newobject(cl,o,msg));
  51.     case OM_DISPOSE:
  52.       return(dispose(cl,o));
  53.     case OM_SET:
  54.       return(setattrs(cl,o,msg));
  55.     case IM_DRAW:
  56.       return(draw(cl,o,msg));
  57.     default:
  58.       return(DoSuperMethodA(cl,o,msg));
  59.   }
  60. }
  61.  
  62. ULONG newobject(Class *cl,Object *o,Msg msg)
  63. {
  64.   ULONG newobj,index = 0;
  65.   struct Image *img;
  66.   struct objectdata *dt;
  67.   struct TagItem *attrs = ((struct opSet *)msg)->ops_AttrList;
  68.  
  69.  
  70.   if(newobj = DoSuperMethodA(cl,o,msg))
  71.   {
  72.     dt = (struct objectdata *)INST_DATA(((Class *)o),newobj);
  73.     dt->gtype = GetTagData(CFGI_Type,GLYPH_PDARROW,attrs);
  74.     img = (struct Image *)newobj;
  75.     if(dt->rasbuf = AllocRaster(img->Width,img->Height))
  76.     {
  77.       InitTmpRas(&(dt->tr),dt->rasbuf,img->Width*img->Height/8);
  78.       while(index<MAXVECTORS) dt->vecbuf[index++] = 0;
  79.       InitArea(&(dt->ai),dt->vecbuf,MAXVECTORS);
  80.       return(newobj);
  81.     }
  82.     DoSuperMethod((Class *)o,(Object *)newobj,OM_DISPOSE);
  83.   }
  84.   return(NULL);
  85. }
  86.  
  87. ULONG dispose(Class *cl,Object *o)
  88. {
  89.   struct objectdata *dt = (struct objectdata *)INST_DATA(cl,o);
  90.   struct Image *img = (struct Image *)o;
  91.  
  92.   FreeRaster(dt->rasbuf,img->Width,img->Height);
  93.   DoSuperMethod(cl,o,OM_DISPOSE);
  94.   return(NULL);
  95. }
  96.  
  97. ULONG setattrs(Class *cl,Object *o,Msg msg)
  98. {
  99.   struct opSet *set = (struct opSet *)msg;
  100.   struct TagItem *attrs = set->ops_AttrList;
  101.   struct objectdata *dt = (struct objectdata *)INST_DATA(cl,o);
  102.   struct Image *img = (struct Image *)o;
  103.   ULONG width,height;
  104.  
  105.   width = GetTagData(IA_Width,NULL,attrs);
  106.   height = GetTagData(IA_Height,NULL,attrs);
  107.   if(width||height)
  108.   {
  109.     FreeRaster(dt->rasbuf,img->Width,img->Height);
  110.     dt->rasbuf = AllocRaster(width,height);
  111.     InitTmpRas(&(dt->tr),dt->rasbuf,width*height/8);
  112.   }
  113.   return(DoSuperMethodA(cl,o,msg));
  114. }
  115.  
  116.  
  117. ULONG draw(Class *cl,Object *o,Msg msg)
  118. {
  119.   struct impDraw *draw = (struct impDraw *)msg;
  120.   struct objectdata *dt = (struct objectdata *)INST_DATA(cl,o);
  121.   struct Image *img = (struct Image *)o;
  122.   struct RastPort *rp = draw->imp_RPort;
  123.   UBYTE fgpen = 1,bgpen = 0;
  124.   UWORD *pens = NULL;
  125.   WORD x,y;
  126.  
  127.   if(draw->imp_DrInfo)
  128.   {
  129.     pens = draw->imp_DrInfo->dri_Pens;
  130.     fgpen = pens[SHINEPEN];
  131.     bgpen = pens[SHADOWPEN];
  132.   }
  133.   switch(dt->gtype)
  134.   {
  135.     case GLYPH_PDARROW:
  136.       rp->AreaInfo = &(dt->ai);
  137.       rp->TmpRas = &(dt->tr);
  138.       SetDrMd(rp,JAM1);
  139.       SetAPen(rp,fgpen);
  140.       SetOPen(rp,bgpen);
  141.       x = img->LeftEdge+draw->imp_Offset.X+img->Width/6;
  142.       y = img->TopEdge+draw->imp_Offset.Y+img->Height/5+1;
  143.       AreaMove(rp,x,y);
  144.       x += img->Width/6*2;
  145.       y += img->Height/5*3;
  146.       AreaDraw(rp,x,y);
  147.       x += img->Width/6*2;
  148.       y = img->TopEdge+draw->imp_Offset.Y+img->Height/5+1;
  149.       AreaDraw(rp,x,y);
  150.       AreaEnd(rp);
  151.       break;
  152.     case GLYPH_TREEMORE:
  153.       SetDrPt(rp,0xcccc);
  154.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge);
  155.       Draw(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height-1);
  156.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height/2);
  157.       Draw(rp,img->LeftEdge+img->Width-1,img->TopEdge+img->Height/2);
  158.       SetDrPt(rp,0xffff);
  159.       break;
  160.     case GLYPH_TREEDONE:
  161.       SetDrPt(rp,0xcccc);
  162.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge);
  163.       Draw(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height/2);
  164.       Draw(rp,img->LeftEdge+img->Width-1,img->TopEdge+img->Height/2);
  165.       SetDrPt(rp,0xffff);
  166.       break;
  167.     case GLYPH_TREEMSUB:
  168.       SetDrPt(rp,0xcccc);
  169.       /* Draw 'more'*/
  170.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge);
  171.       Draw(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height-1);
  172.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height/2);
  173.       Draw(rp,img->LeftEdge+img->Width-1,img->TopEdge+img->Height/2);
  174.       /* Draw box */
  175.       Move(rp,img->LeftEdge+img->Width/4,img->TopEdge+img->Height/4);
  176.       Draw(rp,img->LeftEdge+(img->Width*3)/4,img->TopEdge+img->Height/4);
  177.       Draw(rp,img->LeftEdge+(img->Width*3)/4,img->TopEdge+(img->Height*3)/4);
  178.       Draw(rp,img->LeftEdge+img->Width/4,img->TopEdge+(img->Height*3)/4);
  179.       Draw(rp,img->LeftEdge+img->Width/4,img->TopEdge+img->Height/4);
  180.       SetDrPt(rp,0xffff);
  181.       break;
  182.     case GLYPH_TREEDSUB:
  183.       SetDrPt(rp,0xcccc);
  184.       /* Draw 'done' */
  185.       Move(rp,img->LeftEdge+img->Width/2,img->TopEdge);
  186.       Draw(rp,img->LeftEdge+img->Width/2,img->TopEdge+img->Height/2);
  187.       Draw(rp,img->LeftEdge+img->Width-1,img->TopEdge+img->Height/2);
  188.       /* Draw box */
  189.       Move(rp,img->LeftEdge+img->Width/4,img->TopEdge+img->Height/4);
  190.       Draw(rp,img->LeftEdge+(img->Width*3)/4,img->TopEdge+img->Height/4);
  191.       Draw(rp,img->LeftEdge+(img->Width*3)/4,img->TopEdge+(img->Height*3)/4);
  192.       Draw(rp,img->LeftEdge+img->Width/4,img->TopEdge+(img->Height*3)/4);
  193.       Draw(rp,img->LeftEdge+img->Width/4,img->TopEdge+img->Height/4);
  194.       SetDrPt(rp,0xffff);
  195.       break;
  196.   }
  197.  
  198.   return(0);
  199. }
  200.  
  201.