mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-13 17:34:08 +02:00
Add a hover effect to video player seek bar
This commit is contained in:
parent
2fcf3604a8
commit
9074cdf340
@ -1,32 +1,58 @@
|
||||
using System.Drawing;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TweetDuck.Video.Controls{
|
||||
sealed class SeekBar : ProgressBar{
|
||||
private readonly SolidBrush brush;
|
||||
private readonly SolidBrush brushFore;
|
||||
private readonly SolidBrush brushHover;
|
||||
private readonly SolidBrush brushOverlap;
|
||||
|
||||
public SeekBar(){
|
||||
brush = new SolidBrush(Color.White);
|
||||
brushFore = new SolidBrush(Color.White);
|
||||
brushHover = new SolidBrush(Color.White);
|
||||
brushOverlap = new SolidBrush(Color.White);
|
||||
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e){
|
||||
if (brush.Color != ForeColor){
|
||||
brush.Color = ForeColor;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Rectangle rect = e.ClipRectangle;
|
||||
rect.Width = (int)(rect.Width*((double)Value/Maximum));
|
||||
e.Graphics.FillRectangle(brush, rect);
|
||||
Point cursor = PointToClient(Cursor.Position);
|
||||
int width = rect.Width;
|
||||
int progress = (int)(width*((double)Value/Maximum));
|
||||
|
||||
rect.Width = progress;
|
||||
e.Graphics.FillRectangle(brushFore, rect);
|
||||
|
||||
if (cursor.X >= 0 && cursor.Y >= 0 && cursor.X <= width && cursor.Y <= rect.Height){
|
||||
if (progress >= cursor.X){
|
||||
rect.Width = cursor.X;
|
||||
e.Graphics.FillRectangle(brushOverlap, rect);
|
||||
}
|
||||
else{
|
||||
rect.X = progress;
|
||||
rect.Width = cursor.X-rect.X;
|
||||
e.Graphics.FillRectangle(brushHover, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing){
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing){
|
||||
brush.Dispose();
|
||||
brushFore.Dispose();
|
||||
brushHover.Dispose();
|
||||
brushOverlap.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user