Skip to content

Commit

Permalink
Add a tooltip display when mouse editing a zone (#1420)
Browse files Browse the repository at this point in the history
Its rudimentary but in place for future expansion
  • Loading branch information
baconpaul authored Oct 15, 2024
1 parent 024680a commit 82a69f8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src-ui/app/SCXTEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ struct SCXTEditor : sst::jucegui::components::WindowPanel, juce::DragAndDropCont
}

void showTooltip(const juce::Component &relativeTo);
void showTooltip(const juce::Component &relativeTo, const juce::Point<int> &internalPosition);
void repositionTooltip(const juce::Component &relativeTo,
const juce::Point<int> &internalPosition);
void hideTooltip();
void setTooltipContents(const std::string &title,
const std::vector<sst::jucegui::components::ToolTip::Row> &rows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,29 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)

if (!keyboardHotZones.empty() && keyboardHotZones[0].contains(e.position))
{
updateTooltipContents(true, e.position.toInt());
mouseState = DRAG_KEY;
dragFrom[0] = FROM_START;
return;
}
if (!keyboardHotZones.empty() && keyboardHotZones[1].contains(e.position))
{
updateTooltipContents(true, e.position.toInt());
mouseState = DRAG_KEY;
dragFrom[0] = FROM_END;
return;
}

if (!velocityHotZones.empty() && velocityHotZones[0].contains(e.position))
{
updateTooltipContents(true, e.position.toInt());
mouseState = DRAG_VELOCITY;
dragFrom[1] = FROM_END;
return;
}
if (!velocityHotZones.empty() && velocityHotZones[1].contains(e.position))
{
updateTooltipContents(true, e.position.toInt());
mouseState = DRAG_VELOCITY;
dragFrom[1] = FROM_START;
return;
Expand All @@ -104,6 +108,8 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
dragFrom[0] = (idx == 1 || idx == 2) ? FROM_END : FROM_START;
dragFrom[1] = (idx < 2) ? FROM_END : FROM_START;
mouseState = DRAG_KEY_AND_VEL;
updateTooltipContents(true, e.position.toInt());

return;
}
}
Expand All @@ -115,6 +121,8 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
{
lastMousePos = e.position;
mouseState = DRAG_SELECTED_ZONE;
updateTooltipContents(true, e.position.toInt());

return;
}
}
Expand Down Expand Up @@ -172,6 +180,7 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
display->editor->doSelectionAction(nextZone, true, false, true);
lastMousePos = e.position;
mouseState = DRAG_SELECTED_ZONE;
updateTooltipContents(true, e.position.toInt());
}
else
{
Expand All @@ -180,6 +189,7 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
display->editor->doSelectionAction(nextZone, true, true, true);
lastMousePos = e.position;
mouseState = DRAG_SELECTED_ZONE;
updateTooltipContents(true, e.position.toInt());
}
}
else
Expand All @@ -189,12 +199,16 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
nextZone, true, !(e.mods.isCommandDown() || e.mods.isAltDown()), true);
lastMousePos = e.position;
mouseState = DRAG_SELECTED_ZONE;
updateTooltipContents(true, e.position.toInt());
}
}
else
{
if (e.mods.isCommandDown())
{
mouseState = CREATE_EMPTY_ZONE;
updateTooltipContents(true, e.position.toInt());
}
else
mouseState = MULTI_SELECT;
firstMousePos = e.position.toFloat();
Expand Down Expand Up @@ -448,11 +462,21 @@ void ZoneLayoutDisplay::mouseDrag(const juce::MouseEvent &e)
lastMousePos = e.position.toFloat();
repaint();
}

if (tooltipActive)
{
updateTooltipContents(false, e.position.toInt());
}
}

void ZoneLayoutDisplay::mouseUp(const juce::MouseEvent &e)
{
setMouseCursor(juce::MouseCursor::NormalCursor);
if (tooltipActive)
{
editor->hideTooltip();
tooltipActive = false;
}
if (mouseState == MULTI_SELECT)
{
auto rz = juce::Rectangle<float>(firstMousePos, e.position);
Expand Down Expand Up @@ -1101,4 +1125,38 @@ void ZoneLayoutDisplay::labelZoneRectangle(juce::Graphics &g, const juce::Rectan
}
}

void ZoneLayoutDisplay::updateTooltipContents(bool andShow, const juce::Point<int> &pos)
{
if (!cacheLastZone.has_value())
return;
SCLOG_UNIMPL_ONCE("Update Tooltip in ZoneDisplaye currently bypassed");
if (andShow)
{
juce::Timer::callAfterDelay(100, [pos, w = juce::Component::SafePointer(this)]() {
if (!w)
return;
if (w->tooltipActive)
w->editor->showTooltip(*w, pos);
});
}
else
{
editor->repositionTooltip(*this, pos);
}
tooltipActive = true;

sst::jucegui::components::ToolTip::Row velRow, keyRow;

// TODO: Format these as midi notes not note numbers
keyRow.leftAlignText = std::to_string(cacheLastZone->kr.keyStart);
keyRow.rightAlignText = std::to_string(cacheLastZone->kr.keyEnd);
keyRow.centerAlignText = "key";

velRow.leftAlignText = std::to_string(cacheLastZone->vr.velStart);
velRow.rightAlignText = std::to_string(cacheLastZone->vr.velEnd);
velRow.centerAlignText = "vel";

editor->setTooltipContents(cacheLastZone->name, {keyRow, velRow});
}

} // namespace scxt::ui::app::edit_screen
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct ZoneLayoutDisplay : juce::Component, HasEditor
FROM_START,
FROM_END
} dragFrom[2]; // key and velocity
bool tooltipActive{false};

std::vector<juce::Rectangle<float>> velocityHotZones, keyboardHotZones, bothHotZones,
lastSelectedZone;
Expand All @@ -163,6 +164,7 @@ struct ZoneLayoutDisplay : juce::Component, HasEditor
resetLeadZoneBounds();
repaint();
}
void updateTooltipContents(bool andShow, const juce::Point<int> &pos);
};

} // namespace scxt::ui::app::edit_screen
Expand Down
18 changes: 18 additions & 0 deletions src-ui/app/editor-impl/SCXTEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ void SCXTEditor::showTooltip(const juce::Component &relativeTo)
toolTip->getHeight());
}

void SCXTEditor::showTooltip(const juce::Component &relativeTo, const juce::Point<int> &p)
{
auto fb = getLocalArea(&relativeTo, relativeTo.getLocalBounds());
toolTip->resetSizeFromData();
toolTip->setVisible(true);
toolTip->toFront(false);
toolTip->setBounds(fb.getX() + p.getX(), fb.getY() + p.getY(), toolTip->getWidth(),
toolTip->getHeight());
}

void SCXTEditor::repositionTooltip(const juce::Component &relativeTo, const juce::Point<int> &p)
{
auto fb = getLocalArea(&relativeTo, relativeTo.getLocalBounds());
toolTip->resetSizeFromData();
toolTip->setBounds(fb.getX() + p.getX(), fb.getY() + p.getY(), toolTip->getWidth(),
toolTip->getHeight());
}

void SCXTEditor::hideTooltip() { toolTip->setVisible(false); }

void SCXTEditor::setTooltipContents(const std::string &title, const std::vector<std::string> &data)
Expand Down

0 comments on commit 82a69f8

Please sign in to comment.