[gnome-games] aisleriot: Make non-clutter AisleriotBoard use ArStyle too
- From: Christian Persch <chpe src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] aisleriot: Make non-clutter AisleriotBoard use ArStyle too
- Date: Mon, 4 Jan 2010 18:15:03 +0000 (UTC)
commit 85da42cabea8f194c943c41aa593a0da2abcd3fc
Author: Christian Persch <chpe gnome org>
Date: Mon Jan 4 18:55:07 2010 +0100
aisleriot: Make non-clutter AisleriotBoard use ArStyle too
Unify the style handling by making also the non-clutter AisleriotBoard
variant use ArStyle.
aisleriot/Makefile.am | 5 +
aisleriot/ar-clutter-embed.c | 1 -
aisleriot/ar-style-gtk.c | 24 +++-
aisleriot/ar-style-private.h | 6 +
aisleriot/ar-style.c | 35 ++++
aisleriot/ar-style.h | 9 +
aisleriot/board-noclutter.c | 408 +++++++++++++++---------------------------
aisleriot/board-noclutter.h | 15 +--
aisleriot/board.c | 32 +---
aisleriot/window.c | 27 +---
10 files changed, 237 insertions(+), 325 deletions(-)
---
diff --git a/aisleriot/Makefile.am b/aisleriot/Makefile.am
index 1c4f4dd..ecd995a 100644
--- a/aisleriot/Makefile.am
+++ b/aisleriot/Makefile.am
@@ -22,6 +22,11 @@ bin_PROGRAMS = sol
sol_SOURCES = \
ar-game-chooser.c \
ar-game-chooser.h \
+ ar-style.c \
+ ar-style.h \
+ ar-style-private.h \
+ ar-style-gtk.c \
+ ar-style-gtk.h \
board-noclutter.c \
board-noclutter.h \
conf.c \
diff --git a/aisleriot/ar-clutter-embed.c b/aisleriot/ar-clutter-embed.c
index ce37466..0be1a38 100644
--- a/aisleriot/ar-clutter-embed.c
+++ b/aisleriot/ar-clutter-embed.c
@@ -21,7 +21,6 @@
#include "ar-clutter-embed.h"
#include "ar-style.h"
-#include "ar-style-private.h"
#include "ar-style-gtk.h"
/**
diff --git a/aisleriot/ar-style-gtk.c b/aisleriot/ar-style-gtk.c
index a739562..4291b66 100644
--- a/aisleriot/ar-style-gtk.c
+++ b/aisleriot/ar-style-gtk.c
@@ -212,7 +212,6 @@ style_set_cb (GtkWidget *widget,
ArStylePrivate *style_priv = style->priv;
GObject *style_object = G_OBJECT (style);
GdkColor *color = NULL;
- ClutterColor selection_color;
int focus_line_width, focus_padding;
gboolean interior_focus;
double card_slot_ratio, card_overhang, card_step;
@@ -269,6 +268,10 @@ style_set_cb (GtkWidget *widget,
g_object_notify (style_object, AR_STYLE_PROP_CARD_STEP);
}
+#ifdef HAVE_CLUTTER
+{
+ ClutterColor selection_color;
+
if (color != NULL) {
_ar_clutter_color_from_gdk_color (&selection_color, color);
gdk_color_free (color);
@@ -281,6 +284,25 @@ style_set_cb (GtkWidget *widget,
g_object_notify (style_object, AR_STYLE_PROP_SELECTION_COLOR);
}
+}
+#else
+{
+ GdkColor selection_color;
+
+ if (color != NULL) {
+ selection_color = *color;
+ gdk_color_free (color);
+ } else {
+ selection_color = default_selection_color;
+ }
+
+ if (!gdk_color_equal (&style_priv->selection_color, &selection_color)) {
+ style_priv->selection_color = selection_color;
+
+ g_object_notify (style_object, AR_STYLE_PROP_SELECTION_COLOR);
+ }
+}
+#endif /* HAVE_CLUTTER */
g_object_thaw_notify (style_object);
}
diff --git a/aisleriot/ar-style-private.h b/aisleriot/ar-style-private.h
index 0096336..4293b21 100644
--- a/aisleriot/ar-style-private.h
+++ b/aisleriot/ar-style-private.h
@@ -41,7 +41,11 @@ struct _ArStylePrivate
{
GamesCardTheme* card_theme;
+#ifdef HAVE_CLUTTER
ClutterColor selection_color;
+#else
+ GdkColor selection_color;
+#endif
double card_slot_ratio;
double card_overhang;
@@ -69,8 +73,10 @@ struct _ArStylePrivate
guint show_seleccion : 1;
};
+#ifdef HAVE_CLUTTER
void _ar_clutter_color_from_gdk_color (ClutterColor *clutter_color,
const GdkColor *gdk_color);
+#endif
G_END_DECLS
diff --git a/aisleriot/ar-style.c b/aisleriot/ar-style.c
index 3d40ff6..95bf340 100644
--- a/aisleriot/ar-style.c
+++ b/aisleriot/ar-style.c
@@ -53,7 +53,12 @@ ar_style_init (ArStyle *style)
priv = style->priv = G_TYPE_INSTANCE_GET_PRIVATE (style, AR_TYPE_STYLE, ArStylePrivate);
+#ifdef HAVE_CLUTTER
_ar_clutter_color_from_gdk_color (&priv->selection_color, &default_selection_color);
+#else
+ priv->selection_color = default_selection_color;
+#endif
+
priv->card_slot_ratio = DEFAULT_CARD_SLOT_RATIO;
priv->card_overhang = DEFAULT_CARD_OVERHANG;
priv->card_step = DEFAULT_CARD_STEP;
@@ -218,6 +223,7 @@ ar_style_set_property (GObject *object,
break;
case PROP_SELECTION_COLOR: {
+#ifdef HAVE_CLUTTER
ClutterColor *color;
if ((color = g_value_get_boxed (value)) != NULL) {
@@ -225,6 +231,15 @@ ar_style_set_property (GObject *object,
} else {
_ar_clutter_color_from_gdk_color (&priv->selection_color, &default_selection_color);
}
+#else
+ GdkColor *color;
+
+ if ((color = g_value_get_boxed (value)) != NULL) {
+ priv->selection_color = *color;
+ } else {
+ priv->selection_color = default_selection_color;
+ }
+#endif
break;
}
@@ -245,7 +260,9 @@ static void
ar_style_class_init (ArStyleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+#ifdef HAVE_CLUTTER
ClutterColor color;
+#endif
g_type_class_add_private (klass, sizeof (ArStylePrivate));
@@ -369,6 +386,7 @@ ar_style_class_init (ArStyleClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+#ifdef HAVE_CLUTTER
_ar_clutter_color_from_gdk_color (&color, &default_selection_color);
g_object_class_install_property
(object_class,
@@ -377,6 +395,15 @@ ar_style_class_init (ArStyleClass *klass)
&color,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+#else
+ g_object_class_install_property
+ (object_class,
+ PROP_SELECTION_COLOR,
+ g_param_spec_boxed (AR_STYLE_PROP_SELECTION_COLOR, NULL, NULL,
+ GDK_TYPE_COLOR,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+#endif /* HAVE_CLUTTER */
g_object_class_install_property
(object_class,
@@ -389,6 +416,8 @@ ar_style_class_init (ArStyleClass *klass)
/* private API */
+#ifdef HAVE_CLUTTER
+
void
_ar_clutter_color_from_gdk_color (ClutterColor *clutter_color,
const GdkColor *gdk_color)
@@ -399,6 +428,8 @@ _ar_clutter_color_from_gdk_color (ClutterColor *clutter_color,
clutter_color->alpha = 0xff;
}
+#endif /* HAVE_CLUTTER */
+
/* public API */
/**
@@ -693,7 +724,11 @@ ar_style_get_card_step (ArStyle *style)
*/
void
ar_style_get_selection_color (ArStyle *style,
+#ifdef HAVE_CLUTTER
ClutterColor * const color)
+#else
+ GdkColor * const color)
+#endif
{
ArStylePrivate *priv = style->priv;
diff --git a/aisleriot/ar-style.h b/aisleriot/ar-style.h
index 17d38cb..6e08984 100644
--- a/aisleriot/ar-style.h
+++ b/aisleriot/ar-style.h
@@ -20,7 +20,11 @@
#include <glib-object.h>
+#ifdef HAVE_CLUTTER
#include <clutter/clutter.h>
+#else
+#include <gdk/gdk.h>
+#endif
#include <libgames-support/games-card-theme.h>
@@ -99,8 +103,13 @@ double ar_style_get_card_slot_ratio (ArStyle *style);
double ar_style_get_card_overhang (ArStyle *style);
double ar_style_get_card_step (ArStyle *style);
+#ifdef HAVE_CLUTTER
void ar_style_get_selection_color (ArStyle *style,
ClutterColor * const color);
+#else
+void ar_style_get_selection_color (ArStyle *style,
+ GdkColor * const color);
+#endif
gboolean ar_style_check_dnd_drag_threshold (ArStyle *style,
float x1,
diff --git a/aisleriot/board-noclutter.c b/aisleriot/board-noclutter.c
index 5e8bdd5..39b4985 100644
--- a/aisleriot/board-noclutter.c
+++ b/aisleriot/board-noclutter.c
@@ -35,8 +35,8 @@
#include <libgames-support/games-sound.h>
#include "conf.h"
-
#include "game.h"
+#include "ar-style-gtk.h"
#include "board-noclutter.h"
@@ -55,17 +55,6 @@
* how much is allowed to slip off the bottom or right.
*/
#define MIN_DELTA (0.05)
-#define MAX_DELTA (0.2)
-#define MAX_OVERHANG (0.2)
-
-/* The proportion of a slot dedicated to the card (horiz or vert). */
-#ifndef DEFAULT_CARD_SLOT_RATIO
-#ifdef HAVE_HILDON
-#define DEFAULT_CARD_SLOT_RATIO (0.9)
-#else
-#define DEFAULT_CARD_SLOT_RATIO (0.8)
-#endif
-#endif /* !DEFAULT_CARD_SLOT_RATIO */
#define DOUBLE_TO_INT_CEIL(d) ((int) (d + 0.5))
@@ -106,12 +95,13 @@ struct _AisleriotBoardPrivate
{
AisleriotGame *game;
+ ArStyle *style;
+
GdkGC *draw_gc;
GdkGC *bg_gc;
GdkGC *slot_gc;
GdkCursor *cursor[LAST_CURSOR];
- GamesCardTheme *theme;
CardSize card_size;
GtkAllocation allocation;
@@ -161,15 +151,12 @@ struct _AisleriotBoardPrivate
/* Focus handling */
ArSlot *focus_slot;
int focus_card_id; /* -1 for focused empty slot */
- int focus_line_width;
- int focus_padding;
GdkRectangle focus_rect;
/* Selection */
ArSlot *selection_slot;
int selection_start_card_id;
GdkRectangle selection_rect;
- GdkColor selection_colour;
/* Highlight */
ArSlot *highlight_slot;
@@ -182,10 +169,8 @@ struct _AisleriotBoardPrivate
/* Bit field */
guint droppable_supported : 1;
- guint touchscreen_mode : 1;
guint use_pixbuf_drawing : 1;
guint show_focus : 1; /* whether the focus is drawn */
- guint interior_focus : 1;
guint click_to_move : 1;
@@ -207,7 +192,7 @@ enum
{
PROP_0,
PROP_GAME,
- PROP_THEME
+ PROP_STYLE
};
#ifdef ENABLE_KEYNAV
@@ -592,7 +577,8 @@ get_focus_rect (AisleriotBoard *board,
priv->focus_slot,
priv->focus_card_id,
1, rect);
- widen_rect (rect, priv->focus_line_width + priv->focus_padding);
+ widen_rect (rect, ar_style_get_focus_line_width (priv->style)+
+ ar_style_get_focus_padding (priv->style));
}
static void
@@ -722,6 +708,7 @@ slot_update_geometry (AisleriotBoard *board,
GdkRectangle old_rect;
GByteArray *cards;
int delta, xofs, yofs, pixeldx;
+ double card_step;
if (!priv->geometry_set)
return;
@@ -729,6 +716,8 @@ slot_update_geometry (AisleriotBoard *board,
cards = slot->cards;
old_rect = slot->rect;
+ card_step = ar_style_get_card_step (priv->style);
+
xofs = priv->xoffset;
yofs = priv->yoffset;
@@ -756,36 +745,36 @@ slot_update_geometry (AisleriotBoard *board,
double n_cards = cards->len - 1; /* FIXMEchpe: slot->exposed - 1 ? */
if (slot->expanded_down) {
- double y_from_bottom, max_dy = MAX_DELTA;
+ double y_from_bottom, max_dy = card_step;
if (slot->dy_set)
max_dy = slot->expansion.dy;
/* Calculate the compressed_dy that will let us fit within the board */
y_from_bottom = ((double) (priv->allocation.height - slot->rect.y)) / ((double) priv->card_size.height);
- dy = (y_from_bottom - MAX_OVERHANG) / n_cards;
+ dy = (y_from_bottom - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
dy = CLAMP (dy, MIN_DELTA, max_dy);
} else if (slot->expanded_right) {
if (priv->is_rtl) {
- double x_from_left, max_dx = MAX_DELTA;
+ double x_from_left, max_dx = card_step;
if (slot->dx_set)
max_dx = slot->expansion.dx;
x_from_left = ((double) slot->rect.x) / ((double) priv->card_size.width) + 1.0;
- dx = (x_from_left - MAX_OVERHANG) / n_cards;
+ dx = (x_from_left - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
dx = CLAMP (dx, MIN_DELTA, max_dx);
slot->pixeldx = DOUBLE_TO_INT_CEIL (- dx * priv->card_size.width);
pixeldx = -slot->pixeldx;
} else {
- double x_from_right, max_dx = MAX_DELTA;
+ double x_from_right, max_dx = card_step;
if (slot->dx_set)
max_dx = slot->expansion.dx;
x_from_right = ((double) (priv->allocation.width - slot->rect.x)) / ((double) priv->card_size.width);
- dx = (x_from_right - MAX_OVERHANG) / n_cards;
+ dx = (x_from_right - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
dx = CLAMP (dx, MIN_DELTA, max_dx);
pixeldx = slot->pixeldx = DOUBLE_TO_INT_CEIL (dx * priv->card_size.width);
@@ -1405,29 +1394,6 @@ clear_state (AisleriotBoard *board)
priv->last_clicked_card_id = -1;
}
-static void
-aisleriot_board_settings_update (GtkSettings *settings,
- GParamSpec *pspec,
- AisleriotBoard *board)
-{
- AisleriotBoardPrivate *priv = board->priv;
-#if GTK_CHECK_VERSION (2, 10, 0)
- gboolean touchscreen_mode;
-#endif /* GTK >= 2.10.0 */
-
- /* Set up the double-click detection. */
- g_object_get (settings,
- "gtk-double-click-time", &priv->double_click_time,
-#if GTK_CHECK_VERSION (2, 10, 0)
- "gtk-touchscreen-mode", &touchscreen_mode,
-#endif /* GTK >= 2.10.0 */
- NULL);
-
-#if GTK_CHECK_VERSION (2, 10, 0)
- priv->touchscreen_mode = touchscreen_mode != FALSE;
-#endif /* GTK >= 2.10.0 */
-}
-
/* Note: this unsets the selection! hslot may be equal to priv->selection_slot. */
static gboolean
aisleriot_board_move_selected_cards_to_slot (AisleriotBoard *board,
@@ -2491,106 +2457,126 @@ aisleriot_board_unrealize (GtkWidget *widget)
GTK_WIDGET_CLASS (aisleriot_board_parent_class)->unrealize (widget);
}
+/* Style handling */
+
static void
-aisleriot_board_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen)
+aisleriot_board_sync_style (ArStyle *style,
+ GParamSpec *pspec,
+ AisleriotBoard *board)
{
- AisleriotBoard *board = AISLERIOT_BOARD (widget);
- GdkScreen *screen;
- GtkSettings *settings;
+ AisleriotBoardPrivate *priv = board->priv;
+ GtkWidget *widget = GTK_WIDGET (board);
+ const char *pspec_name;
+ gboolean update_geometry = FALSE, redraw_focus = FALSE, queue_redraw = FALSE, redraw_selection = FALSE;
- if (GTK_WIDGET_CLASS (aisleriot_board_parent_class)->screen_changed) {
- GTK_WIDGET_CLASS (aisleriot_board_parent_class)->screen_changed (widget, previous_screen);
+ g_assert (style == priv->style);
+
+ if (pspec != NULL) {
+ pspec_name = pspec->name;
+ } else {
+ pspec_name = NULL;
}
- screen = gtk_widget_get_screen (widget);
- if (screen == previous_screen)
- return;
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CARD_THEME)) {
+ GamesCardTheme *theme;
- if (previous_screen) {
- g_signal_handlers_disconnect_by_func (gtk_settings_get_for_screen (previous_screen),
- G_CALLBACK (aisleriot_board_settings_update),
- board);
- }
+ theme = ar_style_get_card_theme (style);
+ if (theme != NULL) {
+ priv->geometry_set = FALSE;
+ priv->slot_image = NULL;
- if (screen == NULL)
- return;
+ games_card_images_set_theme (priv->images, theme);
- settings = gtk_settings_get_for_screen (screen);
+ update_geometry |= TRUE;
+ queue_redraw |= TRUE;
+ }
+ }
- aisleriot_board_settings_update (settings, NULL, board);
- g_signal_connect (settings, "notify::gtk-double-click-time",
- G_CALLBACK (aisleriot_board_settings_update), board);
-#if GTK_CHECK_VERSION (2, 10, 0)
- g_signal_connect (settings, "notify::gtk-touchscreen-mode",
- G_CALLBACK (aisleriot_board_settings_update), board);
-#endif /* GTK >= 2.10.0 */
-}
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CARD_SLOT_RATIO)) {
+ double card_slot_ratio;
-static void
-aisleriot_board_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
-{
- AisleriotBoard *board = AISLERIOT_BOARD (widget);
- AisleriotBoardPrivate *priv = board->priv;
- GdkColor *colour = NULL;
- gboolean interior_focus;
- double card_slot_ratio;
+ card_slot_ratio = ar_style_get_card_slot_ratio (style);
- gtk_widget_style_get (widget,
- "focus-line-width", &priv->focus_line_width,
- "focus-padding", &priv->focus_padding,
- "interior-focus", &interior_focus,
- "selection-color", &colour,
- "card-slot-ratio", &card_slot_ratio,
- NULL);
+ update_geometry |= (card_slot_ratio != priv->card_slot_ratio);
-#if 0
- g_print ("style-set: focus width %d padding %d interior-focus %s card-slot-ratio %.2f\n",
- priv->focus_line_width,
- priv->focus_padding,
- interior_focus ? "t" : "f",
- card_slot_ratio);
-#endif
+ priv->card_slot_ratio = card_slot_ratio;
+ }
- priv->interior_focus = interior_focus != FALSE;
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CARD_OVERHANG)) {
+ update_geometry |= TRUE;
+ }
- priv->card_slot_ratio = card_slot_ratio;
- /* FIXMEchpe: if the ratio changed, we should re-layout the board below */
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CARD_STEP)) {
+ update_geometry |= TRUE;
+ }
- if (colour != NULL) {
- priv->selection_colour = *colour;
- gdk_color_free (colour);
- } else {
- static const GdkColor default_colour = { 0, 0 /* red */, 0 /* green */, 0xaa00 /* blue */};
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_INTERIOR_FOCUS)) {
+ redraw_focus = TRUE;
+ }
- priv->selection_colour = default_colour;
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_FOCUS_LINE_WIDTH)) {
+ redraw_focus = TRUE;
}
- games_card_images_set_selection_color (priv->images,
- &priv->selection_colour);
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_FOCUS_PADDING)) {
+ redraw_focus = TRUE;
+ }
- GTK_WIDGET_CLASS (aisleriot_board_parent_class)->style_set (widget, previous_style);
-}
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_RTL)) {
+ gboolean is_rtl;
-static void
-aisleriot_board_direction_changed (GtkWidget *widget,
- GtkTextDirection previous_direction)
-{
- AisleriotBoard *board = AISLERIOT_BOARD (widget);
- AisleriotBoardPrivate *priv = board->priv;
- GtkTextDirection direction;
+ is_rtl = ar_style_get_rtl (style);
- direction = gtk_widget_get_direction (widget);
+ update_geometry |= (is_rtl != priv->is_rtl);
- priv->is_rtl = (direction == GTK_TEXT_DIR_RTL);
+ priv->is_rtl = is_rtl;
- if (direction != previous_direction) {
+ /* FIXMEchpe: necessary? */
priv->force_geometry_update = TRUE;
}
- /* This will queue a resize */
- GTK_WIDGET_CLASS (aisleriot_board_parent_class)->direction_changed (widget, previous_direction);
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CLICK_TO_MOVE)) {
+ gboolean click_to_move;
+
+ click_to_move = ar_style_get_click_to_move (style);
+ if (click_to_move != priv->click_to_move) {
+ /* Clear the selection. Do this before setting the new value,
+ * since otherwise selection won't get cleared correctly.
+ */
+ set_selection (board, NULL, -1, FALSE);
+
+ priv->click_to_move = click_to_move;
+
+ /* FIXMEchpe: we queue a redraw here. WHY?? Check that it's safe not to. */
+ queue_redraw = TRUE;
+ }
+ }
+
+ if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_SELECTION_COLOR)) {
+ GdkColor selection_color;
+
+ ar_style_get_selection_color (priv->style, &selection_color);
+ games_card_images_set_selection_color (priv->images, &selection_color);
+
+ /* FIXMEchpe: update the cached images in the selection slot!! */
+ redraw_selection = TRUE;
+ }
+
+ if (update_geometry && GTK_WIDGET_REALIZED (widget)) {
+ aisleriot_board_setup_geometry (board);
+ }
+
+ if (queue_redraw && GTK_WIDGET_REALIZED (widget)) {
+ gtk_widget_queue_draw (widget);
+ }
+
+ if (redraw_focus) {
+ /* FIXMEchpe: do redraw the focus! */
+ }
+
+ if (redraw_selection) {
+ /* FIXMEchpe: do redraw the selection! */
+ }
}
static void
@@ -3290,7 +3276,7 @@ draw_focus:
if (gdk_region_rect_in (region, &priv->focus_rect) == GDK_OVERLAP_RECTANGLE_OUT)
goto expose_done;
- if (priv->interior_focus) {
+ if (ar_style_get_interior_focus (priv->style)) {
focus_rect = priv->focus_rect;
} else {
get_rect_by_slot_and_card (board,
@@ -3344,6 +3330,8 @@ aisleriot_board_init (AisleriotBoard *board)
priv->moving_cards = g_byte_array_sized_new (SLOT_CARDS_N_PREALLOC);
+ priv->images = games_card_images_new ();
+
gtk_widget_set_events (widget,
gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK |
@@ -3361,26 +3349,24 @@ aisleriot_board_init (AisleriotBoard *board)
#endif /* HAVE_MAEMO */
}
-static GObject *
-aisleriot_board_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+static void
+aisleriot_board_dispose (GObject *object)
{
- GObject *object;
- AisleriotBoard *board;
- AisleriotBoardPrivate *priv;
-
- object = G_OBJECT_CLASS (aisleriot_board_parent_class)->constructor
- (type, n_construct_properties, construct_params);
+ AisleriotBoard *board = AISLERIOT_BOARD (object);
+ AisleriotBoardPrivate *priv = board->priv;
- board = AISLERIOT_BOARD (object);
- priv = board->priv;
+ if (priv->style != NULL) {
+ _ar_style_gtk_detach (priv->style, GTK_WIDGET (board));
- g_assert (priv->game != NULL);
+ g_signal_handlers_disconnect_by_func (priv->style,
+ G_CALLBACK (aisleriot_board_sync_style),
+ board);
- priv->images = games_card_images_new ();
+ g_object_unref (priv->style);
+ priv->style = NULL;
+ }
- return object;
+ G_OBJECT_CLASS (aisleriot_board_parent_class)->dispose (object);
}
static void
@@ -3398,35 +3384,10 @@ aisleriot_board_finalize (GObject *object)
g_object_unref (priv->images);
- if (priv->theme)
- g_object_unref (priv->theme);
-
-#if 0
- screen = gtk_widget_get_settings (widget);
- g_signal_handlers_disconnect_matched (settings, G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL,
- widget);
-#endif
-
G_OBJECT_CLASS (aisleriot_board_parent_class)->finalize (object);
}
static void
-aisleriot_board_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- AisleriotBoard *board = AISLERIOT_BOARD (object);
-
- switch (prop_id) {
- case PROP_THEME:
- g_value_set_object (value, aisleriot_board_get_card_theme (board));
- break;
- }
-}
-
-static void
aisleriot_board_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -3449,8 +3410,14 @@ aisleriot_board_set_property (GObject *object,
G_CALLBACK (slot_changed_cb), board);
break;
- case PROP_THEME:
- aisleriot_board_set_card_theme (board, g_value_get_object (value));
+
+ case PROP_STYLE:
+ priv->style = g_value_dup_object (value);
+ _ar_style_gtk_attach (priv->style, GTK_WIDGET (board));
+
+ aisleriot_board_sync_style (priv->style, NULL, board);
+ g_signal_connect (priv->style, "notify",
+ G_CALLBACK (aisleriot_board_sync_style), board);
break;
}
}
@@ -3466,16 +3433,12 @@ aisleriot_board_class_init (AisleriotBoardClass *klass)
g_type_class_add_private (gobject_class, sizeof (AisleriotBoardPrivate));
- gobject_class->constructor = aisleriot_board_constructor;
+ gobject_class->dispose = aisleriot_board_dispose;
gobject_class->finalize = aisleriot_board_finalize;
gobject_class->set_property = aisleriot_board_set_property;
- gobject_class->get_property = aisleriot_board_get_property;
widget_class->realize = aisleriot_board_realize;
widget_class->unrealize = aisleriot_board_unrealize;
- widget_class->screen_changed = aisleriot_board_screen_changed;
- widget_class->style_set = aisleriot_board_style_set;
- widget_class->direction_changed = aisleriot_board_direction_changed;
widget_class->size_allocate = aisleriot_board_size_allocate;
widget_class->size_request = aisleriot_board_size_request;
#ifdef ENABLE_KEYNAV
@@ -3560,29 +3523,16 @@ aisleriot_board_class_init (AisleriotBoardClass *klass)
g_object_class_install_property
(gobject_class,
- PROP_THEME,
- g_param_spec_object ("theme", NULL, NULL,
- GAMES_TYPE_CARD_THEME,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
-
- gtk_widget_class_install_style_property
- (widget_class,
- g_param_spec_boxed ("selection-color", NULL, NULL,
- GDK_TYPE_COLOR,
- G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
-
- /**
- * AisleriotBoard:card-slot-ratio:
- *
- * The ratio of card to slot size. Note that this is the ratio of
- * card width/slot width and card height/slot height, not of
- * card area/slot area.
- */
- gtk_widget_class_install_style_property
- (widget_class,
- g_param_spec_double ("card-slot-ratio", NULL, NULL,
- 0.1, 1.0, DEFAULT_CARD_SLOT_RATIO,
- G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ PROP_STYLE,
+ g_param_spec_object ("style", NULL, NULL,
+ AR_TYPE_STYLE,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ _ar_style_gtk_class_install_style_properties (widget_class);
#ifdef ENABLE_KEYNAV
/* Keybindings */
@@ -3649,80 +3599,16 @@ aisleriot_board_class_init (AisleriotBoardClass *klass)
/* public API */
GtkWidget *
-aisleriot_board_new (AisleriotGame *game)
+aisleriot_board_new (ArStyle *style,
+ AisleriotGame *game)
{
return g_object_new (AISLERIOT_TYPE_BOARD,
+ "style", style,
"game", game,
NULL);
}
void
-aisleriot_board_set_card_theme (AisleriotBoard *board,
- GamesCardTheme *theme)
-{
- AisleriotBoardPrivate *priv = board->priv;
- GtkWidget *widget = GTK_WIDGET (board);
-
- g_return_if_fail (AISLERIOT_IS_BOARD (board));
- g_return_if_fail (GAMES_IS_CARD_THEME (theme));
-
- if (theme == priv->theme)
- return;
-
- if (priv->theme) {
- g_object_unref (priv->theme);
- }
-
- priv->geometry_set = FALSE;
- priv->slot_image = NULL;
-
- priv->theme = g_object_ref (theme);
-
- games_card_images_set_theme (priv->images, priv->theme);
-
- if (GTK_WIDGET_REALIZED (widget)) {
- /* Update card size and slot locations for new card theme (might have changed aspect!)*/
- aisleriot_board_setup_geometry (board);
-
- gtk_widget_queue_draw (widget);
- }
-
- g_object_notify (G_OBJECT (board), "theme");
-}
-
-GamesCardTheme *
-aisleriot_board_get_card_theme (AisleriotBoard *board)
-{
- AisleriotBoardPrivate *priv = board->priv;
-
- return priv->theme;
-}
-
-void
-aisleriot_board_set_click_to_move (AisleriotBoard *board,
- gboolean click_to_move)
-{
- AisleriotBoardPrivate *priv = board->priv;
- GtkWidget *widget = GTK_WIDGET (board);
-
- click_to_move = click_to_move != FALSE;
- if (priv->click_to_move == click_to_move)
- return;
-
- /* Clear the selection. Do this before setting the new value,
- * since otherwise selection won't get cleared correctly.
- */
- set_selection (board, NULL, -1, FALSE);
-
- priv->click_to_move = click_to_move;
-
- /* FIXMEchpe why? */
- if (GTK_WIDGET_REALIZED (widget)) {
- gtk_widget_queue_draw (widget);
- }
-}
-
-void
aisleriot_board_abort_move (AisleriotBoard *board)
{
clear_state (board);
diff --git a/aisleriot/board-noclutter.h b/aisleriot/board-noclutter.h
index 21691b3..be09594 100644
--- a/aisleriot/board-noclutter.h
+++ b/aisleriot/board-noclutter.h
@@ -24,6 +24,7 @@
#include <libgames-support/games-card-theme.h>
#include "game.h"
+#include "ar-style.h"
G_BEGIN_DECLS
@@ -60,18 +61,8 @@ struct _AisleriotBoardClass {
GType aisleriot_board_get_type (void);
-GtkWidget *aisleriot_board_new (AisleriotGame *game);
-
-void aisleriot_board_set_card_theme (AisleriotBoard * board,
- GamesCardTheme *theme);
-
-GamesCardTheme *aisleriot_board_get_card_theme (AisleriotBoard * board);
-
-void aisleriot_board_set_click_to_move (AisleriotBoard * board,
- gboolean click_to_move);
-
-void aisleriot_board_set_animation_mode (AisleriotBoard *board,
- gboolean enable);
+GtkWidget *aisleriot_board_new (ArStyle *style,
+ AisleriotGame *game);
void aisleriot_board_abort_move (AisleriotBoard * board);
diff --git a/aisleriot/board.c b/aisleriot/board.c
index 263df2a..d92f346 100644
--- a/aisleriot/board.c
+++ b/aisleriot/board.c
@@ -3054,6 +3054,8 @@ aisleriot_board_init (AisleriotBoard *board)
priv = board->priv = AISLERIOT_BOARD_GET_PRIVATE (board);
+ priv->textures = games_card_textures_cache_new ();
+
memset (&priv->allocation, 0, sizeof (ClutterActorBox));
/* We want to receive events! */
@@ -3075,29 +3077,6 @@ aisleriot_board_init (AisleriotBoard *board)
priv->animation_layer, NULL);
}
-static GObject *
-aisleriot_board_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
-{
- GObject *object;
- AisleriotBoard *board;
- AisleriotBoardPrivate *priv;
-
- object = G_OBJECT_CLASS (aisleriot_board_parent_class)->constructor
- (type, n_construct_properties, construct_params);
-
- board = AISLERIOT_BOARD (object);
- priv = board->priv;
-
- g_assert (priv->style != NULL);
- g_assert (priv->game != NULL);
-
- priv->textures = games_card_textures_cache_new ();
-
- return object;
-}
-
static void
aisleriot_board_finalize (GObject *object)
{
@@ -3114,9 +3093,9 @@ aisleriot_board_finalize (GObject *object)
g_byte_array_free (priv->moving_cards, TRUE);
if (priv->style != NULL) {
- g_signal_handlers_disconnect_matched (priv->style,
- G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL, board);
+ g_signal_handlers_disconnect_by_func (priv->style,
+ G_CALLBACK (aisleriot_board_sync_style),
+ board);
g_object_unref (priv->style);
}
@@ -3204,7 +3183,6 @@ aisleriot_board_class_init (AisleriotBoardClass *klass)
g_type_class_add_private (gobject_class, sizeof (AisleriotBoardPrivate));
- gobject_class->constructor = aisleriot_board_constructor;
gobject_class->dispose = aisleriot_board_dispose;
gobject_class->finalize = aisleriot_board_finalize;
gobject_class->set_property = aisleriot_board_set_property;
diff --git a/aisleriot/window.c b/aisleriot/window.c
index 7bbbad1..980e6a7 100644
--- a/aisleriot/window.c
+++ b/aisleriot/window.c
@@ -133,9 +133,9 @@ enum
struct _AisleriotWindowPrivate
{
AisleriotGame *game;
+ ArStyle *board_style;
#ifdef HAVE_CLUTTER
ArClutterEmbed *board;
- ArStyle *board_style;
ClutterActor *baize_actor;
ClutterActor *board_actor;
#else
@@ -873,7 +873,6 @@ debug_pixbuf_drawing_cb (GtkToggleAction *action,
}
#endif /* !HAVE_CLUTTER */
-#ifdef HAVE_CLUTTER
static void
debug_tweak_cb (GtkAction *action,
AisleriotWindow *window)
@@ -892,7 +891,6 @@ debug_tweak_cb (GtkAction *action,
gtk_window_set_transient_for (GTK_WINDOW (prop_editor), GTK_WINDOW (window));
gtk_window_present (GTK_WINDOW (prop_editor));
}
-#endif /* HAVE_CLUTTER */
#endif /* ENABLE_DEBUG_UI */
@@ -1023,11 +1021,7 @@ clickmove_toggle_cb (GtkToggleAction *action,
click_to_move = gtk_toggle_action_get_active (action);
aisleriot_game_set_click_to_move (priv->game, click_to_move);
-#ifdef HAVE_CLUTTER
ar_style_set_click_to_move (priv->board_style, click_to_move);
-#else
- aisleriot_board_set_click_to_move (priv->board, click_to_move);
-#endif
games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_CLICK_TO_MOVE), click_to_move);
}
@@ -1060,11 +1054,7 @@ animations_toggle_cb (GtkToggleAction *action,
enabled = gtk_toggle_action_get_active (action);
-#ifdef HAVE_CLUTTER
ar_style_set_enable_animations (priv->board_style, enabled);
-#else
- aisleriot_board_set_animation_mode (priv->board, enabled);
-#endif
games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), enabled);
}
@@ -1448,11 +1438,7 @@ aisleriot_window_take_card_theme (AisleriotWindow *window,
}
#endif /* GTK+ 2.10.0 */
-#ifdef HAVE_CLUTTER
ar_style_set_card_theme (priv->board_style, theme);
-#else
- aisleriot_board_set_card_theme (priv->board, theme);
-#endif
}
static void
@@ -2286,10 +2272,8 @@ aisleriot_window_init (AisleriotWindow *window)
{ "DebugGamePrev", GTK_STOCK_GO_BACK, NULL, NULL, NULL,
G_CALLBACK (debug_game_prev) },
#endif /* !HAVE_HILDON */
-#ifdef HAVE_CLUTTER
{ "DebugTweakStyle", NULL, "_Tweak Style", NULL, NULL,
G_CALLBACK (debug_tweak_cb) },
-#endif /* HAVE_CLUTTER */
#endif /* ENABLE_DEBUG_UI */
/* Accel actions */
@@ -2398,9 +2382,7 @@ aisleriot_window_init (AisleriotWindow *window)
#ifndef HAVE_CLUTTER
"<menuitem action='DebugPixbufDrawing'/>"
#endif /* !HAVE_CLUTTER */
-#ifdef HAVE_CLUTTER
"<menuitem action='DebugTweakStyle'/>"
-#endif
"</menu>"
#endif /* ENABLE_DEBUG_UI */
"<menuitem action='CloseWindow'/>"
@@ -2451,9 +2433,7 @@ aisleriot_window_init (AisleriotWindow *window)
"</menu>"
#ifdef ENABLE_DEBUG_UI
"<menu action='DebugMenu'>"
-#ifdef HAVE_CLUTTER
"<menuitem action='DebugTweakStyle'/>"
-#endif
#ifndef HAVE_CLUTTER
"<menuitem action='DebugPixbufDrawing'/>"
#endif
@@ -2550,8 +2530,9 @@ aisleriot_window_init (AisleriotWindow *window)
priv->theme_manager = games_card_themes_new ();
-#ifdef HAVE_CLUTTER
priv->board_style = ar_style_new ();
+
+#ifdef HAVE_CLUTTER
priv->board = ar_clutter_embed_new (priv->board_style);
priv->baize_actor = aisleriot_baize_new ();
@@ -2577,7 +2558,7 @@ aisleriot_window_init (AisleriotWindow *window)
/* FIXMEchpe: unref baize & board_actor here? */
#else
- priv->board = AISLERIOT_BOARD (aisleriot_board_new (priv->game));
+ priv->board = AISLERIOT_BOARD (aisleriot_board_new (priv->board_style, priv->game));
aisleriot_board_set_pixbuf_drawing (priv->board, priv->use_pixbuf_drawing);
#endif /* HAVE_CLUTTER */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]