summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/app.c b/src/app.c
index 663fa2e8..ce0898ba 100644
--- a/src/app.c
+++ b/src/app.c
@@ -59,6 +59,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
59#include <stdarg.h> 59#include <stdarg.h>
60#include <errno.h> 60#include <errno.h>
61 61
62//#define LAGRANGE_ENABLE_MOUSE_TOUCH_EMULATION 1
63
62#if defined (iPlatformAppleDesktop) 64#if defined (iPlatformAppleDesktop)
63# include "macos.h" 65# include "macos.h"
64#endif 66#endif
@@ -1149,6 +1151,45 @@ void processEvents_App(enum iAppEventMode eventMode) {
1149 ev.wheel.x = -ev.wheel.x; 1151 ev.wheel.x = -ev.wheel.x;
1150#endif 1152#endif
1151 } 1153 }
1154#if defined (LAGRANGE_ENABLE_MOUSE_TOUCH_EMULATION)
1155 /* Convert mouse events to finger events to test the touch handling. */ {
1156 static float xPrev = 0.0f;
1157 static float yPrev = 0.0f;
1158 if (ev.type == SDL_MOUSEBUTTONDOWN || ev.type == SDL_MOUSEBUTTONUP) {
1159 const float xf = (d->window->pixelRatio * ev.button.x) / (float) d->window->size.x;
1160 const float yf = (d->window->pixelRatio * ev.button.y) / (float) d->window->size.y;
1161 ev.type = (ev.type == SDL_MOUSEBUTTONDOWN ? SDL_FINGERDOWN : SDL_FINGERUP);
1162 ev.tfinger.x = xf;
1163 ev.tfinger.y = yf;
1164 ev.tfinger.dx = xf - xPrev;
1165 ev.tfinger.dy = yf - yPrev;
1166 xPrev = xf;
1167 yPrev = yf;
1168 ev.tfinger.fingerId = 0x1234;
1169 ev.tfinger.pressure = 1.0f;
1170 ev.tfinger.timestamp = SDL_GetTicks();
1171 ev.tfinger.touchId = SDL_TOUCH_MOUSEID;
1172 }
1173 else if (ev.type == SDL_MOUSEMOTION) {
1174 if (~ev.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) {
1175 continue; /* only when pressing a button */
1176 }
1177 const float xf = (d->window->pixelRatio * ev.motion.x) / (float) d->window->size.x;
1178 const float yf = (d->window->pixelRatio * ev.motion.y) / (float) d->window->size.y;
1179 ev.type = SDL_FINGERMOTION;
1180 ev.tfinger.x = xf;
1181 ev.tfinger.y = yf;
1182 ev.tfinger.dx = xf - xPrev;
1183 ev.tfinger.dy = yf - yPrev;
1184 xPrev = xf;
1185 yPrev = yf;
1186 ev.tfinger.fingerId = 0x1234;
1187 ev.tfinger.pressure = 1.0f;
1188 ev.tfinger.timestamp = SDL_GetTicks();
1189 ev.tfinger.touchId = SDL_TOUCH_MOUSEID;
1190 }
1191 }
1192#endif
1152 iBool wasUsed = processEvent_Window(d->window, &ev); 1193 iBool wasUsed = processEvent_Window(d->window, &ev);
1153 if (!wasUsed) { 1194 if (!wasUsed) {
1154 /* There may be a key bindings for this. */ 1195 /* There may be a key bindings for this. */