Beispiel #1
0
static GtkWidget *build_screenshot_dialog(void)
{
    GtkWidget *d, *box, *frame, *vbox, *omenu;
    int i, num_buttons;
    gfxoutputdrv_t *driver;
#ifdef HAVE_FFMPEG
    GtkWidget *l, *hbox, *tmp;
    GtkObject *adj;
    int audio_bitrate, video_bitrate;
    ffmpegdrv_format_t *f;
    GtkListStore *drv_store;
    GtkTreeIter iter;
    GtkCellRenderer *renderer;
    GtkListStore *ac_store = NULL, *vc_store = NULL;
#endif

    num_buttons = gfxoutput_num_drivers();
    if (num_buttons < 1)
    {
	log_message(LOG_DEFAULT, _("No gfxoutputdrivers available"));
	return 0;
    }

    d = gtk_dialog_new_with_buttons(_("Save Screenshot"), 
			 NULL,
			 GTK_DIALOG_DESTROY_WITH_PARENT,
			 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
			 NULL);
    box = gtk_hbox_new(0, FALSE);

    fileentry = vice_file_entry(_("Save Media File..."),  
				NULL, NULL, 
				GTK_FILE_CHOOSER_ACTION_SAVE);
    if (!fileentry)
    {
	gtk_widget_destroy(d);
	return 0;
    }
    gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_ACCEPT);

    gtk_box_pack_start(GTK_BOX(box), fileentry,
		       TRUE, TRUE, 0);
    gtk_widget_show(fileentry);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), box, TRUE, TRUE, 0);
    gtk_widget_show(box);

    frame = gtk_frame_new(_("Image Format"));
    vbox = gtk_vbox_new(FALSE, 5);

    if (! buttons)
	buttons = lib_malloc(sizeof(img_type_buttons) * num_buttons);

    drv_menu = omenu = gtk_combo_box_new_text ();

    driver = gfxoutput_drivers_iter_init();
    for (i = 0; i < num_buttons; i++) {
	gtk_combo_box_append_text(GTK_COMBO_BOX(omenu), driver->displayname);
 	buttons[i].driver = driver->name;
	buttons[i].ext = driver->default_extension;
	driver = gfxoutput_drivers_iter_next();
    }
    gtk_combo_box_set_active(GTK_COMBO_BOX(omenu), 0);
    gtk_box_pack_start(GTK_BOX(vbox), omenu, FALSE, FALSE, 0);
    gtk_widget_show(omenu);

