2

使用 poUnbuffered 选项时,TVirtualStringTree 中的 PaintTree 逻辑似乎存在错误。只有树的第一个节点在输出中可见。我使用 Minimal VST 示例进行了测试,并且行为是相同的。当 poUnbuffered 用作选项时,只有第一个节点可见,删除该选项并正确绘制树。

如果我单步执行代码,那么所有对象都被绘制在画布上,所以它看起来像是一个剪切问题,但我使用 VST 的工作不足以确定问题所在。他们在画布原点和剪裁方面发挥了很多作用。

要查看实际问题,只需将以下代码放在包含 VST 的任何表单上,根据需要更改名称以保护无辜者,然后单击离开。

procedure TMainForm.Button2Click(Sender: TObject);
var
  saveBitmap: TBitmap;
begin
  saveBitmap := TBitmap.Create;
  try
    saveBitmap.height := 400;
    saveBitmap.width := 400;

    vst.PaintTree(
      saveBitmap.Canvas,
      Rect(0, 0, 400, 400),
      Point(0, 0),
      [poBackground, poColumnColor, poGridLines, poUnbuffered], // Remove poUnbuffered to have the tree paint correctly
      pfDevice     // pixelformat
      );

    saveBitmap.SaveToFile('E:\temp\CanvasSave' + FormatDateTime('hhnnsszzz', Now) + '.bmp');
  finally
    saveBitmap.Free; 
  end;
end;

有没有人遇到过这个?

更多细节:

poUnbuffered 的绘制代码和没有它的绘制代码之间几乎没有区别。我没有使用列,所以主要区别是:

  if not (poUnbuffered in PaintOptions) then
  begin
    // Create small bitmaps and initialize default values.
    // The bitmaps are used to paint one node at a time and to draw the result to the target (e.g. screen) in one step,
    // to prevent flickering.
    NodeBitmap := TBitmap.Create;
    // For alpha blending we need the 32 bit pixel format. For other targets there might be a need for a certain
    // pixel format (e.g. printing).
    if MMXAvailable and ((FDrawSelectionMode = smBlendedRectangle) or (tsUseThemes in FStates) or
      (toUseBlendedSelection in FOptions.PaintOptions)) then
      NodeBitmap.PixelFormat := pf32Bit
    else
      NodeBitmap.PixelFormat := PixelFormat;

    NodeBitmap.Width := PaintWidth;

    // Make sure the buffer bitmap and target bitmap use the same transformation mode.
    SetMapMode(NodeBitmap.Canvas.Handle, GetMapMode(TargetCanvas.Handle));
    PaintInfo.Canvas := NodeBitmap.Canvas;
  end
  else
  begin
    PaintInfo.Canvas := TargetCanvas;
    NodeBitmap := nil;
  end;

          if not (poUnbuffered in PaintOptions) then
          begin
            // Adjust height of temporary node bitmap.
            with NodeBitmap do
            begin
              if Height <> PaintInfo.Node.NodeHeight then
              begin
                // Avoid that the VCL copies the bitmap while changing its height.
                Height := 0;
                Height := PaintInfo.Node.NodeHeight;
                SetCanvasOrigin(Canvas, Window.Left, 0);
              end;
            end;
          end
          else
          begin
            SetCanvasOrigin(PaintInfo.Canvas, -TargetRect.Left + Window.Left, -TargetRect.Top);
            ClipCanvas(PaintInfo.Canvas, Rect(TargetRect.Left, TargetRect.Top, TargetRect.Right,
                                              Min(TargetRect.Bottom, MaximumBottom)))
          end;

在不使用 poUnbuffered 时,稍后有几个 BitBlt 将位图复制到画布上。

4

1 回答 1

1

这是我从另一个关于 PaintTree 代码和 poUnbuffered 的问题中发现的问题的解决方法。我在上面列出的第二个代码摘录中显然存在问题。显然 SetCanvasOrigin 正在更改原点,而 ClipCanvas 没有考虑这些更改。代码应更改如下:

      begin
        SetCanvasOrigin(PaintInfo.Canvas, -TargetRect.Left + Window.Left, -TargetRect.Top);
        // ClipCanvas(PaintInfo.Canvas, Rect(TargetRect.Left, TargetRect.Top, TargetRect.Right,
        //                                   Min(TargetRect.Bottom, MaximumBottom)))
        ClipCanvas(PaintInfo.Canvas, Rect(0, 0, TargetRect.Right - TargetRect.Left,
                                          Min(TargetRect.Bottom - TargetRect.Top, MaximumBottom - TargetRect.Top)));
      end;

我已经验证这适用于我的情况。它可能不适用于所有情况。在我的情况下,我只在这种情况下使用 poUnbuffered,所以我的风险是有限的。

于 2014-02-27T01:22:43.683 回答