mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 12:32:37 +00:00
05e15eb1cc
2001-10-29 Michael Natterer <mitch@gimp.org> Cleanup weekend... * app/app_procs.c: pass "no_interface" to gimp_new(). * app/core/gimp.[ch]: added "gboolean no_interface" and the load_procs and save_procs GSLists. * app/core/gimptoolinfo.[ch]: added a "Gimp" pointer to the GimpToolInfo object so more functions find their context without accessing the global "the_gimp" variable. * app/display/display-types.h: removed the GDisplay -> GimpDisplay typedef. * app/display/gimpdisplay.c: look at gimp->no_interface, don't include "appenv.h". * app/file/file-open.[ch] * app/file/file-save.[ch]: don't use "the_gimp" any more. Instead, pass around lots of "Gimp" pointers. Removed the global load_procs and save_procs variables here. Use access() to find out whether a file is readable/writable, removed the manual voodoo and it's Win32 wrappers. Added an optional (can be NULL) "PlunInProcDef" parameter to file_save(), removed file_save_with_proc(). * app/gui/menus.c: Use the unused "gpointer data" parameter of the GtkItemFactory callbacks to pass a "Gimp" pointer to all of them. This reduces the usage of the global "the_gimp" hack to zero in app/gui/... yeah. * app/gui/channels-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palettes-commands.c * app/gui/select-commands.c * app/gui/test-commands.c * app/gui/tools-commands.c * app/gui/view-commands.c: use the passed "Gimp" pointer. * app/gui/color-area.[ch] * app/gui/convert-dialog.c * app/gui/dialogs-constructors.c * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/gui.c * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/palette-editor.c * app/gui/palette-import-dialog.[ch] * app/gui/paths-dialog.c * app/gui/preferences-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/tool-options-dialog.[ch] * app/gui/toolbox.c: pass around lots more "Gimp" and "GimpContext" pointers and don't use "the_gimp" any more. * app/tools/gimptool.h: added a pointer to the corresponding GimpToolInfo object (which in turn has a pointer to a Gimp). * app/tools/tool_manager.[ch]: set the pointer after creating the tool object. Removed tool_manager_get_info_by_tool() as there is a tool->tool_info pointer now. * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/path_tool.c * app/tools/xinput_airbrush.c: s/GDisplay/GimpDisplay/g. Use tool->tool_info and tool_info->gimp in some places to get rid of using "the_gimp". Removing the remaining ones involves changing the tool options system and is scheduled next... * app/widgets/gimpdnd.c * app/widgets/gimpdocumentview.c: pass a "Gimp" pointer to all file_open_*() functions. * app/gdisplay_color.[ch] * app/gdisplay_color_ui.[ch] * app/image_map.[ch] * app/nav_window.[ch] * app/path.c * app/path_bezier.c * app/path_transform.h * app/qmask.[ch]: s/GDisplay/GimpDisplay/g * tools/pdbgen/pdb/fileops.pdb: load_procs and save_procs are members of the "Gimp" object now. * tools/pdbgen/pdb/plug_in.pdb: use gimp->no_interface, don't include "appenv.h". * app/pdb/fileops_cmds.c * app/pdb/plug_in_cmds.c: regenerated.
389 lines
9.5 KiB
C
389 lines
9.5 KiB
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 "libgimpmath/gimpmath.h"
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
#include "gui-types.h"
|
|
|
|
#include "core/gimp.h"
|
|
#include "core/gimpcontext.h"
|
|
#include "core/gimpimage.h"
|
|
#include "core/gimpimage-mask.h"
|
|
|
|
#include "display/gimpdisplay.h"
|
|
#include "display/gimpdisplay-foreach.h"
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
#define return_if_no_display(gdisp,data) \
|
|
gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
|
|
if (! gdisp) \
|
|
return
|
|
|
|
#define return_if_no_image(gimage,data) \
|
|
gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
|
|
if (! gimage) \
|
|
return
|
|
|
|
|
|
/* local functions */
|
|
|
|
static void gimage_mask_feather_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data);
|
|
static void gimage_mask_border_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data);
|
|
static void gimage_mask_grow_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data);
|
|
static void gimage_mask_shrink_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data);
|
|
|
|
|
|
/* local variables */
|
|
|
|
static gdouble selection_feather_radius = 5.0;
|
|
static gint selection_border_radius = 5;
|
|
static gint selection_grow_pixels = 1;
|
|
static gint selection_shrink_pixels = 1;
|
|
static gboolean selection_shrink_edge_lock = FALSE;
|
|
|
|
|
|
void
|
|
select_invert_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_invert (gimage);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
void
|
|
select_all_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_all (gimage);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
void
|
|
select_none_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_none (gimage);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
void
|
|
select_float_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_float (gimage, gimp_image_active_drawable (gimage), 0, 0);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
void
|
|
select_feather_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpDisplay *gdisp;
|
|
GtkWidget *qbox;
|
|
return_if_no_display (gdisp, data);
|
|
|
|
qbox = gimp_query_size_box (_("Feather Selection"),
|
|
gimp_standard_help_func,
|
|
"dialogs/feather_selection.html",
|
|
_("Feather Selection by:"),
|
|
selection_feather_radius, 0, 32767, 3,
|
|
gdisp->gimage->unit,
|
|
MIN (gdisp->gimage->xresolution,
|
|
gdisp->gimage->yresolution),
|
|
gdisp->dot_for_dot,
|
|
G_OBJECT (gdisp->gimage), "disconnect",
|
|
gimage_mask_feather_callback, gdisp->gimage);
|
|
gtk_widget_show (qbox);
|
|
}
|
|
|
|
void
|
|
select_sharpen_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_sharpen (gimage);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
void
|
|
select_shrink_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpDisplay *gdisp;
|
|
GtkWidget *edge_lock;
|
|
GtkWidget *shrink_dialog;
|
|
GList *children;
|
|
return_if_no_display (gdisp, data);
|
|
|
|
shrink_dialog =
|
|
gimp_query_size_box (_("Shrink Selection"),
|
|
gimp_standard_help_func,
|
|
"dialogs/shrink_selection.html",
|
|
_("Shrink Selection by:"),
|
|
selection_shrink_pixels, 1, 32767, 0,
|
|
gdisp->gimage->unit,
|
|
MIN (gdisp->gimage->xresolution,
|
|
gdisp->gimage->yresolution),
|
|
gdisp->dot_for_dot,
|
|
G_OBJECT (gdisp->gimage), "disconnect",
|
|
gimage_mask_shrink_callback, gdisp->gimage);
|
|
|
|
edge_lock = gtk_check_button_new_with_label (_("Shrink from image border"));
|
|
|
|
/* eeek */
|
|
children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (shrink_dialog)->vbox));
|
|
|
|
gtk_box_pack_start (GTK_BOX (children->data), edge_lock, FALSE, FALSE, 0);
|
|
|
|
g_list_free (children);
|
|
|
|
g_object_set_data (G_OBJECT (shrink_dialog), "edge_lock_toggle", edge_lock);
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (edge_lock),
|
|
! selection_shrink_edge_lock);
|
|
gtk_widget_show (edge_lock);
|
|
|
|
gtk_widget_show (shrink_dialog);
|
|
}
|
|
|
|
void
|
|
select_grow_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpDisplay *gdisp;
|
|
GtkWidget *qbox;
|
|
return_if_no_display (gdisp, data);
|
|
|
|
qbox = gimp_query_size_box (_("Grow Selection"),
|
|
gimp_standard_help_func,
|
|
"dialogs/grow_selection.html",
|
|
_("Grow Selection by:"),
|
|
selection_grow_pixels, 1, 32767, 0,
|
|
gdisp->gimage->unit,
|
|
MIN (gdisp->gimage->xresolution,
|
|
gdisp->gimage->yresolution),
|
|
gdisp->dot_for_dot,
|
|
G_OBJECT (gdisp->gimage), "disconnect",
|
|
gimage_mask_grow_callback, gdisp->gimage);
|
|
gtk_widget_show (qbox);
|
|
}
|
|
|
|
void
|
|
select_border_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpDisplay *gdisp;
|
|
GtkWidget *qbox;
|
|
return_if_no_display (gdisp, data);
|
|
|
|
qbox = gimp_query_size_box (_("Border Selection"),
|
|
gimp_standard_help_func,
|
|
"dialogs/border_selection.html",
|
|
_("Border Selection by:"),
|
|
selection_border_radius, 1, 32767, 0,
|
|
gdisp->gimage->unit,
|
|
MIN (gdisp->gimage->xresolution,
|
|
gdisp->gimage->yresolution),
|
|
gdisp->dot_for_dot,
|
|
G_OBJECT (gdisp->gimage), "disconnect",
|
|
gimage_mask_border_callback, gdisp->gimage);
|
|
gtk_widget_show (qbox);
|
|
}
|
|
|
|
void
|
|
select_save_cmd_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
return_if_no_image (gimage, data);
|
|
|
|
gimage_mask_save (gimage);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
|
|
/* private functions */
|
|
|
|
static void
|
|
gimage_mask_feather_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
gdouble radius_x;
|
|
gdouble radius_y;
|
|
|
|
gimage = GIMP_IMAGE (data);
|
|
|
|
selection_feather_radius = size;
|
|
|
|
radius_x = radius_y = selection_feather_radius;
|
|
|
|
if (unit != GIMP_UNIT_PIXEL)
|
|
{
|
|
gdouble factor;
|
|
|
|
factor = (MAX (gimage->xresolution, gimage->yresolution) /
|
|
MIN (gimage->xresolution, gimage->yresolution));
|
|
|
|
if (gimage->xresolution == MIN (gimage->xresolution, gimage->yresolution))
|
|
radius_y *= factor;
|
|
else
|
|
radius_x *= factor;
|
|
}
|
|
|
|
gimage_mask_feather (gimage, radius_x, radius_y);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
static void
|
|
gimage_mask_border_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
gdouble radius_x;
|
|
gdouble radius_y;
|
|
|
|
gimage = GIMP_IMAGE (data);
|
|
|
|
selection_border_radius = ROUND (size);
|
|
|
|
radius_x = radius_y = selection_border_radius;
|
|
|
|
if (unit != GIMP_UNIT_PIXEL)
|
|
{
|
|
gdouble factor;
|
|
|
|
factor = (MAX (gimage->xresolution, gimage->yresolution) /
|
|
MIN (gimage->xresolution, gimage->yresolution));
|
|
|
|
if (gimage->xresolution == MIN (gimage->xresolution, gimage->yresolution))
|
|
radius_y *= factor;
|
|
else
|
|
radius_x *= factor;
|
|
}
|
|
|
|
gimage_mask_border (gimage, radius_x, radius_y);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
static void
|
|
gimage_mask_grow_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
gdouble radius_x;
|
|
gdouble radius_y;
|
|
|
|
gimage = GIMP_IMAGE (data);
|
|
|
|
selection_grow_pixels = ROUND (size);
|
|
|
|
radius_x = radius_y = selection_grow_pixels;
|
|
|
|
if (unit != GIMP_UNIT_PIXEL)
|
|
{
|
|
gdouble factor;
|
|
|
|
factor = (MAX (gimage->xresolution, gimage->yresolution) /
|
|
MIN (gimage->xresolution, gimage->yresolution));
|
|
|
|
if (gimage->xresolution == MIN (gimage->xresolution, gimage->yresolution))
|
|
radius_y *= factor;
|
|
else
|
|
radius_x *= factor;
|
|
}
|
|
|
|
gimage_mask_grow (gimage, radius_x, radius_y);
|
|
gdisplays_flush ();
|
|
}
|
|
|
|
static void
|
|
gimage_mask_shrink_callback (GtkWidget *widget,
|
|
gdouble size,
|
|
GimpUnit unit,
|
|
gpointer data)
|
|
{
|
|
GimpImage *gimage;
|
|
gint radius_x;
|
|
gint radius_y;
|
|
|
|
gimage = GIMP_IMAGE (data);
|
|
|
|
selection_shrink_pixels = ROUND (size);
|
|
|
|
radius_x = radius_y = selection_shrink_pixels;
|
|
|
|
selection_shrink_edge_lock =
|
|
! GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (widget),
|
|
"edge_lock_toggle"))->active;
|
|
|
|
if (unit != GIMP_UNIT_PIXEL)
|
|
{
|
|
gdouble factor;
|
|
|
|
factor = (MAX (gimage->xresolution, gimage->yresolution) /
|
|
MIN (gimage->xresolution, gimage->yresolution));
|
|
|
|
if (gimage->xresolution == MIN (gimage->xresolution, gimage->yresolution))
|
|
radius_y *= factor;
|
|
else
|
|
radius_x *= factor;
|
|
}
|
|
|
|
gimage_mask_shrink (gimage, radius_x, radius_y, selection_shrink_edge_lock);
|
|
gdisplays_flush ();
|
|
}
|