fix merge with master
[ardour.git] / gtk2_ardour / editor_cursors.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cstdlib>
21 #include <cmath>
22
23 #include "canvas/canvas.h"
24 #include "canvas/debug.h"
25
26 #include "utils.h"
27 #include "editor_cursors.h"
28 #include "editor.h"
29
30 using namespace ARDOUR;
31 using namespace PBD;
32 using namespace Gtk;
33
34 EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
35         : _editor (ed)
36         , _time_bars_canvas_item (_editor._time_bars_canvas->root ())
37         , _track_canvas_item (_editor._track_canvas->root ())
38         , _length (1.0)
39 {
40         CANVAS_DEBUG_NAME ((&_time_bars_canvas_item), "timebars editor cursor");
41         CANVAS_DEBUG_NAME ((&_track_canvas_item), "track canvas editor cursor");
42
43         _time_bars_canvas_item.set_show_head (0, true);
44         _time_bars_canvas_item.set_head_height (0, 9);
45         _time_bars_canvas_item.set_head_width (0, 16);
46         _time_bars_canvas_item.set_head_outward (0, false);
47         _time_bars_canvas_item.set_show_head (1, false); // head only
48         _time_bars_canvas_item.set_outline_width (0.5);
49
50         _time_bars_canvas_item.set_data ("cursor", this);
51         _track_canvas_item.set_data ("cursor", this);
52         _track_canvas_item.set_outline_width (0.5);
53
54         _time_bars_canvas_item.Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), &_time_bars_canvas_item));
55         _track_canvas_item.Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), &_track_canvas_item));
56
57         _time_bars_canvas_item.set_y1 (ArdourCanvas::COORD_MAX);
58         _track_canvas_item.set_y1 (ArdourCanvas::COORD_MAX);
59         
60         _current_frame = 1; /* force redraw at 0 */
61 }
62
63 EditorCursor::~EditorCursor ()
64 {
65         
66 }
67
68 void
69 EditorCursor::set_position (framepos_t frame)
70 {
71         PositionChanged (frame);
72
73         /* See Cairo FAQ question on single pixel lines to understand
74            why we add 0.5
75         */
76
77         double const new_pos = _editor.sample_to_pixel (frame) + 0.5;
78
79         if (new_pos != _time_bars_canvas_item.x ()) {
80                 _time_bars_canvas_item.set_x (new_pos);
81         }
82
83         if (new_pos != _track_canvas_item.x0 ()) {
84                 _track_canvas_item.set_x (new_pos, new_pos);
85         }
86         
87         _current_frame = frame;
88 }
89
90 void
91 EditorCursor::show ()
92 {
93         _time_bars_canvas_item.show ();
94         _track_canvas_item.show ();
95 }
96
97 void
98 EditorCursor::hide ()
99 {
100         _time_bars_canvas_item.hide ();
101         _track_canvas_item.hide ();
102 }
103
104 void
105 EditorCursor::set_color (ArdourCanvas::Color color)
106 {
107         _time_bars_canvas_item.set_color (color);
108         _track_canvas_item.set_outline_color (color);
109 }