Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
EKeyboard.hpp
1#include "Element.hpp"
2#include "TextElement.hpp"
3#pragma once
4
5#define KEYCODE_COUNT 47
6
7class EKeyboard : public Element
8{
9public:
10 EKeyboard();
11 EKeyboard(std::function<void(char)> typeAction);
12 ~EKeyboard();
13 void render(Element* parent);
14 bool process(InputEvents* event);
15
16 // setup field variables
17 void updateSize();
18 void just_type(const char input);
19 bool listenForPhysicalKeys(InputEvents* e);
20
21 // get text input on the keyboard so far
22 // (only stored when storeOwnText is true (default true for empty constructor, false for callback constructor))
23 const std::string& getTextInput();
24 std::string textInput;
25
26 // a function to be invoked when we receive a key press, which takes in the char
27 // that's been pressed
28 std::function<void(char)> typeAction = NULL;
29
30 // information representing a default qwerty EKeyboard, lower and upper
31 // alongside default EKeyboards will also be: tab, caps lock, return, delete, and shifts
32 const char* lower_keys = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
33 const char* upper_keys = "~!@#$\%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?";
34 int breaks[4] = { 13, 13, 11, 10 };
35
36 // the rest of the keys will be dynamically drawn by going through hex iterations
37 // these EKeyboards will fill the extra space with more characters
38
39 std::vector<std::string*> rows;
40
41 const CST_Keycode usbKeys[KEYCODE_COUNT] = {
42 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,
43 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,
44 SDLK_a, SDLK_s, SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON, SDLK_QUOTE,
45 SDLK_z, SDLK_x, SDLK_c, SDLK_v, SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH
46 };
47
48 inline int rowCount() {
49 return (int)rows.size();
50 }
51
52 inline int rowLength(int row) {
53 return (int)rows[row]->size() / 2;
54 }
55
56 bool shiftOn = false;
57 bool capsOn = false;
58 int mode = 0; // the mode of which EKeyboard type we're on (first is special and has shift)
59
60 // the currently selected row and index
61 int curRow = -1;
62 int index = -1;
63
64 // the below variables are stored to be used in processing touch events
65 // and rendering the drawings to screen
66
67 // attributes of each key
68 int keyWidth = 0;
69 int padding = 0;
70 int textSize = 0;
71
72 // attributes of delete and backspace keys
73 int dPos = 0;
74 int dHeight = 0;
75 int sPos = 0;
76 int enterPos = 0;
77 int enterHeight = 0;
78 int dWidth = 0;
79 int sWidth = 0;
80 int enterWidth = 0;
81
82 // positions of key location offset information
83 int kXPad = 0;
84 int kXOff = 0;
85 int yYOff = 0;
86 int kYPad = 0;
87 int ySpacing = 0;
88
89 // whether or not to use the rounded rectangle key style
90 bool hasRoundedKeys = false;
91 CST_Font* roundKeyFont = NULL;
92
93 bool touchMode = false;
94 bool immersiveMode = false; // no rendering, but still allow inputs
95 // if using a USB keyboard, they can hide the on-screen one
96
97 bool preventEnterAndTab = false; // hide and don't allow enter/tab inputs
98 bool storeOwnText = false; // whether or not this keyboard will store the text input on its own
99
100 bool isTouchDrag = false; // set to true during a touchdrag
101
102 void type(int y, int x);
103 void generateEKeyboard();
104 void backspace();
105};
void render(Element *parent)
display the current state of the display
Definition: EKeyboard.cpp:26
bool process(InputEvents *event)
process any input that is received for this element
Definition: EKeyboard.cpp:153
Element * parent
the parent element (can sometimes be null if it isn't set)
Definition: Element.hpp:102