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> |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 35 | #include "../twrp-functions.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
| 37 | #include <string> |
| 38 | |
| 39 | extern "C" { |
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 "../minuitwrp/minui.h" |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 42 | #include "../minzip/SysUtil.h" |
| 43 | #include "../minzip/Zip.h" |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 44 | #include "gui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | #include "rapidxml.hpp" |
| 48 | #include "objects.hpp" |
gordon1337 | 0d9133d | 2013-06-08 14:17:07 +0200 | [diff] [blame] | 49 | #include "blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 50 | |
| 51 | extern int gGuiRunning; |
| 52 | |
| 53 | std::map<std::string, PageSet*> PageManager::mPageSets; |
| 54 | PageSet* PageManager::mCurrentSet; |
| 55 | PageSet* PageManager::mBaseSet = NULL; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 56 | MouseCursor *PageManager::mMouseCursor = NULL; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 57 | HardwareKeyboard *PageManager::mHardwareKeyboard = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 58 | |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 59 | int tw_x_offset = 0; |
| 60 | int tw_y_offset = 0; |
| 61 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 62 | // Helper routine to convert a string to a color declaration |
| 63 | int ConvertStrToColor(std::string str, COLOR* color) |
| 64 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 65 | // Set the default, solid black |
| 66 | memset(color, 0, sizeof(COLOR)); |
| 67 | color->alpha = 255; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 69 | // Translate variables |
| 70 | DataManager::GetValue(str, str); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 71 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 72 | // Look for some defaults |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 73 | if (str == "black") return 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 74 | else if (str == "white") { color->red = color->green = color->blue = 255; return 0; } |
| 75 | else if (str == "red") { color->red = 255; return 0; } |
| 76 | else if (str == "green") { color->green = 255; return 0; } |
| 77 | else if (str == "blue") { color->blue = 255; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 78 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | // At this point, we require an RGB(A) color |
| 80 | if (str[0] != '#') |
| 81 | return -1; |
| 82 | |
| 83 | str.erase(0, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 84 | |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 85 | int result; |
| 86 | if (str.size() >= 8) { |
| 87 | // We have alpha channel |
| 88 | string alpha = str.substr(6, 2); |
| 89 | result = strtol(alpha.c_str(), NULL, 16); |
| 90 | color->alpha = result & 0x000000FF; |
| 91 | str.resize(6); |
| 92 | result = strtol(str.c_str(), NULL, 16); |
| 93 | color->red = (result >> 16) & 0x000000FF; |
| 94 | color->green = (result >> 8) & 0x000000FF; |
| 95 | color->blue = result & 0x000000FF; |
| 96 | } else { |
| 97 | result = strtol(str.c_str(), NULL, 16); |
| 98 | color->red = (result >> 16) & 0x000000FF; |
| 99 | color->green = (result >> 8) & 0x000000FF; |
| 100 | color->blue = result & 0x000000FF; |
| 101 | } |
| 102 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Helper APIs |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 106 | xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth /* = 0 */) |
| 107 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 108 | if (!parent) |
| 109 | return NULL; |
| 110 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 111 | xml_node<>* child = parent->first_node(nodename); |
| 112 | if (child) |
| 113 | return child; |
| 114 | |
| 115 | if (depth == 10) { |
| 116 | LOGERR("Too many style loops detected.\n"); |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | xml_node<>* style = parent->first_node("style"); |
| 121 | if (style) { |
| 122 | while (style) { |
| 123 | if (!style->first_attribute("name")) { |
| 124 | LOGERR("No name given for style.\n"); |
| 125 | continue; |
| 126 | } else { |
| 127 | std::string name = style->first_attribute("name")->value(); |
| 128 | xml_node<>* node = PageManager::FindStyle(name); |
| 129 | |
| 130 | if (node) { |
| 131 | // We found the style that was named |
| 132 | xml_node<>* stylenode = FindNode(node, nodename, depth + 1); |
| 133 | if (stylenode) |
| 134 | return stylenode; |
| 135 | } |
| 136 | } |
| 137 | style = style->next_sibling("style"); |
| 138 | } |
| 139 | } else { |
that | 54e9c83 | 2015-11-04 21:46:01 +0100 | [diff] [blame] | 140 | // Search for stylename in the parent node <object type="foo" style="foo2"> |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 141 | xml_attribute<>* attr = parent->first_attribute("style"); |
| 142 | // If no style is found anywhere else and the node wasn't found in the object itself |
| 143 | // as a special case we will search for a style that uses the same style name as the |
| 144 | // object type, so <object type="button"> would search for a style named "button" |
| 145 | if (!attr) |
| 146 | attr = parent->first_attribute("type"); |
that | 54e9c83 | 2015-11-04 21:46:01 +0100 | [diff] [blame] | 147 | // if there's no attribute type, the object type must be the element name |
| 148 | std::string stylename = attr ? attr->value() : parent->name(); |
| 149 | xml_node<>* node = PageManager::FindStyle(stylename); |
| 150 | if (node) { |
| 151 | xml_node<>* stylenode = FindNode(node, nodename, depth + 1); |
| 152 | if (stylenode) |
| 153 | return stylenode; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | return NULL; |
| 157 | } |
| 158 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 159 | std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue) |
| 160 | { |
| 161 | if (!element) |
| 162 | return defaultvalue; |
| 163 | |
| 164 | xml_attribute<>* attr = element->first_attribute(attrname); |
| 165 | return attr ? attr->value() : defaultvalue; |
| 166 | } |
| 167 | |
| 168 | int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue) |
| 169 | { |
| 170 | string value = LoadAttrString(element, attrname); |
| 171 | // resolve variables |
| 172 | DataManager::GetValue(value, value); |
| 173 | return value.empty() ? defaultvalue : atoi(value.c_str()); |
| 174 | } |
| 175 | |
| 176 | int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue) |
| 177 | { |
| 178 | return scale_theme_x(LoadAttrInt(element, attrname, defaultvalue)); |
| 179 | } |
| 180 | |
| 181 | int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue) |
| 182 | { |
| 183 | return scale_theme_y(LoadAttrInt(element, attrname, defaultvalue)); |
| 184 | } |
| 185 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 186 | COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 187 | { |
| 188 | string value = LoadAttrString(element, attrname); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 189 | *found_color = !value.empty(); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 190 | // resolve variables |
| 191 | DataManager::GetValue(value, value); |
| 192 | COLOR ret = defaultvalue; |
| 193 | if (ConvertStrToColor(value, &ret) == 0) |
| 194 | return ret; |
| 195 | else |
| 196 | return defaultvalue; |
| 197 | } |
| 198 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 199 | COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue) |
| 200 | { |
| 201 | bool found_color = false; |
| 202 | return LoadAttrColor(element, attrname, &found_color, defaultvalue); |
| 203 | } |
| 204 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 205 | FontResource* LoadAttrFont(xml_node<>* element, const char* attrname) |
| 206 | { |
| 207 | std::string name = LoadAttrString(element, attrname, ""); |
| 208 | if (name.empty()) |
| 209 | return NULL; |
| 210 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 211 | return PageManager::GetResources()->FindFont(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname) |
| 215 | { |
| 216 | std::string name = LoadAttrString(element, attrname, ""); |
| 217 | if (name.empty()) |
| 218 | return NULL; |
| 219 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 220 | return PageManager::GetResources()->FindImage(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname) |
| 224 | { |
| 225 | std::string name = LoadAttrString(element, attrname, ""); |
| 226 | if (name.empty()) |
| 227 | return NULL; |
| 228 | else |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 229 | return PageManager::GetResources()->FindAnimation(name); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 232 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, Placement* placement /* = NULL */) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 234 | if (!node) |
| 235 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 236 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | if (node->first_attribute("x")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 238 | *x = LoadAttrIntScaleX(node, "x") + tw_x_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 239 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 240 | if (node->first_attribute("y")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 241 | *y = LoadAttrIntScaleY(node, "y") + tw_y_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 242 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 243 | if (w && node->first_attribute("w")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 244 | *w = LoadAttrIntScaleX(node, "w"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 245 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 246 | if (h && node->first_attribute("h")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 247 | *h = LoadAttrIntScaleY(node, "h"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 248 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 249 | if (placement && node->first_attribute("placement")) |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 250 | *placement = (Placement) LoadAttrInt(node, "placement"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | int ActionObject::SetActionPos(int x, int y, int w, int h) |
| 256 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 257 | if (x < 0 || y < 0) |
| 258 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 259 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 260 | mActionX = x; |
| 261 | mActionY = y; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 262 | if (w || h) |
| 263 | { |
| 264 | mActionW = w; |
| 265 | mActionH = h; |
| 266 | } |
| 267 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 268 | } |
| 269 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 270 | Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 272 | mTouchStart = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 273 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 274 | // We can memset the whole structure, because the alpha channel is ignored |
| 275 | memset(&mBackground, 0, sizeof(COLOR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 276 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 277 | // With NULL, we make a console-only display |
| 278 | if (!page) |
| 279 | { |
| 280 | mName = "console"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 281 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 282 | GUIConsole* element = new GUIConsole(NULL); |
| 283 | mRenders.push_back(element); |
| 284 | mActions.push_back(element); |
| 285 | return; |
| 286 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 287 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 288 | if (page->first_attribute("name")) |
| 289 | mName = page->first_attribute("name")->value(); |
| 290 | else |
| 291 | { |
| 292 | LOGERR("No page name attribute found!\n"); |
| 293 | return; |
| 294 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 295 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 296 | LOGINFO("Loading page %s\n", mName.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 297 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 298 | // This is a recursive routine for template handling |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 299 | ProcessNode(page, templates, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 302 | Page::~Page() |
| 303 | { |
| 304 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 305 | delete *itr; |
| 306 | } |
| 307 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 308 | bool Page::ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 309 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 310 | if (depth == 10) |
| 311 | { |
| 312 | LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); |
| 313 | return false; |
| 314 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 315 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 316 | for (xml_node<>* child = page->first_node(); child; child = child->next_sibling()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 317 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 318 | std::string type = child->name(); |
| 319 | |
| 320 | if (type == "background") { |
| 321 | mBackground = LoadAttrColor(child, "color", COLOR(0,0,0,0)); |
| 322 | continue; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 323 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 324 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 325 | if (type == "object") { |
| 326 | // legacy format : <object type="..."> |
| 327 | xml_attribute<>* attr = child->first_attribute("type"); |
| 328 | type = attr ? attr->value() : "*unspecified*"; |
| 329 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 330 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 331 | if (type == "text") |
| 332 | { |
| 333 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 334 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 335 | mRenders.push_back(element); |
| 336 | mActions.push_back(element); |
| 337 | } |
| 338 | else if (type == "image") |
| 339 | { |
| 340 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 341 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 342 | mRenders.push_back(element); |
| 343 | } |
| 344 | else if (type == "fill") |
| 345 | { |
| 346 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 347 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 348 | mRenders.push_back(element); |
| 349 | } |
| 350 | else if (type == "action") |
| 351 | { |
| 352 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 353 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 354 | mActions.push_back(element); |
| 355 | } |
| 356 | else if (type == "console") |
| 357 | { |
| 358 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 359 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 360 | mRenders.push_back(element); |
| 361 | mActions.push_back(element); |
| 362 | } |
| 363 | else if (type == "button") |
| 364 | { |
| 365 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 366 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | mRenders.push_back(element); |
| 368 | mActions.push_back(element); |
| 369 | } |
| 370 | else if (type == "checkbox") |
| 371 | { |
| 372 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 373 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 374 | mRenders.push_back(element); |
| 375 | mActions.push_back(element); |
| 376 | } |
| 377 | else if (type == "fileselector") |
| 378 | { |
| 379 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 380 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 381 | mRenders.push_back(element); |
| 382 | mActions.push_back(element); |
| 383 | } |
| 384 | else if (type == "animation") |
| 385 | { |
| 386 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 387 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 388 | mRenders.push_back(element); |
| 389 | } |
| 390 | else if (type == "progressbar") |
| 391 | { |
| 392 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 393 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 394 | mRenders.push_back(element); |
| 395 | mActions.push_back(element); |
| 396 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 397 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 398 | { |
| 399 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 400 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 401 | mRenders.push_back(element); |
| 402 | mActions.push_back(element); |
| 403 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 404 | else if (type == "slidervalue") |
| 405 | { |
| 406 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 407 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 408 | mRenders.push_back(element); |
| 409 | mActions.push_back(element); |
| 410 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 411 | else if (type == "listbox") |
| 412 | { |
| 413 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 414 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 415 | mRenders.push_back(element); |
| 416 | mActions.push_back(element); |
| 417 | } |
| 418 | else if (type == "keyboard") |
| 419 | { |
| 420 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 421 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 422 | mRenders.push_back(element); |
| 423 | mActions.push_back(element); |
| 424 | } |
| 425 | else if (type == "input") |
| 426 | { |
| 427 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 428 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 429 | mRenders.push_back(element); |
| 430 | mActions.push_back(element); |
| 431 | mInputs.push_back(element); |
| 432 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 433 | else if (type == "partitionlist") |
| 434 | { |
| 435 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 436 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 437 | mRenders.push_back(element); |
| 438 | mActions.push_back(element); |
| 439 | } |
Vojtech Bocek | 7e11ac5 | 2015-03-05 23:21:49 +0100 | [diff] [blame] | 440 | else if (type == "patternpassword") |
| 441 | { |
| 442 | GUIPatternPassword* element = new GUIPatternPassword(child); |
| 443 | mObjects.push_back(element); |
| 444 | mRenders.push_back(element); |
| 445 | mActions.push_back(element); |
| 446 | } |
Ethan Yonker | 44925ad | 2015-07-22 12:33:59 -0500 | [diff] [blame] | 447 | else if (type == "textbox") |
| 448 | { |
| 449 | GUITextBox* element = new GUITextBox(child); |
| 450 | mObjects.push_back(element); |
| 451 | mRenders.push_back(element); |
| 452 | mActions.push_back(element); |
| 453 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 454 | else if (type == "template") |
| 455 | { |
| 456 | if (!templates || !child->first_attribute("name")) |
| 457 | { |
| 458 | LOGERR("Invalid template request.\n"); |
| 459 | } |
| 460 | else |
| 461 | { |
| 462 | std::string name = child->first_attribute("name")->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 463 | xml_node<>* node; |
| 464 | bool node_found = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 465 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 466 | // We need to find the correct template |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 467 | for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) { |
| 468 | node = (*itr)->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 469 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 470 | while (node) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 471 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 472 | if (!node->first_attribute("name")) |
| 473 | continue; |
| 474 | |
| 475 | if (name == node->first_attribute("name")->value()) |
| 476 | { |
| 477 | if (!ProcessNode(node, templates, depth + 1)) |
| 478 | return false; |
| 479 | else { |
| 480 | node_found = true; |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | if (node_found) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 485 | break; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 486 | node = node->next_sibling("template"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 487 | } |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 488 | // [check] why is there no if (node_found) here too? |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | else |
| 493 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 494 | LOGERR("Unknown object type: %s.\n", type.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 495 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 496 | } |
| 497 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | int Page::Render(void) |
| 501 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 502 | // Render background |
| 503 | gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); |
| 504 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 505 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 506 | // Render remaining objects |
| 507 | std::vector<RenderObject*>::iterator iter; |
| 508 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 509 | { |
| 510 | if ((*iter)->Render()) |
| 511 | LOGERR("A render request has failed.\n"); |
| 512 | } |
| 513 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | int Page::Update(void) |
| 517 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 518 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 519 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 520 | std::vector<RenderObject*>::iterator iter; |
| 521 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 522 | { |
| 523 | int ret = (*iter)->Update(); |
| 524 | if (ret < 0) |
| 525 | LOGERR("An update request has failed.\n"); |
| 526 | else if (ret > retCode) |
| 527 | retCode = ret; |
| 528 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 529 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 530 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 534 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 535 | // By default, return 1 to ignore further touches if nobody is listening |
| 536 | int ret = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 537 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 538 | // Don't try to handle a lack of handlers |
| 539 | if (mActions.size() == 0) |
| 540 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 541 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 542 | // We record mTouchStart so we can pass all the touch stream to the same handler |
| 543 | if (state == TOUCH_START) |
| 544 | { |
| 545 | std::vector<ActionObject*>::reverse_iterator iter; |
| 546 | // We work backwards, from top-most element to bottom-most element |
| 547 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 548 | { |
| 549 | if ((*iter)->IsInRegion(x, y)) |
| 550 | { |
| 551 | mTouchStart = (*iter); |
| 552 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 553 | if (ret >= 0) |
| 554 | break; |
| 555 | mTouchStart = NULL; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | else if (state == TOUCH_RELEASE && mTouchStart != NULL) |
| 560 | { |
| 561 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 562 | mTouchStart = NULL; |
| 563 | } |
| 564 | else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) |
| 565 | { |
| 566 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 567 | } |
| 568 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 571 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 572 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 573 | std::vector<ActionObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 574 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 575 | // Don't try to handle a lack of handlers |
| 576 | if (mActions.size() == 0) |
| 577 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 578 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 579 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 580 | // We work backwards, from top-most element to bottom-most element |
| 581 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 582 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 583 | ret = (*iter)->NotifyKey(key, down); |
| 584 | if (ret < 0) { |
| 585 | LOGERR("An action handler has returned an error\n"); |
| 586 | ret = 1; |
| 587 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 588 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 589 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | int Page::NotifyKeyboard(int key) |
| 593 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 594 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 595 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 596 | // Don't try to handle a lack of handlers |
| 597 | if (mInputs.size() == 0) |
| 598 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 599 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 600 | // We work backwards, from top-most element to bottom-most element |
| 601 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 602 | { |
| 603 | int ret = (*iter)->NotifyKeyboard(key); |
| 604 | if (ret == 0) |
| 605 | return 0; |
| 606 | else if (ret < 0) |
| 607 | LOGERR("A keyboard handler has returned an error"); |
| 608 | } |
| 609 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | int Page::SetKeyBoardFocus(int inFocus) |
| 613 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 614 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 615 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 616 | // Don't try to handle a lack of handlers |
| 617 | if (mInputs.size() == 0) |
| 618 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 619 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 620 | // We work backwards, from top-most element to bottom-most element |
| 621 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 622 | { |
| 623 | int ret = (*iter)->SetInputFocus(inFocus); |
| 624 | if (ret == 0) |
| 625 | return 0; |
| 626 | else if (ret < 0) |
| 627 | LOGERR("An input focus handler has returned an error"); |
| 628 | } |
| 629 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void Page::SetPageFocus(int inFocus) |
| 633 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 634 | // Render remaining objects |
| 635 | std::vector<RenderObject*>::iterator iter; |
| 636 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 637 | (*iter)->SetPageFocus(inFocus); |
| 638 | |
| 639 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 643 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 644 | std::vector<GUIObject*>::iterator iter; |
| 645 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 646 | { |
| 647 | if ((*iter)->NotifyVarChange(varName, value)) |
| 648 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 649 | } |
| 650 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | PageSet::PageSet(char* xmlFile) |
| 654 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 655 | mResources = new ResourceManager; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 656 | mCurrentPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 657 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 658 | mXmlFile = xmlFile; |
| 659 | if (xmlFile) |
| 660 | mDoc.parse<0>(mXmlFile); |
| 661 | else |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 662 | mCurrentPage = new Page(NULL, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | PageSet::~PageSet() |
| 666 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 667 | mOverlays.clear(); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 668 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 669 | delete *itr; |
| 670 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 671 | delete mResources; |
| 672 | free(mXmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 673 | |
| 674 | mDoc.clear(); |
| 675 | |
| 676 | for (std::vector<xml_document<>*>::iterator itr = mIncludedDocs.begin(); itr != mIncludedDocs.end(); ++itr) { |
| 677 | (*itr)->clear(); |
| 678 | delete *itr; |
| 679 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | int PageSet::Load(ZipArchive* package) |
| 683 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 684 | xml_node<>* parent; |
| 685 | xml_node<>* child; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 686 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 687 | xml_node<>* xmlstyle; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 688 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 689 | parent = mDoc.first_node("recovery"); |
| 690 | if (!parent) |
| 691 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 692 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 693 | set_scale_values(1, 1); // Reset any previous scaling values |
| 694 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 695 | // Now, let's parse the XML |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 696 | LOGINFO("Checking resolution...\n"); |
| 697 | child = parent->first_node("details"); |
| 698 | if (child) { |
| 699 | xml_node<>* resolution = child->first_node("resolution"); |
| 700 | if (resolution) { |
| 701 | xml_attribute<>* width_attr = resolution->first_attribute("width"); |
| 702 | xml_attribute<>* height_attr = resolution->first_attribute("height"); |
| 703 | xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling"); |
| 704 | if (width_attr && height_attr && !noscale_attr) { |
| 705 | int width = atoi(width_attr->value()); |
| 706 | int height = atoi(height_attr->value()); |
| 707 | int offx = 0, offy = 0; |
| 708 | #ifdef TW_ROUND_SCREEN |
| 709 | xml_node<>* roundscreen = child->first_node("roundscreen"); |
| 710 | if (roundscreen) { |
| 711 | LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n"); |
| 712 | xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x"); |
| 713 | xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y"); |
| 714 | if (offx_attr) { |
| 715 | offx = atoi(offx_attr->value()); |
| 716 | } |
| 717 | if (offy_attr) { |
| 718 | offy = atoi(offy_attr->value()); |
| 719 | } |
| 720 | } |
| 721 | #endif |
| 722 | if (width != 0 && height != 0) { |
| 723 | float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width; |
| 724 | float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height; |
| 725 | #ifdef TW_ROUND_SCREEN |
| 726 | float scale_off_w = (float)gr_fb_width() / (float)width; |
| 727 | float scale_off_h = (float)gr_fb_height() / (float)height; |
| 728 | tw_x_offset = offx * scale_off_w; |
| 729 | tw_y_offset = offy * scale_off_h; |
| 730 | #endif |
| 731 | if (scale_w != 1 || scale_h != 1) { |
| 732 | LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset); |
| 733 | set_scale_values(scale_w, scale_h); |
| 734 | } |
| 735 | } |
| 736 | } else { |
| 737 | LOGINFO("XML does not contain width and height, no scaling will be applied\n"); |
| 738 | } |
| 739 | } else { |
| 740 | LOGINFO("XML contains no resolution tag, no scaling will be applied.\n"); |
| 741 | } |
| 742 | } else { |
| 743 | LOGINFO("XML contains no details tag, no scaling will be applied.\n"); |
| 744 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 745 | LOGINFO("Loading resources...\n"); |
| 746 | child = parent->first_node("resources"); |
| 747 | if (child) |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 748 | mResources->LoadResources(child, package); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 749 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 750 | LOGINFO("Loading variables...\n"); |
| 751 | child = parent->first_node("variables"); |
| 752 | if (child) |
| 753 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 754 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 755 | LOGINFO("Loading mouse cursor...\n"); |
| 756 | child = parent->first_node("mousecursor"); |
| 757 | if(child) |
| 758 | PageManager::LoadCursorData(child); |
| 759 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 760 | LOGINFO("Loading pages...\n"); |
| 761 | // This may be NULL if no templates are present |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 762 | xmltemplate = parent->first_node("templates"); |
| 763 | if (xmltemplate) |
| 764 | templates.push_back(xmltemplate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 765 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 766 | // Load styles if present |
| 767 | xmlstyle = parent->first_node("styles"); |
| 768 | if (xmlstyle) |
| 769 | styles.push_back(xmlstyle); |
| 770 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 771 | child = parent->first_node("pages"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 772 | if (child) { |
| 773 | if (LoadPages(child)) { |
| 774 | LOGERR("PageSet::Load returning -1\n"); |
| 775 | return -1; |
| 776 | } |
| 777 | } |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 778 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 779 | return CheckInclude(package, &mDoc); |
| 780 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 781 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 782 | int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc) |
| 783 | { |
| 784 | xml_node<>* par; |
| 785 | xml_node<>* par2; |
| 786 | xml_node<>* chld; |
| 787 | xml_node<>* parent; |
| 788 | xml_node<>* child; |
| 789 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 790 | xml_node<>* xmlstyle; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 791 | long len; |
| 792 | char* xmlFile = NULL; |
| 793 | string filename; |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 794 | xml_document<> *doc = NULL; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 795 | |
| 796 | par = parentDoc->first_node("recovery"); |
| 797 | if (!par) { |
| 798 | par = parentDoc->first_node("install"); |
| 799 | } |
| 800 | if (!par) { |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | par2 = par->first_node("include"); |
| 805 | if (!par2) |
| 806 | return 0; |
| 807 | chld = par2->first_node("xmlfile"); |
| 808 | while (chld != NULL) { |
| 809 | xml_attribute<>* attr = chld->first_attribute("name"); |
| 810 | if (!attr) |
| 811 | break; |
| 812 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 813 | if (!package) { |
| 814 | // We can try to load the XML directly... |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 815 | filename = TWRES; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 816 | filename += attr->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 817 | } else { |
| 818 | filename += attr->value(); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 819 | } |
| 820 | xmlFile = PageManager::LoadFileToBuffer(filename, package); |
| 821 | if (xmlFile == NULL) { |
| 822 | LOGERR("PageSet::CheckInclude unable to load '%s'\n", filename.c_str()); |
| 823 | return -1; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 824 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 825 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 826 | doc = new xml_document<>(); |
| 827 | doc->parse<0>(xmlFile); |
| 828 | |
| 829 | parent = doc->first_node("recovery"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 830 | if (!parent) |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 831 | parent = doc->first_node("install"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 832 | |
| 833 | // Now, let's parse the XML |
| 834 | LOGINFO("Loading included resources...\n"); |
| 835 | child = parent->first_node("resources"); |
| 836 | if (child) |
| 837 | mResources->LoadResources(child, package); |
| 838 | |
| 839 | LOGINFO("Loading included variables...\n"); |
| 840 | child = parent->first_node("variables"); |
| 841 | if (child) |
| 842 | LoadVariables(child); |
| 843 | |
| 844 | LOGINFO("Loading mouse cursor...\n"); |
| 845 | child = parent->first_node("mousecursor"); |
| 846 | if(child) |
| 847 | PageManager::LoadCursorData(child); |
| 848 | |
| 849 | LOGINFO("Loading included pages...\n"); |
| 850 | // This may be NULL if no templates are present |
| 851 | xmltemplate = parent->first_node("templates"); |
| 852 | if (xmltemplate) |
| 853 | templates.push_back(xmltemplate); |
| 854 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 855 | // Load styles if present |
| 856 | xmlstyle = parent->first_node("styles"); |
| 857 | if (xmlstyle) |
| 858 | styles.push_back(xmlstyle); |
| 859 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 860 | child = parent->first_node("pages"); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 861 | if (child && LoadPages(child)) |
| 862 | { |
| 863 | templates.pop_back(); |
| 864 | doc->clear(); |
| 865 | delete doc; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 866 | free(xmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 867 | return -1; |
| 868 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 869 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 870 | mIncludedDocs.push_back(doc); |
| 871 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 872 | if (CheckInclude(package, doc)) { |
| 873 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 874 | return -1; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 875 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 876 | |
| 877 | chld = chld->next_sibling("xmlfile"); |
| 878 | } |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 879 | if (xmlFile) |
| 880 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 881 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | int PageSet::SetPage(std::string page) |
| 885 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 886 | Page* tmp = FindPage(page); |
| 887 | if (tmp) |
| 888 | { |
| 889 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 890 | mCurrentPage = tmp; |
| 891 | mCurrentPage->SetPageFocus(1); |
| 892 | mCurrentPage->NotifyVarChange("", ""); |
| 893 | return 0; |
| 894 | } |
| 895 | else |
| 896 | { |
| 897 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 898 | } |
| 899 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | int PageSet::SetOverlay(Page* page) |
| 903 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 904 | if (page) { |
| 905 | if (mOverlays.size() >= 10) { |
| 906 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 907 | return -1; |
| 908 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 909 | |
| 910 | std::vector<Page*>::iterator iter; |
| 911 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 912 | if ((*iter)->GetName() == page->GetName()) { |
| 913 | mOverlays.erase(iter); |
| 914 | // SetOverlay() is (and should stay) the only function which |
| 915 | // adds to mOverlays. Then, each page can appear at most once. |
| 916 | break; |
| 917 | } |
| 918 | } |
| 919 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 920 | page->SetPageFocus(1); |
| 921 | page->NotifyVarChange("", ""); |
| 922 | |
| 923 | if (!mOverlays.empty()) |
| 924 | mOverlays.back()->SetPageFocus(0); |
| 925 | |
| 926 | mOverlays.push_back(page); |
| 927 | } else { |
| 928 | if (!mOverlays.empty()) { |
| 929 | mOverlays.back()->SetPageFocus(0); |
| 930 | mOverlays.pop_back(); |
| 931 | if (!mOverlays.empty()) |
| 932 | mOverlays.back()->SetPageFocus(1); |
| 933 | else if (mCurrentPage) |
| 934 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 935 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 936 | } |
| 937 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 938 | } |
| 939 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 940 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 941 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 942 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | Page* PageSet::FindPage(std::string name) |
| 946 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 947 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 948 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 949 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 950 | { |
| 951 | if (name == (*iter)->GetName()) |
| 952 | return (*iter); |
| 953 | } |
| 954 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | int PageSet::LoadVariables(xml_node<>* vars) |
| 958 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 959 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 960 | xml_attribute<> *name, *value, *persist; |
| 961 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 962 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 963 | child = vars->first_node("variable"); |
| 964 | while (child) |
| 965 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 966 | name = child->first_attribute("name"); |
| 967 | value = child->first_attribute("value"); |
| 968 | persist = child->first_attribute("persist"); |
| 969 | if(name && value) |
| 970 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 971 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 972 | tw_x_offset = atoi(value->value()); |
| 973 | child = child->next_sibling("variable"); |
| 974 | continue; |
| 975 | } |
| 976 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 977 | tw_y_offset = atoi(value->value()); |
| 978 | child = child->next_sibling("variable"); |
| 979 | continue; |
| 980 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 981 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 982 | string temp = value->value(); |
| 983 | string valstr = gui_parse_text(temp); |
| 984 | |
| 985 | if (valstr.find("+") != string::npos) { |
| 986 | string val1str = valstr; |
| 987 | val1str = val1str.substr(0, val1str.find('+')); |
| 988 | string val2str = valstr; |
| 989 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 990 | int val1 = atoi(val1str.c_str()); |
| 991 | int val2 = atoi(val2str.c_str()); |
| 992 | int val = val1 + val2; |
| 993 | |
| 994 | DataManager::SetValue(name->value(), val, p); |
| 995 | } else if (valstr.find("-") != string::npos) { |
| 996 | string val1str = valstr; |
| 997 | val1str = val1str.substr(0, val1str.find('-')); |
| 998 | string val2str = valstr; |
| 999 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 1000 | int val1 = atoi(val1str.c_str()); |
| 1001 | int val2 = atoi(val2str.c_str()); |
| 1002 | int val = val1 - val2; |
| 1003 | |
| 1004 | DataManager::SetValue(name->value(), val, p); |
| 1005 | } else { |
| 1006 | DataManager::SetValue(name->value(), valstr, p); |
| 1007 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1008 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1009 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1010 | child = child->next_sibling("variable"); |
| 1011 | } |
| 1012 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1015 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1016 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1017 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1018 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1019 | if (!pages) |
| 1020 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1021 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1022 | child = pages->first_node("page"); |
| 1023 | while (child != NULL) |
| 1024 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1025 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1026 | if (page->GetName().empty()) |
| 1027 | { |
| 1028 | LOGERR("Unable to process load page\n"); |
| 1029 | delete page; |
| 1030 | } |
| 1031 | else |
| 1032 | { |
| 1033 | mPages.push_back(page); |
| 1034 | } |
| 1035 | child = child->next_sibling("page"); |
| 1036 | } |
| 1037 | if (mPages.size() > 0) |
| 1038 | return 0; |
| 1039 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | int PageSet::IsCurrentPage(Page* page) |
| 1043 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1044 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | int PageSet::Render(void) |
| 1048 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1049 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1050 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1051 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1052 | if (ret < 0) |
| 1053 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1054 | |
| 1055 | std::vector<Page*>::iterator iter; |
| 1056 | |
| 1057 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1058 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1059 | if (ret < 0) |
| 1060 | return ret; |
| 1061 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1062 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | int PageSet::Update(void) |
| 1066 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1067 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1068 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1069 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1070 | if (ret < 0 || ret > 1) |
| 1071 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1072 | |
| 1073 | std::vector<Page*>::iterator iter; |
| 1074 | |
| 1075 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1076 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1077 | if (ret < 0) |
| 1078 | return ret; |
| 1079 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1080 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1084 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1085 | if (!mOverlays.empty()) |
| 1086 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1087 | |
| 1088 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1091 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1092 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1093 | if (!mOverlays.empty()) |
| 1094 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1095 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1096 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | int PageSet::NotifyKeyboard(int key) |
| 1100 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1101 | if (!mOverlays.empty()) |
| 1102 | return mOverlays.back()->NotifyKeyboard(key); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1103 | |
| 1104 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1108 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1109 | if (!mOverlays.empty()) |
| 1110 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1111 | |
| 1112 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1116 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1117 | std::vector<Page*>::iterator iter; |
| 1118 | |
| 1119 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1120 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1121 | |
| 1122 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1125 | char* PageManager::LoadFileToBuffer(std::string filename, ZipArchive* package) { |
| 1126 | size_t len; |
| 1127 | char* buffer = NULL; |
| 1128 | |
| 1129 | if (!package) { |
| 1130 | // We can try to load the XML directly... |
| 1131 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' directly\n", filename.c_str()); |
| 1132 | struct stat st; |
| 1133 | if(stat(filename.c_str(),&st) != 0) { |
| 1134 | // This isn't always an error, sometimes we request files that don't exist. |
| 1135 | return NULL; |
| 1136 | } |
| 1137 | |
| 1138 | len = (size_t)st.st_size; |
| 1139 | |
| 1140 | buffer = (char*) malloc(len + 1); |
| 1141 | if (!buffer) { |
| 1142 | LOGERR("PageManager::LoadFileToBuffer failed to malloc\n"); |
| 1143 | return NULL; |
| 1144 | } |
| 1145 | |
| 1146 | int fd = open(filename.c_str(), O_RDONLY); |
| 1147 | if (fd == -1) { |
| 1148 | LOGERR("PageManager::LoadFileToBuffer failed to open '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1149 | free(buffer); |
| 1150 | return NULL; |
| 1151 | } |
| 1152 | |
| 1153 | if (read(fd, buffer, len) < 0) { |
| 1154 | LOGERR("PageManager::LoadFileToBuffer failed to read '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1155 | free(buffer); |
| 1156 | close(fd); |
| 1157 | return NULL; |
| 1158 | } |
| 1159 | close(fd); |
| 1160 | } else { |
| 1161 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str()); |
| 1162 | const ZipEntry* zipentry = mzFindZipEntry(package, filename.c_str()); |
| 1163 | if (zipentry == NULL) { |
| 1164 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 1165 | return NULL; |
| 1166 | } |
| 1167 | |
| 1168 | // Allocate the buffer for the file |
| 1169 | len = mzGetZipEntryUncompLen(zipentry); |
| 1170 | buffer = (char*) malloc(len + 1); |
| 1171 | if (!buffer) |
| 1172 | return NULL; |
| 1173 | |
| 1174 | if (!mzExtractZipEntryToBuffer(package, zipentry, (unsigned char*) buffer)) { |
| 1175 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 1176 | free(buffer); |
| 1177 | return NULL; |
| 1178 | } |
| 1179 | } |
| 1180 | // NULL-terminate the string |
| 1181 | buffer[len] = 0x00; |
| 1182 | return buffer; |
| 1183 | } |
| 1184 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1185 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1186 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1187 | int fd; |
| 1188 | ZipArchive zip, *pZip = NULL; |
| 1189 | long len; |
| 1190 | char* xmlFile = NULL; |
| 1191 | PageSet* pageSet = NULL; |
| 1192 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1193 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1194 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1195 | // Open the XML file |
| 1196 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1197 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1198 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1199 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1200 | tw_x_offset = TW_X_OFFSET; |
| 1201 | tw_y_offset = TW_Y_OFFSET; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1202 | } |
| 1203 | else |
| 1204 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1205 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1206 | tw_x_offset = 0; |
| 1207 | tw_y_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1208 | if (!TWFunc::Path_Exists(package)) |
| 1209 | return -1; |
| 1210 | if (sysMapFile(package.c_str(), &map) != 0) { |
| 1211 | LOGERR("Failed to map '%s'\n", package.c_str()); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1212 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1213 | } |
| 1214 | if (mzOpenZipArchive(map.addr, map.length, &zip)) { |
| 1215 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
| 1216 | sysReleaseMap(&map); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1217 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1218 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1219 | pZip = &zip; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1220 | package = "ui.xml"; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1221 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1222 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1223 | xmlFile = LoadFileToBuffer(package, pZip); |
| 1224 | if (xmlFile == NULL) { |
| 1225 | goto error; |
| 1226 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1227 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1228 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 1229 | pageSet = mCurrentSet; |
| 1230 | mCurrentSet = new PageSet(xmlFile); |
| 1231 | |
| 1232 | ret = mCurrentSet->Load(pZip); |
| 1233 | if (ret == 0) |
| 1234 | { |
| 1235 | mCurrentSet->SetPage(startpage); |
| 1236 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
| 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | LOGERR("Package %s failed to load.\n", name.c_str()); |
| 1241 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1242 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1243 | // The first successful package we loaded is the base |
| 1244 | if (mBaseSet == NULL) |
| 1245 | mBaseSet = mCurrentSet; |
| 1246 | |
| 1247 | mCurrentSet = pageSet; |
| 1248 | |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1249 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1250 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1251 | sysReleaseMap(&map); |
| 1252 | } |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1253 | free(xmlFile); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1254 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1255 | |
| 1256 | error: |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1257 | // Sometimes we get here without a real error |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1258 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1259 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1260 | sysReleaseMap(&map); |
| 1261 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1262 | if (xmlFile) |
| 1263 | free(xmlFile); |
| 1264 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | PageSet* PageManager::FindPackage(std::string name) |
| 1268 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1269 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1270 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1271 | iter = mPageSets.find(name); |
| 1272 | if (iter != mPageSets.end()) |
| 1273 | return (*iter).second; |
| 1274 | |
| 1275 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1276 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | PageSet* PageManager::SelectPackage(std::string name) |
| 1280 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1281 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1282 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1283 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1284 | tmp = FindPackage(name); |
| 1285 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1286 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1287 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1288 | mCurrentSet->NotifyVarChange("", ""); |
| 1289 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1290 | else |
| 1291 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1292 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1293 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1297 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1298 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1299 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1300 | iter = mPageSets.find(name); |
| 1301 | if (iter == mPageSets.end()) |
| 1302 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1303 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1304 | if(mMouseCursor) |
| 1305 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1306 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1307 | PageSet* set = (*iter).second; |
| 1308 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1309 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1310 | if (LoadPackage(name, package, "main") != 0) |
| 1311 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 1312 | LOGERR("Failed to load package '%s'.\n", package.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1313 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1314 | return -1; |
| 1315 | } |
| 1316 | if (mCurrentSet == set) |
| 1317 | SelectPackage(name); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 1318 | if (mBaseSet == set) |
| 1319 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1320 | delete set; |
| 1321 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | void PageManager::ReleasePackage(std::string name) |
| 1325 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1326 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1327 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1328 | iter = mPageSets.find(name); |
| 1329 | if (iter == mPageSets.end()) |
| 1330 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1331 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1332 | PageSet* set = (*iter).second; |
| 1333 | mPageSets.erase(iter); |
| 1334 | delete set; |
| 1335 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | int PageManager::ChangePage(std::string name) |
| 1339 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1340 | DataManager::SetValue("tw_operation_state", 0); |
| 1341 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1342 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | int PageManager::ChangeOverlay(std::string name) |
| 1346 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1347 | if (name.empty()) |
| 1348 | return mCurrentSet->SetOverlay(NULL); |
| 1349 | else |
| 1350 | { |
| 1351 | Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; |
| 1352 | return mCurrentSet->SetOverlay(page); |
| 1353 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1356 | const ResourceManager* PageManager::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1357 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1358 | return (mCurrentSet ? mCurrentSet->GetResources() : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | int PageManager::SwitchToConsole(void) |
| 1362 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1363 | PageSet* console = new PageSet(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1364 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1365 | mCurrentSet = console; |
| 1366 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 1369 | int PageManager::EndConsole(void) |
| 1370 | { |
| 1371 | if (mCurrentSet && mBaseSet) { |
| 1372 | delete mCurrentSet; |
| 1373 | mCurrentSet = mBaseSet; |
| 1374 | return 0; |
| 1375 | } |
| 1376 | return -1; |
| 1377 | } |
| 1378 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1379 | int PageManager::IsCurrentPage(Page* page) |
| 1380 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1381 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | int PageManager::Render(void) |
| 1385 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1386 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 1387 | if(mMouseCursor) |
| 1388 | mMouseCursor->Render(); |
| 1389 | return res; |
| 1390 | } |
| 1391 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1392 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1393 | { |
| 1394 | if(!mHardwareKeyboard) |
| 1395 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1396 | return mHardwareKeyboard; |
| 1397 | } |
| 1398 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1399 | xml_node<>* PageManager::FindStyle(std::string name) |
| 1400 | { |
| 1401 | for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) { |
| 1402 | xml_node<>* node = (*itr)->first_node("style"); |
| 1403 | |
| 1404 | while (node) { |
| 1405 | if (!node->first_attribute("name")) |
| 1406 | continue; |
| 1407 | |
| 1408 | if (name == node->first_attribute("name")->value()) |
| 1409 | return node; |
| 1410 | node = node->next_sibling("style"); |
| 1411 | } |
| 1412 | } |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1416 | MouseCursor *PageManager::GetMouseCursor() |
| 1417 | { |
| 1418 | if(!mMouseCursor) |
| 1419 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1420 | return mMouseCursor; |
| 1421 | } |
| 1422 | |
| 1423 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1424 | { |
| 1425 | if(!mMouseCursor) |
| 1426 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1427 | |
| 1428 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | int PageManager::Update(void) |
| 1432 | { |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 1433 | if(blankTimer.isScreenOff()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1434 | return 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1435 | |
| 1436 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1437 | |
| 1438 | if(mMouseCursor) |
| 1439 | { |
| 1440 | int c_res = mMouseCursor->Update(); |
| 1441 | if(c_res > res) |
| 1442 | res = c_res; |
| 1443 | } |
| 1444 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1448 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1449 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1452 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1453 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1454 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | int PageManager::NotifyKeyboard(int key) |
| 1458 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1459 | return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1463 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1464 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1468 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1469 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1473 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1474 | if (!gGuiRunning) |
| 1475 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1476 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1477 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1478 | } |