Shape DragOver and DragDrop

P

PM

Hi,

Im a student currently designing a game for a project.

As part of my game, I want to be able to drag a shape over a series of
panels. The shape needs to be able to be dropped on any of the panels.

If the shape is dropped outside any of the panels, I want it to be
returned to its original position.

Does anyone have any hints to the code I should be using?

Thanks
 
M

mlimber

PM said:
Hi,

Im a student currently designing a game for a project.

As part of my game, I want to be able to drag a shape over a series of
panels. The shape needs to be able to be dropped on any of the panels.

If the shape is dropped outside any of the panels, I want it to be
returned to its original position.

Does anyone have any hints to the code I should be using?

Thanks

You want to post in comp.sources.wanted. This group is for discussing
C++ *language* issues, not platform-dependent applications. See the FAQ
for what is on topic here and for some additional suggestion of where
to post:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 
P

Peter Jansson

PM said:
Hi,

Im a student currently designing a game for a project.

As part of my game, I want to be able to drag a shape over a series of
panels. The shape needs to be able to be dropped on any of the panels.

If the shape is dropped outside any of the panels, I want it to be
returned to its original position.

Does anyone have any hints to the code I should be using?

Thanks

Hi,

This news group discuss the C++ language as defined by the ANSI/ISO
standard; Therefore, I assume that your "game", "shape" and "panel"
objects are standard C++ classes and further assume that you have the
methods "drop(const shape&)" and "position()" implemented somewhere in
your code.

If so, I guess you need a loop over all panels and an if-statement to
check that the shape is within all panels and a method to set the
position of your "shape" object.

If not, go to a more appropriate news group.

Regards,
Peter Jansson
http://www.jansson.net/
 
L

Luke Meyers

It will depend heavily on the GUI framework you're using, and specific
questions about that will have to be addressed in another forum than
this one. However, I can give you a general indication of how that
functionality is likely to be implemented.

GUIs are generally implemented with an event loop. Events such as
mouse clicks occur, and you write handlers for them. Often it's rolled
up into a big switch statement, with a case for each kind of event.
Some pseudocode for a case like you described:

void processEvent(Event e) {
switch (e.eventType) {
case MOUSE_DOWN:
// Grab hold of a shape
break;
case MOUSE_UP:
if (draggingShape)
if (inPanel())
dropShape();
else revertShape();
break;
// etc.
}
}

HTH,
Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top