juce::Graphics::draw* Examples

juce::Graphics::draw*

drawSingleLineText()

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawSingleLineText ("Suzuki Kengo", 300, 200,
                          juce::Justification::right);
}

drawSingleLineText.png

drawMultiLineText()

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawMultiLineText ("Suzuki Kengo", 350, 100, 50,
                         juce::Justification::left,
                         50.0f);
}

drawMultiLineText.png

drawText()

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawText ("Suzuki Kengo",
                getLocalBounds().withSizeKeepingCentre (50, 50),
                juce::Justification::left,
                true);
}

drawText1.png

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawText ("Suzuki Kengo",
                getLocalBounds().withSizeKeepingCentre (50, 100),
                juce::Justification::left,
                false);
}

drawText2.png

drawFittedText()

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawFittedText ("Suzuki Kengo",
                      getLocalBounds().withSizeKeepingCentre (150, 50),
                      juce::Justification::centred,
                      1);
}

drawFittedText1.png

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

    g.setColour (blue);
    g.setFont (25.0f);
    g.drawFittedText ("Suzuki Kengo",
                      getLocalBounds().withSizeKeepingCentre (80, 50),
                      juce::Justification::centred,
                      2);
}

drawFittedText2.png

drawRect()

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

    g.setColour (blue);
    g.drawRect (getLocalBounds().withSizeKeepingCentre (300.0f, 100.0f));
}

drawRect.png

drawRoundedRectangle()

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

    g.setColour (blue);
    g.drawRoundedRectangle (getLocalBounds().toFloat().withSizeKeepingCentre (300.0f, 100.0f),
                            50.0f, 2.0f);
}

drawRoundedRectangle.png

drawEllipse()

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

    g.setColour (blue);
    g.drawEllipse (getLocalBounds().toFloat().withSizeKeepingCentre (200.0f, 200.0f),
                   1.5f);
}

drawEllipse.png

drawLine()

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

    g.setColour (blue);
    g.drawLine (juce::Line<float> (50.0f, 150.0f, 450.0f, 250.0f), 2.0f);
}

drawLine.png

drawDashedLine()

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

    const float dashLength[] = { 5.0f, 7.0f, 5.0f, 15.0f };
    g.setColour (blue);
    g.drawDashedLine (juce::Line<float> (50.0f, 100.0f, 550.0f, 200.0f),
                      dashLength, 4, 5.0f, 2);
}

drawDashedLine1.png

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

    const float dashLength[] = { 5.0f, 20.0f, 5.0f, 50.0f };
    g.setColour (blue);
    g.drawDashedLine (juce::Line<float> (50.0f, 250.0f, 550.0f, 100.0f),
                      dashLength, 4, 5.0f, 0);
}

drawDashedLine2.png

drawVerticalLine()

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

    g.setColour (blue);
    g.drawVerticalLine (300, 0.0f, 250.0f);
}

drawVerticalLine.png

drawHorizontalLine()

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

    g.setColour (blue);
    g.drawHorizontalLine (200, 0.0f, 450.0f);
}

drawHorizontalLine.png

drawArrow()

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

    g.setColour (blue);
    g.drawArrow (juce::Line<float> (100.0f, 100.0f, 500.0f, 250.0f),
                 2.5f, 50.0f, 50.0f);
}

drawArrow.png

drawImageAt()

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 testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (blue);
    testGraphics.fillRect (testImage.getBounds());

    g.drawImageAt (testImage, 50, 100);
}

drawImageAt.png

drawImage()

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 testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (blue);
    testGraphics.fillRect (testImage.getBounds());

    g.drawImage (testImage, getLocalBounds().toFloat(),
                 juce::RectanglePlacement::doNotResize);
}

drawImage.png

drawImageTransformed()

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 testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (blue);
    testGraphics.fillRect (testImage.getBounds());

    g.drawImageTransformed (testImage, juce::AffineTransform::translation (300, 100));
}

drawImageTransformed.png

drawImageWithin()

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 testImage = juce::Image (juce::Image::PixelFormat::ARGB,
                                  200, 200, true);
    juce::Graphics testGraphics (testImage);
    testGraphics.setColour (blue);
    testGraphics.fillRect (testImage.getBounds());

    g.drawImageWithin (testImage, 300, 50, 50, 50, juce::RectanglePlacement::stretchToFit);
}

drawImageWithin.png

Home