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"
25 #include "canvas/canvas.h"
26 #include "canvas/rectangle.h"
27 #include "canvas/debug.h"
28 #include "canvas/utils.h"
31 using namespace ArdourCanvas;
33 Rectangle::Rectangle (Group* parent)
37 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
42 Rectangle::Rectangle (Group* parent, Rect const & rect)
47 , _outline_what ((What) (LEFT | RIGHT | TOP | BOTTOM))
53 Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
55 Rect self = item_to_window (_rect);
56 boost::optional<Rect> r = self.intersection (area);
59 std::cerr << whatami() << '/' << name << " not covered by render area! ... " << self << " vs. " << area << std::endl;
67 setup_fill_context (context);
69 setup_gradient_context (context, self, Duple (draw.x0, draw.y0));
71 context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
77 setup_outline_context (context);
80 context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
83 if (_outline_what & LEFT) {
84 context->move_to (self.x0, self.y0);
85 context->line_to (self.x0, self.y1);
88 if (_outline_what & BOTTOM) {
89 context->move_to (self.x0, self.y1);
90 context->line_to (self.x1, self.y1);
93 if (_outline_what & RIGHT) {
94 context->move_to (self.x1, self.y0);
95 context->line_to (self.x1, self.y1);
98 if (_outline_what & TOP) {
99 context->move_to (self.x0, self.y0);
100 context->line_to (self.x1, self.y0);
109 Rectangle::compute_bounding_box () const
111 Rect r = _rect.fix ();
112 _bounding_box = boost::optional<Rect> (r.expand (_outline_width/2.0));
113 _bounding_box_dirty = false;
117 Rectangle::set (Rect const & r)
119 /* We don't update the bounding box here; it's just
120 as cheap to do it when asked.
127 _bounding_box_dirty = true;
130 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n");
134 Rectangle::set_x0 (Coord x0)
140 _bounding_box_dirty = true;
143 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n");
147 Rectangle::set_y0 (Coord y0)
153 _bounding_box_dirty = true;
156 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n");
160 Rectangle::set_x1 (Coord x1)
166 _bounding_box_dirty = true;
169 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n");
173 Rectangle::set_y1 (Coord y1)
179 _bounding_box_dirty = true;
182 DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n");
186 Rectangle::set_outline_what (What what)
190 _outline_what = what;
196 Rectangle::set_outline_what (int what)
198 set_outline_what ((What) what);