2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// BusyComponent.cpp
|
|
|
|
//
|
|
|
|
// Animated busy indicator.
|
|
|
|
//
|
|
|
|
|
2014-04-19 18:37:10 +00:00
|
|
|
#include "BusyComponent.h"
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "components/AnimatedImageComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "components/TextComponent.h"
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// Animation definition.
|
2014-04-19 18:37:10 +00:00
|
|
|
AnimationFrame BUSY_ANIMATION_FRAMES[] = {
|
2020-06-28 16:39:18 +00:00
|
|
|
{":/graphics/busy_0.svg", 300},
|
|
|
|
{":/graphics/busy_1.svg", 300},
|
|
|
|
{":/graphics/busy_2.svg", 300},
|
|
|
|
{":/graphics/busy_3.svg", 300},
|
2014-04-19 18:37:10 +00:00
|
|
|
};
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2014-04-19 18:37:10 +00:00
|
|
|
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true };
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
BusyComponent::BusyComponent(Window* window): GuiComponent(window),
|
|
|
|
mBackground(window, ":/graphics/frame.png"), mGrid(window, Vector2i(5, 3))
|
2014-04-19 18:37:10 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
mAnimation = std::make_shared<AnimatedImageComponent>(mWindow);
|
|
|
|
mAnimation->load(&BUSY_ANIMATION_DEF);
|
|
|
|
mText = std::make_shared<TextComponent>(mWindow, "WORKING...",
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// 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);
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
addChild(&mBackground);
|
|
|
|
addChild(&mGrid);
|
2014-04-19 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BusyComponent::onSizeChanged()
|
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
mGrid.setSize(mSize);
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
if (mSize.x() == 0 || mSize.y() == 0)
|
|
|
|
return;
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
const float middleSpacerWidth = 0.01f * Renderer::getScreenWidth();
|
|
|
|
const float textHeight = mText->getFont()->getLetterHeight();
|
|
|
|
mText->setSize(0, textHeight);
|
|
|
|
const float textWidth = mText->getSize().x() + 4;
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
mGrid.setColWidthPerc(1, textHeight / mSize.x()); // Animation is square.
|
|
|
|
mGrid.setColWidthPerc(2, middleSpacerWidth / mSize.x());
|
|
|
|
mGrid.setColWidthPerc(3, textWidth / mSize.x());
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
mGrid.setRowHeightPerc(1, textHeight / mSize.y());
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
mBackground.fitTo(Vector2f(mGrid.getColWidth(1) +
|
|
|
|
mGrid.getColWidth(2) + mGrid.getColWidth(3), textHeight + 2),
|
|
|
|
mAnimation->getPosition(), Vector2f(0, 0));
|
2014-04-19 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BusyComponent::reset()
|
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
//mAnimation->reset();
|
2014-04-19 18:37:10 +00:00
|
|
|
}
|