From ce08ec0de0b0b077d9b28533c23886607991d144 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 9 Jun 2014 23:28:32 -0400 Subject: substantial changes in color management, involving a reduction in the use of Gdk::Color and more consistent logic for region coloring. Group tabs now also get the text drawn in an appropriately contrast-y color --- gtk2_ardour/audio_region_view.cc | 31 ++---------- gtk2_ardour/audio_region_view.h | 9 ++-- gtk2_ardour/audio_streamview.cc | 4 +- gtk2_ardour/audio_time_axis.cc | 2 +- gtk2_ardour/automation_region_view.cc | 8 ++- gtk2_ardour/automation_region_view.h | 4 +- gtk2_ardour/automation_streamview.cc | 2 +- gtk2_ardour/axis_view.h | 1 - gtk2_ardour/editor_drag.cc | 18 ++++--- gtk2_ardour/editor_group_tabs.cc | 28 ++++++++--- gtk2_ardour/editor_regions.cc | 2 +- gtk2_ardour/editor_route_groups.cc | 36 ++++++++------ gtk2_ardour/group_tabs.cc | 46 +++++++++++------- gtk2_ardour/group_tabs.h | 6 +-- gtk2_ardour/midi_region_view.cc | 26 +++------- gtk2_ardour/midi_region_view.h | 6 +-- gtk2_ardour/midi_streamview.cc | 2 +- gtk2_ardour/mixer_group_tabs.cc | 24 +++++++-- gtk2_ardour/note_base.cc | 14 ++---- gtk2_ardour/region_view.cc | 24 ++------- gtk2_ardour/region_view.h | 7 ++- gtk2_ardour/route_group_dialog.cc | 18 +++++-- gtk2_ardour/route_ui.cc | 4 +- gtk2_ardour/streamview.cc | 10 +++- gtk2_ardour/streamview.h | 9 ++-- gtk2_ardour/tape_region_view.cc | 13 ++--- gtk2_ardour/tape_region_view.h | 5 +- gtk2_ardour/time_axis_view_item.cc | 91 +++++++++++------------------------ gtk2_ardour/time_axis_view_item.h | 11 +++-- gtk2_ardour/utils.cc | 68 ++++++++++++++++++++++++-- gtk2_ardour/utils.h | 5 +- 31 files changed, 281 insertions(+), 253 deletions(-) diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index 966b77af87..9e95457d77 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -76,7 +76,7 @@ static const int32_t sync_mark_width = 9; static double const handle_size = 10; /* height of fade handles */ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, - Gdk::Color const & basic_color) + uint32_t basic_color) : RegionView (parent, tv, r, spu, basic_color) , sync_mark(0) , fade_in_handle(0) @@ -90,7 +90,6 @@ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView , end_xfade_rect (0) , _end_xfade_visible (false) , _amplitude_above_axis(1.0) - , fade_color(0) , trim_fade_in_drag_active(false) , trim_fade_out_drag_active(false) { @@ -98,7 +97,7 @@ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView } AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, - Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility) + uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility visibility) : RegionView (parent, tv, r, spu, basic_color, recording, visibility) , sync_mark(0) , fade_in_handle(0) @@ -112,7 +111,6 @@ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView , end_xfade_rect (0) , _end_xfade_visible (false) , _amplitude_above_axis(1.0) - , fade_color(0) , trim_fade_in_drag_active(false) , trim_fade_out_drag_active(false) { @@ -132,33 +130,24 @@ AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_pt , end_xfade_rect (0) , _end_xfade_visible (false) , _amplitude_above_axis (other._amplitude_above_axis) - , fade_color(0) , trim_fade_in_drag_active(false) , trim_fade_out_drag_active(false) { - Gdk::Color c; - int r,g,b,a; - - UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a); - c.set_rgb_p (r/255.0, g/255.0, b/255.0); - - init (c, true); + init (true); Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context()); } void -AudioRegionView::init (Gdk::Color const & basic_color, bool wfd) +AudioRegionView::init (bool wfd) { // FIXME: Some redundancy here with RegionView::init. Need to figure out // where order is important and where it isn't... - RegionView::init (basic_color, wfd); + RegionView::init (wfd); _amplitude_above_axis = 1.0; - compute_colors (basic_color); - create_waves (); if (!_recregion) { @@ -995,16 +984,6 @@ AudioRegionView::set_amplitude_above_axis (gdouble a) } } -void -AudioRegionView::compute_colors (Gdk::Color const & basic_color) -{ - RegionView::compute_colors (basic_color); - - /* gain color computed in envelope_active_changed() */ - - fade_color = UINT_RGBA_CHANGE_A (fill_color, 120); -} - void AudioRegionView::set_colors () { diff --git a/gtk2_ardour/audio_region_view.h b/gtk2_ardour/audio_region_view.h index a80dc5a7b6..20caea17c1 100644 --- a/gtk2_ardour/audio_region_view.h +++ b/gtk2_ardour/audio_region_view.h @@ -55,13 +55,13 @@ class AudioRegionView : public RegionView RouteTimeAxisView&, boost::shared_ptr, double initial_samples_per_pixel, - Gdk::Color const & basic_color); + uint32_t base_color); AudioRegionView (ArdourCanvas::Group *, RouteTimeAxisView&, boost::shared_ptr, double samples_per_pixel, - Gdk::Color const & basic_color, + uint32_t base_color, bool recording, TimeAxisViewItem::Visibility); @@ -69,7 +69,7 @@ class AudioRegionView : public RegionView ~AudioRegionView (); - virtual void init (Gdk::Color const & base_color, bool wait_for_data); + void init (bool wait_for_data); boost::shared_ptr audio_region() const; @@ -173,8 +173,6 @@ class AudioRegionView : public RegionView double _amplitude_above_axis; - uint32_t fade_color; - void reset_fade_shapes (); void reset_fade_in_shape (); void reset_fade_out_shape (); @@ -193,7 +191,6 @@ class AudioRegionView : public RegionView void set_colors (); void set_waveform_colors (); - void compute_colors (Gdk::Color const &); void reset_width_dependent_items (double pixel_width); void set_frame_color (); diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index 6880c8be5b..0520b1846c 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -110,7 +110,7 @@ AudioStreamView::create_region_view (boost::shared_ptr r, bool wait_for_ break; case Destructive: region_view = new TapeAudioRegionView (_canvas_group, _trackview, region, - _samples_per_pixel, region_color); + _samples_per_pixel, region_color); break; default: fatal << string_compose (_("programming error: %1"), "illegal track mode in ::add_region_view_internal") << endmsg; @@ -118,7 +118,7 @@ AudioStreamView::create_region_view (boost::shared_ptr r, bool wait_for_ } - region_view->init (region_color, wait_for_waves); + region_view->init (wait_for_waves); region_view->set_amplitude_above_axis(_amplitude_above_axis); region_view->set_height (child_height ()); diff --git a/gtk2_ardour/audio_time_axis.cc b/gtk2_ardour/audio_time_axis.cc index e59c43fc84..25e981acba 100644 --- a/gtk2_ardour/audio_time_axis.cc +++ b/gtk2_ardour/audio_time_axis.cc @@ -83,7 +83,7 @@ AudioTimeAxisView::set_route (boost::shared_ptr rt) RouteTimeAxisView::set_route (rt); - _view->apply_color (color (), StreamView::RegionColor); + _view->apply_color (gdk_color_to_rgba (color()), StreamView::RegionColor); // Make sure things are sane... assert(!is_track() || is_audio_track()); diff --git a/gtk2_ardour/automation_region_view.cc b/gtk2_ardour/automation_region_view.cc index 86e7121677..82c9278b01 100644 --- a/gtk2_ardour/automation_region_view.cc +++ b/gtk2_ardour/automation_region_view.cc @@ -45,7 +45,7 @@ AutomationRegionView::AutomationRegionView (ArdourCanvas::Group* const Evoral::Parameter& param, boost::shared_ptr list, double spu, - Gdk::Color const & basic_color) + uint32_t basic_color) : RegionView(parent, time_axis, region, spu, basic_color, true) , _parameter(param) { @@ -63,13 +63,11 @@ AutomationRegionView::~AutomationRegionView () } void -AutomationRegionView::init (Gdk::Color const & basic_color, bool /*wfd*/) +AutomationRegionView::init (bool /*wfd*/) { _enable_display = false; - RegionView::init(basic_color, false); - - compute_colors (basic_color); + RegionView::init (false); reset_width_dependent_items ((double) _region->length() / samples_per_pixel); diff --git a/gtk2_ardour/automation_region_view.h b/gtk2_ardour/automation_region_view.h index 726ce85d31..3b372bce7d 100644 --- a/gtk2_ardour/automation_region_view.h +++ b/gtk2_ardour/automation_region_view.h @@ -43,11 +43,11 @@ public: const Evoral::Parameter& parameter, boost::shared_ptr, double initial_samples_per_pixel, - Gdk::Color const & basic_color); + uint32_t basic_color); ~AutomationRegionView(); - void init (Gdk::Color const & basic_color, bool wfd); + void init (bool wfd); inline AutomationTimeAxisView* automation_view() const { return dynamic_cast(&trackview); } diff --git a/gtk2_ardour/automation_streamview.cc b/gtk2_ardour/automation_streamview.cc index f54b95cbc5..797f2741aa 100644 --- a/gtk2_ardour/automation_streamview.cc +++ b/gtk2_ardour/automation_streamview.cc @@ -113,7 +113,7 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr region _samples_per_pixel, region_color ); - region_view->init (region_color, false); + region_view->init (false); region_views.push_front (region_view); /* follow global waveform setting */ diff --git a/gtk2_ardour/axis_view.h b/gtk2_ardour/axis_view.h index 17f8c09a7b..8e777c2a58 100644 --- a/gtk2_ardour/axis_view.h +++ b/gtk2_ardour/axis_view.h @@ -83,7 +83,6 @@ class AxisView : public virtual Selectable, public PBD::ScopedConnectionList, pu */ static Gdk::Color unique_random_color(); - Gdk::Color _color; static std::list used_colors; diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 66ccd399aa..17e14f4441 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -743,7 +743,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) if (first_move) { rv->drag_start (); - rv->fake_set_opaque (true); + rv->set_opacity_for_drag (true); /* reparent the regionview into a group above all * others @@ -938,6 +938,10 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) void RegionMotionDrag::finished (GdkEvent *, bool) { + for (list::iterator i = _views.begin(); i != _views.end(); ++i) { + i->view->set_opacity_for_drag (false); + } + for (vector::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) { if (!(*i)->view()) { continue; @@ -1196,7 +1200,7 @@ RegionMoveDrag::finished_no_copy ( visible. */ rv->hide_region_editor(); - rv->fake_set_opaque (false); + rv->set_opacity_for_drag (false); remove_region_from_playlist (rv->region(), i->initial_playlist, modified_playlists); @@ -1431,7 +1435,7 @@ RegionMotionDrag::aborted (bool) rv->get_canvas_group()->reparent (rtv->view()->canvas_item()); rv->get_canvas_group()->set_y_position (0); rv->drag_end (); - rv->fake_set_opaque (false); + rv->set_opacity_for_drag (false); rv->move (-_total_x_delta, 0); rv->set_height (rtv->view()->child_height ()); } @@ -1833,7 +1837,7 @@ VideoTimeLineDrag::motion (GdkEvent* event, bool first_move) DEBUG_TRACE (DEBUG::Drags, string_compose("SHIFT REGION at %1 by %2\n", i->initial_position, dt)); if (first_move) { rv->drag_start (); - rv->fake_set_opaque (true); + rv->set_opacity_for_drag (true); rv->region()->clear_changes (); rv->region()->suspend_property_changes(); } @@ -1881,7 +1885,7 @@ VideoTimeLineDrag::finished (GdkEvent * /*event*/, bool movement_occurred) for (list::iterator i = _views.begin(); i != _views.end(); ++i) { i->view->drag_end(); - i->view->fake_set_opaque (false); + i->view->set_opacity_for_drag (false); i->view->region()->resume_property_changes (); _editor->session()->add_command (new StatefulDiffCommand (i->view->region())); @@ -2017,7 +2021,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move) for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { RegionView* rv = i->view; - rv->fake_set_opaque (false); + rv->set_opacity_for_drag (false); rv->enable_display (false); rv->region()->playlist()->clear_owned_changes (); @@ -2200,7 +2204,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred) for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { i->view->thaw_after_trim (); i->view->enable_display (true); - i->view->fake_set_opaque (true); + i->view->set_opacity_for_drag (true); /* Trimming one region may affect others on the playlist, so we need to get undo Commands from the whole playlist rather than just the diff --git a/gtk2_ardour/editor_group_tabs.cc b/gtk2_ardour/editor_group_tabs.cc index d02181c9b6..f53326636e 100644 --- a/gtk2_ardour/editor_group_tabs.cc +++ b/gtk2_ardour/editor_group_tabs.cc @@ -20,12 +20,17 @@ #include "gtkmm2ext/utils.h" #include "ardour/route_group.h" -#include "editor_group_tabs.h" + +#include "canvas/utils.h" + #include "editor.h" -#include "route_time_axis.h" -#include "utils.h" +#include "editor_group_tabs.h" #include "editor_route_groups.h" #include "editor_routes.h" +#include "rgb_macros.h" +#include "route_time_axis.h" +#include "utils.h" + #include "i18n.h" using namespace std; @@ -83,13 +88,19 @@ void EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const { double const arc_radius = get_width(); - + double r, g, b, a; + if (tab.group && tab.group->is_active()) { - cairo_set_source_rgba (cr, tab.color.get_red_p (), tab.color.get_green_p (), tab.color.get_blue_p (), 1); + ArdourCanvas::color_to_rgba (tab.color, r, g, b, a); } else { - cairo_set_source_rgba (cr, 1, 1, 1, 0.2); + r = 0.0; + g = 0.0; + b = 0.0; } + a = 1.0; + + cairo_set_source_rgba (cr, r, g, b, a); cairo_move_to (cr, 0, tab.from + arc_radius); cairo_arc (cr, get_width(), tab.from + arc_radius, arc_radius, M_PI, 3 * M_PI / 2); cairo_line_to (cr, get_width(), tab.to); @@ -103,7 +114,10 @@ EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const cairo_text_extents_t ext; cairo_text_extents (cr, tab.group->name().c_str(), &ext); - cairo_set_source_rgb (cr, 1, 1, 1); + ArdourCanvas::Color c = contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a)); + ArdourCanvas::color_to_rgba (c, r, g, b, a); + + cairo_set_source_rgb (cr, r, g, b); cairo_move_to (cr, get_width() - ext.height / 2, tab.from + (f.second + tab.to - tab.from) / 2); cairo_save (cr); cairo_rotate (cr, - M_PI / 2); diff --git a/gtk2_ardour/editor_regions.cc b/gtk2_ardour/editor_regions.cc index 69620d489f..54e520d8aa 100644 --- a/gtk2_ardour/editor_regions.cc +++ b/gtk2_ardour/editor_regions.cc @@ -346,7 +346,7 @@ EditorRegions::add_region (boost::shared_ptr region) c.set_rgb(0,65535,0); // FIXME: error color from style } else { - set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false )); + set_color_from_rgba (c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false )); } diff --git a/gtk2_ardour/editor_route_groups.cc b/gtk2_ardour/editor_route_groups.cc index 72f6adfa82..5d01ef207f 100644 --- a/gtk2_ardour/editor_route_groups.cc +++ b/gtk2_ardour/editor_route_groups.cc @@ -30,22 +30,22 @@ #include "gtkmm2ext/cell_renderer_color_selector.h" #include "ardour/route_group.h" +#include "ardour/route.h" +#include "ardour/session.h" +#include "ardour_ui.h" #include "editor.h" +#include "editor_group_tabs.h" +#include "editor_route_groups.h" +#include "editor_routes.h" +#include "gui_thread.h" #include "keyboard.h" #include "marker.h" -#include "time_axis_view.h" #include "prompter.h" -#include "gui_thread.h" -#include "editor_group_tabs.h" #include "route_group_dialog.h" #include "route_time_axis.h" -#include "editor_routes.h" -#include "editor_route_groups.h" -#include "ardour_ui.h" - -#include "ardour/route.h" -#include "ardour/session.h" +#include "time_axis_view.h" +#include "utils.h" #include "i18n.h" @@ -72,6 +72,7 @@ EditorRouteGroups::EditorRouteGroups (Editor* e) Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector); TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer)); + color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor); _display.append_column (*color_column); @@ -268,8 +269,7 @@ EditorRouteGroups::button_press_event (GdkEventButton* ev) switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) { case 0: - c = (*iter)[_columns.gdkcolor]; - + c = (*iter)[_columns.gdkcolor]; color_dialog.get_colorsel()->set_previous_color (c); color_dialog.get_colorsel()->set_current_color (c); @@ -278,7 +278,7 @@ EditorRouteGroups::button_press_event (GdkEventButton* ev) break; case RESPONSE_ACCEPT: c = color_dialog.get_colorsel()->get_current_color(); - GroupTabs::set_group_color (group, c); + GroupTabs::set_group_color (group, gdk_color_to_rgba (c)); ARDOUR_UI::config()->set_dirty (); break; @@ -409,7 +409,7 @@ EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel group->apply_changes (plist); - GroupTabs::set_group_color ((*iter)[_columns.routegroup], (*iter)[_columns.gdkcolor]); + GroupTabs::set_group_color ((*iter)[_columns.routegroup], gdk_color_to_rgba ((*iter)[_columns.gdkcolor])); } void @@ -430,7 +430,10 @@ EditorRouteGroups::add (RouteGroup* group) row[_columns.active_shared] = group->is_route_active (); row[_columns.active_state] = group->is_active (); row[_columns.is_visible] = !group->is_hidden(); - row[_columns.gdkcolor] = GroupTabs::group_color (group); + + Gdk::Color c; + set_color_from_rgba (c, GroupTabs::group_color (group)); + row[_columns.gdkcolor] = c; _in_row_change = true; @@ -500,7 +503,10 @@ EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange&) (*iter)[_columns.active_shared] = group->is_route_active (); (*iter)[_columns.active_state] = group->is_active (); (*iter)[_columns.is_visible] = !group->is_hidden(); - (*iter)[_columns.gdkcolor] = GroupTabs::group_color (group); + + Gdk::Color c; + set_color_from_rgba (c, GroupTabs::group_color (group)); + (*iter)[_columns.gdkcolor] = c; break; } diff --git a/gtk2_ardour/group_tabs.cc b/gtk2_ardour/group_tabs.cc index 05e8438709..9dd9dd51e3 100644 --- a/gtk2_ardour/group_tabs.cc +++ b/gtk2_ardour/group_tabs.cc @@ -28,6 +28,7 @@ #include "keyboard.h" #include "i18n.h" #include "ardour_ui.h" +#include "rgb_macros.h" #include "utils.h" using namespace std; @@ -535,19 +536,30 @@ GroupTabs::remove_group (RouteGroup* g) /** Set the color of the tab of a route group */ void -GroupTabs::set_group_color (RouteGroup* group, Gdk::Color color) +GroupTabs::set_group_color (RouteGroup* group, uint32_t color) { assert (group); + uint32_t r, g, b, a; + + UINT_TO_RGBA (color, &r, &g, &b, &a); /* Hack to disallow black route groups; force a dark grey instead */ - if (color.get_red() == 0 && color.get_green() == 0 && color.get_blue() == 0) { - color.set_grey_p (0.1); + + if (r == 0 && g == 0 && b == 0) { + r = 25; + g = 25; + b = 25; } GUIObjectState& gui_state = *ARDOUR_UI::instance()->gui_object_state; char buf[64]; - snprintf (buf, sizeof (buf), "%d:%d:%d", color.get_red(), color.get_green(), color.get_blue()); + + /* for historical reasons the colors must be stored as 16 bit color + * values. Ugh. + */ + + snprintf (buf, sizeof (buf), "%d:%d:%d", (r<<8), (g<<8), (b<<8)); gui_state.set_property (group_gui_id (group), "color", buf); /* the group color change notification */ @@ -577,35 +589,35 @@ GroupTabs::group_gui_id (RouteGroup* group) } /** @return the color to use for a route group tab */ -Gdk::Color +uint32_t GroupTabs::group_color (RouteGroup* group) { assert (group); GUIObjectState& gui_state = *ARDOUR_UI::instance()->gui_object_state; - string const gui_id = group_gui_id (group); - bool empty; string const color = gui_state.get_string (gui_id, "color", &empty); + if (empty) { /* no color has yet been set, so use a random one */ - Gdk::Color const color = unique_random_color (_used_colors); - set_group_color (group, color); - return color; + uint32_t c = gdk_color_to_rgba (unique_random_color (_used_colors)); + set_group_color (group, c); + return c; } - Gdk::Color c; - int r, g, b; + /* for historical reasons, colors are stored as 16 bit values. + */ + sscanf (color.c_str(), "%d:%d:%d", &r, &g, &b); - c.set_red (r); - c.set_green (g); - c.set_blue (b); - - return c; + r /= 256; + g /= 256; + b /= 256; + + return RGBA_TO_UINT (r, g, b, 255); } void diff --git a/gtk2_ardour/group_tabs.h b/gtk2_ardour/group_tabs.h index 0d83a553c1..ff231e8a68 100644 --- a/gtk2_ardour/group_tabs.h +++ b/gtk2_ardour/group_tabs.h @@ -50,9 +50,9 @@ public: void run_new_group_dialog (ARDOUR::RouteList const &); - static void set_group_color (ARDOUR::RouteGroup *, Gdk::Color); + static void set_group_color (ARDOUR::RouteGroup *, uint32_t); static std::string group_gui_id (ARDOUR::RouteGroup *); - static Gdk::Color group_color (ARDOUR::RouteGroup *); + static uint32_t group_color (ARDOUR::RouteGroup *); protected: @@ -61,7 +61,7 @@ protected: double from; double to; - Gdk::Color color; ///< color + uint32_t color; ///< color ARDOUR::RouteGroup* group; ///< route group }; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 0d17bdbf6a..db3f4760bc 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -89,7 +89,7 @@ PBD::Signal1 MidiRegionView::SelectionCleared; #define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1) MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, - boost::shared_ptr r, double spu, Gdk::Color const & basic_color) + boost::shared_ptr r, double spu, uint32_t basic_color) : RegionView (parent, tv, r, spu, basic_color) , _current_range_min(0) , _current_range_max(0) @@ -125,7 +125,7 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView & } MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, - boost::shared_ptr r, double spu, Gdk::Color& basic_color, + boost::shared_ptr r, double spu, uint32_t basic_color, TimeAxisViewItem::Visibility visibility) : RegionView (parent, tv, r, spu, basic_color, false, visibility) , _current_range_min(0) @@ -197,13 +197,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other) , pre_press_cursor (0) , _note_player (0) { - Gdk::Color c; - int r,g,b,a; - - UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a); - c.set_rgb_p (r/255.0, g/255.0, b/255.0); - - init (c, false); + init (false); } MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr region) @@ -231,17 +225,11 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptrmidi_source(0)->model(); _enable_display = false; - RegionView::init (basic_color, false); - - compute_colors (basic_color); + RegionView::init (false); set_height (trackview.current_height()); diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 1f1e9c3f2a..0f4dd52ff4 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -71,14 +71,14 @@ public: RouteTimeAxisView&, boost::shared_ptr, double initial_samples_per_pixel, - Gdk::Color const & basic_color); + uint32_t base_color); MidiRegionView (const MidiRegionView& other); MidiRegionView (const MidiRegionView& other, boost::shared_ptr); ~MidiRegionView (); - virtual void init (Gdk::Color const & basic_color, bool wfd); + void init (bool wfd); const boost::shared_ptr midi_region() const; @@ -313,7 +313,7 @@ protected: RouteTimeAxisView&, boost::shared_ptr, double samples_per_pixel, - Gdk::Color& basic_color, + uint32_t basic_color, TimeAxisViewItem::Visibility); void region_resized (const PBD::PropertyChange&); diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 04cbf8301d..b8bd0c257b 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -110,7 +110,7 @@ MidiStreamView::create_region_view (boost::shared_ptr r, bool /*wfd*/, b RegionView* region_view = new MidiRegionView (_canvas_group, _trackview, region, _samples_per_pixel, region_color); - region_view->init (region_color, false); + region_view->init (false); return region_view; } diff --git a/gtk2_ardour/mixer_group_tabs.cc b/gtk2_ardour/mixer_group_tabs.cc index 5878c3d3ac..964849c515 100644 --- a/gtk2_ardour/mixer_group_tabs.cc +++ b/gtk2_ardour/mixer_group_tabs.cc @@ -22,12 +22,17 @@ #include "gtkmm2ext/utils.h" #include "ardour/route_group.h" + +#include "canvas/utils.h" + #include "mixer_group_tabs.h" #include "mixer_strip.h" #include "mixer_ui.h" +#include "rgb_macros.h" +#include "route_group_dialog.h" #include "utils.h" + #include "i18n.h" -#include "route_group_dialog.h" using namespace std; using namespace Gtk; @@ -91,13 +96,19 @@ void MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const { double const arc_radius = get_height(); - + double r, g, b, a; + if (tab.group && tab.group->is_active()) { - cairo_set_source_rgba (cr, tab.color.get_red_p (), tab.color.get_green_p (), tab.color.get_blue_p (), 1); + ArdourCanvas::color_to_rgba (tab.color, r, g, b, a); } else { - cairo_set_source_rgba (cr, 1, 1, 1, 0.2); + r = 0.0; + g = 0.0; + b = 0.0; } + + a = 1.0; + cairo_set_source_rgba (cr, r, g, b, a); cairo_arc (cr, tab.from + arc_radius, get_height(), arc_radius, M_PI, 3 * M_PI / 2); cairo_line_to (cr, tab.to - arc_radius, 0); cairo_arc (cr, tab.to - arc_radius, get_height(), arc_radius, 3 * M_PI / 2, 2 * M_PI); @@ -109,8 +120,11 @@ MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const cairo_text_extents_t ext; cairo_text_extents (cr, tab.group->name().c_str(), &ext); + + ArdourCanvas::Color c = contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a)); + ArdourCanvas::color_to_rgba (c, r, g, b, a); - cairo_set_source_rgb (cr, 1, 1, 1); + cairo_set_source_rgb (cr, r, g, b); cairo_move_to (cr, tab.from + (tab.to - tab.from - f.second) / 2, get_height() - ext.height / 2); cairo_save (cr); cairo_show_text (cr, f.first.c_str()); diff --git a/gtk2_ardour/note_base.cc b/gtk2_ardour/note_base.cc index 3bdb73489e..1a02b6e02e 100644 --- a/gtk2_ardour/note_base.cc +++ b/gtk2_ardour/note_base.cc @@ -170,18 +170,14 @@ NoteBase::base_color() switch (mode) { case TrackColor: { - Gdk::Color color = _region.midi_stream_view()->get_region_color(); - return UINT_INTERPOLATE (RGBA_TO_UINT( - SCALE_USHORT_TO_UINT8_T(color.get_red()), - SCALE_USHORT_TO_UINT8_T(color.get_green()), - SCALE_USHORT_TO_UINT8_T(color.get_blue()), - opacity), - ARDOUR_UI::config()->get_canvasvar_MidiNoteSelected(), 0.5); + uint32_t color = _region.midi_stream_view()->get_region_color(); + return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (color, opacity), + ARDOUR_UI::config()->get_canvasvar_MidiNoteSelected(), + 0.5); } case ChannelColors: - return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (NoteBase::midi_channel_colors[_note->channel()], - opacity), + return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (NoteBase::midi_channel_colors[_note->channel()], opacity), ARDOUR_UI::config()->get_canvasvar_MidiNoteSelected(), 0.5); default: diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index c566d54f2d..378488ab51 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -66,7 +66,7 @@ RegionView::RegionView (ArdourCanvas::Group* parent, TimeAxisView& tv, boost::shared_ptr r, double spu, - Gdk::Color const & basic_color, + uint32_t basic_color, bool automation) : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false, automation, (automation ? TimeAxisViewItem::ShowFrame : @@ -131,7 +131,7 @@ RegionView::RegionView (ArdourCanvas::Group* parent, TimeAxisView& tv, boost::shared_ptr r, double spu, - Gdk::Color const & basic_color, + uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility visibility) : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, false, visibility) @@ -152,7 +152,7 @@ RegionView::RegionView (ArdourCanvas::Group* parent, } void -RegionView::init (Gdk::Color const & basic_color, bool wfd) +RegionView::init (bool wfd) { editor = 0; valid = true; @@ -163,8 +163,6 @@ RegionView::init (Gdk::Color const & basic_color, bool wfd) sync_mark = 0; sync_line = 0; - compute_colors (basic_color); - if (name_highlight) { name_highlight->set_data ("regionview", this); name_highlight->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this)); @@ -539,27 +537,13 @@ RegionView::set_frame_color () return; } - if (_region->opaque()) { - fill_opacity = 130; - } else { + if (!_region->opaque()) { fill_opacity = 60; } TimeAxisViewItem::set_frame_color (); } -void -RegionView::fake_set_opaque (bool yn) -{ - if (yn) { - fill_opacity = 130; - } else { - fill_opacity = 60; - } - - set_frame_color (); -} - void RegionView::show_region_editor () { diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index 59c1e364b8..ff2cf00a0d 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -53,7 +53,7 @@ class RegionView : public TimeAxisViewItem TimeAxisView& time_view, boost::shared_ptr region, double samples_per_pixel, - Gdk::Color const & basic_color, + uint32_t base_color, bool automation = false); RegionView (const RegionView& other); @@ -61,7 +61,7 @@ class RegionView : public TimeAxisViewItem ~RegionView (); - virtual void init (Gdk::Color const & base_color, bool wait_for_data); + virtual void init (bool wait_for_data); boost::shared_ptr region() const { return _region; } @@ -79,7 +79,6 @@ class RegionView : public TimeAxisViewItem void lower_to_bottom (); bool set_position(framepos_t pos, void* src, double* delta = 0); - void fake_set_opaque (bool yn); virtual void show_region_editor (); void hide_region_editor (); @@ -133,7 +132,7 @@ class RegionView : public TimeAxisViewItem TimeAxisView&, boost::shared_ptr, double samples_per_pixel, - Gdk::Color const & basic_color, + uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility); diff --git a/gtk2_ardour/route_group_dialog.cc b/gtk2_ardour/route_group_dialog.cc index bba72fb4a8..0919a715ae 100644 --- a/gtk2_ardour/route_group_dialog.cc +++ b/gtk2_ardour/route_group_dialog.cc @@ -17,15 +17,20 @@ */ +#include + +#include "ardour/route_group.h" +#include "ardour/session.h" + #include #include #include -#include "ardour/route_group.h" -#include "ardour/session.h" + #include "route_group_dialog.h" #include "group_tabs.h" +#include "utils.h" + #include "i18n.h" -#include using namespace Gtk; using namespace ARDOUR; @@ -84,7 +89,10 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new) _name.set_text (_group->name ()); _active.set_active (_group->is_active ()); - _color.set_color (GroupTabs::group_color (_group)); + + Gdk::Color c; + set_color_from_rgba (c, GroupTabs::group_color (_group)); + _color.set_color (c); VBox* options_box = manage (new VBox); options_box->set_spacing (6); @@ -212,7 +220,7 @@ RouteGroupDialog::update () _group->apply_changes (plist); - GroupTabs::set_group_color (_group, _color.get_color ()); + GroupTabs::set_group_color (_group, gdk_color_to_rgba (_color.get_color ())); } void diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index d8db8b5bd9..caf7199930 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -2015,7 +2015,9 @@ RouteUI::color () const RouteGroup* g = _route->route_group (); if (g && g->is_color()) { - return GroupTabs::group_color (g); + Gdk::Color c; + set_color_from_rgba (c, GroupTabs::group_color (g)); + return c; } return _color; diff --git a/gtk2_ardour/streamview.cc b/gtk2_ardour/streamview.cc index 404b934562..97e3d3aa79 100644 --- a/gtk2_ardour/streamview.cc +++ b/gtk2_ardour/streamview.cc @@ -343,7 +343,13 @@ StreamView::diskstream_changed () } void -StreamView::apply_color (Gdk::Color color, ColorTarget target) +StreamView::apply_color (Gdk::Color const& c, ColorTarget target) +{ + return apply_color (gdk_color_to_rgba (c), target); +} + +void +StreamView::apply_color (uint32_t color, ColorTarget target) { list::iterator i; @@ -356,7 +362,7 @@ StreamView::apply_color (Gdk::Color color, ColorTarget target) break; case StreamBaseColor: - stream_base_color = RGBA_TO_UINT (color.get_red_p(), color.get_green_p(), color.get_blue_p(), 255); + stream_base_color = color; canvas_rect->set_fill_color (stream_base_color); break; } diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index e7608cb02c..e0d60baf34 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -89,8 +89,9 @@ public: StreamBaseColor }; - Gdk::Color get_region_color () const { return region_color; } - void apply_color (Gdk::Color, ColorTarget t); + uint32_t get_region_color () const { return region_color; } + void apply_color (uint32_t, ColorTarget t); + void apply_color (Gdk::Color const &, ColorTarget t); uint32_t num_selected_regionviews () const; @@ -164,8 +165,8 @@ protected: bool rec_updating; bool rec_active; - Gdk::Color region_color; ///< Contained region color - uint32_t stream_base_color; ///< Background color + uint32_t region_color; ///< Contained region color + uint32_t stream_base_color; ///< Background color PBD::ScopedConnectionList playlist_connections; PBD::ScopedConnection playlist_switched_connection; diff --git a/gtk2_ardour/tape_region_view.cc b/gtk2_ardour/tape_region_view.cc index d626f3df49..62d37a9f7e 100644 --- a/gtk2_ardour/tape_region_view.cc +++ b/gtk2_ardour/tape_region_view.cc @@ -49,7 +49,7 @@ const TimeAxisViewItem::Visibility TapeAudioRegionView::default_tape_visibility TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, - Gdk::Color const & basic_color) + uint32_t basic_color) : AudioRegionView (parent, tv, r, spu, basic_color, false, TimeAxisViewItem::Visibility ((r->position() != 0) ? default_tape_visibility : @@ -58,13 +58,13 @@ TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTime } void -TapeAudioRegionView::init (Gdk::Color const & basic_color, bool /*wfw*/) +TapeAudioRegionView::init (bool /*wfw*/) { /* never wait for data: always just create the waves, connect once and then we'll update whenever we need to. */ - AudioRegionView::init(basic_color, false); + AudioRegionView::init (false); /* every time the wave data changes and peaks are ready, redraw */ @@ -91,10 +91,3 @@ TapeAudioRegionView::update (uint32_t /*n*/) // CAIROCANVAS // waves[n]->rebuild (); } - -void -TapeAudioRegionView::set_frame_color () -{ - fill_opacity = 255; - AudioRegionView::set_frame_color (); -} diff --git a/gtk2_ardour/tape_region_view.h b/gtk2_ardour/tape_region_view.h index c0e04cd8da..bda41ca8ad 100644 --- a/gtk2_ardour/tape_region_view.h +++ b/gtk2_ardour/tape_region_view.h @@ -31,13 +31,12 @@ class TapeAudioRegionView : public AudioRegionView RouteTimeAxisView&, boost::shared_ptr, double initial_samples_per_pixel, - Gdk::Color const & base_color); + uint32_t base_color); ~TapeAudioRegionView (); protected: - void init (Gdk::Color const & base_color, bool wait_for_waves); + void init (bool wait_for_waves); - void set_frame_color (); void update (uint32_t n); static const TimeAxisViewItem::Visibility default_tape_visibility; diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index 987e541144..8f1efd1902 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -120,7 +120,7 @@ TimeAxisViewItem::set_constant_heights () * @param automation true if this is an automation region view */ TimeAxisViewItem::TimeAxisViewItem( - const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color const & base_color, + const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, uint32_t base_color, framepos_t start, framecnt_t duration, bool recording, bool automation, Visibility vis ) : trackview (tv) @@ -148,25 +148,18 @@ TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other) , _dragging (other._dragging) , _width (0.0) { - - Gdk::Color c; - int r,g,b,a; - - UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a); - c.set_rgb_p (r/255.0, g/255.0, b/255.0); - /* share the other's parent, but still create a new group */ ArdourCanvas::Group* parent = other.group->parent(); _selected = other._selected; - init (parent, other.samples_per_pixel, c, other.frame_position, + init (parent, other.samples_per_pixel, other.fill_color, other.frame_position, other.item_duration, other.visibility, other.wide_enough_for_name, other.high_enough_for_name); } void -TimeAxisViewItem::init (ArdourCanvas::Group* parent, double fpp, Gdk::Color const & base_color, +TimeAxisViewItem::init (ArdourCanvas::Group* parent, double fpp, uint32_t base_color, framepos_t start, framepos_t duration, Visibility vis, bool wide, bool high) { @@ -174,6 +167,8 @@ TimeAxisViewItem::init (ArdourCanvas::Group* parent, double fpp, Gdk::Color cons CANVAS_DEBUG_NAME (group, string_compose ("TAVI group for %1", get_item_name())); group->Event.connect (sigc::mem_fun (*this, &TimeAxisViewItem::canvas_group_event)); + fill_color = base_color; + pre_drag_fill_color = base_color; samples_per_pixel = fpp; frame_position = start; item_duration = duration; @@ -642,9 +637,10 @@ TimeAxisViewItem::manage_name_highlight () } void -TimeAxisViewItem::set_color (Gdk::Color const & base_color) +TimeAxisViewItem::set_color (uint32_t base_color) { - compute_colors (base_color); + fill_color = base_color; + fill_opacity = UINT_RGBA_A (fill_color); set_colors (); } @@ -666,24 +662,6 @@ TimeAxisViewItem::get_name_highlight() return name_highlight; } -/** - * Calculate some contrasting color for displaying various parts of this item, based upon the base color. - * - * @param color the base color of the item - */ -void -TimeAxisViewItem::compute_colors (Gdk::Color const & base_color) -{ - unsigned char r,g,b; - - /* FILL: change opacity to a fixed value */ - - r = base_color.get_red()/256; - g = base_color.get_green()/256; - b = base_color.get_blue()/256; - fill_color = RGBA_TO_UINT(r,g,b,160); -} - /** * Convenience method to set the various canvas item colors */ @@ -707,15 +685,6 @@ TimeAxisViewItem::set_name_text_color () return; } - double r, g, b, a; - - const double black_r = 0.0; - const double black_g = 0.0; - const double black_b = 0.0; - - const double white_r = 1.0; - const double white_g = 1.0; - const double white_b = 1.0; uint32_t f; @@ -731,25 +700,7 @@ TimeAxisViewItem::set_name_text_color () f = get_fill_color (); } - ArdourCanvas::color_to_rgba (f, r, g, b, a); - - /* Use W3C contrast guideline calculation */ - - double white_contrast = (max (r, white_r) - min (r, white_r)) + - (max (g, white_g) - min (g, white_g)) + - (max (b, white_b) - min (b, white_b)); - - double black_contrast = (max (r, black_r) - min (r, black_r)) + - (max (g, black_g) - min (g, black_g)) + - (max (b, black_b) - min (b, black_b)); - - if (white_contrast > black_contrast) { - /* use white */ - name_text->set_color (ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0)); - } else { - /* use black */ - name_text->set_color (ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0)); - } + name_text->set_color (contrasting_text_color (f)); } uint32_t @@ -777,22 +728,25 @@ TimeAxisViewItem::get_fill_color () const if (_recregion) { f = ARDOUR_UI::config()->get_canvasvar_RecordingRect(); } else { - - if (high_enough_for_name && !ARDOUR_UI::config()->get_color_regions_using_track_color()) { + if ((!Config->get_show_name_highlight() || high_enough_for_name) && !ARDOUR_UI::config()->get_color_regions_using_track_color()) { f = ARDOUR_UI::config()->get_canvasvar_FrameBase(); + /* use the opacity as set for the FrameBase color */ + o = UINT_RGBA_A (f); } else { f = fill_color; + o = fill_opacity; } } /* tweak opacity */ if (!rect_visible) { + /* if the frame/rect is marked as invisible, then the + * fill should be transparent. simplest: set + * alpha/opacity to zero. + */ o = 0; - } else { - o = fill_opacity; } - } return UINT_RGBA_CHANGE_A (f, o); @@ -829,6 +783,17 @@ TimeAxisViewItem::set_frame_color() } } +void +TimeAxisViewItem::set_opacity_for_drag (bool drag_starting) +{ + if (drag_starting) { + fill_opacity = 130; + } else { + fill_opacity = UINT_RGBA_A (fill_color); + } + set_frame_color (); +} + void TimeAxisViewItem::set_frame_gradient () { diff --git a/gtk2_ardour/time_axis_view_item.h b/gtk2_ardour/time_axis_view_item.h index faa6ba5d06..76fbbd92e2 100644 --- a/gtk2_ardour/time_axis_view_item.h +++ b/gtk2_ardour/time_axis_view_item.h @@ -72,8 +72,9 @@ class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList void set_name_text(const std::string&); virtual void set_height(double h); void set_y (double); - void set_color (Gdk::Color const &); + void set_color (uint32_t); void set_name_text_color (); + void set_opacity_for_drag (bool drag_starting); uint32_t get_fill_color () const; @@ -169,16 +170,15 @@ class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList }; protected: - TimeAxisViewItem(const std::string &, ArdourCanvas::Group&, TimeAxisView&, double, Gdk::Color const &, - framepos_t, framecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0)); + TimeAxisViewItem (const std::string &, ArdourCanvas::Group&, TimeAxisView&, double, uint32_t fill_color, + framepos_t, framecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0)); TimeAxisViewItem (const TimeAxisViewItem&); - void init (ArdourCanvas::Group*, double, Gdk::Color const &, framepos_t, framepos_t, Visibility, bool, bool); + void init (ArdourCanvas::Group*, double, uint32_t, framepos_t, framepos_t, Visibility, bool, bool); virtual bool canvas_group_event (GdkEvent*); - virtual void compute_colors (Gdk::Color const &); virtual void set_colors(); virtual void set_frame_color(); virtual void set_frame_gradient (); @@ -232,6 +232,7 @@ class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList uint32_t fill_opacity; uint32_t fill_color; + uint32_t pre_drag_fill_color; uint32_t frame_color_r; uint32_t frame_color_g; uint32_t frame_color_b; diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index a8b46f1f57..a04e37f9e5 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -45,7 +45,9 @@ #include #include "ardour/rc_configuration.h" #include "ardour/filesystem_paths.h" + #include "canvas/item.h" +#include "canvas/utils.h" #include "ardour_ui.h" #include "debug.h" @@ -288,7 +290,7 @@ rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a, s if (state == Gtk::STATE_NORMAL && rgba) { return (uint32_t) RGBA_TO_UINT(r,g,b,a); } else { - return (uint32_t) RGB_TO_UINT(r,g,b); + return (uint32_t) RGBA_TO_UINT(r,g,b,255); } } @@ -340,9 +342,69 @@ rgba_p_from_style (string style, float *r, float *g, float *b, string attr, int } void -set_color (Gdk::Color& c, int rgb) +set_color_from_rgb (Gdk::Color& c, uint32_t rgb) +{ + /* Gdk::Color color ranges are 16 bit, so scale from 8 bit by + multiplying by 256. + */ + c.set_rgb ((rgb >> 16)*256, ((rgb & 0xff00) >> 8)*256, (rgb & 0xff)*256); +} + +void +set_color_from_rgba (Gdk::Color& c, uint32_t rgba) +{ + /* Gdk::Color color ranges are 16 bit, so scale from 8 bit by + multiplying by 256. + */ + c.set_rgb ((rgba >> 24)*256, ((rgba & 0xff0000) >> 16)*256, ((rgba & 0xff00) >> 8)*256); +} + +uint32_t +gdk_color_to_rgba (Gdk::Color const& c) +{ + /* since alpha value is not available from a Gdk::Color, it is + hardcoded as 0xff (aka 255 or 1.0) + */ + + const uint32_t r = c.get_red_p () * 255.0; + const uint32_t g = c.get_green_p () * 255.0; + const uint32_t b = c.get_blue_p () * 255.0; + const uint32_t a = 0xff; + + return RGBA_TO_UINT (r,g,b,a); +} + +uint32_t +contrasting_text_color (uint32_t c) { - c.set_rgb((rgb >> 16)*256, ((rgb & 0xff00) >> 8)*256, (rgb & 0xff)*256); + double r, g, b, a; + ArdourCanvas::color_to_rgba (c, r, g, b, a); + + const double black_r = 0.0; + const double black_g = 0.0; + const double black_b = 0.0; + + const double white_r = 1.0; + const double white_g = 1.0; + const double white_b = 1.0; + + /* Use W3C contrast guideline calculation */ + + double white_contrast = (max (r, white_r) - min (r, white_r)) + + (max (g, white_g) - min (g, white_g)) + + (max (b, white_b) - min (b, white_b)); + + double black_contrast = (max (r, black_r) - min (r, black_r)) + + (max (g, black_g) - min (g, black_g)) + + (max (b, black_b) - min (b, black_b)); + + if (white_contrast > black_contrast) { + /* use white */ + return ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0); + } else { + /* use black */ + return ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0); + } } bool diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index 30ccd9c43d..bf5e5b85f5 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -65,7 +65,10 @@ bool rgba_p_from_style (std::string, float*, float*, float*, std::string = "fg", void decorate (Gtk::Window& w, Gdk::WMDecoration d); -void set_color (Gdk::Color&, int); +void set_color_from_rgb (Gdk::Color&, uint32_t); +void set_color_from_rgba (Gdk::Color&, uint32_t); +uint32_t gdk_color_to_rgba (Gdk::Color const&); +uint32_t contrasting_text_color (uint32_t c); bool relay_key_press (GdkEventKey* ev, Gtk::Window* win); bool forward_key_press (GdkEventKey* ev); -- cgit v1.2.3