app/gimpunit.c libgimp/gimpunit.[ch] libgimp/gimpunitmenu.c enabled

1999-04-06  Michael Natterer  <mitschel@cs.tu-berlin.de>

	* app/gimpunit.c
	* libgimp/gimpunit.[ch]
	* libgimp/gimpunitmenu.c
	* libgimp/gimpsizeentry.[ch]: enabled "percent" pseudo-unit.
	New function gimp_size_entry_set_size() to set the values which
	will be treated as 0% and 100%.

	* app/crop.c
	* app/rotate_tool.c
	* app/scale_tool.c: enable "percent".

	* app/rect_select.c fixed size selections can be made in units and
	percent now, table layout, label adjustment.
This commit is contained in:
Michael Natterer 1999-04-06 12:13:54 +00:00 committed by Michael Natterer
parent 67dbf49bf2
commit 16e7aadaf3
26 changed files with 1287 additions and 443 deletions

View File

@ -1,7 +1,23 @@
1999-04-06 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/gimpunit.c
* libgimp/gimpunit.[ch]
* libgimp/gimpunitmenu.c
* libgimp/gimpsizeentry.[ch]: enabled "percent" pseudo-unit.
New function gimp_size_entry_set_size() to set the values which
will be treated as 0% and 100%.
* app/crop.c
* app/rotate_tool.c
* app/scale_tool.c: enable "percent".
* app/rect_select.c fixed size selections can be made in units and
percent now, table layout, label adjustment.
Mon Apr 5 23:24:30 BST 1999 Andy Thomas <alt@gimp.org>
Changed:-
* app/bezier_select.c
* app/bezier_selectP.h
* app/paths_cmds.c

View File

@ -65,6 +65,13 @@ static GimpUnitDef gimp_unit_defs[UNIT_END] =
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
static GSList* user_units = NULL;
static gint number_of_user_units = 0;
@ -176,12 +183,16 @@ gchar *
gimp_unit_get_identifier (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].identifier );
if (unit < UNIT_END)
return gimp_unit_defs[unit].identifier;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.identifier;
return gimp_unit_get_user_unit (unit)->identifier;
}
@ -190,12 +201,16 @@ gchar *
gimp_unit_get_symbol (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].symbol );
if (unit < UNIT_END)
return gimp_unit_defs[unit].symbol;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.symbol;
return gimp_unit_get_user_unit (unit)->symbol;
}
@ -204,12 +219,16 @@ gchar *
gimp_unit_get_abbreviation (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].abbreviation );
if (unit < UNIT_END)
return gimp_unit_defs[unit].abbreviation;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.abbreviation;
return gimp_unit_get_user_unit (unit)->abbreviation;
}
@ -218,12 +237,16 @@ gchar *
gimp_unit_get_singular (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gettext(gimp_unit_defs[UNIT_INCH].singular) );
if (unit < UNIT_END)
return gettext (gimp_unit_defs[unit].singular);
if (unit == UNIT_PERCENT)
return gettext (gimp_unit_percent.singular);
return gimp_unit_get_user_unit (unit)->singular;
}
@ -232,12 +255,16 @@ gchar *
gimp_unit_get_plural (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gettext(gimp_unit_defs[UNIT_INCH].plural) );
if (unit < UNIT_END)
return gettext (gimp_unit_defs[unit].plural);
if (unit == UNIT_PERCENT)
return gettext (gimp_unit_percent.plural);
return gimp_unit_get_user_unit (unit)->plural;
}

View File

@ -67,10 +67,13 @@ struct _crop
/* speed of key movement */
#define ARROW_VELOCITY 25
static InfoDialog * crop_info = NULL;
static InfoDialog *crop_info = NULL;
static gfloat orig_vals[2];
static gfloat size_vals[2];
static GtkWidget *origin_sizeentry;
static GtkWidget *size_sizeentry;
/* crop action functions */
static void crop_button_press (Tool *, GdkEventButton *, gpointer);
static void crop_button_release (Tool *, GdkEventButton *, gpointer);
@ -788,18 +791,40 @@ crop_start (Tool *tool,
gdisp = (GDisplay *) tool->gdisp_ptr;
crop_recalc (tool, crop);
/* if the crop information dialog already exists, delete it */
if (crop_info && (gdisp != old_gdisp))
{
info_dialog_popdown (crop_info);
info_dialog_free (crop_info);
crop_info = NULL;
}
old_gdisp = gdisp;
if (! crop_info)
crop_info_create (tool);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
if (old_gdisp != gdisp)
{
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (origin_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
}
old_gdisp = gdisp;
/* initialize the statusbar display */
crop->context_id =
gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar), "crop");
@ -825,8 +850,7 @@ static void
crop_info_create (Tool *tool)
{
GDisplay *gdisp;
GtkWidget *sizeentry;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) tool->gdisp_ptr;
@ -834,51 +858,61 @@ crop_info_create (Tool *tool)
crop_info = info_dialog_new (_("Crop Information"));
/* add the information fields */
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
origin_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Y:"), orig_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_orig_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (origin_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, orig_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
orig_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, orig_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
orig_vals[1]);
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
size_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Height:"), size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (size_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, size_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 0, size_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, size_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 1, size_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 0, 0);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 1, 6);

View File

@ -65,6 +65,13 @@ static GimpUnitDef gimp_unit_defs[UNIT_END] =
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
static GSList* user_units = NULL;
static gint number_of_user_units = 0;
@ -176,12 +183,16 @@ gchar *
gimp_unit_get_identifier (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].identifier );
if (unit < UNIT_END)
return gimp_unit_defs[unit].identifier;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.identifier;
return gimp_unit_get_user_unit (unit)->identifier;
}
@ -190,12 +201,16 @@ gchar *
gimp_unit_get_symbol (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].symbol );
if (unit < UNIT_END)
return gimp_unit_defs[unit].symbol;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.symbol;
return gimp_unit_get_user_unit (unit)->symbol;
}
@ -204,12 +219,16 @@ gchar *
gimp_unit_get_abbreviation (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gimp_unit_defs[UNIT_INCH].abbreviation );
if (unit < UNIT_END)
return gimp_unit_defs[unit].abbreviation;
if (unit == UNIT_PERCENT)
return gimp_unit_percent.abbreviation;
return gimp_unit_get_user_unit (unit)->abbreviation;
}
@ -218,12 +237,16 @@ gchar *
gimp_unit_get_singular (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gettext(gimp_unit_defs[UNIT_INCH].singular) );
if (unit < UNIT_END)
return gettext (gimp_unit_defs[unit].singular);
if (unit == UNIT_PERCENT)
return gettext (gimp_unit_percent.singular);
return gimp_unit_get_user_unit (unit)->singular;
}
@ -232,12 +255,16 @@ gchar *
gimp_unit_get_plural (GUnit unit)
{
g_return_val_if_fail ( (unit >= UNIT_PIXEL) &&
(unit < (UNIT_END + number_of_user_units)),
(unit < (UNIT_END + number_of_user_units)) ||
(unit == UNIT_PERCENT),
gettext(gimp_unit_defs[UNIT_INCH].plural) );
if (unit < UNIT_END)
return gettext (gimp_unit_defs[unit].plural);
if (unit == UNIT_PERCENT)
return gettext (gimp_unit_percent.plural);
return gimp_unit_get_user_unit (unit)->plural;
}

View File

