9#include "GuiKeyboard.h"
10#include "../filelist.h"
14static char tmptxt[MAX_KEYBOARD_DISPLAY+1];
16static const char * GetDisplayText(
const char * t)
21 strncpy(tmptxt, t, MAX_KEYBOARD_DISPLAY);
22 tmptxt[MAX_KEYBOARD_DISPLAY] =
'\0';
39 Key thekeys[KB_ROWS][KB_COLUMNS] = {
94 memcpy(keys, thekeys,
sizeof(thekeys));
97 keyTextboxImg =
new GuiImage(keyTextbox);
98 keyTextboxImg->setAlignment(ALIGN_H::CENTRE, ALIGN_V::TOP);
99 keyTextboxImg->setPosition(0, 0);
100 this->
append(keyTextboxImg);
104 kbText->setPosition(0, 13);
110 keyMediumOver =
new GuiImageData(keyboard_mediumkey_over_png);
112 keyLargeOver =
new GuiImageData(keyboard_largekey_over_png);
117 keyBackImg =
new GuiImage(keyMedium);
118 keyBackOverImg =
new GuiImage(keyMediumOver);
120 keyBack =
new GuiButton(keyMedium->getWidth(), keyMedium->getHeight());
121 keyBack->setImage(keyBackImg);
122 keyBack->setImageOver(keyBackOverImg);
123 keyBack->setLabel(keyBackText);
129 keyCapsImg =
new GuiImage(keyMedium);
130 keyCapsOverImg =
new GuiImage(keyMediumOver);
132 keyCaps =
new GuiButton(keyMedium->getWidth(), keyMedium->getHeight());
133 keyCaps->setImage(keyCapsImg);
134 keyCaps->setImageOver(keyCapsOverImg);
135 keyCaps->setLabel(keyCapsText);
141 keyShiftImg =
new GuiImage(keyMedium);
142 keyShiftOverImg =
new GuiImage(keyMediumOver);
144 keyShift =
new GuiButton(keyMedium->getWidth(), keyMedium->getHeight());
145 keyShift->setImage(keyShiftImg);
146 keyShift->setImageOver(keyShiftOverImg);
147 keyShift->setLabel(keyShiftText);
153 keySpaceImg =
new GuiImage(keyLarge);
154 keySpaceOverImg =
new GuiImage(keyLargeOver);
155 keySpace =
new GuiButton(keyLarge->getWidth(), keyLarge->getHeight());
156 keySpace->setImage(keySpaceImg);
157 keySpace->setImageOver(keySpaceOverImg);
158 keySpace->setTrigger(trigA);
159 keySpace->setPosition(0, 4*42+80);
160 keySpace->setAlignment(ALIGN_H::CENTRE, ALIGN_V::TOP);
161 keySpace->setEffectGrow();
164 char txt[2] = { 0, 0 };
166 for(
int i=0; i<KB_ROWS; i++)
168 for(
int j=0; j<KB_COLUMNS; j++)
170 if(keys[i][j].ch !=
'\0')
172 txt[0] = keys[i][j].ch;
174 keyImgOver[i][j] =
new GuiImage(keyOver);
176 keyTxt[i][j]->
setAlignment(ALIGN_H::CENTRE, ALIGN_V::BOTTOM);
177 keyTxt[i][j]->setPosition(0, -10);
178 keyBtn[i][j] =
new GuiButton(key->getWidth(), key->getHeight());
179 keyBtn[i][j]->setImage(keyImg[i][j]);
180 keyBtn[i][j]->setImageOver(keyImgOver[i][j]);
181 keyBtn[i][j]->setTrigger(trigA);
182 keyBtn[i][j]->setLabel(keyTxt[i][j]);
183 keyBtn[i][j]->setPosition(j*42+21*i+40, i*42+80);
184 keyBtn[i][j]->setEffectGrow();
185 this->
append(keyBtn[i][j]);
191GuiKeyboard::~GuiKeyboard()
195 delete keyTextboxImg;
198 delete keyCapsOverImg;
202 delete keyShiftOverImg;
206 delete keyBackOverImg;
209 delete keySpaceOverImg;
214 delete keyMediumOver;
219 for(
int i=0; i<KB_ROWS; i++)
221 for(
int j=0; j<KB_COLUMNS; j++)
223 if(keys[i][j].ch !=
'\0')
226 delete keyImgOver[i][j];
239 for (uint8_t i = 0; i <
_elements.size(); i++)
246 if(keySpace->getState() == STATE::CLICKED)
249 if(len < kbtextmaxlen-1)
255 keySpace->setState(STATE::SELECTED, c->
getChannel());
257 else if(keyBack->getState() == STATE::CLICKED)
263 kbText->setText(GetDisplayText(
kbtextstr));
265 keyBack->setState(STATE::SELECTED, c->
getChannel());
267 else if(keyShift->getState() == STATE::CLICKED)
270 keyShift->setState(STATE::SELECTED, c->
getChannel());
273 else if(keyCaps->getState() == STATE::CLICKED)
276 keyCaps->setState(STATE::SELECTED, c->
getChannel());
280 char txt[2] = { 0, 0 };
284 for(
int i=0; i<KB_ROWS; i++)
286 for(
int j=0; j<KB_COLUMNS; j++)
288 if(keys[i][j].ch !=
'\0')
293 txt[0] = keys[i][j].chShift;
295 txt[0] = keys[i][j].ch;
297 keyTxt[i][j]->setText(txt);
300 if(keyBtn[i][j]->
getState() == STATE::CLICKED)
304 if(len < kbtextmaxlen-1)
316 kbText->setText(GetDisplayText(
kbtextstr));
317 keyBtn[i][j]->setState(STATE::SELECTED, c->
getChannel());
Umbrella header for the platform-agnostic libgui core.
bool selectable
Whether or not this element selectable (can change to SELECTED state)
STATE getState()
Gets the element's current state.
void setTrigger(GuiTrigger *t)
Set a new GuiTrigger for the element.
ALIGN_H alignmentHor
Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
void setEffectGrow(int percent=110)
Shortcut to SetEffectOnOver(EFFECT::SCALE, 4, percent)
int height
Element height.
GuiElement * parentElement
Parent element.
ALIGN_V alignmentVert
Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
int focus
Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
STATE state
Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
void setPosition(int x, int y)
Sets the element's position.
Decodes compressed image data (PNG) into a platform-native texture created from it.
Display, manage, and manipulate images in the GUI.
GuiKeyboard(char *t, uint32_t m)
char kbtextstr[256]
Current entered text - read this after the keyboard closes.
void update(InputController *c)
Called constantly to allow the element to respond to the current input data.
Display, manage, and manipulate text in the GUI.
void setAlignment(ALIGN_H hor, ALIGN_V vert)
Sets the text alignment.
Input-condition matcher attached to a GuiElement (via setSimpleTrigger() etc.) and evaluated against ...
void setPrimaryTrigger(int ch=-1)
Semantic Triggers.
void toggleFocus(InputController *c)
Changes window focus to the next focusable window or element If no element is in focus,...
void append(GuiElement *e)
Appends a GuiElement to the GuiWindow.
void moveSelectionVert(int d)
Moves the selected element to the element above or below.
std::vector< GuiElement * > _elements
Contains all elements within the GuiWindow.
void moveSelectionHor(int d)
Moves the selected element to the element to the left or right.
8-bit-per-channel RGBA color used by the video interfaces.