2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-09 05:44:52 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-07-09 05:44:52 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-07-09 05:44:52 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-07-09 05:44:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2001-07-09 05:44:52 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "actions-types.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
#include "core/gimp.h"
|
2004-07-22 21:58:29 +08:00
|
|
|
#include "core/gimpgradient-save.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2003-01-13 22:08:10 +08:00
|
|
|
#include "widgets/gimpcontainereditor.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "widgets/gimpcontainerview.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2024-01-28 14:21:23 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
#include "dialogs/dialogs.h"
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "gradients-commands.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-10-18 19:29:58 +08:00
|
|
|
static void gradients_save_as_pov_ray_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradient *gradient);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
gradients_save_as_pov_ray_cmd_callback (GimpAction *action,
|
2019-07-04 07:11:48 +08:00
|
|
|
GVariant *value,
|
2019-07-02 22:12:18 +08:00
|
|
|
gpointer data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-02-01 04:23:53 +08:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
2004-10-18 19:29:58 +08:00
|
|
|
GimpContext *context;
|
|
|
|
GimpGradient *gradient;
|
2016-09-26 04:18:37 +08:00
|
|
|
GtkWidget *dialog;
|
2004-05-11 01:16:50 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
context = gimp_container_view_get_context (editor->view);
|
2004-05-11 01:16:50 +08:00
|
|
|
gradient = gimp_context_get_gradient (context);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
if (! gradient)
|
|
|
|
return;
|
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
#define SAVE_AS_POV_DIALOG_KEY "gimp-save-as-pov-ray-dialog"
|
|
|
|
|
|
|
|
dialog = dialogs_get_dialog (G_OBJECT (gradient), SAVE_AS_POV_DIALOG_KEY);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
if (! dialog)
|
|
|
|
{
|
|
|
|
gchar *title = g_strdup_printf (_("Save '%s' as POV-Ray"),
|
|
|
|
gimp_object_get_name (gradient));
|
2004-04-16 00:28:26 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
dialog = gtk_file_chooser_dialog_new (title, NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
2004-04-16 00:28:26 +08:00
|
|
|
|
2017-02-12 23:06:34 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Save"), GTK_RESPONSE_OK,
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
NULL);
|
2005-02-10 19:00:46 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
g_free (title);
|
2006-10-10 02:49:15 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2024-01-28 14:21:23 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp", context->gimp);
|
2003-11-10 06:05:37 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (dialog),
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (editor)));
|
|
|
|
gtk_window_set_role (GTK_WINDOW (dialog), "gimp-gradient-save-pov");
|
|
|
|
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
|
|
|
|
TRUE);
|
2007-02-02 15:50:36 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gradients_save_as_pov_ray_response),
|
|
|
|
gradient);
|
|
|
|
g_signal_connect (dialog, "delete-event",
|
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
g_signal_connect_object (dialog, "destroy",
|
|
|
|
G_CALLBACK (g_object_unref),
|
|
|
|
g_object_ref (gradient),
|
|
|
|
G_CONNECT_SWAPPED);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2024-08-25 05:03:04 +08:00
|
|
|
gimp_help_connect (dialog, NULL, gimp_standard_help_func,
|
2019-08-09 19:11:30 +08:00
|
|
|
GIMP_HELP_GRADIENT_SAVE_AS_POV, NULL, NULL);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
dialogs_attach_dialog (G_OBJECT (gradient),
|
|
|
|
SAVE_AS_POV_DIALOG_KEY, dialog);
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2016-09-26 04:18:37 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2024-01-28 14:21:23 +08:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2024-04-11 22:59:15 +08:00
|
|
|
gimp_window_set_title_bar_theme (context->gimp, dialog);
|
2024-01-28 14:21:23 +08:00
|
|
|
#endif
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2004-10-18 19:29:58 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
static void
|
2004-10-18 19:29:58 +08:00
|
|
|
gradients_save_as_pov_ray_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradient *gradient)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2016-09-26 04:18:37 +08:00
|
|
|
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
2014-07-01 21:56:39 +08:00
|
|
|
GError *error = NULL;
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2014-07-01 21:56:39 +08:00
|
|
|
if (! gimp_gradient_save_pov (gradient, file, &error))
|
2003-11-18 02:29:59 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (g_object_get_data (G_OBJECT (dialog), "gimp"),
|
2013-09-15 00:59:20 +08:00
|
|
|
G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
|
|
|
|
error->message);
|
2003-11-18 02:29:59 +08:00
|
|
|
g_clear_error (&error);
|
2014-07-01 21:56:39 +08:00
|
|
|
g_object_unref (file);
|
2006-10-10 02:49:15 +08:00
|
|
|
return;
|
2003-11-18 02:29:59 +08:00
|
|
|
}
|
2014-07-01 21:56:39 +08:00
|
|
|
|
|
|
|
g_object_unref (file);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|