CyclicScrollerOpcityMask.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. namespace HistoryDLL
  10. {
  11. public partial class CyclicScroller : UserControl
  12. {
  13. //OpacityMask Setting
  14. LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
  15. GradientStopCollection myGradientStopCollection = new GradientStopCollection();
  16. GradientStop LeftLineLeftPointStopFirst = new GradientStop();
  17. GradientStop LeftLineRightPointStopFirst = new GradientStop();
  18. GradientStop RightLineLeftPointStopFirst = new GradientStop();
  19. GradientStop RightLineRightPointStopFirst = new GradientStop();
  20. GradientStop LeftLineLeftPointStopSecond = new GradientStop();
  21. GradientStop LeftLineRightPointStopSecond = new GradientStop();
  22. GradientStop RightLineLeftPointStopSecond = new GradientStop();
  23. GradientStop RightLineRightPointStopSecond = new GradientStop();
  24. GradientStop LeftLineLeftPointStopThree = new GradientStop();
  25. GradientStop LeftLineRightPointStopThree = new GradientStop();
  26. GradientStop RightLineLeftPointStopThree = new GradientStop();
  27. GradientStop RightLineRightPointStopThree = new GradientStop();
  28. bool IsUsingFirst = false, IsUsingSecond = false, IsUsingThree = false;
  29. /// <summary>
  30. /// 拖動隱藏區塊顯示設定
  31. /// </summary>
  32. private void SetDisplayPart()
  33. {
  34. #region First
  35. LeftLineLeftPointStopFirst.Offset = 0.0;
  36. Color c1 = new Color();
  37. c1 = GetColorRGB(true);
  38. LeftLineLeftPointStopFirst.Color = c1;
  39. LeftLineRightPointStopFirst.Offset = 0.0;
  40. Color c2 = new Color();
  41. c2 = GetColorRGB(false);
  42. LeftLineRightPointStopFirst.Color = c2;
  43. RightLineLeftPointStopFirst.Offset = 0.0;
  44. Color c3 = new Color();
  45. c3 = GetColorRGB(false);
  46. RightLineLeftPointStopFirst.Color = c3;
  47. RightLineRightPointStopFirst.Offset = 0.0;
  48. Color c4 = new Color();
  49. c4 = GetColorRGB(true);
  50. RightLineRightPointStopFirst.Color = c4;
  51. #endregion
  52. #region Second
  53. LeftLineLeftPointStopSecond.Offset = 0.0;
  54. Color c5 = new Color();
  55. c5 = GetColorRGB(true);
  56. LeftLineLeftPointStopSecond.Color = c5;
  57. LeftLineRightPointStopSecond.Offset = 0.0;
  58. Color c6 = new Color();
  59. c6 = GetColorRGB(false);
  60. LeftLineRightPointStopSecond.Color = c6;
  61. RightLineLeftPointStopSecond.Offset = 0.0;
  62. Color c7 = new Color();
  63. c7 = GetColorRGB(false);
  64. RightLineLeftPointStopSecond.Color = c7;
  65. RightLineRightPointStopSecond.Offset = 0.0;
  66. Color c8 = new Color();
  67. c8 = GetColorRGB(true);
  68. RightLineRightPointStopSecond.Color = c8;
  69. #endregion
  70. #region Three
  71. LeftLineLeftPointStopThree.Offset = 0.0;
  72. Color c9 = new Color();
  73. c9 = GetColorRGB(true);
  74. LeftLineLeftPointStopThree.Color = c9;
  75. LeftLineRightPointStopThree.Offset = 0.0;
  76. Color c10 = new Color();
  77. c10 = GetColorRGB(false);
  78. LeftLineRightPointStopThree.Color = c10;
  79. RightLineLeftPointStopThree.Offset = 0.0;
  80. Color c11 = new Color();
  81. c11 = GetColorRGB(false);
  82. RightLineLeftPointStopThree.Color = c11;
  83. RightLineRightPointStopThree.Offset = 0.0;
  84. Color c12 = new Color();
  85. c12 = GetColorRGB(true);
  86. RightLineRightPointStopThree.Color = c12;
  87. #endregion
  88. #region add GradientStop into Collection
  89. myGradientStopCollection.Add(LeftLineLeftPointStopThree);
  90. myGradientStopCollection.Add(LeftLineRightPointStopThree);
  91. myGradientStopCollection.Add(RightLineLeftPointStopThree);
  92. myGradientStopCollection.Add(RightLineRightPointStopThree);
  93. myGradientStopCollection.Add(LeftLineLeftPointStopSecond);
  94. myGradientStopCollection.Add(LeftLineRightPointStopSecond);
  95. myGradientStopCollection.Add(RightLineLeftPointStopSecond);
  96. myGradientStopCollection.Add(RightLineRightPointStopSecond);
  97. myGradientStopCollection.Add(LeftLineLeftPointStopFirst);
  98. myGradientStopCollection.Add(LeftLineRightPointStopFirst);
  99. myGradientStopCollection.Add(RightLineLeftPointStopFirst);
  100. myGradientStopCollection.Add(RightLineRightPointStopFirst);
  101. #endregion
  102. myLinearGradientBrush.StartPoint = new Point(0, 0);
  103. myLinearGradientBrush.EndPoint = new Point(1, 0);
  104. myLinearGradientBrush.GradientStops = myGradientStopCollection;
  105. uxCyclicGrid.OpacityMask = myLinearGradientBrush;
  106. }
  107. private Color GetColorRGB(bool Show)
  108. {
  109. Color result = new Color();
  110. result.R = 255;
  111. result.G = 255;
  112. result.B = 255;
  113. if (Show)
  114. {
  115. result.A = 255;
  116. }
  117. else
  118. {
  119. result.A = 0;
  120. }
  121. return result;
  122. }
  123. //判斷允許後面顯示的區域~
  124. //不管螢幕個數~最多為三個可畫分的區塊~在SetDisplayPart 函數中~已經將工具加入
  125. //判斷方式 : 取用時~必須判斷為連續幾個 isusing 後 ~ 為一個區塊將計算值放到第一個區塊中~
  126. //一般來說一個螢幕指會需要用到一個該工具~如果今天是雙或者三螢幕
  127. //則必須按照第一個取用方式~去設定第二個甚至第三個~
  128. private void CheckDisplayRange()
  129. {
  130. int startindex = -1, endindex = -1;
  131. int useTools = 1;
  132. bool HaveUsing = false;
  133. double startvalue = 0;
  134. double endvalue = 0;
  135. IsUsingFirst = IsUsingSecond = IsUsingThree = false;
  136. for (int i = 0; i < ExtraUnitGridList.Count; i++)
  137. {
  138. if (ExtraUnitGridList[i].IsUsing != 0 && !HaveUsing)
  139. {
  140. #region GradientStop 的起始位置
  141. HaveUsing = true;
  142. startindex = i;
  143. startvalue = 0;
  144. double Leftwidth = 0;
  145. //計算到此左邊的寬度
  146. for (int index = 0; index < startindex; index++)
  147. {
  148. if (index == 0)
  149. {
  150. //主要為最左邊的寬度~判斷最左邊區塊寬度~為縮小或者為正常大小
  151. if (ExtraUnitGridList[index].Width <= MainEventWidth - (ExtraUnitGridList[index].ShrinkValueOne))
  152. {
  153. //縮小 : 原始大小 - 隱藏的大小 - 右邊被縮小的距離
  154. Leftwidth += MainEventWidth - NoneUseRange - (ExtraUnitGridList[index].ShrinkValueOne);
  155. }
  156. else
  157. {
  158. //正常大小計算方式 : 原始大小 - 隱藏的大小
  159. Leftwidth += MainEventWidth - NoneUseRange;
  160. }
  161. }
  162. else
  163. {
  164. Leftwidth += ExtraUnitGridList[index].Width;
  165. }
  166. }
  167. startvalue = Leftwidth / (double)ResolutionValueWidth;
  168. //Console.WriteLine("起點 : " + Leftwidth);
  169. #endregion
  170. }
  171. else
  172. {
  173. if (HaveUsing && ExtraUnitGridList[i].IsUsing == 0)
  174. {
  175. #region GradientStop 的停止位置 (還沒找到最後一個)
  176. endindex = i;
  177. HaveUsing = false;
  178. endvalue = 0;
  179. double Leftwidth = 0;
  180. //計算到此左邊的寬度
  181. for (int index = 0; index < endindex; index++)
  182. {
  183. if (index == 0)
  184. {
  185. if (ExtraUnitGridList[index].Width < MainEventWidth)
  186. {
  187. //因為左邊縮小的話只有右邊 - ExtraUnitGridList[index].ShrinkValueOne 顧~不用除以2
  188. Leftwidth += MainEventWidth - NoneUseRange - (ExtraUnitGridList[index].ShrinkValueOne);
  189. }
  190. else
  191. {
  192. Leftwidth += MainEventWidth - NoneUseRange;
  193. }
  194. }
  195. else
  196. {
  197. Leftwidth += ExtraUnitGridList[index].Width;
  198. }
  199. }
  200. endvalue = Leftwidth / (double)ResolutionValueWidth;
  201. //Console.WriteLine("終點 : " + Leftwidth);
  202. if (useTools == 1)
  203. {
  204. LeftLineLeftPointStopFirst.Offset = startvalue;
  205. LeftLineRightPointStopFirst.Offset = startvalue;
  206. RightLineLeftPointStopFirst.Offset = endvalue;
  207. RightLineRightPointStopFirst.Offset = endvalue;
  208. IsUsingFirst = true;
  209. useTools++;
  210. }
  211. else if (useTools == 2)
  212. {
  213. LeftLineLeftPointStopSecond.Offset = startvalue;
  214. LeftLineRightPointStopSecond.Offset = startvalue;
  215. RightLineLeftPointStopSecond.Offset = endvalue;
  216. RightLineRightPointStopSecond.Offset = endvalue;
  217. IsUsingSecond = true;
  218. useTools++;
  219. }
  220. else if (useTools == 3)
  221. {
  222. LeftLineLeftPointStopThree.Offset = startvalue;
  223. LeftLineRightPointStopThree.Offset = startvalue;
  224. RightLineLeftPointStopThree.Offset = endvalue;
  225. RightLineRightPointStopThree.Offset = endvalue;
  226. IsUsingThree = true;
  227. useTools = 1;
  228. }
  229. #endregion
  230. }
  231. //或者最後一個Grid
  232. else if (HaveUsing && i + 1 == ExtraUnitGridList.Count)
  233. {
  234. #region GradientStop 的停止位置 (最後一個的話)
  235. HaveUsing = false;
  236. endvalue = 1;
  237. if (useTools == 1)
  238. {
  239. LeftLineLeftPointStopFirst.Offset = startvalue;
  240. LeftLineRightPointStopFirst.Offset = startvalue;
  241. RightLineLeftPointStopFirst.Offset = endvalue;
  242. RightLineRightPointStopFirst.Offset = endvalue;
  243. IsUsingFirst = true;
  244. useTools++;
  245. }
  246. else if (useTools == 2)
  247. {
  248. LeftLineLeftPointStopSecond.Offset = startvalue;
  249. LeftLineRightPointStopSecond.Offset = startvalue;
  250. RightLineLeftPointStopSecond.Offset = endvalue;
  251. RightLineRightPointStopSecond.Offset = endvalue;
  252. IsUsingSecond = true;
  253. useTools++;
  254. }
  255. else if (useTools == 3)
  256. {
  257. LeftLineLeftPointStopThree.Offset = startvalue;
  258. LeftLineRightPointStopThree.Offset = startvalue;
  259. RightLineLeftPointStopThree.Offset = endvalue;
  260. RightLineRightPointStopThree.Offset = endvalue;
  261. IsUsingThree = true;
  262. useTools = 1;
  263. }
  264. #endregion
  265. }
  266. }
  267. }
  268. if (!IsUsingFirst)
  269. {
  270. LeftLineLeftPointStopFirst.Offset = 0;
  271. LeftLineRightPointStopFirst.Offset = 0;
  272. RightLineLeftPointStopFirst.Offset = 0;
  273. RightLineRightPointStopFirst.Offset = 0;
  274. }
  275. if (!IsUsingSecond)
  276. {
  277. LeftLineLeftPointStopSecond.Offset = 0;
  278. LeftLineRightPointStopSecond.Offset = 0;
  279. RightLineLeftPointStopSecond.Offset = 0;
  280. RightLineRightPointStopSecond.Offset = 0;
  281. }
  282. if (!IsUsingThree)
  283. {
  284. LeftLineLeftPointStopThree.Offset = 0;
  285. LeftLineRightPointStopThree.Offset = 0;
  286. RightLineLeftPointStopThree.Offset = 0;
  287. RightLineRightPointStopThree.Offset = 0;
  288. }
  289. }
  290. }
  291. }