home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / tools / boot / powerwindows / developper / examples / iconrenderer.c next >
C/C++ Source or Header  |  1997-04-25  |  5KB  |  170 lines

  1. /*======== Example Source-Code for an external Icon-Renderer =========
  2.  
  3.    (C) Copyright 1997 by Georg Steger.
  4.    
  5.        Created with MaxonCPP 4.0 Pro
  6.  
  7.  
  8. Description:
  9. ¯¯¯¯¯¯¯¯¯¯¯¯
  10. This IconRenderer does a very simple Rendering. But it also shows
  11. you how to use the UserData in riInitIcon, riRenderIcon and
  12. riExitIcon. When you iconify a Window opened by the "Workbench"
  13. Task it will look a little bit different. Try it out!
  14.  
  15. ====================================================================*/
  16.  
  17.  
  18. /* OS-Includes */
  19.  
  20. #include <intuition/intuition.h>
  21. #include <graphics/gfx.h>
  22.  
  23. // #pragma header
  24.  
  25. /* Compiler-Includes */
  26.  
  27. #include <pragma/intuition_lib.h>
  28. #include <pragma/graphics_lib.h>
  29. #include <pragma/exec_lib.h>
  30. #include <string.h>
  31.  
  32. /* Program-Includes */
  33.  
  34. #include "/PWDevelopper.h"
  35.  
  36.  
  37. /* Vars */
  38.  
  39. struct GfxBase *GfxBase;
  40. struct IntuitionBase *IntuitionBase;
  41.  
  42. static struct Window *IconWin;
  43. static struct RastPort *rp;
  44. static struct DrawInfo *di;
  45. static struct Gadget *gad;
  46.  
  47. static struct TextExtent MyTE;
  48. static STRPTR title;
  49. static WORD   a,b,c,slen,x1,y1,x2,y2;
  50.  
  51. /* Program */
  52.  
  53. LONG RenderIcon(Msg msg)
  54. {
  55.     switch (msg->MethodID)
  56.     {
  57.  
  58. /*==========  RI_INIT  ===========================================*/
  59.  
  60.         case RI_INIT:
  61.             GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",36);
  62.             IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36);
  63.  
  64.             if ((!GfxBase) || (!IntuitionBase))
  65.             {
  66.                 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  67.                 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  68.                 return RIR_FAIL;
  69.             }
  70.             return RIR_OK;
  71.  
  72. /*==========  RI_EXIT  ===========================================*/
  73.  
  74.         case RI_EXIT:
  75.             if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  76.             if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  77.             return RIR_OK;
  78.  
  79. /*==========  RI_INITICON  =======================================*/
  80.  
  81.         case RI_INITICON:
  82.             if (RIINITICON_Msg->WinTask)
  83.             {
  84.                 if (strcmp(RIINITICON_Msg->WinTask->tc_Node.ln_Name,"Workbench")==0)
  85.                 {
  86.                     RIINITICON_Msg->UserData=(APTR)1;
  87.                 }
  88.             }
  89.             return RIR_OK;
  90.  
  91. /*==========  RI_EXITICON  =======================================*/
  92.  
  93.         case RI_EXITICON:
  94.             return TRUE;
  95.             
  96. /*==========  RI_RENDERICON  =====================================*/
  97.  
  98.         case RI_RENDERICON:
  99.             IconWin=RIRENDERICON_Msg->Icon;
  100.             rp=IconWin->RPort;
  101.             di=GetScreenDrawInfo(IconWin->WScreen);
  102.             if (!di) return RIR_FAIL;
  103.             SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  104.             RectFill(rp,0,0,IconWin->Width-1,IconWin->Height-1);
  105.             SetAPen(rp,di->dri_Pens[SHINEPEN]);
  106.             RectFill(rp,1,1,IconWin->Width-2,IconWin->Height-2);
  107.             title=RIRENDERICON_Msg->ParentWin->Title;
  108.             if (title)
  109.             {
  110.                 a=rp->TxBaseline+(IconWin->Height - rp->TxHeight + 1) / 2;
  111.                 b=TextFit(rp,title,strlen(title),&MyTE,0,1,IconWin->Width-4,IconWin->Height);
  112.                 
  113.                 while (b && (title[b-1]==' ')) b--;
  114.     
  115.                 c=(IconWin->Width - TextLength(rp,title,b))/2;
  116.     
  117.                 SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  118.                 SetDrMd(rp,JAM1);
  119.  
  120.                 Move(rp,c+1,a+1);
  121.                 Text(rp,title,b);                
  122.             }
  123.             
  124.             if (RIRENDERICON_Msg->UserData == (APTR) 1 )
  125.             {
  126.                 SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  127.                 RectFill(rp,2,2,IconWin->Width-1-2,2);
  128.                 RectFill(rp,2,IconWin->Height-1-2,IconWin->Width-1-2,IconWin->Height-1-2);
  129.             }
  130.  
  131.             /* Let's check if there's any Close/Depth-Gadget */
  132.             
  133.             gad=IconWin->FirstGadget;
  134.             while (gad)
  135.             {
  136.                 x1=gad->LeftEdge;if (gad->Flags&GFLG_RELRIGHT) x1+=(IconWin->Width-1);
  137.                 y1=gad->TopEdge;if (gad->Flags&GFLG_RELBOTTOM) y1+=(IconWin->Height-1);
  138.                 x2=x1+gad->Width-1;if (gad->Flags&GFLG_RELWIDTH) x2+=(IconWin->Width);
  139.                 y2=y1+gad->Height-1;if (gad->Flags&GFLG_RELHEIGHT) y2+=(IconWin->Height);
  140.  
  141.                 if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_CLOSE)    /* Close-Gadget found! */
  142.                 {
  143.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  144.                     RectFill(rp,x1,y1,x2,y2);
  145.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  146.                     RectFill(rp,x1+1,y1+1,x2-1,y2-1);
  147.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  148.                     RectFill(rp,x1+5,y1+3,x2-5,y2-3);
  149.                 } else if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_WDEPTH)    /* Depth-Gadget found! */
  150.                 {
  151.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  152.                     RectFill(rp,x1,y1,x2,y2);
  153.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  154.                     RectFill(rp,x1+1,y1+1,x2-1,y2-1);
  155.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  156.                     RectFill(rp,x1+3,y1+3,x1+7,y1+6);
  157.                     RectFill(rp,x1+4,y1+4,x1+8,y1+7);
  158.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  159.                     RectFill(rp,x1+5,y1+5,x1+7,y1+6);
  160.                 }
  161.                 gad=gad->NextGadget;
  162.             }
  163.             FreeScreenDrawInfo(IconWin->WScreen,di);
  164.             return RIR_OK;
  165.  
  166.         default:
  167.             return RIR_FAIL;
  168.     }
  169. }
  170.