diff --git a/editor/src/editor/Editor.cpp b/editor/src/editor/Editor.cpp index dd0f21ab..256f6302 100644 --- a/editor/src/editor/Editor.cpp +++ b/editor/src/editor/Editor.cpp @@ -375,11 +375,11 @@ void Editor::Impl::createFrameContents() typedef CTextButton Button; #endif typedef CTextButton ValueButton; - typedef SHoverButton LoadFileButton; - typedef SHoverButton CCButton; - typedef SHoverButton HomeButton; - typedef SHoverButton SettingsButton; - typedef SHoverButton EditFileButton; + typedef STextButton LoadFileButton; + typedef STextButton CCButton; + typedef STextButton HomeButton; + typedef STextButton SettingsButton; + typedef STextButton EditFileButton; typedef SPiano Piano; auto createLogicalGroup = [](const CRect& bounds, int, const char*, CHoriTxtAlign, int) { @@ -482,7 +482,7 @@ void Editor::Impl::createFrameContents() return vm; }; auto createGlyphButton = [this, &theme](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) { - SHoverButton* btn = new SHoverButton(bounds, this, tag, glyph); + STextButton* btn = new STextButton(bounds, this, tag, glyph); btn->setFont(new CFontDesc("Fluent System Regular W20", fontsize)); btn->setTextColor(theme->icon); btn->setHoverColor(theme->iconHighlight); diff --git a/editor/src/editor/GUIComponents.cpp b/editor/src/editor/GUIComponents.cpp index 84afec45..0ebcc7d9 100644 --- a/editor/src/editor/GUIComponents.cpp +++ b/editor/src/editor/GUIComponents.cpp @@ -428,20 +428,33 @@ void SValueMenu::onItemClicked(int32_t index) valueChanged(); } -void SHoverButton::setHoverColor (const CColor& color) +void STextButton::setHoverColor (const CColor& color) { hoverColor_ = color; } -CMouseEventResult SHoverButton::onMouseEntered (CPoint& where, const CButtonState& buttons) +void STextButton::draw(CDrawContext* context) { - backupColor_ = getTextColor(); - setTextColor(hoverColor_); + backupColor_ = textColor; + if (hovered) { + textColor = hoverColor_; // textColor is protected + } + CTextButton::draw(context); + if (hovered) + textColor = backupColor_; +} + + +CMouseEventResult STextButton::onMouseEntered (CPoint& where, const CButtonState& buttons) +{ + hovered = true; + setDirty(); return CTextButton::onMouseEntered(where, buttons); } -CMouseEventResult SHoverButton::onMouseExited (CPoint& where, const CButtonState& buttons) +CMouseEventResult STextButton::onMouseExited (CPoint& where, const CButtonState& buttons) { - setTextColor(backupColor_); + hovered = false; + setDirty(); return CTextButton::onMouseExited(where, buttons); } diff --git a/editor/src/editor/GUIComponents.h b/editor/src/editor/GUIComponents.h index 31d14bae..83d7d04a 100644 --- a/editor/src/editor/GUIComponents.h +++ b/editor/src/editor/GUIComponents.h @@ -149,15 +149,17 @@ private: }; /// -class SHoverButton: public CTextButton { +class STextButton: public CTextButton { public: - SHoverButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr) + STextButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr) : CTextButton(size, listener, tag, title) {} void setHoverColor(const CColor& color); CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; + void draw(CDrawContext* context) override; private: CColor hoverColor_; CColor backupColor_; + bool hovered { false }; };