Пример #1
0
/**
 * games_runtime_init:
 *
 * Initialises the runtime file localisator. This also calls setlocale,
 * and initialises gettext support and gnome-games debug support.
 *
 * NOTE: This must be called before using ANY other glib/gtk/etc function!
 * 
 * Returns: %TRUE iff initialisation succeeded
 */
gboolean
games_runtime_init (const char *name)
{
  gboolean retval;

  setlocale (LC_ALL, "");

#if defined(HAVE_GNOME) || defined(HAVE_RSVG_GNOMEVFS) || defined(HAVE_GSTREAMER)
  /* If we're going to use gconf, gnome-vfs, or gstreamer, we need to
   * init threads before calling any glib functions.
   */
  g_thread_init (NULL);
  /* May call any glib function after this point */
#endif

  _games_profile_start ("games_runtime_init");

  _games_debug_init ();

  app_name = g_strdup (name);

  bindtextdomain (GETTEXT_PACKAGE, games_runtime_get_directory (GAMES_RUNTIME_LOCALE_DIRECTORY));
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);

#ifdef G_OS_WIN32
{
  const char *path;

  path = games_runtime_get_directory (GAMES_RUNTIME_MODULE_DIRECTORY);

  _games_debug_print (GAMES_DEBUG_RUNTIME,
                      "Relocation path: %s\n", path ? path : "(null)");

  retval = path != NULL;
}
#else
  retval = TRUE;
#endif

#if defined(ENABLE_CARD_THEME_FORMAT_KDE) || defined(ENABLE_CARD_THEME_FORMAT_SLICED) || defined(ENABLE_CARD_THEME_FORMAT_PYSOL)
  if (strcmp (app_name, "aisleriot") == 0 || strcmp (app_name, "blackjack") == 0) {
    gpl_version = 3;
  } else
#endif
  gpl_version = 2;

  _games_profile_end ("games_runtime_init");

  return retval;
}
Пример #2
0
GamesScoresBackend *
games_scores_backend_new (GamesScoreStyle style,
			  char *base_name,
                          char *name)
{
  GamesScoresBackend *backend;
  gchar *fullname;

  backend = GAMES_SCORES_BACKEND (g_object_new (GAMES_TYPE_SCORES_BACKEND,
						NULL));

  if (name[0] == '\0')		/* Name is "" */
    fullname = g_strjoin (".", base_name, "scores", NULL);
  else
    fullname = g_strjoin (".", base_name, name, "scores", NULL);

  backend->priv->timestamp = 0;
  backend->priv->style = style;
  backend->scores_list = NULL;
  backend->priv->filename = g_build_filename (games_runtime_get_directory (GAMES_RUNTIME_SCORES_DIRECTORY),
                                              fullname, NULL);
  g_free (fullname);

  backend->priv->fd = -1;

  return backend;
}
Пример #3
0
void
bj_chip_set_size (gint width,
                  gint height)
{
        static const gchar *names[4] = { CHIP_FILENAME_100,
                                         CHIP_FILENAME_25,
                                         CHIP_FILENAME_5,
                                         CHIP_FILENAME_1 };
        const char *pixmapdir;

        pixmapdir = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);

        for (guint i = 0; i < G_N_ELEMENTS (names); i++) {
                gchar *fullname;

                fullname = g_build_filename (pixmapdir, names[i], NULL);

                if (!fullname)
                        continue;

		if (!chip_preimage[i])
			chip_preimage[i] = games_preimage_new_from_file (fullname,
									 NULL);

                if (chip_scaled_pixbuf[i])
                        g_object_unref (chip_scaled_pixbuf[i]);

                chip_scaled_pixbuf[i] = games_preimage_render (chip_preimage[i],
                                                               width,
                                                               height);
                g_free (fullname);
        }
}
Пример #4
0
GnibblesBoard *
gnibbles_board_new (void)
{
  gchar *filename;
  const char *dirname;
  GValue val = {0,};

  GnibblesBoard *board = g_new (GnibblesBoard, 1);
  board->width = BOARDWIDTH;
  board->height = BOARDHEIGHT;
  board->level = NULL;
  board->surface = NULL;

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);

  board->surface = clutter_texture_new_from_file (filename, NULL);

  clutter_actor_set_opacity (CLUTTER_ACTOR (board->surface), 100);
  g_value_init (&val, G_TYPE_BOOLEAN);
  g_value_set_boolean ( &val, TRUE);

  g_object_set_property (G_OBJECT (board->surface), "repeat-y", &val);
  g_object_set_property (G_OBJECT (board->surface), "repeat-x", &val);

  clutter_actor_set_position (CLUTTER_ACTOR (board->surface), 0, 0);
  clutter_actor_set_size (CLUTTER_ACTOR (board->surface),
                          properties->tilesize * BOARDWIDTH,
                          properties->tilesize * BOARDHEIGHT);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                               CLUTTER_ACTOR (board->surface));
  clutter_actor_show (CLUTTER_ACTOR (board->surface));

  return board;
}
Пример #5
0
/**
 * load_game_graphics
 *
 * Description:
 * Loads all of the game graphics
 *
 * Returns:
 * TRUE on success FALSE otherwise
 **/
