src/video/picogui/SDL_pgevents.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@433
     1
/*
slouken@433
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@433
     4
slouken@433
     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@433
     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@433
     9
slouken@433
    10
    This library is distributed in the hope that it will be useful,
slouken@433
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@433
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@433
    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@433
    18
slouken@433
    19
    Sam Lantinga
slouken@433
    20
    slouken@libsdl.org
slouken@433
    21
slouken@433
    22
    Micah Dowty
slouken@433
    23
    micahjd@users.sourceforge.net
slouken@433
    24
*/
slouken@1402
    25
#include "SDL_config.h"
slouken@433
    26
slouken@433
    27
#include "SDL.h"
slouken@1361
    28
#include "../../events/SDL_sysevents.h"
slouken@1361
    29
#include "../../events/SDL_events_c.h"
slouken@433
    30
#include "SDL_pgvideo.h"
slouken@433
    31
#include "SDL_pgevents_c.h"
slouken@433
    32
slouken@1662
    33
int
slouken@1668
    34
PG_HandleClose(struct pgEvent *evt)
slouken@433
    35
{
slouken@1668
    36
    SDL_PrivateQuit();
slouken@1662
    37
    return 1;                   /* Intercept the event's normal quit handling */
slouken@433
    38
}
slouken@433
    39
slouken@1662
    40
int
slouken@1668
    41
PG_HandleResize(struct pgEvent *evt)
slouken@433
    42
{
slouken@1668
    43
    SDL_PrivateResize(evt->e.size.w, evt->e.size.h);
slouken@1662
    44
    return 0;
slouken@433
    45
}
slouken@433
    46
slouken@1662
    47
int
slouken@1668
    48
PG_HandleKey(struct pgEvent *evt)
slouken@433
    49
{
slouken@1662
    50
    SDL_keysym sym;
slouken@1668
    51
    SDL_memset(&sym, 0, sizeof(sym));
slouken@1662
    52
    sym.sym = evt->e.kbd.key;
slouken@1662
    53
    sym.mod = evt->e.kbd.mods;
slouken@1668
    54
    SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
slouken@1662
    55
    return 0;
slouken@433
    56
}
slouken@433
    57
slouken@1662
    58
int
slouken@1668
    59
PG_HandleChar(struct pgEvent *evt)
slouken@433
    60
{
slouken@1662
    61
    SDL_keysym sym;
slouken@1668
    62
    SDL_memset(&sym, 0, sizeof(sym));
slouken@1662
    63
    sym.unicode = evt->e.kbd.key;
slouken@1662
    64
    sym.mod = evt->e.kbd.mods;
slouken@1668
    65
    SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
slouken@1662
    66
    return 0;
slouken@433
    67
}
slouken@433
    68
slouken@1662
    69
int
slouken@1668
    70
PG_HandleMouseButton(struct pgEvent *evt)
slouken@1662
    71
{
slouken@1662
    72
    /* We need to focus the canvas when it's clicked */
slouken@1662
    73
    if (evt->extra) {
slouken@1662
    74
        SDL_VideoDevice *this = (SDL_VideoDevice *) evt->extra;
slouken@1668
    75
        pgFocus(this->hidden->wCanvas);
slouken@1662
    76
    }
slouken@1668
    77
    SDL_PrivateMouseButton(evt->type == PG_WE_PNTR_DOWN, evt->e.pntr.chbtn,
slouken@1668
    78
                           evt->e.pntr.x, evt->e.pntr.y);
slouken@1662
    79
    return 0;
slouken@433
    80
}
slouken@433
    81
slouken@1662
    82
int
slouken@1668
    83
PG_HandleMouseMotion(struct pgEvent *evt)
slouken@433
    84
{
slouken@1668
    85
    SDL_PrivateMouseMotion(evt->e.pntr.btn, 0, evt->e.pntr.x, evt->e.pntr.y);
slouken@1662
    86
    return 0;
slouken@433
    87
}
slouken@433
    88
slouken@1662
    89
void
slouken@1668
    90
PG_PumpEvents(_THIS)
slouken@433
    91
{
slouken@1662
    92
    /* Process all pending events */
slouken@1668
    93
    pgEventPoll();
slouken@433
    94
}
slouken@433
    95
slouken@1662
    96
void
slouken@1668
    97
PG_InitOSKeymap(_THIS)
slouken@433
    98
{
slouken@1662
    99
    /* We need no keymap */
slouken@433
   100
}
slouken@433
   101
slouken@1662
   102
void
slouken@1668
   103
PG_InitEvents(_THIS)
slouken@433
   104
{
slouken@1662
   105
    /* Turn on all the mouse and keyboard triggers for our canvas, normally less important
slouken@1662
   106
     * events like mouse movement are ignored to save bandwidth. */
slouken@1668
   107
    pgSetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK,
slouken@1668
   108
                pgGetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK) |
slouken@1668
   109
                PG_TRIGGER_UP | PG_TRIGGER_DOWN | PG_TRIGGER_MOVE |
slouken@1668
   110
                PG_TRIGGER_KEYUP | PG_TRIGGER_KEYDOWN | PG_TRIGGER_CHAR, 0);
slouken@433
   111
slouken@1662
   112
    /* Start our canvas out focused, so we get keyboard input */
slouken@1668
   113
    pgFocus(this->hidden->wCanvas);
slouken@433
   114
slouken@1662
   115
    /* Set up bindings for all the above event handlers */
slouken@1668
   116
    pgBind(this->hidden->wApp, PG_WE_CLOSE, &PG_HandleClose, NULL);
slouken@1668
   117
    pgBind(this->hidden->wCanvas, PG_WE_BUILD, &PG_HandleResize, NULL);
slouken@1668
   118
    pgBind(this->hidden->wCanvas, PG_WE_KBD_CHAR, &PG_HandleChar, NULL);
slouken@1668
   119
    pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYUP, &PG_HandleKey, NULL);
slouken@1668
   120
    pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYDOWN, &PG_HandleKey, NULL);
slouken@1668
   121
    pgBind(this->hidden->wCanvas, PG_WE_PNTR_MOVE, &PG_HandleMouseMotion,
slouken@1668
   122
           NULL);
slouken@1668
   123
    pgBind(this->hidden->wCanvas, PG_WE_PNTR_UP, &PG_HandleMouseButton, NULL);
slouken@1668
   124
    pgBind(this->hidden->wCanvas, PG_WE_PNTR_DOWN, &PG_HandleMouseButton,
slouken@1668
   125
           this);
slouken@433
   126
}
slouken@433
   127
slouken@433
   128
/* end of SDL_pgevents.c ... */
slouken@1662
   129
/* vi: set ts=4 sw=4 expandtab: */