diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-22 11:41:05 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-22 11:41:05 -0400 |
commit | 6a5d805b383cd71bb1d0984964439c5ec08e9270 (patch) | |
tree | d551b417d1dbc026376207a94b4933a0b824797b /libs | |
parent | f0933bf00551ce998ca441aa5611d27702f6e590 (diff) |
more canvas refactoring.
Remove Canvas::Layout, use Canvas::Container for the same purpose, move child-rendering into Item::render_children() so that it
could theoretically be used by any derived type.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/canvas/arrow.cc | 4 | ||||
-rw-r--r-- | libs/canvas/canvas/arrow.h | 4 | ||||
-rw-r--r-- | libs/canvas/canvas/container.h | 8 | ||||
-rw-r--r-- | libs/canvas/canvas/flag.h | 4 | ||||
-rw-r--r-- | libs/canvas/canvas/item.h | 1 | ||||
-rw-r--r-- | libs/canvas/canvas/layout.h | 43 | ||||
-rw-r--r-- | libs/canvas/canvas/root_group.h | 4 | ||||
-rw-r--r-- | libs/canvas/canvas/scroll_group.h | 4 | ||||
-rw-r--r-- | libs/canvas/container.cc | 6 | ||||
-rw-r--r-- | libs/canvas/flag.cc | 4 | ||||
-rw-r--r-- | libs/canvas/item.cc | 90 | ||||
-rw-r--r-- | libs/canvas/layout.cc | 132 | ||||
-rw-r--r-- | libs/canvas/root_group.cc | 4 | ||||
-rw-r--r-- | libs/canvas/scroll_group.cc | 6 | ||||
-rw-r--r-- | libs/canvas/wscript | 1 |
15 files changed, 120 insertions, 195 deletions
diff --git a/libs/canvas/arrow.cc b/libs/canvas/arrow.cc index 5cac31300e..70dbc0b498 100644 --- a/libs/canvas/arrow.cc +++ b/libs/canvas/arrow.cc @@ -35,13 +35,13 @@ using namespace ArdourCanvas; * @param parent Parent canvas group. */ Arrow::Arrow (Canvas* c) - : Layout (c) + : Container (c) { setup (); } Arrow::Arrow (Item* parent) - : Layout (parent) + : Container (parent) { setup (); } diff --git a/libs/canvas/canvas/arrow.h b/libs/canvas/canvas/arrow.h index 7db225553e..45c6eb110e 100644 --- a/libs/canvas/canvas/arrow.h +++ b/libs/canvas/canvas/arrow.h @@ -26,7 +26,7 @@ #define __CANVAS_ARROW_H__ #include "canvas/visibility.h" -#include "canvas/layout.h" +#include "canvas/container.h" namespace ArdourCanvas { @@ -45,7 +45,7 @@ class Polygon; * to draw lines at any angle. */ -class LIBCANVAS_API Arrow : public Layout +class LIBCANVAS_API Arrow : public Container { public: Arrow (Canvas*); diff --git a/libs/canvas/canvas/container.h b/libs/canvas/canvas/container.h index be80b37376..59d93458e6 100644 --- a/libs/canvas/canvas/container.h +++ b/libs/canvas/canvas/container.h @@ -30,7 +30,7 @@ namespace ArdourCanvas * * Imagined examples of containers: * - * Layout: renders each child at the child's self-determined position + * Container: renders each child at the child's self-determined position * Box: renders each child along an axis (vertical or horizontal) * Table/Grid: renders each child within a two-dimensional grid * @@ -47,8 +47,12 @@ public: * in all containers (the union of the children's bounding boxes). * It can be overriden as necessary. */ - void compute_bounding_box () const; + + /** The render() method is likely to be identical in all containers + * (just call Item::render_children()). It can be overridden as necessary. + */ + void render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const; }; } diff --git a/libs/canvas/canvas/flag.h b/libs/canvas/canvas/flag.h index 05c0e2777d..3aff9ed241 100644 --- a/libs/canvas/canvas/flag.h +++ b/libs/canvas/canvas/flag.h @@ -19,7 +19,7 @@ #include "canvas/visibility.h" #include "canvas/types.h" -#include "canvas/layout.h" +#include "canvas/container.h" namespace ArdourCanvas { @@ -27,7 +27,7 @@ class Text; class Line; class Rectangle; -class LIBCANVAS_API Flag : public Layout +class LIBCANVAS_API Flag : public Container { public: Flag (Canvas *, Distance, Color, Color, Duple); diff --git a/libs/canvas/canvas/item.h b/libs/canvas/canvas/item.h index ced94e1e3b..85beedc6b3 100644 --- a/libs/canvas/canvas/item.h +++ b/libs/canvas/canvas/item.h @@ -283,6 +283,7 @@ protected: std::list<Item*> _items; void add_child_bounding_boxes() const; + void render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const; private: void init (); diff --git a/libs/canvas/canvas/layout.h b/libs/canvas/canvas/layout.h deleted file mode 100644 index 8b82b0f635..0000000000 --- a/libs/canvas/canvas/layout.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2011-2014 Paul Davis - Original 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. -*/ - -#ifndef __CANVAS_LAYOUT_H__ -#define __CANVAS_LAYOUT_H__ - -#include "canvas/container.h" - -namespace ArdourCanvas -{ - -/** a Layout is a container item that renders all of its children at fixed - * positions which they control. - */ -class LIBCANVAS_API Layout : public Container -{ -public: - Layout (Canvas *); - Layout (Item *); - Layout (Item*, Duple const & position); - - void render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const; -}; - -} - -#endif diff --git a/libs/canvas/canvas/root_group.h b/libs/canvas/canvas/root_group.h index 5db8024f51..1763fc11df 100644 --- a/libs/canvas/canvas/root_group.h +++ b/libs/canvas/canvas/root_group.h @@ -21,11 +21,11 @@ #define __CANVAS_ROOT_GROUP_H__ #include "canvas/visibility.h" -#include "canvas/layout.h" +#include "canvas/container.h" namespace ArdourCanvas { -class LIBCANVAS_API Root : public Layout +class LIBCANVAS_API Root : public Container { private: friend class Canvas; diff --git a/libs/canvas/canvas/scroll_group.h b/libs/canvas/canvas/scroll_group.h index 013d769c2f..463abc0bbc 100644 --- a/libs/canvas/canvas/scroll_group.h +++ b/libs/canvas/canvas/scroll_group.h @@ -19,7 +19,7 @@ #ifndef __CANVAS_SCROLL_GROUP_H__ #define __CANVAS_SCROLL_GROUP_H__ -#include "canvas/layout.h" +#include "canvas/container.h" namespace ArdourCanvas { @@ -27,7 +27,7 @@ namespace ArdourCanvas { * its children in a way that reflects the most recent * call to its scroll_to() method. */ -class LIBCANVAS_API ScrollGroup : public Layout +class LIBCANVAS_API ScrollGroup : public Container { public: enum ScrollSensitivity { diff --git a/libs/canvas/container.cc b/libs/canvas/container.cc index 4190437e6b..6aa265fd81 100644 --- a/libs/canvas/container.cc +++ b/libs/canvas/container.cc @@ -38,6 +38,12 @@ Container::Container (Item* parent, Duple const & p) } void +Container::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const +{ + Item::render_children (area, context); +} + +void Container::compute_bounding_box () const { _bounding_box = boost::none; diff --git a/libs/canvas/flag.cc b/libs/canvas/flag.cc index b6532d7fd2..243e71cd17 100644 --- a/libs/canvas/flag.cc +++ b/libs/canvas/flag.cc @@ -26,7 +26,7 @@ using namespace std; using namespace ArdourCanvas; Flag::Flag (Canvas* canvas, Distance height, Color outline_color, Color fill_color, Duple position) - : Layout (canvas) + : Container (canvas) , _outline_color (outline_color) , _fill_color (fill_color) { @@ -34,7 +34,7 @@ Flag::Flag (Canvas* canvas, Distance height, Color outline_color, Color fill_col } Flag::Flag (Item* parent, Distance height, Color outline_color, Color fill_color, Duple position) - : Layout (parent) + : Container (parent) , _outline_color (outline_color) , _fill_color (fill_color) { diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index e58411f17f..2d4f03a41f 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -674,6 +674,96 @@ Item::covers (Duple const & point) const /* nesting/grouping API */ 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 + if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { + cerr << string_compose ("%1%7 %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, this, + whatami()); + } +#endif + + ++render_depth; + + for (std::vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) { + + if (!(*i)->visible ()) { +#ifdef CANVAS_DEBUG + if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { + cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << " [" << (*i)->name << "] invisible - skipped\n"; + } +#endif + continue; + } + + boost::optional<Rect> item_bbox = (*i)->bounding_box (); + + if (!item_bbox) { +#ifdef CANVAS_DEBUG + if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { + cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << " [" << (*i)->name << "] empty - skipped\n"; + } +#endif + continue; + } + + Rect item = (*i)->item_to_window (item_bbox.get()); + boost::optional<Rect> d = item.intersection (area); + + if (d) { + Rect draw = d.get(); + if (draw.width() && draw.height()) { +#ifdef CANVAS_DEBUG + if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { + if (dynamic_cast<Container*>(*i) == 0) { + cerr << _canvas->render_indent() << "render " + << ' ' + << (*i) + << ' ' + << (*i)->whatami() + << ' ' + << (*i)->name + << " item " + << item_bbox.get() + << " window = " + << item + << " intersect = " + << draw + << " @ " + << _position + << endl; + } + } +#endif + + (*i)->render (area, context); + ++render_count; + } + + } else { + +#ifdef CANVAS_DEBUG + if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { + cerr << string_compose ("%1skip render of %2 %3, no intersection between %4 and %5\n", _canvas->render_indent(), (*i)->whatami(), + (*i)->name, item, area); + } +#endif + + } + } + + --render_depth; +} + +void Item::add_child_bounding_boxes() const { boost::optional<Rect> self; diff --git a/libs/canvas/layout.cc b/libs/canvas/layout.cc deleted file mode 100644 index ca9f50d05e..0000000000 --- a/libs/canvas/layout.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - Copyright (C) 2011-2014 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. -*/ - -#include "pbd/compose.h" - -#include "canvas/canvas.h" -#include "canvas/debug.h" -#include "canvas/layout.h" - -using namespace std; -using namespace PBD; -using namespace ArdourCanvas; - -Layout::Layout (Canvas* canvas) - : Container (canvas) -{ -} - -Layout::Layout (Item* parent) - : Container (parent) -{ -} - -Layout::Layout (Item* parent, Duple const & p) - : Container (parent, p) -{ -} - -/** @param area Area to draw in window coordinates. - * @param context Context, set up with its origin at this layout's position. - */ -void -Layout::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const -{ - ensure_lut (); - std::vector<Item*> items = _lut->get (area); - -#ifdef CANVAS_DEBUG - if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { - cerr << string_compose ("%1GROUP %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, this); - } -#endif - - ++render_depth; - - for (std::vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) { - - if (!(*i)->visible ()) { -#ifdef CANVAS_DEBUG - if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { - cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << " [" << (*i)->name << "] invisible - skipped\n"; - } -#endif - continue; - } - - boost::optional<Rect> item_bbox = (*i)->bounding_box (); - - if (!item_bbox) { -#ifdef CANVAS_DEBUG - if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { - cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << " [" << (*i)->name << "] empty - skipped\n"; - } -#endif - continue; - } - - Rect item = (*i)->item_to_window (item_bbox.get()); - boost::optional<Rect> d = item.intersection (area); - - if (d) { - Rect draw = d.get(); - if (draw.width() && draw.height()) { -#ifdef CANVAS_DEBUG - if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { - if (dynamic_cast<Container*>(*i) == 0) { - cerr << _canvas->render_indent() << "render " - << ' ' - << (*i) - << ' ' - << (*i)->whatami() - << ' ' - << (*i)->name - << " item " - << item_bbox.get() - << " window = " - << item - << " intersect = " - << draw - << " @ " - << _position - << endl; - } - } -#endif - - (*i)->render (area, context); - ++render_count; - } - - } else { - -#ifdef CANVAS_DEBUG - if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) { - cerr << string_compose ("%1skip render of %2 %3, no intersection between %4 and %5\n", _canvas->render_indent(), (*i)->whatami(), - (*i)->name, item, area); - } -#endif - - } - } - - --render_depth; -} - diff --git a/libs/canvas/root_group.cc b/libs/canvas/root_group.cc index 015f52bb54..accbcb9b30 100644 --- a/libs/canvas/root_group.cc +++ b/libs/canvas/root_group.cc @@ -24,7 +24,7 @@ using namespace std; using namespace ArdourCanvas; Root::Root (Canvas* canvas) - : Layout (canvas) + : Container (canvas) { #ifdef CANVAS_DEBUG name = "ROOT"; @@ -34,7 +34,7 @@ Root::Root (Canvas* canvas) void Root::compute_bounding_box () const { - Layout::compute_bounding_box (); + Container::compute_bounding_box (); if (_bounding_box) { Rect r (_bounding_box.get()); diff --git a/libs/canvas/scroll_group.cc b/libs/canvas/scroll_group.cc index 15b607a564..df51df9ebb 100644 --- a/libs/canvas/scroll_group.cc +++ b/libs/canvas/scroll_group.cc @@ -28,13 +28,13 @@ using namespace std; using namespace ArdourCanvas; ScrollGroup::ScrollGroup (Canvas* c, ScrollSensitivity s) - : Layout (c) + : Container (c) , _scroll_sensitivity (s) { } ScrollGroup::ScrollGroup (Item* parent, ScrollSensitivity s) - : Layout (parent) + : Container (parent) , _scroll_sensitivity (s) { } @@ -61,7 +61,7 @@ ScrollGroup::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) c context->rectangle (self.x0, self.y0, self.width(), self.height()); context->clip (); - Layout::render (area, context); + Container::render (area, context); context->restore (); } diff --git a/libs/canvas/wscript b/libs/canvas/wscript index c6e31cafd6..88ffc93dca 100644 --- a/libs/canvas/wscript +++ b/libs/canvas/wscript @@ -39,7 +39,6 @@ canvas_sources = [ 'fill.cc', 'flag.cc', 'image.cc', - 'layout.cc', 'line.cc', 'line_set.cc', 'lookup_table.cc', |