Move HoverButton to GUIComponents

This commit is contained in:
Paul Ferrand 2020-09-11 10:21:48 +02:00
parent 59c64bcb91
commit 574afcaf74
3 changed files with 33 additions and 26 deletions

View file

@ -313,32 +313,6 @@ void Editor::Impl::uiReceiveValue(EditId id, const EditValue& v)
break;
}
}
class CHoverButton: public CTextButton {
public:
CHoverButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr)
: CTextButton(size, listener, tag, title) {}
void setHoverColor(const CColor& color)
{
hoverColor = color;
}
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override
{
backupColor = getTextColor();
setTextColor(hoverColor);
return CTextButton::onMouseEntered(where, buttons);
}
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override
{
setTextColor(backupColor);
return CTextButton::onMouseExited(where, buttons);
}
private:
CColor hoverColor;
CColor backupColor;
};
void Editor::Impl::createFrameContents()
{

View file

@ -427,3 +427,21 @@ void SValueMenu::onItemClicked(int32_t index)
if (getValue() != oldValue)
valueChanged();
}
void CHoverButton::setHoverColor (const CColor& color)
{
hoverColor_ = color;
}
CMouseEventResult CHoverButton::onMouseEntered (CPoint& where, const CButtonState& buttons)
{
backupColor_ = getTextColor();
setTextColor(hoverColor_);
return CTextButton::onMouseEntered(where, buttons);
}
CMouseEventResult CHoverButton::onMouseExited (CPoint& where, const CButtonState& buttons)
{
setTextColor(backupColor_);
return CTextButton::onMouseExited(where, buttons);
}

View file

@ -11,6 +11,7 @@
#include "vstgui/lib/controls/cslider.h"
#include "vstgui/lib/controls/cknob.h"
#include "vstgui/lib/controls/ctextlabel.h"
#include "vstgui/lib/controls/cbuttons.h"
#include "vstgui/lib/controls/coptionmenu.h"
#include "vstgui/lib/cviewcontainer.h"
#include "vstgui/lib/ccolor.h"
@ -146,3 +147,17 @@ private:
SValueMenu& menu_;
};
};
///
class CHoverButton: public CTextButton {
public:
CHoverButton(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;
private:
CColor hoverColor_;
CColor backupColor_;
};