How to place a chess piece on a bmp square ?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

How to place a chess piece on a bmp square ?

Post by Matthias Gemuh »

How to place a chess piece on a bmp square on MS Windows ?

I can draw the pieces using a font:

Code: Select all

    char *ch[] = {
        "*", "+", "p", "P", "o", "O", "n", "N", "m", "M",
        "b", "B", "v", "V", "r", "R", "t", "T", "q", "Q",
        "w", "W", "k", "K", "l", "L", "x", "X", ".", ":",
        "*", "+", "*", "+", "*", "+"
    };
    Image9->Canvas->Font->Size = 36;
    Image9->Canvas->Font->Color = clBlue;
    Image9->Canvas->Font->Color = ((clBlue&0xFF000000)|0x0049A049);
    Image9->Canvas->Font->Color = 0x0049A049;
    Image9->Canvas->Font->Name = "Chess Merida";
    for &#40;int i = 0; i < 6; i++) &#123;
        for &#40;int j = 0; j < 6; j++) &#123;
            Image9->Canvas->TextOut&#40;1+50*i, 1+50*j, ch&#91;(&#40;6*j&#41;+i&#41;&#93;);
        &#125;
    &#125;
but I don't know how to use a given bmp as background.

I hope the solution is not more complex than merely using StretchBlt() or BitBlt() :wink:

Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to place a chess piece on a bmp square ?

Post by hgm »

Allessandro's code from Winboard_x does this unfortunately in a tedious way:

From the font it creates two bitmaps, a solid mask (which is used with a bitblt to punch out a hole with the shape of the piece in the background bitmap, i.e. make it black), and then an image of the piece with a black surroundings, which is then ORed wth the background using bitblt.

To make the image and the mask it uses a routine to render a true-type font symbol as bitmap (say in purple, after making a white background), and then it uses a black floodfill of the white outside, (to make the piece image), and then a white floodfill of anything-but-black on the inside to create the make (which then has to be inverted).

I found that on some OS (in particular the XP on my laptop) the floodfills do not work properly (they either overfill or underfill), and had to make work-arounds for that, by overlaying a number of pictures 1 bit shifter over each other.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: How to place a chess piece on a bmp square ?

Post by Matthias Gemuh »

hgm wrote:Allessandro's code from Winboard_x does this unfortunately in a tedious way:

From the font it creates two bitmaps, a solid mask (which is used with a bitblt to punch out a hole with the shape of the piece in the background bitmap, i.e. make it black), and then an image of the piece with a black surroundings, which is then ORed wth the background using bitblt.

To make the image and the mask it uses a routine to render a true-type font symbol as bitmap (say in purple, after making a white background), and then it uses a black floodfill of the white outside, (to make the piece image), and then a white floodfill of anything-but-black on the inside to create the make (which then has to be inverted).

I found that on some OS (in particular the XP on my laptop) the floodfills do not work properly (they either overfill or underfill), and had to make work-arounds for that, by overlaying a number of pictures 1 bit shifter over each other.
That is indeed a tedious way to do it.

My idea (not yet tried) is to place a chessboard on the screen,
then place a transparent board on it,
then draw opaque chess pieces on the transparent board.

Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to place a chess piece on a bmp square ?

Post by hgm »

I am not sure if bitblt supports transparancy.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: How to place a chess piece on a bmp square ?

Post by Matthias Gemuh »

hgm wrote:I am not sure if bitblt supports transparancy.
I don't need to support Linux, so I will use a method without bitblt.
Using Borland terminology, I will grab the canvas of the transparent board and change the style of its brush to transparent, then draw on the canvas.

Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
mainsworthy2

Re: How to place a chess piece on a bmp square ?

Post by mainsworthy2 »

My idea would be to have all pieces on black & white bacgrounds (64 pieces) then place appropriate piece at the required place on the black&white board (or whatever color)

dont know if this helps but it would do away with transparency I think
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to place a chess piece on a bmp square ?

Post by hgm »

This is exactly how XBoard does it with the pixmaps, and it is the main reason why I want to deprecate the pixmaps. For one, it does not help you when you are dragging pieces or animating moves, although XBoard solves this. But even if we forget about that, the way you outline would make the board square move with the pieces, so that when you would use a coherent picture as board texture, it would be shuffled during play. To preventthat one really would need 64 versions of each piece type (except Pawns, they could do with 48), so 2*48 + 10*64 = 736 pixmaps. And that of course would still have to be multiplied with the number of bord sizes.

As it is not lkely that you will be making such a number of pixmaps by and, you still would hae to address exactly te same question as in the leading post for creating the pixmaps.
mainsworthy2

Re: How to place a chess piece on a bmp square ?

Post by mainsworthy2 »

Ofcourse H.G the animation! but you could click square to square for an instant move, I was just tinkering with the idea.

I have transparency built into my Programing Language so Im not best suited to input valued comments.
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: How to place a chess piece on a bmp square ?

Post by Karlo Bala »

Matthias Gemuh wrote:How to place a chess piece on a bmp square on MS Windows ?

I can draw the pieces using a font:

Code: Select all

    char *ch&#91;&#93; = &#123;
        "*", "+", "p", "P", "o", "O", "n", "N", "m", "M",
        "b", "B", "v", "V", "r", "R", "t", "T", "q", "Q",
        "w", "W", "k", "K", "l", "L", "x", "X", ".", "&#58;",
        "*", "+", "*", "+", "*", "+"
    &#125;;
    Image9->Canvas->Font->Size = 36;
    Image9->Canvas->Font->Color = clBlue;
    Image9->Canvas->Font->Color = (&#40;clBlue&0xFF000000&#41;|0x0049A049&#41;;
    Image9->Canvas->Font->Color = 0x0049A049;
    Image9->Canvas->Font->Name = "Chess Merida";
    for &#40;int i = 0; i < 6; i++) &#123;
        for &#40;int j = 0; j < 6; j++) &#123;
            Image9->Canvas->TextOut&#40;1+50*i, 1+50*j, ch&#91;(&#40;6*j&#41;+i&#41;&#93;);
        &#125;
    &#125;
but I don't know how to use a given bmp as background.

I hope the solution is not more complex than merely using StretchBlt() or BitBlt() :wink:

Matthias.
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
Best Regards,
Karlo Balla Jr.
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: How to place a chess piece on a bmp square ?

Post by Karlo Bala »

... in Borland C++ builder
Best Regards,
Karlo Balla Jr.