// optimization needed void CGame::DoDrop(CCardRegion *DestRegion) { CCardStack *DestStack; CCardRegion *BestRegion; if(DestRegion != NULL) BestRegion = DestRegion; // else BestRegion = this->GetBestStack(dcard.x, dcard.y, dcard.width, dcard.height, &DragStack); else BestRegion = this->GetBestStack(dcard.x, dcard.y, CARDWIDTH, CARDHEIGHT, &DragStack); if(BestRegion == NULL) BestRegion = SourceRegion; DestStack = BestRegion->GetCardStack(); DestStack->Push(DragStack); BestRegion->InitCardCoords(); VI vi; switch(SourceRegion->GetDragMode()) { case 2: case 3: vi = DestStack->end() - 1; break; default: // 1 and 4 vi = DestStack->end() - DragStack.Size(); } DragStack.Clear(); //when no movement if(dcard.x == vi->x && dcard.y == vi->y) return; ZoomCard(dcard.x, dcard.y, vi->x, vi->y, dcard.width, dcard.height, background, dragface); }
bool CardRegion::OnLButtonUp(int x, int y) { CardRegion *pDestStack = 0; HDC hdc; int dropstackid = CS_DROPZONE_NODROP; RECT dragrect; DropZone *dropzone; fMouseDragging = false; //first of all, see if any drop zones have been registered SetRect(&dragrect, x-mousexoffset, y-mouseyoffset, x-mousexoffset+nDragCardWidth, y-mouseyoffset+nDragCardHeight); dropzone = parentWnd.GetDropZoneFromRect(&dragrect); if(dropzone) { dropstackid = dropzone->DropCards(dragstack); if(dropstackid != CS_DROPZONE_NODROP) pDestStack = parentWnd.CardRegionFromId(dropstackid); else pDestStack = 0; } else { pDestStack = parentWnd.GetBestStack(x - mousexoffset, y - mouseyoffset, nDragCardWidth, nDragCardHeight); } // If have found a stack to drop onto // TRACE ( "can I drop card?\n" ); if(pDestStack && pDestStack->CanDropCards(dragstack)) { TRACE ( "yes, dropping card\n" ); hdc = GetDC((HWND)parentWnd); // UseNicePalette(hdc); ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, pDestStack); ReleaseDC((HWND)parentWnd, hdc); // //add the cards to the destination stack // CardStack temp = pDestStack->GetCardStack(); temp.Push(dragstack); pDestStack->SetCardStack(temp); // pDestStack->Update(); //Update this stack's card count + size // pDestStack->UpdateFaceDir(temp); // Call the remove callback on THIS stack, if one is specified // if(RemoveCallback) RemoveCallback(*this, iNumDragCards); // Call the add callback, if one is specified // if(pDestStack->AddCallback) pDestStack->AddCallback(*pDestStack, pDestStack->cardstack);//index, deststack->numcards); RedrawIfNotDim(pDestStack, true); TRACE ( "done dropping card\n" ); } // // Otherwise, let the cards snap back onto this stack // else { TRACE ( "no, putting card back\n" ); hdc = GetDC((HWND)parentWnd); TRACE ( "calling ZoomCard()\n" ); ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, this); TRACE ( "cardstack += dragstack\n" ); cardstack += dragstack; TRACE ( "calling ReleaseDC()\n" ); ReleaseDC((HWND)parentWnd, hdc); TRACE ( "calling Update()\n" ); Update(); //Update this stack's card count + size TRACE ( "done putting card back\n" ); } ReleaseDragBitmaps(); ReleaseCapture(); TRACE ( "OnLButtonUp() done\n" ); return true; }