src/video/gem/SDL_gemevents.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 10 Jul 2006 21:04:37 +0000
changeset 1895 c121d94672cb
parent 1857 417f2af2bd52
child 2019 d20f4510c718
permissions -rw-r--r--
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@281
     4
slouken@281
     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@281
     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@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@281
    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@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
slouken@281
    25
 * GEM SDL video driver implementation
slouken@281
    26
 * inspired from the Dummy SDL driver
slouken@281
    27
 * 
slouken@281
    28
 * Patrice Mandin
slouken@281
    29
 * and work from
slouken@281
    30
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
slouken@281
    31
 */
slouken@281
    32
slouken@281
    33
#include <gem.h>
slouken@281
    34
slouken@1361
    35
#include "../../events/SDL_sysevents.h"
slouken@1361
    36
#include "../../events/SDL_events_c.h"
slouken@281
    37
#include "SDL_gemvideo.h"
slouken@281
    38
#include "SDL_gemevents_c.h"
slouken@1895
    39
#include "../ataricommon/SDL_atarikeys.h"       /* for keyboard scancodes */
patmandin@1412
    40
#include "../ataricommon/SDL_atarievents_c.h"
patmandin@1412
    41
#include "../ataricommon/SDL_xbiosevents_c.h"
patmandin@1420
    42
#include "../ataricommon/SDL_ataridevmouse_c.h"
slouken@281
    43
slouken@281
    44
/* Defines */
slouken@281
    45
slouken@281
    46
#define ATARIBIOS_MAXKEYS 128
slouken@281
    47
slouken@281
    48
/* Variables */
slouken@281
    49
slouken@281
    50
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    51
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    52
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
slouken@281
    53
slouken@281
    54
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    55
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    56
slouken@281
    57
/* Functions prototypes */
slouken@281
    58
slouken@1895
    59
static SDL_keysym *TranslateKey(int scancode, int asciicode,
slouken@1895
    60
                                SDL_keysym * keysym, SDL_bool pressed);
slouken@281
    61
static int do_messages(_THIS, short *message);
slouken@281
    62
static void do_keyboard(short kc, short ks);
slouken@319
    63
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
slouken@281
    64
slouken@281
    65
/* Functions */
slouken@281
    66
slouken@1895
    67
static SDL_keysym *
slouken@1895
    68
TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
slouken@1895
    69
             SDL_bool pressed)
slouken@281
    70
{
slouken@1895
    71
    /* Set the keysym information */
slouken@1895
    72
    keysym->scancode = scancode;
slouken@281
    73
slouken@1895
    74
    if (asciicode)
slouken@1895
    75
        keysym->sym = asciicode;
slouken@1895
    76
    else
slouken@1895
    77
        keysym->sym = keymap[scancode];
slouken@281
    78
slouken@1895
    79
    keysym->mod = KMOD_NONE;
slouken@1895
    80
    keysym->unicode = 0;
slouken@1895
    81
    if (SDL_TranslateUNICODE && pressed) {
slouken@1895
    82
        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
slouken@1895
    83
    }
slouken@281
    84
slouken@1895
    85
    return (keysym);
slouken@281
    86
}
slouken@281
    87
slouken@1895
    88
void
slouken@1895
    89
GEM_InitOSKeymap(_THIS)
slouken@281
    90
{
slouken@1895
    91
    int i;
slouken@281
    92
slouken@1895
    93
    SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
slouken@1895
    94
    SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
slouken@1895
    95
    SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
slouken@281
    96
slouken@1895
    97
    /* Initialize keymap */
slouken@1895
    98
    for (i = 0; i < sizeof(keymap); i++)
slouken@1895
    99
        keymap[i] = SDLK_UNKNOWN;
slouken@281
   100
slouken@1895
   101
    /* Functions keys */
slouken@1895
   102
    for (i = 0; i < 10; i++)
slouken@1895
   103
        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
slouken@281
   104
slouken@1895
   105
    /* Cursor keypad */
slouken@1895
   106
    keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@1895
   107
    keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@1895
   108
    keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@1895
   109
    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@1895
   110
    keymap[SCANCODE_UP] = SDLK_UP;
slouken@1895
   111
    keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@1895
   112
    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@1895
   113
    keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
   114
slouken@1895
   115
    /* Special keys */
slouken@1895
   116
    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@1895
   117
    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@1895
   118
    keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@1895
   119
    keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@1895
   120
    keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@1895
   121
    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@1895
   122
    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@1895
   123
    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@1895
   124
    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@1895
   125
    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   126
slouken@1895
   127
    /* Mouse init */
slouken@1895
   128
    GEM_mouse_relative = SDL_FALSE;
slouken@281
   129
}
slouken@281
   130
