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

  1. /*======== Example Source-Code for an external Window-Checker =========
  2.  
  3.    (C) Copyright 1997 by Steger Georg.
  4.    
  5.        Created with MaxonCPP 4.0 Pro
  6.  
  7.  
  8. Description:
  9. ¯¯¯¯¯¯¯¯¯¯¯¯
  10. This Windowchecker uses a Routine very similiar to the
  11. standard one of PowerWindows. It also replaces the Look
  12. of the Iconify-Gadget. You will get a little nice Smiley!
  13. It looks a little bit strange on Lowres-Screens, but hey,
  14. this is only an Example!!
  15.  
  16. ====================================================================*/
  17.  
  18.  
  19. /* OS-Includes */
  20.  
  21. #include <intuition/intuition.h>
  22. #include <intuition/imageclass.h>
  23. #include <graphics/gfx.h>
  24.  
  25. // #pragma header
  26.  
  27. /* Compiler-Includes */
  28.  
  29. #include <pragma/intuition_lib.h>
  30. #include <pragma/graphics_lib.h>
  31. #include <pragma/exec_lib.h>
  32. #include <string.h>
  33.  
  34. /* Program-Includes */
  35.  
  36. #include "/PWDevelopper.h"
  37.  
  38. /* Macros */
  39.  
  40. #define CWDRAWIMAGE_Msg    (((struct cwRenderIG *)msg)->DrawImageMsg)
  41. #define IG_IMAGE             (((struct cwRenderIG *)msg)->GadImage)
  42. #define IG_RP                (((struct cwRenderIG *)msg)->DrawImageMsg->imp_RPort)
  43. #define DRI_PENS            di->dri_Pens
  44.  
  45. /* Vars */
  46.  
  47. struct GfxBase *GfxBase;
  48. struct IntuitionBase *IntuitionBase;
  49.  
  50. /* Program */
  51.  
  52. LONG CheckWindow(Msg msg)
  53. {
  54.     struct DrawInfo *di;
  55.     struct Gadget *gad;
  56.  
  57.     WORD x1,y1,x2,y2,width,leftmost,state;
  58.     BYTE IsInactive,IsSelected;
  59.  
  60.     switch (msg->MethodID)
  61.     {
  62.  
  63. /*==========  CW_INIT  ===========================================*/
  64.  
  65.         case CW_INIT:
  66.             GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",36);
  67.             if (!GfxBase) return RIR_FAIL;
  68.             return CWR_OK;
  69.  
  70. /*==========  CW_EXIT  ===========================================*/
  71.  
  72.         case CW_EXIT:
  73.             if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  74.             return CWR_OK;
  75.  
  76. /*==========  CW_CHECK  ==========================================*/
  77.  
  78.         case CW_CHECK:
  79.             gad=CWCHECK_Msg->Win->FirstGadget;
  80.         
  81.             x1=0;y1=0;width=0;leftmost=1;
  82.             while (gad)
  83.             {
  84.                 x1++;
  85.                 if (gad->GadgetType>YP_SYSTYPEMASK)
  86.                 {
  87.                     if (!y1) y1=x1;
  88.                 }
  89.                 
  90.                 if ((gad->TopEdge==0) && (gad->Flags&GFLG_RELRIGHT) && (!(gad->Flags&(GFLG_RELWIDTH|GFLG_RELHEIGHT|GFLG_RELBOTTOM))))
  91.                 {
  92.                     if (((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_WDEPTH) ||
  93.                         ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_WZOOM))
  94.                     {
  95.                         width=gad->Width;
  96.                     }
  97.                     if (gad->LeftEdge<leftmost)
  98.                     {
  99.                         leftmost=gad->LeftEdge;
  100.                     }
  101.                 }
  102.                 gad=gad->NextGadget;
  103.             }
  104.         
  105.             if (!width)
  106.                 width=24;
  107.  
  108.             CWCHECK_Msg->Gad_LeftEdge=leftmost-width+1;
  109.             CWCHECK_Msg->Gad_TopEdge=0;
  110.             CWCHECK_Msg->Gad_Width=width;
  111.             CWCHECK_Msg->Gad_Height=CWCHECK_Msg->Win->BorderTop;
  112.             CWCHECK_Msg->Gad_Flags=GFLG_RELRIGHT;
  113.             CWCHECK_Msg->Gad_Position=y1;
  114.             return CWR_OK|CWR_ICONIFYGAD|CWR_ICONIFYPOS;
  115.  
  116. /*==========  CW_RENDERIG  =======================================*/
  117.  
  118.         case CW_RENDERIG:
  119.             if ((di=CWRENDERIG_Msg->DrawImageMsg->imp_DrInfo))
  120.             {
  121.                 x1=CWDRAWIMAGE_Msg->imp_Offset.X+IG_IMAGE->LeftEdge;
  122.                 y1=CWDRAWIMAGE_Msg->imp_Offset.Y+IG_IMAGE->TopEdge;
  123.                 x2=x1-1+(CWDRAWIMAGE_Msg->MethodID==IM_DRAW ? IG_IMAGE->Width : CWDRAWIMAGE_Msg->imp_Dimensions.Width);
  124.                 y2=y1-1+(CWDRAWIMAGE_Msg->MethodID==IM_DRAW ? IG_IMAGE->Height : CWDRAWIMAGE_Msg->imp_Dimensions.Height);
  125.                 
  126.                 state=CWDRAWIMAGE_Msg->imp_State;
  127.                 
  128.                 IsInactive=((state==IDS_INACTIVENORMAL) || (state==IDS_INACTIVESELECTED) || (state==IDS_INACTIVEDISABLED));
  129.                 IsSelected=((state==IDS_SELECTED) || (state==IDS_INACTIVESELECTED) || (state==IDS_SELECTEDDISABLED));
  130.     
  131.                 /* Standard Frame */
  132.  
  133.                 SetAPen(IG_RP,DRI_PENS[IsInactive ? BACKGROUNDPEN : FILLPEN]);
  134.                 RectFill(IG_RP,x1+2,y1+1,x2-1,y2-1);
  135.                 SetAPen(IG_RP,DRI_PENS[SHADOWPEN]);
  136.                 RectFill(IG_RP,x1,y1+1,x1,y2-1);
  137.             
  138.                 SetAPen(IG_RP,DRI_PENS[IsSelected ? SHADOWPEN : SHINEPEN]);
  139.                 RectFill(IG_RP,x1+1,y1,x1+1,y2-1);
  140.                 RectFill(IG_RP,x1,y1,x2,y1);
  141.                 SetAPen(IG_RP,DRI_PENS[IsSelected ? SHINEPEN : SHADOWPEN]);
  142.                 RectFill(IG_RP,x2,y1+1,x2,y2);
  143.                 RectFill(IG_RP,x1+1,y2,x2-1,y2);
  144.  
  145.                 /* let's draw a Smiley!! */
  146.                 
  147.                 SetAPen(IG_RP,DRI_PENS[SHADOWPEN]);
  148.                 RectFill(IG_RP,x1+5,y1+3,x1+9,y1+7);
  149.                 RectFill(IG_RP,x2-8,y1+3,x2-4,y1+7);
  150.                 
  151.                 SetAPen(IG_RP,DRI_PENS[IsInactive ? BACKGROUNDPEN : SHINEPEN]);
  152.                 
  153.                 RectFill(IG_RP,x1+6,y1+5-(IsSelected ? 0 : 1),x1+8,y1+6);
  154.                 RectFill(IG_RP,x2-7,y1+5-(IsSelected ? 0 : 1),x2-5,y1+6);
  155.                 
  156.                 SetAPen(IG_RP,DRI_PENS[SHADOWPEN]);
  157.                 WritePixel(IG_RP,x1+7,y1+5);
  158.                 WritePixel(IG_RP,x2-6,y1+5);
  159.                 if (IsSelected)
  160.                 {
  161.                     RectFill(IG_RP,x1+8,y2-5,x2-7,y2-3);
  162.                     SetAPen(IG_RP,DRI_PENS[IsInactive ? BACKGROUNDPEN : SHINEPEN]);
  163.                     RectFill(IG_RP,x1+9,y2-4,x2-8,y2-4);
  164.                 } else {
  165.                     RectFill(IG_RP,x1+8,y2-5,x2-7,y2-3);
  166.                     RectFill(IG_RP,x1+6,y2-6,x1+9,y2-4);
  167.                     RectFill(IG_RP,x2-8,y2-6,x2-5,y2-4);
  168.                     SetAPen(IG_RP,DRI_PENS[IsInactive ? BACKGROUNDPEN : SHINEPEN]);
  169.                     RectFill(IG_RP,x1+9,y2-4,x2-8,y2-4);
  170.                     RectFill(IG_RP,x1+7,y2-5,x1+8,y2-5);
  171.                     RectFill(IG_RP,x2-7,y2-5,x2-6,y2-5);
  172.                 }
  173.             }
  174.  
  175.             return CWR_OK;
  176.             
  177. /*==========  default  ===========================================*/
  178.  
  179.         default:
  180.             return CWR_FAIL;
  181.     }
  182. }
  183.  
  184.