gboolean
load_game_graphics (void)
{
  gchar *filename;
  const char *pixmapdir;

  if (theme_preimage != NULL) {
    free_game_graphics ();
  }

  pixmapdir = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = games_find_similar_file (properties_theme_name (), pixmapdir);

  theme_preimage = games_preimage_new_from_file (filename, NULL);
  g_free (filename);

  if (theme_preimage == NULL) {
    filename = games_find_similar_file ("robots", pixmapdir);
    theme_preimage = games_preimage_new_from_file (filename, NULL);
    g_free (filename);
  }

  if (!load_bubble_graphics ())
    return FALSE;

  rerender_needed = TRUE;

  return TRUE;
}
Пример #6
0
/**
 * fill_pmapmenu
 * @menu: menu
 *
 * Description:
 * fills the listbox with pixmap names
 **/
static GtkWidget *
make_theme_menu (void)
{
  const char *pixmapdir;

  if (theme_list)
    g_object_unref (theme_list);

  pixmapdir = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  theme_list = games_file_list_new_images (pixmapdir, NULL);
  games_file_list_transform_basename (theme_list);

  /* FIXME: Get rid of the bubbles images from the list (preferably by
   * getting tid of the bubble pixmaps. */

#if 0
  /* this is just a place holder so that xgettext can found the strings to
   * translate (those are the default graphic styles)
   */
  char *just_a_place_holder[] = {
    N_("robots"),
    N_("cows"),
    N_("eggs"),
    N_("gnomes"),
    N_("mice"),
    N_("ufo"),
    N_("boo"),
  };
#endif

  return games_file_list_create_widget (theme_list,
					properties.themename,
					GAMES_FILE_LIST_REMOVE_EXTENSION |
					GAMES_FILE_LIST_REPLACE_UNDERSCORES);
}
static gboolean
games_card_theme_svg_class_foreach_theme_dir (GamesCardThemeClass *klass,
                                              GamesCardThemeForeachFunc callback,
                                              gpointer data)
{
  if (!_games_card_theme_class_foreach_env (klass, "GAMES_CARD_THEME_PATH_SVG", callback, data))
    return FALSE;

  return callback (klass, games_runtime_get_directory (GAMES_RUNTIME_SCALABLE_CARDS_DIRECTORY), data);
}
Пример #8
0
/* This function is called as a separate thread, playing the sound. */
static void
games_sound_thread_run (gchar * data, gchar * user_data)
{
  const char *dir;
  char *uri;
  gboolean done = FALSE;
  GstBus *bus;

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  /* Set URL for sound to play. */
  dir = games_runtime_get_directory (GAMES_RUNTIME_SOUND_DIRECTORY);
  uri = g_strdup_printf ("file:///%s/%s.ogg", dir, (char *) data);
  g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
  g_free (uri);

  /* Set playbin to playing state. */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  do {
    GstMessage *message;

    /* wait for message on the bus */
    message = gst_bus_timed_pop (bus, GST_CLOCK_TIME_NONE);

    switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_EOS:
      done = TRUE;
      break;
    case GST_MESSAGE_ERROR:{
	GError *err;
	gchar *debug;

	gst_message_parse_error (message, &err, &debug);
        _games_debug_print (GAMES_DEBUG_SOUND,
                            "Error playing sound: %s\n", err->message);

	g_error_free (err);
	g_free (debug);

	done = TRUE;
	break;
      }
    default:
      break;
    }
    gst_message_unref (message);
  }
  while (!done);

  gst_element_set_state (pipeline, GST_STATE_NULL);
}
Пример #9
0
/**
 * games_runtime_get_file:
 * @runtime: the #GamesProgram instance
 * @directory:
 * @name:
 *
 * Returns: a newly allocated string containing the path to the file with name @name
 *   in the directory specicifed by @directory
 */
