2 #include <cairomm/context.h>
3 #include "pbd/stacktrace.h"
5 #include "pbd/compose.h"
6 #include "canvas/rectangle.h"
7 #include "canvas/debug.h"
8 #include "canvas/utils.h"
11 using namespace ArdourCanvas;
13 Rectangle::Rectangle (Group* parent)
17 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
22 Rectangle::Rectangle (Group* parent, Rect const & rect)
27 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
33 Rectangle::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
37 plot.x1 = min (plot.x1, CAIRO_MAX);
38 plot.y1 = min (plot.y1, CAIRO_MAX);
41 setup_fill_context (context);
42 context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
47 if (_outline_what & LEFT) {
48 context->move_to (plot.x0, plot.y0);
49 context->line_to (plot.x0, plot.y1);
52 if (_outline_what & BOTTOM) {
53 context->move_to (plot.x0, plot.y1);
54 context->line_to (plot.x1, plot.y1);
57 if (_outline_what & RIGHT) {
58 context->move_to (plot.x1, plot.y0);
59 context->line_to (plot.x1, plot.y1);
62 if (_outline_what & TOP) {
63 context->move_to (plot.x0, plot.y0);
64 context->line_to (plot.x0, plot.y1);
67 setup_outline_context (context);
73 Rectangle::compute_bounding_box () const
75 Rect r = _rect.fix ();
76 _bounding_box = boost::optional<Rect> (r.expand (_outline_width / 2));
78 _bounding_box_dirty = false;
82 Rectangle::set (Rect const & r)
84 /* We don't update the bounding box here; it's just
85 as cheap to do it when asked.
92 _bounding_box_dirty = true;
95 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n");
99 Rectangle::set_x0 (Coord x0)
105 _bounding_box_dirty = true;
108 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n");
112 Rectangle::set_y0 (Coord y0)
118 _bounding_box_dirty = true;
121 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n");
125 Rectangle::set_x1 (Coord x1)
131 _bounding_box_dirty = true;
134 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n");
138 Rectangle::set_y1 (Coord y1)
144 _bounding_box_dirty = true;
147 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n");
151 Rectangle::set_outline_what (What what)
155 _outline_what = what;
161 Rectangle::set_outline_what (int what)
163 set_outline_what ((What) what);
167 Rectangle::get_state () const
169 XMLNode* node = new XMLNode ("Rectangle");
171 if (!name.empty ()) {
172 node->add_property ("name", name);
175 node->add_property ("x0", string_compose ("%1", _rect.x0));
176 node->add_property ("y0", string_compose ("%1", _rect.y0));
177 node->add_property ("x1", string_compose ("%1", _rect.x1));
178 node->add_property ("y1", string_compose ("%1", _rect.y1));
179 node->add_property ("outline-what", string_compose ("%1", _outline_what));
181 add_item_state (node);
182 add_outline_state (node);
183 add_fill_state (node);
188 Rectangle::set_state (XMLNode const * node)
190 _rect.x0 = atof (node->property("x0")->value().c_str());
191 _rect.y0 = atof (node->property("y0")->value().c_str());
192 _rect.x1 = atof (node->property("x1")->value().c_str());
193 _rect.y1 = atof (node->property("y1")->value().c_str());
194 _outline_what = (What) atoi (node->property("outline-what")->value().c_str());
196 set_item_state (node);
197 set_outline_state (node);
198 set_fill_state (node);
200 _bounding_box_dirty = true;