changed vertical scroller as per wololo's suggestion. Scroll speed is a function of the

dt value gathered from Update() instead of ticks.
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-25 16:39:22 +00:00
parent 22b743ccdf
commit 29805852c8
2 changed files with 14 additions and 10 deletions
+3 -2
View File
@@ -41,10 +41,11 @@ private:
size_t mNbItemsShown; size_t mNbItemsShown;
bool mScrollerInitialized; bool mScrollerInitialized;
float mHeight; // maximum height availble for display float mHeight; // maximum height availble for display
int marginX; int mMarginX;
int marginY; // margin used to allow text to scroll off screen without int mMarginY; // margin used to allow text to scroll off screen without
// affecting look and feel. Should be enough // affecting look and feel. Should be enough
// for at least one line of text ( marginY) // for at least one line of text ( marginY)
float mVerticalScrollSpeed;
protected: protected:
string wordWrap(string sentence, float width); string wordWrap(string sentence, float width);
+11 -8
View File
@@ -90,9 +90,9 @@ TextScroller( fontId, x, y, width, scrollSpeed)
{ {
mHeight = height; mHeight = height;
mNbItemsShown = numItemsShown; mNbItemsShown = numItemsShown;
mVerticalScrollSpeed = 10.0f;
marginX = 0; mMarginX = 0;
marginY = 215; mMarginY = 215;
mScrollerInitialized = false; mScrollerInitialized = false;
} }
@@ -102,13 +102,16 @@ void VerticalTextScroller::Update(float dt)
if (!strings.size()) return; if (!strings.size()) return;
WFont * mFont = resources.GetWFont(fontId); WFont * mFont = resources.GetWFont(fontId);
ostringstream scrollerText; ostringstream scrollerText;
if ( mScrollerInitialized && timer % 10 == 0 )
// update the veritcal scrolling
if ( mScrollerInitialized )
{ {
mY -= 1; mY -= mVerticalScrollSpeed * dt;
if ( mY < marginY ) if ( mY < mMarginY )
mY = marginY + 20; mY = mMarginY + 20;
} }
// update the text
if (timer == 0) if (timer == 0)
{ {
mScrollerInitialized = false; mScrollerInitialized = false;
@@ -122,7 +125,7 @@ void VerticalTextScroller::Update(float dt)
if (currentId >= strings.size()) if (currentId >= strings.size())
currentId = 0; currentId = 0;
mText = wordWrap(scrollerText.str(), mWidth); mText = wordWrap(scrollerText.str(), mWidth);
mY = marginY + 20; mY = mMarginY + 20;
} }
timer = ++timer % ((int) mScrollSpeed); timer = ++timer % ((int) mScrollSpeed);