slouken@1895
   131
void
slouken@1895
   132
GEM_PumpEvents(_THIS)
slouken@281
   133
{
slouken@1895
   134
    short mousex, mousey, mouseb, dummy;
slouken@1895
   135
    short kstate, prevkc, prevks;
slouken@1895
   136
    int i;
slouken@1895
   137
    SDL_keysym keysym;
slouken@281
   138
slouken@1895
   139
    SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
slouken@1895
   140
    prevkc = prevks = 0;
slouken@281
   141
slouken@1895
   142
    for (;;) {
slouken@1895
   143
        int quit, resultat, event_mask, mouse_event;
slouken@1895
   144
        short buffer[8], kc;
slouken@1895
   145
        short x2, y2, w2, h2;
slouken@281
   146
slouken@1895
   147
        quit = mouse_event = x2 = y2 = w2 = h2 = 0;
patmandin@1067
   148
slouken@1895
   149
        event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
slouken@1895
   150
        if (!GEM_fullscreen && (GEM_handle >= 0)) {
slouken@1895
   151
            wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1895
   152
            event_mask |= MU_M1;
slouken@1895
   153
            if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
slouken@1895
   154
                mouse_event = MO_LEAVE;
slouken@1895
   155
            } else {
slouken@1895
   156
                mouse_event = MO_ENTER;
slouken@1895
   157
            }
slouken@1895
   158
        }
slouken@281
   159
slouken@1895
   160
        resultat = evnt_multi(event_mask,
slouken@1895
   161
                              0, 0, 0,
slouken@1895
   162
                              mouse_event, x2, y2, w2, h2,
slouken@1895
   163
                              0, 0, 0, 0, 0,
slouken@1895
   164
                              buffer,
slouken@1895
   165
                              10,
slouken@1895
   166
                              &dummy, &dummy, &dummy, &kstate, &kc, &dummy);
slouken@281
   167
slouken@1895
   168
        /* Message event ? */
slouken@1895
   169
        if (resultat & MU_MESAG)
slouken@1895
   170
            quit = do_messages(this, buffer);
slouken@281
   171
slouken@1895
   172
        /* Keyboard event ? */
slouken@1895
   173
        if (resultat & MU_KEYBD) {
slouken@1895
   174
            if ((prevkc != kc) || (prevks != kstate)) {
slouken@1895
   175
                do_keyboard(kc, kstate);
slouken@1895
   176
            } else {
slouken@1895
   177
                /* Avoid looping, if repeating same key */
slouken@1895
   178
                break;
slouken@1895
   179
            }
slouken@1895
   180
        }
patmandin@1067
   181
slouken@1895
   182
        /* Mouse entering/leaving window */
slouken@1895
   183
        if (resultat & MU_M1) {
slouken@1895
   184
            if (this->input_grab == SDL_GRAB_OFF) {
slouken@1895
   185
                if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
slouken@1895
   186
                    SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
slouken@1895
   187
                } else {
slouken@1895
   188
                    SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@1895
   189
                }
slouken@1895
   190
            }
slouken@1895
   191
        }
slouken@281
   192
slouken@1895
   193
        /* Timer event ? */
slouken@1895
   194
        if ((resultat & MU_TIMER) || quit)
slouken@1895
   195
            break;
slouken@1895
   196
    }
slouken@281
   197
slouken@1895
   198
    /* Update mouse */
slouken@1895
   199
    graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
slouken@1895
   200
    do_mouse(this, mousex, mousey, mouseb, kstate);
slouken@281
   201
slouken@1895
   202
    /* Now generate keyboard events */
slouken@1895
   203
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1895
   204
        /* Key pressed ? */
slouken@1895
   205
        if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
slouken@1895
   206
            SDL_PrivateKeyboard(SDL_PRESSED,
slouken@1895
   207
                                TranslateKey(i, gem_currentascii[i],
slouken@1895
   208
                                             &keysym, SDL_TRUE));
patmandin@996
   209
slouken@1895
   210
        /* Key unpressed ? */
slouken@1895
   211
        if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
slouken@1895
   212
            SDL_PrivateKeyboard(SDL_RELEASED,
slouken@1895
   213
                                TranslateKey(i, gem_currentascii[i],
slouken@1895
   214
                                             &keysym, SDL_FALSE));
