imported catch-22 sol clone with authors permission
[reactos.git] / rosapps / games / solitaire / cardlib / dropzone.cpp
diff --git a/rosapps/games/solitaire/cardlib/dropzone.cpp b/rosapps/games/solitaire/cardlib/dropzone.cpp
new file mode 100644 (file)
index 0000000..dfa6dcc
--- /dev/null
@@ -0,0 +1,69 @@
+//\r
+//     CardLib - DropZone class\r
+//\r
+//     Freeware\r
+//     Copyright J Brown 2001\r
+//\r
+#include <windows.h>\r
+\r
+#include "cardlib.h"\r
+#include "cardwindow.h"\r
+#include "dropzone.h"\r
+\r
+bool CardWindow::RegisterDropZone(int id, RECT *rect, pDropZoneProc proc)\r
+{\r
+       if(nNumDropZones == MAXDROPZONES)\r
+               return false;\r
+\r
+       DropZone *dz = new DropZone(id, rect, proc);\r
+       \r
+       dropzone[nNumDropZones++] = dz;\r
+\r
+       return false;\r
+}\r
+\r
+DropZone *CardWindow::GetDropZoneFromRect(RECT *rect)\r
+{\r
+       for(int i = 0; i < nNumDropZones; i++)\r
+       {\r
+               RECT inter;\r
+               RECT zone;\r
+                               \r
+               //if any part of the drag rectangle falls within a drop zone,\r
+               //let that take priority over any other card stack.\r
+               dropzone[i]->GetZone(&zone);\r
+\r
+               if(IntersectRect(&inter, rect, &zone))\r
+               {\r
+                       //see if the callback wants us to drop a card on\r
+                       //a particular stack\r
+                       return dropzone[i];\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+bool CardWindow::DeleteDropZone(int id)\r
+{\r
+       for(int i = 0; i < nNumDropZones; i++)\r
+       {\r
+               if(dropzone[i]->id == id)\r
+               {\r
+                       DropZone *dz = dropzone[i];\r
+                       \r
+                       //shift any after this one backwards\r
+                       for(int j = i; j < nNumDropZones - 1; j++)\r
+                       {\r
+                               dropzone[j] = dropzone[j + 1];\r
+                       }\r
+\r
+                       delete dz;\r
+                       nNumDropZones--;\r
+                       return true;\r
+               }       \r
+       }\r
+\r
+       return false;\r
+}\r
+\r