# drawRect and component transforms in windows - bug?

**URL:** <https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227>\
**Category:** General JUCE discussion\
**Created:** [July 31, 2015, 4:23pm UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227 "2015-07-31T16:23:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [July 31, 2015, 4:23pm UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/1 "2015-07-31T16:23:39Z")

</div>

```
const int elementSpacing = 3; 
const int elementSize = 2; 

        for (int i = 0; i < elements; ++i)
        {
            Rectangle<int>r (mx, i * elementSpacing, mw, elementSize);
            g.setColour (color[i]);
            g.fillRect (r);
        }
```

This code produces the following _incorrect_ output (the meter) when scaling is applied to a parent component:

![](http://snag.gy/zb3aD.jpg)

WIth a 1.0, 1.0 scaling ratio it looks correct.

If I change the Rectangle\<int\> to a Rectangle\<float\> the correct output appears at all scalings, e.g.&nbsp;

![](http://snag.gy/c4VSX.jpg)

This affects my build on&nbsp;Windows 7, but not my MacOS build. &nbsp;I've not tested with other versions of windows, nor dug into the root cause. &nbsp;But I don't think it's correct behaviour?

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 31, 2015, 4:52pm UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/2 "2015-07-31T16:52:58Z")

</div>

Does it work if you draw a rectangle with floats instead of ints?

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [August 2, 2015, 10:27pm UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/3 "2015-08-02T22:27:00Z")

</div>

Yep.&nbsp; All fine with a float...that's what i was trying to say! :)&nbsp; The bottom image is it drawing, scaled, with floats.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 3, 2015, 1:50pm UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/4 "2015-08-03T13:50:03Z")

</div>

Sorry Jim, failed&nbsp;to read your post properly!

There is actually a bit of a difference between the way it handles int and float rectangles. If everything was drawn with float precision then adjacent large blocks of colour (e.g. the background colour of adjacent components) get little anti-aliasing artifacts between them when the GUI is scaled to tricky&nbsp;scale factors. To avoid that, I opted to use snapping when scaling the integer ones, which solved a lot of painting problems. I think this is only the case in the software renderer, though - somehow OSX seems to have a more cunning algorithm that solves the original problem, though I can't figure out what it is.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [August 4, 2015, 7:16am UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/5 "2015-08-04T07:16:08Z")

</div>

Awkward ;) &nbsp;I'll stick to using the floats for this kind of thing then! &nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 4, 2015, 7:59am UTC](https://forum.juce.com/t/drawrect-and-component-transforms-in-windows-bug/15227/6 "2015-08-04T07:59:04Z")

</div>

Yeah, it's a fundamental problem that if you draw two exactly-adjacent rectangles of the same colour, e.g. (0, 0, 100.5, 100) and (100.5, 0, 100, 100) then with normal anti-aliasing you'll have a visible artifact at the join.

So where people have&nbsp;done totally reasonable paint methods that fill their entire contents with adjacent-but-not-overlapping rectangles, then this goes wrong on scaled displays. Hence my hack. As far as I can tell CoreGraphics does something along the same lines, or maybe messes with the gamma or something.. but not sure exactly what their trick is.
