JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::Graphics Class Referencefinal

A graphics context, used for drawing a component or image. More...

#include <juce_GraphicsContext.h>

Collaboration diagram for juce::Graphics:

Classes

class  ScopedSaveState
 Uses RAII to save and restore the state of a graphics context. More...
 

Public Types

enum  ResamplingQuality {
  lowResamplingQuality = 0,
  mediumResamplingQuality = 1,
  highResamplingQuality = 2
}
 Types of rendering quality that can be specified when drawing images. More...
 

Public Member Functions

 Graphics (const Image &imageToDrawOnto)
 Creates a Graphics object to draw directly onto the given image. More...
 
 Graphics (LowLevelGraphicsContext &) noexcept
 Create a graphics that draws with a given low-level renderer. More...
 
 ~Graphics ()
 Destructor. More...
 
void addTransform (const AffineTransform &transform)
 Adds a transformation which will be performed on all the graphics operations that the context subsequently performs. More...
 
void beginTransparencyLayer (float layerOpacity)
 Begins rendering to an off-screen bitmap which will later be flattened onto the current context with the given opacity. More...
 
bool clipRegionIntersects (Rectangle< int > area) const
 Checks whether a rectangle overlaps the context's clipping region. More...
 
void drawArrow (Line< float > line, float lineThickness, float arrowheadWidth, float arrowheadLength) const
 Draws a line with an arrowhead at its end. More...
 
void drawDashedLine (Line< float > line, const float *dashLengths, int numDashLengths, float lineThickness=1.0f, int dashIndexToStartFrom=0) const
 Draws a dashed line using a custom set of dash-lengths. More...
 
void drawEllipse (float x, float y, float width, float height, float lineThickness) const
 Draws an elliptical stroke using the current colour or brush. More...
 
void drawEllipse (Rectangle< float > area, float lineThickness) const
 Draws an elliptical stroke using the current colour or brush. More...
 
