gimp/app/dialogs/resize-dialog.c

460 lines
15 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-25 06:05:25 +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.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
#include <gtk/gtk.h>
Makefile.am configure.in added new directory libgimpbase/ 2001-05-21 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool-1.4.in: added new directory libgimpbase/ * app/Makefile.am: link against the new lib. * app/appenums.h: removed the PDB enums which are in libgimpbase/gimpbasetypes.h now. They are all "Gimp" prefixed. * app/apptypes.h: #include "libgimpbase/gimpbasetypes.h" * app/[lots] * app/core/[of] * app/gui/[files] * app/tools/: changed includes and all PDB types. * app/pdb/*: regenerated. * libgimp/Makefile.am: don't build libgimpi.a uglyness any more. * libgimp/gimpenv.[ch] * libgimp/gimplimits.[hh] * libgimp/gimpparasite.[ch] * libgimp/gimpparasiteio.[ch] * libgimp/gimpprotocol.[ch] * libgimp/gimpsignal.[ch] * libgimp/gimpunit.h * libgimp/gimputils.[ch] * libgimp/gimpwire.[ch]: removed... * libgimpbase/*: ...and added here as new library. * libgimp/gimp.[ch] * libgimp/gimpdrawable.[ch] * libgimp/gimpenums.h * libgimp/gimpimage.[ch] * libgimp/gimptile.c * libgimp/gimptypes.h * libgimp/gimpunit.c: changed accordingly. Added the gimp_*_add_new_parasite to gimp.[ch], gimpdrawable.[ch] and gimpimage.[ch]. * libgimpwidgets/gimppatheditor.c * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpsizeentry.c * libgimpwidgets/gimpunitmenu.c * libgimpwidgets/gimpwidgets.c * libgimpwidgets/gimpwidgetstypes.h: changed includes accordingly. * plug-ins/*/Makefile.am * plug-ins/common/mkgen.pl: link against libgimpbase. * tools/pdbgen/Makefile.am: scan libgimpbase/gimpbasetypes.h, so the enums are known to pdbgen... * tools/pdbgen/enumcode.pl: ...but don't write them out to libgimp/gimpenums.h * tools/pdbgen/app.pl: include libgimp/gimpbase.h in all *_cmds.c files. Added GIMP_ to the type names ganerated in app/. * tools/pdbgen/enums.pl: regenerated. * tools/pdbgen/pdb.pl * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/procedural_db.pdb * tools/pdbgen/pdb/unit.pdb: changed includes.
2001-05-21 21:58:46 +08:00
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
Makefile.am configure.in added the new library below. 2001-01-24 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added the new library below. * libgimpwidgets/Makefile.am * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.[ch] * libgimpwidgets/gimpcolorbutton.[ch] * libgimpwidgets/gimpdialog.[ch] * libgimpwidgets/gimpfileselection.[ch] * libgimpwidgets/gimphelpui.[ch] * libgimpwidgets/gimppatheditor.[ch] * libgimpwidgets/gimppixmap.[ch] * libgimpwidgets/gimpquerybox.[ch] * libgimpwidgets/gimpsizeentry.[ch] * libgimpwidgets/gimpunitmenu.[ch] * libgimpwidgets/gimpwidgets.[ch] * libgimpwidgets/gimpwidgets.def * libgimpwidgets/gimpwidgetstypes.h: new shared library. Currently there are some ugly dependencies into libgimp. These will be removed and go to a "libgimpglue" library which will be a library for functions which share a common interface between plug-ins and the app but have different implementations. Include "libgimp/gimpunit.h" from "libgimpwidgets/gimpwidgetstypes.h" to simulate this upcoming separation. * libgimp/Makefile.am * libgimp/gimpchainbutton.[ch] * libgimp/gimpcolorarea.[ch] * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimpfileselection.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimppixmap.[ch] * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: removed from here. * libgimp/gimpui.h * libgimp/gimpuitypes.h * libgimp/makefile.mingw.in * libgimp/makefile.msc: changed accordingly. * app/[all ui files] * app/pdb/palette_cmds.c * app/pdb/tools_cmds.c * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/tools.pdb: #include "libgimpwidgets/gimpwidgets.h" and removed useless includes. * app/apptypes.h: #include "libgimpwidgets/gimpwidgetstypes.h" * app/Makefile.am * plug-ins/[all makefiles which link against libgimpui]: link against libgimpwidgets.la * po-libgimp/POTFILES.in: changed file locations.
2001-01-25 06:36:18 +08:00
#include "libgimpwidgets/gimpwidgets.h"
configure.in added new directory app/dialogs and link libappdialogs.c into 2004-09-13 Michael Natterer <mitch@gimp.org> * configure.in * app/Makefile.am: added new directory app/dialogs and link libappdialogs.c into the gimp binary. * app/gui/Makefile.am * app/gui/gui-types.h * app/gui/gui-vtable.c * app/gui/gui.c * app/gui/about-dialog.[ch] * app/gui/authors.h * app/gui/color-notebook.[ch] * app/gui/convert-dialog.[ch] * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.[ch] * app/gui/file-dialog-utils.[ch] * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-open-location-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/grid-dialog.[ch] * app/gui/info-dialog.[ch] * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/offset-dialog.[ch] * app/gui/palette-import-dialog.[ch] * app/gui/preferences-dialog.[ch] * app/gui/quit-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/resolution-calibrate-dialog.[ch] * app/gui/stroke-dialog.[ch] * app/gui/tips-dialog.[ch] * app/gui/tips-parser.[ch] * app/gui/user-install-dialog.[ch]: removed these files... * app/dialogs/Makefile.am * app/dialogs/dialogs-types.h * app/dialogs/*.[ch]: ...and added them here. Changed some filenames like module-browser -> module-dialog. * app/app_procs.c * app/actions/actions-types.h * app/actions/actions.c * app/actions/dialogs-actions.c * app/actions/dialogs-commands.c * app/actions/dockable-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/file-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/select-commands.c * app/actions/templates-commands.c * app/actions/templates-commands.h * app/actions/vectors-commands.c * app/actions/view-commands.c * app/display/gimpdisplayshell-cursor.c * app/display/gimpdisplayshell-title.c * app/display/gimpdisplayshell.[ch] * app/tools/gimpcroptool.c * app/tools/gimpperspectivetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptransformtool.[ch] * app/tools/gimpvectortool.c * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimpcolorpanel.c * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimppaletteeditor.[ch] * app/widgets/gimptoolbox-color-area.c * menus/toolbox-menu.xml.in * tools/authorsgen/authorsgen.pl: changed accordingly.
2004-09-13 23:15:23 +08:00
#include "dialogs-types.h"
added GimpContext parameters and create the GimpView with that context. 2006-09-01 Michael Natterer <mitch@gimp.org> * app/widgets/gimpviewabledialog.[ch]: added GimpContext parameters and create the GimpView with that context. * app/widgets/gimpcolordialog.[ch] * app/dialogs/convert-dialog.[ch] * app/dialogs/desaturate-dialog.[ch] * app/dialogs/grid-dialog.[ch] * app/dialogs/image-properties-dialog.[ch] * app/dialogs/layer-add-mask-dialog.[ch] * app/dialogs/offset-dialog.[ch] * app/dialogs/print-size-dialog.[ch] * app/dialogs/resize-dialog.[ch] * app/dialogs/scale-dialog.[ch] * app/dialogs/stroke-dialog.[ch] * app/dialogs/template-options-dialog.[ch] * app/dialogs/vectors-options-dialog.[ch]: added GimpContext parameters here too and pass them to gimp_viewable_dialog_new(). * app/actions/colormap-editor-commands.c * app/actions/drawable-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palette-editor-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/actions/view-commands.c * app/dialogs/channel-options-dialog.c * app/dialogs/dialogs-constructors.c * app/dialogs/image-merge-layers-dialog.c * app/dialogs/image-scale-dialog.c * app/dialogs/layer-options-dialog.c * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/tools/gimpcolorpickertool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcontrollereditor.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimptoolbox-color-area.c: pass contexts to above dialog constructors.
2006-09-01 19:26:54 +08:00
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
app/widgets/Makefile.am new file defining the available help topics. Work 2003-08-21 Michael Natterer <mitch@gimp.org> * app/widgets/Makefile.am * app/widgets/gimphelp-ids.h: new file defining the available help topics. Work in progress and totally unusable for matching to the help system. Stay tuned... * app/gui/about-dialog.c * app/gui/brushes-menu.c * app/gui/buffers-menu.c * app/gui/channels-commands.[ch] * app/gui/channels-menu.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradients-commands.c * app/gui/gradients-menu.c * app/gui/image-menu.c * app/gui/layers-commands.[ch] * app/gui/layers-menu.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palettes-menu.c * app/gui/patterns-menu.c * app/gui/resize-dialog.c * app/gui/select-commands.c * app/gui/templates-menu.c * app/gui/tips-dialog.c * app/gui/toolbox-menu.c * app/gui/vectors-commands.[ch] * app/gui/vectors-menu.c: replaced literal HTML file paths by help IDs from gimphelp-ids.h. Renamed some menu callbacks to be consistent with similar ones. This is just an intermediate commit and not finished. While browsing all the menus, I noticed that our "x to selection" functions are not consistent at all. They should all offer the REPLACE,ADD,SUBTRACT,INTERSECT options: * app/core/gimpchannel.[ch]: added new function gimp_channel_new_from_alpha(). Removed gimp_channel_layer_alpha() and gimp_channel_layer_mask(). * app/core/gimpimage-mask.[ch]: added gimp_image_mask_select_alpha() and gimp_image_mask_select_component() which offer the full set of operation, feather and feather_radius parameters as the other selection functions. * app/core/gimpimage-mask-select.[ch]: removed gimp_image_mask_layer_alpha() and gimp_image_mask_layer_mask(). * app/gui/channels-commands.c (channels_channel_to_selection): use gimp_image_mask_select_component() instead of implementing it here. * app/gui/image-menu.c * app/gui/layers-commands.[ch]: offer the full choice of REPLACE,ADD,SUBTRACT,INTERSECT with "Alpha to Selection" and "Mask to Selection". * tools/pdbgen/pdb/selection.pdb: changed accordingly. * app/pdb/selection_cmds.c: regenerated.
2003-08-21 23:54:47 +08:00
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpsizebox.h"
#include "widgets/gimpviewabledialog.h"
#include "resize-dialog.h"
#include "gimp-intl.h"
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#define RESPONSE_RESET 1
2004-10-29 02:27:04 +08:00
#define SB_WIDTH 8
typedef struct
{
GimpViewable *viewable;
gint old_width;
gint old_height;
GimpUnit old_unit;
GtkWidget *box;
GtkWidget *offset;
GtkWidget *area;
GimpItemSet layer_set;
GimpResizeCallback callback;
gpointer user_data;
} ResizeDialog;
static void resize_dialog_response (GtkWidget *dialog,
gint response_id,
ResizeDialog *private);
static void resize_dialog_reset (ResizeDialog *private);
static void resize_dialog_free (ResizeDialog *private);
static void size_notify (GimpSizeBox *box,
GParamSpec *pspec,
ResizeDialog *private);
2004-10-29 02:27:04 +08:00
static void offset_update (GtkWidget *widget,
ResizeDialog *private);
2004-10-29 02:27:04 +08:00
static void offsets_changed (GtkWidget *area,
gint off_x,
gint off_y,
ResizeDialog *private);
2004-10-29 02:27:04 +08:00
static void offset_center_clicked (GtkWidget *widget,
ResizeDialog *private);
2004-10-29 02:27:04 +08:00
GtkWidget *
resize_dialog_new (GimpViewable *viewable,
added GimpContext parameters and create the GimpView with that context. 2006-09-01 Michael Natterer <mitch@gimp.org> * app/widgets/gimpviewabledialog.[ch]: added GimpContext parameters and create the GimpView with that context. * app/widgets/gimpcolordialog.[ch] * app/dialogs/convert-dialog.[ch] * app/dialogs/desaturate-dialog.[ch] * app/dialogs/grid-dialog.[ch] * app/dialogs/image-properties-dialog.[ch] * app/dialogs/layer-add-mask-dialog.[ch] * app/dialogs/offset-dialog.[ch] * app/dialogs/print-size-dialog.[ch] * app/dialogs/resize-dialog.[ch] * app/dialogs/scale-dialog.[ch] * app/dialogs/stroke-dialog.[ch] * app/dialogs/template-options-dialog.[ch] * app/dialogs/vectors-options-dialog.[ch]: added GimpContext parameters here too and pass them to gimp_viewable_dialog_new(). * app/actions/colormap-editor-commands.c * app/actions/drawable-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palette-editor-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/actions/view-commands.c * app/dialogs/channel-options-dialog.c * app/dialogs/dialogs-constructors.c * app/dialogs/image-merge-layers-dialog.c * app/dialogs/image-scale-dialog.c * app/dialogs/layer-options-dialog.c * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/tools/gimpcolorpickertool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcontrollereditor.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimptoolbox-color-area.c: pass contexts to above dialog constructors.
2006-09-01 19:26:54 +08:00
GimpContext *context,
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 *main_vbox;
GtkWidget *vbox;
2004-10-29 02:27:04 +08:00
GtkWidget *abox;
GtkWidget *frame;
2004-10-29 02:27:04 +08:00
GtkWidget *button;
GtkWidget *spinbutton;
GtkWidget *entry;
GtkObject *adjustment;
GdkPixbuf *pixbuf;
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 (GIMP_IS_CONTEXT (context), 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);
}
added GimpContext parameters and create the GimpView with that context. 2006-09-01 Michael Natterer <mitch@gimp.org> * app/widgets/gimpviewabledialog.[ch]: added GimpContext parameters and create the GimpView with that context. * app/widgets/gimpcolordialog.[ch] * app/dialogs/convert-dialog.[ch] * app/dialogs/desaturate-dialog.[ch] * app/dialogs/grid-dialog.[ch] * app/dialogs/image-properties-dialog.[ch] * app/dialogs/layer-add-mask-dialog.[ch] * app/dialogs/offset-dialog.[ch] * app/dialogs/print-size-dialog.[ch] * app/dialogs/resize-dialog.[ch] * app/dialogs/scale-dialog.[ch] * app/dialogs/stroke-dialog.[ch] * app/dialogs/template-options-dialog.[ch] * app/dialogs/vectors-options-dialog.[ch]: added GimpContext parameters here too and pass them to gimp_viewable_dialog_new(). * app/actions/colormap-editor-commands.c * app/actions/drawable-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palette-editor-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/actions/view-commands.c * app/dialogs/channel-options-dialog.c * app/dialogs/dialogs-constructors.c * app/dialogs/image-merge-layers-dialog.c * app/dialogs/image-scale-dialog.c * app/dialogs/layer-options-dialog.c * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/tools/gimpcolorpickertool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcontrollereditor.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimptoolbox-color-area.c: pass contexts to above dialog constructors.
2006-09-01 19:26:54 +08:00
dialog = gimp_viewable_dialog_new (viewable, context,
title, role, GIMP_STOCK_RESIZE, title,
parent,
help_func, help_id,
GIMP_STOCK_RESET, RESPONSE_RESET,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GIMP_STOCK_RESIZE, GTK_RESPONSE_OK,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
RESPONSE_RESET,
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
private = g_slice_new0 (ResizeDialog);
g_object_weak_ref (G_OBJECT (dialog),
(GWeakNotify) resize_dialog_free, private);
private->viewable = viewable;
private->old_width = width;
private->old_height = height;
private->old_unit = unit;
private->layer_set = GIMP_ITEM_SET_NONE;
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);
main_vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
gtk_widget_show (main_vbox);
frame = gimp_frame_new (text);
gtk_box_pack_start (GTK_BOX (main_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 (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
2004-10-29 02:27:04 +08:00
vbox = gtk_vbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
/* the offset sizeentry */
spinbutton = gimp_spin_button_new (&adjustment,
1, 1, 1, 1, 10, 1,
1, 2);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), SB_WIDTH);
private->offset = entry = gimp_size_entry_new (1, unit, "%p",
TRUE, FALSE, FALSE, SB_WIDTH,
GIMP_SIZE_ENTRY_UPDATE_SIZE);
gtk_table_set_col_spacing (GTK_TABLE (entry), 0, 6);
gtk_table_set_col_spacing (GTK_TABLE (entry), 1, 6);
gtk_table_set_col_spacing (GTK_TABLE (entry), 3, 12);
gtk_table_set_row_spacing (GTK_TABLE (entry), 0, 2);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (entry),
GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_table_attach_defaults (GTK_TABLE (entry), spinbutton,
1, 2, 0, 1);
gtk_widget_show (spinbutton);
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
_("_X:"), 0, 0, 0.0);
gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),_("_Y:"), 1, 0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
gtk_widget_show (entry);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, xres, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 1, yres, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 0, 0, 0);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 1, 0, 0);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 0, 0);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 1, 0);
g_signal_connect (entry, "value-changed",
2004-10-29 02:27:04 +08:00
G_CALLBACK (offset_update),
private);
2004-10-29 02:27:04 +08:00
button = gtk_button_new_from_stock (GIMP_STOCK_CENTER);
2004-10-29 02:27:04 +08:00
gtk_table_attach_defaults (GTK_TABLE (entry), button, 4, 5, 1, 2);
gtk_widget_show (button);
g_signal_connect (button, "clicked",
G_CALLBACK (offset_center_clicked),
private);
2004-10-29 02:27:04 +08:00
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
gtk_widget_show (abox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
2004-10-29 02:27:04 +08:00
private->area = gimp_offset_area_new (width, height);
gtk_container_add (GTK_CONTAINER (frame), private->area);
gtk_widget_show (private->area);
gimp_viewable_get_preview_size (viewable, 200, FALSE, TRUE, &width, &height);
added GimpContext parameters and create the GimpView with that context. 2006-09-01 Michael Natterer <mitch@gimp.org> * app/widgets/gimpviewabledialog.[ch]: added GimpContext parameters and create the GimpView with that context. * app/widgets/gimpcolordialog.[ch] * app/dialogs/convert-dialog.[ch] * app/dialogs/desaturate-dialog.[ch] * app/dialogs/grid-dialog.[ch] * app/dialogs/image-properties-dialog.[ch] * app/dialogs/layer-add-mask-dialog.[ch] * app/dialogs/offset-dialog.[ch] * app/dialogs/print-size-dialog.[ch] * app/dialogs/resize-dialog.[ch] * app/dialogs/scale-dialog.[ch] * app/dialogs/stroke-dialog.[ch] * app/dialogs/template-options-dialog.[ch] * app/dialogs/vectors-options-dialog.[ch]: added GimpContext parameters here too and pass them to gimp_viewable_dialog_new(). * app/actions/colormap-editor-commands.c * app/actions/drawable-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palette-editor-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/actions/view-commands.c * app/dialogs/channel-options-dialog.c * app/dialogs/dialogs-constructors.c * app/dialogs/image-merge-layers-dialog.c * app/dialogs/image-scale-dialog.c * app/dialogs/layer-options-dialog.c * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/tools/gimpcolorpickertool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcontrollereditor.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimptoolbox-color-area.c: pass contexts to above dialog constructors.
2006-09-01 19:26:54 +08:00
pixbuf = gimp_viewable_get_pixbuf (viewable, context,
Changed GimpViewable preview rendering to have a context to get 2006-08-29 Michael Natterer <mitch@gimp.org> Changed GimpViewable preview rendering to have a context to get FG/BG/whatever from. Use the context to enable dynamic FG/BG colors in gradients. Fixes bug #127676 and bug #352214. Addresses bug #128367 (doesn't fix it because there's no loading/saving and no GUI yet). * app/core/core-enums.[ch]: added enum GimpGradientColor to enable specifying gradient colors in terms of foreground and background. * app/core/gimpgradient.[ch]: added color_type members to the GimpGradientSegment struct and honor them in gimp_gradient_get_color_at(). Added GimpContext parameters to all functions which finally call get_color_at(). * app/core/gimp-gradients.c: use the new method to implement the builtin gradients. * app/core/gimpviewable.[ch]: added GimpContext parameters to all get_preview() and get_pixbuf() functions. * app/core/gimpbrush.c * app/core/gimpbuffer.c * app/core/gimpdrawable-preview.[ch] * app/core/gimpgradient.c * app/core/gimpimage-preview.[ch] * app/core/gimpimagefile.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpundo.[ch] * app/text/gimpfont.c * app/vectors/gimpvectors-preview.[ch]: changed ::get_preview() and ::get_pixbuf() implementations accordingly. * app/core/gimpdrawable-blend.c * app/core/gimppalette-import.[ch] * app/dialogs/dialogs-constructors.c * app/dialogs/palette-import-dialog.c * app/dialogs/resize-dialog.c * app/display/gimpdisplayshell-layer-select.c * app/display/gimpdisplayshell.c * app/display/gimpnavigationeditor.c * app/paint/gimppaintoptions.c * app/tools/gimpeditselectiontool.c * app/tools/gimptexttool.c * app/actions/gradient-editor-commands.c * app/widgets/gimpaction.c * app/widgets/gimpbrusheditor.[ch] * app/widgets/gimpbufferview.c * app/widgets/gimpcellrendererviewable.c * app/widgets/gimpchanneltreeview.c * app/widgets/gimpclipboard.c * app/widgets/gimpcoloreditor.c * app/widgets/gimpcomponenteditor.c * app/widgets/gimpcontainerbox.c * app/widgets/gimpcontainercombobox.c * app/widgets/gimpcontainereditor.c * app/widgets/gimpcontainerentry.c * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainertreeview.[ch] * app/widgets/gimpdataeditor.[ch] * app/widgets/gimpdevicestatus.c * app/widgets/gimpdnd.[ch] * app/widgets/gimpdrawabletreeview.c * app/widgets/gimpfiledialog.c * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimpgradientselect.c * app/widgets/gimpitemtreeview.c * app/widgets/gimplayertreeview.c * app/widgets/gimppaletteeditor.[ch] * app/widgets/gimppropwidgets.[ch] * app/widgets/gimpselectioneditor.c * app/widgets/gimpthumbbox.[ch] * app/widgets/gimptoolbox-image-area.c * app/widgets/gimptoolbox-indicator-area.c * app/widgets/gimptooloptionseditor.c * app/widgets/gimpundoeditor.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpview-popup.[ch] * app/widgets/gimpview.[ch] * app/widgets/gimpviewablebutton.c * app/widgets/gimpviewabledialog.c * app/widgets/gimpviewrenderer.[ch] * app/widgets/gimpviewrenderer-frame.c * app/widgets/gimpviewrendererbrush.c * app/widgets/gimpviewrendererbuffer.c * app/widgets/gimpviewrendererdrawable.c * app/widgets/gimpviewrenderergradient.c * app/widgets/gimpviewrendererimage.c * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/gradient.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/image.pdb: added tons of GimpContext members and parameters, implement GimpDocked::set_context() in many widgets. Pass these locally remembered contexts to GimpViewable functions. Did some minor cleanups on the way. There are still some minor FIXMEs around where the code uses a NULL context (which is allowed by the APIs) * app/pdb/drawable_cmds.c * app/pdb/gradient_cmds.c * app/pdb/gradients_cmds.c * app/pdb/image_cmds.c: regenerated.
2006-08-30 05:44:51 +08:00
width, height);
2004-10-29 02:27:04 +08:00
if (pixbuf)
gimp_offset_area_set_pixbuf (GIMP_OFFSET_AREA (private->area), pixbuf);
2004-10-29 02:27:04 +08:00
g_signal_connect (private->area, "offsets-changed",
2004-10-29 02:27:04 +08:00
G_CALLBACK (offsets_changed),
private);
2004-10-29 02:27:04 +08:00
g_signal_connect (private->box, "notify",
G_CALLBACK (size_notify),
private);
2004-10-29 02:27:04 +08:00
if (GIMP_IS_IMAGE (viewable))
{
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *combo;
frame = gimp_frame_new (_("Layers"));
gtk_box_pack_start (GTK_BOX (main_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 (_("Resize _layers:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
combo = gimp_enum_combo_box_new (GIMP_TYPE_ITEM_SET);
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
gtk_widget_show (combo);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
private->layer_set,
G_CALLBACK (gimp_int_combo_box_get_active),
&private->layer_set);
}
return dialog;
}
static void
resize_dialog_response (GtkWidget *dialog,
gint response_id,
ResizeDialog *private)
{
GimpSizeEntry *entry = GIMP_SIZE_ENTRY (private->offset);
GimpUnit unit;
gint width;
gint height;
switch (response_id)
{
case RESPONSE_RESET:
resize_dialog_reset (private);
break;
case GTK_RESPONSE_OK:
g_object_get (private->box,
"width", &width,
"height", &height,
"unit", &unit,
NULL);
private->callback (dialog,
private->viewable,
width,
height,
unit,
gimp_size_entry_get_refval (entry, 0),
gimp_size_entry_get_refval (entry, 1),
private->layer_set,
private->user_data);
break;
default:
gtk_widget_destroy (dialog);
break;
}
}
static void
resize_dialog_reset (ResizeDialog *private)
{
g_object_set (private->box,
"keep-aspect", FALSE,
NULL);
g_object_set (private->box,
"width", private->old_width,
"height", private->old_height,
"unit", private->old_unit,
NULL);
g_object_set (private->box,
"keep-aspect", TRUE,
NULL);
}
static void
resize_dialog_free (ResizeDialog *private)
{
g_slice_free (ResizeDialog, private);
}
static void
size_notify (GimpSizeBox *box,
GParamSpec *pspec,
ResizeDialog *private)
{
gint diff_x = box->width - private->old_width;
gint diff_y = box->height - private->old_height;
gimp_offset_area_set_size (GIMP_OFFSET_AREA (private->area),
box->width, box->height);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (private->offset), 0,
MIN (0, diff_x), MAX (0, diff_x));
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (private->offset), 1,
MIN (0, diff_y), MAX (0, diff_y));
1997-11-25 06:05:25 +08:00
}
static gint
resize_bound_off_x (ResizeDialog *private,
gint offset_x)
1997-11-25 06:05:25 +08:00
{
GimpSizeBox *box = GIMP_SIZE_BOX (private->box);
1997-11-25 06:05:25 +08:00
if (private->old_width <= box->width)
return CLAMP (offset_x, 0, (box->width - private->old_width));
1997-11-25 06:05:25 +08:00
else
return CLAMP (offset_x, (box->width - private->old_width), 0);
1997-11-25 06:05:25 +08:00
}
static gint
resize_bound_off_y (ResizeDialog *private,
gint off_y)
1997-11-25 06:05:25 +08:00
{
GimpSizeBox *box = GIMP_SIZE_BOX (private->box);
1997-11-25 06:05:25 +08:00
if (private->old_height <= box->height)
return CLAMP (off_y, 0, (box->height - private->old_height));
1997-11-25 06:05:25 +08:00
else
return CLAMP (off_y, (box->height - private->old_height), 0);
1997-11-25 06:05:25 +08:00
}
static void
2004-10-29 02:27:04 +08:00
offset_update (GtkWidget *widget,
ResizeDialog *private)
1997-11-25 06:05:25 +08:00
{
GimpSizeEntry *entry = GIMP_SIZE_ENTRY (private->offset);
2004-10-29 02:27:04 +08:00
gint off_x;
gint off_y;
off_x = resize_bound_off_x (private,
2004-10-29 02:27:04 +08:00
RINT (gimp_size_entry_get_refval (entry, 0)));
off_y = resize_bound_off_y (private,
2004-10-29 02:27:04 +08:00
RINT (gimp_size_entry_get_refval (entry, 1)));
gimp_offset_area_set_offsets (GIMP_OFFSET_AREA (private->area), off_x, off_y);
}
1997-11-25 06:05:25 +08:00
static void
2004-10-29 02:27:04 +08:00
offsets_changed (GtkWidget *area,
gint off_x,
gint off_y,
ResizeDialog *private)
1997-11-25 06:05:25 +08:00
{
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset), 0, off_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset), 1, off_y);
1997-11-25 06:05:25 +08:00
}
static void
2004-10-29 02:27:04 +08:00
offset_center_clicked (GtkWidget *widget,
ResizeDialog *private)
1997-11-25 06:05:25 +08:00
{
GimpSizeBox *box = GIMP_SIZE_BOX (private->box);
2004-10-29 02:27:04 +08:00
gint off_x;
gint off_y;
off_x = resize_bound_off_x (private, (box->width - private->old_width) / 2);
off_y = resize_bound_off_y (private, (box->height - private->old_height) / 2);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset), 0, off_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset), 1, off_y);
g_signal_emit_by_name (private->offset, "value-changed", 0);
}