Make Markers properly themable, use color-names

This simplifies code, and also immediately changes marker
colors when the theme is changed.
This commit is contained in:
Robin Gareus 2023-05-18 00:45:14 +02:00
parent 8c861914c8
commit dbebc0b7e0
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
10 changed files with 108 additions and 115 deletions

View File

@ -267,11 +267,6 @@ Editor::Editor ()
, internal_snap_mode (SnapOff)
, _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
, _notebook_shrunk (false)
, location_marker_color (0)
, location_range_color (0)
, location_loop_color (0)
, location_punch_color (0)
, location_cd_marker_color (0)
, entered_marker (0)
, _show_marker_lines (false)
, clicked_axisview (0)
@ -502,12 +497,6 @@ Editor::Editor ()
build_draw_midi_menus();
build_edit_point_menu();
location_marker_color = UIConfiguration::instance().color ("location marker");
location_range_color = UIConfiguration::instance().color ("location range");
location_cd_marker_color = UIConfiguration::instance().color ("location cd marker");
location_loop_color = UIConfiguration::instance().color ("location loop");
location_punch_color = UIConfiguration::instance().color ("location punch");
timebar_height = std::max (12., ceil (15. * UIConfiguration::instance().get_ui_scale()));
TimeAxisView::setup_sizes ();

View File

@ -734,12 +734,6 @@ private:
void jump_forward_to_mark ();
void jump_backward_to_mark ();
uint32_t location_marker_color;
uint32_t location_range_color;
uint32_t location_loop_color;
uint32_t location_punch_color;
uint32_t location_cd_marker_color;
struct LocationMarkers {
ArdourMarker* start;
ArdourMarker* end;
@ -759,7 +753,7 @@ private:
void set_name (const std::string&);
void set_position (Temporal::timepos_t const & start, Temporal::timepos_t const & end = Temporal::timepos_t());
void set_color_rgba (uint32_t);
void set_color (std::string const&);
};
LocationMarkers* find_location_markers (ARDOUR::Location*) const;

View File

