Split busy animation into its own component for reusability.

Changed the design a bit.
The ScraperSearchComponent now grays out entirely + displays the busy animation in the center.
This commit is contained in:
Aloshi 2014-04-19 13:37:10 -05:00
parent 6d4288f245
commit dedfcfea4c
7 changed files with 95 additions and 44 deletions

View file

@ -164,6 +164,7 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AsyncReqComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentList.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.h
@ -255,6 +256,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AnimatedImageComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/AsyncReqComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/BusyComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentGrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentList.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.cpp

View file

@ -2,16 +2,6 @@
#include "ImageComponent.h"
#include "../Log.h"
// animation definitions because there's only one right now and i'm too lazy to make another file
AnimationFrame BUSY_ANIMATION_FRAMES[] = {
{":/busy_0.svg", 500},
{":/busy_1.svg", 500},
{":/busy_2.svg", 500},
{":/busy_3.svg", 500},
};
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true };
AnimatedImageComponent::AnimatedImageComponent(Window* window) : GuiComponent(window), mEnabled(false)
{
}

View file

@ -39,7 +39,3 @@ private:
int mFrameAccumulator;
int mCurrentFrame;
};
// animation declarations because there's only one right now and I'm too lazy to make another file
extern const AnimationDef BUSY_ANIMATION_DEF;

View file

