Class: Cura::Event::Middleware::Translator::MouseClick
- Defined in:
- lib/cura/event/middleware/translator/mouse_click.rb
Overview
Translates MouseDown and MouseUp events into a MouseClick event.
Instance Method Summary collapse
-
#call(options = {}) ⇒ Object
Call this middleware.
-
#initialize ⇒ MouseClick
constructor
A new instance of MouseClick.
Constructor Details
#initialize ⇒ MouseClick
Returns a new instance of MouseClick.
12 13 14 |
# File 'lib/cura/event/middleware/translator/mouse_click.rb', line 12 def initialize @last_mouse_down_at = Time.now # TODO: This is not a great solution. If/when events are threaded, this will be bad. end |
Instance Method Details
#call(options = {}) ⇒ Object
Call this middleware.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cura/event/middleware/translator/mouse_click.rb', line 21 def call(={}) event = [:event] return unless event.is_a?(Event::Mouse) if event.down? @last_mouse_down_at = event.created_at @last_target = event.target elsif event.up? && event.created_at > @last_mouse_down_at && @last_target.respond_to?(:contains_coordinates) && @last_target.contains_coordinates?(x: event.x, y: event.y) @last_mouse_down_at = nil @last_target = nil [:dispatch_queue] << Event.new_from_name(:mouse_button, state: :click, target: event.target, x: event.x, y: event.y) # TODO: Left? Right? Termbox can't tell.. end end |