home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Source / tcpalette / Render.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-16  |  4.8 KB  |  224 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include "private.h"
  5. #include "protos.h"
  6.  
  7.  
  8. ULONG __saveds gad_Render(Class *C, struct Gadget *Gad, struct gpRender *Render, ULONG update)
  9. {
  10.   struct GadData *gdata;
  11.   struct RastPort *rp;
  12.   LONG l,left,top,width,height,right,bottom;
  13.   ULONG retval=1;
  14.  
  15.   gdata=INST_DATA(C, Gad);
  16.  
  17.   if(Render->MethodID==GM_RENDER)
  18.   {
  19.     rp=Render->gpr_RPort;
  20.     update=Render->gpr_Redraw;
  21.   }
  22.   else
  23.   {
  24.     rp = ObtainGIRPort(Render->gpr_GInfo);
  25.   }
  26.  
  27.   if(rp)
  28.   {
  29.     if(update == GREDRAW_UPDATE)
  30.     {
  31.       if(gdata->ActivePen != gdata->LastActivePen)
  32.       {
  33.         i_RenderColorBox(C, Gad, Render->gpr_GInfo, rp,gdata->LastActivePen);
  34.  
  35.         gdata->LastActivePen=gdata->ActivePen;
  36.       }
  37.       i_RenderColorBox(C, Gad, Render->gpr_GInfo, rp,gdata->ActivePen);
  38.     }
  39.     else
  40.     {
  41.       SetDrMd(rp,JAM1);
  42.       SetDrPt(rp,65535);
  43.       
  44.       left   =Gad->LeftEdge;
  45.       top    =Gad->TopEdge;
  46.       width  =Gad->Width;
  47.       height =Gad->Height;
  48.       
  49.       right =left + width  -1;
  50.       bottom=top  + height -1;
  51.       
  52.       SetAPen(rp,0);
  53.       SetBPen(rp,1);
  54.       SetDrMd(rp,JAM2);
  55.  
  56.       DrawImage(rp,gdata->Bevel,0,0);
  57. /*  
  58.       SetAttrs(gdata->Pattern,PAT_RastPort,    rp,
  59.                               PAT_DitherAmt,   gdata->ActivePen * 256,
  60.                               TAG_DONE);
  61.   */
  62. //      RectFill(rp,left,top,right,bottom);      
  63.       for(l=0;l<gdata->Pens;l++)
  64.       {
  65.         i_RenderColorBox(C, Gad, Render->gpr_GInfo,rp,l);
  66.       }
  67.     }
  68.     
  69.     if (Render->MethodID != GM_RENDER)
  70.       ReleaseGIRPort(rp);  
  71.   }
  72.   return(retval);
  73. }
  74.  
  75. void i_RenderColorBox(Class *C, struct Gadget *Gad, struct GadgetInfo *gi, struct RastPort *rp, ULONG Pen)
  76. {
  77.   struct DrawInfo *di;
  78.   struct GadData *gdata;
  79.   ULONG row,col,
  80.           left,top,
  81.           width,height,
  82.           bottom,right;
  83.  
  84.   gdata=INST_DATA(C, Gad);
  85.   
  86.   di=gi->gi_DrInfo;
  87.   
  88.   col=Pen % gdata->Cols;
  89.   row=Pen / gdata->Cols;
  90.   
  91.   left    =gdata->Col[col];
  92.   right   =gdata->Col[col+1]-1;
  93.   width   =right-left;
  94.   top     =gdata->Row[row];
  95.   bottom  =gdata->Row[row+1]-1;
  96.   height  =bottom-top;
  97.  
  98. #define SIZE (0)
  99.   
  100.   
  101.   if(Pen==gdata->ActivePen && (((Gad->Flags & GFLG_SELECTED) && gdata->MouseMode) || gdata->ShowSelected))
  102.   {
  103.     if(gdata->EditMode)
  104.     {
  105. //      SetDrPt(rp,0x0f0f);
  106.       
  107. /*      SetAPen(rp, di->dri_Pens[BACKGROUNDPEN]);
  108.  
  109.       Move(rp,left,   bottom);
  110.       Draw(rp,left,   top);
  111.       Draw(rp,right,  top);
  112.       Draw(rp,right,  bottom);
  113.       Draw(rp,left,   bottom);
  114.       
  115.       Move(rp,left+1,   bottom-1);
  116.       Draw(rp,left+1,   top+1);
  117.       Draw(rp,right-1,  top+1);
  118.       Draw(rp,right-1,  bottom-1);
  119.       Draw(rp,left+1,   bottom-1);
  120. */
  121.       SetDrPt(rp,0xF0F0);
  122.     }
  123.  
  124.     SetDrMd(rp,JAM2);
  125.  
  126.     SetBPen(rp, di->dri_Pens[BACKGROUNDPEN]);
  127.     
  128.     SetAPen(rp, di->dri_Pens[SHADOWPEN]);
  129.     Move(rp,left,bottom);
  130.     Draw(rp,left,top);
  131.     Draw(rp,right,top);
  132.     
  133.     SetAPen(rp, di->dri_Pens[SHINEPEN]);
  134.     Draw(rp,right,bottom);
  135.     Draw(rp,left,bottom);
  136.     
  137.     SetAPen(rp, di->dri_Pens[SHADOWPEN]);
  138.     Move(rp,left+1,bottom-1);
  139.     Draw(rp,left+1,top+1);
  140.     Draw(rp,right-1,top+1);
  141.     
  142.     SetAPen(rp, di->dri_Pens[SHINEPEN]);
  143.     Draw(rp,right-1,  bottom-1);
  144.     Draw(rp,left+1,   bottom-1);
  145.  
  146.     SetDrPt(rp,0xFfff);
  147.  
  148.     SetAPen(rp, di->dri_Pens[BACKGROUNDPEN]);
  149.     Move(rp,left+2,bottom-2);
  150.     Draw(rp,left+2,top+2);
  151.     Draw(rp,right-2,top+2);
  152.     Draw(rp,right-2,  bottom-2);
  153.     Draw(rp,left+2,   bottom-2);
  154.  
  155.  
  156.  
  157.     top+=3;
  158.     left+=3;
  159.     right-=3;
  160.     bottom-=3;
  161.   }
  162.   else
  163.   {
  164.     SetAPen(rp, di->dri_Pens[BACKGROUNDPEN]);
  165.     Move(rp,left,bottom);
  166.     Draw(rp,left,top);
  167.     Draw(rp,right,top);
  168.     Draw(rp,right,bottom);
  169.     Draw(rp,left,bottom);
  170. /*
  171.  
  172.     Move(rp,left+1,bottom-1);
  173.     Draw(rp,left+1,top+1);
  174.     Draw(rp,right-1,top+1);
  175.     Draw(rp,right-1,  bottom-1);
  176.     Draw(rp,left+1,   bottom-1);*/
  177.  
  178.     top+=1;
  179.     left+=1;
  180.     right-=1;
  181.     bottom-=1;
  182.   }
  183.  
  184.   width   =right-left+1;
  185.   height  =bottom-top+1;
  186.   
  187.   if(CyberGfxBase && GetBitMapAttr(gi->gi_Screen->RastPort.BitMap, BMA_DEPTH )>8)
  188.   {
  189.     ULONG argb;
  190.     
  191.     argb= ((gdata->Palette[Pen].R & 0xff000000) >> 8) |
  192.           ((gdata->Palette[Pen].G & 0xff000000) >> 16) |
  193.           ((gdata->Palette[Pen].B & 0xff000000) >> 24);
  194.  
  195.     
  196.     FillPixelArray(rp, left, top, width, height, argb);
  197.   }
  198.   else
  199.   {
  200.     ULONG p;
  201.     p=FindColor(gi->gi_Screen->ViewPort.ColorMap, 
  202.                         gdata->Palette[Pen].R,
  203.                         gdata->Palette[Pen].G,
  204.                         gdata->Palette[Pen].B,
  205.                         -1);
  206.     
  207.     SetAPen(rp, p);
  208.     RectFill(rp,left, top, right, bottom);
  209.   }
  210.  
  211.   if(gdata->Disabled)
  212.   {
  213.     gui_GhostRect(rp, gi->gi_DrInfo->dri_Pens[TEXTPEN], left, top, right, bottom);
  214.   }
  215.   
  216.   /*  
  217.   SetAttrs(gdata->Pattern,PAT_RastPort,    rp,
  218.                           PAT_DitherAmt,   gdata->ActivePen * 256,
  219.                           TAG_DONE);
  220. */
  221.  
  222. }
  223.  
  224.