summaryrefslogtreecommitdiffhomepage
path: root/lib/ruby2d/window.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ruby2d/window.rb')
-rw-r--r--lib/ruby2d/window.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 9d9012b..eddb833 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -15,9 +15,7 @@ module Ruby2D
@fps = 60
@vsync = vsync
@objects = []
- @keys = {}
- @keys_down = {}
- @controller = {}
+ @keys, @keys_up, @keys_down, @controller = {}, {}, {}, {}
@update_proc = Proc.new {}
end
@@ -82,7 +80,7 @@ module Ruby2D
true
end
- def on(mouse: nil, key: nil, key_down: nil, controller: nil, &proc)
+ def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
unless mouse.nil?
# reg_mouse(btn, &proc)
end
@@ -91,6 +89,10 @@ module Ruby2D
reg_key(key, &proc)
end
+ unless key_up.nil?
+ reg_key_up(key_up, &proc)
+ end
+
unless key_down.nil?
reg_key_down(key_down, &proc)
end
@@ -107,6 +109,16 @@ module Ruby2D
end
end
+ def key_up_callback(key)
+ key.downcase!
+ if @keys_up.has_key? 'any'
+ @keys_up['any'].call
+ end
+ if @keys_up.has_key? key
+ @keys_up[key].call
+ end
+ end
+
def key_down_callback(key)
key.downcase!
if @keys_down.has_key? key
@@ -159,6 +171,12 @@ module Ruby2D
end
# Register key string with proc
+ def reg_key_up(key, &proc)
+ @keys_up[key] = proc
+ true
+ end
+
+ # Register key string with proc
def reg_key_down(key, &proc)
@keys_down[key] = proc
true