Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineCheckLed.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
4
6
15public class DreamineCheckLed : Control
16{
25 private System.Windows.Forms.Timer? _pulseTimer;
34 private float _pulseAlpha = 1f;
43 private bool _pulseUp = false;
44
45 // ── Properties ────────────────────────────────────────
54 private bool _isOn = true;
63 public bool IsOn
64 {
65 get => _isOn;
66 set { _isOn = value; Invalidate(); }
67 }
68
77 private bool _isPulse;
86 public bool IsPulse
87 {
88 get => _isPulse;
89 set
90 {
91 _isPulse = value;
92 if (value) StartPulse();
93 else StopPulse();
94 Invalidate();
95 }
96 }
97
106 private LedCorner _corner = LedCorner.TopRight;
116 {
117 get => _corner;
118 set { _corner = value; Invalidate(); }
119 }
120
129 private float _diameter = 16f;
138 public float Diameter
139 {
140 get => _diameter;
141 set { _diameter = value; Invalidate(); }
142 }
143
144 // ── Constructor ───────────────────────────────────────
154 {
155 SetStyle(
156 ControlStyles.AllPaintingInWmPaint |
157 ControlStyles.UserPaint |
158 ControlStyles.DoubleBuffer |
159 ControlStyles.ResizeRedraw |
160 ControlStyles.SupportsTransparentBackColor, true);
161
162 BackColor = Color.Transparent;
163 Size = new Size(24, 24);
164 }
165
166 // ── Pulse ─────────────────────────────────────────────
175 private void StartPulse()
176 {
177 if (_pulseTimer == null)
178 {
179 _pulseTimer = new System.Windows.Forms.Timer { Interval = 40 };
180 _pulseTimer.Tick += OnPulseTick;
181 }
182 _pulseTimer.Start();
183 }
184
193 private void StopPulse()
194 {
195 if (_pulseTimer != null)
196 {
197 _pulseTimer.Stop();
198 _pulseTimer.Tick -= OnPulseTick;
199 }
200 _pulseAlpha = 1f;
201 Invalidate();
202 }
203
228 private void OnPulseTick(object? s, EventArgs e)
229 {
230 _pulseAlpha += _pulseUp ? 0.06f : -0.06f;
231 if (_pulseAlpha >= 1f) { _pulseAlpha = 1f; _pulseUp = false; }
232 if (_pulseAlpha <= 0.2f) { _pulseAlpha = 0.2f; _pulseUp = true; }
233 Invalidate();
234 }
235
252 protected override void Dispose(bool disposing)
253 {
254 if (disposing) { _pulseTimer?.Dispose(); _pulseTimer = null; }
255 base.Dispose(disposing);
256 }
257
258 // ── Paint ─────────────────────────────────────────────
275 protected override void OnPaint(PaintEventArgs e)
276 {
277 var g = e.Graphics;
278 g.SmoothingMode = SmoothingMode.AntiAlias;
279
280 float d = _diameter;
281 float x, y;
282
283 switch (_corner)
284 {
285 case LedCorner.TopLeft: x = 0; y = 0; break;
286 case LedCorner.TopRight: x = Width - d; y = 0; break;
287 case LedCorner.BottomLeft: x = 0; y = Height - d; break;
288 case LedCorner.BottomRight: x = Width - d; y = Height - d; break;
289 default: x = (Width - d)/2; y = (Height - d)/2; break;
290 }
291
292 var ledRect = new RectangleF(x, y, d, d);
293
294 if (_isOn)
295 {
296 float alpha = _isPulse ? _pulseAlpha : 1f;
297
298 // Outer glow ring
299 float glowD = d + 4;
300 var glowRect = new RectangleF(x - 2, y - 2, glowD, glowD);
301 using var glowBrush = new PathGradientBrush(DreamineDrawHelper.RoundedRect(glowRect, glowD / 2))
302 {
303 CenterColor = Color.FromArgb((int)(80 * alpha), DreamineTheme.LedOnOuter),
304 SurroundColors = new[] { Color.FromArgb(0, DreamineTheme.LedOnOuter) }
305 };
306 g.FillEllipse(glowBrush, glowRect);
307
308 // Outer ring
309 using var outerBrush = new PathGradientBrush(DreamineDrawHelper.RoundedRect(ledRect, d / 2))
310 {
311 CenterColor = Color.FromArgb((int)(220 * alpha), DreamineTheme.LedOnInner),
312 SurroundColors = new[] { Color.FromArgb((int)(160 * alpha), DreamineTheme.LedOnOuter) }
313 };
314 g.FillEllipse(outerBrush, ledRect);
315
316 // Inner highlight
317 float innerD = d * 0.45f;
318 float innerX = x + (d - innerD) / 2, innerY = y + (d - innerD) / 2;
319 using var innerBrush = new SolidBrush(Color.FromArgb((int)(120 * alpha), Color.White));
320 g.FillEllipse(innerBrush, innerX, innerY, innerD, innerD);
321 }
322 else
323 {
324 // Off: dim ring only
325 using var ringPen = new Pen(Color.FromArgb(80, DreamineTheme.LedOnOuter), 1.5f);
326 g.DrawEllipse(ringPen, ledRect.X, ledRect.Y, ledRect.Width - 1, ledRect.Height - 1);
327 using var centerBrush = new SolidBrush(Color.FromArgb(30, DreamineTheme.CardBackground));
328 g.FillEllipse(centerBrush, ledRect);
329 }
330 }
331}
static GraphicsPath RoundedRect(RectangleF r, float radius)
static readonly Color CardBackground