#include "_Graphics.js"
#include "_Main.js"

var g;

var str1 = "";
var str2 = "";
var str3 = "";

var event1 = false;
var event2 = false;
var event3 = false;

var key = -1;

var w, h;

function frameTime(){ return 1000 / 15/*フレーム*/; }

function init()
{
	_USE_KEY = true;
	_USE_MOUSE = true;
}

function start()
{
	setCurrent( "canvas0" );

	g = new _Graphics();

	w = getBrowserWidth();
	h = getBrowserHeight();

	return true;
}

function paint()
{
	g.setColor( g.getColorOfRGB( 127, 127, 127 ) );
	g.fillRect( 0, 0, getWidth(), getHeight() );

	g.setFont( 24, "ＭＳ ゴシック" );

	if( event1 )
	{
		g.setColor( g.getColorOfRGB( 255, 255, 255 ) );
		event1 = false;
	}
	else
	{
		g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	}
	g.drawString( str1, 10, 30 );
	g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	g.drawString( "KEY: " + key, 10, 60 );
	g.drawString( "KEY STATE: " + getKeypadState(), 10, 90 );

	if( event2 )
	{
		g.setColor( g.getColorOfRGB( 255, 255, 255 ) );
		event2 = false;
	}
	else
	{
		g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	}
	g.drawString( str2, 10, 120 );
	g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	g.drawString( "MOUSE X: " + getMouseX(), 10, 150 );
	g.drawString( "MOUSE Y: " + getMouseY(), 10, 180 );

	if( event3 )
	{
		g.setColor( g.getColorOfRGB( 255, 255, 255 ) );
		event3 = false;
	}
	else
	{
		g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	}
	g.drawString( str3, 10, 210 );
	g.setColor( g.getColorOfRGB( 255, 0, 0 ) );
	g.drawString( "BROWSER W: " + w, 10, 240 );
	g.drawString( "BROWSER H: " + h, 10, 270 );
}

function processEvent( type, param )
{
	switch( type )
	{
	case _KEY_PRESSED_EVENT:
		str1 = "KEY PRESSED";
		event1 = true;
		key = param;
		break;
	case _KEY_RELEASED_EVENT:
		str1 = "KEY RELEASED";
		event1 = true;
		key = param;
		break;
	case _MOUSE_DOWN_EVENT:
		str2 = "MOUSE DOWN";
		event2 = true;
		break;
	case _MOUSE_MOVE_EVENT:
		str2 = "MOUSE MOVE";
		event2 = true;
		break;
	case _MOUSE_OUT_EVENT:
		str2 = "MOUSE OUT";
		event2 = true;
		break;
	case _MOUSE_UP_EVENT:
		str2 = "MOUSE UP";
		event2 = true;
		break;
	case _RESIZE_EVENT:
		str3 = "RESIZE";
		event3 = true;
		w = getBrowserWidth();
		h = getBrowserHeight();
		break;
	}
}

function error()
{
	launch( "error.html" );
}
