draw.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include <stdio.h>
  10. #include "resource.h"
  11. #include "draw.h"
  12. #include "WADrawDC.h"
  13. //#define DEBUG_DRAW
  14. // time to fix reloading of main.bmp and just save a copy to restore with
  15. COLORREF mfont_bgcolor=RGB(0,0,0), mfont_fgcolor=RGB(0,255,0);
  16. int pe_fontheight=8;
  17. int mfont_height=6;
  18. HFONT font=0, mfont=0, shadefont=0, osdFontText=0;
  19. HBRUSH selbrush, normbrush, mfont_bgbrush;
  20. volatile int draw_initted;
  21. HDC mainDC, bmDC, specDC,mainDC2;
  22. HBITMAP mainBM_save, mainBM,shufflerepeatBM,
  23. fontBM, specBM, oldMainBM, oldSpecBM;
  24. extern int sa_kill;
  25. static int palmode;
  26. HPALETTE draw_hpal=0;
  27. #ifdef DEBUG_DRAW
  28. static DWORD main_thread_id;
  29. #endif
  30. CRITICAL_SECTION g_mainwndcs, g_srcdccs;
  31. void draw_firstinit()
  32. {
  33. InitializeCriticalSection(&g_srcdccs);
  34. InitializeCriticalSection(&g_mainwndcs);
  35. #ifdef DEBUG_DRAW
  36. main_thread_id=GetCurrentThreadId();
  37. #endif
  38. }
  39. void draw_finalquit()
  40. {
  41. DeleteCriticalSection(&g_mainwndcs);
  42. DeleteCriticalSection(&g_srcdccs);
  43. }
  44. HDC draw_GetWindowDC(HWND hwnd)
  45. {
  46. #ifdef DRAW_DEBUG
  47. if (!hwnd)
  48. {
  49. MessageBox(NULL,"GWDC: hwnd=0","DRAW_DEBUG",0);
  50. }
  51. #endif
  52. HDC hdc;
  53. EnterCriticalSection(&g_mainwndcs);
  54. hdc = GetWindowDC(hwnd);
  55. #ifdef DRAW_DEBUG
  56. if (!hdc)
  57. {
  58. MessageBox(NULL,"GWDC: hdc=0","DRAW_DEBUG",0);
  59. }
  60. #endif
  61. return hdc;
  62. }
  63. int draw_ReleaseDC(HWND hwnd, HDC hdc)
  64. {
  65. int t=ReleaseDC(hwnd,hdc);
  66. #ifdef DRAW_DEBUG
  67. if (!hwnd)
  68. {
  69. MessageBox(NULL,"RDC: hwnd=0","DRAW_DEBUG",0);
  70. }
  71. if (!hdc)
  72. {
  73. MessageBox(NULL,"RDC: hdc=0","DRAW_DEBUG",0);
  74. }
  75. #endif
  76. LeaveCriticalSection(&g_mainwndcs);
  77. return t;
  78. }
  79. HBITMAP draw_LBitmap(LPCTSTR bmname, const wchar_t *filename)
  80. {
  81. if (skin_directory[0] && filename) {
  82. HBITMAP bm;
  83. wchar_t bitmapfilename[MAX_PATH] = {0};
  84. PathCombineW(bitmapfilename, skin_directory, filename);
  85. bm = (HBITMAP)LoadImageW(hMainInstance, bitmapfilename, IMAGE_BITMAP, 0, 0, (palmode?LR_CREATEDIBSECTION:0)|LR_LOADFROMFILE);
  86. if (bm) return bm;
  87. }
  88. if (bmname) return (HBITMAP)LoadImage(hMainInstance, bmname, IMAGE_BITMAP, 0, 0, (palmode?LR_CREATEDIBSECTION:0));
  89. else return 0;
  90. }
  91. void do_palmode(HDC hdc)
  92. {
  93. if (palmode)
  94. {
  95. SelectPalette(hdc,draw_hpal,FALSE);
  96. RealizePalette(hdc);
  97. }
  98. }
  99. int updateen=1;
  100. void update_area(int x1, int y1, int w, int h);
  101. void _setSrcBM(HBITMAP hbm
  102. #ifdef DEBUG_DRAW
  103. , char *a
  104. #endif
  105. )
  106. {
  107. static HBITMAP old;
  108. #ifdef DEBUG_DRAW
  109. if (!hbm && a)
  110. {
  111. char s[156] = {0};
  112. wsprintf(s,"Invalid bitmap: %s",a);
  113. DebugBreak();
  114. MessageBox(NULL,s,"DRAW_DEBUG error",MB_OK);
  115. }
  116. if (main_thread_id != GetCurrentThreadId())
  117. DebugBreak();//MessageBox(NULL,"Not in mainthread","DRAW_DEBUG error",MB_OK);
  118. if (hbm && old)
  119. {
  120. char s[156] = {0};
  121. StringCchPrintf(s,156,"Tried to set bitmap when bitmap already set: %s",a);
  122. DebugBreak();
  123. MessageBox(NULL,s,"DRAW_DEBUG error",MB_OK);
  124. }
  125. if (!hbm && !old)
  126. {
  127. DebugBreak();
  128. MessageBox(NULL,"Tried to unset bitmap when bitmap not set","DRAW_DEBUG error",MB_OK);
  129. }
  130. #endif
  131. if (hbm)
  132. {
  133. EnterCriticalSection(&g_srcdccs);
  134. old = (HBITMAP)SelectObject(bmDC,hbm);
  135. }
  136. else
  137. {
  138. SelectObject(bmDC,old); old=0;
  139. LeaveCriticalSection(&g_srcdccs);
  140. }
  141. }
  142. void draw_setnoupdate(int v)
  143. {
  144. updateen=!v;
  145. if (!v)
  146. update_area(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
  147. }
  148. void draw_reinit_plfont(int update)
  149. {
  150. EnterCriticalSection(&g_srcdccs);
  151. {
  152. HWND plw=hPLWindow;
  153. wchar_t font_name[MAX_PATH] = {0};
  154. int font_charset=DEFAULT_CHARSET;
  155. TEXTMETRIC tm;
  156. WADrawDC hdc(plw?plw:hMainWindow);
  157. HANDLE holdf;
  158. if (font) DeleteObject(font);
  159. if (mfont) DeleteObject(mfont);
  160. if (shadefont) DeleteObject(shadefont);
  161. if (osdFontText) DeleteObject(osdFontText);
  162. if (selbrush) DeleteObject(selbrush);
  163. if (mfont_bgbrush) DeleteObject(mfont_bgbrush);
  164. if (normbrush) DeleteObject(normbrush);
  165. mfont_bgbrush=selbrush=normbrush=0;
  166. font=0;
  167. mfont=0;
  168. shadefont=0;
  169. osdFontText = NULL;
  170. if (config_custom_plfont && *playlist_custom_fontW)
  171. StringCchCopyW(font_name, sizeof(font_name), playlist_custom_fontW);
  172. else
  173. {
  174. if (!Skin_PLFontW[0]) getStringW(IDS_PLFONT,font_name,sizeof(font_name)/sizeof(*font_name));
  175. else StringCbCopyW(font_name,sizeof(font_name), Skin_PLFontW);
  176. }
  177. // TODO: verify the existance of the font and fall back to Arial if it doesn't exist
  178. font_charset=atoi(getString(IDS_PLFONT_CHARSET,NULL,0));
  179. font=CreateFontW(ScaleY(-config_pe_fontsize), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  180. font_charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
  181. DEFAULT_PITCH | FF_DONTCARE, font_name);
  182. mfont=CreateFontW(-10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  183. font_charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  184. (config_dsize && !config_bifont && config_bifont_alt ? ANTIALIASED_QUALITY : DRAFT_QUALITY),
  185. DEFAULT_PITCH | FF_DONTCARE, font_name);
  186. shadefont=CreateFontW(-8, 5, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
  187. font_charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,
  188. DEFAULT_PITCH | FF_DONTCARE, font_name);
  189. osdFontText = CreateFontW(OSD_TEXT_SIZE, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE,
  190. font_charset, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
  191. ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, GetFontNameW());
  192. holdf=SelectObject(hdc,font);
  193. GetTextMetrics(hdc,&tm);
  194. if (!plw) SelectObject(hdc,holdf);
  195. pe_fontheight=tm.tmHeight;
  196. if (pe_fontheight < 1) pe_fontheight=1;
  197. holdf=SelectObject(hdc,mfont);
  198. GetTextMetrics(hdc,&tm);
  199. mfont_height=tm.tmHeight;
  200. SelectObject(hdc,holdf);
  201. {
  202. int ld=0,y;
  203. setSrcBM(fontBM);
  204. mfont_fgcolor=mfont_bgcolor=GetPixel(bmDC,150,4);
  205. for (y = 0; y < 6; y ++)
  206. {
  207. for (int x = 0; x < 20; x ++)
  208. {
  209. int d,a,b,c;
  210. COLORREF r=GetPixel(bmDC,x,y);
  211. a=(r&0xff)-(mfont_bgcolor&0xff);
  212. b=(((r&0xff00)>>8)-((mfont_bgcolor&0xff00)>>8));
  213. c=(((r&0xff0000)>>16)-((mfont_bgcolor&0xff0000)>>16));
  214. d=(a*a+b*b+c*c);
  215. if (d > ld) { ld=d; mfont_fgcolor=r; }
  216. }
  217. }
  218. unsetSrcBM();
  219. //mfont_fgcolor
  220. }
  221. {
  222. LOGBRUSH lb={BS_SOLID};
  223. lb.lbColor=GetNearestColor(hdc,Skin_PLColors[3]);
  224. selbrush = CreateBrushIndirect(&lb);
  225. lb.lbColor=GetNearestColor(hdc,Skin_PLColors[2]);
  226. normbrush = CreateBrushIndirect(&lb);
  227. lb.lbColor=mfont_bgcolor;
  228. mfont_bgbrush = CreateBrushIndirect(&lb);
  229. }
  230. }
  231. LeaveCriticalSection(&g_srcdccs);
  232. if (update) PostMessageW(hMainWindow, WM_WA_IPC, 0, IPC_CB_RESETFONT);
  233. }
  234. static struct
  235. {
  236. BITMAPINFO bmi;
  237. RGBQUAD more_bm7iColors[256];
  238. } bitmap;
  239. static void CopyToMainBM()
  240. {
  241. HDC hdc = CreateCompatibleDC(mainDC);
  242. HBITMAP oldbm = (HBITMAP)SelectObject(hdc,mainBM_save);
  243. BitBlt(mainDC,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,hdc,0,0,SRCCOPY);
  244. SelectObject(hdc,oldbm);
  245. DeleteDC(hdc);
  246. }
  247. void draw_init()
  248. {
  249. HDC screenHdc;
  250. EnterCriticalSection(&g_srcdccs);
  251. if (draw_initted) draw_kill();
  252. screenHdc = draw_GetWindowDC(hMainWindow);
  253. palmode = GetDeviceCaps(screenHdc,RASTERCAPS)&RC_PALETTE?1:0;
  254. mainDC = CreateCompatibleDC(screenHdc);
  255. mainDC2 = CreateCompatibleDC(screenHdc);
  256. bmDC = CreateCompatibleDC(screenHdc);
  257. specDC = CreateCompatibleDC(screenHdc);
  258. mainBM_save = draw_LBitmap(MAKEINTRESOURCE(IDB_MAINBITMAP),L"main.bmp");
  259. oldMainBM = (HBITMAP)SelectObject(mainDC,mainBM_save);
  260. mainBM = CreateCompatibleBitmap(mainDC,WINDOW_WIDTH,WINDOW_HEIGHT);
  261. SelectObject(mainDC,mainBM);
  262. CopyToMainBM();
  263. embedBM = draw_LBitmap(MAKEINTRESOURCE(IDB_EMBEDWND),L"gen.bmp");
  264. {
  265. COLORREF start;
  266. int x;
  267. int pos=0;
  268. setSrcBM(embedBM);
  269. if ((start = GetPixel(bmDC,0,90)) != CLR_INVALID)
  270. {
  271. for (x = 0; x < 26; x ++)
  272. {
  273. int cnt=0;
  274. while (GetPixel(bmDC,pos,90) == start) pos++;
  275. titlebar_font_offsets[x]=pos;
  276. for (;;)
  277. {
  278. COLORREF t=GetPixel(bmDC,pos,90);
  279. if (t == CLR_INVALID) break;
  280. pos++;
  281. if (t == start)
  282. {
  283. titlebar_font_widths[x]=cnt;
  284. break;
  285. }
  286. else cnt++;
  287. }
  288. }
  289. }
  290. if ((start = GetPixel(bmDC,0,74)) != CLR_INVALID)
  291. {
  292. pos = 0;
  293. for (x = 0; x < 12; x ++)
  294. {
  295. int cnt=0;
  296. while (GetPixel(bmDC,pos,74) == start) pos++;
  297. titlebar_font_num_offsets[x]=pos;
  298. for (;;)
  299. {
  300. COLORREF t=GetPixel(bmDC,pos,74);
  301. if (t == CLR_INVALID) break;
  302. pos++;
  303. if (t == start)
  304. {
  305. titlebar_font_num_widths[x]=cnt;
  306. break;
  307. }
  308. else cnt++;
  309. }
  310. }
  311. }
  312. unsetSrcBM();
  313. }
  314. cbuttonsBM = draw_LBitmap(MAKEINTRESOURCE(IDB_CBUTTONS),L"cbuttons.bmp");
  315. monostereoBM = draw_LBitmap(MAKEINTRESOURCE(IDB_MONOSTEREO),L"monoster.bmp");
  316. playpauseBM = draw_LBitmap(MAKEINTRESOURCE(IDB_PLAYPAUSE),L"playpaus.bmp");
  317. shufflerepeatBM = draw_LBitmap(MAKEINTRESOURCE(IDB_SHUFFLEREP),L"shufrep.bmp");
  318. numbersBM_ex = draw_LBitmap(NULL,L"nums_ex.bmp");
  319. if (!numbersBM_ex) numbersBM = draw_LBitmap(MAKEINTRESOURCE(IDB_NUMBERS1),L"numbers.bmp");
  320. else numbersBM=NULL;
  321. volBM = draw_LBitmap(MAKEINTRESOURCE(IDB_VOLBAR),L"volume.bmp");
  322. if (skin_directory[0])
  323. panBM = draw_LBitmap(NULL,L"balance.bmp");
  324. else
  325. panBM = draw_LBitmap(MAKEINTRESOURCE(IDB_PANBAR),NULL);
  326. if (!panBM) panBM=volBM;
  327. fontBM = draw_LBitmap(MAKEINTRESOURCE(IDB_FONT1),L"text.bmp");
  328. posbarBM = draw_LBitmap(MAKEINTRESOURCE(IDB_POSBAR),L"posbar.bmp");
  329. tbBM = draw_LBitmap(MAKEINTRESOURCE(IDB_TB),L"titlebar.bmp");
  330. {
  331. int c;
  332. static unsigned char ppal2[] = {
  333. 0,0,0, // color 0 = black
  334. 24,24,41, // color 1 = grey for dots
  335. 239,49,16, // color 2 = top of spec
  336. 206,41,16, // 3
  337. 214,90,0, // 4
  338. 214,102,0, // 5
  339. 214,115,0, // 6
  340. 198,123,8, // 7
  341. 222,165,24, // 8
  342. 214,181,33, // 9
  343. 189,222,41, // 10
  344. 148,222,33, // 11
  345. 41,206,16, // 12
  346. 50,190,16, // 13
  347. 57,181,16, // 14
  348. 49,156,8, // 15
  349. 41,148,0, // 16
  350. 24,132,8, // 17
  351. 255,255,255, // 18 = osc 1
  352. 214,214,222, // 19 = osc 2 (slightly dimmer)
  353. 181,189,189, // 20 = osc 3
  354. 160,170,175, // 21 = osc 4
  355. 148,156,165, // 22 = osc 4
  356. 150, 150, 150, // 23 = analyzer peak
  357. };
  358. unsigned char ppal[sizeof(ppal2)];
  359. memcpy(ppal,ppal2,sizeof(ppal2));
  360. if (skin_directory[0])
  361. {
  362. FILE *fp;
  363. wchar_t bitmapfilename[MAX_PATH] = {0};
  364. PathCombineW(bitmapfilename, skin_directory, L"viscolor.txt");
  365. fp = _wfopen(bitmapfilename,L"rt");
  366. if (fp)
  367. {
  368. int x;
  369. for (x = 0; x < 24; x ++)
  370. {
  371. int t;
  372. char progdir[91],*p=progdir;
  373. fgets(progdir,90,fp);
  374. if (feof(fp)) break;
  375. for (t=0; t<3; t ++)
  376. {
  377. int b=0,s=0;
  378. while (p && (*p == ' ' || *p == ',' || *p == '\t')) p++;
  379. while (p && *p >= '0' && *p <= '9') {s=1;b=b*10+*p++-'0';}
  380. if (!s) { x=24; break; }
  381. ppal[x*3+t]=b;
  382. }
  383. }
  384. fclose(fp);
  385. }
  386. }
  387. for (c = 0; c < sizeof(ppal)/(3); c ++) {
  388. bitmap.bmi.bmiColors[c].rgbRed = ppal[c*3];
  389. bitmap.bmi.bmiColors[c].rgbGreen = ppal[c*3+1];
  390. bitmap.bmi.bmiColors[c].rgbBlue = ppal[c*3+2];
  391. bitmap.bmi.bmiColors[c].rgbReserved = 0;
  392. }
  393. bitmap.bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  394. bitmap.bmi.bmiHeader.biPlanes = 1;
  395. bitmap.bmi.bmiHeader.biBitCount = 8;
  396. bitmap.bmi.bmiHeader.biCompression = BI_RGB;
  397. bitmap.bmi.bmiHeader.biClrUsed = sizeof(ppal)/(3);
  398. bitmap.bmi.bmiHeader.biClrImportant = sizeof(ppal)/(3);
  399. bitmap.bmi.bmiHeader.biWidth = 76*2;
  400. bitmap.bmi.bmiHeader.biHeight = 16*2;
  401. bitmap.bmi.bmiHeader.biSizeImage = 76*16*4;
  402. specBM = CreateDIBSection(specDC,&bitmap.bmi,DIB_RGB_COLORS, (LPVOID*)&specData, NULL, 0);
  403. oldSpecBM = (HBITMAP)SelectObject(specDC,specBM);
  404. memset(specData,0,76*16*4);
  405. }
  406. if (palmode)
  407. {
  408. RGBQUAD rgb[256] = {0};
  409. int x;
  410. struct {
  411. LOGPALETTE lpal;
  412. PALETTEENTRY pal[256];
  413. } lPal;
  414. GetDIBColorTable(mainDC,0,256,rgb);
  415. lPal.lpal.palVersion = 0x300;
  416. lPal.lpal.palNumEntries = 256;
  417. for (x = 0; x < 256; x ++)
  418. {
  419. lPal.lpal.palPalEntry[x].peRed = rgb[x].rgbRed;
  420. lPal.lpal.palPalEntry[x].peGreen = rgb[x].rgbGreen;
  421. lPal.lpal.palPalEntry[x].peBlue = rgb[x].rgbBlue;
  422. lPal.lpal.palPalEntry[x].peFlags = 0;
  423. }
  424. draw_hpal = CreatePalette((LPLOGPALETTE)&lPal);
  425. }
  426. else draw_hpal = 0;
  427. draw_ReleaseDC(hMainWindow,screenHdc);
  428. draw_initted=1;
  429. draw_reinit_plfont(1);
  430. sa_kill = 0;
  431. draw_pe_init();
  432. draw_eq_init();
  433. draw_vw_init();
  434. LeaveCriticalSection(&g_srcdccs);
  435. }
  436. void draw_kill()
  437. {
  438. int old_sa_mode = sa_curmode;
  439. sa_setthread(-1);
  440. sa_kill = 1;
  441. while (sa_safe>0)
  442. Sleep(50);
  443. sa_setthread(old_sa_mode);
  444. if (!draw_initted) return;
  445. EnterCriticalSection(&g_srcdccs);
  446. sa_safe=0;
  447. draw_initted=0;
  448. specData=0;
  449. DeleteObject(mainBM_save);
  450. SelectObject(mainDC,oldMainBM);
  451. SelectObject(specDC,oldSpecBM);
  452. if (mainBM2)
  453. {
  454. SelectObject(mainDC2,oldmainBM2);
  455. DeleteObject(mainBM2);
  456. mainBM2=NULL;
  457. }
  458. DeleteObject(embedBM);
  459. DeleteDC(mainDC);
  460. DeleteDC(specDC);
  461. DeleteDC(mainDC2);
  462. DeleteDC(bmDC);
  463. DeleteObject(mainBM);
  464. DeleteObject(cbuttonsBM);
  465. DeleteObject(monostereoBM);
  466. DeleteObject(shufflerepeatBM);
  467. DeleteObject(playpauseBM);
  468. if (numbersBM) DeleteObject(numbersBM);
  469. if (numbersBM_ex) DeleteObject(numbersBM_ex);
  470. if (panBM != volBM) DeleteObject(panBM);
  471. DeleteObject(volBM);
  472. DeleteObject(fontBM);
  473. DeleteObject(posbarBM);
  474. DeleteObject(specBM);
  475. DeleteObject(tbBM);
  476. if (draw_hpal) DeleteObject(draw_hpal);
  477. draw_hpal = 0;
  478. if (font) DeleteObject(font);
  479. if (mfont) DeleteObject(mfont);
  480. if (shadefont) DeleteObject(shadefont);
  481. if (osdFontText) DeleteObject(osdFontText);
  482. if (selbrush) DeleteObject(selbrush);
  483. if (mfont_bgbrush) DeleteObject(mfont_bgbrush);
  484. if (normbrush) DeleteObject(normbrush);
  485. mfont_bgbrush=selbrush=normbrush=0;
  486. shadefont=mfont=font=0;
  487. LeaveCriticalSection(&g_srcdccs);
  488. }
  489. void draw_clear()
  490. {
  491. RECT r;
  492. if (!draw_initted) return;
  493. CopyToMainBM();
  494. draw_playicon(2);
  495. GetClientRect(hMainWindow,&r);
  496. draw_tbar(config_hilite?(GetForegroundWindow() == hMainWindow?1:0):1, config_windowshade,0);
  497. update_area(0,0,r.right,r.bottom);
  498. }
  499. void draw_clutterbar(int enable)
  500. {
  501. int x,y;
  502. if (!draw_initted) return;
  503. if (config_ascb_new && !enable) enable=1;
  504. if (!enable)
  505. {
  506. x=8;
  507. y=0;
  508. }
  509. else if (enable == 1)
  510. {
  511. x=0;
  512. y=0;
  513. }
  514. else
  515. {
  516. y=44;
  517. x=(enable-2)*8;
  518. }
  519. setSrcBM(tbBM);
  520. BitBlt(mainDC,10,22,18-10,65-22,bmDC,304+x,y,SRCCOPY);
  521. if (enable != 3 && (config_ascb_new||enable))
  522. {
  523. if (config_aot)
  524. {
  525. BitBlt(mainDC,11,22+11,18-10-1,65-22-34-1,bmDC,312+1,44+11,SRCCOPY);
  526. }
  527. else
  528. BitBlt(mainDC,11,22+11,18-10-1,65-22-34-1,bmDC,304+1,11,SRCCOPY);
  529. }
  530. if (enable != 5 && (config_ascb_new||enable))
  531. {
  532. if (config_dsize)
  533. {
  534. BitBlt(mainDC,11,22+27,18-10-1,6,bmDC,328+1,44+27,SRCCOPY);
  535. }
  536. else
  537. BitBlt(mainDC,11,22+27,18-10-1,6,bmDC,304+1,27,SRCCOPY);
  538. }
  539. unsetSrcBM();
  540. update_area(10,22,8,65-22);
  541. }
  542. void update_area(int x1, int y1, int w, int h)
  543. {
  544. if (updateen && hMainWindow)
  545. {
  546. WADrawDC tDC(hMainWindow);
  547. if (tDC)
  548. {
  549. do_palmode(tDC);
  550. if (!config_dsize)
  551. {
  552. BitBlt(tDC,x1,y1,w,h,mainDC,x1,y1,SRCCOPY);
  553. if (mainBM2)
  554. {
  555. SelectObject(mainDC2,oldmainBM2);
  556. DeleteObject(mainBM2);
  557. mainBM2=NULL;
  558. }
  559. }
  560. else
  561. {
  562. if (!mainBM2)
  563. {
  564. mainBM2 = CreateCompatibleBitmap(mainDC,WINDOW_WIDTH*2,WINDOW_HEIGHT*2);
  565. oldmainBM2 = (HBITMAP)SelectObject(mainDC2,mainBM2);
  566. x1=y1=0;
  567. w=WINDOW_WIDTH;
  568. h=WINDOW_HEIGHT;
  569. }
  570. StretchBlt(mainDC2,x1*2,y1*2,w*2,h*2,mainDC,x1,y1,w,h,SRCCOPY);
  571. BitBlt(tDC,x1*2,y1*2,w*2,h*2,mainDC2,x1*2,y1*2,SRCCOPY);
  572. }
  573. }
  574. }
  575. }
  576. void getXYfromChar(wchar_t ic, int *x, int *y)
  577. {
  578. int c,c2=0;
  579. switch (ic)
  580. {
  581. case L'°': ic = L'0'; break;
  582. case L'Ç': ic = L'C'; break;
  583. case L'ü': ic = L'u'; break;
  584. case L'è': case L'ë': case L'ê': case L'é': ic = L'e'; break;
  585. case L'á': case L'à': case L'â': ic = L'a'; break;
  586. case L'ç': ic = L'c'; break;
  587. case L'í': case L'ì': case L'î': case L'ï': ic = L'i'; break;
  588. case L'É': ic = L'E'; break;
  589. case L'æ': ic = L'a'; break;
  590. case L'Æ': ic = L'A'; break;
  591. case L'ó': case L'ò': case L'ô': ic = L'o'; break;
  592. case L'ú': case L'ù': case L'û': ic = L'u'; break;
  593. case L'ÿ': ic = L'y'; break;
  594. case L'Ü': ic = L'U'; break;
  595. case L'ƒ': ic = L'f'; break;
  596. case L'Ñ': case L'ñ': ic = L'n'; break;
  597. default: break;
  598. } // quick relocations
  599. if (ic <= L'Z' && ic >= L'A') c = (ic-'A');
  600. else if (ic <= L'z' && ic >= L'a') c = (ic-'a');
  601. else
  602. {
  603. c2 = 6;
  604. if (ic == L'\1') c=10;
  605. else if (ic == L'.') c = 11;
  606. else if (ic <= L'9' && ic >= L'0') c = ic - '0';
  607. else if (ic == L':') c = 12;
  608. else if (ic == L'(') c = 13;
  609. else if (ic == L')') c = 14;
  610. else if (ic == L'-') c = 15;
  611. else if (ic == L'\'' || ic=='`') c = 16;
  612. else if (ic == L'!') c = 17;
  613. else if (ic == L'_') c = 18;
  614. else if (ic == L'+') c = 19;
  615. else if (ic == L'\\') c = 20;
  616. else if (ic == L'/') c = 21;
  617. else if (ic == L'[' || ic == L'{' || ic == L'<') c = 22;
  618. else if (ic == L']' || ic == L'}' || ic == L'>') c = 23;
  619. else if (ic == L'~' || ic == L'^') c = 24;
  620. else if (ic == L'&') c = 25;
  621. else if (ic == L'%') c = 26;
  622. else if (ic == L',') c = 27;
  623. else if (ic == L'=') c = 28;
  624. else if (ic == L'$') c = 29;
  625. else if (ic == L'#') c = 30;
  626. else
  627. {
  628. c2=12;
  629. if (ic == L'Å' || ic == L'å') c = 0;
  630. else if (ic == L'Ö' || ic == L'ö') c = 1;
  631. else if (ic == L'Ä' || ic == L'ä') c = 2;
  632. else if (ic == L'?') c = 3;
  633. else if (ic == L'*') c = 4;
  634. else
  635. {
  636. c2 = 0;
  637. if (ic == L'"') c = 26;
  638. else if (ic == L'@') c = 27;
  639. else c = 30;
  640. }
  641. }
  642. }
  643. c*=5;
  644. *x=c;
  645. *y=c2;
  646. }