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; |
| 30 | |
| 31 | extern "C" void gui_print(const char *fmt, ...) |
| 32 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 33 | char buf[512]; // We're going to limit a single request to 512 bytes |
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 | va_list ap; |
| 36 | va_start(ap, fmt); |
| 37 | vsnprintf(buf, 512, fmt, ap); |
| 38 | va_end(ap); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | |
Dees_Troy | 32c8eb8 | 2012-09-11 15:28:06 -0400 | [diff] [blame] | 40 | fputs(buf, stdout); |
| 41 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 42 | char *start, *next; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 43 | |
| 44 | if (buf[0] == '\n' && strlen(buf) < 2) { |
| 45 | // This prevents the double lines bug seen in the console during zip installs |
| 46 | return; |
| 47 | } |
| 48 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 49 | for (start = next = buf; *next != '\0'; next++) |
| 50 | { |
| 51 | if (*next == '\n') |
| 52 | { |
| 53 | *next = '\0'; |
| 54 | next++; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 56 | std::string line = start; |
| 57 | gConsole.push_back(line); |
| 58 | start = next; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
| 60 | // Handle the normal \n\0 case |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 61 | if (*next == '\0') |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 62 | return; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | std::string line = start; |
| 66 | gConsole.push_back(line); |
| 67 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | extern "C" void gui_print_overwrite(const char *fmt, ...) |
| 71 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 72 | char buf[512]; // We're going to limit a single request to 512 bytes |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 74 | va_list ap; |
| 75 | va_start(ap, fmt); |
| 76 | vsnprintf(buf, 512, fmt, ap); |
| 77 | va_end(ap); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 78 | |
Dees_Troy | 32c8eb8 | 2012-09-11 15:28:06 -0400 | [diff] [blame] | 79 | fputs(buf, stdout); |
| 80 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 81 | // Pop the last line, and we can continue |
| 82 | if (!gConsole.empty()) gConsole.pop_back(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | char *start, *next; |
| 85 | for (start = next = buf; *next != '\0'; next++) |
| 86 | { |
| 87 | if (*next == '\n') |
| 88 | { |
| 89 | *next = '\0'; |
| 90 | next++; |
| 91 | |
| 92 | std::string line = start; |
| 93 | gConsole.push_back(line); |
| 94 | start = next; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 95 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 96 | // Handle the normal \n\0 case |
| 97 | if (*next == '\0') |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 98 | return; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | std::string line = start; |
| 102 | gConsole.push_back(line); |
| 103 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | GUIConsole::GUIConsole(xml_node<>* node) |
| 107 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 108 | xml_attribute<>* attr; |
| 109 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 110 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 111 | mFont = NULL; |
| 112 | mCurrentLine = -1; |
| 113 | memset(&mForegroundColor, 255, sizeof(COLOR)); |
| 114 | memset(&mBackgroundColor, 0, sizeof(COLOR)); |
| 115 | mBackgroundColor.alpha = 255; |
| 116 | memset(&mScrollColor, 0x08, sizeof(COLOR)); |
| 117 | mScrollColor.alpha = 255; |
| 118 | mLastCount = 0; |
| 119 | mSlideout = 0; |
| 120 | mSlideoutState = hidden; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 122 | mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 123 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 124 | if (!node) |
| 125 | { |
| 126 | mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0; |
| 127 | mConsoleX = 0; mConsoleY = 0; mConsoleW = gr_fb_width(); mConsoleH = gr_fb_height(); |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | child = node->first_node("font"); |
| 132 | if (child) |
| 133 | { |
| 134 | attr = child->first_attribute("resource"); |
| 135 | if (attr) |
| 136 | mFont = PageManager::FindResource(attr->value()); |
| 137 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 138 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 139 | child = node->first_node("color"); |
| 140 | if (child) |
| 141 | { |
| 142 | attr = child->first_attribute("foreground"); |
| 143 | if (attr) |
| 144 | { |
| 145 | std::string color = attr->value(); |
| 146 | ConvertStrToColor(color, &mForegroundColor); |
| 147 | } |
| 148 | attr = child->first_attribute("background"); |
| 149 | if (attr) |
| 150 | { |
| 151 | std::string color = attr->value(); |
| 152 | ConvertStrToColor(color, &mBackgroundColor); |
| 153 | } |
| 154 | attr = child->first_attribute("scroll"); |
| 155 | if (attr) |
| 156 | { |
| 157 | std::string color = attr->value(); |
| 158 | ConvertStrToColor(color, &mScrollColor); |
| 159 | } |
| 160 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 161 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 162 | // Load the placement |
| 163 | LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 164 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | child = node->first_node("slideout"); |
| 166 | if (child) |
| 167 | { |
| 168 | mSlideout = 1; |
| 169 | LoadPlacement(child, &mSlideoutX, &mSlideoutY); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 170 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 171 | attr = child->first_attribute("resource"); |
| 172 | if (attr) mSlideoutImage = PageManager::FindResource(attr->value()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 173 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 174 | if (mSlideoutImage && mSlideoutImage->GetResource()) |
| 175 | { |
| 176 | mSlideoutW = gr_get_width(mSlideoutImage->GetResource()); |
| 177 | mSlideoutH = gr_get_height(mSlideoutImage->GetResource()); |
| 178 | } |
| 179 | } |
| 180 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 181 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 182 | gr_getFontDetails(mFont, &mFontHeight, NULL); |
| 183 | SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); |
| 184 | SetRenderPos(mConsoleX, mConsoleY); |
| 185 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | int GUIConsole::RenderSlideout(void) |
| 189 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 190 | if (!mSlideoutImage || !mSlideoutImage->GetResource()) |
| 191 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 192 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 193 | gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY); |
| 194 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | int GUIConsole::RenderConsole(void) |
| 198 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 199 | void* fontResource = NULL; |
| 200 | if (mFont) |
| 201 | fontResource = mFont->GetResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 202 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 203 | // We fill the background |
| 204 | gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); |
| 205 | gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 206 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 207 | gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha); |
| 208 | gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 209 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 210 | // Render the lines |
| 211 | gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 212 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 213 | // Don't try to continue to render without data |
| 214 | mLastCount = gConsole.size(); |
| 215 | if (mLastCount == 0) |
| 216 | return (mSlideout ? RenderSlideout() : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 217 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 218 | // Find the start point |
| 219 | int start; |
| 220 | int curLine = mCurrentLine; // Thread-safing (Another thread updates this value) |
| 221 | if (curLine == -1) |
| 222 | { |
| 223 | start = mLastCount - mMaxRows; |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | if (curLine > (int) mLastCount) |
| 228 | curLine = (int) mLastCount; |
| 229 | if ((int) mMaxRows > curLine) |
| 230 | curLine = (int) mMaxRows; |
| 231 | start = curLine - mMaxRows; |
| 232 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 234 | unsigned int line; |
| 235 | for (line = 0; line < mMaxRows; line++) |
| 236 | { |
| 237 | if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount) |
| 238 | gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX); |
| 239 | } |
| 240 | return (mSlideout ? RenderSlideout() : 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | int GUIConsole::Render(void) |
| 244 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | if (mSlideout && mSlideoutState == hidden) |
| 246 | return RenderSlideout(); |
| 247 | |
| 248 | return RenderConsole(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | int GUIConsole::Update(void) |
| 252 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 253 | if (mSlideout && mSlideoutState != visible) |
| 254 | { |
| 255 | if (mSlideoutState == hidden) |
| 256 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 257 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | if (mSlideoutState == request_hide) |
| 259 | mSlideoutState = hidden; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 260 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | if (mSlideoutState == request_show) |
| 262 | mSlideoutState = visible; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 263 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 264 | // Any time we activate the slider, we reset the position |
| 265 | mCurrentLine = -1; |
| 266 | return 2; |
| 267 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 268 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 269 | if (mCurrentLine == -1 && mLastCount != gConsole.size()) |
| 270 | { |
| 271 | // We can use Render, and return for just a flip |
| 272 | Render(); |
| 273 | return 2; |
| 274 | } |
| 275 | else if (mLastTouchY >= 0) |
| 276 | { |
| 277 | // They're still touching, so re-render |
| 278 | Render(); |
| 279 | mLastTouchY = -1; |
| 280 | return 2; |
| 281 | } |
| 282 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | int GUIConsole::SetRenderPos(int x, int y, int w, int h) |
| 286 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 287 | // Adjust the stub position accordingly |
| 288 | mSlideoutX += (x - mConsoleX); |
| 289 | mSlideoutY += (y - mConsoleY); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 290 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 291 | mConsoleX = x; |
| 292 | mConsoleY = y; |
| 293 | if (w || h) |
| 294 | { |
| 295 | mConsoleW = w; |
| 296 | mConsoleH = h; |
| 297 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 298 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 299 | // Calculate the max rows |
| 300 | mMaxRows = mConsoleH / mFontHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 301 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 302 | // Adjust so we always fit to bottom |
| 303 | mStartY = mConsoleY + (mConsoleH % mFontHeight); |
| 304 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // IsInRegion - Checks if the request is handled by this object |
| 308 | // Return 0 if this object handles the request, 1 if not |
| 309 | int GUIConsole::IsInRegion(int x, int y) |
| 310 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 311 | if (mSlideout) |
| 312 | { |
| 313 | // Check if they tapped the slideout button |
| 314 | if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) |
| 315 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 316 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 317 | // If we're only rendering the slideout, bail now |
| 318 | if (mSlideoutState == hidden) |
| 319 | return 0; |
| 320 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 321 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 322 | return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // NotifyTouch - Notify of a touch event |
| 326 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 327 | int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 328 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 329 | if (mSlideout && mSlideoutState == hidden) |
| 330 | { |
| 331 | if (state == TOUCH_START) |
| 332 | { |
| 333 | mSlideoutState = request_show; |
| 334 | return 1; |
| 335 | } |
| 336 | } |
| 337 | else if (mSlideout && mSlideoutState == visible) |
| 338 | { |
| 339 | // Are we sliding it back in? |
| 340 | if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH)) |
| 341 | { |
| 342 | mSlideoutState = request_hide; |
| 343 | return 1; |
| 344 | } |
| 345 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 346 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 347 | // If we don't have enough lines to scroll, throw this away. |
| 348 | if (mLastCount < mMaxRows) return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 349 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 350 | // We are scrolling!!! |
| 351 | switch (state) |
| 352 | { |
| 353 | case TOUCH_START: |
| 354 | mLastTouchX = x; |
| 355 | mLastTouchY = y; |
| 356 | if ((x - mConsoleX) > ((9 * mConsoleW) / 10)) |
| 357 | mSlideMultiplier = 10; |
| 358 | else |
| 359 | mSlideMultiplier = 1; |
| 360 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 361 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 362 | case TOUCH_DRAG: |
| 363 | // This handles tapping |
| 364 | if (x == mLastTouchX && y == mLastTouchY) break; |
| 365 | mLastTouchX = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 366 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | if (y > mLastTouchY + 5) |
| 368 | { |
| 369 | mLastTouchY = y; |
| 370 | if (mCurrentLine == -1) |
| 371 | mCurrentLine = mLastCount - 1; |
| 372 | else if (mCurrentLine > mSlideMultiplier) |
| 373 | mCurrentLine -= mSlideMultiplier; |
| 374 | else |
| 375 | mCurrentLine = mMaxRows; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 376 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 377 | if (mCurrentLine < (int) mMaxRows) |
| 378 | mCurrentLine = mMaxRows; |
| 379 | } |
| 380 | else if (y < mLastTouchY - 5) |
| 381 | { |
| 382 | mLastTouchY = y; |
| 383 | if (mCurrentLine >= 0) |
| 384 | { |
| 385 | mCurrentLine += mSlideMultiplier; |
| 386 | if (mCurrentLine >= (int) mLastCount) |
| 387 | mCurrentLine = -1; |
| 388 | } |
| 389 | } |
| 390 | break; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 391 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 392 | case TOUCH_RELEASE: |
| 393 | // On a tap, we jump to the tail |
| 394 | if (mLastTouchX >= 0) |
| 395 | mCurrentLine = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 396 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 397 | mLastTouchY = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 398 | case TOUCH_REPEAT: |
| 399 | case TOUCH_HOLD: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | break; |
| 401 | } |
| 402 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 403 | } |