New ScriptFu argument type SF-ADJUSTMENT: You can have sliders and
spin-buttons in the dialog. Documented in the new script (test-sphere.scm) --Sven
This commit is contained in:
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
Thu Aug 6 16:55:45 MEST 1998 Sven Neumann <sven@gimp.org>:
|
||||
|
||||
* plug-ins/script-fu/script-fu-enums.h
|
||||
* plug-ins/script-fu/script-fu.c
|
||||
* plug-ins/script-fu/script-fu-scripts.c: New ScriptFu argument type
|
||||
SF-ADJUSTMENT: You can have sliders and spin-buttons in the dialog.
|
||||
|
||||
* plug-ins/script-fu/scripts/test-sphere.scm: Simple script to show
|
||||
and test the new interface.
|
||||
|
||||
Wed Aug 5 16:29:05 PDT 1998 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* initial merge of the internationalization stuff. It's still
|
||||
|
@ -30,7 +30,20 @@ typedef enum
|
||||
SF_COLOR,
|
||||
SF_TOGGLE,
|
||||
SF_VALUE,
|
||||
SF_STRING
|
||||
SF_STRING,
|
||||
SF_ADJUSTMENT
|
||||
} SFArgType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SF_SLIDER = 0,
|
||||
SF_SPINNER
|
||||
} SFAdjustmentType;
|
||||
|
||||
#endif /* __SCRIPT_FU_ENUMS__ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
#define TEXT_HEIGHT 25
|
||||
#define COLOR_SAMPLE_WIDTH 100
|
||||
#define COLOR_SAMPLE_HEIGHT 15
|
||||
#define SLIDER_WIDTH 100
|
||||
#define SLIDER_HEIGHT 30
|
||||
#define SPINNER_WIDTH 75
|
||||
|
||||
#define MAX_STRING_LENGTH 4096
|
||||
|
||||
@ -42,6 +45,18 @@ typedef struct
|
||||
gdouble old_color[3];
|
||||
} SFColor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
gfloat value;
|
||||
gfloat lower;
|
||||
gfloat upper;
|
||||
gfloat step;
|
||||
gfloat page;
|
||||
gint digits;
|
||||
SFAdjustmentType type;
|
||||
} SFAdjustment;
|
||||
|
||||
typedef union
|
||||
{
|
||||
gint32 sfa_image;
|
||||
@ -52,6 +67,7 @@ typedef union
|
||||
gint32 sfa_toggle;
|
||||
gchar * sfa_value;
|
||||
gchar * sfa_string;
|
||||
SFAdjustment sfa_adjustment;
|
||||
} SFArgValue;
|
||||
|
||||
typedef struct
|
||||
@ -279,6 +295,7 @@ script_fu_add_script (LISP a)
|
||||
int i;
|
||||
gdouble color[3];
|
||||
LISP color_list;
|
||||
LISP adj_list;
|
||||
gchar *menu_path = NULL;
|
||||
|
||||
/* Check the length of a */
|
||||
@ -461,6 +478,31 @@ script_fu_add_script (LISP a)
|
||||
args[i + 1].description = script->arg_labels[i];
|
||||
break;
|
||||
|
||||
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);
|
||||
script->arg_defaults[i].sfa_adjustment.value = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.lower = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.upper = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.step = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.page = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.digits = get_c_long (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.type = get_c_long (car (adj_list));
|
||||
script->arg_values[i].sfa_adjustment.adj = NULL;
|
||||
script->arg_values[i].sfa_adjustment.value = script->arg_defaults[i].sfa_adjustment.value;
|
||||
|
||||
args[i + 1].type = PARAM_STRING;
|
||||
args[i + 1].name = "value";
|
||||
args[i + 1].description = script->arg_labels[i];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -603,6 +645,9 @@ script_fu_script_proc (char *name,
|
||||
case SF_STRING:
|
||||
length += strlen (params[i + 1].data.d_string) + 3;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
length += strlen (params[i + 1].data.d_string) + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -642,6 +687,9 @@ script_fu_script_proc (char *name,
|
||||
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
text = params[i + 1].data.d_string;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -730,6 +778,8 @@ script_fu_free_script (SFScript *script)
|
||||
case SF_STRING:
|
||||
g_free (script->arg_defaults[i].sfa_string);
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -934,6 +984,40 @@ script_fu_interface (SFScript *script)
|
||||
gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_string);
|
||||
break;
|
||||
|
||||
case SF_ADJUSTMENT:
|
||||
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);
|
||||
switch (script->arg_defaults[i].sfa_adjustment.type)
|
||||
{
|
||||
case SF_SLIDER:
|
||||
script->args_widgets[i] = gtk_hscale_new (script->arg_values[i].sfa_adjustment.adj);
|
||||
gtk_widget_set_usize (GTK_WIDGET (script->args_widgets[i]),
|
||||
SLIDER_WIDTH, SLIDER_HEIGHT);
|
||||
gtk_scale_set_digits (GTK_SCALE (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_adjustment.digits);
|
||||
gtk_scale_set_draw_value (GTK_SCALE (script->args_widgets[i]), TRUE);
|
||||
gtk_range_set_update_policy (GTK_RANGE (script->args_widgets[i]),
|
||||
GTK_UPDATE_DELAYED);
|
||||
break;
|
||||
case SF_SPINNER:
|
||||
script->args_widgets[i] = gtk_spin_button_new (script->arg_values[i].sfa_adjustment.adj, 0, 0);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (script->args_widgets[i]), TRUE);
|
||||
gtk_widget_set_usize (script->args_widgets[i], SPINNER_WIDTH, 0);
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_adjustment.digits);
|
||||
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (script->args_widgets[i]), TRUE);
|
||||
break;
|
||||
default: /* this shouldn't happen */
|
||||
script->args_widgets[i] = NULL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1069,6 +1153,9 @@ script_fu_ok_callback (GtkWidget *widget,
|
||||
case SF_STRING:
|
||||
length += strlen (gtk_entry_get_text (GTK_ENTRY (script->args_widgets[i]))) + 3;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
length += 24; /* Maximum size of float value should not exceed this many characters */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1107,6 +1194,22 @@ script_fu_ok_callback (GtkWidget *widget,
|
||||
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", text);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
switch (script->arg_defaults[i].sfa_adjustment.type)
|
||||
{
|
||||
case SF_SLIDER:
|
||||
g_snprintf (buffer, 24, "%f", script->arg_values[i].sfa_adjustment.adj->value);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_SPINNER:
|
||||
g_snprintf (buffer, 24, "%f",
|
||||
gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (script->args_widgets[i])));
|
||||
text = buffer;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -31,6 +31,9 @@
|
||||
#define TEXT_HEIGHT 25
|
||||
#define COLOR_SAMPLE_WIDTH 100
|
||||
#define COLOR_SAMPLE_HEIGHT 15
|
||||
#define SLIDER_WIDTH 100
|
||||
#define SLIDER_HEIGHT 30
|
||||
#define SPINNER_WIDTH 75
|
||||
|
||||
#define MAX_STRING_LENGTH 4096
|
||||
|
||||
@ -42,6 +45,18 @@ typedef struct
|
||||
gdouble old_color[3];
|
||||
} SFColor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
gfloat value;
|
||||
gfloat lower;
|
||||
gfloat upper;
|
||||
gfloat step;
|
||||
gfloat page;
|
||||
gint digits;
|
||||
SFAdjustmentType type;
|
||||
} SFAdjustment;
|
||||
|
||||
typedef union
|
||||
{
|
||||
gint32 sfa_image;
|
||||
@ -52,6 +67,7 @@ typedef union
|
||||
gint32 sfa_toggle;
|
||||
gchar * sfa_value;
|
||||
gchar * sfa_string;
|
||||
SFAdjustment sfa_adjustment;
|
||||
} SFArgValue;
|
||||
|
||||
typedef struct
|
||||
@ -279,6 +295,7 @@ script_fu_add_script (LISP a)
|
||||
int i;
|
||||
gdouble color[3];
|
||||
LISP color_list;
|
||||
LISP adj_list;
|
||||
gchar *menu_path = NULL;
|
||||
|
||||
/* Check the length of a */
|
||||
@ -461,6 +478,31 @@ script_fu_add_script (LISP a)
|
||||
args[i + 1].description = script->arg_labels[i];
|
||||
break;
|
||||
|
||||
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);
|
||||
script->arg_defaults[i].sfa_adjustment.value = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.lower = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.upper = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.step = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.page = get_c_double (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.digits = get_c_long (car (adj_list));
|
||||
adj_list = cdr (adj_list);
|
||||
script->arg_defaults[i].sfa_adjustment.type = get_c_long (car (adj_list));
|
||||
script->arg_values[i].sfa_adjustment.adj = NULL;
|
||||
script->arg_values[i].sfa_adjustment.value = script->arg_defaults[i].sfa_adjustment.value;
|
||||
|
||||
args[i + 1].type = PARAM_STRING;
|
||||
args[i + 1].name = "value";
|
||||
args[i + 1].description = script->arg_labels[i];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -603,6 +645,9 @@ script_fu_script_proc (char *name,
|
||||
case SF_STRING:
|
||||
length += strlen (params[i + 1].data.d_string) + 3;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
length += strlen (params[i + 1].data.d_string) + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -642,6 +687,9 @@ script_fu_script_proc (char *name,
|
||||
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", params[i + 1].data.d_string);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
text = params[i + 1].data.d_string;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -730,6 +778,8 @@ script_fu_free_script (SFScript *script)
|
||||
case SF_STRING:
|
||||
g_free (script->arg_defaults[i].sfa_string);
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -934,6 +984,40 @@ script_fu_interface (SFScript *script)
|
||||
gtk_entry_set_text (GTK_ENTRY (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_string);
|
||||
break;
|
||||
|
||||
case SF_ADJUSTMENT:
|
||||
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);
|
||||
switch (script->arg_defaults[i].sfa_adjustment.type)
|
||||
{
|
||||
case SF_SLIDER:
|
||||
script->args_widgets[i] = gtk_hscale_new (script->arg_values[i].sfa_adjustment.adj);
|
||||
gtk_widget_set_usize (GTK_WIDGET (script->args_widgets[i]),
|
||||
SLIDER_WIDTH, SLIDER_HEIGHT);
|
||||
gtk_scale_set_digits (GTK_SCALE (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_adjustment.digits);
|
||||
gtk_scale_set_draw_value (GTK_SCALE (script->args_widgets[i]), TRUE);
|
||||
gtk_range_set_update_policy (GTK_RANGE (script->args_widgets[i]),
|
||||
GTK_UPDATE_DELAYED);
|
||||
break;
|
||||
case SF_SPINNER:
|
||||
script->args_widgets[i] = gtk_spin_button_new (script->arg_values[i].sfa_adjustment.adj, 0, 0);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (script->args_widgets[i]), TRUE);
|
||||
gtk_widget_set_usize (script->args_widgets[i], SPINNER_WIDTH, 0);
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (script->args_widgets[i]),
|
||||
script->arg_defaults[i].sfa_adjustment.digits);
|
||||
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (script->args_widgets[i]), TRUE);
|
||||
break;
|
||||
default: /* this shouldn't happen */
|
||||
script->args_widgets[i] = NULL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1069,6 +1153,9 @@ script_fu_ok_callback (GtkWidget *widget,
|
||||
case SF_STRING:
|
||||
length += strlen (gtk_entry_get_text (GTK_ENTRY (script->args_widgets[i]))) + 3;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
length += 24; /* Maximum size of float value should not exceed this many characters */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1107,6 +1194,22 @@ script_fu_ok_callback (GtkWidget *widget,
|
||||
g_snprintf (buffer, MAX_STRING_LENGTH, "\"%s\"", text);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_ADJUSTMENT:
|
||||
switch (script->arg_defaults[i].sfa_adjustment.type)
|
||||
{
|
||||
case SF_SLIDER:
|
||||
g_snprintf (buffer, 24, "%f", script->arg_values[i].sfa_adjustment.adj->value);
|
||||
text = buffer;
|
||||
break;
|
||||
case SF_SPINNER:
|
||||
g_snprintf (buffer, 24, "%f",
|
||||
gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (script->args_widgets[i])));
|
||||
text = buffer;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -447,6 +447,11 @@ init_constants ()
|
||||
setvar (cintern ("SF-TOGGLE"), flocons (SF_TOGGLE), NIL);
|
||||
setvar (cintern ("SF-VALUE"), flocons (SF_VALUE), NIL);
|
||||
setvar (cintern ("SF-STRING"), flocons (SF_STRING), NIL);
|
||||
setvar (cintern ("SF-ADJUSTMENT"), flocons (SF_ADJUSTMENT), NIL);
|
||||
|
||||
/* for SF_ADJUSTMENT */
|
||||
setvar (cintern ("SF-SLIDER"), flocons (SF_SLIDER), NIL);
|
||||
setvar (cintern ("SF-SPINNER"), flocons (SF_SPINNER), NIL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -95,7 +95,8 @@ scriptdata_DATA = \
|
||||
unsharp-mask.scm \
|
||||
waves-anim.scm \
|
||||
weave.scm \
|
||||
xach-effect.scm
|
||||
xach-effect.scm \
|
||||
test-sphere.scm
|
||||
|
||||
EXTRA_DATA =
|
||||
EXTRA_DIST = $(scriptdata_DATA)
|
||||
|
66
plug-ins/script-fu/scripts/test-sphere.scm
Normal file
66
plug-ins/script-fu/scripts/test-sphere.scm
Normal file
@ -0,0 +1,66 @@
|
||||
; This is a slightly modified copy of the sphere script to show and test
|
||||
; the possibilities of the new Script-Fu API extensions.
|
||||
;
|
||||
; SF-ADJUSTMENT is only useful in interactive mode, if you call a script from
|
||||
; the console, it acts just like a normal SF-VALUE
|
||||
; In interactive mode it creates an adjustment widget in the dialog.
|
||||
;
|
||||
; Usage:
|
||||
; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)
|
||||
;
|
||||
; type is one of: SLIDER(0), SPINNER(1)
|
||||
;
|
||||
(define (script-fu-test-sphere radius light shadow bg-color sphere-color)
|
||||
(let* ((width (* radius 3.75))
|
||||
(height (* radius 2.5))
|
||||
(img (car (gimp-image-new width height RGB)))
|
||||
(drawable (car (gimp-layer-new img width height RGB_IMAGE "Sphere Layer" 100 NORMAL)))
|
||||
(radians (/ (* light *pi*) 180))
|
||||
(cx (/ width 2))
|
||||
(cy (/ height 2))
|
||||
(light-x (+ cx (* radius (* 0.6 (cos radians)))))
|
||||
(light-y (- cy (* radius (* 0.6 (sin radians)))))
|
||||
(light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
|
||||
(light-end-y (- cy (* radius (sin (+ *pi* radians)))))
|
||||
(offset (* radius 0.1))
|
||||
(old-fg (car (gimp-palette-get-foreground)))
|
||||
(old-bg (car (gimp-palette-get-background))))
|
||||
(gimp-image-disable-undo img)
|
||||
(gimp-image-add-layer img drawable 0)
|
||||
(gimp-palette-set-foreground sphere-color)
|
||||
(gimp-palette-set-background bg-color)
|
||||
(gimp-edit-fill img drawable)
|
||||
(gimp-palette-set-background '(20 20 20))
|
||||
(if (and
|
||||
(or (and (>= light 45) (<= light 75)) (and (<= light 135) (>= light 105)))
|
||||
(= shadow TRUE))
|
||||
(let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
|
||||
(shadow-h (* radius 0.5))
|
||||
(shadow-x cx)
|
||||
(shadow-y (+ cy (* radius 0.65))))
|
||||
(if (< shadow-w 0)
|
||||
(prog1 (set! shadow-x (+ cx shadow-w))
|
||||
(set! shadow-w (- shadow-w))))
|
||||
(gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h REPLACE TRUE TRUE 7.5)
|
||||
(gimp-bucket-fill img drawable BG-BUCKET-FILL MULTIPLY 100 0 FALSE 0 0)))
|
||||
(gimp-ellipse-select img (- cx radius) (- cy radius) (* 2 radius) (* 2 radius) REPLACE TRUE FALSE 0)
|
||||
(gimp-blend img drawable FG-BG-RGB NORMAL RADIAL 100 offset REPEAT-NONE
|
||||
FALSE 0 0 light-x light-y light-end-x light-end-y)
|
||||
(gimp-selection-none img)
|
||||
(gimp-palette-set-background old-bg)
|
||||
(gimp-palette-set-foreground old-fg)
|
||||
(gimp-image-enable-undo img)
|
||||
(gimp-display-new img)))
|
||||
|
||||
(script-fu-register "script-fu-test-sphere"
|
||||
"<Toolbox>/Xtns/Script-Fu/Test/Sphere"
|
||||
"Simple spheres with drop shadows"
|
||||
"Spencer Kimball"
|
||||
"Spencer Kimball"
|
||||
"1996"
|
||||
""
|
||||
SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1)
|
||||
SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0)
|
||||
SF-TOGGLE "Shadow" TRUE
|
||||
SF-COLOR "Background Color" '(255 255 255)
|
||||
SF-COLOR "Sphere Color" '(255 0 0))
|
Reference in New Issue
Block a user