static ArCardThemeInfo *
ar_card_theme_sliced_class_get_theme_info (ArCardThemeClass *klass,
                                              const char *path,
                                              const char *filename)
{
  ArCardThemeInfo *info;
  char *name, *display_name, *pref_name;

  info = AR_CARD_THEME_CLASS (ar_card_theme_sliced_parent_class)->get_theme_info (klass, path, filename);
  if (info) {
    g_assert (info->pref_name == NULL);
    info->pref_name = g_strdup_printf ("sliced:%s", filename);
    return info;
  }

  /* This class also supports the old-style PNG format */
  if (!g_str_has_suffix (filename, ".png"))
    return NULL;

  name = games_filename_to_display_name (filename);
  display_name = g_strdup_printf ("%s (Ugly)", name);
  pref_name = g_strdup_printf ("sliced:%s", filename);
  info = _ar_card_theme_info_new (G_OBJECT_CLASS_TYPE (klass),
                                     path,
                                     filename,
                                     display_name /* adopts */,
                                     pref_name /* adopts */,
                                     NULL, NULL);
  g_free (name);

  return info;
}
Esempio n. 2
0
static void
ar_card_theme_kde_class_init (ArCardThemeKDEClass * klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  ArCardThemeClass *theme_class = AR_CARD_THEME_CLASS (klass);

  gobject_class->finalize = ar_card_theme_kde_finalize;
  gobject_class->get_property = ar_card_theme_kde_get_property;
  gobject_class->set_property = ar_card_theme_kde_set_property;

  theme_class->get_theme_info = ar_card_theme_kde_class_get_theme_info;
  theme_class->foreach_theme_dir = ar_card_theme_kde_class_foreach_theme_dir;

  theme_class->load = ar_card_theme_kde_load;
  theme_class->get_card_aspect = ar_card_theme_kde_get_card_aspect;
  theme_class->paint_card = ar_card_theme_kde_paint_card;

  g_object_class_install_property
    (gobject_class,
     PROP_BACK_INDEX,
     g_param_spec_int ("back-index", NULL, NULL,
                       0, 15, 0,
                       G_PARAM_READWRITE |
                       G_PARAM_STATIC_STRINGS));

  g_object_class_install_property
    (gobject_class,
     PROP_N_BACKS,
     g_param_spec_int ("n-backs", NULL, NULL,
                       1, 16, 1,
                       G_PARAM_READABLE |
                       G_PARAM_STATIC_STRINGS));
}
Esempio n. 3
0
static void
ar_card_theme_kde_class_ensure_back_infos (ArCardThemeKDEClass *klass)
{
  ArCardThemeClass *theme_class;

  if (klass->back_names != NULL)
    return;

  klass->back_names = g_hash_table_new_full (g_str_hash, g_str_equal,
                                             g_free, g_free);

  theme_class = AR_CARD_THEME_CLASS (klass);
  theme_class->foreach_theme_dir (theme_class,
                                  (ArCardThemeForeachFunc) ar_card_theme_kde_class_load_back_infos,
                                  klass->back_names);
}
Esempio n. 4
0
static void
ar_card_theme_preimage_class_init (ArCardThemePreimageClass * klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  ArCardThemeClass *theme_class = AR_CARD_THEME_CLASS (klass);

  gobject_class->finalize = ar_card_theme_preimage_finalize;

  theme_class->get_theme_info = ar_card_theme_preimage_class_get_theme_info;

  theme_class->load = ar_card_theme_preimage_load;
  theme_class->set_card_size = ar_card_theme_preimage_set_card_size;
  theme_class->get_card_size = ar_card_theme_preimage_get_card_size;
  theme_class->get_card_aspect = ar_card_theme_preimage_get_card_aspect;
  theme_class->set_font_options = ar_card_theme_preimage_set_font_options;
}
static void
ar_card_theme_sliced_class_init (ArCardThemeSlicedClass * klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  ArCardThemeClass *theme_class = AR_CARD_THEME_CLASS (klass);
  ArCardThemePreimageClass *preimage_theme_class = AR_CARD_THEME_PREIMAGE_CLASS (klass);

  gobject_class->finalize = ar_card_theme_sliced_finalize;

  theme_class->get_theme_info = ar_card_theme_sliced_class_get_theme_info;
  theme_class->foreach_theme_dir = ar_card_theme_sliced_class_foreach_theme_dir;

  theme_class->load = ar_card_theme_sliced_load;
  theme_class->get_card_pixbuf = ar_card_theme_sliced_get_card_pixbuf;

  preimage_theme_class->needs_scalable_cards = FALSE;
  preimage_theme_class->clear_sized_theme_data = ar_card_theme_sliced_clear_sized_theme_data;
}
static gboolean
ar_card_theme_sliced_load (ArCardTheme *card_theme,
                              GError **error)
{
  ArCardThemePreimage *preimage_card_theme = (ArCardThemePreimage *) card_theme;
  ArCardThemeSliced *theme = (ArCardThemeSliced *) card_theme;

  if (!AR_CARD_THEME_CLASS (ar_card_theme_sliced_parent_class)->load (card_theme, error))
    return FALSE;

  /* If we don't have a scalable format, build an unscaled pixbuf that we'll cut up later */
  theme->scalable = games_preimage_is_scalable (preimage_card_theme->cards_preimage);
  if (!theme->scalable) {
    theme->source = games_preimage_render_unscaled_pixbuf (preimage_card_theme->cards_preimage);

    /* This is true because in the non-scalable case GamesPreimage directly holds a GdkPixbuf */
    g_assert (theme->source != NULL);
  
    theme->subsize.width = gdk_pixbuf_get_width (theme->source) / 13;
    theme->subsize.height = gdk_pixbuf_get_height (theme->source) / 5;
  }

  return TRUE;
}
Esempio n. 7
0
static gboolean
ar_card_theme_kde_load (ArCardTheme *card_theme,
                        GError **error)
{
  static const char extra_backs[][11] = {
    "#blue_back",
    "#red_back",
    "#green_back"
  };
  ArCardThemeKDE *theme = (ArCardThemeKDE *) card_theme;
  ArSvg *svg;
  RsvgHandle *rsvg_handle;
  char node[32];
  guint i;
  gboolean has_red_joker, has_black_joker, has_joker;

  if (!AR_CARD_THEME_CLASS (ar_card_theme_kde_parent_class)->load (card_theme, error))
    return FALSE;

  svg = ((ArCardThemePreimage *) theme)->cards_svg;
  rsvg_handle = RSVG_HANDLE (svg);

  /* Check available backs */
  g_assert (theme->n_backs == 0);

  ar_card_get_node_by_id_snprintf (node, sizeof (node), AR_CARD_BACK);
  if (rsvg_handle_has_sub (rsvg_handle, node)) {
    theme->backs[theme->n_backs++] = g_strdup (node);
  }

  for (i = 0; i < G_N_ELEMENTS (extra_backs); ++i) {
    if (rsvg_handle_has_sub (rsvg_handle, extra_backs[i])) {
      theme->backs[theme->n_backs++] = g_strdup (extra_backs[i]);
    }
  }

  for (i = 1; i < 10; ++i) {
    g_snprintf (node, sizeof (node), "#back_c%d", i);
    if (rsvg_handle_has_sub (rsvg_handle, node)) {
      theme->backs[theme->n_backs++] = g_strdup (node);
    }
  }

  /* No backs at all? Fail! */
  if (theme->n_backs == 0) {
    g_set_error (error, AR_CARD_THEME_ERROR, AR_CARD_THEME_ERROR_MISSING_ELEMENT,
                 "Missing element for card back");
    return FALSE;
  }

  /* Look for the jokers */
  ar_card_get_node_by_id_snprintf (node, sizeof (node), AR_CARD_BLACK_JOKER);
  has_black_joker = rsvg_handle_has_sub (rsvg_handle, node);
  ar_card_get_node_by_id_snprintf (node, sizeof (node), AR_CARD_RED_JOKER);
  has_red_joker = rsvg_handle_has_sub (rsvg_handle, node);

  has_joker = rsvg_handle_has_sub (rsvg_handle, "#joker");

  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,
                 "Failed to get the theme's aspect ratio");
    return FALSE;
  }

  return TRUE;
}