X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fmarker.cc;h=d5517b4bcedeed72ae4c536a8bda071f1921771a;hb=2592a320d42dd4a157ee16101c042d875d3142be;hp=0d124f556c46a497671d8ee84fa579dc36df75d7;hpb=8e591b058786c842c46790c96b806ad1eca6cbec;p=ardour.git diff --git a/gtk2_ardour/marker.cc b/gtk2_ardour/marker.cc index 0d124f556c..d5517b4bce 100644 --- a/gtk2_ardour/marker.cc +++ b/gtk2_ardour/marker.cc @@ -18,21 +18,23 @@ $Id$ */ +#include #include #include "marker.h" #include "public_editor.h" -#include "canvas-simpleline.h" #include "utils.h" +#include "canvas_impl.h" #include "i18n.h" -Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const string& annotation, - Type type, gint (*callback)(GnomeCanvasItem *, GdkEvent *, gpointer), jack_nframes_t frame) +Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation, + Type type, nframes_t frame, bool handle_events) : editor (ed), _type(type) { double label_offset = 0; + bool annotate_left = false; /* Shapes we use: @@ -59,88 +61,81 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const Start: - 0,0 -> 5,0 - | \ - | 10,5 - | / - 0,10 -> 5,10 + 0,0\ + | \ + | \ 6,6 + | / + | / + 0,12 End: - 5,0 -> 10,0 - / | - 0,5 | - \ | - 5,10 <-10,10 + /12,0 + / | + / | + 6,6 | + \ | + \ | + \ | + 12,12 TransportStart: - 0,0->3,0 - | | - | | - | | - | 3,8 -> 7,8 - | | - 0,11 ------ 7,11 + 0,0 + | \ + | \ + | \ + | \ + | \ + 0,13 --- 13,13 TransportEnd: - 4,0->7,0 - | | - | | - | | - 0,8 ---- 4,8 | - | | - 0,11 -------- 7,11 + /13,0 + / | + / | + / | + / | + / | + 0,13 ------ 13,13 PunchIn: - 0,0 ------> 8,0 + 0,0 ------> 13,0 | / | / - | 4,5 - | | - | | - | | - 0,11->4,11 + | / + | / + | / + | / + 0,13 PunchOut - 0,0 -->-8,0 + 0,0 -->-13,0 \ | \ | - 4,5 | - | | - | | - | | - 4,11->8,11 + \ | + \ | + \ | + \ | + 13,13 */ switch (type) { case Mark: - points = gnome_canvas_points_new (6); + points = new ArdourCanvas::Points (); - points->coords[0] = 0.0; - points->coords[1] = 0.0; - - points->coords[2] = 6.0; - points->coords[3] = 0.0; - - points->coords[4] = 6.0; - points->coords[5] = 5.0; - - points->coords[6] = 3.0; - points->coords[7] = 10.0; - - points->coords[8] = 0.0; - points->coords[9] = 5.0; - - points->coords[10] = 0.0; - points->coords[11] = 0.0; + points->push_back (Gnome::Art::Point (0.0, 0.0)); + points->push_back (Gnome::Art::Point (6.0, 0.0)); + points->push_back (Gnome::Art::Point (6.0, 5.0)); + points->push_back (Gnome::Art::Point (3.0, 10.0)); + points->push_back (Gnome::Art::Point (0.0, 5.0)); + points->push_back (Gnome::Art::Point (0.0, 0.0)); shift = 3; label_offset = 8.0; @@ -148,184 +143,86 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const case Tempo: case Meter: - points = gnome_canvas_points_new (6); - points->coords[0] = 3.0; - points->coords[1] = 0.0; - - points->coords[2] = 6.0; - points->coords[3] = 5.0; - - points->coords[4] = 6.0; - points->coords[5] = 10.0; - - points->coords[6] = 0.0; - points->coords[7] = 10.0; - - points->coords[8] = 0.0; - points->coords[9] = 5.0; - - points->coords[10] = 3.0; - points->coords[11] = 0.0; - + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (3.0, 0.0)); + points->push_back (Gnome::Art::Point (6.0, 5.0)); + points->push_back (Gnome::Art::Point (6.0, 10.0)); + points->push_back (Gnome::Art::Point (0.0, 10.0)); + points->push_back (Gnome::Art::Point (0.0, 5.0)); + points->push_back (Gnome::Art::Point (3.0, 0.0)); + shift = 3; label_offset = 8.0; break; case Start: - points = gnome_canvas_points_new (6); + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (0.0, 0.0)); + points->push_back (Gnome::Art::Point (6.5, 6.5)); + points->push_back (Gnome::Art::Point (0.0, 13.0)); + points->push_back (Gnome::Art::Point (0.0, 0.0)); - points->coords[0] = 0.0; - points->coords[1] = 0.0; - - points->coords[2] = 5.0; - points->coords[3] = 0.0; - - points->coords[4] = 10.0; - points->coords[5] = 5.0; - - points->coords[6] = 5.0; - points->coords[7] = 10.0; - - points->coords[8] = 0.0; - points->coords[9] = 10.0; - - points->coords[10] = 0.0; - points->coords[11] = 0.0; - - shift = 10; - label_offset = 12.0; + shift = 0; + label_offset = 13.0; break; case End: - points = gnome_canvas_points_new (6); - - points->coords[0] = 5.0; - points->coords[1] = 0.0; - - points->coords[2] = 10.0; - points->coords[3] = 0.0; - - points->coords[4] = 10.0; - points->coords[5] = 10.0; - - points->coords[6] = 5.0; - points->coords[7] = 10.0; - - points->coords[8] = 0.0; - points->coords[9] = 5.0; - - points->coords[10] = 5.0; - points->coords[11] = 0.0; - - shift = 0; - label_offset = 12.0; + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (6.5, 6.5)); + points->push_back (Gnome::Art::Point (13.0, 0.0)); + points->push_back (Gnome::Art::Point (13.0, 13.0)); + points->push_back (Gnome::Art::Point (6.5, 6.5)); + + shift = 13; + label_offset = 6.0; + annotate_left = true; break; case LoopStart: - points = gnome_canvas_points_new (7); - - points->coords[0] = 0.0; - points->coords[1] = 0.0; - - points->coords[2] = 4.0; - points->coords[3] = 0.0; - - points->coords[4] = 4.0; - points->coords[5] = 8.0; - - points->coords[6] = 8.0; - points->coords[7] = 8.0; - - points->coords[8] = 8.0; - points->coords[9] = 11.0; - - points->coords[10] = 0.0; - points->coords[11] = 11.0; - - points->coords[12] = 0.0; - points->coords[13] = 0.0; + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (0.0, 0.0)); + points->push_back (Gnome::Art::Point (13.0, 13.0)); + points->push_back (Gnome::Art::Point (0.0, 13.0)); + points->push_back (Gnome::Art::Point (0.0, 0.0)); shift = 0; - label_offset = 11.0; + label_offset = 12.0; break; case LoopEnd: - points = gnome_canvas_points_new (7); - - points->coords[0] = 8.0; - points->coords[1] = 0.0; - - points->coords[2] = 8.0; - points->coords[3] = 11.0; - - points->coords[4] = 0.0; - points->coords[5] = 11.0; - - points->coords[6] = 0.0; - points->coords[7] = 8.0; - - points->coords[8] = 4.0; - points->coords[9] = 8.0; - - points->coords[10] = 4.0; - points->coords[11] = 0.0; - - points->coords[12] = 8.0; - points->coords[13] = 0.0; - - shift = 8; - label_offset = 11.0; + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (13.0, 0.0)); + points->push_back (Gnome::Art::Point (13.0, 13.0)); + points->push_back (Gnome::Art::Point (0.0, 13.0)); + points->push_back (Gnome::Art::Point (13.0, 0.0)); + + shift = 13; + label_offset = 0.0; + annotate_left = true; break; case PunchIn: - points = gnome_canvas_points_new (6); + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (0.0, 0.0)); + points->push_back (Gnome::Art::Point (13.0, 0.0)); + points->push_back (Gnome::Art::Point (0.0, 13.0)); + points->push_back (Gnome::Art::Point (0.0, 0.0)); - points->coords[0] = 0.0; - points->coords[1] = 0.0; - - points->coords[2] = 8.0; - points->coords[3] = 0.0; - - points->coords[4] = 4.0; - points->coords[5] = 4.0; - - points->coords[6] = 4.0; - points->coords[7] = 11.0; - - points->coords[8] = 0.0; - points->coords[9] = 11.0; - - points->coords[10] = 0.0; - points->coords[11] = 0.0; - shift = 0; - label_offset = 10.0; + label_offset = 13.0; break; case PunchOut: - points = gnome_canvas_points_new (6); - - points->coords[0] = 0.0; - points->coords[1] = 0.0; - - points->coords[2] = 8.0; - points->coords[3] = 0.0; - - points->coords[4] = 8.0; - points->coords[5] = 11.0; - - points->coords[6] = 4.0; - points->coords[7] = 11.0; - - points->coords[8] = 4.0; - points->coords[9] = 4.0; - - points->coords[10] = 0.0; - points->coords[11] = 0.0; - - shift = 8; - label_offset = 11.0; + points = new ArdourCanvas::Points (); + points->push_back (Gnome::Art::Point (0.0, 0.0)); + points->push_back (Gnome::Art::Point (12.0, 0.0)); + points->push_back (Gnome::Art::Point (12.0, 12.0)); + points->push_back (Gnome::Art::Point (0.0, 0.0)); + + shift = 13; + label_offset = 0.0; + annotate_left = true; break; } @@ -337,57 +234,66 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const unit_position -= shift; - group = gnome_canvas_item_new (parent, - gnome_canvas_group_get_type(), - "x", unit_position, - "y", 1.0, - NULL); - - // cerr << "set mark al points, nc = " << points->num_points << endl; - mark = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_polygon_get_type(), - "points", points, - "fill_color_rgba", rgba, - "outline_color", "black", - NULL); + group = new Group (parent, unit_position, 1.0); + mark = new Polygon (*group); + mark->property_points() = *points; + mark->property_fill_color_rgba() = rgba; + mark->property_outline_color_rgba() = rgba; + mark->property_width_pixels() = 1; Pango::FontDescription font = get_font_for_style (N_("MarkerText")); + + text = new Text (*group); + text->property_text() = annotation.c_str(); + text->property_font_desc() = font; + if (annotate_left) { + text->property_x() = -(text->property_text_width()); + } else { + text->property_x() = label_offset; + } + text->property_y() = 0.0; + text->property_anchor() = Gtk::ANCHOR_NW; + text->property_fill_color() = "black"; + + editor.ZoomChanged.connect (mem_fun (*this, &Marker::reposition)); - text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_text_get_type (), - "text", annotation.c_str(), - "x", label_offset, - "y", 0.0, - "fontdesc", font, - "anchor", GTK_ANCHOR_NW, - "fill_color", "black", - NULL); + mark->set_data ("marker", this); - gtk_object_set_data (GTK_OBJECT(group), "marker", this); - gtk_signal_connect (GTK_OBJECT(group), "event", (GtkSignalFunc) callback, &editor); + if (handle_events) { + group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this)); + } - editor.ZoomChanged.connect (mem_fun(*this, &Marker::reposition)); } Marker::~Marker () { - /* destroying the group destroys its contents */ - gtk_object_destroy (GTK_OBJECT(group)); - gnome_canvas_points_unref (points); + /* destroying the parent group destroys its contents, namely any polygons etc. that we added */ + delete text; + delete mark; + delete points; +} + +ArdourCanvas::Item& +Marker::the_item() const +{ + return *mark; } void Marker::set_name (const string& name) { - gnome_canvas_item_set (text, "text", name.c_str(), NULL); + text->property_text() = name.c_str(); + if (_type == End) { + text->property_x() = -(text->property_text_width()); + } } void -Marker::set_position (jack_nframes_t frame) +Marker::set_position (nframes_t frame) { double new_unit_position = editor.frame_to_unit (frame); new_unit_position -= shift; - gnome_canvas_item_move (group, new_unit_position - unit_position, 0.0); + group->move (new_unit_position - unit_position, 0.0); frame_position = frame; unit_position = new_unit_position; } @@ -401,31 +307,30 @@ Marker::reposition () void Marker::show () { - gnome_canvas_item_show (group); + group->show(); } void Marker::hide () { - gnome_canvas_item_hide (group); + group->hide(); } void Marker::set_color_rgba (uint32_t color) { - gnome_canvas_item_set (mark, "fill_color_rgba", color, NULL); + mark->property_fill_color_rgba() = color; } /***********************************************************************/ -TempoMarker::TempoMarker (PublicEditor& editor, GnomeCanvasGroup *parent, guint32 rgba, const string& text, - ARDOUR::TempoSection& temp, - gint (*callback)(GnomeCanvasItem *, GdkEvent *, gpointer)) - : Marker (editor, parent, rgba, text, Tempo, callback, 0), +TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text, + ARDOUR::TempoSection& temp) + : Marker (editor, parent, rgba, text, Tempo, 0, false), _tempo (temp) { set_position (_tempo.frame()); - gtk_object_set_data (GTK_OBJECT(group), "tempo_marker", this); + group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this)); } TempoMarker::~TempoMarker () @@ -434,16 +339,16 @@ TempoMarker::~TempoMarker () /***********************************************************************/ -MeterMarker::MeterMarker (PublicEditor& editor, GnomeCanvasGroup *parent, guint32 rgba, const string& text, - ARDOUR::MeterSection& m, - gint (*callback)(GnomeCanvasItem *, GdkEvent *, gpointer)) - : Marker (editor, parent, rgba, text, Meter, callback, 0), +MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text, + ARDOUR::MeterSection& m) + : Marker (editor, parent, rgba, text, Meter, 0, false), _meter (m) { set_position (_meter.frame()); - gtk_object_set_data (GTK_OBJECT(group), "meter_marker", this); + group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this)); } MeterMarker::~MeterMarker () { } +