Browse Source

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

tags/2021-05-28
jules 7 years ago
parent
commit
d9585241ad
15 changed files with 47 additions and 47 deletions
  1. +1
    -1
      examples/Demo/Source/Demos/GraphicsDemo.cpp
  2. +1
    -1
      examples/Demo/Source/Demos/OpenGLDemo2D.cpp
  3. +1
    -2
      extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h
  4. +1
    -1
      extras/Projucer/Source/ComponentEditor/Components/jucer_TabbedComponentHandler.h
  5. +1
    -1
      extras/Projucer/Source/ComponentEditor/Components/jucer_ViewportHandler.h
  6. +2
    -2
      extras/Projucer/Source/ComponentEditor/PaintElements/jucer_FillType.h
  7. +2
    -2
      extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h
  8. +3
    -2
      extras/Projucer/Source/ComponentEditor/jucer_PaintRoutine.cpp
  9. +2
    -2
      extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h
  10. +18
    -17
      modules/juce_graphics/contexts/juce_GraphicsContext.cpp
  11. +2
    -2
      modules/juce_graphics/contexts/juce_GraphicsContext.h
  12. +8
    -9
      modules/juce_graphics/geometry/juce_RectangleList.h
  13. +1
    -1
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  14. +3
    -3
      modules/juce_gui_extra/misc/juce_ColourSelector.cpp
  15. +1
    -1
      modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp

+ 1
- 1
examples/Demo/Source/Demos/GraphicsDemo.cpp 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);
}


+ 1
- 1
examples/Demo/Source/Demos/OpenGLDemo2D.cpp 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)
{


+ 1
- 2
extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h 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()));


+ 1
- 1
extras/Projucer/Source/ComponentEditor/Components/jucer_TabbedComponentHandler.h 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));
}


+ 1
- 1
extras/Projucer/Source/ComponentEditor/Components/jucer_ViewportHandler.h 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));
}


+ 2
- 2
extras/Projucer/Source/ComponentEditor/PaintElements/jucer_FillType.h 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);


+ 2
- 2
extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h 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));


+ 3
- 2
extras/Projucer/Source/ComponentEditor/jucer_PaintRoutine.cpp 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));
}


+ 2
- 2
extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h 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));


+ 18
- 17
modules/juce_graphics/contexts/juce_GraphicsContext.cpp 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);
}
}
}


+ 2
- 2
modules/juce_graphics/contexts/juce_GraphicsContext.h 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.


+ 8
- 9
modules/juce_graphics/geometry/juce_RectangleList.h 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


+ 1
- 1
modules/juce_gui_basics/widgets/juce_TextEditor.cpp 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


+ 3
- 3
modules/juce_gui_extra/misc/juce_ColourSelector.cpp 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));


+ 1
- 1
modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp 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()));
}


Loading…
Cancel
Save