Mercurial > mm7
annotate Mouse.cpp @ 1232:8eb865b584db
m
author | Ritor1 |
---|---|
date | Sun, 09 Jun 2013 16:38:54 +0600 |
parents | 29a8defbad9e |
children | fac7751b2dc9 |
rev | line source |
---|---|
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
1 #ifdef _MSC_VER |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
3 #endif |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
4 |
0 | 5 #include "OSAPI.h" |
6 | |
1016 | 7 #include "VideoPlayer.h" |
8 #include "Vis.h" | |
0 | 9 #include "Mouse.h" |
10 #include "Items.h" | |
11 #include "Party.h" | |
12 #include "LOD.h" | |
13 #include "Game.h" | |
14 | |
1016 | 15 #include "stru11.h" |
0 | 16 |
17 | |
18 | |
19 | |
20 | |
21 Mouse *pMouse; | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 //----- (00469860) -------------------------------------------------------- | |
28 void Mouse::GetClickPos(unsigned int *pX, unsigned int *pY) | |
29 { | |
1038 | 30 *pX = uMouseClickX; |
31 *pY = uMouseClickY; | |
0 | 32 } |
33 | |
34 //----- (004698A6) -------------------------------------------------------- | |
35 void Mouse::RemoveHoldingItem() | |
36 { | |
37 pParty->pPickedItem.Reset(); | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
38 if (_stricmp(pCurrentCursorName, "MICON2")) |
0 | 39 SetCursorBitmap("MICON1"); |
40 } | |
41 | |
42 //----- (004698D8) -------------------------------------------------------- | |
43 void Mouse::SetCursorBitmapFromItemID(unsigned int uItemID) | |
44 { | |
45 pMouse->SetCursorBitmap(pItemsTable->pItems[uItemID].pIconName); | |
46 } | |
47 | |
48 //----- (004698F6) -------------------------------------------------------- | |
49 void Mouse::SetCurrentCursorBitmap() | |
50 { | |
51 SetCursorBitmap(pCurrentCursorName); | |
52 } | |
53 | |
54 //----- (00469903) -------------------------------------------------------- | |
55 void Mouse::SetCursorBitmap(const char *pName) | |
56 { | |
57 Mouse *v2; // esi@1 | |
58 HCURSOR v3; // eax@10 | |
1038 | 59 //int v4; // ecx@10 |
0 | 60 double v5; // st7@11 |
61 float v6; // ST04_4@12 | |
62 LONG v7; // eax@14 | |
63 LONG v8; // eax@17 | |
64 unsigned int v9; // eax@21 | |
65 float v10; // [sp+4h] [bp-18h]@11 | |
66 struct tagPOINT Point; // [sp+14h] [bp-8h]@20 | |
67 | |
68 v2 = this; | |
69 if ( !this->bInitialized || !pName ) | |
70 return; | |
1104 | 71 if ( _stricmp("MICON2", pName) ) |
0 | 72 pGame->uFlags2 &= 0xFFFFFFEFu; |
73 else | |
74 pGame->uFlags2 |= 0x10u; | |
1104 | 75 if ( _stricmp(v2->pCurrentCursorName, pName) ) |
0 | 76 strcpy(v2->pCurrentCursorName, pName); |
77 ClearCursor(); | |
78 if ( _strnicmp(pName, "MICON1", 5u) ) | |
79 { | |
80 v9 = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE); | |
81 v2->uCursorTextureID = v9; | |
82 v2->uCursorTextureID_2 = v9; | |
83 v2->AllocCursorSystemMem(); | |
84 v2->field_C = 0; | |
791 | 85 v2->bRedraw = 1; |
0 | 86 v2->bActive = 1; |
87 if ( !areWeLoadingTexture ) | |
88 { | |
89 if (uCursorTextureID != -1) | |
90 pIcons_LOD->pTextures[uCursorTextureID].Release(); | |
1006 | 91 pIcons_LOD->SyncLoadedFilesCount(); |
0 | 92 } |
93 return; | |
94 } | |
95 v2->bActive = 0; | |
96 v2->field_C = 1; | |
97 if ( !strcmp(pName, "MICON1") ) | |
98 { | |
99 v3 = LoadCursorA(GetModuleHandleW(nullptr), "Arrow"); | |
100 SetClassLongA(hWnd, GCL_HCURSOR, (LONG)v3); | |
101 } | |
1068 | 102 else if ( !strcmp(pName, "MICON2") ) |
0 | 103 { |
104 v7 = (LONG)LoadCursorA(GetModuleHandleW(nullptr), "Target"); | |
105 SetClassLongA(hWnd, -12, v7); | |
106 } | |
1068 | 107 else if ( !strcmp(pName, "MICON3") ) |
0 | 108 { |
109 v8 = (LONG)LoadCursorA(0, (LPCSTR)IDC_WAIT); | |
110 SetClassLongA(hWnd, -12, v8); | |
111 } | |
779 | 112 //LABEL_18: |
1038 | 113 |
779 | 114 GetCursorPos(&Point); |
1068 | 115 ClientToScreen(hWnd,&Point); |
779 | 116 SetCursorPos(Point.x, Point.y); |
0 | 117 } |
118 // 506128: using guessed type int areWeLoadingTexture; | |
119 | |
120 //----- (00469AE4) -------------------------------------------------------- | |
121 LONG Mouse::_469AE4() | |
122 { | |
123 Mouse *v1; // esi@1 | |
124 LONG v2; // ecx@2 | |
125 LONG result; // eax@2 | |
126 struct tagPOINT Point; // [sp+Ch] [bp-8h]@2 | |
127 | |
128 v1 = this; | |
129 this->field_8 = 1; | |
1038 | 130 /*if (pAsyncMouse) |
0 | 131 { |
132 v2 = *((int *)pAsyncMouse + 6); | |
133 Point.x = *((int *)pAsyncMouse + 6); | |
134 result = *((int *)pAsyncMouse + 7); | |
135 } | |
136 else | |
1038 | 137 {*/ |
0 | 138 GetCursorPos(&Point); |
139 if ( pRenderer->bWindowMode ) | |
140 ScreenToClient(hWnd, &Point); | |
141 result = Point.y; | |
142 v2 = Point.x; | |
1038 | 143 //} |
0 | 144 v1->uMouseClickX = v2; |
145 v1->uMouseClickY = result; | |
146 if ( pRenderer->bWindowMode ) | |
147 goto LABEL_16; | |
1038 | 148 //if (pAsyncMouse) |
149 // goto LABEL_24; | |
0 | 150 if ( v2 < 0 ) |
151 v2 = 0; | |
152 if ( result < 0 ) | |
153 result = 0; | |
154 if ( v2 > 639 ) | |
155 v2 = 639; | |
156 if ( result > 479 ) | |
157 { | |
158 result = 479; | |
159 LABEL_16: | |
1038 | 160 //if (pAsyncMouse) |
161 // goto LABEL_24; | |
0 | 162 if ( pRenderer->bWindowMode && (v2 < 0 || result < 0 || v2 > 639 || result > 479) ) |
163 goto LABEL_23; | |
164 } | |
165 if ( v1->field_C ) | |
166 LABEL_23: | |
167 v1->bActive = 0; | |
168 LABEL_24: | |
169 v1->field_8 = 0; | |
170 return result; | |
171 } | |
172 | |
173 //----- (00469BA3) -------------------------------------------------------- | |
174 void Mouse::ClearCursor() | |
175 { | |
176 Mouse *v1; // esi@1 | |
177 void *v2; // eax@1 | |
178 void **v3; // esi@5 | |
179 | |
180 v1 = this; | |
181 v2 = this->pCursorBitmap_sysmem; | |
182 this->bActive = 0; | |
183 if ( v2 ) | |
184 { | |
185 free(v2); | |
186 v1->pCursorBitmap_sysmem = 0; | |
187 } | |
188 if ( v1->pCursorBitmap2_sysmem ) | |
189 { | |
190 free(v1->pCursorBitmap2_sysmem); | |
191 v1->pCursorBitmap2_sysmem = 0; | |
192 } | |
193 v3 = &v1->ptr_90; | |
194 if ( *v3 ) | |
195 free(*v3); | |
196 *v3 = 0; | |
197 } | |
198 | |
199 //----- (00469BE6) -------------------------------------------------------- | |
200 void Mouse::AllocCursorSystemMem() | |
201 { | |
202 bActive = 0; | |
203 if (!pCursorBitmap_sysmem) | |
204 pCursorBitmap_sysmem = (unsigned __int16 *)DoAllocCursorMem(); | |
205 if (!pCursorBitmap2_sysmem) | |
206 pCursorBitmap2_sysmem = (unsigned __int8 *)DoAllocCursorMem(); | |
207 } | |
208 | |
209 //----- (00469C0D) -------------------------------------------------------- | |
210 void *Mouse::DoAllocCursorMem() | |
211 { | |
973 | 212 auto tex = pIcons_LOD->GetTexture(uCursorTextureID); |
213 return malloc(4 * tex->uTextureWidth * tex->uTextureHeight); | |
0 | 214 } |
215 | |
216 //----- (00469C39) -------------------------------------------------------- | |
217 POINT *Mouse::GetCursorPos(POINT *a2) | |
218 { | |
1038 | 219 a2->x = this->uMouseClickX; |
220 a2->y = this->uMouseClickY; | |
221 return a2; | |
0 | 222 } |
223 | |
224 //----- (00469C65) -------------------------------------------------------- | |
225 void Mouse::Initialize(HWND hWnd) | |
226 { | |
227 this->hWnd = hWnd; | |
228 this->bActive = 0; | |
229 this->bInitialized = 1; | |
230 this->pCursorBitmapPos.x = 0; | |
231 this->pCursorBitmapPos.y = 0; | |
232 this->uMouseClickX = 0; | |
233 this->uMouseClickY = 0; | |
234 this->pCursorBitmap_sysmem = 0; | |
235 this->field_34 = 0; | |
236 this->pCursorBitmap2_sysmem = 0; | |
237 | |
238 SetCursorBitmap("MICON3"); | |
239 SetCursorBitmap("MICON2"); | |
240 SetCursorBitmap("MICON1"); | |
241 } | |
242 | |
762 | 243 // inlined |
244 //----- (0045FE00) mm6 chinese -------------------------------------------- | |
245 void Mouse::SetActive(bool active) | |
246 { | |
247 bActive = active; | |
248 } | |
249 | |
0 | 250 //----- (00469CC2) -------------------------------------------------------- |
251 void Mouse::Deactivate() | |
252 { | |
253 if (bInitialized) | |
762 | 254 SetActive(false); |
0 | 255 } |
256 | |
257 //----- (00469CCD) -------------------------------------------------------- | |
258 void Mouse::DrawCursor() | |
259 { | |
260 Mouse *v1; // esi@1 | |
261 char v11; // zf@6 | |
262 signed int v3; // eax@6 | |
263 signed int v4; // ecx@6 | |
264 Vec4_int_ *v5; // edx@21 | |
265 int v6; // edi@21 | |
266 int v7; // ebx@21 | |
267 int v8; // eax@29 | |
268 unsigned int v9; // eax@31 | |
269 | |
270 v1 = this; | |
271 if ( this->bInitialized ) | |
272 { | |
273 if ( !this->field_8 && this->bActive && !this->field_C ) | |
274 pMouse->_469AE4(); | |
275 v11 = v1->field_C == 0; | |
276 v3 = v1->uMouseClickX; | |
277 v4 = v1->uMouseClickY; | |
278 v1->field_F4 = 1; | |
279 if ( !v11 ) | |
280 goto LABEL_12; | |
281 if ( pRenderer->bWindowMode ) | |
282 { | |
283 if ( v3 < 0 || v4 < 0 || v3 > 639 || v4 > 479 ) | |
284 { | |
285 LABEL_12: | |
286 v1->field_F4 = 0; | |
287 return; | |
288 } | |
289 } | |
290 else | |
291 { | |
292 if ( v3 < 0 ) | |
293 v3 = 0; | |
294 if ( v4 < 0 ) | |
295 v4 = 0; | |
296 if ( v3 > 639 ) | |
297 v3 = 639; | |
298 if ( v4 > 479 ) | |
299 v4 = 479; | |
300 } | |
301 v5 = &v1->pCursorBitmapRect; | |
302 v6 = v3 + v1->uCursorBitmapPitch; | |
303 v7 = v4 + v1->field_5C[0]; | |
304 v1->pCursorBitmapRect.y = v4; | |
305 v1->pCursorBitmapRect.x = v3; | |
306 v1->pCursorBitmapRect.z = v6; | |
307 v1->pCursorBitmapRect.w = v7; | |
308 if ( v3 < 0 ) | |
309 v5->x = 0; | |
310 if ( v4 < 0 ) | |
311 v1->pCursorBitmapRect.y = 0; | |
312 if ( v6 > 640 ) | |
313 v1->pCursorBitmapRect.z = 640; | |
314 if ( v7 > 480 ) | |
315 v1->pCursorBitmapRect.w = 480; | |
316 v8 = v1->pCursorBitmapRect.z; | |
317 v1->bActive = 0; | |
318 v1->uCursorBitmapWidth = v8 - v5->x; | |
791 | 319 v11 = v1->bRedraw == 0; |
0 | 320 v1->uCursorBitmapHeight = v1->pCursorBitmapRect.w - v1->pCursorBitmapRect.y; |
321 if ( !v11 ) | |
322 { | |
323 if ( pMouse->ptr_90 ) | |
324 v9 = 2 * pMouse->uCursorBitmapPitch; | |
325 else | |
326 v9 = 0; | |
327 pRenderer->_4A6DF5( | |
328 v1->pCursorBitmap_sysmem, | |
329 v9, | |
330 &v1->pCursorBitmapPos, | |
331 pRenderer->pTargetSurface, | |
332 pRenderer->uTargetSurfacePitch, | |
333 &v1->pCursorBitmapRect); | |
791 | 334 v1->bRedraw = false; |
0 | 335 } |
336 } | |
337 } | |
338 | |
339 //----- (00469E1C) -------------------------------------------------------- | |
340 void Mouse::_469E1C() | |
341 { | |
342 bActive = true; | |
343 } | |
344 | |
345 //----- (00469E24) -------------------------------------------------------- | |
346 void Mouse::_469E24() | |
347 { | |
348 if (pCursorBitmap3_sysmembits_16bit) | |
349 { | |
350 free(pCursorBitmap3_sysmembits_16bit); | |
351 pCursorBitmap3_sysmembits_16bit = 0; | |
352 } | |
353 } | |
354 | |
355 //----- (00469E3B) -------------------------------------------------------- | |
356 void Mouse::DrawCursorToTarget() | |
357 { | |
358 if (!pCursorBitmap3_sysmembits_16bit) | |
359 return; | |
360 | |
361 auto pSrc = pCursorBitmap3_sysmembits_16bit; | |
362 for (uint y = field_44; y < field_4C; ++y) | |
363 for (uint x = field_40; x < field_48; ++x) | |
364 pRenderer->pTargetSurface[y * pRenderer->uTargetSurfacePitch + x] = *pSrc++; | |
365 } | |
366 | |
367 //----- (00469EA4) -------------------------------------------------------- | |
368 void Mouse::_469EA4() | |
369 { | |
920 | 370 //Mouse *v1; // esi@1 |
371 unsigned int pTextureID; // eax@2 | |
372 Texture *pTexture; // edi@2 | |
0 | 373 unsigned int v4; // ecx@3 |
374 unsigned int v5; // eax@3 | |
375 unsigned int v6; // ebx@5 | |
376 int v7; // ecx@15 | |
377 int v8; // ecx@25 | |
378 int v9; // ebx@26 | |
379 unsigned int v10; // eax@26 | |
380 int v11; // edx@27 | |
381 unsigned __int16 *v12; // edx@29 | |
382 unsigned __int16 *v13; // ebx@29 | |
383 unsigned int a2; // [sp+Ch] [bp-1Ch]@5 | |
384 unsigned int v15; // [sp+10h] [bp-18h]@5 | |
385 unsigned int v16; // [sp+14h] [bp-14h]@25 | |
386 unsigned __int16 *v17; // [sp+18h] [bp-10h]@25 | |
387 int v18; // [sp+1Ch] [bp-Ch]@27 | |
388 int v19; // [sp+20h] [bp-8h]@15 | |
389 unsigned __int16 *v20; // [sp+20h] [bp-8h]@28 | |
920 | 390 int pTextureWidth; // [sp+24h] [bp-4h]@12 |
0 | 391 unsigned __int16 *v22; // [sp+24h] [bp-4h]@25 |
392 | |
920 | 393 //v1 = this; |
0 | 394 if ( pParty->pPickedItem.uItemID ) |
395 { | |
920 | 396 pTextureID = pIcons_LOD->LoadTexture(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
397 pTexture = (Texture *)(pTextureID != -1 ? (int)&pIcons_LOD->pTextures[pTextureID] : 0); | |
1038 | 398 |
0 | 399 v4 = pMouse->uMouseClickX; |
400 v5 = pMouse->uMouseClickY; | |
1038 | 401 |
0 | 402 v6 = v5; |
403 a2 = v4; | |
404 v15 = v5; | |
405 if ( (signed int)v4 <= 639 && (signed int)v5 <= 479 ) | |
406 { | |
407 if ( (v4 & 0x80000000u) != 0 ) | |
408 a2 = 0; | |
409 if ( (v5 & 0x80000000u) != 0 ) | |
410 { | |
411 v6 = 0; | |
412 v15 = 0; | |
413 } | |
920 | 414 if ( (signed int)(pTexture->uTextureWidth + a2) <= 640 ) |
415 pTextureWidth = pTexture->uTextureWidth; | |
0 | 416 else |
920 | 417 pTextureWidth = 640 - a2; |
418 if ( (signed int)(pTexture->uTextureHeight + v6) <= 480 ) | |
0 | 419 { |
920 | 420 v19 = pTexture->uTextureHeight; |
421 v7 = pTexture->uTextureHeight; | |
0 | 422 } |
423 else | |
424 { | |
425 v7 = 480 - v6; | |
426 v19 = 480 - v6; | |
427 } | |
920 | 428 if ( !this->pCursorBitmap3_sysmembits_16bit |
429 || a2 != this->field_40 | |
430 || v6 != this->field_44 | |
431 || a2 + pTextureWidth != this->field_48 | |
432 || v6 + v7 != this->field_4C ) | |
0 | 433 { |
920 | 434 if ( this->pCursorBitmap3_sysmembits_16bit ) |
435 free(this->pCursorBitmap3_sysmembits_16bit); | |
436 this->pCursorBitmap3_sysmembits_16bit = (unsigned __int16 *)operator new(2 * pTexture->uTextureHeight * pTexture->uTextureWidth); | |
437 this->field_40 = a2; | |
438 this->field_48 = a2 + pTextureWidth; | |
439 this->field_44 = v6; | |
440 this->field_4C = v6 + v19; | |
0 | 441 } |
920 | 442 v8 = this->field_44; |
443 v22 = this->pCursorBitmap3_sysmembits_16bit; | |
0 | 444 v17 = pRenderer->pTargetSurface; |
445 v16 = pRenderer->uTargetSurfacePitch; | |
920 | 446 if ( v8 < this->field_4C ) |
0 | 447 { |
920 | 448 v9 = this->field_48; |
0 | 449 v10 = pRenderer->uTargetSurfacePitch * v8; |
450 do | |
451 { | |
920 | 452 v11 = this->field_40; |
453 v18 = this->field_40; | |
0 | 454 if ( v11 < v9 ) |
455 { | |
456 v20 = &v17[v10 + v11]; | |
457 do | |
458 { | |
459 v12 = v20; | |
460 v13 = v22; | |
461 ++v18; | |
462 ++v20; | |
463 ++v22; | |
464 *v13 = *v12; | |
920 | 465 v9 = this->field_48; |
0 | 466 } |
467 while ( v18 < v9 ); | |
468 } | |
469 v10 += v16; | |
470 ++v8; | |
471 } | |
920 | 472 while ( v8 < this->field_4C ); |
0 | 473 v6 = v15; |
474 } | |
315 | 475 if (pParty->pPickedItem.Broken()) |
920 | 476 pRenderer->DrawTransparentRedShade(a2, v6, pTexture); |
315 | 477 else if (!pParty->pPickedItem.Identified()) |
920 | 478 pRenderer->DrawTransparentGreenShade(a2, v6, pTexture); |
0 | 479 else |
920 | 480 pRenderer->DrawTextureTransparent(a2, v6, pTexture); |
0 | 481 } |
482 } | |
483 else | |
484 { | |
485 if ( this->pCursorBitmap3_sysmembits_16bit ) | |
486 { | |
487 free(this->pCursorBitmap3_sysmembits_16bit); | |
920 | 488 this->pCursorBitmap3_sysmembits_16bit = 0; |
0 | 489 } |
490 } | |
491 } | |
492 | |
493 //----- (0046A080) -------------------------------------------------------- | |
494 void Mouse::Activate(int bActive) | |
495 { | |
496 bActive = bActive; | |
497 } | |
498 | |
499 //----- (0046A08A) -------------------------------------------------------- | |
500 void Mouse::SetMouseClick(int x, int y) | |
501 { | |
502 uMouseClickX = x; | |
503 uMouseClickY = y; | |
504 } | |
505 |