Skip to content

Commit

Permalink
Patch Comment Tooltip (#5307)
Browse files Browse the repository at this point in the history
Add a tooltip object which shows and dismisses appropriately.
Size based on comment. Skin colors for everything.

Closes #5298
  • Loading branch information
baconpaul authored Oct 25, 2021
1 parent 931bceb commit 2f90f20
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
4 changes: 4 additions & 0 deletions resources/data/skins/dark-mode.surge-skin/skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@

<color id="patchbrowser.text" value="lightgray"/>

<color id="patchbrowser.commenttooltip.border" value="bordergray"/>
<color id="patchbrowser.commenttooltip.background" value="darkergray"/>
<color id="patchbrowser.commenttooltip.text" value="lightgray"/>

<color id="slider.light.label" value="lightgray"/>
<color id="slider.dark.label" value="lightgray"/>
<color id="slider.modulation.positive" value="#82BF50"/>
Expand Down
7 changes: 7 additions & 0 deletions src/common/SkinColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ namespace PatchBrowser
{
const Surge::Skin::Color Text("patchbrowser.text", 0, 0, 0);

namespace CommentTooltip
{
const Surge::Skin::Color Border("patchbrowser.commenttooltip.border", 0xFF979797),
Background("patchbrowser.commenttooltip.background", 0xFFE3E3E3),
Text("patchbrowser.commenttooltip.text", 0xFF151515);
}

namespace TypeAheadList
{
const Surge::Skin::Color Border("patchbrowser.typeahead.border", 100, 100, 130),
Expand Down
4 changes: 4 additions & 0 deletions src/common/SkinColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ namespace PatchBrowser
{
extern const Surge::Skin::Color Text;

namespace CommentTooltip
{
extern const Surge::Skin::Color Border, Background, Text;
}
namespace TypeAheadList
{
extern const Surge::Skin::Color Border, Background, Text, HighlightBackground, HighlightText,
Expand Down
28 changes: 28 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ SurgeGUIEditor::SurgeGUIEditor(SurgeSynthEditor *jEd, SurgeSynthesizer *synth)
paramInfowindow = std::make_unique<Surge::Widgets::ParameterInfowindow>();
paramInfowindow->setVisible(false);

patchSelectorComment = std::make_unique<Surge::Widgets::PatchSelectorCommentTooltip>();
patchSelectorComment->setVisible(false);

typeinParamEditor = std::make_unique<Surge::Overlays::TypeinParamEditor>();
typeinParamEditor->setVisible(false);
typeinParamEditor->setSurgeGUIEditor(this);
Expand Down Expand Up @@ -1534,6 +1537,7 @@ void SurgeGUIEditor::openOrRecreateEditor()
"Browse");

frame->addAndMakeVisible(*patchSelector);

break;
}
case Surge::Skin::Connector::NonParameterConnection::FX_SELECTOR:
Expand Down Expand Up @@ -1695,6 +1699,9 @@ void SurgeGUIEditor::openOrRecreateEditor()
paramInfowindow->setVisible(false);
frame->addChildComponent(*paramInfowindow);

patchSelectorComment->setVisible(false);
frame->addChildComponent(*patchSelectorComment);

// Mouse behavior
if (Surge::Widgets::ModulatableSlider::sliderMoveRateState ==
Surge::Widgets::ModulatableSlider::kUnInitialized)
Expand Down Expand Up @@ -3654,6 +3661,7 @@ void SurgeGUIEditor::reloadFromSkin()
bitmapStore->setPhysicalZoomFactor(getZoomFactor() * dbs);

paramInfowindow->setSkin(currentSkin, bitmapStore);
patchSelectorComment->setSkin(currentSkin, bitmapStore);

auto bg = currentSkin->customBackgroundImage();

Expand Down Expand Up @@ -5912,3 +5920,23 @@ void SurgeGUIEditor::loadFromDAWExtraState(SurgeSynthesizer *synth)
}
}
}

void SurgeGUIEditor::showPatchCommentTooltip(const std::string &comment)
{
if (patchSelectorComment)
{
patchSelectorComment->setVisible(true);
patchSelectorComment->getParentComponent()->toFront(true);
patchSelectorComment->toFront(true);
patchSelectorComment->positionForComment(patchSelector->getBounds().getBottomLeft(),
comment);
}
}

void SurgeGUIEditor::hidePatchCommentTooltip()
{
if (patchSelectorComment && patchSelectorComment->isVisible())
{
patchSelectorComment->setVisible(false);
}
}
4 changes: 4 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct NumberField;
struct OscillatorWaveformDisplay;
struct ParameterInfowindow;
struct PatchSelector;
struct PatchSelectorCommentTooltip;
struct Switch;
struct VerticalLabel;
struct VuMeter;
Expand Down Expand Up @@ -448,6 +449,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
private:
std::array<std::unique_ptr<Surge::Widgets::VuMeter>, n_fx_slots + 1> vu;
std::unique_ptr<Surge::Widgets::PatchSelector> patchSelector;
std::unique_ptr<Surge::Widgets::PatchSelectorCommentTooltip> patchSelectorComment;
std::unique_ptr<Surge::Widgets::OscillatorMenu> oscMenu;
std::unique_ptr<Surge::Widgets::FxMenu> fxMenu;
std::unique_ptr<Surge::Widgets::WaveShaperSelector> waveshaperSelector;
Expand All @@ -459,6 +461,8 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
void setupAlternates(modsources ms);

