render: Split out icon-effect apply function
This commit is contained in:
@ -923,6 +923,39 @@ _gtk_css_icon_effect_value_get (const GtkCssValue *value)
|
|||||||
return value->value;
|
return value->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_css_icon_effect_apply (GtkCssIconEffect icon_effect,
|
||||||
|
cairo_surface_t *surface)
|
||||||
|
{
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
|
switch (icon_effect)
|
||||||
|
{
|
||||||
|
case GTK_CSS_ICON_EFFECT_DIM:
|
||||||
|
cr = cairo_create (surface);
|
||||||
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_set_source_rgba (cr, 0, 0, 0, 0); /* transparent */
|
||||||
|
cairo_paint_with_alpha (cr, 0.5);
|
||||||
|
cairo_destroy (cr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
|
||||||
|
cr = cairo_create (surface);
|
||||||
|
cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
|
||||||
|
cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
|
||||||
|
/* DANGER: We mask with ourself - that works for images, but... */
|
||||||
|
cairo_mask_surface (cr, surface, 0, 0);
|
||||||
|
cairo_destroy (cr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_warn_if_reached ();
|
||||||
|
/* fall through */
|
||||||
|
case GTK_CSS_ICON_EFFECT_NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* GtkCssIconStyle */
|
/* GtkCssIconStyle */
|
||||||
|
|
||||||
static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
|
static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
|
||||||
|
@ -79,6 +79,8 @@ GtkCssFillMode _gtk_css_fill_mode_value_get (const GtkCssValue *value)
|
|||||||
GtkCssValue * _gtk_css_icon_effect_value_new (GtkCssIconEffect image_effect);
|
GtkCssValue * _gtk_css_icon_effect_value_new (GtkCssIconEffect image_effect);
|
||||||
GtkCssValue * _gtk_css_icon_effect_value_try_parse (GtkCssParser *parser);
|
GtkCssValue * _gtk_css_icon_effect_value_try_parse (GtkCssParser *parser);
|
||||||
GtkCssIconEffect _gtk_css_icon_effect_value_get (const GtkCssValue *value);
|
GtkCssIconEffect _gtk_css_icon_effect_value_get (const GtkCssValue *value);
|
||||||
|
void gtk_css_icon_effect_apply (GtkCssIconEffect icon_effect,
|
||||||
|
cairo_surface_t *surface);
|
||||||
|
|
||||||
GtkCssValue * _gtk_css_icon_style_value_new (GtkCssIconStyle icon_style);
|
GtkCssValue * _gtk_css_icon_style_value_new (GtkCssIconStyle icon_style);
|
||||||
GtkCssValue * _gtk_css_icon_style_value_try_parse (GtkCssParser *parser);
|
GtkCssValue * _gtk_css_icon_style_value_try_parse (GtkCssParser *parser);
|
||||||
|
@ -1031,26 +1031,6 @@ gtk_render_activity (GtkStyleContext *context,
|
|||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
colorshift_source (cairo_t *cr,
|
|
||||||
gdouble shift)
|
|
||||||
{
|
|
||||||
cairo_pattern_t *source;
|
|
||||||
|
|
||||||
cairo_save (cr);
|
|
||||||
cairo_paint (cr);
|
|
||||||
|
|
||||||
source = cairo_pattern_reference (cairo_get_source (cr));
|
|
||||||
|
|
||||||
cairo_set_source_rgb (cr, shift, shift, shift);
|
|
||||||
cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
|
|
||||||
|
|
||||||
cairo_mask (cr, source);
|
|
||||||
|
|
||||||
cairo_pattern_destroy (source);
|
|
||||||
cairo_restore (cr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
scale_or_ref (GdkPixbuf *src,
|
scale_or_ref (GdkPixbuf *src,
|
||||||
gint width,
|
gint width,
|
||||||
@ -1066,19 +1046,18 @@ scale_or_ref (GdkPixbuf *src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
gtk_do_render_icon_pixbuf (GtkStyleContext *context,
|
gtk_render_icon_pixbuf_for_style (GtkCssStyle *style,
|
||||||
const GtkIconSource *source,
|
const GtkIconSource *source,
|
||||||
GtkIconSize size)
|
GtkIconSize size)
|
||||||
{
|
{
|
||||||
GdkPixbuf *scaled;
|
GdkPixbuf *scaled;
|
||||||
GdkPixbuf *stated;
|
GdkPixbuf *stated;
|
||||||
GdkPixbuf *base_pixbuf;
|
GdkPixbuf *base_pixbuf;
|
||||||
gint width = 1;
|
gint width = 1;
|
||||||
gint height = 1;
|
gint height = 1;
|
||||||
cairo_t *cr;
|
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
gboolean wildcarded;
|
gboolean wildcarded;
|
||||||
GtkCssIconEffect image_effect;
|
GtkCssIconEffect icon_effect;
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||||
base_pixbuf = gtk_icon_source_get_pixbuf (source);
|
base_pixbuf = gtk_icon_source_get_pixbuf (source);
|
||||||
@ -1112,52 +1091,20 @@ gtk_do_render_icon_pixbuf (GtkStyleContext *context,
|
|||||||
if (!wildcarded)
|
if (!wildcarded)
|
||||||
return scaled;
|
return scaled;
|
||||||
|
|
||||||
image_effect = _gtk_css_icon_effect_value_get
|
icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
|
||||||
(_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
|
|
||||||
|
|
||||||
switch (image_effect)
|
if (icon_effect != GTK_CSS_ICON_EFFECT_NONE)
|
||||||
{
|
{
|
||||||
case GTK_CSS_ICON_EFFECT_DIM:
|
surface = gdk_cairo_surface_create_from_pixbuf (scaled, 1, NULL);
|
||||||
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
gtk_css_icon_effect_apply (icon_effect, surface);
|
||||||
gdk_pixbuf_get_width (scaled),
|
|
||||||
gdk_pixbuf_get_height (scaled));
|
|
||||||
cr = cairo_create (surface);
|
|
||||||
gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
|
|
||||||
cairo_paint_with_alpha (cr, 0.5);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
g_object_unref (scaled);
|
|
||||||
stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
|
stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
|
||||||
cairo_image_surface_get_width (surface),
|
cairo_image_surface_get_width (surface),
|
||||||
cairo_image_surface_get_height (surface));
|
cairo_image_surface_get_height (surface));
|
||||||
cairo_surface_destroy (surface);
|
cairo_surface_destroy (surface);
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
|
{
|
||||||
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
||||||
gdk_pixbuf_get_width (scaled),
|
|
||||||
gdk_pixbuf_get_height (scaled));
|
|
||||||
|
|
||||||
cr = cairo_create (surface);
|
|
||||||
gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
|
|
||||||
colorshift_source (cr, 0.10);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
g_object_unref (scaled);
|
|
||||||
stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
|
|
||||||
cairo_image_surface_get_width (surface),
|
|
||||||
cairo_image_surface_get_height (surface));
|
|
||||||
cairo_surface_destroy (surface);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_warn_if_reached ();
|
|
||||||
/* fall through */
|
|
||||||
case GTK_CSS_ICON_EFFECT_NONE:
|
|
||||||
stated = scaled;
|
stated = scaled;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stated;
|
return stated;
|
||||||
@ -1188,7 +1135,7 @@ gtk_render_icon_pixbuf (GtkStyleContext *context,
|
|||||||
g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL);
|
g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL);
|
||||||
g_return_val_if_fail (source != NULL, NULL);
|
g_return_val_if_fail (source != NULL, NULL);
|
||||||
|
|
||||||
return gtk_do_render_icon_pixbuf (context, source, size);
|
return gtk_render_icon_pixbuf_for_style (gtk_style_context_lookup_style (context), source, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,11 +22,11 @@
|
|||||||
#include <pango/pango.h>
|
#include <pango/pango.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
void gtk_render_content_path (GtkStyleContext *context,
|
void gtk_render_content_path (GtkStyleContext *context,
|
||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
double width,
|
double width,
|
||||||
double height);
|
double height);
|
||||||
|
|
||||||
#endif /* __GTK_RENDER_PRIVATE_H__ */
|
#endif /* __GTK_RENDER_PRIVATE_H__ */
|
||||||
|
Reference in New Issue
Block a user