mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-10 08:34:06 +02:00
Add tooltip to seek bar in video player
This commit is contained in:
parent
8e162fe031
commit
05510d7bc1
video
@ -6,29 +6,37 @@ sealed class SeekBar : ProgressBar{
|
||||
private readonly SolidBrush brushFore;
|
||||
private readonly SolidBrush brushHover;
|
||||
private readonly SolidBrush brushOverlap;
|
||||
private readonly SolidBrush brushBack;
|
||||
|
||||
public SeekBar(){
|
||||
brushFore = new SolidBrush(Color.White);
|
||||
brushHover = new SolidBrush(Color.White);
|
||||
brushOverlap = new SolidBrush(Color.White);
|
||||
brushBack = new SolidBrush(Color.White);
|
||||
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
}
|
||||
|
||||
public double GetProgress(int clientX){
|
||||
return clientX/(Width-1.0);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e){
|
||||
if (brushFore.Color != ForeColor){
|
||||
brushFore.Color = ForeColor;
|
||||
brushHover.Color = Color.FromArgb(128, ForeColor);
|
||||
brushOverlap.Color = Color.FromArgb(80+ForeColor.R*11/16, 80+ForeColor.G*11/16, 80+ForeColor.B*11/16);
|
||||
brushBack.Color = Parent.BackColor;
|
||||
}
|
||||
|
||||
Rectangle rect = e.ClipRectangle;
|
||||
Point cursor = PointToClient(Cursor.Position);
|
||||
int width = rect.Width;
|
||||
int width = rect.Width-1;
|
||||
int progress = (int)(width*((double)Value/Maximum));
|
||||
|
||||
rect.Width = progress;
|
||||
rect.Height -= 1;
|
||||
e.Graphics.FillRectangle(brushFore, rect);
|
||||
|
||||
if (cursor.X >= 0 && cursor.Y >= 0 && cursor.X <= width && cursor.Y <= rect.Height){
|
||||
@ -42,6 +50,17 @@ protected override void OnPaint(PaintEventArgs e){
|
||||
e.Graphics.FillRectangle(brushHover, rect);
|
||||
}
|
||||
}
|
||||
|
||||
rect.X = width;
|
||||
rect.Width = 1;
|
||||
rect.Height += 1;
|
||||
e.Graphics.FillRectangle(brushBack, rect);
|
||||
|
||||
rect.X = 0;
|
||||
rect.Y = rect.Height-1;
|
||||
rect.Width = width;
|
||||
rect.Height = 1;
|
||||
e.Graphics.FillRectangle(brushBack, rect);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing){
|
||||
@ -51,6 +70,7 @@ protected override void Dispose(bool disposing){
|
||||
brushFore.Dispose();
|
||||
brushHover.Dispose();
|
||||
brushOverlap.Dispose();
|
||||
brushBack.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
video/FormPlayer.Designer.cs
generated
4
video/FormPlayer.Designer.cs
generated
@ -83,10 +83,10 @@ private void InitializeComponent() {
|
||||
this.progressSeek.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.progressSeek.ForeColor = System.Drawing.Color.LimeGreen;
|
||||
this.progressSeek.Location = new System.Drawing.Point(9, 10);
|
||||
this.progressSeek.Margin = new System.Windows.Forms.Padding(9, 10, 9, 11);
|
||||
this.progressSeek.Margin = new System.Windows.Forms.Padding(9, 10, 8, 10);
|
||||
this.progressSeek.Maximum = 5000;
|
||||
this.progressSeek.Name = "progressSeek";
|
||||
this.progressSeek.Size = new System.Drawing.Size(62, 13);
|
||||
this.progressSeek.Size = new System.Drawing.Size(63, 14);
|
||||
this.progressSeek.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
|
||||
this.progressSeek.TabIndex = 0;
|
||||
this.progressSeek.MouseDown += new System.Windows.Forms.MouseEventHandler(this.progressSeek_MouseDown);
|
||||
|
@ -49,6 +49,15 @@ public FormPlayer(IntPtr handle, int volume, string url, string token){
|
||||
|
||||
trackBarVolume.Value = volume; // changes player volume too if non-default
|
||||
|
||||
labelTooltip.AttachTooltip(progressSeek, true, args => {
|
||||
IWMPMedia media = Player.currentMedia;
|
||||
int progress = (int)(media.duration*progressSeek.GetProgress(args.X));
|
||||
|
||||
Marshal.ReleaseComObject(media);
|
||||
|
||||
return $"{(progress/60).ToString("00")}:{(progress%60).ToString("00")}";
|
||||
});
|
||||
|
||||
Application.AddMessageFilter(new MessageFilter(this));
|
||||
}
|
||||
|
||||
@ -158,7 +167,7 @@ private void progressSeek_MouseDown(object sender, MouseEventArgs e){
|
||||
IWMPMedia media = Player.currentMedia;
|
||||
IWMPControls controls = Player.controls;
|
||||
|
||||
controls.currentPosition = media.duration*progressSeek.PointToClient(Cursor.Position).X/progressSeek.Width;
|
||||
controls.currentPosition = media.duration*progressSeek.GetProgress(progressSeek.PointToClient(Cursor.Position).X);
|
||||
|
||||
Marshal.ReleaseComObject(media);
|
||||
Marshal.ReleaseComObject(controls);
|
||||
|
Loading…
Reference in New Issue
Block a user