From f0933bf00551ce998ca441aa5611d27702f6e590 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 22 Jun 2014 09:53:14 -0400 Subject: add missing new files for canvas redesign --- libs/canvas/canvas/container.h | 56 +++++++++++++++++ libs/canvas/canvas/layout.h | 43 ++++++++++++++ libs/canvas/container.cc | 47 +++++++++++++++ libs/canvas/layout.cc | 132 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 libs/canvas/canvas/container.h create mode 100644 libs/canvas/canvas/layout.h create mode 100644 libs/canvas/container.cc create mode 100644 libs/canvas/layout.cc diff --git a/libs/canvas/canvas/container.h b/libs/canvas/canvas/container.h new file mode 100644 index 0000000000..be80b37376 --- /dev/null +++ b/libs/canvas/canvas/container.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2011-2014 Paul Davis + Original Author: Carl Hetherington + + 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_CONTAINER_H__ +#define __CANVAS_CONTAINER_H__ + +#include "canvas/item.h" + +namespace ArdourCanvas +{ + +/** a Container is an item which has no content of its own + * but renders its children in some geometrical arrangement. + * + * Imagined examples of containers: + * + * Layout: 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 + * + * Other? + */ +class LIBCANVAS_API Container : public Item +{ +public: + Container (Canvas *); + Container (Item *); + Container (Item *, Duple const & position); + + /** The compute_bounding_box() method is likely to be identical + * in all containers (the union of the children's bounding boxes). + * It can be overriden as necessary. + */ + + void compute_bounding_box () const; +}; + +} + +#endif diff --git a/libs/canvas/canvas/layout.h b/libs/canvas/canvas/layout.h new file mode 100644 index 0000000000..8b82b0f635 --- /dev/null +++ b/libs/canvas/canvas/layout.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2011-2014 Paul Davis + Original Author: Carl Hetherington + + 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 context) const; +}; + +} + +#endif diff --git a/libs/canvas/container.cc b/libs/canvas/container.cc new file mode 100644 index 0000000000..4190437e6b --- /dev/null +++ b/libs/canvas/container.cc @@ -0,0 +1,47 @@ +/* + Copyright (C) 2011-2014 Paul Davis + Author: Carl Hetherington + + 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 "canvas/container.h" + +using namespace ArdourCanvas; + +Container::Container (Canvas* canvas) + : Item (canvas) +{ +} + +Container::Container (Item* parent) + : Item (parent) +{ +} + + +Container::Container (Item* parent, Duple const & p) + : Item (parent, p) +{ +} + +void +Container::compute_bounding_box () const +{ + _bounding_box = boost::none; + add_child_bounding_boxes (); + _bounding_box_dirty = false; +} + diff --git a/libs/canvas/layout.cc b/libs/canvas/layout.cc new file mode 100644 index 0000000000..ca9f50d05e --- /dev/null +++ b/libs/canvas/layout.cc @@ -0,0 +1,132 @@ +/* + Copyright (C) 2011-2014 Paul Davis + Author: Carl Hetherington + + 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 context) const +{ + ensure_lut (); + std::vector 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::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 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 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(*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; +} + -- cgit v1.2.3