mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-23 23:05:40 +00:00
remove obtrusive static image component and add svg caching
This commit is contained in:
parent
39f67cfcdf
commit
593b6d94ee
es-core/src
|
@ -16,52 +16,41 @@
|
||||||
// Available slot definitions.
|
// Available slot definitions.
|
||||||
const std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN,
|
const std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN,
|
||||||
SLOT_ALTERNATIVE_EMULATOR};
|
SLOT_ALTERNATIVE_EMULATOR};
|
||||||
std::map<std::string, std::string> BadgesComponent::mBadgeIcons = std::map<std::string, std::string>();
|
|
||||||
std::map<std::string, ImageComponent> BadgesComponent::mImageComponents = std::map<std::string, ImageComponent>();
|
|
||||||
std::vector<BadgesComponent *> BadgesComponent::mInstances = {};
|
|
||||||
|
|
||||||
BadgesComponent::BadgesComponent(Window *window)
|
BadgesComponent::BadgesComponent(Window *window)
|
||||||
: FlexboxComponent(window) {
|
: FlexboxComponent(window) {
|
||||||
if (mBadgeIcons.empty()) {
|
|
||||||
mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg";
|
|
||||||
mBadgeIcons[SLOT_COMPLETED] = ":/graphics/badge_completed.svg";
|
|
||||||
mBadgeIcons[SLOT_KIDS] = ":/graphics/badge_kidgame.svg";
|
|
||||||
mBadgeIcons[SLOT_BROKEN] = ":/graphics/badge_broken.svg";
|
|
||||||
mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR] = ":/graphics/badge_altemu.svg";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mBadgeIcons = std::map<std::string, std::string>();
|
||||||
|
mBadgeIcons[SLOT_FAVORITE] = ":/graphics/badge_favorite.svg";
|
||||||
|
mBadgeIcons[SLOT_COMPLETED] = ":/graphics/badge_completed.svg";
|
||||||
|
mBadgeIcons[SLOT_KIDS] = ":/graphics/badge_kidgame.svg";
|
||||||
|
mBadgeIcons[SLOT_BROKEN] = ":/graphics/badge_broken.svg";
|
||||||
|
mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR] = ":/graphics/badge_altemu.svg";
|
||||||
|
|
||||||
// Create the child ImageComponent for every badge.
|
mImageComponents = std::map<std::string, ImageComponent>();
|
||||||
if (mImageComponents.empty()) {
|
ImageComponent mImageFavorite = ImageComponent(window);
|
||||||
ImageComponent mImageFavorite = ImageComponent(window);
|
mImageFavorite.setImage(mBadgeIcons[SLOT_FAVORITE], false, true, true);
|
||||||
mImageFavorite.setImage(mBadgeIcons[SLOT_FAVORITE], false, true);
|
mImageComponents.insert({SLOT_FAVORITE, mImageFavorite});
|
||||||
mImageComponents.insert({SLOT_FAVORITE, mImageFavorite});
|
ImageComponent mImageCompleted = ImageComponent(window);
|
||||||
ImageComponent mImageCompleted = ImageComponent(window);
|
mImageCompleted.setImage(mBadgeIcons[SLOT_COMPLETED], false, true, true);
|
||||||
mImageCompleted.setImage(mBadgeIcons[SLOT_COMPLETED], false, true);
|
mImageComponents.insert({SLOT_COMPLETED, mImageCompleted});
|
||||||
mImageComponents.insert({SLOT_COMPLETED, mImageCompleted});
|
ImageComponent mImageKids = ImageComponent(window);
|
||||||
ImageComponent mImageKids = ImageComponent(window);
|
mImageKids.setImage(mBadgeIcons[SLOT_KIDS], false, true, true);
|
||||||
mImageKids.setImage(mBadgeIcons[SLOT_KIDS], false, true);
|
mImageComponents.insert({SLOT_KIDS, mImageKids});
|
||||||
mImageComponents.insert({SLOT_KIDS, mImageKids});
|
ImageComponent mImageBroken = ImageComponent(window);
|
||||||
ImageComponent mImageBroken = ImageComponent(window);
|
mImageBroken.setImage(mBadgeIcons[SLOT_BROKEN], false, true, true);
|
||||||
mImageBroken.setImage(mBadgeIcons[SLOT_BROKEN], false, true);
|
mImageComponents.insert({SLOT_BROKEN, mImageBroken});
|
||||||
mImageComponents.insert({SLOT_BROKEN, mImageBroken});
|
ImageComponent mImageAltEmu = ImageComponent(window);
|
||||||
ImageComponent mImageAltEmu = ImageComponent(window);
|
mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true, true);
|
||||||
mImageAltEmu.setImage(mBadgeIcons[SLOT_ALTERNATIVE_EMULATOR], false, true);
|
mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu});
|
||||||
mImageComponents.insert({SLOT_ALTERNATIVE_EMULATOR, mImageAltEmu});
|
|
||||||
}
|
|
||||||
|
|
||||||
mInstances.push_back(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BadgesComponent::~BadgesComponent() noexcept {
|
BadgesComponent::~BadgesComponent() noexcept {
|
||||||
for (GuiComponent *c: mChildren)
|
for (GuiComponent *c: mChildren)
|
||||||
c->clearChildren();
|
c->clearChildren();
|
||||||
clearChildren();
|
clearChildren();
|
||||||
mInstances.erase(std::remove(mInstances.begin(), mInstances.end(), this), mInstances.end());
|
mBadgeIcons.clear();
|
||||||
if (mInstances.empty()) {
|
mImageComponents.clear();
|
||||||
mBadgeIcons.clear();
|
|
||||||
mImageComponents.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +96,7 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
||||||
for (auto& slot : mSlots) {
|
for (auto& slot : mSlots) {
|
||||||
if (properties & PATH && elem->has(slot) && mBadgeIcons[slot] != elem->get<std::string>(slot)) {
|
if (properties & PATH && elem->has(slot) && mBadgeIcons[slot] != elem->get<std::string>(slot)) {
|
||||||
mBadgeIcons[slot] = elem->get<std::string>(slot);
|
mBadgeIcons[slot] = elem->get<std::string>(slot);
|
||||||
mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true);
|
mImageComponents.find(slot)->second.setImage(mBadgeIcons[slot], false, true, true);
|
||||||
imgChanged = true;
|
imgChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::vector<std::string> mSlots;
|
static const std::vector<std::string> mSlots;
|
||||||
static std::map<std::string, std::string> mBadgeIcons;
|
std::map<std::string, std::string> mBadgeIcons;
|
||||||
static std::map<std::string, ImageComponent> mImageComponents;
|
std::map<std::string, ImageComponent> mImageComponents;
|
||||||
static std::vector<BadgesComponent *> mInstances;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H
|
#endif // ES_APP_COMPONENTS_BADGES_COMPONENT_H
|
||||||
|
|
|
@ -126,8 +126,7 @@ void ImageComponent::resize()
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify)
|
void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify, bool cacheImage) {
|
||||||
{
|
|
||||||
// Always load bundled graphic resources statically, unless mForceLoad has been set.
|
// Always load bundled graphic resources statically, unless mForceLoad has been set.
|
||||||
// This eliminates annoying texture pop-in problems that would otherwise occur.
|
// This eliminates annoying texture pop-in problems that would otherwise occur.
|
||||||
if (!mForceLoad && (path[0] == ':') && (path[1] == '/')) {
|
if (!mForceLoad && (path[0] == ':') && (path[1] == '/')) {
|
||||||
|
@ -139,10 +138,10 @@ void ImageComponent::setImage(std::string path, bool tile, bool linearMagnify)
|
||||||
mTexture.reset();
|
mTexture.reset();
|
||||||
else
|
else
|
||||||
mTexture =
|
mTexture =
|
||||||
TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic, linearMagnify);
|
TextureResource::get(mDefaultPath, tile, mForceLoad, mDynamic, linearMagnify, 1.0f, cacheImage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, linearMagnify);
|
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic, linearMagnify, 1.0f, cacheImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
resize();
|
resize();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
|
|
||||||
// Loads the image at the given filepath. Will tile if tile is true (retrieves texture
|
// Loads the image at the given filepath. Will tile if tile is true (retrieves texture
|
||||||
// as tiling, creates vertices accordingly).
|
// as tiling, creates vertices accordingly).
|
||||||
void setImage(std::string path, bool tile = false, bool linearMagnify = false);
|
void setImage(std::string path, bool tile = false, bool linearMagnify = false, bool cacheSVG = false);
|
||||||
|
|
||||||
// Loads an image from memory.
|
// Loads an image from memory.
|
||||||
void setImage(const char *data, size_t length, bool tile = false);
|
void setImage(const char *data, size_t length, bool tile = false);
|
||||||
|
|
|
@ -143,12 +143,13 @@ bool TextureResource::bind()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
std::shared_ptr<TextureResource> TextureResource::get(const std::string &path,
|
||||||
bool tile,
|
bool tile,
|
||||||
bool forceLoad,
|
bool forceLoad,
|
||||||
bool dynamic,
|
bool dynamic,
|
||||||
bool linearMagnify,
|
bool linearMagnify,
|
||||||
float scaleDuringLoad)
|
float scaleDuringLoad,
|
||||||
|
bool cacheImage)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
||||||
std::shared_ptr<TextureData> data = sTextureDataManager.get(tex.get());
|
std::shared_ptr<TextureData> data = sTextureDataManager.get(tex.get());
|
||||||
|
|
||||||
// Is it an SVG?
|
// Is it an SVG?
|
||||||
if (key.first.substr(key.first.size() - 4, std::string::npos) != ".svg") {
|
if (key.first.substr(key.first.size() - 4, std::string::npos) != ".svg" || cacheImage) {
|
||||||
// Probably not. Add it to our map. We don't add SVGs because 2 SVGs might be
|
// Probably not. Add it to our map. We don't add SVGs because 2 SVGs might be
|
||||||
// rasterized at different sizes.
|
// rasterized at different sizes.
|
||||||
sTextureMap[key] = std::weak_ptr<TextureResource>(tex);
|
sTextureMap[key] = std::weak_ptr<TextureResource>(tex);
|
||||||
|
|
|
@ -25,13 +25,15 @@ class TextureData;
|
||||||
class TextureResource : public IReloadable
|
class TextureResource : public IReloadable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<TextureResource> get(const std::string& path,
|
static std::shared_ptr<TextureResource> get(const std::string &path,
|
||||||
bool tile = false,
|
bool tile = false,
|
||||||
bool forceLoad = false,
|
bool forceLoad = false,
|
||||||
bool dynamic = true,
|
bool dynamic = true,
|
||||||
bool linearMagnify = false,
|
bool linearMagnify = false,
|
||||||
float scaleDuringLoad = 1.0f);
|
float scaleDuringLoad = 1.0f,
|
||||||
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
|
bool cacheImage = false);
|
||||||
|
|
||||||
|
void initFromPixels(const unsigned char *dataRGBA, size_t width, size_t height);
|
||||||
virtual void initFromMemory(const char* data, size_t length);
|
virtual void initFromMemory(const char* data, size_t length);
|
||||||
static void manualUnload(std::string path, bool tile);
|
static void manualUnload(std::string path, bool tile);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue