summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-12-16 02:15:20 +0100
committerBenjamin Otte <otte@redhat.com>2015-12-16 04:46:22 +0100
commitd3cf3fd267d676f6c4081d45f4eed74ef7732447 (patch)
tree76009091c81d0b75fec827b3d46b3018b77b6995
parent152326bd24432e0e56aaaf6aa769025ea9b2de54 (diff)
downloadgtk+-d3cf3fd267d676f6c4081d45f4eed74ef7732447.tar.gz
rendericon: Move a function
The function is identical if used for builtin icons and regular icons (as per iconhelper). So split it out in a way that doesn't assume either.
-rw-r--r--gtk/gtkrendericon.c74
-rw-r--r--gtk/gtkrendericonprivate.h7
-rw-r--r--gtk/gtkstylecontext.c77
3 files changed, 93 insertions, 65 deletions
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index 411050a6b5..2c756a4929 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -27,6 +27,8 @@
#include "gtkcssstyleprivate.h"
#include "gtkcsstransformvalueprivate.h"
+#include <math.h>
+
void
gtk_css_style_render_icon (GtkCssStyle *style,
cairo_t *cr,
@@ -144,3 +146,75 @@ gtk_css_style_render_icon_surface (GtkCssStyle *style,
cairo_set_matrix (cr, &saved_matrix);
}
+static void
+gtk_cairo_rectangle_transform (cairo_rectangle_int_t *dest,
+ const cairo_rectangle_int_t *src,
+ const cairo_matrix_t *matrix)
+{
+ double x1, x2, x3, x4;
+ double y1, y2, y3, y4;
+
+ g_return_if_fail (dest != NULL);
+ g_return_if_fail (src != NULL);
+ g_return_if_fail (matrix != NULL);
+
+ x1 = src->x;
+ y1 = src->y;
+ x2 = src->x + src->width;
+ y2 = src->y;
+ x3 = src->x + src->width;
+ y3 = src->y + src->height;
+ x4 = src->x;
+ y4 = src->y + src->height;
+
+ cairo_matrix_transform_point (matrix, &x1, &y1);
+ cairo_matrix_transform_point (matrix, &x2, &y2);
+ cairo_matrix_transform_point (matrix, &x3, &y3);
+ cairo_matrix_transform_point (matrix, &x4, &y4);
+
+ dest->x = floor (MIN (MIN (x1, x2), MIN (x3, x4)));
+ dest->y = floor (MIN (MIN (y1, y2), MIN (y3, y4)));
+ dest->width = ceil (MAX (MAX (x1, x2), MAX (x3, x4))) - dest->x;
+ dest->height = ceil (MAX (MAX (y1, y2), MAX (y3, y4))) - dest->y;
+}
+
+void
+gtk_css_style_render_icon_get_extents (GtkCssStyle *style,
+ GdkRectangle *extents,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ cairo_matrix_t transform_matrix, matrix;
+ GtkBorder border;
+ GdkRectangle rect;
+
+ g_return_if_fail (GTK_IS_CSS_STYLE (style));
+ g_return_if_fail (extents != NULL);
+
+ extents->x = x;
+ extents->y = y;
+ extents->width = width;
+ extents->height = height;
+
+ if (!_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
+ return;
+
+ cairo_matrix_init_translate (&matrix, x + width / 2.0, y + height / 2.0);
+ cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
+ /* need to round to full pixels */
+ rect.x = - (width + 1) / 2;
+ rect.y = - (height + 1) / 2;
+ rect.width = (width + 1) & ~1;
+ rect.height = (height + 1) & ~1;
+ gtk_cairo_rectangle_transform (extents, &rect, &matrix);
+
+ _gtk_css_shadows_value_get_extents (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW), &border);
+
+ extents->x -= border.left;
+ extents->y -= border.top;
+ extents->width += border.left + border.right;
+ extents->height += border.top + border.bottom;
+}
+
diff --git a/gtk/gtkrendericonprivate.h b/gtk/gtkrendericonprivate.h
index a92735a96a..f627655f2a 100644
--- a/gtk/gtkrendericonprivate.h
+++ b/gtk/gtkrendericonprivate.h
@@ -42,6 +42,13 @@ void gtk_css_style_render_icon_surface (GtkCssStyle *style,
double x,
double y);
+void gtk_css_style_render_icon_get_extents (GtkCssStyle *style,
+ GdkRectangle *extents,
+ gint x,
+ gint y,
+ gint width,
+ gint height);
+
G_END_DECLS
#endif /* __GTK_RENDER_ICON_PRIVATE_H__ */
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 65ebe68697..7fe5f3cf8a 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -17,12 +17,13 @@
#include "config.h"
+#include "gtkstylecontextprivate.h"
+
#include <gdk/gdk.h>
#include <math.h>
#include <stdlib.h>
#include <gobject/gvaluecollector.h>
-#include "gtkstylecontextprivate.h"
#include "gtkcontainerprivate.h"
#include "gtkcssanimatedstyleprivate.h"
#include "gtkcsscolorvalueprivate.h"
@@ -41,16 +42,17 @@
#include "gtkcsstransientnodeprivate.h"
#include "gtkcsswidgetnodeprivate.h"
#include "gtkdebug.h"
-#include "gtktypebuiltins.h"
#include "gtkintl.h"
-#include "gtkwindow.h"
#include "gtkprivate.h"
-#include "gtkwidgetpath.h"
-#include "gtkwidgetprivate.h"
-#include "gtkstylecascadeprivate.h"
-#include "gtkstyleproviderprivate.h"
+#include "gtkrendericonprivate.h"
#include "gtksettings.h"
#include "gtksettingsprivate.h"
+#include "gtkstylecascadeprivate.h"
+#include "gtkstyleproviderprivate.h"
+#include "gtktypebuiltins.h"
+#include "gtkwindow.h"
+#include "gtkwidgetpath.h"
+#include "gtkwidgetprivate.h"
#include "deprecated/gtkgradientprivate.h"
#include "deprecated/gtksymboliccolorprivate.h"
@@ -3033,37 +3035,6 @@ gtk_style_context_get_change (GtkStyleContext *context)
return context->priv->invalidating_context;
}
-static void
-gtk_cairo_rectangle_transform (cairo_rectangle_int_t *dest,
- const cairo_rectangle_int_t *src,
- const cairo_matrix_t *matrix)
-{
- double x1, x2, x3, x4;
- double y1, y2, y3, y4;
-
- g_return_if_fail (dest != NULL);
- g_return_if_fail (src != NULL);
- g_return_if_fail (matrix != NULL);
-
- x1 = src->x;
- y1 = src->y;
- x2 = src->x + src->width;
- y2 = src->y;
- x3 = src->x + src->width;
- y3 = src->y + src->height;
- x4 = src->x;
- y4 = src->y + src->height;
-
- cairo_matrix_transform_point (matrix, &x1, &y1);
- cairo_matrix_transform_point (matrix, &x2, &y2);
- cairo_matrix_transform_point (matrix, &x3, &y3);
- cairo_matrix_transform_point (matrix, &x4, &y4);
-
- dest->x = floor (MIN (MIN (x1, x2), MIN (x3, x4)));
- dest->y = floor (MIN (MIN (y1, y2), MIN (y3, y4)));
- dest->width = ceil (MAX (MAX (x1, x2), MAX (x3, x4))) - dest->x;
- dest->height = ceil (MAX (MAX (y1, y2), MAX (y3, y4))) - dest->y;
-}
void
_gtk_style_context_get_icon_extents (GtkStyleContext *context,
GdkRectangle *extents,
@@ -3072,10 +3043,6 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
gint width,
gint height)
{
- cairo_matrix_t transform_matrix, matrix;
- GtkBorder border;
- GdkRectangle rect;
-
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (extents != NULL);
@@ -3085,29 +3052,9 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
return;
}
- extents->x = x;
- extents->y = y;
- extents->width = width;
- extents->height = height;
-
- if (!_gtk_css_transform_value_get_matrix (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
- return;
-
- cairo_matrix_init_translate (&matrix, x + width / 2.0, y + height / 2.0);
- cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
- /* need to round to full pixels */
- rect.x = - (width + 1) / 2;
- rect.y = - (height + 1) / 2;
- rect.width = (width + 1) & ~1;
- rect.height = (height + 1) & ~1;
- gtk_cairo_rectangle_transform (extents, &rect, &matrix);
-
- _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SHADOW), &border);
-
- extents->x -= border.left;
- extents->y -= border.top;
- extents->width += border.left + border.right;
- extents->height += border.top + border.bottom;
+ gtk_css_style_render_icon_get_extents (gtk_style_context_lookup_style (context),
+ extents,
+ x, y, width, height);
}
static PangoUnderline