Rewrote most components to use BackgroundComponent instead of NinePatchComponent

This commit is contained in:
Leon Styhre 2025-02-09 18:02:47 +01:00
parent 4e12ad52b6
commit 1c3bc53315
35 changed files with 53 additions and 71 deletions

View file

@ -21,7 +21,6 @@
GuiApplicationUpdater::GuiApplicationUpdater()
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {4, 11}}
, mDownloadPercentage {0}
, mLinuxAppImage {false}

View file

@ -42,7 +42,7 @@ private:
Renderer* mRenderer;
BusyComponent mBusyAnim;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<ComponentGrid> mButtons;
std::shared_ptr<ButtonComponent> mButton1;

View file

@ -17,7 +17,6 @@
GuiLaunchScreen::GuiLaunchScreen()
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {nullptr}
, mMarquee {nullptr}
{

View file

@ -11,9 +11,9 @@
#include "GuiComponent.h"
#include "Window.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/ImageComponent.h"
#include "components/NinePatchComponent.h"
#include "components/TextComponent.h"
class FileData;
@ -34,7 +34,7 @@ public:
private:
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid* mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -44,7 +44,6 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
std::function<void()> clearGameFunc,
std::function<void()> deleteGameFunc)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {2, 6}}
, mScraperParams {scraperParams}
, mControllerBadges {BadgeComponent::getGameControllers()}

View file

@ -13,9 +13,9 @@
#include "GuiComponent.h"
#include "MetaData.h"
#include "components/BackgroundComponent.h"
#include "components/BadgeComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "components/ScrollIndicatorComponent.h"
#include "guis/GuiSettings.h"
#include "scrapers/Scraper.h"
@ -46,7 +46,7 @@ private:
void close();
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -16,7 +16,6 @@
GuiOfflineGenerator::GuiOfflineGenerator(const std::queue<FileData*>& gameQueue)
: mGameQueue {gameQueue}
, mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {6, 13}}
{
addChild(&mBackground);

View file

@ -12,6 +12,7 @@
#include "GuiComponent.h"
#include "MiximageGenerator.h"
#include "components/BackgroundComponent.h"
#include "components/ButtonComponent.h"
#include "components/ComponentGrid.h"
#include "views/ViewController.h"
@ -54,7 +55,7 @@ private:
unsigned int mGamesFailed;
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -19,7 +19,6 @@
GuiOrphanedDataCleanup::GuiOrphanedDataCleanup(std::function<void()> reloadCallback)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {4, 11}}
, mReloadCallback {reloadCallback}
, mCursorPos {0}

View file

@ -10,6 +10,7 @@
#define ES_APP_GUIS_GUI_ORPHANED_DATA_CLEANUP_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/BusyComponent.h"
#include "guis/GuiSettings.h"
#include "views/ViewController.h"
@ -38,7 +39,7 @@ private:
std::vector<HelpPrompt> getHelpPrompts() override;
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
BusyComponent mBusyAnim;
std::function<void()> mReloadCallback;

View file

@ -28,7 +28,6 @@ GuiScraperMulti::GuiScraperMulti(
const std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>>& searches,
bool approveResults)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {2, 6}}
, mSearchQueue {searches.first}
, mApproveResults {approveResults}

View file

@ -14,8 +14,8 @@
#include "GuiComponent.h"
#include "MetaData.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "components/ScrollIndicatorComponent.h"
#include "scrapers/Scraper.h"
#include "views/ViewController.h"
@ -43,7 +43,7 @@ private:
void finish();
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -23,7 +23,6 @@ GuiScraperSingle::GuiScraperSingle(ScraperSearchParams& params,
bool& savedMediaAndAborted)
: mClose {false}
, mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {2, 6}}
, mSearchParams {params}
, mSavedMediaAndAborted {savedMediaAndAborted}

View file

@ -12,7 +12,7 @@
#define ES_APP_GUIS_GUI_SCRAPER_SINGLE_H
#include "GuiComponent.h"
#include "components/NinePatchComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ScrollIndicatorComponent.h"
#include "guis/GuiScraperSearch.h"
#include "views/ViewController.h"
@ -36,7 +36,7 @@ private:
void close();
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mGameName;

View file

