![]() |
|
#1
|
|||
|
|||
Drag and Drop of images ??hi there this is my first time I post here, Ive taken some courses in C++ and Iam on my own now, but there are still alot of basic issues I need to work on so please do not mind the following question:
Iam working on a chess interface and I have an TBitmap for every stone, when a stone is to be moved it will be dragged onMouseUP I will check if hte new position is valid, if it is the stone will take its new position else it will return to its former position, the problem is that Iam not able to drag the image what I tried is the following : 1- on mouse down record initialX and initialY 2-While dragging change Top and Left of the TBitmap according to the X an Y coordinates of the event handler 3-OnMouseUp check for the validity of hte position of the TBitmap. Any help please?? |
|
#2
|
|||
|
|||
|
Hi, shakoush2001
For new users this is important to read. Read it so that you get max. advantage from this forum. From what you write it seems you are using Borland compiler? Is that right? Things like this are important to know by people that try to help you. The logic you described in points 1, 2 & 3 is correct. Did you forget to call repaint() in your code or do you have any code? Please send your current code. |
|
#3
|
|||
|
|||
|
CPP / C++ / C Code:
Iam using Borland C++Builder 5 |
|
#4
|
|||
|
|||
|
It is a long time since I have used Borland Builder but...
It seems that Image1 is one of your chess pieces. In FormMouseDown try "X1 = X; X2 = Image1->Left;" Note that X2 here is new variable to store the coordinate more permanently so that you can put the Image1 back to its original place if the ultimate destination is not valid. In Image1MouseMove I think the mouse coordinates (X,Y) are relative to the up-left corner of the Image1 itself. In that case you should write something like: CPP / C++ / C Code:
finally you still need logic in the mouse up to check if the new location is valid... and to "snap" the piece into its place. Although it would be much better if you made your ChessBoard image (or Canvas control) to handle the mouse events. It gets messy if you are going to write message handlers for every chess piece in the board.. not effective. |
|
#5
|
|||
|
|||
|
Thanks for helping me, but I wana ask you something. If I use the event handlers of every image by itself then I could not drag adn drop them using mouseUp and mouseMove, because the event handlers of the image are only active within image ( at least thats what i figured out :|).
Anyhow, I made to code work but I dont think that it is effective and it flickers alot, I painted the TBitmap Image on the canvas and moved it accordingly CPP / C++ / C Code:
Now, the method you gave me looked like this in the end CPP / C++ / C Code:
But this did not work, actually I want the image to be dragged everything after that is in control, any suggestions ?? |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The