[aisleriot] themes: Fix kde card theme
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aisleriot] themes: Fix kde card theme
- Date: Mon, 5 Dec 2011 21:44:20 +0000 (UTC)
commit f3c8b61b52fe6528c1042d91fe20489c9e76a3ea
Author: Christian Persch <chpe gnome org>
Date: Mon Dec 5 22:43:19 2011 +0100
themes: Fix kde card theme
(Some?) KDE card themes still use the legacy node IDs.
src/lib/ar-card-theme-kde.c | 9 +++++-
src/lib/ar-card.c | 62 ++++++++++++++++++++++++++++++++++++++++--
src/lib/ar-card.h | 19 +++++++++---
3 files changed, 81 insertions(+), 9 deletions(-)
---
diff --git a/src/lib/ar-card-theme-kde.c b/src/lib/ar-card-theme-kde.c
index 38bff97..7ab35c0 100644
--- a/src/lib/ar-card-theme-kde.c
+++ b/src/lib/ar-card-theme-kde.c
@@ -53,6 +53,7 @@ struct _ArCardThemeKDE {
guint back_index : 4; /* same */
guint has_2_jokers : 1;
guint has_joker : 1;
+ guint legacy : 1;
};
enum {
@@ -291,6 +292,9 @@ ar_card_theme_kde_load (ArCardTheme *card_theme,
theme->has_2_jokers = has_red_joker && has_black_joker;
theme->has_joker = has_joker;
+ ar_card_get_legacy_node_by_suit_and_rank_snprintf (node, sizeof (node), AR_CARDS_CLUBS, AR_CARD_ACE);
+ theme->legacy = rsvg_handle_has_sub (rsvg_handle, node);
+
/* Get the card_extents of the card back, which we use to compute the theme's aspect ratio */
if (!ar_card_theme_kde_get_card_extents (theme, AR_CARD_BACK, theme->backs[theme->back_index])) {
g_set_error (error, AR_CARD_THEME_ERROR, AR_CARD_THEME_ERROR_GENERIC,
@@ -334,7 +338,10 @@ ar_card_theme_kde_paint_card (ArCardTheme *card_theme,
return;
}
- ar_card_get_node_by_id_snprintf (node, sizeof (node), card_id);
+ if (theme->legacy)
+ ar_card_get_legacy_node_by_id_snprintf (node, sizeof (node), card_id);
+ else
+ ar_card_get_node_by_id_snprintf (node, sizeof (node), card_id);
card_extents = ar_card_theme_kde_get_card_extents (theme, card_id, node);
if (!card_extents)
diff --git a/src/lib/ar-card.c b/src/lib/ar-card.c
index 60a98d6..531dc44 100644
--- a/src/lib/ar-card.c
+++ b/src/lib/ar-card.c
@@ -93,7 +93,39 @@ ar_card_get_node_by_suit_and_rank_snprintf (char *buffer,
/**
- * ar_card_get_node_by_suit_and_rank_snprintf:
+ * ar_card_get_legacy_node_by_suit_and_rank_snprintf:
+ * @buffer: the output buffer
+ * @bufsize: the size of the output buffer
+ * @suit: the suit of the card
+ * @rank: the rank of the card
+ *
+ * Prints the legacy identifier for the card @card into @buffer.
+ *
+ * Returns: the number of bytes which would be produced if the buffer
+ * was large enough.
+ */
+int
+ar_card_get_legacy_node_by_suit_and_rank_snprintf (char *buffer,
+ gsize bufsize,
+ int suit,
+ int rank)
+{
+ int len;
+
+ if (G_LIKELY (suit < 4)) {
+ len = g_snprintf (buffer, bufsize, "#%s_%s",
+ ranks + rank_offsets[rank],
+ suites + suite_offsets[suit]);
+ } else {
+ len = g_snprintf (buffer, bufsize, "#%s",
+ extra_cards + extra_card_offsets[rank]);
+ }
+
+ return len;
+}
+
+/**
+ * ar_card_get_node_by_id_snprintf:
* @buffer: the output buffer
* @bufsize: the size of the output buffer
* @card_id: the ID of the card
@@ -105,8 +137,8 @@ ar_card_get_node_by_suit_and_rank_snprintf (char *buffer,
*/
int
ar_card_get_node_by_id_snprintf (char *buffer,
- gsize bufsize,
- int card_id)
+ gsize bufsize,
+ int card_id)
{
int suit, rank;
@@ -117,6 +149,30 @@ ar_card_get_node_by_id_snprintf (char *buffer,
}
/**
+ * ar_card_get_legacy_node_by_id_snprintf:
+ * @buffer: the output buffer
+ * @bufsize: the size of the output buffer
+ * @card_id: the ID of the card
+ *
+ * Prints the legacy identifier for the card @card into @buffer.
+ *
+ * Returns: the number of bytes which would be produced if the buffer
+ * was large enough.
+ */
+int
+ar_card_get_legacy_node_by_id_snprintf (char *buffer,
+ gsize bufsize,
+ int card_id)
+{
+ int suit, rank;
+
+ suit = card_id / 13;
+ rank = card_id % 13;
+
+ return ar_card_get_legacy_node_by_suit_and_rank_snprintf (buffer, bufsize, suit, rank);
+}
+
+/**
* ar_card_get_name_by_id_snprintf:
* @buffer: the output buffer
* @bufsize: the size of the output buffer
diff --git a/src/lib/ar-card.h b/src/lib/ar-card.h
index dac112d..30e1a43 100644
--- a/src/lib/ar-card.h
+++ b/src/lib/ar-card.h
@@ -102,13 +102,22 @@ typedef enum {
} ArCardIDType;
int ar_card_get_node_by_suit_and_rank_snprintf (char *buffer,
- gsize bufsize,
- int suit,
- int rank);
+ gsize bufsize,
+ int suit,
+ int rank);
+
+int ar_card_get_legacy_node_by_suit_and_rank_snprintf (char *buffer,
+ gsize bufsize,
+ int suit,
+ int rank);
int ar_card_get_node_by_id_snprintf (char *buffer,
- gsize bufsize,
- int card_id);
+ gsize bufsize,
+ int card_id);
+
+int ar_card_get_legacy_node_by_id_snprintf (char *buffer,
+ gsize bufsize,
+ int card_id);
int ar_card_get_name_by_id_snprintf (char *buffer,
gsize bufsize,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]