snes mouse support drnoksnes_0_9_5
authorJavier S. Pedro <maemo@javispedro.com>
Sat, 29 Aug 2009 01:41:45 +0000 (03:41 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Sat, 29 Aug 2009 01:41:45 +0000 (03:41 +0200)
gui/controls.c
platform/hgw.cpp
platform/platform.h
platform/sdli.cpp
platform/sdlv.cpp

index 0dedcc9..ae147b1 100644 (file)
@@ -80,12 +80,21 @@ static void show_widgets()
                case 0:
                        gtk_widget_show_all(GTK_WIDGET(none_label));
                        break;
-               case 1:
+               case 1: // Keys
                        gtk_widget_show_all(GTK_WIDGET(keys_scroll));
                        break;
-               case 2:
+               case 2: // Touchscreen
                        gtk_widget_show_all(GTK_WIDGET(ts_label));
                        break;
+               case 3: // Touchscreen + keys
+                       gtk_widget_show_all(GTK_WIDGET(keys_scroll));
+                       break;
+               case 4: // Mouse
+                       gtk_widget_show_all(GTK_WIDGET(ts_label));
+                       break;
+               case 5: // Mouse + keys
+                       gtk_widget_show_all(GTK_WIDGET(keys_scroll));
+                       break;
        }
 }
 
@@ -239,6 +248,9 @@ void controls_dialog(GtkWindow* parent)
        gtk_combo_box_append_text(combo, "No controls/Use config file");
        gtk_combo_box_append_text(combo, "Use physical keys");
        gtk_combo_box_append_text(combo, "Use touchscreen");
+       gtk_combo_box_append_text(combo, "Use touchscreen + physical keys");
+       gtk_combo_box_append_text(combo, "Use SNES mouse");
+       gtk_combo_box_append_text(combo, "Use SNES mouse + physical keys");
 
        none_label = GTK_LABEL(gtk_label_new("Check documentation for details."));
 
@@ -278,7 +290,7 @@ void controls_dialog(GtkWindow* parent)
                        -1);
        }
 
