|
|
#Copyright (C) 2006 by Han Dao
#This is an example program that demostrate the input system of the rbGooey library.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
require "rubygame"
require "rbGooey"
include Rubygame
TTF.setup()
class Input
def initialize
@main = Main.new()
@main.screen_set(800, 600)
@main.font_set("freesansbold.ttf", 24)
@main.bgcolor = [20,70,20]
@main.fgcolor = [200,200,200]
@text = TextMode.new(@main)
input()
end
def input
@text.add("Enter a number for how many seconds you want.")
@text.render.render_text()
integer = @text.input.input.to_i()
@text.clear()
@text.add("Enter a message to show when it is done.")
@text.render.render_text()
string = @text.input.input()
Run.new(@main,integer,string)
end
end
class Run
def initialize main , integer , string
@main = main
@text = TextMode.new(@main)
@status = false
@count = 0
@time = Timer.new(integer) {
if @status == false
@text.clear()
@text.add(string)
@text.render.render_text()
@status = true
end
option()
}
@display = Timer.new(1) {
if @status == false
@text.clear()
@count += 1
@text.add(@count.to_s + "/" + integer.to_s)
@text.render.render_text()
end
}
@time.start()
@display.start()
action()
end
def action
loop do
@time.check()
@display.check()
@main.screen.flip()
end
end
def option
q = Rubygame::Queue.instance()
q.get.each do |ev|
case ev
when Rubygame::KeyDownEvent
case ev.key
when Rubygame::K_ESCAPE
exit
when Rubygame::K_RETURN
Input.new
end
end
end
end
end
class Timer
def initialize( interval_in_seconds, &action )
@interval = interval_in_seconds
@action = action
end
def check
t = Time.now.tv_sec
if t >= @fire_at
@action.call
@fire_at = t + @interval
end
end
def start
@fire_at = Time.now.tv_sec + @interval
end
end
Input.new
|