@ -26,6 +26,7 @@
#include "config.h"
#include "libgimp/gimpintl.h"
#include "libgimp/gimpunitmenu.h"
#define NO 0
#define YES 1
@ -60,13 +61,36 @@ selection_toggle_update (GtkWidget *w,
}
static void
selection_spinbutton_update (GtkWidget *widget,
selection_adjustment_update (GtkWidget *widget,
gpointer data)
{
int *val;
val = data;
*val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
val = (int *) data;
*val = GTK_ADJUSTMENT (widget)->value;
}
static void
selection_unitmenu_update (GtkWidget *widget,
gpointer data)
{
GUnit *val;
GtkSpinButton *spinbutton;
int digits;
val = (GUnit *) data;
*val = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));
digits = ((*val == UNIT_PIXEL) ? 0 :
((*val == UNIT_PERCENT) ? 2 :
(MIN (6, MAX (3, gimp_unit_get_digits (*val))))));
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_width_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_height_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
}
static void
@ -90,7 +114,6 @@ create_selection_options (ToolType tool_type)
GtkObject *feather_scale_data;
GtkWidget *fixed_size_toggle;
GtkAdjustment *adj;
GtkWidget *spinbutton;
/* the new options structure */
options = (SelectionOptions *) g_malloc (sizeof (SelectionOptions));
@ -101,6 +124,7 @@ create_selection_options (ToolType tool_type)
options->fixed_size = FALSE;
options->fixed_height = 1;
options->fixed_width = 1;
options->fixed_unit = UNIT_PIXEL;
options->sample_merged = TRUE;
/* the main vbox */
@ -175,6 +199,12 @@ create_selection_options (ToolType tool_type)
/* Widgets for fixed size select */
if (tool_type == RECT_SELECT || tool_type == ELLIPSE_SELECT)
{
GtkWidget *alignment;
GtkWidget *table;
GtkWidget *width_spinbutton;
GtkWidget *height_spinbutton;
GtkWidget *unitmenu;
fixed_size_toggle = gtk_check_button_new_with_label (_("Fixed size / aspect ratio"));
gtk_box_pack_start (GTK_BOX(vbox), fixed_size_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT(fixed_size_toggle), "toggled",
@ -183,42 +213,78 @@ create_selection_options (ToolType tool_type)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fixed_size_toggle),
options->fixed_size);
gtk_widget_show(fixed_size_toggle);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Width: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1.0,
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_container_add (GTK_CONTAINER (alignment), table);
label = gtk_label_new (_("Width:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
width_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(width_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (width_spinbutton), TRUE);
gtk_widget_set_usize (width_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_width);
gtk_table_attach (GTK_TABLE (table), width_spinbutton,
1, 2, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (width_spinbutton);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Height: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1.0,
label = gtk_label_new (_("Height:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
height_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(height_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(height_spinbutton), TRUE);
gtk_widget_set_usize (height_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_height);
gtk_table_attach (GTK_TABLE (table), height_spinbutton,
1, 2, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (height_spinbutton);
label = gtk_label_new (_("Unit:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
unitmenu = gimp_unit_menu_new ("%a", UNIT_PIXEL, TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT (unitmenu), "unit_changed",
(GtkSignalFunc) selection_unitmenu_update,
&options->fixed_unit);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_width_spinbutton",
width_spinbutton);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_height_spinbutton",
height_spinbutton);
gtk_table_attach (GTK_TABLE (table), unitmenu,
1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (unitmenu);
gtk_widget_show (table);
}
/* the feather toggle button */
@ -231,10 +297,11 @@ create_selection_options (ToolType tool_type)
gtk_widget_show (feather_toggle);
/* the feather radius scale */
hbox = gtk_hbox_new (FALSE, 1);
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Feather Radius: "));
label = gtk_label_new (_("Feather Radius:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@ -308,6 +375,8 @@ rect_select_button_press (Tool *tool,
RectSelect * rect_sel;
gchar select_mode[STATUSBAR_SIZE];
int x, y;
GUnit unit = UNIT_PIXEL;
float unit_factor;
gdisp = (GDisplay *) gdisp_ptr;
rect_sel = (RectSelect *) tool->private;
@ -322,16 +391,40 @@ rect_select_button_press (Tool *tool,
rect_sel->fixed_size = rect_options->fixed_size;
rect_sel->fixed_width = rect_options->fixed_width;
rect_sel->fixed_height = rect_options->fixed_height;
unit = rect_options->fixed_unit;
break;
case ELLIPSE_SELECT:
rect_sel->fixed_size = ellipse_options->fixed_size;
rect_sel->fixed_width = ellipse_options->fixed_width;
rect_sel->fixed_height = ellipse_options->fixed_height;
unit = ellipse_options->fixed_unit;
break;
default:
break;
}
switch (unit)
{
case UNIT_PIXEL:
break;
case UNIT_PERCENT:
rect_sel->fixed_width =
gdisp->gimage->width * rect_sel->fixed_width / 100;
rect_sel->fixed_height =
gdisp->gimage->height * rect_sel->fixed_height / 100;
break;
default:
unit_factor = gimp_unit_get_factor (unit);
rect_sel->fixed_width =
rect_sel->fixed_width * gdisp->gimage->xresolution / unit_factor;
rect_sel->fixed_height =
rect_sel->fixed_height * gdisp->gimage->yresolution / unit_factor;
break;
}
rect_sel->fixed_width = MAX (1, rect_sel->fixed_width);
rect_sel->fixed_height = MAX (1, rect_sel->fixed_height);
rect_sel->w = 0;
rect_sel->h = 0;

View File

@ -51,6 +51,9 @@
static gfloat angle_val;
static gfloat center_vals[2];
/* needed for size update */
static GtkWidget *sizeentry;
/* forward function declarations */
static void * rotate_tool_rotate (GImage *, GimpDrawable *, GDisplay *,
double, TileManager *, int, GimpMatrix);
@ -100,31 +103,31 @@ rotate_tool_transform (Tool *tool,
spinbutton2 =
info_dialog_add_spinbutton (transform_info, _("Center X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
widget =
sizeentry =
info_dialog_add_sizeentry (transform_info, _("Y:"),
center_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
rotate_center_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (widget),
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
-4096,
4096 + gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0,
center_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
-4096,
4096 + gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1,
center_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (transform_info->info_table),
@ -134,6 +137,11 @@ rotate_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
transform_core->x1, transform_core->x2);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
transform_core->y1, transform_core->y2);
transform_core->trans_info[ANGLE] = 0.0;
transform_core->trans_info[REAL_ANGLE] = 0.0;
transform_core->trans_info[CENTER_X] =
@ -156,9 +164,13 @@ rotate_tool_transform (Tool *tool,
case FINISH :
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), FALSE);
return rotate_tool_rotate (gdisp->gimage, gimage_active_drawable (gdisp->gimage), gdisp,
transform_core->trans_info[ANGLE], transform_core->original,
transform_tool_smoothing (), transform_core->transform);
return rotate_tool_rotate (gdisp->gimage,
gimage_active_drawable (gdisp->gimage),
gdisp,
transform_core->trans_info[ANGLE],
transform_core->original,
transform_tool_smoothing (),
transform_core->transform);
break;
}

View File

@ -54,7 +54,7 @@ static void scale_tool_motion (Tool *, void *);
static void scale_info_update (Tool *);
static Argument * scale_invoker (Argument *);
/* callback functions for the info dialog entries */
/* callback functions for the info dialog fields */
static void scale_size_changed (GtkWidget *w, gpointer data);
static void scale_unit_changed (GtkWidget *w, gpointer data);
@ -65,7 +65,7 @@ scale_tool_transform (Tool *tool,
{
GDisplay *gdisp;
TransformCore *transform_core;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) gdisp_ptr;
transform_core = (TransformCore *) tool->private;
@ -82,7 +82,7 @@ scale_tool_transform (Tool *tool,
info_dialog_add_label (transform_info, _("Height:"),
orig_height_buf);
spinbutton2 =
spinbutton =
info_dialog_add_spinbutton (transform_info, _("Current Width:"),
NULL, -1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
@ -90,11 +90,11 @@ scale_tool_transform (Tool *tool,
size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
scale_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_signal_connect (GTK_OBJECT (sizeentry), "unit_changed",
scale_unit_changed, tool);
@ -124,6 +124,11 @@ scale_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
0, transform_core->x2 - transform_core->x1);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
0, transform_core->y2- transform_core->y1);
transform_core->trans_info [X1] = (double) transform_core->x1;
transform_core->trans_info [Y1] = (double) transform_core->y1;
transform_core->trans_info [X2] = (double) transform_core->x2;
@ -197,10 +202,11 @@ scale_info_update (Tool *tool)
float unit_factor;
gchar format_buf[16];
static GUnit label_unit = UNIT_PIXEL;
gdisp = (GDisplay *) tool->gdisp_ptr;
transform_core = (TransformCore *) tool->private;
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry));;
unit_factor = gimp_unit_get_factor (unit);
/* Find original sizes */
x1 = transform_core->x1;
@ -208,11 +214,16 @@ scale_info_update (Tool *tool)
x2 = transform_core->x2;
y2 = transform_core->y2;
if (unit) /* unit != UNIT_PIXEL */
if (unit != UNIT_PERCENT)
label_unit = unit;
unit_factor = gimp_unit_get_factor (label_unit);
if (label_unit) /* unit != UNIT_PIXEL */
{
g_snprintf (format_buf, 16, "%%.%df %s",
gimp_unit_get_digits (unit) + 1,
gimp_unit_get_symbol (unit));
gimp_unit_get_digits (label_unit) + 1,
gimp_unit_get_symbol (label_unit));
g_snprintf (orig_width_buf, MAX_INFO_BUF, format_buf,
(x2 - x1) * unit_factor / gdisp->gimage->xresolution);
g_snprintf (orig_height_buf, MAX_INFO_BUF, format_buf,

View File

@ -67,10 +67,13 @@ struct _crop
/* speed of key movement */
#define ARROW_VELOCITY 25
static InfoDialog * crop_info = NULL;
static InfoDialog *crop_info = NULL;
static gfloat orig_vals[2];
static gfloat size_vals[2];
static GtkWidget *origin_sizeentry;
static GtkWidget *size_sizeentry;
/* crop action functions */
static void crop_button_press (Tool *, GdkEventButton *, gpointer);
static void crop_button_release (Tool *, GdkEventButton *, gpointer);
@ -788,18 +791,40 @@ crop_start (Tool *tool,
gdisp = (GDisplay *) tool->gdisp_ptr;
crop_recalc (tool, crop);
/* if the crop information dialog already exists, delete it */
if (crop_info && (gdisp != old_gdisp))
{
info_dialog_popdown (crop_info);
info_dialog_free (crop_info);
crop_info = NULL;
}
old_gdisp = gdisp;
if (! crop_info)
crop_info_create (tool);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
if (old_gdisp != gdisp)
{
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (origin_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
}
old_gdisp = gdisp;
/* initialize the statusbar display */
crop->context_id =
gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar), "crop");
@ -825,8 +850,7 @@ static void
crop_info_create (Tool *tool)
{
GDisplay *gdisp;
GtkWidget *sizeentry;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) tool->gdisp_ptr;
@ -834,51 +858,61 @@ crop_info_create (Tool *tool)
crop_info = info_dialog_new (_("Crop Information"));
/* add the information fields */
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
origin_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Y:"), orig_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_orig_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (origin_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, orig_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
orig_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, orig_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
orig_vals[1]);
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
size_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Height:"), size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (size_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, size_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 0, size_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, size_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 1, size_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 0, 0);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 1, 6);

View File

@ -67,10 +67,13 @@ struct _crop
/* speed of key movement */
#define ARROW_VELOCITY 25
static InfoDialog * crop_info = NULL;
static InfoDialog *crop_info = NULL;
static gfloat orig_vals[2];
static gfloat size_vals[2];
static GtkWidget *origin_sizeentry;
static GtkWidget *size_sizeentry;
/* crop action functions */
static void crop_button_press (Tool *, GdkEventButton *, gpointer);
static void crop_button_release (Tool *, GdkEventButton *, gpointer);
@ -788,18 +791,40 @@ crop_start (Tool *tool,
gdisp = (GDisplay *) tool->gdisp_ptr;
crop_recalc (tool, crop);
/* if the crop information dialog already exists, delete it */
if (crop_info && (gdisp != old_gdisp))
{
info_dialog_popdown (crop_info);
info_dialog_free (crop_info);
crop_info = NULL;
}
old_gdisp = gdisp;
if (! crop_info)
crop_info_create (tool);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
if (old_gdisp != gdisp)
{
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (origin_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (size_sizeentry),
(gdisp->dot_for_dot ? UNIT_PIXEL :
gdisp->gimage->unit));
}
old_gdisp = gdisp;
/* initialize the statusbar display */
crop->context_id =
gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar), "crop");
@ -825,8 +850,7 @@ static void
crop_info_create (Tool *tool)
{
GDisplay *gdisp;
GtkWidget *sizeentry;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) tool->gdisp_ptr;
@ -834,51 +858,61 @@ crop_info_create (Tool *tool)
crop_info = info_dialog_new (_("Crop Information"));
/* add the information fields */
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Origin X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
origin_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Y:"), orig_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_orig_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (origin_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, orig_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 0,
orig_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, orig_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (origin_sizeentry), 1,
orig_vals[1]);
spinbutton2 = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
spinbutton = info_dialog_add_spinbutton (crop_info, _("Width:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
size_sizeentry =
info_dialog_add_sizeentry (crop_info, _("Height:"), size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
TRUE, TRUE, FALSE, GIMP_SIZE_ENTRY_UPDATE_SIZE,
crop_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (size_sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 0,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, size_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 0,
0, gdisp->gimage->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 0, size_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_sizeentry), 1,
-65536, 65536);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, size_vals[1]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_sizeentry), 1,
0, gdisp->gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (size_sizeentry), 1, size_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 0, 0);
gtk_table_set_row_spacing (GTK_TABLE (crop_info->info_table), 1, 6);

View File

@ -26,6 +26,7 @@
#include "config.h"
#include "libgimp/gimpintl.h"
#include "libgimp/gimpunitmenu.h"
#define NO 0
#define YES 1
@ -60,13 +61,36 @@ selection_toggle_update (GtkWidget *w,
}
static void
selection_spinbutton_update (GtkWidget *widget,
selection_adjustment_update (GtkWidget *widget,
gpointer data)
{
int *val;
val = data;
*val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
val = (int *) data;
*val = GTK_ADJUSTMENT (widget)->value;
}
static void
selection_unitmenu_update (GtkWidget *widget,
gpointer data)
{
GUnit *val;
GtkSpinButton *spinbutton;
int digits;
val = (GUnit *) data;
*val = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));
digits = ((*val == UNIT_PIXEL) ? 0 :
((*val == UNIT_PERCENT) ? 2 :
(MIN (6, MAX (3, gimp_unit_get_digits (*val))))));
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_width_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_height_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
}
static void
@ -90,7 +114,6 @@ create_selection_options (ToolType tool_type)
GtkObject *feather_scale_data;
GtkWidget *fixed_size_toggle;
GtkAdjustment *adj;
GtkWidget *spinbutton;
/* the new options structure */
options = (SelectionOptions *) g_malloc (sizeof (SelectionOptions));
@ -101,6 +124,7 @@ create_selection_options (ToolType tool_type)
options->fixed_size = FALSE;
options->fixed_height = 1;
options->fixed_width = 1;
options->fixed_unit = UNIT_PIXEL;
options->sample_merged = TRUE;
/* the main vbox */
@ -175,6 +199,12 @@ create_selection_options (ToolType tool_type)
/* Widgets for fixed size select */
if (tool_type == RECT_SELECT || tool_type == ELLIPSE_SELECT)
{
GtkWidget *alignment;
GtkWidget *table;
GtkWidget *width_spinbutton;
GtkWidget *height_spinbutton;
GtkWidget *unitmenu;
fixed_size_toggle = gtk_check_button_new_with_label (_("Fixed size / aspect ratio"));
gtk_box_pack_start (GTK_BOX(vbox), fixed_size_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT(fixed_size_toggle), "toggled",
@ -183,42 +213,78 @@ create_selection_options (ToolType tool_type)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fixed_size_toggle),
options->fixed_size);
gtk_widget_show(fixed_size_toggle);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Width: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1.0,
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_container_add (GTK_CONTAINER (alignment), table);
label = gtk_label_new (_("Width:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
width_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(width_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (width_spinbutton), TRUE);
gtk_widget_set_usize (width_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_width);
gtk_table_attach (GTK_TABLE (table), width_spinbutton,
1, 2, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (width_spinbutton);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Height: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1.0,
label = gtk_label_new (_("Height:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
height_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(height_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(height_spinbutton), TRUE);
gtk_widget_set_usize (height_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_height);
gtk_table_attach (GTK_TABLE (table), height_spinbutton,
1, 2, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (height_spinbutton);
label = gtk_label_new (_("Unit:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
unitmenu = gimp_unit_menu_new ("%a", UNIT_PIXEL, TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT (unitmenu), "unit_changed",
(GtkSignalFunc) selection_unitmenu_update,
&options->fixed_unit);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_width_spinbutton",
width_spinbutton);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_height_spinbutton",
height_spinbutton);
gtk_table_attach (GTK_TABLE (table), unitmenu,
1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (unitmenu);
gtk_widget_show (table);
}
/* the feather toggle button */
@ -231,10 +297,11 @@ create_selection_options (ToolType tool_type)
gtk_widget_show (feather_toggle);
/* the feather radius scale */
hbox = gtk_hbox_new (FALSE, 1);
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Feather Radius: "));
label = gtk_label_new (_("Feather Radius:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@ -308,6 +375,8 @@ rect_select_button_press (Tool *tool,
RectSelect * rect_sel;
gchar select_mode[STATUSBAR_SIZE];
int x, y;
GUnit unit = UNIT_PIXEL;
float unit_factor;
gdisp = (GDisplay *) gdisp_ptr;
rect_sel = (RectSelect *) tool->private;
@ -322,16 +391,40 @@ rect_select_button_press (Tool *tool,
rect_sel->fixed_size = rect_options->fixed_size;
rect_sel->fixed_width = rect_options->fixed_width;
rect_sel->fixed_height = rect_options->fixed_height;
unit = rect_options->fixed_unit;
break;
case ELLIPSE_SELECT:
rect_sel->fixed_size = ellipse_options->fixed_size;
rect_sel->fixed_width = ellipse_options->fixed_width;
rect_sel->fixed_height = ellipse_options->fixed_height;
unit = ellipse_options->fixed_unit;
break;
default:
break;
}
switch (unit)
{
case UNIT_PIXEL:
break;
case UNIT_PERCENT:
rect_sel->fixed_width =
gdisp->gimage->width * rect_sel->fixed_width / 100;
rect_sel->fixed_height =
gdisp->gimage->height * rect_sel->fixed_height / 100;
break;
default:
unit_factor = gimp_unit_get_factor (unit);
rect_sel->fixed_width =
rect_sel->fixed_width * gdisp->gimage->xresolution / unit_factor;
rect_sel->fixed_height =
rect_sel->fixed_height * gdisp->gimage->yresolution / unit_factor;
break;
}
rect_sel->fixed_width = MAX (1, rect_sel->fixed_width);
rect_sel->fixed_height = MAX (1, rect_sel->fixed_height);
rect_sel->w = 0;
rect_sel->h = 0;

View File

@ -51,6 +51,9 @@
static gfloat angle_val;
static gfloat center_vals[2];
/* needed for size update */
static GtkWidget *sizeentry;
/* forward function declarations */
static void * rotate_tool_rotate (GImage *, GimpDrawable *, GDisplay *,
double, TileManager *, int, GimpMatrix);
@ -100,31 +103,31 @@ rotate_tool_transform (Tool *tool,
spinbutton2 =
info_dialog_add_spinbutton (transform_info, _("Center X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
widget =
sizeentry =
info_dialog_add_sizeentry (transform_info, _("Y:"),
center_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
rotate_center_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (widget),
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
-4096,
4096 + gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0,
center_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
-4096,
4096 + gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1,
center_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (transform_info->info_table),
@ -134,6 +137,11 @@ rotate_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
transform_core->x1, transform_core->x2);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
transform_core->y1, transform_core->y2);
transform_core->trans_info[ANGLE] = 0.0;
transform_core->trans_info[REAL_ANGLE] = 0.0;
transform_core->trans_info[CENTER_X] =
@ -156,9 +164,13 @@ rotate_tool_transform (Tool *tool,
case FINISH :
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), FALSE);
return rotate_tool_rotate (gdisp->gimage, gimage_active_drawable (gdisp->gimage), gdisp,
transform_core->trans_info[ANGLE], transform_core->original,
transform_tool_smoothing (), transform_core->transform);
return rotate_tool_rotate (gdisp->gimage,
gimage_active_drawable (gdisp->gimage),
gdisp,
transform_core->trans_info[ANGLE],
transform_core->original,
transform_tool_smoothing (),
transform_core->transform);
break;
}

View File

@ -54,7 +54,7 @@ static void scale_tool_motion (Tool *, void *);
static void scale_info_update (Tool *);
static Argument * scale_invoker (Argument *);
/* callback functions for the info dialog entries */
/* callback functions for the info dialog fields */
static void scale_size_changed (GtkWidget *w, gpointer data);
static void scale_unit_changed (GtkWidget *w, gpointer data);
@ -65,7 +65,7 @@ scale_tool_transform (Tool *tool,
{
GDisplay *gdisp;
TransformCore *transform_core;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) gdisp_ptr;
transform_core = (TransformCore *) tool->private;
@ -82,7 +82,7 @@ scale_tool_transform (Tool *tool,
info_dialog_add_label (transform_info, _("Height:"),
orig_height_buf);
spinbutton2 =
spinbutton =
info_dialog_add_spinbutton (transform_info, _("Current Width:"),
NULL, -1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
@ -90,11 +90,11 @@ scale_tool_transform (Tool *tool,
size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
scale_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_signal_connect (GTK_OBJECT (sizeentry), "unit_changed",
scale_unit_changed, tool);
@ -124,6 +124,11 @@ scale_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
0, transform_core->x2 - transform_core->x1);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
0, transform_core->y2- transform_core->y1);
transform_core->trans_info [X1] = (double) transform_core->x1;
transform_core->trans_info [Y1] = (double) transform_core->y1;
transform_core->trans_info [X2] = (double) transform_core->x2;
@ -197,10 +202,11 @@ scale_info_update (Tool *tool)
float unit_factor;
gchar format_buf[16];
static GUnit label_unit = UNIT_PIXEL;
gdisp = (GDisplay *) tool->gdisp_ptr;
transform_core = (TransformCore *) tool->private;
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry));;
unit_factor = gimp_unit_get_factor (unit);
/* Find original sizes */
x1 = transform_core->x1;
@ -208,11 +214,16 @@ scale_info_update (Tool *tool)
x2 = transform_core->x2;
y2 = transform_core->y2;
if (unit) /* unit != UNIT_PIXEL */
if (unit != UNIT_PERCENT)
label_unit = unit;
unit_factor = gimp_unit_get_factor (label_unit);
if (label_unit) /* unit != UNIT_PIXEL */
{
g_snprintf (format_buf, 16, "%%.%df %s",
gimp_unit_get_digits (unit) + 1,
gimp_unit_get_symbol (unit));
gimp_unit_get_digits (label_unit) + 1,
gimp_unit_get_symbol (label_unit));
g_snprintf (orig_width_buf, MAX_INFO_BUF, format_buf,
(x2 - x1) * unit_factor / gdisp->gimage->xresolution);
g_snprintf (orig_height_buf, MAX_INFO_BUF, format_buf,

View File

@ -26,6 +26,7 @@
#include "config.h"
#include "libgimp/gimpintl.h"
#include "libgimp/gimpunitmenu.h"
#define NO 0
#define YES 1
@ -60,13 +61,36 @@ selection_toggle_update (GtkWidget *w,
}
static void
selection_spinbutton_update (GtkWidget *widget,
selection_adjustment_update (GtkWidget *widget,
gpointer data)
{
int *val;
val = data;
*val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
val = (int *) data;
*val = GTK_ADJUSTMENT (widget)->value;
}
static void
selection_unitmenu_update (GtkWidget *widget,
gpointer data)
{
GUnit *val;
GtkSpinButton *spinbutton;
int digits;
val = (GUnit *) data;
*val = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));
digits = ((*val == UNIT_PIXEL) ? 0 :
((*val == UNIT_PERCENT) ? 2 :
(MIN (6, MAX (3, gimp_unit_get_digits (*val))))));
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_width_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
spinbutton = GTK_SPIN_BUTTON (gtk_object_get_data (GTK_OBJECT (widget),
"fixed_height_spinbutton"));
gtk_spin_button_set_digits (spinbutton, digits);
}
static void
@ -90,7 +114,6 @@ create_selection_options (ToolType tool_type)
GtkObject *feather_scale_data;
GtkWidget *fixed_size_toggle;
GtkAdjustment *adj;
GtkWidget *spinbutton;
/* the new options structure */
options = (SelectionOptions *) g_malloc (sizeof (SelectionOptions));
@ -101,6 +124,7 @@ create_selection_options (ToolType tool_type)
options->fixed_size = FALSE;
options->fixed_height = 1;
options->fixed_width = 1;
options->fixed_unit = UNIT_PIXEL;
options->sample_merged = TRUE;
/* the main vbox */
@ -175,6 +199,12 @@ create_selection_options (ToolType tool_type)
/* Widgets for fixed size select */
if (tool_type == RECT_SELECT || tool_type == ELLIPSE_SELECT)
{
GtkWidget *alignment;
GtkWidget *table;
GtkWidget *width_spinbutton;
GtkWidget *height_spinbutton;
GtkWidget *unitmenu;
fixed_size_toggle = gtk_check_button_new_with_label (_("Fixed size / aspect ratio"));
gtk_box_pack_start (GTK_BOX(vbox), fixed_size_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT(fixed_size_toggle), "toggled",
@ -183,42 +213,78 @@ create_selection_options (ToolType tool_type)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fixed_size_toggle),
options->fixed_size);
gtk_widget_show(fixed_size_toggle);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Width: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1.0,
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_container_add (GTK_CONTAINER (alignment), table);
label = gtk_label_new (_("Width:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_width, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
width_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(width_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (width_spinbutton), TRUE);
gtk_widget_set_usize (width_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_width);
gtk_table_attach (GTK_TABLE (table), width_spinbutton,
1, 2, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (width_spinbutton);
hbox = gtk_hbox_new (TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Height: "));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1.0,
label = gtk_label_new (_("Height:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (options->fixed_height, 1e-5,
32767.0, 1.0, 50.0, 0.0);
spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(spinbutton), GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (spinbutton), "changed",
(GtkSignalFunc) selection_spinbutton_update,
height_spinbutton = gtk_spin_button_new (adj, 1.0, 0.0);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(height_spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(height_spinbutton), TRUE);
gtk_widget_set_usize (height_spinbutton, 75, 0);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) selection_adjustment_update,
&options->fixed_height);
gtk_table_attach (GTK_TABLE (table), height_spinbutton,
1, 2, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (spinbutton);
gtk_widget_show (hbox);
gtk_widget_show (height_spinbutton);
label = gtk_label_new (_("Unit:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
unitmenu = gimp_unit_menu_new ("%a", UNIT_PIXEL, TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT (unitmenu), "unit_changed",
(GtkSignalFunc) selection_unitmenu_update,
&options->fixed_unit);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_width_spinbutton",
width_spinbutton);
gtk_object_set_data (GTK_OBJECT (unitmenu), "fixed_height_spinbutton",
height_spinbutton);
gtk_table_attach (GTK_TABLE (table), unitmenu,
1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
gtk_widget_show (unitmenu);
gtk_widget_show (table);
}
/* the feather toggle button */
@ -231,10 +297,11 @@ create_selection_options (ToolType tool_type)
gtk_widget_show (feather_toggle);
/* the feather radius scale */
hbox = gtk_hbox_new (FALSE, 1);
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Feather Radius: "));
label = gtk_label_new (_("Feather Radius:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@ -308,6 +375,8 @@ rect_select_button_press (Tool *tool,
RectSelect * rect_sel;
gchar select_mode[STATUSBAR_SIZE];
int x, y;
GUnit unit = UNIT_PIXEL;
float unit_factor;
gdisp = (GDisplay *) gdisp_ptr;
rect_sel = (RectSelect *) tool->private;
@ -322,16 +391,40 @@ rect_select_button_press (Tool *tool,
rect_sel->fixed_size = rect_options->fixed_size;
rect_sel->fixed_width = rect_options->fixed_width;
rect_sel->fixed_height = rect_options->fixed_height;
unit = rect_options->fixed_unit;
break;
case ELLIPSE_SELECT:
rect_sel->fixed_size = ellipse_options->fixed_size;
rect_sel->fixed_width = ellipse_options->fixed_width;
rect_sel->fixed_height = ellipse_options->fixed_height;
unit = ellipse_options->fixed_unit;
break;
default:
break;
}
switch (unit)
{
case UNIT_PIXEL:
break;
case UNIT_PERCENT:
rect_sel->fixed_width =
gdisp->gimage->width * rect_sel->fixed_width / 100;
rect_sel->fixed_height =
gdisp->gimage->height * rect_sel->fixed_height / 100;
break;
default:
unit_factor = gimp_unit_get_factor (unit);
rect_sel->fixed_width =
rect_sel->fixed_width * gdisp->gimage->xresolution / unit_factor;
rect_sel->fixed_height =
rect_sel->fixed_height * gdisp->gimage->yresolution / unit_factor;
break;
}
rect_sel->fixed_width = MAX (1, rect_sel->fixed_width);
rect_sel->fixed_height = MAX (1, rect_sel->fixed_height);
rect_sel->w = 0;
rect_sel->h = 0;

View File

@ -51,6 +51,9 @@
static gfloat angle_val;
static gfloat center_vals[2];
/* needed for size update */
static GtkWidget *sizeentry;
/* forward function declarations */
static void * rotate_tool_rotate (GImage *, GimpDrawable *, GDisplay *,
double, TileManager *, int, GimpMatrix);
@ -100,31 +103,31 @@ rotate_tool_transform (Tool *tool,
spinbutton2 =
info_dialog_add_spinbutton (transform_info, _("Center X:"), NULL,
-1, 1, 1, 10, 1, 1, 2, NULL, NULL);
widget =
sizeentry =
info_dialog_add_sizeentry (transform_info, _("Y:"),
center_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
rotate_center_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (widget),
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
-4096,
4096 + gdisp->gimage->width);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
gdisp->gimage->xresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0,
center_vals[0]);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
-4096,
4096 + gdisp->gimage->height);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
gdisp->gimage->yresolution, FALSE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1,
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1,
center_vals[1]);
gtk_table_set_row_spacing (GTK_TABLE (transform_info->info_table),
@ -134,6 +137,11 @@ rotate_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
transform_core->x1, transform_core->x2);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
transform_core->y1, transform_core->y2);
transform_core->trans_info[ANGLE] = 0.0;
transform_core->trans_info[REAL_ANGLE] = 0.0;
transform_core->trans_info[CENTER_X] =
@ -156,9 +164,13 @@ rotate_tool_transform (Tool *tool,
case FINISH :
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), FALSE);
return rotate_tool_rotate (gdisp->gimage, gimage_active_drawable (gdisp->gimage), gdisp,
transform_core->trans_info[ANGLE], transform_core->original,
transform_tool_smoothing (), transform_core->transform);
return rotate_tool_rotate (gdisp->gimage,
gimage_active_drawable (gdisp->gimage),
gdisp,
transform_core->trans_info[ANGLE],
transform_core->original,
transform_tool_smoothing (),
transform_core->transform);
break;
}

View File

@ -54,7 +54,7 @@ static void scale_tool_motion (Tool *, void *);
static void scale_info_update (Tool *);
static Argument * scale_invoker (Argument *);
/* callback functions for the info dialog entries */
/* callback functions for the info dialog fields */
static void scale_size_changed (GtkWidget *w, gpointer data);
static void scale_unit_changed (GtkWidget *w, gpointer data);
@ -65,7 +65,7 @@ scale_tool_transform (Tool *tool,
{
GDisplay *gdisp;
TransformCore *transform_core;
GtkWidget *spinbutton2;
GtkWidget *spinbutton;
gdisp = (GDisplay *) gdisp_ptr;
transform_core = (TransformCore *) tool->private;
@ -82,7 +82,7 @@ scale_tool_transform (Tool *tool,
info_dialog_add_label (transform_info, _("Height:"),
orig_height_buf);
spinbutton2 =
spinbutton =
info_dialog_add_spinbutton (transform_info, _("Current Width:"),
NULL, -1, 1, 1, 10, 1, 1, 2, NULL, NULL);
sizeentry =
@ -90,11 +90,11 @@ scale_tool_transform (Tool *tool,
size_vals, 1,
gdisp->dot_for_dot ?
UNIT_PIXEL : gdisp->gimage->unit, "%a",
TRUE, FALSE, FALSE,
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
scale_size_changed, tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (sizeentry),
GTK_SPIN_BUTTON (spinbutton2), NULL);
GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_signal_connect (GTK_OBJECT (sizeentry), "unit_changed",
scale_unit_changed, tool);
@ -124,6 +124,11 @@ scale_tool_transform (Tool *tool,
}
gtk_widget_set_sensitive (GTK_WIDGET (transform_info->shell), TRUE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 0,
0, transform_core->x2 - transform_core->x1);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (sizeentry), 1,
0, transform_core->y2- transform_core->y1);
transform_core->trans_info [X1] = (double) transform_core->x1;
transform_core->trans_info [Y1] = (double) transform_core->y1;
transform_core->trans_info [X2] = (double) transform_core->x2;
@ -197,10 +202,11 @@ scale_info_update (Tool *tool)
float unit_factor;
gchar format_buf[16];
static GUnit label_unit = UNIT_PIXEL;
gdisp = (GDisplay *) tool->gdisp_ptr;
transform_core = (TransformCore *) tool->private;
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (sizeentry));;
unit_factor = gimp_unit_get_factor (unit);
/* Find original sizes */
x1 = transform_core->x1;
@ -208,11 +214,16 @@ scale_info_update (Tool *tool)
x2 = transform_core->x2;
y2 = transform_core->y2;
if (unit) /* unit != UNIT_PIXEL */
if (unit != UNIT_PERCENT)
label_unit = unit;
unit_factor = gimp_unit_get_factor (label_unit);
if (label_unit) /* unit != UNIT_PIXEL */
{
g_snprintf (format_buf, 16, "%%.%df %s",
gimp_unit_get_digits (unit) + 1,
gimp_unit_get_symbol (unit));
gimp_unit_get_digits (label_unit) + 1,
gimp_unit_get_symbol (label_unit));
g_snprintf (orig_width_buf, MAX_INFO_BUF, format_buf,
(x2 - x1) * unit_factor / gdisp->gimage->xresolution);
g_snprintf (orig_height_buf, MAX_INFO_BUF, format_buf,

View File

@ -49,6 +49,8 @@ struct _GimpSizeEntryField
gint index;
gfloat resolution;
gfloat lower;
gfloat upper;
GtkObject *value_adjustment;
GtkWidget *value_spinbutton;
@ -223,6 +225,8 @@ gimp_size_entry_new (gint number_of_fields,
gsef->gse = gse;
gsef->index = i;
gsef->resolution = 1.0; /* just to avoid division by zero */
gsef->lower = 0.0;
gsef->upper = 100.0;
gsef->value = 0;
gsef->min_value = 0;
gsef->max_value = SIZE_MAX_VALUE;
@ -240,7 +244,8 @@ gimp_size_entry_new (gint number_of_fields,
1.0, 10.0, 0.0);
gsef->value_spinbutton =
gtk_spin_button_new (GTK_ADJUSTMENT (gsef->value_adjustment), 1.0,
MIN (gimp_unit_get_digits (unit), 5) + 1);
(unit == UNIT_PERCENT) ? 2 :
(MIN (gimp_unit_get_digits (unit), 5) + 1));
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(gsef->value_spinbutton),
GTK_SHADOW_NONE);
gtk_widget_set_usize (gsef->value_spinbutton, spinbutton_usize, 0);
@ -303,7 +308,8 @@ gimp_size_entry_new (gint number_of_fields,
}
gse->unitmenu = gimp_unit_menu_new (unit_format, unit,
gse->menu_show_pixels, FALSE, TRUE);
gse->menu_show_pixels,
gse->menu_show_percent, TRUE);
gtk_table_attach_defaults (GTK_TABLE (gse), gse->unitmenu,
i+2, i+3,
gse->show_refval+1, gse->show_refval+2);
@ -340,6 +346,8 @@ gimp_size_entry_add_field (GimpSizeEntry *gse,
gsef->gse = gse;
gsef->index = 0;
gsef->resolution = 1.0; /* just to avoid division by zero */
gsef->lower = 0.0;
gsef->upper = 100.0;
gsef->value = 0;
gsef->min_value = 0;
gsef->max_value = SIZE_MAX_VALUE;
@ -443,6 +451,29 @@ gimp_size_entry_set_resolution (GimpSizeEntry *gse,
}
/* percent stuff ***********/
void
gimp_size_entry_set_size (GimpSizeEntry *gse,
gint field,
gfloat lower,
gfloat upper)
{
GimpSizeEntryField *gsef;
g_return_if_fail (gse != NULL);
g_return_if_fail (GIMP_IS_SIZE_ENTRY (gse));
g_return_if_fail ((field >= 0) && (field < gse->number_of_fields));
g_return_if_fail (lower < upper);
gsef = (GimpSizeEntryField*) g_slist_nth_data (gse->fields, field);
gsef->lower = lower;
gsef->upper = upper;
gimp_size_entry_set_refval (gse, field, gsef->refval);
}
/* value stuff ***********/
void
@ -476,18 +507,32 @@ gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse,
case GIMP_SIZE_ENTRY_UPDATE_NONE:
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gse->unit) /* unit != UNIT_PIXEL */
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit),
gsef->max_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit));
else /* unit == UNIT_PIXEL */
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value,
gsef->max_value);
switch (gse->unit)
{
case UNIT_PIXEL:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->lower +
(gsef->upper - gsef->lower) *
gsef->min_value / 100,
gsef->lower +
(gsef->upper - gsef->lower) *
gsef->max_value / 100);
break;
case UNIT_PERCENT:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value,
gsef->max_value);
break;
default:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit),
gsef->max_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit));
break;
}
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gimp_size_entry_set_refval_boundaries (gse, field,
@ -531,23 +576,31 @@ gimp_size_entry_update_value (GimpSizeEntryField *gsef,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gsef->gse->unit) /* unit != UNIT_PIXEL */
gsef->refval = gsef->value * gsef->resolution /
gimp_unit_get_factor (gsef->gse->unit);
else /* unit == UNIT_PIXEL */
gsef->refval = value;
switch (gsef->gse->unit)
{
case UNIT_PIXEL:
gsef->refval = value;
break;
case UNIT_PERCENT:
gsef->refval =
gsef->lower + (gsef->upper - gsef->lower) * value / 100;
break;
default:
gsef->refval = gsef->value * gsef->resolution /
gimp_unit_get_factor (gsef->gse->unit);
break;
}
if (gsef->gse->show_refval)
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->refval_adjustment),
gsef->refval);
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gsef->refval = value * gimp_unit_get_factor (gsef->gse->unit);
if (gsef->gse->show_refval)
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->refval_adjustment),
gsef->refval);
break;
default:
break;
}
@ -632,20 +685,33 @@ gimp_size_entry_set_refval_boundaries (GimpSizeEntry *gse,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gse->unit) /* unit != UNIT_PIXEL */
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution,
gsef->max_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution);
else /* unit == UNIT_PIXEL */
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval,
gsef->max_refval);
switch (gse->unit)
{
case UNIT_PIXEL:
gimp_size_entry_set_value_boundaries (gse, field,
100 * (gsef->min_refval -
gsef->lower) /
(gsef->upper - gsef->lower),
100 * (gsef->max_refval -
gsef->lower) /
(gsef->upper - gsef->lower));
break;
case UNIT_PERCENT:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval,
gsef->max_refval);
break;
default:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution,
gsef->max_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution);
break;
}
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval /
@ -716,15 +782,23 @@ gimp_size_entry_update_refval (GimpSizeEntryField *gsef,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gsef->gse->unit) /* unit != UNIT_PIXEL */
gsef->value = gsef->refval * gimp_unit_get_factor (gsef->gse->unit) /
gsef->resolution;
else /* unit == UNIT_PIXEL */
gsef->value = refval;
switch (gsef->gse->unit)
{
case UNIT_PIXEL:
gsef->value = refval;
break;
case UNIT_PERCENT:
gsef->value =
100 * (refval - gsef->lower) / (gsef->upper - gsef->lower);
break;
default:
gsef->value = gsef->refval * gimp_unit_get_factor (gsef->gse->unit) /
gsef->resolution;
break;
}
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->value_adjustment),
gsef->value);
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gsef->value = refval / gimp_unit_get_factor (gsef->gse->unit);
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->value_adjustment),
@ -810,6 +884,9 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse,
if (unit == UNIT_PIXEL)
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
gsef->refval_digits);
else if (unit == UNIT_PERCENT)
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
2);
else
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
MIN(gimp_unit_get_digits (unit), 5) + 1);
@ -835,6 +912,7 @@ gimp_size_entry_set_unit (GimpSizeEntry *gse,
g_return_if_fail (gse != NULL);
g_return_if_fail (GIMP_IS_SIZE_ENTRY (gse));
g_return_if_fail (gse->menu_show_pixels || (unit != UNIT_PIXEL));
g_return_if_fail (gse->menu_show_percent || (unit != UNIT_PERCENT));
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (gse->unitmenu), unit);
gimp_size_entry_update_unit (gse, unit);

