Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Label and Focus
Label and Focus [message #13251] |
Wed, 26 December 2007 10:45  |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
I put a picture made with the iml designer inside a label to build a piece of a chessboard. I can drag it over an empty layout with this snippet:
void Chessboard::LeftDown(Point pos, dword flags)
{ if (!piece.HasCapture()) piece.SetCapture();
else piece.ReleaseCapture();
}
void Chessboard::MouseMove(Point pos, dword flags)
{
p = pos;
if (piece.HasCapture()) piece.LeftPosZ(p.x - D/2, D).TopPosZ(p.y - D/2, D);
Refresh();
}
Unfortunately the piece is moved even when I click click and drag OUT of the label size.
Perhaps I've programmed in a bad way, but now I need to know when I leftclick if I clicked the label or the empty layout. Is there a way?
In future, with many pieces on the board (32), I need to recover the name/adress of the piece. In this case a button with a focus maybe a better ctrl? By the way, in the previous snippet If I change the Label with a Button I'm not able to click and drag anything.
Thank you,
Luigi
PS: I attach the whole package, just other few lines, for a better understanding
|
|
|
Re: Label and Focus [message #13253 is a reply to message #13251] |
Wed, 26 December 2007 11:28   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
forlano wrote on Wed, 26 December 2007 04:45 | Hello,
I put a picture made with the iml designer inside a label to build a piece of a chessboard. I can drag it over an empty layout with this snippet:
void Chessboard::LeftDown(Point pos, dword flags)
{ if (!piece.HasCapture()) piece.SetCapture();
else piece.ReleaseCapture();
}
void Chessboard::MouseMove(Point pos, dword flags)
{
p = pos;
if (piece.HasCapture()) piece.LeftPosZ(p.x - D/2, D).TopPosZ(p.y - D/2, D);
Refresh();
}
Unfortunately the piece is moved even when I click click and drag OUT of the label size.
Perhaps I've programmed in a bad way, but now I need to know when I leftclick if I clicked the label or the empty layout. Is there a way?
In future, with many pieces on the board (32), I need to recover the name/adress of the piece. In this case a button with a focus maybe a better ctrl? By the way, in the previous snippet If I change the Label with a Button I'm not able to click and drag anything.
Thank you,
Luigi
PS: I attach the whole package, just other few lines, for a better understanding
|
Uh, there is a couple of problems with your code. In fact, it works only very accidentally 
Instead of going into details: I would never do this using Label to represent individual pieces. Instead, pieces should not be widgets! Make an array of pieces (16 + 16), when clicking board position, identify the piece standing on it, then SetCapture for the board and move the piece.
Long time ago I was experimenting with simple chess algorithm (only 5x5 board and peons). There is no dragging, but perhaps you could find it helpful... attaching.
Mirek
-
Attachment: Chess.zip
(Size: 2.45KB, Downloaded 314 times)
|
|
|
|
Goto Forum:
Current Time: Sun May 11 17:18:37 CEST 2025
Total time taken to generate the page: 0.00460 seconds
|