char *
games_runtime_get_file (GamesRuntimeDirectory directory,
                        const char *name)
{
  const char *dir;

  g_return_val_if_fail (app_name != NULL, NULL);

  dir = games_runtime_get_directory (directory);
  if (!dir)
    return NULL;

  return g_build_filename (dir, name, NULL);
}
Пример #10
0
void 
splash_new ()
{
        gchar *image_file;
        GtkWidget *splash_pixmap = NULL;
        GtkWidget *vbox;
        const char *pixmapdir;

        pixmapdir = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
        image_file = g_build_filename (pixmapdir, "blackjack-splash.png", NULL);

        if (image_file != NULL)
                splash_pixmap = gtk_image_new_from_file (image_file);

        g_free (image_file);

        progress = gtk_progress_bar_new ();
        label = gtk_label_new ("");

        splash = gtk_dialog_new ();

        gtk_window_set_position (GTK_WINDOW (splash), 
                                 GTK_WIN_POS_CENTER);
        gtk_window_set_title (GTK_WINDOW (splash), _("Blackjack"));
        gtk_window_set_resizable (GTK_WINDOW (splash), FALSE);

        g_signal_connect (splash, "destroy",
                          G_CALLBACK (splash_destroyed),
                          NULL);

        vbox = GTK_DIALOG (splash)->vbox;
  
        gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);

        if (splash_pixmap != NULL)
                gtk_box_pack_start (GTK_BOX (vbox), splash_pixmap, FALSE, FALSE, 6);
        gtk_box_pack_end (GTK_BOX (vbox), progress, FALSE, FALSE, 6);
        gtk_box_pack_end (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  
        gtk_widget_show_all (splash);

        /* Give window manager time to map the window */
        if (splash_pixmap != NULL) {
                g_signal_connect (splash_pixmap, "expose_event",
                                  G_CALLBACK (expose_event), NULL);
                waiting_for_expose = TRUE;
                gtk_main ();
                waiting_for_expose = FALSE;
        }
}
Пример #11
0
/**
 * games_runtime_get_directory:
 * @runtime: the #GamesProgram instance
 * @directory:
 *
 * Returns: the path to use for @directory
 */
