2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2023-12-16 18:48:25 +00:00
|
|
|
// ES-DE
|
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-04-19 18:37:10 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
BusyComponent::BusyComponent()
|
|
|
|
: mBackground {":/graphics/frame.png"}
|
|
|
|
, mGrid {glm::ivec2 {5, 3}}
|
2014-04-19 18:37:10 +00:00
|
|
|
{
|
2022-01-19 17:01:54 +00:00
|
|
|
mAnimation = std::make_shared<AnimatedImageComponent>();
|
2023-05-07 20:56:24 +00:00
|
|
|
mText = std::make_shared<TextComponent>("WORKING...", Font::get(FONT_SIZE_MEDIUM),
|
|
|
|
mMenuColorPrimary);
|
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.
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mAnimation, glm::ivec2 {1, 1}, false, true);
|
|
|
|
mGrid.setEntry(mText, glm::ivec2 {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()
|
|
|
|
{
|
2023-07-29 14:33:07 +00:00
|
|
|
mGrid.setSize(glm::round(mSize));
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2021-08-16 16:25:01 +00:00
|
|
|
if (mSize.x == 0.0f || mSize.y == 0.0f)
|
2020-06-28 16:39:18 +00:00
|
|
|
return;
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2022-02-11 22:38:23 +00:00
|
|
|
const float middleSpacerWidth {0.01f * Renderer::getScreenWidth()};
|
|
|
|
const float textHeight {mText->getFont()->getLetterHeight()};
|
2020-06-28 16:39:18 +00:00
|
|
|
mText->setSize(0, textHeight);
|
2022-02-11 22:38:23 +00:00
|
|
|
const float textWidth {mText->getSize().x + (4.0f * Renderer::getScreenWidthModifier())};
|
2014-04-19 18:37:10 +00:00
|
|
|
|
2021-08-16 16:25:01 +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
|
|
|
|
2023-07-29 18:27:36 +00:00
|
|
|
mGrid.setRowHeightPerc(1, mText->getFont()->getLetterHeight() / mSize.y);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2023-02-07 17:51:04 +00:00
|
|
|
mBackground.setCornerSize({16.0f * Renderer::getScreenResolutionModifier(),
|
|
|
|
16.0f * Renderer::getScreenResolutionModifier()});
|
2022-01-16 11:09:55 +00:00
|
|
|
mBackground.fitTo(glm::vec2 {mGrid.getColWidth(1) + mGrid.getColWidth(2) + mGrid.getColWidth(3),
|
2023-02-07 17:51:04 +00:00
|
|
|
textHeight + (2.0f * Renderer::getScreenResolutionModifier())},
|
2023-04-30 14:49:51 +00:00
|
|
|
mAnimation->getPosition(), glm::vec2 {0.0f, 0.0f});
|
2023-05-07 20:56:24 +00:00
|
|
|
mBackground.setFrameColor(mMenuColorFrameBusyComponent);
|
|
|
|
|
|
|
|
AnimationFrame BUSY_ANIMATION_FRAMES[] {
|
|
|
|
{":/graphics/busy_0.svg", 300},
|
|
|
|
{":/graphics/busy_1.svg", 300},
|
|
|
|
{":/graphics/busy_2.svg", 300},
|
|
|
|
{":/graphics/busy_3.svg", 300},
|
|
|
|
};
|
2023-02-15 22:58:50 +00:00
|
|
|
|
2023-05-07 20:56:24 +00:00
|
|
|
const AnimationDef animationDef {BUSY_ANIMATION_FRAMES, 4, mMenuColorBusyComponent, true};
|
|
|
|
mAnimation->load(&animationDef);
|
2014-04-19 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BusyComponent::reset()
|
|
|
|
{
|
2021-07-07 18:31:46 +00:00
|
|
|
// mAnimation->reset();
|
2014-04-19 18:37:10 +00:00
|
|
|
}
|