plugin ui changes

--Sven
This commit is contained in:
Sven Neumann
2000-01-25 23:11:20 +00:00
parent 4923047146
commit 38ed843bb7
3 changed files with 153 additions and 128 deletions

View File

@ -1,3 +1,9 @@
Wed Jan 26 00:10:34 CET 2000 Sven Neumann <sven@gimp.org>
* plug-ins/common/colorify.c: use a gimp_color_button
* plug-ins/common/spread.c: use gimp_size_entries
2000-01-25 Michael Natterer <mitch@gimp.org> 2000-01-25 Michael Natterer <mitch@gimp.org>
* app/appenv.h: removed BOUNDS, MINIMUM and MAXIMUM. No need to * app/appenv.h: removed BOUNDS, MINIMUM and MAXIMUM. No need to

View File

@ -41,9 +41,11 @@
#include "libgimp/stdplugins-intl.h" #include "libgimp/stdplugins-intl.h"
#define PLUG_IN_NAME "plug_in_colorify" #define PLUG_IN_NAME "plug_in_colorify"
#define PLUG_IN_VERSION "1.1" #define PLUG_IN_VERSION "1.1"
#define COLOR_SIZE 30
static void query (void); static void query (void);
static void run (gchar *name, static void run (gchar *name,
gint nparams, gint nparams,
@ -61,12 +63,8 @@ static gint colorify_dialog (guchar red,
guchar blue); guchar blue);
static void colorify_ok_callback (GtkWidget *widget, static void colorify_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void custom_color_callback (GtkWidget *widget,
gpointer data);
static void predefined_color_callback (GtkWidget *widget, static void predefined_color_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void color_changed (GtkWidget *widget,
gpointer data);
static void set_preview_color (GtkWidget *preview, static void set_preview_color (GtkWidget *preview,
guchar red, guchar red,
guchar green, guchar green,
@ -87,9 +85,7 @@ typedef struct
guchar red; guchar red;
guchar green; guchar green;
guchar blue; guchar blue;
GtkWidget *preview; } ButtonColor;
gint button_num;
} ButtonInformation;
static ColorifyInterface cint = static ColorifyInterface cint =
{ {
@ -101,17 +97,19 @@ static ColorifyVals cvals =
{ 255, 255, 255 } { 255, 255, 255 }
}; };
static ButtonInformation button_info[] = static ButtonColor button_color[] =
{ {
{ 255, 0, 0, NULL, 0 }, { 255, 0, 0 },
{ 255, 255, 0, NULL, 0 }, { 255, 255, 0 },
{ 0, 255, 0, NULL, 0 }, { 0, 255, 0 },
{ 0, 255, 255, NULL, 0 }, { 0, 255, 255 },
{ 0, 0, 255, NULL, 0 }, { 0, 0, 255 },
{ 255, 0, 255, NULL, 0 }, { 255, 0, 255 },
{ 255, 255, 255, NULL, 0 }, { 255, 255, 255 },
}; };
GtkWidget *custum_color_button = NULL;
GPlugInInfo PLUG_IN_INFO = GPlugInInfo PLUG_IN_INFO =
{ {
NULL, NULL,
@ -319,7 +317,6 @@ colorify_dialog (guchar red,
gchar **argv; gchar **argv;
gint argc; gint argc;
gint i; gint i;
GSList *group = NULL;
argc = 1; argc = 1;
argv = g_new (gchar *, 1); argv = g_new (gchar *, 1);
@ -362,40 +359,27 @@ colorify_dialog (guchar red,
GTK_FILL, GTK_FILL, 0, 0); GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label); gtk_widget_show (label);
button = gtk_radio_button_new (group); custum_color_button = gimp_color_button_new (_("Colorify Custom Color"),
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE); COLOR_SIZE, COLOR_SIZE,
gtk_widget_set_usize (button, 35, 35); cvals.color, 3);
gtk_signal_connect (GTK_OBJECT (button), "button_press_event", gtk_table_attach (GTK_TABLE (table), custum_color_button, 6, 7, 0, 1,
(GtkSignalFunc) custom_color_callback,
NULL);
gtk_table_attach (GTK_TABLE (table), button, 6, 7, 0, 1,
GTK_FILL, GTK_FILL, 0, 0); GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (button); gtk_widget_show (custum_color_button);
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview), 30, 30);
set_preview_color (preview, cvals.color[0], cvals.color[1], cvals.color[2]);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
{ {
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); button = gtk_button_new ();
button = gtk_radio_button_new (group); preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE); gtk_preview_size (GTK_PREVIEW (preview), COLOR_SIZE, COLOR_SIZE);
button_info[i].preview = gtk_preview_new (GTK_PREVIEW_COLOR); gtk_container_add (GTK_CONTAINER (button), preview);
gtk_preview_size (GTK_PREVIEW (button_info[i].preview), set_preview_color (preview,
30, 30); button_color[i].red,
gtk_container_add (GTK_CONTAINER (button), button_info[i].preview); button_color[i].green,
set_preview_color (button_info[i].preview, button_color[i].blue);
button_info[i].red,
button_info[i].green,
button_info[i].blue);
button_info[i].button_num = i;
gtk_signal_connect (GTK_OBJECT (button), "clicked", gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) predefined_color_callback, (GtkSignalFunc) predefined_color_callback,
&button_info[i].button_num); &button_color[i]);
gtk_widget_show (button_info[i].preview); gtk_widget_show (preview);
gtk_table_attach (GTK_TABLE (table), button, i, i + 1, 1, 2, gtk_table_attach (GTK_TABLE (table), button, i, i + 1, 1, 2,
GTK_FILL, GTK_FILL, 0, 0); GTK_FILL, GTK_FILL, 0, 0);
@ -426,77 +410,35 @@ set_preview_color (GtkWidget *preview,
guchar blue) guchar blue)
{ {
gint i; gint i;
guchar buf[3 * 30]; guchar buf[3 * COLOR_SIZE];
for (i = 0; i < 30; i ++) for (i = 0; i < COLOR_SIZE; i ++)
{ {
buf [3 * i] = red; buf [3 * i] = red;
buf [3 * i + 1] = green; buf [3 * i + 1] = green;
buf [3 * i + 2] = blue; buf [3 * i + 2] = blue;
} }
for (i = 0; i < 30; i ++) for (i = 0; i < COLOR_SIZE; i ++)
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 30); gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, COLOR_SIZE);
gtk_widget_draw (preview, NULL); gtk_widget_draw (preview, NULL);
} }
static void
custom_color_callback (GtkWidget *widget,
gpointer data)
{
GtkColorSelectionDialog *csd;
gdouble colour[3];
c_dialog = gtk_color_selection_dialog_new (_("Colorify Custom Color"));
csd = GTK_COLOR_SELECTION_DIALOG (c_dialog);
gtk_color_selection_set_update_policy (GTK_COLOR_SELECTION(csd->colorsel),
GTK_UPDATE_DISCONTINUOUS);
gtk_widget_destroy (csd->help_button);
gtk_widget_destroy (csd->cancel_button);
gtk_signal_connect (GTK_OBJECT (csd->ok_button), "clicked",
(GtkSignalFunc) color_changed,
NULL);
colour[0] = cvals.color[0] / 255.0;
colour[1] = cvals.color[1] / 255.0;
colour[2] = cvals.color[2] / 255.0;
gtk_color_selection_set_color (GTK_COLOR_SELECTION (csd->colorsel),
colour);
gtk_window_set_position (GTK_WINDOW (c_dialog), GTK_WIN_POS_MOUSE);
gtk_widget_show (c_dialog);
}
static void static void
predefined_color_callback (GtkWidget *widget, predefined_color_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
gint *num; ButtonColor *color;
num = (gint *) data; color = (ButtonColor *) data;
cvals.color[0] = button_info[*num].red; cvals.color[0] = color->red;
cvals.color[1] = button_info[*num].green; cvals.color[1] = color->green;
cvals.color[2] = button_info[*num].blue; cvals.color[2] = color->blue;
gimp_color_button_update (GIMP_COLOR_BUTTON (custum_color_button));
} }
static void
color_changed (GtkWidget *widget,
gpointer data)
{
gdouble color[3];
gtk_color_selection_get_color (GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (c_dialog)->colorsel),
color);
cvals.color[0] = (guchar) (color[0] * 255.0);
cvals.color[1] = (guchar) (color[1] * 255.0);
cvals.color[2] = (guchar) (color[2] * 255.0);
set_preview_color (preview, cvals.color[0], cvals.color[1], cvals.color[2]);
gtk_widget_destroy (c_dialog);
}

