Date: Sat, 31 Aug 2002 15:42:45 +0200
authorSam Lantinga <slouken@libsdl.org>
Sun, 01 Sep 2002 00:37:24 +0000
changeset 481c96e2137f9eb
parent 480 92596bfe8446
child 482 6417071ba2e5
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
src/video/qtopia/SDL_QWin.h
src/video/qtopia/SDL_sysvideo.cc
     1.1 --- a/src/video/qtopia/SDL_QWin.cc	Sat Aug 31 21:00:28 2002 +0000
     1.2 +++ b/src/video/qtopia/SDL_QWin.cc	Sun Sep 01 00:37:24 2002 +0000
     1.3 @@ -28,6 +28,9 @@
     1.4  #include "SDL_QWin.h"
     1.5  #include <qapplication.h>
     1.6  #include <qdirectpainter_qws.h>
     1.7 +
     1.8 +screenRotationT screenRotation = SDL_QT_NO_ROTATION;
     1.9 +
    1.10  SDL_QWin::SDL_QWin(const QSize& size)
    1.11    : QWidget(0, "SDL_main"), my_painter(0), my_image(0),
    1.12      my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),
    1.13 @@ -82,7 +85,10 @@
    1.14  
    1.15  void SDL_QWin::setMousePos(const QPoint &pos) {
    1.16    if(my_image->width() == height()) {
    1.17 -    my_mouse_pos = QPoint(height()-pos.y(), pos.x());
    1.18 +    if (screenRotation == SDL_QT_ROTATION_90)
    1.19 +      my_mouse_pos = QPoint(height()-pos.y(), pos.x());
    1.20 +    else if (screenRotation == SDL_QT_ROTATION_270)
    1.21 +      my_mouse_pos = QPoint(pos.y(), width()-pos.x());
    1.22    } else {
    1.23      my_mouse_pos = pos;
    1.24    }
    1.25 @@ -105,7 +111,7 @@
    1.26  }
    1.27  
    1.28  void SDL_QWin::mousePressEvent(QMouseEvent *e) {
    1.29 -  setMousePos(e->pos());
    1.30 +  mouseMoveEvent(e);
    1.31    Qt::ButtonState button = e->button();
    1.32    SDL_PrivateMouseButton(SDL_PRESSED,
    1.33  			 (button & Qt::LeftButton) ? 1 :
    1.34 @@ -198,23 +204,49 @@
    1.35        gs_fastRotateBlit_3(fb, buf, rect);
    1.36      } else {
    1.37        // landscape mode
    1.38 -      uchar *fb = (uchar*)my_painter->frameBuffer();
    1.39 -      uchar *buf = (uchar*)my_image->bits();
    1.40 -      if(rect == my_image->rect()) {
    1.41 -	memcpy(fb, buf, width()*height()*2);
    1.42 -      } else {
    1.43 -	int h = rect.height();
    1.44 -	int wd = rect.width()<<1;
    1.45 -	int fblineadd = my_painter->lineStep();
    1.46 -	int buflineadd = my_image->bytesPerLine();
    1.47 -	fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
    1.48 -	buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
    1.49 -	while(h--) {
    1.50 -	  memcpy(fb, buf, wd);
    1.51 -	  fb += fblineadd;
    1.52 -	  buf += buflineadd;
    1.53 -	}
    1.54 +      if (screenRotation == SDL_QT_ROTATION_90) {
    1.55 +        uchar *fb = (uchar*)my_painter->frameBuffer();
    1.56 +        uchar *buf = (uchar*)my_image->bits();
    1.57 +        if(rect == my_image->rect()) {
    1.58 +          memcpy(fb, buf, width()*height()*2);
    1.59 +        } else {
    1.60 +          int h = rect.height();
    1.61 +          int wd = rect.width()<<1;
    1.62 +          int fblineadd = my_painter->lineStep();
    1.63 +          int buflineadd = my_image->bytesPerLine();
    1.64 +          fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
    1.65 +          buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
    1.66 +          while(h--) {
    1.67 +            memcpy(fb, buf, wd);
    1.68 +            fb += fblineadd;
    1.69 +            buf += buflineadd;
    1.70 +          }
    1.71 +        }
    1.72        }
    1.73 +      else if (screenRotation == SDL_QT_ROTATION_270) {
    1.74 +        int h = rect.height();
    1.75 +        int wd = rect.width();
    1.76 +        int fblineadd = my_painter->lineStep() - (rect.width() << 1);
    1.77 +        int buflineadd = my_image->bytesPerLine() - (rect.width() << 1);
    1.78 +        int w;
    1.79 +
    1.80 +        uchar *fb = (uchar*)my_painter->frameBuffer();
    1.81 +        uchar *buf = (uchar*)my_image->bits();
    1.82 +        
    1.83 +        fb += ((my_painter->width() - (rect.top() + rect.height())) * 
    1.84 +            my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + 
    1.85 +                                                                 rect.width()))) << 1);
    1.86 +
    1.87 +        buf += my_image->bytesPerLine() * (rect.top() + rect.height()) -
    1.88 +            (((my_image->width() - (rect.left() + rect.width())) << 1) + 2);
    1.89 +
    1.90 +        while(h--) {
    1.91 +          w = wd;
    1.92 +          while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--;
    1.93 +          fb += fblineadd;
    1.94 +          buf -= buflineadd;
    1.95 +          }
    1.96 +        }
    1.97      }
    1.98    } else {
    1.99  #endif
   1.100 @@ -259,10 +291,27 @@
   1.101      case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break;
   1.102      case Qt::Key_Home: scancode = SDLK_HOME; break;
   1.103      case Qt::Key_End: scancode = SDLK_END; break;
   1.104 -    case Qt::Key_Left: scancode = SDLK_LEFT; break;
   1.105 -    case Qt::Key_Up: scancode = SDLK_UP; break;
   1.106 -    case Qt::Key_Right: scancode = SDLK_RIGHT; break;
   1.107 -    case Qt::Key_Down: scancode = SDLK_DOWN; break;
   1.108 +    // We want the control keys to rotate with the screen
   1.109 +    case Qt::Key_Left: 
   1.110 +        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP;
   1.111 +        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN;
   1.112 +        else scancode = SDLK_LEFT;
   1.113 +        break;
   1.114 +    case Qt::Key_Up: 
   1.115 +        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT;
   1.116 +        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT;
   1.117 +        else scancode = SDLK_UP;
   1.118 +        break;
   1.119 +    case Qt::Key_Right: 
   1.120 +        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN;
   1.121 +        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP;
   1.122 +        else scancode = SDLK_RIGHT;
   1.123 +        break;
   1.124 +    case Qt::Key_Down:
   1.125 +        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT;
   1.126 +        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT;
   1.127 +        else scancode = SDLK_DOWN;
   1.128 +        break;
   1.129      case Qt::Key_Prior: scancode = SDLK_PAGEUP; break;
   1.130      case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break;
   1.131      case Qt::Key_Shift: scancode = SDLK_LSHIFT; break;
     2.1 --- a/src/video/qtopia/SDL_QWin.h	Sat Aug 31 21:00:28 2002 +0000
     2.2 +++ b/src/video/qtopia/SDL_QWin.h	Sun Sep 01 00:37:24 2002 +0000
     2.3 @@ -41,6 +41,14 @@
     2.4  #include "SDL_events_c.h"
     2.5  };
     2.6  
     2.7 +typedef enum { 
     2.8 +    SDL_QT_NO_ROTATION = 0, 
     2.9 +    SDL_QT_ROTATION_90, 
    2.10 +    SDL_QT_ROTATION_270 
    2.11 +} screenRotationT;
    2.12 +
    2.13 +extern screenRotationT screenRotation;
    2.14 +
    2.15  class SDL_QWin : public QWidget
    2.16  {
    2.17    void QueueKey(QKeyEvent *e, int pressed);
     3.1 --- a/src/video/qtopia/SDL_sysvideo.cc	Sat Aug 31 21:00:28 2002 +0000
     3.2 +++ b/src/video/qtopia/SDL_sysvideo.cc	Sun Sep 01 00:37:24 2002 +0000
     3.3 @@ -53,6 +53,12 @@
     3.4    //#define QTOPIA_DEBUG
     3.5  #define QT_HIDDEN_SIZE	32	/* starting hidden window size */
     3.6  
     3.7 +/* Name of the environment variable used to invert the screen rotation or not:
     3.8 +   Possible values:
     3.9 +   !=0 : Screen is 270 rotated
    3.10 +   0: Screen is 90 rotated*/
    3.11 +#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION"
    3.12 +
    3.13    /* Initialization/Query functions */
    3.14    static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat);
    3.15    static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
    3.16 @@ -277,12 +283,15 @@
    3.17      
    3.18      current->flags = SDL_FULLSCREEN; // We always run fullscreen.
    3.19  
    3.20 -    if(width <= desktop_size.width() && height <= desktop_size.height()) {
    3.21 +    if(width <= desktop_size.width()
    3.22 +	      && height <= desktop_size.height()) {
    3.23        current->w = desktop_size.width();
    3.24        current->h = desktop_size.height();
    3.25 -    } else if(width <= desktop_size.height()
    3.26 -	      && height <= desktop_size.width()) {
    3.27 +    } else if(width <= desktop_size.height() && height <= desktop_size.width()) {
    3.28        // Landscape mode
    3.29 +      char * envString = getenv(SDL_QT_ROTATION_ENV_NAME);
    3.30 +      int envValue = envString ? atoi(envString) : 0;
    3.31 +      screenRotation = envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90;
    3.32        current->h = desktop_size.width();
    3.33        current->w = desktop_size.height();
    3.34      } else {