}
/**
- * gtk_theming_engine_register_property:
+ * gtk_theming_engine_register_property: (skip)
* @name_space: namespace for the property name
* @parse_func: parsing function to use, or %NULL
* @pspec: the #GParamSpec for the new property
gint exterior_size, interior_size, pad, thickness, border_width;
GtkBorderStyle border_style;
GtkBorder *border;
- gdouble radius;
flags = gtk_theming_engine_get_state (engine);
- radius = MIN (width, height) / 2 - 0.5;
cairo_save (cr);
cairo_new_sub_path (cr);
cairo_arc (cr,
- x + exterior_size / 2.,
- y + exterior_size / 2.,
- (exterior_size - 1) / 2.,
- 0, 2 * G_PI);
+ x + exterior_size / 2.,
+ y + exterior_size / 2.,
+ (exterior_size - 1) / 2.,
+ 0, 2 * G_PI);
gdk_cairo_set_source_rgba (cr, bg_color);
cairo_fill_preserve (cr);
line_thickness = MAX (1, (3 + interior_size * 2) / 7);
cairo_rectangle (cr,
- x + pad,
- y + pad + (interior_size - line_thickness) / 2.,
- interior_size,
- line_thickness);
+ x + pad,
+ y + pad + (interior_size - line_thickness) / 2.,
+ interior_size,
+ line_thickness);
cairo_fill (cr);
}
if (flags & GTK_STATE_FLAG_ACTIVE)
interior_size = MAX (1, exterior_size - 2 * pad);
if (interior_size < 5)
- {
- interior_size = 7;
- pad = MAX (0, (exterior_size - interior_size) / 2);
- }
+ {
+ interior_size = 7;
+ pad = MAX (0, (exterior_size - interior_size) / 2);
+ }
cairo_new_sub_path (cr);
cairo_arc (cr,
- x + pad + interior_size / 2.,
- y + pad + interior_size / 2.,
- interior_size / 2.,
- 0, 2 * G_PI);
+ x + pad + interior_size / 2.,
+ y + pad + interior_size / 2.,
+ interior_size / 2.,
+ 0, 2 * G_PI);
cairo_fill (cr);
}
}
}
+/* Set the appropriate matrix for
+ * patterns coming from the style context
+ */
+static void
+style_pattern_set_matrix (cairo_pattern_t *pattern,
+ gdouble width,
+ gdouble height)
+{
+ cairo_matrix_t matrix;
+ gint w, h;
+
+ if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SURFACE)
+ {
+ cairo_surface_t *surface;
+
+ cairo_pattern_get_surface (pattern, &surface);
+ w = cairo_image_surface_get_width (surface);
+ h = cairo_image_surface_get_height (surface);
+ }
+ else
+ w = h = 1;
+
+ cairo_matrix_init_scale (&matrix, (gdouble) w / width, (gdouble) h / height);
+ cairo_pattern_set_matrix (pattern, &matrix);
+}
+
static void
render_background_internal (GtkThemingEngine *engine,
cairo_t *cr,
GtkStateFlags flags;
gboolean running;
gdouble progress, alpha = 1;
- gint radius;
+ GtkBorder *border;
+ gint radius, border_width;
+ GtkBorderStyle border_style;
+ gdouble mat_w, mat_h;
+ cairo_matrix_t identity;
+
+ /* Use unmodified size for pattern scaling */
+ mat_w = width;
+ mat_h = height;
flags = gtk_theming_engine_get_state (engine);
- cairo_save (cr);
+
+ cairo_matrix_init_identity (&identity);
gtk_theming_engine_get (engine, flags,
"background-image", &pattern,
"background-color", &bg_color,
"border-radius", &radius,
+ "border-width", &border,
+ "border-style", &border_style,
NULL);
+ border_width = MIN (MIN (border->top, border->bottom),
+ MIN (border->left, border->right));
+
+ if (border_width > 1 &&
+ border_style == GTK_BORDER_STYLE_NONE)
+ {
+ cairo_set_line_width (cr, border_width);
+
+ x += (gdouble) border_width / 2;
+ y += (gdouble) border_width / 2;
+ width -= border_width;
+ height -= border_width;
+ }
+ else
+ {
+ x += border->left;
+ y += border->top;
+ width -= border->left + border->right;
+ height -= border->top + border->bottom;
+ }
+
+ if (width <= 0 || height <= 0)
+ return;
+
+ cairo_save (cr);
+ cairo_translate (cr, x, y);
+
running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
- _cairo_round_rectangle_sides (cr, (gdouble) radius,
- x, y, width, height,
- SIDE_ALL, junction);
- cairo_clip (cr);
if (gtk_theming_engine_has_class (engine, "background"))
{
cairo_paint (cr);
}
- cairo_translate (cr, x, y);
- cairo_scale (cr, width, height);
-
if (running)
{
cairo_pattern_t *other_pattern;
/* Different pattern types, or different color
* stop counts, alpha blend both patterns.
*/
- cairo_rectangle (cr, 0, 0, 1, 1);
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
+
+ style_pattern_set_matrix (other_pattern, mat_w, mat_h);
cairo_set_source (cr, other_pattern);
cairo_fill_preserve (cr);
+ cairo_pattern_set_matrix (other_pattern, &identity);
+
/* Set alpha for posterior drawing
* of the target pattern
*/
gdk_rgba_free (other_bg);
}
- cairo_rectangle (cr, 0, 0, 1, 1);
-
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
if (pattern)
{
+ style_pattern_set_matrix (pattern, mat_w, mat_h);
cairo_set_source (cr, pattern);
- cairo_pattern_destroy (pattern);
}
else
gdk_cairo_set_source_rgba (cr, bg_color);
if (alpha == 1)
- cairo_fill (cr);
+ {
+ if (border_width > 1 &&
+ border_style != GTK_BORDER_STYLE_NONE)
+ {
+ /* stroke with the same source, so the background
+ * has exactly the shape than the frame, this
+ * is important so gtk_render_background() and
+ * gtk_render_frame() fit perfectly with round
+ * borders.
+ */
+ cairo_fill_preserve (cr);
+ cairo_stroke (cr);
+ }
+ else
+ cairo_fill (cr);
+ }
else
{
- cairo_pattern_t *mask;
+ cairo_save (cr);
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ 0, 0, width, height,
+ SIDE_ALL, junction);
+ cairo_clip (cr);
+
+ cairo_paint_with_alpha (cr, alpha);
- mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
- cairo_mask (cr, mask);
- cairo_pattern_destroy (mask);
+ cairo_restore (cr);
+ }
+
+ if (pattern)
+ {
+ cairo_pattern_set_matrix (pattern, &identity);
+ cairo_pattern_destroy (pattern);
}
cairo_restore (cr);
gdk_rgba_free (bg_color);
+ gtk_border_free (border);
}
static void
gdouble height)
{
GtkJunctionSides junction;
- GtkStateFlags flags;
- GtkBorder *border;
junction = gtk_theming_engine_get_junction_sides (engine);
- flags = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get (engine, flags,
- "border-width", &border,
- NULL);
-
- x += border->left;
- y += border->top;
- width -= border->left + border->right;
- height -= border->top + border->bottom;
-
render_background_internal (engine, cr,
x, y, width, height,
junction);
-
- gtk_border_free (border);
}
/* Renders the small triangle on corners so
const PangoMatrix *matrix;
GdkRGBA *fg_color;
GtkStateFlags flags;
- GdkScreen *screen;
gdouble progress;
gboolean running;
"color", &fg_color,
NULL);
- screen = gtk_theming_engine_get_screen (engine);
matrix = pango_context_get_matrix (pango_layout_get_context (layout));
running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
if (matrix)
{
cairo_matrix_t cairo_matrix;
- PangoMatrix tmp_matrix;
PangoRectangle rect;
cairo_matrix_init (&cairo_matrix,
pango_matrix_transform_rectangle (matrix, &rect);
pango_extents_to_pixels (&rect, NULL);
- tmp_matrix = *matrix;
cairo_matrix.x0 += x - rect.x;
cairo_matrix.y0 += y - rect.y;
if (flags & GTK_STATE_FLAG_INSENSITIVE)
{
+ GdkRGBA bg;
+
+ gtk_theming_engine_get_background_color (engine, flags, &bg);
+
cairo_save (cr);
- cairo_set_source_rgb (cr, 1, 1, 1);
+
+ gdk_cairo_set_source_rgba (cr, &bg);
+
cairo_move_to (cr, x + 1, y + 1);
_gtk_pango_fill_layout (cr, layout);
cairo_restore (cr);
GtkStateFlags flags;
GdkRGBA *bg_color;
GdkRGBA lighter, darker;
+ GtkJunctionSides sides;
gint xx, yy;
cairo_save (cr);
flags = gtk_theming_engine_get_state (engine);
- cairo_set_line_width (cr, 1);
+ cairo_set_line_width (cr, 1.0);
+ sides = gtk_theming_engine_get_junction_sides (engine);
gtk_theming_engine_get (engine, flags,
"background-color", &bg_color,
color_shade (bg_color, 0.7, &darker);
color_shade (bg_color, 1.3, &lighter);
- gdk_cairo_set_source_rgba (cr, bg_color);
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
+ render_background_internal (engine, cr, x, y, width, height, sides);
if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
{
- GtkJunctionSides sides;
- gint skip = -1;
-
- cairo_save (cr);
-
- cairo_set_line_width (cr, 1.0);
- sides = gtk_theming_engine_get_junction_sides (engine);
-
/* 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;
height = width;
else if (height < width)
width = height;
-
- skip = 2;
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
{
}
else if (height < width)
width = height;
-
- skip = 1;
}
else if (sides == GTK_JUNCTION_RIGHT)
{
x += (width - height);
width = height;
}
-
- skip = 3;
}
else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
{
x += (width - height);
width = height;
}
-
- skip = 0;
}
else if (sides == GTK_JUNCTION_TOP)
{
gdk_cairo_set_source_rgba (cr, &darker);
add_path_line (cr, x, yi, x + width, yi);
cairo_stroke (cr);
- yi+= 2;
+ yi += 2;
}
}
else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
yi += 3;
}
}
-
- cairo_restore (cr);
}
else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
{
else
{
for (yy = y; yy < y + height; yy += 3)
- for (xx = x; xx < x + width; xx += 6)
- {
- render_dot (cr, &lighter, &darker, xx, yy, 2);
- render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
- }
+ for (xx = x; xx < x + width; xx += 6)
+ {
+ render_dot (cr, &lighter, &darker, xx, yy, 2);
+ render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
+ }
}
cairo_restore (cr);
GtkStateFlags state;
guint num_steps, step;
GdkRGBA *color;
- gdouble dx, dy;
gdouble progress;
gdouble radius;
gdouble half;
cairo_save (cr);
- cairo_translate (cr, x, y);
-
- /* draw clip region */
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_line_width (cr, 2.0);
+ cairo_translate (cr, x + width / 2, y + height / 2);
- dx = width / 2;
- dy = height / 2;
radius = MIN (width / 2, height / 2);
half = num_steps / 2;
gint inset = 0.7 * radius;
/* transparency is a function of time and intial value */
- gdouble t = (gdouble) ((i + num_steps - step)
- % num_steps) / num_steps;
-
- cairo_save (cr);
+ gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
+ gdouble xscale = - sin (i * G_PI / half);
+ gdouble yscale = - cos (i * G_PI / half);
cairo_set_source_rgba (cr,
color->red,
color->blue,
color->alpha * t);
- cairo_set_line_width (cr, 2.0);
cairo_move_to (cr,
- dx + (radius - inset) * cos (i * G_PI / half),
- dy + (radius - inset) * sin (i * G_PI / half));
+ (radius - inset) * xscale,
+ (radius - inset) * yscale);
cairo_line_to (cr,
- dx + radius * cos (i * G_PI / half),
- dy + radius * sin (i * G_PI / half));
+ radius * xscale,
+ radius * yscale);
cairo_stroke (cr);
-
- cairo_restore (cr);
}
cairo_restore (cr);