diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-28 08:02:46 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-04-08 20:43:23 +0200 |
commit | 14dc8218eeebd1583e6bd3c49013b3e501f47228 (patch) | |
tree | 387778ceddd2165ab033c742e5c0eff583a6327a /src/gui/itempopup.cpp | |
parent | de442e7b15a52729ba37946e74f2799804a77dab (diff) | |
download | mana-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/itempopup.cpp')
-rw-r--r-- | src/gui/itempopup.cpp | 21 |
1 files changed, 4 insertions, 17 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) |