> In Windows, you actually can draw any font on any background.
Care to give me a hint how you did this?
The common free chess fonts (Chess Berlin etc.) are really designed for printing. So the font background color is not transparent.
Even if you solve this you have the issue of drawing a White piece on a white or light colored background, where just drawing it directly won't give a good effect.
--Jon
How to place a chess piece on a bmp square ?
Moderators: hgm, Rebel, chrisw
-
- Posts: 4367
- Joined: Fri Mar 10, 2006 5:23 am
- Location: http://www.arasanchess.org
-
- Posts: 3245
- Joined: Thu Mar 09, 2006 9:10 am
Re: How to place a chess piece on a bmp square ?
Matthias Gemuh wrote:I have already written these 2 routines which create a board and pieces on it. Yet you can send me the 4-in-line GUI.Karlo Bala wrote:
I have somewhere GUI for 4-in-line game. It is not totally finished, but it has graphic. If you want I can mail it to you
Now I need to find out how to check for (and eventually install) a chess font programmatically.
Matthias.Code: Select all
void DrawChessPiece(CHESSGUI *ChsGUI, UINT32 Colors[], Graphics::TBitmap *Bitmap1, int X, int Y, int xx, int yy, int nPieceNr, int nSqColour, int nPieceColour, TImage *Image1, char *FontName, bool bMainBoard) { DWORD nPieceColor, nSqColor; char *ch[] = { "*", "p", "n", "b", "r", "q", "k" }; // Bitmap1->Width = 2*xx; Bitmap1->Height = 2*yy; Bitmap1->Canvas->Pen->Color = 0x00000000; Bitmap1->Canvas->Font->Height = 2*yy; Bitmap1->Canvas->Brush->Style = bsSolid; if (bMainBoard) { if (nPieceColour) nPieceColor = Colors[2]; else nPieceColor = Colors[3]; } if (!bMainBoard) { if (nPieceColour) nPieceColor = Colors[6]; else nPieceColor = Colors[7]; } Bitmap1->Canvas->Brush->Color = nPieceColor; Bitmap1->Canvas->Font->Name = FontName; Bitmap1->Canvas->TextOut(0, 0, ch[nPieceNr]); if (bMainBoard) { if (nSqColour) nSqColor = Colors[0]; else nSqColor = Colors[1]; } if (!bMainBoard) { if (nSqColour) nSqColor = Colors[4]; else nSqColor = Colors[5]; } Bitmap1->Canvas->Brush->Color = nSqColor; Bitmap1->Canvas->FloodFill(1, 1, nPieceColor, fsSurface); StretchBlt(Image1->Canvas->Handle, X, Y, xx, yy, Bitmap1->Canvas->Handle, 0, 0, 2*xx, 2*yy, SRCCOPY); } void CreatePieces(CHESSGUI *ChsGUI, UINT32 Colors[], bool bMainBoard, TImage *Image1) { int x, y, x1, y1, xx, yy, x3, y3, px, py, nCnt; int nPieceNr, nSquareColour, nPieceColour; struct { int x1, y1, nPieceNr, nSquareColour, nPieceColour; } pp[] = { { 0, 0, 0, 1, 1 }, { 2, 0, 0, 1, 1 }, { 4, 0, 0, 1, 1 }, { 6, 0, 0, 1, 1 }, { 1, 0, 0, 0, 0 }, { 3, 0, 0, 0, 0 }, { 5, 0, 0, 0, 0 }, { 7, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 2, 1, 1, 0 }, { 0, 3, 1, 0, 1 }, { 0, 4, 1, 1, 1 }, { 1, 1, 2, 1, 0 }, { 1, 2, 2, 0, 0 }, { 1, 3, 2, 1, 1 }, { 1, 4, 2, 0, 1 }, { 2, 1, 3, 0, 0 }, { 2, 2, 3, 1, 0 }, { 2, 3, 3, 0, 1 }, { 2, 4, 3, 1, 1 }, { 3, 1, 4, 1, 0 }, { 3, 2, 4, 0, 0 }, { 3, 3, 4, 1, 1 }, { 3, 4, 4, 0, 1 }, { 4, 1, 5, 0, 0 }, { 4, 2, 5, 1, 0 }, { 4, 3, 5, 0, 1 }, { 4, 4, 5, 1, 1 }, { 5, 1, 6, 1, 0 }, { 5, 2, 6, 0, 0 }, { 5, 3, 6, 1, 1 }, { 5, 4, 6, 0, 1 }, { 0, 5, 0, 0, 1 }, { 2, 5, 0, 0, 1 }, { 4, 5, 0, 0, 1 }, { 6, 5, 0, 0, 1 }, { 1, 5, 0, 1, 0 }, { 3, 5, 0, 1, 0 }, { 5, 5, 0, 1, 0 }, { 7, 5, 0, 1, 0 }, { 0, 6, 0, 1, 1 }, { 2, 6, 0, 1, 1 }, { 4, 6, 0, 1, 1 }, { 6, 6, 0, 1, 1 }, { 1, 6, 0, 0, 0 }, { 3, 6, 0, 0, 0 }, { 5, 6, 0, 0, 0 }, { 7, 6, 0, 0, 0 } }; Graphics::TBitmap *Bitmap1; char FontName[32]; // Bitmap1 = new Graphics::TBitmap(); xx = yy = Image1->Width/8; strcpy(FontName, "Chess Merida"); // strcpy(FontName, "Chess Cases"); Image1->AutoSize = false; Image1->Stretch = true; Image1->Canvas->Brush->Color = clBtnFace; Image1->Canvas->FillRect(Image1->ClientRect); nCnt = (sizeof(pp)/sizeof(pp[0])); for (int i=0; i < nCnt; i++) { DrawChessPiece(ChsGUI, Colors, Bitmap1, pp[i].x1*xx, pp[i].y1*yy, xx, yy, pp[i].nPieceNr, pp[i].nSquareColour, pp[i].nPieceColour, Image1, FontName, bMainBoard); } // Image1->Repaint(); Image1->Update(); delete Bitmap1; }
mgemuh[@]yahoo{.}com
With a slight modification to include more pieces:
http://biglion.110mb.com/chess/Chess10x8_1.bmp
I cut and paste during games.
Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
http://www.chess.hylogic.de
-
- Posts: 3245
- Joined: Thu Mar 09, 2006 9:10 am
Re: How to place a chess piece on a bmp square ?
http://w2410tmq9.homepage.t-online.de/c ... 10x8_1.gifMatthias Gemuh wrote: With a slight modification to include more pieces:
http://biglion.110mb.com/chess/Chess10x8_1.bmp
I cut and paste during games.
Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
http://www.chess.hylogic.de