Gimp/app/tools/gimpimagemaptool.c
Michael Natterer 305db405b2 added "gchar *stock_id" to the GimpViewable struct. It is used by the GUI
2003-02-26  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpviewable.[ch]: added "gchar *stock_id" to the
	GimpViewable struct. It is used by the GUI if the get_preview()
	functions return NULL. Default to GTK_STOCK_DIALOG_QUESTION.

	* app/core/gimptoolinfo.[ch]: set the tool's stock_id. Removed
	the cached GdkPixbuf. Don't implement any preview function
	so the GUI uses the stock_id.

	* app/tools/tool_manager.c: removed GdkPixbuf creation, removed
	the #warning about the buggy way we created the pixbuf.

	* app/gui/dialogs-constructors.c
	* app/gui/image-menu.c
	* app/tools/gimpcroptool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimpimagemaptool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimptransformtool.c
	* app/widgets/gimptoolbox.c: use viewable->stock_id instead
	of tool_info->stock_id.

	* app/core/gimpbrush.c
	* app/core/gimpgradient.c
	* app/core/gimpimagefile.c
	* app/core/gimpundo.c: simplified get_preview() implementations:

	- never scale previews up, only down.
	- don't render white or checks backgrounds but simply return
	  TempBufs with alpha and let the preview system do its job.
	- don't add padding but simply return previews smaller than
	  requested.

	* app/display/gimpdisplayshell-render.[ch]: added
	"render_blend_white", a 2d lookup table for blending on white,
	just as the check lookup tables. Added "render_white_buf".

	* app/widgets/gimppreview.[ch]: changed a lot:

	- don't render the preview's border into the buffer.
	- added "GdkGC *border_gc" and draw the preview's border in expose()
	  using gdk_draw_rectangle().
	- added "GdkPixbuf *no_preview_pixbuf" and create it in
	  gimp_preview_real_render() if gimp_viewable_get_preview()
	  returned NULL.
	- factored the actual preview rendering out to
	  gimp_preview_render_to_buffer(). Added configurable background
	  rendering for the preview itself and it's padding area
	  (the area the preview is larger than the buffer returned
	  by gimp_viewable_get_preview()).
	- changed gimp_preview_render_and_flush() to
	  gimp_preview_render_preview() and added "inside_bg" and
	  "outside_bg" parameters.
	- use the new render buffers for blending on white.

	* app/widgets/gimpbrushpreview.c
	* app/widgets/gimpbufferpreview.c
	* app/widgets/gimpdrawablepreview.c
	* app/widgets/gimpgradientpreview.c
	* app/widgets/gimpimagepreview.c
	* app/widgets/gimppalettepreview.c
	* app/widgets/gimppatternpreview.c: don't create large white
	TempBufs to center the previews in but simply set the TempBuf's
	offsets to get them centered. Simplified & cleaned up many preview
	render functions. Pass the correct GimpPreviewBG modes to
	gimp_preview_render_preview().

	* app/widgets/gimpcellrendererviewable.[ch]: new GtkCellRenderer
	class derived from GtkCellRendererPixbuf which knows how
	to use gimp_viewable_get_preview_size() and renders the
	viewable's stock item if no preview can be created.

	* app/widgets/gimpcontainertreeview.c: added a GtkTreeCellDataFunc
	which creates the preview pixbuf if needed so we don't create it
	unconditionally upon item insertion. Fixed preview size assertion
	to use GIMP_PREVIEW_MAX_SIZE, not "64". Block "selection_changed"
	while reordering the selected item.

	* app/widgets/gimpcontainerview.c: cosmetic.

	* app/widgets/gimpimagefilepreview.[ch]
	* app/widgets/gimptoolinfopreview.[ch]
	* app/widgets/gimpundopreview.[ch]: removed because the default
	implementation is good enough.

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimppreview-utils.c: changed accordingly.

	* app/gui/dialogs-constructors.[ch]
	* app/gui/dialogs-menu.c
	* app/gui/dialogs.c
	* app/gui/image-menu.c
	* app/gui/toolbox-menu.c: register grid and tree view variants
	of the document history.

	Unrelated:

	* app/gui/gui.c (gui_exit_finish_callback): disconnect from
	signals earlier.

	* app/gui/user-install-dialog.c: create the "tool-options" subdir
	of the user's ~/.gimp-1.3 directory.
