Class: Cura::Event::Middleware::Translator::MouseClick

Inherits:
Base
  • Object
show all
Defined in:
lib/cura/event/middleware/translator/mouse_click.rb

Overview

Translates MouseDown and MouseUp events into a MouseClick event.

Instance Method Summary collapse

Constructor Details

#initializeMouseClick

Returns a new instance of MouseClick.



14
15
16
# File 'lib/cura/event/middleware/translator/mouse_click.rb', line 14

def initialize
  @last_mouse_down_at = Time.now
end

Instance Method Details

#call(options = {}) ⇒ Object

Call this middleware.

Parameters:

  • options (#to_h) (defaults to: {})

Options Hash (options):



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cura/event/middleware/translator/mouse_click.rb', line 23

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