require '../src/ClanRuby'
include ClanRuby

class ClanRubyMouse

	def onMouseMove(x, y)
		puts 'Move: ***', x, y
	end
	
	def onButtonPress(key)
		puts 'Press ******', key.id
	end
end
#
# This sample script show the use of input handlers..
#

#
# Initialize the core and display libs.
#
SetupCore.init()
SetupDisplay.init()

#
# Create an 640 X 480 window, 16 bits of color.
#
Display.setVideoMode( 640, 480, 16, false )

#
# Now create an event handler object and use it.
#

x=0
y=0

l1=ClanRubyMouse.new()
l2=ClanRubyMouse.new()


Mouse.addMoveListener(l1)
Mouse.addPressListener(l1)


#
# Just draw a block where the mouse last was.
#

count=0

while ( ! KeyBoard.getKeycode( CL_KEY_ESCAPE) )

	Display.fillRect( 0, 0, 640, 480, 1, 1, 1, 1)
	Display.fillRect( x-20, y-20, x+20, y+20, 1, 0, 0, 1)

	if (  KeyBoard.getKeycode( CL_KEY_X ) )
		Mouse.removeMoveListener(l1)
	end
	

	if (  KeyBoard.getKeycode( CL_KEY_Y ) )
		Mouse.removeMoveListener(l2)
	end

	if (  KeyBoard.getKeycode( CL_KEY_A ) )
		Mouse.addMoveListener(l1)
	end
	
	if (  KeyBoard.getKeycode( CL_KEY_B ) )
		Mouse.addMoveListener(l2)
	end
	
	#
	# Make it all visible.
	#
	Display.flipDisplay()
	System.keepAlive(20)
	
	count=count+1
	
end

#
# Clean up
#
SetupDisplay.deinit()
SetupCore.deinit()




