Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Public Member Functions | Public Attributes | List of all members
EKeyboard Class Reference
Inheritance diagram for EKeyboard:
Inheritance graph
[legend]
Collaboration diagram for EKeyboard:
Collaboration graph
[legend]

Public Member Functions

 EKeyboard (std::function< void(char)> typeAction)
 
void render (Element *parent)
 display the current state of the display More...
 
bool process (InputEvents *event)
 process any input that is received for this element More...
 
void updateSize ()
 
void just_type (const char input)
 
bool listenForPhysicalKeys (InputEvents *e)
 
const std::string & getTextInput ()
 
int rowCount ()
 
int rowLength (int row)
 
void type (int y, int x)
 
void generateEKeyboard ()
 
void backspace ()
 
- Public Member Functions inherited from Element
virtual bool process (InputEvents *event)
 process any input that is received for this element More...
 
virtual void render (Element *parent)
 display the current state of the display More...
 
bool onTouchDown (InputEvents *event)
 
bool onTouchDrag (InputEvents *event)
 
bool onTouchUp (InputEvents *event)
 
void hide ()
 
void unhide ()
 
void renderBackground (bool fill=true)
 
void append (Element *element)
 
void remove (Element *element)
 
void removeAll (bool moveToTrash=false)
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
void wipeAll (bool delSelf=false)
 
Elementchild (Element *child)
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementcenterHorizontallyIn (Element *parent)
 
ElementcenterVerticallyIn (Element *parent)
 
ElementcenterIn (Element *parent)
 
ElementsetAbsolute (bool isAbs)
 
Elementconstrain (int flags, int padding=0)
 
Elementanimate (int durationIn, std::function< void(float)> onStep, std::function< void()> onFinish)
 
ElementmoveToFront ()
 
ElementsetTouchable (bool touchable)
 
void screenshot (std::string path)
 Take a screenshot of this element and its children, and save it to the given path. More...
 

Public Attributes

std::string textInput
 
std::function< void(char)> typeAction = NULL
 
const char * lower_keys = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"
 
const char * upper_keys = "~!@#$\%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"
 
int breaks [4] = { 13, 13, 11, 10 }
 
std::vector< std::string * > rows
 
const CST_Keycode usbKeys [KEYCODE_COUNT]
 
bool shiftOn = false
 
bool capsOn = false
 
int mode = 0
 
int curRow = -1
 
int index = -1
 
int keyWidth = 0
 
int padding = 0
 
int textSize = 0
 
int dPos = 0
 
int dHeight = 0
 
int sPos = 0
 
int enterPos = 0
 
int enterHeight = 0
 
int dWidth = 0
 
int sWidth = 0
 
int enterWidth = 0
 
int kXPad = 0
 
int kXOff = 0
 
int yYOff = 0
 
int kYPad = 0
 
int ySpacing = 0
 
bool hasRoundedKeys = false
 
CST_Font * roundKeyFont = NULL
 
bool touchMode = false
 
bool immersiveMode = false
 
bool preventEnterAndTab = false
 
bool storeOwnText = false
 
bool isTouchDrag = false
 
- Public Attributes inherited from Element
std::function< void()> action = NULL
 the action to call (from binded callback) on touch or button selection https://stackoverflow.com/questions/14189440/c-class-member-callback-simple-examples More...
 
std::function< void(InputEvents *event)> actionWithEvents = NULL
 
std::vector< Element * > elements
 visible GUI child elements of this element More...
 
float scale = 1.0f
 
bool touchable = false
 whether or not this element can be touched (highlights bounds) More...
 
bool dragging = false
 whether or not this element is currently being dragged More...
 
bool needsRedraw = false
 whether or not this element needs the screen redrawn next time it's processed More...
 
int futureRedrawCounter = 0
 whether this element needs a redraw for the next X redraws (decreases each time) (0 is no redraws) More...
 
int lastMouseY = 0
 the last Y, X coordinate of the mouse (from a drag probably) More...
 
int lastMouseX = 0
 
bool hasBackground = false
 
rgb backgroundColor = {0, 0, 0}
 
bool isAbsolute = false
 
