mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
UI tweaks
This commit is contained in:
125
app/Settings.cs
125
app/Settings.cs
@@ -471,11 +471,8 @@ namespace GHelper
|
|||||||
|
|
||||||
public void SetVersionLabel(string label, bool update = false)
|
public void SetVersionLabel(string label, bool update = false)
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
labelVersion.Text = label;
|
||||||
{
|
if (update) labelVersion.ForeColor = colorTurbo;
|
||||||
labelVersion.Text = label;
|
|
||||||
if (update) labelVersion.ForeColor = colorTurbo;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -659,18 +656,12 @@ namespace GHelper
|
|||||||
|
|
||||||
public void FansInit()
|
public void FansInit()
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
if (fansForm != null && fansForm.Text != "") fansForm.InitAll();
|
||||||
{
|
|
||||||
if (fansForm != null && fansForm.Text != "") fansForm.InitAll();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GPUInit()
|
public void GPUInit()
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
if (fansForm != null && fansForm.Text != "") fansForm.InitGPU();
|
||||||
{
|
|
||||||
if (fansForm != null && fansForm.Text != "") fansForm.InitGPU();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FansToggle(int index = 0)
|
public void FansToggle(int index = 0)
|
||||||
@@ -764,12 +755,9 @@ namespace GHelper
|
|||||||
|
|
||||||
public void VisualiseAura()
|
public void VisualiseAura()
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
pictureColor.BackColor = Aura.Color1;
|
||||||
{
|
pictureColor2.BackColor = Aura.Color2;
|
||||||
pictureColor.BackColor = Aura.Color1;
|
pictureColor2.Visible = Aura.HasSecondColor();
|
||||||
pictureColor2.BackColor = Aura.Color2;
|
|
||||||
pictureColor2.Visible = Aura.HasSecondColor();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitMatrix()
|
public void InitMatrix()
|
||||||
@@ -1001,18 +989,19 @@ namespace GHelper
|
|||||||
if (gpuTemp.Length > 0) trayTip += "\nGPU" + gpuTemp + " " + HardwareControl.gpuFan;
|
if (gpuTemp.Length > 0) trayTip += "\nGPU" + gpuTemp + " " + HardwareControl.gpuFan;
|
||||||
if (battery.Length > 0) trayTip += "\n" + battery;
|
if (battery.Length > 0) trayTip += "\n" + battery;
|
||||||
|
|
||||||
Program.settingsForm.BeginInvoke(delegate
|
if (Program.settingsForm.IsHandleCreated)
|
||||||
{
|
Program.settingsForm.BeginInvoke(delegate
|
||||||
labelCPUFan.Text = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
|
{
|
||||||
labelGPUFan.Text = "GPU" + gpuTemp + " " + HardwareControl.gpuFan;
|
labelCPUFan.Text = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
|
||||||
if (HardwareControl.midFan is not null)
|
labelGPUFan.Text = "GPU" + gpuTemp + " " + HardwareControl.gpuFan;
|
||||||
labelMidFan.Text = "Mid " + HardwareControl.midFan;
|
if (HardwareControl.midFan is not null)
|
||||||
|
labelMidFan.Text = "Mid " + HardwareControl.midFan;
|
||||||
|
|
||||||
labelBattery.Text = battery;
|
labelBattery.Text = battery;
|
||||||
if (!batteryMouseOver && !batteryFullMouseOver) labelCharge.Text = charge;
|
if (!batteryMouseOver && !batteryFullMouseOver) labelCharge.Text = charge;
|
||||||
|
|
||||||
//panelPerformance.AccessibleName = labelPerf.Text + " " + trayTip;
|
//panelPerformance.AccessibleName = labelPerf.Text + " " + trayTip;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Program.trayIcon.Text = trayTip;
|
Program.trayIcon.Text = trayTip;
|
||||||
@@ -1027,52 +1016,56 @@ namespace GHelper
|
|||||||
|
|
||||||
public void ShowMode(int mode)
|
public void ShowMode(int mode)
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
buttonSilent.Activated = false;
|
||||||
|
buttonBalanced.Activated = false;
|
||||||
|
buttonTurbo.Activated = false;
|
||||||
|
buttonFans.Activated = false;
|
||||||
|
|
||||||
|
menuSilent.Checked = false;
|
||||||
|
menuBalanced.Checked = false;
|
||||||
|
menuTurbo.Checked = false;
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
{
|
{
|
||||||
buttonSilent.Activated = false;
|
case AsusACPI.PerformanceSilent:
|
||||||
buttonBalanced.Activated = false;
|
buttonSilent.Activated = true;
|
||||||
buttonTurbo.Activated = false;
|
menuSilent.Checked = true;
|
||||||
buttonFans.Activated = false;
|
break;
|
||||||
|
case AsusACPI.PerformanceTurbo:
|
||||||
menuSilent.Checked = false;
|
buttonTurbo.Activated = true;
|
||||||
menuBalanced.Checked = false;
|
menuTurbo.Checked = true;
|
||||||
menuTurbo.Checked = false;
|
break;
|
||||||
|
case AsusACPI.PerformanceBalanced:
|
||||||
switch (mode)
|
buttonBalanced.Activated = true;
|
||||||
{
|
menuBalanced.Checked = true;
|
||||||
case AsusACPI.PerformanceSilent:
|
break;
|
||||||
buttonSilent.Activated = true;
|
default:
|
||||||
menuSilent.Checked = true;
|
buttonFans.Activated = true;
|
||||||
break;
|
buttonFans.BorderColor = Modes.GetBase(mode) switch
|
||||||
case AsusACPI.PerformanceTurbo:
|
{
|
||||||
buttonTurbo.Activated = true;
|
AsusACPI.PerformanceSilent => colorEco,
|
||||||
menuTurbo.Checked = true;
|
AsusACPI.PerformanceTurbo => colorTurbo,
|
||||||
break;
|
_ => colorStandard,
|
||||||
case AsusACPI.PerformanceBalanced:
|
};
|
||||||
buttonBalanced.Activated = true;
|
break;
|
||||||
menuBalanced.Checked = true;
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
buttonFans.Activated = true;
|
|
||||||
buttonFans.BorderColor = Modes.GetBase(mode) switch
|
|
||||||
{
|
|
||||||
AsusACPI.PerformanceSilent => colorEco,
|
|
||||||
AsusACPI.PerformanceTurbo => colorTurbo,
|
|
||||||
_ => colorStandard,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetModeLabel(string modeText)
|
public void SetModeLabel(string modeText)
|
||||||
{
|
{
|
||||||
Invoke(delegate
|
if (InvokeRequired)
|
||||||
|
{
|
||||||
|
Invoke(delegate {
|
||||||
|
labelPerf.Text = modeText;
|
||||||
|
panelPerformance.AccessibleName = labelPerf.Text;
|
||||||
|
});
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
labelPerf.Text = modeText;
|
labelPerf.Text = modeText;
|
||||||
panelPerformance.AccessibleName = labelPerf.Text;
|
panelPerformance.AccessibleName = labelPerf.Text;
|
||||||
});
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public static class ControlHelper
|
|||||||
{
|
{
|
||||||
foreach (Control control in controls)
|
foreach (Control control in controls)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
AdjustControls(control.Controls);
|
||||||
|
|
||||||
var button = control as RButton;
|
var button = control as RButton;
|
||||||
if (button != null)
|
if (button != null)
|
||||||
{
|
{
|
||||||
@@ -132,7 +135,6 @@ public static class ControlHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustControls(control.Controls);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace GHelper.UI
|
namespace GHelper.UI
|
||||||
@@ -108,308 +106,4 @@ namespace GHelper.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class RCheckBox : CheckBox
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class RComboBox : ComboBox
|
|
||||||
{
|
|
||||||
private Color borderColor = Color.Gray;
|
|
||||||
[DefaultValue(typeof(Color), "Gray")]
|
|
||||||
public Color BorderColor
|
|
||||||
{
|
|
||||||
get { return borderColor; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (borderColor != value)
|
|
||||||
{
|
|
||||||
borderColor = value;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Color buttonColor = Color.FromArgb(255, 255, 255, 255);
|
|
||||||
[DefaultValue(typeof(Color), "255, 255, 255")]
|
|
||||||
public Color ButtonColor
|
|
||||||
{
|
|
||||||
get { return buttonColor; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (buttonColor != value)
|
|
||||||
{
|
|
||||||
buttonColor = value;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color arrowColor = Color.Black;
|
|
||||||
[DefaultValue(typeof(Color), "Black")]
|
|
||||||
public Color ArrowColor
|
|
||||||
{
|
|
||||||
get { return arrowColor; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (arrowColor != value)
|
|
||||||
{
|
|
||||||
arrowColor = value;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
|
||||||
{
|
|
||||||
if (m.Msg == WM_PAINT && DropDownStyle != ComboBoxStyle.Simple)
|
|
||||||
{
|
|
||||||
var clientRect = ClientRectangle;
|
|
||||||
var dropDownButtonWidth = SystemInformation.HorizontalScrollBarArrowWidth;
|
|
||||||
var outerBorder = new Rectangle(clientRect.Location,
|
|
||||||
new Size(clientRect.Width - 1, clientRect.Height - 1));
|
|
||||||
var innerBorder = new Rectangle(outerBorder.X + 1, outerBorder.Y + 1,
|
|
||||||
outerBorder.Width - dropDownButtonWidth - 2, outerBorder.Height - 2);
|
|
||||||
var innerInnerBorder = new Rectangle(innerBorder.X + 1, innerBorder.Y + 1,
|
|
||||||
innerBorder.Width - 2, innerBorder.Height - 2);
|
|
||||||
var dropDownRect = new Rectangle(innerBorder.Right + 1, innerBorder.Y,
|
|
||||||
dropDownButtonWidth, innerBorder.Height + 1);
|
|
||||||
if (RightToLeft == RightToLeft.Yes)
|
|
||||||
{
|
|
||||||
innerBorder.X = clientRect.Width - innerBorder.Right;
|
|
||||||
innerInnerBorder.X = clientRect.Width - innerInnerBorder.Right;
|
|
||||||
dropDownRect.X = clientRect.Width - dropDownRect.Right;
|
|
||||||
dropDownRect.Width += 1;
|
|
||||||
}
|
|
||||||
var innerBorderColor = Enabled ? BackColor : SystemColors.Control;
|
|
||||||
var outerBorderColor = Enabled ? BorderColor : SystemColors.ControlDark;
|
|
||||||
var buttonColor = Enabled ? ButtonColor : SystemColors.Control;
|
|
||||||
var middle = new Point(dropDownRect.Left + dropDownRect.Width / 2,
|
|
||||||
dropDownRect.Top + dropDownRect.Height / 2);
|
|
||||||
var arrow = new Point[]
|
|
||||||
{
|
|
||||||
new Point(middle.X - 3, middle.Y - 2),
|
|
||||||
new Point(middle.X + 4, middle.Y - 2),
|
|
||||||
new Point(middle.X, middle.Y + 2)
|
|
||||||
};
|
|
||||||
var ps = new PAINTSTRUCT();
|
|
||||||
bool shoulEndPaint = false;
|
|
||||||
nint dc;
|
|
||||||
if (m.WParam == nint.Zero)
|
|
||||||
{
|
|
||||||
dc = BeginPaint(Handle, ref ps);
|
|
||||||
m.WParam = dc;
|
|
||||||
shoulEndPaint = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dc = m.WParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rgn = CreateRectRgn(innerInnerBorder.Left, innerInnerBorder.Top,
|
|
||||||
innerInnerBorder.Right, innerInnerBorder.Bottom);
|
|
||||||
|
|
||||||
SelectClipRgn(dc, rgn);
|
|
||||||
DefWndProc(ref m);
|
|
||||||
DeleteObject(rgn);
|
|
||||||
rgn = CreateRectRgn(clientRect.Left, clientRect.Top,
|
|
||||||
clientRect.Right, clientRect.Bottom);
|
|
||||||
SelectClipRgn(dc, rgn);
|
|
||||||
using (var g = Graphics.FromHdc(dc))
|
|
||||||
{
|
|
||||||
using (var b = new SolidBrush(buttonColor))
|
|
||||||
{
|
|
||||||
g.FillRectangle(b, dropDownRect);
|
|
||||||
}
|
|
||||||
using (var b = new SolidBrush(arrowColor))
|
|
||||||
{
|
|
||||||
g.FillPolygon(b, arrow);
|
|
||||||
}
|
|
||||||
using (var p = new Pen(innerBorderColor))
|
|
||||||
{
|
|
||||||
g.DrawRectangle(p, innerBorder);
|
|
||||||
g.DrawRectangle(p, innerInnerBorder);
|
|
||||||
}
|
|
||||||
using (var p = new Pen(outerBorderColor))
|
|
||||||
{
|
|
||||||
g.DrawRectangle(p, outerBorder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shoulEndPaint)
|
|
||||||
EndPaint(Handle, ref ps);
|
|
||||||
DeleteObject(rgn);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
base.WndProc(ref m);
|
|
||||||
}
|
|
||||||
|
|
||||||
private const int WM_PAINT = 0xF;
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct RECT
|
|
||||||
{
|
|
||||||
public int L, T, R, B;
|
|
||||||
}
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct PAINTSTRUCT
|
|
||||||
{
|
|
||||||
public nint hdc;
|
|
||||||
public bool fErase;
|
|
||||||
public int rcPaint_left;
|
|
||||||
public int rcPaint_top;
|
|
||||||
public int rcPaint_right;
|
|
||||||
public int rcPaint_bottom;
|
|
||||||
public bool fRestore;
|
|
||||||
public bool fIncUpdate;
|
|
||||||
public int reserved1;
|
|
||||||
public int reserved2;
|
|
||||||
public int reserved3;
|
|
||||||
public int reserved4;
|
|
||||||
public int reserved5;
|
|
||||||
public int reserved6;
|
|
||||||
public int reserved7;
|
|
||||||
public int reserved8;
|
|
||||||
}
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern nint BeginPaint(nint hWnd,
|
|
||||||
[In, Out] ref PAINTSTRUCT lpPaint);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern bool EndPaint(nint hWnd, ref PAINTSTRUCT lpPaint);
|
|
||||||
|
|
||||||
[DllImport("gdi32.dll")]
|
|
||||||
public static extern int SelectClipRgn(nint hDC, nint hRgn);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
public static extern int GetUpdateRgn(nint hwnd, nint hrgn, bool fErase);
|
|
||||||
public enum RegionFlags
|
|
||||||
{
|
|
||||||
ERROR = 0,
|
|
||||||
NULLREGION = 1,
|
|
||||||
SIMPLEREGION = 2,
|
|
||||||
COMPLEXREGION = 3,
|
|
||||||
}
|
|
||||||
[DllImport("gdi32.dll")]
|
|
||||||
internal static extern bool DeleteObject(nint hObject);
|
|
||||||
|
|
||||||
[DllImport("gdi32.dll")]
|
|
||||||
private static extern nint CreateRectRgn(int x1, int y1, int x2, int y2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RButton : Button
|
|
||||||
{
|
|
||||||
//Fields
|
|
||||||
private int borderSize = 5;
|
|
||||||
|
|
||||||
private int borderRadius = 5;
|
|
||||||
public int BorderRadius
|
|
||||||
{
|
|
||||||
get { return borderRadius; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
borderRadius = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color borderColor = Color.Transparent;
|
|
||||||
public Color BorderColor
|
|
||||||
{
|
|
||||||
get { return borderColor; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
borderColor = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private bool activated = false;
|
|
||||||
public bool Activated
|
|
||||||
{
|
|
||||||
get { return activated; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (activated != value)
|
|
||||||
Invalidate();
|
|
||||||
activated = value;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool secondary = false;
|
|
||||||
public bool Secondary
|
|
||||||
{
|
|
||||||
get { return secondary; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
secondary = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public RButton()
|
|
||||||
{
|
|
||||||
DoubleBuffered = true;
|
|
||||||
FlatStyle = FlatStyle.Flat;
|
|
||||||
FlatAppearance.BorderSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GraphicsPath GetFigurePath(Rectangle rect, int radius)
|
|
||||||
{
|
|
||||||
GraphicsPath path = new GraphicsPath();
|
|
||||||
float curveSize = radius * 2F;
|
|
||||||
|
|
||||||
path.StartFigure();
|
|
||||||
path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
|
|
||||||
path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90);
|
|
||||||
path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90);
|
|
||||||
path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90);
|
|
||||||
path.CloseFigure();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs pevent)
|
|
||||||
{
|
|
||||||
|
|
||||||
base.OnPaint(pevent);
|
|
||||||
|
|
||||||
float ratio = pevent.Graphics.DpiX / 192.0f;
|
|
||||||
int border = (int)(ratio * borderSize);
|
|
||||||
|
|
||||||
Rectangle rectSurface = ClientRectangle;
|
|
||||||
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -border, -border);
|
|
||||||
|
|
||||||
Color borderDrawColor = activated ? borderColor : Color.Transparent;
|
|
||||||
|
|
||||||
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius + border))
|
|
||||||
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius))
|
|
||||||
using (Pen penSurface = new Pen(Parent.BackColor, border))
|
|
||||||
using (Pen penBorder = new Pen(borderDrawColor, border))
|
|
||||||
{
|
|
||||||
penBorder.Alignment = PenAlignment.Outset;
|
|
||||||
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
||||||
Region = new Region(pathSurface);
|
|
||||||
pevent.Graphics.DrawPath(penSurface, pathSurface);
|
|
||||||
pevent.Graphics.DrawPath(penBorder, pathBorder);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Enabled && ForeColor != SystemColors.ControlText)
|
|
||||||
{
|
|
||||||
var rect = pevent.ClipRectangle;
|
|
||||||
if (Image is not null)
|
|
||||||
{
|
|
||||||
rect.Y += Image.Height;
|
|
||||||
rect.Height -= Image.Height;
|
|
||||||
}
|
|
||||||
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
|
|
||||||
TextRenderer.DrawText(pevent.Graphics, Text, Font, rect, Color.Gray, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
117
app/UI/RButton.cs
Normal file
117
app/UI/RButton.cs
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
namespace GHelper.UI
|
||||||
|
{
|
||||||
|
public class RButton : Button
|
||||||
|
{
|
||||||
|
//Fields
|
||||||
|
private int borderSize = 5;
|
||||||
|
|
||||||
|
private int borderRadius = 5;
|
||||||
|
public int BorderRadius
|
||||||
|
{
|
||||||
|
get { return borderRadius; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
borderRadius = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color borderColor = Color.Transparent;
|
||||||
|
public Color BorderColor
|
||||||
|
{
|
||||||
|
get { return borderColor; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
borderColor = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private bool activated = false;
|
||||||
|
public bool Activated
|
||||||
|
{
|
||||||
|
get { return activated; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (activated != value)
|
||||||
|
Invalidate();
|
||||||
|
activated = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool secondary = false;
|
||||||
|
public bool Secondary
|
||||||
|
{
|
||||||
|
get { return secondary; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
secondary = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RButton()
|
||||||
|
{
|
||||||
|
DoubleBuffered = true;
|
||||||
|
FlatStyle = FlatStyle.Flat;
|
||||||
|
FlatAppearance.BorderSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GraphicsPath GetFigurePath(Rectangle rect, int radius)
|
||||||
|
{
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
float curveSize = radius * 2F;
|
||||||
|
|
||||||
|
path.StartFigure();
|
||||||
|
path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
|
||||||
|
path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90);
|
||||||
|
path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90);
|
||||||
|
path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90);
|
||||||
|
path.CloseFigure();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs pevent)
|
||||||
|
{
|
||||||
|
|
||||||
|
base.OnPaint(pevent);
|
||||||
|
|
||||||
|
float ratio = pevent.Graphics.DpiX / 192.0f;
|
||||||
|
int border = (int)(ratio * borderSize);
|
||||||
|
|
||||||
|
Rectangle rectSurface = ClientRectangle;
|
||||||
|
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -border, -border);
|
||||||
|
|
||||||
|
Color borderDrawColor = activated ? borderColor : Color.Transparent;
|
||||||
|
|
||||||
|
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius + border))
|
||||||
|
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius))
|
||||||
|
using (Pen penSurface = new Pen(Parent.BackColor, border))
|
||||||
|
using (Pen penBorder = new Pen(borderDrawColor, border))
|
||||||
|
{
|
||||||
|
penBorder.Alignment = PenAlignment.Outset;
|
||||||
|
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
Region = new Region(pathSurface);
|
||||||
|
pevent.Graphics.DrawPath(penSurface, pathSurface);
|
||||||
|
pevent.Graphics.DrawPath(penBorder, pathBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Enabled && ForeColor != SystemColors.ControlText)
|
||||||
|
{
|
||||||
|
var rect = pevent.ClipRectangle;
|
||||||
|
if (Image is not null)
|
||||||
|
{
|
||||||
|
rect.Y += Image.Height;
|
||||||
|
rect.Height -= Image.Height;
|
||||||
|
}
|
||||||
|
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
|
||||||
|
TextRenderer.DrawText(pevent.Graphics, Text, Font, rect, Color.Gray, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
7
app/UI/RCheckBox.cs
Normal file
7
app/UI/RCheckBox.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace GHelper.UI
|
||||||
|
{
|
||||||
|
public class RCheckBox : CheckBox
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
189
app/UI/RComboBox.cs
Normal file
189
app/UI/RComboBox.cs
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace GHelper.UI
|
||||||
|
{
|
||||||
|
public class RComboBox : ComboBox
|
||||||
|
{
|
||||||
|
private Color borderColor = Color.Gray;
|
||||||
|
[DefaultValue(typeof(Color), "Gray")]
|
||||||
|
public Color BorderColor
|
||||||
|
{
|
||||||
|
get { return borderColor; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (borderColor != value)
|
||||||
|
{
|
||||||
|
borderColor = value;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Color buttonColor = Color.FromArgb(255, 255, 255, 255);
|
||||||
|
[DefaultValue(typeof(Color), "255, 255, 255")]
|
||||||
|
public Color ButtonColor
|
||||||
|
{
|
||||||
|
get { return buttonColor; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (buttonColor != value)
|
||||||
|
{
|
||||||
|
buttonColor = value;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color arrowColor = Color.Black;
|
||||||
|
[DefaultValue(typeof(Color), "Black")]
|
||||||
|
public Color ArrowColor
|
||||||
|
{
|
||||||
|
get { return arrowColor; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (arrowColor != value)
|
||||||
|
{
|
||||||
|
arrowColor = value;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
if (m.Msg == WM_PAINT && DropDownStyle != ComboBoxStyle.Simple)
|
||||||
|
{
|
||||||
|
var clientRect = ClientRectangle;
|
||||||
|
var dropDownButtonWidth = SystemInformation.HorizontalScrollBarArrowWidth;
|
||||||
|
var outerBorder = new Rectangle(clientRect.Location,
|
||||||
|
new Size(clientRect.Width - 1, clientRect.Height - 1));
|
||||||
|
var innerBorder = new Rectangle(outerBorder.X + 1, outerBorder.Y + 1,
|
||||||
|
outerBorder.Width - dropDownButtonWidth - 2, outerBorder.Height - 2);
|
||||||
|
var innerInnerBorder = new Rectangle(innerBorder.X + 1, innerBorder.Y + 1,
|
||||||
|
innerBorder.Width - 2, innerBorder.Height - 2);
|
||||||
|
var dropDownRect = new Rectangle(innerBorder.Right + 1, innerBorder.Y,
|
||||||
|
dropDownButtonWidth, innerBorder.Height + 1);
|
||||||
|
if (RightToLeft == RightToLeft.Yes)
|
||||||
|
{
|
||||||
|
innerBorder.X = clientRect.Width - innerBorder.Right;
|
||||||
|
innerInnerBorder.X = clientRect.Width - innerInnerBorder.Right;
|
||||||
|
dropDownRect.X = clientRect.Width - dropDownRect.Right;
|
||||||
|
dropDownRect.Width += 1;
|
||||||
|
}
|
||||||
|
var innerBorderColor = Enabled ? BackColor : SystemColors.Control;
|
||||||
|
var outerBorderColor = Enabled ? BorderColor : SystemColors.ControlDark;
|
||||||
|
var buttonColor = Enabled ? ButtonColor : SystemColors.Control;
|
||||||
|
var middle = new Point(dropDownRect.Left + dropDownRect.Width / 2,
|
||||||
|
dropDownRect.Top + dropDownRect.Height / 2);
|
||||||
|
var arrow = new Point[]
|
||||||
|
{
|
||||||
|
new Point(middle.X - 3, middle.Y - 2),
|
||||||
|
new Point(middle.X + 4, middle.Y - 2),
|
||||||
|
new Point(middle.X, middle.Y + 2)
|
||||||
|
};
|
||||||
|
var ps = new PAINTSTRUCT();
|
||||||
|
bool shoulEndPaint = false;
|
||||||
|
nint dc;
|
||||||
|
if (m.WParam == nint.Zero)
|
||||||
|
{
|
||||||
|
dc = BeginPaint(Handle, ref ps);
|
||||||
|
m.WParam = dc;
|
||||||
|
shoulEndPaint = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dc = m.WParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rgn = CreateRectRgn(innerInnerBorder.Left, innerInnerBorder.Top,
|
||||||
|
innerInnerBorder.Right, innerInnerBorder.Bottom);
|
||||||
|
|
||||||
|
SelectClipRgn(dc, rgn);
|
||||||
|
DefWndProc(ref m);
|
||||||
|
DeleteObject(rgn);
|
||||||
|
rgn = CreateRectRgn(clientRect.Left, clientRect.Top,
|
||||||
|
clientRect.Right, clientRect.Bottom);
|
||||||
|
SelectClipRgn(dc, rgn);
|
||||||
|
using (var g = Graphics.FromHdc(dc))
|
||||||
|
{
|
||||||
|
using (var b = new SolidBrush(buttonColor))
|
||||||
|
{
|
||||||
|
g.FillRectangle(b, dropDownRect);
|
||||||
|
}
|
||||||
|
using (var b = new SolidBrush(arrowColor))
|
||||||
|
{
|
||||||
|
g.FillPolygon(b, arrow);
|
||||||
|
}
|
||||||
|
using (var p = new Pen(innerBorderColor))
|
||||||
|
{
|
||||||
|
g.DrawRectangle(p, innerBorder);
|
||||||
|
g.DrawRectangle(p, innerInnerBorder);
|
||||||
|
}
|
||||||
|
using (var p = new Pen(outerBorderColor))
|
||||||
|
{
|
||||||
|
g.DrawRectangle(p, outerBorder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shoulEndPaint)
|
||||||
|
EndPaint(Handle, ref ps);
|
||||||
|
DeleteObject(rgn);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
base.WndProc(ref m);
|
||||||
|
}
|
||||||
|
|
||||||
|
private const int WM_PAINT = 0xF;
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct RECT
|
||||||
|
{
|
||||||
|
public int L, T, R, B;
|
||||||
|
}
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct PAINTSTRUCT
|
||||||
|
{
|
||||||
|
public nint hdc;
|
||||||
|
public bool fErase;
|
||||||
|
public int rcPaint_left;
|
||||||
|
public int rcPaint_top;
|
||||||
|
public int rcPaint_right;
|
||||||
|
public int rcPaint_bottom;
|
||||||
|
public bool fRestore;
|
||||||
|
public bool fIncUpdate;
|
||||||
|
public int reserved1;
|
||||||
|
public int reserved2;
|
||||||
|
public int reserved3;
|
||||||
|
public int reserved4;
|
||||||
|
public int reserved5;
|
||||||
|
public int reserved6;
|
||||||
|
public int reserved7;
|
||||||
|
public int reserved8;
|
||||||
|
}
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern nint BeginPaint(nint hWnd,
|
||||||
|
[In, Out] ref PAINTSTRUCT lpPaint);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool EndPaint(nint hWnd, ref PAINTSTRUCT lpPaint);
|
||||||
|
|
||||||
|
[DllImport("gdi32.dll")]
|
||||||
|
public static extern int SelectClipRgn(nint hDC, nint hRgn);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern int GetUpdateRgn(nint hwnd, nint hrgn, bool fErase);
|
||||||
|
public enum RegionFlags
|
||||||
|
{
|
||||||
|
ERROR = 0,
|
||||||
|
NULLREGION = 1,
|
||||||
|
SIMPLEREGION = 2,
|
||||||
|
COMPLEXREGION = 3,
|
||||||
|
}
|
||||||
|
[DllImport("gdi32.dll")]
|
||||||
|
internal static extern bool DeleteObject(nint hObject);
|
||||||
|
|
||||||
|
[DllImport("gdi32.dll")]
|
||||||
|
private static extern nint CreateRectRgn(int x1, int y1, int x2, int y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user