Update color stripable color-picker(s)
authorRobin Gareus <robin@gareus.org>
Fri, 10 Mar 2017 22:51:39 +0000 (23:51 +0100)
committerRobin Gareus <robin@gareus.org>
Fri, 10 Mar 2017 23:33:43 +0000 (00:33 +0100)
* consistent behavior (Route, VCA)
* non-modal
* a single color picker for each RouteUI/VCA at most
* fix bug: VCA picker staying around even when VCA was deleted

gtk2_ardour/route_ui.cc
gtk2_ardour/route_ui.h
gtk2_ardour/stripable_colorpicker.cc [new file with mode: 0644]
gtk2_ardour/stripable_colorpicker.h [new file with mode: 0644]
gtk2_ardour/vca_master_strip.cc
gtk2_ardour/vca_master_strip.h
gtk2_ardour/wscript

index 1802425a5a62ab3f055e243676f9e9a892c1549b..c8c48f257e61b33fcd908234156bbcd50d92317c 100644 (file)
@@ -243,6 +243,8 @@ RouteUI::reset ()
        delete mute_menu;
        mute_menu = 0;
 
+       _color_picker.reset ();
+
        denormal_menu_item = 0;
 }
 
@@ -1604,13 +1606,7 @@ RouteUI::toggle_solo_safe (Gtk::CheckMenuItem* check)
 void
 RouteUI::choose_color ()
 {
-       bool picked;
-       Gdk::Color c (gdk_color_from_rgba (_route->presentation_info().color()));
-       Gdk::Color const color = Gtkmm2ext::UI::instance()->get_color (_("Color Selection"), picked, &c);
-
-       if (picked) {
-               set_color (gdk_color_to_rgba (color));
-       }
+       _color_picker.popup (_route);
 }
 
 /** Set the route's own color.  This may not be used for display if
index 6f53b7232d9f1e5cac2ad0e83ec79d06d5a23456..7e4dd2e9688bc4669ea9a6e440461552351936de 100644 (file)
@@ -26,6 +26,7 @@
 #include "pbd/signals.h"
 
 #include <gtkmm/textview.h>
+#include <gtkmm/colorselection.h>
 
 #include "gtkmm2ext/widget_state.h"
 
@@ -40,6 +41,7 @@
 
 #include "axis_view.h"
 #include "selectable.h"
+#include "stripable_colorpicker.h"
 #include "window_manager.h"
 
 namespace ARDOUR {
@@ -336,6 +338,8 @@ private:
        std::vector<ArdourButton*> _invert_buttons;
        Gtk::Menu* _invert_menu;
 
+       StripableColorDialog _color_picker;
+
        static void set_showing_sends_to (boost::shared_ptr<ARDOUR::Route>);
        static boost::weak_ptr<ARDOUR::Route> _showing_sends_to;
 
diff --git a/gtk2_ardour/stripable_colorpicker.cc b/gtk2_ardour/stripable_colorpicker.cc
new file mode 100644 (file)
index 0000000..6b92a94
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "stripable_colorpicker.h"
+#include "utils.h"
+
+using namespace Gtk;
+using namespace ARDOUR_UI_UTILS;
+
+StripableColorDialog::StripableColorDialog ()
+{
+       signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
+}
+
+StripableColorDialog::~StripableColorDialog ()
+{
+       reset ();
+}
+
+void
+StripableColorDialog::reset ()
+{
+       hide ();
+       _stripable.reset ();
+}
+
+void
+StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
+{
+       if (_stripable == s) {
+               /* keep modified color */
+               present ();
+               return;
+       }
+
+       _stripable = s;
+
+       get_colorsel()->set_has_opacity_control (false);
+       get_colorsel()->set_has_palette (true);
+
+       Gdk::Color c = gdk_color_from_rgba (_stripable->presentation_info().color ());
+
+       get_colorsel()->set_previous_color (c);
+       get_colorsel()->set_current_color (c);
+
+       present ();
+}
+
+void
+StripableColorDialog::finish_color_edit (int response)
+{
+       if (_stripable && response == RESPONSE_OK) {
+               _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
+       }
+       reset ();
+}
diff --git a/gtk2_ardour/stripable_colorpicker.h b/gtk2_ardour/stripable_colorpicker.h
new file mode 100644 (file)
index 0000000..79b7ffc
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __gtkardour_stripable_colorpicker_h__
+#define __gtkardour_stripable_colorpicker_h__
+
+#include <boost/shared_ptr.hpp>
+#include <gtkmm/colorselection.h>
+#include "ardour/stripable.h"
+
+class StripableColorDialog : public Gtk::ColorSelectionDialog
+{
+public:
+       StripableColorDialog ();
+       ~StripableColorDialog ();
+       void reset ();
+       void popup (boost::shared_ptr<ARDOUR::Stripable> s);
+
+private:
+       void finish_color_edit (int response);
+
+       boost::shared_ptr<ARDOUR::Stripable> _stripable;
+};
+
+#endif
index 5e96010c3c7cc9551073d932147d28c0353e3120..2d6088fbdf62405757d988b4f2c510caaeca5fd9 100644 (file)
@@ -17,7 +17,6 @@
 */
 
 #include <gtkmm/stock.h>