slouken@1895
   215
    }
slouken@1895
   216
slouken@1895
   217
    SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
slouken@1895
   218
               sizeof(gem_previouskeyboard));
slouken@1895
   219
slouken@1895
   220
    /* Refresh window name ? */
slouken@1895
   221
    if (GEM_refresh_name) {
slouken@1895
   222
        if (SDL_GetAppState() & SDL_APPACTIVE) {
slouken@1895
   223
            /* Fullscreen/windowed */
slouken@1895
   224
            if (GEM_title_name) {
slouken@1895
   225
                wind_set(GEM_handle, WF_NAME,
slouken@1895
   226
                         (short) (((unsigned long) GEM_title_name) >>
slouken@1895
   227
                                  16),
slouken@1895
   228
                         (short) (((unsigned long) GEM_title_name) &
slouken@1895
   229
                                  0xffff), 0, 0);
slouken@1895
   230
            }
slouken@1895
   231
        } else {
slouken@1895
   232
            /* Iconified */
slouken@1895
   233
            if (GEM_icon_name) {
slouken@1895
   234
                wind_set(GEM_handle, WF_NAME,
slouken@1895
   235
                         (short) (((unsigned long) GEM_icon_name) >>
slouken@1895
   236
                                  16),
slouken@1895
   237
                         (short) (((unsigned long) GEM_icon_name) &
slouken@1895
   238
                                  0xffff), 0, 0);
slouken@1895
   239
            }
slouken@1895
   240
        }
slouken@1895
   241
        GEM_refresh_name = SDL_FALSE;
slouken@1895
   242
    }
slouken@281
   243
}
slouken@281
   244
slouken@1895
   245
static int
slouken@1895
   246
