|
|
@@ -1,4 +1,5 @@
|
|
|
using System;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
@@ -7,7 +8,6 @@ using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Animation;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
-using System.Windows.Shapes;
|
|
|
using System.Windows.Threading;
|
|
|
using static PicView.lib.ImageManager;
|
|
|
using static PicView.lib.Variables;
|
|
|
@@ -19,9 +19,14 @@ namespace PicView.lib.UserControls
|
|
|
/// </summary>
|
|
|
public partial class PicGallery : UserControl
|
|
|
{
|
|
|
+ #region Constructor, variables, loaded
|
|
|
+
|
|
|
public bool LoadComplete, isLoading, open;
|
|
|
+
|
|
|
public event MyEventHandler PreviewItemClick, ItemClick;
|
|
|
- int current_page, total_pages, items_per_page, horizontal_items, vertical_items;
|
|
|
+
|
|
|
+ private int current_page, total_pages, items_per_page, horizontal_items, vertical_items;
|
|
|
+
|
|
|
const int picGalleryItem_Size = 230;
|
|
|
|
|
|
//int next_page
|
|
|
@@ -43,12 +48,26 @@ namespace PicView.lib.UserControls
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
Loaded += PicGallery_Loaded;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PicGallery_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Scroller.PreviewMouseWheel += Scroller_MouseWheel;
|
|
|
+ Scroller.MouseDown += (s,x) => Application.Current.MainWindow.Focus();
|
|
|
x2.MouseLeftButtonUp += X2_MouseLeftButtonUp;
|
|
|
+ grid.MouseLeftButtonDown += (s,x) => Application.Current.MainWindow.Focus();
|
|
|
+
|
|
|
+ LoadComplete = isLoading = open = false;
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region animations
|
|
|
+
|
|
|
private void X2_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
- FadeOut();
|
|
|
+ if (Properties.Settings.Default.PicGallery == 1)
|
|
|
+ FadeOut();
|
|
|
}
|
|
|
|
|
|
private void FadeOut()
|
|
|
@@ -64,80 +83,37 @@ namespace PicView.lib.UserControls
|
|
|
open = false;
|
|
|
Visibility = Visibility.Collapsed;
|
|
|
};
|
|
|
- BeginAnimation(UIElement.OpacityProperty, da);
|
|
|
+ BeginAnimation(OpacityProperty, da);
|
|
|
}
|
|
|
|
|
|
- private void PicGallery_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- Scroller.PreviewMouseWheel += Scroller_MouseWheel;
|
|
|
- }
|
|
|
-
|
|
|
- private void Scroller_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
|
- {
|
|
|
- e.Handled = true;
|
|
|
- ScrollTo(e.Delta > 0);
|
|
|
- }
|
|
|
+ #endregion
|
|
|
|
|
|
internal void Calculate_Paging()
|
|
|
{
|
|
|
- horizontal_items = (int)Math.Ceiling(Width / picGalleryItem_Size);
|
|
|
- vertical_items = (int)Math.Ceiling(Container.ActualHeight / picGalleryItem_Size);
|
|
|
- items_per_page = horizontal_items * vertical_items;
|
|
|
- total_pages = (int)Math.Floor((double)Pics.Count / items_per_page);
|
|
|
- current_page = (int)Math.Floor((double)FolderIndex / items_per_page);
|
|
|
-
|
|
|
- //if (!string.IsNullOrWhiteSpace(PagingText.Text))
|
|
|
- // PagingText.Text = "";
|
|
|
-
|
|
|
- //for (int i = 0; i < total_pages; i++)
|
|
|
- //{
|
|
|
- // if (i > 5 && i < (total_pages - 1))
|
|
|
- // continue;
|
|
|
- // PagingText.Text += i;
|
|
|
- // PagingText.Text += " ";
|
|
|
- //}
|
|
|
- //ScrollTo();
|
|
|
- }
|
|
|
-
|
|
|
+ if (Container.ActualHeight == 0)
|
|
|
+ return;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Scrolls a page back or forth
|
|
|
- /// </summary>
|
|
|
- /// <param name="next"></param>
|
|
|
- /// <param name="end"></param>
|
|
|
- internal void ScrollTo(bool next, bool end = false)
|
|
|
- {
|
|
|
- if (end)
|
|
|
+ if (Properties.Settings.Default.PicGallery == 1)
|
|
|
{
|
|
|
- if (next)
|
|
|
- Scroller.ScrollToRightEnd();
|
|
|
- else
|
|
|
- Scroller.ScrollToLeftEnd();
|
|
|
+ horizontal_items = (int)Math.Ceiling(Width / picGalleryItem_Size);
|
|
|
+ vertical_items = (int)Math.Ceiling(Container.ActualHeight / picGalleryItem_Size);
|
|
|
+ items_per_page = horizontal_items * vertical_items;
|
|
|
+ total_pages = (int)Math.Floor((double)Pics.Count / items_per_page);
|
|
|
+ current_page = (int)Math.Floor((double)FolderIndex / items_per_page);
|
|
|
+ return;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- if (next)
|
|
|
- Scroller.ScrollToHorizontalOffset(Scroller.HorizontalOffset - picGalleryItem_Size);
|
|
|
- else
|
|
|
- Scroller.ScrollToHorizontalOffset(Scroller.HorizontalOffset + picGalleryItem_Size);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Scrolls to center of current item
|
|
|
- /// </summary>
|
|
|
- /// <param name="item">The index of picGalleryItem</param>
|
|
|
- internal void ScrollTo()
|
|
|
- {
|
|
|
- var x = (picGalleryItem_Size * horizontal_items) * current_page;
|
|
|
- Scroller.ScrollToHorizontalOffset(x);
|
|
|
+ vertical_items = Pics.Count;
|
|
|
+ items_per_page = (int)Math.Floor(Height / picGalleryItem_Size);
|
|
|
+ total_pages = (int)Math.Floor((double)Pics.Count / items_per_page);
|
|
|
+ current_page = (int)Math.Floor((double)FolderIndex / items_per_page);
|
|
|
}
|
|
|
|
|
|
- async void Add(BitmapSource pic, string file, int index)
|
|
|
+ private async void Add(BitmapSource pic, int index)
|
|
|
{
|
|
|
await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
|
|
|
{
|
|
|
- var item = new PicGalleryItem(pic, file);
|
|
|
+ var item = new PicGalleryItem(pic);
|
|
|
item.MouseLeftButtonUp += (s, x) => Click(index);
|
|
|
Container.Children.Add(item);
|
|
|
}));
|
|
|
@@ -150,16 +126,18 @@ namespace PicView.lib.UserControls
|
|
|
{
|
|
|
for (int i = 0; i < Pics.Count; i++)
|
|
|
{
|
|
|
- var file = Pics[i];
|
|
|
- var pic = GetBitmapSourceThumb(file);
|
|
|
+ var pic = GetBitmapSourceThumb(Pics[i]);
|
|
|
if (pic != null)
|
|
|
{
|
|
|
pic.Freeze();
|
|
|
- Add(pic, file, i);
|
|
|
+ Add(pic, i);
|
|
|
}
|
|
|
|
|
|
if (i == Pics.Count - 1)
|
|
|
+ {
|
|
|
LoadComplete = true;
|
|
|
+ isLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
t.Start();
|
|
|
@@ -178,69 +156,190 @@ namespace PicView.lib.UserControls
|
|
|
|
|
|
internal void Click(int id)
|
|
|
{
|
|
|
+ Application.Current.MainWindow.Focus();
|
|
|
PreviewItemClick(this, new MyEventArgs(id, null));
|
|
|
- var img = new Image()
|
|
|
+
|
|
|
+ if (Properties.Settings.Default.PicGallery == 1)
|
|
|
{
|
|
|
- Source = GetBitmapSourceThumb(Pics[id]),
|
|
|
- Stretch = Stretch.Fill,
|
|
|
- HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
- VerticalAlignment = VerticalAlignment.Center
|
|
|
- };
|
|
|
- var border = new Border()
|
|
|
+ var img = new Image()
|
|
|
+ {
|
|
|
+ Source = GetBitmapSourceThumb(Pics[id]),
|
|
|
+ Stretch = Stretch.Fill,
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
+ VerticalAlignment = VerticalAlignment.Center
|
|
|
+ };
|
|
|
+ var border = new Border()
|
|
|
+ {
|
|
|
+ BorderThickness = new Thickness(1),
|
|
|
+ BorderBrush = (SolidColorBrush)Application.Current.Resources["BorderBrush"],
|
|
|
+ Background = (SolidColorBrush)Application.Current.Resources["BackgroundColorBrush"]
|
|
|
+ };
|
|
|
+ border.Child = img;
|
|
|
+ grid.Children.Add(border);
|
|
|
+
|
|
|
+ var from = picGalleryItem_Size;
|
|
|
+ var to = new double[] { Application.Current.MainWindow.ActualWidth - 15, Application.Current.MainWindow.ActualHeight - 95 };
|
|
|
+
|
|
|
+ var da = new DoubleAnimation
|
|
|
+ {
|
|
|
+ From = from,
|
|
|
+ To = to[0],
|
|
|
+ Duration = TimeSpan.FromSeconds(.3),
|
|
|
+ AccelerationRatio = 0.2,
|
|
|
+ DecelerationRatio = 0.4
|
|
|
+ };
|
|
|
+
|
|
|
+ var da0 = new DoubleAnimation
|
|
|
+ {
|
|
|
+ From = from,
|
|
|
+ To = to[1],
|
|
|
+ Duration = TimeSpan.FromSeconds(.3),
|
|
|
+ AccelerationRatio = 0.2,
|
|
|
+ DecelerationRatio = 0.4
|
|
|
+ };
|
|
|
+
|
|
|
+ da.Completed += delegate
|
|
|
+ {
|
|
|
+ ItemClick(this, new MyEventArgs(id, img.Source));
|
|
|
+ grid.Children.Remove(border);
|
|
|
+ Visibility = Visibility.Collapsed;
|
|
|
+ picGallery.open = false;
|
|
|
+ };
|
|
|
+
|
|
|
+ img.BeginAnimation(WidthProperty, da);
|
|
|
+ img.BeginAnimation(HeightProperty, da0);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- BorderThickness = new Thickness(1),
|
|
|
- BorderBrush = (SolidColorBrush)Application.Current.Resources["BorderBrush"],
|
|
|
- Background = (SolidColorBrush)Application.Current.Resources["BackgroundColorBrush"]
|
|
|
- };
|
|
|
- border.Child = img;
|
|
|
- grid.Children.Add(border);
|
|
|
- var from = 230; // 230 = PicGalleryItem size
|
|
|
- //var to = new double[] { Width, Height };
|
|
|
- var to = new double[] { Application.Current.MainWindow.ActualWidth - 15, Application.Current.MainWindow.ActualHeight - 95 };
|
|
|
- //var to = new double[] { Application.Current.MainWindow.Width, Application.Current.MainWindow.Height};
|
|
|
- var da = new DoubleAnimation();
|
|
|
- da.From = from;
|
|
|
- da.To = to[0]; // Width
|
|
|
- da.Duration = TimeSpan.FromSeconds(.3);
|
|
|
- da.AccelerationRatio = 0.2;
|
|
|
- da.DecelerationRatio = 0.4;
|
|
|
-
|
|
|
- var da0 = new DoubleAnimation();
|
|
|
- da0.From = from;
|
|
|
- da0.To = to[1]; // Height
|
|
|
- da0.Duration = TimeSpan.FromSeconds(.3);
|
|
|
- da0.AccelerationRatio = 0.2;
|
|
|
- da0.DecelerationRatio = 0.4;
|
|
|
+ ItemClick(this, new MyEventArgs(id, GetBitmapSourceThumb(Pics[id])));
|
|
|
+ }
|
|
|
+ Application.Current.MainWindow.Focus();
|
|
|
+ }
|
|
|
|
|
|
- da.Completed += delegate
|
|
|
+ #region Scroll
|
|
|
+
|
|
|
+ private void Scroller_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
|
|
|
+ ScrollTo(e.Delta > 0, true);
|
|
|
+ else
|
|
|
+ ScrollTo(e.Delta > 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Scrolls a page back or forth
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="next"></param>
|
|
|
+ /// <param name="end"></param>
|
|
|
+ internal void ScrollTo(bool next, bool end = false, bool animate = false)
|
|
|
+ {
|
|
|
+ if (end)
|
|
|
{
|
|
|
- ItemClick(this, new MyEventArgs(id, img.Source));
|
|
|
- grid.Children.Remove(border);
|
|
|
- Visibility = Visibility.Collapsed;
|
|
|
- picGallery.open = false;
|
|
|
- };
|
|
|
+ if (next)
|
|
|
+ Scroller.ScrollToRightEnd();
|
|
|
+ else
|
|
|
+ Scroller.ScrollToLeftEnd();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var direction = next ? Scroller.HorizontalOffset + picGalleryItem_Size : Scroller.HorizontalOffset - picGalleryItem_Size;
|
|
|
|
|
|
+ if (Properties.Settings.Default.PicGallery == 1)
|
|
|
+ {
|
|
|
+ if (animate)
|
|
|
+ {
|
|
|
+ //var anim = new DoubleAnimation
|
|
|
+ //{
|
|
|
+ // From = Scroller.HorizontalOffset,
|
|
|
+ // To = direction,
|
|
|
+ // Duration = TimeSpan.FromSeconds(.3),
|
|
|
+ // AccelerationRatio = 0.2,
|
|
|
+ // DecelerationRatio = 0.4
|
|
|
+ //};
|
|
|
|
|
|
- img.BeginAnimation(Rectangle.WidthProperty, da);
|
|
|
- img.BeginAnimation(Rectangle.HeightProperty, da0);
|
|
|
+ //var sb = new Storyboard();
|
|
|
+ //sb.Children.Add(anim);
|
|
|
+ //Storyboard.SetTarget(anim, Scroller);
|
|
|
+ //Storyboard.SetTargetProperty(anim, new PropertyPath(ScrollAnimationBehavior.VerticalOffsetProperty))
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (next)
|
|
|
+ Scroller.ScrollToHorizontalOffset(direction);
|
|
|
+ else
|
|
|
+ Scroller.ScrollToHorizontalOffset(direction);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (animate)
|
|
|
+ {
|
|
|
+ //DoubleAnimation verticalAnimation = new DoubleAnimation
|
|
|
+ //{
|
|
|
+ // From = scrollViewer.VerticalOffset,
|
|
|
+ // To = some
|
|
|
+ //};
|
|
|
+ //value;
|
|
|
+ //verticalAnimation.Duration = new Duration(some duration);
|
|
|
+
|
|
|
+ //Storyboard storyboard = new Storyboard();
|
|
|
+
|
|
|
+ //storyboard.Children.Add(verticalAnimation);
|
|
|
+ //Storyboard.SetTarget(verticalAnimation, scrollViewer);
|
|
|
+ //Storyboard.SetTargetProperty(verticalAnimation, new PropertyPath(ScrollAnimationBehavior.VerticalOffsetProperty)); // Attached dependency property
|
|
|
+ //storyboard.Begin();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (next)
|
|
|
+ Scroller.ScrollToVerticalOffset(Scroller.VerticalOffset - picGalleryItem_Size);
|
|
|
+ else
|
|
|
+ Scroller.ScrollToVerticalOffset(Scroller.VerticalOffset + picGalleryItem_Size);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Scrolls to center of current item
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item">The index of picGalleryItem</param>
|
|
|
+ internal void ScrollTo()
|
|
|
+ {
|
|
|
+ if (Properties.Settings.Default.PicGallery == 1)
|
|
|
+ {
|
|
|
+ var x = (picGalleryItem_Size * horizontal_items) * current_page;
|
|
|
+ Scroller.ScrollToHorizontalOffset(x);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (vertical_items != 0)
|
|
|
+ {
|
|
|
+ var y = (picGalleryItem_Size * Pics.Count) * current_page;
|
|
|
+ Scroller.ScrollToVerticalOffset(y);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ #endregion Scroll
|
|
|
+ }
|
|
|
|
|
|
// Event
|
|
|
|
|
|
public delegate void MyEventHandler(object source, MyEventArgs e);
|
|
|
|
|
|
-
|
|
|
public class MyEventArgs : EventArgs
|
|
|
{
|
|
|
private int Id;
|
|
|
private ImageSource img;
|
|
|
+
|
|
|
public MyEventArgs(int Id, ImageSource img)
|
|
|
{
|
|
|
this.Id = Id;
|
|
|
this.img = img;
|
|
|
}
|
|
|
+
|
|
|
public int GetId()
|
|
|
{
|
|
|
return Id;
|
|
|
@@ -251,5 +350,4 @@ namespace PicView.lib.UserControls
|
|
|
return img;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+}
|