Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight the button of the active panel #826

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions plugins/editor/layout/main.fl
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ widget_class mainView {open
image {../resources/logo_text_shaded.png} xywh {35 9 120 60}
class AboutButton
}
Fl_Button {} {
Fl_Button {panelButtons_[kPanelGeneral]} {
comment {tag=kTagFirstChangePanel+kPanelGeneral}
xywh {36 73 32 32} labelsize 30
class HomeButton
}
Fl_Button {} {
Fl_Button {panelButtons_[kPanelControls]} {
comment {tag=kTagFirstChangePanel+kPanelControls}
xywh {76 73 32 32} labelsize 30
class CCButton
}
Fl_Button {} {
comment {tag=kTagFirstChangePanel+kPanelSettings}
Fl_Button {panelButtons_[kPanelSettings]} {
comment {tag=kTagFirstChangePanel+kPanelSettings} selected
xywh {116 73 32 32} labelsize 30
class SettingsButton
}
Expand Down Expand Up @@ -220,7 +220,7 @@ widget_class mainView {open
xywh {5 110 790 285} box ROUNDED_BOX
class RoundedGroup
} {
Fl_Group controlsPanel_ {selected
Fl_Group controlsPanel_ {
xywh {5 110 790 285} box THIN_DOWN_FRAME labelsize 12
class ControlsPanel
} {}
Expand Down
2 changes: 1 addition & 1 deletion plugins/editor/src/editor/DlgAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
STextButton* btn = new STextButton(bounds, this, tag, glyph);
btn->setFont(makeOwned<CFontDesc>("Sfizz Misc Icons", fontsize));
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->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
btn->setGradient(nullptr);
Expand Down
22 changes: 17 additions & 5 deletions plugins/editor/src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct Editor::Impl : EditorController::Receiver,

unsigned activePanel_ = 0;
CViewContainer* subPanels_[kNumPanels] = {};
STextButton* panelButtons_[kNumPanels] = {};

enum {
kTagLoadSfzFile,
Expand Down Expand Up @@ -238,6 +239,7 @@ struct Editor::Impl : EditorController::Receiver,
void performCCEndEdit(unsigned cc);

void setActivePanel(unsigned panelId);
void setupCurrentPanel();
void applyBackgroundForCurrentPanel();

static void formatLabel(CTextLabel* label, const char* fmt, ...);
Expand Down Expand Up @@ -724,7 +726,7 @@ void Editor::Impl::createFrameContents()
OnThemeChanged.push_back([button, palette]() {
button->setTextColor(palette->text);
button->setInactiveColor(palette->inactiveText);
button->setHoverColor(palette->highlightedText);
button->setHighlightColor(palette->highlightedText);
});
button->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
button->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
Expand All @@ -741,7 +743,7 @@ void Editor::Impl::createFrameContents()
OnThemeChanged.push_back([button, palette]() {
button->setTextColor(palette->valueText);
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));
button->setGradient(gradient);
button->setGradientHighlighted(gradient);
Expand Down Expand Up @@ -783,7 +785,7 @@ void Editor::Impl::createFrameContents()
btn->setFont(makeOwned<CFontDesc>("Sfizz Fluent System F20", fontsize));
OnThemeChanged.push_back([btn, palette]() {
btn->setTextColor(palette->icon);
btn->setHoverColor(palette->iconHighlight);
btn->setHighlightColor(palette->iconHighlight);
});
btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
Expand Down Expand Up @@ -1156,7 +1158,7 @@ void Editor::Impl::createFrameContents()
panel->setVisible(currentPanel == activePanel_);
}

applyBackgroundForCurrentPanel();
setupCurrentPanel();

if (COptionMenu* menu = themeMenu_) {
const std::vector<std::string>& names = Theme::getAvailableNames();
Expand Down Expand Up @@ -1684,6 +1686,16 @@ void Editor::Impl::updateBackgroundImage(const char* filepath)
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()
{
CBitmap* bitmap;
Expand Down Expand Up @@ -1745,7 +1757,7 @@ void Editor::Impl::setActivePanel(unsigned panelId)
if (subPanels_[panelId])
subPanels_[panelId]->setVisible(true);
activePanel_ = panelId;
applyBackgroundForCurrentPanel();
setupCurrentPanel();
}
}

Expand Down
16 changes: 12 additions & 4 deletions plugins/editor/src/editor/GUIComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -433,11 +433,19 @@ void STextButton::setInactive(bool b)
invalid();
}

void STextButton::setHighlighted(bool b)
{
highlighted_ = b;
invalid();
}

void STextButton::draw(CDrawContext* context)
{
CColor backupColor = textColor;
if (hovered_)
textColor = hoverColor_; // textColor is protected
if (inactive_)
textColor = inactiveColor_; // textColor is protected
else if (hovered_ || highlighted_)
textColor = highlightColor_;
else if (inactive_)
textColor = inactiveColor_;
CTextButton::draw(context);
Expand Down
9 changes: 6 additions & 3 deletions plugins/editor/src/editor/GUIComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ class STextButton: public CTextButton {
STextButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr)
: CTextButton(size, listener, tag, title) {}

CColor getHoverColor() const { return hoverColor_; }
void setHoverColor(const CColor& color);
CColor getHighlightColor() const { return highlightColor_; }
void setHighlightColor(const CColor& color);
CColor getInactiveColor() const { return inactiveColor_; }
void setInactiveColor(const CColor& color);
bool isInactive() const { return inactive_; }
void setInactive(bool b);
bool isHighlighted() const { return highlighted_; }
void setHighlighted(bool b);
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
void draw(CDrawContext* context) override;
Expand All @@ -201,8 +203,9 @@ class STextButton: public CTextButton {
std::function<void()> OnHoverLeave;

private:
CColor hoverColor_;
CColor highlightColor_;
bool hovered_ { false };
bool highlighted_ { false };
CColor inactiveColor_;
bool inactive_ { false };
};
Expand Down
3 changes: 3 additions & 0 deletions plugins/editor/src/editor/layout/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ view__2->addView(view__3);
auto* const view__4 = createAboutButton(CRect(30, 5, 150, 65), kTagAbout, "", kCenterText, 14);
view__3->addView(view__4);
auto* const view__5 = createHomeButton(CRect(31, 69, 63, 101), kTagFirstChangePanel+kPanelGeneral, "", kCenterText, 30);
panelButtons_[kPanelGeneral] = view__5;
view__3->addView(view__5);
auto* const view__6 = createCCButton(CRect(71, 69, 103, 101), kTagFirstChangePanel+kPanelControls, "", kCenterText, 30);
panelButtons_[kPanelControls] = view__6;
view__3->addView(view__6);
auto* const view__7 = createSettingsButton(CRect(111, 69, 143, 101), kTagFirstChangePanel+kPanelSettings, "", kCenterText, 30);
panelButtons_[kPanelSettings] = view__7;
view__3->addView(view__7);
auto* const view__8 = createRoundedGroup(CRect(185, 5, 565, 105), -1, "", kCenterText, 14);
view__2->addView(view__8);
Expand Down