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 | |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 232 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, Placement* placement /* = NULL */) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 234 | if (!node) |
| 235 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 236 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | if (node->first_attribute("x")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 238 | *x = LoadAttrIntScaleX(node, "x") + tw_x_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 239 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 240 | if (node->first_attribute("y")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 241 | *y = LoadAttrIntScaleY(node, "y") + tw_y_offset; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 242 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 243 | if (w && node->first_attribute("w")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 244 | *w = LoadAttrIntScaleX(node, "w"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 245 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 246 | if (h && node->first_attribute("h")) |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 247 | *h = LoadAttrIntScaleY(node, "h"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 248 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 249 | if (placement && node->first_attribute("placement")) |
Ethan Yonker | b7a54a3 | 2015-10-05 10:16:27 -0500 | [diff] [blame] | 250 | *placement = (Placement) LoadAttrInt(node, "placement"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | int ActionObject::SetActionPos(int x, int y, int w, int h) |
| 256 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 257 | if (x < 0 || y < 0) |
| 258 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 259 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 260 | mActionX = x; |
| 261 | mActionY = y; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 262 | if (w || h) |
| 263 | { |
| 264 | mActionW = w; |
| 265 | mActionH = h; |
| 266 | } |
| 267 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 268 | } |
| 269 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 270 | Page::Page(xml_node<>* page, std::vector<xml_node<>*> *templates) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 272 | mTouchStart = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 273 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 274 | // We can memset the whole structure, because the alpha channel is ignored |
| 275 | memset(&mBackground, 0, sizeof(COLOR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 276 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 277 | // With NULL, we make a console-only display |
| 278 | if (!page) |
| 279 | { |
| 280 | mName = "console"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 281 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 282 | GUIConsole* element = new GUIConsole(NULL); |
| 283 | mRenders.push_back(element); |
| 284 | mActions.push_back(element); |
| 285 | return; |
| 286 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 287 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 288 | if (page->first_attribute("name")) |
| 289 | mName = page->first_attribute("name")->value(); |
| 290 | else |
| 291 | { |
| 292 | LOGERR("No page name attribute found!\n"); |
| 293 | return; |
| 294 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 295 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 296 | LOGINFO("Loading page %s\n", mName.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 297 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 298 | // This is a recursive routine for template handling |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 299 | ProcessNode(page, templates, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 302 | Page::~Page() |
| 303 | { |
| 304 | for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr) |
| 305 | delete *itr; |
| 306 | } |
| 307 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 308 | bool Page::ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 309 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 310 | if (depth == 10) |
| 311 | { |
| 312 | LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); |
| 313 | return false; |
| 314 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 315 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 316 | for (xml_node<>* child = page->first_node(); child; child = child->next_sibling()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 317 | { |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 318 | std::string type = child->name(); |
| 319 | |
| 320 | if (type == "background") { |
| 321 | mBackground = LoadAttrColor(child, "color", COLOR(0,0,0,0)); |
| 322 | continue; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 323 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 324 | |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 325 | if (type == "object") { |
| 326 | // legacy format : <object type="..."> |
| 327 | xml_attribute<>* attr = child->first_attribute("type"); |
| 328 | type = attr ? attr->value() : "*unspecified*"; |
| 329 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 330 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 331 | if (type == "text") |
| 332 | { |
| 333 | GUIText* element = new GUIText(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 334 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 335 | mRenders.push_back(element); |
| 336 | mActions.push_back(element); |
| 337 | } |
| 338 | else if (type == "image") |
| 339 | { |
| 340 | GUIImage* element = new GUIImage(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 341 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 342 | mRenders.push_back(element); |
| 343 | } |
| 344 | else if (type == "fill") |
| 345 | { |
| 346 | GUIFill* element = new GUIFill(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 347 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 348 | mRenders.push_back(element); |
| 349 | } |
| 350 | else if (type == "action") |
| 351 | { |
| 352 | GUIAction* element = new GUIAction(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 353 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 354 | mActions.push_back(element); |
| 355 | } |
| 356 | else if (type == "console") |
| 357 | { |
| 358 | GUIConsole* element = new GUIConsole(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 359 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 360 | mRenders.push_back(element); |
| 361 | mActions.push_back(element); |
| 362 | } |
| 363 | else if (type == "button") |
| 364 | { |
| 365 | GUIButton* element = new GUIButton(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 366 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | mRenders.push_back(element); |
| 368 | mActions.push_back(element); |
| 369 | } |
| 370 | else if (type == "checkbox") |
| 371 | { |
| 372 | GUICheckbox* element = new GUICheckbox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 373 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 374 | mRenders.push_back(element); |
| 375 | mActions.push_back(element); |
| 376 | } |
| 377 | else if (type == "fileselector") |
| 378 | { |
| 379 | GUIFileSelector* element = new GUIFileSelector(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 380 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 381 | mRenders.push_back(element); |
| 382 | mActions.push_back(element); |
| 383 | } |
| 384 | else if (type == "animation") |
| 385 | { |
| 386 | GUIAnimation* element = new GUIAnimation(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 387 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 388 | mRenders.push_back(element); |
| 389 | } |
| 390 | else if (type == "progressbar") |
| 391 | { |
| 392 | GUIProgressBar* element = new GUIProgressBar(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 393 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 394 | mRenders.push_back(element); |
| 395 | mActions.push_back(element); |
| 396 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 397 | else if (type == "slider") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 398 | { |
| 399 | GUISlider* element = new GUISlider(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 400 | mObjects.push_back(element); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 401 | mRenders.push_back(element); |
| 402 | mActions.push_back(element); |
| 403 | } |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 404 | else if (type == "slidervalue") |
| 405 | { |
| 406 | GUISliderValue *element = new GUISliderValue(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 407 | mObjects.push_back(element); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 408 | mRenders.push_back(element); |
| 409 | mActions.push_back(element); |
| 410 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 411 | else if (type == "listbox") |
| 412 | { |
| 413 | GUIListBox* element = new GUIListBox(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 414 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 415 | mRenders.push_back(element); |
| 416 | mActions.push_back(element); |
| 417 | } |
| 418 | else if (type == "keyboard") |
| 419 | { |
| 420 | GUIKeyboard* element = new GUIKeyboard(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 421 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 422 | mRenders.push_back(element); |
| 423 | mActions.push_back(element); |
| 424 | } |
| 425 | else if (type == "input") |
| 426 | { |
| 427 | GUIInput* element = new GUIInput(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 428 | mObjects.push_back(element); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 429 | mRenders.push_back(element); |
| 430 | mActions.push_back(element); |
| 431 | mInputs.push_back(element); |
| 432 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 433 | else if (type == "partitionlist") |
| 434 | { |
| 435 | GUIPartitionList* element = new GUIPartitionList(child); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 436 | mObjects.push_back(element); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 437 | mRenders.push_back(element); |
| 438 | mActions.push_back(element); |
| 439 | } |
Vojtech Bocek | 7e11ac5 | 2015-03-05 23:21:49 +0100 | [diff] [blame] | 440 | else if (type == "patternpassword") |
| 441 | { |
| 442 | GUIPatternPassword* element = new GUIPatternPassword(child); |
| 443 | mObjects.push_back(element); |
| 444 | mRenders.push_back(element); |
| 445 | mActions.push_back(element); |
| 446 | } |
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(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 810 | } else { |
| 811 | filename += attr->value(); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 812 | } |
| 813 | xmlFile = PageManager::LoadFileToBuffer(filename, package); |
| 814 | if (xmlFile == NULL) { |
| 815 | LOGERR("PageSet::CheckInclude unable to load '%s'\n", filename.c_str()); |
| 816 | return -1; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 817 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 818 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 819 | doc = new xml_document<>(); |
| 820 | doc->parse<0>(xmlFile); |
| 821 | |
| 822 | parent = doc->first_node("recovery"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 823 | if (!parent) |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 824 | parent = doc->first_node("install"); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 825 | |
| 826 | // Now, let's parse the XML |
| 827 | LOGINFO("Loading included resources...\n"); |
| 828 | child = parent->first_node("resources"); |
| 829 | if (child) |
| 830 | mResources->LoadResources(child, package); |
| 831 | |
| 832 | LOGINFO("Loading included variables...\n"); |
| 833 | child = parent->first_node("variables"); |
| 834 | if (child) |
| 835 | LoadVariables(child); |
| 836 | |
| 837 | LOGINFO("Loading mouse cursor...\n"); |
| 838 | child = parent->first_node("mousecursor"); |
| 839 | if(child) |
| 840 | PageManager::LoadCursorData(child); |
| 841 | |
| 842 | LOGINFO("Loading included pages...\n"); |
| 843 | // This may be NULL if no templates are present |
| 844 | xmltemplate = parent->first_node("templates"); |
| 845 | if (xmltemplate) |
| 846 | templates.push_back(xmltemplate); |
| 847 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 848 | // Load styles if present |
| 849 | xmlstyle = parent->first_node("styles"); |
| 850 | if (xmlstyle) |
| 851 | styles.push_back(xmlstyle); |
| 852 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 853 | child = parent->first_node("pages"); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 854 | if (child && LoadPages(child)) |
| 855 | { |
| 856 | templates.pop_back(); |
| 857 | doc->clear(); |
| 858 | delete doc; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 859 | free(xmlFile); |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 860 | return -1; |
| 861 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 862 | |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 863 | mIncludedDocs.push_back(doc); |
| 864 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 865 | if (CheckInclude(package, doc)) { |
| 866 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 867 | return -1; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 868 | } |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 869 | |
| 870 | chld = chld->next_sibling("xmlfile"); |
| 871 | } |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 872 | if (xmlFile) |
| 873 | free(xmlFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 874 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | int PageSet::SetPage(std::string page) |
| 878 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 879 | Page* tmp = FindPage(page); |
| 880 | if (tmp) |
| 881 | { |
| 882 | if (mCurrentPage) mCurrentPage->SetPageFocus(0); |
| 883 | mCurrentPage = tmp; |
| 884 | mCurrentPage->SetPageFocus(1); |
| 885 | mCurrentPage->NotifyVarChange("", ""); |
| 886 | return 0; |
| 887 | } |
| 888 | else |
| 889 | { |
| 890 | LOGERR("Unable to locate page (%s)\n", page.c_str()); |
| 891 | } |
| 892 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | int PageSet::SetOverlay(Page* page) |
| 896 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 897 | if (page) { |
| 898 | if (mOverlays.size() >= 10) { |
| 899 | LOGERR("Too many overlays requested, max is 10.\n"); |
| 900 | return -1; |
| 901 | } |
Matt Mower | d411f8d | 2015-04-09 16:04:12 -0500 | [diff] [blame] | 902 | |
| 903 | std::vector<Page*>::iterator iter; |
| 904 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 905 | if ((*iter)->GetName() == page->GetName()) { |
| 906 | mOverlays.erase(iter); |
| 907 | // SetOverlay() is (and should stay) the only function which |
| 908 | // adds to mOverlays. Then, each page can appear at most once. |
| 909 | break; |
| 910 | } |
| 911 | } |
| 912 | |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 913 | page->SetPageFocus(1); |
| 914 | page->NotifyVarChange("", ""); |
| 915 | |
| 916 | if (!mOverlays.empty()) |
| 917 | mOverlays.back()->SetPageFocus(0); |
| 918 | |
| 919 | mOverlays.push_back(page); |
| 920 | } else { |
| 921 | if (!mOverlays.empty()) { |
| 922 | mOverlays.back()->SetPageFocus(0); |
| 923 | mOverlays.pop_back(); |
| 924 | if (!mOverlays.empty()) |
| 925 | mOverlays.back()->SetPageFocus(1); |
| 926 | else if (mCurrentPage) |
| 927 | mCurrentPage->SetPageFocus(1); // Just in case somehow the regular page lost focus, we'll set it again |
| 928 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 929 | } |
| 930 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 931 | } |
| 932 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 933 | const ResourceManager* PageSet::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 934 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 935 | return mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | Page* PageSet::FindPage(std::string name) |
| 939 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 940 | std::vector<Page*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 941 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 942 | for (iter = mPages.begin(); iter != mPages.end(); iter++) |
| 943 | { |
| 944 | if (name == (*iter)->GetName()) |
| 945 | return (*iter); |
| 946 | } |
| 947 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | int PageSet::LoadVariables(xml_node<>* vars) |
| 951 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 952 | xml_node<>* child; |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 953 | xml_attribute<> *name, *value, *persist; |
| 954 | int p; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 955 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 956 | child = vars->first_node("variable"); |
| 957 | while (child) |
| 958 | { |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 959 | name = child->first_attribute("name"); |
| 960 | value = child->first_attribute("value"); |
| 961 | persist = child->first_attribute("persist"); |
| 962 | if(name && value) |
| 963 | { |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 964 | if (strcmp(name->value(), "tw_x_offset") == 0) { |
| 965 | tw_x_offset = atoi(value->value()); |
| 966 | child = child->next_sibling("variable"); |
| 967 | continue; |
| 968 | } |
| 969 | if (strcmp(name->value(), "tw_y_offset") == 0) { |
| 970 | tw_y_offset = atoi(value->value()); |
| 971 | child = child->next_sibling("variable"); |
| 972 | continue; |
| 973 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 974 | p = persist ? atoi(persist->value()) : 0; |
Ethan Yonker | 96acb3d | 2014-08-05 09:20:30 -0500 | [diff] [blame] | 975 | string temp = value->value(); |
| 976 | string valstr = gui_parse_text(temp); |
| 977 | |
| 978 | if (valstr.find("+") != string::npos) { |
| 979 | string val1str = valstr; |
| 980 | val1str = val1str.substr(0, val1str.find('+')); |
| 981 | string val2str = valstr; |
| 982 | val2str = val2str.substr(val2str.find('+') + 1, string::npos); |
| 983 | int val1 = atoi(val1str.c_str()); |
| 984 | int val2 = atoi(val2str.c_str()); |
| 985 | int val = val1 + val2; |
| 986 | |
| 987 | DataManager::SetValue(name->value(), val, p); |
| 988 | } else if (valstr.find("-") != string::npos) { |
| 989 | string val1str = valstr; |
| 990 | val1str = val1str.substr(0, val1str.find('-')); |
| 991 | string val2str = valstr; |
| 992 | val2str = val2str.substr(val2str.find('-') + 1, string::npos); |
| 993 | int val1 = atoi(val1str.c_str()); |
| 994 | int val2 = atoi(val2str.c_str()); |
| 995 | int val = val1 - val2; |
| 996 | |
| 997 | DataManager::SetValue(name->value(), val, p); |
| 998 | } else { |
| 999 | DataManager::SetValue(name->value(), valstr, p); |
| 1000 | } |
Vojtech Bocek | 81c29dc | 2013-12-07 23:02:09 +0100 | [diff] [blame] | 1001 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1002 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1003 | child = child->next_sibling("variable"); |
| 1004 | } |
| 1005 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1008 | int PageSet::LoadPages(xml_node<>* pages) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1009 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1010 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1011 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1012 | if (!pages) |
| 1013 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1014 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1015 | child = pages->first_node("page"); |
| 1016 | while (child != NULL) |
| 1017 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 1018 | Page* page = new Page(child, &templates); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1019 | if (page->GetName().empty()) |
| 1020 | { |
| 1021 | LOGERR("Unable to process load page\n"); |
| 1022 | delete page; |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | mPages.push_back(page); |
| 1027 | } |
| 1028 | child = child->next_sibling("page"); |
| 1029 | } |
| 1030 | if (mPages.size() > 0) |
| 1031 | return 0; |
| 1032 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | int PageSet::IsCurrentPage(Page* page) |
| 1036 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1037 | return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | int PageSet::Render(void) |
| 1041 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1042 | int ret; |
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 | ret = (mCurrentPage ? mCurrentPage->Render() : -1); |
| 1045 | if (ret < 0) |
| 1046 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1047 | |
| 1048 | std::vector<Page*>::iterator iter; |
| 1049 | |
| 1050 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1051 | ret = ((*iter) ? (*iter)->Render() : -1); |
| 1052 | if (ret < 0) |
| 1053 | return ret; |
| 1054 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1055 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | int PageSet::Update(void) |
| 1059 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1060 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1061 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1062 | ret = (mCurrentPage ? mCurrentPage->Update() : -1); |
| 1063 | if (ret < 0 || ret > 1) |
| 1064 | return ret; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1065 | |
| 1066 | std::vector<Page*>::iterator iter; |
| 1067 | |
| 1068 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) { |
| 1069 | ret = ((*iter) ? (*iter)->Update() : -1); |
| 1070 | if (ret < 0) |
| 1071 | return ret; |
| 1072 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1073 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1077 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1078 | if (!mOverlays.empty()) |
| 1079 | return mOverlays.back()->NotifyTouch(state, x, y); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1080 | |
| 1081 | return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1084 | int PageSet::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1085 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1086 | if (!mOverlays.empty()) |
| 1087 | return mOverlays.back()->NotifyKey(key, down); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1088 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1089 | return (mCurrentPage ? mCurrentPage->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | int PageSet::NotifyKeyboard(int key) |
| 1093 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1094 | if (!mOverlays.empty()) |
| 1095 | return mOverlays.back()->NotifyKeyboard(key); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1096 | |
| 1097 | return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | int PageSet::SetKeyBoardFocus(int inFocus) |
| 1101 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1102 | if (!mOverlays.empty()) |
| 1103 | return mOverlays.back()->SetKeyBoardFocus(inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1104 | |
| 1105 | return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | int PageSet::NotifyVarChange(std::string varName, std::string value) |
| 1109 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 1110 | std::vector<Page*>::iterator iter; |
| 1111 | |
| 1112 | for (iter = mOverlays.begin(); iter != mOverlays.end(); iter++) |
| 1113 | (*iter)->NotifyVarChange(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1114 | |
| 1115 | return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1118 | char* PageManager::LoadFileToBuffer(std::string filename, ZipArchive* package) { |
| 1119 | size_t len; |
| 1120 | char* buffer = NULL; |
| 1121 | |
| 1122 | if (!package) { |
| 1123 | // We can try to load the XML directly... |
| 1124 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' directly\n", filename.c_str()); |
| 1125 | struct stat st; |
| 1126 | if(stat(filename.c_str(),&st) != 0) { |
| 1127 | // This isn't always an error, sometimes we request files that don't exist. |
| 1128 | return NULL; |
| 1129 | } |
| 1130 | |
| 1131 | len = (size_t)st.st_size; |
| 1132 | |
| 1133 | buffer = (char*) malloc(len + 1); |
| 1134 | if (!buffer) { |
| 1135 | LOGERR("PageManager::LoadFileToBuffer failed to malloc\n"); |
| 1136 | return NULL; |
| 1137 | } |
| 1138 | |
| 1139 | int fd = open(filename.c_str(), O_RDONLY); |
| 1140 | if (fd == -1) { |
| 1141 | LOGERR("PageManager::LoadFileToBuffer failed to open '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1142 | free(buffer); |
| 1143 | return NULL; |
| 1144 | } |
| 1145 | |
| 1146 | if (read(fd, buffer, len) < 0) { |
| 1147 | LOGERR("PageManager::LoadFileToBuffer failed to read '%s' - (%s)\n", filename.c_str(), strerror(errno)); |
| 1148 | free(buffer); |
| 1149 | close(fd); |
| 1150 | return NULL; |
| 1151 | } |
| 1152 | close(fd); |
| 1153 | } else { |
| 1154 | LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str()); |
| 1155 | const ZipEntry* zipentry = mzFindZipEntry(package, filename.c_str()); |
| 1156 | if (zipentry == NULL) { |
| 1157 | LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); |
| 1158 | return NULL; |
| 1159 | } |
| 1160 | |
| 1161 | // Allocate the buffer for the file |
| 1162 | len = mzGetZipEntryUncompLen(zipentry); |
| 1163 | buffer = (char*) malloc(len + 1); |
| 1164 | if (!buffer) |
| 1165 | return NULL; |
| 1166 | |
| 1167 | if (!mzExtractZipEntryToBuffer(package, zipentry, (unsigned char*) buffer)) { |
| 1168 | LOGERR("Unable to extract '%s'\n", filename.c_str()); |
| 1169 | free(buffer); |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | } |
| 1173 | // NULL-terminate the string |
| 1174 | buffer[len] = 0x00; |
| 1175 | return buffer; |
| 1176 | } |
| 1177 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1178 | int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) |
| 1179 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1180 | int fd; |
| 1181 | ZipArchive zip, *pZip = NULL; |
| 1182 | long len; |
| 1183 | char* xmlFile = NULL; |
| 1184 | PageSet* pageSet = NULL; |
| 1185 | int ret; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1186 | MemMapping map; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1187 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1188 | // Open the XML file |
| 1189 | LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1190 | if (package.size() > 4 && package.substr(package.size() - 4) != ".zip") |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1191 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1192 | LOGINFO("Load XML directly\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1193 | tw_x_offset = TW_X_OFFSET; |
| 1194 | tw_y_offset = TW_Y_OFFSET; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1195 | } |
| 1196 | else |
| 1197 | { |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1198 | LOGINFO("Loading zip theme\n"); |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 1199 | tw_x_offset = 0; |
| 1200 | tw_y_offset = 0; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1201 | if (!TWFunc::Path_Exists(package)) |
| 1202 | return -1; |
| 1203 | if (sysMapFile(package.c_str(), &map) != 0) { |
| 1204 | LOGERR("Failed to map '%s'\n", package.c_str()); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1205 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1206 | } |
| 1207 | if (mzOpenZipArchive(map.addr, map.length, &zip)) { |
| 1208 | LOGERR("Unable to open zip archive '%s'\n", package.c_str()); |
| 1209 | sysReleaseMap(&map); |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1210 | goto error; |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1211 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1212 | pZip = &zip; |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1213 | package = "ui.xml"; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1214 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1215 | |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1216 | xmlFile = LoadFileToBuffer(package, pZip); |
| 1217 | if (xmlFile == NULL) { |
| 1218 | goto error; |
| 1219 | } |
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 | } |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1246 | free(xmlFile); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1247 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1248 | |
| 1249 | error: |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 1250 | // Sometimes we get here without a real error |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1251 | if (pZip) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1252 | mzCloseZipArchive(pZip); |
Ethan Yonker | a2dc2f2 | 2014-11-08 08:13:40 -0600 | [diff] [blame] | 1253 | sysReleaseMap(&map); |
| 1254 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1255 | if (xmlFile) |
| 1256 | free(xmlFile); |
| 1257 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | PageSet* PageManager::FindPackage(std::string name) |
| 1261 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1262 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1263 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1264 | iter = mPageSets.find(name); |
| 1265 | if (iter != mPageSets.end()) |
| 1266 | return (*iter).second; |
| 1267 | |
| 1268 | LOGERR("Unable to locate package %s\n", name.c_str()); |
| 1269 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | PageSet* PageManager::SelectPackage(std::string name) |
| 1273 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1274 | LOGINFO("Switching packages (%s)\n", name.c_str()); |
| 1275 | PageSet* tmp; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1276 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1277 | tmp = FindPackage(name); |
| 1278 | if (tmp) |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1279 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1280 | mCurrentSet = tmp; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1281 | mCurrentSet->NotifyVarChange("", ""); |
| 1282 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1283 | else |
| 1284 | LOGERR("Unable to find package.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1285 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1286 | return mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | int PageManager::ReloadPackage(std::string name, std::string package) |
| 1290 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1291 | std::map<std::string, PageSet*>::iterator iter; |
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 | iter = mPageSets.find(name); |
| 1294 | if (iter == mPageSets.end()) |
| 1295 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1296 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1297 | if(mMouseCursor) |
| 1298 | mMouseCursor->ResetData(gr_fb_width(), gr_fb_height()); |
| 1299 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1300 | PageSet* set = (*iter).second; |
| 1301 | mPageSets.erase(iter); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1302 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1303 | if (LoadPackage(name, package, "main") != 0) |
| 1304 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 1305 | LOGERR("Failed to load package '%s'.\n", package.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1306 | mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); |
| 1307 | return -1; |
| 1308 | } |
| 1309 | if (mCurrentSet == set) |
| 1310 | SelectPackage(name); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 1311 | if (mBaseSet == set) |
| 1312 | mBaseSet = mCurrentSet; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1313 | delete set; |
| 1314 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void PageManager::ReleasePackage(std::string name) |
| 1318 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1319 | std::map<std::string, PageSet*>::iterator iter; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1320 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1321 | iter = mPageSets.find(name); |
| 1322 | if (iter == mPageSets.end()) |
| 1323 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1324 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1325 | PageSet* set = (*iter).second; |
| 1326 | mPageSets.erase(iter); |
| 1327 | delete set; |
| 1328 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | int PageManager::ChangePage(std::string name) |
| 1332 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1333 | DataManager::SetValue("tw_operation_state", 0); |
| 1334 | int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); |
| 1335 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | int PageManager::ChangeOverlay(std::string name) |
| 1339 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1340 | if (name.empty()) |
| 1341 | return mCurrentSet->SetOverlay(NULL); |
| 1342 | else |
| 1343 | { |
| 1344 | Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; |
| 1345 | return mCurrentSet->SetOverlay(page); |
| 1346 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1349 | const ResourceManager* PageManager::GetResources() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1350 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 1351 | return (mCurrentSet ? mCurrentSet->GetResources() : NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | int PageManager::SwitchToConsole(void) |
| 1355 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1356 | PageSet* console = new PageSet(NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1357 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1358 | mCurrentSet = console; |
| 1359 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1360 | } |
| 1361 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 1362 | int PageManager::EndConsole(void) |
| 1363 | { |
| 1364 | if (mCurrentSet && mBaseSet) { |
| 1365 | delete mCurrentSet; |
| 1366 | mCurrentSet = mBaseSet; |
| 1367 | return 0; |
| 1368 | } |
| 1369 | return -1; |
| 1370 | } |
| 1371 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1372 | int PageManager::IsCurrentPage(Page* page) |
| 1373 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1374 | return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | int PageManager::Render(void) |
| 1378 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1379 | int res = (mCurrentSet ? mCurrentSet->Render() : -1); |
| 1380 | if(mMouseCursor) |
| 1381 | mMouseCursor->Render(); |
| 1382 | return res; |
| 1383 | } |
| 1384 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1385 | HardwareKeyboard *PageManager::GetHardwareKeyboard() |
| 1386 | { |
| 1387 | if(!mHardwareKeyboard) |
| 1388 | mHardwareKeyboard = new HardwareKeyboard(); |
| 1389 | return mHardwareKeyboard; |
| 1390 | } |
| 1391 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 1392 | xml_node<>* PageManager::FindStyle(std::string name) |
| 1393 | { |
| 1394 | for (std::vector<xml_node<>*>::iterator itr = mCurrentSet->styles.begin(); itr != mCurrentSet->styles.end(); itr++) { |
| 1395 | xml_node<>* node = (*itr)->first_node("style"); |
| 1396 | |
| 1397 | while (node) { |
| 1398 | if (!node->first_attribute("name")) |
| 1399 | continue; |
| 1400 | |
| 1401 | if (name == node->first_attribute("name")->value()) |
| 1402 | return node; |
| 1403 | node = node->next_sibling("style"); |
| 1404 | } |
| 1405 | } |
| 1406 | return NULL; |
| 1407 | } |
| 1408 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1409 | MouseCursor *PageManager::GetMouseCursor() |
| 1410 | { |
| 1411 | if(!mMouseCursor) |
| 1412 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1413 | return mMouseCursor; |
| 1414 | } |
| 1415 | |
| 1416 | void PageManager::LoadCursorData(xml_node<>* node) |
| 1417 | { |
| 1418 | if(!mMouseCursor) |
| 1419 | mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height()); |
| 1420 | |
| 1421 | mMouseCursor->LoadData(node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | int PageManager::Update(void) |
| 1425 | { |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 1426 | if(blankTimer.isScreenOff()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1427 | return 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1428 | |
| 1429 | int res = (mCurrentSet ? mCurrentSet->Update() : -1); |
| 1430 | |
| 1431 | if(mMouseCursor) |
| 1432 | { |
| 1433 | int c_res = mMouseCursor->Update(); |
| 1434 | if(c_res > res) |
| 1435 | res = c_res; |
| 1436 | } |
| 1437 | return res; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 1441 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1442 | return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1445 | int PageManager::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1446 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1447 | return (mCurrentSet ? mCurrentSet->NotifyKey(key, down) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | int PageManager::NotifyKeyboard(int key) |
| 1451 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1452 | return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | int PageManager::SetKeyBoardFocus(int inFocus) |
| 1456 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1457 | return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | int PageManager::NotifyVarChange(std::string varName, std::string value) |
| 1461 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1462 | return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | extern "C" void gui_notifyVarChange(const char *name, const char* value) |
| 1466 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1467 | if (!gGuiRunning) |
| 1468 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1469 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1470 | PageManager::NotifyVarChange(name, value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1471 | } |