From c90238e87fdf50091113fda3c983724874119fff Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 10 Dec 2020 14:45:30 +0000 Subject: [PATCH] Add getActiveColor functions to IGUIStaticText and IGUIButton Returns currently used color - depending on state and if override color is set. Note: Not adding this to editbox for now as it's a bit more tricky there (selection changing color, so it has no single color). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6165 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 1 + include/IGUIButton.h | 4 ++++ include/IGUIStaticText.h | 4 ++++ source/Irrlicht/CGUIButton.cpp | 12 +++++++++++- source/Irrlicht/CGUIButton.h | 3 +++ source/Irrlicht/CGUIStaticText.cpp | 16 +++++++++++++--- source/Irrlicht/CGUIStaticText.h | 3 +++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/changes.txt b/changes.txt index 8a507bb..b717e7d 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,6 @@ -------------------------- Changes in 1.9 (not yet released) +- Add getActiveColor functions to IGUIStaticText and IGUIButton (get currently used color). - Add IGUIEnvironment::addToDeletionQueue to allow save removal of gui elements while iterating over them (like the same named function in ISceneManager). - IGUIEnvironment::drawAll has now a parameter to allow disabling automatic resize to screensize. Makes it easier to use partial screens with full alignment support. - No longer try to set WM_QUIT when using an external Window on Win32. diff --git a/include/IGUIButton.h b/include/IGUIButton.h index 1976ada..88eb97b 100644 --- a/include/IGUIButton.h +++ b/include/IGUIButton.h @@ -139,6 +139,10 @@ namespace gui /** \return: The override color */ virtual video::SColor getOverrideColor(void) const = 0; + //! Gets the currently used text color + /** Either a skin-color for the current state or the override color */ + virtual video::SColor getActiveColor() 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 diff --git a/include/IGUIStaticText.h b/include/IGUIStaticText.h index beb8f59..33db281 100644 --- a/include/IGUIStaticText.h +++ b/include/IGUIStaticText.h @@ -51,6 +51,10 @@ namespace gui /** \return: The override color */ virtual video::SColor getOverrideColor(void) const = 0; + //! Gets the currently used text color + /** Either a skin-color for the current state or the override color */ + virtual video::SColor getActiveColor() const = 0; + //! Sets if the static 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 diff --git a/source/Irrlicht/CGUIButton.cpp b/source/Irrlicht/CGUIButton.cpp index 895e31a..95d2b37 100644 --- a/source/Irrlicht/CGUIButton.cpp +++ b/source/Irrlicht/CGUIButton.cpp @@ -327,7 +327,7 @@ void CGUIButton::draw() if (font) font->draw(Text.c_str(), rect, - OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), + getActiveColor(), true, true, &AbsoluteClippingRect); } @@ -466,6 +466,16 @@ video::SColor CGUIButton::getOverrideColor() const return OverrideColor; } +irr::video::SColor CGUIButton::getActiveColor() const +{ + if ( OverrideColorEnabled ) + return OverrideColor; + IGUISkin* skin = Environment->getSkin(); + if (skin) + return OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT); + return OverrideColor; +} + void CGUIButton::enableOverrideColor(bool enable) { OverrideColorEnabled = enable; diff --git a/source/Irrlicht/CGUIButton.h b/source/Irrlicht/CGUIButton.h index ab383db..88ca8f4 100644 --- a/source/Irrlicht/CGUIButton.h +++ b/source/Irrlicht/CGUIButton.h @@ -50,6 +50,9 @@ namespace gui //! Gets the override color virtual video::SColor getOverrideColor(void) const _IRR_OVERRIDE_; + //! Gets the currently used text color + virtual video::SColor getActiveColor() 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_; diff --git a/source/Irrlicht/CGUIStaticText.cpp b/source/Irrlicht/CGUIStaticText.cpp index fc26a1a..086c357 100644 --- a/source/Irrlicht/CGUIStaticText.cpp +++ b/source/Irrlicht/CGUIStaticText.cpp @@ -99,8 +99,8 @@ void CGUIStaticText::draw() font->getDimension(Text.c_str()).Width; } - font->draw(Text.c_str(), frameRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), + font->draw(Text.c_str(), frameRect, + getActiveColor(), HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); } else @@ -129,7 +129,7 @@ void CGUIStaticText::draw() } font->draw(BrokenText[i].c_str(), r, - OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), + getActiveColor(), HAlign == EGUIA_CENTER, false, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); r.LowerRightCorner.Y += height; @@ -254,6 +254,16 @@ video::SColor CGUIStaticText::getOverrideColor() const } +irr::video::SColor CGUIStaticText::getActiveColor() const +{ + if ( OverrideColorEnabled ) + return OverrideColor; + IGUISkin* skin = Environment->getSkin(); + if (skin) + return OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT); + return OverrideColor; +} + //! Sets if the static text should use the override color or the //! color in the gui skin. void CGUIStaticText::enableOverrideColor(bool enable) diff --git a/source/Irrlicht/CGUIStaticText.h b/source/Irrlicht/CGUIStaticText.h index 7ca7401..b7fbf73 100644 --- a/source/Irrlicht/CGUIStaticText.h +++ b/source/Irrlicht/CGUIStaticText.h @@ -66,6 +66,9 @@ namespace gui //! Gets the override color virtual video::SColor getOverrideColor() const _IRR_OVERRIDE_; + //! Gets the currently used text color + virtual video::SColor getActiveColor() const _IRR_OVERRIDE_; + //! Sets if the static text should use the override color or the //! color in the gui skin. virtual void enableOverrideColor(bool enable) _IRR_OVERRIDE_;