render: Don't pass junction sides to builtin image

Instead, split the grip into 8 different builtin images (one for each
side and corner).
This commit is contained in:
Benjamin Otte 2015-01-19 04:40:24 +01:00
parent e6b228f12a
commit 118c887656
3 changed files with 68 additions and 46 deletions

View File

@ -413,12 +413,12 @@ add_path_line (cairo_t *cr,
}
void
gtk_css_image_builtin_draw_grip (GtkCssImage *image,
cairo_t *cr,
double width,
double height,
GtkJunctionSides sides,
const GdkRGBA *bg_color)
gtk_css_image_builtin_draw_grip (GtkCssImage *image,
cairo_t *cr,
double width,
double height,
GtkCssImageBuiltinType image_type,
const GdkRGBA *bg_color)
{
GdkRGBA lighter, darker;
@ -427,30 +427,20 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
color_shade (bg_color, 0.7, &darker);
color_shade (bg_color, 1.3, &lighter);
/* reduce confusing values to a meaningful state */
if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
if (sides == 0)
sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
/* align drawing area to the connected side */
if (sides == GTK_JUNCTION_LEFT)
if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT)
{
if (height < width)
width = height;
}
else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT)
{
if (width < height)
height = width;
else if (height < width)
width = height;
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT)
{
/* make it square, aligning to bottom left */
if (width < height)
@ -461,7 +451,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
else if (height < width)
width = height;
}
else if (sides == GTK_JUNCTION_RIGHT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT)
{
/* aligning to right */
if (height < width)
@ -470,7 +460,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
width = height;
}
}
else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT)
{
if (width < height)
height = width;
@ -480,7 +470,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
width = height;
}
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT)
{
/* make it square, aligning to bottom right */
if (width < height)
@ -494,12 +484,12 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
width = height;
}
}
else if (sides == GTK_JUNCTION_TOP)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOP)
{
if (width < height)
height = width;
}
else if (sides == GTK_JUNCTION_BOTTOM)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM)
{
/* align to bottom */
if (width < height)
@ -511,8 +501,8 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
else
g_assert_not_reached ();
if (sides == GTK_JUNCTION_LEFT ||
sides == GTK_JUNCTION_RIGHT)
if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT ||
image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT)
{
gint xi;
@ -531,8 +521,8 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
xi += 2;
}
}
else if (sides == GTK_JUNCTION_TOP ||
sides == GTK_JUNCTION_BOTTOM)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOP ||
image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM)
{
gint yi;
@ -551,7 +541,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
yi += 2;
}
}
else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT)
{
gint xi, yi;
@ -581,7 +571,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
yi -= 3;
}
}
else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT)
{
gint xi, yi;
@ -611,7 +601,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
yi -= 3;
}
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT)
{
gint xi, yi;
@ -641,7 +631,7 @@ gtk_css_image_builtin_draw_grip (GtkCssImage *image,
yi += 3;
}
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
else if (image_type == GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT)
{
gint xi, yi;
@ -845,7 +835,6 @@ gtk_css_image_builtin_draw (GtkCssImage *image,
double width,
double height,
GtkCssImageBuiltinType image_type,
GtkJunctionSides sides,
const GdkRGBA * fg_color,
const GdkRGBA * bg_color,
const GdkRGBA * border_color,
@ -931,10 +920,17 @@ gtk_css_image_builtin_draw (GtkCssImage *image,
FALSE, TRUE, TRUE,
fg_color, border_color);
break;
case GTK_CSS_IMAGE_BUILTIN_GRIP:
case GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT:
case GTK_CSS_IMAGE_BUILTIN_GRIP_TOP:
case GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT:
case GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT:
case GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT:
case GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM:
case GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT:
case GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT:
gtk_css_image_builtin_draw_grip (image, cr,
width, height,
sides,
image_type,
bg_color);
break;
case GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR:

View File

@ -42,7 +42,14 @@ typedef enum {
GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT_EXPANDED,
GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_RIGHT_EXPANDED,
GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_RIGHT_EXPANDED,
GTK_CSS_IMAGE_BUILTIN_GRIP,
GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT,
GTK_CSS_IMAGE_BUILTIN_GRIP_TOP,
GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT,
GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT,
GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT,
GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM,
GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT,
GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT,
GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR,
GTK_CSS_IMAGE_BUILTIN_HANDLE,
GTK_CSS_IMAGE_BUILTIN_SPINNER
@ -77,7 +84,6 @@ void gtk_css_image_builtin_draw (GtkCssImage
double width,
double height,
GtkCssImageBuiltinType image_type,
GtkJunctionSides sides,
const GdkRGBA *fg_color,
const GdkRGBA *bg_color,
const GdkRGBA *border_color,

View File

@ -134,7 +134,6 @@ gtk_do_render_check (GtkStyleContext *context,
cr,
width, height,
image_type,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
@ -232,7 +231,6 @@ gtk_do_render_option (GtkStyleContext *context,
cr,
width, height,
image_type,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
@ -320,7 +318,6 @@ gtk_do_render_arrow (GtkStyleContext *context,
cr,
size, size,
GTK_CSS_IMAGE_BUILTIN_ARROW,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
@ -521,7 +518,6 @@ gtk_do_render_expander (GtkStyleContext *context,
cr,
width, height,
image_type,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
@ -1105,17 +1101,42 @@ gtk_do_render_handle (GtkStyleContext *context,
cairo_translate (cr, x, y);
if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_GRIP))
type = GTK_CSS_IMAGE_BUILTIN_GRIP;
{
GtkJunctionSides sides = gtk_style_context_get_junction_sides (context);
/* order is important here for when too many (or too few) sides are set */
if ((sides & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT;
else if ((sides & GTK_JUNCTION_CORNER_TOPRIGHT) == GTK_JUNCTION_CORNER_TOPRIGHT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT;
else if ((sides & GTK_JUNCTION_CORNER_BOTTOMLEFT) == GTK_JUNCTION_CORNER_BOTTOMLEFT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT;
else if ((sides & GTK_JUNCTION_CORNER_TOPLEFT) == GTK_JUNCTION_CORNER_TOPLEFT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT;
else if (sides & GTK_JUNCTION_RIGHT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT;
else if (sides & GTK_JUNCTION_BOTTOM)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM;
else if (sides & GTK_JUNCTION_TOP)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOP;
else if (sides & GTK_JUNCTION_LEFT)
type = GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT;
else
type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT;
}
else if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR))
type = GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR;
{
type = GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR;
}
else
type = GTK_CSS_IMAGE_BUILTIN_HANDLE;
{
type = GTK_CSS_IMAGE_BUILTIN_HANDLE;
}
gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
cr,
width, height,
type,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
@ -1251,7 +1272,6 @@ gtk_do_render_activity (GtkStyleContext *context,
cr,
width, height,
GTK_CSS_IMAGE_BUILTIN_SPINNER,
gtk_style_context_get_junction_sides (context),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),