1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Cleaned up a few functions in Graphics, and optimised drawEllipse when used for circles

This commit is contained in:
jules 2016-06-30 15:44:25 +01:00
parent 6e0c1682ca
commit 5960afde1a
2 changed files with 51 additions and 39 deletions

View file

@ -25,7 +25,7 @@
namespace
{
template <typename Type>
Rectangle<Type> coordsToRectangle (Type x, Type y, Type w, Type h)
Rectangle<Type> 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<int>& area)
bool Graphics::reduceClipRegion (Rectangle<int> area)
{
saveStateIfPending();
return context.clipToRectangle (area);
@ -85,7 +85,7 @@ bool Graphics::reduceClipRegion (const Rectangle<int>& area)
bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
{
return reduceClipRegion (Rectangle<int> (x, y, w, h));
return reduceClipRegion (coordsToRectangle (x, y, w, h));
}
bool Graphics::reduceClipRegion (const RectangleList<int>& clipRegion)
@ -108,7 +108,7 @@ bool Graphics::reduceClipRegion (const Image& image, const AffineTransform& tran
return ! context.isClipEmpty();
}
void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
void Graphics::excludeClipRegion (Rectangle<int> rectangleToExclude)
{
saveStateIfPending();
context.excludeClipRectangle (rectangleToExclude);
@ -164,7 +164,7 @@ void Graphics::addTransform (const AffineTransform& transform)
context.addTransform (transform);
}
bool Graphics::clipRegionIntersects (const Rectangle<int>& area) const
bool Graphics::clipRegionIntersects (Rectangle<int> 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<float>& area,
void Graphics::drawText (const String& text, Rectangle<float> 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<float>& area,
}
}
void Graphics::drawText (const String& text, const Rectangle<int>& area,
void Graphics::drawText (const String& text, Rectangle<int> 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<int> (x, y, width, height), justificationType, useEllipsesIfTooBig);
drawText (text, coordsToRectangle (x, y, width, height), justificationType, useEllipsesIfTooBig);
}
void Graphics::drawFittedText (const String& text, const Rectangle<int>& area,
void Graphics::drawFittedText (const String& text, Rectangle<int> area,
Justification justification,
const int maximumNumberOfLines,
const float minimumHorizontalScale) const
@ -328,7 +328,7 @@ void Graphics::drawFittedText (const String& text, const Rectangle<int>& 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<int>& r) const
void Graphics::fillRect (Rectangle<int> r) const
{
context.fillRect (r, false);
}
void Graphics::fillRect (const Rectangle<float>& r) const
void Graphics::fillRect (Rectangle<float> r) const
{
context.fillRect (r);
}
@ -371,7 +371,7 @@ void Graphics::fillRectList (const RectangleList<int>& rects) const
void Graphics::setPixel (int x, int y) const
{
context.fillRect (Rectangle<int> (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<int>& r, int lineThickness) const
void Graphics::drawRect (Rectangle<int> r, int lineThickness) const
{
drawRect (r.toFloat(), (float) lineThickness);
}
@ -444,7 +444,7 @@ void Graphics::drawRect (Rectangle<float> r, const float lineThickness) const
}
//==============================================================================
void Graphics::fillEllipse (const Rectangle<float>& area) const
void Graphics::fillEllipse (Rectangle<float> area) const
{
Path p;
p.addEllipse (area);
@ -453,19 +453,31 @@ void Graphics::fillEllipse (const Rectangle<float>& area) const
void Graphics::fillEllipse (float x, float y, float w, float h) const
{
fillEllipse (Rectangle<float> (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<float>& area, float lineThickness) const
void Graphics::drawEllipse (Rectangle<float> 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<float>& r, const float cornerSize) const
void Graphics::fillRoundedRectangle (Rectangle<float> 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<float>& r, float cornerSize, float lineThickness) const
void Graphics::drawRoundedRectangle (Rectangle<float> r, float cornerSize, float lineThickness) const
{
Path p;
p.addRoundedRectangle (r, cornerSize);
@ -500,7 +512,7 @@ void Graphics::drawArrow (const Line<float>& line, float lineThickness, float ar
fillPath (p);
}
void Graphics::fillCheckerBoard (const Rectangle<int>& area,
void Graphics::fillCheckerBoard (Rectangle<int> area,
const int checkWidth, const int checkHeight,
Colour colour1, Colour colour2) const
{

View file

@ -170,7 +170,7 @@ public:
@see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
*/
void drawText (const String& text,
const Rectangle<int>& area,
Rectangle<int> 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<float>& area,
Rectangle<float> area,
Justification justificationType,
bool useEllipsesIfTooBig = true) const;
@ -233,7 +233,7 @@ public:
@see GlyphArrangement::addFittedText
*/
void drawFittedText (const String& text,
const Rectangle<int>& area,
Rectangle<int> 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<int>& rectangle) const;
void fillRect (Rectangle<int> rectangle) const;
/** Fills a rectangle with the current colour or brush.
@see drawRect, fillRoundedRectangle
*/
void fillRect (const Rectangle<float>& rectangle) const;
void fillRect (Rectangle<float> 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<float>& rectangle,
void fillRoundedRectangle (Rectangle<float> rectangle,
float cornerSize) const;
/** Fills a rectangle with a checkerboard pattern, alternating between two colours. */
void fillCheckerBoard (const Rectangle<int>& area,
void fillCheckerBoard (Rectangle<int> 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<int>& rectangle, int lineThickness = 1) const;
void 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.
@ -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<float>& rectangle,
void drawRoundedRectangle (Rectangle<float> 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<float>& area) const;
void fillEllipse (Rectangle<float> 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<float>& area, float lineThickness) const;
void drawEllipse (Rectangle<float> 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<int>& area) const;
bool clipRegionIntersects (Rectangle<int> 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<int>& area);
bool reduceClipRegion (Rectangle<int> 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<int>& rectangleToExclude);
void excludeClipRegion (Rectangle<int> rectangleToExclude);
/** Returns true if no drawing can be done because the clip region is zero. */
bool isClipEmpty() const;