plug-ins: port gradient-flare to gimp_image_procedure_new2() and GimpProcedureDialog.

The port to GimpProcedureDialog is partial as there are still quite a few pieces
which can be improved. But it's a good start.
This commit is contained in:
Jehan 2023-06-20 23:18:44 +02:00
parent 7da0db9e88
commit 96b3302e65
1 changed files with 408 additions and 436 deletions

View File

@ -346,21 +346,6 @@ struct _GradientCacheItem
guchar values[4 * GRADIENT_RESOLUTION]; guchar values[4 * GRADIENT_RESOLUTION];
}; };
typedef struct
{
gint xcenter;
gint ycenter;
gdouble radius;
gdouble rotation;
gdouble hue;
gdouble vangle;
gdouble vlength;
gint use_asupsample;
gint asupsample_max_depth;
gdouble asupsample_threshold;
gchar gflare_name[GFLARE_NAME_MAX];
} PluginValues;
typedef void (* QueryFunc) (GtkWidget *, typedef void (* QueryFunc) (GtkWidget *,
gpointer, gpointer,
@ -395,7 +380,7 @@ static GimpValueArray * gflare_run (GimpProcedure *procedure
GimpImage *image, GimpImage *image,
gint n_drawables, gint n_drawables,
GimpDrawable **drawables, GimpDrawable **drawables,
const GimpValueArray *args, GimpProcedureConfig *config,
gpointer run_data); gpointer run_data);
static GFlare * gflare_new_with_default (const gchar *new_name); static GFlare * gflare_new_with_default (const gchar *new_name);
@ -406,8 +391,6 @@ static void gflare_copy (GFlare *dest,
static GFlare * gflare_load (const gchar *filename, static GFlare * gflare_load (const gchar *filename,
const gchar *name); const gchar *name);
static void gflare_save (GFlare *gflare); static void gflare_save (GFlare *gflare);
static void gflare_name_copy (gchar *dest,
const gchar *src);
static gint gflares_list_insert (GFlare *gflare); static gint gflares_list_insert (GFlare *gflare);
static GFlare * gflares_list_lookup (const gchar *name); static GFlare * gflares_list_lookup (const gchar *name);
@ -418,8 +401,8 @@ static void gflares_list_free_all (void);
static void calc_init_params (GFlare *gflare, static void calc_init_params (GFlare *gflare,
gint calc_type, gint calc_type,
gdouble xcenter, gint xcenter,
gdouble ycenter, gint ycenter,
gdouble radius, gdouble radius,
gdouble rotation, gdouble rotation,
gdouble hue, gdouble hue,
@ -442,7 +425,8 @@ static void calc_gflare_pix (guchar *dest_pix,
gdouble y, gdouble y,
guchar *src_pix); guchar *src_pix);
static gboolean dlg_run (void); static gboolean dlg_run (GimpProcedure *procedure,
GimpProcedureConfig *config);
static void dlg_preview_calc_window (void); static void dlg_preview_calc_window (void);
static void ed_preview_calc_window (void); static void ed_preview_calc_window (void);
static GtkWidget * ed_mode_menu_new (GFlareMode *mode_var); static GtkWidget * ed_mode_menu_new (GFlareMode *mode_var);
@ -486,12 +470,14 @@ static void gradient_cache_flush (void);
*** +++ Static Functions Prototypes *** +++ Static Functions Prototypes
**/ **/
static void plugin_do (void); static void plugin_do (GimpProcedureConfig *config);
static void plugin_do_non_asupsample (GeglBuffer *src_buffer, static void plugin_do_non_asupsample (GeglBuffer *src_buffer,
GeglBuffer *dest_buffer); GeglBuffer *dest_buffer);
static void plugin_do_asupsample (GeglBuffer *src_buffer, static void plugin_do_asupsample (GeglBuffer *src_buffer,
GeglBuffer *dest_buffer); GeglBuffer *dest_buffer,
gint asupsample_max_depth,
gdouble asupsample_threshold);
static void plugin_render_func (gdouble x, static void plugin_render_func (gdouble x,
gdouble y, gdouble y,
GimpRGB *color, GimpRGB *color,
@ -546,10 +532,11 @@ static void calc_overlay (guchar *dest,
guchar *src1, guchar *src1,
guchar *src2); guchar *src2);
static void dlg_setup_gflare (void); static void dlg_setup_gflare (const gchar *gflare_name);
static void dlg_preview_realize (GtkWidget *widget); static void dlg_preview_realize (GtkWidget *widget);
static gboolean dlg_preview_handle_event (GtkWidget *widget, static gboolean dlg_preview_handle_event (GtkWidget *widget,
GdkEvent *event); GdkEvent *event,
GimpProcedureConfig *config);
static void dlg_preview_update (void); static void dlg_preview_update (void);
static gint dlg_preview_init_func (Preview *preview, static gint dlg_preview_init_func (Preview *preview,
gpointer data); gpointer data);
@ -560,13 +547,15 @@ static void dlg_preview_render_func (Preview *preview,
static void dlg_preview_deinit_func (Preview *preview, static void dlg_preview_deinit_func (Preview *preview,
gpointer data); gpointer data);
static void dlg_make_page_settings (GFlareDialog *dlg, static void dlg_make_page_settings (GFlareDialog *dlg,
GtkWidget *notebook); GtkWidget *notebook,
GimpProcedureConfig *config);
static void dlg_position_entry_callback (GtkWidget *widget, static void dlg_position_entry_callback (GtkWidget *widget,
gpointer data); GimpProcedureConfig *config);
static void dlg_update_preview_callback (GtkWidget *widget, static void dlg_update_preview_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void dlg_make_page_selector (GFlareDialog *dlg, static void dlg_make_page_selector (GFlareDialog *dlg,
GtkWidget *notebook); GtkWidget *notebook,
GimpProcedureConfig *config);
static void dlg_selector_setup_listbox (void); static void dlg_selector_setup_listbox (void);
static void dlg_selector_list_item_callback (GtkTreeSelection *selection); static void dlg_selector_list_item_callback (GtkTreeSelection *selection);
@ -620,18 +609,29 @@ static void ed_mode_menu_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void ed_gradient_menu_callback (const gchar *gradient_name, static void ed_gradient_menu_callback (const gchar *gradient_name,
gpointer data); gpointer data);
static void ed_shape_radio_callback (GtkWidget *widget, gpointer data); static void ed_shape_radio_callback (GtkWidget *widget,
static void ed_ientry_callback (GtkWidget *widget, gpointer data); gpointer data);
static void ed_page_map_callback (GtkWidget *widget, gpointer data); static void ed_ientry_callback (GtkWidget *widget,
gpointer data);
static void ed_page_map_callback (GtkWidget *widget,
gpointer data);
static void ed_preview_update (void); static void ed_preview_update (void);
static gint ed_preview_init_func (Preview *preview, gpointer data); static gint ed_preview_init_func (Preview *preview,
static void ed_preview_deinit_func (Preview *preview, gpointer data); gpointer data);
static void ed_preview_deinit_func (Preview *preview,
gpointer data);
static void ed_preview_render_func (Preview *preview, static void ed_preview_render_func (Preview *preview,
guchar *buffer, gint y, gpointer data); guchar *buffer,
static void ed_preview_render_general (guchar *buffer, gint y); gint y,
static void ed_preview_render_glow (guchar *buffer, gint y); gpointer data);
static void ed_preview_render_rays (guchar *buffer, gint y); static void ed_preview_render_general (guchar *buffer,
static void ed_preview_render_sflare (guchar *buffer, gint y); gint y);
static void ed_preview_render_glow (guchar *buffer,
gint y);
static void ed_preview_render_rays (guchar *buffer,
gint y);
static void ed_preview_render_sflare (guchar *buffer,
gint y);
static gint preview_render_start_2 (Preview *preview); static gint preview_render_start_2 (Preview *preview);
static gint preview_handle_idle (Preview *preview); static gint preview_handle_idle (Preview *preview);
@ -647,15 +647,20 @@ static void gm_combo_destroy_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void gradient_get_values_internal (const gchar *gradient_name, static void gradient_get_values_internal (const gchar *gradient_name,
guchar *values, gint nvalues); guchar *values,
gint nvalues);
static void gradient_get_blend (const guchar *fg, static void gradient_get_blend (const guchar *fg,
const guchar *bg, const guchar *bg,
guchar *values, gint nvalues); guchar *values,
static void gradient_get_random (guchar *values, gint nvalues); gint nvalues);
static void gradient_get_random (guchar *values,
gint nvalues);
static void gradient_get_default (const gchar *name, static void gradient_get_default (const gchar *name,
guchar *values, gint nvalues); guchar *values,
gint nvalues);
static void gradient_get_values_external (const gchar *gradient_name, static void gradient_get_values_external (const gchar *gradient_name,
guchar *values, gint nvalues); guchar *values,
gint nvalues);
static void gradient_get_values_real_external (const gchar *gradient_name, static void gradient_get_values_real_external (const gchar *gradient_name,
guchar *values, guchar *values,
gint nvalues, gint nvalues,
@ -675,21 +680,6 @@ GIMP_MAIN (GFLARE_TYPE)
DEFINE_STD_SET_I18N DEFINE_STD_SET_I18N
PluginValues pvals =
{
128, /* xcenter */
128, /* ycenter */
100.0, /* radius */
0.0, /* rotation */
0.0, /* hue */
60.0, /* vangle */
400.0, /* vlength */
FALSE, /* use_asupsample */
3, /* asupsample_max_depth */
0.2, /* asupsample_threshold */
"Default" /* gflare_name */
};
GFlare default_gflare = GFlare default_gflare =
{ {
NULL, /* name */ NULL, /* name */
@ -808,7 +798,7 @@ gflare_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC)) if (! strcmp (name, PLUG_IN_PROC))
{ {
procedure = gimp_image_procedure_new (plug_in, name, procedure = gimp_image_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN, GIMP_PDB_PROC_TYPE_PLUGIN,
gflare_run, NULL, NULL); gflare_run, NULL, NULL);
@ -860,50 +850,50 @@ gflare_create_procedure (GimpPlugIn *plug_in,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "radius", GIMP_PROC_ARG_DOUBLE (procedure, "radius",
"Radius", _("Radi_us"),
"Radius of GFlare (pixel)", "Radius of GFlare (pixel)",
1, GIMP_MAX_IMAGE_SIZE, 100, 1, GIMP_MAX_IMAGE_SIZE, 100,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "rotation", GIMP_PROC_ARG_DOUBLE (procedure, "rotation",
"Rotation", _("Ro_tation"),
"Rotation of GFlare (degree)", "Rotation of GFlare (degree)",
0, 360, 0, 0, 360, 0,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "hue", GIMP_PROC_ARG_DOUBLE (procedure, "hue",
"Hue", _("_Hue rotation"),
"Hue rotation of GFlare (degree)", "_Hue rotation of GFlare (degree)",
0, 360, 0, 0, 360, 0,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "vector-angle", GIMP_PROC_ARG_DOUBLE (procedure, "vector-angle",
"Vector angle", _("Vector _angle"),
"Vector angle for second flares (degree)", "Vector angle for second flares (degree)",
0, 360, 60, 0, 360, 60,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "vector-length", GIMP_PROC_ARG_DOUBLE (procedure, "vector-length",
"Vector length", _("Vector len_gth"),
"Vector length for second flares " "Vector length for second flares "
"(percentage of Radius)", "(percentage of Radius)",
0, 10000, 400, 0, 10000, 400,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_BOOLEAN (procedure, "use-asupsample", GIMP_PROC_ARG_BOOLEAN (procedure, "use-asupsample",
"Use asupsample", _("Ada_ptive supersampling"),
"Use adaptive supersampling while rendering", "Use adaptive supersampling while rendering",
FALSE, FALSE,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_INT (procedure, "asupsample-max-depth", GIMP_PROC_ARG_INT (procedure, "asupsample-max-depth",
"Asupsample max depth", _("_Max depth"),
"Max depth for adaptive supersampling", "Max depth for adaptive supersampling",
0, 10, 3, 0, 10, 3,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DOUBLE (procedure, "asupsample-threshold", GIMP_PROC_ARG_DOUBLE (procedure, "asupsample-threshold",
"Asupsample threshold", _("Threshol_d"),
"Threshold for adaptive supersampling", "Threshold for adaptive supersampling",
0.0, 1.0, 0.2, 0.0, 1.0, 0.2,
G_PARAM_READWRITE); G_PARAM_READWRITE);
@ -918,7 +908,7 @@ gflare_run (GimpProcedure *procedure,
GimpImage *_image, GimpImage *_image,
gint n_drawables, gint n_drawables,
GimpDrawable **drawables, GimpDrawable **drawables,
const GimpValueArray *args, GimpProcedureConfig *config,
gpointer run_data) gpointer run_data)
{ {
gchar *path; gchar *path;
@ -1008,52 +998,20 @@ gflare_run (GimpProcedure *procedure,
gflares_list_load_all (); gflares_list_load_all ();
switch (run_mode) if (run_mode == GIMP_RUN_INTERACTIVE && ! dlg_run (procedure, config))
{
case GIMP_RUN_INTERACTIVE:
gimp_get_data (PLUG_IN_PROC, &pvals);
if (! dlg_run ())
{
return gimp_procedure_new_return_values (procedure, return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL, GIMP_PDB_CANCEL,
NULL); NULL);
}
break;
case GIMP_RUN_NONINTERACTIVE:
gflare_name_copy (pvals.gflare_name,
GIMP_VALUES_GET_STRING (args, 0));
pvals.xcenter = GIMP_VALUES_GET_INT (args, 1);
pvals.ycenter = GIMP_VALUES_GET_INT (args, 2);
pvals.radius = GIMP_VALUES_GET_DOUBLE (args, 3);
pvals.rotation = GIMP_VALUES_GET_DOUBLE (args, 4);
pvals.hue = GIMP_VALUES_GET_DOUBLE (args, 5);
pvals.vangle = GIMP_VALUES_GET_DOUBLE (args, 6);
pvals.vlength = GIMP_VALUES_GET_DOUBLE (args, 7);
pvals.use_asupsample = GIMP_VALUES_GET_BOOLEAN (args, 8);
pvals.asupsample_max_depth = GIMP_VALUES_GET_INT (args, 9);
pvals.asupsample_threshold = GIMP_VALUES_GET_DOUBLE (args, 10);
break;
case GIMP_RUN_WITH_LAST_VALS:
gimp_get_data (PLUG_IN_PROC, &pvals);
break;
}
if (gimp_drawable_is_rgb (drawable) || if (gimp_drawable_is_rgb (drawable) ||
gimp_drawable_is_gray (drawable)) gimp_drawable_is_gray (drawable))
{ {
gimp_progress_init (_("Gradient Flare")); gimp_progress_init (_("Gradient Flare"));
plugin_do (); plugin_do (config);
if (run_mode != GIMP_RUN_NONINTERACTIVE) if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush (); gimp_displays_flush ();
if (run_mode == GIMP_RUN_INTERACTIVE)
gimp_set_data (PLUG_IN_PROC, &pvals, sizeof (PluginValues));
} }
else else
{ {
@ -1075,33 +1033,60 @@ gflare_run (GimpProcedure *procedure,
} }
static void static void
plugin_do (void) plugin_do (GimpProcedureConfig *config)
{ {
GeglBuffer *src_buffer; GeglBuffer *src_buffer;
GeglBuffer *dest_buffer; GeglBuffer *dest_buffer;
GFlare *gflare; GFlare *gflare;
gchar *gflare_name;
gint xcenter;
gint ycenter;
gdouble radius;
gdouble rotation;
gdouble hue;
gdouble vangle;
gdouble vlength;
gboolean use_asupsample;
gint asupsample_max_depth;
gdouble asupsample_threshold;
gflare = gflares_list_lookup (pvals.gflare_name); g_object_get (config,
"gflare-name", &gflare_name,
"center-x", &xcenter,
"center-y", &ycenter,
"radius", &radius,
"rotation", &rotation,
"hue", &hue,
"vector-angle", &vangle,
"vector-length", &vlength,
"use-asupsample", &use_asupsample,
"asupsample-max-depth", &asupsample_max_depth,
"asupsample-threshold", &asupsample_threshold,
NULL);
gflare = gflares_list_lookup (gflare_name);
if (gflare == NULL) if (gflare == NULL)
{ {
/* FIXME */ /* FIXME */
g_warning ("Not found %s\n", pvals.gflare_name); g_warning ("Not found %s\n", gflare_name);
g_free (gflare_name);
return; return;
} }
g_free (gflare_name);
/* Initialize calc params and gradients */ /* Initialize calc params and gradients */
calc_init_params (gflare, CALC_GLOW | CALC_RAYS | CALC_SFLARE, calc_init_params (gflare, CALC_GLOW | CALC_RAYS | CALC_SFLARE,
pvals.xcenter, pvals.ycenter, xcenter, ycenter,
pvals.radius, pvals.rotation, pvals.hue, radius, rotation, hue,
pvals.vangle, pvals.vlength); vangle, vlength);
while (calc_init_progress ()) ; while (calc_init_progress ()) ;
src_buffer = gimp_drawable_get_buffer (drawable); src_buffer = gimp_drawable_get_buffer (drawable);
dest_buffer = gimp_drawable_get_shadow_buffer (drawable); dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
/* Render it ! */ /* Render it ! */
if (pvals.use_asupsample) if (use_asupsample)
plugin_do_asupsample (src_buffer, dest_buffer); plugin_do_asupsample (src_buffer, dest_buffer, asupsample_max_depth, asupsample_threshold);
else else
plugin_do_non_asupsample (src_buffer, dest_buffer); plugin_do_non_asupsample (src_buffer, dest_buffer);
@ -1200,12 +1185,14 @@ plugin_do_non_asupsample (GeglBuffer *src_buffer,
static void static void
plugin_do_asupsample (GeglBuffer *src_buffer, plugin_do_asupsample (GeglBuffer *src_buffer,
GeglBuffer *dest_buffer) GeglBuffer *dest_buffer,
gint asupsample_max_depth,
gdouble asupsample_threshold)
{ {
gimp_adaptive_supersample_area (dinfo.x, dinfo.y, gimp_adaptive_supersample_area (dinfo.x, dinfo.y,
dinfo.x + dinfo.w - 1, dinfo.y + dinfo.h - 1, dinfo.x + dinfo.w - 1, dinfo.y + dinfo.h - 1,
pvals.asupsample_max_depth, asupsample_max_depth,
pvals.asupsample_threshold, asupsample_threshold,
plugin_render_func, plugin_render_func,
src_buffer, src_buffer,
plugin_put_pixel_func, plugin_put_pixel_func,
@ -1666,13 +1653,6 @@ gflare_write_gradient_name (GradientName name,
fprintf (fp, "%s\n", enc); fprintf (fp, "%s\n", enc);
} }
static void
gflare_name_copy (gchar *dest,
const gchar *src)
{
g_strlcpy (dest, src, GFLARE_NAME_MAX);
}
/*************************************************************************/ /*************************************************************************/
/** **/ /** **/
/** +++ GFlares List **/ /** +++ GFlares List **/
@ -1833,8 +1813,8 @@ gflares_list_free_all (void)
static void static void
calc_init_params (GFlare *gflare, calc_init_params (GFlare *gflare,
gint calc_type, gint calc_type,
gdouble xcenter, gint xcenter,
gdouble ycenter, gint ycenter,
gdouble radius, gdouble radius,
gdouble rotation, gdouble rotation,
gdouble hue, gdouble hue,
@ -2478,7 +2458,8 @@ calc_overlay (guchar *dest, guchar *src1, guchar *src2)
*/ */
static gboolean static gboolean
dlg_run (void) dlg_run (GimpProcedure *procedure,
GimpProcedureConfig *config)
{ {
GeglBuffer *src_buffer; GeglBuffer *src_buffer;
GtkWidget *shell; GtkWidget *shell;
@ -2488,6 +2469,7 @@ dlg_run (void)
GtkWidget *button; GtkWidget *button;
GtkWidget *notebook; GtkWidget *notebook;
gboolean run = FALSE; gboolean run = FALSE;
gchar *gflare_name;
gimp_ui_init (PLUG_IN_BINARY); gimp_ui_init (PLUG_IN_BINARY);
@ -2500,7 +2482,9 @@ dlg_run (void)
dlg->update_preview = TRUE; dlg->update_preview = TRUE;
gradient_menu_init (); /* FIXME: this should go elsewhere */ gradient_menu_init (); /* FIXME: this should go elsewhere */
dlg_setup_gflare (); g_object_get (config, "gflare-name", &gflare_name, NULL);
dlg_setup_gflare (gflare_name);
g_free (gflare_name);
g_assert (gflares_list != NULL); g_assert (gflares_list != NULL);
g_assert (dlg->gflare != NULL); g_assert (dlg->gflare != NULL);
@ -2510,19 +2494,9 @@ dlg_run (void)
* Dialog Shell * Dialog Shell
*/ */
shell = dlg->shell = gimp_dialog_new (_("Gradient Flare"), PLUG_IN_ROLE, shell = dlg->shell = gimp_procedure_dialog_new (procedure,
NULL, 0, GIMP_PROCEDURE_CONFIG (config),
gimp_standard_help_func, PLUG_IN_PROC, _("Gradient Flare"));
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_OK"), GTK_RESPONSE_OK,
NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (shell),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
/* /*
* main hbox * main hbox
@ -2551,7 +2525,7 @@ dlg_run (void)
src_buffer = gimp_drawable_get_buffer (drawable); src_buffer = gimp_drawable_get_buffer (drawable);
dlg->preview = preview_new (DLG_PREVIEW_WIDTH, DLG_PREVIEW_HEIGHT, dlg->preview = preview_new (DLG_PREVIEW_WIDTH, DLG_PREVIEW_HEIGHT,
dlg_preview_init_func, NULL, dlg_preview_init_func, config,
dlg_preview_render_func, src_buffer, dlg_preview_render_func, src_buffer,
dlg_preview_deinit_func, NULL); dlg_preview_deinit_func, NULL);
gtk_widget_set_events (GTK_WIDGET (dlg->preview->widget), DLG_PREVIEW_MASK); gtk_widget_set_events (GTK_WIDGET (dlg->preview->widget), DLG_PREVIEW_MASK);
@ -2562,7 +2536,7 @@ dlg_run (void)
NULL); NULL);
g_signal_connect (dlg->preview->widget, "event", g_signal_connect (dlg->preview->widget, "event",
G_CALLBACK (dlg_preview_handle_event), G_CALLBACK (dlg_preview_handle_event),
NULL); config);
dlg_preview_calc_window (); dlg_preview_calc_window ();
@ -2584,8 +2558,8 @@ dlg_run (void)
gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0);
gtk_widget_show (notebook); gtk_widget_show (notebook);
dlg_make_page_settings (dlg, notebook); dlg_make_page_settings (dlg, notebook, config);
dlg_make_page_selector (dlg, notebook); dlg_make_page_selector (dlg, notebook, config);
gtk_widget_show (shell); gtk_widget_show (shell);
@ -2597,7 +2571,9 @@ dlg_run (void)
if (gimp_dialog_run (GIMP_DIALOG (shell)) == GTK_RESPONSE_OK) if (gimp_dialog_run (GIMP_DIALOG (shell)) == GTK_RESPONSE_OK)
{ {
gflare_name_copy (pvals.gflare_name, dlg->gflare->name); g_object_set (config,
"gflare-name", dlg->gflare->name,
NULL);
run = TRUE; run = TRUE;
} }
@ -2610,9 +2586,9 @@ dlg_run (void)
} }
static void static void
dlg_setup_gflare (void) dlg_setup_gflare (const gchar *gflare_name)
{ {
dlg->gflare = gflares_list_lookup (pvals.gflare_name); dlg->gflare = gflares_list_lookup (gflare_name);
if (!dlg->gflare) if (!dlg->gflare)
{ {
@ -2710,10 +2686,19 @@ dlg_preview_realize (GtkWidget *widget)
static gboolean static gboolean
dlg_preview_handle_event (GtkWidget *widget, dlg_preview_handle_event (GtkWidget *widget,
GdkEvent *event) GdkEvent *event,
GimpProcedureConfig *config)
{ {
GdkEventButton *bevent; GdkEventButton *bevent;
gint bx, by, x, y; gint bx, by, x, y;
gint xcenter;
gint ycenter;
gboolean handled = FALSE;
g_object_get (config,
"center-x", &xcenter,
"center-y", &ycenter,
NULL);
switch (event->type) switch (event->type)
{ {
@ -2728,27 +2713,34 @@ dlg_preview_handle_event (GtkWidget *widget,
y = dlg->pwin.y0 + (double) (dlg->pwin.y1 - dlg->pwin.y0) y = dlg->pwin.y0 + (double) (dlg->pwin.y1 - dlg->pwin.y0)
* by / DLG_PREVIEW_HEIGHT; * by / DLG_PREVIEW_HEIGHT;
if ((x != pvals.xcenter || y != pvals.ycenter)) if ((x != xcenter || y != ycenter))
{ {
if (x != pvals.xcenter) if (x != xcenter)
{ {
pvals.xcenter = x; xcenter = x;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dlg->sizeentry), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dlg->sizeentry),
0, x); 0, x);
} }
if (y != pvals.ycenter) if (y != ycenter)
{ {
pvals.ycenter = y; ycenter = y;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dlg->sizeentry), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dlg->sizeentry),
1, y); 1, y);
} }
dlg_preview_update (); dlg_preview_update ();
} }
return TRUE; handled = TRUE;
break;
default: default:
break; break;
} }
return FALSE;
g_object_set (config,
"center-x", xcenter,
"center-y", ycenter,
NULL);
return handled;
} }
static void static void
@ -2763,17 +2755,38 @@ dlg_preview_update (void)
/* preview callbacks */ /* preview callbacks */
static gint static gint
dlg_preview_init_func (Preview *preview, gpointer data) dlg_preview_init_func (Preview *preview,
gpointer data)
{ {
GimpProcedureConfig *config = GIMP_PROCEDURE_CONFIG (data);
/* call init_params first, and iterate init_progress while /* call init_params first, and iterate init_progress while
it returns true */ it returns true */
if (dlg->init_params_done == FALSE) if (dlg->init_params_done == FALSE)
{ {
gint xcenter;
gint ycenter;
gdouble radius;
gdouble rotation;
gdouble hue;
gdouble vangle;
gdouble vlength;
g_object_get (config,
"center-x", &xcenter,
"center-y", &ycenter,
"radius", &radius,
"rotation", &rotation,
"hue", &hue,
"vector-angle", &vangle,
"vector-length", &vlength,
NULL);
calc_init_params (dlg->gflare, calc_init_params (dlg->gflare,
CALC_GLOW | CALC_RAYS | CALC_SFLARE, CALC_GLOW | CALC_RAYS | CALC_SFLARE,
pvals.xcenter, pvals.ycenter, xcenter, ycenter,
pvals.radius, pvals.rotation, pvals.hue, radius, rotation, hue,
pvals.vangle, pvals.vlength); vangle, vlength);
dlg->init_params_done = TRUE; dlg->init_params_done = TRUE;
return TRUE; return TRUE;
} }
@ -2859,26 +2872,22 @@ dlg_preview_deinit_func (Preview *preview, gpointer data)
static void static void
dlg_make_page_settings (GFlareDialog *dlg, dlg_make_page_settings (GFlareDialog *dlg,
GtkWidget *notebook) GtkWidget *notebook,
GimpProcedureConfig *config)
{ {
GtkWidget *main_vbox; GtkWidget *main_vbox;
GtkWidget *frame; GtkWidget *frame;
GtkWidget *center; GtkWidget *center;
GtkWidget *chain; GtkWidget *chain;
GtkWidget *grid;
GtkWidget *button;
GtkWidget *asup_grid;
GtkWidget *scale; GtkWidget *scale;
gdouble xres, yres; gdouble xres, yres;
gint row; gint xcenter;
gint ycenter;
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
frame = gimp_frame_new (_("Center"));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
g_object_get (config,
"center-x", &xcenter,
"center-y", &ycenter,
NULL);
gimp_image_get_resolution (image, &xres, &yres); gimp_image_get_resolution (image, &xres, &yres);
center = dlg->sizeentry = center = dlg->sizeentry =
@ -2887,146 +2896,92 @@ dlg_make_page_settings (GFlareDialog *dlg,
FALSE, FALSE, FALSE, FALSE,
_("_X:"), pvals.xcenter, xres, _("_X:"), xcenter, xres,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0, gimp_drawable_get_width (drawable), 0, gimp_drawable_get_width (drawable),
_("_Y:"), pvals.ycenter, yres, _("_Y:"), ycenter, yres,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0, gimp_drawable_get_height (drawable)); 0, gimp_drawable_get_height (drawable));
chain = GTK_WIDGET (GIMP_COORDINATES_CHAINBUTTON (center)); chain = GTK_WIDGET (GIMP_COORDINATES_CHAINBUTTON (center));
gtk_container_add (GTK_CONTAINER (frame), center);
g_signal_connect (center, "value-changed", g_signal_connect (center, "value-changed",
G_CALLBACK (dlg_position_entry_callback), G_CALLBACK (dlg_position_entry_callback),
NULL); config);
g_signal_connect (center, "refval-changed", g_signal_connect (center, "refval-changed",
G_CALLBACK (dlg_position_entry_callback), G_CALLBACK (dlg_position_entry_callback),
NULL); config);
gtk_widget_hide (chain); gtk_widget_hide (chain);
gtk_widget_show (center); gtk_widget_show (center);
frame = gimp_frame_new (_("Parameters")); gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dlg->shell),
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); "center-title", _("Center"));
gtk_widget_show (frame); frame = gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dlg->shell),
"center-frame", "center-title",
FALSE, NULL);
gtk_container_add (GTK_CONTAINER (frame), center);
grid = gtk_grid_new (); scale = gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell), "radius", 1.0);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 1.0,
gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gimp_drawable_get_width (drawable) / 2);
gtk_container_add (GTK_CONTAINER (frame), grid);
gtk_widget_show (grid);
row = 0; gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell), "rotation", 1.0);
gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell), "hue", 1.0);
gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell), "vector-angle", 1.0);
scale = gimp_scale_entry_new (_("_Radius:"), pvals.radius, 0.0, GIMP_MAX_IMAGE_SIZE, 1); scale = gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell), "vector-length", 1.0);
gimp_scale_entry_set_bounds (GIMP_SCALE_ENTRY (scale), 0.0, gimp_drawable_get_width (drawable) / 2, TRUE); gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 1.0, 1000);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double), gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dlg->shell),
&pvals.radius); "parameters-box",
g_signal_connect (scale, "value-changed", "radius", "rotation", "hue",
"vector-angle", "vector-length",
NULL);
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dlg->shell),
"parameters-title", _("Parameters"));
gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dlg->shell),
"parameters-frame", "parameters-title",
FALSE, "parameters-box");
g_signal_connect (config, "notify",
G_CALLBACK (dlg_preview_update), G_CALLBACK (dlg_preview_update),
NULL); NULL);
gtk_grid_attach (GTK_GRID (grid), scale, 0, row++, 3, 1);
gtk_widget_show (scale);
scale = gimp_scale_entry_new (_("Ro_tation:"), pvals.rotation, -180.0, 180.0, 1);
gimp_label_spin_set_increments (GIMP_LABEL_SPIN (scale), 1.0, 15.0);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double),
&pvals.rotation);
g_signal_connect (scale, "value-changed",
G_CALLBACK (dlg_preview_update),
NULL);
gtk_grid_attach (GTK_GRID (grid), scale, 0, row++, 3, 1);
gtk_widget_show (scale);
scale = gimp_scale_entry_new (_("_Hue rotation:"), pvals.hue, -180.0, 180.0, 1);
gimp_label_spin_set_increments (GIMP_LABEL_SPIN (scale), 1.0, 15.0);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double),
&pvals.hue);
g_signal_connect (scale, "value-changed",
G_CALLBACK (dlg_preview_update),
NULL);
gtk_grid_attach (GTK_GRID (grid), scale, 0, row++, 3, 1);
gtk_widget_show (scale);
scale = gimp_scale_entry_new (_("Vector _angle:"), pvals.vangle, 0.0, 359.0, 1);
gimp_label_spin_set_increments (GIMP_LABEL_SPIN (scale), 1.0, 15.0);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double),
&pvals.vangle);
g_signal_connect (scale, "value-changed",
G_CALLBACK (dlg_preview_update),
NULL);
gtk_grid_attach (GTK_GRID (grid), scale, 0, row++, 3, 1);
gtk_widget_show (scale);
scale = gimp_scale_entry_new (_("Vector _length:"), pvals.vlength, 1, GIMP_MAX_IMAGE_SIZE, 1);
gimp_scale_entry_set_bounds (GIMP_SCALE_ENTRY (scale), 1, 1000, TRUE);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double),
&pvals.vlength);
g_signal_connect (scale, "value-changed",
G_CALLBACK (dlg_preview_update),
NULL);
gtk_grid_attach (GTK_GRID (grid), scale, 0, row++, 3, 1);
gtk_widget_show (scale);
/** /**
*** Asupsample settings *** Asupsample settings
*** This code is stolen from gimp-0.99.x/app/blend.c *** This code is stolen from gimp-0.99.x/app/blend.c
**/ **/
/* asupsample frame */ gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell),
frame = dlg->asupsample_frame = gimp_frame_new (NULL); "asupsample-max-depth", 1.0);
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
button = gtk_check_button_new_with_mnemonic (_("A_daptive supersampling")); gimp_procedure_dialog_get_spin_scale (GIMP_PROCEDURE_DIALOG (dlg->shell),
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), "asupsample-threshold", 1.0);
pvals.use_asupsample);
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
asup_grid = gtk_grid_new (); gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dlg->shell),
gtk_grid_set_column_spacing (GTK_GRID (asup_grid), 6); "asupsample-box",
gtk_grid_set_row_spacing (GTK_GRID (asup_grid), 6); "asupsample-max-depth", "asupsample-threshold",
gtk_container_add (GTK_CONTAINER (frame), asup_grid); NULL);
gtk_widget_show (asup_grid); gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dlg->shell),
"asupsample-frame", "use-asupsample",
g_signal_connect (button, "toggled", FALSE, "asupsample-box");
G_CALLBACK (gimp_toggle_button_update),
&pvals.use_asupsample);
g_object_bind_property (button, "active",
asup_grid, "sensitive",
G_BINDING_SYNC_CREATE);
scale = gimp_scale_entry_new (_("_Max depth:"), pvals.asupsample_max_depth, 1.0, 10.0, 0);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_int),
&pvals.asupsample_max_depth);
gtk_grid_attach (GTK_GRID (asup_grid), scale, 0, 0, 3, 1);
gtk_widget_show (scale);
scale = gimp_scale_entry_new (_("_Threshold"), pvals.asupsample_threshold, 0.0, 4.0, 2);
gimp_label_spin_set_increments (GIMP_LABEL_SPIN (scale), 0.01, 0.1);
g_signal_connect (scale, "value-changed",
G_CALLBACK (gradient_scale_entry_update_double),
&pvals.asupsample_threshold);
gtk_grid_attach (GTK_GRID (asup_grid), scale, 0, 1, 3, 1);
gtk_widget_show (scale);
main_vbox = gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dlg->shell),
"settings-page",
"center-frame", "parameters-frame", "asupsample-frame",
NULL);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), main_vbox, gtk_notebook_append_page (GTK_NOTEBOOK (notebook), main_vbox,
gtk_label_new_with_mnemonic (_("_Settings"))); gtk_label_new_with_mnemonic (_("_Settings")));
gtk_widget_show (main_vbox); gtk_widget_show (main_vbox);
} }
static void static void
dlg_position_entry_callback (GtkWidget *widget, gpointer data) dlg_position_entry_callback (GtkWidget *widget,
GimpProcedureConfig *config)
{ {
gint xcenter;
gint ycenter;
gint x, y; gint x, y;
x = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0)); x = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0));
@ -3034,11 +2989,17 @@ dlg_position_entry_callback (GtkWidget *widget, gpointer data)
DEBUG_PRINT (("dlg_position_entry_callback\n")); DEBUG_PRINT (("dlg_position_entry_callback\n"));
if (pvals.xcenter != x || g_object_get (config,
pvals.ycenter != y) "center-x", &xcenter,
"center-y", &ycenter,
NULL);
if (xcenter != x || ycenter != y)
{ {
pvals.xcenter = x; g_object_set (config,
pvals.ycenter = y; "center-x", x,
"center-y", y,
NULL);
dlg_preview_update (); dlg_preview_update ();
} }
@ -3059,7 +3020,8 @@ dlg_update_preview_callback (GtkWidget *widget,
static void static void
dlg_make_page_selector (GFlareDialog *dlg, dlg_make_page_selector (GFlareDialog *dlg,
GtkWidget *notebook) GtkWidget *notebook,
GimpProcedureConfig *config)
{ {
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *hbox; GtkWidget *hbox;
@ -3142,7 +3104,7 @@ dlg_make_page_selector (GFlareDialog *dlg,
g_signal_connect (button, "clicked", g_signal_connect (button, "clicked",
buttons[i].callback, buttons[i].callback,
button); config);
} }
gtk_widget_show (vbox); gtk_widget_show (vbox);
@ -3265,7 +3227,7 @@ dlg_selector_edit_callback (GtkWidget *widget,
preview_render_end (dlg->preview); preview_render_end (dlg->preview);
gtk_widget_set_sensitive (dlg->shell, FALSE); gtk_widget_set_sensitive (dlg->shell, FALSE);
ed_run (GTK_WINDOW (dlg->shell), ed_run (GTK_WINDOW (dlg->shell),
dlg->gflare, dlg_selector_edit_done_callback, NULL); dlg->gflare, dlg_selector_edit_done_callback, data);
} }
static void static void
@ -3458,6 +3420,8 @@ ed_run (GtkWindow *parent,
GtkWidget *frame; GtkWidget *frame;
GtkWidget *notebook; GtkWidget *notebook;
g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (calldata));
if (!ed) if (!ed)
ed = g_new0 (GFlareEditor, 1); ed = g_new0 (GFlareEditor, 1);
ed->init = TRUE; ed->init = TRUE;
@ -3515,14 +3479,14 @@ ed_run (GtkWindow *parent,
gtk_widget_show (frame); gtk_widget_show (frame);
ed->preview = preview_new (ED_PREVIEW_WIDTH, ED_PREVIEW_HEIGHT, ed->preview = preview_new (ED_PREVIEW_WIDTH, ED_PREVIEW_HEIGHT,
ed_preview_init_func, NULL, ed_preview_init_func, calldata,
ed_preview_render_func, NULL, ed_preview_render_func, NULL,
ed_preview_deinit_func, NULL); ed_preview_deinit_func, NULL);
gtk_widget_set_events (GTK_WIDGET (ed->preview->widget), DLG_PREVIEW_MASK); gtk_widget_set_events (GTK_WIDGET (ed->preview->widget), DLG_PREVIEW_MASK);
gtk_container_add (GTK_CONTAINER (frame), ed->preview->widget); gtk_container_add (GTK_CONTAINER (frame), ed->preview->widget);
g_signal_connect (ed->preview->widget, "event", g_signal_connect (ed->preview->widget, "event",
G_CALLBACK (dlg_preview_handle_event), G_CALLBACK (dlg_preview_handle_event),
NULL); calldata);
ed_preview_calc_window (); ed_preview_calc_window ();
/* /*
@ -4196,10 +4160,18 @@ ed_preview_update (void)
static gint static gint
ed_preview_init_func (Preview *preview, gpointer data) ed_preview_init_func (Preview *preview, gpointer data)
{ {
GimpProcedureConfig *config = GIMP_PROCEDURE_CONFIG (data);
int type = 0; int type = 0;
if (ed->init_params_done == FALSE) if (ed->init_params_done == FALSE)
{ {
gdouble vangle;
gdouble vlength;
g_object_get (config,
"vector-angle", &vangle,
"vector-length", &vlength,
NULL);
switch (ed->cur_page) switch (ed->cur_page)
{ {
case PAGE_GENERAL: case PAGE_GENERAL:
@ -4221,7 +4193,7 @@ ed_preview_init_func (Preview *preview, gpointer data)
calc_init_params (ed->gflare, type, calc_init_params (ed->gflare, type,
ED_PREVIEW_WIDTH/2, ED_PREVIEW_HEIGHT/2, ED_PREVIEW_WIDTH/2, ED_PREVIEW_HEIGHT/2,
ED_PREVIEW_WIDTH/2, 0.0, 0.0, ED_PREVIEW_WIDTH/2, 0.0, 0.0,
pvals.vangle, pvals.vlength); vangle, vlength);
ed->init_params_done = TRUE; ed->init_params_done = TRUE;
return TRUE; return TRUE;