/*
 *  Source machine generated by GadToolsBox V2.0b
 *  which is (c) Copyright 1991-1993 Jaba Development
 *
 *  GUI Designed by : (ray-1 of A((eSS
 */

#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>

#include "VectorEd.h"

static struct Screen         *Scr = NULL;
static APTR                   VisualInfo = NULL;
static struct Window         *BackgroundWnd = NULL;
static struct Window         *Debug_StatsWnd = NULL;
static struct Gadget         *Debug_StatsGList = NULL;
static struct Menu           *BackgroundMenus = NULL;
static struct Gadget         *Debug_StatsGadgets[9];
static UWORD                  BackgroundLeft = 0;
static UWORD                  BackgroundTop = 0;
static UWORD                  BackgroundWidth = 518;
static UWORD                  BackgroundHeight = 244;
static UWORD                  Debug_StatsLeft = 516;
static UWORD                  Debug_StatsTop = 0;
static UWORD                  Debug_StatsWidth = 132;
static UWORD                  Debug_StatsHeight = 254;
static UBYTE                 *BackgroundWdt = NULL;
static UBYTE                 *Debug_StatsWdt = NULL;

static UBYTE *MODE1Labels[] = {
	(UBYTE *)"Free Draw Mode",
	(UBYTE *)"Edit Mode",
	(UBYTE *)"Trace Mode",
	NULL };

static struct TextAttr XHelvetica9 = {
	( STRPTR )"XHelvetica.font", 9, 0x00, 0x20 };

static struct NewMenu BackgroundNewMenu[] = {
	NM_TITLE, (STRPTR)"Main_Project", NULL, 0, NULL, NULL,
	NM_ITEM, (STRPTR)"About", (STRPTR)"A", 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Auto Trace Vector", NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Low Level Preview", NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
	NM_TITLE, (STRPTR)"File I/O", NULL, 0, NULL, NULL,
	NM_ITEM, (STRPTR)"Load Backdrop", NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Load Vectors", NULL, 0, NULL, NULL,
	NM_SUB, (STRPTR)"Load BT Van File", (STRPTR)"L", 0, 0L, NULL,
	NM_SUB, (STRPTR)"Load BT Word Van File", NULL, 0, 0L, NULL,
	NM_SUB, (STRPTR)"Load Cobra V File", (STRPTR)"C", 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Save Vectors", NULL, 0, NULL, NULL,
	NM_SUB, (STRPTR)"Save BT Van File", (STRPTR)"S", 0, 0L, NULL,
	NM_SUB, (STRPTR)"Save BT Word Van File", NULL, 0, 0L, NULL,
	NM_SUB, (STRPTR)"Save Cobras V Files", (STRPTR)"X", 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Convertion", NULL, 0, NULL, NULL,
	NM_SUB, (STRPTR)"Convert VAN's To Cobra's", NULL, 0, 0L, NULL,
	NM_SUB, (STRPTR)"Convert Cobra's To VAN's", NULL, 0, 0L, NULL,
	NM_SUB, (STRPTR)"Convert Word VANs to VANs", NULL, 0, 0L, NULL,
	NM_SUB, (STRPTR)"Convert VANs to Word VANs", NULL, 0, 0L, NULL,
	NM_TITLE, (STRPTR)"Show / Hide", NULL, 0, NULL, NULL,
	NM_ITEM, (STRPTR)"Hide Show ToolBox", (STRPTR)"0", 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Hide Show Status ", (STRPTR)"9", 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Hide Title Bar", (STRPTR)"8", 0, 0L, NULL,
	NM_TITLE, (STRPTR)"Preferences", NULL, 0, NULL, NULL,
	NM_ITEM, (STRPTR)"Colour", NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Auto Trace Level", NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
	NM_ITEM, (STRPTR)"Default Paths", NULL, 0, 0L, NULL,
	NM_END, NULL, NULL, 0, 0L, NULL };

