/*
 *  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         *Tool_BoxWnd = NULL;
static struct Window         *Debug_StatsWnd = NULL;
static struct Gadget         *Tool_BoxGList = NULL;
static struct Gadget         *Debug_StatsGList = NULL;
static struct Menu           *BackgroundMenus = NULL;
static struct Gadget         *Tool_BoxGadgets[9];
static struct Gadget         *Debug_StatsGadgets[8];
static UWORD                  BackgroundLeft = 0;
static UWORD                  BackgroundTop = 0;
static UWORD                  BackgroundWidth = 648;
static UWORD                  BackgroundHeight = 245;
static UWORD                  Tool_BoxLeft = 410;
static UWORD                  Tool_BoxTop = 0;
static UWORD                  Tool_BoxWidth = 238;
static UWORD                  Tool_BoxHeight = 80;
static UWORD                  Debug_StatsLeft = 364;
static UWORD                  Debug_StatsTop = 80;
static UWORD                  Debug_StatsWidth = 284;
static UWORD                  Debug_StatsHeight = 85;
static UBYTE                 *BackgroundWdt = (UBYTE *)"Work Window";
static UBYTE                 *Tool_BoxWdt = NULL;
static UBYTE                 *Debug_StatsWdt = NULL;

static struct TextAttr XEN8 = {
	( STRPTR )"XEN.font", 8, 0x00, 0x00 };

static struct IntuiText Tool_BoxIText[] = {
	1, 0, JAM1,95, 65, &XEN8, (UBYTE *)"Working...", NULL };

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)"Quit", (STRPTR)"Q", 0, 0L, NULL,
	NM_TITLE, (STRPTR)"File I/O", NULL, 0, NULL, 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 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 Cobras V Files", (STRPTR)"X", 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_END, NULL, NULL, 0, 0L, NULL };

static UWORD Tool_BoxGTypes[] = {
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND,
	BUTTON_KIND
};

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

static struct NewGadget Tool_BoxNGad[] = {
	8, 4, 67, 12, (UBYTE *)"End_Frame", NULL, GD_CUSTOM_1, PLACETEXT_IN, NULL, NULL,
	94, 4, 64, 12, (UBYTE *)"End_File", NULL, GD_CUSTOM_2, PLACETEXT_IN, NULL, NULL,
	168, 4, 60, 11, (UBYTE *)"CUSTOM_3", NULL, GD_CUSTOM_3, PLACETEXT_IN, NULL, NULL,
	168, 17, 59, 11, (UBYTE *)"CUSTOM_6", NULL, GD_CUSTOM_6, PLACETEXT_IN, NULL, NULL,
	15, 18, 61, 11, (UBYTE *)"CUSTOM_4", NULL, GD_CUSTOM_4, PLACETEXT_IN, NULL, NULL,
	97, 18, 61, 11, (UBYTE *)"CUSTOM_5", NULL, GD_CUSTOM_5, PLACETEXT_IN, NULL, NULL,
	15, 30, 62, 11, (UBYTE *)"CUSTOM_7", NULL, GD_CUSTOM_7, PLACETEXT_IN, NULL, NULL,
	95, 32, 64, 11, (UBYTE *)"CUSTOM_8", NULL, GD_CUSTOM_8, PLACETEXT_IN, NULL, NULL,
	169, 31, 60, 11, (UBYTE *)"CUSTOM_9", NULL, GD_CUSTOM_9, PLACETEXT_IN, NULL, NULL
};

static struct NewGadget Debug_StatsNGad[] = {
	94, 7, 34, 13, (UBYTE *)"X Cord", NULL, GD_XCORD, PLACETEXT_LEFT, NULL, NULL,
	163, 9, 32, 11, (UBYTE *)"Y Cord", NULL, GD_YCORD, PLACETEXT_RIGHT, NULL, NULL,
	228, 27, 45, 11, (UBYTE *)"Current Frame", NULL, GD_FRAME, PLACETEXT_LEFT, NULL, NULL,
	229, 40, 45, 11, (UBYTE *)"Current Point", NULL, GD_POINT, PLACETEXT_LEFT, NULL, NULL,
	10, 31, 38, 11, (UBYTE *)"Total Points", NULL, GD_TPOINTS, PLACETEXT_RIGHT, NULL, NULL,
	11, 44, 41, 12, (UBYTE *)"Total Frames", NULL, GD_TFRAMES, PLACETEXT_RIGHT, NULL, NULL,
	109, 61, 33, 13, (UBYTE *)"Current KeyCode", NULL, GD_KEYCODE, PLACETEXT_LEFT, NULL, NULL,
	213, 62, 62, 13, (UBYTE *)"Last Menu", NULL, GD_LASTMENU, PLACETEXT_LEFT, NULL, NULL
};

static ULONG Tool_BoxGTags[] = {
	(TAG_DONE),
	(TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE),
	(GA_Disabled), TRUE, (TAG_DONE)
};

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)
};

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,
	~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,	&XEN8,
					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 = 0, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;

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

	LayoutMenus( BackgroundMenus, VisualInfo, GTMN_TextAttr, &XEN8, 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_CLOSEWINDOW|IDCMP_INACTIVEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
				WA_Flags,	WFLG_SMART_REFRESH|WFLG_BACKDROP|WFLG_REPORTMOUSE|WFLG_BORDERLESS|WFLG_ACTIVATE,
				WA_ScreenTitle,	"GadToolsBox V2.0b © 1991-1993",
				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;
	}
}

void Tool_BoxRender( void )
{
	UWORD		offx, offy;

	offx = Tool_BoxWnd->BorderLeft;
	offy = Tool_BoxWnd->BorderTop;


	DrawBevelBox( Tool_BoxWnd->RPort, offx + 22, offy + 50, 201, 13, GT_VisualInfo, VisualInfo, TAG_DONE );
	PrintIText( Tool_BoxWnd->RPort, Tool_BoxIText, offx, offy );
}

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

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

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

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

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

		Tool_BoxGadgets[ lc ] = g = CreateGadgetA((ULONG)Tool_BoxGTypes[ lc ], g, &ng, ( struct TagItem * )&Tool_BoxGTags[ tc ] );

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

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

	if ( ! ( Tool_BoxWnd = OpenWindowTags( NULL,
				WA_Left,	Tool_BoxLeft,
				WA_Top,		Tool_BoxTop,
				WA_Width,	Tool_BoxWidth,
				WA_Height,	Tool_BoxHeight + offy,
				WA_IDCMP,	BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
				WA_Flags,	WFLG_SMART_REFRESH|WFLG_RMBTRAP,
				WA_Gadgets,	Tool_BoxGList,
				WA_Title,	Tool_BoxWdt,
				WA_CustomScreen,	Scr,
				TAG_DONE )))
	return( 4L );

	GT_RefreshWindow( Tool_BoxWnd, NULL );

	Tool_BoxRender();

	return( 0L );
}

void CloseTool_BoxWindow( void )
{
	if ( Tool_BoxWnd        ) {
		CloseWindow( Tool_BoxWnd );
		Tool_BoxWnd = NULL;
	}

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

int OpenDebug_StatsWindow( void )
{
	struct NewGadget	ng;
	struct Gadget	*g;
	UWORD		lc, tc;
	UWORD		offx = 0, 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   = &XEN8;
		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|IDCMP_REFRESHWINDOW,
				WA_Flags,	WFLG_SMART_REFRESH|WFLG_RMBTRAP,
				WA_Gadgets,	Debug_StatsGList,
				WA_Title,	Debug_StatsWdt,
				WA_ScreenTitle,	"Vector Editor V1.0 By Cray-1",
				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;
	}
}

