Class: TouchscreenTaps::GestureBuffer
- Inherits:
-
Object
- Object
- TouchscreenTaps::GestureBuffer
- Defined in:
- lib/touchscreen_taps/gesture_buffer.rb
Overview
Buffer for all events related to a single gesture Gesture is considered started when first finger touches the screen Gesture is considired ended when last finger leaves the screen Between start and end points at least one finger should be touching the screen
Constant Summary collapse
- TIME_TO_KEEP =
seconds
3
- UP_TYPE =
'UP'
- DOWN_TYPE =
'DOWN'
- MOTION_TYPE =
'MOTION'
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #down_touches ⇒ Object
- #empty? ⇒ Boolean
- #gesture_in_progress? ⇒ Boolean
-
#initialize ⇒ GestureBuffer
constructor
A new instance of GestureBuffer.
- #motion_touches ⇒ Object
- #push(event) ⇒ Object
- #up_touches ⇒ Object
Constructor Details
#initialize ⇒ GestureBuffer
Returns a new instance of GestureBuffer.
16 17 18 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 16 def initialize @events = [] end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
14 15 16 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 14 def events @events end |
Instance Method Details
#down_touches ⇒ Object
36 37 38 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 36 def down_touches events_by_type(DOWN_TYPE) end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 28 def empty? @events.empty? end |
#gesture_in_progress? ⇒ Boolean
32 33 34 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 32 def gesture_in_progress? down_touches.count > up_touches.count end |
#motion_touches ⇒ Object
44 45 46 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 44 def motion_touches events_by_type(MOTION_TYPE) end |
#push(event) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 20 def push(event) delete_old_events clear unless gesture_in_progress? remove_previous_events(event) if repeating_touch?(event) @events.push(event) end |
#up_touches ⇒ Object
40 41 42 |
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 40 def up_touches events_by_type(UP_TYPE) end |