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