src/video/haiku/SDL_bkeyboard.cc
changeset 7981 6d538bc1b395
parent 6885 700f1b25f77f
child 8093 b43765095a6f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/haiku/SDL_bkeyboard.cc	Thu Nov 14 11:51:24 2013 -0500
     1.3 @@ -0,0 +1,188 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_HAIKU
    1.27 +
    1.28 +#include <SupportDefs.h>
    1.29 +#include <support/UTF8.h>
    1.30 +
    1.31 +#ifdef __cplusplus
    1.32 +extern "C" {
    1.33 +#endif
    1.34 +
    1.35 +#include "SDL_events.h"
    1.36 +#include "SDL_keycode.h"
    1.37 +
    1.38 +#include "SDL_bkeyboard.h"
    1.39 +
    1.40 +
    1.41 +#define KEYMAP_SIZE 128
    1.42 +
    1.43 +
    1.44 +static SDL_Scancode keymap[KEYMAP_SIZE];
    1.45 +static int8 keystate[KEYMAP_SIZE];
    1.46 +
    1.47 +void BE_InitOSKeymap() {
    1.48 +		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
    1.49 +			keymap[i] = SDL_SCANCODE_UNKNOWN;
    1.50 +		}
    1.51 +
    1.52 +		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
    1.53 +			keystate[i] = SDL_RELEASED;
    1.54 +		}
    1.55 +
    1.56 +		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
    1.57 +		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
    1.58 +		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
    1.59 +		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
    1.60 +		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
    1.61 +		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
    1.62 +		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
    1.63 +		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
    1.64 +		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
    1.65 +		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
    1.66 +		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
    1.67 +		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
    1.68 +		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
    1.69 +		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
    1.70 +		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
    1.71 +		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
    1.72 +		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
    1.73 +		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
    1.74 +		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
    1.75 +		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
    1.76 +		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
    1.77 +		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
    1.78 +		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
    1.79 +		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
    1.80 +		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
    1.81 +		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
    1.82 +		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
    1.83 +		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
    1.84 +		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
    1.85 +		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
    1.86 +		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
    1.87 +		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
    1.88 +		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
    1.89 +		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
    1.90 +		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
    1.91 +		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
    1.92 +		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
    1.93 +		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
    1.94 +		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
    1.95 +		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
    1.96 +		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
    1.97 +		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
    1.98 +		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
    1.99 +		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
   1.100 +		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
   1.101 +		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
   1.102 +		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
   1.103 +		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
   1.104 +		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
   1.105 +		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
   1.106 +		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
   1.107 +		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
   1.108 +		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
   1.109 +		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
   1.110 +		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
   1.111 +		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
   1.112 +		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
   1.113 +		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
   1.114 +		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
   1.115 +		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
   1.116 +		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
   1.117 +		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
   1.118 +		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
   1.119 +		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
   1.120 +		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
   1.121 +		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
   1.122 +		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
   1.123 +		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
   1.124 +		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
   1.125 +		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
   1.126 +		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
   1.127 +		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
   1.128 +		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
   1.129 +		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
   1.130 +		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
   1.131 +		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
   1.132 +		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
   1.133 +		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
   1.134 +		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
   1.135 +		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
   1.136 +		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
   1.137 +		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
   1.138 +		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
   1.139 +		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
   1.140 +		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
   1.141 +		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
   1.142 +		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
   1.143 +		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
   1.144 +		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
   1.145 +		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
   1.146 +		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
   1.147 +		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
   1.148 +		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
   1.149 +		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
   1.150 +		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
   1.151 +		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
   1.152 +		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
   1.153 +		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
   1.154 +		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
   1.155 +		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
   1.156 +		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
   1.157 +		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
   1.158 +		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
   1.159 +		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
   1.160 +		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
   1.161 +		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
   1.162 +		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
   1.163 +}
   1.164 +
   1.165 +SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
   1.166 +	if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
   1.167 +		return keymap[bkey];
   1.168 +	} else {
   1.169 +		return SDL_SCANCODE_UNKNOWN;
   1.170 +	}
   1.171 +}
   1.172 +
   1.173 +int8 BE_GetKeyState(int32 bkey) {
   1.174 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
   1.175 +		return keystate[bkey];
   1.176 +	} else {
   1.177 +		return SDL_RELEASED;
   1.178 +	}
   1.179 +}
   1.180 +
   1.181 +void BE_SetKeyState(int32 bkey, int8 state) {
   1.182 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
   1.183 +		keystate[bkey] = state;
   1.184 +	}
   1.185 +}
   1.186 +
   1.187 +#ifdef __cplusplus
   1.188 +}
   1.189 +#endif
   1.190 +
   1.191 +#endif /* SDL_VIDEO_DRIVER_HAIKU */