-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGaugeControl.vb
More file actions
613 lines (527 loc) · 26.3 KB
/
Copy pathGaugeControl.vb
File metadata and controls
613 lines (527 loc) · 26.3 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
''' <summary>
''' GaugeControl.vb - Controllo gauge personalizzato
''' Disegna gauge grafici per visualizzare i tempi di attesa delle code.
''' Supporta stili: Arco 270°, Semicerchio, Barra Orizzontale, Barra Verticale.
''' Tutto il rendering è in GDI+ puro, nessuna dipendenza esterna.
''' </summary>
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
'Namespace QueueMonitor
''' <summary>
''' Controllo Windows Forms che disegna un gauge animato per il monitoraggio code.
''' Supporta doppio buffering per rendering fluido senza sfarfallio.
''' </summary>
Public Class GaugeControl
Inherits Control
' ─── Campi privati ───────────────────────────────────────
Private _queue As QueueModel
Private _gaugeConfig As GaugeConfig
Private _animatedValue As Double = 0 ' valore corrente dell'animazione
Private _animTimer As Timer
Private _targetValue As Double = 0
Private ReadOnly _animStep As Double = 2.5
' Colori calcolati
Private _colorNormal As Color = Color.FromArgb(0, 200, 81)
Private _colorWarning As Color = Color.FromArgb(255, 136, 0)
Private _colorCritical As Color = Color.FromArgb(255, 68, 68)
Private _colorBackground As Color = Color.FromArgb(30, 35, 45)
Private _colorTrack As Color = Color.FromArgb(55, 62, 78)
' ─── Costruttore ─────────────────────────────────────────
''' <summary>
''' Inizializza il controllo gauge con la coda e config specificate
''' </summary>
Public Sub New(queue As QueueModel, gaugeConfig As GaugeConfig)
_queue = queue
_gaugeConfig = gaugeConfig
' Abilita doppio buffering per rendering senza sfarfallio
SetStyle(ControlStyles.OptimizedDoubleBuffer Or
ControlStyles.AllPaintingInWmPaint Or
ControlStyles.UserPaint Or
ControlStyles.ResizeRedraw, True)
' Timer per animazione fluida
_animTimer = New Timer With {.Interval = 16} ' ~60fps
AddHandler _animTimer.Tick, AddressOf OnAnimTick
' Valore iniziale senza animazione
_animatedValue = If(queue IsNot Nothing, queue.PercentageFull, 0)
_targetValue = _animatedValue
' Aggiorna colori dalla config
UpdateColors()
' Dimensione minima suggerita
MinimumSize = New Size(120, 120)
End Sub
' ─── Proprietà pubbliche ──────────────────────────────────
''' <summary>
''' La coda associata a questo gauge.
''' Aggiornare questa proprietà rianima il gauge verso il nuovo valore.
''' </summary>
Public Property Queue As QueueModel
Get
Return _queue
End Get
Set(value As QueueModel)
_queue = value
If value IsNot Nothing Then
AnimateTo(value.PercentageFull)
End If
Invalidate()
End Set
End Property
''' <summary>Configurazione visiva del gauge</summary>
Public Property GaugeConfig As GaugeConfig
Get
Return _gaugeConfig
End Get
Set(value As GaugeConfig)
_gaugeConfig = value
UpdateColors()
Invalidate()
End Set
End Property
' ─── Aggiornamento colori ─────────────────────────────────
''' <summary>
''' Calcola i colori del gauge in base allo schema selezionato nella config
''' </summary>
Private Sub UpdateColors()
If _gaugeConfig Is Nothing Then Return
Select Case _gaugeConfig.ColorScheme
Case GaugeColorScheme.TrafficLight
_colorNormal = Color.FromArgb(0, 200, 81)
_colorWarning = Color.FromArgb(255, 165, 0)
_colorCritical = Color.FromArgb(220, 50, 50)
Case GaugeColorScheme.Ocean
_colorNormal = Color.FromArgb(0, 180, 220)
_colorWarning = Color.FromArgb(0, 120, 180)
_colorCritical = Color.FromArgb(0, 60, 140)
Case GaugeColorScheme.Sunset
_colorNormal = Color.FromArgb(180, 80, 220)
_colorWarning = Color.FromArgb(240, 100, 150)
_colorCritical = Color.FromArgb(255, 100, 30)
Case GaugeColorScheme.Monochrome
_colorNormal = Color.FromArgb(200, 200, 200)
_colorWarning = Color.FromArgb(130, 130, 130)
_colorCritical = Color.FromArgb(60, 60, 60)
Case GaugeColorScheme.Custom
Try
_colorNormal = ColorTranslator.FromHtml(_gaugeConfig.CustomColorNormal)
_colorWarning = ColorTranslator.FromHtml(_gaugeConfig.CustomColorWarning)
_colorCritical = ColorTranslator.FromHtml(_gaugeConfig.CustomColorCritical)
Catch
_colorNormal = Color.Green
_colorWarning = Color.Orange
_colorCritical = Color.Red
End Try
End Select
End Sub
''' <summary>
''' Ottieni il colore corrente basato sullo stato della coda
''' </summary>
Private Function GetCurrentColor() As Color
If _queue Is Nothing Then Return _colorNormal
Select Case _queue.Status
Case QueueStatus.Warning : Return _colorWarning
Case QueueStatus.Critical : Return _colorCritical
Case QueueStatus.Offline : Return Color.FromArgb(100, 100, 100)
Case Else : Return _colorNormal
End Select
End Function
' ─── Animazione ───────────────────────────────────────────
''' <summary>Avvia animazione verso il valore target</summary>
Public Sub AnimateTo(targetPercent As Double)
_targetValue = Math.Min(100, Math.Max(0, targetPercent))
If _gaugeConfig?.AnimateTransitions = True Then
_animTimer.Start()
Else
_animatedValue = _targetValue
Invalidate()
End If
End Sub
''' <summary>Tick del timer di animazione: avvicina il valore corrente al target</summary>
Private Sub OnAnimTick(sender As Object, e As EventArgs)
Dim diff = _targetValue - _animatedValue
If Math.Abs(diff) < 0.5 Then
_animatedValue = _targetValue
_animTimer.Stop()
Else
_animatedValue += diff * 0.12 ' easing esponenziale
End If
Invalidate()
End Sub
' ─── Rendering principale ─────────────────────────────────
''' <summary>
''' Override del metodo di disegno del controllo.
''' Dispatcha al renderer corretto in base allo stile configurato.
''' </summary>
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim g = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
g.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
' Sfondo
Using bgBrush As New SolidBrush(_colorBackground)
g.FillRectangle(bgBrush, ClientRectangle)
End Using
' Bordo arrotondato del pannello
DrawRoundedBorder(g)
If _queue Is Nothing OrElse _gaugeConfig Is Nothing Then Return
' Dispatch al renderer corretto
Select Case _gaugeConfig.Style
Case GaugeStyle.Arc270
DrawArc270(g)
Case GaugeStyle.Semicircle
DrawSemicircle(g)
Case GaugeStyle.HorizontalBar
DrawHorizontalBar(g)
Case GaugeStyle.VerticalBar
DrawVerticalBar(g)
End Select
' Etichetta nome coda (in basso)
If _gaugeConfig.ShowName Then
DrawQueueName(g)
End If
End Sub
' ─── Bordo arrotondato ────────────────────────────────────
Private Sub DrawRoundedBorder(g As Graphics)
Dim rect = New Rectangle(1, 1, Width - 3, Height - 3)
Dim radius = 12
Using path = GetRoundedRect(rect, radius)
' Highlight per stato critico
If _queue?.Status = QueueStatus.Critical Then
Using glowPen As New Pen(Color.FromArgb(80, 255, 50, 50), 3)
g.DrawPath(glowPen, path)
End Using
End If
Using borderPen As New Pen(Color.FromArgb(60, 70, 90), 1)
g.DrawPath(borderPen, path)
End Using
End Using
End Sub
''' <summary>Crea un GraphicsPath con angoli arrotondati</summary>
Private Function GetRoundedRect(rect As Rectangle, radius As Integer) As GraphicsPath
Dim path As New GraphicsPath()
path.AddArc(rect.X, rect.Y, radius, radius, 180, 90)
path.AddArc(rect.Right - radius, rect.Y, radius, radius, 270, 90)
path.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90)
path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90)
path.CloseFigure()
Return path
End Function
' ─── STILE 1: Arco 270 gradi ─────────────────────────────
Private Sub DrawArc270(g As Graphics)
Dim padding = 22
Dim arcRect = New Rectangle(padding, padding, Width - padding * 2, Height - padding * 2 - 28)
If arcRect.Width < 10 OrElse arcRect.Height < 10 Then Return
Dim arcWidth = _gaugeConfig.ArcWidth
Dim startAngle = 135F ' parte in basso-sinistra
Dim sweepTotal = 270F ' 270 gradi totali
Dim sweepFill = CSng(sweepTotal * _animatedValue / 100.0)
' Track (sfondo arco)
Using trackPen As New Pen(_colorTrack, arcWidth) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(trackPen, arcRect, startAngle, sweepTotal)
End Using
' Arco riempito con gradiente di colore
If sweepFill > 0 Then
Dim gaugeColor = GetCurrentColor()
Dim darkColor = DarkenColor(gaugeColor, 0.6)
' Crea effetto glow sotto l'arco
Using glowPen As New Pen(Color.FromArgb(50, gaugeColor), arcWidth + 8) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(glowPen, arcRect, startAngle, sweepFill)
End Using
Using fillPen As New Pen(gaugeColor, arcWidth) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(fillPen, arcRect, startAngle, sweepFill)
End Using
End If
' Valore centrale
If _gaugeConfig.ShowValue Then
DrawCenterValue(g, arcRect)
End If
' Etichette min/max
If _gaugeConfig.ShowLabels Then
DrawArcLabels(g, arcRect)
End If
End Sub
' ─── STILE 2: Semicerchio ─────────────────────────────────
Private Sub DrawSemicircle(g As Graphics)
Dim padding = 20
Dim arcRect = New Rectangle(padding, padding, Width - padding * 2, (Height - padding - 36) * 2)
If arcRect.Width < 10 Then Return
Dim arcWidth = _gaugeConfig.ArcWidth
Dim startAngle = 180F
Dim sweepTotal = 180F
Dim sweepFill = CSng(sweepTotal * _animatedValue / 100.0)
' Track
Using trackPen As New Pen(_colorTrack, arcWidth) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(trackPen, arcRect, startAngle, sweepTotal)
End Using
' Fill con glow
If sweepFill > 0 Then
Dim gaugeColor = GetCurrentColor()
Using glowPen As New Pen(Color.FromArgb(50, gaugeColor), arcWidth + 8) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(glowPen, arcRect, startAngle, sweepFill)
End Using
Using fillPen As New Pen(gaugeColor, arcWidth) With {
.StartCap = LineCap.Round,
.EndCap = LineCap.Round
}
g.DrawArc(fillPen, arcRect, startAngle, sweepFill)
End Using
End If
' Valore al centro del semicerchio (parte inferiore)
If _gaugeConfig.ShowValue Then
Dim cx = arcRect.Left + arcRect.Width / 2
Dim cy = arcRect.Top + arcRect.Height / 2 + 4
DrawValueAt(g, cx, cy)
End If
End Sub
' ─── STILE 3: Barra orizzontale ───────────────────────────
Private Sub DrawHorizontalBar(g As Graphics)
Dim padding = 18
Dim barHeight = Math.Max(16, Height / 5)
Dim barY = (Height - barHeight) / 2 - 10
Dim barRect = New Rectangle(padding, barY, Width - padding * 2, barHeight)
If barRect.Width < 4 Then Return
Dim gaugeColor = GetCurrentColor()
Dim fillWidth = CInt(barRect.Width * _animatedValue / 100.0)
' Sfondo barra con griglia
Using bgBrush As New SolidBrush(_colorTrack)
g.FillRectangle(bgBrush, barRect)
End Using
If _gaugeConfig.ShowGrid Then
Dim gridStep = barRect.Width / 10
Using gridPen As New Pen(Color.FromArgb(40, 255, 255, 255), 1)
For x As Single = barRect.Left + gridStep To barRect.Right - 1 Step gridStep
g.DrawLine(gridPen, x, barRect.Top, x, barRect.Bottom)
Next
End Using
End If
' Riempimento barra con gradiente
If fillWidth > 2 Then
Dim fillRect = New Rectangle(barRect.X, barRect.Y, fillWidth, barRect.Height)
Dim darkColor = DarkenColor(gaugeColor, 0.6)
Using gradBrush As New LinearGradientBrush(fillRect, darkColor, gaugeColor, LinearGradientMode.Horizontal)
g.FillRectangle(gradBrush, fillRect)
End Using
' Glow highlight in cima
Using glowBrush As New SolidBrush(Color.FromArgb(60, 255, 255, 255))
g.FillRectangle(glowBrush, New Rectangle(fillRect.X, fillRect.Y, fillRect.Width, fillRect.Height / 3))
End Using
End If
' Bordo barra
Using borderPen As New Pen(Color.FromArgb(80, 80, 100), 1)
g.DrawRectangle(borderPen, barRect)
End Using
' Valore a destra
If _gaugeConfig.ShowValue Then
Dim valText = $"{CInt(_animatedValue)}%"
If _queue IsNot Nothing Then valText = _queue.WaitTimeFormatted
Dim valFont = New Font("Segoe UI", 13, FontStyle.Bold)
Using valBrush As New SolidBrush(gaugeColor)
Dim valSize = g.MeasureString(valText, valFont)
g.DrawString(valText, valFont, valBrush,
barRect.Right - valSize.Width - 4,
barRect.Bottom + 6)
End Using
valFont.Dispose()
End If
' Soglie visive
DrawBarThresholds(g, barRect)
End Sub
' ─── STILE 4: Barra verticale ─────────────────────────────
Private Sub DrawVerticalBar(g As Graphics)
Dim padding = 22
Dim barWidth = Math.Max(20, Width / 4)
Dim barX = (Width - barWidth) / 2
Dim barRect = New Rectangle(barX, padding + 10, barWidth, Height - padding * 2 - 30)
If barRect.Height < 4 Then Return
Dim gaugeColor = GetCurrentColor()
Dim fillHeight = CInt(barRect.Height * _animatedValue / 100.0)
' Sfondo
Using bgBrush As New SolidBrush(_colorTrack)
g.FillRectangle(bgBrush, barRect)
End Using
' Riempimento dal basso verso l'alto
If fillHeight > 2 Then
Dim fillRect = New Rectangle(barRect.X, barRect.Bottom - fillHeight, barRect.Width, fillHeight)
Dim darkColor = DarkenColor(gaugeColor, 0.6)
Using gradBrush As New LinearGradientBrush(
New Point(barRect.X, barRect.Bottom),
New Point(barRect.X, barRect.Top),
darkColor, gaugeColor)
g.FillRectangle(gradBrush, fillRect)
End Using
End If
' Bordo
Using borderPen As New Pen(Color.FromArgb(80, 80, 100), 1)
g.DrawRectangle(borderPen, barRect)
End Using
' Valore sopra la barra
If _gaugeConfig.ShowValue Then
Dim valText = If(_queue IsNot Nothing, _queue.WaitTimeFormatted, $"{CInt(_animatedValue)}%")
Dim valFont = New Font("Segoe UI", 11, FontStyle.Bold)
Using valBrush As New SolidBrush(gaugeColor)
Dim valSize = g.MeasureString(valText, valFont)
g.DrawString(valText, valFont, valBrush,
barRect.Left + (barRect.Width - valSize.Width) / 2,
barRect.Top - valSize.Height - 4)
End Using
valFont.Dispose()
End If
End Sub
' ─── Helpers di disegno ───────────────────────────────────
''' <summary>Disegna il valore centrale nel gauge ad arco</summary>
Private Sub DrawCenterValue(g As Graphics, arcRect As Rectangle)
If _queue Is Nothing Then Return
Dim cx = arcRect.Left + arcRect.Width / 2.0F
Dim cy = arcRect.Top + arcRect.Height / 2.0F + 8
' Valore principale
Dim gaugeColor = GetCurrentColor()
Dim valueText = _queue.WaitTimeFormatted
Dim valueFont = New Font("Segoe UI", AppState.Instance.Config.GaugeValueFontSize, FontStyle.Bold)
Using valueBrush As New SolidBrush(gaugeColor)
Dim sz = g.MeasureString(valueText, valueFont)
g.DrawString(valueText, valueFont, valueBrush, cx - sz.Width / 2, cy - sz.Height / 2 - 4)
End Using
valueFont.Dispose()
' Sottotitolo "attesa"
Dim subFont = New Font("Segoe UI", 8, FontStyle.Regular)
Using subBrush As New SolidBrush(Color.FromArgb(140, 160, 180))
Dim subSz = g.MeasureString("attesa", subFont)
g.DrawString("attesa", subFont, subBrush, cx - subSz.Width / 2, cy + 8)
End Using
subFont.Dispose()
' Icona stato
DrawStatusIcon(g, cx, cy - 26)
End Sub
''' <summary>Disegna un'icona di stato (●) colorata</summary>
Private Sub DrawStatusIcon(g As Graphics, cx As Single, cy As Single)
If _queue Is Nothing Then Return
Dim color = GetCurrentColor()
Dim r = 4
Using dotBrush As New SolidBrush(color)
g.FillEllipse(dotBrush, cx - r, cy - r, r * 2, r * 2)
End Using
' Glow
Using glowBrush As New SolidBrush(Color.FromArgb(50, color))
g.FillEllipse(glowBrush, cx - r - 3, cy - r - 3, (r + 3) * 2, (r + 3) * 2)
End Using
End Sub
''' <summary>Disegna il valore a una coordinata specifica</summary>
Private Sub DrawValueAt(g As Graphics, cx As Single, cy As Single)
If _queue Is Nothing Then Return
Dim gaugeColor = GetCurrentColor()
Dim valueText = _queue.WaitTimeFormatted
Dim valueFont = New Font("Segoe UI", AppState.Instance.Config.GaugeValueFontSize, FontStyle.Bold)
Using valueBrush As New SolidBrush(gaugeColor)
Dim sz = g.MeasureString(valueText, valueFont)
g.DrawString(valueText, valueFont, valueBrush, cx - sz.Width / 2, cy - sz.Height / 2)
End Using
valueFont.Dispose()
End Sub
''' <summary>Disegna le etichette 0 e MAX dell'arco</summary>
Private Sub DrawArcLabels(g As Graphics, arcRect As Rectangle)
If _queue Is Nothing Then Return
Dim labelFont = New Font("Segoe UI", 7.5F, FontStyle.Regular)
Using labelBrush As New SolidBrush(Color.FromArgb(110, 130, 155))
' Label "0" in basso a sinistra
g.DrawString("0", labelFont, labelBrush, arcRect.Left - 8, arcRect.Bottom - 4)
' Label max in basso a destra
Dim maxText = $"{CInt(_queue.MaxWaitTime)}m"
Dim maxSz = g.MeasureString(maxText, labelFont)
g.DrawString(maxText, labelFont, labelBrush, arcRect.Right - maxSz.Width + 4, arcRect.Bottom - 4)
' Label soglia warning
Dim warnPct = _queue.WarningThreshold / _queue.MaxWaitTime
DrawArcThresholdMark(g, arcRect, warnPct, _colorWarning)
' Label soglia critica
Dim critPct = _queue.CriticalThreshold / _queue.MaxWaitTime
DrawArcThresholdMark(g, arcRect, critPct, _colorCritical)
End Using
labelFont.Dispose()
End Sub
''' <summary>Disegna un segno di soglia sull'arco</summary>
Private Sub DrawArcThresholdMark(g As Graphics, arcRect As Rectangle, pct As Double, color As Color)
Dim startAngle = 135.0
Dim sweepTotal = 270.0
Dim angle = (startAngle + sweepTotal * pct) * Math.PI / 180.0
Dim cx = arcRect.Left + arcRect.Width / 2.0
Dim cy = arcRect.Top + arcRect.Height / 2.0
Dim r = arcRect.Width / 2.0
Dim mx = CSng(cx + r * Math.Cos(angle))
Dim my = CSng(cy + r * Math.Sin(angle))
Using markPen As New Pen(Color.FromArgb(180, color), 2)
g.DrawLine(markPen, mx - 4, my - 4, mx + 4, my + 4)
g.DrawLine(markPen, mx + 4, my - 4, mx - 4, my + 4)
End Using
End Sub
''' <summary>Disegna segni di soglia sulla barra orizzontale</summary>
Private Sub DrawBarThresholds(g As Graphics, barRect As Rectangle)
If _queue Is Nothing Then Return
' Soglia warning
Dim warnX = CInt(barRect.Left + barRect.Width * _queue.WarningThreshold / _queue.MaxWaitTime)
If warnX < barRect.Right Then
Using warnPen As New Pen(Color.FromArgb(200, _colorWarning), 2)
g.DrawLine(warnPen, warnX, barRect.Top - 4, warnX, barRect.Bottom + 4)
End Using
End If
' Soglia critica
Dim critX = CInt(barRect.Left + barRect.Width * _queue.CriticalThreshold / _queue.MaxWaitTime)
If critX < barRect.Right Then
Using critPen As New Pen(Color.FromArgb(200, _colorCritical), 2)
g.DrawLine(critPen, critX, barRect.Top - 4, critX, barRect.Bottom + 4)
End Using
End If
End Sub
''' <summary>Disegna il nome della coda in fondo al controllo</summary>
Private Sub DrawQueueName(g As Graphics)
If _queue Is Nothing Then Return
Dim nameFont = New Font("Segoe UI", 9, FontStyle.Bold)
Using nameBrush As New SolidBrush(Color.FromArgb(180, 195, 215))
Dim nameText = _queue.Name
Dim nameSz = g.MeasureString(nameText, nameFont)
g.DrawString(nameText, nameFont, nameBrush,
(Width - nameSz.Width) / 2,
Height - nameSz.Height - 8)
End Using
nameFont.Dispose()
End Sub
' ─── Utility colori ──────────────────────────────────────
''' <summary>Scurisce un colore del fattore indicato (0-1)</summary>
Private Function DarkenColor(color As Color, factor As Double) As Color
Return Color.FromArgb(
color.A,
CInt(color.R * factor),
CInt(color.G * factor),
CInt(color.B * factor))
End Function
' ─── Aggiornamento dati ───────────────────────────────────
''' <summary>
''' Aggiorna il gauge con i nuovi dati della coda e rianima se necessario
''' </summary>
Public Sub RefreshData()
If _queue IsNot Nothing Then
AnimateTo(_queue.PercentageFull)
End If
End Sub
' ─── Cleanup ─────────────────────────────────────────────
Protected Overrides Sub Dispose(disposing As Boolean)
If disposing Then
_animTimer?.Stop()
_animTimer?.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
End Class
'End Namespace