Commit 513d7b33 authored by Sam Lantinga's avatar Sam Lantinga

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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40482
parent 9e896099
...@@ -28,6 +28,9 @@ static char rcsid = ...@@ -28,6 +28,9 @@ static char rcsid =
#include "SDL_QWin.h" #include "SDL_QWin.h"
#include <qapplication.h> #include <qapplication.h>
#include <qdirectpainter_qws.h> #include <qdirectpainter_qws.h>
screenRotationT screenRotation = SDL_QT_NO_ROTATION;
SDL_QWin::SDL_QWin(const QSize& size) SDL_QWin::SDL_QWin(const QSize& size)
: QWidget(0, "SDL_main"), my_painter(0), my_image(0), : QWidget(0, "SDL_main"), my_painter(0), my_image(0),
my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0), my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),
...@@ -82,7 +85,10 @@ void SDL_QWin::closeEvent(QCloseEvent *e) { ...@@ -82,7 +85,10 @@ void SDL_QWin::closeEvent(QCloseEvent *e) {
void SDL_QWin::setMousePos(const QPoint &pos) { void SDL_QWin::setMousePos(const QPoint &pos) {
if(my_image->width() == height()) { 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 { } else {
my_mouse_pos = pos; my_mouse_pos = pos;
} }
...@@ -105,7 +111,7 @@ void SDL_QWin::mouseMoveEvent(QMouseEvent *e) { ...@@ -105,7 +111,7 @@ void SDL_QWin::mouseMoveEvent(QMouseEvent *e) {
} }
void SDL_QWin::mousePressEvent(QMouseEvent *e) { void SDL_QWin::mousePressEvent(QMouseEvent *e) {
setMousePos(e->pos()); mouseMoveEvent(e);
Qt::ButtonState button = e->button(); Qt::ButtonState button = e->button();
SDL_PrivateMouseButton(SDL_PRESSED, SDL_PrivateMouseButton(SDL_PRESSED,
(button & Qt::LeftButton) ? 1 : (button & Qt::LeftButton) ? 1 :
...@@ -198,23 +204,49 @@ void SDL_QWin::repaintRect(const QRect& rect) { ...@@ -198,23 +204,49 @@ void SDL_QWin::repaintRect(const QRect& rect) {
gs_fastRotateBlit_3(fb, buf, rect); gs_fastRotateBlit_3(fb, buf, rect);
} else { } else {
// landscape mode // landscape mode
uchar *fb = (uchar*)my_painter->frameBuffer(); if (screenRotation == SDL_QT_ROTATION_90) {
uchar *buf = (uchar*)my_image->bits(); uchar *fb = (uchar*)my_painter->frameBuffer();
if(rect == my_image->rect()) { uchar *buf = (uchar*)my_image->bits();
memcpy(fb, buf, width()*height()*2); if(rect == my_image->rect()) {
} else { memcpy(fb, buf, width()*height()*2);
int h = rect.height(); } else {
int wd = rect.width()<<1; int h = rect.height();
int fblineadd = my_painter->lineStep(); int wd = rect.width()<<1;
int buflineadd = my_image->bytesPerLine(); int fblineadd = my_painter->lineStep();
fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); int buflineadd = my_image->bytesPerLine();
buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); fb += (rect.left()<<1) + rect.top() * my_painter->lineStep();
while(h--) { buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
memcpy(fb, buf, wd); while(h--) {
fb += fblineadd; memcpy(fb, buf, wd);
buf += buflineadd; 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 { } else {
#endif #endif
...@@ -259,10 +291,27 @@ void SDL_QWin::QueueKey(QKeyEvent *e, int pressed) ...@@ -259,10 +291,27 @@ void SDL_QWin::QueueKey(QKeyEvent *e, int pressed)
case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break; case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break;
case Qt::Key_Home: scancode = SDLK_HOME; break; case Qt::Key_Home: scancode = SDLK_HOME; break;
case Qt::Key_End: scancode = SDLK_END; break; case Qt::Key_End: scancode = SDLK_END; break;
case Qt::Key_Left: scancode = SDLK_LEFT; break; // We want the control keys to rotate with the screen
case Qt::Key_Up: scancode = SDLK_UP; break; case Qt::Key_Left:
case Qt::Key_Right: scancode = SDLK_RIGHT; break; if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP;
case Qt::Key_Down: scancode = SDLK_DOWN; break; 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_Prior: scancode = SDLK_PAGEUP; break;
case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break; case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break;
case Qt::Key_Shift: scancode = SDLK_LSHIFT; break; case Qt::Key_Shift: scancode = SDLK_LSHIFT; break;
......
...@@ -41,6 +41,14 @@ extern "C" { ...@@ -41,6 +41,14 @@ extern "C" {
#include "SDL_events_c.h" #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 class SDL_QWin : public QWidget
{ {
void QueueKey(QKeyEvent *e, int pressed); void QueueKey(QKeyEvent *e, int pressed);
......
...@@ -53,6 +53,12 @@ extern "C" { ...@@ -53,6 +53,12 @@ extern "C" {
//#define QTOPIA_DEBUG //#define QTOPIA_DEBUG
#define QT_HIDDEN_SIZE 32 /* starting hidden window size */ #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 */ /* Initialization/Query functions */
static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat); static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
...@@ -277,12 +283,15 @@ extern "C" { ...@@ -277,12 +283,15 @@ extern "C" {
current->flags = SDL_FULLSCREEN; // We always run fullscreen. 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->w = desktop_size.width();
current->h = desktop_size.height(); current->h = desktop_size.height();
} else if(width <= desktop_size.height() } else if(width <= desktop_size.height() && height <= desktop_size.width()) {
&& height <= desktop_size.width()) {
// Landscape mode // 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->h = desktop_size.width();
current->w = desktop_size.height(); current->w = desktop_size.height();
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment