1997-11-25 06:05:25 +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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-03-29 07:39:32 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gdisplay.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
#include "gimpellipseselecttool.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "selection_options.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tool_options.h"
|
2001-03-08 12:15:32 +08:00
|
|
|
#include "tool_manager.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-05-14 08:04:29 +08:00
|
|
|
#define WANT_ELLIPSE_SELECT_BITS
|
|
|
|
#include "icons.h"
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
static void gimp_ellipse_select_tool_class_init (GimpEllipseSelectToolClass *klass);
|
|
|
|
static void gimp_ellipse_select_tool_init (GimpEllipseSelectTool *ellipse_select);
|
|
|
|
static void gimp_ellipse_select_tool_destroy (GtkObject *object);
|
|
|
|
|
|
|
|
static void gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
|
|
|
static void gimp_ellipse_select_tool_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
|
|
|
|
|
|
|
|
|
|
|
static GimpRectSelectToolClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static SelectionOptions *ellipse_options = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_ellipse_select_tool_register (void)
|
|
|
|
{
|
|
|
|
tool_manager_register_tool (GIMP_TYPE_ELLIPSE_SELECT_TOOL, FALSE,
|
|
|
|
"gimp:ellipse_select_tool",
|
|
|
|
_("Ellipse Select"),
|
|
|
|
_("Select elliptical regions"),
|
|
|
|
_("/Tools/Selection Tools/Ellipse Select"), "E",
|
|
|
|
NULL, "tools/ellipse_select.html",
|
2001-05-14 08:04:29 +08:00
|
|
|
(const gchar **) ellipse_select_bits);
|
2001-03-08 12:15:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gimp_ellipse_select_tool_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType ellipse_select_type = 0;
|
|
|
|
|
|
|
|
if (! ellipse_select_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo ellipse_select_info =
|
|
|
|
{
|
|
|
|
"GimpEllipseSelectTool",
|
|
|
|
sizeof (GimpEllipseSelectTool),
|
|
|
|
sizeof (GimpEllipseSelectToolClass),
|
|
|
|
(GtkClassInitFunc) gimp_ellipse_select_tool_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_ellipse_select_tool_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
ellipse_select_type = gtk_type_unique (GIMP_TYPE_RECT_SELECT_TOOL,
|
|
|
|
&ellipse_select_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ellipse_select_type;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void
|
1999-04-19 05:22:41 +08:00
|
|
|
ellipse_select (GimpImage *gimage,
|
2000-03-29 07:39:32 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
SelectOps op,
|
|
|
|
gboolean antialias,
|
|
|
|
gboolean feather,
|
|
|
|
gdouble feather_radius)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
GimpChannel *new_mask;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if applicable, replace the current selection */
|
1999-05-05 17:10:35 +08:00
|
|
|
if (op == SELECTION_REPLACE)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimage_mask_clear (gimage);
|
|
|
|
else
|
|
|
|
gimage_mask_undo (gimage);
|
|
|
|
|
|
|
|
/* if feathering for rect, make a new mask with the
|
|
|
|
* rectangle and feather that with the old mask
|
|
|
|
*/
|
|
|
|
if (feather)
|
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
new_mask = gimp_channel_new_mask (gimage, gimage->width, gimage->height);
|
|
|
|
gimp_channel_combine_ellipse (new_mask, CHANNEL_OP_ADD,
|
|
|
|
x, y, w, h, antialias);
|
|
|
|
gimp_channel_feather (new_mask, gimp_image_get_mask (gimage),
|
|
|
|
feather_radius,
|
|
|
|
feather_radius,
|
|
|
|
op, 0, 0);
|
2001-01-29 08:46:04 +08:00
|
|
|
gtk_object_unref (GTK_OBJECT (new_mask));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-05-05 17:10:35 +08:00
|
|
|
else if (op == SELECTION_INTERSECT)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
new_mask = gimp_channel_new_mask (gimage, gimage->width, gimage->height);
|
|
|
|
gimp_channel_combine_ellipse (new_mask, CHANNEL_OP_ADD,
|
|
|
|
x, y, w, h, antialias);
|
|
|
|
gimp_channel_combine_mask (gimp_image_get_mask (gimage), new_mask,
|
|
|
|
op, 0, 0);
|
2001-01-29 08:46:04 +08:00
|
|
|
gtk_object_unref (GTK_OBJECT (new_mask));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2001-01-29 10:45:02 +08:00
|
|
|
{
|
|
|
|
gimp_channel_combine_ellipse (gimp_image_get_mask (gimage), op,
|
|
|
|
x, y, w, h, antialias);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ellipse_select_tool_class_init (GimpEllipseSelectToolClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-08 12:15:32 +08:00
|
|
|
GtkObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
|
|
|
GimpRectSelectToolClass *rect_tool_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
object_class = (GtkObjectClass *) klass;
|
|
|
|
tool_class = (GimpToolClass *) klass;
|
|
|
|
draw_tool_class = (GimpDrawToolClass *) klass;
|
|
|
|
rect_tool_class = (GimpRectSelectToolClass *) klass;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_RECT_SELECT_TOOL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
object_class->destroy = gimp_ellipse_select_tool_destroy;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_ellipse_select_tool_draw;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
rect_tool_class->rect_select = gimp_ellipse_select_tool_rect_select;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
2001-03-08 12:15:32 +08:00
|
|
|
gimp_ellipse_select_tool_init (GimpEllipseSelectTool *ellipse_select)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2001-03-08 12:15:32 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionTool *select_tool;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
tool = GIMP_TOOL (ellipse_select);
|
|
|
|
select_tool = GIMP_SELECTION_TOOL (ellipse_select);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
if (! ellipse_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
ellipse_options = selection_options_new (GIMP_TYPE_ELLIPSE_SELECT_TOOL,
|
|
|
|
selection_options_reset);
|
2001-03-08 12:15:32 +08:00
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_ELLIPSE_SELECT_TOOL,
|
|
|
|
(ToolOptions *) ellipse_options);
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
tool->tool_cursor = GIMP_ELLIPSE_SELECT_TOOL_CURSOR;
|
|
|
|
tool->preserve = FALSE; /* Don't preserve on drawable change */
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
static void
|
|
|
|
gimp_ellipse_select_tool_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
static void
|
|
|
|
gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
GimpRectSelectTool *rect_sel;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
tool = GIMP_TOOL (draw_tool);
|
|
|
|
rect_sel = GIMP_RECT_SELECT_TOOL (draw_tool);
|
|
|
|
|
|
|
|
x1 = MIN (rect_sel->x, rect_sel->x + rect_sel->w);
|
|
|
|
y1 = MIN (rect_sel->y, rect_sel->y + rect_sel->h);
|
|
|
|
x2 = MAX (rect_sel->x, rect_sel->x + rect_sel->w);
|
|
|
|
y2 = MAX (rect_sel->y, rect_sel->y + rect_sel->h);
|
2001-02-25 03:29:47 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
gdisplay_transform_coords (tool->gdisp, x1, y1, &x1, &y1, 0);
|
|
|
|
gdisplay_transform_coords (tool->gdisp, x2, y2, &x2, &y2, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
gdk_draw_arc (draw_tool->win,
|
|
|
|
draw_tool->gc,
|
|
|
|
0,
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1),
|
|
|
|
0, 23040);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
static void
|
|
|
|
gimp_ellipse_select_tool_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-08 12:15:32 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
SelectionOptions *sel_options;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (rect_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
sel_options = (SelectionOptions *)
|
|
|
|
tool_manager_get_info_by_tool (tool)->tool_options;
|
|
|
|
|
|
|
|
ellipse_select (tool->gdisp->gimage,
|
|
|
|
x, y, w, h,
|
|
|
|
sel_tool->op,
|
|
|
|
sel_options->antialias,
|
|
|
|
sel_options->feather,
|
|
|
|
sel_options->feather_radius);
|
|
|
|
}
|