void CardRegion::Clip(HDC hdc) { int numtoclip; if(fVisible == false) return; Update(); //Update this stack's size+card count numtoclip = nNumApparentCards; //if we are making this stack flash on/off, then only //clip the stack for drawing if the flash is in its ON state if(nFlashCount != 0) { if(fFlashVisible == FALSE) numtoclip = 0; } //if offset along a diagonal if(xoffset != 0 && yoffset != 0 && cardstack.NumCards() != 0) { for(int j = 0; j < numtoclip; j ++) { ClipCard(hdc, xpos + xoffset * j, ypos + yoffset * j, __cardwidth, __cardheight); } } //otherwise if just offset along a horizontal/vertical axis else { if(yoffset < 0 && numtoclip > 0) { ClipCard(hdc, xpos, ypos-((numtoclip-1)*-yoffset), width, height); } else if(xoffset < 0 && numtoclip > 0) { ClipCard(hdc, xpos-((numtoclip-1)*-xoffset), ypos, width, height); } else { ClipCard(hdc, xpos, ypos, width, height); } } }
void CardRegion::MoveDragCardTo(HDC hdc, int x, int y) { RECT inter, rect1, rect2; //mask off the new position of the drag-card, so //that it will not be painted over ClipCard(hdc, x, y, nDragCardWidth, nDragCardHeight); //restore the area covered by the card at its previous position BitBlt(hdc, oldx, oldy, nDragCardWidth, nDragCardHeight, hdcBackGnd, 0, 0, SRCCOPY); //remove clipping so we can draw the card at its new place SelectClipRgn(hdc, NULL); //if the card's old and new positions overlap, then we //need some funky code to update the "saved background" image, SetRect(&rect1, oldx, oldy, oldx+nDragCardWidth, oldy+nDragCardHeight); SetRect(&rect2, x, y, x+nDragCardWidth, y+nDragCardHeight); if(IntersectRect(&inter, &rect1, &rect2)) { int interwidth = inter.right-inter.left; int interheight = inter.bottom-inter.top; int destx, desty, srcx, srcy; if(rect2.left > rect1.left) { destx = 0; srcx = nDragCardWidth - interwidth; } else { destx = nDragCardWidth - interwidth; srcx = 0; } if(rect2.top > rect1.top) { desty = 0; srcy = nDragCardHeight - interheight; } else { desty = nDragCardHeight - interheight; srcy = 0; } //shift the bit we didn't use for the restore (due to the clipping) //into the opposite corner BitBlt(hdcBackGnd, destx,desty, interwidth, interheight, hdcBackGnd, srcx, srcy, SRCCOPY); ExcludeClipRect(hdcBackGnd, destx, desty, destx+interwidth, desty+interheight); //this bit requires us to clip the BitBlt (from screen to background) //as BitBlt is a bit buggy it seems ClippedBitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); SelectClipRgn(hdcBackGnd, NULL); } else { BitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); } //finally draw the card to the screen DrawCard(hdc, x, y, hdcDragCard, nDragCardWidth, nDragCardHeight); }