2 * Copyright (C) 2005-2008 Nick Mainsbridge <mainsbridge@gmail.com>
3 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6 * Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
7 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "canvas/canvas.h"
28 #include "canvas/debug.h"
29 #include "canvas/scroll_group.h"
31 #include "editor_cursors.h"
34 using namespace ARDOUR;
38 EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
40 , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
42 CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas editor cursor");
44 _track_canvas_item->set_show_head (0, true);
45 _track_canvas_item->set_head_height (0, 9);
46 _track_canvas_item->set_head_width (0, 16);
47 _track_canvas_item->set_head_outward (0, false);
48 _track_canvas_item->set_show_head (1, false); // head only
49 _track_canvas_item->set_data ("cursor", this);
51 _track_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), _track_canvas_item));
53 _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
55 _track_canvas_item->set_x (0);
57 _current_sample = 1; /* force redraw at 0 */
60 EditorCursor::EditorCursor (Editor& ed)
62 , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group()))
64 CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas cursor");
66 _track_canvas_item->set_show_head (0, false);
67 _track_canvas_item->set_show_head (1, false);
68 _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
69 _track_canvas_item->set_ignore_events (true);
71 _track_canvas_item->set_x (0);
73 _current_sample = 1; /* force redraw at 0 */
76 EditorCursor::~EditorCursor ()
78 delete _track_canvas_item;
82 EditorCursor::set_position (samplepos_t sample)
84 if (_current_sample != sample) { PositionChanged (sample); }
86 double const new_pos = _editor.sample_to_pixel_unrounded (sample);
88 if (rint(new_pos) != rint(_track_canvas_item->x ())) {
89 _track_canvas_item->set_x (new_pos-0.5); //accommodate the 1/2 pixel "line" offset in cairo
92 _current_sample = sample;
98 _track_canvas_item->show ();
102 EditorCursor::hide ()
104 _track_canvas_item->hide ();
108 EditorCursor::set_color (Gtkmm2ext::Color color)
110 _track_canvas_item->set_color (color);
114 EditorCursor::set_sensitive (bool yn)
116 _track_canvas_item->set_ignore_events (!yn);