r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23
24 #include <libgnomecanvas/libgnomecanvas.h>
25
26 #include "utils.h"
27 #include "editor.h"
28
29 using namespace sigc;
30 using namespace ARDOUR;
31 using namespace PBD;
32 using namespace Gtk;
33
34 Editor::Cursor::Cursor (Editor& ed, const string& color, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
35         : editor (ed),
36           canvas_item (*editor.cursor_group),
37           length(1.0)
38 {
39         
40         /* "randomly" initialize coords */
41         
42         points.push_back(Gnome::Art::Point(-9383839.0, 0.0));
43         points.push_back(Gnome::Art::Point(1.0, 0.0));
44
45         canvas_item.property_points() = points;
46         canvas_item.property_fill_color() = color; //.c_str());
47         canvas_item.property_width_pixels() = 1;
48         canvas_item.property_first_arrowhead() = TRUE;
49         canvas_item.property_last_arrowhead() = TRUE;
50         canvas_item.property_arrow_shape_a() = 11.0;
51         canvas_item.property_arrow_shape_b() = 0.0;
52         canvas_item.property_arrow_shape_c() = 9.0;
53
54         canvas_item.set_data ("cursor", this);
55         canvas_item.signal_event().connect (bind (mem_fun (ed, callbck), &canvas_item));
56
57         current_frame = 1; /* force redraw at 0 */
58 }
59
60 Editor::Cursor::~Cursor ()
61
62 {
63 }
64
65 void
66 Editor::Cursor::set_position (jack_nframes_t frame)
67 {
68         double new_pos =  editor.frame_to_unit (frame);
69
70         if (editor.session == 0) {
71                 canvas_item.hide();
72         } else {
73                 canvas_item.show();
74         }
75
76         current_frame = frame;
77
78         if (new_pos != points.front().get_x()) {
79
80                 points.front().set_x (new_pos);
81                 points.back().set_x (new_pos);
82
83                 canvas_item.property_points() = points;
84
85                 ArdourCanvas::Points p = canvas_item.property_points();
86         }
87
88         canvas_item.raise_to_top();
89 }
90
91 void
92 Editor::Cursor::set_length (double units)
93 {
94         length = units; 
95         points.back().set_y (points.front().get_y() + length);
96         canvas_item.property_points() = points;
97 }
98
99 void 
100 Editor::Cursor::set_y_axis (double position)
101 {
102         points.front().set_y (position);
103         points.back().set_y (position + length);
104         canvas_item.property_points() = points;
105 }