Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 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 <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <errno.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <sys/reboot.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/time.h> |
| 30 | #include <sys/mman.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/mount.h> |
| 34 | #include <time.h> |
| 35 | #include <unistd.h> |
| 36 | #include <stdlib.h> |
| 37 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 38 | extern "C" |
| 39 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 40 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | #include <pixelflinger/pixelflinger.h> |
| 42 | } |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 43 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | |
| 45 | #include "rapidxml.hpp" |
| 46 | #include "objects.hpp" |
| 47 | #include "../data.hpp" |
| 48 | #include "../variables.h" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 49 | #include "../partitions.hpp" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 50 | #include "../twrp-functions.hpp" |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 51 | #include "../openrecoveryscript.hpp" |
| 52 | #include "../orscmd/orscmd.h" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 53 | #include "blanktimer.hpp" |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 54 | #include "../tw_atomic.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 56 | // Enable to print render time of each frame to the log file |
| 57 | //#define PRINT_RENDER_TIME 1 |
| 58 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 59 | #ifdef _EVENT_LOGGING |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 60 | #define LOGEVENT(...) LOGERR(__VA_ARGS__) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 61 | #else |
| 62 | #define LOGEVENT(...) do {} while (0) |
| 63 | #endif |
| 64 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | using namespace rapidxml; |
| 66 | |
| 67 | // Global values |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | static int gGuiInitialized = 0; |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 69 | static TWAtomicInt gForceRender; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 70 | blanktimer blankTimer; |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 71 | int ors_read_fd = -1; |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 72 | static FILE* orsout = NULL; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 73 | static float scale_theme_w = 1; |
| 74 | static float scale_theme_h = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 75 | |
| 76 | // Needed by pages.cpp too |
| 77 | int gGuiRunning = 0; |
| 78 | |
that | 1964d19 | 2016-01-07 00:41:03 +0100 | [diff] [blame] | 79 | int g_pty_fd = -1; // set by terminal on init |
| 80 | void terminal_pty_read(); |
| 81 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | static int gRecorder = -1; |
| 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | extern "C" void gr_write_frame_to_file(int fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 85 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 86 | void flip(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 87 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 88 | if (gRecorder != -1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 89 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | timespec time; |
| 91 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 92 | write(gRecorder, &time, sizeof(timespec)); |
| 93 | gr_write_frame_to_file(gRecorder); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 94 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 95 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 98 | void rapidxml::parse_error_handler(const char *what, void *where) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 99 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 100 | fprintf(stderr, "Parser error: %s\n", what); |
| 101 | fprintf(stderr, " Start of string: %s\n",(char *) where); |
| 102 | LOGERR("Error parsing XML file.\n"); |
| 103 | //abort(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | } |
| 105 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 106 | class InputHandler |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 107 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 108 | public: |
| 109 | void init() |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 110 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 111 | // these might be read from DataManager in the future |
| 112 | touch_hold_ms = 500; |
| 113 | touch_repeat_ms = 100; |
| 114 | key_hold_ms = 500; |
| 115 | key_repeat_ms = 100; |
| 116 | touch_status = TS_NONE; |
| 117 | key_status = KS_NONE; |
| 118 | state = AS_NO_ACTION; |
| 119 | x = y = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 120 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 121 | #ifndef TW_NO_SCREEN_TIMEOUT |
| 122 | { |
| 123 | string seconds; |
| 124 | DataManager::GetValue("tw_screen_timeout_secs", seconds); |
| 125 | blankTimer.setTime(atoi(seconds.c_str())); |
| 126 | blankTimer.resetTimerAndUnblank(); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 127 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 128 | #else |
| 129 | LOGINFO("Skipping screen timeout: TW_NO_SCREEN_TIMEOUT is set\n"); |
| 130 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 131 | } |
| 132 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 133 | // process input events. returns true if any event was received. |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 134 | bool processInput(int timeout_ms); |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 135 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 136 | void handleDrag(); |
| 137 | |
| 138 | private: |
| 139 | // timeouts for touch/key hold and repeat |
| 140 | int touch_hold_ms; |
| 141 | int touch_repeat_ms; |
| 142 | int key_hold_ms; |
| 143 | int key_repeat_ms; |
| 144 | |
| 145 | enum touch_status_enum { |
| 146 | TS_NONE = 0, |
| 147 | TS_TOUCH_AND_HOLD = 1, |
| 148 | TS_TOUCH_REPEAT = 2, |
| 149 | }; |
| 150 | |
| 151 | enum key_status_enum { |
| 152 | KS_NONE = 0, |
| 153 | KS_KEY_PRESSED = 1, |
| 154 | KS_KEY_REPEAT = 2, |
| 155 | }; |
| 156 | |
| 157 | enum action_state_enum { |
| 158 | AS_IN_ACTION_AREA = 0, // we've touched a spot with an action |
| 159 | AS_NO_ACTION = 1, // we've touched in an empty area (no action) and ignore remaining events until touch release |
| 160 | }; |
| 161 | touch_status_enum touch_status; |
| 162 | key_status_enum key_status; |
| 163 | action_state_enum state; |
| 164 | int x, y; // x and y coordinates of last touch |
| 165 | struct timeval touchStart; // used to track time for long press / key repeat |
| 166 | |
| 167 | void processHoldAndRepeat(); |
| 168 | void process_EV_REL(input_event& ev); |
| 169 | void process_EV_ABS(input_event& ev); |
| 170 | void process_EV_KEY(input_event& ev); |
| 171 | |
| 172 | void doTouchStart(); |
| 173 | }; |
| 174 | |
| 175 | InputHandler input_handler; |
| 176 | |
| 177 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 178 | bool InputHandler::processInput(int timeout_ms) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 179 | { |
| 180 | input_event ev; |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 181 | int ret = ev_get(&ev, timeout_ms); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 182 | |
| 183 | if (ret < 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 184 | { |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 185 | // This path means that we did not get any new touch data, but |
| 186 | // we do not get new touch data if you press and hold on either |
| 187 | // the screen or on a keyboard key or mouse button |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 188 | if (touch_status || key_status) |
| 189 | processHoldAndRepeat(); |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 190 | return (ret != -2); // -2 means no more events in the queue |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 191 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 192 | |
| 193 | switch (ev.type) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 194 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 195 | case EV_ABS: |
| 196 | process_EV_ABS(ev); |
| 197 | break; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 198 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 199 | case EV_REL: |
| 200 | process_EV_REL(ev); |
| 201 | break; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 202 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 203 | case EV_KEY: |
| 204 | process_EV_KEY(ev); |
| 205 | break; |
| 206 | } |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 207 | |
| 208 | blankTimer.resetTimerAndUnblank(); |
| 209 | return true; // we got an event, so there might be more in the queue |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void InputHandler::processHoldAndRepeat() |
| 213 | { |
| 214 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
| 215 | |
| 216 | // touch and key repeat section |
| 217 | struct timeval curTime; |
| 218 | gettimeofday(&curTime, NULL); |
| 219 | long seconds = curTime.tv_sec - touchStart.tv_sec; |
| 220 | long useconds = curTime.tv_usec - touchStart.tv_usec; |
| 221 | long mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; |
| 222 | |
| 223 | if (touch_status == TS_TOUCH_AND_HOLD && mtime > touch_hold_ms) |
| 224 | { |
| 225 | touch_status = TS_TOUCH_REPEAT; |
| 226 | gettimeofday(&touchStart, NULL); |
| 227 | LOGEVENT("TOUCH_HOLD: %d,%d\n", x, y); |
| 228 | PageManager::NotifyTouch(TOUCH_HOLD, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 229 | } |
| 230 | else if (touch_status == TS_TOUCH_REPEAT && mtime > touch_repeat_ms) |
| 231 | { |
| 232 | LOGEVENT("TOUCH_REPEAT: %d,%d\n", x, y); |
| 233 | gettimeofday(&touchStart, NULL); |
| 234 | PageManager::NotifyTouch(TOUCH_REPEAT, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 235 | } |
| 236 | else if (key_status == KS_KEY_PRESSED && mtime > key_hold_ms) |
| 237 | { |
| 238 | LOGEVENT("KEY_HOLD: %d,%d\n", x, y); |
| 239 | gettimeofday(&touchStart, NULL); |
| 240 | key_status = KS_KEY_REPEAT; |
| 241 | kb->KeyRepeat(); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 242 | } |
| 243 | else if (key_status == KS_KEY_REPEAT && mtime > key_repeat_ms) |
| 244 | { |
| 245 | LOGEVENT("KEY_REPEAT: %d,%d\n", x, y); |
| 246 | gettimeofday(&touchStart, NULL); |
| 247 | kb->KeyRepeat(); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | void InputHandler::doTouchStart() |
| 252 | { |
| 253 | LOGEVENT("TOUCH_START: %d,%d\n", x, y); |
| 254 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 255 | state = AS_NO_ACTION; |
| 256 | else |
| 257 | state = AS_IN_ACTION_AREA; |
| 258 | touch_status = TS_TOUCH_AND_HOLD; |
| 259 | gettimeofday(&touchStart, NULL); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void InputHandler::process_EV_ABS(input_event& ev) |
| 263 | { |
| 264 | x = ev.value >> 16; |
| 265 | y = ev.value & 0xFFFF; |
| 266 | |
| 267 | if (ev.code == 0) |
| 268 | { |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 269 | #ifndef TW_USE_KEY_CODE_TOUCH_SYNC |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 270 | if (state == AS_IN_ACTION_AREA) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 271 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 272 | LOGEVENT("TOUCH_RELEASE: %d,%d\n", x, y); |
| 273 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 274 | } |
| 275 | touch_status = TS_NONE; |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 276 | #endif |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 277 | } |
| 278 | else |
| 279 | { |
| 280 | if (!touch_status) |
| 281 | { |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 282 | #ifndef TW_USE_KEY_CODE_TOUCH_SYNC |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 283 | doTouchStart(); |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 284 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 285 | } |
| 286 | else |
| 287 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 288 | if (state == AS_IN_ACTION_AREA) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 289 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 290 | LOGEVENT("TOUCH_DRAG: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 291 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 292 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 293 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void InputHandler::process_EV_KEY(input_event& ev) |
| 297 | { |
| 298 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
| 299 | |
| 300 | // Handle key-press here |
| 301 | LOGEVENT("TOUCH_KEY: %d\n", ev.code); |
| 302 | // Left mouse button is treated as a touch |
| 303 | if(ev.code == BTN_LEFT) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 304 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 305 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
| 306 | if(ev.value == 1) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 307 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 308 | cursor->GetPos(x, y); |
| 309 | doTouchStart(); |
| 310 | } |
| 311 | else if(touch_status) |
| 312 | { |
| 313 | // Left mouse button was previously pressed and now is |
| 314 | // being released so send a TOUCH_RELEASE |
| 315 | if (state == AS_IN_ACTION_AREA) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 316 | { |
| 317 | cursor->GetPos(x, y); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 318 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 319 | LOGEVENT("Mouse TOUCH_RELEASE: %d,%d\n", x, y); |
| 320 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 321 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 322 | touch_status = TS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 323 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 324 | } |
| 325 | // side mouse button, often used for "back" function |
| 326 | else if(ev.code == BTN_SIDE) |
| 327 | { |
| 328 | if(ev.value == 1) |
| 329 | kb->KeyDown(KEY_BACK); |
| 330 | else |
| 331 | kb->KeyUp(KEY_BACK); |
| 332 | } else if (ev.value != 0) { |
| 333 | // This is a key press |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 334 | #ifdef TW_USE_KEY_CODE_TOUCH_SYNC |
| 335 | if (ev.code == TW_USE_KEY_CODE_TOUCH_SYNC) { |
| 336 | LOGEVENT("key code %i key press == touch start %i %i\n", TW_USE_KEY_CODE_TOUCH_SYNC, x, y); |
| 337 | doTouchStart(); |
| 338 | return; |
| 339 | } |
| 340 | #endif |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 341 | if (kb->KeyDown(ev.code)) { |
| 342 | // Key repeat is enabled for this key |
| 343 | key_status = KS_KEY_PRESSED; |
| 344 | touch_status = TS_NONE; |
| 345 | gettimeofday(&touchStart, NULL); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 346 | } else { |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 347 | key_status = KS_NONE; |
| 348 | touch_status = TS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 349 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 350 | } else { |
| 351 | // This is a key release |
| 352 | kb->KeyUp(ev.code); |
| 353 | key_status = KS_NONE; |
| 354 | touch_status = TS_NONE; |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 355 | #ifdef TW_USE_KEY_CODE_TOUCH_SYNC |
| 356 | if (ev.code == TW_USE_KEY_CODE_TOUCH_SYNC) { |
| 357 | LOGEVENT("key code %i key release == touch release %i %i\n", TW_USE_KEY_CODE_TOUCH_SYNC, x, y); |
| 358 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
| 359 | } |
| 360 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 361 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 362 | } |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 363 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 364 | void InputHandler::process_EV_REL(input_event& ev) |
| 365 | { |
| 366 | // Mouse movement |
| 367 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
| 368 | LOGEVENT("EV_REL %d %d\n", ev.code, ev.value); |
| 369 | if(ev.code == REL_X) |
| 370 | cursor->Move(ev.value, 0); |
| 371 | else if(ev.code == REL_Y) |
| 372 | cursor->Move(0, ev.value); |
| 373 | |
| 374 | if(touch_status) { |
| 375 | cursor->GetPos(x, y); |
| 376 | LOGEVENT("Mouse TOUCH_DRAG: %d, %d\n", x, y); |
| 377 | key_status = KS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 378 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void InputHandler::handleDrag() |
| 382 | { |
| 383 | // This allows us to only send one NotifyTouch event per render |
| 384 | // cycle to reduce overhead and perceived input latency. |
| 385 | static int prevx = 0, prevy = 0; // these track where the last drag notice was so that we don't send duplicate drag notices |
| 386 | if (touch_status && (x != prevx || y != prevy)) { |
| 387 | prevx = x; |
| 388 | prevy = y; |
| 389 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 390 | state = AS_NO_ACTION; |
| 391 | else |
| 392 | state = AS_IN_ACTION_AREA; |
| 393 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 394 | } |
| 395 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 396 | static void setup_ors_command() |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 397 | { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 398 | ors_read_fd = -1; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 399 | |
| 400 | unlink(ORS_INPUT_FILE); |
| 401 | if (mkfifo(ORS_INPUT_FILE, 06660) != 0) { |
| 402 | LOGINFO("Unable to mkfifo %s\n", ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 403 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 404 | } |
| 405 | unlink(ORS_OUTPUT_FILE); |
| 406 | if (mkfifo(ORS_OUTPUT_FILE, 06666) != 0) { |
| 407 | LOGINFO("Unable to mkfifo %s\n", ORS_OUTPUT_FILE); |
| 408 | unlink(ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 409 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 410 | } |
| 411 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 412 | ors_read_fd = open(ORS_INPUT_FILE, O_RDONLY | O_NONBLOCK); |
| 413 | if (ors_read_fd < 0) { |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 414 | LOGINFO("Unable to open %s\n", ORS_INPUT_FILE); |
| 415 | unlink(ORS_INPUT_FILE); |
| 416 | unlink(ORS_OUTPUT_FILE); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 417 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 418 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 419 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 420 | // callback called after a CLI command was executed |
| 421 | static void ors_command_done() |
| 422 | { |
| 423 | gui_set_FILE(NULL); |
| 424 | fclose(orsout); |
| 425 | orsout = NULL; |
| 426 | |
| 427 | if (DataManager::GetIntValue("tw_page_done") == 0) { |
| 428 | // The select function will return ready to read and the |
| 429 | // read function will return errno 19 no such device unless |
| 430 | // we set everything up all over again. |
| 431 | close(ors_read_fd); |
| 432 | setup_ors_command(); |
| 433 | } |
| 434 | } |
| 435 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 436 | static void ors_command_read() |
| 437 | { |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 438 | char command[1024]; |
| 439 | int read_ret = read(ors_read_fd, &command, sizeof(command)); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 440 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 441 | if (read_ret > 0) { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 442 | command[1022] = '\n'; |
| 443 | command[1023] = '\0'; |
| 444 | LOGINFO("Command '%s' received\n", command); |
| 445 | orsout = fopen(ORS_OUTPUT_FILE, "w"); |
| 446 | if (!orsout) { |
| 447 | close(ors_read_fd); |
| 448 | ors_read_fd = -1; |
| 449 | LOGINFO("Unable to fopen %s\n", ORS_OUTPUT_FILE); |
| 450 | unlink(ORS_INPUT_FILE); |
| 451 | unlink(ORS_OUTPUT_FILE); |
| 452 | return; |
| 453 | } |
| 454 | if (DataManager::GetIntValue("tw_busy") != 0) { |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 455 | fputs("Failed, operation in progress\n", orsout); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 456 | LOGINFO("Command cannot be performed, operation in progress.\n"); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 457 | fclose(orsout); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 458 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 459 | if (strlen(command) == 11 && strncmp(command, "dumpstrings", 11) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 460 | gui_set_FILE(orsout); |
| 461 | PageManager::GetResources()->DumpStrings(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 462 | ors_command_done(); |
| 463 | } else { |
| 464 | // mirror output messages |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 465 | gui_set_FILE(orsout); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 466 | // close orsout and restart listener after command is done |
| 467 | OpenRecoveryScript::Call_After_CLI_Command(ors_command_done); |
| 468 | // run the command in a threaded action... |
| 469 | DataManager::SetValue("tw_action", "twcmd"); |
| 470 | DataManager::SetValue("tw_action_param", command); |
| 471 | // ...and switch back to the current page when finished |
| 472 | std::string currentPage = PageManager::GetCurrentPage(); |
| 473 | DataManager::SetValue("tw_has_action2", "1"); |
| 474 | DataManager::SetValue("tw_action2", "page"); |
| 475 | DataManager::SetValue("tw_action2_param", currentPage); |
| 476 | DataManager::SetValue("tw_action_text1", gui_lookup("running_recovery_commands", "Running Recovery Commands")); |
| 477 | DataManager::SetValue("tw_action_text2", ""); |
| 478 | gui_changePage("singleaction_page"); |
| 479 | // now immediately return to the GUI main loop (the action runs in the background thread) |
| 480 | // put all things that need to be done after the command is finished into ors_command_done, not here |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 481 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 482 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 483 | } else { |
| 484 | LOGINFO("ORS command line read returned an error: %i, %i, %s\n", read_ret, errno, strerror(errno)); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 485 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 486 | } |
| 487 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 488 | // Get and dispatch input events until it's time to draw the next frame |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 489 | // This special function will return immediately the first time, but then |
| 490 | // always returns 1/30th of a second (or immediately if called later) from |
| 491 | // the last time it was called |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 492 | static void loopTimer(int input_timeout_ms) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 493 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 494 | static timespec lastCall; |
| 495 | static int initialized = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 496 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 497 | if (!initialized) |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 498 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 499 | clock_gettime(CLOCK_MONOTONIC, &lastCall); |
| 500 | initialized = 1; |
| 501 | return; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 502 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 504 | do |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 505 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 506 | bool got_event = input_handler.processInput(input_timeout_ms); // get inputs but don't send drag notices |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 507 | timespec curTime; |
| 508 | clock_gettime(CLOCK_MONOTONIC, &curTime); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 509 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 510 | timespec diff = TWFunc::timespec_diff(lastCall, curTime); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 511 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 512 | // This is really 2 or 30 times per second |
| 513 | // As long as we get events, increase the timeout so we can catch up with input |
| 514 | long timeout = got_event ? 500000000 : 33333333; |
| 515 | |
| 516 | if (diff.tv_sec || diff.tv_nsec > timeout) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 517 | { |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 518 | // int32_t input_time = TWFunc::timespec_diff_ms(lastCall, curTime); |
| 519 | // LOGINFO("loopTimer(): %u ms, count: %u\n", input_time, count); |
| 520 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 521 | lastCall = curTime; |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 522 | input_handler.handleDrag(); // send only drag notices if needed |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 523 | return; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 526 | // We need to sleep some period time microseconds |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 527 | //unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); |
| 528 | //usleep(sleepTime); // removed so we can scan for input |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 529 | input_timeout_ms = 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 530 | } while (1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 531 | } |
| 532 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 533 | static int runPages(const char *page_name, const int stop_on_page_done) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 534 | { |
Ethan Yonker | 3f15be4 | 2015-02-09 09:39:47 -0600 | [diff] [blame] | 535 | DataManager::SetValue("tw_page_done", 0); |
| 536 | DataManager::SetValue("tw_gui_done", 0); |
| 537 | |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 538 | if (page_name) { |
| 539 | PageManager::SetStartPage(page_name); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 540 | gui_changePage(page_name); |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 541 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 542 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 543 | gGuiRunning = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 544 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 545 | DataManager::SetValue("tw_loaded", 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 546 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 547 | #ifndef TW_OEM_BUILD |
| 548 | struct timeval timeout; |
| 549 | fd_set fdset; |
| 550 | int has_data = 0; |
| 551 | #endif |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 552 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 553 | int input_timeout_ms = 0; |
| 554 | int idle_frames = 0; |
| 555 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 556 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 557 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 558 | loopTimer(input_timeout_ms); |
that | 1964d19 | 2016-01-07 00:41:03 +0100 | [diff] [blame] | 559 | if (g_pty_fd > 0) { |
| 560 | // TODO: this is not nice, we should have one central select for input, pty, and ors |
| 561 | FD_ZERO(&fdset); |
| 562 | FD_SET(g_pty_fd, &fdset); |
| 563 | timeout.tv_sec = 0; |
| 564 | timeout.tv_usec = 1; |
| 565 | has_data = select(g_pty_fd+1, &fdset, NULL, NULL, &timeout); |
| 566 | if (has_data > 0) { |
| 567 | terminal_pty_read(); |
| 568 | } |
| 569 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 570 | #ifndef TW_OEM_BUILD |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 571 | if (ors_read_fd > 0 && !orsout) { // orsout is non-NULL if a command is still running |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 572 | FD_ZERO(&fdset); |
| 573 | FD_SET(ors_read_fd, &fdset); |
| 574 | timeout.tv_sec = 0; |
| 575 | timeout.tv_usec = 1; |
| 576 | has_data = select(ors_read_fd+1, &fdset, NULL, NULL, &timeout); |
| 577 | if (has_data > 0) { |
| 578 | ors_command_read(); |
| 579 | } |
| 580 | } |
| 581 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 582 | |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 583 | if (!gForceRender.get_value()) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 584 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 585 | int ret = PageManager::Update(); |
| 586 | if (ret == 0) |
| 587 | ++idle_frames; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 588 | else if (ret == -2) |
| 589 | break; // Theme reload failure |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 590 | else |
| 591 | idle_frames = 0; |
| 592 | // due to possible animation objects, we need to delay activating the input timeout |
| 593 | input_timeout_ms = idle_frames > 15 ? 1000 : 0; |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 594 | |
| 595 | #ifndef PRINT_RENDER_TIME |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 596 | if (ret > 1) |
| 597 | PageManager::Render(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 598 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 599 | if (ret > 0) |
| 600 | flip(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 601 | #else |
| 602 | if (ret > 1) |
| 603 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 604 | timespec start, end; |
| 605 | int32_t render_t, flip_t; |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 606 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 607 | PageManager::Render(); |
| 608 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 609 | render_t = TWFunc::timespec_diff_ms(start, end); |
| 610 | |
| 611 | flip(); |
| 612 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 613 | flip_t = TWFunc::timespec_diff_ms(end, start); |
| 614 | |
| 615 | LOGINFO("Render(): %u ms, flip(): %u ms, total: %u ms\n", render_t, flip_t, render_t+flip_t); |
| 616 | } |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 617 | else if (ret > 0) |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 618 | flip(); |
| 619 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 620 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 621 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 622 | { |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 623 | gForceRender.set_value(0); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 624 | PageManager::Render(); |
| 625 | flip(); |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 626 | input_timeout_ms = 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 627 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 628 | |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 629 | blankTimer.checkForTimeout(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 630 | if (stop_on_page_done && DataManager::GetIntValue("tw_page_done") != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 631 | { |
| 632 | gui_changePage("main"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 633 | break; |
| 634 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 635 | if (DataManager::GetIntValue("tw_gui_done") != 0) |
| 636 | break; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 637 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 638 | if (ors_read_fd > 0) |
| 639 | close(ors_read_fd); |
| 640 | ors_read_fd = -1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 641 | gGuiRunning = 0; |
| 642 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 643 | } |
| 644 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 645 | int gui_forceRender(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 646 | { |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 647 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 648 | return 0; |
| 649 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 650 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 651 | int gui_changePage(std::string newPage) |
| 652 | { |
| 653 | LOGINFO("Set page: '%s'\n", newPage.c_str()); |
| 654 | PageManager::ChangePage(newPage); |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 655 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | int gui_changeOverlay(std::string overlay) |
| 660 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 661 | LOGINFO("Set overlay: '%s'\n", overlay.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 662 | PageManager::ChangeOverlay(overlay); |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 663 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 664 | return 0; |
| 665 | } |
| 666 | |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 667 | std::string gui_parse_text(std::string str) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 668 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 669 | // This function parses text for DataManager values encompassed by %value% in the XML |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 670 | // and string resources (%@resource_name%) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 671 | size_t pos = 0, next, end; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 672 | |
| 673 | while (1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 674 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 675 | next = str.find("{@", pos); |
| 676 | if (next == std::string::npos) |
| 677 | break; |
| 678 | |
| 679 | end = str.find('}', next + 1); |
| 680 | if (end == std::string::npos) |
| 681 | break; |
| 682 | |
| 683 | std::string var = str.substr(next + 2, (end - next) - 2); |
| 684 | str.erase(next, (end - next) + 1); |
| 685 | |
| 686 | size_t default_loc = var.find('=', 0); |
| 687 | std::string lookup; |
| 688 | if (default_loc == std::string::npos) { |
| 689 | str.insert(next, PageManager::GetResources()->FindString(var)); |
| 690 | } else { |
| 691 | lookup = var.substr(0, default_loc); |
| 692 | std::string default_string = var.substr(default_loc + 1, var.size() - default_loc - 1); |
| 693 | str.insert(next, PageManager::GetResources()->FindString(lookup, default_string)); |
| 694 | } |
| 695 | } |
| 696 | pos = 0; |
| 697 | while (1) |
| 698 | { |
| 699 | next = str.find('%', pos); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 700 | if (next == std::string::npos) |
| 701 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 702 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 703 | end = str.find('%', next + 1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 704 | if (end == std::string::npos) |
| 705 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 706 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 707 | // We have a block of data |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 708 | std::string var = str.substr(next + 1, (end - next) - 1); |
| 709 | str.erase(next, (end - next) + 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 710 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 711 | if (next + 1 == end) |
| 712 | str.insert(next, 1, '%'); |
| 713 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 714 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 715 | std::string value; |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 716 | if (var.size() > 0 && var[0] == '@') { |
| 717 | // this is a string resource ("%@string_name%") |
| 718 | value = PageManager::GetResources()->FindString(var.substr(1)); |
| 719 | str.insert(next, value); |
| 720 | } |
| 721 | else if (DataManager::GetValue(var, value) == 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 722 | str.insert(next, value); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 723 | } |
| 724 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 725 | pos = next + 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 729 | std::string gui_lookup(const std::string& resource_name, const std::string& default_value) { |
| 730 | return PageManager::GetResources()->FindString(resource_name, default_value); |
| 731 | } |
| 732 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 733 | extern "C" int gui_init(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 734 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 735 | gr_init(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 736 | |
that | 235c648 | 2016-01-24 21:59:00 +0100 | [diff] [blame] | 737 | // load and show splash screen |
| 738 | if (PageManager::LoadPackage("splash", TWRES "splash.xml", "splash")) { |
| 739 | LOGERR("Failed to load splash screen XML.\n"); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 740 | } |
that | 235c648 | 2016-01-24 21:59:00 +0100 | [diff] [blame] | 741 | else { |
| 742 | PageManager::SelectPackage("splash"); |
| 743 | PageManager::Render(); |
| 744 | flip(); |
| 745 | PageManager::ReleasePackage("splash"); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 746 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 747 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 748 | ev_init(); |
| 749 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 750 | } |
| 751 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 752 | extern "C" int gui_loadResources(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 753 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 754 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 755 | int check = 0; |
| 756 | DataManager::GetValue(TW_IS_ENCRYPTED, check); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 757 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 758 | if (check) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 759 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 760 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "decrypt")) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 761 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 762 | gui_err("base_pkg_err=Failed to load base packages."); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 763 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 765 | else |
| 766 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 767 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 768 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 769 | if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) |
| 770 | { |
| 771 | std::string theme_path; |
| 772 | |
| 773 | theme_path = DataManager::GetSettingsStoragePath(); |
| 774 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 775 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 776 | int retry_count = 5; |
| 777 | while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 778 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 779 | usleep(500000); |
| 780 | retry_count--; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 781 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 782 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 783 | if (!PartitionManager.Mount_Settings_Storage(true)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 784 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 785 | LOGINFO("Unable to mount %s during GUI startup.\n", theme_path.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 786 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 790 | theme_path += "/TWRP/theme/ui.zip"; |
| 791 | if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 792 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 793 | #endif // ifndef TW_OEM_BUILD |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 794 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 795 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 796 | gui_err("base_pkg_err=Failed to load base packages."); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 797 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 798 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 799 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 800 | } |
| 801 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 802 | #endif // ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 803 | // Set the default package |
| 804 | PageManager::SelectPackage("TWRP"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 805 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 806 | gGuiInitialized = 1; |
| 807 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 808 | |
| 809 | error: |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 810 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 811 | gGuiInitialized = 0; |
| 812 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 813 | } |
| 814 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 815 | extern "C" int gui_loadCustomResources(void) |
| 816 | { |
| 817 | #ifndef TW_OEM_BUILD |
| 818 | if (!PartitionManager.Mount_Settings_Storage(false)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 819 | LOGINFO("Unable to mount settings storage during GUI startup.\n"); |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 820 | return -1; |
| 821 | } |
| 822 | |
| 823 | std::string theme_path = DataManager::GetSettingsStoragePath(); |
| 824 | theme_path += "/TWRP/theme/ui.zip"; |
| 825 | // Check for a custom theme |
| 826 | if (TWFunc::Path_Exists(theme_path)) { |
| 827 | // There is a custom theme, try to load it |
| 828 | if (PageManager::ReloadPackage("TWRP", theme_path)) { |
| 829 | // Custom theme failed to load, try to load stock theme |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 830 | if (PageManager::ReloadPackage("TWRP", TWRES "ui.xml")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 831 | gui_err("base_pkg_err=Failed to load base packages."); |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 832 | goto error; |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | // Set the default package |
| 837 | PageManager::SelectPackage("TWRP"); |
| 838 | #endif |
| 839 | return 0; |
| 840 | |
| 841 | error: |
| 842 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
| 843 | gGuiInitialized = 0; |
| 844 | return -1; |
| 845 | } |
| 846 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 847 | extern "C" int gui_start(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 848 | { |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 849 | return gui_startPage("main", 1, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 850 | } |
| 851 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 852 | extern "C" int gui_startPage(const char *page_name, const int allow_commands, int stop_on_page_done) |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 853 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 854 | if (!gGuiInitialized) |
| 855 | return -1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 856 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 857 | // Set the default package |
| 858 | PageManager::SelectPackage("TWRP"); |
| 859 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 860 | input_handler.init(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 861 | #ifndef TW_OEM_BUILD |
| 862 | if (allow_commands) |
| 863 | { |
| 864 | if (ors_read_fd < 0) |
| 865 | setup_ors_command(); |
| 866 | } else { |
| 867 | if (ors_read_fd >= 0) { |
| 868 | close(ors_read_fd); |
| 869 | ors_read_fd = -1; |
| 870 | } |
| 871 | } |
| 872 | #endif |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 873 | return runPages(page_name, stop_on_page_done); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 876 | |
| 877 | extern "C" void set_scale_values(float w, float h) |
| 878 | { |
| 879 | scale_theme_w = w; |
| 880 | scale_theme_h = h; |
| 881 | } |
| 882 | |
| 883 | extern "C" int scale_theme_x(int initial_x) |
| 884 | { |
| 885 | if (scale_theme_w != 1) { |
that | ba75a0e | 2015-02-14 21:20:10 +0100 | [diff] [blame] | 886 | int scaled = (float)initial_x * scale_theme_w; |
| 887 | if (scaled == 0 && initial_x > 0) |
| 888 | return 1; |
| 889 | return scaled; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 890 | } |
| 891 | return initial_x; |
| 892 | } |
| 893 | |
| 894 | extern "C" int scale_theme_y(int initial_y) |
| 895 | { |
| 896 | if (scale_theme_h != 1) { |
that | ba75a0e | 2015-02-14 21:20:10 +0100 | [diff] [blame] | 897 | int scaled = (float)initial_y * scale_theme_h; |
| 898 | if (scaled == 0 && initial_y > 0) |
| 899 | return 1; |
| 900 | return scaled; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 901 | } |
| 902 | return initial_y; |
| 903 | } |
| 904 | |
| 905 | extern "C" int scale_theme_min(int initial_value) |
| 906 | { |
| 907 | if (scale_theme_w != 1 || scale_theme_h != 1) { |
| 908 | if (scale_theme_w < scale_theme_h) |
| 909 | return scale_theme_x(initial_value); |
| 910 | else |
| 911 | return scale_theme_y(initial_value); |
| 912 | } |
| 913 | return initial_value; |
| 914 | } |
| 915 | |
| 916 | extern "C" float get_scale_w() |
| 917 | { |
| 918 | return scale_theme_w; |
| 919 | } |
| 920 | |
| 921 | extern "C" float get_scale_h() |
| 922 | { |
| 923 | return scale_theme_h; |
| 924 | } |