app/tools/Makefile.am added options for GimpForegroundSelectionTool.

2005-07-31  Sven Neumann  <sven@gimp.org>

	* app/tools/Makefile.am
	* app/tools/gimpforegroundselectoptions.[ch]: added options for
	GimpForegroundSelectionTool.

	* app/tools/gimpforegroundselecttool.c: also allow to classify
	background pixels.

	* app/tools/gimpfreeselecttool.c: implement GimpTool::control and
	reset the points array if the tool is HALTed.
This commit is contained in:
Sven Neumann 2005-07-31 18:29:10 +00:00 committed by Sven Neumann
parent 0357e6489d
commit 52d1c1ef95
6 changed files with 289 additions and 16 deletions

View File

@ -1,3 +1,15 @@
2005-07-31 Sven Neumann <sven@gimp.org>
* app/tools/Makefile.am
* app/tools/gimpforegroundselectoptions.[ch]: added options for
GimpForegroundSelectionTool.
* app/tools/gimpforegroundselecttool.c: also allow to classify
background pixels.
* app/tools/gimpfreeselecttool.c: implement GimpTool::control and
reset the points array if the tool is HALTed.
2005-07-31 Sven Neumann <sven@gimp.org>
* app/tools/gimpforegroundselecttool.c: give some visual feedback

View File

@ -68,6 +68,8 @@ libapptools_a_sources = \
gimpfliptool.h \
gimpfreeselecttool.c \
gimpfreeselecttool.h \
gimpforegroundselectoptions.c \
gimpforegroundselectoptions.h \
gimpforegroundselecttool.c \
gimpforegroundselecttool.h \
gimpfuzzyselecttool.c \

View File

