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 | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/reboot.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/time.h> |
| 29 | #include <sys/mman.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/ioctl.h> |
| 32 | #include <time.h> |
| 33 | #include <unistd.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <dirent.h> |
| 36 | #include <ctype.h> |
| 37 | |
| 38 | #include <algorithm> |
| 39 | |
| 40 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 41 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #include "rapidxml.hpp" |
| 46 | #include "objects.hpp" |
| 47 | #include "../data.hpp" |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 48 | #include "../twrp-functions.hpp" |
| 49 | |
| 50 | #define SCROLLING_SPEED_DECREMENT 6 |
| 51 | #define SCROLLING_FLOOR 10 |
| 52 | #define SCROLLING_MULTIPLIER 6 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 54 | GUIListBox::GUIListBox(xml_node<>* node) : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 56 | xml_attribute<>* attr; |
| 57 | xml_node<>* child; |
| 58 | int header_separator_color_specified = 0, header_separator_height_specified = 0, header_text_color_specified = 0, header_background_color_specified = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 60 | mStart = mLineSpacing = startY = mFontHeight = mSeparatorH = scrollingY = scrollingSpeed = 0; |
Dees_Troy | e428459 | 2013-02-19 16:59:35 +0000 | [diff] [blame] | 61 | mIconWidth = mIconHeight = mSelectedIconHeight = mSelectedIconWidth = mUnselectedIconHeight = mUnselectedIconWidth = mHeaderIconHeight = mHeaderIconWidth = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 62 | mHeaderSeparatorH = mLineHeight = mHeaderIsStatic = mHeaderH = actualLineHeight = 0; |
| 63 | mIconSelected = mIconUnselected = mBackground = mFont = mHeaderIcon = NULL; |
| 64 | mBackgroundX = mBackgroundY = mBackgroundW = mBackgroundH = 0; |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 65 | mFastScrollW = mFastScrollLineW = mFastScrollRectW = mFastScrollRectH = 0; |
| 66 | mFastScrollRectX = mFastScrollRectY = -1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 67 | mUpdate = 0; |
| 68 | touchDebounce = 6; |
| 69 | ConvertStrToColor("black", &mBackgroundColor); |
| 70 | ConvertStrToColor("black", &mHeaderBackgroundColor); |
| 71 | ConvertStrToColor("black", &mSeparatorColor); |
| 72 | ConvertStrToColor("black", &mHeaderSeparatorColor); |
| 73 | ConvertStrToColor("white", &mFontColor); |
| 74 | ConvertStrToColor("white", &mHeaderFontColor); |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 75 | ConvertStrToColor("white", &mFastScrollLineColor); |
| 76 | ConvertStrToColor("white", &mFastScrollRectColor); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 77 | hasHighlightColor = false; |
| 78 | hasFontHighlightColor = false; |
| 79 | isHighlighted = false; |
| 80 | startSelection = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 82 | // Load header text |
| 83 | child = node->first_node("header"); |
| 84 | if (child) |
| 85 | { |
| 86 | attr = child->first_attribute("icon"); |
| 87 | if (attr) |
| 88 | mHeaderIcon = PageManager::FindResource(attr->value()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 89 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 90 | attr = child->first_attribute("background"); |
| 91 | if (attr) |
| 92 | { |
| 93 | std::string color = attr->value(); |
| 94 | ConvertStrToColor(color, &mHeaderBackgroundColor); |
| 95 | header_background_color_specified = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 97 | attr = child->first_attribute("textcolor"); |
| 98 | if (attr) |
| 99 | { |
| 100 | std::string color = attr->value(); |
| 101 | ConvertStrToColor(color, &mHeaderFontColor); |
| 102 | header_text_color_specified = -1; |
| 103 | } |
| 104 | attr = child->first_attribute("separatorcolor"); |
| 105 | if (attr) |
| 106 | { |
| 107 | std::string color = attr->value(); |
| 108 | ConvertStrToColor(color, &mHeaderSeparatorColor); |
| 109 | header_separator_color_specified = -1; |
| 110 | } |
| 111 | attr = child->first_attribute("separatorheight"); |
| 112 | if (attr) { |
| 113 | string parsevalue = gui_parse_text(attr->value()); |
| 114 | mHeaderSeparatorH = atoi(parsevalue.c_str()); |
| 115 | header_separator_height_specified = -1; |
| 116 | } |
| 117 | } |
| 118 | child = node->first_node("text"); |
| 119 | if (child) mHeaderText = child->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 120 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 121 | memset(&mHighlightColor, 0, sizeof(COLOR)); |
| 122 | child = node->first_node("highlight"); |
| 123 | if (child) { |
| 124 | attr = child->first_attribute("color"); |
| 125 | if (attr) { |
| 126 | hasHighlightColor = true; |
| 127 | std::string color = attr->value(); |
| 128 | ConvertStrToColor(color, &mHighlightColor); |
| 129 | } |
| 130 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 131 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 132 | // Simple way to check for static state |
| 133 | mLastValue = gui_parse_text(mHeaderText); |
| 134 | if (mLastValue != mHeaderText) |
| 135 | mHeaderIsStatic = 0; |
| 136 | else |
| 137 | mHeaderIsStatic = -1; |
| 138 | |
| 139 | child = node->first_node("icon"); |
| 140 | if (child) |
| 141 | { |
| 142 | attr = child->first_attribute("selected"); |
| 143 | if (attr) |
| 144 | mIconSelected = PageManager::FindResource(attr->value()); |
| 145 | attr = child->first_attribute("unselected"); |
| 146 | if (attr) |
| 147 | mIconUnselected = PageManager::FindResource(attr->value()); |
| 148 | } |
| 149 | child = node->first_node("background"); |
| 150 | if (child) |
| 151 | { |
| 152 | attr = child->first_attribute("resource"); |
| 153 | if (attr) |
| 154 | mBackground = PageManager::FindResource(attr->value()); |
| 155 | attr = child->first_attribute("color"); |
| 156 | if (attr) |
| 157 | { |
| 158 | std::string color = attr->value(); |
| 159 | ConvertStrToColor(color, &mBackgroundColor); |
| 160 | if (!header_background_color_specified) |
| 161 | ConvertStrToColor(color, &mHeaderBackgroundColor); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Load the placement |
| 166 | LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); |
| 167 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 168 | |
| 169 | // Load the font, and possibly override the color |
| 170 | child = node->first_node("font"); |
| 171 | if (child) |
| 172 | { |
| 173 | attr = child->first_attribute("resource"); |
| 174 | if (attr) |
| 175 | mFont = PageManager::FindResource(attr->value()); |
| 176 | |
| 177 | attr = child->first_attribute("color"); |
| 178 | if (attr) |
| 179 | { |
| 180 | std::string color = attr->value(); |
| 181 | ConvertStrToColor(color, &mFontColor); |
| 182 | if (!header_text_color_specified) |
| 183 | ConvertStrToColor(color, &mHeaderFontColor); |
| 184 | } |
| 185 | |
| 186 | attr = child->first_attribute("spacing"); |
| 187 | if (attr) { |
| 188 | string parsevalue = gui_parse_text(attr->value()); |
| 189 | mLineSpacing = atoi(parsevalue.c_str()); |
| 190 | } |
| 191 | |
| 192 | attr = child->first_attribute("highlightcolor"); |
| 193 | memset(&mFontHighlightColor, 0, sizeof(COLOR)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | if (attr) |
| 195 | { |
| 196 | std::string color = attr->value(); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 197 | ConvertStrToColor(color, &mFontHighlightColor); |
| 198 | hasFontHighlightColor = true; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 199 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Load the separator if it exists |
| 203 | child = node->first_node("separator"); |
| 204 | if (child) |
| 205 | { |
| 206 | attr = child->first_attribute("color"); |
| 207 | if (attr) |
| 208 | { |
| 209 | std::string color = attr->value(); |
| 210 | ConvertStrToColor(color, &mSeparatorColor); |
| 211 | if (!header_separator_color_specified) |
| 212 | ConvertStrToColor(color, &mHeaderSeparatorColor); |
| 213 | } |
| 214 | |
| 215 | attr = child->first_attribute("height"); |
| 216 | if (attr) { |
| 217 | string parsevalue = gui_parse_text(attr->value()); |
| 218 | mSeparatorH = atoi(parsevalue.c_str()); |
| 219 | if (!header_separator_height_specified) |
| 220 | mHeaderSeparatorH = mSeparatorH; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Handle the result variable |
| 225 | child = node->first_node("data"); |
| 226 | if (child) |
| 227 | { |
| 228 | attr = child->first_attribute("name"); |
| 229 | if (attr) |
| 230 | mVariable = attr->value(); |
| 231 | attr = child->first_attribute("default"); |
| 232 | if (attr) |
| 233 | DataManager::SetValue(mVariable, attr->value()); |
| 234 | } |
| 235 | |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 236 | // Fast scroll colors |
| 237 | child = node->first_node("fastscroll"); |
| 238 | if (child) |
| 239 | { |
| 240 | attr = child->first_attribute("linecolor"); |
| 241 | if(attr) |
| 242 | ConvertStrToColor(attr->value(), &mFastScrollLineColor); |
| 243 | |
| 244 | attr = child->first_attribute("rectcolor"); |
| 245 | if(attr) |
| 246 | ConvertStrToColor(attr->value(), &mFastScrollRectColor); |
| 247 | |
| 248 | attr = child->first_attribute("w"); |
| 249 | if (attr) { |
| 250 | string parsevalue = gui_parse_text(attr->value()); |
| 251 | mFastScrollW = atoi(parsevalue.c_str()); |
| 252 | } |
| 253 | |
| 254 | attr = child->first_attribute("linew"); |
| 255 | if (attr) { |
| 256 | string parsevalue = gui_parse_text(attr->value()); |
| 257 | mFastScrollLineW = atoi(parsevalue.c_str()); |
| 258 | } |
| 259 | |
| 260 | attr = child->first_attribute("rectw"); |
| 261 | if (attr) { |
| 262 | string parsevalue = gui_parse_text(attr->value()); |
| 263 | mFastScrollRectW = atoi(parsevalue.c_str()); |
| 264 | } |
| 265 | |
| 266 | attr = child->first_attribute("recth"); |
| 267 | if (attr) { |
| 268 | string parsevalue = gui_parse_text(attr->value()); |
| 269 | mFastScrollRectH = atoi(parsevalue.c_str()); |
| 270 | } |
| 271 | } |
| 272 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 273 | // Retrieve the line height |
| 274 | gr_getFontDetails(mFont ? mFont->GetResource() : NULL, &mFontHeight, NULL); |
| 275 | mLineHeight = mFontHeight; |
| 276 | mHeaderH = mFontHeight; |
| 277 | |
| 278 | if (mIconSelected && mIconSelected->GetResource()) |
| 279 | { |
| 280 | mSelectedIconWidth = gr_get_width(mIconSelected->GetResource()); |
| 281 | mSelectedIconHeight = gr_get_height(mIconSelected->GetResource()); |
| 282 | if (mSelectedIconHeight > (int)mLineHeight) |
| 283 | mLineHeight = mSelectedIconHeight; |
| 284 | mIconWidth = mSelectedIconWidth; |
| 285 | } |
| 286 | |
| 287 | if (mIconUnselected && mIconUnselected->GetResource()) |
| 288 | { |
| 289 | mUnselectedIconWidth = gr_get_width(mIconUnselected->GetResource()); |
| 290 | mUnselectedIconHeight = gr_get_height(mIconUnselected->GetResource()); |
| 291 | if (mUnselectedIconHeight > (int)mLineHeight) |
| 292 | mLineHeight = mUnselectedIconHeight; |
| 293 | if (mUnselectedIconWidth > mIconWidth) |
| 294 | mIconWidth = mUnselectedIconWidth; |
| 295 | } |
| 296 | |
| 297 | if (mHeaderIcon && mHeaderIcon->GetResource()) |
| 298 | { |
| 299 | mHeaderIconWidth = gr_get_width(mHeaderIcon->GetResource()); |
| 300 | mHeaderIconHeight = gr_get_height(mHeaderIcon->GetResource()); |
| 301 | if (mHeaderIconHeight > mHeaderH) |
| 302 | mHeaderH = mHeaderIconHeight; |
| 303 | if (mHeaderIconWidth > mIconWidth) |
| 304 | mIconWidth = mHeaderIconWidth; |
| 305 | } |
| 306 | |
| 307 | mHeaderH += mLineSpacing + mHeaderSeparatorH; |
| 308 | actualLineHeight = mLineHeight + mLineSpacing + mSeparatorH; |
| 309 | if (mHeaderH < actualLineHeight) |
| 310 | mHeaderH = actualLineHeight; |
| 311 | |
| 312 | if (actualLineHeight / 3 > 6) |
| 313 | touchDebounce = actualLineHeight / 3; |
| 314 | |
| 315 | if (mBackground && mBackground->GetResource()) |
| 316 | { |
| 317 | mBackgroundW = gr_get_width(mBackground->GetResource()); |
| 318 | mBackgroundH = gr_get_height(mBackground->GetResource()); |
| 319 | } |
| 320 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 321 | // Get the currently selected value for the list |
| 322 | DataManager::GetValue(mVariable, currentValue); |
| 323 | |
| 324 | // Get the data for the list |
| 325 | child = node->first_node("listitem"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 326 | if (!child) return; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 327 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 328 | while (child) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 329 | { |
| 330 | ListData data; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 331 | |
| 332 | attr = child->first_attribute("name"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 333 | if (!attr) return; |
| 334 | data.displayName = attr->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 335 | |
| 336 | data.variableValue = child->value(); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 337 | if (child->value() == currentValue) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 338 | data.selected = 1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 339 | } else { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 340 | data.selected = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 341 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 342 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 343 | mList.push_back(data); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 344 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 345 | child = child->next_sibling("listitem"); |
| 346 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | GUIListBox::~GUIListBox() |
| 350 | { |
| 351 | } |
| 352 | |
| 353 | int GUIListBox::Render(void) |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 354 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 355 | if(!isConditionTrue()) |
| 356 | return 0; |
| 357 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 358 | // First step, fill background |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 359 | gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); |
| 360 | gr_fill(mRenderX, mRenderY + mHeaderH, mRenderW, mRenderH - mHeaderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 361 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 362 | // Next, render the background resource (if it exists) |
| 363 | if (mBackground && mBackground->GetResource()) |
| 364 | { |
| 365 | mBackgroundX = mRenderX + ((mRenderW - mBackgroundW) / 2); |
| 366 | mBackgroundY = mRenderY + ((mRenderH - mBackgroundH) / 2); |
| 367 | gr_blit(mBackground->GetResource(), 0, 0, mBackgroundW, mBackgroundH, mBackgroundX, mBackgroundY); |
| 368 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 369 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 370 | // This tells us how many lines we can actually render |
| 371 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 372 | int line; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 373 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 374 | int listSize = mList.size(); |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 375 | int listW = mRenderW; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 376 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 377 | if (listSize < lines) { |
| 378 | lines = listSize; |
| 379 | scrollingY = 0; |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 380 | mFastScrollRectX = mFastScrollRectY = -1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 381 | } else { |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 382 | listW -= mFastScrollW; // space for fast scroll |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 383 | lines++; |
| 384 | if (lines < listSize) |
| 385 | lines++; |
| 386 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 387 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 388 | void* fontResource = NULL; |
| 389 | if (mFont) fontResource = mFont->GetResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 390 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 391 | int yPos = mRenderY + mHeaderH + scrollingY; |
| 392 | int fontOffsetY = (int)((actualLineHeight - mFontHeight) / 2); |
| 393 | int currentIconHeight = 0, currentIconWidth = 0; |
| 394 | int currentIconOffsetY = 0, currentIconOffsetX = 0; |
| 395 | int UnselectedIconOffsetY = (int)((actualLineHeight - mUnselectedIconHeight) / 2), SelectedIconOffsetY = (int)((actualLineHeight - mSelectedIconHeight) / 2); |
| 396 | int UnselectedIconOffsetX = (mIconWidth - mUnselectedIconWidth) / 2, SelectedIconOffsetX = (mIconWidth - mSelectedIconWidth) / 2; |
| 397 | int actualSelection = mStart; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 398 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 399 | if (isHighlighted) { |
| 400 | int selectY = scrollingY; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 401 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 402 | // Locate the correct line for highlighting |
| 403 | while (selectY + actualLineHeight < startSelection) { |
| 404 | selectY += actualLineHeight; |
| 405 | actualSelection++; |
| 406 | } |
| 407 | if (hasHighlightColor) { |
| 408 | // Highlight the area |
| 409 | gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, 255); |
| 410 | int HighlightHeight = actualLineHeight; |
| 411 | if (mRenderY + mHeaderH + selectY + actualLineHeight > mRenderH + mRenderY) { |
| 412 | HighlightHeight = actualLineHeight - (mRenderY + mHeaderH + selectY + actualLineHeight - mRenderH - mRenderY); |
| 413 | } |
| 414 | gr_fill(mRenderX, mRenderY + mHeaderH + selectY, mRenderW, HighlightHeight); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | for (line = 0; line < lines; line++) |
| 419 | { |
| 420 | Resource* icon; |
| 421 | std::string label; |
| 422 | |
| 423 | if (line + mStart >= listSize) |
| 424 | continue; |
| 425 | |
| 426 | label = mList.at(line + mStart).displayName; |
| 427 | if (isHighlighted && hasFontHighlightColor && line + mStart == actualSelection) { |
| 428 | // Use the highlight color for the font |
| 429 | gr_color(mFontHighlightColor.red, mFontHighlightColor.green, mFontHighlightColor.blue, 255); |
| 430 | } else { |
| 431 | // Set the color for the font |
| 432 | gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, 255); |
| 433 | } |
| 434 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 435 | if (mList.at(line + mStart).selected != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 436 | { |
| 437 | icon = mIconSelected; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 438 | currentIconHeight = mSelectedIconHeight; |
| 439 | currentIconWidth = mSelectedIconWidth; |
| 440 | currentIconOffsetY = SelectedIconOffsetY; |
| 441 | currentIconOffsetX = SelectedIconOffsetX; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
| 445 | icon = mIconUnselected; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 446 | currentIconHeight = mSelectedIconHeight; |
| 447 | currentIconWidth = mSelectedIconWidth; |
| 448 | currentIconOffsetY = SelectedIconOffsetY; |
| 449 | currentIconOffsetX = SelectedIconOffsetX; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 450 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 451 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 452 | if (icon && icon->GetResource()) |
| 453 | { |
| 454 | int rect_y = 0, image_y = (yPos + currentIconOffsetY); |
| 455 | if (image_y + currentIconHeight > mRenderY + mRenderH) |
| 456 | rect_y = mRenderY + mRenderH - image_y; |
| 457 | else |
| 458 | rect_y = currentIconHeight; |
| 459 | gr_blit(icon->GetResource(), 0, 0, currentIconWidth, rect_y, mRenderX + currentIconOffsetX, image_y); |
| 460 | } |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 461 | gr_textExWH(mRenderX + mIconWidth + 5, yPos + fontOffsetY, label.c_str(), fontResource, mRenderX + listW, mRenderY + mRenderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 462 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 463 | // Add the separator |
| 464 | if (yPos + actualLineHeight < mRenderH + mRenderY) { |
| 465 | gr_color(mSeparatorColor.red, mSeparatorColor.green, mSeparatorColor.blue, 255); |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 466 | gr_fill(mRenderX, yPos + actualLineHeight - mSeparatorH, listW, mSeparatorH); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 467 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 468 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 469 | // Move the yPos |
| 470 | yPos += actualLineHeight; |
| 471 | } |
| 472 | |
| 473 | // Render the Header (last so that it overwrites the top most row for per pixel scrolling) |
| 474 | // First step, fill background |
| 475 | gr_color(mHeaderBackgroundColor.red, mHeaderBackgroundColor.green, mHeaderBackgroundColor.blue, 255); |
| 476 | gr_fill(mRenderX, mRenderY, mRenderW, mHeaderH); |
| 477 | |
| 478 | // Now, we need the header (icon + text) |
| 479 | yPos = mRenderY; |
| 480 | { |
| 481 | Resource* headerIcon; |
| 482 | int mIconOffsetX = 0; |
| 483 | |
| 484 | // render the icon if it exists |
| 485 | headerIcon = mHeaderIcon; |
| 486 | if (headerIcon && headerIcon->GetResource()) |
| 487 | { |
| 488 | gr_blit(headerIcon->GetResource(), 0, 0, mHeaderIconWidth, mHeaderIconHeight, mRenderX + ((mHeaderIconWidth - mIconWidth) / 2), (yPos + (int)((mHeaderH - mHeaderIconHeight) / 2))); |
| 489 | mIconOffsetX = mIconWidth; |
| 490 | } |
| 491 | |
| 492 | // render the text |
| 493 | gr_color(mHeaderFontColor.red, mHeaderFontColor.green, mHeaderFontColor.blue, 255); |
| 494 | gr_textExWH(mRenderX + mIconOffsetX + 5, yPos + (int)((mHeaderH - mFontHeight) / 2), mLastValue.c_str(), fontResource, mRenderX + mRenderW, mRenderY + mRenderH); |
| 495 | |
| 496 | // Add the separator |
| 497 | gr_color(mHeaderSeparatorColor.red, mHeaderSeparatorColor.green, mHeaderSeparatorColor.blue, 255); |
| 498 | gr_fill(mRenderX, yPos + mHeaderH - mHeaderSeparatorH, mRenderW, mHeaderSeparatorH); |
| 499 | } |
| 500 | |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 501 | // render fast scroll |
| 502 | lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 503 | if(mFastScrollW > 0 && listSize > lines) |
| 504 | { |
| 505 | int startX = listW + mRenderX; |
| 506 | int fWidth = mRenderW - listW; |
| 507 | int fHeight = mRenderH - mHeaderH; |
| 508 | |
| 509 | // line |
| 510 | gr_color(mFastScrollLineColor.red, mFastScrollLineColor.green, mFastScrollLineColor.blue, 255); |
| 511 | gr_fill(startX + fWidth/2, mRenderY + mHeaderH, mFastScrollLineW, mRenderH - mHeaderH); |
| 512 | |
| 513 | // rect |
| 514 | int pct = ((mStart*actualLineHeight - scrollingY)*100)/((listSize)*actualLineHeight-lines*actualLineHeight); |
| 515 | mFastScrollRectX = startX + (fWidth - mFastScrollRectW)/2; |
| 516 | mFastScrollRectY = mRenderY+mHeaderH + ((fHeight - mFastScrollRectH)*pct)/100; |
| 517 | |
| 518 | gr_color(mFastScrollRectColor.red, mFastScrollRectColor.green, mFastScrollRectColor.blue, 255); |
| 519 | gr_fill(mFastScrollRectX, mFastScrollRectY, mFastScrollRectW, mFastScrollRectH); |
| 520 | } |
| 521 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 522 | mUpdate = 0; |
| 523 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | int GUIListBox::Update(void) |
| 527 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 528 | if(!isConditionTrue()) |
| 529 | return 0; |
| 530 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 531 | if (!mHeaderIsStatic) { |
| 532 | std::string newValue = gui_parse_text(mHeaderText); |
| 533 | if (mLastValue != newValue) { |
| 534 | mLastValue = newValue; |
| 535 | mUpdate = 1; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | if (mUpdate) |
| 540 | { |
| 541 | mUpdate = 0; |
| 542 | if (Render() == 0) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 543 | return 2; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | // Handle kinetic scrolling |
| 547 | if (scrollingSpeed == 0) { |
| 548 | // Do nothing |
| 549 | } else if (scrollingSpeed > 0) { |
| 550 | if (scrollingSpeed < ((int) (actualLineHeight * 2.5))) { |
| 551 | scrollingY += scrollingSpeed; |
| 552 | scrollingSpeed -= SCROLLING_SPEED_DECREMENT; |
| 553 | } else { |
| 554 | scrollingY += ((int) (actualLineHeight * 2.5)); |
| 555 | scrollingSpeed -= SCROLLING_SPEED_DECREMENT; |
| 556 | } |
| 557 | while (mStart && scrollingY > 0) { |
| 558 | mStart--; |
| 559 | scrollingY -= actualLineHeight; |
| 560 | } |
| 561 | if (mStart == 0 && scrollingY > 0) { |
| 562 | scrollingY = 0; |
| 563 | scrollingSpeed = 0; |
| 564 | } else if (scrollingSpeed < SCROLLING_FLOOR) |
| 565 | scrollingSpeed = 0; |
| 566 | mUpdate = 1; |
| 567 | } else if (scrollingSpeed < 0) { |
| 568 | int totalSize = mList.size(); |
| 569 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 570 | |
| 571 | if (totalSize > lines) { |
| 572 | int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight); |
| 573 | |
| 574 | bottom_offset -= actualLineHeight; |
| 575 | |
| 576 | if (abs(scrollingSpeed) < ((int) (actualLineHeight * 2.5))) { |
| 577 | scrollingY += scrollingSpeed; |
| 578 | scrollingSpeed += SCROLLING_SPEED_DECREMENT; |
| 579 | } else { |
| 580 | scrollingY -= ((int) (actualLineHeight * 2.5)); |
| 581 | scrollingSpeed += SCROLLING_SPEED_DECREMENT; |
| 582 | } |
| 583 | while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) { |
| 584 | mStart++; |
| 585 | scrollingY += actualLineHeight; |
| 586 | } |
| 587 | if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) { |
| 588 | mStart = totalSize - lines - 1; |
| 589 | scrollingY = bottom_offset; |
| 590 | } else if (mStart + lines >= totalSize && scrollingY < 0) { |
| 591 | mStart = totalSize - lines; |
| 592 | scrollingY = 0; |
| 593 | } else if (scrollingSpeed * -1 < SCROLLING_FLOOR) |
| 594 | scrollingSpeed = 0; |
| 595 | mUpdate = 1; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | int GUIListBox::GetSelection(int x, int y) |
| 603 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 604 | // We only care about y position |
| 605 | if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) return -1; |
| 606 | return (y - mRenderY - mHeaderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 610 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 611 | if(!isConditionTrue()) |
| 612 | return -1; |
| 613 | |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 614 | static int lastY = 0, last2Y = 0, fastScroll = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 615 | int selection = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 616 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 617 | switch (state) |
| 618 | { |
| 619 | case TOUCH_START: |
| 620 | if (scrollingSpeed != 0) |
| 621 | startSelection = -1; |
| 622 | else |
| 623 | startSelection = GetSelection(x,y); |
| 624 | isHighlighted = (startSelection > -1); |
| 625 | if (isHighlighted) |
| 626 | mUpdate = 1; |
| 627 | startY = lastY = last2Y = y; |
| 628 | scrollingSpeed = 0; |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 629 | |
| 630 | if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW) |
| 631 | fastScroll = 1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 632 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 633 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 634 | case TOUCH_DRAG: |
| 635 | // Check if we dragged out of the selection window |
| 636 | if (GetSelection(x, y) == -1) { |
| 637 | last2Y = lastY = 0; |
| 638 | if (isHighlighted) { |
| 639 | isHighlighted = false; |
| 640 | mUpdate = 1; |
| 641 | } |
| 642 | break; |
| 643 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 644 | |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 645 | // Fast scroll |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 646 | if(fastScroll) |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 647 | { |
| 648 | int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH); |
| 649 | int totalSize = mList.size(); |
| 650 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 651 | |
| 652 | float l = float((totalSize-lines)*pct)/100; |
| 653 | if(l + lines >= totalSize) |
| 654 | { |
| 655 | mStart = totalSize - lines; |
| 656 | scrollingY = 0; |
| 657 | } |
| 658 | else |
| 659 | { |
| 660 | mStart = l; |
| 661 | scrollingY = -(l - int(l))*actualLineHeight; |
| 662 | } |
| 663 | |
| 664 | startSelection = -1; |
| 665 | mUpdate = 1; |
| 666 | scrollingSpeed = 0; |
| 667 | isHighlighted = false; |
| 668 | break; |
| 669 | } |
| 670 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 671 | // Provide some debounce on initial touches |
| 672 | if (startSelection != -1 && abs(y - startY) < touchDebounce) { |
| 673 | isHighlighted = true; |
| 674 | mUpdate = 1; |
| 675 | break; |
| 676 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 677 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 678 | isHighlighted = false; |
| 679 | last2Y = lastY; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 680 | lastY = y; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 681 | startSelection = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 682 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 683 | // Handle scrolling |
| 684 | scrollingY += y - startY; |
| 685 | startY = y; |
| 686 | while(mStart && scrollingY > 0) { |
| 687 | mStart--; |
| 688 | scrollingY -= actualLineHeight; |
| 689 | } |
| 690 | if (mStart == 0 && scrollingY > 0) |
| 691 | scrollingY = 0; |
| 692 | { |
| 693 | int totalSize = mList.size(); |
| 694 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 695 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 696 | if (totalSize > lines) { |
| 697 | int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 698 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 699 | bottom_offset -= actualLineHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 700 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 701 | while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) { |
| 702 | mStart++; |
| 703 | scrollingY += actualLineHeight; |
| 704 | } |
| 705 | if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) { |
| 706 | mStart = totalSize - lines - 1; |
| 707 | scrollingY = bottom_offset; |
| 708 | } else if (mStart + lines >= totalSize && scrollingY < 0) { |
| 709 | mStart = totalSize - lines; |
| 710 | scrollingY = 0; |
| 711 | } |
| 712 | } else |
| 713 | scrollingY = 0; |
| 714 | } |
| 715 | mUpdate = 1; |
| 716 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 717 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 718 | case TOUCH_RELEASE: |
| 719 | isHighlighted = false; |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 720 | fastScroll = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 721 | if (startSelection >= 0) |
| 722 | { |
| 723 | // We've selected an item! |
| 724 | std::string str; |
| 725 | |
| 726 | int listSize = mList.size(); |
| 727 | int selectY = scrollingY, actualSelection = mStart; |
| 728 | |
| 729 | // Move the selection to the proper place in the array |
| 730 | while (selectY + actualLineHeight < startSelection) { |
| 731 | selectY += actualLineHeight; |
| 732 | actualSelection++; |
| 733 | } |
| 734 | |
| 735 | if (actualSelection < listSize && !mVariable.empty()) |
| 736 | { |
| 737 | int i; |
| 738 | for (i=0; i<listSize; i++) |
| 739 | mList.at(i).selected = 0; |
| 740 | |
| 741 | str = mList.at(actualSelection).variableValue; |
| 742 | mList.at(actualSelection).selected = 1; |
| 743 | DataManager::SetValue(mVariable, str); |
| 744 | mUpdate = 1; |
Vojtech Bocek | 5af8f3f | 2014-02-08 02:21:23 +0100 | [diff] [blame] | 745 | |
| 746 | DataManager::Vibrate("tw_button_vibrate"); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 747 | } |
| 748 | } else { |
| 749 | // This is for kinetic scrolling |
| 750 | scrollingSpeed = lastY - last2Y; |
| 751 | if (abs(scrollingSpeed) > SCROLLING_FLOOR) |
| 752 | scrollingSpeed *= SCROLLING_MULTIPLIER; |
| 753 | else |
| 754 | scrollingSpeed = 0; |
| 755 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 756 | case TOUCH_REPEAT: |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 757 | case TOUCH_HOLD: |
| 758 | break; |
| 759 | } |
| 760 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 763 | int GUIListBox::NotifyVarChange(const std::string& varName, const std::string& value) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 765 | GUIObject::NotifyVarChange(varName, value); |
| 766 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 767 | if(!isConditionTrue()) |
| 768 | return 0; |
| 769 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 770 | if (!mHeaderIsStatic) { |
| 771 | std::string newValue = gui_parse_text(mHeaderText); |
| 772 | if (mLastValue != newValue) { |
| 773 | mLastValue = newValue; |
| 774 | mStart = 0; |
| 775 | scrollingY = 0; |
| 776 | scrollingSpeed = 0; |
| 777 | mUpdate = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 778 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 779 | } |
| 780 | if (varName == mVariable) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 781 | { |
| 782 | int i, listSize = mList.size(), selected_index = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 783 | |
| 784 | currentValue = value; |
| 785 | |
| 786 | for (i=0; i<listSize; i++) { |
| 787 | if (mList.at(i).variableValue == currentValue) { |
| 788 | mList.at(i).selected = 1; |
| 789 | selected_index = i; |
| 790 | } else |
| 791 | mList.at(i).selected = 0; |
| 792 | } |
| 793 | |
| 794 | int lines = mRenderH / (mLineHeight + mLineSpacing); |
| 795 | int line; |
| 796 | |
| 797 | if (selected_index > mStart + lines - 1) |
| 798 | mStart = selected_index; |
| 799 | if (mStart > listSize - lines) { |
| 800 | mStart = listSize - lines; |
| 801 | } else if (selected_index < mStart) { |
| 802 | mStart = selected_index; |
| 803 | } |
| 804 | |
| 805 | mUpdate = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 806 | return 0; |
| 807 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 808 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | int GUIListBox::SetRenderPos(int x, int y, int w /* = 0 */, int h /* = 0 */) |
| 812 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 813 | mRenderX = x; |
| 814 | mRenderY = y; |
| 815 | if (w || h) |
| 816 | { |
| 817 | mRenderW = w; |
| 818 | mRenderH = h; |
| 819 | } |
| 820 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 821 | mUpdate = 1; |
| 822 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | void GUIListBox::SetPageFocus(int inFocus) |
| 826 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 827 | if (inFocus) |
| 828 | { |
| 829 | DataManager::GetValue(mVariable, currentValue); |
| 830 | NotifyVarChange(mVariable, currentValue); |
| 831 | mUpdate = 1; |
| 832 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 833 | } |