mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-21 03:52:33 +00:00
app/vectors/gimpstroke.[ch] Moved transformations code to gimpstroke, so
2003-08-07 Simon Budig <simon@gimp.org> * app/vectors/gimpstroke.[ch] * app/vectors/gimpvectors.c: Moved transformations code to gimpstroke, so that the gimpvector no longer fiddles in the stroke internals.
This commit is contained in:
parent
8603467cfa
commit
8d048a513c
|
@ -1,3 +1,10 @@
|
|||
2003-08-07 Simon Budig <simon@gimp.org>
|
||||
|
||||
* app/vectors/gimpstroke.[ch]
|
||||
* app/vectors/gimpvectors.c: Moved transformations code to
|
||||
gimpstroke, so that the gimpvector no longer fiddles in
|
||||
the stroke internals.
|
||||
|
||||
2003-08-07 Raphael Quinet <quinet@gamers.org>
|
||||
|
||||
* app/composite/Makefile.am (test_composite_SOURCES): added
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "vectors-types.h"
|
||||
|
||||
#include "core/gimpdrawable-transform-utils.h"
|
||||
|
||||
#include "gimpanchor.h"
|
||||
#include "gimpstroke.h"
|
||||
|
||||
|
@ -70,6 +72,30 @@ static GimpAnchor * gimp_stroke_real_temp_anchor_set (GimpStroke *stroke,
|
|||
static gboolean gimp_stroke_real_temp_anchor_fix (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 GList * gimp_stroke_real_get_draw_anchors (const GimpStroke *stroke);
|
||||
static GList * gimp_stroke_real_get_draw_controls (const GimpStroke *stroke);
|
||||
static GArray * gimp_stroke_real_get_draw_lines (const GimpStroke *stroke);
|
||||
|
@ -145,6 +171,13 @@ gimp_stroke_class_init (GimpStrokeClass *klass)
|
|||
klass->duplicate = gimp_stroke_real_duplicate;
|
||||
klass->make_bezier = gimp_stroke_real_make_bezier;
|
||||
|
||||
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;
|
||||
klass->get_draw_controls = gimp_stroke_real_get_draw_controls;
|
||||
klass->get_draw_lines = gimp_stroke_real_get_draw_lines;
|
||||
|
@ -571,6 +604,239 @@ gimp_stroke_real_make_bezier (const GimpStroke *stroke)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
gimp_stroke_translate (GimpStroke *stroke,
|
||||
gdouble offset_x,
|
||||
gdouble offset_y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
||||
|
||||
GIMP_STROKE_GET_CLASS (stroke)->translate (stroke, offset_x, offset_y);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_stroke_real_translate (GimpStroke *stroke,
|
||||
gdouble offset_x,
|
||||
gdouble offset_y)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
for (list = stroke->anchors; list; list = g_list_next (list))
|
||||
{
|
||||
GimpAnchor *anchor = list->data;
|
||||
|
||||
anchor->position.x += offset_x;
|
||||
anchor->position.y += offset_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gimp_stroke_scale (GimpStroke *stroke,
|
||||
gdouble scale_x,
|
||||
gdouble scale_y,
|
||||
gint offset_x,
|
||||
gint offset_y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
||||
|
||||
GIMP_STROKE_GET_CLASS (stroke)->scale (stroke,
|
||||
scale_x, scale_y,
|
||||
offset_x, offset_y);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_stroke_real_scale (GimpStroke *stroke,
|
||||
gdouble scale_x,
|
||||
gdouble scale_y,
|
||||
gint offset_x,
|
||||
gint offset_y)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
for (list = stroke->anchors; list; list = g_list_next (list))
|
||||
{
|
||||
GimpAnchor *anchor = list->data;
|
||||
|
||||
anchor->position.x *= scale_x;
|
||||
anchor->position.y *= scale_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gimp_stroke_resize (GimpStroke *stroke,
|
||||
gint new_width,
|
||||
gint new_height,
|
||||
gint offset_x,
|
||||
gint offset_y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
||||
|
||||
GIMP_STROKE_GET_CLASS (stroke)->resize (stroke,
|
||||
new_width, new_height,
|
||||
offset_x, offset_y);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_stroke_real_resize (GimpStroke *stroke,
|
||||
gint new_width,
|
||||
gint new_height,
|
||||
gint offset_x,
|
||||
gint offset_y)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
for (list = stroke->anchors; list; list = g_list_next (list))
|
||||
{
|
||||
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,
|
||||
anchor->position.x,
|
||||
anchor->position.y,
|
||||
&anchor->position.x,
|
||||
&anchor->position.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GList *
|
||||
gimp_stroke_get_draw_anchors (const GimpStroke *stroke)
|
||||
{
|
||||
|
|
|
@ -89,6 +89,41 @@ struct _GimpStrokeClass
|
|||
GimpStroke * (* duplicate) (const GimpStroke *stroke);
|
||||
GimpStroke * (* make_bezier) (const GimpStroke *stroke);
|
||||
|
||||
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);
|
||||
|
||||
void (* transform) (GimpStroke *stroke,
|
||||
const GimpMatrix3 *matrix,
|
||||
GimpTransformDirection direction,
|
||||
GimpInterpolationType interp_type,
|
||||
gboolean clip_result,
|
||||
GimpProgressFunc progress_callback,
|
||||
gpointer progress_data);
|
||||
|
||||
GList * (* get_draw_anchors) (const GimpStroke *stroke);
|
||||
GList * (* get_draw_controls) (const GimpStroke *stroke);
|
||||
GArray * (* get_draw_lines) (const GimpStroke *stroke);
|
||||
|
@ -158,6 +193,37 @@ 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);
|
||||
|
||||
|
||||
GList * gimp_stroke_get_draw_anchors (const GimpStroke *stroke);
|
||||
GList * gimp_stroke_get_draw_controls (const GimpStroke *stroke);
|
||||
GArray * gimp_stroke_get_draw_lines (const GimpStroke *stroke);
|
||||
|
|
|
@ -300,15 +300,8 @@ gimp_vectors_translate (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->data;
|
||||
|
||||
anchor->position.x += offset_x;
|
||||
anchor->position.y += offset_y;
|
||||
}
|
||||
gimp_stroke_translate (stroke, offset_x, offset_y);
|
||||
}
|
||||
|
||||
gimp_vectors_thaw (vectors);
|
||||
|
@ -336,15 +329,11 @@ gimp_vectors_scale (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->data;
|
||||
|
||||
anchor->position.x *= (gdouble) new_width / (gdouble) item->width;
|
||||
anchor->position.y *= (gdouble) new_height / (gdouble) item->height;
|
||||
}
|
||||
gimp_stroke_scale (stroke,
|
||||
(gdouble) new_width / (gdouble) item->width,
|
||||
(gdouble) new_height / (gdouble) item->height,
|
||||
new_offset_x, new_offset_y);
|
||||
}
|
||||
|
||||
GIMP_ITEM_CLASS (parent_class)->scale (item, new_width, new_height,
|
||||
|
@ -375,15 +364,8 @@ gimp_vectors_resize (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->data;
|
||||
|
||||
anchor->position.x += offset_x;
|
||||
anchor->position.y += offset_y;
|
||||
}
|
||||
gimp_stroke_resize (stroke, new_width, new_height, offset_x, offset_y);
|
||||
}
|
||||
|
||||
GIMP_ITEM_CLASS (parent_class)->resize (item, new_width, new_height,
|
||||
|
@ -412,26 +394,8 @@ gimp_vectors_flip (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->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;
|
||||
}
|
||||
}
|
||||
gimp_stroke_flip (stroke, flip_type, axis, clip_result);
|
||||
}
|
||||
|
||||
gimp_vectors_thaw (vectors);
|
||||
|
@ -476,18 +440,8 @@ gimp_vectors_rotate (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->data;
|
||||
|
||||
gimp_matrix3_transform_point (&matrix,
|
||||
anchor->position.x,
|
||||
anchor->position.y,
|
||||
&anchor->position.x,
|
||||
&anchor->position.y);
|
||||
}
|
||||
gimp_stroke_rotate (stroke, rotate_type, center_x, center_y, clip_result);
|
||||
}
|
||||
|
||||
gimp_vectors_thaw (vectors);
|
||||
|
@ -522,18 +476,9 @@ gimp_vectors_transform (GimpItem *item,
|
|||
for (list = vectors->strokes; list; list = g_list_next (list))
|
||||
{
|
||||
GimpStroke *stroke = list->data;
|
||||
GList *list2;
|
||||
|
||||
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
||||
{
|
||||
GimpAnchor *anchor = list2->data;
|
||||
|
||||
gimp_matrix3_transform_point (&local_matrix,
|
||||
anchor->position.x,
|
||||
anchor->position.y,
|
||||
&anchor->position.x,
|
||||
&anchor->position.y);
|
||||
}
|
||||
gimp_stroke_transform (stroke, matrix, direction, interpolation_type,
|
||||
clip_result, progress_callback, progress_data);
|
||||
}
|
||||
|
||||
gimp_vectors_thaw (vectors);
|
||||
|
|
Loading…
Reference in a new issue