implemented wrapping horizontal scrolling for deck selection screens
This commit is contained in:
@@ -12,6 +12,9 @@ class DeckMenuItem: public JGuiObject
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mHasFocus;
|
bool mHasFocus;
|
||||||
|
bool mScrollEnabled;
|
||||||
|
int mRemainder; // difference between the number of characters shown and full title
|
||||||
|
|
||||||
DeckMenu* parent;
|
DeckMenu* parent;
|
||||||
int fontId;
|
int fontId;
|
||||||
string mText;
|
string mText;
|
||||||
@@ -19,6 +22,8 @@ class DeckMenuItem: public JGuiObject
|
|||||||
public:
|
public:
|
||||||
string imageFilename;
|
string imageFilename;
|
||||||
string desc;
|
string desc;
|
||||||
|
string displayName;
|
||||||
|
int mScrollTimer;
|
||||||
DeckMetaData *meta;
|
DeckMetaData *meta;
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
@@ -26,6 +31,8 @@ class DeckMenuItem: public JGuiObject
|
|||||||
|
|
||||||
void Relocate(float x, float y);
|
void Relocate(float x, float y);
|
||||||
float GetWidth();
|
float GetWidth();
|
||||||
|
string GetText() { return mText; }
|
||||||
|
string GetDescription() { return desc; }
|
||||||
bool hasFocus();
|
bool hasFocus();
|
||||||
|
|
||||||
DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL);
|
DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL);
|
||||||
|
|||||||
@@ -5,23 +5,31 @@
|
|||||||
#include "WResourceManager.h"
|
#include "WResourceManager.h"
|
||||||
|
|
||||||
#define ITEM_PX_WIDTH 190.f
|
#define ITEM_PX_WIDTH 190.f
|
||||||
|
const int kHorizontalScrollSpeed = 10; // lower 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)
|
||||||
{
|
{
|
||||||
if (autoTranslate)
|
mText = trim(text);
|
||||||
mText = _(text);
|
displayName = text;
|
||||||
else
|
if (autoTranslate)
|
||||||
mText = text;
|
mText = _(mText);
|
||||||
|
|
||||||
//trim the string so that its width fits in the background.
|
WFont * mFont = resources.GetWFont(fontId);
|
||||||
//in the future we might want to replace this with a horizontal scrolling of long strings
|
while (mFont->GetStringWidth(displayName.c_str()) > ITEM_PX_WIDTH)
|
||||||
WFont * mFont = resources.GetWFont(fontId);
|
displayName.erase(displayName.size() - 1);
|
||||||
while (mFont->GetStringWidth(mText.c_str()) > ITEM_PX_WIDTH)
|
|
||||||
mText.erase(mText.size() - 1);
|
|
||||||
|
|
||||||
|
mScrollTimer = 0;
|
||||||
mHasFocus = hasFocus;
|
mHasFocus = hasFocus;
|
||||||
if (hasFocus)
|
mScrollEnabled = (displayName.length() != mText.length()) ;
|
||||||
|
|
||||||
|
if (mScrollEnabled)
|
||||||
|
mText.append(" "); // add padding to reduce jerkiness when text scrolls
|
||||||
|
|
||||||
|
mRemainder = ( mText.length() - displayName.length() );
|
||||||
|
|
||||||
|
|
||||||
|
if (hasFocus)
|
||||||
Entering();
|
Entering();
|
||||||
|
|
||||||
meta = deckMetaData;
|
meta = deckMetaData;
|
||||||
@@ -35,7 +43,25 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
|
|||||||
void DeckMenuItem::RenderWithOffset(float yOffset)
|
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||||
{
|
{
|
||||||
WFont * mFont = resources.GetWFont(fontId);
|
WFont * mFont = resources.GetWFont(fontId);
|
||||||
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
|
string menuItemString = displayName;
|
||||||
|
size_t offset = 0;
|
||||||
|
|
||||||
|
if ( mHasFocus && mScrollEnabled )
|
||||||
|
{
|
||||||
|
offset = mScrollTimer / kHorizontalScrollSpeed;
|
||||||
|
int wrapIndexEnd = mText.length() - offset;
|
||||||
|
int nbWrapAroundChars = displayName.length() - wrapIndexEnd;
|
||||||
|
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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckMenuItem::Render()
|
void DeckMenuItem::Render()
|
||||||
|
|||||||
Reference in New Issue
Block a user