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