juce::Path::add* Examples

juce::Path::add*

addRectangle()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addRectangle (getLocalBounds().reduced (100));

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addRectangle.png

addRoundedRectangle()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addRoundedRectangle (getLocalBounds().reduced (100), 80.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addRoundedRectangle.png

addTriangle()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addTriangle (juce::Point<float> (400.0f, 150.0f),
                      juce::Point<float> (285.0f, 350.0f),
                      juce::Point<float> (515.0f, 350.0f));

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addTriangle.png

addQuadrilateral()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addQuadrilateral (150.0f, 100.0f,
                           200.0f, 400.0f,
                           650.0f, 400.0f,
                           650.0f, 200.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addQuadrilateral.png

addEllipse()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addEllipse (getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 300.0f));

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addEllipse.png

addArc()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    auto bounds = getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 300.0f);
    juce::Path path;
    path.addArc (bounds.getX(),
                 bounds.getY(),
                 bounds.getWidth(),
                 bounds.getHeight(),
                 juce::MathConstants<float>::halfPi,
                 juce::MathConstants<float>::twoPi,
                 true);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addArc.png

addCentredArc()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    auto bounds = getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 300.0f);
    juce::Path path;
    path.addCentredArc (bounds.getCentreX(),
                        bounds.getCentreY(),
                        bounds.getWidth() / 2.0f,
                        bounds.getHeight() / 2.0f,
                        juce::MathConstants<float>::pi / 4.0f,
                        juce::MathConstants<float>::halfPi,
                        juce::MathConstants<float>::twoPi,
                        true);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addCentredArc.png

addPieSegment()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    auto bounds = getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 300.0f);
    juce::Path path;
    path.addPieSegment (bounds,
                        juce::MathConstants<float>::halfPi,
                        juce::MathConstants<float>::twoPi,
                        0.5f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addPieSegment.png

addLineSegment()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addLineSegment (juce::Line<float> (juce::Point<float> (200.0f, 250.0f), juce::Point<float> (350.0f, 250.0f)),
                         5.0f);
    path.addLineSegment (juce::Line<float> (juce::Point<float> (450.0f, 250.0f), juce::Point<float> (600.0f, 250.0f)),
                         5.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addLineSegment.png

addArrow()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addArrow (juce::Line<float> (juce::Point<float> (200.0f, 250.0f), juce::Point<float> (600.0f, 250.0f)),
                   1.0f, 60.0f, 30.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addArrow.png

addPolygon()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addPolygon (getBounds().toFloat().getCentre(),
                     5, 150.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addPolygon.png

addStar()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path path;
    path.addStar (getBounds().toFloat().getCentre(),
                  8, 20.0f, 150.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addStar.png

addBubble()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    auto bounds = getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 100.0f);
    juce::Path path;
    path.addBubble (bounds,
                    bounds.expanded (0.0f, 50.0f),
                    juce::Point<float> (500.0f, bounds.getBottom() + 49.9f),
                    10.0f, 15.0f);

    g.setColour (blue);
    g.strokePath (path, juce::PathStrokeType (1.5f));
}

addBubble.png

addPath()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto blue  = juce::Colour::fromFloatRGBA (0.43f, 0.83f, 1.0f,  1.0f);

    g.fillAll (black);

    juce::Path pathA;
    pathA.addEllipse (getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 300.0f));

    juce::Path pathB;
    pathB.addEllipse (getLocalBounds().toFloat().withSizeKeepingCentre (150.0f, 150.0f));
    pathB.addPath (pathA);

    g.setColour (blue);
    g.strokePath (pathB, juce::PathStrokeType (1.5f));
}

addPath.png

Home