unit TilePanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TTilePanel = class(TPanel)
private
FTile: TPicture;
procedure TileChanged(Sender: TObject);
procedure SetTile(Value: TPicture);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Tile: TPicture read FTile write SetTile;
end;
procedure Register;
implementation
constructor TTilePanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTile := TPicture.Create;
FTile.OnChange := TileChanged;
end;
destructor TTilePanel.Destroy;
begin
FTile.Free;
inherited Destroy;
end;
procedure TTilePanel.TileChanged(Sender: TObject);
begin
Invalidate;
end;
procedure TTilePanel.SetTile(Value: TPicture);
begin
FTile.Assign(Value);
end;
procedure TTilePanel.Paint;
var
x, y: Integer;
begin
inherited Paint;
if (FTile.Graphic <> nil) and (FTile.Width > 0) and (FTile.Height > 0) then
begin
y := 0;
while y < Height do
begin
x := 0;
while x < Width do
begin
Canvas.Draw(x, y, FTile.Graphic);
Inc (x, FTile.Width);
end;
Inc (y, FTile.Height);
end;
end;
end;
procedure Register;
begin
RegisterComponents('Croco', [TTilePanel]);
end;
end.