-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swipe.elm
34 lines (24 loc) · 1.49 KB
/
Swipe.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Touch
data SwipeDirection = Left|Right|Up|Down|None
data TouchData = { positionX : Int,
positionY : Int,
startPositionX : Int,
startPositionY : Int,
touchTime : Int,
swipeDirection : SwipeDirection }
data TouchState = { touches : [TouchData] }
checkIfTouchEqual touch touchData = let c1 = (touchData.startPositionX,touchData.startPositionY,touchData.touchTime)
c2 = (touch.x0, touch.y0, touch.t0)
in c1 == c2
checkIfTouchEnded touches touchData = let touch = head touches
in if | touch == [] -> False
| checkIfTouchEqual touch touchData == True -> True
| otherwise checkIfTouchEnded (tail touches) touchData
checkIfNewTouch touch touchState = let touchData = head touchState
in if | touchData == [] -> False
| checkIfTouchEqual touch touchData == True -> True
| otherwise checkIfNewTouch touch (tail touchState)
updateTouches
analyseTouches touches touchState = let currentTouches = filter (checkIfTouchEnded touches) touchState
newTouches = filter (checkIfNewTouch touches) touchState.touches
main = asText <~ Touch.touches