Metadata now fades out while scrolling.

TextListComponent::isScrolling() now only returns true if the key has been
held down long enough for scrolling to really start.
Fixed opacity for RatingComponent and DateTimeComponent.
Exposed some more of AnimationController.
This commit is contained in:
Aloshi 2014-01-24 18:10:13 -06:00
parent 3ceeca968f
commit 253ea2b5d3
7 changed files with 60 additions and 3 deletions

View file

@ -227,6 +227,23 @@ void GuiComponent::stopAnimation(unsigned char slot)
} }
} }
bool GuiComponent::isAnimationPlaying(unsigned char slot) const
{
return mAnimationMap[slot] != NULL;
}
bool GuiComponent::isAnimationReversed(unsigned char slot) const
{
assert(mAnimationMap[slot] != NULL);
return mAnimationMap[slot]->isReversed();
}
int GuiComponent::getAnimationTime(unsigned char slot) const
{
assert(mAnimationMap[slot] != NULL);
return mAnimationMap[slot]->getTime();
}
void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
{ {
Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());

View file

@ -53,6 +53,9 @@ public:
GuiComponent* getChild(unsigned int i) const; GuiComponent* getChild(unsigned int i) const;
// animation will be automatically deleted when it completes or is stopped. // animation will be automatically deleted when it completes or is stopped.
bool isAnimationPlaying(unsigned char slot) const;
bool isAnimationReversed(unsigned char slot) const;
int getAnimationTime(unsigned char slot) const;
void setAnimation(Animation* animation, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0); void setAnimation(Animation* animation, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
void stopAnimation(unsigned char slot); void stopAnimation(unsigned char slot);

View file

@ -15,6 +15,9 @@ public:
// Returns true if the animation is complete. // Returns true if the animation is complete.
bool update(int deltaTime); bool update(int deltaTime);
inline bool isReversed() const { return mReverse; }
inline int getTime() const { return mTime; }
private: private:
Animation* mAnimation; Animation* mAnimation;
std::function<void()> mFinishedCallback; std::function<void()> mFinishedCallback;

View file

@ -142,6 +142,8 @@ void DateTimeComponent::render(const Eigen::Affine3f& parentTrans)
if(mTextCache) if(mTextCache)
{ {
std::shared_ptr<Font> font = getFont(); std::shared_ptr<Font> font = getFont();
mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity());
font->renderTextCache(mTextCache.get()); font->renderTextCache(mTextCache.get());
if(mEditing) if(mEditing)

View file

@ -82,6 +82,8 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(255, 255, 255, getOpacity());
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -100,6 +102,8 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glColor4ub(255, 255, 255, 255);
renderChildren(trans); renderChildren(trans);
} }

View file

@ -46,7 +46,7 @@ public:
void setCursor(typename std::vector<ListRow>::const_iterator& it); void setCursor(typename std::vector<ListRow>::const_iterator& it);
void stopScrolling(); void stopScrolling();
inline bool isScrolling() const { return mScrollDir != 0; } inline bool isScrolling() const { return mScrollDir != 0 && mScrollAccumulator >= 0; }
enum CursorState enum CursorState
{ {

View file

@ -1,6 +1,7 @@
#include "DetailedGameListView.h" #include "DetailedGameListView.h"
#include "../../Window.h" #include "../../Window.h"
#include "../ViewController.h" #include "../ViewController.h"
#include "../../animations/LambdaAnimation.h"
DetailedGameListView::DetailedGameListView(Window* window, FileData* root) : DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
BasicGameListView(window, root), BasicGameListView(window, root),
@ -180,10 +181,12 @@ void DetailedGameListView::updateInfoPanel()
{ {
FileData* file = (mList.getList().size() == 0 || mList.isScrolling()) ? NULL : mList.getSelected(); FileData* file = (mList.getList().size() == 0 || mList.isScrolling()) ? NULL : mList.getSelected();
bool fadingOut;
if(file == NULL) if(file == NULL)
{ {
mImage.setImage(""); //mImage.setImage("");
mDescription.setText(""); //mDescription.setText("");
fadingOut = true;
}else{ }else{
mImage.setImage(file->metadata.get("image")); mImage.setImage(file->metadata.get("image"));
mRating.setValue(file->metadata.get("rating")); mRating.setValue(file->metadata.get("rating"));
@ -198,6 +201,31 @@ void DetailedGameListView::updateInfoPanel()
mDescription.setText(file->metadata.get("desc")); mDescription.setText(file->metadata.get("desc"));
mDescContainer.resetAutoScrollTimer(); mDescContainer.resetAutoScrollTimer();
mDescContainer.setScrollPos(Eigen::Vector2d(0, 0)); mDescContainer.setScrollPos(Eigen::Vector2d(0, 0));
fadingOut = false;
}
std::vector<GuiComponent*> comps = getMDValues();
comps.push_back(&mImage);
comps.push_back(&mDescription);
std::vector<TextComponent*> labels = getMDLabels();
comps.insert(comps.end(), labels.begin(), labels.end());
for(auto it = comps.begin(); it != comps.end(); it++)
{
GuiComponent* comp = *it;
// an animation is playing
// then animate if reverse != fadingOut
// an animation is not playing
// then animate if opacity != our target opacity
if((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) ||
(!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255)))
{
auto func = [comp](float t)
{
comp->setOpacity((unsigned char)(lerp<float>(0.0f, 1.0f, t)*255));
};
comp->setAnimation(new LambdaAnimation(func, 150), nullptr, fadingOut);
}
} }
} }