Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2013 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 | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 18 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 19 | // pages.cpp - Source to manage GUI base objects |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 20 | |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/reboot.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/time.h> |
| 29 | #include <sys/mman.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/ioctl.h> |
| 32 | #include <time.h> |
| 33 | #include <unistd.h> |
| 34 | #include <stdlib.h> |
| 35 | |
| 36 | #include <string> |
| 37 | |
| 38 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 39 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 40 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | #include "rapidxml.hpp" |
| 44 | #include "objects.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 45 | #ifndef TW_NO_SCREEN_TIMEOUT |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 46 | #include "blanktimer.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 47 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
| 49 | extern int gGuiRunning; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 50 | #ifndef TW_NO_SCREEN_TIMEOUT |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 51 | extern blanktimer blankTimer; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 52 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
| 54 | std::map<std::string, PageSet*> PageManager::mPageSets; |
| 55 | PageSet* PageManager::mCurrentSet; |
| 56 | PageSet* PageManager::mBaseSet = NULL; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 57 | MouseCursor *PageManager::mMouseCursor = NULL; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 58 | HardwareKeyboard *PageManager::mHardwareKeyboard = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | // Helper routine to convert a string to a color declaration |
| 61 | int ConvertStrToColor(std::string str, COLOR* color) |
| 62 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 63 | // Set the default, solid black |
| 64 | memset(color, 0, sizeof(COLOR)); |
| 65 | color->alpha = 255; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 67 | // Translate variables |
| 68 | DataManager::GetValue(str, str); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 69 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 70 | // Look for some defaults |
| 71 | if (str == "black") return 0; |
| 72 | else if (str == "white") { color->red = color->green = color->blue = 255; return 0; } |
| 73 | else if (str == "red") { color->red = 255; return 0; } |
| 74 | else if (str == "green") { color->green = 255; return 0; } |
| 75 | else if (str == "blue") { color->blue = 255; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 77 | // At this point, we require an RGB(A) color |
| 78 | if (str[0] != '#') |
| 79 | return -1; |
| 80 | |
| 81 | str.erase(0, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 83 | int result; |
| 84 | if (str.size() >= 8) { |
| 85 | // We have alpha channel |
| 86 | string alpha = str.substr(6, 2); |
| 87 | result = strtol(alpha.c_str(), NULL, 16); |
| 88 | color->alpha = result & 0x000000FF; |
| 89 | str.resize(6); |
| 90 | result = strtol(str.c_str(), NULL, 16); |
| 91 | color->red = (result >> 16) & 0x000000FF; |
| 92 | color->green = (result >> 8) & 0x000000FF; |
| 93 | color->blue = result & 0x000000FF; |
| 94 | } else { |
| 95 | result = strtol(str.c_str(), NULL, 16); |
| 96 | color->red = (result >> 16) & 0x000000FF; |
| 97 | color->green = (result >> 8) & 0x000000FF; |
| 98 | color->blue = result & 0x000000FF; |
| 99 | } |
| 100 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Helper APIs |
| 104 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */) |
| 105 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | if (!node) |
| 107 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | std::string value; |
| 110 | if (node->first_attribute("x")) |
| 111 | { |
| 112 | value = node->first_attribute("x")->value(); |
| 113 | DataManager::GetValue(value, value); |
| 114 | *x = atol(value.c_str()); |
| 115 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 116 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 117 | if (node->first_attribute("y")) |
| 118 | { |
| 119 | value = node->first_attribute("y")->value(); |
| 120 | DataManager::GetValue(value, value); |
| 121 | *y = atol(value.c_str()); |
| 122 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 123 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 124 | if (w && node->first_attribute("w")) |
| 125 | { |
| 126 | value = node->first_attribute("w")->value(); |
| 127 | DataManager::GetValue(value, value); |
| 128 | *w = atol(value.c_str()); |
| 129 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 130 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 131 | if (h && node->first_attribute("h")) |
| 132 | { |
| 133 | value = node->first_attribute("h")->value(); |
| 134 | DataManager::GetValue(value, value); |
| 135 | *h = atol(value.c_str()); |
| 136 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 138 | if (placement && node->first_attribute("placement")) |
| 139 | { |
| 140 | value = node->first_attribute("placement")->value(); |
| 141 | DataManager::GetValue(value, value); |
| 142 | *placement = (RenderObject::Placement) atol(value.c_str()); |
| 143 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 144 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | int ActionObject::SetActionPos(int x, int y, int w, int h) |
| 149 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 150 | if (x < 0 || y < 0) |
| 151 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 153 | mActionX = x; |
| 154 | mActionY = y; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 155 | if (w || h) |
| 156 | { |
| 157 | mActionW = w; |
| 158 | mActionH = h; |
| 159 | } |
| 160 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 163 | Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates /* = NULL */) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 164 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | mTouchStart = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 166 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 167 | // We can memset the whole structure, because the alpha channel is ignored |
| 168 | memset(&mBackground, 0, sizeof(COLOR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 169 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 170 | // With NULL, we make a console-only display |
| 171 | if (!page) |
| 172 | { |
| 173 | mName = "console"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 174 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 175 | GUIConsole* element = new GUIConsole(NULL); |
| 176 | mRenders.push_back(element); |
| 177 | mActions.push_back(element); |
| 178 | return; |
| 179 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 180 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 181 | if (page->first_attribute("name")) |
| 182 | mName = page->first_attribute("name")->value(); |
| 183 | else |
| 184 | { |
| 185 | LOGERR("No page name attribute found!\n"); |
| 186 | return; |
| 187 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 188 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 189 | LOGINFO("Loading page %s\n", mName.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 190 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 191 | // This is a recursive routine for template handling |
| 192 | ProcessNode(page, templates); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 193 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 197 | Page::~Page() |
| 198 | { |
| 199 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 200 | delete *itr; |
| 201 | } |
| 202 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 203 | bool Page::ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates /* = NULL */, int depth /* = 0 */) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 204 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 205 | if (depth == 10) |
| 206 | { |
| 207 | LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); |
| 208 | return false; |
| 209 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 211 | // Let's retrieve the background value, if any |
| 212 | xml_node<>* bg = page->first_node("background"); |
| 213 | if (bg) |
| 214 | { |
| 215 | xml_attribute<>* attr = bg->first_attribute("color"); |
| 216 | if (attr) |
| 217 | { |
| 218 | std::string color = attr->value(); |
| 219 | ConvertStrToColor(color, &mBackground); |
| 220 | } |
| 221 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 223 | xml_node<>* child; |
| 224 | child = page->first_node("object"); |
| 225 | while (child) |
| 226 | { |
| 227 | if (!child->first_attribute("type")) |
| 228 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 229 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 230 | std::string type = child->first_attribute("type")->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 231 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 232 | if (type == "text") |
| 233 | { |
| 234 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 235 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 236 | mRenders.push_back(element); |
| 237 | mActions.push_back(element); |
| 238 | } |
| 239 | else if (type == "image") |
| 240 | { |
| 241 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 242 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 243 | mRenders.push_back(element); |
| 244 | } |
| 245 | else if (type == "fill") |
| 246 | { |
| 247 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 248 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 249 | mRenders.push_back(element); |
| 250 | } |
| 251 | else if (type == "action") |
| 252 | { |
| 253 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 254 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 255 | mActions.push_back(element); |
| 256 | } |
| 257 | else if (type == "console") |
| 258 | { |
| 259 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 260 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | mRenders.push_back(element); |
| 262 | mActions.push_back(element); |
| 263 | } |
| 264 | else if (type == "button") |
| 265 | { |
| 266 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 267 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 268 | mRenders.push_back(element); |
| 269 | mActions.push_back(element); |
| 270 | } |
| 271 | else if (type == "checkbox") |
| 272 | { |
| 273 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 274 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 275 | mRenders.push_back(element); |
| 276 | mActions.push_back(element); |
| 277 | } |
| 278 | else if (type == "fileselector") |
| 279 | { |
| 280 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 281 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 282 | mRenders.push_back(element); |
| 283 | mActions.push_back(element); |
| 284 | } |
| 285 | else if (type == "animation") |
| 286 | { |
| 287 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 288 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 289 | mRenders.push_back(element); |
| 290 | } |
| 291 | else if (type == "progressbar") |
| 292 | { |
| 293 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 294 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | mRenders.push_back(element); |
| 296 | mActions.push_back(element); |
| 297 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 298 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 299 | { |
| 300 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 301 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 302 | mRenders.push_back(element); |
| 303 | mActions.push_back(element); |
| 304 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 305 | else if (type == "slidervalue") |
| 306 | { |
| 307 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 308 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 309 | mRenders.push_back(element); |
| 310 | mActions.push_back(element); |
| 311 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 312 | else if (type == "listbox") |
| 313 | { |
| 314 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 315 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 316 | mRenders.push_back(element); |
| 317 | mActions.push_back(element); |
| 318 | } |
| 319 | else if (type == "keyboard") |
| 320 | { |
| 321 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 322 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 323 | mRenders.push_back(element); |
| 324 | mActions.push_back(element); |
| 325 | } |
| 326 | else if (type == "input") |
| 327 | { |
| 328 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 329 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 330 | mRenders.push_back(element); |
| 331 | mActions.push_back(element); |
| 332 | mInputs.push_back(element); |
| 333 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 334 | else if (type == "partitionlist") |
| 335 | { |
| 336 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 337 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 338 | mRenders.push_back(element); |
| 339 | mActions.push_back(element); |
| 340 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 341 | else if (type == "template") |
| 342 | { |
| 343 | if (!templates || !child->first_attribute("name")) |
| 344 | { |
| 345 | LOGERR("Invalid template request.\n"); |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | std::string name = child->first_attribute("name")->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 350 | xml_node<>* node; |
| 351 | bool node_found = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 352 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 353 | // We need to find the correct template |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 354 | for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) { |
| 355 | node = (*itr)->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 356 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 357 | while (node) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 358 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 359 | if (!node->first_attribute("name")) |
| 360 | continue; |
| 361 | |
| 362 | if (name == node->first_attribute("name")->value()) |
| 363 | { |
| 364 | if (!ProcessNode(node, templates, depth + 1)) |
| 365 | return false; |
| 366 | else { |
| 367 | node_found = true; |
| 368 | break; |
| 369 | } |
| 370 | } |
| 371 | if (node_found) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 372 | break; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 373 | node = node->next_sibling("template"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 374 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | LOGERR("Unknown object type.\n"); |
| 381 | } |
| 382 | child = child->next_sibling("object"); |
| 383 | } |
| 384 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int Page::Render(void) |
| 388 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | // Render background |
| 390 | gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); |
| 391 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 392 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 393 | // Render remaining objects |
| 394 | std::vector<RenderObject*>::iterator iter; |
| 395 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 396 | { |
| 397 | if ((*iter)->Render()) |
| 398 | LOGERR("A render request has failed.\n"); |
| 399 | } |
| 400 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | int Page::Update(void) |
| 404 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 405 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 406 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 407 | std::vector<RenderObject*>::iterator iter; |
| 408 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 409 | { |
| 410 | int ret = (*iter)->Update(); |
| 411 | if (ret < 0) |
| 412 | LOGERR("An update request has failed.\n"); |
| 413 | else if (ret > retCode) |
| 414 | retCode = ret; |
| 415 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 416 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 417 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 421 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 422 | // By default, return 1 to ignore further touches if nobody is listening |
| 423 | int ret = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 424 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 425 | // Don't try to handle a lack of handlers |
| 426 | if (mActions.size() == 0) |
| 427 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 428 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 429 | // We record mTouchStart so we can pass all the touch stream to the same handler |
| 430 | if (state == TOUCH_START) |
| 431 | { |
| 432 | std::vector<ActionObject*>::reverse_iterator iter; |
| 433 | // We work backwards, from top-most element to bottom-most element |
| 434 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 435 | { |
| 436 | if ((*iter)->IsInRegion(x, y)) |
| 437 | { |
| 438 | mTouchStart = (*iter); |
| 439 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 440 | if (ret >= 0) |
| 441 | break; |
| 442 | mTouchStart = NULL; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | else if (state == TOUCH_RELEASE && mTouchStart != NULL) |
| 447 | { |
| 448 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 449 | mTouchStart = NULL; |
| 450 | } |
| 451 | else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) |
| 452 | { |
| 453 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 454 | } |
| 455 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 458 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 459 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 460 | std::vector<ActionObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 461 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 462 | // Don't try to handle a lack of handlers |
| 463 | if (mActions.size() == 0) |
| 464 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 465 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 466 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 467 | // We work backwards, from top-most element to bottom-most element |
| 468 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 469 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 470 | ret = (*iter)->NotifyKey(key, down); |
| 471 | if (ret < 0) { |
| 472 | LOGERR("An action handler has returned an error\n"); |
| 473 | ret = 1; |
| 474 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 475 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 476 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | int Page::NotifyKeyboard(int key) |
| 480 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 481 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 482 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 483 | // Don't try to handle a lack of handlers |
| 484 | if (mInputs.size() == 0) |
| 485 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 486 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 487 | // We work backwards, from top-most element to bottom-most element |
| 488 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 489 | { |
| 490 | int ret = (*iter)->NotifyKeyboard(key); |
| 491 | if (ret == 0) |
| 492 | return 0; |
| 493 | else if (ret < 0) |
| 494 | LOGERR("A keyboard handler has returned an error"); |
| 495 | } |
| 496 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | int Page::SetKeyBoardFocus(int inFocus) |
| 500 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 501 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 502 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 503 | // Don't try to handle a lack of handlers |
| 504 | if (mInputs.size() == 0) |
| 505 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 506 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 507 | // We work backwards, from top-most element to bottom-most element |
| 508 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 509 | { |
| 510 | int ret = (*iter)->SetInputFocus(inFocus); |
| 511 | if (ret == 0) |
| 512 | return 0; |
| 513 | else if (ret < 0) |
| 514 | LOGERR("An input focus handler has returned an error"); |
| 515 | } |
| 516 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void Page::SetPageFocus(int inFocus) |
| 520 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 521 | // Render remaining objects |
| 522 | std::vector<RenderObject*>::iterator iter; |
| 523 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 524 | (*iter)->SetPageFocus(inFocus); |
| 525 | |
| 526 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 530 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 531 | std::vector<GUIObject*>::iterator iter; |
| 532 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 533 | { |
| 534 | if ((*iter)->NotifyVarChange(varName, value)) |
| 535 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 536 | } |
| 537 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | PageSet::PageSet(char* xmlFile) |
| 541 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 542 | mResources = NULL; |
| 543 | mCurrentPage = NULL; |
| 544 | mOverlayPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 546 | mXmlFile = xmlFile; |
| 547 | if (xmlFile) |
| 548 | mDoc.parse<0>(mXmlFile); |
| 549 | else |
| 550 | mCurrentPage = new Page(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | PageSet::~PageSet() |
| 554 | { |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 555 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 556 | delete *itr; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 557 | for (std::vector<xml_node<>*>::iterator itr2 = templates.begin(); itr2 != templates.end(); ++itr2) |
| 558 | delete *itr2; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 559 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 560 | delete mResources; |
| 561 | free(mXmlFile); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | int PageSet::Load(ZipArchive* package) |
| 565 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 566 | xml_node<>* parent; |
| 567 | xml_node<>* child; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 568 | xml_node<>* xmltemplate; |
| 569 | xml_node<>* blank_templates; |
| 570 | int pages_loaded = -1, ret; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 571 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 572 | parent = mDoc.first_node("recovery"); |
| 573 | if (!parent) |
| 574 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 575 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 576 | // Now, let's parse the XML |
| 577 | LOGINFO("Loading resources...\n"); |
| 578 | child = parent->first_node("resources"); |
| 579 | if (child) |
| 580 | mResources = new ResourceManager(child, package); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 581 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 582 | LOGINFO("Loading variables...\n"); |
| 583 | child = parent->first_node("variables"); |
| 584 | if (child) |
| 585 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 586 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 587 | LOGINFO("Loading mouse cursor...\n"); |
| 588 | child = parent->first_node("mousecursor"); |
| 589 | if(child) |
| 590 | PageManager::LoadCursorData(child); |
| 591 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 592 | LOGINFO("Loading pages...\n"); |
| 593 | // This may be NULL if no templates are present |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 594 | xmltemplate = parent->first_node("templates"); |
| 595 | if (xmltemplate) |
| 596 | templates.push_back(xmltemplate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 597 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 598 | child = parent->first_node("pages"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 599 | if (child) { |
| 600 | if (LoadPages(child)) { |
| 601 | LOGERR("PageSet::Load returning -1\n"); |
| 602 | return -1; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | return CheckInclude(package, &mDoc); |
| 607 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 608 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 609 | int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc) |
| 610 | { |
| 611 | xml_node<>* par; |
| 612 | xml_node<>* par2; |
| 613 | xml_node<>* chld; |
| 614 | xml_node<>* parent; |
| 615 | xml_node<>* child; |
| 616 | xml_node<>* xmltemplate; |
| 617 | long len; |
| 618 | char* xmlFile = NULL; |
| 619 | string filename; |
| 620 | xml_document<> doc; |
| 621 | |
| 622 | par = parentDoc->first_node("recovery"); |
| 623 | if (!par) { |
| 624 | par = parentDoc->first_node("install"); |
| 625 | } |
| 626 | if (!par) { |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | par2 = par->first_node("include"); |
| 631 | if (!par2) |
| 632 | return 0; |
| 633 | chld = par2->first_node("xmlfile"); |
| 634 | while (chld != NULL) { |
| 635 | xml_attribute<>* attr = chld->first_attribute("name"); |
| 636 | if (!attr) |
| 637 | break; |
| 638 | |
| 639 | LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str()); |
| 640 | if (!package) { |
| 641 | // We can try to load the XML directly... |
| 642 | filename = "/res/"; |
| 643 | filename += attr->value(); |
| 644 | struct stat st; |
| 645 | if(stat(filename.c_str(),&st) != 0) { |
| 646 | LOGERR("Unable to locate '%s'\n", filename.c_str()); |
| 647 | return -1; |
| 648 | } |
| 649 | |
| 650 | len = st.st_size; |
| 651 | xmlFile = (char*) malloc(len + 1); |
| 652 | if (!xmlFile) |
| 653 | return -1; |
| 654 | |
| 655 | int fd = open(filename.c_str(), O_RDONLY); |
| 656 | if (fd == -1) |
| 657 | return -1; |
| 658 | |
| 659 | read(fd, xmlFile, len); |
| 660 | close(fd); |
| 661 | } else { |
| 662 | filename += attr->value(); |
| 663 | const ZipEntry* ui_xml = mzFindZipEntry(package, filename.c_str()); |
| 664 | if (ui_xml == NULL) |
| 665 | { |
| 666 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | // Allocate the buffer for the file |
| 671 | len = mzGetZipEntryUncompLen(ui_xml); |
| 672 | xmlFile = (char*) malloc(len + 1); |
| 673 | if (!xmlFile) |
| 674 | return -1; |
| 675 | |
| 676 | if (!mzExtractZipEntryToBuffer(package, ui_xml, (unsigned char*) xmlFile)) |
| 677 | { |
| 678 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 679 | return -1; |
| 680 | } |
| 681 | } |
| 682 | doc.parse<0>(xmlFile); |
| 683 | |
| 684 | parent = doc.first_node("recovery"); |
| 685 | if (!parent) |
| 686 | parent = doc.first_node("install"); |
| 687 | |
| 688 | // Now, let's parse the XML |
| 689 | LOGINFO("Loading included resources...\n"); |
| 690 | child = parent->first_node("resources"); |
| 691 | if (child) |
| 692 | mResources->LoadResources(child, package); |
| 693 | |
| 694 | LOGINFO("Loading included variables...\n"); |
| 695 | child = parent->first_node("variables"); |
| 696 | if (child) |
| 697 | LoadVariables(child); |
| 698 | |
| 699 | LOGINFO("Loading mouse cursor...\n"); |
| 700 | child = parent->first_node("mousecursor"); |
| 701 | if(child) |
| 702 | PageManager::LoadCursorData(child); |
| 703 | |
| 704 | LOGINFO("Loading included pages...\n"); |
| 705 | // This may be NULL if no templates are present |
| 706 | xmltemplate = parent->first_node("templates"); |
| 707 | if (xmltemplate) |
| 708 | templates.push_back(xmltemplate); |
| 709 | |
| 710 | child = parent->first_node("pages"); |
| 711 | if (child) |
| 712 | if (LoadPages(child)) |
| 713 | return -1; |
| 714 | |
| 715 | if (CheckInclude(package, &doc)) |
| 716 | return -1; |
| 717 | |
| 718 | chld = chld->next_sibling("xmlfile"); |
| 719 | } |
| 720 | |
| 721 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | int PageSet::SetPage(std::string page) |
| 725 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 726 | Page* tmp = FindPage(page); |
| 727 | if (tmp) |
| 728 | { |
| 729 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 730 | mCurrentPage = tmp; |
| 731 | mCurrentPage->SetPageFocus(1); |
| 732 | mCurrentPage->NotifyVarChange("", ""); |
| 733 | return 0; |
| 734 | } |
| 735 | else |
| 736 | { |
| 737 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 738 | } |
| 739 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | int PageSet::SetOverlay(Page* page) |
| 743 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 744 | if (mOverlayPage) mOverlayPage->SetPageFocus(0); |
| 745 | mOverlayPage = page; |
| 746 | if (mOverlayPage) |
| 747 | { |
| 748 | mOverlayPage->SetPageFocus(1); |
| 749 | mOverlayPage->NotifyVarChange("", ""); |
| 750 | } |
| 751 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | Resource* PageSet::FindResource(std::string name) |
| 755 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 756 | return mResources ? mResources->FindResource(name) : NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | Page* PageSet::FindPage(std::string name) |
| 760 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 761 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 762 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 763 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 764 | { |
| 765 | if (name == (*iter)->GetName()) |
| 766 | return (*iter); |
| 767 | } |
| 768 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | int PageSet::LoadVariables(xml_node<>* vars) |
| 772 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 773 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 774 | xml_attribute<> *name, *value, *persist; |
| 775 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 776 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 777 | child = vars->first_node("variable"); |
| 778 | while (child) |
| 779 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 780 | name = child->first_attribute("name"); |
| 781 | value = child->first_attribute("value"); |
| 782 | persist = child->first_attribute("persist"); |
| 783 | if(name && value) |
| 784 | { |
| 785 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 786 | string temp = value->value(); |
| 787 | string valstr = gui_parse_text(temp); |
| 788 | |
| 789 | if (valstr.find("+") != string::npos) { |
| 790 | string val1str = valstr; |
| 791 | val1str = val1str.substr(0, val1str.find('+')); |
| 792 | string val2str = valstr; |
| 793 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 794 | int val1 = atoi(val1str.c_str()); |
| 795 | int val2 = atoi(val2str.c_str()); |
| 796 | int val = val1 + val2; |
| 797 | |
| 798 | DataManager::SetValue(name->value(), val, p); |
| 799 | } else if (valstr.find("-") != string::npos) { |
| 800 | string val1str = valstr; |
| 801 | val1str = val1str.substr(0, val1str.find('-')); |
| 802 | string val2str = valstr; |
| 803 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 804 | int val1 = atoi(val1str.c_str()); |
| 805 | int val2 = atoi(val2str.c_str()); |
| 806 | int val = val1 - val2; |
| 807 | |
| 808 | DataManager::SetValue(name->value(), val, p); |
| 809 | } else { |
| 810 | DataManager::SetValue(name->value(), valstr, p); |
| 811 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 812 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 813 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 814 | child = child->next_sibling("variable"); |
| 815 | } |
| 816 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 819 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 820 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 821 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 822 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 823 | if (!pages) |
| 824 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 825 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 826 | child = pages->first_node("page"); |
| 827 | while (child != NULL) |
| 828 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 829 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 830 | if (page->GetName().empty()) |
| 831 | { |
| 832 | LOGERR("Unable to process load page\n"); |
| 833 | delete page; |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | mPages.push_back(page); |
| 838 | } |
| 839 | child = child->next_sibling("page"); |
| 840 | } |
| 841 | if (mPages.size() > 0) |
| 842 | return 0; |
| 843 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | int PageSet::IsCurrentPage(Page* page) |
| 847 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 848 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | int PageSet::Render(void) |
| 852 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 853 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 854 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 855 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 856 | if (ret < 0) |
| 857 | return ret; |
| 858 | ret = (mOverlayPage ? mOverlayPage->Render() : -1); |
| 859 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | int PageSet::Update(void) |
| 863 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 864 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 865 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 866 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 867 | if (ret < 0 || ret > 1) |
| 868 | return ret; |
| 869 | ret = (mOverlayPage ? mOverlayPage->Update() : -1); |
| 870 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 874 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 875 | if (mOverlayPage) |
| 876 | return (mOverlayPage->NotifyTouch(state, x, y)); |
| 877 | |
| 878 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 879 | } |
| 880 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 881 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 882 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 883 | if (mOverlayPage) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 884 | return (mOverlayPage->NotifyKey(key, down)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 885 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 886 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | int PageSet::NotifyKeyboard(int key) |
| 890 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 891 | if (mOverlayPage) |
| 892 | return (mOverlayPage->NotifyKeyboard(key)); |
| 893 | |
| 894 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 898 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 899 | if (mOverlayPage) |
| 900 | return (mOverlayPage->SetKeyBoardFocus(inFocus)); |
| 901 | |
| 902 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 906 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 907 | if (mOverlayPage) |
| 908 | mOverlayPage->NotifyVarChange(varName, value); |
| 909 | |
| 910 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 914 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 915 | int fd; |
| 916 | ZipArchive zip, *pZip = NULL; |
| 917 | long len; |
| 918 | char* xmlFile = NULL; |
| 919 | PageSet* pageSet = NULL; |
| 920 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 921 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 922 | // Open the XML file |
| 923 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
| 924 | if (mzOpenZipArchive(package.c_str(), &zip)) |
| 925 | { |
| 926 | // We can try to load the XML directly... |
| 927 | struct stat st; |
| 928 | if(stat(package.c_str(),&st) != 0) |
| 929 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 930 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 931 | len = st.st_size; |
| 932 | xmlFile = (char*) malloc(len + 1); |
| 933 | if (!xmlFile) |
| 934 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 935 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 936 | fd = open(package.c_str(), O_RDONLY); |
| 937 | if (fd == -1) |
| 938 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 939 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 940 | read(fd, xmlFile, len); |
| 941 | close(fd); |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | pZip = &zip; |
| 946 | const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); |
| 947 | if (ui_xml == NULL) |
| 948 | { |
| 949 | LOGERR("Unable to locate ui.xml in zip file\n"); |
| 950 | goto error; |
| 951 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 952 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 953 | // Allocate the buffer for the file |
| 954 | len = mzGetZipEntryUncompLen(ui_xml); |
| 955 | xmlFile = (char*) malloc(len + 1); |
| 956 | if (!xmlFile) |
| 957 | goto error; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 958 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 959 | if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) |
| 960 | { |
| 961 | LOGERR("Unable to extract ui.xml\n"); |
| 962 | goto error; |
| 963 | } |
| 964 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 965 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 966 | // NULL-terminate the string |
| 967 | xmlFile[len] = 0x00; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 968 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 969 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 970 | pageSet = mCurrentSet; |
| 971 | mCurrentSet = new PageSet(xmlFile); |
| 972 | |
| 973 | ret = mCurrentSet->Load(pZip); |
| 974 | if (ret == 0) |
| 975 | { |
| 976 | mCurrentSet->SetPage(startpage); |
| 977 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | LOGERR("Package %s failed to load.\n", name.c_str()); |
| 982 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 983 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 984 | // The first successful package we loaded is the base |
| 985 | if (mBaseSet == NULL) |
| 986 | mBaseSet = mCurrentSet; |
| 987 | |
| 988 | mCurrentSet = pageSet; |
| 989 | |
| 990 | if (pZip) |
| 991 | mzCloseZipArchive(pZip); |
| 992 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 993 | |
| 994 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 995 | LOGERR("An internal error has occurred.\n"); |
| 996 | if (pZip) |
| 997 | mzCloseZipArchive(pZip); |
| 998 | if (xmlFile) |
| 999 | free(xmlFile); |
| 1000 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | PageSet* PageManager::FindPackage(std::string name) |
| 1004 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1005 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1006 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1007 | iter = mPageSets.find(name); |
| 1008 | if (iter != mPageSets.end()) |
| 1009 | return (*iter).second; |
| 1010 | |
| 1011 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1012 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | PageSet* PageManager::SelectPackage(std::string name) |
| 1016 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1017 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1018 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1019 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1020 | tmp = FindPackage(name); |
| 1021 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1022 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1023 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1024 | mCurrentSet->NotifyVarChange("", ""); |
| 1025 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1026 | else |
| 1027 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1028 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1029 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1033 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1034 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1035 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1036 | iter = mPageSets.find(name); |
| 1037 | if (iter == mPageSets.end()) |
| 1038 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1039 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1040 | if(mMouseCursor) |
| 1041 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1042 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1043 | PageSet* set = (*iter).second; |
| 1044 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1045 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1046 | if (LoadPackage(name, package, "main") != 0) |
| 1047 | { |
| 1048 | LOGERR("Failed to load package.\n"); |
| 1049 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1050 | return -1; |
| 1051 | } |
| 1052 | if (mCurrentSet == set) |
| 1053 | SelectPackage(name); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 1054 | if (mBaseSet == set) |
| 1055 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1056 | delete set; |
| 1057 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | void PageManager::ReleasePackage(std::string name) |
| 1061 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1062 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1063 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1064 | iter = mPageSets.find(name); |
| 1065 | if (iter == mPageSets.end()) |
| 1066 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1067 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1068 | PageSet* set = (*iter).second; |
| 1069 | mPageSets.erase(iter); |
| 1070 | delete set; |
| 1071 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | int PageManager::ChangePage(std::string name) |
| 1075 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1076 | DataManager::SetValue("tw_operation_state", 0); |
| 1077 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1078 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | int PageManager::ChangeOverlay(std::string name) |
| 1082 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1083 | if (name.empty()) |
| 1084 | return mCurrentSet->SetOverlay(NULL); |
| 1085 | else |
| 1086 | { |
| 1087 | Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; |
| 1088 | return mCurrentSet->SetOverlay(page); |
| 1089 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | Resource* PageManager::FindResource(std::string name) |
| 1093 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1094 | return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | Resource* PageManager::FindResource(std::string package, std::string name) |
| 1098 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1099 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1100 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1101 | tmp = FindPackage(name); |
| 1102 | return (tmp ? tmp->FindResource(name) : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | int PageManager::SwitchToConsole(void) |
| 1106 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1107 | PageSet* console = new PageSet(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1109 | mCurrentSet = console; |
| 1110 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 1113 | int PageManager::EndConsole(void) |
| 1114 | { |
| 1115 | if (mCurrentSet && mBaseSet) { |
| 1116 | delete mCurrentSet; |
| 1117 | mCurrentSet = mBaseSet; |
| 1118 | return 0; |
| 1119 | } |
| 1120 | return -1; |
| 1121 | } |
| 1122 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1123 | int PageManager::IsCurrentPage(Page* page) |
| 1124 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1125 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | int PageManager::Render(void) |
| 1129 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1130 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 1131 | if(mMouseCursor) |
| 1132 | mMouseCursor->Render(); |
| 1133 | return res; |
| 1134 | } |
| 1135 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1136 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1137 | { |
| 1138 | if(!mHardwareKeyboard) |
| 1139 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1140 | return mHardwareKeyboard; |
| 1141 | } |
| 1142 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1143 | MouseCursor *PageManager::GetMouseCursor() |
| 1144 | { |
| 1145 | if(!mMouseCursor) |
| 1146 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1147 | return mMouseCursor; |
| 1148 | } |
| 1149 | |
| 1150 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1151 | { |
| 1152 | if(!mMouseCursor) |
| 1153 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1154 | |
| 1155 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | int PageManager::Update(void) |
| 1159 | { |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 1160 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1161 | if(blankTimer.IsScreenOff()) |
| 1162 | return 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 1163 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1164 | |
| 1165 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1166 | |
| 1167 | if(mMouseCursor) |
| 1168 | { |
| 1169 | int c_res = mMouseCursor->Update(); |
| 1170 | if(c_res > res) |
| 1171 | res = c_res; |
| 1172 | } |
| 1173 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1177 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1178 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1181 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1182 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1183 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | int PageManager::NotifyKeyboard(int key) |
| 1187 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1188 | return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1192 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1193 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1197 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1198 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1202 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1203 | if (!gGuiRunning) |
| 1204 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1205 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1206 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1207 | } |