simple onscreen buttons
authorJavier S. Pedro <maemo@javispedro.com>
Sun, 27 Sep 2009 01:24:33 +0000 (03:24 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Sun, 27 Sep 2009 01:24:33 +0000 (03:24 +0200)
platform/config.cpp
platform/platform.h
platform/sdl.cpp
platform/sdli.cpp
platform/sdlv.cpp

index 6893698..cf01595 100644 (file)
@@ -190,6 +190,7 @@ static void loadDefaults()
        Config.scaler = 0;
        Config.hacksFile = 0;
        Config.touchscreenInput = false;
+       Config.touchscreenShow = false;
 
        Settings.JoystickEnabled = FALSE;
        Settings.SoundPlaybackRate = 22050;
@@ -361,7 +362,7 @@ static void parseArgs(poptContext optCon)
                                break;
                        case 17:
                                Config.touchscreenInput = true;
-                               // TODO  Touchscreen grid
+                               Config.touchscreenShow = true;
                                break;
                        case 18:
                                Settings.HacksEnabled = TRUE;
index 150931f..f761cab 100644 (file)
@@ -22,6 +22,8 @@ extern struct config {
        char * hacksFile;
        /** Enable touchscreen controls */
        bool touchscreenInput;
+       /** Display touchscreen controls grid */
+       bool touchscreenShow;
        /** Current scancode->joypad mapping */
        unsigned short joypad1Mapping[256];
        unsigned char action[256];
@@ -50,6 +52,7 @@ void S9xAudioOutputEnable(bool enable);
 EXTERN_C void S9xInitInputDevices();
 void S9xDeinitInputDevices();
 void S9xInputScreenChanged();
+void S9xInputScreenDraw(int pixelSize, void * buffer, int pitch);
 
 // Input actions
 #define kActionNone                                            0
index 375519f..5d19d67 100644 (file)
@@ -267,7 +267,6 @@ void S9xDoAction(unsigned char action)
 
        if (action & kActionToggleFullscreen) {
                S9xVideoToggleFullscreen();
-               S9xInputScreenChanged();
        }
 
        if (action & kActionQuickLoad1) {
index 01cf4cd..7fdf2b8 100644 (file)
@@ -235,3 +235,47 @@ void S9xInputScreenChanged()
        }
 }
 
+template <typename T>
+static void drawControls(T * buffer, const int pitch)
+{
+       unsigned int i = 0;
+       int x, y;
+       T* temp;
+
+       for (i = 0; i < sizeof(touchbuttons)/sizeof(TouchButton); i++) {
+               temp = buffer + touchbuttons[i].y * pitch + touchbuttons[i].x;
+               for (x = touchbuttons[i].x; x < touchbuttons[i].x2; x++) {
+                       *temp = -1UL; // Black
+                       temp++;
+               }
+               temp = buffer + touchbuttons[i].y2 * pitch + touchbuttons[i].x;
+               for (x = touchbuttons[i].x; x < touchbuttons[i].x2; x++) {
+                       *temp = -1UL; // Black
+                       temp++;
+               }
+               temp = buffer + touchbuttons[i].y * pitch + touchbuttons[i].x;
+               for (y = touchbuttons[i].y; y < touchbuttons[i].y2; y++) {
+                       *temp = -1UL; // Black
+                       temp+=pitch;
+               }
+               temp = buffer + touchbuttons[i].y * pitch + touchbuttons[i].x2;
+               for (y = touchbuttons[i].y; y < touchbuttons[i].y2; y++) {
+                       *temp = -1UL; // Black
+                       temp+=pitch;
+               }
+       }
+}
+
+void S9xInputScreenDraw(int pixelSize, 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;
+       }
+}
+
index a16ef13..f9732d2 100644 (file)
@@ -498,12 +498,25 @@ static void setupVideoSurface()
                scaler->getName());
 }
 
+static void drawOnscreenControls()
+{
+       if (Config.touchscreenInput) {
+               S9xInputScreenChanged();
+               if (Config.touchscreenShow) {
+                       S9xInputScreenDraw(Settings.SixteenBit ? 2 : 1,
+                                                               screen->pixels, screen->pitch);
+                       SDL_Flip(screen);
+               }
+       }
+}
+
 void S9xInitDisplay(int argc, const char ** argv)
 {      
        if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) 
                DIE("SDL_InitSubSystem(VIDEO): %s", SDL_GetError());
 
        setupVideoSurface();
+       drawOnscreenControls();
 }
 
 void S9xDeinitDisplay()
@@ -517,6 +530,7 @@ void S9xVideoToggleFullscreen()
        Config.fullscreen = !Config.fullscreen;
        freeVideoSurface();
        setupVideoSurface();
+       drawOnscreenControls();
 }
 
 void S9xVideoOutputFocus(bool hasFocus)