/
cGraphicEngine.cpp
334 lines (280 loc) · 8.78 KB
/
cGraphicEngine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// cGraphicEngine.cpp
#include "StdAfx.h"
#include "cGraphicEngine.h"
#include "Resource.h"
// value from deck activex (mfc doesn't import them)
// category ID of Decks
// {B3C0DA05-7C56-40c9-9524-9E2F286B1B7D}
CATID CATID_Decks = { 0xb3c0da05, 0x7c56, 0x40c9, { 0x95, 0x24, 0x9e, 0x2f, 0x28, 0x6b, 0x1b, 0x7d } };
// interface IAxJpgCard
/*
const IID IID_IAxJpgCard = {0x25763CCD,0x4C53,0x11D5,{0xA3,0x1D,0x00,0xA0,0xCC,0x77,0xE7,0x9C}};
const ID IAxJpgCard
*/
#include <math.h>
#include "cBriscolaGame.h"
cGraphicEngine::cGraphicEngine()
{
m_pWin = 0;
m_lCardDimX = -1;
m_lCardDimY = -1;
}
////////////////////////////////////////
// checkCardsDecks
/*! Check all decks installed
*/
void cGraphicEngine::checkCardsDecks()
{
ICatInformation* pci = 0;
HRESULT hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 0,
CLSCTX_ALL, IID_ICatInformation, (void**)&pci);
if (pci)
{
IEnumCLSID *pec = 0;
CATID rgcid[1];
rgcid[0] = CATID_Decks;
hr = pci->EnumClassesOfCategories(1, rgcid, -1, 0, &pec);
if (pec)
{
enum{MAX = 64};
CLSID rgclsid[MAX];
do
{
ULONG cActual = 0;
hr = pec->Next(MAX, rgclsid, &cActual);
if (SUCCEEDED(hr))
{
for (unsigned int i = 0; i < cActual; i++)
{
getTheNameOfDeck(rgclsid[i]);
}
}
}
while( hr == S_OK ); // don't use SUCCEEDED please!
pec->Release();
}
pci->Release();
}
}
////////////////////////////////////////
// getTheNameOfDeck
/*!
// \param CLSID clDeck :
*/
void cGraphicEngine::getTheNameOfDeck(CLSID clDeck)
{
IAxJpgCard* pICard = 0;
HRESULT hr = CoCreateInstance(clDeck, 0, CLSCTX_ALL, IID_IAxJpgCard, (void**)&pICard );
_bstr_t bstrName = pICard->GetDeckName();
m_strNomeCarte = (char*)bstrName;
pICard->get_SizeImageX(&m_lCardDimX);
pICard->get_SizeImageY(&m_lCardDimY);
pICard->Release();
m_CLSIDDeck = clDeck;
//myCard.CreateControl(clDeck, NULL, WS_VISIBLE, CRect (0, 0, 150, 300), m_pWin, 1100);
//tmpCard.Create(NULL, WS_VISIBLE, CRect (0, 0, 150, 300), m_pWin, 1100);
}
////////////////////////////////////////
// Init
/*! Init game graphic engine
*/
BOOL cGraphicEngine::Init()
{
showSplash();
DestroySplash();
checkCardsDecks();
//createAllCards();
return TRUE;
}
////////////////////////////////////////
// createAllCards
/*!
*/
BOOL cGraphicEngine::createAllCards()
{
CRect rctParent;
m_pWin->GetClientRect(&rctParent);
int iWidthParent = rctParent.right - rctParent.left;
int iHeightParent = rctParent.bottom - rctParent.top;
CWnd* pcwndBut = m_pWin->GetDlgItem(IDOK);
CRect rctButton;
pcwndBut->GetClientRect(&rctButton);
int iWoffset = rctButton.right / 4;
// remove space for buttons on the right side
int iWidthToFill = iWidthParent - rctButton.right - iWoffset * 2;
// remove space on the left side
iWidthToFill = iWidthToFill - iWoffset;
// remove space on top
int iHeightToFill = iHeightParent - iWoffset;
// remove space on buttom
//iHeightToFill = iHeightToFill - iWoffset;
// 1/3 height is reserved for my hand: check is the dimension fit, if not reduce with proportion
int iHeightForMyHand = iHeightToFill / 3;
int iWidthForMyHand = iWidthToFill - iWoffset;
BOOL bWidthMyHandOk;
BOOL bHeightMyHandOk;
float dRatioWidthMyHand = 0.0;
float dRatioHeightMyHand = 0.0;
int iPrognoseWidthCard = m_lCardDimX;
int iPrognoseHeightCard = m_lCardDimY;
int iWidthPrognoseMyHand;
int iHeightPrognoseMyHand;
do
{
int iReduceStepH = 5;
int iReduceStepW = 5;
// check prognose my hand dimensions
iWidthPrognoseMyHand = 3 * iPrognoseWidthCard + 3 * iWoffset;
iHeightPrognoseMyHand = iPrognoseHeightCard;
//check the width
if (iWidthPrognoseMyHand < iWidthForMyHand)
{
bWidthMyHandOk = TRUE;
}
else
{
bWidthMyHandOk = FALSE;
}
dRatioWidthMyHand = (float)iWidthPrognoseMyHand / (float)iWidthForMyHand;
// check the height
if (iHeightPrognoseMyHand < iHeightForMyHand)
{
bHeightMyHandOk = TRUE;
}
else
{
bHeightMyHandOk = FALSE;
}
dRatioHeightMyHand = (float)iHeightPrognoseMyHand / (float)iHeightForMyHand;
if (!bHeightMyHandOk || !bWidthMyHandOk)
{
float fSup;
float fInf;
// some dimension have to be reduced
if ( dRatioHeightMyHand > dRatioWidthMyHand)
{
iPrognoseHeightCard -= iReduceStepH;
float fReduce = ((float)m_lCardDimX * iReduceStepH );
fReduce = fReduce / m_lCardDimY;
fInf = floor(fReduce);
fSup = ceil(fReduce);
if ( fReduce - fInf > fSup - fReduce)
{
iReduceStepW = (int)fSup;
}
else
{
iReduceStepW = (int)fInf;
}
iPrognoseWidthCard -= iReduceStepW;
}
else
{
iPrognoseWidthCard -= iReduceStepW;
float fReduce = ((float)m_lCardDimY * iReduceStepW );
fReduce = fReduce / m_lCardDimX;
fInf = floor(fReduce);
fSup = ceil(fReduce);
if ( fReduce - fInf > fSup - fReduce)
{
iReduceStepH = (int)fSup;
}
else
{
iReduceStepH = (int)fInf;
}
iPrognoseHeightCard -= iReduceStepH;
}
}
}
while (!bHeightMyHandOk || !bWidthMyHandOk);
int iWoffsetH = 10;
int iIDinitial = 1100;
int iXtop = iWoffset;
int iYtop = iHeightForMyHand * 2 + iWoffsetH;
// now we have the dimension for card in myhand, create the cards
for (int i = 0; i < 3; i ++)
{
m_vctAxMyCards[i].Create(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseWidthCard, iYtop + iPrognoseHeightCard), m_pWin, iIDinitial);
iIDinitial++;
iXtop = iXtop + iWoffset + iPrognoseWidthCard;
}
m_vctAxMyCards[0].SetCardIndex(1);
m_vctAxMyCards[1].SetCardIndex(2);
m_vctAxMyCards[2].SetCardIndex(3);
// now we can draw opponent cards
iXtop = iWoffset;
iYtop = 0 + iWoffsetH;
for (int i = 0; i < 3; i ++)
{
m_vctAxOppCards[i].CreateControl(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseWidthCard, iYtop + iPrognoseHeightCard), m_pWin, iIDinitial);
iIDinitial++;
iXtop = iXtop + iWoffset + iPrognoseWidthCard;
}
//deck
iXtop = (iWidthForMyHand / 2 - iPrognoseWidthCard );
iYtop = iHeightForMyHand + iWoffsetH;
m_AxMyDeck.CreateControl(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseWidthCard, iYtop + iPrognoseHeightCard), m_pWin, iIDinitial);
iIDinitial++;
// in tavola
iXtop = (iWidthForMyHand / 2 - iPrognoseWidthCard ) + iPrognoseWidthCard / 3;
iYtop = iHeightForMyHand + iWoffsetH + iPrognoseWidthCard / 2;
m_AXintavola.CreateControl(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseHeightCard, iYtop + iPrognoseWidthCard), m_pWin, iIDinitial);
iIDinitial++;
// carte giocate 1
iXtop = (iWidthForMyHand / 2 - iPrognoseWidthCard ) + 3 * iPrognoseWidthCard - 20;
iYtop = iHeightForMyHand + iWoffsetH - 10;
m_AxFirstPlayed.CreateControl(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseWidthCard, iYtop + iPrognoseHeightCard), m_pWin, iIDinitial);
iIDinitial++;
// carte giocate 2
iXtop = (iWidthForMyHand / 2 - iPrognoseWidthCard ) + 3 * iPrognoseWidthCard + 30;
iYtop = iHeightForMyHand + iWoffsetH + 10;
m_AxSecondPlayed.CreateControl(m_CLSIDDeck, NULL, WS_VISIBLE,
CRect (iXtop, iYtop, iXtop + iPrognoseWidthCard, iYtop + iPrognoseHeightCard), m_pWin, iIDinitial);
iIDinitial++;
return TRUE;
}
////////////////////////////////////////
// showSplash
/*!
*/
BOOL cGraphicEngine::showSplash()
{
// show spash screen
VERIFY(m_Splash.CreateFromStatic(IDC_HTMLINTRO, m_pWin));
m_Splash.LoadFromResource(_T("initial.htm"));
return TRUE;
}
////////////////////////////////////////
// DestroySplash
/*!
*/
BOOL cGraphicEngine::DestroySplash()
{
m_Splash.DestroyWindow();
return TRUE;
}
////////////////////////////////////////
// allcardsInvisible
/*! Set all cards controls Invisibile
*/
void cGraphicEngine::allcardsInvisible()
{
tagCARDSHOWSTATUS lStatusId = CSW_ST_INVISIBLE;
for (int i = 0; i < 3; i ++)
{
m_vctAxOppCards[i].SetCardStatus(&lStatusId);
m_vctAxMyCards[i].SetCardStatus(&lStatusId);
}
m_AxMazzoDeck.SetCardStatus(&lStatusId);
m_AxFirstPlayed.SetCardStatus(&lStatusId);
m_AxSecondPlayed.SetCardStatus(&lStatusId);
m_AXintavola.SetCardStatus(&lStatusId);
m_AxMyDeck.SetCardStatus(&lStatusId);
m_AxOpponentDeck.SetCardStatus(&lStatusId);
}