imported Löve GLES branch (changeset 1ba9037e558b)

This commit is contained in:
Martin Felis
2013-12-05 18:05:13 +01:00
parent 41b2db04a7
commit 2644d1ee18
615 changed files with 150300 additions and 0 deletions
+238
View File
@@ -0,0 +1,238 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "common/config.h"
#include "Keyboard.h"
namespace love
{
namespace keyboard
{
bool Keyboard::getConstant(const char *in, Keyboard::Key &out)
{
return keys.find(in, out);
}
bool Keyboard::getConstant(Keyboard::Key in, const char *&out)
{
return keys.find(in, out);
}
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
{
{"return", Keyboard::KEY_RETURN},
{"escape", Keyboard::KEY_ESCAPE},
{"backspace", Keyboard::KEY_BACKSPACE},
{"tab", Keyboard::KEY_TAB},
{" ", Keyboard::KEY_SPACE},
{"!", Keyboard::KEY_EXCLAIM},
{"\"", Keyboard::KEY_QUOTEDBL},
{"#", Keyboard::KEY_HASH},
{"$", Keyboard::KEY_DOLLAR},
{"&", Keyboard::KEY_AMPERSAND},
{"'", Keyboard::KEY_QUOTE},
{"(", Keyboard::KEY_LEFTPAREN},
{")", Keyboard::KEY_RIGHTPAREN},
{"*", Keyboard::KEY_ASTERISK},
{"+", Keyboard::KEY_PLUS},
{",", Keyboard::KEY_COMMA},
{"-", Keyboard::KEY_MINUS},
{".", Keyboard::KEY_PERIOD},
{"/", Keyboard::KEY_SLASH},
{"0", Keyboard::KEY_0},
{"1", Keyboard::KEY_1},
{"2", Keyboard::KEY_2},
{"3", Keyboard::KEY_3},
{"4", Keyboard::KEY_4},
{"5", Keyboard::KEY_5},
{"6", Keyboard::KEY_6},
{"7", Keyboard::KEY_7},
{"8", Keyboard::KEY_8},
{"9", Keyboard::KEY_9},
{":", Keyboard::KEY_COLON},
{";", Keyboard::KEY_SEMICOLON},
{"<", Keyboard::KEY_LESS},
{"=", Keyboard::KEY_EQUALS},
{">", Keyboard::KEY_GREATER},
{"?", Keyboard::KEY_QUESTION},
{"@", Keyboard::KEY_AT},
{"[", Keyboard::KEY_LEFTBRACKET},
{"\\", Keyboard::KEY_BACKSLASH},
{"]", Keyboard::KEY_RIGHTBRACKET},
{"^", Keyboard::KEY_CARET},
{"_", Keyboard::KEY_UNDERSCORE},
{"`", Keyboard::KEY_BACKQUOTE},
{"a", Keyboard::KEY_A},
{"b", Keyboard::KEY_B},
{"c", Keyboard::KEY_C},
{"d", Keyboard::KEY_D},
{"e", Keyboard::KEY_E},
{"f", Keyboard::KEY_F},
{"g", Keyboard::KEY_G},
{"h", Keyboard::KEY_H},
{"i", Keyboard::KEY_I},
{"j", Keyboard::KEY_J},
{"k", Keyboard::KEY_K},
{"l", Keyboard::KEY_L},
{"m", Keyboard::KEY_M},
{"n", Keyboard::KEY_N},
{"o", Keyboard::KEY_O},
{"p", Keyboard::KEY_P},
{"q", Keyboard::KEY_Q},
{"r", Keyboard::KEY_R},
{"s", Keyboard::KEY_S},
{"t", Keyboard::KEY_T},
{"u", Keyboard::KEY_U},
{"v", Keyboard::KEY_V},
{"w", Keyboard::KEY_W},
{"x", Keyboard::KEY_X},
{"y", Keyboard::KEY_Y},
{"z", Keyboard::KEY_Z},
{"capslock", Keyboard::KEY_CAPSLOCK},
{"f1", Keyboard::KEY_F1},
{"f2", Keyboard::KEY_F2},
{"f3", Keyboard::KEY_F3},
{"f4", Keyboard::KEY_F4},
{"f5", Keyboard::KEY_F5},
{"f6", Keyboard::KEY_F6},
{"f7", Keyboard::KEY_F7},
{"f8", Keyboard::KEY_F8},
{"f9", Keyboard::KEY_F9},
{"f10", Keyboard::KEY_F10},
{"f11", Keyboard::KEY_F11},
{"f12", Keyboard::KEY_F12},
{"printscreen", Keyboard::KEY_PRINTSCREEN},
{"scrolllock", Keyboard::KEY_SCROLLLOCK},
{"pause", Keyboard::KEY_PAUSE},
{"insert", Keyboard::KEY_INSERT},
{"home", Keyboard::KEY_HOME},
{"pageup", Keyboard::KEY_PAGEUP},
{"delete", Keyboard::KEY_DELETE},
{"end", Keyboard::KEY_END},
{"pagedown", Keyboard::KEY_PAGEDOWN},
{"right", Keyboard::KEY_RIGHT},
{"left", Keyboard::KEY_LEFT},
{"down", Keyboard::KEY_DOWN},
{"up", Keyboard::KEY_UP},
{"numlock", Keyboard::KEY_NUMLOCKCLEAR},
{"kp/", Keyboard::KEY_KP_DIVIDE},
{"kp*", Keyboard::KEY_KP_MULTIPLY},
{"kp-", Keyboard::KEY_KP_MINUS},
{"kp+", Keyboard::KEY_KP_PLUS},
{"kpenter", Keyboard::KEY_KP_ENTER},
{"kp0", Keyboard::KEY_KP_0},
{"kp1", Keyboard::KEY_KP_1},
{"kp2", Keyboard::KEY_KP_2},
{"kp3", Keyboard::KEY_KP_3},
{"kp4", Keyboard::KEY_KP_4},
{"kp5", Keyboard::KEY_KP_5},
{"kp6", Keyboard::KEY_KP_6},
{"kp7", Keyboard::KEY_KP_7},
{"kp8", Keyboard::KEY_KP_8},
{"kp9", Keyboard::KEY_KP_9},
{"kp.", Keyboard::KEY_KP_PERIOD},
{"kp,", Keyboard::KEY_KP_COMMA},
{"kp=", Keyboard::KEY_KP_EQUALS},
{"application", Keyboard::KEY_APPLICATION},
{"power", Keyboard::KEY_POWER},
{"f13", Keyboard::KEY_F13},
{"f14", Keyboard::KEY_F14},
{"f15", Keyboard::KEY_F15},
{"f16", Keyboard::KEY_F16},
{"f17", Keyboard::KEY_F17},
{"f18", Keyboard::KEY_F18},
{"f19", Keyboard::KEY_F19},
{"f20", Keyboard::KEY_F20},
{"f21", Keyboard::KEY_F21},
{"f22", Keyboard::KEY_F22},
{"f23", Keyboard::KEY_F23},
{"f24", Keyboard::KEY_F24},
{"execute", Keyboard::KEY_EXECUTE},
{"help", Keyboard::KEY_HELP},
{"menu", Keyboard::KEY_MENU},
{"select", Keyboard::KEY_SELECT},
{"stop", Keyboard::KEY_STOP},
{"again", Keyboard::KEY_AGAIN},
{"undo", Keyboard::KEY_UNDO},
{"cut", Keyboard::KEY_CUT},
{"copy", Keyboard::KEY_COPY},
{"paste", Keyboard::KEY_PASTE},
{"find", Keyboard::KEY_FIND},
{"mute", Keyboard::KEY_MUTE},
{"volumeup", Keyboard::KEY_VOLUMEUP},
{"volumedown", Keyboard::KEY_VOLUMEDOWN},
{"alterase", Keyboard::KEY_ALTERASE},
{"sysreq", Keyboard::KEY_SYSREQ},
{"cancel", Keyboard::KEY_CANCEL},
{"clear", Keyboard::KEY_CLEAR},
{"prior", Keyboard::KEY_PRIOR},
{"return2", Keyboard::KEY_RETURN2},
{"separator", Keyboard::KEY_SEPARATOR},
{"out", Keyboard::KEY_OUT},
{"oper", Keyboard::KEY_OPER},
{"clearagain", Keyboard::KEY_CLEARAGAIN},
{"thsousandsseparator", Keyboard::KEY_THOUSANDSSEPARATOR},
{"decimalseparator", Keyboard::KEY_DECIMALSEPARATOR},
{"currencyunit", Keyboard::KEY_CURRENCYUNIT},
{"currencysubunit", Keyboard::KEY_CURRENCYSUBUNIT},
{"lctrl", Keyboard::KEY_LCTRL},
{"lshift", Keyboard::KEY_LSHIFT},
{"lalt", Keyboard::KEY_LALT},
{"lgui", Keyboard::KEY_LGUI},
{"rctrl", Keyboard::KEY_RCTRL},
{"rshift", Keyboard::KEY_RSHIFT},
{"ralt", Keyboard::KEY_RALT},
{"rgui", Keyboard::KEY_RGUI},
{"mode", Keyboard::KEY_MODE},
{"audionext", Keyboard::KEY_AUDIONEXT},
{"audioprev", Keyboard::KEY_AUDIOPREV},
{"audiostop", Keyboard::KEY_AUDIOSTOP},
{"audioplay", Keyboard::KEY_AUDIOPLAY},
{"audiomute", Keyboard::KEY_AUDIOMUTE},
{"mediaselect", Keyboard::KEY_MEDIASELECT},
{"brightnessdown", Keyboard::KEY_BRIGHTNESSDOWN},
{"brightnessup", Keyboard::KEY_BRIGHTNESSUP},
{"displayswitch", Keyboard::KEY_DISPLAYSWITCH},
{"kbdillumtoggle", Keyboard::KEY_KBDILLUMTOGGLE},
{"kbdillumdown", Keyboard::KEY_KBDILLUMDOWN},
{"kbdillumup", Keyboard::KEY_KBDILLUMUP},
{"eject", Keyboard::KEY_EJECT},
{"sleep", Keyboard::KEY_SLEEP},
};
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
} // keyboard
} // love
+281
View File
@@ -0,0 +1,281 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_KEYBOARD_KEYBOARD_H
#define LOVE_KEYBOARD_KEYBOARD_H
// LOVE
#include "common/Module.h"
#include "common/StringMap.h"
namespace love
{
namespace keyboard
{
class Keyboard : public Module
{
public:
enum Key
{
KEY_UNKNOWN,
KEY_RETURN,
KEY_ESCAPE,
KEY_BACKSPACE,
KEY_TAB,
KEY_SPACE,
KEY_EXCLAIM,
KEY_QUOTEDBL,
KEY_HASH,
KEY_PERCENT,
KEY_DOLLAR,
KEY_AMPERSAND,
KEY_QUOTE,
KEY_LEFTPAREN,
KEY_RIGHTPAREN,
KEY_ASTERISK,
KEY_PLUS,
KEY_COMMA,
KEY_MINUS,
KEY_PERIOD,
KEY_SLASH,
KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_COLON,
KEY_SEMICOLON,
KEY_LESS,
KEY_EQUALS,
KEY_GREATER,
KEY_QUESTION,
KEY_AT,
KEY_LEFTBRACKET,
KEY_BACKSLASH,
KEY_RIGHTBRACKET,
KEY_CARET,
KEY_UNDERSCORE,
KEY_BACKQUOTE,
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_E,
KEY_F,
KEY_G,
KEY_H,
KEY_I,
KEY_J,
KEY_K,
KEY_L,
KEY_M,
KEY_N,
KEY_O,
KEY_P,
KEY_Q,
KEY_R,
KEY_S,
KEY_T,
KEY_U,
KEY_V,
KEY_W,
KEY_X,
KEY_Y,
KEY_Z,
KEY_CAPSLOCK,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEY_PRINTSCREEN,
KEY_SCROLLLOCK,
KEY_PAUSE,
KEY_INSERT,
KEY_HOME,
KEY_PAGEUP,
KEY_DELETE,
KEY_END,
KEY_PAGEDOWN,
KEY_RIGHT,
KEY_LEFT,
KEY_DOWN,
KEY_UP,
KEY_NUMLOCKCLEAR,
KEY_KP_DIVIDE,
KEY_KP_MULTIPLY,
KEY_KP_MINUS,
KEY_KP_PLUS,
KEY_KP_ENTER,
KEY_KP_1,
KEY_KP_2,
KEY_KP_3,
KEY_KP_4,
KEY_KP_5,
KEY_KP_6,
KEY_KP_7,
KEY_KP_8,
KEY_KP_9,
KEY_KP_0,
KEY_KP_PERIOD,
KEY_KP_COMMA,
KEY_KP_EQUALS,
KEY_APPLICATION,
KEY_POWER,
KEY_F13,
KEY_F14,
KEY_F15,
KEY_F16,
KEY_F17,
KEY_F18,
KEY_F19,
KEY_F20,
KEY_F21,
KEY_F22,
KEY_F23,
KEY_F24,
KEY_EXECUTE,
KEY_HELP,
KEY_MENU,
KEY_SELECT,
KEY_STOP,
KEY_AGAIN,
KEY_UNDO,
KEY_CUT,
KEY_COPY,
KEY_PASTE,
KEY_FIND,
KEY_MUTE,
KEY_VOLUMEUP,
KEY_VOLUMEDOWN,
KEY_ALTERASE,
KEY_SYSREQ,
KEY_CANCEL,
KEY_CLEAR,
KEY_PRIOR,
KEY_RETURN2,
KEY_SEPARATOR,
KEY_OUT,
KEY_OPER,
KEY_CLEARAGAIN,
KEY_THOUSANDSSEPARATOR,
KEY_DECIMALSEPARATOR,
KEY_CURRENCYUNIT,
KEY_CURRENCYSUBUNIT,
KEY_LCTRL,
KEY_LSHIFT,
KEY_LALT,
KEY_LGUI,
KEY_RCTRL,
KEY_RSHIFT,
KEY_RALT,
KEY_RGUI,
KEY_MODE,
KEY_AUDIONEXT,
KEY_AUDIOPREV,
KEY_AUDIOSTOP,
KEY_AUDIOPLAY,
KEY_AUDIOMUTE,
KEY_MEDIASELECT,
KEY_BRIGHTNESSDOWN,
KEY_BRIGHTNESSUP,
KEY_DISPLAYSWITCH,
KEY_KBDILLUMTOGGLE,
KEY_KBDILLUMDOWN,
KEY_KBDILLUMUP,
KEY_EJECT,
KEY_SLEEP,
KEY_MAX_ENUM = 512
};
virtual ~Keyboard() {}
/**
* Sets whether repeat keypress events should be sent if a key is held down.
* Does not affect text input events.
* @param enable Whether to send repeat key press events.
**/
virtual void setKeyRepeat(bool enable) = 0;
/**
* Gets whether repeat keypress events will be sent if a key is held down.
**/
virtual bool hasKeyRepeat() const = 0;
/**
* Checks whether certain keys are down or not.
* @param keylist An array of key identifiers, terminated by KEY_MAX_ENUM.
* @return boolean
**/
virtual bool isDown(Key *keylist) const = 0;
/**
* Sets whether text input events should be sent
* @param enable Whether to send text input events.
**/
virtual void setTextInput(bool enable) = 0;
/**
* Gets whether text input events are enabled.
**/
virtual bool hasTextInput() const = 0;
static bool getConstant(const char *in, Key &out);
static bool getConstant(Key in, const char *&out);
private:
static StringMap<Key, KEY_MAX_ENUM>::Entry keyEntries[];
static StringMap<Key, KEY_MAX_ENUM> keys;
}; // Keyboard
} // keyboard
} // love
#endif // LOVE_KEYBOARD_KEYBOARD_H
@@ -0,0 +1,284 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "common/config.h"
#include "Keyboard.h"
namespace love
{
namespace keyboard
{
namespace sdl
{
Keyboard::Keyboard()
: key_repeat(false)
{
}
const char *Keyboard::getName() const
{
return "love.keyboard.sdl";
}
void Keyboard::setKeyRepeat(bool enable)
{
key_repeat = enable;
}
bool Keyboard::hasKeyRepeat() const
{
return key_repeat;
}
bool Keyboard::isDown(Key *keylist) const
{
const Uint8 *keystate = SDL_GetKeyboardState(0);
std::map<Key, SDL_Keycode>::const_iterator it;
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
{
it = keys.find(key);
if (it != keys.end() && keystate[SDL_GetScancodeFromKey(it->second)])
return true;
}
return false;
}
void Keyboard::setTextInput(bool enable)
{
if (enable)
SDL_StartTextInput();
else
SDL_StopTextInput();
}
bool Keyboard::hasTextInput() const
{
return SDL_IsTextInputActive();
}
std::map<Keyboard::Key, SDL_Keycode> Keyboard::createKeyMap()
{
std::map<Keyboard::Key, SDL_Keycode> k;
k[Keyboard::KEY_UNKNOWN] = SDLK_UNKNOWN;
k[Keyboard::KEY_RETURN] = SDLK_RETURN;
k[Keyboard::KEY_ESCAPE] = SDLK_ESCAPE;
k[Keyboard::KEY_BACKSPACE] = SDLK_BACKSPACE;
k[Keyboard::KEY_TAB] = SDLK_TAB;
k[Keyboard::KEY_SPACE] = SDLK_SPACE;
k[Keyboard::KEY_EXCLAIM] = SDLK_EXCLAIM;
k[Keyboard::KEY_QUOTEDBL] = SDLK_QUOTEDBL;
k[Keyboard::KEY_HASH] = SDLK_HASH;
k[Keyboard::KEY_DOLLAR] = SDLK_DOLLAR;
k[Keyboard::KEY_AMPERSAND] = SDLK_AMPERSAND;
k[Keyboard::KEY_QUOTE] = SDLK_QUOTE;
k[Keyboard::KEY_LEFTPAREN] = SDLK_LEFTPAREN;
k[Keyboard::KEY_RIGHTPAREN] = SDLK_RIGHTPAREN;
k[Keyboard::KEY_ASTERISK] = SDLK_ASTERISK;
k[Keyboard::KEY_PLUS] = SDLK_PLUS;
k[Keyboard::KEY_COMMA] = SDLK_COMMA;
k[Keyboard::KEY_MINUS] = SDLK_MINUS;
k[Keyboard::KEY_PERIOD] = SDLK_PERIOD;
k[Keyboard::KEY_SLASH] = SDLK_SLASH;
k[Keyboard::KEY_0] = SDLK_0;
k[Keyboard::KEY_1] = SDLK_1;
k[Keyboard::KEY_2] = SDLK_2;
k[Keyboard::KEY_3] = SDLK_3;
k[Keyboard::KEY_4] = SDLK_4;
k[Keyboard::KEY_5] = SDLK_5;
k[Keyboard::KEY_6] = SDLK_6;
k[Keyboard::KEY_7] = SDLK_7;
k[Keyboard::KEY_8] = SDLK_8;
k[Keyboard::KEY_9] = SDLK_9;
k[Keyboard::KEY_COLON] = SDLK_COLON;
k[Keyboard::KEY_SEMICOLON] = SDLK_SEMICOLON;
k[Keyboard::KEY_LESS] = SDLK_LESS;
k[Keyboard::KEY_EQUALS] = SDLK_EQUALS;
k[Keyboard::KEY_GREATER] = SDLK_GREATER;
k[Keyboard::KEY_QUESTION] = SDLK_QUESTION;
k[Keyboard::KEY_AT] = SDLK_AT;
k[Keyboard::KEY_LEFTBRACKET] = SDLK_LEFTBRACKET;
k[Keyboard::KEY_BACKSLASH] = SDLK_BACKSLASH;
k[Keyboard::KEY_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
k[Keyboard::KEY_CARET] = SDLK_CARET;
k[Keyboard::KEY_UNDERSCORE] = SDLK_UNDERSCORE;
k[Keyboard::KEY_BACKQUOTE] = SDLK_BACKQUOTE;
k[Keyboard::KEY_A] = SDLK_a;
k[Keyboard::KEY_B] = SDLK_b;
k[Keyboard::KEY_C] = SDLK_c;
k[Keyboard::KEY_D] = SDLK_d;
k[Keyboard::KEY_E] = SDLK_e;
k[Keyboard::KEY_F] = SDLK_f;
k[Keyboard::KEY_G] = SDLK_g;
k[Keyboard::KEY_H] = SDLK_h;
k[Keyboard::KEY_I] = SDLK_i;
k[Keyboard::KEY_J] = SDLK_j;
k[Keyboard::KEY_K] = SDLK_k;
k[Keyboard::KEY_L] = SDLK_l;
k[Keyboard::KEY_M] = SDLK_m;
k[Keyboard::KEY_N] = SDLK_n;
k[Keyboard::KEY_O] = SDLK_o;
k[Keyboard::KEY_P] = SDLK_p;
k[Keyboard::KEY_Q] = SDLK_q;
k[Keyboard::KEY_R] = SDLK_r;
k[Keyboard::KEY_S] = SDLK_s;
k[Keyboard::KEY_T] = SDLK_t;
k[Keyboard::KEY_U] = SDLK_u;
k[Keyboard::KEY_V] = SDLK_v;
k[Keyboard::KEY_W] = SDLK_w;
k[Keyboard::KEY_X] = SDLK_x;
k[Keyboard::KEY_Y] = SDLK_y;
k[Keyboard::KEY_Z] = SDLK_z;
k[Keyboard::KEY_CAPSLOCK] = SDLK_CAPSLOCK;
k[Keyboard::KEY_F1] = SDLK_F1;
k[Keyboard::KEY_F2] = SDLK_F2;
k[Keyboard::KEY_F3] = SDLK_F3;
k[Keyboard::KEY_F4] = SDLK_F4;
k[Keyboard::KEY_F5] = SDLK_F5;
k[Keyboard::KEY_F6] = SDLK_F6;
k[Keyboard::KEY_F7] = SDLK_F7;
k[Keyboard::KEY_F8] = SDLK_F8;
k[Keyboard::KEY_F9] = SDLK_F9;
k[Keyboard::KEY_F10] = SDLK_F10;
k[Keyboard::KEY_F11] = SDLK_F11;
k[Keyboard::KEY_F12] = SDLK_F12;
k[Keyboard::KEY_PRINTSCREEN] = SDLK_PRINTSCREEN;
k[Keyboard::KEY_SCROLLLOCK] = SDLK_SCROLLLOCK;
k[Keyboard::KEY_PAUSE] = SDLK_PAUSE;
k[Keyboard::KEY_INSERT] = SDLK_INSERT;
k[Keyboard::KEY_HOME] = SDLK_HOME;
k[Keyboard::KEY_PAGEUP] = SDLK_PAGEUP;
k[Keyboard::KEY_DELETE] = SDLK_DELETE;
k[Keyboard::KEY_END] = SDLK_END;
k[Keyboard::KEY_PAGEDOWN] = SDLK_PAGEDOWN;
k[Keyboard::KEY_RIGHT] = SDLK_RIGHT;
k[Keyboard::KEY_LEFT] = SDLK_LEFT;
k[Keyboard::KEY_DOWN] = SDLK_DOWN;
k[Keyboard::KEY_UP] = SDLK_UP;
k[Keyboard::KEY_NUMLOCKCLEAR] = SDLK_NUMLOCKCLEAR;
k[Keyboard::KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
k[Keyboard::KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
k[Keyboard::KEY_KP_MINUS] = SDLK_KP_MINUS;
k[Keyboard::KEY_KP_PLUS] = SDLK_KP_PLUS;
k[Keyboard::KEY_KP_ENTER] = SDLK_KP_ENTER;
k[Keyboard::KEY_KP_0] = SDLK_KP_0;
k[Keyboard::KEY_KP_1] = SDLK_KP_1;
k[Keyboard::KEY_KP_2] = SDLK_KP_2;
k[Keyboard::KEY_KP_3] = SDLK_KP_3;
k[Keyboard::KEY_KP_4] = SDLK_KP_4;
k[Keyboard::KEY_KP_5] = SDLK_KP_5;
k[Keyboard::KEY_KP_6] = SDLK_KP_6;
k[Keyboard::KEY_KP_7] = SDLK_KP_7;
k[Keyboard::KEY_KP_8] = SDLK_KP_8;
k[Keyboard::KEY_KP_9] = SDLK_KP_9;
k[Keyboard::KEY_KP_PERIOD] = SDLK_KP_PERIOD;
k[Keyboard::KEY_KP_COMMA] = SDLK_KP_COMMA;
k[Keyboard::KEY_KP_EQUALS] = SDLK_KP_EQUALS;
k[Keyboard::KEY_APPLICATION] = SDLK_APPLICATION;
k[Keyboard::KEY_POWER] = SDLK_POWER;
k[Keyboard::KEY_F13] = SDLK_F13;
k[Keyboard::KEY_F14] = SDLK_F14;
k[Keyboard::KEY_F15] = SDLK_F15;
k[Keyboard::KEY_F16] = SDLK_F16;
k[Keyboard::KEY_F17] = SDLK_F17;
k[Keyboard::KEY_F18] = SDLK_F18;
k[Keyboard::KEY_F19] = SDLK_F19;
k[Keyboard::KEY_F20] = SDLK_F20;
k[Keyboard::KEY_F21] = SDLK_F21;
k[Keyboard::KEY_F22] = SDLK_F22;
k[Keyboard::KEY_F23] = SDLK_F23;
k[Keyboard::KEY_F24] = SDLK_F24;
k[Keyboard::KEY_EXECUTE] = SDLK_EXECUTE;
k[Keyboard::KEY_HELP] = SDLK_HELP;
k[Keyboard::KEY_MENU] = SDLK_MENU;
k[Keyboard::KEY_SELECT] = SDLK_SELECT;
k[Keyboard::KEY_STOP] = SDLK_STOP;
k[Keyboard::KEY_AGAIN] = SDLK_AGAIN;
k[Keyboard::KEY_UNDO] = SDLK_UNDO;
k[Keyboard::KEY_CUT] = SDLK_CUT;
k[Keyboard::KEY_COPY] = SDLK_COPY;
k[Keyboard::KEY_PASTE] = SDLK_PASTE;
k[Keyboard::KEY_FIND] = SDLK_FIND;
k[Keyboard::KEY_MUTE] = SDLK_MUTE;
k[Keyboard::KEY_VOLUMEUP] = SDLK_VOLUMEUP;
k[Keyboard::KEY_VOLUMEDOWN] = SDLK_VOLUMEDOWN;
k[Keyboard::KEY_ALTERASE] = SDLK_ALTERASE;
k[Keyboard::KEY_SYSREQ] = SDLK_SYSREQ;
k[Keyboard::KEY_CANCEL] = SDLK_CANCEL;
k[Keyboard::KEY_CLEAR] = SDLK_CLEAR;
k[Keyboard::KEY_PRIOR] = SDLK_PRIOR;
k[Keyboard::KEY_RETURN2] = SDLK_RETURN2;
k[Keyboard::KEY_SEPARATOR] = SDLK_SEPARATOR;
k[Keyboard::KEY_OUT] = SDLK_OUT;
k[Keyboard::KEY_OPER] = SDLK_OPER;
k[Keyboard::KEY_CLEARAGAIN] = SDLK_CLEARAGAIN;
k[Keyboard::KEY_THOUSANDSSEPARATOR] = SDLK_THOUSANDSSEPARATOR;
k[Keyboard::KEY_DECIMALSEPARATOR] = SDLK_DECIMALSEPARATOR;
k[Keyboard::KEY_CURRENCYUNIT] = SDLK_CURRENCYUNIT;
k[Keyboard::KEY_CURRENCYSUBUNIT] = SDLK_CURRENCYSUBUNIT;
k[Keyboard::KEY_LCTRL] = SDLK_LCTRL;
k[Keyboard::KEY_LSHIFT] = SDLK_LSHIFT;
k[Keyboard::KEY_LALT] = SDLK_LALT;
k[Keyboard::KEY_LGUI] = SDLK_LGUI;
k[Keyboard::KEY_RCTRL] = SDLK_RCTRL;
k[Keyboard::KEY_RSHIFT] = SDLK_RSHIFT;
k[Keyboard::KEY_RALT] = SDLK_RALT;
k[Keyboard::KEY_RGUI] = SDLK_RGUI;
k[Keyboard::KEY_MODE] = SDLK_MODE;
k[Keyboard::KEY_AUDIONEXT] = SDLK_AUDIONEXT;
k[Keyboard::KEY_AUDIOPREV] = SDLK_AUDIOPREV;
k[Keyboard::KEY_AUDIOSTOP] = SDLK_AUDIOSTOP;
k[Keyboard::KEY_AUDIOPLAY] = SDLK_AUDIOPLAY;
k[Keyboard::KEY_AUDIOMUTE] = SDLK_AUDIOMUTE;
k[Keyboard::KEY_MEDIASELECT] = SDLK_MEDIASELECT;
k[Keyboard::KEY_BRIGHTNESSDOWN] = SDLK_BRIGHTNESSDOWN;
k[Keyboard::KEY_BRIGHTNESSUP] = SDLK_BRIGHTNESSUP;
k[Keyboard::KEY_DISPLAYSWITCH] = SDLK_DISPLAYSWITCH;
k[Keyboard::KEY_KBDILLUMTOGGLE] = SDLK_KBDILLUMTOGGLE;
k[Keyboard::KEY_KBDILLUMDOWN] = SDLK_KBDILLUMDOWN;
k[Keyboard::KEY_KBDILLUMUP] = SDLK_KBDILLUMUP;
k[Keyboard::KEY_EJECT] = SDLK_EJECT;
k[Keyboard::KEY_SLEEP] = SDLK_SLEEP;
return k;
}
std::map<Keyboard::Key, SDL_Keycode> Keyboard::keys = Keyboard::createKeyMap();
} // sdl
} // keyboard
} // love
@@ -0,0 +1,70 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_KEYBOARD_SDL_KEYBOARD_H
#define LOVE_KEYBOARD_SDL_KEYBOARD_H
// LOVE
#include "keyboard/Keyboard.h"
#include "common/EnumMap.h"
// SDL
#include <SDL.h>
// STL
#include <map>
namespace love
{
namespace keyboard
{
namespace sdl
{
class Keyboard : public love::keyboard::Keyboard
{
public:
Keyboard();
// Implements Module.
const char *getName() const;
void setKeyRepeat(bool enable);
bool hasKeyRepeat() const;
bool isDown(Key *keylist) const;
void setTextInput(bool enable);
bool hasTextInput() const;
private:
bool key_repeat;
static std::map<Key, SDL_Keycode> createKeyMap();
static std::map<Key, SDL_Keycode> keys;
}; // Keyboard
} // sdl
} // keyboard
} // love
#endif // LOVE_KEYBOARD_SDL_KEYBOARD_H
@@ -0,0 +1,108 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "common/config.h"
#include "wrap_Keyboard.h"
#include "sdl/Keyboard.h"
namespace love
{
namespace keyboard
{
static Keyboard *instance = 0;
int w_setKeyRepeat(lua_State *L)
{
instance->setKeyRepeat(luax_toboolean(L, 1));
return 0;
}
int w_hasKeyRepeat(lua_State *L)
{
luax_pushboolean(L, instance->hasKeyRepeat());
return 1;
}
int w_isDown(lua_State *L)
{
Keyboard::Key k;
unsigned int num = lua_gettop(L);
Keyboard::Key *keylist = new Keyboard::Key[num+1];
unsigned int counter = 0;
for (unsigned int i = 0; i < num; i++)
{
if (Keyboard::getConstant(luaL_checkstring(L, i+1), k))
keylist[counter++] = k;
}
keylist[counter] = Keyboard::KEY_MAX_ENUM;
luax_pushboolean(L, instance->isDown(keylist));
delete[] keylist;
return 1;
}
int w_setTextInput(lua_State *L)
{
instance->setTextInput(luax_toboolean(L, 1));
return 0;
}
int w_hasTextInput(lua_State *L)
{
luax_pushboolean(L, instance->hasTextInput());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "setKeyRepeat", w_setKeyRepeat },
{ "hasKeyRepeat", w_hasKeyRepeat },
{ "setTextInput", w_setTextInput },
{ "hasTextInput", w_hasTextInput },
{ "isDown", w_isDown },
{ 0, 0 }
};
extern "C" int luaopen_love_keyboard(lua_State *L)
{
if (instance == 0)
{
EXCEPT_GUARD(instance = new love::keyboard::sdl::Keyboard();)
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "keyboard";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // keyboard
} // love
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_KEYBOARD_WRAP_KEYBOARD_H
#define LOVE_KEYBOARD_WRAP_KEYBOARD_H
// LOVE
#include "Keyboard.h"
namespace love
{
namespace keyboard
{
int w_setKeyRepeat(lua_State *L);
int w_hasKeyRepeat(lua_State *L);
int w_isDown(lua_State *L);
int w_setTextInput(lua_State *L);
int w_hasTextInput(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
} // keyboard
} // love
#endif // LOVE_KEYBOARD_WRAP_KEYBOARD_H