draw_pe.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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 "draw.h"
  10. #include "api.h"
  11. #include "../nu/AutoWide.h"
  12. #include "../nu/AutoChar.h"
  13. #include "resource.h"
  14. #include <bfc/platform/minmax.h>
  15. #include "WADrawDC.h"
  16. HBITMAP plMainBM=0;
  17. extern "C" int pe_init = 0;
  18. wchar_t playlistStr[19] = {0};
  19. int (WINAPI *jtf_drawtext)(HDC, LPCWSTR, int, LPRECT, UINT) = 0;
  20. void draw_pe_init()
  21. {
  22. EnterCriticalSection(&g_srcdccs);
  23. if (pe_init)
  24. draw_pe_kill();
  25. pe_init=1;
  26. if (!plMainBM)
  27. plMainBM = draw_LBitmap(MAKEINTRESOURCE(IDB_PLEDIT), L"pledit.bmp");
  28. LeaveCriticalSection(&g_srcdccs);
  29. }
  30. void draw_pe_kill()
  31. {
  32. if (!pe_init)
  33. return;
  34. EnterCriticalSection(&g_srcdccs);
  35. DeleteObject(plMainBM);
  36. plMainBM=0;
  37. pe_init=0;
  38. LeaveCriticalSection(&g_srcdccs);
  39. }
  40. void draw_set_plbm(HBITMAP bm)
  41. {
  42. EnterCriticalSection(&g_srcdccs);
  43. if (plMainBM)
  44. DeleteObject(plMainBM);
  45. plMainBM=bm;
  46. LeaveCriticalSection(&g_srcdccs);
  47. }
  48. void draw_pe_iobut(int which) // -1 = none, 0 = load, 1=save, 2=clear
  49. {
  50. if (!pe_init || disable_skin_borders) // if we're not init'd (shouldn't happen) or gen_ff is active
  51. return;
  52. int offs=config_pe_width-44;
  53. WADrawDC hdcout(hPLWindow);
  54. do_palmode(hdcout);
  55. setSrcBM(plMainBM);
  56. BitBlt(hdcout, offs-3, config_pe_height-30-18*2, 3, 18*3, bmDC, 250, 111, SRCCOPY);
  57. BitBlt(hdcout, offs, config_pe_height-30-18*2, 22, 18, bmDC, (which==2)?227:204, 111, SRCCOPY);
  58. BitBlt(hdcout, offs, config_pe_height-30-18, 22, 18, bmDC, (which==1)?227:204, 130, SRCCOPY);
  59. BitBlt(hdcout, offs, config_pe_height-30, 22, 18, bmDC, (which==0)?227:204, 149, SRCCOPY);
  60. unsetSrcBM();
  61. }
  62. static void draw_pe_infostr(HDC hdcout, wchar_t *str)
  63. {
  64. StringCchCopyW(playlistStr, 18, str); // use 18 instead of 19 to keep the last byte null terminated
  65. AutoChar narrowStr(str);
  66. SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)(char *)narrowStr, IPC_CB_PEINFOTEXT);
  67. playlistTextFeed->UpdateText(playlistStr, 19);
  68. if (!pe_init)
  69. return;
  70. wchar_t data[19] = {0};
  71. int x,xp=config_pe_width-143,yp=config_pe_height-28;
  72. if (disable_skin_borders) return;
  73. if (lstrlenW(str) < 18)
  74. {
  75. StringCchCopyW(data,19, str);
  76. for (x = lstrlenW(str); x < 18; x ++) data[x]=L' ';
  77. }
  78. else memcpy(data,str,18*sizeof(wchar_t));
  79. do_palmode(hdcout);
  80. setSrcBM(fontBM);
  81. for (x = 0; x < 18; x ++)
  82. {
  83. int c=0,c2=0;
  84. getXYfromChar(data[x],&c,&c2);
  85. BitBlt(hdcout,xp,yp,5,6,bmDC,c,c2,SRCCOPY);
  86. xp+=5;
  87. }
  88. unsetSrcBM();
  89. }
  90. /* if we ever want to use a font rather than the skin bitmap, we can uncomment this
  91. void draw_pe_infostr_font(char *str)
  92. {
  93. if (!pe_init)
  94. return;
  95. int xp=config_pe_width-145,yp=config_pe_height-30;
  96. HDC hdcout;
  97. SendMessageW(hMainWindow, WM_WA_IPC, reinterpret_cast<WPARAM>(str), IPC_CB_PEINFOTEXT);
  98. if (disable_skin_borders) return;
  99. hdcout=draw_GetWindowDC(hPLWindow);
  100. do_palmode(hdcout);
  101. HFONT oldfont = (HFONT) SelectObject(hdcout,mfont);
  102. SetTextColor(hdcout,Skin_PLColors[0]);
  103. SetBkColor(hdcout,Skin_PLColors[2]);
  104. RECT r={xp, yp, xp+92, yp+10};
  105. DrawText(hdcout, str, min(18, lstrlen(str)), &r, DT_CENTER| DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
  106. SelectObject(hdcout,oldfont);
  107. draw_ReleaseDC(hPLWindow,hdcout);
  108. }
  109. */
  110. void draw_pe_miscbut(int which) // -1 = none, 0 = inf, 1 = sort, 2=misc
  111. {
  112. if (!pe_init || disable_skin_borders) // if we're not init'd (shouldn't happen) or gen_ff is active
  113. return;
  114. WADrawDC hdcout(hPLWindow);
  115. do_palmode(hdcout);
  116. setSrcBM(plMainBM);
  117. BitBlt(hdcout, 98, config_pe_height-30-18*2, 3, 18*3, bmDC, 200, 111, SRCCOPY);
  118. BitBlt(hdcout, 101, config_pe_height-30-18*2, 22, 18, bmDC, (which==2)?177:154, 111, SRCCOPY);
  119. BitBlt(hdcout, 101, config_pe_height-30-18, 22, 18, bmDC, (which==1)?177:154, 130, SRCCOPY);
  120. BitBlt(hdcout, 101, config_pe_height-30, 22, 18, bmDC, (which==0)?177:154, 149, SRCCOPY);
  121. unsetSrcBM();
  122. }
  123. void draw_pe_selbut(int which) // -1 = none, 0 = all, 1 = none, 2=inv
  124. {
  125. if (!pe_init)
  126. return;
  127. if (disable_skin_borders) return;
  128. WADrawDC hdcout(hPLWindow);
  129. do_palmode(hdcout);
  130. setSrcBM(plMainBM);
  131. BitBlt(hdcout,69,config_pe_height-30-18*2,3,18*3,bmDC,150,111,SRCCOPY);
  132. BitBlt(hdcout,72,config_pe_height-30-18*2,22,18,bmDC,(which==2)?127:104,111,SRCCOPY);
  133. BitBlt(hdcout,72,config_pe_height-30-18,22,18,bmDC,(which==1)?127:104,130,SRCCOPY);
  134. BitBlt(hdcout,72,config_pe_height-30,22,18,bmDC,(which==0)?127:104,149,SRCCOPY);
  135. unsetSrcBM();
  136. }
  137. void draw_pe_rembut(int which) // -1 = none, 0 = sel, 1 = crop, 2 = all
  138. {
  139. if (!pe_init)
  140. return;
  141. if (disable_skin_borders) return;
  142. WADrawDC hdcout(hPLWindow);
  143. do_palmode(hdcout);
  144. setSrcBM(plMainBM);
  145. BitBlt(hdcout,40,config_pe_height-30-18*3,3,18*4,bmDC,100,111,SRCCOPY);
  146. BitBlt(hdcout,43,config_pe_height-30-18*3,22,18,bmDC,(which==3)?77:54,168,SRCCOPY);
  147. BitBlt(hdcout,43,config_pe_height-30-18*2,22,18,bmDC,(which==2)?77:54,111,SRCCOPY);
  148. BitBlt(hdcout,43,config_pe_height-30-18,22,18,bmDC,(which==1)?77:54,130,SRCCOPY);
  149. BitBlt(hdcout,43,config_pe_height-30,22,18,bmDC,(which==0)?77:54,149,SRCCOPY);
  150. unsetSrcBM();
  151. }
  152. void draw_pe_addbut(int which) // -1 = none, 0 = file, 1 = dir, 2 = loc
  153. {
  154. if (!pe_init)
  155. return;
  156. if (disable_skin_borders) return;
  157. WADrawDC hdcout(hPLWindow);
  158. do_palmode(hdcout);
  159. setSrcBM(plMainBM);
  160. BitBlt(hdcout,11,config_pe_height-30-18*2,3,18*3,bmDC,48,111,SRCCOPY);
  161. BitBlt(hdcout,14,config_pe_height-30-18*2,22,18,bmDC,(which==2)?23:0,111,SRCCOPY);
  162. BitBlt(hdcout,14,config_pe_height-30-18,22,18,bmDC,(which==1)?23:0,130,SRCCOPY);
  163. BitBlt(hdcout,14,config_pe_height-30,22,18,bmDC,(which==0)?23:0,149,SRCCOPY);
  164. unsetSrcBM();
  165. }
  166. void draw_pe_vslide(HWND hwnd, HDC hdc, int pushed, int pos) // pos 0..playlist_getlength()-num_songs
  167. {
  168. if (!pe_init)
  169. return;
  170. int track_h = config_pe_height-20-38;
  171. int slid_h = 18;
  172. //int w = 25;
  173. int yp,y,oy;
  174. WADrawDC hdcout(hdc, hwnd);
  175. do_palmode(hdcout);
  176. setSrcBM(plMainBM);
  177. {
  178. int num_songs=(config_pe_height-38-20-2)/pe_fontheight;
  179. int t=PlayList_getlength()-num_songs;
  180. if (t < 1) yp = 0;
  181. else {
  182. if (pos > t) pos=t;
  183. yp = ((track_h-slid_h)*pos)/t;
  184. if (yp < 0) yp = 0;
  185. }
  186. }
  187. for (y = 0; y < yp-28; y += 29)
  188. BitBlt(hdcout,config_pe_width-15,20+y,8,29,bmDC,36,42,SRCCOPY);
  189. oy=y+29;
  190. if (slid_h + yp > oy) oy+=29;
  191. if (y < yp) BitBlt(hdcout,config_pe_width-15,20+y,8,yp-y,bmDC,36,42,SRCCOPY);
  192. BitBlt(hdcout,config_pe_width-15,20+yp,8,slid_h,bmDC,pushed?61:52,53,SRCCOPY);
  193. y=yp+slid_h;
  194. if (y < oy && y < track_h) BitBlt(hdcout,config_pe_width-15,20+y,8,((y<track_h-29)?oy-y:track_h-y),bmDC,36,42+29-(oy-y),SRCCOPY);
  195. y = oy;
  196. for (y = oy; y < track_h; y += 29)
  197. {
  198. BitBlt(hdcout,config_pe_width-15,20+y,8,(y<track_h-29)?29:track_h-y,bmDC,36,42,SRCCOPY);
  199. }
  200. unsetSrcBM();
  201. }
  202. static void draw_pe_song(HDC hdcout, int pos, wchar_t *name, int time, int sel)
  203. {
  204. if (!pe_init)
  205. return;
  206. int ypos, left, right, num_songs, fontHeight;
  207. HFONT useFont;
  208. COLORREF foreground, background;
  209. HBRUSH useBrush;
  210. if (pos < 0)
  211. {
  212. // if (config_pe_height != 14) return;
  213. right = config_pe_width-29;
  214. ypos = config_bifont?4:2;
  215. left = 4;
  216. num_songs = 1;
  217. useFont=mfont;//shadefont;
  218. fontHeight=10;
  219. sel=0;
  220. foreground=mfont_fgcolor;
  221. background=mfont_bgcolor;
  222. useBrush=mfont_bgbrush;
  223. }
  224. else
  225. {
  226. fontHeight=pe_fontheight;
  227. right=config_pe_width-20;
  228. ypos=22+pos*fontHeight,
  229. left=12;
  230. num_songs=(config_pe_height-38-20-2)/pe_fontheight;
  231. useFont=font;
  232. if (sel&2) foreground=Skin_PLColors[1];
  233. else foreground= Skin_PLColors[0];
  234. if (!(sel&1)) background= Skin_PLColors[2];
  235. else background=Skin_PLColors[3];
  236. useBrush=(sel&1)?selbrush:normbrush;
  237. }
  238. if (pos >= num_songs) return;
  239. int xpos=left;
  240. int endp=right;
  241. int num_chars=(endp-xpos)/5;
  242. if (pos>=0 || !config_bifont)
  243. {
  244. RECT r={xpos,ypos,endp, ypos+fontHeight};
  245. SetTextColor(hdcout,foreground);
  246. SetBkColor(hdcout,background);
  247. do_palmode(hdcout);
  248. HFONT oldfont = (HFONT) SelectObject(hdcout,useFont);
  249. int rightToLeft = (config_pe_direction == PE_DIRECTION_RTL) || (config_pe_direction == PE_DIRECTION_AUTO && (GetFontLanguageInfo(hdcout) & GCP_REORDER));
  250. if (time >= 0)
  251. {
  252. char str[123];
  253. StringCchPrintfA(str,123," %d:%02d ",time/60,(time)%60); // format the time string
  254. RECT r2=r;
  255. if (pos == -1)
  256. {
  257. r2.top--;
  258. r2.bottom--;
  259. }
  260. SIZE timeSize;
  261. #ifdef BENSKI_NEW_MODE_THAT_BREAKS_GEN_JUMPEX_STUPID_API_HIJACKING
  262. // compute width of the string
  263. GetTextExtentPoint32(hdcout, str, lstrlen(str), &timeSize);
  264. #else
  265. DrawTextA(hdcout,str,lstrlenA(str),&r2,DT_VCENTER|DT_CALCRECT|DT_SINGLELINE/*|DT_NOCLIP*/|DT_NOPREFIX);
  266. timeSize.cx = r2.right-r2.left;
  267. r2.top = r.top;
  268. r2.bottom = r.bottom;
  269. #endif
  270. if (timeSize.cx < endp-xpos)
  271. {
  272. UINT alignment;
  273. if (rightToLeft)
  274. {
  275. r2.left=xpos;
  276. r2.right=xpos+timeSize.cx;
  277. r.left+=timeSize.cx;
  278. xpos+=timeSize.cx;
  279. alignment=DT_LEFT|DT_RTLREADING;
  280. }
  281. else
  282. {
  283. r2.left=endp-timeSize.cx;
  284. r2.right=endp;
  285. r.right-=timeSize.cx;
  286. endp-=timeSize.cx;
  287. alignment=DT_RIGHT;
  288. }
  289. DrawTextA(hdcout,str,lstrlenA(str),&r2,DT_VCENTER|DT_SINGLELINE|alignment/*|DT_NOCLIP*/|DT_NOPREFIX); // fg: removed DT_NOCLIP to fix xp's cleartype from painting too far
  290. }
  291. }
  292. UINT alignment;
  293. if (rightToLeft)
  294. {
  295. alignment=DT_RIGHT|DT_RTLREADING;
  296. }
  297. else
  298. {
  299. alignment=DT_LEFT;
  300. }
  301. if (pos==-1)
  302. CharUpperW(name);
  303. int nameLen = lstrlenW(name);
  304. int jtf_result = 0;
  305. if (jtf_drawtext)
  306. jtf_result=jtf_drawtext(hdcout,name,nameLen,&r,alignment|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
  307. if (!jtf_result)
  308. DrawTextW(hdcout,name,nameLen,&r,alignment|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
  309. if (jtf_result != 2)
  310. DrawTextW(hdcout,name,nameLen,&r,alignment|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX|DT_CALCRECT);
  311. HBRUSH oldbrush=(HBRUSH)SelectObject(hdcout,useBrush);
  312. HPEN oldpen=(HPEN)SelectObject(hdcout,GetStockObject(NULL_PEN));
  313. if (rightToLeft)
  314. Rectangle(hdcout, xpos, r.top, 1+(endp-r.right)+r.left, 1+ypos+fontHeight);
  315. else
  316. Rectangle(hdcout,r.right,r.top,1+endp,1+ypos+fontHeight);
  317. if (!pos || pos == num_songs-1)
  318. {
  319. SelectObject(hdcout,normbrush);
  320. if (!pos)
  321. Rectangle(hdcout, left, 20, 1+right, 1+23);
  322. if (pos == num_songs-1)
  323. Rectangle(hdcout, left, ypos+fontHeight, 1+right, config_pe_height-38+1);
  324. }
  325. SelectObject(hdcout,oldfont);
  326. SelectObject(hdcout,oldpen);
  327. SelectObject(hdcout,oldbrush);
  328. }
  329. else
  330. {
  331. int x;
  332. char str[10]="";
  333. setSrcBM(fontBM);
  334. do_palmode(hdcout);
  335. if (time >= 0)
  336. {
  337. StringCchPrintfA(str,10,"%d:%02d",time/60,(time)%60);
  338. num_chars -= lstrlenA(str)+1;
  339. }
  340. for (x = 0; x < num_chars && name[x]; x ++)
  341. {
  342. int c2=0,c=0;
  343. wchar_t oc;
  344. oc=name[x];
  345. if (x==num_chars-1 && name[x+1]) oc=L'\1';
  346. getXYfromChar(oc,&c,&c2);
  347. BitBlt(hdcout,xpos,ypos,5,6,bmDC,c,c2,SRCCOPY);
  348. xpos += 5;
  349. }
  350. if (!name[x])
  351. {
  352. int c2=0,c=0;
  353. getXYfromChar(L' ',&c,&c2);
  354. if (time >= 0) num_chars++;
  355. while (x++ < num_chars)
  356. {
  357. BitBlt(hdcout,xpos,ypos,5,6,bmDC,c,c2,SRCCOPY);
  358. xpos += 5;
  359. }
  360. }
  361. if (time >= 0)
  362. {
  363. int c2=0,c=0;
  364. getXYfromChar(' ',&c,&c2);
  365. BitBlt(hdcout,xpos,ypos,5,6,bmDC,c,c2,SRCCOPY);
  366. xpos += 5;
  367. if (pos < 0)
  368. xpos = config_pe_width-29-5*lstrlenA(str);
  369. else
  370. xpos = config_pe_width-24-5*lstrlenA(str);
  371. for (x = 0; str[x]; x ++)
  372. {
  373. getXYfromChar(str[x],&c,&c2);
  374. BitBlt(hdcout,xpos,ypos,5,6,bmDC,c,c2,SRCCOPY);
  375. xpos += 5;
  376. }
  377. }
  378. if (xpos < config_pe_width-(pos<0?30:20))
  379. {
  380. int c2=0,c=0;
  381. getXYfromChar(' ',&c,&c2);
  382. BitBlt(hdcout,xpos,ypos,config_pe_width-(pos<0?30:20)-xpos,6,bmDC,c,c2,SRCCOPY);
  383. }
  384. unsetSrcBM();
  385. }
  386. }
  387. void draw_pe_tbar(HWND hwnd, HDC hdc, int state)
  388. {
  389. if (!pe_init)
  390. return;
  391. if (!disable_skin_borders)
  392. {
  393. WADrawDC hdcout(hdc, hwnd);
  394. state = state?0:21;
  395. do_palmode(hdcout);
  396. setSrcBM(plMainBM);
  397. if (config_pe_height != 14)
  398. {
  399. int nt;
  400. int xp=0;
  401. BitBlt(hdcout,xp,0,25,20,bmDC,0,state,SRCCOPY);
  402. xp+=25;
  403. nt = (config_pe_width - 25 - 25 - 100)/25;
  404. if (nt)
  405. {
  406. if (nt&1)
  407. {
  408. BitBlt(hdcout,xp,0,12,20,bmDC,127,state,SRCCOPY);
  409. xp+=12;
  410. }
  411. nt/=2;
  412. while (nt-->0)
  413. {
  414. BitBlt(hdcout,xp,0,25,20,bmDC,127,state,SRCCOPY);
  415. xp+=25;
  416. }
  417. }
  418. BitBlt(hdcout,xp,0,100,20,bmDC,26,state,SRCCOPY);
  419. xp+=100;
  420. nt = (config_pe_width - 25 - 25 - 100)/25;
  421. if (nt)
  422. {
  423. if (nt&1)
  424. {
  425. BitBlt(hdcout,xp,0,13,20,bmDC,127,state,SRCCOPY);
  426. xp+=13;
  427. }
  428. nt/=2;
  429. while (nt-->0)
  430. {
  431. BitBlt(hdcout,xp,0,25,20,bmDC,127,state,SRCCOPY);
  432. xp+=25;
  433. }
  434. }
  435. nt = (config_pe_width - 25 - 25 - 100)%25;
  436. if (nt)
  437. {
  438. StretchBlt(hdcout,xp,0,nt,20,bmDC,127,state,25,20,SRCCOPY);
  439. xp+=nt;
  440. }
  441. BitBlt(hdcout,xp,0,25,20,bmDC,153,state,SRCCOPY);
  442. }
  443. else
  444. {
  445. int xpos=0;
  446. int n = (config_pe_width - 50)/25;
  447. BitBlt(hdcout,xpos,0,25,14,bmDC,72,42,SRCCOPY);
  448. xpos+=25;
  449. n--;
  450. while (n--)
  451. {
  452. BitBlt(hdcout,xpos,0,25,14,bmDC,72,57,SRCCOPY);
  453. xpos+=25;
  454. }
  455. n = (config_pe_width - 50)%25;
  456. if (n)
  457. {
  458. StretchBlt(hdcout,xpos,0,n,14,bmDC,72,57,24,14,SRCCOPY);
  459. xpos+=n;
  460. }
  461. BitBlt(hdcout,xpos,0,50,14,bmDC,99,state?57:42,SRCCOPY);
  462. }
  463. unsetSrcBM();
  464. if (config_pe_height == 14)
  465. {
  466. wchar_t ft[FILETITLE_SIZE] = {0};
  467. int q=PlayList_getPosition();
  468. if (q >= 0 && q < PlayList_getlength())
  469. {
  470. if (!g_has_deleted_current)
  471. {
  472. PlayList_getitem_pl(PlayList_getPosition(),ft);
  473. q=PlayList_getsonglength(PlayList_getPosition());
  474. }
  475. else
  476. {
  477. StringCchCopyW(ft,FILETITLE_SIZE, FileTitle);
  478. q=in_getlength();
  479. }
  480. }
  481. else
  482. {
  483. getStringW(IDS_PLEDIT_NOFILE_WSHADE,ft,FILETITLE_SIZE);
  484. q=-1;
  485. }
  486. draw_pe_song(hdcout, -1,ft,q,state?0:2);
  487. }
  488. }
  489. }
  490. void draw_pe_timedisp(HDC hdc, int minutes, int seconds, int tlm, int clear)
  491. {
  492. if (!pe_init)
  493. return;
  494. static int lastm, lasts, lastc=1,lasttlm;
  495. int x=config_pe_width-94+8;
  496. int y=config_pe_height-15;
  497. if (!hPLWindow) return;
  498. if (disable_skin_borders) return;
  499. WADrawDC mainDC(hdc, hPLWindow);
  500. if (minutes == -666) { minutes=lastm; seconds=lasts; clear=lastc; tlm=lasttlm; }
  501. lastm=minutes; lasts=seconds; lastc=clear; lasttlm=tlm;
  502. do_palmode(mainDC);
  503. setSrcBM(fontBM);
  504. if (clear)
  505. {
  506. BitBlt(mainDC,x,y,4,6,bmDC,142,0,SRCCOPY);
  507. BitBlt(mainDC,x+4,y,5,6,bmDC,142,0,SRCCOPY);
  508. BitBlt(mainDC,x+5+4,y,5,6,bmDC,142,0,SRCCOPY);
  509. BitBlt(mainDC,x+5+4+5,y,5,6,bmDC,142,0,SRCCOPY);
  510. BitBlt(mainDC,x+5+4+5+4+4,y,5,6,bmDC,142,0,SRCCOPY);
  511. BitBlt(mainDC,x+5+4+5+4+5+4,y,5,6,bmDC,142,0,SRCCOPY);
  512. }
  513. else
  514. {
  515. if (tlm)
  516. {
  517. if (minutes < 0) minutes=-minutes;
  518. if (seconds < 0) seconds=-seconds;
  519. if (!(minutes/100)) BitBlt(mainDC,x,y,4,6,bmDC,142,0,SRCCOPY);
  520. BitBlt(mainDC,x+((minutes/100)?0:4),y,3,6,bmDC,75,6,SRCCOPY);
  521. }
  522. else
  523. {
  524. if (!(minutes/100)) BitBlt(mainDC,x,y,4,6,bmDC,142,0,SRCCOPY);
  525. BitBlt(mainDC,x+((minutes/100)?0:4),y,3,6,bmDC,142,0,SRCCOPY);
  526. }
  527. if (minutes/100) BitBlt(mainDC,x+4,y,5,6,bmDC,5*((minutes/100)%10),6,SRCCOPY);
  528. BitBlt(mainDC,x+5+4,y,5,6,bmDC,5*((minutes/10)%10),6,SRCCOPY);
  529. BitBlt(mainDC,x+5+4+5,y,5,6,bmDC,5*((minutes)%10),6,SRCCOPY);
  530. BitBlt(mainDC,x+5+4+5+4+4,y,5,6,bmDC,5*((seconds/10)%10),6,SRCCOPY);
  531. BitBlt(mainDC,x+5+4+5+4+5+4,y,5,6,bmDC,5*((seconds)%10),6,SRCCOPY);
  532. }
  533. unsetSrcBM();
  534. }
  535. void draw_pe_tbutton(int b2, int b3, int b2_ws)
  536. {
  537. if (!pe_init)
  538. return;
  539. if (disable_skin_borders) return;
  540. {
  541. WADrawDC hdcout(hPLWindow);
  542. do_palmode(hdcout);
  543. setSrcBM(plMainBM);
  544. if (!b3)
  545. BitBlt(hdcout,config_pe_width-11,3,9,9,bmDC,167,3,SRCCOPY);
  546. else
  547. BitBlt(hdcout,config_pe_width-11,3,9,9,bmDC,52,42,SRCCOPY);
  548. if (!b2)
  549. {
  550. if (!b2_ws) BitBlt(hdcout,config_pe_width-20,3,9,9,bmDC,158,3,SRCCOPY);
  551. else BitBlt(hdcout,config_pe_width-20,3,9,9,bmDC,128,45,SRCCOPY);
  552. }
  553. else
  554. BitBlt(hdcout,config_pe_width-20,3,9,9,bmDC,b2_ws?150:62,42,SRCCOPY);
  555. unsetSrcBM();
  556. }
  557. }
  558. static bool IntersectY(int top1, int bottom1, int top2, int bottom2)
  559. {
  560. int top = MAX(top1, top2);
  561. int bottom = MIN(bottom1, bottom2);
  562. return top <= bottom;
  563. }
  564. static void draw_pl(HWND hwnd, HDC hdcout)
  565. {
  566. if (!pe_init)
  567. return;
  568. do_palmode(hdcout);
  569. draw_pe_tbar(hwnd, hdcout, GetForegroundWindow()==hwnd?1:(config_hilite?0:1));
  570. setSrcBM(plMainBM);
  571. if (config_pe_height != 14)
  572. {
  573. int y;
  574. int yp=20;
  575. y=(config_pe_height-20-38)/29;
  576. while (y-->0)
  577. {
  578. BitBlt(hdcout,0,yp,12,29,bmDC,0,42,SRCCOPY);
  579. BitBlt(hdcout,config_pe_width-20,yp,5,29,bmDC,31,42,SRCCOPY);
  580. BitBlt(hdcout,config_pe_width-7,yp,7,29,bmDC,31+13,42,SRCCOPY);
  581. yp += 29;
  582. }
  583. y=(config_pe_height-20-38)%29;
  584. if (y)
  585. {
  586. StretchBlt(hdcout,0,yp,12,y,bmDC,0,42,12,29,SRCCOPY);
  587. StretchBlt(hdcout,config_pe_width-20,yp,5,y,bmDC,31,42,5,29,SRCCOPY);
  588. StretchBlt(hdcout,config_pe_width-7,yp,7,y,bmDC,31+13,42,7,29,SRCCOPY);
  589. yp += y;
  590. }
  591. if (!disable_skin_borders)
  592. {
  593. BitBlt(hdcout,0,yp,125,38,bmDC,0,72,SRCCOPY);
  594. int x=(config_pe_width-125-150)/25;
  595. int xp=125, s=0;
  596. if (x >= 3) { x-=3; s=1;}
  597. while (x-->0)
  598. {
  599. BitBlt(hdcout,xp,yp,25,38,bmDC,179,0,SRCCOPY);
  600. xp+=25;
  601. }
  602. x = (config_pe_width-125-150)%25;
  603. if (x)
  604. {
  605. StretchBlt(hdcout,xp,yp,x,38,bmDC,179,0,25,38,SRCCOPY);
  606. xp+=x;
  607. }
  608. if (s)
  609. {
  610. BitBlt(hdcout,xp,yp,75,38,bmDC,205,0,SRCCOPY);
  611. xp+=75;
  612. }
  613. BitBlt(hdcout,xp,yp,150,38,bmDC,126,72,SRCCOPY);
  614. }
  615. }
  616. unsetSrcBM();
  617. }
  618. static void draw_pl2(HWND hwnd, HDC hdc, RECT &r)
  619. {
  620. if (config_pe_height != 14)
  621. {
  622. {
  623. int x,t;
  624. int num_songs=(config_pe_height-38-20-2)/pe_fontheight;
  625. if (pledit_disp_offs < 0) pledit_disp_offs=0;
  626. t=PlayList_getlength()-pledit_disp_offs;
  627. if (t < 1)
  628. {
  629. pledit_disp_offs=0;
  630. t=PlayList_getlength();
  631. }
  632. if (t > num_songs) t = num_songs;
  633. //LeaveCriticalSection(&g_mainwndcs);
  634. for (x = 0; x < t; x ++)
  635. {
  636. int qt,b;
  637. qt=22+x*pe_fontheight;
  638. b=qt+pe_fontheight-1;
  639. if (IntersectY(qt, b, r.top, r.bottom)
  640. || (x == t-1 && config_pe_height-38 >= r.top))
  641. {
  642. wchar_t ft[FILETITLE_SIZE] = {0};
  643. PlayList_getitem_pl(x+pledit_disp_offs,ft);
  644. extern int g_has_deleted_current;
  645. // EnterCriticalSection(&g_mainwndcs);
  646. draw_pe_song(hdc, x,ft,PlayList_getsonglength(x+pledit_disp_offs),(PlayList_getselect(x+pledit_disp_offs) ? 1 : 0) + ((!g_has_deleted_current && PlayList_getPosition() == x+pledit_disp_offs) ? 2 : 0));
  647. //LeaveCriticalSection(&g_mainwndcs);
  648. }
  649. }
  650. //EnterCriticalSection(&g_mainwndcs);
  651. wchar_t blank[] = L" ";
  652. for (; x < num_songs; x ++)
  653. {
  654. draw_pe_song(hdc, x,blank ,-1,0);
  655. }
  656. if (r.right > config_pe_width-18 )
  657. {
  658. draw_pe_vslide(hwnd, hdc, 0, pledit_disp_offs);
  659. }
  660. }
  661. draw_pe_timedisp(hdc, -666,0,0,0);
  662. {
  663. wchar_t str[64]=L"", str2[32]=L"";
  664. {
  665. int /*x=0,*/v,t,p=0;
  666. int seltime=0,st2=0,st1=0, ttime=0;
  667. v = PlayList_getlength();
  668. for (t = 0; t < v; t ++)
  669. {
  670. int a = PlayList_getsonglength(t);
  671. if (PlayList_getselect(t))
  672. {
  673. p++;
  674. if (a<0)
  675. st2=2;
  676. else seltime += a;
  677. }
  678. if (a<0) st1=1;
  679. //else x += a;
  680. if (a > 0) ttime += a;
  681. }
  682. if (!seltime && !st2) StringCchCopyW(str,64, L"0:00");
  683. else if (seltime)
  684. {
  685. if (seltime < 60*60)
  686. StringCchPrintfW(str, 64, L"%d:%02d",seltime/60,seltime%60);
  687. else
  688. StringCchPrintfW(str,64, L"%d:%02d:%02d",seltime/60/60,(seltime/60)%60,seltime%60);
  689. if (st2) StringCchCatW(str,64,L"+");
  690. } else if (st2) StringCchCatW(str,64,L"?");
  691. if (!ttime && !st1) StringCchCopyW(str2,32, L"0:00");
  692. else if (ttime)
  693. {
  694. if (ttime < 60*60)
  695. StringCchPrintfW(str2,32, L"%d:%02d",ttime/60,ttime%60);
  696. else
  697. StringCchPrintfW(str2,32,L"%d:%02d:%02d",ttime/60/60,(ttime/60)%60,ttime%60);
  698. if (st1) StringCchCatW(str2,32,L"+");
  699. } else if (st1) StringCchCatW(str2,32,L"?");
  700. }
  701. StringCchCatW(str,64,L"/");
  702. StringCchCatW(str,64,str2);
  703. draw_pe_infostr(hdc, str);
  704. }
  705. }
  706. }
  707. static void draw_paintDC_pe(HWND hwnd, HDC hdc, RECT &r)
  708. {
  709. draw_pl(hwnd, hdc);
  710. }
  711. void draw_printclient_pe(HWND hwnd, HDC hdc, LPARAM /*drawingOptions*/)
  712. {
  713. RECT r;
  714. GetClientRect(hwnd,&r);
  715. draw_paintDC_pe(hwnd, hdc, r);
  716. draw_pl2(hwnd, hdc, r);
  717. }
  718. void draw_paint_pe(HWND hwnd)
  719. {
  720. if (!pe_init)
  721. return;
  722. PAINTSTRUCT ps;
  723. RECT r;
  724. HDC hdc=BeginPaint(hwnd,&ps);
  725. EnterCriticalSection(&g_mainwndcs);
  726. r=ps.rcPaint;
  727. draw_paintDC_pe(hwnd, hdc, r);
  728. WADrawDC windowDC(0, hwnd);
  729. draw_pl2(hwnd, windowDC, r);
  730. LeaveCriticalSection(&g_mainwndcs);
  731. EndPaint(hwnd,&ps);
  732. }