mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
New battery slider
This commit is contained in:
@@ -52,11 +52,6 @@ namespace CustomControls
|
||||
}
|
||||
|
||||
|
||||
public class RTrackBar : TrackBar
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class RComboBox : ComboBox
|
||||
{
|
||||
private Color borderColor = Color.Gray;
|
||||
@@ -73,6 +68,8 @@ namespace CustomControls
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Color buttonColor = Color.FromArgb(255,230, 230, 230);
|
||||
[DefaultValue(typeof(Color), "230, 230, 230")]
|
||||
public Color ButtonColor
|
||||
|
||||
35
app/Settings.Designer.cs
generated
35
app/Settings.Designer.cs
generated
@@ -40,12 +40,12 @@ namespace GHelper
|
||||
pictureMatrix = new PictureBox();
|
||||
labelMatrix = new Label();
|
||||
panelBattery = new Panel();
|
||||
sliderBattery = new WinFormsSliderBar.Slider();
|
||||
labelModel = new Label();
|
||||
labelVersion = new Label();
|
||||
labelBattery = new Label();
|
||||
pictureBattery = new PictureBox();
|
||||
labelBatteryTitle = new Label();
|
||||
trackBattery = new TrackBar();
|
||||
panelFooter = new Panel();
|
||||
buttonQuit = new RButton();
|
||||
checkStartup = new CheckBox();
|
||||
@@ -93,7 +93,6 @@ namespace GHelper
|
||||
((System.ComponentModel.ISupportInitialize)pictureMatrix).BeginInit();
|
||||
panelBattery.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBattery).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)trackBattery).BeginInit();
|
||||
panelFooter.SuspendLayout();
|
||||
panelPerformance.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)picturePerf).BeginInit();
|
||||
@@ -237,12 +236,12 @@ namespace GHelper
|
||||
//
|
||||
panelBattery.AutoSize = true;
|
||||
panelBattery.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
||||
panelBattery.Controls.Add(sliderBattery);
|
||||
panelBattery.Controls.Add(labelModel);
|
||||
panelBattery.Controls.Add(labelVersion);
|
||||
panelBattery.Controls.Add(labelBattery);
|
||||
panelBattery.Controls.Add(pictureBattery);
|
||||
panelBattery.Controls.Add(labelBatteryTitle);
|
||||
panelBattery.Controls.Add(trackBattery);
|
||||
panelBattery.Dock = DockStyle.Top;
|
||||
panelBattery.Location = new Point(10, 926);
|
||||
panelBattery.Margin = new Padding(8);
|
||||
@@ -251,6 +250,17 @@ namespace GHelper
|
||||
panelBattery.Size = new Size(810, 163);
|
||||
panelBattery.TabIndex = 34;
|
||||
//
|
||||
// sliderBattery
|
||||
//
|
||||
sliderBattery.Location = new Point(16, 70);
|
||||
sliderBattery.Max = 100;
|
||||
sliderBattery.Min = 50;
|
||||
sliderBattery.Name = "sliderBattery";
|
||||
sliderBattery.Size = new Size(772, 40);
|
||||
sliderBattery.TabIndex = 39;
|
||||
sliderBattery.Text = "sliderBattery";
|
||||
sliderBattery.Value = 80;
|
||||
//
|
||||
// labelModel
|
||||
//
|
||||
labelModel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@@ -307,22 +317,6 @@ namespace GHelper
|
||||
labelBatteryTitle.TabIndex = 34;
|
||||
labelBatteryTitle.Text = "Battery Charge Limit";
|
||||
//
|
||||
// trackBattery
|
||||
//
|
||||
trackBattery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
trackBattery.LargeChange = 10;
|
||||
trackBattery.Location = new Point(20, 52);
|
||||
trackBattery.Margin = new Padding(8, 4, 8, 4);
|
||||
trackBattery.Maximum = 100;
|
||||
trackBattery.Minimum = 50;
|
||||
trackBattery.Name = "trackBattery";
|
||||
trackBattery.Size = new Size(766, 90);
|
||||
trackBattery.SmallChange = 5;
|
||||
trackBattery.TabIndex = 33;
|
||||
trackBattery.TickFrequency = 10;
|
||||
trackBattery.TickStyle = TickStyle.TopLeft;
|
||||
trackBattery.Value = 100;
|
||||
//
|
||||
// panelFooter
|
||||
//
|
||||
panelFooter.AutoSize = true;
|
||||
@@ -1033,7 +1027,6 @@ namespace GHelper
|
||||
panelBattery.ResumeLayout(false);
|
||||
panelBattery.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBattery).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)trackBattery).EndInit();
|
||||
panelFooter.ResumeLayout(false);
|
||||
panelFooter.PerformLayout();
|
||||
panelPerformance.ResumeLayout(false);
|
||||
@@ -1069,7 +1062,6 @@ namespace GHelper
|
||||
private Label labelBattery;
|
||||
private PictureBox pictureBattery;
|
||||
private Label labelBatteryTitle;
|
||||
private TrackBar trackBattery;
|
||||
private Panel panelFooter;
|
||||
private RButton buttonQuit;
|
||||
private CheckBox checkStartup;
|
||||
@@ -1118,5 +1110,6 @@ namespace GHelper
|
||||
private RButton buttonFans;
|
||||
private Label labelMidFan;
|
||||
private Label labelModel;
|
||||
private WinFormsSliderBar.Slider sliderBattery;
|
||||
}
|
||||
}
|
||||
@@ -115,11 +115,9 @@ namespace GHelper
|
||||
button120Hz.MouseMove += Button120Hz_MouseHover;
|
||||
button120Hz.MouseLeave += ButtonScreen_MouseLeave;
|
||||
|
||||
trackBattery.ValueChanged += TrackBattery_ValueChanged;
|
||||
sliderBattery.ValueChanged += SliderBattery_ValueChanged;
|
||||
Program.trayIcon.MouseMove += TrayIcon_MouseMove;
|
||||
|
||||
//buttonStandard.Image = (Image)(new Bitmap(buttonStandard.Image, new Size(16, 16)));
|
||||
|
||||
aTimer = new System.Timers.Timer(500);
|
||||
aTimer.Elapsed += OnTimedEvent;
|
||||
|
||||
@@ -146,10 +144,9 @@ namespace GHelper
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void TrackBattery_ValueChanged(object? sender, EventArgs e)
|
||||
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
SetBatteryChargeLimit(trackBattery.Value);
|
||||
SetBatteryChargeLimit(sliderBattery.Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -362,7 +359,8 @@ namespace GHelper
|
||||
{
|
||||
format1 = "H:mm";
|
||||
format2 = "";
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
format1 = "h:mm";
|
||||
format2 = "tt";
|
||||
@@ -372,7 +370,8 @@ namespace GHelper
|
||||
{
|
||||
format1 = format1.Replace(":", " ");
|
||||
matrixTick = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
matrixTick++;
|
||||
}
|
||||
@@ -936,7 +935,8 @@ namespace GHelper
|
||||
|
||||
labelPerf.Text = "Performance Mode+";
|
||||
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
labelPerf.Text = "Performance Mode";
|
||||
}
|
||||
@@ -1324,8 +1324,10 @@ namespace GHelper
|
||||
|
||||
if (limit < 40 || limit > 100) return;
|
||||
|
||||
//Debug.WriteLine(limit);
|
||||
|
||||
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
|
||||
trackBattery.Value = limit;
|
||||
sliderBattery.Value = limit;
|
||||
|
||||
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
|
||||
Program.config.setConfig("charge_limit", limit);
|
||||
|
||||
168
app/Slider.cs
Normal file
168
app/Slider.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace WinFormsSliderBar
|
||||
{
|
||||
public static class GraphicsExtensions
|
||||
{
|
||||
public static void DrawCircle(this Graphics g, Pen pen,
|
||||
float centerX, float centerY, float radius)
|
||||
{
|
||||
g.DrawEllipse(pen, centerX - radius, centerY - radius,
|
||||
radius + radius, radius + radius);
|
||||
}
|
||||
|
||||
public static void FillCircle(this Graphics g, Brush brush,
|
||||
float centerX, float centerY, float radius)
|
||||
{
|
||||
g.FillEllipse(brush, centerX - radius, centerY - radius,
|
||||
radius + radius, radius + radius);
|
||||
}
|
||||
}
|
||||
|
||||
public class Slider : Control
|
||||
{
|
||||
private float _radius;
|
||||
private PointF _thumbPos;
|
||||
private SizeF _barSize;
|
||||
private PointF _barPos;
|
||||
|
||||
private int _step = 5;
|
||||
|
||||
public Color accentColor = Color.FromArgb(255, 58, 174, 239);
|
||||
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
public Slider()
|
||||
{
|
||||
// This reduces flicker
|
||||
DoubleBuffered = true;
|
||||
}
|
||||
|
||||
private int _min = 0;
|
||||
public int Min
|
||||
{
|
||||
get => _min;
|
||||
set
|
||||
{
|
||||
_min = value;
|
||||
RecalculateParameters();
|
||||
}
|
||||
}
|
||||
|
||||
private int _max = 100;
|
||||
public int Max
|
||||
{
|
||||
get => _max;
|
||||
set
|
||||
{
|
||||
_max = value;
|
||||
RecalculateParameters();
|
||||
}
|
||||
}
|
||||
|
||||
private int _value = 50;
|
||||
public int Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
|
||||
value = (int)Math.Round(value / (float)_step) * _step;
|
||||
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||
RecalculateParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
Brush brushAccent = new SolidBrush(accentColor);
|
||||
Brush brushEmpty = new SolidBrush(Color.Gray);
|
||||
Brush brushBorder = new SolidBrush(Color.White);
|
||||
|
||||
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
e.Graphics.FillRectangle(brushEmpty,
|
||||
_barPos.X, _barPos.Y, _barSize.Width, _barSize.Height);
|
||||
e.Graphics.FillRectangle(brushAccent,
|
||||
_barPos.X, _barPos.Y, _thumbPos.X - _barPos.X, _barSize.Height);
|
||||
|
||||
e.Graphics.FillCircle(brushBorder, _thumbPos.X, _thumbPos.Y, _radius);
|
||||
e.Graphics.FillCircle(brushAccent, _thumbPos.X, _thumbPos.Y, 0.7f * _radius);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
RecalculateParameters();
|
||||
}
|
||||
|
||||
private void RecalculateParameters()
|
||||
{
|
||||
_radius = 0.45F * ClientSize.Height;
|
||||
_barSize = new SizeF(ClientSize.Width - 4 * _radius, ClientSize.Height*0.15F);
|
||||
_barPos = new PointF(_radius, (ClientSize.Height - _barSize.Height) / 2);
|
||||
_thumbPos = new PointF(
|
||||
_barSize.Width / (Max - Min) * (Value-Min) + _barPos.X,
|
||||
_barPos.Y + 0.5f * _barSize.Height);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
bool _moving = false;
|
||||
SizeF _delta;
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
||||
// Difference between tumb and mouse position.
|
||||
_delta = new SizeF(e.Location.X - _thumbPos.X, e.Location.Y - _thumbPos.Y);
|
||||
if (_delta.Width * _delta.Width + _delta.Height * _delta.Height <= _radius * _radius)
|
||||
{
|
||||
// Clicking inside thumb.
|
||||
_moving = true;
|
||||
}
|
||||
|
||||
_calculateValue(e);
|
||||
|
||||
}
|
||||
|
||||
private void _calculateValue(MouseEventArgs e)
|
||||
{
|
||||
float thumbX = e.Location.X; // - _delta.Width;
|
||||
if (thumbX < _barPos.X)
|
||||
{
|
||||
thumbX = _barPos.X;
|
||||
}
|
||||
else if (thumbX > _barPos.X + _barSize.Width)
|
||||
{
|
||||
thumbX = _barPos.X + _barSize.Width;
|
||||
}
|
||||
Value = (int)Math.Round(Min + (thumbX - _barPos.X) * (Max - Min) / _barSize.Width);
|
||||
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_moving)
|
||||
{
|
||||
_calculateValue(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
_moving = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user