Class: Metro::EventData

Inherits:
Object
  • Object
show all
Defined in:
lib/metro/events/event_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ EventData

Returns a new instance of EventData.



6
7
8
9
10
11
# File 'lib/metro/events/event_data.rb', line 6

def initialize(window)
  @created_at = Time.now
  @mouse_point = Metro::Units::Point.at window.mouse_x, window.mouse_y

  capture_modifier_keys(window)
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



4
5
6
# File 'lib/metro/events/event_data.rb', line 4

def created_at
  @created_at
end

#mouse_pointObject (readonly)

Returns the value of attribute mouse_point.



4
5
6
# File 'lib/metro/events/event_data.rb', line 4

def mouse_point
  @mouse_point
end

Class Method Details

.modifier_key_listObject



34
35
36
# File 'lib/metro/events/event_data.rb', line 34

def self.modifier_key_list
  @modifier_key_list ||= modifier_key_list_names.map {|key| "Gosu::#{key}".constantize }
end

.modifier_key_list_namesObject

TODO: This attempt to reduce duplication is brittle and will likely end in heartache.



27
28
29
30
31
32
# File 'lib/metro/events/event_data.rb', line 27

def self.modifier_key_list_names
  @modifier_key_list_names ||= %w[ KbLeftControl KbRightControl
                                    KbLeftAlt KbRightAlt
                                    KbLeftMeta KbRightMeta
                                    KbLeftShift KbRightShift ]
end

Instance Method Details

#capture_modifier_keys(window) ⇒ Object



17
18
19
20
21
# File 'lib/metro/events/event_data.rb', line 17

def capture_modifier_keys(window)
  self.class.modifier_key_list.each do |key|
    modifier_keys[key] = window.button_down?(key)
  end
end

#modifier_keysObject



13
14
15
# File 'lib/metro/events/event_data.rb', line 13

def modifier_keys
  @modifier_keys ||= {}
end