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
 
int cornerRadius = 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:120

◆ ~EKeyboard()

EKeyboard::~EKeyboard ( )

Definition at line 630 of file EKeyboard.cpp.

631{
632 InputEvents::bypassKeyEvents = false;
633}

Member Function Documentation

◆ backspace()

void EKeyboard::backspace ( )

Definition at line 606 of file EKeyboard.cpp.

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

◆ generateEKeyboard()

void EKeyboard::generateEKeyboard ( )

Definition at line 560 of file EKeyboard.cpp.

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

◆ getTextInput()

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

Definition at line 625 of file EKeyboard.cpp.

626{
627 return textInput;
628}

◆ just_type()

void EKeyboard::just_type ( const char  input)

Definition at line 544 of file EKeyboard.cpp.

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

◆ listenForPhysicalKeys()

bool EKeyboard::listenForPhysicalKeys ( InputEvents e)

Definition at line 351 of file EKeyboard.cpp.

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

◆ process()

bool EKeyboard::process ( InputEvents event)
virtual

process any input that is received for this element

Reimplemented from Element.

Definition at line 148 of file EKeyboard.cpp.

149{
150 InputEvents::bypassKeyEvents = false;
151
152 // don't do anything if we're hidden, or there's a sidebar and it's active
153 if (hidden)
154 return false;
155
156 // our keyboard will be processing its own key events (not button events)
157 InputEvents::bypassKeyEvents = true;
158
159 if (event->type == SDL_KEYDOWN)
160 return listenForPhysicalKeys(event);
161 if (event->type == SDL_KEYUP && (event->keyCode == SDLK_LSHIFT ||
162 event->keyCode == SDLK_RSHIFT ||
163 event->keyCode == SDLK_CAPSLOCK)) {
164 shiftOn = false;
165 updateSize();
166 return true;
167 }
168
169 // immersive view doesn't use any keyboard touch events
170 if (immersiveMode) return false;
171
172 if (event->isTouchDown())
173 {
174 curRow = index = -1;
175 touchMode = true;
176 isTouchDrag = false;
177 }
178
179 if (event->isKeyDown()) {
180 touchMode = false;
181 isTouchDrag = false;
182 }
183
184 bool ret = false;
185
186 // only set touch drag if a selection hasn't been made
187 auto prevTouchDrag = isTouchDrag;
188 isTouchDrag = (event->isTouchDrag() && (!touchMode || (curRow < 0 && index < 0))) || isTouchDrag;
189 if (prevTouchDrag != isTouchDrag && isTouchDrag) {
190 // started a drag event, play vibrate
191 CST_LowRumble(event, 200);
192 ret = true;
193 }
194
195 if (!touchMode && !isTouchDrag)
196 {
197 if (curRow < 0 && index < 0)
198 {
199 // switched into EKeyboard, set to 0 and return
200 curRow = 1;
201 index = 0;
202 return true;
203 }
204
205 if (event->isKeyDown())
206 {
207 int lastRow = curRow;
208 curRow += (event->held(DOWN_BUTTON) - event->held(UP_BUTTON));
209 index += (event->held(RIGHT_BUTTON) - event->held(LEFT_BUTTON));
210
211 if (curRow < 0) curRow = 0;
212 if (index < 0) index = 0;
213 if (curRow >= rowCount() + 1) curRow = rowCount(); // +1 for bottom "row" (tab, space, enter)
214 if (curRow == rowCount())
215 {
216 // go to space key if last index is in the middle of row
217 if (lastRow < curRow && index > 0 && index < rowLength(lastRow))
218 {
219 index = 1;
220 }
221
222 // tab key
223 if (index < 0) index = 0;
224
225 // enter key
226 if (index > 2) index = 2;
227 }
228 else
229 {
230 if (index > rowLength(curRow))
231 index = rowLength(curRow);
232
233 if (lastRow == rowCount()) {
234 switch (index)
235 {
236 case 0: //tab
237 index = 0;
238 break;
239 case 1: // space
240 // go to middle of current row
241 index = rowLength(curRow) / 2;
242 break;
243 case 2: // enter
244 // go to end of current row
245 index = rowLength(curRow);
246 break;
247 default:
248 break;
249 }
250 }
251 }
252
253 if (event->held(A_BUTTON))
254 {
255 // space bar and enter key
256 if (curRow >= rowCount())
257 {
258 switch (index)
259 {
260 case 0:
261 just_type('\t');
262 break;
263 case 1:
264 just_type(' ');
265 break;
266 case 2:
267 just_type('\n');
268 break;
269 default:
270 break;
271 }
272 return true;
273 }
274
275 type(curRow, index);
276 }
277
278 // updateView();
279 return true;
280 }
281
282 return false;
283 }
284
285 int extWidth = width + 305;
286
287 if ((event->isTouchDown() || event->isTouchDrag()) && event->touchIn(this->x, this->y, extWidth, height + 200))
288 {
289 for (int y = 0; y < rowCount(); y++)
290 for (int x = 0; x < rowLength(y) + 1; x++) {
291 auto xStart = this->x + kXPad + x * kXOff + y * yYOff;
292 auto yStart = this->y + kYPad + y * ySpacing;
293 if (event->touchIn(xStart, yStart, keyWidth, keyWidth))
294 {
295 ret |= true;
296 curRow = y;
297 index = x;
298 }
299 }
300 return true;
301 }
302
303 if (event->isTouchUp())
304 {
305 // only proceed if we've been touchdown'd
306 // reset current row and info
307 curRow = -1;
308 index = -1;
309
310 if (event->touchIn(this->x, this->y, extWidth, height + 200))
311 {
312
313 for (int y = 0; y < rowCount(); y++)
314 for (int x = 0; x < rowLength(y) + 1; x++)
315 if (event->touchIn(this->x + kXPad + x * kXOff + y * yYOff, this->y + kYPad + y * ySpacing, keyWidth, keyWidth))
316 {
317 ret |= true;
318 type(y, x);
319 }
320
321 if (event->touchIn(this->x + dPos, this->y + enterHeight, enterWidth, textSize))
322 {
323 ret |= true;
324 just_type('\t');
325 }
326
327 if (event->touchIn(this->x + sPos, this->y + dHeight, sWidth, textSize))
328 {
329 ret |= true;
330 just_type(' ');
331 }
332
333 if (event->touchIn(this->x + enterPos, this->y + enterHeight, enterWidth, textSize))
334 {
335 ret |= true;
336 just_type('\n');
337 }
338
339 // if (ret)
340 // updateView();
341
342 return ret;
343 }
344
345 return false;
346 }
347
348 return false;
349}
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:107
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 actual enter/space/tab keys if needed
104 if (hasRoundedKeys) {
105 CST_roundedBoxRGBA(renderer, dimensSpace.x, dimensSpace.y, dimensSpace.x + dimensSpace.w, dimensSpace.y + dimensSpace.h, 20, 0xee, 0xee, 0xee, 0xff);
106 CST_roundedBoxRGBA(renderer, dimensEnter.x, dimensEnter.y, dimensEnter.x + dimensEnter.w, dimensEnter.y + dimensEnter.h, 20, 0xee, 0xee, 0xee, 0xff);
107 CST_roundedBoxRGBA(renderer, dimensTab.x, dimensTab.y, dimensTab.x + dimensTab.w, dimensTab.y + dimensTab.h, 20, 0xee, 0xee, 0xee, 0xff);
108 } else {
109 CST_SetDrawColor(renderer, { 0xf4, 0xf4, 0xf4, 0xff });
110 CST_FillRect(renderer, &dimensSpace);
111
112 if (!preventEnterAndTab) {
113 CST_FillRect(renderer, &dimensEnter);
114 CST_FillRect(renderer, &dimensTab);
115 }
116 }
117
118 // draw the currently selected tile if these index things are set
119 if (touchMode && !isTouchDrag)
120 {
121 if (hasRoundedKeys) {
122 CST_roundedBoxRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0xad, 0xd8, 0xe6, 0x90);
123 CST_roundedRectangleRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0x66, 0x7c, 0x89, 0xff);
124 } else {
125 CST_SetDrawColor(renderer, { 0xad, 0xd8, 0xe6, 0x90 }); // TODO: matches the DEEP_HIGHLIGHT color
126 CST_FillRect(renderer, &dimens2);
127 }
128 }
129 else if (hasRoundedKeys) {
130 CST_roundedBoxRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0xad, 0xd8, 0xe6, 0x90);
131 CST_roundedRectangleRGBA(renderer, dimens2.x, dimens2.y, dimens2.x + dimens2.w, dimens2.y + dimens2.h, 20, 0x66, 0x7c, 0x89, 0xff);
132 }
133 else {
134 CST_SetDrawColor(renderer, { 0xff, 0xff, 0xff, 0xff }); // TODO: matches the DEEP_HIGHLIGHT color
135 CST_FillRect(renderer, &dimens2);
136
137 auto d = dimens2;
138 // draw a rectangle that is inlet a little
139 for (int x=-2; x<3; x++) {
140 CST_rectangleRGBA(renderer, d.x + x, d.y + x, d.x + d.w - x, d.y + d.h - x, 0x10, 0xD9, 0xD9, 0xff);
141 }
142 }
143 }
144
145 super::render(this);
146}
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 537 of file EKeyboard.cpp.

538{
539 const char input = (*(rows[y]))[x * 2];
540 just_type(input);
541}

◆ updateSize()

void EKeyboard::updateSize ( )

Definition at line 440 of file EKeyboard.cpp.

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

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: