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-08-06 00:08:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
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-10-22 20:13:44 +08:00
|
|
|
#include "core/gimpimage-mask-select.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
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-07-07 20:17:23 +08:00
|
|
|
#include "app_procs.h"
|
|
|
|
|
2001-03-08 12:15:32 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
|
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_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
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_ellipse_select_tool_register (Gimp *gimp)
|
2001-03-08 12:15:32 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_ELLIPSE_SELECT_TOOL,
|
|
|
|
FALSE,
|
2001-03-08 12:15:32 +08:00
|
|
|
"gimp:ellipse_select_tool",
|
|
|
|
_("Ellipse Select"),
|
|
|
|
_("Select elliptical regions"),
|
|
|
|
_("/Tools/Selection Tools/Ellipse Select"), "E",
|
|
|
|
NULL, "tools/ellipse_select.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_ELLIPSE_SELECT);
|
2001-03-08 12:15:32 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-03-08 12:15:32 +08:00
|
|
|
gimp_ellipse_select_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-03-08 12:15:32 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
if (! tool_type)
|
2001-03-08 12:15:32 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-03-08 12:15:32 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpEllipseSelectToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_ellipse_select_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpEllipseSelectTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_ellipse_select_tool_init,
|
2001-03-08 12:15:32 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_RECT_SELECT_TOOL,
|
|
|
|
"GimpEllipseSelectTool",
|
|
|
|
&tool_info, 0);
|
2001-03-08 12:15:32 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
return tool_type;
|
2001-03-08 12:15:32 +08:00
|
|
|
}
|
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
|
|
|
GimpDrawToolClass *draw_tool_class;
|
|
|
|
GimpRectSelectToolClass *rect_tool_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
|
|
|
rect_tool_class = GIMP_RECT_SELECT_TOOL_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-08 12:15:32 +08:00
|
|
|
|
|
|
|
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,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) 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_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 *)
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_get_info_by_tool (the_gimp, tool)->tool_options;
|
2001-03-08 12:15:32 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_image_mask_select_ellipse (tool->gdisp->gimage,
|
|
|
|
x, y, w, h,
|
|
|
|
sel_tool->op,
|
|
|
|
sel_options->antialias,
|
|
|
|
sel_options->feather,
|
|
|
|
sel_options->feather_radius,
|
|
|
|
sel_options->feather_radius);
|
2001-03-08 12:15:32 +08:00
|
|
|
}
|