1
0
Fork 0

clutter: Remove unused Path related types

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3437>
This commit is contained in:
Bilal Elmoussaoui 2023-12-02 13:20:55 +01:00 committed by Marge Bot
parent 05cd7bc6cb
commit 580d62b9b6
13 changed files with 0 additions and 3251 deletions

View file

@ -53,8 +53,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPanAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPathConstraint, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPath, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPropertyTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterRotateAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref)
@ -77,6 +75,5 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterMargin, clutter_margin_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPaintContext, clutter_paint_context_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPaintNode, clutter_paint_node_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPaintVolume, clutter_paint_volume_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPathNode, clutter_path_node_free)
#endif /* __GI_SCANNER__ */

View file

@ -1,304 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Tomas Frydrych <tf@openedhand.com>
*
* Copyright (C) 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib.h>
#include <string.h>
#include "clutter/clutter-bezier.h"
#include "clutter/clutter-debug.h"
/****************************************************************************
* ClutterBezier -- representation of a cubic bezier curve *
* (private; a building block for the public bspline object) *
****************************************************************************/
/*
* The t parameter of the bezier is from interval <0,1>, so we can use
* 14.18 format and special multiplication functions that preserve
* more of the least significant bits but would overflow if the value
* is > 1
*/
#define CBZ_T_Q 18
#define CBZ_T_ONE (1 << CBZ_T_Q)
#define CBZ_T_MUL(x,y) ((((x) >> 3) * ((y) >> 3)) >> 12)
#define CBZ_T_POW2(x) CBZ_T_MUL (x, x)
#define CBZ_T_POW3(x) CBZ_T_MUL (CBZ_T_POW2 (x), x)
#define CBZ_T_DIV(x,y) ((((x) << 9)/(y)) << 9)
/*
* Constants for sampling of the bezier
*/
#define CBZ_T_SAMPLES 128
#define CBZ_T_STEP (CBZ_T_ONE / CBZ_T_SAMPLES)
#define CBZ_L_STEP (CBZ_T_ONE / CBZ_T_SAMPLES)
#define FIXED_BITS (32)
#define FIXED_Q (FIXED_BITS - 16)
#define FIXED_FROM_INT(x) ((x) << FIXED_Q)
typedef gint32 _FixedT;
/*
* This is a private type representing a single cubic bezier
*/
struct _ClutterBezier
{
/*
* bezier coefficients -- these are calculated using multiplication and
* addition from integer input, so these are also integers
*/
gint ax;
gint bx;
gint cx;
gint dx;
gint ay;
gint by;
gint cy;
gint dy;
/* length of the bezier */
guint length;
};
ClutterBezier *
_clutter_bezier_new (void)
{
return g_new0 (ClutterBezier, 1);
}
void
_clutter_bezier_free (ClutterBezier * b)
{
if (G_LIKELY (b))
{
g_free (b);
}
}
static gint
_clutter_bezier_t2x (const ClutterBezier * b, _FixedT t)
{
/*
* NB -- the int coefficients can be at most 8192 for the multiplication
* to work in this fashion due to the limits of the 14.18 fixed.
*/
return ((b->ax*CBZ_T_POW3(t) + b->bx*CBZ_T_POW2(t) + b->cx*t) >> CBZ_T_Q)
+ b->dx;
}
static gint
_clutter_bezier_t2y (const ClutterBezier * b, _FixedT t)
{
/*
* NB -- the int coefficients can be at most 8192 for the multiplication
* to work in this fashion due to the limits of the 14.18 fixed.
*/
return ((b->ay*CBZ_T_POW3(t) + b->by*CBZ_T_POW2(t) + b->cy*t) >> CBZ_T_Q)
+ b->dy;
}
/*
* Advances along the bezier to relative length L and returns the coordinances
* in knot
*/
void
_clutter_bezier_advance (const ClutterBezier *b, gint L, ClutterKnot * knot)
{
_FixedT t = L;
knot->x = _clutter_bezier_t2x (b, t);
knot->y = _clutter_bezier_t2y (b, t);
CLUTTER_NOTE (MISC, "advancing to relative pt %f: t %f, {%d,%d}",
(double) L / (double) CBZ_T_ONE,
(double) t / (double) CBZ_T_ONE,
knot->x, knot->y);
}
static int
sqrti (int number)
{
#if defined __SSE2__
/* The GCC built-in with SSE2 (sqrtsd) is up to twice as fast as
* the pure integer code below. It is also more accurate.
*/
return __builtin_sqrt (number);
#else
/* This is a fixed point implementation of the Quake III sqrt algorithm,
* described, for example, at
* http://www.codemaestro.com/reviews/review00000105.html
*
* While the original QIII is extremely fast, the use of floating division
* and multiplication makes it perform very on arm processors without FPU.
*
* The key to successfully replacing the floating point operations with
* fixed point is in the choice of the fixed point format. The QIII
* algorithm does not calculate the square root, but its reciprocal ('y'
* below), which is only at the end turned to the inverse value. In order
* for the algorithm to produce satisfactory results, the reciprocal value
* must be represented with sufficient precision; the 16.16 we use
* elsewhere in clutter is not good enough, and 10.22 is used instead.
*/
_FixedT x;
uint32_t y_1; /* 10.22 fixed point */
uint32_t f = 0x600000; /* '1.5' as 10.22 fixed */
union
{
float f;
uint32_t i;
} flt, flt2;
flt.f = number;
x = FIXED_FROM_INT (number) / 2;
/* The QIII initial estimate */
flt.i = 0x5f3759df - ( flt.i >> 1 );
/* Now, we convert the float to 10.22 fixed. We exploit the mechanism
* described at http://www.d6.com/users/checker/pdfs/gdmfp.pdf.
*
* We want 22 bit fraction; a single precision float uses 23 bit
* mantisa, so we only need to add 2^(23-22) (no need for the 1.5
* multiplier as we are only dealing with positive numbers).
*
* Note: we have to use two separate variables here -- for some reason,
* if we try to use just the flt variable, gcc on ARM optimises the whole
* addition out, and it all goes pear shape, since without it, the bits
* in the float will not be correctly aligned.
*/
flt2.f = flt.f + 2.0;
flt2.i &= 0x7FFFFF;
/* Now we correct the estimate */
y_1 = (flt2.i >> 11) * (flt2.i >> 11);
y_1 = (y_1 >> 8) * (x >> 8);
y_1 = f - y_1;
flt2.i = (flt2.i >> 11) * (y_1 >> 11);
/* If the original argument is less than 342, we do another
* iteration to improve precision (for arguments >= 342, the single
* iteration produces generally better results).
*/
if (x < 171)
{
y_1 = (flt2.i >> 11) * (flt2.i >> 11);
y_1 = (y_1 >> 8) * (x >> 8);
y_1 = f - y_1;
flt2.i = (flt2.i >> 11) * (y_1 >> 11);
}
/* Invert, round and convert from 10.22 to an integer
* 0x1e3c68 is a magical rounding constant that produces slightly
* better results than 0x200000.
*/
return (number * flt2.i + 0x1e3c68) >> 22;
#endif
}
void
_clutter_bezier_init (ClutterBezier *b,
gint x_0, gint y_0,
gint x_1, gint y_1,
gint x_2, gint y_2,
gint x_3, gint y_3)
{
_FixedT t;
int i;
int xp = x_0;
int yp = y_0;
_FixedT length [CBZ_T_SAMPLES + 1];
#if 0
g_debug ("Initializing bezier at {{%d,%d},{%d,%d},{%d,%d},{%d,%d}}",
x0, y0, x1, y1, x2, y2, x3, y3);
#endif
b->dx = x_0;
b->dy = y_0;
b->cx = 3 * (x_1 - x_0);
b->cy = 3 * (y_1 - y_0);
b->bx = 3 * (x_2 - x_1) - b->cx;
b->by = 3 * (y_2 - y_1) - b->cy;
b->ax = x_3 - 3 * x_2 + 3 * x_1 - x_0;
b->ay = y_3 - 3 * y_2 + 3 * y_1 - y_0;
#if 0
g_debug ("Cooeficients {{%d,%d},{%d,%d},{%d,%d},{%d,%d}}",
b->ax, b->ay, b->bx, b->by, b->cx, b->cy, b->dx, b->dy);
#endif
/*
* Because of the way we do the multiplication in bezeir_t2x,y
* these coefficients need to be at most 0x1fff; this should be the case,
* I think, but have added this warning to catch any problems -- if it
* triggers, we need to change those two functions a bit.
*/
if (b->ax > 0x1fff || b->bx > 0x1fff || b->cx > 0x1fff)
g_warning ("Calculated coefficients will result in multiplication "
"overflow in clutter_bezier_t2x and clutter_bezier_t2y.");
/*
* Sample the bezier with CBZ_T_SAMPLES and calculate length at
* each point.
*
* We are working with integers here, so we use the fast sqrti function.
*/
length[0] = 0;
for (t = CBZ_T_STEP, i = 1; i <= CBZ_T_SAMPLES; ++i, t += CBZ_T_STEP)
{
int x = _clutter_bezier_t2x (b, t);
int y = _clutter_bezier_t2y (b, t);
guint l = sqrti ((y - yp)*(y - yp) + (x - xp)*(x - xp));
l += length[i-1];
length[i] = l;
xp = x;
yp = y;
}
b->length = length[CBZ_T_SAMPLES];
#if 0
g_debug ("length %d", b->length);
#endif
}
guint
_clutter_bezier_get_length (const ClutterBezier *b)
{
return b->length;
}

