Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/util/keyboard.cpp b/util/keyboard.cpp
index a2d2aa09..0db21b15 100644
--- a/util/keyboard.cpp
+++ b/util/keyboard.cpp
@@ -1,81 +1,91 @@
#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_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;
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 3eb83d37..a7b58e41 100644
--- a/util/keyboard.h
+++ b/util/keyboard.h
@@ -1,78 +1,88 @@
#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_D;
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_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_MINUS_PAD;
static const int Key_PLUS_PAD;
static const int Key_ENTER_PAD;
protected:
map<int,int> my_keys;
map<int,int> key_delay;
};
#endif

File Metadata

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

Event Timeline