Skip to content

Commit

Permalink
Applied formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Jan 8, 2025
1 parent bd9d6e5 commit 2ac66f7
Show file tree
Hide file tree
Showing 28 changed files with 307 additions and 320 deletions.
16 changes: 9 additions & 7 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 @@ -2540,9 +2541,9 @@ void Canvas::valueChanged(Value& v)
auto y1 = static_cast<float>(cnv->gl_screeny1);
auto x2 = static_cast<float>(getValue<int>(patchWidth) + x1);
auto y2 = static_cast<float>(cnv->gl_screeny2);

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

char buf[MAXPDSTRING];
snprintf(buf, MAXPDSTRING-1, ".x%lx", (unsigned long)cnv.get());
snprintf(buf, MAXPDSTRING - 1, ".x%lx", (unsigned long)cnv.get());
pd->sendMessage(buf, "setbounds", { x1, y1, x2, y2 });
}
repaint();
Expand Down Expand Up @@ -2806,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
106 changes: 51 additions & 55 deletions Source/CanvasViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,48 @@ using namespace gl;

#include "Utility/SettingsFile.h"

class Minimap : public Component, public Timer, public AsyncUpdater
{
class Minimap : public Component
, public Timer
, public AsyncUpdater {
public:
Minimap(Canvas* canvas) : cnv(canvas)
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))
{
for (auto* obj : cnv->objects) {
if (obj->getBounds().intersects(area)) {
renderMinimap = false;
break;
}
}

if(renderMinimap && minimapAlpha != 1.0f)
{

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

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

visibleArea = area;
triggerAsyncUpdate();
}

auto getMapBounds()
{
struct
Expand All @@ -73,96 +72,92 @@ class Minimap : public Component, public Timer, public AsyncUpdater
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)
{
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;

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)
{
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);
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)
{

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)))
{
if (approximatelyEqual(minimapAlpha, minimapTargetAlpha, Tolerance<float> {}.withAbsolute(0.01f))) {
minimapAlpha = minimapTargetAlpha;
stopTimer();
}
cnv->editor->nvgSurface.invalidateAll();
}

private:
Canvas* cnv;
float minimapAlpha = 0.0f;
Expand Down Expand Up @@ -462,7 +457,7 @@ class CanvasViewport final : public Viewport
addChildComponent(minimap);
addAndMakeVisible(vbar);
addAndMakeVisible(hbar);

setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this));

lookAndFeelChanged();
Expand All @@ -475,7 +470,7 @@ 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 @@ -681,7 +676,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 @@ -721,12 +716,13 @@ class CanvasViewport final : public Viewport
std::function<void()> onScroll = [] { };

private:
enum Timers { ResizeTimer, AnimationTimer };
enum Timers { ResizeTimer,
AnimationTimer };
Point<int> startPos;
Point<int> targetPos;
float lerpAnimation;
float animationSpeed;

Minimap minimap;
Time lastScrollTime;
Time lastZoomTime;
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
18 changes: 11 additions & 7 deletions Source/Components/CanvasBorderResizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ class BorderResizer final : public Component

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

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 (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 @@ -56,15 +58,17 @@ class BorderResizer final : public Component

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

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;
if (getValue<bool>(cnv->locked))
return;
NVGScopedState state(nvg);
nvgSave(nvg);
nvgTranslate(nvg, getX(), getY());
Expand Down
5 changes: 3 additions & 2 deletions Source/Components/ConnectionMessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class ConnectionMessageDisplay final
messageItemsWithFormat.clear();

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

if (!connection)
return;

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

Expand Down
Loading

0 comments on commit 2ac66f7

Please sign in to comment.