Recent

Author Topic: ReDraw [Invalidate, Repaint, Update, Refresh]  (Read 9110 times)

RAW

  • Hero Member
  • *****
  • Posts: 868
ReDraw [Invalidate, Repaint, Update, Refresh]
« on: March 11, 2018, 07:27:28 pm »
Refresh:
 calls Repaint  // not needed

Repaint:
 If csOpaque Then direct redraw
 Else calls Invalidate and Update

Invalidate:
 InvalidateRect
 wich part is visible?  // can be used more than once, can reduce flicker

Update:
 UpdateWindow  // no Invalidate, no waiting for WM_Paint, faster


Has anybody seen some really good examples to really explain this ???
When do I use what?

Normally -> Invalidate
Fast       -> Update

????
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #1 on: March 11, 2018, 09:18:35 pm »
Refresh is there so you can override it to have your control do other unique updates and then
call the inherited, which in this case is calling repaint.
 
 This makes is easier to make changes to the surface settings or maybe setup a region before repaint.

 " Invalidate" basically will call send a Paint message to the control after other messages in the que have
been processed, it also invalidates the whole control and forces a complete update.
 
 I believe windows will purge any pending invalidate after this gets processed so this means you don't
get repeating painting and there should be no regions set.

As for "Update" what it suppose to do is basically force a WM_PAINT to the control directly if there
was a invalidate done but still sitting in the buffer, this is suppose to check for that check and force
the repaint and then remove the pending invalidate.

 That I can't tell you how well that is supported.

 I wanted to add the UPDATE will also process all the other waiting messages and process any regions
waiting.

 Where as, Repaint just simple does the whole control.
« Last Edit: March 11, 2018, 09:20:32 pm by jamie »
The only true wisdom is knowing you know nothing

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #2 on: March 11, 2018, 09:42:42 pm »
@jamie: Thanks!

Quote
Refresh is there so you can override it to have your control do other unique updates and then
call the inherited, which in this case is calling repaint.
This makes is easier to make changes to the surface settings or maybe setup a region before repaint.
Interesting... never thought about doing something like that...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #3 on: March 11, 2018, 10:40:00 pm »
@ Invalidate:
 InvalidateRect
 wich part is visible?

When you call Invalidate or InvalidateRect, Paint method will follow. Even more, Paint may be called by widgetset of some reason. It may happen that you call InvalidateRect, then other Invalidate or requirement to repaint is called, and Paint of the full area will come (i.e. repaint of the single rectangle specified in InvalidateRect never happen).

You can get the actual area to be repainted easily. Each method Paint is preceded by WMPaint message method. Its parameter Message: TLMPaint contains coordinates:
Message.PaintStruct^.rcPaint.Left
Message.PaintStruct^.rcPaint.Top
Message.PaintStruct^.rcPaint.Right
Message.PaintStruct^.rcPaint.Bottom
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #4 on: March 12, 2018, 12:49:45 am »
Quote
You can get the actual area to be repainted easily. Each method Paint is preceded by WMPaint message method. Its parameter Message: TLMPaint contains coordinates:
Message.PaintStruct^.rcPaint.Left
Message.PaintStruct^.rcPaint.Top
Message.PaintStruct^.rcPaint.Right
Message.PaintStruct^.rcPaint.Bottom
Thanks... good point.. haven't played around with these information delivered by LM_PAINT...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #5 on: March 12, 2018, 03:31:27 am »
Refresh:
 calls Repaint  // not needed
called by the end user to refresh the area of a control usually when there are property changes that do not refresh the control.
Repaint:
 If csOpaque Then direct redraw
 Else calls Invalidate and Update

As far as I remember from delphi repaint will handle all messages that have to do with painting invalidate, paint etc at the time it will be called. I used it to show progress updates on screen with out calling processmessages.
Invalidate:
 InvalidateRect
 wich part is visible?  // can be used more than once, can reduce flicker
The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function.
source
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145002(v=vs.85).aspx
In short it does not matter how ofter you call invalidaterect it will accumulate the rect in to single region which will be passed to the next paint method. Used to speed things up.
Update:
 UpdateWindow  // no Invalidate, no waiting for WM_Paint, faster

never used it my self.

In short as a component writer I use invalidate/invalidaterect as an end user I use repaint.

Now in lcl things are a bit out of spec for example repaint does not handle the paint messages at all as a result it does not update the screen at all.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: ReDraw [Invalidate, Repaint, Update, Refresh]
« Reply #6 on: March 12, 2018, 04:43:11 am »
@taazz: Thanks for the info...
I never really understood the differences and so normally I try all three to see if there are any differences. Normally I use Invalidate and in some cases Update to show a click effect with TImages or TLabels (looks nice and is very easy...). Right now I need some more advanced painting routines and I thought it's a good moment to dig a little bit more into this topic.  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018