#include <../arch/arch.h>
#include <../arch/common/glctx.h>

vboolean autowarp = false;
vboolean vm = false;

#include "dumpevt.c"

void set_mode(arch_window_p w)
{
	int i;
	for(i = 0; i < w->num_vidmodes;i++)
	{
		if(w->vidmodes[i].width == 1024 && w->vidmodes[i].height == 768
				&& w->vidmodes[i].bpp == 32)
			archWinSetVidMode(w, i);
	}
}
	
int main(void)
{
	vboolean enable_kb_repeat = true;
	arch_window_p w;
	ui_event_t ev;

	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);

	w = archWinOpenNP(NULL,NULL,"test",10,10,512,512,true,false);
	assert(w);
	archWinShow(w,true);
	
	for(;;)
	{
		archWinPoll(w, true);
		while(w->msg_que)
		{
			DEQ_POP_BACK(event,w->msg_que,&ev);
			dump_event(0, &ev);
			if(ev.type != ui_key_event)
				continue;
			switch(ev.key.scan)
			{
				case sc_escape:
					if(!ev.key.press)
						goto close_win;
					break;
				case sc_v:
					if(ev.key.press)
						break;
					vm = !vm;
					if(vm)
						set_mode(w);
					else
						archWinSetVidMode(w, -1);
					break;
				case sc_s:
					archWinShow(w, false);
					archWinPoll(w, false);
					while(w->msg_que)
					{
						DEQ_POP_BACK(event,w->msg_que,&ev);
						dump_event(0, &ev);
					}
					timeDelay(3000);
					archWinShow(w, true);
					break;
				case sc_p:
					archWinShowPointer(w, true);
					break;
				case sc_o:
					archWinShowPointer(w, false);
					break;
				case sc_a:
					/*
					if(ev.key.press)
						archWinAutoRepeat(w,enable_kb_repeat = !enable_kb_repeat);
						*/
					break;
				case sc_w:
					/*
					if(!ev.key.press)
						archWinAutoWarp(w,autowarp = !autowarp);*/
					break;
				default:
					break;
			}
		}
		continue;

close_win:;
		printf("Window %d: closing.\n", 0);
		archWinClose(w);
		break;
	}

	memPrintStats();
	return 0;
}

