/*************************************************************
 *  Do square area fills Blitter
 *   by Tom Krotchko for Jumpdisk
 ************************************************************/

#include <exec/types.h>
#include <intuition/intuition.h>
#include <dos.h>

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase; 
struct IntuiMessage *message;

#define INTUITION_REV 0
#define GRAPHICS_REV  0

struct Screen *Screen;
struct Window *Window;

static struct NewScreen NewScreenStructure = {
	0,0,	/* screen XY origin relative to View */
	320,200,	/* screen width and height */
	5,	/* screen depth (number of bitplanes) */
	0,1,	/* detail and block pens */
	NULL,	/* display modes for this screen */
	CUSTOMSCREEN,	/* screen type */
	NULL,	/* pointer to default screen font */
	"Area Fill With Blitter",	/* screen title */
	NULL,	/* first in list of custom screen gadgets */
	NULL	/* pointer to custom BitMap structure */
};

#define NEWSCREENSTRUCTURE NewScreenStructure

static struct NewWindow NewWindowStructure1 = {
	0,11,	/* window XY origin relative to TopLeft of screen */
	320,189,	/* window width and height */
	0,1,	/* detail and block pens */
	CLOSEWINDOW,	/* IDCMP flags */
	WINDOWCLOSE+SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH, /* other window flags */
	NULL,	/* first gadget in gadget list */
	NULL,	/* custom CHECKMARK imagery */
	NULL,	/* window title */
	NULL,	/* custom screen pointer */
	NULL,	/* custom bitmap */
	5,5,	/* minimum width and height */
	-1,-1,	/* maximum width and height */
	CUSTOMSCREEN	/* destination screen type */
};

void main()
{
LONG startx=160,starty=106,endx=161,endy=107;
int color_code=0;

IntuitionBase=(struct IntuitionBase *) 
  OpenLibrary("intuition.library",INTUITION_REV);


GfxBase=(struct GfxBase *)
  OpenLibrary("graphics.library",GRAPHICS_REV);

if ((Screen=(struct Screen *)OpenScreen(&NEWSCREENSTRUCTURE))==NULL)
   {
   printf("Bad OpenScreen. \n");
   exit(FALSE);
   }

NewWindowStructure1.Screen = Screen;

if ((Window=(struct Window *) OpenWindow(&NewWindowStructure1)) == NULL)
    {
    printf("Bad OpenWindow. Closing Screen. \n");
    CloseScreen(Screen);
    exit(FALSE);
    }

 for (;;)
 {
     /* for-ever loop to do processing */
     /* don't waste cycles if nothing's happening */
  
     while(message = (struct IntuiMessage *)GetMsg(Window->UserPort))  
     {
          /* Always check for closewindow event! */
          if (message->Class == CLOSEWINDOW)
          {
             CloseWindow(Window);
             CloseScreen(Screen);
             CloseLibrary(GfxBase);
             CloseLibrary(IntuitionBase);
             exit(TRUE);
          } /* end if */
          ReplyMsg(message);

     } /* end while */

     color_code++;
     color_code++;        
     if(color_code>255) color_code=0;
     SetAPen(Window->RPort,color_code);
     startx--;
     starty--;
     endx++;
     endy++;
     if(startx<2)  startx=160;
     if(starty<12) starty=106;
     if(endx>319)  endx  =161;
     if(endy>199)  endy  =107;

     if(startx>endx) endx=startx+1;
     if(starty>endy) endy=starty+1;

     RectFill(Window->RPort,startx,starty,endx,endy);
 } /* end for */
}  /* End of main procedure */

