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 { |
| 140 | // Search for stylename in the parent node <object type="foo" stylename="foo2"> |
| 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"); |
| 147 | if (attr) { |
| 148 | xml_node<>* node = PageManager::FindStyle(attr->value()); |
| 149 | if (node) { |
| 150 | xml_node<>* stylenode = FindNode(node, nodename, depth + 1); |
| 151 | if (stylenode) |
| 152 | return stylenode; |
| 153 | } |
| 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 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 232 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */) |
| 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")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 250 | *placement = (RenderObject::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 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 270 | Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates /* = NULL */) |
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 |
| 299 | ProcessNode(page, templates); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 300 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 301 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 302 | } |
| 303 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 304 | Page::~Page() |
| 305 | { |
| 306 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 307 | delete *itr; |
| 308 | } |
| 309 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 310 | 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] | 311 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 312 | if (depth == 10) |
| 313 | { |
| 314 | LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); |
| 315 | return false; |
| 316 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 317 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 318 | // Let's retrieve the background value, if any |
| 319 | xml_node<>* bg = page->first_node("background"); |
| 320 | if (bg) |
| 321 | { |
| 322 | xml_attribute<>* attr = bg->first_attribute("color"); |
| 323 | if (attr) |
| 324 | { |
| 325 | std::string color = attr->value(); |
| 326 | ConvertStrToColor(color, &mBackground); |
| 327 | } |
| 328 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 329 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 330 | xml_node<>* child; |
| 331 | child = page->first_node("object"); |
| 332 | while (child) |
| 333 | { |
| 334 | if (!child->first_attribute("type")) |
| 335 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 336 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 337 | std::string type = child->first_attribute("type")->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 338 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 339 | if (type == "text") |
| 340 | { |
| 341 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 342 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 343 | mRenders.push_back(element); |
| 344 | mActions.push_back(element); |
| 345 | } |
| 346 | else if (type == "image") |
| 347 | { |
| 348 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 349 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 350 | mRenders.push_back(element); |
| 351 | } |
| 352 | else if (type == "fill") |
| 353 | { |
| 354 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 355 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 356 | mRenders.push_back(element); |
| 357 | } |
| 358 | else if (type == "action") |
| 359 | { |
| 360 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 361 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 362 | mActions.push_back(element); |
| 363 | } |
| 364 | else if (type == "console") |
| 365 | { |
| 366 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 367 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 368 | mRenders.push_back(element); |
| 369 | mActions.push_back(element); |
| 370 | } |
| 371 | else if (type == "button") |
| 372 | { |
| 373 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 374 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 375 | mRenders.push_back(element); |
| 376 | mActions.push_back(element); |
| 377 | } |
| 378 | else if (type == "checkbox") |
| 379 | { |
| 380 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 381 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 382 | mRenders.push_back(element); |
| 383 | mActions.push_back(element); |
| 384 | } |
| 385 | else if (type == "fileselector") |
| 386 | { |
| 387 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 388 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | mRenders.push_back(element); |
| 390 | mActions.push_back(element); |
| 391 | } |
| 392 | else if (type == "animation") |
| 393 | { |
| 394 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 395 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 396 | mRenders.push_back(element); |
| 397 | } |
| 398 | else if (type == "progressbar") |
| 399 | { |
| 400 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 401 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 402 | mRenders.push_back(element); |
| 403 | mActions.push_back(element); |
| 404 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 405 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 406 | { |
| 407 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 408 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 409 | mRenders.push_back(element); |
| 410 | mActions.push_back(element); |
| 411 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 412 | else if (type == "slidervalue") |
| 413 | { |
| 414 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 415 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 416 | mRenders.push_back(element); |
| 417 | mActions.push_back(element); |
| 418 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 419 | else if (type == "listbox") |
| 420 | { |
| 421 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 422 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 423 | mRenders.push_back(element); |
| 424 | mActions.push_back(element); |
| 425 | } |
| 426 | else if (type == "keyboard") |
| 427 | { |
| 428 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 429 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 430 | mRenders.push_back(element); |
| 431 | mActions.push_back(element); |
| 432 | } |
| 433 | else if (type == "input") |
| 434 | { |
| 435 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 436 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 437 | mRenders.push_back(element); |
| 438 | mActions.push_back(element); |
| 439 | mInputs.push_back(element); |
| 440 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 441 | else if (type == "partitionlist") |
| 442 | { |
| 443 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 444 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 445 | mRenders.push_back(element); |
| 446 | mActions.push_back(element); |
| 447 | } |
Vojtech Bocek | 7e11ac5 | 2015-03-05 23:21:49 +0100 | [diff] [blame] | 448 | else if (type == "patternpassword") |
| 449 | { |
| 450 | GUIPatternPassword* element = new GUIPatternPassword(child); |
| 451 | mObjects.push_back(element); |
| 452 | mRenders.push_back(element); |
| 453 | mActions.push_back(element); |
| 454 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 455 | else if (type == "template") |
| 456 | { |
| 457 | if (!templates || !child->first_attribute("name")) |
| 458 | { |
| 459 | LOGERR("Invalid template request.\n"); |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | std::string name = child->first_attribute("name")->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 464 | xml_node<>* node; |
| 465 | bool node_found = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 466 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 467 | // We need to find the correct template |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 468 | for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) { |
| 469 | node = (*itr)->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 470 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 471 | while (node) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 472 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 473 | if (!node->first_attribute("name")) |
| 474 | continue; |
| 475 | |
| 476 | if (name == node->first_attribute("name")->value()) |
| 477 | { |
| 478 | if (!ProcessNode(node, templates, depth + 1)) |
| 479 | return false; |
| 480 | else { |
| 481 | node_found = true; |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | if (node_found) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 486 | break; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 487 | node = node->next_sibling("template"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 488 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | else |
| 493 | { |
| 494 | LOGERR("Unknown object type.\n"); |
| 495 | } |
| 496 | child = child->next_sibling("object"); |
| 497 | } |
| 498 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | int Page::Render(void) |
| 502 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 503 | // Render background |
| 504 | gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); |
| 505 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
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 | // Render remaining objects |
| 508 | std::vector<RenderObject*>::iterator iter; |
| 509 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 510 | { |
| 511 | if ((*iter)->Render()) |
| 512 | LOGERR("A render request has failed.\n"); |
| 513 | } |
| 514 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | int Page::Update(void) |
| 518 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 519 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 520 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 521 | std::vector<RenderObject*>::iterator iter; |
| 522 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 523 | { |
| 524 | int ret = (*iter)->Update(); |
| 525 | if (ret < 0) |
| 526 | LOGERR("An update request has failed.\n"); |
| 527 | else if (ret > retCode) |
| 528 | retCode = ret; |
| 529 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 531 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 535 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 536 | // By default, return 1 to ignore further touches if nobody is listening |
| 537 | int ret = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 538 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 539 | // Don't try to handle a lack of handlers |
| 540 | if (mActions.size() == 0) |
| 541 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 542 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 543 | // We record mTouchStart so we can pass all the touch stream to the same handler |
| 544 | if (state == TOUCH_START) |
| 545 | { |
| 546 | std::vector<ActionObject*>::reverse_iterator iter; |
| 547 | // We work backwards, from top-most element to bottom-most element |
| 548 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 549 | { |
| 550 | if ((*iter)->IsInRegion(x, y)) |
| 551 | { |
| 552 | mTouchStart = (*iter); |
| 553 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 554 | if (ret >= 0) |
| 555 | break; |
| 556 | mTouchStart = NULL; |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | else if (state == TOUCH_RELEASE && mTouchStart != NULL) |
| 561 | { |
| 562 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 563 | mTouchStart = NULL; |
| 564 | } |
| 565 | else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) |
| 566 | { |
| 567 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 568 | } |
| 569 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 572 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 573 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 574 | std::vector<ActionObject*>::reverse_iterator iter; |
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 | // Don't try to handle a lack of handlers |
| 577 | if (mActions.size() == 0) |
| 578 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 579 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 580 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 581 | // We work backwards, from top-most element to bottom-most element |
| 582 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 583 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 584 | ret = (*iter)->NotifyKey(key, down); |
| 585 | if (ret < 0) { |
| 586 | LOGERR("An action handler has returned an error\n"); |
| 587 | ret = 1; |
| 588 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 589 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 590 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | int Page::NotifyKeyboard(int key) |
| 594 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 595 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 596 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 597 | // Don't try to handle a lack of handlers |
| 598 | if (mInputs.size() == 0) |
| 599 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 600 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 601 | // We work backwards, from top-most element to bottom-most element |
| 602 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 603 | { |
| 604 | int ret = (*iter)->NotifyKeyboard(key); |
| 605 | if (ret == 0) |
| 606 | return 0; |
| 607 | else if (ret < 0) |
| 608 | LOGERR("A keyboard handler has returned an error"); |
| 609 | } |
| 610 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | int Page::SetKeyBoardFocus(int inFocus) |
| 614 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 615 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 616 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 617 | // Don't try to handle a lack of handlers |
| 618 | if (mInputs.size() == 0) |
| 619 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 621 | // We work backwards, from top-most element to bottom-most element |
| 622 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 623 | { |
| 624 | int ret = (*iter)->SetInputFocus(inFocus); |
| 625 | if (ret == 0) |
| 626 | return 0; |
| 627 | else if (ret < 0) |
| 628 | LOGERR("An input focus handler has returned an error"); |
| 629 | } |
| 630 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void Page::SetPageFocus(int inFocus) |
| 634 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 635 | // Render remaining objects |
| 636 | std::vector<RenderObject*>::iterator iter; |
| 637 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 638 | (*iter)->SetPageFocus(inFocus); |
| 639 | |
| 640 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 644 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 645 | std::vector<GUIObject*>::iterator iter; |
| 646 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 647 | { |
| 648 | if ((*iter)->NotifyVarChange(varName, value)) |
| 649 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 650 | } |
| 651 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | PageSet::PageSet(char* xmlFile) |
| 655 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 656 | mResources = new ResourceManager; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 657 | mCurrentPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 658 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 659 | mXmlFile = xmlFile; |
| 660 | if (xmlFile) |
| 661 | mDoc.parse<0>(mXmlFile); |
| 662 | else |
| 663 | mCurrentPage = new Page(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | PageSet::~PageSet() |
| 667 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 668 | mOverlays.clear(); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 669 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 670 | delete *itr; |
| 671 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 672 | delete mResources; |
| 673 | free(mXmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 674 | |
| 675 | mDoc.clear(); |
| 676 | |
| 677 | for (std::vector<xml_document<>*>::iterator itr = mIncludedDocs.begin(); itr != mIncludedDocs.end(); ++itr) { |
| 678 | (*itr)->clear(); |
| 679 | delete *itr; |
| 680 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | int PageSet::Load(ZipArchive* package) |
| 684 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 685 | xml_node<>* parent; |
| 686 | xml_node<>* child; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 687 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 688 | xml_node<>* xmlstyle; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 689 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 690 | parent = mDoc.first_node("recovery"); |
| 691 | if (!parent) |
| 692 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 693 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 694 | set_scale_values(1, 1); // Reset any previous scaling values |
| 695 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 696 | // Now, let's parse the XML |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 697 | LOGINFO("Checking resolution...\n"); |
| 698 | child = parent->first_node("details"); |
| 699 | if (child) { |
| 700 | xml_node<>* resolution = child->first_node("resolution"); |
| 701 | if (resolution) { |
| 702 | xml_attribute<>* width_attr = resolution->first_attribute("width"); |
| 703 | xml_attribute<>* height_attr = resolution->first_attribute("height"); |
| 704 | xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling"); |
| 705 | if (width_attr && height_attr && !noscale_attr) { |
| 706 | int width = atoi(width_attr->value()); |
| 707 | int height = atoi(height_attr->value()); |
| 708 | int offx = 0, offy = 0; |
| 709 | #ifdef TW_ROUND_SCREEN |
| 710 | xml_node<>* roundscreen = child->first_node("roundscreen"); |
| 711 | if (roundscreen) { |
| 712 | LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n"); |
| 713 | xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x"); |
| 714 | xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y"); |
| 715 | if (offx_attr) { |
| 716 | offx = atoi(offx_attr->value()); |
| 717 | } |
| 718 | if (offy_attr) { |
| 719 | offy = atoi(offy_attr->value()); |
| 720 | } |
| 721 | } |
| 722 | #endif |
| 723 | if (width != 0 && height != 0) { |
| 724 | float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width; |
| 725 | float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height; |
| 726 | #ifdef TW_ROUND_SCREEN |
| 727 | float scale_off_w = (float)gr_fb_width() / (float)width; |
| 728 | float scale_off_h = (float)gr_fb_height() / (float)height; |
| 729 | tw_x_offset = offx * scale_off_w; |
| 730 | tw_y_offset = offy * scale_off_h; |
| 731 | #endif |
| 732 | if (scale_w != 1 || scale_h != 1) { |
| 733 | LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset); |
| 734 | set_scale_values(scale_w, scale_h); |
| 735 | } |
| 736 | } |
| 737 | } else { |
| 738 | LOGINFO("XML does not contain width and height, no scaling will be applied\n"); |
| 739 | } |
| 740 | } else { |
| 741 | LOGINFO("XML contains no resolution tag, no scaling will be applied.\n"); |
| 742 | } |
| 743 | } else { |
| 744 | LOGINFO("XML contains no details tag, no scaling will be applied.\n"); |
| 745 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 746 | LOGINFO("Loading resources...\n"); |
| 747 | child = parent->first_node("resources"); |
| 748 | if (child) |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 749 | mResources->LoadResources(child, package); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 750 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 751 | LOGINFO("Loading variables...\n"); |
| 752 | child = parent->first_node("variables"); |
| 753 | if (child) |
| 754 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 755 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 756 | LOGINFO("Loading mouse cursor...\n"); |
| 757 | child = parent->first_node("mousecursor"); |
| 758 | if(child) |
| 759 | PageManager::LoadCursorData(child); |
| 760 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 761 | LOGINFO("Loading pages...\n"); |
| 762 | // This may be NULL if no templates are present |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 763 | xmltemplate = parent->first_node("templates"); |
| 764 | if (xmltemplate) |
| 765 | templates.push_back(xmltemplate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 766 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 767 | // Load styles if present |
| 768 | xmlstyle = parent->first_node("styles"); |
| 769 | if (xmlstyle) |
| 770 | styles.push_back(xmlstyle); |
| 771 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 772 | child = parent->first_node("pages"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 773 | if (child) { |
| 774 | if (LoadPages(child)) { |
| 775 | LOGERR("PageSet::Load returning -1\n"); |
| 776 | return -1; |
| 777 | } |
| 778 | } |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 779 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 780 | return CheckInclude(package, &mDoc); |
| 781 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 783 | int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc) |
| 784 | { |
| 785 | xml_node<>* par; |
| 786 | xml_node<>* par2; |
| 787 | xml_node<>* chld; |
| 788 | xml_node<>* parent; |
| 789 | xml_node<>* child; |
| 790 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 791 | xml_node<>* xmlstyle; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 792 | long len; |
| 793 | char* xmlFile = NULL; |
| 794 | string filename; |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 795 | xml_document<> *doc = NULL; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 796 | |
| 797 | par = parentDoc->first_node("recovery"); |
| 798 | if (!par) { |
| 799 | par = parentDoc->first_node("install"); |
| 800 | } |
| 801 | if (!par) { |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | par2 = par->first_node("include"); |
| 806 | if (!par2) |
| 807 | return 0; |
| 808 | chld = par2->first_node("xmlfile"); |
| 809 | while (chld != NULL) { |
| 810 | xml_attribute<>* attr = chld->first_attribute("name"); |
| 811 | if (!attr) |
| 812 | break; |
| 813 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 814 | if (!package) { |
| 815 | // We can try to load the XML directly... |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 816 | filename = TWRES; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 817 | filename += attr->value(); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 818 | LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str()); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 819 | struct stat st; |
| 820 | if(stat(filename.c_str(),&st) != 0) { |
| 821 | LOGERR("Unable to locate '%s'\n", filename.c_str()); |
| 822 | return -1; |
| 823 | } |
| 824 | |
| 825 | len = st.st_size; |
| 826 | xmlFile = (char*) malloc(len + 1); |
| 827 | if (!xmlFile) |
| 828 | return -1; |
| 829 | |
| 830 | int fd = open(filename.c_str(), O_RDONLY); |
| 831 | if (fd == -1) |
| 832 | return -1; |
| 833 | |
| 834 | read(fd, xmlFile, len); |
| 835 | close(fd); |
| 836 | } else { |
| 837 | filename += attr->value(); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 838 | LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str()); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 839 | const ZipEntry* ui_xml = mzFindZipEntry(package, filename.c_str()); |
| 840 | if (ui_xml == NULL) |
| 841 | { |
| 842 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 843 | return -1; |
| 844 | } |
| 845 | |
| 846 | // Allocate the buffer for the file |
| 847 | len = mzGetZipEntryUncompLen(ui_xml); |
| 848 | xmlFile = (char*) malloc(len + 1); |
| 849 | if (!xmlFile) |
| 850 | return -1; |
| 851 | |
| 852 | if (!mzExtractZipEntryToBuffer(package, ui_xml, (unsigned char*) xmlFile)) |
| 853 | { |
| 854 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 855 | return -1; |
| 856 | } |
| 857 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 858 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 859 | xmlFile[len] = '\0'; |
| 860 | doc = new xml_document<>(); |
| 861 | doc->parse<0>(xmlFile); |
| 862 | |
| 863 | parent = doc->first_node("recovery"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 864 | if (!parent) |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 865 | parent = doc->first_node("install"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 866 | |
| 867 | // Now, let's parse the XML |
| 868 | LOGINFO("Loading included resources...\n"); |
| 869 | child = parent->first_node("resources"); |
| 870 | if (child) |
| 871 | mResources->LoadResources(child, package); |
| 872 | |
| 873 | LOGINFO("Loading included variables...\n"); |
| 874 | child = parent->first_node("variables"); |
| 875 | if (child) |
| 876 | LoadVariables(child); |
| 877 | |
| 878 | LOGINFO("Loading mouse cursor...\n"); |
| 879 | child = parent->first_node("mousecursor"); |
| 880 | if(child) |
| 881 | PageManager::LoadCursorData(child); |
| 882 | |
| 883 | LOGINFO("Loading included pages...\n"); |
| 884 | // This may be NULL if no templates are present |
| 885 | xmltemplate = parent->first_node("templates"); |
| 886 | if (xmltemplate) |
| 887 | templates.push_back(xmltemplate); |
| 888 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 889 | // Load styles if present |
| 890 | xmlstyle = parent->first_node("styles"); |
| 891 | if (xmlstyle) |
| 892 | styles.push_back(xmlstyle); |
| 893 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 894 | child = parent->first_node("pages"); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 895 | if (child && LoadPages(child)) |
| 896 | { |
| 897 | templates.pop_back(); |
| 898 | doc->clear(); |
| 899 | delete doc; |
| 900 | return -1; |
| 901 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 902 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 903 | mIncludedDocs.push_back(doc); |
| 904 | |
| 905 | if (CheckInclude(package, doc)) |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 906 | return -1; |
| 907 | |
| 908 | chld = chld->next_sibling("xmlfile"); |
| 909 | } |
| 910 | |
| 911 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | int PageSet::SetPage(std::string page) |
| 915 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 916 | Page* tmp = FindPage(page); |
| 917 | if (tmp) |
| 918 | { |
| 919 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 920 | mCurrentPage = tmp; |
| 921 | mCurrentPage->SetPageFocus(1); |
| 922 | mCurrentPage->NotifyVarChange("", ""); |
| 923 | return 0; |
| 924 | } |
| 925 | else |
| 926 | { |
| 927 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 928 | } |
| 929 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | int PageSet::SetOverlay(Page* page) |
| 933 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 934 | if (page) { |
| 935 | if (mOverlays.size() >= 10) { |
| 936 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 937 | return -1; |
| 938 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 939 | |
| 940 | std::vector<Page*>::iterator iter; |
| 941 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 942 | if ((*iter)->GetName() == page->GetName()) { |
| 943 | mOverlays.erase(iter); |
| 944 | // SetOverlay() is (and should stay) the only function which |
| 945 | // adds to mOverlays. Then, each page can appear at most once. |
| 946 | break; |
| 947 | } |
| 948 | } |
| 949 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 950 | page->SetPageFocus(1); |
| 951 | page->NotifyVarChange("", ""); |
| 952 | |
| 953 | if (!mOverlays.empty()) |
| 954 | mOverlays.back()->SetPageFocus(0); |
| 955 | |
| 956 | mOverlays.push_back(page); |
| 957 | } else { |
| 958 | if (!mOverlays.empty()) { |
| 959 | mOverlays.back()->SetPageFocus(0); |
| 960 | mOverlays.pop_back(); |
| 961 | if (!mOverlays.empty()) |
| 962 | mOverlays.back()->SetPageFocus(1); |
| 963 | else if (mCurrentPage) |
| 964 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 965 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 966 | } |
| 967 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 968 | } |
| 969 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 970 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 971 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 972 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | Page* PageSet::FindPage(std::string name) |
| 976 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 977 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 978 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 979 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 980 | { |
| 981 | if (name == (*iter)->GetName()) |
| 982 | return (*iter); |
| 983 | } |
| 984 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | int PageSet::LoadVariables(xml_node<>* vars) |
| 988 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 989 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 990 | xml_attribute<> *name, *value, *persist; |
| 991 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 992 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 993 | child = vars->first_node("variable"); |
| 994 | while (child) |
| 995 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 996 | name = child->first_attribute("name"); |
| 997 | value = child->first_attribute("value"); |
| 998 | persist = child->first_attribute("persist"); |
| 999 | if(name && value) |
| 1000 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1001 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 1002 | tw_x_offset = atoi(value->value()); |
| 1003 | child = child->next_sibling("variable"); |
| 1004 | continue; |
| 1005 | } |
| 1006 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 1007 | tw_y_offset = atoi(value->value()); |
| 1008 | child = child->next_sibling("variable"); |
| 1009 | continue; |
| 1010 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1011 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 1012 | string temp = value->value(); |
| 1013 | string valstr = gui_parse_text(temp); |
| 1014 | |
| 1015 | if (valstr.find("+") != string::npos) { |
| 1016 | string val1str = valstr; |
| 1017 | val1str = val1str.substr(0, val1str.find('+')); |
| 1018 | string val2str = valstr; |
| 1019 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 1020 | int val1 = atoi(val1str.c_str()); |
| 1021 | int val2 = atoi(val2str.c_str()); |
| 1022 | int val = val1 + val2; |
| 1023 | |
| 1024 | DataManager::SetValue(name->value(), val, p); |
| 1025 | } else if (valstr.find("-") != string::npos) { |
| 1026 | string val1str = valstr; |
| 1027 | val1str = val1str.substr(0, val1str.find('-')); |
| 1028 | string val2str = valstr; |
| 1029 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 1030 | int val1 = atoi(val1str.c_str()); |
| 1031 | int val2 = atoi(val2str.c_str()); |
| 1032 | int val = val1 - val2; |
| 1033 | |
| 1034 | DataManager::SetValue(name->value(), val, p); |
| 1035 | } else { |
| 1036 | DataManager::SetValue(name->value(), valstr, p); |
| 1037 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1038 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1039 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1040 | child = child->next_sibling("variable"); |
| 1041 | } |
| 1042 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1045 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1046 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1047 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1048 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1049 | if (!pages) |
| 1050 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1051 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1052 | child = pages->first_node("page"); |
| 1053 | while (child != NULL) |
| 1054 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1055 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1056 | if (page->GetName().empty()) |
| 1057 | { |
| 1058 | LOGERR("Unable to process load page\n"); |
| 1059 | delete page; |
| 1060 | } |
| 1061 | else |
| 1062 | { |
| 1063 | mPages.push_back(page); |
| 1064 | } |
| 1065 | child = child->next_sibling("page"); |
| 1066 | } |
| 1067 | if (mPages.size() > 0) |
| 1068 | return 0; |
| 1069 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | int PageSet::IsCurrentPage(Page* page) |
| 1073 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1074 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | int PageSet::Render(void) |
| 1078 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1079 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1080 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1081 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1082 | if (ret < 0) |
| 1083 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1084 | |
| 1085 | std::vector<Page*>::iterator iter; |
| 1086 | |
| 1087 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1088 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1089 | if (ret < 0) |
| 1090 | return ret; |
| 1091 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1092 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | int PageSet::Update(void) |
| 1096 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1097 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1098 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1099 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1100 | if (ret < 0 || ret > 1) |
| 1101 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1102 | |
| 1103 | std::vector<Page*>::iterator iter; |
| 1104 | |
| 1105 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1106 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1107 | if (ret < 0) |
| 1108 | return ret; |
| 1109 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1110 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1114 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1115 | if (!mOverlays.empty()) |
| 1116 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1117 | |
| 1118 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1121 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1122 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1123 | if (!mOverlays.empty()) |
| 1124 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1125 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1126 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | int PageSet::NotifyKeyboard(int key) |
| 1130 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1131 | if (!mOverlays.empty()) |
| 1132 | return mOverlays.back()->NotifyKeyboard(key); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1133 | |
| 1134 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1138 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1139 | if (!mOverlays.empty()) |
| 1140 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1141 | |
| 1142 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1146 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1147 | std::vector<Page*>::iterator iter; |
| 1148 | |
| 1149 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1150 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1151 | |
| 1152 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1156 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1157 | int fd; |
| 1158 | ZipArchive zip, *pZip = NULL; |
| 1159 | long len; |
| 1160 | char* xmlFile = NULL; |
| 1161 | PageSet* pageSet = NULL; |
| 1162 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1163 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1164 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1165 | // Open the XML file |
| 1166 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1167 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1168 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1169 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1170 | tw_x_offset = TW_X_OFFSET; |
| 1171 | tw_y_offset = TW_Y_OFFSET; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1172 | // We can try to load the XML directly... |
| 1173 | struct stat st; |
| 1174 | if(stat(package.c_str(),&st) != 0) |
| 1175 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1176 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1177 | len = st.st_size; |
| 1178 | xmlFile = (char*) malloc(len + 1); |
| 1179 | if (!xmlFile) |
| 1180 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1181 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1182 | fd = open(package.c_str(), O_RDONLY); |
| 1183 | if (fd == -1) |
| 1184 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1185 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1186 | read(fd, xmlFile, len); |
| 1187 | close(fd); |
| 1188 | } |
| 1189 | else |
| 1190 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1191 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1192 | tw_x_offset = 0; |
| 1193 | tw_y_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1194 | if (!TWFunc::Path_Exists(package)) |
| 1195 | return -1; |
| 1196 | if (sysMapFile(package.c_str(), &map) != 0) { |
| 1197 | LOGERR("Failed to map '%s'\n", package.c_str()); |
| 1198 | return -1; |
| 1199 | } |
| 1200 | if (mzOpenZipArchive(map.addr, map.length, &zip)) { |
| 1201 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
| 1202 | sysReleaseMap(&map); |
| 1203 | return -1; |
| 1204 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1205 | pZip = &zip; |
| 1206 | const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); |
| 1207 | if (ui_xml == NULL) |
| 1208 | { |
| 1209 | LOGERR("Unable to locate ui.xml in zip file\n"); |
| 1210 | goto error; |
| 1211 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1212 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1213 | // Allocate the buffer for the file |
| 1214 | len = mzGetZipEntryUncompLen(ui_xml); |
| 1215 | xmlFile = (char*) malloc(len + 1); |
| 1216 | if (!xmlFile) |
| 1217 | goto error; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1218 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1219 | if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) |
| 1220 | { |
| 1221 | LOGERR("Unable to extract ui.xml\n"); |
| 1222 | goto error; |
| 1223 | } |
| 1224 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1225 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1226 | // NULL-terminate the string |
| 1227 | xmlFile[len] = 0x00; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1228 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1229 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 1230 | pageSet = mCurrentSet; |
| 1231 | mCurrentSet = new PageSet(xmlFile); |
| 1232 | |
| 1233 | ret = mCurrentSet->Load(pZip); |
| 1234 | if (ret == 0) |
| 1235 | { |
| 1236 | mCurrentSet->SetPage(startpage); |
| 1237 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
| 1238 | } |
| 1239 | else |
| 1240 | { |
| 1241 | LOGERR("Package %s failed to load.\n", name.c_str()); |
| 1242 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1243 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1244 | // The first successful package we loaded is the base |
| 1245 | if (mBaseSet == NULL) |
| 1246 | mBaseSet = mCurrentSet; |
| 1247 | |
| 1248 | mCurrentSet = pageSet; |
| 1249 | |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1250 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1251 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1252 | sysReleaseMap(&map); |
| 1253 | } |
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: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1257 | LOGERR("An internal error has occurred.\n"); |
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 | } |