gnome-games r7213 - trunk/libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7213 - trunk/libgames-support
- Date: Sun, 13 Jan 2008 22:09:03 +0000 (GMT)
Author: chpe
Date: Sun Jan 13 22:09:03 2008
New Revision: 7213
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7213&view=rev
Log:
Move card routines into games-card.[ch].
Modified:
trunk/libgames-support/games-card-theme.c
trunk/libgames-support/games-card-theme.h
trunk/libgames-support/games-card.c
trunk/libgames-support/games-card.h
trunk/libgames-support/render-cards.c
Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c (original)
+++ trunk/libgames-support/games-card-theme.c Sun Jan 13 22:09:03 2008
@@ -66,36 +66,6 @@
guint subpixel_order : 3; /* enough bits for cairo_subpixel_order_t */
};
-static const char extra_cards[][12] = {
- "black_joker",
- "red_joker",
- "back",
- "slot"
-};
-
-static const char suites[][8] = {
- "club",
- "diamond",
- "heart",
- "spade"
-};
-
-static const char ranks[][6] = {
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "10",
- "jack",
- "queen",
- "king"
-};
-
enum {
PROP_0,
PROP_SCALABLE,
@@ -118,21 +88,6 @@
static long totaltime = 0;
#endif
-static inline void
-print_card_name (int card_id, char *buffer, gsize _size)
-{
- int suit, rank;
-
- suit = card_id / 13;
- rank = card_id % 13;
-
- if (G_LIKELY (suit < 4)) {
- g_snprintf (buffer, _size, "%s-%s", suites[suit], ranks[rank]);
- } else {
- g_snprintf (buffer, _size, "%s", extra_cards[rank]);
- }
-}
-
static void
games_card_theme_clear_source_pixbuf (GamesCardTheme * theme)
{
@@ -487,11 +442,7 @@
zoomx = width / card_width;
zoomy = height / card_height;
- if (G_LIKELY (suit < 4)) {
- g_snprintf (node, sizeof (node), "#%s_%s", ranks[rank], suites[suit]);
- } else {
- g_snprintf (node, sizeof (node), "#%s", extra_cards[rank]);
- }
+ games_card_get_node_by_suit_and_rank_snprintf (node, sizeof (node), suit, rank);
subpixbuf = games_preimage_render_sub (preimage,
node,
@@ -542,7 +493,7 @@
g_return_val_if_fail (!theme->use_scalable, NULL);
- print_card_name (card_id, name, sizeof (name));
+ games_card_get_name_by_id_snprintf (name, sizeof (name), card_id);
g_snprintf (filename, sizeof (filename), "%s.png", name);
path = games_build_filename (theme->theme_data.prerendered.themesizepath, filename);
@@ -939,22 +890,3 @@
return pixbuf;
}
-
-/**
- * games_card_theme_get_card_name:
- * @theme:
- * @cardid:
- *
- * Returns the name of the card @cardid
- *
- * Returns: a newly allocated string containing the card's name
- */
-char *
-games_card_theme_get_card_name (GamesCardTheme * theme, gint card_id)
-{
- char name[128];
-
- print_card_name (card_id, name, sizeof (name));
-
- return g_strdup (name);
-}
Modified: trunk/libgames-support/games-card-theme.h
==============================================================================
--- trunk/libgames-support/games-card-theme.h (original)
+++ trunk/libgames-support/games-card-theme.h Sun Jan 13 22:09:03 2008
@@ -35,40 +35,6 @@
#define GAMES_IS_CARD_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_CARD_THEME))
#define GAMES_CARD_THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_CARD_THEME))
-enum {
- /* Cards */
- GAMES_CARD_JOKER = 0,
- GAMES_CARD_ACE = 1,
- GAMES_CARD_TWO = 2,
- GAMES_CARD_THREE = 3,
- GAMES_CARD_FOUR = 4,
- GAMES_CARD_FIVE = 5,
- GAMES_CARD_SIX = 6,
- GAMES_CARD_SEVEN = 7,
- GAMES_CARD_EIGHT = 8,
- GAMES_CARD_NINE = 9,
- GAMES_CARD_TEN = 10,
- GAMES_CARD_JACK = 11,
- GAMES_CARD_QUEEN = 12,
- GAMES_CARD_KING = 13,
- GAMES_CARD_ACE_HIGH = 14,
-
- /* Suites */
- GAMES_CARDS_CLUBS = 0,
- GAMES_CARDS_DIAMONDS = 2,
- GAMES_CARDS_HEARTS = 1,
- GAMES_CARDS_SPADES = 3,
-
- /* Jokers */
- GAMES_CARD_BLACK_JOKER = 52,
- GAMES_CARD_RED_JOKER = 53,
-
- /* Special */
- GAMES_CARD_BACK = 54,
- GAMES_CARD_SLOT = 55,
- GAMES_CARDS_TOTAL = 56,
-};
-
typedef struct {
gint width;
gint height;
@@ -101,8 +67,6 @@
GdkPixbuf *games_card_theme_get_card_pixbuf (GamesCardTheme * theme,
gint cardid);
-gchar *games_card_theme_get_card_name (GamesCardTheme * theme, gint card_id);
-
G_END_DECLS
#endif /* GAMES_CARD_THEME_H */
Modified: trunk/libgames-support/games-card.c
==============================================================================
--- trunk/libgames-support/games-card.c (original)
+++ trunk/libgames-support/games-card.c Sun Jan 13 22:09:03 2008
@@ -22,6 +22,112 @@
#include "games-card.h"
+static const char extra_cards[][12] = {
+ "black_joker",
+ "red_joker",
+ "back",
+ "slot"
+};
+
+static const char suites[][8] = {
+ "club",
+ "diamond",
+ "heart",
+ "spade"
+};
+
+static const char ranks[][6] = {
+ "1",
+ "2",
+ "3",
+ "4",
+ "5",
+ "6",
+ "7",
+ "8",
+ "9",
+ "10",
+ "jack",
+ "queen",
+ "king"
+};
+
+/**
+ * games_card_get_name_by_id_snprintf:
+ * @buffer: the output buffer
+ * @bufsize: the size of the output buffer
+ * @card_id: the ID of the card
+ *
+ * Prints the identifier for the card @card into @buffer.
+ *
+ * Returns: the number of bytes which would be produced if the buffer
+ * was large enough.
+ */
+int
+games_card_get_name_by_id_snprintf (char *buffer,
+ gsize bufsize,
+ int card_id)
+{
+ int suit, rank, len;
+
+ suit = card_id / 13;
+ rank = card_id % 13;
+
+ if (G_LIKELY (suit < 4)) {
+ len = g_snprintf (buffer, bufsize, "%s-%s", suites[suit], ranks[rank]);
+ } else {
+ len = g_snprintf (buffer, bufsize, "%s", extra_cards[rank]);
+ }
+
+ return len;
+}
+
+/**
+ * games_card_get_node_by_suit_and_rank_snprintf:
+ * @buffer: the output buffer
+ * @bufsize: the size of the output buffer
+ * @card_id: the ID of the card
+ *
+ * Prints the identifier for the card @card into @buffer.
+ *
+ * Returns: the number of bytes which would be produced if the buffer
+ * was large enough.
+ */
+int
+games_card_get_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], suites[suit]);
+ } else {
+ len = g_snprintf (buffer, bufsize, "#%s", extra_cards[rank]);
+ }
+
+ return len;
+}
+
+/**
+ * games_card_get_name_by_id:
+ * @card_id:
+ *
+ * Returns the name of the card @cardid
+ *
+ * Returns: a newly allocated string containing the identifier for @card_id
+ */
+char *
+games_card_get_name_by_id (gint card_id)
+{
+ char name[128];
+
+ games_card_get_name_by_id_snprintf (name, sizeof (name), card_id);
+
+ return g_strdup (name);
+}
+
/**
* games_card_get_name:
* @card:
Modified: trunk/libgames-support/games-card.h
==============================================================================
--- trunk/libgames-support/games-card.h (original)
+++ trunk/libgames-support/games-card.h Sun Jan 13 22:09:03 2008
@@ -23,6 +23,10 @@
#ifndef GAMES_CARD_H
#define GAMES_CARD_H
+#include <glib.h>
+
+G_BEGIN_DECLS
+
/* A card */
/* Black Joker: value = 0, suit = spade or club
@@ -61,6 +65,51 @@
#define GAMES_CARD_THEME_DEFAULT "bonded"
#endif
+typedef enum {
+ /* Cards */
+ GAMES_CARD_JOKER = 0,
+ GAMES_CARD_ACE = 1,
+ GAMES_CARD_TWO = 2,
+ GAMES_CARD_THREE = 3,
+ GAMES_CARD_FOUR = 4,
+ GAMES_CARD_FIVE = 5,
+ GAMES_CARD_SIX = 6,
+ GAMES_CARD_SEVEN = 7,
+ GAMES_CARD_EIGHT = 8,
+ GAMES_CARD_NINE = 9,
+ GAMES_CARD_TEN = 10,
+ GAMES_CARD_JACK = 11,
+ GAMES_CARD_QUEEN = 12,
+ GAMES_CARD_KING = 13,
+ GAMES_CARD_ACE_HIGH = 14,
+
+ /* Suites */
+ GAMES_CARDS_CLUBS = 0,
+ GAMES_CARDS_DIAMONDS = 2,
+ GAMES_CARDS_HEARTS = 1,
+ GAMES_CARDS_SPADES = 3,
+
+ /* Jokers */
+ GAMES_CARD_BLACK_JOKER = 52,
+ GAMES_CARD_RED_JOKER = 53,
+
+ /* Special */
+ GAMES_CARD_BACK = 54,
+ GAMES_CARD_SLOT = 55,
+ GAMES_CARDS_TOTAL = 56,
+} GamesCardIDType;
+
+int games_card_get_name_by_id_snprintf (char *buffer,
+ gsize bufsize,
+ int card_id);
+int games_card_get_node_by_suit_and_rank_snprintf (char *buffer,
+ gsize bufsize,
+ int suit,
+ int rank);
+char * games_card_get_name_by_id (int card_id);
+
const char *games_card_get_name (Card card);
+G_END_DECLS
+
#endif /* !GAMES_CARD_H */
Modified: trunk/libgames-support/render-cards.c
==============================================================================
--- trunk/libgames-support/render-cards.c (original)
+++ trunk/libgames-support/render-cards.c Sun Jan 13 22:09:03 2008
@@ -185,7 +185,7 @@
if (!pixbuf)
goto loser;
- name = games_card_theme_get_card_name (theme, j);
+ name = games_card_get_name_by_id (j);
filename = g_strdup_printf ("%s.png", name);
path = g_build_filename (sizepath, filename, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]