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