mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
done new image viewer
This commit is contained in:
@@ -15,18 +15,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using QuickLook.Common.Annotations;
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Plugin;
|
||||
|
||||
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
{
|
||||
@@ -38,9 +34,6 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
private AnimationProvider _animation;
|
||||
private bool _disposing;
|
||||
|
||||
public event EventHandler ImageLoaded;
|
||||
public event EventHandler DoZoomToFit;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposing = true;
|
||||
@@ -52,12 +45,15 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
_animation = null;
|
||||
}
|
||||
|
||||
private static AnimationProvider LoadFullImageCore(Uri path)
|
||||
public event EventHandler ImageLoaded;
|
||||
public event EventHandler DoZoomToFit;
|
||||
|
||||
private static AnimationProvider LoadFullImageCore(Uri path, NConvert meta)
|
||||
{
|
||||
var ext = Path.GetExtension(path.LocalPath).ToLower();
|
||||
var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value;
|
||||
|
||||
var provider = type.CreateInstance<AnimationProvider>(path.LocalPath);
|
||||
var provider = type.CreateInstance<AnimationProvider>(path.LocalPath, meta);
|
||||
|
||||
return provider;
|
||||
}
|
||||
@@ -66,7 +62,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
|
||||
public static readonly DependencyProperty AnimationFrameIndexProperty =
|
||||
DependencyProperty.Register("AnimationFrameIndex", typeof(int), typeof(AnimatedImage),
|
||||
new UIPropertyMetadata(-2, AnimationFrameIndexChanged));
|
||||
new UIPropertyMetadata(-1, AnimationFrameIndexChanged));
|
||||
|
||||
public static readonly DependencyProperty AnimationUriProperty =
|
||||
DependencyProperty.Register("AnimationUri", typeof(Uri), typeof(AnimatedImage),
|
||||
@@ -80,25 +76,25 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
|
||||
public int AnimationFrameIndex
|
||||
{
|
||||
get => (int)GetValue(AnimationFrameIndexProperty);
|
||||
get => (int) GetValue(AnimationFrameIndexProperty);
|
||||
set => SetValue(AnimationFrameIndexProperty, value);
|
||||
}
|
||||
|
||||
public Uri AnimationUri
|
||||
{
|
||||
get => (Uri)GetValue(AnimationUriProperty);
|
||||
get => (Uri) GetValue(AnimationUriProperty);
|
||||
set => SetValue(AnimationUriProperty, value);
|
||||
}
|
||||
|
||||
public NConvert Meta
|
||||
{
|
||||
private get => (NConvert)GetValue(MetaProperty);
|
||||
private get => (NConvert) GetValue(MetaProperty);
|
||||
set => SetValue(MetaProperty, value);
|
||||
}
|
||||
|
||||
public ContextObject ContextObject
|
||||
{
|
||||
private get => (ContextObject)GetValue(ContextObjectProperty);
|
||||
private get => (ContextObject) GetValue(ContextObjectProperty);
|
||||
set => SetValue(ContextObjectProperty, value);
|
||||
}
|
||||
|
||||
@@ -110,10 +106,27 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
//var thumbnail = instance.Meta?.GetThumbnail(true);
|
||||
//instance.Source = thumbnail;
|
||||
|
||||
instance._animation = LoadFullImageCore((Uri)ev.NewValue);
|
||||
instance._animation = LoadFullImageCore((Uri) ev.NewValue, instance.Meta);
|
||||
ShowThumbnailAndStartAnimation(instance);
|
||||
}
|
||||
|
||||
instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation.Animator);
|
||||
instance.AnimationFrameIndex = -1;
|
||||
private static void ShowThumbnailAndStartAnimation(AnimatedImage instance)
|
||||
{
|
||||
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize, instance.Meta.GetSize());
|
||||
if (task == null) return;
|
||||
|
||||
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (instance._disposing)
|
||||
return;
|
||||
|
||||
instance.Source = _.Result;
|
||||
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
|
||||
instance.ImageLoaded?.Invoke(instance, new EventArgs());
|
||||
|
||||
instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation?.Animator);
|
||||
}));
|
||||
task.Start();
|
||||
}
|
||||
|
||||
private static void AnimationFrameIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs ev)
|
||||
@@ -124,32 +137,14 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
if (instance._disposing)
|
||||
return;
|
||||
|
||||
var task = instance._animation.GetRenderedFrame((int) ev.NewValue);
|
||||
|
||||
if ((int)ev.NewValue == -1) // get thumbnail
|
||||
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize, instance.Meta.GetSize());
|
||||
|
||||
if (task != null)
|
||||
{
|
||||
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
|
||||
{
|
||||
instance.Source = _.Result;
|
||||
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
|
||||
instance.ImageLoaded?.Invoke(instance, new EventArgs());
|
||||
}));
|
||||
task.Start();
|
||||
}
|
||||
}
|
||||
else // begin to loop in the animator
|
||||
{
|
||||
var task = instance._animation.GetRenderedFrame((int)ev.NewValue);
|
||||
|
||||
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (!instance._disposing)
|
||||
instance.Source = _.Result;
|
||||
}));
|
||||
task.Start();
|
||||
}
|
||||
}));
|
||||
task.Start();
|
||||
}
|
||||
|
||||
#endregion DependencyProperty
|
||||
|
Reference in New Issue
Block a user