1
0

draw_eq.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 "plush/plush.h"
  11. #include "WinampAttributes.h"
  12. #include "resource.h"
  13. #include "WADrawDC.h"
  14. HDC eqMainDC, eqMainDC2;
  15. int enable_eq_windowshade_button;
  16. HBITMAP eqMainBM = NULL, eqMainBM2 = NULL, eqExBM = NULL, eqOldmainBM2 = NULL, eqOldmainBM = NULL;
  17. extern "C" int eq_init = 0;
  18. void draw_eq_init()
  19. {
  20. EnterCriticalSection(&g_srcdccs);
  21. if (eq_init)
  22. draw_eq_kill();
  23. eq_init=1;
  24. HDC screenHdc = draw_GetWindowDC(hMainWindow);
  25. eqMainDC = CreateCompatibleDC(screenHdc);
  26. eqMainDC2 = CreateCompatibleDC(screenHdc);
  27. enable_eq_windowshade_button = 2;
  28. // attempt to use the ISO eq image (if present)
  29. if(config_eq_frequencies!=EQ_FREQUENCIES_WINAMP)
  30. eqMainBM = draw_LBitmap(NULL, L"eqmain_iso.bmp");
  31. // otherwise we revert to the normal eq image
  32. if (!eqMainBM)
  33. eqMainBM = draw_LBitmap(NULL, L"eqmain.bmp");
  34. if (eqMainBM)
  35. enable_eq_windowshade_button = 0;
  36. // and if that fails then we revert to the built in classic skin resources
  37. else
  38. eqMainBM = draw_LBitmap(MAKEINTRESOURCE((config_eq_frequencies==EQ_FREQUENCIES_WINAMP)?IDB_EQMAIN:IDB_EQMAIN_ISO), NULL);
  39. eqOldmainBM = (HBITMAP)SelectObject(eqMainDC, eqMainBM);
  40. eqExBM = draw_LBitmap(NULL, L"eq_ex.bmp");
  41. if (!eqExBM)
  42. {
  43. if (!skin_directory[0])
  44. enable_eq_windowshade_button = 1;
  45. eqExBM = draw_LBitmap(MAKEINTRESOURCE(IDB_EQEX), NULL);
  46. }
  47. else
  48. enable_eq_windowshade_button = 1;
  49. draw_ReleaseDC(hMainWindow, screenHdc);
  50. int x;
  51. draw_eq_slid(0,config_preamp,0);
  52. for (x = 1; x <= 10; x ++)
  53. draw_eq_slid(x,eq_tab[x-1],0);
  54. draw_eq_graphthingy();
  55. draw_eq_onauto(config_use_eq, config_autoload_eq, 0,0);
  56. draw_eq_tbar(GetForegroundWindow()==hEQWindow?1:(config_hilite?0:1));
  57. draw_eq_presets(0);
  58. LeaveCriticalSection(&g_srcdccs);
  59. }
  60. void draw_eq_kill()
  61. {
  62. if (!eq_init)
  63. return ;
  64. EnterCriticalSection(&g_srcdccs);
  65. SelectObject(eqMainDC, eqOldmainBM);
  66. DeleteObject(eqMainBM);
  67. eqMainBM = NULL;
  68. if (eqMainBM2)
  69. {
  70. SelectObject(eqMainDC2, eqOldmainBM2);
  71. DeleteObject(eqMainBM2);
  72. eqMainBM2 = NULL;
  73. }
  74. DeleteDC(eqMainDC);
  75. DeleteDC(eqMainDC2);
  76. if (eqExBM)
  77. DeleteObject(eqExBM);
  78. eqExBM=NULL;
  79. LeaveCriticalSection(&g_srcdccs);
  80. }
  81. static void update_area_eq(int x1, int y1, int w, int h)
  82. {
  83. if (updateen && hEQWindow)
  84. {
  85. WADrawDC tDC(hEQWindow);
  86. if (tDC && hEQWindow)
  87. {
  88. do_palmode(tDC);
  89. if (!(config_dsize && config_eqdsize))
  90. {
  91. BitBlt(tDC, x1, y1, w, h, eqMainDC, x1, y1, SRCCOPY);
  92. if (eqMainBM2)
  93. {
  94. SelectObject(eqMainDC2, eqOldmainBM2);
  95. DeleteObject(eqMainBM2);
  96. eqMainBM2 = NULL;
  97. }
  98. }
  99. else
  100. {
  101. if (!eqMainBM2)
  102. {
  103. eqMainBM2 = CreateCompatibleBitmap(mainDC, WINDOW_WIDTH * 2, WINDOW_HEIGHT * 2);
  104. eqOldmainBM2 = (HBITMAP)SelectObject(eqMainDC2, eqMainBM2);
  105. x1 = y1 = 0;
  106. w = WINDOW_WIDTH;
  107. h = WINDOW_HEIGHT;
  108. }
  109. StretchBlt(eqMainDC2, x1*2, y1*2, w*2, h*2, eqMainDC, x1, y1, w, h, SRCCOPY);
  110. BitBlt(tDC, x1*2, y1*2, w*2, h*2, eqMainDC2, x1*2, y1*2, SRCCOPY);
  111. }
  112. }
  113. }
  114. }
  115. void draw_eq_presets(int pressed)
  116. {
  117. int top = 18, left = 217;
  118. int w = 44;
  119. int h = 12;
  120. BitBlt(eqMainDC, left, top, w, h, eqMainDC, 224, pressed ? 176 : 164, SRCCOPY);
  121. update_area_eq(left, top, w, h);
  122. }
  123. void draw_eq_tbar(int active)
  124. {
  125. int l = active ? 134 : 149;
  126. if (!eq_init) return ;
  127. if (config_eq_ws)
  128. {
  129. int xo = 63;
  130. int p = 94;
  131. int r;
  132. int xx = config_volume * 3 / 256;
  133. setSrcBM(eqExBM);
  134. BitBlt(eqMainDC, 0, 0, WINDOW_WIDTH, 14, bmDC, 0, active ? 0 : 15, SRCCOPY);
  135. r = xo + (p * config_volume) / 255;
  136. BitBlt(eqMainDC, r - 2, 4, 3, 7, bmDC, xx*3 + 1, 30, SRCCOPY);
  137. r = 166 + (39 * (config_pan + 128)) / 255;
  138. xx = (config_pan + 128) * 3 / 256;
  139. BitBlt(eqMainDC, r - 2, 4, 3, 7, bmDC, xx*3 + 11, 30, SRCCOPY);
  140. unsetSrcBM();
  141. }
  142. else
  143. {
  144. BitBlt(eqMainDC, 0, 0, WINDOW_WIDTH, 14, eqMainDC, 0, l, SRCCOPY);
  145. }
  146. update_area_eq(0, 0, WINDOW_WIDTH, 14);
  147. }
  148. void draw_eq_slid(int which, int pos, int pressed) // left to right, 0-64
  149. {
  150. int top = 38, h = 63;
  151. int num_pos = 63 - 11;
  152. int w = 14;
  153. int xp;
  154. int n = 0;
  155. if (!which)
  156. xp = 21;
  157. else xp = 78 + (96 - 78) * (which - 1);
  158. if (!eq_init) return ;
  159. n = 27 - ((pos * 28) / 64);
  160. if (n < 14)
  161. BitBlt(eqMainDC, xp, top, w, h, eqMainDC, 13 + n*15, 164, SRCCOPY);
  162. else
  163. BitBlt(eqMainDC, xp, top, w, h, eqMainDC, 13 + (n - 14)*15, 229, SRCCOPY);
  164. BitBlt(eqMainDC, xp + 1, top + h - 12 - ((63 - pos)*num_pos) / 64, 11, 11, eqMainDC, 0, pressed ? 176 : 164, SRCCOPY);
  165. update_area_eq(xp, top, w, h);
  166. }
  167. void draw_eq_onauto(int on, int autoon, int onpressed, int autopressed)
  168. {
  169. int top = 18, left = 14;
  170. int w1 = 25, w2 = 33;
  171. int h = 12;
  172. BitBlt(eqMainDC, left, top, w1, h, eqMainDC, 10 + (onpressed ? 118 : 0) + (on ? 59 : 0), 119, SRCCOPY);
  173. BitBlt(eqMainDC, left + w1, top, w2, h, eqMainDC, 35 + (autopressed ? 118 : 0) + (autoon ? 59 : 0), 119, SRCCOPY);
  174. update_area_eq(left, top, w1 + w2, h);
  175. }
  176. void draw_eq_graphthingy()
  177. {
  178. int top = 17, left = 86;
  179. int src_top = 294;
  180. int w = 113, h = 19;
  181. float keys[12] = {0};
  182. pl_Spline spline = {keys, 1, 12, 0.0f, 0.0f, 0.1f};
  183. BitBlt(eqMainDC, left, top, w, h, eqMainDC, 0, src_top, SRCCOPY);
  184. BitBlt(eqMainDC, left, top - 1 + h - (int)(config_preamp*19.0f / 64.0f), w, 1, eqMainDC, 0, 314, SRCCOPY);
  185. {
  186. int x;
  187. int last_p = -1;
  188. for (x = 0; x < 10; x ++)
  189. keys[x + 1] = eq_tab[x] * 19.0f / 64.0f;
  190. keys[0] = keys[1];
  191. keys[11] = keys[10];
  192. for (x = 0; x < 109; x ++)
  193. {
  194. float p;
  195. int this_p;
  196. int lin_offs = 115;
  197. plSplineGetPoint(&spline, 1.0f + x / 12.0f, &p);
  198. this_p = (int)p;
  199. if (this_p < 0) this_p = 0;
  200. if (this_p > 18) this_p = 18;
  201. if (last_p == -1 || this_p == last_p)
  202. BitBlt(eqMainDC, left + 2 + x, top + this_p, 1, 1, eqMainDC, lin_offs, src_top + this_p, SRCCOPY);
  203. else
  204. {
  205. if (this_p < last_p)
  206. BitBlt(eqMainDC, left + 2 + x, top + this_p, 1, last_p - this_p + 1, eqMainDC, lin_offs, src_top + this_p, SRCCOPY);
  207. else if (this_p > last_p)
  208. BitBlt(eqMainDC, left + 2 + x, top + last_p, 1, this_p - last_p + 1, eqMainDC, lin_offs, src_top + last_p, SRCCOPY);
  209. }
  210. last_p = this_p;
  211. }
  212. }
  213. update_area_eq(left, top, w, h);
  214. }
  215. void draw_eq_tbutton(int b3, int wsb)
  216. {
  217. setSrcBM(eqExBM);
  218. if (config_eq_ws)
  219. {
  220. if (wsb)
  221. BitBlt(eqMainDC, 254, 3, 9, 9, bmDC, 1, 47, SRCCOPY);
  222. else
  223. BitBlt(eqMainDC, 254, 3, 9, 9, bmDC, 254, 3, SRCCOPY);
  224. BitBlt(eqMainDC, 264, 3, 9, 9, bmDC, 11, 38 + b3*9, SRCCOPY);
  225. }
  226. else
  227. {
  228. if (wsb && enable_eq_windowshade_button)
  229. BitBlt(eqMainDC, 254, 3, 9, 9, bmDC, 1, 38, SRCCOPY);
  230. else
  231. BitBlt(eqMainDC, 254, 3, 9, 9, eqMainDC, 254, 137, SRCCOPY);
  232. BitBlt(eqMainDC, 264, 3, 9, 9, eqMainDC, 0, 116 + b3*9, SRCCOPY);
  233. }
  234. unsetSrcBM();
  235. update_area_eq(253, 3, 20, 9);
  236. }
  237. static void draw_paintDC_eq(HDC screenHdc, const RECT &r)
  238. {
  239. int dsize = (config_dsize && config_eqdsize);
  240. do_palmode(screenHdc);
  241. if (!dsize)
  242. {
  243. BitBlt(screenHdc, r.left, r.top, r.right - r.left, r.bottom - r.top, eqMainDC, r.left, r.top, SRCCOPY);
  244. if (eqMainBM2)
  245. {
  246. SelectObject(eqMainDC2, eqOldmainBM2);
  247. DeleteObject(eqMainBM2);
  248. eqMainBM2 = NULL;
  249. }
  250. }
  251. else
  252. {
  253. if (!eqMainBM2)
  254. {
  255. eqMainBM2 = CreateCompatibleBitmap(mainDC, WINDOW_WIDTH * 2, WINDOW_HEIGHT * 2);
  256. eqOldmainBM2 = (HBITMAP)SelectObject(eqMainDC2, eqMainBM2);
  257. StretchBlt(eqMainDC2, 0, 0, WINDOW_WIDTH*2, WINDOW_HEIGHT*2, eqMainDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, SRCCOPY);
  258. }
  259. BitBlt(screenHdc, r.left, r.top, r.right - r.left, r.bottom - r.top, eqMainDC2, r.left, r.top, SRCCOPY);
  260. }
  261. }
  262. void draw_printclient_eq(HDC hdc, LPARAM /*drawingOptions*/)
  263. {
  264. RECT r;
  265. GetClientRect(hEQWindow,&r);
  266. draw_paintDC_eq(hdc, r);
  267. }
  268. void draw_paint_eq(HWND hwnd)
  269. {
  270. if (hwnd || hEQWindow)
  271. {
  272. HDC screenHdc;
  273. PAINTSTRUCT ps;
  274. RECT r;
  275. if (!eq_init) return ;
  276. if (hwnd)
  277. {
  278. GetUpdateRect(hwnd, &ps.rcPaint, 0);
  279. EnterCriticalSection(&g_mainwndcs);
  280. screenHdc = BeginPaint(hwnd, &ps);
  281. memcpy(&r, &ps.rcPaint, sizeof(r));
  282. }
  283. else
  284. {
  285. screenHdc = draw_GetWindowDC(hEQWindow);
  286. GetClientRect(hEQWindow, &r);
  287. }
  288. draw_paintDC_eq(screenHdc, r);
  289. if (hwnd)
  290. {
  291. EndPaint(hwnd, &ps);
  292. LeaveCriticalSection(&g_mainwndcs);
  293. }
  294. else
  295. draw_ReleaseDC(hEQWindow, screenHdc);
  296. }
  297. }