source: trunk/src/platform/sdl/sdlinput.cpp @ 2811

Last change on this file since 2811 was 2811, checked in by benlitz, 6 years ago

build fix on non-SDL platforms

  • Property svn:keywords set to Id
File size: 20.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#if USE_SDL
16#   if HAVE_SDL_SDL_H
17#      include <SDL/SDL.h>
18#   else
19#      include <SDL.h>
20#   endif
21#endif
22
23#include "core.h"
24#include "sdlinput.h"
25
26#ifdef LOL_INPUT_V2
27#include "input/inputdevice_internal.h"
28#endif // LOL_INPUT_V2
29
30/* We force joystick polling because no events are received when
31 * there is no SDL display (eg. on the Raspberry Pi). */
32#define SDL_FORCE_POLL_JOYSTICK 1
33
34namespace lol
35{
36
37/*
38 * SDL Input implementation class
39 */
40
41class SdlInputData
42{
43    friend class SdlInput;
44
45private:
46    void Tick(float seconds);
47
48    static ivec2 GetMousePos();
49    static void SetMousePos(ivec2 position);
50
51#if USE_SDL
52# ifdef LOL_INPUT_V2
53    SdlInputData(int app_w, int app_h, int screen_w, int screen_h) :
54        m_prevmouse(ivec2(0)),
55        m_app_w((float)app_w),
56        m_app_h((float)app_h),
57        m_screen_w((float)screen_w),
58        m_screen_h((float)screen_h)
59    { }
60
61    Array<SDL_Joystick*, InputDeviceInternal*> m_joysticks;
62    InputDeviceInternal* m_mouse;
63    InputDeviceInternal* m_keyboard;
64    ivec2 m_prevmouse;
65    float m_app_w;
66    float m_app_h;
67    float m_screen_w;
68    float m_screen_h;
69    bool m_mousecapture;
70# else
71    Array<SDL_Joystick *, Stick *> m_joysticks;
72# endif // LOL_INPUT_V2
73#endif // USE_SDL
74};
75
76/*
77 * Public SdlInput class
78 */
79
80#ifdef LOL_INPUT_V2
81SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
82  : m_data(new SdlInputData(app_w, app_h, screen_w, screen_h))
83#else
84SdlInput::SdlInput()
85  : m_data(new SdlInputData())
86#endif
87{
88#if USE_SDL
89    /* Enable Unicode translation of keyboard events */
90    SDL_EnableUNICODE(1);
91
92    SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
93
94#   if !EMSCRIPTEN
95#       if SDL_FORCE_POLL_JOYSTICK
96    SDL_JoystickEventState(SDL_QUERY);
97#       else
98    SDL_JoystickEventState(SDL_ENABLE);
99#       endif
100
101#ifdef LOL_INPUT_V2
102    m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard();
103    m_data->m_mouse = InputDeviceInternal::CreateStandardMouse();
104#endif
105
106    /* Register all the joysticks we can find, and let the input
107     * system decide what it wants to track. */
108    for (int i = 0; i < SDL_NumJoysticks(); i++)
109    {
110        SDL_Joystick *sdlstick = SDL_JoystickOpen(i);
111
112        /* Blacklist some devices:
113         *  - HDAPS, it's not a real joystick.
114         *  - X360 controllers, Xinput handles them better since
115         *    it won't think there is only one trigger axis. */
116        char const *name = SDL_JoystickName(i);
117        if (strstr(name, "HDAPS")
118#       if USE_XINPUT
119             || strstr(name, "XBOX 360 For Windows")
120#       endif
121             || false)
122        {
123            SDL_JoystickClose(sdlstick);
124            continue;
125        }
126
127#       ifdef LOL_INPUT_V2
128        InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
129        for (int i = 0; i < SDL_JoystickNumAxes(sdlstick); ++i)
130            stick->AddAxis(String::Printf("Axis%d", i+1).C());
131        for (int i = 0; i < SDL_JoystickNumButtons(sdlstick); ++i)
132            stick->AddKey(String::Printf("Button%d", i+1).C());
133
134        m_data->m_joysticks.Push(sdlstick, stick);
135#       else // !LOL_INPUT_V2
136        Stick *stick = Input::CreateStick();
137        stick->SetAxisCount(SDL_JoystickNumAxes(sdlstick));
138        stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick));
139
140        /* It's possible to remap axes */
141        //stick->RemapAxis(4, 2);
142        //stick->RemapAxis(2, 4);
143
144        m_data->m_joysticks.Push(sdlstick, stick);
145#       endif
146    }
147#   endif
148#endif
149
150    m_gamegroup = GAMEGROUP_BEFORE;
151}
152
153SdlInput::~SdlInput()
154{
155#if USE_SDL && !EMSCRIPTEN
156    /* Unregister all the joysticks we added */
157    while (m_data->m_joysticks.Count())
158    {
159        SDL_JoystickClose(m_data->m_joysticks[0].m1);
160#       ifdef LOL_INPUT_V2
161        delete m_data->m_joysticks[0].m2;
162#       else
163        Input::DestroyStick(m_data->m_joysticks[0].m2);
164#       endif
165        m_data->m_joysticks.Remove(0);
166    }
167#endif
168    delete m_data;
169}
170
171void SdlInput::TickGame(float seconds)
172{
173    Entity::TickGame(seconds);
174
175#if !_WIN32
176    m_data->Tick(seconds);
177#endif
178}
179
180void SdlInput::TickDraw(float seconds)
181{
182    Entity::TickDraw(seconds);
183
184#if _WIN32
185    m_data->Tick(seconds);
186#endif
187}
188
189void SdlInputData::Tick(float seconds)
190{
191#if USE_SDL
192    /* Pump all joystick events because no event is coming to us. */
193#   if SDL_FORCE_POLL_JOYSTICK && !EMSCRIPTEN
194    SDL_JoystickUpdate();
195    for (int j = 0; j < m_joysticks.Count(); j++)
196    {
197#       ifdef LOL_INPUT_V2
198        for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
199            m_joysticks[j].m2->SetKey(i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0);
200        for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
201            m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
202#       else // !LOL_INPUT_V2
203        for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
204            m_joysticks[j].m2->SetButton(i, SDL_JoystickGetButton(m_joysticks[j].m1, i));
205        for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
206            m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
207
208#       endif
209    }
210#   endif
211
212    /* Handle keyboard and WM events */
213    SDL_Event event;
214    while (SDL_PollEvent(&event))
215    {
216        switch (event.type)
217        {
218        case SDL_QUIT:
219            Ticker::Shutdown();
220            break;
221#if 0
222        case SDL_KEYDOWN:
223            if (event.key.keysym.unicode)
224                fprintf(stderr, "%c (0x%04X)\n", event.key.keysym.unicode, event.key.keysym.unicode);
225            break;
226#endif
227        case SDL_MOUSEBUTTONDOWN:
228        case SDL_MOUSEBUTTONUP:
229        {
230#ifdef LOL_INPUT_V2
231            m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN);
232#else // !LOL_INPUT_V2
233            if (event.type == SDL_MOUSEBUTTONDOWN)
234                Input::SetMouseButton(event.button.button - 1);
235            else
236                Input::UnsetMouseButton(event.button.button - 1);
237#endif // LOL_INPUT_V2
238            break;
239        }
240
241#   if !SDL_FORCE_POLL_JOYSTICK
242#        ifdef LOL_INPUT_V2
243        case SDL_JOYAXISMOTION:
244            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
245            break;
246
247        case SDL_JOYBUTTONUP:
248        case SDL_JOYBUTTONDOWN:
249            m_joysticks[event.jbutton.which].m2->SetKey(event.jbutton.button, event.jbutton.state);
250            break;
251#        else // !LOL_INPUT_V2
252        case SDL_JOYAXISMOTION:
253            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
254            break;
255
256        case SDL_JOYBUTTONUP:
257        case SDL_JOYBUTTONDOWN:
258            m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state);
259            break;
260#        endif // LOL_INPUT_V2
261#   endif
262        }
263    }
264
265    /* Handle mouse input */
266    ivec2 mouse = SdlInputData::GetMousePos();
267#   ifdef LOL_INPUT_V2
268    if (InputDeviceInternal::GetMouseCapture() != m_mousecapture)
269    {
270        m_mousecapture = InputDeviceInternal::GetMouseCapture();
271        SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF);
272        //SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE);
273    }
274
275    if (mouse.x >= 0 && mouse.x < m_app_w && mouse.y >= 0 && mouse.y < m_app_h)
276    {
277        m_mouse->SetCursor(0, vec2((float)(mouse.x) / m_app_w, (float)(mouse.y) / m_app_h), mouse);
278        // Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
279        m_mouse->SetAxis(0, (float)(mouse.x - m_prevmouse.x) * 100.0f / m_screen_w);
280        m_mouse->SetAxis(1, (float)(mouse.y - m_prevmouse.y) * 100.0f / m_screen_h);
281    }
282
283    if (m_mousecapture)
284    {
285        mouse = ivec2((int)m_app_w / 2, (int)m_app_h / 2);
286        SdlInputData::SetMousePos(mouse);
287    }
288
289    m_prevmouse = mouse;
290
291#   else // !LOL_INPUT_V2
292    Input::SetMousePos(mouse);
293#       endif // LOL_INPUT_V2
294
295#   if SDL_VERSION_ATLEAST(1,3,0)
296    Uint8 *sdlstate = SDL_GetKeyboardState(nullptr);
297#   else
298    Uint8 *sdlstate = SDL_GetKeyState(nullptr);
299#   endif
300
301    int keyindex = 0;
302#       ifdef LOL_INPUT_V2
303#       define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0);
304#       if !defined SDLK_WORLD_0
305#        define KEY_DISABLE_WORLD
306#   endif // !SDLK_WORLD_0
307#       include "input/keys.h"
308#       undef KEY_FUNC
309#       else // !LOL_INPUT_V2
310
311    /* Send the whole keyboard state to the input system */
312    Array<uint8_t> &lolstate = Input::GetKeyboardState();
313
314    lolstate[Key::Unknown] = sdlstate[SDLK_UNKNOWN];
315    lolstate[Key::Backspace] = sdlstate[SDLK_BACKSPACE];
316    lolstate[Key::Tab] = sdlstate[SDLK_TAB];
317    lolstate[Key::Clear] = sdlstate[SDLK_CLEAR];
318    lolstate[Key::Return] = sdlstate[SDLK_RETURN];
319    lolstate[Key::Pause] = sdlstate[SDLK_PAUSE];
320    lolstate[Key::Escape] = sdlstate[SDLK_ESCAPE];
321    lolstate[Key::Space] = sdlstate[SDLK_SPACE];
322    lolstate[Key::Exclaim] = sdlstate[SDLK_EXCLAIM];
323    lolstate[Key::DoubleQuote] = sdlstate[SDLK_QUOTEDBL];
324    lolstate[Key::Hash] = sdlstate[SDLK_HASH];
325    lolstate[Key::Dollar] = sdlstate[SDLK_DOLLAR];
326    lolstate[Key::Ampersand] = sdlstate[SDLK_AMPERSAND];
327    lolstate[Key::Quote] = sdlstate[SDLK_QUOTE];
328    lolstate[Key::LeftParen] = sdlstate[SDLK_LEFTPAREN];
329    lolstate[Key::RightParen] = sdlstate[SDLK_RIGHTPAREN];
330    lolstate[Key::Asterisk] = sdlstate[SDLK_ASTERISK];
331    lolstate[Key::Plus] = sdlstate[SDLK_PLUS];
332    lolstate[Key::Comma] = sdlstate[SDLK_COMMA];
333    lolstate[Key::Minus] = sdlstate[SDLK_MINUS];
334    lolstate[Key::Period] = sdlstate[SDLK_PERIOD];
335    lolstate[Key::Slash] = sdlstate[SDLK_SLASH];
336    lolstate[Key::K0] = sdlstate[SDLK_0];
337    lolstate[Key::K1] = sdlstate[SDLK_1];
338    lolstate[Key::K2] = sdlstate[SDLK_2];
339    lolstate[Key::K3] = sdlstate[SDLK_3];
340    lolstate[Key::K4] = sdlstate[SDLK_4];
341    lolstate[Key::K5] = sdlstate[SDLK_5];
342    lolstate[Key::K6] = sdlstate[SDLK_6];
343    lolstate[Key::K7] = sdlstate[SDLK_7];
344    lolstate[Key::K8] = sdlstate[SDLK_8];
345    lolstate[Key::K9] = sdlstate[SDLK_9];
346    lolstate[Key::Colon] = sdlstate[SDLK_COLON];
347    lolstate[Key::Semicolon] = sdlstate[SDLK_SEMICOLON];
348    lolstate[Key::Less] = sdlstate[SDLK_LESS];
349    lolstate[Key::Equals] = sdlstate[SDLK_EQUALS];
350    lolstate[Key::Greater] = sdlstate[SDLK_GREATER];
351    lolstate[Key::Question] = sdlstate[SDLK_QUESTION];
352    lolstate[Key::At] = sdlstate[SDLK_AT];
353
354    lolstate[Key::LeftBracket] = sdlstate[SDLK_LEFTBRACKET];
355    lolstate[Key::BackSlash] = sdlstate[SDLK_BACKSLASH];
356    lolstate[Key::RightBracket] = sdlstate[SDLK_RIGHTBRACKET];
357    lolstate[Key::Caret] = sdlstate[SDLK_CARET];
358    lolstate[Key::Underscore] = sdlstate[SDLK_UNDERSCORE];
359    lolstate[Key::Backquote] = sdlstate[SDLK_BACKQUOTE];
360    lolstate[Key::A] = sdlstate[SDLK_a];
361    lolstate[Key::B] = sdlstate[SDLK_b];
362    lolstate[Key::C] = sdlstate[SDLK_c];
363    lolstate[Key::D] = sdlstate[SDLK_d];
364    lolstate[Key::E] = sdlstate[SDLK_e];
365    lolstate[Key::F] = sdlstate[SDLK_f];
366    lolstate[Key::G] = sdlstate[SDLK_g];
367    lolstate[Key::H] = sdlstate[SDLK_h];
368    lolstate[Key::I] = sdlstate[SDLK_i];
369    lolstate[Key::J] = sdlstate[SDLK_j];
370    lolstate[Key::K] = sdlstate[SDLK_k];
371    lolstate[Key::L] = sdlstate[SDLK_l];
372    lolstate[Key::M] = sdlstate[SDLK_m];
373    lolstate[Key::N] = sdlstate[SDLK_n];
374    lolstate[Key::O] = sdlstate[SDLK_o];
375    lolstate[Key::P] = sdlstate[SDLK_p];
376    lolstate[Key::Q] = sdlstate[SDLK_q];
377    lolstate[Key::R] = sdlstate[SDLK_r];
378    lolstate[Key::S] = sdlstate[SDLK_s];
379    lolstate[Key::T] = sdlstate[SDLK_t];
380    lolstate[Key::U] = sdlstate[SDLK_u];
381    lolstate[Key::V] = sdlstate[SDLK_v];
382    lolstate[Key::W] = sdlstate[SDLK_w];
383    lolstate[Key::X] = sdlstate[SDLK_x];
384    lolstate[Key::Y] = sdlstate[SDLK_y];
385    lolstate[Key::Z] = sdlstate[SDLK_z];
386    lolstate[Key::Delete] = sdlstate[SDLK_DELETE];
387
388#if SDLK_WORLD_0
389    lolstate[Key::World0] = sdlstate[SDLK_WORLD_0];
390    lolstate[Key::World1] = sdlstate[SDLK_WORLD_1];
391    lolstate[Key::World2] = sdlstate[SDLK_WORLD_2];
392    lolstate[Key::World3] = sdlstate[SDLK_WORLD_3];
393    lolstate[Key::World4] = sdlstate[SDLK_WORLD_4];
394    lolstate[Key::World5] = sdlstate[SDLK_WORLD_5];
395    lolstate[Key::World6] = sdlstate[SDLK_WORLD_6];
396    lolstate[Key::World7] = sdlstate[SDLK_WORLD_7];
397    lolstate[Key::World8] = sdlstate[SDLK_WORLD_8];
398    lolstate[Key::World9] = sdlstate[SDLK_WORLD_9];
399    lolstate[Key::World10] = sdlstate[SDLK_WORLD_10];
400    lolstate[Key::World11] = sdlstate[SDLK_WORLD_11];
401    lolstate[Key::World12] = sdlstate[SDLK_WORLD_12];
402    lolstate[Key::World13] = sdlstate[SDLK_WORLD_13];
403    lolstate[Key::World14] = sdlstate[SDLK_WORLD_14];
404    lolstate[Key::World15] = sdlstate[SDLK_WORLD_15];
405    lolstate[Key::World16] = sdlstate[SDLK_WORLD_16];
406    lolstate[Key::World17] = sdlstate[SDLK_WORLD_17];
407    lolstate[Key::World18] = sdlstate[SDLK_WORLD_18];
408    lolstate[Key::World19] = sdlstate[SDLK_WORLD_19];
409    lolstate[Key::World20] = sdlstate[SDLK_WORLD_20];
410    lolstate[Key::World21] = sdlstate[SDLK_WORLD_21];
411    lolstate[Key::World22] = sdlstate[SDLK_WORLD_22];
412    lolstate[Key::World23] = sdlstate[SDLK_WORLD_23];
413    lolstate[Key::World24] = sdlstate[SDLK_WORLD_24];
414    lolstate[Key::World25] = sdlstate[SDLK_WORLD_25];
415    lolstate[Key::World26] = sdlstate[SDLK_WORLD_26];
416    lolstate[Key::World27] = sdlstate[SDLK_WORLD_27];
417    lolstate[Key::World28] = sdlstate[SDLK_WORLD_28];
418    lolstate[Key::World29] = sdlstate[SDLK_WORLD_29];
419    lolstate[Key::World30] = sdlstate[SDLK_WORLD_30];
420    lolstate[Key::World31] = sdlstate[SDLK_WORLD_31];
421    lolstate[Key::World32] = sdlstate[SDLK_WORLD_32];
422    lolstate[Key::World33] = sdlstate[SDLK_WORLD_33];
423    lolstate[Key::World34] = sdlstate[SDLK_WORLD_34];
424    lolstate[Key::World35] = sdlstate[SDLK_WORLD_35];
425    lolstate[Key::World36] = sdlstate[SDLK_WORLD_36];
426    lolstate[Key::World37] = sdlstate[SDLK_WORLD_37];
427    lolstate[Key::World38] = sdlstate[SDLK_WORLD_38];
428    lolstate[Key::World39] = sdlstate[SDLK_WORLD_39];
429    lolstate[Key::World40] = sdlstate[SDLK_WORLD_40];
430    lolstate[Key::World41] = sdlstate[SDLK_WORLD_41];
431    lolstate[Key::World42] = sdlstate[SDLK_WORLD_42];
432    lolstate[Key::World43] = sdlstate[SDLK_WORLD_43];
433    lolstate[Key::World44] = sdlstate[SDLK_WORLD_44];
434    lolstate[Key::World45] = sdlstate[SDLK_WORLD_45];
435    lolstate[Key::World46] = sdlstate[SDLK_WORLD_46];
436    lolstate[Key::World47] = sdlstate[SDLK_WORLD_47];
437    lolstate[Key::World48] = sdlstate[SDLK_WORLD_48];
438    lolstate[Key::World49] = sdlstate[SDLK_WORLD_49];
439    lolstate[Key::World50] = sdlstate[SDLK_WORLD_50];
440    lolstate[Key::World51] = sdlstate[SDLK_WORLD_51];
441    lolstate[Key::World52] = sdlstate[SDLK_WORLD_52];
442    lolstate[Key::World53] = sdlstate[SDLK_WORLD_53];
443    lolstate[Key::World54] = sdlstate[SDLK_WORLD_54];
444    lolstate[Key::World55] = sdlstate[SDLK_WORLD_55];
445    lolstate[Key::World56] = sdlstate[SDLK_WORLD_56];
446    lolstate[Key::World57] = sdlstate[SDLK_WORLD_57];
447    lolstate[Key::World58] = sdlstate[SDLK_WORLD_58];
448    lolstate[Key::World59] = sdlstate[SDLK_WORLD_59];
449    lolstate[Key::World60] = sdlstate[SDLK_WORLD_60];
450    lolstate[Key::World61] = sdlstate[SDLK_WORLD_61];
451    lolstate[Key::World62] = sdlstate[SDLK_WORLD_62];
452    lolstate[Key::World63] = sdlstate[SDLK_WORLD_63];
453    lolstate[Key::World64] = sdlstate[SDLK_WORLD_64];
454    lolstate[Key::World65] = sdlstate[SDLK_WORLD_65];
455    lolstate[Key::World66] = sdlstate[SDLK_WORLD_66];
456    lolstate[Key::World67] = sdlstate[SDLK_WORLD_67];
457    lolstate[Key::World68] = sdlstate[SDLK_WORLD_68];
458    lolstate[Key::World69] = sdlstate[SDLK_WORLD_69];
459    lolstate[Key::World70] = sdlstate[SDLK_WORLD_70];
460    lolstate[Key::World71] = sdlstate[SDLK_WORLD_71];
461    lolstate[Key::World72] = sdlstate[SDLK_WORLD_72];
462    lolstate[Key::World73] = sdlstate[SDLK_WORLD_73];
463    lolstate[Key::World74] = sdlstate[SDLK_WORLD_74];
464    lolstate[Key::World75] = sdlstate[SDLK_WORLD_75];
465    lolstate[Key::World76] = sdlstate[SDLK_WORLD_76];
466    lolstate[Key::World77] = sdlstate[SDLK_WORLD_77];
467    lolstate[Key::World78] = sdlstate[SDLK_WORLD_78];
468    lolstate[Key::World79] = sdlstate[SDLK_WORLD_79];
469    lolstate[Key::World80] = sdlstate[SDLK_WORLD_80];
470    lolstate[Key::World81] = sdlstate[SDLK_WORLD_81];
471    lolstate[Key::World82] = sdlstate[SDLK_WORLD_82];
472    lolstate[Key::World83] = sdlstate[SDLK_WORLD_83];
473    lolstate[Key::World84] = sdlstate[SDLK_WORLD_84];
474    lolstate[Key::World85] = sdlstate[SDLK_WORLD_85];
475    lolstate[Key::World86] = sdlstate[SDLK_WORLD_86];
476    lolstate[Key::World87] = sdlstate[SDLK_WORLD_87];
477    lolstate[Key::World88] = sdlstate[SDLK_WORLD_88];
478    lolstate[Key::World89] = sdlstate[SDLK_WORLD_89];
479    lolstate[Key::World90] = sdlstate[SDLK_WORLD_90];
480    lolstate[Key::World91] = sdlstate[SDLK_WORLD_91];
481    lolstate[Key::World92] = sdlstate[SDLK_WORLD_92];
482    lolstate[Key::World93] = sdlstate[SDLK_WORLD_93];
483    lolstate[Key::World94] = sdlstate[SDLK_WORLD_94];
484    lolstate[Key::World95] = sdlstate[SDLK_WORLD_95];
485#endif // SDLK_WORLD_0
486
487    lolstate[Key::KP0] = sdlstate[SDLK_KP0];
488    lolstate[Key::KP1] = sdlstate[SDLK_KP1];
489    lolstate[Key::KP2] = sdlstate[SDLK_KP2];
490    lolstate[Key::KP3] = sdlstate[SDLK_KP3];
491    lolstate[Key::KP4] = sdlstate[SDLK_KP4];
492    lolstate[Key::KP5] = sdlstate[SDLK_KP5];
493    lolstate[Key::KP6] = sdlstate[SDLK_KP6];
494    lolstate[Key::KP7] = sdlstate[SDLK_KP7];
495    lolstate[Key::KP8] = sdlstate[SDLK_KP8];
496    lolstate[Key::KP9] = sdlstate[SDLK_KP9];
497    lolstate[Key::KPPeriod] = sdlstate[SDLK_KP_PERIOD];
498    lolstate[Key::KPDivide] = sdlstate[SDLK_KP_DIVIDE];
499    lolstate[Key::KPMultiply] = sdlstate[SDLK_KP_MULTIPLY];
500    lolstate[Key::KPMinus] = sdlstate[SDLK_KP_MINUS];
501    lolstate[Key::KPPlus] = sdlstate[SDLK_KP_PLUS];
502    lolstate[Key::KPEnter] = sdlstate[SDLK_KP_ENTER];
503    lolstate[Key::KPEquals] = sdlstate[SDLK_KP_EQUALS];
504
505    lolstate[Key::Up] = sdlstate[SDLK_UP];
506    lolstate[Key::Down] = sdlstate[SDLK_DOWN];
507    lolstate[Key::Right] = sdlstate[SDLK_RIGHT];
508    lolstate[Key::Left] = sdlstate[SDLK_LEFT];
509    lolstate[Key::Insert] = sdlstate[SDLK_INSERT];
510    lolstate[Key::Home] = sdlstate[SDLK_HOME];
511    lolstate[Key::End] = sdlstate[SDLK_END];
512    lolstate[Key::PageUp] = sdlstate[SDLK_PAGEUP];
513    lolstate[Key::PageDown] = sdlstate[SDLK_PAGEDOWN];
514
515    lolstate[Key::F1] = sdlstate[SDLK_F1];
516    lolstate[Key::F2] = sdlstate[SDLK_F2];
517    lolstate[Key::F3] = sdlstate[SDLK_F3];
518    lolstate[Key::F4] = sdlstate[SDLK_F4];
519    lolstate[Key::F5] = sdlstate[SDLK_F5];
520    lolstate[Key::F6] = sdlstate[SDLK_F6];
521    lolstate[Key::F7] = sdlstate[SDLK_F7];
522    lolstate[Key::F8] = sdlstate[SDLK_F8];
523    lolstate[Key::F9] = sdlstate[SDLK_F9];
524    lolstate[Key::F10] = sdlstate[SDLK_F10];
525    lolstate[Key::F11] = sdlstate[SDLK_F11];
526    lolstate[Key::F12] = sdlstate[SDLK_F12];
527    lolstate[Key::F13] = sdlstate[SDLK_F13];
528    lolstate[Key::F14] = sdlstate[SDLK_F14];
529    lolstate[Key::F15] = sdlstate[SDLK_F15];
530
531    lolstate[Key::NumLock] = sdlstate[SDLK_NUMLOCK];
532    lolstate[Key::CapsLock] = sdlstate[SDLK_CAPSLOCK];
533    lolstate[Key::ScrollLock] = sdlstate[SDLK_SCROLLOCK];
534    lolstate[Key::RightShift] = sdlstate[SDLK_RSHIFT];
535    lolstate[Key::LeftShift] = sdlstate[SDLK_LSHIFT];
536    lolstate[Key::RightCtrl] = sdlstate[SDLK_RCTRL];
537    lolstate[Key::LeftCtrl] = sdlstate[SDLK_LCTRL];
538    lolstate[Key::RightAlt] = sdlstate[SDLK_RALT];
539    lolstate[Key::LeftAlt] = sdlstate[SDLK_LALT];
540    lolstate[Key::RightMeta] = sdlstate[SDLK_RMETA];
541    lolstate[Key::LeftMeta] = sdlstate[SDLK_LMETA];
542    lolstate[Key::LeftSuper] = sdlstate[SDLK_LSUPER];
543    lolstate[Key::RightSuper] = sdlstate[SDLK_RSUPER];
544    lolstate[Key::Mode] = sdlstate[SDLK_MODE];
545    lolstate[Key::Compose] = sdlstate[SDLK_COMPOSE];
546
547    lolstate[Key::Help] = sdlstate[SDLK_HELP];
548    lolstate[Key::Print] = sdlstate[SDLK_PRINT];
549    lolstate[Key::SysReq] = sdlstate[SDLK_SYSREQ];
550    lolstate[Key::Break] = sdlstate[SDLK_BREAK];
551    lolstate[Key::Menu] = sdlstate[SDLK_MENU];
552    lolstate[Key::Power] = sdlstate[SDLK_POWER];
553    lolstate[Key::Euro] = sdlstate[SDLK_EURO];
554    lolstate[Key::Undo] = sdlstate[SDLK_UNDO];
555
556    UNUSED(seconds);
557#       endif // LOL_INPUT_V2
558
559#endif // USE_SDL
560}
561
562// NOTE: these two functions are pointless now and could be inlined directly
563ivec2 SdlInputData::GetMousePos()
564{
565    ivec2 ret(-1, -1);
566
567#if USE_SDL
568#   if !EMSCRIPTEN
569    if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
570#   endif
571    {
572        SDL_GetMouseState(&ret.x, &ret.y);
573        ret.y = Video::GetSize().y - 1 - ret.y;
574    }
575#endif
576    return ret;
577}
578
579void SdlInputData::SetMousePos(ivec2 position)
580{
581#if USE_SDL
582    SDL_WarpMouse((uint16_t)position.x, (uint16_t)position.y);
583#endif
584}
585
586} /* namespace lol */
587
Note: See TracBrowser for help on using the repository browser.