Class: Rubygame::EventTriggers::MouseMoveTrigger
- Inherits:
-
Object
- Object
- Rubygame::EventTriggers::MouseMoveTrigger
- Defined in:
- lib/rubygame/event_triggers.rb
Overview
MouseMoveTrigger is an event trigger which fires when the mouse cursor is moved (MouseMoved). If buttons are given, it only matches events with those buttons. See #new for details.
Instance Method Summary collapse
-
#initialize(buttons = :any) ⇒ MouseMoveTrigger
constructor
Create a new instance of MouseMoveTrigger.
-
#match?(event) ⇒ Boolean
Returns true if the given event matches this trigger.
Constructor Details
#initialize(buttons = :any) ⇒ MouseMoveTrigger
Create a new instance of MouseMoveTrigger.
The buttons parameter determines which mouse buttons can be held down and still match this trigger. It can be one of:
-
:any
. Matches if zero or more buttons are held. -
:none
. Matches when zero buttons are being held. -
:mouse_left
, etc. Matches when at least the given button is being held. -
An array of
:mouse_*
symbols. Matches when exactly all buttons in the Array are being held, and nothing else.
Example:
# Matches all MouseMoved events, regardless of buttons:
MouseMoveTrigger.new()
MouseMoveTrigger.new( :any )
# Matches only if no buttons pressed:
MouseMoveTrigger.new( :none )
MouseMoveTrigger.new( [] )
# Matches if left mouse is held down, maybe with others:
MouseMoveTrigger.new( :mouse_left )
# Matches if ONLY left mouse held down, nothing else:
MouseMoveTrigger.new( [:mouse_left] )
# Matches if BOTH left AND right mouse are held down, nothing else:
MouseMoveTrigger.new( [:mouse_left, :mouse_right] )
# Matches if EITHER left OR right mouse are held down:
OrTrigger.new( MouseMoveTrigger.new(:mouse_left),
MouseMoveTrigger.new(:mouse_right) )
594 595 596 |
# File 'lib/rubygame/event_triggers.rb', line 594 def initialize( =:any ) @buttons = end |
Instance Method Details
#match?(event) ⇒ Boolean
Returns true if the given event matches this trigger. See #new for information about how events match.
602 603 604 605 606 607 608 609 610 611 |
# File 'lib/rubygame/event_triggers.rb', line 602 def match?( event ) if event.kind_of?( Rubygame::Events::MouseMoved ) ((@buttons == :any) or (@buttons == :none and event. == []) or ((event.)) or (event..include?(@buttons))) else false end end |