upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class AnimationClockPolicy
|
||||
{
|
||||
public static int IntervalFor(TimeSpan sinceLastInput, bool movingPicture)
|
||||
{
|
||||
if (!movingPicture && !(sinceLastInput < TimeSpan.FromSeconds(3.0)))
|
||||
{
|
||||
return 200;
|
||||
}
|
||||
return 47;
|
||||
}
|
||||
|
||||
public static bool ShouldRun(bool visible, bool minimized, bool movingOrSizing, bool goingAway, bool active)
|
||||
{
|
||||
return (visible && !minimized && !movingOrSizing && !goingAway) & active;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class AppFolders
|
||||
{
|
||||
public static string Roaming => For(Environment.SpecialFolder.ApplicationData, RootForTest ?? SecurityCandidate.StorageRoot, FlavourPolicy.Current.DataFolderName);
|
||||
|
||||
public static string Local => For(Environment.SpecialFolder.LocalApplicationData, RootForTest ?? SecurityCandidate.StorageRoot, FlavourPolicy.Current.DataFolderName);
|
||||
|
||||
public static string Pictures => For(Environment.SpecialFolder.MyPictures, RootForTest ?? SecurityCandidate.StorageRoot);
|
||||
|
||||
public static string TaskbarPins => PinnedIn(RootForTest ?? SecurityCandidate.StorageRoot);
|
||||
|
||||
internal static string? RootForTest { get; set; }
|
||||
|
||||
internal static string PinnedIn(string? root)
|
||||
{
|
||||
return Path.Combine((root == null) ? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) : Path.Combine(root, Environment.SpecialFolder.ApplicationData.ToString()), "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");
|
||||
}
|
||||
|
||||
internal static string For(Environment.SpecialFolder folder, string? root)
|
||||
{
|
||||
return For(folder, root, "PlexusX");
|
||||
}
|
||||
|
||||
internal static string For(Environment.SpecialFolder folder, string? root, string folderName)
|
||||
{
|
||||
return Path.Combine((root == null) ? Environment.GetFolderPath(folder) : Path.Combine(root, folder.ToString()), folderName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class AppIcon
|
||||
{
|
||||
private static Icon? _icon;
|
||||
|
||||
public static Icon Value => _icon ?? (_icon = Load());
|
||||
|
||||
private static Icon Load()
|
||||
{
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PlexusX.ico");
|
||||
return (stream != null) ? new Icon(stream) : SystemIcons.Application;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class AppInfo
|
||||
{
|
||||
public const string ProductName = "PlexusX";
|
||||
|
||||
public const string Tagline = "Sharper colours. Every game.";
|
||||
|
||||
public const string DiscordUrl = "https://plexusx.lol/discord";
|
||||
|
||||
public const string SiteUrl = "https://plexusx.lol";
|
||||
|
||||
public const string PresetUploadUrl = "https://plexusx.lol/dashboard?tab=presets";
|
||||
|
||||
public const string SupportEmail = "[email protected]";
|
||||
|
||||
public static string VersionText => FormatVersion(UpdateService.CurrentVersion);
|
||||
|
||||
internal static string PresetReportUrl(string id)
|
||||
{
|
||||
return "https://plexusx.lol/presets?report=" + Uri.EscapeDataString(id);
|
||||
}
|
||||
|
||||
public static string FormatVersion(Version v)
|
||||
{
|
||||
return $"v{v.Major}.{v.Minor}.{Math.Max(v.Build, 0)}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using VibranceHud.Capabilities;
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Customize;
|
||||
using VibranceHud.DarkBoost;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class AppSettings
|
||||
{
|
||||
public sealed class PanelSettings
|
||||
{
|
||||
public int Index { get; set; }
|
||||
|
||||
public int Brightness { get; set; } = -1;
|
||||
|
||||
public int Contrast { get; set; } = -1;
|
||||
|
||||
public int LowBlue { get; set; } = -1;
|
||||
|
||||
public int RedGain { get; set; } = -1;
|
||||
|
||||
public int GreenGain { get; set; } = -1;
|
||||
|
||||
public string Key { get; set; } = "";
|
||||
|
||||
public bool PanelTouched { get; set; }
|
||||
|
||||
public int WroteBrightness { get; set; } = -1;
|
||||
|
||||
public int WroteContrast { get; set; } = -1;
|
||||
|
||||
public int WroteBlueGain { get; set; } = -1;
|
||||
|
||||
public int WroteRedGain { get; set; } = -1;
|
||||
|
||||
public int WroteGreenGain { get; set; } = -1;
|
||||
|
||||
public bool HasOriginals { get; set; }
|
||||
|
||||
public int OriginalBrightness { get; set; }
|
||||
|
||||
public int OriginalContrast { get; set; }
|
||||
|
||||
public int OriginalBlueGain { get; set; }
|
||||
|
||||
public int OriginalRedGain { get; set; }
|
||||
|
||||
public int OriginalGreenGain { get; set; }
|
||||
}
|
||||
|
||||
internal const uint ZoomDefaultVirtualKey = 6u;
|
||||
|
||||
public int Level { get; set; } = 100;
|
||||
|
||||
public int? VibrancePercent { get; set; }
|
||||
|
||||
public int? SaturationPercent { get; set; }
|
||||
|
||||
public int ResolvedVibrance => VibrancePercent ?? Math.Min(Level, 100);
|
||||
|
||||
public int ResolvedSaturation
|
||||
{
|
||||
get
|
||||
{
|
||||
int? saturationPercent = SaturationPercent;
|
||||
if (!saturationPercent.HasValue)
|
||||
{
|
||||
if (Level <= 100)
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
return Level;
|
||||
}
|
||||
return saturationPercent.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public bool VibranceChosenByUser { get; set; }
|
||||
|
||||
public int VibranceOwnershipVersion { get; set; }
|
||||
|
||||
public int? DriverVibranceWeLastWrote { get; set; }
|
||||
|
||||
public bool StartWithWindows { get; set; }
|
||||
|
||||
public bool KeepDesktopComposited { get; set; }
|
||||
|
||||
public bool LowLatencyResetDone { get; set; }
|
||||
|
||||
public bool CompositionKeeperDefaultOnDone { get; set; }
|
||||
|
||||
public bool CompositionKeeperDefaultOffDone { get; set; }
|
||||
|
||||
public int OpacityPercent { get; set; } = 100;
|
||||
|
||||
public bool LightTheme { get; set; }
|
||||
|
||||
public string ThemeName { get; set; } = "";
|
||||
|
||||
public string BackdropLookName { get; set; } = "";
|
||||
|
||||
public string AccessEndingWarnedFor { get; set; } = "";
|
||||
|
||||
public string OfflineNoticeShownFor { get; set; } = "";
|
||||
|
||||
public string ServerNoticeShownId { get; set; } = "";
|
||||
|
||||
public string ServerNoticeShownAt { get; set; } = "";
|
||||
|
||||
public string SignInBrowserPath { get; set; } = "";
|
||||
|
||||
public string SignInBrowserName { get; set; } = "";
|
||||
|
||||
public string SurfaceStyleName { get; set; } = "";
|
||||
|
||||
public string ChromeName { get; set; } = "";
|
||||
|
||||
public int ColourModeLookVersion { get; set; }
|
||||
|
||||
public int Hue { get; set; }
|
||||
|
||||
public int RedGain { get; set; } = 100;
|
||||
|
||||
public int GreenGain { get; set; } = 100;
|
||||
|
||||
public int BlueGain { get; set; } = 100;
|
||||
|
||||
public string TaskbarStyleName { get; set; } = "";
|
||||
|
||||
public uint TaskbarColorArgb { get; set; }
|
||||
|
||||
public bool TaskbarFollowsAccent { get; set; }
|
||||
|
||||
public int BrightnessPercent { get; set; } = 100;
|
||||
|
||||
public int GammaPercent { get; set; } = 100;
|
||||
|
||||
public int ContrastPercent { get; set; } = 100;
|
||||
|
||||
public int? Temperature { get; set; }
|
||||
|
||||
public bool EyeCare { get; set; }
|
||||
|
||||
public int ResolvedTemperature
|
||||
{
|
||||
get
|
||||
{
|
||||
int? temperature = Temperature;
|
||||
if (!temperature.HasValue)
|
||||
{
|
||||
if (!EyeCare)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 50;
|
||||
}
|
||||
return temperature.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public ColourVisionMode ColourVision { get; set; }
|
||||
|
||||
public bool ColourVisionFromPreset { get; set; }
|
||||
|
||||
public ColourVisionMode UserColourVision { get; set; }
|
||||
|
||||
public List<DisplayPreset> CustomPresets { get; set; } = new List<DisplayPreset>();
|
||||
|
||||
public OverlayMode OverlayMode { get; set; }
|
||||
|
||||
public DxInitFailureKind DxFailure { get; set; }
|
||||
|
||||
public string DxFailureMessage { get; set; } = "";
|
||||
|
||||
public int DxFailureCode { get; set; }
|
||||
|
||||
public bool QualityColour { get; set; }
|
||||
|
||||
public string CustomBackgroundFile { get; set; } = "";
|
||||
|
||||
public int CustomBackgroundDim { get; set; } = 40;
|
||||
|
||||
public int CustomBackgroundBlur { get; set; }
|
||||
|
||||
public int CustomBackgroundMatteArgb { get; set; }
|
||||
|
||||
public int SlateGuiOpacityPercent { get; set; }
|
||||
|
||||
public bool SlateMatteBlur { get; set; } = true;
|
||||
|
||||
public int CustomAccentArgb { get; set; }
|
||||
|
||||
public bool NightVisionOn { get; set; }
|
||||
|
||||
public bool DarkBoostBanRiskAccepted { get; set; }
|
||||
|
||||
public bool NightVisionCodeValidated { get; set; }
|
||||
|
||||
public uint NightVisionHotkeyModifierMask { get; set; }
|
||||
|
||||
public uint NightVisionHotkeyVirtualKey { get; set; }
|
||||
|
||||
public bool NightVisionHotkeyEnabled { get; set; }
|
||||
|
||||
public bool ZoomEnabled { get; set; }
|
||||
|
||||
public float ZoomLevel { get; set; } = 2f;
|
||||
|
||||
public uint ZoomHotkeyModifierMask { get; set; }
|
||||
|
||||
public uint ZoomHotkeyVirtualKey { get; set; }
|
||||
|
||||
public bool ZoomSmooth { get; set; } = true;
|
||||
|
||||
public bool ZoomSmoothEdges { get; set; }
|
||||
|
||||
public bool ZoomKeyDefaulted { get; set; }
|
||||
|
||||
public bool CrosshairEnabled { get; set; }
|
||||
|
||||
public CrosshairConfig ActiveCrosshair { get; set; } = new CrosshairConfig();
|
||||
|
||||
public List<CrosshairConfig> SavedCrosshairs { get; set; } = new List<CrosshairConfig>();
|
||||
|
||||
public List<string> FavouriteCrosshairs { get; set; } = new List<string>();
|
||||
|
||||
public string PendingUpdateInstaller { get; set; } = "";
|
||||
|
||||
public string PendingUpdateSha256 { get; set; } = "";
|
||||
|
||||
public string PendingUpdateSignedManifest { get; set; } = "";
|
||||
|
||||
public string PendingUpdateVersion { get; set; } = "";
|
||||
|
||||
public string UpdateRefusedSha256 { get; set; } = "";
|
||||
|
||||
public string UpdateRefusedAtUtc { get; set; } = "";
|
||||
|
||||
public string UpdateRefusedNoticedSha256 { get; set; } = "";
|
||||
|
||||
public string LastSeenVersion { get; set; } = "";
|
||||
|
||||
public bool OnboardingComplete { get; set; }
|
||||
|
||||
public bool ForcedResignInDone { get; set; }
|
||||
|
||||
public string MovedMachineNoticeShownFor { get; set; } = "";
|
||||
|
||||
public bool PlansShown { get; set; }
|
||||
|
||||
public string FavoriteGame { get; set; } = "";
|
||||
|
||||
public string CurrentGameId { get; set; } = "";
|
||||
|
||||
public string PendingGameOfferId { get; set; } = "";
|
||||
|
||||
public string PendingDisplayRestore { get; set; } = "";
|
||||
|
||||
public GameLookSnapshot? LookBeforeGame { get; set; }
|
||||
|
||||
public List<string> DeclinedGameOffers { get; set; } = new List<string>();
|
||||
|
||||
public List<MonitorRule> MonitorRules { get; set; } = new List<MonitorRule>();
|
||||
|
||||
public int RustResolutionWidth { get; set; }
|
||||
|
||||
public int RustResolutionHeight { get; set; }
|
||||
|
||||
public bool AudioEdgeEnabled { get; set; }
|
||||
|
||||
public int AudioEdgeThresholdPercent { get; set; } = 50;
|
||||
|
||||
public float AudioEdgeRestoreVolume { get; set; } = 1f;
|
||||
|
||||
public bool AudioEdgeRestorePending { get; set; }
|
||||
|
||||
public int NvapiRestoreLevel { get; set; } = -1;
|
||||
|
||||
public Dictionary<string, int> NvapiRestoreLevels { get; set; } = new Dictionary<string, int>();
|
||||
|
||||
public bool NvapiRestorePending { get; set; }
|
||||
|
||||
public bool GammaRestorePending { get; set; }
|
||||
|
||||
public int EyeCareWarmth { get; set; }
|
||||
|
||||
public int EyeCareDim { get; set; }
|
||||
|
||||
public uint HotkeyModifierMask { get; set; } = 3u;
|
||||
|
||||
public uint HotkeyVirtualKey { get; set; } = 86u;
|
||||
|
||||
public bool ScreenshotHotkeyEnabled { get; set; } = true;
|
||||
|
||||
public uint ScreenshotHotkeyModifierMask { get; set; } = 3u;
|
||||
|
||||
public uint ScreenshotHotkeyVirtualKey { get; set; } = 83u;
|
||||
|
||||
public int VibranceScaleVersion { get; set; }
|
||||
|
||||
public bool StreamingMode { get; set; }
|
||||
|
||||
public bool CompetitiveMode { get; set; }
|
||||
|
||||
public bool MainHotkeyEnabled { get; set; }
|
||||
|
||||
public uint MainHotkeyModifierMask { get; set; } = 6u;
|
||||
|
||||
public uint MainHotkeyVirtualKey { get; set; } = 77u;
|
||||
|
||||
public List<PresetKeyBinding> PresetKeyBindings { get; set; } = new List<PresetKeyBinding>();
|
||||
|
||||
public List<MonitorColourSetting> MonitorColours { get; set; } = new List<MonitorColourSetting>();
|
||||
|
||||
public List<string>? SelectedMonitorIds { get; set; }
|
||||
|
||||
public List<string>? UntickedDeviceKeys { get; set; }
|
||||
|
||||
public Dictionary<string, int>? OwnedMonitorVibrance { get; set; }
|
||||
|
||||
public Dictionary<string, int>? OwnedMonitorVibranceLastWritten { get; set; }
|
||||
|
||||
public Dictionary<string, ushort[]>? OwnedMonitorGamma { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ManualOverrideActive { get; set; }
|
||||
|
||||
public int PopupX { get; set; } = int.MinValue;
|
||||
|
||||
public int PopupY { get; set; } = int.MinValue;
|
||||
|
||||
public int WindowX { get; set; }
|
||||
|
||||
public int WindowY { get; set; }
|
||||
|
||||
public int WindowWidth { get; set; }
|
||||
|
||||
public int WindowHeight { get; set; }
|
||||
|
||||
public bool WindowMaximized { get; set; }
|
||||
|
||||
public ToneSettings? Tone { get; set; }
|
||||
|
||||
public float[]? Mix { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ChannelMix ResolvedMix => ChannelMix.FromArray(Mix);
|
||||
|
||||
public List<PanelSettings> Panels { get; set; } = new List<PanelSettings>();
|
||||
|
||||
public string ColourPresetGame { get; set; } = "";
|
||||
|
||||
public string ColourPresetName { get; set; } = "";
|
||||
|
||||
public bool ShowOnDiscord { get; set; } = true;
|
||||
|
||||
[JsonIgnore]
|
||||
public ToneSettings ResolvedTone
|
||||
{
|
||||
get
|
||||
{
|
||||
ToneSettings toneSettings = Tone ?? ToneSettings.Neutral;
|
||||
return toneSettings with
|
||||
{
|
||||
Gamma = GammaPercent
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public CustomizationSettings Customization { get; set; } = new CustomizationSettings();
|
||||
|
||||
public SaturationMetric SaturationFormula { get; set; }
|
||||
|
||||
public int Darken { get; set; }
|
||||
|
||||
public int DarkenHue { get; set; } = 120;
|
||||
|
||||
public int HueTurn { get; set; }
|
||||
|
||||
public int HueTurnAmount { get; set; } = 100;
|
||||
|
||||
public int HueComplement { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ColourDepth Depth
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ColourDepth(SaturationFormula, Darken, DarkenHue, HueTurn, HueTurnAmount, HueComplement);
|
||||
}
|
||||
set
|
||||
{
|
||||
SaturationFormula = value.Formula;
|
||||
Darken = value.Darken;
|
||||
DarkenHue = value.DarkenHue;
|
||||
HueTurn = value.HueTurn;
|
||||
HueTurnAmount = value.HueTurnAmount;
|
||||
HueComplement = value.HueComplement;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MusicHotkeyEnabled { get; set; }
|
||||
|
||||
public uint MusicHotkeyModifierMask { get; set; } = 3u;
|
||||
|
||||
public uint MusicHotkeyVirtualKey { get; set; } = 80u;
|
||||
|
||||
public bool NightVisionHotkeyHold { get; set; }
|
||||
|
||||
public bool HotkeysOnlyInGames { get; set; } = true;
|
||||
|
||||
public List<DarkBoostSetup> DarkBoostSetups { get; set; } = new List<DarkBoostSetup> { VibranceHud.DarkBoost.DarkBoostSetups.Default };
|
||||
|
||||
public int DarkBoostSelected { get; set; }
|
||||
|
||||
public bool DarkBoostFade { get; set; } = true;
|
||||
|
||||
public uint DarkBoostNextKeyModifierMask { get; set; }
|
||||
|
||||
public uint DarkBoostNextKeyVirtualKey { get; set; }
|
||||
|
||||
public int? MusicMiniX { get; set; }
|
||||
|
||||
public int? MusicMiniY { get; set; }
|
||||
|
||||
public bool MusicPlayPauseHotkeyEnabled { get; set; }
|
||||
|
||||
public uint MusicPlayPauseHotkeyModifierMask { get; set; }
|
||||
|
||||
public uint MusicPlayPauseHotkeyVirtualKey { get; set; }
|
||||
|
||||
public bool MusicNextHotkeyEnabled { get; set; }
|
||||
|
||||
public uint MusicNextHotkeyModifierMask { get; set; }
|
||||
|
||||
public uint MusicNextHotkeyVirtualKey { get; set; }
|
||||
|
||||
public bool MusicPreviousHotkeyEnabled { get; set; }
|
||||
|
||||
public uint MusicPreviousHotkeyModifierMask { get; set; }
|
||||
|
||||
public uint MusicPreviousHotkeyVirtualKey { get; set; }
|
||||
|
||||
public GammaProbeMemory? GammaProbeMemory { get; set; }
|
||||
|
||||
public static void MigrateVibranceOwnership(AppSettings settings)
|
||||
{
|
||||
if (settings.VibranceOwnershipVersion < 1)
|
||||
{
|
||||
settings.VibranceChosenByUser = settings.VibrancePercent.HasValue || settings.Level != 100;
|
||||
settings.VibranceOwnershipVersion = 1;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool ApplyZoomKeyDefault(AppSettings settings)
|
||||
{
|
||||
if (settings.ZoomKeyDefaulted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (settings.ZoomHotkeyVirtualKey == 0 && !ADarkBoostKeyIsTheZoomDefault(settings) && !HotkeyConflicts.Owner(settings, HotkeySlot.Zoom, 0u, 6u).HasValue)
|
||||
{
|
||||
settings.ZoomHotkeyModifierMask = 0u;
|
||||
settings.ZoomHotkeyVirtualKey = 6u;
|
||||
}
|
||||
settings.ZoomKeyDefaulted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool ADarkBoostKeyIsTheZoomDefault(AppSettings s)
|
||||
{
|
||||
if (s.NightVisionHotkeyVirtualKey != 6 || s.NightVisionHotkeyModifierMask != 0)
|
||||
{
|
||||
if (s.DarkBoostNextKeyVirtualKey == 6)
|
||||
{
|
||||
return s.DarkBoostNextKeyModifierMask == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal bool HoldsTheNextSetupKey(uint mask, uint vk)
|
||||
{
|
||||
if (DarkBoostNextKeyVirtualKey == vk)
|
||||
{
|
||||
return DarkBoostNextKeyModifierMask == mask;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PanelSettings PanelFor(int index)
|
||||
{
|
||||
if (Panels == null)
|
||||
{
|
||||
List<PanelSettings> list = (Panels = new List<PanelSettings>());
|
||||
}
|
||||
PanelSettings panelSettings = Panels.FirstOrDefault((PanelSettings p) => p.Index == index);
|
||||
if (panelSettings != null)
|
||||
{
|
||||
return panelSettings;
|
||||
}
|
||||
panelSettings = new PanelSettings
|
||||
{
|
||||
Index = index
|
||||
};
|
||||
Panels.Add(panelSettings);
|
||||
return panelSettings;
|
||||
}
|
||||
|
||||
public PanelSettings PanelFor(string key, int index, IReadOnlyCollection<string>? connectedKeys = null)
|
||||
{
|
||||
if (Panels == null)
|
||||
{
|
||||
List<PanelSettings> list = (Panels = new List<PanelSettings>());
|
||||
}
|
||||
PanelSettings panelSettings = Panels.FirstOrDefault((PanelSettings p) => p.Key == key);
|
||||
if (panelSettings != null)
|
||||
{
|
||||
panelSettings.Index = index;
|
||||
return panelSettings;
|
||||
}
|
||||
string desc = Desc(key);
|
||||
if (desc.Length > 0 && connectedKeys != null && Enumerable.Count(connectedKeys, (string k) => Desc(k) == desc) <= 1)
|
||||
{
|
||||
List<PanelSettings> list3 = Panels.Where((PanelSettings p) => p.Key.Length > 0 && Desc(p.Key) == desc && !connectedKeys.Contains(p.Key)).ToList();
|
||||
if (list3.Count == 1)
|
||||
{
|
||||
PanelSettings panelSettings2 = list3[0];
|
||||
panelSettings2.Key = key;
|
||||
panelSettings2.Index = index;
|
||||
return panelSettings2;
|
||||
}
|
||||
}
|
||||
PanelSettings panelSettings3 = Panels.FirstOrDefault((PanelSettings p) => p.Key.Length == 0 && p.Index == index);
|
||||
if (panelSettings3 != null)
|
||||
{
|
||||
panelSettings3.Key = key;
|
||||
return panelSettings3;
|
||||
}
|
||||
PanelSettings panelSettings4 = new PanelSettings
|
||||
{
|
||||
Index = index,
|
||||
Key = key
|
||||
};
|
||||
Panels.Add(panelSettings4);
|
||||
return panelSettings4;
|
||||
static string Desc(string k)
|
||||
{
|
||||
int num = k.LastIndexOf('|');
|
||||
if (num < 0)
|
||||
{
|
||||
return k;
|
||||
}
|
||||
return k.Substring(num + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class AppStatus
|
||||
{
|
||||
public Version? MinimumVersion { get; init; }
|
||||
|
||||
public IReadOnlyList<string> BlockedFlavours { get; init; } = Array.Empty<string>();
|
||||
|
||||
public string Message { get; init; } = "";
|
||||
|
||||
public string MessageId { get; init; } = "";
|
||||
|
||||
public string MessageUrl { get; init; } = "";
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class AppStatusService
|
||||
{
|
||||
private static string StatusUrl => ActivationEndpoint.StatusUrlFor("store");
|
||||
|
||||
private static string CacheDir => AppFolders.Local;
|
||||
|
||||
private static string CachePath => Path.Combine(CacheDir, "app-status-cache.json");
|
||||
|
||||
public static AppStatus? LastFetched { get; private set; }
|
||||
|
||||
private static AppStatus ReadCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(CachePath))
|
||||
{
|
||||
return new AppStatus();
|
||||
}
|
||||
return VersionGate.Parse(File.ReadAllText(CachePath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new AppStatus();
|
||||
}
|
||||
}
|
||||
|
||||
public static Version? CachedMinimum()
|
||||
{
|
||||
return ReadCache().MinimumVersion;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> CachedBlockedFlavours()
|
||||
{
|
||||
return ReadCache().BlockedFlavours;
|
||||
}
|
||||
|
||||
public static string CachedMessage()
|
||||
{
|
||||
return ReadCache().Message;
|
||||
}
|
||||
|
||||
public static bool ThisBuildIsBlocked()
|
||||
{
|
||||
AppStatus appStatus = ReadCache();
|
||||
return VersionGate.IsBlocked(UpdateService.CurrentVersion, appStatus.MinimumVersion, "store", appStatus.BlockedFlavours);
|
||||
}
|
||||
|
||||
public static bool ThisBuildIsBlockedByVersion()
|
||||
{
|
||||
return VersionGate.IsBlocked(UpdateService.CurrentVersion, ReadCache().MinimumVersion);
|
||||
}
|
||||
|
||||
public static async Task<Version?> RefreshAsync()
|
||||
{
|
||||
AppStatus cache = ReadCache();
|
||||
Version cached = cache.MinimumVersion;
|
||||
Version fetched = null;
|
||||
IReadOnlyList<string> fetchedFlavours = Array.Empty<string>();
|
||||
string message = "";
|
||||
try
|
||||
{
|
||||
using HttpClient client = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10.0)
|
||||
};
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(UpdateService.UpdaterUserAgent);
|
||||
AppStatus appStatus = VersionGate.Parse(await client.GetStringAsync(StatusUrl));
|
||||
fetched = appStatus.MinimumVersion;
|
||||
fetchedFlavours = appStatus.BlockedFlavours;
|
||||
message = appStatus.Message;
|
||||
LastFetched = appStatus;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
Version version = VersionGate.Resolve(fetched, cached);
|
||||
IReadOnlyList<string> readOnlyList = VersionGate.ResolveFlavours(fetchedFlavours, cache.BlockedFlavours);
|
||||
bool num = version != null && (cached == null || version > cached);
|
||||
bool flag = readOnlyList.Count > cache.BlockedFlavours.Count;
|
||||
if (num | flag)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(CacheDir);
|
||||
File.WriteAllText(CachePath, VersionGate.Serialize(version, message, readOnlyList));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
public sealed class AudioEdgeService : IDisposable
|
||||
{
|
||||
public enum MeterState
|
||||
{
|
||||
Off,
|
||||
NoReading,
|
||||
Holding,
|
||||
Clear
|
||||
}
|
||||
|
||||
public const int TickMs = 30;
|
||||
|
||||
public const float ExternalChangeTolerance = 0.001f;
|
||||
|
||||
public const int HoldTicks = 20;
|
||||
|
||||
public const float WriteEpsilon = 0.002f;
|
||||
|
||||
private readonly IAudioOutput _output;
|
||||
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
private float _restoreVolume = 1f;
|
||||
|
||||
private float _lastWritten = float.NaN;
|
||||
|
||||
private readonly float[] _recentPeaks = new float[20];
|
||||
|
||||
private int _nextPeak;
|
||||
|
||||
internal int WriteCount { get; private set; }
|
||||
|
||||
public float Threshold { get; set; } = 0.3f;
|
||||
|
||||
public bool IsRunning => _cts != null;
|
||||
|
||||
public float Peak => _output.Peak;
|
||||
|
||||
public float CurrentVolume => _output.Volume;
|
||||
|
||||
public float RestoreVolume => _restoreVolume;
|
||||
|
||||
public MeterState Meter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsRunning)
|
||||
{
|
||||
return MeterState.Off;
|
||||
}
|
||||
float currentVolume = CurrentVolume;
|
||||
float restoreVolume = _restoreVolume;
|
||||
if (float.IsNaN(currentVolume) || float.IsNaN(restoreVolume))
|
||||
{
|
||||
return MeterState.NoReading;
|
||||
}
|
||||
if (!(currentVolume < restoreVolume - 0.01f))
|
||||
{
|
||||
return MeterState.Clear;
|
||||
}
|
||||
return MeterState.Holding;
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<float>? OnRestorePointCaptured;
|
||||
|
||||
public event Action? OnRestoreCompleted;
|
||||
|
||||
public AudioEdgeService(IAudioOutput output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Start(runLoop: true);
|
||||
}
|
||||
|
||||
internal void StartWithoutLoopForTest()
|
||||
{
|
||||
Start(runLoop: false);
|
||||
}
|
||||
|
||||
private void Start(bool runLoop)
|
||||
{
|
||||
if (IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float f = (_restoreVolume = _output.Volume);
|
||||
_lastWritten = float.NaN;
|
||||
Array.Clear(_recentPeaks);
|
||||
_nextPeak = 0;
|
||||
if (!float.IsNaN(f))
|
||||
{
|
||||
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||
}
|
||||
_cts = new CancellationTokenSource();
|
||||
CancellationToken token = _cts.Token;
|
||||
if (!runLoop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
Tick();
|
||||
await Task.Delay(30, token);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!float.IsNaN(_restoreVolume))
|
||||
{
|
||||
_output.Volume = _restoreVolume;
|
||||
}
|
||||
OnRestoreCompleted?.Invoke();
|
||||
}
|
||||
}, token);
|
||||
}
|
||||
|
||||
public void ForceRestore(float volume)
|
||||
{
|
||||
_output.Volume = Math.Clamp(volume, 0f, 1f);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
float volume = _output.Volume;
|
||||
if (float.IsNaN(volume))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (float.IsNaN(_restoreVolume))
|
||||
{
|
||||
_restoreVolume = volume;
|
||||
_lastWritten = float.NaN;
|
||||
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||
}
|
||||
if (!float.IsNaN(_lastWritten))
|
||||
{
|
||||
float num = volume - _lastWritten;
|
||||
if (MathF.Abs(num) > 0.001f)
|
||||
{
|
||||
_restoreVolume = Math.Clamp(_restoreVolume + num, 0.05f, 1f);
|
||||
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||
}
|
||||
}
|
||||
_recentPeaks[_nextPeak] = _output.Peak;
|
||||
_nextPeak = (_nextPeak + 1) % _recentPeaks.Length;
|
||||
float num2 = 0f;
|
||||
float[] recentPeaks = _recentPeaks;
|
||||
foreach (float y in recentPeaks)
|
||||
{
|
||||
num2 = MathF.Max(num2, y);
|
||||
}
|
||||
float num3 = AudioLimiter.NextVolume(num2, Threshold, volume, _restoreVolume);
|
||||
if (MathF.Abs(num3 - volume) > 0.002f)
|
||||
{
|
||||
float volume2 = _output.Volume;
|
||||
if (!float.IsNaN(volume2))
|
||||
{
|
||||
if (MathF.Abs(volume2 - volume) > 0.001f)
|
||||
{
|
||||
_restoreVolume = Math.Clamp(_restoreVolume + (volume2 - volume), 0.05f, 1f);
|
||||
_lastWritten = volume2;
|
||||
OnRestorePointCaptured?.Invoke(_restoreVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
_output.Volume = num3;
|
||||
_lastWritten = _output.Volume;
|
||||
WriteCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastWritten = volume;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
CancellationTokenSource cts = _cts;
|
||||
_cts = null;
|
||||
if (cts != null)
|
||||
{
|
||||
cts.Cancel();
|
||||
cts.Dispose();
|
||||
if (!float.IsNaN(_restoreVolume))
|
||||
{
|
||||
_output.Volume = _restoreVolume;
|
||||
}
|
||||
_lastWritten = float.NaN;
|
||||
OnRestoreCompleted?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Stop();
|
||||
(_output as IDisposable)?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
public static class AudioLimiter
|
||||
{
|
||||
public const float MinVolume = 0.05f;
|
||||
|
||||
public const float DefaultAttack = 0.5f;
|
||||
|
||||
public const float DefaultRelease = 0.3f;
|
||||
|
||||
public static float NextVolume(float peak, float threshold, float currentVolume, float maxVolume, float attack = 0.5f, float release = 0.3f)
|
||||
{
|
||||
float num = ((peak > 0.0001f) ? MathF.Min(maxVolume, threshold / peak) : maxVolume);
|
||||
float num2 = ((num < currentVolume) ? attack : release);
|
||||
return Math.Clamp(currentVolume + (num - currentVolume) * num2, 0.05f, maxVolume);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
internal static class AudioLoopDiagnostic
|
||||
{
|
||||
public static void RunAndPrint()
|
||||
{
|
||||
using WindowsAudioOutput windowsAudioOutput = new WindowsAudioOutput();
|
||||
float volume = windowsAudioOutput.Volume;
|
||||
try
|
||||
{
|
||||
float[] array = new float[3] { 1f, 0.5f, 0.25f };
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
float value = (windowsAudioOutput.Volume = array[i]);
|
||||
Thread.Sleep(500);
|
||||
Console.WriteLine($"Volume {value:P0} -> Peak {windowsAudioOutput.Peak:F3}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
windowsAudioOutput.Volume = volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
public interface IAudioOutput
|
||||
{
|
||||
float Peak { get; }
|
||||
|
||||
float Volume { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
internal sealed class RestorePointSaver
|
||||
{
|
||||
private readonly Action _save;
|
||||
|
||||
private readonly int _quietMs;
|
||||
|
||||
private readonly Func<int, Action, IDisposable> _startTimer;
|
||||
|
||||
private readonly object _gate = new object();
|
||||
|
||||
private IDisposable? _timer;
|
||||
|
||||
private int _generation;
|
||||
|
||||
private bool _dirty;
|
||||
|
||||
public RestorePointSaver(Action save, int quietMs = 400, Func<int, Action, IDisposable>? startTimer = null)
|
||||
{
|
||||
_save = save;
|
||||
_quietMs = quietMs;
|
||||
_startTimer = startTimer ?? new Func<int, Action, IDisposable>(DefaultTimer);
|
||||
}
|
||||
|
||||
public void Captured(float volume, AppSettings settings)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
settings.AudioEdgeRestoreVolume = volume;
|
||||
if (!settings.AudioEdgeRestorePending)
|
||||
{
|
||||
settings.AudioEdgeRestorePending = true;
|
||||
CancelTimer();
|
||||
_dirty = false;
|
||||
_save();
|
||||
return;
|
||||
}
|
||||
_dirty = true;
|
||||
if (_timer == null)
|
||||
{
|
||||
CancelTimer();
|
||||
int gen = _generation;
|
||||
_timer = _startTimer(_quietMs, () =>
|
||||
{
|
||||
OnDue(gen);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Completed(AppSettings settings)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
CancelTimer();
|
||||
_dirty = false;
|
||||
settings.AudioEdgeRestorePending = false;
|
||||
_save();
|
||||
}
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
CancelTimer();
|
||||
if (_dirty)
|
||||
{
|
||||
_dirty = false;
|
||||
_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDue(int generation)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (generation == _generation)
|
||||
{
|
||||
_timer?.Dispose();
|
||||
_timer = null;
|
||||
if (_dirty)
|
||||
{
|
||||
_dirty = false;
|
||||
_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelTimer()
|
||||
{
|
||||
_generation++;
|
||||
_timer?.Dispose();
|
||||
_timer = null;
|
||||
}
|
||||
|
||||
private static IDisposable DefaultTimer(int delayMs, Action callback)
|
||||
{
|
||||
return new Timer((object? _) =>
|
||||
{
|
||||
callback();
|
||||
}, null, delayMs, -1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VibranceHud.Audio;
|
||||
|
||||
public sealed class WindowsAudioOutput : IAudioOutput, IDisposable
|
||||
{
|
||||
[ComImport]
|
||||
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
|
||||
private class MMDeviceEnumerator
|
||||
{
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IMMDeviceEnumerator
|
||||
{
|
||||
[PreserveSig]
|
||||
int EnumAudioEndpoints(int dataFlow, int stateMask, out nint devices);
|
||||
|
||||
[PreserveSig]
|
||||
int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice device);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("D666063F-1587-4E43-81F1-B948E807363F")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IMMDevice
|
||||
{
|
||||
[PreserveSig]
|
||||
int Activate(ref Guid iid, int clsCtx, nint activationParams, [MarshalAs(UnmanagedType.IUnknown)] out object iface);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IAudioMeterInformation
|
||||
{
|
||||
[PreserveSig]
|
||||
int GetPeakValue(out float peak);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IAudioEndpointVolume
|
||||
{
|
||||
[PreserveSig]
|
||||
int RegisterControlChangeNotify(nint notify);
|
||||
|
||||
[PreserveSig]
|
||||
int UnregisterControlChangeNotify(nint notify);
|
||||
|
||||
[PreserveSig]
|
||||
int GetChannelCount(out uint count);
|
||||
|
||||
[PreserveSig]
|
||||
int SetMasterVolumeLevel(float level, ref Guid eventContext);
|
||||
|
||||
[PreserveSig]
|
||||
int SetMasterVolumeLevelScalar(float level, ref Guid eventContext);
|
||||
|
||||
[PreserveSig]
|
||||
int GetMasterVolumeLevel(out float level);
|
||||
|
||||
[PreserveSig]
|
||||
int GetMasterVolumeLevelScalar(out float level);
|
||||
}
|
||||
|
||||
private const int ERender = 0;
|
||||
|
||||
private const int EConsole = 0;
|
||||
|
||||
private const int ClsCtxAll = 23;
|
||||
|
||||
private static Guid _meterIid = new Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064");
|
||||
|
||||
private static Guid _volumeIid = new Guid("5CDF2C82-841E-4546-9722-0CF74078229A");
|
||||
|
||||
private static Guid _noEvent = Guid.Empty;
|
||||
|
||||
private readonly IAudioMeterInformation _meter;
|
||||
|
||||
private readonly IAudioEndpointVolume _volume;
|
||||
|
||||
public float Peak
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
float peak;
|
||||
return (_meter.GetPeakValue(out peak) == 0) ? peak : 0f;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Volume
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
float level;
|
||||
return (_volume.GetMasterVolumeLevelScalar(out level) == 0) ? level : float.NaN;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return float.NaN;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
_volume.SetMasterVolumeLevelScalar(Math.Clamp(value, 0f, 1f), ref _noEvent);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WindowsAudioOutput()
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)new MMDeviceEnumerator()).GetDefaultAudioEndpoint(0, 0, out IMMDevice device));
|
||||
Marshal.ThrowExceptionForHR(device.Activate(ref _meterIid, 23, IntPtr.Zero, out object iface));
|
||||
Marshal.ThrowExceptionForHR(device.Activate(ref _volumeIid, 23, IntPtr.Zero, out object iface2));
|
||||
_meter = (IAudioMeterInformation)iface;
|
||||
_volume = (IAudioEndpointVolume)iface2;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Marshal.IsComObject(_meter))
|
||||
{
|
||||
Marshal.ReleaseComObject(_meter);
|
||||
}
|
||||
if (Marshal.IsComObject(_volume))
|
||||
{
|
||||
Marshal.ReleaseComObject(_volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Updates;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class BackgroundUpdateChecker : IDisposable
|
||||
{
|
||||
internal const int CheckIntervalMs = 7200000;
|
||||
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
private readonly SettingsStore _store;
|
||||
|
||||
private readonly NotifyIcon _trayIcon;
|
||||
|
||||
private readonly System.Windows.Forms.Timer _timer;
|
||||
|
||||
private readonly Task? _startupUpdateStep;
|
||||
|
||||
private bool _isRunning;
|
||||
|
||||
private int _ticksBegun;
|
||||
|
||||
private int _manifestChecks;
|
||||
|
||||
internal int TicksBegun => Volatile.Read(in _ticksBegun);
|
||||
|
||||
internal int ManifestChecks => Volatile.Read(in _manifestChecks);
|
||||
|
||||
internal Func<bool> SafeNowCheck { get; set; } = SafeToRestart.IsNow;
|
||||
|
||||
internal static bool ShouldTick(FlavourPolicy policy)
|
||||
{
|
||||
return policy.SelfUpdates;
|
||||
}
|
||||
|
||||
public BackgroundUpdateChecker(AppSettings settings, SettingsStore store, NotifyIcon trayIcon, Task? startupUpdateStep = null)
|
||||
{
|
||||
_settings = settings;
|
||||
_store = store;
|
||||
_trayIcon = trayIcon;
|
||||
_startupUpdateStep = startupUpdateStep;
|
||||
_timer = new System.Windows.Forms.Timer
|
||||
{
|
||||
Interval = 7200000
|
||||
};
|
||||
_timer.Tick += async (object? s, EventArgs e) =>
|
||||
{
|
||||
await TickAsync();
|
||||
};
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_timer.Start();
|
||||
FirstTickAsync();
|
||||
}
|
||||
|
||||
internal async Task FirstTickAsync()
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
if (_startupUpdateStep != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _startupUpdateStep;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
await TickAsync();
|
||||
}
|
||||
|
||||
private async Task TickAsync()
|
||||
{
|
||||
Interlocked.Increment(ref _ticksBegun);
|
||||
if (!ShouldTick(FlavourPolicy.Current) || _isRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_isRunning = true;
|
||||
try
|
||||
{
|
||||
if (!RemoteSwitches.IsOn("updates") || UpdateService.InstallerStartedThisRun)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(_settings.PendingUpdateVersion))
|
||||
{
|
||||
await InstallIfNobodyIsBusyAsync();
|
||||
return;
|
||||
}
|
||||
Interlocked.Increment(ref _manifestChecks);
|
||||
ReleaseInfo release = RefusedUpdate.Unless(release: await UpdateService.TryGetSignedUpdateAsync(), settings: _settings);
|
||||
if (!(release == null) && SafeNowCheck())
|
||||
{
|
||||
string text = await UpdateService.DownloadAndStageAsync(release);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
UpdateService.RecordPending?.Invoke(release, text);
|
||||
await InstallIfNobodyIsBusyAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InstallIfNobodyIsBusyAsync()
|
||||
{
|
||||
if (!SafeNowCheck())
|
||||
{
|
||||
return;
|
||||
}
|
||||
string refusedBefore = _settings.UpdateRefusedSha256 + "|" + _settings.UpdateRefusedNoticedSha256;
|
||||
await UpdateService.RunPendingUpdateIfAnyAsync(_settings);
|
||||
if (!(refusedBefore != _settings.UpdateRefusedSha256 + "|" + _settings.UpdateRefusedNoticedSha256))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_store.Save(_settings);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal Task TickForTest()
|
||||
{
|
||||
return TickAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_timer.Stop();
|
||||
_timer.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class BrandAssets
|
||||
{
|
||||
private static readonly Dictionary<string, Image?> _cache = new Dictionary<string, Image>();
|
||||
|
||||
private static readonly object _gate = new object();
|
||||
|
||||
public static readonly object DrawGate = new object();
|
||||
|
||||
public static string LogoResourceName(bool light)
|
||||
{
|
||||
if (!light)
|
||||
{
|
||||
return "logo-horizontal-white.png";
|
||||
}
|
||||
return "logo-horizontal-black.png";
|
||||
}
|
||||
|
||||
public static Image? HorizontalLogo(bool light)
|
||||
{
|
||||
return Load(LogoResourceName(light));
|
||||
}
|
||||
|
||||
public static Image? PresetChip(string art)
|
||||
{
|
||||
return Load("preset-" + art + ".png");
|
||||
}
|
||||
|
||||
private static Image? Load(string resourceName)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_cache.TryGetValue(resourceName, out Image value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
Image image = null;
|
||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (stream != null)
|
||||
{
|
||||
using Image original = Image.FromStream(stream);
|
||||
image = new Bitmap(original);
|
||||
}
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
_cache[resourceName] = image;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class BuildFlavour
|
||||
{
|
||||
public const string Public = "public";
|
||||
|
||||
public const string NightVision = "nightvision";
|
||||
|
||||
public const string NightVisionGift = "nightvision-gift";
|
||||
|
||||
public const string Store = "store";
|
||||
|
||||
public const string Current = "store";
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public static class CapabilityProbe
|
||||
{
|
||||
private sealed class PerDeviceGammaTarget : IPerDeviceGammaProbeTarget
|
||||
{
|
||||
public IReadOnlyList<string> Devices()
|
||||
{
|
||||
return MultiMonitorGammaRamp.Devices();
|
||||
}
|
||||
|
||||
public bool TrySet(string device, ushort[] ramp)
|
||||
{
|
||||
return MultiMonitorGammaRamp.SetRampOn(device, ramp);
|
||||
}
|
||||
|
||||
public ushort[]? TryGet(string device)
|
||||
{
|
||||
return MultiMonitorGammaRamp.ReadRampOn(device);
|
||||
}
|
||||
}
|
||||
|
||||
private struct POINT
|
||||
{
|
||||
public int X;
|
||||
|
||||
public int Y;
|
||||
}
|
||||
|
||||
private sealed class ScreenGammaTarget : IGammaProbeTarget
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern nint GetDC(nint hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int ReleaseDC(nint hWnd, nint hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool SetDeviceGammaRamp(nint hDC, ushort[] ramp);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool GetDeviceGammaRamp(nint hDC, ushort[] ramp);
|
||||
|
||||
public bool TrySet(ushort[] ramp)
|
||||
{
|
||||
nint dC = GetDC(IntPtr.Zero);
|
||||
if (dC == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
return SetDeviceGammaRamp(dC, ramp);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
}
|
||||
}
|
||||
|
||||
public ushort[]? TryGet()
|
||||
{
|
||||
nint dC = GetDC(IntPtr.Zero);
|
||||
if (dC == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
ushort[] array = new ushort[768];
|
||||
return GetDeviceGammaRamp(dC, array) ? array : null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal const int SameCurveTolerance = 512;
|
||||
|
||||
internal const float TestGamma = 6f;
|
||||
|
||||
private const int MONITOR_DEFAULTTONEAREST = 2;
|
||||
|
||||
internal static GammaSupport Classify(ushort[] written, ushort[]? readback, ushort[] identity)
|
||||
{
|
||||
if (readback == null || written.Length == 0 || readback.Length != written.Length)
|
||||
{
|
||||
return GammaSupport.Untested;
|
||||
}
|
||||
double num = MeanAbsoluteDifference(readback, written);
|
||||
double num2 = MeanAbsoluteDifference(readback, identity);
|
||||
if (num <= 512.0)
|
||||
{
|
||||
return GammaSupport.Working;
|
||||
}
|
||||
if (num2 <= 512.0)
|
||||
{
|
||||
return GammaSupport.Refused;
|
||||
}
|
||||
return GammaSupport.Clamped;
|
||||
}
|
||||
|
||||
private static double MeanAbsoluteDifference(ushort[] a, ushort[] b)
|
||||
{
|
||||
long num = 0L;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
num += Math.Abs(a[i] - b[i]);
|
||||
}
|
||||
return (double)num / (double)a.Length;
|
||||
}
|
||||
|
||||
internal static GammaRefusal WhyRefused(GammaSupport result, bool writeAccepted, bool elevated, bool hdrActive, ushort[]? before, ushort[] identity)
|
||||
{
|
||||
if (result != GammaSupport.Refused)
|
||||
{
|
||||
return GammaRefusal.None;
|
||||
}
|
||||
if (hdrActive)
|
||||
{
|
||||
return GammaRefusal.HdrOn;
|
||||
}
|
||||
if (!elevated)
|
||||
{
|
||||
return GammaRefusal.NotElevated;
|
||||
}
|
||||
if (!writeAccepted)
|
||||
{
|
||||
return GammaRefusal.WriteFailed;
|
||||
}
|
||||
if (before != null && before.Length == identity.Length && MeanAbsoluteDifference(before, identity) > 512.0)
|
||||
{
|
||||
return GammaRefusal.RampHeldByOther;
|
||||
}
|
||||
return GammaRefusal.ReadbackIdentity;
|
||||
}
|
||||
|
||||
internal static ushort[] TestRamp()
|
||||
{
|
||||
return GammaCurve.Build(6f);
|
||||
}
|
||||
|
||||
internal static ushort[] GentleRamp()
|
||||
{
|
||||
return GammaCurve.Build(1.15f);
|
||||
}
|
||||
|
||||
private static bool GentleGetsThrough(Func<ushort[], bool> trySet, Func<ushort[]?> tryGet)
|
||||
{
|
||||
ushort[] array = GentleRamp();
|
||||
if (trySet(array))
|
||||
{
|
||||
return Classify(array, tryGet(), GammaCurve.Identity()) == GammaSupport.Working;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static GammaSupport ProbeGamma(IGammaProbeTarget target)
|
||||
{
|
||||
bool couldRead;
|
||||
return ProbeGamma(target, out couldRead);
|
||||
}
|
||||
|
||||
internal static GammaSupport ProbeGamma(IGammaProbeTarget target, out bool couldRead)
|
||||
{
|
||||
couldRead = false;
|
||||
if (target == null)
|
||||
{
|
||||
return GammaSupport.Untested;
|
||||
}
|
||||
ushort[] array = null;
|
||||
try
|
||||
{
|
||||
array = target.TryGet();
|
||||
couldRead = array != null;
|
||||
if (array == null)
|
||||
{
|
||||
return GammaSupport.Refused;
|
||||
}
|
||||
ushort[] array2 = TestRamp();
|
||||
GammaSupport gammaSupport = (target.TrySet(array2) ? Classify(array2, target.TryGet(), GammaCurve.Identity()) : GammaSupport.Refused);
|
||||
if (gammaSupport == GammaSupport.Refused && GentleGetsThrough(target.TrySet, target.TryGet))
|
||||
{
|
||||
return GammaSupport.Clamped;
|
||||
}
|
||||
return gammaSupport;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return GammaSupport.Untested;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (array != null)
|
||||
{
|
||||
target.TrySet(array);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<DeviceGamma> ProbeDevices(IPerDeviceGammaProbeTarget target, bool elevated, bool hdrActive)
|
||||
{
|
||||
bool anyReadable;
|
||||
return ProbeDevices(target, elevated, hdrActive, out anyReadable);
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<DeviceGamma> ProbeDevices(IPerDeviceGammaProbeTarget target, bool elevated, bool hdrActive, out bool anyReadable)
|
||||
{
|
||||
anyReadable = false;
|
||||
List<DeviceGamma> list = new List<DeviceGamma>();
|
||||
if (target == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
IReadOnlyList<string> readOnlyList;
|
||||
try
|
||||
{
|
||||
readOnlyList = target.Devices() ?? Array.Empty<string>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return list;
|
||||
}
|
||||
ushort[] identity = GammaCurve.Identity();
|
||||
foreach (string device in readOnlyList)
|
||||
{
|
||||
ushort[] array = null;
|
||||
try
|
||||
{
|
||||
array = target.TryGet(device);
|
||||
if (array != null)
|
||||
{
|
||||
anyReadable = true;
|
||||
ushort[] array2 = TestRamp();
|
||||
bool flag = target.TrySet(device, array2);
|
||||
ushort[] readback = (flag ? target.TryGet(device) : null);
|
||||
GammaSupport gammaSupport = (flag ? Classify(array2, readback, identity) : GammaSupport.Refused);
|
||||
if (gammaSupport == GammaSupport.Refused && GentleGetsThrough((ushort[] r) => target.TrySet(device, r), () => target.TryGet(device)))
|
||||
{
|
||||
gammaSupport = GammaSupport.Clamped;
|
||||
}
|
||||
list.Add(new DeviceGamma(device, gammaSupport, WhyRefused(gammaSupport, flag, elevated, hdrActive, array, identity)));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(new DeviceGamma(device, GammaSupport.Untested, GammaRefusal.None));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
list.Add(new DeviceGamma(device, GammaSupport.Untested, GammaRefusal.None));
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (array != null)
|
||||
{
|
||||
target.TrySet(device, array);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static MachineCapabilities Run(bool driverVibrance, OverlayMode overlayPath, IGammaProbeTarget? gammaTarget = null, IPerDeviceGammaProbeTarget? perDeviceTarget = null)
|
||||
{
|
||||
GammaProbeMemory measured;
|
||||
return Run(driverVibrance, overlayPath, null, out measured, gammaTarget, perDeviceTarget);
|
||||
}
|
||||
|
||||
public static MachineCapabilities Run(bool driverVibrance, OverlayMode overlayPath, GammaProbeMemory? remembered, out GammaProbeMemory? measured, IGammaProbeTarget? gammaTarget = null, IPerDeviceGammaProbeTarget? perDeviceTarget = null)
|
||||
{
|
||||
measured = null;
|
||||
bool elevated = SafeElevated();
|
||||
bool flag = SafeHdr();
|
||||
IPerDeviceGammaProbeTarget perDeviceGammaProbeTarget = perDeviceTarget ?? new PerDeviceGammaTarget();
|
||||
perDeviceTarget = perDeviceGammaProbeTarget;
|
||||
IReadOnlyList<string> devices;
|
||||
try
|
||||
{
|
||||
devices = perDeviceGammaProbeTarget.Devices() ?? Array.Empty<string>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
devices = Array.Empty<string>();
|
||||
}
|
||||
string key = GammaProbeMemory.KeyFor(devices, elevated, flag, AppInfo.VersionText);
|
||||
if (remembered != null && remembered.Reusable(key))
|
||||
{
|
||||
measured = remembered;
|
||||
return new MachineCapabilities(remembered.Ramp, flag, SafeVendor(), driverVibrance, SafeMonitorCount(), SafeMixedDpi(), elevated, overlayPath, remembered.Why, remembered.Devices);
|
||||
}
|
||||
GammaSupport gammaSupport = GammaSupport.Untested;
|
||||
bool couldRead = false;
|
||||
try
|
||||
{
|
||||
gammaSupport = ProbeGamma(gammaTarget ?? new ScreenGammaTarget(), out couldRead);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
IReadOnlyList<DeviceGamma> readOnlyList = Array.Empty<DeviceGamma>();
|
||||
bool anyReadable = false;
|
||||
try
|
||||
{
|
||||
readOnlyList = ProbeDevices(perDeviceTarget ?? new PerDeviceGammaTarget(), elevated, flag, out anyReadable);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
GammaRefusal gammaRefusal = GammaRefusal.None;
|
||||
foreach (DeviceGamma item in readOnlyList)
|
||||
{
|
||||
if (item.Why != GammaRefusal.None)
|
||||
{
|
||||
gammaRefusal = item.Why;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gammaRefusal == GammaRefusal.None)
|
||||
{
|
||||
gammaRefusal = WhyRefused(gammaSupport, writeAccepted: true, elevated, flag, null, GammaCurve.Identity());
|
||||
}
|
||||
if (gammaSupport == GammaSupport.Refused && !couldRead && !anyReadable)
|
||||
{
|
||||
gammaRefusal = GammaRefusal.ScreenUnreadable;
|
||||
}
|
||||
if (gammaSupport != GammaSupport.Refused)
|
||||
{
|
||||
measured = new GammaProbeMemory(key, gammaSupport, gammaRefusal, new List<DeviceGamma>(readOnlyList));
|
||||
}
|
||||
return new MachineCapabilities(gammaSupport, flag, SafeVendor(), driverVibrance, SafeMonitorCount(), SafeMixedDpi(), elevated, overlayPath, gammaRefusal, readOnlyList);
|
||||
}
|
||||
|
||||
private static bool SafeHdr()
|
||||
{
|
||||
try
|
||||
{
|
||||
return HdrDetection.AnyDisplayInHdr();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static GpuVendor SafeVendor()
|
||||
{
|
||||
try
|
||||
{
|
||||
return GpuDetection.PrimaryVendor();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return GpuVendor.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
private static int SafeMonitorCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Math.Max(1, Screen.AllScreens.Length);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SafeMixedDpi()
|
||||
{
|
||||
try
|
||||
{
|
||||
Screen[] allScreens = Screen.AllScreens;
|
||||
if (allScreens.Length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uint num = DpiOf(allScreens[0]);
|
||||
for (int i = 1; i < allScreens.Length; i++)
|
||||
{
|
||||
if (DpiOf(allScreens[i]) != num)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static uint DpiOf(Screen screen)
|
||||
{
|
||||
if (GetDpiForMonitor(MonitorFromPoint(new POINT
|
||||
{
|
||||
X = screen.Bounds.Left + 1,
|
||||
Y = screen.Bounds.Top + 1
|
||||
}, 2), 0, out var x, out var _) != 0)
|
||||
{
|
||||
return 96u;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private static bool SafeElevated()
|
||||
{
|
||||
try
|
||||
{
|
||||
using WindowsIdentity ntIdentity = WindowsIdentity.GetCurrent();
|
||||
return new WindowsPrincipal(ntIdentity).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern nint MonitorFromPoint(POINT pt, int flags);
|
||||
|
||||
[DllImport("shcore.dll")]
|
||||
private static extern int GetDpiForMonitor(nint monitor, int type, out uint x, out uint y);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public sealed record DeviceGamma(string Device, GammaSupport Result, GammaRefusal Why);
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public sealed record GammaProbeMemory(string Key, GammaSupport Ramp, GammaRefusal Why, List<DeviceGamma> Devices)
|
||||
{
|
||||
internal const string Version = "g1";
|
||||
|
||||
internal static string KeyFor(IEnumerable<string> devices, bool elevated, bool hdr, string appVersion)
|
||||
{
|
||||
return "g1|" + appVersion + "|" + (elevated ? "E" : "e") + (hdr ? "H" : "h") + "|" + string.Join(";", devices.OrderBy((string d) => d, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
internal bool Reusable(string key)
|
||||
{
|
||||
bool flag = Key == key;
|
||||
if (flag)
|
||||
{
|
||||
GammaSupport ramp = Ramp;
|
||||
bool flag2 = (uint)(ramp - 1) <= 1u;
|
||||
flag = flag2;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
return Why != GammaRefusal.ScreenUnreadable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public enum GammaRefusal
|
||||
{
|
||||
None,
|
||||
NotElevated,
|
||||
HdrOn,
|
||||
RampHeldByOther,
|
||||
WriteFailed,
|
||||
ReadbackIdentity,
|
||||
ScreenUnreadable
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public enum GammaSupport
|
||||
{
|
||||
Untested,
|
||||
Working,
|
||||
Clamped,
|
||||
Refused
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using SharpDX.DXGI;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
internal static class GpuDetection
|
||||
{
|
||||
public static GpuVendor PrimaryVendor()
|
||||
{
|
||||
using Factory1 factory = new Factory1();
|
||||
using Adapter1 adapter = factory.GetAdapter1(0);
|
||||
switch (adapter.Description1.VendorId)
|
||||
{
|
||||
case 4318:
|
||||
return GpuVendor.Nvidia;
|
||||
case 4098:
|
||||
case 4130:
|
||||
return GpuVendor.Amd;
|
||||
case 32902:
|
||||
return GpuVendor.Intel;
|
||||
default:
|
||||
return GpuVendor.Other;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public enum GpuVendor
|
||||
{
|
||||
Unknown,
|
||||
Nvidia,
|
||||
Amd,
|
||||
Intel,
|
||||
Other
|
||||
}
|
||||
@@ -0,0 +1,559 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Controls;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
internal static class HdrDetection
|
||||
{
|
||||
private struct DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||
{
|
||||
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||
|
||||
public uint value;
|
||||
}
|
||||
|
||||
private struct LUID
|
||||
{
|
||||
public uint LowPart;
|
||||
|
||||
public int HighPart;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_PATH_SOURCE_INFO
|
||||
{
|
||||
public LUID adapterId;
|
||||
|
||||
public uint id;
|
||||
|
||||
public uint modeInfoIdx;
|
||||
|
||||
public uint statusFlags;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_RATIONAL
|
||||
{
|
||||
public uint Numerator;
|
||||
|
||||
public uint Denominator;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_PATH_TARGET_INFO
|
||||
{
|
||||
public LUID adapterId;
|
||||
|
||||
public uint id;
|
||||
|
||||
public uint modeInfoIdx;
|
||||
|
||||
public uint outputTechnology;
|
||||
|
||||
public uint rotation;
|
||||
|
||||
public uint scaling;
|
||||
|
||||
public DISPLAYCONFIG_RATIONAL refreshRate;
|
||||
|
||||
public uint scanLineOrdering;
|
||||
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool targetAvailable;
|
||||
|
||||
public uint statusFlags;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_PATH_INFO
|
||||
{
|
||||
public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
|
||||
|
||||
public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
|
||||
|
||||
public uint flags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 64)]
|
||||
private struct DISPLAYCONFIG_MODE_INFO
|
||||
{
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
public int type;
|
||||
|
||||
public int size;
|
||||
|
||||
public LUID adapterId;
|
||||
|
||||
public uint id;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||
{
|
||||
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||
|
||||
public uint value;
|
||||
|
||||
public uint colorEncoding;
|
||||
|
||||
public int bitsPerColorChannel;
|
||||
}
|
||||
|
||||
private struct DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2
|
||||
{
|
||||
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||
|
||||
public uint value;
|
||||
|
||||
public uint colorEncoding;
|
||||
|
||||
public uint bitsPerColorChannel;
|
||||
|
||||
public uint activeColorMode;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct DISPLAYCONFIG_SOURCE_DEVICE_NAME
|
||||
{
|
||||
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public string viewGdiDeviceName;
|
||||
}
|
||||
|
||||
private const uint ColorModeWcg = 1u;
|
||||
|
||||
private const uint ColorModeHdr = 2u;
|
||||
|
||||
private const uint QDC_ONLY_ACTIVE_PATHS = 2u;
|
||||
|
||||
private const int DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1;
|
||||
|
||||
private const int DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9;
|
||||
|
||||
private const int DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10;
|
||||
|
||||
private const int DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2 = 15;
|
||||
|
||||
private const int DISPLAYCONFIG_DEVICE_INFO_SET_HDR_STATE = 16;
|
||||
|
||||
public static bool AnyDisplayInHdr()
|
||||
{
|
||||
return AnyDisplayInHdr(ActivePaths(), AdvancedColourOf);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<HdrDisplay> Report()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Report(ActivePaths(), AdvancedColourOf, SourceNameOf);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<HdrDisplay>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool AnyDisplayInHdr<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour)
|
||||
{
|
||||
return Displays(paths, advancedColour, (TPath _) => "", includeNames: false).Any((HdrDisplay d) => d.Enabled);
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<HdrDisplay> Report<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour, Func<TPath, string> sourceName)
|
||||
{
|
||||
return Displays(paths, advancedColour, sourceName, includeNames: true).ToList();
|
||||
}
|
||||
|
||||
private static IEnumerable<HdrDisplay> Displays<TPath>(IReadOnlyList<TPath>? paths, Func<TPath, (uint Flags, int BitsPerColorChannel)?> advancedColour, Func<TPath, string> sourceName, bool includeNames)
|
||||
{
|
||||
if (paths == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
foreach (TPath path in paths)
|
||||
{
|
||||
(uint, int)? tuple = advancedColour(path);
|
||||
if (tuple.HasValue)
|
||||
{
|
||||
(uint, int) valueOrDefault = tuple.GetValueOrDefault();
|
||||
string device = (includeNames ? sourceName(path) : "");
|
||||
bool supported = (valueOrDefault.Item1 & 1) != 0;
|
||||
bool enabled = (valueOrDefault.Item1 & 2) != 0 && (valueOrDefault.Item1 & 4) == 0;
|
||||
int item = valueOrDefault.Item2;
|
||||
yield return new HdrDisplay(device, supported, enabled, (item > 0 && item < 64) ? valueOrDefault.Item2 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static (uint Flags, int BitsPerColorChannel) FromAdvancedColorInfo2(uint value, uint activeColorMode, int bitsPerColorChannel)
|
||||
{
|
||||
uint num = 0u;
|
||||
if ((value & 0x10) != 0)
|
||||
{
|
||||
num |= 1;
|
||||
}
|
||||
switch (activeColorMode)
|
||||
{
|
||||
case 2u:
|
||||
num |= 2;
|
||||
break;
|
||||
case 1u:
|
||||
num |= 6;
|
||||
break;
|
||||
}
|
||||
return (Flags: num, BitsPerColorChannel: bitsPerColorChannel);
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<(string Device, uint Value, uint Mode)>? RawInfo2ForTest()
|
||||
{
|
||||
IReadOnlyList<DISPLAYCONFIG_PATH_INFO> readOnlyList = ActivePaths();
|
||||
if (readOnlyList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<(string, uint, uint)> list = new List<(string, uint, uint)>();
|
||||
foreach (DISPLAYCONFIG_PATH_INFO item in readOnlyList)
|
||||
{
|
||||
(uint, uint, uint)? tuple = ReadInfo2(item);
|
||||
if (tuple.HasValue)
|
||||
{
|
||||
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||
list.Add((SourceNameOf(item), valueOrDefault.Item1, valueOrDefault.Item2));
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<int> PickPaths(IReadOnlyList<string> sourceNames, string? device)
|
||||
{
|
||||
List<int> list = new List<int>();
|
||||
if (string.IsNullOrEmpty(device))
|
||||
{
|
||||
return list;
|
||||
}
|
||||
for (int i = 0; i < sourceNames.Count; i++)
|
||||
{
|
||||
if (string.Equals(sourceNames[i], device, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
list.Add(i);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
internal static bool AllColouredDisplaysInHdr(IReadOnlyList<string> coloured, IReadOnlyList<HdrDisplay> report)
|
||||
{
|
||||
if (coloured.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (string device in coloured)
|
||||
{
|
||||
if (!report.Any((HdrDisplay d) => d.Enabled && string.Equals(d.Device, device, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AllColouredDisplaysInHdr()
|
||||
{
|
||||
try
|
||||
{
|
||||
return AllColouredDisplaysInHdr(MultiMonitorGammaRamp.Devices(), Report());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool? IsHdrOn(string? gdiDeviceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
string b = ResolveDevice(gdiDeviceName);
|
||||
foreach (HdrDisplay item in Report())
|
||||
{
|
||||
if (string.Equals(item.Device, b, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return item.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string? ResolveDevice(string? gdiDeviceName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(gdiDeviceName))
|
||||
{
|
||||
return gdiDeviceName;
|
||||
}
|
||||
return Screen.PrimaryScreen?.DeviceName;
|
||||
}
|
||||
|
||||
internal static HdrSwitchOutcome SwitchWithRevert(bool enabled, string? device, Func<string?, bool?> isHdrOn, Func<bool, string?, bool> set, Func<bool> keep)
|
||||
{
|
||||
bool? flag = isHdrOn(device);
|
||||
if (flag.HasValue)
|
||||
{
|
||||
bool valueOrDefault = flag == true;
|
||||
if (valueOrDefault == enabled)
|
||||
{
|
||||
return HdrSwitchOutcome.Unchanged;
|
||||
}
|
||||
if (!set(enabled, device))
|
||||
{
|
||||
return HdrSwitchOutcome.Failed;
|
||||
}
|
||||
if (isHdrOn(device) != enabled)
|
||||
{
|
||||
set(valueOrDefault, device);
|
||||
return HdrSwitchOutcome.Failed;
|
||||
}
|
||||
if (keep())
|
||||
{
|
||||
return HdrSwitchOutcome.Kept;
|
||||
}
|
||||
if (!set(valueOrDefault, device))
|
||||
{
|
||||
return HdrSwitchOutcome.Failed;
|
||||
}
|
||||
return HdrSwitchOutcome.Reverted;
|
||||
}
|
||||
return HdrSwitchOutcome.Failed;
|
||||
}
|
||||
|
||||
internal static HdrSwitchOutcome SwitchWithRevertReal(bool enabled, string? device, TimeSpan grace)
|
||||
{
|
||||
string name = ResolveDevice(device) ?? "";
|
||||
return SwitchWithRevert(enabled, name, IsHdrOn, TrySetHdr, () =>
|
||||
{
|
||||
bool confirmed = false;
|
||||
using RevertConfirmForm revertConfirmForm = new RevertConfirmForm($"HDR is now {(enabled ? "on" : "off")} for {name}.", Math.Max(1, (int)Math.Ceiling(grace.TotalSeconds)));
|
||||
revertConfirmForm.Confirmed += () =>
|
||||
{
|
||||
confirmed = true;
|
||||
};
|
||||
revertConfirmForm.ShowDialog();
|
||||
return confirmed;
|
||||
});
|
||||
}
|
||||
|
||||
private static IReadOnlyList<DISPLAYCONFIG_PATH_INFO>? ActivePaths()
|
||||
{
|
||||
if (GetDisplayConfigBufferSizes(2u, out var pathCount, out var modeCount) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
DISPLAYCONFIG_PATH_INFO[] array = new DISPLAYCONFIG_PATH_INFO[pathCount];
|
||||
DISPLAYCONFIG_MODE_INFO[] modes = new DISPLAYCONFIG_MODE_INFO[modeCount];
|
||||
if (QueryDisplayConfig(2u, ref pathCount, array, ref modeCount, modes, IntPtr.Zero) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ArraySegment<DISPLAYCONFIG_PATH_INFO>(array, 0, (int)pathCount);
|
||||
}
|
||||
|
||||
private static (uint Flags, int BitsPerColorChannel)? AdvancedColourOf(DISPLAYCONFIG_PATH_INFO path)
|
||||
{
|
||||
(uint, uint, uint)? tuple = ReadInfo2(path);
|
||||
if (tuple.HasValue)
|
||||
{
|
||||
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||
return FromAdvancedColorInfo2(valueOrDefault.Item1, valueOrDefault.Item2, (int)valueOrDefault.Item3);
|
||||
}
|
||||
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||
{
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
type = 9,
|
||||
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO>(),
|
||||
adapterId = path.targetInfo.adapterId,
|
||||
id = path.targetInfo.id
|
||||
}
|
||||
};
|
||||
if (DisplayConfigGetDeviceInfo(ref info) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (info.value, info.bitsPerColorChannel);
|
||||
}
|
||||
|
||||
private static (uint Value, uint Mode, uint Bits)? ReadInfo2(DISPLAYCONFIG_PATH_INFO path)
|
||||
{
|
||||
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 info = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2
|
||||
{
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
type = 15,
|
||||
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2>(),
|
||||
adapterId = path.targetInfo.adapterId,
|
||||
id = path.targetInfo.id
|
||||
}
|
||||
};
|
||||
if (DisplayConfigGetDeviceInfo(ref info) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (info.value, info.activeColorMode, info.bitsPerColorChannel);
|
||||
}
|
||||
|
||||
private static string SourceNameOf(DISPLAYCONFIG_PATH_INFO path)
|
||||
{
|
||||
try
|
||||
{
|
||||
DISPLAYCONFIG_SOURCE_DEVICE_NAME info = new DISPLAYCONFIG_SOURCE_DEVICE_NAME
|
||||
{
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
type = 1,
|
||||
size = Marshal.SizeOf<DISPLAYCONFIG_SOURCE_DEVICE_NAME>(),
|
||||
adapterId = path.sourceInfo.adapterId,
|
||||
id = path.sourceInfo.id
|
||||
}
|
||||
};
|
||||
return (DisplayConfigGetDeviceInfo(ref info) == 0) ? (info.viewGdiDeviceName ?? "").TrimEnd('\0') : "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TrySetHdr(bool enabled, string? gdiDeviceName)
|
||||
{
|
||||
IReadOnlyList<DISPLAYCONFIG_PATH_INFO> readOnlyList = ActivePaths();
|
||||
if (readOnlyList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IReadOnlyList<int> readOnlyList2 = PickPaths(readOnlyList.Select(SourceNameOf).ToList(), ResolveDevice(gdiDeviceName));
|
||||
if (readOnlyList2.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool result = false;
|
||||
foreach (int item in readOnlyList2)
|
||||
{
|
||||
DISPLAYCONFIG_PATH_INFO path = readOnlyList[item];
|
||||
(uint, uint, uint)? tuple = ReadInfo2(path);
|
||||
if (tuple.HasValue)
|
||||
{
|
||||
(uint, uint, uint) valueOrDefault = tuple.GetValueOrDefault();
|
||||
if ((valueOrDefault.Item1 & 0x10) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (valueOrDefault.Item2 == 2 == enabled)
|
||||
{
|
||||
result = true;
|
||||
continue;
|
||||
}
|
||||
DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info = new DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||
{
|
||||
header = SetHeader(16, path),
|
||||
value = (enabled ? 1u : 0u)
|
||||
};
|
||||
if (DisplayConfigSetDeviceInfo(ref info) != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
tuple = ReadInfo2(path);
|
||||
if (tuple.HasValue && tuple.GetValueOrDefault().Item2 == 2 == enabled)
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info2 = new DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO
|
||||
{
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
type = 9,
|
||||
size = Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO>(),
|
||||
adapterId = path.targetInfo.adapterId,
|
||||
id = path.targetInfo.id
|
||||
}
|
||||
};
|
||||
if (DisplayConfigGetDeviceInfo(ref info2) != 0 || (info2.value & 1) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (((info2.value & 2) != 0 && (info2.value & 4) == 0) == enabled)
|
||||
{
|
||||
result = true;
|
||||
continue;
|
||||
}
|
||||
DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info3 = new DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE
|
||||
{
|
||||
header = SetHeader(10, path),
|
||||
value = (enabled ? 1u : 0u)
|
||||
};
|
||||
if (DisplayConfigSetDeviceInfo(ref info3) == 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DISPLAYCONFIG_DEVICE_INFO_HEADER SetHeader(int type, DISPLAYCONFIG_PATH_INFO path)
|
||||
{
|
||||
return new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
type = type,
|
||||
size = Marshal.SizeOf<DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE>(),
|
||||
adapterId = path.targetInfo.adapterId,
|
||||
id = path.targetInfo.id
|
||||
};
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int DisplayConfigSetDeviceInfo(ref DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE info);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int GetDisplayConfigBufferSizes(uint flags, out uint pathCount, out uint modeCount);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int QueryDisplayConfig(uint flags, ref uint pathCount, [Out] DISPLAYCONFIG_PATH_INFO[] paths, ref uint modeCount, [Out] DISPLAYCONFIG_MODE_INFO[] modes, nint currentTopologyId);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO info);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_SOURCE_DEVICE_NAME info);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2 info);
|
||||
|
||||
internal static (int Target, int Path) MarshalledSizesForTest()
|
||||
{
|
||||
return (Target: Marshal.SizeOf<DISPLAYCONFIG_PATH_TARGET_INFO>(), Path: Marshal.SizeOf<DISPLAYCONFIG_PATH_INFO>());
|
||||
}
|
||||
|
||||
internal static int SourceNameSizeForTest()
|
||||
{
|
||||
return Marshal.SizeOf<DISPLAYCONFIG_SOURCE_DEVICE_NAME>();
|
||||
}
|
||||
|
||||
internal static int AdvancedColorInfo2SizeForTest()
|
||||
{
|
||||
return Marshal.SizeOf<DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO_2>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public readonly record struct HdrDisplay(string Device, bool Supported, bool Enabled, int BitsPerChannel);
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public enum HdrSwitchOutcome
|
||||
{
|
||||
Failed,
|
||||
Unchanged,
|
||||
Kept,
|
||||
Reverted
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public static class HdrWords
|
||||
{
|
||||
private const string Method = "PlexusX reads Windows' own advanced colour setting for each display";
|
||||
|
||||
public static string DetectionLine(IReadOnlyList<HdrDisplay> displays, bool coloursLimited = true)
|
||||
{
|
||||
if (displays == null || displays.Count == 0)
|
||||
{
|
||||
return "PlexusX couldn't read HDR from Windows on this PC.";
|
||||
}
|
||||
List<HdrDisplay> list = displays.Where((HdrDisplay d) => d.Enabled).ToList();
|
||||
if (list.Count != 0)
|
||||
{
|
||||
if (coloursLimited)
|
||||
{
|
||||
return $"HDR is on for {Names(list)}, which is why screen-colour changes are limited there. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||
}
|
||||
return $"HDR is on for {Names(list)}. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||
}
|
||||
return $"HDR is off on {Names(displays)}. {"PlexusX reads Windows' own advanced colour setting for each display"}.";
|
||||
}
|
||||
|
||||
private static string Names(IReadOnlyList<HdrDisplay> displays)
|
||||
{
|
||||
List<string> list = displays.Select((HdrDisplay d) => (!string.IsNullOrWhiteSpace(d.Device)) ? d.Device : "an unnamed display").ToList();
|
||||
if (list.Count == 1)
|
||||
{
|
||||
return list[0];
|
||||
}
|
||||
return string.Join(", ", list.Take(list.Count - 1)) + " and " + list[list.Count - 1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public interface IGammaProbeTarget
|
||||
{
|
||||
bool TrySet(ushort[] ramp);
|
||||
|
||||
ushort[]? TryGet();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public interface IPerDeviceGammaProbeTarget
|
||||
{
|
||||
IReadOnlyList<string> Devices();
|
||||
|
||||
bool TrySet(string device, ushort[] ramp);
|
||||
|
||||
ushort[]? TryGet(string device);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public static class Machine
|
||||
{
|
||||
public static MachineCapabilities Current { get; private set; } = MachineCapabilities.Unknown;
|
||||
|
||||
public static void Measure(bool driverVibrance, OverlayMode overlayPath)
|
||||
{
|
||||
Current = CapabilityProbe.Run(driverVibrance, overlayPath);
|
||||
}
|
||||
|
||||
public static bool MeasureOrReuse(bool driverVibrance, OverlayMode overlayPath, AppSettings settings)
|
||||
{
|
||||
Current = CapabilityProbe.Run(driverVibrance, overlayPath, settings.GammaProbeMemory, out GammaProbeMemory measured);
|
||||
if (measured == null || object.Equals(measured, settings.GammaProbeMemory))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
settings.GammaProbeMemory = measured;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool MeasureAndRemember(bool driverVibrance, OverlayMode overlayPath, AppSettings settings)
|
||||
{
|
||||
Current = CapabilityProbe.Run(driverVibrance, overlayPath, null, out GammaProbeMemory measured);
|
||||
if (measured == null || object.Equals(measured, settings.GammaProbeMemory))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
settings.GammaProbeMemory = measured;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void OverrideForTests(MachineCapabilities caps)
|
||||
{
|
||||
Current = caps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public sealed record MachineCapabilities(GammaSupport GammaRamp = GammaSupport.Untested, bool HdrActive = false, GpuVendor Gpu = GpuVendor.Unknown, bool DriverVibrance = false, int MonitorCount = 1, bool MixedDpi = false, bool Elevated = false, OverlayMode OverlayPath = OverlayMode.Mag, GammaRefusal RefusedWhy = GammaRefusal.None, IReadOnlyList<DeviceGamma>? PerDeviceGamma = null)
|
||||
{
|
||||
public static MachineCapabilities Unknown => new MachineCapabilities();
|
||||
|
||||
public IReadOnlyList<DeviceGamma> Devices => PerDeviceGamma ?? Array.Empty<DeviceGamma>();
|
||||
|
||||
public bool ToneControlsWork
|
||||
{
|
||||
get
|
||||
{
|
||||
GammaSupport gammaRamp = GammaRamp;
|
||||
if ((uint)(gammaRamp - 1) <= 1u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public string ToneLimitation
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (GammaRamp)
|
||||
{
|
||||
case GammaSupport.Refused:
|
||||
{
|
||||
if (HdrActive)
|
||||
{
|
||||
return "HDR is on, and Windows ignores screen-colour changes while it is. Turn HDR off to use these.";
|
||||
}
|
||||
if (RefusedWhy == GammaRefusal.ScreenUnreadable)
|
||||
{
|
||||
return "PlexusX couldn't find your screen when it started - maybe the monitor was off. Restart PlexusX with the screen on to use these. Saturation above works either way.";
|
||||
}
|
||||
if (!Elevated)
|
||||
{
|
||||
return "Windows is blocking screen-colour changes because PlexusX is not running as administrator. Settings has a Fix this button that restarts it properly. Saturation above works either way.";
|
||||
}
|
||||
if (Gpu == GpuVendor.Nvidia)
|
||||
{
|
||||
return "Your NVIDIA driver is refusing screen-colour changes. Something else is usually holding them - Windows Night light, f.lux, or NVIDIA Freestyle. Close those and reopen PlexusX. Saturation above works either way.";
|
||||
}
|
||||
GpuVendor gpu = Gpu;
|
||||
if ((uint)(gpu - 2) <= 1u)
|
||||
{
|
||||
return "Your graphics driver is refusing screen-colour changes. Check for a colour or night-light setting in your GPU control panel, and close anything else that tints the screen. Saturation above works either way.";
|
||||
}
|
||||
return "Your graphics driver is refusing screen-colour changes, so these won't do anything. Saturation and vibrance above still work.";
|
||||
}
|
||||
case GammaSupport.Clamped:
|
||||
if (HdrActive)
|
||||
{
|
||||
return "HDR is on, so Windows is limiting these. They'll work, but weaker than the numbers suggest.";
|
||||
}
|
||||
return "Windows is limiting how far these can go on this PC, so they'll be weaker than the numbers suggest.";
|
||||
case GammaSupport.Untested:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
internal static class RemeasurePolicy
|
||||
{
|
||||
internal const int MaxTries = 3;
|
||||
|
||||
internal static bool ShouldRemeasure(MachineCapabilities current, int triesSoFar)
|
||||
{
|
||||
if (current.GammaRamp != GammaSupport.Refused)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (current.RefusedWhy != GammaRefusal.ScreenUnreadable)
|
||||
{
|
||||
return triesSoFar < 1;
|
||||
}
|
||||
return triesSoFar < 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public static class Repair
|
||||
{
|
||||
public static string RelaunchArguments => "--relaunch";
|
||||
|
||||
public static RepairKind Plan(MachineCapabilities caps)
|
||||
{
|
||||
return Plan(caps, FlavourPolicy.Current);
|
||||
}
|
||||
|
||||
public static RepairKind Plan(MachineCapabilities caps, FlavourPolicy policy)
|
||||
{
|
||||
GammaSupport gammaRamp = caps.GammaRamp;
|
||||
if ((uint)(gammaRamp - 2) > 1u)
|
||||
{
|
||||
return RepairKind.None;
|
||||
}
|
||||
if (caps.HdrActive)
|
||||
{
|
||||
return RepairKind.OpenHdrSettings;
|
||||
}
|
||||
if (caps.RefusedWhy == GammaRefusal.ScreenUnreadable)
|
||||
{
|
||||
return RepairKind.None;
|
||||
}
|
||||
if (!caps.Elevated)
|
||||
{
|
||||
if (!policy.OffersElevation)
|
||||
{
|
||||
return RepairKind.None;
|
||||
}
|
||||
return RepairKind.RestartAsAdministrator;
|
||||
}
|
||||
return RepairKind.None;
|
||||
}
|
||||
|
||||
public static string ButtonText(RepairKind kind)
|
||||
{
|
||||
return kind switch
|
||||
{
|
||||
RepairKind.RestartAsAdministrator => "Fix this",
|
||||
RepairKind.OpenHdrSettings => "Open HDR settings",
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
|
||||
public static string Explain(RepairKind kind)
|
||||
{
|
||||
return kind switch
|
||||
{
|
||||
RepairKind.RestartAsAdministrator => "PlexusX will close and open again as administrator. Windows will ask you to confirm.",
|
||||
RepairKind.OpenHdrSettings => "Opens the Windows HDR page. Turn HDR off there, then come back.",
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
|
||||
public static bool Run(RepairKind kind, Action? beforeRestart = null)
|
||||
{
|
||||
return Run(kind, FlavourPolicy.Current, (ProcessStartInfo elevated) => Process.Start(elevated), beforeRestart);
|
||||
}
|
||||
|
||||
internal static bool Run(RepairKind kind, FlavourPolicy policy, Func<ProcessStartInfo, Process?> start, Action? beforeRestart)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case RepairKind.RestartAsAdministrator:
|
||||
{
|
||||
if (!policy.OffersElevation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string processPath = Environment.ProcessPath;
|
||||
if (string.IsNullOrEmpty(processPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ProcessStartInfo arg = new ProcessStartInfo(processPath, RelaunchArguments)
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Verb = "runas"
|
||||
};
|
||||
if (start(arg) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
beforeRestart?.Invoke();
|
||||
return true;
|
||||
}
|
||||
case RepairKind.OpenHdrSettings:
|
||||
Process.Start(new ProcessStartInfo("ms-settings:display")
|
||||
{
|
||||
UseShellExecute = true
|
||||
});
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public enum RepairKind
|
||||
{
|
||||
None,
|
||||
RestartAsAdministrator,
|
||||
OpenHdrSettings
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace VibranceHud.Capabilities;
|
||||
|
||||
public static class WindowsRampRule
|
||||
{
|
||||
public const int DefaultRange = 128;
|
||||
|
||||
public const int UnlockedRange = 256;
|
||||
|
||||
public static bool WindowsAcceptsRamp(ushort[] ramp, int range = 128)
|
||||
{
|
||||
if (ramp.Length != 768)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (range >= 256)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
if (Math.Abs((ramp[i * 256 + j] >> 8) - j) > range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int? ReadGammaRange()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ICM");
|
||||
return (registryKey?.GetValue("GdiIcmGammaRange") is int value) ? new int?(value) : ((int?)null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int WorstDeviation(ushort[] ramp)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
num = Math.Max(num, Math.Abs((ramp[i * 256 + j] >> 8) - j));
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Capture;
|
||||
|
||||
public static class ColourScreenshot
|
||||
{
|
||||
public static string Folder => AppFolders.Pictures;
|
||||
|
||||
public static void ApplyLook(Bitmap bmp, float[]? matrix, ushort[]? ramp)
|
||||
{
|
||||
if (bmp == null)
|
||||
{
|
||||
throw new ArgumentNullException("bmp");
|
||||
}
|
||||
if (matrix == null && ramp == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
byte[] array = null;
|
||||
if (ramp != null)
|
||||
{
|
||||
array = new byte[768];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
array[i * 256 + j] = (byte)(ramp[i * 256 + j] >> 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||
BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
try
|
||||
{
|
||||
int num = Math.Abs(bitmapData.Stride) * bmp.Height;
|
||||
byte[] array2 = new byte[num];
|
||||
Marshal.Copy(bitmapData.Scan0, array2, 0, num);
|
||||
for (int k = 0; k < num; k += 4)
|
||||
{
|
||||
float num2 = (float)(int)array2[k] / 255f;
|
||||
float num3 = (float)(int)array2[k + 1] / 255f;
|
||||
float num4 = (float)(int)array2[k + 2] / 255f;
|
||||
if (matrix != null)
|
||||
{
|
||||
float num5 = num4 * matrix[0] + num3 * matrix[5] + num2 * matrix[10] + matrix[20];
|
||||
float num6 = num4 * matrix[1] + num3 * matrix[6] + num2 * matrix[11] + matrix[21];
|
||||
float num7 = num4 * matrix[2] + num3 * matrix[7] + num2 * matrix[12] + matrix[22];
|
||||
num4 = num5;
|
||||
num3 = num6;
|
||||
num2 = num7;
|
||||
}
|
||||
byte b = Clamp(num4);
|
||||
byte b2 = Clamp(num3);
|
||||
byte b3 = Clamp(num2);
|
||||
if (array != null)
|
||||
{
|
||||
b = array[b];
|
||||
b2 = array[256 + b2];
|
||||
b3 = array[512 + b3];
|
||||
}
|
||||
array2[k] = b3;
|
||||
array2[k + 1] = b2;
|
||||
array2[k + 2] = b;
|
||||
}
|
||||
Marshal.Copy(array2, 0, bitmapData.Scan0, num);
|
||||
}
|
||||
finally
|
||||
{
|
||||
bmp.UnlockBits(bitmapData);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte Clamp(float v)
|
||||
{
|
||||
if (!(v <= 0f))
|
||||
{
|
||||
if (!(v >= 1f))
|
||||
{
|
||||
return (byte)(v * 255f + 0.5f);
|
||||
}
|
||||
return byte.MaxValue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Bitmap Grab()
|
||||
{
|
||||
Rectangle virtualScreen = SystemInformation.VirtualScreen;
|
||||
Bitmap bitmap = new Bitmap(virtualScreen.Width, virtualScreen.Height, PixelFormat.Format32bppArgb);
|
||||
using Graphics graphics = Graphics.FromImage(bitmap);
|
||||
graphics.CopyFromScreen(virtualScreen.Left, virtualScreen.Top, 0, 0, virtualScreen.Size, CopyPixelOperation.SourceCopy);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static string FileNameFor(DateTime when)
|
||||
{
|
||||
return $"PlexusX-{when:yyyy-MM-dd-HHmmss}.png";
|
||||
}
|
||||
|
||||
internal static string UniquePath(string folder, DateTime now)
|
||||
{
|
||||
string text = Path.Combine(folder, FileNameFor(now));
|
||||
int num = 2;
|
||||
while (File.Exists(text) && num < 100)
|
||||
{
|
||||
text = Path.Combine(folder, Path.GetFileNameWithoutExtension(FileNameFor(now)) + " (" + num + ").png");
|
||||
num++;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string Take(VibranceEngine engine, DateTime now)
|
||||
{
|
||||
if (engine == null)
|
||||
{
|
||||
throw new ArgumentNullException("engine");
|
||||
}
|
||||
using Bitmap bitmap = Grab();
|
||||
ApplyLook(bitmap, engine.CurrentMatrix(), engine.CurrentRamp());
|
||||
Directory.CreateDirectory(Folder);
|
||||
string text = UniquePath(Folder, now);
|
||||
bitmap.Save(text, ImageFormat.Png);
|
||||
try
|
||||
{
|
||||
Clipboard.SetImage(bitmap);
|
||||
}
|
||||
catch (ExternalException)
|
||||
{
|
||||
}
|
||||
catch (ThreadStateException)
|
||||
{
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using SharpDX;
|
||||
using SharpDX.DXGI;
|
||||
using SharpDX.Direct3D11;
|
||||
using VibranceHud.Capabilities;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class CaptureDiagnostic
|
||||
{
|
||||
private const int Pairs = 10;
|
||||
|
||||
private const float TestSaturation = 3f;
|
||||
|
||||
private const double ReachesThreshold = 1.4;
|
||||
|
||||
private const double MissesThreshold = 1.1;
|
||||
|
||||
private const int DxgiErrorUnsupported = -2005270524;
|
||||
|
||||
internal const string DifferentChipWords = "This laptop's screen runs on a different graphics chip, so the test can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||
|
||||
internal const string GenericWords = "Windows wouldn't let the test look at your screen";
|
||||
|
||||
internal const string NoScreenOnAnyChipWords = "The test couldn't find your screen on any graphics chip, so it can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||
|
||||
private const int DxgiErrorNotFound = -2005270526;
|
||||
|
||||
public static CaptureProbe Probe(ISaturationOverlay overlay)
|
||||
{
|
||||
if (overlay == null)
|
||||
{
|
||||
return CaptureProbe.Failed("The colour effect isn't running, so there is nothing to test", "no overlay");
|
||||
}
|
||||
Factory1 factory = null;
|
||||
Adapter1 adapter = null;
|
||||
SharpDX.Direct3D11.Device device = null;
|
||||
Output output = null;
|
||||
Output1 output2 = null;
|
||||
try
|
||||
{
|
||||
Factory1 f;
|
||||
factory = (f = new Factory1());
|
||||
int index = FirstAdapterWithAnOutput(CountAdapters(f), (int i) => AdapterHasAScreen(f, i));
|
||||
adapter = factory.GetAdapter1(index);
|
||||
device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport);
|
||||
output = adapter.GetOutput(0);
|
||||
output2 = output.QueryInterface<Output1>();
|
||||
double[] array = new double[10];
|
||||
for (int num = 0; num < 10; num++)
|
||||
{
|
||||
overlay.Clear();
|
||||
Thread.Sleep(180);
|
||||
double num2 = MeanChroma(device, output2);
|
||||
overlay.Apply(SaturationMatrix.Build(3f));
|
||||
Thread.Sleep(180);
|
||||
double num3 = MeanChroma(device, output2);
|
||||
array[num] = ((num2 > 0.001) ? (num3 / num2) : 1.0);
|
||||
}
|
||||
overlay.Clear();
|
||||
Array.Sort(array);
|
||||
double num4 = (array[4] + array[5]) / 2.0;
|
||||
if (num4 >= 1.4)
|
||||
{
|
||||
return new CaptureProbe(Ran: true, num4, ReachesCapture: true, "the colour effect IS in the desktop-duplication path (Discord screen share sees it)");
|
||||
}
|
||||
if (num4 <= 1.1)
|
||||
{
|
||||
return new CaptureProbe(Ran: true, num4, ReachesCapture: false, "not in the desktop-duplication path (Discord screen share won't see it; OBS still will)");
|
||||
}
|
||||
return new CaptureProbe(Ran: true, num4, ReachesCapture: false, "inconclusive - the screen was changing too much while measuring");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FailedBecause(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
output2?.Dispose();
|
||||
output?.Dispose();
|
||||
device?.Dispose();
|
||||
adapter?.Dispose();
|
||||
factory?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static string BuildReport(AppSettings settings, bool driverVibrance, CaptureProbe probe)
|
||||
{
|
||||
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.AppendLine("PlexusX capture report");
|
||||
stringBuilder.AppendLine("----------------------");
|
||||
StringBuilder stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder3 = stringBuilder2;
|
||||
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("app : ");
|
||||
handler.AppendFormatted(AppInfo.VersionText);
|
||||
stringBuilder3.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder4 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||
handler.AppendLiteral("windows : ");
|
||||
handler.AppendFormatted(Environment.OSVersion.Version);
|
||||
handler.AppendLiteral(" (");
|
||||
handler.AppendFormatted(Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit");
|
||||
handler.AppendLiteral(")");
|
||||
stringBuilder4.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder5 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("gpu : ");
|
||||
handler.AppendFormatted(DescribeAdapters());
|
||||
stringBuilder5.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder6 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("driver vibr. : ");
|
||||
handler.AppendFormatted(driverVibrance ? "available (NVIDIA)" : "not available");
|
||||
stringBuilder6.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder7 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("display path : ");
|
||||
handler.AppendFormatted((settings.OverlayMode == OverlayMode.Dx) ? "DX11" : "Magnification");
|
||||
stringBuilder7.AppendLine(ref handler);
|
||||
if (settings.OverlayMode != OverlayMode.Dx)
|
||||
{
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder8 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||
handler.AppendLiteral("dx11 failed : ");
|
||||
handler.AppendFormatted(settings.DxFailure);
|
||||
handler.AppendLiteral(" - ");
|
||||
handler.AppendFormatted(settings.DxFailureMessage);
|
||||
stringBuilder8.AppendLine(ref handler);
|
||||
if (settings.DxFailureCode != 0)
|
||||
{
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder9 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(17, 1, stringBuilder2);
|
||||
handler.AppendLiteral("dx11 code : 0x");
|
||||
handler.AppendFormatted(settings.DxFailureCode, "X8");
|
||||
stringBuilder9.AppendLine(ref handler);
|
||||
}
|
||||
}
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder10 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("composited : ");
|
||||
handler.AppendFormatted(settings.KeepDesktopComposited ? "forced on" : "off");
|
||||
stringBuilder10.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder11 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("streaming : ");
|
||||
handler.AppendFormatted(settings.StreamingMode ? "on" : "off");
|
||||
stringBuilder11.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder12 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(18, 2, stringBuilder2);
|
||||
handler.AppendLiteral("vibrance/sat : ");
|
||||
handler.AppendFormatted(settings.VibrancePercent);
|
||||
handler.AppendLiteral(" / ");
|
||||
handler.AppendFormatted(settings.SaturationPercent);
|
||||
stringBuilder12.AppendLine(ref handler);
|
||||
MachineCapabilities current = Machine.Current;
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder13 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("gamma ramp : ");
|
||||
handler.AppendFormatted(current.GammaRamp);
|
||||
stringBuilder13.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder14 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("hdr : ");
|
||||
handler.AppendFormatted(current.HdrActive ? "ON" : "off");
|
||||
stringBuilder14.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder15 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 2, stringBuilder2);
|
||||
handler.AppendLiteral("monitors : ");
|
||||
handler.AppendFormatted(current.MonitorCount);
|
||||
handler.AppendFormatted(current.MixedDpi ? " (mixed scaling)" : "");
|
||||
stringBuilder15.AppendLine(ref handler);
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder16 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("elevated : ");
|
||||
handler.AppendFormatted(current.Elevated ? "yes" : "no");
|
||||
stringBuilder16.AppendLine(ref handler);
|
||||
stringBuilder.AppendLine();
|
||||
if (!probe.Ran)
|
||||
{
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder17 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(31, 1, stringBuilder2);
|
||||
handler.AppendLiteral("capture test : could not run (");
|
||||
handler.AppendFormatted(probe.Note);
|
||||
handler.AppendLiteral(")");
|
||||
stringBuilder17.AppendLine(ref handler);
|
||||
if (!string.IsNullOrEmpty(probe.Detail))
|
||||
{
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder18 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral(" detail : ");
|
||||
handler.AppendFormatted(probe.Detail);
|
||||
stringBuilder18.AppendLine(ref handler);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder2 = stringBuilder;
|
||||
StringBuilder stringBuilder19 = stringBuilder2;
|
||||
handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
|
||||
handler.AppendLiteral("capture test : ");
|
||||
handler.AppendFormatted(probe.Note);
|
||||
stringBuilder19.AppendLine(ref handler);
|
||||
stringBuilder.AppendLine(" measured : " + probe.MedianRatio.ToString("F3", invariantCulture) + " (1.0 = capture saw no change, ~2.0 = capture saw the effect)");
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static string DescribeAdapters()
|
||||
{
|
||||
try
|
||||
{
|
||||
using Factory1 factory = new Factory1();
|
||||
List<string> list = new List<string>();
|
||||
int num = 0;
|
||||
while (true)
|
||||
{
|
||||
Adapter1 adapter;
|
||||
try
|
||||
{
|
||||
adapter = factory.GetAdapter1(num);
|
||||
}
|
||||
catch (SharpDXException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
using (adapter)
|
||||
{
|
||||
AdapterDescription1 description = adapter.Description1;
|
||||
if ((description.Flags & AdapterFlags.Software) == 0)
|
||||
{
|
||||
list.Add(description.Description.Trim());
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return (list.Count == 0) ? "none found" : string.Join(" + ", list);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
return "unavailable (" + ex2.GetType().Name + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static CaptureProbe FailedBecause(Exception ex)
|
||||
{
|
||||
return FailedBecause(ex, CountHardwareAdapters());
|
||||
}
|
||||
|
||||
internal static CaptureProbe FailedBecause(Exception ex, int hardwareAdapters)
|
||||
{
|
||||
string detail = ex.GetType().Name + ": " + Short(ex.Message) + $" (0x{ex.HResult:X8})";
|
||||
string why;
|
||||
if (ex.HResult == -2005270524)
|
||||
{
|
||||
why = "This laptop's screen runs on a different graphics chip, so the test can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'";
|
||||
}
|
||||
else
|
||||
{
|
||||
why = ((ex.HResult == -2005270526 && hardwareAdapters > 1) ? "The test couldn't find your screen on any graphics chip, so it can't look. In OBS, try Display Capture with Capture Method 'Windows 10 (1903 and up)'" : "Windows wouldn't let the test look at your screen");
|
||||
}
|
||||
return CaptureProbe.Failed(why, detail);
|
||||
}
|
||||
|
||||
internal static int FirstAdapterWithAnOutput(int adapters, Func<int, bool> hasOutput)
|
||||
{
|
||||
for (int i = 0; i < adapters; i++)
|
||||
{
|
||||
if (hasOutput(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int CountAdapters(Factory1 factory)
|
||||
{
|
||||
int num = 0;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (factory.GetAdapter1(num))
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (SharpDXException)
|
||||
{
|
||||
return num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AdapterHasAScreen(Factory1 factory, int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Adapter1 adapter = factory.GetAdapter1(index);
|
||||
if ((adapter.Description1.Flags & AdapterFlags.Software) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (adapter.GetOutput(0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (SharpDXException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int CountHardwareAdapters()
|
||||
{
|
||||
try
|
||||
{
|
||||
using Factory1 factory = new Factory1();
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
Adapter1 adapter;
|
||||
try
|
||||
{
|
||||
adapter = factory.GetAdapter1(num2);
|
||||
}
|
||||
catch (SharpDXException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
using (adapter)
|
||||
{
|
||||
if ((adapter.Description1.Flags & AdapterFlags.Software) == 0)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
num2++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static string Short(string s)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(s))
|
||||
{
|
||||
return s.Split('\n')[0].Trim();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static double MeanChroma(SharpDX.Direct3D11.Device device, Output1 output1)
|
||||
{
|
||||
using OutputDuplication outputDuplication = output1.DuplicateOutput(device);
|
||||
SharpDX.DXGI.Resource resource = null;
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
if (resource != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (outputDuplication.TryAcquireNextFrame(250, out var _, out var desktopResourceOut).Success && desktopResourceOut != null)
|
||||
{
|
||||
resource = desktopResourceOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(25);
|
||||
}
|
||||
}
|
||||
if (resource == null)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
using (resource)
|
||||
{
|
||||
using Texture2D texture2D = resource.QueryInterface<Texture2D>();
|
||||
Texture2DDescription description = texture2D.Description;
|
||||
using Texture2D texture2D2 = new Texture2D(device, new Texture2DDescription
|
||||
{
|
||||
Width = description.Width,
|
||||
Height = description.Height,
|
||||
MipLevels = 1,
|
||||
ArraySize = 1,
|
||||
Format = description.Format,
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
Usage = ResourceUsage.Staging,
|
||||
BindFlags = BindFlags.None,
|
||||
CpuAccessFlags = CpuAccessFlags.Read,
|
||||
OptionFlags = ResourceOptionFlags.None
|
||||
});
|
||||
device.ImmediateContext.CopyResource(texture2D, texture2D2);
|
||||
DataBox dataBox = device.ImmediateContext.MapSubresource(texture2D2, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
|
||||
double num = 0.0;
|
||||
int num2 = 0;
|
||||
byte[] array = new byte[dataBox.RowPitch];
|
||||
for (int j = 0; j < description.Height; j += 4)
|
||||
{
|
||||
Marshal.Copy(dataBox.DataPointer + j * dataBox.RowPitch, array, 0, dataBox.RowPitch);
|
||||
for (int k = 0; k < description.Width; k += 4)
|
||||
{
|
||||
int num3 = k * 4;
|
||||
if (num3 + 2 >= array.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
byte val = array[num3];
|
||||
byte val2 = array[num3 + 1];
|
||||
byte val3 = array[num3 + 2];
|
||||
int num4 = Math.Max(val3, Math.Max(val2, val));
|
||||
int num5 = Math.Min(val3, Math.Min(val2, val));
|
||||
num += (double)(num4 - num5);
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
device.ImmediateContext.UnmapSubresource(texture2D2, 0);
|
||||
try
|
||||
{
|
||||
outputDuplication.ReleaseFrame();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return (num2 == 0) ? 0.0 : (num / (double)num2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed record CaptureProbe(bool Ran, double MedianRatio, bool ReachesCapture, string Note, string Detail = "")
|
||||
{
|
||||
public static CaptureProbe Failed(string why, string detail = "")
|
||||
{
|
||||
return new CaptureProbe(Ran: false, 0.0, ReachesCapture: false, why, detail);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public enum CaptureState
|
||||
{
|
||||
Visible,
|
||||
NeedsStreamingMode,
|
||||
DependsOnCaptureMethod
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class CaptureStatus
|
||||
{
|
||||
public const string AlwaysTrue = "In OBS use Display Capture, not Game Capture - Game Capture reads the game directly and never sees this. Gamma is never captured either way.";
|
||||
|
||||
public static CaptureState Resolve(OverlayMode overlay, bool driverVibranceAvailable, bool streamingMode)
|
||||
{
|
||||
if (overlay == OverlayMode.Mag)
|
||||
{
|
||||
return CaptureState.DependsOnCaptureMethod;
|
||||
}
|
||||
if (!driverVibranceAvailable)
|
||||
{
|
||||
return CaptureState.Visible;
|
||||
}
|
||||
if (!streamingMode)
|
||||
{
|
||||
return CaptureState.NeedsStreamingMode;
|
||||
}
|
||||
return CaptureState.Visible;
|
||||
}
|
||||
|
||||
public static bool ToggleCanHelp(OverlayMode overlay, bool driverVibranceAvailable)
|
||||
{
|
||||
return driverVibranceAvailable;
|
||||
}
|
||||
|
||||
public static string Headline(CaptureState state)
|
||||
{
|
||||
return state switch
|
||||
{
|
||||
CaptureState.Visible => "Recordings show your colours.",
|
||||
CaptureState.NeedsStreamingMode => "Recordings are missing your vibrance right now.",
|
||||
_ => "Recordings show your colours - screen share may not.",
|
||||
};
|
||||
}
|
||||
|
||||
public static string Reason(CaptureState state, bool driverVibranceAvailable)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case CaptureState.NeedsStreamingMode:
|
||||
return "Your vibrance is being applied by the graphics driver, after recording software has already read the screen. Turn on \"Move my colours where recording can see them\" above to move it somewhere they can see it.";
|
||||
case CaptureState.DependsOnCaptureMethod:
|
||||
if (driverVibranceAvailable)
|
||||
{
|
||||
return "Recordings and screen share both show your colours - most of it comes from your NVIDIA driver, which every capture path can see.\n\nSaturation pushed past 100 is done in software, and that part reaches OBS but not Discord screen share.";
|
||||
}
|
||||
return "OBS records your colours with its default Display Capture settings - confirmed on AMD. If they don't appear, open your Display Capture source and set Capture Method to \"Windows 10 (1903 and up)\".\n\nDiscord screen share reads the screen a different way and won't show them. Your card has no driver-level colour for PlexusX to use yet, which is what would fix that.";
|
||||
default:
|
||||
return driverVibranceAvailable ? "Your vibrance is being applied early enough for capture to pick it up." : "Your colours are already applied in software, which capture reads - so there was never anything to move. That switch is for NVIDIA driver vibrance.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class CardPanel : Panel
|
||||
{
|
||||
private readonly CardSurface _surface = new CardSurface();
|
||||
|
||||
public CardPanel()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
_surface.Paint(this, e.Graphics);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_surface.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
internal sealed class CardSurface : IDisposable
|
||||
{
|
||||
private Bitmap? _glass;
|
||||
|
||||
private Size _glassSize;
|
||||
|
||||
private string _glassTheme = "";
|
||||
|
||||
private Size _failedSize;
|
||||
|
||||
private string _failedKey = "";
|
||||
|
||||
private bool _failureLogged;
|
||||
|
||||
private static int Radius => Tokens.Scale(8);
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
private static bool IsGdiFailure(Exception ex)
|
||||
{
|
||||
if (!(ex is OutOfMemoryException) && !(ex is ExternalException) && !(ex is ArgumentException))
|
||||
{
|
||||
return ex is InvalidOperationException;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LogOnce(Exception ex)
|
||||
{
|
||||
if (!_failureLogged)
|
||||
{
|
||||
_failureLogged = true;
|
||||
CrashLog.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Paint(Control owner, Graphics g)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SlateSurface.Active && AppBackground.IsSet)
|
||||
{
|
||||
Glass.PaintPanel(g, new RectangleF(0.5f, 0.5f, owner.Width - 1, owner.Height - 1), Radius, Glass.BackdropOffsetOf(owner));
|
||||
return;
|
||||
}
|
||||
Bitmap bitmap = EnsureGlass(owner.Size);
|
||||
if (bitmap != null)
|
||||
{
|
||||
FailPointForTest?.Invoke("draw");
|
||||
g.DrawImageUnscaled(bitmap, 0, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (IsGdiFailure(ex))
|
||||
{
|
||||
LogOnce(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PaintSignalCard(Graphics g, Size size)
|
||||
{
|
||||
RectangleF rectangleF = new RectangleF(0.5f, 0.5f, size.Width - 1, size.Height - 1);
|
||||
float num = Radius;
|
||||
using GraphicsPath graphicsPath = new GraphicsPath();
|
||||
graphicsPath.AddArc(rectangleF.X, rectangleF.Y, num, num, 180f, 90f);
|
||||
graphicsPath.AddArc(rectangleF.Right - num, rectangleF.Y, num, num, 270f, 90f);
|
||||
graphicsPath.AddArc(rectangleF.Right - num, rectangleF.Bottom - num, num, num, 0f, 90f);
|
||||
graphicsPath.AddArc(rectangleF.X, rectangleF.Bottom - num, num, num, 90f, 90f);
|
||||
graphicsPath.CloseFigure();
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
using (SolidBrush brush = new SolidBrush(SignalTokens.Ash.Surface1))
|
||||
{
|
||||
g.FillPath(brush, graphicsPath);
|
||||
}
|
||||
using Pen pen = new Pen(SignalTokens.Ash.Border, 1f);
|
||||
g.DrawPath(pen, graphicsPath);
|
||||
}
|
||||
|
||||
private Bitmap? EnsureGlass(Size size)
|
||||
{
|
||||
if (size.Width < 2 || size.Height < 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string text = Theme.CurrentName + "|" + Glass.ActiveChrome;
|
||||
if (_glass != null && _glassSize == size && _glassTheme == text)
|
||||
{
|
||||
return _glass;
|
||||
}
|
||||
if (_failedSize == size && _failedKey == text)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
FailPointForTest?.Invoke("build");
|
||||
_glass?.Dispose();
|
||||
_glass = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);
|
||||
_glassSize = size;
|
||||
_glassTheme = text;
|
||||
using Graphics graphics = Graphics.FromImage(_glass);
|
||||
graphics.Clear(Color.Transparent);
|
||||
if (SlateSurface.Active)
|
||||
{
|
||||
Glass.PaintPanel(graphics, new RectangleF(0.5f, 0.5f, size.Width - 1, size.Height - 1), Radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
PaintSignalCard(graphics, size);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_glass?.Dispose();
|
||||
_glass = null;
|
||||
_glassSize = Size.Empty;
|
||||
_glassTheme = "";
|
||||
_failedSize = size;
|
||||
_failedKey = text;
|
||||
throw;
|
||||
}
|
||||
_failedSize = Size.Empty;
|
||||
_failedKey = "";
|
||||
return _glass;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_glass?.Dispose();
|
||||
_glass = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed record ChannelMix(float RR, float RG, float RB, float GR, float GG, float GB, float BR, float BG, float BB)
|
||||
{
|
||||
public bool IsIdentity => Near(Identity);
|
||||
|
||||
public static readonly ChannelMix Identity = new ChannelMix(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f);
|
||||
|
||||
private const float Tolerance = 0.0005f;
|
||||
|
||||
public bool Near(ChannelMix other)
|
||||
{
|
||||
return ToArray().Zip(other.ToArray(), (float a, float b) => Math.Abs(a - b)).All((float d) => d <= 0.0005f);
|
||||
}
|
||||
|
||||
public float[] ToArray()
|
||||
{
|
||||
return new float[9] { RR, RG, RB, GR, GG, GB, BR, BG, BB };
|
||||
}
|
||||
|
||||
public static ChannelMix FromArray(float[]? nine)
|
||||
{
|
||||
if (nine == null || nine.Length != 9 || nine.Any((float v) => float.IsNaN(v) || float.IsInfinity(v)))
|
||||
{
|
||||
return Identity;
|
||||
}
|
||||
return new ChannelMix(nine[0], nine[1], nine[2], nine[3], nine[4], nine[5], nine[6], nine[7], nine[8]);
|
||||
}
|
||||
|
||||
public static ChannelMix FromPercent(params int[] nine)
|
||||
{
|
||||
if (nine.Length != 9)
|
||||
{
|
||||
throw new ArgumentException("a channel mix is nine numbers", "nine");
|
||||
}
|
||||
return FromArray(nine.Select((int v) => (float)v / 100f).ToArray());
|
||||
}
|
||||
|
||||
public float[] ToMatrix()
|
||||
{
|
||||
return new float[25]
|
||||
{
|
||||
RR, RG, RB, 0f, 0f, GR, GG, GB, 0f, 0f,
|
||||
BR, BG, BB, 0f, 0f, 0f, 0f, 0f, 1f, 0f,
|
||||
0f, 0f, 0f, 0f, 1f
|
||||
};
|
||||
}
|
||||
|
||||
public float[] ComposeInto(float[] matrix)
|
||||
{
|
||||
if (!IsIdentity)
|
||||
{
|
||||
return ColourVision.Compose(matrix, ToMatrix());
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "[" + string.Join(",", from v in ToArray()
|
||||
select Math.Round(v * 100f).ToString(CultureInfo.InvariantCulture)) + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class ChipButton : Control
|
||||
{
|
||||
private sealed class ChipAccessibleObject : ControlAccessibleObject
|
||||
{
|
||||
private readonly ChipButton _owner;
|
||||
|
||||
public override AccessibleStates State => (AccessibleStates)((int)base.State | (_owner._active ? 16 : 0));
|
||||
|
||||
public ChipAccessibleObject(ChipButton owner)
|
||||
: base(owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _active;
|
||||
|
||||
private readonly HoverFade _fade;
|
||||
|
||||
private readonly HoverFade _press;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private string _suffix = "";
|
||||
|
||||
private ContentAlignment _align = ContentAlignment.MiddleCenter;
|
||||
|
||||
public int Level { get; init; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Suffix
|
||||
{
|
||||
get
|
||||
{
|
||||
return _suffix;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
if (!(_suffix == value))
|
||||
{
|
||||
_suffix = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ContentAlignment TextAlign
|
||||
{
|
||||
get
|
||||
{
|
||||
return _align;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_align != value)
|
||||
{
|
||||
_align = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override AccessibleObject CreateAccessibilityInstance()
|
||||
{
|
||||
return new ChipAccessibleObject(this);
|
||||
}
|
||||
|
||||
public ChipButton()
|
||||
{
|
||||
_fade = new HoverFade(this);
|
||||
_press = new HoverFade(this);
|
||||
_ring = new OutsideFocusRing(this, () => Radius(ControlInk.Dpi(this)));
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
Height = 32;
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
AccessibleRole = AccessibleRole.PushButton;
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AccessibleName = Text;
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
_press.Snap(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
internal void TestSetHover(bool on)
|
||||
{
|
||||
_fade.Snap(on);
|
||||
}
|
||||
|
||||
internal void TestSetPressed(bool on)
|
||||
{
|
||||
_press.Snap(on);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_fade.Set(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_fade.Set(hot: false);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||
_fade.Snap(hot: false);
|
||||
_press.Snap(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private static float Radius(int dpi)
|
||||
{
|
||||
return ControlInk.PxF(dpi, 4f);
|
||||
}
|
||||
|
||||
private Font LabelFont(bool strong)
|
||||
{
|
||||
if (!strong)
|
||||
{
|
||||
return Font;
|
||||
}
|
||||
if (Math.Abs(Font.SizeInPoints - Fonts.Body.SizeInPoints) < 0.1f)
|
||||
{
|
||||
return Fonts.BodyBold;
|
||||
}
|
||||
if (Math.Abs(Font.SizeInPoints - Fonts.Caption.SizeInPoints) < 0.1f)
|
||||
{
|
||||
return Fonts.CaptionBold;
|
||||
}
|
||||
return Font;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
int dpi = ControlInk.Dpi(this);
|
||||
Color transparent = Color.Transparent;
|
||||
float t = (Enabled ? _fade.Value : 0f);
|
||||
float t2 = (Enabled ? _press.Value : 0f);
|
||||
Color fill;
|
||||
Color edge;
|
||||
Color foreColor;
|
||||
Color foreColor2;
|
||||
if (!Enabled)
|
||||
{
|
||||
fill = (_active ? ControlInk.Surface2 : transparent);
|
||||
edge = (_active ? ControlInk.Surface2 : ControlInk.TextDisabled);
|
||||
foreColor = (foreColor2 = ControlInk.TextDisabledInk);
|
||||
}
|
||||
else if (_active)
|
||||
{
|
||||
fill = (edge = ControlInk.Accent);
|
||||
foreColor = ControlInk.OnAccent;
|
||||
foreColor2 = ControlInk.SelectedSuffix;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color hover = ControlInk.Hover;
|
||||
fill = ControlInk.Mix(ControlInk.Mix(Color.FromArgb(0, hover), hover, t), ControlInk.Pressed, t2);
|
||||
edge = ControlInk.Edge;
|
||||
foreColor = ControlInk.Text1;
|
||||
foreColor2 = ControlInk.Text3;
|
||||
}
|
||||
ControlInk.PaintBox(graphics, ClientSize, Radius(dpi), ControlInk.Hairline(dpi), fill, edge);
|
||||
Font font = LabelFont(_active);
|
||||
int width = TextRenderer.MeasureText(graphics, Text, font, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding).Width;
|
||||
int num = ControlInk.Px(dpi, 8);
|
||||
Font caption = Fonts.Caption;
|
||||
int num2 = ((_suffix.Length != 0) ? TextRenderer.MeasureText(graphics, _suffix, caption, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding).Width : 0);
|
||||
int num3 = width + ((num2 > 0) ? (num + num2) : 0);
|
||||
int num4 = ((_align == ContentAlignment.MiddleLeft) ? ControlInk.Px(dpi, 12) : ((Width - num3) / 2));
|
||||
TextRenderer.DrawText(graphics, Text, font, new Rectangle(num4, 0, width + 2, Height), foreColor, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
if (num2 > 0)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, _suffix, caption, new Rectangle(num4 + width + num, 0, num2 + 2, Height), foreColor2, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
if (Focused && ShowFocusCues)
|
||||
{
|
||||
_ring.Show(show: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ring.Show(show: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class ColorAdjust
|
||||
{
|
||||
public const float WarmGreenCut = 0.12f;
|
||||
|
||||
public const float WarmBlueCut = 0.38f;
|
||||
|
||||
public const float VibranceRedHold = 0.55f;
|
||||
|
||||
public static float[] Build(float saturation, float brightness, float warmth)
|
||||
{
|
||||
return BuildWithVibranceNumbers(saturation, 1f, 1f, 1f, brightness, warmth);
|
||||
}
|
||||
|
||||
internal static float[] BuildWithVibranceNumbers(float saturation, float red, float chroma, float contrast, float brightness, float warmth)
|
||||
{
|
||||
return BuildWithVibranceNumbers(saturation, red, chroma, contrast, brightness, warmth, ColourDepth.Neutral);
|
||||
}
|
||||
|
||||
internal static float[] BuildWithVibranceNumbers(float saturation, float red, float chroma, float contrast, float brightness, float warmth, ColourDepth depth)
|
||||
{
|
||||
float[] array = (depth.IsNeutral ? SaturationMatrix.Build(saturation * red, saturation * chroma, saturation * chroma) : SaturationMetrics.BuildWithVibranceNumbers(depth.Formula, saturation, red, chroma, depth));
|
||||
float num = Math.Max(0f, warmth);
|
||||
float num2 = Math.Max(0f, 0f - warmth);
|
||||
float num3 = 1f - 0.38f * num2;
|
||||
float num4 = 1f - 0.12f * (num + num2);
|
||||
float num5 = 1f - 0.38f * num;
|
||||
float num6 = brightness * num3 * contrast;
|
||||
float num7 = brightness * num4 * contrast;
|
||||
float num8 = brightness * num5 * contrast;
|
||||
float num9 = 0.5f * (1f - contrast);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
array[i * 5] *= num6;
|
||||
array[i * 5 + 1] *= num7;
|
||||
array[i * 5 + 2] *= num8;
|
||||
}
|
||||
array[20] = num9;
|
||||
array[21] = num9;
|
||||
array[22] = num9;
|
||||
return array;
|
||||
}
|
||||
|
||||
public static bool IsIdentity(float saturation, float brightness, float warmth)
|
||||
{
|
||||
return IsIdentity(saturation, 1f, brightness, warmth);
|
||||
}
|
||||
|
||||
public static bool IsIdentity(float saturation, float vibrance, float brightness, float warmth)
|
||||
{
|
||||
return IsIdentity(saturation, vibrance, 1f, brightness, warmth);
|
||||
}
|
||||
|
||||
public static bool IsIdentity(float saturation, float vibrance, float contrast, float brightness, float warmth)
|
||||
{
|
||||
if (Math.Abs(saturation - 1f) < 0.001f && Math.Abs(vibrance - 1f) < 0.001f && Math.Abs(contrast - 1f) < 0.001f && Math.Abs(brightness - 1f) < 0.001f)
|
||||
{
|
||||
return Math.Abs(warmth) < 0.001f;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class ColourBalance
|
||||
{
|
||||
public const int MinHue = -180;
|
||||
|
||||
public const int MaxHue = 180;
|
||||
|
||||
public const int MinGain = 50;
|
||||
|
||||
public const int MaxGain = 150;
|
||||
|
||||
public static bool GainsNeutral(int red, int green, int blue)
|
||||
{
|
||||
if (red == 100 && green == 100)
|
||||
{
|
||||
return blue == 100;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsNeutral(int hue, int red, int green, int blue)
|
||||
{
|
||||
if (hue == 0)
|
||||
{
|
||||
return GainsNeutral(red, green, blue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static float[] HueMatrix(int degrees)
|
||||
{
|
||||
double num = (double)Math.Clamp(degrees, -180, 180) * Math.PI / 180.0;
|
||||
double num2 = Math.Cos(num);
|
||||
double num3 = Math.Sin(num);
|
||||
double num4 = (1.0 - num2) / 3.0;
|
||||
double num5 = num3 / Math.Sqrt(3.0);
|
||||
int[,] array = new int[3, 3]
|
||||
{
|
||||
{ 0, -1, 1 },
|
||||
{ 1, 0, -1 },
|
||||
{ -1, 1, 0 }
|
||||
};
|
||||
float[] array2 = new float[25];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array2[i * 5 + j] = (float)(((i == j) ? num2 : 0.0) + num4 + num5 * (double)array[j, i]);
|
||||
}
|
||||
}
|
||||
array2[18] = 1f;
|
||||
array2[24] = 1f;
|
||||
return array2;
|
||||
}
|
||||
|
||||
public static float[] GainMatrix(int red, int green, int blue)
|
||||
{
|
||||
return new float[25]
|
||||
{
|
||||
(float)Math.Clamp(red, 50, 150) / 100f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
(float)Math.Clamp(green, 50, 150) / 100f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
(float)Math.Clamp(blue, 50, 150) / 100f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
1f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
1f
|
||||
};
|
||||
}
|
||||
|
||||
public static float[] ComposeInto(float[] matrix, int hue, int red, int green, int blue)
|
||||
{
|
||||
if (IsNeutral(hue, red, green, blue))
|
||||
{
|
||||
return matrix;
|
||||
}
|
||||
float[] array = matrix;
|
||||
if (hue != 0)
|
||||
{
|
||||
array = Multiply(array, HueMatrix(hue));
|
||||
}
|
||||
if (!GainsNeutral(red, green, blue))
|
||||
{
|
||||
array = Multiply(array, GainMatrix(red, green, blue));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
internal static float[] Multiply(float[] a, float[] b)
|
||||
{
|
||||
float[] array = new float[25];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
double num = 0.0;
|
||||
for (int k = 0; k < 5; k++)
|
||||
{
|
||||
num += (double)a[i * 5 + k] * (double)b[k * 5 + j];
|
||||
}
|
||||
array[i * 5 + j] = (float)num;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public readonly record struct ColourDepth(SaturationMetric Formula = SaturationMetric.Rec709, int Darken = 0, int DarkenHue = 120, int HueTurn = 0, int HueTurnAmount = 100, int HueComplement = 0)
|
||||
{
|
||||
public static ColourDepth Neutral => new ColourDepth(SaturationMetric.Rec709, 0, 120, 0, 100, 0);
|
||||
|
||||
public bool IsNeutral
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Formula == SaturationMetric.Rec709 && Darken == 0 && HueComplement == 0)
|
||||
{
|
||||
if (HueTurn != 0)
|
||||
{
|
||||
return HueTurnAmount == 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public const int MinDarken = 0;
|
||||
|
||||
public const int MaxDarken = 400;
|
||||
|
||||
public const int MinDarkenHue = 0;
|
||||
|
||||
public const int MaxDarkenHue = 359;
|
||||
|
||||
public const int MinHueTurn = -180;
|
||||
|
||||
public const int MaxHueTurn = 180;
|
||||
|
||||
public const int MinHueTurnAmount = 0;
|
||||
|
||||
public const int MaxHueTurnAmount = 100;
|
||||
|
||||
public const int MinHueComplement = 0;
|
||||
|
||||
public const int MaxHueComplement = 100;
|
||||
|
||||
public ColourDepth Clamped()
|
||||
{
|
||||
return new ColourDepth(Enum.IsDefined(typeof(SaturationMetric), Formula) ? Formula : SaturationMetric.Rec709, Math.Clamp(Darken, 0, 400), Math.Clamp(DarkenHue, 0, 359), Math.Clamp(HueTurn, -180, 180), Math.Clamp(HueTurnAmount, 0, 100), Math.Clamp(HueComplement, 0, 100));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public readonly record struct ColourReachFacts(bool ExclusiveFullscreen, bool OverlayLive, DxInitFailureKind DxFailure, bool DxTried, bool DisplayIsCarryingTheLook = false, string? WhatTheDisplayCannotHold = null, GammaDelivery RampOutcome = default(GammaDelivery), bool CompetitiveOn = false);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public readonly record struct ColourReachLine(ColourReachSeverity Severity, string Text);
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public enum ColourReachSeverity
|
||||
{
|
||||
Ok,
|
||||
Note,
|
||||
Refused
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class ColourReachStatus
|
||||
{
|
||||
public const string FullscreenSentence = "Fullscreen: colour comes from the driver. Borderless gives the full look.";
|
||||
|
||||
public const string CompetitiveSentence = "Colour on the driver: in full-screen games Competitive mode keeps your colour on the NVIDIA driver. Hue, channel mix, colour aids and Eye care pause there.";
|
||||
|
||||
public const string ScreenEffectRefusedSentence = "Colour engine off: Windows could not start the screen effect (Magnification). Restart PlexusX; if it stays off, tell us.";
|
||||
|
||||
public const string DisplayCarriesItSentence = "Full screen: your monitor is holding this look. It is the closest it can get.";
|
||||
|
||||
public const string RampRefusedSentence = "Full screen: Windows refused this look on this monitor. Borderless gives the full look.";
|
||||
|
||||
public const string RampIgnoredHdrSentence = "Full screen: HDR is on, and Windows ignores this look there. Borderless gives the full look.";
|
||||
|
||||
public const string LookShowsInBorderless = "This look shows in Borderless or Windowed mode. In exclusive fullscreen the game only gets the driver's colour.";
|
||||
|
||||
public const string LookNeedsPaidColourControls = "This look needs the paid colour controls, and they are off on this PC right now.";
|
||||
|
||||
public static string DisplayCarriesItButNot(string missing)
|
||||
{
|
||||
return "Full screen: your monitor is holding this look, but not " + missing + ". Borderless gives the full look.";
|
||||
}
|
||||
|
||||
public static string RampSoftenedSentence(string step)
|
||||
{
|
||||
return "Full screen: Windows only let " + StepWords(step) + " of this look through. Borderless gives the full look.";
|
||||
}
|
||||
|
||||
private static string StepWords(string step)
|
||||
{
|
||||
return step switch
|
||||
{
|
||||
"1/2" => "half",
|
||||
"1/4" => "a quarter",
|
||||
"1/8" => "an eighth",
|
||||
_ => "part",
|
||||
};
|
||||
}
|
||||
|
||||
public static ColourReachLine For(ColourReachFacts facts)
|
||||
{
|
||||
if (!facts.OverlayLive && (!facts.DxTried || facts.DxFailure == DxInitFailureKind.None))
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Refused, "Colour engine off: Windows could not start the screen effect (Magnification). Restart PlexusX; if it stays off, tell us.");
|
||||
}
|
||||
if (!facts.OverlayLive)
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Refused, "Colour engine off: " + Because(facts.DxFailure) + ".");
|
||||
}
|
||||
if (facts.ExclusiveFullscreen && facts.DisplayIsCarryingTheLook && !facts.RampOutcome.IsFull)
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Note, facts.RampOutcome.Kind switch
|
||||
{
|
||||
GammaDeliveryKind.Softened => RampSoftenedSentence(facts.RampOutcome.Step),
|
||||
GammaDeliveryKind.IgnoredHdr => "Full screen: HDR is on, and Windows ignores this look there. Borderless gives the full look.",
|
||||
_ => "Full screen: Windows refused this look on this monitor. Borderless gives the full look.",
|
||||
});
|
||||
}
|
||||
if (facts.ExclusiveFullscreen && facts.DisplayIsCarryingTheLook)
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Note, string.IsNullOrEmpty(facts.WhatTheDisplayCannotHold) ? "Full screen: your monitor is holding this look. It is the closest it can get." : DisplayCarriesItButNot(facts.WhatTheDisplayCannotHold));
|
||||
}
|
||||
if (facts.ExclusiveFullscreen)
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Note, "Fullscreen: colour comes from the driver. Borderless gives the full look.");
|
||||
}
|
||||
if (facts.CompetitiveOn)
|
||||
{
|
||||
return new ColourReachLine(ColourReachSeverity.Note, "Colour on the driver: in full-screen games Competitive mode keeps your colour on the NVIDIA driver. Hue, channel mix, colour aids and Eye care pause there.");
|
||||
}
|
||||
return new ColourReachLine(ColourReachSeverity.Ok, "");
|
||||
}
|
||||
|
||||
public static string Because(DxInitFailureKind kind)
|
||||
{
|
||||
return kind switch
|
||||
{
|
||||
DxInitFailureKind.None => "DirectX started but no monitor could be rendered",
|
||||
DxInitFailureKind.NoCompatibleAdapter => "no graphics card here can do DirectX 11",
|
||||
DxInitFailureKind.DeviceCreationFailed => "Windows would not give PlexusX a DirectX device",
|
||||
DxInitFailureKind.NoOutputs => "Windows reported no display",
|
||||
DxInitFailureKind.DriverIssue => "your display driver turned DirectX 11 down",
|
||||
DxInitFailureKind.SdkIssue => "the DirectX 11 runtime is not installed",
|
||||
DxInitFailureKind.OutOfMemory => "your graphics memory is full",
|
||||
DxInitFailureKind.CaptureInUse => "another app is capturing this display",
|
||||
DxInitFailureKind.Unknown => "DirectX 11 would not start on this PC",
|
||||
_ => "DirectX 11 would not start on this PC",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using VibranceHud.Support;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
internal static class ColourTrace
|
||||
{
|
||||
internal static readonly bool Enabled = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PLEXUSX_SAT_TRACE"));
|
||||
|
||||
private static readonly string Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "plexusx-sat.log");
|
||||
|
||||
private static readonly object Gate = new object();
|
||||
|
||||
private const int Frames = 12;
|
||||
|
||||
public static void Value(string name, int was, int now)
|
||||
{
|
||||
if (Enabled && was != now)
|
||||
{
|
||||
Write(string.Format(CultureInfo.InvariantCulture, "{0} {1}->{2} {3}", name, was, now, Caller()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Screen(bool cleared, int saturation)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
Write(string.Format(CultureInfo.InvariantCulture, "SCREEN {0} (saturation still reads {1}) {2}", cleared ? "CLEARED - picture now neutral" : "applied", saturation, Caller()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Meter(ReassertMeter meter)
|
||||
{
|
||||
if (Enabled && meter != null)
|
||||
{
|
||||
Write("REASSERT" + Environment.NewLine + meter.Describe());
|
||||
}
|
||||
}
|
||||
|
||||
public static void Refused(string layer, string why)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
Write(string.Format(CultureInfo.InvariantCulture, "REFUSED {0}: {1} {2}", layer, why, Caller()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Fallback(string what)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
Write(string.Format(CultureInfo.InvariantCulture, "FALLBACK {0} {1}", what, Caller()));
|
||||
}
|
||||
}
|
||||
|
||||
private static string Caller()
|
||||
{
|
||||
try
|
||||
{
|
||||
StackTrace stackTrace = new StackTrace(2, fNeedFileInfo: false);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int num = Math.Min(12, stackTrace.FrameCount);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
MethodBase methodBase = stackTrace.GetFrame(i)?.GetMethod();
|
||||
if (!(methodBase == null))
|
||||
{
|
||||
stringBuilder.Append(methodBase.DeclaringType?.Name).Append('.').Append(methodBase.Name)
|
||||
.Append(" <- ");
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "(no stack)";
|
||||
}
|
||||
}
|
||||
|
||||
private static void Write(string message)
|
||||
{
|
||||
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,169 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class ColourVision
|
||||
{
|
||||
private static readonly double[,] RgbToLms = new double[3, 3]
|
||||
{
|
||||
{ 17.8824, 43.5161, 4.11935 },
|
||||
{ 3.45565, 27.1554, 3.86714 },
|
||||
{ 0.0299566, 0.184309, 1.46709 }
|
||||
};
|
||||
|
||||
private static readonly double[,] LmsToRgb = new double[3, 3]
|
||||
{
|
||||
{ 0.0809444479, -0.130504409, 0.116721066 },
|
||||
{ -0.0102485335, 0.0540193266, -0.113614708 },
|
||||
{ -0.000365296938, -0.00412161469, 0.693511405 }
|
||||
};
|
||||
|
||||
private static readonly double[,] ErrorShift = new double[3, 3]
|
||||
{
|
||||
{ 0.0, 0.0, 0.0 },
|
||||
{ 0.7, 1.0, 0.0 },
|
||||
{ 0.7, 0.0, 1.0 }
|
||||
};
|
||||
|
||||
private static double[,] Simulation(ColourVisionMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
ColourVisionMode.RedWeak => new double[3, 3]
|
||||
{
|
||||
{ 0.0, 2.02344, -2.52581 },
|
||||
{ 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 }
|
||||
},
|
||||
ColourVisionMode.GreenWeak => new double[3, 3]
|
||||
{
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 0.494207, 0.0, 1.24827 },
|
||||
{ 0.0, 0.0, 1.0 }
|
||||
},
|
||||
ColourVisionMode.BlueWeak => new double[3, 3]
|
||||
{
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0, 0.0 },
|
||||
{ -0.395913, 0.801109, 0.0 }
|
||||
},
|
||||
_ => Identity3(),
|
||||
};
|
||||
}
|
||||
|
||||
public static float[] Matrix(ColourVisionMode mode)
|
||||
{
|
||||
float[] array = Identity5();
|
||||
switch (mode)
|
||||
{
|
||||
case ColourVisionMode.Off:
|
||||
return array;
|
||||
case ColourVisionMode.HoloBlack:
|
||||
return HoloBlack.GreenSubtracted();
|
||||
default:
|
||||
{
|
||||
double[,] b = Multiply3(LmsToRgb, Multiply3(Simulation(mode), RgbToLms));
|
||||
double[,] b2 = Subtract3(Identity3(), b);
|
||||
double[,] array2 = Add3(Identity3(), Multiply3(ErrorShift, b2));
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array[j * 5 + i] = (float)array2[i, j];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] Compose(float[] first, float[] second)
|
||||
{
|
||||
float[] array = new float[25];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
float num = 0f;
|
||||
for (int k = 0; k < 5; k++)
|
||||
{
|
||||
num += first[i * 5 + k] * second[k * 5 + j];
|
||||
}
|
||||
array[i * 5 + j] = num;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static double[,] Identity3()
|
||||
{
|
||||
return new double[3, 3]
|
||||
{
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 }
|
||||
};
|
||||
}
|
||||
|
||||
private static float[] Identity5()
|
||||
{
|
||||
float[] array = new float[25];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
array[i * 5 + i] = 1f;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static double[,] Multiply3(double[,] a, double[,] b)
|
||||
{
|
||||
double[,] array = new double[3, 3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
double num = 0.0;
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
num += a[i, k] * b[k, j];
|
||||
}
|
||||
array[i, j] = num;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static double[,] Add3(double[,] a, double[,] b)
|
||||
{
|
||||
double[,] array = new double[3, 3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array[i, j] = a[i, j] + b[i, j];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static double[,] Subtract3(double[,] a, double[,] b)
|
||||
{
|
||||
double[,] array = new double[3, 3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
array[i, j] = a[i, j] - b[i, j];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static (double R, double G, double B) Simulate(ColourVisionMode mode, double r, double g, double b)
|
||||
{
|
||||
if (mode == ColourVisionMode.Off)
|
||||
{
|
||||
return (R: r, G: g, B: b);
|
||||
}
|
||||
double[,] array = Multiply3(LmsToRgb, Multiply3(Simulation(mode), RgbToLms));
|
||||
return (R: array[0, 0] * r + array[0, 1] * g + array[0, 2] * b, G: array[1, 0] * r + array[1, 1] * g + array[1, 2] * b, B: array[2, 0] * r + array[2, 1] * g + array[2, 2] * b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public enum ColourVisionMode
|
||||
{
|
||||
Off,
|
||||
GreenWeak,
|
||||
RedWeak,
|
||||
BlueWeak,
|
||||
HoloBlack
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class ColourWatchdog
|
||||
{
|
||||
public static readonly TimeSpan Debounce = TimeSpan.FromMilliseconds(400.0);
|
||||
|
||||
public static readonly TimeSpan TickInterval = TimeSpan.FromSeconds(60.0);
|
||||
|
||||
public static readonly TimeSpan ForegroundSettle = TimeSpan.FromSeconds(2.0);
|
||||
|
||||
public const int FailuresBeforeBackingOff = 5;
|
||||
|
||||
private readonly Action _reapply;
|
||||
|
||||
private readonly Func<bool> _isHdrActive;
|
||||
|
||||
private readonly Func<bool> _isNeutral;
|
||||
|
||||
private readonly Func<DateTime> _now;
|
||||
|
||||
private readonly Action<Exception>? _onGaveUp;
|
||||
|
||||
private readonly Action? _worldChanged;
|
||||
|
||||
private DateTime _lastApply = DateTime.MinValue;
|
||||
|
||||
private bool _stopped;
|
||||
|
||||
private int _consecutiveFailures;
|
||||
|
||||
private bool _backedOff;
|
||||
|
||||
private bool _saidSo;
|
||||
|
||||
private DateTime _lastForeground = DateTime.MinValue;
|
||||
|
||||
private DateTime? _foregroundCheckDue;
|
||||
|
||||
internal TimeSpan? ForegroundCheckDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_stopped && _foregroundCheckDue.HasValue)
|
||||
{
|
||||
return TimeSpan.FromTicks(Math.Max(0L, (_foregroundCheckDue.Value - _now()).Ticks));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool HasBackedOff => _backedOff;
|
||||
|
||||
public ColourWatchdog(Action reapply, Func<bool> isHdrActive, Func<bool> isNeutral, Func<DateTime> now, Action<Exception>? onGaveUp = null, Action? onWorldChanged = null)
|
||||
{
|
||||
_reapply = reapply;
|
||||
_isHdrActive = isHdrActive;
|
||||
_isNeutral = isNeutral;
|
||||
_now = now;
|
||||
_onGaveUp = onGaveUp;
|
||||
_worldChanged = onWorldChanged;
|
||||
}
|
||||
|
||||
public void OnDisplayChanged()
|
||||
{
|
||||
Reassert(force: true, forget: true);
|
||||
}
|
||||
|
||||
public void OnResume()
|
||||
{
|
||||
Reassert(force: true, forget: true);
|
||||
}
|
||||
|
||||
public void OnSessionUnlock()
|
||||
{
|
||||
Reassert(force: true, forget: true);
|
||||
}
|
||||
|
||||
public void OnForegroundChanged()
|
||||
{
|
||||
if (!_stopped)
|
||||
{
|
||||
DateTime dateTime = _now();
|
||||
DateTime dateTime2 = _lastForeground + ForegroundSettle;
|
||||
DateTime dateTime3 = _lastApply + Debounce;
|
||||
if (dateTime3 > dateTime2)
|
||||
{
|
||||
dateTime2 = dateTime3;
|
||||
}
|
||||
if (dateTime < dateTime2)
|
||||
{
|
||||
_foregroundCheckDue = dateTime2;
|
||||
return;
|
||||
}
|
||||
_foregroundCheckDue = null;
|
||||
_lastForeground = dateTime;
|
||||
Reassert(force: true, forget: false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (_stopped)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DateTime? foregroundCheckDue = _foregroundCheckDue;
|
||||
if (foregroundCheckDue.HasValue)
|
||||
{
|
||||
DateTime valueOrDefault = foregroundCheckDue.GetValueOrDefault();
|
||||
if (_now() >= valueOrDefault)
|
||||
{
|
||||
_foregroundCheckDue = null;
|
||||
OnForegroundChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reassert(force: false, forget: false);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_stopped = true;
|
||||
_foregroundCheckDue = null;
|
||||
}
|
||||
|
||||
private void Reassert(bool force, bool forget)
|
||||
{
|
||||
if (_stopped)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (force)
|
||||
{
|
||||
_backedOff = false;
|
||||
}
|
||||
else if (_backedOff)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (_isNeutral() || _isHdrActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DateTime dateTime = _now();
|
||||
if (!(dateTime - _lastApply < (force ? Debounce : TickInterval)))
|
||||
{
|
||||
_lastApply = dateTime;
|
||||
if (forget)
|
||||
{
|
||||
_worldChanged?.Invoke();
|
||||
}
|
||||
_reapply();
|
||||
_consecutiveFailures = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception obj)
|
||||
{
|
||||
_consecutiveFailures++;
|
||||
if (_consecutiveFailures < 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_backedOff = true;
|
||||
if (_saidSo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_saidSo = true;
|
||||
try
|
||||
{
|
||||
_onGaveUp?.Invoke(obj);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class ColourWriteMeter
|
||||
{
|
||||
public int Driver { get; private set; }
|
||||
|
||||
public int Gamma { get; private set; }
|
||||
|
||||
public int Overlay { get; private set; }
|
||||
|
||||
public void CountDriver()
|
||||
{
|
||||
Driver++;
|
||||
}
|
||||
|
||||
internal void CountGamma()
|
||||
{
|
||||
Gamma++;
|
||||
}
|
||||
|
||||
public void CountOverlay()
|
||||
{
|
||||
Overlay++;
|
||||
}
|
||||
|
||||
public void AddGamma(int uploads)
|
||||
{
|
||||
if (uploads > 0)
|
||||
{
|
||||
Gamma += uploads;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public sealed class CompositionKeeper : IDisposable
|
||||
{
|
||||
private struct WNDCLASSEX
|
||||
{
|
||||
public int cbSize;
|
||||
|
||||
public int style;
|
||||
|
||||
public nint lpfnWndProc;
|
||||
|
||||
public int cbClsExtra;
|
||||
|
||||
public int cbWndExtra;
|
||||
|
||||
public nint hInstance;
|
||||
|
||||
public nint hIcon;
|
||||
|
||||
public nint hCursor;
|
||||
|
||||
public nint hbrBackground;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string lpszMenuName;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string lpszClassName;
|
||||
|
||||
public nint hIconSm;
|
||||
}
|
||||
|
||||
private delegate nint WndProcDelegate(nint hWnd, uint msg, nint wParam, nint lParam);
|
||||
|
||||
private const int WS_POPUP = int.MinValue;
|
||||
|
||||
private const int WS_VISIBLE = 268435456;
|
||||
|
||||
private const int WS_EX_TOPMOST = 8;
|
||||
|
||||
private const int WS_EX_TRANSPARENT = 32;
|
||||
|
||||
private const int WS_EX_TOOLWINDOW = 128;
|
||||
|
||||
private const int WS_EX_NOACTIVATE = 134217728;
|
||||
|
||||
private const int WS_EX_LAYERED = 524288;
|
||||
|
||||
private const int LWA_ALPHA = 2;
|
||||
|
||||
private const int SW_SHOWNOACTIVATE = 4;
|
||||
|
||||
private static readonly nint HWND_TOPMOST = new IntPtr(-1);
|
||||
|
||||
private const uint SWP_NOMOVE = 2u;
|
||||
|
||||
private const uint SWP_NOSIZE = 1u;
|
||||
|
||||
private const uint SWP_NOACTIVATE = 16u;
|
||||
|
||||
private const uint SWP_SHOWWINDOW = 64u;
|
||||
|
||||
private const int ReassertIntervalMs = 500;
|
||||
|
||||
private const uint GW_HWNDPREV = 3u;
|
||||
|
||||
private static readonly WndProcDelegate s_wndProc = DefWindowProc;
|
||||
|
||||
private static bool s_classRegistered;
|
||||
|
||||
private const string KeeperClass = "PlexusXCompositionKeeper";
|
||||
|
||||
private nint _hwnd;
|
||||
|
||||
private WinEventListener? _foreground;
|
||||
|
||||
private WinEventListener? _reorder;
|
||||
|
||||
private Timer? _reassert;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public bool IsActive => _hwnd != IntPtr.Zero;
|
||||
|
||||
internal bool ListensRatherThanPolls
|
||||
{
|
||||
get
|
||||
{
|
||||
WinEventListener? foreground = _foreground;
|
||||
if (foreground != null && foreground.IsHooked)
|
||||
{
|
||||
WinEventListener? reorder = _reorder;
|
||||
if (reorder != null && reorder.IsHooked)
|
||||
{
|
||||
return _reassert == null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool PollsAsBackstop => _reassert != null;
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern ushort RegisterClassEx(ref WNDCLASSEX lpwcx);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern nint CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, nint hWndParent, nint hMenu, nint hInstance, nint lpParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern nint DefWindowProc(nint hWnd, uint msg, nint wParam, nint lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowWindow(nint hWnd, int nCmdShow);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool DestroyWindow(nint hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetLayeredWindowAttributes(nint hwnd, uint crKey, byte bAlpha, uint dwFlags);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetWindowPos(nint hWnd, nint hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern nint GetWindow(nint hWnd, uint uCmd);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern nint GetModuleHandle(string? lpModuleName);
|
||||
|
||||
public CompositionKeeper()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
internal CompositionKeeper(Func<uint, uint, Action<nint>, WinEventListener>? listenerFactory)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureClass();
|
||||
_hwnd = CreateWindowEx(134742184, "PlexusXCompositionKeeper", "PlexusX Composition Keeper", -1879048192, 0, 0, 1, 1, IntPtr.Zero, IntPtr.Zero, GetModuleHandle(null), IntPtr.Zero);
|
||||
if (_hwnd == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SetLayeredWindowAttributes(_hwnd, 0u, 1, 2u);
|
||||
ShowWindow(_hwnd, 4);
|
||||
Reassert();
|
||||
_foreground = Listen(listenerFactory, 3u);
|
||||
_reorder = Listen(listenerFactory, 32772u);
|
||||
WinEventListener? foreground = _foreground;
|
||||
if (foreground != null && foreground.IsHooked)
|
||||
{
|
||||
WinEventListener? reorder = _reorder;
|
||||
if (reorder != null && reorder.IsHooked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
_reassert = new Timer
|
||||
{
|
||||
Interval = 500
|
||||
};
|
||||
_reassert.Tick += (object? s, EventArgs e) =>
|
||||
{
|
||||
Reassert();
|
||||
};
|
||||
_reassert.Start();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private WinEventListener Listen(Func<uint, uint, Action<nint>, WinEventListener>? factory, uint evt)
|
||||
{
|
||||
if (factory == null)
|
||||
{
|
||||
return new WinEventListener(evt, evt, (nint _) =>
|
||||
{
|
||||
Reassert();
|
||||
});
|
||||
}
|
||||
return factory(evt, evt, (nint _) =>
|
||||
{
|
||||
Reassert();
|
||||
});
|
||||
}
|
||||
|
||||
private void Reassert()
|
||||
{
|
||||
if (_hwnd != IntPtr.Zero && GetWindow(_hwnd, 3u) != IntPtr.Zero)
|
||||
{
|
||||
SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 1, 1, 19u);
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureClass()
|
||||
{
|
||||
if (!s_classRegistered)
|
||||
{
|
||||
WNDCLASSEX lpwcx = new WNDCLASSEX
|
||||
{
|
||||
cbSize = Marshal.SizeOf<WNDCLASSEX>(),
|
||||
style = 0,
|
||||
lpfnWndProc = Marshal.GetFunctionPointerForDelegate(s_wndProc),
|
||||
hInstance = GetModuleHandle(null),
|
||||
lpszClassName = "PlexusXCompositionKeeper"
|
||||
};
|
||||
RegisterClassEx(ref lpwcx);
|
||||
s_classRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_disposed = true;
|
||||
if (_foreground != null)
|
||||
{
|
||||
_foreground.Dispose();
|
||||
_foreground = null;
|
||||
}
|
||||
if (_reorder != null)
|
||||
{
|
||||
_reorder.Dispose();
|
||||
_reorder = null;
|
||||
}
|
||||
if (_reassert != null)
|
||||
{
|
||||
_reassert.Stop();
|
||||
_reassert.Dispose();
|
||||
_reassert = null;
|
||||
}
|
||||
if (_hwnd != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
DestroyWindow(_hwnd);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
_hwnd = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
internal static class ControlInk
|
||||
{
|
||||
internal const double LockedOpacity = 0.38;
|
||||
|
||||
private static bool Slate => SlateSurface.Active;
|
||||
|
||||
internal static Color Accent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Accent;
|
||||
}
|
||||
return SignalTokens.Slate.Accent;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color AccentHover
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.AccentHover;
|
||||
}
|
||||
return SignalTokens.Slate.AccentHover;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color AccentPressed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.AccentPressed;
|
||||
}
|
||||
return SignalTokens.Slate.AccentPressed;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color OnAccent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.OnAccent;
|
||||
}
|
||||
return SignalTokens.Slate.OnAccent;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Hover
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Hover;
|
||||
}
|
||||
return SignalTokens.Slate.Hover;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Pressed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Pressed;
|
||||
}
|
||||
return SignalTokens.Slate.Pressed;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Surface2
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Surface2;
|
||||
}
|
||||
return SignalTokens.Slate.Surface2;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color FieldFill
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.FieldFill;
|
||||
}
|
||||
return SignalTokens.Slate.FieldFill;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Overlay
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Surface3;
|
||||
}
|
||||
return SignalTokens.Slate.SlateBase;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Edge
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.BorderStrong;
|
||||
}
|
||||
return SignalTokens.Slate.BorderStrong;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Border
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Border;
|
||||
}
|
||||
return SignalTokens.Slate.Border;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color WindowEdge
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.WindowEdge;
|
||||
}
|
||||
return SignalTokens.Slate.WindowEdge;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Track
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Track;
|
||||
}
|
||||
return SignalTokens.Slate.Track;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Focus
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Focus;
|
||||
}
|
||||
return SignalTokens.Slate.Focus;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color KnobRing
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Surface1;
|
||||
}
|
||||
return SignalTokens.Slate.KnobRing;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Text1 => Theme.Text;
|
||||
|
||||
internal static Color Text2 => Theme.TextDim;
|
||||
|
||||
internal static Color Text3 => Theme.TextFaint;
|
||||
|
||||
internal static Color TextDisabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.TextDisabled;
|
||||
}
|
||||
return SignalTokens.Slate.TextDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color TextDisabledInk
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.TextDisabled;
|
||||
}
|
||||
return Over(SignalTokens.Slate.TextDisabled, SignalTokens.Slate.SlateBase);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Danger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Danger;
|
||||
}
|
||||
return SignalTokens.Slate.Danger;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Success
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Success;
|
||||
}
|
||||
return SignalTokens.Slate.Success;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Warning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Warning;
|
||||
}
|
||||
return SignalTokens.Slate.Warning;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color Info
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Slate)
|
||||
{
|
||||
return SignalTokens.Ash.Info;
|
||||
}
|
||||
return SignalTokens.Slate.Info;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Color SelectedSuffix => SignalTokens.Root.PInk2;
|
||||
|
||||
internal static Color Locked(Color ink, Color ground)
|
||||
{
|
||||
int num = (int)Math.Round(0.299 * (double)(int)ink.R + 0.587 * (double)(int)ink.G + 0.114 * (double)(int)ink.B);
|
||||
return Over(Color.FromArgb((int)Math.Round(96.9), num, num, num), Color.FromArgb(255, ground));
|
||||
}
|
||||
|
||||
internal static Color Over(Color top, Color ground)
|
||||
{
|
||||
return Color.FromArgb(255, ground.R + top.A * (top.R - ground.R) / 255, ground.G + top.A * (top.G - ground.G) / 255, ground.B + top.A * (top.B - ground.B) / 255);
|
||||
}
|
||||
|
||||
internal static int Dpi(Control c)
|
||||
{
|
||||
return Math.Max((c.DeviceDpi > 0) ? c.DeviceDpi : 96, Tokens.Dpi);
|
||||
}
|
||||
|
||||
internal static int LabelInkInset(Font font)
|
||||
{
|
||||
int width = TextRenderer.MeasureText("A", font).Width;
|
||||
int width2 = TextRenderer.MeasureText("A", font, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.NoPadding).Width;
|
||||
return Math.Max(0, (width - width2 + 2) / 4);
|
||||
}
|
||||
|
||||
internal static int Px(int dpi, int logical)
|
||||
{
|
||||
return Tokens.ScaleAt(dpi, logical);
|
||||
}
|
||||
|
||||
internal static float PxF(int dpi, float logical)
|
||||
{
|
||||
return logical * (float)dpi / 96f;
|
||||
}
|
||||
|
||||
internal static int Hairline(int dpi)
|
||||
{
|
||||
return Math.Max(1, dpi / 96);
|
||||
}
|
||||
|
||||
internal static Color Mix(Color a, Color b, float t)
|
||||
{
|
||||
t = Math.Clamp(t, 0f, 1f);
|
||||
if (t <= 0f)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
if (t >= 1f)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
return Color.FromArgb((int)Math.Round((float)(int)a.A + (float)(b.A - a.A) * t), (int)Math.Round((float)(int)a.R + (float)(b.R - a.R) * t), (int)Math.Round((float)(int)a.G + (float)(b.G - a.G) * t), (int)Math.Round((float)(int)a.B + (float)(b.B - a.B) * t));
|
||||
}
|
||||
|
||||
internal static void PaintBox(Graphics g, Size size, float radius, int line, Color fill, Color edge)
|
||||
{
|
||||
if (size.Width < 2 || size.Height < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
try
|
||||
{
|
||||
bool flag = edge.A > 0;
|
||||
if (fill.A > 0)
|
||||
{
|
||||
float num = (flag ? ((float)line / 2f) : 0f);
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(num, num, (float)size.Width - 2f * num, (float)size.Height - 2f * num), Math.Max(0f, radius - num));
|
||||
using SolidBrush brush = new SolidBrush(fill);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float num2 = (float)line / 2f;
|
||||
using GraphicsPath path2 = Glass.RoundedPath(new RectangleF(num2, num2, size.Width - line, size.Height - line), Math.Max(0f, radius - num2));
|
||||
using Pen pen = new Pen(edge, line);
|
||||
g.DrawPath(pen, path2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void PaintFocusRing(Graphics g, Rectangle bounds, float radius, int dpi)
|
||||
{
|
||||
int num = Px(dpi, 2);
|
||||
float num2 = (float)Px(dpi, 2) + (float)num / 2f;
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
try
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF((float)bounds.X - num2, (float)bounds.Y - num2, (float)bounds.Width + 2f * num2, (float)bounds.Height + 2f * num2), radius + num2);
|
||||
using Pen pen = new Pen(Focus, num);
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
internal static int FocusRingReach(int dpi)
|
||||
{
|
||||
return Px(dpi, 2) + Px(dpi, 2) + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class BrowserWontOpenDialog : SignalDialogWindow
|
||||
{
|
||||
public const string Title = "We couldn't open your browser";
|
||||
|
||||
public const string Body = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.";
|
||||
|
||||
public const string ShortSentence = "We couldn't open your browser. Copy the link and open it yourself.";
|
||||
|
||||
public const string CopyLabel = "Copy link";
|
||||
|
||||
public const string CloseLabel = "Close";
|
||||
|
||||
public const string Copied = "Copied. Paste it into your browser.";
|
||||
|
||||
private const int WidthLogical = 560;
|
||||
|
||||
private const int LinkHeight = 32;
|
||||
|
||||
private const int HintHeight = 16;
|
||||
|
||||
private const int HintGap = 8;
|
||||
|
||||
internal const int Chrome = 208;
|
||||
|
||||
private readonly string _url;
|
||||
|
||||
private readonly string _displayUrl;
|
||||
|
||||
private readonly int _linkHeight;
|
||||
|
||||
private readonly GlassButton _copyButton;
|
||||
|
||||
private readonly Action<string> _copy;
|
||||
|
||||
private string _hint = "";
|
||||
|
||||
internal string HintForTest => _hint;
|
||||
|
||||
internal static Action<string>? InsteadOfShowingForTest { get; set; }
|
||||
|
||||
internal static int MeasureHeight(string body, int width, string url = "")
|
||||
{
|
||||
int num = Math.Max(80, width - 48);
|
||||
int val = (int)Math.Ceiling((double)(SignalDialogWindow.MeasureBody(body, Tokens.Scale(num)) * 96) / (double)Tokens.Dpi);
|
||||
int num2 = (int)Math.Ceiling((double)(MeasureLink(url, Tokens.Scale(num - 24), Tokens.Scale(16), out string _) * 96) / (double)Tokens.Dpi);
|
||||
return 208 + Math.Min(val, 200) + Math.Max(0, num2 - 32);
|
||||
}
|
||||
|
||||
internal BrowserWontOpenDialog(string url, Action<string> copy)
|
||||
{
|
||||
_url = url ?? "";
|
||||
_copy = copy ?? throw new ArgumentNullException("copy");
|
||||
ShowInTaskbar = true;
|
||||
TopMost = true;
|
||||
Text = "PlexusX";
|
||||
AccessibleName = "We couldn't open your browser";
|
||||
AccessibleDescription = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there. " + _url;
|
||||
ChromeTitle = "We couldn't open your browser";
|
||||
ChromeBody = "PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.";
|
||||
int num = S(560);
|
||||
_linkHeight = Math.Max(S(32), MeasureLink(_url, num - 2 * S(24) - S(24), S(16), out _displayUrl));
|
||||
ChromeBodyHeight = Math.Min(SignalDialogWindow.MeasureBody("PlexusX asked Windows to open your browser and nothing happened. Copy the link below, paste it into your browser, and carry on there.", num - 2 * S(24)), S(200));
|
||||
ClientSize = new Size(num, BodyTop + ChromeBodyHeight + S(16) + _linkHeight + S(8) + S(16) + S(24) + S(32) + S(20));
|
||||
GlassButton glassButton = FooterButton("Close", GlassButtonKind.Secondary, "BrowserWontOpenClose");
|
||||
glassButton.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Close();
|
||||
};
|
||||
_copyButton = FooterButton("Copy link", GlassButtonKind.Primary, "BrowserWontOpenCopy");
|
||||
_copyButton.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
CopyTheLink();
|
||||
};
|
||||
Controls.Add(glassButton);
|
||||
Controls.Add(_copyButton);
|
||||
PlaceFooter(glassButton, _copyButton);
|
||||
_copyButton.TabIndex = 0;
|
||||
glassButton.TabIndex = 1;
|
||||
ActiveControl = _copyButton;
|
||||
WindowDrag.Enable(this, this);
|
||||
}
|
||||
|
||||
private static int MeasureLink(string url, int width, int padding, out string display)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int num;
|
||||
for (int i = 0; i < url.Length; i += num)
|
||||
{
|
||||
num = 1;
|
||||
int num2 = url.Length - i;
|
||||
while (num < num2)
|
||||
{
|
||||
int num3 = (num + num2 + 1) / 2;
|
||||
if (TextRenderer.MeasureText(url.Substring(i, num3), Fonts.Body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine).Width <= width)
|
||||
{
|
||||
num = num3;
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 = num3 - 1;
|
||||
}
|
||||
}
|
||||
if (stringBuilder.Length > 0)
|
||||
{
|
||||
stringBuilder.Append('\n');
|
||||
}
|
||||
stringBuilder.Append(url, i, num);
|
||||
}
|
||||
display = stringBuilder.ToString();
|
||||
Size proposedSize = new Size(Math.Max(1, width), int.MaxValue);
|
||||
return Math.Max(TextRenderer.MeasureText(display, Fonts.Body, proposedSize, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height, TextRenderer.MeasureText(url, Fonts.Body, proposedSize, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height) + padding;
|
||||
}
|
||||
|
||||
private void CopyTheLink()
|
||||
{
|
||||
try
|
||||
{
|
||||
_copy(_url);
|
||||
_hint = "Copied. Paste it into your browser.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CrashLog.Write(ex);
|
||||
_hint = "Windows would not let us copy it. Type the link above into your browser.";
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
internal void PressCopyForTest()
|
||||
{
|
||||
CopyTheLink();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
e.Handled = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
int x = S(24);
|
||||
int textWidth = TextWidth;
|
||||
Rectangle rect = new Rectangle(x, ContentTop, textWidth, _linkHeight);
|
||||
GraphicsState gstate = graphics.Save();
|
||||
graphics.TranslateTransform(rect.X, rect.Y);
|
||||
ControlInk.PaintBox(graphics, rect.Size, S(4), ControlInk.Hairline(ChromeDpi), ControlInk.FieldFill, ControlInk.Edge);
|
||||
graphics.Restore(gstate);
|
||||
TextRenderer.DrawText(graphics, _displayUrl, Fonts.Body, Rectangle.Inflate(rect, -S(12), -S(8)), ControlInk.Text1, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak);
|
||||
if (_hint.Length > 0)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, _hint, Fonts.Caption, new Rectangle(x, rect.Bottom + S(8), textWidth, S(16)), ControlInk.Text2, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ShowFor(IWin32Window? owner, string url)
|
||||
{
|
||||
Action<string> insteadOfShowingForTest = InsteadOfShowingForTest;
|
||||
if (insteadOfShowingForTest != null)
|
||||
{
|
||||
insteadOfShowingForTest(url);
|
||||
return;
|
||||
}
|
||||
using BrowserWontOpenDialog browserWontOpenDialog = new BrowserWontOpenDialog(url, ToTheClipboard);
|
||||
if (owner != null)
|
||||
{
|
||||
browserWontOpenDialog.ShowDialog(owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
browserWontOpenDialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToTheClipboard(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || TheClipboard.Put(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw new InvalidOperationException("Windows would not let go of the clipboard.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class CaptionButton : Control
|
||||
{
|
||||
public enum Kind
|
||||
{
|
||||
Minimise,
|
||||
Close
|
||||
}
|
||||
|
||||
private readonly Kind _kind;
|
||||
|
||||
private bool _hot;
|
||||
|
||||
private bool _down;
|
||||
|
||||
internal bool HotForTest
|
||||
{
|
||||
set
|
||||
{
|
||||
_hot = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
internal bool PressedForTest
|
||||
{
|
||||
set
|
||||
{
|
||||
_down = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public CaptionButton(Kind kind)
|
||||
{
|
||||
_kind = kind;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
AccessibleRole = AccessibleRole.PushButton;
|
||||
AccessibleName = ((kind == Kind.Close) ? "Close" : "Minimise");
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
_hot = true;
|
||||
Invalidate();
|
||||
base.OnMouseEnter(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
_hot = false;
|
||||
_down = false;
|
||||
Invalidate();
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
_down = true;
|
||||
Invalidate();
|
||||
}
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
_down = false;
|
||||
Invalidate();
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
if (_down || _hot)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(_down ? ControlInk.Pressed : ControlInk.Hover);
|
||||
graphics.FillRectangle(brush, 0, 0, Width, Height);
|
||||
}
|
||||
using Pen pen = new Pen((_hot || _down) ? Theme.Text : Theme.TextDim, 1.4f);
|
||||
PaintGlyph(graphics, pen, GlyphBox());
|
||||
}
|
||||
|
||||
private void PaintGlyph(Graphics g, Pen pen, Rectangle r)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float num = (float)r.Top + (float)(r.Height + 1) / 2f;
|
||||
if (_kind == Kind.Minimise)
|
||||
{
|
||||
g.DrawLine(pen, r.Left, num, r.Right, num);
|
||||
return;
|
||||
}
|
||||
g.DrawLine(pen, r.Left, r.Top, r.Right, r.Bottom);
|
||||
g.DrawLine(pen, r.Right, r.Top, r.Left, r.Bottom);
|
||||
}
|
||||
|
||||
private Rectangle GlyphBox()
|
||||
{
|
||||
int num = Tokens.Scale(9);
|
||||
return new Rectangle((Width - num) / 2, (Height - num) / 2, num, num);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class ColourWheel : Control
|
||||
{
|
||||
private const int BarWidth = 18;
|
||||
|
||||
private const int BarGap = 12;
|
||||
|
||||
private Bitmap? _wheel;
|
||||
|
||||
private int _wheelDiameter;
|
||||
|
||||
private float _hue;
|
||||
|
||||
private float _saturation;
|
||||
|
||||
private float _value = 1f;
|
||||
|
||||
private bool _draggingWheel;
|
||||
|
||||
private bool _draggingBar;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private int _failedDiameter;
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
public Color Colour
|
||||
{
|
||||
get
|
||||
{
|
||||
return FromHsv(_hue, _saturation, _value);
|
||||
}
|
||||
set
|
||||
{
|
||||
ToHsv(value, out _hue, out _saturation, out _value);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int Diameter => Math.Max(8, Math.Min(Width - 18 - 12, Height));
|
||||
|
||||
private Rectangle WheelRect => new Rectangle(0, (Height - Diameter) / 2, Diameter, Diameter);
|
||||
|
||||
private Rectangle BarRect => new Rectangle(Width - 18, 4, 17, Math.Max(8, Height - 9));
|
||||
|
||||
public event EventHandler? ColourChanged;
|
||||
|
||||
public ColourWheel()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
AccessibleRole = AccessibleRole.Slider;
|
||||
AccessibleName = "Colour picker";
|
||||
Size = new Size(180, 160);
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 4f));
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
if (BarRect.Contains(e.Location))
|
||||
{
|
||||
_draggingBar = true;
|
||||
DragTracker.Begin();
|
||||
TakeBar(e.Y);
|
||||
}
|
||||
else if (WheelRect.Contains(e.Location))
|
||||
{
|
||||
_draggingWheel = true;
|
||||
DragTracker.Begin();
|
||||
TakeWheel(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_draggingBar)
|
||||
{
|
||||
TakeBar(e.Y);
|
||||
}
|
||||
else if (_draggingWheel)
|
||||
{
|
||||
TakeWheel(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_draggingWheel || _draggingBar)
|
||||
{
|
||||
DragTracker.End();
|
||||
}
|
||||
_draggingWheel = false;
|
||||
_draggingBar = false;
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case Keys.Left:
|
||||
_hue = (_hue + 355f) % 360f;
|
||||
break;
|
||||
case Keys.Right:
|
||||
_hue = (_hue + 5f) % 360f;
|
||||
break;
|
||||
case Keys.Up:
|
||||
_value = Math.Min(1f, _value + 0.05f);
|
||||
break;
|
||||
case Keys.Down:
|
||||
_value = Math.Max(0f, _value - 0.05f);
|
||||
break;
|
||||
case Keys.Prior:
|
||||
_saturation = Math.Min(1f, _saturation + 0.1f);
|
||||
break;
|
||||
case Keys.Next:
|
||||
_saturation = Math.Max(0f, _saturation - 0.1f);
|
||||
break;
|
||||
case Keys.End:
|
||||
case Keys.Home:
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
internal bool TestClaimsKey(Keys key)
|
||||
{
|
||||
return IsInputKey(key);
|
||||
}
|
||||
|
||||
protected override bool IsInputKey(Keys keyData)
|
||||
{
|
||||
if ((uint)(keyData - 33) <= 1u || (uint)(keyData - 37) <= 3u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return base.IsInputKey(keyData);
|
||||
}
|
||||
|
||||
private void TakeWheel(Point p)
|
||||
{
|
||||
Rectangle wheelRect = WheelRect;
|
||||
float num = (float)wheelRect.X + (float)wheelRect.Width / 2f;
|
||||
float num2 = (float)wheelRect.Y + (float)wheelRect.Height / 2f;
|
||||
float num3 = (float)p.X - num;
|
||||
float num4 = (float)p.Y - num2;
|
||||
float num5 = (float)wheelRect.Width / 2f;
|
||||
float num6 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
|
||||
_saturation = Math.Clamp(num6 / num5, 0f, 1f);
|
||||
_hue = (float)((Math.Atan2(num4, num3) * 180.0 / Math.PI + 360.0) % 360.0);
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void TakeBar(int y)
|
||||
{
|
||||
Rectangle barRect = BarRect;
|
||||
_value = 1f - Math.Clamp((float)(y - barRect.Y) / (float)barRect.Height, 0f, 1f);
|
||||
Invalidate();
|
||||
ColourChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintBody(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintBody(Graphics g)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Rectangle wheelRect = WheelRect;
|
||||
if (wheelRect.Width > 8)
|
||||
{
|
||||
EnsureWheel(wheelRect.Width);
|
||||
using Region clip = g.Clip;
|
||||
using (GraphicsPath graphicsPath = new GraphicsPath())
|
||||
{
|
||||
graphicsPath.AddEllipse(wheelRect);
|
||||
g.SetClip(graphicsPath);
|
||||
if (_wheel != null)
|
||||
{
|
||||
g.DrawImage(_wheel, wheelRect);
|
||||
}
|
||||
if (_value < 1f)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Color.FromArgb((int)(255f * (1f - _value)), 0, 0, 0));
|
||||
g.FillRectangle(brush, wheelRect);
|
||||
}
|
||||
}
|
||||
g.Clip = clip;
|
||||
DrawWheelMarker(g, wheelRect);
|
||||
}
|
||||
DrawBar(g);
|
||||
if (Focused && ShowFocusCues)
|
||||
{
|
||||
_ring.Show(Enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ring.Show(show: false);
|
||||
}
|
||||
if (!Enabled)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(158, Theme.Background)))
|
||||
{
|
||||
g.FillRectangle(brush2, ClientRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void DrawWheelMarker(Graphics g, Rectangle wheel)
|
||||
{
|
||||
float num = (float)wheel.Width / 2f;
|
||||
float num2 = (float)((double)_hue * Math.PI / 180.0);
|
||||
float num3 = (float)wheel.X + num + (float)Math.Cos(num2) * num * _saturation;
|
||||
float num4 = (float)wheel.Y + num + (float)Math.Sin(num2) * num * _saturation;
|
||||
RectangleF rect = new RectangleF(num3 - 6f, num4 - 6f, 12f, 12f);
|
||||
using (Pen pen = new Pen(Color.FromArgb(200, 0, 0, 0), 3f))
|
||||
{
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
using Pen pen2 = new Pen(Color.White, 1.6f);
|
||||
g.DrawEllipse(pen2, rect);
|
||||
}
|
||||
|
||||
private void DrawBar(Graphics g)
|
||||
{
|
||||
Rectangle barRect = BarRect;
|
||||
if (barRect.Height <= 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Color color = FromHsv(_hue, _saturation, 1f);
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(barRect, color, Color.Black, 90f))
|
||||
{
|
||||
g.FillRectangle(brush, barRect);
|
||||
}
|
||||
using (Pen pen = new Pen(Color.FromArgb(90, Theme.GlassEdge), 1f))
|
||||
{
|
||||
g.DrawRectangle(pen, barRect);
|
||||
}
|
||||
int num = barRect.Y + (int)((1f - _value) * (float)barRect.Height);
|
||||
using (Pen pen2 = new Pen(Color.FromArgb(200, 0, 0, 0), 3f))
|
||||
{
|
||||
g.DrawLine(pen2, barRect.X, num, barRect.Right, num);
|
||||
}
|
||||
using Pen pen3 = new Pen(Color.White, 1.4f);
|
||||
g.DrawLine(pen3, barRect.X, num, barRect.Right, num);
|
||||
}
|
||||
|
||||
private void EnsureWheel(int diameter)
|
||||
{
|
||||
if ((_wheel == null || _wheelDiameter != diameter) && _failedDiameter != diameter)
|
||||
{
|
||||
Bitmap wheel;
|
||||
try
|
||||
{
|
||||
FailPointForTest?.Invoke("build");
|
||||
wheel = BuildWheel(diameter);
|
||||
}
|
||||
catch (Exception ex) when (PaintGuard.IsGdiFailure(ex))
|
||||
{
|
||||
_wheel?.Dispose();
|
||||
_wheel = null;
|
||||
_wheelDiameter = 0;
|
||||
_failedDiameter = diameter;
|
||||
throw;
|
||||
}
|
||||
Bitmap? wheel2 = _wheel;
|
||||
_wheel = wheel;
|
||||
_wheelDiameter = diameter;
|
||||
_failedDiameter = 0;
|
||||
wheel2?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap BuildWheel(int diameter)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(diameter, diameter, PixelFormat.Format32bppArgb);
|
||||
float num = (float)diameter / 2f;
|
||||
BitmapData bitmapData;
|
||||
try
|
||||
{
|
||||
bitmapData = bitmap.LockBits(new Rectangle(0, 0, diameter, diameter), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
catch
|
||||
{
|
||||
bitmap.Dispose();
|
||||
throw;
|
||||
}
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
byte[] array = new byte[bitmapData.Stride];
|
||||
for (int i = 0; i < diameter; i++)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
for (int j = 0; j < diameter; j++)
|
||||
{
|
||||
float num2 = (float)j - num + 0.5f;
|
||||
float num3 = (float)i - num + 0.5f;
|
||||
float num4 = (float)Math.Sqrt(num2 * num2 + num3 * num3);
|
||||
if (!(num4 > num))
|
||||
{
|
||||
Color color = FromHsv((float)((Math.Atan2(num3, num2) * 180.0 / Math.PI + 360.0) % 360.0), Math.Min(1f, num4 / num), 1f);
|
||||
byte b = ((num4 > num - 1.2f) ? ((byte)(255f * Math.Clamp(num - num4, 0f, 1.2f) / 1.2f)) : byte.MaxValue);
|
||||
int num5 = j * 4;
|
||||
array[num5] = color.B;
|
||||
array[num5 + 1] = color.G;
|
||||
array[num5 + 2] = color.R;
|
||||
array[num5 + 3] = b;
|
||||
}
|
||||
}
|
||||
Marshal.Copy(array, 0, bitmapData.Scan0 + i * bitmapData.Stride, bitmapData.Stride);
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
if (!flag)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Color FromHsv(float hue, float saturation, float value)
|
||||
{
|
||||
hue = (hue % 360f + 360f) % 360f;
|
||||
saturation = Math.Clamp(saturation, 0f, 1f);
|
||||
value = Math.Clamp(value, 0f, 1f);
|
||||
float num = value * saturation;
|
||||
float num2 = num * (1f - Math.Abs(hue / 60f % 2f - 1f));
|
||||
float num3 = value - num;
|
||||
var (num4, num5, num6) = ((hue < 60f) ? (num, num2, 0f) : ((hue < 120f) ? (num2, num, 0f) : ((hue < 180f) ? (0f, num, num2) : ((hue < 240f) ? (0f, num2, num) : ((!(hue < 300f)) ? (num, 0f, num2) : (num2, 0f, num))))));
|
||||
return Color.FromArgb(255, (int)Math.Round((num4 + num3) * 255f), (int)Math.Round((num5 + num3) * 255f), (int)Math.Round((num6 + num3) * 255f));
|
||||
}
|
||||
|
||||
public static string ToHex(Color colour)
|
||||
{
|
||||
return $"{colour.R:X2}{colour.G:X2}{colour.B:X2}";
|
||||
}
|
||||
|
||||
public static bool TryParseHex(string? text, out Color colour)
|
||||
{
|
||||
colour = Color.Empty;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text2 = text.Trim().TrimStart('#');
|
||||
int length = text2.Length;
|
||||
if ((length != 3 && length != 6) || 1 == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text3 = text2;
|
||||
for (length = 0; length < text3.Length; length++)
|
||||
{
|
||||
if (!Uri.IsHexDigit(text3[length]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (text2.Length == 3)
|
||||
{
|
||||
text2 = string.Concat(text2[0], text2[0], text2[1], text2[1], text2[2], text2[2]);
|
||||
}
|
||||
colour = Color.FromArgb(255, Convert.ToInt32(text2.Substring(0, 2), 16), Convert.ToInt32(text2.Substring(2, 2), 16), Convert.ToInt32(text2.Substring(4, 2), 16));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ToHsv(Color colour, out float hue, out float saturation, out float value)
|
||||
{
|
||||
float num = (float)(int)colour.R / 255f;
|
||||
float num2 = (float)(int)colour.G / 255f;
|
||||
float num3 = (float)(int)colour.B / 255f;
|
||||
float num4 = Math.Max(num, Math.Max(num2, num3));
|
||||
float num5 = Math.Min(num, Math.Min(num2, num3));
|
||||
float num6 = num4 - num5;
|
||||
value = num4;
|
||||
saturation = ((num4 <= 0f) ? 0f : (num6 / num4));
|
||||
if (num6 <= 0f)
|
||||
{
|
||||
hue = 0f;
|
||||
return;
|
||||
}
|
||||
float num7;
|
||||
if (num4 == num)
|
||||
{
|
||||
num7 = 60f * ((num2 - num3) / num6 % 6f);
|
||||
}
|
||||
else
|
||||
{
|
||||
num7 = ((num4 == num2) ? (60f * ((num3 - num) / num6 + 2f)) : (60f * ((num - num2) / num6 + 4f)));
|
||||
}
|
||||
hue = num7;
|
||||
hue = (hue % 360f + 360f) % 360f;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_wheel?.Dispose();
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class CrosshairCell : Control
|
||||
{
|
||||
private const int HeartSize = 16;
|
||||
|
||||
private bool _hover;
|
||||
|
||||
private bool _hoverHeart;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private bool _active;
|
||||
|
||||
private bool _favourite;
|
||||
|
||||
public CrosshairGallery.GalleryItem Item { get; }
|
||||
|
||||
public CrosshairConfig? PreviewStyle { get; set; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Favourite
|
||||
{
|
||||
get
|
||||
{
|
||||
return _favourite;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_favourite != value)
|
||||
{
|
||||
_favourite = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Color TextOnFill
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!SlateSurface.Active)
|
||||
{
|
||||
return SignalTokens.Ash.TextOnFill;
|
||||
}
|
||||
return SignalTokens.Slate.TextOnFill;
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle HeartRect => new Rectangle(Width - 16 - 6, 6, 16, 16);
|
||||
|
||||
private static int NameStrip => Math.Max(Fonts.LineHeight(FontRole.Caption), TextRenderer.MeasureText("Hg", Fonts.Caption).Height);
|
||||
|
||||
public event EventHandler? FavouriteToggled;
|
||||
|
||||
public CrosshairCell(CrosshairGallery.GalleryItem item)
|
||||
{
|
||||
Item = item;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
TabStop = true;
|
||||
AccessibleRole = AccessibleRole.PushButton;
|
||||
AccessibleName = item.Name;
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 4f));
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
bool flag = HeartRect.Contains(e.Location);
|
||||
if (flag != _hoverHeart)
|
||||
{
|
||||
_hoverHeart = flag;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_hover = true;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = false;
|
||||
_hoverHeart = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left && HeartRect.Contains(e.Location))
|
||||
{
|
||||
FavouriteToggled?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
RectangleF rect = new RectangleF(0f, 0f, Width, Height);
|
||||
float num = Tokens.Scale(4);
|
||||
using (GraphicsPath path = Glass.RoundedPath(rect, num))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush((_hover && !_active) ? ControlInk.Hover : ControlInk.Surface2);
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
if (_active)
|
||||
{
|
||||
float num2 = Tokens.Scale(2);
|
||||
using Pen pen = new Pen(ControlInk.Accent, num2);
|
||||
using GraphicsPath path2 = Glass.RoundedPath(RectangleF.Inflate(rect, (0f - num2) / 2f, (0f - num2) / 2f), Math.Max(1f, num - num2 / 2f));
|
||||
graphics.DrawPath(pen, path2);
|
||||
}
|
||||
DrawPreview(graphics);
|
||||
DrawHeart(graphics);
|
||||
DrawName(graphics);
|
||||
if (Focused && ShowFocusCues)
|
||||
{
|
||||
_ring.Show(Enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ring.Show(show: false);
|
||||
}
|
||||
}
|
||||
|
||||
private (Rectangle Glyph, Rectangle Name) Column()
|
||||
{
|
||||
int num = Tokens.Scale(36);
|
||||
int num2 = Tokens.Scale(8);
|
||||
int nameStrip = NameStrip;
|
||||
int num3 = Math.Max(0, (Height - num - num2 - nameStrip) / 2);
|
||||
return (Glyph: new Rectangle((Width - num) / 2, num3, num, num), Name: new Rectangle(2, num3 + num + num2, Width - 4, nameStrip));
|
||||
}
|
||||
|
||||
private void DrawPreview(Graphics g)
|
||||
{
|
||||
CrosshairConfig crosshairConfig = Item.Config.Clone();
|
||||
if (PreviewStyle != null)
|
||||
{
|
||||
crosshairConfig.ColourArgb = PreviewStyle.ColourArgb;
|
||||
crosshairConfig.Opacity = PreviewStyle.Opacity;
|
||||
crosshairConfig.Outline = PreviewStyle.Outline;
|
||||
}
|
||||
Rectangle item = Column().Glyph;
|
||||
if (item.Width > 4)
|
||||
{
|
||||
CrosshairRender.Draw(g, crosshairConfig, item, (float)Tokens.Scale(100) / 100f);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHeart(Graphics g)
|
||||
{
|
||||
if (!_favourite && !_hover)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Rectangle heartRect = HeartRect;
|
||||
Color color = (_favourite ? Theme.Text : Color.FromArgb(_hoverHeart ? 200 : 90, Theme.GlassEdge));
|
||||
using GraphicsPath path = HeartPath(heartRect);
|
||||
if (_favourite)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
using Pen pen = new Pen(color, 1.4f);
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
|
||||
private static GraphicsPath HeartPath(Rectangle r)
|
||||
{
|
||||
GraphicsPath graphicsPath = new GraphicsPath();
|
||||
float num = r.Width;
|
||||
float num2 = r.Height;
|
||||
float num3 = (float)r.X + num / 2f;
|
||||
graphicsPath.AddBezier(num3, (float)r.Y + num2 * 0.28f, num3, r.Y, r.X, (float)r.Y + num2 * 0.05f, r.X, (float)r.Y + num2 * 0.38f);
|
||||
graphicsPath.AddBezier(r.X, (float)r.Y + num2 * 0.38f, r.X, (float)r.Y + num2 * 0.68f, num3, (float)r.Y + num2 * 0.82f, num3, r.Bottom);
|
||||
graphicsPath.AddBezier(num3, r.Bottom, num3, (float)r.Y + num2 * 0.82f, r.Right, (float)r.Y + num2 * 0.68f, r.Right, (float)r.Y + num2 * 0.38f);
|
||||
graphicsPath.AddBezier(r.Right, (float)r.Y + num2 * 0.38f, r.Right, (float)r.Y + num2 * 0.05f, num3, r.Y, num3, (float)r.Y + num2 * 0.28f);
|
||||
graphicsPath.CloseFigure();
|
||||
return graphicsPath;
|
||||
}
|
||||
|
||||
private void DrawName(Graphics g)
|
||||
{
|
||||
Graphics dc = g;
|
||||
string name = Item.Name;
|
||||
Font caption = Fonts.Caption;
|
||||
Rectangle item = Column().Name;
|
||||
Color foreColor;
|
||||
if (Enabled)
|
||||
{
|
||||
foreColor = ((_active || _hover) ? ControlInk.Text1 : TextOnFill);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreColor = ControlInk.TextDisabledInk;
|
||||
}
|
||||
TextRenderer.DrawText(dc, name, caption, item, foreColor, TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GameProfileManagerSection
|
||||
{
|
||||
private sealed class Row
|
||||
{
|
||||
public GameProfile Profile;
|
||||
|
||||
public Label Name;
|
||||
|
||||
public Label Detail;
|
||||
|
||||
public GlassButton Rename;
|
||||
|
||||
public GlassButton Delete;
|
||||
}
|
||||
|
||||
private readonly Control _parent;
|
||||
|
||||
private readonly Font _bodyFont;
|
||||
|
||||
private readonly Font _captionFont;
|
||||
|
||||
private readonly Func<string, bool>? _isRunning;
|
||||
|
||||
private readonly Func<IReadOnlyList<GameProfile>> _load;
|
||||
|
||||
private readonly Action<GameProfile> _save;
|
||||
|
||||
private readonly Action<string> _remove;
|
||||
|
||||
private readonly Func<string?>? _runningGameName;
|
||||
|
||||
private readonly Action? _saveCurrentLook;
|
||||
|
||||
private readonly Label _caption;
|
||||
|
||||
private readonly Label _empty;
|
||||
|
||||
private readonly GlassButton _saveNow;
|
||||
|
||||
private readonly Label _saveHint;
|
||||
|
||||
private readonly List<Row> _rows = new List<Row>();
|
||||
|
||||
public const string RowNameControl = "profileRowName";
|
||||
|
||||
public const string RowDetailControl = "profileRowDetail";
|
||||
|
||||
public const string SaveNowControl = "profileSaveNow";
|
||||
|
||||
public const string SaveHintControl = "profileSaveHint";
|
||||
|
||||
private bool _visible = true;
|
||||
|
||||
private static int RowHeight => Tokens.Scale(54);
|
||||
|
||||
private static int HeaderHeight => Math.Max(Tokens.Scale(22), Tokens.Scale(28));
|
||||
|
||||
private static int HintHeight => Tokens.Scale(20);
|
||||
|
||||
public int PreferredHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = HeaderHeight + Tokens.Scale(6);
|
||||
if (_saveHint.Visible)
|
||||
{
|
||||
num += HintHeight + Tokens.Scale(6);
|
||||
}
|
||||
return num + ((_rows.Count == 0) ? Tokens.Scale(36) : (_rows.Count * RowHeight));
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? Changed;
|
||||
|
||||
public GameProfileManagerSection(Control parent, Font captionFont, Font bodyFont, Func<IReadOnlyList<GameProfile>>? load = null, Action<GameProfile>? save = null, Action<string>? remove = null, Func<string, bool>? isRunning = null, Func<string?>? runningGameName = null, Action? saveCurrentLook = null)
|
||||
{
|
||||
_parent = parent;
|
||||
_bodyFont = bodyFont;
|
||||
_captionFont = captionFont;
|
||||
_isRunning = isRunning;
|
||||
_runningGameName = runningGameName;
|
||||
_saveCurrentLook = saveCurrentLook;
|
||||
_load = load ?? new Func<IReadOnlyList<GameProfile>>(GameProfileStore.Load);
|
||||
_save = save ?? new Action<GameProfile>(GameProfileStore.Set);
|
||||
_remove = remove ?? new Action<string>(GameProfileStore.Remove);
|
||||
_caption = new Label
|
||||
{
|
||||
Text = UiHelpers.Spaced("SAVED GAME PROFILES"),
|
||||
Font = captionFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft
|
||||
};
|
||||
_parent.Controls.Add(_caption);
|
||||
_empty = new Label
|
||||
{
|
||||
Text = "No saved profiles yet. Pick a game above and save the look on screen, and it will show up here.",
|
||||
Font = bodyFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft
|
||||
};
|
||||
_parent.Controls.Add(_empty);
|
||||
_saveNow = new GlassButton
|
||||
{
|
||||
Text = "Save my colours",
|
||||
Kind = GlassButtonKind.Primary,
|
||||
Name = "profileSaveNow",
|
||||
Visible = false
|
||||
};
|
||||
_saveNow.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
SaveCurrentLookFlow();
|
||||
};
|
||||
_parent.Controls.Add(_saveNow);
|
||||
_saveHint = new Label
|
||||
{
|
||||
Text = "Open a game and this is where you save the colours you're looking at.",
|
||||
Font = bodyFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Name = "profileSaveHint",
|
||||
Visible = false
|
||||
};
|
||||
_parent.Controls.Add(_saveHint);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
foreach (Row row2 in _rows)
|
||||
{
|
||||
_parent.Controls.Remove(row2.Name);
|
||||
_parent.Controls.Remove(row2.Detail);
|
||||
_parent.Controls.Remove(row2.Rename);
|
||||
_parent.Controls.Remove(row2.Delete);
|
||||
row2.Name.Dispose();
|
||||
row2.Detail.Dispose();
|
||||
row2.Rename.Dispose();
|
||||
row2.Delete.Dispose();
|
||||
}
|
||||
_rows.Clear();
|
||||
foreach (GameProfile item in (from p in _load()
|
||||
orderby IsRunningNow(p) descending, ChangesSomething(p) descending
|
||||
select p).ThenBy((GameProfile p) => p.DisplayName, StringComparer.OrdinalIgnoreCase).ToList())
|
||||
{
|
||||
GameProfile captured = item;
|
||||
Row row = new Row
|
||||
{
|
||||
Profile = captured
|
||||
};
|
||||
bool flag = IsRunningNow(captured);
|
||||
row.Name = new Label
|
||||
{
|
||||
Text = (flag ? (captured.DisplayName + " ● running now") : captured.DisplayName),
|
||||
Font = _bodyFont,
|
||||
ForeColor = (flag ? Theme.Accent : Theme.Text),
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Name.Name = "profileRowName";
|
||||
_parent.Controls.Add(row.Name);
|
||||
row.Detail = new Label
|
||||
{
|
||||
Text = (ChangesSomething(captured) ? GameProfileSection.Describe(captured) : "Changes nothing yet — set your colours with this game open, then save."),
|
||||
Font = _captionFont,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Detail.Name = "profileRowDetail";
|
||||
_parent.Controls.Add(row.Detail);
|
||||
row.Rename = new GlassButton
|
||||
{
|
||||
Text = "Rename",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Rename.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
RenameFlow(captured);
|
||||
};
|
||||
_parent.Controls.Add(row.Rename);
|
||||
row.Delete = new GlassButton
|
||||
{
|
||||
Text = "Delete",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Visible = _visible
|
||||
};
|
||||
row.Delete.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
DeleteFlow(captured);
|
||||
};
|
||||
_parent.Controls.Add(row.Delete);
|
||||
_rows.Add(row);
|
||||
}
|
||||
RefreshSaveAffordance();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
private void RefreshSaveAffordance()
|
||||
{
|
||||
string text = null;
|
||||
if (_saveCurrentLook != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
text = _runningGameName?.Invoke();
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = null;
|
||||
}
|
||||
}
|
||||
bool flag = _visible && _saveCurrentLook != null && !string.IsNullOrWhiteSpace(text);
|
||||
_saveNow.Visible = flag;
|
||||
if (flag)
|
||||
{
|
||||
_saveNow.Text = "Save my colours for " + GameProfileSection.Shorten(text);
|
||||
}
|
||||
bool flag2 = _visible && _saveCurrentLook != null && !flag;
|
||||
_saveHint.Visible = flag2;
|
||||
_saveHint.Text = ((_rows.Count == 0) ? "No game profiles yet. Open a game, set your colours, then save them here." : "Open a game and this is where you save the colours you're looking at.");
|
||||
_empty.Visible = _visible && _rows.Count == 0 && !flag2;
|
||||
}
|
||||
|
||||
private void SaveCurrentLookFlow()
|
||||
{
|
||||
_saveCurrentLook?.Invoke();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
_visible = visible;
|
||||
_caption.Visible = visible;
|
||||
RefreshSaveAffordance();
|
||||
foreach (Row row in _rows)
|
||||
{
|
||||
row.Name.Visible = visible;
|
||||
row.Rename.Visible = visible;
|
||||
row.Delete.Visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
private void RenameFlow(GameProfile profile)
|
||||
{
|
||||
string text = Prompt.Ask("Rename profile", profile.DisplayName);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
Rename(profile.GameId, text);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteFlow(GameProfile profile)
|
||||
{
|
||||
if (GlassDialog.Show(_parent.FindForm(), "Delete this profile?", $"\"{profile.DisplayName}\" will be removed. PlexusX will stop switching to it when {profile.DisplayName} opens. There is no undo - saving a new " + "profile for it is the only way back.", GlassDialogButtons.Destructive, GlassDialogTone.Warning, "Delete profile", "Keep it") == DialogResult.Yes)
|
||||
{
|
||||
Delete(profile.GameId);
|
||||
}
|
||||
}
|
||||
|
||||
private void Rename(string gameId, string newName)
|
||||
{
|
||||
GameProfile gameProfile = _load().FirstOrDefault((GameProfile p) => p.GameId == gameId);
|
||||
if (gameProfile != null)
|
||||
{
|
||||
gameProfile.DisplayName = newName;
|
||||
_save(gameProfile);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Delete(string gameId)
|
||||
{
|
||||
_remove(gameId);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
internal void TestRename(string gameId, string newName)
|
||||
{
|
||||
Rename(gameId, newName);
|
||||
}
|
||||
|
||||
internal void TestDelete(string gameId)
|
||||
{
|
||||
Delete(gameId);
|
||||
}
|
||||
|
||||
private bool IsRunningNow(GameProfile p)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _isRunning?.Invoke(p.GameId) ?? false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ChangesSomething(GameProfile p)
|
||||
{
|
||||
return GameProfileSection.ChangesAnything(p);
|
||||
}
|
||||
|
||||
public void Place(int x, int y, int width)
|
||||
{
|
||||
int num = Tokens.Scale(22);
|
||||
int headerHeight = HeaderHeight;
|
||||
int num2 = Tokens.Scale(8);
|
||||
int num3 = Math.Min(Tokens.Scale(196), Math.Max(Tokens.Scale(120), width / 2));
|
||||
int num4 = Tokens.Scale(28);
|
||||
_caption.SetBounds(x, y + (headerHeight - num) / 2, Math.Max(Tokens.Scale(40), width - num3 - num2), num);
|
||||
_saveNow.SetBounds(x + width - num3, y + (headerHeight - num4) / 2, num3, num4);
|
||||
y += headerHeight + Tokens.Scale(6);
|
||||
_saveHint.SetBounds(x, y, width, HintHeight);
|
||||
if (_saveHint.Visible)
|
||||
{
|
||||
y += HintHeight + Tokens.Scale(6);
|
||||
}
|
||||
_empty.SetBounds(x, y, width, Tokens.Scale(36));
|
||||
if (_rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num5 = Tokens.Scale(76);
|
||||
int num6 = Tokens.Scale(28);
|
||||
int num7 = Tokens.Scale(8);
|
||||
int rowHeight = RowHeight;
|
||||
int num8 = width - 2 * num5 - 2 * num7;
|
||||
int num9 = Tokens.Scale(20);
|
||||
int num10 = Math.Max(Tokens.Scale(18), TextRenderer.MeasureText("Hg", Fonts.Body).Height);
|
||||
int num11 = (rowHeight - (num9 + num10)) / 2;
|
||||
foreach (Row row in _rows)
|
||||
{
|
||||
row.Name.SetBounds(x, y + num11, num8, num9);
|
||||
row.Detail.SetBounds(x, y + num11 + num9, num8, num10);
|
||||
row.Rename.SetBounds(x + num8 + num7, y + (rowHeight - num6) / 2, num5, num6);
|
||||
row.Delete.SetBounds(x + num8 + 2 * num7 + num5, y + (rowHeight - num6) / 2, num5, num6);
|
||||
y += rowHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GlassDialog : SignalDialogWindow
|
||||
{
|
||||
private const int WidthLogical = 460;
|
||||
|
||||
private const int MaxBodyLogical = 420;
|
||||
|
||||
private readonly GlassDialogButtons _buttons;
|
||||
|
||||
private readonly GlassButton _safe;
|
||||
|
||||
private readonly GlassButton? _action;
|
||||
|
||||
internal GlassButton TestOpeningButton => (GlassButton)ActiveControl;
|
||||
|
||||
internal GlassButton? TestActionButton => _action;
|
||||
|
||||
internal GlassButton TestSafeButton => _safe;
|
||||
|
||||
internal static Func<string, string, DialogResult>? InsteadOfShowingForTest { get; set; }
|
||||
|
||||
public static int ButtonCount(GlassDialogButtons b)
|
||||
{
|
||||
if (b != GlassDialogButtons.Ok)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int MeasureHeight(string body, int width)
|
||||
{
|
||||
int logical = Math.Max(80, width - 48);
|
||||
int val = (int)Math.Ceiling((double)(SignalDialogWindow.MeasureBody(body, Tokens.Scale(logical)) * 96) / (double)Tokens.Dpi);
|
||||
return 136 + Math.Min(val, 420);
|
||||
}
|
||||
|
||||
internal GlassDialog(string title, string body, GlassDialogButtons buttons, GlassDialogTone tone, string? primaryText = null, string? secondaryText = null)
|
||||
{
|
||||
GlassDialog glassDialog = this;
|
||||
_buttons = buttons;
|
||||
ChromeTitle = title ?? "PlexusX";
|
||||
ChromeBody = body ?? "";
|
||||
Text = ChromeTitle;
|
||||
AccessibleName = ChromeTitle;
|
||||
AccessibleDescription = ChromeBody;
|
||||
int num = S(460);
|
||||
ChromeBodyHeight = Math.Min(SignalDialogWindow.MeasureBody(ChromeBody, num - 2 * S(24)), S(420));
|
||||
ClientSize = new Size(num, BodyTop + ChromeBodyHeight + S(24) + S(32) + S(20));
|
||||
if (buttons == GlassDialogButtons.Ok)
|
||||
{
|
||||
_safe = FooterButton(secondaryText ?? primaryText ?? "Close", GlassButtonKind.Secondary, "DialogClose");
|
||||
_safe.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(DialogResult.OK);
|
||||
};
|
||||
Controls.Add(_safe);
|
||||
PlaceFooter(_safe);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag = buttons == GlassDialogButtons.Destructive;
|
||||
_action = FooterButton(primaryText ?? "Continue", flag ? GlassButtonKind.Destructive : GlassButtonKind.Primary, "DialogAction");
|
||||
_action.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(Affirmative(buttons));
|
||||
};
|
||||
_safe = FooterButton(secondaryText ?? "Cancel", GlassButtonKind.Secondary, "DialogSafe");
|
||||
_safe.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
glassDialog.Finish(Negative(buttons));
|
||||
};
|
||||
Controls.Add(_safe);
|
||||
Controls.Add(_action);
|
||||
PlaceFooter(_safe, _action);
|
||||
}
|
||||
GlassDialogButtons glassDialogButtons = buttons;
|
||||
GlassButton glassButton = (((uint)(glassDialogButtons - 1) <= 1u) ? _action : _safe);
|
||||
if (_action != null)
|
||||
{
|
||||
_safe.TabIndex = ((glassButton != _safe) ? 1 : 0);
|
||||
_action.TabIndex = ((glassButton != _action) ? 1 : 0);
|
||||
}
|
||||
ActiveControl = glassButton;
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Escape) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
glassDialog.Answer(e.KeyCode);
|
||||
}
|
||||
};
|
||||
WindowDrag.Enable(this, this);
|
||||
}
|
||||
|
||||
private void Answer(Keys key)
|
||||
{
|
||||
if (key == Keys.Escape)
|
||||
{
|
||||
Finish(Negative(_buttons));
|
||||
return;
|
||||
}
|
||||
GlassDialogButtons buttons = _buttons;
|
||||
bool flag = (uint)(buttons - 1) <= 1u;
|
||||
Finish(flag ? Affirmative(_buttons) : Negative(_buttons));
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
bool flag = (keyData & (Keys.Control | Keys.Alt)) == 0;
|
||||
if (flag)
|
||||
{
|
||||
Keys keys = keyData & Keys.KeyCode;
|
||||
bool flag2 = ((keys == Keys.Return || keys == Keys.Escape) ? true : false);
|
||||
flag = flag2;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
Answer(keyData & Keys.KeyCode);
|
||||
return true;
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
private static DialogResult Affirmative(GlassDialogButtons b)
|
||||
{
|
||||
if ((uint)(b - 2) <= 2u)
|
||||
{
|
||||
return DialogResult.Yes;
|
||||
}
|
||||
return DialogResult.OK;
|
||||
}
|
||||
|
||||
private static DialogResult Negative(GlassDialogButtons b)
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case GlassDialogButtons.Ok:
|
||||
return DialogResult.OK;
|
||||
case GlassDialogButtons.YesNo:
|
||||
case GlassDialogButtons.Destructive:
|
||||
case GlassDialogButtons.ConfirmSafeEnter:
|
||||
return DialogResult.No;
|
||||
default:
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
|
||||
private void Finish(DialogResult result)
|
||||
{
|
||||
DialogResult = result;
|
||||
Close();
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
Answer(key);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window? owner, string title, string body, GlassDialogButtons buttons = GlassDialogButtons.Ok, GlassDialogTone tone = GlassDialogTone.Info, string? primaryText = null, string? secondaryText = null)
|
||||
{
|
||||
Func<string, string, DialogResult> insteadOfShowingForTest = InsteadOfShowingForTest;
|
||||
if (insteadOfShowingForTest != null)
|
||||
{
|
||||
return insteadOfShowingForTest(title, body);
|
||||
}
|
||||
using GlassDialog glassDialog = new GlassDialog(title, body, buttons, tone, primaryText, secondaryText);
|
||||
return (owner != null) ? glassDialog.ShowDialog(owner) : glassDialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public enum GlassDialogButtons
|
||||
{
|
||||
Ok,
|
||||
OkCancel,
|
||||
YesNo,
|
||||
Destructive,
|
||||
ConfirmSafeEnter
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public enum GlassDialogTone
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Danger
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class GlassScrollBar : Control
|
||||
{
|
||||
private int _value;
|
||||
|
||||
private int _maximum = 100;
|
||||
|
||||
private int _viewport = 10;
|
||||
|
||||
private bool _hover;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
private int _dragOffset;
|
||||
|
||||
public int Maximum
|
||||
{
|
||||
get
|
||||
{
|
||||
return _maximum;
|
||||
}
|
||||
set
|
||||
{
|
||||
_maximum = Math.Max(0, value);
|
||||
Clamp();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Viewport
|
||||
{
|
||||
get
|
||||
{
|
||||
return _viewport;
|
||||
}
|
||||
set
|
||||
{
|
||||
_viewport = Math.Max(1, value);
|
||||
Clamp();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, 0, Math.Max(0, _maximum - _viewport));
|
||||
if (num != _value)
|
||||
{
|
||||
_value = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Needed => _maximum > _viewport;
|
||||
|
||||
private int TrackTop => 4;
|
||||
|
||||
private int TrackHeight => Math.Max(1, Height - 8);
|
||||
|
||||
private int ThumbHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return TrackHeight;
|
||||
}
|
||||
float num = (float)_viewport / (float)_maximum;
|
||||
return Math.Max(28, (int)((float)TrackHeight * num));
|
||||
}
|
||||
}
|
||||
|
||||
private int ThumbTop
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return TrackTop;
|
||||
}
|
||||
float num = (float)_value / (float)(_maximum - _viewport);
|
||||
return TrackTop + (int)((float)(TrackHeight - ThumbHeight) * num);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? Scrolled;
|
||||
|
||||
public GlassScrollBar()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Width = 8;
|
||||
TabStop = false;
|
||||
}
|
||||
|
||||
private void Clamp()
|
||||
{
|
||||
Value = _value;
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_hover = true;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (e.Button == MouseButtons.Left && Needed)
|
||||
{
|
||||
if (e.Y >= ThumbTop && e.Y <= ThumbTop + ThumbHeight)
|
||||
{
|
||||
_dragging = true;
|
||||
DragTracker.BeginScrollBar();
|
||||
_dragOffset = e.Y - ThumbTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveThumbTo(e.Y - ThumbHeight / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_dragging)
|
||||
{
|
||||
MoveThumbTo(e.Y - _dragOffset);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_dragging)
|
||||
{
|
||||
_dragging = false;
|
||||
DragTracker.EndScrollBar();
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveThumbTo(int top)
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int num = TrackHeight - ThumbHeight;
|
||||
if (num > 0)
|
||||
{
|
||||
int num2 = (int)Math.Round(Math.Clamp((float)(top - TrackTop) / (float)num, 0f, 1f) * (float)(_maximum - _viewport));
|
||||
if (num2 != _value)
|
||||
{
|
||||
_value = num2;
|
||||
Invalidate();
|
||||
Scrolled?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (!Needed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float radius = Math.Max(1f, (float)(Width - 4) / 2f);
|
||||
using (GraphicsPath path = Glass.RoundedPath(new RectangleF(2f, TrackTop, Math.Max(1, Width - 4), TrackHeight), radius))
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Color.FromArgb(28, Theme.GlassEdge));
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using GraphicsPath path2 = Glass.RoundedPath(new RectangleF(2f, ThumbTop, Math.Max(1, Width - 4), ThumbHeight), radius);
|
||||
Color baseColor = (Theme.IsLight ? Theme.AccentDim : Theme.Accent);
|
||||
using SolidBrush brush2 = new SolidBrush((_dragging || _hover) ? Color.FromArgb(_dragging ? 200 : 150, baseColor) : Color.FromArgb(Theme.IsLight ? 60 : 90, Theme.Text));
|
||||
graphics.FillPath(brush2, path2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public class GlassShellForm : SignalDialogWindow
|
||||
{
|
||||
private readonly string _title;
|
||||
|
||||
private Rectangle _closeRect;
|
||||
|
||||
private bool _overClose;
|
||||
|
||||
private bool _showClose = true;
|
||||
|
||||
private bool _paintsTitle = true;
|
||||
|
||||
protected static int Pad => Tokens.Scale(24);
|
||||
|
||||
protected new static int ContentTop => Tokens.Scale(56);
|
||||
|
||||
public bool ShowClose
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showClose;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_showClose != value)
|
||||
{
|
||||
_showClose = value;
|
||||
if (!value)
|
||||
{
|
||||
_closeRect = Rectangle.Empty;
|
||||
_overClose = false;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PaintsTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _paintsTitle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_paintsTitle != value)
|
||||
{
|
||||
_paintsTitle = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GlassShellForm(string title)
|
||||
{
|
||||
_title = title;
|
||||
Text = title;
|
||||
AccessibleName = title;
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
CancelShell();
|
||||
}
|
||||
};
|
||||
WindowDrag.Enable(this, this, (Point p) => _closeRect.Contains(p));
|
||||
}
|
||||
|
||||
protected virtual void CancelShell()
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
bool flag = _closeRect.Contains(e.Location);
|
||||
if (flag != _overClose)
|
||||
{
|
||||
_overClose = flag;
|
||||
Invalidate(new Rectangle(_closeRect.X - 4, _closeRect.Y - 4, _closeRect.Width + 8, _closeRect.Height + 8));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (_overClose)
|
||||
{
|
||||
_overClose = false;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (e.Button == MouseButtons.Left && _closeRect.Contains(e.Location))
|
||||
{
|
||||
CancelShell();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
int num = S(24);
|
||||
int num2 = S(28);
|
||||
_closeRect = (_showClose ? new Rectangle(Width - num2 - S(12), S(12), num2, num2) : Rectangle.Empty);
|
||||
int num3 = (_showClose ? (_closeRect.Left - S(8)) : (Width - num));
|
||||
if (_paintsTitle)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, _title, Fonts.Title, new Rectangle(SignalDialogWindow.Ink(num + S(2), Fonts.Title), S(18), num3 - (num + S(2)) + SignalDialogWindow.GlyphPad(Fonts.Title), S(28)), Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
if (_showClose)
|
||||
{
|
||||
if (_overClose)
|
||||
{
|
||||
GraphicsState gstate = graphics.Save();
|
||||
graphics.TranslateTransform(_closeRect.X, _closeRect.Y);
|
||||
ControlInk.PaintBox(graphics, _closeRect.Size, S(4), ControlInk.Hairline(ChromeDpi), ControlInk.Hover, Color.Empty);
|
||||
graphics.Restore(gstate);
|
||||
}
|
||||
int num4 = S(16);
|
||||
SignalIcons.Draw(graphics, SignalIcon.Close, new RectangleF((float)_closeRect.X + (float)(num2 - num4) / 2f, (float)_closeRect.Y + (float)(num2 - num4) / 2f, num4, num4), _overClose ? ControlInk.Text1 : ControlInk.Text2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class HueWheel : Control
|
||||
{
|
||||
internal readonly record struct RingNameSlot(int Degrees, string Name, Rectangle Rect, PointF TickEnd);
|
||||
|
||||
public const int MinHue = -180;
|
||||
|
||||
public const int MaxHue = 180;
|
||||
|
||||
private static readonly float RefR = 0.82f;
|
||||
|
||||
private static readonly float RefG = 0.38f;
|
||||
|
||||
private static readonly float RefB = 0.34f;
|
||||
|
||||
private Bitmap? _disc;
|
||||
|
||||
private int _hue;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
public const int MinDarkenHue = 0;
|
||||
|
||||
public const int MaxDarkenHue = 359;
|
||||
|
||||
public const int MinDarken = 0;
|
||||
|
||||
public const int MaxDarken = 400;
|
||||
|
||||
private bool _darkenMode;
|
||||
|
||||
private int _darkenHue = 120;
|
||||
|
||||
private int _darken;
|
||||
|
||||
private bool _hasDarkenSelection;
|
||||
|
||||
private const int RingBandPx = 28;
|
||||
|
||||
private bool _ring;
|
||||
|
||||
private Color _surface = Color.Empty;
|
||||
|
||||
private static readonly (int Degrees, string Name)[] RingNames = new (int, string)[6]
|
||||
{
|
||||
(0, "Red"),
|
||||
(60, "Yellow"),
|
||||
(120, "Green"),
|
||||
(180, "Cyan"),
|
||||
(240, "Blue"),
|
||||
(300, "Magenta")
|
||||
};
|
||||
|
||||
private (int Diameter, bool Ring, bool Darken) _failedDisc = (Diameter: -1, Ring: false, Darken: false);
|
||||
|
||||
public bool DarkenMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darkenMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_darkenMode != value)
|
||||
{
|
||||
_darkenMode = value;
|
||||
TabStop = value;
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int DarkenHue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darkenHue;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = (value % 360 + 360) % 360;
|
||||
if (num != _darkenHue || !_hasDarkenSelection)
|
||||
{
|
||||
_darkenHue = num;
|
||||
_hasDarkenSelection = true;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Ring
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ring;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_ring != value)
|
||||
{
|
||||
_ring = value;
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Color Surface
|
||||
{
|
||||
get
|
||||
{
|
||||
return _surface;
|
||||
}
|
||||
set
|
||||
{
|
||||
_surface = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public string CentreText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_darkenMode)
|
||||
{
|
||||
if (_hue != 0)
|
||||
{
|
||||
return "Colours turned";
|
||||
}
|
||||
return "No turn";
|
||||
}
|
||||
if (_hasDarkenSelection)
|
||||
{
|
||||
if (_darken != 0)
|
||||
{
|
||||
return HueName(_darkenHue) + " darker";
|
||||
}
|
||||
return "Not darkened";
|
||||
}
|
||||
return "Pick a colour to darken";
|
||||
}
|
||||
}
|
||||
|
||||
private int RingAngle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_darkenMode)
|
||||
{
|
||||
if (_hue < 0)
|
||||
{
|
||||
return 360 + _hue;
|
||||
}
|
||||
return _hue;
|
||||
}
|
||||
return _darkenHue;
|
||||
}
|
||||
}
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
public int Darken
|
||||
{
|
||||
get
|
||||
{
|
||||
return _darken;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, 0, 400);
|
||||
if (num != _darken)
|
||||
{
|
||||
_darken = num;
|
||||
if (num > 0)
|
||||
{
|
||||
_hasDarkenSelection = true;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
int num = Math.Clamp(value, -180, 180);
|
||||
if (num != _hue)
|
||||
{
|
||||
_hue = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Diameter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_ring)
|
||||
{
|
||||
return Math.Max(1, Math.Min(Width, Height) - Tokens.Scale(6));
|
||||
}
|
||||
return Math.Max(1, Math.Min(Tokens.Scale(176), Math.Min(Width, Height) - Tokens.Scale(80)));
|
||||
}
|
||||
}
|
||||
|
||||
private bool SeeThrough
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!(Parent is CardPanel))
|
||||
{
|
||||
if (SlateSurface.Active)
|
||||
{
|
||||
return AppBackground.IsSet;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? DarkenChanged;
|
||||
|
||||
public event EventHandler? HueChanged;
|
||||
|
||||
internal static string NearestName(int degrees)
|
||||
{
|
||||
return HueName(degrees);
|
||||
}
|
||||
|
||||
private static string HueName(int degrees)
|
||||
{
|
||||
int d = (degrees % 360 + 360) % 360;
|
||||
return RingNames.OrderBy(((int Degrees, string Name) n) => Math.Min(Math.Abs(n.Degrees - d), 360 - Math.Abs(n.Degrees - d))).First().Name;
|
||||
}
|
||||
|
||||
private void PaintRing(Graphics g)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
int diameter = Diameter;
|
||||
float num = (float)Width / 2f;
|
||||
float num2 = (float)Height / 2f;
|
||||
float num3 = (float)diameter / 2f;
|
||||
float num4 = S(28f);
|
||||
float num5 = num3 - num4;
|
||||
Bitmap bitmap = Disc();
|
||||
if (bitmap != null)
|
||||
{
|
||||
g.DrawImageUnscaled(bitmap, (int)(num - num3), (int)(num2 - num3));
|
||||
}
|
||||
using (Pen pen = new Pen(ControlInk.Border, Math.Max(1f, S(1f))))
|
||||
{
|
||||
g.DrawEllipse(pen, num - num3 - S(0.5f), num2 - num3 - S(0.5f), 2f * num3 + S(1f), 2f * num3 + S(1f));
|
||||
g.DrawEllipse(pen, num - num5 + S(0.5f), num2 - num5 + S(0.5f), 2f * num5 - S(1f), 2f * num5 - S(1f));
|
||||
}
|
||||
if (_darkenMode)
|
||||
{
|
||||
float num6 = num5 - S(8f);
|
||||
using Pen pen2 = new Pen(ControlInk.Track, S(3f));
|
||||
g.DrawEllipse(pen2, num - num6, num2 - num6, 2f * num6, 2f * num6);
|
||||
if (_darken > 0)
|
||||
{
|
||||
float num7 = (float)_darken / 400f * 50f;
|
||||
using Pen pen3 = new Pen(ControlInk.Text1, S(3f))
|
||||
{
|
||||
StartCap = LineCap.Round,
|
||||
EndCap = LineCap.Round
|
||||
};
|
||||
g.DrawArc(pen3, num - num6, num2 - num6, 2f * num6, 2f * num6, (float)_darkenHue - num7, 2f * num7);
|
||||
}
|
||||
}
|
||||
int ringAngle = RingAngle;
|
||||
using (Pen pen4 = new Pen(ControlInk.Text2, S(1.5f)))
|
||||
{
|
||||
using Pen pen5 = new Pen(ControlInk.TextDisabled, Math.Max(1f, S(1f)));
|
||||
for (int i = 0; i < 360; i += 30)
|
||||
{
|
||||
bool flag = i % 60 == 0;
|
||||
double num8 = (double)i * Math.PI / 180.0;
|
||||
float num9 = (float)Math.Cos(num8);
|
||||
float num10 = (float)Math.Sin(num8);
|
||||
float num11 = num3 + S(3f);
|
||||
float num12 = num3 + S(flag ? 9 : 6);
|
||||
g.DrawLine(flag ? pen4 : pen5, num + num9 * num11, num2 + num10 * num11, num + num9 * num12, num2 + num10 * num12);
|
||||
}
|
||||
}
|
||||
Font captionBold = Fonts.CaptionBold;
|
||||
RingNameSlot[] array = RingNameSlots(g, num, num2, num3);
|
||||
for (int j = 0; j < array.Length; j++)
|
||||
{
|
||||
RingNameSlot ringNameSlot = array[j];
|
||||
bool flag2 = (!_darkenMode || _hasDarkenSelection) && ringAngle % 60 == 0 && ringNameSlot.Degrees == ringAngle;
|
||||
TextRenderer.DrawText(g, ringNameSlot.Name, captionBold, ringNameSlot.Rect.Location, flag2 ? ControlInk.Text1 : ControlInk.Text3, TextFormatFlags.NoPadding);
|
||||
}
|
||||
HueAt(ringAngle, out var r, out var g2, out var b);
|
||||
Color color = Hsl(r, g2, b);
|
||||
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding;
|
||||
int num13 = (int)S(100f);
|
||||
int num14 = (int)Math.Round(num - (float)num13 / 2f);
|
||||
int num15 = Fonts.LineHeight(FontRole.Caption);
|
||||
int num16 = Math.Max(num15, (int)Math.Ceiling((float)TextRenderer.MeasureText(g, CentreText, Fonts.Caption, new Size(num13, int.MaxValue), flags).Height / (float)num15) * num15);
|
||||
bool flag3 = !_darkenMode || _hasDarkenSelection;
|
||||
float num17 = (flag3 ? S(22f) : 0f);
|
||||
float num18 = S(46f) + S(5f) + S(1f) + num17 + S(1f) + (float)num16;
|
||||
float num19 = num2 - num18 / 2f;
|
||||
float num20 = S(46f);
|
||||
if (flag3)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(ControlInk.Edge))
|
||||
{
|
||||
g.FillEllipse(brush, num - num20 / 2f - S(1f), num19 - S(1f), num20 + S(2f), num20 + S(2f));
|
||||
}
|
||||
using SolidBrush brush2 = new SolidBrush(_darkenMode ? DarkenedSwatch(color) : color);
|
||||
g.FillEllipse(brush2, num - num20 / 2f, num19, num20, num20);
|
||||
}
|
||||
float num21 = num19 + num20 + S(5f) + S(1f);
|
||||
if (num17 > 0f)
|
||||
{
|
||||
string text = (_darkenMode ? (_darken + "%") : (_hue + "°"));
|
||||
TextRenderer.DrawText(g, text, Fonts.For(FontRole.Title), new Rectangle(num14 - (int)S(20f), (int)Math.Round(num21 + num17 / 2f) - (int)S(14f), num13 + (int)S(40f), (int)S(28f)), ControlInk.Text1, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
num21 += num17;
|
||||
}
|
||||
num21 += S(1f);
|
||||
TextRenderer.DrawText(g, CentreText, Fonts.Caption, new Rectangle(num14, (int)Math.Round(num21), num13, num16), ControlInk.Text2, flags);
|
||||
if (flag3)
|
||||
{
|
||||
double num22 = (double)ringAngle * Math.PI / 180.0;
|
||||
float num23 = num3 - num4 / 2f;
|
||||
float num24 = num + (float)Math.Cos(num22) * num23;
|
||||
float num25 = num2 + (float)Math.Sin(num22) * num23;
|
||||
float num26 = S(15f);
|
||||
using (SolidBrush brush3 = new SolidBrush(ControlInk.KnobRing))
|
||||
{
|
||||
g.FillEllipse(brush3, num24 - num26 - S(2f), num25 - num26 - S(2f), 2f * num26 + S(4f), 2f * num26 + S(4f));
|
||||
}
|
||||
using (SolidBrush brush4 = new SolidBrush(ControlInk.Focus))
|
||||
{
|
||||
g.FillEllipse(brush4, num24 - num26, num25 - num26, 2f * num26, 2f * num26);
|
||||
}
|
||||
float num27 = num26 - S(3f);
|
||||
using (SolidBrush brush5 = new SolidBrush(color))
|
||||
{
|
||||
g.FillEllipse(brush5, num24 - num27, num25 - num27, 2f * num27, 2f * num27);
|
||||
}
|
||||
g.PixelOffsetMode = PixelOffsetMode.Default;
|
||||
if (_darkenMode && Focused && ShowFocusCues)
|
||||
{
|
||||
ControlInk.PaintFocusRing(g, new Rectangle((int)(num - num3), (int)(num2 - num3), diameter, diameter), num3, ControlInk.Dpi(this));
|
||||
}
|
||||
}
|
||||
static float S(float px)
|
||||
{
|
||||
return px * (float)Tokens.Scale(100) / 100f;
|
||||
}
|
||||
}
|
||||
|
||||
private RingNameSlot[] RingNameSlots(Graphics g, float cx, float cy, float outer)
|
||||
{
|
||||
Font captionBold = Fonts.CaptionBold;
|
||||
RingNameSlot[] array = new RingNameSlot[RingNames.Length];
|
||||
for (int i = 0; i < RingNames.Length; i++)
|
||||
{
|
||||
(int Degrees, string Name) tuple = RingNames[i];
|
||||
int item = tuple.Degrees;
|
||||
string item2 = tuple.Name;
|
||||
double num = (double)item * Math.PI / 180.0;
|
||||
float num2 = (float)Math.Cos(num);
|
||||
float num3 = (float)Math.Sin(num);
|
||||
float num4 = cx + num2 * (outer + S(12f));
|
||||
float num5 = cy + num3 * (outer + S(12f));
|
||||
Size size = TextRenderer.MeasureText(g, item2, captionBold, Size.Empty, TextFormatFlags.NoPadding);
|
||||
float num6;
|
||||
if (num2 > 0.3f)
|
||||
{
|
||||
num6 = num4;
|
||||
}
|
||||
else
|
||||
{
|
||||
num6 = ((num2 < -0.3f) ? (num4 - (float)size.Width) : (num4 - (float)size.Width / 2f));
|
||||
}
|
||||
if (Math.Abs(num3) > 0.3f)
|
||||
{
|
||||
num5 += (float)(Math.Sign(num3) * size.Height) / 2f;
|
||||
}
|
||||
Rectangle rect = new Rectangle(new Point((int)Math.Round(num6), (int)Math.Round(num5 - (float)size.Height / 2f)), size);
|
||||
PointF tickEnd = new PointF(cx + num2 * (outer + S(9f)), cy + num3 * (outer + S(9f)));
|
||||
array[i] = new RingNameSlot(item, item2, rect, tickEnd);
|
||||
}
|
||||
return array;
|
||||
static float S(float px)
|
||||
{
|
||||
return px * (float)Tokens.Scale(100) / 100f;
|
||||
}
|
||||
}
|
||||
|
||||
internal RingNameSlot[] RingNameSlotsForTest()
|
||||
{
|
||||
using Bitmap image = new Bitmap(1, 1);
|
||||
using Graphics g = Graphics.FromImage(image);
|
||||
float outer = (float)Diameter / 2f;
|
||||
return RingNameSlots(g, (float)Width / 2f, (float)Height / 2f, outer);
|
||||
}
|
||||
|
||||
private static Color Hsl(float r, float g, float b)
|
||||
{
|
||||
float num = (1f - Math.Abs(0.100000024f)) * 0.88f;
|
||||
float num2 = 0.55f - num / 2f;
|
||||
return Color.FromArgb(Byte(num2 + r * num), Byte(num2 + g * num), Byte(num2 + b * num));
|
||||
}
|
||||
|
||||
private Color DarkenedSwatch(Color colour)
|
||||
{
|
||||
if (_darken == 0)
|
||||
{
|
||||
return colour;
|
||||
}
|
||||
var (num, num2, num3) = SaturationMetrics.Transform(SaturationMetrics.Build(SaturationMetric.Rec709, 1f, 1f, new ColourDepth(SaturationMetric.Rec709, _darken, _darkenHue)), (double)(int)colour.R / 255.0, (double)(int)colour.G / 255.0, (double)(int)colour.B / 255.0);
|
||||
return Color.FromArgb(Byte((float)num), Byte((float)num2), Byte((float)num3));
|
||||
}
|
||||
|
||||
private void SetDarken(int hue, int amount)
|
||||
{
|
||||
int num = (hue % 360 + 360) % 360;
|
||||
int num2 = Math.Clamp(amount, 0, 400);
|
||||
if (num != _darkenHue || num2 != _darken || !_hasDarkenSelection)
|
||||
{
|
||||
_darkenHue = num;
|
||||
_darken = num2;
|
||||
_hasDarkenSelection = true;
|
||||
Invalidate();
|
||||
DarkenChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressAt(Point p)
|
||||
{
|
||||
OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, p.X, p.Y, 0));
|
||||
OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, p.X, p.Y, 0));
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
internal Point PointFor(int angleDegrees, double strength)
|
||||
{
|
||||
int diameter = Diameter;
|
||||
double num = (double)(Width - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num2 = (double)(Height - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num3 = (double)angleDegrees * Math.PI / 180.0;
|
||||
double num4 = (double)diameter / 2.0 * Math.Clamp(strength, 0.0, 1.0);
|
||||
return new Point((int)Math.Round(num + Math.Cos(num3) * num4), (int)Math.Round(num2 + Math.Sin(num3) * num4));
|
||||
}
|
||||
|
||||
protected override bool IsInputKey(Keys keyData)
|
||||
{
|
||||
bool flag = _darkenMode;
|
||||
if (flag)
|
||||
{
|
||||
Keys keys = keyData & Keys.KeyCode;
|
||||
bool flag2 = (((uint)(keys - 36) <= 4u || keys == Keys.Delete) ? true : false);
|
||||
flag = flag2;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return base.IsInputKey(keyData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
bool shift = e.Shift;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case Keys.Right:
|
||||
SetDarken(_darkenHue + ((!shift) ? 1 : 15), _darken);
|
||||
break;
|
||||
case Keys.Left:
|
||||
SetDarken(_darkenHue - ((!shift) ? 1 : 15), _darken);
|
||||
break;
|
||||
case Keys.Up:
|
||||
SetDarken(_darkenHue, _darken + (shift ? 50 : 5));
|
||||
break;
|
||||
case Keys.Down:
|
||||
SetDarken(_darkenHue, _darken - (shift ? 50 : 5));
|
||||
break;
|
||||
case Keys.Home:
|
||||
case Keys.Delete:
|
||||
SetDarken(120, 0);
|
||||
break;
|
||||
case Keys.Select:
|
||||
case Keys.Print:
|
||||
case Keys.Execute:
|
||||
case Keys.Snapshot:
|
||||
case Keys.Insert:
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDoubleClick(EventArgs e)
|
||||
{
|
||||
base.OnDoubleClick(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(120, 0);
|
||||
}
|
||||
else if (_hue != 0)
|
||||
{
|
||||
_hue = 0;
|
||||
Invalidate();
|
||||
HueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public HueWheel()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
TabStop = false;
|
||||
Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
_disc?.Dispose();
|
||||
_disc = null;
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
if (SeeThrough)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
if (!SeeThrough)
|
||||
{
|
||||
g.Clear((!_surface.IsEmpty) ? _surface : (Parent?.BackColor ?? Theme.Background));
|
||||
}
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintBody(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintBody(Graphics g)
|
||||
{
|
||||
if (_ring)
|
||||
{
|
||||
PaintRing(g);
|
||||
return;
|
||||
}
|
||||
Bitmap bitmap = Disc();
|
||||
int diameter = Diameter;
|
||||
int num = (Width - diameter) / 2;
|
||||
int num2 = (Height - diameter) / 2;
|
||||
if (bitmap != null)
|
||||
{
|
||||
g.DrawImageUnscaled(bitmap, num, num2);
|
||||
}
|
||||
double num3 = (_darkenMode ? ((double)_darken / 400.0) : ((double)Math.Abs(_hue) / 180.0));
|
||||
double num4 = (double)(_darkenMode ? _darkenHue : ((_hue >= 0) ? _hue : (360 + _hue))) * Math.PI / 180.0;
|
||||
int num5 = num + diameter / 2;
|
||||
int num6 = num2 + diameter / 2;
|
||||
int num7 = (int)Math.Round(((double)diameter / 2.0 - (double)Tokens.Scale(7)) * num3);
|
||||
Point point = new Point(num5 + (int)Math.Round(Math.Cos(num4) * (double)num7), num6 + (int)Math.Round(Math.Sin(num4) * (double)num7));
|
||||
int num8 = Tokens.Scale(11);
|
||||
using (SolidBrush brush = new SolidBrush(Theme.Accent))
|
||||
{
|
||||
g.FillEllipse(brush, point.X - num8 / 2, point.Y - num8 / 2, num8, num8);
|
||||
}
|
||||
using (Pen pen = new Pen(Theme.Background, Tokens.Scale(2)))
|
||||
{
|
||||
g.DrawEllipse(pen, point.X - num8 / 2, point.Y - num8 / 2, num8, num8);
|
||||
}
|
||||
if (_darkenMode && Focused && ShowFocusCues)
|
||||
{
|
||||
ControlInk.PaintFocusRing(g, new Rectangle(num, num2, diameter, diameter), (float)diameter / 2f, ControlInk.Dpi(this));
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap? Disc()
|
||||
{
|
||||
if (_disc != null)
|
||||
{
|
||||
return _disc;
|
||||
}
|
||||
(int, bool, bool) tuple = (Diameter, _ring, _darkenMode);
|
||||
(int, bool, bool) failedDisc = _failedDisc;
|
||||
(int, bool, bool) tuple2 = tuple;
|
||||
if (failedDisc.Item1 == tuple2.Item1 && failedDisc.Item2 == tuple2.Item2 && failedDisc.Item3 == tuple2.Item3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
FailPointForTest?.Invoke("build");
|
||||
return _disc = BuildDisc(Diameter);
|
||||
}
|
||||
catch (Exception ex) when (PaintGuard.IsGdiFailure(ex))
|
||||
{
|
||||
_failedDisc = tuple;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap BuildDisc(int d)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(d, d, PixelFormat.Format32bppArgb);
|
||||
BitmapData bitmapData;
|
||||
try
|
||||
{
|
||||
bitmapData = bitmap.LockBits(new Rectangle(0, 0, d, d), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
catch
|
||||
{
|
||||
bitmap.Dispose();
|
||||
throw;
|
||||
}
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
byte[] array = new byte[bitmapData.Stride];
|
||||
float num = (float)d / 2f;
|
||||
float num2 = num;
|
||||
for (int i = 0; i < d; i++)
|
||||
{
|
||||
Array.Clear(array, 0, array.Length);
|
||||
for (int j = 0; j < d; j++)
|
||||
{
|
||||
float num3 = (float)j - num + 0.5f;
|
||||
float num4 = (float)i - num + 0.5f;
|
||||
float num5 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
|
||||
if (num5 > num2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int num6 = (int)Math.Round(Math.Atan2(num4, num3) * 180.0 / Math.PI);
|
||||
if (num6 < 0)
|
||||
{
|
||||
num6 += 360;
|
||||
}
|
||||
int degrees = ((num6 > 180) ? (num6 - 360) : num6);
|
||||
float num7 = (_ring ? 1f : (num5 / num2));
|
||||
float channel;
|
||||
float channel2;
|
||||
float channel3;
|
||||
if (_darkenMode || _ring)
|
||||
{
|
||||
HueAt(num6, out var r, out var g, out var b);
|
||||
channel = 0.5f + (r - 0.5f) * num7;
|
||||
channel2 = 0.5f + (g - 0.5f) * num7;
|
||||
channel3 = 0.5f + (b - 0.5f) * num7;
|
||||
if (_ring)
|
||||
{
|
||||
float num8 = Tokens.Scale(28);
|
||||
float num9 = Math.Clamp((num5 - (num2 - num8)) / num8, 0f, 1f);
|
||||
float num10 = (180f + 20f * num9) / 255f;
|
||||
channel = 37f / 255f + r * num10;
|
||||
channel2 = 37f / 255f + g * num10;
|
||||
channel3 = 37f / 255f + b * num10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] array2 = ColourBalance.HueMatrix(degrees);
|
||||
channel = RefR + (array2[0] * RefR + array2[5] * RefG + array2[10] * RefB - RefR) * num7;
|
||||
channel2 = RefG + (array2[1] * RefR + array2[6] * RefG + array2[11] * RefB - RefG) * num7;
|
||||
channel3 = RefB + (array2[2] * RefR + array2[7] * RefG + array2[12] * RefB - RefB) * num7;
|
||||
}
|
||||
byte b2 = ((num5 > num2 - 1.2f) ? ((byte)(255f * Math.Clamp(num2 - num5, 0f, 1.2f) / 1.2f)) : byte.MaxValue);
|
||||
if (_ring)
|
||||
{
|
||||
float num11 = num2 - (float)Tokens.Scale(28);
|
||||
float num12 = Math.Clamp(num2 - num5 + 0.5f, 0f, 1f) * Math.Clamp(num5 - num11 + 0.5f, 0f, 1f);
|
||||
if (num12 <= 0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
b2 = (byte)Math.Round(255f * num12);
|
||||
}
|
||||
int num13 = j * 4;
|
||||
array[num13] = Byte(channel3);
|
||||
array[num13 + 1] = Byte(channel2);
|
||||
array[num13 + 2] = Byte(channel);
|
||||
array[num13 + 3] = b2;
|
||||
}
|
||||
Marshal.Copy(array, 0, bitmapData.Scan0 + i * bitmapData.Stride, array.Length);
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
if (!flag)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private static byte Byte(float channel)
|
||||
{
|
||||
return (byte)Math.Round(Math.Clamp(channel, 0f, 1f) * 255f);
|
||||
}
|
||||
|
||||
private static void HueAt(int degrees, out float r, out float g, out float b)
|
||||
{
|
||||
float num = (float)((degrees % 360 + 360) % 360) / 60f;
|
||||
float num2 = 1f - Math.Abs(num % 2f - 1f);
|
||||
(r, g, b) = (int)num switch
|
||||
{
|
||||
0 => (1f, num2, 0f),
|
||||
1 => (num2, 1f, 0f),
|
||||
2 => (0f, 1f, num2),
|
||||
3 => (0f, num2, 1f),
|
||||
4 => (num2, 0f, 1f),
|
||||
_ => (1f, 0f, num2),
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
if (_darkenMode && TabStop)
|
||||
{
|
||||
Focus();
|
||||
}
|
||||
_dragging = true;
|
||||
FromPoint(e.Location);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(_darkenHue + ((e.Delta < 0) ? 5 : (-5)), _darken);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (_dragging)
|
||||
{
|
||||
FromPoint(e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
_dragging = false;
|
||||
}
|
||||
|
||||
private void FromPoint(Point p)
|
||||
{
|
||||
int diameter = Diameter;
|
||||
double num = (double)(Width - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num2 = (double)(Height - diameter) / 2.0 + (double)diameter / 2.0;
|
||||
double num3 = (double)p.X - num;
|
||||
double num4 = (double)p.Y - num2;
|
||||
double num5 = Math.Min(1.0, Math.Sqrt(num3 * num3 + num4 * num4) / ((double)diameter / 2.0));
|
||||
int num6 = (int)Math.Round(Math.Atan2(num4, num3) * 180.0 / Math.PI);
|
||||
if (num6 < 0)
|
||||
{
|
||||
num6 += 360;
|
||||
}
|
||||
if (_darkenMode)
|
||||
{
|
||||
SetDarken(num6, _ring ? _darken : ((int)Math.Round(num5 * 400.0)));
|
||||
return;
|
||||
}
|
||||
int num7 = ((num6 > 180) ? (num6 - 360) : num6);
|
||||
int num8 = (_ring ? num7 : ((int)Math.Round((double)num7 * num5)));
|
||||
if (num8 != _hue)
|
||||
{
|
||||
_hue = Math.Clamp(num8, -180, 180);
|
||||
Invalidate();
|
||||
HueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class InUseTag : Control
|
||||
{
|
||||
private int Dpi => ControlInk.Dpi(this);
|
||||
|
||||
internal Size NaturalSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = ControlInk.Hairline(Dpi);
|
||||
return new Size(TextRenderer.MeasureText(Text, Fonts.CaptionBold, Size.Empty, TextFormatFlags.NoPadding).Width + 2 * Px(8) + 2 * num, Fonts.CaptionBold.Height + 2 * Px(2) + 2 * num);
|
||||
}
|
||||
}
|
||||
|
||||
internal InUseTag()
|
||||
: this("In use")
|
||||
{
|
||||
}
|
||||
|
||||
internal InUseTag(string text)
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
BackColor = Color.Transparent;
|
||||
TabStop = false;
|
||||
Font = Fonts.CaptionBold;
|
||||
AccessibleRole = AccessibleRole.StaticText;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
private int Px(int logical)
|
||||
{
|
||||
return ControlInk.Px(Dpi, logical);
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AccessibleName = Text;
|
||||
Size = NaturalSize;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnDpiChangedAfterParent(EventArgs e)
|
||||
{
|
||||
base.OnDpiChangedAfterParent(e);
|
||||
Size = NaturalSize;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
int dpi = Dpi;
|
||||
ControlInk.PaintBox(graphics, Size, ControlInk.PxF(dpi, 4f), ControlInk.Hairline(dpi), ControlInk.Accent, ControlInk.Accent);
|
||||
TextRenderer.DrawText(graphics, Text, Fonts.CaptionBold, ClientRectangle, ControlInk.OnAccent, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class KeyboardNavigation : IMessageFilter
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static KeyboardNavigation? _installed;
|
||||
|
||||
[ThreadStatic]
|
||||
private static bool _moving;
|
||||
|
||||
private const int WM_KEYDOWN = 256;
|
||||
|
||||
private const int WM_SYSKEYDOWN = 260;
|
||||
|
||||
internal static bool InProgress => _moving;
|
||||
|
||||
internal static void EnsureInstalled()
|
||||
{
|
||||
if (_installed == null)
|
||||
{
|
||||
_installed = new KeyboardNavigation();
|
||||
Application.AddMessageFilter(_installed);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool Consume()
|
||||
{
|
||||
bool moving = _moving;
|
||||
_moving = false;
|
||||
return moving;
|
||||
}
|
||||
|
||||
internal static bool IsNavigationKey(Keys key)
|
||||
{
|
||||
Keys keys = key & Keys.KeyCode;
|
||||
if (keys == Keys.Tab || (uint)(keys - 33) <= 7u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool PreFilterMessage(ref Message m)
|
||||
{
|
||||
int msg = m.Msg;
|
||||
bool flag = ((msg == 256 || msg == 260) ? true : false);
|
||||
bool flag2 = flag;
|
||||
Keys keys = (flag2 ? ((Keys)((long)m.WParam & 0xFFFFL)) : Keys.None);
|
||||
_moving = flag2 && IsNavigationKey(keys);
|
||||
if (_moving && keys == Keys.Tab)
|
||||
{
|
||||
try
|
||||
{
|
||||
RovingFocus.RefreshAll();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class LibraryToast : Control
|
||||
{
|
||||
private const int PadLeft = 16;
|
||||
|
||||
private const int PadRight = 8;
|
||||
|
||||
private const int Gap = 8;
|
||||
|
||||
private const int IconSize = 20;
|
||||
|
||||
private const int CloseBox = 28;
|
||||
|
||||
private const int UndoPad = 8;
|
||||
|
||||
private const int ButtonH = 28;
|
||||
|
||||
private const int MinWidth = 360;
|
||||
|
||||
private const int MaxWidth = 560;
|
||||
|
||||
private readonly GlassButton _undo;
|
||||
|
||||
private readonly GlassButton _close;
|
||||
|
||||
public string Message { get; private set; } = "";
|
||||
|
||||
internal (string Lead, string Tail) Parts
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = Message.IndexOf(" · ", StringComparison.Ordinal);
|
||||
if (num <= 0)
|
||||
{
|
||||
return (Lead: "", Tail: Message);
|
||||
}
|
||||
return (Lead: Message.Substring(0, num), Tail: Message.Substring(num));
|
||||
}
|
||||
}
|
||||
|
||||
private static int UndoWidth => Advance("Undo", Fonts.BodyBold) + 2 * S(8);
|
||||
|
||||
internal int PreferredWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
(string Lead, string Tail) parts = Parts;
|
||||
string item = parts.Lead;
|
||||
string item2 = parts.Tail;
|
||||
int num = ((item.Length > 0) ? Advance(item, Fonts.BodyBold) : 0) + Advance(item2, Fonts.Body);
|
||||
return Math.Clamp(S(16) + S(20) + S(8) + num + S(8) + UndoWidth + S(8) + S(28) + S(8), S(360), S(560));
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? UndoRequested;
|
||||
|
||||
public event EventHandler? CloseRequested;
|
||||
|
||||
private static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
public LibraryToast()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Height = 48;
|
||||
Visible = false;
|
||||
_undo = new GlassButton
|
||||
{
|
||||
Kind = GlassButtonKind.Quiet,
|
||||
Text = "Undo",
|
||||
AccessibleName = "Undo",
|
||||
TabIndex = 0
|
||||
};
|
||||
_undo.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
UndoRequested?.Invoke(this, EventArgs.Empty);
|
||||
};
|
||||
_close = new GlassButton
|
||||
{
|
||||
Kind = GlassButtonKind.Icon,
|
||||
Icon = SignalIcon.Close,
|
||||
AccessibleName = "Close",
|
||||
TabIndex = 1
|
||||
};
|
||||
_close.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
};
|
||||
Controls.Add(_undo);
|
||||
Controls.Add(_close);
|
||||
LayOut();
|
||||
}
|
||||
|
||||
public void Show(string message)
|
||||
{
|
||||
Message = message;
|
||||
Visible = true;
|
||||
LayOut();
|
||||
BringToFront();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs levent)
|
||||
{
|
||||
base.OnLayout(levent);
|
||||
LayOut();
|
||||
}
|
||||
|
||||
public void ReassertOnTop()
|
||||
{
|
||||
BringToFront();
|
||||
}
|
||||
|
||||
internal void TestPressUndo()
|
||||
{
|
||||
UndoRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void TestPressClose()
|
||||
{
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void LayOut()
|
||||
{
|
||||
if (_undo != null && _close != null)
|
||||
{
|
||||
int num = S(28);
|
||||
_close.SetBounds(Width - S(8) - num, (Height - num) / 2, num, num);
|
||||
int undoWidth = UndoWidth;
|
||||
int num2 = S(28);
|
||||
_undo.SetBounds(_close.Left - S(8) - undoWidth, (Height - num2) / 2, undoWidth, num2);
|
||||
}
|
||||
}
|
||||
|
||||
private static int Advance(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font, Size.Empty, TextFormatFlags.NoPadding).Width;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
LayOut();
|
||||
RectangleF rect = new RectangleF(0.5f, 0.5f, Width - 1, Height - 1);
|
||||
float radius = S(8);
|
||||
if (SlateSurface.Active)
|
||||
{
|
||||
Glass.PaintPanel(graphics, rect, radius, Glass.BackdropOffsetOf(this), 255, 200, exactAlpha: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(rect, radius);
|
||||
using (SolidBrush brush = new SolidBrush(SignalTokens.Ash.Overlay))
|
||||
{
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using Pen pen = new Pen(SignalTokens.Ash.WindowEdge, S(1));
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
int num = S(20);
|
||||
int num2 = S(16);
|
||||
LineIcons.Success(graphics, new Rectangle(num2, (Height - num) / 2, num, num), Theme.Positive);
|
||||
num2 += num + S(8);
|
||||
int num3 = Math.Max(0, _undo.Left - S(8) - num2);
|
||||
var (text, text2) = Parts;
|
||||
if (text.Length > 0)
|
||||
{
|
||||
int num4 = Math.Min(num3, Advance(text, Fonts.BodyBold));
|
||||
TextRenderer.DrawText(graphics, text, Fonts.BodyBold, new Rectangle(num2, 0, num4, Height), Theme.Text, TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
num2 += num4;
|
||||
num3 -= num4;
|
||||
}
|
||||
TextRenderer.DrawText(graphics, text2, Fonts.Body, new Rectangle(num2, 0, Math.Max(0, num3), Height), Theme.TextDim, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public static class LockPill
|
||||
{
|
||||
public const string Text = "COMES WITH A PLAN";
|
||||
|
||||
private const int Height = 24;
|
||||
|
||||
private const int PadX = 8;
|
||||
|
||||
private const int Icon = 16;
|
||||
|
||||
private const int Gap = 8;
|
||||
|
||||
private const int Radius = 4;
|
||||
|
||||
public static string Label => char.ToUpperInvariant("COMES WITH A PLAN"[0]) + "COMES WITH A PLAN".Substring(1).ToLowerInvariant();
|
||||
|
||||
private static Font WordFont => Fonts.CaptionBold;
|
||||
|
||||
private static int S(int px)
|
||||
{
|
||||
return Tokens.Scale(px);
|
||||
}
|
||||
|
||||
public static Size Measure()
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(Label, WordFont, Size.Empty, TextFormatFlags.SingleLine | TextFormatFlags.NoPadding);
|
||||
return new Size(S(8) + S(16) + S(8) + size.Width + S(8), S(24));
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, Rectangle tag)
|
||||
{
|
||||
if (tag.Width >= 4 && tag.Height >= 4)
|
||||
{
|
||||
int dpi = Tokens.Dpi;
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(tag.X, tag.Y);
|
||||
ControlInk.PaintBox(g, tag.Size, S(4), ControlInk.Hairline(dpi), Color.Empty, ControlInk.Border);
|
||||
g.Restore(gstate);
|
||||
Color text = ControlInk.Text2;
|
||||
int num = S(16);
|
||||
RectangleF box = new RectangleF(tag.X + S(8), (float)tag.Y + (float)(tag.Height - num) / 2f, num, num);
|
||||
SignalIcons.Draw(g, SignalIcon.Lock, box, text);
|
||||
int num2 = (int)box.Right + S(8);
|
||||
TextRenderer.DrawText(g, Label, WordFont, new Rectangle(num2, tag.Y, Math.Max(0, tag.Right - S(8) - num2 + S(2)), tag.Height), text, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Theming;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class LookTile : Control
|
||||
{
|
||||
private readonly string _caption;
|
||||
|
||||
private readonly string _name;
|
||||
|
||||
private readonly HoverFade _fade;
|
||||
|
||||
private readonly OutsideFocusRing _ring;
|
||||
|
||||
private bool _active;
|
||||
|
||||
private const int Pad = 12;
|
||||
|
||||
private const int PreviewH = 104;
|
||||
|
||||
private const int NameGap = 12;
|
||||
|
||||
private const int NameH = 20;
|
||||
|
||||
private const int CaptionGap = 2;
|
||||
|
||||
private const int RadioD = 20;
|
||||
|
||||
private const int RadioDot = 8;
|
||||
|
||||
private static readonly Rectangle[] Boxes = new Rectangle[5]
|
||||
{
|
||||
new Rectangle(6, 6, 22, 92),
|
||||
new Rectangle(34, 6, 199, 18),
|
||||
new Rectangle(34, 30, 199, 34),
|
||||
new Rectangle(34, 70, 120, 28),
|
||||
new Rectangle(160, 70, 73, 28)
|
||||
};
|
||||
|
||||
private const int BoxesW = 242;
|
||||
|
||||
public ThemePalette Palette { get; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal string ShownName => _name;
|
||||
|
||||
internal string Caption => _caption;
|
||||
|
||||
internal Action<string>? FailPointForTest { get; set; }
|
||||
|
||||
private bool IsSlate => Palette.Name == "Slate";
|
||||
|
||||
public LookTile(ThemePalette palette, string caption, string? name = null)
|
||||
{
|
||||
Palette = palette;
|
||||
_caption = caption;
|
||||
_name = name ?? palette.Name;
|
||||
_fade = new HoverFade(this);
|
||||
_ring = new OutsideFocusRing(this, () => ControlInk.PxF(ControlInk.Dpi(this), 8f));
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
Size = new Size(266, 194);
|
||||
AccessibleName = _name;
|
||||
AccessibleRole = AccessibleRole.RadioButton;
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
}
|
||||
|
||||
internal static int HeightFor(int width, string caption, int dpi)
|
||||
{
|
||||
int width2 = Math.Max(1, width - 2 * ControlInk.Px(dpi, 12));
|
||||
int height = TextRenderer.MeasureText(caption, Fonts.Caption, new Size(width2, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding).Height;
|
||||
return ControlInk.Px(dpi, 150) + height + ControlInk.Px(dpi, 12);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_fade.Set(hot: true);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_fade.Set(hot: false);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
Focus();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
base.OnParentChanged(e);
|
||||
_ring.Rehook();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
bool flag = !Enabled;
|
||||
if (!flag)
|
||||
{
|
||||
Keys keyCode = e.KeyCode;
|
||||
bool flag2 = ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false);
|
||||
flag = !flag2;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnEnabledChanged(EventArgs e)
|
||||
{
|
||||
base.OnEnabledChanged(e);
|
||||
Cursor = (Enabled ? Cursors.Hand : Cursors.Default);
|
||||
if (!Enabled)
|
||||
{
|
||||
_fade.Snap(hot: false);
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintTile(g);
|
||||
});
|
||||
}
|
||||
|
||||
private void PaintTile(Graphics g)
|
||||
{
|
||||
int dpi = ControlInk.Dpi(this);
|
||||
int num = ControlInk.Px(dpi, 12);
|
||||
int num2 = ControlInk.Hairline(dpi);
|
||||
float num3 = ControlInk.PxF(dpi, 8f);
|
||||
Color fill = (Enabled ? ControlInk.Mix(Color.FromArgb(0, ControlInk.Hover), ControlInk.Hover, _fade.Value) : Color.Transparent);
|
||||
Color edge;
|
||||
if (Enabled)
|
||||
{
|
||||
edge = (_active ? ControlInk.Accent : ControlInk.Edge);
|
||||
}
|
||||
else
|
||||
{
|
||||
edge = ControlInk.TextDisabled;
|
||||
}
|
||||
ControlInk.PaintBox(g, ClientSize, num3, num2, fill, edge);
|
||||
if (_active && Enabled && Width > 4 && Height > 4)
|
||||
{
|
||||
Size size = new Size(Width - 2 * num2, Height - 2 * num2);
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(num2, num2);
|
||||
ControlInk.PaintBox(g, size, Math.Max(0f, num3 - (float)num2), num2, Color.Transparent, ControlInk.Accent);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
Rectangle well = new Rectangle(num, num, Math.Max(1, Width - 2 * num), Math.Min(ControlInk.Px(dpi, 104), Math.Max(1, Height - 2 * num)));
|
||||
if (well.Width > 4 && well.Height > 4)
|
||||
{
|
||||
PaintGuard.Try(this, () =>
|
||||
{
|
||||
PaintPreview(g, well, dpi);
|
||||
});
|
||||
}
|
||||
int num4 = well.Bottom + ControlInk.Px(dpi, 12);
|
||||
int num5 = ControlInk.Px(dpi, 20);
|
||||
int num6 = ControlInk.Px(dpi, 20);
|
||||
Rectangle box = new Rectangle(Width - num - num6, num4 + (num5 - num6) / 2, num6, num6);
|
||||
Color foreColor = (Enabled ? ControlInk.Text1 : ControlInk.TextDisabledInk);
|
||||
Color foreColor2 = (Enabled ? ControlInk.Text3 : ControlInk.TextDisabledInk);
|
||||
TextRenderer.DrawText(g, _name, Fonts.BodyBold, new Rectangle(num, num4, Math.Max(1, box.Left - num - ControlInk.Px(dpi, 8)), num5), foreColor, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
PaintRadio(g, box, dpi);
|
||||
int num7 = num4 + num5 + ControlInk.Px(dpi, 2);
|
||||
TextRenderer.DrawText(g, _caption, Fonts.Caption, new Rectangle(num, num7, Math.Max(1, Width - 2 * num), Math.Max(1, Height - num7 - num / 2)), foreColor2, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
_ring.Show(Focused && ShowFocusCues && Enabled);
|
||||
}
|
||||
|
||||
private void PaintPreview(Graphics g, Rectangle well, int dpi)
|
||||
{
|
||||
FailPointForTest?.Invoke("draw");
|
||||
float radius = ControlInk.PxF(dpi, 4f);
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(well.X, well.Y, well.Width, well.Height), radius);
|
||||
using Region clip = g.Clip;
|
||||
g.SetClip(path, CombineMode.Intersect);
|
||||
try
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(SlateSurface.Active ? SignalTokens.Slate.PreviewWell : SignalTokens.Ash.PreviewWell))
|
||||
{
|
||||
g.FillRectangle(brush, well);
|
||||
}
|
||||
if (AppBackground.IsSet)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(well.X, well.Y);
|
||||
AppBackground.PaintInto(g, well.Width, well.Height);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
float num = (float)well.Width / 242f;
|
||||
Color color = (IsSlate ? Color.FromArgb((int)Math.Round(168.3), SignalTokens.Slate.SlateBase) : SignalTokens.Ash.Surface1);
|
||||
Color color2 = (IsSlate ? SignalTokens.Slate.Border : SignalTokens.Ash.Border);
|
||||
if (!Enabled)
|
||||
{
|
||||
color = Color.FromArgb(color.A / 2, color);
|
||||
}
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using SolidBrush brush2 = new SolidBrush(color);
|
||||
using Pen pen = new Pen(color2, 1f);
|
||||
Rectangle[] boxes = Boxes;
|
||||
for (int i = 0; i < boxes.Length; i++)
|
||||
{
|
||||
Rectangle rectangle = boxes[i];
|
||||
RectangleF rect = new RectangleF((float)well.X + (float)rectangle.X * num, (float)well.Y + (float)rectangle.Y * num, (float)rectangle.Width * num, Math.Min((float)rectangle.Height * num, (float)well.Bottom - ((float)well.Y + (float)rectangle.Y * num) - 1f));
|
||||
if (!(rect.Width < 2f) && !(rect.Height < 2f))
|
||||
{
|
||||
using GraphicsPath path2 = Glass.RoundedPath(rect, ControlInk.PxF(dpi, 2f));
|
||||
g.FillPath(brush2, path2);
|
||||
g.DrawPath(pen, path2);
|
||||
}
|
||||
}
|
||||
g.SmoothingMode = smoothingMode;
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.Clip = clip;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintRadio(Graphics g, Rectangle box, int dpi)
|
||||
{
|
||||
if (box.Width < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
try
|
||||
{
|
||||
float num = (float)ControlInk.Hairline(dpi) / 2f;
|
||||
RectangleF rect = new RectangleF((float)box.X + num, (float)box.Y + num, (float)box.Width - 2f * num, (float)box.Height - 2f * num);
|
||||
if (_active && Enabled)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(ControlInk.Accent))
|
||||
{
|
||||
g.FillEllipse(brush, box);
|
||||
}
|
||||
float num2 = ControlInk.PxF(dpi, 8f);
|
||||
using SolidBrush brush2 = new SolidBrush(ControlInk.OnAccent);
|
||||
g.FillEllipse(brush2, (float)box.X + ((float)box.Width - num2) / 2f, (float)box.Y + ((float)box.Height - num2) / 2f, num2, num2);
|
||||
return;
|
||||
}
|
||||
using Pen pen = new Pen(Enabled ? ControlInk.Edge : ControlInk.TextDisabled, ControlInk.Hairline(dpi));
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_ring.Release();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class MonitorNumberWindow : Form, IMonitorIdentifyWindow, IDisposable
|
||||
{
|
||||
private readonly string _number;
|
||||
|
||||
protected override bool ShowWithoutActivation => true;
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams createParams = base.CreateParams;
|
||||
createParams.ExStyle |= 134217888;
|
||||
return createParams;
|
||||
}
|
||||
}
|
||||
|
||||
internal MonitorNumberWindow(Rectangle screen, int number)
|
||||
{
|
||||
_number = number.ToString(CultureInfo.InvariantCulture);
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
ShowInTaskbar = false;
|
||||
TopMost = true;
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
BackColor = Theme.Surface;
|
||||
Size = new Size(Tokens.Scale(120), Tokens.Scale(96));
|
||||
Location = new Point(screen.Left + (screen.Width - Width) / 2, screen.Top + (screen.Height - Height) / 2);
|
||||
DoubleBuffered = true;
|
||||
}
|
||||
|
||||
public void ShowNumber()
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
TextRenderer.DrawText(e.Graphics, _number, Fonts.Value, ClientRectangle, Theme.Text, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
using Pen pen = new Pen(Theme.Border);
|
||||
e.Graphics.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class MonitorSelectionCard : IDisposable
|
||||
{
|
||||
private readonly MonitorSelection _selection;
|
||||
|
||||
private readonly MonitorIdentifier _identifier;
|
||||
|
||||
private readonly Action _save;
|
||||
|
||||
private readonly Label _heading = Label("Apply to", Fonts.BodyBold);
|
||||
|
||||
private readonly Label _hint = Label("Unticked monitors keep their own colours.", Fonts.Caption);
|
||||
|
||||
private readonly Label _summary = Label("", Fonts.Caption);
|
||||
|
||||
private readonly Label _limitation = Label("", Fonts.Caption);
|
||||
|
||||
private readonly Label _empty = Label("No monitors found.", Fonts.Caption);
|
||||
|
||||
private readonly GlassButton _identify = new GlassButton
|
||||
{
|
||||
Text = "Identify screens",
|
||||
AccessibleName = "Identify screens"
|
||||
};
|
||||
|
||||
private readonly List<MonitorSelectionTile> _tiles = new List<MonitorSelectionTile>();
|
||||
|
||||
public CardPanel View { get; } = new CardPanel
|
||||
{
|
||||
Name = "monitor-selection"
|
||||
};
|
||||
|
||||
public MonitorSelectionCard(MonitorSelection selection, MonitorIdentifier identifier, Action save)
|
||||
{
|
||||
_selection = selection;
|
||||
_identifier = identifier;
|
||||
_save = save;
|
||||
View.Controls.AddRange(new Control[6] { _heading, _hint, _identify, _summary, _limitation, _empty });
|
||||
_identify.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
_identifier.Identify(_selection.Groups);
|
||||
};
|
||||
_selection.Changed += Refresh;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private static Label Label(string text, Font font)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = font,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
AutoSize = false,
|
||||
TabStop = false
|
||||
};
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
IReadOnlyList<ColourMonitorGroup> groups = _selection.Groups;
|
||||
View.Visible = _selection.WorthShowing;
|
||||
if (_tiles.Count != groups.Count || _tiles.Where((MonitorSelectionTile t, int i) => t.Group.Identity != groups[i].Identity).Any())
|
||||
{
|
||||
foreach (MonitorSelectionTile tile2 in _tiles)
|
||||
{
|
||||
View.Controls.Remove(tile2);
|
||||
tile2.Dispose();
|
||||
}
|
||||
_tiles.Clear();
|
||||
for (int num = 0; num < groups.Count; num++)
|
||||
{
|
||||
MonitorSelectionTile tile = new MonitorSelectionTile(groups[num], num + 1);
|
||||
tile.SelectionRequested += (bool chosen) =>
|
||||
{
|
||||
_selection.SetSelected(tile.Group, chosen);
|
||||
_save();
|
||||
};
|
||||
_tiles.Add(tile);
|
||||
View.Controls.Add(tile);
|
||||
}
|
||||
}
|
||||
for (int num2 = 0; num2 < _tiles.Count; num2++)
|
||||
{
|
||||
_tiles[num2].Group = groups[num2];
|
||||
_tiles[num2].Checked = _selection.IsSelected(groups[num2]);
|
||||
_tiles[num2].Enabled = true;
|
||||
}
|
||||
_identify.Enabled = groups.Count > 0;
|
||||
_empty.Visible = groups.Count == 0;
|
||||
IEnumerable<string> enumerable = from x in groups.Select((ColourMonitorGroup g, int i) => (g: g, i: i))
|
||||
where _selection.IncludesDevice(x.g.DeviceName)
|
||||
select "Monitor " + (x.i + 1);
|
||||
_summary.Text = "Ticked: " + (enumerable.Any() ? string.Join(", ", enumerable) : "None");
|
||||
Label limitation = _limitation;
|
||||
string text;
|
||||
if (groups.Count != 0)
|
||||
{
|
||||
text = (_selection.AllowsMatrix ? "" : "Saturation, hue and other whole-desktop colour effects are paused while a monitor is unticked. Brightness, contrast, temperature, red/green/blue, gamma and NVIDIA Digital Vibrance use the ticked monitors.");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
limitation.Text = text;
|
||||
if (groups.Count > 0 && groups.All((ColourMonitorGroup g) => !_selection.IsSelected(g)))
|
||||
{
|
||||
_limitation.Text = "No monitors selected. Colour changes are paused.";
|
||||
}
|
||||
if (View.Width > 0)
|
||||
{
|
||||
Layout(View.Width);
|
||||
}
|
||||
View.Parent?.PerformLayout();
|
||||
}
|
||||
|
||||
public int Layout(int width)
|
||||
{
|
||||
if (!_selection.WorthShowing)
|
||||
{
|
||||
View.Height = 0;
|
||||
return 0;
|
||||
}
|
||||
int num = Tokens.Scale(21);
|
||||
int num2 = Tokens.Scale(12);
|
||||
int num3 = Math.Max(1, width - 2 * num);
|
||||
int height = Tokens.Scale(32);
|
||||
int width2 = _identify.GetPreferredSize(Size.Empty).Width;
|
||||
_heading.ForeColor = Theme.Text;
|
||||
_heading.SetBounds(num, num, Math.Max(1, num3 - width2 - num2), Fonts.LineHeight(FontRole.BodyBold));
|
||||
_identify.SetBounds(width - num - width2, num, width2, height);
|
||||
int y = _heading.Bottom + Tokens.Scale(3);
|
||||
int width3 = Math.Max(1, num3 - width2 - num2);
|
||||
int height2 = Measure(_hint, width3);
|
||||
_hint.SetBounds(num, y, width3, height2);
|
||||
int num4 = Math.Max(_hint.Bottom, _identify.Bottom) + Tokens.Scale(16);
|
||||
int num5 = ((num3 < Tokens.Scale(640)) ? 1 : 2);
|
||||
int tileW = (num3 - num2 * (num5 - 1)) / num5;
|
||||
for (int i = 0; i < _tiles.Count; i += num5)
|
||||
{
|
||||
int num6 = _tiles.Skip(i).Take(num5).Max((MonitorSelectionTile t) => t.GetPreferredSize(new Size(tileW, 0)).Height);
|
||||
for (int num7 = 0; num7 < num5 && i + num7 < _tiles.Count; num7++)
|
||||
{
|
||||
_tiles[i + num7].SetBounds(num + num7 * (tileW + num2), num4, tileW, num6);
|
||||
}
|
||||
num4 += num6 + num2;
|
||||
}
|
||||
if (_tiles.Count == 0)
|
||||
{
|
||||
_empty.SetBounds(num, num4, num3, Measure(_empty, num3));
|
||||
num4 = _empty.Bottom + num2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_empty.SetBounds(num, num, 0, 0);
|
||||
}
|
||||
_summary.SetBounds(num, num4, num3, Measure(_summary, num3));
|
||||
num4 = _summary.Bottom;
|
||||
int num8 = ((_limitation.Text.Length != 0) ? Measure(_limitation, num3) : 0);
|
||||
_limitation.SetBounds(num, num4 + ((num8 > 0) ? num2 : 0), num3, num8);
|
||||
int num9 = _limitation.Bottom + num;
|
||||
View.Height = num9;
|
||||
return num9;
|
||||
}
|
||||
|
||||
private static int Measure(Label label, int width)
|
||||
{
|
||||
return TextRenderer.MeasureText(label.Text, label.Font, new Size(width, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding).Height;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_selection.Changed -= Refresh;
|
||||
_identifier.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Monitors;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class MonitorSelectionTile : Control
|
||||
{
|
||||
private sealed class TileAccessible : ControlAccessibleObject
|
||||
{
|
||||
private readonly MonitorSelectionTile _tile;
|
||||
|
||||
public override AccessibleStates State => (AccessibleStates)((int)base.State | (_tile.Checked ? 16 : 0));
|
||||
|
||||
public override string DefaultAction => "Toggle selection";
|
||||
|
||||
public TileAccessible(MonitorSelectionTile tile)
|
||||
: base(tile)
|
||||
{
|
||||
_tile = tile;
|
||||
}
|
||||
|
||||
public override void DoDefaultAction()
|
||||
{
|
||||
_tile.Request();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _checked;
|
||||
|
||||
public ColourMonitorGroup Group { get; set; }
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public bool Checked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _checked;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_checked != value)
|
||||
{
|
||||
_checked = value;
|
||||
Invalidate();
|
||||
AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string Detail
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Group.IsClone)
|
||||
{
|
||||
return Group.Bounds.Width + " × " + Group.Bounds.Height + ((Group.RefreshHz > 0) ? (" · " + Group.RefreshHz + " Hz") : "") + (Group.Primary ? " · main" : "");
|
||||
}
|
||||
return "Mirrored screens — selected together";
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<bool>? SelectionRequested;
|
||||
|
||||
public MonitorSelectionTile(ColourMonitorGroup group, int number)
|
||||
{
|
||||
Group = group;
|
||||
Number = number;
|
||||
Name = "monitor-tile-" + number;
|
||||
AccessibleName = group.Name;
|
||||
AccessibleRole = AccessibleRole.CheckButton;
|
||||
TabStop = true;
|
||||
Cursor = Cursors.Hand;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Font = Fonts.BodyBold;
|
||||
}
|
||||
|
||||
private int TextWidth(int width)
|
||||
{
|
||||
return Math.Max(Tokens.Scale(32), width - Tokens.Scale(132));
|
||||
}
|
||||
|
||||
private static Size Measure(string text, Font font, int width)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font, new Size(width, int.MaxValue), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
}
|
||||
|
||||
public override Size GetPreferredSize(Size proposedSize)
|
||||
{
|
||||
int width = ((proposedSize.Width > 0) ? proposedSize.Width : Tokens.Scale(360));
|
||||
int width2 = TextWidth(width);
|
||||
int num = Measure(Group.Name, Fonts.BodyBold, width2).Height + Tokens.Scale(3) + Measure(Detail, Fonts.Caption, width2).Height;
|
||||
return new Size(width, Math.Max(Tokens.Scale(68), num + Tokens.Scale(28)));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
int num = Tokens.Scale(14);
|
||||
int num2 = Tokens.Scale(58);
|
||||
int num3 = Tokens.Scale(38);
|
||||
int num4 = Tokens.Scale(12);
|
||||
using SolidBrush brush = new SolidBrush(Checked ? Theme.Surface : Theme.Background);
|
||||
using Pen pen = new Pen(Checked ? Theme.Text : Theme.Border);
|
||||
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
|
||||
graphics.FillRectangle(brush, rect);
|
||||
graphics.DrawRectangle(pen, rect);
|
||||
Rectangle rectangle = new Rectangle(num, (Height - num3) / 2, num2, num3);
|
||||
graphics.DrawRectangle(pen, rectangle);
|
||||
TextRenderer.DrawText(graphics, Number.ToString(CultureInfo.InvariantCulture), Fonts.Title, rectangle, Checked ? Theme.Text : Theme.TextDim, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding);
|
||||
using SolidBrush brush2 = new SolidBrush(Checked ? Theme.Text : Theme.TextDim);
|
||||
graphics.FillRectangle(brush2, rectangle.Left + num2 / 2 - Tokens.Scale(5), rectangle.Bottom, Tokens.Scale(10), Tokens.Scale(6));
|
||||
int x = num + num2 + num4;
|
||||
int width = TextWidth(Width);
|
||||
int height = Measure(Group.Name, Fonts.BodyBold, width).Height;
|
||||
TextRenderer.DrawText(graphics, Group.Name, Fonts.BodyBold, new Rectangle(x, num, width, height), Theme.Text, TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
TextRenderer.DrawText(graphics, Detail, Fonts.Caption, new Rectangle(x, num + height + Tokens.Scale(3), width, Height - num * 2 - height - Tokens.Scale(3)), Theme.TextDim, TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
int num5 = Tokens.Scale(20);
|
||||
Rectangle rect2 = new Rectangle(Width - num - num5, (Height - num5) / 2, num5, num5);
|
||||
if (Checked)
|
||||
{
|
||||
using SolidBrush brush3 = new SolidBrush(Theme.Text);
|
||||
graphics.FillRectangle(brush3, rect2);
|
||||
using Pen pen2 = new Pen(Theme.Background, Tokens.Scale(2));
|
||||
graphics.DrawLines(pen2, new Point[3]
|
||||
{
|
||||
new Point(rect2.Left + num5 / 4, rect2.Top + num5 / 2),
|
||||
new Point(rect2.Left + num5 * 2 / 5, rect2.Top + num5 * 3 / 4),
|
||||
new Point(rect2.Left + num5 * 4 / 5, rect2.Top + num5 / 4)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.DrawRectangle(pen, rect2);
|
||||
}
|
||||
if (Focused)
|
||||
{
|
||||
using (Pen pen3 = new Pen(Theme.Text)
|
||||
{
|
||||
DashStyle = DashStyle.Dot
|
||||
})
|
||||
{
|
||||
graphics.DrawRectangle(pen3, 2, 2, Width - 5, Height - 5);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Request()
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
SelectionRequested?.Invoke(!Checked);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
base.OnClick(e);
|
||||
Focus();
|
||||
Request();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Space)
|
||||
{
|
||||
Request();
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override AccessibleObject CreateAccessibilityInstance()
|
||||
{
|
||||
return new TileAccessible(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class NotesView : Control
|
||||
{
|
||||
internal readonly record struct Block(string Lead, string Text, bool Bullet, bool Heading, bool GapBefore);
|
||||
|
||||
private const int LanePx = 8;
|
||||
|
||||
private const int ThumbPx = 4;
|
||||
|
||||
private const int ThumbMinPx = 24;
|
||||
|
||||
private const int ParagraphGapPx = 8;
|
||||
|
||||
private const int LinesPerNotch = 3;
|
||||
|
||||
private string _text = "";
|
||||
|
||||
private int _scroll;
|
||||
|
||||
private bool _thumbHot;
|
||||
|
||||
private bool _dragging;
|
||||
|
||||
private int _dragFrom;
|
||||
|
||||
private int _dragScrollFrom;
|
||||
|
||||
private readonly List<(Point At, string Word, bool Strong)> _laid = new List<(Point, string, bool)>();
|
||||
|
||||
private readonly List<Point> _dots = new List<Point>();
|
||||
|
||||
private int _laidFor = -1;
|
||||
|
||||
private int _contentHeight;
|
||||
|
||||
private int _headingLimit = 48;
|
||||
|
||||
private bool _onCard;
|
||||
|
||||
internal const int DefaultHeadingLimit = 48;
|
||||
|
||||
private static readonly Regex LeadIn = new Regex("^(?<lead>[A-Z][^:.!?\\r\\n]{0,38}:)\\s+(?<rest>\\S.*)$", RegexOptions.Singleline);
|
||||
|
||||
public string NotesText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
set
|
||||
{
|
||||
_text = value ?? "";
|
||||
_laidFor = -1;
|
||||
_scroll = 0;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int HeadingLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _headingLimit;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _headingLimit)
|
||||
{
|
||||
_headingLimit = value;
|
||||
_laidFor = -1;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnCard
|
||||
{
|
||||
get
|
||||
{
|
||||
return _onCard;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _onCard)
|
||||
{
|
||||
_onCard = value;
|
||||
if (value)
|
||||
{
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetBackColor();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Dpi => ControlInk.Dpi(this);
|
||||
|
||||
private int TextWidth => Math.Max(1, Width - Px(8));
|
||||
|
||||
private int MaxScroll => Math.Max(0, _contentHeight - Height);
|
||||
|
||||
private int LinePx => Px(20);
|
||||
|
||||
private Rectangle Thumb
|
||||
{
|
||||
get
|
||||
{
|
||||
Lay();
|
||||
if (_contentHeight <= Height || Height <= 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
int num = Math.Max(Px(24), (int)((long)Height * (long)Height / _contentHeight));
|
||||
int num2 = Height - num;
|
||||
int y = (int)((MaxScroll != 0) ? ((long)num2 * (long)_scroll / MaxScroll) : 0);
|
||||
int num3 = Px(4);
|
||||
return new Rectangle(Width - Px(8) + (Px(8) - num3) / 2, y, num3, num);
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle Lane => new Rectangle(Width - Px(8), 0, Px(8), Height);
|
||||
|
||||
internal int ContentHeightForTest
|
||||
{
|
||||
get
|
||||
{
|
||||
Lay();
|
||||
return _contentHeight;
|
||||
}
|
||||
}
|
||||
|
||||
internal int ScrollForTest => _scroll;
|
||||
|
||||
internal Rectangle ThumbForTest => Thumb;
|
||||
|
||||
public NotesView()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
Font = Fonts.Body;
|
||||
}
|
||||
|
||||
private int Px(int logical)
|
||||
{
|
||||
return ControlInk.Px(Dpi, logical);
|
||||
}
|
||||
|
||||
private void Lay()
|
||||
{
|
||||
if (_laidFor == Width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_laid.Clear();
|
||||
_dots.Clear();
|
||||
int textWidth = TextWidth;
|
||||
int num = 0;
|
||||
int num2 = Px(8);
|
||||
int num3 = Px(4);
|
||||
int linePx = LinePx;
|
||||
Font body = Fonts.Body;
|
||||
Font bodyBold = Fonts.BodyBold;
|
||||
int num4 = Math.Max(1, TextRenderer.MeasureText("a a", body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width - TextRenderer.MeasureText("aa", body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width);
|
||||
int num5 = Px(16);
|
||||
foreach (Block item5 in Reflow(_text, _headingLimit))
|
||||
{
|
||||
if (_laid.Count > 0 || _dots.Count > 0)
|
||||
{
|
||||
num += (item5.GapBefore ? num2 : num3);
|
||||
}
|
||||
int num6 = (item5.Bullet ? num5 : 0);
|
||||
if (item5.Bullet)
|
||||
{
|
||||
_dots.Add(new Point(0, num));
|
||||
}
|
||||
List<(string, bool)> list = new List<(string, bool)>();
|
||||
string[] array = item5.Lead.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string item in array)
|
||||
{
|
||||
list.Add((item, true));
|
||||
}
|
||||
array = item5.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string item2 in array)
|
||||
{
|
||||
list.Add((item2, item5.Heading));
|
||||
}
|
||||
int num7 = num6;
|
||||
foreach (var item6 in list)
|
||||
{
|
||||
string item3 = item6.Item1;
|
||||
bool item4 = item6.Item2;
|
||||
int width = TextRenderer.MeasureText(item3, item4 ? bodyBold : body, Size.Empty, TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding).Width;
|
||||
if (num7 > num6 && num7 + width > textWidth)
|
||||
{
|
||||
num7 = num6;
|
||||
num += linePx;
|
||||
}
|
||||
_laid.Add((new Point(num7, num), item3, item4));
|
||||
num7 += width + num4;
|
||||
}
|
||||
num += linePx;
|
||||
}
|
||||
_contentHeight = num;
|
||||
_laidFor = Width;
|
||||
_scroll = Math.Clamp(_scroll, 0, MaxScroll);
|
||||
}
|
||||
|
||||
private void ScrollBy(int pixels)
|
||||
{
|
||||
Lay();
|
||||
int num = Math.Clamp(_scroll + pixels, 0, MaxScroll);
|
||||
if (num != _scroll)
|
||||
{
|
||||
_scroll = num;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public bool ScrollByKey(Keys key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Keys.Up:
|
||||
ScrollBy(-LinePx);
|
||||
return true;
|
||||
case Keys.Down:
|
||||
ScrollBy(LinePx);
|
||||
return true;
|
||||
case Keys.Prior:
|
||||
ScrollBy(-Math.Max(LinePx, Height - LinePx));
|
||||
return true;
|
||||
case Keys.Next:
|
||||
ScrollBy(Math.Max(LinePx, Height - LinePx));
|
||||
return true;
|
||||
case Keys.Home:
|
||||
ScrollBy(-1073741823);
|
||||
return true;
|
||||
case Keys.End:
|
||||
ScrollBy(1073741823);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Wheel(int delta)
|
||||
{
|
||||
ScrollBy(-delta * 3 * LinePx / 120);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
HandledMouseEventArgs e2 = (e as HandledMouseEventArgs) ?? new HandledMouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta);
|
||||
e2.Handled = true;
|
||||
base.OnMouseWheel(e2);
|
||||
Wheel(e.Delta);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (_dragging)
|
||||
{
|
||||
Rectangle thumb = Thumb;
|
||||
int num = Math.Max(1, Height - thumb.Height);
|
||||
int num2 = _dragScrollFrom + (int)((long)(e.Y - _dragFrom) * (long)MaxScroll / num);
|
||||
ScrollBy(num2 - _scroll);
|
||||
return;
|
||||
}
|
||||
bool flag = Lane.Contains(e.Location) && !Thumb.IsEmpty;
|
||||
if (flag != _thumbHot)
|
||||
{
|
||||
_thumbHot = flag;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (_thumbHot)
|
||||
{
|
||||
_thumbHot = false;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Rectangle thumb = Thumb;
|
||||
if (e.Button == MouseButtons.Left && !thumb.IsEmpty && Lane.Contains(e.Location))
|
||||
{
|
||||
if (e.Y < thumb.Top)
|
||||
{
|
||||
ScrollByKey(Keys.Prior);
|
||||
return;
|
||||
}
|
||||
if (e.Y >= thumb.Bottom)
|
||||
{
|
||||
ScrollByKey(Keys.Next);
|
||||
return;
|
||||
}
|
||||
_dragging = true;
|
||||
_dragFrom = e.Y;
|
||||
_dragScrollFrom = _scroll;
|
||||
Capture = true;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (_dragging)
|
||||
{
|
||||
_dragging = false;
|
||||
Capture = false;
|
||||
Invalidate(Lane);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
_laidFor = -1;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Lay();
|
||||
Graphics graphics = e.Graphics;
|
||||
if (!_onCard)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(ControlInk.Overlay);
|
||||
graphics.FillRectangle(brush, ClientRectangle);
|
||||
}
|
||||
Font body = Fonts.Body;
|
||||
Font bodyBold = Fonts.BodyBold;
|
||||
int linePx = LinePx;
|
||||
int num = Px(4);
|
||||
SmoothingMode smoothingMode = graphics.SmoothingMode;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using (SolidBrush brush2 = new SolidBrush(ControlInk.Text2))
|
||||
{
|
||||
foreach (Point dot in _dots)
|
||||
{
|
||||
int num2 = dot.Y - _scroll;
|
||||
if (num2 + linePx >= 0 && num2 <= Height)
|
||||
{
|
||||
graphics.FillEllipse(brush2, dot.X + Px(4), (float)num2 + (float)(linePx - num) / 2f, num, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
graphics.SmoothingMode = smoothingMode;
|
||||
foreach (var item4 in _laid)
|
||||
{
|
||||
Point item = item4.At;
|
||||
string item2 = item4.Word;
|
||||
bool item3 = item4.Strong;
|
||||
int num3 = item.Y - _scroll;
|
||||
if (num3 + linePx >= 0 && num3 <= Height)
|
||||
{
|
||||
TextRenderer.DrawText(graphics, item2, item3 ? bodyBold : body, new Point(item.X, num3), item3 ? ControlInk.Text1 : ControlInk.Text2, TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
Rectangle thumb = Thumb;
|
||||
if (thumb.IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Color color;
|
||||
if (_dragging)
|
||||
{
|
||||
color = ControlInk.Text1;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = (_thumbHot ? ControlInk.Text2 : ControlInk.Edge);
|
||||
}
|
||||
SmoothingMode smoothingMode2 = graphics.SmoothingMode;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using (SolidBrush brush3 = new SolidBrush(color))
|
||||
{
|
||||
using GraphicsPath path = Glass.RoundedPath(thumb, (float)thumb.Width / 2f);
|
||||
graphics.FillPath(brush3, path);
|
||||
}
|
||||
graphics.SmoothingMode = smoothingMode2;
|
||||
}
|
||||
|
||||
internal static List<Block> Reflow(string plain)
|
||||
{
|
||||
return Reflow(plain, 48);
|
||||
}
|
||||
|
||||
internal static List<Block> Reflow(string plain, int headingLimit)
|
||||
{
|
||||
List<Block> blocks = new List<Block>();
|
||||
string[] array = (plain ?? "").Replace("\r\n", "\n").Replace('\r', '\n').Split('\n');
|
||||
StringBuilder text = new StringBuilder();
|
||||
bool bullet = false;
|
||||
bool gap = false;
|
||||
bool open = false;
|
||||
int lineCount = 0;
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
string text2 = array[i].Trim();
|
||||
if (text2.Length == 0)
|
||||
{
|
||||
Flush(followedByBlank: true);
|
||||
gap = true;
|
||||
continue;
|
||||
}
|
||||
if (text2[0] == '•' || ((text2[0] == '-' || text2[0] == '*') && text2.Length > 1 && char.IsWhiteSpace(text2[1])))
|
||||
{
|
||||
Flush(followedByBlank: false);
|
||||
bullet = true;
|
||||
text2 = text2.Substring(1).TrimStart();
|
||||
}
|
||||
else if (!open)
|
||||
{
|
||||
bullet = false;
|
||||
}
|
||||
if (open)
|
||||
{
|
||||
text.Append(' ');
|
||||
}
|
||||
text.Append(text2);
|
||||
open = true;
|
||||
lineCount++;
|
||||
}
|
||||
Flush(followedByBlank: true);
|
||||
return blocks;
|
||||
void Flush(bool followedByBlank)
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
string text3 = text.ToString().Trim();
|
||||
string lead = "";
|
||||
if (bullet)
|
||||
{
|
||||
Match match = LeadIn.Match(text3);
|
||||
if (match.Success)
|
||||
{
|
||||
lead = match.Groups["lead"].Value;
|
||||
text3 = match.Groups["rest"].Value;
|
||||
}
|
||||
}
|
||||
int num;
|
||||
if (((!bullet && lineCount == 1) & followedByBlank) && text3.Length <= headingLimit && !text3.Contains("://"))
|
||||
{
|
||||
string text4 = text3;
|
||||
num = ((".:!?".IndexOf(text4[text4.Length - 1]) < 0) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
bool heading = (byte)num != 0;
|
||||
blocks.Add(new Block(lead, text3, bullet, heading, gap && blocks.Count > 0));
|
||||
text.Clear();
|
||||
open = false;
|
||||
gap = false;
|
||||
lineCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void WheelForTest(int delta)
|
||||
{
|
||||
Wheel(delta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public static class Prompt
|
||||
{
|
||||
public static string Ask(string title, string initial)
|
||||
{
|
||||
return Ask(title, initial, null);
|
||||
}
|
||||
|
||||
public static string Ask(string title, string initial, string? body)
|
||||
{
|
||||
GlassTextBox box;
|
||||
using GlassShellForm glassShellForm = Build(title, initial, body, out box);
|
||||
return (glassShellForm.ShowDialog() == DialogResult.OK) ? box.Text : "";
|
||||
}
|
||||
|
||||
internal static GlassShellForm Build(string title, string initial, out GlassTextBox box)
|
||||
{
|
||||
return Build(title, initial, null, out box);
|
||||
}
|
||||
|
||||
internal static GlassShellForm Build(string title, string initial, string? body, out GlassTextBox box)
|
||||
{
|
||||
int num = S(24);
|
||||
int num2 = S(400);
|
||||
int num3 = num2 - 2 * num;
|
||||
int num4 = S(32);
|
||||
Label label = SignalDialogWindow.TitleLabel(title, num + S(2), S(23), num3);
|
||||
Label label2 = null;
|
||||
int num5 = S(60);
|
||||
if (!string.IsNullOrEmpty(body))
|
||||
{
|
||||
int height = SignalDialogWindow.MeasureBody(body, num3);
|
||||
label2 = SignalDialogWindow.BodyLabel(body, num + S(2), S(60), num3, height);
|
||||
num5 = label2.Bottom + S(16);
|
||||
}
|
||||
int num6 = num5 + num4 + S(24);
|
||||
GlassShellForm form = new GlassShellForm(title)
|
||||
{
|
||||
PaintsTitle = false,
|
||||
ClientSize = new Size(num2, num6 + num4 + S(20))
|
||||
};
|
||||
GlassTextBox field = new GlassTextBox
|
||||
{
|
||||
Text = initial,
|
||||
MaxLength = 40,
|
||||
FocusOnEdge = true,
|
||||
Location = new Point(num, num5),
|
||||
Size = new Size(num3, num4)
|
||||
};
|
||||
GlassButton ok = new GlassButton
|
||||
{
|
||||
Text = "Save",
|
||||
Kind = GlassButtonKind.Primary
|
||||
};
|
||||
ok.Size = new Size(SignalDialogWindow.TwinButtonWidth(ok.Text, ok.Font, S(20), S(96)), num4);
|
||||
ok.Location = new Point(num2 - num - ok.Width, num6);
|
||||
ok.Click += (object? s, EventArgs e) =>
|
||||
{
|
||||
Finish(DialogResult.OK);
|
||||
};
|
||||
GlassButton glassButton = new GlassButton
|
||||
{
|
||||
Text = "Cancel",
|
||||
Kind = GlassButtonKind.Secondary
|
||||
};
|
||||
glassButton.Size = new Size(SignalDialogWindow.TwinButtonWidth(glassButton.Text, glassButton.Font, S(20), S(96)), num4);
|
||||
glassButton.Location = new Point(ok.Left - S(8) - glassButton.Width, num6);
|
||||
glassButton.Click += (object? s, EventArgs e) =>
|
||||
{
|
||||
Finish(DialogResult.Cancel);
|
||||
};
|
||||
field.TextChanged += (object? s, EventArgs e) =>
|
||||
{
|
||||
SyncSave();
|
||||
};
|
||||
SyncSave();
|
||||
form.KeyDown += (object? s, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Return)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
if (ok.Enabled)
|
||||
{
|
||||
Finish(DialogResult.OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
form.ShowClose = false;
|
||||
form.Controls.Add(label);
|
||||
WindowDrag.Enable(label, form);
|
||||
if (label2 != null)
|
||||
{
|
||||
form.Controls.Add(label2);
|
||||
WindowDrag.Enable(label2, form);
|
||||
}
|
||||
form.Controls.Add(field);
|
||||
form.Controls.Add(ok);
|
||||
form.Controls.Add(glassButton);
|
||||
form.ActiveControl = field;
|
||||
form.Shown += (object? s, EventArgs e) =>
|
||||
{
|
||||
field.Inner.SelectionLength = 0;
|
||||
field.Inner.SelectionStart = field.Inner.TextLength;
|
||||
};
|
||||
box = field;
|
||||
return form;
|
||||
void Finish(DialogResult r)
|
||||
{
|
||||
form.DialogResult = r;
|
||||
form.Close();
|
||||
}
|
||||
static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
void SyncSave()
|
||||
{
|
||||
ok.Enabled = !string.IsNullOrWhiteSpace(field.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class QuietScrollPanel : Panel
|
||||
{
|
||||
private const int SB_BOTH = 3;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowScrollBar(nint hWnd, int wBar, bool bShow);
|
||||
|
||||
public QuietScrollPanel()
|
||||
{
|
||||
AutoScroll = true;
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
internal void ScrollByWheel(int delta)
|
||||
{
|
||||
OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
int num = DisplayRectangle.Height - ClientSize.Height;
|
||||
if (AutoScroll && num > 0)
|
||||
{
|
||||
int num2 = SystemInformation.MouseWheelScrollLines;
|
||||
if (num2 <= 0)
|
||||
{
|
||||
num2 = 3;
|
||||
}
|
||||
int num3 = e.Delta * num2 * 22 / 120;
|
||||
int y = Math.Clamp(-AutoScrollPosition.Y - num3, 0, num);
|
||||
AutoScrollPosition = new Point(-AutoScrollPosition.X, y);
|
||||
if (e is HandledMouseEventArgs e2)
|
||||
{
|
||||
e2.Handled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
}
|
||||
Invalidate(invalidateChildren: true);
|
||||
}
|
||||
|
||||
internal void TestScrollWheel(int delta)
|
||||
{
|
||||
OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
|
||||
}
|
||||
|
||||
protected override Point ScrollToControl(Control activeControl)
|
||||
{
|
||||
return DisplayRectangle.Location;
|
||||
}
|
||||
|
||||
private void ForwardWheel(object? sender, MouseEventArgs e)
|
||||
{
|
||||
OnMouseWheel(e);
|
||||
}
|
||||
|
||||
private void Hook(Control root)
|
||||
{
|
||||
foreach (Control control in root.Controls)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
control.ControlAdded -= OnDescendantAdded;
|
||||
control.ControlAdded += OnDescendantAdded;
|
||||
Hook(control);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDescendantAdded(object? sender, ControlEventArgs e)
|
||||
{
|
||||
Control control = e.Control;
|
||||
if (control != null)
|
||||
{
|
||||
control.MouseWheel -= ForwardWheel;
|
||||
control.MouseWheel += ForwardWheel;
|
||||
Hook(control);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnControlAdded(ControlEventArgs e)
|
||||
{
|
||||
base.OnControlAdded(e);
|
||||
OnDescendantAdded(this, e);
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
Hook(this);
|
||||
HideBars();
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
base.OnLayout(e);
|
||||
HideBars();
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
int msg = m.Msg;
|
||||
if ((msg == 131 || (uint)(msg - 276) <= 1u) ? true : false)
|
||||
{
|
||||
HideBars();
|
||||
}
|
||||
}
|
||||
|
||||
private void HideBars()
|
||||
{
|
||||
if (IsHandleCreated && !IsDisposed)
|
||||
{
|
||||
ShowScrollBar(Handle, 3, bShow: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class RevertConfirmForm : SignalDialogWindow
|
||||
{
|
||||
private static class Shape
|
||||
{
|
||||
public const int Width = 462;
|
||||
|
||||
public const int Pad = 24;
|
||||
|
||||
public const int TitleY = 23;
|
||||
|
||||
public const int BodyY = 60;
|
||||
|
||||
public const int BarGap = 26;
|
||||
|
||||
public const int FillH = 4;
|
||||
|
||||
public const int TrackH = 2;
|
||||
|
||||
public const int CountdownW = 24;
|
||||
|
||||
public const int CountdownGap = 14;
|
||||
|
||||
public const int CaptionGap = 15;
|
||||
|
||||
public const int ButtonGap = 39;
|
||||
|
||||
public const int BottomPad = 20;
|
||||
|
||||
public const int ButtonPad = 20;
|
||||
|
||||
public const int ButtonSplit = 8;
|
||||
|
||||
public const int Radius = 8;
|
||||
}
|
||||
|
||||
private sealed class ProgressTrack : Control
|
||||
{
|
||||
public float Fraction { get; set; } = 1f;
|
||||
|
||||
public ProgressTrack()
|
||||
{
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
SetStyle(ControlStyles.Selectable, value: false);
|
||||
TabStop = false;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
float num = Math.Max(1, Tokens.Scale(2));
|
||||
float y = ((float)Height - num) / 2f;
|
||||
using (SolidBrush brush = new SolidBrush(Theme.AccentDim))
|
||||
{
|
||||
FillPill(graphics, brush, new RectangleF(0f, y, Width, num), num / 2f);
|
||||
}
|
||||
float num2 = Math.Clamp(Fraction, 0f, 1f) * (float)Width;
|
||||
if (num2 >= (float)Height)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(Theme.Accent))
|
||||
{
|
||||
FillPill(graphics, brush2, new RectangleF(0f, 0f, num2, Height), (float)Height / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FillPill(Graphics g, Brush brush, RectangleF r, float radius)
|
||||
{
|
||||
if (r.Width < 1f || r.Height < 1f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using GraphicsPath path = Glass.RoundedPath(r, radius);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Timer _timer;
|
||||
|
||||
private readonly Label _title;
|
||||
|
||||
private readonly Label _body;
|
||||
|
||||
private readonly ProgressTrack _progress;
|
||||
|
||||
private readonly Label _countdown;
|
||||
|
||||
private readonly Label _safetyCaption;
|
||||
|
||||
private readonly GlassButton _keep;
|
||||
|
||||
private readonly GlassButton _goBack;
|
||||
|
||||
private readonly int _totalSeconds;
|
||||
|
||||
private int _secondsLeft;
|
||||
|
||||
private static readonly TimeSpan ArmAfter = TimeSpan.FromMilliseconds(400.0);
|
||||
|
||||
private bool _armed;
|
||||
|
||||
internal GlassButton TestKeepButton => _keep;
|
||||
|
||||
internal GlassButton TestGoBackButton => _goBack;
|
||||
|
||||
internal string TestCountdownText => _countdown.Text;
|
||||
|
||||
internal float TestProgressFraction => _progress.Fraction;
|
||||
|
||||
internal string TestMessageText => _body.Text;
|
||||
|
||||
internal string TestSafetyCaptionText => _safetyCaption.Text;
|
||||
|
||||
internal int TestTimerIntervalMs => _timer.Interval;
|
||||
|
||||
internal static int TestArmDelayMs => (int)ArmAfter.TotalMilliseconds;
|
||||
|
||||
public event Action? Confirmed;
|
||||
|
||||
private new static int S(int logical)
|
||||
{
|
||||
return Tokens.Scale(logical);
|
||||
}
|
||||
|
||||
public RevertConfirmForm(string message, int graceSeconds)
|
||||
{
|
||||
_totalSeconds = Math.Max(1, graceSeconds);
|
||||
_secondsLeft = _totalSeconds;
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
TopMost = true;
|
||||
AccessibleName = "Keep this display mode?";
|
||||
AccessibleDescription = message;
|
||||
int num = S(24);
|
||||
int num2 = S(462);
|
||||
int num3 = num2 - 2 * num;
|
||||
_title = SignalDialogWindow.TitleLabel("Keep this display mode?", num + S(2), S(23), num3);
|
||||
Controls.Add(_title);
|
||||
int height = Math.Max(2 * Fonts.LineHeight(FontRole.Body), TextRenderer.MeasureText(message, Fonts.Body, new Size(num3, int.MaxValue), TextFormatFlags.WordBreak).Height);
|
||||
_body = SignalDialogWindow.BodyLabel(message, num + S(2), S(60), num3, height);
|
||||
Controls.Add(_body);
|
||||
int num4 = _body.Bottom + S(26);
|
||||
int num5 = S(24);
|
||||
int num6 = num3 - num5 - S(14);
|
||||
_progress = new ProgressTrack
|
||||
{
|
||||
Location = new Point(num, num4),
|
||||
Size = new Size(num6, S(4))
|
||||
};
|
||||
Controls.Add(_progress);
|
||||
_countdown = new Label
|
||||
{
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.CaptionBold,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleRight,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(num + num6 + S(14), num4 + S(4) / 2 - S(8)),
|
||||
Size = new Size(num5 + SignalDialogWindow.GlyphPad(Fonts.CaptionBold), S(16))
|
||||
};
|
||||
Controls.Add(_countdown);
|
||||
int num7 = num4 + S(4) + S(15);
|
||||
_safetyCaption = new Label
|
||||
{
|
||||
Text = "Doing nothing is safe: the old mode comes back.",
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Caption,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(SignalDialogWindow.Ink(num + S(2), Fonts.Caption), num7),
|
||||
Size = new Size(num3, Fonts.LineHeight(FontRole.Caption))
|
||||
};
|
||||
Controls.Add(_safetyCaption);
|
||||
int num8 = num7 + _safetyCaption.Height + S(39);
|
||||
int num9 = S(32);
|
||||
_keep = new GlassButton
|
||||
{
|
||||
Text = "Keep this mode",
|
||||
Kind = GlassButtonKind.Primary,
|
||||
Name = "RevertConfirmKeep"
|
||||
};
|
||||
_keep.Size = new Size(ButtonWidth(_keep.Text, _keep.Font), num9);
|
||||
_keep.Location = new Point(num2 - num - _keep.Width, num8);
|
||||
_keep.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Accept();
|
||||
};
|
||||
Controls.Add(_keep);
|
||||
_goBack = new GlassButton
|
||||
{
|
||||
Text = "Go back now",
|
||||
Kind = GlassButtonKind.Secondary,
|
||||
Name = "RevertConfirmGoBack"
|
||||
};
|
||||
_goBack.Size = new Size(ButtonWidth(_goBack.Text, _goBack.Font), num9);
|
||||
_goBack.Location = new Point(_keep.Left - S(8) - _goBack.Width, num8);
|
||||
_goBack.Click += (object? _, EventArgs _) =>
|
||||
{
|
||||
Close();
|
||||
};
|
||||
Controls.Add(_goBack);
|
||||
_goBack.TabIndex = 0;
|
||||
_keep.TabIndex = 1;
|
||||
ActiveControl = _goBack;
|
||||
ClientSize = new Size(num2, num8 + num9 + S(20));
|
||||
UpdateCountdown();
|
||||
_timer = new Timer
|
||||
{
|
||||
Interval = 1000
|
||||
};
|
||||
_timer.Tick += (object? _, EventArgs _) =>
|
||||
{
|
||||
Tick();
|
||||
};
|
||||
KeyDown += (object? _, KeyEventArgs e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
Swallow(e);
|
||||
GoBack();
|
||||
}
|
||||
else if (e.KeyCode == Keys.Return)
|
||||
{
|
||||
Swallow(e);
|
||||
if (_armed)
|
||||
{
|
||||
GoBack();
|
||||
}
|
||||
}
|
||||
else if (!_armed)
|
||||
{
|
||||
Swallow(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void Swallow(KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
_timer.Stop();
|
||||
_goBack.PerformClick();
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
if ((keyData & (Keys.Control | Keys.Alt)) == 0)
|
||||
{
|
||||
switch (keyData & Keys.KeyCode)
|
||||
{
|
||||
case Keys.Escape:
|
||||
GoBack();
|
||||
return true;
|
||||
case Keys.Return:
|
||||
if (_armed)
|
||||
{
|
||||
GoBack();
|
||||
}
|
||||
return true;
|
||||
case Keys.Tab:
|
||||
if (!_armed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Keys.Left:
|
||||
case Keys.Up:
|
||||
case Keys.Right:
|
||||
case Keys.Down:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
private static int ButtonWidth(string text, Font font)
|
||||
{
|
||||
return TextRenderer.MeasureText(text, font).Width + S(20);
|
||||
}
|
||||
|
||||
private void Accept()
|
||||
{
|
||||
_timer.Stop();
|
||||
Confirmed?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
_secondsLeft--;
|
||||
if (_secondsLeft <= 0)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCountdown();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCountdown()
|
||||
{
|
||||
_countdown.Text = $"{_secondsLeft} s";
|
||||
_progress.Fraction = ((_totalSeconds <= 0) ? 0f : ((float)_secondsLeft / (float)_totalSeconds));
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
base.OnShown(e);
|
||||
_timer.Start();
|
||||
ActiveControl = _goBack;
|
||||
Activate();
|
||||
Timer arm = new Timer
|
||||
{
|
||||
Interval = (int)ArmAfter.TotalMilliseconds
|
||||
};
|
||||
arm.Tick += (object? _, EventArgs _) =>
|
||||
{
|
||||
_armed = true;
|
||||
arm.Stop();
|
||||
arm.Dispose();
|
||||
};
|
||||
arm.Start();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_timer.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
internal void TestAdvanceOneSecond()
|
||||
{
|
||||
Tick();
|
||||
}
|
||||
|
||||
internal void TestArmEnterNow()
|
||||
{
|
||||
_armed = true;
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal sealed class RovingFocus
|
||||
{
|
||||
private static readonly ConditionalWeakTable<Control, RovingFocus> ByItem = new ConditionalWeakTable<Control, RovingFocus>();
|
||||
|
||||
[ThreadStatic]
|
||||
private static List<WeakReference<RovingFocus>>? _groups;
|
||||
|
||||
private readonly Control[] _items;
|
||||
|
||||
private readonly Func<Control, bool> _isSelected;
|
||||
|
||||
private readonly Func<Control, bool> _arrowChooses;
|
||||
|
||||
internal IReadOnlyList<Control> Items => _items;
|
||||
|
||||
private RovingFocus(Control[] items, Func<Control, bool> isSelected, Func<Control, bool> arrowChooses)
|
||||
{
|
||||
_items = items;
|
||||
_isSelected = isSelected;
|
||||
_arrowChooses = arrowChooses;
|
||||
}
|
||||
|
||||
internal static RovingFocus Attach(IEnumerable<Control> items, Func<Control, bool> isSelected, Func<Control, bool>? arrowChooses = null)
|
||||
{
|
||||
RovingFocus rovingFocus = new RovingFocus(items.ToArray(), isSelected, arrowChooses ?? ((Func<Control, bool>)((Control _) => true)));
|
||||
Control[] items2 = rovingFocus._items;
|
||||
foreach (Control key in items2)
|
||||
{
|
||||
ByItem.AddOrUpdate(key, rovingFocus);
|
||||
}
|
||||
(_groups ?? (_groups = new List<WeakReference<RovingFocus>>())).Add(new WeakReference<RovingFocus>(rovingFocus));
|
||||
rovingFocus.Refresh();
|
||||
return rovingFocus;
|
||||
}
|
||||
|
||||
internal static RovingFocus? Of(Control item)
|
||||
{
|
||||
if (!ByItem.TryGetValue(item, out RovingFocus value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static bool Usable(Control c)
|
||||
{
|
||||
if (!c.IsDisposed && c.Enabled)
|
||||
{
|
||||
return c.Visible;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal Control? Current()
|
||||
{
|
||||
Control control = null;
|
||||
Control control2 = null;
|
||||
Control[] items = _items;
|
||||
foreach (Control control3 in items)
|
||||
{
|
||||
if (Usable(control3))
|
||||
{
|
||||
if (_isSelected(control3))
|
||||
{
|
||||
return control3;
|
||||
}
|
||||
if (control == null)
|
||||
{
|
||||
control = control3;
|
||||
}
|
||||
if (control3.Focused)
|
||||
{
|
||||
control2 = control3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return control2 ?? control;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
Control control = Current();
|
||||
if (control == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Control[] items = _items;
|
||||
foreach (Control control2 in items)
|
||||
{
|
||||
if (!control2.IsDisposed)
|
||||
{
|
||||
control2.TabStop = control2 == control;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RefreshAll()
|
||||
{
|
||||
if (_groups == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_groups.RemoveAll((WeakReference<RovingFocus> w) => !w.TryGetTarget(out RovingFocus target2) || target2._items.All((Control c) => c.IsDisposed));
|
||||
foreach (WeakReference<RovingFocus> group in _groups)
|
||||
{
|
||||
if (group.TryGetTarget(out var target))
|
||||
{
|
||||
target.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal Control? Target(Control from, Keys keyData)
|
||||
{
|
||||
if ((keyData & Keys.Modifiers) != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num = Array.IndexOf(_items, from);
|
||||
if (num < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num2 = _items.Length;
|
||||
switch (keyData & Keys.KeyCode)
|
||||
{
|
||||
case Keys.Left:
|
||||
case Keys.Up:
|
||||
{
|
||||
for (int j = 1; j <= num2; j++)
|
||||
{
|
||||
if (Usable(_items[(num - j + num2) % num2]))
|
||||
{
|
||||
return _items[(num - j + num2) % num2];
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
case Keys.Right:
|
||||
case Keys.Down:
|
||||
{
|
||||
for (int i = 1; i <= num2; i++)
|
||||
{
|
||||
if (Usable(_items[(num + i) % num2]))
|
||||
{
|
||||
return _items[(num + i) % num2];
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
case Keys.Home:
|
||||
return _items.FirstOrDefault(Usable) ?? from;
|
||||
case Keys.End:
|
||||
return _items.LastOrDefault(Usable) ?? from;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ArrowChooses(Control item)
|
||||
{
|
||||
return _arrowChooses(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public abstract class SignalDialogWindow : Form
|
||||
{
|
||||
public static class Measure
|
||||
{
|
||||
public const int Radius = 8;
|
||||
|
||||
public const int Pad = 24;
|
||||
|
||||
public const int TitleY = 23;
|
||||
|
||||
public const int BodyY = 60;
|
||||
|
||||
public const int BodyToContent = 16;
|
||||
|
||||
public const int ContentToFooter = 24;
|
||||
|
||||
public const int ButtonMinWidth = 96;
|
||||
|
||||
public const int ButtonPadX = 12;
|
||||
|
||||
public const int ButtonGap = 8;
|
||||
|
||||
public const int FooterBottom = 20;
|
||||
|
||||
public const int ButtonPad = 20;
|
||||
|
||||
public const int WidthSm = 400;
|
||||
|
||||
public const int WidthMd = 460;
|
||||
|
||||
public const int WidthLg = 560;
|
||||
}
|
||||
|
||||
private readonly int _dpi;
|
||||
|
||||
protected int ChromeDpi => _dpi;
|
||||
|
||||
protected string? ChromeTitle { get; set; }
|
||||
|
||||
protected string? ChromeBody { get; set; }
|
||||
|
||||
protected int ChromeBodyHeight { get; set; }
|
||||
|
||||
protected int TextWidth => ClientSize.Width - 2 * S(24);
|
||||
|
||||
protected int BodyTop => S(60);
|
||||
|
||||
protected int ContentTop => BodyTop + ChromeBodyHeight + S(16);
|
||||
|
||||
protected virtual bool Square => false;
|
||||
|
||||
internal static Color EdgeInk
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!SlateSurface.Active)
|
||||
{
|
||||
return SignalTokens.Ash.WindowEdge;
|
||||
}
|
||||
return ControlInk.Over(SignalTokens.Slate.WindowEdge, ControlInk.Overlay);
|
||||
}
|
||||
}
|
||||
|
||||
protected SignalDialogWindow()
|
||||
{
|
||||
_dpi = SignalInk.DpiFor(this);
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
ShowInTaskbar = false;
|
||||
BackColor = Theme.Background;
|
||||
DoubleBuffered = true;
|
||||
Icon = AppIcon.Value;
|
||||
KeyPreview = true;
|
||||
Font = Fonts.Body;
|
||||
AccessibleRole = AccessibleRole.Dialog;
|
||||
Opacity = 0.99;
|
||||
Load += (object? _, EventArgs _) =>
|
||||
{
|
||||
ApplyRegion();
|
||||
};
|
||||
Resize += (object? _, EventArgs _) =>
|
||||
{
|
||||
ApplyRegion();
|
||||
};
|
||||
}
|
||||
|
||||
protected int S(int logical)
|
||||
{
|
||||
return Tokens.ScaleAt(_dpi, logical);
|
||||
}
|
||||
|
||||
internal static int MeasureBody(string? body, int textWidth)
|
||||
{
|
||||
int val = Fonts.LineHeight(FontRole.Body);
|
||||
if (string.IsNullOrEmpty(body))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int height = TextRenderer.MeasureText(body, Fonts.Body, new Size(Math.Max(1, textWidth), 0), TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak).Height;
|
||||
return Math.Max(val, height);
|
||||
}
|
||||
|
||||
internal static Label TitleLabel(string text, int inkLeft, int top, int width)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
ForeColor = Theme.Text,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Title,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(Ink(inkLeft, Fonts.Title), top),
|
||||
Size = new Size(width, Fonts.LineHeight(FontRole.Title))
|
||||
};
|
||||
}
|
||||
|
||||
internal static Label BodyLabel(string text, int inkLeft, int top, int width, int height)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
ForeColor = Theme.TextDim,
|
||||
BackColor = Color.Transparent,
|
||||
Font = Fonts.Body,
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.TopLeft,
|
||||
UseMnemonic = false,
|
||||
Location = new Point(Ink(inkLeft, Fonts.Body), top),
|
||||
Size = new Size(width, height)
|
||||
};
|
||||
}
|
||||
|
||||
internal static int TwinButtonWidth(string text, Font font, int scaledPad, int scaledMin)
|
||||
{
|
||||
return Math.Max(scaledMin, TextRenderer.MeasureText(text, font).Width + scaledPad);
|
||||
}
|
||||
|
||||
protected GlassButton FooterButton(string text, GlassButtonKind kind, string? name = null)
|
||||
{
|
||||
GlassButton glassButton = new GlassButton
|
||||
{
|
||||
Text = text,
|
||||
Kind = kind
|
||||
};
|
||||
if (name != null)
|
||||
{
|
||||
glassButton.Name = name;
|
||||
}
|
||||
int width = Math.Max(S(96), TextRenderer.MeasureText(text, glassButton.Font).Width + 2 * S(12));
|
||||
glassButton.Size = new Size(width, S(32));
|
||||
glassButton.AccessibleName = text;
|
||||
return glassButton;
|
||||
}
|
||||
|
||||
protected void PlaceFooter(params GlassButton[] leftToRight)
|
||||
{
|
||||
int num = S(24);
|
||||
int num2 = ClientSize.Width - num;
|
||||
for (int num3 = leftToRight.Length - 1; num3 >= 0; num3--)
|
||||
{
|
||||
GlassButton glassButton = leftToRight[num3];
|
||||
num2 -= glassButton.Width;
|
||||
glassButton.Location = new Point(num2, ClientSize.Height - S(20) - glassButton.Height);
|
||||
glassButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
num2 -= S(8);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyRegion()
|
||||
{
|
||||
if (Square)
|
||||
{
|
||||
if (Region != null)
|
||||
{
|
||||
Region = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
using GraphicsPath path = Glass.RoundedPath(new RectangleF(0f, 0f, ClientSize.Width, ClientSize.Height), S(8));
|
||||
Region = new Region(path);
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(Theme.Background);
|
||||
e.Graphics.FillRectangle(brush, ClientRectangle);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
PaintChrome(e.Graphics, ClientSize, _dpi, Square);
|
||||
PaintWords(e.Graphics);
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
internal static void PaintChrome(Graphics g, Size size, int dpi, bool square = false)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Theme.Background))
|
||||
{
|
||||
g.FillRectangle(brush, new Rectangle(Point.Empty, size));
|
||||
}
|
||||
if (square)
|
||||
{
|
||||
using (SolidBrush brush2 = new SolidBrush(ControlInk.Overlay))
|
||||
{
|
||||
g.FillRectangle(brush2, new Rectangle(Point.Empty, size));
|
||||
}
|
||||
PaintSquareEdge(g, size, dpi);
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlInk.PaintBox(g, size, Tokens.ScaleAt(dpi, 8), ControlInk.Hairline(dpi), ControlInk.Overlay, EdgeInk);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void PaintSquareEdge(Graphics g, Size size, int dpi)
|
||||
{
|
||||
int num = Math.Min(ControlInk.Hairline(dpi), Math.Min(size.Width, size.Height) / 2);
|
||||
SmoothingMode smoothingMode = g.SmoothingMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
g.PixelOffsetMode = PixelOffsetMode.None;
|
||||
try
|
||||
{
|
||||
using SolidBrush brush = new SolidBrush(EdgeInk);
|
||||
g.FillRectangle(brush, 0, 0, size.Width, num);
|
||||
g.FillRectangle(brush, 0, size.Height - num, size.Width, num);
|
||||
g.FillRectangle(brush, 0, 0, num, size.Height);
|
||||
g.FillRectangle(brush, size.Width - num, 0, num, size.Height);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.SmoothingMode = smoothingMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintWords(Graphics g)
|
||||
{
|
||||
int num = S(24);
|
||||
int textWidth = TextWidth;
|
||||
if (!string.IsNullOrEmpty(ChromeTitle))
|
||||
{
|
||||
TextRenderer.DrawText(g, ChromeTitle, Fonts.Title, new Rectangle(Ink(num + S(2), Fonts.Title), S(23), textWidth + GlyphPad(Fonts.Title), Fonts.LineHeight(FontRole.Title)), Theme.Text, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ChromeBody))
|
||||
{
|
||||
TextRenderer.DrawText(g, ChromeBody, Fonts.Body, new Rectangle(Ink(num + S(2), Fonts.Body), BodyTop, textWidth + GlyphPad(Fonts.Body), ChromeBodyHeight), Theme.TextDim, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak);
|
||||
}
|
||||
}
|
||||
|
||||
internal static int GlyphPad(Font font)
|
||||
{
|
||||
return (TextRenderer.MeasureText("H", font).Width - TextRenderer.MeasureText("H", font, Size.Empty, TextFormatFlags.NoPadding).Width) / 2;
|
||||
}
|
||||
|
||||
internal static int Ink(int x, Font font)
|
||||
{
|
||||
return x - GlyphPad(font);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class SignalToolTip : ToolTip
|
||||
{
|
||||
internal const int PadX = 8;
|
||||
|
||||
internal const int PadY = 4;
|
||||
|
||||
internal const int MaxWidth = 280;
|
||||
|
||||
internal const int Radius = 4;
|
||||
|
||||
private static int Dpi => Tokens.Dpi;
|
||||
|
||||
public SignalToolTip()
|
||||
{
|
||||
OwnerDraw = true;
|
||||
UseAnimation = false;
|
||||
UseFading = false;
|
||||
InitialDelay = 500;
|
||||
ReshowDelay = 120;
|
||||
AutoPopDelay = 32767;
|
||||
BackColor = ControlInk.Overlay;
|
||||
ForeColor = ControlInk.Text1;
|
||||
Draw += (object? _, DrawToolTipEventArgs e) =>
|
||||
{
|
||||
Paint(e.Graphics, e.Bounds, e.ToolTipText, GroundOf(e.AssociatedControl));
|
||||
};
|
||||
Popup += (object? _, PopupEventArgs e) =>
|
||||
{
|
||||
e.ToolTipSize = Measure(GetToolTip(e.AssociatedControl) ?? string.Empty);
|
||||
};
|
||||
}
|
||||
|
||||
internal static Color GroundOf(Control? c)
|
||||
{
|
||||
while (c != null)
|
||||
{
|
||||
Color backColor = c.BackColor;
|
||||
if (backColor.A == byte.MaxValue && !backColor.IsEmpty && backColor.ToArgb() != Control.DefaultBackColor.ToArgb())
|
||||
{
|
||||
return backColor;
|
||||
}
|
||||
c = c.Parent;
|
||||
}
|
||||
return Theme.Background;
|
||||
}
|
||||
|
||||
internal static Size Measure(string text)
|
||||
{
|
||||
int dpi = Dpi;
|
||||
int num = Tokens.ScaleAt(dpi, 8);
|
||||
int num2 = Tokens.ScaleAt(dpi, 4);
|
||||
int width = Tokens.ScaleAt(dpi, 280) - 2 * num;
|
||||
Size size = TextRenderer.MeasureText(text, Fonts.Caption, new Size(width, 0), TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
return new Size(size.Width + 2 * num, size.Height + 2 * num2);
|
||||
}
|
||||
|
||||
internal static void Paint(Graphics g, Rectangle bounds, string text, Color? ground = null)
|
||||
{
|
||||
int dpi = Dpi;
|
||||
using (SolidBrush brush = new SolidBrush(ground ?? Theme.Background))
|
||||
{
|
||||
g.FillRectangle(brush, bounds);
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
g.TranslateTransform(bounds.X, bounds.Y);
|
||||
ControlInk.PaintBox(g, bounds.Size, Tokens.ScaleAt(dpi, 4), ControlInk.Hairline(dpi), ControlInk.Overlay, SignalDialogWindow.EdgeInk);
|
||||
g.Restore(gstate);
|
||||
int num = Tokens.ScaleAt(dpi, 8);
|
||||
int num2 = Tokens.ScaleAt(dpi, 4);
|
||||
TextRenderer.DrawText(g, text, Fonts.Caption, new Rectangle(bounds.X + num, bounds.Y + num2, bounds.Width - 2 * num, bounds.Height - 2 * num2), ControlInk.Text1, TextFormatFlags.NoPrefix | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
internal static class TheClipboard
|
||||
{
|
||||
internal static Action<string>? InsteadOfTheRealOneForTest { get; set; }
|
||||
|
||||
internal static bool Put(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Action<string> insteadOfTheRealOneForTest = InsteadOfTheRealOneForTest;
|
||||
if (insteadOfTheRealOneForTest != null)
|
||||
{
|
||||
insteadOfTheRealOneForTest(text);
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(text);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CrashLog.Write(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class VoteButton : Control
|
||||
{
|
||||
private bool _active;
|
||||
|
||||
private readonly HoverFade _fade;
|
||||
|
||||
private readonly HoverFade _press;
|
||||
|
||||
public bool ThumbUp { get; init; }
|
||||
|
||||
public Func<Color> Tint { get; init; } = () => Theme.Accent;
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_active != value)
|
||||
{
|
||||
_active = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public VoteButton()
|
||||
{
|
||||
_fade = new HoverFade(this);
|
||||
_press = new HoverFade(this);
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
|
||||
BackColor = Color.Transparent;
|
||||
Cursor = Cursors.Hand;
|
||||
Size = new Size(64, 40);
|
||||
TabStop = true;
|
||||
SetStyle(ControlStyles.Selectable, value: true);
|
||||
AccessibleRole = AccessibleRole.RadioButton;
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AccessibleName = Text;
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
{
|
||||
base.OnGotFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
_fade.Set(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_fade.Set(hot: false);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
Focus();
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
_press.Snap(hot: true);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
_press.Set(hot: false);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
Keys keyCode = e.KeyCode;
|
||||
if ((keyCode == Keys.Return || keyCode == Keys.Space) ? true : false)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TestPressKey(Keys key)
|
||||
{
|
||||
OnKeyDown(new KeyEventArgs(key));
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics graphics = e.Graphics;
|
||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Color color = Tint();
|
||||
float value = _press.Value;
|
||||
float num = 1.5f * value;
|
||||
RectangleF rect = new RectangleF(0.5f + num, 0.5f + num, (float)(Width - 1) - 2f * num, (float)(Height - 1) - 2f * num);
|
||||
if (rect.Width <= 0f || rect.Height <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float num2 = rect.Height / 2f;
|
||||
using (GraphicsPath path = Glass.RoundedPath(rect, num2))
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Color.FromArgb(_active ? 210 : ((int)(26f + 34f * _fade.Value)), color)))
|
||||
{
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
using Pen pen = new Pen(Color.FromArgb(_active ? 235 : 110, color), 1f);
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
if (Focused)
|
||||
{
|
||||
using Pen pen2 = new Pen(Color.FromArgb(200, color), 2f);
|
||||
using GraphicsPath path2 = Glass.RoundedPath(RectangleF.Inflate(rect, -2.5f, -2.5f), Math.Max(1f, num2 - 2.5f));
|
||||
graphics.DrawPath(pen2, path2);
|
||||
}
|
||||
Color color2 = (_active ? Theme.OnAccent : color);
|
||||
DrawThumb(graphics, new Rectangle((int)(rect.X + rect.Width / 2f) - 9, (int)(rect.Y + rect.Height / 2f) - 9, 18, 18), color2, ThumbUp);
|
||||
}
|
||||
|
||||
private static void DrawThumb(Graphics g, Rectangle r, Color color, bool up)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
try
|
||||
{
|
||||
g.TranslateTransform((float)r.X + (float)r.Width / 2f, (float)r.Y + (float)r.Height / 2f);
|
||||
if (!up)
|
||||
{
|
||||
g.ScaleTransform(1f, -1f);
|
||||
}
|
||||
float num = (float)r.Width / 20f;
|
||||
g.ScaleTransform(num, num);
|
||||
using SolidBrush brush = new SolidBrush(color);
|
||||
using (GraphicsPath path = Glass.RoundedPath(new RectangleF(-3.5f, -9f, 5f, 9f), 2.5f))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
using (GraphicsPath path2 = Glass.RoundedPath(new RectangleF(-3.5f, -2.5f, 11.5f, 9.5f), 2.5f))
|
||||
{
|
||||
g.FillPath(brush, path2);
|
||||
}
|
||||
using GraphicsPath path3 = Glass.RoundedPath(new RectangleF(-9f, -1.5f, 4f, 8.5f), 1.5f);
|
||||
g.FillPath(brush, path3);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.Restore(gstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using VibranceHud.Design;
|
||||
using VibranceHud.Zoom;
|
||||
|
||||
namespace VibranceHud.Controls;
|
||||
|
||||
public sealed class ZoomSection : Panel
|
||||
{
|
||||
internal const string Title = "Hold to zoom";
|
||||
|
||||
internal const string FairPlay = "Zoom uses Windows' own Magnifier. Some games' rules treat zoom as an advantage - check yours.";
|
||||
|
||||
internal const string LockedLine = "Zoom comes with the Dark Boost & Zoom add-on.";
|
||||
|
||||
internal const string PickAKey = "Pick a key to hold.";
|
||||
|
||||
internal const string EdgesWord = "Smooth edges";
|
||||
|
||||
internal const string EdgesHint = "Off: sharp pixels. On: softer, a little blurry.";
|
||||
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
private readonly Action _save;
|
||||
|
||||
private readonly Func<bool> _allowed;
|
||||
|
||||
private readonly Func<uint, uint, bool> _bindKey;
|
||||
|
||||
private readonly Func<string> _whyRefused;
|
||||
|
||||
private bool _syncing;
|
||||
|
||||
private readonly Label _title;
|
||||
|
||||
private readonly Label _keyWord;
|
||||
|
||||
private readonly Label _levelWord;
|
||||
|
||||
private readonly Label _levelValue;
|
||||
|
||||
private readonly Label _smoothWord;
|
||||
|
||||
private readonly Label _edgesWord;
|
||||
|
||||
private readonly Label _edgesHint;
|
||||
|
||||
private readonly Label _status;
|
||||
|
||||
private readonly Label _fair;
|
||||
|
||||
private readonly ToggleSwitch _on;
|
||||
|
||||
private readonly ToggleSwitch _smooth;
|
||||
|
||||
private readonly ToggleSwitch _edges;
|
||||
|
||||
private readonly HotkeyPicker _key;
|
||||
|
||||
private readonly FlatSlider _level;
|
||||
|
||||
public int WantedHeight => RowPitch * 4 + EdgesBlockHeight() + Tokens.Scale(20) + FairHeight() + Tokens.Scale(8);
|
||||
|
||||
private int RowPitch => Tokens.Scale(40);
|
||||
|
||||
public int Gutter => FlatSlider.EdgeInsetAt(ControlInk.Dpi(this));
|
||||
|
||||
internal ToggleSwitch SwitchForTest => _on;
|
||||
|
||||
internal ToggleSwitch EdgesForTest => _edges;
|
||||
|
||||
internal HotkeyPicker KeyForTest => _key;
|
||||
|
||||
internal FlatSlider LevelForTest => _level;
|
||||
|
||||
internal string StatusForTest => _status.Text;
|
||||
|
||||
public event Action? Changed;
|
||||
|
||||
public ZoomSection(AppSettings settings, Action save, Func<bool> allowed, Func<uint, uint, bool> bindKey, Func<string> whyRefused)
|
||||
{
|
||||
_settings = settings;
|
||||
_save = save;
|
||||
_allowed = allowed;
|
||||
_bindKey = bindKey;
|
||||
_whyRefused = whyRefused;
|
||||
BackColor = Color.Transparent;
|
||||
Name = "zoomSection";
|
||||
_title = Words("Hold to zoom", Fonts.BodyBold, Theme.Text);
|
||||
_on = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Hold to zoom",
|
||||
Name = "zoomSwitch"
|
||||
};
|
||||
_on.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetEnabled(_on.Checked);
|
||||
}
|
||||
};
|
||||
_keyWord = Words("Zoom key", Fonts.Body, Theme.TextDim);
|
||||
_key = new HotkeyPicker
|
||||
{
|
||||
AllowMouseButtons = true,
|
||||
AccessibleName = "Zoom key",
|
||||
Name = "zoomKey"
|
||||
};
|
||||
_key.HotkeyChanged += (uint mask, uint vk) =>
|
||||
{
|
||||
ChooseKey(mask, vk);
|
||||
};
|
||||
_levelWord = Words("Zoom level", Fonts.Body, Theme.TextDim);
|
||||
_levelValue = Words("", Fonts.BodyBold, Theme.Text);
|
||||
_levelValue.TextAlign = ContentAlignment.MiddleRight;
|
||||
_level = new FlatSlider
|
||||
{
|
||||
AccessibleName = "Zoom level",
|
||||
Name = "zoomLevel",
|
||||
Minimum = (int)Math.Round(6.0),
|
||||
Maximum = (int)Math.Round(16.0),
|
||||
Value = (int)Math.Round(8.0)
|
||||
};
|
||||
_level.ValueChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetLevel((float)_level.Value * 0.25f);
|
||||
}
|
||||
};
|
||||
_smoothWord = Words("Smooth", Fonts.Body, Theme.TextDim);
|
||||
_smooth = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Smooth zoom",
|
||||
Name = "zoomSmooth"
|
||||
};
|
||||
_smooth.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetSmooth(_smooth.Checked);
|
||||
}
|
||||
};
|
||||
_edgesWord = Words("Smooth edges", Fonts.Body, Theme.TextDim);
|
||||
_edges = new ToggleSwitch
|
||||
{
|
||||
Size = new Size(40, 20),
|
||||
AccessibleName = "Smooth edges",
|
||||
Name = "zoomSmoothEdges"
|
||||
};
|
||||
_edges.CheckedChanged += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (!_syncing)
|
||||
{
|
||||
SetSmoothEdges(_edges.Checked);
|
||||
}
|
||||
};
|
||||
_edgesHint = Words("Off: sharp pixels. On: softer, a little blurry.", Fonts.Caption, Theme.TextFaint);
|
||||
_status = Words("", Fonts.Caption, Theme.TextDim);
|
||||
_fair = Words("Zoom uses Windows' own Magnifier. Some games' rules treat zoom as an advantage - check yours.", Fonts.Caption, Theme.TextFaint);
|
||||
Controls.AddRange(new Control[14]
|
||||
{
|
||||
_title, _on, _keyWord, _key, _levelWord, _levelValue, _level, _smoothWord, _smooth, _edgesWord,
|
||||
_edges, _edgesHint, _status, _fair
|
||||
});
|
||||
Sync();
|
||||
}
|
||||
|
||||
private Label Words(string text, Font font, Color colour)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Text = text,
|
||||
Font = font,
|
||||
ForeColor = colour,
|
||||
BackColor = Color.Transparent,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
AutoSize = false,
|
||||
UseMnemonic = false
|
||||
};
|
||||
}
|
||||
|
||||
private static int EdgesBlockHeight()
|
||||
{
|
||||
return Tokens.Scale(26) + Tokens.Scale(20) + Tokens.Scale(4);
|
||||
}
|
||||
|
||||
private int FairHeight()
|
||||
{
|
||||
return Tokens.Scale(36);
|
||||
}
|
||||
|
||||
protected override void OnLayout(LayoutEventArgs e)
|
||||
{
|
||||
base.OnLayout(e);
|
||||
int gutter = Gutter;
|
||||
int num = Math.Max(Tokens.Scale(200), ClientSize.Width - 2 * gutter);
|
||||
int rowPitch = RowPitch;
|
||||
int num2 = Tokens.Scale(26);
|
||||
int num3 = Tokens.Scale(40);
|
||||
int num4 = Tokens.Scale(20);
|
||||
int num5 = 0;
|
||||
_title.SetBounds(gutter - Ink(_title), num5, num - num3 - 8, num2);
|
||||
_on.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += rowPitch;
|
||||
int num6 = Math.Min(num - Tokens.Scale(110), Tokens.Scale(300));
|
||||
_keyWord.SetBounds(gutter - Ink(_keyWord), num5, Tokens.Scale(100), num2);
|
||||
_key.SetBounds(gutter + num - num6, num5 - Tokens.Scale(4), num6, Tokens.Scale(36));
|
||||
num5 += rowPitch;
|
||||
_levelWord.SetBounds(gutter - Ink(_levelWord), num5, num - Tokens.Scale(70), num2);
|
||||
_levelValue.SetBounds(gutter + num - Tokens.Scale(70) + Ink(_levelValue), num5, Tokens.Scale(70), num2);
|
||||
_level.SetTrackBounds(gutter, num5 + num2 + Tokens.Scale(2), num, Tokens.Scale(16));
|
||||
num5 += rowPitch + Tokens.Scale(8);
|
||||
_smoothWord.SetBounds(gutter - Ink(_smoothWord), num5, num - num3 - 8, num2);
|
||||
_smooth.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += rowPitch - Tokens.Scale(8);
|
||||
_edgesWord.SetBounds(gutter - Ink(_edgesWord), num5, num - num3 - 8, num2);
|
||||
_edges.SetBounds(gutter + num - num3, num5 + (num2 - num4) / 2, num3, num4);
|
||||
num5 += num2;
|
||||
_edgesHint.SetBounds(gutter - Ink(_edgesHint), num5, num, Tokens.Scale(20));
|
||||
num5 += Tokens.Scale(20) + Tokens.Scale(4);
|
||||
_status.SetBounds(gutter - Ink(_status), num5, num, Tokens.Scale(20));
|
||||
_fair.SetBounds(gutter - Ink(_fair), num5 + Tokens.Scale(20), num, FairHeight());
|
||||
}
|
||||
|
||||
private static int Ink(Label l)
|
||||
{
|
||||
return ControlInk.LabelInkInset(l.Font);
|
||||
}
|
||||
|
||||
public void Sync()
|
||||
{
|
||||
_syncing = true;
|
||||
try
|
||||
{
|
||||
bool flag = _allowed();
|
||||
_on.Checked = _settings.ZoomEnabled & flag;
|
||||
ToggleSwitch toggleSwitch = _on;
|
||||
HotkeyPicker key = _key;
|
||||
FlatSlider level = _level;
|
||||
ToggleSwitch smooth = _smooth;
|
||||
bool flag2 = (_edges.Enabled = flag);
|
||||
bool flag4 = (smooth.Enabled = flag2);
|
||||
bool flag6 = (level.Enabled = flag4);
|
||||
bool enabled = (key.Enabled = flag6);
|
||||
toggleSwitch.Enabled = enabled;
|
||||
_key.ModifierMask = _settings.ZoomHotkeyModifierMask;
|
||||
_key.VirtualKey = _settings.ZoomHotkeyVirtualKey;
|
||||
float num = ZoomMath.ClampSetting(_settings.ZoomLevel);
|
||||
_level.Value = (int)Math.Round(num / 0.25f);
|
||||
_levelValue.Text = num.ToString("0.0#", CultureInfo.InvariantCulture) + "x";
|
||||
_smooth.Checked = _settings.ZoomSmooth;
|
||||
_edges.Checked = _settings.ZoomSmoothEdges;
|
||||
_status.Text = StatusLine();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_syncing = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal string StatusLine()
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
return "Zoom comes with the Dark Boost & Zoom add-on.";
|
||||
}
|
||||
string text = _whyRefused();
|
||||
if (text.Length > 0)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
if (!_settings.ZoomEnabled)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (_settings.ZoomHotkeyVirtualKey == 0)
|
||||
{
|
||||
return "Pick a key to hold.";
|
||||
}
|
||||
string display = HotkeyPicker.GetDisplay(_settings.ZoomHotkeyModifierMask, _settings.ZoomHotkeyVirtualKey);
|
||||
HotkeySlot? hotkeySlot = HotkeyConflicts.Owner(_settings, HotkeySlot.Zoom, _settings.ZoomHotkeyModifierMask, _settings.ZoomHotkeyVirtualKey);
|
||||
if (hotkeySlot.HasValue)
|
||||
{
|
||||
HotkeySlot valueOrDefault = hotkeySlot.GetValueOrDefault();
|
||||
return display + " is taken by " + HotkeyConflicts.Describe(valueOrDefault) + ". Pick another key.";
|
||||
}
|
||||
return "Hold " + display + (_settings.HotkeysOnlyInGames ? " in a game to zoom." : " to zoom.");
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomEnabled = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void ChooseKey(uint mask, uint vk)
|
||||
{
|
||||
if (_syncing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
if (vk == 0 || _bindKey(mask, vk))
|
||||
{
|
||||
_settings.ZoomHotkeyModifierMask = ((vk != 0) ? mask : 0u);
|
||||
_settings.ZoomHotkeyVirtualKey = vk;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetLevel(float level)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomLevel = ZoomMath.ClampSetting(level);
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetSmooth(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomSmooth = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
|
||||
internal void SetSmoothEdges(bool on)
|
||||
{
|
||||
if (!_allowed())
|
||||
{
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
_settings.ZoomSmoothEdges = on;
|
||||
_save();
|
||||
Changed?.Invoke();
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud;
|
||||
|
||||
public static class CrashLog
|
||||
{
|
||||
public const int RetentionDays = 30;
|
||||
|
||||
public const int MaxRetainedLogs = 50;
|
||||
|
||||
private static readonly string CrashFileNamePrefix = "crash-";
|
||||
|
||||
private static readonly Regex[] RedactionPatterns = new Regex[5]
|
||||
{
|
||||
new Regex("[A-Z]:[\\\\/]Users[\\\\/][^\\\\\\/\\r\\n\\\"<>|*?]*[^\\\\\\/\\r\\n\\\"<>|*?\\s]", RegexOptions.Compiled),
|
||||
new Regex("\\b[A-Z]{4}-[A-Z]-[FTP]-[A-Z2-9]{8}-[A-Z2-9]{8}\\b", RegexOptions.Compiled),
|
||||
new Regex("\\b[A-Z2-9]{4}-[A-Z2-9]{4}-[A-Z2-9]{4}-[A-Z2-9]{4}\\b", RegexOptions.Compiled),
|
||||
new Regex("\\b[A-Z2-9]{16}\\b", RegexOptions.Compiled),
|
||||
new Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9\\-]+(?:\\.[A-Za-z0-9\\-]+)+", RegexOptions.Compiled)
|
||||
};
|
||||
|
||||
private static readonly string[] RedactionReplacements = new string[5] { "<user>", "<serial>", "<hw>", "<hw>", "<email>" };
|
||||
|
||||
internal static readonly string[] SensitiveFolderNames = new string[3] { "Steam\\steamapps", "Steam\\userdata", "Epic Games" };
|
||||
|
||||
internal static readonly string[] SensitiveFolderReplacements = new string[3] { "<steam-path>", "<steam-path>", "<epic-path>" };
|
||||
|
||||
public static string CrashDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
string text = DirectoryForTest ?? Path.Combine(AppFolders.Local, "crashes");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string? DirectoryForTest { get; set; }
|
||||
|
||||
public static string Write(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string crashDirectory = CrashDirectory;
|
||||
string text = CrashFileNamePrefix + DateTime.UtcNow.ToString("yyyy-MM-dd-HHmmss-fff");
|
||||
string value = BuildReport(ex);
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
string path = text + ((i == 0) ? "" : ("-" + i)) + ".txt";
|
||||
string text2 = Path.Combine(crashDirectory, path);
|
||||
FileStream fileStream;
|
||||
try
|
||||
{
|
||||
fileStream = new FileStream(text2, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
||||
}
|
||||
catch (IOException) when (File.Exists(text2))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
using (fileStream)
|
||||
{
|
||||
using StreamWriter streamWriter = new StreamWriter(fileStream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true));
|
||||
streamWriter.Write(value);
|
||||
}
|
||||
return text2;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Cleanup()
|
||||
{
|
||||
try
|
||||
{
|
||||
string crashDirectory = CrashDirectory;
|
||||
if (!Directory.Exists(crashDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
DateTime dateTime = DateTime.UtcNow.AddDays(-30.0);
|
||||
List<(string, DateTime)> list = (from x in Directory.EnumerateFiles(crashDirectory, CrashFileNamePrefix + "*.txt").Select((string p) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Path: p, Time: File.GetLastWriteTimeUtc(p));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return (Path: p, Time: DateTime.MinValue);
|
||||
}
|
||||
})
|
||||
orderby x.Time
|
||||
select x).ToList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (item.Item2 < dateTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(item.Item1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
List<(string, DateTime)> list2 = list.Where(((string Path, DateTime Time) f) => File.Exists(f.Path)).OrderByDescending(((string Path, DateTime Time) f) => f.Time).ToList();
|
||||
while (list2.Count > 50)
|
||||
{
|
||||
(string, DateTime) tuple = list2[list2.Count - 1];
|
||||
try
|
||||
{
|
||||
File.Delete(tuple.Item1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
list2.RemoveAt(list2.Count - 1);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildReport(Exception ex)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.AppendLine("PlexusX crash report");
|
||||
stringBuilder.AppendLine("Generated: " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + " UTC");
|
||||
stringBuilder.AppendLine("Version: " + SafeVersion());
|
||||
stringBuilder.AppendLine("OS: " + SafeOs());
|
||||
stringBuilder.AppendLine(".NET: " + SafeDotnet());
|
||||
stringBuilder.AppendLine("Build: " + SafeBuild());
|
||||
stringBuilder.AppendLine("Resources: " + SafeResources());
|
||||
stringBuilder.AppendLine();
|
||||
AppendException(stringBuilder, ex);
|
||||
return Redact(stringBuilder.ToString());
|
||||
}
|
||||
|
||||
private static void AppendException(StringBuilder sb, Exception ex, int depth = 0)
|
||||
{
|
||||
if (ex == null || depth > 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string text = new string(' ', depth * 2);
|
||||
sb.AppendLine(text + "Exception type: " + ex.GetType().FullName);
|
||||
sb.AppendLine(text + "Message: " + ex.Message);
|
||||
sb.AppendLine(text + "Stack trace:");
|
||||
sb.AppendLine(text + ex.StackTrace);
|
||||
if (ex is AggregateException ex2)
|
||||
{
|
||||
{
|
||||
foreach (Exception item in ex2.InnerExceptions.Take(5))
|
||||
{
|
||||
sb.AppendLine(text + "-- Inner exception --");
|
||||
AppendException(sb, item, depth + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
sb.AppendLine(text + "-- Inner exception --");
|
||||
AppendException(sb, ex.InnerException, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
return UpdateService.CurrentVersion.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeOs()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Environment.OSVersion.VersionString;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeDotnet()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Environment.Version.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeBuild()
|
||||
{
|
||||
try
|
||||
{
|
||||
return LoadedBuild.Sha256() ?? "unknown";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetGuiResources(nint hProcess, uint uiFlags);
|
||||
|
||||
private static string SafeResources()
|
||||
{
|
||||
try
|
||||
{
|
||||
using Process process = Process.GetCurrentProcess();
|
||||
return string.Format(CultureInfo.InvariantCulture, "gdi={0} user={1} handles={2} private_mb={3} uptime_min={4:0}", GetGuiResources(process.Handle, 0u), GetGuiResources(process.Handle, 1u), process.HandleCount, process.PrivateMemorySize64 / 1048576, (DateTime.Now - process.StartTime).TotalMinutes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
internal static string Redact(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return input ?? "";
|
||||
}
|
||||
string input2 = input;
|
||||
for (int i = 0; i < RedactionPatterns.Length; i++)
|
||||
{
|
||||
input2 = RedactionPatterns[i].Replace(input2, RedactionReplacements[i]);
|
||||
}
|
||||
return RedactBySubstring(input2);
|
||||
}
|
||||
|
||||
internal static string RedactBySubstring(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return input ?? "";
|
||||
}
|
||||
string text = input;
|
||||
for (int i = 0; i < SensitiveFolderNames.Length; i++)
|
||||
{
|
||||
text = text.Replace(SensitiveFolderNames[i], SensitiveFolderReplacements[i]);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed record AngledBar(RectangleF Rect, float Degrees);
|
||||
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairCode
|
||||
{
|
||||
private const string Prefix = "PXC-";
|
||||
|
||||
private const string Alphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ#";
|
||||
|
||||
private const int ShortValueCount = 10;
|
||||
|
||||
private const int LongValueCount = 13;
|
||||
|
||||
private const int LongestValueCount = 18;
|
||||
|
||||
private const int ShortBodyLength = 21;
|
||||
|
||||
private const int LongBodyLength = 27;
|
||||
|
||||
private const int LongestBodyLength = 37;
|
||||
|
||||
private const int ArmTop = 1;
|
||||
|
||||
private const int ArmBottom = 2;
|
||||
|
||||
private const int ArmLeft = 4;
|
||||
|
||||
private const int ArmRight = 8;
|
||||
|
||||
private const int Circle = 16;
|
||||
|
||||
private const int Dot = 32;
|
||||
|
||||
private const int Outline = 64;
|
||||
|
||||
private const int DiagonalArms = 128;
|
||||
|
||||
private const int ChevronArms = 256;
|
||||
|
||||
private const int OffsetBias = 200;
|
||||
|
||||
public static string Encode(CrosshairConfig c)
|
||||
{
|
||||
int resolvedRotationDegrees = c.ResolvedRotationDegrees;
|
||||
int num = 0;
|
||||
if (c.ResolvedArmTop)
|
||||
{
|
||||
num |= 1;
|
||||
}
|
||||
if (c.ResolvedArmBottom)
|
||||
{
|
||||
num |= 2;
|
||||
}
|
||||
if (c.ResolvedArmLeft)
|
||||
{
|
||||
num |= 4;
|
||||
}
|
||||
if (c.ResolvedArmRight)
|
||||
{
|
||||
num |= 8;
|
||||
}
|
||||
if (c.ResolvedShowCircle)
|
||||
{
|
||||
num |= 0x10;
|
||||
}
|
||||
if (c.ResolvedCentreDot)
|
||||
{
|
||||
num |= 0x20;
|
||||
}
|
||||
if (c.Outline)
|
||||
{
|
||||
num |= 0x40;
|
||||
}
|
||||
if (resolvedRotationDegrees == 45)
|
||||
{
|
||||
num |= 0x80;
|
||||
}
|
||||
if (c.Chevron)
|
||||
{
|
||||
num |= 0x100;
|
||||
}
|
||||
int colourArgb = c.ColourArgb;
|
||||
int num2 = c.OutlineThicknessTenths ?? 10;
|
||||
int resolvedOffsetX = c.ResolvedOffsetX;
|
||||
int resolvedOffsetY = c.ResolvedOffsetY;
|
||||
int resolvedDotOpacity = c.ResolvedDotOpacity;
|
||||
int num3 = c.ResolvedOutlineColourArgb & 0xFFFFFF;
|
||||
bool flag = c.Chevron || (resolvedRotationDegrees != 0 && resolvedRotationDegrees != 45) || resolvedDotOpacity != 100 || num3 != 0;
|
||||
bool flag2 = flag || resolvedRotationDegrees == 45 || num2 != 10 || resolvedOffsetX != 0 || resolvedOffsetY != 0;
|
||||
int[] array = new int[18]
|
||||
{
|
||||
num,
|
||||
Tenths(c.ResolvedSize),
|
||||
Tenths(c.ResolvedThickness),
|
||||
Tenths(c.ResolvedGap),
|
||||
Tenths(c.ResolvedDotSize),
|
||||
Tenths(c.ResolvedCircleRadius),
|
||||
Math.Clamp(c.Opacity, 0, 100),
|
||||
(colourArgb >> 16) & 0xFF,
|
||||
(colourArgb >> 8) & 0xFF,
|
||||
colourArgb & 0xFF,
|
||||
Math.Clamp(num2, 0, 40),
|
||||
resolvedOffsetX + 200,
|
||||
resolvedOffsetY + 200,
|
||||
resolvedRotationDegrees,
|
||||
resolvedDotOpacity,
|
||||
(num3 >> 16) & 0xFF,
|
||||
(num3 >> 8) & 0xFF,
|
||||
num3 & 0xFF
|
||||
};
|
||||
int num4;
|
||||
if (flag)
|
||||
{
|
||||
num4 = 18;
|
||||
}
|
||||
else
|
||||
{
|
||||
num4 = (flag2 ? 13 : 10);
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(num4 * 2 + 1);
|
||||
int[] subArray = array[..num4];
|
||||
for (int i = 0; i < subArray.Length; i++)
|
||||
{
|
||||
int num5 = Math.Clamp(subArray[i], 0, 1023);
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[num5 / 32]);
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[num5 % 32]);
|
||||
}
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[Checksum(stringBuilder.ToString())]);
|
||||
return "PXC-" + stringBuilder;
|
||||
}
|
||||
|
||||
public static bool TryDecode(string? code, out CrosshairConfig crosshair)
|
||||
{
|
||||
crosshair = new CrosshairConfig();
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = ShareCodeText.Normalize(code).Trim().ToUpperInvariant();
|
||||
if (!text.StartsWith("PXC-", StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text2 = text.Substring("PXC-".Length);
|
||||
int num = text2.Length switch
|
||||
{
|
||||
21 => 10,
|
||||
27 => 13,
|
||||
37 => 18,
|
||||
_ => 0,
|
||||
};
|
||||
if (num == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int[] array = new int[text2.Length];
|
||||
for (int i = 0; i < text2.Length; i++)
|
||||
{
|
||||
array[i] = "23456789ABCDEFGHJKMNPQRSTUVWXYZ#".IndexOf(text2[i]);
|
||||
if (array[i] < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (array[num * 2] != Checksum(text2.Substring(0, num * 2)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int[] array2 = new int[num];
|
||||
for (int j = 0; j < num; j++)
|
||||
{
|
||||
array2[j] = array[j * 2] * 32 + array[j * 2 + 1];
|
||||
}
|
||||
int num2 = array2[0];
|
||||
crosshair = new CrosshairConfig
|
||||
{
|
||||
ArmTop = ((num2 & 1) != 0),
|
||||
ArmBottom = ((num2 & 2) != 0),
|
||||
ArmLeft = ((num2 & 4) != 0),
|
||||
ArmRight = ((num2 & 8) != 0),
|
||||
ShowCircle = ((num2 & 0x10) != 0),
|
||||
CentreDot = ((num2 & 0x20) != 0),
|
||||
Outline = ((num2 & 0x40) != 0),
|
||||
Diagonal = ((num2 & 0x80) != 0),
|
||||
Opacity = Math.Clamp(array2[6], 10, 100),
|
||||
ColourArgb = (-16777216 | ((array2[7] & 0xFF) << 16) | ((array2[8] & 0xFF) << 8) | (array2[9] & 0xFF))
|
||||
};
|
||||
crosshair.SetSizeTenths(Math.Clamp(array2[1], 5, 300));
|
||||
crosshair.SetThicknessTenths(Math.Clamp(array2[2], 5, 100));
|
||||
crosshair.SetGapTenths(Math.Clamp(array2[3], 0, 300));
|
||||
crosshair.DotSizeTenths = Math.Clamp(array2[4], 5, 100);
|
||||
crosshair.CircleRadiusTenths = Math.Clamp(array2[5], 10, 400);
|
||||
if (num >= 13)
|
||||
{
|
||||
crosshair.OutlineThicknessTenths = Math.Clamp(array2[10], 0, 40);
|
||||
crosshair.OffsetXPx = Math.Clamp(array2[11] - 200, -200, 200);
|
||||
crosshair.OffsetYPx = Math.Clamp(array2[12] - 200, -200, 200);
|
||||
}
|
||||
if (num == 18)
|
||||
{
|
||||
crosshair.Chevron = (num2 & 0x100) != 0;
|
||||
crosshair.SetRotationDegrees(Math.Clamp(array2[13], 0, 90));
|
||||
crosshair.DotOpacity = Math.Clamp(array2[14], 10, 100);
|
||||
crosshair.OutlineColourRgb = ((array2[15] & 0xFF) << 16) | ((array2[16] & 0xFF) << 8) | (array2[17] & 0xFF);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int Tenths(float value)
|
||||
{
|
||||
return Math.Clamp((int)Math.Round(value * 10f), 0, 1023);
|
||||
}
|
||||
|
||||
private static int Checksum(string body)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; i < body.Length; i++)
|
||||
{
|
||||
num += ("23456789ABCDEFGHJKMNPQRSTUVWXYZ#".IndexOf(body[i]) + 1) * (2 * i + 1);
|
||||
}
|
||||
return num % 32;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed class CrosshairConfig
|
||||
{
|
||||
public const int MaxOffsetPx = 200;
|
||||
|
||||
public string Name { get; set; } = "New crosshair";
|
||||
|
||||
public CrosshairShape Shape { get; set; }
|
||||
|
||||
public bool? ArmTop { get; set; }
|
||||
|
||||
public bool? ArmBottom { get; set; }
|
||||
|
||||
public bool? ArmLeft { get; set; }
|
||||
|
||||
public bool? ArmRight { get; set; }
|
||||
|
||||
public bool? ShowCircle { get; set; }
|
||||
|
||||
public bool Diagonal { get; set; }
|
||||
|
||||
public int? DotSizeTenths { get; set; }
|
||||
|
||||
public int? CircleRadiusTenths { get; set; }
|
||||
|
||||
public int Opacity { get; set; } = 100;
|
||||
|
||||
private bool LegacyHasArms
|
||||
{
|
||||
get
|
||||
{
|
||||
CrosshairShape shape = Shape;
|
||||
if (shape == CrosshairShape.Cross || shape == CrosshairShape.T)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ResolvedArmTop => ArmFrom(ArmTop, Shape == CrosshairShape.Cross);
|
||||
|
||||
public bool ResolvedArmBottom => ArmFrom(ArmBottom, LegacyHasArms);
|
||||
|
||||
public bool ResolvedArmLeft => ArmFrom(ArmLeft, LegacyHasArms);
|
||||
|
||||
public bool ResolvedArmRight => ArmFrom(ArmRight, LegacyHasArms);
|
||||
|
||||
public bool ResolvedShowCircle => ShowCircle ?? (Shape == CrosshairShape.Circle);
|
||||
|
||||
public bool ResolvedCentreDot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!CentreDot)
|
||||
{
|
||||
return Shape == CrosshairShape.Dot;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public float ResolvedDotSize => (float)(DotSizeTenths ?? ((int)Math.Round(ResolvedThickness * 10f))) / 10f;
|
||||
|
||||
public float ResolvedCircleRadius => (float)(CircleRadiusTenths ?? ((int)Math.Round((ResolvedGap + ResolvedSize) * 10f))) / 10f;
|
||||
|
||||
public int ResolvedColourArgb
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = (byte)((ColourArgb >> 24) & 0xFF) * Math.Clamp(Opacity, 0, 100) / 100;
|
||||
return (ColourArgb & 0xFFFFFF) | (num << 24);
|
||||
}
|
||||
}
|
||||
|
||||
public int ColourArgb { get; set; } = -16711834;
|
||||
|
||||
public int Size { get; set; } = 8;
|
||||
|
||||
public int Thickness { get; set; } = 2;
|
||||
|
||||
public int Gap { get; set; } = 4;
|
||||
|
||||
public int? SizeTenths { get; set; }
|
||||
|
||||
public int? ThicknessTenths { get; set; }
|
||||
|
||||
public int? GapTenths { get; set; }
|
||||
|
||||
public float ResolvedSize => (float)(SizeTenths ?? (Size * 10)) / 10f;
|
||||
|
||||
public float ResolvedThickness => (float)(ThicknessTenths ?? (Thickness * 10)) / 10f;
|
||||
|
||||
public float ResolvedGap => (float)(GapTenths ?? (Gap * 10)) / 10f;
|
||||
|
||||
public bool Outline { get; set; } = true;
|
||||
|
||||
public int? OutlineThicknessTenths { get; set; }
|
||||
|
||||
public float ResolvedOutlineThickness
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Outline)
|
||||
{
|
||||
return (float)(OutlineThicknessTenths ?? 10) / 10f;
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public int? OffsetXPx { get; set; }
|
||||
|
||||
public int? OffsetYPx { get; set; }
|
||||
|
||||
public int ResolvedOffsetX => Clamp(OffsetXPx);
|
||||
|
||||
public int ResolvedOffsetY => Clamp(OffsetYPx);
|
||||
|
||||
public bool CentreDot { get; set; }
|
||||
|
||||
public bool Chevron { get; set; }
|
||||
|
||||
public int? RotationDegrees { get; set; }
|
||||
|
||||
public int ResolvedRotationDegrees => Math.Clamp(RotationDegrees ?? (Diagonal ? 45 : 0), 0, 90);
|
||||
|
||||
public int? DotOpacity { get; set; }
|
||||
|
||||
public int ResolvedDotOpacity => Math.Clamp(DotOpacity ?? 100, 10, 100);
|
||||
|
||||
public int ResolvedDotColourArgb
|
||||
{
|
||||
get
|
||||
{
|
||||
int resolvedColourArgb = ResolvedColourArgb;
|
||||
int num = ((resolvedColourArgb >> 24) & 0xFF) * ResolvedDotOpacity / 100;
|
||||
return (resolvedColourArgb & 0xFFFFFF) | (num << 24);
|
||||
}
|
||||
}
|
||||
|
||||
public int? OutlineColourRgb { get; set; }
|
||||
|
||||
public int ResolvedOutlineColourArgb => -1107296256 | (OutlineColourRgb.GetValueOrDefault() & 0xFFFFFF);
|
||||
|
||||
public string? ImagePath { get; set; }
|
||||
|
||||
public int ImageScalePercent { get; set; } = 100;
|
||||
|
||||
public bool UsesImage => ImageCrosshair.Load(ImagePath) != null;
|
||||
|
||||
private bool ArmFrom(bool? saved, bool legacyDefault)
|
||||
{
|
||||
return saved ?? legacyDefault;
|
||||
}
|
||||
|
||||
public void SetSizeTenths(int tenths)
|
||||
{
|
||||
SizeTenths = tenths;
|
||||
Size = LegacyPixels(tenths, 1);
|
||||
}
|
||||
|
||||
public void SetThicknessTenths(int tenths)
|
||||
{
|
||||
ThicknessTenths = tenths;
|
||||
Thickness = LegacyPixels(tenths, 1);
|
||||
}
|
||||
|
||||
public void SetGapTenths(int tenths)
|
||||
{
|
||||
GapTenths = tenths;
|
||||
Gap = LegacyPixels(tenths, 0);
|
||||
}
|
||||
|
||||
private static int LegacyPixels(int tenths, int floor)
|
||||
{
|
||||
return Math.Max(floor, (int)Math.Round((double)tenths / 10.0, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
private static int Clamp(int? value)
|
||||
{
|
||||
return Math.Clamp(value.GetValueOrDefault(), -200, 200);
|
||||
}
|
||||
|
||||
public void SetRotationDegrees(int degrees)
|
||||
{
|
||||
int num = Math.Clamp(degrees, 0, 90);
|
||||
RotationDegrees = num;
|
||||
Diagonal = num > 22 && num < 68;
|
||||
}
|
||||
|
||||
public CrosshairConfig Clone()
|
||||
{
|
||||
return (CrosshairConfig)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairGallery
|
||||
{
|
||||
public enum Family
|
||||
{
|
||||
Dot,
|
||||
X,
|
||||
Ring,
|
||||
Cross,
|
||||
Funny
|
||||
}
|
||||
|
||||
public sealed record GalleryItem(string Id, string Name, Family Group, CrosshairConfig Config);
|
||||
|
||||
public static IReadOnlyList<GalleryItem> All => ServedCrosshairs.Designs;
|
||||
|
||||
public static void Apply(CrosshairConfig target, GalleryItem item)
|
||||
{
|
||||
CrosshairConfig config = item.Config;
|
||||
target.ArmTop = config.ResolvedArmTop;
|
||||
target.ArmBottom = config.ResolvedArmBottom;
|
||||
target.ArmLeft = config.ResolvedArmLeft;
|
||||
target.ArmRight = config.ResolvedArmRight;
|
||||
target.CentreDot = config.ResolvedCentreDot;
|
||||
target.DotSizeTenths = config.DotSizeTenths;
|
||||
target.ShowCircle = config.ResolvedShowCircle;
|
||||
target.CircleRadiusTenths = config.CircleRadiusTenths;
|
||||
target.Diagonal = config.Diagonal;
|
||||
target.RotationDegrees = config.RotationDegrees;
|
||||
target.Chevron = config.Chevron;
|
||||
target.SetSizeTenths(config.SizeTenths ?? 80);
|
||||
target.SetThicknessTenths(config.ThicknessTenths ?? 20);
|
||||
target.SetGapTenths(config.GapTenths ?? 40);
|
||||
bool flag = !config.ResolvedArmTop && !config.ResolvedArmBottom && !config.ResolvedArmLeft && !config.ResolvedArmRight;
|
||||
target.Shape = ((config.ResolvedShowCircle && !config.ResolvedArmLeft) ? CrosshairShape.Circle : (flag ? CrosshairShape.Dot : ((!config.ResolvedArmTop) ? CrosshairShape.T : CrosshairShape.Cross)));
|
||||
}
|
||||
|
||||
public static GalleryItem? Matching(CrosshairConfig c)
|
||||
{
|
||||
return All.FirstOrDefault((GalleryItem item) => item.Config.ResolvedArmTop == c.ResolvedArmTop && item.Config.ResolvedArmBottom == c.ResolvedArmBottom && item.Config.ResolvedArmLeft == c.ResolvedArmLeft && item.Config.ResolvedArmRight == c.ResolvedArmRight && item.Config.ResolvedCentreDot == c.ResolvedCentreDot && item.Config.ResolvedShowCircle == c.ResolvedShowCircle && item.Config.ResolvedRotationDegrees == c.ResolvedRotationDegrees && item.Config.Chevron == c.Chevron && Near(item.Config.ResolvedSize, c.ResolvedSize) && Near(item.Config.ResolvedThickness, c.ResolvedThickness) && Near(item.Config.ResolvedGap, c.ResolvedGap) && (!c.ResolvedCentreDot || Near(item.Config.ResolvedDotSize, c.ResolvedDotSize)) && (!c.ResolvedShowCircle || Near(item.Config.ResolvedCircleRadius, c.ResolvedCircleRadius)));
|
||||
}
|
||||
|
||||
private static bool Near(float a, float b)
|
||||
{
|
||||
return Math.Abs(a - b) < 0.05f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairGeometry
|
||||
{
|
||||
public const float ChevronDegrees = 45f;
|
||||
|
||||
private const float AntiAliasMargin = 1f;
|
||||
|
||||
public static CrosshairShapes Build(CrosshairConfig c)
|
||||
{
|
||||
float num = Math.Max(0.5f, c.ResolvedThickness);
|
||||
float num2 = Math.Max(0.5f, c.ResolvedSize);
|
||||
float num3 = Math.Max(0f, c.ResolvedGap);
|
||||
float num4 = num / 2f;
|
||||
List<RectangleF> list = new List<RectangleF>();
|
||||
List<AngledBar> list2 = new List<AngledBar>();
|
||||
RectangleF? circle = null;
|
||||
RectangleF rectangleF = new RectangleF(0f - (num3 + num2), 0f - num4, num2, num);
|
||||
RectangleF rectangleF2 = new RectangleF(num3, 0f - num4, num2, num);
|
||||
if (c.ResolvedArmLeft)
|
||||
{
|
||||
if (c.Chevron)
|
||||
{
|
||||
list2.Add(new AngledBar(rectangleF, -45f));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(rectangleF);
|
||||
}
|
||||
}
|
||||
if (c.ResolvedArmRight)
|
||||
{
|
||||
if (c.Chevron)
|
||||
{
|
||||
list2.Add(new AngledBar(rectangleF2, 45f));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(rectangleF2);
|
||||
}
|
||||
}
|
||||
if (c.ResolvedArmBottom)
|
||||
{
|
||||
list.Add(new RectangleF(0f - num4, num3, num, num2));
|
||||
}
|
||||
if (c.ResolvedArmTop)
|
||||
{
|
||||
list.Add(new RectangleF(0f - num4, 0f - (num3 + num2), num, num2));
|
||||
}
|
||||
if (c.Chevron && c.ResolvedArmLeft && c.ResolvedArmRight && num3 <= 0f)
|
||||
{
|
||||
list2.Add(new AngledBar(new RectangleF(0f - num4, 0f - num4, num, num), 45f));
|
||||
}
|
||||
if (c.ResolvedShowCircle)
|
||||
{
|
||||
float num5 = Math.Max(0.5f, c.ResolvedCircleRadius);
|
||||
circle = new RectangleF(0f - num5, 0f - num5, num5 * 2f, num5 * 2f);
|
||||
}
|
||||
int dotIndex = -1;
|
||||
if (c.ResolvedCentreDot)
|
||||
{
|
||||
float num6 = Math.Max(0.5f, c.ResolvedDotSize);
|
||||
list.Add(new RectangleF((0f - num6) / 2f, (0f - num6) / 2f, num6, num6));
|
||||
dotIndex = list.Count - 1;
|
||||
}
|
||||
int resolvedOffsetX = c.ResolvedOffsetX;
|
||||
int resolvedOffsetY = c.ResolvedOffsetY;
|
||||
if (resolvedOffsetX != 0 || resolvedOffsetY != 0)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
list[i] = Offset(list[i], resolvedOffsetX, resolvedOffsetY);
|
||||
}
|
||||
for (int j = 0; j < list2.Count; j++)
|
||||
{
|
||||
list2[j] = list2[j] with
|
||||
{
|
||||
Rect = Offset(list2[j].Rect, resolvedOffsetX, resolvedOffsetY)
|
||||
};
|
||||
}
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
circle = Offset(valueOrDefault, resolvedOffsetX, resolvedOffsetY);
|
||||
}
|
||||
}
|
||||
PointF pivot = new PointF(resolvedOffsetX, resolvedOffsetY);
|
||||
float num7 = c.ResolvedRotationDegrees;
|
||||
return new CrosshairShapes(list, circle, Bounds(list, circle, list2, pivot, 0f, 0f))
|
||||
{
|
||||
Angled = list2,
|
||||
DotIndex = dotIndex,
|
||||
RotationDegrees = num7,
|
||||
Pivot = pivot,
|
||||
DrawnBounds = Bounds(list, circle, list2, pivot, num7, 0f)
|
||||
};
|
||||
}
|
||||
|
||||
public static Size OverlaySize(CrosshairConfig c)
|
||||
{
|
||||
Bitmap bitmap = ImageCrosshair.Load(c.ImagePath);
|
||||
if (bitmap != null)
|
||||
{
|
||||
float num = (float)Math.Max(1, c.ImageScalePercent) / 100f;
|
||||
float num2 = (float)bitmap.Width * num + (float)(Math.Abs(c.ResolvedOffsetX) * 2);
|
||||
float num3 = (float)bitmap.Height * num + (float)(Math.Abs(c.ResolvedOffsetY) * 2);
|
||||
float num4 = c.ResolvedOutlineThickness * 2f + 4f;
|
||||
return new Size(Math.Max(8, (int)Math.Ceiling(num2 + num4)), Math.Max(8, (int)Math.Ceiling(num3 + num4)));
|
||||
}
|
||||
CrosshairShapes crosshairShapes = Build(c);
|
||||
float num5 = crosshairShapes.Bounds.Width;
|
||||
float num6 = crosshairShapes.Bounds.Height;
|
||||
if (c.Diagonal)
|
||||
{
|
||||
num5 *= 1.4142f;
|
||||
num6 *= 1.4142f;
|
||||
}
|
||||
num5 += (float)(Math.Abs(c.ResolvedOffsetX) * 2);
|
||||
num6 += (float)(Math.Abs(c.ResolvedOffsetY) * 2);
|
||||
float num7 = c.ResolvedOutlineThickness * 2f + 4f;
|
||||
int val = (int)Math.Ceiling(num5 + num7);
|
||||
int val2 = (int)Math.Ceiling(num6 + num7);
|
||||
float resolvedOutlineThickness = c.ResolvedOutlineThickness;
|
||||
float ringGrow = ((!crosshairShapes.Circle.HasValue) ? 0f : (Math.Max(0.5f, c.ResolvedThickness) / 2f + resolvedOutlineThickness));
|
||||
RectangleF rectangleF = Bounds(crosshairShapes.Bars, crosshairShapes.Circle, crosshairShapes.Angled, crosshairShapes.Pivot, crosshairShapes.RotationDegrees, resolvedOutlineThickness, ringGrow);
|
||||
float num8 = Math.Max(Math.Abs(rectangleF.Left), Math.Abs(rectangleF.Right)) + 1f;
|
||||
float num9 = Math.Max(Math.Abs(rectangleF.Top), Math.Abs(rectangleF.Bottom)) + 1f;
|
||||
return new Size(Math.Max(8, Math.Max(val, (int)Math.Ceiling(num8 * 2f))), Math.Max(8, Math.Max(val2, (int)Math.Ceiling(num9 * 2f))));
|
||||
}
|
||||
|
||||
private static RectangleF Offset(RectangleF r, float dx, float dy)
|
||||
{
|
||||
return new RectangleF(r.X + dx, r.Y + dy, r.Width, r.Height);
|
||||
}
|
||||
|
||||
private static RectangleF Bounds(IReadOnlyList<RectangleF> bars, RectangleF? circle, IReadOnlyList<AngledBar> angled, PointF pivot, float rotation, float grow, float ringGrow = 0f)
|
||||
{
|
||||
if (bars.Count == 0 && !circle.HasValue && angled.Count == 0)
|
||||
{
|
||||
return RectangleF.Empty;
|
||||
}
|
||||
float minX = float.MaxValue;
|
||||
float minY = float.MaxValue;
|
||||
float maxX = float.MinValue;
|
||||
float maxY = float.MinValue;
|
||||
foreach (RectangleF bar in bars)
|
||||
{
|
||||
Take(bar, rotation);
|
||||
}
|
||||
foreach (AngledBar item3 in angled)
|
||||
{
|
||||
Take(item3.Rect, rotation + item3.Degrees);
|
||||
}
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
RectangleF rectangleF = ((ringGrow > 0f) ? RectangleF.Inflate(valueOrDefault, ringGrow, ringGrow) : valueOrDefault);
|
||||
TakePoint(rectangleF.Left, rectangleF.Top);
|
||||
TakePoint(rectangleF.Right, rectangleF.Bottom);
|
||||
}
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
void Take(RectangleF r, float degrees)
|
||||
{
|
||||
RectangleF rectangleF2 = ((grow > 0f) ? RectangleF.Inflate(r, grow, grow) : r);
|
||||
if (degrees == 0f)
|
||||
{
|
||||
TakePoint(rectangleF2.Left, rectangleF2.Top);
|
||||
TakePoint(rectangleF2.Right, rectangleF2.Bottom);
|
||||
}
|
||||
else
|
||||
{
|
||||
double num = (double)degrees * Math.PI / 180.0;
|
||||
double num2 = Math.Cos(num);
|
||||
double num3 = Math.Sin(num);
|
||||
(float, float)[] array = new (float, float)[4]
|
||||
{
|
||||
(rectangleF2.Left, rectangleF2.Top),
|
||||
(rectangleF2.Right, rectangleF2.Top),
|
||||
(rectangleF2.Right, rectangleF2.Bottom),
|
||||
(rectangleF2.Left, rectangleF2.Bottom)
|
||||
};
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
(float, float) tuple = array[i];
|
||||
float item = tuple.Item1;
|
||||
float item2 = tuple.Item2;
|
||||
double num4 = item - pivot.X;
|
||||
double num5 = item2 - pivot.Y;
|
||||
TakePoint((float)((double)pivot.X + num4 * num2 - num5 * num3), (float)((double)pivot.Y + num4 * num3 + num5 * num2));
|
||||
}
|
||||
}
|
||||
}
|
||||
void TakePoint(float x, float y)
|
||||
{
|
||||
minX = Math.Min(minX, x);
|
||||
minY = Math.Min(minY, y);
|
||||
maxX = Math.Max(maxX, x);
|
||||
maxY = Math.Max(maxY, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairLimits
|
||||
{
|
||||
public const int MinSizeTenths = 5;
|
||||
|
||||
public const int MaxSizeTenths = 300;
|
||||
|
||||
public const int DefaultSizeTenths = 80;
|
||||
|
||||
public const int MinThicknessTenths = 5;
|
||||
|
||||
public const int MaxThicknessTenths = 100;
|
||||
|
||||
public const int DefaultThicknessTenths = 20;
|
||||
|
||||
public const int MinGapTenths = 0;
|
||||
|
||||
public const int MaxGapTenths = 300;
|
||||
|
||||
public const int DefaultGapTenths = 40;
|
||||
|
||||
public const int MinDotTenths = 5;
|
||||
|
||||
public const int MaxDotTenths = 100;
|
||||
|
||||
public const int MinRingTenths = 10;
|
||||
|
||||
public const int MaxRingTenths = 400;
|
||||
|
||||
public const int MinOpacity = 10;
|
||||
|
||||
public const int MaxOpacity = 100;
|
||||
|
||||
public const int DefaultOpacity = 100;
|
||||
|
||||
public const int MinOutlineTenths = 0;
|
||||
|
||||
public const int MaxOutlineTenths = 40;
|
||||
|
||||
public const int DefaultOutlineTenths = 10;
|
||||
|
||||
public const int MinImageScale = 25;
|
||||
|
||||
public const int MaxImageScale = 400;
|
||||
|
||||
public const int MinRotationDegrees = 0;
|
||||
|
||||
public const int MaxRotationDegrees = 90;
|
||||
|
||||
public const int DefaultRotationDegrees = 0;
|
||||
|
||||
public const int MinDotOpacity = 10;
|
||||
|
||||
public const int MaxDotOpacity = 100;
|
||||
|
||||
public const int DefaultDotOpacity = 100;
|
||||
|
||||
public const int DefaultOutlineColourRgb = 0;
|
||||
|
||||
public const int OutlineAlpha = 190;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairPresets
|
||||
{
|
||||
public const int White = -1;
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairRender
|
||||
{
|
||||
private static readonly int ClassicOutlineArgb = -1107296256;
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config)
|
||||
{
|
||||
Bitmap bitmap = ImageCrosshair.Load(config.ImagePath);
|
||||
if (bitmap != null)
|
||||
{
|
||||
DrawImage(g, config, bitmap);
|
||||
return;
|
||||
}
|
||||
CrosshairShapes shapes = CrosshairGeometry.Build(config);
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Color color = Color.FromArgb(config.ResolvedColourArgb);
|
||||
SolidBrush fill = new SolidBrush(color);
|
||||
try
|
||||
{
|
||||
int resolvedOutlineColourArgb = config.ResolvedOutlineColourArgb;
|
||||
Color color2 = Color.FromArgb(resolvedOutlineColourArgb);
|
||||
SolidBrush halo = new SolidBrush(color2);
|
||||
try
|
||||
{
|
||||
bool hasDot = shapes.DotIndex >= 0;
|
||||
bool fadedDot = hasDot && config.ResolvedDotOpacity < 100;
|
||||
SolidBrush dotFill = new SolidBrush(Color.FromArgb(config.ResolvedDotColourArgb));
|
||||
try
|
||||
{
|
||||
SolidBrush dotHalo = new SolidBrush(Color.FromArgb(color2.A * config.ResolvedDotOpacity / 100, color2.R, color2.G, color2.B));
|
||||
try
|
||||
{
|
||||
float outline = config.ResolvedOutlineThickness;
|
||||
float num = Math.Max(0.5f, config.ResolvedThickness);
|
||||
if (outline > 0f)
|
||||
{
|
||||
bool oneShape = resolvedOutlineColourArgb != ClassicOutlineArgb || shapes.Angled.Count > 0;
|
||||
GraphicsPath armsOutline = ((oneShape | fadedDot) ? Arms(shapes, outline, oneShape && !fadedDot) : null);
|
||||
try
|
||||
{
|
||||
Turned(g, shapes.Pivot, shapes.RotationDegrees, () =>
|
||||
{
|
||||
if (oneShape)
|
||||
{
|
||||
g.FillPath(halo, armsOutline);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < shapes.Bars.Count; i++)
|
||||
{
|
||||
if (i != shapes.DotIndex)
|
||||
{
|
||||
g.FillRectangle(halo, RectangleF.Inflate(shapes.Bars[i], outline, outline));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasDot)
|
||||
{
|
||||
RectangleF rect = RectangleF.Inflate(shapes.Bars[shapes.DotIndex], outline, outline);
|
||||
if (fadedDot)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
g.SetClip(armsOutline, CombineMode.Exclude);
|
||||
g.FillRectangle(dotHalo, rect);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
else if (!oneShape)
|
||||
{
|
||||
g.FillRectangle(halo, rect);
|
||||
}
|
||||
}
|
||||
});
|
||||
RectangleF? circle = shapes.Circle;
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
using Pen pen = new Pen(color2, num + outline * 2f);
|
||||
g.DrawEllipse(pen, valueOrDefault);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (armsOutline != null)
|
||||
{
|
||||
((IDisposable)armsOutline).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
GraphicsPath armsFill = Arms(shapes, 0f, withDot: false);
|
||||
try
|
||||
{
|
||||
Turned(g, shapes.Pivot, shapes.RotationDegrees, () =>
|
||||
{
|
||||
g.FillPath(fill, armsFill);
|
||||
if (hasDot)
|
||||
{
|
||||
g.FillRectangle(dotFill, shapes.Bars[shapes.DotIndex]);
|
||||
}
|
||||
});
|
||||
RectangleF? circle = shapes.Circle;
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault2 = circle.GetValueOrDefault();
|
||||
using Pen pen2 = new Pen(color, num);
|
||||
g.DrawEllipse(pen2, valueOrDefault2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (armsFill != null)
|
||||
{
|
||||
((IDisposable)armsFill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dotHalo != null)
|
||||
{
|
||||
((IDisposable)dotHalo).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dotFill != null)
|
||||
{
|
||||
((IDisposable)dotFill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (halo != null)
|
||||
{
|
||||
((IDisposable)halo).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fill != null)
|
||||
{
|
||||
((IDisposable)fill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static GraphicsPath Arms(CrosshairShapes shapes, float grow, bool withDot)
|
||||
{
|
||||
GraphicsPath graphicsPath = new GraphicsPath(FillMode.Winding);
|
||||
for (int i = 0; i < shapes.Bars.Count; i++)
|
||||
{
|
||||
if (i != shapes.DotIndex || withDot)
|
||||
{
|
||||
graphicsPath.AddRectangle((grow > 0f) ? RectangleF.Inflate(shapes.Bars[i], grow, grow) : shapes.Bars[i]);
|
||||
}
|
||||
}
|
||||
foreach (AngledBar item in shapes.Angled)
|
||||
{
|
||||
using GraphicsPath graphicsPath2 = new GraphicsPath(FillMode.Winding);
|
||||
graphicsPath2.AddRectangle((grow > 0f) ? RectangleF.Inflate(item.Rect, grow, grow) : item.Rect);
|
||||
using Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(item.Degrees, shapes.Pivot);
|
||||
graphicsPath2.Transform(matrix);
|
||||
graphicsPath.AddPath(graphicsPath2, connect: false);
|
||||
}
|
||||
return graphicsPath;
|
||||
}
|
||||
|
||||
private static void Turned(Graphics g, PointF pivot, float degrees, Action draw)
|
||||
{
|
||||
if (degrees == 0f)
|
||||
{
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
int num;
|
||||
if (pivot.X == 0f)
|
||||
{
|
||||
num = ((pivot.Y != 0f) ? 1 : 0);
|
||||
if (num == 0)
|
||||
{
|
||||
goto IL_004f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num = 1;
|
||||
}
|
||||
g.TranslateTransform(pivot.X, pivot.Y);
|
||||
goto IL_004f;
|
||||
IL_004f:
|
||||
g.RotateTransform(degrees);
|
||||
if (num != 0)
|
||||
{
|
||||
g.TranslateTransform(0f - pivot.X, 0f - pivot.Y);
|
||||
}
|
||||
draw();
|
||||
g.Restore(gstate);
|
||||
}
|
||||
|
||||
private static void DrawImage(Graphics g, CrosshairConfig config, Image image)
|
||||
{
|
||||
float num = (float)Math.Max(1, config.ImageScalePercent) / 100f;
|
||||
float num2 = (float)image.Width * num;
|
||||
float num3 = (float)image.Height * num;
|
||||
float num4 = config.ResolvedOffsetX;
|
||||
float num5 = config.ResolvedOffsetY;
|
||||
InterpolationMode interpolationMode = g.InterpolationMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
int num6 = Math.Clamp(config.Opacity, 0, 100);
|
||||
if (num6 >= 100)
|
||||
{
|
||||
g.DrawImage(image, (0f - num2) / 2f + num4, (0f - num3) / 2f + num5, num2, num3);
|
||||
}
|
||||
else
|
||||
{
|
||||
using ImageAttributes imageAttributes = new ImageAttributes();
|
||||
ColorMatrix colorMatrix = new ColorMatrix
|
||||
{
|
||||
Matrix33 = (float)num6 / 100f
|
||||
};
|
||||
imageAttributes.SetColorMatrix(colorMatrix);
|
||||
g.DrawImage(image, new Rectangle((int)((0f - num2) / 2f) + (int)num4, (int)((0f - num3) / 2f) + (int)num5, (int)num2, (int)num3), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
|
||||
}
|
||||
g.InterpolationMode = interpolationMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config, Rectangle target)
|
||||
{
|
||||
Draw(g, config, target, 1f);
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config, Rectangle target, float maxScale)
|
||||
{
|
||||
RectangleF bounds = CrosshairGeometry.Build(config).Bounds;
|
||||
float num = maxScale;
|
||||
if (bounds.Width > 0f && bounds.Height > 0f)
|
||||
{
|
||||
num = Math.Min(maxScale, 0.82f * Math.Min((float)target.Width / bounds.Width, (float)target.Height / bounds.Height));
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
g.SetClip(target);
|
||||
g.TranslateTransform((float)target.X + (float)target.Width / 2f, (float)target.Y + (float)target.Height / 2f);
|
||||
g.ScaleTransform(num, num);
|
||||
Draw(g, config);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
|
||||
public static void DrawCheckerboard(Graphics g, Rectangle rect, int cell)
|
||||
{
|
||||
using Region clip = g.Clip;
|
||||
g.SetClip(rect, CombineMode.Intersect);
|
||||
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 58, 58, 64)))
|
||||
{
|
||||
using SolidBrush solidBrush2 = new SolidBrush(Color.FromArgb(255, 78, 78, 86));
|
||||
for (int i = rect.Top; i < rect.Bottom; i += cell)
|
||||
{
|
||||
for (int j = rect.Left; j < rect.Right; j += cell)
|
||||
{
|
||||
g.FillRectangle((((j - rect.Left) / cell + (i - rect.Top) / cell) % 2 == 0) ? solidBrush : solidBrush2, j, i, cell, cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Clip = clip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed class CrosshairService : IDisposable
|
||||
{
|
||||
private const int QUNS_RUNNING_D3D_FULL_SCREEN = 3;
|
||||
|
||||
private CrosshairWindow? _window;
|
||||
|
||||
private readonly Func<CrosshairWindow> _newWindow;
|
||||
|
||||
public bool IsVisible { get; private set; }
|
||||
|
||||
public CrosshairConfig Config { get; private set; } = new CrosshairConfig();
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
private static extern int SHQueryUserNotificationState(out int state);
|
||||
|
||||
public CrosshairService()
|
||||
: this(() => new CrosshairWindow())
|
||||
{
|
||||
}
|
||||
|
||||
internal CrosshairService(Func<CrosshairWindow> newWindow)
|
||||
{
|
||||
_newWindow = newWindow;
|
||||
}
|
||||
|
||||
public static bool IsExclusiveFullscreen()
|
||||
{
|
||||
try
|
||||
{
|
||||
int state;
|
||||
return SHQueryUserNotificationState(out state) == 0 && state == 3;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Apply(CrosshairConfig config)
|
||||
{
|
||||
Config = config;
|
||||
if (IsVisible)
|
||||
{
|
||||
_window?.Apply(config);
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (_window == null)
|
||||
{
|
||||
_window = _newWindow();
|
||||
}
|
||||
_ = _window.Handle;
|
||||
_window.Apply(Config);
|
||||
if (!_window.Visible)
|
||||
{
|
||||
_window.Show();
|
||||
}
|
||||
IsVisible = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_window?.Hide();
|
||||
IsVisible = false;
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
if (IsVisible)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_window?.Dispose();
|
||||
_window = null;
|
||||
IsVisible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public enum CrosshairShape
|
||||
{
|
||||
Cross,
|
||||
Dot,
|
||||
Circle,
|
||||
T
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public enum CrosshairShapeKind
|
||||
{
|
||||
Cross,
|
||||
T,
|
||||
Circle,
|
||||
Dot,
|
||||
Chevron
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairShapeKinds
|
||||
{
|
||||
public static IReadOnlyList<CrosshairShapeKind> All { get; } = new CrosshairShapeKind[5]
|
||||
{
|
||||
CrosshairShapeKind.Cross,
|
||||
CrosshairShapeKind.T,
|
||||
CrosshairShapeKind.Circle,
|
||||
CrosshairShapeKind.Dot,
|
||||
CrosshairShapeKind.Chevron
|
||||
};
|
||||
|
||||
public static void Apply(CrosshairConfig config, CrosshairShapeKind kind)
|
||||
{
|
||||
config.CentreDot = config.ResolvedCentreDot;
|
||||
switch (kind)
|
||||
{
|
||||
case CrosshairShapeKind.Cross:
|
||||
SetParts(config, top: true, bottom: true, left: true, right: true, ring: false, chevron: false);
|
||||
config.Shape = CrosshairShape.Cross;
|
||||
break;
|
||||
case CrosshairShapeKind.T:
|
||||
SetParts(config, top: false, bottom: true, left: true, right: true, ring: false, chevron: false);
|
||||
config.Shape = CrosshairShape.T;
|
||||
break;
|
||||
case CrosshairShapeKind.Circle:
|
||||
SetParts(config, top: false, bottom: false, left: false, right: false, ring: true, chevron: false);
|
||||
config.Shape = CrosshairShape.Circle;
|
||||
break;
|
||||
case CrosshairShapeKind.Dot:
|
||||
SetParts(config, top: false, bottom: false, left: false, right: false, ring: false, chevron: false);
|
||||
config.CentreDot = true;
|
||||
config.Shape = CrosshairShape.Dot;
|
||||
break;
|
||||
case CrosshairShapeKind.Chevron:
|
||||
SetParts(config, top: false, bottom: false, left: true, right: true, ring: false, chevron: true);
|
||||
config.Shape = CrosshairShape.Cross;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static CrosshairShapeKind? Of(CrosshairConfig c)
|
||||
{
|
||||
bool resolvedArmTop = c.ResolvedArmTop;
|
||||
bool resolvedArmBottom = c.ResolvedArmBottom;
|
||||
bool resolvedArmLeft = c.ResolvedArmLeft;
|
||||
bool resolvedArmRight = c.ResolvedArmRight;
|
||||
bool resolvedShowCircle = c.ResolvedShowCircle;
|
||||
if (c.Chevron)
|
||||
{
|
||||
if (!(resolvedArmLeft & resolvedArmRight) || resolvedArmTop || resolvedArmBottom || resolvedShowCircle)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CrosshairShapeKind.Chevron;
|
||||
}
|
||||
bool flag = !resolvedArmTop && !resolvedArmBottom && !resolvedArmLeft && !resolvedArmRight;
|
||||
if (resolvedShowCircle)
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CrosshairShapeKind.Circle;
|
||||
}
|
||||
if (resolvedArmTop & resolvedArmBottom & resolvedArmLeft & resolvedArmRight)
|
||||
{
|
||||
return CrosshairShapeKind.Cross;
|
||||
}
|
||||
if (!resolvedArmTop & resolvedArmBottom & resolvedArmLeft & resolvedArmRight)
|
||||
{
|
||||
return CrosshairShapeKind.T;
|
||||
}
|
||||
if (flag && c.ResolvedCentreDot)
|
||||
{
|
||||
return CrosshairShapeKind.Dot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void SetParts(CrosshairConfig c, bool top, bool bottom, bool left, bool right, bool ring, bool chevron)
|
||||
{
|
||||
c.ArmTop = top;
|
||||
c.ArmBottom = bottom;
|
||||
c.ArmLeft = left;
|
||||
c.ArmRight = right;
|
||||
c.ShowCircle = ring;
|
||||
c.Chevron = chevron;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 579 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user