Dreamine.UI.Wpf.Controls 1.0.1
Dreamine.UI.Wpf.Controls 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineLightBulb.cs
이 파일의 문서화 페이지로 가기
1using System.Windows;
2using System.Windows.Media;
3
5
14public class DreamineLightBulb : FrameworkElement
15{
24 public static readonly DependencyProperty IsOnProperty =
25 DependencyProperty.Register(nameof(IsOn), typeof(bool), typeof(DreamineLightBulb),
26 new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
27
36 public static readonly DependencyProperty DiameterProperty =
37 DependencyProperty.Register(nameof(Diameter), typeof(double), typeof(DreamineLightBulb),
38 new FrameworkPropertyMetadata(96.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
39
48 public bool IsOn
49 {
50 get => (bool)GetValue(IsOnProperty);
51 set => SetValue(IsOnProperty, value);
52 }
53
62 public double Diameter
63 {
64 get => (double)GetValue(DiameterProperty);
65 set => SetValue(DiameterProperty, value);
66 }
67
92 protected override Size MeasureOverride(Size availableSize)
93 {
94 var d = Math.Max(32, Diameter);
95 return new Size(d * 1.25, d * 1.65);
96 }
97
122 protected override void OnRender(DrawingContext dc)
123 {
124 base.OnRender(dc);
125
126 var d = Math.Max(32, Diameter);
127 var cx = RenderSize.Width / 2;
128 var top = 2.0;
129 var glassFill = IsOn ? Color.FromRgb(255, 214, 102) : Color.FromArgb(42, 100, 116, 139);
130 var glassStroke = IsOn ? Color.FromRgb(255, 196, 0) : Color.FromRgb(102, 117, 139);
131 var filament = IsOn ? Color.FromRgb(122, 75, 0) : Color.FromRgb(100, 116, 139);
132 var baseFill = Color.FromRgb(112, 128, 152);
133 var glass = CreateGlassGeometry(cx, top, d);
134
135 if (IsOn)
136 {
137 dc.PushOpacity(0.35);
138 dc.DrawEllipse(new SolidColorBrush(Color.FromRgb(255, 214, 102)), null, new Point(cx, top + d * .50), d * .62, d * .62);
139 dc.Pop();
140 }
141
142 dc.DrawGeometry(
143 new SolidColorBrush(glassFill),
144 new Pen(new SolidColorBrush(glassStroke), 4),
145 glass);
146
147 var filamentGeometry = Geometry.Parse($"M {cx - d * .22:F1},{top + d * .56:F1} C {cx - d * .12:F1},{top + d * .38:F1} {cx - d * .02:F1},{top + d * .72:F1} {cx + d * .10:F1},{top + d * .53:F1} C {cx + d * .16:F1},{top + d * .44:F1} {cx + d * .21:F1},{top + d * .49:F1} {cx + d * .25:F1},{top + d * .55:F1}");
148 dc.DrawGeometry(null, new Pen(new SolidColorBrush(filament), 4) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }, filamentGeometry);
149
150 var neckTop = top + d * .92;
151 var neck = new StreamGeometry();
152 using (var ctx = neck.Open())
153 {
154 ctx.BeginFigure(new Point(cx - d * .30, neckTop), true, true);
155 ctx.LineTo(new Point(cx + d * .30, neckTop), true, false);
156 ctx.LineTo(new Point(cx + d * .20, neckTop + d * .26), true, false);
157 ctx.LineTo(new Point(cx - d * .20, neckTop + d * .26), true, false);
158 }
159 neck.Freeze();
160 dc.DrawGeometry(new SolidColorBrush(baseFill), null, neck);
161
162 DrawBaseRib(dc, cx, neckTop + d * .10, d * .44, baseFill);
163 DrawBaseRib(dc, cx, neckTop + d * .22, d * .36, baseFill);
164 DrawBaseRib(dc, cx, neckTop + d * .34, d * .27, baseFill);
165 }
166
207 private static StreamGeometry CreateGlassGeometry(double cx, double top, double d)
208 {
209 var geometry = new StreamGeometry();
210 using var ctx = geometry.Open();
211
212 ctx.BeginFigure(new Point(cx, top + d * .02), true, true);
213 ctx.BezierTo(new Point(cx - d * .36, top + d * .02), new Point(cx - d * .52, top + d * .27), new Point(cx - d * .52, top + d * .54), true, false);
214 ctx.BezierTo(new Point(cx - d * .52, top + d * .74), new Point(cx - d * .35, top + d * .87), new Point(cx - d * .25, top + d * .96), true, false);
215 ctx.LineTo(new Point(cx + d * .25, top + d * .96), true, false);
216 ctx.BezierTo(new Point(cx + d * .35, top + d * .87), new Point(cx + d * .52, top + d * .74), new Point(cx + d * .52, top + d * .54), true, false);
217 ctx.BezierTo(new Point(cx + d * .52, top + d * .27), new Point(cx + d * .36, top + d * .02), new Point(cx, top + d * .02), true, false);
218
219 geometry.Freeze();
220 return geometry;
221 }
222
271 private static void DrawBaseRib(DrawingContext dc, double cx, double y, double width, Color color)
272 {
273 var rect = new Rect(cx - width / 2, y, width, 7);
274 dc.DrawRoundedRectangle(new SolidColorBrush(color), null, rect, 3.5, 3.5);
275 }
276}
static void DrawBaseRib(DrawingContext dc, double cx, double y, double width, Color color)
static readonly DependencyProperty IsOnProperty
static readonly DependencyProperty DiameterProperty
override void OnRender(DrawingContext dc)
static StreamGeometry CreateGlassGeometry(double cx, double top, double d)
override Size MeasureOverride(Size availableSize)