Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware keyboard & mice input #29

Merged
merged 14 commits into from
Dec 19, 2017
Merged
5 changes: 5 additions & 0 deletions include/ace/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#define MAX(x,y) ((x)>(y)? (x): (y))
#define CLAMP(x, min, max) ((x) < (min)? (min) : ((x) > (max) ? (max) : (x)))

/**
* Bit value macro - useful for setting & testing bits.
*/
#define BV(x) (1 << (x))

/**
* Checks if given x,y is in specified tRect.
*/
Expand Down
73 changes: 57 additions & 16 deletions include/ace/managers/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@

#include <ace/types.h>
#ifdef AMIGA
#include <clib/intuition_protos.h> // IDCMP_RAWKEY etc
#include <exec/interrupts.h> // struct Interrupt
#endif // AMIGA

#include <ace/types.h>

#include <ace/managers/window.h>

/* ****************************************************************** DEFINES */

/**
Expand Down Expand Up @@ -131,7 +127,7 @@
#define KEY_DEL 0x46
#define KEY_HELP 0x5F

// Key status flags
// Key state flags
#define KEY_NACTIVE 0
#define KEY_USED 1
#define KEY_ACTIVE 2
Expand All @@ -140,6 +136,7 @@
/* ******************************************************************** TYPES */

typedef struct {
struct Interrupt *pInt;
UBYTE pStates[103];
UBYTE ubLastKey;
} tKeyManager;
Expand All @@ -152,19 +149,63 @@ extern const UBYTE g_pToAscii[];

/* **************************************************************** FUNCTIONS */

void keySetState(
/**
* Initializes mouse manager.
*/
void keyCreate(void);

/**
* Cleans up after mouse manager.
*/
void keyDestroy(void);

/**
* Processes key manager, updating keys' states.
* This function should be called once per frame.
*/
void keyProcess(void);

/**
* Sets state of given key.
* @param ubKeyCode: Code of key, which state should be changed.
* @param ubKeyState: Key state (KEY_ACTIVE, KEY_NACTIVE or KEY_USED).
*/
static inline void keySetState(
IN UBYTE ubKeyCode,
IN UBYTE ubKeyState
);
) {
g_sKeyManager.pStates[ubKeyCode] = ubKeyState;
if(ubKeyState == KEY_ACTIVE)
g_sKeyManager.ubLastKey = ubKeyCode;
}

UBYTE keyCheck(
/**
* Polls state of key with given code.
* @param ubKeyCode: Code of key, which state should be polled.
* @return 1 if key is pressed, otherwise 0.
* @see keyUse()
*/
static inline UBYTE keyCheck(
IN UBYTE ubKeyCode
);
) {
return g_sKeyManager.pStates[ubKeyCode] != KEY_NACTIVE;
}

UBYTE keyUse(
/**
* Checks if given key was recently pressed.
* If key's code is ACTIVE, fn returns 1 and changes key state to USED.
* @param ubKeyCode: Code of key, which state should be polled.
* @return 1 if key was recently pressed, otherwise 0.
* @see keyCheck()
*/
static inline UBYTE keyUse(
IN UBYTE ubKeyCode
);

void keyProcess(void);

#endif
) {
if (g_sKeyManager.pStates[ubKeyCode] == KEY_ACTIVE) {
g_sKeyManager.pStates[ubKeyCode] = KEY_USED;
return 1;
}
return 0;
}

#endif
Loading