void drawFittedText (const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
 Tries to draw a text string inside a given space. More...
 
void drawFittedText (const String &text, Rectangle< int > area, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
 Tries to draw a text string inside a given space. More...
 
void drawHorizontalLine (int y, float left, float right) const
 Draws a horizontal line of pixels at a given y position. More...
 
void drawImage (const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
 Draws part of an image, rescaling it to fit in a given target region. More...
 
void drawImage (const Image &imageToDraw, Rectangle< float > targetArea, RectanglePlacement placementWithinTarget=RectanglePlacement::stretchToFit, bool fillAlphaChannelWithCurrentBrush=false) const
 Draws an image to fit within a designated rectangle. More...
 
void drawImageAt (const Image &imageToDraw, int topLeftX, int topLeftY, bool fillAlphaChannelWithCurrentBrush=false) const
 Draws an image. More...
 
void drawImageTransformed (const Image &imageToDraw, const AffineTransform &transform, bool fillAlphaChannelWithCurrentBrush=false) const
 Draws an image, having applied an affine transform to it. More...
 
void drawImageWithin (const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, RectanglePlacement placementWithinTarget, bool fillAlphaChannelWithCurrentBrush=false) const
 Draws an image to fit within a designated rectangle. More...
 
void drawLine (float startX, float startY, float endX, float endY) const
 Draws a line between two points. More...
 
void drawLine (float startX, float startY, float endX, float endY, float lineThickness) const
 Draws a line between two points with a given thickness. More...
 
void drawLine (Line< float > line) const
 Draws a line between two points. More...
 
void drawLine (Line< float > line, float lineThickness) const
 Draws a line between two points with a given thickness. More...
 
void drawMultiLineText (const String &text, int startX, int baselineY, int maximumLineWidth, Justification justification=Justification::left) const
 Draws text across multiple lines. More...
 
void drawRect (int x, int y, int width, int height, int lineThickness=1) const
 Draws a rectangular outline, using the current colour or brush. More...
 
void drawRect (float x, float y, float width, float height, float lineThickness=1.0f) const
 Draws a rectangular outline, using the current colour or brush. More...
 
void drawRect (Rectangle< int > rectangle, int lineThickness=1) const
 Draws a rectangular outline, using the current colour or brush. More...
 
void drawRect (Rectangle< float > rectangle, float lineThickness=1.0f) const
 Draws a rectangular outline, using the current colour or brush. More...
 
void drawRoundedRectangle (float x, float y, float width, float height, float cornerSize, float lineThickness) const
 Uses the current colour or brush to draw the outline of a rectangle with rounded corners. More...
 
void drawRoundedRectangle (Rectangle< float > rectangle, float cornerSize, float lineThickness) const
 Uses the current colour or brush to draw the outline of a rectangle with rounded corners. More...
 
void drawSingleLineText (const String &text, int startX, int baselineY, Justification justification=Justification::left) const
 Draws a one-line text string. More...
 
void drawText (const String &text, int x, int y, int width, int height, Justification justificationType, bool useEllipsesIfTooBig=true) const
 Draws a line of text within a specified rectangle. More...
 
void drawText (const String &text, Rectangle< int > area, Justification justificationType, bool useEllipsesIfTooBig=true) const
 Draws a line of text within a specified rectangle. More...
 
void drawText (const String &text, Rectangle< float > area, Justification justificationType, bool useEllipsesIfTooBig=true) const
 Draws a line of text within a specified rectangle. More...
 
void drawVerticalLine (int x, float top, float bottom) const
 Draws a vertical line of pixels at a given x position. More...
 
void endTransparencyLayer ()
 Completes a drawing operation to a temporary semi-transparent buffer. More...
 
void excludeClipRegion (Rectangle< int > rectangleToExclude)
 Excludes a rectangle to stop it being drawn into. More...
 
void fillAll () const
 Fills the context's entire clip region with the current colour or brush. More...
 
void fillAll (Colour colourToUse) const
 Fills the context's entire clip region with a given colour. More...
 
void fillCheckerBoard (Rectangle< float > area, float checkWidth, float checkHeight, Colour colour1, Colour colour2) const
 Fills a rectangle with a checkerboard pattern, alternating between two colours. More...
 
void fillEllipse (float x, float y, float width, float height) const
 Fills an ellipse with the current colour or brush. More...
 
void fillEllipse (Rectangle< float > area) const
 Fills an ellipse with the current colour or brush. More...
 
void fillPath (const Path &path) const
 Fills a path using the currently selected colour or brush. More...
 
void fillPath (const Path &path, const AffineTransform &transform) const
 Fills a path using the currently selected colour or brush, and adds a transform. More...
 
void fillRect (Rectangle< int > rectangle) const
 Fills a rectangle with the current colour or brush. More...
 
void fillRect (Rectangle< float > rectangle) const
 Fills a rectangle with the current colour or brush. More...
 
void fillRect (int x, int y, int width, int height) const
 Fills a rectangle with the current colour or brush. More...
 
void fillRect (float x, float y, float width, float height) const
 Fills a rectangle with the current colour or brush. More...
 
void fillRectList (const RectangleList< float > &rectangles) const
 Fills a set of rectangles using the current colour or brush. More...
 
void fillRectList (const RectangleList< int > &rectangles) const
 Fills a set of rectangles using the current colour or brush. More...
 
void fillRoundedRectangle (float x, float y, float width, float height, float cornerSize) const
 Uses the current colour or brush to fill a rectangle with rounded corners. More...
 
void fillRoundedRectangle (Rectangle< float > rectangle, float cornerSize) const
 Uses the current colour or brush to fill a rectangle with rounded corners. More...
 
Rectangle< intgetClipBounds () const
 Returns the position of the bounding box for the current clipping region. More...
 
Font getCurrentFont () const
 Returns the currently selected font. More...
 
LowLevelGraphicsContextgetInternalContext () const noexcept
 
bool isClipEmpty () const
 Returns true if no drawing can be done because the clip region is zero. More...
 
bool isVectorDevice () const
 Returns true if this context is drawing to a vector-based device, such as a printer. More...
 
bool reduceClipRegion (int x, int y, int width, int height)
 Intersects the current clipping region with another region. More...
 
bool reduceClipRegion (Rectangle< int > area)
 Intersects the current clipping region with another region. More...
 
bool reduceClipRegion (const RectangleList< int > &clipRegion)
 Intersects the current clipping region with a rectangle list region. More...
 
bool reduceClipRegion (const Path &path, const AffineTransform &transform=AffineTransform())
 Intersects the current clipping region with a path. More...
 
bool reduceClipRegion (const Image &image, const AffineTransform &transform)
 Intersects the current clipping region with an image's alpha-channel. More...
 
void resetToDefaultState ()
 Resets the current colour, brush, and font to default settings. More...
 
void restoreState ()
 Restores a graphics state that was previously saved with saveState(). More...
 
void saveState ()
 Saves the current graphics state on an internal stack. More...
 
void setColour (Colour newColour)
 Changes the current drawing colour. More...
 
void setFillType (const FillType &newFill)
 Changes the current fill settings. More...
 
void setFont (const Font &newFont)
 Changes the font to use for subsequent text-drawing functions. More...
 
void setFont (float newFontHeight)
 Changes the size of the currently-selected font. More...
 
void setGradientFill (const ColourGradient &gradient)
 Sets the context to use a gradient for its fill pattern. More...
 
void setGradientFill (ColourGradient &&gradient)
 Sets the context to use a gradient for its fill pattern. More...
 
void setImageResamplingQuality (const ResamplingQuality newQuality)
 Changes the quality that will be used when resampling images. More...
 
void setOpacity (float newOpacity)
 Changes the opacity to use with the current colour. More...
 
void setOrigin (Point< int > newOrigin)
 Moves the position of the context's origin. More...
 
void setOrigin (int newOriginX, int newOriginY)
 Moves the position of the context's origin. More...
 
void setTiledImageFill (const Image &imageToUse, int anchorX, int anchorY, float opacity)
 Sets the context to use a tiled image pattern for filling. More...
 
void strokePath (const Path &path, const PathStrokeType &strokeType, const AffineTransform &transform={}) const
 Draws a path's outline using the currently selected colour or brush. More...
 

Private Member Functions

void saveStateIfPending ()
 

Private Attributes

LowLevelGraphicsContextcontext
 
std::unique_ptr< LowLevelGraphicsContextcontextToDelete
 
bool saveStatePending = false
 

Detailed Description

A graphics context, used for drawing a component or image.

When a Component needs painting, a Graphics context is passed to its Component::paint() method, and this you then call methods within this object to actually draw the component's content.

A Graphics can also be created from an image, to allow drawing directly onto that image.

See also
Component::paint

{Graphics}

Member Enumeration Documentation

◆ ResamplingQuality

Types of rendering quality that can be specified when drawing images.

See also
Graphics::setImageResamplingQuality
Enumerator
lowResamplingQuality 

Just uses a nearest-neighbour algorithm for resampling.

mediumResamplingQuality 

Uses bilinear interpolation for upsampling and area-averaging for downsampling.

highResamplingQuality 

Uses bicubic interpolation for upsampling and area-averaging for downsampling.

Constructor & Destructor Documentation

◆ Graphics() [1/2]

juce::Graphics::Graphics ( const Image imageToDrawOnto)
explicit

Creates a Graphics object to draw directly onto the given image.

The graphics object that is created will be set up to draw onto the image, with the context's clipping area being the entire size of the image, and its origin being the image's origin. To draw into a subsection of an image, use the reduceClipRegion() and setOrigin() methods.

Obviously you shouldn't delete the image before this context is deleted.

◆ ~Graphics()

juce::Graphics::~Graphics ( )

Destructor.

◆ Graphics() [2/2]

juce::Graphics::Graphics ( LowLevelGraphicsContext )
noexcept

Create a graphics that draws with a given low-level renderer.

This method is intended for use only by people who know what they're doing. Note that the LowLevelGraphicsContext will NOT be deleted by this object.

Member Function Documentation

◆ addTransform()

void juce::Graphics::addTransform ( const AffineTransform transform)

Adds a transformation which will be performed on all the graphics operations that the context subsequently performs.

After calling this, all the coordinates that are passed into the context will be transformed by this matrix.

See also
setOrigin

◆ beginTransparencyLayer()

void juce::Graphics::beginTransparencyLayer ( float  layerOpacity)

Begins rendering to an off-screen bitmap which will later be flattened onto the current context with the given opacity.

The context uses an internal stack of temporary image layers to do this. When you've finished drawing to the layer, call endTransparencyLayer() to complete the operation and composite the finished layer. Every call to beginTransparencyLayer() MUST be matched by a corresponding call to endTransparencyLayer()!

This call also saves the current state, and endTransparencyLayer() restores it.

◆ clipRegionIntersects()

bool juce::Graphics::clipRegionIntersects ( Rectangle< int area) const

Checks whether a rectangle overlaps the context's clipping region.

If this returns false, no part of the given area can be drawn onto, so this method can be used to optimise a component's paint() method, by letting it avoid drawing complex objects that aren't within the region being repainted.

◆ drawArrow()

void juce::Graphics::drawArrow ( Line< float line,
float  lineThickness,
float  arrowheadWidth,
float  arrowheadLength 
) const

Draws a line with an arrowhead at its end.

Parameters
linethe line to draw
lineThicknessthe thickness of the line
arrowheadWidththe width of the arrow head (perpendicular to the line)
arrowheadLengththe length of the arrow head (along the length of the line)

◆ drawDashedLine()

void juce::Graphics::drawDashedLine ( Line< float line,
const float dashLengths,
int  numDashLengths,
float  lineThickness = 1.0f,
int  dashIndexToStartFrom = 0 
) const

Draws a dashed line using a custom set of dash-lengths.

Parameters
linethe line to draw
dashLengthsa series of lengths to specify the on/off lengths - e.g. { 4, 5, 6, 7 } will draw a line of 4 pixels, skip 5 pixels, draw 6 pixels, skip 7 pixels, and then repeat.
numDashLengthsthe number of elements in the array (this must be an even number).
lineThicknessthe thickness of the line to draw
dashIndexToStartFromthe index in the dash-length array to use for the first segment
See also
PathStrokeType::createDashedStroke

◆ drawEllipse() [1/2]

void juce::Graphics::drawEllipse ( float  x,
float  y,
float  width,
float  height,
float  lineThickness 
) const

Draws an elliptical stroke using the current colour or brush.

See also
fillEllipse, Path::addEllipse

◆ drawEllipse() [2/2]

void juce::Graphics::drawEllipse ( Rectangle< float area,
float  lineThickness 
) const

Draws an elliptical stroke using the current colour or brush.

See also
fillEllipse, Path::addEllipse

◆ drawFittedText() [1/2]

void juce::Graphics::drawFittedText ( const String text,
int  x,
int  y,
int  width,
int  height,
Justification  justificationFlags,
int  maximumNumberOfLines,
float  minimumHorizontalScale = 0.0f 
) const

Tries to draw a text string inside a given space.

This does its best to make the given text readable within the specified rectangle, so it useful for labelling things.

If the text is too big, it'll be squashed horizontally or broken over multiple lines if the maximumLinesToUse value allows this. If the text just won't fit into the space, it'll cram as much as possible in there, and put some ellipsis at the end to show that it's been truncated.

A Justification parameter lets you specify how the text is laid out within the rectangle, both horizontally and vertically.

The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you can set this value to 1.0f. Pass 0 if you want it to use a default value.

See also
GlyphArrangement::addFittedText

◆ drawFittedText() [2/2]

void juce::Graphics::drawFittedText ( const String text,
Rectangle< int area,
Justification  justificationFlags,
int  maximumNumberOfLines,
float  minimumHorizontalScale = 0.0f 
) const

Tries to draw a text string inside a given space.

This does its best to make the given text readable within the specified rectangle, so it useful for labelling things.

If the text is too big, it'll be squashed horizontally or broken over multiple lines if the maximumLinesToUse value allows this. If the text just won't fit into the space, it'll cram as much as possible in there, and put some ellipsis at the end to show that it's been truncated.

A Justification parameter lets you specify how the text is laid out within the rectangle, both horizontally and vertically.

The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you can set this value to 1.0f. Pass 0 if you want it to use a default value.

See also
GlyphArrangement::addFittedText

◆ drawHorizontalLine()

void juce::Graphics::drawHorizontalLine ( int  y,
float  left,
float  right 
) const

Draws a horizontal line of pixels at a given y position.

The y position is an integer, but the left and right ends of the line can be sub-pixel positions, and these will be anti-aliased if necessary.

The right parameter must be greater than or equal to the left parameter.

◆ drawImage() [1/2]

void juce::Graphics::drawImage ( const Image imageToDraw,
int  destX,
int  destY,
int  destWidth,
int  destHeight,
int  sourceX,
int  sourceY,
int  sourceWidth,
int  sourceHeight,
bool  fillAlphaChannelWithCurrentBrush = false 
) const

Draws part of an image, rescaling it to fit in a given target region.

The specified area of the source image is rescaled and drawn to fill the specifed destination rectangle.

Images are composited using the context's current opacity, so if you don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f) (or setColour() with an opaque colour) before drawing images.

Parameters
imageToDrawthe image to overlay
destXthe left of the destination rectangle
destYthe top of the destination rectangle
destWidththe width of the destination rectangle
destHeightthe height of the destination rectangle
sourceXthe left of the rectangle to copy from the source image
sourceYthe top of the rectangle to copy from the source image
sourceWidththe width of the rectangle to copy from the source image
sourceHeightthe height of the rectangle to copy from the source image
fillAlphaChannelWithCurrentBrushif true, then instead of drawing the source image's pixels, the source image's alpha channel is used as a mask with which to fill the destination using the current colour or brush. (If the source is has no alpha channel, then it will just fill the target with a solid rectangle)
See also
setImageResamplingQuality, drawImageAt, drawImageWithin, fillAlphaMap

◆ drawImage() [2/2]

void juce::Graphics::drawImage ( const Image imageToDraw,
Rectangle< float targetArea,
RectanglePlacement  placementWithinTarget = RectanglePlacement::stretchToFit,
bool  fillAlphaChannelWithCurrentBrush = false 
) const

Draws an image to fit within a designated rectangle.

Parameters
imageToDrawthe source image to draw
targetAreathe target rectangle to fit it into
placementWithinTargetthis specifies how the image should be positioned within the target rectangle - see the RectanglePlacement class for more details about this.
fillAlphaChannelWithCurrentBrushif true, then instead of drawing the image, just its alpha channel will be used as a mask with which to draw with the current brush or colour. This is similar to fillAlphaMap(), and see also drawImage()
See also
drawImage, drawImageTransformed, drawImageAt, RectanglePlacement

◆ drawImageAt()

void juce::Graphics::drawImageAt ( const Image imageToDraw,
int  topLeftX,
int  topLeftY,
bool  fillAlphaChannelWithCurrentBrush = false 
) const

Draws an image.

This will draw the whole of an image, positioning its top-left corner at the given coordinates, and keeping its size the same. This is the simplest image drawing method - the others give more control over the scaling and clipping of the images.

Images are composited using the context's current opacity, so if you don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f) (or setColour() with an opaque colour) before drawing images.

◆ drawImageTransformed()

void juce::Graphics::drawImageTransformed ( const Image imageToDraw,
const AffineTransform transform,
bool  fillAlphaChannelWithCurrentBrush = false 
) const

Draws an image, having applied an affine transform to it.

This lets you throw the image around in some wacky ways, rotate it, shear, scale it, etc.

Images are composited using the context's current opacity, so if you don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f) (or setColour() with an opaque colour) before drawing images.

If fillAlphaChannelWithCurrentBrush is set to true, then the image's RGB channels are ignored and it is filled with the current brush, masked by its alpha channel.

If you want to render only a subsection of an image, use Image::getClippedImage() to create the section that you need.

See also
setImageResamplingQuality, drawImage

◆ drawImageWithin()

void juce::Graphics::drawImageWithin ( const Image imageToDraw,
int  destX,
int  destY,
int  destWidth,
int  destHeight,
RectanglePlacement  placementWithinTarget,
bool  fillAlphaChannelWithCurrentBrush = false 
) const

Draws an image to fit within a designated rectangle.

If the image is too big or too small for the space, it will be rescaled to fit as nicely as it can do without affecting its aspect ratio. It will then be placed within the target rectangle according to the justification flags specified.

Parameters
imageToDrawthe source image to draw
destXtop-left of the target rectangle to fit it into
destYtop-left of the target rectangle to fit it into
destWidthsize of the target rectangle to fit the image into
destHeightsize of the target rectangle to fit the image into
placementWithinTargetthis specifies how the image should be positioned within the target rectangle - see the RectanglePlacement class for more details about this.
fillAlphaChannelWithCurrentBrushif true, then instead of drawing the image, just its alpha channel will be used as a mask with which to draw with the current brush or colour. This is similar to fillAlphaMap(), and see also drawImage()
See also
setImageResamplingQuality, drawImage, drawImageTransformed, drawImageAt, RectanglePlacement

◆ drawLine() [1/4]

void juce::Graphics::drawLine ( float  startX,
float  startY,
float  endX,
float  endY 
) const

Draws a line between two points.

The line is 1 pixel wide and drawn with the current colour or brush. TIP: If you're trying to draw horizontal or vertical lines, don't use this - it's better to use fillRect() instead unless you really need an angled line.

◆ drawLine() [2/4]

void juce::Graphics::drawLine ( float  startX,
float  startY,
float  endX,
float  endY,
float  lineThickness 
) const

Draws a line between two points with a given thickness.

TIP: If you're trying to draw horizontal or vertical lines, don't use this - it's better to use fillRect() instead unless you really need an angled line.

See also
Path::addLineSegment

◆ drawLine() [3/4]

void juce::Graphics::drawLine ( Line< float line) const

Draws a line between two points.

The line is 1 pixel wide and drawn with the current colour or brush. TIP: If you're trying to draw horizontal or vertical lines, don't use this - it's better to use fillRect() instead unless you really need an angled line.

◆ drawLine() [4/4]

void juce::Graphics::drawLine ( Line< float line,
float  lineThickness 
) const

Draws a line between two points with a given thickness.

See also
Path::addLineSegment TIP: If you're trying to draw horizontal or vertical lines, don't use this - it's better to use fillRect() instead unless you really need an angled line.

◆ drawMultiLineText()

void juce::Graphics::drawMultiLineText ( const String text,
int  startX,
int  baselineY,
int  maximumLineWidth,
Justification  justification = Justification::left 
) const

Draws text across multiple lines.

This will break the text onto a new line where there's a new-line or carriage-return character, or at a word-boundary when the text becomes wider than the size specified by the maximumLineWidth parameter.

See also
setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText

◆ drawRect() [1/4]

void juce::Graphics::drawRect ( int  x,
int  y,
int  width,
int  height,
int  lineThickness = 1 
) const

Draws a rectangular outline, using the current colour or brush.

The lines are drawn inside the given rectangle, and greater line thicknesses extend inwards.

See also
fillRect

◆ drawRect() [2/4]

void juce::Graphics::drawRect ( float  x,
float  y,
float  width,
float  height,
float  lineThickness = 1.0f 
) const

Draws a rectangular outline, using the current colour or brush.

The lines are drawn inside the given rectangle, and greater line thicknesses extend inwards.

See also
fillRect

◆ drawRect() [3/4]

void juce::Graphics::drawRect ( Rectangle< int rectangle,
int  lineThickness = 1 
) const

Draws a rectangular outline, using the current colour or brush.

The lines are drawn inside the given rectangle, and greater line thicknesses extend inwards.

See also
fillRect

◆ drawRect() [4/4]

void juce::Graphics::drawRect ( Rectangle< float rectangle,
float  lineThickness = 1.0f 
) const

Draws a rectangular outline, using the current colour or brush.

The lines are drawn inside the given rectangle, and greater line thicknesses extend inwards.

See also
fillRect

◆ drawRoundedRectangle() [1/2]

void juce::Graphics::drawRoundedRectangle ( float  x,
float  y,
float  width,
float  height,
float  cornerSize,
float  lineThickness 
) const

Uses the current colour or brush to draw the outline of a rectangle with rounded corners.

See also
fillRoundedRectangle, Path::addRoundedRectangle

◆ drawRoundedRectangle() [2/2]

void juce::Graphics::drawRoundedRectangle ( Rectangle< float rectangle,
float  cornerSize,
float  lineThickness 
) const

Uses the current colour or brush to draw the outline of a rectangle with rounded corners.

See also
fillRoundedRectangle, Path::addRoundedRectangle

◆ drawSingleLineText()

void juce::Graphics::drawSingleLineText ( const String text,
int  startX,
int  baselineY,
Justification  justification = Justification::left 
) const

Draws a one-line text string.

This will use the current colour (or brush) to fill the text. The font is the last one specified by setFont().

Parameters
textthe string to draw
startXthe position to draw the left-hand edge of the text
baselineYthe position of the text's baseline
justificationthe horizontal flags indicate which end of the text string is anchored at the specified point.
See also
drawMultiLineText, drawText, drawFittedText, GlyphArrangement::addLineOfText

◆ drawText() [1/3]

void juce::Graphics::drawText ( const String text,
int  x,
int  y,
int  width,
int  height,
Justification  justificationType,
bool  useEllipsesIfTooBig = true 
) const

Draws a line of text within a specified rectangle.

The text will be positioned within the rectangle based on the justification flags passed-in. If the string is too long to fit inside the rectangle, it will either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig flag is true).

See also
drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText

◆ drawText() [2/3]

void juce::Graphics::drawText ( const String text,
Rectangle< int area,
Justification  justificationType,
bool  useEllipsesIfTooBig = true 
) const

Draws a line of text within a specified rectangle.

The text will be positioned within the rectangle based on the justification flags passed-in. If the string is too long to fit inside the rectangle, it will either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig flag is true).

See also
drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText

◆ drawText() [3/3]

void juce::Graphics::drawText ( const String text,
Rectangle< float area,
Justification  justificationType,
bool  useEllipsesIfTooBig = true 
) const

Draws a line of text within a specified rectangle.

The text will be positioned within the rectangle based on the justification flags passed-in. If the string is too long to fit inside the rectangle, it will either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig flag is true).

