#include "exec/types.h"
#include "intuition/intuition.h"

struct IntuitionBase *IntuitionBase;
struct Window *NoBorder;
struct GfxBase *GfxBase;
struct IntuiMessage *mesg;
struct RastPort *r;
struct Screen *Scrn;


#define INTUITION_REV 0
#define GRAPHICS_REV 0

USHORT imagepts[]=
       {0x0380,0x0780,0x0f80,0x1f80,
        0x3b80,0x7180,0xe180,0xc180,
        0x0180,0x0180,0x0180,0x0180,
        0x03c0,0x07e0,0x3ffc,0x3ffc};

struct Image picture[3];
           

main()
{
 ULONG flags,mclass;
 SHORT x,y,w,h,d;
 USHORT mode;
 UBYTE *name,c0,c1;
 VOID OpenALL();

 OpenALL();

 
 /* ======open een hires custom-screen======*/

 name=NULL;
 y=0;
 w=640;
 h=200;
 d=3;
 c0=0x00;
 c1=0x01;
 mode=HIRES;

 Scrn=(struct Screen *)
         make_screen(y,w,h,d,c0,c1,mode,name);


 
 /* ======open window====== */

 name=NULL;
 x=0;
 y=0;
 w=640;
 h=200;
 flags=ACTIVATE|SMART_REFRESH|BORDERLESS;
 c0=-0x01;
 c1=-0x01;

 NoBorder=(struct Window *)
         make_window(x,y,w,h,name,flags,c0,c1,Scrn,NULL);

 /* ======Create image structures====== */

  picture[0].LeftEdge=0;
  picture[0].TopEdge=0;
  picture[0].Width=16;
  picture[0].Height=16;
  picture[0].Depth=1;
  picture[0].ImageData=imagepts;
  picture[0].PlanePick=0x0001;
  picture[0].PlaneOnOff=0x0000;
  picture[0].NextImage=&picture[1];

  picture[1].LeftEdge=25;
  picture[1].TopEdge=18;
  picture[1].Width=16;
  picture[1].Height=16;
  picture[1].Depth=1;
  picture[1].ImageData=imagepts;
  picture[1].PlanePick=0x0001;
  picture[1].PlaneOnOff=0x0000;
  picture[1].NextImage=&picture[2];

  picture[2].LeftEdge=50;
  picture[2].TopEdge=36;
  picture[2].Width=16;
  picture[2].Height=16;
  picture[2].Depth=1;
  picture[2].ImageData=imagepts;
  picture[2].PlanePick=0x0001;
  picture[2].PlaneOnOff=0x0000;
  picture[2].NextImage=NULL;

  r=NoBorder->RPort;
  
  for(x=15;x<580;x+=17)
  {
   DrawImage(r,&picture,x,99-(16/2));
  };

 /* ======close de windows in volgorde====== */

 Wait(1<<NoBorder->UserPort->mp_SigBit);

 while((mesg=(struct IntuiMessage *)
     GetMsg(NoBorder->UserPort))!=NULL)
  {
   mclass=mesg->Class;
   ReplyMsg(mesg);
  }
  if(mclass==MOUSEBUTTONS)
   {
     CloseWindow(NoBorder);
     CloseScreen(Scrn);

   }
}
 /*========================================================================*/

 VOID OpenALL()
 {
 /* ======open Intuition====== */

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

 if(IntuitionBase==NULL)
   exit(FALSE);

 /* ======open the Graphics Library====== */

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

 if(GfxBase==NULL)
   exit(FALSE);
 }



make_window(x,y,w,h,name,flags,color0,color1,screen,gadg)
SHORT x,y,w,h;
UBYTE *name,color0,color1;
ULONG flags;
struct Screen *screen;
struct Gadget *gadg;

{
 struct NewWindow NewWindow;

 NewWindow.LeftEdge = x;
 NewWindow.TopEdge = y;
 NewWindow.Width = w;
 NewWindow.Height = h;
 NewWindow.DetailPen = color0;
 NewWindow.BlockPen = color1;
 NewWindow.Title = name;
 NewWindow.Flags = flags;
 NewWindow.IDCMPFlags = MOUSEBUTTONS;
 NewWindow.Type = CUSTOMSCREEN;
 NewWindow.FirstGadget = gadg;
 NewWindow.CheckMark = NULL;
 NewWindow.Screen = screen;
 NewWindow.BitMap = NULL;
 NewWindow.MinWidth = 1;
 NewWindow.MinHeight = 1;
 NewWindow.MaxWidth = 640;
 NewWindow.MaxHeight = 200;

 return(OpenWindow(&NewWindow));

}
make_screen(y,w,h,d,color0,color1,mode,name)
SHORT y,w,h,d;
UBYTE color0,color1,*name;
USHORT mode;
{
 struct NewScreen NewScreen;

 NewScreen.LeftEdge = 0;
 NewScreen.TopEdge = y;
 NewScreen.Width = w;
 NewScreen.Height = h;
 NewScreen.Depth = d;
 NewScreen.DetailPen = color0;
 NewScreen.BlockPen = color1;
 NewScreen.ViewModes = mode;
 NewScreen.Type = CUSTOMSCREEN;
 NewScreen.Font = NULL;
 NewScreen.DefaultTitle = name;
 NewScreen.Gadgets = NULL;
 NewScreen.CustomBitMap = NULL;

 return(OpenScreen(&NewScreen));
}



