mirror of
https://github.com/brl/mutter.git
synced 2024-11-10 07:56:14 -05:00
color: Add Color.interpolate() method
The interpolate() method does what it says on the tin: it interpolates between two colors using the given factor. ClutterColor uses it to register a progress function for Intervals.
This commit is contained in:
parent
7e112472b5
commit
d5376bf317
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <pango/pango-attributes.h>
|
#include <pango/pango-attributes.h>
|
||||||
|
|
||||||
|
#include "clutter-interval.h"
|
||||||
#include "clutter-main.h"
|
#include "clutter-main.h"
|
||||||
#include "clutter-color.h"
|
#include "clutter-color.h"
|
||||||
#include "clutter-private.h"
|
#include "clutter-private.h"
|
||||||
@ -555,6 +556,50 @@ clutter_color_hash (gconstpointer v)
|
|||||||
return clutter_color_to_pixel ((const ClutterColor *) v);
|
return clutter_color_to_pixel ((const ClutterColor *) v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clutter_color_interpolate:
|
||||||
|
* @initial: the initial #ClutterColor
|
||||||
|
* @final: the final #ClutterColor
|
||||||
|
* @progress: the interpolation progress
|
||||||
|
* @result: (out): return location for the interpolation
|
||||||
|
*
|
||||||
|
* Interpolates between @initial and @final #ClutterColor<!-- -->s
|
||||||
|
* using @progress
|
||||||
|
*
|
||||||
|
* Since: 1.6
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
clutter_color_interpolate (const ClutterColor *initial,
|
||||||
|
const ClutterColor *final,
|
||||||
|
gdouble progress,
|
||||||
|
ClutterColor *result)
|
||||||
|
{
|
||||||
|
g_return_if_fail (initial != NULL);
|
||||||
|
g_return_if_fail (final != NULL);
|
||||||
|
g_return_if_fail (result != NULL);
|
||||||
|
|
||||||
|
result->red = initial->red + (final->red - initial->red) * progress;
|
||||||
|
result->green = initial->green + (final->green - initial->green) * progress;
|
||||||
|
result->blue = initial->blue + (final->blue - initial->blue) * progress;
|
||||||
|
result->alpha = initial->alpha + (final->alpha - initial->alpha) * progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
clutter_color_progress (const GValue *a,
|
||||||
|
const GValue *b,
|
||||||
|
gdouble progress,
|
||||||
|
GValue *retval)
|
||||||
|
{
|
||||||
|
const ClutterColor *a_color = clutter_value_get_color (a);
|
||||||
|
const ClutterColor *b_color = clutter_value_get_color (b);
|
||||||
|
ClutterColor res = { 0, };
|
||||||
|
|
||||||
|
clutter_color_interpolate (a_color, b_color, progress, &res);
|
||||||
|
clutter_value_set_color (retval, &res);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_color_copy:
|
* clutter_color_copy:
|
||||||
* @color: a #ClutterColor
|
* @color: a #ClutterColor
|
||||||
@ -672,6 +717,9 @@ clutter_color_get_type (void)
|
|||||||
clutter_value_transform_color_string);
|
clutter_value_transform_color_string);
|
||||||
g_value_register_transform_func (G_TYPE_STRING, _clutter_color_type,
|
g_value_register_transform_func (G_TYPE_STRING, _clutter_color_type,
|
||||||
clutter_value_transform_string_color);
|
clutter_value_transform_string_color);
|
||||||
|
|
||||||
|
clutter_interval_register_progress_func (_clutter_color_type,
|
||||||
|
clutter_color_progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clutter_color_type;
|
return _clutter_color_type;
|
||||||
|
@ -102,6 +102,11 @@ guint clutter_color_hash (gconstpointer v);
|
|||||||
gboolean clutter_color_equal (gconstpointer v1,
|
gboolean clutter_color_equal (gconstpointer v1,
|
||||||
gconstpointer v2);
|
gconstpointer v2);
|
||||||
|
|
||||||
|
void clutter_color_interpolate (const ClutterColor *initial,
|
||||||
|
const ClutterColor *final,
|
||||||
|
gdouble progress,
|
||||||
|
ClutterColor *result);
|
||||||
|
|
||||||
#define CLUTTER_TYPE_PARAM_COLOR (clutter_param_color_get_type ())
|
#define CLUTTER_TYPE_PARAM_COLOR (clutter_param_color_get_type ())
|
||||||
#define CLUTTER_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), CLUTTER_TYPE_PARAM_COLOR, ClutterParamSpecColor))
|
#define CLUTTER_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), CLUTTER_TYPE_PARAM_COLOR, ClutterParamSpecColor))
|
||||||
#define CLUTTER_IS_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), CLUTTER_TYPE_PARAM_COLOR))
|
#define CLUTTER_IS_PARAM_SPEC_COLOR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), CLUTTER_TYPE_PARAM_COLOR))
|
||||||
|
@ -973,6 +973,7 @@ clutter_color_subtract
|
|||||||
clutter_color_lighten
|
clutter_color_lighten
|
||||||
clutter_color_darken
|
clutter_color_darken
|
||||||
clutter_color_shade
|
clutter_color_shade
|
||||||
|
clutter_color_interpolate
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
ClutterParamSpecColor
|
ClutterParamSpecColor
|
||||||
|
Loading…
Reference in New Issue
Block a user