1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-07-03 10:27:32 +08:00
|
|
|
#include <glib.h> /* Include early for obscure Win32
|
|
|
|
build reasons */
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1999-04-26 03:30:31 +08:00
|
|
|
#include <sys/types.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#include <gtk/gtk.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2002-02-17 23:55:54 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "siod.h"
|
|
|
|
#include "script-fu-scripts.h"
|
|
|
|
|
2000-02-28 03:35:39 +08:00
|
|
|
#include "script-fu-intl.h"
|
2000-02-01 04:47:44 +08:00
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#define TEXT_WIDTH 100
|
|
|
|
#define COLOR_SAMPLE_WIDTH 100
|
|
|
|
#define COLOR_SAMPLE_HEIGHT 15
|
|
|
|
#define SLIDER_WIDTH 100
|
|
|
|
#define FONT_PREVIEW_WIDTH 100
|
1998-08-10 23:06:58 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#define DEFAULT_FONT_SIZE 240
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
#define MAX_STRING_LENGTH 4096
|
1998-08-06 05:36:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
gfloat value;
|
|
|
|
gfloat lower;
|
|
|
|
gfloat upper;
|
|
|
|
gfloat step;
|
|
|
|
gfloat page;
|
|
|
|
gint digits;
|
|
|
|
SFAdjustmentType type;
|
1998-08-06 22:58:39 +08:00
|
|
|
} SFAdjustment;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
gchar *fontname;
|
|
|
|
} SFFont;
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
1999-05-19 01:33:39 +08:00
|
|
|
GtkWidget *fileselection;
|
1998-11-06 08:51:39 +08:00
|
|
|
gchar *filename;
|
|
|
|
} SFFilename;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
gchar *name;
|
1998-10-21 06:36:52 +08:00
|
|
|
gdouble opacity;
|
|
|
|
gint spacing;
|
|
|
|
gint paint_mode;
|
|
|
|
} SFBrush;
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
guint history;
|
|
|
|
} SFOption;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
typedef union
|
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
gint32 sfa_image;
|
|
|
|
gint32 sfa_drawable;
|
|
|
|
gint32 sfa_layer;
|
|
|
|
gint32 sfa_channel;
|
2001-01-11 06:49:45 +08:00
|
|
|
GimpRGB sfa_color;
|
2000-11-08 22:35:50 +08:00
|
|
|
gint32 sfa_toggle;
|
|
|
|
gchar *sfa_value;
|
|
|
|
SFAdjustment sfa_adjustment;
|
|
|
|
SFFont sfa_font;
|
|
|
|
SFFilename sfa_file;
|
|
|
|
gchar *sfa_pattern;
|
|
|
|
gchar *sfa_gradient;
|
|
|
|
SFBrush sfa_brush;
|
|
|
|
SFOption sfa_option;
|
1997-11-25 06:05:25 +08:00
|
|
|
} SFArgValue;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2000-08-08 05:30:35 +08:00
|
|
|
gchar *script_name;
|
|
|
|
gchar *pdb_name;
|
|
|
|
gchar *description;
|
|
|
|
gchar *help;
|
|
|
|
gchar *author;
|
|
|
|
gchar *copyright;
|
|
|
|
gchar *date;
|
|
|
|
gchar *img_types;
|
|
|
|
gint num_args;
|
|
|
|
SFArgType *arg_types;
|
|
|
|
gchar **arg_labels;
|
|
|
|
SFArgValue *arg_defaults;
|
|
|
|
SFArgValue *arg_values;
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean image_based;
|
2000-08-08 05:30:35 +08:00
|
|
|
GimpParamDef *args; /* used only temporary until installed */
|
1997-11-25 06:05:25 +08:00
|
|
|
} SFScript;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2002-05-25 03:44:37 +08:00
|
|
|
GtkWidget *dialog;
|
2000-11-08 22:35:50 +08:00
|
|
|
GtkWidget **args_widgets;
|
|
|
|
GtkWidget *status;
|
|
|
|
GtkWidget *about_dialog;
|
2002-09-17 21:57:30 +08:00
|
|
|
gchar *title;
|
2000-11-08 22:35:50 +08:00
|
|
|
gchar *last_command;
|
|
|
|
gint command_count;
|
|
|
|
gint consec_command_count;
|
1997-11-25 06:05:25 +08:00
|
|
|
} SFInterface;
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* External functions
|
|
|
|
*/
|
2000-02-01 04:47:44 +08:00
|
|
|
extern long nlength (LISP obj);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Functions
|
|
|
|
*/
|
|
|
|
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean script_fu_install_script (gpointer foo,
|
2000-08-08 05:30:35 +08:00
|
|
|
SFScript *script,
|
|
|
|
gpointer bar);
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean script_fu_remove_script (gpointer foo,
|
2000-08-08 05:30:35 +08:00
|
|
|
SFScript *script,
|
|
|
|
gpointer bar);
|
|
|
|
static void script_fu_script_proc (gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
GimpParam *params,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
|
|
|
static SFScript * script_fu_find_script (gchar *script_name);
|
|
|
|
static void script_fu_free_script (SFScript *script);
|
|
|
|
static void script_fu_interface (SFScript *script);
|
2000-11-08 22:35:50 +08:00
|
|
|
static void script_fu_interface_quit (SFScript *script);
|
|
|
|
static void script_fu_error_msg (gchar *command);
|
|
|
|
|
|
|
|
static void script_fu_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void script_fu_about_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void script_fu_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void script_fu_menu_callback (gint32 id,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void script_fu_file_selection_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void script_fu_font_preview_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void script_fu_font_dialog_ok (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void script_fu_font_dialog_cancel (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean script_fu_font_dialog_delete (GtkWidget *widget,
|
2000-11-08 22:35:50 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void script_fu_font_preview (GtkWidget *preview,
|
|
|
|
gchar *fontname);
|
|
|
|
static void script_fu_pattern_preview (gchar *name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
gchar *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-11-08 22:35:50 +08:00
|
|
|
gpointer data);
|
|
|
|
static void script_fu_gradient_preview (gchar *name,
|
|
|
|
gint width,
|
|
|
|
gdouble *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-11-08 22:35:50 +08:00
|
|
|
gpointer data);
|
|
|
|
static void script_fu_brush_preview (gchar *name,
|
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
gint paint_mode,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gchar *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-11-08 22:35:50 +08:00
|
|
|
gpointer data);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
2002-12-13 21:23:47 +08:00
|
|
|
static GTree *script_list = NULL;
|
2000-11-08 22:35:50 +08:00
|
|
|
static SFInterface *sf_interface = NULL; /* there can only be at most one
|
|
|
|
interactive interface */
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
extern gchar siod_err_msg[];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2000-02-01 04:47:44 +08:00
|
|
|
script_fu_find_scripts (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-29 23:54:39 +08:00
|
|
|
const gchar *home;
|
|
|
|
const gchar *entry;
|
|
|
|
gchar *path_str;
|
|
|
|
gchar *local_path;
|
|
|
|
gchar *path;
|
|
|
|
gchar *filename;
|
|
|
|
gchar *token;
|
|
|
|
gchar *next_token;
|
|
|
|
gchar *command;
|
|
|
|
GDir *dir;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Make sure to clear any existing scripts */
|
|
|
|
if (script_list != NULL)
|
|
|
|
{
|
2001-11-29 23:54:39 +08:00
|
|
|
g_tree_foreach (script_list,
|
|
|
|
(GTraverseFunc) script_fu_remove_script,
|
|
|
|
NULL);
|
2000-05-08 06:04:51 +08:00
|
|
|
g_tree_destroy (script_list);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-11-29 23:54:39 +08:00
|
|
|
script_list = g_tree_new ((GCompareFunc) strcoll);
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
path_str = gimp_gimprc_query ("script-fu-path");
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
if (path_str == NULL)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
/* Set local path to contain temp_path, where (supposedly)
|
|
|
|
* there may be working files.
|
|
|
|
*/
|
|
|
|
home = g_get_home_dir ();
|
|
|
|
local_path = g_strdup (path_str);
|
|
|
|
|
|
|
|
/* Search through all directories in the local path */
|
|
|
|
|
|
|
|
next_token = local_path;
|
|
|
|
|
|
|
|
token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
while (token)
|
|
|
|
{
|
|
|
|
if (*token == '~')
|
2000-11-09 00:57:47 +08:00
|
|
|
{
|
|
|
|
path = g_malloc (strlen (home) + strlen (token) + 2);
|
|
|
|
sprintf (path, "%s%s", home, token + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = g_malloc (strlen (token) + 2);
|
|
|
|
strcpy (path, token);
|
|
|
|
}
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-08-01 08:38:38 +08:00
|
|
|
/* Check if directory exists and if it has any items in it */
|
2001-11-29 23:54:39 +08:00
|
|
|
if (g_file_test (path, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
GError *error;
|
2000-11-09 00:57:47 +08:00
|
|
|
|
2001-11-29 23:54:39 +08:00
|
|
|
dir = g_dir_open (path, 0, &error);
|
2000-08-01 08:38:38 +08:00
|
|
|
|
|
|
|
if (!dir)
|
2001-11-29 23:54:39 +08:00
|
|
|
{
|
2002-02-09 01:59:40 +08:00
|
|
|
g_message ("Error reading script folder '%s'\n%s",
|
2001-11-29 23:54:39 +08:00
|
|
|
path, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2001-11-29 23:54:39 +08:00
|
|
|
while ((entry = g_dir_read_name (dir)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-29 23:54:39 +08:00
|
|
|
filename = g_build_filename (path, entry, NULL);
|
2000-08-01 08:38:38 +08:00
|
|
|
|
2001-08-30 01:48:28 +08:00
|
|
|
if (g_ascii_strcasecmp (filename + strlen (filename) - 4, ".scm") == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-01 08:38:38 +08:00
|
|
|
/* Check the file and see that it is not a sub-directory */
|
2001-11-29 23:54:39 +08:00
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-23 07:46:13 +08:00
|
|
|
gchar *qf = g_strescape (filename, NULL);
|
1999-04-26 03:30:31 +08:00
|
|
|
#ifdef __EMX__
|
2000-08-01 08:38:38 +08:00
|
|
|
_fnslashify(qf);
|
1999-04-26 03:30:31 +08:00
|
|
|
#endif
|
2000-08-01 08:38:38 +08:00
|
|
|
command = g_strdup_printf ("(load \"%s\")", qf);
|
|
|
|
g_free (qf);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
|
|
|
if (repl_c_string (command, 0, 0, 1) != 0)
|
|
|
|
script_fu_error_msg (command);
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2000-08-01 08:38:38 +08:00
|
|
|
/* No, I don't know why, but this is
|
|
|
|
* necessary on NT 4.0.
|
|
|
|
*/
|
|
|
|
Sleep(0);
|
1999-05-29 09:28:24 +08:00
|
|
|
#endif
|
2000-08-01 08:38:38 +08:00
|
|
|
g_free (command);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-08-01 08:38:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
} /* while */
|
|
|
|
|
2001-11-29 23:54:39 +08:00
|
|
|
g_dir_close (dir);
|
2000-08-01 08:38:38 +08:00
|
|
|
} /* else */
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S);
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
g_free (local_path);
|
|
|
|
g_free (path_str);
|
2000-05-08 06:04:51 +08:00
|
|
|
|
|
|
|
/* now that all scripts are read in and sorted, tell gimp about them */
|
2001-11-29 23:54:39 +08:00
|
|
|
g_tree_foreach (script_list,
|
|
|
|
(GTraverseFunc) script_fu_install_script,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LISP
|
|
|
|
script_fu_add_script (LISP a)
|
|
|
|
{
|
2000-08-08 05:30:35 +08:00
|
|
|
GimpParamDef *args;
|
2000-11-08 22:35:50 +08:00
|
|
|
SFScript *script;
|
|
|
|
gchar *val;
|
|
|
|
gint i;
|
2001-01-15 04:25:46 +08:00
|
|
|
guchar r, g, b;
|
2000-11-08 22:35:50 +08:00
|
|
|
LISP color_list;
|
|
|
|
LISP adj_list;
|
|
|
|
LISP brush_list;
|
|
|
|
LISP option_list;
|
|
|
|
gchar *s;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Check the length of a */
|
|
|
|
if (nlength (a) < 7)
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("Too few arguments to script-fu-register", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Create a new script */
|
2000-11-08 22:35:50 +08:00
|
|
|
script = g_new0 (SFScript, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Find the script name */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->script_name = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
/* transform the function name into a name containing "_" for each "-".
|
|
|
|
* this does not hurt anybody, yet improves the life of many... ;)
|
|
|
|
*/
|
|
|
|
script->pdb_name = g_strdup (val);
|
|
|
|
|
|
|
|
for (s = script->pdb_name; *s; s++)
|
|
|
|
if (*s == '-')
|
|
|
|
*s = '_';
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Find the script description */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->description = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script help */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->help = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script author */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->author = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script copyright */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->copyright = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script date */
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
script->date = g_strdup (val);
|
|
|
|
a = cdr (a);
|
|
|
|
|
|
|
|
/* Find the script image types */
|
|
|
|
if (TYPEP (a, tc_cons))
|
|
|
|
{
|
|
|
|
val = get_c_string (car (a));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = get_c_string (a);
|
|
|
|
a = NIL;
|
|
|
|
}
|
|
|
|
script->img_types = g_strdup (val);
|
|
|
|
|
|
|
|
/* Check the supplied number of arguments */
|
|
|
|
script->num_args = nlength (a) / 3;
|
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args = g_new (GimpParamDef, script->num_args + 1);
|
2001-01-22 04:06:26 +08:00
|
|
|
args[0].type = GIMP_PDB_INT32;
|
|
|
|
args[0].name = "run_mode";
|
1998-02-25 18:48:59 +08:00
|
|
|
args[0].description = "Interactive, non-interactive";
|
|
|
|
|
1999-10-21 20:37:18 +08:00
|
|
|
script->arg_types = g_new (SFArgType, script->num_args);
|
2000-05-08 06:04:51 +08:00
|
|
|
script->arg_labels = g_new (gchar *, script->num_args);
|
1999-10-21 20:37:18 +08:00
|
|
|
script->arg_defaults = g_new0 (SFArgValue, script->num_args);
|
|
|
|
script->arg_values = g_new0 (SFArgValue, script->num_args);
|
1998-02-25 18:48:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (script->num_args > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: argument types must be integer values", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_types[i] = get_c_long (car (a));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: missing type specifier", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: argument labels must be strings", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_labels[i] = g_strdup (get_c_string (car (a)));
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: missing arguments label", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (a != NIL)
|
|
|
|
{
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: drawable defaults must be integer values", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_defaults[i].sfa_image = get_c_long (car (a));
|
|
|
|
script->arg_values[i].sfa_image = script->arg_defaults[i].sfa_image;
|
|
|
|
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_IMAGE;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "image";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_DRAWABLE:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_DRAWABLE;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "drawable";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_LAYER:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_LAYER;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "layer";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_CHANNEL:
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_CHANNEL;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "channel";
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_COLOR:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: color defaults must be a list of 3 integers", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = car (a);
|
2001-01-15 04:25:46 +08:00
|
|
|
r = CLAMP (get_c_long (car (color_list)), 0, 255);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = cdr (color_list);
|
2001-01-15 04:25:46 +08:00
|
|
|
g = CLAMP (get_c_long (car (color_list)), 0, 255);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_list = cdr (color_list);
|
2001-01-15 04:25:46 +08:00
|
|
|
b = CLAMP (get_c_long (car (color_list)), 0, 255);
|
2001-01-11 06:49:45 +08:00
|
|
|
|
2001-01-15 04:25:46 +08:00
|
|
|
gimp_rgb_set_uchar (&script->arg_defaults[i].sfa_color,
|
|
|
|
r, g, b);
|
2001-01-11 06:49:45 +08:00
|
|
|
|
|
|
|
script->arg_values[i].sfa_color =
|
|
|
|
script->arg_defaults[i].sfa_color;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_COLOR;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "color";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_TOGGLE:
|
|
|
|
if (!TYPEP (car (a), tc_flonum))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: toggle default must be an integer value", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_toggle =
|
|
|
|
(get_c_long (car (a))) ? TRUE : FALSE;
|
|
|
|
script->arg_values[i].sfa_toggle =
|
|
|
|
script->arg_defaults[i].sfa_toggle;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_INT32;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "toggle";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_VALUE:
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!TYPEP (car (a), tc_string))
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: value defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_value =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_value =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_value);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1997-11-25 06:05:25 +08:00
|
|
|
args[i + 1].name = "value";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
1998-08-06 03:58:10 +08:00
|
|
|
|
|
|
|
case SF_STRING:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: string defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_value =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_value =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_value);
|
1998-08-06 03:58:10 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1998-08-06 03:58:10 +08:00
|
|
|
args[i + 1].name = "string";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: adjustment defaults must be a list", NIL);
|
|
|
|
adj_list = car (a);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.value =
|
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.lower =
|
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.upper =
|
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.step =
|
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.page =
|
|
|
|
get_c_double (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.digits =
|
|
|
|
get_c_long (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
adj_list = cdr (adj_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.type =
|
|
|
|
get_c_long (car (adj_list));
|
1998-08-06 22:58:39 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.adj = NULL;
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.value =
|
|
|
|
script->arg_defaults[i].sfa_adjustment.value;
|
1998-08-06 22:58:39 +08:00
|
|
|
|
2002-02-22 23:21:08 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_FLOAT;
|
1998-08-06 22:58:39 +08:00
|
|
|
args[i + 1].name = "value";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: filename defaults must be string values", NIL);
|
2001-11-22 02:50:50 +08:00
|
|
|
/* fallthrough */
|
|
|
|
case SF_DIRNAME:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: dirname defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_file.filename =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
1999-05-29 09:28:24 +08:00
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-05-29 09:28:24 +08:00
|
|
|
/* Replace POSIX slashes with Win32 backslashes. This
|
|
|
|
* is just so script-fus can be written with only
|
|
|
|
* POSIX directory separators.
|
|
|
|
*/
|
|
|
|
val = script->arg_defaults[i].sfa_file.filename;
|
|
|
|
while (*val)
|
|
|
|
{
|
|
|
|
if (*val == '/')
|
|
|
|
*val = '\\';
|
|
|
|
val++;
|
|
|
|
}
|
|
|
|
#endif
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_values[i].sfa_file.filename =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_file.filename);
|
1999-05-19 01:33:39 +08:00
|
|
|
script->arg_values[i].sfa_file.fileselection = NULL;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
2001-11-22 02:50:50 +08:00
|
|
|
args[i + 1].name = (script->arg_types[i] == SF_FILENAME ?
|
|
|
|
"filename" : "dirname");
|
1999-05-19 01:33:39 +08:00
|
|
|
args[i + 1].description = script->arg_labels[i];
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: font defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_font.fontname =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_font.fontname =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_font.fontname);
|
1998-08-10 23:06:58 +08:00
|
|
|
script->arg_values[i].sfa_font.preview = NULL;
|
|
|
|
script->arg_values[i].sfa_font.dialog = NULL;
|
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1998-08-10 23:06:58 +08:00
|
|
|
args[i + 1].name = "font";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
|
|
|
case SF_PATTERN:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: pattern defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_pattern =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_pattern =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_pattern);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1998-10-02 06:09:01 +08:00
|
|
|
args[i + 1].name = "pattern";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: brush defaults must be a list", NIL);
|
|
|
|
brush_list = car (a);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.name =
|
|
|
|
g_strdup (get_c_string (car (brush_list)));
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.opacity =
|
|
|
|
get_c_double (car (brush_list));
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.spacing =
|
|
|
|
get_c_long (car (brush_list));
|
1998-10-21 06:36:52 +08:00
|
|
|
brush_list = cdr (brush_list);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.paint_mode =
|
|
|
|
get_c_long (car (brush_list));
|
|
|
|
script->arg_values[i].sfa_brush =
|
|
|
|
script->arg_defaults[i].sfa_brush;
|
1998-10-21 06:36:52 +08:00
|
|
|
/* Need this since we need a copy of the string
|
|
|
|
* in the values area. We could free it later but the
|
|
|
|
* default one must hang around.
|
|
|
|
*/
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_values[i].sfa_brush.name =
|
|
|
|
g_strdup(script->arg_defaults[i].sfa_brush.name);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1998-10-21 06:36:52 +08:00
|
|
|
args[i + 1].name = "brush";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
1998-08-10 23:06:58 +08:00
|
|
|
break;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
|
|
|
if (!TYPEP (car (a), tc_string))
|
|
|
|
return my_err ("script-fu-register: gradient defaults must be string values", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_defaults[i].sfa_gradient =
|
|
|
|
g_strdup (get_c_string (car (a)));
|
|
|
|
script->arg_values[i].sfa_gradient =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_pattern);
|
1998-11-01 00:22:37 +08:00
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_STRING;
|
1998-11-01 00:22:37 +08:00
|
|
|
args[i + 1].name = "gradient";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
if (!TYPEP (car (a), tc_cons))
|
|
|
|
return my_err ("script-fu-register: option defaults must be a list", NIL);
|
2000-11-08 22:35:50 +08:00
|
|
|
for (option_list = car (a);
|
|
|
|
option_list;
|
|
|
|
option_list = cdr (option_list))
|
2000-04-28 08:02:11 +08:00
|
|
|
{
|
|
|
|
script->arg_defaults[i].sfa_option.list =
|
|
|
|
g_slist_append (script->arg_defaults[i].sfa_option.list,
|
|
|
|
g_strdup (get_c_string (car (option_list))));
|
|
|
|
}
|
|
|
|
script->arg_defaults[i].sfa_option.history = 0;
|
|
|
|
script->arg_values[i].sfa_option.history = 0;
|
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
args[i + 1].type = GIMP_PDB_INT32;
|
2000-04-28 08:02:11 +08:00
|
|
|
args[i + 1].name = "option";
|
|
|
|
args[i + 1].description = script->arg_labels[i];
|
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = cdr (a);
|
|
|
|
}
|
|
|
|
else
|
1998-04-09 17:00:27 +08:00
|
|
|
return my_err ("script-fu-register: missing default argument", NIL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
script->args = args;
|
|
|
|
g_tree_insert (script_list, gettext (script->description), script);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
script_fu_report_cc (gchar *command)
|
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
if (sf_interface == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sf_interface->last_command &&
|
|
|
|
strcmp (sf_interface->last_command, command) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
gchar *new_command;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->command_count++;
|
|
|
|
|
|
|
|
new_command = g_strdup_printf ("%s <%d>",
|
|
|
|
command, sf_interface->command_count);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (sf_interface->status), new_command);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (new_command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->command_count = 1;
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (sf_interface->status), command);
|
2000-11-08 22:35:50 +08:00
|
|
|
g_free (sf_interface->last_command);
|
|
|
|
sf_interface->last_command = g_strdup (command);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-05-25 03:44:37 +08:00
|
|
|
|
|
|
|
while (gtk_main_iteration ());
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
|
|
|
|
/*
|
2001-02-14 12:55:21 +08:00
|
|
|
* The following function is a GTraverseFunction. Please
|
2000-11-08 22:35:50 +08:00
|
|
|
* note that it frees the script->args structure. --Sven
|
2000-05-08 06:04:51 +08:00
|
|
|
*/
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2000-05-08 06:04:51 +08:00
|
|
|
script_fu_install_script (gpointer foo,
|
|
|
|
SFScript *script,
|
|
|
|
gpointer bar)
|
|
|
|
{
|
|
|
|
gchar *menu_path = NULL;
|
|
|
|
|
|
|
|
/* Allow scripts with no menus */
|
|
|
|
if (strncmp (script->description, "<None>", 6) != 0)
|
|
|
|
menu_path = script->description;
|
|
|
|
|
|
|
|
gimp_install_temp_proc (script->pdb_name,
|
|
|
|
script->description,
|
|
|
|
script->help,
|
|
|
|
script->author,
|
|
|
|
script->copyright,
|
|
|
|
script->date,
|
|
|
|
menu_path,
|
|
|
|
script->img_types,
|
2000-08-22 11:27:14 +08:00
|
|
|
GIMP_TEMPORARY,
|
2000-05-08 06:04:51 +08:00
|
|
|
script->num_args + 1, 0,
|
|
|
|
script->args, NULL,
|
|
|
|
script_fu_script_proc);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
g_free (script->args);
|
|
|
|
script->args = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following function is a GTraverseFunction.
|
|
|
|
*/
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2000-05-08 06:04:51 +08:00
|
|
|
script_fu_remove_script (gpointer foo,
|
|
|
|
SFScript *script,
|
|
|
|
gpointer bar)
|
|
|
|
{
|
|
|
|
script_fu_free_script (script);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2000-08-08 05:30:35 +08:00
|
|
|
script_fu_script_proc (gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
GimpParam *params,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-25 03:44:37 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
SFScript *script;
|
|
|
|
gint min_args;
|
|
|
|
gchar *escaped;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
run_mode = params[0].data.d_int32;
|
|
|
|
|
|
|
|
if (! (script = script_fu_find_script (name)))
|
2001-01-22 04:06:26 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
1998-02-25 18:48:59 +08:00
|
|
|
if (script->num_args == 0)
|
2000-08-22 11:27:14 +08:00
|
|
|
run_mode = GIMP_RUN_NONINTERACTIVE;
|
1998-02-25 18:48:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-11-08 22:35:50 +08:00
|
|
|
/* Determine whether the script is image based (runs on an image) */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (strncmp (script->description, "<Image>", 7) == 0)
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
script->arg_values[0].sfa_image = params[1].data.d_image;
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_values[1].sfa_drawable = params[2].data.d_drawable;
|
|
|
|
script->image_based = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
script->image_based = FALSE;
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
1998-01-25 17:29:29 +08:00
|
|
|
/* Skip this part if the script takes no parameters */
|
|
|
|
min_args = (script->image_based) ? 2 : 0;
|
1999-10-21 20:37:18 +08:00
|
|
|
if (script->num_args > min_args)
|
|
|
|
{
|
|
|
|
script_fu_interface (script);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
}
|
|
|
|
/* else fallthrough */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != (script->num_args + 1))
|
2000-08-22 11:27:14 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-25 09:20:05 +08:00
|
|
|
guchar color[3];
|
2000-04-28 08:02:11 +08:00
|
|
|
gchar *text = NULL;
|
|
|
|
gchar *command;
|
|
|
|
gchar *c;
|
|
|
|
gchar buffer[MAX_STRING_LENGTH];
|
|
|
|
gint length;
|
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
length = strlen (script->script_name) + 3;
|
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
length += 12; /* Maximum size of integer value will not exceed this many characters */
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_COLOR:
|
|
|
|
length += 16; /* Maximum size of color string: '(XXX XXX XXX) */
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_TOGGLE:
|
|
|
|
length += 6; /* Maximum size of (TRUE, FALSE) */
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_VALUE:
|
|
|
|
length += strlen (params[i + 1].data.d_string) + 1;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 03:58:10 +08:00
|
|
|
case SF_STRING:
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (params[i + 1].data.d_string, NULL);
|
1999-05-29 09:28:24 +08:00
|
|
|
length += strlen (escaped) + 3;
|
|
|
|
g_free (escaped);
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
length += strlen (params[i + 1].data.d_string) + 1;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
length += strlen (params[i + 1].data.d_string) + 3;
|
2000-04-28 08:02:11 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
length += strlen (params[i + 1].data.d_string) + 1;
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
c = command = g_new (gchar, length);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-02-25 18:48:59 +08:00
|
|
|
if (script->num_args)
|
1999-12-06 04:48:06 +08:00
|
|
|
{
|
|
|
|
sprintf (command, "(%s ", script->script_name);
|
|
|
|
c += strlen (script->script_name) + 2;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d",
|
|
|
|
params[i + 1].data.d_image);
|
1999-12-06 04:48:06 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_COLOR:
|
2001-01-25 09:20:05 +08:00
|
|
|
gimp_rgb_get_uchar (¶ms[i + 1].data.d_color,
|
|
|
|
color, color + 1, color + 2);
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "'(%d %d %d)",
|
2001-01-25 09:20:05 +08:00
|
|
|
color[0], color[1], color[2]);
|
1999-12-06 04:48:06 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_TOGGLE:
|
2000-02-01 04:47:44 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%s",
|
2000-11-08 22:35:50 +08:00
|
|
|
(params[i + 1].data.d_int32) ? "TRUE"
|
|
|
|
: "FALSE");
|
1999-12-06 04:48:06 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_VALUE:
|
|
|
|
text = params[i + 1].data.d_string;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_STRING:
|
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (params[i + 1].data.d_string,
|
|
|
|
NULL);
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"",
|
|
|
|
escaped);
|
1999-12-06 04:48:06 +08:00
|
|
|
g_free (escaped);
|
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
text = params[i + 1].data.d_string;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
case SF_FONT:
|
|
|
|
case SF_PATTERN:
|
|
|
|
case SF_GRADIENT:
|
|
|
|
case SF_BRUSH:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"",
|
|
|
|
params[i + 1].data.d_string);
|
1999-12-06 04:48:06 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
text = params[i + 1].data.d_string;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == script->num_args - 1)
|
|
|
|
sprintf (c, "%s)", text);
|
|
|
|
else
|
|
|
|
sprintf (c, "%s ", text);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1999-12-06 04:48:06 +08:00
|
|
|
c += strlen (text) + 1;
|
|
|
|
}
|
|
|
|
}
|
1998-02-25 18:48:59 +08:00
|
|
|
else
|
|
|
|
sprintf (command, "(%s)", script->script_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* run the command through the interpreter */
|
2000-11-08 22:35:50 +08:00
|
|
|
if (repl_c_string (command, 0, 0, 1) != 0)
|
|
|
|
script_fu_error_msg (command);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
2000-08-08 05:30:35 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
/* this is a GTraverseFunction */
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
2000-05-08 06:04:51 +08:00
|
|
|
script_fu_lookup_script (gpointer *foo,
|
|
|
|
SFScript *script,
|
|
|
|
gchar **name)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-08 06:04:51 +08:00
|
|
|
if (strcmp (script->pdb_name, *name) == 0)
|
|
|
|
{
|
|
|
|
/* store the script in the name pointer and stop the traversal */
|
|
|
|
*name = (gchar *)script;
|
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-05-08 06:04:51 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
static SFScript *
|
|
|
|
script_fu_find_script (gchar *pdb_name)
|
|
|
|
{
|
|
|
|
gchar *script;
|
|
|
|
|
|
|
|
script = pdb_name;
|
2001-11-29 23:54:39 +08:00
|
|
|
g_tree_foreach (script_list,
|
|
|
|
(GTraverseFunc) script_fu_lookup_script,
|
|
|
|
&script);
|
2001-01-22 04:06:26 +08:00
|
|
|
|
2000-05-08 06:04:51 +08:00
|
|
|
if (script == pdb_name)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return (SFScript *)script;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_free_script (SFScript *script)
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Uninstall the temporary procedure for this script */
|
|
|
|
gimp_uninstall_temp_proc (script->script_name);
|
|
|
|
|
|
|
|
if (script)
|
|
|
|
{
|
|
|
|
g_free (script->script_name);
|
|
|
|
g_free (script->description);
|
|
|
|
g_free (script->help);
|
|
|
|
g_free (script->author);
|
|
|
|
g_free (script->copyright);
|
|
|
|
g_free (script->date);
|
|
|
|
g_free (script->img_types);
|
|
|
|
g_free (script->arg_types);
|
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
g_free (script->arg_labels[i]);
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
case SF_COLOR:
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_VALUE:
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_STRING:
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (script->arg_defaults[i].sfa_value);
|
1998-08-09 20:17:51 +08:00
|
|
|
g_free (script->arg_values[i].sfa_value);
|
1998-08-06 03:58:10 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
1998-11-06 08:51:39 +08:00
|
|
|
g_free (script->arg_defaults[i].sfa_file.filename);
|
|
|
|
g_free (script->arg_values[i].sfa_file.filename);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
|
|
|
g_free (script->arg_defaults[i].sfa_font.fontname);
|
|
|
|
g_free (script->arg_values[i].sfa_font.fontname);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
|
|
|
g_free (script->arg_defaults[i].sfa_pattern);
|
|
|
|
g_free (script->arg_values[i].sfa_pattern);
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
|
|
|
g_free (script->arg_defaults[i].sfa_gradient);
|
|
|
|
g_free (script->arg_values[i].sfa_gradient);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
g_free (script->arg_defaults[i].sfa_brush.name);
|
|
|
|
g_free (script->arg_values[i].sfa_brush.name);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
g_slist_foreach (script->arg_defaults[i].sfa_option.list,
|
|
|
|
(GFunc)g_free, NULL);
|
|
|
|
if (script->arg_defaults[i].sfa_option.list)
|
|
|
|
g_slist_free (script->arg_defaults[i].sfa_option.list);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (script->arg_labels);
|
|
|
|
g_free (script->arg_defaults);
|
|
|
|
g_free (script->arg_values);
|
|
|
|
|
|
|
|
g_free (script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_interface (SFScript *script)
|
|
|
|
{
|
|
|
|
GtkWidget *dlg;
|
2000-02-01 04:47:44 +08:00
|
|
|
GtkWidget *frame;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *table;
|
1998-07-19 01:31:31 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
2000-04-28 08:02:11 +08:00
|
|
|
GtkWidget *menu_item;
|
2000-11-08 22:35:50 +08:00
|
|
|
GSList *list;
|
|
|
|
gchar *buf;
|
|
|
|
gint start_args;
|
|
|
|
gint i;
|
|
|
|
guint j;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
static gboolean gtk_initted = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
/* Simply return if there is already an interface. This is an
|
|
|
|
ugly workaround for the fact that we can not process two
|
|
|
|
scripts at a time. */
|
|
|
|
if (sf_interface != NULL)
|
|
|
|
return;
|
|
|
|
|
1999-10-21 20:37:18 +08:00
|
|
|
g_return_if_fail (script != NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!gtk_initted)
|
|
|
|
{
|
2001-10-29 20:51:21 +08:00
|
|
|
INIT_I18N();
|
1999-08-25 03:57:55 +08:00
|
|
|
|
2000-05-01 02:17:55 +08:00
|
|
|
gimp_ui_init ("script-fu", TRUE);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_initted = TRUE;
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface = g_new0 (SFInterface, 1);
|
|
|
|
sf_interface->args_widgets = g_new0 (GtkWidget *, script->num_args);
|
1998-07-19 01:31:31 +08:00
|
|
|
|
2000-02-28 03:35:39 +08:00
|
|
|
/* strip the first part of the menupath if it contains _("/Script-Fu/") */
|
|
|
|
buf = strstr (gettext (script->description), _("/Script-Fu/"));
|
1998-07-19 01:31:31 +08:00
|
|
|
if (buf)
|
2002-09-17 21:57:30 +08:00
|
|
|
sf_interface->title = g_strdup (buf + strlen (_("/Script-Fu/")));
|
1998-07-19 01:31:31 +08:00
|
|
|
else
|
2002-09-17 21:57:30 +08:00
|
|
|
sf_interface->title = g_strdup (gettext (script->description));
|
2000-02-28 03:35:39 +08:00
|
|
|
|
2002-09-17 21:57:30 +08:00
|
|
|
buf = strstr (sf_interface->title, "...");
|
2000-02-28 03:35:39 +08:00
|
|
|
if (buf)
|
|
|
|
*buf = '\0';
|
1998-07-19 01:31:31 +08:00
|
|
|
|
2002-09-17 21:57:30 +08:00
|
|
|
buf = g_strdup_printf (_("Script-Fu: %s"), sf_interface->title);
|
|
|
|
|
|
|
|
dlg = gimp_dialog_new (buf, "script-fu",
|
2002-05-25 03:44:37 +08:00
|
|
|
gimp_standard_help_func, "filters/script-fu.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
TRUE, FALSE, TRUE,
|
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
GTK_STOCK_OK, script_fu_ok_callback,
|
|
|
|
script, NULL, NULL, TRUE, FALSE,
|
|
|
|
|
2002-09-17 21:57:30 +08:00
|
|
|
NULL);
|
|
|
|
g_free (buf);
|
|
|
|
|
2002-05-25 03:44:37 +08:00
|
|
|
sf_interface->dialog = dlg;
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect_swapped (dlg, "destroy",
|
2002-05-25 03:44:37 +08:00
|
|
|
G_CALLBACK (script_fu_interface_quit),
|
|
|
|
script);
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dlg), TRUE);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2002-11-08 22:46:14 +08:00
|
|
|
sf_interface->status = gtk_label_new (sf_interface->title);
|
2002-09-17 21:57:30 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (sf_interface->status), 0.0, 0.5);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), sf_interface->status, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (sf_interface->status);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label (_("About"));
|
|
|
|
gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2002-05-25 03:44:37 +08:00
|
|
|
G_CALLBACK (script_fu_about_callback),
|
|
|
|
script);
|
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
/* the script arguments frame */
|
1999-09-24 08:23:33 +08:00
|
|
|
frame = gtk_frame_new (_("Script Arguments"));
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-19 01:31:31 +08:00
|
|
|
/* the vbox holding all widgets */
|
2000-02-01 04:47:44 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The argument table */
|
1998-08-09 20:17:51 +08:00
|
|
|
table = gtk_table_new (script->num_args + 1, 2, FALSE);
|
2000-04-28 08:02:11 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
1998-07-19 01:31:31 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
start_args = (script->image_based) ? 2 : 0;
|
|
|
|
|
|
|
|
for (i = start_args; i < script->num_args; i++)
|
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
/* we add a colon after the label;
|
|
|
|
some languages want an extra space here */
|
2001-01-22 04:06:26 +08:00
|
|
|
gchar *label_text =
|
2000-11-08 22:35:50 +08:00
|
|
|
g_strdup_printf (_("%s:"), gettext (script->arg_labels[i]));
|
2001-01-22 04:06:26 +08:00
|
|
|
gfloat label_yalign = 0.5;
|
2000-04-28 08:02:11 +08:00
|
|
|
gboolean widget_leftalign = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] = gtk_option_menu_new ();
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
menu = gimp_image_menu_new (NULL, script_fu_menu_callback,
|
|
|
|
&script->arg_values[i].sfa_image,
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_image);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_DRAWABLE:
|
|
|
|
menu = gimp_drawable_menu_new (NULL, script_fu_menu_callback,
|
|
|
|
&script->arg_values[i].sfa_drawable,
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_LAYER:
|
|
|
|
menu = gimp_layer_menu_new (NULL, script_fu_menu_callback,
|
|
|
|
&script->arg_values[i].sfa_layer,
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_CHANNEL:
|
|
|
|
menu = gimp_channel_menu_new (NULL, script_fu_menu_callback,
|
|
|
|
&script->arg_values[i].sfa_channel,
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_channel);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
menu = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (sf_interface->args_widgets[i]),
|
|
|
|
menu);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_COLOR:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_color_button_new (_("Script-Fu Color Selection"),
|
|
|
|
COLOR_SAMPLE_WIDTH, COLOR_SAMPLE_HEIGHT,
|
2001-01-15 14:24:24 +08:00
|
|
|
&script->arg_values[i].sfa_color,
|
|
|
|
GIMP_COLOR_AREA_FLAT);
|
2001-07-30 08:46:09 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (sf_interface->args_widgets[i],
|
2001-07-30 08:46:09 +08:00
|
|
|
"color_changed",
|
|
|
|
G_CALLBACK (gimp_color_button_get_color),
|
|
|
|
&script->arg_values[i].sfa_color);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_TOGGLE:
|
2000-04-28 08:02:11 +08:00
|
|
|
g_free (label_text);
|
|
|
|
label_text = NULL;
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2000-02-28 03:35:39 +08:00
|
|
|
gtk_check_button_new_with_label (gettext (script->arg_labels[i]));
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sf_interface->args_widgets[i]),
|
1997-11-25 06:05:25 +08:00
|
|
|
script->arg_values[i].sfa_toggle);
|
2001-07-30 08:46:09 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (sf_interface->args_widgets[i],
|
2001-07-30 08:46:09 +08:00
|
|
|
"toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&script->arg_values[i].sfa_toggle);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_VALUE:
|
1998-08-06 03:58:10 +08:00
|
|
|
case SF_STRING:
|
2000-02-01 04:47:44 +08:00
|
|
|
widget_leftalign = FALSE;
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] = gtk_entry_new ();
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (sf_interface->args_widgets[i],
|
|
|
|
TEXT_WIDTH, -1);
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (sf_interface->args_widgets[i]),
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_value);
|
1998-08-06 03:58:10 +08:00
|
|
|
break;
|
1998-08-06 22:58:39 +08:00
|
|
|
|
|
|
|
case SF_ADJUSTMENT:
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.adj = (GtkAdjustment *)
|
|
|
|
gtk_adjustment_new (script->arg_values[i].sfa_adjustment.value,
|
|
|
|
script->arg_defaults[i].sfa_adjustment.lower,
|
|
|
|
script->arg_defaults[i].sfa_adjustment.upper,
|
|
|
|
script->arg_defaults[i].sfa_adjustment.step,
|
|
|
|
script->arg_defaults[i].sfa_adjustment.page, 0);
|
1998-08-06 22:58:39 +08:00
|
|
|
switch (script->arg_defaults[i].sfa_adjustment.type)
|
|
|
|
{
|
|
|
|
case SF_SLIDER:
|
2000-02-01 04:47:44 +08:00
|
|
|
label_yalign = 1.0;
|
2000-04-28 08:02:11 +08:00
|
|
|
widget_leftalign = FALSE;
|
2000-02-01 04:47:44 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_hscale_new (script->arg_values[i].sfa_adjustment.adj);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (sf_interface->args_widgets[i]),
|
|
|
|
SLIDER_WIDTH, -1);
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_scale_set_digits (GTK_SCALE (sf_interface->args_widgets[i]),
|
1998-08-06 22:58:39 +08:00
|
|
|
script->arg_defaults[i].sfa_adjustment.digits);
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (sf_interface->args_widgets[i]), TRUE);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (sf_interface->args_widgets[i]),
|
1998-08-06 22:58:39 +08:00
|
|
|
GTK_UPDATE_DELAYED);
|
|
|
|
break;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_SPINNER:
|
2002-09-08 19:09:33 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
|
|
|
gtk_spin_button_new (script->arg_values[i].sfa_adjustment.adj,
|
|
|
|
0,
|
|
|
|
script->arg_defaults[i].sfa_adjustment.digits);
|
|
|
|
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (sf_interface->args_widgets[i]), TRUE);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (sf_interface->args_widgets[i]), TRUE);
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
2001-01-22 04:06:26 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
default: /* this shouldn't happen */
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] = NULL;
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
|
|
|
widget_leftalign = FALSE;
|
|
|
|
|
|
|
|
if (script->arg_types[i] == SF_FILENAME)
|
|
|
|
sf_interface->args_widgets[i] =
|
|
|
|
gimp_file_selection_new (_("Script-Fu File Selection"),
|
|
|
|
script->arg_values[i].sfa_file.filename,
|
|
|
|
FALSE, TRUE);
|
|
|
|
else
|
|
|
|
sf_interface->args_widgets[i] =
|
2002-02-09 01:59:40 +08:00
|
|
|
gimp_file_selection_new (_("Script-Fu Folder Selection"),
|
2001-11-22 02:50:50 +08:00
|
|
|
script->arg_values[i].sfa_file.filename,
|
|
|
|
TRUE, TRUE);
|
|
|
|
|
2001-01-22 04:06:26 +08:00
|
|
|
script->arg_values[i].sfa_file.fileselection =
|
|
|
|
sf_interface->args_widgets[i];
|
1999-05-19 01:33:39 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (sf_interface->args_widgets[i],
|
2001-07-30 08:46:09 +08:00
|
|
|
"filename_changed",
|
|
|
|
G_CALLBACK (script_fu_file_selection_callback),
|
|
|
|
&script->arg_values[i].sfa_file);
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
2000-02-01 04:47:44 +08:00
|
|
|
widget_leftalign = FALSE;
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] = gtk_button_new ();
|
1998-08-10 23:06:58 +08:00
|
|
|
script->arg_values[i].sfa_font.preview = gtk_label_new ("");
|
1999-10-21 20:37:18 +08:00
|
|
|
script->arg_values[i].sfa_font.dialog = NULL;
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (sf_interface->args_widgets[i],
|
|
|
|
FONT_PREVIEW_WIDTH, -1);
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (sf_interface->args_widgets[i]),
|
1998-08-10 23:06:58 +08:00
|
|
|
script->arg_values[i].sfa_font.preview);
|
|
|
|
gtk_widget_show (script->arg_values[i].sfa_font.preview);
|
|
|
|
|
|
|
|
script_fu_font_preview (script->arg_values[i].sfa_font.preview,
|
|
|
|
script->arg_values[i].sfa_font.fontname);
|
1998-08-06 22:58:39 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (sf_interface->args_widgets[i], "clicked",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (script_fu_font_preview_callback),
|
|
|
|
&script->arg_values[i].sfa_font);
|
1998-08-10 23:06:58 +08:00
|
|
|
break;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2001-01-22 04:06:26 +08:00
|
|
|
gimp_pattern_select_widget (_("Script-fu Pattern Selection"),
|
|
|
|
script->arg_values[i].sfa_pattern,
|
|
|
|
script_fu_pattern_preview,
|
|
|
|
&script->arg_values[i].sfa_pattern);
|
1998-10-02 06:09:01 +08:00
|
|
|
break;
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2001-01-22 04:06:26 +08:00
|
|
|
gimp_gradient_select_widget (_("Script-Fu Gradient Selection"),
|
|
|
|
script->arg_values[i].sfa_gradient,
|
|
|
|
script_fu_gradient_preview,
|
|
|
|
&script->arg_values[i].sfa_gradient);
|
1998-11-01 00:22:37 +08:00
|
|
|
break;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] =
|
2001-01-22 04:06:26 +08:00
|
|
|
gimp_brush_select_widget (_("Script-Fu Brush Selection"),
|
|
|
|
script->arg_values[i].sfa_brush.name,
|
|
|
|
script->arg_values[i].sfa_brush.opacity,
|
|
|
|
script->arg_values[i].sfa_brush.spacing,
|
|
|
|
script->arg_values[i].sfa_brush.paint_mode,
|
|
|
|
script_fu_brush_preview,
|
|
|
|
&script->arg_values[i].sfa_brush);
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i] = gtk_option_menu_new ();
|
2000-04-28 08:02:11 +08:00
|
|
|
menu = gtk_menu_new ();
|
|
|
|
for (list = script->arg_defaults[i].sfa_option.list, j = 0;
|
|
|
|
list;
|
|
|
|
list = g_slist_next (list), j++)
|
|
|
|
{
|
|
|
|
menu_item = gtk_menu_item_new_with_label (gettext ((gchar *)list->data));
|
2001-12-29 21:26:29 +08:00
|
|
|
g_object_set_data (G_OBJECT (menu_item), "gimp-item-data",
|
|
|
|
GUINT_TO_POINTER (j));
|
2001-07-30 08:46:09 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
2000-04-28 08:02:11 +08:00
|
|
|
gtk_widget_show (menu_item);
|
|
|
|
}
|
2001-01-22 04:06:26 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (sf_interface->args_widgets[i]),
|
|
|
|
menu);
|
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (sf_interface->args_widgets[i]),
|
2000-04-28 08:02:11 +08:00
|
|
|
script->arg_values[i].sfa_option.history);
|
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, i,
|
|
|
|
label_text, 1.0, label_yalign,
|
2000-11-08 22:35:50 +08:00
|
|
|
sf_interface->args_widgets[i], 1,
|
|
|
|
widget_leftalign);
|
2000-04-28 08:02:11 +08:00
|
|
|
g_free (label_text);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-08-09 20:17:51 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
/* Reset to defaults */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
|
2001-07-30 08:46:09 +08:00
|
|
|
gtk_widget_show (hbox);
|
1998-08-09 20:17:51 +08:00
|
|
|
|
2002-05-25 03:44:37 +08:00
|
|
|
button = gtk_button_new_from_stock (GIMP_STOCK_RESET);
|
1998-08-09 20:17:51 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
2001-07-30 08:46:09 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (script_fu_reset_callback),
|
|
|
|
script);
|
1998-08-09 20:17:51 +08:00
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
|
|
|
gtk_main ();
|
2000-11-08 22:35:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_interface_quit (SFScript *script)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (script != NULL);
|
|
|
|
g_return_if_fail (sf_interface != NULL);
|
|
|
|
|
2002-09-17 21:57:30 +08:00
|
|
|
g_free (sf_interface->title);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
|
|
|
if (sf_interface->about_dialog)
|
|
|
|
gtk_widget_destroy (sf_interface->about_dialog);
|
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_FONT:
|
|
|
|
if (script->arg_values[i].sfa_font.dialog != NULL)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (script->arg_values[i].sfa_font.dialog);
|
|
|
|
script->arg_values[i].sfa_font.dialog = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_PATTERN:
|
|
|
|
gimp_pattern_select_widget_close_popup (sf_interface->args_widgets[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_GRADIENT:
|
|
|
|
gimp_gradient_select_widget_close_popup (sf_interface->args_widgets[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SF_BRUSH:
|
|
|
|
gimp_brush_select_widget_close_popup (sf_interface->args_widgets[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (sf_interface->args_widgets);
|
|
|
|
g_free (sf_interface->last_command);
|
|
|
|
|
|
|
|
g_free (sf_interface);
|
|
|
|
sf_interface = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not call gtk_main_quit() earlier to reduce the possibility
|
|
|
|
* that script_fu_script_proc() is called from gimp_extension_process()
|
|
|
|
* while we are not finished with the current script. This sucks!
|
|
|
|
*/
|
1999-10-21 20:37:18 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_main_quit ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
static void
|
1998-11-09 23:23:29 +08:00
|
|
|
script_fu_pattern_preview (gchar *name,
|
1999-07-28 04:49:55 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
gchar *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-05-03 21:14:32 +08:00
|
|
|
gpointer data)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2000-05-03 21:14:32 +08:00
|
|
|
gchar **pname;
|
|
|
|
|
|
|
|
pname = (gchar **) data;
|
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
g_free (*pname);
|
|
|
|
*pname = g_strdup (name);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
static void
|
2000-02-01 04:47:44 +08:00
|
|
|
script_fu_gradient_preview (gchar *name,
|
|
|
|
gint width,
|
|
|
|
gdouble *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-05-03 21:14:32 +08:00
|
|
|
gpointer data)
|
1998-11-01 00:22:37 +08:00
|
|
|
{
|
2000-05-03 21:14:32 +08:00
|
|
|
gchar **gname;
|
|
|
|
|
|
|
|
gname = (gchar **) data;
|
|
|
|
|
|
|
|
g_free (*gname);
|
|
|
|
*gname = g_strdup (name);
|
1998-11-01 00:22:37 +08:00
|
|
|
}
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
static void
|
2000-05-03 21:14:32 +08:00
|
|
|
script_fu_brush_preview (gchar *name,
|
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
gint paint_mode,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gchar *mask_data,
|
2001-01-22 04:06:26 +08:00
|
|
|
gboolean closing,
|
2000-05-03 21:14:32 +08:00
|
|
|
gpointer data)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2000-05-03 21:14:32 +08:00
|
|
|
SFBrush *brush;
|
|
|
|
|
|
|
|
brush = (SFBrush *) data;
|
|
|
|
|
1999-10-21 20:37:18 +08:00
|
|
|
g_free (brush->name);
|
2001-01-22 04:06:26 +08:00
|
|
|
|
2000-05-03 21:14:32 +08:00
|
|
|
brush->name = g_strdup (name);
|
|
|
|
brush->opacity = opacity;
|
|
|
|
brush->spacing = spacing;
|
1998-10-21 06:36:52 +08:00
|
|
|
brush->paint_mode = paint_mode;
|
|
|
|
}
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
static void
|
|
|
|
script_fu_font_preview (GtkWidget *preview,
|
|
|
|
gchar *data)
|
|
|
|
{
|
2001-11-29 23:54:39 +08:00
|
|
|
/* FIXME: here should be a check if the fontname is valid and the font is present */
|
|
|
|
gtk_label_set_text (GTK_LABEL (preview), data);
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
|
|
|
script_fu_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
GtkWidget *menu_item;
|
2000-11-08 22:35:50 +08:00
|
|
|
gchar *escaped;
|
|
|
|
gchar *text = NULL;
|
|
|
|
gchar *command;
|
|
|
|
gchar *c;
|
2001-01-15 04:25:46 +08:00
|
|
|
guchar r, g, b;
|
2000-11-08 22:35:50 +08:00
|
|
|
gchar buffer[MAX_STRING_LENGTH];
|
|
|
|
gint length;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
SFScript *script = (SFScript *) data;
|
|
|
|
|
2001-11-29 23:54:39 +08:00
|
|
|
#if 0
|
|
|
|
GdkFont *font;
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
/* Check if choosen fonts are there */
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
if (script->arg_types[i] == SF_FONT)
|
|
|
|
{
|
|
|
|
font = gdk_font_load (script->arg_values[i].sfa_font.fontname);
|
|
|
|
if (font == NULL)
|
|
|
|
{
|
2000-04-28 08:02:11 +08:00
|
|
|
g_message (_("At least one font you've choosen is invalid.\n"
|
|
|
|
"Please check your settings.\n"));
|
1998-08-10 23:06:58 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-11-03 05:48:53 +08:00
|
|
|
else
|
|
|
|
gdk_font_unref (font);
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
2001-11-29 23:54:39 +08:00
|
|
|
#endif
|
1998-08-12 03:17:23 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
length = strlen (script->script_name) + 3;
|
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
2001-01-22 04:06:26 +08:00
|
|
|
length += 12; /* Maximum size of integer value */
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_COLOR:
|
|
|
|
length += 16; /* Maximum size of color string: '(XXX XXX XXX) */
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_TOGGLE:
|
|
|
|
length += 6; /* Maximum size of (TRUE, FALSE) */
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_VALUE:
|
2000-11-08 22:35:50 +08:00
|
|
|
length += strlen (gtk_entry_get_text (GTK_ENTRY (sf_interface->args_widgets[i]))) + 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 03:58:10 +08:00
|
|
|
case SF_STRING:
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (gtk_entry_get_text (GTK_ENTRY (sf_interface->args_widgets[i])), NULL);
|
1999-05-29 09:28:24 +08:00
|
|
|
length += strlen (escaped) + 3;
|
|
|
|
g_free (escaped);
|
1998-08-06 03:58:10 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
2001-01-22 04:06:26 +08:00
|
|
|
length += 24; /* Maximum size of float value */
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (script->arg_values[i].sfa_file.filename, NULL);
|
1999-05-29 09:28:24 +08:00
|
|
|
length += strlen (escaped) + 3;
|
|
|
|
g_free (escaped);
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
|
|
|
length += strlen (script->arg_values[i].sfa_font.fontname) + 3;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
|
|
|
length += strlen (script->arg_values[i].sfa_pattern) + 3;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
|
|
|
length += strlen (script->arg_values[i].sfa_gradient) + 3;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
|
|
|
length += strlen (script->arg_values[i].sfa_brush.name) + 3;
|
2001-01-22 04:06:26 +08:00
|
|
|
length += 36; /* Maximum size of three ints */
|
|
|
|
/* for opacity, spacing, mode */
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
2001-01-22 04:06:26 +08:00
|
|
|
length += 12; /* Maximum size of integer value */
|
2000-04-28 08:02:11 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
c = command = g_new (gchar, length);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
sprintf (command, "(%s ", script->script_name);
|
|
|
|
c += strlen (script->script_name) + 2;
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
{
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
2000-02-01 04:47:44 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d",
|
|
|
|
script->arg_values[i].sfa_image);
|
1997-11-25 06:05:25 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
|
|
|
case SF_COLOR:
|
2001-01-15 04:25:46 +08:00
|
|
|
gimp_rgb_get_uchar (&script->arg_values[i].sfa_color, &r, &g, &b);
|
2001-01-22 04:06:26 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "'(%d %d %d)",
|
|
|
|
(gint) r, (gint) g, (gint) b);
|
1997-11-25 06:05:25 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_TOGGLE:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%s",
|
|
|
|
(script->arg_values[i].sfa_toggle) ? "TRUE" : "FALSE");
|
1997-11-25 06:05:25 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case SF_VALUE:
|
2001-07-30 08:46:09 +08:00
|
|
|
text = (gchar *) gtk_entry_get_text (GTK_ENTRY (sf_interface->args_widgets[i]));
|
1998-08-09 20:17:51 +08:00
|
|
|
g_free (script->arg_values[i].sfa_value);
|
|
|
|
script->arg_values[i].sfa_value = g_strdup (text);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 03:58:10 +08:00
|
|
|
case SF_STRING:
|
2001-07-30 08:46:09 +08:00
|
|
|
text = (gchar *) gtk_entry_get_text (GTK_ENTRY (sf_interface->args_widgets[i]));
|
1998-08-09 20:17:51 +08:00
|
|
|
g_free (script->arg_values[i].sfa_value);
|
1999-07-28 04:49:55 +08:00
|
|
|
script->arg_values[i].sfa_value = g_strdup (text);
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (text, NULL);
|
2000-02-01 04:47:44 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"", escaped);
|
1999-05-29 09:28:24 +08:00
|
|
|
g_free (escaped);
|
1998-08-06 03:58:10 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_ADJUSTMENT:
|
2002-11-08 22:46:14 +08:00
|
|
|
switch (script->arg_defaults[i].sfa_adjustment.type)
|
|
|
|
{
|
|
|
|
case SF_SLIDER:
|
|
|
|
script->arg_values[i].sfa_adjustment.value =
|
|
|
|
script->arg_values[i].sfa_adjustment.adj->value;
|
|
|
|
|
|
|
|
text = g_ascii_dtostr (buffer, sizeof (buffer),
|
|
|
|
script->arg_values[i].sfa_adjustment.value);
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
case SF_SPINNER:
|
1999-07-28 04:49:55 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.value =
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_spin_button_get_value (GTK_SPIN_BUTTON (sf_interface->args_widgets[i]));
|
2002-11-08 22:46:14 +08:00
|
|
|
text = g_ascii_dtostr (buffer, sizeof (buffer),
|
|
|
|
script->arg_values[i].sfa_adjustment.value);
|
1998-08-06 22:58:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-06 22:58:39 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
2001-11-23 07:46:13 +08:00
|
|
|
escaped = g_strescape (script->arg_values[i].sfa_file.filename,
|
|
|
|
NULL);
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"", escaped);
|
1999-05-29 09:28:24 +08:00
|
|
|
g_free (escaped);
|
1998-11-06 08:51:39 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"",
|
|
|
|
script->arg_values[i].sfa_font.fontname);
|
1998-08-10 23:06:58 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"",
|
|
|
|
script->arg_values[i].sfa_pattern);
|
1998-10-02 06:09:01 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "\"%s\"",
|
|
|
|
script->arg_values[i].sfa_gradient);
|
1998-11-01 00:22:37 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
2002-11-08 22:46:14 +08:00
|
|
|
{
|
|
|
|
gchar opacity[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
g_ascii_dtostr (opacity, sizeof (opacity),
|
|
|
|
script->arg_values[i].sfa_brush.opacity);
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "'(\"%s\" %s %d %d)",
|
|
|
|
script->arg_values[i].sfa_brush.name,
|
|
|
|
opacity,
|
|
|
|
script->arg_values[i].sfa_brush.spacing,
|
|
|
|
script->arg_values[i].sfa_brush.paint_mode);
|
|
|
|
text = buffer;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
|
|
|
menu_item =
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_menu_get_active (GTK_MENU (gtk_option_menu_get_menu (GTK_OPTION_MENU (sf_interface->args_widgets[i]))));
|
2000-04-28 08:02:11 +08:00
|
|
|
script->arg_values[i].sfa_option.history =
|
2001-12-29 21:26:29 +08:00
|
|
|
GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (menu_item),
|
|
|
|
"gimp-item-data"));
|
2000-05-03 21:14:32 +08:00
|
|
|
g_snprintf (buffer, sizeof (buffer), "%d",
|
|
|
|
script->arg_values[i].sfa_option.history);
|
2000-04-28 08:02:11 +08:00
|
|
|
text = buffer;
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == script->num_args - 1)
|
|
|
|
sprintf (c, "%s)", text);
|
|
|
|
else
|
|
|
|
sprintf (c, "%s ", text);
|
|
|
|
c += strlen (text) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run the command through the interpreter */
|
2000-11-08 22:35:50 +08:00
|
|
|
if (repl_c_string (command, 0, 0, 1) != 0)
|
|
|
|
script_fu_error_msg (command);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
g_free (command);
|
|
|
|
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_widget_destroy (sf_interface->dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
static void
|
|
|
|
script_fu_about_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-07-30 08:46:09 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *text_view;
|
|
|
|
GtkTextBuffer *text_buffer;
|
1998-08-12 03:17:23 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
SFScript *script = (SFScript *) data;
|
|
|
|
|
|
|
|
if (sf_interface->about_dialog == NULL)
|
1998-08-12 03:17:23 +08:00
|
|
|
{
|
2002-09-17 21:57:30 +08:00
|
|
|
dialog = gimp_dialog_new (sf_interface->title, "script-fu-about",
|
2001-07-30 08:46:09 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
"filters/script-fu.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, TRUE, FALSE,
|
|
|
|
|
2001-08-04 03:52:08 +08:00
|
|
|
GTK_STOCK_CLOSE, gtk_widget_destroy, NULL,
|
2001-07-30 08:46:09 +08:00
|
|
|
1, NULL, TRUE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
sf_interface->about_dialog = dialog;
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (dialog, "destroy",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
&sf_interface->about_dialog);
|
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
|
|
|
|
TRUE, TRUE, 0);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-05-25 03:44:37 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
2000-02-01 04:47:44 +08:00
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
/* the name */
|
2002-05-25 03:44:37 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
label = gtk_label_new (script->script_name);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_misc_set_padding (GTK_MISC (label), 2, 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), label);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
/* the help display */
|
2001-07-30 08:46:09 +08:00
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
|
2001-07-30 08:46:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
|
|
|
text_buffer = gtk_text_buffer_new (NULL);
|
|
|
|
text_view = gtk_text_view_new_with_buffer (text_buffer);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_object_unref (text_buffer);
|
2001-07-30 08:46:09 +08:00
|
|
|
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_widget_set_size_request (text_view, 240, 120);
|
2001-07-30 08:46:09 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
|
|
|
gtk_widget_show (text_view);
|
|
|
|
|
|
|
|
gtk_text_buffer_set_text (text_buffer, script->help, -1);
|
1998-08-12 03:17:23 +08:00
|
|
|
|
|
|
|
/* author, copyright, etc. */
|
|
|
|
table = gtk_table_new (2, 4, FALSE);
|
2002-05-25 03:44:37 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
label = gtk_label_new (script->author);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Author:"), 1.0, 0.5,
|
|
|
|
label, 1, FALSE);
|
1998-08-12 03:17:23 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
label = gtk_label_new (script->copyright);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
|
|
|
_("Copyright:"), 1.0, 0.5,
|
|
|
|
label, 1, FALSE);
|
1998-08-12 03:17:23 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
label = gtk_label_new (script->date);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
|
|
|
|
_("Date:"), 1.0, 0.5,
|
|
|
|
label, 1, FALSE);
|
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
if (strlen (script->img_types) > 0)
|
1998-08-12 03:17:23 +08:00
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
label = gtk_label_new (script->img_types);
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
|
|
|
|
_("Image Types:"), 1.0, 0.5,
|
|
|
|
label, 1, FALSE);
|
1998-08-12 03:17:23 +08:00
|
|
|
}
|
|
|
|
}
|
2000-11-08 22:35:50 +08:00
|
|
|
|
|
|
|
gtk_widget_show (sf_interface->about_dialog);
|
1998-08-12 03:17:23 +08:00
|
|
|
}
|
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
static void
|
|
|
|
script_fu_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-01-11 06:49:45 +08:00
|
|
|
gint i;
|
1998-08-09 20:17:51 +08:00
|
|
|
|
2000-11-08 22:35:50 +08:00
|
|
|
SFScript *script = (SFScript *) data;
|
1998-08-09 20:17:51 +08:00
|
|
|
|
|
|
|
for (i = 0; i < script->num_args; i++)
|
|
|
|
switch (script->arg_types[i])
|
|
|
|
{
|
|
|
|
case SF_IMAGE:
|
|
|
|
case SF_DRAWABLE:
|
|
|
|
case SF_LAYER:
|
|
|
|
case SF_CHANNEL:
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
case SF_COLOR:
|
2001-01-15 04:25:46 +08:00
|
|
|
script->arg_values[i].sfa_color = script->arg_defaults[i].sfa_color;
|
2001-01-11 06:49:45 +08:00
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (sf_interface->args_widgets[i]),
|
|
|
|
&script->arg_values[i].sfa_color);
|
1998-08-09 20:17:51 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
case SF_TOGGLE:
|
|
|
|
script->arg_values[i].sfa_toggle = script->arg_defaults[i].sfa_toggle;
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sf_interface->args_widgets[i]),
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_toggle);
|
1998-08-09 20:17:51 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
case SF_VALUE:
|
|
|
|
case SF_STRING:
|
|
|
|
g_free (script->arg_values[i].sfa_value);
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_value =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_value);
|
2000-11-08 22:35:50 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (sf_interface->args_widgets[i]),
|
1998-08-09 20:17:51 +08:00
|
|
|
script->arg_values[i].sfa_value);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
case SF_ADJUSTMENT:
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_adjustment.value =
|
|
|
|
script->arg_defaults[i].sfa_adjustment.value;
|
1998-08-09 20:17:51 +08:00
|
|
|
gtk_adjustment_set_value (script->arg_values[i].sfa_adjustment.adj,
|
|
|
|
script->arg_values[i].sfa_adjustment.value);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
case SF_FILENAME:
|
2001-11-22 02:50:50 +08:00
|
|
|
case SF_DIRNAME:
|
1998-11-06 08:51:39 +08:00
|
|
|
g_free (script->arg_values[i].sfa_file.filename);
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_file.filename =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_file.filename);
|
|
|
|
gimp_file_selection_set_filename
|
|
|
|
(GIMP_FILE_SELECTION (script->arg_values[i].sfa_file.fileselection),
|
|
|
|
script->arg_values[i].sfa_file.filename);
|
1998-11-06 08:51:39 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
case SF_FONT:
|
|
|
|
g_free (script->arg_values[i].sfa_font.fontname);
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_values[i].sfa_font.fontname =
|
|
|
|
g_strdup (script->arg_defaults[i].sfa_font.fontname);
|
1998-08-10 23:06:58 +08:00
|
|
|
if (script->arg_values[i].sfa_font.dialog)
|
|
|
|
{
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_font_selection_dialog_set_font_name
|
|
|
|
(GTK_FONT_SELECTION_DIALOG (script->arg_values[i].sfa_font.dialog),
|
|
|
|
script->arg_values[i].sfa_font.fontname);
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
|
|
|
script_fu_font_preview (script->arg_values[i].sfa_font.preview,
|
|
|
|
script->arg_values[i].sfa_font.fontname);
|
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
case SF_PATTERN:
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_pattern_select_widget_set_popup
|
2000-11-08 22:35:50 +08:00
|
|
|
(sf_interface->args_widgets[i], script->arg_defaults[i].sfa_pattern);
|
1998-10-02 06:09:01 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-11-01 00:22:37 +08:00
|
|
|
case SF_GRADIENT:
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_gradient_select_widget_set_popup
|
2000-11-08 22:35:50 +08:00
|
|
|
(sf_interface->args_widgets[i], script->arg_defaults[i].sfa_gradient);
|
1998-11-01 00:22:37 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case SF_BRUSH:
|
2000-02-01 04:47:44 +08:00
|
|
|
gimp_brush_select_widget_set_popup
|
2000-11-08 22:35:50 +08:00
|
|
|
(sf_interface->args_widgets[i],
|
2000-02-01 04:47:44 +08:00
|
|
|
script->arg_defaults[i].sfa_brush.name,
|
|
|
|
script->arg_defaults[i].sfa_brush.opacity,
|
|
|
|
script->arg_defaults[i].sfa_brush.spacing,
|
|
|
|
script->arg_defaults[i].sfa_brush.paint_mode);
|
1998-10-21 06:36:52 +08:00
|
|
|
break;
|
2000-11-08 22:35:50 +08:00
|
|
|
|
2000-04-28 08:02:11 +08:00
|
|
|
case SF_OPTION:
|
2000-11-08 22:35:50 +08:00
|
|
|
script->arg_values[i].sfa_option.history =
|
|
|
|
script->arg_defaults[i].sfa_option.history;
|
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (sf_interface->args_widgets[i]),
|
2000-04-28 08:02:11 +08:00
|
|
|
script->arg_values[i].sfa_option.history);
|
2000-11-08 22:35:50 +08:00
|
|
|
|
1998-08-09 20:17:51 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2000-04-28 08:02:11 +08:00
|
|
|
script_fu_menu_callback (gint32 id,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
*((gint32 *) data) = id;
|
|
|
|
}
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
static void
|
1999-05-19 01:33:39 +08:00
|
|
|
script_fu_file_selection_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
|
|
|
SFFilename *file;
|
|
|
|
|
|
|
|
file = (SFFilename *) data;
|
|
|
|
|
1999-05-19 01:33:39 +08:00
|
|
|
if (file->filename)
|
|
|
|
g_free (file->filename);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
1999-10-21 20:37:18 +08:00
|
|
|
file->filename =
|
|
|
|
gimp_file_selection_get_filename (GIMP_FILE_SELECTION (file->fileselection));
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
1998-08-10 23:06:58 +08:00
|
|
|
static void
|
|
|
|
script_fu_font_preview_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFontSelectionDialog *fsd;
|
2001-01-22 04:06:26 +08:00
|
|
|
SFFont *font;
|
1998-08-10 23:06:58 +08:00
|
|
|
|
|
|
|
font = (SFFont *) data;
|
|
|
|
|
2001-07-30 08:46:09 +08:00
|
|
|
if (! font->dialog)
|
1998-08-10 23:06:58 +08:00
|
|
|
{
|
2001-07-30 08:46:09 +08:00
|
|
|
font->dialog =
|
2001-01-22 04:06:26 +08:00
|
|
|
gtk_font_selection_dialog_new (_("Script-Fu Font Selection"));
|
1998-08-10 23:06:58 +08:00
|
|
|
fsd = GTK_FONT_SELECTION_DIALOG (font->dialog);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (fsd->ok_button, "clicked",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (script_fu_font_dialog_ok),
|
|
|
|
font);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (fsd, "delete_event",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (script_fu_font_dialog_delete),
|
|
|
|
font);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (fsd, "destroy",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
&font->dialog);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (fsd->cancel_button, "clicked",
|
2001-07-30 08:46:09 +08:00
|
|
|
G_CALLBACK (script_fu_font_dialog_cancel),
|
|
|
|
font);
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
|
|
|
else
|
2001-07-30 08:46:09 +08:00
|
|
|
{
|
|
|
|
fsd = GTK_FONT_SELECTION_DIALOG (font->dialog);
|
|
|
|
}
|
1998-08-10 23:06:58 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_font_selection_dialog_set_font_name (fsd, font->fontname);
|
2000-08-28 08:42:32 +08:00
|
|
|
gtk_window_set_position (GTK_WINDOW (font->dialog), GTK_WIN_POS_MOUSE);
|
1998-08-10 23:06:58 +08:00
|
|
|
gtk_widget_show (font->dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_font_dialog_ok (GtkWidget *widget,
|
1999-07-28 04:49:55 +08:00
|
|
|
gpointer data)
|
1998-08-10 23:06:58 +08:00
|
|
|
{
|
|
|
|
SFFont *font;
|
|
|
|
gchar *fontname;
|
|
|
|
|
|
|
|
font = (SFFont *) data;
|
|
|
|
|
2001-01-22 04:06:26 +08:00
|
|
|
fontname =
|
|
|
|
gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font->dialog));
|
1998-08-10 23:06:58 +08:00
|
|
|
if (fontname != NULL)
|
|
|
|
{
|
|
|
|
g_free (font->fontname);
|
|
|
|
font->fontname = fontname;
|
|
|
|
}
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_widget_hide (font->dialog);
|
1998-08-10 23:06:58 +08:00
|
|
|
|
|
|
|
script_fu_font_preview (font->preview, font->fontname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
script_fu_font_dialog_cancel (GtkWidget *widget,
|
1999-07-28 04:49:55 +08:00
|
|
|
gpointer data)
|
1998-08-10 23:06:58 +08:00
|
|
|
{
|
|
|
|
SFFont *font;
|
|
|
|
|
|
|
|
font = (SFFont *) data;
|
|
|
|
|
1998-08-12 03:17:23 +08:00
|
|
|
gtk_widget_hide (font->dialog);
|
1998-08-10 23:06:58 +08:00
|
|
|
}
|
|
|
|
|
2001-01-22 04:06:26 +08:00
|
|
|
static gboolean
|
1998-08-10 23:06:58 +08:00
|
|
|
script_fu_font_dialog_delete (GtkWidget *widget,
|
1999-07-28 04:49:55 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
1998-08-10 23:06:58 +08:00
|
|
|
{
|
|
|
|
script_fu_font_dialog_cancel (widget, data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
1998-08-12 03:17:23 +08:00
|
|
|
|
|
|
|
static void
|
2000-11-08 22:35:50 +08:00
|
|
|
script_fu_error_msg (gchar *command)
|
1998-08-12 03:17:23 +08:00
|
|
|
{
|
2000-11-08 22:35:50 +08:00
|
|
|
g_message (_("Script-Fu Error while executing\n %s\n%s"),
|
|
|
|
command, siod_err_msg);
|
1998-08-12 03:17:23 +08:00
|
|
|
}
|