-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_settings.cpp
More file actions
1566 lines (1351 loc) · 47.2 KB
/
Copy pathquick_settings.cpp
File metadata and controls
1566 lines (1351 loc) · 47.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
The MIT License (MIT)
Copyright (c) 2024 sigma-axis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstdint>
#include <algorithm>
#include <memory>
#include <vector>
#include <forward_list>
#include <string>
#include <charconv>
#include <map>
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#pragma comment(lib, "imm32")
#include <CommCtrl.h>
#pragma comment(lib, "comctl32")
#pragma warning(push)
#pragma warning(disable : 6387 26454)
#include <json.h>
#pragma warning(pop)
using byte = uint8_t;
#include <exedit.hpp>
////////////////////////////////
// 主要情報源の変数アドレス.
////////////////////////////////
inline constinit struct AviUtl110 {
constexpr static int32_t build110 = 11003;
bool init(HMODULE hinst, AviUtl::SysInfo const& si)
{
if (si.build != build110) return false;
instance = hinst;
font = si.hfont;
init_pointers();
return true;
}
HMODULE instance;
HFONT font;
// 任意フレーム数移動
int32_t(* frame_jump_distance)[4]; // 0x086424
// 編集のレジューム機能を有効
int32_t* resume_enabled; // 0x086268
// 関連ウィンドウ同士を移動時にスナップする
int32_t* snaps_window; // 0x086434
// トラックバーでクリックした位置に直接移動する
int32_t* seeks_clicked_point; // 0x086270
private:
void init_pointers()
{
auto pick_addr = [aviutl_base = reinterpret_cast<uintptr_t>(instance)]
<class T>(T& target, ptrdiff_t offset) { target = reinterpret_cast<T>(aviutl_base + offset); };
pick_addr(frame_jump_distance, 0x086424);
pick_addr(resume_enabled, 0x086268);
pick_addr(snaps_window, 0x086434);
pick_addr(seeks_clicked_point, 0x086270);
}
} aviutl;
enum class time_fmt :int32_t {
frame = 0,
hms = 1,
};
inline constinit struct ExEdit092 {
AviUtl::FilterPlugin* fp;
constexpr static auto info_exedit092 = "拡張編集(exedit) version 0.92 by KENくん";
bool init(AviUtl::FilterPlugin* this_fp)
{
if (fp != nullptr) return true;
AviUtl::SysInfo si; this_fp->exfunc->get_sys_info(nullptr, &si);
if (!aviutl.init(this_fp->hinst_parent, si)) return false;
for (int i = 0; i < si.filter_n; i++) {
auto that_fp = this_fp->exfunc->get_filterp(i);
if (that_fp->information != nullptr &&
0 == std::strcmp(that_fp->information, info_exedit092)) {
fp = that_fp;
init_pointers();
return true;
}
}
return false;
}
int32_t* is_playing; // 0x1a52ec; 0: editing, 1: playing.
time_fmt* tl_time_format; // 0x178e20
time_fmt* dlg_time_format; // 0x14dec8
void(* update_dialog_top)(); // 0x02c580
int32_t* layer_size_mode; // 0x1539d4; 0: large, 1: medium, 2: small.
int32_t(* layer_size_preset)[3]; // 0x0a3e08
int32_t(* midpt_mk_sz_preset)[3]; // 0x0a3e14
int32_t* layer_size; // 0x0a3e20
int32_t* midpt_marker_size; // 0x0a3e24
int32_t* playback_syncs_cursor; // 0x158d14
int32_t* pos_green_line; // 0x0a3fc0
int32_t* scroll_follows_cursor; // 0x1790d0
int32_t* groups_drag_drop; // 0x179224
int32_t* relocates_file_path; // 0x177a20
int32_t* split_calcs_midvalue; // 0x1460b0
int32_t* splits_at_current; // 0x1538b0
int32_t* drags_adjacent_obj; // 0x14ea00
int32_t* split_seps_groups; // 0x153de0
int32_t* clamps_into_rgb_box; // 0x1538b8
int32_t* auto_backup_enabled; // 0x135aa8
private:
void init_pointers()
{
auto pick_addr = [exedit_base = reinterpret_cast<uintptr_t>(fp->dll_hinst)]
<class T>(T& target, ptrdiff_t offset) { target = reinterpret_cast<T>(exedit_base + offset); };
pick_addr(is_playing, 0x1a52ec);
pick_addr(tl_time_format, 0x178e20);
pick_addr(dlg_time_format, 0x14dec8);
pick_addr(update_dialog_top, 0x02c580);
pick_addr(layer_size_mode, 0x1539d4);
pick_addr(layer_size_preset, 0x0a3e08);
pick_addr(midpt_mk_sz_preset, 0x0a3e14);
pick_addr(layer_size, 0x0a3e20);
pick_addr(midpt_marker_size, 0x0a3e24);
pick_addr(playback_syncs_cursor, 0x158d14);
pick_addr(pos_green_line, 0x0a3fc0);
pick_addr(scroll_follows_cursor, 0x1790d0);
pick_addr(groups_drag_drop, 0x179224);
pick_addr(relocates_file_path, 0x177a20);
pick_addr(split_calcs_midvalue, 0x1460b0);
pick_addr(splits_at_current, 0x1538b0);
pick_addr(drags_adjacent_obj, 0x14ea00);
pick_addr(split_seps_groups, 0x153de0);
pick_addr(clamps_into_rgb_box, 0x1538b8);
pick_addr(auto_backup_enabled, 0x135aa8);
}
} exedit;
////////////////////////////////
// 文字エンコード変換.
////////////////////////////////
struct Encodes {
static std::string to_narrow(wchar_t const* wstr)
{
auto len = ::WideCharToMultiByte(CP_ACP, 0, wstr, -1, nullptr, 0, nullptr, nullptr);
if (len <= 0) return "";
std::string ret(len - 1, '\0');
::WideCharToMultiByte(CP_ACP, 0, wstr, -1, ret.data(), len, nullptr, nullptr);
return ret;
}
};
////////////////////////////////
// aviutl.ini への書き込み補助.
////////////////////////////////
struct aviutl_ini {
static char const* ini_path()
{
static constinit char path[MAX_PATH] = "";
if (path[0] == '\0') {
auto const len = ::GetModuleFileNameA(nullptr, path, std::size(path));
auto pos = std::string_view{ path, len }.find_last_of("/\\");
pos = pos == std::string_view::npos ? 0 : pos + 1;
::strcpy_s(path + pos, std::size(path) - pos, "aviutl.ini");
}
return path;
}
static void write_int(char const* key, int32_t val)
{
write_string(key, std::to_string(val).c_str());
}
static void write_bool(char const* key, bool val)
{
write_string(key, val ? "1" : "0");
}
static void write_string(char const* key, char const* val)
{
::WritePrivateProfileStringA("system", key, val, ini_path());
}
};
////////////////////////////////
// 各種設定項目.
////////////////////////////////
struct setting_item {
// synchronizes GUI from effective settings.
virtual void on_update() = 0;
// synchronizes GUI to effective settings.
virtual bool on_notify(HWND ctrl, uint32_t code) = 0;
// used as a menu command.
virtual bool menu_command() { return false; };
virtual wchar_t const* menu_title() const { return nullptr; }
virtual std::pair<int, int> measure(HWND parent) = 0;
virtual void create(HWND parent, int x, int y, int w, int h) = 0;
virtual void destroy() = 0;
virtual ~setting_item() {}
// to be called when GUI recieves updates.
static bool notify(HWND ctrl, uint32_t code)
{
auto that = lookup(ctrl);
return that != nullptr && that->on_notify(ctrl, code);
}
void associate(HWND hwnd) const
{
::SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG>(this));
}
template<std::derived_from<setting_item> ItemT = setting_item>
static ItemT* lookup(HWND hwnd)
{
return dynamic_cast<ItemT*>(reinterpret_cast<setting_item*>(
::GetWindowLongPtrW(hwnd, GWLP_USERDATA)));
}
constexpr setting_item() = default;
setting_item(setting_item const&) = delete;
setting_item(setting_item&&) = delete;
protected:
// helper functions to measure window size.
struct text_measure {
HWND parent;
HDC dc;
HGDIOBJ old_font;
text_measure(HWND parent, HFONT font) : parent{ parent } {
dc = ::GetDC(parent);
old_font = ::SelectObject(dc, font);
}
~text_measure() {
::SelectObject(dc, old_font);
::ReleaseDC(parent, dc);
}
std::pair<int, int> operator()(wchar_t const* text) const
{
RECT rc{};
::DrawTextW(dc, text, -1, &rc, DT_CALCRECT);
return { rc.right, rc.bottom };
}
operator bool() const { return dc != nullptr; }
};
// helper functions to create controls.
static HWND create_label(HWND parent, wchar_t const* text, int x, int y, int w, int h,
uint32_t extra_style = SS_SIMPLE, uint32_t extra_ex_style = WS_EX_NOPARENTNOTIFY)
{
auto ret = ::CreateWindowExW(extra_ex_style, WC_STATICW, text,
WS_VISIBLE | WS_CHILD | extra_style,
x, y, w, h, parent, nullptr, aviutl.instance, nullptr);
::SendMessageW(ret, WM_SETFONT, reinterpret_cast<WPARAM>(aviutl.font), {});
return ret;
}
HWND create_edit(HWND parent, wchar_t const* text, int x, int y, int w, int h,
uint32_t extra_style = ES_AUTOHSCROLL | ES_LEFT,
uint32_t extra_ex_style = WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY) const
{
// edit control.
auto ret = ::CreateWindowExW(extra_ex_style, WC_EDITW, text,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | extra_style,
x, y, w, h, parent, nullptr, aviutl.instance, nullptr);
::SendMessageW(ret, WM_SETFONT, reinterpret_cast<WPARAM>(aviutl.font), {});
associate(ret);
enable_focus_nav(ret, parent);
return ret;
}
template<size_t max_digits = 15>
static bool try_parse_edit(HWND edit, auto& num)
{
// parses input text as a number.
wchar_t wbuf[max_digits + 1];
if (::SendMessageW(edit, WM_GETTEXT, std::size(wbuf), reinterpret_cast<LPARAM>(wbuf)) == 0)
return false;
auto buf = Encodes::to_narrow(wbuf);
auto result = std::from_chars(&*buf.begin(), &*buf.end(), num);
return result.ec == std::errc{} && result.ptr == &*buf.end();
}
HWND create_check(HWND parent, wchar_t const* text, int x, int y, int w, int h,
uint32_t extra_style = 0, uint32_t extra_ex_style = WS_EX_NOPARENTNOTIFY) const
{
// check box control.
auto ret = ::CreateWindowExW(extra_ex_style, WC_BUTTONW, text,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | extra_style,
x, y, w, h, parent, nullptr, aviutl.instance, nullptr);
::SendMessageW(ret, BM_SETCHECK, BST_UNCHECKED, 0);
::SendMessageW(ret, WM_SETFONT, reinterpret_cast<WPARAM>(aviutl.font), {});
associate(ret);
enable_focus_nav(ret, parent);
return ret;
}
HWND create_radio(HWND parent, wchar_t const* text, int x, int y, int w, int h, bool is_first,
uint32_t extra_style = 0, uint32_t extra_ex_style = WS_EX_NOPARENTNOTIFY) const
{
// radio button control.
auto ret = ::CreateWindowExW(extra_ex_style, WC_BUTTONW, text,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | extra_style
| (is_first ? WS_GROUP : 0), x, y, w, h, parent,
nullptr, aviutl.instance, nullptr);
::SendMessageW(ret, BM_SETCHECK, is_first ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessageW(ret, WM_SETFONT, reinterpret_cast<WPARAM>(aviutl.font), {});
associate(ret);
enable_focus_nav(ret, parent);
return ret;
}
// helper function to destroy multiple windows.
static void destroy_windows(auto&... windows)
{
constexpr auto destroy = [](HWND& wnd) {
if (wnd != nullptr) {
::DestroyWindow(wnd);
wnd = nullptr;
}
};
(destroy(windows), ...);
}
private:
// implement tab navigation.
static void enable_focus_nav(HWND hwnd, HWND parent) {
::SetWindowSubclass(hwnd, focus_nav_proc, reinterpret_cast<uintptr_t>(parent), {});
}
static LRESULT CALLBACK focus_nav_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, uintptr_t id, DWORD_PTR)
{
switch (message) {
case WM_KEYDOWN:
{
HWND next = hwnd;
switch (wparam) {
case VK_TAB:
next = ::GetNextDlgTabItem(reinterpret_cast<HWND>(id), hwnd,
::GetKeyState(VK_SHIFT) < 0 ? TRUE : FALSE);
break;
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
{
if (is_radio(hwnd)) {
next = ::GetNextDlgGroupItem(reinterpret_cast<HWND>(id), hwnd,
wparam == VK_LEFT || wparam == VK_UP ? TRUE : FALSE);
if (!is_radio(next)) next = hwnd;
}
break;
}
}
if (next != hwnd) {
::SetFocus(next);
return 0;
}
break;
}
case WM_CHAR:
if (wparam == L'\t') return 0; // suppress notification sound.
break;
case WM_NCDESTROY:
::RemoveWindowSubclass(hwnd, focus_nav_proc, id);
break;
}
return ::DefSubclassProc(hwnd, message, wparam, lparam);
}
static inline bool is_radio(HWND hwnd);
};
// 任意フレーム数移動.
struct setting_item_frame_jump : setting_item {
constexpr static auto title = L"任意フレーム数移動";
constexpr static wchar_t const* title_a[] = { L"A", L"B", L"C", L"D" };
constexpr static char const* ini_keys[] = { "moveA", "moveB", "moveC", "moveD" };
constexpr static size_t cnt_values = std::size(title_a);
// returns lengths of { title, maximum of A/B/C/D, numbers, height }.
static std::tuple<int, int, int, int> label_size(HWND parent) {
static constinit int label = -1, label_a = -1, num, height = -1;
if (label < 0) {
text_measure measure{ parent, aviutl.font };
std::tie(label, height) = measure(title);
num = measure(L"123456").first; // accept at most 6 digits.
for (auto a : title_a)
label_a = std::max(label_a, measure(a).first);
}
return { label, label_a, num, height };
}
static int edit_pad_size() {
static constinit int padding = -1;
if (padding < 0) {
padding = 2 * ::GetSystemMetrics(SM_CXEDGE);
}
return padding;
}
// GUI elemnts.
HWND label = nullptr;
struct gui_unit {
int32_t gui_val;
HWND label = nullptr, edit = nullptr;
} units[cnt_values]{ { 5 }, { 30 }, { 899 }, { 8991 } };
// metrics for small blanks.
constexpr static int left_pad = 16, gap_unit = 8, gap_label = 4, gap_v = 0, pad_edit = 4;
void on_update() override
{
if (label == nullptr) return;
auto focused = ::GetFocus();
for (size_t i = 0; i < cnt_values; i++) {
auto& val = units[i];
if (focused == val.edit) continue;
auto src = (*aviutl.frame_jump_distance)[i];
if (val.gui_val == src) continue;
pull(val, src);
}
}
bool on_notify(HWND ctrl, uint32_t code) override
{
if (label != nullptr) {
switch (code) {
case EN_SETFOCUS:
{
::SendMessageW(ctrl, EM_SETSEL, 0, -1);
return false;
}
case EN_KILLFOCUS:
{
size_t idx = 0;
for (; idx < cnt_values; idx++) {
if (units[idx].edit == ctrl) break;
}
if (int value; idx < cnt_values &&
try_parse_edit(ctrl, value) && value > 0) {
// valid number was input. write it as an effective setting.
units[idx].gui_val = value;
return push(idx, value);
}
else {
// invalid number input. rewind the edit state.
pull(units[idx], units[idx].gui_val);
return false;
}
}
}
}
return false;
}
std::pair<int, int> measure(HWND parent) override
{
auto const pad = edit_pad_size(), pad_h = pad + pad_edit;
auto const [title_w, lbl_w, num_w, height] = label_size(parent);
return {
std::max<int>(title_w, left_pad
+ cnt_values * (lbl_w + gap_label + pad_h + num_w)
+ (cnt_values - 1) * gap_unit),
2 * height + gap_v + pad
};
}
void create(HWND parent, int x, int y, int w, int h) override
{
auto const pad = edit_pad_size(), pad_h = pad + pad_edit;
auto const [title_w, lbl_w, num_w, height] = label_size(parent);
// title.
label = create_label(parent, title, x, y, w, height);
// each number boxes.
int const unit_w = lbl_w + gap_label + pad_h + num_w + gap_unit,
Y = y + height + gap_v;
int X = x + w - cnt_values * unit_w + gap_unit;
size_t idx = 0;
for (auto& val : units) {
// labels A/B/C/D.
val.label = create_label(parent, title_a[idx],
X, Y + (pad >> 1), lbl_w + gap_label, height);
// edit control to input numbers.
val.edit = create_edit(parent, std::to_wstring(val.gui_val).c_str(),
X + lbl_w + gap_label, Y, pad_h + num_w, pad + height,
ES_AUTOHSCROLL | ES_NUMBER | ES_RIGHT);
X += unit_w; idx++;
}
}
void destroy() override
{
[this] <size_t... I>(std::index_sequence<I...>) {
destroy_windows(label, units[I].label..., units[I].edit...);
}(std::make_index_sequence<cnt_values>{});
}
~setting_item_frame_jump() override { destroy(); }
private:
// syncs between GUIs and effective settings.
void pull(gui_unit& unit, int32_t value)
{
unit.gui_val = value;
::SendMessageW(unit.edit, WM_SETTEXT, {},
reinterpret_cast<LPARAM>(std::to_wstring(value).c_str()));
}
bool push(size_t idx, int32_t gui_val) {
auto* target = &(*aviutl.frame_jump_distance)[idx];
if (*target == gui_val) return false;
*target = gui_val;
aviutl_ini::write_int(ini_keys[idx], gui_val);
return true;
}
};
// ボタン利用の設定項目 (push_like のフィールド定義が目的).
struct setting_item_button_base : setting_item {
static auto min_check_size()
{
static constinit int min_width = -1, min_height = -1;
if (min_width < 0) {
min_width = ::GetSystemMetrics(SM_CXMENUCHECK) + 2 * ::GetSystemMetrics(SM_CXEDGE);
min_height = ::GetSystemMetrics(SM_CYMENUCHECK);
}
return std::pair{ min_width, min_height };
}
static int button_pad_size()
{
static constinit int padding = -1;
if (padding < 0) {
padding = 2 * ::GetSystemMetrics(SM_CXEDGE);
}
return padding;
}
bool push_like = false;
};
// チェックボックス形式.
struct setting_item_check_base : setting_item_button_base {
// target field for the effective setting.
int32_t*& target;
// GUI elements.
wchar_t const* title;
HWND check = nullptr; bool gui_val = false;
constexpr setting_item_check_base(int32_t*& target, wchar_t const* title)
: target{ target }, title{ title } {}
void on_update() override
{
if (check != nullptr && (*target != 0) != gui_val) {
gui_val = *target != 0;
::SendMessageW(check, BM_SETCHECK, gui_val ? BST_CHECKED : BST_UNCHECKED, 0);
}
}
bool on_notify(HWND ctrl, uint32_t code) override
{
if (check != nullptr && code == BN_CLICKED) {
gui_val = ::SendMessageW(check, BM_GETCHECK, 0, 0) != BST_UNCHECKED;
return push(gui_val);
}
return false;
}
bool menu_command() override
{
auto ret = push(*target == 0);
on_update();
return ret;
}
wchar_t const* menu_title() const override { return title; }
std::pair<int, int> measure(HWND parent) override
{
if (push_like) {
auto const pad = button_pad_size();
auto const [W, H] = text_measure{ parent, aviutl.font }(title);
return { W + pad, H + pad };
}
else {
auto const [w, h] = min_check_size();
auto const [W, H] = text_measure{ parent, aviutl.font }(title);
return { w + W, std::max(h, H) };
}
}
void create(HWND parent, int x, int y, int w, int h) override
{
check = create_check(parent, title, x, y, w, h, push_like ? BS_PUSHLIKE : 0);
gui_val = false;
}
void destroy() override { destroy_windows(check); }
~setting_item_check_base() override { destroy(); }
protected:
virtual bool push(bool value) = 0;
};
template<bool redraw>
struct setting_item_check : setting_item_check_base {
constexpr setting_item_check(int32_t*& target, wchar_t const* title)
: setting_item_check_base{ target, title } {}
protected:
// syncs between GUIs and effective settings.
bool push(bool val) override
{
int32_t const value = val ? 1 : 0;
if (*target == value) return false;
*target = value;
on_push_extra(val);
return redraw;
}
virtual void on_push_extra(bool val) {}
};
// 再生を停止して緑の線を隠す特殊化.
struct setting_item_sync_cursor : setting_item_check_base {
constexpr setting_item_sync_cursor(wchar_t const* title)
: setting_item_check_base{ exedit.playback_syncs_cursor, title } {}
protected:
// syncs between GUIs and effective settings.
bool push(bool val) override
{
int32_t const value = val ? 1 : 0;
if (*target == value) return false;
*target = value;
if (*exedit.is_playing != 0) {
if (val && *exedit.pos_green_line >= 0) {
// hide the green line.
*exedit.pos_green_line = -1;
// redraw the timeline as well.
::InvalidateRect(exedit.fp->hwnd, nullptr, FALSE);
}
// stops playing by updating the screen.
return true;
}
return false;
}
};
// aviutl.ini に変更を保存する特殊化.
template<bool redraw>
struct setting_item_check_ini : setting_item_check<redraw> {
char const* const ini_key = nullptr;
constexpr setting_item_check_ini(int32_t*& target, wchar_t const* title, char const* key)
: setting_item_check<redraw>{ target, title }, ini_key{ key } {}
protected:
// write to .ini file when effective setting updates.
void on_push_extra(bool val) override {
aviutl_ini::write_bool(ini_key, val);
}
};
// ラジオボタン形式の基底クラス.
struct setting_item_radio_base : setting_item_button_base {};
inline bool setting_item::is_radio(HWND hwnd) {
// checks if it's a radio button control.
return lookup<setting_item_radio_base>(hwnd) != nullptr;
}
// 時間表示形式の選択.
struct setting_item_time_fmt : setting_item_radio_base {
constexpr static auto
label_hms = L"時分秒",
label_frame = L"フレーム";
// returns a tuple of widths of { hms, frame }.
static std::tuple<int, int> label_widths(HWND parent) {
static constinit int hms = -1, frame = -1;
if (hms < 0) {
text_measure measure{ parent, aviutl.font };
hms = measure(label_hms).first;
frame = measure(label_frame).first;
}
return { hms, frame };
}
// left/top padding of timeline window.
constexpr static int
timeline_layer_header_width = 64,
timeline_ruler_height = 42;
// target field for the effective setting.
time_fmt*& target;
// GUI elements.
wchar_t const* title;
HWND label = nullptr, radio_hms = nullptr, radio_frame = nullptr;
time_fmt gui_val = time_fmt::hms;
// metrics for small blanks.
constexpr static int gap_title = 8, gap_radio = 4, pad_button = 12;
constexpr setting_item_time_fmt(time_fmt*& target, wchar_t const* title)
: target{ target }, title{ title } {}
void on_update() override
{
if (label == nullptr) return;
if (*target != gui_val) {
// update the check states of radio buttons.
auto prev_val = std::exchange(gui_val, *target);
::SendMessageW(choose_radio(prev_val), BM_SETCHECK, BST_UNCHECKED, 0);
::SendMessageW(choose_radio(gui_val), BM_SETCHECK, BST_CHECKED, 0);
}
}
bool on_notify(HWND ctrl, uint32_t code) override
{
if (label != nullptr && code == BN_CLICKED) {
auto prev_val = std::exchange(gui_val, ctrl == radio_hms ? time_fmt::hms : time_fmt::frame);
if (prev_val != gui_val) {
::SendMessageW(choose_radio(prev_val), BM_SETCHECK, BST_UNCHECKED, 0);
::SendMessageW(ctrl, BM_SETCHECK, BST_CHECKED, 0);
}
return push(gui_val);
}
return false;
}
bool menu_command() override
{
auto ret = push(toggle(*target));
on_update();
return ret;
}
wchar_t const* menu_title() const override { return title; }
std::pair<int, int> measure(HWND parent) override
{
auto const [title_w, title_h] = text_measure{ parent, aviutl.font }(title);
auto const [hms_w, frame_w] = label_widths(parent);
if (push_like) {
auto const pad = button_pad_size(), pad_h = pad + pad_button;
return { title_w + gap_title + 2 * pad_h + hms_w + frame_w, title_h + pad };
}
else {
auto const [radio_w, radio_h] = min_check_size();
return { title_w + gap_title + 2 * radio_w + hms_w + frame_w + gap_radio, std::max(radio_h, title_h) };
}
}
void create(HWND parent, int x, int y, int w, int h) override
{
auto const [hms_w, frame_w] = label_widths(parent);
if (push_like) {
auto const pad = button_pad_size(), pad_h = pad + pad_button;
// title.
label = create_label(parent, title, x, y + (pad >> 1),
std::max(0, w - (2 * pad_h + hms_w + frame_w)), h - pad);
// radio for H:M:S format.
radio_hms = create_radio(parent, label_hms,
x + w - (2 * pad_h + hms_w + frame_w), y,
pad_h + hms_w, h, true, BS_PUSHLIKE);
// radio for frame count.
radio_frame = create_radio(parent, label_frame,
x + w - (pad_h + frame_w), y, pad_h + frame_w, h, false, BS_PUSHLIKE);
}
else {
auto const radio_w = min_check_size().first;
// title.
label = create_label(parent, title, x, y,
std::max(0, w - (2 * radio_w + hms_w + frame_w + gap_radio)), h);
// radio for H:M:S format.
radio_hms = create_radio(parent, label_hms,
x + w - (2 * radio_w + hms_w + frame_w + gap_radio), y,
radio_w + hms_w, h, true);
// radio for frame count.
radio_frame = create_radio(parent, label_frame,
x + w - (radio_w + frame_w), y, radio_w + frame_w, h, false);
}
gui_val = time_fmt::hms;
}
void destroy() override { destroy_windows(label, radio_hms, radio_frame); }
~setting_item_time_fmt() override { destroy(); }
protected:
HWND choose_radio(time_fmt val) const {
return val == time_fmt::hms ? radio_hms : radio_frame;
}
static constexpr time_fmt toggle(time_fmt val) {
switch (val) {
case time_fmt::hms:
default: return time_fmt::frame;
case time_fmt::frame: return time_fmt::hms;
}
}
virtual bool push(time_fmt val) = 0;
};
struct setting_item_tl_time_fmt : setting_item_time_fmt {
constexpr setting_item_tl_time_fmt(wchar_t const* title)
: setting_item_time_fmt(exedit.tl_time_format, title) {}
protected:
// syncs between GUIs and effective settings.
bool push(time_fmt val) override
{
if (*target == val) return false;
// update the setting from radio button state.
*target = val;
// let redraw the ruler of the timeline.
RECT rc;
::GetClientRect(exedit.fp->hwnd, &rc);
rc.left = timeline_layer_header_width;
rc.bottom = timeline_ruler_height;
::InvalidateRect(exedit.fp->hwnd, &rc, FALSE);
return true;
}
};
struct setting_item_dlg_time_fmt : setting_item_time_fmt {
constexpr setting_item_dlg_time_fmt(wchar_t const* title)
: setting_item_time_fmt(exedit.dlg_time_format, title) {}
protected:
// syncs between GUIs and effective settings.
bool push(time_fmt val) override
{
if (*target == val) return false;
// update the setting from radio button state.
*target = val;
// update the top part of the dialog.
exedit.update_dialog_top();
return true;
}
};
// レイヤー幅の選択.
struct setting_item_layer_height : setting_item_radio_base {
constexpr static auto title = L"レイヤーの幅";
constexpr static wchar_t const* label_btn[] = { L"大", L"中", L"小" };
// returns the lengths of { title, maximum of label_btn[*], height }.
static std::tuple<int, int, int> label_size(HWND parent) {
static constinit int label = -1, button = -1, height;
if (label < 0) {
text_measure measure{ parent, aviutl.font };
std::tie(label, height) = measure(title);
for (auto str : label_btn)
button = std::max(button, measure(str).first);
}
return { label, button, height };
}
constexpr static int num_layers = 100;
// GUI elements.
HWND label = nullptr, radio_L = nullptr, radio_M = nullptr, radio_S = nullptr;
int32_t gui_val = 0;
// metrics for small blanks.
constexpr static int gap_title = 8, gap_radio = 12, pad_button = 8;
void on_update() override
{
if (label == nullptr) return;
if (*exedit.layer_size_mode != gui_val) {
// update the check states of radio buttons.
auto prev_val = std::exchange(gui_val, *exedit.layer_size_mode);
::SendMessageW(choose_radio(prev_val), BM_SETCHECK, BST_UNCHECKED, 0);
::SendMessageW(choose_radio(gui_val), BM_SETCHECK, BST_CHECKED, 0);
}
}
bool on_notify(HWND ctrl, uint32_t code) override
{
if (label != nullptr && code == BN_CLICKED) {
auto prev_val = std::exchange(gui_val, ctrl != radio_S ? ctrl != radio_M ? 0 : 1 : 2);
if (prev_val != gui_val) {
::SendMessageW(choose_radio(prev_val), BM_SETCHECK, BST_UNCHECKED, 0);
::SendMessageW(ctrl, BM_SETCHECK, BST_CHECKED, 0);
}
return push(gui_val);
}
return false;
}
bool menu_command() override
{
auto ret = push(toggle(*exedit.layer_size_mode));
on_update();
return ret;
}
wchar_t const* menu_title() const override { return title; }
std::pair<int, int> measure(HWND parent)
{
auto const [title_w, btn_w, height] = label_size(parent);
if (push_like) {
auto const pad = button_pad_size(), pad_h = pad + pad_button;
return { title_w + gap_title + 3 * (pad_h + btn_w), pad + height };
}
else {
auto const [radio_w, radio_h] = min_check_size();
return { title_w + gap_title + 3 * (radio_w + btn_w) + 2 * gap_radio, std::max(radio_h, height) };
}
}
void create(HWND parent, int x, int y, int w, int h)
{
auto const btn_w = std::get<1>(label_size(parent));
if (push_like) {
auto const pad = button_pad_size(), pad_h = pad + pad_button;
// title.
label = create_label(parent, title,
x, y + (pad >> 1), std::max(0, w - 3 * (pad_h + btn_w)), h - pad);
// radio buttons.
radio_L = create_radio(parent, label_btn[0],
x + w - 3 * (pad_h + btn_w), y,
pad_h + btn_w, h, true, BS_PUSHLIKE);
radio_M = create_radio(parent, label_btn[1],
x + w - 2 * (pad_h + btn_w), y,
pad_h + btn_w, h, false, BS_PUSHLIKE);
radio_S = create_radio(parent, label_btn[2],
x + w - (pad_h + btn_w), y, pad_h + btn_w, h, false, BS_PUSHLIKE);
}
else {
auto const radio_w = min_check_size().first;
// title.
label = create_label(parent, title,
x, y, std::max(0, w - (3 * (radio_w + btn_w) + 2 * gap_radio)), h);
// radio buttons.
radio_L = create_radio(parent, label_btn[0],
x + w - (3 * (radio_w + btn_w) + 2 * gap_radio), y,
radio_w + btn_w, h, true);
radio_M = create_radio(parent, label_btn[1],
x + w - (2 * (radio_w + btn_w) + gap_radio), y,
radio_w + btn_w, h, false);
radio_S = create_radio(parent, label_btn[2],
x + w - (radio_w + btn_w), y, radio_w + btn_w, h, false);
}
gui_val = 0;
}
void destroy() override { destroy_windows(label, radio_L, radio_M, radio_S); }
~setting_item_layer_height() override { destroy(); }