add multitouch fixes
[drnoksnes] / platform / sdli.cpp
index 21adc45..3e0a118 100644 (file)
@@ -3,13 +3,16 @@
 
 #include "platform.h"
 #include "snes9x.h"
-#include "display.h"
 #include "sdlv.h" // Dispatching video-related events
 
 #if CONF_ZEEMOTE
 #include "zeemote.h"
 #endif
 
+#if !defined(SDL_MAXMOUSE)
+#define SDL_MAXMOUSE 1
+#endif
+
 struct TouchButton {
        unsigned short mask;
        unsigned short x, y;
@@ -47,7 +50,7 @@ static TouchButton touchbuttons[] = {
 #undef TB
 };
 
-static TouchButton* current = 0;
+static TouchButton* current[SDL_MAXMOUSE] = { 0 };
 
 static uint32 joypads[2];
 static struct {
@@ -77,7 +80,7 @@ static inline void press(TouchButton* b) {
        joypads[Config.touchscreenInput - 1] |= b->mask;
 }
 
-static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
+static void processMouse(int which, unsigned int x, unsigned int y, int pressed = 0)
 {
 #if CONF_EXIT_BUTTON
        /* no fullscreen escape button, we have to simulate one! */
@@ -89,27 +92,27 @@ static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
        if (Config.touchscreenInput) {
                if (pressed < 0) {
                        // Button up.
-                       if (current) {
+                       if (current[which]) {
                                // Leaving button
-                               unpress(current);
-                               current = 0;
+                               unpress(current[which]);
+                               current[which] = 0;
                        }
                } else {
                        // Button down, or mouse motion.
                        TouchButton* b = getButtonFor(x, y);
-                       if (current && b && current != b) {
+                       if (current[which] && b && current[which] != b) {
                                // Moving from button to button
-                               unpress(current);
-                               current = b;
-                               press(current);
-                       } else if (current && !b) {
+                               unpress(current[which]);
+                               current[which] = b;
+                               press(current[which]);
+                       } else if (current[which] && !b) {
                                // Leaving button
-                               unpress(current);
-                               current = 0;
-                       } else if (!current && b) {
+                               unpress(current[which]);
+                               current[which] = 0;
+                       } else if (!current[which] && b) {
                                // Entering button
-                               current = b;
-                               press(current);
+                               current[which] = b;
+                               press(current[which]);
                        }
                }
        } else if (mouse.enabled) {
@@ -142,6 +145,8 @@ static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
 
 static void processEvent(const SDL_Event& event)
 {
+       if (videoEventFilter(event)) return;
+
        switch (event.type) 
        {
                case SDL_KEYDOWN:
@@ -156,19 +161,15 @@ static void processEvent(const SDL_Event& event)
                        break;
                case SDL_MOUSEBUTTONUP:
                case SDL_MOUSEBUTTONDOWN:
-                       processMouse(event.button.x, event.button.y,
+                       processMouse(event.button.which, event.button.x, event.button.y,
                                        (event.button.state == SDL_PRESSED) ? 1 : - 1);
                        break;
                case SDL_MOUSEMOTION:
-                       processMouse(event.motion.x, event.motion.y);
+                       processMouse(event.button.which, event.motion.x, event.motion.y);
                        break;
                case SDL_QUIT:
                        Config.quitting = true;
                        break;
-               case SDL_ACTIVEEVENT:
-               case SDL_SYSWMEVENT:
-                       processVideoEvent(event);
-                       break;
        }
 }
 
@@ -196,22 +197,22 @@ uint32 S9xReadJoypad (int which)
        @param buttons The buttons return value is a bit-wise mask of the two SNES
                mouse buttons, bit 0 for button 1 (left) and bit 1 for button 2 (right).
 */
-bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons)
+bool8 S9xReadMousePosition(int which, int *x, int *y, uint32 *buttons)
 {
-       if (which1 != 0) return FALSE;
+       if (which != 0) return FALSE;
 
-       x = mouse.x;
-       y = mouse.y;
-       buttons = mouse.pressed ? 1 : 0;
+       *x = mouse.x;
+       *y = mouse.y;
+       *buttons = mouse.pressed ? 1 : 0;
 
        return TRUE;
 }
 
-bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons)
+bool8 S9xReadSuperScopePosition(int *x, int *y, uint32 *buttons)
 {
-       x = mouse.x;
-       y = mouse.y;
-       buttons = mouse.pressed ? 8 : 0;
+       *x = mouse.x;
+       *y = mouse.y;
+       *buttons = mouse.pressed ? 8 : 0;
 
        return TRUE;
 }
@@ -245,6 +246,10 @@ void S9xInitInputDevices()
        mouse.enabled = false;
        mouse.pressed = false;
 
+#if CONF_ZEEMOTE
+       ZeeInit();
+#endif
+
        if (Config.joypad1Enabled) {
                joypads[0] = 0x80000000UL;
        }
@@ -266,24 +271,20 @@ void S9xInitInputDevices()
        }
        printf("\n");
 
-#if CONF_ZEEMOTE
-       ZeeInit();
-#endif
-
-       // TODO Non-awful mouse support, Superscope
+       // TODO Non-awful mouse & superscope support
 
        S9xInputScreenChanged();
 }
 
 void S9xDeinitInputDevices()
 {
+#if CONF_ZEEMOTE
+       ZeeQuit();
+#endif
        joypads[0] = 0;
        joypads[1] = 0;
        mouse.enabled = false;
        mouse.pressed = false;
-#if CONF_ZEEMOTE
-       ZeeQuit();
-#endif
 }
 
 void S9xInputScreenChanged()
@@ -330,16 +331,8 @@ static void drawControls(T * buffer, const int pitch)
        }
 }
 
-void S9xInputScreenDraw(int pixelSize, void * buffer, int pitch)
+void S9xInputScreenDraw(void * buffer, int pitch)
 {
-       switch (pixelSize)
-       {
-               case 1:
-                       drawControls(reinterpret_cast<uint8*>(buffer), pitch);
-                       break;
-               case 2:
-                       drawControls(reinterpret_cast<uint16*>(buffer), pitch / 2);
-                       break;
-       }
+       drawControls(reinterpret_cast<uint16*>(buffer), pitch / 2);
 }