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