You've already forked lazarus-ccr
Reworks the tappydrawer structure
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2129 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -11,19 +11,25 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TTappyTuxAnimation }
|
||||||
|
|
||||||
TTappyTuxAnimation = class
|
TTappyTuxAnimation = class
|
||||||
CurrentStep: Integer;
|
CurrentStep: Integer;
|
||||||
FinalStep: Integer;
|
StepCount: Integer;
|
||||||
|
IsInfinite: Boolean; // if True the animation will never end
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
procedure DrawToIntfImg(AIntfImg: TLazIntfImage); virtual; abstract;
|
procedure DrawToCanvas(ACanvas: TCanvas); virtual;
|
||||||
procedure ExecuteFinal; virtual; abstract;
|
procedure DrawToIntfImg(AIntfImage: TLazIntfImage); virtual;
|
||||||
|
procedure ExecuteFinal; virtual;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFireAnimation }
|
{ TTappySpriteAnimation }
|
||||||
|
|
||||||
TFireAnimation = class(TTappyTuxAnimation)
|
TTappySpriteAnimation = class(TTappyTuxAnimation)
|
||||||
public
|
public
|
||||||
procedure DrawToIntfImg(AIntfImg: TLazIntfImage); override;
|
StartPoint, EndPoint: TPoint;
|
||||||
|
Bitmaps: array of TBitmap;
|
||||||
|
procedure DrawToIntfImg(AIntfImage: TLazIntfImage); override;
|
||||||
procedure ExecuteFinal; override;
|
procedure ExecuteFinal; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -32,7 +38,7 @@ type
|
|||||||
TBallonAnimation = class(TTappyTuxAnimation)
|
TBallonAnimation = class(TTappyTuxAnimation)
|
||||||
public
|
public
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
procedure DrawToIntfImg(AIntfImg: TLazIntfImage); override;
|
procedure DrawToCanvas(ACanvas: TCanvas); override;
|
||||||
procedure ExecuteFinal; override;
|
procedure ExecuteFinal; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -48,7 +54,7 @@ type
|
|||||||
procedure EraseBackground(DC: HDC); override;
|
procedure EraseBackground(DC: HDC); override;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure DrawToCanvas(ACanvas: TCanvas);
|
procedure DrawToCanvas(ACanvas: TCanvas);
|
||||||
procedure DrawImageWithTransparentColor(
|
class procedure DrawImageWithTransparentColor(
|
||||||
ADest: TLazIntfImage; const ADestX, ADestY: Integer; AColor: TFPColor;
|
ADest: TLazIntfImage; const ADestX, ADestY: Integer; AColor: TFPColor;
|
||||||
AImage: TFPImageBitmap);
|
AImage: TFPImageBitmap);
|
||||||
//function GetImage(ATile: TChessTile): TPortableNetworkGraphic;
|
//function GetImage(ATile: TChessTile): TPortableNetworkGraphic;
|
||||||
@@ -59,6 +65,8 @@ type
|
|||||||
Shift: TShiftState; X, Y: Integer);
|
Shift: TShiftState; X, Y: Integer);
|
||||||
procedure HandleOnTimer(Sender: TObject);
|
procedure HandleOnTimer(Sender: TObject);
|
||||||
procedure AddAnimation(AAnimation: TTappyTuxAnimation);
|
procedure AddAnimation(AAnimation: TTappyTuxAnimation);
|
||||||
|
function GetAnimation(AIndex: Integer): TTappyTuxAnimation;
|
||||||
|
function GetAnimationCount: Integer;
|
||||||
procedure HandleAnimationOnTimer();
|
procedure HandleAnimationOnTimer();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -74,12 +82,12 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
CurrentStep := 0;
|
CurrentStep := 0;
|
||||||
FinalStep := 200;
|
StepCount := 200;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBallonAnimation.DrawToIntfImg(AIntfImg: TLazIntfImage);
|
procedure TBallonAnimation.DrawToCanvas(ACanvas: TCanvas);
|
||||||
begin
|
begin
|
||||||
AIntfImg.Colors[CurrentStep, CurrentStep] := colRed;
|
ACanvas.Pixels[CurrentStep, CurrentStep] := clRed;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBallonAnimation.ExecuteFinal;
|
procedure TBallonAnimation.ExecuteFinal;
|
||||||
@@ -87,36 +95,30 @@ begin
|
|||||||
// Lost the game if the ballon reached its end
|
// Lost the game if the ballon reached its end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFireAnimation }
|
{ TTappySpriteAnimation }
|
||||||
|
|
||||||
procedure TFireAnimation.DrawToIntfImg(AIntfImg: TLazIntfImage);
|
procedure TTappySpriteAnimation.DrawToIntfImg(AIntfImage: TLazIntfImage);
|
||||||
var
|
var
|
||||||
lTileBmp: TPortableNetworkGraphic;
|
lNumBitmaps, lCurBmpIndex: Integer;
|
||||||
X, Y, SourceX, SourceY, DestX, DestY: integer;
|
|
||||||
dx, dy: Integer;
|
|
||||||
t: Double;
|
t: Double;
|
||||||
//lTile: TChessTile;
|
lPos: TPoint;
|
||||||
begin
|
begin
|
||||||
{ // Draw the moving tile
|
lNumBitmaps := Length(Bitmaps);
|
||||||
//WriteLn(Format('[TChessMoveAnimation.DrawToIntfImg] Afrom=%d,%d', [AFrom.X, AFrom.Y]));
|
if lNumBitmaps = 0 then Exit;
|
||||||
lTile := vChessGame.Board[AFrom.X][AFrom.Y];
|
|
||||||
lTileBmp := vChessDrawer.GetChessTileImage(lTile);
|
|
||||||
if lTileBmp = nil then Exit;
|
|
||||||
|
|
||||||
SourceX := (AFrom.X - 1) * INT_CHESSTILE_SIZE;
|
lCurBmpIndex := CurrentStep mod lNumBitmaps;
|
||||||
SourceY := (8 - AFrom.Y) * INT_CHESSTILE_SIZE;
|
|
||||||
DestX := (ATo.X - 1) * INT_CHESSTILE_SIZE;
|
|
||||||
DestY := (8 - ATo.Y) * INT_CHESSTILE_SIZE;
|
|
||||||
t := CurrentStep / FinalStep;
|
|
||||||
X := Round(t * DestX + (1-t) * SourceX);
|
|
||||||
Y := Round(t * DestY + (1-t) * SourceY);
|
|
||||||
|
|
||||||
vChessDrawer.DrawImageWithTransparentColor(AIntfImg, X, Y, FPCOLOR_TRANSPARENT_TILE, lTileBmp);}
|
t := CurrentStep / StepCount;
|
||||||
|
lPos.X := Round(StartPoint.X + t * (EndPoint.X - StartPoint.X));
|
||||||
|
lPos.Y := Round(StartPoint.Y + t * (EndPoint.Y - StartPoint.Y));
|
||||||
|
|
||||||
|
TTappyTuxDrawer.DrawImageWithTransparentColor(AIntfImage,
|
||||||
|
lPos.X, lPos.Y, colFuchsia, Bitmaps[lCurBmpIndex]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFireAnimation.ExecuteFinal;
|
procedure TTappySpriteAnimation.ExecuteFinal;
|
||||||
begin
|
begin
|
||||||
//vChessGame.MovePiece(AFrom, ATo);
|
inherited ExecuteFinal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTappyTuxAnimation }
|
{ TTappyTuxAnimation }
|
||||||
@@ -126,7 +128,22 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
CurrentStep := 0;
|
CurrentStep := 0;
|
||||||
FinalStep := 20;
|
StepCount := 20;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTappyTuxAnimation.DrawToCanvas(ACanvas: TCanvas);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTappyTuxAnimation.DrawToIntfImg(AIntfImage: TLazIntfImage);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTappyTuxAnimation.ExecuteFinal;
|
||||||
|
begin
|
||||||
|
// inherit from this class and add something to ExecuteFinal
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TTappyTuxDrawer.Create(AOwner: TComponent);
|
constructor TTappyTuxDrawer.Create(AOwner: TComponent);
|
||||||
@@ -135,20 +152,6 @@ begin
|
|||||||
|
|
||||||
FAnimationList := TFPList.Create;
|
FAnimationList := TFPList.Create;
|
||||||
|
|
||||||
{ imgBoard := TPortableNetworkGraphic.Create;
|
|
||||||
imgWPawn := TPortableNetworkGraphic.Create;
|
|
||||||
imgWKnight := TPortableNetworkGraphic.Create;
|
|
||||||
imgWBishop := TPortableNetworkGraphic.Create;
|
|
||||||
imgWRook := TPortableNetworkGraphic.Create;
|
|
||||||
imgWQueen := TPortableNetworkGraphic.Create;
|
|
||||||
imgWKing := TPortableNetworkGraphic.Create;
|
|
||||||
imgBPawn := TPortableNetworkGraphic.Create;
|
|
||||||
imgBKnight := TPortableNetworkGraphic.Create;
|
|
||||||
imgBBishop := TPortableNetworkGraphic.Create;
|
|
||||||
imgBRook := TPortableNetworkGraphic.Create;
|
|
||||||
imgBQueen := TPortableNetworkGraphic.Create;
|
|
||||||
imgBKing := TPortableNetworkGraphic.Create;}
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
OnMouseMove := @HandleMouseMove;
|
OnMouseMove := @HandleMouseMove;
|
||||||
OnMouseUp := @HandleMouseUp;
|
OnMouseUp := @HandleMouseUp;
|
||||||
@@ -164,8 +167,7 @@ end;
|
|||||||
|
|
||||||
procedure TTappyTuxDrawer.EraseBackground(DC: HDC);
|
procedure TTappyTuxDrawer.EraseBackground(DC: HDC);
|
||||||
begin
|
begin
|
||||||
// Uncomment this to enable default background erasing
|
// Don't erase the background
|
||||||
//inherited EraseBackground(DC);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTappyTuxDrawer.Paint;
|
procedure TTappyTuxDrawer.Paint;
|
||||||
@@ -185,8 +187,6 @@ begin
|
|||||||
finally
|
finally
|
||||||
Bitmap.Free;
|
Bitmap.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// inherited Paint;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTappyTuxDrawer.DrawToCanvas(ACanvas: TCanvas);
|
procedure TTappyTuxDrawer.DrawToCanvas(ACanvas: TCanvas);
|
||||||
@@ -204,27 +204,7 @@ begin
|
|||||||
// First draw the background
|
// First draw the background
|
||||||
lIntfImage.LoadFromBitmap(GetCurrentModule().GetBackgroundImage(2).Handle, 0{bmpBoard.MaskHandle});
|
lIntfImage.LoadFromBitmap(GetCurrentModule().GetBackgroundImage(2).Handle, 0{bmpBoard.MaskHandle});
|
||||||
|
|
||||||
// Now the module should draw itself
|
// Draw all animations via TLazIntfImage
|
||||||
|
|
||||||
// Draw all animations
|
|
||||||
|
|
||||||
{ // Now all pieces
|
|
||||||
for col := 1 to 8 do
|
|
||||||
for row := 1 to 8 do
|
|
||||||
begin
|
|
||||||
// Check if the animation wants us to skip drawing this piece
|
|
||||||
if Assigned(FAnimation) and FAnimation.SkipDrawingPiece(col, row) then Continue;
|
|
||||||
|
|
||||||
lTileBmp := GetChessTileImage(vChessGame.Board[col][row]);
|
|
||||||
if lTileBmp = nil then Continue;
|
|
||||||
|
|
||||||
X := (col - 1) * INT_CHESSTILE_SIZE;
|
|
||||||
Y := (8 - row) * INT_CHESSTILE_SIZE;
|
|
||||||
|
|
||||||
DrawImageWithTransparentColor(lIntfImage, X, Y, FPCOLOR_TRANSPARENT_TILE, lTileBmp);
|
|
||||||
end;}
|
|
||||||
|
|
||||||
// Now animations
|
|
||||||
for i := 0 to FAnimationList.Count - 1 do
|
for i := 0 to FAnimationList.Count - 1 do
|
||||||
begin
|
begin
|
||||||
lAnimation := TTappyTuxAnimation(FAnimationList.Items[i]);
|
lAnimation := TTappyTuxAnimation(FAnimationList.Items[i]);
|
||||||
@@ -233,13 +213,27 @@ begin
|
|||||||
|
|
||||||
lTmpBmp.LoadFromIntfImage(lIntfImage);
|
lTmpBmp.LoadFromIntfImage(lIntfImage);
|
||||||
ACanvas.Draw(0, 0, lTmpBmp);
|
ACanvas.Draw(0, 0, lTmpBmp);
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// Now TCanvas drawings
|
||||||
|
// -------------------------
|
||||||
|
|
||||||
|
// Now the module should draw itself
|
||||||
|
|
||||||
|
// Draw all animations via TLazIntfImage
|
||||||
|
for i := 0 to FAnimationList.Count - 1 do
|
||||||
|
begin
|
||||||
|
lAnimation := TTappyTuxAnimation(FAnimationList.Items[i]);
|
||||||
|
lAnimation.DrawToCanvas(ACanvas);
|
||||||
|
end;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
lTmpBmp.Free;
|
lTmpBmp.Free;
|
||||||
lIntfImage.Free;
|
lIntfImage.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTappyTuxDrawer.DrawImageWithTransparentColor(ADest: TLazIntfImage;
|
class procedure TTappyTuxDrawer.DrawImageWithTransparentColor(ADest: TLazIntfImage;
|
||||||
const ADestX, ADestY: Integer; AColor: TFPColor; AImage: TFPImageBitmap);
|
const ADestX, ADestY: Integer; AColor: TFPColor; AImage: TFPImageBitmap);
|
||||||
var
|
var
|
||||||
x, y, CurX, CurY: Integer;
|
x, y, CurX, CurY: Integer;
|
||||||
@@ -277,26 +271,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{function TTappyTuxDrawer.GetChessTileImage(ATile: TChessTile): TPortableNetworkGraphic;
|
|
||||||
begin
|
|
||||||
case ATile of
|
|
||||||
ctWPawn: Result := imgWPawn;
|
|
||||||
ctWKnight: Result := imgWKnight;
|
|
||||||
ctWBishop: Result := imgWBishop;
|
|
||||||
ctWRook: Result := imgWRook;
|
|
||||||
ctWQueen: Result := imgWQueen;
|
|
||||||
ctWKing: Result := imgWKing;
|
|
||||||
ctBPawn: Result := imgBPawn;
|
|
||||||
ctBKnight: Result := imgBKnight;
|
|
||||||
ctBBishop: Result := imgBBishop;
|
|
||||||
ctBRook: Result := imgBRook;
|
|
||||||
ctBQueen: Result := imgBQueen;
|
|
||||||
ctBKing: Result := imgBKing;
|
|
||||||
else
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
end;}
|
|
||||||
|
|
||||||
procedure TTappyTuxDrawer.HandleMouseMove(Sender: TObject; Shift: TShiftState; X,
|
procedure TTappyTuxDrawer.HandleMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||||
Y: Integer);
|
Y: Integer);
|
||||||
begin
|
begin
|
||||||
@@ -339,6 +313,16 @@ begin
|
|||||||
FAnimationList.Add(AAnimation);
|
FAnimationList.Add(AAnimation);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TTappyTuxDrawer.GetAnimation(AIndex: Integer): TTappyTuxAnimation;
|
||||||
|
begin
|
||||||
|
Result := TTappyTuxAnimation(FAnimationList.Items[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTappyTuxDrawer.GetAnimationCount: Integer;
|
||||||
|
begin
|
||||||
|
Result := FAnimationList.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTappyTuxDrawer.HandleAnimationOnTimer;
|
procedure TTappyTuxDrawer.HandleAnimationOnTimer;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Reference in New Issue
Block a user