quinn-sdl/src/video/quinn/SDL_quinnevents.c
2017-10-07 23:41:23 +10:00

262 lines
7.2 KiB
C

/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_quinnvideo.h"
#include "SDL_quinnevents_c.h"
#include "quinn.h"
static const int SDLK_unicode_shift[] = {
0, 0, 0x21, 0x40,
0x23, 0x24, 0x25, 0x5e,
0x26, 0x2a, 0x28, 0x29,
0x5f, 0x2b, 0x08, 0x09,
0x51, 0x57, 0x45, 0x52,
0x54, 0x59, 0x55, 0x49,
0x4F, 0x50, 0x7b, 0x7d,
0x0d, 0, 0x41, 0x53,
0x44, 0x46, 0x47, 0x48,
0x4a, 0x4b, 0x4c, 0x3A,
0x22, 0x7e, 0, 0x7c,
0x5a, 0x58, 0x43, 0x56,
0x42, 0x4e, 0x4d, 0x3c,
0x3e, 0x3f, 0, 0,
0, 0x20, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0, 0
};
static const int SDLK_unicode[] = {
0, 0, 0x31, 0x32,
0x33, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x30,
0x2d, 0x3d, 0x08, 0x09,
0x71, 0x77, 0x65, 0x72,
0x74, 0x79, 0x75, 0x69,
0x6F, 0x70, 0x5b, 0x5d,
0x0d, 0, 0x61, 0x73,
0x64, 0x66, 0x67, 0x68,
0x6a, 0x6b, 0x6c, 0x3B,
0x27, 0x60, 0, 0x5c,
0x7a, 0x78, 0x63, 0x76,
0x62, 0x6e, 0x6d, 0x2c,
0x2e, 0x2f, 0, 0,
0, 0x20, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0, 0
};
static const int SDLK_keyset[] = {
0, SDLK_ESCAPE, SDLK_1, SDLK_2,
SDLK_3, SDLK_4, SDLK_5, SDLK_6,
SDLK_7, SDLK_8, SDLK_9, SDLK_0,
SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_TAB,
SDLK_q, SDLK_w, SDLK_e, SDLK_r,
SDLK_t, SDLK_y, SDLK_u, SDLK_i,
SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET,
SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s,
SDLK_d, SDLK_f, SDLK_g, SDLK_h,
SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON,
SDLK_QUOTE, SDLK_BACKQUOTE, SDLK_LSHIFT, SDLK_BACKSLASH,
SDLK_z, SDLK_x, SDLK_c, SDLK_v,
SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA,
SDLK_PERIOD, SDLK_SLASH, SDLK_RSHIFT, SDLK_KP_MULTIPLY,
SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1,
SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5,
SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9,
SDLK_F10, 0, 0, SDLK_KP7,
SDLK_KP8, SDLK_KP9, SDLK_KP_MINUS, SDLK_KP4,
SDLK_KP5, SDLK_KP6, SDLK_KP_PLUS, SDLK_KP1,
SDLK_KP2, SDLK_KP3, SDLK_KP0, SDLK_KP_PERIOD,
0, 0, 0, SDLK_F11, SDLK_F12
};
static const int SDLK_keyset_e0[] = {
0, 0, 0, 0, //3
0, 0, 0, 0, //7
0, 0, 0, 0, //0b
0, 0, 0, 0, //0f
0, 0, 0, 0, //13
0, 0, 0, 0, //17
0, 0, 0, 0, //1b
SDLK_KP_ENTER, SDLK_RCTRL, 0, 0, //1f
0, 0, 0, 0, //23
0, 0, 0, 0, //27
0, 0, 0, 0, //2b
0, 0, 0, 0, //2f
0, 0, 0, 0, //33
0, SDLK_KP_DIVIDE, 0, 0, //37
SDLK_RALT, 0, 0, 0, //3b
0, 0, 0, 0, //3f
0, 0, 0, 0, //43
0, 0, 0, SDLK_HOME, //47
SDLK_UP, SDLK_PAGEUP, 0, SDLK_LEFT, //4b
0, SDLK_RIGHT, 0, SDLK_END, //4f
SDLK_DOWN, SDLK_PAGEDOWN, SDLK_INSERT, SDLK_DELETE, //53
0, 0, 0, 0, //57
0
};
static SDLKey keymap[256];
static SDLMod modstate = KMOD_NONE;
int mouse_state = 0;
static SDLMod make_mod(char *keycodes) {
SDLMod ret = KMOD_NONE;
if (keycodes[29]) ret |= KMOD_LCTRL;
if (keycodes[42]) ret |= KMOD_LSHIFT;
if (keycodes[56]) ret |= KMOD_LALT;
if (keycodes[54]) ret |= KMOD_RSHIFT;
return ret;
}
static struct window_update_req current_req;
static int current_req_current = 0;
static int _lmstate = 0;
static int _rmstate = 0;
static int _mmstate = 0;
static char _k_last_state[256];
static int _k_e0 = 0;
void QUINN_recv_event(struct window_update_req *req) {
memcpy(&current_req, req, sizeof(struct window_update_req));
current_req_current = 1;
}
void QUINN_PumpEvents(_THIS) {
int i;
int l;
if (this->hidden->doexit == 1) {
SDL_PrivateQuit();
}
if (current_req_current) {
for (l=0;l<current_req.event_msgs_count;l++) {
if (current_req.event_msgs[l].type == 1) {
// keyboard
SDL_keysym keysym;
if (_k_e0 == 0 && current_req.event_msgs[l].code == 0xe0) {
_k_e0 = 1;
continue;
}
if (_k_last_state[current_req.event_msgs[l].code] != current_req.event_msgs[l].state) {
keysym.scancode = current_req.event_msgs[l].code;
if (_k_last_state[42] == 1 || _k_last_state[54] == 1) {
keysym.unicode = SDLK_unicode_shift[current_req.event_msgs[l].code];
} else {
keysym.unicode = SDLK_unicode[current_req.event_msgs[l].code];
}
keysym.mod = make_mod(_k_last_state);
if (current_req.event_msgs[l].state == 1) {
if (_k_e0) {
keysym.sym = SDLK_keyset_e0[current_req.event_msgs[l].code];
} else {
keysym.sym = SDLK_keyset[current_req.event_msgs[l].code];
}
SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
} else {
// key up
if (_k_e0) {
keysym.sym = SDLK_keyset_e0[current_req.event_msgs[l].code];
} else {
keysym.sym = SDLK_keyset[current_req.event_msgs[l].code];
}
SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
}
}
_k_e0 = 0;
_k_last_state[current_req.event_msgs[l].code] = current_req.event_msgs[l].state;
} else if (current_req.event_msgs[l].type == 2) {
// mouse
if (current_req.event_msgs[l].code == 1) {
if (current_req.event_msgs[l].state != _lmstate) {
if (current_req.event_msgs[l].state == 1) {
SDL_PrivateMouseButton(SDL_PRESSED, 1, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
} else {
SDL_PrivateMouseButton(SDL_RELEASED, 1, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
}
}
_lmstate = current_req.event_msgs[l].state;
} else if (current_req.event_msgs[l].code == 2) {
if (current_req.event_msgs[l].state != _mmstate) {
if (current_req.event_msgs[l].state == 1) {
SDL_PrivateMouseButton(SDL_PRESSED, 2, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
} else {
SDL_PrivateMouseButton(SDL_RELEASED, 2, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
}
}
_mmstate = current_req.event_msgs[l].state;
} else if (current_req.event_msgs[l].code == 3) {
if (current_req.event_msgs[l].state != _rmstate) {
if (current_req.event_msgs[l].state == 1) {
SDL_PrivateMouseButton(SDL_PRESSED, 3, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
} else {
SDL_PrivateMouseButton(SDL_RELEASED, 3, current_req.event_msgs[l].x, current_req.event_msgs[l].y);
}
}
_rmstate = current_req.event_msgs[l].state;
}
}
}
SDL_PrivateMouseMotion(0, 0, current_req.mousex, current_req.mousey);
current_req_current = 0;
}
quinn_process_input();
}
void QUINN_InitOSKeymap(_THIS)
{
/* do nothing. */
memset(_k_last_state, 0, 256);
}
/* end of SDLK_nullevents.c ... */