GalleryStretch.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using Avalonia.Media;
  2. using PicView.Avalonia.ViewModels;
  3. namespace PicView.Avalonia.Gallery;
  4. public static class GalleryStretchMode
  5. {
  6. public static void DetermineStretchMode(MainViewModel vm)
  7. {
  8. // Reset all boolean properties
  9. vm.Gallery.IsUniformMenuChecked.Value = false;
  10. vm.Gallery.IsUniformBottomChecked.Value = false;
  11. vm.Gallery.IsUniformFullChecked.Value = false;
  12. vm.Gallery.IsUniformToFillMenuChecked.Value = false;
  13. vm.Gallery.IsUniformToFillBottomChecked.Value = false;
  14. vm.Gallery.IsUniformToFillFullChecked.Value = false;
  15. vm.Gallery.IsFillMenuChecked.Value = false;
  16. vm.Gallery.IsFillBottomChecked.Value = false;
  17. vm.Gallery.IsFillFullChecked.Value = false;
  18. vm.Gallery.IsNoneMenuChecked.Value = false;
  19. vm.Gallery.IsNoneBottomChecked.Value = false;
  20. vm.Gallery.IsNoneFullChecked.Value = false;
  21. vm.Gallery.IsSquareMenuChecked.Value = false;
  22. vm.Gallery.IsSquareBottomChecked.Value = false;
  23. vm.Gallery.IsSquareFullChecked.Value = false;
  24. vm.Gallery.IsFillSquareMenuChecked.Value = false;
  25. vm.Gallery.IsFillSquareBottomChecked.Value = false;
  26. vm.Gallery.IsFillSquareFullChecked.Value = false;
  27. if (Settings.Gallery.FullGalleryStretchMode.Equals("Square", StringComparison.OrdinalIgnoreCase))
  28. {
  29. vm.Gallery.IsSquareFullChecked.Value = true;
  30. if (GalleryFunctions.IsFullGalleryOpen)
  31. {
  32. vm.Gallery.IsSquareMenuChecked.Value = true;
  33. SetSquareStretch(vm);
  34. }
  35. }
  36. else if (Settings.Gallery.FullGalleryStretchMode.Equals("FillSquare", StringComparison.OrdinalIgnoreCase))
  37. {
  38. vm.Gallery.IsFillSquareFullChecked.Value = true;
  39. if (GalleryFunctions.IsFullGalleryOpen)
  40. {
  41. vm.Gallery.IsFillSquareMenuChecked.Value = true;
  42. SetSquareFillStretch(vm);
  43. }
  44. }
  45. else if (Enum.TryParse<Stretch>(Settings.Gallery.FullGalleryStretchMode, out var stretchMode))
  46. {
  47. SetStretchIsChecked(stretchMode, true);
  48. if (GalleryFunctions.IsFullGalleryOpen)
  49. {
  50. SetGalleryStretch(vm, stretchMode);
  51. }
  52. }
  53. else
  54. {
  55. vm.Gallery.GalleryItem.ItemWidth.Value = double.NaN;
  56. if (GalleryFunctions.IsFullGalleryOpen)
  57. {
  58. vm.Gallery.IsUniformMenuChecked.Value = true;
  59. SetGalleryStretch(vm, Stretch.Uniform);
  60. }
  61. vm.Gallery.IsUniformFullChecked.Value = true;
  62. }
  63. if (Settings.Gallery.BottomGalleryStretchMode.Equals("Square", StringComparison.OrdinalIgnoreCase))
  64. {
  65. vm.Gallery.IsSquareBottomChecked.Value = true;
  66. if (!GalleryFunctions.IsFullGalleryOpen)
  67. {
  68. vm.Gallery.IsSquareMenuChecked.Value = true;
  69. SetSquareStretch(vm);
  70. }
  71. }
  72. else if (Settings.Gallery.BottomGalleryStretchMode.Equals("FillSquare", StringComparison.OrdinalIgnoreCase))
  73. {
  74. vm.Gallery.IsFillSquareBottomChecked.Value = true;
  75. if (!GalleryFunctions.IsFullGalleryOpen)
  76. {
  77. vm.Gallery.IsFillSquareMenuChecked.Value = true;
  78. SetSquareFillStretch(vm);
  79. }
  80. }
  81. else if (Enum.TryParse<Stretch>(Settings.Gallery.BottomGalleryStretchMode, out var stretchMode))
  82. {
  83. SetStretchIsChecked(stretchMode, false);
  84. if (!GalleryFunctions.IsFullGalleryOpen)
  85. {
  86. SetGalleryStretch(vm, stretchMode);
  87. }
  88. }
  89. else
  90. {
  91. vm.Gallery.IsUniformBottomChecked.Value = true;
  92. if (!GalleryFunctions.IsFullGalleryOpen)
  93. {
  94. vm.Gallery.IsUniformMenuChecked.Value = true;
  95. SetGalleryStretch(vm, Stretch.Uniform);
  96. }
  97. }
  98. return;
  99. void SetStretchIsChecked(Stretch stretchMode, bool isFullGallery)
  100. {
  101. switch (stretchMode)
  102. {
  103. case Stretch.Uniform:
  104. if (GalleryFunctions.IsFullGalleryOpen)
  105. {
  106. vm.Gallery.IsUniformFullChecked.Value = true;
  107. if (isFullGallery)
  108. {
  109. vm.Gallery.IsUniformMenuChecked.Value = true;
  110. }
  111. }
  112. else
  113. {
  114. vm.Gallery.IsUniformBottomChecked.Value = true;
  115. if (!isFullGallery)
  116. {
  117. vm.Gallery.IsUniformMenuChecked.Value = true;
  118. }
  119. }
  120. break;
  121. case Stretch.UniformToFill:
  122. if (GalleryFunctions.IsFullGalleryOpen)
  123. {
  124. vm.Gallery.IsUniformToFillFullChecked.Value = true;
  125. if (isFullGallery)
  126. {
  127. vm.Gallery.IsUniformToFillMenuChecked.Value = true;
  128. }
  129. }
  130. else
  131. {
  132. vm.Gallery.IsUniformToFillBottomChecked.Value = true;
  133. if (!isFullGallery)
  134. {
  135. vm.Gallery.IsUniformToFillMenuChecked.Value = true;
  136. }
  137. }
  138. break;
  139. case Stretch.Fill:
  140. if (GalleryFunctions.IsFullGalleryOpen)
  141. {
  142. vm.Gallery.IsFillFullChecked.Value = true;
  143. if (isFullGallery)
  144. {
  145. vm.Gallery.IsFillMenuChecked.Value = true;
  146. }
  147. }
  148. else
  149. {
  150. vm.Gallery.IsFillBottomChecked.Value = true;
  151. if (!isFullGallery)
  152. {
  153. vm.Gallery.IsFillMenuChecked.Value = true;
  154. }
  155. }
  156. break;
  157. case Stretch.None:
  158. if (GalleryFunctions.IsFullGalleryOpen)
  159. {
  160. vm.Gallery.IsNoneFullChecked.Value = true;
  161. if (isFullGallery)
  162. {
  163. vm.Gallery.IsNoneMenuChecked.Value = true;
  164. }
  165. }
  166. else
  167. {
  168. vm.Gallery.IsNoneBottomChecked.Value = true;
  169. if (!isFullGallery)
  170. {
  171. vm.Gallery.IsNoneMenuChecked.Value = true;
  172. }
  173. }
  174. break;
  175. default:
  176. if (!GalleryFunctions.IsFullGalleryOpen)
  177. {
  178. vm.Gallery.IsUniformMenuChecked.Value = true;
  179. }
  180. vm.Gallery.IsUniformFullChecked.Value = true;
  181. vm.Gallery.IsUniformBottomChecked.Value = true;
  182. break;
  183. }
  184. }
  185. }
  186. public static void SetGalleryStretch(MainViewModel vm, Stretch stretch)
  187. {
  188. vm.Gallery.GalleryItem.ItemWidth.Value = double.NaN;
  189. vm.Gallery.GalleryStretch.Value = stretch;
  190. }
  191. public static void SetSquareStretch(MainViewModel vm)
  192. {
  193. vm.Gallery.GalleryItem.ItemWidth.Value = vm.Gallery.GalleryItem.ItemHeight.Value;
  194. vm.Gallery.GalleryStretch.Value = Stretch.Uniform;
  195. }
  196. public static void SetSquareFillStretch(MainViewModel vm)
  197. {
  198. vm.Gallery.GalleryItem.ItemWidth.Value = vm.Gallery.GalleryItem.ItemHeight.Value;;
  199. vm.Gallery.GalleryStretch.Value = Stretch.Fill;
  200. }
  201. public static void ChangeBottomGalleryItemStretch(MainViewModel vm, Stretch stretch)
  202. {
  203. SetGalleryStretch(vm, stretch);
  204. Settings.Gallery.BottomGalleryStretchMode = stretch.ToString();
  205. }
  206. public static void ChangeFullGalleryItemStretch(MainViewModel vm, Stretch stretch)
  207. {
  208. SetGalleryStretch(vm, stretch);
  209. Settings.Gallery.FullGalleryStretchMode = stretch.ToString();
  210. }
  211. public static void ChangeBottomGalleryStretchSquare(MainViewModel vm)
  212. {
  213. SetSquareStretch(vm);
  214. Settings.Gallery.BottomGalleryStretchMode = "Square";
  215. }
  216. public static void ChangeBottomGalleryStretchSquareFill(MainViewModel vm)
  217. {
  218. SetSquareFillStretch(vm);
  219. Settings.Gallery.BottomGalleryStretchMode = "FillSquare";
  220. }
  221. public static void ChangeFullGalleryStretchSquare(MainViewModel vm)
  222. {
  223. SetSquareStretch(vm);
  224. Settings.Gallery.FullGalleryStretchMode = "Square";
  225. }
  226. public static void ChangeFullGalleryStretchSquareFill(MainViewModel vm)
  227. {
  228. SetSquareFillStretch(vm);
  229. Settings.Gallery.FullGalleryStretchMode = "FillSquare";
  230. }
  231. }