2 Copyright (C) 2000 Paul Davis
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.
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.
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.
24 #include <libgnomecanvas/libgnomecanvas.h>
30 using namespace ARDOUR;
33 Editor::Cursor::Cursor (Editor& ed, const string& color, bool (Editor::*callbck)(GdkEvent*))
34 : editor (ed), length(1.0)
37 /* "randomly" initialize coords */
39 points->push_back(Gnome::Art::Point(-9383839.0, 0.0));
40 points->push_back(Gnome::Art::Point(1.0, 0.0));
41 Gnome::Canvas::Group *group = editor.cursor_group;
43 // cerr << "set cursor points, nc = " << points->num_points << endl;
45 canvas_item = new Gnome::Canvas::Line (*group, *points);
46 canvas_item->set_property ("fill_color", color.c_str());
47 canvas_item->set_property ("width_pixels", 1);
48 canvas_item->set_property ("first_arrowhead", (gboolean) TRUE);
49 canvas_item->set_property ("last_arrowhead", (gboolean) TRUE);
50 canvas_item->set_property ("arrow_shape_a", 11.0);
51 canvas_item->set_property ("arrow_shape_b", 0.0);
52 canvas_item->set_property ("arrow_shape_c", 9.0);
54 // cerr << "cursor line @ " << canvas_item << endl;
56 canvas_item->set_data ("cursor", this);
57 canvas_item->signal_event().connect (mem_fun (ed, callbck));
59 current_frame = 1; /* force redraw at 0 */
62 Editor::Cursor::~Cursor ()
65 gtk_object_destroy (GTK_OBJECT(canvas_item));
66 gnome_canvas_points_unref (points->gobj());
70 Editor::Cursor::set_position (jack_nframes_t frame)
72 double new_pos = editor.frame_to_unit (frame);
74 if (editor.session == 0) {
80 current_frame = frame;
82 if (new_pos == points->front().get_x()) {
84 /* change in position is not visible, so just raise it */
86 canvas_item->raise_to_top();
90 points->front().set_x(new_pos);
91 points->back().set_x(new_pos);
93 // cerr << "set cursor2 al points, nc = " << points->num_points << endl;
94 canvas_item->set_property ("points", points);
95 canvas_item->raise_to_top();
99 Editor::Cursor::set_length (double units)
102 points->back().set_x (points->front().get_y() + length);
103 // cerr << "set cursor3 al points, nc = " << points->num_points << endl;
104 canvas_item->set_property("points", points);
108 Editor::Cursor::set_y_axis (double position)
110 points->front().set_y (position);
111 points->back().set_x (position + length);
112 // cerr << "set cursor4 al points, nc = " << points->num_points << endl;
113 canvas_item->set_property("points", points);