View File

@ -62,9 +62,11 @@ static void run (gchar *name,
static void spread (GDrawable * drawable); static void spread (GDrawable * drawable);
static gint spread_dialog (void); static gint spread_dialog (gint32 image_ID);
static void spread_ok_callback (GtkWidget *widget, static void spread_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void spread_entry_callback (GtkWidget *widget,
gpointer data);
static GTile * spread_pixel (GDrawable *drawable, static GTile * spread_pixel (GDrawable *drawable,
GTile *tile, GTile *tile,
@ -142,13 +144,15 @@ run (gchar *name,
GParam **return_vals) GParam **return_vals)
{ {
static GParam values[1]; static GParam values[1];
gint32 image_ID;
GDrawable *drawable; GDrawable *drawable;
GRunModeType run_mode; GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS; GStatusType status = STATUS_SUCCESS;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
/* Get the specified drawable */ /* Get the specified image and drawable */
image_ID = param[1].data.d_image;
drawable = gimp_drawable_get (param[2].data.d_drawable); drawable = gimp_drawable_get (param[2].data.d_drawable);
*nreturn_vals = 1; *nreturn_vals = 1;
@ -165,7 +169,7 @@ run (gchar *name,
gimp_get_data ("plug_in_spread", &spvals); gimp_get_data ("plug_in_spread", &spvals);
/* First acquire information with a dialog */ /* First acquire information with a dialog */
if (! spread_dialog ()) if (! spread_dialog (image_ID))
return; return;
break; break;
@ -349,12 +353,17 @@ spread (GDrawable *drawable)
static gint static gint
spread_dialog (void) spread_dialog (gint32 image_ID)
{ {
GtkWidget *dlg; GtkWidget *dlg;
GtkWidget *frame; GtkWidget *frame;
GtkWidget *table;
GtkObject *adj; GtkObject *adj;
GtkWidget *spinbutton;
GtkWidget *size;
GtkWidget *chain;
GUnit unit;
gdouble xres;
gdouble yres;
gchar **argv; gchar **argv;
gint argc; gint argc;
@ -382,37 +391,62 @@ spread_dialog (void)
NULL); NULL);
/* parameter settings */ /* parameter settings */
frame = gtk_frame_new (_("Parameter Settings")); frame = gtk_frame_new (_("Spread Amount"));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_container_set_border_width (GTK_CONTAINER (frame), 6); gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0);
table = gtk_table_new (2, 3, FALSE); /* Get the image resolution and unit */
gtk_table_set_col_spacings (GTK_TABLE (table), 4); gimp_image_get_resolution (image_ID, &xres, &yres);
gtk_table_set_row_spacings (GTK_TABLE (table), 2); unit = gimp_image_get_unit (image_ID);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table);
/* Horizontal Amount */ /* two sizeentries */
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, adj = gtk_adjustment_new (1, 0, 1, 1, 10, 1);
_("Horizontal Spread Amount:"), SCALE_WIDTH, 0, spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 2);
spvals.spread_amount_x, 0, 200, 1, 10, 2, gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton),
NULL, NULL); GTK_SHADOW_NONE);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed", gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
GTK_SIGNAL_FUNC (gimp_double_adjustment_update), gtk_widget_set_usize (spinbutton, 75, 0);
&spvals.spread_amount_x);
/* Vertical Amount */ size = gimp_size_entry_new (1, unit, "%a", TRUE, FALSE, FALSE, 75,
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, GIMP_SIZE_ENTRY_UPDATE_SIZE);
_("Vertical Spread Amount:"), SCALE_WIDTH, 0, gtk_table_set_col_spacing (GTK_TABLE (size), 0, 4);
spvals.spread_amount_y, 0, 200, 1, 10, 2, gimp_size_entry_add_field (GIMP_SIZE_ENTRY (size), GTK_SPIN_BUTTON (spinbutton), NULL);
NULL, NULL); gtk_table_attach_defaults (GTK_TABLE (size), spinbutton, 1, 2, 0, 1);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (gimp_double_adjustment_update),
&spvals.spread_amount_y);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size), UNIT_PIXEL);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size), 0, xres, TRUE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size), 1, yres, TRUE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size), 0, 0.0, 200.0);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size), 1, 0.0, 200.0);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size), 0, spvals.spread_amount_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size), 1, spvals.spread_amount_y);
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (size), _("Horizontal:"), 0, 0, 1.0);
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (size), _("Vertical:"), 1, 0, 1.0);
/* put a chain_button to the right */
chain = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
if ( spvals.spread_amount_x == spvals.spread_amount_y)
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain), TRUE);
gtk_table_attach_defaults (GTK_TABLE (size), chain, 2, 3, 0, 2);
gtk_widget_show (chain);
gtk_signal_connect (GTK_OBJECT (size), "value_changed",
(GtkSignalFunc) spread_entry_callback, chain);
gtk_signal_connect (GTK_OBJECT (size), "unit_changed",
(GtkSignalFunc) spread_entry_callback, chain);
gtk_container_set_border_width (GTK_CONTAINER (size), 4);
gtk_container_add (GTK_CONTAINER (frame), size);
gtk_object_set_data (GTK_OBJECT (dlg), "size", size);
gtk_widget_show (spinbutton);
gtk_widget_show (size);
gtk_widget_show (frame); gtk_widget_show (frame);
gtk_widget_show (table);
gtk_widget_show (dlg); gtk_widget_show (dlg);
@ -468,7 +502,50 @@ static void
spread_ok_callback (GtkWidget *widget, spread_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
GtkWidget *size;
pint.run = TRUE; pint.run = TRUE;
size = gtk_object_get_data (GTK_OBJECT (data), "size");
if (size)
{
spvals.spread_amount_x = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (size), 0);
spvals.spread_amount_y = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (size), 1);
}
gtk_widget_destroy (GTK_WIDGET (data)); gtk_widget_destroy (GTK_WIDGET (data));
} }
static void
spread_entry_callback (GtkWidget *widget,
gpointer data)
{
static gdouble x = -1.0;
static gdouble y = -1.0;
gdouble new_x;
gdouble new_y;
new_x = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
new_y = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);
if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (data)))
{
if (new_x != x)
{
y = new_y = x = new_x;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1, y);
}
if (new_y != y)
{
x = new_x = y = new_y;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0, x);
}
}
else
{
if (new_x != x)
x = new_x;
if (new_y != y)
y = new_y;
}
}