#ifdef HAVE_FFMPEG
    if (!ffmpegdrv_formatlist[0].name)
	goto no_ffmpeg;
    
    g_signal_connect(G_OBJECT(omenu), "changed",
		     G_CALLBACK(ffmpeg_widget), (gpointer) omenu);

    /* ffmpg options */
    ffmpg_opts = gtk_vbox_new(FALSE, 5);

    drv_store = gtk_list_store_new(DRV_N, G_TYPE_STRING, G_TYPE_INT, 
				   G_TYPE_OBJECT, G_TYPE_OBJECT);
    for (i = 0; ffmpegdrv_formatlist[i].name != NULL; i++)
    {
	int j;
	GtkTreeIter ac_iter, vc_iter;
	
	f = &ffmpegdrv_formatlist[i];

	gtk_list_store_append(drv_store, &iter);
	gtk_list_store_set(drv_store, &iter, DRV_NAME, f->name, 
			   DRV_INDEX, i, -1);

	log_message(LOG_DEFAULT, _("FFMPEG Driver: %s"), f->name);

	ac_store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
	for (j = 0; f->audio_codecs && f->audio_codecs[j].name; j++)
	{
	    gtk_list_store_append(ac_store, &ac_iter);
	    gtk_list_store_set(ac_store, &ac_iter, 
			       0, f->audio_codecs[j].name,
			       1, f->audio_codecs[j].id, 
			       2, j, -1);
	    log_message(LOG_DEFAULT, _("\tAC: %s(%d)"), 
			f->audio_codecs[j].name,
			f->audio_codecs[j].id);
	}

	vc_store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
	for (j = 0; f->video_codecs && f->video_codecs[j].name; j++)
	{
	    gtk_list_store_append(vc_store, &vc_iter);
	    gtk_list_store_set(vc_store, &vc_iter, 
			       0, f->video_codecs[j].name,
			       1, f->video_codecs[j].id, 
			       2, j, -1);
	    log_message(LOG_DEFAULT, _("\tVC: %s(%d)"), 
			f->video_codecs[j].name,
			f->video_codecs[j].id);
	}

	gtk_list_store_set(drv_store, &iter, 
			   DRV_ACMENU, ac_store, 
			   DRV_VCMENU, vc_store, -1);
    }

    ffmpeg_omenu = omenu = gtk_combo_box_new_with_model(GTK_TREE_MODEL(drv_store));    
    g_signal_connect(G_OBJECT(omenu), "changed",
		     G_CALLBACK(ffmpeg_details), (gpointer) omenu);
    renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (omenu), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (omenu), renderer,
				    "text", DRV_NAME, NULL);

    hbox = gtk_hbox_new(0, FALSE);
    tmp = gtk_label_new(_("Format"));
    gtk_box_pack_start(GTK_BOX(hbox), tmp, FALSE, FALSE, 0);
    gtk_widget_show(tmp);
    gtk_box_pack_start(GTK_BOX(hbox), omenu, FALSE, FALSE, 0);
    gtk_widget_show(omenu);
    gtk_box_pack_start(GTK_BOX(ffmpg_opts), hbox, FALSE, FALSE, 0);
    gtk_widget_show(hbox);
    
    acmenu = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ac_store));    
    renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (acmenu), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (acmenu), renderer,
				    "text", 0, NULL);
    hbox = gtk_hbox_new(0, FALSE);
    tmp = gtk_label_new(_("Audio Codec"));
    gtk_box_pack_start(GTK_BOX(hbox), tmp, FALSE, FALSE, 0);
    gtk_widget_show(tmp);
    gtk_box_pack_start(GTK_BOX(hbox), acmenu, FALSE, FALSE, 0);
    gtk_widget_show(acmenu);
    gtk_box_pack_start(GTK_BOX(ffmpg_opts), hbox, FALSE, FALSE, 0);
    gtk_widget_show(hbox);

    vcmenu = gtk_combo_box_new_with_model(GTK_TREE_MODEL(vc_store));    
    renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (vcmenu), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (vcmenu), renderer,
				    "text", 0, NULL);
    hbox = gtk_hbox_new(0, FALSE);
    tmp = gtk_label_new(_("Video Codec"));
    gtk_box_pack_start(GTK_BOX(hbox), tmp, FALSE, FALSE, 0);
    gtk_widget_show(tmp);
    gtk_box_pack_start(GTK_BOX(hbox), vcmenu, FALSE, FALSE, 0);
    gtk_widget_show(vcmenu);
    gtk_box_pack_start(GTK_BOX(ffmpg_opts), hbox, FALSE, FALSE, 0);
    gtk_widget_show(hbox);

    resources_get_int("FFMPEGAudioBitrate", &audio_bitrate);
    adj = gtk_adjustment_new ((gfloat) audio_bitrate, 
			      (gfloat) 16000, 
			      (gfloat) 128000,
			      (gfloat) 1000,
			      (gfloat) 10000,
			      (gfloat) 10000);
    ffmpg_audio = gtk_spin_button_new(GTK_ADJUSTMENT(adj), (gfloat) 1000, 0);
    gtk_widget_set_size_request(ffmpg_audio, 100, -1);
    l = gtk_label_new(_("Audio Bitrate"));
    tmp = gtk_hbox_new(FALSE, 5);
    gtk_box_pack_start(GTK_BOX(tmp), l, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(tmp), ffmpg_audio, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(ffmpg_opts), tmp, FALSE, FALSE, 0);
    
    resources_get_int("FFMPEGVideoBitrate", &video_bitrate);
    adj = gtk_adjustment_new ((gfloat) video_bitrate, 
			      (gfloat) 100000, 
			      (gfloat) 10000000,
			      (gfloat) 10000,
			      (gfloat) 100000,
			      (gfloat) 100000);
    ffmpg_video = gtk_spin_button_new(GTK_ADJUSTMENT(adj), (gfloat) 10000, 0);
    gtk_widget_set_size_request(ffmpg_video, 100, -1);
    l = gtk_label_new(_("Video Bitrate"));
    tmp = gtk_hbox_new(FALSE, 5);
    gtk_box_pack_start(GTK_BOX(tmp), l, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(tmp), ffmpg_video, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(ffmpg_opts), tmp, FALSE, FALSE, 0);

    gtk_box_pack_start(GTK_BOX(vbox), ffmpg_opts, FALSE, FALSE, 0);
    gtk_widget_show_all(ffmpg_opts);
    gtk_widget_set_sensitive(ffmpg_opts, FALSE);
  no_ffmpeg:
