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