Class: AdventureRL::EventHandlers::MouseButtons
- Inherits:
-
Buttons
- Object
- EventHandler
- Buttons
- AdventureRL::EventHandlers::MouseButtons
- Defined in:
- lib/AdventureRL/EventHandlers/MouseButtons.rb
Constant Summary collapse
- MOUSE_BUTTON_IDS =
This constant contains the IDs of all mouse buttons.
[ Gosu::MS_LEFT, Gosu::MS_MIDDLE, Gosu::MS_RIGHT, Gosu::MS_WHEEL_DOWN, Gosu::MS_WHEEL_UP ] .concat((0 .. 7).map do |n| next Gosu.const_get "MS_OTHER_#{n.to_s}" end)
- DEFAULT_SETTINGS =
Settings.new( only_mouse_buttons: true )
Constants inherited from Buttons
Buttons::BUTTON_EVENT_HANDLERS
Instance Method Summary collapse
- #add_pressable_button(*args) ⇒ Object
- #button_down(btnid) ⇒ Object
- #button_up(btnid) ⇒ Object
-
#initialize(settings = {}) ⇒ MouseButtons
constructor
A new instance of MouseButtons.
- #update ⇒ Object
Methods inherited from Buttons
button_down, button_up, #get_pressable_buttons, update
Methods inherited from EventHandler
#add_event, #subscribe, #trigger, #unsubscribe
Constructor Details
#initialize(settings = {}) ⇒ MouseButtons
19 20 21 22 23 |
# File 'lib/AdventureRL/EventHandlers/MouseButtons.rb', line 19 def initialize settings = {} @settings = DEFAULT_SETTINGS.merge settings = @settings.get :only_mouse_buttons super @settings end |
Instance Method Details
#add_pressable_button(*args) ⇒ Object
63 64 65 66 67 |
# File 'lib/AdventureRL/EventHandlers/MouseButtons.rb', line 63 def *args Helpers::Error.error( "Cannot add pressable button(s) to #{self.class.name}." ) end |
#button_down(btnid) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/AdventureRL/EventHandlers/MouseButtons.rb', line 25 def btnid super unless () trigger( :mouse_down, (btnid), shift: , control: , alt: ) if (MOUSE_BUTTON_IDS.include?(btnid)) end |
#button_up(btnid) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/AdventureRL/EventHandlers/MouseButtons.rb', line 36 def btnid return unless (MOUSE_BUTTON_IDS.include? btnid) trigger( :mouse_up, (btnid), shift: , control: , alt: ) end |
#update ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/AdventureRL/EventHandlers/MouseButtons.rb', line 47 def update pressed_btnids = MOUSE_BUTTON_IDS.select do |btnid| next Gosu.(btnid) end return unless (pressed_btnids.any?) pressed_btnids.each do |btnid| trigger( :mouse_press, (btnid), shift: , control: , alt: ) end end |