-#include <gtkmm/colorselection.h>
 
 #include "pbd/convert.h"
 
@@ -526,30 +525,7 @@ VCAMasterStrip::state_id () const
 void
 VCAMasterStrip::start_color_edit ()
 {
-       Gtk::ColorSelectionDialog* color_dialog = new Gtk::ColorSelectionDialog;
-
-       color_dialog->get_colorsel()->set_has_opacity_control (false);
-       color_dialog->get_colorsel()->set_has_palette (true);
-
-       Gdk::Color c = gdk_color_from_rgba (_vca->presentation_info().color ());
-
-       color_dialog->get_colorsel()->set_previous_color (c);
-       color_dialog->get_colorsel()->set_current_color (c);
-
-       color_dialog->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &VCAMasterStrip::finish_color_edit), color_dialog));
-       color_dialog->present ();
-}
-
-void
-VCAMasterStrip::finish_color_edit (int response, Gtk::ColorSelectionDialog* dialog)
-{
-       switch (response) {
-       case RESPONSE_OK:
-               _vca->presentation_info().set_color (gdk_color_to_rgba (dialog->get_colorsel()->get_current_color()));
-               break;
-       }
-
-       delete_when_idle (dialog);
+       _color_picker.popup (_vca);
 }
 
 bool
index 6cc728ea5214602d01dacda90eaab354536c98b2..0694b15e230c65ee20d7ab3eb53e870df628cfbf 100644 (file)
 
 #include <gtkmm/box.h>
 #include <gtkmm/menuitem.h>
+#include <gtkmm/colorselection.h>
 
 #include "ardour_button.h"
 #include "axis_view.h"
 #include "control_slave_ui.h"
 #include "gain_meter.h"
+#include "stripable_colorpicker.h"
 
 namespace ARDOUR {
        class GainControl;
@@ -107,7 +109,7 @@ class VCAMasterStrip : public AxisView, public Gtk::EventBox
        void update_bottom_padding ();
 
        void start_color_edit ();
-       void finish_color_edit (int, Gtk::ColorSelectionDialog*);
+       StripableColorDialog _color_picker;
 };
 
 
index 2e3ff2e6be19c47634b83188d2aec0dd1337c65a..7accf20fe5f0d9fdb605d508b58e27686ac4ab02 100644 (file)
@@ -243,6 +243,7 @@ gtk2_ardour_sources = [
         'stereo_panner_editor.cc',
         'streamview.cc',
         'strip_silence_dialog.cc',
+        'stripable_colorpicker.cc',
         'sys_ex.cc',
         'tape_region_view.cc',
         'tempo_curve.cc',