summaryrefslogtreecommitdiff
path: root/libs/canvas/poly_item.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-04-04 00:32:52 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-04-04 00:32:52 -0400
commitaaea166135ace01709f7e0be64f40be80f4107ec (patch)
tree0e794ef7a723e4aaf909b841a6816e405b4ceca1 /libs/canvas/poly_item.cc
parent1d8bac08c0c00d44e22c581768a275e1b21a99a7 (diff)
initial commit of hand merging, plus getting "ancient" waf script to work correctly
Diffstat (limited to 'libs/canvas/poly_item.cc')
-rw-r--r--libs/canvas/poly_item.cc101
1 files changed, 101 insertions, 0 deletions
diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc
new file mode 100644
index 0000000000..1fb2c6c8b8
--- /dev/null
+++ b/libs/canvas/poly_item.cc
@@ -0,0 +1,101 @@
+#include <algorithm>
+#include "pbd/xml++.h"
+#include "pbd/compose.h"
+#include "canvas/poly_item.h"
+
+using namespace std;
+using namespace ArdourCanvas;
+
+PolyItem::PolyItem (Group* parent)
+ : Item (parent)
+ , Outline (parent)
+{
+
+}
+
+void
+PolyItem::compute_bounding_box () const
+{
+ bool have_one = false;
+
+ Rect bbox;
+
+ for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
+ if (have_one) {
+ bbox.x0 = min (bbox.x0, i->x);
+ bbox.y0 = min (bbox.y0, i->y);
+ bbox.x1 = max (bbox.x1, i->x);
+ bbox.y1 = max (bbox.y1, i->y);
+ } else {
+ bbox.x0 = bbox.x1 = i->x;
+ bbox.y0 = bbox.y1 = i->y;
+ have_one = true;
+ }
+ }
+
+ if (!have_one) {
+ _bounding_box = boost::optional<Rect> ();
+ } else {
+ _bounding_box = bbox.expand (_outline_width / 2);
+ }
+
+ _bounding_box_dirty = false;
+}
+
+void
+PolyItem::render_path (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
+{
+ bool done_first = false;
+ for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
+ if (done_first) {
+ context->line_to (i->x, i->y);
+ } else {
+ context->move_to (i->x, i->y);
+ done_first = true;
+ }
+ }
+}
+
+void
+PolyItem::set (Points const & points)
+{
+ begin_change ();
+
+ _points = points;
+
+ _bounding_box_dirty = true;
+ end_change ();
+}
+
+Points const &
+PolyItem::get () const
+{
+ return _points;
+}
+
+void
+PolyItem::add_poly_item_state (XMLNode* node) const
+{
+ add_item_state (node);
+
+ for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
+ XMLNode* p = new XMLNode ("Point");
+ p->add_property ("x", string_compose ("%1", i->x));
+ p->add_property ("y", string_compose ("%1", i->y));
+ node->add_child_nocopy (*p);
+ }
+}
+
+void
+PolyItem::set_poly_item_state (XMLNode const * node)
+{
+ XMLNodeList const & children = node->children ();
+ for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
+ Duple p;
+ p.x = atof ((*i)->property("x")->value().c_str());
+ p.y = atof ((*i)->property("y")->value().c_str());
+ _points.push_back (p);
+ }
+
+ _bounding_box_dirty = true;
+}