forked from alphanu1/EmulationStation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "IList.h" | ||
|
||
const IList::ScrollTier IList::SCROLL_SPEED[IList::SCROLL_SPEED_COUNT] = { | ||
{500, 500}, | ||
{2600, 150}, | ||
{0, 100} | ||
}; | ||
|
||
IList::IList() | ||
{ | ||
mScrollTier = 0; | ||
mScrollVelocity = 0; | ||
mScrollTierAccumulator = 0; | ||
mScrollCursorAccumulator = 0; | ||
} | ||
|
||
void IList::listInput(int velocity) | ||
{ | ||
mScrollVelocity = velocity; | ||
mScrollTier = 0; | ||
mScrollTierAccumulator = 0; | ||
mScrollCursorAccumulator = 0; | ||
scroll(mScrollVelocity); | ||
} | ||
|
||
void IList::listUpdate(int deltaTime) | ||
{ | ||
if(mScrollVelocity == 0 || getLength() < 2) | ||
return; | ||
|
||
mScrollCursorAccumulator += deltaTime; | ||
mScrollTierAccumulator += deltaTime; | ||
|
||
while(mScrollCursorAccumulator >= SCROLL_SPEED[mScrollTier].scrollDelay) | ||
{ | ||
mScrollCursorAccumulator -= SCROLL_SPEED[mScrollTier].scrollDelay; | ||
scroll(mScrollVelocity); | ||
} | ||
|
||
// are we ready to go even FASTER? | ||
while(mScrollTier < SCROLL_SPEED_COUNT - 1 && mScrollTierAccumulator >= SCROLL_SPEED[mScrollTier].length) | ||
{ | ||
mScrollTierAccumulator -= SCROLL_SPEED[mScrollTier].length; | ||
mScrollTier++; | ||
} | ||
} | ||
|
||
void IList::scroll(int amt) | ||
{ | ||
if(mScrollVelocity == 0 || getLength() < 2) | ||
return; | ||
|
||
int cursor = getCursorIndex() + amt; | ||
int absAmt = amt < 0 ? -amt : amt; | ||
|
||
// stop at the end if we've been holding down the button for a long time or | ||
// we're scrolling faster than one item at a time (e.g. page up/down) | ||
// otherwise, loop around | ||
if(mScrollTier > 0 || absAmt > 1) | ||
{ | ||
if(cursor < 0) | ||
cursor = 0; | ||
else if(cursor >= getLength()) | ||
cursor = getLength() - 1; | ||
}else{ | ||
if(cursor < 0) | ||
cursor += getLength(); | ||
else if(cursor >= getLength()) | ||
cursor -= getLength(); | ||
} | ||
|
||
if(cursor != getCursorIndex()) | ||
onScroll(absAmt); | ||
|
||
setCursorIndex(cursor); | ||
} | ||
|
||
bool IList::isScrolling() const | ||
{ | ||
return (mScrollVelocity != 0 && mScrollTier > 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
class IList | ||
{ | ||
public: | ||
IList(); | ||
|
||
bool isScrolling() const; | ||
|
||
protected: | ||
void listInput(int velocity); // a velocity of 0 = stop scrolling | ||
void listUpdate(int deltaTime); | ||
|
||
virtual int getCursorIndex() = 0; | ||
virtual void setCursorIndex(int index) = 0; // (index >= 0 && index < getLength()) is guaranteed to be true | ||
virtual int getLength() = 0; | ||
|
||
void scroll(int amt); | ||
virtual void onScroll(int amt) {}; | ||
|
||
private: | ||
struct ScrollTier | ||
{ | ||
int length; // how long we stay on this level before going to the next | ||
int scrollDelay; // how long between scrolls | ||
}; | ||
|
||
static const int SCROLL_SPEED_COUNT = 3; | ||
static const ScrollTier SCROLL_SPEED[SCROLL_SPEED_COUNT]; | ||
|
||
int mScrollTier; | ||
int mScrollVelocity; | ||
|
||
int mScrollTierAccumulator; | ||
int mScrollCursorAccumulator; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.