2003-02-26 16:17:10 +00:00

427 lines
12 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 "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "gimpimagemaptool.h"
#include "tool_manager.h"
#include "libgimp/gimpintl.h"
/* local function prototypes */
static void gimp_image_map_tool_class_init (GimpImageMapToolClass *klass);
static void gimp_image_map_tool_init (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_finalize (GObject *object);
static void gimp_image_map_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp);
static void gimp_image_map_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp);
static void gimp_image_map_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_reset (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_flush (GimpImageMap *image_map,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_cancel_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_reset_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_ok_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_preview_toggled (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static GimpToolClass *parent_class = NULL;
GType
gimp_image_map_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpImageMapToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_image_map_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpImageMapTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_image_map_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
"GimpImageMapTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
{
GObjectClass *object_class;
GimpToolClass *tool_class;
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_image_map_tool_finalize;
tool_class->initialize = gimp_image_map_tool_initialize;
tool_class->control = gimp_image_map_tool_control;
klass->map = NULL;
klass->dialog = NULL;
klass->reset = NULL;
}
static void
gimp_image_map_tool_init (GimpImageMapTool *image_map_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (image_map_tool);
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_preserve (tool->control, FALSE);
image_map_tool->drawable = NULL;
image_map_tool->image_map = NULL;
image_map_tool->preview = TRUE;
image_map_tool->shell_desc = NULL;
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
}
void
gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
{
GimpTool *tool;
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));
tool = GIMP_TOOL (image_map_tool);
if (image_map_tool->preview)
{
gimp_tool_control_set_preserve (tool->control, TRUE);
gimp_image_map_tool_map (image_map_tool);
gimp_tool_control_set_preserve (tool->control, FALSE);
}
}
static void
gimp_image_map_tool_finalize (GObject *object)
{
GimpImageMapTool *image_map_tool;
image_map_tool = GIMP_IMAGE_MAP_TOOL (object);
if (image_map_tool->shell)
{
gtk_widget_destroy (image_map_tool->shell);
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_image_map_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpImageMapTool *image_map_tool;
GimpToolInfo *tool_info;
GimpDrawable *drawable;
image_map_tool = GIMP_IMAGE_MAP_TOOL (tool);
tool_info = tool->tool_info;
/* set gdisp so the dialog can be hidden on display destruction */
tool->gdisp = gdisp;
if (! image_map_tool->shell)
{
GtkWidget *shell;
GtkWidget *vbox;
GtkWidget *toggle;
image_map_tool->shell = shell =
gimp_viewable_dialog_new (NULL,
tool_info->blurb,
GIMP_OBJECT (tool_info)->name,
GIMP_VIEWABLE (tool_info)->stock_id,
image_map_tool->shell_desc,
tool_manager_help_func, NULL,
GIMP_STOCK_RESET,
gimp_image_map_tool_reset_clicked,
image_map_tool, NULL, NULL, FALSE, FALSE,
GTK_STOCK_CANCEL,
gimp_image_map_tool_cancel_clicked,
image_map_tool, NULL, NULL, FALSE, TRUE,
GTK_STOCK_OK,
gimp_image_map_tool_ok_clicked,
image_map_tool, NULL, NULL, TRUE, FALSE,
NULL);
image_map_tool->main_vbox = vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
/* The preview toggle */
toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
image_map_tool->preview);
gtk_box_pack_end (GTK_BOX (image_map_tool->main_vbox), toggle,
FALSE, FALSE, 0);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_image_map_tool_preview_toggled),
image_map_tool);
/* Fill in subclass widgets */
gimp_image_map_tool_dialog (image_map_tool);
gtk_widget_show (vbox);
}
drawable = gimp_image_active_drawable (gdisp->gimage);
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (image_map_tool->shell),
GIMP_VIEWABLE (drawable));
gtk_widget_show (image_map_tool->shell);
image_map_tool->drawable = drawable;
image_map_tool->image_map = gimp_image_map_new (TRUE, drawable,
tool_info->blurb);
g_signal_connect (image_map_tool->image_map, "flush",
G_CALLBACK (gimp_image_map_tool_flush),
image_map_tool);
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
gimp_item_factory_update (shell->menubar_factory, shell);
gimp_item_factory_update (shell->popup_factory, shell);
}
}
static void
gimp_image_map_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp)
{
GimpImageMapTool *image_map_tool;
image_map_tool = GIMP_IMAGE_MAP_TOOL (tool);
switch (action)
{
case PAUSE:
break;
case RESUME:
break;
case HALT:
if (image_map_tool->shell)
gimp_image_map_tool_cancel_clicked (NULL, image_map_tool);
break;
default:
break;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
static void
gimp_image_map_tool_map (GimpImageMapTool *image_map_tool)
{
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->map (image_map_tool);
}
static void
gimp_image_map_tool_dialog (GimpImageMapTool *image_map_tool)
{
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->dialog (image_map_tool);
}
static void
gimp_image_map_tool_reset (GimpImageMapTool *image_map_tool)
{
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->reset (image_map_tool);
}
static void
gimp_image_map_tool_flush (GimpImageMap *image_map,
GimpImageMapTool *image_map_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (image_map_tool);
gimp_display_flush_now (tool->gdisp);
}
static void
gimp_image_map_tool_cancel_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (image_map_tool);
gtk_widget_hide (image_map_tool->shell);
if (image_map_tool->image_map)
{
gimp_tool_control_set_preserve (tool->control, TRUE);
gimp_image_map_abort (image_map_tool->image_map);
image_map_tool->image_map = NULL;
gimp_tool_control_set_preserve (tool->control, FALSE);
gimp_image_flush (tool->gdisp->gimage);
}
tool->gdisp = NULL;
tool->drawable = NULL;
}
static void
gimp_image_map_tool_reset_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
gimp_image_map_tool_reset (image_map_tool);
gimp_image_map_tool_preview (image_map_tool);
}
static void
gimp_image_map_tool_ok_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
GimpDisplayShell *shell;
GimpTool *tool;
tool = GIMP_TOOL (image_map_tool);
gtk_widget_hide (image_map_tool->shell);
gimp_tool_control_set_preserve (tool->control, TRUE);
if (! image_map_tool->preview)
{
gimp_image_map_tool_map (image_map_tool);
}
if (image_map_tool->image_map)
{
gimp_image_map_commit (image_map_tool->image_map);
image_map_tool->image_map = NULL;
}
gimp_tool_control_set_preserve (tool->control, FALSE);
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
gimp_item_factory_update (shell->menubar_factory, shell);
gimp_item_factory_update (shell->popup_factory, shell);
tool->gdisp = NULL;
tool->drawable = NULL;
}
static void
gimp_image_map_tool_preview_toggled (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (image_map_tool);
image_map_tool->preview = GTK_TOGGLE_BUTTON (widget)->active;
if (image_map_tool->preview)
{
gimp_tool_control_set_preserve (tool->control, TRUE);
gimp_image_map_tool_map (image_map_tool);
gimp_tool_control_set_preserve (tool->control, FALSE);
}
else
{
if (image_map_tool->image_map)
{
gimp_tool_control_set_preserve (tool->control, TRUE);
gimp_image_map_clear (image_map_tool->image_map);
gimp_tool_control_set_preserve (tool->control, FALSE);
gimp_image_flush (tool->gdisp->gimage);
}
}
}