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
Re: Label and Focus [message #13253 is a reply to message #13251] Wed, 26 December 2007 11:28 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
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 327 times)
 
Read Message
Read Message
Read Message
Previous Topic: Horizontal scrolling for ArrayCtrl
Next Topic: Button color Foreground Background
Goto Forum:
  


Current Time: Sun Aug 24 19:18:00 CEST 2025

Total time taken to generate the page: 0.10228 seconds