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 | |
| 54 | GUIListBox::GUIListBox(xml_node<>* node) |
| 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; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 327 | |
| 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 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 355 | // First step, fill background |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 356 | gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); |
| 357 | gr_fill(mRenderX, mRenderY + mHeaderH, mRenderW, mRenderH - mHeaderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 358 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 359 | // Next, render the background resource (if it exists) |
| 360 | if (mBackground && mBackground->GetResource()) |
| 361 | { |
| 362 | mBackgroundX = mRenderX + ((mRenderW - mBackgroundW) / 2); |
| 363 | mBackgroundY = mRenderY + ((mRenderH - mBackgroundH) / 2); |
| 364 | gr_blit(mBackground->GetResource(), 0, 0, mBackgroundW, mBackgroundH, mBackgroundX, mBackgroundY); |
| 365 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 366 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 367 | // This tells us how many lines we can actually render |
| 368 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 369 | int line; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 370 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 371 | int listSize = mList.size(); |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 372 | int listW = mRenderW; |
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 | if (listSize < lines) { |
| 375 | lines = listSize; |
| 376 | scrollingY = 0; |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 377 | mFastScrollRectX = mFastScrollRectY = -1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 378 | } else { |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 379 | listW -= mFastScrollW; // space for fast scroll |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 380 | lines++; |
| 381 | if (lines < listSize) |
| 382 | lines++; |
| 383 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 384 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 385 | void* fontResource = NULL; |
| 386 | if (mFont) fontResource = mFont->GetResource(); |
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 | int yPos = mRenderY + mHeaderH + scrollingY; |
| 389 | int fontOffsetY = (int)((actualLineHeight - mFontHeight) / 2); |
| 390 | int currentIconHeight = 0, currentIconWidth = 0; |
| 391 | int currentIconOffsetY = 0, currentIconOffsetX = 0; |
| 392 | int UnselectedIconOffsetY = (int)((actualLineHeight - mUnselectedIconHeight) / 2), SelectedIconOffsetY = (int)((actualLineHeight - mSelectedIconHeight) / 2); |
| 393 | int UnselectedIconOffsetX = (mIconWidth - mUnselectedIconWidth) / 2, SelectedIconOffsetX = (mIconWidth - mSelectedIconWidth) / 2; |
| 394 | int actualSelection = mStart; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 395 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 396 | if (isHighlighted) { |
| 397 | int selectY = scrollingY; |
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 | // Locate the correct line for highlighting |
| 400 | while (selectY + actualLineHeight < startSelection) { |
| 401 | selectY += actualLineHeight; |
| 402 | actualSelection++; |
| 403 | } |
| 404 | if (hasHighlightColor) { |
| 405 | // Highlight the area |
| 406 | gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, 255); |
| 407 | int HighlightHeight = actualLineHeight; |
| 408 | if (mRenderY + mHeaderH + selectY + actualLineHeight > mRenderH + mRenderY) { |
| 409 | HighlightHeight = actualLineHeight - (mRenderY + mHeaderH + selectY + actualLineHeight - mRenderH - mRenderY); |
| 410 | } |
| 411 | gr_fill(mRenderX, mRenderY + mHeaderH + selectY, mRenderW, HighlightHeight); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | for (line = 0; line < lines; line++) |
| 416 | { |
| 417 | Resource* icon; |
| 418 | std::string label; |
| 419 | |
| 420 | if (line + mStart >= listSize) |
| 421 | continue; |
| 422 | |
| 423 | label = mList.at(line + mStart).displayName; |
| 424 | if (isHighlighted && hasFontHighlightColor && line + mStart == actualSelection) { |
| 425 | // Use the highlight color for the font |
| 426 | gr_color(mFontHighlightColor.red, mFontHighlightColor.green, mFontHighlightColor.blue, 255); |
| 427 | } else { |
| 428 | // Set the color for the font |
| 429 | gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, 255); |
| 430 | } |
| 431 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 432 | if (mList.at(line + mStart).selected != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 433 | { |
| 434 | icon = mIconSelected; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 435 | currentIconHeight = mSelectedIconHeight; |
| 436 | currentIconWidth = mSelectedIconWidth; |
| 437 | currentIconOffsetY = SelectedIconOffsetY; |
| 438 | currentIconOffsetX = SelectedIconOffsetX; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 439 | } |
| 440 | else |
| 441 | { |
| 442 | icon = mIconUnselected; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 443 | currentIconHeight = mSelectedIconHeight; |
| 444 | currentIconWidth = mSelectedIconWidth; |
| 445 | currentIconOffsetY = SelectedIconOffsetY; |
| 446 | currentIconOffsetX = SelectedIconOffsetX; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 447 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 448 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 449 | if (icon && icon->GetResource()) |
| 450 | { |
| 451 | int rect_y = 0, image_y = (yPos + currentIconOffsetY); |
| 452 | if (image_y + currentIconHeight > mRenderY + mRenderH) |
| 453 | rect_y = mRenderY + mRenderH - image_y; |
| 454 | else |
| 455 | rect_y = currentIconHeight; |
| 456 | gr_blit(icon->GetResource(), 0, 0, currentIconWidth, rect_y, mRenderX + currentIconOffsetX, image_y); |
| 457 | } |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 458 | 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] | 459 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 460 | // Add the separator |
| 461 | if (yPos + actualLineHeight < mRenderH + mRenderY) { |
| 462 | gr_color(mSeparatorColor.red, mSeparatorColor.green, mSeparatorColor.blue, 255); |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 463 | gr_fill(mRenderX, yPos + actualLineHeight - mSeparatorH, listW, mSeparatorH); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 464 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 465 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 466 | // Move the yPos |
| 467 | yPos += actualLineHeight; |
| 468 | } |
| 469 | |
| 470 | // Render the Header (last so that it overwrites the top most row for per pixel scrolling) |
| 471 | // First step, fill background |
| 472 | gr_color(mHeaderBackgroundColor.red, mHeaderBackgroundColor.green, mHeaderBackgroundColor.blue, 255); |
| 473 | gr_fill(mRenderX, mRenderY, mRenderW, mHeaderH); |
| 474 | |
| 475 | // Now, we need the header (icon + text) |
| 476 | yPos = mRenderY; |
| 477 | { |
| 478 | Resource* headerIcon; |
| 479 | int mIconOffsetX = 0; |
| 480 | |
| 481 | // render the icon if it exists |
| 482 | headerIcon = mHeaderIcon; |
| 483 | if (headerIcon && headerIcon->GetResource()) |
| 484 | { |
| 485 | gr_blit(headerIcon->GetResource(), 0, 0, mHeaderIconWidth, mHeaderIconHeight, mRenderX + ((mHeaderIconWidth - mIconWidth) / 2), (yPos + (int)((mHeaderH - mHeaderIconHeight) / 2))); |
| 486 | mIconOffsetX = mIconWidth; |
| 487 | } |
| 488 | |
| 489 | // render the text |
| 490 | gr_color(mHeaderFontColor.red, mHeaderFontColor.green, mHeaderFontColor.blue, 255); |
| 491 | gr_textExWH(mRenderX + mIconOffsetX + 5, yPos + (int)((mHeaderH - mFontHeight) / 2), mLastValue.c_str(), fontResource, mRenderX + mRenderW, mRenderY + mRenderH); |
| 492 | |
| 493 | // Add the separator |
| 494 | gr_color(mHeaderSeparatorColor.red, mHeaderSeparatorColor.green, mHeaderSeparatorColor.blue, 255); |
| 495 | gr_fill(mRenderX, yPos + mHeaderH - mHeaderSeparatorH, mRenderW, mHeaderSeparatorH); |
| 496 | } |
| 497 | |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 498 | // render fast scroll |
| 499 | lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 500 | if(mFastScrollW > 0 && listSize > lines) |
| 501 | { |
| 502 | int startX = listW + mRenderX; |
| 503 | int fWidth = mRenderW - listW; |
| 504 | int fHeight = mRenderH - mHeaderH; |
| 505 | |
| 506 | // line |
| 507 | gr_color(mFastScrollLineColor.red, mFastScrollLineColor.green, mFastScrollLineColor.blue, 255); |
| 508 | gr_fill(startX + fWidth/2, mRenderY + mHeaderH, mFastScrollLineW, mRenderH - mHeaderH); |
| 509 | |
| 510 | // rect |
| 511 | int pct = ((mStart*actualLineHeight - scrollingY)*100)/((listSize)*actualLineHeight-lines*actualLineHeight); |
| 512 | mFastScrollRectX = startX + (fWidth - mFastScrollRectW)/2; |
| 513 | mFastScrollRectY = mRenderY+mHeaderH + ((fHeight - mFastScrollRectH)*pct)/100; |
| 514 | |
| 515 | gr_color(mFastScrollRectColor.red, mFastScrollRectColor.green, mFastScrollRectColor.blue, 255); |
| 516 | gr_fill(mFastScrollRectX, mFastScrollRectY, mFastScrollRectW, mFastScrollRectH); |
| 517 | } |
| 518 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 519 | mUpdate = 0; |
| 520 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | int GUIListBox::Update(void) |
| 524 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 525 | if (!mHeaderIsStatic) { |
| 526 | std::string newValue = gui_parse_text(mHeaderText); |
| 527 | if (mLastValue != newValue) { |
| 528 | mLastValue = newValue; |
| 529 | mUpdate = 1; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (mUpdate) |
| 534 | { |
| 535 | mUpdate = 0; |
| 536 | if (Render() == 0) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 537 | return 2; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // Handle kinetic scrolling |
| 541 | if (scrollingSpeed == 0) { |
| 542 | // Do nothing |
| 543 | } else if (scrollingSpeed > 0) { |
| 544 | if (scrollingSpeed < ((int) (actualLineHeight * 2.5))) { |
| 545 | scrollingY += scrollingSpeed; |
| 546 | scrollingSpeed -= SCROLLING_SPEED_DECREMENT; |
| 547 | } else { |
| 548 | scrollingY += ((int) (actualLineHeight * 2.5)); |
| 549 | scrollingSpeed -= SCROLLING_SPEED_DECREMENT; |
| 550 | } |
| 551 | while (mStart && scrollingY > 0) { |
| 552 | mStart--; |
| 553 | scrollingY -= actualLineHeight; |
| 554 | } |
| 555 | if (mStart == 0 && scrollingY > 0) { |
| 556 | scrollingY = 0; |
| 557 | scrollingSpeed = 0; |
| 558 | } else if (scrollingSpeed < SCROLLING_FLOOR) |
| 559 | scrollingSpeed = 0; |
| 560 | mUpdate = 1; |
| 561 | } else if (scrollingSpeed < 0) { |
| 562 | int totalSize = mList.size(); |
| 563 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 564 | |
| 565 | if (totalSize > lines) { |
| 566 | int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight); |
| 567 | |
| 568 | bottom_offset -= actualLineHeight; |
| 569 | |
| 570 | if (abs(scrollingSpeed) < ((int) (actualLineHeight * 2.5))) { |
| 571 | scrollingY += scrollingSpeed; |
| 572 | scrollingSpeed += SCROLLING_SPEED_DECREMENT; |
| 573 | } else { |
| 574 | scrollingY -= ((int) (actualLineHeight * 2.5)); |
| 575 | scrollingSpeed += SCROLLING_SPEED_DECREMENT; |
| 576 | } |
| 577 | while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) { |
| 578 | mStart++; |
| 579 | scrollingY += actualLineHeight; |
| 580 | } |
| 581 | if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) { |
| 582 | mStart = totalSize - lines - 1; |
| 583 | scrollingY = bottom_offset; |
| 584 | } else if (mStart + lines >= totalSize && scrollingY < 0) { |
| 585 | mStart = totalSize - lines; |
| 586 | scrollingY = 0; |
| 587 | } else if (scrollingSpeed * -1 < SCROLLING_FLOOR) |
| 588 | scrollingSpeed = 0; |
| 589 | mUpdate = 1; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | int GUIListBox::GetSelection(int x, int y) |
| 597 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 598 | // We only care about y position |
| 599 | if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) return -1; |
| 600 | return (y - mRenderY - mHeaderH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 604 | { |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 605 | static int lastY = 0, last2Y = 0, fastScroll = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 606 | int selection = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 607 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 608 | switch (state) |
| 609 | { |
| 610 | case TOUCH_START: |
| 611 | if (scrollingSpeed != 0) |
| 612 | startSelection = -1; |
| 613 | else |
| 614 | startSelection = GetSelection(x,y); |
| 615 | isHighlighted = (startSelection > -1); |
| 616 | if (isHighlighted) |
| 617 | mUpdate = 1; |
| 618 | startY = lastY = last2Y = y; |
| 619 | scrollingSpeed = 0; |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 620 | |
| 621 | if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW) |
| 622 | fastScroll = 1; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 623 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 624 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 625 | case TOUCH_DRAG: |
| 626 | // Check if we dragged out of the selection window |
| 627 | if (GetSelection(x, y) == -1) { |
| 628 | last2Y = lastY = 0; |
| 629 | if (isHighlighted) { |
| 630 | isHighlighted = false; |
| 631 | mUpdate = 1; |
| 632 | } |
| 633 | break; |
| 634 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 635 | |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 636 | // Fast scroll |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 637 | if(fastScroll) |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 638 | { |
| 639 | int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH); |
| 640 | int totalSize = mList.size(); |
| 641 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
| 642 | |
| 643 | float l = float((totalSize-lines)*pct)/100; |
| 644 | if(l + lines >= totalSize) |
| 645 | { |
| 646 | mStart = totalSize - lines; |
| 647 | scrollingY = 0; |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | mStart = l; |
| 652 | scrollingY = -(l - int(l))*actualLineHeight; |
| 653 | } |
| 654 | |
| 655 | startSelection = -1; |
| 656 | mUpdate = 1; |
| 657 | scrollingSpeed = 0; |
| 658 | isHighlighted = false; |
| 659 | break; |
| 660 | } |
| 661 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 662 | // Provide some debounce on initial touches |
| 663 | if (startSelection != -1 && abs(y - startY) < touchDebounce) { |
| 664 | isHighlighted = true; |
| 665 | mUpdate = 1; |
| 666 | break; |
| 667 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 668 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 669 | isHighlighted = false; |
| 670 | last2Y = lastY; |
| 671 | lastY = y; |
| 672 | startSelection = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 673 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 674 | // Handle scrolling |
| 675 | scrollingY += y - startY; |
| 676 | startY = y; |
| 677 | while(mStart && scrollingY > 0) { |
| 678 | mStart--; |
| 679 | scrollingY -= actualLineHeight; |
| 680 | } |
| 681 | if (mStart == 0 && scrollingY > 0) |
| 682 | scrollingY = 0; |
| 683 | { |
| 684 | int totalSize = mList.size(); |
| 685 | int lines = (mRenderH - mHeaderH) / (actualLineHeight); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 686 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 687 | if (totalSize > lines) { |
| 688 | int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 689 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 690 | bottom_offset -= actualLineHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 691 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 692 | while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) { |
| 693 | mStart++; |
| 694 | scrollingY += actualLineHeight; |
| 695 | } |
| 696 | if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) { |
| 697 | mStart = totalSize - lines - 1; |
| 698 | scrollingY = bottom_offset; |
| 699 | } else if (mStart + lines >= totalSize && scrollingY < 0) { |
| 700 | mStart = totalSize - lines; |
| 701 | scrollingY = 0; |
| 702 | } |
| 703 | } else |
| 704 | scrollingY = 0; |
| 705 | } |
| 706 | mUpdate = 1; |
| 707 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 708 | |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 709 | case TOUCH_RELEASE: |
| 710 | isHighlighted = false; |
Vojtech Bocek | 59e51a4 | 2014-01-29 19:11:15 +0100 | [diff] [blame] | 711 | fastScroll = 0; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 712 | if (startSelection >= 0) |
| 713 | { |
| 714 | // We've selected an item! |
| 715 | std::string str; |
| 716 | |
| 717 | int listSize = mList.size(); |
| 718 | int selectY = scrollingY, actualSelection = mStart; |
| 719 | |
| 720 | // Move the selection to the proper place in the array |
| 721 | while (selectY + actualLineHeight < startSelection) { |
| 722 | selectY += actualLineHeight; |
| 723 | actualSelection++; |
| 724 | } |
| 725 | |
| 726 | if (actualSelection < listSize && !mVariable.empty()) |
| 727 | { |
| 728 | int i; |
| 729 | for (i=0; i<listSize; i++) |
| 730 | mList.at(i).selected = 0; |
| 731 | |
| 732 | str = mList.at(actualSelection).variableValue; |
| 733 | mList.at(actualSelection).selected = 1; |
| 734 | DataManager::SetValue(mVariable, str); |
| 735 | mUpdate = 1; |
Vojtech Bocek | 5af8f3f | 2014-02-08 02:21:23 +0100 | [diff] [blame] | 736 | |
| 737 | DataManager::Vibrate("tw_button_vibrate"); |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 738 | } |
| 739 | } else { |
| 740 | // This is for kinetic scrolling |
| 741 | scrollingSpeed = lastY - last2Y; |
| 742 | if (abs(scrollingSpeed) > SCROLLING_FLOOR) |
| 743 | scrollingSpeed *= SCROLLING_MULTIPLIER; |
| 744 | else |
| 745 | scrollingSpeed = 0; |
| 746 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 747 | case TOUCH_REPEAT: |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 748 | case TOUCH_HOLD: |
| 749 | break; |
| 750 | } |
| 751 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | int GUIListBox::NotifyVarChange(std::string varName, std::string value) |
| 755 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 756 | if (!mHeaderIsStatic) { |
| 757 | std::string newValue = gui_parse_text(mHeaderText); |
| 758 | if (mLastValue != newValue) { |
| 759 | mLastValue = newValue; |
| 760 | mStart = 0; |
| 761 | scrollingY = 0; |
| 762 | scrollingSpeed = 0; |
| 763 | mUpdate = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 765 | } |
| 766 | if (varName == mVariable) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 767 | { |
| 768 | int i, listSize = mList.size(), selected_index = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 769 | |
| 770 | currentValue = value; |
| 771 | |
| 772 | for (i=0; i<listSize; i++) { |
| 773 | if (mList.at(i).variableValue == currentValue) { |
| 774 | mList.at(i).selected = 1; |
| 775 | selected_index = i; |
| 776 | } else |
| 777 | mList.at(i).selected = 0; |
| 778 | } |
| 779 | |
| 780 | int lines = mRenderH / (mLineHeight + mLineSpacing); |
| 781 | int line; |
| 782 | |
| 783 | if (selected_index > mStart + lines - 1) |
| 784 | mStart = selected_index; |
| 785 | if (mStart > listSize - lines) { |
| 786 | mStart = listSize - lines; |
| 787 | } else if (selected_index < mStart) { |
| 788 | mStart = selected_index; |
| 789 | } |
| 790 | |
| 791 | mUpdate = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 792 | return 0; |
| 793 | } |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 794 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | int GUIListBox::SetRenderPos(int x, int y, int w /* = 0 */, int h /* = 0 */) |
| 798 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 799 | mRenderX = x; |
| 800 | mRenderY = y; |
| 801 | if (w || h) |
| 802 | { |
| 803 | mRenderW = w; |
| 804 | mRenderH = h; |
| 805 | } |
| 806 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 807 | mUpdate = 1; |
| 808 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void GUIListBox::SetPageFocus(int inFocus) |
| 812 | { |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 813 | if (inFocus) |
| 814 | { |
| 815 | DataManager::GetValue(mVariable, currentValue); |
| 816 | NotifyVarChange(mVariable, currentValue); |
| 817 | mUpdate = 1; |
| 818 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 819 | } |