juce::Graphics::draw* Examples

drawSingleLineText()

drawSingleLineText()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawSingleLineText ("Suzuki Kengo", 300, 200,
                          juce::Justification::right);
}

drawMultiLineText()

drawMultiLineText()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawMultiLineText ("Suzuki Kengo", 350, 100, 50,
                         juce::Justification::left,
                         50.0f);
}

drawText()

drawText()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawText ("Suzuki Kengo",
                getLocalBounds().withSizeKeepingCentre (50, 50),
                juce::Justification::left,
                true);
}
void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawText ("Suzuki Kengo",
                getLocalBounds().withSizeKeepingCentre (50, 100),
                juce::Justification::left,
                false);
}

drawFittedText()

drawFittedText()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawFittedText ("Suzuki Kengo",
                      getLocalBounds().withSizeKeepingCentre (150, 50),
                      juce::Justification::centred,
                      1);
}
void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.setFont (25.0f);
    g.drawFittedText ("Suzuki Kengo",
                      getLocalBounds().withSizeKeepingCentre (80, 50),
                      juce::Justification::centred,
                      2);
}

drawRect()

drawRect()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawRect (getLocalBounds().withSizeKeepingCentre (300.0f, 100.0f));
}

drawRoundedRectangle()

drawRoundedRectangle()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawRoundedRectangle (getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 100.0f),
                            50.0f, 2.0f);
}

drawEllipse()

drawEllipse()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawEllipse (getLocalBounds().toFloat().withSizeKeepingCentre (200.0f, 200.0f),
                   1.5f);
}

drawLine()

drawLine()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawLine (juce::Line<float> (50.0f, 150.0f, 450.0f, 250.0f), 2.0f);
}

drawDashedLine()

drawDashedLine()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    const float dashLength[] = { 5.0f, 7.0f, 5.0f, 15.0f };
    g.setColour (green);
    g.drawDashedLine (juce::Line<float> (50.0f, 100.0f, 550.0f, 200.0f),
                      dashLength, 4, 5.0f, 2);
}
void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    const float dashLength[] = { 5.0f, 20.0f, 5.0f, 50.0f };
    g.setColour (green);
    g.drawDashedLine (juce::Line<float> (50.0f, 250.0f, 550.0f, 100.0f),
                      dashLength, 4, 5.0f, 0);
}

drawVerticalLine()

drawVerticalLine()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawVerticalLine (300, 0.0f, 250.0f);
}

drawHorizontalLine()

drawHorizontalLine()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawHorizontalLine (200, 0.0f, 450.0f);
}

drawArrow()

drawArrow()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    g.setColour (green);
    g.drawArrow (juce::Line<float> (100.0f, 100.0f, 500.0f, 250.0f),
                 2.5f, 50.0f, 50.0f);
}

drawImageAt()

drawImageAt()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    auto testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (green);
    testGraphics.fillRect (testImage.getBounds());
    
    g.drawImageAt (testImage, 50, 100);
}

drawImage()

drawImage()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    auto testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (green);
    testGraphics.fillRect (testImage.getBounds());
    
    g.drawImage (testImage, getLocalBounds().toFloat(),
                 juce::RectanglePlacement::doNotResize);
}

drawImageTransformed()

drawImageTransformed()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    auto testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (green);
    testGraphics.fillRect (testImage.getBounds());
    
    g.drawImageTransformed (testImage, juce::AffineTransform::translation (300, 100));
}

drawImageWithin()

drawImageWithin()

void MainComponent::paint (juce::Graphics& g)
{
    auto black = juce::Colour::fromFloatRGBA (0.08f, 0.08f, 0.08f, 1.0f);
    auto green = juce::Colour::fromFloatRGBA (0.34f, 0.74f, 0.66f, 1.0f);
    
    g.fillAll (black);
    
    auto testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (green);
    testGraphics.fillRect (testImage.getBounds());
    
    g.drawImageWithin (testImage, 300, 50, 50, 50, juce::RectanglePlacement::stretchToFit);
}
References

Comments

Copied title and URL