imported catch-22 sol clone with authors permission
[reactos.git] / rosapps / games / solitaire / cardlib / dropzone.cpp
1 //
2 // CardLib - DropZone class
3 //
4 // Freeware
5 // Copyright J Brown 2001
6 //
7 #include <windows.h>
8
9 #include "cardlib.h"
10 #include "cardwindow.h"
11 #include "dropzone.h"
12
13 bool CardWindow::RegisterDropZone(int id, RECT *rect, pDropZoneProc proc)
14 {
15 if(nNumDropZones == MAXDROPZONES)
16 return false;
17
18 DropZone *dz = new DropZone(id, rect, proc);
19
20 dropzone[nNumDropZones++] = dz;
21
22 return false;
23 }
24
25 DropZone *CardWindow::GetDropZoneFromRect(RECT *rect)
26 {
27 for(int i = 0; i < nNumDropZones; i++)
28 {
29 RECT inter;
30 RECT zone;
31
32 //if any part of the drag rectangle falls within a drop zone,
33 //let that take priority over any other card stack.
34 dropzone[i]->GetZone(&zone);
35
36 if(IntersectRect(&inter, rect, &zone))
37 {
38 //see if the callback wants us to drop a card on
39 //a particular stack
40 return dropzone[i];
41 }
42 }
43
44 return 0;
45 }
46
47 bool CardWindow::DeleteDropZone(int id)
48 {
49 for(int i = 0; i < nNumDropZones; i++)
50 {
51 if(dropzone[i]->id == id)
52 {
53 DropZone *dz = dropzone[i];
54
55 //shift any after this one backwards
56 for(int j = i; j < nNumDropZones - 1; j++)
57 {
58 dropzone[j] = dropzone[j + 1];
59 }
60
61 delete dz;
62 nNumDropZones--;
63 return true;
64 }
65 }
66
67 return false;
68 }
69