diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-12 11:01:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-13 01:02:41 +0300 |
commit | 14a9a1da30ca772efd42a9ce6662a11b102818bc (patch) | |
tree | d19264fc77a677b0a25e989119dfbddb1ff14773 /src/gui | |
parent | f42921c0597101b5d6f10afa68d0ffc6f6d1a66f (diff) | |
download | manaverse-14a9a1da30ca772efd42a9ce6662a11b102818bc.tar.gz manaverse-14a9a1da30ca772efd42a9ce6662a11b102818bc.tar.bz2 manaverse-14a9a1da30ca772efd42a9ce6662a11b102818bc.tar.xz manaverse-14a9a1da30ca772efd42a9ce6662a11b102818bc.zip |
Fix leaks after last commit.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/theme.cpp | 56 | ||||
-rw-r--r-- | src/gui/theme.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 6 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/resizegrip.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 15 | ||||
-rw-r--r-- | src/gui/widgets/slider.cpp | 6 | ||||
-rw-r--r-- | src/gui/widgets/tab.cpp | 6 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 5 |
12 files changed, 104 insertions, 17 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 6b9ac023b..e7d8f0393 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -66,7 +66,7 @@ static void initDefaultThemePath() Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, const std::string &filePath, const std::string &name, int padding, int titlePadding): - instances(0), + instances(1), mFilePath(filePath), mName(name), mBorder(skin), @@ -83,18 +83,30 @@ Skin::~Skin() // Clean up static resources for (int i = 0; i < 9; i++) { - delete mBorder.grid[i]; - mBorder.grid[i] = nullptr; + if (mBorder.grid[i]) + { + mBorder.grid[i]->decRef(); + mBorder.grid[i] = nullptr; + } } - delete mCloseImage; - mCloseImage = nullptr; + if (mCloseImage) + { + mCloseImage->decRef(); + mCloseImage = nullptr; + } - delete mStickyImageUp; - mStickyImageUp = nullptr; + if (mStickyImageUp) + { + mStickyImageUp->decRef(); + mStickyImageUp = nullptr; + } - delete mStickyImageDown; - mStickyImageDown = nullptr; + if (mStickyImageDown) + { + mStickyImageDown->decRef(); + mStickyImageDown = nullptr; + } } void Skin::updateAlpha(float minimumOpacityAllowed) @@ -261,7 +273,6 @@ void Theme::unload(Skin *skin) if (!skin) return; skin->instances --; -/* // unload theme if no instances if (!skin->instances) { @@ -278,7 +289,6 @@ void Theme::unload(Skin *skin) } delete skin; } -*/ } void Theme::setMinimumOpacity(float minimumOpacity) @@ -358,6 +368,7 @@ struct SkinHelper ImageRect *rect; XmlNodePtr *node; Image *image; + ResourceManager *resman; bool loadList(SkinParameter *params, size_t size) { @@ -365,8 +376,10 @@ struct SkinHelper { if (partType == params[f].name) { - rect->grid[params[f].index] = image->getSubImage( - xPos, yPos, width, height); +// rect->grid[params[f].index] = image->getSubImage( +// xPos, yPos, width, height); + rect->grid[params[f].index] = resman->getSubImage( + image, xPos, yPos, width, height); return true; } } @@ -420,6 +433,7 @@ Skin *Theme::readSkin(const std::string &filename) if (widgetType == "Window") { SkinHelper helper; + helper.resman = ResourceManager::getInstance(); const int globalXPos = XML::getProperty(widgetNode, "xpos", 0); const int globalYPos = XML::getProperty(widgetNode, "ypos", 0); for_each_xml_child_node(partNode, widgetNode) @@ -865,14 +879,23 @@ void Theme::loadRect(ImageRect &image, std::string name, int start, int end) { if (rect.grid[f]) { - rect.grid[f]->incRef(); image.grid[f] = rect.grid[f]; + image.grid[f]->incRef(); } } unload(skin); } } +void Theme::unloadRect(ImageRect &rect, int start, int end) +{ + for (int f = start; f <= end; f ++) + { + if (rect.grid[f]) + rect.grid[f]->decRef(); + } +} + Image *Theme::getImageFromThemeXml(const std::string &name) { Theme *theme = Theme::instance(); @@ -882,9 +905,10 @@ Image *Theme::getImageFromThemeXml(const std::string &name) const ImageRect &rect = skin->getBorder(); if (rect.grid[0]) { - rect.grid[0]->incRef(); + Image *image = rect.grid[0]; + image->incRef(); theme->unload(skin); - return rect.grid[0]; + return image; } theme->unload(skin); } diff --git a/src/gui/theme.h b/src/gui/theme.h index bd5359c65..e2be8a232 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -272,6 +272,8 @@ class Theme : public Palette, public ConfigListener void loadRect(ImageRect &image, std::string name, int start = 0, int end = 8); + void unloadRect(ImageRect &rect, int start = 0, int end = 8); + static Image *getImageFromThemeXml(const std::string &name); private: diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index ba789f2c5..15b4abdc2 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -191,6 +191,12 @@ Button::~Button() { mInstances--; + if (mInstances == 0 && Theme::instance()) + { + Theme *theme = Theme::instance(); + for (int mode = 0; mode < BUTTON_COUNT; mode ++) + theme->unloadRect(button[mode]); + } delete mVertexes; mVertexes = nullptr; if (mImageSet) diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 8727f940f..8b5f81e6b 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -115,6 +115,19 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ActionListener* listener, DropDown::~DropDown() { instances--; + if (instances == 0) + { + for (int f = 0; f < 2; f ++) + { + for (int i = 0; i < 2; i ++) + { + if (buttons[f][i]) + buttons[f][i]->decRef(); + } + } + if (Theme::instance()) + Theme::instance()->unloadRect(skin); + } delete mScrollArea; mScrollArea = nullptr; } diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index d505aa27e..bf17793f5 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -60,6 +60,8 @@ PlayerBox::PlayerBox(Being *being): PlayerBox::~PlayerBox() { instances--; + if (instances == 0 && Theme::instance()) + Theme::instance()->unloadRect(background); mBeing = nullptr; } diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index d4492a2b6..2ddd2b0b9 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -84,7 +84,10 @@ ProgressBar::ProgressBar(float progress, ProgressBar::~ProgressBar() { mInstances--; - + if (mInstances == 0 && Theme::instance()) + { + Theme::instance()->unloadRect(mBorder); + } delete mVertexes; mVertexes = nullptr; } diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index 98df17d12..4b299a5dc 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -44,6 +44,7 @@ ResizeGrip::ResizeGrip(const std::string &image) { // Load the grip image gripImage = Theme::getImageFromThemeXml(image); + if (gripImage) gripImage->setAlpha(mAlpha); } @@ -65,6 +66,8 @@ ResizeGrip::ResizeGrip(const std::string &image) ResizeGrip::~ResizeGrip() { mInstances--; + if (mInstances == 0 && gripImage) + gripImage->decRef(); } void ResizeGrip::draw(gcn::Graphics *graphics) diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 4e15bc167..4cc4cad41 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -92,6 +92,21 @@ ScrollArea::~ScrollArea() delete getContent(); instances--; + if (instances == 0 && Theme::instance()) + { + Theme *theme = Theme::instance(); + theme->unloadRect(background); + theme->unloadRect(vMarker); + theme->unloadRect(vMarkerHi); + for (int i = 0; i < 2; i ++) + { + for (int f = UP; f < BUTTONS_DIR; f ++) + { + if (buttons[f][i]) + buttons[f][i]->decRef(); + } + } + } delete mVertexes; mVertexes = nullptr; diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 595b2f85d..6b5ad28a4 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -61,6 +61,12 @@ Slider::Slider(double scaleStart, double scaleEnd): Slider::~Slider() { mInstances--; + if (mInstances == 0 && Theme::instance()) + { + Theme *theme = Theme::instance(); + for (int mode = 0; mode < 2; mode ++) + theme->unloadRect(buttons[mode]); + } } void Slider::init() diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index f7b353c7e..d2236c1d8 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -78,6 +78,12 @@ Tab::Tab() : Tab::~Tab() { mInstances--; + if (mInstances == 0 && Theme::instance()) + { + Theme *theme = Theme::instance(); + for (int mode = 0; mode < TAB_COUNT; mode ++) + Theme::instance()->unloadRect(tabImg[mode]); + } delete mVertexes; mVertexes = nullptr; } diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 4b71bd795..8f543e3bf 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -83,6 +83,8 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab, TextField::~TextField() { instances--; + if (instances == 0 && Theme::instance()) + Theme::instance()->unloadRect(skin); } void TextField::updateAlpha() diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index d956e9adf..d2ba03e07 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -339,6 +339,11 @@ void Window::setResizable(bool r) if (r) { + if (mGrip) + { + remove(mGrip); + delete mGrip; + } mGrip = new ResizeGrip; mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); |