[Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
I am trying to use a TProgressbar to display the position of a playing
video. This works OK while playing.

Now I want to reposition the video by clicking on the progress bar and
it does work, but the bar progress to the new position when clicking
is really slow....

When I click the bar the X position is read in the MouseUp event and
the Video time value is calculated as the correspondinmg number of
milliseconds as used by the VLC player component.
Then the progressbar and the video are repositioned by setting their
position properties to this value.

What happens on screen is that the video *immediately* jumps to the
wanted position and continues playing but the progress bar only
*slowly* advances towards the playing point.
For a jump from the start of the video until near the end it takes
almost 3 seconds to complete.

Why is the TProgressBar doing this when the TTrackBar I used before
displays an instant move?

(I can't use the TTrackBar because of other issues with it)

Using Lazarus 2.0.0 32 bit and fpc 3.0.4 on Windows 7 x64 Pro.

--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
On 15.05.2019 13:34, Bo Berglund via lazarus wrote:
> Why is the TProgressBar doing this when the TTrackBar I used before displays an instant move?

Because WinAPI developers wanted it so - the drawing of TProgressBar is
fully in charge of the OS.

Ondrej

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
On Wed, 15 May 2019 13:38:19 +0200, Ondrej Pokorny via lazarus
<[hidden email]> wrote:

>On 15.05.2019 13:34, Bo Berglund via lazarus wrote:
>> Why is the TProgressBar doing this when the TTrackBar I used before displays an instant move?
>
>Because WinAPI developers wanted it so - the drawing of TProgressBar is
>fully in charge of the OS.
>

I feared as much...
So is there an alternate control I can use to visualize the position
in the video, which does not react so slowly?


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 15 May 2019 13:38:19 +0200, Ondrej Pokorny via lazarus
<[hidden email]> wrote:

>Because WinAPI developers wanted it so - the drawing of TProgressBar is
>fully in charge of the OS.

Strangely just discovered that the progressbar is painted "fast
enough" if I click a position towards the lower side of the current
position!

So start and click towards the end (max) - it slowly paints the bar.
Then click towards the start (min) - it *immediately* paints it
correctly.

There *must* be a way to enforce the latter paint method also for
positive moves....

I really do not want to create a panel child to implement this
behaviour unless I am really forced to....


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
On 15.05.2019 17:11, Bo Berglund via lazarus wrote:

> On Wed, 15 May 2019 13:38:19 +0200, Ondrej Pokorny via lazarus
> <[hidden email]> wrote:
>
>> Because WinAPI developers wanted it so - the drawing of TProgressBar is
>> fully in charge of the OS.
> Strangely just discovered that the progressbar is painted "fast
> enough" if I click a position towards the lower side of the current
> position!
>
> So start and click towards the end (max) - it slowly paints the bar.
> Then click towards the start (min) - it *immediately* paints it
> correctly.
>
> There *must* be a way to enforce the latter paint method also for
> positive moves....

Try to set DoubleBuffered:=True. That should disable all possible OS
painting animations.


> I really do not want to create a panel child to implement this
> behaviour unless I am really forced to....

That's what I would do. (But not a panel child but a TGraphicControl
descendant.)

Ondrej

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
I suggest to use ATScrollbar from ATFlatControls, but it needs the option for fast move- I can easily add it soon.


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am Mi., 15. Mai 2019, 17:11:
On Wed, 15 May 2019 13:38:19 +0200, Ondrej Pokorny via lazarus
<[hidden email]> wrote:

>Because WinAPI developers wanted it so - the drawing of TProgressBar is
>fully in charge of the OS.

Strangely just discovered that the progressbar is painted "fast
enough" if I click a position towards the lower side of the current
position!

So start and click towards the end (max) - it slowly paints the bar.
Then click towards the start (min) - it *immediately* paints it
correctly.

There *must* be a way to enforce the latter paint method also for
positive moves....

I really do not want to create a panel child to implement this
behaviour unless I am really forced to....

One possible workaround I found (not tested) is this:

=== code begin ===

YourProgressbar.Position := YourTarget;
YourProgressbar.Position := Your Target - 1;
YourProgressbar.Position := YourTarget;

=== code end ===

You first tell the progress bar your new desired target value (which triggers a slow animation), then you go one step back (which will enforce a fast redraw) and then to the target again (which again will be a slow animation, but shouldn't be that slow with only one point difference).

Note: I currently don't know whether the property on TProgressBar is Position or Value. It's been a while since I last used one ;) 

Note 2: you can put similar code into the click handler, though there without the first step probably. 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 15 May 2019 17:13:48 +0200, Ondrej Pokorny via lazarus
<[hidden email]> wrote:

>> I really do not want to create a panel child to implement this
>> behaviour unless I am really forced to....
>
>That's what I would do. (But not a panel child but a TGraphicControl
>descendant.)

After thinking a bit on the difference between going forwards and
backwards, I did this test:

MouseUp event used to reposition the video playing pos:

procedure TfrmMain.pgbProgressMouseUp(Sender: TObject; Button:
TMouseButton;  Shift: TShiftState; X, Y: Integer);
{Progressbar set to seconds resolution rather than milisec}
var
  Pos: double;
begin
  Pos := double(X) / pgbProgress.Width * (pgbProgress.Max -
pgbProgress.Min);
  vlcPlayer.SetVideoPosInMs(Round(Pos) * 1000);
end;

The player's TimeChanged event updates the progress bar:

procedure TfrmMain.vlcPlayerMediaPlayerTimeChanged(Sender: TObject;
time: Int64);
var
  P: int64;
begin
    P := vlcPlayer.GetVideoPosInMs();
    P := P div 1000; //Progressbar is in sec rather than ms
    pgbProgress.Position := P + 1;
    pgbProgress.Position := P ;
  end;
end;

Notice that I am now first setting the position 1 higher than
requested and then immediately backing down by 1.

AND IT WORKS!!!!!

Now the progress bar immediately jumps to the wanted position without
the "smooth scroll" that MS implemented!


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TProgressbar moves slowly, is there a hidden setting for faster response?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 15 May 2019 17:20:04 +0200, Sven Barth via lazarus
<[hidden email]> wrote:

>One possible workaround I found (not tested) is this:
>
>=== code begin ===
>
>YourProgressbar.Position := YourTarget;
>YourProgressbar.Position := Your Target - 1;
>YourProgressbar.Position := YourTarget;
>
>=== code end ===
>
>You first tell the progress bar your new desired target value (which
>triggers a slow animation), then you go one step back (which will enforce a
>fast redraw) and then to the target again (which again will be a slow
>animation, but shouldn't be that slow with only one point difference).
>
>Note: I currently don't know whether the property on TProgressBar is
>Position or Value. It's been a while since I last used one ;)
>
>Note 2: you can put similar code into the click handler, though there
>without the first step probably.
>

Before I saw this reply I had already tested successfully this
structure:

YourProgressbar.Position := YourTarget + 1;
YourProgressbar.Position := YourTarget;

And it really does work, no longer the animated slow move...


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus