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

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

require 'evas'

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

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

rect = $evas.new_rectangle()
rect.move(0, 0)
rect.resize(w, h)
rect.set_color(255, 255, 255, 255)
rect.set_layer(-1)
rect.show()

y = 10
text = $evas.new_text(
	:fontname => "Verdana_Bold",
	:fontsize => 10,
	:text => "Updated every half second")
text.move(10, y)
text.set_color(0, 0, 0, 255)
text.show()

y += text.height

text = $evas.new_text(
	:fontname => "Verdana_Bold",
	:fontsize => 10,
	:text => "and whenever the window receives an X event...")
text.move(10, y)
text.set_color(0, 0, 0, 255)
text.show()

text = $evas.new_text(
	:fontname => "Verdana_Bold",
	:fontsize => 20,
	:text => "")
text.move(100, 100)
text.set_color(0, 0, 0, 255)
text.show()

rect.onevent(EvasObject::EVENT_MOUSE_DOWN, proc { |b, x, y|
	$quit = true if b == 3
})

$evas.handle_x_events
$evas.render

$quit = false
$i = 0
xio = IO.new(dpy.xconnection, "r")
while not $quit 
	if select([xio], nil, nil, 0.5)
		$evas.handle_x_events
	end
	text.text = $i.to_s
	$i += 1
	$evas.render
end