Elementparent = NULL
 the parent element (can sometimes be null if it isn't set) More...
 
bool hidden = false
 whether this element should skip rendering or not More...
 
bool isProtected = false
 
int elasticCounter = 0
 how much time is left in an elastic-type flick/scroll set by the last distance traveled in a scroll, and counts down every frame More...
 
int width = 0
 width and height of this element (must be manually set, isn't usually calculated (but is in some cases, like text or images)) More...
 
int height = 0
 
int x = 0
 
int y = 0
 
int xAbs = 0
 
int yAbs = 0
 
double angle = 0
 rotation angle in degrees More...
 
int xOff = 0
 
int yOff = 0
 
std::vector< Constraint * > constraints
 
std::vector< Animation * > animations
 
bool useColorMask = false
 whether or not to overlay a color mask on top of this element More...
 
CST_Color maskColor = {0,0,0,0}
 The color to overlay on top. More...
 

Additional Inherited Members

- Public Types inherited from Element
typedef Element super
 

Detailed Description

Definition at line 7 of file EKeyboard.hpp.

Constructor & Destructor Documentation

◆ EKeyboard() [1/2]

EKeyboard::EKeyboard ( )

Definition at line 5 of file EKeyboard.cpp.

5 : EKeyboard::EKeyboard(NULL)
6{
7 storeOwnText = true;
8}

◆ EKeyboard() [2/2]

EKeyboard::EKeyboard ( std::function< void(char)>  typeAction)

Definition at line 10 of file EKeyboard.cpp.

11{
12 this->x = 30;
13 this->y = SCREEN_HEIGHT - 420;
14
15 this->width = SCREEN_WIDTH - 380;
16
17 this->typeAction = typeAction;
18
19 curRow = index = -1;
20 this->isAbsolute = true;
21
22 // position the EKeyboard based on this x and y
23 updateSize();
24}
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:118

◆ ~EKeyboard()

EKeyboard::~EKeyboard ( )

Definition at line 633 of file EKeyboard.cpp.

634{
635 InputEvents::bypassKeyEvents = false;
636}

Member Function Documentation

◆ backspace()

void EKeyboard::backspace ( )

Definition at line 609 of file EKeyboard.cpp.

610{
611 if (storeOwnText) {
612 // manage our own internal string
613 if (!textInput.empty())
614 textInput.pop_back();
615 // call out to the typing callback TODO: use a separate callback (see below)
616 typeAction('\b'); // not great
617 return;
618 }
619
620 // TODO: use a backspace callback instead of hardcoding a B button event
621 // (B is used by vgedit to manage external backspaces)
622 SDL_Event sdlevent;
623 sdlevent.type = SDL_JOYBUTTONDOWN;
624 sdlevent.jbutton.button = SDL_B;
625 SDL_PushEvent(&sdlevent);
626}

◆ generateEKeyboard()

void EKeyboard::generateEKeyboard ( )

Definition at line 563 of file EKeyboard.cpp.

564{
565 int count = 0;
566 string keys;
567
568 if (mode == 0)
569 keys = string((shiftOn || capsOn) ? upper_keys : lower_keys);
570 else
571 {
572 // depending on the mode, grab a bunch of characters from unicode starting from
573 // upside exclamation mark (U+00A1) and onward https://unicode-table.com/en/
574 // TODO: don't hardcode amount here, or hardcode a better one
575 int offset = 47 * (mode - 1) + 0x00a1;
576 char chars[47 + (mode == 2)];
577 for (int x = 0; x < 47 + (mode == 2); x++)
578 {
579 chars[x] = offset + x;
580 }
581
582 keys = string(chars);
583 }
584
585 breaks[3] += (mode == 2); // one more key for bottom row of mode 2
586
587 for (int& end : breaks)
588 {
589 auto roundedOffset = (hasRoundedKeys && count == 0) ? 1 : 0;
590 string* row = new string(keys.substr(count + roundedOffset, end - roundedOffset));
591 for (int x = 1; x < (int)row->size(); x += 2)
592 {
593 row->insert(row->begin() + x, ' ');
594 }
595
596 rows.push_back(row);
597 count += end;
598 }
599
600 if (hasRoundedKeys && roundKeyFont == NULL) {
601 // load the round key font
602 roundKeyFont = CST_CreateFont();
603 auto fontPath = RAMFS "res/lightsans.ttf";
604 auto renderer = getRenderer();
605 CST_LoadFont(roundKeyFont, renderer, fontPath, 40, CST_MakeColor(0,0,0,255), TTF_STYLE_NORMAL);
606 }
607}

◆ getTextInput()

const std::string & EKeyboard::getTextInput ( )

Definition at line 628 of file EKeyboard.cpp.

629{
630 return textInput;
631}

◆ just_type()

void EKeyboard::just_type ( const char  input)

Definition at line 547 of file EKeyboard.cpp.

548{
549 if (preventEnterAndTab && (input == '\n' || input == '\t'))
550 return;
551
552 // store our own string if we need to
553 if (storeOwnText)
554 textInput.push_back(input);
555
556 // call the underlying type action, if present
557 if (typeAction != NULL) {
558 typeAction(input);
559 return;
560 }
561}

◆ listenForPhysicalKeys()

bool EKeyboard::listenForPhysicalKeys ( InputEvents e)

Definition at line 354 of file EKeyboard.cpp.

355{
356 int curBreak = 0;
357 int offset = 0;
358
359 auto keyCode = e->keyCode;
360 auto mod = e->mod;
361
362 // special keys
363 if (keyCode == SDLK_LSHIFT || keyCode == SDLK_RSHIFT || keyCode == SDLK_CAPSLOCK) {
364 shiftOn = true;
365 updateSize();
366 return true;
367 }
368
369 if (keyCode == SDLK_TAB) {
370 just_type('\t');
371 return true;
372 }
373 if (keyCode == SDLK_SPACE) {
374 just_type(' ');
375 return true;
376 }
377 if (keyCode == SDLK_RETURN && !preventEnterAndTab) {
378 just_type('\n');
379 return true;
380 }
381
382 // alt key will toggle the keyboard, but still allow inputs
383 if (keyCode == SDLK_LALT || keyCode == SDLK_RALT) {
384 immersiveMode = !immersiveMode;
385 return true;
386 }
387
388 // primary typing loop, handles all the keycodes on our keyboard
389 auto roundedOffset = hasRoundedKeys ? 1 : 0;
390 for (int x=roundedOffset; x<KEYCODE_COUNT; x++)
391 {
392 int xx = x - offset;
393 int topRowOffset = curBreak == 0 ? roundedOffset : 0;
394
395 if (keyCode == usbKeys[x])
396 {
397 // we got a key down for this code, type our current position
398 // and update cursor
399 type(curBreak, xx - topRowOffset);
400 curRow = curBreak;
401 index = xx - topRowOffset;
402 return true;
403 }
404
405 if (xx + 1 >= breaks[curBreak]) {
406 curBreak++;
407 offset = x + 1;
408 }
409 }
410
411 // below are progammatic invocations of certain features we expect to be there
412 // in vgedit
413 // TODO: either make these callbacks or internal calls rather than going through SDL event engine
414
415 if (keyCode == SDLK_BACKSPACE) {
416 // programatically invoke the B button event
417 backspace();
418 return true;
419 }
420
421 if (keyCode == SDLK_RETURN && preventEnterAndTab) {
422 // if don't allow enter, let's consider RETURN as submitting the type action (hardcoded to X button)
423 // TODO: make it its own callback
424 SDL_Event sdlevent;
425 sdlevent.type = SDL_JOYBUTTONDOWN;
426 sdlevent.jbutton.button = SDL_X;
427 SDL_PushEvent(&sdlevent);
428 return true;
429 }
430
431 if (keyCode == SDLK_ESCAPE) {
432 // dismiss keyboard, also programmatically
433 SDL_Event sdlevent;
434 sdlevent.type = SDL_JOYBUTTONDOWN;
435 sdlevent.jbutton.button = SDL_Y;
436 SDL_PushEvent(&sdlevent);
437 return true;
438 }
439
440 return false;
441}

◆ process()

bool EKeyboard::process ( InputEvents event)
virtual

process any input that is received for this element

Reimplemented from Element.

Definition at line 153 of file EKeyboard.cpp.

154{
155 InputEvents::bypassKeyEvents = false;
156
157 // don't do anything if we're hidden, or there's a sidebar and it's active
158 if (hidden)
159 return false;
160
161 // our keyboard will be processing its own key events (not button events)
162 InputEvents::bypassKeyEvents = true;
163
164 if (event->type == SDL_KEYDOWN)
165 return listenForPhysicalKeys(event);
166 if (event->type == SDL_KEYUP && (event->keyCode == SDLK_LSHIFT ||
167 event->keyCode == SDLK_RSHIFT ||
168 event->keyCode == SDLK_CAPSLOCK)) {
169 shiftOn = false;
170 updateSize();
171 return true;
172 }
173
174 // immersive view doesn't use any keyboard touch events
175 if (immersiveMode) return false;
176
177 if (event->isTouchDown())
178 {
179 curRow = index = -1;
180 touchMode = true;
181 isTouchDrag = false;
182 }
183
184 if (event->isKeyDown())
185 touchMode = false;
186
187 bool ret = false;
188
189 // only set touch drag if a selection hasn't been made
190 auto prevTouchDrag = isTouchDrag;
191 isTouchDrag = (event->isTouchDrag() && (!touchMode || (curRow < 0 && index < 0))) || isTouchDrag;
192 if (prevTouchDrag != isTouchDrag && isTouchDrag) {
193 // started a drag event, play vibrate
194 CST_LowRumble(event, 200);
195 ret = true;
196 }
197
198 if (!touchMode && !isTouchDrag)
199 {
200 if (curRow < 0 && index < 0)
201 {
202 // switched into EKeyboard, set to 0 and return
203 curRow = 1;
204 index = 0;
205 return true;
206 }
207
208 if (event->isKeyDown())
209 {
210 int lastRow = curRow;
211 curRow += (event->held(DOWN_BUTTON) - event->held(UP_BUTTON));
212 index += (event->held(RIGHT_BUTTON) - event->held(LEFT_BUTTON));
213
214 if (curRow < 0) curRow = 0;
215 if (index < 0) index = 0;
216 if (curRow >= rowCount() + 1) curRow = rowCount(); // +1 for bottom "row" (tab, space, enter)
217 if (curRow == rowCount())
218 {
219 // go to space key if last index is in the middle of row
220 if (lastRow < curRow && index > 0 && index < rowLength(lastRow))
221 {
222 index = 1;
223 }
224
225 // tab key
226 if (index < 0) index = 0;
227
228 // enter key
229 if (index > 2) index = 2;
230 }
231 else
232 {
233 if (index > rowLength(curRow))
234 index = rowLength(curRow);
235
236 if (lastRow == rowCount()) {
237 switch (index)
238 {
239 case 0: //tab
240 index = 0;
241 break;
242 case 1: // space
243 // go to middle of current row
244 index = rowLength(curRow) / 2;
245 break;
246 case 2: // enter
247 // go to end of current row
248 index = rowLength(curRow);
249 break;
250 default:
251 break;
252 }
253 }
254 }
255
256 if (event->held(A_BUTTON))
257 {
258 // space bar and enter key
259 if (curRow >= rowCount())
260 {
261 switch (index)
262 {
263 case 0:
264 just_type('\t');
265 break;
266 case 1:
267 just_type(' ');
268 break;
269 case 2:
270 just_type('\n');
271 break;
272 default:
273 break;
274 }
275 return true;
276 }
277
278 type(curRow, index);
279 }
280
281 // updateView();
282 return true;
283 }
284
285 return false;
286 }
287
288 int extWidth = width + 305;
289
290 if ((event->isTouchDown() || event->isTouchDrag()) && event->touchIn(this->x, this->y, extWidth, height + 200))
291 {
292 for (int y = 0; y < rowCount(); y++)
293 for (int x = 0; x < rowLength(y) + 1; x++) {
294 auto xStart = this->x + kXPad + x * kXOff + y * yYOff;
295 auto yStart = this->y + kYPad + y * ySpacing;
296 if (event->touchIn(xStart, yStart, keyWidth, keyWidth))
297 {
298 ret |= true;
299 curRow = y;
300 index = x;
301 }
302 }
303 return true;
304 }
305
306 if (event->isTouchUp())
307 {
308 // only proceed if we've been touchdown'd
309 // reset current row and info
310 curRow = -1;
311 index = -1;
312
313 if (event->touchIn(this->x, this->y, extWidth, height + 200))
314 {
315
316 for (int y = 0; y < rowCount(); y++)
317 for (int x = 0; x < rowLength(y) + 1; x++)
318 if (event->touchIn(this->x + kXPad + x * kXOff + y * yYOff, this->y + kYPad + y * ySpacing, keyWidth, keyWidth))
319 {
320 ret |= true;
321 type(y, x);
322 }
323
324 if (event->touchIn(this->x + dPos, this->y + enterHeight, enterWidth, textSize))
325 {
326 ret |= true;
327 just_type('\t');
328 }
329
330 if (event->touchIn(this->x + sPos, this->y + dHeight, sWidth, textSize))
331 {
332 ret |= true;
333 just_type(' ');
334 }
335
336 if (event->touchIn(this->x + enterPos, this->y + enterHeight, enterWidth, textSize))
337 {
338 ret |= true;
339 just_type('\n');
340 }
341
342 // if (ret)
343 // updateView();
344
345 return ret;
346 }
347
348 return false;
349 }
350
351 return false;
352}
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:105
bool touchIn(int x, int width, int y, int height)
whether or not a touch is detected within the specified rect in this cycle
bool held(int buttons)
whether or not a button is pressed during this cycle

References InputEvents::held(), Element::hidden, InputEvents::touchIn(), and Element::width.

◆ render()

void EKeyboard::render ( Element parent)
virtual

display the current state of the display

Reimplemented from Element.

Definition at line 26 of file EKeyboard.cpp.

27{
28 if (hidden || immersiveMode)
29 return;
30
31 CST_Rect dimens = { this->x, this->y, this->width + 305, this->height + 140 };
32
33 auto renderer = getRenderer();
34
35 CST_SetDrawColor(renderer, { 0xf9, 0xf9, 0xf9, 0xFF });
36 if (hasRoundedKeys) {
37 CST_SetDrawColor(renderer, { 0xdd, 0xdd, 0xdd, 0xFF });
38
39 // rounded keys keyboard is full screen width
40 dimens.x = 0;
41 dimens.y -= 15;
42 dimens.w = RootDisplay::screenWidth;
43 }
44
45 CST_FillRect(renderer, &dimens);
46
47 for (int y = 0; y < rowCount(); y++)
48 for (int x = 0; x < rowLength(y) + 1; x++)
49 {
50 CST_Rect dimens2 = { this->x + kXPad + x * kXOff + y * yYOff, this->y + kYPad + y * ySpacing, keyWidth, keyWidth };
51 if (this->hasRoundedKeys) {
52 CST_roundedBoxRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0xee, 0xee, 0xee, 0xff);
53 } else {
54 CST_SetDrawColor(renderer, { 0xf4, 0xf4, 0xf4, 0xff });
55 CST_FillRect(renderer, &dimens2);
56 }
57
58 // draw the letters with fontcache, for rounded keys
59 if (hasRoundedKeys) {
60 char curChar = rows[y]->at(x*2);
61 auto curCharStr = std::string(1, curChar);
62 int fHeight = CST_GetFontHeight(roundKeyFont, curCharStr.c_str());
63 int fWidth = CST_GetFontWidth(roundKeyFont, curCharStr.c_str());
64 CST_DrawFont(
65 roundKeyFont,
66 renderer,
67 dimens2.x + dimens2.w/2 - fWidth/2,
68 dimens2.y + dimens2.h/2 - fHeight/2,
69 curCharStr.c_str()
70 );
71 }
72 }
73
74 CST_Rect dimensSpace = { this->x + sPos, this->y + dHeight, sWidth, textSize };
75 CST_Rect dimensEnter = { this->x + enterPos, this->y + enterHeight, enterWidth, (int)(1.5 * textSize) };
76 CST_Rect dimensTab = { this->x + dPos, this->y + enterHeight, enterWidth, (int)(1.5 * textSize) };
77
78 // if there's a highlighted piece set, color it in
79 if (curRow >= 0 || index >= 0)
80 {
81 CST_Rect dimens2 = { this->x + kXPad + index * kXOff + curRow * yYOff, this->y + kYPad + curRow * ySpacing, keyWidth, keyWidth };
82
83 if (curRow >= rowCount())
84 {
85 switch (index)
86 {
87 case 0:
88 dimens2 = dimensTab;
89 break;
90 case 1:
91 // if we're on SPACE, expand the dimens width of the highlighted button
92 dimens2 = dimensSpace;
93 break;
94 case 2:
95 // if we're on ENTER, expand the dimens width of the highlighted button
96 dimens2 = dimensEnter;
97 break;
98 default:
99 break;
100 }
101 }
102
103 // draw the currently selected tile if these index things are set
104 if (touchMode && !isTouchDrag)
105 {
106 if (hasRoundedKeys) {
107 CST_roundedBoxRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0xad, 0xd8, 0xe6, 0x90);
108 CST_roundedRectangleRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0x66, 0x7c, 0x89, 0xff);
109 } else {
110 CST_SetDrawColor(renderer, { 0xad, 0xd8, 0xe6, 0x90 }); // TODO: matches the DEEP_HIGHLIGHT color
111 CST_FillRect(renderer, &dimens2);
112 }
113 }
114 else if (hasRoundedKeys) {
115 CST_roundedBoxRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0xad, 0xd8, 0xe6, 0x90);
116 CST_roundedRectangleRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0x66, 0x7c, 0x89, 0xff);
117 }
118 else {
119 CST_SetDrawColor(renderer, { 0xff, 0xff, 0xff, 0xff }); // TODO: matches the DEEP_HIGHLIGHT color
120 CST_FillRect(renderer, &dimens2);
121
122 // border
123 for (int z = 4; z >= 0; z--)
124 {
125 dimens2.x--;
126 dimens2.y--;
127 dimens2.w += 2;
128 dimens2.h += 2;
129
130 CST_SetDrawColor(renderer, { 0x66 - z * 10, 0x7c + z * 20, 0x89 + z * 10, 0xFF });
131 CST_DrawRect(renderer, &dimens2);
132 }
133 }
134 }
135
136 if (hasRoundedKeys) {
137 CST_roundedBoxRGBA(renderer, dimensSpace.x, dimensSpace.y, dimensSpace.x + dimensSpace.w, dimensSpace.y + dimensSpace.h, 20, 0xee, 0xee, 0xee, 0xff);
138 CST_roundedBoxRGBA(renderer, dimensEnter.x, dimensEnter.y, dimensEnter.x + dimensEnter.w, dimensEnter.y + dimensEnter.h, 20, 0xee, 0xee, 0xee, 0xff);
139 CST_roundedBoxRGBA(renderer, dimensTab.x, dimensTab.y, dimensTab.x + dimensTab.w, dimensTab.y + dimensTab.h, 20, 0xee, 0xee, 0xee, 0xff);
140 } else {
141 CST_SetDrawColor(renderer, { 0xf4, 0xf4, 0xf4, 0xff });
142 CST_FillRect(renderer, &dimensSpace);
143
144 if (!preventEnterAndTab) {
145 CST_FillRect(renderer, &dimensEnter);
146 CST_FillRect(renderer, &dimensTab);
147 }
148 }
149
150 super::render(this);
151}
virtual void render(Element *parent)
display the current state of the display
Definition: Element.cpp:60

