Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Wieder mal: Einzelne Zellen in einem Grid zeichnen (https://www.delphipraxis.net/42763-wieder-mal-einzelne-zellen-einem-grid-zeichnen.html)

junale 23. Mär 2005 14:12


Wieder mal: Einzelne Zellen in einem Grid zeichnen
 
Hi,

Ich habe ein TDrawGrid, in welchem ein (variables) 19 auf 19 Raster (durch die Komponente) erzeugt wird. Parallel existiert ein (variables) Array[0..18, 0..18] in dem die Farben der Spielsteine hinterlegt sind. Wenn ich nun einen Stein mit folgendem Code "bewege" werden nicht alle Steine erneut gezeichnet // gelöscht.

Waran kann das liegen?

Wenn ich das "Refresh" in der Routine MoveItem einfüge (momentan auskommentiert), dann wird die Bewegung der Spielsteine sehr langsam, sobald ein paar Steine gleichzeitig bewegt werden müssen.

Durch die Suche hier im Forum habe ich InvalidateCell probiert -> wird auch nicht besser.

Delphi-Quellcode:
type
  TGameBoard = class (TDrawGrid)
  private
    fFields: Array of Array of TGameItems;
    ...
  protected
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
  public
    ...
    procedure MoveItem (aRow, aCol: Integer; Dir: TGravitation);
  published
    ...
  end;

...

procedure TGameBoard.MoveItem (aRow, aCol: Integer; Dir: TGravitation);
var
  ToRow, ToCol: Integer;
begin
  case Dir of
    grBottom: begin ToRow := Succ(aRow); ToCol := aCol;       end;
    grLeft:  begin ToRow := aRow;      ToCol := Pred (aCol); end;
    grRight: begin ToRow := aRow;      ToCol := Succ (aCol); end;
    grTop:   begin ToRow := Pred(aRow); ToCol := aCol;       end;
  end;

  fFields[ToRow, ToCol] := fFields[aRow, aCol];
  fFields[aRow, aCol] := giNone;
  InvalidateCell (aRow, aCol);
  InvalidateCell (ToRow, ToCol);
// Refresh;
end;

procedure TAEJGameBoard.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
  procedure PaintCoin (CoinColor: TColor);
  begin
    Canvas.Pen.Color := clGray;
    Canvas.Brush.Color := CoinColor;
    Canvas.Ellipse (aCol * (DefaultColWidth + GridLineWidth) + 2, aRow * (DefaultRowHeight + GridLineWidth)+ 2, Succ (aCol) * (DefaultColWidth + GridLineWidth) - 2, Succ (aRow) * (DefaultRowHeight + GridLineWidth) - 2);
  end;
begin
  inherited;
  case fFields[aRow, aCol] of
    giCoinBlack: PaintCoin (clBlack);
    giCoinBlue: PaintCoin (clBlue);
    giCoinRed:  PaintCoin (clRed);
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:05 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz