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