added new function gimp_drawable_transform_matrix_flip().

2003-09-11  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdrawable-transform-utils.[ch]: added new function
	gimp_drawable_transform_matrix_flip().

	* app/vectors/gimpstroke.[ch]
	* app/vectors/gimpvectors.c: don't push the complex GimpItem
	transformation API down to GimpStroke. Instead setup the matrices
	in GimpVectors and use a simpler API for GimpStroke.

	* app/vectors/gimpvectors-import.c: changed accordingly.

	* app/vectors/gimpvectors-export.c: close the <path> element.
This commit is contained in:
Sven Neumann 2003-09-11 01:23:58 +00:00 committed by Sven Neumann
parent 7772ca4606
commit 8bd0ec7685
7 changed files with 92 additions and 250 deletions

View File

@ -27,6 +27,32 @@
#include "gimpdrawable-transform-utils.h"
void
gimp_drawable_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result)
{
gimp_matrix3_identity (result);
switch (flip_type)
{
case GIMP_ORIENTATION_HORIZONTAL:
gimp_matrix3_translate (result, - axis, 0.0);
gimp_matrix3_scale (result, -1.0, 1.0);
gimp_matrix3_translate (result, axis, 0.0);
break;
case GIMP_ORIENTATION_VERTICAL:
gimp_matrix3_translate (result, 0.0, - axis);
gimp_matrix3_scale (result, 1.0, -1.0);
gimp_matrix3_translate (result, 0.0, axis);
break;
case GIMP_ORIENTATION_UNKNOWN:
break;
}
}
void
gimp_drawable_transform_matrix_rotate (gint x1,
gint y1,

View File

@ -20,6 +20,9 @@
#define __GIMP_DRAWABLE_TRANSFORM_UTILS_H__
void gimp_drawable_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_rotate (gint x1,
gint y1,
gint x2,

View File

@ -27,6 +27,32 @@
#include "gimpdrawable-transform-utils.h"
void
gimp_drawable_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result)
{
gimp_matrix3_identity (result);
switch (flip_type)
{
case GIMP_ORIENTATION_HORIZONTAL:
gimp_matrix3_translate (result, - axis, 0.0);
gimp_matrix3_scale (result, -1.0, 1.0);
gimp_matrix3_translate (result, axis, 0.0);
break;
case GIMP_ORIENTATION_VERTICAL:
gimp_matrix3_translate (result, 0.0, - axis);
gimp_matrix3_scale (result, 1.0, -1.0);
gimp_matrix3_translate (result, 0.0, axis);
break;
case GIMP_ORIENTATION_UNKNOWN:
break;
}
}
void
gimp_drawable_transform_matrix_rotate (gint x1,
gint y1,

View File

@ -20,6 +20,9 @@
#define __GIMP_DRAWABLE_TRANSFORM_UTILS_H__
void gimp_drawable_transform_matrix_flip (GimpOrientationType flip_type,
gdouble axis,
GimpMatrix3 *result);
void gimp_drawable_transform_matrix_rotate (gint x1,
gint y1,
gint x2,

View File

@ -135,28 +135,14 @@ static GArray * gimp_stroke_real_interpolate (const GimpStroke *stroke,
static GimpStroke * gimp_stroke_real_duplicate (const GimpStroke *stroke);
static GimpStroke * gimp_stroke_real_make_bezier (const GimpStroke *stroke);
static void gimp_stroke_real_translate (GimpStroke *stroke,
gdouble offset_x, gdouble offset_y);
static void gimp_stroke_real_scale (GimpStroke *stroke,
gdouble scale_x, gdouble scale_y,
gint offset_x, gint offset_y);
static void gimp_stroke_real_resize (GimpStroke *stroke,
gint new_width, gint new_height,
gint offset_x, gint offset_y);
static void gimp_stroke_real_flip (GimpStroke *stroke,
GimpOrientationType flip_type,
gdouble axis, gboolean clip_result);
static void gimp_stroke_real_rotate (GimpStroke *stroke,
GimpRotationType rotate_type,
gdouble center_x, gdouble center_y,
gboolean clip_result);
static void gimp_stroke_real_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data);
static void gimp_stroke_real_translate (GimpStroke *stroke,
gdouble offset_x,
gdouble offset_y);
static void gimp_stroke_real_scale (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y);
static void gimp_stroke_real_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix);
static GList * gimp_stroke_real_get_draw_anchors (const GimpStroke *stroke);
static GList * gimp_stroke_real_get_draw_controls (const GimpStroke *stroke);
@ -253,9 +239,6 @@ gimp_stroke_class_init (GimpStrokeClass *klass)
klass->translate = gimp_stroke_real_translate;
klass->scale = gimp_stroke_real_scale;
klass->resize = gimp_stroke_real_resize;
klass->flip = gimp_stroke_real_flip;
klass->rotate = gimp_stroke_real_rotate;
klass->transform = gimp_stroke_real_transform;
klass->get_draw_anchors = gimp_stroke_real_get_draw_anchors;
@ -1003,23 +986,17 @@ gimp_stroke_real_translate (GimpStroke *stroke,
void
gimp_stroke_scale (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y,
gint offset_x,
gint offset_y)
gdouble scale_y)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->scale (stroke,
scale_x, scale_y,
offset_x, offset_y);
GIMP_STROKE_GET_CLASS (stroke)->scale (stroke, scale_x, scale_y);
}
static void
gimp_stroke_real_scale (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y,
gint offset_x,
gint offset_y)
gdouble scale_y)
{
GList *list;
@ -1032,27 +1009,18 @@ gimp_stroke_real_scale (GimpStroke *stroke,
}
}
void
gimp_stroke_resize (GimpStroke *stroke,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y)
gimp_stroke_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->resize (stroke,
new_width, new_height,
offset_x, offset_y);
GIMP_STROKE_GET_CLASS (stroke)->transform (stroke, matrix);
}
static void
gimp_stroke_real_resize (GimpStroke *stroke,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y)
gimp_stroke_real_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix)
{
GList *list;
@ -1060,144 +1028,7 @@ gimp_stroke_real_resize (GimpStroke *stroke,
{
GimpAnchor *anchor = list->data;
anchor->position.x += offset_x;
anchor->position.y += offset_y;
}
}
void
gimp_stroke_flip (GimpStroke *stroke,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->flip (stroke, flip_type,
axis, clip_result);
}
static void
gimp_stroke_real_flip (GimpStroke *stroke,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result)
{
GList *list;
for (list = stroke->anchors; list; list = g_list_next (list))
{
GimpAnchor *anchor = list->data;
switch (flip_type)
{
case GIMP_ORIENTATION_HORIZONTAL:
anchor->position.x = -(anchor->position.x - axis) + axis;
break;
case GIMP_ORIENTATION_VERTICAL:
anchor->position.y = -(anchor->position.y - axis) + axis;
break;
default:
break;
}
}
}
void
gimp_stroke_rotate (GimpStroke *stroke,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->rotate (stroke, rotate_type,
center_x, center_y, clip_result);
}
static void
gimp_stroke_real_rotate (GimpStroke *stroke,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result)
{
GList *list;
GimpMatrix3 matrix;
gdouble angle = 0.0;
switch (rotate_type)
{
case GIMP_ROTATE_90:
angle = G_PI_2;
break;
case GIMP_ROTATE_180:
angle = G_PI;
break;
case GIMP_ROTATE_270:
angle = - G_PI_2;
break;
}
gimp_drawable_transform_matrix_rotate_center (center_x, center_y, angle,
&matrix);
for (list = stroke->anchors; list; list = g_list_next (list))
{
GimpAnchor *anchor = list->data;
gimp_matrix3_transform_point (&matrix,
anchor->position.x,
anchor->position.y,
&anchor->position.x,
&anchor->position.y);
}
}
void
gimp_stroke_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->transform (stroke, matrix, direction,
interp_type, clip_result,
progress_callback, progress_data);
}
static void
gimp_stroke_real_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data)
{
GimpMatrix3 local_matrix;
GList *list;
local_matrix = *matrix;
if (direction == GIMP_TRANSFORM_BACKWARD)
gimp_matrix3_invert (&local_matrix);
for (list = stroke->anchors; list; list = g_list_next (list))
{
GimpAnchor *anchor = list->data;
gimp_matrix3_transform_point (&local_matrix,
gimp_matrix3_transform_point (matrix,
anchor->position.x,
anchor->position.y,
&anchor->position.x,

View File

@ -128,37 +128,11 @@ struct _GimpStrokeClass
void (* translate) (GimpStroke *stroke,
gdouble offset_x,
gdouble offset_y);
void (* scale) (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y,
gint offset_x,
gint offset_y);
void (* resize) (GimpStroke *stroke,
gint new_width,
gint new_heigth,
gint offset_x,
gint offset_y);
void (* flip) (GimpStroke *stroke,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result);
void (* rotate) (GimpStroke *stroke,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result);
gdouble scale_y);
void (* transform) (GimpStroke *stroke,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data);
const GimpMatrix3 *matrix);
GList * (* get_draw_anchors) (const GimpStroke *stroke);
GList * (* get_draw_controls) (const GimpStroke *stroke);
@ -273,35 +247,13 @@ GimpStroke * gimp_stroke_duplicate (const GimpStroke *stroke);
/* creates a bezier approximation. */
GimpStroke * gimp_stroke_make_bezier (const GimpStroke *stroke);
void gimp_stroke_translate (GimpStroke *stroke,
gdouble offset_x,
gdouble offset_y);
void gimp_stroke_scale (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y,
gint offset_x,
gint offset_y);
void gimp_stroke_resize (GimpStroke *stroke,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y);
void gimp_stroke_flip (GimpStroke *stroke,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result);
void gimp_stroke_rotate (GimpStroke *stroke,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result);
void gimp_stroke_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data);
void gimp_stroke_translate (GimpStroke *stroke,
gdouble offset_x,
gdouble offset_y);void gimp_stroke_scale (GimpStroke *stroke,
gdouble scale_x,
gdouble scale_y);
void gimp_stroke_transform (GimpStroke *stroke,
const GimpMatrix3 *matrix);
GList * gimp_stroke_get_draw_anchors (const GimpStroke *stroke);

View File

@ -380,8 +380,7 @@ gimp_vectors_scale (GimpItem *item,
gimp_stroke_scale (stroke,
(gdouble) new_width / (gdouble) item->width,
(gdouble) new_height / (gdouble) item->height,
new_offset_x, new_offset_y);
(gdouble) new_height / (gdouble) item->height);
}
GIMP_ITEM_CLASS (parent_class)->scale (item, new_width, new_height,
@ -413,7 +412,7 @@ gimp_vectors_resize (GimpItem *item,
{
GimpStroke *stroke = list->data;
gimp_stroke_resize (stroke, new_width, new_height, offset_x, offset_y);
gimp_stroke_translate (stroke, offset_x, offset_y);
}
GIMP_ITEM_CLASS (parent_class)->resize (item, new_width, new_height,
@ -430,6 +429,9 @@ gimp_vectors_flip (GimpItem *item,
{
GimpVectors *vectors;
GList *list;
GimpMatrix3 matrix;
gimp_drawable_transform_matrix_flip (flip_type, axis, &matrix);
vectors = GIMP_VECTORS (item);
@ -443,7 +445,7 @@ gimp_vectors_flip (GimpItem *item,
{
GimpStroke *stroke = list->data;
gimp_stroke_flip (stroke, flip_type, axis, clip_result);
gimp_stroke_transform (stroke, &matrix);
}
gimp_vectors_thaw (vectors);
@ -489,7 +491,7 @@ gimp_vectors_rotate (GimpItem *item,
{
GimpStroke *stroke = list->data;
gimp_stroke_rotate (stroke, rotate_type, center_x, center_y, clip_result);
gimp_stroke_transform (stroke, &matrix);
}
gimp_vectors_thaw (vectors);
@ -525,8 +527,7 @@ gimp_vectors_transform (GimpItem *item,
{
GimpStroke *stroke = list->data;
gimp_stroke_transform (stroke, matrix, direction, interpolation_type,
clip_result, progress_callback, progress_data);
gimp_stroke_transform (stroke, &local_matrix);
}
gimp_vectors_thaw (vectors);