public:
void showPatchCommentTooltip(const std::string &comment);
void hidePatchCommentTooltip();
void showInfowindow(int ptag, juce::Rectangle<int> relativeTo, bool isModulated);
void showInfowindowSelfDismiss(int ptag, juce::Rectangle<int> relativeTo, bool isModulated);
void updateInfowindowContents(int ptag, bool isModulated);
Expand Down
66 changes: 63 additions & 3 deletions src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ void PatchSelector::mouseMove(const juce::MouseEvent &e)
{
if (tooltipCountdown >= 0)
tooltipCountdown = 5;
toggleCommentTooltip(false);
// todo : apply mouse tolerance here
if (tooltipShowing && e.position.getDistanceFrom(tooltipMouseLocation.toFloat()) > 1)
toggleCommentTooltip(false);
else
tooltipMouseLocation = e.position;

auto pfh = favoritesHover;
favoritesHover = false;
if (favoritesRect.contains(e.position.toInt()))
Expand Down Expand Up @@ -306,8 +311,21 @@ void PatchSelector::shouldTooltip()

void PatchSelector::toggleCommentTooltip(bool b)
{
if (b && !comment.empty())
std::cout << "-------------\n" << comment << "---------------\n" << std::endl;
auto sge = firstListenerOfType<SurgeGUIEditor>();

if (sge)
{
if (b && !comment.empty())
{
tooltipShowing = true;
sge->showPatchCommentTooltip(comment);
}
else
{
tooltipShowing = false;
sge->hidePatchCommentTooltip();
}
}
}

void PatchSelector::openPatchBrowser()
Expand Down Expand Up @@ -927,5 +945,47 @@ std::unique_ptr<juce::AccessibilityHandler> PatchSelector::createAccessibilityHa
}
#endif

void PatchSelectorCommentTooltip::paint(juce::Graphics &g)
{
namespace clr = Colors::PatchBrowser::CommentTooltip;
g.fillAll(skin->getColor(clr::Border));
g.setColour(skin->getColor(clr::Background));
g.fillRect(getLocalBounds().reduced(1));
g.setColour(skin->getColor(clr::Text));
g.setFont(Surge::GUI::getFontManager()->getLatoAtSize(9));
g.drawMultiLineText(comment, 5, g.getCurrentFont().getHeight() + 2, getWidth(),
juce::Justification::left);
}

void PatchSelectorCommentTooltip::positionForComment(const juce::Point<int> &topLeft,
const std::string &c)
{
comment = c;

std::stringstream ss(comment);
std::string to;

int idx = 0;

auto ft = Surge::GUI::getFontManager()->getLatoAtSize(9);
auto width = 0;
while (std::getline(ss, to, '\n'))
{
auto w = ft.getStringWidth(to);
width = std::max(w, width);
idx++;
}

auto height = std::max(idx * (ft.getHeight() + 2), 30.f);

auto r = juce::Rectangle<int>()
.withX(topLeft.x)
.withY(topLeft.y)
.withWidth(width + 12)
.withHeight(height);
setBounds(r);
repaint();
}

} // namespace Widgets
} // namespace Surge
17 changes: 16 additions & 1 deletion src/surge-xt/gui/widgets/PatchSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct PatchSelector : public juce::Component,
favoritesHover = false;
searchHover = false;
tooltipCountdown = -1;
toggleCommentTooltip(false);
// toggleCommentTooltip(false);
repaint();
}
void showClassicMenu(bool singleCategory = false);
Expand Down Expand Up @@ -150,6 +150,8 @@ struct PatchSelector : public juce::Component,
int tooltipCountdown{-1};
void toggleCommentTooltip(bool b);
void shouldTooltip();
juce::Point<float> tooltipMouseLocation;
bool tooltipShowing{false};

/**
* populatePatchMenuForCategory
Expand All @@ -168,6 +170,19 @@ struct PatchSelector : public juce::Component,
protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchSelector);
};

struct PatchSelectorCommentTooltip : public juce::Component,
public Surge::GUI::SkinConsumingComponent
{
PatchSelectorCommentTooltip(){};
void paint(juce::Graphics &g) override;

std::string comment;
void positionForComment(const juce::Point<int> &topLeft, const std::string &comment);

protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchSelectorCommentTooltip);
};
} // namespace Widgets
} // namespace Surge
#endif // SURGE_XT_PATCHSELECTOR_H

0 comments on commit 2f90f20

Please sign in to comment.