Skip to content

Commit

Permalink
Merge branch 'develop' into feature/heavy_owl
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Jan 8, 2025
2 parents 6c458d5 + 2ac66f7 commit 018e350
Show file tree
Hide file tree
Showing 38 changed files with 497 additions and 287 deletions.
2 changes: 1 addition & 1 deletion Libraries/nanovg
3 changes: 0 additions & 3 deletions Resources/Documentation/ELSE/scope~.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ flags:
- name: -nsamples <f>
- name: -nlines <f>
- name: -delay <f>
- name: -drawstyle <f>
- name: -dim <f f>
- name: -receive <sym>

Expand All @@ -49,8 +48,6 @@ methods:
description: sets background RGB color (values 0-255)
- type: gridcolor <f, f, f>
description: sets grid RGB color (values 0-255)
- type: drawstyle <float>
description: <1> sets alternate drawing style (default 0)
- type: trigger <float>
description: sets trigger mode: 0 (none, default), 1 (up) or 2 (down)
- type: triglevel <float>
Expand Down
21 changes: 12 additions & 9 deletions Source/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,10 @@ void Canvas::performSynchronise()
{
static bool alreadyFlushed = false;
// By flushing twice, we can make sure that any message sent before this point will be dequeued
if(!alreadyFlushed) pd->doubleFlushMessageQueue();
if (!alreadyFlushed)
pd->doubleFlushMessageQueue();
ScopedValueSetter<bool> flushGuard(alreadyFlushed, true);

// Remove deleted connections
for (int n = connections.size() - 1; n >= 0; n--) {
if (!connections[n]->getPointer()) {
Expand Down Expand Up @@ -2541,10 +2542,9 @@ void Canvas::valueChanged(Value& v)
auto x2 = static_cast<float>(getValue<int>(patchWidth) + x1);
auto y2 = static_cast<float>(cnv->gl_screeny2);

pd->sendDirectMessage(cnv.get(), "setbounds", { x1, y1, x2, y2 });
}
if (auto patchPtr = patch.getPointer()) {
patchPtr->gl_screenx2 = getValue<int>(patchWidth) + patchPtr->gl_screenx1;
char buf[MAXPDSTRING];
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
}
repaint();
} else if (v.refersToSameSourceAs(patchHeight)) {
Expand All @@ -2555,7 +2555,9 @@ void Canvas::valueChanged(Value& v)
auto x2 = static_cast<float>(cnv->gl_screenx2);
auto y2 = static_cast<float>(getValue<int>(patchHeight) + y1);

pd->sendDirectMessage(cnv.get(), "setbounds", { x1, y1, x2, y2 });
char buf[MAXPDSTRING];
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
}
repaint();
}
Expand Down Expand Up @@ -2805,8 +2807,9 @@ void Canvas::receiveMessage(t_symbol* symbol, SmallArray<pd::Atom> const& atoms)
break;
}
case hash("editmode"): {
if(::getValue<bool>(commandLocked)) return;

if (::getValue<bool>(commandLocked))
return;

if (atoms.size() >= 1) {
int const flag = atoms[0].getFloat();
if (flag % 2 == 0) {
Expand Down
158 changes: 157 additions & 1 deletion Source/CanvasViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,154 @@ using namespace gl;

#include "Utility/SettingsFile.h"

class Minimap : public Component
, public Timer
, public AsyncUpdater {
public:
Minimap(Canvas* canvas)
: cnv(canvas)
{
}

void handleAsyncUpdate() override
{
auto area = visibleArea / getValue<float>(cnv->zoomScale);
bool renderMinimap = cnv->objects.not_empty();
for (auto* obj : cnv->objects) {
if (obj->getBounds().intersects(area)) {
renderMinimap = false;
break;
}
}

if (renderMinimap && minimapAlpha != 1.0f) {
setVisible(true);
minimapTargetAlpha = 1.0f;
if (!isTimerRunning())
startTimer(11);
} else if (!renderMinimap && minimapAlpha != 0.0f) {
setVisible(false);
minimapTargetAlpha = 0.0f;
if (!isTimerRunning())
startTimer(11);
}
}

void updateMinimap(Rectangle<int> area)
{
if (isMouseDown || area.isEmpty())
return;

visibleArea = area;
triggerAsyncUpdate();
}

auto getMapBounds()
{
struct
{
Rectangle<int> fullBounds, viewBounds;
int offsetX, offsetY;
float scale;
} b;

auto const zoom = getValue<float>(cnv->zoomScale);
b.viewBounds = cnv->viewport->getViewArea() / zoom;
Rectangle<int> allObjectBounds = Rectangle<int>(cnv->canvasOrigin.x, cnv->canvasOrigin.y, b.viewBounds.getWidth(), b.viewBounds.getHeight());
for (auto* object : cnv->objects) {
allObjectBounds = allObjectBounds.getUnion(object->getBounds());
}

b.fullBounds = isMouseDown ? boundsBeforeDrag : allObjectBounds.getUnion(b.viewBounds);

b.offsetX = -std::min(0, b.fullBounds.getX() - cnv->canvasOrigin.x);
b.offsetY = -std::min(0, b.fullBounds.getY() - cnv->canvasOrigin.y);
b.scale = std::min<float>(width / (b.fullBounds.getWidth() + b.offsetX), height / (b.fullBounds.getHeight() + b.offsetY));
boundsBeforeDrag = b.fullBounds;

return b;
}

void render(NVGcontext* nvg)
{
if (approximatelyEqual(minimapAlpha, 0.0f))
return;

nvgGlobalAlpha(nvg, minimapAlpha);

auto map = getMapBounds();

float const x = cnv->viewport->getViewWidth() - (width + 10);
float const y = cnv->viewport->getViewHeight() - (height + 10);

auto canvasBackground = cnv->findColour(PlugDataColour::canvasBackgroundColourId);
auto mapBackground = canvasBackground.contrasting(0.5f);

// draw background
nvgFillColor(nvg, NVGComponent::convertColour(mapBackground.withAlpha(0.4f)));
nvgFillRoundedRect(nvg, x - 4, y - 4, width + 8, height + 8, Corners::largeCornerRadius);

nvgFillColor(nvg, NVGComponent::convertColour(mapBackground.withAlpha(0.8f)));

// draw objects
for (auto* object : cnv->objects) {
auto b = (object->getBounds().reduced(Object::margin).translated(map.offsetX, map.offsetY) - cnv->canvasOrigin).toFloat() * map.scale;
nvgFillRoundedRect(nvg, x + b.getX(), y + b.getY(), b.getWidth(), b.getHeight(), Corners::objectCornerRadius * map.scale);
}

// draw visible area
nvgDrawRoundedRect(nvg, x + (map.offsetX + map.viewBounds.getX() - cnv->canvasOrigin.x) * map.scale, y + (map.offsetY + map.viewBounds.getY() - cnv->canvasOrigin.y) * map.scale, map.viewBounds.getWidth() * map.scale, map.viewBounds.getHeight() * map.scale, NVGComponent::convertColour(canvasBackground.withAlpha(0.6f)), NVGComponent::convertColour(canvasBackground.contrasting(0.4f)), 0.0f);
nvgGlobalAlpha(nvg, 1.0f);
}

void mouseDown(MouseEvent const& e) override
{
downPosition = cnv->viewport->getViewPosition();

auto map = getMapBounds();
auto realViewBounds = Rectangle<int>((map.offsetX + map.viewBounds.getX() - cnv->canvasOrigin.x) * map.scale, (map.offsetY + map.viewBounds.getY() - cnv->canvasOrigin.y) * map.scale, map.viewBounds.getWidth() * map.scale, map.viewBounds.getHeight() * map.scale);
isMouseDown = realViewBounds.contains(e.getMouseDownPosition());
}

void mouseUp(MouseEvent const& e) override
{
auto viewBounds = cnv->viewport->getViewArea();
downPosition = viewBounds.getPosition();
isMouseDown = false;
updateMinimap(viewBounds);
}

void mouseDrag(MouseEvent const& e) override
{
auto map = getMapBounds();

if (isMouseDown) {
cnv->viewport->setViewPosition(downPosition + (e.getOffsetFromDragStart() / map.scale));
}
}

void timerCallback() override
{
minimapAlpha = jmap<float>(0.2f, minimapAlpha, minimapTargetAlpha);
if (approximatelyEqual(minimapAlpha, minimapTargetAlpha, Tolerance<float> {}.withAbsolute(0.01f))) {
minimapAlpha = minimapTargetAlpha;
stopTimer();
}
cnv->editor->nvgSurface.invalidateAll();
}

private:
Canvas* cnv;
float minimapAlpha = 0.0f;
float minimapTargetAlpha = 0.0f;
Rectangle<int> visibleArea;
Point<int> downPosition;
Rectangle<int> boundsBeforeDrag;
bool isMouseDown = false;
static constexpr float width = 180;
static constexpr float height = 130;
};

// Special viewport that shows scrollbars on top of content instead of next to it
class CanvasViewport final : public Viewport
, public NVGComponent
Expand Down Expand Up @@ -292,6 +440,7 @@ class CanvasViewport final : public Viewport
public:
CanvasViewport(PluginEditor* parent, Canvas* cnv)
: NVGComponent(this)
, minimap(cnv)
, editor(parent)
, cnv(cnv)
{
Expand All @@ -305,6 +454,7 @@ class CanvasViewport final : public Viewport

setScrollBarThickness(8);

addChildComponent(minimap);
addAndMakeVisible(vbar);
addAndMakeVisible(hbar);

Expand All @@ -319,6 +469,8 @@ class CanvasViewport final : public Viewport

void render(NVGcontext* nvg, Rectangle<int> const area)
{
minimap.render(nvg);

if (area.intersects(vbar.getBounds())) {
NVGScopedState scopedState(nvg);
nvgTranslate(nvg, vbar.getX(), vbar.getY());
Expand Down Expand Up @@ -361,7 +513,8 @@ class CanvasViewport final : public Viewport
}

lerpAnimation += animationSpeed;
} break;
break;
}
}
}

Expand Down Expand Up @@ -513,6 +666,7 @@ class CanvasViewport final : public Viewport

onScroll();
adjustScrollbarBounds();
minimap.updateMinimap(r);
editor->nvgSurface.invalidateAll();
cnv->getParentComponent()->setSize(getWidth(), getHeight());
}
Expand All @@ -521,6 +675,7 @@ class CanvasViewport final : public Viewport
{
vbar.setVisible(isVerticalScrollBarShown());
hbar.setVisible(isHorizontalScrollBarShown());
minimap.setBounds(Rectangle<int>(getWidth() - 200, getHeight() - 150, 190, 140));

if (editor->isInPluginMode())
return;
Expand Down Expand Up @@ -568,6 +723,7 @@ class CanvasViewport final : public Viewport
float lerpAnimation;
float animationSpeed;

Minimap minimap;
Time lastScrollTime;
Time lastZoomTime;
float lastScaleFactor = -1.0f;
Expand Down
4 changes: 2 additions & 2 deletions Source/Components/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class MainToolbarButton final : public TextButton {
}
}
}
void mouseEnter(const MouseEvent& e) override

