* Create the subsystem for keybindings.
This commit is contained in:
jean.chalard
2010-02-14 13:21:12 +00:00
parent 4913eec2fb
commit 56ce4a14ae
38 changed files with 2154 additions and 1477 deletions

View File

@@ -16,6 +16,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <queue>
#include <map>
#include "JTypes.h"
@@ -23,27 +25,25 @@
//#define _MP3_ENABLED_
#ifdef WIN32
#if defined(WIN32)
#include <windows.h>
void JGEControl();
BOOL JGEGetKeyState(int key);
bool JGEGetButtonState(u32 button);
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
#elif LINUX
void JGEControl();
BOOL JGEGetKeyState(int key);
bool JGEGetButtonState(u32 button);
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
typedef WPARAM LocalKeySym;
#elif defined(LINUX)
#include <X11/XKBlib.h>
typedef KeySym LocalKeySym;
#else
typedef u32 LocalKeySym;
#endif
bool JGEGetButtonState(const JButton button);
bool JGEGetButtonClick(const JButton button);
void JGECreateDefaultBindings();
int JGEGetTime();
u8 JGEGetAnalogX();
u8 JGEGetAnalogY();
#if !defined(WIN32) && !defined(LINUX)
#include <pspgu.h>
#include <pspkernel.h>
@@ -77,46 +77,32 @@ class JGE
{
private:
JApp *mApp;
// JResourceManager *mResourceManager;
// JFileSystem* mFileSystem;
// JParticleSystem* mParticleSystem;
// JMotionSystem* mMotionSystem;
#if defined (WIN32) || defined (LINUX)
float mDeltaTime;
JMusic *mCurrentMusic;
#else
SceCtrlData mCtrlPad;
u32 mOldButtons;
u32 mVeryOldButtons;
u64 mLastTime;
u32 mTickFrequency;
#endif
bool mDone;
float mDelta;
bool mDebug;
bool mPaused;
char mDebuggingMsg[256];
bool mCriticalAssert;
const char *mAssertFile;
int mAssertLine;
u32 tickFrequency;
static JGE* mInstance;
static std::queue<JButton> keyBuffer;
static std::multimap<LocalKeySym, JButton> keyBinds;
typedef std::multimap<LocalKeySym, JButton>::iterator keycodes_it;
friend void Run();
public:
//////////////////////////////////////////////////////////////////////////
@@ -128,10 +114,9 @@ class JGE
static void Destroy();
void Init();
void Run();
void End();
void Update();
void Update(float);
void Render();
void Pause();
@@ -154,7 +139,7 @@ class JGE
//////////////////////////////////////////////////////////////////////////
/// Return frame rate.
///
/// @note This is just 1.0f/GetDelat().
/// @note This is just 1.0f/GetDelta().
///
/// @return Number of frames per second.
//////////////////////////////////////////////////////////////////////////
@@ -167,29 +152,78 @@ class JGE
///
/// @return Button state.
//////////////////////////////////////////////////////////////////////////
bool GetButtonState(u32 button);
bool GetButtonState(JButton button);
//////////////////////////////////////////////////////////////////////////
/// Check if a button is down the first time.
/// THIS DOES NOT WORK RELIABLY. DO NOT USE THIS.
/// USE ReadButton() INSTEAD.
///
/// @param button - Button id.
///
/// @return Button state.
//////////////////////////////////////////////////////////////////////////
bool GetButtonClick(u32 button);
bool GetButtonClick(JButton button);
//////////////////////////////////////////////////////////////////////////
/// Get the next keypress.
///
/// @return Next pressed button, or 0 if none.
//////////////////////////////////////////////////////////////////////////
u32 ReadButton();
JButton ReadButton();
//////////////////////////////////////////////////////////////////////////
/// Bind an actual key to a symbolic button. A key can be bound to
/// several buttons and even several times to the same button (for
/// double clicks on one button, for example.
///
/// @param keycode - The local code of the key
/// @param button - The button to bind it to
///
/// @return The number of bound keys so far
//////////////////////////////////////////////////////////////////////////
u32 BindKey(LocalKeySym keycode, JButton button);
//////////////////////////////////////////////////////////////////////////
/// Undo a binding.
/// If the second parameter is omitted, remove all bindings to this key ;
/// else, remove exactly once the binding from this key to this button.
///
/// @param keycode - The local code of the key
/// @param button - The button
///
/// @return The number of still bound keys
//////////////////////////////////////////////////////////////////////////
u32 UnbindKey(LocalKeySym keycode, JButton button);
u32 UnbindKey(LocalKeySym keycode);
//////////////////////////////////////////////////////////////////////////
/// Clear bindings.
/// This removes ALL bindings. Take care to re-bind keys after doing it.
///
//////////////////////////////////////////////////////////////////////////
void ClearBindings();
//////////////////////////////////////////////////////////////////////////
/// Reset bindings.
/// This resets ALL bindings to their default value.
///
//////////////////////////////////////////////////////////////////////////
void ResetBindings();
//////////////////////////////////////////////////////////////////////////
/// Iterators for bindings.
//////////////////////////////////////////////////////////////////////////
typedef std::multimap<LocalKeySym, JButton>::const_iterator keybindings_it;
keybindings_it KeyBindings_begin();
keybindings_it KeyBindings_end();
//////////////////////////////////////////////////////////////////////////
/// Reset the input buffer.
/// This is necessary because there might be phases when GetButtonState
/// or GetButtonClick are used, thereby accumulating keypresses in the
/// key buffer.
/// This is necessary because there might be phases when only
/// GetButtonState is used, thereby accumulating keypresses
/// in the key buffer.
///
//////////////////////////////////////////////////////////////////////////
void ResetInput();
@@ -208,13 +242,28 @@ class JGE
//////////////////////////////////////////////////////////////////////////
u8 GetAnalogY();
//////////////////////////////////////////////////////////////////////////
/// Simulate a keypress, or a keyhold/release.
///
//////////////////////////////////////////////////////////////////////////
void PressKey(const LocalKeySym);
void PressKey(const JButton);
void HoldKey(const LocalKeySym);
void HoldKey(const JButton);
void HoldKey_NoRepeat(const LocalKeySym);
void HoldKey_NoRepeat(const JButton);
void ReleaseKey(const LocalKeySym);
void ReleaseKey(const JButton);
//////////////////////////////////////////////////////////////////////////
/// Get if the system is ended or not.
/// Get if the system is ended/paused or not.
///
/// @return Status of the system.
//////////////////////////////////////////////////////////////////////////
bool IsDone() { return mDone; }
bool IsPaused() { return mPaused; }
//////////////////////////////////////////////////////////////////////////
@@ -235,7 +284,7 @@ class JGE
void Assert(const char *filename, long lineNumber);
#if defined (WIN32) || defined (LINUX)
void SetDelta(int delta);
void SetDelta(float delta);
#endif
protected:

View File

@@ -67,7 +67,7 @@ class JGuiController
bool mActive;
u32 mActionButton;
JButton mActionButton;
int mCurr;
int mStyle;
@@ -94,14 +94,14 @@ class JGuiController
virtual void Render();
virtual void Update(float dt);
virtual bool CheckUserInput(u32 key);
virtual bool CheckUserInput(JButton key);
void Add(JGuiObject* ctrl);
void RemoveAt(int i);
void Remove(int id);
void Remove(JGuiObject* ctrl);
void SetActionButton(u32 button);
void SetActionButton(JButton button);
void SetStyle(int style);
void SetCursor(JSprite* cursor);

View File

@@ -86,7 +86,7 @@
#include <GL/glu.h>
#endif
#if defined (WIN32) || defined (LINUX)
#if defined (WIN32) || defined (LINUX)
typedef int8_t s8;
typedef int16_t s16;
@@ -111,25 +111,6 @@ typedef uint32_t u32;
#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define RGBA(r, g, b, a) (((a) << 24) | ((b) << 16) | ((g) << 8) | (r))
typedef enum PspCtrlButtons
{
PSP_CTRL_SELECT = 0x000001,
PSP_CTRL_START = 0x000008,
PSP_CTRL_UP = 0x000010,
PSP_CTRL_RIGHT = 0x000020,
PSP_CTRL_DOWN = 0x000040,
PSP_CTRL_LEFT = 0x000080,
PSP_CTRL_LTRIGGER = 0x000100,
PSP_CTRL_RTRIGGER = 0x000200,
PSP_CTRL_TRIANGLE = 0x001000,
PSP_CTRL_CIRCLE = 0x002000,
PSP_CTRL_CROSS = 0x004000,
PSP_CTRL_SQUARE = 0x008000,
PSP_CTRL_HOME = 0x010000,
PSP_CTRL_HOLD = 0x020000,
PSP_CTRL_NOTE = 0x800000
} PspCtrlButtons;
#define TEXTURE_FORMAT 0
#define GU_PSM_8888 0
#define GU_PSM_5551 0
@@ -228,6 +209,29 @@ typedef uint32_t u32;
typedef enum Buttons
{
JGE_BTN_NONE = 0, // No button pressed
JGE_BTN_QUIT, // Home on PSP
JGE_BTN_MENU, // Start on PSP
JGE_BTN_CTRL, // Select
JGE_BTN_POWER, // Hold
JGE_BTN_SOUND, // Music note
JGE_BTN_RIGHT,
JGE_BTN_LEFT,
JGE_BTN_UP,
JGE_BTN_DOWN,
JGE_BTN_OK, // Circle in Japan, Cross in Europe
JGE_BTN_CANCEL, // Triangle
JGE_BTN_PRI, // Square (primary)
JGE_BTN_SEC, // Cross or Circle (secondary)
JGE_BTN_PREV, // Left trigger
JGE_BTN_NEXT, // Right trigger
JGE_BTN_MAX = JGE_BTN_NEXT + 1
} JButton;
//------------------------------------------------------------------------------------------------
struct Vertex