Game Development Reference
In-Depth Information
'
Here
s the code that performs this dirty work of the drag:
// Place this code at the top of your mouse movement handler
if (m_aboutToDrag)
{
CPoint offset = currentPoint - dragStartingPoint;
if (abs(offset.x) > DRAG_THRESHOLD || abs(offset.y) > DRAG_THRESHOLD)
{
// We have a real drag event!
bool dragOK =
pseudocode::InitiateDrag(draggedObject, dragStartingPoint);
SetCapture( GetWindow()->m_hWnd );
m_dragging = TRUE;
}
}
The call to pseudocode::InitiateDrag() is something you write yourself. Its
job is to set the game state to remove the original object from the display and draw
the dragged object in some obvious form, such as a transparent ghost object.
Until the mouse button is released, the mouse movement handler will continue to get
mouse movement commands, even those that are outside the client area of your win-
dow if you are running in windowed mode. Make sure that your draw routines don
'
t
freak out when they see these odd coordinates.
While the drag is active, you must direct all the mouse input to the control that ini-
tiated the drag. Other controls should essentially ignore the input. The best way to do
this is to keep a pointer to the control that initiated the drag and send all input
directly to it, essentially bypassing any code that sends messages to your control list.
It
s a little like masking all the controls in your control list, rendering them deaf to all
incoming messages until the drag is complete.
What must go down must finally come up again. When the mouse button is released,
your drag is complete, but the drag location might not be in a legal spot, so you
might have to reset your game back to the state before the drag started, like this:
'
// Place this code at the top of your mouse button up handler
if ( m_dragging )
{
ReleaseCapture();
m_bDragging = false;
if (!pseudocode::FinishDrag(point))
{
Search WWH ::




Custom Search