upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class BrowserWontOpenDialog : SignalDialogWindow
|
||||
{
|
||||
public const string Title = "We couldn't open your browser";
|
||||
|
||||
public const string Body = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.";
|
||||
|
||||
public const string ShortSentence = "We couldn't open your browser. Copy the link and open it yourself.";
|
||||
|
||||
public const string CopyLabel = "Copy link";
|
||||
|
||||
public const string CloseLabel = "Close";
|
||||
|
||||
public const string Copied = "Copied. Paste it into your browser.";
|
||||
|
||||
private const int WidthLogical = 560;
|
||||
|
||||
private const int LinkHeight = 32;
|
||||
|
||||
private const int HintHeight = 16;
|
||||
|
||||
private const int HintGap = 8;
|
||||
|
||||
internal const int Chrome = 208;
|
||||
|
||||
private readonly string _url;
|
||||
|
||||
private readonly string _displayUrl;
|
||||
|
||||
private readonly int _linkHeight;
|
||||
|
||||
private readonly GlassButton _copyButton;
|
||||
|
||||
private readonly Action<string> _copy;
|
||||
|
||||
private string _hint = "";
|
||||
|
||||
internal string HintForTest => _hint;
|
||||
|
||||
internal static Action<string>? InsteadOfShowingForTest { get; set; }
|
||||
|
||||
internal static int MeasureHeight(string body, int width, string url = "")
|
||||
{
|
||||
int num = Math.Max(80, width - 48);
|
||||
int val = (int)Math.Ceiling((double)(SignalDialogWindow.MeasureBody(body, Tokens.Scale(num)) * 96) / (double)Tokens.Dpi);
|
||||
int num2 = (int)Math.Ceiling((double)(MeasureLink(url, Tokens.Scale(num - 24), Tokens.Scale(16), out string _) * 96) / (double)Tokens.Dpi);
|
||||
return 208 + Math.Min(val, 200) + Math.Max(0, num2 - 32);
|
||||
}
|
||||
|
||||
internal BrowserWontOpenDialog(string url, Action<string> copy)
|
||||
{
|
||||
_url = url ?? "";
|
||||
_copy = copy ?? throw new ArgumentNullException("copy");
|
||||
ShowInTaskbar = true;
|
||||
TopMost = true;
|
||||
Text = "PlexusX";
|
||||
AccessibleName = "We couldn't open your browser";
|
||||
AccessibleDescription = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there. " + _url;
|
||||
ChromeTitle = "We couldn't open your browser";
|
||||
ChromeBody = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.";
|
||||
int num = S(560);
|
||||
_linkHeight = Math.Max(S(32), MeasureLink(_url, num - 2 * S(24) - S(24), S(16), out _displayUrl));
|
||||
ChromeBodyHeight = Math.Min(SignalDialogWindow.MeasureBody("PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.", num - 2 * S(24)), S(200));
|
||||
ClientSize = new Size(num, BodyTop + ChromeBodyHeight + S(16) + _linkHeight + S(8) + S(16) + S(24) + S(32) + S(20));
|
||||
GlassButton glassButton = FooterButton("Close", GlassButtonKind.Secondary, "BrowserWontOpenClose");
|
||||
glassButton.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Close();
|
||||
};
|
||||
_copyButton = FooterButton("Copy link", GlassButtonKind.Primary, "BrowserWontOpenCopy");
|
||||
_copyButton.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
CopyTheLink();
|
||||
};
|
||||
Controls.Add(glassButton);
|
||||
Controls.Add(_copyButton);
|
||||
PlaceFooter(glassButton, _copyButton);
|
||||
_copyButton.TabIndex = 0;
|
||||
glassButton.TabIndex = 1;
|
||||
ActiveControl = _copyButton;
|
||||
WindowDrag.Enable(this, this);
|
||||
}
|
||||
|
||||
private static int MeasureLink(string url, int width, int padding, out string display)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int num;
|
||||
for (int i = 0; i < url.Length; i += num)
|
||||
{
|
||||
num = 1;
|
||||
int num2 = url.Length - i;
|
||||
while (num < num2)
|
||||
{
|
||||
int num3 = (num + num2 + 1) / 2;
|
||||
if (TextRenderer.MeasureText(url.Substring(i, num3), Fonts.Body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine).Width <= width)
|
||||
{
|
||||
num = num3;
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 = num3 - 1;
|
||||
}
|
||||
}
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append('\n');
|
||||
}
|
||||
stringBuilder.Append(url, i, num);
|
||||
}
|
||||
display = stringBuilder.ToString();
|
||||
Size proposedSize = new Size(Math.Max(1, width), int.MaxValue);
|
||||
return Math.Max(TextRenderer.MeasureText(display, Fonts.Body, proposedSize, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height, TextRenderer.MeasureText(url, Fonts.Body, proposedSize, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height) + padding;
|
||||
}
|
||||
|
||||
private void CopyTheLink()
|
||||
{
|
||||
try
|
||||
{
|
||||
_copy(_url);
|
||||
_hint = "Copied. Paste it into your browser.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CrashLog.Write(ex);
|
||||
_hint = "Windows would not let us copy it. Type the link above into your browser.";
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
internal void PressCopyForTest()
|
||||
{
|
||||
CopyTheLink();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
e.Handled = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
int x = S(24);
|
||||
int textWidth = TextWidth;
|
||||
Rectangle rect = new Rectangle(x, ContentTop, textWidth, _linkHeight);
|
||||
GraphicsState gstate = graphics.Save();
|
||||
graphics.TranslateTransform(rect.X, rect.Y);
|
||||
ControlInk.PaintBox(graphics, rect.Size, S(4), ControlInk.Hairline(ChromeDpi), ControlInk.FieldFill, ControlInk.Edge);
|
||||
graphics.Restore(gstate);
|
||||
TextRenderer.DrawText(graphics, _displayUrl, Fonts.Body, Rectangle.Inflate(rect, -S(12), -S(8)), ControlInk.Text1, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak);
|
||||
if (_hint.Length > 0)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, _hint, Fonts.Caption, new Rectangle(x, rect.Bottom + S(8), textWidth, S(16)), ControlInk.Text2, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ShowFor(IWin32Window? owner, string url)
|
||||
{
|
||||
Action<string> insteadOfShowingForTest = InsteadOfShowingForTest;
|
||||
if (insteadOfShowingForTest != null)
|
||||
{
|
||||
insteadOfShowingForTest(url);
|
||||
return;
|
||||
}
|
||||
using BrowserWontOpenDialog browserWontOpenDialog = new BrowserWontOpenDialog(url, ToTheClipboard);
|
||||
if (owner != null)
|
||||
{
|
||||
browserWontOpenDialog.ShowDialog(owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
browserWontOpenDialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToTheClipboard(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || TheClipboard.Put(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw new InvalidOperationException("Windows would not let go of the clipboard.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class CaptionButton : Control
|
||||
{
|
||||
public enum Kind
|
||||
{
|
||||
Minimise,
|
||||
Close
|
||||
}
|
||||
|
||||
private readonly Kind _kind;
|
||||
|
||||
private bool _hot;
|
||||
|
||||
private bool _down;
|
||||
|
||||
internal bool HotForTest
|
||||
{
|
||||
set
|
||||
{
|
||||
_hot = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
internal bool PressedForTest
|
||||
{
|
||||
set
|
||||
{
|
||||
_down = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public CaptionButton(Kind kind)
|
||||
{
|
||||
_kind = kind;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
AccessibleRole = AccessibleRole.PushButton;
|
||||
AccessibleName = ((kind == Kind.Close) ? "Close" : "Minimise");
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
_hot = true;
|
||||
Invalidate();
|
||||
base.OnMouseEnter(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
_hot = false;
|
||||
_down = false;
|
||||
Invalidate();
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
_down = true;
|
||||
Invalidate();
|
||||
}
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
_down = false;
|
||||
Invalidate();
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
if (_down || _hot)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(_down ? ControlInk.Pressed : ControlInk.Hover);
|
||||
graphics.FillRectangle(brush, 0, 0, Width, Height);
|
||||
}
|
||||
using Pen pen = new Pen((_hot || _down) ? Theme.Text : Theme.TextDim, 1.4f);
|
||||
PaintGlyph(graphics, pen, GlyphBox());
|
||||
}
|
||||
|
||||
private void PaintGlyph(Graphics g, Pen pen, Rectangle r)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float num = (float)r.Top + (float)(r.Height + 1) / 2f;
|
||||
if (_kind == Kind.Minimise)
|
||||
{
|
||||
g.DrawLine(pen, r.Left, num, r.Right, num);
|
||||
return;
|
||||
}
|
||||
g.DrawLine(pen, r.Left, r.Top, r.Right, r.Bottom);
|
||||
g.DrawLine(pen, r.Right, r.Top, r.Left, r.Bottom);
|
||||
}
|
||||
|
||||
private Rectangle GlyphBox()
|
||||
{
|
||||
int num = Tokens.Scale(9);
|
||||
return new Rectangle((Width - num) / 2, (Height - num) / 2, num, num);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class ColourWheel : Control
|
||||
{
|
||||
private const int BarWidth = 18;
|
||||
|
||||
private const int BarGap = 12;
|
||||
|
||||
private Bitmap? _wheel;
|
||||
|
||||
private int _wheelDiameter;
|
||||
|
||||
private float _hue;
|
||||
|
||||
private float _saturation;
|
||||
|
||||
private float _value = 1f;
|
||||
|
||||
private bool _draggingWheel;
|
||||
|
||||
private bool _draggingBar;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private int _failedDiameter;
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
public Color Colour
|
||||
{
|
||||
get
|
||||
{
|
||||
return FromHsv(_hue, _saturation, _value);
|
||||
}
|
||||
set
|
||||
{
|
||||
ToHsv(value, out _hue, out _saturation, out _value);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int Diameter => Math.Max(8, Math.Min(Width - 18 - 12, Height));
|
||||
|
||||
private Rectangle WheelRect => new Rectangle(0, (Height - Diameter) / 2, Diameter, Diameter);
|
||||
|
||||
private Rectangle BarRect => new Rectangle(Width - 18, 4, 17, Math.Max(8, Height - 9));
|
||||
|
||||
public event EventHandler? ColourChanged;
|
||||
|
||||
public ColourWheel()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
AccessibleRole = AccessibleRole.Slider;
|
||||
AccessibleName = "Colour picker";
|
||||
Size = new Size(180, 160);
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 4f));
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
if (BarRect.Contains(e.Location))
|
||||
{
|
||||
_draggingBar = true;
|
||||
DragTracker.Begin();
|
||||
TakeBar(e.Y);
|
||||
}
|
||||
else if (WheelRect.Contains(e.Location))
|
||||
{
|
||||
_draggingWheel = true;
|
||||
DragTracker.Begin();
|
||||
TakeWheel(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_draggingBar)
|
||||
{
|
||||
TakeBar(e.Y);
|
||||
}
|
||||
else if (_draggingWheel)
|
||||
{
|
||||
TakeWheel(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_draggingWheel || _draggingBar)
|
||||
{
|
||||
DragTracker.End();
|
||||
}
|
||||
_draggingWheel = false;
|
||||
_draggingBar = false;
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case Keys.Left:
|
||||
_hue = (_hue + 355f) % 360f;
|
||||
break;
|
||||
case Keys.Right:
|
||||
_hue = (_hue + 5f) % 360f;
|
||||
break;
|
||||
case Keys.Up:
|
||||
_value = Math.Min(1f, _value + 0.05f);
|
||||
break;
|
||||
case Keys.Down:
|
||||
_value = Math.Max(0f, _value - 0.05f);
|
||||
break;
|
||||
case Keys.Prior:
|
||||
_saturation = Math.Min(1f, _saturation + 0.1f);
|
||||
break;
|
||||
case Keys.Next:
|
||||
_saturation = Math.Max(0f, _saturation - 0.1f);
|
||||
break;
|
||||
case Keys.End:
|
||||
case Keys.Home:
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
internal bool TestClaimsKey(Keys key)
|
||||
{
|
||||
return IsInputKey(key);
|
||||
}
|
||||
|
||||
protected override bool IsInputKey(Keys keyData)
|
||||
{
|
||||
if ((uint)(keyData - 33) <= 1u || (uint)(keyData - 37) <= 3u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return base.IsInputKey(keyData);
|
||||
}
|
||||
|
||||
private void TakeWheel(Point p)
|
||||
{
|
||||
Rectangle wheelRect = WheelRect;
|
||||
float num = (float)wheelRect.X + (float)wheelRect.Width / 2f;
|
||||
float num2 = (float)wheelRect.Y + (float)wheelRect.Height / 2f;
|
||||
float num3 = (float)p.X - num;
|
||||
float num4 = (float)p.Y - num2;
|
||||
float num5 = (float)wheelRect.Width / 2f;
|
||||
float num6 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
|
||||
_saturation = Math.Clamp(num6 / num5, 0f, 1f);
|
||||
_hue = (float)((Math.Atan2(num4, num3) * 180.0 / Math.PI + 360.0) % 360.0);
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void TakeBar(int y)
|
||||
{
|
||||
Rectangle barRect = BarRect;
|
||||
_value = 1f - Math.Clamp((float)(y - barRect.Y) / (float)barRect.Height, 0f, 1f);
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintBody(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintBody(Graphics g)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Rectangle wheelRect = WheelRect;
|
||||
if (wheelRect.Width > 8)
|
||||
{
|
||||
EnsureWheel(wheelRect.Width);
|
||||
using Region clip = g.Clip;
|
||||
using (GraphicsPath graphicsPath = new GraphicsPath())
|
||||
{
|
||||
graphicsPath.AddEllipse(wheelRect);
|
||||
g.SetClip(graphicsPath);
|
||||
if (_wheel != null)
|
||||
{
|
||||
g.DrawImage(_wheel, wheelRect);
|
||||
}
|
||||
if (_value < 1f)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Color.FromArgb((int)(255f * (1f - _value)), 0, 0, 0));
|
||||
g.FillRectangle(brush, wheelRect);
|
||||
}
|
||||
}
|
||||
g.Clip = clip;
|
||||
DrawWheelMarker(g, wheelRect);
|
||||
}
|
||||
DrawBar(g);
|
||||
if (Focused && ShowFocusCues)
|
||||
{
|
||||
_ring.Show(Enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ring.Show(show: false);
|
||||
}
|
||||
if (!Enabled)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(158, Theme.Background)))
|
||||
{
|
||||
g.FillRectangle(brush2, ClientRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void DrawWheelMarker(Graphics g, Rectangle wheel)
|
||||
{
|
||||
float num = (float)wheel.Width / 2f;
|
||||
float num2 = (float)((double)_hue * Math.PI / 180.0);
|
||||
float num3 = (float)wheel.X + num + (float)Math.Cos(num2) * num * _saturation;
|
||||
float num4 = (float)wheel.Y + num + (float)Math.Sin(num2) * num * _saturation;
|
||||
RectangleF rect = new RectangleF(num3 - 6f, num4 - 6f, 12f, 12f);
|
||||
using (Pen pen = new Pen(Color.FromArgb(200, 0, 0, 0), 3f))
|
||||
{
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
using Pen pen2 = new Pen(Color.White, 1.6f);
|
||||
g.DrawEllipse(pen2, rect);
|
||||
}
|
||||
|
||||
private void DrawBar(Graphics g)
|
||||
{
|
||||
Rectangle barRect = BarRect;
|
||||
if (barRect.Height <= 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Color color = FromHsv(_hue, _saturation, 1f);
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(barRect, color, Color.Black, 90f))
|
||||
{
|
||||
g.FillRectangle(brush, barRect);
|
||||
}
|
||||
using (Pen pen = new Pen(Color.FromArgb(90, Theme.GlassEdge), 1f))
|
||||
{
|
||||
g.DrawRectangle(pen, barRect);
|
||||
}
|
||||
int num = barRect.Y + (int)((1f - _value) * (float)barRect.Height);
|
||||
using (Pen pen2 = new Pen(Color.FromArgb(200, 0, 0, 0), 3f))
|
||||
{
|
||||
g.DrawLine(pen2, barRect.X, num, barRect.Right, num);
|
||||
}
|
||||
using Pen pen3 = new Pen(Color.White, 1.4f);
|
||||
g.DrawLine(pen3, barRect.X, num, barRect.Right, num);
|
||||
}
|
||||
|
||||
private void EnsureWheel(int diameter)
|
||||
{
|
||||
if ((_wheel == null || _wheelDiameter != diameter) && _failedDiameter != diameter)
|
||||
{
|
||||
Bitmap wheel;
|
||||
try
|
||||
{
|
||||
FailPointForTest?.Invoke("build");
|
||||
wheel = BuildWheel(diameter);
|
||||
}
|
||||
catch (Exception ex) when (PaintGuard.IsGdiFailure(ex))
|
||||
{
|
||||
_wheel?.Dispose();
|
||||
_wheel = null;
|
||||
_wheelDiameter = 0;
|
||||
_failedDiameter = diameter;
|
||||
throw;
|
||||
}
|
||||
Bitmap? wheel2 = _wheel;
|
||||
_wheel = wheel;
|
||||
_wheelDiameter = diameter;
|
||||
_failedDiameter = 0;
|
||||
wheel2?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap BuildWheel(int diameter)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(diameter, diameter, PixelFormat.Format32bppArgb);
|
||||
float num = (float)diameter / 2f;
|
||||
BitmapData bitmapData;
|
||||
try
|
||||
{
|
||||
bitmapData = bitmap.LockBits(new Rectangle(0, 0, diameter, diameter), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
catch
|
||||
{
|
||||
bitmap.Dispose();
|
||||
throw;
|
||||
}
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
byte[] array = new byte[bitmapData.Stride];
|
||||
for (int i = 0; i < diameter; i++)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
for (int j = 0; j < diameter; j++)
|
||||
{
|
||||
float num2 = (float)j - num + 0.5f;
|
||||
float num3 = (float)i - num + 0.5f;
|
||||
float num4 = (float)Math.Sqrt(num2 * num2 + num3 * num3);
|
||||
if (!(num4 > num))
|
||||
{
|
||||
Color color = FromHsv((float)((Math.Atan2(num3, num2) * 180.0 / Math.PI + 360.0) % 360.0), Math.Min(1f, num4 / num), 1f);
|
||||
byte b = ((num4 > num - 1.2f) ? ((byte)(255f * Math.Clamp(num - num4, 0f, 1.2f) / 1.2f)) : byte.MaxValue);
|
||||
int num5 = j * 4;
|
||||
array[num5] = color.B;
|
||||
array[num5 + 1] = color.G;
|
||||
array[num5 + 2] = color.R;
|
||||
array[num5 + 3] = b;
|
||||
}
|
||||
}
|
||||
Marshal.Copy(array, 0, bitmapData.Scan0 + i * bitmapData.Stride, bitmapData.Stride);
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
if (!flag)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Color FromHsv(float hue, float saturation, float value)
|
||||
{
|
||||
hue = (hue % 360f + 360f) % 360f;
|
||||
saturation = Math.Clamp(saturation, 0f, 1f);
|
||||
value = Math.Clamp(value, 0f, 1f);
|
||||
float num = value * saturation;
|
||||
float num2 = num * (1f - Math.Abs(hue / 60f % 2f - 1f));
|
||||
float num3 = value - num;
|
||||
var (num4, num5, num6) = ((hue < 60f) ? (num, num2, 0f) : ((hue < 120f) ? (num2, num, 0f) : ((hue < 180f) ? (0f, num, num2) : ((hue < 240f) ? (0f, num2, num) : ((!(hue < 300f)) ? (num, 0f, num2) : (num2, 0f, num))))));
|
||||
return Color.FromArgb(255, (int)Math.Round((num4 + num3) * 255f), (int)Math.Round((num5 + num3) * 255f), (int)Math.Round((num6 + num3) * 255f));
|
||||
}
|
||||
|
||||
public static string ToHex(Color colour)
|
||||
{
|
||||
return $"{colour.R:X2}{colour.G:X2}{colour.B:X2}";
|
||||
}
|
||||
|
||||
public static bool TryParseHex(string? text, out Color colour)
|
||||
{
|
||||
colour = Color.Empty;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text2 = text.Trim().TrimStart('#');
|
||||
int length = text2.Length;
|
||||
if ((length != 3 && length != 6) || 1 == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text3 = text2;
|
||||
for (length = 0; length < text3.Length; length++)
|
||||
{
|
||||
if (!Uri.IsHexDigit(text3[length]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (text2.Length == 3)
|
||||
{
|
||||
text2 = string.Concat(text2[0], text2[0], text2[1], text2[1], text2[2], text2[2]);
|
||||
}
|
||||
colour = Color.FromArgb(255, Convert.ToInt32(text2.Substring(0, 2), 16), Convert.ToInt32(text2.Substring(2, 2), 16), Convert.ToInt32(text2.Substring(4, 2), 16));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ToHsv(Color colour, out float hue, out float saturation, out float value)
|
||||
{
|
||||
float num = (float)(int)colour.R / 255f;
|
||||
float num2 = (float)(int)colour.G / 255f;
|
||||
float num3 = (float)(int)colour.B / 255f;
|
||||
float num4 = Math.Max(num, Math.Max(num2, num3));
|
||||
float num5 = Math.Min(num, Math.Min(num2, num3));
|
||||
float num6 = num4 - num5;
|
||||
value = num4;
|
||||
saturation = ((num4 <= 0f) ? 0f : (num6 / num4));
|
||||
if (num6 <= 0f)
|
||||
{
|
||||
hue = 0f;
|
||||
return;
|
||||
}
|
||||
float num7;
|
||||
if (num4 == num)
|
||||
{
|
||||
num7 = 60f * ((num2 - num3) / num6 % 6f);
|
||||
}
|
||||
else
|
||||
{
|
||||
num7 = ((num4 == num2) ? (60f * ((num3 - num) / num6 + 2f)) : (60f * ((num - num2) / num6 + 4f)));
|
||||
}
|
||||
hue = num7;
|
||||
hue = (hue % 360f + 360f) % 360f;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_wheel?.Dispose();
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class CrosshairCell : Control
|
||||
{
|
||||
private const int HeartSize = 16;
|
||||
|
||||
private bool _hover;
|
||||
|
||||
private bool _hoverHeart;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private bool _active;
|
||||
|
||||
private bool _favourite;
|
||||
|
||||
public CrosshairGallery.GalleryItem Item { get; }
|
||||
|
||||
public CrosshairConfig? PreviewStyle { get; set; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Favourite
|
||||
{
|
||||
get
|
||||
{
|
||||
return _favourite;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_favourite != value)
|
||||
{
|
||||
_favourite = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Color TextOnFill
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!SlateSurface.Active)
|
||||
{
|
||||
return SignalTokens.Ash.TextOnFill;
|
||||
}
|
||||
return SignalTokens.Slate.TextOnFill;
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle HeartRect => new Rectangle(Width - 16 - 6, 6, 16, 16);
|
||||
|
||||
private static int NameStrip => Math.Max(Fonts.LineHeight(FontRole.Caption), TextRenderer.MeasureText("Hg", Fonts.Caption).Height);
|
||||
|
||||
public event EventHandler? FavouriteToggled;
|
||||
|
||||
public CrosshairCell(CrosshairGallery.GalleryItem item)
|
||||
{
|
||||
Item = item;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
AccessibleRole = AccessibleRole.PushButton;
|
||||
AccessibleName = item.Name;
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 4f));
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
bool flag = HeartRect.Contains(e.Location);
|
||||
if (flag != _hoverHeart)
|
||||
{
|
||||
_hoverHeart = flag;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_hover = true;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = false;
|
||||
_hoverHeart = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left && HeartRect.Contains(e.Location))
|
||||
{
|
||||
FavouriteToggled?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
RectangleF rect = new RectangleF(0f, 0f, Width, Height);
|
||||
float num = Tokens.Scale(4);
|
||||
using (GraphicsPath path = Glass.RoundedPath(rect, num))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush((_hover && !_active) ? ControlInk.Hover : ControlInk.Surface2);
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
if (_active)
|
||||
{
|
||||
float num2 = Tokens.Scale(2);
|
||||
using Pen pen = new Pen(ControlInk.Accent, num2);
|
||||
using GraphicsPath path2 = Glass.RoundedPath(RectangleF.Inflate(rect, (0f - num2) / 2f, (0f - num2) / 2f), Math.Max(1f, num - num2 / 2f));
|
||||
graphics.DrawPath(pen, path2);
|
||||
}
|
||||
DrawPreview(graphics);
|
||||
DrawHeart(graphics);
|
||||
DrawName(graphics);
|
||||
if (Focused && ShowFocusCues)
|
||||
{
|
||||
_ring.Show(Enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ring.Show(show: false);
|
||||
}
|
||||
}
|
||||
|
||||
private (Rectangle Glyph, Rectangle Name) Column()
|
||||
{
|
||||
int num = Tokens.Scale(36);
|
||||
int num2 = Tokens.Scale(8);
|
||||
int nameStrip = NameStrip;
|
||||
int num3 = Math.Max(0, (Height - num - num2 - nameStrip) / 2);
|
||||
return (Glyph: new Rectangle((Width - num) / 2, num3, num, num), Name: new Rectangle(2, num3 + num + num2, Width - 4, nameStrip));
|
||||
}
|
||||
|
||||
private void DrawPreview(Graphics g)
|
||||
{
|
||||
CrosshairConfig crosshairConfig = Item.Config.Clone();
|
||||
if (PreviewStyle != null)
|
||||
{
|
||||
crosshairConfig.ColourArgb = PreviewStyle.ColourArgb;
|
||||
crosshairConfig.Opacity = PreviewStyle.Opacity;
|
||||
crosshairConfig.Outline = PreviewStyle.Outline;
|
||||
}
|
||||
Rectangle item = Column().Glyph;
|
||||
if (item.Width > 4)
|
||||
{
|
||||
CrosshairRender.Draw(g, crosshairConfig, item, (float)Tokens.Scale(100) / 100f);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHeart(Graphics g)
|
||||
{
|
||||
if (!_favourite && !_hover)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Rectangle heartRect = HeartRect;
|
||||
Color color = (_favourite ? Theme.Text : Color.FromArgb(_hoverHeart ? 200 : 90, Theme.GlassEdge));
|
||||
using GraphicsPath path = HeartPath(heartRect);
|
||||
if (_favourite)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
using Pen pen = new Pen(color, 1.4f);
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
|
||||
private static GraphicsPath HeartPath(Rectangle r)
|
||||
{
|
||||
GraphicsPath graphicsPath = new GraphicsPath();
|
||||
float num = r.Width;
|
||||
float num2 = r.Height;
|
||||
float num3 = (float)r.X + num / 2f;
|
||||
graphicsPath.AddBezier(num3, (float)r.Y + num2 * 0.28f, num3, r.Y, r.X, (float)r.Y + num2 * 0.05f, r.X, (float)r.Y + num2 * 0.38f);
|
||||
graphicsPath.AddBezier(r.X, (float)r.Y + num2 * 0.38f, r.X, (float)r.Y + num2 * 0.68f, num3, (float)r.Y + num2 * 0.82f, num3, r.Bottom);
|
||||
graphicsPath.AddBezier(num3, r.Bottom, num3, (float)r.Y + num2 * 0.82f, r.Right, (float)r.Y + num2 * 0.68f, r.Right, (float)r.Y + num2 * 0.38f);
|
||||
graphicsPath.AddBezier(r.Right, (float)r.Y + num2 * 0.38f, r.Right, (float)r.Y + num2 * 0.05f, num3, r.Y, num3, (float)r.Y + num2 * 0.28f);
|
||||
graphicsPath.CloseFigure();
|
||||
return graphicsPath;
|
||||
}
|
||||
|
||||
private void DrawName(Graphics g)
|
||||
{
|
||||
Graphics dc = g;
|
||||
string name = Item.Name;
|
||||
Font caption = Fonts.Caption;
|
||||
Rectangle item = Column().Name;
|
||||
Color foreColor;
|
||||
if (Enabled)
|
||||
{
|
||||
foreColor = ((_active || _hover) ? ControlInk.Text1 : TextOnFill);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreColor = ControlInk.TextDisabledInk;
|
||||
}
|
||||
TextRenderer.DrawText(dc, name, caption, item, foreColor, TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GameProfileManagerSection
|
||||
{
|
||||
private sealed class Row
|
||||
{
|
||||
public GameProfile Profile;
|
||||
|
||||
public Label Name;
|
||||
|
||||
public Label Detail;
|
||||
|
||||
public GlassButton Rename;
|
||||
|
||||
public GlassButton Delete;
|
||||
}
|
||||
|
||||
private readonly Control _parent;
|
||||
|
||||
private readonly Font _bodyFont;
|
||||
|
||||
private readonly Font _captionFont;
|
||||
|
||||
private readonly Func<string, bool>? _isRunning;
|
||||
|
||||
private readonly Func<IReadOnlyList<GameProfile>> _load;
|
||||
|
||||
private readonly Action<GameProfile> _save;
|
||||
|
||||
private readonly Action<string> _remove;
|
||||
|
||||
private readonly Func<string?>? _runningGameName;
|
||||
|
||||
private readonly Action? _saveCurrentLook;
|
||||
|
||||
private readonly Label _caption;
|
||||
|
||||
private readonly Label _empty;
|
||||
|
||||
private readonly GlassButton _saveNow;
|
||||
|
||||
private readonly Label _saveHint;
|
||||
|
||||
private readonly List<Row> _rows = new List<Row>();
|
||||
|
||||
public const string RowNameControl = "profileRowName";
|
||||
|
||||
public const string RowDetailControl = "profileRowDetail";
|
||||
|
||||
public const string SaveNowControl = "profileSaveNow";
|
||||
|
||||
public const string SaveHintControl = "profileSaveHint";
|
||||
|
||||
private bool _visible = true;
|
||||
|
||||
private static int RowHeight => Tokens.Scale(54);
|
||||
|
||||
private static int HeaderHeight => Math.Max(Tokens.Scale(22), Tokens.Scale(28));
|
||||
|
||||
private static int HintHeight => Tokens.Scale(20);
|
||||
|
||||
public int PreferredHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = HeaderHeight + Tokens.Scale(6);
|
||||
if (_saveHint.Visible)
|
||||
{
|
||||
num += HintHeight + Tokens.Scale(6);
|
||||
}
|
||||
return num + ((_rows.Count == 0) ? Tokens.Scale(36) : (_rows.Count * RowHeight));
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? Changed;
|
||||
|
||||
public GameProfileManagerSection(Control parent, Font captionFont, Font bodyFont, Func<IReadOnlyList<GameProfile>>? load = null, Action<GameProfile>? save = null, Action<string>? remove = null, Func<string, bool>? isRunning = null, Func<string?>? runningGameName = null, Action? saveCurrentLook = null)
|
||||
{
|
||||
_parent = parent;
|
||||
_bodyFont = bodyFont;
|
||||
_captionFont = captionFont;
|
||||
_isRunning = isRunning;
|
||||
_runningGameName = runningGameName;
|
||||
_saveCurrentLook = saveCurrentLook;
|
||||
_load = load ?? new Func<IReadOnlyList<GameProfile>>(GameProfileStore.Load);
|
||||
_save = save ?? new Action<GameProfile>(GameProfileStore.Set);
|
||||
_remove = remove ?? new Action<string>(GameProfileStore.Remove);
|
||||
_caption = new Label
|
||||
{
|
||||
Text = UiHelpers.Spaced("SAVED GAME PROFILES"),
|
||||
Font = captionFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft
|
||||
};
|
||||
_parent.Controls.Add(_caption);
|
||||
_empty = new Label
|
||||
{
|
||||
Text = "No saved profiles yet. Pick a game above and save the look on screen, and it will show up here.",
|
||||
Font = bodyFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft
|
||||
};
|
||||
_parent.Controls.Add(_empty);
|
||||
_saveNow = new GlassButton
|
||||
{
|
||||
Text = "Save my colours",
|
||||
Kind = GlassButtonKind.Primary,
|
||||
Name = "profileSaveNow",
|
||||
Visible = false
|
||||
};
|
||||
_saveNow.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
SaveCurrentLookFlow();
|
||||
};
|
||||
_parent.Controls.Add(_saveNow);
|
||||
_saveHint = new Label
|
||||
{
|
||||
Text = "Open a game and this is where you save the colours you're looking at.",
|
||||
Font = bodyFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Name = "profileSaveHint",
|
||||
Visible = false
|
||||
};
|
||||
_parent.Controls.Add(_saveHint);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
foreach (Row row2 in _rows)
|
||||
{
|
||||
_parent.Controls.Remove(row2.Name);
|
||||
_parent.Controls.Remove(row2.Detail);
|
||||
_parent.Controls.Remove(row2.Rename);
|
||||
_parent.Controls.Remove(row2.Delete);
|
||||
row2.Name.Dispose();
|
||||
row2.Detail.Dispose();
|
||||
row2.Rename.Dispose();
|
||||
row2.Delete.Dispose();
|
||||
}
|
||||
_rows.Clear();
|
||||
foreach (GameProfile item in (from p in _load()
|
||||
orderby IsRunningNow(p) descending, ChangesSomething(p) descending
|
||||
select p).ThenBy((GameProfile p) => p.DisplayName, StringComparer.OrdinalIgnoreCase).ToList())
|
||||
{
|
||||
GameProfile captured = item;
|
||||
Row row = new Row
|
||||
{
|
||||
Profile = captured
|
||||
};
|
||||
bool flag = IsRunningNow(captured);
|
||||
row.Name = new Label
|
||||
{
|
||||
Text = (flag ? (captured.DisplayName + " ● running now") : captured.DisplayName),
|
||||
Font = _bodyFont,
|
||||
ForeColor = (flag ? Theme.Accent : Theme.Text),
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Name.Name = "profileRowName";
|
||||
_parent.Controls.Add(row.Name);
|
||||
row.Detail = new Label
|
||||
{
|
||||
Text = (ChangesSomething(captured) ? GameProfileSection.Describe(captured) : "Changes nothing yet — set your colours with this game open, then save."),
|
||||
Font = _captionFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Detail.Name = "profileRowDetail";
|
||||
_parent.Controls.Add(row.Detail);
|
||||
row.Rename = new GlassButton
|
||||
{
|
||||
Text = "Rename",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Rename.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
RenameFlow(captured);
|
||||
};
|
||||
_parent.Controls.Add(row.Rename);
|
||||
row.Delete = new GlassButton
|
||||
{
|
||||
Text = "Delete",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Delete.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
DeleteFlow(captured);
|
||||
};
|
||||
_parent.Controls.Add(row.Delete);
|
||||
_rows.Add(row);
|
||||
}
|
||||
RefreshSaveAffordance();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
private void RefreshSaveAffordance()
|
||||
{
|
||||
string text = null;
|
||||
if (_saveCurrentLook != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
text = _runningGameName?.Invoke();
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = null;
|
||||
}
|
||||
}
|
||||
bool flag = _visible && _saveCurrentLook != null && !string.IsNullOrWhiteSpace(text);
|
||||
_saveNow.Visible = flag;
|
||||
if (flag)
|
||||
{
|
||||
_saveNow.Text = "Save my colours for " + GameProfileSection.Shorten(text);
|
||||
}
|
||||
bool flag2 = _visible && _saveCurrentLook != null && !flag;
|
||||
_saveHint.Visible = flag2;
|
||||
_saveHint.Text = ((_rows.Count == 0) ? "No game profiles yet. Open a game, set your colours, then save them here." : "Open a game and this is where you save the colours you're looking at.");
|
||||
_empty.Visible = _visible && _rows.Count == 0 && !flag2;
|
||||
}
|
||||
|
||||
private void SaveCurrentLookFlow()
|
||||
{
|
||||
_saveCurrentLook?.Invoke();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
_visible = visible;
|
||||
_caption.Visible = visible;
|
||||
RefreshSaveAffordance();
|
||||
foreach (Row row in _rows)
|
||||
{
|
||||
row.Name.Visible = visible;
|
||||
row.Rename.Visible = visible;
|
||||
row.Delete.Visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
private void RenameFlow(GameProfile profile)
|
||||
{
|
||||
string text = Prompt.Ask("Rename profile", profile.DisplayName);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
Rename(profile.GameId, text);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteFlow(GameProfile profile)
|
||||
{
|
||||
if (GlassDialog.Show(_parent.FindForm(), "Delete this profile?", $"\"{profile.DisplayName}\" will be removed. PlexusX will stop switching to it when {profile.DisplayName} opens. There is no undo - saving a new " + "profile for it is the only way back.", GlassDialogButtons.Destructive, GlassDialogTone.Warning, "Delete profile", "Keep it") == DialogResult.Yes)
|
||||
{
|
||||
Delete(profile.GameId);
|
||||
}
|
||||
}
|
||||
|
||||
private void Rename(string gameId, string newName)
|
||||
{
|
||||
GameProfile gameProfile = _load().FirstOrDefault((GameProfile p) => p.GameId == gameId);
|
||||
if (gameProfile != null)
|
||||
{
|
||||
gameProfile.DisplayName = newName;
|
||||
_save(gameProfile);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Delete(string gameId)
|
||||
{
|
||||
_remove(gameId);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
internal void TestRename(string gameId, string newName)
|
||||
{
|
||||
Rename(gameId, newName);
|
||||
}
|
||||
|
||||
internal void TestDelete(string gameId)
|
||||
{
|
||||
Delete(gameId);
|
||||
}
|
||||
|
||||
private bool IsRunningNow(GameProfile p)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _isRunning?.Invoke(p.GameId) ?? false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ChangesSomething(GameProfile p)
|
||||
{
|
||||
return GameProfileSection.ChangesAnything(p);
|
||||
}
|
||||
|
||||
public void Place(int x, int y, int width)
|
||||
{
|
||||
int num = Tokens.Scale(22);
|
||||
int headerHeight = HeaderHeight;
|
||||
int num2 = Tokens.Scale(8);
|
||||
int num3 = Math.Min(Tokens.Scale(196), Math.Max(Tokens.Scale(120), width / 2));
|
||||
int num4 = Tokens.Scale(28);
|
||||
_caption.SetBounds(x, y + (headerHeight - num) / 2, Math.Max(Tokens.Scale(40), width - num3 - num2), num);
|
||||
_saveNow.SetBounds(x + width - num3, y + (headerHeight - num4) / 2, num3, num4);
|
||||
y += headerHeight + Tokens.Scale(6);
|
||||
_saveHint.SetBounds(x, y, width, HintHeight);
|
||||
if (_saveHint.Visible)
|
||||
{
|
||||
y += HintHeight + Tokens.Scale(6);
|
||||
}
|
||||
_empty.SetBounds(x, y, width, Tokens.Scale(36));
|
||||
if (_rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num5 = Tokens.Scale(76);
|
||||
int num6 = Tokens.Scale(28);
|
||||
int num7 = Tokens.Scale(8);
|
||||
int rowHeight = RowHeight;
|
||||
int num8 = width - 2 * num5 - 2 * num7;
|
||||
int num9 = Tokens.Scale(20);
|
||||
int num10 = Math.Max(Tokens.Scale(18), TextRenderer.MeasureText("Hg", Fonts.Body).Height);
|
||||
int num11 = (rowHeight - (num9 + num10)) / 2;
|
||||
foreach (Row row in _rows)
|
||||
{
|
||||
row.Name.SetBounds(x, y + num11, num8, num9);
|
||||
row.Detail.SetBounds(x, y + num11 + num9, num8, num10);
|
||||
row.Rename.SetBounds(x + num8 + num7, y + (rowHeight - num6) / 2, num5, num6);
|
||||
row.Delete.SetBounds(x + num8 + 2 * num7 + num5, y + (rowHeight - num6) / 2, num5, num6);
|
||||
y += rowHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GlassDialog : SignalDialogWindow
|
||||
{
|
||||
private const int WidthLogical = 460;
|
||||
|
||||
private const int MaxBodyLogical = 420;
|
||||
|
||||
private readonly GlassDialogButtons _buttons;
|
||||
|
||||
private readonly GlassButton _safe;
|
||||
|
||||
private readonly GlassButton? _action;
|
||||
|
||||
internal GlassButton TestOpeningButton => (GlassButton)ActiveControl;
|
||||
|
||||
internal GlassButton? TestActionButton => _action;
|
||||
|
||||
internal GlassButton TestSafeButton => _safe;
|
||||
|
||||
internal static Func<string, string, DialogResult>? InsteadOfShowingForTest { get; set; }
|
||||
|
||||
public static int ButtonCount(GlassDialogButtons b)
|
||||
{
|
||||
if (b != GlassDialogButtons.Ok)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int MeasureHeight(string body, int width)
|
||||
{
|
||||
int logical = Math.Max(80, width - 48);
|
||||
int val = (int)Math.Ceiling((double)(SignalDialogWindow.MeasureBody(body, Tokens.Scale(logical)) * 96) / (double)Tokens.Dpi);
|
||||
return 136 + Math.Min(val, 420);
|
||||
}
|
||||
|
||||
internal GlassDialog(string title, string body, GlassDialogButtons buttons, GlassDialogTone tone, string? primaryText = null, string? secondaryText = null)
|
||||
{
|
||||
GlassDialog glassDialog = this;
|
||||
_buttons = buttons;
|
||||
ChromeTitle = title ?? "PlexusX";
|
||||
ChromeBody = body ?? "";
|
||||
Text = ChromeTitle;
|
||||
AccessibleName = ChromeTitle;
|
||||
AccessibleDescription = ChromeBody;
|
||||
int num = S(460);
|
||||
ChromeBodyHeight = Math.Min(SignalDialogWindow.MeasureBody(ChromeBody, num - 2 * S(24)), S(420));
|
||||
ClientSize = new Size(num, BodyTop + ChromeBodyHeight + S(24) + S(32) + S(20));
|
||||
if (buttons == GlassDialogButtons.Ok)
|
||||
{
|
||||
_safe = FooterButton(secondaryText ?? primaryText ?? "Close", GlassButtonKind.Secondary, "DialogClose");
|
||||
_safe.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(DialogResult.OK);
|
||||
};
|
||||
Controls.Add(_safe);
|
||||
PlaceFooter(_safe);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag = buttons == GlassDialogButtons.Destructive;
|
||||
_action = FooterButton(primaryText ?? "Continue", flag ? GlassButtonKind.Destructive : GlassButtonKind.Primary, "DialogAction");
|
||||
_action.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(Affirmative(buttons));
|
||||
};
|
||||
_safe = FooterButton(secondaryText ?? "Cancel", GlassButtonKind.Secondary, "DialogSafe");
|
||||
_safe.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(Negative(buttons));
|
||||
};
|
||||
Controls.Add(_safe);
|
||||
Controls.Add(_action);
|
||||
PlaceFooter(_safe, _action);
|
||||
}
|
||||
GlassDialogButtons glassDialogButtons = buttons;
|
||||
GlassButton glassButton = (((uint)(glassDialogButtons - 1) <= 1u) ? _action : _safe);
|
||||
if (_action != null)
|
||||
{
|
||||
_safe.TabIndex = ((glassButton != _safe) ? 1 : 0);
|
||||
_action.TabIndex = ((glassButton != _action) ? 1 : 0);
|
||||
}
|
||||
ActiveControl = glassButton;
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Escape) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
glassDialog.Answer(e.KeyCode);
|
||||
}
|
||||
};
|
||||
WindowDrag.Enable(this, this);
|
||||
}
|
||||
|
||||
private void Answer(Keys key)
|
||||
{
|
||||
if (key == Keys.Escape)
|
||||
{
|
||||
Finish(Negative(_buttons));
|
||||
return;
|
||||
}
|
||||
GlassDialogButtons buttons = _buttons;
|
||||
bool flag = (uint)(buttons - 1) <= 1u;
|
||||
Finish(flag ? Affirmative(_buttons) : Negative(_buttons));
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
bool flag = (keyData & (Keys.Control | Keys.Alt)) == 0;
|
||||
if (flag)
|
||||
{
|
||||
Keys keys = keyData & Keys.KeyCode;
|
||||
bool flag2 = ((keys == Keys.Return || keys == Keys.Escape) ? true : false);
|
||||
flag = flag2;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
Answer(keyData & Keys.KeyCode);
|
||||
return true;
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
private static DialogResult Affirmative(GlassDialogButtons b)
|
||||
{
|
||||
if ((uint)(b - 2) <= 2u)
|
||||
{
|
||||
return DialogResult.Yes;
|
||||
}
|
||||
return DialogResult.OK;
|
||||
}
|
||||
|
||||
private static DialogResult Negative(GlassDialogButtons b)
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case GlassDialogButtons.Ok:
|
||||
return DialogResult.OK;
|
||||
case GlassDialogButtons.YesNo:
|
||||
case GlassDialogButtons.Destructive:
|
||||
case GlassDialogButtons.ConfirmSafeEnter:
|
||||
return DialogResult.No;
|
||||
default:
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
|
||||
private void Finish(DialogResult result)
|
||||
{
|
||||
DialogResult = result;
|
||||
Close();
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
Answer(key);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window? owner, string title, string body, GlassDialogButtons buttons = GlassDialogButtons.Ok, GlassDialogTone tone = GlassDialogTone.Info, string? primaryText = null, string? secondaryText = null)
|
||||
{
|
||||
Func<string, string, DialogResult> insteadOfShowingForTest = InsteadOfShowingForTest;
|
||||
if (insteadOfShowingForTest != null)
|
||||
{
|
||||
return insteadOfShowingForTest(title, body);
|
||||
}
|
||||
using GlassDialog glassDialog = new GlassDialog(title, body, buttons, tone, primaryText, secondaryText);
|
||||
return (owner != null) ? glassDialog.ShowDialog(owner) : glassDialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public enum GlassDialogButtons
|
||||
{
|
||||
Ok,
|
||||
OkCancel,
|
||||
YesNo,
|
||||
Destructive,
|
||||
ConfirmSafeEnter
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public enum GlassDialogTone
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Danger
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GlassScrollBar : Control
|
||||
{
|
||||
private int _value;
|
||||
|
||||
private int _maximum = 100;
|
||||
|
||||
private int _viewport = 10;
|
||||
|
||||
private bool _hover;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
private int _dragOffset;
|
||||
|
||||
public int Maximum
|
||||
{
|
||||
get
|
||||
{
|
||||
return _maximum;
|
||||
}
|
||||
set
|
||||
{
|
||||
_maximum = Math.Max(0, value);
|
||||
Clamp();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Viewport
|
||||
{
|
||||
get
|
||||
{
|
||||
return _viewport;
|
||||
}
|
||||
set
|
||||
{
|
||||
_viewport = Math.Max(1, value);
|
||||
Clamp();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, 0, Math.Max(0, _maximum - _viewport));
|
||||
if (num != _value)
|
||||
{
|
||||
_value = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Needed => _maximum > _viewport;
|
||||
|
||||
private int TrackTop => 4;
|
||||
|
||||
private int TrackHeight => Math.Max(1, Height - 8);
|
||||
|
||||
private int ThumbHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return TrackHeight;
|
||||
}
|
||||
float num = (float)_viewport / (float)_maximum;
|
||||
return Math.Max(28, (int)((float)TrackHeight * num));
|
||||
}
|
||||
}
|
||||
|
||||
private int ThumbTop
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return TrackTop;
|
||||
}
|
||||
float num = (float)_value / (float)(_maximum - _viewport);
|
||||
return TrackTop + (int)((float)(TrackHeight - ThumbHeight) * num);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? Scrolled;
|
||||
|
||||
public GlassScrollBar()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Width = 8;
|
||||
TabStop = false;
|
||||
}
|
||||
|
||||
private void Clamp()
|
||||
{
|
||||
Value = _value;
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_hover = true;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (e.Button == MouseButtons.Left && Needed)
|
||||
{
|
||||
if (e.Y >= ThumbTop && e.Y <= ThumbTop + ThumbHeight)
|
||||
{
|
||||
_dragging = true;
|
||||
DragTracker.BeginScrollBar();
|
||||
_dragOffset = e.Y - ThumbTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveThumbTo(e.Y - ThumbHeight / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_dragging)
|
||||
{
|
||||
MoveThumbTo(e.Y - _dragOffset);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_dragging)
|
||||
{
|
||||
_dragging = false;
|
||||
DragTracker.EndScrollBar();
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveThumbTo(int top)
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num = TrackHeight - ThumbHeight;
|
||||
if (num > 0)
|
||||
{
|
||||
int num2 = (int)Math.Round(Math.Clamp((float)(top - TrackTop) / (float)num, 0f, 1f) * (float)(_maximum - _viewport));
|
||||
if (num2 != _value)
|
||||
{
|
||||
_value = num2;
|
||||
Invalidate();
|
||||
Scrolled?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float radius = Math.Max(1f, (float)(Width - 4) / 2f);
|
||||
using (GraphicsPath path = Glass.RoundedPath(new RectangleF(2f, TrackTop, Math.Max(1, Width - 4), TrackHeight), radius))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Color.FromArgb(28, Theme.GlassEdge));
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using GraphicsPath path2 = Glass.RoundedPath(new RectangleF(2f, ThumbTop, Math.Max(1, Width - 4), ThumbHeight), radius);
|
||||
Color baseColor = (Theme.IsLight ? Theme.AccentDim : Theme.Accent);
|
||||
using SolidBrush brush2 = new SolidBrush((_dragging || _hover) ? Color.FromArgb(_dragging ? 200 : 150, baseColor) : Color.FromArgb(Theme.IsLight ? 60 : 90, Theme.Text));
|
||||
graphics.FillPath(brush2, path2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public class GlassShellForm : SignalDialogWindow
|
||||
{
|
||||
private readonly string _title;
|
||||
|
||||
private Rectangle _closeRect;
|
||||
|
||||
private bool _overClose;
|
||||
|
||||
private bool _showClose = true;
|
||||
|
||||
private bool _paintsTitle = true;
|
||||
|
||||
protected static int Pad => Tokens.Scale(24);
|
||||
|
||||
protected new static int ContentTop => Tokens.Scale(56);
|
||||
|
||||
public bool ShowClose
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showClose;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_showClose != value)
|
||||
{
|
||||
_showClose = value;
|
||||
if (!value)
|
||||
{
|
||||
_closeRect = Rectangle.Empty;
|
||||
_overClose = false;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PaintsTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _paintsTitle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_paintsTitle != value)
|
||||
{
|
||||
_paintsTitle = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GlassShellForm(string title)
|
||||
{
|
||||
_title = title;
|
||||
Text = title;
|
||||
AccessibleName = title;
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
CancelShell();
|
||||
}
|
||||
};
|
||||
WindowDrag.Enable(this, this, (Point p) => _closeRect.Contains(p));
|
||||
}
|
||||
|
||||
protected virtual void CancelShell()
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
bool flag = _closeRect.Contains(e.Location);
|
||||
if (flag != _overClose)
|
||||
{
|
||||
_overClose = flag;
|
||||
Invalidate(new Rectangle(_closeRect.X - 4, _closeRect.Y - 4, _closeRect.Width + 8, _closeRect.Height + 8));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (_overClose)
|
||||
{
|
||||
_overClose = false;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (e.Button == MouseButtons.Left && _closeRect.Contains(e.Location))
|
||||
{
|
||||
CancelShell();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
int num = S(24);
|
||||
int num2 = S(28);
|
||||
_closeRect = (_showClose ? new Rectangle(Width - num2 - S(12), S(12), num2, num2) : Rectangle.Empty);
|
||||
int num3 = (_showClose ? (_closeRect.Left - S(8)) : (Width - num));
|
||||
if (_paintsTitle)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, _title, Fonts.Title, new Rectangle(SignalDialogWindow.Ink(num + S(2), Fonts.Title), S(18), num3 - (num + S(2)) + SignalDialogWindow.GlyphPad(Fonts.Title), S(28)), Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
if (_showClose)
|
||||
{
|
||||
if (_overClose)
|
||||
{
|
||||
GraphicsState gstate = graphics.Save();
|
||||
graphics.TranslateTransform(_closeRect.X, _closeRect.Y);
|
||||
ControlInk.PaintBox(graphics, _closeRect.Size, S(4), ControlInk.Hairline(ChromeDpi), ControlInk.Hover, Color.Empty);
|
||||
graphics.Restore(gstate);
|
||||
}
|
||||
int num4 = S(16);
|
||||
SignalIcons.Draw(graphics, SignalIcon.Close, new RectangleF((float)_closeRect.X + (float)(num2 - num4) / 2f, (float)_closeRect.Y + (float)(num2 - num4) / 2f, num4, num4), _overClose ? ControlInk.Text1 : ControlInk.Text2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class HueWheel : Control
|
||||
{
|
||||
internal readonly record struct RingNameSlot(int Degrees, string Name, Rectangle Rect, PointF TickEnd);
|
||||
|
||||
public const int MinHue = -180;
|
||||
|
||||
public const int MaxHue = 180;
|
||||
|
||||
private static readonly float RefR = 0.82f;
|
||||
|
||||
private static readonly float RefG = 0.38f;
|
||||
|
||||
private static readonly float RefB = 0.34f;
|
||||
|
||||
private Bitmap? _disc;
|
||||
|
||||
private int _hue;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
public const int MinDarkenHue = 0;
|
||||
|
||||
public const int MaxDarkenHue = 359;
|
||||
|
||||
public const int MinDarken = 0;
|
||||
|
||||
public const int MaxDarken = 400;
|
||||
|
||||
private bool _darkenMode;
|
||||
|
||||
private int _darkenHue = 120;
|
||||
|
||||
private int _darken;
|
||||
|
||||
private bool _hasDarkenSelection;
|
||||
|
||||
private const int RingBandPx = 28;
|
||||
|
||||
private bool _ring;
|
||||
|
||||
private Color _surface = Color.Empty;
|
||||
|
||||
private static readonly (int Degrees, string Name)[] RingNames = new (int, string)[6]
|
||||
{
|
||||
(0, "Red"),
|
||||
(60, "Yellow"),
|
||||
(120, "Green"),
|
||||
(180, "Cyan"),
|
||||
(240, "Blue"),
|
||||
(300, "Magenta")
|
||||
};
|
||||
|
||||
private (int Diameter, bool Ring, bool Darken) _failedDisc = (Diameter: -1, Ring: false, Darken: false);
|
||||
|
||||
public bool DarkenMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darkenMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_darkenMode != value)
|
||||
{
|
||||
_darkenMode = value;
|
||||
TabStop = value;
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int DarkenHue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darkenHue;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = (value % 360 + 360) % 360;
|
||||
if (num != _darkenHue || !_hasDarkenSelection)
|
||||
{
|
||||
_darkenHue = num;
|
||||
_hasDarkenSelection = true;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Ring
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ring;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_ring != value)
|
||||
{
|
||||
_ring = value;
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Color Surface
|
||||
{
|
||||
get
|
||||
{
|
||||
return _surface;
|
||||
}
|
||||
set
|
||||
{
|
||||
_surface = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public string CentreText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_darkenMode)
|
||||
{
|
||||
if (_hue != 0)
|
||||
{
|
||||
return "Colours turned";
|
||||
}
|
||||
return "No turn";
|
||||
}
|
||||
if (_hasDarkenSelection)
|
||||
{
|
||||
if (_darken != 0)
|
||||
{
|
||||
return HueName(_darkenHue) + " darker";
|
||||
}
|
||||
return "Not darkened";
|
||||
}
|
||||
return "Pick a colour to darken";
|
||||
}
|
||||
}
|
||||
|
||||
private int RingAngle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_darkenMode)
|
||||
{
|
||||
if (_hue < 0)
|
||||
{
|
||||
return 360 + _hue;
|
||||
}
|
||||
return _hue;
|
||||
}
|
||||
return _darkenHue;
|
||||
}
|
||||
}
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
public int Darken
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darken;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, 0, 400);
|
||||
if (num != _darken)
|
||||
{
|
||||
_darken = num;
|
||||
if (num > 0)
|
||||
{
|
||||
_hasDarkenSelection = true;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, -180, 180);
|
||||
if (num != _hue)
|
||||
{
|
||||
_hue = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Diameter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_ring)
|
||||
{
|
||||
return Math.Max(1, Math.Min(Width, Height) - Tokens.Scale(6));
|
||||
}
|
||||
return Math.Max(1, Math.Min(Tokens.Scale(176), Math.Min(Width, Height) - Tokens.Scale(80)));
|
||||
}
|
||||
}
|
||||
|
||||
private bool SeeThrough
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!(Parent is CardPanel))
|
||||
{
|
||||
if (SlateSurface.Active)
|
||||
{
|
||||
return AppBackground.IsSet;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? DarkenChanged;
|
||||
|
||||
public event EventHandler? HueChanged;
|
||||
|
||||
internal static string NearestName(int degrees)
|
||||
{
|
||||
return HueName(degrees);
|
||||
}
|
||||
|
||||
private static string HueName(int degrees)
|
||||
{
|
||||
int d = (degrees % 360 + 360) % 360;
|
||||
return RingNames.OrderBy(((int Degrees, string Name) n) => Math.Min(Math.Abs(n.Degrees - d), 360 - Math.Abs(n.Degrees - d))).First().Name;
|
||||
}
|
||||
|
||||
private void PaintRing(Graphics g)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
int diameter = Diameter;
|
||||
float num = (float)Width / 2f;
|
||||
float num2 = (float)Height / 2f;
|
||||
float num3 = (float)diameter / 2f;
|
||||
float num4 = S(28f);
|
||||
float num5 = num3 - num4;
|
||||
Bitmap bitmap = Disc();
|
||||
if (bitmap != null)
|
||||
{
|
||||
g.DrawImageUnscaled(bitmap, (int)(num - num3), (int)(num2 - num3));
|
||||
}
|
||||
using (Pen pen = new Pen(ControlInk.Border, Math.Max(1f, S(1f))))
|
||||
{
|
||||
g.DrawEllipse(pen, num - num3 - S(0.5f), num2 - num3 - S(0.5f), 2f * num3 + S(1f), 2f * num3 + S(1f));
|
||||
g.DrawEllipse(pen, num - num5 + S(0.5f), num2 - num5 + S(0.5f), 2f * num5 - S(1f), 2f * num5 - S(1f));
|
||||
}
|
||||
if (_darkenMode)
|
||||
{
|
||||
float num6 = num5 - S(8f);
|
||||
using Pen pen2 = new Pen(ControlInk.Track, S(3f));
|
||||
g.DrawEllipse(pen2, num - num6, num2 - num6, 2f * num6, 2f * num6);
|
||||
if (_darken > 0)
|
||||
{
|
||||
float num7 = (float)_darken / 400f * 50f;
|
||||
using Pen pen3 = new Pen(ControlInk.Text1, S(3f))
|
||||
{
|
||||
StartCap = LineCap.Round,
|
||||
EndCap = LineCap.Round
|
||||
};
|
||||
g.DrawArc(pen3, num - num6, num2 - num6, 2f * num6, 2f * num6, (float)_darkenHue - num7, 2f * num7);
|
||||
}
|
||||
}
|
||||
int ringAngle = RingAngle;
|
||||
using (Pen pen4 = new Pen(ControlInk.Text2, S(1.5f)))
|
||||
{
|
||||
using Pen pen5 = new Pen(ControlInk.TextDisabled, Math.Max(1f, S(1f)));
|
||||
for (int i = 0; i < 360; i += 30)
|
||||
{
|
||||
bool flag = i % 60 == 0;
|
||||
double num8 = (double)i * Math.PI / 180.0;
|
||||
float num9 = (float)Math.Cos(num8);
|
||||
float num10 = (float)Math.Sin(num8);
|
||||
float num11 = num3 + S(3f);
|
||||
float num12 = num3 + S(flag ? 9 : 6);
|
||||
g.DrawLine(flag ? pen4 : pen5, num + num9 * num11, num2 + num10 * num11, num + num9 * num12, num2 + num10 * num12);
|
||||
}
|
||||
}
|
||||
Font captionBold = Fonts.CaptionBold;
|
||||
RingNameSlot[] array = RingNameSlots(g, num, num2, num3);
|
||||
for (int j = 0; j < array.Length; j++)
|
||||
{
|
||||
RingNameSlot ringNameSlot = array[j];
|
||||
bool flag2 = (!_darkenMode || _hasDarkenSelection) && ringAngle % 60 == 0 && ringNameSlot.Degrees == ringAngle;
|
||||
TextRenderer.DrawText(g, ringNameSlot.Name, captionBold, ringNameSlot.Rect.Location, flag2 ? ControlInk.Text1 : ControlInk.Text3, TextFormatFlags.NoPadding);
|
||||
}
|
||||
HueAt(ringAngle, out var r, out var g2, out var b);
|
||||
Color color = Hsl(r, g2, b);
|
||||
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding;
|
||||
int num13 = (int)S(100f);
|
||||
int num14 = (int)Math.Round(num - (float)num13 / 2f);
|
||||
int num15 = Fonts.LineHeight(FontRole.Caption);
|
||||
int num16 = Math.Max(num15, (int)Math.Ceiling((float)TextRenderer.MeasureText(g, CentreText, Fonts.Caption, new Size(num13, int.MaxValue), flags).Height / (float)num15) * num15);
|
||||
bool flag3 = !_darkenMode || _hasDarkenSelection;
|
||||
float num17 = (flag3 ? S(22f) : 0f);
|
||||
float num18 = S(46f) + S(5f) + S(1f) + num17 + S(1f) + (float)num16;
|
||||
float num19 = num2 - num18 / 2f;
|
||||
float num20 = S(46f);
|
||||
if (flag3)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(ControlInk.Edge))
|
||||
{
|
||||
g.FillEllipse(brush, num - num20 / 2f - S(1f), num19 - S(1f), num20 + S(2f), num20 + S(2f));
|
||||
}
|
||||
using SolidBrush brush2 = new SolidBrush(_darkenMode ? DarkenedSwatch(color) : color);
|
||||
g.FillEllipse(brush2, num - num20 / 2f, num19, num20, num20);
|
||||
}
|
||||
float num21 = num19 + num20 + S(5f) + S(1f);
|
||||
if (num17 > 0f)
|
||||
{
|
||||
string text = (_darkenMode ? (_darken + "%") : (_hue + "°"));
|
||||
TextRenderer.DrawText(g, text, Fonts.For(FontRole.Title), new Rectangle(num14 - (int)S(20f), (int)Math.Round(num21 + num17 / 2f) - (int)S(14f), num13 + (int)S(40f), (int)S(28f)), ControlInk.Text1, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
num21 += num17;
|
||||
}
|
||||
num21 += S(1f);
|
||||
TextRenderer.DrawText(g, CentreText, Fonts.Caption, new Rectangle(num14, (int)Math.Round(num21), num13, num16), ControlInk.Text2, flags);
|
||||
if (flag3)
|
||||
{
|
||||
double num22 = (double)ringAngle * Math.PI / 180.0;
|
||||
float num23 = num3 - num4 / 2f;
|
||||
float num24 = num + (float)Math.Cos(num22) * num23;
|
||||
float num25 = num2 + (float)Math.Sin(num22) * num23;
|
||||
float num26 = S(15f);
|
||||
using (SolidBrush brush3 = new SolidBrush(ControlInk.KnobRing))
|
||||
{
|
||||
g.FillEllipse(brush3, num24 - num26 - S(2f), num25 - num26 - S(2f), 2f * num26 + S(4f), 2f * num26 + S(4f));
|
||||
}
|
||||
using (SolidBrush brush4 = new SolidBrush(ControlInk.Focus))
|
||||
{
|
||||
g.FillEllipse(brush4, num24 - num26, num25 - num26, 2f * num26, 2f * num26);
|
||||
}
|
||||
float num27 = num26 - S(3f);
|
||||
using (SolidBrush brush5 = new SolidBrush(color))
|
||||
{
|
||||
g.FillEllipse(brush5, num24 - num27, num25 - num27, 2f * num27, 2f * num27);
|
||||
}
|
||||
g.PixelOffsetMode = PixelOffsetMode.Default;
|
||||
if (_darkenMode && Focused && ShowFocusCues)
|
||||
{
|
||||
ControlInk.PaintFocusRing(g, new Rectangle((int)(num - num3), (int)(num2 - num3), diameter, diameter), num3, ControlInk.Dpi(this));
|
||||
}
|
||||
}
|
||||
static float S(float px)
|
||||
{
|
||||
return px * (float)Tokens.Scale(100) / 100f;
|
||||
}
|
||||
}
|
||||
|
||||
private RingNameSlot[] RingNameSlots(Graphics g, float cx, float cy, float outer)
|
||||
{
|
||||
Font captionBold = Fonts.CaptionBold;
|
||||
RingNameSlot[] array = new RingNameSlot[RingNames.Length];
|
||||
for (int i = 0; i < RingNames.Length; i++)
|
||||
{
|
||||
(int Degrees, string Name) tuple = RingNames[i];
|
||||
int item = tuple.Degrees;
|
||||
string item2 = tuple.Name;
|
||||
double num = (double)item * Math.PI / 180.0;
|
||||
float num2 = (float)Math.Cos(num);
|
||||
float num3 = (float)Math.Sin(num);
|
||||
float num4 = cx + num2 * (outer + S(12f));
|
||||
float num5 = cy + num3 * (outer + S(12f));
|
||||
Size size = TextRenderer.MeasureText(g, item2, captionBold, Size.Empty, TextFormatFlags.NoPadding);
|
||||
float num6;
|
||||
if (num2 > 0.3f)
|
||||
{
|
||||
num6 = num4;
|
||||
}
|
||||
else
|
||||
{
|
||||
num6 = ((num2 < -0.3f) ? (num4 - (float)size.Width) : (num4 - (float)size.Width / 2f));
|
||||
}
|
||||
if (Math.Abs(num3) > 0.3f)
|
||||
{
|
||||
num5 += (float)(Math.Sign(num3) * size.Height) / 2f;
|
||||
}
|
||||
Rectangle rect = new Rectangle(new Point((int)Math.Round(num6), (int)Math.Round(num5 - (float)size.Height / 2f)), size);
|
||||
PointF tickEnd = new PointF(cx + num2 * (outer + S(9f)), cy + num3 * (outer + S(9f)));
|
||||
array[i] = new RingNameSlot(item, item2, rect, tickEnd);
|
||||
}
|
||||
return array;
|
||||
static float S(float px)
|
||||
{
|
||||
return px * (float)Tokens.Scale(100) / 100f;
|
||||
}
|
||||
}
|
||||
|
||||
internal RingNameSlot[] RingNameSlotsForTest()
|
||||
{
|
||||
using Bitmap image = new Bitmap(1, 1);
|
||||
using Graphics g = Graphics.FromImage(image);
|
||||
float outer = (float)Diameter / 2f;
|
||||
return RingNameSlots(g, (float)Width / 2f, (float)Height / 2f, outer);
|
||||
}
|
||||
|
||||
private static Color Hsl(float r, float g, float b)
|
||||
{
|
||||
float num = (1f - Math.Abs(0.100000024f)) * 0.88f;
|
||||
float num2 = 0.55f - num / 2f;
|
||||
return Color.FromArgb(Byte(num2 + r * num), Byte(num2 + g * num), Byte(num2 + b * num));
|
||||
}
|
||||
|
||||
private Color DarkenedSwatch(Color colour)
|
||||
{
|
||||
if (_darken == 0)
|
||||
{
|
||||
return colour;
|
||||
}
|
||||
var (num, num2, num3) = SaturationMetrics.Transform(SaturationMetrics.Build(SaturationMetric.Rec709, 1f, 1f, new ColourDepth(SaturationMetric.Rec709, _darken, _darkenHue)), (double)(int)colour.R / 255.0, (double)(int)colour.G / 255.0, (double)(int)colour.B / 255.0);
|
||||
return Color.FromArgb(Byte((float)num), Byte((float)num2), Byte((float)num3));
|
||||
}
|
||||
|
||||
private void SetDarken(int hue, int amount)
|
||||
{
|
||||
int num = (hue % 360 + 360) % 360;
|
||||
int num2 = Math.Clamp(amount, 0, 400);
|
||||
if (num != _darkenHue || num2 != _darken || !_hasDarkenSelection)
|
||||
{
|
||||
_darkenHue = num;
|
||||
_darken = num2;
|
||||
_hasDarkenSelection = true;
|
||||
Invalidate();
|
||||
DarkenChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressAt(Point p)
|
||||
{
|
||||
OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, p.X, p.Y, 0));
|
||||
OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, p.X, p.Y, 0));
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
internal Point PointFor(int angleDegrees, double strength)
|
||||
{
|
||||
int diameter = Diameter;
|
||||
double num = (double)(Width - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num2 = (double)(Height - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num3 = (double)angleDegrees * Math.PI / 180.0;
|
||||
double num4 = (double)diameter / 2.0 * Math.Clamp(strength, 0.0, 1.0);
|
||||
return new Point((int)Math.Round(num + Math.Cos(num3) * num4), (int)Math.Round(num2 + Math.Sin(num3) * num4));
|
||||
}
|
||||
|
||||
protected override bool IsInputKey(Keys keyData)
|
||||
{
|
||||
bool flag = _darkenMode;
|
||||
if (flag)
|
||||
{
|
||||
Keys keys = keyData & Keys.KeyCode;
|
||||
bool flag2 = (((uint)(keys - 36) <= 4u || keys == Keys.Delete) ? true : false);
|
||||
flag = flag2;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return base.IsInputKey(keyData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
bool shift = e.Shift;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case Keys.Right:
|
||||
SetDarken(_darkenHue + ((!shift) ? 1 : 15), _darken);
|
||||
break;
|
||||
case Keys.Left:
|
||||
SetDarken(_darkenHue - ((!shift) ? 1 : 15), _darken);
|
||||
break;
|
||||
case Keys.Up:
|
||||
SetDarken(_darkenHue, _darken + (shift ? 50 : 5));
|
||||
break;
|
||||
case Keys.Down:
|
||||
SetDarken(_darkenHue, _darken - (shift ? 50 : 5));
|
||||
break;
|
||||
case Keys.Home:
|
||||
case Keys.Delete:
|
||||
SetDarken(120, 0);
|
||||
break;
|
||||
case Keys.Select:
|
||||
case Keys.Print:
|
||||
case Keys.Execute:
|
||||
case Keys.Snapshot:
|
||||
case Keys.Insert:
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDoubleClick(EventArgs e)
|
||||
{
|
||||
base.OnDoubleClick(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(120, 0);
|
||||
}
|
||||
else if (_hue != 0)
|
||||
{
|
||||
_hue = 0;
|
||||
Invalidate();
|
||||
HueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public HueWheel()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
TabStop = false;
|
||||
Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
if (SeeThrough)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
if (!SeeThrough)
|
||||
{
|
||||
g.Clear((!_surface.IsEmpty) ? _surface : (Parent?.BackColor ?? Theme.Background));
|
||||
}
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintBody(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintBody(Graphics g)
|
||||
{
|
||||
if (_ring)
|
||||
{
|
||||
PaintRing(g);
|
||||
return;
|
||||
}
|
||||
Bitmap bitmap = Disc();
|
||||
int diameter = Diameter;
|
||||
int num = (Width - diameter) / 2;
|
||||
int num2 = (Height - diameter) / 2;
|
||||
if (bitmap != null)
|
||||
{
|
||||
g.DrawImageUnscaled(bitmap, num, num2);
|
||||
}
|
||||
double num3 = (_darkenMode ? ((double)_darken / 400.0) : ((double)Math.Abs(_hue) / 180.0));
|
||||
double num4 = (double)(_darkenMode ? _darkenHue : ((_hue >= 0) ? _hue : (360 + _hue))) * Math.PI / 180.0;
|
||||
int num5 = num + diameter / 2;
|
||||
int num6 = num2 + diameter / 2;
|
||||
int num7 = (int)Math.Round(((double)diameter / 2.0 - (double)Tokens.Scale(7)) * num3);
|
||||
Point point = new Point(num5 + (int)Math.Round(Math.Cos(num4) * (double)num7), num6 + (int)Math.Round(Math.Sin(num4) * (double)num7));
|
||||
int num8 = Tokens.Scale(11);
|
||||
using (SolidBrush brush = new SolidBrush(Theme.Accent))
|
||||
{
|
||||
g.FillEllipse(brush, point.X - num8 / 2, point.Y - num8 / 2, num8, num8);
|
||||
}
|
||||
using (Pen pen = new Pen(Theme.Background, Tokens.Scale(2)))
|
||||
{
|
||||
g.DrawEllipse(pen, point.X - num8 / 2, point.Y - num8 / 2, num8, num8);
|
||||
}
|
||||
if (_darkenMode && Focused && ShowFocusCues)
|
||||
{
|
||||
ControlInk.PaintFocusRing(g, new Rectangle(num, num2, diameter, diameter), (float)diameter / 2f, ControlInk.Dpi(this));
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap? Disc()
|
||||
{
|
||||
if (_disc != null)
|
||||
{
|
||||
return _disc;
|
||||
}
|
||||
(int, bool, bool) tuple = (Diameter, _ring, _darkenMode);
|
||||
(int, bool, bool) failedDisc = _failedDisc;
|
||||
(int, bool, bool) tuple2 = tuple;
|
||||
if (failedDisc.Item1 == tuple2.Item1 && failedDisc.Item2 == tuple2.Item2 && failedDisc.Item3 == tuple2.Item3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
FailPointForTest?.Invoke("build");
|
||||
return _disc = BuildDisc(Diameter);
|
||||
}
|
||||
catch (Exception ex) when (PaintGuard.IsGdiFailure(ex))
|
||||
{
|
||||
_failedDisc = tuple;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap BuildDisc(int d)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(d, d, PixelFormat.Format32bppArgb);
|
||||
BitmapData bitmapData;
|
||||
try
|
||||
{
|
||||
bitmapData = bitmap.LockBits(new Rectangle(0, 0, d, d), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
catch
|
||||
{
|
||||
bitmap.Dispose();
|
||||
throw;
|
||||
}
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
byte[] array = new byte[bitmapData.Stride];
|
||||
float num = (float)d / 2f;
|
||||
float num2 = num;
|
||||
for (int i = 0; i < d; i++)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
for (int j = 0; j < d; j++)
|
||||
{
|
||||
float num3 = (float)j - num + 0.5f;
|
||||
float num4 = (float)i - num + 0.5f;
|
||||
float num5 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
|
||||
if (num5 > num2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int num6 = (int)Math.Round(Math.Atan2(num4, num3) * 180.0 / Math.PI);
|
||||
if (num6 < 0)
|
||||
{
|
||||
num6 += 360;
|
||||
}
|
||||
int degrees = ((num6 > 180) ? (num6 - 360) : num6);
|
||||
float num7 = (_ring ? 1f : (num5 / num2));
|
||||
float channel;
|
||||
float channel2;
|
||||
float channel3;
|
||||
if (_darkenMode || _ring)
|
||||
{
|
||||
HueAt(num6, out var r, out var g, out var b);
|
||||
channel = 0.5f + (r - 0.5f) * num7;
|
||||
channel2 = 0.5f + (g - 0.5f) * num7;
|
||||
channel3 = 0.5f + (b - 0.5f) * num7;
|
||||
if (_ring)
|
||||
{
|
||||
float num8 = Tokens.Scale(28);
|
||||
float num9 = Math.Clamp((num5 - (num2 - num8)) / num8, 0f, 1f);
|
||||
float num10 = (180f + 20f * num9) / 255f;
|
||||
channel = 37f / 255f + r * num10;
|
||||
channel2 = 37f / 255f + g * num10;
|
||||
channel3 = 37f / 255f + b * num10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] array2 = ColourBalance.HueMatrix(degrees);
|
||||
channel = RefR + (array2[0] * RefR + array2[5] * RefG + array2[10] * RefB - RefR) * num7;
|
||||
channel2 = RefG + (array2[1] * RefR + array2[6] * RefG + array2[11] * RefB - RefG) * num7;
|
||||
channel3 = RefB + (array2[2] * RefR + array2[7] * RefG + array2[12] * RefB - RefB) * num7;
|
||||
}
|
||||
byte b2 = ((num5 > num2 - 1.2f) ? ((byte)(255f * Math.Clamp(num2 - num5, 0f, 1.2f) / 1.2f)) : byte.MaxValue);
|
||||
if (_ring)
|
||||
{
|
||||
float num11 = num2 - (float)Tokens.Scale(28);
|
||||
float num12 = Math.Clamp(num2 - num5 + 0.5f, 0f, 1f) * Math.Clamp(num5 - num11 + 0.5f, 0f, 1f);
|
||||
if (num12 <= 0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
b2 = (byte)Math.Round(255f * num12);
|
||||
}
|
||||
int num13 = j * 4;
|
||||
array[num13] = Byte(channel3);
|
||||
array[num13 + 1] = Byte(channel2);
|
||||
array[num13 + 2] = Byte(channel);
|
||||
array[num13 + 3] = b2;
|
||||
}
|
||||
Marshal.Copy(array, 0, bitmapData.Scan0 + i * bitmapData.Stride, array.Length);
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
if (!flag)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private static byte Byte(float channel)
|
||||
{
|
||||
return (byte)Math.Round(Math.Clamp(channel, 0f, 1f) * 255f);
|
||||
}
|
||||
|
||||
private static void HueAt(int degrees, out float r, out float g, out float b)
|
||||
{
|
||||
float num = (float)((degrees % 360 + 360) % 360) / 60f;
|
||||
float num2 = 1f - Math.Abs(num % 2f - 1f);
|
||||
(r, g, b) = (int)num switch
|
||||
{
|
||||
0 => (1f, num2, 0f),
|
||||
1 => (num2, 1f, 0f),
|
||||
2 => (0f, 1f, num2),
|
||||
3 => (0f, num2, 1f),
|
||||
4 => (num2, 0f, 1f),
|
||||
_ => (1f, 0f, num2),
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
if (_darkenMode && TabStop)
|
||||
{
|
||||
Focus();
|
||||
}
|
||||
_dragging = true;
|
||||
FromPoint(e.Location);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(_darkenHue + ((e.Delta < 0) ? 5 : (-5)), _darken);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (_dragging)
|
||||
{
|
||||
FromPoint(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
_dragging = false;
|
||||
}
|
||||
|
||||
private void FromPoint(Point p)
|
||||
{
|
||||
int diameter = Diameter;
|
||||
double num = (double)(Width - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num2 = (double)(Height - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num3 = (double)p.X - num;
|
||||
double num4 = (double)p.Y - num2;
|
||||
double num5 = Math.Min(1.0, Math.Sqrt(num3 * num3 + num4 * num4) / ((double)diameter / 2.0));
|
||||
int num6 = (int)Math.Round(Math.Atan2(num4, num3) * 180.0 / Math.PI);
|
||||
if (num6 < 0)
|
||||
{
|
||||
num6 += 360;
|
||||
}
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(num6, _ring ? _darken : ((int)Math.Round(num5 * 400.0)));
|
||||
return;
|
||||
}
|
||||
int num7 = ((num6 > 180) ? (num6 - 360) : num6);
|
||||
int num8 = (_ring ? num7 : ((int)Math.Round((double)num7 * num5)));
|
||||
if (num8 != _hue)
|
||||
{
|
||||
_hue = Math.Clamp(num8, -180, 180);
|
||||
Invalidate();
|
||||
HueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class InUseTag : Control
|
||||
{
|
||||
private int Dpi => ControlInk.Dpi(this);
|
||||
|
||||
internal Size NaturalSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = ControlInk.Hairline(Dpi);
|
||||
return new Size(TextRenderer.MeasureText(Text, Fonts.CaptionBold, Size.Empty, TextFormatFlags.NoPadding).Width + 2 * Px(8) + 2 * num, Fonts.CaptionBold.Height + 2 * Px(2) + 2 * num);
|
||||
}
|
||||
}
|
||||
|
||||
internal InUseTag()
|
||||
: this("In use")
|
||||
{
|
||||
}
|
||||
|
||||
internal InUseTag(string text)
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
BackColor = Color.Transparent;
|
||||
TabStop = false;
|
||||
Font = Fonts.CaptionBold;
|
||||
AccessibleRole = AccessibleRole.StaticText;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
private int Px(int logical)
|
||||
{
|
||||
return ControlInk.Px(Dpi, logical);
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AccessibleName = Text;
|
||||
Size = NaturalSize;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnDpiChangedAfterParent(EventArgs e)
|
||||
{
|
||||
base.OnDpiChangedAfterParent(e);
|
||||
Size = NaturalSize;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
int dpi = Dpi;
|
||||
ControlInk.PaintBox(graphics, Size, ControlInk.PxF(dpi, 4f), ControlInk.Hairline(dpi), ControlInk.Accent, ControlInk.Accent);
|
||||
TextRenderer.DrawText(graphics, Text, Fonts.CaptionBold, ClientRectangle, ControlInk.OnAccent, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class KeyboardNavigation : IMessageFilter
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static KeyboardNavigation? _installed;
|
||||
|
||||
[ThreadStatic]
|
||||
private static bool _moving;
|
||||
|
||||
private const int WM_KEYDOWN = 256;
|
||||
|
||||
private const int WM_SYSKEYDOWN = 260;
|
||||
|
||||
internal static bool InProgress => _moving;
|
||||
|
||||
internal static void EnsureInstalled()
|
||||
{
|
||||
if (_installed == null)
|
||||
{
|
||||
_installed = new KeyboardNavigation();
|
||||
Application.AddMessageFilter(_installed);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool Consume()
|
||||
{
|
||||
bool moving = _moving;
|
||||
_moving = false;
|
||||
return moving;
|
||||
}
|
||||
|
||||
internal static bool IsNavigationKey(Keys key)
|
||||
{
|
||||
Keys keys = key & Keys.KeyCode;
|
||||
if (keys == Keys.Tab || (uint)(keys - 33) <= 7u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool PreFilterMessage(ref Message m)
|
||||
{
|
||||
int msg = m.Msg;
|
||||
bool flag = ((msg == 256 || msg == 260) ? true : false);
|
||||
bool flag2 = flag;
|
||||
Keys keys = (flag2 ? ((Keys)((long)m.WParam & 0xFFFFL)) : Keys.None);
|
||||
_moving = flag2 && IsNavigationKey(keys);
|
||||
if (_moving && keys == Keys.Tab)
|
||||
{
|
||||
try
|
||||
{
|
||||
RovingFocus.RefreshAll();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class LibraryToast : Control
|
||||
{
|
||||
private const int PadLeft = 16;
|
||||
|
||||
private const int PadRight = 8;
|
||||
|
||||
private const int Gap = 8;
|
||||
|
||||
private const int IconSize = 20;
|
||||
|
||||
private const int CloseBox = 28;
|
||||
|
||||
private const int UndoPad = 8;
|
||||
|
||||
private const int ButtonH = 28;
|
||||
|
||||
private const int MinWidth = 360;
|
||||
|
||||
private const int MaxWidth = 560;
|
||||
|
||||
private readonly GlassButton _undo;
|
||||
|
||||
private readonly GlassButton _close;
|
||||
|
||||
public string Message { get; private set; } = "";
|
||||
|
||||
internal (string Lead, string Tail) Parts
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = Message.IndexOf(" · ", StringComparison.Ordinal);
|
||||
if (num <= 0)
|
||||
{
|
||||
return (Lead: "", Tail: Message);
|
||||
}
|
||||
return (Lead: Message.Substring(0, num), Tail: Message.Substring(num));
|
||||
}
|
||||
}
|
||||
|
||||
private static int UndoWidth => Advance("Undo", Fonts.BodyBold) + 2 * S(8);
|
||||
|
||||
internal int PreferredWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
(string Lead, string Tail) parts = Parts;
|
||||
string item = parts.Lead;
|
||||
string item2 = parts.Tail;
|
||||
int num = ((item.Length > 0) ? Advance(item, Fonts.BodyBold) : 0) + Advance(item2, Fonts.Body);
|
||||
return Math.Clamp(S(16) + S(20) + S(8) + num + S(8) + UndoWidth + S(8) + S(28) + S(8), S(360), S(560));
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? UndoRequested;
|
||||
|
||||
public event EventHandler? CloseRequested;
|
||||
|
||||
private static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
public LibraryToast()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Height = 48;
|
||||
Visible = false;
|
||||
_undo = new GlassButton
|
||||
{
|
||||
Kind = GlassButtonKind.Quiet,
|
||||
Text = "Undo",
|
||||
AccessibleName = "Undo",
|
||||
TabIndex = 0
|
||||
};
|
||||
_undo.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
UndoRequested?.Invoke(this, EventArgs.Empty);
|
||||
};
|
||||
_close = new GlassButton
|
||||
{
|
||||
Kind = GlassButtonKind.Icon,
|
||||
Icon = SignalIcon.Close,
|
||||
AccessibleName = "Close",
|
||||
TabIndex = 1
|
||||
};
|
||||
_close.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
};
|
||||
Controls.Add(_undo);
|
||||
Controls.Add(_close);
|
||||
LayOut();
|
||||
}
|
||||
|
||||
public void Show(string message)
|
||||
{
|
||||
Message = message;
|
||||
Visible = true;
|
||||
LayOut();
|
||||
BringToFront();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs levent)
|
||||
{
|
||||
base.OnLayout(levent);
|
||||
LayOut();
|
||||
}
|
||||
|
||||
public void ReassertOnTop()
|
||||
{
|
||||
BringToFront();
|
||||
}
|
||||
|
||||
internal void TestPressUndo()
|
||||
{
|
||||
UndoRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void TestPressClose()
|
||||
{
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void LayOut()
|
||||
{
|
||||
if (_undo != null && _close != null)
|
||||
{
|
||||
int num = S(28);
|
||||
_close.SetBounds(Width - S(8) - num, (Height - num) / 2, num, num);
|
||||
int undoWidth = UndoWidth;
|
||||
int num2 = S(28);
|
||||
_undo.SetBounds(_close.Left - S(8) - undoWidth, (Height - num2) / 2, undoWidth, num2);
|
||||
}
|
||||
}
|
||||
|
||||
private static int Advance(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font, Size.Empty, TextFormatFlags.NoPadding).Width;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
LayOut();
|
||||
RectangleF rect = new RectangleF(0.5f, 0.5f, Width - 1, Height - 1);
|
||||
float radius = S(8);
|
||||
if (SlateSurface.Active)
|
||||
{
|
||||
Glass.PaintPanel(graphics, rect, radius, Glass.BackdropOffsetOf(this), 255, 200, exactAlpha: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(rect, radius);
|
||||
using (SolidBrush brush = new SolidBrush(SignalTokens.Ash.Overlay))
|
||||
{
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using Pen pen = new Pen(SignalTokens.Ash.WindowEdge, S(1));
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
int num = S(20);
|
||||
int num2 = S(16);
|
||||
LineIcons.Success(graphics, new Rectangle(num2, (Height - num) / 2, num, num), Theme.Positive);
|
||||
num2 += num + S(8);
|
||||
int num3 = Math.Max(0, _undo.Left - S(8) - num2);
|
||||
var (text, text2) = Parts;
|
||||
if (text.Length > 0)
|
||||
{
|
||||
int num4 = Math.Min(num3, Advance(text, Fonts.BodyBold));
|
||||
TextRenderer.DrawText(graphics, text, Fonts.BodyBold, new Rectangle(num2, 0, num4, Height), Theme.Text, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
num2 += num4;
|
||||
num3 -= num4;
|
||||
}
|
||||
TextRenderer.DrawText(graphics, text2, Fonts.Body, new Rectangle(num2, 0, Math.Max(0, num3), Height), Theme.TextDim, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public static class LockPill
|
||||
{
|
||||
public const string Text = "COMES WITH A PLAN";
|
||||
|
||||
private const int Height = 24;
|
||||
|
||||
private const int PadX = 8;
|
||||
|
||||
private const int Icon = 16;
|
||||
|
||||
private const int Gap = 8;
|
||||
|
||||
private const int Radius = 4;
|
||||
|
||||
public static string Label => char.ToUpperInvariant("COMES WITH A PLAN"[0]) + "COMES WITH A PLAN".Substring(1).ToLowerInvariant();
|
||||
|
||||
private static Font WordFont => Fonts.CaptionBold;
|
||||
|
||||
private static int S(int px)
|
||||
{
|
||||
return Tokens.Scale(px);
|
||||
}
|
||||
|
||||
public static Size Measure()
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(Label, WordFont, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.NoPadding);
|
||||
return new Size(S(8) + S(16) + S(8) + size.Width + S(8), S(24));
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, Rectangle tag)
|
||||
{
|
||||
if (tag.Width >= 4 && tag.Height >= 4)
|
||||
{
|
||||
int dpi = Tokens.Dpi;
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(tag.X, tag.Y);
|
||||
ControlInk.PaintBox(g, tag.Size, S(4), ControlInk.Hairline(dpi), Color.Empty, ControlInk.Border);
|
||||
g.Restore(gstate);
|
||||
Color text = ControlInk.Text2;
|
||||
int num = S(16);
|
||||
RectangleF box = new RectangleF(tag.X + S(8), (float)tag.Y + (float)(tag.Height - num) / 2f, num, num);
|
||||
SignalIcons.Draw(g, SignalIcon.Lock, box, text);
|
||||
int num2 = (int)box.Right + S(8);
|
||||
TextRenderer.DrawText(g, Label, WordFont, new Rectangle(num2, tag.Y, Math.Max(0, tag.Right - S(8) - num2 + S(2)), tag.Height), text, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class LookTile : Control
|
||||
{
|
||||
private readonly string _caption;
|
||||
|
||||
private readonly string _name;
|
||||
|
||||
private readonly HoverFade _fade;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private bool _active;
|
||||
|
||||
private const int Pad = 12;
|
||||
|
||||
private const int PreviewH = 104;
|
||||
|
||||
private const int NameGap = 12;
|
||||
|
||||
private const int NameH = 20;
|
||||
|
||||
private const int CaptionGap = 2;
|
||||
|
||||
private const int RadioD = 20;
|
||||
|
||||
private const int RadioDot = 8;
|
||||
|
||||
private static readonly Rectangle[] Boxes = new Rectangle[5]
|
||||
{
|
||||
new Rectangle(6, 6, 22, 92),
|
||||
new Rectangle(34, 6, 199, 18),
|
||||
new Rectangle(34, 30, 199, 34),
|
||||
new Rectangle(34, 70, 120, 28),
|
||||
new Rectangle(160, 70, 73, 28)
|
||||
};
|
||||
|
||||
private const int BoxesW = 242;
|
||||
|
||||
public ThemePalette Palette { get; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal string ShownName => _name;
|
||||
|
||||
internal string Caption => _caption;
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
private bool IsSlate => Palette.Name == "Slate";
|
||||
|
||||
public LookTile(ThemePalette palette, string caption, string? name = null)
|
||||
{
|
||||
Palette = palette;
|
||||
_caption = caption;
|
||||
_name = name ?? palette.Name;
|
||||
_fade = new HoverFade(this);
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 8f));
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
Size = new Size(266, 194);
|
||||
AccessibleName = _name;
|
||||
AccessibleRole = AccessibleRole.RadioButton;
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
}
|
||||
|
||||
internal static int HeightFor(int width, string caption, int dpi)
|
||||
{
|
||||
int width2 = Math.Max(1, width - 2 * ControlInk.Px(dpi, 12));
|
||||
int height = TextRenderer.MeasureText(caption, Fonts.Caption, new Size(width2, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding).Height;
|
||||
return ControlInk.Px(dpi, 150) + height + ControlInk.Px(dpi, 12);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_fade.Set(hot: true);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_fade.Set(hot: false);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
Focus();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
bool flag = !Enabled;
|
||||
if (!flag)
|
||||
{
|
||||
Keys keyCode = e.KeyCode;
|
||||
bool flag2 = ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false);
|
||||
flag = !flag2;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||
if (!Enabled)
|
||||
{
|
||||
_fade.Snap(hot: false);
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintTile(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintTile(Graphics g)
|
||||
{
|
||||
int dpi = ControlInk.Dpi(this);
|
||||
int num = ControlInk.Px(dpi, 12);
|
||||
int num2 = ControlInk.Hairline(dpi);
|
||||
float num3 = ControlInk.PxF(dpi, 8f);
|
||||
Color fill = (Enabled ? ControlInk.Mix(Color.FromArgb(0, ControlInk.Hover), ControlInk.Hover, _fade.Value) : Color.Transparent);
|
||||
Color edge;
|
||||
if (Enabled)
|
||||
{
|
||||
edge = (_active ? ControlInk.Accent : ControlInk.Edge);
|
||||
}
|
||||
else
|
||||
{
|
||||
edge = ControlInk.TextDisabled;
|
||||
}
|
||||
ControlInk.PaintBox(g, ClientSize, num3, num2, fill, edge);
|
||||
if (_active && Enabled && Width > 4 && Height > 4)
|
||||
{
|
||||
Size size = new Size(Width - 2 * num2, Height - 2 * num2);
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(num2, num2);
|
||||
ControlInk.PaintBox(g, size, Math.Max(0f, num3 - (float)num2), num2, Color.Transparent, ControlInk.Accent);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
Rectangle well = new Rectangle(num, num, Math.Max(1, Width - 2 * num), Math.Min(ControlInk.Px(dpi, 104), Math.Max(1, Height - 2 * num)));
|
||||
if (well.Width > 4 && well.Height > 4)
|
||||
{
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintPreview(g, well, dpi);
|
||||
});
|
||||
}
|
||||
int num4 = well.Bottom + ControlInk.Px(dpi, 12);
|
||||
int num5 = ControlInk.Px(dpi, 20);
|
||||
int num6 = ControlInk.Px(dpi, 20);
|
||||
Rectangle box = new Rectangle(Width - num - num6, num4 + (num5 - num6) / 2, num6, num6);
|
||||
Color foreColor = (Enabled ? ControlInk.Text1 : ControlInk.TextDisabledInk);
|
||||
Color foreColor2 = (Enabled ? ControlInk.Text3 : ControlInk.TextDisabledInk);
|
||||
TextRenderer.DrawText(g, _name, Fonts.BodyBold, new Rectangle(num, num4, Math.Max(1, box.Left - num - ControlInk.Px(dpi, 8)), num5), foreColor, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
PaintRadio(g, box, dpi);
|
||||
int num7 = num4 + num5 + ControlInk.Px(dpi, 2);
|
||||
TextRenderer.DrawText(g, _caption, Fonts.Caption, new Rectangle(num, num7, Math.Max(1, Width - 2 * num), Math.Max(1, Height - num7 - num / 2)), foreColor2, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
_ring.Show(Focused && ShowFocusCues && Enabled);
|
||||
}
|
||||
|
||||
private void PaintPreview(Graphics g, Rectangle well, int dpi)
|
||||
{
|
||||
FailPointForTest?.Invoke("draw");
|
||||
float radius = ControlInk.PxF(dpi, 4f);
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(well.X, well.Y, well.Width, well.Height), radius);
|
||||
using Region clip = g.Clip;
|
||||
g.SetClip(path, CombineMode.Intersect);
|
||||
try
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(SlateSurface.Active ? SignalTokens.Slate.PreviewWell : SignalTokens.Ash.PreviewWell))
|
||||
{
|
||||
g.FillRectangle(brush, well);
|
||||
}
|
||||
if (AppBackground.IsSet)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(well.X, well.Y);
|
||||
AppBackground.PaintInto(g, well.Width, well.Height);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
float num = (float)well.Width / 242f;
|
||||
Color color = (IsSlate ? Color.FromArgb((int)Math.Round(168.3), SignalTokens.Slate.SlateBase) : SignalTokens.Ash.Surface1);
|
||||
Color color2 = (IsSlate ? SignalTokens.Slate.Border : SignalTokens.Ash.Border);
|
||||
if (!Enabled)
|
||||
{
|
||||
color = Color.FromArgb(color.A / 2, color);
|
||||
}
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using SolidBrush brush2 = new SolidBrush(color);
|
||||
using Pen pen = new Pen(color2, 1f);
|
||||
Rectangle[] boxes = Boxes;
|
||||
for (int i = 0; i < boxes.Length; i++)
|
||||
{
|
||||
Rectangle rectangle = boxes[i];
|
||||
RectangleF rect = new RectangleF((float)well.X + (float)rectangle.X * num, (float)well.Y + (float)rectangle.Y * num, (float)rectangle.Width * num, Math.Min((float)rectangle.Height * num, (float)well.Bottom - ((float)well.Y + (float)rectangle.Y * num) - 1f));
|
||||
if (!(rect.Width < 2f) && !(rect.Height < 2f))
|
||||
{
|
||||
using GraphicsPath path2 = Glass.RoundedPath(rect, ControlInk.PxF(dpi, 2f));
|
||||
g.FillPath(brush2, path2);
|
||||
g.DrawPath(pen, path2);
|
||||
}
|
||||
}
|
||||
g.SmoothingMode = smoothingMode;
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.Clip = clip;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintRadio(Graphics g, Rectangle box, int dpi)
|
||||
{
|
||||
if (box.Width < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
try
|
||||
{
|
||||
float num = (float)ControlInk.Hairline(dpi) / 2f;
|
||||
RectangleF rect = new RectangleF((float)box.X + num, (float)box.Y + num, (float)box.Width - 2f * num, (float)box.Height - 2f * num);
|
||||
if (_active && Enabled)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(ControlInk.Accent))
|
||||
{
|
||||
g.FillEllipse(brush, box);
|
||||
}
|
||||
float num2 = ControlInk.PxF(dpi, 8f);
|
||||
using SolidBrush brush2 = new SolidBrush(ControlInk.OnAccent);
|
||||
g.FillEllipse(brush2, (float)box.X + ((float)box.Width - num2) / 2f, (float)box.Y + ((float)box.Height - num2) / 2f, num2, num2);
|
||||
return;
|
||||
}
|
||||
using Pen pen = new Pen(Enabled ? ControlInk.Edge : ControlInk.TextDisabled, ControlInk.Hairline(dpi));
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class MonitorNumberWindow : Form, IMonitorIdentifyWindow, IDisposable
|
||||
{
|
||||
private readonly string _number;
|
||||
|
||||
protected override bool ShowWithoutActivation => true;
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams createParams = base.CreateParams;
|
||||
createParams.ExStyle |= 134217888;
|
||||
return createParams;
|
||||
}
|
||||
}
|
||||
|
||||
internal MonitorNumberWindow(Rectangle screen, int number)
|
||||
{
|
||||
_number = number.ToString(CultureInfo.InvariantCulture);
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
ShowInTaskbar = false;
|
||||
TopMost = true;
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
BackColor = Theme.Surface;
|
||||
Size = new Size(Tokens.Scale(120), Tokens.Scale(96));
|
||||
Location = new Point(screen.Left + (screen.Width - Width) / 2, screen.Top + (screen.Height - Height) / 2);
|
||||
DoubleBuffered = true;
|
||||
}
|
||||
|
||||
public void ShowNumber()
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
TextRenderer.DrawText(e.Graphics, _number, Fonts.Value, ClientRectangle, Theme.Text, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
using Pen pen = new Pen(Theme.Border);
|
||||
e.Graphics.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class MonitorSelectionCard : IDisposable
|
||||
{
|
||||
private readonly MonitorSelection _selection;
|
||||
|
||||
private readonly MonitorIdentifier _identifier;
|
||||
|
||||
private readonly Action _save;
|
||||
|
||||
private readonly Label _heading = Label("Apply to", Fonts.BodyBold);
|
||||
|
||||
private readonly Label _hint = Label("Unticked monitors keep their own colours.", Fonts.Caption);
|
||||
|
||||
private readonly Label _summary = Label("", Fonts.Caption);
|
||||
|
||||
private readonly Label _limitation = Label("", Fonts.Caption);
|
||||
|
||||
private readonly Label _empty = Label("No monitors found.", Fonts.Caption);
|
||||
|
||||
private readonly GlassButton _identify = new GlassButton
|
||||
{
|
||||
Text = "Identify screens",
|
||||
AccessibleName = "Identify screens"
|
||||
};
|
||||
|
||||
private readonly List<MonitorSelectionTile> _tiles = new List<MonitorSelectionTile>();
|
||||
|
||||
public CardPanel View { get; } = new CardPanel
|
||||
{
|
||||
Name = "monitor-selection"
|
||||
};
|
||||
|
||||
public MonitorSelectionCard(MonitorSelection selection, MonitorIdentifier identifier, Action save)
|
||||
{
|
||||
_selection = selection;
|
||||
_identifier = identifier;
|
||||
_save = save;
|
||||
View.Controls.AddRange(new Control[6] { _heading, _hint, _identify, _summary, _limitation, _empty });
|
||||
_identify.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
_identifier.Identify(_selection.Groups);
|
||||
};
|
||||
_selection.Changed += Refresh;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private static Label Label(string text, Font font)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = font,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TabStop = false
|
||||
};
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
IReadOnlyList<ColourMonitorGroup> groups = _selection.Groups;
|
||||
View.Visible = _selection.WorthShowing;
|
||||
if (_tiles.Count != groups.Count || _tiles.Where((MonitorSelectionTile t, int i) => t.Group.Identity != groups[i].Identity).Any())
|
||||
{
|
||||
foreach (MonitorSelectionTile tile2 in _tiles)
|
||||
{
|
||||
View.Controls.Remove(tile2);
|
||||
tile2.Dispose();
|
||||
}
|
||||
_tiles.Clear();
|
||||
for (int num = 0; num < groups.Count; num++)
|
||||
{
|
||||
MonitorSelectionTile tile = new MonitorSelectionTile(groups[num], num + 1);
|
||||
tile.SelectionRequested += (bool chosen) =>
|
||||
{
|
||||
_selection.SetSelected(tile.Group, chosen);
|
||||
_save();
|
||||
};
|
||||
_tiles.Add(tile);
|
||||
View.Controls.Add(tile);
|
||||
}
|
||||
}
|
||||
for (int num2 = 0; num2 < _tiles.Count; num2++)
|
||||
{
|
||||
_tiles[num2].Group = groups[num2];
|
||||
_tiles[num2].Checked = _selection.IsSelected(groups[num2]);
|
||||
_tiles[num2].Enabled = true;
|
||||
}
|
||||
_identify.Enabled = groups.Count > 0;
|
||||
_empty.Visible = groups.Count == 0;
|
||||
IEnumerable<string> enumerable = from x in groups.Select((ColourMonitorGroup g, int i) => (g: g, i: i))
|
||||
where _selection.IncludesDevice(x.g.DeviceName)
|
||||
select "Monitor " + (x.i + 1);
|
||||
_summary.Text = "Ticked: " + (enumerable.Any() ? string.Join(", ", enumerable) : "None");
|
||||
Label limitation = _limitation;
|
||||
string text;
|
||||
if (groups.Count != 0)
|
||||
{
|
||||
text = (_selection.AllowsMatrix ? "" : "Saturation, hue and other whole-desktop colour effects are paused while a monitor is unticked. Brightness, contrast, temperature, red/green/blue, gamma and NVIDIA Digital Vibrance use the ticked monitors.");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
limitation.Text = text;
|
||||
if (groups.Count > 0 && groups.All((ColourMonitorGroup g) => !_selection.IsSelected(g)))
|
||||
{
|
||||
_limitation.Text = "No monitors selected. Colour changes are paused.";
|
||||
}
|
||||
if (View.Width > 0)
|
||||
{
|
||||
Layout(View.Width);
|
||||
}
|
||||
View.Parent?.PerformLayout();
|
||||
}
|
||||
|
||||
public int Layout(int width)
|
||||
{
|
||||
if (!_selection.WorthShowing)
|
||||
{
|
||||
View.Height = 0;
|
||||
return 0;
|
||||
}
|
||||
int num = Tokens.Scale(21);
|
||||
int num2 = Tokens.Scale(12);
|
||||
int num3 = Math.Max(1, width - 2 * num);
|
||||
int height = Tokens.Scale(32);
|
||||
int width2 = _identify.GetPreferredSize(Size.Empty).Width;
|
||||
_heading.ForeColor = Theme.Text;
|
||||
_heading.SetBounds(num, num, Math.Max(1, num3 - width2 - num2), Fonts.LineHeight(FontRole.BodyBold));
|
||||
_identify.SetBounds(width - num - width2, num, width2, height);
|
||||
int y = _heading.Bottom + Tokens.Scale(3);
|
||||
int width3 = Math.Max(1, num3 - width2 - num2);
|
||||
int height2 = Measure(_hint, width3);
|
||||
_hint.SetBounds(num, y, width3, height2);
|
||||
int num4 = Math.Max(_hint.Bottom, _identify.Bottom) + Tokens.Scale(16);
|
||||
int num5 = ((num3 < Tokens.Scale(640)) ? 1 : 2);
|
||||
int tileW = (num3 - num2 * (num5 - 1)) / num5;
|
||||
for (int i = 0; i < _tiles.Count; i += num5)
|
||||
{
|
||||
int num6 = _tiles.Skip(i).Take(num5).Max((MonitorSelectionTile t) => t.GetPreferredSize(new Size(tileW, 0)).Height);
|
||||
for (int num7 = 0; num7 < num5 && i + num7 < _tiles.Count; num7++)
|
||||
{
|
||||
_tiles[i + num7].SetBounds(num + num7 * (tileW + num2), num4, tileW, num6);
|
||||
}
|
||||
num4 += num6 + num2;
|
||||
}
|
||||
if (_tiles.Count == 0)
|
||||
{
|
||||
_empty.SetBounds(num, num4, num3, Measure(_empty, num3));
|
||||
num4 = _empty.Bottom + num2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_empty.SetBounds(num, num, 0, 0);
|
||||
}
|
||||
_summary.SetBounds(num, num4, num3, Measure(_summary, num3));
|
||||
num4 = _summary.Bottom;
|
||||
int num8 = ((_limitation.Text.Length != 0) ? Measure(_limitation, num3) : 0);
|
||||
_limitation.SetBounds(num, num4 + ((num8 > 0) ? num2 : 0), num3, num8);
|
||||
int num9 = _limitation.Bottom + num;
|
||||
View.Height = num9;
|
||||
return num9;
|
||||
}
|
||||
|
||||
private static int Measure(Label label, int width)
|
||||
{
|
||||
return TextRenderer.MeasureText(label.Text, label.Font, new Size(width, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding).Height;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_selection.Changed -= Refresh;
|
||||
_identifier.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class MonitorSelectionTile : Control
|
||||
{
|
||||
private sealed class TileAccessible : ControlAccessibleObject
|
||||
{
|
||||
private readonly MonitorSelectionTile _tile;
|
||||
|
||||
public override AccessibleStates State => (AccessibleStates)((int)base.State | (_tile.Checked ? 16 : 0));
|
||||
|
||||
public override string DefaultAction => "Toggle selection";
|
||||
|
||||
public TileAccessible(MonitorSelectionTile tile)
|
||||
: base(tile)
|
||||
{
|
||||
_tile = tile;
|
||||
}
|
||||
|
||||
public override void DoDefaultAction()
|
||||
{
|
||||
_tile.Request();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _checked;
|
||||
|
||||
public ColourMonitorGroup Group { get; set; }
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public bool Checked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _checked;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_checked != value)
|
||||
{
|
||||
_checked = value;
|
||||
Invalidate();
|
||||
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string Detail
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Group.IsClone)
|
||||
{
|
||||
return Group.Bounds.Width + " × " + Group.Bounds.Height + ((Group.RefreshHz > 0) ? (" · " + Group.RefreshHz + " Hz") : "") + (Group.Primary ? " · main" : "");
|
||||
}
|
||||
return "Mirrored screens — selected together";
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<bool>? SelectionRequested;
|
||||
|
||||
public MonitorSelectionTile(ColourMonitorGroup group, int number)
|
||||
{
|
||||
Group = group;
|
||||
Number = number;
|
||||
Name = "monitor-tile-" + number;
|
||||
AccessibleName = group.Name;
|
||||
AccessibleRole = AccessibleRole.CheckButton;
|
||||
TabStop = true;
|
||||
Cursor = Cursors.Hand;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Font = Fonts.BodyBold;
|
||||
}
|
||||
|
||||
private int TextWidth(int width)
|
||||
{
|
||||
return Math.Max(Tokens.Scale(32), width - Tokens.Scale(132));
|
||||
}
|
||||
|
||||
private static Size Measure(string text, Font font, int width)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font, new Size(width, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
}
|
||||
|
||||
public override Size GetPreferredSize(Size proposedSize)
|
||||
{
|
||||
int width = ((proposedSize.Width > 0) ? proposedSize.Width : Tokens.Scale(360));
|
||||
int width2 = TextWidth(width);
|
||||
int num = Measure(Group.Name, Fonts.BodyBold, width2).Height + Tokens.Scale(3) + Measure(Detail, Fonts.Caption, width2).Height;
|
||||
return new Size(width, Math.Max(Tokens.Scale(68), num + Tokens.Scale(28)));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
int num = Tokens.Scale(14);
|
||||
int num2 = Tokens.Scale(58);
|
||||
int num3 = Tokens.Scale(38);
|
||||
int num4 = Tokens.Scale(12);
|
||||
using SolidBrush brush = new SolidBrush(Checked ? Theme.Surface : Theme.Background);
|
||||
using Pen pen = new Pen(Checked ? Theme.Text : Theme.Border);
|
||||
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
|
||||
graphics.FillRectangle(brush, rect);
|
||||
graphics.DrawRectangle(pen, rect);
|
||||
Rectangle rectangle = new Rectangle(num, (Height - num3) / 2, num2, num3);
|
||||
graphics.DrawRectangle(pen, rectangle);
|
||||
TextRenderer.DrawText(graphics, Number.ToString(CultureInfo.InvariantCulture), Fonts.Title, rectangle, Checked ? Theme.Text : Theme.TextDim, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
using SolidBrush brush2 = new SolidBrush(Checked ? Theme.Text : Theme.TextDim);
|
||||
graphics.FillRectangle(brush2, rectangle.Left + num2 / 2 - Tokens.Scale(5), rectangle.Bottom, Tokens.Scale(10), Tokens.Scale(6));
|
||||
int x = num + num2 + num4;
|
||||
int width = TextWidth(Width);
|
||||
int height = Measure(Group.Name, Fonts.BodyBold, width).Height;
|
||||
TextRenderer.DrawText(graphics, Group.Name, Fonts.BodyBold, new Rectangle(x, num, width, height), Theme.Text, TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
TextRenderer.DrawText(graphics, Detail, Fonts.Caption, new Rectangle(x, num + height + Tokens.Scale(3), width, Height - num * 2 - height - Tokens.Scale(3)), Theme.TextDim, TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
int num5 = Tokens.Scale(20);
|
||||
Rectangle rect2 = new Rectangle(Width - num - num5, (Height - num5) / 2, num5, num5);
|
||||
if (Checked)
|
||||
{
|
||||
using SolidBrush brush3 = new SolidBrush(Theme.Text);
|
||||
graphics.FillRectangle(brush3, rect2);
|
||||
using Pen pen2 = new Pen(Theme.Background, Tokens.Scale(2));
|
||||
graphics.DrawLines(pen2, new Point[3]
|
||||
{
|
||||
new Point(rect2.Left + num5 / 4, rect2.Top + num5 / 2),
|
||||
new Point(rect2.Left + num5 * 2 / 5, rect2.Top + num5 * 3 / 4),
|
||||
new Point(rect2.Left + num5 * 4 / 5, rect2.Top + num5 / 4)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.DrawRectangle(pen, rect2);
|
||||
}
|
||||
if (Focused)
|
||||
{
|
||||
using (Pen pen3 = new Pen(Theme.Text)
|
||||
{
|
||||
DashStyle = DashStyle.Dot
|
||||
})
|
||||
{
|
||||
graphics.DrawRectangle(pen3, 2, 2, Width - 5, Height - 5);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Request()
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
SelectionRequested?.Invoke(!Checked);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
base.OnClick(e);
|
||||
Focus();
|
||||
Request();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Space)
|
||||
{
|
||||
Request();
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override AccessibleObject CreateAccessibilityInstance()
|
||||
{
|
||||
return new TileAccessible(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class NotesView : Control
|
||||
{
|
||||
internal readonly record struct Block(string Lead, string Text, bool Bullet, bool Heading, bool GapBefore);
|
||||
|
||||
private const int LanePx = 8;
|
||||
|
||||
private const int ThumbPx = 4;
|
||||
|
||||
private const int ThumbMinPx = 24;
|
||||
|
||||
private const int ParagraphGapPx = 8;
|
||||
|
||||
private const int LinesPerNotch = 3;
|
||||
|
||||
private string _text = "";
|
||||
|
||||
private int _scroll;
|
||||
|
||||
private bool _thumbHot;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
private int _dragFrom;
|
||||
|
||||
private int _dragScrollFrom;
|
||||
|
||||
private readonly List<(Point At, string Word, bool Strong)> _laid = new List<(Point, string, bool)>();
|
||||
|
||||
private readonly List<Point> _dots = new List<Point>();
|
||||
|
||||
private int _laidFor = -1;
|
||||
|
||||
private int _contentHeight;
|
||||
|
||||
private int _headingLimit = 48;
|
||||
|
||||
private bool _onCard;
|
||||
|
||||
internal const int DefaultHeadingLimit = 48;
|
||||
|
||||
private static readonly Regex LeadIn = new Regex("^(?<lead>[A-Z][^:.!?\\r\\n]{0,38}:)\\s+(?<rest>\\S.*)$", RegexOptions.Singleline);
|
||||
|
||||
public string NotesText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
set
|
||||
{
|
||||
_text = value ?? "";
|
||||
_laidFor = -1;
|
||||
_scroll = 0;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int HeadingLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _headingLimit;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _headingLimit)
|
||||
{
|
||||
_headingLimit = value;
|
||||
_laidFor = -1;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnCard
|
||||
{
|
||||
get
|
||||
{
|
||||
return _onCard;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _onCard)
|
||||
{
|
||||
_onCard = value;
|
||||
if (value)
|
||||
{
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetBackColor();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Dpi => ControlInk.Dpi(this);
|
||||
|
||||
private int TextWidth => Math.Max(1, Width - Px(8));
|
||||
|
||||
private int MaxScroll => Math.Max(0, _contentHeight - Height);
|
||||
|
||||
private int LinePx => Px(20);
|
||||
|
||||
private Rectangle Thumb
|
||||
{
|
||||
get
|
||||
{
|
||||
Lay();
|
||||
if (_contentHeight <= Height || Height <= 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
int num = Math.Max(Px(24), (int)((long)Height * (long)Height / _contentHeight));
|
||||
int num2 = Height - num;
|
||||
int y = (int)((MaxScroll != 0) ? ((long)num2 * (long)_scroll / MaxScroll) : 0);
|
||||
int num3 = Px(4);
|
||||
return new Rectangle(Width - Px(8) + (Px(8) - num3) / 2, y, num3, num);
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle Lane => new Rectangle(Width - Px(8), 0, Px(8), Height);
|
||||
|
||||
internal int ContentHeightForTest
|
||||
{
|
||||
get
|
||||
{
|
||||
Lay();
|
||||
return _contentHeight;
|
||||
}
|
||||
}
|
||||
|
||||
internal int ScrollForTest => _scroll;
|
||||
|
||||
internal Rectangle ThumbForTest => Thumb;
|
||||
|
||||
public NotesView()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
Font = Fonts.Body;
|
||||
}
|
||||
|
||||
private int Px(int logical)
|
||||
{
|
||||
return ControlInk.Px(Dpi, logical);
|
||||
}
|
||||
|
||||
private void Lay()
|
||||
{
|
||||
if (_laidFor == Width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_laid.Clear();
|
||||
_dots.Clear();
|
||||
int textWidth = TextWidth;
|
||||
int num = 0;
|
||||
int num2 = Px(8);
|
||||
int num3 = Px(4);
|
||||
int linePx = LinePx;
|
||||
Font body = Fonts.Body;
|
||||
Font bodyBold = Fonts.BodyBold;
|
||||
int num4 = Math.Max(1, TextRenderer.MeasureText("a a", body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width - TextRenderer.MeasureText("aa", body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width);
|
||||
int num5 = Px(16);
|
||||
foreach (Block item5 in Reflow(_text, _headingLimit))
|
||||
{
|
||||
if (_laid.Count > 0 || _dots.Count > 0)
|
||||
{
|
||||
num += (item5.GapBefore ? num2 : num3);
|
||||
}
|
||||
int num6 = (item5.Bullet ? num5 : 0);
|
||||
if (item5.Bullet)
|
||||
{
|
||||
_dots.Add(new Point(0, num));
|
||||
}
|
||||
List<(string, bool)> list = new List<(string, bool)>();
|
||||
string[] array = item5.Lead.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string item in array)
|
||||
{
|
||||
list.Add((item, true));
|
||||
}
|
||||
array = item5.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string item2 in array)
|
||||
{
|
||||
list.Add((item2, item5.Heading));
|
||||
}
|
||||
int num7 = num6;
|
||||
foreach (var item6 in list)
|
||||
{
|
||||
string item3 = item6.Item1;
|
||||
bool item4 = item6.Item2;
|
||||
int width = TextRenderer.MeasureText(item3, item4 ? bodyBold : body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width;
|
||||
if (num7 > num6 && num7 + width > textWidth)
|
||||
{
|
||||
num7 = num6;
|
||||
num += linePx;
|
||||
}
|
||||
_laid.Add((new Point(num7, num), item3, item4));
|
||||
num7 += width + num4;
|
||||
}
|
||||
num += linePx;
|
||||
}
|
||||
_contentHeight = num;
|
||||
_laidFor = Width;
|
||||
_scroll = Math.Clamp(_scroll, 0, MaxScroll);
|
||||
}
|
||||
|
||||
private void ScrollBy(int pixels)
|
||||
{
|
||||
Lay();
|
||||
int num = Math.Clamp(_scroll + pixels, 0, MaxScroll);
|
||||
if (num != _scroll)
|
||||
{
|
||||
_scroll = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public bool ScrollByKey(Keys key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Keys.Up:
|
||||
ScrollBy(-LinePx);
|
||||
return true;
|
||||
case Keys.Down:
|
||||
ScrollBy(LinePx);
|
||||
return true;
|
||||
case Keys.Prior:
|
||||
ScrollBy(-Math.Max(LinePx, Height - LinePx));
|
||||
return true;
|
||||
case Keys.Next:
|
||||
ScrollBy(Math.Max(LinePx, Height - LinePx));
|
||||
return true;
|
||||
case Keys.Home:
|
||||
ScrollBy(-1073741823);
|
||||
return true;
|
||||
case Keys.End:
|
||||
ScrollBy(1073741823);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Wheel(int delta)
|
||||
{
|
||||
ScrollBy(-delta * 3 * LinePx / 120);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
HandledMouseEventArgs e2 = (e as HandledMouseEventArgs) ?? new HandledMouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta);
|
||||
e2.Handled = true;
|
||||
base.OnMouseWheel(e2);
|
||||
Wheel(e.Delta);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_dragging)
|
||||
{
|
||||
Rectangle thumb = Thumb;
|
||||
int num = Math.Max(1, Height - thumb.Height);
|
||||
int num2 = _dragScrollFrom + (int)((long)(e.Y - _dragFrom) * (long)MaxScroll / num);
|
||||
ScrollBy(num2 - _scroll);
|
||||
return;
|
||||
}
|
||||
bool flag = Lane.Contains(e.Location) && !Thumb.IsEmpty;
|
||||
if (flag != _thumbHot)
|
||||
{
|
||||
_thumbHot = flag;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (_thumbHot)
|
||||
{
|
||||
_thumbHot = false;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Rectangle thumb = Thumb;
|
||||
if (e.Button == MouseButtons.Left && !thumb.IsEmpty && Lane.Contains(e.Location))
|
||||
{
|
||||
if (e.Y < thumb.Top)
|
||||
{
|
||||
ScrollByKey(Keys.Prior);
|
||||
return;
|
||||
}
|
||||
if (e.Y >= thumb.Bottom)
|
||||
{
|
||||
ScrollByKey(Keys.Next);
|
||||
return;
|
||||
}
|
||||
_dragging = true;
|
||||
_dragFrom = e.Y;
|
||||
_dragScrollFrom = _scroll;
|
||||
Capture = true;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_dragging)
|
||||
{
|
||||
_dragging = false;
|
||||
Capture = false;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
_laidFor = -1;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Lay();
|
||||
Graphics graphics = e.Graphics;
|
||||
if (!_onCard)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(ControlInk.Overlay);
|
||||
graphics.FillRectangle(brush, ClientRectangle);
|
||||
}
|
||||
Font body = Fonts.Body;
|
||||
Font bodyBold = Fonts.BodyBold;
|
||||
int linePx = LinePx;
|
||||
int num = Px(4);
|
||||
SmoothingMode smoothingMode = graphics.SmoothingMode;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using (SolidBrush brush2 = new SolidBrush(ControlInk.Text2))
|
||||
{
|
||||
foreach (Point dot in _dots)
|
||||
{
|
||||
int num2 = dot.Y - _scroll;
|
||||
if (num2 + linePx >= 0 && num2 <= Height)
|
||||
{
|
||||
graphics.FillEllipse(brush2, dot.X + Px(4), (float)num2 + (float)(linePx - num) / 2f, num, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
graphics.SmoothingMode = smoothingMode;
|
||||
foreach (var item4 in _laid)
|
||||
{
|
||||
Point item = item4.At;
|
||||
string item2 = item4.Word;
|
||||
bool item3 = item4.Strong;
|
||||
int num3 = item.Y - _scroll;
|
||||
if (num3 + linePx >= 0 && num3 <= Height)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, item2, item3 ? bodyBold : body, new Point(item.X, num3), item3 ? ControlInk.Text1 : ControlInk.Text2, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
Rectangle thumb = Thumb;
|
||||
if (thumb.IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Color color;
|
||||
if (_dragging)
|
||||
{
|
||||
color = ControlInk.Text1;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = (_thumbHot ? ControlInk.Text2 : ControlInk.Edge);
|
||||
}
|
||||
SmoothingMode smoothingMode2 = graphics.SmoothingMode;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using (SolidBrush brush3 = new SolidBrush(color))
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(thumb, (float)thumb.Width / 2f);
|
||||
graphics.FillPath(brush3, path);
|
||||
}
|
||||
graphics.SmoothingMode = smoothingMode2;
|
||||
}
|
||||
|
||||
internal static List<Block> Reflow(string plain)
|
||||
{
|
||||
return Reflow(plain, 48);
|
||||
}
|
||||
|
||||
internal static List<Block> Reflow(string plain, int headingLimit)
|
||||
{
|
||||
List<Block> blocks = new List<Block>();
|
||||
string[] array = (plain ?? "").Replace("\r\n", "\n").Replace('\r', '\n').Split('\n');
|
||||
StringBuilder text = new StringBuilder();
|
||||
bool bullet = false;
|
||||
bool gap = false;
|
||||
bool open = false;
|
||||
int lineCount = 0;
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
string text2 = array[i].Trim();
|
||||
if (text2.Length == 0)
|
||||
{
|
||||
Flush(followedByBlank: true);
|
||||
gap = true;
|
||||
continue;
|
||||
}
|
||||
if (text2[0] == '•' || ((text2[0] == '-' || text2[0] == '*') && text2.Length > 1 && char.IsWhiteSpace(text2[1])))
|
||||
{
|
||||
Flush(followedByBlank: false);
|
||||
bullet = true;
|
||||
text2 = text2.Substring(1).TrimStart();
|
||||
}
|
||||
else if (!open)
|
||||
{
|
||||
bullet = false;
|
||||
}
|
||||
if (open)
|
||||
{
|
||||
text.Append(' ');
|
||||
}
|
||||
text.Append(text2);
|
||||
open = true;
|
||||
lineCount++;
|
||||
}
|
||||
Flush(followedByBlank: true);
|
||||
return blocks;
|
||||
void Flush(bool followedByBlank)
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
string text3 = text.ToString().Trim();
|
||||
string lead = "";
|
||||
if (bullet)
|
||||
{
|
||||
Match match = LeadIn.Match(text3);
|
||||
if (match.Success)
|
||||
{
|
||||
lead = match.Groups["lead"].Value;
|
||||
text3 = match.Groups["rest"].Value;
|
||||
}
|
||||
}
|
||||
int num;
|
||||
if (((!bullet && lineCount == 1) & followedByBlank) && text3.Length <= headingLimit && !text3.Contains("://"))
|
||||
{
|
||||
string text4 = text3;
|
||||
num = ((".:!?".IndexOf(text4[text4.Length - 1]) < 0) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
bool heading = (byte)num != 0;
|
||||
blocks.Add(new Block(lead, text3, bullet, heading, gap && blocks.Count > 0));
|
||||
text.Clear();
|
||||
open = false;
|
||||
gap = false;
|
||||
lineCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void WheelForTest(int delta)
|
||||
{
|
||||
Wheel(delta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public static class Prompt
|
||||
{
|
||||
public static string Ask(string title, string initial)
|
||||
{
|
||||
return Ask(title, initial, null);
|
||||
}
|
||||
|
||||
public static string Ask(string title, string initial, string? body)
|
||||
{
|
||||
GlassTextBox box;
|
||||
using GlassShellForm glassShellForm = Build(title, initial, body, out box);
|
||||
return (glassShellForm.ShowDialog() == DialogResult.OK) ? box.Text : "";
|
||||
}
|
||||
|
||||
internal static GlassShellForm Build(string title, string initial, out GlassTextBox box)
|
||||
{
|
||||
return Build(title, initial, null, out box);
|
||||
}
|
||||
|
||||
internal static GlassShellForm Build(string title, string initial, string? body, out GlassTextBox box)
|
||||
{
|
||||
int num = S(24);
|
||||
int num2 = S(400);
|
||||
int num3 = num2 - 2 * num;
|
||||
int num4 = S(32);
|
||||
Label label = SignalDialogWindow.TitleLabel(title, num + S(2), S(23), num3);
|
||||
Label label2 = null;
|
||||
int num5 = S(60);
|
||||
if (!string.IsNullOrEmpty(body))
|
||||
{
|
||||
int height = SignalDialogWindow.MeasureBody(body, num3);
|
||||
label2 = SignalDialogWindow.BodyLabel(body, num + S(2), S(60), num3, height);
|
||||
num5 = label2.Bottom + S(16);
|
||||
}
|
||||
int num6 = num5 + num4 + S(24);
|
||||
GlassShellForm form = new GlassShellForm(title)
|
||||
{
|
||||
PaintsTitle = false,
|
||||
ClientSize = new Size(num2, num6 + num4 + S(20))
|
||||
};
|
||||
GlassTextBox field = new GlassTextBox
|
||||
{
|
||||
Text = initial,
|
||||
MaxLength = 40,
|
||||
FocusOnEdge = true,
|
||||
Location = new Point(num, num5),
|
||||
Size = new Size(num3, num4)
|
||||
};
|
||||
GlassButton ok = new GlassButton
|
||||
{
|
||||
Text = "Save",
|
||||
Kind = GlassButtonKind.Primary
|
||||
};
|
||||
ok.Size = new Size(SignalDialogWindow.TwinButtonWidth(ok.Text, ok.Font, S(20), S(96)), num4);
|
||||
ok.Location = new Point(num2 - num - ok.Width, num6);
|
||||
ok.Click += (object? s, EventArgs e) =>
|
||||
{
|
||||
Finish(DialogResult.OK);
|
||||
};
|
||||
GlassButton glassButton = new GlassButton
|
||||
{
|
||||
Text = "Cancel",
|
||||
Kind = GlassButtonKind.Secondary
|
||||
};
|
||||
glassButton.Size = new Size(SignalDialogWindow.TwinButtonWidth(glassButton.Text, glassButton.Font, S(20), S(96)), num4);
|
||||
glassButton.Location = new Point(ok.Left - S(8) - glassButton.Width, num6);
|
||||
glassButton.Click += (object? s, EventArgs e) =>
|
||||
{
|
||||
Finish(DialogResult.Cancel);
|
||||
};
|
||||
field.TextChanged += (object? s, EventArgs e) =>
|
||||
{
|
||||
SyncSave();
|
||||
};
|
||||
SyncSave();
|
||||
form.KeyDown += (object? s, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Return)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
if (ok.Enabled)
|
||||
{
|
||||
Finish(DialogResult.OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
form.ShowClose = false;
|
||||
form.Controls.Add(label);
|
||||
WindowDrag.Enable(label, form);
|
||||
if (label2 != null)
|
||||
{
|
||||
form.Controls.Add(label2);
|
||||
WindowDrag.Enable(label2, form);
|
||||
}
|
||||
form.Controls.Add(field);
|
||||
form.Controls.Add(ok);
|
||||
form.Controls.Add(glassButton);
|
||||
form.ActiveControl = field;
|
||||
form.Shown += (object? s, EventArgs e) =>
|
||||
{
|
||||
field.Inner.SelectionLength = 0;
|
||||
field.Inner.SelectionStart = field.Inner.TextLength;
|
||||
};
|
||||
box = field;
|
||||
return form;
|
||||
void Finish(DialogResult r)
|
||||
{
|
||||
form.DialogResult = r;
|
||||
form.Close();
|
||||
}
|
||||
static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
void SyncSave()
|
||||
{
|
||||
ok.Enabled = !string.IsNullOrWhiteSpace(field.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class QuietScrollPanel : Panel
|
||||
{
|
||||
private const int SB_BOTH = 3;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowScrollBar(nint hWnd, int wBar, bool bShow);
|
||||
|
||||
public QuietScrollPanel()
|
||||
{
|
||||
AutoScroll = true;
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
internal void ScrollByWheel(int delta)
|
||||
{
|
||||
OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
int num = DisplayRectangle.Height - ClientSize.Height;
|
||||
if (AutoScroll && num > 0)
|
||||
{
|
||||
int num2 = SystemInformation.MouseWheelScrollLines;
|
||||
if (num2 <= 0)
|
||||
{
|
||||
num2 = 3;
|
||||
}
|
||||
int num3 = e.Delta * num2 * 22 / 120;
|
||||
int y = Math.Clamp(-AutoScrollPosition.Y - num3, 0, num);
|
||||
AutoScrollPosition = new Point(-AutoScrollPosition.X, y);
|
||||
if (e is HandledMouseEventArgs e2)
|
||||
{
|
||||
e2.Handled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
}
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
internal void TestScrollWheel(int delta)
|
||||
{
|
||||
OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
|
||||
}
|
||||
|
||||
protected override Point ScrollToControl(Control activeControl)
|
||||
{
|
||||
return DisplayRectangle.Location;
|
||||
}
|
||||
|
||||
private void ForwardWheel(object? sender, MouseEventArgs e)
|
||||
{
|
||||
OnMouseWheel(e);
|
||||
}
|
||||
|
||||
private void Hook(Control root)
|
||||
{
|
||||
foreach (Control control in root.Controls)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
control.ControlAdded -= OnDescendantAdded;
|
||||
control.ControlAdded += OnDescendantAdded;
|
||||
Hook(control);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDescendantAdded(object? sender, ControlEventArgs e)
|
||||
{
|
||||
Control control = e.Control;
|
||||
if (control != null)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
Hook(control);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnControlAdded(ControlEventArgs e)
|
||||
{
|
||||
base.OnControlAdded(e);
|
||||
OnDescendantAdded(this, e);
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
Hook(this);
|
||||
HideBars();
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
base.OnLayout(e);
|
||||
HideBars();
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
int msg = m.Msg;
|
||||
if ((msg == 131 || (uint)(msg - 276) <= 1u) ? true : false)
|
||||
{
|
||||
HideBars();
|
||||
}
|
||||
}
|
||||
|
||||
private void HideBars()
|
||||
{
|
||||
if (IsHandleCreated && !IsDisposed)
|
||||
{
|
||||
ShowScrollBar(Handle, 3, bShow: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class RevertConfirmForm : SignalDialogWindow
|
||||
{
|
||||
private static class Shape
|
||||
{
|
||||
public const int Width = 462;
|
||||
|
||||
public const int Pad = 24;
|
||||
|
||||
public const int TitleY = 23;
|
||||
|
||||
public const int BodyY = 60;
|
||||
|
||||
public const int BarGap = 26;
|
||||
|
||||
public const int FillH = 4;
|
||||
|
||||
public const int TrackH = 2;
|
||||
|
||||
public const int CountdownW = 24;
|
||||
|
||||
public const int CountdownGap = 14;
|
||||
|
||||
public const int CaptionGap = 15;
|
||||
|
||||
public const int ButtonGap = 39;
|
||||
|
||||
public const int BottomPad = 20;
|
||||
|
||||
public const int ButtonPad = 20;
|
||||
|
||||
public const int ButtonSplit = 8;
|
||||
|
||||
public const int Radius = 8;
|
||||
}
|
||||
|
||||
private sealed class ProgressTrack : Control
|
||||
{
|
||||
public float Fraction { get; set; } = 1f;
|
||||
|
||||
public ProgressTrack()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float num = Math.Max(1, Tokens.Scale(2));
|
||||
float y = ((float)Height - num) / 2f;
|
||||
using (SolidBrush brush = new SolidBrush(Theme.AccentDim))
|
||||
{
|
||||
FillPill(graphics, brush, new RectangleF(0f, y, Width, num), num / 2f);
|
||||
}
|
||||
float num2 = Math.Clamp(Fraction, 0f, 1f) * (float)Width;
|
||||
if (num2 >= (float)Height)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(Theme.Accent))
|
||||
{
|
||||
FillPill(graphics, brush2, new RectangleF(0f, 0f, num2, Height), (float)Height / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FillPill(Graphics g, Brush brush, RectangleF r, float radius)
|
||||
{
|
||||
if (r.Width < 1f || r.Height < 1f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using GraphicsPath path = Glass.RoundedPath(r, radius);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Timer _timer;
|
||||
|
||||
private readonly Label _title;
|
||||
|
||||
private readonly Label _body;
|
||||
|
||||
private readonly ProgressTrack _progress;
|
||||
|
||||
private readonly Label _countdown;
|
||||
|
||||
private readonly Label _safetyCaption;
|
||||
|
||||
private readonly GlassButton _keep;
|
||||
|
||||
private readonly GlassButton _goBack;
|
||||
|
||||
private readonly int _totalSeconds;
|
||||
|
||||
private int _secondsLeft;
|
||||
|
||||
private static readonly TimeSpan ArmAfter = TimeSpan.FromMilliseconds(400.0);
|
||||
|
||||
private bool _armed;
|
||||
|
||||
internal GlassButton TestKeepButton => _keep;
|
||||
|
||||
internal GlassButton TestGoBackButton => _goBack;
|
||||
|
||||
internal string TestCountdownText => _countdown.Text;
|
||||
|
||||
internal float TestProgressFraction => _progress.Fraction;
|
||||
|
||||
internal string TestMessageText => _body.Text;
|
||||
|
||||
internal string TestSafetyCaptionText => _safetyCaption.Text;
|
||||
|
||||
internal int TestTimerIntervalMs => _timer.Interval;
|
||||
|
||||
internal static int TestArmDelayMs => (int)ArmAfter.TotalMilliseconds;
|
||||
|
||||
public event Action? Confirmed;
|
||||
|
||||
private new static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
public RevertConfirmForm(string message, int graceSeconds)
|
||||
{
|
||||
_totalSeconds = Math.Max(1, graceSeconds);
|
||||
_secondsLeft = _totalSeconds;
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
TopMost = true;
|
||||
AccessibleName = "Keep this display mode?";
|
||||
AccessibleDescription = message;
|
||||
int num = S(24);
|
||||
int num2 = S(462);
|
||||
int num3 = num2 - 2 * num;
|
||||
_title = SignalDialogWindow.TitleLabel("Keep this display mode?", num + S(2), S(23), num3);
|
||||
Controls.Add(_title);
|
||||
int height = Math.Max(2 * Fonts.LineHeight(FontRole.Body), TextRenderer.MeasureText(message, Fonts.Body, new Size(num3, int.MaxValue), TextFormatFlags.WordBreak).Height);
|
||||
_body = SignalDialogWindow.BodyLabel(message, num + S(2), S(60), num3, height);
|
||||
Controls.Add(_body);
|
||||
int num4 = _body.Bottom + S(26);
|
||||
int num5 = S(24);
|
||||
int num6 = num3 - num5 - S(14);
|
||||
_progress = new ProgressTrack
|
||||
{
|
||||
Location = new Point(num, num4),
|
||||
Size = new Size(num6, S(4))
|
||||
};
|
||||
Controls.Add(_progress);
|
||||
_countdown = new Label
|
||||
{
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.CaptionBold,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleRight,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(num + num6 + S(14), num4 + S(4) / 2 - S(8)),
|
||||
Size = new Size(num5 + SignalDialogWindow.GlyphPad(Fonts.CaptionBold), S(16))
|
||||
};
|
||||
Controls.Add(_countdown);
|
||||
int num7 = num4 + S(4) + S(15);
|
||||
_safetyCaption = new Label
|
||||
{
|
||||
Text = "Doing nothing is safe: the old mode comes back.",
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Caption,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(SignalDialogWindow.Ink(num + S(2), Fonts.Caption), num7),
|
||||
Size = new Size(num3, Fonts.LineHeight(FontRole.Caption))
|
||||
};
|
||||
Controls.Add(_safetyCaption);
|
||||
int num8 = num7 + _safetyCaption.Height + S(39);
|
||||
int num9 = S(32);
|
||||
_keep = new GlassButton
|
||||
{
|
||||
Text = "Keep this mode",
|
||||
Kind = GlassButtonKind.Primary,
|
||||
Name = "RevertConfirmKeep"
|
||||
};
|
||||
_keep.Size = new Size(ButtonWidth(_keep.Text, _keep.Font), num9);
|
||||
_keep.Location = new Point(num2 - num - _keep.Width, num8);
|
||||
_keep.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Accept();
|
||||
};
|
||||
Controls.Add(_keep);
|
||||
_goBack = new GlassButton
|
||||
{
|
||||
Text = "Go back now",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Name = "RevertConfirmGoBack"
|
||||
};
|
||||
_goBack.Size = new Size(ButtonWidth(_goBack.Text, _goBack.Font), num9);
|
||||
_goBack.Location = new Point(_keep.Left - S(8) - _goBack.Width, num8);
|
||||
_goBack.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Close();
|
||||
};
|
||||
Controls.Add(_goBack);
|
||||
_goBack.TabIndex = 0;
|
||||
_keep.TabIndex = 1;
|
||||
ActiveControl = _goBack;
|
||||
ClientSize = new Size(num2, num8 + num9 + S(20));
|
||||
UpdateCountdown();
|
||||
_timer = new Timer
|
||||
{
|
||||
Interval = 1000
|
||||
};
|
||||
_timer.Tick += (object? _, EventArgs _) =>
|
||||
{
|
||||
Tick();
|
||||
};
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
Swallow(e);
|
||||
GoBack();
|
||||
}
|
||||
else if (e.KeyCode == Keys.Return)
|
||||
{
|
||||
Swallow(e);
|
||||
if (_armed)
|
||||
{
|
||||
GoBack();
|
||||
}
|
||||
}
|
||||
else if (!_armed)
|
||||
{
|
||||
Swallow(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void Swallow(KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
_timer.Stop();
|
||||
_goBack.PerformClick();
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
if ((keyData & (Keys.Control | Keys.Alt)) == 0)
|
||||
{
|
||||
switch (keyData & Keys.KeyCode)
|
||||
{
|
||||
case Keys.Escape:
|
||||
GoBack();
|
||||
return true;
|
||||
case Keys.Return:
|
||||
if (_armed)
|
||||
{
|
||||
GoBack();
|
||||
}
|
||||
return true;
|
||||
case Keys.Tab:
|
||||
if (!_armed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Keys.Left:
|
||||
case Keys.Up:
|
||||
case Keys.Right:
|
||||
case Keys.Down:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
private static int ButtonWidth(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font).Width + S(20);
|
||||
}
|
||||
|
||||
private void Accept()
|
||||
{
|
||||
_timer.Stop();
|
||||
Confirmed?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
_secondsLeft--;
|
||||
if (_secondsLeft <= 0)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCountdown();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCountdown()
|
||||
{
|
||||
_countdown.Text = $"{_secondsLeft} s";
|
||||
_progress.Fraction = ((_totalSeconds <= 0) ? 0f : ((float)_secondsLeft / (float)_totalSeconds));
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
base.OnShown(e);
|
||||
_timer.Start();
|
||||
ActiveControl = _goBack;
|
||||
Activate();
|
||||
Timer arm = new Timer
|
||||
{
|
||||
Interval = (int)ArmAfter.TotalMilliseconds
|
||||
};
|
||||
arm.Tick += (object? _, EventArgs _) =>
|
||||
{
|
||||
_armed = true;
|
||||
arm.Stop();
|
||||
arm.Dispose();
|
||||
};
|
||||
arm.Start();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_timer.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
internal void TestAdvanceOneSecond()
|
||||
{
|
||||
Tick();
|
||||
}
|
||||
|
||||
internal void TestArmEnterNow()
|
||||
{
|
||||
_armed = true;
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class RovingFocus
|
||||
{
|
||||
private static readonly ConditionalWeakTable<Control, RovingFocus> ByItem = new ConditionalWeakTable<Control, RovingFocus>();
|
||||
|
||||
[ThreadStatic]
|
||||
private static List<WeakReference<RovingFocus>>? _groups;
|
||||
|
||||
private readonly Control[] _items;
|
||||
|
||||
private readonly Func<Control, bool> _isSelected;
|
||||
|
||||
private readonly Func<Control, bool> _arrowChooses;
|
||||
|
||||
internal IReadOnlyList<Control> Items => _items;
|
||||
|
||||
private RovingFocus(Control[] items, Func<Control, bool> isSelected, Func<Control, bool> arrowChooses)
|
||||
{
|
||||
_items = items;
|
||||
_isSelected = isSelected;
|
||||
_arrowChooses = arrowChooses;
|
||||
}
|
||||
|
||||
internal static RovingFocus Attach(IEnumerable<Control> items, Func<Control, bool> isSelected, Func<Control, bool>? arrowChooses = null)
|
||||
{
|
||||
RovingFocus rovingFocus = new RovingFocus(items.ToArray(), isSelected, arrowChooses ?? ((Func<Control, bool>)((Control _) => true)));
|
||||
Control[] items2 = rovingFocus._items;
|
||||
foreach (Control key in items2)
|
||||
{
|
||||
ByItem.AddOrUpdate(key, rovingFocus);
|
||||
}
|
||||
(_groups ?? (_groups = new List<WeakReference<RovingFocus>>())).Add(new WeakReference<RovingFocus>(rovingFocus));
|
||||
rovingFocus.Refresh();
|
||||
return rovingFocus;
|
||||
}
|
||||
|
||||
internal static RovingFocus? Of(Control item)
|
||||
{
|
||||
if (!ByItem.TryGetValue(item, out RovingFocus value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static bool Usable(Control c)
|
||||
{
|
||||
if (!c.IsDisposed && c.Enabled)
|
||||
{
|
||||
return c.Visible;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal Control? Current()
|
||||
{
|
||||
Control control = null;
|
||||
Control control2 = null;
|
||||
Control[] items = _items;
|
||||
foreach (Control control3 in items)
|
||||
{
|
||||
if (Usable(control3))
|
||||
{
|
||||
if (_isSelected(control3))
|
||||
{
|
||||
return control3;
|
||||
}
|
||||
if (control == null)
|
||||
{
|
||||
control = control3;
|
||||
}
|
||||
if (control3.Focused)
|
||||
{
|
||||
control2 = control3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return control2 ?? control;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
Control control = Current();
|
||||
if (control == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Control[] items = _items;
|
||||
foreach (Control control2 in items)
|
||||
{
|
||||
if (!control2.IsDisposed)
|
||||
{
|
||||
control2.TabStop = control2 == control;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RefreshAll()
|
||||
{
|
||||
if (_groups == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_groups.RemoveAll((WeakReference<RovingFocus> w) => !w.TryGetTarget(out RovingFocus target2) || target2._items.All((Control c) => c.IsDisposed));
|
||||
foreach (WeakReference<RovingFocus> group in _groups)
|
||||
{
|
||||
if (group.TryGetTarget(out var target))
|
||||
{
|
||||
target.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal Control? Target(Control from, Keys keyData)
|
||||
{
|
||||
if ((keyData & Keys.Modifiers) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num = Array.IndexOf(_items, from);
|
||||
if (num < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num2 = _items.Length;
|
||||
switch (keyData & Keys.KeyCode)
|
||||
{
|
||||
case Keys.Left:
|
||||
case Keys.Up:
|
||||
{
|
||||
for (int j = 1; j <= num2; j++)
|
||||
{
|
||||
if (Usable(_items[(num - j + num2) % num2]))
|
||||
{
|
||||
return _items[(num - j + num2) % num2];
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
case Keys.Right:
|
||||
case Keys.Down:
|
||||
{
|
||||
for (int i = 1; i <= num2; i++)
|
||||
{
|
||||
if (Usable(_items[(num + i) % num2]))
|
||||
{
|
||||
return _items[(num + i) % num2];
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
case Keys.Home:
|
||||
return _items.FirstOrDefault(Usable) ?? from;
|
||||
case Keys.End:
|
||||
return _items.LastOrDefault(Usable) ?? from;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ArrowChooses(Control item)
|
||||
{
|
||||
return _arrowChooses(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public abstract class SignalDialogWindow : Form
|
||||
{
|
||||
public static class Measure
|
||||
{
|
||||
public const int Radius = 8;
|
||||
|
||||
public const int Pad = 24;
|
||||
|
||||
public const int TitleY = 23;
|
||||
|
||||
public const int BodyY = 60;
|
||||
|
||||
public const int BodyToContent = 16;
|
||||
|
||||
public const int ContentToFooter = 24;
|
||||
|
||||
public const int ButtonMinWidth = 96;
|
||||
|
||||
public const int ButtonPadX = 12;
|
||||
|
||||
public const int ButtonGap = 8;
|
||||
|
||||
public const int FooterBottom = 20;
|
||||
|
||||
public const int ButtonPad = 20;
|
||||
|
||||
public const int WidthSm = 400;
|
||||
|
||||
public const int WidthMd = 460;
|
||||
|
||||
public const int WidthLg = 560;
|
||||
}
|
||||
|
||||
private readonly int _dpi;
|
||||
|
||||
protected int ChromeDpi => _dpi;
|
||||
|
||||
protected string? ChromeTitle { get; set; }
|
||||
|
||||
protected string? ChromeBody { get; set; }
|
||||
|
||||
protected int ChromeBodyHeight { get; set; }
|
||||
|
||||
protected int TextWidth => ClientSize.Width - 2 * S(24);
|
||||
|
||||
protected int BodyTop => S(60);
|
||||
|
||||
protected int ContentTop => BodyTop + ChromeBodyHeight + S(16);
|
||||
|
||||
protected virtual bool Square => false;
|
||||
|
||||
internal static Color EdgeInk
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!SlateSurface.Active)
|
||||
{
|
||||
return SignalTokens.Ash.WindowEdge;
|
||||
}
|
||||
return ControlInk.Over(SignalTokens.Slate.WindowEdge, ControlInk.Overlay);
|
||||
}
|
||||
}
|
||||
|
||||
protected SignalDialogWindow()
|
||||
{
|
||||
_dpi = SignalInk.DpiFor(this);
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
ShowInTaskbar = false;
|
||||
BackColor = Theme.Background;
|
||||
DoubleBuffered = true;
|
||||
Icon = AppIcon.Value;
|
||||
KeyPreview = true;
|
||||
Font = Fonts.Body;
|
||||
AccessibleRole = AccessibleRole.Dialog;
|
||||
Opacity = 0.99;
|
||||
Load += (object? _, EventArgs _) =>
|
||||
{
|
||||
ApplyRegion();
|
||||
};
|
||||
Resize += (object? _, EventArgs _) =>
|
||||
{
|
||||
ApplyRegion();
|
||||
};
|
||||
}
|
||||
|
||||
protected int S(int logical)
|
||||
{
|
||||
return Tokens.ScaleAt(_dpi, logical);
|
||||
}
|
||||
|
||||
internal static int MeasureBody(string? body, int textWidth)
|
||||
{
|
||||
int val = Fonts.LineHeight(FontRole.Body);
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int height = TextRenderer.MeasureText(body, Fonts.Body, new Size(Math.Max(1, textWidth), 0), TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height;
|
||||
return Math.Max(val, height);
|
||||
}
|
||||
|
||||
internal static Label TitleLabel(string text, int inkLeft, int top, int width)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Title,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(Ink(inkLeft, Fonts.Title), top),
|
||||
Size = new Size(width, Fonts.LineHeight(FontRole.Title))
|
||||
};
|
||||
}
|
||||
|
||||
internal static Label BodyLabel(string text, int inkLeft, int top, int width, int height)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(Ink(inkLeft, Fonts.Body), top),
|
||||
Size = new Size(width, height)
|
||||
};
|
||||
}
|
||||
|
||||
internal static int TwinButtonWidth(string text, Font font, int scaledPad, int scaledMin)
|
||||
{
|
||||
return Math.Max(scaledMin, TextRenderer.MeasureText(text, font).Width + scaledPad);
|
||||
}
|
||||
|
||||
protected GlassButton FooterButton(string text, GlassButtonKind kind, string? name = null)
|
||||
{
|
||||
GlassButton glassButton = new GlassButton
|
||||
{
|
||||
Text = text,
|
||||
Kind = kind
|
||||
};
|
||||
if (name != null)
|
||||
{
|
||||
glassButton.Name = name;
|
||||
}
|
||||
int width = Math.Max(S(96), TextRenderer.MeasureText(text, glassButton.Font).Width + 2 * S(12));
|
||||
glassButton.Size = new Size(width, S(32));
|
||||
glassButton.AccessibleName = text;
|
||||
return glassButton;
|
||||
}
|
||||
|
||||
protected void PlaceFooter(params GlassButton[] leftToRight)
|
||||
{
|
||||
int num = S(24);
|
||||
int num2 = ClientSize.Width - num;
|
||||
for (int num3 = leftToRight.Length - 1; num3 >= 0; num3--)
|
||||
{
|
||||
GlassButton glassButton = leftToRight[num3];
|
||||
num2 -= glassButton.Width;
|
||||
glassButton.Location = new Point(num2, ClientSize.Height - S(20) - glassButton.Height);
|
||||
glassButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
num2 -= S(8);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyRegion()
|
||||
{
|
||||
if (Square)
|
||||
{
|
||||
if (Region != null)
|
||||
{
|
||||
Region = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(0f, 0f, ClientSize.Width, ClientSize.Height), S(8));
|
||||
Region = new Region(path);
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Theme.Background);
|
||||
e.Graphics.FillRectangle(brush, ClientRectangle);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
PaintChrome(e.Graphics, ClientSize, _dpi, Square);
|
||||
PaintWords(e.Graphics);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
internal static void PaintChrome(Graphics g, Size size, int dpi, bool square = false)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Theme.Background))
|
||||
{
|
||||
g.FillRectangle(brush, new Rectangle(Point.Empty, size));
|
||||
}
|
||||
if (square)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(ControlInk.Overlay))
|
||||
{
|
||||
g.FillRectangle(brush2, new Rectangle(Point.Empty, size));
|
||||
}
|
||||
PaintSquareEdge(g, size, dpi);
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlInk.PaintBox(g, size, Tokens.ScaleAt(dpi, 8), ControlInk.Hairline(dpi), ControlInk.Overlay, EdgeInk);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void PaintSquareEdge(Graphics g, Size size, int dpi)
|
||||
{
|
||||
int num = Math.Min(ControlInk.Hairline(dpi), Math.Min(size.Width, size.Height) / 2);
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
g.PixelOffsetMode = PixelOffsetMode.None;
|
||||
try
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(EdgeInk);
|
||||
g.FillRectangle(brush, 0, 0, size.Width, num);
|
||||
g.FillRectangle(brush, 0, size.Height - num, size.Width, num);
|
||||
g.FillRectangle(brush, 0, 0, num, size.Height);
|
||||
g.FillRectangle(brush, size.Width - num, 0, num, size.Height);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintWords(Graphics g)
|
||||
{
|
||||
int num = S(24);
|
||||
int textWidth = TextWidth;
|
||||
if (!string.IsNullOrEmpty(ChromeTitle))
|
||||
{
|
||||
TextRenderer.DrawText(g, ChromeTitle, Fonts.Title, new Rectangle(Ink(num + S(2), Fonts.Title), S(23), textWidth + GlyphPad(Fonts.Title), Fonts.LineHeight(FontRole.Title)), Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ChromeBody))
|
||||
{
|
||||
TextRenderer.DrawText(g, ChromeBody, Fonts.Body, new Rectangle(Ink(num + S(2), Fonts.Body), BodyTop, textWidth + GlyphPad(Fonts.Body), ChromeBodyHeight), Theme.TextDim, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak);
|
||||
}
|
||||
}
|
||||
|
||||
internal static int GlyphPad(Font font)
|
||||
{
|
||||
return (TextRenderer.MeasureText("H", font).Width - TextRenderer.MeasureText("H", font, Size.Empty, TextFormatFlags.NoPadding).Width) / 2;
|
||||
}
|
||||
|
||||
internal static int Ink(int x, Font font)
|
||||
{
|
||||
return x - GlyphPad(font);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class SignalToolTip : ToolTip
|
||||
{
|
||||
internal const int PadX = 8;
|
||||
|
||||
internal const int PadY = 4;
|
||||
|
||||
internal const int MaxWidth = 280;
|
||||
|
||||
internal const int Radius = 4;
|
||||
|
||||
private static int Dpi => Tokens.Dpi;
|
||||
|
||||
public SignalToolTip()
|
||||
{
|
||||
OwnerDraw = true;
|
||||
UseAnimation = false;
|
||||
UseFading = false;
|
||||
InitialDelay = 500;
|
||||
ReshowDelay = 120;
|
||||
AutoPopDelay = 32767;
|
||||
BackColor = ControlInk.Overlay;
|
||||
ForeColor = ControlInk.Text1;
|
||||
Draw += (object? _, DrawToolTipEventArgs e) =>
|
||||
{
|
||||
Paint(e.Graphics, e.Bounds, e.ToolTipText, GroundOf(e.AssociatedControl));
|
||||
};
|
||||
Popup += (object? _, PopupEventArgs e) =>
|
||||
{
|
||||
e.ToolTipSize = Measure(GetToolTip(e.AssociatedControl) ?? string.Empty);
|
||||
};
|
||||
}
|
||||
|
||||
internal static Color GroundOf(Control? c)
|
||||
{
|
||||
while (c != null)
|
||||
{
|
||||
Color backColor = c.BackColor;
|
||||
if (backColor.A == byte.MaxValue && !backColor.IsEmpty && backColor.ToArgb() != Control.DefaultBackColor.ToArgb())
|
||||
{
|
||||
return backColor;
|
||||
}
|
||||
c = c.Parent;
|
||||
}
|
||||
return Theme.Background;
|
||||
}
|
||||
|
||||
internal static Size Measure(string text)
|
||||
{
|
||||
int dpi = Dpi;
|
||||
int num = Tokens.ScaleAt(dpi, 8);
|
||||
int num2 = Tokens.ScaleAt(dpi, 4);
|
||||
int width = Tokens.ScaleAt(dpi, 280) - 2 * num;
|
||||
Size size = TextRenderer.MeasureText(text, Fonts.Caption, new Size(width, 0), TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
return new Size(size.Width + 2 * num, size.Height + 2 * num2);
|
||||
}
|
||||
|
||||
internal static void Paint(Graphics g, Rectangle bounds, string text, Color? ground = null)
|
||||
{
|
||||
int dpi = Dpi;
|
||||
using (SolidBrush brush = new SolidBrush(ground ?? Theme.Background))
|
||||
{
|
||||
g.FillRectangle(brush, bounds);
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(bounds.X, bounds.Y);
|
||||
ControlInk.PaintBox(g, bounds.Size, Tokens.ScaleAt(dpi, 4), ControlInk.Hairline(dpi), ControlInk.Overlay, SignalDialogWindow.EdgeInk);
|
||||
g.Restore(gstate);
|
||||
int num = Tokens.ScaleAt(dpi, 8);
|
||||
int num2 = Tokens.ScaleAt(dpi, 4);
|
||||
TextRenderer.DrawText(g, text, Fonts.Caption, new Rectangle(bounds.X + num, bounds.Y + num2, bounds.Width - 2 * num, bounds.Height - 2 * num2), ControlInk.Text1, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal static class TheClipboard
|
||||
{
|
||||
internal static Action<string>? InsteadOfTheRealOneForTest { get; set; }
|
||||
|
||||
internal static bool Put(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Action<string> insteadOfTheRealOneForTest = InsteadOfTheRealOneForTest;
|
||||
if (insteadOfTheRealOneForTest != null)
|
||||
{
|
||||
insteadOfTheRealOneForTest(text);
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(text);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CrashLog.Write(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class VoteButton : Control
|
||||
{
|
||||
private bool _active;
|
||||
|
||||
private readonly HoverFade _fade;
|
||||
|
||||
private readonly HoverFade _press;
|
||||
|
||||
public bool ThumbUp { get; init; }
|
||||
|
||||
public Func<Color> Tint { get; init; } = () => Theme.Accent;
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public VoteButton()
|
||||
{
|
||||
_fade = new HoverFade(this);
|
||||
_press = new HoverFade(this);
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
Size = new Size(64, 40);
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
AccessibleRole = AccessibleRole.RadioButton;
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AccessibleName = Text;
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_fade.Set(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_fade.Set(hot: false);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
_press.Snap(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Color color = Tint();
|
||||
float value = _press.Value;
|
||||
float num = 1.5f * value;
|
||||
RectangleF rect = new RectangleF(0.5f + num, 0.5f + num, (float)(Width - 1) - 2f * num, (float)(Height - 1) - 2f * num);
|
||||
if (rect.Width <= 0f || rect.Height <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float num2 = rect.Height / 2f;
|
||||
using (GraphicsPath path = Glass.RoundedPath(rect, num2))
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Color.FromArgb(_active ? 210 : ((int)(26f + 34f * _fade.Value)), color)))
|
||||
{
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using Pen pen = new Pen(Color.FromArgb(_active ? 235 : 110, color), 1f);
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
if (Focused)
|
||||
{
|
||||
using Pen pen2 = new Pen(Color.FromArgb(200, color), 2f);
|
||||
using GraphicsPath path2 = Glass.RoundedPath(RectangleF.Inflate(rect, -2.5f, -2.5f), Math.Max(1f, num2 - 2.5f));
|
||||
graphics.DrawPath(pen2, path2);
|
||||
}
|
||||
Color color2 = (_active ? Theme.OnAccent : color);
|
||||
DrawThumb(graphics, new Rectangle((int)(rect.X + rect.Width / 2f) - 9, (int)(rect.Y + rect.Height / 2f) - 9, 18, 18), color2, ThumbUp);
|
||||
}
|
||||
|
||||
private static void DrawThumb(Graphics g, Rectangle r, Color color, bool up)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
try
|
||||
{
|
||||
g.TranslateTransform((float)r.X + (float)r.Width / 2f, (float)r.Y + (float)r.Height / 2f);
|
||||
if (!up)
|
||||
{
|
||||
g.ScaleTransform(1f, -1f);
|
||||
}
|
||||
float num = (float)r.Width / 20f;
|
||||
g.ScaleTransform(num, num);
|
||||
using SolidBrush brush = new SolidBrush(color);
|
||||
using (GraphicsPath path = Glass.RoundedPath(new RectangleF(-3.5f, -9f, 5f, 9f), 2.5f))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
using (GraphicsPath path2 = Glass.RoundedPath(new RectangleF(-3.5f, -2.5f, 11.5f, 9.5f), 2.5f))
|
||||
{
|
||||
g.FillPath(brush, path2);
|
||||
}
|
||||
using GraphicsPath path3 = Glass.RoundedPath(new RectangleF(-9f, -1.5f, 4f, 8.5f), 1.5f);
|
||||
g.FillPath(brush, path3);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.Restore(gstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Zoom;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class ZoomSection : Panel
|
||||
{
|
||||
internal const string Title = "Hold to zoom";
|
||||
|
||||
internal const string FairPlay = "Zoom uses Windows' own Magnifier. Some games' rules treat zoom as an advantage - check yours.";
|
||||
|
||||
internal const string LockedLine = "Zoom comes with the Dark Boost & Zoom add-on.";
|
||||
|
||||
internal const string PickAKey = "Pick a key to hold.";
|
||||
|
||||
internal const string EdgesWord = "Smooth edges";
|
||||
|
||||
internal const string EdgesHint = "Off: sharp pixels. On: softer, a little blurry.";
|
||||
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
private readonly Action _save;
|
||||
|
||||
private readonly Func<bool> _allowed;
|
||||
|
||||
private readonly Func<uint, uint, bool> _bindKey;
|
||||
|
||||
private readonly Func<string> _whyRefused;
|
||||
|
||||
private bool _syncing;
|
||||
|
||||
private readonly Label _title;
|
||||
|
||||
private readonly Label _keyWord;
|
||||
|
||||
private readonly Label _levelWord;
|
||||
|
||||
private readonly Label _levelValue;
|
||||
|
||||
private readonly Label _smoothWord;
|
||||
|
||||
private readonly Label _edgesWord;
|
||||
|
||||
private readonly Label _edgesHint;
|
||||
|
||||
private readonly Label _status;
|
||||
|
||||
private readonly Label _fair;
|
||||
|
||||
private readonly ToggleSwitch _on;
|
||||
|
||||
private readonly ToggleSwitch _smooth;
|
||||
|
||||
private readonly ToggleSwitch _edges;
|
||||
|
||||
private readonly HotkeyPicker _key;
|
||||
|
||||
private readonly FlatSlider _level;
|
||||
|
||||
public int WantedHeight => RowPitch * 4 + EdgesBlockHeight() + Tokens.Scale(20) + FairHeight() + Tokens.Scale(8);
|
||||
|
||||
private int RowPitch => Tokens.Scale(40);
|
||||
|
||||
public int Gutter => FlatSlider.EdgeInsetAt(ControlInk.Dpi(this));
|
||||
|
||||
internal ToggleSwitch SwitchForTest => _on;
|
||||
|
||||
internal ToggleSwitch EdgesForTest => _edges;
|
||||
|
||||
internal HotkeyPicker KeyForTest => _key;
|
||||
|
||||
internal FlatSlider LevelForTest => _level;
|
||||
|
||||
internal string StatusForTest => _status.Text;
|
||||
|
||||
public event Action? Changed;
|
||||
|
||||
public ZoomSection(AppSettings settings, Action save, Func<bool> allowed, Func<uint, uint, bool> bindKey, Func<string> whyRefused)
|
||||
{
|
||||
_settings = settings;
|
||||
_save = save;
|
||||
_allowed = allowed;
|
||||
_bindKey = bindKey;
|
||||
_whyRefused = whyRefused;
|
||||
BackColor = Color.Transparent;
|
||||
Name = "zoomSection";
|
||||
_title = Words("Hold to zoom", Fonts.BodyBold, Theme.Text);
|
||||
_on = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Hold to zoom",
|
||||
Name = "zoomSwitch"
|
||||
};
|
||||
_on.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetEnabled(_on.Checked);
|
||||
}
|
||||
};
|
||||
_keyWord = Words("Zoom key", Fonts.Body, Theme.TextDim);
|
||||
_key = new HotkeyPicker
|
||||
{
|
||||
AllowMouseButtons = true,
|
||||
AccessibleName = "Zoom key",
|
||||
Name = "zoomKey"
|
||||
};
|
||||
_key.HotkeyChanged += (uint mask, uint vk) =>
|
||||
{
|
||||
ChooseKey(mask, vk);
|
||||
};
|
||||
_levelWord = Words("Zoom level", Fonts.Body, Theme.TextDim);
|
||||
_levelValue = Words("", Fonts.BodyBold, Theme.Text);
|
||||
_levelValue.TextAlign = ContentAlignment.MiddleRight;
|
||||
_level = new FlatSlider
|
||||
{
|
||||
AccessibleName = "Zoom level",
|
||||
Name = "zoomLevel",
|
||||
Minimum = (int)Math.Round(6.0),
|
||||
Maximum = (int)Math.Round(16.0),
|
||||
Value = (int)Math.Round(8.0)
|
||||
};
|
||||
_level.ValueChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetLevel((float)_level.Value * 0.25f);
|
||||
}
|
||||
};
|
||||
_smoothWord = Words("Smooth", Fonts.Body, Theme.TextDim);
|
||||
_smooth = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Smooth zoom",
|
||||
Name = "zoomSmooth"
|
||||
};
|
||||
_smooth.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetSmooth(_smooth.Checked);
|
||||
}
|
||||
};
|
||||
_edgesWord = Words("Smooth edges", Fonts.Body, Theme.TextDim);
|
||||
_edges = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Smooth edges",
|
||||
Name = "zoomSmoothEdges"
|
||||
};
|
||||
_edges.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetSmoothEdges(_edges.Checked);
|
||||
}
|
||||
};
|
||||
_edgesHint = Words("Off: sharp pixels. On: softer, a little blurry.", Fonts.Caption, Theme.TextFaint);
|
||||
_status = Words("", Fonts.Caption, Theme.TextDim);
|
||||
_fair = Words("Zoom uses Windows' own Magnifier. Some games' rules treat zoom as an advantage - check yours.", Fonts.Caption, Theme.TextFaint);
|
||||
Controls.AddRange(new Control[14]
|
||||
{
|
||||
_title, _on, _keyWord, _key, _levelWord, _levelValue, _level, _smoothWord, _smooth, _edgesWord,
|
||||
_edges, _edgesHint, _status, _fair
|
||||
});
|
||||
Sync();
|
||||
}
|
||||
|
||||
private Label Words(string text, Font font, Color colour)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = font,
|
||||
ForeColor = colour,
|
||||
BackColor = Color.Transparent,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
AutoSize = false,
|
||||
UseMnemonic = false
|
||||
};
|
||||
}
|
||||
|
||||
private static int EdgesBlockHeight()
|
||||
{
|
||||
return Tokens.Scale(26) + Tokens.Scale(20) + Tokens.Scale(4);
|
||||
}
|
||||
|
||||
private int FairHeight()
|
||||
{
|
||||
return Tokens.Scale(36);
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
base.OnLayout(e);
|
||||
int gutter = Gutter;
|
||||
int num = Math.Max(Tokens.Scale(200), ClientSize.Width - 2 * gutter);
|
||||
int rowPitch = RowPitch;
|
||||
int num2 = Tokens.Scale(26);
|
||||
int num3 = Tokens.Scale(40);
|
||||
int num4 = Tokens.Scale(20);
|
||||
int num5 = 0;
|
||||
_title.SetBounds(gutter - Ink(_title), num5, num - num3 - 8, num2);
|
||||
_on.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += rowPitch;
|
||||
int num6 = Math.Min(num - Tokens.Scale(110), Tokens.Scale(300));
|
||||
_keyWord.SetBounds(gutter - Ink(_keyWord), num5, Tokens.Scale(100), num2);
|
||||
_key.SetBounds(gutter + num - num6, num5 - Tokens.Scale(4), num6, Tokens.Scale(36));
|
||||
num5 += rowPitch;
|
||||
_levelWord.SetBounds(gutter - Ink(_levelWord), num5, num - Tokens.Scale(70), num2);
|
||||
_levelValue.SetBounds(gutter + num - Tokens.Scale(70) + Ink(_levelValue), num5, Tokens.Scale(70), num2);
|
||||
_level.SetTrackBounds(gutter, num5 + num2 + Tokens.Scale(2), num, Tokens.Scale(16));
|
||||
num5 += rowPitch + Tokens.Scale(8);
|
||||
_smoothWord.SetBounds(gutter - Ink(_smoothWord), num5, num - num3 - 8, num2);
|
||||
_smooth.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += rowPitch - Tokens.Scale(8);
|
||||
_edgesWord.SetBounds(gutter - Ink(_edgesWord), num5, num - num3 - 8, num2);
|
||||
_edges.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += num2;
|
||||
_edgesHint.SetBounds(gutter - Ink(_edgesHint), num5, num, Tokens.Scale(20));
|
||||
num5 += Tokens.Scale(20) + Tokens.Scale(4);
|
||||
_status.SetBounds(gutter - Ink(_status), num5, num, Tokens.Scale(20));
|
||||
_fair.SetBounds(gutter - Ink(_fair), num5 + Tokens.Scale(20), num, FairHeight());
|
||||
}
|
||||
|
||||
private static int Ink(Label l)
|
||||
{
|
||||
return ControlInk.LabelInkInset(l.Font);
|
||||
}
|
||||
|
||||
public void Sync()
|
||||
{
|
||||
_syncing = true;
|
||||
try
|
||||
{
|
||||
bool flag = _allowed();
|
||||
_on.Checked = _settings.ZoomEnabled & flag;
|
||||
ToggleSwitch toggleSwitch = _on;
|
||||
HotkeyPicker key = _key;
|
||||
FlatSlider level = _level;
|
||||
ToggleSwitch smooth = _smooth;
|
||||
bool flag2 = (_edges.Enabled = flag);
|
||||
bool flag4 = (smooth.Enabled = flag2);
|
||||
bool flag6 = (level.Enabled = flag4);
|
||||
bool enabled = (key.Enabled = flag6);
|
||||
toggleSwitch.Enabled = enabled;
|
||||
_key.ModifierMask = _settings.ZoomHotkeyModifierMask;
|
||||
_key.VirtualKey = _settings.ZoomHotkeyVirtualKey;
|
||||
float num = ZoomMath.ClampSetting(_settings.ZoomLevel);
|
||||
_level.Value = (int)Math.Round(num / 0.25f);
|
||||
_levelValue.Text = num.ToString("0.0#", CultureInfo.InvariantCulture) + "x";
|
||||
_smooth.Checked = _settings.ZoomSmooth;
|
||||
_edges.Checked = _settings.ZoomSmoothEdges;
|
||||
_status.Text = StatusLine();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_syncing = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal string StatusLine()
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
return "Zoom comes with the Dark Boost & Zoom add-on.";
|
||||
}
|
||||
string text = _whyRefused();
|
||||
if (text.Length > 0)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
if (!_settings.ZoomEnabled)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (_settings.ZoomHotkeyVirtualKey == 0)
|
||||
{
|
||||
return "Pick a key to hold.";
|
||||
}
|
||||
string display = HotkeyPicker.GetDisplay(_settings.ZoomHotkeyModifierMask, _settings.ZoomHotkeyVirtualKey);
|
||||
HotkeySlot? hotkeySlot = HotkeyConflicts.Owner(_settings, HotkeySlot.Zoom, _settings.ZoomHotkeyModifierMask, _settings.ZoomHotkeyVirtualKey);
|
||||
if (hotkeySlot.HasValue)
|
||||
{
|
||||
HotkeySlot valueOrDefault = hotkeySlot.GetValueOrDefault();
|
||||
return display + " is taken by " + HotkeyConflicts.Describe(valueOrDefault) + ". Pick another key.";
|
||||
}
|
||||
return "Hold " + display + (_settings.HotkeysOnlyInGames ? " in a game to zoom." : " to zoom.");
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomEnabled = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void ChooseKey(uint mask, uint vk)
|
||||
{
|
||||
if (_syncing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
if (vk == 0 || _bindKey(mask, vk))
|
||||
{
|
||||
_settings.ZoomHotkeyModifierMask = ((vk != 0) ? mask : 0u);
|
||||
_settings.ZoomHotkeyVirtualKey = vk;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetLevel(float level)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomLevel = ZoomMath.ClampSetting(level);
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetSmooth(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomSmooth = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetSmoothEdges(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomSmoothEdges = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user