Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Chess pieces snap to new squares, how?

Author: Odd Gunnar Malin

Date: 10:57:45 12/01/01

Go up one level in this thread


On November 30, 2001 at 16:11:39, Bo Persson wrote:

>On November 30, 2001 at 12:46:40, Eran wrote:
>
>>
>>I develop a chess interface based on MFC 6. The draggable chess pieces, from
>>bitmap sources, are not based on Ole Drag and Drop at all but based on
>>OnLButtonDown, OnMouseMove, and OnLButtonUp functions. I successfully drag them
>>smoothly every where on the chess board window, but I do not know how to write
>>code that make a dragged chess piece snapped into a new square.
>
>It's not supposed to land on the new square. :-)
>You have to check the validity of the move first. Use the From and To squares of
>the mouse drag and find a move that matches those squares.
>
>Here's my code for the mouse-up event:
>
>void CBoardView::OnLButtonUp(UINT /*nFlags*/, CPoint point)
>{
>   if (GetDocument()->InputIsActive() && Chess::IsOnBoard(DragFromSquare))
>   {
>      const Chess::SQUARE FromSquare = DragFromSquare;
>      const Chess::SQUARE ToSquare   = PointToSquare(point);
>
>      // Button released -> stop further dragging
>
>      ResetDragDrop();
>
>      // Remove the dragged image
>
>      PieceImages.EndDrag();
>      PieceImages.DragLeave(this);
>
>      // Release the mouse
>
>      ReleaseCapture();
>
>      // Initiate repainting of the original square
>
>      InvalidateRect(DisplayedBoard[FromSquare]);
>
>      // Process move, if piece really dragged to a new square
>
>      if (ToSquare != FromSquare && Chess::IsOnBoard(ToSquare))
>         GetDocument()->ProcessHumanMove(FromSquare,ToSquare);
>
>   }
>}
>

I see that you use the imagelist. How do you make the pieces not to turn into a
ghost on WinNT when you move them. I programmed my function on Win98 and all was
well but when I tried it on NT the pieces was a sort of transparent when
dragging.

Odd Gunnar



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.