mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Applied the new style guidelines.
Well, sort of. Lot's more to be done, but this is a start.
This commit is contained in:
+189
-188
@@ -1,188 +1,189 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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[] =
|
||||
{
|
||||
{"backspace", Keyboard::KEY_BACKSPACE},
|
||||
{"tab", Keyboard::KEY_TAB},
|
||||
{"clear", Keyboard::KEY_CLEAR},
|
||||
{"return", Keyboard::KEY_RETURN},
|
||||
{"pause", Keyboard::KEY_PAUSE},
|
||||
{"escape", Keyboard::KEY_ESCAPE},
|
||||
{" ", 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},
|
||||
{"delete", Keyboard::KEY_DELETE},
|
||||
|
||||
{"kp0", Keyboard::KEY_KP0},
|
||||
{"kp1", Keyboard::KEY_KP1},
|
||||
{"kp2", Keyboard::KEY_KP2},
|
||||
{"kp3", Keyboard::KEY_KP3},
|
||||
{"kp4", Keyboard::KEY_KP4},
|
||||
{"kp5", Keyboard::KEY_KP5},
|
||||
{"kp6", Keyboard::KEY_KP6},
|
||||
{"kp7", Keyboard::KEY_KP7},
|
||||
{"kp8", Keyboard::KEY_KP8},
|
||||
{"kp9", Keyboard::KEY_KP9},
|
||||
{"kp.", Keyboard::KEY_KP_PERIOD},
|
||||
{"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},
|
||||
{"kp=", Keyboard::KEY_KP_EQUALS},
|
||||
|
||||
{"up", Keyboard::KEY_UP},
|
||||
{"down", Keyboard::KEY_DOWN},
|
||||
{"right", Keyboard::KEY_RIGHT},
|
||||
{"left", Keyboard::KEY_LEFT},
|
||||
{"insert", Keyboard::KEY_INSERT},
|
||||
{"home", Keyboard::KEY_HOME},
|
||||
{"end", Keyboard::KEY_END},
|
||||
{"pageup", Keyboard::KEY_PAGEUP},
|
||||
{"pagedown", Keyboard::KEY_PAGEDOWN},
|
||||
|
||||
{"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},
|
||||
{"f13", Keyboard::KEY_F13},
|
||||
{"f14", Keyboard::KEY_F14},
|
||||
{"f15", Keyboard::KEY_F15},
|
||||
|
||||
{"numlock", Keyboard::KEY_NUMLOCK},
|
||||
{"capslock", Keyboard::KEY_CAPSLOCK},
|
||||
{"scrollock", Keyboard::KEY_SCROLLOCK},
|
||||
{"rshift", Keyboard::KEY_RSHIFT},
|
||||
{"lshift", Keyboard::KEY_LSHIFT},
|
||||
{"rctrl", Keyboard::KEY_RCTRL},
|
||||
{"lctrl", Keyboard::KEY_LCTRL},
|
||||
{"ralt", Keyboard::KEY_RALT},
|
||||
{"lalt", Keyboard::KEY_LALT},
|
||||
{"rmeta", Keyboard::KEY_RMETA},
|
||||
{"lmeta", Keyboard::KEY_LMETA},
|
||||
{"lsuper", Keyboard::KEY_LSUPER},
|
||||
{"rsuper", Keyboard::KEY_RSUPER},
|
||||
{"mode", Keyboard::KEY_MODE},
|
||||
{"compose", Keyboard::KEY_COMPOSE},
|
||||
|
||||
{"help", Keyboard::KEY_HELP},
|
||||
{"print", Keyboard::KEY_PRINT},
|
||||
{"sysreq", Keyboard::KEY_SYSREQ},
|
||||
{"break", Keyboard::KEY_BREAK},
|
||||
{"menu", Keyboard::KEY_MENU},
|
||||
{"power", Keyboard::KEY_POWER},
|
||||
{"euro", Keyboard::KEY_EURO},
|
||||
{"undo", Keyboard::KEY_UNDO},
|
||||
};
|
||||
|
||||
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
|
||||
|
||||
|
||||
} // keyboard
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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[] =
|
||||
{
|
||||
{"backspace", Keyboard::KEY_BACKSPACE},
|
||||
{"tab", Keyboard::KEY_TAB},
|
||||
{"clear", Keyboard::KEY_CLEAR},
|
||||
{"return", Keyboard::KEY_RETURN},
|
||||
{"pause", Keyboard::KEY_PAUSE},
|
||||
{"escape", Keyboard::KEY_ESCAPE},
|
||||
{" ", 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},
|
||||
{"delete", Keyboard::KEY_DELETE},
|
||||
|
||||
{"kp0", Keyboard::KEY_KP0},
|
||||
{"kp1", Keyboard::KEY_KP1},
|
||||
{"kp2", Keyboard::KEY_KP2},
|
||||
{"kp3", Keyboard::KEY_KP3},
|
||||
{"kp4", Keyboard::KEY_KP4},
|
||||
{"kp5", Keyboard::KEY_KP5},
|
||||
{"kp6", Keyboard::KEY_KP6},
|
||||
{"kp7", Keyboard::KEY_KP7},
|
||||
{"kp8", Keyboard::KEY_KP8},
|
||||
{"kp9", Keyboard::KEY_KP9},
|
||||
{"kp.", Keyboard::KEY_KP_PERIOD},
|
||||
{"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},
|
||||
{"kp=", Keyboard::KEY_KP_EQUALS},
|
||||
|
||||
{"up", Keyboard::KEY_UP},
|
||||
{"down", Keyboard::KEY_DOWN},
|
||||
{"right", Keyboard::KEY_RIGHT},
|
||||
{"left", Keyboard::KEY_LEFT},
|
||||
{"insert", Keyboard::KEY_INSERT},
|
||||
{"home", Keyboard::KEY_HOME},
|
||||
{"end", Keyboard::KEY_END},
|
||||
{"pageup", Keyboard::KEY_PAGEUP},
|
||||
{"pagedown", Keyboard::KEY_PAGEDOWN},
|
||||
|
||||
{"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},
|
||||
{"f13", Keyboard::KEY_F13},
|
||||
{"f14", Keyboard::KEY_F14},
|
||||
{"f15", Keyboard::KEY_F15},
|
||||
|
||||
{"numlock", Keyboard::KEY_NUMLOCK},
|
||||
{"capslock", Keyboard::KEY_CAPSLOCK},
|
||||
{"scrollock", Keyboard::KEY_SCROLLOCK},
|
||||
{"rshift", Keyboard::KEY_RSHIFT},
|
||||
{"lshift", Keyboard::KEY_LSHIFT},
|
||||
{"rctrl", Keyboard::KEY_RCTRL},
|
||||
{"lctrl", Keyboard::KEY_LCTRL},
|
||||
{"ralt", Keyboard::KEY_RALT},
|
||||
{"lalt", Keyboard::KEY_LALT},
|
||||
{"rmeta", Keyboard::KEY_RMETA},
|
||||
{"lmeta", Keyboard::KEY_LMETA},
|
||||
{"lsuper", Keyboard::KEY_LSUPER},
|
||||
{"rsuper", Keyboard::KEY_RSUPER},
|
||||
{"mode", Keyboard::KEY_MODE},
|
||||
{"compose", Keyboard::KEY_COMPOSE},
|
||||
|
||||
{"help", Keyboard::KEY_HELP},
|
||||
{"print", Keyboard::KEY_PRINT},
|
||||
{"sysreq", Keyboard::KEY_SYSREQ},
|
||||
{"break", Keyboard::KEY_BREAK},
|
||||
{"menu", Keyboard::KEY_MENU},
|
||||
{"power", Keyboard::KEY_POWER},
|
||||
{"euro", Keyboard::KEY_EURO},
|
||||
{"undo", Keyboard::KEY_UNDO},
|
||||
};
|
||||
|
||||
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
|
||||
|
||||
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
+227
-226
@@ -1,226 +1,227 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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_BACKSPACE,
|
||||
KEY_TAB,
|
||||
KEY_CLEAR,
|
||||
KEY_RETURN,
|
||||
KEY_PAUSE,
|
||||
KEY_ESCAPE,
|
||||
KEY_SPACE,
|
||||
KEY_EXCLAIM,
|
||||
KEY_QUOTEDBL,
|
||||
KEY_HASH,
|
||||
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_DELETE,
|
||||
|
||||
KEY_KP0,
|
||||
KEY_KP1,
|
||||
KEY_KP2,
|
||||
KEY_KP3,
|
||||
KEY_KP4,
|
||||
KEY_KP5,
|
||||
KEY_KP6,
|
||||
KEY_KP7,
|
||||
KEY_KP8,
|
||||
KEY_KP9,
|
||||
KEY_KP_PERIOD,
|
||||
KEY_KP_DIVIDE,
|
||||
KEY_KP_MULTIPLY,
|
||||
KEY_KP_MINUS,
|
||||
KEY_KP_PLUS,
|
||||
KEY_KP_ENTER,
|
||||
KEY_KP_EQUALS,
|
||||
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
KEY_INSERT,
|
||||
KEY_HOME,
|
||||
KEY_END,
|
||||
KEY_PAGEUP,
|
||||
KEY_PAGEDOWN,
|
||||
|
||||
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_F13,
|
||||
KEY_F14,
|
||||
KEY_F15,
|
||||
|
||||
KEY_NUMLOCK,
|
||||
KEY_CAPSLOCK,
|
||||
KEY_SCROLLOCK,
|
||||
KEY_RSHIFT,
|
||||
KEY_LSHIFT,
|
||||
KEY_RCTRL,
|
||||
KEY_LCTRL,
|
||||
KEY_RALT,
|
||||
KEY_LALT,
|
||||
KEY_RMETA,
|
||||
KEY_LMETA,
|
||||
KEY_LSUPER,
|
||||
KEY_RSUPER,
|
||||
KEY_MODE,
|
||||
KEY_COMPOSE,
|
||||
|
||||
KEY_HELP,
|
||||
KEY_PRINT,
|
||||
KEY_SYSREQ,
|
||||
KEY_BREAK,
|
||||
KEY_MENU,
|
||||
KEY_POWER,
|
||||
KEY_EURO,
|
||||
KEY_UNDO,
|
||||
KEY_MAX_ENUM = 512
|
||||
};
|
||||
|
||||
static const int DEFAULT = -1;
|
||||
|
||||
virtual ~Keyboard(){}
|
||||
|
||||
/**
|
||||
* Checks whether a certain key is down or not.
|
||||
* @param key A key identifier.
|
||||
* @return boolean
|
||||
**/
|
||||
virtual bool isDown(Key * keylist) const = 0;
|
||||
|
||||
/**
|
||||
* Enables key repeating.
|
||||
* @param delay The amount of delay before repeating the key (in milliseconds)
|
||||
* @param interval Specifies the amount of time between repeats (in milliseconds)
|
||||
**/
|
||||
virtual void setKeyRepeat(int delay, int interval) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the specified delay for the key repeat.
|
||||
* @return int
|
||||
**/
|
||||
virtual int getKeyRepeatDelay() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the specified interval for the key repeat.
|
||||
* @return int
|
||||
**/
|
||||
virtual int getKeyRepeatInterval() 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
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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_BACKSPACE,
|
||||
KEY_TAB,
|
||||
KEY_CLEAR,
|
||||
KEY_RETURN,
|
||||
KEY_PAUSE,
|
||||
KEY_ESCAPE,
|
||||
KEY_SPACE,
|
||||
KEY_EXCLAIM,
|
||||
KEY_QUOTEDBL,
|
||||
KEY_HASH,
|
||||
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_DELETE,
|
||||
|
||||
KEY_KP0,
|
||||
KEY_KP1,
|
||||
KEY_KP2,
|
||||
KEY_KP3,
|
||||
KEY_KP4,
|
||||
KEY_KP5,
|
||||
KEY_KP6,
|
||||
KEY_KP7,
|
||||
KEY_KP8,
|
||||
KEY_KP9,
|
||||
KEY_KP_PERIOD,
|
||||
KEY_KP_DIVIDE,
|
||||
KEY_KP_MULTIPLY,
|
||||
KEY_KP_MINUS,
|
||||
KEY_KP_PLUS,
|
||||
KEY_KP_ENTER,
|
||||
KEY_KP_EQUALS,
|
||||
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
KEY_INSERT,
|
||||
KEY_HOME,
|
||||
KEY_END,
|
||||
KEY_PAGEUP,
|
||||
KEY_PAGEDOWN,
|
||||
|
||||
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_F13,
|
||||
KEY_F14,
|
||||
KEY_F15,
|
||||
|
||||
KEY_NUMLOCK,
|
||||
KEY_CAPSLOCK,
|
||||
KEY_SCROLLOCK,
|
||||
KEY_RSHIFT,
|
||||
KEY_LSHIFT,
|
||||
KEY_RCTRL,
|
||||
KEY_LCTRL,
|
||||
KEY_RALT,
|
||||
KEY_LALT,
|
||||
KEY_RMETA,
|
||||
KEY_LMETA,
|
||||
KEY_LSUPER,
|
||||
KEY_RSUPER,
|
||||
KEY_MODE,
|
||||
KEY_COMPOSE,
|
||||
|
||||
KEY_HELP,
|
||||
KEY_PRINT,
|
||||
KEY_SYSREQ,
|
||||
KEY_BREAK,
|
||||
KEY_MENU,
|
||||
KEY_POWER,
|
||||
KEY_EURO,
|
||||
KEY_UNDO,
|
||||
KEY_MAX_ENUM = 512
|
||||
};
|
||||
|
||||
static const int DEFAULT = -1;
|
||||
|
||||
virtual ~Keyboard() {}
|
||||
|
||||
/**
|
||||
* Checks whether a certain key is down or not.
|
||||
* @param key A key identifier.
|
||||
* @return boolean
|
||||
**/
|
||||
virtual bool isDown(Key *keylist) const = 0;
|
||||
|
||||
/**
|
||||
* Enables key repeating.
|
||||
* @param delay The amount of delay before repeating the key (in milliseconds)
|
||||
* @param interval Specifies the amount of time between repeats (in milliseconds)
|
||||
**/
|
||||
virtual void setKeyRepeat(int delay, int interval) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the specified delay for the key repeat.
|
||||
* @return int
|
||||
**/
|
||||
virtual int getKeyRepeatDelay() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the specified interval for the key repeat.
|
||||
* @return int
|
||||
**/
|
||||
virtual int getKeyRepeatInterval() 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
|
||||
|
||||
@@ -1,222 +1,223 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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
|
||||
{
|
||||
const char * Keyboard::getName() const
|
||||
{
|
||||
return "love.keyboard.sdl";
|
||||
}
|
||||
|
||||
bool Keyboard::isDown(Key * keylist) const
|
||||
{
|
||||
SDLKey k;
|
||||
Uint8 * keystate = SDL_GetKeyState(0);
|
||||
|
||||
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||
{
|
||||
if (keys.find(key, k) && keystate[(unsigned)k] == 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Keyboard::setKeyRepeat(int delay, int interval) const
|
||||
{
|
||||
delay = (delay == DEFAULT) ? SDL_DEFAULT_REPEAT_DELAY : delay;
|
||||
interval = (interval == DEFAULT) ? SDL_DEFAULT_REPEAT_INTERVAL : interval;
|
||||
|
||||
SDL_EnableKeyRepeat(delay, interval);
|
||||
}
|
||||
|
||||
int Keyboard::getKeyRepeatDelay() const
|
||||
{
|
||||
int delay, interval;
|
||||
SDL_GetKeyRepeat(&delay, &interval);
|
||||
return delay;
|
||||
}
|
||||
|
||||
int Keyboard::getKeyRepeatInterval() const
|
||||
{
|
||||
int delay, interval;
|
||||
SDL_GetKeyRepeat(&delay, &interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
|
||||
{
|
||||
{ Keyboard::KEY_BACKSPACE, SDLK_BACKSPACE},
|
||||
{ Keyboard::KEY_TAB, SDLK_TAB},
|
||||
{ Keyboard::KEY_CLEAR, SDLK_CLEAR},
|
||||
{ Keyboard::KEY_RETURN, SDLK_RETURN},
|
||||
{ Keyboard::KEY_PAUSE, SDLK_PAUSE},
|
||||
{ Keyboard::KEY_ESCAPE, SDLK_ESCAPE },
|
||||
{ Keyboard::KEY_SPACE, SDLK_SPACE },
|
||||
{ Keyboard::KEY_EXCLAIM, SDLK_EXCLAIM },
|
||||
{ Keyboard::KEY_QUOTEDBL, SDLK_QUOTEDBL },
|
||||
{ Keyboard::KEY_HASH, SDLK_HASH },
|
||||
{ Keyboard::KEY_DOLLAR, SDLK_DOLLAR },
|
||||
{ Keyboard::KEY_AMPERSAND, SDLK_AMPERSAND },
|
||||
{ Keyboard::KEY_QUOTE, SDLK_QUOTE },
|
||||
{ Keyboard::KEY_LEFTPAREN, SDLK_LEFTPAREN },
|
||||
{ Keyboard::KEY_RIGHTPAREN, SDLK_RIGHTPAREN },
|
||||
{ Keyboard::KEY_ASTERISK, SDLK_ASTERISK },
|
||||
{ Keyboard::KEY_PLUS, SDLK_PLUS },
|
||||
{ Keyboard::KEY_COMMA, SDLK_COMMA },
|
||||
{ Keyboard::KEY_MINUS, SDLK_MINUS },
|
||||
{ Keyboard::KEY_PERIOD, SDLK_PERIOD },
|
||||
{ Keyboard::KEY_SLASH, SDLK_SLASH },
|
||||
{ Keyboard::KEY_0, SDLK_0 },
|
||||
{ Keyboard::KEY_1, SDLK_1 },
|
||||
{ Keyboard::KEY_2, SDLK_2 },
|
||||
{ Keyboard::KEY_3, SDLK_3 },
|
||||
{ Keyboard::KEY_4, SDLK_4 },
|
||||
{ Keyboard::KEY_5, SDLK_5 },
|
||||
{ Keyboard::KEY_6, SDLK_6 },
|
||||
{ Keyboard::KEY_7, SDLK_7 },
|
||||
{ Keyboard::KEY_8, SDLK_8 },
|
||||
{ Keyboard::KEY_9, SDLK_9 },
|
||||
{ Keyboard::KEY_COLON, SDLK_COLON },
|
||||
{ Keyboard::KEY_SEMICOLON, SDLK_SEMICOLON },
|
||||
{ Keyboard::KEY_LESS, SDLK_LESS },
|
||||
{ Keyboard::KEY_EQUALS, SDLK_EQUALS },
|
||||
{ Keyboard::KEY_GREATER, SDLK_GREATER },
|
||||
{ Keyboard::KEY_QUESTION, SDLK_QUESTION },
|
||||
{ Keyboard::KEY_AT, SDLK_AT },
|
||||
|
||||
{ Keyboard::KEY_LEFTBRACKET, SDLK_LEFTBRACKET },
|
||||
{ Keyboard::KEY_BACKSLASH, SDLK_BACKSLASH },
|
||||
{ Keyboard::KEY_RIGHTBRACKET, SDLK_RIGHTBRACKET },
|
||||
{ Keyboard::KEY_CARET, SDLK_CARET },
|
||||
{ Keyboard::KEY_UNDERSCORE, SDLK_UNDERSCORE },
|
||||
{ Keyboard::KEY_BACKQUOTE, SDLK_BACKQUOTE },
|
||||
{ Keyboard::KEY_A, SDLK_a },
|
||||
{ Keyboard::KEY_B, SDLK_b },
|
||||
{ Keyboard::KEY_C, SDLK_c },
|
||||
{ Keyboard::KEY_D, SDLK_d },
|
||||
{ Keyboard::KEY_E, SDLK_e },
|
||||
{ Keyboard::KEY_F, SDLK_f },
|
||||
{ Keyboard::KEY_G, SDLK_g },
|
||||
{ Keyboard::KEY_H, SDLK_h },
|
||||
{ Keyboard::KEY_I, SDLK_i },
|
||||
{ Keyboard::KEY_J, SDLK_j },
|
||||
{ Keyboard::KEY_K, SDLK_k },
|
||||
{ Keyboard::KEY_L, SDLK_l },
|
||||
{ Keyboard::KEY_M, SDLK_m },
|
||||
{ Keyboard::KEY_N, SDLK_n },
|
||||
{ Keyboard::KEY_O, SDLK_o },
|
||||
{ Keyboard::KEY_P, SDLK_p },
|
||||
{ Keyboard::KEY_Q, SDLK_q },
|
||||
{ Keyboard::KEY_R, SDLK_r },
|
||||
{ Keyboard::KEY_S, SDLK_s },
|
||||
{ Keyboard::KEY_T, SDLK_t },
|
||||
{ Keyboard::KEY_U, SDLK_u },
|
||||
{ Keyboard::KEY_V, SDLK_v },
|
||||
{ Keyboard::KEY_W, SDLK_w },
|
||||
{ Keyboard::KEY_X, SDLK_x },
|
||||
{ Keyboard::KEY_Y, SDLK_y },
|
||||
{ Keyboard::KEY_Z, SDLK_z },
|
||||
{ Keyboard::KEY_DELETE, SDLK_DELETE },
|
||||
|
||||
{ Keyboard::KEY_KP0, SDLK_KP0 },
|
||||
{ Keyboard::KEY_KP1, SDLK_KP1 },
|
||||
{ Keyboard::KEY_KP2, SDLK_KP2 },
|
||||
{ Keyboard::KEY_KP3, SDLK_KP3 },
|
||||
{ Keyboard::KEY_KP4, SDLK_KP4 },
|
||||
{ Keyboard::KEY_KP5, SDLK_KP5 },
|
||||
{ Keyboard::KEY_KP6, SDLK_KP6 },
|
||||
{ Keyboard::KEY_KP7, SDLK_KP7 },
|
||||
{ Keyboard::KEY_KP8, SDLK_KP8 },
|
||||
{ Keyboard::KEY_KP9, SDLK_KP9 },
|
||||
{ Keyboard::KEY_KP_PERIOD, SDLK_KP_PERIOD },
|
||||
{ Keyboard::KEY_KP_DIVIDE, SDLK_KP_DIVIDE },
|
||||
{ Keyboard::KEY_KP_MULTIPLY, SDLK_KP_MULTIPLY},
|
||||
{ Keyboard::KEY_KP_MINUS, SDLK_KP_MINUS },
|
||||
{ Keyboard::KEY_KP_PLUS, SDLK_KP_PLUS },
|
||||
{ Keyboard::KEY_KP_ENTER, SDLK_KP_ENTER },
|
||||
{ Keyboard::KEY_KP_EQUALS, SDLK_KP_EQUALS },
|
||||
|
||||
{ Keyboard::KEY_UP, SDLK_UP },
|
||||
{ Keyboard::KEY_DOWN, SDLK_DOWN },
|
||||
{ Keyboard::KEY_RIGHT, SDLK_RIGHT },
|
||||
{ Keyboard::KEY_LEFT, SDLK_LEFT },
|
||||
{ Keyboard::KEY_INSERT, SDLK_INSERT },
|
||||
{ Keyboard::KEY_HOME, SDLK_HOME },
|
||||
{ Keyboard::KEY_END, SDLK_END },
|
||||
{ Keyboard::KEY_PAGEUP, SDLK_PAGEUP },
|
||||
{ Keyboard::KEY_PAGEDOWN, SDLK_PAGEDOWN },
|
||||
|
||||
{ Keyboard::KEY_F1, SDLK_F1 },
|
||||
{ Keyboard::KEY_F2, SDLK_F2 },
|
||||
{ Keyboard::KEY_F3, SDLK_F3 },
|
||||
{ Keyboard::KEY_F4, SDLK_F4 },
|
||||
{ Keyboard::KEY_F5, SDLK_F5 },
|
||||
{ Keyboard::KEY_F6, SDLK_F6 },
|
||||
{ Keyboard::KEY_F7, SDLK_F7 },
|
||||
{ Keyboard::KEY_F8, SDLK_F8 },
|
||||
{ Keyboard::KEY_F9, SDLK_F9 },
|
||||
{ Keyboard::KEY_F10, SDLK_F10 },
|
||||
{ Keyboard::KEY_F11, SDLK_F11 },
|
||||
{ Keyboard::KEY_F12, SDLK_F12 },
|
||||
{ Keyboard::KEY_F13, SDLK_F13 },
|
||||
{ Keyboard::KEY_F14, SDLK_F14 },
|
||||
{ Keyboard::KEY_F15, SDLK_F15 },
|
||||
|
||||
{ Keyboard::KEY_NUMLOCK, SDLK_NUMLOCK },
|
||||
{ Keyboard::KEY_CAPSLOCK, SDLK_CAPSLOCK },
|
||||
{ Keyboard::KEY_SCROLLOCK, SDLK_SCROLLOCK },
|
||||
{ Keyboard::KEY_RSHIFT, SDLK_RSHIFT },
|
||||
{ Keyboard::KEY_LSHIFT, SDLK_LSHIFT },
|
||||
{ Keyboard::KEY_RCTRL, SDLK_RCTRL },
|
||||
{ Keyboard::KEY_LCTRL, SDLK_LCTRL },
|
||||
{ Keyboard::KEY_RALT, SDLK_RALT },
|
||||
{ Keyboard::KEY_LALT, SDLK_LALT },
|
||||
{ Keyboard::KEY_RMETA, SDLK_RMETA },
|
||||
{ Keyboard::KEY_LMETA, SDLK_LMETA },
|
||||
{ Keyboard::KEY_LSUPER, SDLK_LSUPER },
|
||||
{ Keyboard::KEY_RSUPER, SDLK_RSUPER },
|
||||
{ Keyboard::KEY_MODE, SDLK_MODE },
|
||||
{ Keyboard::KEY_COMPOSE, SDLK_COMPOSE },
|
||||
|
||||
{ Keyboard::KEY_HELP, SDLK_HELP },
|
||||
{ Keyboard::KEY_PRINT, SDLK_PRINT },
|
||||
{ Keyboard::KEY_SYSREQ, SDLK_SYSREQ },
|
||||
{ Keyboard::KEY_BREAK, SDLK_BREAK },
|
||||
{ Keyboard::KEY_MENU, SDLK_MENU },
|
||||
{ Keyboard::KEY_POWER, SDLK_POWER },
|
||||
{ Keyboard::KEY_EURO, SDLK_EURO },
|
||||
{ Keyboard::KEY_UNDO, SDLK_UNDO },
|
||||
};
|
||||
|
||||
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
|
||||
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
} // love
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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
|
||||
{
|
||||
|
||||
const char *Keyboard::getName() const
|
||||
{
|
||||
return "love.keyboard.sdl";
|
||||
}
|
||||
|
||||
bool Keyboard::isDown(Key *keylist) const
|
||||
{
|
||||
SDLKey k;
|
||||
Uint8 *keystate = SDL_GetKeyState(0);
|
||||
|
||||
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||
{
|
||||
if (keys.find(key, k) && keystate[(unsigned)k] == 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Keyboard::setKeyRepeat(int delay, int interval) const
|
||||
{
|
||||
delay = (delay == DEFAULT) ? SDL_DEFAULT_REPEAT_DELAY : delay;
|
||||
interval = (interval == DEFAULT) ? SDL_DEFAULT_REPEAT_INTERVAL : interval;
|
||||
|
||||
SDL_EnableKeyRepeat(delay, interval);
|
||||
}
|
||||
|
||||
int Keyboard::getKeyRepeatDelay() const
|
||||
{
|
||||
int delay, interval;
|
||||
SDL_GetKeyRepeat(&delay, &interval);
|
||||
return delay;
|
||||
}
|
||||
|
||||
int Keyboard::getKeyRepeatInterval() const
|
||||
{
|
||||
int delay, interval;
|
||||
SDL_GetKeyRepeat(&delay, &interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
|
||||
{
|
||||
{ Keyboard::KEY_BACKSPACE, SDLK_BACKSPACE},
|
||||
{ Keyboard::KEY_TAB, SDLK_TAB},
|
||||
{ Keyboard::KEY_CLEAR, SDLK_CLEAR},
|
||||
{ Keyboard::KEY_RETURN, SDLK_RETURN},
|
||||
{ Keyboard::KEY_PAUSE, SDLK_PAUSE},
|
||||
{ Keyboard::KEY_ESCAPE, SDLK_ESCAPE },
|
||||
{ Keyboard::KEY_SPACE, SDLK_SPACE },
|
||||
{ Keyboard::KEY_EXCLAIM, SDLK_EXCLAIM },
|
||||
{ Keyboard::KEY_QUOTEDBL, SDLK_QUOTEDBL },
|
||||
{ Keyboard::KEY_HASH, SDLK_HASH },
|
||||
{ Keyboard::KEY_DOLLAR, SDLK_DOLLAR },
|
||||
{ Keyboard::KEY_AMPERSAND, SDLK_AMPERSAND },
|
||||
{ Keyboard::KEY_QUOTE, SDLK_QUOTE },
|
||||
{ Keyboard::KEY_LEFTPAREN, SDLK_LEFTPAREN },
|
||||
{ Keyboard::KEY_RIGHTPAREN, SDLK_RIGHTPAREN },
|
||||
{ Keyboard::KEY_ASTERISK, SDLK_ASTERISK },
|
||||
{ Keyboard::KEY_PLUS, SDLK_PLUS },
|
||||
{ Keyboard::KEY_COMMA, SDLK_COMMA },
|
||||
{ Keyboard::KEY_MINUS, SDLK_MINUS },
|
||||
{ Keyboard::KEY_PERIOD, SDLK_PERIOD },
|
||||
{ Keyboard::KEY_SLASH, SDLK_SLASH },
|
||||
{ Keyboard::KEY_0, SDLK_0 },
|
||||
{ Keyboard::KEY_1, SDLK_1 },
|
||||
{ Keyboard::KEY_2, SDLK_2 },
|
||||
{ Keyboard::KEY_3, SDLK_3 },
|
||||
{ Keyboard::KEY_4, SDLK_4 },
|
||||
{ Keyboard::KEY_5, SDLK_5 },
|
||||
{ Keyboard::KEY_6, SDLK_6 },
|
||||
{ Keyboard::KEY_7, SDLK_7 },
|
||||
{ Keyboard::KEY_8, SDLK_8 },
|
||||
{ Keyboard::KEY_9, SDLK_9 },
|
||||
{ Keyboard::KEY_COLON, SDLK_COLON },
|
||||
{ Keyboard::KEY_SEMICOLON, SDLK_SEMICOLON },
|
||||
{ Keyboard::KEY_LESS, SDLK_LESS },
|
||||
{ Keyboard::KEY_EQUALS, SDLK_EQUALS },
|
||||
{ Keyboard::KEY_GREATER, SDLK_GREATER },
|
||||
{ Keyboard::KEY_QUESTION, SDLK_QUESTION },
|
||||
{ Keyboard::KEY_AT, SDLK_AT },
|
||||
|
||||
{ Keyboard::KEY_LEFTBRACKET, SDLK_LEFTBRACKET },
|
||||
{ Keyboard::KEY_BACKSLASH, SDLK_BACKSLASH },
|
||||
{ Keyboard::KEY_RIGHTBRACKET, SDLK_RIGHTBRACKET },
|
||||
{ Keyboard::KEY_CARET, SDLK_CARET },
|
||||
{ Keyboard::KEY_UNDERSCORE, SDLK_UNDERSCORE },
|
||||
{ Keyboard::KEY_BACKQUOTE, SDLK_BACKQUOTE },
|
||||
{ Keyboard::KEY_A, SDLK_a },
|
||||
{ Keyboard::KEY_B, SDLK_b },
|
||||
{ Keyboard::KEY_C, SDLK_c },
|
||||
{ Keyboard::KEY_D, SDLK_d },
|
||||
{ Keyboard::KEY_E, SDLK_e },
|
||||
{ Keyboard::KEY_F, SDLK_f },
|
||||
{ Keyboard::KEY_G, SDLK_g },
|
||||
{ Keyboard::KEY_H, SDLK_h },
|
||||
{ Keyboard::KEY_I, SDLK_i },
|
||||
{ Keyboard::KEY_J, SDLK_j },
|
||||
{ Keyboard::KEY_K, SDLK_k },
|
||||
{ Keyboard::KEY_L, SDLK_l },
|
||||
{ Keyboard::KEY_M, SDLK_m },
|
||||
{ Keyboard::KEY_N, SDLK_n },
|
||||
{ Keyboard::KEY_O, SDLK_o },
|
||||
{ Keyboard::KEY_P, SDLK_p },
|
||||
{ Keyboard::KEY_Q, SDLK_q },
|
||||
{ Keyboard::KEY_R, SDLK_r },
|
||||
{ Keyboard::KEY_S, SDLK_s },
|
||||
{ Keyboard::KEY_T, SDLK_t },
|
||||
{ Keyboard::KEY_U, SDLK_u },
|
||||
{ Keyboard::KEY_V, SDLK_v },
|
||||
{ Keyboard::KEY_W, SDLK_w },
|
||||
{ Keyboard::KEY_X, SDLK_x },
|
||||
{ Keyboard::KEY_Y, SDLK_y },
|
||||
{ Keyboard::KEY_Z, SDLK_z },
|
||||
{ Keyboard::KEY_DELETE, SDLK_DELETE },
|
||||
|
||||
{ Keyboard::KEY_KP0, SDLK_KP0 },
|
||||
{ Keyboard::KEY_KP1, SDLK_KP1 },
|
||||
{ Keyboard::KEY_KP2, SDLK_KP2 },
|
||||
{ Keyboard::KEY_KP3, SDLK_KP3 },
|
||||
{ Keyboard::KEY_KP4, SDLK_KP4 },
|
||||
{ Keyboard::KEY_KP5, SDLK_KP5 },
|
||||
{ Keyboard::KEY_KP6, SDLK_KP6 },
|
||||
{ Keyboard::KEY_KP7, SDLK_KP7 },
|
||||
{ Keyboard::KEY_KP8, SDLK_KP8 },
|
||||
{ Keyboard::KEY_KP9, SDLK_KP9 },
|
||||
{ Keyboard::KEY_KP_PERIOD, SDLK_KP_PERIOD },
|
||||
{ Keyboard::KEY_KP_DIVIDE, SDLK_KP_DIVIDE },
|
||||
{ Keyboard::KEY_KP_MULTIPLY, SDLK_KP_MULTIPLY},
|
||||
{ Keyboard::KEY_KP_MINUS, SDLK_KP_MINUS },
|
||||
{ Keyboard::KEY_KP_PLUS, SDLK_KP_PLUS },
|
||||
{ Keyboard::KEY_KP_ENTER, SDLK_KP_ENTER },
|
||||
{ Keyboard::KEY_KP_EQUALS, SDLK_KP_EQUALS },
|
||||
|
||||
{ Keyboard::KEY_UP, SDLK_UP },
|
||||
{ Keyboard::KEY_DOWN, SDLK_DOWN },
|
||||
{ Keyboard::KEY_RIGHT, SDLK_RIGHT },
|
||||
{ Keyboard::KEY_LEFT, SDLK_LEFT },
|
||||
{ Keyboard::KEY_INSERT, SDLK_INSERT },
|
||||
{ Keyboard::KEY_HOME, SDLK_HOME },
|
||||
{ Keyboard::KEY_END, SDLK_END },
|
||||
{ Keyboard::KEY_PAGEUP, SDLK_PAGEUP },
|
||||
{ Keyboard::KEY_PAGEDOWN, SDLK_PAGEDOWN },
|
||||
|
||||
{ Keyboard::KEY_F1, SDLK_F1 },
|
||||
{ Keyboard::KEY_F2, SDLK_F2 },
|
||||
{ Keyboard::KEY_F3, SDLK_F3 },
|
||||
{ Keyboard::KEY_F4, SDLK_F4 },
|
||||
{ Keyboard::KEY_F5, SDLK_F5 },
|
||||
{ Keyboard::KEY_F6, SDLK_F6 },
|
||||
{ Keyboard::KEY_F7, SDLK_F7 },
|
||||
{ Keyboard::KEY_F8, SDLK_F8 },
|
||||
{ Keyboard::KEY_F9, SDLK_F9 },
|
||||
{ Keyboard::KEY_F10, SDLK_F10 },
|
||||
{ Keyboard::KEY_F11, SDLK_F11 },
|
||||
{ Keyboard::KEY_F12, SDLK_F12 },
|
||||
{ Keyboard::KEY_F13, SDLK_F13 },
|
||||
{ Keyboard::KEY_F14, SDLK_F14 },
|
||||
{ Keyboard::KEY_F15, SDLK_F15 },
|
||||
|
||||
{ Keyboard::KEY_NUMLOCK, SDLK_NUMLOCK },
|
||||
{ Keyboard::KEY_CAPSLOCK, SDLK_CAPSLOCK },
|
||||
{ Keyboard::KEY_SCROLLOCK, SDLK_SCROLLOCK },
|
||||
{ Keyboard::KEY_RSHIFT, SDLK_RSHIFT },
|
||||
{ Keyboard::KEY_LSHIFT, SDLK_LSHIFT },
|
||||
{ Keyboard::KEY_RCTRL, SDLK_RCTRL },
|
||||
{ Keyboard::KEY_LCTRL, SDLK_LCTRL },
|
||||
{ Keyboard::KEY_RALT, SDLK_RALT },
|
||||
{ Keyboard::KEY_LALT, SDLK_LALT },
|
||||
{ Keyboard::KEY_RMETA, SDLK_RMETA },
|
||||
{ Keyboard::KEY_LMETA, SDLK_LMETA },
|
||||
{ Keyboard::KEY_LSUPER, SDLK_LSUPER },
|
||||
{ Keyboard::KEY_RSUPER, SDLK_RSUPER },
|
||||
{ Keyboard::KEY_MODE, SDLK_MODE },
|
||||
{ Keyboard::KEY_COMPOSE, SDLK_COMPOSE },
|
||||
|
||||
{ Keyboard::KEY_HELP, SDLK_HELP },
|
||||
{ Keyboard::KEY_PRINT, SDLK_PRINT },
|
||||
{ Keyboard::KEY_SYSREQ, SDLK_SYSREQ },
|
||||
{ Keyboard::KEY_BREAK, SDLK_BREAK },
|
||||
{ Keyboard::KEY_MENU, SDLK_MENU },
|
||||
{ Keyboard::KEY_POWER, SDLK_POWER },
|
||||
{ Keyboard::KEY_EURO, SDLK_EURO },
|
||||
{ Keyboard::KEY_UNDO, SDLK_UNDO },
|
||||
};
|
||||
|
||||
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
|
||||
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
@@ -1,59 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace keyboard
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
class Keyboard : public love::keyboard::Keyboard
|
||||
{
|
||||
public:
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
bool isDown(Key * keylist) const;
|
||||
void setKeyRepeat(int delay, int interval) const;
|
||||
int getKeyRepeatDelay() const;
|
||||
int getKeyRepeatInterval() const;
|
||||
|
||||
private:
|
||||
|
||||
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
|
||||
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM> keys;
|
||||
|
||||
}; // Keyboard
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
#endif // LOVE_KEYBOARD_SDL_KEYBOARD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace keyboard
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
class Keyboard : public love::keyboard::Keyboard
|
||||
{
|
||||
public:
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
bool isDown(Key *keylist) const;
|
||||
void setKeyRepeat(int delay, int interval) const;
|
||||
int getKeyRepeatDelay() const;
|
||||
int getKeyRepeatInterval() const;
|
||||
|
||||
private:
|
||||
|
||||
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
|
||||
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM> keys;
|
||||
|
||||
}; // Keyboard
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
#endif // LOVE_KEYBOARD_SDL_KEYBOARD_H
|
||||
|
||||
@@ -1,108 +1,111 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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;
|
||||
|
||||
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_setKeyRepeat(lua_State * L)
|
||||
{
|
||||
if (lua_gettop(L) == 0)
|
||||
{
|
||||
// Disables key repeat.
|
||||
instance->setKeyRepeat(0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delay = lua_isnumber(L, 1) ? (int) (lua_tonumber(L, 1) * 1000 + 0.5) : Keyboard::DEFAULT;
|
||||
int interval = lua_isnumber(L, 2) ? (int) (lua_tonumber(L, 2) * 1000 + 0.5) : Keyboard::DEFAULT;
|
||||
instance->setKeyRepeat(delay, interval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getKeyRepeat(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, (lua_Number) instance->getKeyRepeatDelay() * 0.001);
|
||||
lua_pushnumber(L, (lua_Number) instance->getKeyRepeatInterval() * 0.001);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "isDown", w_isDown },
|
||||
{ "setKeyRepeat", w_setKeyRepeat },
|
||||
{ "getKeyRepeat", w_getKeyRepeat },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_keyboard(lua_State * L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new love::keyboard::sdl::Keyboard();
|
||||
}
|
||||
catch (Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
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
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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;
|
||||
|
||||
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_setKeyRepeat(lua_State *L)
|
||||
{
|
||||
if (lua_gettop(L) == 0)
|
||||
{
|
||||
// Disables key repeat.
|
||||
instance->setKeyRepeat(0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delay = lua_isnumber(L, 1) ? (int)(lua_tonumber(L, 1) * 1000 + 0.5) : Keyboard::DEFAULT;
|
||||
int interval = lua_isnumber(L, 2) ? (int)(lua_tonumber(L, 2) * 1000 + 0.5) : Keyboard::DEFAULT;
|
||||
instance->setKeyRepeat(delay, interval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getKeyRepeat(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, (lua_Number) instance->getKeyRepeatDelay() * 0.001);
|
||||
lua_pushnumber(L, (lua_Number) instance->getKeyRepeatInterval() * 0.001);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "isDown", w_isDown },
|
||||
{ "setKeyRepeat", w_setKeyRepeat },
|
||||
{ "getKeyRepeat", w_getKeyRepeat },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_keyboard(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new love::keyboard::sdl::Keyboard();
|
||||
}
|
||||
catch(Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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_isDown(lua_State * L);
|
||||
int w_setKeyRepeat(lua_State * L);
|
||||
int w_getKeyRepeat(lua_State * L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State * L);
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
#endif // LOVE_KEYBOARD_WRAP_KEYBOARD_H
|
||||
/**
|
||||
* Copyright (c) 2006-2012 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_isDown(lua_State *L);
|
||||
int w_setKeyRepeat(lua_State *L);
|
||||
int w_getKeyRepeat(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
|
||||
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
#endif // LOVE_KEYBOARD_WRAP_KEYBOARD_H
|
||||
|
||||
Reference in New Issue
Block a user