#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <graphics/gfx.h>
#include <graphics/clip.h>
#include <graphics/rastport.h>
#include <graphics/view.h>
#include <graphics/text.h>
#include <graphics/gfxmacros.h>

#include <graphics/layers.h>
#include <intuition/intuition.h>

#define DEPTH 3 

#define TXHEIGHT 8

struct TextAttr TestFont =
    {
    "topez.font",
    TXHEIGHT,
    0,
    0,
    };

long GfxBase = 0;
long LayersBase = 0;
long IntuitionBase = 0;

startgfx(x,y,height, width, n_bit_Planess, palette, gfxproc,s,flags,sbitmap)
WORD x,y;
WORD height, width, n_bit_Planess;
UWORD *palette;
int (*gfxproc)();
UBYTE *s;
struct BitMap *sbitmap;		/* optional parameter */
{
    struct Screen *myscreen;
	struct Window *window;
	struct RastPort *w=0;
    struct View *view;
	register i, j;
	int idcmp;
	struct NewWindow nw;
    struct NewScreen ns;

    
	GfxBase = OpenLibrary("graphics.library",31);
	if (GfxBase == 0)
	{
		exit();
	}

	LayersBase = OpenLibrary("layers.library",31);
	if (LayersBase == 0)
	{
		exit();
	}


	IntuitionBase = OpenLibrary("intuition.library",31);
	if (IntuitionBase == 0)
	{
		exit();
	}

	/* intuition direct comunication message port */
	idcmp = CLOSEWINDOW|REFRESHWINDOW;

    ns.LeftEdge = 0;
	ns.TopEdge = 0;
	ns.Width = 320;
	ns.Height = 200;
	ns.Depth = DEPTH;
	ns.DetailPen = -1;
	ns.BlockPen = -1;
	ns.ViewModes = 0;
	ns.Type = CUSTOMSCREEN;
	ns.Font = &TestFont;
    ns.DefaultTitle = NULL;
    ns.Gadgets = NULL;

    if ((myscreen =(struct Screen *)OpenScreen(&ns)) == 0)
   		{
			exit(1);
		}


	nw.LeftEdge = x;
	nw.TopEdge = y;
    nw.Width = width;
	nw.Height = height;
	nw.DetailPen = -1;
	nw.BlockPen = -1;
	nw.IDCMPFlags = idcmp;
	nw.Flags = WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE|flags;
	nw.FirstGadget = 0;
	nw.CheckMark = 0;
	nw.Title = s;
	nw.Screen = 0;
	nw.BitMap = sbitmap;
	nw.MinWidth = 80;
	nw.MinHeight = 16;
	nw.MaxWidth = 640;
	nw.MaxHeight = 200;
    nw.Type = WBENCHSCREEN;

    window = (struct Window *)OpenWindow(&nw);
    view = (struct View *)ViewAddress(); 
    (*gfxproc)(myscreen,view,&myscreen->ViewPort,&myscreen->RastPort,window);
    CloseWindow(window);    
    CloseScreen(myscreen);
}
