二维图形的矩阵变换(三)——在WPF中的应用矩阵变换
2016-03-20 16:24
417 查看
原文:二维图形的矩阵变换(三)——在WPF中的应用矩阵变换UIElement和RenderTransform
首先,我们来看看什么样的对象可以进行变换。在WPF中,用于呈现给用户的对象的基类为Visual类,但是Visual对象并不具有变换功能,具有变换功能的是它的子类UIElement。这个类也是非常底层的类了,几乎我们所有的常用控件都是继承自它,也就是说,基本上所有的UI对象都是可以应用变换的。
然后,我们在再来看看UIElement中变换种类。UIElement支持两种变换:RenderTransform和LayoutTransform,其中LayoutTransform是会改变其布局,从而影响相邻的空间大小和位置的,如下图所示。
View Code
首先,我们来看看什么样的对象可以进行变换。在WPF中,用于呈现给用户的对象的基类为Visual类,但是Visual对象并不具有变换功能,具有变换功能的是它的子类UIElement。这个类也是非常底层的类了,几乎我们所有的常用控件都是继承自它,也就是说,基本上所有的UI对象都是可以应用变换的。
然后,我们在再来看看UIElement中变换种类。UIElement支持两种变换:RenderTransform和LayoutTransform,其中LayoutTransform是会改变其布局,从而影响相邻的空间大小和位置的,如下图所示。
public class MatrixAnimation : MatrixAnimationBase { public Matrix? From { set { SetValue(FromProperty, value); } get { return (Matrix?)GetValue(FromProperty); } } public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(Matrix?), typeof(MatrixAnimation), new PropertyMetadata(null)); public Matrix? To { set { SetValue(ToProperty, value); } get { return (Matrix?)GetValue(ToProperty); } } public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(Matrix?), typeof(MatrixAnimation), new PropertyMetadata(null)); public IEasingFunction EasingFunction { get { return (IEasingFunction)GetValue(EasingFunctionProperty); } set { SetValue(EasingFunctionProperty, value); } } public static readonly DependencyProperty EasingFunctionProperty = DependencyProperty.Register("EasingFunction", typeof(IEasingFunction), typeof(MatrixAnimation), new UIPropertyMetadata(null)); public MatrixAnimation() { } public MatrixAnimation(Matrix toValue, Duration duration) { To = toValue; Duration = duration; } public MatrixAnimation(Matrix toValue, Duration duration, FillBehavior fillBehavior) { To = toValue; Duration = duration; FillBehavior = fillBehavior; } public MatrixAnimation(Matrix fromValue, Matrix toValue, Duration duration) { From = fromValue; To = toValue; Duration = duration; } public MatrixAnimation(Matrix fromValue, Matrix toValue, Duration duration, FillBehavior fillBehavior) { From = fromValue; To = toValue; Duration = duration; FillBehavior = fillBehavior; } protected override Freezable CreateInstanceCore() { return new MatrixAnimation(); } protected override Matrix GetCurrentValueCore(Matrix defaultOriginValue, Matrix defaultDestinationValue, AnimationClock animationClock) { if (animationClock.CurrentProgress == null) { return Matrix.Identity; } var normalizedTime = animationClock.CurrentProgress.Value; if (EasingFunction != null) { normalizedTime = EasingFunction.Ease(normalizedTime); } var from = From ?? defaultOriginValue; var to = To ?? defaultDestinationValue; var newMatrix = new Matrix( ((to.M11 - from.M11) * normalizedTime) + from.M11, ((to.M12 - from.M12) * normalizedTime) + from.M12, ((to.M21 - from.M21) * normalizedTime) + from.M21, ((to.M22 - from.M22) * normalizedTime) + from.M22, ((to.OffsetX - from.OffsetX) * normalizedTime) + from.OffsetX, ((to.OffsetY - from.OffsetY) * normalizedTime) + from.OffsetY); return newMatrix; } }
View Code
相关文章推荐
- 二维图形的矩阵变换(三)——在WPF中的应用矩阵变换
- 关于git托管的一些心得
- SVD:奇异值分解
- ansible playbook实战——下发部署nginx以及更新、回滚
- DOM事件处理程序学习随笔1(IMOOC)
- Java String理解
- hdu2079选课时间(背包)
- getParameter和getParameterValues
- 二维图形的矩阵变换(二)——WPF中的矩阵变换基础
- java集合框架——Map
- Hibernate逍遥游记-第9章 Hibernate的映射类型
- 97. Interleaving String
- 安卓基础:自定义控件实现ViewPager指示器
- Servlet 工作原理解析
- File类通过递归列出目录的结构
- 二维图形的矩阵变换(一)——基本概念
- 关于css中的opacity
- 《Java高级程序设计》第二次作业
- Android手机内存
- BZOJ-1879 Bill的挑战 状态压缩DP