const char *
games_runtime_get_directory (GamesRuntimeDirectory directory)
{

  char *path = NULL;

  g_return_val_if_fail (app_name != NULL, NULL);
  g_return_val_if_fail (directory >= 0 && directory < GAMES_RUNTIME_LAST_DIRECTORY, NULL);

  if (cached_directories[directory])
    return cached_directories[directory];

  switch ((int) directory) {
#ifndef G_OS_WIN32
    case GAMES_RUNTIME_DATA_DIRECTORY:
      path = g_strdup (DATADIR);
      break;

    case GAMES_RUNTIME_COMMON_DATA_DIRECTORY:
      path = g_build_filename (DATADIR, "gnome-games-common", NULL);
      break;

    case GAMES_RUNTIME_PKG_DATA_DIRECTORY:
      path = g_strdup (PKGDATADIR);
      break;

    case GAMES_RUNTIME_SCORES_DIRECTORY:
      path = g_strdup (SCORESDIR);
      break;

#else /* G_OS_WIN32 */
    case GAMES_RUNTIME_MODULE_DIRECTORY:
      path = g_win32_get_package_installation_directory_of_module (NULL);
      break;
#endif /* !G_OS_WIN32 */

    default: {
      const DerivedDirectory *base = &derived_directories[directory - GAMES_RUNTIME_FIRST_DERIVED_DIRECTORY];

      path = g_build_filename (games_runtime_get_directory (base->base_dir),
                               base->name ? base->name : app_name,
                               NULL);
    }
  }

  cached_directories[directory] = path;
  return path;
}
Пример #12
0
static gboolean
ar_card_theme_sliced_class_foreach_theme_dir (ArCardThemeClass *klass,
                                                 ArCardThemeForeachFunc callback,
                                                 gpointer data)
{
  char *dir;
  gboolean retval;

  if (!_ar_card_theme_class_foreach_env (klass, "AR_CARD_THEME_PATH_SLICED", callback, data))
    return FALSE;

  /* Themes in the pre-2.19 theme format: $(datadir)/pixmaps/mate-games-common/cards */
  dir = g_build_filename (games_runtime_get_directory (GAMES_RUNTIME_DATA_DIRECTORY),
                          "pixmaps", "mate-games-common", "cards", NULL);
  retval = callback (klass, dir, data);
  g_free (dir);

  return retval;
}
Пример #13
0
static GdkPixbuf *
gnibbles_load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
{
  GdkPixbuf *image;
  gchar *filename;
  const char *dirname;

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = g_build_filename (dirname, pixmap, NULL);

  if (!filename) {
    char *message =
      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
                       "Please check your Nibbles installation"), pixmap);
    gnibbles_error (message);
    g_free(message);
  }

  image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
  g_free (filename);

  return image;
}
Пример #14
0
/**
 * load_bubble_graphics
 *
 * Description:
 * Loads all of the 'speech bubble' graphics
 *
 * Returns:
 * TRUE on success FALSE otherwise
 **/
