comparison src/video/qtopia/SDL_QWin.cc @ 481:c96e2137f9eb

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.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 01 Sep 2002 00:37:24 +0000
parents 11c8a7684f74
children 969fbd4dcd4e
comparison
equal deleted inserted replaced
480:92596bfe8446 481:c96e2137f9eb
26 #endif 26 #endif
27 27
28 #include "SDL_QWin.h" 28 #include "SDL_QWin.h"
29 #include <qapplication.h> 29 #include <qapplication.h>
30 #include <qdirectpainter_qws.h> 30 #include <qdirectpainter_qws.h>
31
32 screenRotationT screenRotation = SDL_QT_NO_ROTATION;
33
31 SDL_QWin::SDL_QWin(const QSize& size) 34 SDL_QWin::SDL_QWin(const QSize& size)
32 : QWidget(0, "SDL_main"), my_painter(0), my_image(0), 35 : QWidget(0, "SDL_main"), my_painter(0), my_image(0),
33 my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0), 36 my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),
34 my_has_fullscreen(false), my_locked(0) 37 my_has_fullscreen(false), my_locked(0)
35 { 38 {
80 e->ignore(); 83 e->ignore();
81 } 84 }
82 85
83 void SDL_QWin::setMousePos(const QPoint &pos) { 86 void SDL_QWin::setMousePos(const QPoint &pos) {
84 if(my_image->width() == height()) { 87 if(my_image->width() == height()) {
85 my_mouse_pos = QPoint(height()-pos.y(), pos.x()); 88 if (screenRotation == SDL_QT_ROTATION_90)
89 my_mouse_pos = QPoint(height()-pos.y(), pos.x());
90 else if (screenRotation == SDL_QT_ROTATION_270)
91 my_mouse_pos = QPoint(pos.y(), width()-pos.x());
86 } else { 92 } else {
87 my_mouse_pos = pos; 93 my_mouse_pos = pos;
88 } 94 }
89 } 95 }
90 96
103 setMousePos(e->pos()); 109 setMousePos(e->pos());
104 SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y()); 110 SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y());
105 } 111 }
106 112
107 void SDL_QWin::mousePressEvent(QMouseEvent *e) { 113 void SDL_QWin::mousePressEvent(QMouseEvent *e) {
108 setMousePos(e->pos()); 114 mouseMoveEvent(e);
109 Qt::ButtonState button = e->button(); 115 Qt::ButtonState button = e->button();
110 SDL_PrivateMouseButton(SDL_PRESSED, 116 SDL_PrivateMouseButton(SDL_PRESSED,
111 (button & Qt::LeftButton) ? 1 : 117 (button & Qt::LeftButton) ? 1 :
112 ((button & Qt::RightButton) ? 2 : 3), 118 ((button & Qt::RightButton) ? 2 : 3),
113 my_mouse_pos.x(), my_mouse_pos.y()); 119 my_mouse_pos.x(), my_mouse_pos.y());
196 ushort *fb = (ushort*)my_painter->frameBuffer(); 202 ushort *fb = (ushort*)my_painter->frameBuffer();
197 ushort *buf = (ushort*)my_image->bits(); 203 ushort *buf = (ushort*)my_image->bits();
198 gs_fastRotateBlit_3(fb, buf, rect); 204 gs_fastRotateBlit_3(fb, buf, rect);
199 } else { 205 } else {
200 // landscape mode 206 // landscape mode
201 uchar *fb = (uchar*)my_painter->frameBuffer(); 207 if (screenRotation == SDL_QT_ROTATION_90) {
202 uchar *buf = (uchar*)my_image->bits(); 208 uchar *fb = (uchar*)my_painter->frameBuffer();
203 if(rect == my_image->rect()) { 209 uchar *buf = (uchar*)my_image->bits();
204 memcpy(fb, buf, width()*height()*2); 210 if(rect == my_image->rect()) {
205 } else { 211 memcpy(fb, buf, width()*height()*2);
206 int h = rect.height(); 212 } else {
207 int wd = rect.width()<<1; 213 int h = rect.height();
208 int fblineadd = my_painter->lineStep(); 214 int wd = rect.width()<<1;
209 int buflineadd = my_image->bytesPerLine(); 215 int fblineadd = my_painter->lineStep();
210 fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); 216 int buflineadd = my_image->bytesPerLine();
211 buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); 217 fb += (rect.left()<<1) + rect.top() * my_painter->lineStep();
212 while(h--) { 218 buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
213 memcpy(fb, buf, wd); 219 while(h--) {
214 fb += fblineadd; 220 memcpy(fb, buf, wd);
215 buf += buflineadd; 221 fb += fblineadd;
216 } 222 buf += buflineadd;
223 }
224 }
217 } 225 }
226 else if (screenRotation == SDL_QT_ROTATION_270) {
227 int h = rect.height();
228 int wd = rect.width();
229 int fblineadd = my_painter->lineStep() - (rect.width() << 1);
230 int buflineadd = my_image->bytesPerLine() - (rect.width() << 1);
231 int w;
232
233 uchar *fb = (uchar*)my_painter->frameBuffer();
234 uchar *buf = (uchar*)my_image->bits();
235
236 fb += ((my_painter->width() - (rect.top() + rect.height())) *
237 my_painter->lineStep()) + ((my_painter->height() - ((rect.left() +
238 rect.width()))) << 1);
239
240 buf += my_image->bytesPerLine() * (rect.top() + rect.height()) -
241 (((my_image->width() - (rect.left() + rect.width())) << 1) + 2);
242
243 while(h--) {
244 w = wd;
245 while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--;
246 fb += fblineadd;
247 buf -= buflineadd;
248 }
249 }
218 } 250 }
219 } else { 251 } else {
220 #endif 252 #endif
221 QPainter pp(this); 253 QPainter pp(this);
222 pp.drawImage(rect.topLeft(), *my_image, rect); 254 pp.drawImage(rect.topLeft(), *my_image, rect);
257 case Qt::Key_Pause: scancode = SDLK_PAUSE; break; 289 case Qt::Key_Pause: scancode = SDLK_PAUSE; break;
258 case Qt::Key_Print: scancode = SDLK_PRINT; break; 290 case Qt::Key_Print: scancode = SDLK_PRINT; break;
259 case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break; 291 case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break;
260 case Qt::Key_Home: scancode = SDLK_HOME; break; 292 case Qt::Key_Home: scancode = SDLK_HOME; break;
261 case Qt::Key_End: scancode = SDLK_END; break; 293 case Qt::Key_End: scancode = SDLK_END; break;
262 case Qt::Key_Left: scancode = SDLK_LEFT; break; 294 // We want the control keys to rotate with the screen
263 case Qt::Key_Up: scancode = SDLK_UP; break; 295 case Qt::Key_Left:
264 case Qt::Key_Right: scancode = SDLK_RIGHT; break; 296 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP;
265 case Qt::Key_Down: scancode = SDLK_DOWN; break; 297 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN;
298 else scancode = SDLK_LEFT;
299 break;
300 case Qt::Key_Up:
301 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT;
302 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT;
303 else scancode = SDLK_UP;
304 break;
305 case Qt::Key_Right:
306 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN;
307 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP;
308 else scancode = SDLK_RIGHT;
309 break;
310 case Qt::Key_Down:
311 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT;
312 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT;
313 else scancode = SDLK_DOWN;
314 break;
266 case Qt::Key_Prior: scancode = SDLK_PAGEUP; break; 315 case Qt::Key_Prior: scancode = SDLK_PAGEUP; break;
267 case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break; 316 case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break;
268 case Qt::Key_Shift: scancode = SDLK_LSHIFT; break; 317 case Qt::Key_Shift: scancode = SDLK_LSHIFT; break;
269 case Qt::Key_Control: scancode = SDLK_LCTRL; break; 318 case Qt::Key_Control: scancode = SDLK_LCTRL; break;
270 case Qt::Key_Meta: scancode = SDLK_LMETA; break; 319 case Qt::Key_Meta: scancode = SDLK_LMETA; break;