@ -28,7 +28,6 @@
GuiThemeDownloader::GuiThemeDownloader(std::function<void()> updateCallback)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {2, 4}}
, mUpdateCallback(updateCallback)
, mRepositoryError {RepositoryError::NO_REPO_ERROR}

View file

@ -10,12 +10,12 @@
#define ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/BusyComponent.h"
#include "components/ButtonComponent.h"
#include "components/ComponentGrid.h"
#include "components/ComponentList.h"
#include "components/ImageComponent.h"
#include "components/NinePatchComponent.h"
#include "components/ScrollIndicatorComponent.h"
#include "components/TextComponent.h"
#include "renderers/Renderer.h"
@ -107,7 +107,7 @@ private:
void setupFullscreenViewer();
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<ComponentGrid> mCenterGrid;
std::shared_ptr<ComponentList> mList;

View file

@ -72,7 +72,7 @@ void ViewController::setMenuColors()
if (Settings::getInstance()->getString("MenuColorScheme") == "light") {
mMenuColorFrame = 0xEFEFEFFF;
mMenuColorFrameLaunchScreen = 0xDFDFDFFF;
mMenuColorFrameBusyComponent = 0xFFFFFFFF;
mMenuColorFrameBusyComponent = 0xF5F5F5FF;
mMenuColorPanelDimmed = 0x00000009;
mMenuColorTitle = 0x555555FF;
@ -109,7 +109,7 @@ void ViewController::setMenuColors()
else if (Settings::getInstance()->getString("MenuColorScheme") == "darkred") {
mMenuColorFrame = 0x191919FF;
mMenuColorFrameLaunchScreen = 0x121212FF;
mMenuColorFrameBusyComponent = 0x090909FF;
mMenuColorFrameBusyComponent = 0x000000FF;
mMenuColorPanelDimmed = 0x00000024;
mMenuColorTitle = 0x909090FF;
@ -146,7 +146,7 @@ void ViewController::setMenuColors()
else {
mMenuColorFrame = 0x191919FF;
mMenuColorFrameLaunchScreen = 0x121212FF;
mMenuColorFrameBusyComponent = 0x090909FF;
mMenuColorFrameBusyComponent = 0x000000FF;
mMenuColorPanelDimmed = 0x00000024;
mMenuColorTitle = 0x909090FF;

View file

@ -375,7 +375,7 @@ protected:
// Default values are for the "light" color scheme.
static inline unsigned int mMenuColorFrame {0xEFEFEFFF};
static inline unsigned int mMenuColorFrameLaunchScreen {0xDFDFDFFF};
static inline unsigned int mMenuColorFrameBusyComponent {0xFFFFFFFF};
static inline unsigned int mMenuColorFrameBusyComponent {0xF5F5F5FF};
static inline unsigned int mMenuColorPanelDimmed {0x00000009};
static inline unsigned int mMenuColorTitle {0x555555FF};

View file

@ -179,7 +179,6 @@ bool Window::init(bool resized)
progressBarRect.color = 0x79010FFF;
mProgressBarRectangles.emplace_back(progressBarRect);
mBackgroundOverlay->setImage(":/graphics/frame.png");
mBackgroundOverlay->setResize(mRenderer->getScreenWidth(), mRenderer->getScreenHeight());
mPostprocessedBackground = TextureResource::get("", false, false, false, false, false);

View file

@ -13,7 +13,8 @@
#include "utils/LocalizationUtil.h"
BusyComponent::BusyComponent()
: mBackground {":/graphics/frame.png"}
: mRenderer {Renderer::getInstance()}
, mBackground {glm::vec2 {16.0f, 16.0f}}
, mGrid {glm::ivec2 {5, 3}}
{
mAnimation = std::make_shared<AnimatedImageComponent>();
@ -36,10 +37,10 @@ void BusyComponent::onSizeChanged()
if (mSize.x == 0.0f || mSize.y == 0.0f)
return;
const float middleSpacerWidth {0.01f * Renderer::getScreenWidth()};
const float middleSpacerWidth {0.01f * mRenderer->getScreenWidth()};
const float textHeight {mText->getFont()->getLetterHeight()};
mText->setSize(0.0f, textHeight);
const float textWidth {mText->getSize().x + (4.0f * Renderer::getScreenWidthModifier())};
const float textWidth {mText->getSize().x + (4.0f * mRenderer->getScreenWidthModifier())};
mGrid.setColWidthPerc(1, textHeight / mSize.x); // Animation is square.
mGrid.setColWidthPerc(2, middleSpacerWidth / mSize.x);
@ -47,11 +48,11 @@ void BusyComponent::onSizeChanged()
mGrid.setRowHeightPerc(1, mText->getFont()->getLetterHeight() / mSize.y);
mBackground.setCornerSize({16.0f * Renderer::getScreenResolutionModifier(),
16.0f * Renderer::getScreenResolutionModifier()});
mBackground.fitTo(glm::vec2 {mGrid.getColWidth(1) + mGrid.getColWidth(2) + mGrid.getColWidth(3),
textHeight + (2.0f * Renderer::getScreenResolutionModifier())},
mAnimation->getPosition(), glm::vec2 {0.0f, 0.0f});
textHeight + (2.0f * mRenderer->getScreenResolutionModifier())},
mAnimation->getPosition(),
glm::vec2 {32.0f * mRenderer->getScreenResolutionModifier(),
32.0f * mRenderer->getScreenResolutionModifier()});
mBackground.setFrameColor(mMenuColorFrameBusyComponent);
AnimationFrame BUSY_ANIMATION_FRAMES[] {
@ -64,8 +65,3 @@ void BusyComponent::onSizeChanged()
const AnimationDef animationDef {BUSY_ANIMATION_FRAMES, 4, mMenuColorBusyComponent, true};
mAnimation->load(&animationDef);
}
void BusyComponent::reset()
{
// mAnimation->reset();
}

View file

@ -10,8 +10,8 @@
#define ES_CORE_COMPONENTS_BUSY_COMPONENT_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "components/TextComponent.h"
class AnimatedImageComponent;
@ -25,10 +25,9 @@ public:
void setText(const std::string& text) { mText->setText(text, true); }
void onSizeChanged() override;
void reset(); // Reset to frame 0.
private:
NinePatchComponent mBackground;
Renderer* mRenderer;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<AnimatedImageComponent> mAnimation;

View file

@ -27,8 +27,6 @@ MenuComponent::MenuComponent(std::string title, const std::shared_ptr<Font>& tit
addChild(&mBackground);
addChild(&mGrid);
mBackground.setImagePath(":/graphics/frame.svg");
// Set up title.
mTitle = std::make_shared<TextComponent>();
mTitle->setAutoCalcExtent(glm::ivec2 {0, 0});

View file

@ -9,11 +9,11 @@
#ifndef ES_CORE_COMPONENTS_MENU_COMPONENT_H
#define ES_CORE_COMPONENTS_MENU_COMPONENT_H
#include "components/BackgroundComponent.h"
#include "components/ButtonComponent.h"
#include "components/ComponentGrid.h"
#include "components/ComponentList.h"
#include "components/ImageComponent.h"
#include "components/NinePatchComponent.h"
#include "components/ScrollIndicatorComponent.h"
#include "components/TextComponent.h"
#include "utils/LocalizationUtil.h"
@ -85,7 +85,7 @@ private:
float getButtonGridHeight() const;
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -24,7 +24,6 @@ GuiDetectDevice::GuiDetectDevice(bool firstRun,
: mFirstRun {firstRun}
, mForcedConfig {forcedConfig}
, mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, 5}}
{
mHoldingConfig = nullptr;

View file

@ -10,8 +10,8 @@
#define ES_CORE_GUIS_GUI_DETECT_DEVICE_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
class TextComponent;
@ -31,7 +31,7 @@ private:
int mHoldTime;
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -9,7 +9,6 @@
#include "guis/GuiInfoPopup.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "components/TextComponent.h"
#include <SDL2/SDL_timer.h>
@ -21,7 +20,7 @@ GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
, mAlpha {1.0f}
, mRunning {true}
{
mFrame = new NinePatchComponent;
mBackground = new BackgroundComponent(glm::vec2 {22.0f, 22.0f});
float maxWidth {Renderer::getScreenWidth() * 0.9f};
float maxHeight {Renderer::getScreenHeight() * 0.2f};
@ -54,9 +53,8 @@ GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
setPosition(posX, posY, 0);
mFrame->setImagePath(":/graphics/frame.svg");
mFrame->fitTo(mSize);
addChild(mFrame);
mBackground->fitTo(mSize);
addChild(mBackground);
// We only initialize the actual time when we first start to render.
mStartTime = 0;
@ -71,7 +69,7 @@ GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
GuiInfoPopup::~GuiInfoPopup()
{
delete mGrid;
delete mFrame;
delete mBackground;
}
void GuiInfoPopup::render(const glm::mat4& /*parentTrans*/)
@ -116,7 +114,7 @@ bool GuiInfoPopup::updateState()
mGrid->setOpacity(mAlpha);
// Apply fade-in effect to popup frame.
mFrame->setFrameColor((mMenuColorFrame & 0xFFFFFF00) |
static_cast<unsigned char>(mAlpha * 255.0f));
mBackground->setFrameColor((mMenuColorFrame & 0xFFFFFF00) |
static_cast<unsigned char>(mAlpha * 255.0f));
return true;
}

View file

@ -10,10 +10,11 @@
#define ES_APP_GUIS_GUI_INFO_POPUP_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "renderers/Renderer.h"
class ComponentGrid;
class NinePatchComponent;
class BackgroundComponent;
class GuiInfoPopup : public GuiComponent
{
@ -30,7 +31,7 @@ private:
Renderer* mRenderer;
ComponentGrid* mGrid;
NinePatchComponent* mFrame;
BackgroundComponent* mBackground;
std::string mMessage;
int mDuration;

View file

@ -30,8 +30,7 @@ static InputConfigStructure sGuiInputConfigList[inputCount];
GuiInputConfig::GuiInputConfig(InputConfig* target,
bool reconfigureAll,
const std::function<void()>& okCallback)
: mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, 7}}
: mGrid {glm::ivec2 {1, 7}}
, mTargetConfig {target}
, mHoldingInput {false}
{

View file

@ -10,8 +10,8 @@
#define ES_CORE_GUIS_GUI_INPUT_CONFIG_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
class ComponentList;
class TextComponent;
@ -46,7 +46,7 @@ private:
bool assign(Input input, int inputId);
void clearAssignment(int inputId);
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -27,7 +27,6 @@ GuiMsgBox::GuiMsgBox(const std::string& text,
const bool deleteOnButtonPress,
const float maxWidthMultiplier)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, 2}}
, mBackFunc {backFunc}
, mDisableBackButton {disableBackButton}

View file

@ -11,8 +11,8 @@
#define ES_CORE_GUIS_GUI_MSG_BOX_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "utils/LocalizationUtil.h"
class ButtonComponent;
@ -46,7 +46,7 @@ private:
void deleteMeAndCall(const std::function<void()>& func);
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mMsg;

View file

@ -54,7 +54,6 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
const std::string& clearBtnHelpText,
const std::string& cancelBtnHelpText)
: mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, (infoString != "" && defaultValue != "" ? 8 : 6)}}
, mInitValue {initValue}
, mAcceptBtnHelpText {acceptBtnHelpText}

