Gimp/app/core/gimpviewable.c
Michael Natterer 3ef20cd842 major cleanup. After being finished, I decided that it needs to be
2001-06-18  Michael Natterer  <mitch@gimp.org>

	* app/nav_window.[ch]: major cleanup. After being finished, I
	decided that it needs to be factored out to a widget (see below),
	so like 90% of this file will go away soon.

	* app/apptypes.h: added opaque NavigationDialog typedef.

	* app/gdisplay.[ch]: Added gdisplay_selection_visibility() which
	is called from gdisplays_selection_visibility(). Capitalized the
	SelectionControl enum values. Cleaned up the GDisplay struct and
	it's initialisation while i was on it.

	* app/gimage.c: gimage_size_changed_handler(): removed stuff which
	is now done by GimpImage itself.

	* app/scale.c
	* app/scroll.c: also update the navigation popup, not only the
	dialog.

	* app/selection.[ch]: major indentation & cleanup attack. Maybe
	found the "Selection vanishes" bug (the timeout id was assinged to
	a gint, not a _guint_).

	* app/undo.c: s/gimp_image_size_changed/gimp_viweable_size_changed/

	* app/core/gimpdrawable.c: invalidate the image's preview from our
	"invalidate_preview" implementation. This means that the image's
	preview is invalidated way too often currently, which cries for
	some general freeze/thaw mechanism on the GimpViewable level.
	(Note that previews are rendered in the idle loop, so this is not
	really a major performance impact, it's just ugly).

	* app/core/gimpimage.[ch]: removed the "size_changed" signal...

	* app/core/gimpviewable.[ch]: ...and added it here.

	* app/core/gimplayer.c: invalidate_preview(): always chain up,
	also if it's a floating selection.

	* app/gui/info-dialog.[ch]
	* app/gui/info-window.c: minor cleanups.

	* app/gui/preferences-dialog.c: no need to invalidate the image
	after we have invalidated all it's layers.

	* app/core/gimpimage-mask.c
	* app/gui/commands.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppainttool.c: capitalized the SelectionCommand enum
	values.

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

	* app/widgets/gimppreview.[ch]: added a non-working
	non-dot-for-dot mode. Added xres/yres params to the
	gimp_preview_calc_size() helper function.

	Cache the "size" value which was passed to the simple function
	variants (gimp_preview_new() and gimp_preview_set_size()) so we
	can re-calculate the preview's extents on the underlying
	viewable's "size_changed" signal and on gimp_preview_set_viewable().

	* app/widgets/gimpdrawablepreview.c
	* app/widgets/gimpimagepreview.c: changed accordingly.
2001-06-18 13:10:03 +00:00

236 lines
6 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpviewable.h
* Copyright (C) 2001 Michael Natterer <mitch@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 "core-types.h"
#include "base/temp-buf.h"
#include "gimpmarshal.h"
#include "gimpviewable.h"
enum
{
INVALIDATE_PREVIEW,
SIZE_CHANGED,
GET_PREVIEW,
GET_NEW_PREVIEW,
LAST_SIGNAL
};
static void gimp_viewable_class_init (GimpViewableClass *klass);
static void gimp_viewable_init (GimpViewable *viewable);
static void gimp_viewable_real_invalidate_preview (GimpViewable *viewable);
static guint viewable_signals[LAST_SIGNAL] = { 0 };
static GimpObjectClass *parent_class = NULL;
GtkType
gimp_viewable_get_type (void)
{
static GtkType viewable_type = 0;
if (! viewable_type)
{
GtkTypeInfo viewable_info =
{
"GimpViewable",
sizeof (GimpViewable),
sizeof (GimpViewableClass),
(GtkClassInitFunc) gimp_viewable_class_init,
(GtkObjectInitFunc) gimp_viewable_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
viewable_type = gtk_type_unique (GIMP_TYPE_OBJECT, &viewable_info);
}
return viewable_type;
}
static void
gimp_viewable_class_init (GimpViewableClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
viewable_signals[INVALIDATE_PREVIEW] =
gtk_signal_new ("invalidate_preview",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpViewableClass,
invalidate_preview),
gtk_signal_default_marshaller,
GTK_TYPE_NONE, 0);
viewable_signals[SIZE_CHANGED] =
gtk_signal_new ("size_changed",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpViewableClass,
size_changed),
gtk_signal_default_marshaller,
GTK_TYPE_NONE, 0);
viewable_signals[GET_PREVIEW] =
gtk_signal_new ("get_preview",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpViewableClass,
get_preview),
gimp_marshal_POINTER__INT_INT,
GTK_TYPE_POINTER, 3,
GTK_TYPE_POINTER,
GTK_TYPE_INT,
GTK_TYPE_INT);
viewable_signals[GET_NEW_PREVIEW] =
gtk_signal_new ("get_new_preview",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpViewableClass,
get_new_preview),
gimp_marshal_POINTER__INT_INT,
GTK_TYPE_POINTER, 3,
GTK_TYPE_POINTER,
GTK_TYPE_INT,
GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, viewable_signals, LAST_SIGNAL);
klass->invalidate_preview = gimp_viewable_real_invalidate_preview;
klass->size_changed = NULL;
klass->get_preview = NULL;
klass->get_new_preview = NULL;
}
static void
gimp_viewable_init (GimpViewable *viewable)
{
}
void
gimp_viewable_invalidate_preview (GimpViewable *viewable)
{
g_return_if_fail (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[INVALIDATE_PREVIEW]);
}
void
gimp_viewable_size_changed (GimpViewable *viewable)
{
g_return_if_fail (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[SIZE_CHANGED]);
}
static void
gimp_viewable_real_invalidate_preview (GimpViewable *viewable)
{
g_return_if_fail (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
gtk_object_set_data (GTK_OBJECT (viewable), "static-viewable-preview", NULL);
}
TempBuf *
gimp_viewable_get_preview (GimpViewable *viewable,
gint width,
gint height)
{
TempBuf *temp_buf = NULL;
g_return_val_if_fail (viewable, NULL);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_PREVIEW],
width, height, &temp_buf);
if (temp_buf)
return temp_buf;
temp_buf = gtk_object_get_data (GTK_OBJECT (viewable),
"static-viewable-preview");
if (temp_buf &&
temp_buf->width == width &&
temp_buf->height == height)
return temp_buf;
temp_buf = NULL;
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_NEW_PREVIEW],
width, height, &temp_buf);
gtk_object_set_data_full (GTK_OBJECT (viewable), "static-viewable-preview",
temp_buf,
(GtkDestroyNotify) temp_buf_free);
return temp_buf;
}
TempBuf *
gimp_viewable_get_new_preview (GimpViewable *viewable,
gint width,
gint height)
{
TempBuf *temp_buf = NULL;
g_return_val_if_fail (viewable, NULL);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_NEW_PREVIEW],
width, height, &temp_buf);
if (temp_buf)
return temp_buf;
gtk_signal_emit (GTK_OBJECT (viewable), viewable_signals[GET_PREVIEW],
width, height, &temp_buf);
if (temp_buf)
return temp_buf_copy (temp_buf, NULL);
return NULL;
}