@@ -44,6 +44,7 @@ liblol_a_SOURCES = \ | |||||
math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp \ | math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp \ | ||||
\ | \ | ||||
input/input.cpp input/input.h \ | input/input.cpp input/input.h \ | ||||
input/keyboard.cpp input/keyboard.h \ | |||||
input/stick.cpp input/stick.h \ | input/stick.cpp input/stick.h \ | ||||
\ | \ | ||||
gpu/shader.cpp gpu/shader.h \ | gpu/shader.cpp gpu/shader.h \ | ||||
@@ -91,6 +91,7 @@ static inline int isnan(float f) | |||||
#include "audio.h" | #include "audio.h" | ||||
#include "scene.h" | #include "scene.h" | ||||
#include "input/input.h" | #include "input/input.h" | ||||
#include "input/keyboard.h" | |||||
#include "input/stick.h" | #include "input/stick.h" | ||||
#include "profiler.h" | #include "profiler.h" | ||||
@@ -22,6 +22,7 @@ | |||||
#include "core.h" | #include "core.h" | ||||
#include "lol/math/vector.h" | #include "lol/math/vector.h" | ||||
#include "input/keyboard.h" | |||||
#include "input/stick.h" | #include "input/stick.h" | ||||
namespace lol | namespace lol | ||||
@@ -432,10 +433,19 @@ public: | |||||
static void UntrackMouse(WorldEntity *e); | static void UntrackMouse(WorldEntity *e); | ||||
/* These methods are called by the underlying input listeners */ | /* 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 SetMousePos(ivec2 coord); | ||||
static void SetMouseButton(int index); | static void SetMouseButton(int index); | ||||
static void UnsetMouseButton(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 */ | /* Joystick handling */ | ||||
static Stick *CreateStick(); | static Stick *CreateStick(); | ||||
static void DestroyStick(Stick *stick); | static void DestroyStick(Stick *stick); | ||||
@@ -0,0 +1,68 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||||
// 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 <cstdlib> | |||||
#include "core.h" | |||||
namespace lol | |||||
{ | |||||
/* | |||||
* Keyboard implementation class | |||||
*/ | |||||
static class KeyboardData | |||||
{ | |||||
friend class Keyboard; | |||||
public: | |||||
KeyboardData() { } | |||||
private: | |||||
Array<uint32_t> 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 */ | |||||
@@ -0,0 +1,43 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||||
// 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__ | |||||
@@ -266,6 +266,7 @@ | |||||
<ClCompile Include="image\codec\sdl-image.cpp" /> | <ClCompile Include="image\codec\sdl-image.cpp" /> | ||||
<ClCompile Include="image\image.cpp" /> | <ClCompile Include="image\image.cpp" /> | ||||
<ClCompile Include="input\input.cpp" /> | <ClCompile Include="input\input.cpp" /> | ||||
<ClCompile Include="input\keyboard.cpp" /> | |||||
<ClCompile Include="input\stick.cpp" /> | <ClCompile Include="input\stick.cpp" /> | ||||
<ClCompile Include="layer.cpp" /> | <ClCompile Include="layer.cpp" /> | ||||
<ClCompile Include="log.cpp" /> | <ClCompile Include="log.cpp" /> | ||||
@@ -575,6 +576,7 @@ | |||||
<ClInclude Include="image\image-private.h" /> | <ClInclude Include="image\image-private.h" /> | ||||
<ClInclude Include="image\image.h" /> | <ClInclude Include="image\image.h" /> | ||||
<ClInclude Include="input\input.h" /> | <ClInclude Include="input\input.h" /> | ||||
<ClInclude Include="input\keyboard.h" /> | |||||
<ClInclude Include="input\stick.h" /> | <ClInclude Include="input\stick.h" /> | ||||
<ClInclude Include="layer.h" /> | <ClInclude Include="layer.h" /> | ||||
<ClInclude Include="log.h" /> | <ClInclude Include="log.h" /> | ||||
@@ -136,6 +136,9 @@ | |||||
<ClCompile Include="input\input.cpp"> | <ClCompile Include="input\input.cpp"> | ||||
<Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="input\keyboard.cpp"> | |||||
<Filter>src\input</Filter> | |||||
</ClCompile> | |||||
<ClCompile Include="input\stick.cpp"> | <ClCompile Include="input\stick.cpp"> | ||||
<Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
@@ -705,6 +708,9 @@ | |||||
<ClInclude Include="input\input.h"> | <ClInclude Include="input\input.h"> | ||||
<Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="input\keyboard.h"> | |||||
<Filter>src\input</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="input\stick.h"> | <ClInclude Include="input\stick.h"> | ||||
<Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -55,6 +55,9 @@ SdlInput::SdlInput() | |||||
: m_data(new SdlInputData()) | : m_data(new SdlInputData()) | ||||
{ | { | ||||
#if defined USE_SDL | #if defined USE_SDL | ||||
/* Enable Unicode translation of keyboard events */ | |||||
SDL_EnableUNICODE(1); | |||||
SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); | SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); | ||||
# if SDL_FORCE_POLL_JOYSTICK | # if SDL_FORCE_POLL_JOYSTICK | ||||
@@ -161,7 +164,8 @@ void SdlInputData::Tick(float seconds) | |||||
break; | break; | ||||
#if 0 | #if 0 | ||||
case SDL_KEYDOWN: | 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; | break; | ||||
#endif | #endif | ||||
case SDL_MOUSEBUTTONDOWN: | case SDL_MOUSEBUTTONDOWN: | ||||