GuiDragAndDropControl in Torque 3D
by Joshua Parker · in Torque 3D Professional · 07/30/2009 (5:36 pm) · 6 replies
Does anyone know if GuiDragAndDropControl is working properly in Torque 3D or not? I have followed the example in http://www.garagegames.com/community/forums/viewthread/79327 to create Drag and Drop controls that can be used for an inventory system. The problem I keep running into comes when I apply a GuiBitmapCtrl object to the control to represent an object. I am unable to drag the object if I click on the mouse inside if the bitmap image. So say I have a 64 by 64 GuiBitmapCtrl that fits into a 64 by 64 GuiDragAndDropControl, I am unable to select and drag the object. If however I were to palce a 32 by 32 bitmap inside of a 64 by 64 control, I am able to select on the portion of the control that the bitmap does not occupy,(the part that can not be seen). The entire object can then be moved around, including the bitmap image inside the control. the object can be dropped, and picked up again as long as it is selected inside the area not occupied by the image. Is this a fluke in the GuiDragAndDropControl, or am I simply implementing it the wrong way?
About the author
Hobbiest Programmer/Designer
#2
function guiBitmapButtonCtrl::onMouseDragged(%this)
that was shown in the link I posted above. I never could get the funtion itself to work with a guiBitmapButtonCtrl. Im not exactly sure how drag and drop works on buttons as opposed to the actual drag and drop control. So basicly what I have is the control with a bitmap sitting in it. I drag on the control outside of the bitmap. I have it set to not delete after dropping and I use a function to read the cursor position in relation to designated drop points. So if my mouse is in an acceptable rectangular area when I release the mouse button, the entire control snaps to that area's position, making for nice, neat drops.
One proble I do run into is the engine crashing if I persistently try dragging from the bitmap rather than outside of it.
07/31/2009 (6:08 pm)
I had tried using thefunction guiBitmapButtonCtrl::onMouseDragged(%this)
that was shown in the link I posted above. I never could get the funtion itself to work with a guiBitmapButtonCtrl. Im not exactly sure how drag and drop works on buttons as opposed to the actual drag and drop control. So basicly what I have is the control with a bitmap sitting in it. I drag on the control outside of the bitmap. I have it set to not delete after dropping and I use a function to read the cursor position in relation to designated drop points. So if my mouse is in an acceptable rectangular area when I release the mouse button, the entire control snaps to that area's position, making for nice, neat drops.
One proble I do run into is the engine crashing if I persistently try dragging from the bitmap rather than outside of it.
#3
A GuiBitmapButtonCtrl is not a GuiDragAndDropCtrl. If you parent the button within a GuiDragAndDropCtrl, you can get the approximate behavior, but it will be limited to the area that you've set for the GuiDragAndDropCtrl.
With the onMouseDragged approach, what you are saying is:
"When a drag action is performed on this button, create a new bitmap that is a copy of the actual bitmap, and set it as the payload on a new GuiDragAndDropCtrl. Add the GuiDragAndDropCtrl to the canvas so that I can move it anywhere."
You will have deleteOnMouseUp set to true, to do proper cleanup.
The resource is sound, you just have to be persistent and watch the console for issues you experience.
08/01/2009 (5:22 am)
I think you want to backup and get the onMouseDragged approach working.A GuiBitmapButtonCtrl is not a GuiDragAndDropCtrl. If you parent the button within a GuiDragAndDropCtrl, you can get the approximate behavior, but it will be limited to the area that you've set for the GuiDragAndDropCtrl.
With the onMouseDragged approach, what you are saying is:
"When a drag action is performed on this button, create a new bitmap that is a copy of the actual bitmap, and set it as the payload on a new GuiDragAndDropCtrl. Add the GuiDragAndDropCtrl to the canvas so that I can move it anywhere."
You will have deleteOnMouseUp set to true, to do proper cleanup.
The resource is sound, you just have to be persistent and watch the console for issues you experience.
#4
So, looking at that resource, every mouseMove we are creating a new GuiBitmapCtrl and a new GuiDragAndDropControl, we are creating a lot of new objects, or after we have created the guiDragAndDropControl, the onMouseDragged event is delivered to this new control?
08/01/2009 (9:11 am)
Just a silly question, but onMouseDragged isn't called for every mouseMove event?So, looking at that resource, every mouseMove we are creating a new GuiBitmapCtrl and a new GuiDragAndDropControl, we are creating a lot of new objects, or after we have created the guiDragAndDropControl, the onMouseDragged event is delivered to this new control?
#5
So with all of that being said, dragging the mouse does not create a new object every time the mouse is moved, Only a new image at the start, and a new object at the end.
08/02/2009 (7:17 am)
For my project, I have included the four functions: onControlDragEnter, onControlDragged, onControlDropped, and onControlDragExit even though I have yet to see this fouth one actuly be called. How I was able to get mine to work was to create a drag and drop control with a GuiBitmapCtrl set to invisible inside of it, which also meant needing to create a guiContainer holding a visible representation of what I wanted to drag.(Seems like there would be a better way. Please let me know if there is.) Once you click on the control and start to move the mouse, onControlDragEnter is called. Here is where you want to create a visble bitmap image inside of the control. onControlDragged takes over and is called repeatedly until onControlDropped is exacuted but does not create any new objects. onControlDropped is where you want to create a new drag an drop control becasue the one you just dropped has been deleted.(deleteOnMouseUp is set to true on the control to function properly). So create the new control, fill it with another invisible GuiBitmapCtrl, and set a visable copy of the image at the position of the control, but not as a child of the control.(Again, a little help if there isa cleaner way to accomplish this.)So with all of that being said, dragging the mouse does not create a new object every time the mouse is moved, Only a new image at the start, and a new object at the end.
#6
I am looking for any resources on how to take an object from the ObjectViewer on a GUI to a 3D object in the scene. Any ideas?
08/29/2009 (10:12 pm)
Take a look at the guiEditorPalette.ed.cs file as it does drag and drop from one gui to another. And works in Beta5.I am looking for any resources on how to take an object from the ObjectViewer on a GUI to a 3D object in the scene. Any ideas?
Torque 3D Owner Robert Lee
One quick question - are you following the resource to where in the OnMouseDragged method you are creating a new bitmap for the dragged object?
If you have one icon that you expect to drag that is the original GuiBitmapCtrl I think you'll run into the problem where its representation is clipped by the parent control that contains it.
If you want it to "move", I think you'll want to hide the bitmap on the source GuiBitmapCtrl with the new bitmap being the proxy actually being moved. This proxy also has the benefit that it will render all over your PlayGui.