@ -0,0 +1,58 @@
#include "BusyComponent.h"
#include "AnimatedImageComponent.h"
#include "TextComponent.h"
#include "../Renderer.h"
// animation definition
AnimationFrame BUSY_ANIMATION_FRAMES[] = {
{":/busy_0.svg", 300},
{":/busy_1.svg", 300},
{":/busy_2.svg", 300},
{":/busy_3.svg", 300},
};
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true };
using namespace Eigen;
BusyComponent::BusyComponent(Window* window) : GuiComponent(window),
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(5, 3))
{
mAnimation = std::make_shared<AnimatedImageComponent>(mWindow);
mAnimation->load(&BUSY_ANIMATION_DEF);
mText = std::make_shared<TextComponent>(mWindow, "WORKING...", Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
// col 0 = animation, col 1 = spacer, col 2 = text
mGrid.setEntry(mAnimation, Vector2i(1, 1), false, true);
mGrid.setEntry(mText, Vector2i(3, 1), false, true);
addChild(&mBackground);
addChild(&mGrid);
}
void BusyComponent::onSizeChanged()
{
mGrid.setSize(mSize);
if(mSize.x() == 0 || mSize.y() == 0)
return;
const float middleSpacerWidth = 0.01f * Renderer::getScreenWidth();
const float textHeight = mText->getFont()->getLetterHeight();
mText->setSize(0, textHeight);
const float textWidth = mText->getSize().x();
mGrid.setColWidthPerc(1, textHeight / mSize.x()); // animation is square
mGrid.setColWidthPerc(2, middleSpacerWidth / mSize.x());
mGrid.setColWidthPerc(3, textWidth / mSize.x());
mGrid.setRowHeightPerc(1, textHeight / mSize.y());
mBackground.fitTo(Vector2f(mGrid.getColWidth(1) + mGrid.getColWidth(2) + mGrid.getColWidth(3), textHeight + 2),
mAnimation->getPosition(), Vector2f(0, 0));
}
void BusyComponent::reset()
{
mAnimation->reset();
}

View file

@ -0,0 +1,23 @@
#include "../GuiComponent.h"
#include "ComponentGrid.h"
#include "NinePatchComponent.h"
class AnimatedImageComponent;
class TextComponent;
class BusyComponent : public GuiComponent
{
public:
BusyComponent(Window* window);
void onSizeChanged() override;
void reset(); // reset to frame 0
private:
NinePatchComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<AnimatedImageComponent> mAnimation;
std::shared_ptr<TextComponent> mText;
};

View file

@ -15,7 +15,7 @@
#include "../guis/GuiTextEditPopup.h"
ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window),
mGrid(window, Eigen::Vector2i(4, 3)), mBusyGrid(window, Eigen::Vector2i(3, 1)),
mGrid(window, Eigen::Vector2i(4, 3)), mBusyAnim(window),
mSearchType(type)
{
addChild(&mGrid);
@ -74,14 +74,6 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type)
mResultList = std::make_shared<ComponentList>(mWindow);
mResultList->setCursorChangedCallback([this](CursorState state) { if(state == CURSOR_STOPPED) updateInfoPane(); });
mBusyAnimation = std::make_shared<AnimatedImageComponent>(mWindow);
mBusyAnimation->load(&BUSY_ANIMATION_DEF);
mBusyText = std::make_shared<TextComponent>(mWindow, "WORKING...", Font::get(FONT_SIZE_LARGE), 0x777777FF);
// col 0 = animation, col 1 = spacer, col 2 = text
mBusyGrid.setEntry(mBusyAnimation, Vector2i(0, 0), false, true);
mBusyGrid.setEntry(mBusyText, Vector2i(2, 0), false, true);
updateViewStyle();
}
@ -152,21 +144,11 @@ void ScraperSearchComponent::onSizeChanged()
mDescContainer->setSize(mGrid.getColWidth(1)*boxartCellScale + mGrid.getColWidth(2), mResultDesc->getFont()->getHeight() * 3);
mResultDesc->setSize(mDescContainer->getSize().x(), 0); // make desc text wrap at edge of container
const float busyGridHeight = mBusyText->getSize().y();
const float busyGridWidth = (busyGridHeight + mBusyText->getSize().x()) * 1.03f;
if(busyGridWidth > 0 && busyGridHeight > 0)
{
mBusyGrid.setSize(busyGridWidth, busyGridHeight);
mBusyGrid.setColWidthPerc(0, (busyGridHeight) / busyGridWidth);
mBusyGrid.setColWidthPerc(1, 0.025f);
// in the far right
mBusyGrid.setPosition(mGrid.getColWidth(0) + mGrid.getColWidth(1) + mGrid.getColWidth(2) + (mGrid.getColWidth(3) - busyGridWidth)/2,
mGrid.getRowHeight(0) + mGrid.getRowHeight(1) + (mGrid.getRowHeight(2) - busyGridHeight) / 2);
}
mGrid.onSizeChanged();
mBusyAnim.setSize(mSize);
//mBusyAnim.setPosition(mSearchType == ALWAYS_ACCEPT_FIRST_RESULT ? mDescContainer->getPosition() : mResultList->getPosition());
//mBusyAnim.setSize(mSearchType == ALWAYS_ACCEPT_FIRST_RESULT ? mDescContainer->getSize() : mResultList->getSize());
}
void ScraperSearchComponent::updateViewStyle()
@ -351,10 +333,11 @@ void ScraperSearchComponent::render(const Eigen::Affine3f& parentTrans)
if(mBlockAccept)
{
Renderer::setMatrix(trans);
Renderer::drawRect((int)mResultList->getPosition().x(), (int)mResultList->getPosition().y(),
(int)mResultList->getSize().x(), (int)mResultList->getSize().y(), 0x00000011);
Renderer::drawRect(0.f, 0.f, mSize.x(), mSize.y(), 0x00000011);
//Renderer::drawRect((int)mResultList->getPosition().x(), (int)mResultList->getPosition().y(),
// (int)mResultList->getSize().x(), (int)mResultList->getSize().y(), 0x00000011);
mBusyGrid.render(trans);
mBusyAnim.render(trans);
}
}
@ -378,7 +361,7 @@ void ScraperSearchComponent::update(int deltaTime)
if(mBlockAccept)
{
mBusyAnimation->update(deltaTime);
mBusyAnim.update(deltaTime);
}
if(mThumbnailReq && mThumbnailReq->status() != HttpReq::REQ_IN_PROGRESS)

View file

@ -3,6 +3,7 @@
#include "../GuiComponent.h"
#include "../scrapers/Scraper.h"
#include "../components/ComponentGrid.h"
#include "../components/BusyComponent.h"
#include <functional>
#define MAX_SCRAPER_RESULTS 7
@ -98,7 +99,5 @@ private:
std::vector<ScraperSearchResult> mScraperResults;
std::unique_ptr<HttpReq> mThumbnailReq;
ComponentGrid mBusyGrid;
std::shared_ptr<AnimatedImageComponent> mBusyAnimation;
std::shared_ptr<TextComponent> mBusyText;
BusyComponent mBusyAnim;
};