View File

@ -117,7 +117,6 @@ void gimp_size_entry_add_field (GimpSizeEntry *gse,
/* this one is just a convenience function if you want to add labels
* to the empty cells of the widget
* (take care not to specify cells which already have a widget ;-)
*/
void gimp_size_entry_attach_label (GimpSizeEntry *gse,
gchar *text,
@ -137,10 +136,20 @@ void gimp_size_entry_set_resolution (GimpSizeEntry *gse,
gfloat resolution,
guint keep_size);
/* this one sets the values (in pixels) which will be treated as
* 0% and 100% when we want "percent" in the unit menu
*
* does nothing if update_policy != GIMP_SIZE_ENTRY_UPDATE_SIZE
*/
void gimp_size_entry_set_size (GimpSizeEntry *gse,
gint field,
gfloat lower,
gfloat upper);
/* these functions set/return the value in the units the user selected
* note that in some cases where the caller chooses not to have the
* reference value row and the user selected the reference unit
* the both values 'value' and 'refvalue' will be the same
* the both values 'value' and 'refval' will be the same
*/
void gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse,
gint field,

View File

@ -24,7 +24,7 @@
#include "gimpunit.h"
#include "libgimp/gimpintl.h"
/* internal structures */
/* internal structures */
typedef struct {
guint delete_on_exit;
@ -51,8 +51,14 @@ static GimpUnitDef gimp_unit_defs[UNIT_END] =
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
/* public functions */
/* public functions */
gint
gimp_unit_get_number_of_units (void)
@ -235,6 +241,9 @@ gimp_unit_get_identifier (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].identifier);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.identifier);
return_vals = gimp_run_procedure ("gimp_unit_get_identifier",
&nreturn_vals,
PARAM_INT32, unit,
@ -263,6 +272,9 @@ gimp_unit_get_symbol (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].symbol);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.symbol);
return_vals = gimp_run_procedure ("gimp_unit_get_symbol",
&nreturn_vals,
PARAM_INT32, unit,
@ -286,6 +298,14 @@ gimp_unit_get_abbreviation (GUnit unit)
gchar *abbreviation;
g_return_val_if_fail (unit >= UNIT_PIXEL, g_strdup (""));
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].abbreviation);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.abbreviation);
return_vals = gimp_run_procedure ("gimp_unit_get_abbreviation",
&nreturn_vals,
PARAM_INT32, unit,
@ -314,6 +334,9 @@ gimp_unit_get_singular (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].singular));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.singular));
return_vals = gimp_run_procedure ("gimp_unit_get_singular",
&nreturn_vals,
PARAM_INT32, unit,
@ -342,6 +365,9 @@ gimp_unit_get_plural (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].plural));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.plural));
return_vals = gimp_run_procedure ("gimp_unit_get_plural",
&nreturn_vals,
PARAM_INT32, unit,

View File

@ -36,7 +36,6 @@
extern "C" {
#endif /* __cplusplus */
typedef enum
{
UNIT_PIXEL = 0,
@ -44,8 +43,18 @@ typedef enum
UNIT_MM = 2,
UNIT_POINT = 3,
UNIT_PICA = 4,
UNIT_END = 5 /* never use UNIT_END but
gimp_unit_get_number_of_units() instead */
UNIT_END = 5, /* never use UNIT_END but
* gimp_unit_get_number_of_units() instead
*/
UNIT_PERCENT = 65536 /* this one does not really belong here but it's
* convenient to use the unit system for the
* various strings (symbol, singular, ...)
*
* you can only ask it for it's strings, asking for
* factor, digits or deletion_flag will produce
* an error.
*/
} GUnit;
@ -77,7 +86,7 @@ GUnit gimp_unit_new (gchar *identifier,
*/
guint gimp_unit_get_deletion_flag (GUnit unit);
void gimp_unit_set_deletion_flag (GUnit unit,
guint deletion_flag);
guint deletion_flag);
/* The meaning of 'factor' is:
* distance_in_units == ( factor * distance_in_inches )

View File

@ -24,7 +24,7 @@
#include "gimpunit.h"
#include "libgimp/gimpintl.h"
/* internal structures */
/* internal structures */
typedef struct {
guint delete_on_exit;
@ -51,8 +51,14 @@ static GimpUnitDef gimp_unit_defs[UNIT_END] =
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
/* public functions */
/* public functions */
gint
gimp_unit_get_number_of_units (void)
@ -235,6 +241,9 @@ gimp_unit_get_identifier (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].identifier);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.identifier);
return_vals = gimp_run_procedure ("gimp_unit_get_identifier",
&nreturn_vals,
PARAM_INT32, unit,
@ -263,6 +272,9 @@ gimp_unit_get_symbol (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].symbol);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.symbol);
return_vals = gimp_run_procedure ("gimp_unit_get_symbol",
&nreturn_vals,
PARAM_INT32, unit,
@ -286,6 +298,14 @@ gimp_unit_get_abbreviation (GUnit unit)
gchar *abbreviation;
g_return_val_if_fail (unit >= UNIT_PIXEL, g_strdup (""));
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].abbreviation);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.abbreviation);
return_vals = gimp_run_procedure ("gimp_unit_get_abbreviation",
&nreturn_vals,
PARAM_INT32, unit,
@ -314,6 +334,9 @@ gimp_unit_get_singular (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].singular));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.singular));
return_vals = gimp_run_procedure ("gimp_unit_get_singular",
&nreturn_vals,
PARAM_INT32, unit,
@ -342,6 +365,9 @@ gimp_unit_get_plural (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].plural));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.plural));
return_vals = gimp_run_procedure ("gimp_unit_get_plural",
&nreturn_vals,
PARAM_INT32, unit,

View File

@ -24,7 +24,7 @@
#include "gimpunit.h"
#include "libgimp/gimpintl.h"
/* internal structures */
/* internal structures */
typedef struct {
guint delete_on_exit;
@ -51,8 +51,14 @@ static GimpUnitDef gimp_unit_defs[UNIT_END] =
{ FALSE, 6.0, 1, "picas", "pc", "pc", N_("pica"), N_("picas") },
};
/* not a unit at all but kept here to have the strings in one place
*/
static GimpUnitDef gimp_unit_percent =
{
FALSE, 0.0, 0, "percent", "%", "%", N_("percent"), N_("percent")
};
/* public functions */
/* public functions */
gint
gimp_unit_get_number_of_units (void)
@ -235,6 +241,9 @@ gimp_unit_get_identifier (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].identifier);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.identifier);
return_vals = gimp_run_procedure ("gimp_unit_get_identifier",
&nreturn_vals,
PARAM_INT32, unit,
@ -263,6 +272,9 @@ gimp_unit_get_symbol (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].symbol);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.symbol);
return_vals = gimp_run_procedure ("gimp_unit_get_symbol",
&nreturn_vals,
PARAM_INT32, unit,
@ -286,6 +298,14 @@ gimp_unit_get_abbreviation (GUnit unit)
gchar *abbreviation;
g_return_val_if_fail (unit >= UNIT_PIXEL, g_strdup (""));
if (unit < UNIT_END)
return g_strdup (gimp_unit_defs[unit].abbreviation);
if (unit == UNIT_PERCENT)
return g_strdup (gimp_unit_percent.abbreviation);
return_vals = gimp_run_procedure ("gimp_unit_get_abbreviation",
&nreturn_vals,
PARAM_INT32, unit,
@ -314,6 +334,9 @@ gimp_unit_get_singular (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].singular));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.singular));
return_vals = gimp_run_procedure ("gimp_unit_get_singular",
&nreturn_vals,
PARAM_INT32, unit,
@ -342,6 +365,9 @@ gimp_unit_get_plural (GUnit unit)
if (unit < UNIT_END)
return g_strdup (gettext (gimp_unit_defs[unit].plural));
if (unit == UNIT_PERCENT)
return g_strdup (gettext (gimp_unit_percent.plural));
return_vals = gimp_run_procedure ("gimp_unit_get_plural",
&nreturn_vals,
PARAM_INT32, unit,

View File

@ -129,9 +129,11 @@ gimp_unit_menu_new (gchar *format,
GUnit u;
g_return_val_if_fail ((unit >= UNIT_PIXEL) &&
(unit < gimp_unit_get_number_of_units ()), NULL);
(unit < gimp_unit_get_number_of_units ()) ||
(unit == UNIT_PERCENT), NULL);
if (unit >= gimp_unit_get_number_of_built_in_units ())
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
(unit != UNIT_PERCENT))
show_custom = TRUE;
gum = gtk_type_new (gimp_unit_menu_get_type ());
@ -145,6 +147,29 @@ gimp_unit_menu_new (gchar *format,
u < gimp_unit_get_number_of_built_in_units();
u++)
{
/* special cases "pixels" and "percent" */
if (u == UNIT_INCH)
{
if (show_percent)
{
menuitem =
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, UNIT_PERCENT));
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem),
"gimp_unit_menu", (gpointer) UNIT_PERCENT);
gtk_widget_show (menuitem);
}
if (show_pixels || show_percent)
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
}
}
menuitem =
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, u));
gtk_menu_append (GTK_MENU (menu), menuitem);
@ -152,17 +177,10 @@ gimp_unit_menu_new (gchar *format,
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu", (gpointer)u);
gtk_widget_show (menuitem);
/* add a separator after "pixels" */
if (u == UNIT_PIXEL)
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
}
}
if (unit >= gimp_unit_get_number_of_built_in_units ())
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
(unit != UNIT_PERCENT))
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
@ -182,26 +200,26 @@ gimp_unit_menu_new (gchar *format,
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
menuitem =
gtk_menu_item_new_with_label (_("More..."));
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
(gpointer)65536);
(gpointer) (UNIT_PERCENT + 1));
gtk_widget_show(menuitem);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (gum), menu);
gum->unit = unit;
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(unit == UNIT_PIXEL) ? 0 :
(show_pixels ?
((unit < UNIT_END) ? unit + 1 : UNIT_END + 2) :
((unit < UNIT_END) ? unit - 1 : UNIT_END)));
((unit == UNIT_PERCENT) ? (show_pixels ? 1 : 0) :
(((show_pixels || show_percent) ? 2 : 0) +
((show_pixels && show_percent) ? 1 : 0) +
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
return GTK_WIDGET (gum);
}
@ -216,17 +234,19 @@ gimp_unit_menu_set_unit (GimpUnitMenu *gum,
g_return_if_fail (gum != NULL);
g_return_if_fail (GIMP_IS_UNIT_MENU (gum));
g_return_if_fail ((unit >= UNIT_PIXEL) &&
((unit > UNIT_PIXEL) || gum->show_pixels) &&
(unit < gimp_unit_get_number_of_units ()));
g_return_if_fail (((unit >= UNIT_PIXEL) &&
((unit > UNIT_PIXEL) || gum->show_pixels) &&
(unit < gimp_unit_get_number_of_units ())) ||
((unit == UNIT_PERCENT) && gum->show_percent));
if (unit == gum->unit)
return;
items = GTK_MENU_SHELL (GTK_OPTION_MENU (gum)->menu)->children;
user_unit = UNIT_END + (gum->show_pixels ? 2 : 0);
user_unit = UNIT_END + (((gum->show_pixels || gum->show_percent) ? 2 : 0) +
((gum->show_pixels && gum->show_percent) ? 1 : 0));
if (unit >= UNIT_END)
if ((unit >= UNIT_END) && (unit != UNIT_PERCENT))
{
if ((g_list_length (items) - 3) >= user_unit)
{
@ -256,9 +276,13 @@ gimp_unit_menu_set_unit (GimpUnitMenu *gum,
gum->unit = unit;
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(unit == UNIT_PIXEL) ? 0 :
(gum->show_pixels ?
((unit < UNIT_END) ? unit + 1 : UNIT_END + 2) :
((unit < UNIT_END) ? unit - 1 : UNIT_END)));
((unit == UNIT_PERCENT) ?
(gum->show_pixels ? 1 : 0) :
(((gum->show_pixels ||
gum->show_percent) ? 2 : 0) +
((gum->show_pixels &&
gum->show_percent) ? 1 : 0) +
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
}
GUnit
@ -545,15 +569,18 @@ gimp_unit_menu_callback (GtkWidget *widget,
return;
/* was "More..." selected? */
if (new_unit == 65536)
if (new_unit == (UNIT_PERCENT + 1))
{
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(gum->unit == UNIT_PIXEL) ? 0 :
(gum->show_pixels ?
((gum->unit < UNIT_END) ?
gum->unit + 1 : UNIT_END + 2) :
((gum->unit < UNIT_END) ?
gum->unit - 1 : UNIT_END)));
((gum->unit == UNIT_PERCENT) ?
(gum->show_pixels ? 1 : 0) :
((gum->show_pixels ||
gum->show_percent ? 2 : 0) +
(gum->show_pixels &&
gum->show_percent ? 1 : 0) +
((gum->unit < UNIT_END) ?
gum->unit - 1 : UNIT_END))));
if (! gum->selection)
gimp_unit_menu_create_selection (gum);
return;

View File

@ -36,7 +36,6 @@
extern "C" {
#endif /* __cplusplus */
typedef enum
{
UNIT_PIXEL = 0,
@ -44,8 +43,18 @@ typedef enum
UNIT_MM = 2,
UNIT_POINT = 3,
UNIT_PICA = 4,
UNIT_END = 5 /* never use UNIT_END but
gimp_unit_get_number_of_units() instead */
UNIT_END = 5, /* never use UNIT_END but
* gimp_unit_get_number_of_units() instead
*/
UNIT_PERCENT = 65536 /* this one does not really belong here but it's
* convenient to use the unit system for the
* various strings (symbol, singular, ...)
*
* you can only ask it for it's strings, asking for
* factor, digits or deletion_flag will produce
* an error.
*/
} GUnit;
@ -77,7 +86,7 @@ GUnit gimp_unit_new (gchar *identifier,
*/
guint gimp_unit_get_deletion_flag (GUnit unit);
void gimp_unit_set_deletion_flag (GUnit unit,
guint deletion_flag);
guint deletion_flag);
/* The meaning of 'factor' is:
* distance_in_units == ( factor * distance_in_inches )

View File

@ -49,6 +49,8 @@ struct _GimpSizeEntryField
gint index;
gfloat resolution;
gfloat lower;
gfloat upper;
GtkObject *value_adjustment;
GtkWidget *value_spinbutton;
@ -223,6 +225,8 @@ gimp_size_entry_new (gint number_of_fields,
gsef->gse = gse;
gsef->index = i;
gsef->resolution = 1.0; /* just to avoid division by zero */
gsef->lower = 0.0;
gsef->upper = 100.0;
gsef->value = 0;
gsef->min_value = 0;
gsef->max_value = SIZE_MAX_VALUE;
@ -240,7 +244,8 @@ gimp_size_entry_new (gint number_of_fields,
1.0, 10.0, 0.0);
gsef->value_spinbutton =
gtk_spin_button_new (GTK_ADJUSTMENT (gsef->value_adjustment), 1.0,
MIN (gimp_unit_get_digits (unit), 5) + 1);
(unit == UNIT_PERCENT) ? 2 :
(MIN (gimp_unit_get_digits (unit), 5) + 1));
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(gsef->value_spinbutton),
GTK_SHADOW_NONE);
gtk_widget_set_usize (gsef->value_spinbutton, spinbutton_usize, 0);
@ -303,7 +308,8 @@ gimp_size_entry_new (gint number_of_fields,
}
gse->unitmenu = gimp_unit_menu_new (unit_format, unit,
gse->menu_show_pixels, FALSE, TRUE);
gse->menu_show_pixels,
gse->menu_show_percent, TRUE);
gtk_table_attach_defaults (GTK_TABLE (gse), gse->unitmenu,
i+2, i+3,
gse->show_refval+1, gse->show_refval+2);
@ -340,6 +346,8 @@ gimp_size_entry_add_field (GimpSizeEntry *gse,
gsef->gse = gse;
gsef->index = 0;
gsef->resolution = 1.0; /* just to avoid division by zero */
gsef->lower = 0.0;
gsef->upper = 100.0;
gsef->value = 0;
gsef->min_value = 0;
gsef->max_value = SIZE_MAX_VALUE;
@ -443,6 +451,29 @@ gimp_size_entry_set_resolution (GimpSizeEntry *gse,
}
/* percent stuff ***********/
void
gimp_size_entry_set_size (GimpSizeEntry *gse,
gint field,
gfloat lower,
gfloat upper)
{
GimpSizeEntryField *gsef;
g_return_if_fail (gse != NULL);
g_return_if_fail (GIMP_IS_SIZE_ENTRY (gse));
g_return_if_fail ((field >= 0) && (field < gse->number_of_fields));
g_return_if_fail (lower < upper);
gsef = (GimpSizeEntryField*) g_slist_nth_data (gse->fields, field);
gsef->lower = lower;
gsef->upper = upper;
gimp_size_entry_set_refval (gse, field, gsef->refval);
}
/* value stuff ***********/
void
@ -476,18 +507,32 @@ gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse,
case GIMP_SIZE_ENTRY_UPDATE_NONE:
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gse->unit) /* unit != UNIT_PIXEL */
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit),
gsef->max_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit));
else /* unit == UNIT_PIXEL */
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value,
gsef->max_value);
switch (gse->unit)
{
case UNIT_PIXEL:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->lower +
(gsef->upper - gsef->lower) *
gsef->min_value / 100,
gsef->lower +
(gsef->upper - gsef->lower) *
gsef->max_value / 100);
break;
case UNIT_PERCENT:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value,
gsef->max_value);
break;
default:
gimp_size_entry_set_refval_boundaries (gse, field,
gsef->min_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit),
gsef->max_value *
gsef->resolution /
gimp_unit_get_factor (gse->unit));
break;
}
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gimp_size_entry_set_refval_boundaries (gse, field,
@ -531,23 +576,31 @@ gimp_size_entry_update_value (GimpSizeEntryField *gsef,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gsef->gse->unit) /* unit != UNIT_PIXEL */
gsef->refval = gsef->value * gsef->resolution /
gimp_unit_get_factor (gsef->gse->unit);
else /* unit == UNIT_PIXEL */
gsef->refval = value;
switch (gsef->gse->unit)
{
case UNIT_PIXEL:
gsef->refval = value;
break;
case UNIT_PERCENT:
gsef->refval =
gsef->lower + (gsef->upper - gsef->lower) * value / 100;
break;
default:
gsef->refval = gsef->value * gsef->resolution /
gimp_unit_get_factor (gsef->gse->unit);
break;
}
if (gsef->gse->show_refval)
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->refval_adjustment),
gsef->refval);
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gsef->refval = value * gimp_unit_get_factor (gsef->gse->unit);
if (gsef->gse->show_refval)
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->refval_adjustment),
gsef->refval);
break;
default:
break;
}
@ -632,20 +685,33 @@ gimp_size_entry_set_refval_boundaries (GimpSizeEntry *gse,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gse->unit) /* unit != UNIT_PIXEL */
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution,
gsef->max_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution);
else /* unit == UNIT_PIXEL */
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval,
gsef->max_refval);
switch (gse->unit)
{
case UNIT_PIXEL:
gimp_size_entry_set_value_boundaries (gse, field,
100 * (gsef->min_refval -
gsef->lower) /
(gsef->upper - gsef->lower),
100 * (gsef->max_refval -
gsef->lower) /
(gsef->upper - gsef->lower));
break;
case UNIT_PERCENT:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval,
gsef->max_refval);
break;
default:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution,
gsef->max_refval *
gimp_unit_get_factor (gse->unit) /
gsef->resolution);
break;
}
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gimp_size_entry_set_value_boundaries (gse, field,
gsef->min_refval /
@ -716,15 +782,23 @@ gimp_size_entry_update_refval (GimpSizeEntryField *gsef,
break;
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
if (gsef->gse->unit) /* unit != UNIT_PIXEL */
gsef->value = gsef->refval * gimp_unit_get_factor (gsef->gse->unit) /
gsef->resolution;
else /* unit == UNIT_PIXEL */
gsef->value = refval;
switch (gsef->gse->unit)
{
case UNIT_PIXEL:
gsef->value = refval;
break;
case UNIT_PERCENT:
gsef->value =
100 * (refval - gsef->lower) / (gsef->upper - gsef->lower);
break;
default:
gsef->value = gsef->refval * gimp_unit_get_factor (gsef->gse->unit) /
gsef->resolution;
break;
}
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->value_adjustment),
gsef->value);
break;
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
gsef->value = refval / gimp_unit_get_factor (gsef->gse->unit);
gtk_adjustment_set_value (GTK_ADJUSTMENT (gsef->value_adjustment),
@ -810,6 +884,9 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse,
if (unit == UNIT_PIXEL)
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
gsef->refval_digits);
else if (unit == UNIT_PERCENT)
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
2);
else
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
MIN(gimp_unit_get_digits (unit), 5) + 1);
@ -835,6 +912,7 @@ gimp_size_entry_set_unit (GimpSizeEntry *gse,
g_return_if_fail (gse != NULL);
g_return_if_fail (GIMP_IS_SIZE_ENTRY (gse));
g_return_if_fail (gse->menu_show_pixels || (unit != UNIT_PIXEL));
g_return_if_fail (gse->menu_show_percent || (unit != UNIT_PERCENT));
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (gse->unitmenu), unit);
gimp_size_entry_update_unit (gse, unit);