See also
drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText

◆ drawVerticalLine()

void juce::Graphics::drawVerticalLine ( int  x,
float  top,
float  bottom 
) const

Draws a vertical line of pixels at a given x position.

The x position is an integer, but the top and bottom of the line can be sub-pixel positions, and these will be anti-aliased if necessary.

The bottom parameter must be greater than or equal to the top parameter.

◆ endTransparencyLayer()

void juce::Graphics::endTransparencyLayer ( )

Completes a drawing operation to a temporary semi-transparent buffer.

See beginTransparencyLayer() for more details.

◆ excludeClipRegion()

void juce::Graphics::excludeClipRegion ( Rectangle< int rectangleToExclude)

Excludes a rectangle to stop it being drawn into.

◆ fillAll() [1/2]

void juce::Graphics::fillAll ( ) const

Fills the context's entire clip region with the current colour or brush.

(See also the fillAll (Colour) method which is a quick way of filling it with a given colour).

Referenced by juce::StandalonePluginHolder::SettingsComponent::paint().

◆ fillAll() [2/2]

void juce::Graphics::fillAll ( Colour  colourToUse) const

Fills the context's entire clip region with a given colour.

This leaves the context's current colour and brush unchanged, it just uses the specified colour temporarily.

◆ fillCheckerBoard()

