home *** CD-ROM | disk | FTP | other *** search
- /*======== Example Source-Code for an external Icon-Renderer =========
-
- (C) Copyright 1997 by Georg Steger.
-
- Created with MaxonCPP 4.0 Pro
-
-
- Description:
- ¯¯¯¯¯¯¯¯¯¯¯¯
- This IconRenderer does a very simple Rendering. But it also shows
- you how to use the UserData in riInitIcon, riRenderIcon and
- riExitIcon. When you iconify a Window opened by the "Workbench"
- Task it will look a little bit different. Try it out!
-
- ====================================================================*/
-
-
- /* OS-Includes */
-
- #include <intuition/intuition.h>
- #include <graphics/gfx.h>
-
- // #pragma header
-
- /* Compiler-Includes */
-
- #include <pragma/intuition_lib.h>
- #include <pragma/graphics_lib.h>
- #include <pragma/exec_lib.h>
- #include <string.h>
-
- /* Program-Includes */
-
- #include "/PWDevelopper.h"
-
-
- /* Vars */
-
- struct GfxBase *GfxBase;
- struct IntuitionBase *IntuitionBase;
-
- static struct Window *IconWin;
- static struct RastPort *rp;
- static struct DrawInfo *di;
- static struct Gadget *gad;
-
- static struct TextExtent MyTE;
- static STRPTR title;
- static WORD a,b,c,slen,x1,y1,x2,y2;
-
- /* Program */
-
- LONG RenderIcon(Msg msg)
- {
- switch (msg->MethodID)
- {
-
- /*========== RI_INIT ===========================================*/
-
- case RI_INIT:
- GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",36);
- IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36);
-
- if ((!GfxBase) || (!IntuitionBase))
- {
- if (GfxBase) CloseLibrary((struct Library *)GfxBase);
- if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
- return RIR_FAIL;
- }
- return RIR_OK;
-
- /*========== RI_EXIT ===========================================*/
-
- case RI_EXIT:
- if (GfxBase) CloseLibrary((struct Library *)GfxBase);
- if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
- return RIR_OK;
-
- /*========== RI_INITICON =======================================*/
-
- case RI_INITICON:
- if (RIINITICON_Msg->WinTask)
- {
- if (strcmp(RIINITICON_Msg->WinTask->tc_Node.ln_Name,"Workbench")==0)
- {
- RIINITICON_Msg->UserData=(APTR)1;
- }
- }
- return RIR_OK;
-
- /*========== RI_EXITICON =======================================*/
-
- case RI_EXITICON:
- return TRUE;
-
- /*========== RI_RENDERICON =====================================*/
-
- case RI_RENDERICON:
- IconWin=RIRENDERICON_Msg->Icon;
- rp=IconWin->RPort;
- di=GetScreenDrawInfo(IconWin->WScreen);
- if (!di) return RIR_FAIL;
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,0,0,IconWin->Width-1,IconWin->Height-1);
- SetAPen(rp,di->dri_Pens[SHINEPEN]);
- RectFill(rp,1,1,IconWin->Width-2,IconWin->Height-2);
- title=RIRENDERICON_Msg->ParentWin->Title;
- if (title)
- {
- a=rp->TxBaseline+(IconWin->Height - rp->TxHeight + 1) / 2;
- b=TextFit(rp,title,strlen(title),&MyTE,0,1,IconWin->Width-4,IconWin->Height);
-
- while (b && (title[b-1]==' ')) b--;
-
- c=(IconWin->Width - TextLength(rp,title,b))/2;
-
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- SetDrMd(rp,JAM1);
-
- Move(rp,c+1,a+1);
- Text(rp,title,b);
- }
-
- if (RIRENDERICON_Msg->UserData == (APTR) 1 )
- {
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,2,2,IconWin->Width-1-2,2);
- RectFill(rp,2,IconWin->Height-1-2,IconWin->Width-1-2,IconWin->Height-1-2);
- }
-
- /* Let's check if there's any Close/Depth-Gadget */
-
- gad=IconWin->FirstGadget;
- while (gad)
- {
- x1=gad->LeftEdge;if (gad->Flags&GFLG_RELRIGHT) x1+=(IconWin->Width-1);
- y1=gad->TopEdge;if (gad->Flags&GFLG_RELBOTTOM) y1+=(IconWin->Height-1);
- x2=x1+gad->Width-1;if (gad->Flags&GFLG_RELWIDTH) x2+=(IconWin->Width);
- y2=y1+gad->Height-1;if (gad->Flags&GFLG_RELHEIGHT) y2+=(IconWin->Height);
-
- if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_CLOSE) /* Close-Gadget found! */
- {
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,x1,y1,x2,y2);
- SetAPen(rp,di->dri_Pens[SHINEPEN]);
- RectFill(rp,x1+1,y1+1,x2-1,y2-1);
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,x1+5,y1+3,x2-5,y2-3);
- } else if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_WDEPTH) /* Depth-Gadget found! */
- {
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,x1,y1,x2,y2);
- SetAPen(rp,di->dri_Pens[SHINEPEN]);
- RectFill(rp,x1+1,y1+1,x2-1,y2-1);
- SetAPen(rp,di->dri_Pens[SHADOWPEN]);
- RectFill(rp,x1+3,y1+3,x1+7,y1+6);
- RectFill(rp,x1+4,y1+4,x1+8,y1+7);
- SetAPen(rp,di->dri_Pens[SHINEPEN]);
- RectFill(rp,x1+5,y1+5,x1+7,y1+6);
- }
- gad=gad->NextGadget;
- }
- FreeScreenDrawInfo(IconWin->WScreen,di);
- return RIR_OK;
-
- default:
- return RIR_FAIL;
- }
- }
-