2013-04-15 22:10:18 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015-2017 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-04-15 22:10:18 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "pbd/compose.h"
|
2015-10-29 07:58:51 -04:00
|
|
|
#include "pbd/demangle.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "pbd/convert.h"
|
|
|
|
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/debug.h"
|
2014-05-21 19:14:40 -04:00
|
|
|
#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;
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
int Item::default_items_per_cell = 64;
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
Item::Item (Canvas* canvas)
|
2014-06-12 14:53:44 -04:00
|
|
|
: Fill (*this)
|
|
|
|
, Outline (*this)
|
|
|
|
, _canvas (canvas)
|
2013-04-04 00:32:52 -04:00
|
|
|
, _parent (0)
|
2014-06-14 20:31:47 -04:00
|
|
|
, _scroll_parent (0)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _visible (true)
|
|
|
|
, _bounding_box_dirty (true)
|
2021-07-29 14:19:08 -04:00
|
|
|
, _pack_options (PackOptions (0))
|
2020-06-10 17:52:41 -04:00
|
|
|
, _layout_sensitive (false)
|
2014-06-21 11:43:42 -04:00
|
|
|
, _lut (0)
|
2018-11-19 11:31:09 -05:00
|
|
|
, _resize_queued (false)
|
2021-08-01 23:18:35 -04:00
|
|
|
, _requested_width (-1)
|
|
|
|
, _requested_height (-1)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _ignore_events (false)
|
2022-01-20 11:45:47 -05:00
|
|
|
, _scroll_translation (true)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this));
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
Item::Item (Item* parent)
|
2014-06-12 14:53:44 -04:00
|
|
|
: Fill (*this)
|
|
|
|
, Outline (*this)
|
|
|
|
, _canvas (parent->canvas())
|
2013-04-09 14:22:58 -04:00
|
|
|
, _parent (parent)
|
2014-06-15 12:17:03 -04:00
|
|
|
, _scroll_parent (0)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _visible (true)
|
|
|
|
, _bounding_box_dirty (true)
|
2021-07-29 14:19:08 -04:00
|
|
|
, _pack_options (PackOptions (0))
|
2020-06-10 17:52:41 -04:00
|
|
|
, _layout_sensitive (false)
|
2014-06-21 11:43:42 -04:00
|
|
|
, _lut (0)
|
2018-11-19 11:31:09 -05:00
|
|
|
, _resize_queued (false)
|
2021-08-01 23:18:35 -04:00
|
|
|
, _requested_width (-1)
|
|
|
|
, _requested_height (-1)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _ignore_events (false)
|
2022-01-20 11:45:47 -05:00
|
|
|
, _scroll_translation (true)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this));
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
_parent->add (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
find_scroll_parent ();
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
Item::Item (Item* parent, Duple const& p)
|
2014-06-12 14:53:44 -04:00
|
|
|
: Fill (*this)
|
|
|
|
, Outline (*this)
|
|
|
|
, _canvas (parent->canvas())
|
2013-04-09 14:22:58 -04:00
|
|
|
, _parent (parent)
|
2014-06-15 12:17:03 -04:00
|
|
|
, _scroll_parent (0)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _position (p)
|
|
|
|
, _visible (true)
|
|
|
|
, _bounding_box_dirty (true)
|
2021-07-29 14:19:08 -04:00
|
|
|
, _pack_options (PackOptions (0))
|
2021-07-27 14:25:24 -04:00
|
|
|
, _layout_sensitive (false)
|
2021-08-01 23:18:35 -04:00
|
|
|
, _requested_width (-1.)
|
|
|
|
, _requested_height(-1.)
|
2014-06-21 11:43:42 -04:00
|
|
|
, _lut (0)
|
2018-11-19 11:31:09 -05:00
|
|
|
, _resize_queued (false)
|
2014-06-12 14:53:44 -04:00
|
|
|
, _ignore_events (false)
|
2022-01-27 16:01:23 -05:00
|
|
|
, _scroll_translation (true)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this));
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2014-06-12 14:53:44 -04:00
|
|
|
if (parent) {
|
2013-04-04 00:32:52 -04:00
|
|
|
_parent->add (this);
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:05:18 -04:00
|
|
|
find_scroll_parent ();
|
|
|
|
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
Item::~Item ()
|
|
|
|
{
|
|
|
|
if (_parent) {
|
|
|
|
_parent->remove (this);
|
|
|
|
}
|
2013-04-24 18:31:00 -04:00
|
|
|
|
|
|
|
if (_canvas) {
|
|
|
|
_canvas->item_going_away (this, _bounding_box);
|
|
|
|
}
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
clear_items (true);
|
|
|
|
delete _lut;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
bool
|
|
|
|
Item::visible() const
|
|
|
|
{
|
|
|
|
Item const * i = this;
|
|
|
|
|
|
|
|
while (i) {
|
|
|
|
if (!i->self_visible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
i = i->parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
2015-10-04 14:51:05 -04:00
|
|
|
Item::window_origin () const
|
2014-06-03 15:57:56 -04:00
|
|
|
{
|
2015-10-04 14:51:05 -04:00
|
|
|
/* This is slightly subtle. Our _position is in the coordinate space of
|
2014-06-03 15:57:56 -04:00
|
|
|
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 {
|
2014-06-12 14:53:44 -04:00
|
|
|
return _position;
|
2014-06-03 15:57:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2014-06-09 08:39:38 -04:00
|
|
|
return Duple (0,0);
|
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));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-15 10:38:12 -04:00
|
|
|
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
|
2015-02-09 16:40:10 -05:00
|
|
|
Item::item_to_window (ArdourCanvas::Rect const & r, bool rounded) const
|
2013-06-18 08:23:06 -04:00
|
|
|
{
|
2014-05-22 23:05:18 -04:00
|
|
|
Rect ret = item_to_canvas (r).translate (-scroll_offset());
|
|
|
|
|
2015-02-09 16:40:10 -05:00
|
|
|
if (rounded) {
|
|
|
|
ret.x0 = round (ret.x0);
|
|
|
|
ret.x1 = round (ret.x1);
|
|
|
|
ret.y0 = round (ret.y0);
|
|
|
|
ret.y1 = round (ret.y1);
|
|
|
|
}
|
2014-05-22 23:05:18 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
ArdourCanvas::Rect bbox = bounding_box ();
|
|
|
|
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.
|
|
|
|
*/
|
2017-01-19 14:54:24 -05:00
|
|
|
pre_change_parent_bounding_box = item_to_parent (bbox);
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
_position = p;
|
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
/* only update canvas and parent if visible. Otherwise, this
|
|
|
|
will be done when ::show() is called.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
if (visible()) {
|
|
|
|
_canvas->item_moved (this, pre_change_parent_bounding_box);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
if (_parent) {
|
2021-07-27 14:26:26 -04:00
|
|
|
_parent->child_changed (true);
|
2014-12-18 10:30:38 -05:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:31:09 -05:00
|
|
|
void
|
|
|
|
Item::layout()
|
|
|
|
{
|
|
|
|
for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
if ((*i)->resize_queued()) {
|
|
|
|
(*i)->layout ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_resize_queued = false;
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
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 ()
|
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
if (_parent) {
|
|
|
|
_parent->raise_child_to_top (this);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::raise (int levels)
|
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
if (_parent) {
|
|
|
|
_parent->raise_child (this, levels);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::lower_to_bottom ()
|
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
if (_parent) {
|
|
|
|
_parent->lower_child_to_bottom (this);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::hide ()
|
|
|
|
{
|
2014-03-04 10:04:21 -05:00
|
|
|
if (_visible) {
|
|
|
|
_visible = false;
|
2014-06-18 21:02:30 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
/* children are all hidden because we are hidden, no need
|
|
|
|
to propagate change because our bounding box necessarily
|
|
|
|
includes them all already. thus our being hidden results
|
|
|
|
in (a) a redraw of the entire bounding box (b) no children
|
|
|
|
will be drawn.
|
2014-06-18 21:02:30 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
BUT ... current item in canvas might be one of our children,
|
|
|
|
which is now hidden. So propagate away.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
|
|
|
|
if ((*i)->self_visible()) {
|
|
|
|
/* item was visible but is now hidden because
|
|
|
|
we (its parent) are hidden
|
|
|
|
*/
|
|
|
|
(*i)->propagate_show_hide ();
|
|
|
|
}
|
2014-06-18 21:02:30 -04:00
|
|
|
}
|
|
|
|
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
propagate_show_hide ();
|
2014-03-04 10:04:21 -05:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::show ()
|
|
|
|
{
|
2014-03-04 10:04:21 -05:00
|
|
|
if (!_visible) {
|
2014-06-18 21:02:30 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
_visible = true;
|
2014-06-18 21:02:30 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
if ((*i)->self_visible()) {
|
|
|
|
/* item used to be hidden by us (its parent),
|
|
|
|
but is now visible
|
|
|
|
*/
|
|
|
|
(*i)->propagate_show_hide ();
|
|
|
|
}
|
2014-06-18 21:02:30 -04:00
|
|
|
}
|
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
propagate_show_hide ();
|
2014-03-04 10:04:21 -05:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
void
|
|
|
|
Item::propagate_show_hide ()
|
|
|
|
{
|
|
|
|
/* bounding box may have changed while we were hidden */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
if (_parent) {
|
2021-11-09 10:49:21 -05:00
|
|
|
_parent->child_changed (true);
|
2014-12-18 10:30:38 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-18 10:30:38 -05:00
|
|
|
_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;
|
2020-06-10 17:52:41 -04:00
|
|
|
_layout_sensitive = false;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-18 04:21:58 -05:00
|
|
|
Item::reparent (Item* new_parent, bool already_added)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
if (new_parent == _parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (_canvas == new_parent->canvas());
|
2013-04-21 18:57:55 -04:00
|
|
|
|
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 ();
|
2020-06-10 17:52:41 -04:00
|
|
|
set_layout_sensitive (_parent->layout_sensitive());
|
2014-05-22 23:05:18 -04:00
|
|
|
|
2017-01-18 04:21:58 -05:00
|
|
|
if (!already_added) {
|
|
|
|
_parent->add (this);
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-22 23:05:18 -04:00
|
|
|
_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;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-30 23:36:30 -04:00
|
|
|
/* move towards root until we are at the same level
|
|
|
|
for both items
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (d1 != d2) {
|
|
|
|
if (d1 > d2) {
|
2014-06-12 14:53:44 -04:00
|
|
|
if (!i1) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-30 23:36:30 -04:00
|
|
|
i1 = i1->parent();
|
|
|
|
d1--;
|
|
|
|
limit--;
|
|
|
|
} else {
|
2014-06-12 14:53:44 -04:00
|
|
|
if (!i2) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-30 23:36:30 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-30 23:36:30 -04:00
|
|
|
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) {
|
2014-06-12 14:53:44 -04:00
|
|
|
if (!i1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-30 23:36:30 -04:00
|
|
|
i1 = i1->parent();
|
|
|
|
d1--;
|
|
|
|
} else {
|
2014-06-12 14:53:44 -04:00
|
|
|
if (!i2) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-30 23:36:30 -04:00
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-30 23:36:30 -04:00
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2017-01-20 06:08:58 -05:00
|
|
|
void
|
|
|
|
Item::size_allocate (Rect const & r)
|
2021-08-04 01:21:55 -04:00
|
|
|
{
|
|
|
|
begin_change ();
|
|
|
|
_size_allocate (r);
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::_size_allocate (Rect const & r)
|
2017-01-20 06:08:58 -05:00
|
|
|
{
|
2021-08-01 23:56:33 -04:00
|
|
|
if (_layout_sensitive) {
|
2021-08-04 01:21:55 -04:00
|
|
|
/* this definitely affects the item */
|
2021-08-01 23:56:33 -04:00
|
|
|
_position = Duple (r.x0, r.y0);
|
2021-08-04 01:21:55 -04:00
|
|
|
/* this may have no effect on the item */
|
|
|
|
_allocation = r;
|
2021-08-01 23:56:33 -04:00
|
|
|
}
|
2021-08-04 01:21:55 -04:00
|
|
|
|
|
|
|
size_allocate_children (r);
|
2020-07-09 18:38:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::size_allocate_children (Rect const & r)
|
|
|
|
{
|
2021-08-04 20:59:20 -04:00
|
|
|
/* this does nothing by default. Containers like Box or
|
|
|
|
* ConstraintPacker can override it to do "smart" layout based on this
|
|
|
|
* Item's allocation.
|
|
|
|
*/
|
2020-07-09 18:38:52 -04:00
|
|
|
|
2021-09-29 13:19:03 -04:00
|
|
|
/* parent was told "you get width x height @ x,y""
|
|
|
|
*
|
|
|
|
* x must be 0 and y must be 0 in parent-relatve coordinates
|
|
|
|
*/
|
|
|
|
|
|
|
|
Rect parent_relative = r.translate (-_position);
|
|
|
|
|
2021-08-04 20:59:20 -04:00
|
|
|
if (_items.size() == 1 && _items.front()->layout_sensitive()) {
|
2021-09-29 13:19:03 -04:00
|
|
|
_items.front()->size_allocate (parent_relative);
|
2020-07-09 18:38:52 -04:00
|
|
|
}
|
2017-01-20 06:08:58 -05:00
|
|
|
}
|
|
|
|
|
2018-11-19 11:31:09 -05:00
|
|
|
void
|
|
|
|
Item::size_request (double& w, double& h) const
|
|
|
|
{
|
|
|
|
Rect r (bounding_box());
|
|
|
|
|
2021-08-01 23:18:35 -04:00
|
|
|
w = _requested_width < 0 ? r.width() : _requested_width;
|
|
|
|
h = _requested_width < 0 ? r.height() : _requested_height;
|
2018-11-19 11:31:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_size_request (double w, double h)
|
|
|
|
{
|
|
|
|
/* allow reset to zero or require that both are positive */
|
|
|
|
|
|
|
|
begin_change ();
|
2021-08-01 23:18:35 -04:00
|
|
|
_requested_width = w;
|
|
|
|
_requested_height = h;
|
2018-11-19 11:31:09 -05:00
|
|
|
_bounding_box_dirty = true;
|
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
|
2021-09-07 16:45:31 -04:00
|
|
|
void
|
|
|
|
Item::set_size_request_to_display_given_text (const std::vector<std::string>& strings, gint hpadding, gint vpadding)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Pango::Context> context = _canvas->get_pango_context();
|
|
|
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
int width_max = 0;
|
|
|
|
int height_max = 0;
|
|
|
|
|
|
|
|
vector<string> copy;
|
|
|
|
const vector<string>* to_use;
|
|
|
|
vector<string>::const_iterator i;
|
|
|
|
|
|
|
|
for (i = strings.begin(); i != strings.end(); ++i) {
|
|
|
|
if ((*i).find_first_of ("gy") != string::npos) {
|
|
|
|
/* contains a descender */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == strings.end()) {
|
|
|
|
/* make a copy of the strings then add one that has a descender */
|
|
|
|
copy = strings;
|
|
|
|
copy.push_back ("g");
|
|
|
|
to_use = ©
|
|
|
|
} else {
|
|
|
|
to_use = &strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator i = to_use->begin(); i != to_use->end(); ++i) {
|
|
|
|
layout->set_text (*i);
|
|
|
|
layout->get_pixel_size (width, height);
|
|
|
|
width_max = max (width_max,width);
|
|
|
|
height_max = max (height_max, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_size_request (width_max + hpadding, height_max + vpadding);
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
/** @return Bounding box in this item's coordinates */
|
2017-01-19 14:54:24 -05:00
|
|
|
ArdourCanvas::Rect
|
2020-06-10 17:52:41 -04:00
|
|
|
Item::bounding_box () const
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
|
|
|
if (_bounding_box_dirty) {
|
|
|
|
compute_bounding_box ();
|
2014-03-07 11:23:22 -05:00
|
|
|
assert (!_bounding_box_dirty);
|
2014-06-21 11:43:42 -04:00
|
|
|
add_child_bounding_boxes ();
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return _bounding_box;
|
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
Coord
|
2015-10-04 14:51:05 -04:00
|
|
|
Item::height () const
|
2013-04-04 18:45:27 -04:00
|
|
|
{
|
2017-01-19 14:54:24 -05:00
|
|
|
ArdourCanvas::Rect bb = bounding_box();
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
if (bb) {
|
2017-01-19 14:54:24 -05:00
|
|
|
return bb.height ();
|
2013-04-05 11:27:26 -04:00
|
|
|
}
|
|
|
|
return 0;
|
2013-04-04 18:45:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
2015-10-04 14:51:05 -04:00
|
|
|
Item::width () const
|
2013-04-04 18:45:27 -04:00
|
|
|
{
|
2017-01-19 14:54:24 -05:00
|
|
|
ArdourCanvas::Rect bb = bounding_box();
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
if (bb) {
|
2017-01-19 14:54:24 -05:00
|
|
|
return bb.width ();
|
2013-04-05 11:27:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-04-04 18:45:27 -04:00
|
|
|
}
|
|
|
|
|
2013-10-24 17:54:54 -04:00
|
|
|
void
|
|
|
|
Item::redraw () const
|
|
|
|
{
|
2014-12-18 10:30:38 -05:00
|
|
|
if (visible() && _bounding_box && _canvas) {
|
2018-11-25 19:08:05 -05:00
|
|
|
_canvas->request_redraw (item_to_window (_bounding_box, false));
|
2013-10-24 17:54:54 -04:00
|
|
|
}
|
2018-11-25 19:08:05 -05:00
|
|
|
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
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 ()
|
|
|
|
{
|
2014-12-18 10:30:38 -05:00
|
|
|
if (visible()) {
|
2014-06-18 10:06:32 -04:00
|
|
|
_canvas->item_changed (this, _pre_change_bounding_box);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-18 10:06:32 -04:00
|
|
|
if (_parent) {
|
2020-06-10 17:24:52 -04:00
|
|
|
_parent->child_changed (_pre_change_bounding_box != _bounding_box);
|
2014-06-18 10:06:32 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 20:38:10 -04:00
|
|
|
void
|
|
|
|
Item::begin_visual_change ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::end_visual_change ()
|
|
|
|
{
|
2014-12-18 10:30:38 -05:00
|
|
|
if (visible()) {
|
2014-06-18 10:06:32 -04:00
|
|
|
_canvas->item_visual_property_changed (this);
|
|
|
|
}
|
2013-04-16 20:38:10 -04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::set_ignore_events (bool ignore)
|
|
|
|
{
|
|
|
|
_ignore_events = ignore;
|
|
|
|
}
|
2013-04-05 11:27:26 -04:00
|
|
|
|
|
|
|
std::string
|
2015-10-04 14:51:05 -04:00
|
|
|
Item::whatami () const
|
2013-04-05 11:27:26 -04:00
|
|
|
{
|
|
|
|
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) {
|
2021-07-27 15:23:37 -04:00
|
|
|
(void) bounding_box ();
|
2013-11-04 11:56:10 -05:00
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect r = bounding_box();
|
2013-11-04 11:56:10 -05:00
|
|
|
|
2021-07-27 15:23:37 -04:00
|
|
|
/* bounding box uses item coordinates, with _position as the origin */
|
|
|
|
|
2013-11-04 11:56:10 -05:00
|
|
|
if (!r) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
return r.contains (p);
|
2013-11-04 11:56:10 -05:00
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
/* nesting/grouping API */
|
|
|
|
|
2020-06-25 17:03:26 -04:00
|
|
|
static bool debug_render = false;
|
2020-06-24 20:11:37 -04:00
|
|
|
#define CANVAS_DEBUG 1
|
|
|
|
|
2014-06-22 11:41:05 -04:00
|
|
|
void
|
|
|
|
Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|
|
|
{
|
|
|
|
if (_items.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_lut ();
|
|
|
|
std::vector<Item*> items = _lut->get (area);
|
|
|
|
|
|
|
|
#ifdef CANVAS_DEBUG
|
2020-06-24 20:11:37 -04:00
|
|
|
if (debug_render || DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
2020-06-19 15:57:58 -04:00
|
|
|
cerr << string_compose ("%1%8 %2 @ %7 render %5 @ %6 %3 items out of %4\n",
|
|
|
|
_canvas->render_indent(), (name.empty() ? string ("[unnamed]") : name), items.size(), _items.size(), area, _position, 0 /* this */,
|
|
|
|
whatami());
|
2014-06-22 11:41:05 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
++render_depth;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-22 11:41:05 -04:00
|
|
|
for (std::vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
|
|
|
|
|
|
|
if (!(*i)->visible ()) {
|
|
|
|
#ifdef CANVAS_DEBUG
|
2020-06-24 20:11:37 -04:00
|
|
|
if (debug_render || DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
2021-07-27 15:23:12 -04:00
|
|
|
cerr << _canvas->render_indent() << "Item " << (*i)->whoami() << " invisible - skipped\n";
|
2014-06-22 11:41:05 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect item_bbox = (*i)->bounding_box ();
|
2014-06-22 11:41:05 -04:00
|
|
|
|
|
|
|
if (!item_bbox) {
|
|
|
|
#ifdef CANVAS_DEBUG
|
2020-06-24 20:11:37 -04:00
|
|
|
if (debug_render || DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
2021-07-27 15:23:12 -04:00
|
|
|
cerr << _canvas->render_indent() << "Item " << (*i)->whoami() << " empty - skipped\n";
|
2014-06-22 11:41:05 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect item = (*i)->item_to_window (item_bbox, false);
|
|
|
|
Rect d = item.intersection (area);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-22 11:41:05 -04:00
|
|
|
if (d) {
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect draw = d;
|
2014-06-22 11:41:05 -04:00
|
|
|
if (draw.width() && draw.height()) {
|
|
|
|
#ifdef CANVAS_DEBUG
|
2020-06-24 20:11:37 -04:00
|
|
|
if (debug_render || DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
2014-06-22 11:41:05 -04:00
|
|
|
if (dynamic_cast<Container*>(*i) == 0) {
|
|
|
|
cerr << _canvas->render_indent() << "render "
|
2015-10-04 14:51:05 -04:00
|
|
|
<< ' '
|
2014-06-22 11:41:05 -04:00
|
|
|
<< (*i)
|
|
|
|
<< ' '
|
2020-06-24 20:11:37 -04:00
|
|
|
<< (*i)->whoami()
|
2014-06-22 11:41:05 -04:00
|
|
|
<< " item "
|
2017-01-19 14:54:24 -05:00
|
|
|
<< item_bbox
|
2015-10-04 14:51:05 -04:00
|
|
|
<< " window = "
|
2014-06-22 11:41:05 -04:00
|
|
|
<< item
|
|
|
|
<< " intersect = "
|
|
|
|
<< draw
|
2015-10-04 14:51:05 -04:00
|
|
|
<< " @ "
|
2014-06-22 11:41:05 -04:00
|
|
|
<< _position
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(*i)->render (area, context);
|
|
|
|
++render_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
#ifdef CANVAS_DEBUG
|
2020-06-24 20:11:37 -04:00
|
|
|
if (debug_render || DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
2021-07-27 15:23:12 -04:00
|
|
|
cerr << string_compose ("%1skip render of %2, no intersection between %3 and %4\n", _canvas->render_indent(), (*i)->whoami(), item, area);
|
2014-06-22 11:41:05 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--render_depth;
|
|
|
|
}
|
2020-06-24 20:11:37 -04:00
|
|
|
#undef CANVAS_DEBUG
|
2014-06-22 11:41:05 -04:00
|
|
|
|
2017-04-01 09:02:49 -04:00
|
|
|
void
|
|
|
|
Item::prepare_for_render_children (Rect const & area) const
|
|
|
|
{
|
|
|
|
if (_items.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_lut ();
|
|
|
|
std::vector<Item*> items = _lut->get (area);
|
|
|
|
|
|
|
|
for (std::vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
|
|
|
|
|
|
|
if (!(*i)->visible ()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect item_bbox = (*i)->bounding_box ();
|
|
|
|
|
|
|
|
if (!item_bbox) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect item = (*i)->item_to_window (item_bbox, false);
|
|
|
|
Rect d = item.intersection (area);
|
|
|
|
|
|
|
|
if (d) {
|
|
|
|
Rect draw = d;
|
|
|
|
if (draw.width() && draw.height()) {
|
|
|
|
(*i)->prepare_for_render (area);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Item does not intersect with visible canvas area
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
void
|
2016-09-25 15:44:27 -04:00
|
|
|
Item::add_child_bounding_boxes (bool include_hidden) const
|
2014-06-21 11:43:42 -04:00
|
|
|
{
|
2021-07-27 15:22:26 -04:00
|
|
|
Rect self;
|
2014-06-21 11:43:42 -04:00
|
|
|
Rect bbox;
|
|
|
|
bool have_one = false;
|
|
|
|
|
|
|
|
if (_bounding_box) {
|
2017-01-19 14:54:24 -05:00
|
|
|
bbox = _bounding_box;
|
2014-06-21 11:43:42 -04:00
|
|
|
have_one = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
|
2016-09-25 15:44:27 -04:00
|
|
|
if (!(*i)->visible() && !include_hidden) {
|
2014-10-13 22:40:08 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect item_bbox = (*i)->bounding_box ();
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
if (!item_bbox) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-27 18:54:33 -04:00
|
|
|
Rect child_bbox = (*i)->item_to_parent (item_bbox);
|
2014-06-21 11:43:42 -04:00
|
|
|
if (have_one) {
|
2021-07-27 18:54:33 -04:00
|
|
|
bbox = bbox.extend (child_bbox);
|
2014-06-21 11:43:42 -04:00
|
|
|
} else {
|
2021-07-27 18:54:33 -04:00
|
|
|
bbox = child_bbox;
|
2014-06-21 11:43:42 -04:00
|
|
|
have_one = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_one) {
|
2017-01-19 14:54:24 -05:00
|
|
|
_bounding_box = Rect ();
|
2014-06-21 11:43:42 -04:00
|
|
|
} else {
|
|
|
|
_bounding_box = bbox;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:31:09 -05:00
|
|
|
void
|
|
|
|
Item::queue_resize()
|
|
|
|
{
|
|
|
|
_resize_queued = true;
|
|
|
|
|
|
|
|
if (_parent) {
|
|
|
|
_parent->queue_resize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this == _canvas->root()) {
|
|
|
|
_canvas->queue_resize ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
void
|
|
|
|
Item::add (Item* i)
|
|
|
|
{
|
|
|
|
/* XXX should really notify canvas about this */
|
|
|
|
|
|
|
|
_items.push_back (i);
|
2017-01-18 04:21:58 -05:00
|
|
|
i->reparent (this, true);
|
2014-06-21 11:43:42 -04:00
|
|
|
invalidate_lut ();
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
}
|
|
|
|
|
2016-09-25 15:43:57 -04:00
|
|
|
void
|
|
|
|
Item::add_front (Item* i)
|
|
|
|
{
|
|
|
|
/* XXX should really notify canvas about this */
|
|
|
|
|
|
|
|
_items.push_front (i);
|
2017-01-18 04:21:58 -05:00
|
|
|
i->reparent (this, true);
|
2016-09-25 15:43:57 -04:00
|
|
|
invalidate_lut ();
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
void
|
|
|
|
Item::remove (Item* i)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i->parent() != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we cannot call bounding_box() here because that will iterate over
|
|
|
|
_items, one of which (the argument, i) may be in the middle of
|
|
|
|
deletion, making it impossible to call compute_bounding_box()
|
|
|
|
on it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (_bounding_box) {
|
|
|
|
_pre_change_bounding_box = _bounding_box;
|
|
|
|
} else {
|
|
|
|
_pre_change_bounding_box = Rect();
|
|
|
|
}
|
|
|
|
|
|
|
|
i->unparent ();
|
2020-06-10 17:52:41 -04:00
|
|
|
i->set_layout_sensitive (false);
|
2014-06-21 11:43:42 -04:00
|
|
|
_items.remove (i);
|
|
|
|
invalidate_lut ();
|
|
|
|
_bounding_box_dirty = true;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::clear (bool with_delete)
|
|
|
|
{
|
|
|
|
begin_change ();
|
|
|
|
|
|
|
|
clear_items (with_delete);
|
|
|
|
|
|
|
|
invalidate_lut ();
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
|
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::clear_items (bool with_delete)
|
|
|
|
{
|
|
|
|
for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ) {
|
|
|
|
|
|
|
|
list<Item*>::iterator tmp = i;
|
|
|
|
Item *item = *i;
|
|
|
|
|
|
|
|
++tmp;
|
|
|
|
|
|
|
|
/* remove from list before doing anything else, because we
|
|
|
|
* don't want to find the item in _items during any activity
|
|
|
|
* driven by unparent-ing or deletion.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_items.erase (i);
|
|
|
|
item->unparent ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
if (with_delete) {
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::raise_child_to_top (Item* i)
|
|
|
|
{
|
|
|
|
if (!_items.empty()) {
|
|
|
|
if (_items.back() == i) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_items.remove (i);
|
|
|
|
_items.push_back (i);
|
2014-11-06 10:53:48 -05:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
invalidate_lut ();
|
2014-11-06 10:53:48 -05:00
|
|
|
redraw ();
|
2014-06-21 11:43:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::raise_child (Item* i, int levels)
|
|
|
|
{
|
|
|
|
list<Item*>::iterator j = find (_items.begin(), _items.end(), i);
|
|
|
|
assert (j != _items.end ());
|
|
|
|
|
|
|
|
++j;
|
|
|
|
_items.remove (i);
|
|
|
|
|
|
|
|
while (levels > 0 && j != _items.end ()) {
|
|
|
|
++j;
|
|
|
|
--levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
_items.insert (j, i);
|
|
|
|
invalidate_lut ();
|
2014-11-06 10:53:48 -05:00
|
|
|
redraw ();
|
2014-06-21 11:43:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::lower_child_to_bottom (Item* i)
|
|
|
|
{
|
|
|
|
if (!_items.empty()) {
|
|
|
|
if (_items.front() == i) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_items.remove (i);
|
|
|
|
_items.push_front (i);
|
|
|
|
invalidate_lut ();
|
2014-11-06 10:53:48 -05:00
|
|
|
redraw ();
|
2014-06-21 11:43:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::ensure_lut () const
|
|
|
|
{
|
|
|
|
if (!_lut) {
|
|
|
|
_lut = new DumbLookupTable (*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::invalidate_lut () const
|
|
|
|
{
|
|
|
|
delete _lut;
|
|
|
|
_lut = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-06-10 17:24:52 -04:00
|
|
|
Item::child_changed (bool bbox_changed)
|
2014-06-21 11:43:42 -04:00
|
|
|
{
|
|
|
|
invalidate_lut ();
|
2021-07-27 14:27:37 -04:00
|
|
|
|
|
|
|
if (bbox_changed) {
|
|
|
|
_bounding_box_dirty = true;
|
|
|
|
}
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
if (_parent) {
|
2020-06-10 17:24:52 -04:00
|
|
|
_parent->child_changed (bbox_changed);
|
2014-06-21 11:43:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::add_items_at_point (Duple const point, vector<Item const *>& items) const
|
|
|
|
{
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect const bbox = bounding_box ();
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
/* Point is in window coordinate system */
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
if (!bbox || !item_to_window (bbox).contains (point)) {
|
2014-06-21 11:43:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-30 08:32:18 -04:00
|
|
|
/* recurse and add any items within our group that contain point.
|
2014-06-30 16:31:31 -04:00
|
|
|
Our children are only considered visible if we are, and similarly
|
|
|
|
only if we do not ignore events.
|
2014-06-30 08:32:18 -04:00
|
|
|
*/
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
vector<Item*> our_items;
|
|
|
|
|
2014-06-30 16:31:31 -04:00
|
|
|
if (!_items.empty() && visible() && !_ignore_events) {
|
2014-06-21 11:43:42 -04:00
|
|
|
ensure_lut ();
|
|
|
|
our_items = _lut->items_at_point (point);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!our_items.empty() || covers (point)) {
|
|
|
|
/* this adds this item itself to the list of items at point */
|
|
|
|
items.push_back (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (vector<Item*>::iterator i = our_items.begin(); i != our_items.end(); ++i) {
|
|
|
|
(*i)->add_items_at_point (point, items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 21:43:15 -04:00
|
|
|
void
|
|
|
|
Item::set_tooltip (const std::string& s)
|
|
|
|
{
|
|
|
|
_tooltip = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::start_tooltip_timeout ()
|
|
|
|
{
|
|
|
|
if (!_tooltip.empty()) {
|
|
|
|
_canvas->start_tooltip_timeout (this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Item::stop_tooltip_timeout ()
|
|
|
|
{
|
|
|
|
_canvas->stop_tooltip_timeout ();
|
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
void
|
|
|
|
Item::dump (ostream& o) const
|
|
|
|
{
|
2017-01-19 14:54:24 -05:00
|
|
|
ArdourCanvas::Rect bb = bounding_box();
|
2014-06-21 11:43:42 -04:00
|
|
|
|
2020-06-10 17:52:41 -04:00
|
|
|
o << _canvas->indent() << whoami() << ' ' << this << " self-Visible ? " << self_visible() << " visible ? " << visible() << " layout " << layout_sensitive()
|
2021-12-10 19:16:10 -05:00
|
|
|
<< " @ " << position() << " +/- " << scroll_offset();
|
2014-06-21 11:43:42 -04:00
|
|
|
|
|
|
|
if (bb) {
|
2017-01-19 14:54:24 -05:00
|
|
|
o << endl << _canvas->indent() << "\tbbox: " << bb;
|
|
|
|
o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb);
|
2014-06-21 11:43:42 -04:00
|
|
|
} else {
|
|
|
|
o << " bbox unset";
|
|
|
|
}
|
|
|
|
|
|
|
|
o << endl;
|
|
|
|
|
|
|
|
if (!_items.empty()) {
|
|
|
|
|
|
|
|
#ifdef CANVAS_DEBUG
|
|
|
|
o << _canvas->indent();
|
|
|
|
o << " @ " << position();
|
|
|
|
o << " Items: " << _items.size();
|
2014-12-18 10:30:38 -05:00
|
|
|
o << " Self-Visible ? " << self_visible();
|
|
|
|
o << " Visible ? " << visible();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect bb = bounding_box();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
if (bb) {
|
2017-01-19 14:54:24 -05:00
|
|
|
o << endl << _canvas->indent() << " bbox: " << bb;
|
|
|
|
o << endl << _canvas->indent() << " CANVAS bbox: " << item_to_canvas (bb);
|
2014-06-21 11:43:42 -04:00
|
|
|
} else {
|
|
|
|
o << " bbox unset";
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
o << endl;
|
|
|
|
#endif
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
ArdourCanvas::dump_depth++;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
o << **i;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
ArdourCanvas::dump_depth--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-06-10 17:52:41 -04:00
|
|
|
void
|
|
|
|
Item::set_layout_sensitive (bool yn)
|
|
|
|
{
|
|
|
|
_layout_sensitive = yn;
|
2021-08-01 23:18:35 -04:00
|
|
|
|
|
|
|
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
|
|
|
|
(*i)->set_layout_sensitive (yn);
|
|
|
|
}
|
2020-06-10 17:52:41 -04:00
|
|
|
}
|
2021-07-27 15:13:14 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Item::bb_clean () const
|
|
|
|
{
|
|
|
|
_bounding_box_dirty = false;
|
|
|
|
}
|
|
|
|
|
2021-07-29 14:23:53 -04:00
|
|
|
void
|
|
|
|
Item::set_pack_options (PackOptions po)
|
|
|
|
{
|
|
|
|
/* must be called before adding/packing Item in a Container */
|
|
|
|
_pack_options = po;
|
|
|
|
}
|
2022-01-20 11:45:47 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Item::disable_scroll_translation ()
|
|
|
|
{
|
|
|
|
_scroll_translation = false;
|
|
|
|
}
|