gnome-games r8424 - trunk/libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8424 - trunk/libgames-support
- Date: Tue, 6 Jan 2009 18:18:15 +0000 (UTC)
Author: chpe
Date: Tue Jan 6 18:18:15 2009
New Revision: 8424
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8424&view=rev
Log:
Add class to load KDE card themes. Not working yet since the theme path
logic needs more work in the base class.
Added:
trunk/libgames-support/games-card-theme-kde.c
Modified:
trunk/libgames-support/Makefile.am
trunk/libgames-support/games-card-theme.c
trunk/libgames-support/games-card-theme.h
Modified: trunk/libgames-support/Makefile.am
==============================================================================
--- trunk/libgames-support/Makefile.am (original)
+++ trunk/libgames-support/Makefile.am Tue Jan 6 18:18:15 2009
@@ -94,6 +94,7 @@
if HAVE_RSVG
libgames_support_la_SOURCES += \
games-card-theme-svg.c \
+ games-card-theme-kde.c \
$(NULL)
endif
Added: trunk/libgames-support/games-card-theme-kde.c
==============================================================================
--- (empty file)
+++ trunk/libgames-support/games-card-theme-kde.c Tue Jan 6 18:18:15 2009
@@ -0,0 +1,197 @@
+/*
+ Copyright  2004 Callum McKenzie
+ Copyright  2007, 2008 Christian Persch
+
+ This programme is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This programme 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this programme. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Authors: Callum McKenzie <callum physics otago ac nz> */
+
+#include <config.h>
+
+#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"
+#include "games-preimage.h"
+#include "games-runtime.h"
+
+#include "games-card-theme.h"
+#include "games-card-theme-private.h"
+
+struct _GamesCardThemeKDEClass {
+ GamesCardThemePreimageClass parent_class;
+};
+
+struct _GamesCardThemeKDE {
+ GamesCardThemePreimage parent_instance;
+};
+
+#if defined(HAVE_RSVG)
+#include <librsvg/librsvg-features.h>
+#endif
+#if defined(HAVE_RSVG) && defined(LIBRSVG_CHECK_VERSION) && LIBRSVG_CHECK_VERSION(2, 22, 4)
+#define HAVE_RSVG_BBOX
+#else
+#error version check
+#endif
+
+#define N_ROWS ((double) 5.0)
+#define N_COLS ((double) 13.0)
+
+#define DELTA (0.0f)
+
+/* #defining this prints out the time it takes to render the theme */
+/* #define INSTRUMENT_LOADING */
+
+#ifdef INSTRUMENT_LOADING
+static long totaltime = 0;
+#endif
+
+/* Class implementation */
+
+G_DEFINE_TYPE (GamesCardThemeKDE, games_card_theme_kde, GAMES_TYPE_CARD_THEME_PREIMAGE);
+
+static gboolean
+games_card_theme_kde_load_theme (GamesCardTheme *card_theme,
+ const char *theme_dir,
+ const char *theme_name,
+ GError **error)
+{
+ GamesCardThemePreimage *preimage_card_theme = (GamesCardThemePreimage *) card_theme;
+ gboolean retval = FALSE;
+
+#ifdef INSTRUMENT_LOADING
+ clock_t t1, t2;
+
+ t1 = clock ();
+#endif
+
+ if (!GAMES_CARD_THEME_CLASS (games_card_theme_kde_parent_class)->load_theme
+ (card_theme, theme_dir, theme_name, error))
+ goto out;
+
+#ifndef HAVE_RSVG_BBOX
+ goto out;
+#endif
+
+ if (!games_preimage_is_scalable (preimage_card_theme->cards_preimage))
+ goto out;
+
+ retval = TRUE;
+
+out:
+
+#ifdef INSTRUMENT_LOADING
+ t2 = clock ();
+ totaltime += (t2 - t1);
+ g_print ("took %.3fs to create preimage (cumulative %.3fs)\n",
+ (t2 - t1) * 1.0 / CLOCKS_PER_SEC,
+ totaltime * 1.0 / CLOCKS_PER_SEC);
+#endif
+
+ return retval;
+}
+
+static GdkPixbuf *
+games_card_theme_kde_get_card_pixbuf (GamesCardTheme *card_theme,
+ int card_id)
+{
+#ifndef HAVE_RSVG_BBOX
+ GamesCardThemePreimage *preimage_card_theme = (GamesCardThemePreimage *) card_theme;
+ GamesPreimage *preimage = preimage_card_theme->cards_preimage;
+ GdkPixbuf *subpixbuf;
+ int suit, rank;
+ double card_width, card_height;
+ double width, height;
+ double offsetx, offsety;
+ double zoomx, zoomy;
+ char node[64];
+
+ if (!preimage_card_theme->theme_loaded)
+ return NULL;
+
+ suit = card_id / 13;
+ rank = card_id % 13;
+
+ if (G_UNLIKELY (card_id == GAMES_CARD_SLOT)) {
+ subpixbuf = games_preimage_render (preimage_card_theme->slot_preimage,
+ preimage_card_theme->card_size.width,
+ preimage_card_theme->card_size.height);
+
+ return subpixbuf;
+ }
+
+ card_width = ((double) games_preimage_get_width (preimage)) / N_COLS;
+ card_height = ((double) games_preimage_get_height (preimage)) / N_ROWS;
+
+ width = preimage_card_theme->card_size.width - 2 * DELTA;
+ height = preimage_card_theme->card_size.height - 2 * DELTA;
+
+ offsetx = -((double) rank) * card_width + DELTA;
+ offsety = -((double) suit) * card_height + DELTA;
+
+ zoomx = width / card_width;
+ zoomy = height / card_height;
+
+ games_card_get_node_by_suit_and_rank_snprintf (node, sizeof (node), suit, rank);
+
+ subpixbuf = games_preimage_render_sub (preimage,
+ node,
+ preimage_card_theme->card_size.width,
+ preimage_card_theme->card_size.height,
+ offsetx, offsety,
+ zoomx, zoomy);
+
+ return subpixbuf;
+#else
+ return NULL;
+#endif
+}
+
+static void
+games_card_theme_kde_init (GamesCardThemeKDE * cardtheme)
+{
+}
+
+static const char *
+games_card_theme_preimage_get_theme_glob (GamesCardThemeClass *klass)
+{
+ return "*.svgz";
+}
+
+static void
+games_card_theme_kde_class_init (GamesCardThemeKDEClass * klass)
+{
+ GamesCardThemeClass *theme_class = GAMES_CARD_THEME_CLASS (klass);
+
+ theme_class->get_theme_glob = games_card_theme_preimage_get_theme_glob;
+ theme_class->load_theme = games_card_theme_kde_load_theme;
+ theme_class->get_card_pixbuf = games_card_theme_kde_get_card_pixbuf;
+}
+
+/* public API */
+
+/**
+ * games_card_theme_kde_new:
+ *
+ * Returns: a new #GamesCardThemeKDE
+ */
+GamesCardTheme*
+games_card_theme_kde_new (void)
+{
+ return g_object_new (GAMES_TYPE_CARD_THEME_KDE, NULL);
+}
Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c (original)
+++ trunk/libgames-support/games-card-theme.c Tue Jan 6 18:18:15 2009
@@ -72,6 +72,8 @@
#endif
if (strcmp (env, "sliced") == 0)
type = GAMES_TYPE_CARD_THEME_SLICED;
+ else if (strcmp (env, "kde") == 0)
+ type = GAMES_TYPE_CARD_THEME_KDE;
else if (strcmp (env, "fixed") == 0)
type = GAMES_TYPE_CARD_THEME_FIXED;
}
Modified: trunk/libgames-support/games-card-theme.h
==============================================================================
--- trunk/libgames-support/games-card-theme.h (original)
+++ trunk/libgames-support/games-card-theme.h Tue Jan 6 18:18:15 2009
@@ -122,6 +122,22 @@
GamesCardTheme* games_card_theme_sliced_new (void);
+/* GamesCardThemeKDE */
+
+#define GAMES_TYPE_CARD_THEME_KDE (games_card_theme_kde_get_type ())
+#define GAMES_CARD_THEME_KDE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_CARD_THEME_KDE, GamesCardThemeKDE))
+#define GAMES_CARD_THEME_KDE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_CARD_THEME_KDE, GamesCardThemeKDEClass))
+#define GAMES_IS_CARD_THEME_KDE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_CARD_THEME_KDE))
+#define GAMES_IS_CARD_THEME_KDE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_CARD_THEME_KDE))
+#define GAMES_CARD_THEME_KDE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_CARD_THEME_KDE, GamesCardThemeKDEClass))
+
+typedef struct _GamesCardThemeKDEClass GamesCardThemeKDEClass;
+typedef struct _GamesCardThemeKDE GamesCardThemeKDE;
+
+GType games_card_theme_kde_get_type (void);
+
+GamesCardTheme* games_card_theme_kde_new (void);
+
/* GamesCardThemeFixed */
#define GAMES_TYPE_CARD_THEME_FIXED (games_card_theme_fixed_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]