comparison src/video/qtopia/SDL_QWin.cc @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 376665398b25
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
25 #include <qapplication.h> 25 #include <qapplication.h>
26 #include <qdirectpainter_qws.h> 26 #include <qdirectpainter_qws.h>
27 27
28 screenRotationT screenRotation = SDL_QT_NO_ROTATION; 28 screenRotationT screenRotation = SDL_QT_NO_ROTATION;
29 29
30 SDL_QWin::SDL_QWin(const QSize& size) 30 SDL_QWin::SDL_QWin(const QSize & size):
31 : QWidget(0, "SDL_main"), my_painter(0), my_image(0), 31 QWidget(0, "SDL_main"),
32 my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0), 32 my_painter(0),
33 my_has_fullscreen(false), my_locked(0) 33 my_image(0),
34 { 34 my_inhibit_resize(false),
35 setBackgroundMode(NoBackground); 35 my_mouse_pos(-1, -1),
36 } 36 my_flags(0),
37 37 my_has_fullscreen(false),
38 SDL_QWin::~SDL_QWin() { 38 my_locked(0)
39 // Nothing to do yet. 39 {
40 if(my_image) { 40 setBackgroundMode(NoBackground);
41 delete my_image; 41 }
42 } 42
43 } 43 SDL_QWin::~SDL_QWin()
44 44 {
45 void SDL_QWin::setImage(QImage *image) { 45 // Nothing to do yet.
46 if ( my_image ) { 46 if (my_image) {
47 delete my_image; 47 delete my_image;
48 } 48 }
49 my_image = image; 49 }
50 // setFixedSize(image->size()); 50
51 } 51 void
52 52 SDL_QWin::setImage(QImage * image)
53 void SDL_QWin::resizeEvent(QResizeEvent *e) { 53 {
54 if(size() != qApp->desktop()->size()) { 54 if (my_image) {
55 // Widget is not the correct size, so do the fullscreen magic 55 delete my_image;
56 }
57 my_image = image;
58 // setFixedSize(image->size());
59 }
60
61 void
62 SDL_QWin::resizeEvent(QResizeEvent * e)
63 {
64 if (size() != qApp->desktop()->size()) {
65 // Widget is not the correct size, so do the fullscreen magic
66 my_has_fullscreen = false;
67 enableFullscreen();
68 }
69 if (my_inhibit_resize) {
70 my_inhibit_resize = false;
71 } else {
72 SDL_PrivateResize(e->size().width(), e->size().height());
73 }
74 }
75
76 void
77 SDL_QWin::focusInEvent(QFocusEvent *)
78 {
79 // Always do it here, no matter the size.
80 enableFullscreen();
81 SDL_PrivateAppActive(true, SDL_APPINPUTFOCUS);
82 }
83
84 void
85 SDL_QWin::focusOutEvent(QFocusEvent *)
86 {
56 my_has_fullscreen = false; 87 my_has_fullscreen = false;
57 enableFullscreen(); 88 SDL_PrivateAppActive(false, SDL_APPINPUTFOCUS);
58 } 89 }
59 if(my_inhibit_resize) { 90
60 my_inhibit_resize = false; 91 void
61 } else { 92 SDL_QWin::closeEvent(QCloseEvent * e)
62 SDL_PrivateResize(e->size().width(), e->size().height()); 93 {
63 } 94 SDL_PrivateQuit();
64 } 95 e->ignore();
65 96 }
66 void SDL_QWin::focusInEvent(QFocusEvent *) { 97
67 // Always do it here, no matter the size. 98 void
68 enableFullscreen(); 99 SDL_QWin::setMousePos(const QPoint & pos)
69 SDL_PrivateAppActive(true, SDL_APPINPUTFOCUS); 100 {
70 } 101 if (my_image->width() == height()) {
71 102 if (screenRotation == SDL_QT_ROTATION_90)
72 void SDL_QWin::focusOutEvent(QFocusEvent *) { 103 my_mouse_pos = QPoint(height() - pos.y(), pos.x());
73 my_has_fullscreen = false; 104 else if (screenRotation == SDL_QT_ROTATION_270)
74 SDL_PrivateAppActive(false, SDL_APPINPUTFOCUS); 105 my_mouse_pos = QPoint(pos.y(), width() - pos.x());
75 } 106 } else {
76 107 my_mouse_pos = pos;
77 void SDL_QWin::closeEvent(QCloseEvent *e) { 108 }
78 SDL_PrivateQuit(); 109 }
79 e->ignore(); 110
80 } 111 void
81 112 SDL_QWin::mouseMoveEvent(QMouseEvent * e)
82 void SDL_QWin::setMousePos(const QPoint &pos) { 113 {
83 if(my_image->width() == height()) { 114 Qt::ButtonState button = e->button();
84 if (screenRotation == SDL_QT_ROTATION_90) 115 int sdlstate = 0;
85 my_mouse_pos = QPoint(height()-pos.y(), pos.x()); 116 if ((button & Qt::LeftButton)) {
86 else if (screenRotation == SDL_QT_ROTATION_270) 117 sdlstate |= SDL_BUTTON_LMASK;
87 my_mouse_pos = QPoint(pos.y(), width()-pos.x()); 118 }
88 } else { 119 if ((button & Qt::RightButton)) {
89 my_mouse_pos = pos; 120 sdlstate |= SDL_BUTTON_RMASK;
90 } 121 }
91 } 122 if ((button & Qt::MidButton)) {
92 123 sdlstate |= SDL_BUTTON_MMASK;
93 void SDL_QWin::mouseMoveEvent(QMouseEvent *e) { 124 }
94 Qt::ButtonState button = e->button(); 125 setMousePos(e->pos());
95 int sdlstate = 0; 126 SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y());
96 if( (button & Qt::LeftButton)) { 127 }
97 sdlstate |= SDL_BUTTON_LMASK; 128
98 } 129 void
99 if( (button & Qt::RightButton)) { 130 SDL_QWin::mousePressEvent(QMouseEvent * e)
100 sdlstate |= SDL_BUTTON_RMASK; 131 {
101 } 132 mouseMoveEvent(e);
102 if( (button & Qt::MidButton)) { 133 Qt::ButtonState button = e->button();
103 sdlstate |= SDL_BUTTON_MMASK; 134 SDL_PrivateMouseButton(SDL_PRESSED,
104 } 135 (button & Qt::LeftButton) ? 1 :
105 setMousePos(e->pos()); 136 ((button & Qt::RightButton) ? 2 : 3),
106 SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y()); 137 my_mouse_pos.x(), my_mouse_pos.y());
107 } 138 }
108 139
109 void SDL_QWin::mousePressEvent(QMouseEvent *e) { 140 void
110 mouseMoveEvent(e); 141 SDL_QWin::mouseReleaseEvent(QMouseEvent * e)
111 Qt::ButtonState button = e->button(); 142 {
112 SDL_PrivateMouseButton(SDL_PRESSED, 143 setMousePos(e->pos());
113 (button & Qt::LeftButton) ? 1 : 144 Qt::ButtonState button = e->button();
114 ((button & Qt::RightButton) ? 2 : 3), 145 SDL_PrivateMouseButton(SDL_RELEASED,
115 my_mouse_pos.x(), my_mouse_pos.y()); 146 (button & Qt::LeftButton) ? 1 :
116 } 147 ((button & Qt::RightButton) ? 2 : 3),
117 148 my_mouse_pos.x(), my_mouse_pos.y());
118 void SDL_QWin::mouseReleaseEvent(QMouseEvent *e) { 149 my_mouse_pos = QPoint(-1, -1);
119 setMousePos(e->pos());
120 Qt::ButtonState button = e->button();
121 SDL_PrivateMouseButton(SDL_RELEASED,
122 (button & Qt::LeftButton) ? 1 :
123 ((button & Qt::RightButton) ? 2 : 3),
124 my_mouse_pos.x(), my_mouse_pos.y());
125 my_mouse_pos = QPoint(-1, -1);
126 } 150 }
127 151
128 static inline void 152 static inline void
129 gs_fastRotateBlit_3 ( unsigned short *fb, 153 gs_fastRotateBlit_3(unsigned short *fb,
130 unsigned short *bits, 154 unsigned short *bits, const QRect & rect)
131 const QRect& rect ) 155 {
132 { 156 // FIXME: this only works correctly for 240x320 displays
133 // FIXME: this only works correctly for 240x320 displays 157 int startx, starty;
134 int startx, starty; 158 int width, height;
135 int width, height; 159
136 160 startx = rect.left() >> 1;
137 startx = rect.left() >> 1; 161 starty = rect.top() >> 1;
138 starty = rect.top() >> 1; 162 width = ((rect.right() - rect.left()) >> 1) + 2;
139 width = ((rect.right() - rect.left()) >> 1) + 2; 163 height = ((rect.bottom() - rect.top()) >> 1) + 2;
140 height = ((rect.bottom() - rect.top()) >> 1) + 2; 164
141 165 if ((startx + width) > 120) {
142 if((startx+width) > 120) { 166 width = 120 - startx; // avoid horizontal overflow
143 width = 120 - startx; // avoid horizontal overflow 167 }
144 } 168 if ((starty + height) > 160) {
145 if((starty+height) > 160) { 169 height = 160 - starty; // avoid vertical overflow
146 height = 160 - starty; // avoid vertical overflow 170 }
147 } 171
148 172 ulong *sp1, *sp2, *dp1, *dp2;
149 ulong *sp1, *sp2, *dp1, *dp2; 173 ulong stop, sbot, dtop, dbot;
150 ulong stop, sbot, dtop, dbot; 174
151 175 sp1 = (ulong *) bits + startx + starty * 240;
152 sp1 = (ulong*)bits + startx + starty*240; 176 sp2 = sp1 + 120;
153 sp2 = sp1 + 120; 177 dp1 = (ulong *) fb + (159 - starty) + startx * 320;
154 dp1 = (ulong *)fb + (159 - starty) + startx*320; 178 dp2 = dp1 + 160;
155 dp2 = dp1 + 160; 179 int rowadd = (-320 * width) - 1;
156 int rowadd = (-320*width) - 1; 180 int rowadd2 = 240 - width;
157 int rowadd2 = 240 - width; 181 // transfer in cells of 2x2 pixels in words
158 // transfer in cells of 2x2 pixels in words 182 for (int y = 0; y < height; y++) {
159 for (int y=0; y<height; y++) { 183 for (int x = 0; x < width; x++) {
160 for (int x=0; x<width; x++) { 184 // read source pixels
161 // read source pixels 185 stop = *sp1;
162 stop = *sp1; 186 sbot = *sp2;
163 sbot = *sp2; 187 // rotate pixels
164 // rotate pixels 188 dtop = (sbot & 0xffff) + ((stop & 0xffff) << 16);
165 dtop = (sbot & 0xffff) + ((stop & 0xffff)<<16); 189 dbot = ((sbot & 0xffff0000) >> 16) + (stop & 0xffff0000);
166 dbot = ((sbot & 0xffff0000)>>16) + (stop & 0xffff0000); 190 // write to framebuffer
167 // write to framebuffer 191 *dp1 = dtop;
168 *dp1 = dtop; 192 *dp2 = dbot;
169 *dp2 = dbot; 193 // update source ptrs
170 // update source ptrs 194 sp1++;
171 sp1++; sp2++; 195 sp2++;
172 // update dest ptrs - 2 pix at a time 196 // update dest ptrs - 2 pix at a time
173 dp1 += 320; 197 dp1 += 320;
174 dp2 += 320; 198 dp2 += 320;
175 } 199 }
176 // adjust src ptrs - skip a row as we work in pairs 200 // adjust src ptrs - skip a row as we work in pairs
177 sp1 += rowadd2; 201 sp1 += rowadd2;
178 sp2 += rowadd2; 202 sp2 += rowadd2;
179 // adjust dest ptrs for rotation 203 // adjust dest ptrs for rotation
180 dp1 += rowadd; 204 dp1 += rowadd;
181 dp2 += rowadd; 205 dp2 += rowadd;
182 } 206 }
183 } 207 }
184 208
185 static inline void 209 static inline void
186 gs_fastRotateBlit_1 ( unsigned short *fb, 210 gs_fastRotateBlit_1(unsigned short *fb,
187 unsigned short *bits, 211 unsigned short *bits, const QRect & rect)
188 const QRect& rect ) { 212 {
189 // FIXME: this only works correctly for 240x320 displays 213 // FIXME: this only works correctly for 240x320 displays
190 int startx, starty; 214 int startx, starty;
191 int width, height; 215 int width, height;
192 216
193 startx = rect.left() >> 1; 217 startx = rect.left() >> 1;
194 starty = rect.top() >> 1; 218 starty = rect.top() >> 1;
195 width = ((rect.right() - rect.left()) >> 1) + 2; 219 width = ((rect.right() - rect.left()) >> 1) + 2;
196 height = ((rect.bottom() - rect.top()) >> 1) + 2; 220 height = ((rect.bottom() - rect.top()) >> 1) + 2;
197 221
198 if((startx+width) > 120) { 222 if ((startx + width) > 120) {
199 width = 120 - startx; // avoid horizontal overflow 223 width = 120 - startx; // avoid horizontal overflow
200 } 224 }
201 if((starty+height) > 160) { 225 if ((starty + height) > 160) {
202 height = 160 - starty; // avoid vertical overflow 226 height = 160 - starty; // avoid vertical overflow
203 } 227 }
204 228
205 ulong *sp1, *sp2, *dp1, *dp2; 229 ulong *sp1, *sp2, *dp1, *dp2;
206 ulong stop, sbot, dtop, dbot; 230 ulong stop, sbot, dtop, dbot;
207 fb += 320*239; // Move "fb" to top left corner 231 fb += 320 * 239; // Move "fb" to top left corner
208 sp1 = (ulong*)bits + startx + starty*240; 232 sp1 = (ulong *) bits + startx + starty * 240;
209 sp2 = sp1 + 120; 233 sp2 = sp1 + 120;
210 dp1 = (ulong*)fb - startx * 320 - starty; 234 dp1 = (ulong *) fb - startx * 320 - starty;
211 dp2 = dp1 - 160; 235 dp2 = dp1 - 160;
212 int rowadd = (320*width) + 1; 236 int rowadd = (320 * width) + 1;
213 int rowadd2 = 240 - width; 237 int rowadd2 = 240 - width;
214 // transfer in cells of 2x2 pixels in words 238 // transfer in cells of 2x2 pixels in words
215 for (int y=0; y<height; y++) { 239 for (int y = 0; y < height; y++) {
216 for (int x=0; x<width; x++) { 240 for (int x = 0; x < width; x++) {
217 // read 241 // read
218 stop = *sp1; 242 stop = *sp1;
219 sbot = *sp2; 243 sbot = *sp2;
220 // rotate 244 // rotate
221 dtop = (stop & 0xffff) + ((sbot & 0xffff)<<16); 245 dtop = (stop & 0xffff) + ((sbot & 0xffff) << 16);
222 dbot = ((stop & 0xffff0000)>>16) + (sbot & 0xffff0000); 246 dbot = ((stop & 0xffff0000) >> 16) + (sbot & 0xffff0000);
223 // write 247 // write
224 *dp1 = dtop; 248 *dp1 = dtop;
225 *dp2 = dbot; 249 *dp2 = dbot;
226 // update source ptrs 250 // update source ptrs
227 sp1++; sp2++; 251 sp1++;
228 // update dest ptrs - 2 pix at a time 252 sp2++;
229 dp1 -= 320; 253 // update dest ptrs - 2 pix at a time
230 dp2 -= 320; 254 dp1 -= 320;
231 } 255 dp2 -= 320;
232 // adjust src ptrs - skip a row as we work in pairs 256 }
233 sp1 += rowadd2; 257 // adjust src ptrs - skip a row as we work in pairs
234 sp2 += rowadd2; 258 sp1 += rowadd2;
235 // adjust dest ptrs for rotation 259 sp2 += rowadd2;
236 dp1 += rowadd; 260 // adjust dest ptrs for rotation
237 dp2 += rowadd; 261 dp1 += rowadd;
238 } 262 dp2 += rowadd;
263 }
239 } 264 }
240 265
241 // desktop, SL-A300 etc 266 // desktop, SL-A300 etc
242 bool SDL_QWin::repaintRotation0(const QRect& rect) { 267 /* *INDENT-OFF* */
243 if(my_image->width() == width()) { 268 bool SDL_QWin::repaintRotation0 (const QRect & rect)
244 uchar *fb = (uchar*)my_painter->frameBuffer(); 269 {
245 uchar *buf = (uchar*)my_image->bits(); 270 if (my_image->width () == width ()) {
246 if(rect == my_image->rect()) { 271 uchar * fb = (uchar *) my_painter->frameBuffer ();
247 SDL_memcpy(fb, buf, width()*height()*2); 272 uchar * buf = (uchar *) my_image->bits ();
248 } else { 273 if (rect == my_image->rect ()) {
249 int h = rect.height(); 274 SDL_memcpy (fb, buf, width () * height () * 2);
250 int wd = rect.width()<<1; 275 } else {
251 int fblineadd = my_painter->lineStep(); 276 int h = rect.height ();
252 int buflineadd = my_image->bytesPerLine(); 277 int wd = rect.width () << 1;
253 fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); 278 int fblineadd = my_painter->lineStep ();
254 buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); 279 int buflineadd = my_image->bytesPerLine ();
255 while(h--) { 280 fb += (rect.left () << 1) + rect.top () * my_painter->lineStep ();
256 SDL_memcpy(fb, buf, wd); 281 buf += (rect.left () << 1) + rect.top () * my_image->bytesPerLine ();
257 fb += fblineadd; 282 while (h--) {
258 buf += buflineadd; 283 SDL_memcpy (fb, buf, wd);
259 } 284 fb += fblineadd;
260 } 285 buf += buflineadd;
261 } else { 286 }
262 return false; // FIXME: Landscape 287 }
263 } 288 } else {
289 return false; // FIXME: Landscape
290 }
264 #ifdef __i386__ 291 #ifdef __i386__
265 my_painter->fillRect( rect, QBrush( Qt::NoBrush ) ); 292 my_painter->fillRect (rect, QBrush (Qt::NoBrush));
266 #endif 293 #endif
267 return true; 294 return true;
268 } 295 }
269 296 /* *INDENT-ON* */
270 297
298
271 // Sharp Zaurus SL-5500 etc 299 // Sharp Zaurus SL-5500 etc
272 bool SDL_QWin::repaintRotation3(const QRect& rect) { 300 /* *INDENT-OFF* */
273 if(my_image->width() == width()) { 301 bool SDL_QWin::repaintRotation3 (const QRect & rect)
274 ushort *fb = (ushort*)my_painter->frameBuffer(); 302 {
275 ushort *buf = (ushort*)my_image->bits(); 303 if (my_image->width () == width ()) {
276 gs_fastRotateBlit_3(fb, buf, rect); 304 ushort * fb = (ushort *) my_painter->frameBuffer ();
277 } else { 305 ushort * buf = (ushort *) my_image->bits ();
278 // landscape mode 306 gs_fastRotateBlit_3 (fb, buf, rect);
279 if (screenRotation == SDL_QT_ROTATION_90) { 307 } else {
280 uchar *fb = (uchar*)my_painter->frameBuffer(); 308 // landscape mode
281 uchar *buf = (uchar*)my_image->bits(); 309 if (screenRotation == SDL_QT_ROTATION_90) {
282 if(rect == my_image->rect()) { 310 uchar * fb = (uchar *) my_painter->frameBuffer ();
283 SDL_memcpy(fb, buf, width()*height()*2); 311 uchar * buf = (uchar *) my_image->bits ();
284 } else { 312 if (rect == my_image->rect ()) {
285 int h = rect.height(); 313 SDL_memcpy (fb, buf, width () * height () * 2);
286 int wd = rect.width()<<1; 314 } else {
287 int fblineadd = my_painter->lineStep(); 315 int h = rect.height ();
288 int buflineadd = my_image->bytesPerLine(); 316 int wd = rect.width () << 1;
289 fb += (rect.left()<<1) + rect.top() * my_painter->lineStep(); 317 int fblineadd = my_painter->lineStep ();
290 buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine(); 318 int buflineadd = my_image->bytesPerLine ();
291 while(h--) { 319 fb +=
292 SDL_memcpy(fb, buf, wd); 320 (rect.left () << 1) +
293 fb += fblineadd; 321 rect.top () * my_painter->lineStep ();
294 buf += buflineadd; 322 buf +=
295 } 323 (rect.left () << 1) +
296 } 324 rect.top () * my_image->bytesPerLine ();
297 } else if (screenRotation == SDL_QT_ROTATION_270) { 325 while (h--) {
298 int h = rect.height(); 326 SDL_memcpy (fb, buf, wd);
299 int wd = rect.width(); 327 fb += fblineadd;
300 int fblineadd = my_painter->lineStep() - (rect.width() << 1); 328 buf += buflineadd;
301 int buflineadd = my_image->bytesPerLine() - (rect.width() << 1); 329 }
302 int w; 330 }
303 331 } else if (screenRotation == SDL_QT_ROTATION_270) {
304 uchar *fb = (uchar*)my_painter->frameBuffer(); 332 int h = rect.height ();
305 uchar *buf = (uchar*)my_image->bits(); 333 int wd = rect.width ();
306 334 int fblineadd = my_painter->lineStep () - (rect.width () << 1);
307 fb += ((my_painter->width() - (rect.top() + rect.height())) * 335 int buflineadd = my_image->bytesPerLine () - (rect.width () << 1);
308 my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + 336 int w;
309 rect.width()))) << 1); 337
310 338 uchar * fb = (uchar *) my_painter->frameBuffer ();
311 buf += my_image->bytesPerLine() * (rect.top() + rect.height()) - 339 uchar * buf = (uchar *) my_image->bits ();
312 (((my_image->width() - (rect.left() + rect.width())) << 1) + 2); 340
313 341 fb +=
314 while(h--) { 342 ((my_painter->width () -
315 w = wd; 343 (rect.top () +
316 while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--; 344 rect.height ())) * my_painter->lineStep ()) +
317 fb += fblineadd; 345 ((my_painter->height () -
318 buf -= buflineadd; 346 ((rect.left () + rect.width ()))) << 1);
319 } 347
320 } 348 buf +=
321 } 349 my_image->bytesPerLine () * (rect.top () +
322 return true; 350 rect.height ()) -
323 } 351 (((my_image->width () -
352 (rect.left () + rect.width ())) << 1) + 2);
353
354 while (h--) {
355 w = wd;
356 while (w--)
357 *((unsigned short *) fb)++ = *((unsigned short *) buf)--;
358 fb += fblineadd;
359 buf -= buflineadd;
360 }
361 }
362 }
363 return true;
364 }
365 /* *INDENT-ON* */
324 366
325 // ipaq 3800... 367 // ipaq 3800...
326 bool SDL_QWin::repaintRotation1(const QRect& rect) { 368 /* *INDENT-OFF* */
327 if(my_image->width() == width()) { 369 bool SDL_QWin::repaintRotation1 (const QRect & rect)
328 ushort *fb = (ushort*)my_painter->frameBuffer(); 370 {
329 ushort *buf = (ushort*)my_image->bits(); 371 if (my_image->width () == width ()) {
330 gs_fastRotateBlit_1(fb, buf, rect); 372 ushort *fb = (ushort *) my_painter->frameBuffer ();
331 } else { 373 ushort *buf = (ushort *) my_image->bits ();
332 return false; // FIXME: landscape mode 374 gs_fastRotateBlit_1 (fb, buf, rect);
333 } 375 } else {
334 return true; 376 return false; // FIXME: landscape mode
335 } 377 }
336 378 return true;
337 void SDL_QWin::repaintRect(const QRect& rect) { 379 }
338 if(!my_painter || !rect.width() || !rect.height()) { 380 /* *INDENT-ON* */
339 return; 381
340 } 382 void
341 383 SDL_QWin::repaintRect(const QRect & rect)
342 if(QPixmap::defaultDepth() == 16) { 384 {
343 switch(my_painter->transformOrientation()) { 385 if (!my_painter || !rect.width() || !rect.height()) {
344 case 3: 386 return;
345 if(repaintRotation3(rect)) { return; } 387 }
346 break; 388
347 case 1: 389 if (QPixmap::defaultDepth() == 16) {
348 if(repaintRotation1(rect)) { return; } 390 switch (my_painter->transformOrientation()) {
349 break; 391 case 3:
350 case 0: 392 if (repaintRotation3(rect)) {
351 if(repaintRotation0(rect)) { return; } 393 return;
352 break; 394 }
353 } 395 break;
354 } 396 case 1:
355 my_painter->drawImage(rect.topLeft(), *my_image, rect); 397 if (repaintRotation1(rect)) {
398 return;
399 }
400 break;
401 case 0:
402 if (repaintRotation0(rect)) {
403 return;
404 }
405 break;
406 }
407 }
408 my_painter->drawImage(rect.topLeft(), *my_image, rect);
356 } 409 }
357 410
358 // This paints the current buffer to the screen, when desired. 411 // This paints the current buffer to the screen, when desired.
359 void SDL_QWin::paintEvent(QPaintEvent *ev) { 412 void
360 if(my_image) { 413 SDL_QWin::paintEvent(QPaintEvent * ev)
361 lockScreen(true); 414 {
362 repaintRect(ev->rect()); 415 if (my_image) {
363 unlockScreen(); 416 lockScreen(true);
364 } 417 repaintRect(ev->rect());
365 } 418 unlockScreen();
419 }
420 }
366 421
367 /* Function to translate a keyboard transition and queue the key event 422 /* Function to translate a keyboard transition and queue the key event
368 * This should probably be a table although this method isn't exactly 423 * This should probably be a table although this method isn't exactly
369 * slow. 424 * slow.
370 */ 425 */
371 void SDL_QWin::QueueKey(QKeyEvent *e, int pressed) 426 void
372 { 427 SDL_QWin::QueueKey(QKeyEvent * e, int pressed)
373 SDL_keysym keysym; 428 {
374 int scancode = e->key(); 429 SDL_keysym keysym;
375 /* Set the keysym information */ 430 int scancode = e->key();
376 if(scancode >= 'A' && scancode <= 'Z') { 431 /* Set the keysym information */
377 // Qt sends uppercase, SDL wants lowercase 432 if (scancode >= 'A' && scancode <= 'Z') {
378 keysym.sym = static_cast<SDLKey>(scancode + 32); 433 // Qt sends uppercase, SDL wants lowercase
379 } else if(scancode >= 0x1000) { 434 keysym.sym = static_cast < SDLKey > (scancode + 32);
380 // Special keys 435 } else if (scancode >= 0x1000) {
381 switch(scancode) { 436 // Special keys
382 case Qt::Key_Escape: scancode = SDLK_ESCAPE; break; 437 switch (scancode) {
383 case Qt::Key_Tab: scancode = SDLK_TAB; break; 438 case Qt::Key_Escape:
384 case Qt::Key_Backspace: scancode = SDLK_BACKSPACE; break; 439 scancode = SDLK_ESCAPE;
385 case Qt::Key_Return: scancode = SDLK_RETURN; break; 440 break;
386 case Qt::Key_Enter: scancode = SDLK_KP_ENTER; break; 441 case Qt::Key_Tab:
387 case Qt::Key_Insert: scancode = SDLK_INSERT; break; 442 scancode = SDLK_TAB;
388 case Qt::Key_Delete: scancode = SDLK_DELETE; break; 443 break;
389 case Qt::Key_Pause: scancode = SDLK_PAUSE; break; 444 case Qt::Key_Backspace:
390 case Qt::Key_Print: scancode = SDLK_PRINT; break; 445 scancode = SDLK_BACKSPACE;
391 case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break; 446 break;
392 case Qt::Key_Home: scancode = SDLK_HOME; break; 447 case Qt::Key_Return:
393 case Qt::Key_End: scancode = SDLK_END; break; 448 scancode = SDLK_RETURN;
394 // We want the control keys to rotate with the screen 449 break;
395 case Qt::Key_Left: 450 case Qt::Key_Enter:
396 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP; 451 scancode = SDLK_KP_ENTER;
397 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN; 452 break;
398 else scancode = SDLK_LEFT; 453 case Qt::Key_Insert:
399 break; 454 scancode = SDLK_INSERT;
400 case Qt::Key_Up: 455 break;
401 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT; 456 case Qt::Key_Delete:
402 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT; 457 scancode = SDLK_DELETE;
403 else scancode = SDLK_UP; 458 break;
404 break; 459 case Qt::Key_Pause:
405 case Qt::Key_Right: 460 scancode = SDLK_PAUSE;
406 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN; 461 break;
407 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP; 462 case Qt::Key_Print:
408 else scancode = SDLK_RIGHT; 463 scancode = SDLK_PRINT;
409 break; 464 break;
410 case Qt::Key_Down: 465 case Qt::Key_SysReq:
411 if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT; 466 scancode = SDLK_SYSREQ;
412 else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT; 467 break;
413 else scancode = SDLK_DOWN; 468 case Qt::Key_Home:
414 break; 469 scancode = SDLK_HOME;
415 case Qt::Key_Prior: scancode = SDLK_PAGEUP; break; 470 break;
416 case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break; 471 case Qt::Key_End:
417 case Qt::Key_Shift: scancode = SDLK_LSHIFT; break; 472 scancode = SDLK_END;
418 case Qt::Key_Control: scancode = SDLK_LCTRL; break; 473 break;
419 case Qt::Key_Meta: scancode = SDLK_LMETA; break; 474 // We want the control keys to rotate with the screen
420 case Qt::Key_Alt: scancode = SDLK_LALT; break; 475 case Qt::Key_Left:
421 case Qt::Key_CapsLock: scancode = SDLK_CAPSLOCK; break; 476 if (screenRotation == SDL_QT_ROTATION_90)
422 case Qt::Key_NumLock: scancode = SDLK_NUMLOCK; break; 477 scancode = SDLK_UP;
423 case Qt::Key_ScrollLock: scancode = SDLK_SCROLLOCK; break; 478 else if (screenRotation == SDL_QT_ROTATION_270)
424 case Qt::Key_F1: scancode = SDLK_F1; break; 479 scancode = SDLK_DOWN;
425 case Qt::Key_F2: scancode = SDLK_F2; break; 480 else
426 case Qt::Key_F3: scancode = SDLK_F3; break; 481 scancode = SDLK_LEFT;
427 case Qt::Key_F4: scancode = SDLK_F4; break; 482 break;
428 case Qt::Key_F5: scancode = SDLK_F5; break; 483 case Qt::Key_Up:
429 case Qt::Key_F6: scancode = SDLK_F6; break; 484 if (screenRotation == SDL_QT_ROTATION_90)
430 case Qt::Key_F7: scancode = SDLK_F7; break; 485 scancode = SDLK_RIGHT;
431 case Qt::Key_F8: scancode = SDLK_F8; break; 486 else if (screenRotation == SDL_QT_ROTATION_270)
432 case Qt::Key_F9: scancode = SDLK_F9; break; 487 scancode = SDLK_LEFT;
433 case Qt::Key_F10: scancode = SDLK_F10; break; 488 else
434 case Qt::Key_F11: scancode = SDLK_F11; break; 489 scancode = SDLK_UP;
435 case Qt::Key_F12: scancode = SDLK_F12; break; 490 break;
436 case Qt::Key_F13: scancode = SDLK_F13; break; 491 case Qt::Key_Right:
437 case Qt::Key_F14: scancode = SDLK_F14; break; 492 if (screenRotation == SDL_QT_ROTATION_90)
438 case Qt::Key_F15: scancode = SDLK_F15; break; 493 scancode = SDLK_DOWN;
439 case Qt::Key_Super_L: scancode = SDLK_LSUPER; break; 494 else if (screenRotation == SDL_QT_ROTATION_270)
440 case Qt::Key_Super_R: scancode = SDLK_RSUPER; break; 495 scancode = SDLK_UP;
441 case Qt::Key_Menu: scancode = SDLK_MENU; break; 496 else
442 case Qt::Key_Help: scancode = SDLK_HELP; break; 497 scancode = SDLK_RIGHT;
443 498 break;
444 case Qt::Key_F33: 499 case Qt::Key_Down:
445 // FIXME: This is a hack to enable the OK key on 500 if (screenRotation == SDL_QT_ROTATION_90)
446 // Zaurii devices. SDLK_RETURN is a suitable key to use 501 scancode = SDLK_LEFT;
447 // since it often is used as such. 502 else if (screenRotation == SDL_QT_ROTATION_270)
448 // david@hedbor.org 503 scancode = SDLK_RIGHT;
449 scancode = SDLK_RETURN; 504 else
450 break; 505 scancode = SDLK_DOWN;
451 default: 506 break;
452 scancode = SDLK_UNKNOWN; 507 case Qt::Key_Prior:
453 break; 508 scancode = SDLK_PAGEUP;
454 } 509 break;
455 keysym.sym = static_cast<SDLKey>(scancode); 510 case Qt::Key_Next:
456 } else { 511 scancode = SDLK_PAGEDOWN;
457 keysym.sym = static_cast<SDLKey>(scancode); 512 break;
458 } 513 case Qt::Key_Shift:
459 keysym.scancode = scancode; 514 scancode = SDLK_LSHIFT;
460 keysym.mod = KMOD_NONE; 515 break;
461 ButtonState st = e->state(); 516 case Qt::Key_Control:
462 if( (st & ShiftButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LSHIFT); } 517 scancode = SDLK_LCTRL;
463 if( (st & ControlButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LCTRL); } 518 break;
464 if( (st & AltButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LALT); } 519 case Qt::Key_Meta:
465 if ( SDL_TranslateUNICODE ) { 520 scancode = SDLK_LMETA;
466 QChar qchar = e->text()[0]; 521 break;
467 keysym.unicode = qchar.unicode(); 522 case Qt::Key_Alt:
468 } else { 523 scancode = SDLK_LALT;
469 keysym.unicode = 0; 524 break;
470 } 525 case Qt::Key_CapsLock:
471 526 scancode = SDLK_CAPSLOCK;
472 /* NUMLOCK and CAPSLOCK are implemented as double-presses in reality */ 527 break;
473 // if ( (keysym.sym == SDLK_NUMLOCK) || (keysym.sym == SDLK_CAPSLOCK) ) { 528 case Qt::Key_NumLock:
474 // pressed = 1; 529 scancode = SDLK_NUMLOCK;
475 // } 530 break;
476 531 case Qt::Key_ScrollLock:
477 /* Queue the key event */ 532 scancode = SDLK_SCROLLOCK;
478 if ( pressed ) { 533 break;
479 SDL_PrivateKeyboard(SDL_PRESSED, &keysym); 534 case Qt::Key_F1:
480 } else { 535 scancode = SDLK_F1;
481 SDL_PrivateKeyboard(SDL_RELEASED, &keysym); 536 break;
482 } 537 case Qt::Key_F2:
483 } 538 scancode = SDLK_F2;
484 539 break;
485 void SDL_QWin::setFullscreen(bool fs_on) { 540 case Qt::Key_F3:
486 my_has_fullscreen = false; 541 scancode = SDLK_F3;
487 enableFullscreen(); 542 break;
488 } 543 case Qt::Key_F4:
489 544 scancode = SDLK_F4;
490 void SDL_QWin::enableFullscreen() { 545 break;
491 // Make sure size is correct 546 case Qt::Key_F5:
492 if(!my_has_fullscreen) { 547 scancode = SDLK_F5;
493 setFixedSize(qApp->desktop()->size()); 548 break;
494 // This call is needed because showFullScreen won't work 549 case Qt::Key_F6:
495 // correctly if the widget already considers itself to be fullscreen. 550 scancode = SDLK_F6;
496 showNormal(); 551 break;
497 // This is needed because showNormal() forcefully changes the window 552 case Qt::Key_F7:
498 // style to WSTyle_TopLevel. 553 scancode = SDLK_F7;
499 setWFlags(WStyle_Customize | WStyle_NoBorder); 554 break;
500 // Enable fullscreen. 555 case Qt::Key_F8:
501 showFullScreen(); 556 scancode = SDLK_F8;
502 my_has_fullscreen = true; 557 break;
503 } 558 case Qt::Key_F9:
504 } 559 scancode = SDLK_F9;
505 560 break;
506 bool SDL_QWin::lockScreen(bool force) { 561 case Qt::Key_F10:
507 if(!my_painter) { 562 scancode = SDLK_F10;
508 if(force || (isVisible() && isActiveWindow())) { 563 break;
509 my_painter = new QDirectPainter(this); 564 case Qt::Key_F11:
510 } else { 565 scancode = SDLK_F11;
511 return false; 566 break;
512 } 567 case Qt::Key_F12:
513 } 568 scancode = SDLK_F12;
514 my_locked++; // Increate lock refcount 569 break;
515 return true; 570 case Qt::Key_F13:
516 } 571 scancode = SDLK_F13;
517 572 break;
518 void SDL_QWin::unlockScreen() { 573 case Qt::Key_F14:
519 if(my_locked > 0) { 574 scancode = SDLK_F14;
520 my_locked--; // decrease lock refcount; 575 break;
521 } 576 case Qt::Key_F15:
522 if(!my_locked && my_painter) { 577 scancode = SDLK_F15;
523 my_painter->end(); 578 break;
524 delete my_painter; 579 case Qt::Key_Super_L:
525 my_painter = 0; 580 scancode = SDLK_LSUPER;
526 } 581 break;
527 } 582 case Qt::Key_Super_R:
583 scancode = SDLK_RSUPER;
584 break;
585 case Qt::Key_Menu:
586 scancode = SDLK_MENU;
587 break;
588 case Qt::Key_Help:
589 scancode = SDLK_HELP;
590 break;
591
592 case Qt::Key_F33:
593 // FIXME: This is a hack to enable the OK key on
594 // Zaurii devices. SDLK_RETURN is a suitable key to use
595 // since it often is used as such.
596 // david@hedbor.org
597 scancode = SDLK_RETURN;
598 break;
599 default:
600 scancode = SDLK_UNKNOWN;
601 break;
602 }
603 keysym.sym = static_cast < SDLKey > (scancode);
604 } else {
605 keysym.sym = static_cast < SDLKey > (scancode);
606 }
607 keysym.scancode = scancode;
608 keysym.mod = KMOD_NONE;
609 ButtonState st = e->state();
610 if ((st & ShiftButton)) {
611 keysym.mod = static_cast < SDLMod > (keysym.mod | KMOD_LSHIFT);
612 }
613 if ((st & ControlButton)) {
614 keysym.mod = static_cast < SDLMod > (keysym.mod | KMOD_LCTRL);
615 }
616 if ((st & AltButton)) {
617 keysym.mod = static_cast < SDLMod > (keysym.mod | KMOD_LALT);
618 }
619 if (SDL_TranslateUNICODE) {
620 QChar qchar = e->text()[0];
621 keysym.unicode = qchar.unicode();
622 } else {
623 keysym.unicode = 0;
624 }
625
626 /* NUMLOCK and CAPSLOCK are implemented as double-presses in reality */
627 // if ( (keysym.sym == SDLK_NUMLOCK) || (keysym.sym == SDLK_CAPSLOCK) ) {
628 // pressed = 1;
629 // }
630
631 /* Queue the key event */
632 if (pressed) {
633 SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
634 } else {
635 SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
636 }
637 }
638
639 void
640 SDL_QWin::setFullscreen(bool fs_on)
641 {
642 my_has_fullscreen = false;
643 enableFullscreen();
644 }
645
646 void
647 SDL_QWin::enableFullscreen()
648 {
649 // Make sure size is correct
650 if (!my_has_fullscreen) {
651 setFixedSize(qApp->desktop()->size());
652 // This call is needed because showFullScreen won't work
653 // correctly if the widget already considers itself to be fullscreen.
654 showNormal();
655 // This is needed because showNormal() forcefully changes the window
656 // style to WSTyle_TopLevel.
657 setWFlags(WStyle_Customize | WStyle_NoBorder);
658 // Enable fullscreen.
659 showFullScreen();
660 my_has_fullscreen = true;
661 }
662 }
663
664 /* *INDENT-OFF* */
665 bool
666 SDL_QWin::lockScreen (bool force)
667 {
668 if (!my_painter) {
669 if (force || (isVisible () && isActiveWindow ())) {
670 my_painter = new QDirectPainter (this);
671 } else {
672 return false;
673 }
674 }
675 my_locked++; // Increate lock refcount
676 return true;
677 }
678 /* *INDENT-ON* */
679
680 void
681 SDL_QWin::unlockScreen()
682 {
683 if (my_locked > 0) {
684 my_locked--; // decrease lock refcount;
685 }
686 if (!my_locked && my_painter) {
687 my_painter->end();
688 delete my_painter;
689 my_painter = 0;
690 }
691 }
692
693 /* vi: set ts=4 sw=4 expandtab: */