Skip to content

Commit 9b01a92

Browse files
committed
カーブをプロジェクトファイルに保存する機能を実装
1 parent d5734ec commit 9b01a92

15 files changed

+541
-413
lines changed

curve_editor/ce_curve_id.cpp

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

curve_editor/ce_curve_value.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
//---------------------------------------------------------------------
1111
// 指定した座標が制御点の内部に存在するか
1212
//---------------------------------------------------------------------
13-
int ce::Curve_Value::point_in_control_points(POINT cl_pt)
13+
int ce::Curve_Value::point_in_ctpts(POINT cl_pt)
1414
{
1515
RECT rcCtpt1 = {
16-
to_client(control_point[0]).x - CE_POINT_RANGE,
17-
to_client(control_point[0]).y - CE_POINT_RANGE,
18-
to_client(control_point[0]).x + CE_POINT_RANGE,
19-
to_client(control_point[0]).y + CE_POINT_RANGE
16+
to_client(ctpt[0]).x - CE_POINT_RANGE,
17+
to_client(ctpt[0]).y - CE_POINT_RANGE,
18+
to_client(ctpt[0]).x + CE_POINT_RANGE,
19+
to_client(ctpt[0]).y + CE_POINT_RANGE
2020
};
2121
RECT rcCtpt2 = {
22-
to_client(control_point[1]).x - CE_POINT_RANGE,
23-
to_client(control_point[1]).y - CE_POINT_RANGE,
24-
to_client(control_point[1]).x + CE_POINT_RANGE,
25-
to_client(control_point[1]).y + CE_POINT_RANGE
22+
to_client(ctpt[1]).x - CE_POINT_RANGE,
23+
to_client(ctpt[1]).y - CE_POINT_RANGE,
24+
to_client(ctpt[1]).x + CE_POINT_RANGE,
25+
to_client(ctpt[1]).y + CE_POINT_RANGE
2626
};
2727
if (PtInRect(&rcCtpt2, cl_pt))
2828
return 2;
@@ -50,31 +50,31 @@ void ce::Curve_Value::move_point(int index, POINT gr_pt)
5050
//Altキーが押されている間
5151
else if (GetAsyncKeyState(VK_MENU) < 0) {
5252
//X
53-
g_curve_value.control_point[index].x = MINMAXLIM(gr_pt.x, 0, CE_GR_RES);
53+
g_curve_value.ctpt[index].x = MINMAXLIM(gr_pt.x, 0, CE_GR_RES);
5454
//Y
5555
//Anti-ZeroDivisionError
5656
if (!index) {
5757
if (ptLock.x < 0)
58-
g_curve_value.control_point[0].y = gr_pt.y;
58+
g_curve_value.ctpt[0].y = gr_pt.y;
5959
else
60-
g_curve_value.control_point[0].y = (int)(g_curve_value.control_point[0].x * ptLock.y / (double)ptLock.x);
60+
g_curve_value.ctpt[0].y = (int)(g_curve_value.ctpt[0].x * ptLock.y / (double)ptLock.x);
6161
}
6262
else {
6363
if (ptLock.x > CE_GR_RES)
64-
g_curve_value.control_point[1].y = gr_pt.y;
64+
g_curve_value.ctpt[1].y = gr_pt.y;
6565
else
66-
g_curve_value.control_point[1].y
67-
= CE_GR_RES - (int)((CE_GR_RES - (int)g_curve_value.control_point[1].x) * (CE_GR_RES - ptLock.y) / (double)(CE_GR_RES - ptLock.x));
66+
g_curve_value.ctpt[1].y
67+
= CE_GR_RES - (int)((CE_GR_RES - (int)g_curve_value.ctpt[1].x) * (CE_GR_RES - ptLock.y) / (double)(CE_GR_RES - ptLock.x));
6868
}
6969
}
7070
//同時に動かす
7171
else if (GetAsyncKeyState(VK_SHIFT) < 0 && GetAsyncKeyState(VK_CONTROL) < 0) {
7272
//X
73-
g_curve_value.control_point[index].x = gr_pt.x;
74-
g_curve_value.control_point[!index].x = MINMAXLIM(CE_GR_RES - g_curve_value.control_point[index].x, 0, CE_GR_RES);
73+
g_curve_value.ctpt[index].x = gr_pt.x;
74+
g_curve_value.ctpt[!index].x = MINMAXLIM(CE_GR_RES - g_curve_value.ctpt[index].x, 0, CE_GR_RES);
7575
//Y
76-
g_curve_value.control_point[index].y = gr_pt.y;
77-
g_curve_value.control_point[!index].y = CE_GR_RES - g_curve_value.control_point[index].y;
76+
g_curve_value.ctpt[index].y = gr_pt.y;
77+
g_curve_value.ctpt[!index].y = CE_GR_RES - g_curve_value.ctpt[index].y;
7878
bCtrlKey = FALSE;
7979
bAltKey = FALSE;
8080
bShiftKey = FALSE;
@@ -89,13 +89,13 @@ void ce::Curve_Value::move_point(int index, POINT gr_pt)
8989
}
9090
//While the Shift Key is being pressed
9191
else if (GetAsyncKeyState(VK_SHIFT) < 0) {
92-
g_curve_value.control_point[index].x = gr_pt.x;
92+
g_curve_value.ctpt[index].x = gr_pt.x;
9393
//if Y is larger than 500
9494
if (ptLock.y < CE_GR_RES / 2)
95-
g_curve_value.control_point[index].y = 0;
95+
g_curve_value.ctpt[index].y = 0;
9696
//if Y is less than 500
9797
else if (ptLock.y >= CE_GR_RES / 2)
98-
g_curve_value.control_point[index].y = CE_GR_RES;
98+
g_curve_value.ctpt[index].y = CE_GR_RES;
9999
}
100100
//The moment the Control Key is pressed
101101
else if (GetAsyncKeyState(VK_CONTROL) < 0 && !bCtrlKey) {
@@ -118,34 +118,34 @@ void ce::Curve_Value::move_point(int index, POINT gr_pt)
118118
intResult_x = CE_GR_RES - (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES) * std::cos(theta));
119119
intResult_y = CE_GR_RES - (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES) * std::sin(theta));
120120
}
121-
g_curve_value.control_point[index].x = intResult_x;
121+
g_curve_value.ctpt[index].x = intResult_x;
122122
//Y
123123
if (!index) {
124124
if (theta > MATH_PI * 0.5)
125-
g_curve_value.control_point[0].y = (int)(DISTANCE1(ptLock));
125+
g_curve_value.ctpt[0].y = (int)(DISTANCE1(ptLock));
126126

127127
else if (theta < -MATH_PI * 0.5)
128-
g_curve_value.control_point[0].y = (int)-(DISTANCE1(ptLock));
128+
g_curve_value.ctpt[0].y = (int)-(DISTANCE1(ptLock));
129129

130-
else g_curve_value.control_point[0].y = intResult_y;
130+
else g_curve_value.ctpt[0].y = intResult_y;
131131
}
132132
else {
133133
if (theta > MATH_PI * 0.5)
134-
g_curve_value.control_point[1].y = CE_GR_RES - (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES));
134+
g_curve_value.ctpt[1].y = CE_GR_RES - (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES));
135135

