gnome-games r7827 - in trunk: aisleriot libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7827 - in trunk: aisleriot libgames-support
- Date: Fri, 15 Aug 2008 10:14:49 +0000 (UTC)
Author: chpe
Date: Fri Aug 15 10:14:49 2008
New Revision: 7827
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7827&view=rev
Log:
Get the cairo font options from the screen instead of creating them ourself from the gtk settings.
Modified:
trunk/aisleriot/board.c
trunk/libgames-support/games-card-theme.c
trunk/libgames-support/games-card-theme.h
trunk/libgames-support/games-preimage.c
trunk/libgames-support/games-preimage.h
trunk/libgames-support/render-cards.c
Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c (original)
+++ trunk/aisleriot/board.c Fri Aug 15 10:14:49 2008
@@ -1383,71 +1383,51 @@
}
static void
-aisleriot_board_settings_update (AisleriotBoard *board)
+aisleriot_board_settings_update (GtkSettings *settings,
+ GParamSpec *pspec,
+ AisleriotBoard *board)
{
AisleriotBoardPrivate *priv = board->priv;
- GtkWidget *widget = GTK_WIDGET (board);
- GtkSettings *settings;
-#ifndef HAVE_HILDON
+#ifndef HAVE_HILDON
gboolean touchscreen_mode;
-#ifdef GDK_WINDOWING_X11
- char *xft_rgba = NULL;
-#endif /* GDK_WINDOWING_X11 */
#endif /* !HAVE_HILDON */
/* Set up the double-click detection. */
- settings = gtk_widget_get_settings (widget);
g_object_get (settings,
"gtk-double-click-time", &priv->double_click_time,
#ifndef HAVE_HILDON
"gtk-touchscreen-mode", &touchscreen_mode,
-#ifdef GDK_WINDOWING_X11
- "gtk-xft-rgba", &xft_rgba,
-#endif /* GDK_WINDOWING_X11 */
#endif /* !HAVE_HILDON */
NULL);
-#if defined (GDK_WINDOWING_X11) && !defined (HAVE_HILDON)
- if (xft_rgba != NULL) {
- gboolean antialias_set = TRUE;
- cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_DEFAULT;
- cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
-
- if (strcmp (xft_rgba, "none") == 0) {
- antialias_set = FALSE;
- } else if (strcmp (xft_rgba, "rgb") == 0) {
- antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
- subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
- } else if (strcmp (xft_rgba, "bgr") == 0) {
- antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
- subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
- } else if (strcmp (xft_rgba, "vrgb") == 0) {
- antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
- subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
- } else if (strcmp (xft_rgba, "vbgr") == 0) {
- antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
- subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
- }
-
- g_free (xft_rgba);
-
- if (antialias_set) {
- games_card_theme_set_antialias (priv->theme,
- antialias_mode,
- subpixel_order);
-
- /* FIXMEchpe: clear the cached cards in the slots! */
- if (GTK_WIDGET_REALIZED (widget)) {
- gtk_widget_queue_draw (widget);
- }
- }
- }
-#endif /* GDK_WINDOWING_X11 && !HAVE_HILDON */
-#ifndef HAVE_HILDON
+#ifndef HAVE_HILDON
priv->touchscreen_mode = touchscreen_mode != FALSE;
#endif /* !HAVE_HILDON */
}
+#if GTK_CHECK_VERSION (2, 10, 0)
+static void
+aisleriot_board_screen_font_options_changed (GdkScreen *screen,
+ GParamSpec *pspec,
+ AisleriotBoard *board)
+{
+ AisleriotBoardPrivate *priv = board->priv;
+ GtkWidget *widget = GTK_WIDGET (board);
+ const cairo_font_options_t *font_options;
+
+ font_options = gdk_screen_get_font_options (gtk_widget_get_screen (widget));
+ games_card_theme_set_antialias (priv->theme,
+ cairo_font_options_get_antialias (font_options),
+ cairo_font_options_get_subpixel_order (font_options));
+ games_card_theme_set_font_options (priv->theme, font_options);
+
+ /* FIXMEchpe: clear the cached cards in the slots! */
+ if (GTK_WIDGET_REALIZED (widget)) {
+ gtk_widget_queue_draw (widget);
+ }
+}
+#endif /* GTK 2.10.0 */
+
/* Note: this unsets the selection! */
static gboolean
aisleriot_board_move_selected_cards_to_slot (AisleriotBoard *board,
@@ -2513,19 +2493,7 @@
{
AisleriotBoard *board = AISLERIOT_BOARD (widget);
GdkScreen *screen;
-
- screen = gtk_widget_get_screen (widget);
-
-#if 0
- if (previous_screen != NULL) {
- GtkSettings *settings;
-
- settings = gtk_settings_get_for_screen (previous_screen);
- g_signal_handlers_disconnect_matched (settings, G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL,
- widget);
- }
-#endif
+ GtkSettings *settings;
if (GTK_WIDGET_CLASS (aisleriot_board_parent_class)->screen_changed) {
GTK_WIDGET_CLASS (aisleriot_board_parent_class)->screen_changed (widget, previous_screen);
@@ -2534,9 +2502,31 @@
if (screen == NULL || screen == previous_screen)
return;
- /* FIXMEchpe listen to changes! */
+ if (previous_screen) {
+ g_signal_handlers_disconnect_by_func (gtk_settings_get_for_screen (previous_screen),
+ G_CALLBACK (aisleriot_board_settings_update),
+ board);
+ g_signal_handlers_disconnect_by_func (previous_screen,
+ G_CALLBACK (aisleriot_board_screen_font_options_changed),
+ board);
+ }
+
+ screen = gtk_widget_get_screen (widget);
+ settings = gtk_settings_get_for_screen (screen);
+
+ aisleriot_board_settings_update (settings, NULL, board);
+ g_signal_connect (settings, "notify::gtk-double-click-time",
+ G_CALLBACK (aisleriot_board_settings_update), board);
+#ifndef HAVE_HILDON
+ g_signal_connect (settings, "notify::gtk-touchscreen-mode",
+ G_CALLBACK (aisleriot_board_settings_update), board);
+#endif /* !HAVE_HILDON */
- aisleriot_board_settings_update (board);
+#if GTK_CHECK_VERSION (2, 10, 0)
+ aisleriot_board_screen_font_options_changed (screen, NULL, board);
+ g_signal_connect (screen, "notify::font-options",
+ G_CALLBACK (aisleriot_board_screen_font_options_changed), board);
+#endif
}
static void
@@ -3397,6 +3387,10 @@
widget);
#endif
+ g_signal_handlers_disconnect_by_func (gtk_widget_get_screen (GTK_WIDGET (object)),
+ G_CALLBACK (aisleriot_board_screen_font_options_changed),
+ board);
+
G_OBJECT_CLASS (aisleriot_board_parent_class)->finalize (object);
}
Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c (original)
+++ trunk/libgames-support/games-card-theme.c Fri Aug 15 10:14:49 2008
@@ -23,6 +23,7 @@
#include <string.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
#include "games-find-file.h"
#include "games-files.h"
@@ -65,9 +66,11 @@
guint subrender : 1;
guint prescaled : 1;
- guint antialias_set : 1;
- guint antialias : 2; /* enough bits for cairo_antialias_t */
- guint subpixel_order : 3; /* enough bits for cairo_subpixel_order_t */
+#if GTK_CHECK_VERSION (2, 10, 0)
+ cairo_font_options_t *font_options;
+ cairo_antialias_t antialias;
+ cairo_subpixel_order_t subpixel_order;
+#endif
};
enum {
@@ -192,10 +195,13 @@
if (!preimage)
goto out;
- if (theme->antialias_set) {
- games_preimage_set_antialias (preimage, theme->antialias,
- theme->subpixel_order);
+#if GTK_CHECK_VERSION (2, 10, 0)
+ games_preimage_set_antialias (preimage, theme->antialias, theme->subpixel_order);
+
+ if (theme->font_options) {
+ games_preimage_set_font_options (preimage, theme->font_options);
}
+#endif
theme->theme_data.scalable.cards_preimage = preimage;
theme->prescaled = games_preimage_is_scalable (preimage);
@@ -213,9 +219,15 @@
g_free (path);
g_return_val_if_fail (theme->theme_data.scalable.slot_preimage != NULL, FALSE);
- if (theme->antialias_set)
- games_preimage_set_antialias (theme->theme_data.scalable.slot_preimage,
- theme->antialias, theme->subpixel_order);
+#if GTK_CHECK_VERSION (2, 10, 0)
+ games_preimage_set_antialias (theme->theme_data.scalable.slot_preimage,
+ theme->antialias, theme->subpixel_order);
+
+ if (theme->font_options) {
+ games_preimage_set_font_options (theme->theme_data.scalable.slot_preimage,
+ theme->font_options);
+ }
+#endif
/* Use subrendering by default, but allow to override with the env var */
theme->subrender = TRUE;
@@ -536,6 +548,12 @@
g_free (theme->theme_name);
g_free (theme->theme_dir);
+#if GTK_CHECK_VERSION (2, 10, 0)
+ if (theme->font_options) {
+ cairo_font_options_destroy (theme->font_options);
+ }
+#endif
+
G_OBJECT_CLASS (games_card_theme_parent_class)->finalize (object);
}
@@ -553,6 +571,11 @@
#else
cardtheme->use_scalable = FALSE;
#endif /* HAVE_RSVG */
+
+#if GTK_CHECK_VERSION (2, 10, 0)
+ cardtheme->antialias = CAIRO_ANTIALIAS_DEFAULT;
+ cardtheme->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+#endif /* GTK 2.10.0 */
}
static void
@@ -646,27 +669,27 @@
NULL);
}
+#if GTK_CHECK_VERSION (2, 10, 0)
+
/**
- * games_card_theme_set_antialias:
+ * games_preimage_set_antialias:
* @theme:
- * @antialias: the antialiasing mode to use (see @cairo_antialias_t)
- * @subpixel_order: the subpixel order to use (see @cairo_subpixel_order_t)
- * if @antialias is %CAIRO_ANTIALIAS_SUBPIXEL
+ * @antialias: the antialiasing mode to use
+ * @subpixel_order: the subpixel order to use
*
- * Turns on antialising of cards, if using a scalable theme.
+ * Turns on antialising of @theme, if is is has loaded a scalable theme.
*/
void
games_card_theme_set_antialias (GamesCardTheme * theme,
- guint antialias, guint subpixel_order)
+ cairo_antialias_t antialias,
+ cairo_subpixel_order_t subpixel_order)
{
g_return_if_fail (GAMES_IS_CARD_THEME (theme));
- if (theme->antialias_set &&
- theme->antialias == antialias &&
+ if (theme->antialias == antialias &&
theme->subpixel_order == subpixel_order)
return;
- theme->antialias_set = TRUE;
theme->antialias = antialias;
theme->subpixel_order = subpixel_order;
@@ -675,6 +698,40 @@
}
/**
+ * games_card_theme_set_font_options:
+ * @theme:
+ * @font_options: the #cairo_font_options_t to use
+ *
+ * Sets the font options to use when drawing the card images.
+ */
+void
+games_card_theme_set_font_options (GamesCardTheme * theme,
+ const cairo_font_options_t *font_options)
+{
+ g_return_if_fail (GAMES_IS_CARD_THEME (theme));
+
+ if (font_options &&
+ theme->font_options &&
+ cairo_font_options_equal (font_options, theme->font_options))
+ return;
+
+ if (theme->font_options) {
+ cairo_font_options_destroy (theme->font_options);
+ }
+
+ if (font_options) {
+ theme->font_options = cairo_font_options_copy (font_options);
+ } else {
+ theme->font_options = NULL;
+ }
+
+ games_card_theme_clear_source_pixbuf (theme);
+ g_signal_emit (theme, signals[CHANGED], 0);
+}
+
+#endif /* GTK 2.10.0 */
+
+/**
* games_card_theme_set_theme:
* @theme:
* @theme_name: the name of the theme to load
Modified: trunk/libgames-support/games-card-theme.h
==============================================================================
--- trunk/libgames-support/games-card-theme.h (original)
+++ trunk/libgames-support/games-card-theme.h Fri Aug 15 10:14:49 2008
@@ -48,8 +48,14 @@
GamesCardTheme *games_card_theme_new (const char *theme_dir,
gboolean scalable);
+#if GTK_CHECK_VERSION (2, 10, 0)
void games_card_theme_set_antialias (GamesCardTheme * theme,
- guint antialias, guint subpixel_order);
+ cairo_antialias_t antialias,
+ cairo_subpixel_order_t subpixel_order);
+
+void games_card_theme_set_font_options (GamesCardTheme *theme,
+ const cairo_font_options_t *font_options);
+#endif
gboolean games_card_theme_set_theme (GamesCardTheme * theme,
const gchar * name);
Modified: trunk/libgames-support/games-preimage.c
==============================================================================
--- trunk/libgames-support/games-preimage.c (original)
+++ trunk/libgames-support/games-preimage.c Fri Aug 15 10:14:49 2008
@@ -43,16 +43,15 @@
#ifdef HAVE_RSVG
RsvgHandle *rsvg_handle;
+ cairo_font_options_t *font_options;
+ cairo_antialias_t antialias;
+ cairo_subpixel_order_t subpixel_order;
#endif
/* raster pixbuf data */
GdkPixbuf *pixbuf;
guint scalable : 1;
-
- guint antialias_set : 1;
- guint antialias : 2; /* enough bits for cairo_antialias_t */
- guint subpixel_order : 3; /* enough bits for cairo_subpixel_order_t */
};
G_DEFINE_TYPE (GamesPreimage, games_preimage, G_TYPE_OBJECT);
@@ -63,6 +62,11 @@
preimage->scalable = FALSE;
preimage->width = 0;
preimage->height = 0;
+
+#ifdef HAVE_RSVG
+ preimage->antialias = CAIRO_ANTIALIAS_DEFAULT;
+ preimage->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+#endif
}
static void
@@ -74,6 +78,9 @@
if (preimage->rsvg_handle != NULL) {
g_object_unref (preimage->rsvg_handle);
}
+ if (preimage->font_options) {
+ cairo_font_options_destroy (preimage->font_options);
+ }
#endif
if (preimage->pixbuf != NULL) {
@@ -210,7 +217,11 @@
if (!preimage->scalable)
return NULL;
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 6, 0)
+ rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
+#else
rowstride = width * 4;
+#endif
data = g_try_malloc0 (rowstride * height);
if (!data)
@@ -226,21 +237,10 @@
cx = cairo_create (surface);
- if (preimage->antialias_set) {
- cairo_font_options_t *options;
+ cairo_set_antialias (cx, preimage->antialias);
- cairo_set_antialias (cx, (cairo_antialias_t) preimage->antialias);
-
- options = cairo_font_options_create ();
- cairo_get_font_options (cx, options);
- cairo_font_options_set_antialias (options,
- (cairo_antialias_t) preimage->
- antialias);
- cairo_font_options_set_subpixel_order (options,
- (cairo_subpixel_order_t) preimage->
- subpixel_order);
- cairo_set_font_options (cx, options);
- cairo_font_options_destroy (options);
+ if (preimage->font_options) {
+ cairo_set_font_options (cx, preimage->font_options);
}
cairo_matrix_init_identity (&matrix);
@@ -336,25 +336,48 @@
/**
* games_preimage_set_antialias:
- * @preimage:
- * @antialias: the antialiasing mode to use (see @cairo_antialias_t)
- * @subpixel_order: the subpixel order to use (see @cairo_subpixel_order_t)
- * if @antialias is %CAIRO_ANTIALIAS_SUBPIXEL
+ * @preimage: a #GamesPreimage
+ * @antialias: the antialiasing mode to use
+ * @subpixel_order: the subpixel order to use
*
* Turns on antialising of @preimage, if it contains an SVG image.
*/
void
games_preimage_set_antialias (GamesPreimage * preimage,
- guint antialias, guint subpixel_order)
+ cairo_antialias_t antialias,
+ cairo_subpixel_order_t subpixel_order)
{
g_return_if_fail (GAMES_IS_PREIMAGE (preimage));
- preimage->antialias_set = TRUE;
preimage->antialias = antialias;
preimage->subpixel_order = subpixel_order;
}
/**
+ * games_preimage_set_font_options:
+ * @preimage: a #GamesPreimage
+ * @font_options: the font options
+ *
+ * Turns on antialising of @preimage, if it contains an SVG image.
+ */
+void
+games_preimage_set_font_options (GamesPreimage * preimage,
+ const cairo_font_options_t * font_options)
+{
+ g_return_if_fail (GAMES_IS_PREIMAGE (preimage));
+
+ if (preimage->font_options) {
+ cairo_font_options_destroy (preimage->font_options);
+ }
+
+ if (font_options) {
+ preimage->font_options = cairo_font_options_copy (font_options);
+ } else {
+ preimage->font_options = NULL;
+ }
+}
+
+/**
* games_preimage_is_scalable:
* @preimage:
*
Modified: trunk/libgames-support/games-preimage.h
==============================================================================
--- trunk/libgames-support/games-preimage.h (original)
+++ trunk/libgames-support/games-preimage.h Fri Aug 15 10:14:49 2008
@@ -46,7 +46,11 @@
GError ** error);
void games_preimage_set_antialias (GamesPreimage * preimage,
- guint antialias, guint subpixel_order);
+ cairo_antialias_t antialias,
+ cairo_subpixel_order_t subpixel_order);
+
+void games_preimage_set_font_options (GamesPreimage * preimage,
+ const cairo_font_options_t *font_options);
GdkPixbuf *games_preimage_render (GamesPreimage * preimage,
gint width, gint height);
Modified: trunk/libgames-support/render-cards.c
==============================================================================
--- trunk/libgames-support/render-cards.c (original)
+++ trunk/libgames-support/render-cards.c Fri Aug 15 10:14:49 2008
@@ -43,6 +43,7 @@
int *sizes = NULL, n_sizes = 0;
char *data = NULL;
gsize len;
+ cairo_font_options_t *font_options;
cairo_subpixel_order_t subpixels = CAIRO_SUBPIXEL_ORDER_DEFAULT;
cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_DEFAULT;
char *outpath = NULL, *theme_name = NULL, *theme_dir =
@@ -132,8 +133,15 @@
}
theme = games_card_theme_new (NULL, TRUE);
+
if (antialias_set) {
games_card_theme_set_antialias (theme, antialias_mode, subpixels);
+
+ font_options = cairo_font_options_create ();
+ cairo_font_options_set_antialias (font_options, antialias_mode);
+ cairo_font_options_set_subpixel_order (font_options, subpixels);
+ games_card_theme_set_font_options (theme, font_options);
+ cairo_font_options_destroy (font_options);
}
if (!games_card_theme_set_theme (theme, theme_name)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]