zoukankan      html  css  js  c++  java
  • FMX.Controls单元 中图形矩阵变换

    procedure TControl.DoMatrixChanged(Sender: TObject);
    var
    TranslateMatrix, ScaleMatrix, RotMatrix: TMatrix;
    M1, M2: TMatrix;
    begin
    if (not FInPaintTo) and not IsUpdating then
    Repaint;
    if SameValue(FScale.X, 1.0, TEpsilon.Scale) and SameValue(FScale.Y, 1.0, TEpsilon.Scale) and SameValue(FRotationAngle, 0.0, TEpsilon.Scale) then
    begin
    if (FParentControl <> nil) and not FParentControl.FSimpleTransform then
    FSimpleTransform := False
    else
    FSimpleTransform := True;
    end
    else
    FSimpleTransform := False;

    if not FSimpleTransform then
    begin
    if not SameValue(FRotationAngle, 0.0, TEpsilon.Scale) then
    begin
    // scale
    ScaleMatrix := TMatrix.Identity;
    ScaleMatrix.m11 := FScale.X;
    ScaleMatrix.m22 := FScale.Y;
    FLocalMatrix := ScaleMatrix;
    // rotation
    if FRotationAngle <> 0 then
    begin
    M1 := TMatrix.Identity;
    M1.m31 := -FRotationCenter.X * FSize.Width * FScale.X;
    M1.m32 := -FRotationCenter.Y * FSize.Height * FScale.Y;
    M2 := TMatrix.Identity;
    M2.m31 := FRotationCenter.X * FSize.Width * FScale.X;
    M2.m32 := FRotationCenter.Y * FSize.Height * FScale.Y;
    RotMatrix := M1 * (TMatrix.CreateRotation(DegToRad(FRotationAngle)) * M2);
    FLocalMatrix := FLocalMatrix * RotMatrix;
    end;
    // translate
    TranslateMatrix := TMatrix.Identity;
    TranslateMatrix.m31 := FPosition.X;
    TranslateMatrix.m32 := FPosition.Y;
    FLocalMatrix := FLocalMatrix * TranslateMatrix;
    end
    else
    begin
    FLocalMatrix := TMatrix.Identity;
    FLocalMatrix.m31 := FPosition.X;
    FLocalMatrix.m32 := FPosition.Y;
    FLocalMatrix.m11 := FScale.X;
    FLocalMatrix.m22 := FScale.Y;
    end;
    end
    else
    begin
    FLocalMatrix := TMatrix.Identity;
    FLocalMatrix.m31 := FPosition.X;
    FLocalMatrix.m32 := FPosition.Y;
    end;

    RecalcAbsolute;
    RecalcUpdateRect;
    if HasDisablePaintEffect then
    UpdateEffects;
    if Visible and (ParentContent <> nil) then
    ParentContent.Changed;
    if not FAnchorMove then
    begin
    UpdateExplicitBounds;
    UpdateAnchorRules(True);
    end;
    if (not FInPaintTo) and not IsUpdating then
    Repaint;
    end;

    procedure TControl.DoMatrixChanged(Sender: TObject);
    var
    TranslateMatrix, ScaleMatrix, RotMatrix: TMatrix;
    M1, M2: TMatrix;
    begin
    if (not FInPaintTo) and not IsUpdating then
    Repaint;
    if SameValue(FScale.X, 1.0, TEpsilon.Scale) and SameValue(FScale.Y, 1.0, TEpsilon.Scale) and SameValue(FRotationAngle, 0.0, TEpsilon.Scale) then
    begin
    if (FParentControl <> nil) and not FParentControl.FSimpleTransform then
    FSimpleTransform := False
    else
    FSimpleTransform := True;
    end
    else
    FSimpleTransform := False;

    if not FSimpleTransform then
    begin
    if not SameValue(FRotationAngle, 0.0, TEpsilon.Scale) then
    begin
    // scale
    ScaleMatrix := TMatrix.Identity;
    ScaleMatrix.m11 := FScale.X;
    ScaleMatrix.m22 := FScale.Y;
    FLocalMatrix := ScaleMatrix;
    // rotation
    if FRotationAngle <> 0 then
    begin
    M1 := TMatrix.Identity;
    M1.m31 := -FRotationCenter.X * FSize.Width * FScale.X;
    M1.m32 := -FRotationCenter.Y * FSize.Height * FScale.Y;
    M2 := TMatrix.Identity;
    M2.m31 := FRotationCenter.X * FSize.Width * FScale.X;
    M2.m32 := FRotationCenter.Y * FSize.Height * FScale.Y;
    RotMatrix := M1 * (TMatrix.CreateRotation(DegToRad(FRotationAngle)) * M2);
    FLocalMatrix := FLocalMatrix * RotMatrix;
    end;
    // translate
    TranslateMatrix := TMatrix.Identity;
    TranslateMatrix.m31 := FPosition.X;
    TranslateMatrix.m32 := FPosition.Y;
    FLocalMatrix := FLocalMatrix * TranslateMatrix;
    end
    else
    begin
    FLocalMatrix := TMatrix.Identity;
    FLocalMatrix.m31 := FPosition.X;
    FLocalMatrix.m32 := FPosition.Y;
    FLocalMatrix.m11 := FScale.X;
    FLocalMatrix.m22 := FScale.Y;
    end;
    end
    else
    begin
    FLocalMatrix := TMatrix.Identity;
    FLocalMatrix.m31 := FPosition.X;
    FLocalMatrix.m32 := FPosition.Y;
    end;

    RecalcAbsolute;
    RecalcUpdateRect;
    if HasDisablePaintEffect then
    UpdateEffects;
    if Visible and (ParentContent <> nil) then
    ParentContent.Changed;
    if not FAnchorMove then
    begin
    UpdateExplicitBounds;
    UpdateAnchorRules(True);
    end;
    if (not FInPaintTo) and not IsUpdating then
    Repaint;
    end;

  • 相关阅读:
    今天学到的新知识自己的电脑可以像Github Pages、码云 Pages一样发布静态资源
    移动端安卓开发学习记录Android Studio打断点调试操作步骤记录
    图文并茂学习记录从零开始进行微信小程序开发+引入Vant Weapp组件
    代码小DEMO随笔JS原生手机版本alert弹框
    移动端安卓开发学习记录Android Studio使用adb链接夜神模拟器常用指令
    图文并茂的学习笔记微信小程序自定义tabbar
    解决微信小程序 自定义tabBar 切换时候闪烁问题
    App扫码登录
    TypeScript 参数简化实战(进阶知识点conditional types) 广东靓仔
    前端进阶指南(优秀文章) 广东靓仔
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/10069113.html
Copyright © 2011-2022 走看看