void juce::Graphics::fillCheckerBoard ( Rectangle< float area,
float  checkWidth,
float  checkHeight,
Colour  colour1,
Colour  colour2 
) const

Fills a rectangle with a checkerboard pattern, alternating between two colours.

◆ fillEllipse() [1/2]

void juce::Graphics::fillEllipse ( float  x,
float  y,
float  width,
float  height 
) const

Fills an ellipse with the current colour or brush.

The ellipse is drawn to fit inside the given rectangle.

See also
drawEllipse, Path::addEllipse

◆ fillEllipse() [2/2]

void juce::Graphics::fillEllipse ( Rectangle< float area) const

Fills an ellipse with the current colour or brush.

The ellipse is drawn to fit inside the given rectangle.

See also
drawEllipse, Path::addEllipse

◆ fillPath() [1/2]

void juce::Graphics::fillPath ( const Path path) const

Fills a path using the currently selected colour or brush.

◆ fillPath() [2/2]

void juce::Graphics::fillPath ( const Path path,
const AffineTransform transform 
) const

Fills a path using the currently selected colour or brush, and adds a transform.

◆ fillRect() [1/4]

void juce::Graphics::fillRect ( Rectangle< int rectangle) const

Fills a rectangle with the current colour or brush.

See also
drawRect, fillRoundedRectangle

