summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-28 08:02:46 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-04-08 20:43:23 +0200
commit14dc8218eeebd1583e6bd3c49013b3e501f47228 (patch)
tree387778ceddd2165ab033c742e5c0eff583a6327a /src/gui/widgets
parentde442e7b15a52729ba37946e74f2799804a77dab (diff)
downloadmana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.gz
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.bz2
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.xz
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.zip
Use ResourceRef<Image> in more places
Automatic reference counting of images is now used by Item, Icon, AnimatedSprite, ImageSprite, ParticleEmitter, Minimap, Desktop and Emote. Since ResourceManager::get automatically adds a reference, it needs to be explicitly subtracted when the resource is managed by ResourceRef. This is taken care of by the new ResourceManager::getImageRef. Also removed the apprently unused and duplicate "mDrawImage" from Item (which also didn't get decRef called on it). Fixes cleanup of emote ImageSet and ImageSprite instances, as well as particle images.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/desktop.cpp13
-rw-r--r--src/gui/widgets/desktop.h4
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/icon.cpp7
-rw-r--r--src/gui/widgets/icon.h10
5 files changed, 19 insertions, 17 deletions
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