References Element::hidden, Element::render(), and Element::width.

◆ rowCount()

int EKeyboard::rowCount ( )
inline

Definition at line 48 of file EKeyboard.hpp.

48 {
49 return (int)rows.size();
50 }

◆ rowLength()

int EKeyboard::rowLength ( int  row)
inline

Definition at line 52 of file EKeyboard.hpp.

52 {
53 return (int)rows[row]->size() / 2;
54 }

◆ type()

void EKeyboard::type ( int  y,
int  x 
)

Definition at line 540 of file EKeyboard.cpp.

541{
542 const char input = (*(rows[y]))[x * 2];
543 just_type(input);
544}

◆ updateSize()

void EKeyboard::updateSize ( )

Definition at line 443 of file EKeyboard.cpp.

444{
445 this->elements.clear();
446 rows.clear();
447
448 this->height = (304 / 900.0) * width;
449
450 // set up lots of scaling variables based on the width/height
451
452 this->keyWidth = (int)(0.08 * width);
453 this->padding = keyWidth / 2.0;
454
455 // these field variables are for displaying the QWERTY keys (touching and displaying)
456 kXPad = (int)((23 / 400.0) * width);
457 kXOff = (int)((36.5 / 400.0) * width) + (900.0 / width) * ( 900.0 != width); // when scaling, adjust our key x offset TODO: probably a guesstimate
458 yYOff = (int)((22 / 400.0) * width);
459 kYPad = (int)((17 / 135.0) * height);
460 ySpacing = (int)((33 / 400.0) * width);
461
462 if (hasRoundedKeys) {
463 // different positioning for round keyboard
464 // TODO: something else
465 kXOff = (int)((38 / 400.0) * width) + (900.0 / width) * ( 900.0 != width); // when scaling, adjust our key x offset TODO: probably a guesstimate
466 yYOff = (int)((10 / 400.0) * width);
467 kYPad = (int)((0 / 135.0) * height);
468 ySpacing = (int)((37 / 400.0) * width);
469 }
470
471 // these local variables position only the text, and has nothing to do with the
472 // touch. They should likely be based on the above field variables so those
473 // can change quickly
474 int kXPad = (int)((30 / 400.0) * width);
475 int kXOff = (int)((22 / 400.0) * width);
476#ifdef __WIIU__
477 // cheeky positioning hack because wiiu screen dimensions are different
478 // to properly fix, the above comments would need to be addressed
479 int kYPad = (int)((14 / 400.0) * width);
480#endif
481 int kYOff = (int)((33 / 400.0) * width);
482
483 this->textSize = 0.9375 * keyWidth;
484
485 // delete, space and enter key dimensions
486 dPos = (int)((13 / 400.0) * width);
487 dHeight = (int)((85 / 135.0) * height) + 145;
488 sPos = (int)((150 / 400.0) * width);
489 enterPos = dPos + 1000;
490 enterHeight = dHeight - 34;
491
492 dWidth = (int)(1.4125 * textSize);
493 sWidth = (int)(7.5 * textSize);
494 enterWidth = (int)(2.25 * textSize);
495
496 // set up the keys vector based on the current EKeyboard selection
497 generateEKeyboard();
498
499 CST_Color gray = { 0x52, 0x52, 0x52, 0xff };
500
501 int targetHeight = -1;
502
503 // go through and draw each of the three rows at the right position
504 if (!hasRoundedKeys) {
505 for (int x = 0; x < rowCount(); x++)
506 {
507 TextElement* rowText = new TextElement(rows[x]->c_str(), textSize, &gray, ICON);
508 // rowText->customFontPath = RAMFS "res/lightsans.ttf";
509 if (targetHeight < 0) {
510 targetHeight = rowText->height;
511 }
512 rowText->update(true);
513 rowText->position(kXPad + x * kXOff, kYPad + x * kYOff + targetHeight/2 - rowText->height/2);
514 this->elements.push_back(rowText);
515 }
516 }
517
518 // text for space, enter, and symbols
519 CST_Color grayish = { 0x55, 0x55, 0x55, 0xff };
520 TextElement* spaceText = new TextElement("space", 30, &grayish);
521 CST_Rect d4 = { this->x + sPos, this->y + dHeight, sWidth, textSize }; // todo: extract out hardcoded rects like this
522 spaceText->position(d4.x + d4.w / 2 - spaceText->width / 2 - 15, 345);
523 this->elements.push_back(spaceText);
524
525 if (!preventEnterAndTab)
526 {
527 TextElement* enterText = new TextElement("enter", 30, &grayish);
528 CST_Rect d3 = { this->x + enterPos, this->y + enterHeight, enterWidth, textSize }; // todo: extract out hardcoded rects like this
529 enterText->position(d3.x + d3.w / 2 - enterText->width / 2 - 30, 327);
530 this->elements.push_back(enterText);
531
532 TextElement* symText = new TextElement(hasRoundedKeys ? "shift" : "tab", 30, &grayish);
533 CST_Rect d5 = { this->x + dPos, this->y + enterHeight, enterWidth, textSize }; // todo: extract out hardcoded rects like this
534 symText->position(d5.x + d5.w / 2 - symText->width / 2 - 30, 327);
535 this->elements.push_back(symText);
536 }
537}
void position(int x, int y)
position the element
Definition: Element.cpp:193
std::vector< Element * > elements
visible GUI child elements of this element
Definition: Element.hpp:62
void update(bool forceUpdate=false)
update TextElement with changes
Definition: TextElement.cpp:89

