Vlark.Lopin
Vlark.Lopin

Reputation: 792

how to draw nodes inline in TvirualTree?

I am currently drawing some images inside Tvirtualdrawtree using on before paint. Here is my drawing code

procedure TForm2.VDTAniBeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
  Data: PAnimeData;
  NewRect: TRect;
  R: TRect;
begin
//
  if not Assigned(Node) then
  begin
    exit;
  end;

  Data := VDTAni.GetNodeData(Node);

  case Column of
    0, 1 ,2, 3, 4, 5, 6, 7:
  begin
  TargetCanvas.Brush.Style := bsClear;
  TargetCanvas.FillRect(CellRect);
  NewRect := ContentRect;
  NewRect.Left := NewRect.Left;
  NewRect.Width := 55;
  NewRect.Height := 55;
  NewRect.Top := NewRect.Top + 2;
  NewRect.Bottom := NewRect.Bottom;

  if Column = 0 then
  begin

    with NewRect do
    begin
      TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
    end;

  end;
end;

The images drawn comes vertically. I want to show them horizontally for example as in this following image

enter image description here

Here is the data structure

type
  TAnmiClass = class
  private
    Fanmigraphic : TGifImage;

  public
    property anmigraphic: TGifImage read Fanmigraphic write Fanmigraphic;

  public
    constructor Create;
    destructor Destroy; override;
  end;

type
  PAnimeData = ^TAnimeData;

  TAnimeData = record
    FObject: TAnmiClass;
  end;

Upvotes: 1

Views: 235

Answers (1)

Tom Brunberg
Tom Brunberg

Reputation: 21045

You said:

the images drawn comes vertically

That is because you draw only if column is 0:

if Column = 0 then
begin
  with NewRect do
  begin
    TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
  end;
end;

You did not show the structure of Data but I suspect you have several images in each Data. It can not be determined from your code, how you can address the different images, so I show that part only as pseudocode in a pair of < and >.

If you want to draw different images in different columns, I suggest something like:

case Column of
  0: TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
  1: TargetCanvas.StretchDraw( NewRect, Data.FObject.<reference to second image>);

  7: TargetCanvas.StretchDraw( NewRect, Data.FObject.<reference to eight image>);
end;

instead of the code shown above.

Upvotes: 1

Related Questions