
#include <stdlib.h>
#include <stdio.h>
#include <proto/intuition.h>
#include <intuition/intuition.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/layers.h>
#include <libraries/gadtools.h>

#ifndef GUINAME
#include "test.h"
#else
#include GUINAME
#endif

#include <graphics/gfxmacros.h>

extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
extern struct Library *GadToolsBase;

struct LMsg {
   struct Layer *Layer;
   WORD   MinX,MinY;
   WORD   MaxX,MaxY;
   LONG OffsetX,OffsetY;
};

ULONG __interrupt __saveds __asm HookFunc(register __a0 struct Hook *hook,
                                 register __a2 struct RastPort *rastport,
                                 register __a1 struct LMsg *msg)
{
   struct RastPort rp=*rastport;

   static __chip USHORT bitmap[]={0xaaaa,0x5555,0xaaaa};

   rp.Layer=NULL;

   SetAPen(&rp,0);
   SetBPen(&rp,2);
   SetDrMd(&rp,JAM2);

   /* Adjust the pattern to the window position */

   if((msg->MinX ^ msg->MinY ^ msg->OffsetX ^ msg->OffsetY) & 1)
                                         {SetAfPt(&rp,(bitmap+1),1);} else
                                         {SetAfPt(&rp,bitmap,1);}

   RectFill(&rp,msg->MinX,msg->MinY,msg->MaxX,msg->MaxY);

   return(0);
}


main()
{
   struct IntuiMessage msg;
   struct Window *win;
   int run=1;

   struct Hook hook;

   hook.h_Entry=(HOOKFUNC)HookFunc;
   hook.h_SubEntry=NULL;

   win=OpenWindowTags(NULL,
            WA_Left,0,WA_Top,20,
            WA_Width,300,WA_Height,100,
            WA_Title,TITLE,
            WA_IDCMP,BUTTONIDCMP|IDCMP_CLOSEWINDOW|SLIDERIDCMP|
                     IDCMP_NEWSIZE|IDCMP_REFRESHWINDOW,
            WA_Flags,WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET
                        |WFLG_SIMPLE_REFRESH
                        |WFLG_CLOSEGADGET|WFLG_ACTIVATE,
            WA_MinWidth,300,WA_MinHeight,100,
            WA_MaxWidth,-1,WA_MaxHeight,-1,
            WA_BackFill,&hook,
            TAG_DONE );

   if(!win) exit(0);

   if(RenderGui(win,&TestPro)) {CloseWindow(win);exit(0);}

   while(run) {
      WaitPort(win->UserPort);
      while(Gui_GetIMsg(win->UserPort,&msg)) {
         switch(msg.Class) {
            case IDCMP_CLOSEWINDOW: run=0;
                                    break;
            case IDCMP_NEWSIZE:     ResizeGui(&TestPro);
                                    break;
            case IDCMP_REFRESHWINDOW:
                                    RefreshGui(&TestPro);
                                    break;
            case IDCMP_GADGETUP:
                                    break;
         }
      }
   }
   FreeGui(&TestPro);
   CloseWindow(win);
   return(0);
}
