Skip to content

Commit e8a260f

Browse files
committed
カーブの仕様変更2
1 parent 7762b9c commit e8a260f

File tree

9 files changed

+371
-117
lines changed

9 files changed

+371
-117
lines changed

curve_editor/ce_bitmap_buffer.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ void ce::Bitmap_Buffer::init(HWND hw)
1919
bitmap = CreateCompatibleBitmap(hdc, CE_MAX_W, CE_MAX_H);
2020
SelectObject(hdc_memory, bitmap);
2121
ReleaseDC(hw, hdc);
22+
23+
if (brush == nullptr)
24+
g_render_target->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
2225
}
2326

2427

@@ -30,18 +33,53 @@ void ce::Bitmap_Buffer::exit() const
3033
{
3134
DeleteDC(hdc_memory);
3235
DeleteObject(bitmap);
36+
37+
brush->Release();
38+
}
39+
40+
41+
42+
//---------------------------------------------------------------------
43+
// RenderTargetをDCにバインド & 背景を塗りつぶし
44+
//---------------------------------------------------------------------
45+
bool ce::Bitmap_Buffer::d2d_setup(COLORREF cr)
46+
{
47+
if (g_render_target != nullptr && g_d2d1_factory != nullptr) {
48+
g_render_target->BindDC(hdc_memory, &rect);
49+
g_render_target->BeginDraw();
50+
g_render_target->SetTransform(D2D1::Matrix3x2F::Identity());
51+
g_render_target->Clear(D2D1::ColorF(cr));
52+
g_render_target->EndDraw();
53+
return true;
54+
}
55+
else
56+
return false;
3357
}
3458

3559

3660

61+
62+
63+
64+
3765
//---------------------------------------------------------------------
3866
// ビットマップをバッファから画面に転送
3967
//---------------------------------------------------------------------
40-
void ce::Bitmap_Buffer::transfer(const RECT& rect) const
68+
void ce::Bitmap_Buffer::transfer() const
4169
{
4270
PAINTSTRUCT ps;
4371
HDC hdc = BeginPaint(hwnd, &ps);
4472
BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdc_memory, 0, 0, SRCCOPY);
4573
EndPaint(hwnd, &ps);
4674
DeleteDC(hdc);
75+
}
76+
77+
78+
79+
//---------------------------------------------------------------------
80+
// サイズを更新
81+
//---------------------------------------------------------------------
82+
void ce::Bitmap_Buffer::set_size(const RECT& rect_wnd)
83+
{
84+
rect = rect_wnd;
4785
}

