/*
 *  Source machine generated by GadToolsBox V1.4
 *  which is (c) Copyright 1991,92 Jaba Development
 */

#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 <proto/intuition.h>
#include <string.h>

#include "dt_gad.h"
extern	WORD	maxcolors,maxdepth;
extern	WORD	scale_code;
extern	BOOL	jump_screen;

struct Screen         *Scr = NULL;
APTR                   VisualInfo = NULL;
struct Window         *InputWnd = NULL;
struct Gadget         *InputGList = NULL;
struct Gadget         *InputGadgets[Input_CNT];
struct Menu           *InputMenus = NULL;
UWORD                  InputLeft = 50;
UWORD                  InputTop = 91;
UWORD                  InputWidth = 160;
UWORD                  InputHeight = 255;
UBYTE                 *InputWdt = (UBYTE *)"DeskTop BETA © 1993, (Raul A. Sobon)";

struct TextAttr thinpaz8 = {
	( STRPTR )"thinpaz.font", 8, 0x00, 0x00 };


struct NewMenu InputNewMenu[] = {
	NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
		NM_ITEM, (STRPTR)"Screen Jumping", NULL, CHECKIT|MENUTOGGLE, 0x0L, NULL,
		NM_ITEM, (STRPTR)"Render Type", NULL, 0, NULL, NULL,
			NM_SUB, (STRPTR)"OS Scale", NULL, CHECKIT, 0x2L, NULL,
			NM_SUB, (STRPTR)"Custom Scale", NULL, CHECKIT|CHECKED, 0x1L, NULL,
		NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
		NM_ITEM, (STRPTR)"Save", (STRPTR)"s", 0, NULL, NULL,
		NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
		NM_ITEM, (STRPTR)"Quit", (STRPTR)"q", 0, NULL, NULL,
};

UWORD InputGTypes[] = {
	BUTTON_KIND,
	BUTTON_KIND,
};

struct NewGadget InputNGad[] = {
	6, 3, 45, 12, (UBYTE *)"_UpDate", NULL, GD_f1, PLACETEXT_IN, NULL, NULL,
	53, 3, 65, 12, (UBYTE *)"_CloseScr", NULL, GD_f2, PLACETEXT_IN, NULL, NULL,
};

ULONG InputGTags[] = {
	(GT_Underscore), '_', (TAG_DONE),
	(GT_Underscore), '_', (TAG_DONE),
};



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


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

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

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

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

		InputGadgets[ lc ] = g = CreateGadgetA((ULONG)InputGTypes[ lc ], g, &ng, ( struct TagItem * )&InputGTags[ tc ] );

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

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

//	printf("a=%08xl,b=%08lx\n",&InputNewMenu[ 3 ],&InputNewMenu[ 4 ]);
	if( jump_screen )
			InputNewMenu[ 1 ].nm_Flags |= CHECKED;
	else	InputNewMenu[ 1 ].nm_Flags &= ~CHECKED;
	switch( scale_code ){
		case 0 : InputNewMenu[ 4 ].nm_Flags &= ~CHECKED;
				 InputNewMenu[ 3 ].nm_Flags |= CHECKED; break;
		case 1 : InputNewMenu[ 3 ].nm_Flags &= ~CHECKED;
				 InputNewMenu[ 4 ].nm_Flags |= CHECKED; break;
	}

	if ( ! ( InputMenus = CreateMenus( InputNewMenu,
					GTMN_FrontPen,		2L,
					TAG_DONE )))
		return( 3L );

	LayoutMenus( InputMenus, VisualInfo,
			//		GTMN_TextAttr, 		&helvetica18,
					GTMN_NewLookMenus,	TRUE,
					TAG_DONE );

	if ( ! ( InputWnd = OpenWindowTags( NULL,
				WA_Left,		InputLeft,
				WA_Top,			InputTop,
				WA_Width,		InputWidth,
				WA_Height,		InputHeight + offy,
				WA_IDCMP,		IDCMP_MOUSEBUTTONS|IDCMP_CHANGEWINDOW|BUTTONIDCMP|IDCMP_NEWSIZE|INTEGERIDCMP|
								IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW|
								IDCMP_MENUPICK,
				WA_Flags,		WFLG_NEWLOOKMENUS|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|
								WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
			//	WA_Gadgets,		InputGList,
				WA_Title,		InputWdt,
				WA_PubScreen,	Scr,
				WA_MinWidth,	InputWidth,
				WA_MinHeight,	InputHeight + offy,
				WA_MaxWidth,	InputWidth + 140,
				WA_MaxHeight,	InputHeight + offy + 500,
				TAG_DONE )))
	return( 4L );

	SetMenuStrip( InputWnd, InputMenus );

	GT_RefreshWindow( InputWnd, NULL );

	return( 0L );
}

void CloseInputWindow( void )
{
	InputLeft = InputWnd->LeftEdge;
	InputTop = InputWnd->TopEdge;

	if ( InputMenus      ) {
		ClearMenuStrip( InputWnd );
		FreeMenus( InputMenus );
		InputMenus = NULL;	}

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

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