Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // console.cpp - GUIConsole object |
| 2 | |
| 3 | #include <stdarg.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <sys/reboot.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <sys/time.h> |
| 11 | #include <sys/mman.h> |
| 12 | #include <sys/types.h> |
| 13 | #include <sys/ioctl.h> |
| 14 | #include <time.h> |
| 15 | #include <unistd.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 21 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | #include "rapidxml.hpp" |
| 26 | #include "objects.hpp" |
| 27 | |
| 28 | |
| 29 | static std::vector<std::string> gConsole; |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 30 | static std::vector<std::string> gConsoleColor; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 31 | static FILE* ors_file; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 32 | |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 33 | extern "C" void __gui_print(const char *color, char *buf) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 34 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 35 | char *start, *next; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
| 37 | if (buf[0] == '\n' && strlen(buf) < 2) { |
| 38 | // This prevents the double lines bug seen in the console during zip installs |
| 39 | return; |
| 40 | } |
| 41 | |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 42 | for (start = next = buf; *next != '\0';) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 43 | { |
| 44 | if (*next == '\n') |
| 45 | { |
| 46 | *next = '\0'; |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 47 | gConsole.push_back(start); |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 48 | gConsoleColor.push_back(color); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 50 | start = ++next; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 51 | } |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 52 | else |
| 53 | ++next; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 54 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 56 | // The text after last \n (or whole string if there is no \n) |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 57 | if(*start) { |
Vojtech Bocek | d5b26d6 | 2014-03-06 22:56:13 +0100 | [diff] [blame] | 58 | gConsole.push_back(start); |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 59 | gConsoleColor.push_back(color); |
| 60 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 61 | if (ors_file) { |
| 62 | fprintf(ors_file, "%s\n", buf); |
| 63 | fflush(ors_file); |
| 64 | } |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | extern "C" void gui_print(const char *fmt, ...) |
| 68 | { |
| 69 | char buf[512]; // We're going to limit a single request to 512 bytes |
| 70 | |
| 71 | va_list ap; |
| 72 | va_start(ap, fmt); |
| 73 | vsnprintf(buf, 512, fmt, ap); |
| 74 | va_end(ap); |
| 75 | |
| 76 | fputs(buf, stdout); |
| 77 | |
| 78 | __gui_print("normal", buf); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | extern "C" void gui_print_color(const char *color, const char *fmt, ...) |
| 83 | { |
| 84 | char buf[512]; // We're going to limit a single request to 512 bytes |
| 85 | |
| 86 | va_list ap; |
| 87 | va_start(ap, fmt); |
| 88 | vsnprintf(buf, 512, fmt, ap); |
| 89 | va_end(ap); |
| 90 | |
| 91 | fputs(buf, stdout); |
| 92 | |
| 93 | __gui_print(color, buf); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 94 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 97 | extern "C" void gui_set_FILE(FILE* f) |
| 98 | { |
| 99 | ors_file = f; |
| 100 | } |
| 101 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 102 | GUIConsole::GUIConsole(xml_node<>* node) : GUIScrollList(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 103 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 104 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | mLastCount = 0; |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 107 | scrollToEnd = true; |
| 108 | mSlideoutX = mSlideoutY = mSlideoutW = mSlideoutH = 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | mSlideout = 0; |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 110 | mSlideoutState = visible; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 111 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 112 | allowSelection = false; // console doesn't support list item selections |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 113 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 114 | if (!node) |
| 115 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 116 | mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 117 | } |
| 118 | else |
| 119 | { |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 120 | child = FindNode(node, "color"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 121 | if (child) |
| 122 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 123 | mFontColor = LoadAttrColor(child, "foreground", mFontColor); |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 124 | mBackgroundColor = LoadAttrColor(child, "background", mBackgroundColor); |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 125 | //mScrollColor = LoadAttrColor(child, "scroll", mScrollColor); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 126 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 127 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 128 | child = FindNode(node, "slideout"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 129 | if (child) |
| 130 | { |
| 131 | mSlideout = 1; |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 132 | mSlideoutState = hidden; |
Ethan Yonker | 591b920 | 2015-03-11 11:17:15 -0500 | [diff] [blame] | 133 | LoadPlacement(child, &mSlideoutX, &mSlideoutY, &mSlideoutW, &mSlideoutH, &mPlacement); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 134 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 135 | mSlideoutImage = LoadAttrImage(child, "resource"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 136 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 137 | if (mSlideoutImage && mSlideoutImage->GetResource()) |
| 138 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 139 | mSlideoutW = mSlideoutImage->GetWidth(); |
| 140 | mSlideoutH = mSlideoutImage->GetHeight(); |
Ethan Yonker | 591b920 | 2015-03-11 11:17:15 -0500 | [diff] [blame] | 141 | if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY) { |
| 142 | mSlideoutX = mSlideoutX - (mSlideoutW / 2); |
| 143 | if (mPlacement == CENTER) { |
| 144 | mSlideoutY = mSlideoutY - (mSlideoutH / 2); |
| 145 | } |
| 146 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | int GUIConsole::RenderSlideout(void) |
| 153 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 154 | if (!mSlideoutImage || !mSlideoutImage->GetResource()) |
| 155 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 156 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 157 | gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY); |
| 158 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 159 | } |
| 160 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 161 | bool GUIConsole::AddLines() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 162 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 163 | if (mLastCount == gConsole.size()) |
| 164 | return false; // nothing to add |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 165 | |
that | 05360ba | 2015-02-06 00:58:16 +0100 | [diff] [blame] | 166 | size_t prevCount = mLastCount; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 167 | mLastCount = gConsole.size(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 168 | |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 169 | // Due to word wrap, figure out what / how the newly added text needs to be added to the render vector that is word wrapped |
| 170 | // Note, that multiple consoles on different GUI pages may be different widths or use different fonts, so the word wrapping |
| 171 | // may different in different console windows |
that | 05360ba | 2015-02-06 00:58:16 +0100 | [diff] [blame] | 172 | for (size_t i = prevCount; i < mLastCount; i++) { |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 173 | string curr_line = gConsole[i]; |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 174 | string curr_color = gConsoleColor[i]; |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 175 | for(;;) { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 176 | size_t line_char_width = gr_maxExW(curr_line.c_str(), mFont->GetResource(), mRenderW); |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 177 | if (line_char_width < curr_line.size()) { |
| 178 | rConsole.push_back(curr_line.substr(0, line_char_width)); |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 179 | rConsoleColor.push_back(curr_color); |
Ethan Yonker | 6b4276f | 2014-03-07 06:48:45 -0600 | [diff] [blame] | 180 | curr_line = curr_line.substr(line_char_width); |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 181 | } else { |
| 182 | rConsole.push_back(curr_line); |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 183 | rConsoleColor.push_back(curr_color); |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 184 | break; |
| 185 | } |
| 186 | } |
| 187 | } |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 188 | return true; |
| 189 | } |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 190 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 191 | int GUIConsole::RenderConsole(void) |
| 192 | { |
| 193 | AddLines(); |
| 194 | GUIScrollList::Render(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 196 | // if last line is fully visible, keep tracking the last line when new lines are added |
| 197 | int bottom_offset = GetDisplayRemainder() - actualItemHeight; |
| 198 | bool isAtBottom = firstDisplayedItem == GetItemCount() - GetDisplayItemCount() - (bottom_offset != 0) && y_offset == bottom_offset; |
| 199 | if (isAtBottom) |
| 200 | scrollToEnd = true; |
| 201 | #if 0 |
| 202 | // debug - show if we are tracking the last line |
| 203 | if (scrollToEnd) { |
| 204 | gr_color(0,255,0,255); |
| 205 | gr_fill(mRenderX+mRenderW-5, mRenderY+mRenderH-5, 5, 5); |
| 206 | } else { |
| 207 | gr_color(255,0,0,255); |
| 208 | gr_fill(mRenderX+mRenderW-5, mRenderY+mRenderH-5, 5, 5); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 209 | } |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 210 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 211 | return (mSlideout ? RenderSlideout() : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | int GUIConsole::Render(void) |
| 215 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 216 | if(!isConditionTrue()) |
| 217 | return 0; |
| 218 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 219 | if (mSlideout && mSlideoutState == hidden) |
| 220 | return RenderSlideout(); |
| 221 | |
| 222 | return RenderConsole(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | int GUIConsole::Update(void) |
| 226 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 227 | if (mSlideout && mSlideoutState != visible) |
| 228 | { |
| 229 | if (mSlideoutState == hidden) |
| 230 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 231 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 232 | if (mSlideoutState == request_hide) |
| 233 | mSlideoutState = hidden; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 234 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 235 | if (mSlideoutState == request_show) |
| 236 | mSlideoutState = visible; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 237 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 238 | // Any time we activate the console, we reset the position |
| 239 | SetVisibleListLocation(rConsole.size() - 1); |
| 240 | mUpdate = 1; |
| 241 | scrollToEnd = true; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 242 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 243 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 244 | if (AddLines()) { |
| 245 | // someone added new text |
| 246 | // at least the scrollbar must be updated, even if the new lines are currently not visible |
| 247 | mUpdate = 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 248 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 249 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 250 | if (scrollToEnd) { |
| 251 | // keep the last line in view |
| 252 | SetVisibleListLocation(rConsole.size() - 1); |
| 253 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 254 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 255 | GUIScrollList::Update(); |
| 256 | |
| 257 | if (mUpdate) { |
| 258 | mUpdate = 0; |
| 259 | if (Render() == 0) |
| 260 | return 2; |
| 261 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 262 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | // IsInRegion - Checks if the request is handled by this object |
that | f8194e2 | 2015-01-29 01:05:01 +0100 | [diff] [blame] | 266 | // Return 1 if this object handles the request, 0 if not |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 267 | int GUIConsole::IsInRegion(int x, int y) |
| 268 | { |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 269 | if (mSlideout) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 270 | // Check if they tapped the slideout button |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 271 | if (x >= mSlideoutX && x < mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 272 | return 1; |
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 | // If we're only rendering the slideout, bail now |
| 275 | if (mSlideoutState == hidden) |
| 276 | return 0; |
| 277 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 278 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 279 | return GUIScrollList::IsInRegion(x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // NotifyTouch - Notify of a touch event |
| 283 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 284 | int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 285 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 286 | if(!isConditionTrue()) |
| 287 | return -1; |
| 288 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 289 | if (mSlideout && x >= mSlideoutX && x < mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) { |
| 290 | if (state == TOUCH_START) { |
| 291 | if (mSlideoutState == hidden) |
| 292 | mSlideoutState = request_show; |
| 293 | else if (mSlideoutState == visible) |
| 294 | mSlideoutState = request_hide; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | } |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 296 | return 1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 297 | } |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 298 | scrollToEnd = false; |
| 299 | return GUIScrollList::NotifyTouch(state, x, y); |
| 300 | } |
| 301 | |
| 302 | size_t GUIConsole::GetItemCount() |
| 303 | { |
| 304 | return rConsole.size(); |
| 305 | } |
| 306 | |
| 307 | void GUIConsole::RenderItem(size_t itemindex, int yPos, bool selected) |
| 308 | { |
| 309 | // Set the color for the font |
| 310 | if (rConsoleColor[itemindex] == "normal") { |
| 311 | gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); |
| 312 | } else { |
| 313 | COLOR FontColor; |
| 314 | std::string color = rConsoleColor[itemindex]; |
| 315 | ConvertStrToColor(color, &FontColor); |
| 316 | FontColor.alpha = 255; |
| 317 | gr_color(FontColor.red, FontColor.green, FontColor.blue, FontColor.alpha); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 318 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 319 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 320 | // render text |
| 321 | const char* text = rConsole[itemindex].c_str(); |
| 322 | gr_textEx(mRenderX, yPos, text, mFont->GetResource()); |
| 323 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 324 | |
that | 8d46c09 | 2015-02-26 01:30:04 +0100 | [diff] [blame] | 325 | void GUIConsole::NotifySelect(size_t item_selected) |
| 326 | { |
| 327 | // do nothing - console ignores selections |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 328 | } |