Commit 7d148f02 authored by Manish Singh's avatar Manish Singh

Added Sven's patch for the scale and resize dialogs

Added Raph's patch for the transperancy blur problem
parent ff7139d3
Sun Dec 7 17:05:32 PST 1997
* added Sven Neumann's patch to the scale and resize dialogs for ratio input fields (app/resize.h, app/resize.c)
* added Raph Levien's patch for the transperancy blur problem
(app/convolve.c, app/gimage.h, app/gimage.c, paint_core.h,
paint_core.c, paint_funcs.h, paint_funcs.c)
Sun Dec 7 15:27:14 EST 1997 Adrian Likins <adrian@gimp.org>
* fixed refract.c to look for megawidget.h in the proper place
......
......@@ -266,6 +266,11 @@ convolve_motion (PaintCore *paint_core,
/* if the source has no alpha, then add alpha pixels */
if (!drawable_has_alpha (drawable_id))
{
/* note: this architecture needlessly convolves the totally-
opaque alpha channel. A faster approach would be to keep
tempPR the same number of bytes as srcPR, and extend the
paint_core_replace_canvas API to handle non-alpha images. */
tempPR.bytes = srcPR.bytes + 1;
tempPR.x = 0; tempPR.y = 0;
tempPR.w = area->width;
......@@ -287,6 +292,13 @@ convolve_motion (PaintCore *paint_core,
tempPR.data = temp_data;
copy_region (&srcPR, &tempPR);
tempPR.x = 0; tempPR.y = 0;
tempPR.w = area->width;
tempPR.h = area->height;
tempPR.data = temp_data;
multiply_alpha_region (&tempPR);
}
tempPR.x = 0; tempPR.y = 0;
......@@ -298,6 +310,9 @@ convolve_motion (PaintCore *paint_core,
convolve_region (&tempPR, &destPR, matrix, matrix_size,
matrix_divisor, NORMAL);
if (drawable_has_alpha (drawable_id))
separate_alpha_region (&destPR);
/* Free the allocated temp space */
g_free (temp_data);
}
......@@ -311,9 +326,9 @@ convolve_motion (PaintCore *paint_core,
}
/* paste the newly painted canvas to the gimage which is being worked on */
paint_core_paste_canvas (paint_core, drawable_id, OPAQUE,
paint_core_replace_canvas (paint_core, drawable_id, OPAQUE,
(int) (get_brush_opacity () * 255),
NORMAL_MODE, SOFT, INCREMENTAL);
SOFT, INCREMENTAL);
}
static void
......
......@@ -31,6 +31,8 @@ struct _ResizePrivate
{
GtkWidget *width_text;
GtkWidget *height_text;
GtkWidget *ratio_x_text;
GtkWidget *ratio_y_text;
GtkWidget *off_x_text;
GtkWidget *off_y_text;
GtkWidget *drawing_area;
......@@ -50,6 +52,8 @@ static void off_x_update (GtkWidget *w, gpointer data);
static void off_y_update (GtkWidget *w, gpointer data);
static void width_update (GtkWidget *w, gpointer data);
static void height_update (GtkWidget *w, gpointer data);
static void ratio_x_update (GtkWidget *w, gpointer data);
static void ratio_y_update (GtkWidget *w, gpointer data);
static void constrain_update (GtkWidget *w, gpointer data);
static gint resize_events (GtkWidget *area, GdkEvent *event);
......@@ -68,6 +72,7 @@ resize_widget_new (ResizeType type,
GtkWidget *constrain;
GtkWidget *table;
char size[12];
char ratio_text[12];
table = NULL;
......@@ -77,6 +82,8 @@ resize_widget_new (ResizeType type,
resize->private_part = private;
resize->width = width;
resize->height = height;
resize->ratio_x = 1.0;
resize->ratio_y = 1.0;
resize->off_x = 0;
resize->off_y = 0;
private->old_width = width;
......@@ -95,11 +102,11 @@ resize_widget_new (ResizeType type,
{
case ScaleWidget:
resize->resize_widget = gtk_frame_new ("Scale");
table = gtk_table_new (2, 2, TRUE);
table = gtk_table_new (4, 2, TRUE);
break;
case ResizeWidget:
resize->resize_widget = gtk_frame_new ("Resize");
table = gtk_table_new (4, 2, TRUE);
table = gtk_table_new (6, 2, TRUE);
break;
}
gtk_frame_set_shadow_type (GTK_FRAME (resize->resize_widget), GTK_SHADOW_ETCHED_IN);
......@@ -146,17 +153,51 @@ resize_widget_new (ResizeType type,
resize);
gtk_widget_show (private->height_text);
/* the x scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_x);
label = gtk_label_new ("X ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_x_text, 1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_x_text), "changed",
(GtkSignalFunc) ratio_x_update,
resize);
gtk_widget_show (private->ratio_x_text);
/* the y scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_y);
label = gtk_label_new ("Y ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_y_text, 1, 2, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_y_text), "changed",
(GtkSignalFunc) ratio_y_update,
resize);
gtk_widget_show (private->ratio_y_text);
if (type == ResizeWidget)
{
/* the off_x label and entry */
sprintf (size, "%d", 0);
label = gtk_label_new ("X Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_x_text, 1, 2, 2, 3,
gtk_table_attach (GTK_TABLE (table), private->off_x_text, 1, 2, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
......@@ -169,11 +210,11 @@ resize_widget_new (ResizeType type,
sprintf (size, "%d", 0);
label = gtk_label_new ("Y Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_y_text, 1, 2, 3, 4,
gtk_table_attach (GTK_TABLE (table), private->off_y_text, 1, 2, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
......@@ -425,6 +466,7 @@ width_update (GtkWidget *w,
double ratio;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
......@@ -432,6 +474,14 @@ width_update (GtkWidget *w,
resize->width = atoi (str);
ratio = (double) resize->width / (double) private->old_width;
resize->ratio_x = ratio;
sprintf (ratio_text, "%0.4f", ratio);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
......@@ -445,7 +495,6 @@ width_update (GtkWidget *w,
if (private->constrain && resize->width != 0)
{
private->constrain = FALSE;
ratio = (double) resize->width / (double) private->old_width;
new_height = (int) (private->old_height * ratio);
if (new_height == 0) new_height = 1;
......@@ -458,6 +507,12 @@ width_update (GtkWidget *w,
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
resize->ratio_y = ratio;
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
......@@ -485,6 +540,7 @@ height_update (GtkWidget *w,
double ratio;
int new_width;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
......@@ -492,6 +548,13 @@ height_update (GtkWidget *w,
resize->height = atoi (str);
ratio = (double) resize->height / (double) private->old_height;
resize->ratio_y = ratio;
sprintf (ratio_text, "%0.4f", ratio);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
......@@ -517,6 +580,176 @@ height_update (GtkWidget *w,
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
resize->ratio_x = ratio;
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static void
ratio_x_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int new_width;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->ratio_x = atof (str);
new_width = (int) ((double) private->old_width * resize->ratio_x);
if (new_width != resize->width)
{
resize->width = new_width;
sprintf (size, "%d", new_width);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
sprintf (size, "%d", resize->off_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_x_text), data);
}
}
if (private->constrain && resize->width != 0)
{
private->constrain = FALSE;
resize->ratio_y = resize->ratio_x;
new_height = (int) (private->old_height * resize->ratio_y);
if (new_height == 0) new_height = 1;
if (new_height != resize->height)
{
resize->height = new_height;
sprintf (size, "%d", resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->height_text), data);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
sprintf (ratio_text, "%0.4f", resize->ratio_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
}
private->constrain = TRUE;
}
resize_draw (resize);
}
static void
ratio_y_update (GtkWidget *w,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
char *str;
int new_width;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
str = gtk_entry_get_text (GTK_ENTRY (w));
resize->ratio_y = atof (str);
new_height = (int) ((double) private->old_height * resize->ratio_y);
if (new_height != resize->height)
{
resize->height = new_height;
sprintf (size, "%d", new_height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->height_text), data);
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
if (resize->type == ResizeWidget)
{
resize->off_y = resize_bound_off_y (resize, (resize->height - private->old_height) / 2);
sprintf (size, "%d", resize->off_y);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->off_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->off_y_text), data);
}
}
if (private->constrain && resize->height != 0)
{
private->constrain = FALSE;
resize->ratio_x = resize->ratio_y;
new_width = (int) (private->old_width * resize->ratio_x);
if (new_width == 0) new_width = 1;
if (new_width != resize->width)
{
resize->width = new_width;
sprintf (size, "%d", resize->width);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->width_text), data);
gtk_entry_set_text (GTK_ENTRY (private->width_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->width_text), data);
sprintf (ratio_text, "%0.4f", resize->ratio_x);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
......
......@@ -34,6 +34,8 @@ struct _Resize
ResizeType type;
int width;
int height;
double ratio_x;
double ratio_y;
int off_x;
int off_y;
......
......@@ -584,6 +584,126 @@ gimage_apply_image (GImage *gimage, int drawable_id, PixelRegion *src2PR,
opacity, mode, active, operation);
}
/* Similar to gimage_apply_image but works in "replace" mode (i.e.
transparent pixels in src2 make the result transparent rather
than opaque.
Takes an additional mask pixel region as well.
*/
void
gimage_replace_image (GImage *gimage, int drawable_id, PixelRegion *src2PR,
int undo, int opacity,
PixelRegion *maskPR,
int x, int y)
{
Channel * mask;
int x1, y1, x2, y2;
int offset_x, offset_y;
PixelRegion src1PR, destPR;
PixelRegion mask2PR, tempPR;
unsigned char *temp_data;
int operation;
int active [MAX_CHANNELS];
/* get the selection mask if one exists */
mask = (gimage_mask_is_empty (gimage)) ?
NULL : gimage_get_mask (gimage);
/* configure the active channel array */
gimage_get_active_channels (gimage, drawable_id, active);
/* determine what sort of operation is being attempted and
* if it's actually legal...
*/
operation = valid_combinations [drawable_type (drawable_id)][src2PR->bytes];
if (operation == -1)
{
warning ("gimage_apply_image sent illegal parameters\n");
return;
}
/* get the layer offsets */
drawable_offsets (drawable_id, &offset_x, &offset_y);
/* make sure the image application coordinates are within gimage bounds */
x1 = BOUNDS (x, 0, drawable_width (drawable_id));
y1 = BOUNDS (y, 0, drawable_height (drawable_id));
x2 = BOUNDS (x + src2PR->w, 0, drawable_width (drawable_id));
y2 = BOUNDS (y + src2PR->h, 0, drawable_height (drawable_id));
if (mask)
{
/* make sure coordinates are in mask bounds ...
* we need to add the layer offset to transform coords
* into the mask coordinate system
*/
x1 = BOUNDS (x1, -offset_x, mask->width - offset_x);
y1 = BOUNDS (y1, -offset_y, mask->height - offset_y);
x2 = BOUNDS (x2, -offset_x, mask->width - offset_x);
y2 = BOUNDS (y2, -offset_y, mask->height - offset_y);
}
/* If the calling procedure specified an undo step... */
if (undo)
drawable_apply_image (drawable_id, x1, y1, x2, y2, NULL, FALSE);
/* configure the pixel regions
* If an alternative to using the drawable's data as src1 was provided...
*/
pixel_region_init (&src1PR, drawable_data (drawable_id), x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, drawable_data (drawable_id), x1, y1, (x2 - x1), (y2 - y1), TRUE);
pixel_region_resize (src2PR, src2PR->x + (x1 - x), src2PR->y + (y1 - y), (x2 - x1), (y2 - y1));
if (mask)
{
int mx, my;
/* configure the mask pixel region
* don't use x1 and y1 because they are in layer
* coordinate system. Need mask coordinate system
*/
mx = x1 + offset_x;
my = y1 + offset_y;
pixel_region_init (&mask2PR, mask->tiles, mx, my, (x2 - x1), (y2 - y1), FALSE);
tempPR.bytes = 1;
tempPR.x = 0;
tempPR.y = 0;
tempPR.w = x2 - x1;
tempPR.h = y2 - y1;
tempPR.rowstride = mask2PR.rowstride;
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
tempPR.data = temp_data;
copy_region (&mask2PR, &tempPR);
/* apparently, region operations can mutate some PR data. */
tempPR.x = 0;
tempPR.y = 0;
tempPR.w = x2 - x1;
tempPR.h = y2 - y1;
tempPR.data = temp_data;
apply_mask_to_region (&tempPR, maskPR, OPAQUE);
tempPR.x = 0;
tempPR.y = 0;
tempPR.w = x2 - x1;
tempPR.h = y2 - y1;
tempPR.data = temp_data;
combine_regions_replace (&src1PR, src2PR, &destPR, &tempPR, NULL,
opacity, active, operation);
g_free (temp_data);
}
else
combine_regions_replace (&src1PR, src2PR, &destPR, maskPR, NULL,
opacity, active, operation);
}
void
gimage_get_foreground (GImage *gimage, int drawable_id, unsigned char *fg)
......
......@@ -163,6 +163,8 @@ void gimage_free_shadow (GImage *);
void gimage_delete (GImage *);
void gimage_apply_image (GImage *, int, PixelRegion *, int, int, int,
TileManager *, int, int);
void gimage_replace_image (GImage *, int, PixelRegion *, int, int,
PixelRegion *, int, int);
void gimage_get_foreground (GImage *, int, unsigned char *);
void gimage_get_background (GImage *, int, unsigned char *);
void gimage_get_color (GImage *, int, unsigned char *,
......
......@@ -31,6 +31,8 @@ struct _ResizePrivate
{
GtkWidget *width_text;
GtkWidget *height_text;
GtkWidget *ratio_x_text;
GtkWidget *ratio_y_text;
GtkWidget *off_x_text;
GtkWidget *off_y_text;
GtkWidget *drawing_area;
......@@ -50,6 +52,8 @@ static void off_x_update (GtkWidget *w, gpointer data);
static void off_y_update (GtkWidget *w, gpointer data);
static void width_update (GtkWidget *w, gpointer data);
static void height_update (GtkWidget *w, gpointer data);
static void ratio_x_update (GtkWidget *w, gpointer data);
static void ratio_y_update (GtkWidget *w, gpointer data);
static void constrain_update (GtkWidget *w, gpointer data);
static gint resize_events (GtkWidget *area, GdkEvent *event);
......@@ -68,6 +72,7 @@ resize_widget_new (ResizeType type,
GtkWidget *constrain;
GtkWidget *table;
char size[12];
char ratio_text[12];
table = NULL;
......@@ -77,6 +82,8 @@ resize_widget_new (ResizeType type,
resize->private_part = private;
resize->width = width;
resize->height = height;
resize->ratio_x = 1.0;
resize->ratio_y = 1.0;
resize->off_x = 0;
resize->off_y = 0;
private->old_width = width;
......@@ -95,11 +102,11 @@ resize_widget_new (ResizeType type,
{
case ScaleWidget:
resize->resize_widget = gtk_frame_new ("Scale");
table = gtk_table_new (2, 2, TRUE);
table = gtk_table_new (4, 2, TRUE);
break;
case ResizeWidget:
resize->resize_widget = gtk_frame_new ("Resize");
table = gtk_table_new (4, 2, TRUE);
table = gtk_table_new (6, 2, TRUE);
break;
}
gtk_frame_set_shadow_type (GTK_FRAME (resize->resize_widget), GTK_SHADOW_ETCHED_IN);
......@@ -146,17 +153,51 @@ resize_widget_new (ResizeType type,
resize);
gtk_widget_show (private->height_text);
/* the x scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_x);
label = gtk_label_new ("X ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_x_text, 1, 2, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_x_text), "changed",
(GtkSignalFunc) ratio_x_update,
resize);
gtk_widget_show (private->ratio_x_text);
/* the y scale ratio label and entry */
sprintf (ratio_text, "%0.4f", resize->ratio_y);
label = gtk_label_new ("Y ratio:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->ratio_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->ratio_y_text, 1, 2, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->ratio_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_connect (GTK_OBJECT (private->ratio_y_text), "changed",
(GtkSignalFunc) ratio_y_update,
resize);
gtk_widget_show (private->ratio_y_text);
if (type == ResizeWidget)
{
/* the off_x label and entry */
sprintf (size, "%d", 0);
label = gtk_label_new ("X Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_x_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_x_text, 1, 2, 2, 3,
gtk_table_attach (GTK_TABLE (table), private->off_x_text, 1, 2, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_x_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_x_text), size);
......@@ -169,11 +210,11 @@ resize_widget_new (ResizeType type,
sprintf (size, "%d", 0);
label = gtk_label_new ("Y Offset:");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_show (label);
private->off_y_text = gtk_entry_new ();
gtk_table_attach (GTK_TABLE (table), private->off_y_text, 1, 2, 3, 4,
gtk_table_attach (GTK_TABLE (table), private->off_y_text, 1, 2, 5, 6,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 2, 2);
gtk_widget_set_usize (private->off_y_text, TEXT_WIDTH, 25);
gtk_entry_set_text (GTK_ENTRY (private->off_y_text), size);
......@@ -425,6 +466,7 @@ width_update (GtkWidget *w,
double ratio;
int new_height;
char size[12];
char ratio_text[12];
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
......@@ -432,6 +474,14 @@ width_update (GtkWidget *w,
resize->width = atoi (str);
ratio = (double) resize->width / (double) private->old_width;
resize->ratio_x = ratio;
sprintf (ratio_text, "%0.4f", ratio);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_x_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_x_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_text), data);
if (resize->type == ResizeWidget)
{
resize->off_x = resize_bound_off_x (resize, (resize->width - private->old_width) / 2);
......@@ -445,7 +495,6 @@ width_update (GtkWidget *w,
if (private->constrain && resize->width != 0)
{
private->constrain = FALSE;
ratio = (double) resize->width / (double) private->old_width;
new_height = (int) (private->old_height * ratio);
if (new_height == 0) new_height = 1;
......@@ -458,6 +507,12 @@ width_update (GtkWidget *w,
gtk_entry_set_text (GTK_ENTRY (private->height_text), size);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->height_text), data);
resize->ratio_y = ratio;
gtk_signal_handler_block_by_data (GTK_OBJECT (private->ratio_y_text), data);
gtk_entry_set_text (GTK_ENTRY (private->ratio_y_text), ratio_text);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_text), data);