1
0

prefs_general.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include "precomp__gen_ff.h"
  2. #include "resource.h"
  3. #include <commctrl.h>
  4. #include "wa2cfgitems.h"
  5. #include "gen.h"
  6. #include "prefs.h"
  7. #include "../Agave/Language/api_language.h"
  8. #include <api/skin/skinparse.h>
  9. void turnonoff(HWND wnd, int *t, int n, int v);
  10. extern int toggle_from_wa2;
  11. extern HWND subWnd;
  12. static int auto_res = -1;
  13. static int cur_res = 10;
  14. static DWORD cur_res_last = 0;
  15. static int cur_res_total = 0;
  16. static int cur_res_num = 0;
  17. static int old_res = 0;
  18. static int dock_dist = 0;
  19. static int dock_dist2 = 0;
  20. static int spin_inc = 0;
  21. static int spin_show = 0;
  22. static int spin_hide = 0;
  23. int desktopalpha_unavail[] = {IDC_STATIC_DA1, IDC_CHECK_DESKTOPALPHA};
  24. static const wchar_t *getScrollTextSpeedW(float v)
  25. {
  26. int skipn = (int)((1.0f / v) - 1 + 0.5f);
  27. static wchar_t buf[64];
  28. ZERO(buf);
  29. switch (skipn)
  30. {
  31. case 0: return WASABI_API_LNGSTRINGW_BUF(IDS_FASTER, buf, 64);
  32. case 1: return WASABI_API_LNGSTRINGW_BUF(IDS_FAST, buf, 64);
  33. case 2: return WASABI_API_LNGSTRINGW_BUF(IDS_AVERAGE, buf, 64);
  34. case 3: return WASABI_API_LNGSTRINGW_BUF(IDS_SLOW, buf, 64);
  35. case 4: return WASABI_API_LNGSTRINGW_BUF(IDS_SLOWER, buf, 64);
  36. }
  37. return WASABI_API_LNGSTRINGW_BUF(IDS_N_A, buf, 64);
  38. }
  39. static void nextRes(HWND dlg)
  40. {
  41. if (cur_res == 250)
  42. {
  43. cfg_uioptions_timerresolution.setValueAsInt(old_res);
  44. SetDlgItemTextW(dlg, IDC_TXT, WASABI_API_LNGSTRINGW(IDS_FAILED_TO_DETECT_OPTIMAL_RESOLUTION));
  45. }
  46. else
  47. {
  48. if (cur_res >= 100)
  49. cur_res += 5;
  50. else if (cur_res >= 50)
  51. cur_res += 2;
  52. else
  53. cur_res++;
  54. SetDlgItemTextW(dlg, IDC_TXT, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_AUTO_DETECTING), cur_res));
  55. cur_res_last = Wasabi::Std::getTickCount();
  56. cur_res_total = 0;
  57. cur_res_num = 0;
  58. SetTimer(dlg, 1, cur_res, NULL);
  59. }
  60. }
  61. static INT_PTR CALLBACK autoTimerResProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  62. {
  63. switch (uMsg)
  64. {
  65. case WM_INITDIALOG:
  66. {
  67. old_res = cfg_uioptions_timerresolution.getValueAsInt();
  68. cur_res = -1;
  69. return 1;
  70. }
  71. case WM_COMMAND:
  72. switch (LOWORD(wParam))
  73. {
  74. case IDCANCEL:
  75. cfg_uioptions_timerresolution.setValueAsInt(old_res);
  76. EndDialog(hwndDlg, 0);
  77. return 0;
  78. case IDOK:
  79. if (cur_res == -1)
  80. {
  81. cfg_uioptions_timerresolution.setValueAsInt(250);
  82. EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
  83. SetDlgItemTextW(hwndDlg, IDC_TXT, WASABI_API_LNGSTRINGW(IDS_PREPARING_AUTO_DETECTION));
  84. SetTimer(hwndDlg, 2, 1000, NULL);
  85. }
  86. else EndDialog(hwndDlg, IDOK);
  87. return 0;
  88. }
  89. break;
  90. case WM_TIMER:
  91. {
  92. if (wParam == 1)
  93. {
  94. DWORD now = Wasabi::Std::getTickCount();
  95. cur_res_total += now - cur_res_last;
  96. cur_res_num++;
  97. cur_res_last = now;
  98. int m = 5;
  99. if (cur_res >= 100) m = 2;
  100. else if (cur_res >= 50) m = 3;
  101. if (cur_res_num == m)
  102. {
  103. float average = (float)cur_res_total / (float)m;
  104. if (average <= (float)cur_res*1.1)
  105. {
  106. auto_res = cur_res;
  107. cfg_uioptions_timerresolution.setValueAsInt(old_res);
  108. SetDlgItemTextW(hwndDlg, IDC_TXT, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_AUTO_DETECTION_SUCCESSFUL), cur_res));
  109. SetDlgItemTextW(hwndDlg, IDOK, WASABI_API_LNGSTRINGW(IDS_ACCEPT));
  110. EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
  111. }
  112. else
  113. {
  114. nextRes(hwndDlg);
  115. }
  116. }
  117. return 0;
  118. }
  119. else if (wParam == 2)
  120. {
  121. KillTimer(hwndDlg, 2);
  122. cur_res = 9;
  123. nextRes(hwndDlg);
  124. return 0;
  125. }
  126. break;
  127. }
  128. }
  129. return FALSE;
  130. }
  131. static void autoTimerRes(HWND dlg)
  132. {
  133. INT_PTR r = WASABI_API_DIALOGBOXW(IDD_AUTOTIMERRES, dlg, autoTimerResProc);
  134. if (r == IDOK)
  135. {
  136. cfg_uioptions_timerresolution.setValueAsInt(auto_res);
  137. SendMessageW(GetDlgItem(dlg, IDC_SLIDER_TIMERRESOLUTION), TBM_SETPOS, 1, auto_res);
  138. SetDlgItemTextW(dlg, IDC_STATIC_TIMERRES, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_TIMERS_RESOLUTION), auto_res));
  139. }
  140. }
  141. INT_PTR CALLBACK ffPrefsProc1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  142. {
  143. switch (uMsg)
  144. {
  145. case WM_INITDIALOG:
  146. {
  147. dock_dist = dock_dist2 = spin_inc = spin_show = spin_hide = 0;
  148. CheckDlgButton(hwndDlg, IDC_CHECK_DESKTOPALPHA, cfg_uioptions_desktopalpha.getValueAsInt());
  149. if (!Wasabi::Std::Wnd::isDesktopAlphaAvailable()) turnonoff(hwndDlg, desktopalpha_unavail, sizeof(desktopalpha_unavail)/sizeof(int), 0);
  150. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TIMERRESOLUTION), TBM_SETRANGEMAX, 0, 250);
  151. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TIMERRESOLUTION), TBM_SETRANGEMIN, 0, 10);
  152. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TIMERRESOLUTION), TBM_SETPOS, 1, cfg_uioptions_timerresolution.getValueAsInt());
  153. SetDlgItemTextW(hwndDlg, IDC_STATIC_TIMERRES, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_TIMERS_RESOLUTION), cfg_uioptions_timerresolution.getValueAsInt()));
  154. CheckDlgButton(hwndDlg, IDC_CHECK_TOOLTIPS, cfg_uioptions_tooltips.getValueAsInt());
  155. CheckDlgButton(hwndDlg, IDC_CHECK_DOCKING, cfg_options_docking.getValueAsInt());
  156. CheckDlgButton(hwndDlg, IDC_CHECK_DOCKING2, cfg_options_appbarondrag.getValueAsInt());
  157. SendMessageW(GetDlgItem(hwndDlg,IDC_SPIN_DOCKDISTANCE),UDM_SETRANGE,0,MAKELONG(1000,0));
  158. SetDlgItemInt(hwndDlg, IDC_EDIT_DOCKDISTANCE, cfg_options_dockingdistance.getValueAsInt(), 0);
  159. SendMessageW(GetDlgItem(hwndDlg,IDC_SPIN_DOCKDISTANCE2),UDM_SETRANGE,0,MAKELONG(1000,0));
  160. SetDlgItemInt(hwndDlg, IDC_EDIT_DOCKDISTANCE2, cfg_options_appbardockingdistance.getValueAsInt(), 0);
  161. SetDlgItemTextA(hwndDlg, IDC_EDIT_INCREMENT, StringPrintf("%d", cfg_uioptions_textincrement.getValueAsInt()));
  162. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TICKERSPEED), TBM_SETRANGEMAX, 0, 4);
  163. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TICKERSPEED), TBM_SETRANGEMIN, 0, 0);
  164. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_TICKERSPEED), TBM_SETPOS, 1, (int)(1.0f / cfg_uioptions_textspeed.getValueAsDouble() - 1.0f + 0.5f));
  165. SetDlgItemTextW(hwndDlg, IDC_STATIC_TICKER, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_TEXT_SCROLL_SPEED), getScrollTextSpeedW((float)cfg_uioptions_textspeed.getValueAsDouble())));
  166. SendMessageW(GetDlgItem(hwndDlg,IDC_SPIN_SHOWTIME),UDM_SETRANGE,0,MAKELONG(9999,0));
  167. SetDlgItemInt(hwndDlg, IDC_EDIT_SHOWTIME, cfg_uioptions_appbarsshowtime.getValueAsInt(), 0);
  168. SendMessageW(GetDlgItem(hwndDlg,IDC_SPIN_HIDETIME),UDM_SETRANGE,0,MAKELONG(9999,0));
  169. SetDlgItemInt(hwndDlg, IDC_EDIT_HIDETIME, cfg_uioptions_appbarshidetime.getValueAsInt(), 0);
  170. dock_dist = dock_dist2 = spin_inc = spin_show = spin_hide = 1;
  171. return 1;
  172. }
  173. case WM_COMMAND:
  174. toggle_from_wa2 = 1;
  175. switch (LOWORD(wParam))
  176. {
  177. case IDC_CHECK_DESKTOPALPHA:
  178. cfg_uioptions_desktopalpha.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_DESKTOPALPHA));
  179. return 0;
  180. case IDC_BUTTON_AUTOTIMERRES:
  181. autoTimerRes(hwndDlg);
  182. return 0;
  183. case IDC_CHECK_TOOLTIPS:
  184. cfg_uioptions_tooltips.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_TOOLTIPS));
  185. return 0;
  186. case IDC_CHECK_DOCKING:
  187. cfg_options_docking.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_DOCKING));
  188. return 0;
  189. case IDC_CHECK_DOCKING2:
  190. cfg_options_appbarondrag.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_DOCKING2));
  191. return 0;
  192. case IDC_EDIT_DOCKDISTANCE:
  193. if (HIWORD(wParam) == EN_CHANGE && dock_dist)
  194. {
  195. int t, a = GetDlgItemInt(hwndDlg, IDC_EDIT_DOCKDISTANCE, &t, 0);
  196. if (t) cfg_options_dockingdistance.setValueAsInt(a);
  197. }
  198. return 0;
  199. case IDC_EDIT_DOCKDISTANCE2:
  200. if (HIWORD(wParam) == EN_CHANGE && dock_dist2)
  201. {
  202. int t, a = GetDlgItemInt(hwndDlg, IDC_EDIT_DOCKDISTANCE2, &t, 0);
  203. if (t) cfg_options_appbardockingdistance.setValueAsInt(a);
  204. }
  205. return 0;
  206. case IDC_EDIT_INCREMENT:
  207. if (HIWORD(wParam) == EN_CHANGE && spin_inc)
  208. {
  209. int t, a = GetDlgItemInt(hwndDlg, IDC_EDIT_INCREMENT, &t, 0);
  210. if (t) cfg_uioptions_textincrement.setValueAsInt(a);
  211. }
  212. return 0;
  213. case IDC_EDIT_SHOWTIME:
  214. if (HIWORD(wParam) == EN_CHANGE && spin_show)
  215. {
  216. int t, a = GetDlgItemInt(hwndDlg, IDC_EDIT_SHOWTIME, &t, 0);
  217. if (t) cfg_uioptions_appbarsshowtime.setValueAsInt(a);
  218. }
  219. return 0;
  220. case IDC_EDIT_HIDETIME:
  221. if (HIWORD(wParam) == EN_CHANGE && spin_hide)
  222. {
  223. int t, a = GetDlgItemInt(hwndDlg, IDC_EDIT_HIDETIME, &t, 0);
  224. if (t) cfg_uioptions_appbarshidetime.setValueAsInt(a);
  225. }
  226. return 0;
  227. }
  228. toggle_from_wa2 = 0;
  229. break;
  230. case WM_HSCROLL:
  231. {
  232. int t = (int)SendMessageW((HWND) lParam, TBM_GETPOS, 0, 0);
  233. HWND ctrl = (HWND) lParam;
  234. if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_TIMERRESOLUTION))
  235. {
  236. cfg_uioptions_timerresolution.setValueAsInt(t);
  237. SetDlgItemTextW(hwndDlg, IDC_STATIC_TIMERRES, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_TIMERS_RESOLUTION), cfg_uioptions_timerresolution.getValueAsInt()));
  238. }
  239. else if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_TICKERSPEED))
  240. {
  241. cfg_uioptions_textspeed.setValueAsDouble(1.0 / (float)(t + 1));
  242. SetDlgItemTextW(hwndDlg, IDC_STATIC_TICKER, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_TEXT_SCROLL_SPEED), getScrollTextSpeedW((float)cfg_uioptions_textspeed.getValueAsDouble())));
  243. }
  244. break;
  245. }
  246. case WM_DESTROY:
  247. subWnd = NULL;
  248. dock_dist = dock_dist2 = spin_inc = spin_show = spin_hide = 0;
  249. return 0;
  250. }
  251. const int controls[] =
  252. {
  253. IDC_SLIDER_TIMERRESOLUTION,
  254. IDC_SLIDER_TICKERSPEED,
  255. };
  256. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  257. return TRUE;
  258. return 0;
  259. }