Commit 22a1384b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/widgets/Makefile.am app/widgets/widgets-types.h added new widget

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

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpsizebox.[ch]: added new widget GimpSizeBox.

	* app/widgets/gimppropwidgets.c: the order of setting the X and Y
	properties does matter.

	* app/dialogs/Makefile.am
	* app/dialogs/scale-dialog.[ch]: added first version of a new
	Scale dialog in an attempt to address bug #151022.

	* app/actions/layers-commands.c: use the new scale dialog.
parent 5ae3d595
2004-10-12 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpsizebox.[ch]: added new widget GimpSizeBox.
* app/widgets/gimppropwidgets.c: the order of setting the X and Y
properties does matter.
* app/dialogs/Makefile.am
* app/dialogs/scale-dialog.[ch]: added first version of a new
Scale dialog in an attempt to address bug #151022.
* app/actions/layers-commands.c: use the new scale dialog.
2004-10-12 Sven Neumann <sven@gimp.org>
* app/widgets/gimptemplateeditor.c: added mnemonics for the size
......
......@@ -28,6 +28,8 @@
#include "actions-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpchannel-select.h"
#include "core/gimpcontext.h"
......@@ -50,6 +52,7 @@
#include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemtreeview.h"
#include "widgets/gimpprogressdialog.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpviewabledialog.h"
......@@ -60,6 +63,7 @@
#include "tools/tool_manager.h"
#include "dialogs/resize-dialog.h"
#include "dialogs/scale-dialog.h"
#include "actions.h"
#include "layers-commands.h"
......@@ -338,7 +342,7 @@ layers_scale_cmd_callback (GtkAction *action,
return_if_no_layer (gimage, layer, data);
return_if_no_widget (widget, data);
layers_scale_layer_query (GIMP_IS_DISPLAY (data) ? data : NULL,
layers_scale_layer_query (action_data_get_display (data),
gimage, layer, widget);
}
......@@ -1201,44 +1205,51 @@ layers_add_mask_query (GimpLayer *layer,
/* The scale layer dialog */
/****************************/
typedef struct _ScaleLayerOptions ScaleLayerOptions;
struct _ScaleLayerOptions
{
ResizeDialog *dialog;
GimpDisplay *gdisp;
GimpLayer *layer;
};
static void
scale_layer_query_ok_callback (GtkWidget *widget,
gpointer data)
scale_layer_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
GimpUnit unit,
GimpInterpolationType interpolation,
gpointer data)
{
ScaleLayerOptions *options = data;
GimpDisplay *gdisp = data ? GIMP_DISPLAY (data) : NULL;
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);
GimpProgress *progress;
GtkWidget *progress_dialog = NULL;
gtk_widget_set_sensitive (options->dialog->shell, FALSE);
gtk_widget_destroy (dialog);
progress = gimp_progress_start (GIMP_PROGRESS (options->gdisp),
_("Scaling..."), FALSE);
if (width == gimp_item_width (item) && height == gimp_item_height (item))
return;
gimp_item_scale_by_origin (GIMP_ITEM (options->layer),
options->dialog->width,
options->dialog->height,
options->dialog->interpolation,
progress,
TRUE);
if (gdisp)
{
progress = GIMP_PROGRESS (gdisp);
}
else
{
progress_dialog = gimp_progress_dialog_new ();
progress = GIMP_PROGRESS (progress_dialog);
}
progress = gimp_progress_start (progress, _("Scaling..."), FALSE);
gimp_item_scale_by_origin (item,
width, height, interpolation,
progress, TRUE);
if (progress)
gimp_progress_end (progress);
gimp_image_flush (gimage);
if (progress_dialog)
gtk_widget_destroy (progress_dialog);
gtk_widget_destroy (options->dialog->shell);
gimp_image_flush (gimp_item_get_image (item));
}
else
{
......@@ -1252,31 +1263,20 @@ layers_scale_layer_query (GimpDisplay *gdisp,
GimpLayer *layer,
GtkWidget *parent)
{
ScaleLayerOptions *options;
GtkWidget *dialog;
GimpUnit unit;
options = g_new0 (ScaleLayerOptions, 1);
unit = gdisp ? GIMP_DISPLAY_SHELL (gdisp->shell)->unit : GIMP_UNIT_PIXEL;
options->gdisp = gdisp;
options->layer = layer;
dialog = scale_dialog_new (GIMP_VIEWABLE (layer),
_("Scale Layer"), "gimp-layer-scale",
parent,
gimp_standard_help_func, GIMP_HELP_LAYER_SCALE,
unit, gimage->gimp->config->interpolation_type,
scale_layer_callback,
gdisp);
options->dialog =
resize_dialog_new (GIMP_VIEWABLE (layer), parent,
SCALE_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 (scale_layer_query_ok_callback),
options);
g_object_weak_ref (G_OBJECT (options->dialog->shell),
(GWeakNotify) g_free,
options);
gtk_widget_show (options->dialog->shell);
gtk_widget_show (dialog);
}
......
......@@ -42,6 +42,8 @@ libappdialogs_a_SOURCES = \
resize-dialog.h \
resolution-calibrate-dialog.c \
resolution-calibrate-dialog.h \
scale-dialog.c \
scale-dialog.h \
stroke-dialog.c \
stroke-dialog.h \
tips-dialog.c \
......
/* The GIMP -- an image manipulation program
* 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"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "widgets/gimpenumcombobox.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpsizebox.h"
#include "widgets/gimpviewabledialog.h"
#include "scale-dialog.h"
#include "gimp-intl.h"
#define RESPONSE_RESET 1
typedef struct _ScaleDialog ScaleDialog;
struct _ScaleDialog
{
GimpViewable *viewable;
GimpUnit unit;
GimpInterpolationType interpolation;
GtkWidget *box;
GtkWidget *combo;
GimpScaleCallback callback;
gpointer user_data;
};
static void scale_dialog_response (GtkWidget *dialog,
gint response_id,
ScaleDialog *private);
static void scale_dialog_reset (ScaleDialog *private);
GtkWidget *
scale_dialog_new (GimpViewable *viewable,
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);
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);
}
gimp_image_get_resolution (image, &xres, &yres);
dialog = gimp_viewable_dialog_new (viewable,
title, role, GIMP_STOCK_SCALE, title,
parent,
help_func, help_id,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GIMP_STOCK_RESET, RESPONSE_RESET,
GIMP_STOCK_SCALE, GTK_RESPONSE_OK,
NULL);
private = g_new0 (ScaleDialog, 1);
g_signal_connect_swapped (dialog, "destroy",
G_CALLBACK (g_free),
private);
private->viewable = viewable;
private->interpolation = interpolation;
private->unit = unit;
private->callback = callback;
private->user_data = user_data;
private->box = g_object_new (GIMP_TYPE_SIZE_BOX,
"width", width,
"height", height,
"unit", unit,
"xresolution", xres,
"yresolution", yres,
"keep-aspect", TRUE,
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);
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (frame), hbox);
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);
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);
return dialog;
}
static void
scale_dialog_response (GtkWidget *dialog,
gint response_id,
ScaleDialog *private)
{
GimpUnit unit = private->unit;
gint interpolation = private->interpolation;
gint width;
gint height;
switch (response_id)
{
case GTK_RESPONSE_CANCEL:
gtk_widget_destroy (dialog);
break;
case RESPONSE_RESET:
scale_dialog_reset (private);
break;
case GTK_RESPONSE_OK:
g_object_get (private->box,
"width", &width,
"height", &height,
"unit", &unit,
NULL);
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (private->combo),
&interpolation);
private->callback (dialog,
private->viewable,
width, height, unit, interpolation,
private->user_data);
break;
}
}
static void
scale_dialog_reset (ScaleDialog *private)
{
gint width;
gint height;
if (GIMP_IS_IMAGE (private->viewable))
{
GimpImage *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);
width = gimp_item_width (item);
height = gimp_item_height (item);
}
else
{
g_return_if_reached ();
}
g_object_set (private->box,
"width", width,
"height", height,
"unit", private->unit,
"keep-aspect", TRUE,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->combo),
private->interpolation);
}
/* The GIMP -- an image manipulation program
* 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.
*/
#ifndef __SCALE_DIALOG_H__
#define __SCALE_DIALOG_H__
typedef void (* GimpScaleCallback) (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
GimpUnit unit,
GimpInterpolationType interpolation,
gpointer user_data);
GtkWidget * scale_dialog_new (GimpViewable *viewable,
const gchar *title,
const gchar *role,
GtkWidget *parent,
GimpHelpFunc help_func,
const gchar *help_id,
GimpUnit unit,
GimpInterpolationType interpolation,
GimpScaleCallback callback,
gpointer user_data);
#endif /* __SCALE_DIALOG_H__ */
......@@ -200,6 +200,8 @@ libappwidgets_a_sources = \
gimpselectioneditor.h \
gimpsessioninfo.c \
gimpsessioninfo.h \
gimpsizebox.c \
gimpsizebox.h \
gimpstringaction.c \
gimpstringaction.h \
gimpstrokeeditor.c \
......
......@@ -2357,6 +2357,7 @@ gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
gdouble *old_x_value;
gdouble *old_y_value;
GimpUnit *old_unit_value;
gboolean backwards;
x_param_spec = g_object_get_data (G_OBJECT (sizeentry),
"gimp-config-param-spec-x");
......@@ -2396,6 +2397,8 @@ gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
}
}
backwards = (*old_x_value == x_value);
if (*old_x_value == x_value &&
*old_y_value == y_value &&
(old_unit_value == NULL || *old_unit_value == unit_value))
......@@ -2415,18 +2418,31 @@ gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
if (G_IS_PARAM_SPEC_INT (x_param_spec) &&
G_IS_PARAM_SPEC_INT (y_param_spec))
{
g_object_set (config,
x_param_spec->name, ROUND (x_value),
y_param_spec->name, ROUND (y_value),
NULL);
if (backwards)
g_object_set (config,
y_param_spec->name, ROUND (y_value),
x_param_spec->name, ROUND (x_value),
NULL);
else
g_object_set (config,
x_param_spec->name, ROUND (x_value),
y_param_spec->name, ROUND (y_value),
NULL);
}
else if (G_IS_PARAM_SPEC_DOUBLE (x_param_spec) &&
G_IS_PARAM_SPEC_DOUBLE (y_param_spec))
{
g_object_set (config,
x_param_spec->name, x_value,
y_param_spec->name, y_value,
NULL);
if (backwards)
g_object_set (config,
y_param_spec->name, y_value,
x_param_spec->name, x_value,
NULL);
else
g_object_set (config,
x_param_spec->name, x_value,
y_param_spec->name, y_value,
NULL);
}
}
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsizebox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpconfig-params.h"
#include "gimppropwidgets.h"
#include "gimpsizebox.h"
#include "gimp-intl.h"
#define SB_WIDTH 8
enum
{
PROP_0,
PROP_WIDTH,
PROP_HEIGHT,
PROP_UNIT,
PROP_XRESOLUTION,
PROP_YRESOLUTION,
PROP_KEEP_ASPECT
};
#define GIMP_SIZE_BOX_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_SIZE_BOX, GimpSizeBoxPrivate))
typedef struct _GimpSizeBoxPrivate GimpSizeBoxPrivate;
struct _GimpSizeBoxPrivate
{
GimpSizeEntry *entry;
GimpChainButton *chain;
gdouble aspect;
};
static void gimp_size_box_class_init (GimpSizeBoxClass *klass);
static GObject * gimp_size_box_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_size_box_init (GimpSizeBox *box);
static void gimp_size_box_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_size_box_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GtkVBoxClass *parent_class = NULL;
GType
gimp_size_box_get_type (void)
{
static GType box_type = 0;
if (! box_type)
{
static const GTypeInfo box_info =
{
sizeof (GimpSizeBoxClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_size_box_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpSizeBox),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_size_box_init
};
box_type = g_type_register_static (GTK_TYPE_VBOX,
"GimpSizeBox",
&box_info, 0);
}
return box_type;
}
static void
gimp_size_box_class_init (GimpSizeBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_size_box_constructor;
object_class->set_property = gimp_size_box_set_property;
object_class->get_property = gimp_size_box_get_property;
g_type_class_add_private (object_class, sizeof (GimpSizeBoxPrivate));
g_object_class_install_property (object_class, PROP_WIDTH,
g_param_spec_int ("width", NULL, NULL,
GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE,
256,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_int ("height", NULL, NULL,
GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE,
256,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_UNIT,
gimp_param_spec_unit ("unit", NULL, NULL,
TRUE, TRUE,
GIMP_UNIT_PIXEL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_XRESOLUTION,
g_param_spec_double ("xresolution",
NULL, NULL,
GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION,
72.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_YRESOLUTION,
g_param_spec_double ("yresolution",
NULL, NULL,
GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION,
72.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_KEEP_ASPECT,
g_param_spec_boolean ("keep-aspect",
NULL, NULL,
TRUE,
G_PARAM_READWRITE));
}
static void
gimp_size_box_init (GimpSizeBox *box)
{
gtk_box_set_spacing (GTK_BOX (box), 6);
}
static GObject *
gimp_size_box_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpSizeBox *box;
GtkWidget *entry;
GtkWidget *table;
GtkWidget *label;