diff --git a/applications/fpchess/chessdrawer.pas b/applications/fpchess/chessdrawer.pas index dbb5f5e43..9e168f609 100644 --- a/applications/fpchess/chessdrawer.pas +++ b/applications/fpchess/chessdrawer.pas @@ -5,8 +5,8 @@ unit chessdrawer; interface uses - Classes, SysUtils, Controls, Graphics, LCLType, - // + Classes, SysUtils, Controls, Graphics, LCLType, IntfGraphics, fpimage, + Math, chessgame, chessconfig; type @@ -15,17 +15,21 @@ type TChessDrawer = class(TCustomControl) private - imgBoard, - imgWPawn, imgWKnight, imgWBishop, imgWRook, imgWQueen, imgWKing, - imgBPawn, imgBKnight, imgBBishop, imgBRook, imgBQueen, imgBKing: - TPortableNetworkGraphic; + imgBoard, imgWPawn, imgWKnight, imgWBishop, imgWRook, imgWQueen, + imgWKing, imgBPawn, imgBKnight, imgBBishop, imgBRook, imgBQueen, + imgBKing: TPortableNetworkGraphic; +{ bmpBoard, bmpWPawn, bmpWKnight, bmpWBishop, bmpWRook, bmpWQueen, + bmpWKing, bmpBPawn, bmpBKnight, bmpBBishop, bmpBRook, bmpBQueen, + bmpBKing: TBitmap;} public constructor Create(AOwner: TComponent); override; procedure EraseBackground(DC: HDC); override; procedure Paint; override; procedure DrawToCanvas(ACanvas: TCanvas); - procedure DrawChessTile(ACanvas: TCanvas; ACol, ARow: Integer; - ATile: TChessTile); + procedure DrawImageWithTransparentColor( + ADest: TLazIntfImage; const ADestX, ADestY: Integer; AColor: TFPColor; + AImage: TFPImageBitmap); + function GetChessTileImage(ATile: TChessTile): TPortableNetworkGraphic; procedure LoadImages(); end; @@ -51,6 +55,20 @@ begin imgBRook := TPortableNetworkGraphic.Create; imgBQueen := TPortableNetworkGraphic.Create; imgBKing := TPortableNetworkGraphic.Create; + +{ bmpBoard := TBitmap.Create; + bmpWPawn := TBitmap.Create; + bmpWKnight := TBitmap.Create; + bmpWBishop := TBitmap.Create; + bmpWRook := TBitmap.Create; + bmpWQueen := TBitmap.Create; + bmpWKing := TBitmap.Create; + bmpBPawn := TBitmap.Create; + bmpBKnight := TBitmap.Create; + bmpBBishop := TBitmap.Create; + bmpBRook := TBitmap.Create; + bmpBQueen := TBitmap.Create; + bmpBKing := TBitmap.Create; } end; procedure TChessDrawer.EraseBackground(DC: HDC); @@ -61,7 +79,7 @@ end; procedure TChessDrawer.Paint; var - x, y: Integer; + x, y: integer; Bitmap: TBitmap; begin Bitmap := TBitmap.Create; @@ -77,45 +95,96 @@ begin Bitmap.Free; end; -// inherited Paint; + // inherited Paint; end; procedure TChessDrawer.DrawToCanvas(ACanvas: TCanvas); var - col, row: Integer; + col, row: integer; + lIntfImage: TLazIntfImage; + lTmpBmp: TBitmap; + lTileBmp: TPortableNetworkGraphic; + X, Y: integer; begin - // First draw the board - ACanvas.Draw(0, 0, imgBoard); + lIntfImage := TLazIntfImage.Create(0, 0); + lTmpBmp := TBitmap.Create; + try + // First draw the board + lIntfImage.LoadFromBitmap(imgBoard.Handle, 0{bmpBoard.MaskHandle}); - // Now all pieces - for col := 1 to 8 do - for row := 1 to 8 do - DrawChessTile(ACanvas, col, row, vChessGame.Board[col][row]); + // Now all pieces + for col := 1 to 8 do + for row := 1 to 8 do + begin + 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; + + lTmpBmp.LoadFromIntfImage(lIntfImage); + ACanvas.Draw(0, 0, lTmpBmp); + finally + lTmpBmp.Free; + lIntfImage.Free; + end; end; -procedure TChessDrawer.DrawChessTile(ACanvas: TCanvas; ACol, ARow: Integer; - ATile: TChessTile); +procedure TChessDrawer.DrawImageWithTransparentColor(ADest: TLazIntfImage; + const ADestX, ADestY: Integer; AColor: TFPColor; AImage: TFPImageBitmap); var - X, Y: Integer; + x, y, CurX, CurY: Integer; + CurColor: TFPColor; + IntfImage: TLazIntfImage; + lDrawWidth, lDrawHeight: Integer; begin - if ATile = ctEmpty then Exit; + IntfImage := TLazIntfImage.Create(0,0); + try + IntfImage.LoadFromBitmap(AImage.Handle, AImage.MaskHandle); - X := (ACol - 1) * INT_CHESSTILE_SIZE; - Y := (8 - ARow) * INT_CHESSTILE_SIZE; + // Take care not to draw outside the destination area + lDrawWidth := Min(ADest.Width - ADestX, AImage.Width); + lDrawHeight := Min(ADest.Height - ADestY, AImage.Height); + for y := 0 to lDrawHeight - 1 do + begin + for x := 0 to lDrawWidth - 1 do + begin + CurX := ADestX + x; + CurY := ADestY + y; + // Never draw outside the destination + if (CurX < 0) or (CurY < 0) then Continue; + + // CurColor := IntfImage.Colors[x, y]; // Just for debugging + if IntfImage.Colors[x, y].Green <> AColor.Green then + ADest.Colors[CurX, CurY] := IntfImage.Colors[x, y]; + end; + end; + finally + IntfImage.Free; + end; +end; + +function TChessDrawer.GetChessTileImage(ATile: TChessTile): TPortableNetworkGraphic; +begin case ATile of - ctWPawn: ACanvas.Draw(X, Y, imgWPawn); - ctWKnight: ACanvas.Draw(X, Y, imgWKnight); - ctWBishop: ACanvas.Draw(X, Y, imgWBishop); - ctWRook: ACanvas.Draw(X, Y, imgWRook); - ctWQueen: ACanvas.Draw(X, Y, imgWQueen); - ctWKing: ACanvas.Draw(X, Y, imgWKing); - ctBPawn: ACanvas.Draw(X, Y, imgBPawn); - ctBKnight: ACanvas.Draw(X, Y, imgBKnight); - ctBBishop: ACanvas.Draw(X, Y, imgBBishop); - ctBRook: ACanvas.Draw(X, Y, imgBRook); - ctBQueen: ACanvas.Draw(X, Y, imgBQueen); - ctBKing: ACanvas.Draw(X, Y, imgBKing); + 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; @@ -125,7 +194,7 @@ var begin lDir := vChessConfig.GetCurrentSkinDir(); - imgBoard.LoadFromFile(lDir + 'board.png'); + imgBoard.LoadFromFile(lDir + 'base.png'); imgWPawn.LoadFromFile(lDir + 'wpawn.png'); imgWKnight.LoadFromFile(lDir + 'wknight.png'); imgWBishop.LoadFromFile(lDir + 'wbishop.png'); @@ -138,6 +207,18 @@ begin imgBRook.LoadFromFile(lDir + 'brook.png'); imgBQueen.LoadFromFile(lDir + 'bqueen.png'); imgBKing.LoadFromFile(lDir + 'bking.png'); + +{ bmpWKnight.Assign(imgWKnight); + bmpWKnight.Assign(imgWBishop); + bmpWKnight.Assign(imgWRook); + bmpWKnight.Assign(imgWQueen); + bmpWKnight.Assign(imgWKing); + bmpWKnight.Assign(imgBPawn); + bmpWKnight.Assign(imgBKnight); + bmpWKnight.Assign(imgBBishop); + bmpWKnight.Assign(imgBRook); + bmpWKnight.Assign(imgBQueen); + bmpWKnight.Assign(imgBKing); } end; end. diff --git a/applications/fpchess/chessgame.pas b/applications/fpchess/chessgame.pas index 164bd7444..03eed0fa6 100644 --- a/applications/fpchess/chessgame.pas +++ b/applications/fpchess/chessgame.pas @@ -5,7 +5,7 @@ unit chessgame; interface uses - Classes, SysUtils; + Classes, SysUtils, fpimage; const colA = 1; @@ -17,8 +17,10 @@ const colG = 7; colH = 8; - INT_CHESSTILE_SIZE = 20; - INT_CHESSBOARD_SIZE = 200; + INT_CHESSTILE_SIZE = 40; + INT_CHESSBOARD_SIZE = 40 * 8; + + FPCOLOR_TRANSPARENT_TILE: TFPColor = (Red: $0000; Green: $8000; Blue: $8000; Alpha: alphaOpaque); //colTeal type diff --git a/applications/fpchess/fpchess.lpi b/applications/fpchess/fpchess.lpi index 25f142f43..fd5a64be4 100644 --- a/applications/fpchess/fpchess.lpi +++ b/applications/fpchess/fpchess.lpi @@ -31,12 +31,12 @@ - + - + @@ -46,9 +46,9 @@ - - - + + + @@ -164,9 +164,9 @@ - - - + + + @@ -222,9 +222,9 @@ - - - + + + @@ -233,132 +233,177 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - + - + - + - + - + - + diff --git a/applications/fpchess/mainform.lfm b/applications/fpchess/mainform.lfm index e51311434..e127f5898 100644 --- a/applications/fpchess/mainform.lfm +++ b/applications/fpchess/mainform.lfm @@ -18,10 +18,8 @@ object formChess: TformChess TabOrder = 0 TabStop = True object pageStart: TUNBPage - Left = 0 - Height = 300 - Top = 0 - Width = 240 + ClientWidth = 240 + ClientHeight = 300 object Label1: TLabel Left = 0 Height = 32 @@ -72,7 +70,7 @@ object formChess: TformChess end object editPlayerName: TLabeledEdit Left = 104 - Height = 22 + Height = 21 Top = 80 Width = 120 EditLabel.AnchorSideLeft.Control = editPlayerName @@ -80,10 +78,10 @@ object formChess: TformChess EditLabel.AnchorSideTop.Side = asrCenter EditLabel.AnchorSideRight.Control = editPlayerName EditLabel.AnchorSideBottom.Control = editPlayerName - EditLabel.Left = 22 - EditLabel.Height = 17 + EditLabel.Left = 40 + EditLabel.Height = 14 EditLabel.Top = 83 - EditLabel.Width = 79 + EditLabel.Width = 61 EditLabel.Caption = 'Player Name' EditLabel.ParentColor = False LabelPosition = lpLeft @@ -91,9 +89,9 @@ object formChess: TformChess end object Label6: TLabel Left = 21 - Height = 17 + Height = 14 Top = 112 - Width = 52 + Width = 43 Caption = 'Start as:' ParentColor = False end @@ -102,7 +100,7 @@ object formChess: TformChess Height = 21 Top = 111 Width = 120 - ItemHeight = 0 + ItemHeight = 13 ItemIndex = 0 Items.Strings = ( 'White' @@ -113,10 +111,8 @@ object formChess: TformChess end end object pageConfigConnection: TUNBPage - Left = 0 - Height = 300 - Top = 0 - Width = 240 + ClientWidth = 240 + ClientHeight = 300 object Label3: TLabel Left = 0 Height = 32 @@ -180,10 +176,8 @@ object formChess: TformChess end end object pageConnecting: TUNBPage - Left = 0 - Height = 300 - Top = 0 - Width = 240 + ClientWidth = 240 + ClientHeight = 300 object Label4: TLabel Left = 0 Height = 32 @@ -205,10 +199,8 @@ object formChess: TformChess end end object pageGame: TUNBPage - Left = 0 - Height = 300 - Top = 0 - Width = 240 + ClientWidth = 240 + ClientHeight = 300 object Label5: TLabel Left = 0 Height = 32 diff --git a/applications/fpchess/mainform.pas b/applications/fpchess/mainform.pas index 110c9febc..4cbcf13c0 100644 --- a/applications/fpchess/mainform.pas +++ b/applications/fpchess/mainform.pas @@ -56,7 +56,7 @@ procedure TformChess.HandleMainScreenButton(Sender: TObject); begin if Sender = btnSinglePlayer then begin - notebookMain.PageIndex := 2; + notebookMain.PageIndex := 3; vChessGame.StartNewGame(comboStartColor.ItemIndex); end else if Sender = btnDirectComm then notebookMain.PageIndex := 1; @@ -67,7 +67,7 @@ begin // Creation of internal components vChessDrawer := TChessDrawer.Create(Self); vChessDrawer.Parent := pageGame; - vChessDrawer.Top := 20; + vChessDrawer.Top := 50; vChessDrawer.Left := 20; vChessDrawer.Height := INT_CHESSBOARD_SIZE; vChessDrawer.Width := INT_CHESSBOARD_SIZE; diff --git a/applications/fpchess/skins/classic/base.png b/applications/fpchess/skins/classic/base.png index ca816133b..3d11fe471 100644 Binary files a/applications/fpchess/skins/classic/base.png and b/applications/fpchess/skins/classic/base.png differ diff --git a/applications/fpchess/skins/classic/bbishop.png b/applications/fpchess/skins/classic/bbishop.png new file mode 100644 index 000000000..4d49fe100 Binary files /dev/null and b/applications/fpchess/skins/classic/bbishop.png differ diff --git a/applications/fpchess/skins/classic/bking.png b/applications/fpchess/skins/classic/bking.png new file mode 100644 index 000000000..fec3a2e30 Binary files /dev/null and b/applications/fpchess/skins/classic/bking.png differ diff --git a/applications/fpchess/skins/classic/bknight.png b/applications/fpchess/skins/classic/bknight.png new file mode 100644 index 000000000..7e82f9df1 Binary files /dev/null and b/applications/fpchess/skins/classic/bknight.png differ diff --git a/applications/fpchess/skins/classic/bpawn.png b/applications/fpchess/skins/classic/bpawn.png new file mode 100644 index 000000000..7f5182d14 Binary files /dev/null and b/applications/fpchess/skins/classic/bpawn.png differ diff --git a/applications/fpchess/skins/classic/bqueen.png b/applications/fpchess/skins/classic/bqueen.png new file mode 100644 index 000000000..a6a8699d7 Binary files /dev/null and b/applications/fpchess/skins/classic/bqueen.png differ diff --git a/applications/fpchess/skins/classic/brook.png b/applications/fpchess/skins/classic/brook.png new file mode 100644 index 000000000..a2f24759d Binary files /dev/null and b/applications/fpchess/skins/classic/brook.png differ diff --git a/applications/fpchess/skins/classic/wbishop.png b/applications/fpchess/skins/classic/wbishop.png new file mode 100644 index 000000000..503e64063 Binary files /dev/null and b/applications/fpchess/skins/classic/wbishop.png differ diff --git a/applications/fpchess/skins/classic/wking.png b/applications/fpchess/skins/classic/wking.png new file mode 100644 index 000000000..a982397fd Binary files /dev/null and b/applications/fpchess/skins/classic/wking.png differ diff --git a/applications/fpchess/skins/classic/wknight.png b/applications/fpchess/skins/classic/wknight.png new file mode 100644 index 000000000..35bca188d Binary files /dev/null and b/applications/fpchess/skins/classic/wknight.png differ diff --git a/applications/fpchess/skins/classic/wpawn.png b/applications/fpchess/skins/classic/wpawn.png new file mode 100644 index 000000000..a36cbaf3d Binary files /dev/null and b/applications/fpchess/skins/classic/wpawn.png differ diff --git a/applications/fpchess/skins/classic/wqueen.png b/applications/fpchess/skins/classic/wqueen.png new file mode 100644 index 000000000..2900f1409 Binary files /dev/null and b/applications/fpchess/skins/classic/wqueen.png differ diff --git a/applications/fpchess/skins/classic/wrook.png b/applications/fpchess/skins/classic/wrook.png new file mode 100644 index 000000000..210abab67 Binary files /dev/null and b/applications/fpchess/skins/classic/wrook.png differ