summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/application.rb4
-rw-r--r--lib/ruby2d/dsl.rb4
-rw-r--r--lib/ruby2d/window.rb12
3 files changed, 16 insertions, 4 deletions
diff --git a/lib/ruby2d/application.rb b/lib/ruby2d/application.rb
index ebef2b5..3883a88 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, &proc)
- @@window.on(mouse: mouse, key: key, &proc)
+ 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)
end
def add(o)
diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb
index c5bed09..2c8db94 100644
--- a/lib/ruby2d/dsl.rb
+++ b/lib/ruby2d/dsl.rb
@@ -13,8 +13,8 @@ module Ruby2D::DSL
Ruby2D::Application.set(opts)
end
- def on(mouse: nil, key: nil, &proc)
- Ruby2D::Application.on(mouse: mouse, key: key, &proc)
+ def on(mouse: nil, key: nil, key_down: nil, controller: nil, &proc)
+ Ruby2D::Application.on(mouse: mouse, key: key, key_down: key_down, controller: controller, &proc)
end
def update(&proc)
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 6011d42..200a1e9 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -13,6 +13,7 @@ module Ruby2D
@objects = []
@keys = {}
@keys_down = {}
+ @controller = {}
@update_proc = Proc.new {}
end
@@ -88,6 +89,11 @@ module Ruby2D
true
end
+ unless controller.nil?
+ reg_controller(controller, &proc)
+ end
+ end
+
def key_callback(key)
key.downcase!
if @keys.has_key? key
@@ -128,5 +134,11 @@ module Ruby2D
end
end
+ # Register controller string with proc
+ def reg_controller(event, &proc)
+ @controller[event] = proc
+ true
+ end
+
end
end