mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-12-24 02:00:55 +08:00
fix blur coordinate error
This commit is contained in:
47
QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs
Normal file
47
QuickLook/Controls/GlassLayer/ElementCoordinateConverter.cs
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@
|
||||
mc:Ignorable="d"
|
||||
x:Name="glassLayer"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.Resources>
|
||||
<local:ElementCoordinateConverter x:Key="ElementCoordinateConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Rectangle Panel.ZIndex="100" Visibility="{Binding ElementName=glassLayer, Path=NoiseVisibility}">
|
||||
<Rectangle.Fill>
|
||||
@@ -29,9 +32,10 @@
|
||||
Shader="pack://application:,,,/QuickLook;component/Controls/GlassLayer/GaussianBlur.ps" />
|
||||
</Grid.Effect>
|
||||
<Grid.Background>
|
||||
<VisualBrush Visual="{Binding ElementName=glassLayer, Path=BlurredElement}" AlignmentX="Left"
|
||||
AlignmentY="Top"
|
||||
Stretch="None" />
|
||||
<VisualBrush x:Name="brush" Visual="{Binding ElementName=glassLayer, Path=BlurredElement}"
|
||||
Viewbox="{Binding ElementName=glassLayer, Converter={StaticResource ElementCoordinateConverter}}"
|
||||
ViewboxUnits="Absolute"
|
||||
AlignmentX="Left" AlignmentY="Top" Stretch="None" />
|
||||
</Grid.Background>
|
||||
<StackPanel />
|
||||
</Grid>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Controls\BusyDecorator\ISpinable.cs" />
|
||||
<Compile Include="Controls\BusyDecorator\SpinIcon.cs" />
|
||||
<Compile Include="Controls\GlassLayer\ElementCoordinateConverter.cs" />
|
||||
<Compile Include="Controls\GlassLayer\GaussianBlurEffect.cs" />
|
||||
<Compile Include="Controls\GlassLayer\GlassLayer.xaml.cs">
|
||||
<DependentUpon>GlassLayer.xaml</DependentUpon>
|
||||
|
||||
Reference in New Issue
Block a user