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 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 21 | #include "../data.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | |
| 23 | #include <string> |
| 24 | |
| 25 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 26 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 27 | #include "../minuitwrp/minui.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 | } |
| 30 | |
| 31 | #include "rapidxml.hpp" |
| 32 | #include "objects.hpp" |
| 33 | |
| 34 | GUIKeyboard::GUIKeyboard(xml_node<>* node) |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 35 | : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | { |
| 37 | int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 38 | rowY = colX = -1; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 39 | highlightRenderCount = 0; |
| 40 | hasHighlight = hasCapsHighlight = false; |
Dees_Troy | 3a16cb5 | 2013-01-10 15:16:02 +0000 | [diff] [blame] | 41 | char resource[10], layout[8], row[5], key[6], longpress[7]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | xml_attribute<>* attr; |
| 43 | xml_node<>* child; |
| 44 | xml_node<>* keylayout; |
| 45 | xml_node<>* keyrow; |
| 46 | |
| 47 | for (layoutindex=0; layoutindex<MAX_KEYBOARD_LAYOUTS; layoutindex++) |
| 48 | keyboardImg[layoutindex] = NULL; |
| 49 | |
| 50 | mRendered = false; |
| 51 | currentLayout = 1; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 52 | KeyboardHeight = KeyboardWidth = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
| 54 | if (!node) return; |
| 55 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 56 | mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlight); |
| 57 | mCapsHighlightColor = LoadAttrColor(FindNode(node, "capshighlight"), "color", &hasCapsHighlight); |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 58 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | // Load the images for the different layouts |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 60 | child = FindNode(node, "layout"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 61 | if (child) |
| 62 | { |
| 63 | layoutindex = 1; |
| 64 | strcpy(resource, "resource1"); |
| 65 | attr = child->first_attribute(resource); |
| 66 | while (attr && layoutindex < (MAX_KEYBOARD_LAYOUTS + 1)) { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 67 | keyboardImg[layoutindex - 1] = LoadAttrImage(child, resource); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | |
| 69 | layoutindex++; |
| 70 | resource[8] = (char)(layoutindex + 48); |
| 71 | attr = child->first_attribute(resource); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Check the first image to get height and width |
| 76 | if (keyboardImg[0] && keyboardImg[0]->GetResource()) |
| 77 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 78 | KeyboardWidth = keyboardImg[0]->GetWidth(); |
| 79 | KeyboardHeight = keyboardImg[0]->GetHeight(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Load all of the layout maps |
| 83 | layoutindex = 1; |
| 84 | strcpy(layout, "layout1"); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 85 | keylayout = FindNode(node, layout); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | while (keylayout) |
| 87 | { |
| 88 | if (layoutindex > MAX_KEYBOARD_LAYOUTS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 89 | LOGERR("Too many layouts defined in keyboard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
| 93 | child = keylayout->first_node("keysize"); |
| 94 | if (child) { |
| 95 | attr = child->first_attribute("height"); |
| 96 | if (attr) |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 97 | keyHeight = scale_theme_y(atoi(attr->value())); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 98 | else |
| 99 | keyHeight = 0; |
| 100 | attr = child->first_attribute("width"); |
| 101 | if (attr) |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 102 | keyWidth = scale_theme_x(atoi(attr->value())); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 103 | else |
| 104 | keyWidth = 0; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 105 | attr = child->first_attribute("capslock"); |
| 106 | if (attr) |
| 107 | caps_tracking[layoutindex - 1].capslock = atoi(attr->value()); |
| 108 | else |
| 109 | caps_tracking[layoutindex - 1].capslock = 1; |
| 110 | attr = child->first_attribute("revert_layout"); |
| 111 | if (attr) |
| 112 | caps_tracking[layoutindex - 1].revert_layout = atoi(attr->value()); |
| 113 | else |
| 114 | caps_tracking[layoutindex - 1].revert_layout = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | rowindex = 1; |
| 118 | Yindex = 0; |
| 119 | strcpy(row, "row1"); |
| 120 | keyrow = keylayout->first_node(row); |
| 121 | while (keyrow) |
| 122 | { |
| 123 | if (rowindex > MAX_KEYBOARD_ROWS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 124 | LOGERR("Too many rows defined in keyboard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 125 | return; |
| 126 | } |
| 127 | |
| 128 | Yindex += keyHeight; |
| 129 | row_heights[layoutindex - 1][rowindex - 1] = Yindex; |
| 130 | |
| 131 | keyindex = 1; |
| 132 | Xindex = 0; |
| 133 | strcpy(key, "key01"); |
| 134 | attr = keyrow->first_attribute(key); |
| 135 | |
| 136 | while (attr) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | if (keyindex > MAX_KEYBOARD_KEYS) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 138 | LOGERR("Too many keys defined in a keyboard row.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 139 | return; |
| 140 | } |
| 141 | |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 142 | const char* keyinfo = attr->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 143 | |
| 144 | if (strlen(keyinfo) == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 145 | 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] | 146 | return; |
| 147 | } |
| 148 | |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 149 | if (ParseKey(keyinfo, keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1], Xindex, keyWidth, false)) |
| 150 | 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] | 151 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | |
| 153 | // PROCESS LONG PRESS INFO IF EXISTS |
| 154 | sprintf(longpress, "long%02i", keyindex); |
| 155 | attr = keyrow->first_attribute(longpress); |
| 156 | if (attr) { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 157 | const char* keyinfo = attr->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 158 | |
| 159 | if (strlen(keyinfo) == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 160 | 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] | 161 | return; |
| 162 | } |
| 163 | |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 164 | if (ParseKey(keyinfo, keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1], Xindex, keyWidth, true)) |
| 165 | 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] | 166 | } |
| 167 | keyindex++; |
| 168 | sprintf(key, "key%02i", keyindex); |
| 169 | attr = keyrow->first_attribute(key); |
| 170 | } |
| 171 | rowindex++; |
| 172 | row[3] = (char)(rowindex + 48); |
| 173 | keyrow = keylayout->first_node(row); |
| 174 | } |
| 175 | layoutindex++; |
| 176 | layout[6] = (char)(layoutindex + 48); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 177 | keylayout = FindNode(node, layout); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | int x, y, w, h; |
| 181 | // Load the placement |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 182 | LoadPlacement(FindNode(node, "placement"), &x, &y, &w, &h); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 183 | SetActionPos(x, y, KeyboardWidth, KeyboardHeight); |
| 184 | SetRenderPos(x, y, w, h); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | GUIKeyboard::~GUIKeyboard() |
| 189 | { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 190 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 191 | |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 192 | int GUIKeyboard::ParseKey(const char* keyinfo, keyboard_key_class& key, int& Xindex, int keyWidth, bool longpress) |
| 193 | { |
| 194 | int keychar = 0; |
| 195 | if (strlen(keyinfo) == 1) { |
| 196 | // This is a single key, simple definition |
| 197 | keychar = keyinfo[0]; |
| 198 | } else { |
| 199 | // This key has extra data: {keywidth}:{what_the_key_does} |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 200 | keyWidth = scale_theme_x(atoi(keyinfo)); |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 201 | |
| 202 | const char* ptr = keyinfo; |
| 203 | while (*ptr > 32 && *ptr != ':') |
| 204 | ptr++; |
| 205 | if (*ptr != ':') |
| 206 | return -1; // no colon is an error |
| 207 | ptr++; |
| 208 | |
| 209 | if (*ptr == 0) { // This is an empty area |
| 210 | keychar = 0; |
| 211 | } else if (strlen(ptr) == 1) { // This is the character that this key uses |
| 212 | keychar = *ptr; |
| 213 | } else if (*ptr == 'c') { // This is an ASCII character code: "c:{number}" |
| 214 | keychar = atoi(ptr + 2); |
| 215 | } else if (*ptr == 'l') { // This is a different layout: "layout{number}" |
| 216 | keychar = KEYBOARD_LAYOUT; |
| 217 | key.layout = atoi(ptr + 6); |
| 218 | } else if (*ptr == 'a') { // This is an action: "action" |
| 219 | keychar = KEYBOARD_ACTION; |
| 220 | } else |
| 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | if (longpress) { |
| 225 | key.longpresskey = keychar; |
| 226 | } else { |
| 227 | key.key = keychar; |
| 228 | Xindex += keyWidth; |
| 229 | key.end_x = Xindex - 1; |
| 230 | } |
| 231 | |
| 232 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | int GUIKeyboard::Render(void) |
| 236 | { |
| 237 | if (!isConditionTrue()) |
| 238 | { |
| 239 | mRendered = false; |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | int ret = 0; |
| 244 | |
| 245 | if (keyboardImg[currentLayout - 1] && keyboardImg[currentLayout - 1]->GetResource()) |
| 246 | gr_blit(keyboardImg[currentLayout - 1]->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY); |
| 247 | |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 248 | // Draw highlight for capslock |
| 249 | if (hasCapsHighlight && caps_tracking[currentLayout - 1].capslock == 0 && caps_tracking[currentLayout - 1].set_capslock) { |
| 250 | int boxheight, boxwidth, x; |
| 251 | gr_color(mCapsHighlightColor.red, mCapsHighlightColor.green, mCapsHighlightColor.blue, mCapsHighlightColor.alpha); |
| 252 | for (int indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) { |
| 253 | for (int indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) { |
| 254 | if ((int)keyboard_keys[currentLayout - 1][indexy][indexx].key == KEYBOARD_LAYOUT && (int)keyboard_keys[currentLayout - 1][indexy][indexx].layout == caps_tracking[currentLayout - 1].revert_layout) { |
| 255 | if (indexy == 0) |
| 256 | boxheight = row_heights[currentLayout - 1][indexy]; |
| 257 | else |
| 258 | boxheight = row_heights[currentLayout - 1][indexy] - row_heights[currentLayout - 1][indexy - 1]; |
| 259 | if (indexx == 0) { |
| 260 | x = mRenderX; |
| 261 | boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x; |
| 262 | } else { |
| 263 | x = mRenderX + keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x; |
| 264 | boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x - keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x; |
| 265 | } |
| 266 | gr_fill(x, mRenderY + row_heights[currentLayout - 1][indexy - 1], boxwidth, boxheight); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 272 | if (hasHighlight && highlightRenderCount != 0) { |
| 273 | int boxheight, boxwidth, x; |
| 274 | if (rowY == 0) |
| 275 | boxheight = row_heights[currentLayout - 1][rowY]; |
| 276 | else |
| 277 | boxheight = row_heights[currentLayout - 1][rowY] - row_heights[currentLayout - 1][rowY - 1]; |
| 278 | if (colX == 0) { |
| 279 | x = mRenderX; |
| 280 | boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x; |
| 281 | } else { |
| 282 | x = mRenderX + keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; |
| 283 | boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x - keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; |
| 284 | } |
| 285 | gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); |
| 286 | gr_fill(x, mRenderY + row_heights[currentLayout - 1][rowY - 1], boxwidth, boxheight); |
| 287 | if (highlightRenderCount > 0) |
| 288 | highlightRenderCount--; |
| 289 | } else |
| 290 | mRendered = true; |
| 291 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | int GUIKeyboard::Update(void) |
| 296 | { |
| 297 | if (!isConditionTrue()) return (mRendered ? 2 : 0); |
| 298 | if (!mRendered) return 2; |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | int GUIKeyboard::SetRenderPos(int x, int y, int w, int h) |
| 304 | { |
| 305 | mRenderX = x; |
| 306 | mRenderY = y; |
| 307 | if (w || h) |
| 308 | { |
| 309 | mRenderW = KeyboardWidth; |
| 310 | mRenderH = KeyboardHeight; |
| 311 | } |
| 312 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 313 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | int GUIKeyboard::GetSelection(int x, int y) |
| 318 | { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 319 | if (x < mRenderX || x - mRenderX > (int)KeyboardWidth || y < mRenderY || y - mRenderY > (int)KeyboardHeight) return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 324 | { |
| 325 | static int startSelection = -1, was_held = 0, startX = 0; |
| 326 | static unsigned char initial_key = 0; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 327 | int indexy, indexx, rely, relx, rowIndex = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 328 | |
| 329 | rely = y - mRenderY; |
| 330 | relx = x - mRenderX; |
| 331 | |
| 332 | if (!isConditionTrue()) return -1; |
| 333 | |
| 334 | switch (state) |
| 335 | { |
| 336 | case TOUCH_START: |
| 337 | if (GetSelection(x, y) == 0) { |
| 338 | startSelection = -1; |
| 339 | was_held = 0; |
| 340 | startX = x; |
| 341 | // Find the correct row |
| 342 | for (indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) { |
| 343 | if (row_heights[currentLayout - 1][indexy] > rely) { |
| 344 | rowIndex = indexy; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 345 | rowY = indexy; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 346 | indexy = MAX_KEYBOARD_ROWS; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // Find the correct key (column) |
| 351 | for (indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) { |
| 352 | if (keyboard_keys[currentLayout - 1][rowIndex][indexx].end_x > relx) { |
| 353 | // This is the key that was pressed! |
| 354 | initial_key = keyboard_keys[currentLayout - 1][rowIndex][indexx].key; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 355 | colX = indexx; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 356 | indexx = MAX_KEYBOARD_KEYS; |
| 357 | } |
| 358 | } |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 359 | if (initial_key != 0) |
| 360 | highlightRenderCount = -1; |
| 361 | else |
| 362 | highlightRenderCount = 0; |
| 363 | mRendered = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 364 | } else { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 365 | if (highlightRenderCount != 0) |
| 366 | mRendered = false; |
| 367 | highlightRenderCount = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 368 | startSelection = 0; |
| 369 | } |
| 370 | break; |
| 371 | case TOUCH_DRAG: |
| 372 | break; |
| 373 | case TOUCH_RELEASE: |
Dees_Troy | 0cb64e5 | 2012-10-15 15:56:10 -0400 | [diff] [blame] | 374 | if (x < startX - (KeyboardWidth * 0.5)) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 375 | if (highlightRenderCount != 0) { |
| 376 | highlightRenderCount = 0; |
| 377 | mRendered = false; |
| 378 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 379 | PageManager::NotifyKeyboard(KEYBOARD_SWIPE_LEFT); |
| 380 | return 0; |
Dees_Troy | 0cb64e5 | 2012-10-15 15:56:10 -0400 | [diff] [blame] | 381 | } else if (x > startX + (KeyboardWidth * 0.5)) { |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 382 | if (highlightRenderCount != 0) { |
| 383 | highlightRenderCount = 0; |
| 384 | mRendered = false; |
| 385 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 386 | PageManager::NotifyKeyboard(KEYBOARD_SWIPE_RIGHT); |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | case TOUCH_HOLD: |
| 391 | case TOUCH_REPEAT: |
| 392 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 393 | if (startSelection == 0 || GetSelection(x, y) == -1) { |
| 394 | if (highlightRenderCount != 0) { |
| 395 | highlightRenderCount = 0; |
| 396 | mRendered = false; |
| 397 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 398 | return 0; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 399 | } else if (highlightRenderCount != 0) { |
| 400 | if (state == TOUCH_RELEASE) |
| 401 | highlightRenderCount = 2; |
| 402 | else |
| 403 | highlightRenderCount = -1; |
| 404 | mRendered = false; |
| 405 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 406 | |
| 407 | // Find the correct row |
| 408 | for (indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) { |
| 409 | if (row_heights[currentLayout - 1][indexy] > rely) { |
| 410 | rowIndex = indexy; |
| 411 | indexy = MAX_KEYBOARD_ROWS; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // Find the correct key (column) |
| 416 | for (indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 417 | keyboard_key_class& key = keyboard_keys[currentLayout - 1][rowIndex][indexx]; |
| 418 | if (key.end_x > relx) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 419 | // This is the key that was pressed! |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 420 | if (key.key != initial_key) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 421 | // We dragged off of the starting key |
| 422 | startSelection = 0; |
| 423 | break; |
| 424 | } else if (state == TOUCH_RELEASE && was_held == 0) { |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 425 | DataManager::Vibrate("tw_keyboard_vibrate"); |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 426 | if ((int)key.key < KEYBOARD_SPECIAL_KEYS && (int)key.key > 0) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 427 | // Regular key |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 428 | PageManager::NotifyKeyboard(key.key); |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 429 | if (caps_tracking[currentLayout - 1].capslock == 0 && !caps_tracking[currentLayout - 1].set_capslock) { |
| 430 | // caps lock was not set, change layouts |
| 431 | currentLayout = caps_tracking[currentLayout - 1].revert_layout; |
| 432 | mRendered = false; |
| 433 | } |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 434 | } else if ((int)key.key == KEYBOARD_LAYOUT) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 435 | // Switch layouts |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 436 | if (caps_tracking[currentLayout - 1].capslock == 0 && key.layout == caps_tracking[currentLayout - 1].revert_layout) { |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 437 | if (!caps_tracking[currentLayout - 1].set_capslock) { |
| 438 | caps_tracking[currentLayout - 1].set_capslock = 1; // Set the caps lock |
| 439 | } else { |
| 440 | caps_tracking[currentLayout - 1].set_capslock = 0; // Unset the caps lock and change layouts |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 441 | currentLayout = key.layout; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 442 | } |
| 443 | } else { |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 444 | currentLayout = key.layout; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 445 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 446 | mRendered = false; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 447 | } else if ((int)key.key == KEYBOARD_ACTION) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 448 | // Action |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 449 | highlightRenderCount = 0; |
that | 6db855e | 2015-03-14 21:31:43 +0100 | [diff] [blame^] | 450 | // Send action notification |
| 451 | PageManager::NotifyKeyboard(key.key); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | } |
| 453 | } else if (state == TOUCH_HOLD) { |
| 454 | was_held = 1; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 455 | if ((int)key.key == KEYBOARD_BACKSPACE) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 456 | // Repeat backspace |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 457 | PageManager::NotifyKeyboard(key.key); |
| 458 | } else if ((int)key.longpresskey < KEYBOARD_SPECIAL_KEYS && (int)key.longpresskey > 0) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 459 | // Long Press Key |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 460 | DataManager::Vibrate("tw_keyboard_vibrate"); |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 461 | PageManager::NotifyKeyboard(key.longpresskey); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 462 | } |
| 463 | } else if (state == TOUCH_REPEAT) { |
| 464 | was_held = 1; |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 465 | if ((int)key.key == KEYBOARD_BACKSPACE) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 466 | // Repeat backspace |
that | 1a7ba97 | 2015-02-01 19:48:19 +0100 | [diff] [blame] | 467 | PageManager::NotifyKeyboard(key.key); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | indexx = MAX_KEYBOARD_KEYS; |
| 471 | } |
| 472 | } |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | return 0; |
| 477 | } |