summaryrefslogtreecommitdiff
path: root/libs/canvas/line.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/line.cc
parent1d8bac08c0c00d44e22c581768a275e1b21a99a7 (diff)
initial commit of hand merging, plus getting "ancient" waf script to work correctly
Diffstat (limited to 'libs/canvas/line.cc')
-rw-r--r--libs/canvas/line.cc148
1 files changed, 148 insertions, 0 deletions
diff --git a/libs/canvas/line.cc b/libs/canvas/line.cc
new file mode 100644
index 0000000000..6c3a62e5dc
--- /dev/null
+++ b/libs/canvas/line.cc
@@ -0,0 +1,148 @@
+#include <algorithm>
+#include <cairomm/context.h>
+#include "pbd/xml++.h"
+#include "pbd/compose.h"
+#include "canvas/line.h"
+#include "canvas/types.h"
+#include "canvas/debug.h"
+#include "canvas/utils.h"
+
+using namespace std;
+using namespace ArdourCanvas;
+
+Line::Line (Group* parent)
+ : Item (parent)
+ , Outline (parent)
+{
+
+}
+
+void
+Line::compute_bounding_box () const
+{
+ Rect bbox;
+
+ bbox.x0 = min (_points[0].x, _points[1].x);
+ bbox.y0 = min (_points[0].y, _points[1].y);
+ bbox.x1 = max (_points[0].x, _points[1].x);
+ bbox.y1 = max (_points[0].y, _points[1].y);
+
+ bbox = bbox.expand (_outline_width / 2);
+
+ _bounding_box = bbox;
+ _bounding_box_dirty = false;
+}
+
+void
+Line::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
+{
+ setup_outline_context (context);
+
+ Duple plot[2] = {
+ Duple (min (_points[0].x, CAIRO_MAX), min (_points[0].y, CAIRO_MAX)),
+ Duple (min (_points[1].x, CAIRO_MAX), min (_points[1].y, CAIRO_MAX))
+ };
+
+ context->move_to (plot[0].x, plot[0].y);
+ context->line_to (plot[1].x, plot[1].y);
+ context->stroke ();
+}
+
+void
+Line::set (Duple a, Duple b)
+{
+ begin_change ();
+
+ _points[0] = a;
+ _points[1] = b;
+
+ _bounding_box_dirty = true;
+ end_change ();
+
+ DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
+}
+
+void
+Line::set_x0 (Coord x0)
+{
+ begin_change ();
+
+ _points[0].x = x0;
+
+ _bounding_box_dirty = true;
+ end_change ();
+
+ DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
+}
+
+void
+Line::set_y0 (Coord y0)
+{
+ begin_change ();
+
+ _points[0].y = y0;
+
+ _bounding_box_dirty = true;
+ end_change ();
+
+ DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
+}
+
+void
+Line::set_x1 (Coord x1)
+{
+ begin_change ();
+
+ _points[1].x = x1;
+
+ _bounding_box_dirty = true;
+ end_change ();
+
+ DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
+}
+
+void
+Line::set_y1 (Coord y1)
+{
+ begin_change ();
+
+ _points[1].y = y1;
+
+ _bounding_box_dirty = true;
+ end_change ();
+
+ DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
+}
+
+XMLNode *
+Line::get_state () const
+{
+ XMLNode* node = new XMLNode ("Line");
+#ifdef CANVAS_DEBUG
+ if (!name.empty ()) {
+ node->add_property ("name", name);
+ }
+#endif
+ node->add_property ("x0", string_compose ("%1", _points[0].x));
+ node->add_property ("y0", string_compose ("%1", _points[0].y));
+ node->add_property ("x1", string_compose ("%1", _points[1].x));
+ node->add_property ("y1", string_compose ("%1", _points[1].y));
+
+ add_item_state (node);
+ add_outline_state (node);
+ return node;
+}
+
+void
+Line::set_state (XMLNode const * node)
+{
+ _points[0].x = atof (node->property("x0")->value().c_str());
+ _points[0].y = atof (node->property("y0")->value().c_str());
+ _points[1].x = atof (node->property("x1")->value().c_str());
+ _points[1].y = atof (node->property("y1")->value().c_str());
+
+ set_item_state (node);
+ set_outline_state (node);
+
+ _bounding_box_dirty = true;
+}