require '../src/ClanRuby'
include ClanRuby
include Math

#
# 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 )

#
# Get the logo image.
#
sur_logo = TargaProvider::create("logo.tga")
puts 'sur_logo:', sur_logo

#
# Display loop
#
sin_count = 0.0
ypos = 0.0
ydir = 3.0

while ( ! KeyBoard.getKeycode( CL_KEY_ESCAPE) )

	Display::clearDisplay(0, 0, 0.2, 1.0)

	ypos += ydir
	if (ypos+200 >= Display::height() || ypos < 0)
		ydir *= -1
	end
				
	Display::drawLine(0, ypos-1, Display::width(), ypos-1, 1, 0, 0)
	Display::drawLine(0, ypos+198, Display::width(), ypos+198, 1, 0, 0)

	# Show the logo surface.
	# Use the width() and height() functions of both
	# Display and CL_Surface, to show the surface in the bottom right corner

	sur_logo.putScreen(
	Display::width()-sur_logo.width(),
	Display::height()-sur_logo.height())

	Display::pushClipRect( ClipRect.new(0, ypos, Display::width(), ypos+198))

	# Draw a rectangle in the center of the screen
	# going from (240, 140) . (440, 340) _not_ including the 
	# pixels in the right-most column and bottom-most row (440, 340)
	Display::fillRect(240, 140, 440, 340, 1.0, 1.0, 1.0, 1.0)

	# Frame the rectangle with red lines
	Display::drawLine(240, 140, 440, 140, 1.0, 0, 0)
	Display::drawLine(240, 340, 440, 340, 1.0, 0, 0)
	Display::drawLine(240, 140, 240, 340, 1.0, 0, 0)
	Display::drawLine(440, 140, 440, 340, 1.0, 0, 0)

	# Show a few alpha-blending moving rectangles that moves in circles
	x = cos(sin_count)*120
	y = sin(sin_count)*120
	sin_count += 0.05
	Display::fillRect(320+x-30, 240+y-30, 320+x+30, 240+y+30, 0, 1, 0, 0.5)
	x = cos(sin_count+3.14159)*120
	y = sin(sin_count+3.14159)*120
	Display::fillRect(320+x-30,240+y-30,320+x+30,240+y+30, 1, 1, 0, 0.5)

	Display::popClipRect()

	#
	# Make it all visible.
	#
	Display.flipDisplay()
	System.keepAlive(2)
	
end

#
# Clean up
#
SetupDisplay.deinit()
SetupCore.deinit()

