#!/usr/bin/env ruby
# vim: ts=2 sw=2

# make this demo run without installing the library...
$: << "../src"

require 'evas'

MYFONT = "Verdana_Bold"

dpy = Display.new
w, h = dpy.width/2, dpy.height/2

$evas = Evas.new(
	:display => dpy,
	:width => w, :height => h,
	:title => 'Evas Demonstration',
	:fontpath => '/usr/share/fonts/truetype')

img = $evas.new_image(
	:x => 0, :y => 0,
	:width => w, :height => h,
	:layer => -1,
	:fill_width => 256, :fill_height => 256,
	:path => 'bg.png'
)
img.show()

img.onevent(EvasObject::EVENT_MOUSE_DOWN) {
	$quit = true
}

$logos = []
4.times do |i|
	$logos << $evas.new_text(
		:fontname => MYFONT, :fontsize => 15,
		:text => "Ruby/Evas"
	)
	$logos[i].show
end
$logos[0].set_color(0, 0, 255, 0)
$logos[1].set_color(0, 255, 0, 0)
$logos[2].set_color(255, 0, 0, 0)
$logos[3].set_color(255, 255, 255, 0)

$logo_x = (w - $logos[0].width) / 2
$logo_y = (h - $logos[0].height) / 2

$pi = 3.1415926
$pi_4 = $pi / 4.0
$radius = 50
$angle = $pi

def update_logos(angle, radius)
	4.times do |i|
		x =  Math.sin(angle + (i * $pi_4))
		y = -Math.cos(angle + (i * $pi_4))

		sx = $logo_x + x * radius
		sy = $logo_y + y * radius

		$logos[i].move(sx, sy)
		$logos[i].alpha = (-y + 1) * 128.0
	end
end

$quit = false
xio = IO.new(dpy.xconnection, "r")
while not $quit 
	if select([xio], nil, nil, 0.02)
		$evas.handle_x_events
	end
	update_logos($angle, $radius)
	$angle += ($pi / 70.0)
	$angle -= 2*$pi if $angle > 2*$pi
	$evas.render
end

