GalleryToggle.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using PicView.UI.Sizing;
  2. using PicView.UI.Windows;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Media.Animation;
  6. using static PicView.Library.Fields;
  7. using static PicView.UI.PicGallery.GalleryFunctions;
  8. using static PicView.UI.PicGallery.GalleryLoad;
  9. using static PicView.UI.PicGallery.GalleryScroll;
  10. using static PicView.UI.Sizing.WindowLogic;
  11. using static PicView.UI.UserControls.UC;
  12. namespace PicView.UI.PicGallery
  13. {
  14. internal static class GalleryToggle
  15. {
  16. #region Toggle
  17. internal static void Toggle(bool change = false)
  18. {
  19. if (Pics.Count < 1)
  20. {
  21. return;
  22. }
  23. var picGallery = Properties.Settings.Default.PicGallery;
  24. /// Toggle PicGallery, when not changed
  25. if (!change)
  26. {
  27. if (picGallery == 1)
  28. {
  29. if (!IsOpen)
  30. {
  31. OpenContainedGallery();
  32. }
  33. else
  34. {
  35. CloseContainedGallery();
  36. }
  37. }
  38. else
  39. {
  40. if (!IsOpen)
  41. {
  42. OpenFullscreenGallery();
  43. }
  44. else
  45. {
  46. CloseFullscreenGallery();
  47. }
  48. }
  49. }
  50. /// Toggle PicGallery, when changed
  51. else
  52. {
  53. if (picGallery == 1)
  54. {
  55. ChangeToPicGalleryTwo();
  56. }
  57. else
  58. {
  59. ChangeToPicGalleryOne();
  60. }
  61. }
  62. }
  63. #endregion Toggle
  64. #region Open
  65. internal static async void OpenContainedGallery()
  66. {
  67. if (Pics.Count < 1)
  68. {
  69. return;
  70. }
  71. Properties.Settings.Default.PicGallery = 1;
  72. LoadLayout();
  73. var da = new DoubleAnimation
  74. {
  75. Duration = TimeSpan.FromSeconds(.5),
  76. To = 1,
  77. From = 0
  78. };
  79. picGallery.BeginAnimation(UIElement.OpacityProperty, da);
  80. clickArrowLeft.Visibility =
  81. clickArrowRight.Visibility =
  82. x2.Visibility =
  83. minus.Visibility =
  84. galleryShortcut.Visibility = Visibility.Hidden;
  85. if (fakeWindow != null)
  86. {
  87. if (fakeWindow.grid.Children.Contains(picGallery))
  88. {
  89. fakeWindow.grid.Children.Remove(picGallery);
  90. mainWindow.bg.Children.Add(picGallery);
  91. }
  92. }
  93. ScrollTo();
  94. if (!IsLoading)
  95. {
  96. await Load().ConfigureAwait(false);
  97. }
  98. }
  99. internal static async void OpenFullscreenGallery()
  100. {
  101. if (Pics.Count < 1)
  102. {
  103. return;
  104. }
  105. Properties.Settings.Default.PicGallery = 2;
  106. LoadLayout();
  107. if (fakeWindow == null)
  108. {
  109. fakeWindow = new FakeWindow();
  110. }
  111. if (mainWindow.bg.Children.Contains(picGallery))
  112. {
  113. mainWindow.bg.Children.Remove(picGallery);
  114. fakeWindow.grid.Children.Add(picGallery);
  115. }
  116. else if (!fakeWindow.grid.Children.Contains(picGallery))
  117. {
  118. mainWindow.bg.Children.Remove(picGallery);
  119. fakeWindow.grid.Children.Add(picGallery);
  120. }
  121. fakeWindow.Show();
  122. ScrollTo();
  123. mainWindow.Focus();
  124. if (!FreshStartup)
  125. {
  126. ScaleImage.TryFitImage();
  127. }
  128. // Fix not showing up opacity bug..
  129. VisualStateManager.GoToElementState(picGallery, "Opacity", false);
  130. if (!IsLoading)
  131. {
  132. await Load().ConfigureAwait(false);
  133. }
  134. }
  135. #endregion Open
  136. #region Close
  137. internal static void CloseContainedGallery()
  138. {
  139. IsOpen = false;
  140. if (!Properties.Settings.Default.ShowInterface)
  141. {
  142. clickArrowLeft.Visibility =
  143. clickArrowRight.Visibility =
  144. x2.Visibility =
  145. minus.Visibility =
  146. galleryShortcut.Visibility = Visibility.Visible;
  147. }
  148. var da = new DoubleAnimation
  149. {
  150. Duration = TimeSpan.FromSeconds(.5),
  151. From = 1,
  152. To = 0,
  153. FillBehavior = FillBehavior.Stop
  154. };
  155. da.Completed += delegate
  156. {
  157. picGallery.Visibility = Visibility.Collapsed;
  158. picGallery.Opacity = 1;
  159. };
  160. picGallery.BeginAnimation(UIElement.OpacityProperty, da);
  161. }
  162. internal static void CloseFullscreenGallery()
  163. {
  164. Properties.Settings.Default.PicGallery = 1;
  165. IsOpen = false;
  166. fakeWindow.Hide();
  167. ConfigColors.UpdateColor();
  168. HideInterfaceLogic.ShowStandardInterface();
  169. }
  170. #endregion Close
  171. #region Change
  172. internal static void ChangeToPicGalleryOne()
  173. {
  174. Properties.Settings.Default.PicGallery = 1;
  175. LoadLayout();
  176. if (fakeWindow.grid.Children.Contains(picGallery))
  177. {
  178. fakeWindow.grid.Children.Remove(picGallery);
  179. mainWindow.bg.Children.Add(picGallery);
  180. }
  181. fakeWindow.Hide();
  182. }
  183. internal static void ChangeToPicGalleryTwo()
  184. {
  185. Properties.Settings.Default.PicGallery = 2;
  186. LoadLayout();
  187. if (fakeWindow != null)
  188. {
  189. if (!fakeWindow.grid.Children.Contains(picGallery))
  190. {
  191. mainWindow.bg.Children.Remove(picGallery);
  192. fakeWindow.grid.Children.Add(picGallery);
  193. }
  194. }
  195. else
  196. {
  197. mainWindow.bg.Children.Remove(picGallery);
  198. fakeWindow = new FakeWindow();
  199. fakeWindow.grid.Children.Add(picGallery);
  200. }
  201. fakeWindow.Show();
  202. ScrollTo();
  203. mainWindow.Focus();
  204. }
  205. #endregion Change
  206. }
  207. }