diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index 2efb3aa991..fd45ad824e 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -25,7 +25,7 @@ namespace { template - Rectangle coordsToRectangle (Type x, Type y, Type w, Type h) + Rectangle coordsToRectangle (Type x, Type y, Type w, Type h) noexcept { #if JUCE_DEBUG const int maxVal = 0x3fffffff; @@ -77,7 +77,7 @@ bool Graphics::isVectorDevice() const return context.isVectorDevice(); } -bool Graphics::reduceClipRegion (const Rectangle& area) +bool Graphics::reduceClipRegion (Rectangle area) { saveStateIfPending(); return context.clipToRectangle (area); @@ -85,7 +85,7 @@ bool Graphics::reduceClipRegion (const Rectangle& area) bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h) { - return reduceClipRegion (Rectangle (x, y, w, h)); + return reduceClipRegion (coordsToRectangle (x, y, w, h)); } bool Graphics::reduceClipRegion (const RectangleList& clipRegion) @@ -108,7 +108,7 @@ bool Graphics::reduceClipRegion (const Image& image, const AffineTransform& tran return ! context.isClipEmpty(); } -void Graphics::excludeClipRegion (const Rectangle& rectangleToExclude) +void Graphics::excludeClipRegion (Rectangle rectangleToExclude) { saveStateIfPending(); context.excludeClipRectangle (rectangleToExclude); @@ -164,7 +164,7 @@ void Graphics::addTransform (const AffineTransform& transform) context.addTransform (transform); } -bool Graphics::clipRegionIntersects (const Rectangle& area) const +bool Graphics::clipRegionIntersects (Rectangle area) const { return context.clipRegionIntersects (area); } @@ -281,7 +281,7 @@ void Graphics::drawMultiLineText (const String& text, const int startX, } } -void Graphics::drawText (const String& text, const Rectangle& area, +void Graphics::drawText (const String& text, Rectangle area, Justification justificationType, bool useEllipsesIfTooBig) const { if (text.isNotEmpty() && context.clipRegionIntersects (area.getSmallestIntegerContainer())) @@ -297,19 +297,19 @@ void Graphics::drawText (const String& text, const Rectangle& area, } } -void Graphics::drawText (const String& text, const Rectangle& area, +void Graphics::drawText (const String& text, Rectangle area, Justification justificationType, bool useEllipsesIfTooBig) const { drawText (text, area.toFloat(), justificationType, useEllipsesIfTooBig); } -void Graphics::drawText (const String& text, const int x, const int y, const int width, const int height, +void Graphics::drawText (const String& text, int x, int y, int width, int height, Justification justificationType, const bool useEllipsesIfTooBig) const { - drawText (text, Rectangle (x, y, width, height), justificationType, useEllipsesIfTooBig); + drawText (text, coordsToRectangle (x, y, width, height), justificationType, useEllipsesIfTooBig); } -void Graphics::drawFittedText (const String& text, const Rectangle& area, +void Graphics::drawFittedText (const String& text, Rectangle area, Justification justification, const int maximumNumberOfLines, const float minimumHorizontalScale) const @@ -328,7 +328,7 @@ void Graphics::drawFittedText (const String& text, const Rectangle& area, } } -void Graphics::drawFittedText (const String& text, const int x, const int y, const int width, const int height, +void Graphics::drawFittedText (const String& text, int x, int y, int width, int height, Justification justification, const int maximumNumberOfLines, const float minimumHorizontalScale) const @@ -338,12 +338,12 @@ void Graphics::drawFittedText (const String& text, const int x, const int y, con } //============================================================================== -void Graphics::fillRect (const Rectangle& r) const +void Graphics::fillRect (Rectangle r) const { context.fillRect (r, false); } -void Graphics::fillRect (const Rectangle& r) const +void Graphics::fillRect (Rectangle r) const { context.fillRect (r); } @@ -371,7 +371,7 @@ void Graphics::fillRectList (const RectangleList& rects) const void Graphics::setPixel (int x, int y) const { - context.fillRect (Rectangle (x, y, 1, 1), false); + context.fillRect (coordsToRectangle (x, y, 1, 1), false); } void Graphics::fillAll() const @@ -426,7 +426,7 @@ void Graphics::drawRect (int x, int y, int width, int height, int lineThickness) drawRect (coordsToRectangle (x, y, width, height), lineThickness); } -void Graphics::drawRect (const Rectangle& r, int lineThickness) const +void Graphics::drawRect (Rectangle r, int lineThickness) const { drawRect (r.toFloat(), (float) lineThickness); } @@ -444,7 +444,7 @@ void Graphics::drawRect (Rectangle r, const float lineThickness) const } //============================================================================== -void Graphics::fillEllipse (const Rectangle& area) const +void Graphics::fillEllipse (Rectangle area) const { Path p; p.addEllipse (area); @@ -453,19 +453,31 @@ void Graphics::fillEllipse (const Rectangle& area) const void Graphics::fillEllipse (float x, float y, float w, float h) const { - fillEllipse (Rectangle (x, y, w, h)); + fillEllipse (coordsToRectangle (x, y, w, h)); } void Graphics::drawEllipse (float x, float y, float width, float height, float lineThickness) const { - Path p; - p.addEllipse (x, y, width, height); - strokePath (p, PathStrokeType (lineThickness)); + drawEllipse (coordsToRectangle (x, y, width, height), lineThickness); } -void Graphics::drawEllipse (const Rectangle& area, float lineThickness) const +void Graphics::drawEllipse (Rectangle area, float lineThickness) const { - drawEllipse (area.getX(), area.getY(), area.getWidth(), area.getHeight(), lineThickness); + Path p; + + if (area.getWidth() == area.getHeight()) + { + // For a circle, we can avoid having to generate a stroke + p.addEllipse (area.expanded (lineThickness * 0.5f)); + p.addEllipse (area.reduced (lineThickness * 0.5f)); + p.setUsingNonZeroWinding (false); + fillPath (p); + } + else + { + p.addEllipse (area); + strokePath (p, PathStrokeType (lineThickness)); + } } void Graphics::fillRoundedRectangle (float x, float y, float width, float height, float cornerSize) const @@ -473,7 +485,7 @@ void Graphics::fillRoundedRectangle (float x, float y, float width, float height fillRoundedRectangle (coordsToRectangle (x, y, width, height), cornerSize); } -void Graphics::fillRoundedRectangle (const Rectangle& r, const float cornerSize) const +void Graphics::fillRoundedRectangle (Rectangle r, const float cornerSize) const { Path p; p.addRoundedRectangle (r, cornerSize); @@ -486,7 +498,7 @@ void Graphics::drawRoundedRectangle (float x, float y, float width, float height drawRoundedRectangle (coordsToRectangle (x, y, width, height), cornerSize, lineThickness); } -void Graphics::drawRoundedRectangle (const Rectangle& r, float cornerSize, float lineThickness) const +void Graphics::drawRoundedRectangle (Rectangle r, float cornerSize, float lineThickness) const { Path p; p.addRoundedRectangle (r, cornerSize); @@ -500,7 +512,7 @@ void Graphics::drawArrow (const Line& line, float lineThickness, float ar fillPath (p); } -void Graphics::fillCheckerBoard (const Rectangle& area, +void Graphics::fillCheckerBoard (Rectangle area, const int checkWidth, const int checkHeight, Colour colour1, Colour colour2) const { diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 3cfcc8cf62..9c89b9370f 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -170,7 +170,7 @@ public: @see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText */ void drawText (const String& text, - const Rectangle& area, + Rectangle area, Justification justificationType, bool useEllipsesIfTooBig = true) const; @@ -184,7 +184,7 @@ public: @see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText */ void drawText (const String& text, - const Rectangle& area, + Rectangle area, Justification justificationType, bool useEllipsesIfTooBig = true) const; @@ -233,7 +233,7 @@ public: @see GlyphArrangement::addFittedText */ void drawFittedText (const String& text, - const Rectangle& area, + Rectangle area, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale = 0.0f) const; @@ -257,12 +257,12 @@ public: /** Fills a rectangle with the current colour or brush. @see drawRect, fillRoundedRectangle */ - void fillRect (const Rectangle& rectangle) const; + void fillRect (Rectangle rectangle) const; /** Fills a rectangle with the current colour or brush. @see drawRect, fillRoundedRectangle */ - void fillRect (const Rectangle& rectangle) const; + void fillRect (Rectangle rectangle) const; /** Fills a rectangle with the current colour or brush. @see drawRect, fillRoundedRectangle @@ -297,11 +297,11 @@ public: /** Uses the current colour or brush to fill a rectangle with rounded corners. @see drawRoundedRectangle, Path::addRoundedRectangle */ - void fillRoundedRectangle (const Rectangle& rectangle, + void fillRoundedRectangle (Rectangle rectangle, float cornerSize) const; /** Fills a rectangle with a checkerboard pattern, alternating between two colours. */ - void fillCheckerBoard (const Rectangle& area, + void fillCheckerBoard (Rectangle area, int checkWidth, int checkHeight, Colour colour1, Colour colour2) const; @@ -321,7 +321,7 @@ public: The lines are drawn inside the given rectangle, and greater line thicknesses extend inwards. @see fillRect */ - void drawRect (const Rectangle& rectangle, int lineThickness = 1) const; + void drawRect (Rectangle 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. @@ -338,7 +338,7 @@ public: /** Uses the current colour or brush to draw the outline of a rectangle with rounded corners. @see fillRoundedRectangle, Path::addRoundedRectangle */ - void drawRoundedRectangle (const Rectangle& rectangle, + void drawRoundedRectangle (Rectangle rectangle, float cornerSize, float lineThickness) const; /** Fills a 1x1 pixel using the current colour or brush. @@ -358,7 +358,7 @@ public: The ellipse is drawn to fit inside the given rectangle. @see drawEllipse, Path::addEllipse */ - void fillEllipse (const Rectangle& area) const; + void fillEllipse (Rectangle area) const; /** Draws an elliptical stroke using the current colour or brush. @see fillEllipse, Path::addEllipse @@ -369,7 +369,7 @@ public: /** Draws an elliptical stroke using the current colour or brush. @see fillEllipse, Path::addEllipse */ - void drawEllipse (const Rectangle& area, float lineThickness) const; + void drawEllipse (Rectangle area, float lineThickness) const; //============================================================================== /** Draws a line between two points. @@ -581,7 +581,7 @@ public: 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. */ - bool clipRegionIntersects (const Rectangle& area) const; + bool clipRegionIntersects (Rectangle area) const; /** Intersects the current clipping region with another region. @@ -595,7 +595,7 @@ public: @returns true if the resulting clipping region is non-zero in size @see setOrigin, clipRegionIntersects */ - bool reduceClipRegion (const Rectangle& area); + bool reduceClipRegion (Rectangle area); /** Intersects the current clipping region with a rectangle list region. @@ -625,7 +625,7 @@ public: bool reduceClipRegion (const Image& image, const AffineTransform& transform); /** Excludes a rectangle to stop it being drawn into. */ - void excludeClipRegion (const Rectangle& rectangleToExclude); + void excludeClipRegion (Rectangle rectangleToExclude); /** Returns true if no drawing can be done because the clip region is zero. */ bool isClipEmpty() const;