Skip to content

Commit

Permalink
Add colour and font clients for drop-down list toolbars
Browse files Browse the repository at this point in the history
This adds colour and font clients for the DSP preset, output device, output format, pPlayback order and ReplayGain mode toolbars so that their colours and fonts can be configured independently of the global settings.
  • Loading branch information
reupen committed Oct 10, 2021
1 parent 7b0e36a commit 687ba68
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Features

* The DSP preset, Output device, Playback order and ReplayGain mode toolbars now use the global item foreground and background colours configured on the Colour and fonts preferences page. [[#390](https://github.com/reupen/columns_ui/pull/390), contributed by [@rplociennik](https://github.com/rplociennik)]
* The foreground and background colours of items in the DSP preset, Output device, Playback order and ReplayGain mode toolbars can now be configured on the Colour and fonts preferences page. [[#390](https://github.com/reupen/columns_ui/pull/390) (contributed by [@rplociennik](https://github.com/rplociennik)), [#397](https://github.com/reupen/columns_ui/pull/397)]

(Note that selection colours are currently not used.)

Expand Down
65 changes: 26 additions & 39 deletions foo_ui_columns/drop_down_list_toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class DropDownListToolbar : public ui_extension::container_ui_extension {

static void s_update_colours()
{
cui::colours::helper helper(GUID{});

s_background_brush.reset(CreateSolidBrush(helper.get_colour(cui::colours::colour_background)));
cui::colours::helper colour_helper(ToolbarArgs::colour_client_id);
s_background_brush.reset(CreateSolidBrush(colour_helper.get_colour(cui::colours::colour_background)));

for (auto&& window : s_windows) {
const HWND wnd = window->m_wnd_combo;
Expand All @@ -32,8 +31,8 @@ class DropDownListToolbar : public ui_extension::container_ui_extension {

static void s_update_font()
{
const auto font_manager = fb2k::std_api_get<cui::fonts::manager>();
s_items_font.reset(font_manager->get_font(cui::fonts::font_type_items));
const cui::fonts::helper font_helper(ToolbarArgs::font_client_id);
s_items_font.reset(font_helper.get_font());

for (auto&& window : s_windows) {
const HWND wnd = window->m_wnd_combo;
Expand Down Expand Up @@ -61,13 +60,22 @@ class DropDownListToolbar : public ui_extension::container_ui_extension {
}

private:
class FontCallback : public cui::fonts::common_callback {
public:
void on_font_changed(t_size mask) const override { s_update_font(); }
class FontClient : public cui::fonts::client {
const GUID& get_client_guid() const override { return ToolbarArgs::font_client_id; }
void get_name(pfc::string_base& p_out) const override { p_out = ToolbarArgs::name; }
cui::fonts::font_type_t get_default_font_type() const override { return cui::fonts::font_type_items; }
void on_font_changed() const override { s_update_font(); }
};

class ColourCallback : public cui::colours::common_callback {
public:
class ColourClient : public cui::colours::client {
const GUID& get_client_guid() const override { return ToolbarArgs::colour_client_id; }
void get_name(pfc::string_base& p_out) const override { p_out = ToolbarArgs::name; }
size_t get_supported_colours() const override
{
return cui::colours::colour_flag_text | cui::colours::colour_flag_background;
}
size_t get_supported_bools() const override { return 0; }
bool get_themes_supported() const override { return false; }
void on_bool_changed(t_size mask) const override {}
void on_colour_changed(t_size mask) const override { s_update_colours(); }
};
Expand All @@ -86,11 +94,11 @@ class DropDownListToolbar : public ui_extension::container_ui_extension {
static constexpr unsigned initial_height = 300;
static constexpr unsigned initial_width = 150;
static constexpr unsigned maximum_minimum_width = 150;
static FontCallback s_font_callback;
static wil::unique_hfont s_items_font;
static ColourCallback s_colour_callback;
static wil::unique_hbrush s_background_brush;
static std::vector<DropDownListToolbar<ToolbarArgs>*> s_windows;
inline static cui::fonts::client::factory<FontClient> s_font_client;
inline static wil::unique_hfont s_items_font;
inline static cui::colours::client::factory<ColourClient> s_colour_client;
inline static wil::unique_hbrush s_background_brush;
inline static std::vector<DropDownListToolbar<ToolbarArgs>*> s_windows;

void refresh_all_items();
void update_active_item();
Expand Down Expand Up @@ -230,9 +238,6 @@ LRESULT DropDownListToolbar<ToolbarArgs>::on_message(HWND wnd, UINT msg, WPARAM
s_windows.emplace_back(this);
if (s_windows.size() == 1) {
ToolbarArgs::on_first_window_created();

fb2k::std_api_get<cui::colours::manager>()->register_common_callback(&s_colour_callback);
fb2k::std_api_get<cui::fonts::manager>()->register_common_callback(&s_font_callback);
}

if (!s_items_font)
Expand Down Expand Up @@ -263,9 +268,6 @@ LRESULT DropDownListToolbar<ToolbarArgs>::on_message(HWND wnd, UINT msg, WPARAM
case WM_DESTROY: {
if (s_windows.size() == 1) {
ToolbarArgs::on_last_window_destroyed();

fb2k::std_api_get<cui::fonts::manager>()->deregister_common_callback(&s_font_callback);
fb2k::std_api_get<cui::colours::manager>()->deregister_common_callback(&s_colour_callback);
}
s_windows.erase(std::remove(s_windows.begin(), s_windows.end(), this), s_windows.end());

Expand All @@ -282,10 +284,10 @@ LRESULT DropDownListToolbar<ToolbarArgs>::on_message(HWND wnd, UINT msg, WPARAM
case WM_CTLCOLORLISTBOX: {
const auto dc = reinterpret_cast<HDC>(wp);

cui::colours::helper helper(GUID{});
cui::colours::helper colour_helper(ToolbarArgs::colour_client_id);

SetTextColor(dc, helper.get_colour(cui::colours::colour_text));
SetBkColor(dc, helper.get_colour(cui::colours::colour_background));
SetTextColor(dc, colour_helper.get_colour(cui::colours::colour_text));
SetBkColor(dc, colour_helper.get_colour(cui::colours::colour_background));

return reinterpret_cast<LRESULT>(s_background_brush.get());
}
Expand Down Expand Up @@ -385,18 +387,3 @@ LRESULT DropDownListToolbar<ToolbarArgs>::on_hook(HWND wnd, UINT msg, WPARAM wp,
}
return CallWindowProc(m_order_proc, wnd, msg, wp, lp);
}

template <class ToolbarArgs>
typename DropDownListToolbar<ToolbarArgs>::FontCallback DropDownListToolbar<ToolbarArgs>::s_font_callback;

template <class ToolbarArgs>
wil::unique_hfont DropDownListToolbar<ToolbarArgs>::s_items_font;

template <class ToolbarArgs>
typename DropDownListToolbar<ToolbarArgs>::ColourCallback DropDownListToolbar<ToolbarArgs>::s_colour_callback;

template <class ToolbarArgs>
wil::unique_hbrush DropDownListToolbar<ToolbarArgs>::s_background_brush;

template <class ToolbarArgs>
std::vector<DropDownListToolbar<ToolbarArgs>*> DropDownListToolbar<ToolbarArgs>::s_windows;
3 changes: 3 additions & 0 deletions foo_ui_columns/dsp_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct DspPresetToolbarArgs {
static constexpr const wchar_t* class_name{L"columns_ui_dsp_preset_TB7ds8Gd8SMzVA"};
static constexpr const char* name{"DSP preset"};
static constexpr GUID extension_guid{0x9bd325a4, 0xb2e6, 0x47ad, {0x9b, 0x54, 0x8d, 0xa3, 0x5f, 0x42, 0x78, 0x49}};
static constexpr GUID colour_client_id{
0xbbae33d4, 0x878c, 0x4c4a, {0x9a, 0xd0, 0x69, 0xe6, 0xf8, 0xc1, 0xc5, 0x8c}};
static constexpr GUID font_client_id{0x4f145326, 0xeda6, 0x4f80, {0xbd, 0xf8, 0x91, 0x92, 0xf2, 0x28, 0xa0, 0x77}};
};

ui_extension::window_factory<DropDownListToolbar<DspPresetToolbarArgs>> dsp_preset_toolbar;
Expand Down
3 changes: 3 additions & 0 deletions foo_ui_columns/order_dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct PlaybackOrderToolbarArgs {
static constexpr const wchar_t* class_name{L"columns_ui_playback_order_i3z1Bci1KNo"};
static constexpr const char* name{"Playback order"};
static constexpr GUID extension_guid{0xaba09e7e, 0x9c95, 0x443e, {0xbd, 0xfc, 0x4, 0x9d, 0x66, 0xb3, 0x24, 0xa0}};
static constexpr GUID colour_client_id{
0x9ab1c765, 0x31c7, 0x4ae9, {0xbf, 0xc1, 0xc6, 0x65, 0x76, 0xbf, 0x24, 0x83}};
static constexpr GUID font_client_id{0xb1ace74e, 0xddc0, 0x451f, {0x9a, 0x9a, 0xfc, 0x49, 0xdc, 0x4d, 0x5c, 0xfc}};
};

ui_extension::window_factory<DropDownListToolbar<PlaybackOrderToolbarArgs>> playback_order_toolbar;
Expand Down
2 changes: 2 additions & 0 deletions foo_ui_columns/output_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct OutputDeviceToolbarArgs {
static constexpr const wchar_t* class_name{L"columns_ui_output_device_DQLvIKXzFVY"};
static constexpr const char* name{"Output device"};
static constexpr GUID extension_guid{0xc25e4fe6, 0xb9a0, 0x48c3, {0xa4, 0xc0, 0x44, 0x3d, 0x69, 0xda, 0xd3, 0x6d}};
static constexpr GUID colour_client_id{0x45a4226d, 0xd606, 0x4917, {0xb1, 0x70, 0x86, 0x96, 0x50, 0xb, 0xab, 0x2b}};
static constexpr GUID font_client_id{0x20772a7b, 0xb5b5, 0x48c7, {0xa7, 0xca, 0x98, 0xde, 0x17, 0xff, 0xfc, 0xb4}};
};

service_ptr OutputDeviceToolbarArgs::callback_handle;
Expand Down
2 changes: 2 additions & 0 deletions foo_ui_columns/output_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct OutputFormatToolbarArgs {
static constexpr const wchar_t* class_name{L"columns_ui_output_format_TBWOn9HkOxhkU"};
static constexpr const char* name{"Output format"};
static constexpr GUID extension_guid{0xa379ccd9, 0xbc38, 0x4e2b, {0x85, 0xd6, 0x97, 0x5d, 0x11, 0x7b, 0xdd, 0xcc}};
static constexpr GUID colour_client_id{0xb5eaad91, 0x3939, 0x4cbe, {0x9a, 0x1f, 0xa9, 0xbb, 0xdc, 0xd0, 0x4, 0x8d}};
static constexpr GUID font_client_id{0x1fb03f29, 0x1a1d, 0x4d11, {0xb5, 0x74, 0xaf, 0x2e, 0xb2, 0x62, 0x48, 0xc2}};
};

service_ptr OutputFormatToolbarArgs::callback_handle;
Expand Down
2 changes: 2 additions & 0 deletions foo_ui_columns/replaygain_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct ReplayGainModeToolbarArgs {
static constexpr const wchar_t* class_name{L"columns_ui_replaygain_mode_-bdvzDNKnwDniA"};
static constexpr const char* name{"ReplayGain mode"};
static constexpr GUID extension_guid{0xad9a81f7, 0x723a, 0x4cce, {0x87, 0xb6, 0x13, 0x39, 0xb, 0xda, 0xc2, 0x16}};
static constexpr GUID colour_client_id{0x3096eaa4, 0xf97a, 0x4ff8, {0x84, 0xbd, 0xc6, 0xa, 0xcd, 0x69, 0x5e, 0xf9}};
static constexpr GUID font_client_id{0x25df8f6b, 0x78e9, 0x4555, {0xaf, 0x63, 0xa9, 0xc5, 0x8f, 0x2a, 0xbe, 0xe9}};
};

std::unique_ptr<ReplayGainCoreSettingsNotifyLambda> ReplayGainModeToolbarArgs::callback;
Expand Down

0 comments on commit 687ba68

Please sign in to comment.