#include "ui/FlMods.h" #include "ui/EditorTools.h" #include "core/NoteEdit.h" #include "ui/HintBar.h" #include "ui/I18n.h" #include "ui/Theme.h" namespace lynx { // --- edit tools ------------------------------------------------------------------------ const std::vector& editTools() { static const std::vector list { { EditTool::pencil, Icon::draw, TR_NOOP ("Pencil"), TR_NOOP ("Click adds, drag moves, drag an edge resizes"), 'P' }, { EditTool::brush, Icon::brush, TR_NOOP ("Brush"), TR_NOOP ("Drag to paint a run of notes or clips"), 'B' }, { EditTool::drumPaint, Icon::drumBrush, TR_NOOP ("Drum brush"), TR_NOOP ("Drag to paint one short hit per grid cell, on whatever key is under the mouse"), 'N' }, { EditTool::eraser, Icon::erase, TR_NOOP ("Eraser"), TR_NOOP ("Click or drag to delete"), 'D' }, { EditTool::mute, Icon::mute, TR_NOOP ("Mute"), TR_NOOP ("Click or drag to mute or unmute"), 'T' }, { EditTool::knife, Icon::knife, TR_NOOP ("Knife"), TR_NOOP ("Drag a line to cut; a click cuts at the cursor"), 'C' }, { EditTool::lasso, Icon::select, TR_NOOP ("Lasso"), TR_NOOP ("Click or drag to select (Shift adds)"), 'E' }, { EditTool::zoom, Icon::zoom, TR_NOOP ("Zoom"), TR_NOOP ("Click zooms in, drag a range to zoom to it; right-click zooms out"), 'Z' }, { EditTool::listen, Icon::listen, TR_NOOP ("Listen"), TR_NOOP ("Click or drag to hear what is under the cursor"), 'Y' }, { EditTool::slip, Icon::slip, TR_NOOP ("Slip"), TR_NOOP ("Drag inside a clip to move its content under it"), 'S' }, }; return list; } const char* editToolId (EditTool tool) { switch (tool) { case EditTool::pencil: return "pencil"; case EditTool::brush: return "brush"; case EditTool::drumPaint: return "drumPaint"; case EditTool::eraser: return "eraser"; case EditTool::mute: return "mute"; case EditTool::knife: return "knife"; case EditTool::lasso: return "lasso"; case EditTool::zoom: return "zoom"; case EditTool::listen: return "listen"; case EditTool::slip: return "slip"; } return "pencil"; } const EditToolInfo& editToolInfo (EditTool tool) { for (const auto& t : editTools()) if (t.tool == tool) return t; return editTools().front(); } namespace { void setKeyTip (IconButton& button, const EditToolInfo& info, const juce::String& key) { button.setTooltip (tr (info.name) + (key.isNotEmpty() ? " (" + key + ")" : juce::String()) + "\n" + tr (info.description) + "\n" + tr ("Every tool: right-click deletes, Alt ignores the grid, Ctrl+drag selects")); ui::setQuickTip (button, tr (info.name), key); } } // namespace void ToolStrip::refreshKeys (const std::function& keyOf) { for (std::size_t i = 0; i < tools.size() && i < buttons.size(); ++i) setKeyTip (*buttons[i], editToolInfo (tools[i]), keyOf (tools[i])); } ToolStrip::ToolStrip (bool includeSlip) { for (const auto& info : editTools()) { // the Playlist has Slip, the Piano Roll the drum brush if ((info.tool == EditTool::slip && ! includeSlip) || (info.tool == EditTool::drumPaint && includeSlip)) continue; auto button = std::make_unique (info.name, info.icon); button->setRadioGroupId (0x7001); button->setClickingTogglesState (true); button->setFlat (true); button->setWantsKeyboardFocus (false); button->setMouseClickGrabsKeyboardFocus (false); button->setOnColour (theme::colour::accent.withAlpha (0.16f)); // the light header style: a faint accent wash button->setIconColourWhenOn (theme::colour::accentHover); setKeyTip (*button, info, juce::String::charToString ((juce::juce_wchar) info.key)); button->setToggleState (info.tool == tool, juce::dontSendNotification); button->onClick = [this, t = info.tool] { if (tool != t) { tool = t; if (onChange) onChange (t); } }; addAndMakeVisible (*button); buttons.push_back (std::move (button)); tools.push_back (info.tool); } } void ToolStrip::setTool (EditTool newTool) { for (std::size_t i = 0; i < tools.size(); ++i) if (tools[i] == newTool) { tool = newTool; buttons[i]->setToggleState (true, juce::dontSendNotification); for (std::size_t j = 0; j < buttons.size(); ++j) if (j != i) buttons[j]->setToggleState (false, juce::dontSendNotification); if (onChange) onChange (tool); return; } } int ToolStrip::getIdealWidth (int height) const { return (int) buttons.size() * toolbarlayout::toolButtonWidth (iconSize, height); } void ToolStrip::resized() { const auto size = getHeight(); const auto width = toolbarlayout::toolButtonWidth (iconSize, size); const auto icon = toolbarlayout::toolIconPx (iconSize); for (std::size_t i = 0; i < buttons.size(); ++i) { buttons[i]->setIconSizing (1.0f, icon); buttons[i]->setBounds ((int) i * width, 0, width, size); } } void ToolStrip::mouseWheelMove (const juce::MouseEvent&, const juce::MouseWheelDetails& wheel) { if (wheel.deltaY == 0.0f || tools.empty()) return; const auto at = (int) (std::find (tools.begin(), tools.end(), tool) - tools.begin()); const auto next = juce::jlimit (0, (int) tools.size() - 1, at + (wheel.deltaY < 0.0f ? 1 : -1)); setTool (tools[(std::size_t) next]); } // --- cursors --------------------------------------------------------------------------- namespace { // A tool icon as a cursor: drawn at 2x, light strokes with a dark outline so it reads on the dark grid // and on bright notes alike. `hot` is the hotspot on the icon's 24-unit grid. juce::MouseCursor iconCursor (Icon icon, juce::Point hot) { constexpr int size = 24, scale = 2; juce::Image image (juce::Image::ARGB, size * scale, size * scale, true); { juce::Graphics g (image); g.addTransform (juce::AffineTransform::scale ((float) scale)); const auto area = juce::Rectangle (0.0f, 0.0f, (float) size, (float) size); for (auto [dx, dy] : { std::pair { -1.0f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, -1.0f }, { 0.0f, 1.0f }, { -0.7f, -0.7f }, { 0.7f, 0.7f }, { -0.7f, 0.7f }, { 0.7f, -0.7f } }) icons::draw (g, icon, area.translated (dx, dy), theme::colour::bg0); icons::draw (g, icon, area, theme::colour::textPrimary); } return juce::MouseCursor (juce::ScaledImage (image, (double) scale), hot.roundToInt()); } } // namespace juce::MouseCursor editorCursor (gesture::Cursor cursor) { using C = gesture::Cursor; // icons are drawn with a margin (fitted into the 24x24 box), so the hotspots are the icon's tips static const auto pencil = iconCursor (Icon::draw, { 4.0f, 20.0f }); static const auto brush = iconCursor (Icon::brush, { 4.0f, 20.0f }); static const auto eraser = iconCursor (Icon::erase, { 6.0f, 18.0f }); static const auto mute = iconCursor (Icon::mute, { 12.0f, 12.0f }); static const auto knife = iconCursor (Icon::knife, { 4.0f, 20.0f }); static const auto zoom = iconCursor (Icon::zoom, { 10.0f, 10.0f }); static const auto listen = iconCursor (Icon::listen, { 12.0f, 12.0f }); static const auto slip = iconCursor (Icon::slip, { 12.0f, 12.0f }); switch (cursor) { case C::draw: return pencil; case C::paint: return brush; case C::erase: return eraser; case C::mute: return mute; case C::slice: return knife; case C::zoom: return zoom; case C::listen: return listen; case C::slip: return slip; case C::move: return juce::MouseCursor::UpDownLeftRightResizeCursor; case C::copy: return juce::MouseCursor::CopyingCursor; case C::resizeH: return juce::MouseCursor::LeftRightResizeCursor; case C::resizeV: return juce::MouseCursor::UpDownResizeCursor; case C::select: return juce::MouseCursor::CrosshairCursor; case C::point: return juce::MouseCursor::PointingHandCursor; case C::pan: return juce::MouseCursor::DraggingHandCursor; case C::normal: break; } return juce::MouseCursor::NormalCursor; } juce::String actionHint (gesture::Action action, bool playlist) { using A = gesture::Action; const auto common = tr ("[RMB] delete [Ctrl][LMB] select [Alt] no snap"); switch (action) { case A::create: return (playlist ? tr ("[LMB] place the Picker's clip, drag to position it") : tr ("[LMB] add a note, drag to position it")) + " " + common; case A::paint: return (playlist ? tr ("[LMB] drag paints clips end to end") : tr ("[LMB] drag paints a run of notes [Shift] one at a time")) + " " + common; case A::move: return (playlist ? tr ("Clip: [LMB] drag moves [Shift][LMB] copies [2xLMB] opens [RMB] deletes") : tr ("Note: [LMB] drag moves [Shift][LMB] copies [2xLMB] properties [RMB] deletes [Alt][Wheel] velocity")); case A::copyMove: return playlist ? tr ("[Shift][LMB] drags a copy of the clip (selection)") : tr ("[Shift][LMB] drags a copy of the note (selection)"); case A::resizeRight: return (playlist ? tr ("Clip end: [LMB] drag resizes") : tr ("Note end: [LMB] drag resizes")) + " " + tr ("[Alt] no snap"); case A::resizeLeft: return (playlist ? tr ("Clip start: [LMB] drag trims, the content stays in place") : tr ("Note start: [LMB] drag resizes, the end stays")) + " " + tr ("[Alt] no snap"); case A::slipContent: return tr ("[LMB] drag slides the clip's content inside it (the clip stays)"); case A::toggleSelect: return tr ("[Ctrl][LMB] adds to / removes from the selection"); case A::boxSelect: return tr ("[LMB] drag draws a selection box [Shift] adds"); case A::erase: return tr ("[LMB] click or drag deletes"); case A::toggleMute: return tr ("[LMB] click or drag mutes / unmutes"); case A::slice: return tr ("[LMB] drag a line to cut across, a click cuts here") + " " + tr ("[Alt] no snap"); case A::zoomRange: return tr ("[LMB] click zooms in, drag a range to zoom to it [RMB] zooms out"); case A::listen: return playlist ? tr ("[LMB] click or drag plays from here") : tr ("[LMB] click or drag plays the notes under the cursor"); case A::fade: return tr ("Fade: [LMB] drag sets its length"); case A::clipGain: return tr ("Clip gain: [LMB] drag up / down (the selected clips together) [RMB] menu"); case A::movePoint: return tr ("Point: [LMB] drag moves, then [Shift] keeps time, [Ctrl] keeps value [Alt] no snap [RMB] menu"); case A::addPoint: return tr ("Curve: [LMB] or [RMB] adds a point (hold and drag to place it)"); case A::bendSegment: return tr ("Tension: [LMB] drag up / down bends the segment ([Ctrl] fine) [RMB] straight"); case A::openMenu: return tr ("[LMB] clip menu"); case A::none: break; } return {}; } // --- grid -------------------------------------------------------------------------------- namespace grid { const std::vector