static UWORD Debug_StatsGTypes[] = {
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	NUMBER_KIND,
	MX_KIND
};

static struct NewGadget Debug_StatsNGad[] = {
	27, 14, 75, 12, (UBYTE *)"X Cord", NULL, GD_XCORD, PLACETEXT_ABOVE, NULL, NULL,
	29, 27, 75, 13, (UBYTE *)"Y Cord", NULL, GD_YCORD, PLACETEXT_BELOW, NULL, NULL,
	85, 91, 30, 12, (UBYTE *)"Current Frame", NULL, GD_FRAME, PLACETEXT_LEFT, NULL, NULL,
	87, 107, 29, 12, (UBYTE *)"Current Point", NULL, GD_POINT, PLACETEXT_LEFT, NULL, NULL,
	23, 167, 81, 12, (UBYTE *)"Total Points", NULL, GD_TPOINTS, PLACETEXT_ABOVE, NULL, NULL,
	22, 185, 86, 12, (UBYTE *)"Total Frames", NULL, GD_TFRAMES, PLACETEXT_BELOW, NULL, NULL,
	30, 138, 69, 12, (UBYTE *)"Current KeyCode", NULL, GD_KEYCODE, PLACETEXT_ABOVE, NULL, NULL,
	33, 71, 58, 13, (UBYTE *)"Last Menu", NULL, GD_LASTMENU, PLACETEXT_ABOVE, NULL, NULL,
	86, 217, 17, 9, NULL, NULL, GD_MODE, PLACETEXT_LEFT, NULL, NULL
};

static ULONG Debug_StatsGTags[] = {
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTNM_Border), TRUE, (TAG_DONE),
	(GTMX_Labels), (ULONG)&MODE1Labels[ 0 ], (TAG_DONE)
};

static struct ColorSpec ScreenColors[] = {
	 0, 0x0A, 0x0A, 0x0A,
	 1, 0x00, 0x00, 0x00,
	 2, 0x0F, 0x0F, 0x0F,
	 3, 0x06, 0x08, 0x0B,
	 4, 0x09, 0x09, 0x09,
	 5, 0x0B, 0x0B, 0x0B,
	 6, 0x0B, 0x0A, 0x09,
	 7, 0x0F, 0x0B, 0x0A,
	 8, 0x06, 0x02, 0x00,
	 9, 0x0E, 0x05, 0x00,
	10, 0x09, 0x0F, 0x01,
	11, 0x0E, 0x0B, 0x00,
	12, 0x05, 0x05, 0x0F,
	13, 0x09, 0x02, 0x0F,
	14, 0x00, 0x0F, 0x08,
	15, 0x0C, 0x0C, 0x0C,
	(unsigned short)~0, 0x00, 0x00, 0x00 };

static UWORD DriPens[] = {
	(unsigned short)~0 };

int SetupScreen( void )
{
	if ( ! ( Scr = OpenScreenTags( NULL, SA_Left,	0,
					SA_Top,		0,
					SA_Width,	648,
					SA_Height,	256,
					SA_Depth,	3,
					SA_Colors,	&ScreenColors[0],
					SA_Font,	&XHelvetica9,
					SA_Type,	CUSTOMSCREEN,
					SA_DisplayID,	PAL_MONITOR_ID|HIRES_KEY,
					SA_AutoScroll,	TRUE,
					SA_Overscan,	OSCAN_TEXT,
					SA_Pens,	&DriPens[0],
					SA_Title,	"Vector Editor V1.0 By Cray-1",
					TAG_DONE )))
		return( 1L );

	if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
		return( 2L );

	return( 0L );
}

void CloseDownScreen( void )
{
	if ( VisualInfo ) {
		FreeVisualInfo( VisualInfo );
		VisualInfo = NULL;
	}

	if ( Scr        ) {
		CloseScreen( Scr );
		Scr = NULL;
	}
}

