summaryrefslogtreecommitdiff
path: root/gtk2_ardour/editor_cursors.cc
blob: e951f94424f34a6872092a1558057f3088e1f0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright (C) 2005-2008 Nick Mainsbridge <mainsbridge@gmail.com>
 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
 * Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <cstdlib>
#include <cmath>

#include "canvas/canvas.h"
#include "canvas/debug.h"
#include "canvas/scroll_group.h"

#include "editor_cursors.h"
#include "editor.h"

using namespace ARDOUR;
using namespace PBD;
using namespace Gtk;

EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
	: _editor (ed)
	, _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
{
	CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas editor cursor");

	_track_canvas_item->set_show_head (0, true);
	_track_canvas_item->set_head_height (0, 9);
	_track_canvas_item->set_head_width (0, 16);
	_track_canvas_item->set_head_outward (0, false);
	_track_canvas_item->set_show_head (1, false); // head only
	_track_canvas_item->set_data ("cursor", this);

	_track_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), _track_canvas_item));

	_track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);

	_track_canvas_item->set_x (0);

	_current_sample = 1; /* force redraw at 0 */
}

EditorCursor::EditorCursor (Editor& ed)
	: _editor (ed)
	, _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group()))
{
	CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas cursor");

	_track_canvas_item->set_show_head (0, false);
	_track_canvas_item->set_show_head (1, false);
	_track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
	_track_canvas_item->set_ignore_events (true);

	_track_canvas_item->set_x (0);

	_current_sample = 1; /* force redraw at 0 */
}

EditorCursor::~EditorCursor ()
{
	delete _track_canvas_item;
}

void
EditorCursor::set_position (samplepos_t sample)
{
	if (_current_sample != sample) { PositionChanged (sample); }

	double const new_pos = _editor.sample_to_pixel_unrounded (sample);

	if (rint(new_pos) != rint(_track_canvas_item->x ())) {
		_track_canvas_item->set_x (new_pos-0.5);  //accommodate the 1/2 pixel "line" offset in cairo
	}

	_current_sample = sample;
}

void
EditorCursor::show ()
{
	_track_canvas_item->show ();
}

void
EditorCursor::hide ()
{
	_track_canvas_item->hide ();
}

void
EditorCursor::set_color (Gtkmm2ext::Color color)
{
	_track_canvas_item->set_color (color);
}

void
EditorCursor::set_sensitive (bool yn)
{
	_track_canvas_item->set_ignore_events (!yn);
}