diff options
| author | Tom Black <[email protected]> | 2016-10-09 16:05:50 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2016-10-09 16:05:50 -0400 |
| commit | 365d286e7789b1ac2e7b3a825732dd615b76aea6 (patch) | |
| tree | f2d05f32427b4976ea29d4c8762ac02aeb1e7c4f | |
| parent | 4b3cd2c81ad8c03dd25bbb8617e54e349054fcf5 (diff) | |
| download | ruby2d-365d286e7789b1ac2e7b3a825732dd615b76aea6.tar.gz ruby2d-365d286e7789b1ac2e7b3a825732dd615b76aea6.zip | |
Add `key_up` to window and DSL
| -rw-r--r-- | lib/ruby2d/application.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/dsl.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/window.rb | 26 |
3 files changed, 26 insertions, 8 deletions
diff --git a/lib/ruby2d/application.rb b/lib/ruby2d/application.rb index 2ceff4b..5a91760 100644 --- a/lib/ruby2d/application.rb +++ b/lib/ruby2d/application.rb @@ -12,8 +12,8 @@ module Ruby2D::Application @@window.set(opts) end - def on(mouse: nil, key: nil, key_down: nil, controller: nil, &proc) - @@window.on(mouse: mouse, key: key, key_down: key_down, controller: controller, &proc) + def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc) + @@window.on(mouse: mouse, key: key, key_up: key_up, key_down: key_down, controller: controller, &proc) end def add(o) diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb index 3960a0f..431f83f 100644 --- a/lib/ruby2d/dsl.rb +++ b/lib/ruby2d/dsl.rb @@ -9,8 +9,8 @@ module Ruby2D::DSL Application.set(opts) end - def on(mouse: nil, key: nil, key_down: nil, controller: nil, &proc) - Application.on(mouse: mouse, key: key, key_down: key_down, controller: controller, &proc) + def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc) + Application.on(mouse: mouse, key: key, key_up: key_up, key_down: key_down, controller: controller, &proc) end def update(&proc) 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 |
