23
23
#include <touch/gestures.h>
24
24
#include <ui/ui_util.h>
25
25
#include <util.h>
26
+ #include <utils_assert.h>
26
27
27
28
#include <stdbool.h>
28
29
#include <stdint.h>
31
32
#define SCALE 6 // Divide active_count by scale to slow down motion
32
33
33
34
typedef struct {
34
- bool active_top ; // Marker is 'active', i.e., touched
35
- bool active_bottom ; // Marker is ' active', i.e., touched
36
- bool confirmed ; // Confirm event occurred
35
+ bool gesture_active ; // Marker is 'active', i.e., touched.
36
+ bool active [ 2 ] ; // Slider is active
37
+ bool confirmed ; // Confirm callback called
37
38
uint16_t active_count ; // Start at an offset to allow movement on first touch
38
39
uint16_t bottom_arrow_slidein ; // from zero to arrow height * SCALE
39
40
void (* callback )(void * user_data );
@@ -43,7 +44,7 @@ typedef struct {
43
44
bool confirm_gesture_is_active (component_t * component )
44
45
{
45
46
confirm_data_t * data = (confirm_data_t * )component -> data ;
46
- return data -> active_top ;
47
+ return data -> gesture_active ;
47
48
}
48
49
49
50
/**
@@ -57,19 +58,22 @@ static void _render(component_t* component)
57
58
confirm_data_t * data = (confirm_data_t * )component -> data ;
58
59
59
60
// Update active_count
60
- if (data -> active_top && data -> active_bottom ) {
61
+ if (data -> active [ 0 ] && data -> active [ 1 ] ) {
61
62
data -> active_count ++ ;
63
+ data -> gesture_active = true;
62
64
} else {
63
65
data -> active_count = MAX (SCALE - 1 , data -> active_count - SCALE );
64
66
}
65
67
66
- // Update bottom arrow slidein
67
- if (data -> active_top ) {
68
+ // Update bottom arrow slidein if top is active
69
+ if (data -> active [ top_slider ] ) {
68
70
if (data -> bottom_arrow_slidein < arrow_height * SCALE ) {
69
71
data -> bottom_arrow_slidein ++ ;
70
72
}
71
73
} else if (data -> bottom_arrow_slidein > 0 ) {
72
74
data -> bottom_arrow_slidein -- ;
75
+ } else if (data -> bottom_arrow_slidein == 0 ) {
76
+ data -> gesture_active = false;
73
77
}
74
78
75
79
// Draw the top arrow
@@ -101,31 +105,18 @@ static void _render(component_t* component)
101
105
static void _on_event (const event_t * event , component_t * component )
102
106
{
103
107
confirm_data_t * data = (confirm_data_t * )component -> data ;
108
+ ASSERT (event -> data .source < sizeof (data -> active ));
104
109
105
110
switch (event -> id ) {
106
- case EVENT_SLIDE_RELEASED :
107
- if (event -> data .source == top_slider ) {
108
- data -> active_top = false;
109
- } else {
110
- data -> active_bottom = false;
111
- }
112
- break ;
113
111
case EVENT_CONTINUOUS_TAP :
114
112
if (event -> data .position > SLIDER_POSITION_TWO_THIRD &&
115
113
event -> data .position <= MAX_SLIDER_POS ) {
116
- if (event -> data .source == top_slider ) {
117
- data -> active_top = true;
118
- } else {
119
- data -> active_bottom = true;
120
- }
114
+ data -> active [event -> data .source ] = true;
121
115
}
122
116
break ;
117
+ case EVENT_SLIDE_RELEASED :
123
118
case EVENT_SHORT_TAP :
124
- if (event -> data .source == top_slider ) {
125
- data -> active_top = false;
126
- } else {
127
- data -> active_bottom = false;
128
- }
119
+ data -> active [event -> data .source ] = false;
129
120
break ;
130
121
default :
131
122
break ;
@@ -155,8 +146,9 @@ component_t* confirm_gesture_create(void (*callback)(void*), void* user_data)
155
146
Abort ("Error: malloc confirm_gesture data" );
156
147
}
157
148
memset (data , 0 , sizeof (confirm_data_t ));
158
- data -> active_top = false;
159
- data -> active_bottom = false;
149
+ data -> gesture_active = false;
150
+ data -> active [0 ] = false;
151
+ data -> active [1 ] = false;
160
152
data -> confirmed = false;
161
153
data -> active_count = SCALE - 1 ;
162
154
data -> bottom_arrow_slidein = 0 ;
0 commit comments