diff options
Diffstat (limited to 'go/ui/hoverDetector.go')
| -rw-r--r-- | go/ui/hoverDetector.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/go/ui/hoverDetector.go b/go/ui/hoverDetector.go index 385b2ffd..d18ea53e 100644 --- a/go/ui/hoverDetector.go +++ b/go/ui/hoverDetector.go @@ -6,23 +6,23 @@ package ui type _hoverDetector struct { last_x, last_y int ticks int + threshold int } -const HOVER_THRESHOLD = 60 var ( - hoverDetector _hoverDetector - longtapHoverDetector _hoverDetector + hoverDetector = _hoverDetector{threshold: 60} + longtapHoverDetector = _longtapHoverDetector{} ) func (h *_hoverDetector) update(x, y int) (ev InputEvent, ch bool) { if x == h.last_x && y == h.last_y { h.ticks = h.ticks + 1 - if h.ticks == HOVER_THRESHOLD { + if h.ticks == h.threshold { return InputEvent{HoverStart, x, y, nil}, true } } else { - if h.ticks > HOVER_THRESHOLD { + if h.ticks > h.threshold { ev = InputEvent{HoverEnd, h.last_x, h.last_y, nil} ch = true } @@ -32,3 +32,24 @@ func (h *_hoverDetector) update(x, y int) (ev InputEvent, ch bool) { return } + +type _longtapHoverDetector struct { + active *longtap +} + +func (h *_longtapHoverDetector) update(longtap *longtap) (ev InputEvent, ch bool) { + if longtap != nil && h.active == nil { + h.active = longtap + return InputEvent{HoverStart, longtap.x, longtap.y, nil}, true + } + return InputEvent{}, false +} + +func (h *_longtapHoverDetector) reset() (ev InputEvent, ch bool) { + if h.active != nil { + ev := InputEvent{HoverEnd, h.active.x, h.active.y, nil} + h.active = nil + return ev, true + } + return InputEvent{}, false +} |
