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

vboolean autowarp = false;
#include "dumpevt.c"

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,100,100,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_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;
}