View File

@ -117,7 +117,6 @@ void gimp_size_entry_add_field (GimpSizeEntry *gse,
/* this one is just a convenience function if you want to add labels
* to the empty cells of the widget
* (take care not to specify cells which already have a widget ;-)
*/
void gimp_size_entry_attach_label (GimpSizeEntry *gse,
gchar *text,
@ -137,10 +136,20 @@ void gimp_size_entry_set_resolution (GimpSizeEntry *gse,
gfloat resolution,
guint keep_size);
/* this one sets the values (in pixels) which will be treated as
* 0% and 100% when we want "percent" in the unit menu
*
* does nothing if update_policy != GIMP_SIZE_ENTRY_UPDATE_SIZE
*/
void gimp_size_entry_set_size (GimpSizeEntry *gse,
gint field,
gfloat lower,
gfloat upper);
/* these functions set/return the value in the units the user selected
* note that in some cases where the caller chooses not to have the
* reference value row and the user selected the reference unit
* the both values 'value' and 'refvalue' will be the same
* the both values 'value' and 'refval' will be the same
*/
void gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse,
gint field,

View File

@ -129,9 +129,11 @@ gimp_unit_menu_new (gchar *format,
GUnit u;
g_return_val_if_fail ((unit >= UNIT_PIXEL) &&
(unit < gimp_unit_get_number_of_units ()), NULL);
(unit < gimp_unit_get_number_of_units ()) ||
(unit == UNIT_PERCENT), NULL);
if (unit >= gimp_unit_get_number_of_built_in_units ())
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
(unit != UNIT_PERCENT))
show_custom = TRUE;
gum = gtk_type_new (gimp_unit_menu_get_type ());
@ -145,6 +147,29 @@ gimp_unit_menu_new (gchar *format,
u < gimp_unit_get_number_of_built_in_units();
u++)
{
/* special cases "pixels" and "percent" */
if (u == UNIT_INCH)
{
if (show_percent)
{
menuitem =
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, UNIT_PERCENT));
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem),
"gimp_unit_menu", (gpointer) UNIT_PERCENT);
gtk_widget_show (menuitem);
}
if (show_pixels || show_percent)
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
}
}
menuitem =
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, u));
gtk_menu_append (GTK_MENU (menu), menuitem);
@ -152,17 +177,10 @@ gimp_unit_menu_new (gchar *format,
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu", (gpointer)u);
gtk_widget_show (menuitem);
/* add a separator after "pixels" */
if (u == UNIT_PIXEL)
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
}
}
if (unit >= gimp_unit_get_number_of_built_in_units ())
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
(unit != UNIT_PERCENT))
{
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
@ -182,26 +200,26 @@ gimp_unit_menu_new (gchar *format,
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
menuitem =
gtk_menu_item_new_with_label (_("More..."));
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
(GtkSignalFunc) gimp_unit_menu_callback, gum);
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
(gpointer)65536);
(gpointer) (UNIT_PERCENT + 1));
gtk_widget_show(menuitem);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (gum), menu);
gum->unit = unit;
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(unit == UNIT_PIXEL) ? 0 :
(show_pixels ?
((unit < UNIT_END) ? unit + 1 : UNIT_END + 2) :
((unit < UNIT_END) ? unit - 1 : UNIT_END)));
((unit == UNIT_PERCENT) ? (show_pixels ? 1 : 0) :
(((show_pixels || show_percent) ? 2 : 0) +
((show_pixels && show_percent) ? 1 : 0) +
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
return GTK_WIDGET (gum);
}
@ -216,17 +234,19 @@ gimp_unit_menu_set_unit (GimpUnitMenu *gum,
g_return_if_fail (gum != NULL);
g_return_if_fail (GIMP_IS_UNIT_MENU (gum));
g_return_if_fail ((unit >= UNIT_PIXEL) &&
((unit > UNIT_PIXEL) || gum->show_pixels) &&
(unit < gimp_unit_get_number_of_units ()));
g_return_if_fail (((unit >= UNIT_PIXEL) &&
((unit > UNIT_PIXEL) || gum->show_pixels) &&
(unit < gimp_unit_get_number_of_units ())) ||
((unit == UNIT_PERCENT) && gum->show_percent));
if (unit == gum->unit)
return;
items = GTK_MENU_SHELL (GTK_OPTION_MENU (gum)->menu)->children;
user_unit = UNIT_END + (gum->show_pixels ? 2 : 0);
user_unit = UNIT_END + (((gum->show_pixels || gum->show_percent) ? 2 : 0) +
((gum->show_pixels && gum->show_percent) ? 1 : 0));
if (unit >= UNIT_END)
if ((unit >= UNIT_END) && (unit != UNIT_PERCENT))
{
if ((g_list_length (items) - 3) >= user_unit)
{
@ -256,9 +276,13 @@ gimp_unit_menu_set_unit (GimpUnitMenu *gum,
gum->unit = unit;
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(unit == UNIT_PIXEL) ? 0 :
(gum->show_pixels ?
((unit < UNIT_END) ? unit + 1 : UNIT_END + 2) :
((unit < UNIT_END) ? unit - 1 : UNIT_END)));
((unit == UNIT_PERCENT) ?
(gum->show_pixels ? 1 : 0) :
(((gum->show_pixels ||
gum->show_percent) ? 2 : 0) +
((gum->show_pixels &&
gum->show_percent) ? 1 : 0) +
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
}
GUnit
@ -545,15 +569,18 @@ gimp_unit_menu_callback (GtkWidget *widget,
return;
/* was "More..." selected? */
if (new_unit == 65536)
if (new_unit == (UNIT_PERCENT + 1))
{
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
(gum->unit == UNIT_PIXEL) ? 0 :
(gum->show_pixels ?
((gum->unit < UNIT_END) ?
gum->unit + 1 : UNIT_END + 2) :
((gum->unit < UNIT_END) ?
gum->unit - 1 : UNIT_END)));
((gum->unit == UNIT_PERCENT) ?
(gum->show_pixels ? 1 : 0) :
((gum->show_pixels ||
gum->show_percent ? 2 : 0) +
(gum->show_pixels &&
gum->show_percent ? 1 : 0) +
((gum->unit < UNIT_END) ?
gum->unit - 1 : UNIT_END))));
if (! gum->selection)
gimp_unit_menu_create_selection (gum);
return;