View file

@ -1,55 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Tomas Frydrych <tf@openedhand.com>
*
* Copyright (C) 2006, 2007 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib.h>
#include "clutter/clutter-types.h"
G_BEGIN_DECLS
/* This is used in _clutter_bezier_advance to represent the full
length of the bezier curve. Anything less than that represents a
fraction of the length */
#define CLUTTER_BEZIER_MAX_LENGTH (1 << 18)
typedef struct _ClutterBezier ClutterBezier;
ClutterBezier *_clutter_bezier_new (void);
void _clutter_bezier_free (ClutterBezier * b);
void _clutter_bezier_advance (const ClutterBezier *b,
gint L,
ClutterKnot *knot);
void _clutter_bezier_init (ClutterBezier *b,
gint x_0, gint y_0,
gint x_1, gint y_1,
gint x_2, gint y_2,
gint x_3, gint y_3);
guint _clutter_bezier_get_length (const ClutterBezier *b);
G_END_DECLS

View file

@ -1021,38 +1021,6 @@ typedef enum /*< prefix=CLUTTER_UNIT >*/
CLUTTER_UNIT_CM
} ClutterUnitType;
#define CLUTTER_PATH_RELATIVE (32)
/**
* ClutterPathNodeType:
* @CLUTTER_PATH_MOVE_TO: jump to the given position
* @CLUTTER_PATH_LINE_TO: create a line from the last node to the
* given position
* @CLUTTER_PATH_CURVE_TO: bezier curve using the last position and
* three control points.
* @CLUTTER_PATH_CLOSE: create a line from the last node to the last
* %CLUTTER_PATH_MOVE_TO node.
* @CLUTTER_PATH_REL_MOVE_TO: same as %CLUTTER_PATH_MOVE_TO but with
* coordinates relative to the last node.
* @CLUTTER_PATH_REL_LINE_TO: same as %CLUTTER_PATH_LINE_TO but with
* coordinates relative to the last node.
* @CLUTTER_PATH_REL_CURVE_TO: same as %CLUTTER_PATH_CURVE_TO but with
* coordinates relative to the last node.
*
* Types of nodes in a #ClutterPath.
*/
typedef enum
{
CLUTTER_PATH_MOVE_TO = 0,
CLUTTER_PATH_LINE_TO = 1,
CLUTTER_PATH_CURVE_TO = 2,
CLUTTER_PATH_CLOSE = 3,
CLUTTER_PATH_REL_MOVE_TO = CLUTTER_PATH_MOVE_TO | CLUTTER_PATH_RELATIVE,
CLUTTER_PATH_REL_LINE_TO = CLUTTER_PATH_LINE_TO | CLUTTER_PATH_RELATIVE,
CLUTTER_PATH_REL_CURVE_TO = CLUTTER_PATH_CURVE_TO | CLUTTER_PATH_RELATIVE
} ClutterPathNodeType;
/**
* ClutterActorAlign:
* @CLUTTER_ACTOR_ALIGN_FILL: Stretch to cover the whole allocated space

View file

@ -1,366 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
/**
* ClutterPathConstraint:
*
* A constraint that follows a path
*
* #ClutterPathConstraint is a simple constraint that modifies the allocation
* of the [class@Actor] to which it has been applied using a [class@Path].
*
* By setting the [property@PathConstraint:offset] property it is possible to
* control how far along the path the [class@Actor] should be..
*/
#include "config.h"
#include "clutter/clutter-path-constraint.h"
#include "clutter/clutter-debug.h"
#include "clutter/clutter-marshal.h"
#include "clutter/clutter-private.h"
#define CLUTTER_PATH_CONSTRAINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_PATH_CONSTRAINT, ClutterPathConstraintClass))
#define CLUTTER_IS_PATH_CONSTRAINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_PATH_CONSTRAINT))
#define CLUTTER_PATH_CONSTRAINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_PATH_CONSTRAINT, ClutterPathConstraintClass))
struct _ClutterPathConstraint
{
ClutterConstraint parent_instance;
ClutterPath *path;
gfloat offset;
ClutterActor *actor;
guint current_node;
};
struct _ClutterPathConstraintClass
{
ClutterConstraintClass parent_class;
};
enum
{
PROP_0,
PROP_PATH,
PROP_OFFSET,
LAST_PROPERTY
};
enum
{
NODE_REACHED,
LAST_SIGNAL
};
G_DEFINE_TYPE (ClutterPathConstraint, clutter_path_constraint, CLUTTER_TYPE_CONSTRAINT);
static GParamSpec *path_properties[LAST_PROPERTY] = { NULL, };
static guint path_signals[LAST_SIGNAL] = { 0, };
static void
clutter_path_constraint_update_allocation (ClutterConstraint *constraint,
ClutterActor *actor,
ClutterActorBox *allocation)
{
ClutterPathConstraint *self = CLUTTER_PATH_CONSTRAINT (constraint);
gfloat width, height;
ClutterKnot position;
guint knot_id;
if (self->path == NULL)
return;
knot_id = clutter_path_get_position (self->path, self->offset, &position);
clutter_actor_box_get_size (allocation, &width, &height);
allocation->x1 = position.x;
allocation->y1 = position.y;
allocation->x2 = allocation->x1 + width;
allocation->y2 = allocation->y1 + height;
if (knot_id != self->current_node)
{
self->current_node = knot_id;
g_signal_emit (self, path_signals[NODE_REACHED], 0,
self->actor,
self->current_node);
}
}
static void
clutter_path_constraint_set_actor (ClutterActorMeta *meta,
ClutterActor *new_actor)
{
ClutterPathConstraint *path = CLUTTER_PATH_CONSTRAINT (meta);
ClutterActorMetaClass *parent;
/* store the pointer to the actor, for later use */
path->actor = new_actor;
parent = CLUTTER_ACTOR_META_CLASS (clutter_path_constraint_parent_class);
parent->set_actor (meta, new_actor);
}
static void
clutter_path_constraint_dispose (GObject *gobject)
{
ClutterPathConstraint *self = CLUTTER_PATH_CONSTRAINT (gobject);
g_clear_object (&self->path);
G_OBJECT_CLASS (clutter_path_constraint_parent_class)->dispose (gobject);
}
static void
clutter_path_constraint_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterPathConstraint *self = CLUTTER_PATH_CONSTRAINT (gobject);
switch (prop_id)
{
case PROP_PATH:
clutter_path_constraint_set_path (self, g_value_get_object (value));
break;
case PROP_OFFSET:
clutter_path_constraint_set_offset (self, g_value_get_float (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}
static void
clutter_path_constraint_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterPathConstraint *self = CLUTTER_PATH_CONSTRAINT (gobject);
switch (prop_id)
{
case PROP_PATH:
g_value_set_object (value, self->path);
break;
case PROP_OFFSET:
g_value_set_float (value, self->offset);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}
static void
clutter_path_constraint_class_init (ClutterPathConstraintClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorMetaClass *meta_class = CLUTTER_ACTOR_META_CLASS (klass);
ClutterConstraintClass *constraint_class = CLUTTER_CONSTRAINT_CLASS (klass);
/**
* ClutterPathConstraint:path:
*
* The #ClutterPath used to constrain the position of an actor.
*/
path_properties[PROP_PATH] =
g_param_spec_object ("path", NULL, NULL,
CLUTTER_TYPE_PATH,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
/**
* ClutterPathConstraint:offset:
*
* The offset along the #ClutterPathConstraint:path, between -1.0 and 2.0.
*/
path_properties[PROP_OFFSET] =
g_param_spec_float ("offset", NULL, NULL,
-1.0, 2.0,
0.0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
gobject_class->set_property = clutter_path_constraint_set_property;
gobject_class->get_property = clutter_path_constraint_get_property;
gobject_class->dispose = clutter_path_constraint_dispose;
g_object_class_install_properties (gobject_class,
LAST_PROPERTY,
path_properties);
meta_class->set_actor = clutter_path_constraint_set_actor;
constraint_class->update_allocation = clutter_path_constraint_update_allocation;
/**
* ClutterPathConstraint::node-reached:
* @constraint: the #ClutterPathConstraint that emitted the signal
* @actor: the #ClutterActor using the @constraint
* @index: the index of the node that has been reached
*
* The signal is emitted each time a
* #ClutterPathConstraint:offset value results in the actor
* passing a #ClutterPathNode
*/
path_signals[NODE_REACHED] =
g_signal_new (I_("node-reached"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_clutter_marshal_VOID__OBJECT_UINT,
G_TYPE_NONE, 2,
CLUTTER_TYPE_ACTOR,
G_TYPE_UINT);
}
static void
clutter_path_constraint_init (ClutterPathConstraint *self)
{
self->offset = 0.0f;
self->current_node = G_MAXUINT;
}
/**
* clutter_path_constraint_new:
* @path: (allow-none): a #ClutterPath, or %NULL
* @offset: the offset along the #ClutterPath
*
* Creates a new #ClutterPathConstraint with the given @path and @offset
*
* Return value: the newly created #ClutterPathConstraint
*/
ClutterConstraint *
clutter_path_constraint_new (ClutterPath *path,
gfloat offset)
{
g_return_val_if_fail (path == NULL || CLUTTER_IS_PATH (path), NULL);
return g_object_new (CLUTTER_TYPE_PATH_CONSTRAINT,
"path", path,
"offset", offset,
NULL);
}
/**
* clutter_path_constraint_set_path:
* @constraint: a #ClutterPathConstraint
* @path: (allow-none): a #ClutterPath
*
* Sets the @path to be followed by the #ClutterPathConstraint.
*
* The @constraint will take ownership of the #ClutterPath passed to this
* function.
*/
void
clutter_path_constraint_set_path (ClutterPathConstraint *constraint,
ClutterPath *path)
{
g_return_if_fail (CLUTTER_IS_PATH_CONSTRAINT (constraint));
g_return_if_fail (path == NULL || CLUTTER_IS_PATH (path));
if (constraint->path == path)
return;
g_clear_object (&constraint->path);
if (path != NULL)
constraint->path = g_object_ref_sink (path);
if (constraint->actor != NULL)
clutter_actor_queue_relayout (constraint->actor);
g_object_notify_by_pspec (G_OBJECT (constraint), path_properties[PROP_PATH]);
}
/**
* clutter_path_constraint_get_path:
* @constraint: a #ClutterPathConstraint
*
* Retrieves a pointer to the #ClutterPath used by @constraint.
*
* Return value: (transfer none): the #ClutterPath used by the
* #ClutterPathConstraint, or %NULL. The returned #ClutterPath is owned
* by the constraint and it should not be unreferenced
*/
ClutterPath *
clutter_path_constraint_get_path (ClutterPathConstraint *constraint)
{
g_return_val_if_fail (CLUTTER_IS_PATH_CONSTRAINT (constraint), NULL);
return constraint->path;
}
/**
* clutter_path_constraint_set_offset:
* @constraint: a #ClutterPathConstraint
* @offset: the offset along the path
*
* Sets the offset along the #ClutterPath used by @constraint.
*/
void
clutter_path_constraint_set_offset (ClutterPathConstraint *constraint,
gfloat offset)
{
g_return_if_fail (CLUTTER_IS_PATH_CONSTRAINT (constraint));
if (constraint->offset == offset)
return;
constraint->offset = offset;
if (constraint->actor != NULL)
clutter_actor_queue_relayout (constraint->actor);
g_object_notify_by_pspec (G_OBJECT (constraint), path_properties[PROP_OFFSET]);
}
/**
* clutter_path_constraint_get_offset:
* @constraint: a #ClutterPathConstraint
*
* Retrieves the offset along the [class@Path] used by @constraint.
*
* Return value: the offset
*/
gfloat
clutter_path_constraint_get_offset (ClutterPathConstraint *constraint)
{
g_return_val_if_fail (CLUTTER_IS_PATH_CONSTRAINT (constraint), 0.0);
return constraint->offset;
}

View file

@ -1,61 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
#pragma once
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#include "clutter/clutter-constraint.h"
#include "clutter/clutter-path.h"
G_BEGIN_DECLS
#define CLUTTER_TYPE_PATH_CONSTRAINT (clutter_path_constraint_get_type ())
#define CLUTTER_PATH_CONSTRAINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_PATH_CONSTRAINT, ClutterPathConstraint))
#define CLUTTER_IS_PATH_CONSTRAINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_PATH_CONSTRAINT))
typedef struct _ClutterPathConstraint ClutterPathConstraint;
typedef struct _ClutterPathConstraintClass ClutterPathConstraintClass;
CLUTTER_EXPORT
GType clutter_path_constraint_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterConstraint *clutter_path_constraint_new (ClutterPath *path,
gfloat offset);
CLUTTER_EXPORT
void clutter_path_constraint_set_path (ClutterPathConstraint *constraint,
ClutterPath *path);
CLUTTER_EXPORT
ClutterPath * clutter_path_constraint_get_path (ClutterPathConstraint *constraint);
CLUTTER_EXPORT
void clutter_path_constraint_set_offset (ClutterPathConstraint *constraint,
gfloat offset);
CLUTTER_EXPORT
gfloat clutter_path_constraint_get_offset (ClutterPathConstraint *constraint);
G_END_DECLS

File diff suppressed because it is too large Load diff

View file

@ -1,159 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2008 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#include "clutter/clutter-types.h"
G_BEGIN_DECLS
#define CLUTTER_TYPE_PATH (clutter_path_get_type ())
#define CLUTTER_TYPE_PATH_NODE (clutter_path_node_get_type ())
#define CLUTTER_PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_PATH, ClutterPath))
#define CLUTTER_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_PATH, ClutterPathClass))
#define CLUTTER_IS_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_PATH))
#define CLUTTER_IS_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_PATH))
#define CLUTTER_PATH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_PATH, ClutterPathClass))
typedef struct _ClutterPathClass ClutterPathClass;
typedef struct _ClutterPathPrivate ClutterPathPrivate;
/**
* ClutterPathCallback:
* @node: the node
* @data: (closure): optional data passed to the function
*
* This function is passed to [method@Path.foreach] and will be
* called for each node contained in the path.
*/
typedef void (* ClutterPathCallback) (const ClutterPathNode *node,
gpointer data);
struct _ClutterPath
{
/*< private >*/
GInitiallyUnowned parent;
ClutterPathPrivate *priv;
};
/**
* ClutterPathClass:
*
* The #ClutterPathClass struct contains only private data.
*/
struct _ClutterPathClass
{
/*< private >*/
GInitiallyUnownedClass parent_class;
};
CLUTTER_EXPORT
GType clutter_path_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterPath *clutter_path_new (void);
CLUTTER_EXPORT
ClutterPath *clutter_path_new_with_description (const gchar *desc);
CLUTTER_EXPORT
void clutter_path_add_move_to (ClutterPath *path,
gint x,
gint y);
CLUTTER_EXPORT
void clutter_path_add_rel_move_to (ClutterPath *path,
gint x,
gint y);
CLUTTER_EXPORT
void clutter_path_add_line_to (ClutterPath *path,
gint x,
gint y);
CLUTTER_EXPORT
void clutter_path_add_rel_line_to (ClutterPath *path,
gint x,
gint y);
CLUTTER_EXPORT
void clutter_path_add_curve_to (ClutterPath *path,
gint x_1,
gint y_1,
gint x_2,
gint y_2,
gint x_3,
gint y_3);
CLUTTER_EXPORT
void clutter_path_add_rel_curve_to (ClutterPath *path,
gint x_1,
gint y_1,
gint x_2,
gint y_2,
gint x_3,
gint y_3);
CLUTTER_EXPORT
void clutter_path_add_close (ClutterPath *path);
CLUTTER_EXPORT
gboolean clutter_path_add_string (ClutterPath *path,
const gchar *str);
CLUTTER_EXPORT
void clutter_path_add_node (ClutterPath *path,
const ClutterPathNode *node);
CLUTTER_EXPORT
guint clutter_path_get_n_nodes (ClutterPath *path);
CLUTTER_EXPORT
void clutter_path_get_node (ClutterPath *path,
guint index_,
ClutterPathNode *node);
CLUTTER_EXPORT
GSList * clutter_path_get_nodes (ClutterPath *path);
CLUTTER_EXPORT
void clutter_path_foreach (ClutterPath *path,
ClutterPathCallback callback,
gpointer user_data);
CLUTTER_EXPORT
void clutter_path_insert_node (ClutterPath *path,
gint index_,
const ClutterPathNode *node);
CLUTTER_EXPORT
void clutter_path_remove_node (ClutterPath *path,
guint index_);
CLUTTER_EXPORT
void clutter_path_replace_node (ClutterPath *path,
guint index_,
const ClutterPathNode *node);
CLUTTER_EXPORT
gchar * clutter_path_get_description (ClutterPath *path);
CLUTTER_EXPORT
gboolean clutter_path_set_description (ClutterPath *path,
const gchar *str);
CLUTTER_EXPORT
void clutter_path_clear (ClutterPath *path);
CLUTTER_EXPORT
guint clutter_path_get_position (ClutterPath *path,
gdouble progress,
ClutterKnot *position);
CLUTTER_EXPORT
guint clutter_path_get_length (ClutterPath *path);
G_END_DECLS

View file

@ -36,7 +36,6 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_ACTOR_BOX (clutter_actor_box_get_type ())
#define CLUTTER_TYPE_KNOT (clutter_knot_get_type ())
#define CLUTTER_TYPE_MARGIN (clutter_margin_get_type ())
#define CLUTTER_TYPE_PAINT_VOLUME (clutter_paint_volume_get_type ())
#define CLUTTER_TYPE_PERSPECTIVE (clutter_perspective_get_type ())
@ -69,13 +68,9 @@ typedef struct _ClutterAction ClutterAction;
typedef struct _ClutterConstraint ClutterConstraint;
typedef struct _ClutterEffect ClutterEffect;
typedef struct _ClutterPath ClutterPath;
typedef struct _ClutterPathNode ClutterPathNode;
typedef struct _ClutterActorBox ClutterActorBox;
typedef struct _ClutterColor ClutterColor;
typedef struct _ClutterColorState ClutterColorState;
typedef struct _ClutterKnot ClutterKnot;
typedef struct _ClutterMargin ClutterMargin;
typedef struct _ClutterPerspective ClutterPerspective;
@ -258,59 +253,6 @@ void clutter_actor_box_scale (ClutterActorBox *box,
CLUTTER_EXPORT
gboolean clutter_actor_box_is_initialized (ClutterActorBox *box);
/**
* ClutterKnot:
* @x: X coordinate of the knot
* @y: Y coordinate of the knot
*
* Point in a path behaviour.
*/
struct _ClutterKnot
{
gint x;
gint y;
};
CLUTTER_EXPORT
GType clutter_knot_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterKnot *clutter_knot_copy (const ClutterKnot *knot);
CLUTTER_EXPORT
void clutter_knot_free (ClutterKnot *knot);
CLUTTER_EXPORT
gboolean clutter_knot_equal (const ClutterKnot *knot_a,
const ClutterKnot *knot_b);
/**
* ClutterPathNode:
* @type: the node's type
* @points: the coordinates of the node
*
* Represents a single node of a #ClutterPath.
*
* Some of the coordinates in @points may be unused for some node
* types. %CLUTTER_PATH_MOVE_TO and %CLUTTER_PATH_LINE_TO use only one
* pair of coordinates, %CLUTTER_PATH_CURVE_TO uses all three and
* %CLUTTER_PATH_CLOSE uses none.
*/
struct _ClutterPathNode
{
ClutterPathNodeType type;
ClutterKnot points[3];
};
CLUTTER_EXPORT
GType clutter_path_node_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterPathNode *clutter_path_node_copy (const ClutterPathNode *node);
CLUTTER_EXPORT
void clutter_path_node_free (ClutterPathNode *node);
CLUTTER_EXPORT
gboolean clutter_path_node_equal (const ClutterPathNode *node_a,
const ClutterPathNode *node_b);
/*
* ClutterPaintVolume
*/

View file

@ -82,8 +82,6 @@
#include "clutter/clutter-paint-nodes.h"
#include "clutter/clutter-paint-node.h"
#include "clutter/clutter-pan-action.h"
#include "clutter/clutter-path-constraint.h"
#include "clutter/clutter-path.h"
#include "clutter/clutter-property-transition.h"
#include "clutter/clutter-rotate-action.h"
#include "clutter/clutter-scroll-actor.h"

View file

@ -60,8 +60,6 @@ clutter_headers = [
'clutter-paint-nodes.h',
'clutter-paint-node.h',
'clutter-pan-action.h',
'clutter-path-constraint.h',
'clutter-path.h',
'clutter-pick-context.h',
'clutter-property-transition.h',
'clutter-rotate-action.h',
@ -96,7 +94,6 @@ clutter_sources = [
'clutter-animatable.c',
'clutter-backend.c',
'clutter-base-types.c',
'clutter-bezier.c',
'clutter-bind-constraint.c',
'clutter-binding-pool.c',
'clutter-bin-layout.c',
@ -148,8 +145,6 @@ clutter_sources = [
'clutter-paint-nodes.c',
'clutter-paint-node.c',
'clutter-pan-action.c',
'clutter-path-constraint.c',
'clutter-path.c',
'clutter-pick-context.c',
'clutter-pick-stack.c',
'clutter-property-transition.c',
@ -181,7 +176,6 @@ clutter_private_headers = [
'clutter-actor-meta-private.h',
'clutter-actor-private.h',
'clutter-backend-private.h',
'clutter-bezier.h',
'clutter-blur-private.h',
'clutter-constraint-private.h',
'clutter-content-private.h',

View file

@ -1,644 +0,0 @@
#include <clutter/clutter.h>
#include <cairo.h>
#include <string.h>
#include <math.h>
#include "test-conform-common.h"
#define MAX_NODES 128
#define FLOAT_FUZZ_AMOUNT 5.0f
typedef struct _CallbackData CallbackData;
typedef gboolean (* PathTestFunc) (CallbackData *data);
static void compare_node (const ClutterPathNode *node, gpointer data_p);
struct _CallbackData
{
ClutterPath *path;
guint n_nodes;
ClutterPathNode nodes[MAX_NODES];
gboolean nodes_different;
guint nodes_found;
};
static const char path_desc[] =
"M 21 22 "
"L 25 26 "
"C 29 30 31 32 33 34 "
"m 23 24 "
"l 27 28 "
"c 35 36 37 38 39 40 "
"z";
static const ClutterPathNode path_nodes[] =
{ { CLUTTER_PATH_MOVE_TO, { { 21, 22 }, { 0, 0 }, { 0, 0 } } },
{ CLUTTER_PATH_LINE_TO, { { 25, 26 }, { 0, 0 }, { 0, 0 } } },
{ CLUTTER_PATH_CURVE_TO, { { 29, 30 }, { 31, 32 }, { 33, 34 } } },
{ CLUTTER_PATH_REL_MOVE_TO, { { 23, 24 }, { 0, 0 }, { 0, 0 } } },
{ CLUTTER_PATH_REL_LINE_TO, { { 27, 28 }, { 0, 0 }, { 0, 0 } } },
{ CLUTTER_PATH_REL_CURVE_TO, { { 35, 36 }, { 37, 38 }, { 39, 40 } } },
{ CLUTTER_PATH_CLOSE, { { 0, 0 }, { 0, 0 }, { 0, 0 } } } };
static gboolean
path_test_add_move_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_MOVE_TO;
node.points[0].x = 1;
node.points[0].y = 2;
clutter_path_add_move_to (data->path, node.points[0].x, node.points[0].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_line_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_LINE_TO;
node.points[0].x = 3;
node.points[0].y = 4;
clutter_path_add_line_to (data->path, node.points[0].x, node.points[0].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_curve_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_CURVE_TO;
node.points[0].x = 5;
node.points[0].y = 6;
node.points[1].x = 7;
node.points[1].y = 8;
node.points[2].x = 9;
node.points[2].y = 10;
clutter_path_add_curve_to (data->path,
node.points[0].x, node.points[0].y,
node.points[1].x, node.points[1].y,
node.points[2].x, node.points[2].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_close (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_CLOSE;
clutter_path_add_close (data->path);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_rel_move_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_REL_MOVE_TO;
node.points[0].x = 11;
node.points[0].y = 12;
clutter_path_add_rel_move_to (data->path, node.points[0].x, node.points[0].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_rel_line_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_REL_LINE_TO;
node.points[0].x = 13;
node.points[0].y = 14;
clutter_path_add_rel_line_to (data->path, node.points[0].x, node.points[0].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_rel_curve_to (CallbackData *data)
{
ClutterPathNode node = { 0, };
node.type = CLUTTER_PATH_REL_CURVE_TO;
node.points[0].x = 15;
node.points[0].y = 16;
node.points[1].x = 17;
node.points[1].y = 18;
node.points[2].x = 19;
node.points[2].y = 20;
clutter_path_add_rel_curve_to (data->path,
node.points[0].x, node.points[0].y,
node.points[1].x, node.points[1].y,
node.points[2].x, node.points[2].y);
data->nodes[data->n_nodes++] = node;
return TRUE;
}
static gboolean
path_test_add_string (CallbackData *data)
{
int i;
for (i = 0; i < G_N_ELEMENTS (path_nodes); i++)
data->nodes[data->n_nodes++] = path_nodes[i];
clutter_path_add_string (data->path, path_desc);
return TRUE;
}
static gboolean
path_test_add_node_by_struct (CallbackData *data)
{
int i;
for (i = 0; i < G_N_ELEMENTS (path_nodes); i++)
{
data->nodes[data->n_nodes++] = path_nodes[i];
clutter_path_add_node (data->path, path_nodes + i);
}
return TRUE;
}
static gboolean
path_test_get_n_nodes (CallbackData *data)
{
return clutter_path_get_n_nodes (data->path) == data->n_nodes;
}
static gboolean
path_test_get_node (CallbackData *data)
{
int i;
data->nodes_found = 0;
data->nodes_different = FALSE;
for (i = 0; i < data->n_nodes; i++)
{
ClutterPathNode node;
clutter_path_get_node (data->path, i, &node);
compare_node (&node, data);
}
return !data->nodes_different;
}
static gboolean
path_test_get_nodes (CallbackData *data)
{
GSList *list, *node;
data->nodes_found = 0;
data->nodes_different = FALSE;
list = clutter_path_get_nodes (data->path);
for (node = list; node; node = node->next)
compare_node (node->data, data);
g_slist_free (list);
return !data->nodes_different && data->nodes_found == data->n_nodes;
}
static gboolean
path_test_insert_beginning (CallbackData *data)
{
ClutterPathNode node;
node.type = CLUTTER_PATH_LINE_TO;
node.points[0].x = 41;
node.points[0].y = 42;
memmove (data->nodes + 1, data->nodes,
data->n_nodes++ * sizeof (ClutterPathNode));
data->nodes[0] = node;
clutter_path_insert_node (data->path, 0, &node);
return TRUE;
}
static gboolean
path_test_insert_end (CallbackData *data)
{
ClutterPathNode node;
node.type = CLUTTER_PATH_LINE_TO;
node.points[0].x = 43;
node.points[0].y = 44;
data->nodes[data->n_nodes++] = node;
clutter_path_insert_node (data->path, -1, &node);
return TRUE;
}
static gboolean
path_test_insert_middle (CallbackData *data)
{
ClutterPathNode node;
int pos = data->n_nodes / 2;
node.type = CLUTTER_PATH_LINE_TO;
node.points[0].x = 45;
node.points[0].y = 46;
memmove (data->nodes + pos + 1, data->nodes + pos,
(data->n_nodes - pos) * sizeof (ClutterPathNode));
data->nodes[pos] = node;
data->n_nodes++;
clutter_path_insert_node (data->path, pos, &node);
return TRUE;
}
static gboolean
path_test_clear (CallbackData *data)
{
clutter_path_clear (data->path);
data->n_nodes = 0;
return TRUE;
}
static gboolean
path_test_clear_insert (CallbackData *data)
{
return path_test_clear (data) && path_test_insert_middle (data);
}
static gboolean
path_test_remove_beginning (CallbackData *data)
{
memmove (data->nodes, data->nodes + 1,
--data->n_nodes * sizeof (ClutterPathNode));
clutter_path_remove_node (data->path, 0);
return TRUE;
}
static gboolean
path_test_remove_end (CallbackData *data)
{
clutter_path_remove_node (data->path, --data->n_nodes);
return TRUE;
}
static gboolean
path_test_remove_middle (CallbackData *data)
{
int pos = data->n_nodes / 2;
memmove (data->nodes + pos, data->nodes + pos + 1,
(--data->n_nodes - pos) * sizeof (ClutterPathNode));
clutter_path_remove_node (data->path, pos);
return TRUE;
}
static gboolean
path_test_remove_only (CallbackData *data)
{
return path_test_clear (data)
&& path_test_add_line_to (data)
&& path_test_remove_beginning (data);
}
static gboolean
path_test_replace (CallbackData *data)
{
ClutterPathNode node;
int pos = data->n_nodes / 2;
node.type = CLUTTER_PATH_LINE_TO;
node.points[0].x = 47;
node.points[0].y = 48;
data->nodes[pos] = node;
clutter_path_replace_node (data->path, pos, &node);
return TRUE;
}
static gboolean
path_test_set_description (CallbackData *data)
{
data->n_nodes = G_N_ELEMENTS (path_nodes);
memcpy (data->nodes, path_nodes, sizeof (path_nodes));
return clutter_path_set_description (data->path, path_desc);
}
static gboolean
path_test_get_description (CallbackData *data)
{
char *desc1, *desc2;
gboolean ret = TRUE;
desc1 = clutter_path_get_description (data->path);
clutter_path_clear (data->path);
if (!clutter_path_set_description (data->path, desc1))
ret = FALSE;
desc2 = clutter_path_get_description (data->path);
if (strcmp (desc1, desc2))
ret = FALSE;
g_free (desc1);
g_free (desc2);
return ret;
}
static gboolean
float_fuzzy_equals (float fa, float fb)
{
return fabs (fa - fb) <= FLOAT_FUZZ_AMOUNT;
}
static void
set_triangle_path (CallbackData *data)
{
/* Triangular shaped path hitting (0,0), (64,64) and (128,0) in four
parts. The two curves are actually straight lines */
static const ClutterPathNode nodes[] =
{ { CLUTTER_PATH_MOVE_TO, { { 0, 0 } } },
{ CLUTTER_PATH_LINE_TO, { { 32, 32 } } },
{ CLUTTER_PATH_CURVE_TO, { { 40, 40 }, { 56, 56 }, { 64, 64 } } },
{ CLUTTER_PATH_REL_CURVE_TO, { { 8, -8 }, { 24, -24 }, { 32, -32 } } },
{ CLUTTER_PATH_REL_LINE_TO, { { 32, -32 } } } };
gint i;
clutter_path_clear (data->path);
for (i = 0; i < G_N_ELEMENTS (nodes); i++)
clutter_path_add_node (data->path, nodes + i);
memcpy (data->nodes, nodes, sizeof (nodes));
data->n_nodes = G_N_ELEMENTS (nodes);
}
static gboolean
path_test_get_position (CallbackData *data)
{
static const float values[] = { 0.125f, 16.0f, 16.0f,
0.375f, 48.0f, 48.0f,
0.625f, 80.0f, 48.0f,
0.875f, 112.0f, 16.0f };
gint i;
set_triangle_path (data);
for (i = 0; i < G_N_ELEMENTS (values); i += 3)
{
ClutterKnot pos;
clutter_path_get_position (data->path,
values[i],
&pos);
if (!float_fuzzy_equals (values[i + 1], pos.x)
|| !float_fuzzy_equals (values[i + 2], pos.y))
return FALSE;
}
return TRUE;
}
static gboolean
path_test_get_length (CallbackData *data)
{
const float actual_length /* sqrt(64**2 + 64**2) * 2 */ = 181.019336f;
guint approx_length;
clutter_path_set_description (data->path, "M 0 0 L 46340 0");
g_object_get (data->path, "length", &approx_length, NULL);
if (!(fabs (approx_length - 46340.f) / 46340.f <= 0.15f))
{
if (!g_test_quiet ())
g_print ("M 0 0 L 46340 0 - Expected 46340, got %d instead.", approx_length);
return FALSE;
}
clutter_path_set_description (data->path, "M 0 0 L 46341 0");
g_object_get (data->path, "length", &approx_length, NULL);
if (!(fabs (approx_length - 46341.f) / 46341.f <= 0.15f))
{
if (!g_test_quiet ())
g_print ("M 0 0 L 46341 0 - Expected 46341, got %d instead.", approx_length);
return FALSE;
}
set_triangle_path (data);
g_object_get (data->path, "length", &approx_length, NULL);
/* Allow 15% margin of error */
if (!(fabs (approx_length - actual_length) / (float) actual_length <= 0.15f))
{
if (!g_test_quiet ())
g_print ("Expected %g, got %d instead.\n", actual_length, approx_length);
return FALSE;
}
return TRUE;
}
static gboolean
path_test_boxed_type (CallbackData *data)
{
gboolean ret = TRUE;
GSList *nodes, *l;
GValue value;
nodes = clutter_path_get_nodes (data->path);
memset (&value, 0, sizeof (value));
for (l = nodes; l; l = l->next)
{
g_value_init (&value, CLUTTER_TYPE_PATH_NODE);
g_value_set_boxed (&value, l->data);
if (!clutter_path_node_equal (l->data,
g_value_get_boxed (&value)))
ret = FALSE;
g_value_unset (&value);
}
g_slist_free (nodes);
return ret;
}
static const struct
{
const char *desc;
PathTestFunc func;
}
path_tests[] =
{
{ "Add line to", path_test_add_line_to },
{ "Add move to", path_test_add_move_to },
{ "Add curve to", path_test_add_curve_to },
{ "Add close", path_test_add_close },
{ "Add relative line to", path_test_add_rel_line_to },
{ "Add relative move to", path_test_add_rel_move_to },
{ "Add relative curve to", path_test_add_rel_curve_to },
{ "Add string", path_test_add_string },
{ "Add node by struct", path_test_add_node_by_struct },
{ "Get number of nodes", path_test_get_n_nodes },
{ "Get a node", path_test_get_node },
{ "Get all nodes", path_test_get_nodes },
{ "Insert at beginning", path_test_insert_beginning },
{ "Insert at end", path_test_insert_end },
{ "Insert at middle", path_test_insert_middle },
{ "Add after insert", path_test_add_line_to },
{ "Clear then insert", path_test_clear_insert },
{ "Add string again", path_test_add_string },
{ "Remove from beginning", path_test_remove_beginning },
{ "Remove from end", path_test_remove_end },
{ "Remove from middle", path_test_remove_middle },
{ "Add after remove", path_test_add_line_to },
{ "Remove only node", path_test_remove_only },
{ "Add after remove again", path_test_add_line_to },
{ "Replace a node", path_test_replace },
{ "Set description", path_test_set_description },
{ "Get description", path_test_get_description },
{ "Clear", path_test_clear },
{ "Get position", path_test_get_position },
{ "Check node boxed type", path_test_boxed_type },
{ "Get length", path_test_get_length }
};
static void
compare_node (const ClutterPathNode *node, gpointer data_p)
{
CallbackData *data = data_p;
if (data->nodes_found >= data->n_nodes)
data->nodes_different = TRUE;
else
{
guint n_points = 0, i;
const ClutterPathNode *onode = data->nodes + data->nodes_found;
if (node->type != onode->type)
data->nodes_different = TRUE;
switch (node->type & ~CLUTTER_PATH_RELATIVE)
{
case CLUTTER_PATH_MOVE_TO: n_points = 1; break;
case CLUTTER_PATH_LINE_TO: n_points = 1; break;
case CLUTTER_PATH_CURVE_TO: n_points = 3; break;
case CLUTTER_PATH_CLOSE: n_points = 0; break;
default:
data->nodes_different = TRUE;
break;
}
for (i = 0; i < n_points; i++)
if (node->points[i].x != onode->points[i].x
|| node->points[i].y != onode->points[i].y)
{
data->nodes_different = TRUE;
break;
}
}
data->nodes_found++;
}
static gboolean
compare_nodes (CallbackData *data)
{
data->nodes_different = FALSE;
data->nodes_found = 0;
clutter_path_foreach (data->path, compare_node, data);
return !data->nodes_different && data->nodes_found == data->n_nodes;
}
void
path_base (TestConformSimpleFixture *fixture,
gconstpointer _data)
{
CallbackData data;
gint i;
memset (&data, 0, sizeof (data));
data.path = clutter_path_new ();
for (i = 0; i < G_N_ELEMENTS (path_tests); i++)
{
gboolean succeeded;
if (!g_test_quiet ())
g_print ("%s... ", path_tests[i].desc);
succeeded = path_tests[i].func (&data) && compare_nodes (&data);
if (!g_test_quiet ())
g_print ("%s\n", succeeded ? "ok" : "FAIL");
g_assert (succeeded);
}
g_object_unref (data.path);
}

View file

@ -1,138 +0,0 @@
#include <stdlib.h>
#include <gmodule.h>
#include <clutter/clutter.h>
#include "tests/clutter-test-utils.h"
#define PATH_DESCRIPTION \
"M 0, 0 " \
"L 0, 300 " \
"L 300, 300 " \
"L 300, 0 " \
"L 0, 0"
static gboolean toggled = FALSE;
int
test_path_constraint_main (int argc,
char *argv[]);
static gboolean
on_button_press (ClutterActor *actor,
const ClutterEvent *event,
gpointer dummy G_GNUC_UNUSED)
{
if (!toggled)
clutter_actor_animate (actor, CLUTTER_EASE_OUT_CUBIC, 500,
"@constraints.path.offset", 1.0,
NULL);
else
clutter_actor_animate (actor, CLUTTER_EASE_OUT_CUBIC, 500,
"@constraints.path.offset", 0.0,
NULL);
toggled = !toggled;
return TRUE;
}
static gchar *
node_to_string (const ClutterPathNode *node)
{
GString *buffer = g_string_sized_new (256);
gsize len = 0, i;
switch (node->type)
{
case CLUTTER_PATH_MOVE_TO:
g_string_append (buffer, "move-to ");
len = 1;
break;
case CLUTTER_PATH_LINE_TO:
g_string_append (buffer, "line-to ");
len = 1;
break;
case CLUTTER_PATH_CURVE_TO:
g_string_append (buffer, "curve-to ");
len = 3;
break;
case CLUTTER_PATH_CLOSE:
g_string_append (buffer, "close");
len = 0;
break;
default:
break;
}
for (i = 0; i < len; i++)
{
if (i == 0)
g_string_append (buffer, "[ ");
g_string_append_printf (buffer, "[ %d, %d ]",
node->points[i].x,
node->points[i].y);
if (i == len - 1)
g_string_append (buffer, " ]");
}
return g_string_free (buffer, FALSE);
}
static void
on_node_reached (ClutterPathConstraint *constraint,
ClutterActor *actor,
guint index_)
{
ClutterPath *path = clutter_path_constraint_get_path (constraint);
ClutterPathNode node;
gchar *str;
clutter_path_get_node (path, index_, &node);
str = node_to_string (&node);
g_print ("Node %d reached: %s\n", index_, str);
g_free (str);
}
G_MODULE_EXPORT int
test_path_constraint_main (int argc,
char *argv[])
{
ClutterActor *stage, *rect;
ClutterPath *path;
ClutterColor rect_color = { 0xcc, 0x00, 0x00, 0xff };
clutter_test_init (&argc, &argv);
stage = clutter_test_get_stage ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Path Constraint");
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL);
path = clutter_path_new ();
clutter_path_set_description (path, PATH_DESCRIPTION);
rect = clutter_actor_new ();
clutter_actor_set_background_color (rect, &rect_color);
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_reactive (rect, TRUE);
clutter_actor_add_constraint_with_name (rect, "path", clutter_path_constraint_new (path, 0.0));
clutter_actor_add_child (stage, rect);
g_signal_connect (rect, "button-press-event", G_CALLBACK (on_button_press), NULL);
g_signal_connect (clutter_actor_get_constraint (rect, "path"),
"node-reached",
G_CALLBACK (on_node_reached),
NULL);
clutter_actor_show (stage);
clutter_test_main ();
return EXIT_SUCCESS;
}