J :
* Re-add the ReadLocalKey function that I had forgotten to re-implement with the key bindings.
This commit is contained in:
@@ -28,11 +28,15 @@
|
|||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
typedef WPARAM LocalKeySym;
|
typedef WPARAM LocalKeySym;
|
||||||
|
#define LOCAL_NO_KEY ((WPARAM)-1)
|
||||||
#elif defined(LINUX)
|
#elif defined(LINUX)
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
typedef KeySym LocalKeySym;
|
typedef KeySym LocalKeySym;
|
||||||
|
#define LOCAL_NO_KEY XK_VoidSymbol
|
||||||
#else
|
#else
|
||||||
typedef u32 LocalKeySym;
|
typedef u32 LocalKeySym;
|
||||||
|
#define LOCAL_NO_KEY ((u32)-1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +101,7 @@ class JGE
|
|||||||
static JGE* mInstance;
|
static JGE* mInstance;
|
||||||
|
|
||||||
|
|
||||||
static std::queue<JButton> keyBuffer;
|
static std::queue< std::pair<LocalKeySym, JButton> > keyBuffer;
|
||||||
static std::multimap<LocalKeySym, JButton> keyBinds;
|
static std::multimap<LocalKeySym, JButton> keyBinds;
|
||||||
typedef std::multimap<LocalKeySym, JButton>::iterator keycodes_it;
|
typedef std::multimap<LocalKeySym, JButton>::iterator keycodes_it;
|
||||||
|
|
||||||
@@ -171,6 +175,7 @@ class JGE
|
|||||||
/// @return Next pressed button, or 0 if none.
|
/// @return Next pressed button, or 0 if none.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JButton ReadButton();
|
JButton ReadButton();
|
||||||
|
LocalKeySym ReadLocalKey();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Bind an actual key to a symbolic button. A key can be bound to
|
/// Bind an actual key to a symbolic button. A key can be bound to
|
||||||
|
|||||||
@@ -79,18 +79,18 @@ void JGE::PressKey(const LocalKeySym sym)
|
|||||||
{
|
{
|
||||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||||
keyBuffer.push(it->second);
|
keyBuffer.push(*it);
|
||||||
}
|
}
|
||||||
void JGE::PressKey(const JButton sym)
|
void JGE::PressKey(const JButton sym)
|
||||||
{
|
{
|
||||||
keyBuffer.push(sym);
|
keyBuffer.push(make_pair(LOCAL_NO_KEY, sym));
|
||||||
}
|
}
|
||||||
void JGE::HoldKey(const LocalKeySym sym)
|
void JGE::HoldKey(const LocalKeySym sym)
|
||||||
{
|
{
|
||||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||||
{
|
{
|
||||||
keyBuffer.push(it->second);
|
keyBuffer.push(*it);
|
||||||
if (holds.end() == holds.find(it->second))
|
if (holds.end() == holds.find(it->second))
|
||||||
holds[it->second] = REPEAT_DELAY;
|
holds[it->second] = REPEAT_DELAY;
|
||||||
}
|
}
|
||||||
@@ -100,19 +100,19 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
|
|||||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||||
{
|
{
|
||||||
keyBuffer.push(it->second);
|
keyBuffer.push(*it);
|
||||||
if (holds.end() == holds.find(it->second))
|
if (holds.end() == holds.find(it->second))
|
||||||
holds[it->second] = std::numeric_limits<float>::quiet_NaN();
|
holds[it->second] = std::numeric_limits<float>::quiet_NaN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void JGE::HoldKey(const JButton sym)
|
void JGE::HoldKey(const JButton sym)
|
||||||
{
|
{
|
||||||
keyBuffer.push(sym);
|
keyBuffer.push(make_pair(LOCAL_NO_KEY, sym));
|
||||||
if (holds.end() == holds.find(sym)) holds[sym] = REPEAT_DELAY;
|
if (holds.end() == holds.find(sym)) holds[sym] = REPEAT_DELAY;
|
||||||
}
|
}
|
||||||
void JGE::HoldKey_NoRepeat(const JButton sym)
|
void JGE::HoldKey_NoRepeat(const JButton sym)
|
||||||
{
|
{
|
||||||
keyBuffer.push(sym);
|
keyBuffer.push(make_pair(LOCAL_NO_KEY, sym));
|
||||||
if (holds.end() == holds.find(sym)) holds[sym] = std::numeric_limits<float>::quiet_NaN();
|
if (holds.end() == holds.find(sym)) holds[sym] = std::numeric_limits<float>::quiet_NaN();
|
||||||
}
|
}
|
||||||
void JGE::ReleaseKey(const LocalKeySym sym)
|
void JGE::ReleaseKey(const LocalKeySym sym)
|
||||||
@@ -129,7 +129,7 @@ void JGE::Update(float dt)
|
|||||||
{
|
{
|
||||||
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
|
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->second < 0) { keyBuffer.push(it->first); it->second = REPEAT_PERIOD; }
|
if (it->second < 0) { keyBuffer.push(make_pair(LOCAL_NO_KEY, it->first)); it->second = REPEAT_PERIOD; }
|
||||||
it->second -= dt;
|
it->second -= dt;
|
||||||
}
|
}
|
||||||
if (mApp != NULL) mApp->Update();
|
if (mApp != NULL) mApp->Update();
|
||||||
@@ -152,7 +152,15 @@ bool JGE::GetButtonClick(JButton button)
|
|||||||
JButton JGE::ReadButton()
|
JButton JGE::ReadButton()
|
||||||
{
|
{
|
||||||
if (keyBuffer.empty()) return JGE_BTN_NONE;
|
if (keyBuffer.empty()) return JGE_BTN_NONE;
|
||||||
JButton val = keyBuffer.front();
|
JButton val = keyBuffer.front().second;
|
||||||
|
keyBuffer.pop();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalKeySym JGE::ReadLocalKey()
|
||||||
|
{
|
||||||
|
if (keyBuffer.empty()) return LOCAL_NO_KEY;
|
||||||
|
LocalKeySym val = keyBuffer.front().first;
|
||||||
keyBuffer.pop();
|
keyBuffer.pop();
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@@ -440,5 +448,5 @@ void JGE::Assert(const char *filename, long lineNumber)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::queue<JButton> JGE::keyBuffer;
|
std::queue< pair<LocalKeySym, JButton> > JGE::keyBuffer;
|
||||||
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
|
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
|
||||||
|
|||||||
Reference in New Issue
Block a user