[gnome-themes-standard] adwaita: split some common code into a separate source file
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-themes-standard] adwaita: split some common code into a separate source file
- Date: Mon, 2 May 2011 18:03:13 +0000 (UTC)
commit 933db1bbd209a1e626f06bf5ee726aa656593305
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon May 2 14:02:56 2011 -0400
adwaita: split some common code into a separate source file
src/Makefile.am | 2 +
src/adwaita_engine.c | 215 ++-----------------------------------------------
src/adwaita_utils.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/adwaita_utils.h | 74 +++++++++++++++++
4 files changed, 301 insertions(+), 209 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 90b3990..f9761e2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,8 @@ INCLUDES = \
$(GTK_CFLAGS)
libadwaita_la_SOURCES = \
+ adwaita_utils.h \
+ adwaita_utils.c \
adwaita_engine.c
libadwaita_la_LDFLAGS = -module -avoid-version -no-undefined -export-symbols $(top_srcdir)/src/engine.symbols
diff --git a/src/adwaita_engine.c b/src/adwaita_engine.c
index c0f5fa7..09a2ef0 100644
--- a/src/adwaita_engine.c
+++ b/src/adwaita_engine.c
@@ -29,6 +29,8 @@
#include <math.h>
#include <cairo-gobject.h>
+#include "adwaita_utils.h"
+
#define ADWAITA_NAMESPACE "adwaita"
typedef struct _AdwaitaEngine AdwaitaEngine;
@@ -67,163 +69,6 @@ adwaita_engine_init (AdwaitaEngine *self)
{
}
-enum {
- SIDE_LEFT = 1,
- SIDE_BOTTOM = 1 << 1,
- SIDE_RIGHT = 1 << 2,
- SIDE_TOP = 1 << 3,
- SIDE_ALL = 0xF
-};
-
-static void
-_cairo_round_rectangle_sides (cairo_t *cr,
- gdouble radius,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- guint sides,
- GtkJunctionSides junction)
-{
- radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
-
- if (sides & SIDE_RIGHT)
- {
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
- cairo_move_to (cr, x + width, y);
- else
- {
- cairo_new_sub_path (cr);
- cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
- }
-
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
- cairo_line_to (cr, x + width, y + height);
- else
- cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
- }
-
- if (sides & SIDE_BOTTOM)
- {
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
- {
- if ((sides & SIDE_RIGHT) == 0)
- cairo_new_sub_path (cr);
-
- cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
- }
- else if ((sides & SIDE_RIGHT) == 0)
- cairo_move_to (cr, x + width, y + height);
-
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
- cairo_line_to (cr, x, y + height);
- else
- cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
- }
- else
- cairo_move_to (cr, x, y + height);
-
- if (sides & SIDE_LEFT)
- {
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
- {
- if ((sides & SIDE_BOTTOM) == 0)
- cairo_new_sub_path (cr);
-
- cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
- }
- else if ((sides & SIDE_BOTTOM) == 0)
- cairo_move_to (cr, x, y + height);
-
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_TOPLEFT))
- cairo_line_to (cr, x, y);
- else
- cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
- }
-
- if (sides & SIDE_TOP)
- {
- if (radius != 0 &&
- ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
- {
- if ((sides & SIDE_LEFT) == 0)
- cairo_new_sub_path (cr);
-
- cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
- }
- else if ((sides & SIDE_LEFT) == 0)
- cairo_move_to (cr, x, y);
-
- if (radius == 0 ||
- (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
- cairo_line_to (cr, x + width, y);
- else
- cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
- }
-}
-
-static void
-_cairo_uneven_frame (cairo_t *cr,
- gdouble radius,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- GtkBorder *border,
- GtkJunctionSides junction)
-{
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_set_line_width (cr, 1);
-
- _cairo_round_rectangle_sides (cr, (gdouble) radius,
- x, y,
- width, height,
- SIDE_ALL, junction);
-
- _cairo_round_rectangle_sides (cr, (gdouble) radius,
- x + border->left,
- y + border->top,
- width - border->left - border->right,
- height - border->top - border->bottom,
- SIDE_ALL, junction);
-}
-
-/* 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,
- gboolean repeat)
-{
- 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);
-
- if (repeat)
- cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
-}
-
static void
adwaita_engine_render_arrow (GtkThemingEngine *engine,
cairo_t *cr,
@@ -369,54 +214,6 @@ adwaita_engine_render_focus (GtkThemingEngine *engine,
}
}
-static gboolean
-render_from_assets_common (GtkThemingEngine *engine,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
-{
- gboolean retval = FALSE;
- GtkStateFlags state;
- GValue value = { 0, };
- cairo_pattern_t *asset = NULL;
- cairo_surface_t *surface = NULL;
-
- state = gtk_theming_engine_get_state (engine);
- gtk_theming_engine_get_property (engine,
- "background-image",
- state,
- &value);
-
- asset = g_value_dup_boxed (&value);
- g_value_unset (&value);
-
- if (asset != NULL) {
- cairo_pattern_get_surface (asset, &surface);
- }
-
- if (surface != NULL) {
- cairo_save (cr);
-
- cairo_set_source_surface (cr, surface, x, y);
- cairo_scale (cr,
- width / cairo_image_surface_get_width (surface),
- height / cairo_image_surface_get_height (surface));
-
- cairo_paint (cr);
-
- cairo_restore (cr);
- retval = TRUE;
- }
-
- if (asset != NULL) {
- cairo_pattern_destroy (asset);
- }
-
- return retval;
-}
-
static void
render_check_menuitem (GtkThemingEngine *engine,
cairo_t *cr,
@@ -471,8 +268,8 @@ adwaita_engine_render_check (GtkThemingEngine *engine,
return;
}
- res = render_from_assets_common (engine, cr,
- x, y + 2.0, width, height);
+ res = adwaita_render_from_assets_common (engine, cr,
+ x, y + 2.0, width, height);
if (!res) {
GTK_THEMING_ENGINE_CLASS (adwaita_engine_parent_class)->render_check
@@ -532,8 +329,8 @@ adwaita_engine_render_option (GtkThemingEngine *engine,
return;
}
- res = render_from_assets_common (engine, cr,
- x, y + 2.0, width, height);
+ res = adwaita_render_from_assets_common (engine, cr,
+ x, y + 2.0, width, height);
if (!res) {
GTK_THEMING_ENGINE_CLASS (adwaita_engine_parent_class)->render_option
diff --git a/src/adwaita_utils.c b/src/adwaita_utils.c
new file mode 100644
index 0000000..c282dac
--- /dev/null
+++ b/src/adwaita_utils.c
@@ -0,0 +1,219 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* Adwaita - a GTK+ engine
+ *
+ * Copyright (C) 2011 Carlos Garnacho <carlosg gnome org>
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Carlos Garnacho <carlosg gnome org>
+ * Cosimo Cecchi <cosimoc gnome org>
+ *
+ * Project contact: <gnome-themes-list gnome org>
+ */
+
+#include "adwaita_utils.h"
+
+void
+_cairo_round_rectangle_sides (cairo_t *cr,
+ gdouble radius,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ guint sides,
+ GtkJunctionSides junction)
+{
+ radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
+
+ if (sides & SIDE_RIGHT)
+ {
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
+ cairo_move_to (cr, x + width, y);
+ else
+ {
+ cairo_new_sub_path (cr);
+ cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
+ }
+
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
+ cairo_line_to (cr, x + width, y + height);
+ else
+ cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
+ }
+
+ if (sides & SIDE_BOTTOM)
+ {
+ if (radius != 0 &&
+ ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
+ {
+ if ((sides & SIDE_RIGHT) == 0)
+ cairo_new_sub_path (cr);
+
+ cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
+ }
+ else if ((sides & SIDE_RIGHT) == 0)
+ cairo_move_to (cr, x + width, y + height);
+
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
+ cairo_line_to (cr, x, y + height);
+ else
+ cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
+ }
+ else
+ cairo_move_to (cr, x, y + height);
+
+ if (sides & SIDE_LEFT)
+ {
+ if (radius != 0 &&
+ ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
+ {
+ if ((sides & SIDE_BOTTOM) == 0)
+ cairo_new_sub_path (cr);
+
+ cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
+ }
+ else if ((sides & SIDE_BOTTOM) == 0)
+ cairo_move_to (cr, x, y + height);
+
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_TOPLEFT))
+ cairo_line_to (cr, x, y);
+ else
+ cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
+ }
+
+ if (sides & SIDE_TOP)
+ {
+ if (radius != 0 &&
+ ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
+ {
+ if ((sides & SIDE_LEFT) == 0)
+ cairo_new_sub_path (cr);
+
+ cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
+ }
+ else if ((sides & SIDE_LEFT) == 0)
+ cairo_move_to (cr, x, y);
+
+ if (radius == 0 ||
+ (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
+ cairo_line_to (cr, x + width, y);
+ else
+ cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
+ }
+}
+
+void
+_cairo_uneven_frame (cairo_t *cr,
+ gdouble radius,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GtkBorder *border,
+ GtkJunctionSides junction)
+{
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_set_line_width (cr, 1);
+
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ x, y,
+ width, height,
+ SIDE_ALL, junction);
+
+ _cairo_round_rectangle_sides (cr, (gdouble) radius,
+ x + border->left,
+ y + border->top,
+ width - border->left - border->right,
+ height - border->top - border->bottom,
+ SIDE_ALL, junction);
+}
+
+/* Set the appropriate matrix for
+ * patterns coming from the style context
+ */
+void
+style_pattern_set_matrix (cairo_pattern_t *pattern,
+ gdouble width,
+ gdouble height,
+ gboolean repeat)
+{
+ 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);
+
+ if (repeat)
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+}
+
+gboolean
+adwaita_render_from_assets_common (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ gboolean retval = FALSE;
+ GtkStateFlags state;
+ cairo_pattern_t *asset = NULL;
+ cairo_surface_t *surface = NULL;
+
+ state = gtk_theming_engine_get_state (engine);
+ gtk_theming_engine_get (engine, state,
+ "background-image", &asset,
+ NULL);
+
+ if (asset != NULL) {
+ cairo_pattern_get_surface (asset, &surface);
+ }
+
+ if (surface != NULL) {
+ cairo_save (cr);
+
+ cairo_set_source_surface (cr, surface, x, y);
+ cairo_scale (cr,
+ width / cairo_image_surface_get_width (surface),
+ height / cairo_image_surface_get_height (surface));
+
+ cairo_paint (cr);
+
+ cairo_restore (cr);
+ retval = TRUE;
+ }
+
+ if (asset != NULL) {
+ cairo_pattern_destroy (asset);
+ }
+
+ return retval;
+}
diff --git a/src/adwaita_utils.h b/src/adwaita_utils.h
new file mode 100644
index 0000000..e926e8a
--- /dev/null
+++ b/src/adwaita_utils.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* Adwaita - a GTK+ engine
+ *
+ * Copyright (C) 2011 Carlos Garnacho <carlosg gnome org>
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Carlos Garnacho <carlosg gnome org>
+ * Cosimo Cecchi <cosimoc gnome org>
+ *
+ * Project contact: <gnome-themes-list gnome org>
+ */
+
+#include <gtk/gtk.h>
+
+#ifndef __ADWAITA_UTILS_H__
+#define __ADWAITA_UTILS_H__
+
+enum {
+ SIDE_LEFT = 1,
+ SIDE_BOTTOM = 1 << 1,
+ SIDE_RIGHT = 1 << 2,
+ SIDE_TOP = 1 << 3,
+ SIDE_ALL = 0xF
+};
+
+gboolean
+adwaita_render_from_assets_common (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height);
+
+ void
+style_pattern_set_matrix (cairo_pattern_t *pattern,
+ gdouble width,
+ gdouble height,
+ gboolean repeat);
+
+void
+_cairo_uneven_frame (cairo_t *cr,
+ gdouble radius,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GtkBorder *border,
+ GtkJunctionSides junction);
+
+void
+_cairo_round_rectangle_sides (cairo_t *cr,
+ gdouble radius,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ guint sides,
+ GtkJunctionSides junction);
+
+#endif /* __ADWAITA_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]