Member Data Documentation

◆ breaks

int EKeyboard::breaks[4] = { 13, 13, 11, 10 }

Definition at line 34 of file EKeyboard.hpp.

◆ capsOn

bool EKeyboard::capsOn = false

Definition at line 57 of file EKeyboard.hpp.

◆ curRow

int EKeyboard::curRow = -1

Definition at line 61 of file EKeyboard.hpp.

◆ dHeight

int EKeyboard::dHeight = 0

Definition at line 74 of file EKeyboard.hpp.

◆ dPos

int EKeyboard::dPos = 0

Definition at line 73 of file EKeyboard.hpp.

◆ dWidth

int EKeyboard::dWidth = 0

Definition at line 78 of file EKeyboard.hpp.

◆ enterHeight

int EKeyboard::enterHeight = 0

Definition at line 77 of file EKeyboard.hpp.

◆ enterPos

int EKeyboard::enterPos = 0

Definition at line 76 of file EKeyboard.hpp.

◆ enterWidth

int EKeyboard::enterWidth = 0

Definition at line 80 of file EKeyboard.hpp.

◆ hasRoundedKeys

bool EKeyboard::hasRoundedKeys = false

Definition at line 90 of file EKeyboard.hpp.

◆ immersiveMode

bool EKeyboard::immersiveMode = false

