d2806a9c9b52505522632266497b5fb4727cfdaa
[reactos.git] / rosapps / games / solitaire / cardlib / cardregion.h
1 #ifndef CARDREGION_INCLUDED
2 #define CARDREGION_INCLUDED
3
4 #include "globals.h"
5 #include "cardstack.h"
6 #include "cardlib.h"
7
8 class CardWindow;
9
10 //
11 // This class defines a physical card-stack,
12 // which draws the cards, supports
13 //
14
15 class CardRegion
16 {
17 friend class CardWindow;
18 friend class CardStack;
19
20 //
21 // Constructor is PRIVATE - only
22 // a CardWindow can create cardstacks!
23 //
24 CardRegion(CardWindow &parent, int id, bool fVisible,
25 int x, int y, int xOffset, int yOffset);
26
27 ~CardRegion();
28
29 public:
30
31 void SetBackColor(COLORREF cr);
32
33 void SetCardStack(const CardStack &cs);
34 const CardStack & GetCardStack();
35
36 //
37 // Event-callback support
38 //
39 bool SetDragRule(UINT uDragType, pCanDragProc proc = 0);
40 bool SetDropRule(UINT uDropType, pCanDropProc proc = 0);
41
42 void SetClickProc (pClickProc proc);
43 void SetDblClickProc (pClickProc proc);
44
45 void SetAddCardProc (pAddProc proc);
46 void SetRemoveCardProc (pRemoveProc proc);
47
48 //
49 // Physical attribute support
50 //
51 bool SetThreedCount (int count);
52 void SetOffsets (int x, int y);
53 void SetPos (int x, int y);
54 void Show (bool fShow);
55 bool IsVisible ();
56
57 void SetEmptyImage (UINT uImage);
58 void SetBackCardIdx (UINT uBackIdx);
59 void SetPlacement (UINT xJustify, UINT yJustify, int xAdjust, int yAdjust);
60
61 void Update();
62 void Redraw();
63
64 void SetFaceDirection(UINT uDirType, int nOption);
65 UINT GetFaceDirection(int *pnOption);
66
67 void Flash(int count, int timeout);
68 void StopFlash();
69
70 int Id();
71
72 CardWindow &GetCardWindow() { return parentWnd; }
73
74 bool PlayCard(CardRegion *pDestStack, int value, int num);
75 bool MoveCard(CardRegion *pDestStack, int nNumCards, bool fAnimate);
76 bool SimulateDrag(CardRegion *pDestStack, int nNumCards, bool fAnimate);
77
78 bool Lock();
79 bool UnLock();
80
81 //
82 // Common wrappers for the CardStack object
83 //
84 int NumCards() const;
85 void NewDeck() { cardstack.NewDeck(); }
86 void Shuffle() { cardstack.Shuffle(); }
87 void Clear() { cardstack.Clear(); }
88
89 void Reverse() { cardstack.Reverse(); }
90
91 void Push(const Card card) { cardstack.Push(card); }
92 void Push(const CardStack &cs) { cardstack.Push(cs); }
93
94 Card Pop() { return cardstack.Pop(); }
95 CardStack Pop(int items) { return cardstack.Pop(items); }
96
97 Card Top() { return cardstack.Top(); }
98 CardStack Top(int items) { return cardstack.Top(items); }
99
100
101 private:
102
103 void DoFlash();
104 void RedrawIfNotDim(CardRegion *compare, bool fFullRedraw);
105
106 void UpdateFaceDir(CardStack &cards);
107 void Clip(HDC hdc);
108 void Render(HDC hdc);
109 int GetOverlapRatio(int x, int y, int width, int height);
110
111 void MoveDragCardTo(HDC hdc, int x, int y);
112 void ZoomCard(HDC hdc, int xpos, int ypos, CardRegion *dest);
113
114 void RenderBottomMost(HDC hdc, int minustopmost = 0);
115 void PrepareDragBitmaps(int numtodrag);
116 void PrepareDragBitmapsThreed(int numtodrag);
117 void ReleaseDragBitmaps(void);
118
119 bool CanDragCards(int iNumCards);
120 bool CanDropCards(CardStack &cards);
121
122 void CalcApparentCards();
123 int CalcApparentCards(int realnum);
124
125 void UpdateSize();
126 void AdjustPosition(int winwidth, int winheight);
127
128 bool IsPointInStack(int x, int y);
129
130 int GetNumDragCards(int x, int y);
131 bool OnLButtonDown(int x, int y);
132 bool OnLButtonDblClk(int x, int y);
133 bool OnMouseMove(int x, int y);
134 bool OnLButtonUp(int x, int y);
135
136
137 //
138 // Private data members
139 //
140
141 int id;
142
143 CardWindow &parentWnd;
144
145 CardStack cardstack; //cards in this stack
146 CardStack dragstack; //cards which we might be dragging
147
148 bool fMouseDragging;
149
150 int xoffset; //direction that cards take
151 int yoffset;
152
153 int xpos; //coordinates of stack
154 int ypos;
155
156 int width; //stack-size of all cards
157 int height;
158
159 //
160 // justify / placement vars
161 int xjustify;
162 int yjustify;
163 int xadjust;
164 int yadjust;
165
166 //
167 // Used for mouse-dragging / moving cards
168 //
169 int iNumDragCards;
170 int mousexoffset;
171 int mouseyoffset;
172 int oldx;
173 int oldy;
174
175 int nDragCardWidth;
176 int nDragCardHeight;
177
178 HDC hdcBackGnd;
179 HBITMAP hbmBackGnd;
180 HDC hdcDragCard;
181 HBITMAP hbmDragCard;
182
183 int nNumApparentCards;
184 int nThreedCount;
185 bool fVisible;
186
187 int nFlashCount;
188 bool fFlashVisible;
189 UINT uFlashTimer;
190
191 COLORREF crBackgnd;
192
193 UINT uEmptyImage;
194 UINT uFaceDirType;
195 int nFaceDirOption;
196 int nBackCardIdx;
197
198 UINT uDragRule;
199 UINT uDropRule;
200
201 //
202 // Stack callback support
203 //
204 pCanDragProc CanDragCallback;
205 pCanDropProc CanDropCallback;
206 pClickProc ClickCallback;
207 pClickProc DblClickCallback;
208 pAddProc AddCallback;
209 pRemoveProc RemoveCallback;
210
211 //locking mechanism to prevent user dragging etc
212 HANDLE mxlock;
213 };
214
215 #endif
216