Class: TouchscreenTaps::GestureBuffer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeGestureBuffer

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

#eventsObject (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_touchesObject



36
37
38
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 36

def down_touches
  events_by_type(DOWN_TYPE)
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 28

def empty?
  @events.empty?
end

#gesture_in_progress?Boolean

Returns:

  • (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_touchesObject



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_touchesObject



40
41
42
# File 'lib/touchscreen_taps/gesture_buffer.rb', line 40

def up_touches
  events_by_type(UP_TYPE)
end