68
68
// Types and Structures Definition
69
69
//----------------------------------------------------------------------------------
70
70
71
+ typedef enum {
72
+ FINGER_STATE_REMOVED = 0 , // state when finger was removed and we handled its removal + default state
73
+ FINGER_STATE_REMOVING , // state when finger is currently being removed from panel (released event)
74
+ FINGER_STATE_TOUCHING , // state when finger is touching panel at any time
75
+ } FingerState ;
76
+
71
77
struct finger {
72
- TouchAction action ;
78
+ FingerState state ;
73
79
int x ;
74
80
int y ;
75
81
bool resetNextFrame ;
@@ -315,7 +321,7 @@ static int init_touch(const char *dev_path, const char *origin_path) {
315
321
for (int i = 0 ; i < MAX_TOUCH_POINTS ; ++ i ) {
316
322
platform .touch .fingers [i ].x = -1 ;
317
323
platform .touch .fingers [i ].y = -1 ;
318
- platform .touch .fingers [i ].action = TOUCH_ACTION_UP ;
324
+ platform .touch .fingers [i ].state = FINGER_STATE_REMOVED ;
319
325
platform .touch .fingers [i ].resetNextFrame = false;
320
326
321
327
CORE .Input .Touch .currentTouchState [0 ] = 0 ;
@@ -640,7 +646,7 @@ void PollInputEvents(void) {
640
646
if (event .type == SYN_REPORT ) { // synchronization frame. Expose completed events back to the library
641
647
642
648
for (int i = 0 ; i < MAX_TOUCH_POINTS ; ++ i ) {
643
- if (platform .touch .fingers [i ].action == TOUCH_ACTION_DOWN ) {
649
+ if (platform .touch .fingers [i ].state == FINGER_STATE_TOUCHING ) {
644
650
645
651
CORE .Input .Touch .position [i ].x = platform .touch .fingers [i ].x ;
646
652
CORE .Input .Touch .position [i ].y = platform .touch .fingers [i ].y ;
@@ -653,9 +659,10 @@ void PollInputEvents(void) {
653
659
CORE .Input .Mouse .currentPosition .y = platform .touch .fingers [i ].y ;
654
660
}
655
661
656
- } else if (platform .touch .fingers [i ].action == TOUCH_ACTION_UP ) {
662
+ } else if (platform .touch .fingers [i ].state == FINGER_STATE_REMOVING ) {
657
663
CORE .Input .Touch .position [i ].x = -1 ;
658
664
CORE .Input .Touch .position [i ].y = -1 ;
665
+
659
666
// if we received a touch down and up event in the same frame,
660
667
// delay up event by one frame so that API user needs no special handling
661
668
if (CORE .Input .Touch .previousTouchState [i ] == 0 ) {
@@ -664,6 +671,8 @@ void PollInputEvents(void) {
664
671
} else {
665
672
CORE .Input .Touch .currentTouchState [i ] = 0 ;
666
673
}
674
+
675
+ platform .touch .fingers [i ].state = FINGER_STATE_REMOVED ;
667
676
}
668
677
}
669
678
@@ -672,7 +681,7 @@ void PollInputEvents(void) {
672
681
if (event .code == ABS_MT_SLOT ) { // switch finger
673
682
slot = event .value ;
674
683
} else if (event .code == ABS_MT_TRACKING_ID ) { // finger on screen or not
675
- platform .touch .fingers [slot ].action = event .value == -1 ? TOUCH_ACTION_UP : TOUCH_ACTION_DOWN ;
684
+ platform .touch .fingers [slot ].state = event .value == -1 ? FINGER_STATE_REMOVING : FINGER_STATE_TOUCHING ;
676
685
} else if (event .code == ABS_MT_POSITION_X ) {
677
686
platform .touch .fingers [slot ].y = (1 - platform .touch .canonical ) * (CORE .Window .screen .height - event .value ) + (platform .touch .canonical * event .value );
678
687
} else if (event .code == ABS_MT_POSITION_Y ) {
@@ -683,7 +692,7 @@ void PollInputEvents(void) {
683
692
684
693
// count how many fingers are left on the screen after processing all events
685
694
for (int i = 0 ; i < MAX_TOUCH_POINTS ; ++ i ) {
686
- CORE .Input .Touch .pointCount += platform .touch .fingers [i ].action != TOUCH_ACTION_UP ;
695
+ CORE .Input .Touch .pointCount += platform .touch .fingers [i ].state == FINGER_STATE_TOUCHING ;
687
696
}
688
697
}
689
698
0 commit comments