Vkeybd: use ArdourWidgets for all GUI elements
[ardour.git] / gtk2_ardour / editor_cursors.cc
1 /*
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>
8  *
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.
13  *
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.
18  *
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.
22  */
23
24 #include <cstdlib>
25 #include <cmath>
26
27 #include "canvas/canvas.h"
28 #include "canvas/debug.h"
29 #include "canvas/scroll_group.h"
30
31 #include "editor_cursors.h"
32 #include "editor.h"
33
34 using namespace ARDOUR;
35 using namespace PBD;
36 using namespace Gtk;
37
38 EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
39         : _editor (ed)
40         , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
41 {
42         CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas editor cursor");
43
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);
50
51         _track_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), _track_canvas_item));
52
53         _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
54
55         _track_canvas_item->set_x (0);
56
57         _current_sample = 1; /* force redraw at 0 */
58 }
59
60 EditorCursor::EditorCursor (Editor& ed)
61         : _editor (ed)
62         , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group()))
63 {
64         CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas cursor");
65
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);
70
71         _track_canvas_item->set_x (0);
72
73         _current_sample = 1; /* force redraw at 0 */
74 }
75
76 EditorCursor::~EditorCursor ()
77 {
78         delete _track_canvas_item;
79 }
80
81 void
82 EditorCursor::set_position (samplepos_t sample)
83 {
84         if (_current_sample != sample) { PositionChanged (sample); }
85
86         double const new_pos = _editor.sample_to_pixel_unrounded (sample);
87
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
90         }
91
92         _current_sample = sample;
93 }
94
95 void
96 EditorCursor::show ()
97 {
98         _track_canvas_item->show ();
99 }
100
101 void
102 EditorCursor::hide ()
103 {
104         _track_canvas_item->hide ();
105 }
106
107 void
108 EditorCursor::set_color (Gtkmm2ext::Color color)
109 {
110         _track_canvas_item->set_color (color);
111 }
112
113 void
114 EditorCursor::set_sensitive (bool yn)
115 {
116         _track_canvas_item->set_ignore_events (!yn);
117 }