@ -0,0 +1,151 @@
/* 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 "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimptoolinfo.h"
#include "gimpforegroundselectoptions.h"
#include "gimptooloptions-gui.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_BACKGROUND
};
static void gimp_foreground_select_options_class_init (GimpForegroundSelectOptionsClass *klass);
static void gimp_foreground_select_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_foreground_select_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
GType
gimp_foreground_select_options_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo info =
{
sizeof (GimpForegroundSelectOptionsClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_foreground_select_options_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpForegroundSelectOptions),
0, /* n_preallocs */
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GIMP_TYPE_SELECTION_OPTIONS,
"GimpForegroundSelectOptions",
&info, 0);
}
return type;
}
static void
gimp_foreground_select_options_class_init (GimpForegroundSelectOptionsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gimp_foreground_select_options_set_property;
object_class->get_property = gimp_foreground_select_options_get_property;
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_BACKGROUND,
"background", NULL,
FALSE,
0);
}
static void
gimp_foreground_select_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpForegroundSelectOptions *options = GIMP_FOREGROUND_SELECT_OPTIONS (object);
switch (property_id)
{
case PROP_BACKGROUND:
options->background = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_foreground_select_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpForegroundSelectOptions *options = GIMP_FOREGROUND_SELECT_OPTIONS (object);
switch (property_id)
{
case PROP_BACKGROUND:
g_value_set_boolean (value, options->background);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GtkWidget *
gimp_foreground_select_options_gui (GimpToolOptions *tool_options)
{
GtkWidget *vbox = gimp_selection_options_gui (tool_options);
GtkWidget *frame;
frame = gimp_prop_boolean_radio_frame_new ( G_OBJECT (tool_options),
"background",
_("Interactive refinement"),
_("Mark background"),
_("Mark foreground"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
return vbox;
}

View File

@ -0,0 +1,50 @@
/* 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.
*/
#ifndef __GIMP_FOREGROUND_SELECT_OPTIONS_H__
#define __GIMP_FOREGROUND_SELECT_OPTIONS_H__
#include "gimpselectionoptions.h"
#define GIMP_TYPE_FOREGROUND_SELECT_OPTIONS (gimp_foreground_select_options_get_type ())
#define GIMP_FOREGROUND_SELECT_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_FOREGROUND_SELECT_OPTIONS, GimpForegroundSelectOptions))
#define GIMP_FOREGROUND_SELECT_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_FOREGROUND_SELECT_OPTIONS, GimpForegroundSelectOptionsClass))
#define GIMP_IS_FOREGROUND_SELECT_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_FOREGROUND_SELECT_OPTIONS))
#define GIMP_IS_FOREGROUND_SELECT_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_FOREGROUND_SELECT_OPTIONS))
#define GIMP_FOREGROUND_SELECT_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FOREGROUND_SELECT_OPTIONS, GimpForegroundSelectOptionsClass))
typedef struct _GimpForegroundSelectOptions GimpForegroundSelectOptions;
typedef GimpSelectionOptionsClass GimpForegroundSelectOptionsClass;
struct _GimpForegroundSelectOptions
{
GimpSelectionOptions parent_instance;
gboolean background;
};
GType gimp_foreground_select_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_foreground_select_options_gui (GimpToolOptions *tool_options);
#endif /* __GIMP_FOREGROUND_SELECT_OPTIONS_H__ */

View File

@ -44,7 +44,7 @@
#include "display/gimpdisplayshell.h"
#include "gimpforegroundselecttool.h"
#include "gimpselectionoptions.h"
#include "gimpforegroundselectoptions.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
@ -113,8 +113,8 @@ gimp_foreground_select_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_FOREGROUND_SELECT_TOOL,
GIMP_TYPE_SELECTION_OPTIONS,
gimp_selection_options_gui,
GIMP_TYPE_FOREGROUND_SELECT_OPTIONS,
gimp_foreground_select_options_gui,
0,
"gimp-foreground-select-tool",
_("Foreground Select"),
@ -191,8 +191,6 @@ gimp_foreground_select_tool_init (GimpForegroundSelectTool *fg_select)
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
fg_select->stroke = NULL;
fg_select->stroke_width = 6;
@ -302,6 +300,12 @@ gimp_foreground_select_tool_cursor_update (GimpTool *tool,
if (fg_select->mask)
{
GimpForegroundSelectOptions *options;
options = GIMP_FOREGROUND_SELECT_OPTIONS (tool->tool_info->tool_options);
gimp_tool_control_set_toggle (tool->control, options->background);
switch (GIMP_SELECTION_TOOL (tool)->op)
{
case SELECTION_MOVE_MASK:
@ -394,15 +398,24 @@ gimp_foreground_select_tool_button_release (GimpTool *tool,
if (fg_select->mask)
{
GList *list = fg_select->fg_strokes;
GimpForegroundSelectOptions *options;
GList *list;
gimp_tool_control_halt (tool->control);
options = GIMP_FOREGROUND_SELECT_OPTIONS (tool->tool_info->tool_options);
list = (options->background ?
fg_select->bg_strokes : fg_select->fg_strokes);
list = g_list_append (list, GINT_TO_POINTER (fg_select->stroke->len));
list = g_list_append (list, g_array_free (fg_select->stroke, FALSE));
list = g_list_append (list, GINT_TO_POINTER (fg_select->stroke_width));
fg_select->fg_strokes = list;
if (options->background)
fg_select->bg_strokes = list;
else
fg_select->fg_strokes = list;
fg_select->stroke = NULL;
@ -455,11 +468,12 @@ gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (draw_tool);
if (fg_select->stroke)
gimp_draw_tool_draw_lines (draw_tool,
&g_array_index (fg_select->stroke,
GimpVector2, 0),
fg_select->stroke->len,
FALSE, FALSE);
{
const gdouble *points = (const gdouble *) fg_select->stroke->data;
gimp_draw_tool_draw_lines (draw_tool,
points, fg_select->stroke->len, FALSE, FALSE);
}
if (! fg_select->mask)
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
@ -533,6 +547,8 @@ gimp_foreground_select_tool_set_mask (GimpForegroundSelectTool *fg_select,
GimpDisplay *gdisp,
GimpChannel *mask)
{
GimpTool *tool = GIMP_TOOL (fg_select);
if (fg_select->mask == mask)
return;
@ -548,7 +564,28 @@ gimp_foreground_select_tool_set_mask (GimpForegroundSelectTool *fg_select,
gimp_display_shell_set_mask (GIMP_DISPLAY_SHELL (gdisp->shell),
GIMP_DRAWABLE (mask));
gimp_tool_control_set_toggle (GIMP_TOOL (fg_select)->control, mask != NULL);
if (mask)
{
GimpForegroundSelectOptions *options;
options = GIMP_FOREGROUND_SELECT_OPTIONS (tool->tool_info->tool_options);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_ERASER);
gimp_tool_control_set_toggle (tool->control, options->background);
}
else
{
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_toggle (tool->control, FALSE);
}
}
static void
@ -559,8 +596,7 @@ gimp_foreground_select_tool_apply (GimpForegroundSelectTool *fg_select,
GimpChannelOps op = GIMP_SELECTION_TOOL (tool)->op;
GimpSelectionOptions *options;
if (! fg_select->mask)
return;
g_return_if_fail (fg_select->mask != NULL);
if (op > GIMP_CHANNEL_OP_INTERSECT)
op = GIMP_CHANNEL_OP_REPLACE;
@ -575,7 +611,7 @@ gimp_foreground_select_tool_apply (GimpForegroundSelectTool *fg_select,
options->feather_radius,
options->feather_radius);
gimp_foreground_select_tool_set_mask (fg_select, gdisp, NULL);
gimp_tool_control (tool, HALT, gdisp);
gimp_image_flush (gdisp->gimage);
}

View File

@ -48,6 +48,9 @@ static void gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass);
static void gimp_free_select_tool_init (GimpFreeSelectTool *free_select);
static void gimp_free_select_tool_finalize (GObject *object);
static void gimp_free_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp);
static void gimp_free_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
@ -140,6 +143,7 @@ gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
object_class->finalize = gimp_free_select_tool_finalize;
tool_class->control = gimp_free_select_tool_control;
tool_class->button_press = gimp_free_select_tool_button_press;
tool_class->button_release = gimp_free_select_tool_button_release;
tool_class->motion = gimp_free_select_tool_motion;
@ -177,6 +181,24 @@ gimp_free_select_tool_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_free_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *gdisp)
{
switch (action)
{
case HALT:
GIMP_FREE_SELECT_TOOL (tool)->num_points = 0;
break;
default:
break;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
static void
gimp_free_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,