Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
forlano is currently offline  forlano
Messages: 1185
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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 Smile

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 271 times)
Re: Label and Focus [message #13267 is a reply to message #13253] Thu, 27 December 2007 09:31 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Wed, 26 December 2007 11:28


Uh, there is a couple of problems with your code. In fact, it works only very accidentally Smile



To say the true, I had the suspect that was too easy to produce the drag and drop with only three lines when I saw other examples with many lines.

Quote:


Instead of going into details: I would never do this using Label to represent individual pieces.


Very interesting although mysterious. Anyway I'll use your suggestion hoping to not miss the drag and drop feature.
Thanks,

Luigi
Previous Topic: Horizontal scrolling for ArrayCtrl
Next Topic: Button color Foreground Background
Goto Forum:
  


Current Time: Mon Apr 29 18:16:33 CEST 2024

Total time taken to generate the page: 0.02656 seconds