Recent

Author Topic: How to prevent image lag when moving panels around ??  (Read 4673 times)

Josh

  • Hero Member
  • *****
  • Posts: 1274
How to prevent image lag when moving panels around ??
« on: September 12, 2017, 12:01:47 am »
Hi

just been experimenting with re_sizing and moving panels around the screen, but if I move them at any speed I get a screen update lag isssue.

I have used setbounds when updating any panels position/size to minimize updates.

I have doublebuffered on for form and panels

Placing Application.processmessages; after updating the panels positions helps; but does not eliminate.
Removing the background TImage drastically helps; but does not eliminate also

Is there some other technique that can help?
« Last Edit: September 12, 2017, 12:05:01 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: How to prevent image lag when moving panels around ??
« Reply #1 on: September 12, 2017, 04:24:02 am »
There's not really any way to completely eliminate the "trailing effect". The window simply can't redraw itself fast enough. Just one of those things that comes with GDI software rendering.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to prevent image lag when moving panels around ??
« Reply #2 on: September 12, 2017, 09:19:02 am »
that looks to me like miscalculated region/rect update, I usually see that effect when my painting procedure is a bit smaller than the invalidated rectangle or the window is bussy and does not refresh it self at all forcing windows to draw the cached image instead. If your application is processing heavy try to move the processing to a thread or call the form's update method once a while and see if that helps.
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

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: How to prevent image lag when moving panels around ??
« Reply #3 on: September 12, 2017, 11:18:53 am »
Hi
Thanks for the feedback, I think you have confirmed that the issue is not something that can be easily solved, if at all.

I experimented adding a timer, that called form update only when a panel is moving/resizing at an interval of 20; this had some improvement.

I may have to go back to forms; but main issue I had with form was that I want to keep the child forms within the screen bounds of the main form, if they exceed then to increase the main forms dimensions to suit. Its just an experiment to create a basic 'scaleable desktop environment' within a main form.

So some re-thinking required......
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to prevent image lag when moving panels around ??
« Reply #4 on: September 12, 2017, 02:43:12 pm »
Hi
Thanks for the feedback, I think you have confirmed that the issue is not something that can be easily solved, if at all.
It is expected yes, mostly because of the way that windows handles refreshing. The form creates a region that needs to refresh that excludes the rectangles of the child TWinControls (panels, tedits, scrollbox, etc) expecting that those control will receive their own refresh message and draw them self after the current paint operation is finished. As you said you are moving a panel but I'm thinking that you do not call invalidate after each move of the panel. This should force the form to recalculate the region to paint after each move and probably introduce flickering in the process
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

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: How to prevent image lag when moving panels around ??
« Reply #5 on: September 12, 2017, 05:47:34 pm »
Hi Tazz,

I have tried invalidate,update, application.processmessages when ever the panel ordinates have changed or its dimension have changed, and always get a screen update lag.

I have never played with GL, so wondering if a GL component exists where it would take standard lcl components and work, as I think that GL would solve the issue, but suspect I will end up with other issues in the process.

So I am doing some research into what I can expect if I go and try that approach.

At the moment it is not for anything in particular, but have a few days free and thought I would spend the time expanding my knowledge on some ideas and areas that I have not used before....

Thanks again for your input. As I thin if I try the GL route I will have many more questions to fire at the community. :)
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to prevent image lag when moving panels around ??
« Reply #6 on: September 12, 2017, 06:16:10 pm »
Hi Tazz,

I have tried invalidate,update, application.processmessages when ever the panel ordinates have changed or its dimension have changed, and always get a screen update lag.
bammer I was hopping that would help. I'll try to create a small sample application that demonstrates the problem and see if I get something out of it.
I have never played with GL, so wondering if a GL component exists where it would take standard lcl components and work, as I think that GL would solve the issue, but suspect I will end up with other issues in the process.

So I am doing some research into what I can expect if I go and try that approach.

