I created a GuiWindow class that held a texture, title, and rectangle so I can draw the texture and title. I’ve been trying to make it draggable, though I am having a bit of trouble. Originally I had the GuiWindow’s bounds rectangle just lock onto the mouse positions:
if(bounds.contains(MouseHandle.Update()) && MouseHandle.Pressed()) //checks if the bounds rectangle contains the mouse rectangle and the mouse left button is pressed
{
bounds.X = MouseHandle.Update().X;
bounds.Y = MouseHandle.Update().Y;
}
which would allow me to drag, though only in a single direction. I then tried
if(bounds.contains(MouseHandle.Update()) && MouseHandle.Pressed())
{
int offx = bounds.X - MouseHandle.Update().X;
int offy = bounds.Y - MouseHandle.Update().Y;
bounds.X = MouseHandle.Update().X + offx;
bounds.Y = MouseHandle.Update().Y + offy;
}
this time the window just stayed still when I tried dragging. I’m pretty sure I have the basic concept of dragging down. Am I doing something wrong?
Alright this is some code that I’ve been using to move objects with the mouse in some of my XNA applications. Hopefully this will help you with your problem.
This will make you able to drag the object with the mouse. Now of course this won’t be directly copyable to your application, as i don’t know how the code of your GuiWindow, but it should be easy to convert to your needs. Hope this helps 🙂