mirror of https://github.com/GNOME/gimp.git
Added a Polygon Select Tool which is a primitive selection tool based on
2008-01-30 Martin Nordholts <martinn@svn.gnome.org> Added a Polygon Select Tool which is a primitive selection tool based on Free Hand Select. Code filtered through David Gowers who also made the tool icon. This version of the tool is a for-now solution to bug #119646. * app/tools/gimppolygonselecttool.[ch]: The new tool. * app/tools/gimp-tools.c: Add the tool. * app/tools/Makefile.am: Add tool source. * app/widgets/gimphelp-ids.h: Add help id for the tool. * libgimpwidgets/gimpstock.[ch]: Setup for the new tool icon. * menus/image-menu.xml.in: Add action entry for the tool. * themes/Default/images/tools/stock-tool-polygon-select-{16,24}.png: Tool icon graphics. * themes/Default/images/Makefile.am: Add tool icon graphics. svn path=/trunk/; revision=24753
This commit is contained in:
parent
b8ca285631
commit
919a298092
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
|||
2008-01-30 Martin Nordholts <martinn@svn.gnome.org>
|
||||
|
||||
Added a Polygon Select Tool which is a primitive selection tool
|
||||
based on Free Hand Select. Code filtered through David Gowers who
|
||||
also made the tool icon. This version of the tool is a for-now
|
||||
solution to bug #119646.
|
||||
|
||||
* app/tools/gimppolygonselecttool.[ch]: The new tool.
|
||||
|
||||
* app/tools/gimp-tools.c: Add the tool.
|
||||
|
||||
* app/tools/Makefile.am: Add tool source.
|
||||
|
||||
* app/widgets/gimphelp-ids.h: Add help id for the tool.
|
||||
|
||||
* libgimpwidgets/gimpstock.[ch]: Setup for the new tool icon.
|
||||
|
||||
* menus/image-menu.xml.in: Add action entry for the tool.
|
||||
|
||||
* themes/Default/images/tools/stock-tool-polygon-select-{16,24}.png:
|
||||
Tool icon graphics.
|
||||
|
||||
* themes/Default/images/Makefile.am: Add tool icon graphics.
|
||||
|
||||
2008-01-30 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/tools/gimpimagemaptool.[ch]: add "GObject **config" return
|
||||
|
|
|
@ -120,6 +120,8 @@ libapptools_a_sources = \
|
|||
gimpperspectiveclonetool.h \
|
||||
gimpperspectivetool.c \
|
||||
gimpperspectivetool.h \
|
||||
gimppolygonselecttool.c \
|
||||
gimppolygonselecttool.h \
|
||||
gimpposterizetool.c \
|
||||
gimpposterizetool.h \
|
||||
gimprectangleselecttool.c \
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
#include "gimppenciltool.h"
|
||||
#include "gimpperspectiveclonetool.h"
|
||||
#include "gimpperspectivetool.h"
|
||||
#include "gimppolygonselecttool.h"
|
||||
#include "gimpposterizetool.h"
|
||||
#include "gimpthresholdtool.h"
|
||||
#include "gimprectangleselecttool.h"
|
||||
|
@ -167,6 +168,7 @@ gimp_tools_init (Gimp *gimp)
|
|||
gimp_iscissors_tool_register,
|
||||
gimp_by_color_select_tool_register,
|
||||
gimp_fuzzy_select_tool_register,
|
||||
gimp_polygon_select_tool_register,
|
||||
gimp_free_select_tool_register,
|
||||
gimp_ellipse_select_tool_register,
|
||||
gimp_rect_select_tool_register
|
||||
|
|
|
@ -0,0 +1,615 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
*
|
||||
* A polygonal selection tool for GIMP
|
||||
* Copyright (C) 2007 Martin Nordholts
|
||||
*
|
||||
* Based on gimpfreeselecttool.c which is
|
||||
* 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 <gdk/gdkkeysyms.h>
|
||||
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "tools-types.h"
|
||||
|
||||
#include "core/gimpchannel.h"
|
||||
#include "core/gimpchannel-select.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimplayer-floating-sel.h"
|
||||
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
|
||||
#include "gimppolygonselecttool.h"
|
||||
#include "gimpselectionoptions.h"
|
||||
#include "gimptoolcontrol.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define DEFAULT_MAX_INC 1024
|
||||
|
||||
#define POINT_GRAB_THRESHOLD_SQ 100
|
||||
|
||||
|
||||
struct _GimpPolygonSelectToolPrivate
|
||||
{
|
||||
/* Point which is part of he polygon already. */
|
||||
GimpVector2 *grabbed_point;
|
||||
|
||||
/* Save the grabbed point state so we can cancel a movement
|
||||
* operation.
|
||||
*/
|
||||
GimpVector2 saved_grabbed_point;
|
||||
|
||||
/* Point which is used to draw the polygon but which is not part of
|
||||
* it yet.
|
||||
*/
|
||||
GimpVector2 pending_point;
|
||||
gboolean show_pending_point;
|
||||
|
||||
/* The points of the polygon. */
|
||||
GimpVector2 *points;
|
||||
|
||||
/* The number of points used for the actual selection. */
|
||||
gint num_points;
|
||||
|
||||
gint max_segs;
|
||||
};
|
||||
|
||||
|
||||
static void gimp_polygon_select_tool_finalize (GObject *object);
|
||||
static void gimp_polygon_select_tool_control (GimpTool *tool,
|
||||
GimpToolAction action,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_oper_update (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
gboolean proximity,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_button_press (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_motion (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_button_release (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpButtonReleaseType release_type,
|
||||
GimpDisplay *display);
|
||||
static gboolean gimp_polygon_select_tool_key_press (GimpTool *tool,
|
||||
GdkEventKey *kevent,
|
||||
GimpDisplay *display);
|
||||
|
||||
static void gimp_polygon_select_tool_start (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_commit (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display);
|
||||
static void gimp_polygon_select_tool_halt (GimpPolygonSelectTool *poly_sel_tool);
|
||||
|
||||
static void gimp_polygon_select_tool_draw (GimpDrawTool *draw_tool);
|
||||
|
||||
static void gimp_polygon_select_tool_real_select (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display);
|
||||
|
||||
static GimpVector2 *gimp_polygon_select_tool_add_point (GimpPolygonSelectTool *poly_sel_tool,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
static void gimp_polygon_select_tool_remove_last (GimpPolygonSelectTool *poly_sel_tool);
|
||||
static void gimp_polygon_select_tool_select_closet_point
|
||||
(GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display,
|
||||
GimpCoords *coords);
|
||||
static gboolean gimp_polygon_select_tool_should_close (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display,
|
||||
GimpCoords *coords);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpPolygonSelectTool, gimp_polygon_select_tool,
|
||||
GIMP_TYPE_SELECTION_TOOL);
|
||||
|
||||
|
||||
|
||||
#define parent_class gimp_polygon_select_tool_parent_class
|
||||
|
||||
|
||||
void
|
||||
gimp_polygon_select_tool_register (GimpToolRegisterCallback callback,
|
||||
gpointer data)
|
||||
{
|
||||
(* callback) (GIMP_TYPE_POLYGON_SELECT_TOOL,
|
||||
GIMP_TYPE_SELECTION_OPTIONS,
|
||||
gimp_selection_options_gui,
|
||||
0,
|
||||
"gimp-polygon-select-tool",
|
||||
_("Polygon Select"),
|
||||
_("Polygon Select Tool: Select a hand-drawn polygon"),
|
||||
N_("_Polygon Select"), "G",
|
||||
NULL, GIMP_HELP_TOOL_POLYGON_SELECT,
|
||||
GIMP_STOCK_TOOL_POLYGON_SELECT,
|
||||
data);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_class_init (GimpPolygonSelectToolClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
||||
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpPolygonSelectToolPrivate));
|
||||
|
||||
object_class->finalize = gimp_polygon_select_tool_finalize;
|
||||
|
||||
tool_class->control = gimp_polygon_select_tool_control;
|
||||
tool_class->oper_update = gimp_polygon_select_tool_oper_update;
|
||||
tool_class->button_press = gimp_polygon_select_tool_button_press;
|
||||
tool_class->motion = gimp_polygon_select_tool_motion;
|
||||
tool_class->button_release = gimp_polygon_select_tool_button_release;
|
||||
tool_class->key_press = gimp_polygon_select_tool_key_press;
|
||||
|
||||
draw_tool_class->draw = gimp_polygon_select_tool_draw;
|
||||
|
||||
klass->select = gimp_polygon_select_tool_real_select;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_init (GimpPolygonSelectTool *poly_sel_tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (poly_sel_tool);
|
||||
|
||||
poly_sel_tool->priv = G_TYPE_INSTANCE_GET_PRIVATE (poly_sel_tool,
|
||||
GIMP_TYPE_POLYGON_SELECT_TOOL,
|
||||
GimpPolygonSelectToolPrivate);
|
||||
|
||||
gimp_tool_control_set_scroll_lock (tool->control, FALSE);
|
||||
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
||||
gimp_tool_control_set_tool_cursor (tool->control,
|
||||
GIMP_TOOL_CURSOR_FREE_SELECT);
|
||||
|
||||
poly_sel_tool->priv->points = NULL;
|
||||
poly_sel_tool->priv->max_segs = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_finalize (GObject *object)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (object);
|
||||
|
||||
if (poly_sel_tool->priv->points)
|
||||
{
|
||||
g_free (poly_sel_tool->priv->points);
|
||||
poly_sel_tool->priv->points = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_control (GimpTool *tool,
|
||||
GimpToolAction action,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GIMP_TOOL_ACTION_PAUSE:
|
||||
case GIMP_TOOL_ACTION_RESUME:
|
||||
break;
|
||||
|
||||
case GIMP_TOOL_ACTION_HALT:
|
||||
gimp_polygon_select_tool_halt (GIMP_POLYGON_SELECT_TOOL (tool));
|
||||
break;
|
||||
}
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_oper_update (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
gboolean proximity,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (tool);
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
|
||||
if (tool->display == display)
|
||||
{
|
||||
gimp_polygon_select_tool_select_closet_point (poly_sel_tool,
|
||||
display,
|
||||
coords);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
if (priv->grabbed_point || priv->num_points == 0)
|
||||
{
|
||||
priv->show_pending_point = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->show_pending_point = TRUE;
|
||||
|
||||
priv->pending_point.x = coords->x;
|
||||
priv->pending_point.y = coords->y;
|
||||
}
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_button_press (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (tool);
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
|
||||
if (display != tool->display)
|
||||
{
|
||||
gimp_polygon_select_tool_start (poly_sel_tool, display);
|
||||
|
||||
gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (poly_sel_tool),
|
||||
coords);
|
||||
}
|
||||
|
||||
if (priv->grabbed_point)
|
||||
{
|
||||
priv->saved_grabbed_point = *priv->grabbed_point;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_motion (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
if (tool->display == display)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (tool);
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
|
||||
gimp_draw_tool_pause (draw_tool);
|
||||
|
||||
if (priv->grabbed_point)
|
||||
{
|
||||
priv->grabbed_point->x = coords->x;
|
||||
priv->grabbed_point->y = coords->y;
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->pending_point.x = coords->x;
|
||||
priv->pending_point.y = coords->y;
|
||||
}
|
||||
|
||||
gimp_draw_tool_resume (draw_tool);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_button_release (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpButtonReleaseType release_type,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (tool);
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
|
||||
switch (release_type)
|
||||
{
|
||||
case GIMP_BUTTON_RELEASE_CLICK:
|
||||
if (gimp_polygon_select_tool_should_close (poly_sel_tool,
|
||||
display,
|
||||
coords))
|
||||
{
|
||||
gimp_polygon_select_tool_commit (poly_sel_tool,
|
||||
display);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Fall through */
|
||||
|
||||
case GIMP_BUTTON_RELEASE_NORMAL:
|
||||
if (! priv->grabbed_point)
|
||||
{
|
||||
gimp_polygon_select_tool_add_point (poly_sel_tool, coords->x, coords->y);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We don't need to do anything since the grabbed point have
|
||||
* already been moved in _motion.
|
||||
*/
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_BUTTON_RELEASE_CANCEL:
|
||||
{
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (poly_sel_tool));
|
||||
|
||||
if (priv->grabbed_point)
|
||||
{
|
||||
*priv->grabbed_point = priv->saved_grabbed_point;
|
||||
}
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (poly_sel_tool));
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_BUTTON_RELEASE_NO_MOTION:
|
||||
if (gimp_image_floating_sel (display->image))
|
||||
{
|
||||
/* If there is a floating selection, anchor it */
|
||||
floating_sel_anchor (gimp_image_floating_sel (display->image));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, clear the selection mask */
|
||||
gimp_channel_clear (gimp_image_get_mask (display->image), NULL, TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_polygon_select_tool_key_press (GimpTool *tool,
|
||||
GdkEventKey *kevent,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (tool);
|
||||
gboolean handled_key = FALSE;
|
||||
|
||||
switch (kevent->keyval)
|
||||
{
|
||||
case GDK_BackSpace:
|
||||
gimp_polygon_select_tool_remove_last (poly_sel_tool);
|
||||
handled_key = TRUE;
|
||||
break;
|
||||
|
||||
case GDK_KP_Enter:
|
||||
case GDK_Return:
|
||||
gimp_polygon_select_tool_commit (poly_sel_tool, display);
|
||||
handled_key = TRUE;
|
||||
break;
|
||||
|
||||
case GDK_Escape:
|
||||
gimp_polygon_select_tool_halt (poly_sel_tool);
|
||||
handled_key = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
handled_key = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
return handled_key;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_start (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (poly_sel_tool);
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
||||
|
||||
gimp_polygon_select_tool_halt (poly_sel_tool);
|
||||
|
||||
gimp_tool_control_activate (tool->control);
|
||||
|
||||
tool->display = display;
|
||||
|
||||
poly_sel_tool->priv->num_points = 0;
|
||||
poly_sel_tool->priv->grabbed_point = NULL;
|
||||
poly_sel_tool->priv->show_pending_point = FALSE;
|
||||
|
||||
gimp_draw_tool_start (draw_tool, display);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_commit (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
gimp_polygon_select_tool_select (poly_sel_tool, display);
|
||||
|
||||
gimp_polygon_select_tool_halt (poly_sel_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_halt (GimpPolygonSelectTool *poly_sel_tool)
|
||||
{
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
GimpTool *tool = GIMP_TOOL (poly_sel_tool);
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (poly_sel_tool);
|
||||
|
||||
if (gimp_draw_tool_is_active (draw_tool))
|
||||
gimp_draw_tool_stop (draw_tool);
|
||||
|
||||
if (gimp_tool_control_is_active (tool->control))
|
||||
gimp_tool_control_halt (tool->control);
|
||||
|
||||
priv->grabbed_point = NULL;
|
||||
priv->show_pending_point = FALSE;
|
||||
priv->num_points = 0;
|
||||
|
||||
tool->display = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_draw (GimpDrawTool *draw_tool)
|
||||
{
|
||||
GimpPolygonSelectTool *poly_sel_tool = GIMP_POLYGON_SELECT_TOOL (draw_tool);
|
||||
|
||||
gimp_draw_tool_draw_lines (draw_tool,
|
||||
(const gdouble *) poly_sel_tool->priv->points,
|
||||
poly_sel_tool->priv->num_points,
|
||||
FALSE, FALSE);
|
||||
|
||||
if (poly_sel_tool->priv->show_pending_point)
|
||||
{
|
||||
GimpPolygonSelectToolPrivate *priv;
|
||||
|
||||
priv = poly_sel_tool->priv;
|
||||
|
||||
gimp_draw_tool_draw_line (draw_tool,
|
||||
priv->points[priv->num_points - 1].x,
|
||||
priv->points[priv->num_points - 1].y,
|
||||
priv->pending_point.x,
|
||||
priv->pending_point.y,
|
||||
FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_polygon_select_tool_select (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_POLYGON_SELECT_TOOL (poly_sel_tool));
|
||||
g_return_if_fail (GIMP_IS_DISPLAY (display));
|
||||
|
||||
GIMP_POLYGON_SELECT_TOOL_GET_CLASS (poly_sel_tool)->select (poly_sel_tool, display);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_real_select (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (poly_sel_tool);
|
||||
|
||||
gimp_channel_select_polygon (gimp_image_get_mask (display->image),
|
||||
Q_("command|Free Select"),
|
||||
poly_sel_tool->priv->num_points,
|
||||
poly_sel_tool->priv->points,
|
||||
options->operation,
|
||||
options->antialias,
|
||||
options->feather,
|
||||
options->feather_radius,
|
||||
options->feather_radius,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
static GimpVector2 *
|
||||
gimp_polygon_select_tool_add_point (GimpPolygonSelectTool *poly_sel_tool,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
if (poly_sel_tool->priv->num_points >= poly_sel_tool->priv->max_segs)
|
||||
{
|
||||
poly_sel_tool->priv->max_segs += DEFAULT_MAX_INC;
|
||||
|
||||
poly_sel_tool->priv->points = g_realloc (poly_sel_tool->priv->points,
|
||||
sizeof (GimpVector2) * poly_sel_tool->priv->max_segs);
|
||||
}
|
||||
|
||||
poly_sel_tool->priv->points[poly_sel_tool->priv->num_points].x = x;
|
||||
poly_sel_tool->priv->points[poly_sel_tool->priv->num_points].y = y;
|
||||
|
||||
return &poly_sel_tool->priv->points[poly_sel_tool->priv->num_points++];
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_remove_last (GimpPolygonSelectTool *poly_sel_tool)
|
||||
{
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (poly_sel_tool);
|
||||
|
||||
gimp_draw_tool_pause (draw_tool);
|
||||
|
||||
if (priv->num_points == 0)
|
||||
{
|
||||
gimp_polygon_select_tool_halt (poly_sel_tool);
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->num_points--;
|
||||
}
|
||||
|
||||
gimp_draw_tool_resume (draw_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_polygon_select_tool_select_closet_point (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display,
|
||||
GimpCoords *coords)
|
||||
{
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (poly_sel_tool);
|
||||
gdouble shortest_dist_sq;
|
||||
int i;
|
||||
|
||||
priv->grabbed_point = NULL;
|
||||
shortest_dist_sq = POINT_GRAB_THRESHOLD_SQ;
|
||||
|
||||
for (i = 0; i < priv->num_points; i++)
|
||||
{
|
||||
gdouble dist_sq;
|
||||
|
||||
dist_sq = gimp_draw_tool_calc_distance_square (draw_tool,
|
||||
display,
|
||||
coords->x,
|
||||
coords->y,
|
||||
priv->points[i].x,
|
||||
priv->points[i].y);
|
||||
if (dist_sq < shortest_dist_sq)
|
||||
{
|
||||
priv->grabbed_point = &priv->points[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_polygon_select_tool_should_close (GimpPolygonSelectTool *poly_sel_tool,
|
||||
GimpDisplay *display,
|
||||
GimpCoords *coords)
|
||||
{
|
||||
GimpPolygonSelectToolPrivate *priv = poly_sel_tool->priv;
|
||||
gboolean should_close = FALSE;
|
||||
|
||||
if (priv->num_points > 0)
|
||||
{
|
||||
gdouble dist_sq;
|
||||
|
||||
dist_sq = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (poly_sel_tool),
|
||||
display,
|
||||
coords->x,
|
||||
coords->y,
|
||||
priv->points[0].x,
|
||||
priv->points[0].y);
|
||||
should_close = dist_sq < POINT_GRAB_THRESHOLD_SQ;
|
||||
}
|
||||
|
||||
return should_close;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
*
|
||||
* A polygonal selection tool for GIMP
|
||||
* Copyright (C) 2007 Martin Nordholts
|
||||
*
|
||||
* Based on gimpfreeselecttool.h which is
|
||||
* 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_POLYGON_SELECT_TOOL_H
|
||||
#define GIMP_POLYGON_SELECT_TOOL_H
|
||||
|
||||
|
||||
#include "gimpselectiontool.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_POLYGON_SELECT_TOOL (gimp_polygon_select_tool_get_type ())
|
||||
#define GIMP_POLYGON_SELECT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_POLYGON_SELECT_TOOL, GimpPolygonSelectTool))
|
||||
#define GIMP_POLYGON_SELECT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_POLYGON_SELECT_TOOL, GimpPolygonSelectToolClass))
|
||||
#define GIMP_IS_POLYGON_SELECT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_POLYGON_SELECT_TOOL))
|
||||
#define GIMP_IS_POLYGON_SELECT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_POLYGON_SELECT_TOOL))
|
||||
#define GIMP_POLYGON_SELECT_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_POLYGON_SELECT_TOOL, GimpPolygonSelectToolClass))
|
||||
|
||||
|
||||
typedef struct _GimpPolygonSelectTool GimpPolygonSelectTool;
|
||||
typedef struct _GimpPolygonSelectToolPrivate GimpPolygonSelectToolPrivate;
|
||||
typedef struct _GimpPolygonSelectToolClass GimpPolygonSelectToolClass;
|
||||
|
||||
struct _GimpPolygonSelectTool
|
||||
{
|
||||
GimpSelectionTool parent_instance;
|
||||
|
||||
GimpPolygonSelectToolPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GimpPolygonSelectToolClass
|
||||
{
|
||||
GimpSelectionToolClass parent_class;
|
||||
|
||||
/* virtual function */
|
||||
|
||||
void (* select) (GimpPolygonSelectTool *poly_select_tool,
|
||||
GimpDisplay *display);
|
||||
};
|
||||
|
||||
|
||||
void gimp_polygon_select_tool_register (GimpToolRegisterCallback callback,
|
||||
gpointer data);
|
||||
|
||||
GType gimp_polygon_select_tool_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gimp_polygon_select_tool_select (GimpPolygonSelectTool *poly_sel,
|
||||
GimpDisplay *display);
|
||||
|
||||
|
||||
#endif /* GIMP_POLYGON_SELECT_TOOL_H */
|
|
@ -267,6 +267,7 @@
|
|||
#define GIMP_HELP_TOOL_PENCIL "gimp-tool-pencil"
|
||||
#define GIMP_HELP_TOOL_PERSPECTIVE "gimp-tool-perspective"
|
||||
#define GIMP_HELP_TOOL_PERSPECTIVE_CLONE "gimp-tool-perspective-clone"
|
||||
#define GIMP_HELP_TOOL_POLYGON_SELECT "gimp-tool-polygon-select"
|
||||
#define GIMP_HELP_TOOL_POSTERIZE "gimp-tool-posterize"
|
||||
#define GIMP_HELP_TOOL_RECT_SELECT "gimp-tool-rect-select"
|
||||
#define GIMP_HELP_TOOL_ROTATE "gimp-tool-rotate"
|
||||
|
|
|
@ -313,6 +313,7 @@ static const GtkStockItem gimp_stock_items[] =
|
|||
{ GIMP_STOCK_TOOL_PENCIL, NULL, 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE, N_("_Transform"), 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE_CLONE, NULL, 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_POLYGON_SELECT, NULL, 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_POSTERIZE, NULL, 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_RECT_SELECT, NULL, 0, 0, LIBGIMP_DOMAIN },
|
||||
{ GIMP_STOCK_TOOL_ROTATE, N_("_Rotate"), 0, 0, LIBGIMP_DOMAIN },
|
||||
|
@ -463,6 +464,7 @@ gimp_stock_button_pixbufs[] =
|
|||
{ GIMP_STOCK_TOOL_PENCIL, stock_tool_pencil_22 },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE, stock_tool_perspective_22 },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE_CLONE, stock_tool_perspective_clone_22 },
|
||||
{ GIMP_STOCK_TOOL_POLYGON_SELECT, stock_tool_polygon_select_22 },
|
||||
{ GIMP_STOCK_TOOL_POSTERIZE, stock_tool_posterize_22 },
|
||||
{ GIMP_STOCK_TOOL_RECT_SELECT, stock_tool_rect_select_22 },
|
||||
{ GIMP_STOCK_TOOL_ROTATE, stock_tool_rotate_22 },
|
||||
|
@ -624,6 +626,7 @@ gimp_stock_menu_pixbufs[] =
|
|||
{ GIMP_STOCK_TOOL_PENCIL, stock_tool_pencil_16 },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE, stock_tool_perspective_16 },
|
||||
{ GIMP_STOCK_TOOL_PERSPECTIVE_CLONE, stock_tool_perspective_clone_16 },
|
||||
{ GIMP_STOCK_TOOL_POLYGON_SELECT, stock_tool_polygon_select_16 },
|
||||
{ GIMP_STOCK_TOOL_POSTERIZE, stock_tool_posterize_16 },
|
||||
{ GIMP_STOCK_TOOL_RECT_SELECT, stock_tool_rect_select_16 },
|
||||
{ GIMP_STOCK_TOOL_ROTATE, stock_tool_rotate_16 },
|
||||
|
|
|
@ -130,6 +130,7 @@ G_BEGIN_DECLS
|
|||
#define GIMP_STOCK_TOOL_PENCIL "gimp-tool-pencil"
|
||||
#define GIMP_STOCK_TOOL_PERSPECTIVE "gimp-tool-perspective"
|
||||
#define GIMP_STOCK_TOOL_PERSPECTIVE_CLONE "gimp-tool-perspective-clone"
|
||||
#define GIMP_STOCK_TOOL_POLYGON_SELECT "gimp-tool-polygon-select"
|
||||
#define GIMP_STOCK_TOOL_POSTERIZE "gimp-tool-posterize"
|
||||
#define GIMP_STOCK_TOOL_RECT_SELECT "gimp-tool-rect-select"
|
||||
#define GIMP_STOCK_TOOL_ROTATE "gimp-tool-rotate"
|
||||
|
|
|
@ -492,6 +492,7 @@
|
|||
<menuitem action="tools-rect-select" />
|
||||
<menuitem action="tools-ellipse-select" />
|
||||
<menuitem action="tools-free-select" />
|
||||
<menuitem action="tools-polygon-select" />
|
||||
<menuitem action="tools-foreground-select" />
|
||||
<menuitem action="tools-fuzzy-select" />
|
||||
<menuitem action="tools-by-color-select" />
|
||||
|
|
|
@ -315,6 +315,8 @@ STOCK_TOOL_IMAGES = \
|
|||
tools/stock-tool-perspective-22.png \
|
||||
tools/stock-tool-perspective-clone-16.png \
|
||||
tools/stock-tool-perspective-clone-22.png \
|
||||
tools/stock-tool-polygon-select-16.png \
|
||||
tools/stock-tool-polygon-select-22.png \
|
||||
tools/stock-tool-posterize-16.png \
|
||||
tools/stock-tool-posterize-22.png \
|
||||
tools/stock-tool-rect-select-16.png \
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 398 B |
Binary file not shown.
After Width: | Height: | Size: 568 B |
Loading…
Reference in New Issue