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