diff --git a/src/components/AnimatedImageComponent.cpp b/src/components/AnimatedImageComponent.cpp index 665045df7..deb3d584a 100644 --- a/src/components/AnimatedImageComponent.cpp +++ b/src/components/AnimatedImageComponent.cpp @@ -12,10 +12,8 @@ AnimationFrame BUSY_ANIMATION_FRAMES[] = { const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true }; -AnimatedImageComponent::AnimatedImageComponent(Window* window, const AnimationDef* def) : GuiComponent(window), mEnabled(false) +AnimatedImageComponent::AnimatedImageComponent(Window* window) : GuiComponent(window), mEnabled(false) { - if(def) - load(def); } void AnimatedImageComponent::load(const AnimationDef* def) @@ -46,6 +44,12 @@ void AnimatedImageComponent::load(const AnimationDef* def) mEnabled = true; } +void AnimatedImageComponent::reset() +{ + mCurrentFrame = 0; + mFrameAccumulator = 0; +} + void AnimatedImageComponent::onSizeChanged() { for(auto it = mFrames.begin(); it != mFrames.end(); it++) diff --git a/src/components/AnimatedImageComponent.h b/src/components/AnimatedImageComponent.h index a49bc0804..fc44034e0 100644 --- a/src/components/AnimatedImageComponent.h +++ b/src/components/AnimatedImageComponent.h @@ -18,10 +18,12 @@ struct AnimationDef class AnimatedImageComponent : public GuiComponent { public: - AnimatedImageComponent(Window* window, const AnimationDef* def = NULL); + AnimatedImageComponent(Window* window); void load(const AnimationDef* def); // no reference to def is kept after loading is complete + void reset(); // set to frame 0 + void update(int deltaTime) override; void render(const Eigen::Affine3f& trans) override; diff --git a/src/components/ScraperSearchComponent.cpp b/src/components/ScraperSearchComponent.cpp index 22cb648f7..794b59a3e 100644 --- a/src/components/ScraperSearchComponent.cpp +++ b/src/components/ScraperSearchComponent.cpp @@ -6,6 +6,7 @@ #include "ImageComponent.h" #include "RatingComponent.h" #include "DateTimeComponent.h" +#include "AnimatedImageComponent.h" #include "ComponentList.h" #include "../HttpReq.h" #include "../Settings.h" @@ -14,7 +15,7 @@ #include "../guis/GuiTextEditPopup.h" ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window), - mGrid(window, Eigen::Vector2i(4, 3)), + mGrid(window, Eigen::Vector2i(4, 3)), mBusyGrid(window, Eigen::Vector2i(3, 1)), mSearchType(type) { addChild(&mGrid); @@ -73,6 +74,14 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) mResultList = std::make_shared(mWindow); mResultList->setCursorChangedCallback([this](CursorState state) { if(state == CURSOR_STOPPED) updateInfoPane(); }); + mBusyAnimation = std::make_shared(mWindow); + mBusyAnimation->load(&BUSY_ANIMATION_DEF); + mBusyText = std::make_shared(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(); } @@ -143,6 +152,20 @@ 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(); } @@ -330,6 +353,8 @@ void ScraperSearchComponent::render(const Eigen::Affine3f& parentTrans) Renderer::setMatrix(trans); Renderer::drawRect((int)mResultList->getPosition().x(), (int)mResultList->getPosition().y(), (int)mResultList->getSize().x(), (int)mResultList->getSize().y(), 0x00000011); + + mBusyGrid.render(trans); } } @@ -351,6 +376,11 @@ void ScraperSearchComponent::update(int deltaTime) { GuiComponent::update(deltaTime); + if(mBlockAccept) + { + mBusyAnimation->update(deltaTime); + } + if(mThumbnailReq && mThumbnailReq->status() != HttpReq::REQ_IN_PROGRESS) { updateThumbnail(); diff --git a/src/components/ScraperSearchComponent.h b/src/components/ScraperSearchComponent.h index e1260acac..a4cfb9b74 100644 --- a/src/components/ScraperSearchComponent.h +++ b/src/components/ScraperSearchComponent.h @@ -14,7 +14,7 @@ class TextComponent; class DateTimeComponent; class ScrollableContainer; class HttpReq; - +class AnimatedImageComponent; class ScraperSearchComponent : public GuiComponent { @@ -97,4 +97,8 @@ private: std::unique_ptr mMDResolveHandle; std::vector mScraperResults; std::unique_ptr mThumbnailReq; + + ComponentGrid mBusyGrid; + std::shared_ptr mBusyAnimation; + std::shared_ptr mBusyText; };