From 29805852c875947f345aca71b6b5a62e60950ce0 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Thu, 25 Nov 2010 16:39:22 +0000 Subject: [PATCH] changed vertical scroller as per wololo's suggestion. Scroll speed is a function of the dt value gathered from Update() instead of ticks. --- projects/mtg/include/TextScroller.h | 5 +++-- projects/mtg/src/TextScroller.cpp | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/projects/mtg/include/TextScroller.h b/projects/mtg/include/TextScroller.h index 49d0bf7ba..019f88a13 100644 --- a/projects/mtg/include/TextScroller.h +++ b/projects/mtg/include/TextScroller.h @@ -41,10 +41,11 @@ private: size_t mNbItemsShown; bool mScrollerInitialized; float mHeight; // maximum height availble for display - int marginX; - int marginY; // margin used to allow text to scroll off screen without + int mMarginX; + int mMarginY; // margin used to allow text to scroll off screen without // affecting look and feel. Should be enough // for at least one line of text ( marginY) + float mVerticalScrollSpeed; protected: string wordWrap(string sentence, float width); diff --git a/projects/mtg/src/TextScroller.cpp b/projects/mtg/src/TextScroller.cpp index aab90b038..adcd7fe37 100644 --- a/projects/mtg/src/TextScroller.cpp +++ b/projects/mtg/src/TextScroller.cpp @@ -90,9 +90,9 @@ TextScroller( fontId, x, y, width, scrollSpeed) { mHeight = height; mNbItemsShown = numItemsShown; - - marginX = 0; - marginY = 215; + mVerticalScrollSpeed = 10.0f; + mMarginX = 0; + mMarginY = 215; mScrollerInitialized = false; } @@ -102,13 +102,16 @@ void VerticalTextScroller::Update(float dt) if (!strings.size()) return; WFont * mFont = resources.GetWFont(fontId); ostringstream scrollerText; - if ( mScrollerInitialized && timer % 10 == 0 ) + + // update the veritcal scrolling + if ( mScrollerInitialized ) { - mY -= 1; - if ( mY < marginY ) - mY = marginY + 20; + mY -= mVerticalScrollSpeed * dt; + if ( mY < mMarginY ) + mY = mMarginY + 20; } + // update the text if (timer == 0) { mScrollerInitialized = false; @@ -122,7 +125,7 @@ void VerticalTextScroller::Update(float dt) if (currentId >= strings.size()) currentId = 0; mText = wordWrap(scrollerText.str(), mWidth); - mY = marginY + 20; + mY = mMarginY + 20; } timer = ++timer % ((int) mScrollSpeed);