/***********************************************************************/
/* Demo fuer RectFill()                                                */
/* fuer Markt&Technik von H. Knappe                                    */
/***********************************************************************/

#include <exec/types.h>
#include <intuition/intuition.h>
#include <graphics/gfxmacros.h>

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct NewWindow MyNewWindow=
 {10,10,100,100,0,1,NEWSIZE+CLOSEWINDOW,WINDOWDRAG+WINDOWDEPTH+
 WINDOWCLOSE+WINDOWSIZING+ACTIVATE+NOCAREREFRESH+GIMMEZEROZERO,0,0,
 "RectFill Demo",0,0,50,50,640,250,WBENCHSCREEN};
struct Window *MyWindow;
struct RastPort *MyRastPort;
struct IntuiMessage *MyMessage;

short col=0;                   /* Farbe der Flaeche */
short x0,y0;                   /* Fenstergroesse */
short xmin,ymin,xmax,ymax;     /* Eckkoordinaten des Rechtecks */


main()
{
 o_(); /* Oeffnen der Libraries und des Windows */
 for(;;)
 {
    while((MyMessage=GetMsg(MyWindow->UserPort))==0)
       rechteck_();  /* Solange nichts passiert */
    if(MyMessage->Class==CLOSEWINDOW)
       break;
    SetRast(MyRastPort,0); /* Fensterinhalt loeschen */
 }
 ReplyMsg(MyMessage);
 c_();
}


rechteck_()
{
 /* Anpassung an die augenblickliche Fenstergroesse */
 x0=MyWindow->Width,y0=MyWindow->Height;
 xmin=RangeRand(x0),ymin=RangeRand(y0);
 xmax=RangeRand(x0-xmin)+xmin,ymax=RangeRand(y0-ymin)+ymin;
 ++col;
 if(col==4) col=0;
 SetAPen(MyRastPort,col);   /* Fuellfarbe */
 SetOPen(MyRastPort,3-col); /* Randfarbe */
 RectFill(MyRastPort,xmin,ymin,xmax,ymax);
}
 

o_()
{
 if((IntuitionBase=OpenLibrary("intuition.library",0))==0)
    c_();
 if((GfxBase=OpenLibrary("graphics.library",0))==0)
    c_();
 if((MyWindow=OpenWindow(&MyNewWindow))==NULL)
    c_();
 MyRastPort=MyWindow->RPort;
}

c_()
{
 if(MyWindow!=0) CloseWindow(MyWindow);
 if(GfxBase!=0) CloseLibrary(GfxBase);
 if(IntuitionBase!=0)  CloseLibrary(IntuitionBase);
 exit(0);
}
