Skip to content

Commit

Permalink
Changed the style of the combo box for selecting font, so users can w…
Browse files Browse the repository at this point in the history
…rite the font name there.
  • Loading branch information
sigma-axis committed Apr 22, 2024
1 parent d319d1e commit d237da9
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 65 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
###############################################################################
* text=auto
*.ini text working-tree-encoding=UTF-8 eol=crlf
*.rc diff=astextplain

###############################################################################
# Set default behavior for command prompt diff.
Expand Down
2 changes: 1 addition & 1 deletion color_loupe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved)
// 看板.
////////////////////////////////
#define PLUGIN_NAME "色ルーペ"
#define PLUGIN_VERSION "v2.21"
#define PLUGIN_VERSION "v2.22-beta1"
#define PLUGIN_AUTHOR "sigma-axis"
#define PLUGIN_INFO_FMT(name, ver, author) (name##" "##ver##" by "##author)
#define PLUGIN_INFO PLUGIN_INFO_FMT(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
Expand Down
Binary file modified color_loupe.rc
Binary file not shown.
50 changes: 32 additions & 18 deletions dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,9 @@ class tip_drag_metrics : public dialog_base {
{
// suppress notifications from controls.
auto sc = suppress_callback();
#define set_spin(id, field) init_spin(::GetDlgItem(hwnd, IDC_SPIN##id), drag.field, Settings::TipDrag::field##_min, Settings::TipDrag::field##_max)
#define set_spin(id, field) init_spin(::GetDlgItem(hwnd, IDC_SPIN##id), drag.field, Settings::TipDrag::field##_min, Settings::TipDrag::field##_max)
populate_field(set_spin);
#undef set_spin
#undef set_spin

std::srand(reinterpret_cast<uint32_t>(hwnd));
return false;
Expand All @@ -843,13 +843,12 @@ class tip_drag_metrics : public dialog_base {
switch (auto id = 0xffff & wparam, code = wparam >> 16; code) {
case EN_CHANGE:
switch (id) {
#define invoke_on_change(id, field) \
#define invoke_on_change(id, field) \
case IDC_EDIT##id:\
on_change_##field(get_spin_value(::GetDlgItem(hwnd, IDC_SPIN##id)));\
goto update
populate_field(invoke_on_change);
#undef invoke_on_change
#undef populate_field
#undef invoke_on_change

update:
update_view();
Expand Down Expand Up @@ -879,6 +878,7 @@ class tip_drag_metrics : public dialog_base {
}
return false;
}
#undef populate_field
};


Expand Down Expand Up @@ -1316,9 +1316,9 @@ class toast_metrics : public dialog_base {
{
// suppress notifications from controls.
auto sc = suppress_callback();
#define set_spin(id, field) init_spin(::GetDlgItem(hwnd, IDC_SPIN##id), toast.field, Settings::Toast::field##_min, Settings::Toast::field##_max)
#define set_spin(id, field) init_spin(::GetDlgItem(hwnd, IDC_SPIN##id), toast.field, Settings::Toast::field##_min, Settings::Toast::field##_max)
populate_field(set_spin);
#undef set_spin
#undef set_spin

::SendMessageW(::GetDlgItem(hwnd, IDC_EDIT7), WM_SETTEXT,
{}, reinterpret_cast<LPARAM>(res_str::get(IDS_DLG_TOAST_SAMPLE)));
Expand All @@ -1334,13 +1334,12 @@ class toast_metrics : public dialog_base {
switch (auto id = 0xffff & wparam, code = wparam >> 16; code) {
case EN_CHANGE:
switch (id) {
#define invoke_on_change(id, field) \
#define invoke_on_change(id, field) \
case IDC_EDIT##id:\
on_change_##field(get_spin_value(::GetDlgItem(hwnd, IDC_SPIN##id)));\
goto update
populate_field(invoke_on_change);
#undef invoke_on_change
#undef populate_field
#undef invoke_on_change

case IDC_EDIT7:
update:
Expand All @@ -1362,6 +1361,7 @@ class toast_metrics : public dialog_base {
}
return false;
}
#undef populate_field
};


Expand Down Expand Up @@ -1448,22 +1448,26 @@ class grid_options : public dialog_base {
// フォントの設定.
////////////////////////////////
class font_settings : public dialog_base {
using Pivot = Settings::WheelZoom::Pivot;
using ClickActions = Settings::ClickActions;

public:
wchar_t (&name)[LF_FACESIZE];
wchar_t(&name)[LF_FACESIZE];
int8_t& size;
int8_t const min, max;
dialog_base* const update_target;
font_settings(decltype(name) name, int8_t& size, int8_t min, int8_t max,
dialog_base* const update_target)
dialog_base* update_target)
: name{ name }, size{ size }, min{ min }, max{ max }, update_target{ update_target } {}

private:
void on_change_name(HWND ctrl) {
void on_edit_name(HWND ctrl) {
::SendMessageW(ctrl, WM_GETTEXT, std::size(name), reinterpret_cast<LPARAM>(name));
}
void on_select_name(HWND ctrl) {
size_t idx = ::SendMessageW(ctrl, CB_GETCURSEL, {}, {});
if (idx == CB_ERR) return;
if (size_t len = ::SendMessageW(ctrl, CB_GETLBTEXTLEN, idx, {});
len == CB_ERR || std::size(name) <= len) return;
::SendMessageW(ctrl, CB_GETLBTEXT, idx, reinterpret_cast<LPARAM>(name));
}
void on_change_size(int8_t data_new) { size = std::clamp(data_new, min, max); }
void update_view() {
if (update_target != nullptr && update_target->hwnd != nullptr)
Expand All @@ -1488,11 +1492,13 @@ class font_settings : public dialog_base {
return TRUE;
}, reinterpret_cast<LPARAM>(combo));
::ReleaseDC(nullptr, hdc);
::SendMessageW(combo, CB_SELECTSTRING, -1, reinterpret_cast<LPARAM>(name));
::SendMessageW(combo, WM_SETTEXT, {}, reinterpret_cast<LPARAM>(name));

// font size.
init_spin(::GetDlgItem(hwnd, IDC_SPIN1), size, min, max);

::SendMessageW(::GetDlgItem(hwnd, IDC_EDIT2), WM_SETTEXT,
{}, reinterpret_cast<LPARAM>(res_str::get(IDS_DESC_FONT_STYLE)));
return false;
}

Expand All @@ -1502,10 +1508,18 @@ class font_settings : public dialog_base {
switch (message) {
case WM_COMMAND:
switch (auto id = 0xffff & wparam, code = wparam >> 16; code) {
case CBN_EDITCHANGE:
switch (id) {
case IDC_COMBO1:
on_edit_name(ctrl);
update_view();
return true;
}
break;
case CBN_SELCHANGE:
switch (id) {
case IDC_COMBO1:
on_change_name(ctrl);
on_select_name(ctrl);
update_view();
return true;
}
Expand Down
31 changes: 16 additions & 15 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,22 @@
#define IDS_DESC_EXEDIT_FAKE 173
#define IDS_DESC_GRID_KINDS 174
#define IDS_DESC_CLIPBOARD_FMT 175
#define IDS_DESC_CMD_NONE 176
#define IDS_DESC_CMD_SWAP_ZOOM 177
#define IDS_DESC_CMD_COPY_COLOR 178
#define IDS_DESC_CMD_COPY_COORD 179
#define IDS_DESC_CMD_FOLLOW 180
#define IDS_DESC_CMD_CENTRALIZE 181
#define IDS_DESC_CMD_GRID 182
#define IDS_DESC_CMD_ZOOM_UP 183
#define IDS_DESC_CMD_ZOOM_DOWN 184
#define IDS_DESC_CMD_BRING_CENTER 185
#define IDS_DESC_CMD_CXT_MENU 186
#define IDS_DESC_CMD_SETTINGS 187
#define IDS_DLG_TOAST_SAMPLE 188
#define IDS_COLOR_THEME_LIGHT 189
#define IDS_COLOR_THEME_DARK 190
#define IDS_DESC_FONT_STYLE 176
#define IDS_DESC_CMD_NONE 177
#define IDS_DESC_CMD_SWAP_ZOOM 178
#define IDS_DESC_CMD_COPY_COLOR 179
#define IDS_DESC_CMD_COPY_COORD 180
#define IDS_DESC_CMD_FOLLOW 181
#define IDS_DESC_CMD_CENTRALIZE 182
#define IDS_DESC_CMD_GRID 183
#define IDS_DESC_CMD_ZOOM_UP 184
#define IDS_DESC_CMD_ZOOM_DOWN 185
#define IDS_DESC_CMD_BRING_CENTER 186
#define IDS_DESC_CMD_CXT_MENU 187
#define IDS_DESC_CMD_SETTINGS 188
#define IDS_DLG_TOAST_SAMPLE 189
#define IDS_COLOR_THEME_LIGHT 190
#define IDS_COLOR_THEME_DARK 191
#define IDD_VSCROLLFORM 800
#define IDD_SETTINGS 801
#define IDD_SETTINGS_FORM_CLICK_ACTION 802
Expand Down
60 changes: 30 additions & 30 deletions settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,21 @@ inline constinit struct Settings {
return static_cast<decltype(def)>(
::GetPrivateProfileIntA(section, key, static_cast<int32_t>(def), ini_file));
};
#define load_gen(section, tgt, read, write) section.tgt = read(read_raw(write(section.tgt), #section, #tgt))
#define load_int(section, tgt) load_gen(section, tgt, \
[&](auto y) { return std::clamp(y, section.tgt##_min, section.tgt##_max); }, /*id*/)
#define load_bool(section, tgt) load_gen(section, tgt, \
[](auto y) { return y != 0; }, [](auto x) { return x ? 1 : 0; })
#define load_enum(section, tgt) load_gen(section, tgt, \
[](auto y) { return static_cast<decltype(section.tgt)>(y); }, [](auto x) { return static_cast<int>(x); })
#define load_color(section, tgt) load_gen(section, tgt, \
[](auto y) { return Color::fromARGB(y); }, [](auto x) { return x.to_formattable(); })
#define load_zoom(section, header) \
#define load_gen(section, tgt, read, write) section.tgt = read(read_raw(write(section.tgt), #section, #tgt))
#define load_int(section, tgt) \
load_gen(section, tgt, [&](auto y) { return std::clamp(y, section.tgt##_min, section.tgt##_max); }, /*id*/)
#define load_bool(section, tgt) \
load_gen(section, tgt, [](auto y) { return y != 0; }, [](auto x) { return x ? 1 : 0; })
#define load_enum(section, tgt) \
load_gen(section, tgt, [](auto y) { return static_cast<decltype(section.tgt)>(y); }, [](auto x) { return static_cast<int>(x); })
#define load_color(section, tgt) \
load_gen(section, tgt, [](auto y) { return Color::fromARGB(y); }, [](auto x) { return x.to_formattable(); })
#define load_zoom(section, header) \
load_bool(section, header##enabled);\
load_bool(section, header##reversed);\
load_int(section, header##num_steps);\
load_enum(section, header##pivot)
#define load_drag(section) \
#define load_drag(section) \
load_enum(section, keys.button);\
load_enum(section, keys.ctrl);\
load_enum(section, keys.shift);\
Expand Down Expand Up @@ -402,13 +402,13 @@ inline constinit struct Settings {
load_enum(commands, copy_color_fmt);
load_enum(commands, copy_coord_fmt);

#undef load_drag
#undef load_zoom
#undef load_color
#undef load_enum
#undef load_bool
#undef load_int
#undef load_gen
#undef load_drag
#undef load_zoom
#undef load_color
#undef load_enum
#undef load_bool
#undef load_int
#undef load_gen
}

// saving to .ini file.
Expand All @@ -420,16 +420,16 @@ inline constinit struct Settings {
::WritePrivateProfileStringA(section, key, buf, ini_file);
};

#define save_gen(section, tgt, write, col) save_raw(static_cast<int32_t>(write(section.tgt)), #section, #tgt, col)
#define save_dec(section, tgt) save_gen(section, tgt, /* id */, false)
#define save_color(section, tgt) save_gen(section, tgt, [](auto y) { return y.to_formattable(); }, true)
#define save_bool(section, tgt) ::WritePrivateProfileStringA(#section, #tgt, section.tgt ? "1" : "0", ini_file)
#define save_zoom(section, header) \
#define save_gen(section, tgt, write, col) save_raw(static_cast<int32_t>(write(section.tgt)), #section, #tgt, col)
#define save_dec(section, tgt) save_gen(section, tgt, /* id */, false)
#define save_color(section, tgt) save_gen(section, tgt, [](auto y) { return y.to_formattable(); }, true)
#define save_bool(section, tgt) ::WritePrivateProfileStringA(#section, #tgt, section.tgt ? "1" : "0", ini_file)
#define save_zoom(section, header) \
save_bool(section, header##enabled);\
save_bool(section, header##reversed);\
save_dec(section, header##num_steps);\
save_dec(section, header##pivot)
#define save_drag(section) \
#define save_drag(section) \
save_dec(section, keys.button);\
save_dec(section, keys.ctrl);\
save_dec(section, keys.shift);\
Expand Down Expand Up @@ -531,11 +531,11 @@ inline constinit struct Settings {

// lines commented out are setting items that threre're no means to change at runtime. (all cleared now.)

#undef save_drag
#undef save_zoom
#undef save_bool
#undef save_color
#undef save_dec
#undef save_gen
#undef save_drag
#undef save_zoom
#undef save_bool
#undef save_color
#undef save_dec
#undef save_gen
}
} settings;

0 comments on commit d237da9

Please sign in to comment.