Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
13 KB
Referenced Files
None
Subscribers
None
diff --git a/util/keyboard.cpp b/util/keyboard.cpp
index 2c8b7b04..6bf59e3e 100644
--- a/util/keyboard.cpp
+++ b/util/keyboard.cpp
@@ -1,92 +1,191 @@
#include "keyboard.h"
#include "allegro.h"
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#ifndef debug
#define debug cout<<"File: "<<__FILE__<<" Line: "<<__LINE__<<endl;
#endif
-const int Keyboard::Key_A = KEY_A;
-const int Keyboard::Key_S = KEY_S;
-const int Keyboard::Key_D = KEY_D;
-const int Keyboard::Key_P = KEY_P;
-
-const int Keyboard::Key_LEFT = KEY_LEFT;
-const int Keyboard::Key_RIGHT = KEY_RIGHT;
-const int Keyboard::Key_UP = KEY_UP;
-const int Keyboard::Key_DOWN = KEY_DOWN;
-const int Keyboard::Key_ENTER = KEY_ENTER;
-const int Keyboard::Key_SPACE = KEY_SPACE;
-const int Keyboard::Key_F1 = KEY_F1;
-const int Keyboard::Key_F2 = KEY_F2;
-const int Keyboard::Key_F3 = KEY_F3;
-const int Keyboard::Key_F4 = KEY_F4;
-const int Keyboard::Key_F5 = KEY_F5;
-const int Keyboard::Key_F6 = KEY_F6;
-const int Keyboard::Key_F7 = KEY_F7;
-const int Keyboard::Key_F8 = KEY_F8;
-const int Keyboard::Key_F9 = KEY_F9;
-const int Keyboard::Key_F10 = KEY_F10;
-const int Keyboard::Key_F11 = KEY_F11;
-const int Keyboard::Key_F12 = KEY_F12;
-const int Keyboard::Key_ESC = KEY_ESC;
-
-const int Keyboard::Key_MINUS_PAD = KEY_MINUS_PAD;
-const int Keyboard::Key_PLUS_PAD = KEY_PLUS_PAD;
-const int Keyboard::Key_ENTER_PAD = KEY_ENTER_PAD;
+const int Keyboard::Key_A = ::KEY_A;
+const int Keyboard::Key_B = ::KEY_B;
+const int Keyboard::Key_C = ::KEY_C;
+const int Keyboard::Key_D = ::KEY_D;
+const int Keyboard::Key_E = ::KEY_E;
+const int Keyboard::Key_F = ::KEY_F;
+const int Keyboard::Key_G = ::KEY_G;
+const int Keyboard::Key_H = ::KEY_H;
+const int Keyboard::Key_I = ::KEY_I;
+const int Keyboard::Key_J = ::KEY_J;
+const int Keyboard::Key_K = ::KEY_K;
+const int Keyboard::Key_L = ::KEY_L;
+const int Keyboard::Key_M = ::KEY_M;
+const int Keyboard::Key_N = ::KEY_N;
+const int Keyboard::Key_O = ::KEY_O;
+const int Keyboard::Key_P = ::KEY_P;
+const int Keyboard::Key_Q = ::KEY_Q;
+const int Keyboard::Key_R = ::KEY_R;
+const int Keyboard::Key_S = ::KEY_S;
+const int Keyboard::Key_T = ::KEY_T;
+const int Keyboard::Key_U = ::KEY_U;
+const int Keyboard::Key_V = ::KEY_V;
+const int Keyboard::Key_W = ::KEY_W;
+const int Keyboard::Key_X = ::KEY_X;
+const int Keyboard::Key_Y = ::KEY_Y;
+const int Keyboard::Key_Z = ::KEY_Z;
+const int Keyboard::Key_0 = ::KEY_0;
+const int Keyboard::Key_1 = ::KEY_1;
+const int Keyboard::Key_2 = ::KEY_2;
+const int Keyboard::Key_3 = ::KEY_3;
+const int Keyboard::Key_4 = ::KEY_4;
+const int Keyboard::Key_5 = ::KEY_5;
+const int Keyboard::Key_6 = ::KEY_6;
+const int Keyboard::Key_7 = ::KEY_7;
+const int Keyboard::Key_8 = ::KEY_8;
+const int Keyboard::Key_9 = ::KEY_9;
+const int Keyboard::Key_0_PAD = ::KEY_0_PAD;
+const int Keyboard::Key_1_PAD = ::KEY_1_PAD;
+const int Keyboard::Key_2_PAD = ::KEY_2_PAD;
+const int Keyboard::Key_3_PAD = ::KEY_3_PAD;
+const int Keyboard::Key_4_PAD = ::KEY_4_PAD;
+const int Keyboard::Key_5_PAD = ::KEY_5_PAD;
+const int Keyboard::Key_6_PAD = ::KEY_6_PAD;
+const int Keyboard::Key_7_PAD = ::KEY_7_PAD;
+const int Keyboard::Key_8_PAD = ::KEY_8_PAD;
+const int Keyboard::Key_9_PAD = ::KEY_9_PAD;
+const int Keyboard::Key_F1 = ::KEY_F1;
+const int Keyboard::Key_F2 = ::KEY_F2;
+const int Keyboard::Key_F3 = ::KEY_F3;
+const int Keyboard::Key_F4 = ::KEY_F4;
+const int Keyboard::Key_F5 = ::KEY_F5;
+const int Keyboard::Key_F6 = ::KEY_F6;
+const int Keyboard::Key_F7 = ::KEY_F7;
+const int Keyboard::Key_F8 = ::KEY_F8;
+const int Keyboard::Key_F9 = ::KEY_F9;
+const int Keyboard::Key_F10 = ::KEY_F10;
+const int Keyboard::Key_F11 = ::KEY_F11;
+const int Keyboard::Key_F12 = ::KEY_F12;
+const int Keyboard::Key_ESC = ::KEY_ESC;
+const int Keyboard::Key_TILDE = ::KEY_TILDE;
+const int Keyboard::Key_MINUS = ::KEY_MINUS;
+const int Keyboard::Key_EQUALS = ::KEY_EQUALS;
+const int Keyboard::Key_BACKSPACE = ::KEY_BACKSPACE;
+const int Keyboard::Key_TAB = ::KEY_TAB;
+const int Keyboard::Key_OPENBRACE = ::KEY_OPENBRACE;
+const int Keyboard::Key_CLOSEBRACE = ::KEY_CLOSEBRACE;
+const int Keyboard::Key_ENTER = ::KEY_ENTER;
+const int Keyboard::Key_COLON = ::KEY_COLON;
+const int Keyboard::Key_QUOTE = ::KEY_QUOTE;
+const int Keyboard::Key_BACKSLASH = ::KEY_BACKSLASH;
+const int Keyboard::Key_BACKSLASH2 = ::KEY_BACKSLASH2;
+const int Keyboard::Key_COMMA = ::KEY_COMMA;
+const int Keyboard::Key_STOP = ::KEY_STOP;
+const int Keyboard::Key_SLASH = ::KEY_SLASH;
+const int Keyboard::Key_SPACE = ::KEY_SPACE;
+const int Keyboard::Key_INSERT = ::KEY_INSERT;
+const int Keyboard::Key_DEL = ::KEY_DEL;
+const int Keyboard::Key_HOME = ::KEY_HOME;
+const int Keyboard::Key_END = ::KEY_END;
+const int Keyboard::Key_PGUP = ::KEY_PGUP;
+const int Keyboard::Key_PGDN = ::KEY_PGDN;
+const int Keyboard::Key_LEFT = ::KEY_LEFT;
+const int Keyboard::Key_RIGHT = ::KEY_RIGHT;
+const int Keyboard::Key_UP = ::KEY_UP;
+const int Keyboard::Key_DOWN = ::KEY_DOWN;
+const int Keyboard::Key_SLASH_PAD = ::KEY_SLASH_PAD;
+const int Keyboard::Key_ASTERISK = ::KEY_ASTERISK;
+const int Keyboard::Key_MINUS_PAD = ::KEY_MINUS_PAD;
+const int Keyboard::Key_PLUS_PAD = ::KEY_PLUS_PAD;
+const int Keyboard::Key_DEL_PAD = ::KEY_DEL_PAD;
+const int Keyboard::Key_ENTER_PAD = ::KEY_ENTER_PAD;
+const int Keyboard::Key_PRTSCR = ::KEY_PRTSCR;
+const int Keyboard::Key_PAUSE = ::KEY_PAUSE;
+const int Keyboard::Key_ABNT_C1 = ::KEY_ABNT_C1;
+const int Keyboard::Key_YEN = ::KEY_YEN;
+const int Keyboard::Key_KANA = ::KEY_KANA;
+const int Keyboard::Key_CONVERT = ::KEY_CONVERT;
+const int Keyboard::Key_NOCONVERT = ::KEY_NOCONVERT;
+const int Keyboard::Key_AT = ::KEY_AT;
+const int Keyboard::Key_CIRCUMFLEX = ::KEY_CIRCUMFLEX;
+const int Keyboard::Key_COLON2 = ::KEY_COLON2;
+const int Keyboard::Key_KANJI = ::KEY_KANJI;
+const int Keyboard::Key_EQUALS_PAD = ::KEY_EQUALS_PAD;
+const int Keyboard::Key_BACKQUOTE = ::KEY_BACKQUOTE;
+const int Keyboard::Key_SEMICOLON = ::KEY_SEMICOLON;
+const int Keyboard::Key_COMMAND = ::KEY_COMMAND;
+const int Keyboard::Key_UNKNOWN1 = ::KEY_UNKNOWN1;
+const int Keyboard::Key_UNKNOWN2 = ::KEY_UNKNOWN2;
+const int Keyboard::Key_UNKNOWN3 = ::KEY_UNKNOWN3;
+const int Keyboard::Key_UNKNOWN4 = ::KEY_UNKNOWN4;
+const int Keyboard::Key_UNKNOWN5 = ::KEY_UNKNOWN5;
+const int Keyboard::Key_UNKNOWN6 = ::KEY_UNKNOWN6;
+const int Keyboard::Key_UNKNOWN7 = ::KEY_UNKNOWN7;
+const int Keyboard::Key_UNKNOWN8 = ::KEY_UNKNOWN8;
+const int Keyboard::Key_MODIFIERS = ::KEY_MODIFIERS;
+const int Keyboard::Key_LSHIFT = ::KEY_LSHIFT;
+const int Keyboard::Key_RSHIFT = ::KEY_RSHIFT;
+const int Keyboard::Key_LCONTROL = ::KEY_LCONTROL;
+const int Keyboard::Key_RCONTROL = ::KEY_RCONTROL;
+const int Keyboard::Key_ALT = ::KEY_ALT;
+const int Keyboard::Key_ALTGR = ::KEY_ALTGR;
+const int Keyboard::Key_LWIN = ::KEY_LWIN;
+const int Keyboard::Key_RWIN = ::KEY_RWIN;
+const int Keyboard::Key_MENU = ::KEY_MENU;
+const int Keyboard::Key_SCRLOCK = ::KEY_SCRLOCK;
+const int Keyboard::Key_NUMLOCK = ::KEY_NUMLOCK;
+const int Keyboard::Key_CAPSLOCK = ::KEY_CAPSLOCK;
Keyboard::Keyboard(){
}
/* KEY_MAX is defined in allegro at
* allegro/include/allegro/keyboard.h
*/
void Keyboard::poll(){
for ( int q = 0; q < KEY_MAX; q++ ){
// my_keys[ q ] = key[ q ];
if ( key[ q ] ){
/* my_keys[ q ] becomes negative so that the key
* can be pressed the first time without having
* to wait for a delay
*/
if ( my_keys[ q ] <= 0 ){
my_keys[ q ] -= 1;
} else {
my_keys[ q ] += 1;
}
// printf( "Key %d = %d\n", q, my_keys[ q ] );
} else {
my_keys[ q ] = 0;
}
}
}
void Keyboard::readKeys( vector< int > & all_keys ){
for ( map<int,int>::const_iterator it = my_keys.begin(); it != my_keys.end(); it++ ){
const int & key = it->first;
const int & delay = it->second;
if ( delay < 0 || delay > key_delay[ key ] ){
all_keys.push_back( key );
}
}
}
void Keyboard::setDelay( const int key, const int delay ){
key_delay[ key ] = delay;
}
const bool Keyboard::keypressed(){
for ( map<int,int>::const_iterator it = my_keys.begin(); it != my_keys.end(); it++ ){
const int & n = (*it).second;
if ( n < 0 || n > key_delay[ it->first ] ){
return true;
}
}
return false;
}
diff --git a/util/keyboard.h b/util/keyboard.h
index 03059508..f6037c05 100644
--- a/util/keyboard.h
+++ b/util/keyboard.h
@@ -1,89 +1,187 @@
#ifndef _keyboard_h
#define _keyboard_h
#include <map>
#include <vector>
using namespace std;
/* handles allegro key[] array better than keypressed()
* and readkey()
*/
class Keyboard{
public:
Keyboard();
/* poll:
* Put the keys in Allegro's key[] array into our map of int -> bool
*/
void poll();
/* []:
* Extract a boolean value given a key number
*/
inline const bool operator[] ( const int i ){
/* if the key has been pressed for the first time return true */
if ( my_keys[ i ] < 0 ){
my_keys[ i ] = 1;
return true;
}
bool b = my_keys[ i ] > key_delay[ i ];
if ( b ){
my_keys[ i ] = 1;
}
return b;
}
/* keypressed:
* Returns true if a key is pressed
*/
const bool keypressed();
/* readKeys:
* Store all pressed keys in a user supplied vector
*/
void readKeys( vector< int > & all_keys );
void setDelay( const int key, const int delay );
static const int Key_A;
- static const int Key_S;
+ static const int Key_B;
+ static const int Key_C;
static const int Key_D;
+ static const int Key_E;
+ static const int Key_F;
+ static const int Key_G;
+ static const int Key_H;
+ static const int Key_I;
+ static const int Key_J;
+ static const int Key_K;
+ static const int Key_L;
+ static const int Key_M;
+ static const int Key_N;
+ static const int Key_O;
static const int Key_P;
-
- static const int Key_LEFT;
- static const int Key_RIGHT;
- static const int Key_UP;
- static const int Key_DOWN;
- static const int Key_SPACE;
- static const int Key_ENTER;
-
+ static const int Key_Q;
+ static const int Key_R;
+ static const int Key_S;
+ static const int Key_T;
+ static const int Key_U;
+ static const int Key_V;
+ static const int Key_W;
+ static const int Key_X;
+ static const int Key_Y;
+ static const int Key_Z;
+ static const int Key_0;
+ static const int Key_1;
+ static const int Key_2;
+ static const int Key_3;
+ static const int Key_4;
+ static const int Key_5;
+ static const int Key_6;
+ static const int Key_7;
+ static const int Key_8;
+ static const int Key_9;
+ static const int Key_0_PAD;
+ static const int Key_1_PAD;
+ static const int Key_2_PAD;
+ static const int Key_3_PAD;
+ static const int Key_4_PAD;
+ static const int Key_5_PAD;
+ static const int Key_6_PAD;
+ static const int Key_7_PAD;
+ static const int Key_8_PAD;
+ static const int Key_9_PAD;
static const int Key_F1;
static const int Key_F2;
static const int Key_F3;
static const int Key_F4;
static const int Key_F5;
static const int Key_F6;
static const int Key_F7;
static const int Key_F8;
static const int Key_F9;
static const int Key_F10;
static const int Key_F11;
static const int Key_F12;
static const int Key_ESC;
-
+ static const int Key_TILDE;
+ static const int Key_MINUS;
+ static const int Key_EQUALS;
+ static const int Key_BACKSPACE;
+ static const int Key_TAB;
+ static const int Key_OPENBRACE;
+ static const int Key_CLOSEBRACE;
+ static const int Key_ENTER;
+ static const int Key_COLON;
+ static const int Key_QUOTE;
+ static const int Key_BACKSLASH;
+ static const int Key_BACKSLASH2;
+ static const int Key_COMMA;
+ static const int Key_STOP;
+ static const int Key_SLASH;
+ static const int Key_SPACE;
+ static const int Key_INSERT;
+ static const int Key_DEL;
+ static const int Key_HOME;
+ static const int Key_END;
+ static const int Key_PGUP;
+ static const int Key_PGDN;
+ static const int Key_LEFT;
+ static const int Key_RIGHT;
+ static const int Key_UP;
+ static const int Key_DOWN;
+ static const int Key_SLASH_PAD;
+ static const int Key_ASTERISK;
static const int Key_MINUS_PAD;
static const int Key_PLUS_PAD;
+ static const int Key_DEL_PAD;
static const int Key_ENTER_PAD;
+ static const int Key_PRTSCR;
+ static const int Key_PAUSE;
+ static const int Key_ABNT_C1;
+ static const int Key_YEN;
+ static const int Key_KANA;
+ static const int Key_CONVERT;
+ static const int Key_NOCONVERT;
+ static const int Key_AT;
+ static const int Key_CIRCUMFLEX;
+ static const int Key_COLON2;
+ static const int Key_KANJI;
+ static const int Key_EQUALS_PAD;
+ static const int Key_BACKQUOTE;
+ static const int Key_SEMICOLON;
+ static const int Key_COMMAND;
+ static const int Key_UNKNOWN1;
+ static const int Key_UNKNOWN2;
+ static const int Key_UNKNOWN3;
+ static const int Key_UNKNOWN4;
+ static const int Key_UNKNOWN5;
+ static const int Key_UNKNOWN6;
+ static const int Key_UNKNOWN7;
+ static const int Key_UNKNOWN8;
+ static const int Key_MODIFIERS;
+ static const int Key_LSHIFT;
+ static const int Key_RSHIFT;
+ static const int Key_LCONTROL;
+ static const int Key_RCONTROL;
+ static const int Key_ALT;
+ static const int Key_ALTGR;
+ static const int Key_LWIN;
+ static const int Key_RWIN;
+ static const int Key_MENU;
+ static const int Key_SCRLOCK;
+ static const int Key_NUMLOCK;
+ static const int Key_CAPSLOCK;
protected:
map<int,int> my_keys;
map<int,int> key_delay;
};
#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 2:10 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69400
Default Alt Text
(13 KB)

Event Timeline