-       ts_label = GTK_LABEL(gtk_label_new("Not implemented."));
+       ts_label = GTK_LABEL(gtk_label_new("Check layout somewhere else for now."));
 
        gtk_window_resize(GTK_WINDOW(dialog), 600, 340);
        gtk_box_pack_start(GTK_BOX(dialog->vbox), GTK_WIDGET(combo),
index d1c813d..11dafd9 100644 (file)
@@ -83,11 +83,13 @@ void HgwConfig()
        if (hgw_conf_request_bool(hgw, kGConfTransparency, &transparency) == HGW_ERR_NONE) {
                Settings.Transparency = transparency ? TRUE : FALSE;
        }
-       
+
+#if 0
        char displayFramerate = FALSE;
        if (hgw_conf_request_bool(hgw, kGConfDisplayFramerate, &displayFramerate) == HGW_ERR_NONE) {
                Settings.DisplayFrameRate = displayFramerate ? TRUE : FALSE;
        }
+#endif
 
        int speedhacks = 0;
        if (hgw_conf_request_int(hgw, kGConfFrameskip, &speedhacks) == HGW_ERR_NONE) {
@@ -123,6 +125,7 @@ void HgwConfig()
                        case 4: // Mouse
                                Settings.Mouse = TRUE;
                                Settings.ControllerOption = SNES_MOUSE_SWAPPED;
+                               createActionMappingsOnly();
                                break;
                        case 5: // Mouse + keys
                                Settings.Mouse = TRUE;
index f261bb6..2a7e805 100644 (file)
@@ -30,8 +30,13 @@ extern struct config {
 } Config;
 
 // Video
+extern struct gui {
+       /** Size of the GUI Window */
+       unsigned short Width, Height;
+       /** Size of the rendering area, relative to window. 2x if Xsp on. */
+       unsigned short RenderX, RenderY, RenderW, RenderH;
+} GUI;
 void S9xVideoToggleFullscreen();
-void S9xVideoGetWindowSize(unsigned int * w, unsigned int * h);
 void S9xVideoOutputFocus(bool hasFocus);
 
 // Audio output
index 5696f29..9cfa1f4 100644 (file)
@@ -90,13 +90,29 @@ static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
                        }
                }
        } else if (mouse.enabled) {
-               // TODO Review this
                mouse.x = x;
                mouse.y = y;
+
+               if (mouse.x < GUI.RenderX) mouse.x = 0;
+               else {
+                       mouse.x -= GUI.RenderX;
+                       if (mouse.x > GUI.RenderW) mouse.x = GUI.RenderW;
+               }
+
+               if (mouse.y < GUI.RenderY) mouse.y = 0;
+               else {
+                       mouse.y -= GUI.RenderY;
+                       if (mouse.y > GUI.RenderH) mouse.y = GUI.RenderH;
+               }
+
+#ifdef MAEMO
+               // Remember RenderH, RenderW is 2x if using Xsp.
                if (Config.xsp) {
                        mouse.x /= 2;
                        mouse.y /= 2;
                }
+#endif
+
                if (pressed > 0)
                        mouse.pressed = true;
                else if (pressed < 0)
@@ -213,8 +229,8 @@ void S9xDeinitInputDevices()
 
 void S9xInputScreenChanged()
 {
-       unsigned int i = 0, w = 0, h = 0;
-       S9xVideoGetWindowSize(&w, &h);
+       unsigned int i = 0;
+       const unsigned int w = GUI.Width, h = GUI.Height;
        for (i = 0; i < sizeof(touchbuttons)/sizeof(TouchButton); i++) {
                touchbuttons[i].x = (unsigned)round(touchbuttons[i].fx * w);
                touchbuttons[i].y = (unsigned)round(touchbuttons[i].fy * h);
index 641e92e..5cdc1aa 100644 (file)
@@ -18,6 +18,8 @@
                abort(); \
        } while (0);
 
+struct gui GUI;
+
 static SDL_Surface *screen;
 
 static SDL_Rect windowSize, screenSize;
@@ -105,10 +107,8 @@ static void freeVideoSurface()
 static void setupVideoSurface()
 {
        // Real surface area.
-       unsigned gameWidth = IMAGE_WIDTH;
-       unsigned gameHeight = IMAGE_HEIGHT;
-       // SDL Window/Surface size (bigger, so we can get mouse events there).
-       unsigned winWidth, winHeight;
+       const unsigned gameWidth = IMAGE_WIDTH;
+       const unsigned gameHeight = IMAGE_HEIGHT;
 
 #ifdef MAEMO
        if ((Config.fullscreen && !gotScreenSize) ||
@@ -121,30 +121,30 @@ static void setupVideoSurface()
                calculateScreenSize();
        }
        if (Config.fullscreen) {
-               winWidth = screenSize.w;
-               winHeight = screenSize.h;
+               GUI.Width = screenSize.w;
+               GUI.Height = screenSize.h;
        } else {
-               winWidth = windowSize.w;
-               winHeight = windowSize.h;
+               GUI.Width = windowSize.w;
+               GUI.Height = windowSize.h;
        }
        
        // So, can we enable Xsp?
-       if (gameWidth * 2 < winWidth && gameHeight * 2 < winHeight) {
+       if (gameWidth * 2 < GUI.Width && gameHeight * 2 < GUI.Height) {
                Config.xsp = true;
        } else  {
                Config.xsp = false;
                setDoubling(false); // Before switching video modes; avoids flicker.
        }
 #else
-       winWidth = gameWidth;
-       winHeight = gameHeight;
+       GUI.Width = gameWidth;
+       GUI.Height = gameHeight;
 #endif
 
        // Safeguard
-       if (gameHeight > winHeight || gameWidth > winWidth)
+       if (gameHeight > GUI.Height || gameWidth > GUI.Width)
                DIE("Video is larger than window size!");
 
-       screen = SDL_SetVideoMode(winWidth, winHeight,
+       screen = SDL_SetVideoMode(GUI.Width, GUI.Height,
                                                                Settings.SixteenBit ? 16 : 8,
                                                                SDL_SWSURFACE |
                                                                (Config.fullscreen ? SDL_FULLSCREEN : 0));
@@ -162,15 +162,14 @@ static void setupVideoSurface()
 #ifdef MAEMO
        if (Config.xsp) {
                setDoubling(true);
-               centerRectangle(renderArea, winWidth, winHeight,
+               centerRectangle(renderArea, GUI.Width, GUI.Height,
                        gameWidth * 2, gameHeight * 2);
-               renderArea.w /= 2;
-               renderArea.h /= 2;
        } else {
-               centerRectangle(renderArea, winWidth, winHeight, gameWidth, gameHeight);
+               centerRectangle(renderArea, GUI.Width, GUI.Height,
+                       gameWidth, gameHeight);
        }
 #else
-       centerRectangle(renderArea, winWidth, winHeight, gameWidth, gameHeight);
+       centerRectangle(renderArea, GUI.Width, GUI.Height, gameWidth, gameHeight);
 #endif
        
        GFX.Screen = ((uint8*) screen->pixels)
@@ -184,6 +183,19 @@ static void setupVideoSurface()
        GFX.PPL = GFX.Pitch >> 1;
        GFX.PPLx2 = GFX.Pitch;
 
+       GUI.RenderX = renderArea.x;
+       GUI.RenderY = renderArea.y;
+       GUI.RenderW = renderArea.w;
+       GUI.RenderH = renderArea.h;
+
+#ifdef MAEMO
+       if (Config.xsp) {
+               // Do not update 2x the area.
+               renderArea.w /= 2;
+               renderArea.h /= 2;
+       }
+#endif
+
        printf("Video: %dx%d (%dx%d output), %hu bits per pixel, %s %s\n",
                gameWidth, gameHeight,
                screen->w, screen->h, screen->format->BitsPerPixel,
@@ -219,17 +231,6 @@ void S9xVideoOutputFocus(bool hasFocus)
        } 
 }
 
-void S9xVideoGetWindowSize(unsigned int* w, unsigned int* h)
-{
-       if (Config.fullscreen) {
-               *w = screenSize.w;
-               *h = screenSize.h;
-       } else {
-               *w = windowSize.w;
-               *h = windowSize.h;
-       }
-}
-
 // This is here for completeness, but palette mode is useless on N8x0
 void S9xSetPalette ()
 {