13
0

do not create a Gtk::ColorSelectionDialog for every trigger/slot, create on demand

This commit is contained in:
Paul Davis 2023-10-05 08:17:33 -06:00
parent 14973bd894
commit e23f79a8a9
2 changed files with 16 additions and 10 deletions

View File

@ -77,6 +77,7 @@ TriggerUI::TriggerUI ()
, _follow_context_menu (0)
, _context_menu (0)
, _ignore_menu_action (false)
, _color_dialog (nullptr)
{
if (follow_strings.empty()) {
follow_strings.push_back (follow_action_to_string (FollowAction (FollowAction::None)));
@ -120,6 +121,7 @@ TriggerUI::TriggerUI ()
TriggerUI::~TriggerUI()
{
delete _color_dialog;
trigger_swap_connection.disconnect ();
trigger_connections.drop_connections ();
}
@ -142,19 +144,23 @@ TriggerUI::trigger_swap (uint32_t n)
void
TriggerUI::choose_color ()
{
_color_dialog.get_color_selection()->set_has_opacity_control (false);
_color_dialog.get_color_selection()->set_has_palette (true);
_color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_ACCEPT));
_color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_CANCEL));
if (!_color_dialog) {
_color_dialog = new Gtk::ColorSelectionDialog;
}
_color_dialog->get_color_selection()->set_has_opacity_control (false);
_color_dialog->get_color_selection()->set_has_palette (true);
_color_dialog->get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_ACCEPT));
_color_dialog->get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_CANCEL));
Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba(trigger()->color());
_color_dialog.get_color_selection()->set_previous_color (c);
_color_dialog.get_color_selection()->set_current_color (c);
_color_dialog->get_color_selection()->set_previous_color (c);
_color_dialog->get_color_selection()->set_current_color (c);
switch (_color_dialog.run()) {
switch (_color_dialog->run()) {
case Gtk::RESPONSE_ACCEPT: {
c = _color_dialog.get_color_selection()->get_current_color();
c = _color_dialog->get_color_selection()->get_current_color();
color_t ct = Gtkmm2ext::gdk_color_to_rgba(c);
trigger()->set_color(ct);
} break;
@ -162,7 +168,7 @@ TriggerUI::choose_color ()
break;
}
_color_dialog.hide ();
_color_dialog->hide ();
}
void

View File

@ -122,7 +122,7 @@ protected:
Gtk::Menu* _context_menu;
bool _ignore_menu_action;
Gtk::ColorSelectionDialog _color_dialog;
Gtk::ColorSelectionDialog* _color_dialog;
void trigger_swap (uint32_t);
PBD::ScopedConnection trigger_swap_connection;