summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ext/ruby2d/ruby2d.c4
-rw-r--r--lib/ruby2d/window.rb22
-rw-r--r--test/controller.rb39
3 files changed, 8 insertions, 57 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index ff506c6..0bc4214 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -456,10 +456,10 @@ void on_mouse(int x, int y) {
* Simple 2D `on_controller` input callback function
*/
static void on_controller(int which, bool is_axis, int axis, int val, bool is_btn, int btn, bool pressed) {
- r_funcall(ruby2d_window, "controller_callback", 6,
+ r_funcall(ruby2d_window, "controller_callback", 7,
INT2NUM(which),
is_axis ? R_TRUE : R_FALSE, INT2NUM(axis), INT2NUM(val),
- is_btn ? R_TRUE : R_FALSE, INT2NUM(btn)
+ is_btn ? R_TRUE : R_FALSE, INT2NUM(btn), pressed ? R_TRUE : R_FALSE
);
}
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index e2b7c88..f449b9d 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -176,26 +176,8 @@ module Ruby2D
true
end
- def controller_callback(which, is_axis, axis, val, is_btn, btn)
- @on_controller_proc.call(which, is_axis, axis, val, is_btn, btn)
-
- if is_axis
- if axis == 0 && val == -32768
- event = 'left'
- elsif axis == 0 && val == 32767
- event = 'right'
- elsif axis == 1 && val == -32768
- event = 'up'
- elsif axis == 1 && val == 32767
- event = 'down'
- end
- elsif is_btn
- event = btn
- end
-
- if @controller.has_key? event
- @controller[event].call
- end
+ def controller_callback(which, is_axis, axis, val, is_btn, btn, pressed)
+ @on_controller_proc.call(which, is_axis, axis, val, is_btn, btn, pressed)
end
def update_callback
diff --git a/test/controller.rb b/test/controller.rb
index 0007ddd..72a193f 100644
--- a/test/controller.rb
+++ b/test/controller.rb
@@ -1,47 +1,16 @@
require 'ruby2d'
-set width: 200, height: 100, title: "Ruby 2D – Controller"
+set width: 300, height: 200, title: "Ruby 2D — Controller"
-on controller: 'left' do
- puts "conroller left"
-end
-
-on controller: 'right' do
- puts "conroller right"
-end
-
-on controller: 'up' do
- puts "conroller up"
-end
-
-on controller: 'down' do
- puts "conroller down"
-end
-
-on controller: 0 do
- puts "conroller btn 0"
-end
-
-on controller: 1 do
- puts "conroller btn 1"
-end
-
-on controller: 2 do
- puts "conroller btn 2"
-end
-
-on controller: 3 do
- puts "conroller btn 3"
-end
-
-on_controller do |which, is_axis, axis, val, is_btn, btn|
+on_controller do |which, is_axis, axis, val, is_btn, btn, pressed|
puts "=== Controller Pressed ===",
"which: which",
"is_axis: #{is_axis}",
"axis: #{axis}",
"val: #{val}",
"is_btn: #{is_btn}",
- "btn: #{btn}"
+ "btn: #{btn}",
+ "pressed: #{pressed}", ""
end
show