Updated to OVR 0.4.3. Added support for event char to read keyboard text input.

This commit is contained in:
Branimir Karadžić
2014-11-08 20:57:47 -08:00
parent ace930ebd9
commit 31efb2991f
13 changed files with 146 additions and 25 deletions
+53
View File
@@ -8,6 +8,7 @@
#include "entry_p.h"
#include "input.h"
#include <bx/ringbuffer.h>
#include <tinystl/allocator.h>
#include <tinystl/unordered_map.h>
namespace stl = tinystl;
@@ -68,6 +69,7 @@ struct Mouse
struct Keyboard
{
Keyboard()
: m_ring(BX_COUNTOF(m_char) )
{
}
@@ -97,8 +99,44 @@ struct Keyboard
m_once[_key] = false;
}
void pushChar(uint8_t _len, const uint8_t _char[4])
{
for (uint32_t len = m_ring.reserve(4)
; len < _len
; len = m_ring.reserve(4)
)
{
popChar();
}
memcpy(&m_char[m_ring.m_write], _char, 4);
m_ring.commit(4);
}
const uint8_t* popChar()
{
if (0 < m_ring.available() )
{
uint8_t* utf8 = &m_char[m_ring.m_read];
m_ring.consume(4);
return utf8;
}
return NULL;
}
void charFlush()
{
m_ring.m_current = 0;
m_ring.m_write = 0;
m_ring.m_read = 0;
}
uint32_t m_key[256];
bool m_once[256];
bx::RingBufferControl m_ring;
uint8_t m_char[256];
};
struct Input
@@ -204,6 +242,21 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
}
void inputChar(uint8_t _len, const uint8_t _char[4])
{
s_input.m_keyboard.pushChar(_len, _char);
}
const uint8_t* inputGetChar()
{
return s_input.m_keyboard.popChar();
}
void inputCharFlush()
{
s_input.m_keyboard.charFlush();
}
void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz)
{
s_input.m_mouse.setPos(_mx, _my, _mz);