From c49972edb772b17d44ad995f400a4aa8c753af02 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 1 Sep 2002 00:37:24 +0000 Subject: [PATCH] Date: Sat, 31 Aug 2002 15:42:45 +0200 From: Alexandre Courbot Subject: [SDL] Qtopia port fixes/improvments -Whenever the screen is rotated, the pad is rotated as well, -Fixed a mouse bug: when tapping on the screen, the click event was often sent at the previous position of the stylus (resulting in strange behavior in Scummvm for instance) -Added the SDL_QT_INVERT_ROTATION environment variable which, when set, rotates the screen (and the mouse, and the pad) the other way. This can be useful for left-handed people. --- src/video/qtopia/SDL_QWin.cc | 93 ++++++++++++++++++++++++-------- src/video/qtopia/SDL_QWin.h | 8 +++ src/video/qtopia/SDL_sysvideo.cc | 15 ++++-- 3 files changed, 91 insertions(+), 25 deletions(-) diff --git a/src/video/qtopia/SDL_QWin.cc b/src/video/qtopia/SDL_QWin.cc index adf3b5cdb..a67fb5eee 100644 --- a/src/video/qtopia/SDL_QWin.cc +++ b/src/video/qtopia/SDL_QWin.cc @@ -28,6 +28,9 @@ static char rcsid = #include "SDL_QWin.h" #include #include + +screenRotationT screenRotation = SDL_QT_NO_ROTATION; + SDL_QWin::SDL_QWin(const QSize& size) : QWidget(0, "SDL_main"), my_painter(0), my_image(0), my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0), @@ -82,7 +85,10 @@ void SDL_QWin::closeEvent(QCloseEvent *e) { void SDL_QWin::setMousePos(const QPoint &pos) { if(my_image->width() == height()) { - my_mouse_pos = QPoint(height()-pos.y(), pos.x()); + if (screenRotation == SDL_QT_ROTATION_90) + my_mouse_pos = QPoint(height()-pos.y(), pos.x()); + else if (screenRotation == SDL_QT_ROTATION_270) + my_mouse_pos = QPoint(pos.y(), width()-pos.x()); } else { my_mouse_pos = pos; } @@ -105,7 +111,7 @@ void SDL_QWin::mouseMoveEvent(QMouseEvent *e) { } void SDL_QWin::mousePressEvent(QMouseEvent *e) { - setMousePos(e->pos()); + mouseMoveEvent(e); Qt::ButtonState button = e->button(); SDL_PrivateMouseButton(SDL_PRESSED, (button & Qt::LeftButton) ? 1 : @@ -198,23 +204,49 @@ void SDL_QWin::repaintRect(const QRect& rect) { gs_fastRotateBlit_3(fb, buf, rect); } else { // landscape mode - uchar *fb = (uchar*)my_painter->frameBuffer(); - uchar *buf = (uchar*)my_image->bits(); - if(rect == my_image->rect()) { - memcpy(fb, buf, width()*height()*2); - } else { - int h = rect.height(); - int wd = rect.width()<<1; - int fblineadd = my_painter->lineStep(); - int buflineadd = my_image->bytesPerLine(); - fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); - buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); - while(h--) { - memcpy(fb, buf, wd); - fb += fblineadd; - buf += buflineadd; - } + if (screenRotation == SDL_QT_ROTATION_90) { + uchar *fb = (uchar*)my_painter->frameBuffer(); + uchar *buf = (uchar*)my_image->bits(); + if(rect == my_image->rect()) { + memcpy(fb, buf, width()*height()*2); + } else { + int h = rect.height(); + int wd = rect.width()<<1; + int fblineadd = my_painter->lineStep(); + int buflineadd = my_image->bytesPerLine(); + fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); + buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); + while(h--) { + memcpy(fb, buf, wd); + fb += fblineadd; + buf += buflineadd; + } + } } + else if (screenRotation == SDL_QT_ROTATION_270) { + int h = rect.height(); + int wd = rect.width(); + int fblineadd = my_painter->lineStep() - (rect.width() << 1); + int buflineadd = my_image->bytesPerLine() - (rect.width() << 1); + int w; + + uchar *fb = (uchar*)my_painter->frameBuffer(); + uchar *buf = (uchar*)my_image->bits(); + + fb += ((my_painter->width() - (rect.top() + rect.height())) * + my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + + rect.width()))) << 1); + + buf += my_image->bytesPerLine() * (rect.top() + rect.height()) - + (((my_image->width() - (rect.left() + rect.width())) << 1) + 2); + + while(h--) { + w = wd; + while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--; + fb += fblineadd; + buf -= buflineadd; + } + } } } else { #endif @@ -259,10 +291,27 @@ void SDL_QWin::QueueKey(QKeyEvent *e, int pressed) case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break; case Qt::Key_Home: scancode = SDLK_HOME; break; case Qt::Key_End: scancode = SDLK_END; break; - case Qt::Key_Left: scancode = SDLK_LEFT; break; - case Qt::Key_Up: scancode = SDLK_UP; break; - case Qt::Key_Right: scancode = SDLK_RIGHT; break; - case Qt::Key_Down: scancode = SDLK_DOWN; break; + // We want the control keys to rotate with the screen + case Qt::Key_Left: + if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP; + else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN; + else scancode = SDLK_LEFT; + break; + case Qt::Key_Up: + if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT; + else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT; + else scancode = SDLK_UP; + break; + case Qt::Key_Right: + if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN; + else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP; + else scancode = SDLK_RIGHT; + break; + case Qt::Key_Down: + if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT; + else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT; + else scancode = SDLK_DOWN; + break; case Qt::Key_Prior: scancode = SDLK_PAGEUP; break; case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break; case Qt::Key_Shift: scancode = SDLK_LSHIFT; break; diff --git a/src/video/qtopia/SDL_QWin.h b/src/video/qtopia/SDL_QWin.h index 97c49389f..d5f3f8ddb 100644 --- a/src/video/qtopia/SDL_QWin.h +++ b/src/video/qtopia/SDL_QWin.h @@ -41,6 +41,14 @@ extern "C" { #include "SDL_events_c.h" }; +typedef enum { + SDL_QT_NO_ROTATION = 0, + SDL_QT_ROTATION_90, + SDL_QT_ROTATION_270 +} screenRotationT; + +extern screenRotationT screenRotation; + class SDL_QWin : public QWidget { void QueueKey(QKeyEvent *e, int pressed); diff --git a/src/video/qtopia/SDL_sysvideo.cc b/src/video/qtopia/SDL_sysvideo.cc index 1d0ad6416..85274320a 100644 --- a/src/video/qtopia/SDL_sysvideo.cc +++ b/src/video/qtopia/SDL_sysvideo.cc @@ -53,6 +53,12 @@ extern "C" { //#define QTOPIA_DEBUG #define QT_HIDDEN_SIZE 32 /* starting hidden window size */ +/* Name of the environment variable used to invert the screen rotation or not: + Possible values: + !=0 : Screen is 270° rotated + 0: Screen is 90° rotated*/ +#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION" + /* Initialization/Query functions */ static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat); static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); @@ -277,12 +283,15 @@ extern "C" { current->flags = SDL_FULLSCREEN; // We always run fullscreen. - if(width <= desktop_size.width() && height <= desktop_size.height()) { + if(width <= desktop_size.width() + && height <= desktop_size.height()) { current->w = desktop_size.width(); current->h = desktop_size.height(); - } else if(width <= desktop_size.height() - && height <= desktop_size.width()) { + } else if(width <= desktop_size.height() && height <= desktop_size.width()) { // Landscape mode + char * envString = getenv(SDL_QT_ROTATION_ENV_NAME); + int envValue = envString ? atoi(envString) : 0; + screenRotation = envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90; current->h = desktop_size.width(); current->w = desktop_size.height(); } else {