diff options
Diffstat (limited to 'src')
-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 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 4 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 3 |
14 files changed, 107 insertions, 21 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); diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 2c4bc0f95..b88c4dbb5 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -573,7 +573,7 @@ struct SubImageLoader } }; -SubImage *ResourceManager::getSubImage(Image *parent, int x, int y, +Image *ResourceManager::getSubImage(Image *parent, int x, int y, int width, int height) { if (!parent) @@ -584,7 +584,7 @@ SubImage *ResourceManager::getSubImage(Image *parent, int x, int y, std::stringstream ss; ss << parent->getIdPath() << ",[" << x << "," << y << "," << width << "x" << height << "]"; - return reinterpret_cast<SubImage*>(get(ss.str(), SubImageLoader::load, &rl)); + return static_cast<Image*>(get(ss.str(), SubImageLoader::load, &rl)); } struct SpriteDefLoader diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index b4892227e..7a1e517c0 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -38,7 +38,6 @@ class ImageSet; class Music; class Resource; class SoundEffect; -class SubImage; class SpriteDef; struct SDL_Surface; @@ -203,7 +202,7 @@ class ResourceManager */ ImageSet *getImageSet(const std::string &imagePath, int w, int h); - SubImage *getSubImage(Image *parent, int x, int y, int width, int height); + Image *getSubImage(Image *parent, int x, int y, int width, int height); /** * Creates a sprite definition based on a given path and the supplied |