remove all xml++.h inclusion by canvas implementations
[ardour.git] / libs / canvas / line.cc
1 #include <algorithm>
2 #include <cairomm/context.h>
3 #include "pbd/compose.h"
4 #include "canvas/line.h"
5 #include "canvas/types.h"
6 #include "canvas/debug.h"
7 #include "canvas/utils.h"
8
9 using namespace std;
10 using namespace ArdourCanvas;
11
12 Line::Line (Group* parent)
13         : Item (parent)
14         , Outline (parent)
15 {
16
17 }
18
19 void
20 Line::compute_bounding_box () const
21 {
22         Rect bbox;
23         
24         bbox.x0 = min (_points[0].x, _points[1].x);
25         bbox.y0 = min (_points[0].y, _points[1].y);
26         bbox.x1 = max (_points[0].x, _points[1].x);
27         bbox.y1 = max (_points[0].y, _points[1].y);
28
29         bbox = bbox.expand (_outline_width / 2);
30
31         _bounding_box = bbox;
32         _bounding_box_dirty = false;
33 }
34
35 void
36 Line::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
37 {
38         setup_outline_context (context);
39
40         Duple plot[2] = {
41                 Duple (min (_points[0].x, CAIRO_MAX), min (_points[0].y, CAIRO_MAX)),
42                 Duple (min (_points[1].x, CAIRO_MAX), min (_points[1].y, CAIRO_MAX))
43         };
44
45         context->move_to (plot[0].x, plot[0].y);
46         context->line_to (plot[1].x, plot[1].y);
47         context->stroke ();
48 }
49
50 void
51 Line::set (Duple a, Duple b)
52 {
53         begin_change ();
54
55         _points[0] = a;
56         _points[1] = b;
57
58         _bounding_box_dirty = true;
59         end_change ();
60
61         DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
62 }
63
64 void
65 Line::set_x0 (Coord x0)
66 {
67         begin_change ();
68         
69         _points[0].x = x0;
70
71         _bounding_box_dirty = true;
72         end_change ();
73
74         DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
75 }
76
77 void
78 Line::set_y0 (Coord y0)
79 {
80         begin_change ();
81
82         _points[0].y = y0;
83
84         _bounding_box_dirty = true;
85         end_change ();
86
87         DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
88 }
89
90 void
91 Line::set_x1 (Coord x1)
92 {
93         begin_change ();
94
95         _points[1].x = x1;
96
97         _bounding_box_dirty = true;
98         end_change ();
99
100         DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
101 }
102
103 void
104 Line::set_y1 (Coord y1)
105 {
106         begin_change ();
107
108         _points[1].y = y1;
109
110         _bounding_box_dirty = true;
111         end_change ();
112
113         DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
114 }