Skip to content

Commit 91cce1d

Browse files
committed
ID表示・移動ボタンの追加
1 parent 92240c2 commit 91cce1d

16 files changed

+299
-433
lines changed

curve_editor/ce_classes.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ namespace ce {
196196
int edge_flag;
197197
ID2D1SolidColorBrush* brush;
198198

199-
void draw(COLORREF bg, LPRECT rect_wnd);
199+
void draw(COLORREF bg, LPRECT rect_wnd, LPTSTR content);
200200

201201
public:
202202
int id;
@@ -232,6 +232,20 @@ namespace ce {
232232

233233

234234

235+
//---------------------------------------------------------------------
236+
// ボタン(ID)
237+
//---------------------------------------------------------------------
238+
class Button_ID : public Button {
239+
private:
240+
int id_buffer;
241+
POINT pt_lock;
242+
243+
public:
244+
LRESULT wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
245+
};
246+
247+
248+
235249
//---------------------------------------------------------------------
236250
// グラフ表示
237251
//---------------------------------------------------------------------

curve_editor/ce_control.cpp

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ BOOL ce::Button::create(HWND hwnd_p, LPTSTR name, LPTSTR desc, int ic_or_str, LP
2424
label = lb;
2525
}
2626
else {
27+
label = "";
2728
icon_res_dark = ico_res_dark;
2829
icon_res_light = ico_res_light;
2930
}
@@ -67,7 +68,7 @@ BOOL ce::Button::create(HWND hwnd_p, LPTSTR name, LPTSTR desc, int ic_or_str, LP
6768
//---------------------------------------------------------------------
6869
// コントロール描画用の関数
6970
//---------------------------------------------------------------------
70-
void ce::Button::draw(COLORREF bg, LPRECT rect_wnd)
71+
void ce::Button::draw(COLORREF bg, LPRECT rect_wnd, LPTSTR content)
7172
{
7273
d2d_setup(&canvas, rect_wnd, TO_BGR(bg));
7374

@@ -78,8 +79,8 @@ void ce::Button::draw(COLORREF bg, LPRECT rect_wnd)
7879
::SelectObject(canvas.hdc_memory, font);
7980
::DrawText(
8081
canvas.hdc_memory,
81-
label,
82-
strlen(label),
82+
content,
83+
strlen(content),
8384
rect_wnd,
8485
DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_SINGLELINE
8586
);
@@ -139,7 +140,7 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
139140
tool_info.hwnd = hwnd;
140141
tool_info.uId = id;
141142
tool_info.lpszText = description;
142-
SendMessage(hwnd_tooltip, TTM_ADDTOOL, 0, (LPARAM)&tool_info);
143+
::SendMessage(hwnd_tooltip, TTM_ADDTOOL, 0, (LPARAM)&tool_info);
143144
}
144145

145146
tme.cbSize = sizeof(tme);
@@ -150,14 +151,14 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
150151
font = ::CreateFont(
151152
CE_CT_FONT_H, 0,
152153
0, 0,
153-
FW_BOLD,
154+
FW_REGULAR,
154155
FALSE, FALSE, FALSE,
155-
SHIFTJIS_CHARSET,
156+
ANSI_CHARSET,
156157
OUT_DEFAULT_PRECIS,
157158
CLIP_DEFAULT_PRECIS,
158159
DEFAULT_QUALITY,
159160
NULL,
160-
NULL
161+
CE_FONT_YU
161162
);
162163
return 0;
163164

@@ -166,9 +167,9 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
166167
return 0;
167168

168169
case WM_SIZE:
169-
if (icon_or_str) {
170+
if (!icon_or_str) {
170171
tool_info.rect = rect_wnd;
171-
SendMessage(hwnd_tooltip, TTM_NEWTOOLRECT, 0, (LPARAM)&tool_info);
172+
::SendMessage(hwnd_tooltip, TTM_NEWTOOLRECT, 0, (LPARAM)&tool_info);
172173
}
173174
return 0;
174175

@@ -186,21 +187,21 @@ LRESULT ce::Button::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
186187

187188
::SetTextColor(canvas.hdc_memory, g_theme[g_config.theme].bt_tx);
188189

189-
draw(bg, &rect_wnd);
190+
draw(bg, &rect_wnd, label);
190191
return 0;
191192
}
192193

193194
// マウスが動いたとき
194195
case WM_MOUSEMOVE:
195-
::SetCursor(LoadCursor(NULL, IDC_HAND));
196+
::SetCursor(::LoadCursor(NULL, IDC_HAND));
196197
hovered = TRUE;
197198
::InvalidateRect(hwnd, NULL, FALSE);
198199
::TrackMouseEvent(&tme);
199200
return 0;
200201

201202
// 左クリックがされたとき
202203
case WM_LBUTTONDOWN:
203-
::SetCursor(LoadCursor(NULL, IDC_HAND));
204+
::SetCursor(::LoadCursor(NULL, IDC_HAND));
204205
clicked = TRUE;
205206
::InvalidateRect(hwnd, NULL, FALSE);
206207
::TrackMouseEvent(&tme);
@@ -274,7 +275,7 @@ LRESULT ce::Button_Switch::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp
274275
::SetTextColor(canvas.hdc_memory, g_theme[g_config.theme].bt_tx);
275276
}
276277

277-
draw(bg, &rect_wnd);
278+
draw(bg, &rect_wnd, label);
278279
return 0;
279280
}
280281

@@ -303,4 +304,71 @@ void ce::Button_Switch::set_status(BOOL bl)
303304
{
304305
is_selected = bl;
305306
::InvalidateRect(hwnd, NULL, FALSE);
307+
}
308+
309+
310+
311+
//---------------------------------------------------------------------
312+
// ウィンドウプロシージャ(ID)
313+
//---------------------------------------------------------------------
314+
LRESULT ce::Button_ID::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
315+
{
316+
RECT rect_wnd;
317+
POINT cl_pt = { GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam) };
318+
319+
::GetClientRect(hwnd, &rect_wnd);
320+
321+
switch (msg) {
322+
case WM_PAINT:
323+
{
324+
COLORREF bg;
325+
std::string id_str = std::to_string(g_config.current_id);
326+
LPCTSTR id_lps = id_str.c_str();
327+
328+
if (clicked)
329+
bg = BRIGHTEN(g_theme[g_config.theme].bg, CE_CT_BR_CLICKED);
330+
else if (hovered)
331+
bg = BRIGHTEN(g_theme[g_config.theme].bg, CE_CT_BR_HOVERED);
332+
else
333+
bg = g_theme[g_config.theme].bg;
334+
335+
::SetTextColor(canvas.hdc_memory, g_theme[g_config.theme].bt_tx);
336+
337+
draw(bg, &rect_wnd, const_cast<LPTSTR>(id_lps));
338+
return 0;
339+
}
340+
341+
// 左クリックがされたとき
342+
case WM_LBUTTONDOWN:
343+
pt_lock = cl_pt;
344+
id_buffer = g_config.current_id;
345+
::SetCursor(LoadCursor(NULL, IDC_HAND));
346+
clicked = TRUE;
347+
::InvalidateRect(hwnd, NULL, FALSE);
348+
::SetCapture(hwnd);
349+
return 0;
350+
351+
// カーソルが動いたとき
352+
case WM_MOUSEMOVE:
353+
if (clicked && g_config.mode == 1) {
354+
::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
355+
g_config.current_id = MINMAXLIM(id_buffer + (cl_pt.x - pt_lock.x) / 9, 0, CE_CURVE_MAX - 1);
356+
::SendMessage(g_window_editor.hwnd, WM_COMMAND, CE_CM_REDRAW, 0);
357+
}
358+
else ::SetCursor(LoadCursor(NULL, IDC_HAND));
359+
360+
hovered = TRUE;
361+
InvalidateRect(hwnd, NULL, FALSE);
362+
TrackMouseEvent(&tme);
363+
return 0;
364+
365+
case WM_LBUTTONUP:
366+
clicked = FALSE;
367+
::ReleaseCapture();
368+
::InvalidateRect(hwnd, NULL, FALSE);
369+
return 0;
370+
371+
default:
372+
return Button::wndproc(hwnd, msg, wparam, lparam);
373+
}
306374
}

0 commit comments

Comments
 (0)