persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
keyboard.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <etl/vector.h>
10#include <nds.h>
11
15enum class KEYCODES
16{
19 SHIFT = 2,
21 LEFT = 4,
22 RIGHT = 5,
24};
25
30struct Key
31{
32 int topX;
34
35 char key;
36
37 bool keyHit(int x)
38 {
39 if (x >= topX && x <= bottomX)
40 {
41 return true;
42 }
43 return false;
44 }
45};
46
50struct KeyRow
51{
52 int topY;
54
55 etl::vector<Key, 12> keys;
56 void addKey(Key key)
57 {
58 keys.push_back(key);
59 }
60
61 char checkRow(int x)
62 {
63 for (Key& key : keys)
64 {
65 if (key.keyHit(x))
66 {
67 return key.key;
68 }
69 }
70 return 0;
71 }
72};
73
79{
80 public:
81 OnScreenKeyboard() = default;
82 ~OnScreenKeyboard() = default;
83
90 int evaluateInput(touchPosition* touch);
91
95 void reset();
96
97 private:
98 bool isCapsLock = false;
99 bool isShift = false;
100
102 80,
103 94,
104 {{27, 41, '1'},
105 {44, 58, '2'},
106 {61, 75, '3'},
107 {78, 92, '4'},
108 {95, 109, '5'},
109 {112, 126, '6'},
110 {129, 143, '7'},
111 {146, 160, '8'},
112 {163, 177, '9'},
113 {180, 194, '0'}},
114 },
115 {
116 97,
117 111,
118 {{36, 50, 'q'},
119 {53, 67, 'w'},
120 {70, 84, 'e'},
121 {87, 101, 'r'},
122 {104, 118, 't'},
123 {121, 135, 'y'},
124 {138, 152, 'u'},
125 {155, 169, 'i'},
126 {172, 186, 'o'},
127 {189, 203, 'p'},
128 {206, 220, '['},
129 {223, 237, ']'}},
130 },
131 {114,
132 128,
133 {
134 {19, 41, static_cast<char>(KEYCODES::CAPSLOCK)},
135 {44, 58, 'a'},
136 {61, 75, 's'},
137 {78, 92, 'd'},
138 {95, 109, 'f'},
139 {112, 126, 'g'},
140 {129, 143, 'h'},
141 {146, 160, 'j'},
142 {163, 177, 'k'},
143 {180, 194, 'l'},
144 {197, 211, ';'},
145 {214, 228, '\''},
146 }},
147 {131,
148 145,
149 {
150 {19, 50, static_cast<char>(KEYCODES::SHIFT)},
151 {53, 67, 'z'},
152 {70, 84, 'x'},
153 {87, 101, 'c'},
154 {104, 118, 'v'},
155 {121, 135, 'b'},
156 {138, 152, 'n'},
157 {155, 169, 'm'},
158 {172, 186, ','},
159 {189, 203, '.'},
160 {206, 220, '/'},
161 }},
162 {148,
163 162,
164 {
165 {19, 50, static_cast<char>(KEYCODES::LEFT)},
166 {53, 84, static_cast<char>(KEYCODES::RIGHT)},
167 {87, 186, ' '},
168 {189, 228, static_cast<char>(KEYCODES::BACKSPACE)},
169 }},
170 {170, 184, {{100, 155, static_cast<char>(KEYCODES::CONFIRM)}}}};
171};
int evaluateInput(touchPosition *touch)
Checks a touch input against the keyboard positions and returns pressed charcater.
Definition keyboard.cpp:4
~OnScreenKeyboard()=default
KeyRow keyboardRows[6]
Definition keyboard.hpp:101
void reset()
Resets all internal variables to their defaults.
Definition keyboard.cpp:42
OnScreenKeyboard()=default
KEYCODES
Collection of keycodes for special keys on the keyboard.
Definition keyboard.hpp:16
@ CAPSLOCK
Zero is reserved for not touching the keyboard.
Definition keyboard.hpp:18
Stores a row of keys on a keyboard and their associated y boundaries.
Definition keyboard.hpp:51
void addKey(Key key)
Definition keyboard.hpp:56
etl::vector< Key, 12 > keys
Definition keyboard.hpp:55
int bottomY
Definition keyboard.hpp:53
int topY
Definition keyboard.hpp:52
char checkRow(int x)
Definition keyboard.hpp:61
Represent a single key on the keyboard. Stores x bounadaries and the associated key.
Definition keyboard.hpp:31
int topX
Definition keyboard.hpp:32
char key
Definition keyboard.hpp:35
int bottomX
Definition keyboard.hpp:33
bool keyHit(int x)
Definition keyboard.hpp:37