Definition at line 94 of file EKeyboard.hpp.

◆ index

int EKeyboard::index = -1

Definition at line 62 of file EKeyboard.hpp.

◆ isTouchDrag

bool EKeyboard::isTouchDrag = false

Definition at line 100 of file EKeyboard.hpp.

◆ keyWidth

int EKeyboard::keyWidth = 0

Definition at line 68 of file EKeyboard.hpp.

◆ kXOff

int EKeyboard::kXOff = 0

Definition at line 84 of file EKeyboard.hpp.

◆ kXPad

int EKeyboard::kXPad = 0

Definition at line 83 of file EKeyboard.hpp.

◆ kYPad

int EKeyboard::kYPad = 0

Definition at line 86 of file EKeyboard.hpp.

◆ lower_keys

const char* EKeyboard::lower_keys = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"

Definition at line 32 of file EKeyboard.hpp.

◆ mode

int EKeyboard::mode = 0

Definition at line 58 of file EKeyboard.hpp.

◆ padding

int EKeyboard::padding = 0

Definition at line 69 of file EKeyboard.hpp.

◆ preventEnterAndTab

bool EKeyboard::preventEnterAndTab = false

Definition at line 97 of file EKeyboard.hpp.

◆ roundKeyFont

CST_Font* EKeyboard::roundKeyFont = NULL

