Browse Source

input: add the Keyboard abstraction object type.

legacy
Sam Hocevar sam 12 years ago
parent
commit
b438a94642
8 changed files with 136 additions and 1 deletions
  1. +1
    -0
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +10
    -0
      src/input/input.h
  4. +68
    -0
      src/input/keyboard.cpp
  5. +43
    -0
      src/input/keyboard.h
  6. +2
    -0
      src/lolcore.vcxproj
  7. +6
    -0
      src/lolcore.vcxproj.filters
  8. +5
    -1
      src/platform/sdl/sdlinput.cpp

+ 1
- 0
src/Makefile.am View File

@@ -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 \


+ 1
- 0
src/core.h View File

@@ -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"



+ 10
- 0
src/input/input.h View File

@@ -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);


+ 68
- 0
src/input/keyboard.cpp View File

@@ -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 */


+ 43
- 0
src/input/keyboard.h View File

@@ -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__


+ 2
- 0
src/lolcore.vcxproj View File

@@ -266,6 +266,7 @@
<ClCompile Include="image\codec\sdl-image.cpp" />
<ClCompile Include="image\image.cpp" />
<ClCompile Include="input\input.cpp" />
<ClCompile Include="input\keyboard.cpp" />
<ClCompile Include="input\stick.cpp" />
<ClCompile Include="layer.cpp" />
<ClCompile Include="log.cpp" />
@@ -575,6 +576,7 @@
<ClInclude Include="image\image-private.h" />
<ClInclude Include="image\image.h" />
<ClInclude Include="input\input.h" />
<ClInclude Include="input\keyboard.h" />
<ClInclude Include="input\stick.h" />
<ClInclude Include="layer.h" />
<ClInclude Include="log.h" />


+ 6
- 0
src/lolcore.vcxproj.filters View File

@@ -136,6 +136,9 @@
<ClCompile Include="input\input.cpp">
<Filter>src\input</Filter>
</ClCompile>
<ClCompile Include="input\keyboard.cpp">
<Filter>src\input</Filter>
</ClCompile>
<ClCompile Include="input\stick.cpp">
<Filter>src\input</Filter>
</ClCompile>
@@ -705,6 +708,9 @@
<ClInclude Include="input\input.h">
<Filter>src\input</Filter>
</ClInclude>
<ClInclude Include="input\keyboard.h">
<Filter>src\input</Filter>
</ClInclude>
<ClInclude Include="input\stick.h">
<Filter>src\input</Filter>
</ClInclude>


+ 5
- 1
src/platform/sdl/sdlinput.cpp View File

@@ -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:


Loading…
Cancel
Save