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());
48 /* special/common case: outline the entire rectangle is
49 * requested, so just use the same path for the fill
53 if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
54 context->fill_preserve();
55 setup_outline_context (context);
65 if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
67 /* if we filled and use full outline, we are already done */
70 context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
71 setup_outline_context (context);
77 if (_outline_what & LEFT) {
78 context->move_to (plot.x0, plot.y0);
79 context->line_to (plot.x0, plot.y1);
82 if (_outline_what & BOTTOM) {
83 context->move_to (plot.x0, plot.y1);
84 context->line_to (plot.x1, plot.y1);
87 if (_outline_what & RIGHT) {
88 context->move_to (plot.x1, plot.y0);
89 context->line_to (plot.x1, plot.y1);
92 if (_outline_what & TOP) {
93 context->move_to (plot.x0, plot.y0);
94 context->line_to (plot.x1, plot.y0);
97 setup_outline_context (context);
104 Rectangle::compute_bounding_box () const
106 Rect r = _rect.fix ();
107 _bounding_box = boost::optional<Rect> (r.expand (_outline_width / 2));
109 _bounding_box_dirty = false;
113 Rectangle::set (Rect const & r)
115 /* We don't update the bounding box here; it's just
116 as cheap to do it when asked.
123 _bounding_box_dirty = true;
126 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n");
130 Rectangle::set_x0 (Coord x0)
136 _bounding_box_dirty = true;
139 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n");
143 Rectangle::set_y0 (Coord y0)
149 _bounding_box_dirty = true;
152 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n");
156 Rectangle::set_x1 (Coord x1)
162 _bounding_box_dirty = true;
165 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n");
169 Rectangle::set_y1 (Coord y1)
175 _bounding_box_dirty = true;
178 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n");
182 Rectangle::set_outline_what (What what)
186 _outline_what = what;
192 Rectangle::set_outline_what (int what)
194 set_outline_what ((What) what);