471,584 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,584 software developers and data experts.

Shape DragOver and DragDrop

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

Jan 3 '06 #1
3 2109
PM wrote:
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-lit...t.html#faq-5.9

Cheers! --M

Jan 3 '06 #2
PM wrote:
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/
Jan 3 '06 #3
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

Jan 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Kate | last post: by
reply views Thread by Gene Hubert | last post: by
3 posts views Thread by Gary Dunne | last post: by
1 post views Thread by Gary Brown | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.