Class: Tuile::MouseEvent
- Inherits:
-
Object
- Object
- Tuile::MouseEvent
- Defined in:
- lib/tuile/mouse_event.rb
Overview
A mouse event.
Instance Attribute Summary collapse
-
#button ⇒ Symbol?
readonly
One of ‘:left`, `:middle`, `:right`, `:scroll_up`, `:scroll_down`; `nil` if not known.
-
#x ⇒ Integer
readonly
X coordinate, 0-based.
-
#y ⇒ Integer
readonly
Y coordinate, 0-based.
Class Method Summary collapse
-
.mouse_event?(key) ⇒ Boolean
Checks whether given key is a mouse event key.
- .parse(key) ⇒ MouseEvent?
- .start_tracking ⇒ String
- .stop_tracking ⇒ String
Instance Method Summary collapse
-
#point ⇒ Point
The event’s position.
Instance Attribute Details
#button ⇒ Symbol? (readonly)
Returns one of ‘:left`, `:middle`, `:right`, `:scroll_up`, `:scroll_down`; `nil` if not known.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tuile/mouse_event.rb', line 13 class MouseEvent < Data.define(:button, :x, :y) # @return [Point] the event's position. def point = Point.new(x, y) # Checks whether given key is a mouse event key # @param key [String] key read via {Keys.getkey} # @return [Boolean] true if it is a mouse event def self.mouse_event?(key) key.start_with?("\e[M") && key.size >= 6 end # @param key [String] key read via {Keys.getkey} # @return [MouseEvent, nil] def self.parse(key) return nil unless mouse_event?(key) = key[3].ord - 32 # XTerm reports coordinates 1-based (column N is encoded as N + 32); # subtract 33 so that `x` and `y` are 0-based. x = key[4].ord - 33 y = key[5].ord - 33 = case when 0 then :left when 2 then :right when 1 then :middle when 64 then :scroll_up when 65 then :scroll_down end MouseEvent.new(, x, y) end # @return [String] def self.start_tracking = "\e[?1000h" # @return [String] def self.stop_tracking = "\e[?1000l" end |
#x ⇒ Integer (readonly)
Returns x coordinate, 0-based.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tuile/mouse_event.rb', line 13 class MouseEvent < Data.define(:button, :x, :y) # @return [Point] the event's position. def point = Point.new(x, y) # Checks whether given key is a mouse event key # @param key [String] key read via {Keys.getkey} # @return [Boolean] true if it is a mouse event def self.mouse_event?(key) key.start_with?("\e[M") && key.size >= 6 end # @param key [String] key read via {Keys.getkey} # @return [MouseEvent, nil] def self.parse(key) return nil unless mouse_event?(key) = key[3].ord - 32 # XTerm reports coordinates 1-based (column N is encoded as N + 32); # subtract 33 so that `x` and `y` are 0-based. x = key[4].ord - 33 y = key[5].ord - 33 = case when 0 then :left when 2 then :right when 1 then :middle when 64 then :scroll_up when 65 then :scroll_down end MouseEvent.new(, x, y) end # @return [String] def self.start_tracking = "\e[?1000h" # @return [String] def self.stop_tracking = "\e[?1000l" end |
#y ⇒ Integer (readonly)
Returns y coordinate, 0-based.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tuile/mouse_event.rb', line 13 class MouseEvent < Data.define(:button, :x, :y) # @return [Point] the event's position. def point = Point.new(x, y) # Checks whether given key is a mouse event key # @param key [String] key read via {Keys.getkey} # @return [Boolean] true if it is a mouse event def self.mouse_event?(key) key.start_with?("\e[M") && key.size >= 6 end # @param key [String] key read via {Keys.getkey} # @return [MouseEvent, nil] def self.parse(key) return nil unless mouse_event?(key) = key[3].ord - 32 # XTerm reports coordinates 1-based (column N is encoded as N + 32); # subtract 33 so that `x` and `y` are 0-based. x = key[4].ord - 33 y = key[5].ord - 33 = case when 0 then :left when 2 then :right when 1 then :middle when 64 then :scroll_up when 65 then :scroll_down end MouseEvent.new(, x, y) end # @return [String] def self.start_tracking = "\e[?1000h" # @return [String] def self.stop_tracking = "\e[?1000l" end |
Class Method Details
.mouse_event?(key) ⇒ Boolean
Checks whether given key is a mouse event key
20 21 22 |
# File 'lib/tuile/mouse_event.rb', line 20 def self.mouse_event?(key) key.start_with?("\e[M") && key.size >= 6 end |
.parse(key) ⇒ MouseEvent?
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tuile/mouse_event.rb', line 26 def self.parse(key) return nil unless mouse_event?(key) = key[3].ord - 32 # XTerm reports coordinates 1-based (column N is encoded as N + 32); # subtract 33 so that `x` and `y` are 0-based. x = key[4].ord - 33 y = key[5].ord - 33 = case when 0 then :left when 2 then :right when 1 then :middle when 64 then :scroll_up when 65 then :scroll_down end MouseEvent.new(, x, y) end |
.start_tracking ⇒ String
45 46 |
# File 'lib/tuile/mouse_event.rb', line 45 def self.start_tracking = "\e[?1000h" # @return [String] |
.stop_tracking ⇒ String
47 |
# File 'lib/tuile/mouse_event.rb', line 47 def self.stop_tracking = "\e[?1000l" |