@ -146,8 +146,8 @@ Editor::initialize_canvas ()
/* group above rulers, to show selection triangles */
_selection_marker_group = new ArdourCanvas::Container (h_scroll_group);
CANVAS_DEBUG_NAME (_selection_marker_group, "Canvas Selection Ruler");
_selection_marker.start = new SelectionMarker (*this, *_selection_marker_group, 0xff0000ff, ArdourMarker::SelectionStart);
_selection_marker.end = new SelectionMarker (*this, *_selection_marker_group, 0xff0000ff, ArdourMarker::SelectionEnd);
_selection_marker.start = new SelectionMarker (*this, *_selection_marker_group, "play head", ArdourMarker::SelectionStart);
_selection_marker.end = new SelectionMarker (*this, *_selection_marker_group, "play head", ArdourMarker::SelectionEnd);
_selection_marker_group->raise_to_top ();
/* Note that because of ascending-y-axis coordinates, this order is
@ -1113,12 +1113,6 @@ Editor::color_handler()
rubberband_rect->set_outline_color (UIConfiguration::instance().color ("rubber band rect"));
rubberband_rect->set_fill_color (UIConfiguration::instance().color_mod ("rubber band rect", "selection rect"));
location_marker_color = UIConfiguration::instance().color ("location marker");
location_range_color = UIConfiguration::instance().color ("location range");
location_cd_marker_color = UIConfiguration::instance().color ("location cd marker");
location_loop_color = UIConfiguration::instance().color ("location loop");
location_punch_color = UIConfiguration::instance().color ("location punch");
refresh_location_display ();
NoteBase::set_colors ();

View File

@ -3095,7 +3095,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
_marker = new MeterMarker (
*_editor,
*_editor->meter_group,
UIConfiguration::instance().color ("meter marker"),
"meter marker",
name,
_marker->meter()
);

View File

@ -100,21 +100,21 @@ ArdourCanvas::Container*
Editor::add_new_location_internal (Location* location)
{
LocationMarkers *lam = new LocationMarkers;
uint32_t color;
std::string color;
/* make a note here of which group this marker ends up in */
ArdourCanvas::Container* group = 0;
if (location->is_cd_marker()) {
color = location_cd_marker_color;
color = X_("location cd marker");
} else if (location->is_mark()) {
color = location_marker_color;
color = X_("location marker");
} else if (location->is_auto_loop()) {
color = location_loop_color;
color = X_("location loop");
} else if (location->is_auto_punch()) {
color = location_punch_color;
color = X_("location punch");
} else {
color = location_range_color;
color = X_("location range");
}
if (location->is_mark()) {
@ -414,15 +414,15 @@ Editor::location_flags_changed (Location *location)
ensure_cd_marker_updated (lam, location);
if (location->is_cd_marker()) {
lam->set_color_rgba (location_cd_marker_color);
lam->set_color ("location cd marker");
} else if (location->is_mark()) {
lam->set_color_rgba (location_marker_color);
lam->set_color ("location marker");
} else if (location->is_auto_punch()) {
lam->set_color_rgba (location_punch_color);
lam->set_color ("location punch");
} else if (location->is_auto_loop()) {
lam->set_color_rgba (location_loop_color);
lam->set_color ("location loop");
} else {
lam->set_color_rgba (location_range_color);
lam->set_color ("location range");
}
if (location->is_hidden()) {
@ -691,11 +691,11 @@ Editor::LocationMarkers::set_position (timepos_t const & startt,
}
void
Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
Editor::LocationMarkers::set_color (std::string const& color_name)
{
start->set_color_rgba (rgba);
start->set_color (color_name);
if (end) {
end->set_color_rgba (rgba);
end->set_color (color_name);
}
}

View File

@ -2039,7 +2039,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
}
entered_marker = m_marker;
/* "music" currently serves as a stand-in for "entered". */
m_marker->set_color_rgba (UIConfiguration::instance().color ("meter marker music"));
m_marker->set_color ("meter marker music");
break;
case TempoMarkerItem:
@ -2048,7 +2048,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
}
entered_marker = t_marker;
/* "music" currently serves as a stand-in for "entered". */
t_marker->set_color_rgba (UIConfiguration::instance().color ("tempo marker music"));
t_marker->set_color ("tempo marker music");
break;
case FadeInHandleItem:
@ -2162,7 +2162,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent*, ItemType item_type)
if ((m_marker = static_cast<MeterMarker *> (item->get_data ("marker"))) == 0) {
break;
}
m_marker->set_color_rgba (UIConfiguration::instance().color ("meter marker"));
m_marker->set_color ("meter marker");
entered_marker = 0;
break;
@ -2170,7 +2170,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent*, ItemType item_type)
if ((t_marker = static_cast<TempoMarker *> (item->get_data ("marker"))) == 0) {
break;
}
t_marker->set_color_rgba (UIConfiguration::instance().color ("tempo marker"));
t_marker->set_color ("tempo marker");
entered_marker = 0;
break;

View File

