• 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;

  • 相关阅读:
    iPhone 上利用MKMapView实现简单地图的方法
    项目经理:做好项目开始阶段的九条经验(1) 项目 技术应用
    iPhone的Push(推送通知)功能原理浅析
    iPhone拍照/摄像软件开发实例
    每位开发人员都应铭记的10句编程谚语
    注册itunes 中国区app Store账号详细步骤
    [转载]:各位技术牛人和应届毕业生,外企是唯一的选择吗?
    [推荐] IT外企那点儿事(1):外企也就那么回事[
    CheckBox全选与不全选(不用刷新页面)
    CheckBox的全选与不全选(刷新页面效果) .
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/10069113.html
Copyright © 2020-2023  润新知