2 #include <cairomm/context.h>
4 #include "pbd/compose.h"
5 #include "canvas/line.h"
6 #include "canvas/types.h"
7 #include "canvas/debug.h"
8 #include "canvas/utils.h"
11 using namespace ArdourCanvas;
13 Line::Line (Group* parent)
21 Line::compute_bounding_box () const
25 bbox.x0 = min (_points[0].x, _points[1].x);
26 bbox.y0 = min (_points[0].y, _points[1].y);
27 bbox.x1 = max (_points[0].x, _points[1].x);
28 bbox.y1 = max (_points[0].y, _points[1].y);
30 bbox = bbox.expand (_outline_width / 2);
33 _bounding_box_dirty = false;
37 Line::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
39 setup_outline_context (context);
42 Duple (min (_points[0].x, CAIRO_MAX), min (_points[0].y, CAIRO_MAX)),
43 Duple (min (_points[1].x, CAIRO_MAX), min (_points[1].y, CAIRO_MAX))
46 context->move_to (plot[0].x, plot[0].y);
47 context->line_to (plot[1].x, plot[1].y);
52 Line::set (Duple a, Duple b)
59 _bounding_box_dirty = true;
62 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
66 Line::set_x0 (Coord x0)
72 _bounding_box_dirty = true;
75 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
79 Line::set_y0 (Coord y0)
85 _bounding_box_dirty = true;
88 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
92 Line::set_x1 (Coord x1)
98 _bounding_box_dirty = true;
101 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
105 Line::set_y1 (Coord y1)
111 _bounding_box_dirty = true;
114 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
118 Line::get_state () const
120 XMLNode* node = new XMLNode ("Line");
122 if (!name.empty ()) {
123 node->add_property ("name", name);
126 node->add_property ("x0", string_compose ("%1", _points[0].x));
127 node->add_property ("y0", string_compose ("%1", _points[0].y));
128 node->add_property ("x1", string_compose ("%1", _points[1].x));
129 node->add_property ("y1", string_compose ("%1", _points[1].y));
131 add_item_state (node);
132 add_outline_state (node);
137 Line::set_state (XMLNode const * node)
139 _points[0].x = atof (node->property("x0")->value().c_str());
140 _points[0].y = atof (node->property("y0")->value().c_str());
141 _points[1].x = atof (node->property("x1")->value().c_str());
142 _points[1].y = atof (node->property("y1")->value().c_str());
144 set_item_state (node);
145 set_outline_state (node);
147 _bounding_box_dirty = true;