X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_cursors.cc;h=40245778d5b950dfc270f540c7484c79ddf8de06;hb=01251e7e14bba0b4604618ccfad87361e32dac18;hp=f8388a3a3de8b28284e28e422e881fc50564ef11;hpb=e493b2b7c4fbbbfc457f02babf9546289b430177;p=ardour.git diff --git a/gtk2_ardour/editor_cursors.cc b/gtk2_ardour/editor_cursors.cc index f8388a3a3d..40245778d5 100644 --- a/gtk2_ardour/editor_cursors.cc +++ b/gtk2_ardour/editor_cursors.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000 Paul Davis + Copyright (C) 2000 Paul Davis 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 @@ -15,107 +15,99 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include #include -#include +#include "canvas/canvas.h" +#include "canvas/debug.h" +#include "canvas/scroll_group.h" -#include "utils.h" +#include "editor_cursors.h" #include "editor.h" -using namespace sigc; using namespace ARDOUR; +using namespace PBD; using namespace Gtk; -Editor::Cursor::Cursor (Editor& ed, const string& color, GtkSignalFunc callbck) - : editor (ed), callback (callbck), length(1.0) +EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*)) + : _editor (ed) + , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group())) { - GtkCanvasGroup *group; - points = gtk_canvas_points_new (2); - - /* "randomly" initialize coords */ - - points->coords[0] = -9383839.0; - points->coords[1] = 0.0; - points->coords[2] = 1.0; - points->coords[3] = 0.0; - - group = GTK_CANVAS_GROUP (editor.cursor_group); - - // cerr << "set cursor points, nc = " << points->num_points << endl; - canvas_item = gtk_canvas_item_new (group, - gtk_canvas_line_get_type(), - "points", points, - "fill_color", color.c_str(), - "width_pixels", 1, - "first_arrowhead", (gboolean) TRUE, - "last_arrowhead", (gboolean) TRUE, - "arrow_shape_a", 11.0, - "arrow_shape_b", 0.0, - "arrow_shape_c", 9.0, - NULL); - - // cerr << "cursor line @ " << canvas_item << endl; - - gtk_object_set_data (GTK_OBJECT(canvas_item), "cursor", this); - gtk_signal_connect (GTK_OBJECT(canvas_item), "event", callback, &editor); - - current_frame = 1; /* force redraw at 0 */ + CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas editor cursor"); + + _track_canvas_item->set_show_head (0, true); + _track_canvas_item->set_head_height (0, 9); + _track_canvas_item->set_head_width (0, 16); + _track_canvas_item->set_head_outward (0, false); + _track_canvas_item->set_show_head (1, false); // head only + _track_canvas_item->set_data ("cursor", this); + + _track_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), _track_canvas_item)); + + _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX); + + _track_canvas_item->set_x (0); + + _current_frame = 1; /* force redraw at 0 */ } -Editor::Cursor::~Cursor () +EditorCursor::EditorCursor (Editor& ed) + : _editor (ed) + , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group())) +{ + CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas cursor"); + + _track_canvas_item->set_show_head (0, false); + _track_canvas_item->set_show_head (1, false); + _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX); + _track_canvas_item->set_ignore_events (true); + + _track_canvas_item->set_x (0); + + _current_frame = 1; /* force redraw at 0 */ +} +EditorCursor::~EditorCursor () { - gtk_object_destroy (GTK_OBJECT(canvas_item)); - gtk_canvas_points_unref (points); + delete _track_canvas_item; } void -Editor::Cursor::set_position (jack_nframes_t frame) +EditorCursor::set_position (framepos_t frame) { - double new_pos = editor.frame_to_unit (frame); + if (_current_frame != frame) { PositionChanged (frame); } - if (editor.session == 0) { - gtk_canvas_item_hide (canvas_item); - } else { - gtk_canvas_item_show (canvas_item); - } - - current_frame = frame; + double const new_pos = _editor.sample_to_pixel_unrounded (frame); - if (new_pos == points->coords[0]) { + if (rint(new_pos) != rint(_track_canvas_item->x ())) { + _track_canvas_item->set_x (new_pos); + } - /* change in position is not visible, so just raise it */ - - gtk_canvas_item_raise_to_top (canvas_item); - return; - } + _current_frame = frame; +} - points->coords[0] = new_pos; - points->coords[2] = new_pos; +void +EditorCursor::show () +{ + _track_canvas_item->show (); +} - // cerr << "set cursor2 al points, nc = " << points->num_points << endl; - gtk_canvas_item_set (canvas_item, "points", points, NULL); - gtk_canvas_item_raise_to_top (canvas_item); +void +EditorCursor::hide () +{ + _track_canvas_item->hide (); } void -Editor::Cursor::set_length (double units) +EditorCursor::set_color (ArdourCanvas::Color color) { - length = units; - points->coords[3] = points->coords[1] + length; - // cerr << "set cursor3 al points, nc = " << points->num_points << endl; - gtk_canvas_item_set (canvas_item, "points", points, NULL); + _track_canvas_item->set_color (color); } -void -Editor::Cursor::set_y_axis (double position) +void +EditorCursor::set_sensitive (bool yn) { - points->coords[1] = position; - points->coords[3] = position + length; - // cerr << "set cursor4 al points, nc = " << points->num_points << endl; - gtk_canvas_item_set (canvas_item, "points", points, NULL); + _track_canvas_item->set_ignore_events (!yn); }