#import_plugin Nuklear as nk

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Input Demo" )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 10, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

#insert "../Nuklear.agc"

// basic nuklear initialization
nkInit()

// some variables for displaying actions.
cur_name as string = ""
cur_bound as nk_rect
cur_state as string = ""
do

	// pass agk inputs to nuklear
    nk.HandleInput()

	// make a data view window
	if nk.WindowBegin("Input Data Display", 0, 0, 1280, 90, NK_WINDOW_BORDER||NK_WINDOW_TITLE||NK_WINDOW_NO_SCROLLBAR)
		nk.LayoutRowDynamic(20, 10)
		// first row
		// labeling of the data
		nk.Label("Mouse X", NK_TEXT_CENTERED)
		nk.Label("Mouse Y", NK_TEXT_CENTERED)
		nk.Label("Delta X", NK_TEXT_CENTERED)
		nk.Label("Delta Y", NK_TEXT_CENTERED)
		nk.Label("Button Left", NK_TEXT_CENTERED)
		nk.Label("Button Right", NK_TEXT_CENTERED)
		nk.Label("Button Middle", NK_TEXT_CENTERED)
		nk.Label("Current Window", NK_TEXT_CENTERED)
		nk.Label("Current Bound", NK_TEXT_CENTERED)
		nk.Label("Current Bu.State", NK_TEXT_CENTERED)
		
		// second row
		// display mouse position and mouse move (delta)
		nk.Label(str(GetRawMouseX(),0), NK_TEXT_CENTERED)
		nk.Label(str(GetRawMousey(),0), NK_TEXT_CENTERED)
		nk.Label(str(nk.InputGetMouseDeltaX(),0), NK_TEXT_CENTERED)
		nk.Label(str(nk.InputGetMouseDeltaY(),0), NK_TEXT_CENTERED)
		
		// display mouse buttons
		down_text as string = ""
		if nk.InputIsMouseDown(NK_BUTTON_LEFT) then down_text = "  Hold  "
		if nk.InputIsMousePressed(NK_BUTTON_LEFT) then down_text = "  Down  "
		if nk.InputIsMouseReleased(NK_BUTTON_LEFT) then down_text = "   Up   "
		nk.Label(down_text, NK_TEXT_CENTERED)
		
		down_text = ""
		if nk.InputIsMouseDown(NK_BUTTON_RIGHT) then down_text = "  Hold  "
		if nk.InputIsMousePressed(NK_BUTTON_RIGHT) then down_text = "  Down  "
		if nk.InputIsMouseReleased(NK_BUTTON_RIGHT) then down_text = "   Up   "
		nk.Label(down_text, NK_TEXT_CENTERED)

		down_text = ""
		if nk.InputIsMouseDown(NK_BUTTON_MIDDLE) then down_text = "  Hold  "
		if nk.InputIsMousePressed(NK_BUTTON_MIDDLE) then down_text = "  Down  "
		if nk.InputIsMouseReleased(NK_BUTTON_MIDDLE) then down_text = "   Up   "
		nk.Label(down_text, NK_TEXT_CENTERED)
		
		// and window data
		nk.Label(cur_name, NK_TEXT_CENTERED)

		down_text = ""
		if len(cur_name) > 0 then down_text = str(cur_bound.x,0)+","+str(cur_bound.y,0)+":"+str(cur_bound.w,0)+"x"+str(cur_bound.h,0)
		nk.Label(down_text, NK_TEXT_CENTERED)

		nk.Label(cur_state, NK_TEXT_CENTERED)		
	endif
	nk.WindowEnd()
	
	
	win1_bound as nk_rect
	win2_bound as nk_rect
	win3_bound as nk_rect
	
	cur_name = ""
	cur_state = ""
	
	// display first window
	if nk.WindowBegin("Window 1", 50, 150, 320, 240, NK_WINDOW_BORDER||NK_WINDOW_TITLE||NK_WINDOW_MOVABLE||NK_WINDOW_SCALABLE)
		// get the bounds of this window
		win1_bound = nkWindowGetBounds()
		
		// if the mouse pointer is within the boundaries of this window, 
		// the window name, window boundaries and button status are set 
		// to variable.
		if nkInputIsMouseHoveringRect(win1_bound)
			cur_name = "Window 1"
			cur_bound = win1_bound
			if nk.InputIsMouseDown(NK_BUTTON_LEFT) then cur_state = "Left "
			if nk.InputIsMouseDown(NK_BUTTON_RIGHT) then cur_state = cur_state+"Right "
			if nk.InputIsMouseDown(NK_BUTTON_MIDDLE) then cur_state = cur_state+"Middle "
		endif
	endif
	nk.WindowEnd()
	
	// display second window
	if nk.WindowBegin("Window 2", 400, 420, 240, 240, NK_WINDOW_BORDER||NK_WINDOW_TITLE||NK_WINDOW_MOVABLE||NK_WINDOW_SCALABLE)
		win2_bound = nkWindowGetBounds()
		if nkInputIsMouseHoveringRect(win2_bound)
			if len(cur_name) = 0 or nk.WindowHasFocus()
				cur_name = "Window 2"
				cur_bound = win2_bound
				if nk.InputIsMouseDown(NK_BUTTON_LEFT) then cur_state = "Left "
				if nk.InputIsMouseDown(NK_BUTTON_RIGHT) then cur_state = cur_state+"Right "
				if nk.InputIsMouseDown(NK_BUTTON_MIDDLE) then cur_state = cur_state+"Middle "
			endif
		endif
	endif
	nk.WindowEnd()
	
	// display third window
	if nk.WindowBegin("Window 3", 670, 150, 240, 320, NK_WINDOW_BORDER||NK_WINDOW_TITLE||NK_WINDOW_MOVABLE||NK_WINDOW_SCALABLE)
		win3_bound = nkWindowGetBounds()
		if nkInputIsMouseHoveringRect(win3_bound)
			if len(cur_name) = 0 or nk.WindowHasFocus()
				cur_name = "Window 3"
				cur_bound = win3_bound
				if nk.InputIsMouseDown(NK_BUTTON_LEFT) then cur_state = "Left "
				if nk.InputIsMouseDown(NK_BUTTON_RIGHT) then cur_state = cur_state+"Right "
				if nk.InputIsMouseDown(NK_BUTTON_MIDDLE) then cur_state = cur_state+"Middle "
			endif
		endif
	endif
	nk.WindowEnd()
	
	if len(cur_state) > 0 then cur_state = cur_state + "down"

    nkSync()
loop
