Skip to content

Commit b5f00fd

Browse files
authored
Merge pull request #112 from mimaraka/develop
v2.0-beta1.4
2 parents 6ed53a7 + 3ef5e1d commit b5f00fd

25 files changed

Lines changed: 361 additions & 280 deletions

curve_editor/constants.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace curve_editor::global {
2626
inline constexpr auto PLUGIN_VERSION = mkaul::Version{
2727
mkaul::VersionNumber{2},
2828
mkaul::PreviewType{mkaul::PreviewType::Type::Beta},
29-
mkaul::VersionNumber{1, 3, 1}
29+
mkaul::VersionNumber{1, 4}
3030
};
3131
inline constexpr auto PLUGIN_DEVELOPER = L"mimaraka";
3232
inline constexpr auto PLUGIN_TRANSLATOR = L"Deepdive";

curve_editor/curve_editor.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,76 @@ namespace curve_editor::global {
161161
return 0;
162162
}
163163
}
164+
165+
std::optional<double> CurveEditor::get_curve_value(EditMode mode, int32_t param, double progress, double start, double end) const noexcept {
166+
static BezierCurve bezier;
167+
static ElasticCurve elastic;
168+
static BounceCurve bounce;
169+
170+
double ret = 0.;
171+
172+
switch (mode) {
173+
case EditMode::Normal:
174+
{
175+
int idx = param - 1;
176+
if (idx < 0) {
177+
return std::nullopt;
178+
}
179+
auto p_curve_normal = global::editor.editor_graph().p_curve_normal(static_cast<size_t>(idx));
180+
if (p_curve_normal) {
181+
ret = p_curve_normal->get_value(progress, start, end);
182+
}
183+
else {
184+
return std::nullopt;
185+
}
186+
break;
187+
}
188+
189+
case EditMode::Value:
190+
return std::nullopt;
191+
break;
192+
193+
case EditMode::Bezier:
194+
if (!bezier.decode(param)) {
195+
return std::nullopt;
196+
}
197+
ret = bezier.get_value(progress, start, end);
198+
break;
199+
200+
case EditMode::Elastic:
201+
if (!elastic.decode(param)) {
202+
return std::nullopt;
203+
}
204+
ret = elastic.get_value(progress, start, end);
205+
break;
206+
207+
case EditMode::Bounce:
208+
if (!bounce.decode(param)) {
209+
return std::nullopt;
210+
}
211+
ret = bounce.get_value(progress, start, end);
212+
break;
213+
214+
case EditMode::Script:
215+
{
216+
int idx = param - 1;
217+
if (idx < 0) {
218+
return std::nullopt;
219+
}
220+
auto p_curve_script = global::editor.editor_script().p_curve_script(static_cast<size_t>(idx));
221+
if (p_curve_script) {
222+
ret = p_curve_script->get_value(progress, start, end);
223+
}
224+
else {
225+
return std::nullopt;
226+
}
227+
break;
228+
}
229+
230+
default:
231+
return std::nullopt;
232+
}
233+
234+
return ret;
235+
}
164236
} // namespace curve_editor::global

