Class: Fusuma::Plugin::Detectors::TouchDetectors::HoldDetector

Inherits:
TapHoldBase
  • Object
show all
Defined in:
lib/fusuma/plugin/detectors/touch_detectors/hold_detector.rb

Instance Method Summary collapse

Instance Method Details

#detect(touch_buffer) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fusuma/plugin/detectors/touch_detectors/hold_detector.rb', line 9

def detect(touch_buffer)
  MultiLogger.debug('> hold detector')

  MultiLogger.debug('  no movement?')
  if touch_buffer.moved?
    touch_buffer.finger_movements.each do |finger, movement|
      distance = Touchscreen::Math.distance(movement[:first_position], movement[:last_position])
      if distance > jitter_threshold
        MultiLogger.debug("  finger #{finger} moved too much: #{distance} > #{jitter_threshold}")
        return
      end
    end
  end

  MultiLogger.debug("  tap / hold threshold? (duration #{touch_buffer.duration})")
  return unless touch_buffer.duration > tap_hold_threshold

  MultiLogger.debug("  hold (#{touch_buffer.finger}) detected!")
  Plugin::Events::Records::TouchRecords::HoldRecord.new(finger: touch_buffer.finger)
end