|
13 | 13 | #include <sys/stat.h>
|
14 | 14 | #include <algorithm>
|
15 | 15 |
|
16 |
| -#if defined(__WIIU__) |
17 |
| -#include <sysapp/launch.h> |
18 |
| -#endif |
19 |
| - |
20 | 16 | #if defined(WIN32)
|
21 | 17 | #include <sys/types.h>
|
22 | 18 | #endif
|
@@ -79,23 +75,40 @@ bool FileBrowser::process(InputEvents* events)
|
79 | 75 |
|
80 | 76 | int cardY = currentCard->yAbs;
|
81 | 77 |
|
82 |
| - if (!touchMode) { |
83 |
| - // keep the cursor on screen if using buttons |
84 |
| - if (highlighted <= 3) { |
85 |
| - this->y = 0; |
86 |
| - updateUI |= true; |
87 |
| - } |
88 |
| - else |
89 |
| - { |
90 |
| - if (cardY < 10) { |
91 |
| - this->y += currentCard->height; |
92 |
| - updateUI |= true; |
93 |
| - } |
94 |
| - if (cardY > SCREEN_HEIGHT - (currentCard->height + 10)) { |
95 |
| - this->y -= currentCard->height; |
96 |
| - updateUI |= true; |
97 |
| - } |
98 |
| - } |
| 78 | + // Below code is lifted from HBAS's AppList.cpp |
| 79 | + // TODO: consolidate into Chesto's ListElement |
| 80 | + if (!touchMode && this->elements.size() > this->highlighted && this->highlighted >= 0 && this->elements[this->highlighted]) |
| 81 | + { |
| 82 | + // if our highlighted position is large enough, force scroll the screen so that our cursor stays on screen |
| 83 | + Element* curTile = this->elements[this->highlighted]; |
| 84 | + |
| 85 | + // the y-position of the currently highlighted tile, precisely on them screen (accounting for scroll) |
| 86 | + // this means that if it's < 0 or > SCREEN_HEIGHT then it's not visible |
| 87 | + int normalizedY = curTile->y + this->y; |
| 88 | + |
| 89 | + // if we're FAR out of range upwards, speed up the scroll wheel (additive) to get back in range quicker |
| 90 | + if (normalizedY < -200) |
| 91 | + events->wheelScroll += 0.15; |
| 92 | + |
| 93 | + // far out of range, for bottom of screen |
| 94 | + else if (normalizedY > SCREEN_HEIGHT - curTile->height + 200) |
| 95 | + events->wheelScroll -= 0.15; |
| 96 | + |
| 97 | + // if we're slightly out of range above, recenter at the top row slowly |
| 98 | + else if (normalizedY < -100) |
| 99 | + events->wheelScroll = 1; |
| 100 | + |
| 101 | + // special case, scroll when we're on the bottom row of the top of the not-yet-scrolled screen |
| 102 | + else if (this->y == 0 && normalizedY > SCREEN_HEIGHT/2) |
| 103 | + events->wheelScroll -= 0.5; |
| 104 | + |
| 105 | + // if we're out of range below, recenter at bottom row |
| 106 | + else if (normalizedY > SCREEN_HEIGHT - curTile->height + 100) |
| 107 | + events->wheelScroll = -1; |
| 108 | + |
| 109 | + // if the card is this close to the top, just set it the list offset to 0 to scroll up to the top |
| 110 | + else if (this->y != 0 && this->highlighted < cardsPerRow) |
| 111 | + events->wheelScroll = 1; |
99 | 112 |
|
100 | 113 | if (this->elements[this->highlighted] && this->elements[this->highlighted]->elasticCounter == NO_HIGHLIGHT)
|
101 | 114 | {
|
@@ -255,18 +268,7 @@ void FileBrowser::listfiles()
|
255 | 268 | // new folder, file, and exit buttons
|
256 | 269 | Container* con = new Container(ROW_LAYOUT, 10);
|
257 | 270 |
|
258 |
| - auto quitaction = [mainDisplay](){ |
259 |
| -#ifdef __WIIU__ |
260 |
| - // will exit via procui loop in RootDisplay |
261 |
| - SYSLaunchMenu(); |
262 |
| -#else |
263 |
| - mainDisplay->exitRequested = true; |
264 |
| - mainDisplay->isRunning = false; |
265 |
| -#endif |
266 |
| - }; |
267 |
| - |
268 |
| - con->add((new Button("Exit", SELECT_BUTTON, true))->setAction(quitaction)); |
269 |
| - mainDisplay->events->quitaction = quitaction; |
| 271 | + con->add((new Button("Exit", SELECT_BUTTON, true))->setAction(mainDisplay->events->quitaction)); |
270 | 272 |
|
271 | 273 | con->add((new Button("New Folder", X_BUTTON, true))->setAction([this, mainDisplay](){
|
272 | 274 | std::function<void(const char*)> createFunc = [this](const char* name){
|
|
0 commit comments