Font *Gui::loadThemeFont(const char *dir, const char *what, int size)
{
	TTF_Font *fnt;

	fnt = read_and_alloc_font(get_theme_path(dir, what), size);
	if (!fnt)
		return NULL;

	return new Font_TTF(fnt, 255,255,255);
}
SDL_Surface *Gui::loadThemeImage(const char *dir, const char *what)
{
	SDL_Surface *img = IMG_Load(get_theme_path(dir, what));
	SDL_Surface *out;

	if (!img)
		return NULL;
	out = SDL_DisplayFormat(img);
	SDL_FreeSurface(img);

	return out;
}
SDL_Surface *Gui::loadThemeImage(const char *dir, const char *what)
{
	SDL_Surface *img = IMG_Load(get_theme_path(dir, what));
	SDL_Surface *out;

	if (!img)
		return NULL;
	out = SDL_ConvertSurface(img, pixel_format, 0);
	if (!out)
		return img;
	SDL_FreeSurface(img);

	return out;
}
Exemple #4
0
gint
main (gint argc, gchar *argv[])
{
    gtk_init (&argc, &argv);
    g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", TRUE, NULL);

    gsize size = DEFAULT_SIZE;
    guint32 target = DEFAULT_TARGET;
    const gchar *theme = DEFAULT_THEME;

    GOptionEntry options[] = {
        { "size",   's',  0, G_OPTION_ARG_INT,    &size,   "The size of the grid", "4"           },
        { "target", '\0', 0, G_OPTION_ARG_INT,    &target, "The tile to reach",    "2048"        },
        { "theme",  't',  0, G_OPTION_ARG_STRING, &theme,  "The theme to use",     DEFAULT_THEME },
        { NULL,     '\0', 0, G_OPTION_ARG_NONE,   NULL,    NULL,                   NULL          }
    };
    G_2048_CLEANUP_OPTIONS_FREE GOptionContext *ctx = g_option_context_new ("foobar");
    g_option_context_add_main_entries (ctx, options, NULL);
    g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
    g_option_context_parse (ctx, &argc, &argv, NULL);

    GtkApplication *app = gtk_application_new ("org.gnome.g2048", G_APPLICATION_FLAGS_NONE);
    GApplication *gapp = G_APPLICATION (app);
    G_2048_CLEANUP_ERROR_FREE GError *error = NULL;
    G_APPLICATION_GET_CLASS (gapp)->activate = show_win;

    g_application_register (gapp, NULL, &error);
    if (error)
    {
        fprintf (stderr, "Failed to register the gtk application: %s\n", error->message);
        return EXIT_FAILURE;
    }
    if (g_application_get_is_remote (gapp))
    {
        g_application_activate (gapp);
        return EXIT_SUCCESS;
    }

    G_2048_CLEANUP_FREE gchar *theme_path = get_theme_path (theme);
    if (!theme_path)
        theme_path = get_theme_path (DEFAULT_THEME);
    if (!theme_path)
    {
        g_critical ("No theme found");
        exit (EXIT_FAILURE);
    }

    GtkWidget *score_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
    GtkBox *hbox = GTK_BOX (score_box);
    gtk_box_pack_start (hbox, gtk_label_new ("Score:"), TRUE, TRUE, 0);

    GtkWidget *score_label = gtk_label_new ("0");
    GtkLabel *label = GTK_LABEL (score_label);
    GdkRGBA color;
    gdk_rgba_parse (&color, "white");
    gtk_widget_override_background_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gdk_rgba_parse (&color, "black");
    gtk_widget_override_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gtk_label_set_width_chars (GTK_LABEL (score_label), 8);
    gtk_box_pack_end (hbox, score_label, TRUE, FALSE, 0);

    GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    GtkBox *vbox = GTK_BOX (box);
    gtk_box_pack_start (vbox, g_2048_grid_new (size, target, theme_path, label), TRUE, TRUE, 0);
    gtk_box_pack_end (vbox, score_box, TRUE, TRUE, 20);

    GtkWidget *win = gtk_widget_new (GTK_TYPE_APPLICATION_WINDOW,
                                     "application",     app,
                                     "type",            GTK_WINDOW_TOPLEVEL,
                                     "window-position", GTK_WIN_POS_CENTER,
                                     "resizable",       FALSE,
                                     NULL);
    gtk_container_add (GTK_CONTAINER (win), box);
    gtk_widget_show_all (win);
    gtk_widget_override_font (win, pango_font_description_from_string("Monospace 18"));
    GTK_WIDGET_GET_CLASS (win)->key_press_event = on_key;

    return g_application_run (gapp, argc, argv);
}