upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using VibranceHud.DarkBoost;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal static class DarkBoostScene
|
||||
{
|
||||
internal const int W = 360;
|
||||
|
||||
internal const int H = 120;
|
||||
|
||||
private const double Gain = 4.0;
|
||||
|
||||
private static float[]? _scene;
|
||||
|
||||
private static double Hash(double x, double y)
|
||||
{
|
||||
double num = Math.Sin(x * 127.1 + y * 311.7) * 43758.5453;
|
||||
return num - Math.Floor(num);
|
||||
}
|
||||
|
||||
internal static float[] Scene()
|
||||
{
|
||||
if (_scene != null)
|
||||
{
|
||||
return _scene;
|
||||
}
|
||||
float[] array = new float[129600];
|
||||
for (int i = 0; i < 120; i++)
|
||||
{
|
||||
for (int j = 0; j < 360; j++)
|
||||
{
|
||||
double num = 70.0 + 10.0 * Math.Sin((double)j / 40.0) + 5.0 * Math.Sin((double)j / 13.0);
|
||||
double num2 = (Hash(j, i) - 0.5) * 0.004;
|
||||
double num4;
|
||||
double num5;
|
||||
double num6;
|
||||
if ((double)i < num)
|
||||
{
|
||||
double num3 = 0.022 + 0.012 * ((double)i / num);
|
||||
num4 = num3 * 0.6;
|
||||
num5 = num3 * 0.75;
|
||||
num6 = num3;
|
||||
}
|
||||
else
|
||||
{
|
||||
double num7 = 0.016 + 0.005 * Math.Sin((double)j / 23.0) * Math.Sin((double)i / 11.0);
|
||||
num4 = num7 * 0.9;
|
||||
num5 = num7;
|
||||
num6 = num7 * 0.6;
|
||||
}
|
||||
double value = j % 70 - 35;
|
||||
double num8 = num - 34.0;
|
||||
if (j > 20 && j < 330 && (double)i > num8 + Math.Abs(value) * 1.3 && (double)i < num + 6.0 && Math.Abs(value) < 18.0 && Math.Floor((double)j / 70.0) % 2.0 == 0.0)
|
||||
{
|
||||
num4 = 0.006;
|
||||
num5 = 0.009;
|
||||
num6 = 0.006;
|
||||
}
|
||||
if (j >= 230 && j <= 300 && i >= 48 && i <= 96)
|
||||
{
|
||||
num4 = 0.03;
|
||||
num5 = 0.024;
|
||||
num6 = 0.02;
|
||||
}
|
||||
if (j >= 250 && j <= 266 && i >= 60 && i <= 74)
|
||||
{
|
||||
num4 = 0.85;
|
||||
num5 = 0.62;
|
||||
num6 = 0.3;
|
||||
}
|
||||
double num9 = Math.Sqrt((j - 120) * (j - 120) + (i - 30) * (i - 30));
|
||||
if (num9 < 4.0)
|
||||
{
|
||||
num4 = 0.95;
|
||||
num5 = 0.9;
|
||||
num6 = 0.75;
|
||||
}
|
||||
else if (num9 < 30.0)
|
||||
{
|
||||
double num10 = (30.0 - num9) / 30.0 * 0.05;
|
||||
num4 += num10;
|
||||
num5 += num10 * 0.9;
|
||||
num6 += num10 * 0.6;
|
||||
}
|
||||
if (Math.Sqrt(Math.Pow((double)(j - 60) / 1.6, 2.0) + Math.Pow(i - 104, 2.0)) < 9.0 || Math.Sqrt(Math.Pow((double)(j - 175) / 2.0, 2.0) + Math.Pow(i - 100, 2.0)) < 7.0)
|
||||
{
|
||||
num4 = 0.008;
|
||||
num5 = 0.008;
|
||||
num6 = 0.009;
|
||||
}
|
||||
int num11 = (i * 360 + j) * 3;
|
||||
array[num11] = (float)(num4 + num2);
|
||||
array[num11 + 1] = (float)(num5 + num2);
|
||||
array[num11 + 2] = (float)(num6 + num2);
|
||||
}
|
||||
}
|
||||
return _scene = array;
|
||||
}
|
||||
|
||||
internal static float[] IllustrationBase()
|
||||
{
|
||||
double[] array = DarkBoostTints.PreviewWeights(DarkBoostTint.Green);
|
||||
float[] array2 = new float[25];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array2[i * 5 + j] = (float)(4.0 * array[j]);
|
||||
}
|
||||
}
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
array2[20 + k] = (float)(-12.0 * array[k] / 255.0);
|
||||
}
|
||||
array2[18] = 1f;
|
||||
array2[24] = 1f;
|
||||
return array2;
|
||||
}
|
||||
|
||||
internal static float[] PictureFor(DarkBoostSetup setup, double strength, float[]? basis)
|
||||
{
|
||||
return DarkBoostLook.Picture(basis ?? IllustrationBase(), setup.Tint, setup.BlackLevel, strength);
|
||||
}
|
||||
|
||||
internal static double WhiteFrom(DarkBoostSetup setup, float[]? basis)
|
||||
{
|
||||
return DarkBoostLook.WhiteFrom(PictureFor(setup, (double)setup.Strength / 100.0, basis));
|
||||
}
|
||||
|
||||
internal static Bitmap Render(float[] matrix, ushort[]? ramp)
|
||||
{
|
||||
float[] array = Scene();
|
||||
Bitmap bitmap = new Bitmap(360, 120, PixelFormat.Format32bppArgb);
|
||||
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, 360, 120), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
try
|
||||
{
|
||||
byte[] array2 = new byte[1440];
|
||||
for (int i = 0; i < 120; i++)
|
||||
{
|
||||
for (int j = 0; j < 360; j++)
|
||||
{
|
||||
int num = (i * 360 + j) * 3;
|
||||
var (b, b2, b3) = DarkBoostLook.Pixel(array[num], array[num + 1], array[num + 2], matrix, ramp);
|
||||
array2[j * 4] = b3;
|
||||
array2[j * 4 + 1] = b2;
|
||||
array2[j * 4 + 2] = b;
|
||||
array2[j * 4 + 3] = byte.MaxValue;
|
||||
}
|
||||
Marshal.Copy(array2, 0, bitmapData.Scan0 + i * bitmapData.Stride, array2.Length);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,875 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Controls;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
public class GlowPage : UserControl
|
||||
{
|
||||
private sealed class HeaderLabel : Label
|
||||
{
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (!NeedsAHalo || Font.Height < 28)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
PaintHeaderText(e.Graphics, Text, Font, ForeColor, ClientRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _bringingIntoView;
|
||||
|
||||
private const int SB_BOTH = 3;
|
||||
|
||||
protected const int HeaderHeight = 86;
|
||||
|
||||
private bool _headerAdded;
|
||||
|
||||
protected const int Gutter = 16;
|
||||
|
||||
internal const int HeaderPanelHeight = 84;
|
||||
|
||||
internal const int HeaderToolbarGap = 12;
|
||||
|
||||
internal const int HeaderToolbarHeight = 32;
|
||||
|
||||
private const int HeaderPadX = 20;
|
||||
|
||||
private const int HeaderPadY = 12;
|
||||
|
||||
private const int ShellEdge = 1;
|
||||
|
||||
private HeaderPanel? _headerCard;
|
||||
|
||||
private Control? _headerTitleControl;
|
||||
|
||||
private Control? _headerSubtitleControl;
|
||||
|
||||
private Control? _headerToolbar;
|
||||
|
||||
private Control[] _headerActions = Array.Empty<Control>();
|
||||
|
||||
private int _headerSubtitleExtra;
|
||||
|
||||
private int _scaledForDpi = 96;
|
||||
|
||||
private HeaderLabel? _headerTitle;
|
||||
|
||||
private HeaderLabel? _headerSubtitle;
|
||||
|
||||
private int _contentWidth;
|
||||
|
||||
private Dictionary<Control, int>? _designLeft;
|
||||
|
||||
private int _centredForWidth = -1;
|
||||
|
||||
private int _lastOffset;
|
||||
|
||||
public IBackdrop? Field { get; set; }
|
||||
|
||||
public Point FieldOffset { get; set; }
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams createParams = base.CreateParams;
|
||||
createParams.ExStyle |= 33554432;
|
||||
return createParams;
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollExtent => HonestExtentHeight();
|
||||
|
||||
public int ScrollViewport => ClientSize.Height;
|
||||
|
||||
public int ScrollOffset => -AutoScrollPosition.Y;
|
||||
|
||||
protected virtual int ScrollBottomPadding => 40;
|
||||
|
||||
protected virtual string? PageTitle => null;
|
||||
|
||||
protected virtual string PageSubtitle => "";
|
||||
|
||||
protected virtual bool UsesHeaderPanel => false;
|
||||
|
||||
protected virtual Control[] HeaderActions => Array.Empty<Control>();
|
||||
|
||||
protected virtual Control? HeaderToolbar => null;
|
||||
|
||||
internal HeaderPanel? HeaderCardForTest => _headerCard;
|
||||
|
||||
internal Control? HeaderTitleForTest => _headerTitleControl;
|
||||
|
||||
internal Control? HeaderSubtitleForTest => _headerSubtitleControl;
|
||||
|
||||
protected bool HasHeaderPanel => _headerCard != null;
|
||||
|
||||
protected static int ContentLeft => S(16);
|
||||
|
||||
protected int ContentRight => Width + 1 - S(16);
|
||||
|
||||
protected int HeaderPanelHeightPx
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_headerCard != null)
|
||||
{
|
||||
return S(84) + _headerSubtitleExtra + ((_headerToolbar != null) ? S(44) : 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected int ContentTop
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_headerCard != null)
|
||||
{
|
||||
return S(16) + HeaderPanelHeightPx + S(16);
|
||||
}
|
||||
return S(16);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool LaysOutInLogicalPixels => true;
|
||||
|
||||
internal static bool NeedsAHalo => SlateSurface.Active;
|
||||
|
||||
protected int ContentWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _contentWidth;
|
||||
}
|
||||
set
|
||||
{
|
||||
_contentWidth = value;
|
||||
CentreContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected float DesignScale => (float)_scaledForDpi / 96f;
|
||||
|
||||
public event EventHandler? ScrollStateChanged;
|
||||
|
||||
protected GlowPage()
|
||||
{
|
||||
Dock = DockStyle.Fill;
|
||||
BackColor = Theme.Background;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
}
|
||||
|
||||
protected override void OnScroll(ScrollEventArgs se)
|
||||
{
|
||||
base.OnScroll(se);
|
||||
RaiseScrollState();
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
internal void InvalidateBackdropOnly()
|
||||
{
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
int extent = ScrollExtent - ClientSize.Height;
|
||||
ScrollTrace.Write(() => $"{GetType().Name} wheel {e.Delta} autoScroll={AutoScroll} client={ClientSize.Height} min={AutoScrollMinSize.Height} extent={extent} offset={-AutoScrollPosition.Y}");
|
||||
int num = -AutoScrollPosition.Y;
|
||||
if (AutoScroll && extent > 0)
|
||||
{
|
||||
int num2 = SystemInformation.MouseWheelScrollLines;
|
||||
if (num2 <= 0)
|
||||
{
|
||||
num2 = 3;
|
||||
}
|
||||
int num3 = e.Delta * num2 * 22 / 120;
|
||||
int target = Math.Clamp(-AutoScrollPosition.Y - num3, 0, extent);
|
||||
if (target != -AutoScrollPosition.Y)
|
||||
{
|
||||
AutoScrollPosition = new Point(-AutoScrollPosition.X, target);
|
||||
}
|
||||
ScrollTrace.Write(() => $" -> target={target} landed={-AutoScrollPosition.Y}");
|
||||
if (e is HandledMouseEventArgs e2)
|
||||
{
|
||||
e2.Handled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ScrollTrace.Write(() => " -> IGNORED (nothing to scroll)");
|
||||
base.OnMouseWheel(e);
|
||||
}
|
||||
if (-AutoScrollPosition.Y != num)
|
||||
{
|
||||
RaiseScrollState();
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
}
|
||||
|
||||
public void ScrollByWheel(int delta)
|
||||
{
|
||||
OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
|
||||
}
|
||||
|
||||
internal void TestScrollWheel(int delta)
|
||||
{
|
||||
ScrollByWheel(delta);
|
||||
}
|
||||
|
||||
private void HookWheelForwarding(Control root)
|
||||
{
|
||||
foreach (Control control in root.Controls)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
control.GotFocus -= OnDescendantGotFocus;
|
||||
control.GotFocus += OnDescendantGotFocus;
|
||||
control.ControlAdded -= OnDescendantAdded;
|
||||
control.ControlAdded += OnDescendantAdded;
|
||||
HookWheelForwarding(control);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDescendantAdded(object? sender, ControlEventArgs e)
|
||||
{
|
||||
Control control = e.Control;
|
||||
if (control != null)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
control.GotFocus -= OnDescendantGotFocus;
|
||||
control.GotFocus += OnDescendantGotFocus;
|
||||
control.ControlAdded -= OnDescendantAdded;
|
||||
control.ControlAdded += OnDescendantAdded;
|
||||
HookWheelForwarding(control);
|
||||
}
|
||||
}
|
||||
|
||||
private void ForwardWheel(object? sender, MouseEventArgs e)
|
||||
{
|
||||
OnMouseWheel(e);
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
Control control = ActiveControl;
|
||||
while (control is ContainerControl containerControl)
|
||||
{
|
||||
Control activeControl = containerControl.ActiveControl;
|
||||
if (activeControl == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
control = activeControl;
|
||||
}
|
||||
if (control != null)
|
||||
{
|
||||
RovingFocus rovingFocus = RovingFocus.Of(control);
|
||||
if (rovingFocus != null)
|
||||
{
|
||||
Control control2 = rovingFocus.Target(control, keyData);
|
||||
if (control2 != null)
|
||||
{
|
||||
if (control2 != control)
|
||||
{
|
||||
control2.Focus();
|
||||
if (rovingFocus.ArrowChooses(control2) && !control2.IsDisposed)
|
||||
{
|
||||
InvokeOnClick(control2, EventArgs.Empty);
|
||||
}
|
||||
rovingFocus.Refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
private void OnDescendantGotFocus(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is Control focused && KeyboardNavigation.Consume())
|
||||
{
|
||||
ScrollIntoViewForKeyboard(focused);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ScrollIntoViewForKeyboard(Control focused)
|
||||
{
|
||||
if (_bringingIntoView || !IsHandleCreated || focused.IsDisposed || !Contains(focused))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_bringingIntoView = true;
|
||||
try
|
||||
{
|
||||
Control target = ((focused is TextBox && focused.Parent is GlassTextBox glassTextBox) ? glassTextBox : focused);
|
||||
if (target.Parent == null || !target.IsHandleCreated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int margin = ControlInk.FocusRingReach(ControlInk.Dpi(target)) + S(16);
|
||||
Control parent = target.Parent;
|
||||
while (parent != null && parent != this)
|
||||
{
|
||||
if (parent is ScrollableControl { AutoScroll: not false, IsHandleCreated: not false } scrollableControl)
|
||||
{
|
||||
BringInto(scrollableControl, target, margin);
|
||||
}
|
||||
parent = parent.Parent;
|
||||
}
|
||||
int num = ScrollExtent - ClientSize.Height;
|
||||
if (AutoScroll && num > 0)
|
||||
{
|
||||
int before = -AutoScrollPosition.Y;
|
||||
int want = OffsetThatShows(before, RectIn(this, target), ClientSize.Height, margin, num);
|
||||
ScrollTrace.Write(() => $"{GetType().Name} keyboard focus {target.GetType().Name} '{target.Text}' offset {before} -> {want}");
|
||||
if (want != before)
|
||||
{
|
||||
AutoScrollPosition = new Point(-AutoScrollPosition.X, want);
|
||||
RaiseScrollState();
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_bringingIntoView = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void BringInto(ScrollableControl inner, Control target, int margin)
|
||||
{
|
||||
int num = inner.DisplayRectangle.Height - inner.ClientSize.Height;
|
||||
if (num > 0)
|
||||
{
|
||||
int num2 = -inner.AutoScrollPosition.Y;
|
||||
int num3 = OffsetThatShows(num2, RectIn(inner, target), inner.ClientSize.Height, margin, num);
|
||||
if (num3 != num2)
|
||||
{
|
||||
inner.AutoScrollPosition = new Point(-inner.AutoScrollPosition.X, num3);
|
||||
inner.Invalidate(invalidateChildren: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Rectangle RectIn(Control container, Control target)
|
||||
{
|
||||
return container.RectangleToClient(target.Parent.RectangleToScreen(target.Bounds));
|
||||
}
|
||||
|
||||
internal static int OffsetThatShows(int offset, Rectangle box, int viewport, int margin, int max)
|
||||
{
|
||||
int num = box.Top - margin;
|
||||
int num2 = box.Bottom + margin;
|
||||
int value = offset;
|
||||
if (num < 0 || num2 - num > viewport)
|
||||
{
|
||||
value = offset + num;
|
||||
}
|
||||
else if (num2 > viewport)
|
||||
{
|
||||
value = offset + (num2 - viewport);
|
||||
}
|
||||
return Math.Clamp(value, 0, Math.Max(0, max));
|
||||
}
|
||||
|
||||
protected override void OnControlAdded(ControlEventArgs e)
|
||||
{
|
||||
base.OnControlAdded(e);
|
||||
OnDescendantAdded(this, e);
|
||||
}
|
||||
|
||||
private void RaiseScrollState()
|
||||
{
|
||||
HideNativeScrollBars();
|
||||
ScrollStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void ScrollTo(int offset)
|
||||
{
|
||||
ScrollTrace.Write(() => $"{GetType().Name} ScrollTo({offset}) from offset={-AutoScrollPosition.Y}\n" + Environment.StackTrace);
|
||||
AutoScrollPosition = new Point(-AutoScrollPosition.X, Math.Max(0, offset));
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
AddHeaderIfWanted();
|
||||
ApplyDpi(Tokens.Dpi);
|
||||
LayoutHeaderPanel();
|
||||
KeyboardNavigation.EnsureInstalled();
|
||||
HookWheelForwarding(this);
|
||||
RaiseScrollState();
|
||||
ScrollTrace.Write(() => $"{GetType().Name} shown: dpi={DeviceDpi} client={ClientSize.Width}x{ClientSize.Height} min={AutoScrollMinSize.Height} autoScroll={AutoScroll}");
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
int msg = m.Msg;
|
||||
if ((uint)(msg - 276) <= 1u)
|
||||
{
|
||||
Message msg2 = m;
|
||||
ScrollTrace.Write(() => $"{GetType().Name} WM_{((msg2.Msg == 277) ? "V" : "H")}SCROLL wParam=0x{msg2.WParam:X} now offset={-AutoScrollPosition.Y}");
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
msg = m.Msg;
|
||||
if ((msg == 131 || (uint)(msg - 276) <= 1u) ? true : false)
|
||||
{
|
||||
HideNativeScrollBars();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowScrollBar(nint hWnd, int wBar, bool bShow);
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
int before = -AutoScrollPosition.Y;
|
||||
base.OnLayout(e);
|
||||
int after = -AutoScrollPosition.Y;
|
||||
if (before != after)
|
||||
{
|
||||
ScrollTrace.Write(() => $"{GetType().Name} layout moved the page {before} -> {after} (affected={e.AffectedControl?.GetType().Name} '{e.AffectedProperty}')\n" + Environment.StackTrace);
|
||||
}
|
||||
RaiseScrollState();
|
||||
}
|
||||
|
||||
protected override Point ScrollToControl(Control activeControl)
|
||||
{
|
||||
ScrollTrace.Write(() => $"{GetType().Name} ScrollToControl({activeControl?.GetType().Name} '{activeControl?.Text}') declined at offset={-AutoScrollPosition.Y}");
|
||||
return AutoScrollPosition;
|
||||
}
|
||||
|
||||
private int HonestExtentHeight()
|
||||
{
|
||||
int height = AutoScrollMinSize.Height;
|
||||
int num = LowestChildBottom();
|
||||
if (num <= 0)
|
||||
{
|
||||
return height;
|
||||
}
|
||||
return Math.Min(height, num + ScrollBottomPadding);
|
||||
}
|
||||
|
||||
private void AddHeaderIfWanted()
|
||||
{
|
||||
if (!_headerAdded && PageTitle != null)
|
||||
{
|
||||
_headerAdded = true;
|
||||
AddPageHeader(PageTitle, PageSubtitle);
|
||||
}
|
||||
}
|
||||
|
||||
private static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
protected void UseHeaderPanel(Control title, Control subtitle, Control[]? actions = null, Control? toolbar = null)
|
||||
{
|
||||
if (_headerCard == null)
|
||||
{
|
||||
_headerCard = new HeaderPanel
|
||||
{
|
||||
Name = "HeaderPanel",
|
||||
AccessibleRole = AccessibleRole.Grouping
|
||||
};
|
||||
Controls.Add(_headerCard);
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (control != _headerCard)
|
||||
{
|
||||
control.TabIndex++;
|
||||
}
|
||||
}
|
||||
_headerCard.TabIndex = 0;
|
||||
}
|
||||
_headerCard.AccessibleName = title.Text;
|
||||
_headerTitleControl = title;
|
||||
_headerSubtitleControl = subtitle;
|
||||
_headerActions = actions ?? Array.Empty<Control>();
|
||||
_headerToolbar = toolbar;
|
||||
foreach (Control item in new Control[2] { title, subtitle }.Concat(_headerActions).Concat((toolbar == null) ? Array.Empty<Control>() : new Control[1] { toolbar }))
|
||||
{
|
||||
if (item.Parent != _headerCard)
|
||||
{
|
||||
item.Parent?.Controls.Remove(item);
|
||||
_headerCard.Controls.Add(item);
|
||||
}
|
||||
}
|
||||
LayoutHeaderPanel();
|
||||
}
|
||||
|
||||
protected void LayoutHeaderPanel()
|
||||
{
|
||||
if (_headerCard == null || Width <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num = Math.Max(S(200), ContentRight - ContentLeft);
|
||||
int num2 = ControlInk.Hairline(Tokens.Dpi);
|
||||
int num3 = num2 + S(20);
|
||||
int num4 = num2 + S(12);
|
||||
int num5 = S(36);
|
||||
int num6 = S(20);
|
||||
int num7 = num4 + (num5 + S(2) + num6) / 2;
|
||||
int num8 = num - num3;
|
||||
bool flag = false;
|
||||
for (int num9 = _headerActions.Length - 1; num9 >= 0; num9--)
|
||||
{
|
||||
Control control = _headerActions[num9];
|
||||
if (control.Visible)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
num8 -= S(8);
|
||||
}
|
||||
int num10 = InkInset(control);
|
||||
int num11 = Math.Max(0, control.Width - 2 * num10);
|
||||
control.Location = new Point(num8 - num11 - num10, num7 - control.Height / 2);
|
||||
num8 -= num11;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
int num12 = (flag ? (num8 - S(16)) : (num - num3));
|
||||
int num13 = Math.Max(S(40), num12 - num3);
|
||||
Control headerTitleControl = _headerTitleControl;
|
||||
if (headerTitleControl != null)
|
||||
{
|
||||
int num14 = Math.Max(num5, TextRenderer.MeasureText(headerTitleControl.Text, headerTitleControl.Font).Height);
|
||||
int num15 = InkInset(headerTitleControl);
|
||||
headerTitleControl.SetBounds(num3 - num15, num4 - (num14 - num5) / 2, num13 + num15, num14);
|
||||
}
|
||||
_headerSubtitleExtra = 0;
|
||||
Control headerSubtitleControl = _headerSubtitleControl;
|
||||
if (headerSubtitleControl != null)
|
||||
{
|
||||
int num16 = num6;
|
||||
if (headerSubtitleControl.Visible && headerSubtitleControl.Text.Length > 0)
|
||||
{
|
||||
int height = TextRenderer.MeasureText(headerSubtitleControl.Text, headerSubtitleControl.Font, new Size(num13, int.MaxValue), TextFormatFlags.WordBreak).Height;
|
||||
num16 = Math.Max(num6, height);
|
||||
}
|
||||
_headerSubtitleExtra = num16 - num6;
|
||||
int num17 = InkInset(headerSubtitleControl);
|
||||
headerSubtitleControl.SetBounds(num3 - num17, num4 + num5 + S(2), num13 + num17, num16);
|
||||
}
|
||||
if (_headerToolbar != null)
|
||||
{
|
||||
_headerToolbar.SetBounds(num3, num4 + num5 + S(2) + num6 + _headerSubtitleExtra + S(12), num - 2 * num3, S(32));
|
||||
}
|
||||
_headerCard.SetBounds(ContentLeft, S(16) + AutoScrollPosition.Y, num, HeaderPanelHeightPx);
|
||||
}
|
||||
|
||||
private static int InkInset(Control c)
|
||||
{
|
||||
if (!(c is Label label) || string.IsNullOrEmpty(label.Text))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int width = TextRenderer.MeasureText(label.Text, label.Font).Width;
|
||||
int width2 = TextRenderer.MeasureText(label.Text, label.Font, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.NoPadding).Width;
|
||||
return Math.Max(0, (width - width2) / 2);
|
||||
}
|
||||
|
||||
public void ApplyDpi(int dpi)
|
||||
{
|
||||
if (!LaysOutInLogicalPixels || dpi <= 0 || dpi == _scaledForDpi)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float num = (float)dpi / (float)_scaledForDpi;
|
||||
_scaledForDpi = dpi;
|
||||
SuspendLayout();
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
control.Scale(new SizeF(num, num));
|
||||
}
|
||||
if (AutoScrollMinSize.Height > 0)
|
||||
{
|
||||
AutoScrollMinSize = new Size((int)Math.Round((float)AutoScrollMinSize.Width * num), (int)Math.Round((float)AutoScrollMinSize.Height * num));
|
||||
}
|
||||
ResumeLayout(performLayout: true);
|
||||
LayoutHeaderPanel();
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
internal static void PaintHeaderText(Graphics g, string text, Font font, Color ink, Rectangle box)
|
||||
{
|
||||
Color foreColor = Color.FromArgb(150, Theme.IsLight ? Color.White : Color.Black);
|
||||
for (int i = 1; i <= 2; i++)
|
||||
{
|
||||
(int, int)[] array = new (int, int)[8]
|
||||
{
|
||||
(i, 0),
|
||||
(-i, 0),
|
||||
(0, i),
|
||||
(0, -i),
|
||||
(i, i),
|
||||
(-i, -i),
|
||||
(i, -i),
|
||||
(-i, i)
|
||||
};
|
||||
for (int j = 0; j < array.Length; j++)
|
||||
{
|
||||
var (num, num2) = array[j];
|
||||
TextRenderer.DrawText(g, text, font, new Rectangle(box.X + num, box.Y + num2, box.Width, box.Height), foreColor, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
}
|
||||
TextRenderer.DrawText(g, text, font, box, ink, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
|
||||
protected void AddPageHeader(string title, string subtitle)
|
||||
{
|
||||
if (UsesHeaderPanel)
|
||||
{
|
||||
AddPageHeaderPanel(title, subtitle);
|
||||
return;
|
||||
}
|
||||
int num = 86;
|
||||
int num2 = int.MaxValue;
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (control.Visible && control.Left > 0)
|
||||
{
|
||||
num2 = Math.Min(num2, control.Left);
|
||||
}
|
||||
}
|
||||
if (num2 == int.MaxValue)
|
||||
{
|
||||
num2 = 24;
|
||||
}
|
||||
foreach (Control control2 in Controls)
|
||||
{
|
||||
control2.Top += num;
|
||||
}
|
||||
_headerTitle = new HeaderLabel
|
||||
{
|
||||
Text = title,
|
||||
Font = Fonts.Display,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Bounds = new Rectangle(num2, 16, Wide(title, Fonts.Display), 36)
|
||||
};
|
||||
Controls.Add(_headerTitle);
|
||||
_headerSubtitle = new HeaderLabel
|
||||
{
|
||||
Text = subtitle,
|
||||
Font = Fonts.Label,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Bounds = new Rectangle(num2, 56, Wide(subtitle, Fonts.Label), 20),
|
||||
Visible = (subtitle.Length > 0)
|
||||
};
|
||||
Controls.Add(_headerSubtitle);
|
||||
if (AutoScrollMinSize.Height > 0)
|
||||
{
|
||||
AutoScrollMinSize = new Size(AutoScrollMinSize.Width, AutoScrollMinSize.Height + num);
|
||||
}
|
||||
static int Wide(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font).Width + 4;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddPageHeaderPanel(string title, string subtitle)
|
||||
{
|
||||
Control[] headerActions = HeaderActions;
|
||||
Control headerToolbar = HeaderToolbar;
|
||||
HashSet<Control> hashSet = new HashSet<Control>(headerActions);
|
||||
if (headerToolbar != null)
|
||||
{
|
||||
hashSet.Add(headerToolbar);
|
||||
}
|
||||
int num = 116 + ((headerToolbar != null) ? 44 : 0);
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (!hashSet.Contains(control))
|
||||
{
|
||||
control.Top += num;
|
||||
}
|
||||
}
|
||||
Label title2 = new Label
|
||||
{
|
||||
Text = title,
|
||||
Font = Fonts.Display,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
UseMnemonic = false,
|
||||
Name = "PageTitle"
|
||||
};
|
||||
Label subtitle2 = new Label
|
||||
{
|
||||
Text = subtitle,
|
||||
Font = Fonts.Label,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Visible = (subtitle.Length > 0),
|
||||
Name = "PageSubtitle"
|
||||
};
|
||||
UseHeaderPanel(title2, subtitle2, headerActions, headerToolbar);
|
||||
if (AutoScrollMinSize.Height > 0)
|
||||
{
|
||||
AutoScrollMinSize = new Size(AutoScrollMinSize.Width, AutoScrollMinSize.Height + num);
|
||||
}
|
||||
}
|
||||
|
||||
private int LowestChildBottom()
|
||||
{
|
||||
int num = 0;
|
||||
int y = AutoScrollPosition.Y;
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (control.Visible)
|
||||
{
|
||||
num = Math.Max(num, control.Bottom - y);
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
private void HideNativeScrollBars()
|
||||
{
|
||||
if (IsHandleCreated && !IsDisposed)
|
||||
{
|
||||
ShowScrollBar(Handle, 3, bShow: false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void FitScrollToContent(int bottomPadding = 40)
|
||||
{
|
||||
int y = AutoScrollPosition.Y;
|
||||
int num = 0;
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (control.Visible)
|
||||
{
|
||||
num = Math.Max(num, control.Bottom - y);
|
||||
}
|
||||
}
|
||||
if (num > 0)
|
||||
{
|
||||
AutoScrollMinSize = new Size(0, num + bottomPadding);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
CentreContent();
|
||||
LayoutHeaderPanel();
|
||||
}
|
||||
|
||||
protected int AtDesignScale(int logical)
|
||||
{
|
||||
return (int)Math.Round((float)logical * DesignScale);
|
||||
}
|
||||
|
||||
protected void ScaleToCurrentDesign(Control c)
|
||||
{
|
||||
float designScale = DesignScale;
|
||||
if (!(Math.Abs(designScale - 1f) < 0.001f))
|
||||
{
|
||||
c.Scale(new SizeF(designScale, designScale));
|
||||
}
|
||||
}
|
||||
|
||||
private void CentreContent()
|
||||
{
|
||||
if (_contentWidth <= 0 || Width <= 0 || Width == _centredForWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_centredForWidth = Width;
|
||||
float scale = DesignScale;
|
||||
if (_designLeft == null)
|
||||
{
|
||||
_designLeft = Controls.Cast<Control>().ToDictionary((Control c) => c, (Control c) => (int)Math.Round((float)c.Left / scale));
|
||||
}
|
||||
if (_designLeft.Count > Controls.Count)
|
||||
{
|
||||
HashSet<Control> live = new HashSet<Control>(Controls.Cast<Control>());
|
||||
foreach (Control item in _designLeft.Keys.Where((Control k) => !live.Contains(k)).ToList())
|
||||
{
|
||||
_designLeft.Remove(item);
|
||||
}
|
||||
}
|
||||
int num = Math.Max(0, (Width - (int)Math.Round((float)_contentWidth * scale)) / 2);
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
if (control != _headerCard)
|
||||
{
|
||||
if (!_designLeft.TryGetValue(control, out var value))
|
||||
{
|
||||
value = (int)Math.Round((float)(control.Left - CurrentOffset()) / scale);
|
||||
_designLeft[control] = value;
|
||||
}
|
||||
control.Left = (int)Math.Round((float)value * scale) + num;
|
||||
}
|
||||
}
|
||||
_lastOffset = num;
|
||||
}
|
||||
|
||||
private int CurrentOffset()
|
||||
{
|
||||
return _lastOffset;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Theme.Background))
|
||||
{
|
||||
e.Graphics.FillRectangle(brush, ClientRectangle);
|
||||
}
|
||||
Graphics g = e.Graphics;
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
AppBackground.Paint(g, FieldOffset.X, FieldOffset.Y);
|
||||
Field?.Paint(g, FieldOffset.X, FieldOffset.Y);
|
||||
PaintHeaderScrim(g);
|
||||
});
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
private void PaintHeaderScrim(Graphics g)
|
||||
{
|
||||
if (Width <= 0 || _headerCard != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Rectangle rect = new Rectangle(0, 0, Width, 102);
|
||||
if (rect.Height <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int alpha = (SlateSurface.Active ? 215 : 150);
|
||||
using LinearGradientBrush brush = new LinearGradientBrush(rect, Color.FromArgb(alpha, Theme.Background), Color.FromArgb(0, Theme.Background), LinearGradientMode.Vertical);
|
||||
g.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Controls;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
public sealed class LegalPage : GlowPage
|
||||
{
|
||||
internal static readonly (string Title, string Resource)[] Documents = new (string, string)[4]
|
||||
{
|
||||
("Terms of use", "EULA.md"),
|
||||
("Privacy", "PRIVACY.md"),
|
||||
("Licence", "LICENSE.md"),
|
||||
("Third-party notices", "THIRD-PARTY-NOTICES.md")
|
||||
};
|
||||
|
||||
internal const string CouldNotShow = "This document couldn't be shown. A copy is installed next to PlexusX.exe.";
|
||||
|
||||
private const int HeadingLimit = 90;
|
||||
|
||||
private readonly CardPanel _card;
|
||||
|
||||
private readonly Label _caption;
|
||||
|
||||
private readonly GlassDropdown _picker;
|
||||
|
||||
private readonly NotesView _notes;
|
||||
|
||||
private readonly GlassButton _back;
|
||||
|
||||
private bool _laying;
|
||||
|
||||
private bool _built;
|
||||
|
||||
private static readonly Regex Rule = new Regex("^(-{3,}|\\*{3,}|_{3,})$", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex TableSeparator = new Regex("^\\|?[\\s:|\\-]+\\|?$", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex Numbered = new Regex("^\\d+[.)]\\s+", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex Link = new Regex("\\[([^\\]]+)\\]\\(([^)\\s]+)\\)", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex Italic = new Regex("(?<![\\*\\w])\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*(?![\\*\\w])", RegexOptions.Compiled);
|
||||
|
||||
protected override string? PageTitle => "Legal & licences";
|
||||
|
||||
protected override string PageSubtitle => "The terms of use, the privacy policy and the licences of the parts PlexusX uses.";
|
||||
|
||||
protected override bool UsesHeaderPanel => true;
|
||||
|
||||
protected override Control[] HeaderActions => new Control[1] { _back };
|
||||
|
||||
protected override bool LaysOutInLogicalPixels => false;
|
||||
|
||||
private static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
public LegalPage(Action? onBack = null)
|
||||
{
|
||||
LegalPage legalPage = this;
|
||||
AutoScroll = false;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
TabStop = false;
|
||||
_back = new GlassButton
|
||||
{
|
||||
Text = "Back",
|
||||
Kind = GlassButtonKind.Secondary
|
||||
};
|
||||
_back.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
onBack?.Invoke();
|
||||
};
|
||||
SizeBack();
|
||||
_card = new CardPanel
|
||||
{
|
||||
Name = "LegalCard"
|
||||
};
|
||||
_caption = UiHelpers.Caption("Document", 0, 0, 100);
|
||||
_caption.UseMnemonic = false;
|
||||
_card.Controls.Add(_caption);
|
||||
_picker = new GlassDropdown
|
||||
{
|
||||
AccessibleName = "Document"
|
||||
};
|
||||
_picker.SetItems(Documents.Select(((string Title, string Resource) d) => d.Title));
|
||||
_card.Controls.Add(_picker);
|
||||
_notes = new NotesView
|
||||
{
|
||||
OnCard = true,
|
||||
HeadingLimit = 90,
|
||||
AccessibleName = "Document text",
|
||||
AccessibleRole = AccessibleRole.Document
|
||||
};
|
||||
_notes.MouseDown += (object? _, MouseEventArgs _) =>
|
||||
{
|
||||
if (!legalPage.ContainsFocus)
|
||||
{
|
||||
legalPage.Focus();
|
||||
}
|
||||
};
|
||||
_card.Controls.Add(_notes);
|
||||
_picker.SelectedIndexChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
legalPage.Show(legalPage._picker.SelectedIndex);
|
||||
};
|
||||
Controls.Add(_card);
|
||||
Show(0);
|
||||
_built = true;
|
||||
}
|
||||
|
||||
private void SizeBack()
|
||||
{
|
||||
int height = S(32);
|
||||
_back.Height = height;
|
||||
_back.Width = Math.Max(S(64), _back.GetPreferredSize(Size.Empty).Width);
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
LayoutContent();
|
||||
BeginInvoke(() =>
|
||||
{
|
||||
if (!IsDisposed && Visible && !ContainsFocus)
|
||||
{
|
||||
Focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
base.OnLayout(e);
|
||||
LayoutContent();
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
LayoutContent();
|
||||
}
|
||||
|
||||
private void LayoutContent()
|
||||
{
|
||||
if (!_built || _laying || IsDisposed || ClientSize.Width <= 0 || ClientSize.Height <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_laying = true;
|
||||
try
|
||||
{
|
||||
int num = _back.Width * 4096 + _back.Height;
|
||||
SizeBack();
|
||||
if (HasHeaderPanel && num != _back.Width * 4096 + _back.Height)
|
||||
{
|
||||
LayoutHeaderPanel();
|
||||
}
|
||||
int contentLeft = GlowPage.ContentLeft;
|
||||
int contentTop = ContentTop;
|
||||
int num2 = ClientSize.Height + 1 - S(16);
|
||||
int num3 = Math.Max(S(240), ContentRight - GlowPage.ContentLeft);
|
||||
int num4 = Math.Max(S(120), num2 - contentTop);
|
||||
_card.SetBounds(contentLeft, contentTop, num3, num4);
|
||||
int num5 = S(20);
|
||||
int num6 = S(16);
|
||||
int num7 = Math.Max(S(120), num3 - 2 * num5);
|
||||
int num8 = Fonts.LineHeight(FontRole.CaptionBold);
|
||||
_caption.SetBounds(num5, num6, num7, num8);
|
||||
int num9 = num6 + num8 + S(8);
|
||||
_picker.SetBounds(num5, num9, Math.Min(S(280), num7), S(32));
|
||||
int num10 = num9 + S(32) + S(16);
|
||||
_notes.SetBounds(num5, num10, num7, Math.Max(S(40), num4 - num10 - num6));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_laying = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Show(int index)
|
||||
{
|
||||
if (index < 0 || index >= Documents.Length)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
_notes.NotesText = LoadDocument(Documents[index].Resource);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
if (!(e is HandledMouseEventArgs { Handled: not false }))
|
||||
{
|
||||
_notes.Wheel(e.Delta);
|
||||
if (e is HandledMouseEventArgs e3)
|
||||
{
|
||||
e3.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
{
|
||||
Control control = ActiveControl;
|
||||
while (control is ContainerControl containerControl)
|
||||
{
|
||||
Control activeControl = containerControl.ActiveControl;
|
||||
if (activeControl == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
control = activeControl;
|
||||
}
|
||||
if (ScrollKey(keyData, control))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return base.ProcessCmdKey(ref msg, keyData);
|
||||
}
|
||||
|
||||
private bool ScrollKey(Keys keyData, Control? focused)
|
||||
{
|
||||
if ((keyData & Keys.Modifiers) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag;
|
||||
switch (keyData)
|
||||
{
|
||||
case Keys.End:
|
||||
case Keys.Home:
|
||||
case Keys.Up:
|
||||
case Keys.Down:
|
||||
flag = true;
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
if (flag && focused is GlassDropdown)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _notes.ScrollByKey(keyData);
|
||||
}
|
||||
|
||||
internal bool PressKeyForTest(Keys key, Control? focused = null)
|
||||
{
|
||||
return ScrollKey(key, focused);
|
||||
}
|
||||
|
||||
internal static string LoadDocument(string resource)
|
||||
{
|
||||
return LoadDocument(resource, (string name) => Assembly.GetExecutingAssembly().GetManifestResourceStream(name));
|
||||
}
|
||||
|
||||
internal static string LoadDocument(string resource, Func<string, Stream?> open)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Stream stream = open(resource);
|
||||
if (stream == null)
|
||||
{
|
||||
return "This document couldn't be shown. A copy is installed next to PlexusX.exe.";
|
||||
}
|
||||
using StreamReader streamReader = new StreamReader(stream);
|
||||
return Normalise(streamReader.ReadToEnd());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
CrashLog.Write(ex);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return "This document couldn't be shown. A copy is installed next to PlexusX.exe.";
|
||||
}
|
||||
}
|
||||
|
||||
internal static string Normalise(string markdown)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
string[] array = markdown.Replace("\r\n", "\n").Split('\n');
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
string text = array[i].Trim();
|
||||
if (text.StartsWith("```"))
|
||||
{
|
||||
flag = !flag;
|
||||
Blank();
|
||||
continue;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (text.Length > 0)
|
||||
{
|
||||
lines.Add(text);
|
||||
lines.Add("");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
bool flag3 = text.StartsWith("|");
|
||||
if (flag2 && !flag3)
|
||||
{
|
||||
Blank();
|
||||
flag2 = false;
|
||||
}
|
||||
if (text.Length == 0)
|
||||
{
|
||||
Blank();
|
||||
}
|
||||
else if (Rule.IsMatch(text))
|
||||
{
|
||||
Blank();
|
||||
}
|
||||
else if (text.StartsWith("#"))
|
||||
{
|
||||
Blank();
|
||||
lines.Add(Inline(text.TrimStart('#').Trim()));
|
||||
lines.Add("");
|
||||
}
|
||||
else if (flag3)
|
||||
{
|
||||
flag2 = true;
|
||||
if (!TableSeparator.IsMatch(text))
|
||||
{
|
||||
IEnumerable<string> values = from c in text.Trim('|').Split('|')
|
||||
select Inline(c.Trim()) into c
|
||||
where c.Length > 0
|
||||
select c;
|
||||
lines.Add("• " + string.Join(" — ", values));
|
||||
}
|
||||
}
|
||||
else if (text.StartsWith("> ") || text == ">")
|
||||
{
|
||||
lines.Add(Inline(text.TrimStart('>').Trim()));
|
||||
}
|
||||
else if ((text[0] == '-' || text[0] == '*' || text[0] == '+') && text.Length > 1 && char.IsWhiteSpace(text[1]))
|
||||
{
|
||||
lines.Add("• " + Inline(text.Substring(1).Trim()));
|
||||
}
|
||||
else if (Numbered.IsMatch(text))
|
||||
{
|
||||
Blank();
|
||||
lines.Add(Inline(text));
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.Add(Inline(text));
|
||||
}
|
||||
}
|
||||
return string.Join("\n", lines).Trim('\n');
|
||||
void Blank()
|
||||
{
|
||||
if (lines.Count > 0)
|
||||
{
|
||||
List<string> list = lines;
|
||||
if (list[list.Count - 1].Length != 0)
|
||||
{
|
||||
lines.Add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string Inline(string s)
|
||||
{
|
||||
s = Link.Replace(s, (Match m) => (!(m.Groups[1].Value == m.Groups[2].Value)) ? (m.Groups[1].Value + " (" + m.Groups[2].Value + ")") : m.Groups[1].Value);
|
||||
s = s.Replace("**", "").Replace("`", "");
|
||||
s = Italic.Replace(s, "$1");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,513 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Controls;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Games;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
public sealed class ProfilesPage : GlowPage
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
private readonly SettingsStore _store;
|
||||
|
||||
private readonly GameSelection _selection;
|
||||
|
||||
private readonly IVibranceEngine _engine;
|
||||
|
||||
private readonly Action<DisplayPreset>? _applyLook;
|
||||
|
||||
private readonly Func<string?> _runningGameId;
|
||||
|
||||
private readonly Func<string, GameProfile?> _gameProfileLookup;
|
||||
|
||||
private readonly Action<GameProfile> _gameProfileSave;
|
||||
|
||||
private readonly Func<IReadOnlyList<GameProfile>> _gameProfileLoadAll;
|
||||
|
||||
private readonly Action<string> _gameProfileRemove;
|
||||
|
||||
private readonly Label _title;
|
||||
|
||||
private readonly Label _subtitle;
|
||||
|
||||
private CardPanel? _offerCard;
|
||||
|
||||
private Label? _offerLine;
|
||||
|
||||
private GlassButton? _offerYes;
|
||||
|
||||
private GlassButton? _offerNo;
|
||||
|
||||
private CardPanel? _pickCard;
|
||||
|
||||
private Label? _pickTitle;
|
||||
|
||||
private Label? _pickHint;
|
||||
|
||||
private GameChooser? _picker;
|
||||
|
||||
private CardPanel? _profileCard;
|
||||
|
||||
private CardPanel? _listCard;
|
||||
|
||||
private GameProfileManagerSection? _manager;
|
||||
|
||||
private int _cardW;
|
||||
|
||||
private bool _built;
|
||||
|
||||
private readonly EventHandler _onSelectionChanged;
|
||||
|
||||
protected override bool LaysOutInLogicalPixels => false;
|
||||
|
||||
private static int CardPad => S(20);
|
||||
|
||||
private static int CardGap => S(16);
|
||||
|
||||
private static int RowTopPad => S(8);
|
||||
|
||||
private static int RowBottomPad => S(6);
|
||||
|
||||
private static int TitleToNote => S(2);
|
||||
|
||||
private static int PickerW => S(260);
|
||||
|
||||
private static int PickerH => S(32);
|
||||
|
||||
internal GameProfileManagerSection ProfileManagerForTest => _manager ?? throw new InvalidOperationException("no list built");
|
||||
|
||||
internal int RefreshesForTest { get; private set; }
|
||||
|
||||
private static int TitleHeight => Math.Max(Fonts.LineHeight(FontRole.BodyBold), TextRenderer.MeasureText("Ag", Fonts.BodyBold).Height);
|
||||
|
||||
private static int NoteLineHeight => Math.Max(Fonts.LineHeight(FontRole.Caption), TextRenderer.MeasureText("Ag", Fonts.Caption).Height);
|
||||
|
||||
private static int S(int px)
|
||||
{
|
||||
return Tokens.Scale(px);
|
||||
}
|
||||
|
||||
public ProfilesPage(AppSettings settings, SettingsStore store, GameSelection selection, IVibranceEngine engine, Action<DisplayPreset>? applyLook = null, Func<string?>? runningGameId = null, Func<string, GameProfile?>? gameProfileLookup = null, Action<GameProfile>? gameProfileSave = null, Func<IReadOnlyList<GameProfile>>? gameProfileLoadAll = null, Action<string>? gameProfileRemove = null)
|
||||
{
|
||||
_settings = settings;
|
||||
_store = store;
|
||||
_selection = selection;
|
||||
_engine = engine;
|
||||
_applyLook = applyLook;
|
||||
_runningGameId = runningGameId ?? (() => SupportedGames.CurrentlyRunning()?.Id);
|
||||
_gameProfileLookup = gameProfileLookup ?? new Func<string, GameProfile?>(GameProfileStore.Get);
|
||||
_gameProfileSave = gameProfileSave ?? new Action<GameProfile>(GameProfileStore.Set);
|
||||
_gameProfileLoadAll = gameProfileLoadAll ?? new Func<IReadOnlyList<GameProfile>>(GameProfileStore.Load);
|
||||
_gameProfileRemove = gameProfileRemove ?? new Action<string>(GameProfileStore.Remove);
|
||||
AutoScroll = true;
|
||||
Font = Fonts.Body;
|
||||
_title = PageLabel("Profiles", Fonts.Display, Theme.Text);
|
||||
_subtitle = PageLabel("A look for each game — saved here, applied when it opens, put back when it closes.", Fonts.Label, Theme.TextDim);
|
||||
BuildSections();
|
||||
_onSelectionChanged = (object? _, EventArgs _) =>
|
||||
{
|
||||
RefreshProfileCard();
|
||||
LayoutContent();
|
||||
};
|
||||
_selection.Changed += _onSelectionChanged;
|
||||
Resize += (object? _, EventArgs _) =>
|
||||
{
|
||||
LayoutContent();
|
||||
};
|
||||
ParentChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (Parent != null)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
};
|
||||
_subtitle.TextAlign = ContentAlignment.TopLeft;
|
||||
UseHeaderPanel(_title, _subtitle);
|
||||
_built = true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_selection.Changed -= _onSelectionChanged;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void BuildSections()
|
||||
{
|
||||
_offerCard = new CardPanel
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
Controls.Add(_offerCard);
|
||||
_offerLine = new Label
|
||||
{
|
||||
Text = "",
|
||||
Font = Fonts.Body,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = true,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false
|
||||
};
|
||||
_offerCard.Controls.Add(_offerLine);
|
||||
_offerYes = new GlassButton
|
||||
{
|
||||
Text = "Yes, set it up",
|
||||
Kind = GlassButtonKind.Primary
|
||||
};
|
||||
_offerYes.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
AcceptSetupOffer();
|
||||
};
|
||||
_offerCard.Controls.Add(_offerYes);
|
||||
_offerNo = new GlassButton
|
||||
{
|
||||
Text = "No thanks",
|
||||
Kind = GlassButtonKind.Secondary
|
||||
};
|
||||
_offerNo.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
DeclineSetupOffer();
|
||||
};
|
||||
_offerCard.Controls.Add(_offerNo);
|
||||
_pickCard = new CardPanel();
|
||||
_pickTitle = RowTitle(_pickCard, "Pick a game");
|
||||
_picker = new GameChooser(_selection);
|
||||
_pickCard.Controls.Add(_picker);
|
||||
_pickHint = RowNote(_pickCard, "Choose a game to give it its own colours.");
|
||||
Controls.Add(_pickCard);
|
||||
_listCard = new CardPanel();
|
||||
Controls.Add(_listCard);
|
||||
_manager = new GameProfileManagerSection(_listCard, Fonts.BodyBold, Fonts.Caption, _gameProfileLoadAll, _gameProfileSave, _gameProfileRemove, (string id) => !string.IsNullOrEmpty(id) && _runningGameId() == id, () =>
|
||||
{
|
||||
string text = _runningGameId();
|
||||
return (text != null) ? SupportedGames.ById(text)?.DisplayName : null;
|
||||
}, SaveCurrentLookForRunningGame);
|
||||
Retitle(_listCard, "SAVED GAME PROFILES", "Saved game profiles");
|
||||
_manager.Changed += () =>
|
||||
{
|
||||
if (_built)
|
||||
{
|
||||
LayoutContent();
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
};
|
||||
RefreshProfileCard();
|
||||
}
|
||||
|
||||
private static void Retitle(Control card, string oldText, string newText)
|
||||
{
|
||||
string value = oldText.Replace(" ", "");
|
||||
foreach (Label item in card.Controls.OfType<Label>())
|
||||
{
|
||||
if ((item.Text ?? "").Replace(" ", "").Equals(value, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.Text = newText;
|
||||
item.Font = Fonts.BodyBold;
|
||||
item.ForeColor = Theme.Text;
|
||||
item.UseMnemonic = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshProfileCard()
|
||||
{
|
||||
if (_listCard == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_profileCard != null)
|
||||
{
|
||||
Controls.Remove(_profileCard);
|
||||
_profileCard.Dispose();
|
||||
_profileCard = null;
|
||||
}
|
||||
SupportedGame current = _selection.Current;
|
||||
if (!(current == null))
|
||||
{
|
||||
_profileCard = GameProfileSection.BuildCard(current.Id, current.DisplayName, _engine, 0, 0, (_cardW > 0) ? _cardW : S(700), _settings, _gameProfileLookup, _gameProfileSave, _gameProfileRemove, () =>
|
||||
{
|
||||
_manager?.Refresh();
|
||||
});
|
||||
Retitle(_profileCard, "PROFILE", "Profile");
|
||||
Controls.Add(_profileCard);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshSetupOffer()
|
||||
{
|
||||
if (_offerCard != null && _offerLine != null)
|
||||
{
|
||||
string text = _settings.PendingGameOfferId ?? "";
|
||||
bool flag = text.Length > 0 && GameLookJoin.LookGameFor(text) != null;
|
||||
if (flag)
|
||||
{
|
||||
_offerLine.Text = GameSetupOffer.Sentence(text);
|
||||
}
|
||||
_offerCard.Visible = flag;
|
||||
LayoutContent();
|
||||
}
|
||||
}
|
||||
|
||||
private void AcceptSetupOffer()
|
||||
{
|
||||
string text = _settings.PendingGameOfferId ?? "";
|
||||
DisplayPreset displayPreset = GameLookJoin.StartingLookFor(text);
|
||||
if (displayPreset == null)
|
||||
{
|
||||
ClearSetupOffer();
|
||||
return;
|
||||
}
|
||||
_applyLook?.Invoke(displayPreset);
|
||||
string gameName = GameLookJoin.LookGameFor(text) ?? text;
|
||||
_gameProfileSave(GameProfileSection.CaptureFromPreset(text, gameName, displayPreset, _gameProfileLookup(text)));
|
||||
new GameProfileApplyGate(_settings).UserOptedBackIn();
|
||||
ClearSetupOffer();
|
||||
_manager?.Refresh();
|
||||
RefreshProfileCard();
|
||||
LayoutContent();
|
||||
}
|
||||
|
||||
private void DeclineSetupOffer()
|
||||
{
|
||||
string text = _settings.PendingGameOfferId ?? "";
|
||||
if (text.Length > 0 && !_settings.DeclinedGameOffers.Contains(text, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
_settings.DeclinedGameOffers.Add(text);
|
||||
}
|
||||
ClearSetupOffer();
|
||||
}
|
||||
|
||||
private void ClearSetupOffer()
|
||||
{
|
||||
_settings.PendingGameOfferId = "";
|
||||
_store.Save(_settings);
|
||||
RefreshSetupOffer();
|
||||
}
|
||||
|
||||
private void SaveCurrentLookForRunningGame()
|
||||
{
|
||||
string text = _runningGameId();
|
||||
if (text != null)
|
||||
{
|
||||
SupportedGame supportedGame = SupportedGames.ById(text);
|
||||
if (!(supportedGame == null))
|
||||
{
|
||||
_gameProfileSave(GameProfileSection.Capture(text, supportedGame.DisplayName, _engine, _gameProfileLookup(text)));
|
||||
new GameProfileApplyGate(_settings).UserOptedBackIn();
|
||||
RefreshProfileCard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new void Refresh()
|
||||
{
|
||||
RefreshesForTest++;
|
||||
if (_built)
|
||||
{
|
||||
_manager?.Refresh();
|
||||
if (_listCard != null)
|
||||
{
|
||||
Retitle(_listCard, "SAVED GAME PROFILES", "Saved game profiles");
|
||||
}
|
||||
RefreshProfileCard();
|
||||
RefreshSetupOffer();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnVisibleChanged(EventArgs e)
|
||||
{
|
||||
base.OnVisibleChanged(e);
|
||||
if (Visible)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
LayoutContent();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private Label PageLabel(string text, Font font, Color colour)
|
||||
{
|
||||
Label label = new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = font,
|
||||
ForeColor = colour,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
UseMnemonic = false
|
||||
};
|
||||
Controls.Add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
private static Label RowTitle(Control card, string text)
|
||||
{
|
||||
Label label = new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = Fonts.BodyBold,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
UseMnemonic = false
|
||||
};
|
||||
card.Controls.Add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
private static Label RowNote(Control card, string text)
|
||||
{
|
||||
Label label = new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = Fonts.Caption,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = true,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false
|
||||
};
|
||||
card.Controls.Add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
private static int WidthOf(Label l)
|
||||
{
|
||||
return TextRenderer.MeasureText(l.Text ?? "", l.Font).Width + S(4);
|
||||
}
|
||||
|
||||
private static int PlaceNote(Label note, int x, int y, int width)
|
||||
{
|
||||
note.MaximumSize = new Size(Math.Max(1, width), 0);
|
||||
note.Location = new Point(x, y);
|
||||
return Math.Max(NoteLineHeight, note.Height);
|
||||
}
|
||||
|
||||
private void LayoutContent()
|
||||
{
|
||||
if (!_built || Width <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num = ContentRight - GlowPage.ContentLeft;
|
||||
if (num <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num2 = Math.Clamp(num, S(520), S(980));
|
||||
int num3 = GlowPage.ContentLeft + Math.Max(0, (num - num2) / 2);
|
||||
int num4 = num2 - 2 * CardPad;
|
||||
int y = AutoScrollPosition.Y;
|
||||
int num5 = ContentTop + y;
|
||||
if (_pickCard != null && _listCard != null && _manager != null && _offerCard != null && _offerLine != null && _offerYes != null && _offerNo != null && _pickTitle != null && _picker != null && _pickHint != null)
|
||||
{
|
||||
bool flag = _cardW != num2;
|
||||
_cardW = num2;
|
||||
int num6 = LayoutOfferCard(num3, num5, num2, num4);
|
||||
if (_offerCard.Visible)
|
||||
{
|
||||
num5 += num6 + CardGap;
|
||||
}
|
||||
_picker.Size = new Size(PickerW, PickerH);
|
||||
int num7 = ControlRow(_pickTitle, _pickHint, new Control[1] { _picker }, 0, num4) + RowBottomPad;
|
||||
_pickCard.SetBounds(num3, num5, num2, num7);
|
||||
num5 += num7 + CardGap;
|
||||
if ((_profileCard != null) & flag)
|
||||
{
|
||||
RefreshProfileCard();
|
||||
}
|
||||
if (_profileCard != null)
|
||||
{
|
||||
_profileCard.Location = new Point(num3, num5);
|
||||
num5 += _profileCard.Height + CardGap;
|
||||
}
|
||||
int num8 = _manager.PreferredHeight + 2 * CardPad;
|
||||
_listCard.SetBounds(num3, num5, num2, num8);
|
||||
_manager.Place(CardPad, CardPad, num4);
|
||||
num5 += num8;
|
||||
}
|
||||
AutoScrollMinSize = new Size(0, num5 - y + S(40));
|
||||
}
|
||||
|
||||
private int LayoutOfferCard(int left, int y, int cardW, int innerW)
|
||||
{
|
||||
int num = 32;
|
||||
int num2 = ((num > 0) ? S(num) : S(32));
|
||||
_offerYes.Size = new Size(S(140), num2);
|
||||
_offerNo.Size = new Size(S(110), num2);
|
||||
int num3 = S(8);
|
||||
int num4 = _offerYes.Width + num3 + _offerNo.Width;
|
||||
bool flag = innerW - num4 - S(16) >= S(180);
|
||||
int num5 = PlaceNote(width: flag ? (innerW - num4 - S(16)) : innerW, note: _offerLine, x: CardPad, y: RowTopPad);
|
||||
int num6;
|
||||
if (flag)
|
||||
{
|
||||
num6 = Math.Max(RowTopPad + num5 + RowBottomPad, RowTopPad + num2 + RowBottomPad);
|
||||
_offerYes.Location = new Point(CardPad + innerW - num4, (num6 - num2) / 2);
|
||||
_offerNo.Location = new Point(_offerYes.Right + num3, _offerYes.Top);
|
||||
}
|
||||
else
|
||||
{
|
||||
int num7 = RowTopPad + num5 + S(10);
|
||||
_offerYes.Location = new Point(CardPad, num7);
|
||||
_offerNo.Location = new Point(_offerYes.Right + num3, num7);
|
||||
num6 = num7 + num2 + RowBottomPad;
|
||||
}
|
||||
_offerCard.SetBounds(left, y, cardW, num6);
|
||||
return num6;
|
||||
}
|
||||
|
||||
private int ControlRow(Label title, Label? note, Control[] controls, int cy, int inner)
|
||||
{
|
||||
int num = S(8);
|
||||
int num2 = controls.Sum((Control control3) => control3.Width) + num * (controls.Length - 1);
|
||||
int num3 = controls.Max((Control control3) => control3.Height);
|
||||
bool flag = inner - num2 - S(16) >= WidthOf(title);
|
||||
int width = Math.Max(S(40), flag ? (inner - num2 - S(16)) : inner);
|
||||
int num4 = RowTopPad + TitleHeight;
|
||||
title.SetBounds(CardPad, cy + RowTopPad, width, TitleHeight);
|
||||
if (note != null)
|
||||
{
|
||||
num4 += TitleToNote + PlaceNote(note, CardPad, cy + num4 + TitleToNote, width);
|
||||
}
|
||||
Control[] array;
|
||||
if (flag)
|
||||
{
|
||||
int num5 = Math.Max(num4 + RowBottomPad, RowTopPad + num3 + RowBottomPad);
|
||||
int num6 = CardPad + inner - num2;
|
||||
array = controls;
|
||||
foreach (Control control in array)
|
||||
{
|
||||
control.Location = new Point(num6, cy + (num5 - control.Height) / 2);
|
||||
num6 += control.Width + num;
|
||||
}
|
||||
return cy + num5;
|
||||
}
|
||||
int num8 = cy + num4 + S(10);
|
||||
int num9 = CardPad;
|
||||
array = controls;
|
||||
foreach (Control control2 in array)
|
||||
{
|
||||
control2.Location = new Point(num9, num8);
|
||||
num9 += control2.Width + num;
|
||||
}
|
||||
return num8 + num3 + RowBottomPad;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,702 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal sealed class SceneTile : Control
|
||||
{
|
||||
private sealed class TileAccessible : ControlAccessibleObject
|
||||
{
|
||||
private readonly SceneTile _tile;
|
||||
|
||||
public override AccessibleRole Role => AccessibleRole.RadioButton;
|
||||
|
||||
public override AccessibleStates State => (AccessibleStates)((int)base.State | (_tile.Active ? 16 : 0));
|
||||
|
||||
public override string DefaultAction => "Select";
|
||||
|
||||
internal TileAccessible(SceneTile tile)
|
||||
: base(tile)
|
||||
{
|
||||
_tile = tile;
|
||||
}
|
||||
|
||||
public override void DoDefaultAction()
|
||||
{
|
||||
_tile.InvokeOnClick(_tile, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private const int PhotoPx = 30;
|
||||
|
||||
private const float NameStartPt = 9f;
|
||||
|
||||
private const float NameFloorPt = 7.5f;
|
||||
|
||||
private const float NameStepPt = 0.25f;
|
||||
|
||||
private const float PillPt = 7f;
|
||||
|
||||
private const float ChipPt = 7f;
|
||||
|
||||
private const float NominalPt = 9f;
|
||||
|
||||
private static readonly Dictionary<(string, float, FontStyle), Font> ScaledFonts = new Dictionary<(string, float, FontStyle), Font>();
|
||||
|
||||
private const TextFormatFlags Measure = TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding;
|
||||
|
||||
private static readonly int[] StripRgb = new int[6] { 16726832, 16749824, 16766474, 3458905, 2001151, 15902074 };
|
||||
|
||||
internal const int StripSegments = 6;
|
||||
|
||||
private const int ActiveDotRgb = 6213251;
|
||||
|
||||
private Image? _photo;
|
||||
|
||||
private float[]? _matrix;
|
||||
|
||||
private bool _lookOnPhoto;
|
||||
|
||||
private bool _active;
|
||||
|
||||
private bool _hover;
|
||||
|
||||
private int _reading;
|
||||
|
||||
private string? _boundHotkey;
|
||||
|
||||
private Bitmap? _thumb;
|
||||
|
||||
private Size _thumbFor;
|
||||
|
||||
private Font? _nameFont;
|
||||
|
||||
private bool _nameCut;
|
||||
|
||||
private (string Text, int Width, Font Basis)? _nameFitFor;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
internal static int PictureHeight => Tokens.Scale(30);
|
||||
|
||||
private static int Pad => Tokens.Scale(6);
|
||||
|
||||
private static int CardRadius => Tokens.Scale(8);
|
||||
|
||||
private static int PhotoRadius => Tokens.Scale(4);
|
||||
|
||||
private static int StripGap => Tokens.Scale(4);
|
||||
|
||||
private static int StripHeight => Tokens.Scale(5);
|
||||
|
||||
private static int SegmentGap => Tokens.Scale(2);
|
||||
|
||||
private static int NameGap => Tokens.Scale(5);
|
||||
|
||||
private static int NameLine => Tokens.Scale(14);
|
||||
|
||||
private static int PillGap => Tokens.Scale(4);
|
||||
|
||||
private static int PillHeight => Tokens.Scale(14);
|
||||
|
||||
private static int ChipHeight => Tokens.Scale(13);
|
||||
|
||||
internal static int BoxHeight => Pad + PictureHeight + StripGap + StripHeight + NameGap + NameLine + PillGap + PillHeight + Pad;
|
||||
|
||||
internal static int ControlHeight => BoxHeight;
|
||||
|
||||
public string Caption
|
||||
{
|
||||
get
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
Text = value;
|
||||
Rename();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public string Subtitle { get; set; } = "";
|
||||
|
||||
public string Kind { get; set; } = "";
|
||||
|
||||
public int Reading
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reading;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reading = value;
|
||||
Rename();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public Image? Photo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _photo;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_photo != value)
|
||||
{
|
||||
_photo = value;
|
||||
DropThumb();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowsTheLookOnThePhoto
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lookOnPhoto;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_lookOnPhoto != value)
|
||||
{
|
||||
_lookOnPhoto = value;
|
||||
DropThumb();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float[]? Matrix
|
||||
{
|
||||
get
|
||||
{
|
||||
return _matrix;
|
||||
}
|
||||
set
|
||||
{
|
||||
_matrix = value;
|
||||
DropThumb();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Deletable { get; set; }
|
||||
|
||||
public bool Bindable { get; set; }
|
||||
|
||||
public string? BoundHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _boundHotkey;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(_boundHotkey == value))
|
||||
{
|
||||
_boundHotkey = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle PhotoRect => new Rectangle(Pad, Pad, Math.Max(1, Width - 2 * Pad), PictureHeight);
|
||||
|
||||
internal Rectangle TestBox => PhotoRect;
|
||||
|
||||
private Rectangle StripRect => new Rectangle(PhotoRect.X, PhotoRect.Bottom + StripGap, PhotoRect.Width, StripHeight);
|
||||
|
||||
internal Rectangle TestStrip => StripRect;
|
||||
|
||||
private Rectangle NameRect => new Rectangle(Pad, StripRect.Bottom + NameGap, Math.Max(1, Width - 2 * Pad), NameLine);
|
||||
|
||||
internal bool TestShowsActiveChip => _active;
|
||||
|
||||
internal bool TestShowsHotkeyChip => !string.IsNullOrEmpty(_boundHotkey);
|
||||
|
||||
internal float TestNamePoints
|
||||
{
|
||||
get
|
||||
{
|
||||
FitName();
|
||||
return _nameFont.SizeInPoints / Fonts.CaptionBold.SizeInPoints * 9f;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool TestNameIsCut
|
||||
{
|
||||
get
|
||||
{
|
||||
FitName();
|
||||
return _nameCut;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? DeleteRequested;
|
||||
|
||||
public event EventHandler? BindRequested;
|
||||
|
||||
private static Font House(Font basis, float pt, FontStyle? style = null)
|
||||
{
|
||||
float num = basis.SizeInPoints * pt / 9f;
|
||||
(string, float, FontStyle) key = (basis.FontFamily.Name, num, style ?? basis.Style);
|
||||
lock (ScaledFonts)
|
||||
{
|
||||
if (!ScaledFonts.TryGetValue(key, out Font value))
|
||||
{
|
||||
value = (ScaledFonts[key] = new Font(basis.FontFamily, num, style ?? basis.Style, GraphicsUnit.Point));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static int TextWidth(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font, new Size(1073741823, 1073741823), TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding).Width;
|
||||
}
|
||||
|
||||
internal static Color[] StripColours(float[]? m)
|
||||
{
|
||||
Color[] array = new Color[StripRgb.Length];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
Color color = Color.FromArgb(StripRgb[i]);
|
||||
float r = (float)(int)color.R / 255f;
|
||||
float g = (float)(int)color.G / 255f;
|
||||
float b = (float)(int)color.B / 255f;
|
||||
if (m != null && m.Length >= 25)
|
||||
{
|
||||
float num = Out(0);
|
||||
float num2 = Out(1);
|
||||
float num3 = Out(2);
|
||||
r = num;
|
||||
g = num2;
|
||||
b = num3;
|
||||
}
|
||||
array[i] = Color.FromArgb(255, (int)Math.Round(r * 255f), (int)Math.Round(g * 255f), (int)Math.Round(b * 255f));
|
||||
float Out(int c)
|
||||
{
|
||||
return Math.Clamp(r * m[c] + g * m[5 + c] + b * m[10 + c] + m[20 + c], 0f, 1f);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public SceneTile()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
SetStyle(ControlStyles.StandardClick, value: false);
|
||||
_ring = new OutsideFocusRing(this, () => CardRadius);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
AccessibleRole = AccessibleRole.RadioButton;
|
||||
}
|
||||
|
||||
private void Rename()
|
||||
{
|
||||
AccessibleName = string.Format(CultureInfo.InvariantCulture, "{0}, {1} percent", Text, _reading);
|
||||
}
|
||||
|
||||
internal RectangleF TestSegment(int i)
|
||||
{
|
||||
return Segment(StripRect, i);
|
||||
}
|
||||
|
||||
private static RectangleF Segment(Rectangle strip, int i)
|
||||
{
|
||||
float num = (float)(strip.Width - 5 * SegmentGap) / 6f;
|
||||
return new RectangleF((float)strip.X + (float)i * (num + (float)SegmentGap), strip.Y, num, strip.Height);
|
||||
}
|
||||
|
||||
private void FitName()
|
||||
{
|
||||
Font captionBold = Fonts.CaptionBold;
|
||||
int width = NameRect.Width;
|
||||
(string, int, Font)? nameFitFor = _nameFitFor;
|
||||
if (nameFitFor.HasValue)
|
||||
{
|
||||
(string, int, Font) valueOrDefault = nameFitFor.GetValueOrDefault();
|
||||
if (valueOrDefault.Item1 == Text && valueOrDefault.Item2 == width && valueOrDefault.Item3 == captionBold && _nameFont != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
Font nameFont = House(captionBold, 7.5f);
|
||||
_nameCut = true;
|
||||
for (float num = 9f; num >= 7.499f; num -= 0.25f)
|
||||
{
|
||||
Font font = House(captionBold, num);
|
||||
if (TextWidth(Text, font) <= width)
|
||||
{
|
||||
nameFont = font;
|
||||
_nameCut = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_nameFont = nameFont;
|
||||
_nameFitFor = (Text, width, captionBold);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
_hover = true;
|
||||
Invalidate();
|
||||
base.OnMouseEnter(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
_hover = false;
|
||||
Invalidate();
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
Invalidate();
|
||||
base.OnGotFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
Invalidate();
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (ClientRectangle.Contains(e.Location))
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
ShowMenu(e.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowMenu(Point at)
|
||||
{
|
||||
if (!Bindable && !Deletable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ContextMenuStrip menu = SignalMenu.ActionMenu();
|
||||
if (Bindable)
|
||||
{
|
||||
menu.Items.Add((BoundHotkey == null) ? "Set hotkey" : "Change hotkey", null, (object? _, EventArgs _) =>
|
||||
{
|
||||
BindRequested?.Invoke(this, EventArgs.Empty);
|
||||
});
|
||||
}
|
||||
if (Deletable)
|
||||
{
|
||||
menu.Items.Add("Delete look", null, (object? _, EventArgs _) =>
|
||||
{
|
||||
DeleteRequested?.Invoke(this, EventArgs.Empty);
|
||||
});
|
||||
}
|
||||
menu.Closed += (object? _, ToolStripDropDownClosedEventArgs _) =>
|
||||
{
|
||||
if (!menu.IsDisposed)
|
||||
{
|
||||
BeginInvoke(menu.Dispose);
|
||||
}
|
||||
};
|
||||
menu.Show(this, at);
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (Deletable && e.KeyCode == Keys.Delete)
|
||||
{
|
||||
DeleteRequested?.Invoke(this, EventArgs.Empty);
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Space)
|
||||
{
|
||||
OnClick(EventArgs.Empty);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override AccessibleObject CreateAccessibilityInstance()
|
||||
{
|
||||
return new TileAccessible(this);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
SmoothingMode smoothingMode = graphics.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = graphics.PixelOffsetMode;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
Rectangle rectangle = new Rectangle(0, 0, Math.Max(1, Width), Math.Max(1, Height));
|
||||
using (GraphicsPath path = Glass.RoundedPath(rectangle, CardRadius))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(ControlInk.Overlay);
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
Rectangle photoRect = PhotoRect;
|
||||
if (_photo == null)
|
||||
{
|
||||
using GraphicsPath path2 = Glass.RoundedPath(photoRect, PhotoRadius);
|
||||
using SolidBrush brush2 = new SolidBrush(SignalInk.PreviewWell);
|
||||
graphics.FillPath(brush2, path2);
|
||||
}
|
||||
if (_photo != null && photoRect.Width > 1 && photoRect.Height > 1)
|
||||
{
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.Default;
|
||||
graphics.DrawImageUnscaled(Thumb(photoRect.Size), photoRect.Location);
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
}
|
||||
DrawChips(graphics, photoRect);
|
||||
Rectangle stripRect = StripRect;
|
||||
Color[] array = StripColours(_matrix);
|
||||
float radius = (float)Tokens.Scale(3) / 2f;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
using GraphicsPath path3 = Glass.RoundedPath(Segment(stripRect, i), radius);
|
||||
using SolidBrush brush3 = new SolidBrush(array[i]);
|
||||
graphics.FillPath(brush3, path3);
|
||||
}
|
||||
FitName();
|
||||
TextRenderer.DrawText(graphics, Text, _nameFont, NameRect, Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
DrawPill(graphics, NameRect.Bottom + PillGap);
|
||||
float num = (_active ? ((float)Tokens.Scale(3) / 2f) : ((float)Tokens.Scale(1)));
|
||||
Color color;
|
||||
if (_active)
|
||||
{
|
||||
color = ControlInk.Accent;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = (_hover ? ControlInk.Edge : ControlInk.WindowEdge);
|
||||
}
|
||||
using (GraphicsPath path4 = Glass.RoundedPath(new RectangleF(num / 2f, num / 2f, (float)rectangle.Width - num, (float)rectangle.Height - num), Math.Max(0f, (float)CardRadius - num / 2f)))
|
||||
{
|
||||
using Pen pen = new Pen(color, num);
|
||||
graphics.DrawPath(pen, path4);
|
||||
}
|
||||
graphics.SmoothingMode = smoothingMode;
|
||||
graphics.PixelOffsetMode = pixelOffsetMode;
|
||||
_ring.Show(Focused && ShowFocusCues);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
private void DrawChips(Graphics g, Rectangle photo)
|
||||
{
|
||||
Font font = House(Fonts.CaptionBold, 7f);
|
||||
int num = Tokens.Scale(4);
|
||||
int num2 = Tokens.Scale(5);
|
||||
int num3 = Tokens.Scale(5);
|
||||
int num4 = Tokens.Scale(3);
|
||||
int chipHeight = ChipHeight;
|
||||
int y = photo.Y + num;
|
||||
int num5 = 0;
|
||||
string text = _boundHotkey ?? "";
|
||||
if (text.Length > 0)
|
||||
{
|
||||
num5 = Math.Min(TextWidth(text, font) + 2 * num2, Math.Max(chipHeight, photo.Width - 2 * num));
|
||||
}
|
||||
int num6 = 2 * num2 + num3 + num4 + TextWidth("zapnuto", font);
|
||||
int num7 = 2 * num2 + num3;
|
||||
int width = 0;
|
||||
bool flag = false;
|
||||
if (_active)
|
||||
{
|
||||
int num8 = photo.Width - 2 * num - ((num5 > 0) ? (num5 + num) : 0);
|
||||
flag = num6 <= num8;
|
||||
width = (flag ? num6 : num7);
|
||||
}
|
||||
using SolidBrush brush = new SolidBrush(Color.FromArgb(230, SignalInk.PreviewWell));
|
||||
int num9 = Tokens.Scale(4);
|
||||
if (_active)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(photo.X + num, y, width, chipHeight);
|
||||
using (GraphicsPath path = Glass.RoundedPath(rectangle, num9))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
int num10 = rectangle.Y + chipHeight / 2;
|
||||
using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(255, Color.FromArgb(6213251))))
|
||||
{
|
||||
g.FillEllipse(brush2, rectangle.X + num2, (float)num10 - (float)num3 / 2f, num3, num3);
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
TextRenderer.DrawText(g, "zapnuto", font, new Rectangle(rectangle.X + num2 + num3 + num4, rectangle.Y, rectangle.Width - num2 - num3 - num4, chipHeight), Theme.Text, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
if (num5 > 0)
|
||||
{
|
||||
Rectangle rectangle2 = new Rectangle(photo.Right - num - num5, y, num5, chipHeight);
|
||||
using (GraphicsPath path2 = Glass.RoundedPath(rectangle2, num9))
|
||||
{
|
||||
g.FillPath(brush, path2);
|
||||
}
|
||||
TextRenderer.DrawText(g, text, font, rectangle2, Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPill(Graphics g, int y)
|
||||
{
|
||||
Font font = House(Fonts.Caption, 7f);
|
||||
string text = _reading.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
int num = Tokens.Scale(8);
|
||||
int width = Math.Min(Width - 2 * Pad, TextWidth(text, font) + 2 * num);
|
||||
Rectangle rectangle = new Rectangle(Pad, y, width, PillHeight);
|
||||
using (GraphicsPath path = Glass.RoundedPath(rectangle, (float)rectangle.Height / 2f))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(ControlInk.Surface2);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
float num2 = Tokens.Scale(1);
|
||||
RectangleF rect = new RectangleF((float)rectangle.X + num2 / 2f, (float)rectangle.Y + num2 / 2f, (float)rectangle.Width - num2, (float)rectangle.Height - num2);
|
||||
using (GraphicsPath path2 = Glass.RoundedPath(rect, rect.Height / 2f))
|
||||
{
|
||||
using Pen pen = new Pen(ControlInk.WindowEdge, num2);
|
||||
g.DrawPath(pen, path2);
|
||||
}
|
||||
TextRenderer.DrawText(g, text, font, rectangle, Theme.TextDim, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
private void DropThumb()
|
||||
{
|
||||
_thumb?.Dispose();
|
||||
_thumb = null;
|
||||
}
|
||||
|
||||
private Bitmap Thumb(Size size)
|
||||
{
|
||||
if (_thumb != null && _thumbFor == size)
|
||||
{
|
||||
return _thumb;
|
||||
}
|
||||
_thumb?.Dispose();
|
||||
using Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb);
|
||||
using (Graphics graphics = Graphics.FromImage(bitmap))
|
||||
{
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
Image photo = _photo;
|
||||
float num = Math.Max((float)size.Width / (float)photo.Width, (float)size.Height / (float)photo.Height);
|
||||
float num2 = (float)size.Width / num;
|
||||
float num3 = (float)size.Height / num;
|
||||
using ImageAttributes imageAttributes = new ImageAttributes();
|
||||
imageAttributes.SetWrapMode(WrapMode.TileFlipXY);
|
||||
if (_lookOnPhoto)
|
||||
{
|
||||
float[] matrix = _matrix;
|
||||
if (matrix != null && matrix.Length >= 25)
|
||||
{
|
||||
imageAttributes.SetColorMatrix(ColourMatrixOf(matrix));
|
||||
}
|
||||
}
|
||||
lock (BrandAssets.DrawGate)
|
||||
{
|
||||
graphics.DrawImage(photo, new Rectangle(Point.Empty, size), ((float)photo.Width - num2) / 2f, ((float)photo.Height - num3) / 2f, num2, num3, GraphicsUnit.Pixel, imageAttributes);
|
||||
}
|
||||
}
|
||||
Bitmap bitmap2 = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb);
|
||||
using (Graphics graphics2 = Graphics.FromImage(bitmap2))
|
||||
{
|
||||
using TextureBrush brush = new TextureBrush(bitmap);
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(0f, 0f, size.Width, size.Height), PhotoRadius);
|
||||
graphics2.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
graphics2.FillPath(brush, path);
|
||||
}
|
||||
_thumb = bitmap2;
|
||||
_thumbFor = size;
|
||||
return bitmap2;
|
||||
}
|
||||
|
||||
private static ColorMatrix ColourMatrixOf(float[] m)
|
||||
{
|
||||
return new ColorMatrix(new float[5][]
|
||||
{
|
||||
Row(0),
|
||||
Row(1),
|
||||
Row(2),
|
||||
new float[5] { 0f, 0f, 0f, 1f, 0f },
|
||||
new float[5]
|
||||
{
|
||||
m[20],
|
||||
m[21],
|
||||
m[22],
|
||||
0f,
|
||||
1f
|
||||
}
|
||||
});
|
||||
float[] Row(int r)
|
||||
{
|
||||
return new float[5]
|
||||
{
|
||||
m[r * 5],
|
||||
m[r * 5 + 1],
|
||||
m[r * 5 + 2],
|
||||
0f,
|
||||
0f
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
DropThumb();
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal static class ScrollTrace
|
||||
{
|
||||
private static readonly bool Enabled = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PLEXUSX_SCROLL_TRACE"));
|
||||
|
||||
private static readonly string Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "plexusx-scroll.log");
|
||||
|
||||
private static readonly object Gate = new object();
|
||||
|
||||
public static void Write(Func<string> message)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
string text = string.Format(CultureInfo.InvariantCulture, "{0:HH:mm:ss.fff} {1}", DateTime.Now, message());
|
||||
lock (Gate)
|
||||
{
|
||||
File.AppendAllText(Path, text + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal sealed class SegmentStrip : Control
|
||||
{
|
||||
private sealed class StripAccessibleObject : ControlAccessibleObject
|
||||
{
|
||||
private readonly SegmentStrip _owner;
|
||||
|
||||
private readonly SegmentAccessibleObject[] _children;
|
||||
|
||||
public StripAccessibleObject(SegmentStrip owner)
|
||||
: base(owner)
|
||||
{
|
||||
_owner = owner;
|
||||
_children = new SegmentAccessibleObject[owner._kinds.Length];
|
||||
for (int i = 0; i < _children.Length; i++)
|
||||
{
|
||||
_children[i] = new SegmentAccessibleObject(owner, this, i);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetChildCount()
|
||||
{
|
||||
return _children.Length;
|
||||
}
|
||||
|
||||
public override AccessibleObject? GetChild(int index)
|
||||
{
|
||||
if (index < 0 || index >= _children.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _children[index];
|
||||
}
|
||||
|
||||
public override AccessibleObject? Navigate(AccessibleNavigation direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
AccessibleNavigation.FirstChild => GetChild(0),
|
||||
AccessibleNavigation.LastChild => GetChild(_children.Length - 1),
|
||||
_ => base.Navigate(direction),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class SegmentAccessibleObject : AccessibleObject
|
||||
{
|
||||
private readonly SegmentStrip _owner;
|
||||
|
||||
private readonly StripAccessibleObject _parent;
|
||||
|
||||
private readonly int _index;
|
||||
|
||||
public override AccessibleObject? Parent => _parent;
|
||||
|
||||
public override string? Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _owner._kinds[_index];
|
||||
}
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override AccessibleRole Role
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_owner.ArrowsChoose)
|
||||
{
|
||||
return AccessibleRole.RadioButton;
|
||||
}
|
||||
return AccessibleRole.PageTab;
|
||||
}
|
||||
}
|
||||
|
||||
public override AccessibleStates State
|
||||
{
|
||||
get
|
||||
{
|
||||
AccessibleStates accessibleStates = AccessibleStates.Selectable;
|
||||
accessibleStates = ((!_owner.Enabled) ? (accessibleStates | AccessibleStates.Unavailable) : (accessibleStates | AccessibleStates.Focusable));
|
||||
if (_owner._kinds[_index] == _owner._active)
|
||||
{
|
||||
accessibleStates = (AccessibleStates)((int)accessibleStates | (_owner.ArrowsChoose ? 2 : 16));
|
||||
}
|
||||
return accessibleStates;
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle[] array = _owner.Segments();
|
||||
if (_index >= array.Length)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
return _owner.RectangleToScreen(array[_index]);
|
||||
}
|
||||
}
|
||||
|
||||
public override string? DefaultAction => "Select";
|
||||
|
||||
public SegmentAccessibleObject(SegmentStrip owner, StripAccessibleObject parent, int index)
|
||||
{
|
||||
_owner = owner;
|
||||
_parent = parent;
|
||||
_index = index;
|
||||
}
|
||||
|
||||
public override void DoDefaultAction()
|
||||
{
|
||||
if (_owner.Enabled)
|
||||
{
|
||||
_owner.TestChoose(_owner._kinds[_index]);
|
||||
}
|
||||
}
|
||||
|
||||
public override AccessibleObject? Navigate(AccessibleNavigation direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
AccessibleNavigation.Next => _parent.GetChild(_index + 1),
|
||||
AccessibleNavigation.Previous => _parent.GetChild(_index - 1),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private const int PoPadding = 3;
|
||||
|
||||
private readonly string[] _kinds;
|
||||
|
||||
private string _active;
|
||||
|
||||
private int _hover = -1;
|
||||
|
||||
private int _cursor = -1;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private readonly OutsideFocusRing _stripRing;
|
||||
|
||||
private static int Radius => Tokens.Scale(4);
|
||||
|
||||
private static int SegmentRadius => Tokens.Scale(2);
|
||||
|
||||
private static int Inset => Tokens.Scale(4);
|
||||
|
||||
private static int SegmentGap => Tokens.Scale(2);
|
||||
|
||||
internal bool ArrowsChoose { get; set; }
|
||||
|
||||
internal int NaturalWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = 2 * Inset + SegmentGap * Math.Max(0, _kinds.Length - 1);
|
||||
for (int i = 0; i < _kinds.Length; i++)
|
||||
{
|
||||
num += TextRenderer.MeasureText(_kinds[i], FontOf(i), Size.Empty, TextFormatFlags.NoPadding).Width + 2 * Tokens.Scale(12);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
internal IReadOnlyList<string> Items => _kinds;
|
||||
|
||||
private int CursorIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cursor < 0 || _cursor >= _kinds.Length)
|
||||
{
|
||||
return Math.Max(0, Array.IndexOf(_kinds, _active));
|
||||
}
|
||||
return _cursor;
|
||||
}
|
||||
}
|
||||
|
||||
internal Rectangle TestRingBox => RingBox();
|
||||
|
||||
internal string Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(_active == value))
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal Rectangle[] TestSegments => Segments();
|
||||
|
||||
internal event EventHandler<string>? Chosen;
|
||||
|
||||
private Font FontOf(int i)
|
||||
{
|
||||
if (!(_kinds[i] == _active))
|
||||
{
|
||||
return Fonts.Body;
|
||||
}
|
||||
return Fonts.BodyBold;
|
||||
}
|
||||
|
||||
private Color Ink(Color c)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
return ControlInk.Locked(c, Theme.Surface);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
internal SegmentStrip(string[] kinds)
|
||||
{
|
||||
_kinds = kinds;
|
||||
_active = ((kinds.Length != 0) ? kinds[0] : "");
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
AccessibleRole = AccessibleRole.PageTabList;
|
||||
_ring = new OutsideFocusRing(this, () => SegmentRadius, RingBox);
|
||||
_stripRing = new OutsideFocusRing(this, () => Radius);
|
||||
}
|
||||
|
||||
private Rectangle RingBox()
|
||||
{
|
||||
Rectangle[] array = Segments();
|
||||
if (array.Length != 0)
|
||||
{
|
||||
return array[Math.Min(CursorIndex, array.Length - 1)];
|
||||
}
|
||||
return ClientRectangle;
|
||||
}
|
||||
|
||||
internal bool TestClaimsKey(Keys key)
|
||||
{
|
||||
return IsInputKey(key);
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override bool IsInputKey(Keys keyData)
|
||||
{
|
||||
bool flag = (keyData & Keys.Modifiers) == 0;
|
||||
if (flag)
|
||||
{
|
||||
Keys keys = keyData & Keys.KeyCode;
|
||||
bool flag2 = (uint)(keys - 35) <= 5u;
|
||||
flag = flag2;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return base.IsInputKey(keyData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (_kinds.Length == 0 || e.Modifiers != Keys.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int cursorIndex = CursorIndex;
|
||||
int num;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Left:
|
||||
case Keys.Up:
|
||||
num = (cursorIndex - 1 + _kinds.Length) % _kinds.Length;
|
||||
break;
|
||||
case Keys.Right:
|
||||
case Keys.Down:
|
||||
num = (cursorIndex + 1) % _kinds.Length;
|
||||
break;
|
||||
case Keys.Home:
|
||||
num = 0;
|
||||
break;
|
||||
case Keys.End:
|
||||
num = _kinds.Length - 1;
|
||||
break;
|
||||
case Keys.Return:
|
||||
case Keys.Space:
|
||||
e.Handled = true;
|
||||
_cursor = -1;
|
||||
if (_kinds[cursorIndex] != _active)
|
||||
{
|
||||
Chosen?.Invoke(this, _kinds[cursorIndex]);
|
||||
}
|
||||
Invalidate();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
if (num != cursorIndex)
|
||||
{
|
||||
if (ArrowsChoose)
|
||||
{
|
||||
_cursor = -1;
|
||||
Chosen?.Invoke(this, _kinds[num]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_cursor = num;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
_cursor = -1;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
_cursor = -1;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
_stripRing.Rehook();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
_stripRing.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override AccessibleObject CreateAccessibilityInstance()
|
||||
{
|
||||
return new StripAccessibleObject(this);
|
||||
}
|
||||
|
||||
private Rectangle[] Segments()
|
||||
{
|
||||
Rectangle[] array = new Rectangle[_kinds.Length];
|
||||
if (_kinds.Length == 0)
|
||||
{
|
||||
return array;
|
||||
}
|
||||
int inset = Inset;
|
||||
int segmentGap = SegmentGap;
|
||||
int num = Math.Max(1, Width - 2 * inset - segmentGap * (_kinds.Length - 1));
|
||||
int num2 = 0;
|
||||
int[] array2 = new int[_kinds.Length];
|
||||
for (int i = 0; i < _kinds.Length; i++)
|
||||
{
|
||||
array2[i] = TextRenderer.MeasureText(_kinds[i], FontOf(i), Size.Empty, TextFormatFlags.NoPadding).Width;
|
||||
num2 += array2[i];
|
||||
}
|
||||
int num3 = Math.Max(0, num - num2);
|
||||
int num4 = inset;
|
||||
for (int j = 0; j < _kinds.Length; j++)
|
||||
{
|
||||
int num5 = num3 * (j + 1) / _kinds.Length - num3 * j / _kinds.Length;
|
||||
int num6 = array2[j] + num5;
|
||||
array[j] = new Rectangle(num4, inset, num6, Math.Max(1, Height - 2 * inset));
|
||||
num4 += num6 + segmentGap;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Rectangle[] array = Segments();
|
||||
int hover = _hover;
|
||||
_hover = -1;
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].Contains(e.Location))
|
||||
{
|
||||
_hover = i;
|
||||
}
|
||||
}
|
||||
if (_hover != hover)
|
||||
{
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (_hover >= 0)
|
||||
{
|
||||
_hover = -1;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (e.Button != MouseButtons.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Rectangle[] array = Segments();
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].Contains(e.Location))
|
||||
{
|
||||
if (!(_kinds[i] == _active))
|
||||
{
|
||||
Chosen?.Invoke(this, _kinds[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rect = new RectangleF(0.5f, 0.5f, Width - 1, Height - 1);
|
||||
using (Pen pen = new Pen(Ink(Theme.GlassEdge), Tokens.Scale(1)))
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(rect, Radius);
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
Rectangle[] array = Segments();
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
bool flag = _kinds[i] == _active;
|
||||
RectangleF rect2 = new RectangleF(array[i].X, array[i].Y, array[i].Width, array[i].Height);
|
||||
if (flag)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Ink(Theme.Accent));
|
||||
using GraphicsPath path2 = Glass.RoundedPath(rect2, SegmentRadius);
|
||||
graphics.FillPath(brush, path2);
|
||||
}
|
||||
else if (_hover == i && Enabled)
|
||||
{
|
||||
using SolidBrush brush2 = new SolidBrush(Theme.SurfaceHover);
|
||||
using GraphicsPath path3 = Glass.RoundedPath(rect2, SegmentRadius);
|
||||
graphics.FillPath(brush2, path3);
|
||||
}
|
||||
TextRenderer.DrawText(graphics, _kinds[i], FontOf(i), array[i], Ink(flag ? Theme.OnAccent : Theme.TextDim), TextFormatFlags.HorizontalCenter | TextFormatFlags.NoClipping | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
bool flag2 = Focused && ShowFocusCues && Enabled;
|
||||
if (flag2)
|
||||
{
|
||||
ControlInk.PaintFocusRing(graphics, RingBox(), SegmentRadius, ControlInk.Dpi(this));
|
||||
}
|
||||
_ring.Show(flag2);
|
||||
_stripRing.Show(flag2);
|
||||
}
|
||||
|
||||
internal void TestChoose(string item)
|
||||
{
|
||||
if (item != _active && Array.IndexOf(_kinds, item) >= 0)
|
||||
{
|
||||
Chosen?.Invoke(this, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal sealed class SignalCard
|
||||
{
|
||||
internal sealed record Placed(int Top, int Height, Label Title, Label? Caption)
|
||||
{
|
||||
internal int Bottom => Top + Height;
|
||||
}
|
||||
|
||||
private sealed class UnpaddedStatusLabel : Label
|
||||
{
|
||||
public override Size GetPreferredSize(Size proposedSize)
|
||||
{
|
||||
return TextRenderer.MeasureText(Text, Font, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.NoPadding);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
|
||||
internal const int Inset = 21;
|
||||
|
||||
internal const int PadY = 4;
|
||||
|
||||
internal const int RowHeight = 52;
|
||||
|
||||
internal const int TitleLine = 20;
|
||||
|
||||
internal const int CaptionLine = 16;
|
||||
|
||||
internal const int ControlHeight = 28;
|
||||
|
||||
internal const int ToggleWidth = 40;
|
||||
|
||||
internal const int ToggleHeight = 20;
|
||||
|
||||
internal const int TextX = 18;
|
||||
|
||||
internal const int CaptionX = 20;
|
||||
|
||||
private readonly int _width;
|
||||
|
||||
private int _rowTop = 5;
|
||||
|
||||
private bool _first = true;
|
||||
|
||||
internal CardPanel Panel { get; }
|
||||
|
||||
internal int ContentWidth => _width - 42;
|
||||
|
||||
internal int Bottom => _rowTop;
|
||||
|
||||
internal (Label Lead, Label Tail, Control? Control)? StatusParts { get; private set; }
|
||||
|
||||
internal static int RowHeightFor(int lines)
|
||||
{
|
||||
return Math.Max(52, 30 + 16 * Math.Max(0, lines));
|
||||
}
|
||||
|
||||
internal SignalCard(int x, int y, int width)
|
||||
{
|
||||
_width = width;
|
||||
Panel = new CardPanel
|
||||
{
|
||||
Location = new Point(x, y),
|
||||
Size = new Size(width, 62)
|
||||
};
|
||||
}
|
||||
|
||||
internal static ToggleSwitch Toggle(bool on)
|
||||
{
|
||||
return new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
Checked = on
|
||||
};
|
||||
}
|
||||
|
||||
internal Placed Row(string title, string caption = "", Control? control = null, string? value = null, int captionLines = 1, Color? captionInk = null, Color? titleInk = null)
|
||||
{
|
||||
if (caption.Length == 0)
|
||||
{
|
||||
captionLines = 0;
|
||||
}
|
||||
int rowTop = _rowTop;
|
||||
int num = RowHeightFor(captionLines);
|
||||
int num2 = rowTop;
|
||||
if (!_first)
|
||||
{
|
||||
Panel.Controls.Add(new Label
|
||||
{
|
||||
AutoSize = false,
|
||||
Text = "",
|
||||
BackColor = Theme.Border,
|
||||
Bounds = new Rectangle(21, rowTop, _width - 42, 1)
|
||||
});
|
||||
num2 = rowTop + 1;
|
||||
}
|
||||
_first = false;
|
||||
int num3 = 20 + 16 * captionLines;
|
||||
int num4 = num2 + (num - num3) / 2;
|
||||
int num5 = num2 + num / 2;
|
||||
int num6 = ((value != null) ? (TextRenderer.MeasureText(value, Fonts.Body).Width + 6) : 0);
|
||||
int num7 = ((control != null) ? (control.Width + 16) : 0) + ((num6 > 0) ? (num6 + 16) : 0);
|
||||
Label label = new Label
|
||||
{
|
||||
Text = title,
|
||||
ForeColor = (titleInk ?? Theme.Text),
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
Location = new Point(18, num4 - 1),
|
||||
AutoSize = true,
|
||||
UseMnemonic = false
|
||||
};
|
||||
Panel.Controls.Add(label);
|
||||
Label label2 = null;
|
||||
if (captionLines > 0)
|
||||
{
|
||||
label2 = new Label
|
||||
{
|
||||
Text = caption,
|
||||
ForeColor = (captionInk ?? SettingsPage.RowCaptionInk),
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Caption,
|
||||
Location = new Point(20, num4 + 20 + 2),
|
||||
AutoSize = false,
|
||||
Size = new Size(Math.Max(40, ContentWidth - num7), 16 * captionLines),
|
||||
UseMnemonic = false
|
||||
};
|
||||
Panel.Controls.Add(label2);
|
||||
}
|
||||
int num8 = _width - 21 + 3;
|
||||
if (control != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(control.AccessibleName))
|
||||
{
|
||||
control.AccessibleName = title;
|
||||
control.AccessibleDescription = caption;
|
||||
}
|
||||
control.Location = new Point(_width - 21 - control.Width, num5 - control.Height / 2);
|
||||
Panel.Controls.Add(control);
|
||||
num8 = control.Left - 6;
|
||||
}
|
||||
if (value != null)
|
||||
{
|
||||
Panel.Controls.Add(new Label
|
||||
{
|
||||
Text = value,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleRight,
|
||||
Bounds = new Rectangle(num8 - num6, num5 - 10, num6, 20),
|
||||
UseMnemonic = false
|
||||
});
|
||||
}
|
||||
_rowTop = rowTop + num;
|
||||
Panel.Height = _rowTop + 4 + 1;
|
||||
return new Placed(rowTop, num, label, label2);
|
||||
}
|
||||
|
||||
internal void StatusRow(string lead, string tail, Control? control = null)
|
||||
{
|
||||
int rowTop = _rowTop;
|
||||
int num = rowTop + 26;
|
||||
UnpaddedStatusLabel unpaddedStatusLabel = new UnpaddedStatusLabel
|
||||
{
|
||||
Text = lead,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
Location = new Point(18, num - 10),
|
||||
AutoSize = false,
|
||||
Size = new Size(TextRenderer.MeasureText(lead, Fonts.Body, Size.Empty, TextFormatFlags.NoPadding).Width, 20),
|
||||
UseMnemonic = false
|
||||
};
|
||||
Panel.Controls.Add(unpaddedStatusLabel);
|
||||
int width = unpaddedStatusLabel.Width;
|
||||
if (control != null)
|
||||
{
|
||||
control.Location = new Point(_width - 21 - control.Width, num - control.Height / 2);
|
||||
Panel.Controls.Add(control);
|
||||
}
|
||||
int num2 = 18 + width + 4;
|
||||
int val = ((control != null) ? (control.Left - 12) : (_width - 21)) - num2;
|
||||
UnpaddedStatusLabel unpaddedStatusLabel2 = new UnpaddedStatusLabel
|
||||
{
|
||||
Text = tail,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
Location = new Point(num2, num - 10),
|
||||
AutoSize = false,
|
||||
Size = new Size(Math.Max(40, val), 20),
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
UseMnemonic = false
|
||||
};
|
||||
Panel.Controls.Add(unpaddedStatusLabel2);
|
||||
StatusParts = (unpaddedStatusLabel, unpaddedStatusLabel2, control);
|
||||
_first = false;
|
||||
_rowTop = rowTop + 52;
|
||||
Panel.Height = _rowTop + 4 + 1;
|
||||
}
|
||||
|
||||
internal void GrowToFit(Control child)
|
||||
{
|
||||
int num = child.Bottom + 4 + 1;
|
||||
if (num > Panel.Height)
|
||||
{
|
||||
Panel.Height = num;
|
||||
}
|
||||
}
|
||||
|
||||
internal void GrowToFitAll()
|
||||
{
|
||||
int num = 0;
|
||||
foreach (Control control in Panel.Controls)
|
||||
{
|
||||
num = Math.Max(num, control.Bottom);
|
||||
}
|
||||
Panel.Height = Math.Max(Panel.Height, num + 4 + 1);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Pages;
|
||||
|
||||
internal static class WordsFit
|
||||
{
|
||||
private const TextFormatFlags Wrapped = TextFormatFlags.NoPrefix | TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak;
|
||||
|
||||
internal static int Needed(Label l)
|
||||
{
|
||||
return TextRenderer.MeasureText(l.Text, l.Font, new Size(Math.Max(1, l.Width), int.MaxValue), TextFormatFlags.NoPrefix | TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak).Height;
|
||||
}
|
||||
|
||||
internal static int OneLine(Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText("Hg", font, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPrefix | TextFormatFlags.TextBoxControl).Height;
|
||||
}
|
||||
|
||||
internal static bool TypeAndBoxesAgree(int captionLineAtPageScale, int pageDpi)
|
||||
{
|
||||
if (pageDpi != Tokens.Dpi)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Math.Abs(OneLine(Fonts.Caption) - captionLineAtPageScale) * 8 <= captionLineAtPageScale;
|
||||
}
|
||||
|
||||
internal static int GrowWrappedLabels(Control card, Func<Label, bool>? skip = null)
|
||||
{
|
||||
int num = 0;
|
||||
foreach (Label item in (from l in card.Controls.OfType<Label>()
|
||||
orderby l.Top
|
||||
select l).ToList())
|
||||
{
|
||||
if (item.AutoSize || item.Width <= 0 || item.Height <= 0 || string.IsNullOrEmpty(item.Text) || (skip != null && skip(item)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int num2 = Needed(item);
|
||||
if (num2 <= OneLine(item.Font) + 2 || item.Height >= num2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int num3 = num2 - item.Height;
|
||||
int bottom = item.Bottom;
|
||||
int num4 = int.MaxValue;
|
||||
foreach (Control control3 in card.Controls)
|
||||
{
|
||||
if (control3 != item && control3.Height > 0 && control3.Top >= bottom - 1 && control3.Left < item.Right && control3.Right > item.Left)
|
||||
{
|
||||
num4 = Math.Min(num4, control3.Top);
|
||||
}
|
||||
}
|
||||
int num5 = ((num4 != int.MaxValue) ? Math.Max(0, num4 - bottom) : 0);
|
||||
item.Height = num2;
|
||||
int num6 = Math.Max(0, num3 - num5);
|
||||
if (num6 == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (Control control4 in card.Controls)
|
||||
{
|
||||
if (control4 != item && control4.Top >= bottom - 1)
|
||||
{
|
||||
control4.Top += num6;
|
||||
}
|
||||
}
|
||||
card.Height += num6;
|
||||
num += num6;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
internal static void GrowNarrowButtons(Control card, int inset)
|
||||
{
|
||||
foreach (GlassButton item in (from b in card.Controls.OfType<GlassButton>()
|
||||
orderby b.Left
|
||||
select b).ToList())
|
||||
{
|
||||
int width = item.GetPreferredSize(Size.Empty).Width;
|
||||
if (item.Width >= width)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int num = width - item.Width;
|
||||
if (Math.Abs(item.Right - (card.Width - inset)) <= 2)
|
||||
{
|
||||
item.SetBounds(item.Left - num, item.Top, width, item.Height);
|
||||
continue;
|
||||
}
|
||||
int right = item.Right;
|
||||
item.Width = width;
|
||||
foreach (Control control in card.Controls)
|
||||
{
|
||||
if (control != item && control.Left >= right - 1 && control.Top < item.Bottom && control.Bottom > item.Top)
|
||||
{
|
||||
control.Left += num;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user