int OpenBackgroundWindow( void )
{
	struct NewGadget	ng;
	struct Gadget	*g;
	UWORD		lc, tc;
	UWORD		offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;

	if ( ! ( BackgroundMenus = CreateMenus( BackgroundNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
		return( 3L );

	LayoutMenus( BackgroundMenus, VisualInfo, GTMN_TextAttr, &XHelvetica9, TAG_DONE );

	if ( ! ( BackgroundWnd = OpenWindowTags( NULL,
				WA_Left,	BackgroundLeft,
				WA_Top,		BackgroundTop,
				WA_Width,	BackgroundWidth,
				WA_Height,	BackgroundHeight + offy,
				WA_IDCMP,	IDCMP_MOUSEMOVE|IDCMP_MOUSEBUTTONS|IDCMP_MENUPICK|IDCMP_INACTIVEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
				WA_Flags,	WFLG_SMART_REFRESH|WFLG_REPORTMOUSE|WFLG_ACTIVATE,
				WA_Title,	BackgroundWdt,
				WA_ScreenTitle,	"Vector Editor V1.0 By Cray-1 For Big Time",
				WA_CustomScreen,	Scr,
				TAG_DONE )))
	return( 4L );

	SetMenuStrip( BackgroundWnd, BackgroundMenus );
	GT_RefreshWindow( BackgroundWnd, NULL );

	return( 0L );
}

void CloseBackgroundWindow( void )
{
	if ( BackgroundMenus      ) {
		ClearMenuStrip( BackgroundWnd );
		FreeMenus( BackgroundMenus );
		BackgroundMenus = NULL;	}

	if ( BackgroundWnd        ) {
		CloseWindow( BackgroundWnd );
		BackgroundWnd = NULL;
	}
}

int OpenDebug_StatsWindow( void )
{
	struct NewGadget	ng;
	struct Gadget	*g;
	UWORD		lc, tc;
	UWORD		offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;

	if ( ! ( g = CreateContext( &Debug_StatsGList )))
		return( 1L );

	for( lc = 0, tc = 0; lc < Debug_Stats_CNT; lc++ ) {

		CopyMem((char * )&Debug_StatsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));

		ng.ng_VisualInfo = VisualInfo;
		ng.ng_TextAttr   = &XHelvetica9;
		ng.ng_LeftEdge  += offx;
		ng.ng_TopEdge   += offy;

		Debug_StatsGadgets[ lc ] = g = CreateGadgetA((ULONG)Debug_StatsGTypes[ lc ], g, &ng, ( struct TagItem * )&Debug_StatsGTags[ tc ] );

		while( Debug_StatsGTags[ tc ] ) tc += 2;
		tc++;

		if ( NOT g )
			return( 2L );
	}

	if ( ! ( Debug_StatsWnd = OpenWindowTags( NULL,
				WA_Left,	Debug_StatsLeft,
				WA_Top,		Debug_StatsTop,
				WA_Width,	Debug_StatsWidth,
				WA_Height,	Debug_StatsHeight + offy,
				WA_IDCMP,	NUMBERIDCMP|MXIDCMP|IDCMP_ACTIVEWINDOW|IDCMP_REFRESHWINDOW,
				WA_Flags,	WFLG_SMART_REFRESH|WFLG_RMBTRAP,
				WA_Gadgets,	Debug_StatsGList,
				WA_Title,	Debug_StatsWdt,
				WA_ScreenTitle,	"You Should Never Be Able To Read This Title!",
				WA_CustomScreen,	Scr,
				TAG_DONE )))
	return( 4L );

	GT_RefreshWindow( Debug_StatsWnd, NULL );

	return( 0L );
}

void CloseDebug_StatsWindow( void )
{
	if ( Debug_StatsWnd        ) {
		CloseWindow( Debug_StatsWnd );
		Debug_StatsWnd = NULL;
	}

	if ( Debug_StatsGList      ) {
		FreeGadgets( Debug_StatsGList );
		Debug_StatsGList = NULL;
	}
}

