Skip to content

Commit dba435b

Browse files
committed
ボタンを追加
1 parent 76ab802 commit dba435b

17 files changed

+798
-1054
lines changed

curve_editor/ce_classes.hpp

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
//----------------------------------------------------------------------------------
2+
// Curve Editor
3+
// ヘッダファイル (クラス)
4+
// Visual C++ 2022
5+
//----------------------------------------------------------------------------------
6+
7+
#pragma once
8+
9+
#include "ce_structs.hpp"
10+
11+
12+
13+
namespace ce {
14+
//---------------------------------------------------------------------
15+
// 配列
16+
//---------------------------------------------------------------------
17+
template <typename T, size_t N>
18+
class Static_Array {
19+
public:
20+
size_t size;
21+
static const size_t max_size = N;
22+
T elements[N];
23+
24+
Static_Array() : size(0) {}
25+
26+
template <typename U>
27+
T& operator[] (U i) { return elements[MINMAXLIM(i, 0, N - 1)]; }
28+
29+
// クリア
30+
void clear()
31+
{
32+
size = 0;
33+
}
34+
35+
// 挿入
36+
void insert(size_t index, const T& v)
37+
{
38+
int max = size >= max_size ? max_size - 1 : size;
39+
for (int i = max; i > (int)index;) {
40+
i--;
41+
elements[i + 1] = elements[i];
42+
}
43+
elements[index] = v;
44+
if (size < max_size) size++;
45+
}
46+
47+
// 押し込み
48+
void push_back(const T& v)
49+
{
50+
if (size < max_size) {
51+
size++;
52+
elements[size - 1] = v;
53+
}
54+
}
55+
56+
// 削除
57+
void erase(int index)
58+
{
59+
size--;
60+
for (int i = index; i < (int)size; i++) {
61+
elements[i] = elements[i + 1];
62+
}
63+
}
64+
};
65+
66+
67+
68+
//---------------------------------------------------------------------
69+
// カーブ(Valueモード)
70+
//---------------------------------------------------------------------
71+
class Curve_Value {
72+
public:
73+
POINT ctpt[2];
74+
75+
Curve_Value() { init(); }
76+
77+
void init();
78+
int point_in_ctpts(POINT cl_pt);
79+
void move_point(int index, POINT gr_pt);
80+
int create_value_1d();
81+
std::string create_value_4d();
82+
void read_value_1d(int value);
83+
};
84+
85+
86+
87+
//---------------------------------------------------------------------
88+
// カーブ(IDモード)
89+
//---------------------------------------------------------------------
90+
class Curve_ID {
91+
public:
92+
Static_Array <Points_ID, CE_POINT_MAX> ctpts;
93+
94+
Curve_ID() { init(); }
95+
96+
void init();
97+
void add_point(POINT cl_pt);
98+
void delete_point(POINT cl_pt);
99+
void clear();
100+
POINT get_point(Point_Address address);
101+
void move_point(Point_Address address, POINT gr_pt, BOOL bReset);
102+
Point_Address pt_in_ctpt(POINT cl_pt);
103+
double get_handle_angle(Point_Address address);
104+
void correct_handle(Point_Address address, double angle);
105+
void set_handle_angle(Point_Address address, double angle, BOOL bLength, double lgth);
106+
void reverse_curve();
107+
double get_value(double ratio, double st, double ed);
108+
};
109+
110+
111+
112+
//---------------------------------------------------------------------
113+
// プリセット
114+
//---------------------------------------------------------------------
115+
class Preset {
116+
private:
117+
static LRESULT CALLBACK wndproc_tmp(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
118+
public:
119+
HWND hwnd;
120+
LPTSTR name;
121+
Curve_Value curve_value;
122+
Curve_ID curve_id;
123+
time_t unix_time;
124+
const int val_or_id, def_or_user;
125+
int index;
126+
127+
Preset(int v_i, Curve_Value c_value, Curve_ID c_id, LPTSTR n, int d_u) : name(n), val_or_id(v_i), def_or_user(d_u)
128+
{
129+
if (v_i == 1)
130+
curve_id = c_id;
131+
else
132+
curve_value = c_value;
133+
time(&unix_time);
134+
}
135+
136+
void move(int idx, int width);
137+
138+
};
139+
140+
141+
142+
//---------------------------------------------------------------------
143+
// ビットマップキャンバス
144+
//---------------------------------------------------------------------
145+
class Bitmap_Canvas {
146+
private:
147+
HBITMAP bitmap;
148+
HWND hwnd;
149+
public:
150+
HDC hdc_memory;
151+
152+
void init(HWND hw);
153+
void exit();
154+
void transfer(LPRECT rect);
155+
};
156+
157+
158+
159+
//---------------------------------------------------------------------
160+
// コントロールウィンドウ
161+
//---------------------------------------------------------------------
162+
class Control {
163+
private:
164+
int icon;
165+
Bitmap_Canvas canvas;
166+
HWND hwnd_parent;
167+
BOOL hovered, clicked;
168+
TRACKMOUSEEVENT tme;
169+
170+
static LRESULT CALLBACK wndproc_static(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
171+
172+
public:
173+
HWND hwnd;
174+
int id;
175+
176+
BOOL create(HWND hwnd_p, LPSTR name, int ico, int ct_id, LPRECT rect);
177+
void move(LPRECT rect);
178+
virtual LRESULT wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
179+
};
180+
}

curve_editor/ce_control.cpp

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
//----------------------------------------------------------------------------------
2+
// Curve Editor
3+
// ソースファイル(コントロール)
4+
// Visual C++ 2022
5+
//----------------------------------------------------------------------------------
6+
7+
#include "ce_header.hpp"
8+
9+
10+
11+
//---------------------------------------------------------------------
12+
// コントロールを作成
13+
//---------------------------------------------------------------------
14+
BOOL ce::Control::create(HWND hwnd_p, LPSTR name, int ico, int ct_id, LPRECT rect)
15+
{
16+
WNDCLASSEX tmp;
17+
id = ct_id;
18+
icon = ico;
19+
20+
tmp.cbSize = sizeof(tmp);
21+
tmp.style = CS_HREDRAW | CS_VREDRAW;
22+
tmp.lpfnWndProc = wndproc_static;
23+
tmp.cbClsExtra = 0;
24+
tmp.cbWndExtra = 0;
25+
tmp.hInstance = g_fp->dll_hinst;
26+
tmp.hIcon = NULL;
27+
tmp.hIconSm = NULL;
28+
tmp.hCursor = LoadCursor(NULL, IDC_ARROW);
29+
tmp.hbrBackground = NULL;
30+
tmp.lpszMenuName = NULL;
31+
tmp.lpszClassName = name;
32+
33+
if (RegisterClassEx(&tmp)) {
34+
hwnd = CreateWindowExA(
35+
NULL,
36+
name,
37+
NULL,
38+
WS_CHILD | WS_VISIBLE,
39+
rect->left, rect->top,
40+
rect->right - rect->left,
41+
rect->bottom - rect->top,
42+
hwnd_p,
43+
NULL,
44+
g_fp->dll_hinst,
45+
this
46+
);
47+
if (hwnd != nullptr)
48+
return 1;
49+
}
50+
return 0;
51+
}
52+
53+
54+
55+
//---------------------------------------------------------------------
56+
// コントロールを移動
57+
//---------------------------------------------------------------------
58+
void ce::Control::move(LPRECT rect)
59+
{
60+
MoveWindow(
61+
hwnd,
62+
rect->left, rect->top,
63+
rect->right - rect->left,
64+
rect->bottom - rect->top,
65+
TRUE
66+
);
67+
}
68+
69+
70+
71+
//---------------------------------------------------------------------
72+
// 静的ウィンドウプロシージャ
73+
//---------------------------------------------------------------------
74+
LRESULT CALLBACK ce::Control::wndproc_static(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
75+
{
76+
Control* app = (Control*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
77+
if (!app) {//取得できなかった(ウィンドウ生成中)場合
78+
if (msg == WM_CREATE) {
79+
app = (Control*)((LPCREATESTRUCT)lparam)->lpCreateParams;
80+
if (app) {
81+
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)app);
82+
return app->wndproc(hwnd, msg, wparam, lparam);
83+
}
84+
}
85+
}
86+
else {//取得できた場合(ウィンドウ生成後)
87+
return app->wndproc(hwnd, msg, wparam, lparam);
88+
}
89+
return DefWindowProc(hwnd, msg, wparam, lparam);
90+
}
91+
92+
93+
94+
//---------------------------------------------------------------------
95+
// ウィンドウプロシージャ(static変数使っちゃダメ!)
96+
//---------------------------------------------------------------------
97+
LRESULT ce::Control::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
98+
{
99+
RECT rect_wnd;
100+
101+
GetClientRect(hwnd, &rect_wnd);
102+
103+
switch (msg) {
104+
case WM_CREATE:
105+
canvas.init(hwnd);
106+
107+
hwnd_parent = GetParent(hwnd);
108+
109+
tme.cbSize = sizeof(tme);
110+
tme.dwFlags = TME_LEAVE;
111+
tme.hwndTrack = hwnd;
112+
return 0;
113+
114+
case WM_CLOSE:
115+
canvas.exit();
116+
return 0;
117+
118+
case WM_PAINT:
119+
{
120+
COLORREF bg;
121+
ID2D1SolidColorBrush* pBrush = NULL;
122+
123+
if (clicked)
124+
bg = BRIGHTEN(g_theme[g_config.theme].bg_others, CE_CT_BR_CLICKED);
125+
else if (hovered)
126+
bg = BRIGHTEN(g_theme[g_config.theme].bg_others, CE_CT_BR_HOVERED);
127+
else
128+
bg = g_theme[g_config.theme].bg_others;
129+
d2d_setup(&canvas, &rect_wnd, bg);
130+
131+
if (g_render_target != NULL && g_d2d1_factory != NULL) {
132+
g_render_target->BeginDraw();
133+
if (pBrush == NULL)
134+
g_render_target->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &pBrush);
135+
g_render_target->EndDraw();
136+
}
137+
138+
canvas.transfer(&rect_wnd);
139+
}
140+
return 0;
141+
142+
case WM_MOUSEMOVE:
143+
SetCursor(LoadCursor(NULL, IDC_HAND));
144+
hovered = TRUE;
145+
InvalidateRect(hwnd, NULL, FALSE);
146+
TrackMouseEvent(&tme);
147+
return 0;
148+
149+
case WM_LBUTTONDOWN:
150+
SetCursor(LoadCursor(NULL, IDC_HAND));
151+
clicked = TRUE;
152+
InvalidateRect(hwnd, NULL, FALSE);
153+
TrackMouseEvent(&tme);
154+
return 0;
155+
156+
case WM_LBUTTONUP:
157+
SetCursor(LoadCursor(NULL, IDC_HAND));
158+
clicked = FALSE;
159+
InvalidateRect(hwnd, NULL, FALSE);
160+
SendMessage(hwnd_parent, WM_COMMAND, id, 0);
161+
return 0;
162+
163+
case WM_MOUSELEAVE:
164+
clicked = FALSE;
165+
hovered = FALSE;
166+
InvalidateRect(hwnd, NULL, FALSE);
167+
return 0;
168+
169+
case WM_COMMAND:
170+
switch (wparam) {
171+
case CE_CM_REDRAW:
172+
InvalidateRect(hwnd, NULL, FALSE);
173+
return 0;
174+
}
175+
return 0;
176+
177+
default:
178+
return DefWindowProc(hwnd, msg, wparam, lparam);
179+
}
180+
}

0 commit comments

Comments
 (0)