136136
else if (theta < -MATH_PI * 0.5)
137-
g_curve_value.control_point[1].y = CE_GR_RES + (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES));
137+
g_curve_value.ctpt[1].y = CE_GR_RES + (int)(DISTANCE2(ptLock, CE_GR_RES, CE_GR_RES));
138138

139-
else g_curve_value.control_point[1].y = intResult_y;
139+
else g_curve_value.ctpt[1].y = intResult_y;
140140
}
141141
}
142142
//Nomal Mode
143143
else {
144-
g_curve_value.control_point[index] = gr_pt;
144+
g_curve_value.ctpt[index] = gr_pt;
145145
bCtrlKey = FALSE;
146146
bAltKey = FALSE;
147147
bShiftKey = FALSE;
148148
}
149149

150-
g_curve_value.control_point[index].x = MINMAXLIM(g_curve_value.control_point[index].x, 0, CE_GR_RES);
150+
g_curve_value.ctpt[index].x = MINMAXLIM(g_curve_value.ctpt[index].x, 0, CE_GR_RES);
151151
}

curve_editor/ce_dlgproc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ BOOL CALLBACK wndproc_daialog_value(HWND hDlg, UINT msg, WPARAM wparam, LPARAM l
8080
if (std::regex_match(chBuffer, re)) {
8181
std::string str = chBuffer;
8282
std::vector<std::string> vec = split(chBuffer, ',');
83-
g_curve_value.control_point[0].x = (int)(std::stod(vec[0]) * 1000);
84-
g_curve_value.control_point[0].x = (int)(std::stod(vec[0]) * 1000);
85-
g_curve_value.control_point[0].y = (int)(std::stod(vec[1]) * 1000);
86-
g_curve_value.control_point[1].x = (int)(std::stod(vec[2]) * 1000);
87-
g_curve_value.control_point[1].y = (int)(std::stod(vec[3]) * 1000);
83+
g_curve_value.ctpt[0].x = (int)(std::stod(vec[0]) * 1000);
84+
g_curve_value.ctpt[0].x = (int)(std::stod(vec[0]) * 1000);
85+
g_curve_value.ctpt[0].y = (int)(std::stod(vec[1]) * 1000);
86+
g_curve_value.ctpt[1].x = (int)(std::stod(vec[2]) * 1000);
87+
g_curve_value.ctpt[1].y = (int)(std::stod(vec[3]) * 1000);
8888

8989
for (int i = 0; i < 2; i++) {
90-
if (g_curve_value.control_point[i].y > 3730) g_curve_value.control_point[i].y = 3730;
91-
else if (g_curve_value.control_point[i].y < -2730) g_curve_value.control_point[i].y = -2730;
90+
if (g_curve_value.ctpt[i].y > 3730) g_curve_value.ctpt[i].y = 3730;
91+
else if (g_curve_value.ctpt[i].y < -2730) g_curve_value.ctpt[i].y = -2730;
9292
}
9393
EndDialog(hDlg, 1);
9494
}
@@ -209,7 +209,7 @@ BOOL CALLBACK wndproc_daialog_save(HWND hDlg, UINT msg, WPARAM wparam, LPARAM lp
209209
ce::Preset_Value additem;
210210
GetDlgItemText(hDlg, IDC_EDIT_SAVE, chBuffer, 64);
211211
if (strlen(chBuffer) < 64 && strlen(chBuffer) != 0) {
212-
additem = { chBuffer, g_curve_value.control_point[0].x, g_curve_value.control_point[0].y, g_curve_value.control_point[1].x, g_curve_value.control_point[1].y };
212+
additem = { chBuffer, g_curve_value.ctpt[0].x, g_curve_value.ctpt[0].y, g_curve_value.ctpt[1].x, g_curve_value.ctpt[1].y };
213213
g_presets_value.emplace_back(additem);
214214
EndDialog(hDlg, 1);
215215
}

curve_editor/ce_func.cpp

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ BOOL initialize(FILTER* fp)
3333
//---------------------------------------------------------------------
3434
BOOL exit(FILTER* fp)
3535
{
36-
fp->exfunc->ini_save_int(fp, "x1", g_curve_value.control_point[0].x);
37-
fp->exfunc->ini_save_int(fp, "y1", g_curve_value.control_point[0].y);
38-
fp->exfunc->ini_save_int(fp, "x2", g_curve_value.control_point[1].x);
39-
fp->exfunc->ini_save_int(fp, "y2", g_curve_value.control_point[1].y);
36+
fp->exfunc->ini_save_int(fp, "x1", g_curve_value.ctpt[0].x);
37+
fp->exfunc->ini_save_int(fp, "y1", g_curve_value.ctpt[0].y);
38+
fp->exfunc->ini_save_int(fp, "x2", g_curve_value.ctpt[1].x);
39+
fp->exfunc->ini_save_int(fp, "y2", g_curve_value.ctpt[1].y);
4040
fp->exfunc->ini_save_int(fp, "separator", g_config.separator);
4141
fp->exfunc->ini_save_int(fp, "mode", g_config.mode);
4242
fp->exfunc->ini_save_int(fp, "align_mode", g_config.align_mode);
@@ -51,6 +51,37 @@ BOOL exit(FILTER* fp)
5151
}
5252

5353

54+
55+
//---------------------------------------------------------------------
56+
// プロジェクトファイル読み込み時に実行される関数
57+
//---------------------------------------------------------------------
58+
BOOL on_project_load(FILTER* fp, void* editp, void* data, int size)
59+
{
60+
if (data) {
61+
memcpy(g_curve_id, data, size);
62+
}
63+
return TRUE;
64+
}
65+
66+
67+
68+
//---------------------------------------------------------------------
69+
// プロジェクトファイル保存時に実行される関数
70+
//---------------------------------------------------------------------
71+
BOOL on_project_save(FILTER* fp, void* editp, void* data, int* size)
72+
{
73+
int size_curve_id = sizeof(ce::Points_ID) * CE_POINT_MAX * CE_CURVE_MAX;
74+
if (!data) {
75+
*size = sizeof(g_curve_id);
76+
}
77+
else {
78+
memcpy(data, g_curve_id, sizeof(g_curve_id));
79+
}
80+
return TRUE;
81+
}
82+
83+
84+
5485
//---------------------------------------------------------------------
5586
// aviutl.iniから設定を読み込み
5687
//---------------------------------------------------------------------
@@ -61,10 +92,10 @@ void ini_load_configs(FILTER* fp)
6192
g_config.alert = fp->exfunc->ini_load_int(fp, "show_alerts", 1);
6293
g_config.auto_copy = fp->exfunc->ini_load_int(fp, "auto_copy", 0);
6394
g_config.id_current = fp->exfunc->ini_load_int(fp, "id", 0);
64-
g_curve_value.control_point[0].x = fp->exfunc->ini_load_int(fp, "x1", 400);
65-
g_curve_value.control_point[0].y = fp->exfunc->ini_load_int(fp, "y1", 400);
66-
g_curve_value.control_point[1].x = fp->exfunc->ini_load_int(fp, "x2", 600);
67-
g_curve_value.control_point[1].y = fp->exfunc->ini_load_int(fp, "y2", 600);
95+
g_curve_value.ctpt[0].x = fp->exfunc->ini_load_int(fp, "x1", 400);
96+
g_curve_value.ctpt[0].y = fp->exfunc->ini_load_int(fp, "y1", 400);
97+
g_curve_value.ctpt[1].x = fp->exfunc->ini_load_int(fp, "x2", 600);
98+
g_curve_value.ctpt[1].y = fp->exfunc->ini_load_int(fp, "y2", 600);
6899
g_config.separator = fp->exfunc->ini_load_int(fp, "separator", 200);
69100
g_config.mode = fp->exfunc->ini_load_int(fp, "mode", 0);
70101
g_config.align_mode = fp->exfunc->ini_load_int(fp, "align_mode", 1);
@@ -136,16 +167,16 @@ void read_value(int value)
136167
UINT usint;
137168
if (value < 0) usint = value + 2147483647;
138169
else usint = (UINT)value + (UINT)2147483647;
139-
g_curve_value.control_point[1].y = usint / 6600047;
140-
g_curve_value.control_point[1].x = (usint - g_curve_value.control_point[1].y * 6600047) / 65347;
141-
g_curve_value.control_point[0].y = (usint - (g_curve_value.control_point[1].y * 6600047 + g_curve_value.control_point[1].x * 65347)) / 101;
142-
g_curve_value.control_point[0].x = (usint - (g_curve_value.control_point[1].y * 6600047 + g_curve_value.control_point[1].x * 65347)) % 101;
143-
g_curve_value.control_point[0].x *= CE_GR_RES / 100;
144-
g_curve_value.control_point[0].y *= CE_GR_RES / 100;
145-
g_curve_value.control_point[1].x *= CE_GR_RES / 100;
146-
g_curve_value.control_point[1].y *= CE_GR_RES / 100;
147-
g_curve_value.control_point[0].y -= 273;
148-
g_curve_value.control_point[0].y -= 273;
170+
g_curve_value.ctpt[1].y = usint / 6600047;
171+
g_curve_value.ctpt[1].x = (usint - g_curve_value.ctpt[1].y * 6600047) / 65347;
172+
g_curve_value.ctpt[0].y = (usint - (g_curve_value.ctpt[1].y * 6600047 + g_curve_value.ctpt[1].x * 65347)) / 101;
173+
g_curve_value.ctpt[0].x = (usint - (g_curve_value.ctpt[1].y * 6600047 + g_curve_value.ctpt[1].x * 65347)) % 101;
174+
g_curve_value.ctpt[0].x *= CE_GR_RES / 100;
175+
g_curve_value.ctpt[0].y *= CE_GR_RES / 100;
176+
g_curve_value.ctpt[1].x *= CE_GR_RES / 100;
177+
g_curve_value.ctpt[1].y *= CE_GR_RES / 100;
178+
g_curve_value.ctpt[0].y -= 273;
179+
g_curve_value.ctpt[0].y -= 273;
149180
}
150181

151182

@@ -179,12 +210,12 @@ std::string create_value_4d()
179210
FLOAT ptx, pty;
180211
std::string strx, stry, strResult;
181212
for (int i = 0; i < 2; i++) {
182-
ptx = std::round(g_curve_value.control_point[i].x * 100 / (double)CE_GR_RES) * 0.01;
183-
pty = std::round(g_curve_value.control_point[i].y * 100 / (double)CE_GR_RES) * 0.01;
213+
ptx = std::round(g_curve_value.ctpt[i].x * 100 / (double)CE_GR_RES) * 0.01;
214+
pty = std::round(g_curve_value.ctpt[i].y * 100 / (double)CE_GR_RES) * 0.01;
184215
strx = std::to_string(ptx);
185216
stry = std::to_string(pty);
186217
strx.erase(4);
187-
if (g_curve_value.control_point[i].y < 0) stry.erase(5);
218+
if (g_curve_value.ctpt[i].y < 0) stry.erase(5);
188219
else stry.erase(4);
189220
strResult += strx + ", " + stry + ", ";
190221
}
@@ -200,10 +231,10 @@ int create_value_1d()
200231
{
201232
int result;
202233
int x1, y1, x2, y2;
203-
x1 = (int)std::round(g_curve_value.control_point[0].x * 100 / (double)CE_GR_RES);
204-
y1 = (int)std::round(g_curve_value.control_point[0].y * 100 / (double)CE_GR_RES);
205-
x2 = (int)std::round(g_curve_value.control_point[1].x * 100 / (double)CE_GR_RES);
206-
y2 = (int)std::round(g_curve_value.control_point[1].y * 100 / (double)CE_GR_RES);
234+
x1 = (int)std::round(g_curve_value.ctpt[0].x * 100 / (double)CE_GR_RES);
235+
y1 = (int)std::round(g_curve_value.ctpt[0].y * 100 / (double)CE_GR_RES);
236+
x2 = (int)std::round(g_curve_value.ctpt[1].x * 100 / (double)CE_GR_RES);
237+
y2 = (int)std::round(g_curve_value.ctpt[1].y * 100 / (double)CE_GR_RES);
207238
//Limit Values
208239
if (y1 < -273 || 373 < y1 || y2 < -273 || 373 < y2) {
209240
return CE_OUTOFRANGE;

0 commit comments

Comments
 (0)