diff --git a/src/Makefile.am b/src/Makefile.am index 34cd258a..dceb4ce0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,6 +44,7 @@ liblol_a_SOURCES = \ math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp \ \ input/input.cpp input/input.h \ + input/keyboard.cpp input/keyboard.h \ input/stick.cpp input/stick.h \ \ gpu/shader.cpp gpu/shader.h \ diff --git a/src/core.h b/src/core.h index 87a3e64d..7492c2d7 100644 --- a/src/core.h +++ b/src/core.h @@ -91,6 +91,7 @@ static inline int isnan(float f) #include "audio.h" #include "scene.h" #include "input/input.h" +#include "input/keyboard.h" #include "input/stick.h" #include "profiler.h" diff --git a/src/input/input.h b/src/input/input.h index 659eb0db..768bbb78 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -22,6 +22,7 @@ #include "core.h" #include "lol/math/vector.h" +#include "input/keyboard.h" #include "input/stick.h" namespace lol @@ -432,10 +433,19 @@ public: static void UntrackMouse(WorldEntity *e); /* These methods are called by the underlying input listeners */ + /* FIXME: this should disappear and be replaced by an input + * system that abstracts mice */ static void SetMousePos(ivec2 coord); static void SetMouseButton(int index); static void UnsetMouseButton(int index); + /* Keyboard handling */ + static Keyboard *CreateKeyboard(); + static void DestroyKeyboard(Keyboard *keyboard); + + static Keyboard *TrackKeyboard(int desired); + static void UntrackKeyboard(Keyboard *keyboard); + /* Joystick handling */ static Stick *CreateStick(); static void DestroyStick(Stick *stick); diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp new file mode 100644 index 00000000..9f0f2da7 --- /dev/null +++ b/src/input/keyboard.cpp @@ -0,0 +1,68 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" + +namespace lol +{ + +/* + * Keyboard implementation class + */ + +static class KeyboardData +{ + friend class Keyboard; + +public: + KeyboardData() { } + +private: + Array m_chars; +} +keyboarddata; + +/* + * Public Keyboard class + */ + +Keyboard::Keyboard() + : m_data(new KeyboardData()) +{ +} + +Keyboard::~Keyboard() +{ + delete m_data; +} + +void Keyboard::PushChar(uint32_t ch) +{ + m_data->m_chars.Push(ch); +} + +uint32_t Keyboard::PopChar() +{ + if (!m_data->m_chars.Count()) + return 0; + + uint32_t ret = m_data->m_chars[0]; + m_data->m_chars.Remove(0); + return ret; +} + +} /* namespace lol */ + diff --git a/src/input/keyboard.h b/src/input/keyboard.h new file mode 100644 index 00000000..3009c2fd --- /dev/null +++ b/src/input/keyboard.h @@ -0,0 +1,43 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The Keyboard class +// ------------------ +// + +#if !defined __LOL_INPUT_KEYBOARD_H__ +#define __LOL_INPUT_KEYBOARD_H__ + +#include "entity.h" + +namespace lol +{ + +class KeyboardData; + +class Keyboard : public Entity +{ + friend class Input; + +public: + void PushChar(uint32_t ch); + uint32_t PopChar(); + +private: + Keyboard(); + ~Keyboard(); + KeyboardData *m_data; +}; + +} /* namespace lol */ + +#endif // __LOL_INPUT_KEYBOARD_H__ + diff --git a/src/lolcore.vcxproj b/src/lolcore.vcxproj index 00dcff14..57e1488b 100644 --- a/src/lolcore.vcxproj +++ b/src/lolcore.vcxproj @@ -266,6 +266,7 @@ + @@ -575,6 +576,7 @@ + diff --git a/src/lolcore.vcxproj.filters b/src/lolcore.vcxproj.filters index 27db2b4f..bb2f3b4b 100644 --- a/src/lolcore.vcxproj.filters +++ b/src/lolcore.vcxproj.filters @@ -136,6 +136,9 @@ src\input + + src\input + src\input @@ -705,6 +708,9 @@ src\input + + src\input + src\input diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index db1b6ef8..32d4f08c 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -55,6 +55,9 @@ SdlInput::SdlInput() : m_data(new SdlInputData()) { #if defined USE_SDL + /* Enable Unicode translation of keyboard events */ + SDL_EnableUNICODE(1); + SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); # if SDL_FORCE_POLL_JOYSTICK @@ -161,7 +164,8 @@ void SdlInputData::Tick(float seconds) break; #if 0 case SDL_KEYDOWN: - Input::KeyPressed(event.key.keysym.sym, seconds); + if (event.key.keysym.unicode) + fprintf(stderr, "%c (0x%04X)\n", event.key.keysym.unicode, event.key.keysym.unicode); break; #endif case SDL_MOUSEBUTTONDOWN: