Highlight the button of the active panel

This commit is contained in:
Jean Pierre Cimalando 2021-04-14 04:10:49 +02:00
parent ae5e27b7cc
commit 6b835cafbe
6 changed files with 44 additions and 18 deletions

View file

@ -24,18 +24,18 @@ widget_class mainView {open
image {../resources/logo_text_shaded.png} xywh {35 9 120 60} image {../resources/logo_text_shaded.png} xywh {35 9 120 60}
class AboutButton class AboutButton
} }
Fl_Button {} { Fl_Button {panelButtons_[kPanelGeneral]} {
comment {tag=kTagFirstChangePanel+kPanelGeneral} comment {tag=kTagFirstChangePanel+kPanelGeneral}
xywh {36 73 32 32} labelsize 30 xywh {36 73 32 32} labelsize 30
class HomeButton class HomeButton
} }
Fl_Button {} { Fl_Button {panelButtons_[kPanelControls]} {
comment {tag=kTagFirstChangePanel+kPanelControls} comment {tag=kTagFirstChangePanel+kPanelControls}
xywh {76 73 32 32} labelsize 30 xywh {76 73 32 32} labelsize 30
class CCButton class CCButton
} }
Fl_Button {} { Fl_Button {panelButtons_[kPanelSettings]} {
comment {tag=kTagFirstChangePanel+kPanelSettings} comment {tag=kTagFirstChangePanel+kPanelSettings} selected
xywh {116 73 32 32} labelsize 30 xywh {116 73 32 32} labelsize 30
class SettingsButton class SettingsButton
} }
@ -220,7 +220,7 @@ widget_class mainView {open
xywh {5 110 790 285} box ROUNDED_BOX xywh {5 110 790 285} box ROUNDED_BOX
class RoundedGroup class RoundedGroup
} { } {
Fl_Group controlsPanel_ {selected Fl_Group controlsPanel_ {
xywh {5 110 790 285} box THIN_DOWN_FRAME labelsize 12 xywh {5 110 790 285} box THIN_DOWN_FRAME labelsize 12
class ControlsPanel class ControlsPanel
} {} } {}

View file

@ -113,7 +113,7 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
STextButton* btn = new STextButton(bounds, this, tag, glyph); STextButton* btn = new STextButton(bounds, this, tag, glyph);
btn->setFont(makeOwned<CFontDesc>("Sfizz Misc Icons", fontsize)); btn->setFont(makeOwned<CFontDesc>("Sfizz Misc Icons", fontsize));
btn->setTextColor(kWhiteCColor); btn->setTextColor(kWhiteCColor);
btn->setHoverColor(CColor(0xfd, 0x98, 0x00, 0xff)); btn->setHighlightColor(CColor(0xfd, 0x98, 0x00, 0xff));
btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00)); btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00)); btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
btn->setGradient(nullptr); btn->setGradient(nullptr);

View file

@ -73,6 +73,7 @@ struct Editor::Impl : EditorController::Receiver,
unsigned activePanel_ = 0; unsigned activePanel_ = 0;
CViewContainer* subPanels_[kNumPanels] = {}; CViewContainer* subPanels_[kNumPanels] = {};
STextButton* panelButtons_[kNumPanels] = {};
enum { enum {
kTagLoadSfzFile, kTagLoadSfzFile,
@ -238,6 +239,7 @@ struct Editor::Impl : EditorController::Receiver,
void performCCEndEdit(unsigned cc); void performCCEndEdit(unsigned cc);
void setActivePanel(unsigned panelId); void setActivePanel(unsigned panelId);
void setupCurrentPanel();
void applyBackgroundForCurrentPanel(); void applyBackgroundForCurrentPanel();
static void formatLabel(CTextLabel* label, const char* fmt, ...); static void formatLabel(CTextLabel* label, const char* fmt, ...);
@ -724,7 +726,7 @@ void Editor::Impl::createFrameContents()
OnThemeChanged.push_back([button, palette]() { OnThemeChanged.push_back([button, palette]() {
button->setTextColor(palette->text); button->setTextColor(palette->text);
button->setInactiveColor(palette->inactiveText); button->setInactiveColor(palette->inactiveText);
button->setHoverColor(palette->highlightedText); button->setHighlightColor(palette->highlightedText);
}); });
button->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00)); button->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
button->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00)); button->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
@ -741,7 +743,7 @@ void Editor::Impl::createFrameContents()
OnThemeChanged.push_back([button, palette]() { OnThemeChanged.push_back([button, palette]() {
button->setTextColor(palette->valueText); button->setTextColor(palette->valueText);
button->setInactiveColor(palette->inactiveText); button->setInactiveColor(palette->inactiveText);
button->setHoverColor(palette->highlightedText); button->setHighlightColor(palette->highlightedText);
SharedPointer<CGradient> gradient = owned(CGradient::create(0.0, 1.0, palette->valueBackground, palette->valueBackground)); SharedPointer<CGradient> gradient = owned(CGradient::create(0.0, 1.0, palette->valueBackground, palette->valueBackground));
button->setGradient(gradient); button->setGradient(gradient);
button->setGradientHighlighted(gradient); button->setGradientHighlighted(gradient);
@ -783,7 +785,7 @@ void Editor::Impl::createFrameContents()
btn->setFont(makeOwned<CFontDesc>("Sfizz Fluent System F20", fontsize)); btn->setFont(makeOwned<CFontDesc>("Sfizz Fluent System F20", fontsize));
OnThemeChanged.push_back([btn, palette]() { OnThemeChanged.push_back([btn, palette]() {
btn->setTextColor(palette->icon); btn->setTextColor(palette->icon);
btn->setHoverColor(palette->iconHighlight); btn->setHighlightColor(palette->iconHighlight);
}); });
btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00)); btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00)); btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
@ -1156,7 +1158,7 @@ void Editor::Impl::createFrameContents()
panel->setVisible(currentPanel == activePanel_); panel->setVisible(currentPanel == activePanel_);
} }
applyBackgroundForCurrentPanel(); setupCurrentPanel();
if (COptionMenu* menu = themeMenu_) { if (COptionMenu* menu = themeMenu_) {
const std::vector<std::string>& names = Theme::getAvailableNames(); const std::vector<std::string>& names = Theme::getAvailableNames();
@ -1684,6 +1686,16 @@ void Editor::Impl::updateBackgroundImage(const char* filepath)
applyBackgroundForCurrentPanel(); applyBackgroundForCurrentPanel();
} }
void Editor::Impl::setupCurrentPanel()
{
for (unsigned i = 0; i < kNumPanels; ++i) {
if (STextButton* button = panelButtons_[i])
button->setHighlighted(i == activePanel_);
}
applyBackgroundForCurrentPanel();
}
void Editor::Impl::applyBackgroundForCurrentPanel() void Editor::Impl::applyBackgroundForCurrentPanel()
{ {
CBitmap* bitmap; CBitmap* bitmap;
@ -1745,7 +1757,7 @@ void Editor::Impl::setActivePanel(unsigned panelId)
if (subPanels_[panelId]) if (subPanels_[panelId])
subPanels_[panelId]->setVisible(true); subPanels_[panelId]->setVisible(true);
activePanel_ = panelId; activePanel_ = panelId;
applyBackgroundForCurrentPanel(); setupCurrentPanel();
} }
} }

View file

