class Cura::Event::Middleware::Translator::MouseClick
Translates MouseDown and MouseUp events into a MouseClick
event.
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
call(options={})
click to toggle source
Call this middleware.
@param [#to_h] options @option options [Event::Dispatcher] :dispatcher @option options [Event::Base] :event
# File lib/cura/event/middleware/translator/mouse_click.rb, line 21 def call(options={}) event = options[: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 options[: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