# getUnclippedArea

**URL:** <https://forum.juce.com/t/getunclippedarea/1881>\
**Category:** General JUCE discussion\
**Created:** [July 9, 2007, 9:56am UTC](https://forum.juce.com/t/getunclippedarea/1881 "2007-07-09T09:56:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 9, 2007, 9:56am UTC](https://forum.juce.com/t/getunclippedarea/1881/1 "2007-07-09T09:56:06Z")

</div>

Hi Jules, any particular reason the Component::getUnclippedArea is private? I’d like to get hold of it to minimize time in paint…

---

<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 9, 2007, 10:08am UTC](https://forum.juce.com/t/getunclippedarea/1881/2 "2007-07-09T10:08:49Z")

</div>

You should use getVisibleArea() for that. The private one is just used internally for stuff.

---

<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 9, 2007, 10:10am UTC](https://forum.juce.com/t/getunclippedarea/1881/3 "2007-07-09T10:10:21Z")

</div>

…BTW that’s definitely not a good way to optimise your painting - use Graphics::getClipBounds() to find the area that’s being drawn.

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 9, 2007, 10:11am UTC](https://forum.juce.com/t/getunclippedarea/1881/4 "2007-07-09T10:11:14Z")

</div>

Thanks Jules, that is really what I wanted.

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 9, 2007, 11:29am UTC](https://forum.juce.com/t/getunclippedarea/1881/5 "2007-07-09T11:29:59Z")

</div>

While on topic, how’d you suggest handling a component that is being scrolled so that every now & then a bit more of it is shown. A fully optimised drawing would draw only that part. But getClipBounds returns the whole area that is visible, not just that little piece ?

---

<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 9, 2007, 11:37am UTC](https://forum.juce.com/t/getunclippedarea/1881/6 "2007-07-09T11:37:22Z")

</div>

It’s actually quite a fiddly problem, because you’d need to keep a buffered image of the content, so you can quickly draw the bits that haven’t changed, and then render and add the new bits. (Unless the content is really slow to draw, this often wouldn’t really be much faster, though)

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 9, 2007, 11:41am UTC](https://forum.juce.com/t/getunclippedarea/1881/7 "2007-07-09T11:41:32Z")

</div>

Mmm… that’s about what I had in mind. I noticed though that in release build, the repaint time is quite tolerable, so I’ll skip it for now.

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 10, 2007, 6:33pm UTC](https://forum.juce.com/t/getunclippedarea/1881/8 "2007-07-10T18:33:55Z")

</div>

Strange, I did a get-uncovered-area-thingy that correctly returns the invalidated area so I can render only there, and it works nicely in debug mode, but in release mode once in a while the whole invalidated area is not drawn, just part of it. But only in release mode… :?

---

<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 10, 2007, 6:55pm UTC](https://forum.juce.com/t/getunclippedarea/1881/9 "2007-07-10T18:55:07Z")

</div>

Got any code to reproduce it?

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 10, 2007, 7:10pm UTC](https://forum.juce.com/t/getunclippedarea/1881/10 "2007-07-10T19:10:39Z")

</div>

Yup, something like this:

[code]//==============================================================================  
void MyComponent::paint (Graphics& g)  
{  
Rectangle clipBounds = g.getClipBounds();  
if (!clipBounds.isEmpty())  
{  
Rectangle toDrawInto = getUncoveredArea(clipBounds);  
if (!toDrawInto.isEmpty() || (m\_cachedImage.get() == 0))   
{  
if (m\_cachedImage.get() == 0)  
{  
m\_cachedImage.reset(new Image(Image::ARGB, getWidth(), getHeight(), true));  
// New image, draw everything within clipping area.  
toDrawInto = clipBounds;  
}  
else  
{  
m\_cachedImage-\>clear(toDrawInto.getX(), toDrawInto.getY(), toDrawInto.getWidth(), toDrawInto.getHeight());  
}  
Graphics memG(\*m\_cachedImage.get());  
// Here comes the drawing stuff which will draw from  
// toDrawInto.getX() to toDrawInto.getRight()  
[…snip…]  
}

```
    if (m_waveImage.get() != 0)
    {
        g.drawImage(m_waveImage.get(), clipBounds.getX(), clipBounds.getY(), clipBounds.getWidth(), clipBounds.getHeight(), 

```

clipBounds.getX(), clipBounds.getY(), clipBounds.getWidth(), clipBounds.getHeight());  
}

```
}

```

}

void MyComponent::resized()  
{  
// Clear cached image so entire clipping area will be redrawn…  
m\_cachedImage.reset( 0 );  
}

[/code]  
And it does work nicely in debug mode… (the .get() and .reset(…) on m\_cachedImage has to do with it being a std::auto\_ptr )

---

<div class="post-metadata">

**Author:** ![robiwan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/robiwan/32/2446_2.png) [@robiwan](https://forum.juce.com/u/robiwan)\
**Post date:** [July 10, 2007, 7:25pm UTC](https://forum.juce.com/t/getunclippedarea/1881/11 "2007-07-10T19:25:56Z")

</div>

Ehrm… it was a bug in my impl of getUncoveredArea. Now I only return the uncovered area if the last clip bounds are of the same size as the new clip bounds, otherwise I return the clip bounds. Now it works in release to. Yay! 🙂

Ps. It occasionally didn’t work in debug either…

---

<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:** [May 12, 2017, 10:27am UTC](https://forum.juce.com/t/getunclippedarea/1881/12 "2017-05-12T10:27:14Z")

</div>


