*/
#include "pbd/compose.h"
-#include "pbd/stacktrace.h"
+#include "pbd/demangle.h"
#include "pbd/convert.h"
#include "ardour/utils.h"
, _ignore_events (false)
{
DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this));
-}
+}
Item::Item (Item* parent)
: Fill (*this)
}
find_scroll_parent ();
-}
+}
Item::Item (Item* parent, Duple const& p)
: Fill (*this)
find_scroll_parent ();
-}
+}
Item::~Item ()
{
Item::item_to_canvas (Coord& x, Coord& y) const
{
Duple d = item_to_canvas (Duple (x, y));
-
+
x = d.x;
y = d.y;
}
return;
}
- boost::optional<ArdourCanvas::Rect> bbox = bounding_box ();
- boost::optional<ArdourCanvas::Rect> pre_change_parent_bounding_box;
+ ArdourCanvas::Rect bbox = bounding_box ();
+ ArdourCanvas::Rect pre_change_parent_bounding_box;
if (bbox) {
/* see the comment in Canvas::item_moved() to understand
* why we use the parent's bounding box here.
*/
- pre_change_parent_bounding_box = item_to_parent (bbox.get());
+ pre_change_parent_bounding_box = item_to_parent (bbox);
}
-
+
_position = p;
/* only update canvas and parent if visible. Otherwise, this
will be done when ::show() is called.
*/
-
+
if (visible()) {
_canvas->item_moved (this, pre_change_parent_bounding_box);
-
+
if (_parent) {
_parent->child_changed ();
}
}
-
+
propagate_show_hide ();
}
}
Item::propagate_show_hide ()
{
/* bounding box may have changed while we were hidden */
-
+
if (_parent) {
_parent->child_changed ();
}
-
+
_canvas->item_shown_or_hidden (this);
}
}
void
-Item::reparent (Item* new_parent)
+Item::reparent (Item* new_parent, bool already_added)
{
if (new_parent == _parent) {
return;
find_scroll_parent ();
- _parent->add (this);
+ if (!already_added) {
+ _parent->add (this);
+ }
}
void
}
i = i->parent();
}
-
+
_scroll_parent = const_cast<ScrollGroup*> (last_scroll_group);
}
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
*/
return false;
}
}
-
+
return true;
}
i2 = i2->parent ();
}
}
-
+
return i1;
}
/* XXX */
}
+void
+Item::size_allocate (Rect const & r)
+{
+ _allocation = r;
+}
+
/** @return Bounding box in this item's coordinates */
-boost::optional<ArdourCanvas::Rect>
-Item::bounding_box () const
+ArdourCanvas::Rect
+Item::bounding_box (bool for_own_purposes) const
{
if (_bounding_box_dirty) {
compute_bounding_box ();
add_child_bounding_boxes ();
}
+ if (!for_own_purposes) {
+ if (_allocation) {
+ return _allocation;
+ }
+ }
+
return _bounding_box;
}
Coord
Item::height () const
{
- boost::optional<ArdourCanvas::Rect> bb = bounding_box();
+ ArdourCanvas::Rect bb = bounding_box();
if (bb) {
- return bb->height ();
+ return bb.height ();
}
return 0;
}
Coord
Item::width () const
{
- boost::optional<ArdourCanvas::Rect> bb = bounding_box();
+ ArdourCanvas::Rect bb = bounding_box();
if (bb) {
- return bb->width ();
+ return bb.width ();
}
return 0;
Item::redraw () const
{
if (visible() && _bounding_box && _canvas) {
- _canvas->request_redraw (item_to_window (_bounding_box.get()));
+ _canvas->request_redraw (item_to_window (_bounding_box));
}
-}
+}
void
Item::begin_change ()
{
if (visible()) {
_canvas->item_changed (this, _pre_change_bounding_box);
-
+
if (_parent) {
_parent->child_changed ();
}
if (i == _data.end ()) {
return 0;
}
-
+
return i->second;
}
compute_bounding_box ();
}
- boost::optional<Rect> r = bounding_box();
+ Rect r = bounding_box();
if (!r) {
return false;
}
- return r.get().contains (p);
+ return r.contains (p);
}
/* nesting/grouping API */
#endif
++render_depth;
-
+
for (std::vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
if (!(*i)->visible ()) {
#endif
continue;
}
-
- boost::optional<Rect> item_bbox = (*i)->bounding_box ();
+
+ Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
#ifdef CANVAS_DEBUG
#endif
continue;
}
-
- Rect item = (*i)->item_to_window (item_bbox.get(), false);
- boost::optional<Rect> d = item.intersection (area);
-
+
+ Rect item = (*i)->item_to_window (item_bbox, false);
+ Rect d = item.intersection (area);
+
if (d) {
- Rect draw = d.get();
+ Rect draw = d;
if (draw.width() && draw.height()) {
#ifdef CANVAS_DEBUG
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
<< ' '
<< (*i)->name
<< " item "
- << item_bbox.get()
+ << item_bbox
<< " window = "
<< item
<< " intersect = "
}
void
-Item::add_child_bounding_boxes() const
+Item::prepare_for_render_children (Rect const & area) const
{
- boost::optional<Rect> self;
+ 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
+ }
+ }
+}
+
+void
+Item::add_child_bounding_boxes (bool include_hidden) const
+{
+ Rect self;
Rect bbox;
bool have_one = false;
if (_bounding_box) {
- bbox = _bounding_box.get();
+ bbox = _bounding_box;
have_one = true;
}
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
- if (!(*i)->visible()) {
+ if (!(*i)->visible() && !include_hidden) {
continue;
}
- boost::optional<Rect> item_bbox = (*i)->bounding_box ();
+ Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
continue;
}
- Rect group_bbox = (*i)->item_to_parent (item_bbox.get ());
+ Rect group_bbox = (*i)->item_to_parent (item_bbox);
if (have_one) {
bbox = bbox.extend (group_bbox);
} else {
}
if (!have_one) {
- _bounding_box = boost::optional<Rect> ();
+ _bounding_box = Rect ();
} else {
_bounding_box = bbox;
}
/* XXX should really notify canvas about this */
_items.push_back (i);
- i->reparent (this);
+ i->reparent (this, true);
+ invalidate_lut ();
+ _bounding_box_dirty = true;
+}
+
+void
+Item::add_front (Item* i)
+{
+ /* XXX should really notify canvas about this */
+
+ _items.push_front (i);
+ i->reparent (this, true);
invalidate_lut ();
_bounding_box_dirty = true;
}
_items.remove (i);
invalidate_lut ();
_bounding_box_dirty = true;
-
+
end_change ();
}
_items.erase (i);
item->unparent ();
-
+
if (with_delete) {
delete item;
}
void
Item::add_items_at_point (Duple const point, vector<Item const *>& items) const
{
- boost::optional<Rect> const bbox = bounding_box ();
+ Rect const bbox = bounding_box ();
/* Point is in window coordinate system */
- if (!bbox || !item_to_window (bbox.get()).contains (point)) {
+ if (!bbox || !item_to_window (bbox).contains (point)) {
return;
}
void
Item::dump (ostream& o) const
{
- boost::optional<ArdourCanvas::Rect> bb = bounding_box();
+ ArdourCanvas::Rect bb = bounding_box();
o << _canvas->indent() << whatami() << ' ' << this << " self-Visible ? " << self_visible() << " visible ? " << visible();
o << " @ " << position();
-
+
#ifdef CANVAS_DEBUG
if (!name.empty()) {
o << ' ' << name;
#endif
if (bb) {
- o << endl << _canvas->indent() << "\tbbox: " << bb.get();
- o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb.get());
+ o << endl << _canvas->indent() << "\tbbox: " << bb;
+ o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb);
} else {
o << " bbox unset";
}
o << " Items: " << _items.size();
o << " Self-Visible ? " << self_visible();
o << " Visible ? " << visible();
-
- boost::optional<Rect> bb = bounding_box();
-
+
+ Rect bb = bounding_box();
+
if (bb) {
- o << endl << _canvas->indent() << " bbox: " << bb.get();
- o << endl << _canvas->indent() << " CANVAS bbox: " << item_to_canvas (bb.get());
+ o << endl << _canvas->indent() << " bbox: " << bb;
+ o << endl << _canvas->indent() << " CANVAS bbox: " << item_to_canvas (bb);
} else {
o << " bbox unset";
}
-
+
o << endl;
#endif
-
+
ArdourCanvas::dump_depth++;
-
+
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
o << **i;
}
-
+
ArdourCanvas::dump_depth--;
}
}