-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixHandler.h
37 lines (31 loc) · 862 Bytes
/
MatrixHandler.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
#ifndef MATRIX_HANDLER_H
#define MATRIX_HANDLER_H
#include "MatrixKeyboard.h"
#include "KeyHandler.h"
template<byte WIDTH, byte HEIGHT>
class MatrixHandler {
public:
MatrixHandler(MatrixKeyboard<WIDTH, HEIGHT> keyboard, IKeyHandler* keyHandler)
: keyboard(keyboard)
, handler(keyHandler)
{}
void onSetup() {
this->keyboard.onSetup();
}
void onFrame() {
this->keyboard.onFrame();
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
if (this->keyboard.getButton(x, y).justPressed()) {
this->handler->onPressed(x, y);
} else if (this->keyboard.getButton(x, y).justReleased()) {
this->handler->onReleased(x, y);
}
}
}
}
private:
MatrixKeyboard<WIDTH, HEIGHT> keyboard;
IKeyHandler* handler;
};
#endif