2013-04-15 22:10:18 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011-2013 Paul Davis
|
|
|
|
Author: Carl Hetherington <cth@carlh.net>
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "pbd/stacktrace.h"
|
|
|
|
#include "pbd/convert.h"
|
|
|
|
|
|
|
|
#include "ardour/utils.h"
|
|
|
|
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/debug.h"
|
2014-05-21 19:14:40 -04:00
|
|
|
#include "canvas/group.h"
|
|
|
|
#include "canvas/item.h"
|
|
|
|
#include "canvas/scroll_group.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
|
|
|
Item::Item (Canvas* canvas)
|
|
|
|
: _canvas (canvas)
|
|
|
|
, _parent (0)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Item::Item (Group* parent)
|
2013-04-09 14:22:58 -04:00
|
|
|
: _canvas (parent->canvas ())
|
|
|
|
, _parent (parent)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Item::Item (Group* parent, Duple position)
|
2013-04-09 14:22:58 -04:00
|
|
|
: _canvas (parent->canvas())
|
|
|
|
, _parent (parent)
|
2013-04-04 00:32:52 -04:00
|
|
|
, _position (position)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::init ()
|
|
|
|
{
|
|
|
|
_visible = true;
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
_ignore_events = false;
|
|
|
|
|
|
|
|
if (_parent) {
|
|
|
|
_parent->add (this);
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:05:18 -04:00
|
|
|
find_scroll_parent ();
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
Item::~Item ()
|
|
|
|
{
|
|
|
|
if (_parent) {
|
|
|
|
_parent->remove (this);
|
|
|
|
}
|
2013-04-24 18:31:00 -04:00
|
|
|
|
|
|
|
if (_canvas) {
|
|
|
|
_canvas->item_going_away (this, _bounding_box);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2014-06-08 11:23:36 -04:00
|
|
|
Duple
|
|
|
|
Item::canvas_origin () const
|
|
|
|
{
|
|
|
|
return item_to_canvas (Duple (0,0));
|
|
|
|
}
|
|
|
|
|
2014-06-03 15:57:56 -04:00
|
|
|
Duple
|
|
|
|
Item::window_origin () const
|
|
|
|
{
|
|
|
|
/* This is slightly subtle. Our _position is in the coordinate space of
|
|
|
|
our parent. So to find out where that is in window coordinates, we
|
|
|
|
have to ask our parent.
|
|
|
|
*/
|
|
|
|
if (_parent) {
|
|
|
|
return _parent->item_to_window (_position);
|
|
|
|
} else {
|
|
|
|
return _parent->item_to_window (Duple (0,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 21:46:44 -04:00
|
|
|
ArdourCanvas::Rect
|
|
|
|
Item::item_to_parent (ArdourCanvas::Rect const & r) const
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
|
|
|
return r.translate (_position);
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
Duple
|
|
|
|
Item::scroll_offset () const
|
2013-04-15 10:38:12 -04:00
|
|
|
{
|
2014-05-22 23:05:18 -04:00
|
|
|
if (_scroll_parent) {
|
|
|
|
return _scroll_parent->scroll_offset();
|
|
|
|
}
|
|
|
|
return _canvas->scroll_offset();
|
2013-04-15 10:38:12 -04:00
|
|
|
}
|
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
Duple
|
|
|
|
Item::position_offset() const
|
2013-04-15 10:38:12 -04:00
|
|
|
{
|
|
|
|
Item const * i = this;
|
|
|
|
Duple offset;
|
|
|
|
|
|
|
|
while (i) {
|
2014-05-22 23:05:18 -04:00
|
|
|
offset = offset.translate (i->position());
|
2013-04-15 10:38:12 -04:00
|
|
|
i = i->parent();
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
return offset;
|
2013-04-15 10:38:12 -04:00
|
|
|
}
|
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
ArdourCanvas::Rect
|
|
|
|
Item::item_to_canvas (ArdourCanvas::Rect const & r) const
|
2013-04-15 10:38:12 -04:00
|
|
|
{
|
2014-05-21 19:14:40 -04:00
|
|
|
return r.translate (position_offset());
|
|
|
|
}
|
2013-04-15 10:38:12 -04:00
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
ArdourCanvas::Duple
|
|
|
|
Item::item_to_canvas (ArdourCanvas::Duple const & d) const
|
|
|
|
{
|
|
|
|
return d.translate (position_offset());
|
|
|
|
}
|
2013-04-15 10:38:12 -04:00
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
ArdourCanvas::Duple
|
|
|
|
Item::canvas_to_item (ArdourCanvas::Duple const & r) const
|
|
|
|
{
|
|
|
|
return r.translate (-position_offset());
|
2013-04-15 10:38:12 -04:00
|
|
|
}
|
|
|
|
|
2013-06-18 08:23:06 -04:00
|
|
|
ArdourCanvas::Rect
|
2014-05-21 19:14:40 -04:00
|
|
|
Item::canvas_to_item (ArdourCanvas::Rect const & r) const
|
2013-06-18 08:23:06 -04:00
|
|
|
{
|
2014-05-21 19:14:40 -04:00
|
|
|
return r.translate (-position_offset());
|
2013-06-18 08:23:06 -04:00
|
|
|
}
|
|
|
|
|
2013-04-15 10:38:12 -04:00
|
|
|
void
|
|
|
|
Item::item_to_canvas (Coord& x, Coord& y) const
|
|
|
|
{
|
|
|
|
Duple d = item_to_canvas (Duple (x, y));
|
|
|
|
|
|
|
|
x = d.x;
|
|
|
|
y = d.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::canvas_to_item (Coord& x, Coord& y) const
|
|
|
|
{
|
|
|
|
Duple d = canvas_to_item (Duple (x, y));
|
|
|
|
|
|
|
|
x = d.x;
|
|
|
|
y = d.y;
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:14:40 -04:00
|
|
|
|
2013-06-18 08:23:06 -04:00
|
|
|
Duple
|
2014-05-29 21:04:02 -04:00
|
|
|
Item::item_to_window (ArdourCanvas::Duple const & d, bool rounded) const
|
2013-06-18 08:23:06 -04:00
|
|
|
{
|
2014-05-22 23:05:18 -04:00
|
|
|
Duple ret = item_to_canvas (d).translate (-scroll_offset());
|
|
|
|
|
2014-06-03 16:37:53 -04:00
|
|
|
if (rounded) {
|
|
|
|
ret.x = round (ret.x);
|
|
|
|
ret.y = round (ret.y);
|
|
|
|
}
|
2014-05-22 23:05:18 -04:00
|
|
|
|
|
|
|
return ret;
|
2013-06-18 08:23:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Duple
|
|
|
|
Item::window_to_item (ArdourCanvas::Duple const & d) const
|
|
|
|
{
|
2014-05-21 19:14:40 -04:00
|
|
|
return canvas_to_item (d.translate (scroll_offset()));
|
2013-06-18 08:23:06 -04:00
|
|
|
}
|
|
|
|
|
2013-07-01 12:04:02 -04:00
|
|
|
ArdourCanvas::Rect
|
2013-06-18 08:23:06 -04:00
|
|
|
Item::item_to_window (ArdourCanvas::Rect const & r) const
|
|
|
|
{
|
2014-05-22 23:05:18 -04:00
|
|
|
Rect ret = item_to_canvas (r).translate (-scroll_offset());
|
|
|
|
|
|
|
|
ret.x0 = round (ret.x0);
|
|
|
|
ret.x1 = round (ret.x1);
|
|
|
|
ret.y0 = round (ret.y0);
|
|
|
|
ret.y1 = round (ret.y1);
|
|
|
|
|
|
|
|
return ret;
|
2014-05-18 12:22:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Rect
|
|
|
|
Item::window_to_item (ArdourCanvas::Rect const & r) const
|
|
|
|
{
|
2014-05-21 19:14:40 -04:00
|
|
|
return canvas_to_item (r.translate (scroll_offset()));
|
2013-06-18 08:23:06 -04:00
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
/** Set the position of this item in the parent's coordinates */
|
|
|
|
void
|
|
|
|
Item::set_position (Duple p)
|
|
|
|
{
|
2014-02-13 18:15:19 -05:00
|
|
|
if (p == _position) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-12 21:46:44 -04:00
|
|
|
boost::optional<ArdourCanvas::Rect> bbox = bounding_box ();
|
|
|
|
boost::optional<ArdourCanvas::Rect> pre_change_parent_bounding_box;
|
2013-04-11 20:19:22 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
if (bbox) {
|
2013-04-15 10:38:12 -04:00
|
|
|
/* see the comment in Canvas::item_moved() to understand
|
|
|
|
* why we use the parent's bounding box here.
|
|
|
|
*/
|
2013-04-04 00:32:52 -04:00
|
|
|
pre_change_parent_bounding_box = item_to_parent (bbox.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
_position = p;
|
|
|
|
|
|
|
|
_canvas->item_moved (this, pre_change_parent_bounding_box);
|
|
|
|
|
|
|
|
if (_parent) {
|
|
|
|
_parent->child_changed ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_x_position (Coord x)
|
|
|
|
{
|
|
|
|
set_position (Duple (x, _position.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_y_position (Coord y)
|
|
|
|
{
|
|
|
|
set_position (Duple (_position.x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::raise_to_top ()
|
|
|
|
{
|
|
|
|
assert (_parent);
|
|
|
|
_parent->raise_child_to_top (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::raise (int levels)
|
|
|
|
{
|
|
|
|
assert (_parent);
|
|
|
|
_parent->raise_child (this, levels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::lower_to_bottom ()
|
|
|
|
{
|
|
|
|
assert (_parent);
|
|
|
|
_parent->lower_child_to_bottom (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::hide ()
|
|
|
|
{
|
2014-03-04 10:04:21 -05:00
|
|
|
if (_visible) {
|
|
|
|
_visible = false;
|
|
|
|
_canvas->item_shown_or_hidden (this);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::show ()
|
|
|
|
{
|
2014-03-04 10:04:21 -05:00
|
|
|
if (!_visible) {
|
|
|
|
_visible = true;
|
|
|
|
_canvas->item_shown_or_hidden (this);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Duple
|
|
|
|
Item::item_to_parent (Duple const & d) const
|
|
|
|
{
|
|
|
|
return d.translate (_position);
|
|
|
|
}
|
|
|
|
|
|
|
|
Duple
|
|
|
|
Item::parent_to_item (Duple const & d) const
|
|
|
|
{
|
|
|
|
return d.translate (- _position);
|
|
|
|
}
|
|
|
|
|
2013-04-12 21:46:44 -04:00
|
|
|
ArdourCanvas::Rect
|
|
|
|
Item::parent_to_item (ArdourCanvas::Rect const & d) const
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
|
|
|
return d.translate (- _position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::unparent ()
|
|
|
|
{
|
|
|
|
_parent = 0;
|
2014-05-22 23:05:18 -04:00
|
|
|
_scroll_parent = 0;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::reparent (Group* new_parent)
|
|
|
|
{
|
2013-04-21 18:57:55 -04:00
|
|
|
assert (_canvas == _parent->canvas());
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
if (_parent) {
|
|
|
|
_parent->remove (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (new_parent);
|
|
|
|
|
|
|
|
_parent = new_parent;
|
2013-04-21 13:10:42 -04:00
|
|
|
_canvas = _parent->canvas ();
|
2014-05-22 23:05:18 -04:00
|
|
|
|
|
|
|
find_scroll_parent ();
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
_parent->add (this);
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:05:18 -04:00
|
|
|
void
|
|
|
|
Item::find_scroll_parent ()
|
|
|
|
{
|
|
|
|
Item const * i = this;
|
|
|
|
ScrollGroup const * last_scroll_group = 0;
|
|
|
|
|
2014-05-23 22:05:08 -04:00
|
|
|
/* Don't allow a scroll group to find itself as its own scroll parent
|
|
|
|
*/
|
|
|
|
|
|
|
|
i = i->parent ();
|
|
|
|
|
2014-05-22 23:05:18 -04:00
|
|
|
while (i) {
|
|
|
|
ScrollGroup const * sg = dynamic_cast<ScrollGroup const *> (i);
|
|
|
|
if (sg) {
|
|
|
|
last_scroll_group = sg;
|
|
|
|
}
|
|
|
|
i = i->parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
_scroll_parent = const_cast<ScrollGroup*> (last_scroll_group);
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:36:30 -04:00
|
|
|
bool
|
|
|
|
Item::common_ancestor_within (uint32_t limit, const Item& other) const
|
|
|
|
{
|
|
|
|
uint32_t d1 = depth();
|
|
|
|
uint32_t d2 = other.depth();
|
|
|
|
const Item* i1 = this;
|
|
|
|
const Item* i2 = &other;
|
|
|
|
|
|
|
|
/* move towards root until we are at the same level
|
|
|
|
for both items
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (d1 != d2) {
|
|
|
|
if (d1 > d2) {
|
|
|
|
i1 = i1->parent();
|
|
|
|
d1--;
|
|
|
|
limit--;
|
|
|
|
} else {
|
|
|
|
i2 = i2->parent();
|
|
|
|
d2--;
|
|
|
|
limit--;
|
|
|
|
}
|
|
|
|
if (limit == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now see if there is a common parent */
|
|
|
|
|
|
|
|
while (i1 != i2) {
|
|
|
|
if (i1) {
|
|
|
|
i1 = i1->parent();
|
|
|
|
}
|
|
|
|
if (i2) {
|
|
|
|
i2 = i2->parent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
limit--;
|
|
|
|
if (limit == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item*
|
|
|
|
Item::closest_ancestor_with (const Item& other) const
|
|
|
|
{
|
|
|
|
uint32_t d1 = depth();
|
|
|
|
uint32_t d2 = other.depth();
|
|
|
|
const Item* i1 = this;
|
|
|
|
const Item* i2 = &other;
|
|
|
|
|
|
|
|
/* move towards root until we are at the same level
|
|
|
|
for both items
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (d1 != d2) {
|
|
|
|
if (d1 > d2) {
|
|
|
|
i1 = i1->parent();
|
|
|
|
d1--;
|
|
|
|
} else {
|
|
|
|
i2 = i2->parent();
|
|
|
|
d2--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now see if there is a common parent */
|
|
|
|
|
|
|
|
while (i1 != i2) {
|
|
|
|
if (i1) {
|
|
|
|
i1 = i1->parent();
|
|
|
|
}
|
|
|
|
if (i2) {
|
|
|
|
i2 = i2->parent ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Item::is_descendant_of (const Item& candidate) const
|
|
|
|
{
|
|
|
|
Item const * i = _parent;
|
|
|
|
|
|
|
|
while (i) {
|
|
|
|
if (i == &candidate) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
i = i->parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
|
|
|
Item::grab_focus ()
|
|
|
|
{
|
|
|
|
/* XXX */
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return Bounding box in this item's coordinates */
|
2013-04-12 21:46:44 -04:00
|
|
|
boost::optional<ArdourCanvas::Rect>
|
2013-04-04 00:32:52 -04:00
|
|
|
Item::bounding_box () const
|
|
|
|
{
|
|
|
|
if (_bounding_box_dirty) {
|
|
|
|
compute_bounding_box ();
|
2014-03-07 11:23:22 -05:00
|
|
|
assert (!_bounding_box_dirty);
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return _bounding_box;
|
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
Coord
|
|
|
|
Item::height () const
|
|
|
|
{
|
2013-04-12 21:46:44 -04:00
|
|
|
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
if (bb) {
|
|
|
|
return bb->height ();
|
|
|
|
}
|
|
|
|
return 0;
|
2013-04-04 18:45:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Item::width () const
|
|
|
|
{
|
2013-04-12 21:46:44 -04:00
|
|
|
boost::optional<ArdourCanvas::Rect> bb = bounding_box().get();
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
if (bb) {
|
|
|
|
return bb->width ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-04-04 18:45:27 -04:00
|
|
|
}
|
|
|
|
|
2013-10-24 17:54:54 -04:00
|
|
|
void
|
|
|
|
Item::redraw () const
|
|
|
|
{
|
2013-10-25 13:29:23 -04:00
|
|
|
if (_visible && _bounding_box && _canvas) {
|
2014-05-22 23:05:18 -04:00
|
|
|
_canvas->request_redraw (item_to_window (_bounding_box.get()));
|
2013-10-24 17:54:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
|
|
|
Item::begin_change ()
|
|
|
|
{
|
|
|
|
_pre_change_bounding_box = bounding_box ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::end_change ()
|
|
|
|
{
|
|
|
|
_canvas->item_changed (this, _pre_change_bounding_box);
|
|
|
|
|
|
|
|
if (_parent) {
|
|
|
|
_parent->child_changed ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 20:38:10 -04:00
|
|
|
void
|
|
|
|
Item::begin_visual_change ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::end_visual_change ()
|
|
|
|
{
|
|
|
|
_canvas->item_visual_property_changed (this);
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
|
|
|
Item::move (Duple movement)
|
|
|
|
{
|
|
|
|
set_position (position() + movement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::grab ()
|
|
|
|
{
|
|
|
|
assert (_canvas);
|
|
|
|
_canvas->grab (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::ungrab ()
|
|
|
|
{
|
|
|
|
assert (_canvas);
|
|
|
|
_canvas->ungrab ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_data (string const & key, void* data)
|
|
|
|
{
|
|
|
|
_data[key] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
Item::get_data (string const & key) const
|
|
|
|
{
|
|
|
|
map<string, void*>::const_iterator i = _data.find (key);
|
|
|
|
if (i == _data.end ()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_ignore_events (bool ignore)
|
|
|
|
{
|
|
|
|
_ignore_events = ignore;
|
|
|
|
}
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Item::dump (ostream& o) const
|
|
|
|
{
|
2013-04-12 21:46:44 -04:00
|
|
|
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
|
2013-04-05 11:27:26 -04:00
|
|
|
|
2013-04-17 10:53:17 -04:00
|
|
|
o << _canvas->indent() << whatami() << ' ' << this << " Visible ? " << _visible;
|
2014-05-20 23:08:15 -04:00
|
|
|
o << " @ " << position();
|
2013-04-08 19:48:09 -04:00
|
|
|
|
|
|
|
#ifdef CANVAS_DEBUG
|
|
|
|
if (!name.empty()) {
|
|
|
|
o << ' ' << name;
|
|
|
|
}
|
|
|
|
#endif
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
if (bb) {
|
|
|
|
o << endl << _canvas->indent() << "\tbbox: " << bb.get();
|
2013-04-15 10:38:12 -04:00
|
|
|
o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb.get());
|
2013-04-05 11:27:26 -04:00
|
|
|
} else {
|
2013-04-08 19:48:09 -04:00
|
|
|
o << " bbox unset";
|
2013-04-05 11:27:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
o << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
Item::whatami () const
|
|
|
|
{
|
|
|
|
std::string type = demangle (typeid (*this).name());
|
|
|
|
return type.substr (type.find_last_of (':') + 1);
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:36:30 -04:00
|
|
|
uint32_t
|
|
|
|
Item::depth () const
|
|
|
|
{
|
|
|
|
Item* i = _parent;
|
|
|
|
int d = 0;
|
|
|
|
while (i) {
|
|
|
|
++d;
|
|
|
|
i = i->parent();
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2013-11-04 11:56:10 -05:00
|
|
|
bool
|
|
|
|
Item::covers (Duple const & point) const
|
|
|
|
{
|
2014-05-23 22:05:08 -04:00
|
|
|
Duple p = window_to_item (point);
|
2013-11-04 11:56:10 -05:00
|
|
|
|
|
|
|
if (_bounding_box_dirty) {
|
|
|
|
compute_bounding_box ();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<Rect> r = bounding_box();
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.get().contains (p);
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:27:26 -04:00
|
|
|
ostream&
|
|
|
|
ArdourCanvas::operator<< (ostream& o, const Item& i)
|
|
|
|
{
|
|
|
|
i.dump (o);
|
|
|
|
return o;
|
|
|
|
}
|
2013-10-30 23:36:30 -04:00
|
|
|
|