static gboolean
load_bubble_graphics (void)
{
  gchar *buffer = NULL;
  const char *dname;

  dname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);

  buffer = g_build_filename (dname, "yahoo.png", NULL);
  if (!load_bubble_graphic (buffer, &yahoo_pixbuf))
    return FALSE;
  g_free (buffer);

  buffer = g_build_filename (dname, "aieee.png", NULL);
  if (!load_bubble_graphic (buffer, &aieee_pixbuf))
    return FALSE;

  buffer = g_build_filename (dname, "splat.png", NULL);
  if (!load_bubble_graphic (buffer, &splat_pixbuf))
    return FALSE;

  return TRUE;
}
Пример #15
0
void
gnibbles_board_level_new (GnibblesBoard *board, gint level)
{

  gchar *tmp = NULL;
  const char *dirname;
  gchar *filename;
  FILE *in;
  gchar tmpboard [BOARDWIDTH +2];
  gint i,j;
  gint count = 0;

  board->current_level = level;

  tmp = g_strdup_printf("level%03d.gnl", level);

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_GAMES_DIRECTORY);
  filename = g_build_filename (dirname, tmp, NULL);

  g_free (tmp);

  if ((in = fopen (filename, "r")) == NULL) {
    char *message =
      g_strdup_printf (_("Nibbles couldn't load level file:\n%s\n\n"
                        "Please check your Nibbles installation"), filename);
    gnibbles_error (message);
    g_free (message);
  }

  if (warpmanager)
    gnibbles_warpmanager_destroy (warpmanager);

  warpmanager = gnibbles_warpmanager_new ();

  if (boni)
    gnibbles_boni_destroy (boni);

  boni = gnibbles_boni_new ();

  for (i = 0; i < BOARDHEIGHT; i++) {
    if (!fgets (tmpboard, sizeof (tmpboard), in)) {
      char *message =
        g_strdup_printf (_("Level file appears to be damaged:\n%s\n\n"
                         "Please check your Nibbles installation"), filename);
      gnibbles_error (message);
      g_free (message);
      break;
    }

    for (j = 0; j < BOARDWIDTH; j++) {
      board->walls[j][i] = tmpboard[j];
      switch (board->walls[j][i]) {
        case 'm':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
          break;
        case 'n':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start(worms[count++], j, i, WORMLEFT);
          break;
        case 'o':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
          break;
        case 'p':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
          break;
        case 'Q':
          gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
          break;
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
          gnibbles_warpmanager_add_warp
            (warpmanager, j - 1, i - 1, -(board->walls[j][i]), 0);
          break;
        case 'r':
        case 's':
        case 't':
        case 'u':
        case 'v':
        case 'w':
        case 'x':
        case 'y':
        case 'z':
          gnibbles_warpmanager_add_warp
            (warpmanager, -(board->walls[j][i] - 'a' + 'A'), 0, j, i);
          board->walls[j][i] = EMPTYCHAR;
          break;
       }
    }
  }

  g_free (filename);
  fclose (in);

  for (i = 0; i < count; i++) {
    if (worms[i]->direction == WORMRIGHT) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->xtail++;
    } else if ( worms[i]->direction == WORMLEFT) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->xtail--;
    } else if (worms[i]->direction == WORMDOWN) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->ytail++;
    } else if (worms[i]->direction == WORMUP) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->ytail--;
    }
    board->walls[worms[i]->xtail][worms[i]->ytail] = EMPTYCHAR;
  }
  gnibbles_board_load_level (board);
}
Пример #16
0
Tetris::Tetris(int cmdlLevel):
	themeno (0),
	field(0),
	paused(false),
	timeoutId(0),
	onePause(false),
	inPlay(false),
	useTarget(false),
	bgimage(0),
	setupdialog(0),
	cmdlineLevel(cmdlLevel),
	fastFall(false),
	dropBlock(false)
{
	GtkUIManager *ui_manager;
	GtkAccelGroup *accel_group;
	GtkActionGroup *action_group;
	GtkWidget *vbox;
	GtkWidget *aspect_frame;
	GtkWidget *menubar;

	gchar *outdir;
	const char *dname;

	const GtkTargetEntry targets[] = {{(gchar*) "text/uri-list", 0, URI_LIST},
					  {(gchar*) "property/bgimage", 0, URI_LIST},
					  {(gchar*) "text/plain", 0, TEXT_PLAIN},
					  {(gchar*) "STRING", 0, TEXT_PLAIN},
					  {(gchar*) "application/x-color", 0, COLOUR},
					  {(gchar*) "x-special/gnome-reset-background", 0, RESET}};

	const GtkActionEntry actions[] = {
	{ "GameMenu", NULL, N_("_Game") },
	{ "SettingsMenu", NULL, N_("_Settings") },
	{ "HelpMenu", NULL, N_("_Help") },
	{ "NewGame", GAMES_STOCK_NEW_GAME, NULL, NULL, NULL, G_CALLBACK (gameNew) },
	{ "Pause", GAMES_STOCK_PAUSE_GAME, NULL, NULL, NULL, G_CALLBACK (gamePause) },
	{ "Resume", GAMES_STOCK_RESUME_GAME, NULL, NULL, NULL, G_CALLBACK (gamePause) },
	{ "Scores", GAMES_STOCK_SCORES, NULL, NULL, NULL, G_CALLBACK (gameTopTen) },
	{ "EndGame", GAMES_STOCK_END_GAME, NULL, NULL, NULL, G_CALLBACK (gameEnd) },
	{ "Quit", GTK_STOCK_QUIT, NULL, NULL, NULL, G_CALLBACK (gameQuit) },
	{ "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, NULL, G_CALLBACK (gameProperties) },
#ifdef WITH_GAMEPLAYDOC
	{ "Contents", GAMES_STOCK_CONTENTS, NULL, NULL, NULL, G_CALLBACK (gameHelp) },
#endif
	{ "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK (gameAbout) }
	};

	const char ui_description[] =
	"<ui>"
	"  <menubar name='MainMenu'>"
	"    <menu action='GameMenu'>"
	"      <menuitem action='NewGame'/>"
	"      <menuitem action='Pause'/>"
	"      <menuitem action='Resume'/>"
	"      <separator/>"
	"      <menuitem action='Scores'/>"
	"      <menuitem action='EndGame'/>"
	"      <separator/>"
	"      <menuitem action='Quit'/>"
	"    </menu>"
	"    <menu action='SettingsMenu'>"
	"      <menuitem action='Preferences'/>"
	"    </menu>"
	"    <menu action='HelpMenu'>"
#ifdef WITH_GAMEPLAYDOC
	"      <menuitem action='Contents'/>"
#endif
	"      <menuitem action='About'/>"
	"    </menu>"
	"  </menubar>"
	"</ui>";


	/* Locate our background image. */

	outdir = g_build_filename (g_get_user_data_dir (), "gnometris", NULL);
	if (!g_file_test (outdir, G_FILE_TEST_EXISTS))
#ifdef _WIN32
	    mkdir (outdir);
#else
	    mkdir (outdir, 0700);
#endif
	bgPixmap = g_build_filename (outdir, "background.bin", NULL);
	g_free (outdir);

	/*  Use default background image, if none found in user's home dir.*/
	if (!g_file_test (bgPixmap, G_FILE_TEST_EXISTS)) {
		dname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
		defaultPixmap = g_build_filename (dname, "gnometris.svg", NULL);
		default_bgimage = true;
	}

	w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (w), _("Gnometris"));

	g_signal_connect (w, "delete_event", G_CALLBACK (gameQuit), this);
	gtk_drag_dest_set (w, GTK_DEST_DEFAULT_ALL, targets,
			   G_N_ELEMENTS(targets),
			   GDK_ACTION_MOVE);
	g_signal_connect (G_OBJECT (w), "drag_data_received",
			  G_CALLBACK (dragDrop), this);
	g_signal_connect (G_OBJECT (w), "focus_out_event",
			  G_CALLBACK (focusOut), this);

	line_fill_height = 0;
	line_fill_prob = 5;

	gtk_window_set_default_size (GTK_WINDOW (w), DEFAULT_WIDTH, DEFAULT_HEIGHT);
	games_conf_add_window (GTK_WINDOW (w), KEY_SAVED_GROUP);

	preview = new Preview ();
	field = new Field();
	field->setUseTarget (false);

	initOptions ();

	/* prepare menus */
	games_stock_init ();
	action_group = gtk_action_group_new ("MenuActions");
	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
	gtk_action_group_add_actions (action_group, actions, G_N_ELEMENTS (actions), this);
	ui_manager = gtk_ui_manager_new ();
	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
	gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL);
	accel_group = gtk_ui_manager_get_accel_group (ui_manager);
	gtk_window_add_accel_group (GTK_WINDOW (w), accel_group);

	new_game_action = gtk_action_group_get_action (action_group, "NewGame");
	pause_action = gtk_action_group_get_action (action_group, "Pause");
	resume_action = gtk_action_group_get_action (action_group, "Resume");
	scores_action = gtk_action_group_get_action (action_group, "Scores");
	end_game_action = gtk_action_group_get_action (action_group, "EndGame");
	preferences_action = gtk_action_group_get_action (action_group, "Preferences");

	games_stock_set_pause_actions (pause_action, resume_action);

	menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");

	GtkWidget * hb = gtk_hbox_new(FALSE, 0);

	vbox = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (w), vbox);
	gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox), hb, TRUE, TRUE, 0);

	aspect_frame = gtk_aspect_frame_new (NULL, 0.5, 0.5, (float) COLUMNS / (float) LINES, FALSE);
	gtk_frame_set_shadow_type (GTK_FRAME (aspect_frame), GTK_SHADOW_NONE);
	gtk_container_add (GTK_CONTAINER (aspect_frame), field->getWidget());

	gtk_widget_set_events(w, gtk_widget_get_events(w) |
						  GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);

	GtkWidget *vb1 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vb1), 10);
	gtk_box_pack_start(GTK_BOX(vb1), aspect_frame, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(hb), vb1, TRUE, TRUE, 0);

	setupPixmap();

	g_signal_connect (w, "key_press_event", G_CALLBACK (keyPressHandler), this);
	g_signal_connect (w, "key_release_event", G_CALLBACK (keyReleaseHandler), this);

	GtkWidget *vb2 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vb2), 10);
	gtk_box_pack_end(GTK_BOX(hb), vb2, 0, 0, 0);

	gtk_box_pack_start(GTK_BOX(vb2), preview->getWidget(), FALSE, FALSE, 0);

	scoreFrame = new ScoreFrame(cmdlineLevel);

	gtk_box_pack_end(GTK_BOX(vb2), scoreFrame->getWidget(), TRUE, FALSE, 0);
	high_scores = new HighScores ();

	setOptions ();

	themeList = NULL;

	gtk_widget_show(vbox);
	gtk_widget_show(hb);
	gtk_widget_show(vb1);
	gtk_widget_show(vb2);
	gtk_widget_show(aspect_frame);
	gtk_widget_show(field->getWidget());
	gtk_widget_show(preview->getWidget());
	scoreFrame->show();
	gtk_widget_show(w);

	gtk_action_set_sensitive(pause_action, FALSE);
	gtk_action_set_sensitive(end_game_action, FALSE);
	gtk_action_set_sensitive(preferences_action, TRUE);

	confNotifyID = g_signal_connect (games_conf_get_default (),
					 "value-changed",
					 G_CALLBACK (confNotify),
					 this);
}
Пример #17
0
GnibblesBoard *
gnibbles_board_new (gint t_w, gint t_h) 
{
  ClutterColor stage_color = {0x00,0x00,0x00,0xff};

  GnibblesBoard *board = g_new (GnibblesBoard, 1);
  board->width = t_w;
  board->height = t_h;
  board->level = NULL;
  board->surface =NULL;
  board->clutter_widget = gtk_clutter_embed_new ();

  ClutterActor *stage;

  load_pixmap ();

  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget));
  clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);

  clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE); 
  clutter_actor_set_size (CLUTTER_ACTOR (stage), 
                        properties->tilesize * BOARDWIDTH,
                        properties->tilesize * BOARDHEIGHT);
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
  clutter_actor_show (stage);

  gchar *filename;
  const char *dirname;

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);

  /* Using ClutterScript to set special texture property such as "repeat-x",
   * "repeat-y" and "keep-aspect-ratio" */
  gchar texture_script[200];

  g_sprintf (texture_script, "["
                             "  {"
                             "    \"id\" : \"surface\","
                             "    \"type\" : \"ClutterTexture\","
                             "    \"filename\" : \"%s\","
                             "    \"x\" : 0,"
                             "    \"y\" : 0,"
                             "    \"width\" : %d,"
                             "    \"height\" : %d,"
                             "    \"keep-aspect-ratio\" : true"
                             "    \"visible\" : true,"
                             "    \"repeat-x\" : true,"
                             "    \"repeat-y\" : true"
                             "  }"
                             "]",
                             filename,
                             properties->tilesize,
                             properties->tilesize);

  ClutterScript *script = clutter_script_new ();

  clutter_script_load_from_data (script, texture_script, -1, NULL);
  clutter_script_get_objects (script, "surface", &(board->surface), NULL);

  clutter_actor_set_size (CLUTTER_ACTOR (board->surface),
                          properties->tilesize * BOARDWIDTH,
                          properties->tilesize * BOARDHEIGHT);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->surface);
  clutter_actor_show (board->surface);

  g_object_unref (script);
  return board;
}