Commit 52252cf0 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

started to redo the Resize dialog in the style of the new Scale dialog.

2004-10-27  Sven Neumann  <sven@gimp.org>

	* app/dialogs/resize-dialog.[ch]: started to redo the Resize
	dialog in the style of the new Scale dialog. Only halfway done but
	at least the new API is there.

	* app/actions/image-commands.c
	* app/actions/layers-commands.c: changed accordingly.

	* app/dialogs/image-scale-dialog.c: cosmetics.
parent 47ce269d
2004-10-27 Sven Neumann <sven@gimp.org>
* app/dialogs/resize-dialog.[ch]: started to redo the Resize
dialog in the style of the new Scale dialog. Only halfway done but
at least the new API is there.
* app/actions/image-commands.c
* app/actions/layers-commands.c: changed accordingly.
* app/dialogs/image-scale-dialog.c: cosmetics.
2004-10-27 DindinX <dindinx@gimp.org>
 
* plug-ins/gfig/*[ch]: preliminary cleanups: removed all trailing
......
......@@ -42,6 +42,7 @@
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
......@@ -64,19 +65,22 @@ typedef struct _ImageResizeOptions ImageResizeOptions;
struct _ImageResizeOptions
{
ResizeDialog *dialog;
GimpContext *context;
GimpDisplay *gdisp;
GimpImage *gimage;
};
/* local function prototypes */
static void image_resize_callback (GtkWidget *widget,
static void image_resize_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
gint offset_x,
gint offset_y,
gpointer data);
static void image_scale_callback (ImageScaleDialog *dialog);
static void image_merge_layers_response (GtkWidget *widget,
gint response_id,
ImageMergeLayersDialog *dialog);
......@@ -165,39 +169,35 @@ image_resize_cmd_callback (GtkAction *action,
gpointer data)
{
ImageResizeOptions *options;
GimpDisplay *gdisp;
GimpImage *gimage;
GtkWidget *widget;
GimpDisplay *gdisp;
GtkWidget *dialog;
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
return_if_no_display (gdisp, data);
gimage = gdisp->gimage;
options = g_new0 (ImageResizeOptions, 1);
options->context = action_data_get_context (data);
options->gdisp = gdisp;
options->gimage = gimage;
options->dialog =
resize_dialog_new (GIMP_VIEWABLE (gimage), gdisp->shell,
RESIZE_DIALOG,
gimage->width,
gimage->height,
gimage->xresolution,
gimage->yresolution,
GIMP_DISPLAY_SHELL (gdisp->shell)->unit,
G_CALLBACK (image_resize_callback),
options);
options->context = action_data_get_context (data);
dialog = resize_dialog_new (GIMP_VIEWABLE (gimage),
_("Set Image Canvas Size"), "gimp-image-resize",
widget,
gimp_standard_help_func, GIMP_HELP_IMAGE_RESIZE,
GIMP_DISPLAY_SHELL (gdisp->shell)->unit,
image_resize_callback,
options);
g_signal_connect_object (gdisp, "disconnect",
G_CALLBACK (gtk_widget_destroy),
options->dialog->shell,
G_CONNECT_SWAPPED);
dialog, G_CONNECT_SWAPPED);
g_object_weak_ref (G_OBJECT (options->dialog->shell),
(GWeakNotify) g_free,
options);
g_object_weak_ref (G_OBJECT (dialog),
(GWeakNotify) g_free, options);
gtk_widget_show (options->dialog->shell);
gtk_widget_show (dialog);
}
void
......@@ -387,41 +387,46 @@ image_configure_grid_cmd_callback (GtkAction *action,
/* private functions */
static void
image_resize_callback (GtkWidget *widget,
gpointer data)
image_resize_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
gint offset_x,
gint offset_y,
gpointer data)
{
ImageResizeOptions *options = data;
gtk_widget_set_sensitive (options->dialog->shell, FALSE);
if (options->dialog->width > 0 &&
options->dialog->height > 0)
if (width > 0 && height > 0)
{
GimpImage *image = GIMP_IMAGE (viewable);
GimpDisplay *gdisp = options->gdisp;
GimpContext *context = options->context;
GimpProgress *progress;
progress = gimp_progress_start (GIMP_PROGRESS (options->gdisp),
gtk_widget_destroy (dialog);
if (width == image->width && height == image->height)
return;
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
_("Resizing..."), FALSE);
gimp_image_resize (options->gimage,
options->context,
options->dialog->width,
options->dialog->height,
options->dialog->offset_x,
options->dialog->offset_y,
gimp_image_resize (image,
context,
width, height, offset_x, offset_y,
progress);
if (progress)
gimp_progress_end (progress);
gimp_image_flush (options->gimage);
gimp_image_flush (image);
}
else
{
g_message (_("Resize Error: Both width and height must be "
"greater than zero."));
}
gtk_widget_destroy (options->dialog->shell);
}
static void
......
......@@ -96,16 +96,6 @@ static const GimpLayerModeEffects layer_modes[] =
};
typedef struct _ResizeLayerOptions ResizeLayerOptions;
struct _ResizeLayerOptions
{
GimpLayer *layer;
GimpContext *context;
ResizeDialog *dialog;
};
/* local function prototypes */
static void layers_new_layer_response (GtkWidget *widget,
......@@ -117,6 +107,7 @@ static void layers_edit_layer_response (GtkWidget *widget,
static void layers_add_mask_response (GtkWidget *widget,
gint response_id,
LayerAddMaskDialog *dialog);
static void layers_scale_layer_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
......@@ -127,8 +118,14 @@ static void layers_scale_layer_callback (GtkWidget *dialog,
gdouble yresolution,
GimpUnit resolution_unit,
gpointer data);
static void layers_resize_layer_callback (GtkWidget *widget,
static void layers_resize_layer_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
gint offset_x,
gint offset_y,
gpointer data);
static gint layers_mode_index (GimpLayerModeEffects layer_mode);
......@@ -459,39 +456,27 @@ void
layers_resize_cmd_callback (GtkAction *action,
gpointer data)
{
ResizeLayerOptions *options;
GimpImage *gimage;
GimpLayer *layer;
GtkWidget *widget;
GimpDisplay *gdisp;
GimpDisplay *gdisp;
GimpImage *gimage;
GimpLayer *layer;
GtkWidget *widget;
GtkWidget *dialog;
return_if_no_layer (gimage, layer, data);
return_if_no_widget (widget, data);
gdisp = GIMP_IS_DISPLAY (data) ? data : NULL;
options = g_new0 (ResizeLayerOptions, 1);
options->context = action_data_get_context (data);
options->layer = layer;
options->dialog =
resize_dialog_new (GIMP_VIEWABLE (layer), widget,
RESIZE_DIALOG,
gimp_item_width (GIMP_ITEM (layer)),
gimp_item_height (GIMP_ITEM (layer)),
gimage->xresolution,
gimage->yresolution,
(gdisp ?
GIMP_DISPLAY_SHELL (gdisp->shell)->unit :
GIMP_UNIT_PIXEL),
G_CALLBACK (layers_resize_layer_callback),
options);
g_object_weak_ref (G_OBJECT (options->dialog->shell),
(GWeakNotify) g_free,
options);
gtk_widget_show (options->dialog->shell);
dialog = resize_dialog_new (GIMP_VIEWABLE (layer),
_("Set Layer Boundary Size"), "gimp-layer-resize",
widget,
gimp_standard_help_func, GIMP_HELP_LAYER_RESIZE,
(gdisp ?
GIMP_DISPLAY_SHELL (gdisp->shell)->unit :
GIMP_UNIT_PIXEL),
layers_resize_layer_callback,
action_data_get_context (data));
gtk_widget_show (dialog);
}
void
......@@ -989,27 +974,30 @@ layers_scale_layer_callback (GtkWidget *dialog,
}
static void
layers_resize_layer_callback (GtkWidget *widget,
gpointer data)
layers_resize_layer_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
gint offset_x,
gint offset_y,
gpointer data)
{
ResizeLayerOptions *options = data;
GimpContext *context = GIMP_CONTEXT (data);
if (options->dialog->width > 0 && options->dialog->height > 0)
if (width > 0 && height > 0)
{
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (options->layer));
GimpItem *item = GIMP_ITEM (viewable);
gtk_widget_set_sensitive (options->dialog->shell, FALSE);
gtk_widget_destroy (dialog);
gimp_item_resize (GIMP_ITEM (options->layer),
options->context,
options->dialog->width,
options->dialog->height,
options->dialog->offset_x,
options->dialog->offset_y);
if (width == gimp_item_width (item) && height == gimp_item_height (item))
return;
gimp_image_flush (gimage);
gimp_item_resize (item,
context,
width, height, offset_x, offset_y);
gtk_widget_destroy (options->dialog->shell);
gimp_image_flush (gimp_item_get_image (item));
}
else
{
......
......@@ -87,15 +87,15 @@ image_scale_dialog_new (GimpImage *image,
dialog->gimage = image;
dialog->gdisp = display;
dialog->context = context;
dialog->dialog =
scale_dialog_new (GIMP_VIEWABLE (display->gimage),
_("Scale Image"), "gimp-image-scale",
display->shell,
gimp_standard_help_func, GIMP_HELP_IMAGE_SCALE,
GIMP_DISPLAY_SHELL (display->shell)->unit,
image->gimp->config->interpolation_type,
image_scale_callback,
dialog);
dialog->dialog = scale_dialog_new (GIMP_VIEWABLE (display->gimage),
_("Scale Image"), "gimp-image-scale",
display->shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE,
GIMP_DISPLAY_SHELL (display->shell)->unit,
image->gimp->config->interpolation_type,
image_scale_callback,
dialog);
g_object_weak_ref (G_OBJECT (dialog->dialog),
(GWeakNotify) g_free, dialog);
......
......@@ -20,21 +20,16 @@
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimptemplate.h"
#include "widgets/gimpenumcombobox.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpsizebox.h"
#include "widgets/gimpviewabledialog.h"
#include "resize-dialog.h"
......@@ -42,10 +37,204 @@
#include "gimp-intl.h"
#define RESIZE_RESPONSE_RESET 1
#define SB_WIDTH 8
#define RESPONSE_RESET 1
typedef struct _ResizeDialog ResizeDialog;
struct _ResizeDialog
{
GimpViewable *viewable;
GimpUnit unit;
GtkWidget *box;
GimpResizeCallback callback;
gpointer user_data;
};
static void resize_dialog_response (GtkWidget *dialog,
gint response_id,
ResizeDialog *private);
static void resize_dialog_reset (ResizeDialog *private);
GtkWidget *
resize_dialog_new (GimpViewable *viewable,
const gchar *title,
const gchar *role,
GtkWidget *parent,
GimpHelpFunc help_func,
const gchar *help_id,
GimpUnit unit,
GimpResizeCallback callback,
gpointer user_data)
{
GtkWidget *dialog;
GtkWidget *vbox;
GtkWidget *frame;
ResizeDialog *private;
GimpImage *image = NULL;
const gchar *text = NULL;
gint width, height;
gdouble xres, yres;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (callback != NULL, NULL);
if (GIMP_IS_IMAGE (viewable))
{
image = GIMP_IMAGE (viewable);
width = gimp_image_get_width (image);
height = gimp_image_get_height (image);
text = _("Canvas Size");
}
else if (GIMP_IS_ITEM (viewable))
{
GimpItem *item = GIMP_ITEM (viewable);
image = gimp_item_get_image (item);
width = gimp_item_width (item);
height = gimp_item_height (item);
text = _("Layer Size");
}
else
{
g_return_val_if_reached (NULL);
}
dialog = gimp_viewable_dialog_new (viewable,
title, role, GIMP_STOCK_RESIZE, title,
parent,
help_func, help_id,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GIMP_STOCK_RESET, RESPONSE_RESET,
GIMP_STOCK_RESIZE, GTK_RESPONSE_OK,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
private = g_new0 (ResizeDialog, 1);
g_signal_connect_swapped (dialog, "destroy",
G_CALLBACK (g_free),
private);
private->viewable = viewable;
private->callback = callback;
private->user_data = user_data;
gimp_image_get_resolution (image, &xres, &yres);
private->box = g_object_new (GIMP_TYPE_SIZE_BOX,
"width", width,
"height", height,
"unit", unit,
"xresolution", xres,
"yresolution", yres,
"keep-aspect", TRUE,
"edit-resolution", FALSE,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (resize_dialog_response),
private);
vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
gtk_widget_show (vbox);
frame = gimp_frame_new (text);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
gtk_container_add (GTK_CONTAINER (frame), private->box);
gtk_widget_show (private->box);
frame = gimp_frame_new (_("Offset"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
return dialog;
}
static void
resize_dialog_response (GtkWidget *dialog,
gint response_id,
ResizeDialog *private)
{
gint width, height;
switch (response_id)
{
case GTK_RESPONSE_CANCEL:
gtk_widget_destroy (dialog);
break;
case RESPONSE_RESET:
resize_dialog_reset (private);
break;
case GTK_RESPONSE_OK:
g_object_get (private->box,
"width", &width,
"height", &height,
NULL);
private->callback (dialog,
private->viewable,
width, height, 0, 0,
private->user_data);
break;
}
}
static void
resize_dialog_reset (ResizeDialog *private)
{
GimpImage *image;
gint width, height;
gdouble xres, yres;
if (GIMP_IS_IMAGE (private->viewable))
{
image = GIMP_IMAGE (private->viewable);
width = gimp_image_get_width (image);
height = gimp_image_get_height (image);
}
else if (GIMP_IS_ITEM (private->viewable))
{
GimpItem *item = GIMP_ITEM (private->viewable);
image = gimp_item_get_image (item);
width = gimp_item_width (item);
height = gimp_item_height (item);
}
else
{
g_return_if_reached ();
}
gimp_image_get_resolution (image, &xres, &yres);
g_object_set (private->box,
"width", width,
"height", height,
"xresolution", xres,
"yresolution", yres,
NULL);
}
#if 0
typedef struct _ResizePrivate ResizePrivate;
struct _ResizePrivate
......@@ -194,24 +383,24 @@ resize_dialog_new (GimpViewable *viewable,
switch (type)
{
case SCALE_DIALOG:
stock_id = GIMP_STOCK_SCALE;
case RESIZE_DIALOG:
stock_id = GIMP_STOCK_RESIZE;
switch (dialog->target)
{
case RESIZE_LAYER:
role = "gimp-layer-scale";
window_title = _("Scale Layer");
window_desc = _("Scale Layer Options");
help_page = GIMP_HELP_LAYER_SCALE;
role = "gimp-layer-resize";
window_title = _("Resize Layer");
window_desc = _("Resize Layer Options");
help_page = GIMP_HELP_LAYER_RESIZE;
frame = gimp_frame_new (_("Size"));
break;
case RESIZE_IMAGE:
role = "gimp-image-scale";
window_title = _("Scale Image");
window_desc = _("Scale Image Options");
help_page = GIMP_HELP_IMAGE_SCALE;
role = "gimp-image-resize";
window_title = _("Resize Image");
window_desc = _("Resize Image Options");
help_page = GIMP_HELP_IMAGE_RESIZE;
frame = gimp_frame_new (_("Pixel Dimensions"));
break;
}
......@@ -375,7 +564,7 @@ resize_dialog_new (GimpViewable *viewable,
/* initialize the original width & height labels */
orig_labels_update (private->size_se, dialog);
/* the scale ratio labels */
/* the resize ratio labels */
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, 4, 5,
......@@ -400,7 +589,7 @@ resize_dialog_new (GimpViewable *viewable,
gtk_box_pack_start (GTK_BOX (hbox), table2, FALSE, FALSE, 0);
gtk_widget_show (table2);
/* the scale ratio spinbuttons */
/* the resize ratio spinbuttons */
spinbutton =
gimp_spin_button_new (&private->ratio_x_adj,
dialog->ratio_x,
......@@ -544,7 +733,7 @@ resize_dialog_new (GimpViewable *viewable,
}
/* the resolution stuff */
if ((type == SCALE_DIALOG) && (dialog->target == RESIZE_IMAGE))
if ((type == RESIZE_DIALOG) && (dialog->target == RESIZE_IMAGE))
{