From 8e400e7ee5d702c0883da0bd44cad74bb8db9294 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Fri, 11 Aug 2017 20:14:45 +0300 Subject: [PATCH] fix blur coordinate error --- .../GlassLayer/ElementCoordinateConverter.cs | 47 +++++++++++++++++++ QuickLook/Controls/GlassLayer/GlassLayer.xaml | 10 ++-- .../Controls/GlassLayer/GlassLayer.xaml.cs | 6 +++ QuickLook/QuickLook.csproj | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs diff --git a/QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs b/QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs new file mode 100644 index 0000000..571d634 --- /dev/null +++ b/QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs @@ -0,0 +1,47 @@ +// Copyright © 2017 Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace QuickLook.Controls.GlassLayer +{ + public sealed class ElementCoordinateConverter : DependencyObject, IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var glass = (GlassLayer) value; + + if (glass?.BlurredElement == null) + return null; + + var target = glass.BlurredElement; + + var trans = glass.TransformToVisual(target); + var p = trans.Transform(new Point(0, 0)); + + return new Rect {X = p.X, Y = p.Y, Width = glass.ActualWidth, Height = glass.ActualHeight}; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/QuickLook/Controls/GlassLayer/GlassLayer.xaml b/QuickLook/Controls/GlassLayer/GlassLayer.xaml index 8e4f6e5..40c221d 100644 --- a/QuickLook/Controls/GlassLayer/GlassLayer.xaml +++ b/QuickLook/Controls/GlassLayer/GlassLayer.xaml @@ -7,6 +7,9 @@ mc:Ignorable="d" x:Name="glassLayer" d:DesignHeight="300" d:DesignWidth="300"> + + + @@ -29,9 +32,10 @@ Shader="pack://application:,,,/QuickLook;component/Controls/GlassLayer/GaussianBlur.ps" /> - + diff --git a/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs b/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs index b8991e8..e2800b6 100644 --- a/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs +++ b/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs @@ -17,6 +17,7 @@ using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Media; using QuickLook.Helpers; @@ -35,6 +36,11 @@ namespace QuickLook.Controls.GlassLayer noiseBrush.Viewport = new Rect(new Size( noiseBrush.ImageSource.Width / scale.Horizontal, noiseBrush.ImageSource.Height / scale.Vertical)); + + LayoutUpdated += (sender, e) => + { + BindingOperations.GetBindingExpressionBase(brush, TileBrush.ViewboxProperty)?.UpdateTarget(); + }; } #region public Visual BlurredElement diff --git a/QuickLook/QuickLook.csproj b/QuickLook/QuickLook.csproj index 5671d63..97a06e5 100644 --- a/QuickLook/QuickLook.csproj +++ b/QuickLook/QuickLook.csproj @@ -111,6 +111,7 @@ + GlassLayer.xaml