diff options
| author | Tom Black <[email protected]> | 2017-12-02 21:58:07 -0800 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-12-02 22:27:16 -0800 |
| commit | b13074ebe542aa25c5b3b08afed4b60e1d23e1c6 (patch) | |
| tree | 6ed6ca0e0bdf74198981bf01f626c6ade21b251c /lib | |
| parent | 18e5a492e9f3f3ba6c69998f577f7cc0d6ea085d (diff) | |
| download | ruby2d-b13074ebe542aa25c5b3b08afed4b60e1d23e1c6.tar.gz ruby2d-b13074ebe542aa25c5b3b08afed4b60e1d23e1c6.zip | |
Use controller mappings
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/window.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index 0a5a995..686c6b0 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -6,10 +6,12 @@ module Ruby2D attr_reader :objects attr_accessor :mouse_x, :mouse_y, :frames, :fps - MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y) - KeyEvent = Struct.new(:type, :key) - ControllerEvent = Struct.new(:which, :type, :axis, :value, :button) EventDescriptor = Struct.new(:type, :id) + MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y) + KeyEvent = Struct.new(:type, :key) + ControllerEvent = Struct.new(:which, :type, :axis, :value, :button) + ControllerAxisEvent = Struct.new(:which, :axis, :value) + ControllerButtonEvent = Struct.new(:which, :button) def initialize(args = {}) @title = args[:title] || "Ruby 2D" @@ -173,10 +175,6 @@ module Ruby2D end def mouse_callback(type, button, direction, x, y, delta_x, delta_y) - # Convert to symbols (see MRuby bug in native extension) - button = button.to_sym unless button == nil - direction = direction.to_sym unless direction == nil - # All mouse events @events[:mouse].each do |id, e| e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y)) @@ -216,17 +214,17 @@ module Ruby2D # When controller axis motion, like analog sticks when :axis @events[:controller_axis].each do |id, e| - e.call(ControllerEvent.new(which, type, axis, value, nil)) + e.call(ControllerAxisEvent.new(which, axis, value)) end # When controller button is pressed when :button_down @events[:controller_button_down].each do |id, e| - e.call(ControllerEvent.new(which, type, nil, nil, button)) + e.call(ControllerButtonEvent.new(which, button)) end # When controller button is released when :button_up @events[:controller_button_up].each do |id, e| - e.call(ControllerEvent.new(which, type, nil, nil, button)) + e.call(ControllerButtonEvent.new(which, button)) end end end |
