原创:一个带阴影的Border(WPF控件)成品
该控件值得关注的属性有以下几个:
ShadowColor 获取或设置阴影的颜色
ShadowBrush 获取或设置阴影的画刷
上述两个属性当ShadowBrush不为null时使用ShadowBrush否则使用ShadowColor,一般使用ShadowColor效果好,使用ShadowBrush不容易控制效果
ShadowLightArc 获取或设置光源照射角度(顺时针,以度为单位) >=0且<90度表示从左上角照射 >=90且<180表示从右上角照射 >=180且<270表示从右下角照射 >=270且小于360表示从左下角照射
ShadowWidth 获取或设置阴影斜长,该属性同ShadowLightArc属性共同确定X方向和Y方向的阴影宽度
下面几个属性同Border控件属性一样:
BorderCornerRadius(等同Border控件的CornerRadius属性)
Background
BorderBrush
BorderThickness
Padding
好了,下面是代码,可直编译使用,编译后拖到一个窗口上看看效果,哈哈,是不是有阴影效果呢,转载请注明本出处
ShadowBorder
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Controls;
6 using System.Windows;
7 using System.Windows.Media;
8
9 namespace YZKFrame.Controls.WpfControls
10 {
11 /// <summary>
12 /// 带阴影的边框
13 /// </summary>
14 public class ShadowBorder : Decorator
15 {
16
17 static ShadowBorder()
18 {
19
20 DefaultStyleKeyProperty.OverrideMetadata(
21 typeof(ShadowBorder),
22 new FrameworkPropertyMetadata(typeof(ShadowBorder)));
23
24 ShadowLightArcProperty = DependencyProperty.Register(
25 "ShadowLightArc", typeof(double), typeof(ShadowBorder),
26 new FrameworkPropertyMetadata((double)45,
27 FrameworkPropertyMetadataOptions.AffectsRender
28 | FrameworkPropertyMetadataOptions.AffectsArrange
29 | FrameworkPropertyMetadataOptions.AffectsMeasure));
30
31 ShadowWidthProperty = DependencyProperty.Register(
32 "ShadowWidth", typeof(double), typeof(ShadowBorder),
33 new FrameworkPropertyMetadata((double)4,
34 FrameworkPropertyMetadataOptions.AffectsRender
35 | FrameworkPropertyMetadataOptions.AffectsArrange
36 | FrameworkPropertyMetadataOptions.AffectsMeasure));
37
38 ShadowBrushProperty = DependencyProperty.Register(
39 "ShadowBrush", typeof(Brush), typeof(ShadowBorder),
40 new FrameworkPropertyMetadata(null,
41 FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender
42 | FrameworkPropertyMetadataOptions.AffectsRender));
43
44 BorderCornerRadiusProperty = DependencyProperty.Register(
45 "BorderCornerRadius", typeof(CornerRadius), typeof(ShadowBorder),
46 new FrameworkPropertyMetadata(new CornerRadius(4),
47 FrameworkPropertyMetadataOptions.AffectsRender
48 | FrameworkPropertyMetadataOptions.AffectsArrange
49 | FrameworkPropertyMetadataOptions.AffectsMeasure));
50
51
52 BackgroundProperty =
53 Panel.BackgroundProperty.AddOwner(typeof(ShadowBorder),
54 new FrameworkPropertyMetadata(null,
55 FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender
56 | FrameworkPropertyMetadataOptions.AffectsRender));
57
58 BorderBrushProperty =
59 DependencyProperty.Register("BorderBrush", typeof(Brush),
60 typeof(ShadowBorder), new FrameworkPropertyMetadata(new SolidColorBrush(Color.FromArgb(255,100,100,100)),
61 FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender
62 | FrameworkPropertyMetadataOptions.AffectsRender));
63
64 BorderThicknessProperty =
65 DependencyProperty.Register("BorderThickness", typeof(Thickness),
66 typeof(ShadowBorder),
67 new FrameworkPropertyMetadata(new Thickness(1),
68 FrameworkPropertyMetadataOptions.AffectsRender
69 | FrameworkPropertyMetadataOptions.AffectsMeasure,
70 new PropertyChangedCallback(ShadowBorder.OnBorderThicknessChanged)),
71 new ValidateValueCallback(ShadowBorder.IsThicknessValid));
72
73 PaddingProperty =
74 DependencyProperty.Register("Padding",
75 typeof(Thickness), typeof(ShadowBorder),
76 new FrameworkPropertyMetadata(new Thickness(),
77 FrameworkPropertyMetadataOptions.AffectsRender
78 | FrameworkPropertyMetadataOptions.AffectsMeasure),
79 new ValidateValueCallback(ShadowBorder.IsThicknessValid));
80
81 MeasureDataProperty = DependencyProperty.Register(
82 "MeasureData", typeof(ShadowBorderMeasureData),
83 typeof(ShadowBorder),
84 new FrameworkPropertyMetadata(new ShadowBorderMeasureData(),
85 FrameworkPropertyMetadataOptions.None));
86
87 BorderGeometryCacheProperty = DependencyProperty.Register(
88 "BorderGeometryCache", typeof(StreamGeometry), typeof(ShadowBorder),
89 new FrameworkPropertyMetadata(null,
90 FrameworkPropertyMetadataOptions.None));
91
92 X_ShadowGeometryCacheProperty = DependencyProperty.Register(
93 "X_ShadowGeometryCache", typeof(Geometry), typeof(ShadowBorder),
94 new FrameworkPropertyMetadata(null,
95 FrameworkPropertyMetadataOptions.None));
96
97 Y_ShadowGeometryCacheProperty = DependencyProperty.Register(
98 "Y_ShadowGeometryCache", typeof(Geometry), typeof(ShadowBorder),
99 new FrameworkPropertyMetadata(null,
100 FrameworkPropertyMetadataOptions.None));
101
102 BackgroundGeometryCacheProperty = DependencyProperty.Register(
103 "BackgroundGeometryCache", typeof(Geometry), typeof(ShadowBorder),
104 new FrameworkPropertyMetadata(null,
105 FrameworkPropertyMetadataOptions.None));
106
107 X_ShadowBrushCacheProperty =
108 DependencyProperty.Register("X_ShadowBrushCache", typeof(Brush),
109 typeof(ShadowBorder), new FrameworkPropertyMetadata(null,
110 FrameworkPropertyMetadataOptions.None));
111
112 Y_ShadowBrushCacheProperty =
113 DependencyProperty.Register("Y_ShadowBrushCache", typeof(Brush),
114 typeof(ShadowBorder), new FrameworkPropertyMetadata(null,
115 FrameworkPropertyMetadataOptions.None));
116
117 ShadowColorProperty =
118 DependencyProperty.Register("ShadowColor", typeof(Color),
119 typeof(ShadowBorder), new FrameworkPropertyMetadata(Color.FromArgb(255,146,146,146),
120 FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender
121 | FrameworkPropertyMetadataOptions.AffectsRender,
122 new PropertyChangedCallback(ShadowBorder.OnShadowColorChanged)));
123 }
124
125 #region 属性依赖项
126
127 public static readonly DependencyProperty ShadowBrushProperty;
128
129 public static readonly DependencyProperty ShadowLightArcProperty;
130
131 public static readonly DependencyProperty ShadowWidthProperty;
132
133 public static readonly DependencyProperty BorderCornerRadiusProperty;
134
135 public static readonly DependencyProperty BackgroundProperty;
136
137 public static readonly DependencyProperty BorderBrushProperty;
138
139 public static readonly DependencyProperty BorderThicknessProperty;
140
141 public static readonly DependencyProperty PaddingProperty;
142
143 public static readonly DependencyProperty MeasureDataProperty;
144
145 public static readonly DependencyProperty ShadowColorProperty;
146
147 private static readonly DependencyProperty BorderGeometryCacheProperty;
148
149 private static readonly DependencyProperty X_ShadowGeometryCacheProperty;
150
151 private static readonly DependencyProperty Y_ShadowGeometryCacheProperty;
152
153 private static readonly DependencyProperty BackgroundGeometryCacheProperty;
154
155 private static readonly DependencyProperty X_ShadowBrushCacheProperty;
156
157 private static readonly DependencyProperty Y_ShadowBrushCacheProperty;
158
159 #endregion
160
161 #region 私有静态方法
162
163 private static bool IsThicknessValid(object value)
164 {
165 Thickness thickness = (Thickness)value;
166 return thickness.IsValid(false, false, false, false);
167 }
168
169 private static void OnBorderThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
170 {
171 }
172
173 private static void OnShadowColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
174 {
175 ShadowBorder border = (ShadowBorder)d;
176 border.OnShadowColorChanged((Color)e.NewValue, (Color)e.OldValue);
177 }
178
179 #endregion
180
181 #region 属性
182
183 #region 私有
184
185 private ShadowBorderMeasureData MeasureData
186 {
187 get
188 {
189 return (ShadowBorderMeasureData)GetValue(MeasureDataProperty);
190 }
191 }
192
193 private StreamGeometry BorderGeometryCache
194 {
195 get { return (StreamGeometry)GetValue(BorderGeometryCacheProperty); }
196 set { SetValue(BorderGeometryCacheProperty, value); }
197 }
198
199 private Geometry X_ShadowGeometryCache
200 {
201 get { return (Geometry)GetValue(X_ShadowGeometryCacheProperty); }
202 set { SetValue(X_ShadowGeometryCacheProperty, value); }
203 }
204
205 private Geometry Y_ShadowGeometryCache
206 {
207 get { return (Geometry)GetValue(Y_ShadowGeometryCacheProperty); }
208 set { SetValue(Y_ShadowGeometryCacheProperty, value); }
209 }
210
211 private Geometry BackgroundGeometryCache
212 {
213 get { return (Geometry)GetValue(BackgroundGeometryCacheProperty); }
214 set { SetValue(BackgroundGeometryCacheProperty, value); }
215 }
216
217 private Brush X_ShadowBrushCache
218 {
219 get
220 {
221 return (Brush)base.GetValue(X_ShadowBrushCacheProperty);
222 }
223 set
224 {
225 base.SetValue(X_ShadowBrushCacheProperty, value);
226 }
227 }
228
229 private Brush Y_ShadowBrushCache
230 {
231 get
232 {
233 return (Brush)base.GetValue(Y_ShadowBrushCacheProperty);
234 }
235 set
236 {
237 base.SetValue(Y_ShadowBrushCacheProperty, value);
238 }
239 }
240 #endregion
241
242 #region 公有
243 /// <summary>
244 /// 获取或设置阴影颜色属性
245 /// </summary>
246 public Color ShadowColor
247 {
248 get { return (Color)GetValue(ShadowColorProperty); }
249 set { SetValue(ShadowColorProperty, value); }
250 }
251 /// <summary>
252 /// 获取或设置阴影画刷
253 /// </summary>
254 public Brush ShadowBrush
255 {
256 get
257 {
258 return (Brush)base.GetValue(ShadowBrushProperty);
259 }
260 set
261 {
262 base.SetValue(ShadowBrushProperty, value);
263 }
264 }
265 /// <summary>
266 /// 获取或设置阴影光源照射的角度:相对于x轴顺时针角度,度为单位
267 /// </summary>
268 public double ShadowLightArc
269 {
270 get
271 {
272 return (double)base.GetValue(ShadowLightArcProperty);
273 }
274 set
275 {
276 base.SetValue(ShadowLightArcProperty, value);
277 }
278 }
279 /// <summary>
280 /// 获取或设置阴影宽度
281 /// </summary>
282 public double ShadowWidth
283 {
284 get
285 {
286 return (double)base.GetValue(ShadowWidthProperty);
287 }
288 set
289 {
290 base.SetValue(ShadowWidthProperty, value);
291 }
292 }
293 /// <summary>
294 /// 获取或设置边框的倒角
295 /// </summary>
296 public CornerRadius BorderCornerRadius
297 {
298 get
299 {
300 return (CornerRadius)base.GetValue(BorderCornerRadiusProperty);
301 }
302 set
303 {
304 base.SetValue(BorderCornerRadiusProperty, value);
305 }
306 }
307
308 public Brush Background
309 {
310 get
311 {
312 return (Brush)base.GetValue(BackgroundProperty);
313 }
314 set
315 {
316 base.SetValue(BackgroundProperty, value);
317 }
318 }
319
320 public Brush BorderBrush
321 {
322 get
323 {
324 return (Brush)base.GetValue(BorderBrushProperty);
325 }
326 set
327 {
328 base.SetValue(BorderBrushProperty, value);
329 }
330 }
331
332 public Thickness BorderThickness
333 {
334 get
335 {
336 return (Thickness)base.GetValue(BorderThicknessProperty);
337 }
338 set
339 {
340 base.SetValue(BorderThicknessProperty, value);
341 }
342 }
343
344 public Thickness Padding
345 {
346 get
347 {
348 return (Thickness)base.GetValue(PaddingProperty);
349 }
350 set
351 {
352 base.SetValue(PaddingProperty, value);
353 }
354 }
355 #endregion
356
357 #endregion
358
359 #region 私有方法
360
361 protected virtual void OnShadowColorChanged(Color newcolor,Color oldcolor)
362 {
363 Brush x_b;
364 Brush y_b;
365 MeasureData.SetShadowBrush(ShadowLightArc,
366 ShadowColor, out x_b, out y_b);
367 X_ShadowBrushCache = x_b;
368 Y_ShadowBrushCache = y_b;
369 }
370
371 #endregion
372
373 #region 已重载方法
374
375 protected override Size MeasureOverride(Size constraint)
376 {
377 ShadowBorderMeasureData measuredata = MeasureData;
378 measuredata.MeasureData(constraint,
379 ShadowWidth,
380 ShadowLightArc,
381 BorderCornerRadius,
382 BorderThickness,
383 Padding);
384 base.MeasureOverride(measuredata.ChildSize);
385 return constraint;
386 }
387
388 protected override Size ArrangeOverride(Size arrangeSize)
389 {
390 ShadowBorderMeasureData measuredata = MeasureData;
391 measuredata.ArrangeData(arrangeSize,
392 ShadowWidth,
393 ShadowLightArc,
394 BorderCornerRadius,
395 BorderThickness,
396 Padding);
397 UIElement child = this.Child;
398 if (child != null)
399 child.Arrange(measuredata.ChildRect);
400 StreamGeometry back = new StreamGeometry();
401 using (StreamGeometryContext context = back.Open())
402 {
403 measuredata.SetBackgroundGeometry(context);
404 }
405 back.Freeze();
406 BackgroundGeometryCache = back;
407 if (measuredata.HasBorder)
408 {
409 StreamGeometry x = new StreamGeometry();
410 using (StreamGeometryContext context = x.Open())
411 {
412 measuredata.SetBorderGeometry(context);
413 }
414 x.Freeze();
415 BorderGeometryCache = x;
416 }
417 else
418 BorderGeometryCache = null;
419 if (measuredata.HasShadow)
420 {
421 Geometry x_shadow;
422 Geometry y_shadow;
423 measuredata.GetShadowGeometry(out x_shadow, out y_shadow);
424 if (x_shadow != null && x_shadow.CanFreeze)
425 x_shadow.Freeze();
426 if (y_shadow != null && y_shadow.CanFreeze)
427 y_shadow.Freeze();
428 X_ShadowGeometryCache = x_shadow;
429 Y_ShadowGeometryCache = y_shadow;
430 Brush x_b;
431 Brush y_b;
432 measuredata.SetShadowBrush(ShadowLightArc,
433 ShadowColor, out x_b, out y_b);
434 X_ShadowBrushCache = x_b;
435 Y_ShadowBrushCache = y_b;
436 }
437 else
438 {
439 X_ShadowGeometryCache = null;
440 Y_ShadowGeometryCache = null;
441 X_ShadowBrushCache = null;
442 Y_ShadowBrushCache = null;
443 }
444 return arrangeSize;
445 }
446
447 protected override void OnRender(DrawingContext drawingContext)
448 {
449 base.OnRender(drawingContext);
450 if (Background != null && BackgroundGeometryCache != null)
451 {
452 drawingContext.DrawGeometry(
453 Background, null, BackgroundGeometryCache);
454 }
455 if (MeasureData.HasShadow)
456 {
457 Brush shadowb = ShadowBrush;
458 if (shadowb != null)
459 {
460 Geometry y_shadow = Y_ShadowGeometryCache;
461 if (y_shadow != null)
462 {
463 drawingContext.DrawGeometry(
464 shadowb, null, y_shadow);
465 }
466 Geometry x_shadow = X_ShadowGeometryCache;
467 if (x_shadow != null)
468 {
469 drawingContext.DrawGeometry(
470 shadowb, null, x_shadow);
471 }
472 }
473 else
474 {
475 Brush x_b = X_ShadowBrushCache;
476 Brush y_b = Y_ShadowBrushCache;
477 if (x_b == null || y_b == null)
478 {
479 MeasureData.SetShadowBrush(ShadowLightArc,
480 ShadowColor, out x_b, out y_b);
481 X_ShadowBrushCache = x_b;
482 Y_ShadowBrushCache = y_b;
483 }
484 Geometry x_shadow = X_ShadowGeometryCache;
485 if (x_shadow != null)
486 {
487 drawingContext.DrawGeometry(
488 x_b, null, x_shadow);
489 }
490 Geometry y_shadow = Y_ShadowGeometryCache;
491 if (y_shadow != null)
492 {
493 drawingContext.DrawGeometry(
494 y_b, null, y_shadow);
495 }
496 }
497 }
498 StreamGeometry border = BorderGeometryCache;
499 if (border != null)
500 {
501 drawingContext.DrawGeometry(
502 BorderBrush, null, border);
503 }
504
505
506 }
507
508 #endregion
509
510 #region 私有类
511
512 private class ShadowBorderMeasureData
513 {
514
515 internal ShadowBorderMeasureData()
516 {
517 g_ShadowLightPosition = MeasureShadowLightPosition.None;
518 g_Dy = 0;
519 g_Dy = 0;
520 p_ShadowBorderInnerSize = new Size();
521 p_ShadowBorderOuterSize = new Size();
522 p_BorderInnerSize = new Size();
523 p_ChildSize = new Size();
524 g_BorderCornerRadius = new CornerRadius();
525 p_ShadowBorderOuterRect = new Rect();
526 p_ShadowBorderInnerRect = new Rect();
527 p_BorderInnerRect = new Rect();
528 p_ChildRect = new Rect();
529 g_LightArc = 0;
530 }
531
532 private MeasureShadowLightPosition g_ShadowLightPosition;/*阴影光源的位置*/
533
534 private double g_Dx;/*X轴偏移量*/
535 private double g_Dy;/*Y轴偏移量*/
536 private double g_LightArc;/*光源角度*/
537 private Size p_ShadowBorderOuterSize;/*所有外围大小*/
538 private Size p_ShadowBorderInnerSize;/*除去阴影部份的外围大小*/
539 private Size p_BorderInnerSize;/*除去阴影部份和边框部份的外围大小*/
540 private Size p_ChildSize;/*子控件可用的大小*/
541 private CornerRadius g_BorderCornerRadius;/*边框倒角*/
542
543 private Rect p_ShadowBorderOuterRect;/*所有外围区域*/
544 private Rect p_ShadowBorderInnerRect;/*除去阴影部份的外围区域*/
545 private Rect p_BorderInnerRect;/*除去阴影部份和边框部份的外围区域*/
546 private Rect p_ChildRect;/*子控件可用的区域*/
547
548 internal void MeasureData(
549 Size constraint,
550 double shadowwidth,
551 double lightarc,
552 CornerRadius bordercornerradius,
553 Thickness borderthickness,
554 Thickness padding)
555 {
556 p_ShadowBorderOuterSize.Width = constraint.Width;
557 p_ShadowBorderOuterSize.Height = constraint.Height;
558 bool b = (shadowwidth > 0 && lightarc >= 0);
559 g_BorderCornerRadius.TopLeft = bordercornerradius.TopLeft;
560 g_BorderCornerRadius.TopRight = bordercornerradius.TopRight;
561 g_BorderCornerRadius.BottomLeft = bordercornerradius.BottomLeft;
562 g_BorderCornerRadius.BottomRight = bordercornerradius.BottomRight;
563 if (b)
564 {
565 ResetDxDy(shadowwidth, lightarc);
566 p_ShadowBorderInnerSize.Width =
567 p_ShadowBorderOuterSize.Width - g_Dx;
568 p_ShadowBorderInnerSize.Height =
569 p_ShadowBorderOuterSize.Height - g_Dy;
570 }
571 else
572 {
573 g_ShadowLightPosition = MeasureShadowLightPosition.None;
574 g_Dx = 0;
575 g_Dy = 0;
576 p_ShadowBorderInnerSize.Width = constraint.Width;
577 p_ShadowBorderInnerSize.Height = constraint.Height;
578 }
579 p_BorderInnerSize.Width =
580 p_ShadowBorderInnerSize.Width -
581 borderthickness.Left -
582 borderthickness.Right;
583 p_BorderInnerSize.Height =
584 p_ShadowBorderInnerSize.Height -
585 borderthickness.Top -
586 borderthickness.Bottom;
587 p_ChildSize.Width = p_BorderInnerSize.Width -
588 padding.Left - padding.Right;
589 p_ChildSize.Height = p_BorderInnerSize.Height -
590 padding.Top - padding.Bottom;
591 }
592
593 internal Size ChildSize
594 {
595 get { return p_ChildSize; }
596 }
597
598 internal Rect ChildRect
599 {
600 get { return p_ChildRect; }
601 }
602
603 internal Rect ShadowBorderOuterRect
604 {
605 get { return p_ShadowBorderOuterRect; }
606 }
607
608 internal Rect ShadowBorderInnerRect
609 {
610 get { return p_ShadowBorderInnerRect; }
611 }
612
613 internal bool HasShadow
614 {
615 get { return g_ShadowLightPosition != MeasureShadowLightPosition.None; }
616 }
617
618 internal void ArrangeData(
619 Size constraint,
620 double shadowwidth,
621 double lightarc,
622 CornerRadius bordercornerradius,
623 Thickness borderthickness,
624 Thickness padding)
625 {
626 MeasureData(constraint,
627 shadowwidth, lightarc, bordercornerradius,
628 borderthickness, padding);
629 p_ShadowBorderOuterRect.Width = p_ShadowBorderOuterSize.Width;
630 p_ShadowBorderOuterRect.Height = p_ShadowBorderOuterSize.Height;
631 p_ShadowBorderInnerRect.Width = p_ShadowBorderInnerSize.Width;
632 p_ShadowBorderInnerRect.Height = p_ShadowBorderInnerSize.Height;
633 switch (g_ShadowLightPosition)
634 {
635 case MeasureShadowLightPosition.None:
636 case MeasureShadowLightPosition.LeftTop:
637 {
638 p_ShadowBorderInnerRect.X = p_ShadowBorderOuterRect.X;
639 p_ShadowBorderInnerRect.Y = p_ShadowBorderOuterRect.Y;
640 break;
641 }
642 case MeasureShadowLightPosition.RightTop:
643 {
644 p_ShadowBorderInnerRect.X = p_ShadowBorderOuterRect.X + g_Dx;
645 p_ShadowBorderInnerRect.Y = p_ShadowBorderOuterRect.Y;
646 break;
647 }
648 case MeasureShadowLightPosition.RightBottom:
649 {
650 p_ShadowBorderInnerRect.X = p_ShadowBorderOuterRect.X + g_Dx;
651 p_ShadowBorderInnerRect.Y = p_ShadowBorderOuterRect.Y + g_Dy;
652 break;
653 }
654 case MeasureShadowLightPosition.LeftBottom:
655 {
656 p_ShadowBorderInnerRect.X = p_ShadowBorderOuterRect.X;
657 p_ShadowBorderInnerRect.Y = p_ShadowBorderOuterRect.Y + g_Dy;
658 break;
659 }
660 }
661 p_BorderInnerRect.Width = p_BorderInnerSize.Width;
662 p_BorderInnerRect.Height = p_BorderInnerSize.Height;
663 p_BorderInnerRect.X = p_ShadowBorderInnerRect.X + borderthickness.Left;
664 p_BorderInnerRect.Y = p_ShadowBorderInnerRect.Y + borderthickness.Top;
665 p_ChildRect.Width = p_ChildSize.Width;
666 p_ChildRect.Height = p_ChildSize.Height;
667 p_ChildRect.X = p_BorderInnerRect.X + padding.Left;
668 p_ChildRect.Y = p_BorderInnerRect.Y + padding.Top;
669 }
670
671 internal bool HasBorder
672 {
673 get
674 {
675 return (p_ShadowBorderInnerSize.Width >
676 p_BorderInnerSize.Width &&
677 p_ShadowBorderInnerSize.Height >
678 p_BorderInnerSize.Height);
679 }
680 }
681
682 internal void SetBackgroundGeometry(StreamGeometryContext ctx)
683 {
684 SetBorderGeometry(ctx, p_BorderInnerRect);
685 }
686
687 internal void SetBorderGeometry(StreamGeometryContext ctx)
688 {
689 SetBorderGeometry(ctx, p_ShadowBorderInnerRect);
690 SetBorderGeometry(ctx, p_BorderInnerRect);
691 }
692
693 internal void GetShadowGeometry(out Geometry x_shadow,out Geometry y_shadow)
694 {
695 Rect vx = new Rect(
696 p_ShadowBorderInnerRect.X,
697 p_ShadowBorderInnerRect.Y,
698 p_ShadowBorderInnerRect.Width,
699 p_ShadowBorderInnerRect.Height);
700 Point[] joinpoints = null;
701 switch (g_ShadowLightPosition)
702 {
703 case MeasureShadowLightPosition.LeftTop:
704 {
705 vx.X += g_Dx;
706 vx.Y += g_Dy;
707 joinpoints = GetBorderJoinPoints(p_ShadowBorderInnerRect,
708 vx);
709 break;
710 }
711 case MeasureShadowLightPosition.RightTop:
712 {
713 vx.X -= g_Dx;
714 vx.Y += g_Dy;
715 joinpoints = GetBorderJoinPoints(p_ShadowBorderInnerRect, vx);
716 break;
717 }
718 case MeasureShadowLightPosition.RightBottom:
719 {
720 vx.X -= g_Dx;
721 vx.Y -= g_Dy;
722 joinpoints = GetBorderJoinPoints(vx, p_ShadowBorderInnerRect);
723 break;
724 }
725 case MeasureShadowLightPosition.LeftBottom:
726 {
727 vx.X += g_Dx;
728 vx.Y -= g_Dy;
729 joinpoints = GetBorderJoinPoints(vx, p_ShadowBorderInnerRect);
730 break;
731 }
732 }
733 StreamGeometry border1 = new StreamGeometry();
734 border1.FillRule = FillRule.EvenOdd;
735 using (StreamGeometryContext context = border1.Open())
736 {
737 SetBorderGeometry(context, p_ShadowBorderInnerRect);
738 }
739 if (border1.CanFreeze)
740 border1.Freeze();
741 StreamGeometry border2 = new StreamGeometry();
742 border2.FillRule = FillRule.EvenOdd;
743 using (StreamGeometryContext context = border2.Open())
744 {
745 SetBorderGeometry(context, vx);
746 }
747 if (border2.CanFreeze)
748 border2.Freeze();
749 PathGeometry p = Geometry.Combine(border1, border2, GeometryCombineMode.Union,
750 null);
751 if (!(g_LightArc == 0 ||
752 g_LightArc == 90 ||
753 g_LightArc == 180 ||
754 g_LightArc == 270)
755 && joinpoints != null)
756 {
757 StreamGeometry border3 = new StreamGeometry();
758 using (StreamGeometryContext context = border3.Open())
759 {
760 context.BeginFigure(joinpoints[0], true, true);
761 context.LineTo(joinpoints[1], true, false);
762 context.LineTo(joinpoints[2], true, false);
763 context.LineTo(joinpoints[3], true, true);
764 }
765 if (border3.CanFreeze)
766 border3.Freeze();
767 p = Geometry.Combine(p, border3, GeometryCombineMode.Union, null);
768 }
769 p = Geometry.Combine(p, border1, GeometryCombineMode.Exclude, null);
770 SplitGeometty(p,out x_shadow, out y_shadow);
771 }
772 internal void SetShadowBrush(
773 double lightarc, Color shadowcolor, out Brush x_brush, out Brush y_brush)
774 {
775 x_brush = null;
776 y_brush = null;
777 double fgd = StandardHelpMethod.HjFgPoint;
778 byte a = (byte)(255 * fgd);
779 Color startcolor = shadowcolor;
780 Color fgdcolor=Color.FromArgb(
781 a,shadowcolor.R,shadowcolor.G,shadowcolor.B);
782 Color endcolor = Color.FromArgb(0,
783 shadowcolor.R, shadowcolor.G, shadowcolor.B);
784 Point x_startpoint = new Point();
785 Point x_endpoint = new Point();
786 Point y_startpoint = new Point();
787 Point y_endpoint = new Point();
788 MeasureShadowLightPosition pos = GetLightPosition(lightarc);
789 switch (pos)
790 {
791 case MeasureShadowLightPosition.LeftTop:
792 {
793 x_startpoint = new Point();
794 x_endpoint = new Point(0, 1);
795 y_startpoint = new Point();
796 y_endpoint = new Point(1, 0);
797 break;
798 }
799 case MeasureShadowLightPosition.LeftBottom:
800 {
801 x_startpoint = new Point(0, 1);
802 x_endpoint = new Point(0, 0);
803 y_startpoint = new Point(0, 0);
804 y_endpoint = new Point(1, 0);
805 break;
806 }
807 case MeasureShadowLightPosition.RightTop:
808 {
809 x_startpoint = new Point();
810 x_endpoint = new Point(0, 1);
811 y_startpoint = new Point(1, 0);
812 y_endpoint = new Point(0, 0);
813 break;
814 }
815 case MeasureShadowLightPosition.RightBottom:
816 {
817 x_startpoint = new Point(0, 1);
818 x_endpoint = new Point(0, 0);
819 y_startpoint = new Point(1, 0);
820 y_endpoint = new Point(0, 0);
821 break;
822 }
823 }
824 GradientStopCollection stops = new GradientStopCollection();
825 stops.Add(new GradientStop(startcolor, 0));
826 stops.Add(new GradientStop(fgdcolor, fgd));
827 stops.Add(new GradientStop(endcolor, 1));
828 x_brush = new LinearGradientBrush(stops)
829 {
830 StartPoint = x_startpoint,
831 EndPoint = x_endpoint
832 };
833 y_brush = new LinearGradientBrush(stops)
834 {
835 StartPoint = y_startpoint,
836 EndPoint = y_endpoint
837 };
838 }
839
840 private MeasureShadowLightPosition GetLightPosition(double lightarc)
841 {
842 double arc = GetArc(lightarc);
843 MeasureShadowLightPosition lp = MeasureShadowLightPosition.None;
844 if (arc >= 0 && arc < 90)
845 lp = MeasureShadowLightPosition.LeftTop;
846 else if (arc >= 90 && arc < 180)
847 {
848 lp = MeasureShadowLightPosition.RightTop;
849 arc = 180 - arc;
850 }
851 else if (arc >= 180 && arc < 270)
852 {
853 lp = MeasureShadowLightPosition.RightBottom;
854 arc -= 180;
855 }
856 else if (arc >= 270 && arc < 360)
857 lp = MeasureShadowLightPosition.LeftBottom;
858 return lp;
859 }
860
861 private void SplitGeometty(PathGeometry shadow,out Geometry shadow_x,out Geometry shadow_y)
862 {
863 switch (g_ShadowLightPosition)
864 {
865 case MeasureShadowLightPosition.RightBottom:
866 {
867 SplitGeometty_RightBottom(shadow, out shadow_x, out shadow_y);
868 break;
869 }
870 case MeasureShadowLightPosition.LeftTop:
871 {
872 SplitGeometty_LeftTop(shadow, out shadow_x, out shadow_y);
873 break;
874 }
875 case MeasureShadowLightPosition.LeftBottom:
876 {
877 SplitGeometty_LeftBottom(shadow, out shadow_x, out shadow_y);
878 break;
879 }
880 case MeasureShadowLightPosition.RightTop:
881 {
882 SplitGeometty_RightTop(shadow, out shadow_x, out shadow_y);
883 break;
884 }
885 default:
886 {
887 shadow_x = null;
888 shadow_y = null;
889 break;
890 }
891 }
892 }
893
894 private void SplitGeometty_LeftTop(PathGeometry shadow, out Geometry shadow_x, out Geometry shadow_y)
895 {
896 if (g_LightArc == 0)
897 {
898 shadow_y = shadow;
899 shadow_x = null;
900 return;
901 }
902 double arc = g_LightArc * (Math.PI / 180);
903 double dy = p_ShadowBorderOuterRect.Width * (Math.Sin(arc) / Math.Cos(arc));
904 Point xstartpoint = p_ShadowBorderOuterRect.BottomLeft + new Vector(0, 0 - dy);
905 StreamGeometry xg = new StreamGeometry();
906 using (StreamGeometryContext context = xg.Open())
907 {
908 context.BeginFigure(xstartpoint, true, true);
909 context.LineTo(p_ShadowBorderOuterRect.BottomLeft, true, false);
910 context.LineTo(p_ShadowBorderOuterRect.BottomRight, true, false);
911 }
912 xg.Freeze();
913 StreamGeometry yg = new StreamGeometry();
914 using (StreamGeometryContext context = yg.Open())
915 {
916 context.BeginFigure(xstartpoint, true, true);
917 if (!DoubleUtil.AreClose(xstartpoint,
918 p_ShadowBorderOuterRect.TopLeft))
919 {
920 context.LineTo(p_ShadowBorderOuterRect.TopLeft, true, false);
921 }
922 context.LineTo(p_ShadowBorderOuterRect.TopRight, true, false);
923 context.LineTo(p_ShadowBorderOuterRect.BottomRight, true, false);
924 }
925 yg.Freeze();
926 shadow_x = Geometry.Combine(
927 xg, shadow, GeometryCombineMode.Intersect, null);
928 shadow_y = Geometry.Combine(
929 yg, shadow, GeometryCombineMode.Intersect, null);
930 }
931
932 private void SplitGeometty_RightBottom(PathGeometry shadow, out Geometry shadow_x, out Geometry shadow_y)
933 {
934 if (g_LightArc == 180)
935 {
936 shadow_y = shadow;
937 shadow_x = null;
938 return;
939 }
940 double arc = (g_LightArc - 180) * (Math.PI / 180);
941 double dy = (Math.Sin(arc) / Math.Cos(arc)) * p_ShadowBorderOuterRect.Width;
942 Point xstartpoint = p_ShadowBorderOuterRect.TopRight + new Vector(0, dy);
943 StreamGeometry xg = new StreamGeometry();
944 using (StreamGeometryContext context = xg.Open())
945 {
946 context.BeginFigure(xstartpoint, true, true);
947 context.LineTo(p_ShadowBorderOuterRect.TopRight, true, false);
948 context.LineTo(p_ShadowBorderOuterRect.TopLeft, true, false);
949 }
950 xg.Freeze();
951 StreamGeometry yg = new StreamGeometry();
952 using (StreamGeometryContext context = yg.Open())
953 {
954 context.BeginFigure(xstartpoint, true, true);
955 if (!DoubleUtil.AreClose(xstartpoint,
956 p_ShadowBorderOuterRect.BottomRight))
957 {
958 context.LineTo(p_ShadowBorderOuterRect.BottomRight, true, false);
959 }
960 context.LineTo(p_ShadowBorderOuterRect.BottomLeft, true, false);
961 context.LineTo(p_ShadowBorderOuterRect.TopLeft, true, false);
962 }
963 yg.Freeze();
964 shadow_x = Geometry.Combine(
965 xg, shadow, GeometryCombineMode.Intersect, null);
966 shadow_y = Geometry.Combine(
967 yg, shadow, GeometryCombineMode.Intersect, null);
968 }
969
970 private void SplitGeometty_RightTop(PathGeometry shadow, out Geometry shadow_x, out Geometry shadow_y)
971 {
972 if (g_LightArc == 90)
973 {
974 shadow_y = null;
975 shadow_x = shadow;
976 return;
977 }
978 double arc = (180 - g_LightArc) * (Math.PI / 180);
979 double dy = p_ShadowBorderOuterRect.Width * (Math.Sin(arc) / Math.Cos(arc));
980 Point xstartpoint = p_ShadowBorderOuterRect.BottomRight + new Vector(0, 0 - dy);
981 StreamGeometry xg = new StreamGeometry();
982 using (StreamGeometryContext context = xg.Open())
983 {
984 context.BeginFigure(xstartpoint, true, true);
985 context.LineTo(p_ShadowBorderOuterRect.BottomRight, true, false);
986 context.LineTo(p_ShadowBorderOuterRect.BottomLeft, true, false);
987 }
988 xg.Freeze();
989 StreamGeometry yg = new StreamGeometry();
990 using (StreamGeometryContext context = yg.Open())
991 {
992 context.BeginFigure(xstartpoint, true, true);
993 if (!DoubleUtil.AreClose(xstartpoint,
994 p_ShadowBorderOuterRect.TopRight))
995 {
996 context.LineTo(p_ShadowBorderOuterRect.TopRight, true, false);
997 }
998 context.LineTo(p_ShadowBorderOuterRect.TopLeft, true, false);
999 context.LineTo(p_ShadowBorderOuterRect.BottomLeft, true, false);
1000 }
1001 yg.Freeze();
1002 shadow_x = Geometry.Combine(
1003 xg, shadow, GeometryCombineMode.Intersect, null);
1004 shadow_y = Geometry.Combine(
1005 yg, shadow, GeometryCombineMode.Intersect, null);
1006 }
1007
1008 private void SplitGeometty_LeftBottom(PathGeometry shadow, out Geometry shadow_x, out Geometry shadow_y)
1009 {
1010 if (g_LightArc == 270)
1011 {
1012 shadow_y = null;
1013 shadow_x = shadow;
1014 return;
1015 }
1016 double arc = (360 - g_LightArc) * (Math.PI / 180);
1017 double dy = (Math.Sin(arc) / Math.Cos(arc)) * p_ShadowBorderOuterRect.Width;
1018 Point xstartpoint = p_ShadowBorderOuterRect.TopLeft + new Vector(0, dy);
1019 StreamGeometry xg = new StreamGeometry();
1020 using (StreamGeometryContext context = xg.Open())
1021 {
1022 context.BeginFigure(xstartpoint, true, true);
1023 context.LineTo(p_ShadowBorderOuterRect.TopLeft, true, false);
1024 context.LineTo(p_ShadowBorderOuterRect.TopRight, true, false);
1025 }
1026 xg.Freeze();
1027 StreamGeometry yg = new StreamGeometry();
1028 using (StreamGeometryContext context = yg.Open())
1029 {
1030 context.BeginFigure(xstartpoint, true, true);
1031 if (!DoubleUtil.AreClose(xstartpoint,
1032 p_ShadowBorderOuterRect.BottomLeft))
1033 {
1034 context.LineTo(p_ShadowBorderOuterRect.BottomLeft, true, false);
1035 }
1036 context.LineTo(p_ShadowBorderOuterRect.BottomRight, true, false);
1037 context.LineTo(p_ShadowBorderOuterRect.TopRight, true, false);
1038 }
1039 yg.Freeze();
1040 shadow_x = Geometry.Combine(
1041 xg, shadow, GeometryCombineMode.Intersect, null);
1042 shadow_y = Geometry.Combine(
1043 yg, shadow, GeometryCombineMode.Intersect, null);
1044 }
1045
1046 private double GetArc(double larc)
1047 {
1048 double arc = Math.Abs(larc);
1049 while (arc >= 360)
1050 arc -= 360;
1051 return arc;
1052 }
1053
1054 private void ResetDxDy(
1055 double shadowwidth,
1056 double lightarc)
1057 {
1058 double arc = GetArc(lightarc);
1059 g_LightArc = arc;
1060 if (arc >= 0 && arc < 90)
1061 {
1062 g_Dx = Math.Abs(shadowwidth * Math.Cos(arc * (Math.PI / 180)));
1063 if (DoubleUtil.IsZero(g_Dx))
1064 g_Dx = 0;
1065 g_Dy = Math.Abs(shadowwidth * Math.Sin(arc * (Math.PI / 180)));
1066 if (DoubleUtil.IsZero(g_Dy))
1067 g_Dy = 0;
1068 g_ShadowLightPosition = MeasureShadowLightPosition.LeftTop;
1069 return;
1070 }
1071 if (arc >= 90 && arc < 180)
1072 {
1073 g_Dx = Math.Abs(shadowwidth * Math.Cos((180 - arc) * (Math.PI / 180)));
1074 if (DoubleUtil.IsZero(g_Dx))
1075 g_Dx = 0;
1076 g_Dy = Math.Abs(shadowwidth * Math.Sin((180 - arc) * (Math.PI / 180)));
1077 if (DoubleUtil.IsZero(g_Dy))
1078 g_Dy = 0;
1079 g_ShadowLightPosition = MeasureShadowLightPosition.RightTop;
1080 return;
1081 }
1082 if (arc >= 180 && arc < 270)
1083 {
1084 g_Dx = Math.Abs(shadowwidth * Math.Cos((arc - 180) * (Math.PI / 180)));
1085 if (DoubleUtil.IsZero(g_Dx))
1086 g_Dx = 0;
1087 g_Dy = Math.Abs(shadowwidth * Math.Sin((arc - 180) * (Math.PI / 180)));
1088 if (DoubleUtil.IsZero(g_Dy))
1089 g_Dy = 0;
1090 g_ShadowLightPosition = MeasureShadowLightPosition.RightBottom;
1091 return;
1092 }
1093 if (arc >= 270 && arc < 360)
1094 {
1095 g_Dx = Math.Abs(shadowwidth * Math.Cos((360 - arc) * (Math.PI / 180)));
1096 if (DoubleUtil.IsZero(g_Dx))
1097 g_Dx = 0;
1098 g_Dy = Math.Abs(shadowwidth * Math.Sin((360 - arc) * (Math.PI / 180)));
1099 if (DoubleUtil.IsZero(g_Dy))
1100 g_Dy = 0;
1101 g_ShadowLightPosition = MeasureShadowLightPosition.LeftBottom;
1102 return;
1103 }
1104 }
1105
1106 private void AddJoinPoints(StreamGeometryContext ctx,Point[] points)
1107 {
1108 ctx.BeginFigure(points[0],true,false);
1109 ctx.LineTo(points[1], true, false);
1110 ctx.BeginFigure(points[2], true, false);
1111 ctx.LineTo(points[3], true, false);
1112 }
1113
1114 private void SetBorderGeometry(StreamGeometryContext ctx,Rect rect)
1115 {
1116 Point p1;
1117 Point p2;
1118 Point p3;
1119 Point p4;
1120 Point p5;
1121 Point p6;
1122 Point p7;
1123 Point p8;
1124 if (DoubleUtil.IsZero(g_BorderCornerRadius.TopLeft))
1125 {
1126 p1 = p8 = rect.Location;
1127 }
1128 else
1129 {
1130 p1 = rect.Location + new Vector(g_BorderCornerRadius.TopLeft, 0);
1131 p8 = rect.Location + new Vector(0, g_BorderCornerRadius.TopLeft);
1132 }
1133 if (DoubleUtil.IsZero(g_BorderCornerRadius.TopRight))
1134 {
1135 p2 = p3 = rect.TopRight;
1136 }
1137 else
1138 {
1139 p2 = rect.TopRight + new Vector(0 - g_BorderCornerRadius.TopRight, 0);
1140 p3 = rect.TopRight + new Vector(0, g_BorderCornerRadius.TopRight);
1141 }
1142 if (DoubleUtil.IsZero(g_BorderCornerRadius.BottomRight))
1143 {
1144 p4 = p5 = rect.BottomRight;
1145 }
1146 else
1147 {
1148 p4 = rect.BottomRight + new Vector(0, 0 - g_BorderCornerRadius.BottomRight);
1149 p5 = rect.BottomRight + new Vector(0 - g_BorderCornerRadius.BottomRight, 0);
1150 }
1151 if (DoubleUtil.IsZero(g_BorderCornerRadius.BottomLeft))
1152 {
1153 p6 = p7 = rect.BottomLeft;
1154 }
1155 else
1156 {
1157 p6 = rect.BottomLeft + new Vector(g_BorderCornerRadius.BottomLeft, 0);
1158 p7 = rect.BottomLeft + new Vector(0, 0 - g_BorderCornerRadius.BottomLeft);
1159 }
1160 if (p1.X > p2.X)
1161 {
1162 double num = (g_BorderCornerRadius.TopLeft / (g_BorderCornerRadius.TopLeft + g_BorderCornerRadius.TopRight)) * rect.Width;
1163 p1.X = num;
1164 p2.X = num;
1165 }
1166 if (p3.Y > p4.Y)
1167 {
1168 double num2 = (g_BorderCornerRadius.TopRight / (g_BorderCornerRadius.TopRight + g_BorderCornerRadius.BottomRight)) * rect.Height;
1169 p3.Y = num2;
1170 p4.Y = num2;
1171 }
1172 if (p5.X < p6.X)
1173 {
1174 double num3 = (g_BorderCornerRadius.BottomRight / (g_BorderCornerRadius.BottomLeft + g_BorderCornerRadius.BottomRight)) * rect.Width;
1175 p6.X = num3;
1176 p6.X = num3;
1177 }
1178 if (p7.Y < p8.Y)
1179 {
1180 double num4 = (g_BorderCornerRadius.BottomLeft / (g_BorderCornerRadius.TopLeft + g_BorderCornerRadius.BottomLeft)) * rect.Height;
1181 p7.Y = num4;
1182 p8.Y = num4;
1183 }
1184 ctx.BeginFigure(p1, true, true);
1185 ToPoint(ctx, p1, p2);
1186 ToPoint(ctx, p2, p3);
1187 ToPoint(ctx, p3, p4);
1188 ToPoint(ctx, p4, p5);
1189 ToPoint(ctx, p5, p6);
1190 ToPoint(ctx, p6, p7);
1191 ToPoint(ctx, p7, p8);
1192 ToPoint(ctx, p8, p1);
1193 }
1194
1195 private void ToPoint(StreamGeometryContext ctx, Point start, Point end)
1196 {
1197 if (DoubleUtil.AreClose(start, end)) return;
1198 Size cornerradius = new Size(Math.Abs(start.X - end.X),
1199 Math.Abs(start.Y - end.Y));
1200 if (DoubleUtil.IsZero(cornerradius.Width) ||
1201 DoubleUtil.IsZero(cornerradius.Height) ||
1202 cornerradius.Width < 0 ||
1203 cornerradius.Height < 0)
1204 {
1205 ctx.LineTo(end, true, false);
1206 }
1207 else
1208 {
1209 ctx.ArcTo(end, cornerradius, 0,
1210 false, SweepDirection.Clockwise,
1211 true, false);
1212 }
1213 }
1214
1215 private Point[] GetBorderJoinPoints(Rect border1,Rect border2)
1216 {
1217 if (g_LightArc == 0 ||
1218 g_LightArc == 90 ||
1219 g_LightArc == 270) return null;
1220 Point[] r = new Point[4];
1221 switch (g_ShadowLightPosition)
1222 {
1223 case MeasureShadowLightPosition.LeftTop:
1224 case MeasureShadowLightPosition.RightBottom:
1225 {
1226 if (DoubleUtil.IsZero(g_BorderCornerRadius.TopRight))
1227 {
1228 r[0] = border1.TopRight;
1229 r[1] = border2.TopRight;
1230 }
1231 else
1232 {
1233 Vector v = GetBorderJoinPointVector_LT_RB(g_BorderCornerRadius.TopRight);
1234 v.X = 0 - v.X;
1235 r[0] = border1.TopRight + v;
1236 r[1] = r[0] + new Vector(g_Dx, g_Dy);
1237 }
1238 if (DoubleUtil.IsZero(g_BorderCornerRadius.BottomLeft))
1239 {
1240 r[2] = border1.BottomLeft;
1241 r[3] = border2.BottomLeft;
1242 }
1243 else
1244 {
1245 Vector v = GetBorderJoinPointVector_LT_RB(g_BorderCornerRadius.BottomLeft);
1246 v.Y = 0 - v.Y;
1247 r[2] = border1.BottomLeft + v;
1248 r[3] = r[2] + new Vector(g_Dx, g_Dy);
1249 }
1250 break;
1251 }
1252 case MeasureShadowLightPosition.RightTop:
1253 case MeasureShadowLightPosition.LeftBottom:
1254 {
1255 if (DoubleUtil.IsZero(g_BorderCornerRadius.TopLeft))
1256 {
1257 r[0] = border1.TopLeft;
1258 r[1] = border2.TopLeft;
1259 }
1260 else
1261 {
1262 Vector v = GetBorderJoinPointVector_RT_LB(g_BorderCornerRadius.TopLeft);
1263 r[0] = border1.TopLeft + v;
1264 r[1] = r[0] + new Vector(0 - g_Dx, g_Dy);
1265 }
1266 if (DoubleUtil.IsZero(g_BorderCornerRadius.BottomRight))
1267 {
1268 r[2] = border1.BottomRight;
1269 r[3] = border2.BottomRight;
1270 }
1271 else
1272 {
1273 Vector v = GetBorderJoinPointVector_RT_LB(g_BorderCornerRadius.TopLeft);
1274 v.X = 0 - v.X;
1275 v.Y = 0 - v.Y;
1276 r[2] = border1.BottomRight + v;
1277 r[3] = r[2] + new Vector(0 - g_Dx, g_Dy);
1278 }
1279 break;
1280 }
1281 default: return null;
1282 }
1283 return r;
1284 }
1285
1286 private Vector GetBorderJoinPointVector_LT_RB(double bj)
1287 {
1288 double arc = g_LightArc;
1289 if (arc > 180)
1290 arc -= 180;
1291 double ax = bj * Math.Cos((90 - arc) * (Math.PI / 180));
1292 double dx = bj - ax;
1293 double ay = bj * Math.Sin((90 - arc) * (Math.PI / 180));
1294 double dy = bj - ay;
1295 return new Vector(dx, dy);
1296 }
1297
1298 private Vector GetBorderJoinPointVector_RT_LB(double bj)
1299 {
1300 double arc;
1301 if (g_LightArc > 270)
1302 {
1303 arc = 360 - g_LightArc;
1304 }
1305 else
1306 {
1307 arc = 360 - (g_LightArc + 180);
1308 }
1309 double ax = bj * Math.Cos((90 - arc) * (Math.PI / 180));
1310 double dx = bj - ax;
1311 double ay = bj * Math.Sin((90 - arc) * (Math.PI / 180));
1312 double dy = bj - ay;
1313 return new Vector(dx, dy);
1314 }
1315
1316 }
1317
1318 private enum MeasureShadowLightPosition
1319 {
1320 None,
1321 LeftTop,
1322 RightTop,
1323 RightBottom,
1324 LeftBottom
1325 }
1326 #endregion
1327 }
1328 }
1329

浙公网安备 33010602011771号