2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-10-12 22:59:14 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "dialogs-types.h"
|
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2004-10-12 22:59:14 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpitem.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
2005-01-09 00:22:31 +08:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
2004-10-12 22:59:14 +08:00
|
|
|
#include "widgets/gimpsizebox.h"
|
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
|
|
|
|
#include "scale-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define RESPONSE_RESET 1
|
|
|
|
|
|
|
|
|
2007-05-24 04:08:27 +08:00
|
|
|
typedef struct
|
2004-10-12 22:59:14 +08:00
|
|
|
{
|
|
|
|
GimpViewable *viewable;
|
|
|
|
GimpUnit unit;
|
|
|
|
GimpInterpolationType interpolation;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GimpScaleCallback callback;
|
|
|
|
gpointer user_data;
|
2007-05-24 04:08:27 +08:00
|
|
|
} ScaleDialog;
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void scale_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
ScaleDialog *private);
|
|
|
|
static void scale_dialog_reset (ScaleDialog *private);
|
2007-05-24 04:08:27 +08:00
|
|
|
static void scale_dialog_free (ScaleDialog *private);
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
scale_dialog_new (GimpViewable *viewable,
|
2006-09-01 19:26:54 +08:00
|
|
|
GimpContext *context,
|
2004-10-12 22:59:14 +08:00
|
|
|
const gchar *title,
|
|
|
|
const gchar *role,
|
|
|
|
GtkWidget *parent,
|
|
|
|
GimpHelpFunc help_func,
|
|
|
|
const gchar *help_id,
|
|
|
|
GimpUnit unit,
|
|
|
|
GimpInterpolationType interpolation,
|
|
|
|
GimpScaleCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *label;
|
|
|
|
ScaleDialog *private;
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
const gchar *text = NULL;
|
|
|
|
gint width, height;
|
|
|
|
gdouble xres, yres;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
|
2006-10-15 02:15:41 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-10-12 22:59:14 +08:00
|
|
|
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 = _("Image 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);
|
|
|
|
}
|
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
dialog = gimp_viewable_dialog_new (viewable, context,
|
2004-10-12 22:59:14 +08:00
|
|
|
title, role, GIMP_STOCK_SCALE, title,
|
|
|
|
parent,
|
|
|
|
help_func, help_id,
|
|
|
|
|
|
|
|
GIMP_STOCK_RESET, RESPONSE_RESET,
|
2005-02-04 04:36:19 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2004-10-12 22:59:14 +08:00
|
|
|
GIMP_STOCK_SCALE, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
RESPONSE_RESET,
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
2007-05-24 04:08:27 +08:00
|
|
|
private = g_slice_new0 (ScaleDialog);
|
2004-10-12 22:59:14 +08:00
|
|
|
|
2007-05-24 04:08:27 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (dialog),
|
|
|
|
(GWeakNotify) scale_dialog_free, private);
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
private->viewable = viewable;
|
|
|
|
private->interpolation = interpolation;
|
|
|
|
private->unit = unit;
|
|
|
|
private->callback = callback;
|
|
|
|
private->user_data = user_data;
|
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
private->box = g_object_new (GIMP_TYPE_SIZE_BOX,
|
2004-10-27 07:31:34 +08:00
|
|
|
"width", width,
|
|
|
|
"height", height,
|
|
|
|
"unit", unit,
|
|
|
|
"xresolution", xres,
|
|
|
|
"yresolution", yres,
|
|
|
|
"resolution-unit", gimp_image_get_unit (image),
|
|
|
|
"keep-aspect", TRUE,
|
|
|
|
"edit-resolution", GIMP_IS_IMAGE (viewable),
|
2004-10-12 22:59:14 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (scale_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 (_("Quality"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-10-27 23:59:52 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2004-10-27 23:59:52 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2004-10-12 22:59:14 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("I_nterpolation:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2005-11-02 17:27:15 +08:00
|
|
|
gtk_size_group_add_widget (GIMP_SIZE_BOX (private->box)->size_group, label);
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
private->combo = gimp_enum_combo_box_new (GIMP_TYPE_INTERPOLATION_TYPE);
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), private->combo);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), private->combo, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (private->combo);
|
|
|
|
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->combo),
|
|
|
|
private->interpolation);
|
|
|
|
|
2004-10-27 23:59:52 +08:00
|
|
|
if (gimp_image_base_type (image) == GIMP_INDEXED)
|
|
|
|
{
|
2005-01-09 00:22:31 +08:00
|
|
|
GtkWidget *box = gimp_message_box_new (GIMP_STOCK_INFO);
|
|
|
|
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_BOX (box),
|
|
|
|
_("Indexed color layers are always scaled "
|
|
|
|
"without interpolation. The chosen "
|
|
|
|
"interpolation type will affect channels "
|
2007-06-21 16:03:36 +08:00
|
|
|
"and layer masks only."));
|
2005-01-09 00:22:31 +08:00
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box), 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box);
|
2004-10-27 23:59:52 +08:00
|
|
|
}
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scale_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
ScaleDialog *private)
|
|
|
|
{
|
|
|
|
GimpUnit unit = private->unit;
|
|
|
|
gint interpolation = private->interpolation;
|
2004-10-27 07:31:34 +08:00
|
|
|
GimpUnit resolution_unit;
|
|
|
|
gint width, height;
|
|
|
|
gdouble xres, yres;
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case RESPONSE_RESET:
|
|
|
|
scale_dialog_reset (private);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
g_object_get (private->box,
|
2004-10-27 07:31:34 +08:00
|
|
|
"width", &width,
|
|
|
|
"height", &height,
|
|
|
|
"unit", &unit,
|
|
|
|
"xresolution", &xres,
|
|
|
|
"yresolution", &yres,
|
|
|
|
"resolution-unit", &resolution_unit,
|
2004-10-12 22:59:14 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (private->combo),
|
|
|
|
&interpolation);
|
|
|
|
|
|
|
|
private->callback (dialog,
|
|
|
|
private->viewable,
|
|
|
|
width, height, unit, interpolation,
|
2004-10-27 07:31:34 +08:00
|
|
|
xres, yres, resolution_unit,
|
2004-10-12 22:59:14 +08:00
|
|
|
private->user_data);
|
|
|
|
break;
|
2004-11-08 19:22:24 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
break;
|
2004-10-12 22:59:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scale_dialog_reset (ScaleDialog *private)
|
|
|
|
{
|
2004-10-27 09:20:07 +08:00
|
|
|
GimpImage *image;
|
|
|
|
gint width, height;
|
|
|
|
gdouble xres, yres;
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
if (GIMP_IS_IMAGE (private->viewable))
|
|
|
|
{
|
2004-10-27 09:20:07 +08:00
|
|
|
image = GIMP_IMAGE (private->viewable);
|
2004-10-12 22:59:14 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
width = gimp_item_width (item);
|
|
|
|
height = gimp_item_height (item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
g_object_set (private->box,
|
2004-11-07 00:04:44 +08:00
|
|
|
"keep-aspect", FALSE,
|
2005-03-03 05:13:02 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_set (private->box,
|
2004-10-27 09:20:07 +08:00
|
|
|
"width", width,
|
|
|
|
"height", height,
|
|
|
|
"unit", private->unit,
|
2005-03-03 05:13:02 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_set (private->box,
|
2004-10-27 09:20:07 +08:00
|
|
|
"keep-aspect", TRUE,
|
|
|
|
"xresolution", xres,
|
|
|
|
"yresolution", yres,
|
|
|
|
"resolution-unit", gimp_image_get_unit (image),
|
2004-10-12 22:59:14 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->combo),
|
|
|
|
private->interpolation);
|
|
|
|
}
|
2007-05-24 04:08:27 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
scale_dialog_free (ScaleDialog *private)
|
|
|
|
{
|
|
|
|
g_slice_free (ScaleDialog, private);
|
|
|
|
}
|