[gimp] Move the stuff in tools-utils to the core so it can be used from
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Subject: [gimp] Move the stuff in tools-utils to the core so it can be used from
- Date: Wed, 22 Apr 2009 15:09:53 -0400 (EDT)
commit 090e06ecdd3aee58d7c51b9f117dbabcd2602e5e
Author: Michael Natterer <mitch gimp org>
Date: Wed Apr 22 21:08:42 2009 +0200
Move the stuff in tools-utils to the core so it can be used from
app/paint/ in the next step.
* app/tools/Makefile.am
* app/tools/tools-utils.[ch]: removed.
* app/core/gimp-utils.[ch]: add gimp_constrain_line() instead.
* app/tools/gimpblendtool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpfreeselecttool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimppainttool.c: changed accordingly.
---
app/core/gimp-utils.c | 87 +++++++++++++++++++++++++++
app/core/gimp-utils.h | 13 ++++
app/tools/Makefile.am | 2 -
app/tools/gimpblendtool.c | 14 ++--
app/tools/gimpeditselectiontool.c | 8 +-
app/tools/gimpfreeselecttool.c | 20 +++---
app/tools/gimpmeasuretool.c | 14 ++--
app/tools/gimppainttool.c | 8 +-
app/tools/tools-utils.c | 118 -------------------------------------
app/tools/tools-utils.h | 38 ------------
10 files changed, 132 insertions(+), 190 deletions(-)
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 0d1a051..9fe4a4a 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -527,3 +527,90 @@ gimp_container_get_neighbor_of_active (GimpContainer *container,
return NULL;
}
+
+/**
+ * gimp_utils_point_to_line_distance:
+ * @point: The point to calculate the distance for.
+ * @point_on_line: A point on the line.
+ * @line_direction: Normalized line direction vector.
+ * @closest_line_point: Gets set to the point on the line that is
+ * closest to @point.
+ *
+ * Returns: The shortest distance from @point to the line defined by
+ * @point_on_line and @normalized_line_direction.
+ **/
+static gdouble
+gimp_utils_point_to_line_distance (const GimpVector2 *point,
+ const GimpVector2 *point_on_line,
+ const GimpVector2 *line_direction,
+ GimpVector2 *closest_line_point)
+{
+ GimpVector2 distance_vector;
+ GimpVector2 tmp_a;
+ GimpVector2 tmp_b;
+ gdouble d;
+
+ gimp_vector2_sub (&tmp_a, point, point_on_line);
+
+ d = gimp_vector2_inner_product (&tmp_a, line_direction);
+
+ tmp_b = gimp_vector2_mul_val (*line_direction, d);
+
+ *closest_line_point = gimp_vector2_add_val (*point_on_line,
+ tmp_b);
+
+ gimp_vector2_sub (&distance_vector, closest_line_point, point);
+
+ return gimp_vector2_length (&distance_vector);
+}
+
+/**
+ * gimp_constrain_line:
+ * @start_x:
+ * @start_y:
+ * @end_x:
+ * @end_y:
+ * @n_snap_lines: Number evenly disributed lines to snap to.
+ *
+ * Projects a line onto the specified subset of evenly radially
+ * distributed lines. @n_lines of 2 makes the line snap horizontally
+ * or vertically. @n_lines of 4 snaps on 45 degree steps. @n_lines of
+ * 12 on 15 degree steps. etc.
+ **/
+void
+gimp_constrain_line (gdouble start_x,
+ gdouble start_y,
+ gdouble *end_x,
+ gdouble *end_y,
+ gint n_snap_lines)
+{
+ GimpVector2 line_point = { start_x, start_y };
+ GimpVector2 point = { *end_x, *end_y };
+ GimpVector2 constrained_point;
+ GimpVector2 line_dir;
+ gdouble shortest_dist_moved = G_MAXDOUBLE;
+ gdouble dist_moved;
+ gdouble angle;
+ gint i;
+
+ for (i = 0; i < n_snap_lines; i++)
+ {
+ angle = i * G_PI / n_snap_lines;
+
+ gimp_vector2_set (&line_dir,
+ cos (angle),
+ sin (angle));
+
+ dist_moved = gimp_utils_point_to_line_distance (&point,
+ &line_point,
+ &line_dir,
+ &constrained_point);
+ if (dist_moved < shortest_dist_moved)
+ {
+ shortest_dist_moved = dist_moved;
+
+ *end_x = constrained_point.x;
+ *end_y = constrained_point.y;
+ }
+ }
+}
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 0536ee9..9ed2254 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -67,5 +67,18 @@ GimpObject * gimp_container_get_neighbor_of_active (GimpContainer *container,
GimpContext *context,
GimpObject *active);
+/* Common values for the n_snap_lines parameter of
+ * gimp_constrain_line.
+ */
+#define GIMP_CONSTRAIN_LINE_90_DEGREES 2
+#define GIMP_CONSTRAIN_LINE_45_DEGREES 4
+#define GIMP_CONSTRAIN_LINE_15_DEGREES 12
+
+void gimp_constrain_line (gdouble start_x,
+ gdouble start_y,
+ gdouble *end_x,
+ gdouble *end_y,
+ gint n_snap_lines);
+
#endif /* __APP_GIMP_UTILS_H__ */
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index a2e42aa..b35855d 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -19,8 +19,6 @@ libapptools_a_sources = \
tools-types.h \
gimp-tools.c \
gimp-tools.h \
- tools-utils.c \
- tools-utils.h \
tool_manager.c \
tool_manager.h \
\
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index a1317ce..e40828a 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -26,6 +26,7 @@
#include "tools-types.h"
+#include "core/gimp-utils.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-blend.h"
#include "core/gimperror.h"
@@ -41,7 +42,6 @@
#include "gimpblendoptions.h"
#include "gimpblendtool.h"
#include "gimptoolcontrol.h"
-#include "tools-utils.h"
#include "gimp-intl.h"
@@ -287,9 +287,9 @@ gimp_blend_tool_motion (GimpTool *tool,
if (state & GDK_CONTROL_MASK)
{
- gimp_tool_motion_constrain (blend_tool->start_x, blend_tool->start_y,
- &blend_tool->end_x, &blend_tool->end_y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (blend_tool->start_x, blend_tool->start_y,
+ &blend_tool->end_x, &blend_tool->end_y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
}
gimp_tool_pop_status (tool, display);
@@ -320,9 +320,9 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
/* Restrict to multiples of 15 degrees if ctrl is pressed */
if (press)
{
- gimp_tool_motion_constrain (blend_tool->start_x, blend_tool->start_y,
- &blend_tool->end_x, &blend_tool->end_y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (blend_tool->start_x, blend_tool->start_y,
+ &blend_tool->end_x, &blend_tool->end_y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
}
gimp_tool_pop_status (tool, display);
diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c
index 1de4849..ed47916 100644
--- a/app/tools/gimpeditselectiontool.c
+++ b/app/tools/gimpeditselectiontool.c
@@ -32,6 +32,7 @@
#include "base/boundary.h"
#include "core/gimp.h"
+#include "core/gimp-utils.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-item-list.h"
@@ -55,7 +56,6 @@
#include "gimpeditselectiontool.h"
#include "gimptoolcontrol.h"
#include "tool_manager.h"
-#include "tools-utils.h"
#include "gimp-intl.h"
@@ -601,9 +601,9 @@ gimp_edit_selection_tool_update_motion (GimpEditSelectionTool *edit_select,
if (edit_select->constrain)
{
- gimp_tool_motion_constrain (edit_select->start_x, edit_select->start_y,
- &new_x, &new_y,
- GIMP_TOOL_CONSTRAIN_45_DEGREES);
+ gimp_constrain_line (edit_select->start_x, edit_select->start_y,
+ &new_x, &new_y,
+ GIMP_CONSTRAIN_LINE_45_DEGREES);
}
motion_x = new_x - off_x;
diff --git a/app/tools/gimpfreeselecttool.c b/app/tools/gimpfreeselecttool.c
index 2f31df9..1353b7b 100644
--- a/app/tools/gimpfreeselecttool.c
+++ b/app/tools/gimpfreeselecttool.c
@@ -31,6 +31,7 @@
#include "tools-types.h"
+#include "core/gimp-utils.h"
#include "core/gimpchannel.h"
#include "core/gimpchannel-select.h"
#include "core/gimpimage.h"
@@ -43,7 +44,6 @@
#include "gimpfreeselecttool.h"
#include "gimpselectionoptions.h"
#include "gimptoolcontrol.h"
-#include "tools-utils.h"
#include "gimp-intl.h"
@@ -1059,11 +1059,11 @@ gimp_free_select_tool_update_motion (GimpFreeSelectTool *fst,
&start_point_y,
segment_index);
- gimp_tool_motion_constrain (start_point_x,
- start_point_y,
- &new_x,
- &new_y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (start_point_x,
+ start_point_y,
+ &new_x,
+ &new_y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
}
gimp_free_select_tool_move_segment_vertex_to (fst,
@@ -1208,10 +1208,10 @@ gimp_free_select_tool_oper_update (GimpTool *tool,
&start_point_x,
&start_point_y);
- gimp_tool_motion_constrain (start_point_x, start_point_y,
- &priv->pending_point.x,
- &priv->pending_point.y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (start_point_x, start_point_y,
+ &priv->pending_point.x,
+ &priv->pending_point.y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
}
}
}
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index 4ff5ea6..8d8f26f 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -31,6 +31,7 @@
#include "tools-types.h"
+#include "core/gimp-utils.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-undo.h"
@@ -47,7 +48,6 @@
#include "gimpmeasureoptions.h"
#include "gimpmeasuretool.h"
#include "gimptoolcontrol.h"
-#include "tools-utils.h"
#include "gimp-intl.h"
@@ -437,9 +437,9 @@ gimp_measure_tool_motion (GimpTool *tool,
gdouble x = measure->x[i];
gdouble y = measure->y[i];
- gimp_tool_motion_constrain (measure->x[0], measure->y[0],
- &x, &y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (measure->x[0], measure->y[0],
+ &x, &y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
measure->x[i] = ROUND (x);
measure->y[i] = ROUND (y);
@@ -510,9 +510,9 @@ gimp_measure_tool_active_modifier_key (GimpTool *tool,
y = measure->mouse_y;
if (press)
- gimp_tool_motion_constrain (measure->x[0], measure->y[0],
- &x, &y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (measure->x[0], measure->y[0],
+ &x, &y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
measure->x[measure->point] = ROUND (x);
measure->y[measure->point] = ROUND (y);
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index b6555aa..48cb206 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -25,6 +25,7 @@
#include "tools-types.h"
#include "core/gimp.h"
+#include "core/gimp-utils.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimppaintinfo.h"
@@ -44,7 +45,6 @@
#include "gimpcoloroptions.h"
#include "gimppainttool.h"
#include "gimptoolcontrol.h"
-#include "tools-utils.h"
#include "gimp-intl.h"
@@ -269,9 +269,9 @@ gimp_paint_tool_round_line (GimpPaintCore *core,
}
if (state & GDK_CONTROL_MASK)
- gimp_tool_motion_constrain (core->last_coords.x, core->last_coords.y,
- &core->cur_coords.x, &core->cur_coords.y,
- GIMP_TOOL_CONSTRAIN_15_DEGREES);
+ gimp_constrain_line (core->last_coords.x, core->last_coords.y,
+ &core->cur_coords.x, &core->cur_coords.y,
+ GIMP_CONSTRAIN_LINE_15_DEGREES);
}
static void
diff --git a/app/tools/tools-utils.c b/app/tools/tools-utils.c
deleted file mode 100644
index 0f6b9ba..0000000
--- a/app/tools/tools-utils.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-
-#include "libgimpmath/gimpmath.h"
-
-#include "tools-utils.h"
-
-
-static gdouble gimp_tool_utils_point_to_line_distance (const GimpVector2 *point,
- const GimpVector2 *point_on_line,
- const GimpVector2 *normalized_line_direction,
- GimpVector2 *closest_line_point);
-
-
-/**
- * gimp_tool_utils_point_to_line_distance:
- * @point: The point to calculate the distance for.
- * @point_on_line: A point on the line.
- * @line_direction: Normalized line direction vector.
- * @closest_line_point: Gets set to the point on the line that is
- * closest to @point.
- *
- * Returns: The shortest distance from @point to the line defined by
- * @point_on_line and @normalized_line_direction.
- **/
-static gdouble
-gimp_tool_utils_point_to_line_distance (const GimpVector2 *point,
- const GimpVector2 *point_on_line,
- const GimpVector2 *line_direction,
- GimpVector2 *closest_line_point)
-{
- GimpVector2 distance_vector;
- GimpVector2 tmp_a;
- GimpVector2 tmp_b;
- gdouble d;
-
- gimp_vector2_sub (&tmp_a, point, point_on_line);
-
- d = gimp_vector2_inner_product (&tmp_a, line_direction);
-
- tmp_b = gimp_vector2_mul_val (*line_direction, d);
-
- *closest_line_point = gimp_vector2_add_val (*point_on_line,
- tmp_b);
-
- gimp_vector2_sub (&distance_vector, closest_line_point, point);
-
- return gimp_vector2_length (&distance_vector);
-}
-
-/**
- * gimp_tool_motion_constrain:
- * @start_x:
- * @start_y:
- * @end_x:
- * @end_y:
- * @n_snap_lines: Number evenly disributed lines to snap to.
- *
- * Projects a line onto the specified subset of evenly radially
- * distributed lines. @n_lines of 2 makes the line snap horizontally
- * or vertically. @n_lines of 4 snaps on 45 degree steps. @n_lines of
- * 12 on 15 degree steps. etc.
- **/
-void
-gimp_tool_motion_constrain (gdouble start_x,
- gdouble start_y,
- gdouble *end_x,
- gdouble *end_y,
- gint n_snap_lines)
-{
- GimpVector2 line_point = { start_x, start_y };
- GimpVector2 point = { *end_x, *end_y };
- GimpVector2 constrained_point;
- GimpVector2 line_dir;
- gdouble shortest_dist_moved = G_MAXDOUBLE;
- gdouble dist_moved;
- gdouble angle;
- gint i;
-
- for (i = 0; i < n_snap_lines; i++)
- {
- angle = i * G_PI / n_snap_lines;
-
- gimp_vector2_set (&line_dir,
- cos (angle),
- sin (angle));
-
- dist_moved = gimp_tool_utils_point_to_line_distance (&point,
- &line_point,
- &line_dir,
- &constrained_point);
- if (dist_moved < shortest_dist_moved)
- {
- shortest_dist_moved = dist_moved;
-
- *end_x = constrained_point.x;
- *end_y = constrained_point.y;
- }
- }
-}
diff --git a/app/tools/tools-utils.h b/app/tools/tools-utils.h
deleted file mode 100644
index dd4b6a1..0000000
--- a/app/tools/tools-utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __TOOLS_UTILS_H__
-#define __TOOLS_UTILS_H__
-
-
-/*
- * Common values for the n_snap_lines parameter of
- * gimp_tool_motion_constrain.
- */
-#define GIMP_TOOL_CONSTRAIN_90_DEGREES 2
-#define GIMP_TOOL_CONSTRAIN_45_DEGREES 4
-#define GIMP_TOOL_CONSTRAIN_15_DEGREES 12
-
-
-void gimp_tool_motion_constrain (gdouble start_x,
- gdouble start_y,
- gdouble *end_x,
- gdouble *end_y,
- gint n_snap_lines);
-
-
-#endif /* __TOOLS_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]