@ -164,7 +164,7 @@ Editor::reassociate_bartime_marker (TempoMap::SharedPtr const & tmap, TempoMap::
void
Editor::make_bbt_marker (MusicTimePoint const * mtp, Marks::iterator before)
{
bbt_marks.insert (before, new BBTMarker (*this, *bbt_ruler, UIConfiguration::instance().color ("meter marker"), *mtp));
bbt_marks.insert (before, new BBTMarker (*this, *bbt_ruler, "meter marker", *mtp));
}
void
@ -173,7 +173,7 @@ Editor::make_meter_marker (Temporal::MeterPoint const * ms, Marks::iterator befo
char buf[64];
snprintf (buf, sizeof(buf), "%d/%d", ms->divisions_per_bar(), ms->note_value ());
meter_marks.insert (before, new MeterMarker (*this, *meter_group, UIConfiguration::instance().color ("meter marker"), buf, *ms));
meter_marks.insert (before, new MeterMarker (*this, *meter_group, "meter marker", buf, *ms));
}
void
@ -187,16 +187,16 @@ Editor::make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, d
const std::string tname (X_(""));
char const * color_name = X_("tempo marker");
tempo_marks.insert (before, new TempoMarker (*this, *tempo_group, *mapping_group, UIConfiguration::instance().color (color_name), tname, *ts, ts->sample (sr), tc_color));
tempo_marks.insert (before, new TempoMarker (*this, *tempo_group, *mapping_group, color_name, tname, *ts, ts->sample (sr), tc_color));
/* XXX the point of this code was "a jump in tempo by more than 1 ntpm results in a red
tempo mark pointer." (3a7bc1fd3f32f0)
*/
if (prev_ts && abs (prev_ts->end_note_types_per_minute() - ts->note_types_per_minute()) < 1.0) {
tempo_marks.back()->set_points_color (UIConfiguration::instance().color ("tempo marker music"));
tempo_marks.back()->set_points_color ("tempo marker music");
} else {
tempo_marks.back()->set_points_color (UIConfiguration::instance().color ("tempo marker"));
tempo_marks.back()->set_points_color ("tempo marker");
}
prev_ts = ts;

View File

@ -73,7 +73,15 @@ void ArdourMarker::setup_sizes(const double timebar_height)
marker_height = floor (timebar_height) - 2;
}
ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rgba, const string& annotation,
uint32_t
ArdourMarker::color (std::string const& color_name)
{
const Gtkmm2ext::SVAModifier alpha = UIConfiguration::instance().modifier (color_name);
return Gtkmm2ext::HSV (UIConfiguration::instance().color (color_name)).mod (alpha).color();
}
ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Item& parent, std::string const& color_name, string const& annotation,
Type type, timepos_t const & pos, bool handle_events, RegionView* rv)
: editor (ed)
@ -84,9 +92,8 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint3
, _entered (false)
, _shown (false)
, _line_shown (false)
, _color (rgba)
, pre_enter_color (rgba)
, _points_color (rgba)
, _color (color_name)
, _points_color (color_name)
, _left_label_limit (DBL_MAX)
, _right_label_limit (DBL_MAX)
, _label_offset (0)
@ -358,7 +365,7 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint3
_name_item->set_color (RGBA_TO_UINT (0,0,0,255));
_name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height - 4)*0.5 - (name_height) * .5 ));
set_color_rgba (rgba);
apply_color ();
set_name (annotation.c_str());
@ -375,6 +382,7 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint3
if (handle_events) {
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
}
UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourMarker::color_handler));
}
ArdourMarker::~ArdourMarker ()
@ -399,13 +407,13 @@ void ArdourMarker::reparent(ArdourCanvas::Item & parent)
void
ArdourMarker::set_selected (bool s)
{
if (_selected == s) {
return;
}
_selected = s;
setup_line ();
_pcue->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
_pmark->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
_pmark->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
apply_color ();
}
void
@ -420,13 +428,7 @@ ArdourMarker::set_entered (bool yn)
}
_entered = yn;
if (yn) {
pre_enter_color = _color;
set_color_rgba (UIConfiguration::instance().color ("entered marker"));
} else {
set_color_rgba (pre_enter_color);
}
apply_color ();
}
void
@ -471,7 +473,7 @@ ArdourMarker::setup_line ()
_track_canvas_line->set_x1 (d.x);
_track_canvas_line->set_y0 (d.y);
_track_canvas_line->set_y1 (_line_height > 0 ? d.y + _line_height : ArdourCanvas::COORD_MAX);
_track_canvas_line->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
_track_canvas_line->set_outline_color (UIConfiguration::instance().color (_selected ? "entered marker" : _color));
_track_canvas_line->raise_to_top ();
_track_canvas_line->show ();
@ -643,31 +645,43 @@ ArdourMarker::hide ()
}
void
ArdourMarker::set_points_color (uint32_t c)
ArdourMarker::set_points_color (std::string const& color_name)
{
_points_color = c;
_pcue->set_fill_color (_points_color);
_pmark->set_fill_color (_points_color);
_pmark->set_outline_color (_points_color);
_points_color = color_name;
uint32_t c = UIConfiguration::instance().color (_points_color);
_pcue->set_fill_color (c);
_pmark->set_fill_color (c);
_pmark->set_outline_color (c);
}
void
ArdourMarker::set_color_rgba (uint32_t c)
ArdourMarker::set_color (std::string const& color_name)
{
_color = c;
if (_color == color_name) {
return;
}
_color = color_name;
apply_color ();
}
_pcue->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
_pmark->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
_pmark->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
void
ArdourMarker::apply_color ()
{
uint32_t c = color (_entered ? "entered marker" : _color);
uint32_t cs = color (_selected || _entered ? "entered marker" : _color);
if (_track_canvas_line && ((_type == RegionCue) || !_selected)) {
_track_canvas_line->set_outline_color (_color);
_pcue->set_fill_color (cs);
_pmark->set_fill_color (cs);
_pmark->set_outline_color (cs);
if (_track_canvas_line) {
_track_canvas_line->set_outline_color (cs);
}
if (_name_item) {
if (_name_flag) {
/* make sure text stands out over bg color */
_name_item->set_color (contrasting_text_color (_color));
_name_item->set_color (contrasting_text_color (c));
} else {
_name_item->set_color (RGBA_TO_UINT (255,255,255,255)); //white: matched to TempoCurve text
}
@ -675,11 +689,18 @@ ArdourMarker::set_color_rgba (uint32_t c)
if (_name_flag) {
_name_flag->set_fill (true);
_name_flag->set_fill_color (_color);
_name_flag->set_fill_color (c);
_name_flag->set_outline (false);
}
}
void
ArdourMarker::color_handler ()
{
apply_color ();
set_points_color (_points_color);
}
/** Set the number of pixels that are available for a label to the left of the centre of this marker */
void
ArdourMarker::set_left_label_limit (double p)
@ -710,15 +731,15 @@ ArdourMarker::set_right_label_limit (double p)
}
}
MetricMarker::MetricMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rgba, const string& annotation,
MetricMarker::MetricMarker (PublicEditor& ed, ArdourCanvas::Item& parent, std::string const& color_name, const string& annotation,
Type type, timepos_t const & pos, bool handle_events)
: ArdourMarker (ed, parent, rgba, annotation, type, pos, false)
: ArdourMarker (ed, parent, color_name, annotation, type, pos, false)
{
}
/***********************************************************************/
SelectionMarker::SelectionMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, Type type)
: ArdourMarker (editor, parent, rgba, "", type, timepos_t(0), false)
SelectionMarker::SelectionMarker (PublicEditor& editor, ArdourCanvas::Item& parent, std::string const& color_name, Type type)
: ArdourMarker (editor, parent, color_name, "", type, timepos_t(0), false)
{
assert (type == SelectionStart || type == SelectionEnd);
#ifdef CANVAS_DEBUG
@ -729,8 +750,8 @@ SelectionMarker::SelectionMarker (PublicEditor& editor, ArdourCanvas::Item& pare
/***********************************************************************/
TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Item& parent, ArdourCanvas::Item& text_parent, guint32 rgba, const string& text, Temporal::TempoPoint const & temp, samplepos_t sample, uint32_t curve_color)
: MetricMarker (editor, parent, rgba, text, Tempo, temp.time(), false)
TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Item& parent, ArdourCanvas::Item& text_parent, std::string const& color_name, const string& text, Temporal::TempoPoint const & temp, samplepos_t sample, uint32_t curve_color)
: MetricMarker (editor, parent, color_name, text, Tempo, temp.time(), false)
, _tempo (&temp)
, _mapping_text (new ArdourCanvas::Text (&text_parent))
{
@ -800,8 +821,8 @@ TempoMarker::point() const
/***********************************************************************/
MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, const string& text, Temporal::MeterPoint const & m)
: MetricMarker (editor, parent, rgba, text, Meter, m.time(), false)
MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Item& parent, std::string const& color_name, const string& text, Temporal::MeterPoint const & m)
: MetricMarker (editor, parent, color_name, text, Meter, m.time(), false)
, _meter (&m)
{
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
@ -831,8 +852,8 @@ MeterMarker::point() const
/***********************************************************************/
BBTMarker::BBTMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, Temporal::MusicTimePoint const & p)
: MetricMarker (editor, parent, rgba, p.name(), BBTPosition, p.time(), false)
BBTMarker::BBTMarker (PublicEditor& editor, ArdourCanvas::Item& parent, std::string const& color_name, Temporal::MusicTimePoint const & p)
: MetricMarker (editor, parent, color_name, p.name(), BBTPosition, p.time(), false)
, _point (&p)
{
std::stringstream full_tooltip;

View File

@ -75,7 +75,7 @@ public:
};
ArdourMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, const std::string& text, Type,
ArdourMarker (PublicEditor& editor, ArdourCanvas::Item &, std::string const& color_name, std::string const& text, Type,
Temporal::timepos_t const & position, bool handle_events = true, RegionView* rv = 0);
virtual ~ArdourMarker ();
@ -93,8 +93,8 @@ public:
void set_position (Temporal::timepos_t const &);
void set_name (const std::string&, const std::string & tooltip = std::string());
void set_points_color (uint32_t rgba);
void set_color_rgba (uint32_t rgba);
void set_color (std::string const& color_name);
void set_points_color (std::string const& color_name);
void setup_line ();
ARDOUR::timepos_t position() const { return _position; }
@ -149,9 +149,10 @@ protected:
bool _entered;
bool _shown;
bool _line_shown;
uint32_t _color;
uint32_t pre_enter_color;
uint32_t _points_color;
std::string _color;
std::string _points_color;
double _left_label_limit; ///< the number of pixels available to the left of this marker for a label
double _right_label_limit; ///< the number of pixels available to the right of this marker for a label
double _label_offset;
@ -169,18 +170,22 @@ private:
/* disallow copy construction */
ArdourMarker (ArdourMarker const &);
ArdourMarker & operator= (ArdourMarker const &);
static uint32_t color (std::string const&);
void apply_color ();
void color_handler ();
};
class SelectionMarker : public ArdourMarker
{
public:
SelectionMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rgba, Type);
SelectionMarker (PublicEditor& ed, ArdourCanvas::Item& parent, std::string const& color_name, Type);
};
class MetricMarker : public ArdourMarker
{
public:
MetricMarker (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rgba, const std::string& annotation, Type type, Temporal::timepos_t const & pos, bool handle_events);
MetricMarker (PublicEditor& ed, ArdourCanvas::Item& parent, std::string const& color_name, const std::string& annotation, Type type, Temporal::timepos_t const & pos, bool handle_events);
virtual Temporal::Point const & point() const = 0;
virtual void update() = 0;
};
@ -188,7 +193,7 @@ class MetricMarker : public ArdourMarker
class TempoMarker : public MetricMarker
{
public:
TempoMarker (PublicEditor& editor, ArdourCanvas::Item & parent, ArdourCanvas::Item & text_parent, guint32 rgba, const std::string& text, Temporal::TempoPoint const &, samplepos_t sample, uint32_t curve_color);
TempoMarker (PublicEditor& editor, ArdourCanvas::Item & parent, ArdourCanvas::Item & text_parent, std::string const& color_name, const std::string& text, Temporal::TempoPoint const &, samplepos_t sample, uint32_t curve_color);
~TempoMarker ();
void reset_tempo (Temporal::TempoPoint const & t);
@ -209,7 +214,7 @@ class TempoMarker : public MetricMarker
class MeterMarker : public MetricMarker
{
public:
MeterMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, const std::string& text, Temporal::MeterPoint const &);
MeterMarker (PublicEditor& editor, ArdourCanvas::Item &, std::string const& color_name, const std::string& text, Temporal::MeterPoint const &);
~MeterMarker ();
void reset_meter (Temporal::MeterPoint const & m);
@ -225,7 +230,7 @@ class MeterMarker : public MetricMarker
class BBTMarker : public MetricMarker
{
public:
BBTMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, Temporal::MusicTimePoint const &);
BBTMarker (PublicEditor& editor, ArdourCanvas::Item &, std::string const& color_name, Temporal::MusicTimePoint const &);
~BBTMarker ();
void reset_point (Temporal::MusicTimePoint const &);

View File

@ -546,9 +546,6 @@ RegionView::update_cue_markers ()
const timepos_t start = region()->start();
const timepos_t end = region()->start() + region()->length();
const Gtkmm2ext::SVAModifier alpha = UIConfiguration::instance().modifier (X_("region mark"));
const uint32_t color = Gtkmm2ext::HSV (UIConfiguration::instance().color ("region mark")).mod (alpha).color();
/* We assume that if the region has multiple sources, any of them will
* be appropriate as the origin of cue markers. We use the first one.
*/
@ -593,8 +590,8 @@ RegionView::update_cue_markers ()
/* Create a new ViewCueMarker */
auto* mark = new ArdourMarker (trackview.editor(), *group, color , model_marker.text(), ArdourMarker::RegionCue, timepos_t (start.distance (model_marker.position())), true, this);
mark->set_points_color (color);
auto* mark = new ArdourMarker (trackview.editor(), *group, "region mark" , model_marker.text(), ArdourMarker::RegionCue, timepos_t (start.distance (model_marker.position())), true, this);
mark->set_points_color ("region mark");
mark->set_show_line (true);
/* make sure the line has a clean end, before the frame
of the region view
@ -715,13 +712,6 @@ RegionView::set_colors ()
{
TimeAxisViewItem::set_colors ();
set_sync_mark_color ();
const Gtkmm2ext::SVAModifier alpha = UIConfiguration::instance().modifier (X_("region mark"));
const uint32_t color = Gtkmm2ext::HSV (UIConfiguration::instance().color ("region mark")).mod (alpha).color();
for (auto& _cue_marker : _cue_markers) {
_cue_marker->view_marker->set_color_rgba (color);
}
}
void