85
virtual void InitKeyboard(void) {
86
for ( uint i=0; i<SDL_TABLESIZE(keymap); ++i )
87
keymap[i] = SDLK_UNKNOWN;
89
keymap[0x01] = SDLK_ESCAPE;
90
keymap[B_F1_KEY] = SDLK_F1;
91
keymap[B_F2_KEY] = SDLK_F2;
92
keymap[B_F3_KEY] = SDLK_F3;
93
keymap[B_F4_KEY] = SDLK_F4;
94
keymap[B_F5_KEY] = SDLK_F5;
95
keymap[B_F6_KEY] = SDLK_F6;
96
keymap[B_F7_KEY] = SDLK_F7;
97
keymap[B_F8_KEY] = SDLK_F8;
98
keymap[B_F9_KEY] = SDLK_F9;
99
keymap[B_F10_KEY] = SDLK_F10;
100
keymap[B_F11_KEY] = SDLK_F11;
101
keymap[B_F12_KEY] = SDLK_F12;
102
keymap[B_PRINT_KEY] = SDLK_PRINT;
103
keymap[B_SCROLL_KEY] = SDLK_SCROLLOCK;
104
keymap[B_PAUSE_KEY] = SDLK_PAUSE;
105
keymap[0x11] = SDLK_BACKQUOTE;
106
keymap[0x12] = SDLK_1;
107
keymap[0x13] = SDLK_2;
108
keymap[0x14] = SDLK_3;
109
keymap[0x15] = SDLK_4;
110
keymap[0x16] = SDLK_5;
111
keymap[0x17] = SDLK_6;
112
keymap[0x18] = SDLK_7;
113
keymap[0x19] = SDLK_8;
114
keymap[0x1a] = SDLK_9;
115
keymap[0x1b] = SDLK_0;
116
keymap[0x1c] = SDLK_MINUS;
117
keymap[0x1d] = SDLK_EQUALS;
118
keymap[0x1e] = SDLK_BACKSPACE;
119
keymap[0x1f] = SDLK_INSERT;
120
keymap[0x20] = SDLK_HOME;
121
keymap[0x21] = SDLK_PAGEUP;
122
keymap[0x22] = SDLK_NUMLOCK;
123
keymap[0x23] = SDLK_KP_DIVIDE;
124
keymap[0x24] = SDLK_KP_MULTIPLY;
125
keymap[0x25] = SDLK_KP_MINUS;
126
keymap[0x26] = SDLK_TAB;
127
keymap[0x27] = SDLK_q;
128
keymap[0x28] = SDLK_w;
129
keymap[0x29] = SDLK_e;
130
keymap[0x2a] = SDLK_r;
131
keymap[0x2b] = SDLK_t;
132
keymap[0x2c] = SDLK_y;
133
keymap[0x2d] = SDLK_u;
134
keymap[0x2e] = SDLK_i;
135
keymap[0x2f] = SDLK_o;
136
keymap[0x30] = SDLK_p;
137
keymap[0x31] = SDLK_LEFTBRACKET;
138
keymap[0x32] = SDLK_RIGHTBRACKET;
139
keymap[0x33] = SDLK_BACKSLASH;
140
keymap[0x34] = SDLK_DELETE;
141
keymap[0x35] = SDLK_END;
142
keymap[0x36] = SDLK_PAGEDOWN;
143
keymap[0x37] = SDLK_KP7;
144
keymap[0x38] = SDLK_KP8;
145
keymap[0x39] = SDLK_KP9;
146
keymap[0x3a] = SDLK_KP_PLUS;
147
keymap[0x3b] = SDLK_CAPSLOCK;
148
keymap[0x3c] = SDLK_a;
149
keymap[0x3d] = SDLK_s;
150
keymap[0x3e] = SDLK_d;
151
keymap[0x3f] = SDLK_f;
152
keymap[0x40] = SDLK_g;
153
keymap[0x41] = SDLK_h;
154
keymap[0x42] = SDLK_j;
155
keymap[0x43] = SDLK_k;
156
keymap[0x44] = SDLK_l;
157
keymap[0x45] = SDLK_SEMICOLON;
158
keymap[0x46] = SDLK_QUOTE;
159
keymap[0x47] = SDLK_RETURN;
160
keymap[0x48] = SDLK_KP4;
161
keymap[0x49] = SDLK_KP5;
162
keymap[0x4a] = SDLK_KP6;
163
keymap[0x4b] = SDLK_LSHIFT;
164
keymap[0x4c] = SDLK_z;
165
keymap[0x4d] = SDLK_x;
166
keymap[0x4e] = SDLK_c;
167
keymap[0x4f] = SDLK_v;
168
keymap[0x50] = SDLK_b;
169
keymap[0x51] = SDLK_n;
170
keymap[0x52] = SDLK_m;
171
keymap[0x53] = SDLK_COMMA;
172
keymap[0x54] = SDLK_PERIOD;
173
keymap[0x55] = SDLK_SLASH;
174
keymap[0x56] = SDLK_RSHIFT;
175
keymap[0x57] = SDLK_UP;
176
keymap[0x58] = SDLK_KP1;
177
keymap[0x59] = SDLK_KP2;
178
keymap[0x5a] = SDLK_KP3;
179
keymap[0x5b] = SDLK_KP_ENTER;
180
keymap[0x5c] = SDLK_LCTRL;
181
keymap[0x5d] = SDLK_LALT;
182
keymap[0x5e] = SDLK_SPACE;
183
keymap[0x5f] = SDLK_RALT;
184
keymap[0x60] = SDLK_RCTRL;
185
keymap[0x61] = SDLK_LEFT;
186
keymap[0x62] = SDLK_DOWN;
187
keymap[0x63] = SDLK_RIGHT;
188
keymap[0x64] = SDLK_KP0;
189
keymap[0x65] = SDLK_KP_PERIOD;
190
keymap[0x66] = SDLK_LMETA;
191
keymap[0x67] = SDLK_RMETA;
192
keymap[0x68] = SDLK_MENU;
193
keymap[0x69] = SDLK_EURO;
194
keymap[0x6a] = SDLK_KP_EQUALS;
195
keymap[0x6b] = SDLK_POWER;
198
86
/* Override the Show() method so we can tell when we've been shown */
199
87
virtual void Show(void) {
370
virtual void DispatchMessage(BMessage *msg, BHandler *target) {
376
if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
377
if (transit == B_EXITED_VIEW) {
378
if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
379
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
380
be_app->SetCursor(B_HAND_CURSOR);
384
if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
385
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
389
x = (int)where.x - x;
390
y = (int)where.y - y;
391
SDL_PrivateMouseMotion(0, 0, x, y);
399
/* it looks like mouse down is send only for first clicked
400
button, each next is not send while last one is holded */
403
if (msg->FindInt32("buttons", &buttons) == B_OK) {
404
/* Add any mouse button events */
405
if (buttons & B_PRIMARY_MOUSE_BUTTON) {
406
sdl_buttons |= SDL_BUTTON_LEFT;
408
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
409
sdl_buttons |= SDL_BUTTON_RIGHT;
411
if (buttons & B_TERTIARY_MOUSE_BUTTON) {
412
sdl_buttons |= SDL_BUTTON_MIDDLE;
414
SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
416
last_buttons = buttons;
423
/* mouse up doesn't give which button was released,
424
only state of buttons (after release, so it's always = 0),
425
which is not what we need ;]
426
So we need to store button in mouse down, and restore
428
mouse up is (similarly to mouse down) send only for
429
first button down (ie. it's no send if we click another button
430
without releasing previous one first) - but that's probably
431
because of how drivers are written?, not BeOS itself. */
434
if (msg->FindInt32("buttons", &buttons) == B_OK) {
435
/* Add any mouse button events */
436
if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
437
sdl_buttons |= SDL_BUTTON_LEFT;
439
if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
440
sdl_buttons |= SDL_BUTTON_RIGHT;
442
if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
443
sdl_buttons |= SDL_BUTTON_MIDDLE;
445
SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
447
last_buttons = buttons;
452
case B_MOUSE_WHEEL_CHANGED:
456
if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
457
if (x < 0 || y < 0) {
458
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
459
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
460
} else if (x > 0 || y > 0) {
461
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
462
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
469
case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
474
/* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
475
if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK && key_repeat > 0)
478
if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
480
keysym.scancode = key;
481
if ((key > 0) && (key < 128)) {
482
keysym.sym = keymap[key];
484
keysym.sym = SDLK_UNKNOWN;
487
it seems SDL_PrivateKeyboard() changes mod value
488
anyway, and doesn't care about what we setup here */
489
keysym.mod = KMOD_NONE;
491
if (SDL_TranslateUNICODE) {
493
if (msg->FindString("bytes", &bytes) == B_OK) {
495
this cares only about first "letter",
496
so if someone maps some key to print
497
"BeOS rulez!" only "B" will be used. */
498
keysym.unicode = Translate2Unicode(bytes);
501
SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
507
case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
511
if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
513
keysym.scancode = key;
514
if ((key > 0) && (key < 128)) {
515
keysym.sym = keymap[key];
517
keysym.sym = SDLK_UNKNOWN;
519
keysym.mod = KMOD_NONE; /* FIX THIS? */
521
if (SDL_TranslateUNICODE) {
523
if (msg->FindString("bytes", &bytes) == B_OK) {
524
keysym.unicode = Translate2Unicode(bytes);
527
SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
533
/* move it after switch{} so it's always handled
534
that way we keep BeOS feautures like:
535
- CTRL+Q to close window (and other shortcuts)
536
- PrintScreen to make screenshot into /boot/home
538
//BDirectWindow::DispatchMessage(msg, target);
541
BDirectWindow::DispatchMessage(msg, target);
269
virtual void DispatchMessage(BMessage *msg, BHandler *target);
545
272
#if SDL_VIDEO_OPENGL