2001-02-27 13:21:12 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
#include "vectors/gimpanchor.h"
|
2003-09-12 02:02:39 +08:00
|
|
|
#include "vectors/gimpstroke.h"
|
|
|
|
#include "vectors/gimpvectors.h"
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
#include "display/gimpcanvas.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdrawtool.h"
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void gimp_draw_tool_finalize (GObject *object);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void gimp_draw_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void gimp_draw_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
static void gimp_draw_tool_real_draw (GimpDrawTool *draw_tool);
|
2002-02-19 01:00:09 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
static inline void gimp_draw_tool_shift_to_north_west
|
2005-12-13 17:13:50 +08:00
|
|
|
(gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y);
|
2001-11-16 05:17:36 +08:00
|
|
|
static inline void gimp_draw_tool_shift_to_center
|
2005-12-13 17:13:50 +08:00
|
|
|
(gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y);
|
2004-11-14 10:50:33 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpDrawTool, gimp_draw_tool, GIMP_TYPE_TOOL)
|
2004-11-14 10:50:33 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_draw_tool_parent_class
|
2004-11-14 10:50:33 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_draw_tool_class_init (GimpDrawToolClass *klass)
|
|
|
|
{
|
2005-12-13 17:13:50 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
object_class->finalize = gimp_draw_tool_finalize;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class->control = gimp_draw_tool_control;
|
2001-11-20 22:20:17 +08:00
|
|
|
|
2003-09-12 02:02:39 +08:00
|
|
|
klass->draw = gimp_draw_tool_real_draw;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 22:14:13 +08:00
|
|
|
static void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_init (GimpDrawTool *draw_tool)
|
2001-02-27 22:14:13 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = NULL;
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
draw_tool->paused_count = 0;
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
draw_tool->vectors = NULL;
|
|
|
|
draw_tool->transform = NULL;
|
2001-02-27 22:14:13 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
2001-08-14 22:53:55 +08:00
|
|
|
gimp_draw_tool_finalize (GObject *object)
|
2001-02-28 03:18:01 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (object);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2003-09-12 02:02:39 +08:00
|
|
|
if (draw_tool->vectors)
|
|
|
|
{
|
|
|
|
g_list_foreach (draw_tool->vectors, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (draw_tool->vectors);
|
|
|
|
draw_tool->vectors = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw_tool->transform)
|
|
|
|
{
|
|
|
|
g_free (draw_tool->transform);
|
|
|
|
draw_tool->transform = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-19 01:00:09 +08:00
|
|
|
gimp_draw_tool_control (GimpTool *tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
2001-02-28 03:18:01 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
break;
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
break;
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
break;
|
|
|
|
}
|
2001-08-14 22:53:55 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
|
|
|
|
2002-02-19 01:00:09 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
if (draw_tool->paused_count == 0 && draw_tool->display)
|
2003-07-11 00:01:45 +08:00
|
|
|
{
|
2002-02-19 01:00:09 +08:00
|
|
|
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
|
2003-07-11 00:01:45 +08:00
|
|
|
}
|
2002-02-19 01:00:09 +08:00
|
|
|
}
|
|
|
|
|
2003-09-12 02:02:39 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_real_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
if (! draw_tool->vectors)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (list = draw_tool->vectors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpVectors *vectors = list->data;
|
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
|
|
|
{
|
|
|
|
GArray *coords;
|
|
|
|
gboolean closed;
|
|
|
|
|
|
|
|
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
|
|
|
|
|
2003-09-12 18:04:37 +08:00
|
|
|
if (coords && coords->len)
|
2003-09-12 02:02:39 +08:00
|
|
|
{
|
|
|
|
if (draw_tool->transform)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < coords->len; i++)
|
|
|
|
{
|
|
|
|
GimpCoords *curr = &g_array_index (coords, GimpCoords, i);
|
|
|
|
|
|
|
|
gimp_matrix3_transform_point (draw_tool->transform,
|
|
|
|
curr->x, curr->y,
|
|
|
|
&curr->x, &curr->y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_strokes (draw_tool,
|
|
|
|
&g_array_index (coords,
|
|
|
|
GimpCoords, 0),
|
|
|
|
coords->len, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-09-12 18:04:37 +08:00
|
|
|
if (coords)
|
|
|
|
g_array_free (coords, TRUE);
|
2003-09-12 02:02:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_start (GimpDrawTool *draw_tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpDisplay *display)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-03 20:10:23 +08:00
|
|
|
GimpDisplayShell *shell;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (display));
|
2002-02-03 20:10:23 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
gimp_draw_tool_stop (draw_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = display;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2002-02-19 01:00:09 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_stop (GimpDrawTool *draw_tool)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = NULL;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2003-06-28 00:05:05 +08:00
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_is_active (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
return draw_tool->display != NULL;
|
2003-06-28 00:05:05 +08:00
|
|
|
}
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_pause (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2001-11-22 21:01:26 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
draw_tool->paused_count++;
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_resume (GimpDrawTool *draw_tool)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
|
|
|
if (draw_tool->paused_count > 0)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-07 19:33:01 +08:00
|
|
|
draw_tool->paused_count--;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2002-02-07 19:33:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: called with draw_tool->paused_count == 0", G_STRFUNC);
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-12 02:02:39 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_set_vectors (GimpDrawTool *draw_tool,
|
|
|
|
GList *vectors)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
|
|
if (draw_tool->vectors)
|
|
|
|
{
|
|
|
|
g_list_foreach (draw_tool->vectors, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (draw_tool->vectors);
|
|
|
|
draw_tool->vectors = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vectors)
|
|
|
|
{
|
|
|
|
draw_tool->vectors = g_list_copy (vectors);
|
|
|
|
g_list_foreach (draw_tool->vectors, (GFunc) g_object_ref, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_set_transform (GimpDrawTool *draw_tool,
|
|
|
|
GimpMatrix3 *transform)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
|
|
if (draw_tool->transform)
|
|
|
|
{
|
|
|
|
g_free (draw_tool->transform);
|
|
|
|
draw_tool->transform = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform)
|
|
|
|
draw_tool->transform = g_memdup (transform, sizeof (GimpMatrix3));
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
}
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble
|
|
|
|
gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), 0.0);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), 0.0);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1, FALSE);
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2, FALSE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
return sqrt (SQR (tx2 - tx1) + SQR (ty2 - ty1));
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_in_radius (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gint radius)
|
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1, FALSE);
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2, FALSE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
return (SQR (tx2 - tx1) + SQR (ty2 - ty1)) < SQR (radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_line (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2004-03-21 05:59:41 +08:00
|
|
|
gint tx1, ty1;
|
|
|
|
gint tx2, ty2;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x1, y1,
|
|
|
|
&tx1, &ty1,
|
|
|
|
use_offsets);
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x2, y2,
|
|
|
|
&tx2, &ty2,
|
|
|
|
use_offsets);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2004-03-21 05:59:41 +08:00
|
|
|
tx1, ty1,
|
|
|
|
tx2, ty2);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2003-09-03 00:13:48 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_dashed_line (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpDisplayShell *shell;
|
2004-03-21 05:59:41 +08:00
|
|
|
gint tx1, ty1;
|
|
|
|
gint tx2, ty2;
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x1, y1,
|
|
|
|
&tx1, &ty1,
|
|
|
|
use_offsets);
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x2, y2,
|
|
|
|
&tx2, &ty2,
|
|
|
|
use_offsets);
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR_DASHED,
|
2004-03-21 05:59:41 +08:00
|
|
|
tx1, ty1,
|
|
|
|
tx2, ty2);
|
2003-09-03 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_draw_rectangle (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
gboolean use_offsets)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
GimpDisplayShell *shell;
|
2004-03-21 05:59:41 +08:00
|
|
|
gint tx1, ty1;
|
|
|
|
gint tx2, ty2;
|
2003-05-06 02:45:58 +08:00
|
|
|
guint w, h;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
MIN (x, x + width), MIN (y, y + height),
|
|
|
|
&tx1, &ty1,
|
|
|
|
use_offsets);
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
MAX (x, x + width), MAX (y, y + height),
|
|
|
|
&tx2, &ty2,
|
|
|
|
use_offsets);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-05-26 07:23:34 +08:00
|
|
|
tx1 = CLAMP (tx1, -1, shell->disp_width + 1);
|
|
|
|
ty1 = CLAMP (ty1, -1, shell->disp_height + 1);
|
|
|
|
tx2 = CLAMP (tx2, -1, shell->disp_width + 1);
|
|
|
|
ty2 = CLAMP (ty2, -1, shell->disp_height + 1);
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
tx2 -= tx1;
|
|
|
|
ty2 -= ty1;
|
2004-03-21 05:59:41 +08:00
|
|
|
w = MAX (0, tx2);
|
|
|
|
h = MAX (0, ty2);
|
2003-05-06 02:45:58 +08:00
|
|
|
|
|
|
|
if (w > 0 && h > 0)
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
tx1, ty1,
|
2003-11-11 03:35:56 +08:00
|
|
|
w - 1, h - 1);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_arc (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
gint angle1,
|
|
|
|
gint angle2,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2004-03-21 05:59:41 +08:00
|
|
|
gint tx1, ty1;
|
|
|
|
gint tx2, ty2;
|
2003-05-06 02:45:58 +08:00
|
|
|
guint w, h;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
MIN (x, x + width), MIN (y, y + height),
|
|
|
|
&tx1, &ty1,
|
|
|
|
use_offsets);
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
MAX (x, x + width), MAX (y, y + height),
|
|
|
|
&tx2, &ty2,
|
|
|
|
use_offsets);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
tx2 -= tx1;
|
|
|
|
ty2 -= ty1;
|
2004-03-21 05:59:41 +08:00
|
|
|
w = MAX (0, tx2);
|
|
|
|
h = MAX (0, ty2);
|
2003-05-06 02:45:58 +08:00
|
|
|
|
|
|
|
if (w > 0 && h > 0)
|
|
|
|
{
|
|
|
|
if (w != 1 && h != 1)
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
tx1, ty1,
|
2003-11-11 03:35:56 +08:00
|
|
|
w - 1, h - 1,
|
|
|
|
angle1, angle2);
|
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
else
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
/* work around the problem of an 1xN or Nx1 arc not being shown
|
|
|
|
properly */
|
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
tx1, ty1,
|
2003-11-11 03:35:56 +08:00
|
|
|
w - 1, h - 1);
|
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_rectangle_by_anchor (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx, ty;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_shift_to_north_west (tx, ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
|
|
|
if (filled)
|
|
|
|
{
|
|
|
|
width++;
|
|
|
|
height++;
|
|
|
|
}
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty),
|
2003-11-11 03:35:56 +08:00
|
|
|
width, height);
|
2001-02-27 22:14:13 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_arc_by_anchor (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
gint angle1,
|
|
|
|
gint angle2,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx, ty;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
/* well... */
|
|
|
|
radius_x *= 2;
|
|
|
|
radius_y *= 2;
|
|
|
|
|
|
|
|
gimp_draw_tool_shift_to_north_west (tx, ty,
|
|
|
|
radius_x, radius_y,
|
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
|
|
|
if (filled)
|
|
|
|
{
|
|
|
|
radius_x += 1;
|
|
|
|
radius_y += 1;
|
|
|
|
}
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty),
|
2003-11-11 03:35:56 +08:00
|
|
|
radius_x, radius_y,
|
|
|
|
angle1, angle2);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
|
|
|
void
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_cross_by_anchor (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
2001-04-07 22:55:39 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble tx, ty;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_shift_to_center (tx, ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty) - (height >> 1),
|
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty) + (height >> 1));
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx) - (width >> 1), PROJ_ROUND (ty),
|
|
|
|
PROJ_ROUND (tx) + (width >> 1), PROJ_ROUND (ty));
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
2003-07-11 00:01:45 +08:00
|
|
|
gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
|
2001-11-12 22:45:58 +08:00
|
|
|
GimpHandleType type,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
2001-11-16 05:17:36 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
2001-11-12 22:45:58 +08:00
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
switch (type)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
case GIMP_HANDLE_SQUARE:
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_rectangle_by_anchor (draw_tool,
|
|
|
|
FALSE,
|
2001-11-12 22:45:58 +08:00
|
|
|
x, y,
|
2001-11-16 05:17:36 +08:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
anchor,
|
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_HANDLE_FILLED_SQUARE:
|
|
|
|
gimp_draw_tool_draw_rectangle_by_anchor (draw_tool,
|
|
|
|
TRUE,
|
|
|
|
x, y,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
anchor,
|
2001-11-12 22:45:58 +08:00
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_HANDLE_CIRCLE:
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
|
|
|
|
FALSE,
|
|
|
|
x, y,
|
|
|
|
width >> 1,
|
|
|
|
height >> 1,
|
|
|
|
0, 360 * 64,
|
|
|
|
anchor,
|
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_HANDLE_FILLED_CIRCLE:
|
|
|
|
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
|
|
|
|
TRUE,
|
2001-11-12 22:45:58 +08:00
|
|
|
x, y,
|
2001-11-16 05:17:36 +08:00
|
|
|
width >> 1,
|
|
|
|
height >> 1,
|
2001-11-12 22:45:58 +08:00
|
|
|
0, 360 * 64,
|
2001-11-16 05:17:36 +08:00
|
|
|
anchor,
|
2001-11-12 22:45:58 +08:00
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
case GIMP_HANDLE_CROSS:
|
|
|
|
gimp_draw_tool_draw_cross_by_anchor (draw_tool,
|
|
|
|
x, y,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
anchor,
|
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
|
2001-11-12 22:45:58 +08:00
|
|
|
break;
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
}
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_on_handle (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2001-11-16 05:17:36 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GimpHandleType type,
|
|
|
|
gdouble handle_x,
|
|
|
|
gdouble handle_y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx, ty;
|
|
|
|
gdouble handle_tx, handle_ty;
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2002-02-21 19:01:12 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
handle_x, handle_y,
|
|
|
|
&handle_tx, &handle_ty,
|
|
|
|
use_offsets);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_HANDLE_SQUARE:
|
|
|
|
case GIMP_HANDLE_FILLED_SQUARE:
|
|
|
|
case GIMP_HANDLE_CROSS:
|
|
|
|
gimp_draw_tool_shift_to_north_west (handle_tx, handle_ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&handle_tx, &handle_ty);
|
|
|
|
|
|
|
|
return (tx == CLAMP (tx, handle_tx, handle_tx + width) &&
|
|
|
|
ty == CLAMP (ty, handle_ty, handle_ty + height));
|
|
|
|
|
|
|
|
case GIMP_HANDLE_CIRCLE:
|
|
|
|
case GIMP_HANDLE_FILLED_CIRCLE:
|
|
|
|
gimp_draw_tool_shift_to_center (handle_tx, handle_ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&handle_tx, &handle_ty);
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
if (width != height)
|
2001-11-22 22:28:39 +08:00
|
|
|
width = (width + height) / 2;
|
|
|
|
|
|
|
|
width /= 2;
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
return ((SQR (handle_tx - tx) + SQR (handle_ty - ty)) < SQR (width));
|
|
|
|
|
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
|
2001-11-16 05:17:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors_handle (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
GimpVectors *vectors,
|
|
|
|
const GimpCoords *coord,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpAnchorType preferred,
|
|
|
|
gboolean exclusive,
|
|
|
|
GimpAnchor **ret_anchor,
|
|
|
|
GimpStroke **ret_stroke)
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpStroke *pref_stroke = NULL;
|
|
|
|
GimpAnchor *anchor = NULL;
|
|
|
|
GimpAnchor *pref_anchor = NULL;
|
|
|
|
GList *list;
|
|
|
|
gdouble dx, dy;
|
|
|
|
gdouble pref_mindist = -1;
|
|
|
|
gdouble mindist = -1;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2003-09-13 00:44:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
|
|
|
|
g_return_val_if_fail (coord != NULL, FALSE);
|
|
|
|
|
|
|
|
if (ret_anchor) *ret_anchor = NULL;
|
|
|
|
if (ret_stroke) *ret_stroke = NULL;
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
|
|
|
{
|
|
|
|
GList *anchor_list;
|
|
|
|
|
|
|
|
anchor_list = gimp_stroke_get_draw_anchors (stroke);
|
|
|
|
|
|
|
|
list = gimp_stroke_get_draw_controls (stroke);
|
|
|
|
anchor_list = g_list_concat (anchor_list, list);
|
|
|
|
|
|
|
|
while (anchor_list)
|
|
|
|
{
|
|
|
|
dx = coord->x - GIMP_ANCHOR (anchor_list->data)->position.x;
|
|
|
|
dy = coord->y - GIMP_ANCHOR (anchor_list->data)->position.y;
|
|
|
|
|
|
|
|
if (mindist < 0 || mindist > dx * dx + dy * dy)
|
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
|
|
|
anchor = GIMP_ANCHOR (anchor_list->data);
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pref_mindist < 0 || pref_mindist > dx * dx + dy * dy) &&
|
|
|
|
GIMP_ANCHOR (anchor_list->data)->type == preferred)
|
|
|
|
{
|
|
|
|
pref_mindist = dx * dx + dy * dy;
|
|
|
|
pref_anchor = GIMP_ANCHOR (anchor_list->data);
|
|
|
|
pref_stroke = stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
anchor_list = anchor_list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (anchor_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the data passed into ret_anchor is a preferred anchor, return it. */
|
|
|
|
if (ret_anchor && *ret_anchor &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
(*ret_anchor)->position.x,
|
|
|
|
(*ret_anchor)->position.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE) &&
|
|
|
|
(*ret_anchor)->type == preferred)
|
|
|
|
{
|
|
|
|
if (ret_stroke) *ret_stroke = pref_stroke;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
if (pref_anchor && gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
pref_anchor->position.x,
|
|
|
|
pref_anchor->position.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
if (ret_anchor) *ret_anchor = pref_anchor;
|
|
|
|
if (ret_stroke) *ret_stroke = pref_stroke;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-09-18 05:49:45 +08:00
|
|
|
else if (!exclusive && anchor &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-18 05:49:45 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
anchor->position.x,
|
|
|
|
anchor->position.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = anchor;
|
|
|
|
|
|
|
|
/* *ret_stroke already set correctly. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-18 05:49:45 +08:00
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = NULL;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = NULL;
|
2004-03-10 20:45:11 +08:00
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors_curve (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
GimpVectors *vectors,
|
|
|
|
const GimpCoords *coord,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpCoords *ret_coords,
|
|
|
|
gdouble *ret_pos,
|
|
|
|
GimpAnchor **ret_segment_start,
|
|
|
|
GimpAnchor **ret_segment_end,
|
|
|
|
GimpStroke **ret_stroke)
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpAnchor *segment_start;
|
2003-09-18 21:20:40 +08:00
|
|
|
GimpAnchor *segment_end;
|
2006-04-03 02:19:48 +08:00
|
|
|
GimpCoords min_coords = GIMP_COORDS_DEFAULT_VALUES;
|
|
|
|
GimpCoords cur_coords;
|
2003-09-13 00:44:10 +08:00
|
|
|
gdouble min_dist, cur_dist, cur_pos;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2003-09-13 00:44:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
|
|
|
|
g_return_val_if_fail (coord != NULL, FALSE);
|
|
|
|
|
|
|
|
if (ret_coords) *ret_coords = *coord;
|
2003-09-16 05:12:10 +08:00
|
|
|
if (ret_pos) *ret_pos = -1.0;
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_segment_start) *ret_segment_start = NULL;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_start) *ret_segment_end = NULL;
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_stroke) *ret_stroke = NULL;
|
|
|
|
|
|
|
|
min_dist = -1.0;
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
|
|
|
{
|
|
|
|
cur_dist = gimp_stroke_nearest_point_get (stroke, coord, 1.0,
|
2006-04-12 20:49:29 +08:00
|
|
|
&cur_coords,
|
2003-09-13 00:44:10 +08:00
|
|
|
&segment_start,
|
2003-09-18 21:20:40 +08:00
|
|
|
&segment_end,
|
2003-09-13 00:44:10 +08:00
|
|
|
&cur_pos);
|
|
|
|
|
2003-09-29 19:48:15 +08:00
|
|
|
if (cur_dist >= 0 && (min_dist < 0 || cur_dist < min_dist))
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
min_dist = cur_dist;
|
|
|
|
min_coords = cur_coords;
|
|
|
|
|
|
|
|
if (ret_coords) *ret_coords = cur_coords;
|
|
|
|
if (ret_pos) *ret_pos = cur_pos;
|
|
|
|
if (ret_segment_start) *ret_segment_start = segment_start;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_end) *ret_segment_end = segment_end;
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_stroke) *ret_stroke = stroke;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_dist >= 0 &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
min_coords.x,
|
|
|
|
min_coords.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpCoords *ret_coords,
|
|
|
|
gdouble *ret_pos,
|
|
|
|
GimpAnchor **ret_segment_start,
|
|
|
|
GimpAnchor **ret_segment_end,
|
|
|
|
GimpStroke **ret_stroke,
|
|
|
|
GimpVectors **ret_vectors)
|
2003-09-16 05:12:10 +08:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_coords) *ret_coords = *coords;
|
|
|
|
if (ret_pos) *ret_pos = -1.0;
|
2003-09-16 06:41:25 +08:00
|
|
|
if (ret_segment_start) *ret_segment_start = NULL;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_end) *ret_segment_end = NULL;
|
|
|
|
if (ret_stroke) *ret_stroke = NULL;
|
|
|
|
if (ret_vectors) *ret_vectors = NULL;
|
2003-09-16 05:12:10 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
for (list = GIMP_LIST (display->image->vectors)->list;
|
2003-09-16 05:12:10 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2004-03-10 20:45:11 +08:00
|
|
|
GimpVectors *vectors = list->data;
|
2003-09-16 05:12:10 +08:00
|
|
|
|
|
|
|
if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
|
|
|
|
continue;
|
|
|
|
|
2004-03-10 20:45:11 +08:00
|
|
|
if (gimp_draw_tool_on_vectors_curve (draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
display,
|
2004-03-10 20:45:11 +08:00
|
|
|
vectors, coords,
|
|
|
|
width, height,
|
|
|
|
ret_coords,
|
|
|
|
ret_pos,
|
|
|
|
ret_segment_start,
|
|
|
|
ret_segment_end,
|
|
|
|
ret_stroke))
|
2003-09-16 05:12:10 +08:00
|
|
|
{
|
|
|
|
if (ret_vectors)
|
|
|
|
*ret_vectors = vectors;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-07 22:55:39 +08:00
|
|
|
void
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
const gdouble *points,
|
|
|
|
gint n_points,
|
|
|
|
gboolean filled,
|
2005-08-01 00:05:06 +08:00
|
|
|
gboolean use_offsets)
|
2001-04-07 22:55:39 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GdkPoint *coords;
|
|
|
|
gint i;
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
coords = g_new (GdkPoint, n_points);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
for (i = 0; i < n_points ; i++)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
points[i*2], points[i*2+1],
|
2005-08-01 00:05:06 +08:00
|
|
|
&coords[i].x, &coords[i].y,
|
2004-03-21 05:59:41 +08:00
|
|
|
use_offsets);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2002-02-26 08:58:04 +08:00
|
|
|
if (filled)
|
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_polygon (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
TRUE, coords, n_points);
|
2002-02-26 08:58:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
coords, n_points);
|
2002-02-26 08:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (coords);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
const GimpCoords *points,
|
|
|
|
gint n_points,
|
|
|
|
gboolean filled,
|
2005-08-01 00:05:06 +08:00
|
|
|
gboolean use_offsets)
|
2002-02-26 08:58:04 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GdkPoint *coords;
|
|
|
|
gint i;
|
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
coords = g_new (GdkPoint, n_points);
|
2002-02-26 08:58:04 +08:00
|
|
|
|
2002-03-03 18:38:37 +08:00
|
|
|
for (i = 0; i < n_points ; i++)
|
2002-02-26 08:58:04 +08:00
|
|
|
{
|
2004-03-21 05:59:41 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
points[i].x, points[i].y,
|
2005-08-01 00:05:06 +08:00
|
|
|
&coords[i].x, &coords[i].y,
|
2004-03-21 05:59:41 +08:00
|
|
|
use_offsets);
|
2002-02-26 08:58:04 +08:00
|
|
|
}
|
|
|
|
|
2001-04-07 22:55:39 +08:00
|
|
|
if (filled)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_polygon (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
TRUE, coords, n_points);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
else
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
coords, n_points);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
|
|
|
g_free (coords);
|
|
|
|
}
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2005-06-27 00:51:13 +08:00
|
|
|
/**
|
|
|
|
* gimp_draw_tool_draw_boundary:
|
|
|
|
*
|
|
|
|
* @draw_tool: a #GimpDrawTool
|
|
|
|
* @bound_segs: the sorted brush outline
|
|
|
|
* @n_bound_segs: the number of segments in @bound_segs
|
|
|
|
* @offset_x: x offset
|
|
|
|
* @offset_y: y offset
|
|
|
|
* @use_offsets: whether to use offsets
|
|
|
|
*
|
|
|
|
* Draw the boundary of the brush that @draw_tool uses. The boundary
|
|
|
|
* should be sorted with sort_boundary(), and @n_bound_segs should
|
|
|
|
* include the sentinel segments inserted by sort_boundary() that
|
|
|
|
* indicate the end of connected segment sequences (groups) .
|
|
|
|
*/
|
2003-07-11 00:01:45 +08:00
|
|
|
void
|
2003-08-30 22:25:05 +08:00
|
|
|
gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool,
|
|
|
|
const BoundSeg *bound_segs,
|
|
|
|
gint n_bound_segs,
|
|
|
|
gdouble offset_x,
|
2004-02-22 00:06:56 +08:00
|
|
|
gdouble offset_y,
|
|
|
|
gboolean use_offsets)
|
2003-07-11 00:01:45 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2005-06-25 07:28:38 +08:00
|
|
|
GdkPoint *gdk_points;
|
|
|
|
gint n_gdk_points;
|
2003-07-14 22:50:41 +08:00
|
|
|
gint xmax, ymax;
|
2004-03-21 05:59:41 +08:00
|
|
|
gint x, y;
|
2003-07-11 00:01:45 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2005-08-20 12:01:13 +08:00
|
|
|
g_return_if_fail (n_bound_segs > 0);
|
|
|
|
g_return_if_fail (bound_segs != NULL);
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2005-06-25 07:28:38 +08:00
|
|
|
gdk_points = g_new0 (GdkPoint, n_bound_segs + 1);
|
|
|
|
n_gdk_points = 0;
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
xmax = shell->disp_width + 1;
|
|
|
|
ymax = shell->disp_height + 1;
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2005-06-25 07:28:38 +08:00
|
|
|
/* The sorted boundary has sentinel segments inserted at the end of
|
|
|
|
* each group.
|
|
|
|
*/
|
2005-06-27 00:51:13 +08:00
|
|
|
for (i = 0; i < n_bound_segs; i++)
|
2003-07-11 00:01:45 +08:00
|
|
|
{
|
2005-06-27 00:51:13 +08:00
|
|
|
if (bound_segs[i].x1 == -1 &&
|
2006-04-12 20:49:29 +08:00
|
|
|
bound_segs[i].y1 == -1 &&
|
|
|
|
bound_segs[i].x2 == -1 &&
|
|
|
|
bound_segs[i].y2 == -1)
|
|
|
|
{
|
|
|
|
/* Group ends */
|
|
|
|
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR_DOTTED,
|
|
|
|
gdk_points, n_gdk_points);
|
|
|
|
n_gdk_points = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2005-06-25 07:28:38 +08:00
|
|
|
|
|
|
|
if (n_gdk_points == 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
bound_segs[i].x1 + offset_x,
|
|
|
|
bound_segs[i].y1 + offset_y,
|
|
|
|
&x, &y,
|
|
|
|
use_offsets);
|
|
|
|
|
|
|
|
gdk_points[0].x = CLAMP (x, -1, xmax);
|
|
|
|
gdk_points[0].y = CLAMP (y, -1, ymax);
|
|
|
|
|
|
|
|
n_gdk_points++;
|
|
|
|
}
|
2005-06-25 07:28:38 +08:00
|
|
|
|
|
|
|
g_assert (n_gdk_points < n_bound_segs + 1);
|
2004-03-21 05:59:41 +08:00
|
|
|
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
2005-06-27 00:51:13 +08:00
|
|
|
bound_segs[i].x2 + offset_x,
|
|
|
|
bound_segs[i].y2 + offset_y,
|
2004-03-21 05:59:41 +08:00
|
|
|
&x, &y,
|
|
|
|
use_offsets);
|
|
|
|
|
2005-06-25 07:28:38 +08:00
|
|
|
gdk_points[n_gdk_points].x = CLAMP (x, -1, xmax);
|
|
|
|
gdk_points[n_gdk_points].y = CLAMP (y, -1, ymax);
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2005-06-25 07:28:38 +08:00
|
|
|
n_gdk_points++;
|
2003-07-11 00:01:45 +08:00
|
|
|
}
|
|
|
|
|
2005-06-25 07:28:38 +08:00
|
|
|
g_free (gdk_points);
|
2003-07-11 00:01:45 +08:00
|
|
|
}
|
2005-12-13 17:13:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gimp_draw_tool_shift_to_north_west (gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y)
|
|
|
|
{
|
|
|
|
switch (anchor)
|
|
|
|
{
|
|
|
|
case GTK_ANCHOR_CENTER:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_WEST:
|
|
|
|
/* nothing, this is the default */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_EAST:
|
|
|
|
x -= handle_width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
y -= handle_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_WEST:
|
|
|
|
y -= handle_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_EAST:
|
|
|
|
x -= handle_width;
|
|
|
|
y -= handle_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_WEST:
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_EAST:
|
|
|
|
x -= handle_width;
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shifted_x)
|
|
|
|
*shifted_x = x;
|
|
|
|
|
|
|
|
if (shifted_y)
|
|
|
|
*shifted_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gimp_draw_tool_shift_to_center (gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y)
|
|
|
|
{
|
|
|
|
switch (anchor)
|
|
|
|
{
|
|
|
|
case GTK_ANCHOR_CENTER:
|
|
|
|
/* nothing, this is the default */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH:
|
|
|
|
y += (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_WEST:
|
|
|
|
x += (handle_width >> 1);
|
|
|
|
y += (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_EAST:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
y += (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH:
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_WEST:
|
|
|
|
x += (handle_width >> 1);
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_EAST:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
y -= (handle_height >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_WEST:
|
|
|
|
x += (handle_width >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_EAST:
|
|
|
|
x -= (handle_width >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shifted_x)
|
|
|
|
*shifted_x = x;
|
|
|
|
|
|
|
|
if (shifted_y)
|
|
|
|
*shifted_y = y;
|
|
|
|
}
|