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

Allow the SFZ label to be clicked like a button #496

Merged
merged 1 commit into from
Oct 13, 2020
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
5 changes: 3 additions & 2 deletions editor/layout/main.fl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ widget_class mainView {open
}
Fl_Box sfzFileLabel_ {
label {DefaultInstrument.sfz}
comment {tag=kTagLoadSfzFile} selected
xywh {195 11 250 31} labelsize 20 align 20
class Label
class ClickableLabel
}
Fl_Box {} {
label {Key switch:}
Expand All @@ -80,7 +81,7 @@ widget_class mainView {open
class NextFileButton
}
Fl_Button fileOperationsMenu_ {
comment {tag=kTagFileOperations} selected
comment {tag=kTagFileOperations}
xywh {530 14 25 25} labelsize 24
class ChevronDropDown
}
Expand Down
52 changes: 43 additions & 9 deletions editor/src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
kTagLastChangePanel = kTagFirstChangePanel + kNumPanels - 1,
};

CTextLabel* sfzFileLabel_ = nullptr;
STextButton* sfzFileLabel_ = nullptr;
CTextLabel* scalaFileLabel_ = nullptr;
CTextButton* scalaFileButton_ = nullptr;
STextButton* scalaFileButton_ = nullptr;
CControl *volumeSlider_ = nullptr;
CTextLabel* volumeLabel_ = nullptr;
SValueMenu *numVoicesSlider_ = nullptr;
Expand Down Expand Up @@ -122,7 +122,8 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
void updateSfzFileLabel(const std::string& filePath);
void updateScalaFileLabel(const std::string& filePath);
static void updateLabelWithFileName(CTextLabel* label, const std::string& filePath, absl::string_view removedSuffix);
static void updateButtonWithFileName(CTextButton* button, const std::string& filePath, absl::string_view removedSuffix);
static void updateButtonWithFileName(STextButton* button, const std::string& filePath, absl::string_view removedSuffix);
static void updateSButtonWithFileName(STextButton* button, const std::string& filePath, absl::string_view removedSuffix);
void updateVolumeLabel(float volume);
void updateNumVoicesLabel(int numVoices);
void updateOversamplingLabel(int oversamplingLog2);
Expand Down Expand Up @@ -329,6 +330,8 @@ void Editor::Impl::createFrameContents()
struct Theme {
CColor boxBackground;
CColor text;
CColor inactiveText;
CColor highlightedText;
CColor titleBoxText;
CColor titleBoxBackground;
CColor icon;
Expand All @@ -343,6 +346,8 @@ void Editor::Impl::createFrameContents()
Theme lightTheme;
lightTheme.boxBackground = { 0xba, 0xbd, 0xb6 };
lightTheme.text = { 0x00, 0x00, 0x00 };
lightTheme.inactiveText = { 0xb2, 0xb2, 0xb2 };
lightTheme.highlightedText = { 0xfd, 0x98, 0x00 };
lightTheme.titleBoxText = { 0xff, 0xff, 0xff };
lightTheme.titleBoxBackground = { 0x2e, 0x34, 0x36 };
lightTheme.icon = lightTheme.text;
Expand All @@ -355,6 +360,8 @@ void Editor::Impl::createFrameContents()
Theme darkTheme;
darkTheme.boxBackground = { 0x2e, 0x34, 0x36 };
darkTheme.text = { 0xff, 0xff, 0xff };
darkTheme.inactiveText = { 0xb2, 0xb2, 0xb2 };
darkTheme.highlightedText = { 0xfd, 0x98, 0x00 };
darkTheme.titleBoxText = { 0x00, 0x00, 0x00 };
darkTheme.titleBoxBackground = { 0xba, 0xbd, 0xb6 };
darkTheme.icon = darkTheme.text;
Expand Down Expand Up @@ -384,7 +391,8 @@ void Editor::Impl::createFrameContents()
#if 0
typedef CTextButton Button;
#endif
typedef CTextButton ValueButton;
typedef STextButton ClickableLabel;
typedef STextButton ValueButton;
typedef STextButton LoadFileButton;
typedef STextButton CCButton;
typedef STextButton HomeButton;
Expand Down Expand Up @@ -471,13 +479,31 @@ void Editor::Impl::createFrameContents()
return button;
};
#endif
auto createClickableLabel = [this, &theme](const CRect& bounds, int tag, const char* label, CHoriTxtAlign align, int fontsize) {
STextButton* button = new STextButton(bounds, this, tag, label);
auto font = owned(new CFontDesc("Roboto", fontsize));
button->setFont(font);
button->setTextAlignment(align);
button->setTextColor(theme->text);
button->setInactiveColor(theme->inactiveText);
button->setHoverColor(theme->highlightedText);
button->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
button->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
SharedPointer<CGradient> gradient = owned(CGradient::create(0.0, 1.0, CColor(0x00, 0x00, 0x00, 0x00), CColor(0x00, 0x00, 0x00, 0x00)));
button->setGradient(gradient);
button->setGradientHighlighted(gradient);
return button;
};
auto createValueButton = [this, &theme](const CRect& bounds, int tag, const char* label, CHoriTxtAlign align, int fontsize) {
CTextButton* button = new CTextButton(bounds, this, tag, label);
STextButton* button = new STextButton(bounds, this, tag, label);
auto font = owned(new CFontDesc("Roboto", fontsize));
button->setFont(font);
button->setTextAlignment(align);
button->setTextColor(theme->valueText);
button->setInactiveColor(theme->inactiveText);
button->setHoverColor(theme->highlightedText);
button->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
button->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
SharedPointer<CGradient> gradient = owned(CGradient::create(0.0, 1.0, theme->valueBackground, theme->valueBackground));
button->setGradient(gradient);
button->setGradientHighlighted(gradient);
Expand All @@ -501,6 +527,7 @@ void Editor::Impl::createFrameContents()
btn->setTextColor(theme->icon);
btn->setHoverColor(theme->iconHighlight);
btn->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
btn->setFrameColorHighlighted(CColor(0x00, 0x00, 0x00, 0x00));
btn->setGradient(nullptr);
btn->setGradientHighlighted(nullptr);
return btn;
Expand Down Expand Up @@ -834,7 +861,7 @@ absl::string_view Editor::Impl::simplifiedFileName(absl::string_view path, absl:

void Editor::Impl::updateSfzFileLabel(const std::string& filePath)
{
updateLabelWithFileName(sfzFileLabel_, filePath, ".sfz");
updateButtonWithFileName(sfzFileLabel_, filePath, ".sfz");
}

void Editor::Impl::updateScalaFileLabel(const std::string& filePath)
Expand All @@ -852,13 +879,20 @@ void Editor::Impl::updateLabelWithFileName(CTextLabel* label, const std::string&
label->setText(fileName.c_str());
}

void Editor::Impl::updateButtonWithFileName(CTextButton* button, const std::string& filePath, absl::string_view removedSuffix)
void Editor::Impl::updateButtonWithFileName(STextButton* button, const std::string& filePath, absl::string_view removedSuffix)
{
if (!button)
return;

std::string fileName = std::string(simplifiedFileName(filePath, removedSuffix, "<No file>"));
button->setTitle(fileName.c_str());
std::string fileName = std::string(simplifiedFileName(filePath, removedSuffix, {}));
if (!fileName.empty()) {
button->setTitle(fileName.c_str());
button->setInactive(false);
}
else {
button->setTitle("No file");
button->setInactive(true);
}
}

void Editor::Impl::updateVolumeLabel(float volume)
Expand Down
28 changes: 21 additions & 7 deletions editor/src/editor/GUIComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ void SActionMenu::setTitle(std::string title)
void SActionMenu::setHoverColor(const CColor& color)
{
hoverColor_ = color;
invalid();
}

CMenuItem* SActionMenu::addEntry(CMenuItem* item, int32_t tag, int32_t index)
Expand Down Expand Up @@ -554,33 +555,46 @@ void SActionMenu::onItemClicked(int32_t index)
}

///
void STextButton::setHoverColor (const CColor& color)
void STextButton::setHoverColor(const CColor& color)
{
hoverColor_ = color;
invalid();
}

void STextButton::setInactiveColor(const CColor& color)
{
inactiveColor_ = color;
invalid();
}

void STextButton::setInactive(bool b)
{
inactive_ = b;
invalid();
}

void STextButton::draw(CDrawContext* context)
{
CColor backupColor = textColor;
if (hovered) {
if (hovered_)
textColor = hoverColor_; // textColor is protected
}
else if (inactive_)
textColor = inactiveColor_;
CTextButton::draw(context);
if (hovered)
textColor = backupColor;
textColor = backupColor;
}


CMouseEventResult STextButton::onMouseEntered (CPoint& where, const CButtonState& buttons)
{
hovered = true;
hovered_ = true;
invalid();
return CTextButton::onMouseEntered(where, buttons);
}

CMouseEventResult STextButton::onMouseExited (CPoint& where, const CButtonState& buttons)
{
hovered = false;
hovered_ = false;
invalid();
return CTextButton::onMouseExited(where, buttons);
}
Expand Down
8 changes: 7 additions & 1 deletion editor/src/editor/GUIComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,18 @@ class STextButton: public CTextButton {

CColor getHoverColor() const { return hoverColor_; }
void setHoverColor(const CColor& color);
CColor getInactiveColor() const { return inactiveColor_; }
void setInactiveColor(const CColor& color);
bool isInactive() const { return inactive_; }
void setInactive(bool b);
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
void draw(CDrawContext* context) override;
private:
CColor hoverColor_;
bool hovered { false };
bool hovered_ { false };
CColor inactiveColor_;
bool inactive_ { false };
};

///
Expand Down
2 changes: 1 addition & 1 deletion editor/src/editor/layout/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HLine* const view__9 = createHLine(CRect(10, 36, 370, 41), -1, "", kCenterText,
view__8->addView(view__9);
HLine* const view__10 = createHLine(CRect(10, 68, 370, 73), -1, "", kCenterText, 14);
view__8->addView(view__10);
Label* const view__11 = createLabel(CRect(10, 6, 260, 37), -1, "DefaultInstrument.sfz", kLeftText, 20);
ClickableLabel* const view__11 = createClickableLabel(CRect(10, 6, 260, 37), kTagLoadSfzFile, "DefaultInstrument.sfz", kLeftText, 20);
sfzFileLabel_ = view__11;
view__8->addView(view__11);
Label* const view__12 = createLabel(CRect(10, 39, 260, 69), -1, "Key switch:", kLeftText, 20);
Expand Down