gimp/app/tools/gimpposterizetool.c
Michael Natterer 5dc2b347d2 app/widgets/gimplayerlistview.c some more auto-sizing spinbuttons.
2002-09-08  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimplayerlistview.c
	* app/gui/channels-commands.c: some more auto-sizing spinbuttons.

	* app/gui/offset-dialog.c: added mnemonics for "X" and "Y".

	Dialog auto-hide cleanup:

	* app/widgets/gimpviewabledialog.c: close the dialog when the
	GimpViewable goes away (special cased GimpItems which become
	invisible on "removed"). Close the dialog by syntesizing a
	"delete_event" instead of simply hiding or destroying it so the
	closing method of the dialog's user gets invoked.

	* app/gui/resize-dialog.[ch]: don't do the same here. Simplifies
	the API even more as we don't have to pass the object to watch any
	more.

	* app/gui/image-commands.c
	* app/gui/layers-commands.c: changed accordingly.

	* app/undo_history.c
	* app/gui/convert-dialog.c
	* app/gui/qmask-commands.c
	* app/gui/vectors-commands.c: removed all dialog auto-hiding which
	is now done by GimpViewableDialog. Also connect more close
	callbacks to gtk_widget_destroy() and handle shell destruction
	accordingly, so these pseudo widgets behave more like real ones.

	Tool-dialog auto-hide fix:

	* app/tools/tool_manager.c: never call a tool's initialize()
	method with a NULL gdisp (I can't follow why we did this before
	because it's conceptually broken and makes the semantics of
	initialize() more than unclear).
	To be sure, added g_return_if_fail(GIMP_IS_DISPLAY(gdisp)) to
	tool_manager_initialize_active().

	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimpimagemaptool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimpthresholdtool.c: removed the recently added code
	for handling NULL displays in initialize().
2002-09-08 12:18:23 +00:00

265 lines
7.7 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 "base/gimplut.h"
#include "base/lut-funcs.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "display/gimpdisplay.h"
#include "gimpposterizetool.h"
#include "tool_manager.h"
#include "libgimp/gimpintl.h"
#define POSTERIZE_DEFAULT_LEVELS 3
#define SLIDER_WIDTH 200
static void gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass);
static void gimp_posterize_tool_init (GimpPosterizeTool *bc_tool);
static void gimp_posterize_tool_finalize (GObject *object);
static void gimp_posterize_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp);
static void gimp_posterize_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_posterize_tool_reset (GimpImageMapTool *image_map_tool);
static void posterize_levels_adjustment_update (GtkAdjustment *adjustment,
GimpPosterizeTool *posterize_tool);
static GimpImageMapToolClass *parent_class = NULL;
/* functions */
void
gimp_posterize_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_POSTERIZE_TOOL,
NULL,
FALSE,
"gimp-posterize-tool",
_("Posterize"),
_("Reduce image to a fixed number of colors"),
N_("/Layer/Colors/Posterize..."), NULL,
NULL, "tools/posterize.html",
GIMP_STOCK_TOOL_POSTERIZE,
data);
}
GType
gimp_posterize_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpPosterizeToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_posterize_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPosterizeTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_posterize_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
"GimpPosterizeTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
{
GObjectClass *object_class;
GimpToolClass *tool_class;
GimpImageMapToolClass *image_map_tool_class;
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
image_map_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_posterize_tool_finalize;
tool_class->initialize = gimp_posterize_tool_initialize;
image_map_tool_class->map = gimp_posterize_tool_map;
image_map_tool_class->dialog = gimp_posterize_tool_dialog;
image_map_tool_class->reset = gimp_posterize_tool_reset;
}
static void
gimp_posterize_tool_init (GimpPosterizeTool *posterize_tool)
{
GimpImageMapTool *image_map_tool;
image_map_tool = GIMP_IMAGE_MAP_TOOL (posterize_tool);
image_map_tool->shell_desc = _("Posterize (Reduce Number of Colors)");
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
posterize_tool->lut = gimp_lut_new ();
}
static void
gimp_posterize_tool_finalize (GObject *object)
{
GimpPosterizeTool *posterize_tool;
posterize_tool = GIMP_POSTERIZE_TOOL (object);
if (posterize_tool->lut)
{
gimp_lut_free (posterize_tool->lut);
posterize_tool->lut = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_posterize_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpPosterizeTool *posterize_tool;
posterize_tool = GIMP_POSTERIZE_TOOL (tool);
if (gimp_drawable_is_indexed (gimp_image_active_drawable (gdisp->gimage)))
{
g_message (_("Posterize does not operate on indexed drawables."));
return;
}
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (posterize_tool->levels_data),
posterize_tool->levels);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (posterize_tool));
}
static void
gimp_posterize_tool_map (GimpImageMapTool *image_map_tool)
{
GimpPosterizeTool *posterize_tool;
GimpTool *tool;
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
tool = GIMP_TOOL (image_map_tool);
posterize_lut_setup (posterize_tool->lut,
posterize_tool->levels,
gimp_drawable_bytes (image_map_tool->drawable));
gimp_image_map_apply (image_map_tool->image_map,
(GimpImageMapApplyFunc) gimp_lut_process_2,
posterize_tool->lut);
}
/**********************/
/* Posterize dialog */
/**********************/
static void
gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool)
{
GimpPosterizeTool *posterize_tool;
GtkWidget *table;
GtkWidget *slider;
GtkObject *data;
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
/* The table containing sliders */
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), table,
FALSE, FALSE, 0);
gtk_widget_show (table);
data = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("Posterize _Levels:"), SLIDER_WIDTH, -1,
posterize_tool->levels,
2.0, 256.0, 1.0, 10.0, 0,
TRUE, 0.0, 0.0,
NULL, NULL);
posterize_tool->levels_data = GTK_ADJUSTMENT (data);
slider = GIMP_SCALE_ENTRY_SCALE (data);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
g_signal_connect (G_OBJECT (posterize_tool->levels_data), "value_changed",
G_CALLBACK (posterize_levels_adjustment_update),
posterize_tool);
}
static void
gimp_posterize_tool_reset (GimpImageMapTool *image_map_tool)
{
GimpPosterizeTool *posterize_tool;
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
gtk_adjustment_set_value (GTK_ADJUSTMENT (posterize_tool->levels_data),
posterize_tool->levels);
}
static void
posterize_levels_adjustment_update (GtkAdjustment *adjustment,
GimpPosterizeTool *posterize_tool)
{
if (posterize_tool->levels != adjustment->value)
{
posterize_tool->levels = adjustment->value;
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (posterize_tool));
}
}