[SOLVED] Slider TPanel lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2021-11-14 19:51 Hello, I wrote a slider using TPanel components, I'm stuck at the end of the slider does not show 100% how I can do it. How to modify the code so that you can assign a final value, e.g. 100, 200 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,  StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    ProgressBar1: TProgressBar;    SeekBarSlider: TPanel;    SeekBar: TPanel;    SeekBarFrame: TPanel;  procedure SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);    procedure SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);  private   public   end; var  Form1: TForm1;  Seeking: Boolean;  SeekMouseX, SeekBaseX, MaxPos: Integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var MaxPos: Integer;begin  if not SeekBarSlider.Visible then Exit;  dec(X, SeekBarSlider.Width DIV 2);  MaxPos := SeekBarFrame.ClientWidth - SeekBarSlider.Width;end; procedure TForm1.SeekBarMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var P: TPoint;begin  P := SeekBarFrame.ScreenToClient(SeekBar.ClientToScreen(Point(X, Y)));  SeekBarFrameMouseDown(Sender, Button, Shift, P.X, P.Y);end; procedure TForm1.SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if Button <> mbLeft then Exit;  Seeking := True;  SeekBarSlider.BevelInner := bvLowered;  SeekMouseX := X;  SeekBaseX := SeekBarSlider.Left;end; procedure TForm1.SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);var NewX, MaxX: Integer;begin  if not (ssLeft in Shift) OR not (Seeking) then Exit;  NewX := X - SeekMouseX + SeekBarSlider.Left;  MaxX := SeekBarFrame.ClientWidth - SeekBarSlider.Width;  if NewX < 0 then NewX := 0;  if NewX > MaxX then NewX := MaxX;  SeekBarSlider.Left := NewX;     ProgressBar1.Position:= NewX;    Form1.Caption := IntToStr(NewX);end; procedure TForm1.SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var MaxPos: Integer;begin  if Button <> mbLeft then Exit;  Seeking := False;  SeekBarSlider.BevelInner := bvRaised;  MaxPos := SeekBarFrame.ClientWidth - SeekBarSlider.Width;end; end. ---------------------------------------------------------------------- Tony Stone · 2021-11-19 05:09 I played with your demo and came up with this. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,  StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    ProgressBar1: TProgressBar;    SeekBarSlider: TPanel;    SeekBar: TPanel;    SeekBarFrame: TPanel;  procedure SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);    procedure SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    function CalcProgress(Pos64, Max64: int64): integer;  private   public   end; var  Form1: TForm1;  Seeking: Boolean;  SeekMouseX, SeekBaseX, MaxPos: Integer;  newx, maxx, perc: Int64;  implementation {$R *.lfm} { TForm1 } procedure TForm1.SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer); begin  if not SeekBarSlider.Visible then Exit;  dec(X, SeekBarSlider.Width DIV 2);  //MaxPos := SeekBarFrame.ClientWidth - SeekBarSlider.Width;end; procedure TForm1.SeekBarMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var P: TPoint;begin  P := SeekBarFrame.ScreenToClient(SeekBar.ClientToScreen(Point(X, Y)));  SeekBarFrameMouseDown(Sender, Button, Shift, P.X, P.Y);end; procedure TForm1.SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if Button <> mbLeft then Exit;  Seeking := True;  SeekBarSlider.BevelInner := bvLowered;  SeekMouseX := X;  SeekBaseX := SeekBarSlider.Left;end; procedure TForm1.SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer); begin  if not (ssLeft in Shift) OR not (Seeking) then Exit;  NewX := X - SeekMouseX + SeekBarSlider.Left;  MaxX := SeekBarFrame.ClientWidth - SeekBarSlider.Width;  if NewX < 0 then NewX := 0;  if NewX > MaxX then NewX := MaxX;   SeekBarSlider.Left := NewX;    perc:=CalcProgress(newx,maxx);     ProgressBar1.Position:= (perc);    Form1.Caption := IntToStr(perc);   end; function TForm1.CalcProgress(Pos64, Max64: int64): integer;begin   Result := integer(Trunc((Pos64 / Max64) * 100)); end; procedure TForm1.SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer); begin  if Button <> mbLeft then Exit;  Seeking := False;  SeekBarSlider.BevelInner := bvRaised;  //MaxPos := SeekBarFrame.ClientWidth - SeekBarSlider.Width;end; end. ---------------------------------------------------------------------- Pe3s · 2021-11-19 09:23 @Tony Stone Thank you, I still have a question, it can be done so as to assign a final value, for example, the length of the film or music. ---------------------------------------------------------------------- Tony Stone · 2021-11-19 15:53 I'm not so sure I understand your question.  Give me a clear example and I'll try to help. ---------------------------------------------------------------------- Pe3s · 2021-11-19 16:44 I wanted to make a custom slider for a PasLIbVLC based program in this component OnMediaPlayerTimeChanged procedure responsible for moving the bar during playback and here there is a problem with the bar moving too fast. ---------------------------------------------------------------------- Tony Stone · 2021-11-19 20:00 Quote from: Pe3s on November 19, 2021, 05:44:14 pmI wanted to make a custom slider for a PasLIbVLC based program in this component OnMediaPlayerTimeChanged procedure responsible for moving the bar during playback and here there is a problem with the bar moving too fast. Ahh, I think I know what you are trying to do.  Give me a little bit.  I will use your demo and see if i can make something work.  So The progress bar can be representitive of 600 to mean 600 seconds for example?  Is that what you mean? ---------------------------------------------------------------------- Pe3s · 2021-11-19 20:48 The progress bar should adjust to the length of the movie. For example, if we use the ProgressBar component and use the properties of ProgressBar.Max: = PasLibVlcPlayer1.GetVideoLenInMs (); // The length of the movie and ProgressBar.Position: = PasLibVlcPlayer1.GetVideoPosInMs (); // Movie position I want to do something like that on my belt. I have included a second demo from ProgressBar for the visualization ---------------------------------------------------------------------- Tony Stone · 2021-11-20 00:04 try something like this.... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,  StdCtrls, Buttons, PasLibVlcPlayerUnit, vlc; type   { TForm1 }   TForm1 = class(TForm)  OpenDialog1: TOpenDialog;    PasLibVlcPlayer1: TPasLibVlcPlayer;    SeekBarSlider: TPanel;    SeekBar: TPanel;    SeekBarFrame: TPanel;  SpeedButton1: TSpeedButton;    SpeedButton2: TSpeedButton;    SpeedButton3: TSpeedButton;    SpeedButton4: TSpeedButton;     procedure PasLibVlcPlayer1MediaPlayerLengthChanged(Sender: TObject;    time: Int64);    procedure PasLibVlcPlayer1MediaPlayerTimeChanged(Sender: TObject;      time: Int64);    procedure SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);    procedure SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure SpeedButton1Click(Sender: TObject);    procedure SpeedButton2Click(Sender: TObject);    procedure SpeedButton3Click(Sender: TObject);    procedure SpeedButton4Click(Sender: TObject);  private   public   end; var  Form1: TForm1;  Seeking: Boolean;  SeekMouseX, SeekBaseX, MaxPos, TotalVideoPos, seekPerc, perc: Integer;  vidlenMS, NewX, MaxX, perc64: Int64; implementation {$R *.lfm} { TForm1 } procedure TForm1.SeekBarFrameMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if not SeekBarSlider.Visible then Exit;  dec(X, SeekBarSlider.Width DIV 2);end; procedure TForm1.PasLibVlcPlayer1MediaPlayerLengthChanged(Sender: TObject;  time: Int64);begin  TotalVideoPos := PasLibVlcPlayer1.GetVideoLenInMs();end; procedure TForm1.PasLibVlcPlayer1MediaPlayerTimeChanged(Sender: TObject;  time: Int64);begin  //SeekBarSlider.Left := PasLibVlcPlayer1.GetVideoPosInMs();end; procedure TForm1.SeekBarMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var P: TPoint;begin  P := SeekBarFrame.ScreenToClient(SeekBar.ClientToScreen(Point(X, Y)));  SeekBarFrameMouseDown(Sender, Button, Shift, P.X, P.Y);end; procedure TForm1.SeekBarSliderMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if Button <> mbLeft then Exit;  Seeking := True;  SeekBarSlider.BevelInner := bvLowered;  SeekMouseX := X;  SeekBaseX := SeekBarSlider.Left;end; procedure TForm1.SeekBarSliderMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  if not (ssLeft in Shift) OR not (Seeking) then Exit;  NewX := X - SeekMouseX + SeekBarSlider.Left;  MaxX := SeekBarFrame.ClientWidth - SeekBarSlider.Width;  if NewX < 0 then NewX := 0;  if NewX > MaxX then NewX := MaxX;  SeekBarSlider.Left := NewX;   vidlenMS:=PasLibVlcPlayer1.GetVideoLenInMs;  if NewX > 0 then begin    seekPerc:=(vidlenMS div MaxX) * NewX;  end;  Form1.Caption:='Length in MS: ' + IntToStr(vidlenMS) + '  Seek To:' + IntToStr(seekPerc)  + '   Percentage: ' + IntToStr(NewX);end; procedure TForm1.SeekBarSliderMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if Button <> mbLeft then Exit;  Seeking := False;  SeekBarSlider.BevelInner := bvRaised;  PasLibVlcPlayer1.SetVideoPosInMs(seekPerc);end; procedure TForm1.SpeedButton1Click(Sender: TObject);begin  if OpenDialog1.Execute then  begin    PasLibVlcPlayer1.Play(WideString(OpenDialog1.FileName));   end;end; procedure TForm1.SpeedButton2Click(Sender: TObject);begin  PasLibVlcPlayer1.Resume();end; procedure TForm1.SpeedButton3Click(Sender: TObject);begin  PasLibVlcPlayer1.Pause();end; procedure TForm1.SpeedButton4Click(Sender: TObject);begin  PasLibVlcPlayer1.Stop();end;   end.  at around line 110 where i set playback position you need to do the opposite in the actual time changed event to reposition your selector to the current play position. There is probably much better ways to go about this but I am not the guy to make those recommendations!  Hopefully this is what you were trying to do...? ---------------------------------------------------------------------- Pe3s · 2021-11-20 07:34 I don't understand how to reverse to get the current play position. To determine the current playback position is OnMediaPlayerTimeChanged SeekbarSlider.Left: = PasLibVlcPlayer1.GetVideoPosInMs (); But that doesn't work with this slider ---------------------------------------------------------------------- Tony Stone · 2021-11-20 14:48 Quote from: Pe3s on November 20, 2021, 08:34:58 amI don't understand how to reverse to get the current play position. To determine the current playback position is OnMediaPlayerTimeChanged SeekbarSlider.Left: = PasLibVlcPlayer1.GetVideoPosInMs (); But that doesn't work with this slider You need to do the same thing I did on line 110.  Except use current video position instead of slider newx.... Like I said there is probably better ways to do this. But try something like that and you may realize some issues and see a better way to go about it.  I am a total idiot with simple math as I get older so it took me a little bit to figure that out in the first place.  It's pretty simple though really...  Good luck. ---------------------------------------------------------------------- Pe3s · 2021-11-20 15:18 Napisalem cos takiego ale pojawiaja sie bledy Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PasLibVlcPlayer1MediaPlayerTimeChanged(Sender: TObject;  time: Int64);begin  SeekBarSlider.Left := (vidlenMS div MaxX) * PasLibVlcPlayer1.GetVideoPosInMs();end; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if PasLibVlcPlayer1.GetVideoPosInMs() > 0 then begin  SeekBarSlider.Left := (vidlenMS div MaxX) * PasLibVlcPlayer1.GetVideoPosInMs();end;  end; ---------------------------------------------------------------------- Tony Stone · 2021-11-20 15:22 Look what Jamie posted.  His little formula is correct, not what I said.  I'm not in front of a computer right now to test and do it myself. Sorry. ---------------------------------------------------------------------- Pe3s · 2021-11-20 16:08 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  vidlenPS := PasLibVlcPlayer1.GetVideoPosInMs();  SeekBarSlider.Left := MaxX * vidlenPS div vidlenMS; Error division by zero ---------------------------------------------------------------------- Pe3s · 2021-11-20 17:39 Thanks