At the moment it is not for anything in particular, but have a few days free and thought I would spend the time expanding my knowledge on some ideas and areas that I have not used before....

Thanks again for your input. As I thin if I try the GL route I will have many more questions to fire at the community. :)
GL you mean opengl? Isn't this a bit like using a cannon to swat a fly? In any case there are a number of opengl libraries out there that you can use. Lately I'm playing around with GLScene my self which seems to have some standard controls that can be used inside the opengl I haven't used them yet as I'm more focused on the geometry of things at the moment.
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

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to prevent image lag when moving panels around ??
« Reply #7 on: September 12, 2017, 06:40:47 pm »
I failed in replicating the problem on my old computer!!

Here is the code I used:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Image1: TImage;
  16.     Panel1: TPanel;
  17.     procedure Image1Click(Sender: TObject);
  18.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  19.       Shift: TShiftState; X, Y: Integer);
  20.     procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
  21.       );
  22.     procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  23.       Shift: TShiftState; X, Y: Integer);
  24.   private
  25.     sx, sy: Integer;
  26.   public
  27.  
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TForm1 }
  38.  
  39. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  40.   Shift: TShiftState; X, Y: Integer);
  41. var
  42.   panel: TPanel absolute Sender;
  43. begin
  44.   if Sender is TPanel then
  45.   begin
  46.     panel.Tag := 1;
  47.     sx := x;
  48.     sy := y;
  49.   end;
  50. end;
  51.  
  52. procedure TForm1.Image1Click(Sender: TObject);
  53. begin
  54.  
  55. end;
  56.  
  57. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  58.   Y: Integer);
  59. var
  60.   dx, dy: Integer;
  61.   panel: TPanel absolute Sender;
  62. begin
  63.   if Sender is TPanel then
  64.   begin
  65.     if panel.Tag = 1 then
  66.     begin
  67.       dx := x-sx;
  68.       dy := y-sy;
  69.       panel.Left := panel.Left + dx;
  70.       panel.Top := panel.Top + dy;
  71.     end;
  72.   end;
  73. end;
  74.  
  75. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  76.   Shift: TShiftState; X, Y: Integer);
  77. var
  78.   panel: TPanel absolute Sender;
  79. begin
  80.   if Sender is TPanel then
  81.     panel.Tag := 0;
  82. end;
  83.  
  84. end.

I think the image you are using is too big, maybe?
I assumed you are using Windows?
What bit depths do you have in your desktop settings?
Can you provide a small example that we can test?

I most likely would do the background painting myself, not using TImage. In addition to that I would bypass the WM_ERASEBKGND message, it is not needed since the image covers everything.

Edit:
Hold a second, the image you provided has a bad area that is bigger than the panel you are moving. Is that another panel? if so, then it is that panel that is not getting painted, not the form.
« Last Edit: September 12, 2017, 07:03:06 pm by engkin »

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: How to prevent image lag when moving panels around ??
« Reply #8 on: September 12, 2017, 08:19:42 pm »
Hi engkin

I have a form
with 2 primary panels
Top Panel ( where menus etc to go)
Main Panel ( where all other panels and background timage is placed).

This was only a test, I was going to have the form be a borderless form, and the top panel to simulate these controls, the main panel can be streched to increase the overall size of the form, and the panels with in the mainpanel can be stretched and moved about, when they are moved beyound the bounds of main panel, the main panel is increased but not the form which then creates the scroll bars to navigate around the new area.

I'll create a sample project, I will need to remove some graphics and components I have added on for testing..

« Last Edit: September 12, 2017, 08:23:36 pm by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: How to prevent image lag when moving panels around ??
« Reply #9 on: September 12, 2017, 11:03:16 pm »
Hi

Just try to set panel's properties, BevelInner and BevelOuter to bvNone.

Normally, the "Lag" you see is now off. A Bug with contours drawing ?

Cheers

 

TinyPortal © 2005-2018