do_messages(_THIS, short *message)
slouken@281
   247
{
slouken@1895
   248
    int quit, posted;
slouken@1895
   249
    short x2, y2, w2, h2;
slouken@281
   250
slouken@1895
   251
    quit = 0;
slouken@1895
   252
    switch (message[0]) {
slouken@1895
   253
    case WM_CLOSED:
slouken@1895
   254
    case AP_TERM:
slouken@1895
   255
        posted = SDL_PrivateQuit();
slouken@1895
   256
        quit = 1;
slouken@1895
   257
        break;
slouken@1895
   258
    case WM_MOVED:
slouken@1895
   259
        wind_set(message[3], WF_CURRXYWH, message[4], message[5],
slouken@1895
   260
                 message[6], message[7]);
slouken@1895
   261
        break;
slouken@1895
   262
    case WM_TOPPED:
slouken@1895
   263
        wind_set(message[3], WF_TOP, message[4], 0, 0, 0);
slouken@1895
   264
        /* Continue with TOP event processing */
slouken@1895
   265
    case WM_ONTOP:
slouken@1895
   266
        SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
slouken@1895
   267
        if (VDI_setpalette) {
slouken@1895
   268
            VDI_setpalette(this, VDI_curpalette);
slouken@1895
   269
        }
slouken@1895
   270
        break;
slouken@1895
   271
    case WM_REDRAW:
slouken@1895
   272
        if (!GEM_lock_redraw) {
slouken@1895
   273
            GEM_wind_redraw(this, message[3], &message[4]);
slouken@1895
   274
        }
slouken@1895
   275
        break;
slouken@1895
   276
    case WM_ICONIFY:
slouken@1895
   277
    case WM_ALLICONIFY:
slouken@1895
   278
        wind_set(message[3], WF_ICONIFY, message[4], message[5],
slouken@1895
   279
                 message[6], message[7]);
slouken@1895
   280
        /* If we're active, make ourselves inactive */
slouken@1895
   281
        if (SDL_GetAppState() & SDL_APPACTIVE) {
slouken@1895
   282
            /* Send an internal deactivate event */
slouken@1895
   283
            SDL_PrivateAppActive(0, SDL_APPACTIVE);
slouken@1895
   284
        }
slouken@1895
   285
        /* Update window title */
slouken@1895
   286
        if (GEM_refresh_name && GEM_icon_name) {
slouken@1895
   287
            wind_set(GEM_handle, WF_NAME,
slouken@1895
   288
                     (short) (((unsigned long) GEM_icon_name) >> 16),
slouken@1895
   289
                     (short) (((unsigned long) GEM_icon_name) & 0xffff),
slouken@1895
   290
                     0, 0);
slouken@1895
   291
            GEM_refresh_name = SDL_FALSE;
slouken@1895
   292
        }
slouken@1895
   293
        break;
slouken@1895
   294
    case WM_UNICONIFY:
slouken@1895
   295
        wind_set(message[3], WF_UNICONIFY, message[4], message[5],
slouken@1895
   296
                 message[6], message[7]);
slouken@1895
   297
        /* If we're not active, make ourselves active */
slouken@1895
   298
        if (!(SDL_GetAppState() & SDL_APPACTIVE)) {
slouken@1895
   299
            /* Send an internal activate event */
slouken@1895
   300
            SDL_PrivateAppActive(1, SDL_APPACTIVE);
slouken@1895
   301
        }
slouken@1895
   302
        if (GEM_refresh_name && GEM_title_name) {
slouken@1895
   303
            wind_set(GEM_handle, WF_NAME,
slouken@1895
   304
                     (short) (((unsigned long) GEM_title_name) >> 16),
slouken@1895
   305
                     (short) (((unsigned long) GEM_title_name) & 0xffff),
slouken@1895
   306
                     0, 0);
slouken@1895
   307
            GEM_refresh_name = SDL_FALSE;
slouken@1895
   308
        }
slouken@1895
   309
        break;
slouken@1895
   310
    case WM_SIZED:
slouken@1895
   311
        wind_set(message[3], WF_CURRXYWH, message[4], message[5],
slouken@1895
   312
                 message[6], message[7]);
slouken@1895
   313
        wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1895
   314
        GEM_win_fulled = SDL_FALSE;     /* Cancel maximized flag */
slouken@1895
   315
        GEM_lock_redraw = SDL_TRUE;     /* Prevent redraw till buffers resized */
slouken@1895
   316
        SDL_PrivateResize(w2, h2);
slouken@1895
   317
        break;
slouken@1895
   318
    case WM_FULLED:
slouken@1895
   319
        {
slouken@1895
   320
            short x, y, w, h;
slouken@281
   321
slouken@1895
   322
            if (GEM_win_fulled) {
slouken@1895
   323
                wind_get(message[3], WF_PREVXYWH, &x, &y, &w, &h);
slouken@1895
   324
                GEM_win_fulled = SDL_FALSE;
slouken@1895
   325
            } else {
slouken@1895
   326
                x = GEM_desk_x;
slouken@1895
   327
                y = GEM_desk_y;
slouken@1895
   328
                w = GEM_desk_w;
slouken@1895
   329
                h = GEM_desk_h;
slouken@1895
   330
                GEM_win_fulled = SDL_TRUE;
slouken@1895
   331
            }
slouken@1895
   332
            wind_set(message[3], WF_CURRXYWH, x, y, w, h);
slouken@1895
   333
            wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1895
   334
            GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
slouken@1895
   335
            SDL_PrivateResize(w2, h2);
slouken@1895
   336
        }
slouken@1895
   337
        break;
slouken@1895
   338
    case WM_BOTTOMED:
slouken@1895
   339
        wind_set(message[3], WF_BOTTOM, 0, 0, 0, 0);
slouken@1895
   340
        /* Continue with BOTTOM event processing */
slouken@1895
   341
    case WM_UNTOPPED:
slouken@1895
   342
        SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
slouken@1895
   343
        if (VDI_setpalette) {
slouken@1895
   344
            VDI_setpalette(this, VDI_oldpalette);
slouken@1895
   345
        }
slouken@1895
   346
        break;
slouken@1895
   347
    }
slouken@1895
   348
slouken@1895
   349
    return quit;
slouken@281
   350
}
slouken@281
   351
slouken@1895
   352
static void
slouken@1895
   353
do_keyboard(short kc, short ks)
slouken@281
   354
{
slouken@1895
   355
    int scancode, asciicode;
slouken@281
   356
slouken@1895
   357
    if (kc) {
slouken@1895
   358
        scancode = (kc >> 8) & 127;
slouken@1895
   359
        asciicode = kc & 255;
slouken@281
   360
slouken@1895
   361
        gem_currentkeyboard[scancode] = 0xFF;
slouken@1895
   362
        gem_currentascii[scancode] = asciicode;
slouken@1895
   363
    }
slouken@281
   364
slouken@1895
   365
    /* Read special keys */
slouken@1895
   366
    if (ks & K_RSHIFT)
slouken@1895
   367
        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
slouken@1895
   368
    if (ks & K_LSHIFT)
slouken@1895
   369
        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
slouken@1895
   370
    if (ks & K_CTRL)
slouken@1895
   371
        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
slouken@1895
   372
    if (ks & K_ALT)
slouken@1895
   373
        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
slouken@281
   374
}
slouken@281
   375
