summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-14 23:04:52 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-17 13:47:58 +0100
commitea172d1a0ebcd39069e6a24f6f36d0c542c7cdf4 (patch)
treed9f58bee8efd9a48bfff90d48826ba4d1e689592 /src
parent4d8a5ed01560cde4e2c3caa819cb165dc7ac3df6 (diff)
downloadmana-ea172d1a0ebcd39069e6a24f6f36d0c542c7cdf4.tar.gz
mana-ea172d1a0ebcd39069e6a24f6f36d0c542c7cdf4.tar.bz2
mana-ea172d1a0ebcd39069e6a24f6f36d0c542c7cdf4.tar.xz
mana-ea172d1a0ebcd39069e6a24f6f36d0c542c7cdf4.zip
Have ImageRect automatically initialize and clean up
Diffstat (limited to 'src')
-rw-r--r--src/graphics.cpp17
-rw-r--r--src/graphics.h8
-rw-r--r--src/gui/widgets/button.h1
-rw-r--r--src/gui/widgets/scrollarea.h3
-rw-r--r--src/resources/theme.cpp36
-rw-r--r--src/resources/theme.h3
-rw-r--r--src/text.cpp5
7 files changed, 36 insertions, 37 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 92f291c8..2b262625 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -25,6 +25,23 @@
#include <guichan/exception.hpp>
+ImageRect::ImageRect()
+{
+ memset(grid, 0, sizeof(grid));
+}
+
+ImageRect::ImageRect(ImageRect &&r)
+{
+ memcpy(grid, r.grid, sizeof(grid));
+ memset(r.grid, 0, sizeof(grid));
+}
+
+ImageRect::~ImageRect()
+{
+ for (auto img : grid)
+ delete img;
+}
+
void ImageRect::setAlpha(float alpha)
{
for (auto img : grid)
diff --git a/src/graphics.h b/src/graphics.h
index 005acbb0..4556e499 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -61,6 +61,14 @@ public:
LOWER_RIGHT = 8
};
+ ImageRect();
+ ImageRect(const ImageRect &) = delete;
+ ImageRect(ImageRect &&);
+ ~ImageRect();
+
+ ImageRect &operator=(const ImageRect &) = delete;
+ ImageRect &operator=(ImageRect &&r) = delete;
+
Image *grid[9];
void setAlpha(float alpha);
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 32f7cb77..97f7307b 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -26,7 +26,6 @@
#include <memory>
#include <vector>
-class ImageRect;
class Image;
class TextPopup;
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 18b1f17d..ab0eb026 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -24,9 +24,6 @@
#include <guichan/widgetlistener.hpp>
#include <guichan/widgets/scrollarea.hpp>
-class Image;
-class ImageRect;
-
/**
* A scroll area.
*
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index bdb5ce31..41d09ab2 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -32,7 +32,6 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
-#include "utils/dtor.h"
#include "utils/filesystem.h"
#include "utils/stringutils.h"
#include "utils/xml.h"
@@ -73,18 +72,13 @@ static std::optional<std::string> findThemePath(const std::string &theme)
Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown):
- mBorder(skin),
+ mBorder(std::move(skin)),
mCloseImage(close),
mStickyImageUp(stickyUp),
mStickyImageDown(stickyDown)
{}
-Skin::~Skin()
-{
- // Clean up static resources
- for (auto img : mBorder.grid)
- delete img;
-}
+Skin::~Skin() = default;
void Skin::updateAlpha(float alpha)
{
@@ -159,8 +153,6 @@ Theme::Theme(const std::string &path)
{ "button_disabled.png", 25, 23 }
};
- mButton = new ImageRect[BUTTON_MODE_COUNT];
-
for (int mode = 0; mode < BUTTON_MODE_COUNT; ++mode)
{
auto modeImage = getImage(data[mode].file);
@@ -321,22 +313,7 @@ Theme::Theme(const std::string &path)
mResizeGripImage = getImage("resize.png");
}
-Theme::~Theme()
-{
- for (int mode = 0; mode < BUTTON_MODE_COUNT; ++mode)
- {
- std::for_each(mButton[mode].grid, mButton[mode].grid + 9,
- dtor<Image*>());
- }
- delete[] mButton;
-
- for (auto &imgRect : mTabImg)
- std::for_each(imgRect.grid, imgRect.grid + 9, dtor<Image*>());
-
- std::for_each(mDeepBoxImageRect.grid, mDeepBoxImageRect.grid + 9, dtor<Image*>());
- std::for_each(mScrollBarMarker.grid, mScrollBarMarker.grid + 9, dtor<Image*>());
- std::for_each(mScrollBarMarkerHi.grid, mScrollBarMarkerHi.grid + 9, dtor<Image*>());
-}
+Theme::~Theme() = default;
const gcn::Color &Theme::getThemeColor(int type, int alpha)
{
@@ -600,8 +577,8 @@ void Theme::updateAlpha()
for (auto &skin : mSkins)
skin.second->updateAlpha(mAlpha);
- for (int mode = 0; mode < BUTTON_MODE_COUNT; ++mode)
- mButton[mode].setAlpha(mAlpha);
+ for (auto &mode : mButton)
+ mode.setAlpha(mAlpha);
for (auto &t : mTabImg)
t.setAlpha(mAlpha);
@@ -691,7 +668,6 @@ std::unique_ptr<Skin> Theme::readSkin(const std::string &filename) const
auto dBorders = getImage(skinSetImage);
ImageRect border;
- memset(&border, 0, sizeof(ImageRect));
// iterate <widget>'s
for (auto widgetNode : rootNode.children())
@@ -763,7 +739,7 @@ std::unique_ptr<Skin> Theme::readSkin(const std::string &filename) const
Image *stickyImageUp = sticky->getSubImage(0, 0, 15, 15);
Image *stickyImageDown = sticky->getSubImage(15, 0, 15, 15);
- auto skin = std::make_unique<Skin>(border, closeImage, stickyImageUp, stickyImageDown);
+ auto skin = std::make_unique<Skin>(std::move(border), closeImage, stickyImageUp, stickyImageDown);
skin->updateAlpha(mAlpha);
return skin;
}
diff --git a/src/resources/theme.h b/src/resources/theme.h
index 6a55e6dd..8aba8769 100644
--- a/src/resources/theme.h
+++ b/src/resources/theme.h
@@ -42,7 +42,6 @@ class Skin
{
public:
Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown);
-
~Skin();
/**
@@ -258,7 +257,7 @@ class Theme : public Palette, public EventListener
std::vector<std::unique_ptr<DyePalette>> mProgressColors;
- ImageRect *mButton; /**< Button state graphics */
+ ImageRect mButton[4]; /**< Button state graphics */
ImageRect mTabImg[4]; /**< Tab state graphics */
ImageRect mDeepBoxImageRect;
diff --git a/src/text.cpp b/src/text.cpp
index 7f305401..f45cb706 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -96,8 +96,11 @@ Text::~Text()
{
delete textManager;
textManager = nullptr;
- for (auto img : mBubble.grid)
+ for (auto &img : mBubble.grid)
+ {
delete img;
+ img = nullptr;
+ }
delete mBubbleArrow;
}
}