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