2D_graphic.cpp 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. //------------------------------------------------------------------------------------------------
  2. // version 0.0.2
  3. //------------------------------------------------------------------------------------------------
  4. #include <stdio.h>
  5. #include <assert.h>
  6. #include <math.h>
  7. #include "3d_all.h"
  8. #include "Berusky_universal.h"
  9. #include "2D_graphic.h"
  10. #include "Apak.h"
  11. #include "Berusky3d_ini.h"
  12. const int NUM_OF_BITMAPS = 700;
  13. static _2D_DATA _2dd;
  14. extern APAK_HANDLE *pBmpArchive;
  15. extern int iWinVer;
  16. extern int iActualScene;
  17. //#pragma comment(lib,"msimg32.lib")
  18. //HMODULE g_hMSIModule = NULL;
  19. //LPTRANSPARENTBLT g_pTransparentBlt = NULL;
  20. extern char CurrentWorkingDirectory[256];
  21. //------------------------------------------------------------------------------------------------
  22. // init 2d
  23. //------------------------------------------------------------------------------------------------
  24. int _2d_Init(void)
  25. {
  26. int i;
  27. kprintf(1, "Kofola - init bitmap -");
  28. _2dd.bm_count = NUM_OF_BITMAPS;
  29. //_2dd.hDC = GetDC(hwnd_hry);
  30. //kprintf(1,"GetDC() returned %d", GetLastError());
  31. //_2dd.hWnd = hwnd_hry;
  32. /*
  33. if(!_2dd.hDC)
  34. kprintf(1,"Nepodarilo se nacist DC");
  35. */
  36. _2dd.bitmap =
  37. (BITMAPSTRUCT *) malloc((_2dd.bm_count) * sizeof(BITMAPSTRUCT));
  38. if (!_2dd.bitmap) {
  39. //MessageBox(hWnd,"Unable to allocate memory for bitmaps","Error",MB_OK);
  40. kprintf(1, "Unable to allocate memory for bitmaps");
  41. return 0;
  42. }
  43. for (i = 0; i < _2dd.bm_count; i++) {
  44. //_2dd.bitmap[i].bitmapDC = NULL;
  45. _2dd.bitmap[i].bLoad = 0;
  46. }
  47. GetPrivateProfileString("game", "bitmap_dir", "c:\\", _2dd.bm_dir, 256,
  48. ini_file);
  49. working_file_translate(_2dd.bm_dir, 256);
  50. return 1;
  51. }
  52. //------------------------------------------------------------------------------------------------
  53. // 2d release
  54. //------------------------------------------------------------------------------------------------
  55. void _2d_Release(void)
  56. {
  57. /*
  58. int i;
  59. kprintf(1,"Kofola: - Release Bitmap...");
  60. for(i=0;i<_2dd.bm_count;i++)
  61. if(_2dd.bitmap[i].bLoad)
  62. {
  63. SelectObject(_2dd.bitmap[i].bitmapDC,_2dd.bitmap[i].old_hbitmap);
  64. // Every time you select an object into a device context
  65. DeleteObject(_2dd.bitmap[i].hbitmap);
  66. // Delete the HBITMAP we created -- Notice we didn't create "old_hbitmap"
  67. DeleteDC(_2dd.bitmap[i].bitmapDC);
  68. //kprintf(1, " GetLastError() returned %d", GetLastError());
  69. _2dd.bitmap[i].bLoad = 0;
  70. _2dd.bitmap[i].bitmapDC = NULL;
  71. }
  72. if(_2dd.bitmap)
  73. {
  74. free ((void *) _2dd.bitmap);
  75. _2dd.bitmap = NULL;
  76. }
  77. if(_2dd.hDC)
  78. {
  79. ReleaseDC(_2dd.hWnd, _2dd.hDC);
  80. //kprintf(1, " ReleaseDC() returned %d", GetLastError());
  81. _2dd.hDC = NULL;
  82. }
  83. */
  84. }
  85. //------------------------------------------------------------------------------------------------
  86. // finds first free index
  87. //------------------------------------------------------------------------------------------------
  88. int _2d_Find_Free_Surface(void)
  89. {
  90. int i;
  91. for (i = 0; i < _2dd.bm_count; i++)
  92. if (!_2dd.bitmap[i].bLoad)
  93. return i;
  94. return -1;
  95. }
  96. //------------------------------------------------------------------------------------------------
  97. // load bitmap
  98. //------------------------------------------------------------------------------------------------
  99. int _2d_Load_Bitmap(char *p_File_Name)
  100. {
  101. //HBITMAP hbitmap;
  102. int pointer;
  103. pointer = _2d_Find_Free_Surface();
  104. if (pointer == -1)
  105. return -1;
  106. /* TODO
  107. _2dd.bitmap[pointer].hbitmap = (HBITMAP)LoadImage(hinst,p_File_Name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  108. _2dd.bitmap[pointer].bitmapDC = CreateCompatibleDC(_2dd.hDC);
  109. if(!_2dd.bitmap[pointer].bitmapDC)
  110. {
  111. _2dd.bitmap[pointer].bLoad = 0;
  112. kprintf(1,"Can't load %s",p_File_Name);
  113. return -1;
  114. }
  115. if(!(_2dd.bitmap[pointer].old_hbitmap =
  116. SelectObject(_2dd.bitmap[pointer].bitmapDC, _2dd.bitmap[pointer].hbitmap)))
  117. {
  118. DeleteDC(_2dd.bitmap[pointer].bitmapDC);
  119. _2dd.bitmap[pointer].bitmapDC = NULL;
  120. _2dd.bitmap[pointer].bLoad = 0;
  121. kprintf(1,"Can't load %s",p_File_Name);
  122. return -1;
  123. }
  124. */
  125. /*
  126. GetObject(hbitmap, sizeof(BITMAP), &_2dd.bitmap[pointer].bitmap);
  127. DeleteObject(hbitmap);
  128. */
  129. _2dd.bitmap[pointer].bLoad = 1;
  130. return pointer;
  131. }
  132. /*int _2d_APAK_Load_Bitmap(char *p_File_Name, char bSeek)
  133. {
  134. long size;
  135. APAK_FILE_HANDLE *fHandle;
  136. BITMAPINFO bmpInfo;
  137. HBITMAP hDIB;
  138. char *pBmp, *pDIB;
  139. BITMAPINFOHEADER bmpInfoHeader;
  140. BITMAPFILEHEADER bmpFileHeader;
  141. FILE *file;
  142. int pointer;
  143. pointer = _2d_Find_Free_Surface();
  144. if(pointer == -1)
  145. return -1;
  146. file = aopen(pBmpArchive, p_File_Name, "rb", bSeek);
  147. if(pBmpArchive->bError)
  148. kprintf(1,pBmpArchive->cError);
  149. if(!file)
  150. return -1;
  151. fHandle = (APAK_FILE_HANDLE *)file;
  152. aread(1, &bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, file, 0);
  153. aread(1, &bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, file, 0);
  154. size = bmpFileHeader.bfSize - bmpFileHeader.bfOffBits;
  155. pBmp = (char *) malloc(size);
  156. aread(1, pBmp, size, 1, file, 0);
  157. aclose(1, file);
  158. _2dd.bitmap[pointer].bitmapDC = CreateCompatibleDC(_2dd.hDC);
  159. kprintf(1, "CreateCompatibleDC returned %d", GetLastError());
  160. if(!_2dd.bitmap[pointer].bitmapDC)
  161. {
  162. _2dd.bitmap[pointer].bLoad = 0;
  163. kprintf(1,"Can't load %s",p_File_Name);
  164. return -1;
  165. }
  166. bmpInfoHeader.biBitCount = 24;
  167. bmpInfo.bmiHeader = bmpInfoHeader;
  168. hDIB = CreateDIBSection(_2dd.bitmap[pointer].bitmapDC,
  169. &bmpInfo,
  170. DIB_RGB_COLORS,
  171. (void **)&pDIB,
  172. NULL, 0);
  173. SetDIBits(_2dd.bitmap[pointer].bitmapDC, hDIB,
  174. 0, bmpInfoHeader.biHeight,
  175. (CONST VOID *)pBmp,
  176. &bmpInfo,
  177. DIB_RGB_COLORS);
  178. if(!SelectObject(_2dd.bitmap[pointer].bitmapDC, hDIB))
  179. kprintf(1,"!SelectObject(hDIB) v _2d_APAK_Load_Bitmap");
  180. free((void *) pBmp);
  181. if(!DeleteObject(hDIB))
  182. kprintf(1,"!DeleteObject(hDIB) v _2d_APAK_Load_Bitmap");
  183. _2dd.bitmap[pointer].bitmap.bmType = 0;
  184. _2dd.bitmap[pointer].bitmap.bmWidth = bmpInfoHeader.biWidth;
  185. _2dd.bitmap[pointer].bitmap.bmHeight = bmpInfoHeader.biHeight;
  186. _2dd.bitmap[pointer].bLoad = 1;
  187. return pointer;
  188. }
  189. */
  190. /*int _2d_APAK_Load_Bitmap(char *p_File_Name, char bSeek)
  191. {
  192. long size;
  193. APAK_FILE_HANDLE *fHandle;
  194. BITMAPINFO bmpInfo;
  195. HBITMAP hDIB;
  196. char *pBmp, *pDIB;
  197. BITMAPINFOHEADER bmpInfoHeader;
  198. BITMAPFILEHEADER bmpFileHeader;
  199. FILE *file;
  200. int pointer;
  201. BITMAP bmp;
  202. pointer = _2d_Find_Free_Surface();
  203. if(pointer == -1)
  204. return -1;
  205. file = aopen(pBmpArchive, p_File_Name, "rb", bSeek);
  206. if(pBmpArchive->bError)
  207. kprintf(1,pBmpArchive->cError);
  208. if(!file)
  209. return -1;
  210. fHandle = (APAK_FILE_HANDLE *)file;
  211. aread(1, &bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, file, 0);
  212. aread(1, &bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, file, 0);
  213. size = bmpFileHeader.bfSize - bmpFileHeader.bfOffBits;
  214. pBmp = (char *) malloc(size);
  215. aread(1, pBmp, size, 1, file, 0);
  216. aclose(1, file);
  217. _2dd.bitmap[pointer].bitmapDC = CreateCompatibleDC(_2dd.hDC);
  218. kprintf(1, "CreateCompatibleDC returned %d", GetLastError());
  219. if(!_2dd.bitmap[pointer].bitmapDC)
  220. {
  221. _2dd.bitmap[pointer].bLoad = 0;
  222. kprintf(1,"Can't load %s",p_File_Name);
  223. return -1;
  224. }
  225. bmpInfo.bmiHeader = bmpInfoHeader;
  226. hDIB = CreateCompatibleBitmap(_2dd.hDC,
  227. bmpInfoHeader.biWidth,
  228. bmpInfoHeader.biHeight);
  229. if(!hDIB)
  230. {
  231. kprintf(1, "CreateCompatibleBitmap returned %d", GetLastError());
  232. DeleteDC(_2dd.bitmap[pointer].bitmapDC);
  233. _2dd.bitmap[pointer].bLoad = 0;
  234. kprintf(1,"Can't load %s",p_File_Name);
  235. return -1;
  236. }
  237. if(!SelectObject(_2dd.bitmap[pointer].bitmapDC, hDIB))
  238. kprintf(1,"!SelectObject(hDIB) v _2d_APAK_Load_Bitmap");
  239. StretchDIBits(_2dd.bitmap[pointer].bitmapDC,
  240. 0,
  241. 0,
  242. bmpInfoHeader.biWidth,
  243. bmpInfoHeader.biHeight,
  244. 0,
  245. 0,
  246. bmpInfoHeader.biWidth,
  247. bmpInfoHeader.biHeight,
  248. (CONST VOID *)pBmp,
  249. &bmpInfo,
  250. DIB_RGB_COLORS,
  251. SRCCOPY);
  252. free((void *) pBmp);
  253. if(!DeleteObject(hDIB))
  254. kprintf(1,"!DeleteObject(hDIB) v _2d_APAK_Load_Bitmap");
  255. _2dd.bitmap[pointer].bitmap.bmType = 0;
  256. _2dd.bitmap[pointer].bitmap.bmWidth = bmpInfoHeader.biWidth;
  257. _2dd.bitmap[pointer].bitmap.bmHeight = bmpInfoHeader.biHeight;
  258. _2dd.bitmap[pointer].bLoad = 1;
  259. return pointer;
  260. }
  261. */
  262. int _2d_APAK_Load_Bitmap(char *p_File_Name, APAK_HANDLE * pHandle)
  263. {
  264. /*
  265. long size;
  266. APAK_FILE_HANDLE *fHandle;
  267. BITMAPINFO bmpInfo;
  268. //HBITMAP hDIB;
  269. char *pBmp;
  270. BITMAPINFOHEADER bmpInfoHeader;
  271. BITMAPFILEHEADER bmpFileHeader;
  272. FILE *file;
  273. int pointer;
  274. pointer = _2d_Find_Free_Surface();
  275. if(pointer == -1)
  276. return -1;
  277. file = aopen(pHandle, p_File_Name, "rb");
  278. if(pBmpArchive->bError)
  279. kprintf(1,"%s: %s", p_File_Name, pBmpArchive->cError);
  280. if(!file)
  281. return -1;
  282. fHandle = (APAK_FILE_HANDLE *)file;
  283. aread(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, file);
  284. aread(&bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, file);
  285. size = bmpFileHeader.bfSize - bmpFileHeader.bfOffBits;
  286. pBmp = (char *) malloc(size);
  287. aread(pBmp, size, 1, file);
  288. aclose(file);
  289. _2dd.bitmap[pointer].bitmapDC = CreateCompatibleDC(_2dd.hDC);
  290. //kprintf(1, "CreateCompatibleDC returned %d", GetLastError());
  291. if(!_2dd.bitmap[pointer].bitmapDC)
  292. {
  293. _2dd.bitmap[pointer].bLoad = 0;
  294. kprintf(1,"Can't load %s",p_File_Name);
  295. return -1;
  296. }
  297. bmpInfo.bmiHeader = bmpInfoHeader;
  298. _2dd.bitmap[pointer].hbitmap = CreateCompatibleBitmap(_2dd.hDC,
  299. bmpInfoHeader.biWidth,
  300. bmpInfoHeader.biHeight);
  301. if(!_2dd.bitmap[pointer].hbitmap)
  302. {
  303. kprintf(1, "CreateCompatibleBitmap returned %d", GetLastError());
  304. DeleteDC(_2dd.bitmap[pointer].bitmapDC);
  305. _2dd.bitmap[pointer].bLoad = 0;
  306. kprintf(1,"Can't load %s",p_File_Name);
  307. return -1;
  308. }
  309. if(!(_2dd.bitmap[pointer].old_hbitmap =
  310. SelectObject(_2dd.bitmap[pointer].bitmapDC, _2dd.bitmap[pointer].hbitmap)))
  311. {
  312. DeleteDC(_2dd.bitmap[pointer].bitmapDC);
  313. DeleteObject(_2dd.bitmap[pointer].hbitmap);
  314. _2dd.bitmap[pointer].bitmapDC = NULL;
  315. _2dd.bitmap[pointer].bLoad = 0;
  316. kprintf(1,"Can't load %s",p_File_Name);
  317. return -1;
  318. }
  319. SetDIBits(_2dd.bitmap[pointer].bitmapDC,
  320. _2dd.bitmap[pointer].hbitmap,
  321. 0, bmpInfoHeader.biHeight,
  322. (CONST VOID *)pBmp,
  323. &bmpInfo,
  324. DIB_RGB_COLORS);
  325. free((void *) pBmp);
  326. */
  327. /* if(!DeleteObject(hDIB))
  328. kprintf(1,"!DeleteObject(hDIB) v _2d_APAK_Load_Bitmap");*/
  329. /*
  330. _2dd.bitmap[pointer].bitmap.bmType = 0;
  331. _2dd.bitmap[pointer].bitmap.bmWidth = bmpInfoHeader.biWidth;
  332. _2dd.bitmap[pointer].bitmap.bmHeight = bmpInfoHeader.biHeight;
  333. _2dd.bitmap[pointer].bLoad = 1;
  334. return pointer;
  335. */
  336. }
  337. /*
  338. void lsi_Make_Screenshot(HDC hdc, char *pFile)
  339. {
  340. HDC hdcMem;
  341. BITMAPINFO *pbmiRGB = (BITMAPINFO *) NULL;
  342. HBITMAP hbmRGB = (HBITMAP) NULL;
  343. PBYTE pjBitsRGB;
  344. BITMAPFILEHEADER bmpHeader;
  345. FILE *bmpFile = NULL;
  346. hdcMem = CreateCompatibleDC(hdc);
  347. pbmiRGB = (BITMAPINFO *)LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, sizeof(BITMAPINFO) );
  348. if (!pbmiRGB)
  349. MessageBox(NULL,"!pbmiRGB","!!!", MB_OK);
  350. pbmiRGB->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  351. pbmiRGB->bmiHeader.biWidth = Xresolution;
  352. pbmiRGB->bmiHeader.biHeight = Yresolution;
  353. pbmiRGB->bmiHeader.biPlanes = 1;
  354. pbmiRGB->bmiHeader.biBitCount = 24;
  355. pbmiRGB->bmiHeader.biCompression = BI_RGB;
  356. pbmiRGB->bmiHeader.biSizeImage = pbmiRGB->bmiHeader.biWidth
  357. * abs(pbmiRGB->bmiHeader.biHeight) * 3;
  358. hbmRGB = CreateDIBSection(hdcMem, pbmiRGB, DIB_RGB_COLORS,
  359. (PVOID *) &pjBitsRGB, NULL, 0);
  360. if (!hbmRGB)
  361. MessageBox(NULL,"!hbmRGB","!!!", MB_OK);
  362. if (!SelectObject(hdcMem, hbmRGB))
  363. MessageBox(NULL,"!SelectObject(hdcMem, hbmRGB)","!!!", MB_OK);
  364. if (!BitBlt(hdcMem, 0,0, Xresolution, Yresolution, hdc, 0,0,SRCCOPY))
  365. MessageBox(NULL,"!BitBlt","!!!", MB_OK);
  366. pjBitsRGB = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbmiRGB->bmiHeader.biSizeImage);
  367. if (!pjBitsRGB)
  368. MessageBox(NULL,"!pjBitsRGB","!!!", MB_OK);
  369. if (!GetDIBits(hdcMem, hbmRGB, 0, (UINT)pbmiRGB->bmiHeader.biHeight, pjBitsRGB,
  370. (LPBITMAPINFO)pbmiRGB, DIB_RGB_COLORS))
  371. MessageBox(NULL,"!GetDIBits","!!!", MB_OK);
  372. bmpHeader.bfType = 'MB';
  373. bmpHeader.bfSize = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + pbmiRGB->bmiHeader.biSizeImage;
  374. bmpHeader.bfOffBits = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER);
  375. bmpHeader.bfReserved1 = 0;
  376. bmpHeader.bfReserved2 = 0;
  377. bmpFile = fopen(pFile,"wb");
  378. if (!bmpFile)
  379. MessageBox(NULL,"!bmpFile","!!!", MB_OK);
  380. fwrite(&bmpHeader,sizeof(BITMAPFILEHEADER),1,bmpFile);
  381. fwrite(&pbmiRGB->bmiHeader,sizeof(BITMAPINFOHEADER),1,bmpFile);
  382. fwrite(pjBitsRGB,sizeof(BYTE),pbmiRGB->bmiHeader.biSizeImage,bmpFile);
  383. fclose(bmpFile);
  384. DeleteDC(hdcMem);
  385. DeleteObject(hbmRGB);
  386. LocalFree(pbmiRGB);
  387. GlobalFree((HGLOBAL)pjBitsRGB);
  388. }
  389. */
  390. //------------------------------------------------------------------------------------------------
  391. // release bitmap
  392. //------------------------------------------------------------------------------------------------
  393. int _2d_Release_Bitmap(int pointer)
  394. {
  395. /*
  396. if(pointer < 0)
  397. return 1;
  398. if(pointer > (_2dd.bm_count - 1))
  399. return 0;
  400. if(_2dd.bitmap[pointer].bLoad)
  401. {
  402. SelectObject(_2dd.bitmap[pointer].bitmapDC,_2dd.bitmap[pointer].old_hbitmap);
  403. // Every time you select an object into a device context
  404. DeleteObject(_2dd.bitmap[pointer].hbitmap);
  405. // Delete the HBITMAP we created -- Notice we didn't create "old_hbitmap"
  406. DeleteDC(_2dd.bitmap[pointer].bitmapDC);
  407. _2dd.bitmap[pointer].bLoad = 0;
  408. _2dd.bitmap[pointer].bitmapDC = NULL;
  409. }
  410. */
  411. return 1;
  412. }
  413. //------------------------------------------------------------------------------------------------
  414. // load list of bitmaps
  415. //------------------------------------------------------------------------------------------------
  416. int _2d_Load_List(char *p_File_Name)
  417. {
  418. char text[256];
  419. FILE *file = 0;
  420. chdir((_2dd.bm_dir));
  421. file = fopen(p_File_Name, "r");
  422. kprintf(1, "Kofola: - Load bitmap pro herni menu");
  423. if (!file) {
  424. //MessageBox(_3dd.hWnd,"File not found","Error",MB_OK);
  425. kprintf(1, "File not found : %s", p_File_Name);
  426. return 0;
  427. }
  428. else {
  429. while (!feof(file)) {
  430. fgets(text, 256, file);
  431. if (!feof(file)) {
  432. text[strlen(text) - 1] = '\0';
  433. _2d_Load_Bitmap(text);
  434. //kprintf(1,"Bitmap %s loaded.",text);
  435. }
  436. }
  437. fclose(file);
  438. return 1;
  439. }
  440. }
  441. int _2d_APAK_Load_List(char *p_File_Name)
  442. {
  443. char text[256];
  444. FILE *file = 0;
  445. DWORD Eplased = 0;
  446. DWORD Start, Stop;
  447. achdir(pBmpArchive, _2dd.bm_dir);
  448. file = aopen(pBmpArchive, p_File_Name, "rb");
  449. kprintf(1, "Kofola: - Load bitmap pro herni menu");
  450. if (!file) {
  451. //MessageBox(_3dd.hWnd,"File not found","Error",MB_OK);
  452. kprintf(1, "File not found : %s", p_File_Name);
  453. return 0;
  454. }
  455. else {
  456. Start = timeGetTime();
  457. while (!aeof(file)) {
  458. agets(text, 256, file);
  459. if (!aeof(file)) {
  460. text[strlen(text) - 1] = '\0';
  461. _2d_APAK_Load_Bitmap(text, pBmpArchive);
  462. //kprintf(1,"Bitmap %s loaded.",text);
  463. }
  464. }
  465. aclose(file);
  466. Stop = timeGetTime();
  467. kprintf(1, "--------------Total load time %.1f s -----------------",
  468. Eplased / 1000.0f);
  469. return 1;
  470. }
  471. /* DWORD Eplased = 0;
  472. DWORD Start, Stop;
  473. int c = 0, i;
  474. TEXT_STRUCT *pText;
  475. char text[256];
  476. FILE *file = 0;
  477. _2d_Init_Load_Progress_Bar(353);
  478. achdir(pBmpArchive, _2dd.bm_dir);
  479. if(pBmpArchive->bError)
  480. kprintf(1, "Change dir: %s", pBmpArchive->cError);
  481. file = aopen(pBmpArchive, p_File_Name,"rb");
  482. kprintf(1,"Kofola: - Load bitmap pro herni menu");
  483. if(!file)
  484. {
  485. //MessageBox(_3dd.hWnd,"File not found","Error",MB_OK);
  486. kprintf(1,"File not found : %s",p_File_Name);
  487. return 0;
  488. }
  489. do
  490. {
  491. agets(text, 256, file);
  492. c++;
  493. }
  494. while(!aeof(file));
  495. _2d_Add_Progress(-1);
  496. _2d_Draw_Progress(1024,768);
  497. aseek(file, 0, SEEK_SET);
  498. _2d_Add_Progress(-1);
  499. _2d_Draw_Progress(1024,768);
  500. pText = (TEXT_STRUCT *) malloc(c * sizeof(TEXT_STRUCT));
  501. if(!pText)
  502. {
  503. aclose(file);
  504. return 0;
  505. }
  506. c = 0;
  507. do
  508. {
  509. agets(text, 256, file);
  510. text[strlen(text)-2] = '\0';
  511. strcpy(pText[c].cText, text);
  512. c++;
  513. }
  514. while(!aeof(file));
  515. aclose(file);
  516. _2d_Add_Progress(-1);
  517. _2d_Draw_Progress(1024,768);
  518. for(i=0;i<c;i++)
  519. {
  520. Start = timeGetTime();
  521. if(!i)
  522. {
  523. if(_2d_APAK_Load_Bitmap(pText[i].cText, 1) == -1)
  524. {
  525. kprintf(1,"Bitmap %s NOT loaded!",pText[i].cText);
  526. }
  527. }
  528. else
  529. {
  530. if(_2d_APAK_Load_Bitmap(pText[i].cText, 0) == -1)
  531. {
  532. kprintf(1,"Bitmap %s NOT loaded!",pText[i].cText);
  533. }
  534. }
  535. Stop = timeGetTime();
  536. //kprintf(1, "%s loaded in %d ms", pText[i].cText, Stop - Start);
  537. Eplased += (Stop - Start);
  538. _2d_Add_Progress(-1);
  539. _2d_Draw_Progress(1024,768);
  540. }
  541. free((void *)pText);
  542. kprintf(1, "--------------Total load time %.1f s -----------------", Eplased / 1000.0f);
  543. return 1;*/
  544. }
  545. void _2d_Draw_Load_Screen(void)
  546. {
  547. int i;
  548. //schovej_konzoli();
  549. _2d_Init();
  550. _2d_Blackness();
  551. chdir((_2dd.bm_dir));
  552. achdir(pBmpArchive, _2dd.bm_dir);
  553. if (iActualScene < 13) {
  554. char text[256];
  555. sprintf(text, "scene%d.bmp", iActualScene);
  556. i = _2d_APAK_Load_Bitmap(text, pBmpArchive);
  557. }
  558. else
  559. i = _2d_APAK_Load_Bitmap("LoadScreen.bmp", pBmpArchive);
  560. /*
  561. SetStretchBltMode(_2dd.hDC, HALFTONE);
  562. //SetBrushOrgEx(_2dd.hDC, 0, 0, NULL);
  563. StretchBlt(_2dd.hDC, 0, 0, hwconf.xres, hwconf.yres, _2dd.bitmap[i].bitmapDC,0,0,1024, 768, SRCCOPY);
  564. */
  565. _2d_Release_Bitmap(i);
  566. //_2dd.ProgressBmp = _2d_Load_Bitmap("LoadScreen3.bmp");
  567. //_2d_Release();
  568. }
  569. void _2d_Init_Load_Progress_Bar(int iNumOfItems)
  570. {
  571. _2dd.ProgressStatus = 0;
  572. _2dd.ProgressPlus = 100.0f / (float) iNumOfItems;
  573. }
  574. void _2d_Add_Progress(float fPercent)
  575. {
  576. if (fPercent >= 0)
  577. _2dd.ProgressStatus += fPercent;
  578. else
  579. _2dd.ProgressStatus += _2dd.ProgressPlus;
  580. }
  581. void _2d_Draw_Progress(int x, int y)
  582. {
  583. /*
  584. HPEN LastPen;
  585. HPEN MePen;
  586. int i;
  587. int Width;
  588. int RWidth;
  589. Width = ftoi((1024 * _2dd.ProgressStatus) / 100.0f);
  590. if(x < 0 || y < 0)
  591. RWidth = ftoi((hwconf.xres * _2dd.ProgressStatus) / 100.0f);
  592. else
  593. RWidth = ftoi((x * _2dd.ProgressStatus) / 100.0f);
  594. //SetStretchBltMode(_2dd.hDC, COLORONCOLOR);
  595. //StretchBlt(_2dd.hDC, 0, 0, RWidth, hwconf.yres,
  596. //_2dd.bitmap[_2dd.ProgressBmp].bitmapDC,0,0,Width, 768, SRCCOPY);
  597. MePen = CreatePen(PS_SOLID,1,RGB(255,0,0));
  598. LastPen = (HPEN)SelectObject(_2dd.hDC,MePen);
  599. if(x < 0 || y < 0)
  600. for(i=hwconf.yres - 5;i<hwconf.yres;i++)
  601. {
  602. MoveToEx(_2dd.hDC,0, i, NULL);
  603. LineTo(_2dd.hDC,RWidth, i);
  604. }
  605. else
  606. for(i=y - 5;i<y;i++)
  607. {
  608. MoveToEx(_2dd.hDC,0, i, NULL);
  609. LineTo(_2dd.hDC,RWidth, i);
  610. }
  611. SelectObject(_2dd.hDC,LastPen);
  612. DeleteObject(MePen);
  613. */
  614. }
  615. void _2d_Release_Progress(void)
  616. {
  617. _2d_Release();
  618. }
  619. void _2d_Blackness(void)
  620. {
  621. //BitBlt(_2dd.hDC, 0, 0, hwconf.xres, hwconf.yres, NULL, 0, 0, BLACKNESS);
  622. }
  623. void _2d_Clear_RectLine(RECT_LINE * p_rl)
  624. {
  625. memset(p_rl, 0, sizeof(RECT_LINE));
  626. p_rl->rlast = 0;
  627. }
  628. int _2d_Is_InRectLine(RECT * rline, RECT * p_r, int size)
  629. {
  630. int i;
  631. for (i = 0; i < size; i++)
  632. if (rline[i].bottom == p_r->bottom &&
  633. rline[i].left == p_r->left &&
  634. rline[i].right == p_r->right && rline[i].top == p_r->top)
  635. return 1;
  636. return 0;
  637. }
  638. void _2d_Add_RectItem_IfNPresent(RECT_LINE * p_rl, RECT rect, int iLayer)
  639. {
  640. int i;
  641. for (i = 0; i < p_rl->rlast; i++)
  642. if (p_rl->rect[i].rect.bottom == rect.bottom &&
  643. p_rl->rect[i].rect.left == rect.left &&
  644. p_rl->rect[i].rect.right == rect.right &&
  645. p_rl->rect[i].rect.top == rect.top)
  646. return;
  647. if (p_rl->rlast < DRAW_RECT_NUM) {
  648. p_rl->rect[p_rl->rlast].rect = rect;
  649. p_rl->rect[p_rl->rlast].iLayer = iLayer;
  650. p_rl->rect[p_rl->rlast].bUsed = 1;
  651. p_rl->rlast++;
  652. }
  653. }
  654. void _2d_Add_RectItem(RECT_LINE * p_rl, RECT rect, int iLayer)
  655. {
  656. if (p_rl->rlast < DRAW_RECT_NUM) {
  657. p_rl->rect[p_rl->rlast].rect = rect;
  658. p_rl->rect[p_rl->rlast].iLayer = iLayer;
  659. p_rl->rect[p_rl->rlast].bUsed = 1;
  660. p_rl->rlast++;
  661. }
  662. }
  663. /*
  664. BOOL TransparentBltU98(
  665. HDC dcDest, // handle to Dest DC
  666. int nXOriginDest, // x-coord of destination upper-left corner
  667. int nYOriginDest, // y-coord of destination upper-left corner
  668. int nWidthDest, // width of destination rectangle
  669. int nHeightDest, // height of destination rectangle
  670. HDC dcSrc, // handle to source DC
  671. int nXOriginSrc, // x-coord of source upper-left corner
  672. int nYOriginSrc, // y-coord of source upper-left corner
  673. int nWidthSrc, // width of source rectangle
  674. int nHeightSrc, // height of source rectangle
  675. UINT crTransparent // color to make transparent
  676. )
  677. {
  678. HDC dc;
  679. HBITMAP bitmap;
  680. HBITMAP oldBitmap;
  681. HDC maskDC;
  682. HBITMAP maskBitmap;
  683. HBITMAP oldMask;
  684. HDC newMaskDC;
  685. HBITMAP newMask;
  686. HBITMAP oldNewMask;
  687. HDC newImageDC;
  688. HBITMAP newImage;
  689. HBITMAP oldNewImage;
  690. HDC tmpImageDC;
  691. HBITMAP tmpImage;
  692. HBITMAP oldTmpImage;
  693. if (nWidthDest < 1) return FALSE;
  694. if (nWidthSrc < 1) return FALSE;
  695. if (nHeightDest < 1) return FALSE;
  696. if (nHeightSrc < 1) return FALSE;
  697. tmpImageDC = CreateCompatibleDC(_2dd.hDC);
  698. tmpImage = CreateBitmap(nWidthSrc, nHeightSrc, 1, GetDeviceCaps(tmpImageDC, BITSPIXEL), NULL);
  699. if (tmpImage == NULL)
  700. return FALSE;
  701. oldTmpImage = (HBITMAP)SelectObject(tmpImageDC, tmpImage);
  702. BitBlt(tmpImageDC, 0, 0, nWidthDest, nHeightDest, dcDest, nXOriginDest, nYOriginDest, SRCCOPY);
  703. dc = CreateCompatibleDC(_2dd.hDC);
  704. bitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, GetDeviceCaps(dc, BITSPIXEL), NULL);
  705. if (bitmap == NULL)
  706. return FALSE;
  707. oldBitmap = (HBITMAP)SelectObject(dc, bitmap);
  708. if (!BitBlt(dc, 0, 0, nWidthSrc, nHeightSrc, dcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY))
  709. return FALSE;
  710. maskDC = CreateCompatibleDC(_2dd.hDC);
  711. maskBitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, 1, NULL);
  712. if (maskBitmap == NULL)
  713. return FALSE;
  714. oldMask = (HBITMAP)SelectObject(maskDC, maskBitmap);
  715. SetBkColor(maskDC, RGB(0,0,0));
  716. SetTextColor(maskDC, RGB(255,255,255));
  717. if (!BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,NULL,0,0,BLACKNESS))
  718. return FALSE;
  719. SetBkColor(dc, crTransparent);
  720. BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,dc,0,0,SRCINVERT);
  721. SetBkColor(dc, RGB(0,0,0));
  722. SetTextColor(dc, RGB(255,255,255));
  723. BitBlt(dc, 0,0,nWidthSrc,nHeightSrc,maskDC,0,0,SRCAND);
  724. newMaskDC = CreateCompatibleDC(_2dd.hDC);
  725. newMask = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);
  726. if (newMask == NULL)
  727. {
  728. SelectObject(dc, oldBitmap);
  729. DeleteDC(dc);
  730. SelectObject(maskDC, oldMask);
  731. DeleteDC(maskDC);
  732. DeleteDC(newMaskDC);
  733. return FALSE;
  734. }
  735. SetStretchBltMode(newMaskDC, COLORONCOLOR);
  736. oldNewMask = (HBITMAP) SelectObject(newMaskDC, newMask);
  737. StretchBlt(newMaskDC, 0, 0, nWidthDest, nHeightDest, maskDC, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);
  738. SelectObject(maskDC, oldMask);
  739. DeleteDC(maskDC);
  740. newImageDC = CreateCompatibleDC(_2dd.hDC);
  741. newImage = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);
  742. if (newImage == NULL)
  743. {
  744. SelectObject(dc, oldBitmap);
  745. DeleteDC(dc);
  746. DeleteDC(newMaskDC);
  747. return FALSE;
  748. }
  749. oldNewImage = (HBITMAP)SelectObject(newImageDC, newImage);
  750. StretchBlt(newImageDC, 0, 0, nWidthDest, nHeightDest, dc, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);
  751. SelectObject(dc, oldBitmap);
  752. DeleteDC(dc);
  753. BitBlt( tmpImageDC, 0, 0, nWidthDest, nHeightDest, newMaskDC, 0, 0, SRCAND);
  754. BitBlt( tmpImageDC, 0, 0, nWidthDest, nHeightDest, newImageDC, 0, 0, SRCPAINT);
  755. BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, tmpImageDC, 0, 0, SRCCOPY);
  756. //BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newMaskDC, 0, 0, SRCAND);
  757. //BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newImageDC, 0, 0, SRCPAINT);
  758. SelectObject(tmpImageDC, oldTmpImage);
  759. DeleteDC(tmpImageDC);
  760. SelectObject(newImageDC, oldNewImage);
  761. DeleteDC(newImageDC);
  762. SelectObject(newMaskDC, oldNewMask);
  763. DeleteDC(newMaskDC);
  764. DeleteObject(tmpImage);
  765. DeleteObject(maskBitmap);
  766. DeleteObject(bitmap);
  767. DeleteObject(newMask);
  768. DeleteObject(newImage);
  769. return TRUE;
  770. }
  771. */
  772. /*
  773. void _2d_Fill_Rect(RECT rect, COLORREF color)
  774. {
  775. HBRUSH hbr = CreateSolidBrush(color);
  776. FillRect(hdc, &rect, hbr);
  777. DeleteObject(hbr);
  778. }
  779. BOOL BitBltU(
  780. HDC hdcDest, // handle to destination DC
  781. int nXDest, // x-coord of destination upper-left corner
  782. int nYDest, // y-coord of destination upper-left corner
  783. int nWidth, // width of destination rectangle
  784. int nHeight, // height of destination rectangle
  785. HDC hdcSrc, // handle to source DC
  786. int nXSrc, // x-coordinate of source upper-left corner
  787. int nYSrc, // y-coordinate of source upper-left corner
  788. DWORD dwRop // raster operation code
  789. )
  790. {
  791. RECT r;
  792. r.left = nXDest - 1;
  793. r.top = nYDest - 1;
  794. r.right = nXDest + nWidth + 1;
  795. r.bottom = nYDest + nHeight + 1;
  796. _2d_Fill_Rect(hdcDest, r, RGB(255, 0, 255));
  797. return TRUE;
  798. }
  799. */
  800. int LoadTransparentBlt(void)
  801. {
  802. /* char lib[1024];
  803. // I try to locate the function
  804. // Do this early in your program
  805. strcpy(lib, CurrentWorkingDirectory);
  806. strcat(lib, "\\");
  807. strcat(lib, "Msimg32.dll");
  808. g_hMSIModule = LoadLibrary(lib);
  809. if (g_hMSIModule)
  810. {
  811. g_pTransparentBlt = (LPTRANSPARENTBLT) GetProcAddress(g_hMSIModule, "TransparentBlt");
  812. }
  813. else
  814. {
  815. kprintf(1, "Unable to load Msimg32.dll");
  816. return 0;
  817. }
  818. // if the pointer is valid, you may use it
  819. // see Documentation of this function - not hard to use
  820. if(g_pTransparentBlt)
  821. {
  822. kprintf(1, "TransparentBlt succesfully wraped");
  823. return 1;
  824. }
  825. else
  826. {
  827. kprintf(1, "Unable to wrap TransparentBlt");
  828. return 0;
  829. }*/
  830. return 1;
  831. }
  832. void UnloadTransparentBlt(void)
  833. {
  834. /* if(g_hMSIModule)
  835. FreeLibrary(g_hMSIModule);*/
  836. }