summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-04-05 11:27:26 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-04-05 11:27:26 -0400
commit07a505b1b271f64a1ffb2da32da0548d32cd13de (patch)
tree82b5d1ac8a5e825791fbfcc5789f6fa0aba290ae /libs
parent7db5d68cdb1c7b6138907cb732e913ec91212e13 (diff)
lots of tweaking and adding debug output including operator<</dump(ostream&) methods to help visualize canvas structure
Diffstat (limited to 'libs')
-rw-r--r--libs/canvas/canvas.cc37
-rw-r--r--libs/canvas/canvas/canvas.h10
-rw-r--r--libs/canvas/canvas/debug.h1
-rw-r--r--libs/canvas/canvas/group.h2
-rw-r--r--libs/canvas/canvas/item.h28
-rw-r--r--libs/canvas/canvas/poly_item.h2
-rw-r--r--libs/canvas/debug.cc1
-rw-r--r--libs/canvas/group.cc32
-rw-r--r--libs/canvas/item.cc45
-rw-r--r--libs/canvas/poly_item.cc15
-rw-r--r--libs/canvas/root_group.cc1
-rw-r--r--libs/canvas/types.cc4
12 files changed, 167 insertions, 11 deletions
diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc
index 828d277b2f..0fced89bc4 100644
--- a/libs/canvas/canvas.cc
+++ b/libs/canvas/canvas.cc
@@ -24,8 +24,11 @@
#include <cassert>
#include <gtkmm/adjustment.h>
+
#include "pbd/xml++.h"
#include "pbd/compose.h"
+#include "pbd/stacktrace.h"
+
#include "canvas/canvas.h"
#include "canvas/debug.h"
@@ -74,6 +77,10 @@ Canvas::Canvas (XMLTree const * tree)
void
Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context) const
{
+ // cerr << "CANVAS @ " << this << endl;
+ // dump (cerr);
+ // cerr << "-------------------------\n";
+
checkpoint ("render", "-> render");
render_count = 0;
@@ -86,6 +93,7 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
boost::optional<Rect> root_bbox = _root.bounding_box();
if (!root_bbox) {
/* the root has no bounding box, so there's nothing to render */
+ checkpoint ("render", "no root bbox");
context->restore ();
return;
}
@@ -95,6 +103,7 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
/* there's a common area between the root and the requested
area, so render it.
*/
+ checkpoint ("render", "... root");
_root.render (*draw, context);
}
@@ -108,6 +117,32 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
checkpoint ("render", "<- render");
}
+ostream&
+operator<< (ostream& o, Canvas& c)
+{
+ c.dump (o);
+ return o;
+}
+
+std::string
+Canvas::indent() const
+{
+ string s;
+
+ for (int n = 0; n < ArdourCanvas::dump_depth; ++n) {
+ s += '\t';
+ }
+
+ return s;
+}
+
+void
+Canvas::dump (ostream& o) const
+{
+ dump_depth = 0;
+ _root.dump (o);
+}
+
/** Called when an item has been shown or hidden.
* @param item Item that has been shown or hidden.
*/
@@ -485,7 +520,7 @@ GtkCanvas::request_size (Duple size)
if (req.y > INT_MAX) {
req.y = INT_MAX;
}
-
+
set_size_request (req.x, req.y);
}
diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h
index a4e76bf3f8..8c23ef6852 100644
--- a/libs/canvas/canvas/canvas.h
+++ b/libs/canvas/canvas/canvas.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2011 Paul Davis
+ Copyright (C) 2011-2013 Paul Davis
Author: Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
@@ -15,7 +15,6 @@
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.
-
*/
/** @file canvas/canvas.h
@@ -92,6 +91,9 @@ public:
_log_renders = log;
}
+ std::string indent() const;
+ void dump (std::ostream&) const;
+
protected:
void queue_draw_item_area (Item *, Rect);
@@ -148,7 +150,7 @@ public:
void ungrab ();
Cairo::RefPtr<Cairo::Context> context ();
-
+
protected:
bool on_expose_event (GdkEventExpose *);
bool on_button_press_event (GdkEventButton *);
@@ -195,4 +197,6 @@ private:
}
+std::ostream& operator<< (std::ostream&, const ArdourCanvas::Canvas&);
+
#endif
diff --git a/libs/canvas/canvas/debug.h b/libs/canvas/canvas/debug.h
index ac5f4763ad..c9350d6630 100644
--- a/libs/canvas/canvas/debug.h
+++ b/libs/canvas/canvas/debug.h
@@ -25,6 +25,7 @@ namespace ArdourCanvas {
extern void checkpoint (std::string, std::string);
extern void set_epoch ();
extern int render_count;
+ extern int dump_depth;
}
#endif
diff --git a/libs/canvas/canvas/group.h b/libs/canvas/canvas/group.h
index 6a9d59b2b5..89d566b6ed 100644
--- a/libs/canvas/canvas/group.h
+++ b/libs/canvas/canvas/group.h
@@ -34,6 +34,8 @@ public:
void add_items_at_point (Duple, std::vector<Item const *> &) const;
+ void dump (std::ostream&) const;
+
static int default_items_per_cell;
protected:
diff --git a/libs/canvas/canvas/item.h b/libs/canvas/canvas/item.h
index 7898fb2bc8..a440573731 100644
--- a/libs/canvas/canvas/item.h
+++ b/libs/canvas/canvas/item.h
@@ -1,3 +1,22 @@
+/*
+ Copyright (C) 2011-2013 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_ITEM_H__
#define __CANVAS_ITEM_H__
@@ -148,8 +167,10 @@ public:
#ifdef CANVAS_COMPATIBILITY
void grab_focus ();
#endif
-
-
+
+ virtual void dump (std::ostream&) const;
+ std::string whatami() const;
+
protected:
void begin_change ();
@@ -179,6 +200,9 @@ private:
bool _ignore_events;
};
+extern std::ostream& operator<< (std::ostream&, const ArdourCanvas::Item&);
+
}
+
#endif
diff --git a/libs/canvas/canvas/poly_item.h b/libs/canvas/canvas/poly_item.h
index 11b649cfb8..de5e5cf188 100644
--- a/libs/canvas/canvas/poly_item.h
+++ b/libs/canvas/canvas/poly_item.h
@@ -19,6 +19,8 @@ public:
void set (Points const &);
Points const & get () const;
+ void dump (std::ostream&) const;
+
protected:
void render_path (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
diff --git a/libs/canvas/debug.cc b/libs/canvas/debug.cc
index 18ff40f8f7..1d947a8866 100644
--- a/libs/canvas/debug.cc
+++ b/libs/canvas/debug.cc
@@ -11,6 +11,7 @@ uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
struct timeval ArdourCanvas::epoch;
map<string, struct timeval> ArdourCanvas::last_time;
int ArdourCanvas::render_count;
+int ArdourCanvas::dump_depth;
void
ArdourCanvas::set_epoch ()
diff --git a/libs/canvas/group.cc b/libs/canvas/group.cc
index adb4b206a8..7d0d61308f 100644
--- a/libs/canvas/group.cc
+++ b/libs/canvas/group.cc
@@ -2,16 +2,20 @@
#include <cairomm/context.h>
#include "pbd/stacktrace.h"
#include "pbd/xml++.h"
+
#include "canvas/group.h"
#include "canvas/types.h"
#include "canvas/debug.h"
#include "canvas/item_factory.h"
+#include "canvas/item.h"
+#include "canvas/canvas.h"
using namespace std;
using namespace ArdourCanvas;
int Group::default_items_per_cell = 64;
+
Group::Group (Canvas* canvas)
: Item (canvas)
, _lut (0)
@@ -52,11 +56,13 @@ Group::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
vector<Item*> items = _lut->get (area);
for (vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
+
if (!(*i)->visible ()) {
continue;
}
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
+
if (!item_bbox) {
continue;
}
@@ -230,3 +236,29 @@ Group::set_state (XMLNode const * node)
create_item (this, *i);
}
}
+
+void
+Group::dump (ostream& o) const
+{
+ o << _canvas->indent();
+ o << "Group " << this;
+ o << " Items: " << _items.size();
+
+ boost::optional<Rect> bb = bounding_box();
+
+ if (bb) {
+ o << endl << _canvas->indent() << " bbox: " << bb.get();
+ } else {
+ o << " bbox unset";
+ }
+
+ o << endl;
+
+ ArdourCanvas::dump_depth++;
+
+ for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
+ o << **i;
+ }
+
+ ArdourCanvas::dump_depth--;
+}
diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc
index 570eff9f14..340c503fe7 100644
--- a/libs/canvas/item.cc
+++ b/libs/canvas/item.cc
@@ -195,15 +195,24 @@ Item::bounding_box () const
Coord
Item::height () const
{
- boost::optional<Rect> bb = bounding_box().get();
- return bb->height ();
+ boost::optional<Rect> bb = bounding_box();
+
+ if (bb) {
+ return bb->height ();
+ }
+ return 0;
}
Coord
Item::width () const
{
boost::optional<Rect> bb = bounding_box().get();
- return bb->width ();
+
+ if (bb) {
+ return bb->width ();
+ }
+
+ return 0;
}
/* XXX may be called even if bbox is not changing ... bit grotty */
@@ -325,3 +334,33 @@ Item::set_ignore_events (bool ignore)
{
_ignore_events = ignore;
}
+
+void
+Item::dump (ostream& o) const
+{
+ boost::optional<Rect> bb = bounding_box();
+
+ o << _canvas->indent() << whatami() << ' ' << this;
+
+ if (bb) {
+ o << endl << _canvas->indent() << "\tbbox: " << bb.get();
+ } else {
+ o << "bbox unset";
+ }
+
+ o << endl;
+}
+
+std::string
+Item::whatami () const
+{
+ std::string type = demangle (typeid (*this).name());
+ return type.substr (type.find_last_of (':') + 1);
+}
+
+ostream&
+ArdourCanvas::operator<< (ostream& o, const Item& i)
+{
+ i.dump (o);
+ return o;
+}
diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc
index 1fb2c6c8b8..e43d48fa8d 100644
--- a/libs/canvas/poly_item.cc
+++ b/libs/canvas/poly_item.cc
@@ -1,7 +1,10 @@
#include <algorithm>
+
#include "pbd/xml++.h"
#include "pbd/compose.h"
+
#include "canvas/poly_item.h"
+#include "canvas/canvas.h"
using namespace std;
using namespace ArdourCanvas;
@@ -33,6 +36,7 @@ PolyItem::compute_bounding_box () const
}
}
+
if (!have_one) {
_bounding_box = boost::optional<Rect> ();
} else {
@@ -99,3 +103,14 @@ PolyItem::set_poly_item_state (XMLNode const * node)
_bounding_box_dirty = true;
}
+
+void
+PolyItem::dump (ostream& o) const
+{
+ Item::dump (o);
+
+ o << _canvas->indent() << _points.size() << " points" << endl;
+ for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
+ o << i->x << ", " << i->y << endl;
+ }
+}
diff --git a/libs/canvas/root_group.cc b/libs/canvas/root_group.cc
index a9e0aae77f..b8637d9988 100644
--- a/libs/canvas/root_group.cc
+++ b/libs/canvas/root_group.cc
@@ -18,6 +18,7 @@ RootGroup::compute_bounding_box () const
Group::compute_bounding_box ();
if (_bounding_box) {
+ cerr << "!!!!! requesting canvas size " << _bounding_box.get() << endl;
_canvas->request_size (Duple (_bounding_box.get().width (), _bounding_box.get().height ()));
}
}
diff --git a/libs/canvas/types.cc b/libs/canvas/types.cc
index 56312741cf..8d7fbf1c27 100644
--- a/libs/canvas/types.cc
+++ b/libs/canvas/types.cc
@@ -13,7 +13,7 @@ Coord const ArdourCanvas::CAIRO_MAX = 65536;
static inline Coord
safe_add (Coord a, Coord b)
{
- if (((COORD_MAX - a) > b) || ((COORD_MAX - b) > a)) {
+ if (((COORD_MAX - a) <= b) || ((COORD_MAX - b) <= a)) {
return COORD_MAX;
}
@@ -135,7 +135,7 @@ ArdourCanvas::operator<< (ostream & s, Duple const & r)
ostream &
ArdourCanvas::operator<< (ostream & s, Rect const & r)
{
- s << "[(" << r.x0 << ", " << r.y0 << "), (" << r.x1 << ", " << r.y1 << ")]";
+ s << "[(" << r.x0 << ", " << r.y0 << "), (" << r.x1 << ", " << r.y1 << ") " << r.width() << " x " << r.height() << "]";
return s;
}