Referenced by juce::StandaloneFilterWindow::MainContentComponent::NotificationArea::paint().

◆ fillRect() [2/4]

void juce::Graphics::fillRect ( Rectangle< float rectangle) const

Fills a rectangle with the current colour or brush.

See also
drawRect, fillRoundedRectangle

◆ fillRect() [3/4]

void juce::Graphics::fillRect ( int  x,
int  y,
int  width,
int  height 
) const

Fills a rectangle with the current colour or brush.

See also
drawRect, fillRoundedRectangle

◆ fillRect() [4/4]

void juce::Graphics::fillRect ( float  x,
float  y,
float  width,
float  height 
) const

Fills a rectangle with the current colour or brush.

See also
drawRect, fillRoundedRectangle

◆ fillRectList() [1/2]

void juce::Graphics::fillRectList ( const RectangleList< float > &  rectangles) const

Fills a set of rectangles using the current colour or brush.

If you have a lot of rectangles to draw, it may be more efficient to create a RectangleList and use this method than to call fillRect() multiple times.

◆ fillRectList() [2/2]

void juce::Graphics::fillRectList ( const RectangleList< int > &  rectangles) const

Fills a set of rectangles using the current colour or brush.

If you have a lot of rectangles to draw, it may be more efficient to create a RectangleList and use this method than to call fillRect() multiple times.

