【问题标题】:Too much calls paint method太多调用paint方法
【发布时间】:2016-06-27 12:50:57
【问题描述】:

我创建了一个测试组件

unit Control1;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls;

type
  TTestComp = class(TControl)
  private
    i: integer;
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Width;
    property Height;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Test', [TTestComp]);
end;

{ TTestComp }

constructor TTestComp.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  i := 0;
end;

procedure TTestComp.Paint;
begin
  inherited;
  inc(i);
  canvas.BeginScene;
  canvas.Fill.Color := $FF000000;
  canvas.FillRect(localrect, 0, 0, [], 1);
  canvas.Fill.Color := $FFFFFFFF;
  canvas.FillText(localrect, IntToStr(i), false, 1, [], TTextAlign.Center);
  canvas.EndScene;
end;

end.

问题来了:

  1. 组件在左上角绘制
  2. 调整表单大小时调用了过多的绘制方法。

刚刚调整大小的表格。

我有很多组件,都是按照这个原理构建的。当我改变表单的大小时,它们开始滞后(低 FPS)。

标准组件(TButton 等)工作正常

【问题讨论】:

  • 如何确定 Paint 调用次数过多?应该调用多少次,被调用多少次?
  • @DavidHeffernan 看看我的方法中的 Paint 过程。每次重新绘制时都会增加 var "I"。
  • 表示它被调用了多少次。如何确定应该调用多少次,以及为什么这个数字太大。

标签: delphi firemonkey delphi-xe7


【解决方案1】:

1.组件在左上角绘制

您的组件正在准确地绘制它所在的位置(Position 属性)。如果您没有为 Position.X 和 Position.Y 分配任何值,则默认值 0 用于两者。

2.调整表单大小时调用的paint方法过多。

当您调整表单大小时,所有组件都会重新绘制,f.ex 也是如此。纽扣。在对您的 81 个控件进行的测试中,我没有意识到任何滞后(但我假设您的实际控件比此示例控件执行的绘制更多)。

【讨论】:

    猜你喜欢
    • 2019-09-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2015-09-24
    相关资源
    最近更新 更多