Jump to content
  • Advertisement
Sign in to follow this  
Ludi83

Drag and Drop

This topic is 4483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm currently working on a scriptable GUI for a game. It has already the basic items, like buttons, labels, windows, tooltips. Now I want to add DnD to the system. It will be needed to, e.g. add items to a character sheet or add skills to some kind of "quick menu", etc. What's the best approach to do DnD. I need some basic tips, how to do it. I don't post any source code, because I don't know, what would be important. So, if you need more informations, feel free to ask. Greetings

Share this post


Link to post
Share on other sites
Advertisement
important elements of dragdrop are mouse movement/position, state of mouse buttons, and active view

Kuphryn

Share this post


Link to post
Share on other sites
I can explain how I did it in my GUI system.

First off, all events, like mouse motion and mouse buttons, start at the 'root widget' and perculate upwards through all child widgets.

It is the to-be-dragged widgets responsibility to initiate a drag operation. For example, when the widget that represents an inventory item receives the mouse button down event, it would call this->drag. (This really might be rather confusing without source code...)

The drag function sets a flag saying 'we are dragging something', remembers the widget being dragged, and where it is. Then it removes it from it's current parent and sticks it into the root widget, so that it floats on top of everything.

Now, when this inventory item widget receives a mouse_motion event, it asks 'Am I being dragged?' Since it is, it 'sticks' itself to the mouse.

When it receives a mouse button up event, it figures out what the top-most (or forward-most) widget is under the mouse (excluding itself). It asks the top-most "Can I be dropped here?" If it can, it adds itself to that widget. If not, it teleports itself back to where it was originally. Then is clears the 'we are dragging something' flag.

You can find almost all of the code for my GUI in my journal. The widget base class is there in it's entirety, but there aren't any actual example widgets.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!