curve_editor/ce_classes.hpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,38 @@ namespace ce {
2828

2929

3030
//---------------------------------------------------------------------
31-
// カーブ
31+
// カーブ(2048バイト)
3232
//---------------------------------------------------------------------
3333
class Curve {
3434
private:
3535
void set_handle_position(const Point_Address& pt_address, const POINT& pt_graph, double length, bool use_angle, double angle);
3636
void correct_handle(const Point_Address& pt_address, double angle);
3737
double get_handle_angle(const Point_Address& pt_address);
3838
void set_handle_angle(const Point_Address& pt_address, double angle, bool use_length, double lgth);
39+
void draw_bezier(
40+
ID2D1SolidColorBrush* brush,
41+
const ce::Float_Point& stpt,
42+
const ce::Float_Point& ctpt1,
43+
const ce::Float_Point& ctpt2,
44+
const ce::Float_Point& edpt,
45+
float thickness
46+
);
47+
void draw_handle(ID2D1SolidColorBrush* brush, const ce::Float_Point& st, const ce::Float_Point& ed);
3948

4049
public:
4150
ce::Static_Array<Curve_Points, CE_POINT_MAX> ctpts;
42-
Mode mode;
51+
Mode mode = Mode_Value;
52+
53+
Curve() { initialize(); }
4354

4455
// 共通
4556
void initialize();
46-
void initialize(Mode md);
57+
void set_mode(Mode md);
4758
void clear();
4859
void pt_in_ctpt(const POINT& pt_client, Point_Address* pt_address);
4960
void reverse_curve();
61+
void draw_curve(ID2D1SolidColorBrush* brush);
62+
bool is_data_valid();
5063

5164
// Valueモード用
5265
int create_value_1d();
@@ -64,18 +77,30 @@ namespace ce {
6477

6578

6679
//---------------------------------------------------------------------
67-
// ビットマップキャンバス
80+
// ビットマップバッファ
6881
//---------------------------------------------------------------------
6982
class Bitmap_Buffer {
7083
private:
7184
HBITMAP bitmap;
7285
HWND hwnd;
86+
RECT rect;
87+
ID2D1SolidColorBrush* brush = nullptr;
88+
7389
public:
7490
HDC hdc_memory;
7591

7692
void init(HWND hw);
7793
void exit() const;
78-
void transfer(const RECT& rect) const;
94+
void transfer() const;
95+
bool d2d_setup(COLORREF cr);
96+
void set_size(const RECT& rect_wnd);
97+
98+
void draw_panel_main(const RECT& rect_sepr);
99+
void draw_panel_header();
100+
void draw_panel_preset();
101+
void draw_panel_editor();
102+
103+
void draw_rounded_edge(int flag, float radius);
79104
};
80105

81106

@@ -265,14 +290,14 @@ namespace ce {
265290
origin.x = CE_GR_PADDING;
266291
scale.x = ((double)rect.right - (int)(2 * CE_GR_PADDING)) / (double)CE_GR_RESOLUTION;
267292

268-
if (rect.right <= rect.bottom) {
269-
origin.y = (rect.bottom + rect.right) * 0.5f - CE_GR_PADDING;
270-
scale.y = scale.x;
271-
}
272-
else if (rect.bottom > CE_GR_PADDING * 2 + CE_GR_RESOLUTION * CE_GR_SCALE_MIN) {
293+
if (rect.right > rect.bottom && rect.bottom > CE_GR_PADDING * 2 + CE_GR_RESOLUTION * CE_GR_SCALE_MIN) {
273294
origin.y = (float)(rect.bottom - CE_GR_PADDING);
274295
scale.y = ((double)rect.bottom - (int)(2 * CE_GR_PADDING)) / (double)CE_GR_RESOLUTION;
275296
}
297+
else {
298+
origin.y = (rect.bottom + rect.right) * 0.5f - CE_GR_PADDING;
299+
scale.y = scale.x;
300+
}
276301
}
277302
};
278303
}

curve_editor/ce_control.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BOOL ce::Button::create(HWND hwnd_p, LPTSTR name, LPTSTR desc, int ic_or_str, LP
7070
//---------------------------------------------------------------------
7171
void ce::Button::draw(COLORREF bg, RECT& rect_wnd, LPTSTR content)
7272
{
73-
d2d_setup(bitmap_buffer, rect_wnd, TO_BGR(bg));
73+
bitmap_buffer.d2d_setup(TO_BGR(bg));
7474

7575
::SetBkColor(bitmap_buffer.hdc_memory, bg);
7676

@@ -99,12 +99,12 @@ void ce::Button::draw(COLORREF bg, RECT& rect_wnd, LPTSTR content)
9999
if (g_render_target != NULL) {
100100
g_render_target->BeginDraw();
101101
if (brush == NULL) g_render_target->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
102-
d2d_draw_rounded_edge(brush, rect_wnd, edge_flag, CE_ROUND_RADIUS);
102+
bitmap_buffer.draw_rounded_edge(edge_flag, CE_ROUND_RADIUS);
103103

104104
g_render_target->EndDraw();
105105
}
106106

107-
bitmap_buffer.transfer(rect_wnd);
107+
bitmap_buffer.transfer();
108108
}
109109

110110

@@ -121,6 +121,7 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
121121
switch (msg) {
122122
case WM_CREATE:
123123
bitmap_buffer.init(hwnd);
124+
bitmap_buffer.set_size(rect_wnd);
124125

125126
if (icon_or_str == 0) {
126127
icon_dark = ::LoadIcon(g_fp->dll_hinst, icon_res_dark);
@@ -167,6 +168,8 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
167168
return 0;
168169

169170
case WM_SIZE:
171+
bitmap_buffer.set_size(rect_wnd);
172+
170173
if (!icon_or_str) {
171174
tool_info.rect = rect_wnd;
172175
::SendMessage(hwnd_tooltip, TTM_NEWTOOLRECT, 0, (LPARAM)&tool_info);

curve_editor/ce_curve.cpp

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ void ce::Curve::initialize()
5252
//---------------------------------------------------------------------
5353
// 初期化2
5454
//---------------------------------------------------------------------
55-
void ce::Curve::initialize(Mode md)
55+
void ce::Curve::set_mode(Mode md)
5656
{
5757
mode = md;
58-
initialize();
5958
}
6059

6160

@@ -876,6 +875,103 @@ void ce::Curve::reverse_curve()
876875

877876

878877

878+
void ce::Curve::draw_bezier(ID2D1SolidColorBrush* brush,
879+
const ce::Float_Point& stpt, const ce::Float_Point& ctpt1, const ce::Float_Point& ctpt2, const ce::Float_Point& edpt, float thickness)
880+
{
881+
ID2D1GeometrySink* sink;
882+
ID2D1PathGeometry* bezier;
883+
ID2D1StrokeStyle* pStyle = nullptr;
884+
g_d2d1_factory->CreateStrokeStyle(
885+
D2D1::StrokeStyleProperties(
886+
D2D1_CAP_STYLE_ROUND,
887+
D2D1_CAP_STYLE_ROUND,
888+
D2D1_CAP_STYLE_ROUND,
889+
D2D1_LINE_JOIN_MITER,
890+
10.0f,
891+
D2D1_DASH_STYLE_SOLID,
892+
0.0f),
893+
NULL, NULL,
894+
&pStyle
895+
);
896+
g_d2d1_factory->CreatePathGeometry(&bezier);
897+
bezier->Open(&sink);
898+
sink->BeginFigure(D2D1::Point2F(stpt.x, stpt.y), D2D1_FIGURE_BEGIN_HOLLOW);
899+
sink->AddBezier(D2D1::BezierSegment(
900+
D2D1::Point2F(ctpt1.x, ctpt1.y),
901+
D2D1::Point2F(ctpt2.x, ctpt2.y),
902+
D2D1::Point2F(edpt.x, edpt.y)
903+
));
904+
sink->EndFigure(D2D1_FIGURE_END_OPEN);
905+
sink->Close();
906+
907+
if (bezier)
908+
g_render_target->DrawGeometry(bezier, brush, thickness, pStyle);
909+
}
910+
911+
912+
913+
void ce::Curve::draw_handle(ID2D1SolidColorBrush* brush, const ce::Float_Point& st, const ce::Float_Point& ed)
914+
{
915+
ce::Float_Point st_new, ed_new;
916+
917+
subtract_length(&st_new, ed, st, CE_SUBTRACT_LENGTH_2);
918+
subtract_length(&ed_new, st, ed, CE_SUBTRACT_LENGTH);
919+
920+
ID2D1StrokeStyle* pStyle = NULL;
921+
922+
g_d2d1_factory->CreateStrokeStyle(
923+
D2D1::StrokeStyleProperties(
924+
D2D1_CAP_STYLE_ROUND,
925+
D2D1_CAP_STYLE_ROUND,
926+
D2D1_CAP_STYLE_ROUND,
927+
D2D1_LINE_JOIN_MITER,
928+
10.0f,
929+
D2D1_DASH_STYLE_SOLID,
930+
0.0f),
931+
NULL, NULL,
932+
&pStyle
933+
);
934+
935+
g_render_target->DrawLine(
936+
D2D1::Point2F(st_new.x, st_new.y),
937+
D2D1::Point2F(ed_new.x, ed_new.y),
938+
brush, CE_HANDLE_TH
939+
);
940+
941+
g_render_target->DrawEllipse(
942+
D2D1::Ellipse(
943+
D2D1::Point2F(ed.x, ed.y),
944+
(float)CE_HANDLE_SIZE, (float)CE_HANDLE_SIZE),
945+
brush, (float)CE_HANDLE_SIRCLE_LINE
946+
);
947+
948+
g_render_target->FillEllipse(
949+
D2D1::Ellipse(
950+
D2D1::Point2F(st.x, st.y),
951+
(float)CE_POINT_SIZE, (float)CE_POINT_SIZE),
952+
brush
953+
);
954+
}
955+
956+
957+
958+
void ce::Curve::draw_curve(ID2D1SolidColorBrush* brush)
959+
{
960+
961+
}
962+
963+
964+
965+
//---------------------------------------------------------------------
966+
// データが有効かどうか
967+
//---------------------------------------------------------------------
968+
bool ce::Curve::is_data_valid()
969+
{
970+
return ISINRANGEEQ(ctpts.size, 2, CE_POINT_MAX);
971+
}
972+
973+
974+
879975
//---------------------------------------------------------------------
880976
// スクリプトに渡す値を生成
881977
//---------------------------------------------------------------------

curve_editor/ce_func_filter.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ BOOL filter_init(FILTER* fp)
2626
{
2727
g_fp = fp;
2828

29-
// カーブの初期化
30-
g_curve_value.initialize(ce::Mode_Value);
31-
g_curve_value_previous.initialize(ce::Mode_Value);
32-
3329
for (int i = 0; i < CE_CURVE_MAX; i++) {
34-
g_curve_id[i].initialize(ce::Mode_ID);
30+
g_curve_id[i].set_mode(ce::Mode_ID);
3531
}
36-
g_curve_id_previous.initialize(ce::Mode_ID);
32+
g_curve_id_previous.set_mode(ce::Mode_ID);
3733

3834

3935
// aviutl.iniから設定を読み込み
@@ -89,11 +85,40 @@ BOOL filter_exit(FILTER* fp)
8985
//---------------------------------------------------------------------
9086
BOOL on_project_load(FILTER* fp, void* editp, void* data, int size)
9187
{
88+
static ce::Static_Array<ce::Curve_Points, CE_POINT_MAX> point_data[CE_CURVE_MAX];
89+
9290
if (data) {
93-
memcpy(g_curve_id, data, size);
91+
memcpy(point_data, data, size);
92+
93+
for (int i = 0; i < CE_CURVE_MAX; i++)
94+
g_curve_id[i].ctpts = point_data[i];
95+
9496
g_curve_id_previous = g_curve_id[g_config.current_id];
95-
if (g_window_editor.hwnd)
97+
98+
if (g_window_editor.hwnd) {
9699
::SendMessage(g_window_editor.hwnd, WM_COMMAND, CE_CM_REDRAW, 0);
100+
101+
for (int i = 0; i < CE_CURVE_MAX; i++) {
102+
if (!g_curve_id[i].is_data_valid()) {
103+
int response = IDOK;
104+
105+
response = ::MessageBox(
106+
g_window_editor.hwnd,
107+
CE_STR_DATA_INVALID,
108+
CE_PLUGIN_NAME,
109+
MB_OKCANCEL | MB_ICONEXCLAMATION
110+
);
111+
112+
if (response == IDOK)
113+
::PostMessage(g_window_editor.hwnd, WM_COMMAND, ID_MENU_DELETE_ALL, TRUE);
114+
115+
break;
116+
}
117+
}
118+
}
119+
120+
121+
97122
}
98123
return TRUE;
99124
}
@@ -105,12 +130,16 @@ BOOL on_project_load(FILTER* fp, void* editp, void* data, int size)
105130
//---------------------------------------------------------------------
106131
BOOL on_project_save(FILTER* fp, void* editp, void* data, int* size)
107132
{
108-
int size_curve_id = sizeof(ce::Curve_Points) * CE_POINT_MAX * CE_CURVE_MAX;
133+
static ce::Static_Array<ce::Curve_Points, CE_POINT_MAX> point_data[CE_CURVE_MAX] = {};
134+
135+
for (int i = 0; i < CE_CURVE_MAX; i++)
136+
point_data[i] = g_curve_id[i].ctpts;
137+
109138
if (!data) {
110-
*size = sizeof(g_curve_id);
139+
*size = sizeof(point_data);
111140
}
112141
else {
113-
memcpy(data, g_curve_id, sizeof(g_curve_id));
142+
memcpy(data, point_data, sizeof(point_data));
114143
}
115144
return TRUE;
116145
}

0 commit comments

Comments
 (0)