Definition at line 91 of file EKeyboard.hpp.

◆ rows

std::vector<std::string*> EKeyboard::rows

Definition at line 39 of file EKeyboard.hpp.

◆ shiftOn

bool EKeyboard::shiftOn = false

Definition at line 56 of file EKeyboard.hpp.

◆ sPos

int EKeyboard::sPos = 0

Definition at line 75 of file EKeyboard.hpp.

◆ storeOwnText

bool EKeyboard::storeOwnText = false

Definition at line 98 of file EKeyboard.hpp.

◆ sWidth

int EKeyboard::sWidth = 0

Definition at line 79 of file EKeyboard.hpp.

◆ textInput

std::string EKeyboard::textInput

Definition at line 24 of file EKeyboard.hpp.

◆ textSize

int EKeyboard::textSize = 0

Definition at line 70 of file EKeyboard.hpp.

◆ touchMode

bool EKeyboard::touchMode = false

Definition at line 93 of file EKeyboard.hpp.

◆ typeAction

std::function<void(char)> EKeyboard::typeAction = NULL

Definition at line 28 of file EKeyboard.hpp.

◆ upper_keys

const char* EKeyboard::upper_keys = "~!@#$\%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"

Definition at line 33 of file EKeyboard.hpp.

◆ usbKeys

const CST_Keycode EKeyboard::usbKeys[KEYCODE_COUNT]
Initial value:
= {
SDLK_BACKQUOTE, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS,
SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i, SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_BACKSLASH,
SDLK_a, SDLK_s, SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON, SDLK_QUOTE,
SDLK_z, SDLK_x, SDLK_c, SDLK_v, SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH
}

Definition at line 41 of file EKeyboard.hpp.

◆ ySpacing

int EKeyboard::ySpacing = 0

Definition at line 87 of file EKeyboard.hpp.

◆ yYOff

int EKeyboard::yYOff = 0

Definition at line 85 of file EKeyboard.hpp.


The documentation for this class was generated from the following files: