Equi.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. #include "Main.h"
  2. #include "WinampAttributes.h"
  3. #include "resource.h"
  4. #define inreg(x,y,x2,y2) \
  5. ((mouse_x <= ( x2 ) && mouse_x >= ( x ) && \
  6. mouse_y <= ( y2 ) && mouse_y >= ( y )))
  7. static int mouse_x, mouse_y, mouse_type, mouse_stats;
  8. static int which_cap=0;
  9. enum { NO_CAP,TITLE_CAP,TB_CAP,QB_CAP,TOGBUTS_CAP,PB_CAP, PAN_CAP,VOL_CAP, SLID_CAP=100 };
  10. static void do_titlebar();
  11. static void do_titlebuttons();
  12. static void do_quickbuts();
  13. static void do_sliders(int which);
  14. static void do_togbuts();
  15. static void do_volctrl();
  16. static void do_panctrl();
  17. static void do_presetbutton();
  18. void equi_handlemouseevent(int x, int y, int type, int stats)
  19. {
  20. mouse_x = x;
  21. mouse_y = y;
  22. mouse_type = type;
  23. mouse_stats = stats;
  24. switch (which_cap)
  25. {
  26. case PAN_CAP:
  27. do_panctrl();
  28. return;
  29. case VOL_CAP:
  30. do_volctrl();
  31. return;
  32. case PB_CAP:
  33. do_presetbutton();
  34. return;
  35. case TOGBUTS_CAP:
  36. do_togbuts();
  37. return;
  38. case TITLE_CAP:
  39. do_titlebar();
  40. return;
  41. case TB_CAP:
  42. do_titlebuttons();
  43. return;
  44. case QB_CAP:
  45. do_quickbuts();
  46. return;
  47. default:
  48. if (which_cap >= SLID_CAP)
  49. {
  50. do_sliders(which_cap-SLID_CAP);
  51. return;
  52. }
  53. }
  54. if (config_eq_ws)
  55. {
  56. do_volctrl();
  57. do_panctrl();
  58. }
  59. else
  60. {
  61. for (x = 0; x < 11; x ++)
  62. do_sliders(x);
  63. }
  64. do_titlebuttons();
  65. do_quickbuts();
  66. do_togbuts();
  67. do_presetbutton();
  68. do_titlebar();
  69. }
  70. static void do_volctrl()
  71. {
  72. extern int do_volbar_active;
  73. if (inreg(61,3,162,11) || which_cap==VOL_CAP)
  74. {
  75. if (mouse_type == 1 && !which_cap) which_cap=VOL_CAP;
  76. if (which_cap==VOL_CAP && mouse_stats & MK_LBUTTON)
  77. {
  78. int t=mouse_x-61;
  79. if (t < 0) t=0;
  80. if (t > 157-61) t=157-61;
  81. config_volume=(t*255)/(157-61);
  82. in_setvol(config_volume);
  83. draw_volumebar(config_volume,0);
  84. update_volume_text(-1);
  85. do_volbar_active=1;
  86. }
  87. if (mouse_type == -1 && which_cap == VOL_CAP)
  88. {
  89. which_cap=0;
  90. do_volbar_active=0;
  91. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  92. }
  93. }
  94. else if (which_cap==VOL_CAP)
  95. {
  96. which_cap=0;
  97. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  98. do_volbar_active=0;
  99. }
  100. }
  101. static void do_panctrl()
  102. {
  103. extern int do_volbar_active;
  104. if (inreg(163,3,206,11) || which_cap==PAN_CAP)
  105. {
  106. if (mouse_type == 1 && !which_cap) which_cap=PAN_CAP;
  107. if (which_cap==PAN_CAP && mouse_stats & MK_LBUTTON)
  108. {
  109. int t=mouse_x-164;
  110. if (t < 0) t=0;
  111. if (t > 206-164) t=206-164;
  112. int p = (t*255)/(206-164)-127;
  113. config_pan = (p > 127 ? 127 : p);
  114. // changed in 5.64 to have a lower limit (~18% vs 9%) and for
  115. // holding shift to drop the central clamp (allows 4% balance)
  116. // and the above change fixes the balance to be even going +/-
  117. if (!(mouse_stats & MK_SHIFT)) if (config_pan < 9 && config_pan > -9) config_pan=0;
  118. in_setpan(config_pan);
  119. draw_panbar(config_pan,0);
  120. update_panning_text(-1);
  121. do_volbar_active=1;
  122. }
  123. if (mouse_type == -1 && which_cap == PAN_CAP)
  124. {
  125. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  126. do_volbar_active=0;
  127. which_cap=0;
  128. }
  129. }
  130. else if (which_cap==PAN_CAP)
  131. {
  132. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  133. do_volbar_active=0;
  134. which_cap=0;
  135. }
  136. }
  137. static void do_presetbutton()
  138. {
  139. if (inreg(217,18,217+44,18+12))
  140. {
  141. if (!which_cap && mouse_stats & MK_LBUTTON)
  142. {
  143. draw_eq_presets(1);
  144. which_cap = PB_CAP;
  145. }
  146. if (mouse_type == -1 && which_cap == PB_CAP)
  147. {
  148. draw_eq_presets(0);
  149. which_cap=0;
  150. SendMessageW(hEQWindow,WM_COMMAND,EQ_PRESETS,0);
  151. }
  152. } else if (which_cap == PB_CAP)
  153. {
  154. which_cap=0;
  155. draw_eq_presets(0);
  156. }
  157. }
  158. static void do_togbuts()
  159. {
  160. if (inreg(14,18,14+25+33,18+12))
  161. {
  162. int w=mouse_x >= 14+25 ? 1 : 0;
  163. if (mouse_type == -1)
  164. {
  165. if (w)
  166. {
  167. config_autoload_eq=!config_autoload_eq;
  168. }
  169. else
  170. {
  171. config_use_eq=!config_use_eq;
  172. }
  173. eq_set(config_use_eq, (char*)eq_tab,config_preamp);
  174. draw_eq_onauto(config_use_eq, config_autoload_eq, 0,0);
  175. PostMessageW(hMainWindow,WM_WA_IPC,IPC_CB_MISC_EQ,IPC_CB_MISC);
  176. }
  177. else if (mouse_stats & MK_LBUTTON)
  178. {
  179. which_cap = TOGBUTS_CAP;
  180. draw_eq_onauto(config_use_eq, config_autoload_eq, w?0:1,w?1:0);
  181. }
  182. } else if (which_cap == TOGBUTS_CAP)
  183. {
  184. which_cap=0;
  185. draw_eq_onauto(config_use_eq, config_autoload_eq, 0,0);
  186. }
  187. }
  188. static void do_sliders(int which)
  189. {
  190. int top=39,bottom=98;
  191. int xoffs,w=33-21;
  192. if (!which) xoffs=21;
  193. else xoffs=78+(which-1)*(96-78);
  194. if (which_cap == SLID_CAP+which || inreg(xoffs,top,xoffs+w,bottom))
  195. {
  196. unsigned char *b = (which?eq_tab+which-1:&config_preamp);
  197. if (mouse_type == 1 || which_cap == SLID_CAP+which || (!which_cap && mouse_stats & MK_LBUTTON))
  198. {
  199. static int click_yoffs=5;
  200. int num_pos=63-11;
  201. int d;
  202. int p;
  203. int t= (mouse_type == -1 || (!(mouse_x >= xoffs-3 && mouse_x <= xoffs+w+3) && (mouse_y >= top && mouse_y <= bottom && mouse_x >= 78 && mouse_x <= 180+78) && which));
  204. p=63-12-((63-*b)*num_pos)/64;
  205. if (mouse_type == 1 && mouse_y-top >= p-1 && mouse_y-top < p + 11)
  206. {
  207. click_yoffs=mouse_y-top - p;
  208. } else if (mouse_type == 1)
  209. click_yoffs=5;
  210. d=((mouse_y-click_yoffs-top)*64)/num_pos;
  211. if (d < 0) d = 0;
  212. if (d > 63) d = 63;
  213. // changed in 5.66 for holding shift to drop the central clamp (allows 7% balance)
  214. if (!(mouse_stats & MK_SHIFT)) if (d >= 30 && d <= 32) d=31;
  215. *b = d;
  216. draw_eq_slid(which,*b,t? 0 : 1);
  217. draw_eq_graphthingy();
  218. if (t)
  219. {
  220. do_posbar_active=0;
  221. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  222. which_cap=0;
  223. } else
  224. {
  225. wchar_t buf[128] = {0};
  226. float v=(float)d;
  227. static wchar_t preampStr[64];
  228. static wchar_t *bands[11] =
  229. {
  230. preampStr, // PREAMP
  231. L"70",L"180",L"320",L"600", // Hz
  232. L"1",L"3",L"6",L"12",L"14",L"16" // KHz
  233. };
  234. static wchar_t *bandsISO[11] =
  235. {
  236. preampStr, // PREAMP
  237. L"31.5",L"63",L"125",L"250", // Hz
  238. L"500",L"1",L"2",L"4",L"8",L"16" // KHz
  239. };
  240. getStringW(IDS_PREAMP,preampStr,64);
  241. v -= 31.5f;
  242. v /= 31.5f;
  243. v *= -12.0f;
  244. if (v >= -0.32 && v <= 0.32) v=0.0;
  245. wchar_t HZStr[16] = {0};
  246. getStringW((which<5+!(config_eq_frequencies==EQ_FREQUENCIES_WINAMP)?IDS_EQ_HZ:IDS_EQ_KHZ),HZStr,16);
  247. StringCchPrintfW(buf,128,L"EQ: %s%s: %s%0.01f %s",
  248. ((config_eq_frequencies==EQ_FREQUENCIES_WINAMP)?bands[which]:bandsISO[which]),
  249. (!which?L"":HZStr),
  250. v>=0.0?L"+":L"", v,
  251. getStringW(IDS_EQ_DB,NULL,0));
  252. d=0;
  253. do_posbar_active=1;
  254. draw_songname(buf,&d,-1);
  255. which_cap = SLID_CAP+which;
  256. }
  257. eq_set(config_use_eq, (char*)eq_tab,config_preamp);
  258. PostMessageW(hMainWindow,WM_WA_IPC,IPC_CB_MISC_EQ,IPC_CB_MISC);
  259. }
  260. }
  261. }
  262. static void do_quickbuts()
  263. {
  264. int l=42, r=67;
  265. if (inreg(l,65,r,74) || inreg(l,33,r,42) || inreg(l,92,r,101)) // +0
  266. {
  267. if (mouse_type == -1 && which_cap == QB_CAP)
  268. {
  269. int v;
  270. which_cap=0;
  271. if (mouse_y <= 42) v=0;
  272. else if (mouse_y <= 74) v=31;
  273. else v=63;
  274. memset(eq_tab,v,10);
  275. {
  276. int x;
  277. for (x = 1; x <= 10; x ++)
  278. draw_eq_slid(x,eq_tab[x-1],0);
  279. }
  280. eq_set(config_use_eq, (char*)eq_tab,config_preamp);
  281. draw_eq_graphthingy();
  282. PostMessageW(hMainWindow,WM_WA_IPC,IPC_CB_MISC_EQ,IPC_CB_MISC);
  283. }
  284. else if (mouse_stats & MK_LBUTTON)
  285. {
  286. which_cap=QB_CAP;
  287. }
  288. }
  289. else if (which_cap == QB_CAP)
  290. {
  291. which_cap=0;
  292. }
  293. }
  294. static void do_titlebar()
  295. {
  296. if (which_cap == TITLE_CAP || (!which_cap && (config_easymove || mouse_y < 14)))
  297. {
  298. static int clickx, clicky;
  299. switch (mouse_type)
  300. {
  301. case 1:
  302. {
  303. which_cap=TITLE_CAP;
  304. clickx=mouse_x;
  305. clicky=mouse_y;
  306. }
  307. break;
  308. case -1:
  309. which_cap=0;
  310. break;
  311. case 0:
  312. if (which_cap == TITLE_CAP && mouse_stats & MK_LBUTTON)
  313. {
  314. POINT p = { mouse_x,mouse_y};
  315. ClientToScreen(hEQWindow,&p);
  316. config_eq_wx = p.x-clickx;
  317. config_eq_wy = p.y-clicky;
  318. if ((!!config_snap) ^ (!!(mouse_stats & MK_SHIFT)))
  319. {
  320. RECT rr;
  321. EstEQWindowRect(&rr);
  322. SnapWindowToAllWindows(&rr,hEQWindow);
  323. SetEQWindowRect(&rr);
  324. }
  325. SetWindowPos(hEQWindow,0,config_eq_wx,config_eq_wy,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  326. }
  327. break;
  328. }
  329. }
  330. }
  331. static void do_titlebuttons()
  332. {
  333. if (inreg(253,3,264+9,3+9)) // kill button
  334. {
  335. int ws;
  336. if (mouse_x < 264) ws=1;
  337. else ws=0;
  338. if (mouse_type == -1 && which_cap == TB_CAP)
  339. {
  340. which_cap=0;
  341. draw_eq_tbutton(0,0);
  342. if (ws==0) SendMessageW(hMainWindow,WM_COMMAND,WINAMP_OPTIONS_EQ,0);
  343. else SendMessageW(hMainWindow,WM_COMMAND,WINAMP_OPTIONS_WINDOWSHADE_EQ,0);
  344. }
  345. else if (mouse_stats & MK_LBUTTON)
  346. {
  347. which_cap=TB_CAP;
  348. if (ws) draw_eq_tbutton(0,1);
  349. else draw_eq_tbutton(1,0);
  350. }
  351. }
  352. else if (which_cap == TB_CAP)
  353. {
  354. which_cap=0;
  355. draw_eq_tbutton(0,0);
  356. }
  357. }
  358. void eq_ui_handlecursor(void)
  359. {
  360. int mouse_x, mouse_y;
  361. POINT p;
  362. static RECT b[] =
  363. {
  364. {264,3,272,12},//close
  365. {0,0,275,13},// titelbar
  366. };
  367. int b_len;
  368. int x;
  369. if (!config_usecursors || disable_skin_cursors) return;
  370. b_len = sizeof(b)/sizeof(b[0]);
  371. GetCursorPos(&p);
  372. ScreenToClient(hEQWindow,&p);
  373. mouse_x=p.x;
  374. mouse_y=p.y;
  375. if (config_dsize && config_eqdsize) { mouse_x/=2; mouse_y/=2;}
  376. {
  377. int y;
  378. x=1;
  379. for (y = 0; y < 11; y ++)
  380. {
  381. int top=39,bottom=98;
  382. int xoffs,w=33-21;
  383. if (!y) xoffs=21;
  384. else xoffs=78+(y-1)*(96-78);
  385. if (inreg(xoffs,top,xoffs+w,bottom))
  386. {
  387. x=0;
  388. break;
  389. }
  390. }
  391. if (x) for (x = 1; x <= b_len; x ++)
  392. if (inreg(b[x-1].left,b[x-1].top,b[x-1].right,b[x-1].bottom)) break;
  393. }
  394. x+=25;
  395. if (Skin_Cursors[x]) SetCursor(Skin_Cursors[x]);
  396. else SetCursor(LoadCursor(NULL,IDC_ARROW));
  397. }