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

Changed the parameters to Graphics::fillCheckerBoard() to be floats rather than ints, and improved its performance

This commit is contained in:
jules 2017-12-06 17:33:26 +00:00
parent d727f2a35a
commit d9585241ad
15 changed files with 47 additions and 47 deletions

View file

@ -573,7 +573,7 @@ public:
void paint (Graphics& g) override
{
g.fillCheckerBoard (getLocalBounds(), 48, 48,
g.fillCheckerBoard (getLocalBounds().toFloat(), 48.0f, 48.0f,
Colours::lightgrey, Colours::white);
}

View file

@ -74,7 +74,7 @@ public:
void paint (Graphics& g) override
{
g.fillCheckerBoard (getLocalBounds(), 48, 48, Colours::lightgrey, Colours::white);
g.fillCheckerBoard (getLocalBounds().toFloat(), 48.0f, 48.0f, Colours::lightgrey, Colours::white);
if (shader == nullptr || shader->getFragmentShaderCode() != fragmentCode)
{

View file

@ -60,8 +60,7 @@ public:
p.addRectangle (area);
DropShadow (Colours::black.withAlpha (0.5f), 6, Point<int> (0, 1)).drawForPath (g, p);
g.fillCheckerBoard (area.getSmallestIntegerContainer(), 24, 24,
Colour (0xffffffff), Colour (0xffeeeeee));
g.fillCheckerBoard (area, 24.0f, 24.0f, Colour (0xffffffff), Colour (0xffeeeeee));
drawable->draw (g, 1.0f, RectanglePlacement (RectanglePlacement::stretchToFit)
.getTransformToFit (contentBounds, area.toFloat()));

View file

@ -356,7 +356,7 @@ private:
void paint (Graphics& g) override
{
if (jucerComp == nullptr)
g.fillCheckerBoard (getLocalBounds(), 50, 50,
g.fillCheckerBoard (getLocalBounds().toFloat(), 50.0f, 50.0f,
Colour::greyLevel (0.9f).withAlpha (0.4f),
Colour::greyLevel (0.8f).withAlpha (0.4f));
}

View file

@ -285,7 +285,7 @@ private:
void paint (Graphics& g) override
{
g.fillCheckerBoard (getLocalBounds(), 50, 50,
g.fillCheckerBoard (getLocalBounds().toFloat(), 50.0f, 50.0f,
Colours::lightgrey.withAlpha (0.5f),
Colours::darkgrey.withAlpha (0.5f));
}

View file

@ -407,8 +407,8 @@ private:
image = Image (Image::RGB, 100, 100, true);
Graphics g (image);
g.fillCheckerBoard (image.getBounds(),
image.getWidth() / 2, image.getHeight() / 2,
g.fillCheckerBoard (image.getBounds().toFloat(),
image.getWidth() * 0.5f, image.getHeight() * 0.5f,
Colours::white, Colours::lightgrey);
g.setFont (12.0f);

View file

@ -61,8 +61,8 @@ public:
{
g.fillAll (Colours::grey);
g.fillCheckerBoard (getLocalBounds().reduced (2, 2),
10, 10,
g.fillCheckerBoard (getLocalBounds().reduced (2, 2).toFloat(),
10.0f, 10.0f,
Colour (0xffdddddd).overlaidWith (colour),
Colour (0xffffffff).overlaidWith (colour));

View file

@ -525,8 +525,9 @@ void PaintRoutine::fillWithBackground (Graphics& g, const bool drawOpaqueBackgro
{
if ((! backgroundColour.isOpaque()) && drawOpaqueBackground)
{
g.fillCheckerBoard (Rectangle<int> (0, 0, g.getClipBounds().getRight(), g.getClipBounds().getBottom()),
50, 50,
g.fillCheckerBoard (Rectangle<float> ((float) g.getClipBounds().getRight(),
(float) g.getClipBounds().getBottom()),
50.0f, 50.0f,
Colour (0xffdddddd).overlaidWith (backgroundColour),
Colour (0xffffffff).overlaidWith (backgroundColour));
}

View file

@ -66,8 +66,8 @@ private:
const Colour colour (getColour());
g.fillAll (Colours::grey);
g.fillCheckerBoard (getLocalBounds().reduced (2),
10, 10,
g.fillCheckerBoard (getLocalBounds().reduced (2).toFloat(),
10.0f, 10.0f,
Colour (0xffdddddd).overlaidWith (colour),
Colour (0xffffffff).overlaidWith (colour));

View file

@ -512,8 +512,7 @@ void Graphics::drawArrow (Line<float> line, float lineThickness, float arrowhead
fillPath (p);
}
void Graphics::fillCheckerBoard (Rectangle<int> area,
const int checkWidth, const int checkHeight,
void Graphics::fillCheckerBoard (Rectangle<float> area, float checkWidth, float checkHeight,
Colour colour1, Colour colour2) const
{
jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
@ -525,31 +524,33 @@ void Graphics::fillCheckerBoard (Rectangle<int> area,
if (colour1 == colour2)
{
context.setFill (colour1);
context.fillRect (area, false);
context.fillRect (area);
}
else
{
auto clipped = context.getClipBounds().getIntersection (area);
auto clipped = context.getClipBounds().getIntersection (area.getSmallestIntegerContainer());
if (! clipped.isEmpty())
{
context.clipToRectangle (clipped);
const int checkNumX = (clipped.getX() - area.getX()) / checkWidth;
const int checkNumY = (clipped.getY() - area.getY()) / checkHeight;
const int startX = area.getX() + checkNumX * checkWidth;
const int startY = area.getY() + checkNumY * checkHeight;
const int right = clipped.getRight();
const int bottom = clipped.getBottom();
const int checkNumX = (int) ((clipped.getX() - area.getX()) / checkWidth);
const int checkNumY = (int) ((clipped.getY() - area.getY()) / checkHeight);
const float startX = area.getX() + checkNumX * checkWidth;
const float startY = area.getY() + checkNumY * checkHeight;
const float right = clipped.getRight();
const float bottom = clipped.getBottom();
for (int i = 0; i < 2; ++i)
{
context.setFill (i == ((checkNumX ^ checkNumY) & 1) ? colour1 : colour2);
int cy = i;
for (int y = startY; y < bottom; y += checkHeight)
for (int x = startX + (cy++ & 1) * checkWidth; x < right; x += checkWidth * 2)
context.fillRect (Rectangle<int> (x, y, checkWidth, checkHeight), false);
RectangleList<float> checks;
for (float y = startY; y < bottom; y += checkHeight)
for (float x = startX + (cy++ & 1) * checkWidth; x < right; x += checkWidth * 2.0f)
checks.addWithoutMerging ({ x, y, checkWidth, checkHeight });
checks.clipTo (area);
context.setFill (i == ((checkNumX ^ checkNumY) & 1) ? colour1 : colour2);
context.fillRectList (checks);
}
}
}

View file

@ -300,8 +300,8 @@ public:
float cornerSize) const;
/** Fills a rectangle with a checkerboard pattern, alternating between two colours. */
void fillCheckerBoard (Rectangle<int> area,
int checkWidth, int checkHeight,
void fillCheckerBoard (Rectangle<float> area,
float checkWidth, float checkHeight,
Colour colour1, Colour colour2) const;
/** Draws a rectangular outline, using the current colour or brush.

View file

@ -53,7 +53,7 @@ public:
}
/** Creates a list containing just one rectangle. */
RectangleList (const RectangleType& rect)
RectangleList (RectangleType rect)
{
addWithoutMerging (rect);
}
@ -106,7 +106,7 @@ public:
The rectangle can have any size and may be empty, but if it's floating point
then it's expected to not contain any INF values.
*/
void add (const RectangleType& rect)
void add (RectangleType rect)
{
jassert (rect.isFinite()); // You must provide a valid rectangle to this method!
@ -176,7 +176,7 @@ public:
The rectangle can have any size and may be empty, but if it's floating point
then it's expected to not contain any INF values.
*/
void addWithoutMerging (const RectangleType& rect)
void addWithoutMerging (RectangleType rect)
{
jassert (rect.isFinite()); // You must provide a valid rectangle to this method!
@ -200,7 +200,7 @@ public:
Any rectangles in the list which overlap this will be clipped and subdivided
if necessary.
*/
void subtract (const RectangleType& rect)
void subtract (RectangleType rect)
{
if (auto numRects = rects.size())
{
@ -310,7 +310,7 @@ public:
@see getIntersectionWith
*/
bool clipTo (const RectangleType& rect)
bool clipTo (RectangleType rect)
{
jassert (rect.isFinite()); // You must provide a valid rectangle to this method!
@ -377,7 +377,7 @@ public:
@see clipTo
*/
bool getIntersectionWith (const RectangleType& rect, RectangleList& destRegion) const
bool getIntersectionWith (RectangleType rect, RectangleList& destRegion) const
{
jassert (rect.isFinite()); // You must provide a valid rectangle to this method!
@ -428,7 +428,7 @@ public:
defined by this object
@see intersectsRectangle, containsPoint
*/
bool containsRectangle (const RectangleType& rectangleToCheck) const
bool containsRectangle (RectangleType rectangleToCheck) const
{
if (rects.size() > 1)
{
@ -456,7 +456,7 @@ public:
defined by this object
@see containsRectangle
*/
bool intersectsRectangle (const RectangleType& rectangleToCheck) const noexcept
bool intersectsRectangle (RectangleType rectangleToCheck) const noexcept
{
for (auto& r : rects)
if (r.intersects (rectangleToCheck))
@ -466,7 +466,6 @@ public:
}
/** Checks whether this region intersects any part of another one.
@see intersectsRectangle
*/
bool intersects (const RectangleList& other) const noexcept

View file

@ -553,7 +553,7 @@ struct TextEditor::Iterator
Graphics::ScopedSaveState state (g);
g.reduceClipRegion ({ startX, baselineY, endX - startX, 1 });
g.fillCheckerBoard ({ endX, baselineY + 1 }, 3, 1, colour, Colours::transparentBlack);
g.fillCheckerBoard ({ (float) endX, baselineY + 1.0f }, 3.0f, 1.0f, colour, Colours::transparentBlack);
}
void drawSelectedText (Graphics& g, Range<int> selected, Colour selectedTextColour) const

View file

@ -261,7 +261,7 @@ public:
{
const Colour c (owner.getSwatchColour (index));
g.fillCheckerBoard (getLocalBounds(), 6, 6,
g.fillCheckerBoard (getLocalBounds().toFloat(), 6.0f, 6.0f,
Colour (0xffdddddd).overlaidWith (c),
Colour (0xffffffff).overlaidWith (c));
}
@ -430,9 +430,9 @@ void ColourSelector::paint (Graphics& g)
if ((flags & showColourAtTop) != 0)
{
const Colour currentColour (getCurrentColour());
auto currentColour = getCurrentColour();
g.fillCheckerBoard (previewArea, 10, 10,
g.fillCheckerBoard (previewArea.toFloat(), 10.0f, 10.0f,
Colour (0xffdddddd).overlaidWith (currentColour),
Colour (0xffffffff).overlaidWith (currentColour));

View file

@ -410,7 +410,7 @@ struct ColourEditorComp : public Component,
void paint (Graphics& g) override
{
g.fillCheckerBoard (getLocalBounds(), 6, 6,
g.fillCheckerBoard (getLocalBounds().toFloat(), 6.0f, 6.0f,
Colour (0xffdddddd).overlaidWith (getColour()),
Colour (0xffffffff).overlaidWith (getColour()));
}