SystemDropShadowChrome.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using Microsoft.VisualBasic.CompilerServices;
  7. namespace PCL
  8. {
  9. // Token: 0x0200011F RID: 287
  10. public sealed class SystemDropShadowChrome : Decorator
  11. {
  12. // Token: 0x170001FC RID: 508
  13. // (get) Token: 0x06000C87 RID: 3207 RVA: 0x00053624 File Offset: 0x00051824
  14. // (set) Token: 0x06000C88 RID: 3208 RVA: 0x0000853B File Offset: 0x0000673B
  15. public Color Color
  16. {
  17. get
  18. {
  19. object value = base.GetValue(SystemDropShadowChrome._ObserverTests);
  20. if (value == null)
  21. {
  22. return default(Color);
  23. }
  24. return (Color)value;
  25. }
  26. set
  27. {
  28. base.SetValue(SystemDropShadowChrome._ObserverTests, value);
  29. }
  30. }
  31. // Token: 0x170001FD RID: 509
  32. // (get) Token: 0x06000C89 RID: 3209 RVA: 0x00053650 File Offset: 0x00051850
  33. // (set) Token: 0x06000C8A RID: 3210 RVA: 0x0000854E File Offset: 0x0000674E
  34. public CornerRadius CornerRadius
  35. {
  36. get
  37. {
  38. object value = base.GetValue(SystemDropShadowChrome._StubTests);
  39. if (value == null)
  40. {
  41. return default(CornerRadius);
  42. }
  43. return (CornerRadius)value;
  44. }
  45. set
  46. {
  47. base.SetValue(SystemDropShadowChrome._StubTests, value);
  48. }
  49. }
  50. // Token: 0x06000C8B RID: 3211 RVA: 0x0005367C File Offset: 0x0005187C
  51. private static bool IsCornerRadiusValid(object value)
  52. {
  53. CornerRadius cornerRadius = (value != null) ? ((CornerRadius)value) : default(CornerRadius);
  54. return cornerRadius.TopLeft >= 0.0 && cornerRadius.TopRight >= 0.0 && cornerRadius.BottomLeft >= 0.0 && cornerRadius.BottomRight >= 0.0 && !double.IsNaN(cornerRadius.TopLeft) && !double.IsNaN(cornerRadius.TopRight) && !double.IsNaN(cornerRadius.BottomLeft) && !double.IsNaN(cornerRadius.BottomRight) && !double.IsInfinity(cornerRadius.TopLeft) && !double.IsInfinity(cornerRadius.TopRight) && !double.IsInfinity(cornerRadius.BottomLeft) && !double.IsInfinity(cornerRadius.BottomRight);
  55. }
  56. // Token: 0x06000C8C RID: 3212 RVA: 0x00053764 File Offset: 0x00051964
  57. protected override void OnRender(DrawingContext drawingContext)
  58. {
  59. CornerRadius cornerRadius = this.CornerRadius;
  60. Rect rect = new Rect(new Point(5.0, 5.0), new Size(base.RenderSize.Width, base.RenderSize.Height));
  61. Color color = this.Color;
  62. if (rect.Width > 0.0 && rect.Height > 0.0 && color.A > 0)
  63. {
  64. double num = rect.Right - rect.Left - 10.0;
  65. double num2 = rect.Bottom - rect.Top - 10.0;
  66. double val = Math.Min(num * 0.5, num2 * 0.5);
  67. cornerRadius.TopLeft = Math.Min(cornerRadius.TopLeft, val);
  68. cornerRadius.TopRight = Math.Min(cornerRadius.TopRight, val);
  69. cornerRadius.BottomLeft = Math.Min(cornerRadius.BottomLeft, val);
  70. cornerRadius.BottomRight = Math.Min(cornerRadius.BottomRight, val);
  71. Brush[] brushes = this.GetBrushes(color, cornerRadius);
  72. double num3 = rect.Top + 5.0;
  73. double num4 = rect.Left + 5.0;
  74. double num5 = rect.Right - 5.0;
  75. double num6 = rect.Bottom - 5.0;
  76. double[] array = new double[]
  77. {
  78. num4,
  79. num4 + cornerRadius.TopLeft,
  80. num5 - cornerRadius.TopRight,
  81. num4 + cornerRadius.BottomLeft,
  82. num5 - cornerRadius.BottomRight,
  83. num5
  84. };
  85. double[] array2 = new double[]
  86. {
  87. num3,
  88. num3 + cornerRadius.TopLeft,
  89. num3 + cornerRadius.TopRight,
  90. num6 - cornerRadius.BottomLeft,
  91. num6 - cornerRadius.BottomRight,
  92. num6
  93. };
  94. drawingContext.PushGuidelineSet(new GuidelineSet(array, array2));
  95. cornerRadius.TopLeft += 5.0;
  96. cornerRadius.TopRight += 5.0;
  97. cornerRadius.BottomLeft += 5.0;
  98. cornerRadius.BottomRight += 5.0;
  99. Rect rectangle = new Rect(rect.Left, rect.Top, cornerRadius.TopLeft, cornerRadius.TopLeft);
  100. drawingContext.DrawRectangle(brushes[0], null, rectangle);
  101. double num7 = array[2] - array[1];
  102. if (num7 > 0.0)
  103. {
  104. Rect rectangle2 = new Rect(array[1], rect.Top, num7, 5.0);
  105. drawingContext.DrawRectangle(brushes[1], null, rectangle2);
  106. }
  107. Rect rectangle3 = new Rect(array[2], rect.Top, cornerRadius.TopRight, cornerRadius.TopRight);
  108. drawingContext.DrawRectangle(brushes[2], null, rectangle3);
  109. double num8 = array2[3] - array2[1];
  110. if (num8 > 0.0)
  111. {
  112. Rect rectangle4 = new Rect(rect.Left, array2[1], 5.0, num8);
  113. drawingContext.DrawRectangle(brushes[3], null, rectangle4);
  114. }
  115. double num9 = array2[4] - array2[2];
  116. if (num9 > 0.0)
  117. {
  118. Rect rectangle5 = new Rect(array[5], array2[2], 5.0, num9);
  119. drawingContext.DrawRectangle(brushes[5], null, rectangle5);
  120. }
  121. Rect rectangle6 = new Rect(rect.Left, array2[3], cornerRadius.BottomLeft, cornerRadius.BottomLeft);
  122. drawingContext.DrawRectangle(brushes[6], null, rectangle6);
  123. double num10 = array[4] - array[3];
  124. if (num10 > 0.0)
  125. {
  126. Rect rectangle7 = new Rect(array[3], array2[5], num10, 5.0);
  127. drawingContext.DrawRectangle(brushes[7], null, rectangle7);
  128. }
  129. Rect rectangle8 = new Rect(array[4], array2[4], cornerRadius.BottomRight, cornerRadius.BottomRight);
  130. drawingContext.DrawRectangle(brushes[8], null, rectangle8);
  131. if (cornerRadius.TopLeft == 5.0 && cornerRadius.TopLeft == cornerRadius.TopRight && cornerRadius.TopLeft == cornerRadius.BottomLeft && cornerRadius.TopLeft == cornerRadius.BottomRight)
  132. {
  133. Rect rectangle9 = new Rect(array[0], array2[0], num, num2);
  134. drawingContext.DrawRectangle(brushes[4], null, rectangle9);
  135. }
  136. else
  137. {
  138. PathFigure pathFigure = new PathFigure();
  139. if (cornerRadius.TopLeft > 5.0)
  140. {
  141. pathFigure.StartPoint = new Point(array[1], array2[0]);
  142. pathFigure.Segments.Add(new LineSegment(new Point(array[1], array2[1]), true));
  143. pathFigure.Segments.Add(new LineSegment(new Point(array[0], array2[1]), true));
  144. }
  145. else
  146. {
  147. pathFigure.StartPoint = new Point(array[0], array2[0]);
  148. }
  149. if (cornerRadius.BottomLeft > 5.0)
  150. {
  151. pathFigure.Segments.Add(new LineSegment(new Point(array[0], array2[3]), true));
  152. pathFigure.Segments.Add(new LineSegment(new Point(array[3], array2[3]), true));
  153. pathFigure.Segments.Add(new LineSegment(new Point(array[3], array2[5]), true));
  154. }
  155. else
  156. {
  157. pathFigure.Segments.Add(new LineSegment(new Point(array[0], array2[5]), true));
  158. }
  159. if (cornerRadius.BottomRight > 5.0)
  160. {
  161. pathFigure.Segments.Add(new LineSegment(new Point(array[4], array2[5]), true));
  162. pathFigure.Segments.Add(new LineSegment(new Point(array[4], array2[4]), true));
  163. pathFigure.Segments.Add(new LineSegment(new Point(array[5], array2[4]), true));
  164. }
  165. else
  166. {
  167. pathFigure.Segments.Add(new LineSegment(new Point(array[5], array2[5]), true));
  168. }
  169. if (cornerRadius.TopRight > 5.0)
  170. {
  171. pathFigure.Segments.Add(new LineSegment(new Point(array[5], array2[2]), true));
  172. pathFigure.Segments.Add(new LineSegment(new Point(array[2], array2[2]), true));
  173. pathFigure.Segments.Add(new LineSegment(new Point(array[2], array2[0]), true));
  174. }
  175. else
  176. {
  177. pathFigure.Segments.Add(new LineSegment(new Point(array[5], array2[0]), true));
  178. }
  179. pathFigure.IsClosed = true;
  180. pathFigure.Freeze();
  181. PathGeometry pathGeometry = new PathGeometry();
  182. pathGeometry.Figures.Add(pathFigure);
  183. pathGeometry.Freeze();
  184. drawingContext.DrawGeometry(brushes[4], null, pathGeometry);
  185. }
  186. drawingContext.Pop();
  187. }
  188. }
  189. // Token: 0x06000C8D RID: 3213 RVA: 0x00008561 File Offset: 0x00006761
  190. private static void ClearBrushes(DependencyObject o, DependencyPropertyChangedEventArgs e)
  191. {
  192. ((SystemDropShadowChrome)o)._InstanceTests = null;
  193. }
  194. // Token: 0x06000C8E RID: 3214 RVA: 0x00053E7C File Offset: 0x0005207C
  195. private static GradientStopCollection CreateStops(Color c, double cornerRadius)
  196. {
  197. double num = 1.0 / (cornerRadius + 5.0);
  198. GradientStopCollection gradientStopCollection = new GradientStopCollection();
  199. gradientStopCollection.Add(new GradientStop(c, (0.5 + cornerRadius) * num));
  200. Color color = c;
  201. color.A = checked((byte)Math.Round(unchecked(0.74336 * (double)c.A)));
  202. gradientStopCollection.Add(new GradientStop(color, (1.5 + cornerRadius) * num));
  203. color.A = checked((byte)Math.Round(unchecked(0.38053 * (double)c.A)));
  204. gradientStopCollection.Add(new GradientStop(color, (2.5 + cornerRadius) * num));
  205. color.A = checked((byte)Math.Round(unchecked(0.12389 * (double)c.A)));
  206. gradientStopCollection.Add(new GradientStop(color, (3.5 + cornerRadius) * num));
  207. color.A = checked((byte)Math.Round(unchecked(0.02654 * (double)c.A)));
  208. gradientStopCollection.Add(new GradientStop(color, (4.5 + cornerRadius) * num));
  209. color.A = 0;
  210. gradientStopCollection.Add(new GradientStop(color, (5.0 + cornerRadius) * num));
  211. gradientStopCollection.Freeze();
  212. return gradientStopCollection;
  213. }
  214. // Token: 0x06000C8F RID: 3215 RVA: 0x00053FC8 File Offset: 0x000521C8
  215. private static Brush[] CreateBrushes(Color c, CornerRadius cornerRadius)
  216. {
  217. Brush[] array = new Brush[9];
  218. array[4] = new SolidColorBrush(c);
  219. array[4].Freeze();
  220. GradientStopCollection gradientStopCollection = SystemDropShadowChrome.CreateStops(c, 0.0);
  221. LinearGradientBrush linearGradientBrush = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 1.0), new Point(0.0, 0.0));
  222. linearGradientBrush.Freeze();
  223. array[1] = linearGradientBrush;
  224. LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(gradientStopCollection, new Point(1.0, 0.0), new Point(0.0, 0.0));
  225. linearGradientBrush2.Freeze();
  226. array[3] = linearGradientBrush2;
  227. LinearGradientBrush linearGradientBrush3 = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 0.0), new Point(1.0, 0.0));
  228. linearGradientBrush3.Freeze();
  229. array[5] = linearGradientBrush3;
  230. LinearGradientBrush linearGradientBrush4 = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 0.0), new Point(0.0, 1.0));
  231. linearGradientBrush4.Freeze();
  232. array[7] = linearGradientBrush4;
  233. GradientStopCollection gradientStopCollection2;
  234. if (cornerRadius.TopLeft == 0.0)
  235. {
  236. gradientStopCollection2 = gradientStopCollection;
  237. }
  238. else
  239. {
  240. gradientStopCollection2 = SystemDropShadowChrome.CreateStops(c, cornerRadius.TopLeft);
  241. }
  242. RadialGradientBrush radialGradientBrush = new RadialGradientBrush(gradientStopCollection2)
  243. {
  244. RadiusX = 1.0,
  245. RadiusY = 1.0,
  246. Center = new Point(1.0, 1.0),
  247. GradientOrigin = new Point(1.0, 1.0)
  248. };
  249. radialGradientBrush.Freeze();
  250. array[0] = radialGradientBrush;
  251. GradientStopCollection gradientStopCollection3;
  252. if (cornerRadius.TopRight == 0.0)
  253. {
  254. gradientStopCollection3 = gradientStopCollection;
  255. }
  256. else if (cornerRadius.TopRight == cornerRadius.TopLeft)
  257. {
  258. gradientStopCollection3 = gradientStopCollection2;
  259. }
  260. else
  261. {
  262. gradientStopCollection3 = SystemDropShadowChrome.CreateStops(c, cornerRadius.TopRight);
  263. }
  264. RadialGradientBrush radialGradientBrush2 = new RadialGradientBrush(gradientStopCollection3)
  265. {
  266. RadiusX = 1.0,
  267. RadiusY = 1.0,
  268. Center = new Point(0.0, 1.0),
  269. GradientOrigin = new Point(0.0, 1.0)
  270. };
  271. radialGradientBrush2.Freeze();
  272. array[2] = radialGradientBrush2;
  273. GradientStopCollection gradientStopCollection4;
  274. if (cornerRadius.BottomLeft == 0.0)
  275. {
  276. gradientStopCollection4 = gradientStopCollection;
  277. }
  278. else if (cornerRadius.BottomLeft == cornerRadius.TopLeft)
  279. {
  280. gradientStopCollection4 = gradientStopCollection2;
  281. }
  282. else if (cornerRadius.BottomLeft == cornerRadius.TopRight)
  283. {
  284. gradientStopCollection4 = gradientStopCollection3;
  285. }
  286. else
  287. {
  288. gradientStopCollection4 = SystemDropShadowChrome.CreateStops(c, cornerRadius.BottomLeft);
  289. }
  290. RadialGradientBrush radialGradientBrush3 = new RadialGradientBrush(gradientStopCollection4)
  291. {
  292. RadiusX = 1.0,
  293. RadiusY = 1.0,
  294. Center = new Point(1.0, 0.0),
  295. GradientOrigin = new Point(1.0, 0.0)
  296. };
  297. radialGradientBrush3.Freeze();
  298. array[6] = radialGradientBrush3;
  299. GradientStopCollection gradientStopCollection5;
  300. if (cornerRadius.BottomRight == 0.0)
  301. {
  302. gradientStopCollection5 = gradientStopCollection;
  303. }
  304. else if (cornerRadius.BottomRight == cornerRadius.TopLeft)
  305. {
  306. gradientStopCollection5 = gradientStopCollection2;
  307. }
  308. else if (cornerRadius.BottomRight == cornerRadius.TopRight)
  309. {
  310. gradientStopCollection5 = gradientStopCollection3;
  311. }
  312. else if (cornerRadius.BottomRight == cornerRadius.BottomLeft)
  313. {
  314. gradientStopCollection5 = gradientStopCollection4;
  315. }
  316. else
  317. {
  318. gradientStopCollection5 = SystemDropShadowChrome.CreateStops(c, cornerRadius.BottomRight);
  319. }
  320. RadialGradientBrush radialGradientBrush4 = new RadialGradientBrush(gradientStopCollection5)
  321. {
  322. RadiusX = 1.0,
  323. RadiusY = 1.0,
  324. Center = new Point(0.0, 0.0),
  325. GradientOrigin = new Point(0.0, 0.0)
  326. };
  327. radialGradientBrush4.Freeze();
  328. array[8] = radialGradientBrush4;
  329. return array;
  330. }
  331. // Token: 0x06000C90 RID: 3216 RVA: 0x000543CC File Offset: 0x000525CC
  332. private Brush[] GetBrushes(Color c, CornerRadius cornerRadius)
  333. {
  334. if (SystemDropShadowChrome.m_RulesTests == null)
  335. {
  336. object decoratorTests = SystemDropShadowChrome.m_DecoratorTests;
  337. ObjectFlowControl.CheckForSyncLockOnValueType(decoratorTests);
  338. lock (decoratorTests)
  339. {
  340. if (SystemDropShadowChrome.m_RulesTests == null)
  341. {
  342. SystemDropShadowChrome.m_RulesTests = SystemDropShadowChrome.CreateBrushes(c, cornerRadius);
  343. SystemDropShadowChrome._RefTests = cornerRadius;
  344. }
  345. }
  346. }
  347. Brush[] result;
  348. if (c == ((SolidColorBrush)SystemDropShadowChrome.m_RulesTests[4]).Color && cornerRadius == SystemDropShadowChrome._RefTests)
  349. {
  350. this._InstanceTests = null;
  351. result = SystemDropShadowChrome.m_RulesTests;
  352. }
  353. else
  354. {
  355. if (this._InstanceTests == null)
  356. {
  357. this._InstanceTests = SystemDropShadowChrome.CreateBrushes(c, cornerRadius);
  358. }
  359. result = this._InstanceTests;
  360. }
  361. return result;
  362. }
  363. // Token: 0x04000647 RID: 1607
  364. public static readonly DependencyProperty _ObserverTests = DependencyProperty.Register("Color", typeof(Color), typeof(SystemDropShadowChrome), new FrameworkPropertyMetadata(Color.FromArgb(113, 0, 0, 0), FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(SystemDropShadowChrome.ClearBrushes)));
  365. // Token: 0x04000648 RID: 1608
  366. public static readonly DependencyProperty _StubTests = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(SystemDropShadowChrome), new FrameworkPropertyMetadata(default(CornerRadius), FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(SystemDropShadowChrome.ClearBrushes)), new ValidateValueCallback(SystemDropShadowChrome.IsCornerRadiusValid));
  367. // Token: 0x04000649 RID: 1609
  368. private const double ShadowDepth = 5.0;
  369. // Token: 0x0400064A RID: 1610
  370. private static Brush[] m_RulesTests;
  371. // Token: 0x0400064B RID: 1611
  372. private static CornerRadius _RefTests;
  373. // Token: 0x0400064C RID: 1612
  374. private static readonly object m_DecoratorTests = RuntimeHelpers.GetObjectValue(new object());
  375. // Token: 0x0400064D RID: 1613
  376. private Brush[] _InstanceTests;
  377. // Token: 0x02000120 RID: 288
  378. private enum Placement
  379. {
  380. // Token: 0x0400064F RID: 1615
  381. TopLeft,
  382. // Token: 0x04000650 RID: 1616
  383. Top,
  384. // Token: 0x04000651 RID: 1617
  385. TopRight,
  386. // Token: 0x04000652 RID: 1618
  387. Left,
  388. // Token: 0x04000653 RID: 1619
  389. Center,
  390. // Token: 0x04000654 RID: 1620
  391. Right,
  392. // Token: 0x04000655 RID: 1621
  393. BottomLeft,
  394. // Token: 0x04000656 RID: 1622
  395. Bottom,
  396. // Token: 0x04000657 RID: 1623
  397. BottomRight
  398. }
  399. }
  400. }