View file

@ -11,6 +11,7 @@
#define ES_CORE_GUIS_GUI_TEXT_EDIT_KEYBOARD_POPUP_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ButtonComponent.h"
#include "components/ComponentGrid.h"
#include "components/TextComponent.h"
@ -77,7 +78,7 @@ private:
std::shared_ptr<ButtonComponent> mAltButton;
Renderer* mRenderer;
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;

View file

@ -26,8 +26,7 @@ GuiTextEditPopup::GuiTextEditPopup(const std::string& title,
const std::string& loadBtnHelpText,
const std::string& clearBtnHelpText,
const std::string& cancelBtnHelpText)
: mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {1, (infoString != "" && defaultValue != "" ? 5 : 3)}}
: mGrid {glm::ivec2 {1, (infoString != "" && defaultValue != "" ? 5 : 3)}}
, mInitValue {initValue}
, mAcceptBtnText {acceptBtnText}
, mSaveConfirmationText {saveConfirmationText}

View file

@ -11,6 +11,7 @@
#define ES_CORE_GUIS_GUI_TEXT_EDIT_POPUP_H
#include "GuiComponent.h"
#include "components/BackgroundComponent.h"
#include "components/ButtonComponent.h"
#include "components/ComponentGrid.h"
#include "components/TextComponent.h"
@ -41,7 +42,7 @@ public:
private:
void updateDeleteRepeat(int deltaTime);
NinePatchComponent mBackground;
BackgroundComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<TextComponent> mTitle;