From 57d3219bda4f72f82ffa97d0ef9e9c48aa843925 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 21 Oct 2013 00:10:41 +0300 Subject: add function to load separate image into button. --- src/gui/widgets/button.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++- src/gui/widgets/button.h | 10 +++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index f8ae3e65c..0c71bf8bd 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -147,7 +147,7 @@ Button::Button(const Widget2 *const widget, mPressed(false) { init(); - loadImage(imageName); + loadImageSet(imageName); adjustSize(); setActionEventId(actionEventId); @@ -184,6 +184,46 @@ Button::Button(const Widget2 *const widget, const std::string &imageName, mRedraw(true), mStick(false), mPressed(false) +{ + init(); + loadImageSet(imageName); + adjustSize(); + setActionEventId(actionEventId); + + if (listener) + addActionListener(listener); +} + +Button::Button(const Widget2 *const widget, + const std::string &caption, + const std::string &imageName, + const std::string &actionEventId, + gcn::ActionListener *const listener) : + gcn::Button(caption), + Widget2(widget), + gcn::WidgetListener(), + mDescription(), + mVertexes2(new ImageCollection), + mEnabledColor(getThemeColor(Theme::BUTTON)), + mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)), + mDisabledColor(getThemeColor(Theme::BUTTON_DISABLED)), + mDisabledColor2(getThemeColor(Theme::BUTTON_DISABLED_OUTLINE)), + mHighlightedColor(getThemeColor(Theme::BUTTON_HIGHLIGHTED)), + mHighlightedColor2(getThemeColor(Theme::BUTTON_HIGHLIGHTED_OUTLINE)), + mPressedColor(getThemeColor(Theme::BUTTON_PRESSED)), + mPressedColor2(getThemeColor(Theme::BUTTON_PRESSED_OUTLINE)), + mImages(nullptr), + mImageSet(nullptr), + mClickCount(0), + mTag(0), + mMode(0), + mXOffset(0), + mYOffset(0), + mImageWidth(0), + mImageHeight(0), + mRedraw(true), + mStick(false), + mPressed(false) { init(); loadImage(imageName); @@ -247,6 +287,19 @@ Button::~Button() } void Button::loadImage(const std::string &imageName) +{ + if (mImageSet) + { + mImageSet->decRef(); + mImageSet = nullptr; + } + Image *const image = Theme::getImageFromThemeXml(imageName, ""); + mImages = new Image*[BUTTON_COUNT]; + for (int f = 0; f < BUTTON_COUNT; f ++) + mImages[f] = image; +} + +void Button::loadImageSet(const std::string &imageName) { if (mImageSet) { diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index 2ba91822b..e07a3bc1d 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -79,6 +79,14 @@ class Button final : public gcn::Button, const std::string &actionEventId, gcn::ActionListener *const listener); + /** + * Constructor, sets the caption of the button to the given string and + * adds the given action listener. + */ + Button(const Widget2 *const widget, const std::string &imageName, + const std::string &caption, const std::string &actionEventId, + gcn::ActionListener *const listener); + A_DELETE_COPY(Button) /** @@ -125,6 +133,8 @@ class Button final : public gcn::Button, void loadImage(const std::string &imageName); + void loadImageSet(const std::string &imageName); + void adjustSize(); void setCaption(const std::string& caption); -- cgit v1.2.3-70-g09d2