void mouseEnter(MouseEvent const& e) override
{
if (auto const* topLevel = getTopLevelComponent()) {
if (auto const* peer = topLevel->getPeer()) {
Expand Down
11 changes: 11 additions & 0 deletions Source/Components/CanvasBorderResizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ class BorderResizer final : public Component

void mouseDown(MouseEvent const& e) override
{
if (getValue<bool>(cnv->locked))
return;

if (cnv->showBorder) {
dragger.startDraggingComponent(this, e);
}
}

void mouseDrag(MouseEvent const& e) override
{
if (getValue<bool>(cnv->locked))
return;

if (cnv->showBorder) {
auto const constrainedPoint = getLocalPoint(cnv, Rectangle<int>(cnv->canvasOrigin.x + 11, cnv->canvasOrigin.y + 11, cnv->canvasOrigin.x, cnv->canvasOrigin.y).getConstrainedPoint(e.getEventRelativeTo(cnv).getPosition()));
dragger.dragComponent(this, e.withNewPosition(constrainedPoint), nullptr);
Expand All @@ -52,12 +58,17 @@ class BorderResizer final : public Component

void mouseUp(MouseEvent const& e) override
{
if (getValue<bool>(cnv->locked))
return;

cnv->patchHeight.addListener(this);
cnv->patchWidth.addListener(this);
}

void render(NVGcontext* nvg) override
{
if (getValue<bool>(cnv->locked))
return;
NVGScopedState state(nvg);
nvgSave(nvg);
nvgTranslate(nvg, getX(), getY());
Expand Down
8 changes: 6 additions & 2 deletions Source/Components/ConnectionMessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ class ConnectionMessageDisplay final
{
messageItemsWithFormat.clear();

auto* connection = activeConnection.load();
if (!connection)
return;

auto haveMessage = true;
auto textString = activeConnection.load()->getMessageFormated();
auto textString = connection->getMessageFormated();

if (textString[0].isEmpty()) {
haveMessage = false;
Expand Down Expand Up @@ -315,7 +319,7 @@ class ConnectionMessageDisplay final
auto roundedIndex = static_cast<int>(index);
auto currentSample = lastSamples[ch][roundedIndex];
auto nextSample = roundedIndex == 1023 ? lastSamples[ch][roundedIndex] : lastSamples[ch][roundedIndex + 1];
auto interpolatedSample = jmap<float>(index - roundedIndex, currentSample, nextSample);
auto interpolatedSample = jmap<float>(index - roundedIndex, currentSample, nextSample) * -1.0f;

auto y = jmap<float>(interpolatedSample, valleyAmplitude, peakAmplitude, channelBounds.getY(), channelBounds.getBottom());
auto newPoint = Point<float>(x, y);
Expand Down
Loading

0 comments on commit 018e350

Please sign in to comment.