slouken@1895
   376
static void
slouken@1895
   377
do_mouse(_THIS, short mx, short my, short mb, short ks)
slouken@281
   378
{
slouken@1895
   379
    static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
slouken@1895
   380
    short x2, y2, w2, h2;
patmandin@926
   381
slouken@1895
   382
    /* Don't return mouse events if out of window */
slouken@1895
   383
    if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) {
slouken@1895
   384
        return;
slouken@1895
   385
    }
patmandin@1067
   386
slouken@1895
   387
    /* Retrieve window coords, and generate mouse events accordingly */
slouken@1895
   388
    x2 = y2 = 0;
slouken@1895
   389
    w2 = VDI_w;
slouken@1895
   390
    h2 = VDI_h;
slouken@1895
   391
    if ((!GEM_fullscreen) && (GEM_handle >= 0)) {
slouken@1895
   392
        wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@926
   393
slouken@1895
   394
        /* Do not generate mouse button event if out of window working area */
slouken@1895
   395
        if ((mx < x2) || (mx >= x2 + w2) || (my < y2) || (my >= y2 + h2)) {
slouken@1895
   396
            mb = prevmouseb;
slouken@1895
   397
        }
slouken@1895
   398
    }
slouken@319
   399
slouken@1895
   400
    /* Mouse motion ? */
slouken@1895
   401
    if (GEM_mouse_relative) {
slouken@1895
   402
        if (GEM_usedevmouse) {
slouken@1895
   403
            SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
slouken@1895
   404
        } else {
slouken@1895
   405
            SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
slouken@1895
   406
        }
slouken@1895
   407
    } else {
slouken@1895
   408
        if ((prevmousex != mx) || (prevmousey != my)) {
slouken@1895
   409
            int posx, posy;
patmandin@926
   410
slouken@1895
   411
            /* Give mouse position relative to window position */
slouken@1895
   412
            posx = mx - x2;
slouken@1895
   413
            if (posx < 0)
slouken@1895
   414
                posx = 0;
slouken@1895
   415
            if (posx > w2)
slouken@1895
   416
                posx = w2 - 1;
slouken@1895
   417
            posy = my - y2;
slouken@1895
   418
            if (posy < 0)
slouken@1895
   419
                posy = 0;
slouken@1895
   420
            if (posy > h2)
slouken@1895
   421
                posy = h2 - 1;
patmandin@926
   422
slouken@1895
   423
            SDL_PrivateMouseMotion(0, 0, posx, posy);
slouken@1895
   424
        }
slouken@1895
   425
        prevmousex = mx;
slouken@1895
   426
        prevmousey = my;
slouken@1895
   427
    }
slouken@281
   428
slouken@1895
   429
    /* Mouse button ? */
slouken@1895
   430
    if (prevmouseb != mb) {
slouken@1895
   431
        int i;
slouken@281
   432
slouken@1895
   433
        for (i = 0; i < 2; i++) {
slouken@1895
   434
            int curbutton, prevbutton;
slouken@319
   435
slouken@1895
   436
            curbutton = mb & (1 << i);
slouken@1895
   437
            prevbutton = prevmouseb & (1 << i);
slouken@1895
   438
slouken@1895
   439
            if (curbutton && !prevbutton) {
slouken@1895
   440
                SDL_PrivateMouseButton(SDL_PRESSED, i + 1, 0, 0);
slouken@1895
   441
            }
slouken@1895
   442
            if (!curbutton && prevbutton) {
slouken@1895
   443
                SDL_PrivateMouseButton(SDL_RELEASED, i + 1, 0, 0);
slouken@1895
   444
            }
slouken@1895
   445
        }
slouken@1895
   446
        prevmouseb = mb;
slouken@1895
   447
    }
slouken@1895
   448
slouken@1895
   449
    /* Read special keys */
slouken@1895
   450
    if (ks & K_RSHIFT)
slouken@1895
   451
        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
slouken@1895
   452
    if (ks & K_LSHIFT)
slouken@1895
   453
        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
slouken@1895
   454
    if (ks & K_CTRL)
slouken@1895
   455
        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
slouken@1895
   456
    if (ks & K_ALT)
slouken@1895
   457
        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
slouken@281
   458
}
slouken@1895
   459
slouken@1895
   460
/* vi: set ts=4 sw=4 expandtab: */