[gtk+/wip/otte/rendernode: 107/110] API: gdk: Add gdk_rgba_is_clear() and gdk_rgba_is_opaque()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/rendernode: 107/110] API: gdk: Add gdk_rgba_is_clear() and gdk_rgba_is_opaque()
- Date: Mon, 19 Dec 2016 04:53:12 +0000 (UTC)
commit a883e297d6162290f2f760eb832a6ad7976eb8b5
Author: Benjamin Otte <otte redhat com>
Date: Sun Dec 18 22:31:18 2016 +0100
API: gdk: Add gdk_rgba_is_clear() and gdk_rgba_is_opaque()
I want to use these inside GSK, and I'm not a fan of putting GdkRGBA
APIs into it or duplicating it into GTK.
So public API it is.
docs/reference/gdk/gdk4-sections.txt | 2 ++
gdk/gdkrgba.c | 34 ++++++++++++++++++++++++++++++++++
gdk/gdkrgba.h | 5 +++++
gtk/gtkcssshadowvalue.c | 10 +++++-----
gtk/gtkcsstypesprivate.h | 4 ----
gtk/gtkrenderbackground.c | 6 +++---
gtk/gtkwindow.c | 4 +---
7 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 7d3bd5f..4cc5040 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -222,6 +222,8 @@ gdk_pixbuf_get_from_surface
GdkRGBA
gdk_rgba_copy
gdk_rgba_free
+gdk_rgba_is_clear
+gdk_rgba_is_opaque
gdk_rgba_parse
gdk_rgba_equal
gdk_rgba_hash
diff --git a/gdk/gdkrgba.c b/gdk/gdkrgba.c
index 2a8e096..a073790 100644
--- a/gdk/gdkrgba.c
+++ b/gdk/gdkrgba.c
@@ -90,6 +90,40 @@ gdk_rgba_free (GdkRGBA *rgba)
g_slice_free (GdkRGBA, rgba);
}
+/**
+ * gdk_rgba_is_clear:
+ * @rgba: a #GdkRGBA
+ *
+ * Checks if an @rgba value is transparent. That is, drawing with the value
+ * would not produce any change.
+ *
+ * Returns: %TRUE if the @rgab is clear
+ *
+ * Since: 3.90
+ */
+gboolean
+gdk_rgba_is_clear (const GdkRGBA *rgba)
+{
+ return rgba->alpha < ((double) 0x00ff / (double) 0xffff);
+}
+
+/**
+ * gdk_rgba_is_opaque:
+ * @rgba: a #GdkRGBA
+ *
+ * Checks if an @rgba value is opaque. That is, drawing with the value
+ * will not retain any results from previous contents.
+ *
+ * Returns: %TRUE if the @rgab is opaque
+ *
+ * Since: 3.90
+ */
+gboolean
+gdk_rgba_is_opaque (const GdkRGBA *rgba)
+{
+ return rgba->alpha > ((double)0xff00 / (double)0xffff);
+}
+
#define SKIP_WHITESPACES(s) while (*(s) == ' ') (s)++;
/* Parses a single color component from a rgb() or rgba() specification
diff --git a/gdk/gdkrgba.h b/gdk/gdkrgba.h
index a37711a..3a9e85c 100644
--- a/gdk/gdkrgba.h
+++ b/gdk/gdkrgba.h
@@ -52,6 +52,11 @@ GdkRGBA * gdk_rgba_copy (const GdkRGBA *rgba);
GDK_AVAILABLE_IN_ALL
void gdk_rgba_free (GdkRGBA *rgba);
+GDK_AVAILABLE_IN_3_90
+gboolean gdk_rgba_is_clear (const GdkRGBA *rgba);
+GDK_AVAILABLE_IN_3_90
+gboolean gdk_rgba_is_opaque (const GdkRGBA *rgba);
+
GDK_AVAILABLE_IN_ALL
guint gdk_rgba_hash (gconstpointer p);
GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 86b3029..f68a39e 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -533,7 +533,7 @@ _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
/* We don't need to draw invisible shadows */
- if (gtk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
+ if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
return;
if (!cairo_has_current_point (cr))
@@ -579,7 +579,7 @@ _gtk_css_shadow_value_paint_icon (const GtkCssValue *shadow,
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
/* We don't need to draw invisible shadows */
- if (gtk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
+ if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
return;
cairo_save (cr);
@@ -898,7 +898,7 @@ _gtk_css_shadow_value_paint_box (const GtkCssValue *shadow,
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
/* We don't need to draw invisible shadows */
- if (gtk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
+ if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
return;
cairo_clip_extents (cr, &x1c, &y1c, &x2c, &y2c);
@@ -1034,7 +1034,7 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue *shadow,
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
/* We don't need to draw invisible shadows */
- if (gtk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
+ if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
return;
gtk_css_shadow_value_get_extents (shadow, &extents);
@@ -1060,7 +1060,7 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue *shadow,
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
/* We don't need to draw invisible shadows */
- if (gtk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
+ if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
return;
cr = gtk_snapshot_append_cairo_node (snapshot,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index b9a4fce..87582e5 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -370,10 +370,6 @@ char * gtk_css_change_to_string (GtkCssChange
void gtk_css_change_print (GtkCssChange change,
GString *string);
-/* for lack of better place to put it */
-/* mirror what cairo does */
-#define gtk_rgba_is_clear(rgba) ((rgba)->alpha < ((double)0x00ff / (double)0xffff))
-
G_END_DECLS
#endif /* __GTK_CSS_TYPES_PRIVATE_H__ */
diff --git a/gtk/gtkrenderbackground.c b/gtk/gtkrenderbackground.c
index 4beafb2..1e2a5e6 100644
--- a/gtk/gtkrenderbackground.c
+++ b/gtk/gtkrenderbackground.c
@@ -86,7 +86,7 @@ gtk_theming_background_snapshot_color (GtkThemingBackground *bg,
(gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BACKGROUND_CLIP),
n_values - 1));
- if (gtk_rgba_is_clear (bg_color))
+ if (gdk_rgba_is_clear (bg_color))
return;
if (gsk_rounded_rect_is_rectilinear (&bg->boxes[clip]))
@@ -587,7 +587,7 @@ gtk_css_style_render_background (GtkCssStyle *style,
box_shadow = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BOX_SHADOW);
/* This is the common default case of no background */
- if (gtk_rgba_is_clear (bg_color) &&
+ if (gdk_rgba_is_clear (bg_color) &&
_gtk_css_array_value_get_n_values (background_image) == 1 &&
_gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (background_image, 0)) == NULL &&
_gtk_css_shadows_value_is_none (box_shadow))
@@ -665,7 +665,7 @@ gtk_css_style_snapshot_background (GtkCssStyle *style,
box_shadow = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BOX_SHADOW);
/* This is the common default case of no background */
- if (gtk_rgba_is_clear (bg_color) &&
+ if (gdk_rgba_is_clear (bg_color) &&
_gtk_css_array_value_get_n_values (background_image) == 1 &&
_gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (background_image, 0)) == NULL &&
_gtk_css_shadows_value_is_none (box_shadow))
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index c6600c2..9bc51b3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6811,15 +6811,13 @@ update_opaque_region (GtkWindow *window,
cairo_region_t *opaque_region;
GtkStyleContext *context;
gboolean is_opaque = FALSE;
- const GdkRGBA *color;
if (!_gtk_widget_get_realized (widget))
return;
context = gtk_widget_get_style_context (widget);
- color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
- is_opaque = (color->alpha >= 1.0);
+ is_opaque = gdk_rgba_is_opaque (_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_BACKGROUND_COLOR)));
if (gtk_widget_get_opacity (widget) < 1.0)
is_opaque = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]