2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <cairomm/context.h>
22 #include "pbd/stacktrace.h"
23 #include "pbd/compose.h"
24 #include "canvas/rectangle.h"
25 #include "canvas/debug.h"
26 #include "canvas/utils.h"
29 using namespace ArdourCanvas;
31 Rectangle::Rectangle (Group* parent)
35 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
40 Rectangle::Rectangle (Group* parent, Rect const & rect)
45 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
51 Rectangle::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
55 plot.x1 = min (plot.x1, CAIRO_MAX);
56 plot.y1 = min (plot.y1, CAIRO_MAX);
59 setup_fill_context (context);
60 context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
66 /* special/common case: outline the entire rectangle is
67 * requested, so just use the same path for the fill
71 if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
72 context->fill_preserve();
73 setup_outline_context (context);
83 if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
85 /* if we filled and use full outline, we are already done */
88 context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
89 setup_outline_context (context);
95 if (_outline_what & LEFT) {
96 context->move_to (plot.x0, plot.y0);
97 context->line_to (plot.x0, plot.y1);
100 if (_outline_what & BOTTOM) {
101 context->move_to (plot.x0, plot.y1);
102 context->line_to (plot.x1, plot.y1);
105 if (_outline_what & RIGHT) {
106 context->move_to (plot.x1, plot.y0);
107 context->line_to (plot.x1, plot.y1);
110 if (_outline_what & TOP) {
111 context->move_to (plot.x0, plot.y0);
112 context->line_to (plot.x1, plot.y0);
115 setup_outline_context (context);
122 Rectangle::compute_bounding_box () const
124 Rect r = _rect.fix ();
125 _bounding_box = boost::optional<Rect> (r.expand (_outline_width / 2));
127 _bounding_box_dirty = false;
131 Rectangle::set (Rect const & r)
133 /* We don't update the bounding box here; it's just
134 as cheap to do it when asked.
141 _bounding_box_dirty = true;
144 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n");
148 Rectangle::set_x0 (Coord x0)
154 _bounding_box_dirty = true;
157 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n");
161 Rectangle::set_y0 (Coord y0)
167 _bounding_box_dirty = true;
170 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n");
174 Rectangle::set_x1 (Coord x1)
180 _bounding_box_dirty = true;
183 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n");
187 Rectangle::set_y1 (Coord y1)
193 _bounding_box_dirty = true;
196 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n");
200 Rectangle::set_outline_what (What what)
204 _outline_what = what;
210 Rectangle::set_outline_what (int what)
212 set_outline_what ((What) what);