From dd3ec1de7d192fbd7385aa6e8939feeecb928330 Mon Sep 17 00:00:00 2001 From: Anjal Doshi Date: Wed, 7 Feb 2024 15:28:57 -0800 Subject: [PATCH] Make graph node corners rounded --- Source/UI/GraphViewer.cpp | 26 +++++++++++++++++++++----- Source/UI/GraphViewer.h | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Source/UI/GraphViewer.cpp b/Source/UI/GraphViewer.cpp index dcc300232..475a7ba38 100644 --- a/Source/UI/GraphViewer.cpp +++ b/Source/UI/GraphViewer.cpp @@ -79,7 +79,7 @@ GraphViewer::GraphViewer() void GraphViewer::updateBoundaries() { int maxHeight = 0; - int maxWidth = graphViewport->getWidth() - 30; + int maxWidth = 0; for (auto node : availableNodes) { @@ -90,7 +90,7 @@ void GraphViewer::updateBoundaries() maxWidth = node->getRight(); } - setBounds(0, 0, maxWidth + 10, maxHeight + 10); + setBounds(0, 0, maxWidth + 20, maxHeight + 20); } @@ -1167,7 +1167,7 @@ void GraphNode::paint (Graphics& g) if(processor->isEmpty()) { g.setColour(Colour(150, 150, 150)); - g.drawRect(0, 0, getWidth(), 20, 2); + g.drawRoundedRectangle(1, 1, getWidth() - 2, 18, 5.0f, 2.0f); g.drawFittedText("No Source", 10, 0, getWidth() - 10, 20, Justification::centredLeft, 1); @@ -1191,9 +1191,25 @@ void GraphNode::paint (Graphics& g) void GraphNode::paintOverChildren(Graphics& g) { - g.setColour(Colours::yellow); + if (processor->isEmpty()) + return; + if (isMouseOver) { - g.drawRect(0, 0, getWidth(), getHeight(), 2); + g.setColour(Colours::yellow); + g.drawRoundedRectangle(1, 1, getWidth() - 2, getHeight() - 2, 5.0f, 2.0f); + } + else + { + Path fakeRoundedCorners; + juce::Rectangle bounds = {0, 0, (float)getWidth(), (float)getHeight()}; + + const float cornerSize = 5.0f; //desired corner size + fakeRoundedCorners.addRectangle(bounds); //What you start with + fakeRoundedCorners.setUsingNonZeroWinding(false); //The secret sauce + fakeRoundedCorners.addRoundedRectangle(bounds.reduced(1.0f), cornerSize); //subtract this shape + + g.setColour(findColour(ThemeColors::graphViewerBackgroundColorId)); + g.fillPath(fakeRoundedCorners); } } diff --git a/Source/UI/GraphViewer.h b/Source/UI/GraphViewer.h index d48a3c0d0..d82f90abd 100644 --- a/Source/UI/GraphViewer.h +++ b/Source/UI/GraphViewer.h @@ -285,7 +285,7 @@ class GraphNode : public Component, std::unique_ptr processorParamComponent; std::unique_ptr processorParamHeader; - DropShadower nodeDropShadower { DropShadow(Colours::black.withAlpha(0.8f), 10, {2,10}) }; + DropShadower nodeDropShadower { DropShadow(Colours::black.withAlpha(0.85f), 10, {2,10}) }; bool isMouseOver; int horzShift;