ResizableWindow: don't paint() until resizeEnd()?


I have a DocumentWindow whose contents is dynamically drawn via paint().   whenever i resize the window, paint() is called every frame.   as i'm dealing with a lot of std::vector<>'s being cleared and recalculated, it would be a big improvement to performance if I could make the window not recalculate while it's being resized.   I noticed the resizeBegin() and resizeEnd() methods in the ComponentBoundsContainer class, so i'm wondering if there's a way to make some code not be run until the window is finished being resized.   If so, what is the proper approach?   since any call to resized() results in a subsequent call to paint(), I can't figure out how to get around this.   Any help would be appreciated.  

to summarize, I'm hoping to not do any calculations until ResizableWindow has finished being resized, once that lower right hand corner is grabbed and dragged, and only then should my DocumentWindow call paint() and refresh.


You could set a really short timer on resized() and hold all updates until an interval of 30ms or so has passed since the last call to resized().  



The correct way to think about this kind of thing is that your paint routine should never do anything that takes a long time.

If you've got time-consuming work happening, then it should go in a background thread, or at least be on a timer. Your paint routine should just display whatever's currently ready, as quickly as possible.


the paint routine doesn't do any calculations.   but the resized() method does.   and that resized() gets called every time the window dimensions change when it's being dragged.   

I do a lot of work with Finale, from MakeMusic.   They have a thing where when you resize the score window, it doesn't redraw the score until after you release the mouse.   They show you the outline of a rectangle that follows the window's new dimensions as long as you're dragging.   it's kinda similar to the rectangle that's shown when you press Cmd Option 4 and click-drag.   once you release the mouse, the window resizes to rectangle you drew.    How would something like that be implemented?


Same answer as I gave above, but replace "paint" with "resized" :)


ok, so just add a timer to my class, and when resize() is called, start the timer if it's not already running.   Then when the timer fires, call my method and stop the timer? 


You can not just draw on a cached bitmap juce::Image? With a juce::Viewport to allow user to scroll inside? Of course it is not possible if the content of your paint depends of the window size.