[gtk+/gtk-style-context: 285/490] GtkSymbolicColor: Add gtk_symbolic_color_new_alpha()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 285/490] GtkSymbolicColor: Add gtk_symbolic_color_new_alpha()
- Date: Wed, 24 Nov 2010 14:03:38 +0000 (UTC)
commit 634b9a7ff216156c66c0a286e3979f845f321659
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Oct 25 20:41:36 2010 +0200
GtkSymbolicColor: Add gtk_symbolic_color_new_alpha()
This function modifies the alpha channel of a color, multiplying
it by a factor.
gtk/gtksymboliccolor.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-
gtk/gtksymboliccolor.h | 2 +
2 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index 92d3eff..f45c8d2 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -32,6 +32,7 @@ typedef enum {
COLOR_TYPE_LITERAL,
COLOR_TYPE_NAME,
COLOR_TYPE_SHADE,
+ COLOR_TYPE_ALPHA,
COLOR_TYPE_MIX
} ColorType;
@@ -49,7 +50,7 @@ struct _GtkSymbolicColor
{
GtkSymbolicColor *color;
gdouble factor;
- } shade;
+ } shade, alpha;
struct
{
@@ -166,6 +167,37 @@ gtk_symbolic_color_new_shade (GtkSymbolicColor *color,
}
/**
+ * gtk_symbolic_color_new_alpha:
+ * @color: another #GtkSymbolicColor
+ * @factor: factor to apply to @color alpha
+ *
+ * Creates a symbolic color by modifying the relative alpha
+ * value of @color. A factor < 1.0 would resolve to a more
+ * transparent color, while > 1.0 would resolve to a more
+ * opaque color.
+ *
+ * Returns: A newly created #GtkSymbolicColor
+ *
+ * Since: 3.0
+ **/
+GtkSymbolicColor *
+gtk_symbolic_color_new_alpha (GtkSymbolicColor *color,
+ gdouble factor)
+{
+ GtkSymbolicColor *symbolic_color;
+
+ g_return_val_if_fail (color != NULL, NULL);
+
+ symbolic_color = g_slice_new0 (GtkSymbolicColor);
+ symbolic_color->type = COLOR_TYPE_ALPHA;
+ symbolic_color->alpha.color = gtk_symbolic_color_ref (color);
+ symbolic_color->alpha.factor = CLAMP (factor, 0, 1);
+ symbolic_color->ref_count = 1;
+
+ return symbolic_color;
+}
+
+/**
* gtk_symbolic_color_new_mix:
* @color1: color to mix
* @color2: another color to mix
@@ -245,6 +277,9 @@ gtk_symbolic_color_unref (GtkSymbolicColor *color)
case COLOR_TYPE_SHADE:
gtk_symbolic_color_unref (color->shade.color);
break;
+ case COLOR_TYPE_ALPHA:
+ gtk_symbolic_color_unref (color->alpha.color);
+ break;
case COLOR_TYPE_MIX:
gtk_symbolic_color_unref (color->mix.color1);
gtk_symbolic_color_unref (color->mix.color2);
@@ -315,6 +350,18 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
}
break;
+ case COLOR_TYPE_ALPHA:
+ {
+ GdkRGBA alpha;
+
+ if (!gtk_symbolic_color_resolve (color->alpha.color, style_set, &alpha))
+ return FALSE;
+
+ *resolved_color = alpha;
+ resolved_color->alpha = CLAMP (alpha.alpha * color->alpha.factor, 0, 1);
+
+ return TRUE;
+ }
case COLOR_TYPE_MIX:
{
GdkRGBA color1, color2;
diff --git a/gtk/gtksymboliccolor.h b/gtk/gtksymboliccolor.h
index ce1d3c6..d52a9d3 100644
--- a/gtk/gtksymboliccolor.h
+++ b/gtk/gtksymboliccolor.h
@@ -38,6 +38,8 @@ GtkSymbolicColor * gtk_symbolic_color_new_literal (GdkRGBA *color);
GtkSymbolicColor * gtk_symbolic_color_new_name (const gchar *name);
GtkSymbolicColor * gtk_symbolic_color_new_shade (GtkSymbolicColor *color,
gdouble factor);
+GtkSymbolicColor * gtk_symbolic_color_new_alpha (GtkSymbolicColor *color,
+ gdouble factor);
GtkSymbolicColor * gtk_symbolic_color_new_mix (GtkSymbolicColor *color1,
GtkSymbolicColor *color2,
gdouble factor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]