diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/itempopup.cpp | 21 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 14 | ||||
-rw-r--r-- | src/gui/minimap.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/desktop.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/desktop.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/emoteshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/icon.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/icon.h | 10 |
8 files changed, 29 insertions, 46 deletions
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index f552a570..8208a5d8 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -102,7 +102,7 @@ ItemPopup::ItemPopup(): mItemWeight = new TextBox; mItemWeight->setEditable(false); - mIcon = new Icon(nullptr); + mIcon = new Icon; add(mItemName); add(mItemDesc); @@ -113,15 +113,7 @@ ItemPopup::ItemPopup(): addMouseListener(this); } -ItemPopup::~ItemPopup() -{ - if (mIcon) - { - Image *image = mIcon->getImage(); - if (image) - image->decRef(); - } -} +ItemPopup::~ItemPopup() = default; void ItemPopup::setEquipmentText(const std::string& text) { @@ -158,16 +150,11 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) int space = 0; - Image *oldImage = mIcon->getImage(); - if (oldImage) - oldImage->decRef(); - if (showImage) { ResourceManager *resman = ResourceManager::getInstance(); - Image *image = resman->getImage( - paths.getStringValue("itemIcons") - + item.getDisplay().image); + auto image = resman->getImageRef(paths.getStringValue("itemIcons") + + item.getDisplay().image); mIcon->setImage(image); if (image) diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 4a940254..cb38fba6 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -65,16 +65,12 @@ Minimap::Minimap(): Minimap::~Minimap() { config.setValue(getWindowName() + "Show", mShow); - - if (mMapImage) - mMapImage->decRef(); } void Minimap::setMap(Map *map) { // Set the title for the Minimap std::string caption; - std::string minimapName; if (map) caption = map->getName(); @@ -85,11 +81,7 @@ void Minimap::setMap(Map *map) minimap->setCaption(caption); // Adapt the image - if (mMapImage) - { - mMapImage->decRef(); - mMapImage = nullptr; - } + mMapImage = nullptr; if (map) { @@ -98,13 +90,13 @@ void Minimap::setMap(Map *map) "graphics/minimaps/" + map->getFilename() + ".png"; ResourceManager *resman = ResourceManager::getInstance(); - minimapName = map->getProperty("minimap"); + std::string minimapName = map->getProperty("minimap"); if (minimapName.empty() && resman->exists(tempname)) minimapName = tempname; if (!minimapName.empty()) - mMapImage = resman->getImage(minimapName); + mMapImage = resman->getImageRef(minimapName); } if (mMapImage) diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 6eb051ef..6e80a3c1 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -24,6 +24,8 @@ #include "gui/widgets/window.h" +#include "resources/resource.h" + class Image; class Map; @@ -59,7 +61,7 @@ class Minimap : public Window private: Map *mMap = nullptr; - Image *mMapImage = nullptr; + ResourceRef<Image> mMapImage; float mWidthProportion = 0.5; float mHeightProportion = 0.5; static bool mShow; diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 474aadb0..ca86360e 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -52,11 +52,7 @@ Desktop::Desktop() add(mVersionLabel, 25, 2); } -Desktop::~Desktop() -{ - if (mWallpaper) - mWallpaper->decRef(); -} +Desktop::~Desktop() = default; void Desktop::reloadWallpaper() { @@ -109,14 +105,11 @@ void Desktop::setBestFittingWallpaper() return; ResourceManager *resman = ResourceManager::getInstance(); - Image *wallpaper = resman->getImage(wallpaperName); + auto wallpaper = resman->getImageRef(wallpaperName); if (wallpaper) { - if (mWallpaper) - mWallpaper->decRef(Resource::DeleteImmediately); - - mWallpaper = wallpaper; + mWallpaper = std::move(wallpaper); } else { diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index 97294423..5909ac72 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -26,6 +26,8 @@ #include "gui/widgets/container.h" +#include "resources/resource.h" + #include <guichan/widgetlistener.hpp> class Image; @@ -61,7 +63,7 @@ class Desktop : public Container, gcn::WidgetListener private: void setBestFittingWallpaper(); - Image *mWallpaper = nullptr; + ResourceRef<Image> mWallpaper; gcn::Label *mVersionLabel; }; diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 4df0c4b9..c72d166f 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -89,7 +89,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (mEmoteMoved != -1) { // Draw the emote image being dragged by the cursor. - const ImageSprite *sprite = EmoteDB::get(mEmoteMoved).sprite; + const ImageSprite *sprite = EmoteDB::get(mEmoteMoved).sprite.get(); const int tPosX = mCursorPosX - (sprite->getWidth() / 2); const int tPosY = mCursorPosY - (sprite->getHeight() / 2); diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index 5becadd1..67fd8384 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -27,14 +27,17 @@ #include "resources/resourcemanager.h" Icon::Icon(const std::string &file) - : Icon(ResourceManager::getInstance()->getImage(file)) -{} + : Icon(ResourceManager::getInstance()->getImageRef(file)) +{ +} Icon::Icon(Image *image) { setImage(image); } +Icon::~Icon() = default; + void Icon::setImage(Image *image) { mImage = image; diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h index 508d2095..3ebc2c16 100644 --- a/src/gui/widgets/icon.h +++ b/src/gui/widgets/icon.h @@ -22,6 +22,8 @@ #ifndef ICON_H #define ICON_H +#include "resources/resource.h" + #include <guichan/widget.hpp> class Image; @@ -39,12 +41,14 @@ class Icon : public gcn::Widget * * @param filename The file name of the image to display */ - Icon(const std::string &filename); + explicit Icon(const std::string &filename); /** * Constructor, uses an existing Image. */ - Icon(Image *image); + explicit Icon(Image *image = nullptr); + + ~Icon() override; /** * Gets the current Image. @@ -62,7 +66,7 @@ class Icon : public gcn::Widget void draw(gcn::Graphics *g) override; private: - Image *mImage = nullptr; + ResourceRef<Image> mImage; }; #endif // ICON_H |