void
Rectangle::render_self (Rect const & area, Cairo::RefPtr<Cairo::Context> context, Rect self) const
{
- boost::optional<Rect> r = self.intersection (area);
-
+ Rect r = self.intersection (area);
+
if (!r) {
return;
}
- Rect draw = r.get ();
+ Rect draw = r;
if (_fill && !_transparent) {
if (_stops.empty()) {
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
context->fill ();
- }
-
- if (_outline) {
+ }
+
+ if (_outline && _outline_width && _outline_what) {
setup_outline_context (context);
-
+
/* the goal here is that if the border is 1 pixel
* thick, it will precisely align with the corner
* coordinates of the rectangle. So if the rectangle
* to be colored are actually "at" 0.5 and 10.5 (midway
* between the integer coordinates).
*
- * See the Cairo FAQ on single pixel lines for more
+ * See the Cairo FAQ on single pixel lines for more
* detail.
*/
const double shift = _outline_width * 0.5;
self = self.translate (Duple (shift, shift));
}
-
+
if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
-
+
context->rectangle (self.x0, self.y0, self.width(), self.height());
} else {
context->move_to (self.x0, self.y0);
context->line_to (self.x0, self.y1);
}
-
+
if (_outline_what & TOP) {
context->move_to (self.x0, self.y0);
context->line_to (self.x1, self.y0);
context->move_to (self.x0, self.y1);
context->line_to (self.x1, self.y1);
}
-
+
if (_outline_what & RIGHT) {
context->move_to (self.x1, self.y0);
context->line_to (self.x1, self.y1);
}
}
-
+
context->stroke ();
}
}
bounding box is 1.0 pixels outside the stated
corners of the rectangle (so that the middle
of the 2 pixel wide border passes through
- the corners, alternatively described as 1 row
+ the corners, alternatively described as 1 row
of pixels outside of the corners, and 1 row
inside).
*/
if (r != _rect) {
-
+
begin_change ();
-
+
_rect = r;
-
+
_bounding_box_dirty = true;
end_change ();
}
{
if (x0 != _rect.x0) {
begin_change ();
-
+
_rect.x0 = x0;
-
+
_bounding_box_dirty = true;
end_change ();
}
{
if (y0 != _rect.y0) {
begin_change ();
-
+
_rect.y0 = y0;
-
+
_bounding_box_dirty = true;
end_change();
}
{
if (x1 != _rect.x1) {
begin_change ();
-
+
_rect.x1 = x1;
-
+
_bounding_box_dirty = true;
end_change ();
}
{
if (y1 != _rect.y1) {
begin_change ();
-
+
_rect.y1 = y1;
-
+
_bounding_box_dirty = true;
end_change ();
}
/* y is in canvas coordinates */
Duple i (canvas_to_item (Duple (0, y)));
- boost::optional<Rect> r = bounding_box();
+ Rect r = bounding_box();
if (!r) {
return 0; /* not really correct, but what else can we do? */
}
- Rect bbox (r.get());
+ Rect bbox (r);
if (i.y < bbox.y0 || i.y >= bbox.y1) {
return 0;
}
- return (i.y - bbox.y0) / bbox.height();
+ /* convert to fit Cairo origin model (origin at upper left)
+ */
+
+ return 1.0 - ((i.y - bbox.y0) / bbox.height());
}