Recent

Author Topic: ExcludeClipRect and other platforms  (Read 13135 times)

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
ExcludeClipRect and other platforms
« on: September 12, 2007, 09:24:49 pm »
I used ExcludeClipRect to improve my controls in paint/repaint to make it faster, in (Win32/Wince) and it work fine, but i am afraid is it will work on other platforms like as Linux/Mac ?

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: ExcludeClipRect and other platforms
« Reply #1 on: September 12, 2007, 10:00:54 pm »
Quote from: "zaher"
I used ExcludeClipRect to improve my controls in paint/repaint to make it faster, in (Win32/Wince) and it work fine, but i am afraid is it will work on other platforms like as Linux/Mac ?


ExcludeClipRect does not appear to be implemented on GTK / GTK2, but it is implemented in the Carbon widgetset, so you're okay on Mac OS X, but not on Linux.

-Phil

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2706
RE: Re: ExcludeClipRect and other platforms
« Reply #2 on: September 13, 2007, 10:47:53 am »
If you use invalidate rect to invalidate pieces of your control, the paintarea is already clipped to that rect. Also on gtk.
I wonder what kind of controls would need an exclude.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
RE: Re: ExcludeClipRect and other platforms
« Reply #3 on: September 13, 2007, 11:51:38 pm »
To reduce the flicker for slow computers like as WinCE or to huge controls like a grid sheet in the full screen, and not use a Double Buffer because it is take a more resource.

the idea by example: when i want to draw image and text in same box with background blue
- i paint the background by FillRect
- Draw the image at left of the rectangle
-  Draw the text at the right
my eye will see every time i refresh the control a flicker (blue then image and text)
there is another way to prevent the flicker

- Draw the image at top of the rectangle
- ExcludeClipRect the rect of that image
- Draw the text at the bottom
- ExcludeClipRect the rect of that text
- use FillRect over the whale rect, this will not paint over the image and the text, just the area that not execluded

I have control listing a images with text, without this way i will have many flickers with it on WinCE
(http://sahlisoft.com/gallery/mpos/mpos_materials.png)

It is in Arabic and right to left (i used png images with alpha)

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
RE: Re: ExcludeClipRect and other platforms
« Reply #4 on: September 14, 2007, 01:11:08 pm »
How About Canvas.ClipRect is it work also?

I just like make my control work in all platform supported.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2706
RE: Re: ExcludeClipRect and other platforms
« Reply #5 on: September 14, 2007, 02:24:36 pm »
You say you use alpha, but then you need to draw the background first. In my experience if you draw rectangle+image+text in one go, you won't see flicker. However, if like in your example,  you first fill the entire sceen with blue and then paint the images one by one I can imagine that you notice some flicker.
But, most times the flicker isn't caused by this. It is because the background is erased with a default color like crBtnFace and in a second phase the real color is painted.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
RE: Re: ExcludeClipRect and other platforms
« Reply #6 on: September 14, 2007, 04:48:10 pm »
I can return to old way and not exclude the rect, may i use a DEFINE for it,  you catch me with Alpha :)
But i have another controls like as virtual keyboard that what i need the to ExcludeClipRect because it is very slow in WINCE (200mh CPU) and work faster with ExcludeClipRect .

For the background erased with Color i override the EraseBackground and not inherited for my MainForm and my Panels (TposPanel)
Code: [Select]

procedure TMainForm.EraseBackground(DC: HDC);
begin
end;

For background it is same in Delphi too and i think it must exclude the rect of Graph control in EraseBackground (or WM_EREASEBKGRN..)  before paint it.

When i am surfing the code i noticed that a huge work Lazarus/FPC team worked on, i like to thanks them all.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2706
RE: Re: ExcludeClipRect and other platforms
« Reply #7 on: September 17, 2007, 11:41:59 am »
ok, makes sense. I've to admit that I haven't tried to paint on ce like this yet. (for testing I use an emulator, since oploading to my device takes ages)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
RE: Re: ExcludeClipRect and other platforms
« Reply #8 on: September 18, 2007, 03:05:06 am »
About WinCE it is like as Win32 i feel its compatible,
If you like, We can return to the topic, i see ExcludeClipRect in wincontrol.inc in

procedure TWinControl.PaintHandler(var TheMessage: TLMPaint);

Code: [Select]

    if not ControlsNeedsClipping then begin
      //DebugLn('[TWinControl.PaintHandler] ',DbgSName(Self),' no clipping ...');
      PaintWindow(DC)
    end else
    begin
      SaveIndex := SaveDC(DC);
      Clip := SimpleRegion;
      for I := 0 to FControls.Count - 1 do begin
        CurControl:=TControl(FControls[I]);
        if ControlMustBeClipped(CurControl) then
          with CurControl do begin
            //DebugLn('TWinControl.PaintHandler Exclude Child ',DbgSName(Self),' Control=',DbgSName(CurControl),'(',dbgs(CurControl.BoundsRect),')');
            Clip := ExcludeClipRect(DC, Left, Top, Left + Width, Top + Height);
            if Clip = NullRegion then Break;
          end;
      end;      


PaintHandler  Clip the rect of Child Graph Controls it then paint the window PaintWindow

Code: [Select]

procedure TWinControl.EraseBackground(DC: HDC);
var
  ARect: TRect;
begin
  if DC=0 then exit;
  ARect:=Rect(0,0,Width,Height);
  FillRect(DC,ARect,Brush.Handle)
end;



In this function also must Clip the rect of Controls before FillRect, this will  remove flicker, but that can make slow painting, or not work in GTK, and some Graph controls depend on the EraseBackground to paint it self, (maybe can add csClipRect to Control.ControlStyle)

This problem also found in Delphi and i always inherit painting background to remove painting it, and paint the FillRect in the Paint() method (it is happened after clipping the Controls)

 
I mention Graph controls not All controls because WinControls already clipped by the system if WS_CLIPCHILDREN used

 

TinyPortal © 2005-2018