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