prefs_alpha.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #include "precomp__gen_ff.h"
  2. #include "resource.h"
  3. #include "prefs.h"
  4. #include "wa2cfgitems.h"
  5. #include <bfc/wasabi_std_wnd.h>
  6. #include "../Agave/Language/api_language.h"
  7. #include <api/skin/skinparse.h>
  8. #include <commctrl.h>
  9. void turnonoff(HWND wnd, int *t, int n, int v);
  10. extern int toggle_from_wa2;
  11. int opacity_all_on[] = {IDC_SLIDER_CUSTOMALPHA, IDC_STATIC_TRANSP, IDC_STATIC_ALPHA, IDC_STATIC_OPAQUE, IDC_COMBO_OPACITY};
  12. int opacity_all_off[] = {IDC_CHECK_LINKALPHA, };
  13. int opacity_unavail[] = {IDC_STATIC_OPACITY, IDC_CHECK_LINKALLALPHA, IDC_COMBO_OPACITY, IDC_SLIDER_CUSTOMALPHA,
  14. IDC_STATIC_TRANSP,IDC_STATIC_ALPHA,IDC_STATIC_OPAQUE,IDC_CHECK_LINKALPHA,IDC_STATIC_AUTOON,
  15. IDC_STATIC_AUTOONTXT,IDC_STATIC_FADEIN2,IDC_SLIDER_FADEIN,IDC_STATIC_FADEIN,IDC_STATIC_HOLD2,
  16. IDC_SLIDER_HOLD,IDC_STATIC_HOLD,IDC_STATIC_FADEOUT2,IDC_SLIDER_FADEOUT,IDC_STATIC_FADEOUT,
  17. IDC_STATIC_EXTENDBOX,IDC_EDIT_EXTEND,IDC_STATIC_EXTEND,IDC_SPIN_EXTEND};
  18. static int ratio_all_on[] = {IDC_SLIDER_CUSTOMSCALE, IDC_COMBO_SCALE, IDC_STATIC_SCALE};
  19. static int ratio_all_off[] = {IDC_CHECK_LINKRATIO, };
  20. static int spin_extend = 0;
  21. static UINT get_logslider(HWND wnd) {
  22. int z = SendMessageW(wnd, TBM_GETPOS, 0, 0);
  23. long a = (long)(0.5 + 303.03 * pow(100.0, (double)z/30303.0) - 303.03);
  24. return a;
  25. }
  26. void set_logslider(HWND wnd, int b) {
  27. long a = (long) (0.5 + 30303.0 * log((double)(b+303.0)/303.03)/log(100.0));
  28. SendMessageW(wnd, TBM_SETPOS, 1, a);
  29. }
  30. int ResizeComboBoxDropDown(HWND hwndDlg, UINT id, const wchar_t * str, int width) {
  31. SIZE size = {0};
  32. HWND control = (id ? GetDlgItem(hwndDlg, id) : hwndDlg);
  33. HDC hdc = GetDC(control);
  34. // get and select parent dialog's font so that it'll calculate things correctly
  35. HFONT font = (HFONT)SendMessageW((id ? hwndDlg : GetParent(hwndDlg)), WM_GETFONT, 0, 0),
  36. oldfont = (HFONT)SelectObject(hdc, font);
  37. GetTextExtentPoint32W(hdc, str, lstrlenW(str)+1, &size);
  38. int ret = width;
  39. if(size.cx > width)
  40. {
  41. if (id)
  42. SendDlgItemMessageW(hwndDlg, id, CB_SETDROPPEDWIDTH, size.cx, 0);
  43. else
  44. SendMessageW(hwndDlg, CB_SETDROPPEDWIDTH, size.cx, 0);
  45. ret = size.cx;
  46. }
  47. SelectObject(hdc, oldfont);
  48. ReleaseDC(control, hdc);
  49. return ret;
  50. }
  51. INT_PTR CALLBACK ffPrefsProc4(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  52. switch (uMsg) {
  53. case WM_INITDIALOG:
  54. {
  55. spin_extend = 0;
  56. int transpavail = Wasabi::Std::Wnd::isTransparencyAvailable();
  57. if (!transpavail) turnonoff(hwndDlg, opacity_unavail, sizeof(opacity_unavail)/sizeof(int), 0);
  58. CheckDlgButton(hwndDlg, IDC_CHECK_LINKALPHA, cfg_uioptions_linkalpha.getValueAsInt());
  59. CheckDlgButton(hwndDlg, IDC_CHECK_LINKALLALPHA, cfg_uioptions_linkallalpha.getValueAsInt());
  60. Layout *main = SkinParser::getMainLayout();
  61. int curalpha = 255;
  62. if (main) {
  63. if (!WASABI_API_WND->rootwndIsValid(main)) { return 0; }
  64. curalpha = cfg_uioptions_linkedalpha.getValueAsInt();
  65. }
  66. int v = (int)((curalpha / 255.0f * 100.0f)+0.5f);
  67. wchar_t msStr[16] = {0};
  68. WASABI_API_LNGSTRINGW_BUF(IDS_MS,msStr,16);
  69. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_CUSTOMALPHA),TBM_SETRANGEMAX,0,100);
  70. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_CUSTOMALPHA),TBM_SETRANGEMIN,0,10);
  71. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_CUSTOMALPHA),TBM_SETPOS,1,v);
  72. wchar_t *name = 0;
  73. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_ADDSTRING, 0, (LPARAM)(name = WASABI_API_LNGSTRINGW(IDS_OPAQUE_FOCUS)));
  74. int width = ResizeComboBoxDropDown(hwndDlg, IDC_COMBO_OPACITY, name, 0);
  75. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_SETITEMDATA, 0, 2);
  76. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_ADDSTRING, 0, (LPARAM)(name = WASABI_API_LNGSTRINGW(IDS_OPAQUE_HOVER)));
  77. width = ResizeComboBoxDropDown(hwndDlg, IDC_COMBO_OPACITY, name, width);
  78. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_SETITEMDATA, 1, 1);
  79. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_ADDSTRING, 0, (LPARAM)(name = WASABI_API_LNGSTRINGW(IDS_NO_OPACITY)));
  80. ResizeComboBoxDropDown(hwndDlg, IDC_COMBO_OPACITY, name, width);
  81. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_SETITEMDATA, 2, 0);
  82. int item = 2;
  83. switch(cfg_uioptions_autoopacitylinked.getValueAsInt())
  84. {
  85. case 1:
  86. item = 1;
  87. break;
  88. case 2:
  89. item = 0;
  90. break;
  91. default:
  92. item = 2;
  93. break;
  94. }
  95. SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_SETCURSEL, item, 0);
  96. SetDlgItemTextA(hwndDlg, IDC_STATIC_ALPHA, StringPrintf("%d%%", v));
  97. turnonoff(hwndDlg, opacity_all_on, sizeof(opacity_all_on)/sizeof(int), cfg_uioptions_linkallalpha.getValueAsInt() && transpavail);
  98. turnonoff(hwndDlg, opacity_all_off, sizeof(opacity_all_off)/sizeof(int), !cfg_uioptions_linkallalpha.getValueAsInt() && transpavail);
  99. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_HOLD),TBM_SETRANGEMAX,0,30303);
  100. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_HOLD),TBM_SETRANGEMIN,0,0);
  101. set_logslider(GetDlgItem(hwndDlg,IDC_SLIDER_HOLD),cfg_uioptions_autoopacitytime.getValueAsInt());
  102. SetDlgItemTextW(hwndDlg, IDC_STATIC_HOLD, StringPrintfW(L"%d%s", cfg_uioptions_autoopacitytime.getValueAsInt(),msStr));
  103. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_FADEIN),TBM_SETRANGEMAX,0,30303);
  104. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_FADEIN),TBM_SETRANGEMIN,0,0);
  105. set_logslider(GetDlgItem(hwndDlg,IDC_SLIDER_FADEIN),cfg_uioptions_autoopacityfadein.getValueAsInt());
  106. SetDlgItemTextW(hwndDlg, IDC_STATIC_FADEIN, StringPrintfW(L"%d%s", cfg_uioptions_autoopacityfadein.getValueAsInt(),msStr));
  107. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_FADEOUT),TBM_SETRANGEMAX,0,30303);
  108. SendMessageW(GetDlgItem(hwndDlg,IDC_SLIDER_FADEOUT),TBM_SETRANGEMIN,0,0);
  109. set_logslider(GetDlgItem(hwndDlg,IDC_SLIDER_FADEOUT),cfg_uioptions_autoopacityfadeout.getValueAsInt());
  110. SetDlgItemTextW(hwndDlg, IDC_STATIC_FADEOUT, StringPrintfW(L"%d%s", cfg_uioptions_autoopacityfadeout.getValueAsInt(),msStr));
  111. SendMessageW(GetDlgItem(hwndDlg,IDC_SPIN_EXTEND),UDM_SETRANGE,0,MAKELONG(100,0));
  112. SetDlgItemInt(hwndDlg, IDC_EDIT_EXTEND, cfg_uioptions_extendautoopacity.getValueAsInt(), FALSE);
  113. CheckDlgButton(hwndDlg, IDC_CHECK_LINKALLRATIO, cfg_uioptions_linkallratio.getValueAsInt());
  114. CheckDlgButton(hwndDlg, IDC_CHECK_LINKRATIO, cfg_uioptions_linkratio.getValueAsInt());
  115. SendDlgItemMessageW(hwndDlg, IDC_COMBO_SCALE, CB_ADDSTRING, 0, (LPARAM)(name = WASABI_API_LNGSTRINGW(IDS_USELOCK)));
  116. width = ResizeComboBoxDropDown(hwndDlg, IDC_COMBO_SCALE, name, 0);
  117. SendDlgItemMessageW(hwndDlg, IDC_COMBO_SCALE, CB_ADDSTRING, 0, (LPARAM)(name = WASABI_API_LNGSTRINGW(IDS_ALLLOCKED)));
  118. ResizeComboBoxDropDown(hwndDlg, IDC_COMBO_SCALE, name, width);
  119. SendDlgItemMessageW(hwndDlg, IDC_COMBO_SCALE, CB_SETCURSEL, !!cfg_uioptions_uselocks.getValueAsInt(), 0);
  120. int oldscale = 1;
  121. if (main)
  122. {
  123. if (!WASABI_API_WND->rootwndIsValid(main)) { return 0; }
  124. oldscale = (int)main->getRenderRatio();
  125. }
  126. int u = (int)((oldscale * 100.0f) + 0.5f);
  127. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETRANGEMAX, 0, 300);
  128. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETRANGEMIN, 0, 10);
  129. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETPOS, 1, u);
  130. SetDlgItemTextA(hwndDlg, IDC_STATIC_SCALE, StringPrintf("%d%%", u));
  131. turnonoff(hwndDlg, ratio_all_on, sizeof(ratio_all_on) / sizeof(int), cfg_uioptions_linkallratio.getValueAsInt());
  132. turnonoff(hwndDlg, ratio_all_off, sizeof(ratio_all_off) / sizeof(int), !cfg_uioptions_linkallratio.getValueAsInt());
  133. spin_extend = 1;
  134. return 1;
  135. }
  136. case WM_HSCROLL:
  137. {
  138. char msStr[16] = {0};
  139. WASABI_API_LNGSTRING_BUF(IDS_MS,msStr,16);
  140. HWND ctrl = (HWND)lParam;
  141. int t=(int)SendMessageW((HWND) lParam,TBM_GETPOS,0,0);
  142. if (ctrl == GetDlgItem(hwndDlg,IDC_SLIDER_CUSTOMALPHA)) {
  143. SetDlgItemTextA(hwndDlg, IDC_STATIC_ALPHA, StringPrintf("%d%%", t));
  144. int v = (int)(t / 100.0 * 255 + 0.5);
  145. if (v == 254) v = 255;
  146. cfg_uioptions_linkedalpha.setValueAsInt(v);
  147. }
  148. else if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_HOLD)) {
  149. t = get_logslider(ctrl);
  150. SetDlgItemTextA(hwndDlg, IDC_STATIC_HOLD, StringPrintf("%d%s", t, msStr));
  151. cfg_uioptions_autoopacitytime.setValueAsInt(t);
  152. }
  153. else if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_FADEIN)) {
  154. t = get_logslider(ctrl);
  155. SetDlgItemTextA(hwndDlg, IDC_STATIC_FADEIN, StringPrintf("%d%s", t, msStr));
  156. cfg_uioptions_autoopacityfadein.setValueAsInt(t);
  157. }
  158. else if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_FADEOUT)) {
  159. int t = get_logslider(ctrl);
  160. SetDlgItemTextA(hwndDlg, IDC_STATIC_FADEOUT, StringPrintf("%d%s", t, msStr));
  161. cfg_uioptions_autoopacityfadeout.setValueAsInt(t);
  162. }
  163. else if (ctrl == GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE))
  164. {
  165. SetDlgItemTextA(hwndDlg, IDC_STATIC_SCALE, StringPrintf("%d%%", t));
  166. Layout *main = SkinParser::getMainLayout();
  167. if (main)
  168. {
  169. main->setRenderRatio((float)t / 100.0);
  170. if (cfg_uioptions_linkratio.getValueAsInt())
  171. {
  172. int nc = SkinParser::getNumContainers();
  173. for (int i = 0;i < nc;i++)
  174. {
  175. Container *c = SkinParser::enumContainer(i);
  176. if (c)
  177. {
  178. int nl = c->getNumLayouts();
  179. for (int j = 0;j < nl;j++)
  180. {
  181. Layout *l = c->enumLayout(j);
  182. if (l)
  183. {
  184. UpdateWindow(l->gethWnd());
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. return 0;
  192. }
  193. break;
  194. }
  195. case WM_COMMAND:
  196. toggle_from_wa2 = 1;
  197. switch (LOWORD(wParam)) {
  198. case IDC_CHECK_LINKALPHA:
  199. cfg_uioptions_linkalpha.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_LINKALPHA));
  200. return 0;
  201. case IDC_CHECK_LINKALLALPHA:
  202. cfg_uioptions_linkallalpha.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_LINKALLALPHA));
  203. turnonoff(hwndDlg, opacity_all_on, sizeof(opacity_all_on)/sizeof(int), cfg_uioptions_linkallalpha.getValueAsInt());
  204. turnonoff(hwndDlg, opacity_all_off, sizeof(opacity_all_off)/sizeof(int), !cfg_uioptions_linkallalpha.getValueAsInt());
  205. return 0;
  206. case IDC_EDIT_EXTEND:
  207. if (HIWORD(wParam) == EN_CHANGE && spin_extend) {
  208. int t, a = GetDlgItemInt(hwndDlg,IDC_EDIT_EXTEND,&t,0);
  209. if (t) cfg_uioptions_extendautoopacity.setValueAsInt(MAX(a,0));
  210. if (a < 0)
  211. {
  212. char msStr[16] = {0};
  213. SetDlgItemTextA(hwndDlg, IDC_STATIC_HOLD,
  214. StringPrintf("%d%s", cfg_uioptions_autoopacitytime.getValueAsInt(),WASABI_API_LNGSTRING_BUF(IDS_MS,msStr,16)));
  215. }
  216. }
  217. return 0;
  218. case IDC_CHECK_LINKALLRATIO:
  219. cfg_uioptions_linkallratio.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_LINKALLRATIO));
  220. turnonoff(hwndDlg, ratio_all_on, sizeof(ratio_all_on) / sizeof(int), cfg_uioptions_linkallratio.getValueAsInt());
  221. turnonoff(hwndDlg, ratio_all_off, sizeof(ratio_all_off) / sizeof(int), !cfg_uioptions_linkallratio.getValueAsInt());
  222. return 0;
  223. case IDC_COMBO_OPACITY:
  224. if (HIWORD(wParam) == CBN_SELCHANGE)
  225. {
  226. int sel = SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_GETCURSEL, 0, 0);
  227. if (sel != CB_ERR)
  228. {
  229. cfg_uioptions_autoopacitylinked.setValueAsInt(SendDlgItemMessageW(hwndDlg, IDC_COMBO_OPACITY, CB_GETITEMDATA, sel, 0));
  230. }
  231. }
  232. return 0;
  233. case IDC_COMBO_SCALE:
  234. if (HIWORD(wParam) == CBN_SELCHANGE)
  235. {
  236. int sel = SendDlgItemMessageW(hwndDlg, IDC_COMBO_SCALE, CB_GETCURSEL, 0, 0);
  237. if (sel != CB_ERR)
  238. {
  239. cfg_uioptions_uselocks.setValueAsInt(!!sel);
  240. }
  241. }
  242. return 0;
  243. case IDC_CHECK_LINKRATIO:
  244. cfg_uioptions_linkratio.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_LINKRATIO));
  245. return 0;
  246. }
  247. case WM_DESTROY:
  248. spin_extend = 0;
  249. return 0;
  250. }
  251. const int controls[] =
  252. {
  253. IDC_SLIDER_CUSTOMALPHA,
  254. IDC_SLIDER_HOLD,
  255. IDC_SLIDER_FADEIN,
  256. IDC_SLIDER_FADEOUT,
  257. IDC_SLIDER_CUSTOMSCALE,
  258. };
  259. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  260. return TRUE;
  261. return 0;
  262. }