-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardInput.h
84 lines (67 loc) · 1.91 KB
/
KeyboardInput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef __KEYBOARDINPUT_H__
#define __KEYBOARDINPUT_H__
/**
* KeyboardInput.h
*
* $Revision$
* $Id$
*
* Lukee tickillä näppäinbufferin, ja parsii sen komennoiksi,
* jotka lähetetään komentokuuntelijoille (VCommandListener)
* KeyboardInput on singleton, koska vain yksi luokka vaaditaan
* kuunteluun (yksi näppäimistöbufferi jota lukea..)
*
* Changelog
* - korvattiin Singleton-templaten käyttö paikallisella getInstance:lla
* - vaihdettiin vektori pointteritaulukkoon
*/
#include "TickListener.h"
#include "CommandListener.h"
#include "Observable.h"
#include <stdio.h>
class SKeyboardInput : public VObservable<VCommandListener>, public VTickListener {
friend class VObservable<VCommandListener>;
public:
/** Access to this singleton class */
static SKeyboardInput& getInstance() {
static SKeyboardInput theSingleInstance;
return theSingleInstance;
}
/**
* @see TickListener.h
*/
virtual int handleTick();
private:
// std::vector<VCommandListener*> listeners;
static const int m_tickDelay = 5;
inline void dump(char key) {
printf(" %d ", key);
}
/**
* handleKeyPress(char key)
*
* Parsii näppäinpainalluksen näppäinkoodin mukaan
*
* @param key näppäinkoodi
*/
void handleKeyPress(char key);
/**
* notifyCommand(COMMAND cmd)
*
* Lähettää näppäinpainallukseen assosioidun komennon
* kuuntelijoille.
* @param cmd kuuntelijoille lähetettävä komento
*/
void notifyCommand(VCommandListener::COMMAND cmd);
protected:
/**
* Konstruktori määritellään näkyvyydellä protected, jolloin
* pakotetaan käyttämään getInstance() -metodia
*
* Rekisteröidytään konstruktorissa STickerille tick-listeneriksi,
* että saadaan prosessoriaikaa näppäimistöbufferin lukuun.
*/
SKeyboardInput();
virtual ~SKeyboardInput();
};
#endif // __KEYBOARDINPUT_H__