From 92799fded9df433e683b513cf8cd0d4e4c7a2385 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sat, 21 Oct 2017 14:56:19 +0000 Subject: [PATCH] Add IGUIButton::setOverrideColor to allow overriding text-color (same function as statictexts and editboxes have). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5546 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 1 + include/IGUIButton.h | 21 +++++++++++++++++++++ source/Irrlicht/CGUIButton.cpp | 25 ++++++++++++++++++++++++- source/Irrlicht/CGUIButton.h | 15 +++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index 33d07ee3..d42d6da5 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) +- Add IGUIButton::setOverrideColor to allow overriding text-color (same function as statictexts and editboxes have). - Add functions IGUIButton::getClickShiftState and IGUIButton::getClickControlState to get shift/ctrl key-state when a button was clicked. Thanks @StarSonata for patch. - Add function ISceneManager::clearAllRegisteredNodesForRendering. - Add function IVideoDriver::queryTextureFormat to allow checking if a driver supports textures with a specific color format. diff --git a/include/IGUIButton.h b/include/IGUIButton.h index 1775d475..1976adaf 100644 --- a/include/IGUIButton.h +++ b/include/IGUIButton.h @@ -128,6 +128,27 @@ namespace gui font of the active skin otherwise */ virtual IGUIFont* getActiveFont() const = 0; + //! Sets another color for the button text. + /** When set, this color is used instead of EGDC_BUTTON_TEXT/EGDC_GRAY_TEXT. + You don't need to call enableOverrideColor(true), that's done by this function. + If you want the the color of the skin back, call enableOverrideColor(false); + \param color: New color of the text. */ + virtual void setOverrideColor(video::SColor color) = 0; + + //! Gets the override color + /** \return: The override color */ + virtual video::SColor getOverrideColor(void) const = 0; + + //! Sets if the button text should use the override color or the color in the gui skin. + /** \param enable: If set to true, the override color, which can be set + with IGUIStaticText::setOverrideColor is used, otherwise the + EGDC_BUTTON_TEXT or EGDC_GRAY_TEXT color of the skin. */ + virtual void enableOverrideColor(bool enable) = 0; + + //! Checks if an override color is enabled + /** \return true if the override color is enabled, false otherwise */ + virtual bool isOverrideColorEnabled(void) const = 0; + //! Sets an image which should be displayed on the button when it is in the given state. /** Only one image-state can be active at a time. Images are drawn below sprites. If a state is without image it will try to use images from other states as described diff --git a/source/Irrlicht/CGUIButton.cpp b/source/Irrlicht/CGUIButton.cpp index d99215a9..1a0bb7a6 100644 --- a/source/Irrlicht/CGUIButton.cpp +++ b/source/Irrlicht/CGUIButton.cpp @@ -21,6 +21,7 @@ CGUIButton::CGUIButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle, bool noclip) : IGUIButton(environment, parent, id, rectangle), SpriteBank(0), OverrideFont(0), + OverrideColorEnabled(false), OverrideColor(video::SColor(101,255,255,255)), ClickTime(0), HoverTime(0), FocusTime(0), ClickShiftState(false), ClickControlState(false), IsPushButton(false), Pressed(false), @@ -327,7 +328,7 @@ void CGUIButton::draw() if (font) font->draw(Text.c_str(), rect, - skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), + OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), true, true, &AbsoluteClippingRect); } @@ -454,6 +455,28 @@ IGUIFont* CGUIButton::getActiveFont() const return 0; } +//! Sets another color for the text. +void CGUIButton::setOverrideColor(video::SColor color) +{ + OverrideColor = color; + OverrideColorEnabled = true; +} + +video::SColor CGUIButton::getOverrideColor() const +{ + return OverrideColor; +} + +void CGUIButton::enableOverrideColor(bool enable) +{ + OverrideColorEnabled = enable; +} + +bool CGUIButton::isOverrideColorEnabled() const +{ + return OverrideColorEnabled; +} + void CGUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, const core::rect& sourceRect) { if ( state >= EGBIS_COUNT ) diff --git a/source/Irrlicht/CGUIButton.h b/source/Irrlicht/CGUIButton.h index c3360601..ab383db7 100644 --- a/source/Irrlicht/CGUIButton.h +++ b/source/Irrlicht/CGUIButton.h @@ -44,6 +44,18 @@ namespace gui //! Get the font which is used right now for drawing virtual IGUIFont* getActiveFont() const _IRR_OVERRIDE_; + //! Sets another color for the button text. + virtual void setOverrideColor(video::SColor color) _IRR_OVERRIDE_; + + //! Gets the override color + virtual video::SColor getOverrideColor(void) const _IRR_OVERRIDE_; + + //! Sets if the button text should use the override color or the color in the gui skin. + virtual void enableOverrideColor(bool enable) _IRR_OVERRIDE_; + + //! Checks if an override color is enabled + virtual bool isOverrideColorEnabled(void) const _IRR_OVERRIDE_; + //! Sets an image which should be displayed on the button when it is in the given state. virtual void setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image=0, const core::rect& sourceRect=core::rect(0,0,0,0)) _IRR_OVERRIDE_; @@ -217,6 +229,9 @@ namespace gui IGUIFont* OverrideFont; + bool OverrideColorEnabled; + video::SColor OverrideColor; + u32 ClickTime, HoverTime, FocusTime; bool ClickShiftState;