◆ fillRoundedRectangle() [1/2]

void juce::Graphics::fillRoundedRectangle ( float  x,
float  y,
float  width,
float  height,
float  cornerSize 
) const

Uses the current colour or brush to fill a rectangle with rounded corners.

See also
drawRoundedRectangle, Path::addRoundedRectangle

◆ fillRoundedRectangle() [2/2]

void juce::Graphics::fillRoundedRectangle ( Rectangle< float rectangle,
float  cornerSize 
) const

Uses the current colour or brush to fill a rectangle with rounded corners.

See also
drawRoundedRectangle, Path::addRoundedRectangle

◆ getClipBounds()

Rectangle<int> juce::Graphics::getClipBounds ( ) const

Returns the position of the bounding box for the current clipping region.

See also
getClipRegion, clipRegionIntersects

◆ getCurrentFont()

Font juce::Graphics::getCurrentFont ( ) const

Returns the currently selected font.

◆ getInternalContext()

LowLevelGraphicsContext& juce::Graphics::getInternalContext ( ) const
inlinenoexcept

◆ isClipEmpty()

bool juce::Graphics::isClipEmpty ( ) const

Returns true if no drawing can be done because the clip region is zero.

◆ isVectorDevice()

bool juce::Graphics::isVectorDevice ( ) const

