From d3f227916cb941244d2b70385342e6e4751a7de9 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 11 Oct 2009 18:06:18 +0200 Subject: [PATCH] fixing some onscreen controls bugs --- platform/sdli.cpp | 56 ++++++++++++++++++++++++++++------------------------- platform/sdlv.cpp | 12 +++++++++--- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/platform/sdli.cpp b/platform/sdli.cpp index db032fe..8b83934 100644 --- a/platform/sdli.cpp +++ b/platform/sdli.cpp @@ -9,26 +9,31 @@ struct TouchButton { unsigned short mask; unsigned short x, y; unsigned short x2, y2; - float fx, fy; - float fw, fh; + double fx, fy; + double fw, fh; }; #define TOUCH_BUTTON_INITIALIZER(name, x, y, w, h) \ {SNES_##name##_MASK, 0, 0, 0, 0, x, y, w, h} +#define kCornerButtonWidth (0.375) +#define kCornerButtonHeight (0.0833333333334) +#define kBigButtonWidth (0.125) +#define kBigButtonHeight (0.2777777777778) + static TouchButton touchbuttons[] = { - TOUCH_BUTTON_INITIALIZER(TL, 0, 0, 0.375, 0.0833), - TOUCH_BUTTON_INITIALIZER(TR, 0.625, 0, 0.375, 0.0833), - TOUCH_BUTTON_INITIALIZER(UP, 0.125, 0.0833, 0.125, 0.2777), //2 - TOUCH_BUTTON_INITIALIZER(LEFT, 0.0, 0.3611, 0.125, 0.2777), //3 - TOUCH_BUTTON_INITIALIZER(RIGHT, 0.25, 0.3611, 0.125, 0.2777), //4 - TOUCH_BUTTON_INITIALIZER(DOWN, 0.125, 0.6388, 0.125, 0.2777), //5 - TOUCH_BUTTON_INITIALIZER(START, 0, 0.9166, 0.375, 0.0833), - TOUCH_BUTTON_INITIALIZER(Y, 0.75, 0.0833, 0.125, 0.2777), - TOUCH_BUTTON_INITIALIZER(X, 0.625, 0.3611, 0.125, 0.2777), - TOUCH_BUTTON_INITIALIZER(A, 0.875, 0.3611, 0.125, 0.2777), - TOUCH_BUTTON_INITIALIZER(B, 0.75, 0.6388, 0.125, 0.2777), - TOUCH_BUTTON_INITIALIZER(SELECT, 0.625, 0.9166, 0.375, 0.0833), + TOUCH_BUTTON_INITIALIZER(TL, 0.0, 0.0, kCornerButtonWidth, kCornerButtonHeight), + TOUCH_BUTTON_INITIALIZER(TR, 0.625, 0.0, kCornerButtonWidth, kCornerButtonHeight), + TOUCH_BUTTON_INITIALIZER(UP, kBigButtonWidth, kCornerButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(LEFT, 0.0, kCornerButtonHeight + kBigButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(RIGHT, 2.0 * kBigButtonWidth, kCornerButtonHeight + kBigButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(DOWN, kBigButtonWidth, 1.0 - (kCornerButtonHeight + kBigButtonHeight), kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(SELECT, 0.0, 1.0 - kCornerButtonHeight, kCornerButtonWidth, kCornerButtonHeight), + TOUCH_BUTTON_INITIALIZER(X, 1.0 - 2.0 * kBigButtonWidth, kCornerButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(Y, 1.0 - 3.0 * kBigButtonWidth, kCornerButtonHeight + kBigButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(A, 1.0 - kBigButtonWidth, kCornerButtonHeight + kBigButtonHeight, kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(B, 1.0 - 2.0 * kBigButtonWidth, 1.0 - (kCornerButtonHeight + kBigButtonHeight), kBigButtonWidth, kBigButtonHeight), + TOUCH_BUTTON_INITIALIZER(START, 1.0 - kCornerButtonWidth, 1.0 - kCornerButtonHeight, kCornerButtonWidth, kCornerButtonHeight), }; static TouchButton* current = 0; @@ -44,8 +49,8 @@ static TouchButton* getButtonFor(unsigned int x, unsigned int y) { unsigned int i; for (i = 0; i < sizeof(touchbuttons)/sizeof(TouchButton); i++) { - if (x > touchbuttons[i].x && x < touchbuttons[i].x2 && - y > touchbuttons[i].y && y < touchbuttons[i].y2) { + if (x >= touchbuttons[i].x && x < touchbuttons[i].x2 && + y >= touchbuttons[i].y && y < touchbuttons[i].y2) { return &touchbuttons[i]; } @@ -179,8 +184,7 @@ void S9xProcessEvents(bool8_32 block) SDL_WaitEvent(&event); processEvent(event); } else { - while(SDL_PollEvent(&event)) - { + while(SDL_PollEvent(&event)) { processEvent(event); } } @@ -228,10 +232,10 @@ void S9xInputScreenChanged() 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); - touchbuttons[i].x2 = (unsigned)round(touchbuttons[i].x + touchbuttons[i].fw * w); - touchbuttons[i].y2 = (unsigned)round(touchbuttons[i].y + touchbuttons[i].fh * h); + touchbuttons[i].x = (unsigned int)(touchbuttons[i].fx * w); + touchbuttons[i].y = (unsigned int)(touchbuttons[i].fy * h); + touchbuttons[i].x2 = (unsigned int)(touchbuttons[i].x + touchbuttons[i].fw * w); + touchbuttons[i].y2 = (unsigned int)(touchbuttons[i].y + touchbuttons[i].fh * h); } } @@ -246,22 +250,22 @@ static void drawControls(T * buffer, const int pitch) 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 = black; // Black + *temp = black; temp++; } temp = buffer + touchbuttons[i].y2 * pitch + touchbuttons[i].x; for (x = touchbuttons[i].x; x < touchbuttons[i].x2; x++) { - *temp = black; // Black + *temp = black; temp++; } temp = buffer + touchbuttons[i].y * pitch + touchbuttons[i].x; for (y = touchbuttons[i].y; y < touchbuttons[i].y2; y++) { - *temp = black; // Black + *temp = black; temp+=pitch; } temp = buffer + touchbuttons[i].y * pitch + touchbuttons[i].x2; for (y = touchbuttons[i].y; y < touchbuttons[i].y2; y++) { - *temp = black; // Black + *temp = black; temp+=pitch; } } diff --git a/platform/sdlv.cpp b/platform/sdlv.cpp index 586e828..e45a804 100644 --- a/platform/sdlv.cpp +++ b/platform/sdlv.cpp @@ -532,15 +532,20 @@ static const ScalerFactory* searchForScaler(int bpp, int w, int h) // Found the scaler selected by the user, and we can use it. return scalers[i]; } else { - fprintf(stderr, "Selected scaler '%s' cannot be enabled\n", + fprintf(stderr, + "Selected scaler '%s' cannot be enabled in this mode\n", Config.scaler); + break; // Fallback to another scaler. } } } - fprintf(stderr, "Selected scaler '%s' does not exist\n", Config.scaler); + if (i == n) { + fprintf(stderr, "Selected scaler '%s' does not exist\n", + Config.scaler); + } } - // Just try them all now, in a set priority. + // Just try them all now, in a buildtime set priority. for (i = 0; i < n; i++) { if (scalers[i]->canEnable(bpp, w, h)) { return scalers[i]; @@ -683,6 +688,7 @@ static void drawOnscreenControls() S9xInputScreenChanged(); if (Config.touchscreenShow) { scaler->pause(); + SDL_FillRect(screen, NULL, 0); S9xInputScreenDraw(Settings.SixteenBit ? 2 : 1, screen->pixels, screen->pitch); SDL_Flip(screen); -- 1.7.9.5