Skip to content

Commit

Permalink
Merge pull request #1057 from paulfd/button-hints
Browse files Browse the repository at this point in the history
Button hints and closing the about dialog with Esc
  • Loading branch information
paulfd authored Dec 30, 2021
2 parents 8993426 + 8114292 commit 3d50afc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 16 deletions.
15 changes: 10 additions & 5 deletions plugins/editor/layout/main.fl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version 1.0304
header_name {.h}
code_name {.cxx}
widget_class mainView {open
xywh {607 439 800 475} type Double
xywh {624 612 800 475} type Double
class LogicalGroup visible
} {
Fl_Box imageContainer_ {
Expand Down Expand Up @@ -161,7 +161,7 @@ widget_class mainView {open
}
}
}
Fl_Group {subPanels_[kPanelInfo]} {open
Fl_Group {subPanels_[kPanelInfo]} {
xywh {5 110 790 285} hide
class LogicalGroup
} {
Expand Down Expand Up @@ -221,7 +221,7 @@ widget_class mainView {open
}
}
}
Fl_Group {subPanels_[kPanelControls]} {open
Fl_Group {subPanels_[kPanelControls]} {
xywh {5 110 790 285} hide
class LogicalGroup
} {
Expand All @@ -235,7 +235,7 @@ widget_class mainView {open
} {}
}
}
Fl_Group {subPanels_[kPanelSettings]} {open
Fl_Group {subPanels_[kPanelSettings]} {
xywh {0 110 825 360}
class LogicalGroup
} {
Expand Down Expand Up @@ -366,7 +366,7 @@ widget_class mainView {open
class Label
}
Fl_Check_Button sustainCancelsReleaseCheckbox_ {
comment {tag=kTagSetSustainCancelsRelease} selected
comment {tag=kTagSetSustainCancelsRelease}
xywh {200 220 25 25} down_box DOWN_BOX
class Checkbox
}
Expand Down Expand Up @@ -456,4 +456,9 @@ widget_class mainView {open
xywh {5 110 790 285} hide
class LogicalGroup
} {}
Fl_Box lblHover_ {
comment {palette=invertedPalette} selected
xywh {5 105 170 25} labelsize 12 hide
class HoverBox
}
}
18 changes: 18 additions & 0 deletions plugins/editor/src/editor/DlgAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ CMouseEventResult SAboutDialog::onMouseDown(CPoint& where, const CButtonState& b
return result;
}

int32_t SAboutDialog::onKeyDown (const VstKeyCode& keyCode, CFrame* frame)
{
if (keyCode.virt == VKEY_ESCAPE) {
setVisible(false);
frame->unregisterKeyboardHook(this);
return 1;
}

return -1;
}

int32_t SAboutDialog::onKeyUp (const VstKeyCode& keyCode, CFrame* frame)
{
(void)keyCode;
(void)frame;
return -1;
}

void SAboutDialog::valueChanged(CControl *ctl)
{
int32_t tag = ctl->getTag();
Expand Down
4 changes: 3 additions & 1 deletion plugins/editor/src/editor/DlgAbout.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using namespace VSTGUI;

class SAboutDialog : public CViewContainer, public IControlListener {
class SAboutDialog : public CViewContainer, public IControlListener, public IKeyboardHook{

enum {
kTagButtonSfztools,
Expand All @@ -28,6 +28,8 @@ class SAboutDialog : public CViewContainer, public IControlListener {

void setPluginFormat(const std::string& pluginFormat);
void setPluginHost(const std::string& pluginHost);
int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override;
int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override;

protected:
CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
Expand Down
74 changes: 64 additions & 10 deletions plugins/editor/src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct Editor::Impl : EditorController::Receiver,
CTextLabel* keyswitchLabel_ = nullptr;
CTextLabel* keyswitchInactiveLabel_ = nullptr;
CTextLabel* keyswitchBadge_ = nullptr;
CTextLabel* lblHover_ = nullptr;
COptionMenu* themeMenu_ = nullptr;
std::unique_ptr<Theme> theme_;

Expand Down Expand Up @@ -232,6 +233,8 @@ struct Editor::Impl : EditorController::Receiver,
void updatePreloadSizeLabel(int preloadSize);
void updateScalaRootKeyLabel(int rootKey);
void updateStretchedTuningLabel(float stretchedTuning);
void buttonHoverEnter(CControl* btn, const char* text);
void buttonHoverLeave(CControl* btn);

absl::string_view getCurrentKeyswitchName() const;
void updateKeyswitchNameLabel();
Expand Down Expand Up @@ -871,6 +874,19 @@ void Editor::Impl::createFrameContents()
cb->setRoundRectRadius(5.0);
return cb;
};
auto createHoverBox = [this, &palette](const CRect& bounds, int, const char* label, CHoriTxtAlign align, int fontsize) {
CTextLabel* lbl = new CTextLabel(bounds, label);
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
OnThemeChanged.push_back([lbl, palette]() {
lbl->setFontColor(palette->valueText);
lbl->setBackColor(palette->valueBackground);
lbl->setFrameColor(palette->valueText);
});
lbl->setHoriAlign(align);
lbl->setFont(font);
lbl->setAutosizeFlags(kAutosizeAll);
return lbl;
};
auto createGlyphButton = [this, &palette](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) {
STextButton* btn = new STextButton(bounds, this, tag, glyph);
btn->setFont(makeOwned<CFontDesc>("Sfizz Fluent System F20", fontsize));
Expand All @@ -884,18 +900,29 @@ void Editor::Impl::createFrameContents()
btn->setGradientHighlighted(nullptr);
return btn;
};
auto createHomeButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue1d6", bounds, tag, fontsize);
auto createHomeButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue1d6", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Home"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createInfoButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue1e7", bounds, tag, fontsize);
auto createInfoButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue1e7", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Information"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createCCButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
// return createGlyphButton(u8"\ue240", bounds, tag, fontsize);
return createGlyphButton(u8"\ue253", bounds, tag, fontsize);
auto createCCButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue253", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Controls"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createSettingsButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue2e4", bounds, tag, fontsize);
auto createSettingsButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue2e4", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Settings"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
#if 0
auto createEditFileButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
Expand Down Expand Up @@ -1714,6 +1741,30 @@ void Editor::Impl::updateStretchedTuningLabel(float stretchedTuning)
label->setText(text);
}

void Editor::Impl::buttonHoverEnter(CControl* btn, const char* text)
{
lblHover_->setText(text);
lblHover_->sizeToFit();
CRect rect = lblHover_->getViewSize();
CRect btnRect = btn->getViewSize();
auto height = rect.getHeight();
auto width = rect.getWidth();
rect.left = btnRect.left;
rect.top = btnRect.bottom + 2;
rect.setWidth(width + 10);
rect.setHeight(height);
lblHover_->setViewSize(rect);
lblHover_->setVisible(true);
lblHover_->invalid();
}

void Editor::Impl::buttonHoverLeave(CControl* btn)
{
(void)btn;
lblHover_->setVisible(false);
lblHover_->invalid();
}

absl::string_view Editor::Impl::getCurrentKeyswitchName() const
{
int sw = currentKeyswitch_;
Expand Down Expand Up @@ -2076,7 +2127,10 @@ void Editor::Impl::valueChanged(CControl* ctl)
if (value != 1)
break;

Call::later([this]() { aboutDialog_->setVisible(true); });
Call::later([this]() {
aboutDialog_->setVisible(true);
frame_->registerKeyboardHook(aboutDialog_);
});
break;

case kTagThemeMenu:
Expand Down
6 changes: 6 additions & 0 deletions plugins/editor/src/editor/layout/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,9 @@ auto* const view__91 = createLogicalGroup(CRect(5, 110, 795, 395), -1, "", kCent
subPanels_[kPanelGeneral] = view__91;
view__0->addView(view__91);
view__91->setVisible(false);
enterPalette(invertedPalette);
auto* const view__92 = createHoverBox(CRect(5, 105, 175, 130), -1, "", kCenterText, 12);
lblHover_ = view__92;
view__0->addView(view__92);
view__92->setVisible(false);
enterPalette(defaultPalette);

0 comments on commit 3d50afc

Please sign in to comment.