2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "canvas/canvas.h"
|
2013-04-17 10:53:17 -04:00
|
|
|
#include "canvas/debug.h"
|
2014-06-21 11:44:22 -04:00
|
|
|
#include "canvas/scroll_group.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-16 09:53:16 -05:00
|
|
|
#include "editor_cursors.h"
|
2024-01-26 22:45:22 -05:00
|
|
|
#include "editing_context.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
|
2024-01-26 22:45:22 -05:00
|
|
|
EditorCursor::EditorCursor (EditingContext& ed, bool (EditingContext::*callback)(GdkEvent*,ArdourCanvas::Item*), std::string const & name)
|
2013-04-04 00:32:52 -04:00
|
|
|
: _editor (ed)
|
2024-10-17 23:47:52 -04:00
|
|
|
, _canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
CANVAS_DEBUG_NAME (_canvas_item, string_compose ("track canvas editor cursor <%1>", name));
|
2013-04-17 10:53:17 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_show_head (0, true);
|
|
|
|
_canvas_item->set_head_height (0, 9);
|
|
|
|
_canvas_item->set_head_width (0, 16);
|
|
|
|
_canvas_item->set_head_outward (0, false);
|
|
|
|
_canvas_item->set_show_head (1, false); // head only
|
|
|
|
_canvas_item->set_data ("cursor", this);
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callback), _canvas_item));
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
|
2014-09-15 07:28:13 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_x (0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
_current_sample = 1; /* force redraw at 0 */
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2024-01-26 22:45:22 -05:00
|
|
|
EditorCursor::EditorCursor (EditingContext& ed, std::string const & name)
|
2014-07-07 08:16:57 -04:00
|
|
|
: _editor (ed)
|
2024-10-17 23:47:52 -04:00
|
|
|
, _canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group()))
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
CANVAS_DEBUG_NAME (_canvas_item, string_compose ("track canvas cursor <%1>", name));
|
2014-07-07 08:16:57 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_show_head (0, false);
|
|
|
|
_canvas_item->set_show_head (1, false);
|
|
|
|
_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
|
|
|
|
_canvas_item->set_ignore_events (true);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_x (0);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
_current_sample = 1; /* force redraw at 0 */
|
2014-07-07 08:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorCursor::~EditorCursor ()
|
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
delete _canvas_item;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-18 12:39:17 -04:00
|
|
|
EditorCursor::set_position (samplepos_t sample)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2023-09-15 11:59:59 -04:00
|
|
|
if (_current_sample != sample) {
|
|
|
|
PositionChanged (sample);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2023-09-15 11:59:59 -04:00
|
|
|
const double new_pos = _editor.sample_to_pixel (sample);
|
2005-11-30 14:34:09 -05:00
|
|
|
|
2024-10-17 23:47:52 -04:00
|
|
|
if (new_pos != _canvas_item->x ()) {
|
|
|
|
_canvas_item->set_x (new_pos);
|
2005-11-30 14:34:09 -05:00
|
|
|
}
|
2014-02-12 15:13:11 -05:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
_current_sample = sample;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EditorCursor::show ()
|
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->show ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-04 00:32:52 -04:00
|
|
|
EditorCursor::hide ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->hide ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2017-07-17 12:34:35 -04:00
|
|
|
EditorCursor::set_color (Gtkmm2ext::Color color)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_color (color);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2014-06-30 16:32:38 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
EditorCursor::set_sensitive (bool yn)
|
|
|
|
{
|
2024-10-17 23:47:52 -04:00
|
|
|
_canvas_item->set_ignore_events (!yn);
|
2014-06-30 16:32:38 -04:00
|
|
|
}
|