Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineLightBulb.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing.Drawing2D;
2
4
13public class DreamineLightBulb : Control
14{
23 private bool _isOn;
32 private float _diameter = 96f;
33
42 public bool IsOn
43 {
44 get => _isOn;
45 set { _isOn = value; Invalidate(); }
46 }
47
56 public float Diameter
57 {
58 get => _diameter;
59 set { _diameter = Math.Max(32f, value); Invalidate(); }
60 }
61
71 {
72 SetStyle(
73 ControlStyles.AllPaintingInWmPaint |
74 ControlStyles.UserPaint |
75 ControlStyles.DoubleBuffer |
76 ControlStyles.ResizeRedraw |
77 ControlStyles.SupportsTransparentBackColor, true);
78
79 BackColor = Color.Transparent;
80 Size = new Size(150, 180);
81 }
82
99 protected override void OnPaint(PaintEventArgs e)
100 {
101 base.OnPaint(e);
102
103 var g = e.Graphics;
104 g.SmoothingMode = SmoothingMode.AntiAlias;
105
106 var d = Math.Min(_diameter, Math.Min(Width * .85f, Height * .62f));
107 var cx = Width / 2f;
108 var top = 4f;
109
110 var glassFill = _isOn ? Color.FromArgb(255, 214, 102) : Color.FromArgb(42, 100, 116, 139);
111 var glassStroke = _isOn ? Color.FromArgb(255, 196, 0) : Color.FromArgb(102, 117, 139);
112 var filament = _isOn ? Color.FromArgb(122, 75, 0) : Color.FromArgb(100, 116, 139);
113 var baseFill = Color.FromArgb(112, 128, 152);
114 using var glassPath = CreateGlassPath(cx, top, d);
115
116 if (_isOn)
117 {
118 using var glow = new SolidBrush(Color.FromArgb(70, 255, 214, 102));
119 g.FillEllipse(glow, cx - d * .62f, top + d * .50f - d * .62f, d * 1.24f, d * 1.24f);
120 }
121
122 using var fill = new SolidBrush(glassFill);
123 using var stroke = new Pen(glassStroke, 4);
124 g.FillPath(fill, glassPath);
125 g.DrawPath(stroke, glassPath);
126
127 using var filamentPen = new Pen(filament, 4)
128 {
129 StartCap = LineCap.Round,
130 EndCap = LineCap.Round
131 };
132 g.DrawBezier(filamentPen, cx - d * .22f, top + d * .56f, cx - d * .12f, top + d * .38f, cx - d * .02f, top + d * .72f, cx + d * .10f, top + d * .53f);
133 g.DrawBezier(filamentPen, cx + d * .10f, top + d * .53f, cx + d * .16f, top + d * .44f, cx + d * .21f, top + d * .49f, cx + d * .25f, top + d * .55f);
134
135 var neckTop = top + d * .92f;
136 using var baseBrush = new SolidBrush(baseFill);
137 g.FillPolygon(baseBrush, new[]
138 {
139 new PointF(cx - d * .30f, neckTop),
140 new PointF(cx + d * .30f, neckTop),
141 new PointF(cx + d * .20f, neckTop + d * .26f),
142 new PointF(cx - d * .20f, neckTop + d * .26f)
143 });
144 FillRib(g, baseBrush, cx, neckTop + d * .10f, d * .44f);
145 FillRib(g, baseBrush, cx, neckTop + d * .22f, d * .36f);
146 FillRib(g, baseBrush, cx, neckTop + d * .34f, d * .27f);
147 }
148
189 private static GraphicsPath CreateGlassPath(float cx, float top, float d)
190 {
191 var path = new GraphicsPath();
192 path.StartFigure();
193 path.AddBezier(cx, top + d * .02f, cx - d * .36f, top + d * .02f, cx - d * .52f, top + d * .27f, cx - d * .52f, top + d * .54f);
194 path.AddBezier(cx - d * .52f, top + d * .54f, cx - d * .52f, top + d * .74f, cx - d * .35f, top + d * .87f, cx - d * .25f, top + d * .96f);
195 path.AddLine(cx - d * .25f, top + d * .96f, cx + d * .25f, top + d * .96f);
196 path.AddBezier(cx + d * .25f, top + d * .96f, cx + d * .35f, top + d * .87f, cx + d * .52f, top + d * .74f, cx + d * .52f, top + d * .54f);
197 path.AddBezier(cx + d * .52f, top + d * .54f, cx + d * .52f, top + d * .27f, cx + d * .36f, top + d * .02f, cx, top + d * .02f);
198 path.CloseFigure();
199 return path;
200 }
201
250 private static void FillRib(Graphics g, Brush brush, float cx, float y, float width)
251 {
252 g.FillRectangle(brush, cx - width / 2f, y, width, 7f);
253 }
254}
static void FillRib(Graphics g, Brush brush, float cx, float y, float width)
static GraphicsPath CreateGlassPath(float cx, float top, float d)