@ -415,9 +415,9 @@ void SActionMenu::onItemClicked(int32_t index)
} }
/// ///
void STextButton::setHoverColor(const CColor& color) void STextButton::setHighlightColor(const CColor& color)
{ {
hoverColor_ = color; highlightColor_ = color;
invalid(); invalid();
} }
@ -433,11 +433,19 @@ void STextButton::setInactive(bool b)
invalid(); invalid();
} }
void STextButton::setHighlighted(bool b)
{
highlighted_ = b;
invalid();
}
void STextButton::draw(CDrawContext* context) void STextButton::draw(CDrawContext* context)
{ {
CColor backupColor = textColor; CColor backupColor = textColor;
if (hovered_) if (inactive_)
textColor = hoverColor_; // textColor is protected textColor = inactiveColor_; // textColor is protected
else if (hovered_ || highlighted_)
textColor = highlightColor_;
else if (inactive_) else if (inactive_)
textColor = inactiveColor_; textColor = inactiveColor_;
CTextButton::draw(context); CTextButton::draw(context);

View file

@ -187,12 +187,14 @@ public:
STextButton(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) {} : CTextButton(size, listener, tag, title) {}
CColor getHoverColor() const { return hoverColor_; } CColor getHighlightColor() const { return highlightColor_; }
void setHoverColor(const CColor& color); void setHighlightColor(const CColor& color);
CColor getInactiveColor() const { return inactiveColor_; } CColor getInactiveColor() const { return inactiveColor_; }
void setInactiveColor(const CColor& color); void setInactiveColor(const CColor& color);
bool isInactive() const { return inactive_; } bool isInactive() const { return inactive_; }
void setInactive(bool b); void setInactive(bool b);
bool isHighlighted() const { return highlighted_; }
void setHighlighted(bool b);
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
void draw(CDrawContext* context) override; void draw(CDrawContext* context) override;
@ -201,8 +203,9 @@ public:
std::function<void()> OnHoverLeave; std::function<void()> OnHoverLeave;
private: private:
CColor hoverColor_; CColor highlightColor_;
bool hovered_ { false }; bool hovered_ { false };
bool highlighted_ { false };
CColor inactiveColor_; CColor inactiveColor_;
bool inactive_ { false }; bool inactive_ { false };
}; };

View file

@ -12,10 +12,13 @@ view__2->addView(view__3);
auto* const view__4 = createAboutButton(CRect(30, 5, 150, 65), kTagAbout, "", kCenterText, 14); auto* const view__4 = createAboutButton(CRect(30, 5, 150, 65), kTagAbout, "", kCenterText, 14);
view__3->addView(view__4); view__3->addView(view__4);
auto* const view__5 = createHomeButton(CRect(31, 69, 63, 101), kTagFirstChangePanel+kPanelGeneral, "", kCenterText, 30); auto* const view__5 = createHomeButton(CRect(31, 69, 63, 101), kTagFirstChangePanel+kPanelGeneral, "", kCenterText, 30);
panelButtons_[kPanelGeneral] = view__5;
view__3->addView(view__5); view__3->addView(view__5);
auto* const view__6 = createCCButton(CRect(71, 69, 103, 101), kTagFirstChangePanel+kPanelControls, "", kCenterText, 30); auto* const view__6 = createCCButton(CRect(71, 69, 103, 101), kTagFirstChangePanel+kPanelControls, "", kCenterText, 30);
panelButtons_[kPanelControls] = view__6;
view__3->addView(view__6); view__3->addView(view__6);
auto* const view__7 = createSettingsButton(CRect(111, 69, 143, 101), kTagFirstChangePanel+kPanelSettings, "", kCenterText, 30); auto* const view__7 = createSettingsButton(CRect(111, 69, 143, 101), kTagFirstChangePanel+kPanelSettings, "", kCenterText, 30);
panelButtons_[kPanelSettings] = view__7;
view__3->addView(view__7); view__3->addView(view__7);
auto* const view__8 = createRoundedGroup(CRect(185, 5, 565, 105), -1, "", kCenterText, 14); auto* const view__8 = createRoundedGroup(CRect(185, 5, 565, 105), -1, "", kCenterText, 14);
view__2->addView(view__8); view__2->addView(view__8);