-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGpuPlugin.cs
More file actions
690 lines (615 loc) · 25.5 KB
/
Copy pathGpuPlugin.cs
File metadata and controls
690 lines (615 loc) · 25.5 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using CoreTemp.Plugin;
using Microsoft.Win32;
namespace CoreTempGPU
{
/// <summary>
/// Thin orange shade strip: Bold Condensed UI, drag + magnetic snap,
/// VRAM/RAM heat bars with cumulative ≥67% process tooltips.
/// </summary>
public sealed class GpuPlugin : Form, IPlugin
{
private GpuMonitor _monitor;
private PluginSettings _settings;
private TrayIcons _tray;
private bool _snapOnRelease = true;
private ToolTip _tips;
private Label _titleLabel;
private Label _loadValue;
private Label _vramValue;
private Label _ramValue;
private Label _tempValue;
private Label _clockValue;
private MiniBar _loadBar;
private MiniBar _vramBar;
private MiniBar _ramBar;
private bool _dragArmed;
private bool _dragging;
private Point _dragCursorOrigin;
private Point _dragFormOrigin;
// Content with 88px bars + gutters is ~722px; keep a few px end pad so nothing clips.
private const int StripW = 732;
private const int StripH = 26;
private const int EdgeMargin = 4;
private const int SnapThreshold = 48;
private const int DragDeadZone = 4;
private const int Gutter = 8;
public GpuPlugin()
{
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
TopMost = true;
StartPosition = FormStartPosition.Manual;
AutoScaleMode = AutoScaleMode.None;
Size = new Size(StripW, StripH);
MinimumSize = new Size(StripW, StripH);
MaximumSize = new Size(StripW, StripH);
// Mid tone; actual fill is a vertical gradient in OnPaint.
BackColor = Color.FromArgb(255, 140, 0);
Font = UiStyle.Regular(9F);
DoubleBuffered = true;
Text = "CoreTempGPU";
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
Opacity = 1.0;
MouseDown += OnDragMouseDown;
MouseMove += OnDragMouseMove;
MouseUp += OnDragMouseUp;
MouseCaptureChanged += OnMouseCaptureChanged;
}
// Bright orange → subtle dark/brownish orange (vertical, 180° from prior).
private static readonly Color GradTop = Color.FromArgb(255, 140, 0);
private static readonly Color GradBottom = Color.FromArgb(120, 55, 8);
protected override void OnPaint(PaintEventArgs e)
{
PaintGradient(e.Graphics, ClientRectangle);
base.OnPaint(e);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
PaintGradient(e.Graphics, ClientRectangle);
}
private static void PaintGradient(Graphics g, Rectangle bounds)
{
if (bounds.Width <= 0 || bounds.Height <= 0) return;
using (var brush = new LinearGradientBrush(
bounds,
GradTop,
GradBottom,
LinearGradientMode.Vertical))
{
g.FillRectangle(brush, bounds);
}
}
// ---- IPlugin --------------------------------------------------------------
public eStartStatus Start()
{
Log("Start() enter font=" + UiStyle.FontFamilyName);
try
{
_settings = new PluginSettings();
_settings.Load();
_snapOnRelease = _settings.SnapOnRelease;
TopMost = _settings.AlwaysOnTop;
BuildUi();
WireDragOnChildren();
SetupToolTips();
_monitor = new GpuMonitor();
_monitor.Initialize();
Log("monitor adapter=" + (_monitor.AdapterName ?? "(null)"));
if (CoreTempPluginProxyReference != null && CoreTempPluginProxyReference.ParentHandle != null)
Show(CoreTempPluginProxyReference.ParentHandle);
else
Show();
RestoreOrDefaultPosition();
BringToFront();
try { SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged; } catch { }
_tray = new TrayIcons();
_tray.ConfigureRequested += (s, e) => Configure();
_tray.TogglePanelRequested += (s, e) => TogglePanel();
_tray.ApplyVisibility(_settings);
ApplyPanelVisibility();
try
{
_monitor.Poll();
ApplySnapshot(_monitor.Last);
}
catch (Exception ex) { Log("first poll: " + ex.Message); }
Log("ready snap=" + _snapOnRelease + " pos=" + Location + " stripW=" + StripW);
return eStartStatus.Success;
}
catch (Exception ex)
{
Log("Start FAILED: " + ex);
try { if (_monitor != null) _monitor.Dispose(); } catch { }
return eStartStatus.Failed;
}
}
public void Update(CoreTempSharedData data)
{
try
{
if (_monitor == null) return;
_monitor.Poll();
ApplySnapshot(_monitor.Last);
}
catch (Exception ex) { Log("Update error: " + ex.Message); }
}
public void Stop()
{
Log("Stop()");
try { SystemEvents.DisplaySettingsChanged -= OnDisplaySettingsChanged; } catch { }
try { if (_tips != null) _tips.Dispose(); } catch { }
_tips = null;
try { if (_tray != null) _tray.Dispose(); } catch { }
_tray = null;
try { Hide(); } catch { }
try { if (_monitor != null) _monitor.Dispose(); } catch { }
_monitor = null;
}
public eConfigureStatus Configure()
{
if (_settings == null) return eConfigureStatus.Handled;
using (var dlg = new SettingsDialog(_settings, BuildStatusText()))
{
if (dlg.ShowDialog(this) != DialogResult.OK) return eConfigureStatus.Handled;
_settings.SnapOnRelease = dlg.SnapOnRelease;
_settings.AlwaysOnTop = dlg.AlwaysOnTop;
_settings.IntervalMs = dlg.IntervalMs;
_settings.ShowPanel = dlg.ShowPanel;
_settings.TrayShowLoad = dlg.TrayShowLoad;
_settings.TrayShowVram = dlg.TrayShowVram;
_settings.TrayShowTemp = dlg.TrayShowTemp;
_settings.TrayShowClock = dlg.TrayShowClock;
_settings.Save();
_snapOnRelease = _settings.SnapOnRelease;
TopMost = _settings.AlwaysOnTop;
if (_tray != null)
{
_tray.ApplyVisibility(_settings);
if (_monitor != null) _tray.Update(_monitor.Last, _settings);
}
ApplyPanelVisibility();
}
return eConfigureStatus.Handled;
}
public void Remove(string path)
{
try
{
try { SystemEvents.DisplaySettingsChanged -= OnDisplaySettingsChanged; } catch { }
try { if (_tips != null) _tips.Dispose(); } catch { }
_tips = null;
try { if (_tray != null) _tray.Dispose(); } catch { }
_tray = null;
Hide();
string ini = new PluginSettings().SettingsPath;
if (!string.IsNullOrEmpty(path) && System.IO.Directory.Exists(path))
{
string candidate = System.IO.Path.Combine(path, "CoreTempGPU.ini");
if (System.IO.File.Exists(candidate))
try { System.IO.File.Delete(candidate); } catch { }
}
else if (System.IO.File.Exists(ini))
{
try { System.IO.File.Delete(ini); } catch { }
}
}
catch { }
}
public new string Name { get { return "CoreTempGPU"; } }
public string Description { get { return "GPU usage, VRAM, RAM, temperature and clock (PDH + NVML)."; } }
public string Version { get { return "1.3.5"; } }
private CoreTempPluginProxy _proxy;
public CoreTempPluginProxy CoreTempPluginProxyReference
{
get { return _proxy; }
set { _proxy = value; }
}
// ---- UI -------------------------------------------------------------------
private void BuildUi()
{
if (_titleLabel != null) return;
// Flow layout with gutters — avoids absolute-position overlap when fonts change.
var row = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
Padding = new Padding(6, 0, 8, 0),
Margin = Padding.Empty,
BackColor = Color.Transparent
};
// Longer heat bars eat the former empty right margin (~90px each).
_titleLabel = MkLabel("GPU", 72, true);
_loadValue = MkLabel("--%", 36, false);
_loadBar = MkBar(88);
_vramValue = MkLabel("--/-- GB", 92, false);
_vramBar = MkBar(88);
_ramValue = MkLabel("--/-- GB", 92, false);
_ramBar = MkBar(88);
_tempValue = MkLabel("--°C", 42, false);
_clockValue = MkLabel("-- MHz", 62, false);
AddCell(row, _titleLabel, afterGap: Gutter);
AddCell(row, _loadValue, afterGap: 4);
AddCell(row, _loadBar, afterGap: Gutter);
AddCell(row, _vramValue, afterGap: 4);
AddCell(row, _vramBar, afterGap: Gutter);
AddCell(row, _ramValue, afterGap: 4);
AddCell(row, _ramBar, afterGap: Gutter);
AddCell(row, _tempValue, afterGap: 6);
AddCell(row, _clockValue, afterGap: 0);
Controls.Add(row);
}
private static void AddCell(FlowLayoutPanel row, Control c, int afterGap)
{
c.Margin = new Padding(0, (StripH - c.Height) / 2, afterGap, 0);
row.Controls.Add(c);
}
private void SetupToolTips()
{
_tips = new ToolTip
{
ShowAlways = true,
UseAnimation = false,
UseFading = false,
AutoPopDelay = 15000,
InitialDelay = 400,
ReshowDelay = 200,
IsBalloon = false
};
_vramBar.MouseEnter += (s, e) => RefreshVramTip();
_vramValue.MouseEnter += (s, e) => RefreshVramTip();
_ramBar.MouseEnter += (s, e) => RefreshRamTip();
_ramValue.MouseEnter += (s, e) => RefreshRamTip();
}
private void RefreshVramTip()
{
try
{
var snap = _monitor != null ? _monitor.Last : null;
ulong used = snap != null && snap.VramUsed.HasValue ? snap.VramUsed.Value : 0;
IntPtr dev = _monitor != null ? _monitor.NvmlDevice : IntPtr.Zero;
var shares = ProcessMemory.GetVramTopContributors(dev, used);
string text = ProcessMemory.FormatTooltip("VRAM top contributors", shares, used);
_tips.SetToolTip(_vramBar, text);
_tips.SetToolTip(_vramValue, text);
}
catch
{
_tips.SetToolTip(_vramBar, "VRAM breakdown unavailable");
_tips.SetToolTip(_vramValue, "VRAM breakdown unavailable");
}
}
private void RefreshRamTip()
{
try
{
var snap = _monitor != null ? _monitor.Last : null;
ulong used = snap != null && snap.RamUsed.HasValue ? snap.RamUsed.Value : 0;
var shares = ProcessMemory.GetRamTopContributors(used);
string text = ProcessMemory.FormatTooltip("RAM top contributors", shares, used);
_tips.SetToolTip(_ramBar, text);
_tips.SetToolTip(_ramValue, text);
}
catch
{
_tips.SetToolTip(_ramBar, "RAM breakdown unavailable");
_tips.SetToolTip(_ramValue, "RAM breakdown unavailable");
}
}
private void WireDragOnChildren()
{
WireDragRecursive(this);
}
private void WireDragRecursive(Control root)
{
root.MouseDown += OnDragMouseDown;
root.MouseMove += OnDragMouseMove;
root.MouseUp += OnDragMouseUp;
foreach (Control c in root.Controls)
WireDragRecursive(c);
}
private Label MkLabel(string text, int w, bool emphasis)
{
return new Label
{
AutoSize = false,
Text = text,
ForeColor = Color.Black,
BackColor = Color.Transparent,
Font = emphasis ? UiStyle.Bold(9F) : UiStyle.Regular(8.5F),
Size = new Size(w, StripH - 4),
TextAlign = ContentAlignment.MiddleLeft,
AutoEllipsis = true
};
}
private MiniBar MkBar(int w)
{
return new MiniBar
{
Size = new Size(w, 11),
BackColor = Color.FromArgb(60, 40, 0)
};
}
private void ApplySnapshot(GpuSnapshot snap)
{
if (snap == null || IsDisposed) return;
if (InvokeRequired)
{
try { BeginInvoke(new Action(() => ApplySnapshot(snap))); } catch { }
return;
}
_titleLabel.Text = !string.IsNullOrEmpty(snap.AdapterName) ? ShortName(snap.AdapterName) : "GPU";
_loadValue.Text = snap.Load.HasValue ? Math.Round(snap.Load.Value).ToString("0") + "%" : "--%";
_vramValue.Text = FormatMemLine(snap.VramUsed, snap.VramTotal);
_ramValue.Text = FormatMemLine(snap.RamUsed, snap.RamTotal);
_tempValue.Text = snap.Temperature.HasValue ? Math.Round(snap.Temperature.Value).ToString("0") + "°C" : "--°C";
_clockValue.Text = snap.ClockMhz.HasValue ? Math.Round(snap.ClockMhz.Value).ToString("0") + " MHz" : "-- MHz";
_loadBar.Value = snap.Load ?? 0;
_vramBar.Value = Pct(snap.VramUsed, snap.VramTotal) ?? 0;
_ramBar.Value = Pct(snap.RamUsed, snap.RamTotal) ?? 0;
if (_tray != null && _settings != null)
_tray.Update(snap, _settings);
}
// ---- Drag + snap (P0 fix: Capture) ----------------------------------------
private void OnDragMouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
_dragArmed = true;
_dragging = false;
_dragCursorOrigin = Cursor.Position;
_dragFormOrigin = Location;
Capture = true; // keep MouseMove/Up even when cursor leaves the strip
}
private void OnDragMouseMove(object sender, MouseEventArgs e)
{
if (!_dragArmed) return;
Point cur = Cursor.Position;
int dx = cur.X - _dragCursorOrigin.X;
int dy = cur.Y - _dragCursorOrigin.Y;
if (!_dragging)
{
if (Math.Abs(dx) < DragDeadZone && Math.Abs(dy) < DragDeadZone) return;
_dragging = true;
Cursor = Cursors.SizeAll;
}
Location = new Point(_dragFormOrigin.X + dx, _dragFormOrigin.Y + dy);
}
private void OnDragMouseUp(object sender, MouseEventArgs e)
{
EndDrag(applySnap: true);
}
private void OnMouseCaptureChanged(object sender, EventArgs e)
{
// Capture lost without MouseUp (alt-tab, etc.)
if (!Capture && (_dragArmed || _dragging))
EndDrag(applySnap: _dragging);
}
private void EndDrag(bool applySnap)
{
if (!_dragArmed && !_dragging) return;
bool wasDragging = _dragging;
_dragArmed = false;
_dragging = false;
try { if (Capture) Capture = false; } catch { }
Cursor = Cursors.Default;
if (!wasDragging || !applySnap) return;
Point from = Location;
ApplySnapOrClamp();
PersistPosition();
Log("snap from=" + from + " to=" + Location + " enabled=" + _snapOnRelease);
}
private void ApplySnapOrClamp()
{
if (IsDisposed) return;
Screen scr = Screen.FromPoint(Cursor.Position) ?? Screen.PrimaryScreen;
Rectangle wa = scr != null ? scr.WorkingArea : SystemInformation.WorkingArea;
int x = Location.X;
int y = Location.Y;
int threshold = SnapThreshold;
try
{
// Scale threshold with DPI when available (.NET 4.7+ DeviceDpi).
threshold = (int)Math.Round(SnapThreshold * (DeviceDpi / 96.0));
}
catch { }
if (_snapOnRelease || (_settings != null && _settings.SnapOnRelease))
{
int left = wa.Left + EdgeMargin;
int right = wa.Right - StripW - EdgeMargin;
int top = wa.Top + EdgeMargin;
int bottom = wa.Bottom - StripH - EdgeMargin;
int centerX = wa.Left + (wa.Width - StripW) / 2;
int centerY = wa.Top + (wa.Height - StripH) / 2;
if (right < left) right = left;
if (bottom < top) bottom = top;
x = SnapAxis(x, left, centerX, right, threshold);
y = SnapAxis(y, top, centerY, bottom, threshold);
}
Location = ClampToWorkArea(new Point(x, y), wa);
if (Width != StripW || Height != StripH)
Size = new Size(StripW, StripH);
}
private static int SnapAxis(int value, int a, int b, int c, int threshold)
{
int best = value;
int bestDist = int.MaxValue;
foreach (int rail in new[] { a, b, c })
{
int d = Math.Abs(value - rail);
if (d < bestDist) { bestDist = d; best = rail; }
}
return bestDist <= threshold ? best : value;
}
private static Point ClampToWorkArea(Point p, Rectangle wa)
{
int minX = wa.Left + EdgeMargin;
int maxX = wa.Right - StripW - EdgeMargin;
int minY = wa.Top + EdgeMargin;
int maxY = wa.Bottom - StripH - EdgeMargin;
if (maxX < minX) maxX = minX;
if (maxY < minY) maxY = minY;
int x = p.X; int y = p.Y;
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
return new Point(x, y);
}
private void RestoreOrDefaultPosition()
{
Point? saved = null;
if (_settings != null
&& _settings.PosX != PluginSettings.PosUnset
&& _settings.PosY != PluginSettings.PosUnset)
saved = new Point(_settings.PosX, _settings.PosY);
if (saved.HasValue && IsPointOnAnyWorkArea(saved.Value))
{
Screen scr = Screen.FromPoint(saved.Value) ?? Screen.PrimaryScreen;
Rectangle wa = scr != null ? scr.WorkingArea : SystemInformation.WorkingArea;
Location = ClampToWorkArea(saved.Value, wa);
}
else
{
PlaceBottomRight(Screen.PrimaryScreen);
}
if (Width != StripW || Height != StripH)
Size = new Size(StripW, StripH);
}
private void PlaceBottomRight(Screen scr)
{
Rectangle wa = scr != null ? scr.WorkingArea : SystemInformation.WorkingArea;
Location = new Point(wa.Right - StripW - EdgeMargin, wa.Bottom - StripH - EdgeMargin);
}
private static bool IsPointOnAnyWorkArea(Point p)
{
Rectangle probe = new Rectangle(p.X, p.Y, Math.Max(8, StripW / 4), Math.Max(4, StripH));
foreach (Screen s in Screen.AllScreens)
if (s.WorkingArea.IntersectsWith(probe)) return true;
return false;
}
private void PersistPosition()
{
if (_settings == null) return;
_settings.PosX = Location.X;
_settings.PosY = Location.Y;
_settings.Save();
}
private void OnDisplaySettingsChanged(object sender, EventArgs e)
{
try
{
if (IsDisposed) return;
BeginInvoke(new Action(() =>
{
Screen scr = Screen.FromControl(this) ?? Screen.PrimaryScreen;
Rectangle wa = scr != null ? scr.WorkingArea : SystemInformation.WorkingArea;
Location = ClampToWorkArea(Location, wa);
PersistPosition();
}));
}
catch { }
}
private void TogglePanel()
{
if (_settings == null) return;
_settings.ShowPanel = !_settings.ShowPanel;
_settings.Save();
ApplyPanelVisibility();
}
private void ApplyPanelVisibility()
{
if (_settings == null) return;
if (_settings.ShowPanel) { if (!Visible) Show(); }
else Hide();
}
// ---- helpers --------------------------------------------------------------
private static string ShortName(string name)
{
string n = name.Replace("NVIDIA ", "").Replace("GeForce ", "").Replace("AMD ", "").Replace("Radeon ", "");
return n.Length > 10 ? n.Substring(0, 10) + "…" : n;
}
private static string FormatMemLine(ulong? used, ulong? total)
{
if (!used.HasValue && !total.HasValue) return "--/-- GB";
if (used.HasValue && total.HasValue)
{
if (total.Value >= 1024UL * 1024 * 1024)
{
double u = used.Value / (1024.0 * 1024 * 1024);
double t = total.Value / (1024.0 * 1024 * 1024);
return u.ToString("0.0") + "/" + t.ToString("0.0") + " GB";
}
return (used.Value / (1024.0 * 1024)).ToString("0") + "/"
+ (total.Value / (1024.0 * 1024)).ToString("0") + " MB";
}
return used.HasValue ? GpuSnapshot.FormatBytes(used.Value) : GpuSnapshot.FormatBytes(total.Value);
}
private static double? Pct(ulong? used, ulong? total)
{
if (!used.HasValue || !total.HasValue || total.Value == 0) return null;
return Math.Min(100.0, 100.0 * used.Value / total.Value);
}
private string BuildStatusText()
{
if (_monitor == null) return "Not initialized.";
var snap = _monitor.Last;
string src = string.IsNullOrEmpty(snap.Source) ? "no data yet" : snap.Source;
string adapter = string.IsNullOrEmpty(snap.AdapterName) ? "unknown" : snap.AdapterName;
return "Font: " + UiStyle.FontFamilyName + " Bold"
+ Environment.NewLine + "Source: " + src
+ Environment.NewLine + "Adapter: " + adapter
+ Environment.NewLine + "Drag near edges to snap; hover VRAM/RAM bars for top processes.";
}
private static void Log(string msg)
{
try
{
string path = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(typeof(GpuPlugin).Assembly.Location) ?? ".",
"CoreTempGPU.log");
System.IO.File.AppendAllText(path,
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + msg + Environment.NewLine);
}
catch { }
}
/// <summary>Painted heat bar — ProgressBar swallows mouse; Panel does not.</summary>
private sealed class MiniBar : Panel
{
private double _value;
public double Value
{
get { return _value; }
set
{
double v = value;
if (v < 0) v = 0;
if (v > 100) v = 100;
if (Math.Abs(_value - v) < 0.01) return;
_value = v;
Invalidate();
}
}
public MiniBar()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(BackColor);
int fill = (int)Math.Round(Width * (_value / 100.0));
if (fill > 0)
{
using (var b = new SolidBrush(UiStyle.Heat(_value)))
e.Graphics.FillRectangle(b, 0, 0, fill, Height);
}
using (var p = new Pen(Color.FromArgb(90, 50, 0)))
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
}
}
}
}