diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-20 16:47:05 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-20 16:47:05 +0300 |
commit | 992e3d00aa407d0d1d481051e2504bc56395dfb8 (patch) | |
tree | 5961b052b2c20daf10f2c35c2c6f37656b64659e /src/ui/touch.c | |
parent | d41d2e4f68ac990cff543f5e5cffa098714e0de7 (diff) |
Mobile: Fixed invalid touch positions
Diffstat (limited to 'src/ui/touch.c')
-rw-r--r-- | src/ui/touch.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/ui/touch.c b/src/ui/touch.c index 98dabc39..4bbabece 100644 --- a/src/ui/touch.c +++ b/src/ui/touch.c | |||
@@ -100,6 +100,7 @@ struct Impl_TouchState { | |||
100 | iArray *pinches; | 100 | iArray *pinches; |
101 | iArray *moms; | 101 | iArray *moms; |
102 | double lastMomTime; | 102 | double lastMomTime; |
103 | iInt2 currentTouchPos; /* for emulating SDL_GetMouseState() */ | ||
103 | }; | 104 | }; |
104 | 105 | ||
105 | static iTouchState *touchState_(void) { | 106 | static iTouchState *touchState_(void) { |
@@ -150,6 +151,7 @@ static void clearWidgetMomentum_TouchState_(iTouchState *d, iWidget *widget) { | |||
150 | } | 151 | } |
151 | 152 | ||
152 | static void dispatchMotion_Touch_(iFloat3 pos, int buttonState) { | 153 | static void dispatchMotion_Touch_(iFloat3 pos, int buttonState) { |
154 | touchState_()->currentTouchPos = initF3_I2(pos); | ||
153 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseMotionEvent){ | 155 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseMotionEvent){ |
154 | .type = SDL_MOUSEMOTION, | 156 | .type = SDL_MOUSEMOTION, |
155 | .timestamp = SDL_GetTicks(), | 157 | .timestamp = SDL_GetTicks(), |
@@ -162,6 +164,7 @@ static void dispatchMotion_Touch_(iFloat3 pos, int buttonState) { | |||
162 | 164 | ||
163 | static iBool dispatchClick_Touch_(const iTouch *d, int button) { | 165 | static iBool dispatchClick_Touch_(const iTouch *d, int button) { |
164 | const iFloat3 tapPos = d->pos[0]; | 166 | const iFloat3 tapPos = d->pos[0]; |
167 | touchState_()->currentTouchPos = initF3_I2(tapPos); | ||
165 | iWindow *window = get_Window(); | 168 | iWindow *window = get_Window(); |
166 | SDL_MouseButtonEvent btn = { | 169 | SDL_MouseButtonEvent btn = { |
167 | .type = SDL_MOUSEBUTTONDOWN, | 170 | .type = SDL_MOUSEBUTTONDOWN, |
@@ -186,6 +189,7 @@ static iBool dispatchClick_Touch_(const iTouch *d, int button) { | |||
186 | } | 189 | } |
187 | 190 | ||
188 | static void dispatchButtonDown_Touch_(iFloat3 pos) { | 191 | static void dispatchButtonDown_Touch_(iFloat3 pos) { |
192 | touchState_()->currentTouchPos = initF3_I2(pos); | ||
189 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseButtonEvent){ | 193 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseButtonEvent){ |
190 | .type = SDL_MOUSEBUTTONDOWN, | 194 | .type = SDL_MOUSEBUTTONDOWN, |
191 | .timestamp = SDL_GetTicks(), | 195 | .timestamp = SDL_GetTicks(), |
@@ -199,6 +203,7 @@ static void dispatchButtonDown_Touch_(iFloat3 pos) { | |||
199 | } | 203 | } |
200 | 204 | ||
201 | static void dispatchButtonUp_Touch_(iFloat3 pos) { | 205 | static void dispatchButtonUp_Touch_(iFloat3 pos) { |
206 | touchState_()->currentTouchPos = initF3_I2(pos); | ||
202 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseButtonEvent){ | 207 | dispatchEvent_Widget(get_Window()->root, (SDL_Event *) &(SDL_MouseButtonEvent){ |
203 | .type = SDL_MOUSEBUTTONUP, | 208 | .type = SDL_MOUSEBUTTONUP, |
204 | .timestamp = SDL_GetTicks(), | 209 | .timestamp = SDL_GetTicks(), |
@@ -694,6 +699,10 @@ void widgetDestroyed_Touch(iWidget *widget) { | |||
694 | } | 699 | } |
695 | } | 700 | } |
696 | 701 | ||
702 | iInt2 latestPosition_Touch(void) { | ||
703 | return touchState_()->currentTouchPos; | ||
704 | } | ||
705 | |||
697 | size_t numFingers_Touch(void) { | 706 | size_t numFingers_Touch(void) { |
698 | return size_Array(touchState_()->touches); | 707 | return size_Array(touchState_()->touches); |
699 | } | 708 | } |