-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUiStyle.cs
More file actions
117 lines (107 loc) · 3.97 KB
/
Copy pathUiStyle.cs
File metadata and controls
117 lines (107 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Drawing;
using System.Drawing.Text;
namespace CoreTempGPU
{
/// <summary>
/// Shared UI fonts + green→yellow→red heat scale.
/// Default: Segoe UI Semibold — proportional Windows UI face, readable at strip size
/// without Aptos Narrow thinness or JetBrains Mono code-block look.
/// </summary>
internal static class UiStyle
{
private static string _family;
private static FontStyle _style = FontStyle.Bold;
private static readonly object _lock = new object();
public static string FontFamilyName
{
get
{
EnsureResolved();
return _family;
}
}
/// <summary>Body text — Semibold/Bold proportional UI font.</summary>
public static Font Regular(float emSize)
{
return Make(emSize);
}
/// <summary>Title / emphasis — same family, bold weight.</summary>
public static Font Bold(float emSize)
{
return Make(emSize);
}
private static void EnsureResolved()
{
lock (_lock)
{
if (_family != null) return;
Resolve();
}
}
private static Font Make(float emSize)
{
EnsureResolved();
try { return new Font(_family, emSize, _style, GraphicsUnit.Point); }
catch
{
try { return new Font("Segoe UI", emSize, FontStyle.Bold, GraphicsUnit.Point); }
catch { return new Font("Tahoma", emSize, FontStyle.Bold, GraphicsUnit.Point); }
}
}
private static void Resolve()
{
// Prefer proportional UI fonts (not monospace). Semibold > Bold > Regular.
// Skip Narrow/Thin/Light and JetBrains Mono (too “codey” on a dense strip).
string[] preferred =
{
"Segoe UI Semibold",
"Segoe UI",
"Bahnschrift SemiBold",
"Bahnschrift",
"Calibri",
"Tahoma"
};
using (var coll = new InstalledFontCollection())
{
foreach (string want in preferred)
{
foreach (FontFamily f in coll.Families)
{
if (!string.Equals(f.Name, want, StringComparison.OrdinalIgnoreCase))
continue;
_family = f.Name;
// "Segoe UI Semibold" is already a semibold face — Regular style is correct.
// Plain "Segoe UI" / Calibri / Tahoma → Bold for weight.
if (f.Name.IndexOf("Semibold", StringComparison.OrdinalIgnoreCase) >= 0
|| f.Name.IndexOf("SemiBold", StringComparison.OrdinalIgnoreCase) >= 0)
_style = FontStyle.Regular;
else
_style = FontStyle.Bold;
return;
}
}
}
_family = "Segoe UI";
_style = FontStyle.Bold;
}
/// <summary>Bright green (low) → yellow (mid) → red (high). t is 0..100.</summary>
public static Color Heat(double t)
{
if (t < 0) t = 0;
if (t > 100) t = 100;
if (t <= 50.0)
return Lerp(Color.FromArgb(40, 220, 40), Color.FromArgb(255, 230, 0), t / 50.0);
return Lerp(Color.FromArgb(255, 230, 0), Color.FromArgb(240, 30, 30), (t - 50.0) / 50.0);
}
private static Color Lerp(Color a, Color b, double u)
{
if (u < 0) u = 0;
if (u > 1) u = 1;
return Color.FromArgb(
(int)Math.Round(a.R + (b.R - a.R) * u),
(int)Math.Round(a.G + (b.G - a.G) * u),
(int)Math.Round(a.B + (b.B - a.B) * u));
}
}
}