Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Ctrl: Paint only affected area?
Ctrl: Paint only affected area? [message #31693] Sun, 20 March 2011 13:44 Go to next message
Lance is currently offline  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 #31697 is a reply to message #31693] Sun, 20 March 2011 14:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
Hello Lance

As fas as I know only by default only the changed subrect is changed so you do not need to redraw it all.



Best regards
Iñaki
Re: Ctrl: Paint only affected area? [message #31698 is a reply to message #31697] Sun, 20 March 2011 14:54 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 527
Registered: March 2007
Contributor
Thank you very much. That's good to know! U++ is terrific.

As a way of learning U++, I was considering to write a Array/Grid control. Not to oversmart the existing ones, just to learn the U++ stuff and approach the problem in a different way. There are too much to learn before I can do that plus I don't really have a lot of time to invest into it right now.

But when I do become less busy, will you be able to mentor me on this topic?

Thank you,
Lance
Re: Ctrl: Paint only affected area? [message #31699 is a reply to message #31693] Sun, 20 March 2011 15:03 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Wink

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 Smile ) 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 Smile

Best regards,
Honza
Re: Ctrl: Paint only affected area? [message #31700 is a reply to message #31699] Sun, 20 March 2011 15:31 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 527
Registered: March 2007
Contributor
Shall I call you Honza or dolik? Smile I use the Ubuntu ppa you maintain regularly, and thank you for the time you you invested for the community.

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?

Thank you again,
Lance
Re: Ctrl: Paint only affected area? [message #31701 is a reply to message #31700] Sun, 20 March 2011 15:51 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Lance wrote on Sun, 20 March 2011 15:31

Shall I call you Honza or dolik? Smile 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 Smile

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 Wink

Honza
Re: Ctrl: Paint only affected area? [message #31703 is a reply to message #31693] Sun, 20 March 2011 21:46 Go to previous messageGo to next message
mirek is currently offline  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

Re: Ctrl: Paint only affected area? [message #31704 is a reply to message #31701] Sun, 20 March 2011 21:55 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
Hello Lance

As far as I know, (Honza post in summary Smile), you draw all Ctrl Rect but U++ finally only paints on the screen updated area (that is the slower side of painting).

This way code is simple but effective.

Put here the slowest part of your code, in a package better, and I am sure it will finally work fast.


Best regards
Iñaki
Re: Ctrl: Paint only affected area? [message #31719 is a reply to message #31704] Mon, 21 March 2011 12:22 Go to previous message
Lance is currently offline  Lance
Messages: 527
Registered: March 2007
Contributor
Great information. Thanks koldo and Mirek.

I will paint it the lazy way, and look into IsPaint only when there is actually need for further improvement.


Previous Topic: U++ questions
Next Topic: VC++ 2010 Express
Goto Forum:
  


Current Time: Sun Apr 28 21:02:11 CEST 2024

Total time taken to generate the page: 0.03364 seconds