curve_editor/curve_editor.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace curve_editor::global {
1616
public:
1717
CurveEditor() {}
1818

19+
// TODO: 廃止したい
1920
int32_t track_param() noexcept;
2021
Curve* p_current_curve() noexcept;
2122
size_t current_idx() noexcept;
@@ -34,6 +35,8 @@ namespace curve_editor::global {
3435

3536
Curve* get_curve(EditMode mode) noexcept;
3637

38+
std::optional<double> get_curve_value(EditMode mode, int32_t param, double progress, double start, double end) const noexcept;
39+
3740
template <class Archive>
3841
void serialize(Archive& archive, const std::uint32_t) {
3942
archive(

curve_editor/curve_editor.rc

14.8 KB
Binary file not shown.

curve_editor/curve_linear.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
namespace curve_editor {
77
double LinearCurve::curve_function(double progress, double start, double end) const noexcept {
88
progress = mkaul::clamp((progress - anchor_start().x) / (anchor_end().x - anchor_start().x), 0., 1.);
9-
return start + (end - start) * (anchor_start().y + (anchor_end().y - anchor_start().y) * progress);
9+
return start + (end - start) * std::lerp(anchor_start().y, anchor_end().y, progress);
1010
}
1111
} // namespace curve_editor

curve_editor/curve_normal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ namespace curve_editor {
122122
else {
123123
if (*it != curve_segments_.back() and mkaul::in_range(progress, (*it)->anchor_end().x, (*std::next(it))->anchor_start().x, false)) {
124124
// 線形補間
125-
double tmp = (progress - (*it)->anchor_end().x) / ((*std::next(it))->anchor_start().x - (*it)->anchor_end().x);
126-
return ((*std::next(it))->anchor_start().y - (*it)->anchor_end().y) * tmp + (*it)->anchor_end().y;
125+
const double tmp = (progress - (*it)->anchor_end().x) / ((*std::next(it))->anchor_start().x - (*it)->anchor_end().x);
126+
return std::lerp((*it)->anchor_end().y, (*std::next(it))->anchor_start().y, tmp);
127127
}
128128
else if (mkaul::in_range(progress, (*it)->anchor_start().x, (*it)->anchor_end().x)) {
129129
return (*it)->get_value(progress, start, end);

curve_editor/curve_script.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "curve_script.hpp"
2+
#include "curve_editor.hpp"
23
#include <FastNoiseLite.h>
34
#include <sol/sol.hpp>
45
#include <strconv2.h>
@@ -41,14 +42,52 @@ namespace curve_editor {
4142
[noise](double amp, float freq, double phase) { return noise(amp, freq, phase); },
4243
[noise](double amp, float freq) { return noise(amp, freq); },
4344
[noise](double amp) { return noise(amp); },
44-
[noise]() mutable { return noise(); }
45+
[noise]() { return noise(); }
46+
));
47+
lua.set_function("getcurve", sol::overload(
48+
[](std::string mode, int32_t param, double t_, double st_, double ed_) {
49+
return global::editor.get_curve_value(global::editor.get_mode(mode), param, t_, st_, ed_);
50+
},
51+
[st, ed](std::string mode, int32_t param, double t_) {
52+
return global::editor.get_curve_value(global::editor.get_mode(mode), param, t_, st, ed);
53+
},
54+
[t, st, ed](std::string mode, int32_t param) {
55+
return global::editor.get_curve_value(global::editor.get_mode(mode), param, t, st, ed);
56+
},
57+
[](int32_t mode_int, int32_t param, double t_, double st_, double ed_) -> std::optional<double> {
58+
// TODO: lua_export.cppと同じものなので共通化する
59+
EditMode mode = EditMode::NumEditMode;
60+
switch (mode_int) {
61+
case 0:
62+
mode = EditMode::Bezier;
63+
break;
64+
case 1:
65+
mode = EditMode::Normal;
66+
break;
67+
case 2:
68+
mode = EditMode::Value;
69+
break;
70+
case 3:
71+
mode = EditMode::Elastic;
72+
break;
73+
case 4:
74+
mode = EditMode::Bounce;
75+
break;
76+
case 5:
77+
mode = EditMode::Script;
78+
break;
79+
default:
80+
return std::nullopt;
81+
}
82+
return global::editor.get_curve_value(mode, param, t_, st_, ed_);
83+
}
4584
));
4685
try {
4786
auto ret = lua.script(::wide_to_utf8(script_)).get<double>();
4887
return ret;
4988
}
5089
catch (sol::error&) {
51-
return (ed - st) * t + st;
90+
return std::lerp(st, ed, t);
5291
}
5392
}
5493

curve_editor/dialog_pref_appearance.cpp

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@ namespace curve_editor {
3636
hwnd_check_enable_animation_ = ::GetDlgItem(hwnd, IDC_CHECK_ENABLE_ANIMATION);
3737

3838
for (uint32_t i = 0u; i < (uint32_t)ThemeId::NumThemeId; i++) {
39-
::SendMessageW(
39+
::SendMessage(
4040
hwnd_combo_theme_,
4141
CB_ADDSTRING,
4242
NULL,
4343
(LPARAM)global::string_table[(StringId)((uint32_t)StringId::ThemeSystem + i)]
4444
);
4545
}
4646

47-
::SendMessageA(hwnd_slider_curve_thickness_, TBM_SETRANGE, TRUE, MAKELPARAM(1, 100));
48-
::SendMessageA(hwnd_slider_curve_quality_, TBM_SETRANGE, TRUE, MAKELPARAM(100, 1000));
49-
::SendMessageA(hwnd_slider_bg_image_opacity_, TBM_SETRANGE, TRUE, MAKELPARAM(0, 100));
50-
::SendMessageA(hwnd_slider_apply_button_height_, TBM_SETRANGE, TRUE, MAKELPARAM(30, 200));
47+
::SendMessage(hwnd_slider_curve_thickness_, TBM_SETRANGE, TRUE, MAKELPARAM(1, 100));
48+
::SendMessage(hwnd_slider_curve_quality_, TBM_SETRANGE, TRUE, MAKELPARAM(100, 1000));
49+
::SendMessage(hwnd_slider_bg_image_opacity_, TBM_SETRANGE, TRUE, MAKELPARAM(0, 100));
50+
::SendMessage(hwnd_slider_apply_button_height_, TBM_SETRANGE, TRUE, MAKELPARAM(30, 200));
5151
}
5252

5353

5454
INT_PTR AppearancePrefDialog::dialog_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
5555
using StringId = global::StringTable::StringId;
5656
static COLORREF custom_colors[16];
57-
static CHOOSECOLORA cc{
58-
.lStructSize = sizeof(CHOOSECOLORA),
57+
static CHOOSECOLOR cc{
58+
.lStructSize = sizeof(CHOOSECOLOR),
5959
.lpCustColors = custom_colors,
6060
.Flags = CC_FULLOPEN | CC_RGBINIT
6161
};
62-
static char image_path[MAX_PATH + 1];
63-
image_path[MAX_PATH] = '\0';
62+
static wchar_t image_path[MAX_PATH + 1];
63+
image_path[MAX_PATH] = L'\0';
6464

6565
switch (message) {
6666
case WM_INITDIALOG:
@@ -71,20 +71,20 @@ namespace curve_editor {
7171

7272
case WM_HSCROLL:
7373
if (lparam == (LPARAM)hwnd_slider_curve_thickness_) {
74-
int value_int = ::SendMessageA(hwnd_slider_curve_thickness_, TBM_GETPOS, NULL, NULL);
75-
::SetWindowTextA(hwnd_static_curve_thickness_, std::format("{:.1f}", value_int * 0.1f).c_str());
74+
int value_int = ::SendMessage(hwnd_slider_curve_thickness_, TBM_GETPOS, NULL, NULL);
75+
::SetWindowText(hwnd_static_curve_thickness_, std::format(L"{:.1f}", value_int * 0.1f).c_str());
7676
}
7777
else if (lparam == (LPARAM)hwnd_slider_curve_quality_) {
78-
int value_int = ::SendMessageA(hwnd_slider_curve_quality_, TBM_GETPOS, NULL, NULL);
79-
::SetWindowTextA(hwnd_static_curve_quality_, std::format("{}", value_int).c_str());
78+
int value_int = ::SendMessage(hwnd_slider_curve_quality_, TBM_GETPOS, NULL, NULL);
79+
::SetWindowText(hwnd_static_curve_quality_, std::format(L"{}", value_int).c_str());
8080
}
8181
else if (lparam == (LPARAM)hwnd_slider_bg_image_opacity_) {
82-
int value_int = ::SendMessageA(hwnd_slider_bg_image_opacity_, TBM_GETPOS, NULL, NULL);
83-
::SetWindowTextA(hwnd_static_bg_image_opacity_, std::format("{}%", value_int).c_str());
82+
int value_int = ::SendMessage(hwnd_slider_bg_image_opacity_, TBM_GETPOS, NULL, NULL);
83+
::SetWindowText(hwnd_static_bg_image_opacity_, std::format(L"{}%", value_int).c_str());
8484
}
8585
else if (lparam == (LPARAM)hwnd_slider_apply_button_height_) {
86-
int value_int = ::SendMessageA(hwnd_slider_apply_button_height_, TBM_GETPOS, NULL, NULL);
87-
::SetWindowTextA(hwnd_static_apply_button_height_, std::format("{}", value_int).c_str());
86+
int value_int = ::SendMessage(hwnd_slider_apply_button_height_, TBM_GETPOS, NULL, NULL);
87+
::SetWindowText(hwnd_static_apply_button_height_, std::format(L"{}", value_int).c_str());
8888
}
8989
return TRUE;
9090

@@ -110,20 +110,20 @@ namespace curve_editor {
110110
case (UINT)WindowCommand::LoadConfig:
111111
cc.rgbResult = global::config.get_curve_color().colorref();
112112
::InvalidateRect(hwnd, NULL, FALSE);
113-
::SendMessageA(hwnd_combo_theme_, CB_SETCURSEL, (WPARAM)global::config.get_theme(), NULL);
114-
::SendMessageA(
113+
::SendMessage(hwnd_combo_theme_, CB_SETCURSEL, (WPARAM)global::config.get_theme(), NULL);
114+
::SendMessage(
115115
hwnd_check_show_trace_,
116116
BM_SETCHECK,
117117
(WPARAM)global::config.get_show_trace(),
118118
NULL
119119
);
120-
::SendMessageA(
120+
::SendMessage(
121121
hwnd_check_set_bg_image_,
122122
BM_SETCHECK,
123123
(WPARAM)global::config.get_show_bg_image(),
124124
NULL
125125
);
126-
::SendMessageA(
126+
::SendMessage(
127127
hwnd_check_enable_animation_,
128128
BM_SETCHECK,
129129
(WPARAM)global::config.get_enable_animation(),
@@ -145,49 +145,49 @@ namespace curve_editor {
145145
::EnableWindow(hwnd_slider_bg_image_opacity_, FALSE);
146146
::EnableWindow(hwnd_static_bg_image_opacity_, FALSE);
147147
};
148-
::SetWindowTextA(hwnd_edit_bg_image_path_, global::config.get_bg_image_path().string().c_str());
149-
::SendMessageA(hwnd_edit_bg_image_path_, EM_SETLIMITTEXT, MAX_PATH, NULL);
148+
::SetWindowText(hwnd_edit_bg_image_path_, global::config.get_bg_image_path().wstring().c_str());
149+
::SendMessage(hwnd_edit_bg_image_path_, EM_SETLIMITTEXT, MAX_PATH, NULL);
150150

151-
::SendMessageA(hwnd_slider_curve_thickness_, TBM_SETPOS, TRUE, (LPARAM)(global::config.get_curve_thickness() * 10.f));
152-
::SendMessageA(hwnd_slider_curve_quality_, TBM_SETPOS, TRUE, (LPARAM)(global::config.get_curve_resolution()));
153-
::SendMessageA(hwnd_slider_bg_image_opacity_, TBM_SETPOS, TRUE, (LPARAM)round(global::config.get_bg_image_opacity() * 100.f));
154-
::SendMessageA(hwnd_slider_apply_button_height_, TBM_SETPOS, TRUE, (LPARAM)global::config.get_apply_button_height());
151+
::SendMessage(hwnd_slider_curve_thickness_, TBM_SETPOS, TRUE, (LPARAM)(global::config.get_curve_thickness() * 10.f));
152+
::SendMessage(hwnd_slider_curve_quality_, TBM_SETPOS, TRUE, (LPARAM)(global::config.get_curve_resolution()));
153+
::SendMessage(hwnd_slider_bg_image_opacity_, TBM_SETPOS, TRUE, (LPARAM)round(global::config.get_bg_image_opacity() * 100.f));
154+
::SendMessage(hwnd_slider_apply_button_height_, TBM_SETPOS, TRUE, (LPARAM)global::config.get_apply_button_height());
155155

156-
::SendMessageA(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_curve_thickness_);
157-
::SendMessageA(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_curve_quality_);
158-
::SendMessageA(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_bg_image_opacity_);
159-
::SendMessageA(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_apply_button_height_);
156+
::SendMessage(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_curve_thickness_);
157+
::SendMessage(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_curve_quality_);
158+
::SendMessage(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_bg_image_opacity_);
159+
::SendMessage(hwnd, WM_HSCROLL, NULL, (LPARAM)hwnd_slider_apply_button_height_);
160160

161161
return TRUE;
162162

163163
case (UINT)WindowCommand::SaveConfig:
164-
global::config.set_theme((ThemeId)::SendMessageA(hwnd_combo_theme_, CB_GETCURSEL, NULL, NULL));
165-
global::config.set_show_trace((bool)::SendMessageA(hwnd_check_show_trace_, BM_GETCHECK, NULL, NULL));
166-
global::config.set_show_bg_image((bool)::SendMessageA(hwnd_check_set_bg_image_, BM_GETCHECK, NULL, NULL));
167-
global::config.set_enable_animation((bool)::SendMessageA(hwnd_check_enable_animation_, BM_GETCHECK, NULL, NULL));
164+
global::config.set_theme((ThemeId)::SendMessage(hwnd_combo_theme_, CB_GETCURSEL, NULL, NULL));
165+
global::config.set_show_trace((bool)::SendMessage(hwnd_check_show_trace_, BM_GETCHECK, NULL, NULL));
166+
global::config.set_show_bg_image((bool)::SendMessage(hwnd_check_set_bg_image_, BM_GETCHECK, NULL, NULL));
167+
global::config.set_enable_animation((bool)::SendMessage(hwnd_check_enable_animation_, BM_GETCHECK, NULL, NULL));
168168
global::config.set_curve_color(cc.rgbResult);
169169
global::config.set_curve_thickness(
170-
(float)::SendMessageA(hwnd_slider_curve_thickness_, TBM_GETPOS, NULL, NULL) * 0.1f
170+
(float)::SendMessage(hwnd_slider_curve_thickness_, TBM_GETPOS, NULL, NULL) * 0.1f
171171
);
172172
global::config.set_curve_resolution(
173-
(uint32_t)::SendMessageA(hwnd_slider_curve_quality_, TBM_GETPOS, NULL, NULL)
173+
(uint32_t)::SendMessage(hwnd_slider_curve_quality_, TBM_GETPOS, NULL, NULL)
174174
);
175175
global::config.set_bg_image_opacity(
176-
(float)::SendMessageA(hwnd_slider_bg_image_opacity_, TBM_GETPOS, NULL, NULL) * 0.01f
176+
(float)::SendMessage(hwnd_slider_bg_image_opacity_, TBM_GETPOS, NULL, NULL) * 0.01f
177177
);
178178
global::config.set_apply_button_height(
179-
(uint32_t)::SendMessageA(hwnd_slider_apply_button_height_, TBM_GETPOS, NULL, NULL)
179+
(uint32_t)::SendMessage(hwnd_slider_apply_button_height_, TBM_GETPOS, NULL, NULL)
180180
);
181181
{
182-
char buffer[MAX_PATH];
183-
::GetWindowTextA(hwnd_edit_bg_image_path_, buffer, MAX_PATH);
182+
wchar_t buffer[MAX_PATH];
183+
::GetWindowTextW(hwnd_edit_bg_image_path_, buffer, MAX_PATH);
184184
global::config.set_bg_image_path(std::filesystem::path(buffer));
185185
}
186186
if (global::webview) global::webview->update_color_scheme();
187187
return TRUE;
188188

189189
case IDC_BUTTON_CURVE_COLOR:
190-
if (::ChooseColorA(&cc)) {
190+
if (::ChooseColor(&cc)) {
191191
::InvalidateRect(hwnd, NULL, FALSE);
192192
}
193193
return TRUE;
@@ -221,17 +221,17 @@ namespace curve_editor {
221221
global::string_table[StringId::WordImageFile],
222222
TEMPLATE_IMAGE
223223
);
224-
OPENFILENAMEW ofn{
225-
.lStructSize = sizeof(OPENFILENAMEA),
224+
OPENFILENAME ofn{
225+
.lStructSize = sizeof(OPENFILENAME),
226226
.hwndOwner = hwnd,
227227
.lpstrFilter = str_filter.c_str(),
228-
.lpstrFile = const_cast<wchar_t*>(::sjis_to_wide(image_path).c_str()),
228+
.lpstrFile = image_path,
229229
.nMaxFile = MAX_PATH + 1,
230230
.lpstrTitle = global::string_table[StringId::CaptionSelectBackgroundImage],
231231
.Flags = OFN_FILEMUSTEXIST
232232
};
233-
if (::GetOpenFileNameW(&ofn)) {
234-
::SetWindowTextW(hwnd_edit_bg_image_path_, ofn.lpstrFile);
233+
if (::GetOpenFileName(&ofn)) {
234+
::SetWindowText(hwnd_edit_bg_image_path_, ofn.lpstrFile);
235235
}
236236
return TRUE;
237237
}

curve_editor/host_object_preset.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace curve_editor {
2121
register_member(L"getCollectionName", DispatchType::Method, +[](uint32_t id) { return global::preset_manager.get_collection_name(id); });
2222
register_member(L"currentCollectionId", DispatchType::PropertyGet, +[]() { return global::preset_manager.get_current_collection_id(); });
2323
register_member(L"currentCollectionId", DispatchType::PropertyPut, +[](uint32_t id) { global::preset_manager.set_current_collection_id(id); });
24+
register_member(L"numCollections", DispatchType::PropertyGet, +[]() { return global::preset_manager.get_num_collections(); });
2425
register_member(L"sortBy", DispatchType::PropertyGet, +[]() { return magic_enum::enum_name(global::preset_manager.get_sort_by()).data(); });
2526
register_member(L"sortOrder", DispatchType::PropertyGet, +[]() { return magic_enum::enum_name(global::preset_manager.get_sort_order()).data(); });
2627
register_member(L"getFilterInfoAsJson", DispatchType::Method, get_filter_info_as_json);

0 commit comments

Comments
 (0)