#endif    

    gtk_container_add(GTK_CONTAINER(frame), vbox);
    gtk_widget_show(vbox);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), frame, TRUE, TRUE, 0);
    gtk_widget_show(frame);
    gtk_widget_show(d);

    return d;
}
Beispiel #2
0
int ui_screenshot_dialog(char *name, struct video_canvas_s *wid)
{
    int res, i, driveridx = -1;
    char *fn, *tmp, *tmpext;
    const char *driver, *ext;

    if (screenshot_dialog) {
        gdk_window_show(screenshot_dialog->window);
        gdk_window_raise(screenshot_dialog->window);
        gtk_widget_show(screenshot_dialog);
        gtk_combo_box_set_active(GTK_COMBO_BOX(drv_menu), combo_box_current_active);
    } else {
        screenshot_dialog = build_screenshot_dialog();
        if (screenshot_dialog) {
            g_signal_connect(G_OBJECT(screenshot_dialog), "destroy", G_CALLBACK(gtk_widget_destroyed), &screenshot_dialog);
        } else {
            return -1;
        }
    }

    ui_popup(screenshot_dialog, _("Save screenshot file"), FALSE);
    res = gtk_dialog_run(GTK_DIALOG(screenshot_dialog));
    ui_popdown(screenshot_dialog);

    if (res != GTK_RESPONSE_ACCEPT) {
        return -1;
    }

    fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(screenshot_dialog));
    if (!fn) {
        ui_error(_("Invalid filename"));
        return -1;
    }

    tmpext = util_get_extension(fn);
    if (tmpext) {
        for (i = 0; i < gfxoutput_num_drivers(); i++) {
            if (buttons[i].ext && !strcmp(buttons[i].ext, tmpext)) {
                driveridx = i;
                break;
            }
        }
    }

    i = gtk_combo_box_get_active(GTK_COMBO_BOX(drv_menu));
    if (i < 0) {
        return -1;
    }
    if ((driveridx != -1) && (driveridx != i)) {
        i = driveridx;
    }
    combo_box_current_active = i;

    driver = buttons[i].driver;
    ext = buttons[i].ext;

#ifdef HAVE_FFMPEG
    if (strcmp(driver, "FFMPEG") == 0) {
        int audio_bitrate, video_bitrate;

        audio_bitrate = (int)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ffmpg_audio));
        resources_set_int("FFMPEGAudioBitrate", audio_bitrate);
        video_bitrate = (int)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ffmpg_video));
        resources_set_int("FFMPEGVideoBitrate", video_bitrate);

        resources_set_string("FFMPEGFormat", selected_driver);
        resources_set_int("FFMPEGAudioCodec", selected_ac);
        resources_set_int("FFMPEGVideoCodec", selected_vc);
        log_message(LOG_DEFAULT, "FFMPEG: Driver: %s, ac: %d, vc: %d\n", selected_driver, selected_ac, selected_vc);
    }
#endif
    tmp = lib_stralloc(fn);
    lib_free(fn);
    if (!util_get_extension(tmp)) {
        util_add_extension(&tmp, ext);
    }
    if (screenshot_save(driver, tmp, wid) < 0) {
        ui_error(_("Couldn't write screenshot to `%s' with driver `%s'."), tmp, driver);
        lib_free(tmp);
        return -1;
    } else {
        if (screenshot_is_recording()) {
            gtk_widget_show(video_ctrl_checkbox);
        }
        ui_message(_("Successfully wrote `%s'"), tmp);
        lib_free(tmp);
    }

    return 0;
}