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 | |
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 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 447 | else if (type == "template") |
| 448 | { |
| 449 | if (!templates || !child->first_attribute("name")) |
| 450 | { |
| 451 | LOGERR("Invalid template request.\n"); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | std::string name = child->first_attribute("name")->value(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 456 | xml_node<>* node; |
| 457 | bool node_found = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 458 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 459 | // We need to find the correct template |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 460 | for (std::vector<xml_node<>*>::iterator itr = templates->begin(); itr != templates->end(); itr++) { |
| 461 | node = (*itr)->first_node("template"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 462 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 463 | while (node) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 464 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 465 | if (!node->first_attribute("name")) |
| 466 | continue; |
| 467 | |
| 468 | if (name == node->first_attribute("name")->value()) |
| 469 | { |
| 470 | if (!ProcessNode(node, templates, depth + 1)) |
| 471 | return false; |
| 472 | else { |
| 473 | node_found = true; |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | if (node_found) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 478 | break; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 479 | node = node->next_sibling("template"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 480 | } |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 481 | // [check] why is there no if (node_found) here too? |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | } |
| 485 | else |
| 486 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 487 | LOGERR("Unknown object type: %s.\n", type.c_str()); |
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 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | int Page::Render(void) |
| 494 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 495 | // Render background |
| 496 | gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); |
| 497 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 498 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 499 | // Render remaining objects |
| 500 | std::vector<RenderObject*>::iterator iter; |
| 501 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 502 | { |
| 503 | if ((*iter)->Render()) |
| 504 | LOGERR("A render request has failed.\n"); |
| 505 | } |
| 506 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | int Page::Update(void) |
| 510 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 511 | int retCode = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 512 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 513 | std::vector<RenderObject*>::iterator iter; |
| 514 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 515 | { |
| 516 | int ret = (*iter)->Update(); |
| 517 | if (ret < 0) |
| 518 | LOGERR("An update request has failed.\n"); |
| 519 | else if (ret > retCode) |
| 520 | retCode = ret; |
| 521 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 522 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 523 | return retCode; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | int Page::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 527 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 528 | // By default, return 1 to ignore further touches if nobody is listening |
| 529 | int ret = 1; |
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 | // Don't try to handle a lack of handlers |
| 532 | if (mActions.size() == 0) |
| 533 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 534 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 535 | // We record mTouchStart so we can pass all the touch stream to the same handler |
| 536 | if (state == TOUCH_START) |
| 537 | { |
| 538 | std::vector<ActionObject*>::reverse_iterator iter; |
| 539 | // We work backwards, from top-most element to bottom-most element |
| 540 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 541 | { |
| 542 | if ((*iter)->IsInRegion(x, y)) |
| 543 | { |
| 544 | mTouchStart = (*iter); |
| 545 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 546 | if (ret >= 0) |
| 547 | break; |
| 548 | mTouchStart = NULL; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | else if (state == TOUCH_RELEASE && mTouchStart != NULL) |
| 553 | { |
| 554 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 555 | mTouchStart = NULL; |
| 556 | } |
| 557 | else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) |
| 558 | { |
| 559 | ret = mTouchStart->NotifyTouch(state, x, y); |
| 560 | } |
| 561 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 564 | int Page::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 565 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 566 | std::vector<ActionObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 567 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 568 | // Don't try to handle a lack of handlers |
| 569 | if (mActions.size() == 0) |
| 570 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 571 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 572 | int ret = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 573 | // We work backwards, from top-most element to bottom-most element |
| 574 | for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) |
| 575 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 576 | ret = (*iter)->NotifyKey(key, down); |
| 577 | if (ret < 0) { |
| 578 | LOGERR("An action handler has returned an error\n"); |
| 579 | ret = 1; |
| 580 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 581 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 582 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | int Page::NotifyKeyboard(int key) |
| 586 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 587 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 588 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 589 | // Don't try to handle a lack of handlers |
| 590 | if (mInputs.size() == 0) |
| 591 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 592 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 593 | // We work backwards, from top-most element to bottom-most element |
| 594 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 595 | { |
| 596 | int ret = (*iter)->NotifyKeyboard(key); |
| 597 | if (ret == 0) |
| 598 | return 0; |
| 599 | else if (ret < 0) |
| 600 | LOGERR("A keyboard handler has returned an error"); |
| 601 | } |
| 602 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | int Page::SetKeyBoardFocus(int inFocus) |
| 606 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 607 | std::vector<InputObject*>::reverse_iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 608 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 609 | // Don't try to handle a lack of handlers |
| 610 | if (mInputs.size() == 0) |
| 611 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 612 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 613 | // We work backwards, from top-most element to bottom-most element |
| 614 | for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) |
| 615 | { |
| 616 | int ret = (*iter)->SetInputFocus(inFocus); |
| 617 | if (ret == 0) |
| 618 | return 0; |
| 619 | else if (ret < 0) |
| 620 | LOGERR("An input focus handler has returned an error"); |
| 621 | } |
| 622 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | void Page::SetPageFocus(int inFocus) |
| 626 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 627 | // Render remaining objects |
| 628 | std::vector<RenderObject*>::iterator iter; |
| 629 | for (iter = mRenders.begin(); iter != mRenders.end(); iter++) |
| 630 | (*iter)->SetPageFocus(inFocus); |
| 631 | |
| 632 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | int Page::NotifyVarChange(std::string varName, std::string value) |
| 636 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 637 | std::vector<GUIObject*>::iterator iter; |
| 638 | for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 639 | { |
| 640 | if ((*iter)->NotifyVarChange(varName, value)) |
| 641 | LOGERR("An action handler errored on NotifyVarChange.\n"); |
| 642 | } |
| 643 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | PageSet::PageSet(char* xmlFile) |
| 647 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 648 | mResources = new ResourceManager; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 649 | mCurrentPage = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 650 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 651 | mXmlFile = xmlFile; |
| 652 | if (xmlFile) |
| 653 | mDoc.parse<0>(mXmlFile); |
| 654 | else |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 655 | mCurrentPage = new Page(NULL, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | PageSet::~PageSet() |
| 659 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 660 | mOverlays.clear(); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 661 | for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) |
| 662 | delete *itr; |
| 663 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 664 | delete mResources; |
| 665 | free(mXmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 666 | |
| 667 | mDoc.clear(); |
| 668 | |
| 669 | for (std::vector<xml_document<>*>::iterator itr = mIncludedDocs.begin(); itr != mIncludedDocs.end(); ++itr) { |
| 670 | (*itr)->clear(); |
| 671 | delete *itr; |
| 672 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | int PageSet::Load(ZipArchive* package) |
| 676 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 677 | xml_node<>* parent; |
| 678 | xml_node<>* child; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 679 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 680 | xml_node<>* xmlstyle; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 681 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 682 | parent = mDoc.first_node("recovery"); |
| 683 | if (!parent) |
| 684 | parent = mDoc.first_node("install"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 685 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 686 | set_scale_values(1, 1); // Reset any previous scaling values |
| 687 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 688 | // Now, let's parse the XML |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 689 | LOGINFO("Checking resolution...\n"); |
| 690 | child = parent->first_node("details"); |
| 691 | if (child) { |
| 692 | xml_node<>* resolution = child->first_node("resolution"); |
| 693 | if (resolution) { |
| 694 | xml_attribute<>* width_attr = resolution->first_attribute("width"); |
| 695 | xml_attribute<>* height_attr = resolution->first_attribute("height"); |
| 696 | xml_attribute<>* noscale_attr = resolution->first_attribute("noscaling"); |
| 697 | if (width_attr && height_attr && !noscale_attr) { |
| 698 | int width = atoi(width_attr->value()); |
| 699 | int height = atoi(height_attr->value()); |
| 700 | int offx = 0, offy = 0; |
| 701 | #ifdef TW_ROUND_SCREEN |
| 702 | xml_node<>* roundscreen = child->first_node("roundscreen"); |
| 703 | if (roundscreen) { |
| 704 | LOGINFO("TW_ROUND_SCREEN := true, using round screen XML settings.\n"); |
| 705 | xml_attribute<>* offx_attr = roundscreen->first_attribute("offset_x"); |
| 706 | xml_attribute<>* offy_attr = roundscreen->first_attribute("offset_y"); |
| 707 | if (offx_attr) { |
| 708 | offx = atoi(offx_attr->value()); |
| 709 | } |
| 710 | if (offy_attr) { |
| 711 | offy = atoi(offy_attr->value()); |
| 712 | } |
| 713 | } |
| 714 | #endif |
| 715 | if (width != 0 && height != 0) { |
| 716 | float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width; |
| 717 | float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height; |
| 718 | #ifdef TW_ROUND_SCREEN |
| 719 | float scale_off_w = (float)gr_fb_width() / (float)width; |
| 720 | float scale_off_h = (float)gr_fb_height() / (float)height; |
| 721 | tw_x_offset = offx * scale_off_w; |
| 722 | tw_y_offset = offy * scale_off_h; |
| 723 | #endif |
| 724 | if (scale_w != 1 || scale_h != 1) { |
| 725 | LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset); |
| 726 | set_scale_values(scale_w, scale_h); |
| 727 | } |
| 728 | } |
| 729 | } else { |
| 730 | LOGINFO("XML does not contain width and height, no scaling will be applied\n"); |
| 731 | } |
| 732 | } else { |
| 733 | LOGINFO("XML contains no resolution tag, no scaling will be applied.\n"); |
| 734 | } |
| 735 | } else { |
| 736 | LOGINFO("XML contains no details tag, no scaling will be applied.\n"); |
| 737 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 738 | LOGINFO("Loading resources...\n"); |
| 739 | child = parent->first_node("resources"); |
| 740 | if (child) |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 741 | mResources->LoadResources(child, package); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 742 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 743 | LOGINFO("Loading variables...\n"); |
| 744 | child = parent->first_node("variables"); |
| 745 | if (child) |
| 746 | LoadVariables(child); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 747 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 748 | LOGINFO("Loading mouse cursor...\n"); |
| 749 | child = parent->first_node("mousecursor"); |
| 750 | if(child) |
| 751 | PageManager::LoadCursorData(child); |
| 752 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 753 | LOGINFO("Loading pages...\n"); |
| 754 | // This may be NULL if no templates are present |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 755 | xmltemplate = parent->first_node("templates"); |
| 756 | if (xmltemplate) |
| 757 | templates.push_back(xmltemplate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 758 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 759 | // Load styles if present |
| 760 | xmlstyle = parent->first_node("styles"); |
| 761 | if (xmlstyle) |
| 762 | styles.push_back(xmlstyle); |
| 763 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 764 | child = parent->first_node("pages"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 765 | if (child) { |
| 766 | if (LoadPages(child)) { |
| 767 | LOGERR("PageSet::Load returning -1\n"); |
| 768 | return -1; |
| 769 | } |
| 770 | } |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 771 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 772 | return CheckInclude(package, &mDoc); |
| 773 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 774 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 775 | int PageSet::CheckInclude(ZipArchive* package, xml_document<> *parentDoc) |
| 776 | { |
| 777 | xml_node<>* par; |
| 778 | xml_node<>* par2; |
| 779 | xml_node<>* chld; |
| 780 | xml_node<>* parent; |
| 781 | xml_node<>* child; |
| 782 | xml_node<>* xmltemplate; |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 783 | xml_node<>* xmlstyle; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 784 | long len; |
| 785 | char* xmlFile = NULL; |
| 786 | string filename; |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 787 | xml_document<> *doc = NULL; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 788 | |
| 789 | par = parentDoc->first_node("recovery"); |
| 790 | if (!par) { |
| 791 | par = parentDoc->first_node("install"); |
| 792 | } |
| 793 | if (!par) { |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | par2 = par->first_node("include"); |
| 798 | if (!par2) |
| 799 | return 0; |
| 800 | chld = par2->first_node("xmlfile"); |
| 801 | while (chld != NULL) { |
| 802 | xml_attribute<>* attr = chld->first_attribute("name"); |
| 803 | if (!attr) |
| 804 | break; |
| 805 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 806 | if (!package) { |
| 807 | // We can try to load the XML directly... |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 808 | filename = TWRES; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 809 | filename += attr->value(); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 810 | LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str()); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 811 | struct stat st; |
| 812 | if(stat(filename.c_str(),&st) != 0) { |
| 813 | LOGERR("Unable to locate '%s'\n", filename.c_str()); |
| 814 | return -1; |
| 815 | } |
| 816 | |
| 817 | len = st.st_size; |
| 818 | xmlFile = (char*) malloc(len + 1); |
| 819 | if (!xmlFile) |
| 820 | return -1; |
| 821 | |
| 822 | int fd = open(filename.c_str(), O_RDONLY); |
| 823 | if (fd == -1) |
| 824 | return -1; |
| 825 | |
| 826 | read(fd, xmlFile, len); |
| 827 | close(fd); |
| 828 | } else { |
| 829 | filename += attr->value(); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 830 | LOGINFO("PageSet::CheckInclude loading filename: '%s'\n", filename.c_str()); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 831 | const ZipEntry* ui_xml = mzFindZipEntry(package, filename.c_str()); |
| 832 | if (ui_xml == NULL) |
| 833 | { |
| 834 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 835 | return -1; |
| 836 | } |
| 837 | |
| 838 | // Allocate the buffer for the file |
| 839 | len = mzGetZipEntryUncompLen(ui_xml); |
| 840 | xmlFile = (char*) malloc(len + 1); |
| 841 | if (!xmlFile) |
| 842 | return -1; |
| 843 | |
| 844 | if (!mzExtractZipEntryToBuffer(package, ui_xml, (unsigned char*) xmlFile)) |
| 845 | { |
| 846 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 847 | return -1; |
| 848 | } |
| 849 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 850 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 851 | xmlFile[len] = '\0'; |
| 852 | doc = new xml_document<>(); |
| 853 | doc->parse<0>(xmlFile); |
| 854 | |
| 855 | parent = doc->first_node("recovery"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 856 | if (!parent) |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 857 | parent = doc->first_node("install"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 858 | |
| 859 | // Now, let's parse the XML |
| 860 | LOGINFO("Loading included resources...\n"); |
| 861 | child = parent->first_node("resources"); |
| 862 | if (child) |
| 863 | mResources->LoadResources(child, package); |
| 864 | |
| 865 | LOGINFO("Loading included variables...\n"); |
| 866 | child = parent->first_node("variables"); |
| 867 | if (child) |
| 868 | LoadVariables(child); |
| 869 | |
| 870 | LOGINFO("Loading mouse cursor...\n"); |
| 871 | child = parent->first_node("mousecursor"); |
| 872 | if(child) |
| 873 | PageManager::LoadCursorData(child); |
| 874 | |
| 875 | LOGINFO("Loading included pages...\n"); |
| 876 | // This may be NULL if no templates are present |
| 877 | xmltemplate = parent->first_node("templates"); |
| 878 | if (xmltemplate) |
| 879 | templates.push_back(xmltemplate); |
| 880 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 881 | // Load styles if present |
| 882 | xmlstyle = parent->first_node("styles"); |
| 883 | if (xmlstyle) |
| 884 | styles.push_back(xmlstyle); |
| 885 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 886 | child = parent->first_node("pages"); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 887 | if (child && LoadPages(child)) |
| 888 | { |
| 889 | templates.pop_back(); |
| 890 | doc->clear(); |
| 891 | delete doc; |
| 892 | return -1; |
| 893 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 894 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 895 | mIncludedDocs.push_back(doc); |
| 896 | |
| 897 | if (CheckInclude(package, doc)) |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 898 | return -1; |
| 899 | |
| 900 | chld = chld->next_sibling("xmlfile"); |
| 901 | } |
| 902 | |
| 903 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | int PageSet::SetPage(std::string page) |
| 907 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 908 | Page* tmp = FindPage(page); |
| 909 | if (tmp) |
| 910 | { |
| 911 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 912 | mCurrentPage = tmp; |
| 913 | mCurrentPage->SetPageFocus(1); |
| 914 | mCurrentPage->NotifyVarChange("", ""); |
| 915 | return 0; |
| 916 | } |
| 917 | else |
| 918 | { |
| 919 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 920 | } |
| 921 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | int PageSet::SetOverlay(Page* page) |
| 925 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 926 | if (page) { |
| 927 | if (mOverlays.size() >= 10) { |
| 928 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 929 | return -1; |
| 930 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 931 | |
| 932 | std::vector<Page*>::iterator iter; |
| 933 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 934 | if ((*iter)->GetName() == page->GetName()) { |
| 935 | mOverlays.erase(iter); |
| 936 | // SetOverlay() is (and should stay) the only function which |
| 937 | // adds to mOverlays. Then, each page can appear at most once. |
| 938 | break; |
| 939 | } |
| 940 | } |
| 941 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 942 | page->SetPageFocus(1); |
| 943 | page->NotifyVarChange("", ""); |
| 944 | |
| 945 | if (!mOverlays.empty()) |
| 946 | mOverlays.back()->SetPageFocus(0); |
| 947 | |
| 948 | mOverlays.push_back(page); |
| 949 | } else { |
| 950 | if (!mOverlays.empty()) { |
| 951 | mOverlays.back()->SetPageFocus(0); |
| 952 | mOverlays.pop_back(); |
| 953 | if (!mOverlays.empty()) |
| 954 | mOverlays.back()->SetPageFocus(1); |
| 955 | else if (mCurrentPage) |
| 956 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 957 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 958 | } |
| 959 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 960 | } |
| 961 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 962 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 963 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 964 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | Page* PageSet::FindPage(std::string name) |
| 968 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 969 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 970 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 971 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 972 | { |
| 973 | if (name == (*iter)->GetName()) |
| 974 | return (*iter); |
| 975 | } |
| 976 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | int PageSet::LoadVariables(xml_node<>* vars) |
| 980 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 981 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 982 | xml_attribute<> *name, *value, *persist; |
| 983 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 984 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 985 | child = vars->first_node("variable"); |
| 986 | while (child) |
| 987 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 988 | name = child->first_attribute("name"); |
| 989 | value = child->first_attribute("value"); |
| 990 | persist = child->first_attribute("persist"); |
| 991 | if(name && value) |
| 992 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 993 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 994 | tw_x_offset = atoi(value->value()); |
| 995 | child = child->next_sibling("variable"); |
| 996 | continue; |
| 997 | } |
| 998 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 999 | tw_y_offset = atoi(value->value()); |
| 1000 | child = child->next_sibling("variable"); |
| 1001 | continue; |
| 1002 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1003 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 1004 | string temp = value->value(); |
| 1005 | string valstr = gui_parse_text(temp); |
| 1006 | |
| 1007 | if (valstr.find("+") != string::npos) { |
| 1008 | string val1str = valstr; |
| 1009 | val1str = val1str.substr(0, val1str.find('+')); |
| 1010 | string val2str = valstr; |
| 1011 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 1012 | int val1 = atoi(val1str.c_str()); |
| 1013 | int val2 = atoi(val2str.c_str()); |
| 1014 | int val = val1 + val2; |
| 1015 | |
| 1016 | DataManager::SetValue(name->value(), val, p); |
| 1017 | } else if (valstr.find("-") != string::npos) { |
| 1018 | string val1str = valstr; |
| 1019 | val1str = val1str.substr(0, val1str.find('-')); |
| 1020 | string val2str = valstr; |
| 1021 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 1022 | int val1 = atoi(val1str.c_str()); |
| 1023 | int val2 = atoi(val2str.c_str()); |
| 1024 | int val = val1 - val2; |
| 1025 | |
| 1026 | DataManager::SetValue(name->value(), val, p); |
| 1027 | } else { |
| 1028 | DataManager::SetValue(name->value(), valstr, p); |
| 1029 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1030 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1031 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1032 | child = child->next_sibling("variable"); |
| 1033 | } |
| 1034 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1037 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1038 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1039 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1040 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1041 | if (!pages) |
| 1042 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1043 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1044 | child = pages->first_node("page"); |
| 1045 | while (child != NULL) |
| 1046 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1047 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1048 | if (page->GetName().empty()) |
| 1049 | { |
| 1050 | LOGERR("Unable to process load page\n"); |
| 1051 | delete page; |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | mPages.push_back(page); |
| 1056 | } |
| 1057 | child = child->next_sibling("page"); |
| 1058 | } |
| 1059 | if (mPages.size() > 0) |
| 1060 | return 0; |
| 1061 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | int PageSet::IsCurrentPage(Page* page) |
| 1065 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1066 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | int PageSet::Render(void) |
| 1070 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1071 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1072 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1073 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1074 | if (ret < 0) |
| 1075 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1076 | |
| 1077 | std::vector<Page*>::iterator iter; |
| 1078 | |
| 1079 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1080 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1081 | if (ret < 0) |
| 1082 | return ret; |
| 1083 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1084 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | int PageSet::Update(void) |
| 1088 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1089 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1090 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1091 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1092 | if (ret < 0 || ret > 1) |
| 1093 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1094 | |
| 1095 | std::vector<Page*>::iterator iter; |
| 1096 | |
| 1097 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1098 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1099 | if (ret < 0) |
| 1100 | return ret; |
| 1101 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1102 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1106 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1107 | if (!mOverlays.empty()) |
| 1108 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1109 | |
| 1110 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1113 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1114 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1115 | if (!mOverlays.empty()) |
| 1116 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1117 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1118 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | int PageSet::NotifyKeyboard(int key) |
| 1122 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1123 | if (!mOverlays.empty()) |
| 1124 | return mOverlays.back()->NotifyKeyboard(key); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1125 | |
| 1126 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1130 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1131 | if (!mOverlays.empty()) |
| 1132 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1133 | |
| 1134 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1138 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1139 | std::vector<Page*>::iterator iter; |
| 1140 | |
| 1141 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1142 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1143 | |
| 1144 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1148 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1149 | int fd; |
| 1150 | ZipArchive zip, *pZip = NULL; |
| 1151 | long len; |
| 1152 | char* xmlFile = NULL; |
| 1153 | PageSet* pageSet = NULL; |
| 1154 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1155 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1156 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1157 | // Open the XML file |
| 1158 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1159 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1160 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1161 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1162 | tw_x_offset = TW_X_OFFSET; |
| 1163 | tw_y_offset = TW_Y_OFFSET; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1164 | // We can try to load the XML directly... |
| 1165 | struct stat st; |
| 1166 | if(stat(package.c_str(),&st) != 0) |
| 1167 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1168 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1169 | len = st.st_size; |
| 1170 | xmlFile = (char*) malloc(len + 1); |
| 1171 | if (!xmlFile) |
| 1172 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1173 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1174 | fd = open(package.c_str(), O_RDONLY); |
| 1175 | if (fd == -1) |
| 1176 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1177 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1178 | read(fd, xmlFile, len); |
| 1179 | close(fd); |
| 1180 | } |
| 1181 | else |
| 1182 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1183 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1184 | tw_x_offset = 0; |
| 1185 | tw_y_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1186 | if (!TWFunc::Path_Exists(package)) |
| 1187 | return -1; |
| 1188 | if (sysMapFile(package.c_str(), &map) != 0) { |
| 1189 | LOGERR("Failed to map '%s'\n", package.c_str()); |
| 1190 | return -1; |
| 1191 | } |
| 1192 | if (mzOpenZipArchive(map.addr, map.length, &zip)) { |
| 1193 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
| 1194 | sysReleaseMap(&map); |
| 1195 | return -1; |
| 1196 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1197 | pZip = &zip; |
| 1198 | const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); |
| 1199 | if (ui_xml == NULL) |
| 1200 | { |
| 1201 | LOGERR("Unable to locate ui.xml in zip file\n"); |
| 1202 | goto error; |
| 1203 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1204 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1205 | // Allocate the buffer for the file |
| 1206 | len = mzGetZipEntryUncompLen(ui_xml); |
| 1207 | xmlFile = (char*) malloc(len + 1); |
| 1208 | if (!xmlFile) |
| 1209 | goto error; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1210 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1211 | if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) |
| 1212 | { |
| 1213 | LOGERR("Unable to extract ui.xml\n"); |
| 1214 | goto error; |
| 1215 | } |
| 1216 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1217 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1218 | // NULL-terminate the string |
| 1219 | xmlFile[len] = 0x00; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1220 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1221 | // Before loading, mCurrentSet must be the loading package so we can find resources |
| 1222 | pageSet = mCurrentSet; |
| 1223 | mCurrentSet = new PageSet(xmlFile); |
| 1224 | |
| 1225 | ret = mCurrentSet->Load(pZip); |
| 1226 | if (ret == 0) |
| 1227 | { |
| 1228 | mCurrentSet->SetPage(startpage); |
| 1229 | mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); |
| 1230 | } |
| 1231 | else |
| 1232 | { |
| 1233 | LOGERR("Package %s failed to load.\n", name.c_str()); |
| 1234 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 1235 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1236 | // The first successful package we loaded is the base |
| 1237 | if (mBaseSet == NULL) |
| 1238 | mBaseSet = mCurrentSet; |
| 1239 | |
| 1240 | mCurrentSet = pageSet; |
| 1241 | |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1242 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1243 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1244 | sysReleaseMap(&map); |
| 1245 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1246 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1247 | |
| 1248 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1249 | LOGERR("An internal error has occurred.\n"); |
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 | if (xmlFile) |
| 1255 | free(xmlFile); |
| 1256 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | PageSet* PageManager::FindPackage(std::string name) |
| 1260 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1261 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1262 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1263 | iter = mPageSets.find(name); |
| 1264 | if (iter != mPageSets.end()) |
| 1265 | return (*iter).second; |
| 1266 | |
| 1267 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1268 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | PageSet* PageManager::SelectPackage(std::string name) |
| 1272 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1273 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1274 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1275 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1276 | tmp = FindPackage(name); |
| 1277 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1278 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1279 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1280 | mCurrentSet->NotifyVarChange("", ""); |
| 1281 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1282 | else |
| 1283 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1284 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1285 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1289 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1290 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1291 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1292 | iter = mPageSets.find(name); |
| 1293 | if (iter == mPageSets.end()) |
| 1294 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1295 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1296 | if(mMouseCursor) |
| 1297 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1298 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1299 | PageSet* set = (*iter).second; |
| 1300 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1301 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1302 | if (LoadPackage(name, package, "main") != 0) |
| 1303 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 1304 | LOGERR("Failed to load package '%s'.\n", package.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1305 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1306 | return -1; |
| 1307 | } |
| 1308 | if (mCurrentSet == set) |
| 1309 | SelectPackage(name); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 1310 | if (mBaseSet == set) |
| 1311 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1312 | delete set; |
| 1313 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | void PageManager::ReleasePackage(std::string name) |
| 1317 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1318 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1319 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1320 | iter = mPageSets.find(name); |
| 1321 | if (iter == mPageSets.end()) |
| 1322 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1323 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1324 | PageSet* set = (*iter).second; |
| 1325 | mPageSets.erase(iter); |
| 1326 | delete set; |
| 1327 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | int PageManager::ChangePage(std::string name) |
| 1331 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1332 | DataManager::SetValue("tw_operation_state", 0); |
| 1333 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1334 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | int PageManager::ChangeOverlay(std::string name) |
| 1338 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1339 | if (name.empty()) |
| 1340 | return mCurrentSet->SetOverlay(NULL); |
| 1341 | else |
| 1342 | { |
| 1343 | Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; |
| 1344 | return mCurrentSet->SetOverlay(page); |
| 1345 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1348 | const ResourceManager* PageManager::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1349 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1350 | return (mCurrentSet ? mCurrentSet->GetResources() : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | int PageManager::SwitchToConsole(void) |
| 1354 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1355 | PageSet* console = new PageSet(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1356 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1357 | mCurrentSet = console; |
| 1358 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 1361 | int PageManager::EndConsole(void) |
| 1362 | { |
| 1363 | if (mCurrentSet && mBaseSet) { |
| 1364 | delete mCurrentSet; |
| 1365 | mCurrentSet = mBaseSet; |
| 1366 | return 0; |
| 1367 | } |
| 1368 | return -1; |
| 1369 | } |
| 1370 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1371 | int PageManager::IsCurrentPage(Page* page) |
| 1372 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1373 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | int PageManager::Render(void) |
| 1377 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1378 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 1379 | if(mMouseCursor) |
| 1380 | mMouseCursor->Render(); |
| 1381 | return res; |
| 1382 | } |
| 1383 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1384 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1385 | { |
| 1386 | if(!mHardwareKeyboard) |
| 1387 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1388 | return mHardwareKeyboard; |
| 1389 | } |
| 1390 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1391 | xml_node<>* PageManager::FindStyle(std::string name) |
| 1392 | { |
| 1393 | for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) { |
| 1394 | xml_node<>* node = (*itr)->first_node("style"); |
| 1395 | |
| 1396 | while (node) { |
| 1397 | if (!node->first_attribute("name")) |
| 1398 | continue; |
| 1399 | |
| 1400 | if (name == node->first_attribute("name")->value()) |
| 1401 | return node; |
| 1402 | node = node->next_sibling("style"); |
| 1403 | } |
| 1404 | } |
| 1405 | return NULL; |
| 1406 | } |
| 1407 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1408 | MouseCursor *PageManager::GetMouseCursor() |
| 1409 | { |
| 1410 | if(!mMouseCursor) |
| 1411 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1412 | return mMouseCursor; |
| 1413 | } |
| 1414 | |
| 1415 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1416 | { |
| 1417 | if(!mMouseCursor) |
| 1418 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1419 | |
| 1420 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | int PageManager::Update(void) |
| 1424 | { |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 1425 | if(blankTimer.isScreenOff()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1426 | return 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1427 | |
| 1428 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1429 | |
| 1430 | if(mMouseCursor) |
| 1431 | { |
| 1432 | int c_res = mMouseCursor->Update(); |
| 1433 | if(c_res > res) |
| 1434 | res = c_res; |
| 1435 | } |
| 1436 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1440 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1441 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1442 | } |
| 1443 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1444 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1445 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1446 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | int PageManager::NotifyKeyboard(int key) |
| 1450 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1451 | return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1455 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1456 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1460 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1461 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1465 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1466 | if (!gGuiRunning) |
| 1467 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1468 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1469 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1470 | } |