19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_QWin.h" 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qapplication.h> 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qdirectpainter_qws.h> 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallscreenRotationT screenRotation = SDL_QT_NO_ROTATION; 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_QWin::SDL_QWin(const QSize& size) 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall : QWidget(0, "SDL_main"), my_painter(0), my_image(0), 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0), 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_has_fullscreen(false), my_locked(0) 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall setBackgroundMode(NoBackground); 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_QWin::~SDL_QWin() { 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Nothing to do yet. 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image) { 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete my_image; 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::setImage(QImage *image) { 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( my_image ) { 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete my_image; 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_image = image; 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // setFixedSize(image->size()); 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::resizeEvent(QResizeEvent *e) { 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(size() != qApp->desktop()->size()) { 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Widget is not the correct size, so do the fullscreen magic 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_has_fullscreen = false; 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall enableFullscreen(); 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_inhibit_resize) { 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_inhibit_resize = false; 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateResize(e->size().width(), e->size().height()); 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::focusInEvent(QFocusEvent *) { 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Always do it here, no matter the size. 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall enableFullscreen(); 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(true, SDL_APPINPUTFOCUS); 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::focusOutEvent(QFocusEvent *) { 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_has_fullscreen = false; 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(false, SDL_APPINPUTFOCUS); 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::closeEvent(QCloseEvent *e) { 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateQuit(); 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall e->ignore(); 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::setMousePos(const QPoint &pos) { 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image->width() == height()) { 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos = QPoint(height()-pos.y(), pos.x()); 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if (screenRotation == SDL_QT_ROTATION_270) 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos = QPoint(pos.y(), width()-pos.x()); 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos = pos; 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::mouseMoveEvent(QMouseEvent *e) { 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Qt::ButtonState button = e->button(); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int sdlstate = 0; 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (button & Qt::LeftButton)) { 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdlstate |= SDL_BUTTON_LMASK; 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (button & Qt::RightButton)) { 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdlstate |= SDL_BUTTON_RMASK; 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (button & Qt::MidButton)) { 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdlstate |= SDL_BUTTON_MMASK; 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall setMousePos(e->pos()); 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y()); 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::mousePressEvent(QMouseEvent *e) { 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouseMoveEvent(e); 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Qt::ButtonState button = e->button(); 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseButton(SDL_PRESSED, 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (button & Qt::LeftButton) ? 1 : 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ((button & Qt::RightButton) ? 2 : 3), 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos.x(), my_mouse_pos.y()); 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::mouseReleaseEvent(QMouseEvent *e) { 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall setMousePos(e->pos()); 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Qt::ButtonState button = e->button(); 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseButton(SDL_RELEASED, 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (button & Qt::LeftButton) ? 1 : 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ((button & Qt::RightButton) ? 2 : 3), 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos.x(), my_mouse_pos.y()); 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_mouse_pos = QPoint(-1, -1); 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic inline void 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallgs_fastRotateBlit_3 ( unsigned short *fb, 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned short *bits, 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const QRect& rect ) 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // FIXME: this only works correctly for 240x320 displays 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int startx, starty; 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width, height; 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall startx = rect.left() >> 1; 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall starty = rect.top() >> 1; 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width = ((rect.right() - rect.left()) >> 1) + 2; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height = ((rect.bottom() - rect.top()) >> 1) + 2; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if((startx+width) > 120) { 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width = 120 - startx; // avoid horizontal overflow 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if((starty+height) > 160) { 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height = 160 - starty; // avoid vertical overflow 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ulong *sp1, *sp2, *dp1, *dp2; 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ulong stop, sbot, dtop, dbot; 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1 = (ulong*)bits + startx + starty*240; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp2 = sp1 + 120; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 = (ulong *)fb + (159 - starty) + startx*320; 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 = dp1 + 160; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rowadd = (-320*width) - 1; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rowadd2 = 240 - width; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // transfer in cells of 2x2 pixels in words 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (int y=0; y<height; y++) { 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (int x=0; x<width; x++) { 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // read source pixels 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall stop = *sp1; 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sbot = *sp2; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // rotate pixels 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dtop = (sbot & 0xffff) + ((stop & 0xffff)<<16); 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dbot = ((sbot & 0xffff0000)>>16) + (stop & 0xffff0000); 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // write to framebuffer 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dp1 = dtop; 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dp2 = dbot; 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // update source ptrs 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1++; sp2++; 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // update dest ptrs - 2 pix at a time 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 += 320; 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 += 320; 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // adjust src ptrs - skip a row as we work in pairs 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1 += rowadd2; 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp2 += rowadd2; 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // adjust dest ptrs for rotation 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 += rowadd; 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 += rowadd; 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic inline void 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallgs_fastRotateBlit_1 ( unsigned short *fb, 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned short *bits, 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const QRect& rect ) { 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // FIXME: this only works correctly for 240x320 displays 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int startx, starty; 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width, height; 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall startx = rect.left() >> 1; 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall starty = rect.top() >> 1; 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width = ((rect.right() - rect.left()) >> 1) + 2; 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height = ((rect.bottom() - rect.top()) >> 1) + 2; 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if((startx+width) > 120) { 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall width = 120 - startx; // avoid horizontal overflow 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if((starty+height) > 160) { 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall height = 160 - starty; // avoid vertical overflow 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ulong *sp1, *sp2, *dp1, *dp2; 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ulong stop, sbot, dtop, dbot; 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += 320*239; // Move "fb" to top left corner 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1 = (ulong*)bits + startx + starty*240; 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp2 = sp1 + 120; 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 = (ulong*)fb - startx * 320 - starty; 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 = dp1 - 160; 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rowadd = (320*width) + 1; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rowadd2 = 240 - width; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // transfer in cells of 2x2 pixels in words 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (int y=0; y<height; y++) { 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (int x=0; x<width; x++) { 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // read 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall stop = *sp1; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sbot = *sp2; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // rotate 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dtop = (stop & 0xffff) + ((sbot & 0xffff)<<16); 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dbot = ((stop & 0xffff0000)>>16) + (sbot & 0xffff0000); 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // write 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dp1 = dtop; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dp2 = dbot; 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // update source ptrs 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1++; sp2++; 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // update dest ptrs - 2 pix at a time 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 -= 320; 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 -= 320; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // adjust src ptrs - skip a row as we work in pairs 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp1 += rowadd2; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sp2 += rowadd2; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // adjust dest ptrs for rotation 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp1 += rowadd; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dp2 += rowadd; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// desktop, SL-A300 etc 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallbool SDL_QWin::repaintRotation0(const QRect& rect) { 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image->width() == width()) { 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *fb = (uchar*)my_painter->frameBuffer(); 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *buf = (uchar*)my_image->bits(); 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(rect == my_image->rect()) { 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(fb, buf, width()*height()*2); 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int h = rect.height(); 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int wd = rect.width()<<1; 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fblineadd = my_painter->lineStep(); 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int buflineadd = my_image->bytesPerLine(); 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while(h--) { 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(fb, buf, wd); 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += fblineadd; 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf += buflineadd; 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return false; // FIXME: Landscape 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __i386__ 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter->fillRect( rect, QBrush( Qt::NoBrush ) ); 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return true; 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Sharp Zaurus SL-5500 etc 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallbool SDL_QWin::repaintRotation3(const QRect& rect) { 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image->width() == width()) { 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ushort *fb = (ushort*)my_painter->frameBuffer(); 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ushort *buf = (ushort*)my_image->bits(); 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gs_fastRotateBlit_3(fb, buf, rect); 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // landscape mode 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) { 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *fb = (uchar*)my_painter->frameBuffer(); 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *buf = (uchar*)my_image->bits(); 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(rect == my_image->rect()) { 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(fb, buf, width()*height()*2); 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int h = rect.height(); 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int wd = rect.width()<<1; 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fblineadd = my_painter->lineStep(); 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int buflineadd = my_image->bytesPerLine(); 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while(h--) { 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(fb, buf, wd); 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += fblineadd; 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf += buflineadd; 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if (screenRotation == SDL_QT_ROTATION_270) { 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int h = rect.height(); 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int wd = rect.width(); 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fblineadd = my_painter->lineStep() - (rect.width() << 1); 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int buflineadd = my_image->bytesPerLine() - (rect.width() << 1); 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int w; 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *fb = (uchar*)my_painter->frameBuffer(); 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uchar *buf = (uchar*)my_image->bits(); 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += ((my_painter->width() - (rect.top() + rect.height())) * 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.width()))) << 1); 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf += my_image->bytesPerLine() * (rect.top() + rect.height()) - 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (((my_image->width() - (rect.left() + rect.width())) << 1) + 2); 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while(h--) { 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall w = wd; 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--; 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fb += fblineadd; 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buf -= buflineadd; 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return true; 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// ipaq 3800... 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallbool SDL_QWin::repaintRotation1(const QRect& rect) { 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image->width() == width()) { 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ushort *fb = (ushort*)my_painter->frameBuffer(); 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ushort *buf = (ushort*)my_image->bits(); 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gs_fastRotateBlit_1(fb, buf, rect); 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return false; // FIXME: landscape mode 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return true; 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::repaintRect(const QRect& rect) { 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!my_painter || !rect.width() || !rect.height()) { 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(QPixmap::defaultDepth() == 16) { 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(my_painter->transformOrientation()) { 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 3: 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(repaintRotation3(rect)) { return; } 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 1: 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(repaintRotation1(rect)) { return; } 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 0: 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(repaintRotation0(rect)) { return; } 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter->drawImage(rect.topLeft(), *my_image, rect); 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// This paints the current buffer to the screen, when desired. 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::paintEvent(QPaintEvent *ev) { 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_image) { 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lockScreen(true); 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall repaintRect(ev->rect()); 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unlockScreen(); 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Function to translate a keyboard transition and queue the key event 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This should probably be a table although this method isn't exactly 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * slow. 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::QueueKey(QKeyEvent *e, int pressed) 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_keysym keysym; 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int scancode = e->key(); 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the keysym information */ 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(scancode >= 'A' && scancode <= 'Z') { 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Qt sends uppercase, SDL wants lowercase 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.sym = static_cast<SDLKey>(scancode + 32); 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if(scancode >= 0x1000) { 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Special keys 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(scancode) { 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Escape: scancode = SDLK_ESCAPE; break; 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Tab: scancode = SDLK_TAB; break; 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Backspace: scancode = SDLK_BACKSPACE; break; 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Return: scancode = SDLK_RETURN; break; 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Enter: scancode = SDLK_KP_ENTER; break; 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Insert: scancode = SDLK_INSERT; break; 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Delete: scancode = SDLK_DELETE; break; 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Pause: scancode = SDLK_PAUSE; break; 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Print: scancode = SDLK_PRINT; break; 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break; 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Home: scancode = SDLK_HOME; break; 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_End: scancode = SDLK_END; break; 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // We want the control keys to rotate with the screen 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Left: 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP; 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN; 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else scancode = SDLK_LEFT; 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Up: 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT; 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT; 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else scancode = SDLK_UP; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Right: 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN; 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP; 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else scancode = SDLK_RIGHT; 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Down: 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT; 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT; 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else scancode = SDLK_DOWN; 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Prior: scancode = SDLK_PAGEUP; break; 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break; 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Shift: scancode = SDLK_LSHIFT; break; 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Control: scancode = SDLK_LCTRL; break; 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Meta: scancode = SDLK_LMETA; break; 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Alt: scancode = SDLK_LALT; break; 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_CapsLock: scancode = SDLK_CAPSLOCK; break; 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_NumLock: scancode = SDLK_NUMLOCK; break; 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_ScrollLock: scancode = SDLK_SCROLLOCK; break; 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F1: scancode = SDLK_F1; break; 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F2: scancode = SDLK_F2; break; 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F3: scancode = SDLK_F3; break; 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F4: scancode = SDLK_F4; break; 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F5: scancode = SDLK_F5; break; 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F6: scancode = SDLK_F6; break; 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F7: scancode = SDLK_F7; break; 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F8: scancode = SDLK_F8; break; 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F9: scancode = SDLK_F9; break; 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F10: scancode = SDLK_F10; break; 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F11: scancode = SDLK_F11; break; 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F12: scancode = SDLK_F12; break; 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F13: scancode = SDLK_F13; break; 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F14: scancode = SDLK_F14; break; 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F15: scancode = SDLK_F15; break; 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Super_L: scancode = SDLK_LSUPER; break; 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Super_R: scancode = SDLK_RSUPER; break; 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Menu: scancode = SDLK_MENU; break; 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_Help: scancode = SDLK_HELP; break; 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case Qt::Key_F33: 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // FIXME: This is a hack to enable the OK key on 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Zaurii devices. SDLK_RETURN is a suitable key to use 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // since it often is used as such. 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // david@hedbor.org 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scancode = SDLK_RETURN; 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scancode = SDLK_UNKNOWN; 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.sym = static_cast<SDLKey>(scancode); 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.sym = static_cast<SDLKey>(scancode); 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.scancode = scancode; 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.mod = KMOD_NONE; 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ButtonState st = e->state(); 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (st & ShiftButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LSHIFT); } 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (st & ControlButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LCTRL); } 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( (st & AltButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LALT); } 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_TranslateUNICODE ) { 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall QChar qchar = e->text()[0]; 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.unicode = qchar.unicode(); 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall keysym.unicode = 0; 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* NUMLOCK and CAPSLOCK are implemented as double-presses in reality */ 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // if ( (keysym.sym == SDLK_NUMLOCK) || (keysym.sym == SDLK_CAPSLOCK) ) { 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // pressed = 1; 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // } 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Queue the key event */ 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( pressed ) { 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateKeyboard(SDL_PRESSED, &keysym); 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateKeyboard(SDL_RELEASED, &keysym); 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::setFullscreen(bool fs_on) { 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_has_fullscreen = false; 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall enableFullscreen(); 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::enableFullscreen() { 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Make sure size is correct 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!my_has_fullscreen) { 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall setFixedSize(qApp->desktop()->size()); 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // This call is needed because showFullScreen won't work 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // correctly if the widget already considers itself to be fullscreen. 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall showNormal(); 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // This is needed because showNormal() forcefully changes the window 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // style to WSTyle_TopLevel. 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall setWFlags(WStyle_Customize | WStyle_NoBorder); 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Enable fullscreen. 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall showFullScreen(); 5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_has_fullscreen = true; 5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallbool SDL_QWin::lockScreen(bool force) { 5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!my_painter) { 5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(force || (isVisible() && isActiveWindow())) { 5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter = new QDirectPainter(this); 5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return false; 5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_locked++; // Increate lock refcount 5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return true; 5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_QWin::unlockScreen() { 5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(my_locked > 0) { 5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_locked--; // decrease lock refcount; 5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!my_locked && my_painter) { 5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter->end(); 5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete my_painter; 5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall my_painter = 0; 5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 528