Returns true if this context is drawing to a vector-based device, such as a printer.

◆ reduceClipRegion() [1/5]

bool juce::Graphics::reduceClipRegion ( int  x,
int  y,
int  width,
int  height 
)

Intersects the current clipping region with another region.

Returns
true if the resulting clipping region is non-zero in size
See also
setOrigin, clipRegionIntersects

◆ reduceClipRegion() [2/5]

bool juce::Graphics::reduceClipRegion ( Rectangle< int area)

Intersects the current clipping region with another region.

Returns
true if the resulting clipping region is non-zero in size
See also
setOrigin, clipRegionIntersects

◆ reduceClipRegion() [3/5]

bool juce::Graphics::reduceClipRegion ( const RectangleList< int > &  clipRegion)

Intersects the current clipping region with a rectangle list region.

Returns
true if the resulting clipping region is non-zero in size
See also
setOrigin, clipRegionIntersects

◆ reduceClipRegion() [4/5]

bool juce::Graphics::reduceClipRegion ( const Path path,
const AffineTransform transform = AffineTransform() 
)

Intersects the current clipping region with a path.

Returns
true if the resulting clipping region is non-zero in size
See also
reduceClipRegion

◆ reduceClipRegion() [5/5]

bool juce::Graphics::reduceClipRegion ( const Image image,
const AffineTransform transform 
)

