From 49ed0f022dd394587abd321a435714647d5cfdd4 Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Wed, 7 Aug 2024 14:30:10 +0100 Subject: [PATCH] DemoRunner: Add a test for shapes drawn directly in a graphics context Also expanded the lines test to include a line with a given thickness --- examples/GUI/GraphicsDemo.h | 49 +++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/examples/GUI/GraphicsDemo.h b/examples/GUI/GraphicsDemo.h index 3aed2eaca9..8ca9a15339 100644 --- a/examples/GUI/GraphicsDemo.h +++ b/examples/GUI/GraphicsDemo.h @@ -573,10 +573,54 @@ public: g.drawLine (positions[4].getValue() * w, positions[5].getValue() * h, positions[6].getValue() * w, - positions[7].getValue() * h); + positions[7].getValue() * h, + 10.0f * thickness.getValue()); } - SlowerBouncingNumber offset, positions[8]; + SlowerBouncingNumber offset, positions[8], thickness; +}; + +//============================================================================== +class ShapesDemo final : public GraphicsDemoBase +{ +public: + explicit ShapesDemo (ControllersComponent& cc) + : GraphicsDemoBase (cc, "Shapes") + {} + + void drawDemo (Graphics& g) override + { + auto bounds = getLocalBounds().toFloat(); + const auto rowHeight = bounds.getHeight() / 2.0f; + const auto spacing = 5.0f; + + const auto drawShapes = [&] (auto area) + { + const auto lineThickness = thickness.getValue() * 25.0f; + const auto cornerSize = 15.0f; + const auto shapeWidth = area.getWidth() / 4.0f; + + g.drawEllipse (area.removeFromLeft (shapeWidth).reduced (spacing), lineThickness); + g.fillEllipse (area.removeFromLeft (shapeWidth).reduced (spacing)); + + g.drawRoundedRectangle (area.removeFromLeft (shapeWidth).reduced (spacing), cornerSize, lineThickness); + g.fillRoundedRectangle (area.removeFromLeft (shapeWidth).reduced (spacing), cornerSize); + }; + + g.addTransform (AffineTransform::translation (-(bounds.getWidth() / 2.0f), -(bounds.getHeight() / 2.0f)).followedBy (getTransform())); + + g.setColour (juce::Colours::red.withAlpha (getAlpha())); + drawShapes (bounds.removeFromTop (rowHeight).reduced (spacing)); + + const auto r = bounds.removeFromTop (rowHeight).reduced (spacing); + g.setGradientFill (juce::ColourGradient (juce::Colours::green, r.getTopLeft(), + juce::Colours::blue, r.getBottomRight(), + false)); + g.setOpacity (getAlpha()); + drawShapes (r); + } + + SlowerBouncingNumber thickness; }; //============================================================================== @@ -646,6 +690,7 @@ public: demos.add (new GlyphsDemo (controls)); demos.add (new SVGDemo (controls)); demos.add (new LinesDemo (controls)); + demos.add (new ShapesDemo (controls)); addAndMakeVisible (listBox); listBox.setTitle ("Test List");