rectangle: Fix the border drawing conditions

And reorganize the code a bit while we're at it.
This commit is contained in:
Emmanuele Bassi 2015-03-15 15:10:31 +00:00
parent 239280f855
commit ce2d86515a

View File

@ -92,10 +92,13 @@ clutter_rectangle_paint (ClutterActor *self)
: "unknown"); : "unknown");
clutter_actor_get_allocation_geometry (self, &geom); clutter_actor_get_allocation_geometry (self, &geom);
/* We paint the border if the rectangle is big enough to show it */ if (priv->has_border)
if (priv->has_border && {
priv->border_width < geom.width && /* We paint the border and the content only if the rectangle
priv->border_width < geom.height) * is big enough to show them
*/
if ((priv->border_width * 2) < geom.width &&
(priv->border_width * 2) < geom.height)
{ {
/* compute the composited opacity of the actor taking into /* compute the composited opacity of the actor taking into
* account the opacity of the color set by the user * account the opacity of the color set by the user
@ -142,6 +145,24 @@ clutter_rectangle_paint (ClutterActor *self)
geom.width - priv->border_width, geom.width - priv->border_width,
geom.height - priv->border_width); geom.height - priv->border_width);
} }
else
{
/* Otherwise, we draw a rectangle with the same color
* as the border, since we can only fit that into the
* allocation.
*/
tmp_alpha = clutter_actor_get_paint_opacity (self)
* priv->border_color.alpha
/ 255;
cogl_set_source_color4ub (priv->border_color.red,
priv->border_color.green,
priv->border_color.blue,
tmp_alpha);
cogl_rectangle (0, 0, geom.width, geom.height);
}
}
else else
{ {
/* compute the composited opacity of the actor taking into /* compute the composited opacity of the actor taking into
@ -151,24 +172,10 @@ clutter_rectangle_paint (ClutterActor *self)
* priv->color.alpha * priv->color.alpha
/ 255; / 255;
if (priv->border_width < geom.width &&
priv->border_width < geom.height)
{
cogl_set_source_color4ub (priv->color.red, cogl_set_source_color4ub (priv->color.red,
priv->color.green, priv->color.green,
priv->color.blue, priv->color.blue,
tmp_alpha); tmp_alpha);
}
else
{
/* If the rectangle is as big as the border, we
* use the border color to draw
*/
cogl_set_source_color4ub (priv->border_color.red,
priv->border_color.green,
priv->border_color.blue,
tmp_alpha);
}
cogl_rectangle (0, 0, geom.width, geom.height); cogl_rectangle (0, 0, geom.width, geom.height);
} }