fixed line endings

fixed horizontal scrolling to be controlled by a function of dt as per linshier suggestion.
  * this allows compatibility for multi-byte character sets
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-30 12:15:32 +00:00
parent be707e2396
commit 96cdb7353a
5 changed files with 2082 additions and 2082 deletions
+6 -6
View File
@@ -10,20 +10,20 @@ using std::string;
class DeckMenuItem: public JGuiObject class DeckMenuItem: public JGuiObject
{ {
private: private:
bool mHasFocus; bool mHasFocus;
bool mScrollEnabled; bool mScrollEnabled;
int mRemainder; // difference between the number of characters shown and full title bool mDisplayInitialized;
DeckMenu* parent; DeckMenu* parent;
int fontId; int fontId;
string mText; string mText;
float mTitleResetWidth;
public: public:
string imageFilename; string imageFilename;
string desc; string desc;
string displayName; float mScrollerOffset;
int mScrollTimer;
DeckMetaData *meta; DeckMetaData *meta;
float mX; float mX;
@@ -40,7 +40,7 @@ class DeckMenuItem: public JGuiObject
void RenderWithOffset(float yOffset); void RenderWithOffset(float yOffset);
virtual void Render(); virtual void Render();
virtual void Update( float dt );
virtual void Entering(); virtual void Entering();
virtual bool Leaving(JButton key); virtual bool Leaving(JButton key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
+1 -1
View File
@@ -40,7 +40,7 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve
mSelectedDeck = NULL; mSelectedDeck = NULL;
mY = 50; mY = 50;
mWidth = 176; mWidth = 176;
mX = 110; mX = 115;
titleX = 110; // center point in title box titleX = 110; // center point in title box
titleY = 15; titleY = 15;
+39 -35
View File
@@ -5,74 +5,78 @@
#include "WResourceManager.h" #include "WResourceManager.h"
#include <algorithm> #include <algorithm>
#define ITEM_PX_WIDTH 190.f #define ITEM_PX_WIDTH 190.0f
const int kHorizontalScrollSpeed = 10; // lower numbers mean faster scrolling
const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData) DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData)
: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y) : JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
{ {
WFont * mFont = resources.GetWFont(fontId);
meta = deckMetaData;
mText = trim(text); mText = trim(text);
displayName = text;
if (autoTranslate) if (autoTranslate)
mText = _(mText); mText = _(mText);
WFont * mFont = resources.GetWFont(fontId);
while (mFont->GetStringWidth(displayName.c_str()) > ITEM_PX_WIDTH)
displayName.erase(displayName.size() - 1);
mScrollTimer = 0;
mHasFocus = hasFocus; mHasFocus = hasFocus;
mScrollEnabled = (displayName.length() != mText.length()) ; float newImageWidth = 0.0f;
if (meta && !meta->getGamesPlayed())
if (mScrollEnabled) {
mText.append(" "); // add padding to reduce jerkiness when text scrolls JTexture * tex = resources.RetrieveTexture("new.png");
if (tex)
mRemainder = ( mText.length() - displayName.length() ); {
JQuad * quad = resources.RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle around the texture because of bilinear filtering
newImageWidth = quad->mWidth;
}
}
float titleStringWidth = mFont->GetStringWidth( mText.c_str() );
mTitleResetWidth = (titleStringWidth - newImageWidth )/ 2;
mScrollEnabled = titleStringWidth > ( ITEM_PX_WIDTH - newImageWidth );
mScrollerOffset = 0.0f;
if (hasFocus) if (hasFocus)
Entering(); Entering();
meta = deckMetaData;
if (meta && meta->getAvatarFilename().size() > 0) if (meta && meta->getAvatarFilename().size() > 0)
this->imageFilename = meta->getAvatarFilename(); this->imageFilename = meta->getAvatarFilename();
else else
this->imageFilename = "avatar.jpg"; this->imageFilename = "avatar.jpg";
mDisplayInitialized = false;
} }
void DeckMenuItem::Update(float dt)
{
mScrollerOffset += kHorizontalScrollSpeed * dt;
if ( (mScrollerOffset) > mTitleResetWidth )
mScrollerOffset = -ITEM_PX_WIDTH;
}
void DeckMenuItem::RenderWithOffset(float yOffset) void DeckMenuItem::RenderWithOffset(float yOffset)
{ {
WFont * mFont = resources.GetWFont(fontId); WFont * mFont = resources.GetWFont(fontId);
string menuItemString = displayName;
size_t offset = 0;
if ( mHasFocus && mScrollEnabled ) if (!( mHasFocus && mScrollEnabled ))
{ mScrollerOffset = 0;
offset = mScrollTimer / kHorizontalScrollSpeed; if (!mHasFocus && mScrollEnabled)
int wrapIndexEnd = mText.length() - offset; mScrollerOffset = -1 * ( GetWidth() - ITEM_PX_WIDTH )/2;
int nbWrapAroundChars = displayName.length() - wrapIndexEnd; float offSet = mScrollerOffset;
menuItemString = mText.substr(offset, displayName.length());
if ( nbWrapAroundChars > 0 )
// need to append start of title to end of menuItemString
menuItemString.append( mText.substr(0, nbWrapAroundChars ) );
}
mFont->DrawString(menuItemString.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
if ( mHasFocus && mScrollEnabled && offset == mText.length())
mScrollTimer = 0;
else if (mHasFocus && mScrollEnabled)
mScrollTimer++;
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER, offSet, ITEM_PX_WIDTH);
mDisplayInitialized = true;
//Render a "new" icon for decks that have never been played yet //Render a "new" icon for decks that have never been played yet
if (meta && !meta->getGamesPlayed()) if (meta && !meta->getGamesPlayed())
{ {
JTexture * tex = resources.RetrieveTexture("new.png"); JTexture * tex = resources.RetrieveTexture("new.png");
if (tex) if (tex)
{ {
JQuad * quad = resources.RetrieveQuad("new.png", 2, 2, tex->mWidth - 4, tex->mHeight - 4); //avoids weird rectangle aroudn the texture because of bilinear filtering JQuad * quad = resources.RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle aroudn the texture because of bilinear filtering
quad->SetHotSpot(quad->mWidth/2, quad->mHeight/2); quad->SetHotSpot(quad->mWidth/2.0f, quad->mHeight/2.0f);
float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, mFont->GetStringWidth(menuItemString.c_str()))/2 + quad->mWidth/2; float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, GetWidth() )/2 + quad->mWidth/2;
if (quad) JRenderer::GetInstance()->RenderQuad(quad, x , mY + yOffset + quad->mHeight/2, 0.5); if (quad) JRenderer::GetInstance()->RenderQuad(quad, x , mY + yOffset + quad->mHeight/2, 0.5);
} }
} }
-4
View File
@@ -17,10 +17,8 @@ vector<DeckMetaData *> GameState::fillDeckMenu(SimpleMenu * _menu, const string&
Player * statsPlayer) Player * statsPlayer)
{ {
bool translate = _menu->autoTranslate; bool translate = _menu->autoTranslate;
_menu->autoTranslate = false;
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer); vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer);
renderDeckMenu(_menu, deckMetaDataVector); renderDeckMenu(_menu, deckMetaDataVector);
_menu->autoTranslate = translate;
return deckMetaDataVector; return deckMetaDataVector;
} }
@@ -29,10 +27,8 @@ vector<DeckMetaData *> GameState::fillDeckMenu(DeckMenu * _menu, const string& p
Player * statsPlayer, int maxDecks) Player * statsPlayer, int maxDecks)
{ {
bool translate = _menu->mAutoTranslate; bool translate = _menu->mAutoTranslate;
_menu->mAutoTranslate = false;
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer, maxDecks); vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer, maxDecks);
renderDeckMenu(_menu, deckMetaDataVector); renderDeckMenu(_menu, deckMetaDataVector);
_menu->mAutoTranslate = translate;
return deckMetaDataVector; return deckMetaDataVector;
} }