Intersects the current clipping region with an image's alpha-channel.

The current clipping path is intersected with the area covered by this image's alpha-channel, after the image has been transformed by the specified matrix.

Parameters
imagethe image whose alpha-channel should be used. If the image doesn't have an alpha-channel, it is treated as entirely opaque.
transforma matrix to apply to the image
Returns
true if the resulting clipping region is non-zero in size
See also
reduceClipRegion

◆ resetToDefaultState()

void juce::Graphics::resetToDefaultState ( )

Resets the current colour, brush, and font to default settings.

◆ restoreState()

void juce::Graphics::restoreState ( )

Restores a graphics state that was previously saved with saveState().

See also
ScopedSaveState

◆ saveState()

void juce::Graphics::saveState ( )

Saves the current graphics state on an internal stack.

To restore the state, use restoreState().

See also
ScopedSaveState

◆ saveStateIfPending()

void juce::Graphics::saveStateIfPending ( )
private

◆ setColour()

void juce::Graphics::setColour ( Colour  newColour)

Changes the current drawing colour.

This sets the colour that will now be used for drawing operations - it also sets the opacity to that of the colour passed-in.

If a brush is being used when this method is called, the brush will be deselected, and any subsequent drawing will be done with a solid colour brush instead.

See also
setOpacity

Referenced by juce::StandaloneFilterWindow::MainContentComponent::NotificationArea::paint().

◆ setFillType()

void juce::Graphics::setFillType ( const FillType newFill)

Changes the current fill settings.

See also
setColour, setGradientFill, setTiledImageFill

◆ setFont() [1/2]

void juce::Graphics::setFont ( const Font newFont)

Changes the font to use for subsequent text-drawing functions.

See also
drawSingleLineText, drawMultiLineText, drawText, drawFittedText

◆ setFont() [2/2]

void juce::Graphics::setFont ( float  newFontHeight)

Changes the size of the currently-selected font.

This is a convenient shortcut that changes the context's current font to a different size. The typeface won't be changed.

See also
Font

◆ setGradientFill() [1/2]

void juce::Graphics::setGradientFill ( const ColourGradient gradient)

Sets the context to use a gradient for its fill pattern.

◆ setGradientFill() [2/2]

void juce::Graphics::setGradientFill ( ColourGradient &&  gradient)

Sets the context to use a gradient for its fill pattern.

◆ setImageResamplingQuality()

void juce::Graphics::setImageResamplingQuality ( const ResamplingQuality  newQuality)

Changes the quality that will be used when resampling images.

By default a Graphics object will be set to mediumRenderingQuality.

See also
Graphics::drawImage, Graphics::drawImageTransformed, Graphics::drawImageWithin

◆ setOpacity()

void juce::Graphics::setOpacity ( float  newOpacity)

Changes the opacity to use with the current colour.

If a solid colour is being used for drawing, this changes its opacity to this new value (i.e. it doesn't multiply the colour's opacity by this amount).

If a gradient is being used, this will have no effect on it.

A value of 0.0 is completely transparent, 1.0 is completely opaque.

◆ setOrigin() [1/2]

void juce::Graphics::setOrigin ( Point< int newOrigin)

Moves the position of the context's origin.

This changes the position that the context considers to be (0, 0) to the specified position.

So if you call setOrigin with (100, 100), then the position that was previously referred to as (100, 100) will subsequently be considered to be (0, 0).

See also
reduceClipRegion, addTransform

◆ setOrigin() [2/2]

void juce::Graphics::setOrigin ( int  newOriginX,
int  newOriginY 
)

Moves the position of the context's origin.

This changes the position that the context considers to be (0, 0) to the specified position.

So if you call setOrigin (100, 100), then the position that was previously referred to as (100, 100) will subsequently be considered to be (0, 0).

See also
reduceClipRegion, addTransform

◆ setTiledImageFill()

void juce::Graphics::setTiledImageFill ( const Image imageToUse,
int  anchorX,
int  anchorY,
float  opacity 
)

Sets the context to use a tiled image pattern for filling.

Make sure that you don't delete this image while it's still being used by this context!

◆ strokePath()

void juce::Graphics::strokePath ( const Path path,
const PathStrokeType strokeType,
const AffineTransform transform = {} 
) const

Draws a path's outline using the currently selected colour or brush.

Member Data Documentation

◆ context

LowLevelGraphicsContext& juce::Graphics::context
private

◆ contextToDelete

std::unique_ptr<LowLevelGraphicsContext> juce::Graphics::contextToDelete
private

◆ saveStatePending

bool juce::Graphics::saveStatePending = false
private

The documentation for this class was generated from the following file: