Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2012 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 19 | #include <linux/input.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 22 | #include "../data.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | |
| 24 | #include <string> |
| 25 | |
| 26 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 27 | #include "../twcommon.h" |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 28 | #include "gui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 29 | } |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 30 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 31 | |
| 32 | #include "rapidxml.hpp" |
| 33 | #include "objects.hpp" |
| 34 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 35 | bool GUIKeyboard::CtrlActive = false; |
| 36 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 37 | GUIKeyboard::GUIKeyboard(xml_node<>* node) |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 38 | : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | { |
| 40 | int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0; |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 41 | currentKey = NULL; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 42 | highlightRenderCount = 0; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 43 | hasHighlight = hasCapsHighlight = hasCtrlHighlight = false; |
Dees_Troy | 3a16cb5 | 2013-01-10 15:16:02 +0000 | [diff] [blame] | 44 | char resource[10], layout[8], row[5], key[6], longpress[7]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | xml_attribute<>* attr; |
| 46 | xml_node<>* child; |
| 47 | xml_node<>* keylayout; |
| 48 | xml_node<>* keyrow; |
| 49 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 50 | for (layoutindex=0; layoutindex<MAX_KEYBOARD_LAYOUTS; layoutindex++) { |
| 51 | layouts[layoutindex].keyboardImg = NULL; |
| 52 | memset(layouts[layoutindex].keys, 0, sizeof(Layout::keys)); |
| 53 | memset(layouts[layoutindex].row_end_y, 0, sizeof(Layout::row_end_y)); |
| 54 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
| 56 | mRendered = false; |
| 57 | currentLayout = 1; |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 58 | CapsLockOn = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
| 60 | if (!node) return; |
| 61 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 62 | mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlight); |
| 63 | mCapsHighlightColor = LoadAttrColor(FindNode(node, "capshighlight"), "color", &hasCapsHighlight); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 64 | mCtrlHighlightColor = LoadAttrColor(FindNode(node, "ctrlhighlight"), "color", &hasCtrlHighlight); |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 65 | |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 66 | child = FindNode(node, "keymargin"); |
| 67 | mKeyMarginX = LoadAttrIntScaleX(child, "x", 0); |
| 68 | mKeyMarginY = LoadAttrIntScaleY(child, "y", 0); |
| 69 | |
| 70 | child = FindNode(node, "background"); |
| 71 | mBackgroundColor = LoadAttrColor(child, "color", COLOR(32,32,32,255)); |
| 72 | |
| 73 | child = FindNode(node, "key-alphanumeric"); |
| 74 | mFont = PageManager::GetResources()->FindFont(LoadAttrString(child, "font", "keylabel")); |
| 75 | mFontColor = LoadAttrColor(child, "textcolor", COLOR(255,255,255,255)); |
| 76 | mKeyColorAlphanumeric = LoadAttrColor(child, "color", COLOR(0,0,0,0)); |
| 77 | |
| 78 | child = FindNode(node, "key-other"); |
| 79 | mSmallFont = PageManager::GetResources()->FindFont(LoadAttrString(child, "font", "keylabel-small")); |
| 80 | mFontColorSmall = LoadAttrColor(child, "textcolor", COLOR(192,192,192,255)); |
| 81 | mKeyColorOther = LoadAttrColor(child, "color", COLOR(0,0,0,0)); |
| 82 | |
| 83 | child = FindNode(node, "longpress"); |
| 84 | mLongpressFont = PageManager::GetResources()->FindFont(LoadAttrString(child, "font", "keylabel-longpress")); |
| 85 | mLongpressFontColor = LoadAttrColor(child, "textcolor", COLOR(128,128,128,255)); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 86 | LoadPlacement(child, &longpressOffsetX, &longpressOffsetY); |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 87 | |
| 88 | LoadKeyLabels(node, 0); // load global key labels |
| 89 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 90 | // compatibility ugliness: resources should be specified in the layouts themselves instead |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | // Load the images for the different layouts |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 92 | child = FindNode(node, "layout"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 93 | if (child) |
| 94 | { |
| 95 | layoutindex = 1; |
| 96 | strcpy(resource, "resource1"); |
| 97 | attr = child->first_attribute(resource); |
| 98 | while (attr && layoutindex < (MAX_KEYBOARD_LAYOUTS + 1)) { |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 99 | layouts[layoutindex - 1].keyboardImg = LoadAttrImage(child, resource); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 100 | |
| 101 | layoutindex++; |
| 102 | resource[8] = (char)(layoutindex + 48); |
| 103 | attr = child->first_attribute(resource); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Check the first image to get height and width |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 108 | if (layouts[0].keyboardImg && layouts[0].keyboardImg->GetResource()) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 109 | { |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 110 | mRenderW = layouts[0].keyboardImg->GetWidth(); |
| 111 | mRenderH = layouts[0].keyboardImg->GetHeight(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | // Load all of the layout maps |
| 115 | layoutindex = 1; |
| 116 | strcpy(layout, "layout1"); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 117 | keylayout = FindNode(node, layout); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 118 | while (keylayout) |
| 119 | { |
| 120 | if (layoutindex > MAX_KEYBOARD_LAYOUTS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 121 | LOGERR("Too many layouts defined in keyboard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 125 | LoadKeyLabels(keylayout, layoutindex); // load per-layout key labels |
| 126 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 127 | Layout& lay = layouts[layoutindex - 1]; |
| 128 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 129 | child = keylayout->first_node("keysize"); |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 130 | keyHeight = LoadAttrIntScaleY(child, "height", 0); |
| 131 | keyWidth = LoadAttrIntScaleX(child, "width", 0); |
| 132 | // compatibility ugliness: capslock="0" means that this is the caps layout. Also it has nothing to do with keysize. |
| 133 | lay.is_caps = (LoadAttrInt(child, "capslock", 1) == 0); |
| 134 | // compatibility ugliness: revert_layout has nothing to do with keysize. |
| 135 | lay.revert_layout = LoadAttrInt(child, "revert_layout", -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 136 | |
| 137 | rowindex = 1; |
| 138 | Yindex = 0; |
| 139 | strcpy(row, "row1"); |
| 140 | keyrow = keylayout->first_node(row); |
| 141 | while (keyrow) |
| 142 | { |
| 143 | if (rowindex > MAX_KEYBOARD_ROWS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 144 | LOGERR("Too many rows defined in keyboard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | |
| 148 | Yindex += keyHeight; |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 149 | lay.row_end_y[rowindex - 1] = Yindex; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 150 | |
| 151 | keyindex = 1; |
| 152 | Xindex = 0; |
| 153 | strcpy(key, "key01"); |
| 154 | attr = keyrow->first_attribute(key); |
| 155 | |
| 156 | while (attr) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 157 | if (keyindex > MAX_KEYBOARD_KEYS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 158 | LOGERR("Too many keys defined in a keyboard row.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 162 | const char* keyinfo = attr->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 163 | |
| 164 | if (strlen(keyinfo) == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 165 | LOGERR("No key info on layout%i, row%i, key%dd.\n", layoutindex, rowindex, keyindex); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 169 | if (ParseKey(keyinfo, lay.keys[rowindex - 1][keyindex - 1], Xindex, keyWidth, false)) |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 170 | LOGERR("Invalid key info on layout%i, row%i, key%02i.\n", layoutindex, rowindex, keyindex); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 171 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 172 | |
| 173 | // PROCESS LONG PRESS INFO IF EXISTS |
| 174 | sprintf(longpress, "long%02i", keyindex); |
| 175 | attr = keyrow->first_attribute(longpress); |
| 176 | if (attr) { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 177 | const char* keyinfo = attr->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 178 | |
| 179 | if (strlen(keyinfo) == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 180 | LOGERR("No long press info on layout%i, row%i, long%dd.\n", layoutindex, rowindex, keyindex); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 184 | if (ParseKey(keyinfo, lay.keys[rowindex - 1][keyindex - 1], Xindex, keyWidth, true)) |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 185 | LOGERR("Invalid long press key info on layout%i, row%i, long%02i.\n", layoutindex, rowindex, keyindex); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 186 | } |
| 187 | keyindex++; |
| 188 | sprintf(key, "key%02i", keyindex); |
| 189 | attr = keyrow->first_attribute(key); |
| 190 | } |
| 191 | rowindex++; |
| 192 | row[3] = (char)(rowindex + 48); |
| 193 | keyrow = keylayout->first_node(row); |
| 194 | } |
| 195 | layoutindex++; |
| 196 | layout[6] = (char)(layoutindex + 48); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 197 | keylayout = FindNode(node, layout); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 198 | } |
| 199 | |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 200 | int x, y; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 201 | // Load the placement |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 202 | LoadPlacement(FindNode(node, "placement"), &x, &y, &mRenderW, &mRenderH); |
| 203 | SetRenderPos(x, y, mRenderW, mRenderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | GUIKeyboard::~GUIKeyboard() |
| 208 | { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 209 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 211 | int GUIKeyboard::ParseKey(const char* keyinfo, Key& key, int& Xindex, int keyWidth, bool longpress) |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 212 | { |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 213 | key.layout = 0; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 214 | int keychar = 0; |
| 215 | if (strlen(keyinfo) == 1) { |
| 216 | // This is a single key, simple definition |
| 217 | keychar = keyinfo[0]; |
| 218 | } else { |
| 219 | // This key has extra data: {keywidth}:{what_the_key_does} |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 220 | keyWidth = scale_theme_x(atoi(keyinfo)); |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 221 | |
| 222 | const char* ptr = keyinfo; |
| 223 | while (*ptr > 32 && *ptr != ':') |
| 224 | ptr++; |
| 225 | if (*ptr != ':') |
| 226 | return -1; // no colon is an error |
| 227 | ptr++; |
| 228 | |
| 229 | if (*ptr == 0) { // This is an empty area |
| 230 | keychar = 0; |
| 231 | } else if (strlen(ptr) == 1) { // This is the character that this key uses |
| 232 | keychar = *ptr; |
| 233 | } else if (*ptr == 'c') { // This is an ASCII character code: "c:{number}" |
| 234 | keychar = atoi(ptr + 2); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 235 | } else if (*ptr == 'k') { // This is a Linux keycode from input.h: "k:{number}" |
| 236 | keychar = -atoi(ptr + 2); |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 237 | } else if (*ptr == 'l') { // This is a different layout: "layout{number}" |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 238 | key.layout = atoi(ptr + 6); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 239 | } else if (*ptr == 'a') { // This is an action: "action" (the Enter key) |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 240 | keychar = KEYBOARD_ACTION; |
| 241 | } else |
| 242 | return -1; |
| 243 | } |
| 244 | |
| 245 | if (longpress) { |
| 246 | key.longpresskey = keychar; |
| 247 | } else { |
| 248 | key.key = keychar; |
| 249 | Xindex += keyWidth; |
| 250 | key.end_x = Xindex - 1; |
| 251 | } |
| 252 | |
| 253 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 254 | } |
| 255 | |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 256 | void GUIKeyboard::LoadKeyLabels(xml_node<>* parent, int layout) |
| 257 | { |
| 258 | for (xml_node<>* child = parent->first_node(); child; child = child->next_sibling()) { |
| 259 | std::string name = child->name(); |
| 260 | if (name == "keylabel") { |
| 261 | std::string keydef = LoadAttrString(child, "key", ""); |
| 262 | Key tempkey; |
| 263 | int dummyX; |
| 264 | if (ParseKey(keydef.c_str(), tempkey, dummyX, 0, false) == 0) { |
| 265 | KeyLabel keylabel; |
| 266 | keylabel.key = tempkey.key; |
| 267 | keylabel.layout_from = layout; |
| 268 | keylabel.layout_to = tempkey.layout; |
| 269 | keylabel.text = LoadAttrString(child, "text", ""); |
| 270 | keylabel.image = LoadAttrImage(child, "resource"); |
| 271 | mKeyLabels.push_back(keylabel); |
| 272 | } else { |
| 273 | LOGERR("Ignoring invalid keylabel in layout %d: '%s'.\n", layout, keydef.c_str()); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 279 | void GUIKeyboard::DrawKey(Key& key, int keyX, int keyY, int keyW, int keyH) |
| 280 | { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 281 | int keychar = key.key; |
| 282 | if (!keychar && !key.layout) |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 283 | return; |
| 284 | |
| 285 | // key background |
| 286 | COLOR& c = (keychar >= 32 && keychar < 127) ? mKeyColorAlphanumeric : mKeyColorOther; |
| 287 | gr_color(c.red, c.green, c.blue, c.alpha); |
| 288 | keyX += mKeyMarginX; |
| 289 | keyY += mKeyMarginY; |
| 290 | keyW -= mKeyMarginX * 2; |
| 291 | keyH -= mKeyMarginY * 2; |
| 292 | gr_fill(keyX, keyY, keyW, keyH); |
| 293 | |
| 294 | // key label |
| 295 | FontResource* labelFont = mFont; |
| 296 | string labelText; |
| 297 | ImageResource* labelImage = NULL; |
| 298 | if (keychar > 32 && keychar < 127) { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 299 | // TODO: this will eventually need UTF-8 support |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 300 | labelText = (char) keychar; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 301 | if (CtrlActive) { |
| 302 | int ctrlchar = KeyCharToCtrlChar(keychar); |
| 303 | if (ctrlchar != keychar) |
| 304 | labelText = std::string("^") + (char)(ctrlchar + 64); |
| 305 | } |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 306 | gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); |
| 307 | } |
| 308 | else { |
| 309 | // search for a special key label |
| 310 | for (std::vector<KeyLabel>::iterator it = mKeyLabels.begin(); it != mKeyLabels.end(); ++it) { |
| 311 | if (it->layout_from > 0 && it->layout_from != currentLayout) |
| 312 | continue; // this label is for another layout |
| 313 | if (it->key == key.key && it->layout_to == key.layout) |
| 314 | { |
| 315 | // found a label |
| 316 | labelText = it->text; |
| 317 | labelImage = it->image; |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | labelFont = mSmallFont; |
| 322 | gr_color(mFontColorSmall.red, mFontColorSmall.green, mFontColorSmall.blue, mFontColorSmall.alpha); |
| 323 | } |
| 324 | |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 325 | if (labelImage && labelImage->GetResource()) |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 326 | { |
| 327 | int w = labelImage->GetWidth(); |
| 328 | int h = labelImage->GetHeight(); |
| 329 | int x = keyX + (keyW - w) / 2; |
| 330 | int y = keyY + (keyH - h) / 2; |
| 331 | gr_blit(labelImage->GetResource(), 0, 0, w, h, x, y); |
| 332 | } |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 333 | else if (!labelText.empty() && labelFont && labelFont->GetResource()) |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 334 | { |
| 335 | void* fontResource = labelFont->GetResource(); |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 336 | int textW = gr_ttf_measureEx(labelText.c_str(), fontResource); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 337 | int textH = labelFont->GetHeight(); |
| 338 | int textX = keyX + (keyW - textW) / 2; |
| 339 | int textY = keyY + (keyH - textH) / 2; |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 340 | gr_textEx_scaleW(textX, textY, labelText.c_str(), fontResource, keyW, TOP_LEFT, 0); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // longpress key label (only if font is defined) |
| 344 | keychar = key.longpresskey; |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 345 | if (keychar > 32 && keychar < 127 && mLongpressFont && mLongpressFont->GetResource()) { |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 346 | void* fontResource = mLongpressFont->GetResource(); |
| 347 | gr_color(mLongpressFontColor.red, mLongpressFontColor.green, mLongpressFontColor.blue, mLongpressFontColor.alpha); |
| 348 | string text(1, keychar); |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 349 | int textW = gr_ttf_measureEx(text.c_str(), fontResource); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 350 | int textX = keyX + keyW - longpressOffsetX - textW; |
| 351 | int textY = keyY + longpressOffsetY; |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 352 | gr_textEx_scaleW(textX, textY, text.c_str(), fontResource, keyW, TOP_LEFT, 0); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 356 | int GUIKeyboard::KeyCharToCtrlChar(int key) |
| 357 | { |
| 358 | // convert upper and lower case to ctrl chars |
| 359 | // Ctrl+A to Ctrl+_ (we don't support entering null bytes) |
| 360 | if (key >= 65 && key <= 127 && key != 96) |
| 361 | return key & 0x1f; |
| 362 | return key; // pass on others (already ctrl chars, numbers, etc.) unchanged |
| 363 | } |
| 364 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 365 | int GUIKeyboard::Render(void) |
| 366 | { |
| 367 | if (!isConditionTrue()) |
| 368 | { |
| 369 | mRendered = false; |
| 370 | return 0; |
| 371 | } |
| 372 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 373 | Layout& lay = layouts[currentLayout - 1]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 374 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 375 | bool drawKeys = false; |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 376 | if (lay.keyboardImg && lay.keyboardImg->GetResource()) |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 377 | // keyboard is image based |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 378 | gr_blit(lay.keyboardImg->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); |
| 379 | else { |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 380 | // keyboard is software drawn |
| 381 | // fill background |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 382 | gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha); |
| 383 | gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 384 | drawKeys = true; |
| 385 | } |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 386 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 387 | // draw keys |
| 388 | int y1 = 0; |
| 389 | for (int row = 0; row < MAX_KEYBOARD_ROWS; ++row) { |
| 390 | int rowY = mRenderY + y1; |
| 391 | int rowH = lay.row_end_y[row] - y1; |
| 392 | y1 = lay.row_end_y[row]; |
| 393 | int x1 = 0; |
| 394 | for (int col = 0; col < MAX_KEYBOARD_KEYS; ++col) { |
| 395 | Key& key = lay.keys[row][col]; |
| 396 | int keyY = rowY; |
| 397 | int keyH = rowH; |
| 398 | int keyX = mRenderX + x1; |
| 399 | int keyW = key.end_x - x1; |
| 400 | x1 = key.end_x; |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 401 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 402 | // Draw key for software drawn keyboard |
| 403 | if (drawKeys) |
| 404 | DrawKey(key, keyX, keyY, keyW, keyH); |
| 405 | |
| 406 | // Draw highlight for capslock |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 407 | if (hasCapsHighlight && lay.is_caps && CapsLockOn && key.layout > 0 && key.layout == lay.revert_layout) { |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 408 | gr_color(mCapsHighlightColor.red, mCapsHighlightColor.green, mCapsHighlightColor.blue, mCapsHighlightColor.alpha); |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 409 | gr_fill(keyX, keyY, keyW, keyH); |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 410 | } |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 411 | |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 412 | // Draw highlight for control |
| 413 | if (hasCtrlHighlight && key.key == -KEY_LEFTCTRL && CtrlActive) { |
| 414 | gr_color(mCtrlHighlightColor.red, mCtrlHighlightColor.green, mCtrlHighlightColor.blue, mCtrlHighlightColor.alpha); |
| 415 | gr_fill(keyX, keyY, keyW, keyH); |
| 416 | } |
| 417 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 418 | // Highlight current key |
| 419 | if (hasHighlight && &key == currentKey && highlightRenderCount != 0) { |
| 420 | gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); |
| 421 | gr_fill(keyX, keyY, keyW, keyH); |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 425 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 426 | if (!hasHighlight || highlightRenderCount == 0) |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 427 | mRendered = true; |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 428 | else if (highlightRenderCount > 0) |
| 429 | highlightRenderCount--; |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 430 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | int GUIKeyboard::Update(void) |
| 434 | { |
| 435 | if (!isConditionTrue()) return (mRendered ? 2 : 0); |
| 436 | if (!mRendered) return 2; |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | int GUIKeyboard::SetRenderPos(int x, int y, int w, int h) |
| 442 | { |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 443 | RenderObject::SetRenderPos(x, y, w, h); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 444 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 445 | return 0; |
| 446 | } |
| 447 | |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 448 | GUIKeyboard::Key* GUIKeyboard::HitTestKey(int x, int y) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 449 | { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 450 | if (!IsInRegion(x, y)) |
| 451 | return NULL; |
| 452 | |
| 453 | int rely = y - mRenderY; |
| 454 | int relx = x - mRenderX; |
| 455 | |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 456 | Layout& lay = layouts[currentLayout - 1]; |
| 457 | |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 458 | // Find the correct row |
| 459 | int row; |
| 460 | for (row = 0; row < MAX_KEYBOARD_ROWS; ++row) { |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 461 | if (lay.row_end_y[row] > rely) |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | if (row == MAX_KEYBOARD_ROWS) |
| 465 | return NULL; |
| 466 | |
| 467 | // Find the correct key (column) |
| 468 | int col; |
| 469 | int x1 = 0; |
| 470 | for (col = 0; col < MAX_KEYBOARD_KEYS; ++col) { |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 471 | Key& key = lay.keys[row][col]; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 472 | if (x1 <= relx && relx < key.end_x && (key.key != 0 || key.layout != 0)) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 473 | // This is the key that was pressed! |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 474 | return &key; |
| 475 | } |
| 476 | x1 = key.end_x; |
| 477 | } |
| 478 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 482 | { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 483 | static int was_held = 0, startX = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 484 | |
| 485 | if (!isConditionTrue()) return -1; |
| 486 | |
| 487 | switch (state) |
| 488 | { |
| 489 | case TOUCH_START: |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 490 | was_held = 0; |
| 491 | startX = x; |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 492 | currentKey = HitTestKey(x, y); |
| 493 | if (currentKey) |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 494 | highlightRenderCount = -1; |
| 495 | else |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 496 | highlightRenderCount = 0; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 497 | mRendered = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 498 | break; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 499 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 500 | case TOUCH_DRAG: |
| 501 | break; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 502 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | case TOUCH_RELEASE: |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 504 | // TODO: we might want to notify of key releases here |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 505 | if (x < startX - (mRenderW * 0.5)) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 506 | if (highlightRenderCount != 0) { |
| 507 | highlightRenderCount = 0; |
| 508 | mRendered = false; |
| 509 | } |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 510 | PageManager::NotifyCharInput(KEYBOARD_SWIPE_LEFT); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 511 | return 0; |
that | f256b72 | 2015-05-23 20:44:12 +0200 | [diff] [blame] | 512 | } else if (x > startX + (mRenderW * 0.5)) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 513 | if (highlightRenderCount != 0) { |
| 514 | highlightRenderCount = 0; |
| 515 | mRendered = false; |
| 516 | } |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 517 | PageManager::NotifyCharInput(KEYBOARD_SWIPE_RIGHT); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 518 | return 0; |
| 519 | } |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 520 | // fall through |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 521 | case TOUCH_HOLD: |
| 522 | case TOUCH_REPEAT: |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 523 | if (!currentKey) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 524 | if (highlightRenderCount != 0) { |
| 525 | highlightRenderCount = 0; |
| 526 | mRendered = false; |
| 527 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 528 | return 0; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | if (highlightRenderCount != 0) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 532 | if (state == TOUCH_RELEASE) |
| 533 | highlightRenderCount = 2; |
| 534 | else |
| 535 | highlightRenderCount = -1; |
| 536 | mRendered = false; |
| 537 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 538 | |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 539 | if (HitTestKey(x, y) != currentKey) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 540 | // We dragged off of the starting key |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 541 | currentKey = NULL; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 542 | if (highlightRenderCount != 0) { |
| 543 | highlightRenderCount = 0; |
| 544 | mRendered = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | } |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 546 | return 0; |
| 547 | } else { |
that | f6b2066 | 2015-06-25 21:51:37 +0200 | [diff] [blame] | 548 | Key& key = *currentKey; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 549 | bool repeatKey = false; |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 550 | Layout& lay = layouts[currentLayout - 1]; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 551 | if (state == TOUCH_RELEASE && was_held == 0) { |
| 552 | DataManager::Vibrate("tw_keyboard_vibrate"); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 553 | if (key.layout > 0) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 554 | // Switch layouts |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 555 | if (lay.is_caps && key.layout == lay.revert_layout && !CapsLockOn) { |
| 556 | CapsLockOn = true; // Set the caps lock |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 557 | } else { |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 558 | CapsLockOn = false; // Unset the caps lock and change layouts |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 559 | currentLayout = key.layout; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 560 | } |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 561 | mRendered = false; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 562 | } else if (key.key == KEYBOARD_ACTION) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 563 | // Action |
| 564 | highlightRenderCount = 0; |
| 565 | // Send action notification |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 566 | PageManager::NotifyCharInput(key.key); |
| 567 | } else if (key.key == -KEY_LEFTCTRL) { |
| 568 | CtrlActive = !CtrlActive; // toggle Control key state |
| 569 | mRendered = false; // render Ctrl key highlight |
| 570 | } else if (key.key != 0) { |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 571 | // Regular key |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 572 | if (key.key > 0) { |
| 573 | // ASCII code or character |
| 574 | int keycode = key.key; |
| 575 | if (CtrlActive) { |
| 576 | CtrlActive = false; |
| 577 | mRendered = false; |
| 578 | keycode = KeyCharToCtrlChar(key.key); |
| 579 | } |
| 580 | PageManager::NotifyCharInput(keycode); |
| 581 | } else { |
| 582 | // Linux key code |
| 583 | PageManager::NotifyKey(-key.key, true); |
| 584 | PageManager::NotifyKey(-key.key, false); |
| 585 | } |
that | d86f49d | 2015-03-15 00:56:57 +0100 | [diff] [blame] | 586 | if (!CapsLockOn && lay.is_caps) { |
| 587 | // caps lock was not set, change layouts |
| 588 | currentLayout = lay.revert_layout; |
| 589 | mRendered = false; |
| 590 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 591 | } |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 592 | } else if (state == TOUCH_HOLD) { |
| 593 | was_held = 1; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 594 | if (key.longpresskey > 0) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 595 | // Long Press Key |
| 596 | DataManager::Vibrate("tw_keyboard_vibrate"); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 597 | PageManager::NotifyCharInput(key.longpresskey); |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 598 | } |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 599 | else |
| 600 | repeatKey = true; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 601 | } else if (state == TOUCH_REPEAT) { |
| 602 | was_held = 1; |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 603 | repeatKey = true; |
| 604 | } |
| 605 | if (repeatKey) { |
| 606 | if (key.key == KEYBOARD_BACKSPACE) { |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 607 | // Repeat backspace |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 608 | PageManager::NotifyCharInput(key.key); |
| 609 | } |
| 610 | switch (key.key) |
| 611 | { |
| 612 | // Repeat arrows |
| 613 | case -KEY_LEFT: |
| 614 | case -KEY_RIGHT: |
| 615 | case -KEY_UP: |
| 616 | case -KEY_DOWN: |
| 617 | PageManager::NotifyKey(-key.key, true); |
| 618 | PageManager::NotifyKey(-key.key, false); |
| 619 | break; |
that | e79878b | 2015-03-14 23:07:23 +0100 | [diff] [blame] | 620 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | break; |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 628 | |
| 629 | void GUIKeyboard::SetPageFocus(int inFocus) |
| 630 | { |
| 631 | if (inFocus) |
| 632 | CtrlActive = false; |
| 633 | } |