|
|
Home » Community » Newbie corner » Ctrl: Paint only affected area?
Ctrl: Paint only affected area? [message #31693] |
Sun, 20 March 2011 13:44 |
Lance
Messages: 527 Registered: March 2007
|
Contributor |
|
|
Does there exist a mechanism to allow a Ctrl derivative to get informed the actual Rect that needs to be redrawn? virtual Paint(Draw& w); doesn't seem to allow that.
Or the design of Upp has determined the whole area of a Ctrl needs to be redrawn however minor the change might be.
Let's say, we have a really large ArrayCtrl/GridCtrl/etc that spans multiple monitors displaying instant stock market information. Do we need to redraw the whole array when only one cell is changed?
Thanks,
Lance
|
|
|
|
|
Re: Ctrl: Paint only affected area? [message #31699 is a reply to message #31693] |
Sun, 20 March 2011 15:03 |
|
Hi Lance
If I am not mistaken, U++ always repaints only the parts that are necessary. The Paint() method always repaints the entire area of the Ctrl, but only parts that need to be updated are actually transfered to the screen (which is the slowest part of the process usually). The Ctrl itself should usually repaint it's whole area. In some cases, you can cache the image inside the Ctrl and change only parts that you know that they need it (e.g. GridCtrl uses this approach I think), but it requires you keep track of what needs to be repainted yourself.
The mechanism works like this: When something needs to be updated, you call its Refresh() method, if only part of Ctrl needs to be updated then use Refresh(Rect r). U++ then calls Paint() on all Ctrls with changed areas and then transfers all the marked areas to the screen. To see which parts of your GUI are repainted and when, call Ctrl::ShowRepaint(50) inside your code, it will help you understand and it is sometimes also quite useful for debugging
There is also a set of methods intended to track the changes inside Ctrl, which can be helpful sometimes: SetModify(), IsModified() and ClearModify(). These are not directly related to the repainting (AFAIK), but they are worth mentioning since they provide common interface that can be often used to optimize the performance (I (mis)use it for caching the Ctrls visuals ) while keeping the code readable.
Hope I didn't simplify it too much, but this is actually all I ever needed to know about this
Best regards,
Honza
|
|
|
|
Re: Ctrl: Paint only affected area? [message #31701 is a reply to message #31700] |
Sun, 20 March 2011 15:51 |
|
Lance wrote on Sun, 20 March 2011 15:31 | Shall I call you Honza or dolik? I use the Ubuntu ppa you maintain regularly, and thank you for the time you you invested for the community.
| Honza is my real name, dolik.rce is a nick. You can use whichever you prefer, I respond on both
Lance wrote on Sun, 20 March 2011 15:31 | Your reply is closer to what I was actually seeking. A little question, as Upp will alway mask and transfer the changed Rect or possibly combined area to the screen, what's the point of cache the Ctrl image? I should be able to draw on a blank image representing the Ctrl Rect, and draw only the part that's changed, Upp will mask off other parts before it transfer to the screen anyways.
Am I right or do I misinterpret your answer?
|
You are quite possibly right. I just never tried this, so I am not sure how it works. There might be some hidden obstacles with this approach, e.g. when the whole area needs to be repainted even though nothing or only part has changed (e.g. when minimalized window is restored). This could be worked around if there was a way to obtain description of area which is scheduled for repainting, but AFAIK that is not possible at the moment (the screen area is invalidated right away and the rect is not stored anywhere). But as I say, I never tried so the problems I imagine might not exist or might have a solution
Honza
|
|
|
Re: Ctrl: Paint only affected area? [message #31703 is a reply to message #31693] |
Sun, 20 March 2011 21:46 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Also check Draw::IsPainting.
Generally, you do not use this as drawing is masked out and operations to masked out areas not performed.
However, sometimes there is some processing power associated outside draw operations, then it can be handy to have a way to check whether some area is to be painted...
Mirek
[Updated on: Sun, 20 March 2011 21:48] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 29 07:28:37 CEST 2024
Total time taken to generate the page: 0.03122 seconds
|
|
|