2000-12-17 05:37:03 +08:00
|
|
|
/* 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 "apptypes.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-02-04 06:05:41 +08:00
|
|
|
#include "context_manager.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "dialog_handler.h"
|
2001-01-30 01:54:02 +08:00
|
|
|
#include "gdisplay.h"
|
1998-06-28 18:39:58 +08:00
|
|
|
#include "gimage.h"
|
2001-02-04 06:05:41 +08:00
|
|
|
#include "gimpcontainer.h"
|
2001-01-30 01:54:02 +08:00
|
|
|
#include "gimpdrawable.h"
|
1998-06-28 18:39:58 +08:00
|
|
|
#include "gimpimage.h"
|
2001-02-02 02:44:22 +08:00
|
|
|
#include "gimplayer.h"
|
1999-06-07 01:26:51 +08:00
|
|
|
#include "lc_dialog.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "paint_funcs.h"
|
2001-01-22 05:29:31 +08:00
|
|
|
#include "palette_import.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "undo.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-14 12:55:21 +08:00
|
|
|
#include "tools/tool_manager.h"
|
2001-01-22 09:46:28 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
/* gimage.c: Junk (ugly dependencies) from gimpimage.c on its way
|
2000-12-29 23:22:01 +08:00
|
|
|
* to proper places. That is, the handlers should be moved to
|
|
|
|
* layers_dialog, gdisplay, tools, etc..
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-30 01:54:02 +08:00
|
|
|
static void gimage_dirty_handler (GimpImage *gimage);
|
|
|
|
static void gimage_destroy_handler (GimpImage *gimage);
|
|
|
|
static void gimage_cmap_change_handler (GimpImage *gimage,
|
1999-10-27 02:27:27 +08:00
|
|
|
gint ncol,
|
|
|
|
gpointer user_data);
|
2001-01-30 01:54:02 +08:00
|
|
|
static void gimage_rename_handler (GimpImage *gimage);
|
|
|
|
static void gimage_resize_handler (GimpImage *gimage);
|
|
|
|
static void gimage_restructure_handler (GimpImage *gimage);
|
|
|
|
static void gimage_repaint_handler (GimpImage *gimage,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
1999-07-20 03:46:05 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpImage *
|
2000-12-29 23:22:01 +08:00
|
|
|
gimage_new (gint width,
|
|
|
|
gint height,
|
1999-10-14 07:07:45 +08:00
|
|
|
GimpImageBaseType base_type)
|
1998-06-28 18:39:58 +08:00
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
GimpImage *gimage = gimp_image_new (width, height, base_type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "dirty",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_dirty_handler),
|
|
|
|
NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "destroy",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_destroy_handler),
|
|
|
|
NULL);
|
2001-01-14 11:55:56 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "name_changed",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_rename_handler),
|
|
|
|
NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "resize",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_resize_handler),
|
|
|
|
NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "restructure",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_restructure_handler),
|
|
|
|
NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "repaint",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_repaint_handler),
|
|
|
|
NULL);
|
1999-01-08 03:53:05 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gimage), "colormap_changed",
|
2000-12-29 23:22:01 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimage_cmap_change_handler),
|
|
|
|
NULL);
|
1998-06-30 23:31:32 +08:00
|
|
|
|
2001-02-04 06:05:41 +08:00
|
|
|
gimp_container_add (image_context, GIMP_OBJECT (gimage));
|
1998-12-19 08:00:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return gimage;
|
|
|
|
}
|
|
|
|
|
2001-02-14 12:55:21 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
1999-10-14 07:07:45 +08:00
|
|
|
gimage_dirty_handler (GimpImage *gimage)
|
1999-06-26 19:16:47 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
if (active_tool && ! active_tool->preserve)
|
1999-06-26 19:16:47 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
GDisplay* gdisp = active_tool->gdisp;
|
1999-06-26 19:16:47 +08:00
|
|
|
|
|
|
|
if (gdisp)
|
|
|
|
{
|
|
|
|
if (gdisp->gimage == gimage)
|
2001-02-14 12:55:21 +08:00
|
|
|
gimp_tool_old_initialize (active_tool, gdisp);
|
1999-06-26 19:16:47 +08:00
|
|
|
else
|
2001-02-14 12:55:21 +08:00
|
|
|
gimp_tool_old_initialize (active_tool, NULL);
|
|
|
|
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-06-28 18:39:58 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
1999-10-14 07:07:45 +08:00
|
|
|
gimage_destroy_handler (GimpImage *gimage)
|
1998-06-28 18:39:58 +08:00
|
|
|
{
|
1999-10-14 07:07:45 +08:00
|
|
|
GList *list;
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
/* free the undo list */
|
|
|
|
undo_free (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-14 07:07:45 +08:00
|
|
|
/* free all guides */
|
2000-12-30 08:16:50 +08:00
|
|
|
for (list = gimage->guides; list; list = g_list_next (list))
|
1999-10-14 07:07:45 +08:00
|
|
|
{
|
|
|
|
g_free ((Guide*) list->data);
|
|
|
|
}
|
2000-12-30 08:16:50 +08:00
|
|
|
|
1999-10-14 07:07:45 +08:00
|
|
|
g_list_free (gimage->guides);
|
|
|
|
|
2001-02-07 23:01:52 +08:00
|
|
|
/* check if this is the last image */
|
|
|
|
if (gimp_container_num_children (image_context) == 1)
|
1999-01-31 09:08:26 +08:00
|
|
|
{
|
1999-07-20 03:46:05 +08:00
|
|
|
dialog_show_toolbox ();
|
1999-01-31 09:08:26 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-07-20 03:46:05 +08:00
|
|
|
static void
|
|
|
|
gimage_cmap_change_handler (GimpImage *gimage,
|
|
|
|
gint ncol,
|
|
|
|
gpointer user_data)
|
1999-01-08 03:53:05 +08:00
|
|
|
{
|
1999-07-20 03:46:05 +08:00
|
|
|
gdisplays_update_full (gimage);
|
2000-02-11 05:38:43 +08:00
|
|
|
|
|
|
|
if (gimp_image_base_type (gimage) == INDEXED)
|
|
|
|
paint_funcs_invalidate_color_hash_table (gimage, ncol);
|
1999-01-08 03:53:05 +08:00
|
|
|
}
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
1999-10-14 07:07:45 +08:00
|
|
|
gimage_rename_handler (GimpImage *gimage)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_title (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
lc_dialog_update_image_list ();
|
1998-12-19 08:00:06 +08:00
|
|
|
|
1999-07-20 03:46:05 +08:00
|
|
|
palette_import_image_renamed (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
1999-10-14 07:07:45 +08:00
|
|
|
gimage_resize_handler (GimpImage *gimage)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
|
|
|
|
/* shrink wrap and update all views */
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_image_invalidate_layer_previews (gimage);
|
|
|
|
gimp_image_invalidate_channel_previews (gimage);
|
2001-02-05 06:10:54 +08:00
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
|
1998-12-14 02:52:34 +08:00
|
|
|
gdisplays_resize_cursor_label (gimage);
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_full (gimage);
|
|
|
|
gdisplays_shrink_wrap (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
2000-12-30 08:16:50 +08:00
|
|
|
gimage_restructure_handler (GimpImage *gimage)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_title (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
static void
|
1999-10-14 07:07:45 +08:00
|
|
|
gimage_repaint_handler (GimpImage *gimage,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_area (gimage, x, y, w, h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
|
|
|
|
/* These really belong in the layer class */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimage_set_layer_mask_apply (GimpImage *gimage,
|
1999-07-20 03:46:05 +08:00
|
|
|
GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
gint off_x, off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-20 03:46:05 +08:00
|
|
|
g_return_if_fail (gimage);
|
|
|
|
g_return_if_fail (layer);
|
1998-06-30 09:14:36 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
if (! layer->mask)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
layer->apply_mask = ! layer->apply_mask;
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_area (gimage, off_x, off_y,
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_width (GIMP_DRAWABLE (layer)),
|
|
|
|
gimp_drawable_height (GIMP_DRAWABLE (layer)));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1997-12-08 09:13:10 +08:00
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimage_set_layer_mask_edit (GimpImage *gimage,
|
2001-01-29 07:25:25 +08:00
|
|
|
GimpLayer *layer,
|
2001-01-29 00:44:22 +08:00
|
|
|
gboolean edit)
|
1997-12-08 09:13:10 +08:00
|
|
|
{
|
1998-06-28 18:39:58 +08:00
|
|
|
/* find the layer */
|
|
|
|
if (!layer)
|
|
|
|
return;
|
1997-12-08 09:13:10 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
if (layer->mask)
|
|
|
|
layer->edit_mask = edit;
|
1997-12-08 09:13:10 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimage_set_layer_mask_show (GimpImage *gimage,
|
1999-07-20 03:46:05 +08:00
|
|
|
GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-30 08:16:50 +08:00
|
|
|
gint off_x, off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-20 03:46:05 +08:00
|
|
|
g_return_if_fail (gimage);
|
|
|
|
g_return_if_fail (layer);
|
1998-06-30 09:14:36 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
if (! layer->mask)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
layer->show_mask = ! layer->show_mask;
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_update_area (gimage, off_x, off_y,
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_width (GIMP_DRAWABLE (layer)),
|
|
|
|
gimp_drawable_height (GIMP_DRAWABLE (layer)));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|