css: Make GtkStyleAnimation and subclasses non-objects

Making them GObjects is unnecessary. This enables further optimizations
down the road. The only place we use them in is gtkcssanimatedstyle.c
after all.
This commit is contained in:
Timm Bäder 2020-05-06 19:17:11 +02:00
parent 57444f77f7
commit 1b10020b6e
9 changed files with 157 additions and 226 deletions

View File

@ -81,7 +81,7 @@ gtk_css_animated_style_dispose (GObject *object)
guint i; guint i;
for (i = 0; i < style->n_animations; i ++) for (i = 0; i < style->n_animations; i ++)
g_object_unref (style->animations[i]); gtk_style_animation_unref (style->animations[i]);
style->n_animations = 0; style->n_animations = 0;
g_free (style->animations); g_free (style->animations);
@ -646,7 +646,7 @@ gtk_css_animated_style_find_transition (GtkCssAnimatedStyle *style,
{ {
GtkStyleAnimation *animation = style->animations[i]; GtkStyleAnimation *animation = style->animations[i];
if (!GTK_IS_CSS_TRANSITION (animation)) if (!_gtk_css_transition_is_transition (animation))
continue; continue;
if (_gtk_css_transition_get_property ((GtkCssTransition *)animation) == property_id) if (_gtk_css_transition_get_property ((GtkCssTransition *)animation) == property_id)
@ -745,7 +745,7 @@ gtk_css_animated_style_find_animation (GtkStyleAnimation **animations,
{ {
GtkStyleAnimation *animation = animations[i]; GtkStyleAnimation *animation = animations[i];
if (!GTK_IS_CSS_ANIMATION (animation)) if (!_gtk_css_animation_is_animation (animation))
continue; continue;
if (g_str_equal (_gtk_css_animation_get_name ((GtkCssAnimation *)animation), name)) if (g_str_equal (_gtk_css_animation_get_name ((GtkCssAnimation *)animation), name))
@ -765,9 +765,19 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
{ {
GtkCssValue *durations, *delays, *timing_functions, *animation_names; GtkCssValue *durations, *delays, *timing_functions, *animation_names;
GtkCssValue *iteration_counts, *directions, *play_states, *fill_modes; GtkCssValue *iteration_counts, *directions, *play_states, *fill_modes;
gboolean source_is_animated;
guint i; guint i;
animation_names = base_style->animation->animation_name; animation_names = base_style->animation->animation_name;
if (_gtk_css_array_value_get_n_values (animation_names) == 1)
{
const char *name = _gtk_css_ident_value_get (_gtk_css_array_value_get_nth (animation_names, 0));
if (g_ascii_strcasecmp (name, "none") == 0)
return animations;
}
durations = base_style->animation->animation_duration; durations = base_style->animation->animation_duration;
delays = base_style->animation->animation_delay; delays = base_style->animation->animation_delay;
timing_functions = base_style->animation->animation_timing_function; timing_functions = base_style->animation->animation_timing_function;
@ -775,6 +785,7 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
directions = base_style->animation->animation_direction; directions = base_style->animation->animation_direction;
play_states = base_style->animation->animation_play_state; play_states = base_style->animation->animation_play_state;
fill_modes = base_style->animation->animation_fill_mode; fill_modes = base_style->animation->animation_fill_mode;
source_is_animated = GTK_IS_CSS_ANIMATED_STYLE (source);
for (i = 0; i < _gtk_css_array_value_get_n_values (animation_names); i++) for (i = 0; i < _gtk_css_array_value_get_n_values (animation_names); i++)
{ {
@ -792,14 +803,14 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
if (animation) if (animation)
continue; continue;
if (GTK_IS_CSS_ANIMATED_STYLE (source)) if (source_is_animated)
animation = gtk_css_animated_style_find_animation ((GtkStyleAnimation **)GTK_CSS_ANIMATED_STYLE (source)->animations, animation = gtk_css_animated_style_find_animation ((GtkStyleAnimation **)GTK_CSS_ANIMATED_STYLE (source)->animations,
GTK_CSS_ANIMATED_STYLE (source)->n_animations, GTK_CSS_ANIMATED_STYLE (source)->n_animations,
name); name);
if (animation) if (animation)
{ {
animation = _gtk_css_animation_advance_with_play_state (GTK_CSS_ANIMATION (animation), animation = _gtk_css_animation_advance_with_play_state ((GtkCssAnimation *)animation,
timestamp, timestamp,
_gtk_css_play_state_value_get (_gtk_css_array_value_get_nth (play_states, i))); _gtk_css_play_state_value_get (_gtk_css_array_value_get_nth (play_states, i)));
} }
@ -825,7 +836,7 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
} }
if (!animations) if (!animations)
animations = g_ptr_array_new (); animations = g_ptr_array_sized_new (16);
g_ptr_array_add (animations, animation); g_ptr_array_add (animations, animation);
} }
@ -928,7 +939,7 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
continue; continue;
if (!animations) if (!animations)
animations = g_ptr_array_new (); animations = g_ptr_array_sized_new (16);
animation = _gtk_style_animation_advance (animation, timestamp); animation = _gtk_style_animation_advance (animation, timestamp);
g_ptr_array_add (animations, animation); g_ptr_array_add (animations, animation);

View File

@ -26,8 +26,6 @@
#include <math.h> #include <math.h>
G_DEFINE_TYPE (GtkCssAnimation, _gtk_css_animation, GTK_TYPE_STYLE_ANIMATION)
static gboolean static gboolean
gtk_css_animation_is_executing (GtkCssAnimation *animation) gtk_css_animation_is_executing (GtkCssAnimation *animation)
{ {
@ -80,7 +78,7 @@ static GtkStyleAnimation *
gtk_css_animation_advance (GtkStyleAnimation *style_animation, gtk_css_animation_advance (GtkStyleAnimation *style_animation,
gint64 timestamp) gint64 timestamp)
{ {
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation); GtkCssAnimation *animation = (GtkCssAnimation *)style_animation;
return _gtk_css_animation_advance_with_play_state (animation, return _gtk_css_animation_advance_with_play_state (animation,
timestamp, timestamp,
@ -91,7 +89,7 @@ static void
gtk_css_animation_apply_values (GtkStyleAnimation *style_animation, gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
GtkCssAnimatedStyle *style) GtkCssAnimatedStyle *style)
{ {
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation); GtkCssAnimation *animation = (GtkCssAnimation *)style_animation;
double progress; double progress;
guint i; guint i;
@ -125,7 +123,7 @@ gtk_css_animation_is_finished (GtkStyleAnimation *style_animation)
static gboolean static gboolean
gtk_css_animation_is_static (GtkStyleAnimation *style_animation) gtk_css_animation_is_static (GtkStyleAnimation *style_animation)
{ {
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation); GtkCssAnimation *animation = (GtkCssAnimation *)style_animation;
if (animation->play_state == GTK_CSS_PLAY_STATE_PAUSED) if (animation->play_state == GTK_CSS_PLAY_STATE_PAUSED)
return TRUE; return TRUE;
@ -134,35 +132,26 @@ gtk_css_animation_is_static (GtkStyleAnimation *style_animation)
} }
static void static void
gtk_css_animation_finalize (GObject *object) gtk_css_animation_free (GtkStyleAnimation *animation)
{ {
GtkCssAnimation *animation = GTK_CSS_ANIMATION (object); GtkCssAnimation *self = (GtkCssAnimation *)animation;
g_free (animation->name); g_free (self->name);
_gtk_css_keyframes_unref (animation->keyframes); _gtk_css_keyframes_unref (self->keyframes);
_gtk_css_value_unref (animation->ease); _gtk_css_value_unref (self->ease);
G_OBJECT_CLASS (_gtk_css_animation_parent_class)->finalize (object); g_slice_free (GtkCssAnimation, self);
} }
static void static const GtkStyleAnimationClass GTK_CSS_ANIMATION_CLASS = {
_gtk_css_animation_class_init (GtkCssAnimationClass *klass) "GtkCssAnimation",
{ gtk_css_animation_free,
GObjectClass *object_class = G_OBJECT_CLASS (klass); gtk_css_animation_is_finished,
GtkStyleAnimationClass *animation_class = GTK_STYLE_ANIMATION_CLASS (klass); gtk_css_animation_is_static,
gtk_css_animation_apply_values,
gtk_css_animation_advance,
};
object_class->finalize = gtk_css_animation_finalize;
animation_class->advance = gtk_css_animation_advance;
animation_class->apply_values = gtk_css_animation_apply_values;
animation_class->is_finished = gtk_css_animation_is_finished;
animation_class->is_static = gtk_css_animation_is_static;
}
static void
_gtk_css_animation_init (GtkCssAnimation *animation)
{
}
GtkStyleAnimation * GtkStyleAnimation *
_gtk_css_animation_new (const char *name, _gtk_css_animation_new (const char *name,
@ -183,7 +172,9 @@ _gtk_css_animation_new (const char *name,
g_return_val_if_fail (ease != NULL, NULL); g_return_val_if_fail (ease != NULL, NULL);
g_return_val_if_fail (iteration_count >= 0, NULL); g_return_val_if_fail (iteration_count >= 0, NULL);
animation = g_object_new (GTK_TYPE_CSS_ANIMATION, NULL); animation = g_slice_alloc (sizeof (GtkCssAnimation));
animation->parent.class = &GTK_CSS_ANIMATION_CLASS;
animation->parent.ref_count = 1;
animation->name = g_strdup (name); animation->name = g_strdup (name);
animation->keyframes = _gtk_css_keyframes_ref (keyframes); animation->keyframes = _gtk_css_keyframes_ref (keyframes);
@ -198,14 +189,12 @@ _gtk_css_animation_new (const char *name,
else else
gtk_progress_tracker_advance_frame (&animation->tracker, timestamp); gtk_progress_tracker_advance_frame (&animation->tracker, timestamp);
return GTK_STYLE_ANIMATION (animation); return (GtkStyleAnimation *)animation;
} }
const char * const char *
_gtk_css_animation_get_name (GtkCssAnimation *animation) _gtk_css_animation_get_name (GtkCssAnimation *animation)
{ {
g_return_val_if_fail (GTK_IS_CSS_ANIMATION (animation), NULL);
return animation->name; return animation->name;
} }
@ -214,11 +203,9 @@ _gtk_css_animation_advance_with_play_state (GtkCssAnimation *source,
gint64 timestamp, gint64 timestamp,
GtkCssPlayState play_state) GtkCssPlayState play_state)
{ {
GtkCssAnimation *animation; GtkCssAnimation *animation = g_slice_alloc (sizeof (GtkCssAnimation));
animation->parent.class = &GTK_CSS_ANIMATION_CLASS;
g_return_val_if_fail (GTK_IS_CSS_ANIMATION (source), NULL); animation->parent.ref_count = 1;
animation = g_object_new (GTK_TYPE_CSS_ANIMATION, NULL);
animation->name = g_strdup (source->name); animation->name = g_strdup (source->name);
animation->keyframes = _gtk_css_keyframes_ref (source->keyframes); animation->keyframes = _gtk_css_keyframes_ref (source->keyframes);
@ -233,5 +220,11 @@ _gtk_css_animation_advance_with_play_state (GtkCssAnimation *source,
else else
gtk_progress_tracker_advance_frame (&animation->tracker, timestamp); gtk_progress_tracker_advance_frame (&animation->tracker, timestamp);
return GTK_STYLE_ANIMATION (animation); return (GtkStyleAnimation *)animation;
}
gboolean
_gtk_css_animation_is_animation (GtkStyleAnimation *animation)
{
return animation->class == &GTK_CSS_ANIMATION_CLASS;
} }

View File

@ -27,13 +27,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GTK_TYPE_CSS_ANIMATION (_gtk_css_animation_get_type ())
#define GTK_CSS_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_ANIMATION, GtkCssAnimation))
#define GTK_CSS_ANIMATION_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_ANIMATION, GtkCssAnimationClass))
#define GTK_IS_CSS_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_ANIMATION))
#define GTK_IS_CSS_ANIMATION_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_ANIMATION))
#define GTK_CSS_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_ANIMATION, GtkCssAnimationClass))
typedef struct _GtkCssAnimation GtkCssAnimation; typedef struct _GtkCssAnimation GtkCssAnimation;
typedef struct _GtkCssAnimationClass GtkCssAnimationClass; typedef struct _GtkCssAnimationClass GtkCssAnimationClass;
@ -73,6 +66,7 @@ GtkStyleAnimation * _gtk_css_animation_advance_with_play_state (GtkCssAnimat
GtkCssPlayState play_state); GtkCssPlayState play_state);
const char * _gtk_css_animation_get_name (GtkCssAnimation *animation); const char * _gtk_css_animation_get_name (GtkCssAnimation *animation);
gboolean _gtk_css_animation_is_animation (GtkStyleAnimation *animation);
G_END_DECLS G_END_DECLS

View File

@ -20,10 +20,13 @@
#include "config.h" #include "config.h"
#include "gtkcssdynamicprivate.h" #include "gtkcssdynamicprivate.h"
#include "gtkprogresstrackerprivate.h" #include "gtkprogresstrackerprivate.h"
G_DEFINE_TYPE (GtkCssDynamic, gtk_css_dynamic, GTK_TYPE_STYLE_ANIMATION) struct _GtkCssDynamic
{
GtkStyleAnimation parent;
gint64 timestamp;
};
static GtkStyleAnimation * static GtkStyleAnimation *
gtk_css_dynamic_advance (GtkStyleAnimation *style_animation, gtk_css_dynamic_advance (GtkStyleAnimation *style_animation,
@ -36,7 +39,7 @@ static void
gtk_css_dynamic_apply_values (GtkStyleAnimation *style_animation, gtk_css_dynamic_apply_values (GtkStyleAnimation *style_animation,
GtkCssAnimatedStyle *style) GtkCssAnimatedStyle *style)
{ {
GtkCssDynamic *dynamic = GTK_CSS_DYNAMIC (style_animation); GtkCssDynamic *dynamic = (GtkCssDynamic *)style_animation;
guint i; guint i;
for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++) for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
@ -65,30 +68,29 @@ gtk_css_dynamic_is_static (GtkStyleAnimation *style_animation)
} }
static void static void
gtk_css_dynamic_class_init (GtkCssDynamicClass *klass) gtk_css_dynamic_free (GtkStyleAnimation *animation)
{ {
GtkStyleAnimationClass *animation_class = GTK_STYLE_ANIMATION_CLASS (klass); g_slice_free (GtkCssDynamic, (GtkCssDynamic *)animation);
animation_class->advance = gtk_css_dynamic_advance;
animation_class->apply_values = gtk_css_dynamic_apply_values;
animation_class->is_finished = gtk_css_dynamic_is_finished;
animation_class->is_static = gtk_css_dynamic_is_static;
} }
static void static const GtkStyleAnimationClass GTK_CSS_DYNAMIC_CLASS = {
gtk_css_dynamic_init (GtkCssDynamic *dynamic) "GtkCssDynamic",
{ gtk_css_dynamic_free,
} gtk_css_dynamic_is_finished,
gtk_css_dynamic_is_static,
gtk_css_dynamic_apply_values,
gtk_css_dynamic_advance,
};
GtkStyleAnimation * GtkStyleAnimation *
gtk_css_dynamic_new (gint64 timestamp) gtk_css_dynamic_new (gint64 timestamp)
{ {
GtkCssDynamic *dynamic; GtkCssDynamic *dynamic = g_slice_alloc (sizeof (GtkCssDynamic));
dynamic = g_object_new (GTK_TYPE_CSS_DYNAMIC, NULL);
dynamic->parent.class = &GTK_CSS_DYNAMIC_CLASS;
dynamic->parent.ref_count = 1;
dynamic->timestamp = timestamp; dynamic->timestamp = timestamp;
return GTK_STYLE_ANIMATION (dynamic); return (GtkStyleAnimation *)dynamic;
} }

View File

@ -26,27 +26,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GTK_TYPE_CSS_DYNAMIC (gtk_css_dynamic_get_type ())
#define GTK_CSS_DYNAMIC(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_DYNAMIC, GtkCssDynamic))
#define GTK_CSS_DYNAMIC_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_DYNAMIC, GtkCssDynamicClass))
#define GTK_IS_CSS_DYNAMIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_DYNAMIC))
#define GTK_IS_CSS_DYNAMIC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_DYNAMIC))
#define GTK_CSS_DYNAMIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_DYNAMIC, GtkCssDynamicClass))
typedef struct _GtkCssDynamic GtkCssDynamic; typedef struct _GtkCssDynamic GtkCssDynamic;
typedef struct _GtkCssDynamicClass GtkCssDynamicClass;
struct _GtkCssDynamic
{
GtkStyleAnimation parent;
gint64 timestamp;
};
struct _GtkCssDynamicClass
{
GtkStyleAnimationClass parent_class;
};
GType gtk_css_dynamic_get_type (void) G_GNUC_CONST; GType gtk_css_dynamic_get_type (void) G_GNUC_CONST;

View File

@ -24,27 +24,22 @@
#include "gtkcsseasevalueprivate.h" #include "gtkcsseasevalueprivate.h"
#include "gtkprogresstrackerprivate.h" #include "gtkprogresstrackerprivate.h"
G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION) struct _GtkCssTransition
static GtkStyleAnimation *
gtk_css_transition_advance (GtkStyleAnimation *style_animation,
gint64 timestamp)
{ {
GtkCssTransition *source = (GtkCssTransition *)style_animation; GtkStyleAnimation parent;
GtkCssTransition *transition;
transition = g_object_new (GTK_TYPE_CSS_TRANSITION, NULL); guint property;
GtkCssValue *start;
GtkCssValue *ease;
GtkProgressTracker tracker;
guint finished;
};
transition->property = source->property;
transition->start = _gtk_css_value_ref (source->start);
transition->ease = _gtk_css_value_ref (source->ease);
gtk_progress_tracker_init_copy (&source->tracker, &transition->tracker); static GtkStyleAnimation * gtk_css_transition_advance (GtkStyleAnimation *style_animation,
gtk_progress_tracker_advance_frame (&transition->tracker, timestamp); gint64 timestamp);
transition->finished = gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER;
return (GtkStyleAnimation *)transition;
}
static void static void
gtk_css_transition_apply_values (GtkStyleAnimation *style_animation, gtk_css_transition_apply_values (GtkStyleAnimation *style_animation,
@ -99,35 +94,46 @@ gtk_css_transition_is_static (GtkStyleAnimation *animation)
} }
static void static void
gtk_css_transition_finalize (GObject *object) gtk_css_transition_free (GtkStyleAnimation *animation)
{ {
GtkCssTransition *transition = GTK_CSS_TRANSITION (object); GtkCssTransition *self = (GtkCssTransition *)animation;
_gtk_css_value_unref (transition->start); gtk_css_value_unref (self->start);
_gtk_css_value_unref (transition->ease); gtk_css_value_unref (self->ease);
G_OBJECT_CLASS (_gtk_css_transition_parent_class)->finalize (object); g_slice_free (GtkCssTransition, self);
} }
static void static const GtkStyleAnimationClass GTK_CSS_TRANSITION_CLASS = {
_gtk_css_transition_class_init (GtkCssTransitionClass *klass) "GtkCssTransition",
gtk_css_transition_free,
gtk_css_transition_is_finished,
gtk_css_transition_is_static,
gtk_css_transition_apply_values,
gtk_css_transition_advance,
};
static GtkStyleAnimation *
gtk_css_transition_advance (GtkStyleAnimation *style_animation,
gint64 timestamp)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkCssTransition *source = (GtkCssTransition *)style_animation;
GtkStyleAnimationClass *animation_class = GTK_STYLE_ANIMATION_CLASS (klass); GtkCssTransition *transition;
object_class->finalize = gtk_css_transition_finalize; transition = g_slice_alloc (sizeof (GtkCssTransition));
transition->parent.class = &GTK_CSS_TRANSITION_CLASS;
transition->parent.ref_count = 1;
animation_class->advance = gtk_css_transition_advance; transition->property = source->property;
animation_class->apply_values = gtk_css_transition_apply_values; transition->start = _gtk_css_value_ref (source->start);
animation_class->is_finished = gtk_css_transition_is_finished; transition->ease = _gtk_css_value_ref (source->ease);
animation_class->is_static = gtk_css_transition_is_static;
gtk_progress_tracker_init_copy (&source->tracker, &transition->tracker);
gtk_progress_tracker_advance_frame (&transition->tracker, timestamp);
transition->finished = gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER;
return (GtkStyleAnimation *)transition;
} }
static void
_gtk_css_transition_init (GtkCssTransition *transition)
{
}
GtkStyleAnimation * GtkStyleAnimation *
_gtk_css_transition_new (guint property, _gtk_css_transition_new (guint property,
GtkCssValue *start, GtkCssValue *start,
@ -141,7 +147,9 @@ _gtk_css_transition_new (guint property,
g_return_val_if_fail (start != NULL, NULL); g_return_val_if_fail (start != NULL, NULL);
g_return_val_if_fail (ease != NULL, NULL); g_return_val_if_fail (ease != NULL, NULL);
transition = g_object_new (GTK_TYPE_CSS_TRANSITION, NULL); transition = g_slice_alloc (sizeof (GtkCssTransition));
transition->parent.class = &GTK_CSS_TRANSITION_CLASS;
transition->parent.ref_count = 1;
transition->property = property; transition->property = property;
transition->start = _gtk_css_value_ref (start); transition->start = _gtk_css_value_ref (start);
@ -150,13 +158,17 @@ _gtk_css_transition_new (guint property,
gtk_progress_tracker_advance_frame (&transition->tracker, timestamp); gtk_progress_tracker_advance_frame (&transition->tracker, timestamp);
transition->finished = gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER; transition->finished = gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER;
return GTK_STYLE_ANIMATION (transition); return (GtkStyleAnimation*)transition;
} }
guint guint
_gtk_css_transition_get_property (GtkCssTransition *transition) _gtk_css_transition_get_property (GtkCssTransition *transition)
{ {
g_return_val_if_fail (GTK_IS_CSS_TRANSITION (transition), 0);
return transition->property; return transition->property;
} }
gboolean
_gtk_css_transition_is_transition (GtkStyleAnimation *animation)
{
return animation->class == &GTK_CSS_TRANSITION_CLASS;
}

View File

@ -25,26 +25,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GTK_TYPE_CSS_TRANSITION (_gtk_css_transition_get_type ())
#define GTK_CSS_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_TRANSITION, GtkCssTransition))
#define GTK_CSS_TRANSITION_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_TRANSITION, GtkCssTransitionClass))
#define GTK_IS_CSS_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_TRANSITION))
#define GTK_IS_CSS_TRANSITION_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_TRANSITION))
#define GTK_CSS_TRANSITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_TRANSITION, GtkCssTransitionClass))
typedef struct _GtkCssTransition GtkCssTransition;
typedef struct _GtkCssTransitionClass GtkCssTransitionClass; typedef struct _GtkCssTransitionClass GtkCssTransitionClass;
typedef struct _GtkCssTransition GtkCssTransition;
struct _GtkCssTransition
{
GtkStyleAnimation parent;
guint property;
GtkCssValue *start;
GtkCssValue *ease;
GtkProgressTracker tracker;
guint finished;
};
struct _GtkCssTransitionClass struct _GtkCssTransitionClass
{ {
@ -61,6 +43,7 @@ GtkStyleAnimation * _gtk_css_transition_new (guint
gint64 delay_us); gint64 delay_us);
guint _gtk_css_transition_get_property (GtkCssTransition *transition); guint _gtk_css_transition_get_property (GtkCssTransition *transition);
gboolean _gtk_css_transition_is_transition (GtkStyleAnimation *animation);
G_END_DECLS G_END_DECLS

View File

@ -21,84 +21,47 @@
#include "gtkstyleanimationprivate.h" #include "gtkstyleanimationprivate.h"
G_DEFINE_ABSTRACT_TYPE (GtkStyleAnimation, _gtk_style_animation, G_TYPE_OBJECT)
static GtkStyleAnimation *
gtk_style_animation_real_advance (GtkStyleAnimation *animation,
gint64 timestamp)
{
return NULL;
}
static void
gtk_style_animation_real_apply_values (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style)
{
}
static gboolean
gtk_style_animation_real_is_finished (GtkStyleAnimation *animation)
{
return TRUE;
}
static gboolean
gtk_style_animation_real_is_static (GtkStyleAnimation *animation)
{
return FALSE;
}
static void
_gtk_style_animation_class_init (GtkStyleAnimationClass *klass)
{
klass->advance = gtk_style_animation_real_advance;
klass->apply_values = gtk_style_animation_real_apply_values;
klass->is_finished = gtk_style_animation_real_is_finished;
klass->is_static = gtk_style_animation_real_is_static;
}
static void
_gtk_style_animation_init (GtkStyleAnimation *animation)
{
}
GtkStyleAnimation * GtkStyleAnimation *
_gtk_style_animation_advance (GtkStyleAnimation *animation, _gtk_style_animation_advance (GtkStyleAnimation *animation,
gint64 timestamp) gint64 timestamp)
{ {
GtkStyleAnimationClass *klass; g_assert (animation != NULL);
g_return_val_if_fail (GTK_IS_STYLE_ANIMATION (animation), NULL); return animation->class->advance (animation, timestamp);
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->advance (animation, timestamp);
} }
void void
_gtk_style_animation_apply_values (GtkStyleAnimation *animation, _gtk_style_animation_apply_values (GtkStyleAnimation *animation,
GtkCssAnimatedStyle *style) GtkCssAnimatedStyle *style)
{ {
GtkStyleAnimationClass *klass; animation->class->apply_values (animation, style);
g_return_if_fail (GTK_IS_STYLE_ANIMATION (animation));
g_return_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style));
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
klass->apply_values (animation, style);
} }
gboolean gboolean
_gtk_style_animation_is_finished (GtkStyleAnimation *animation) _gtk_style_animation_is_finished (GtkStyleAnimation *animation)
{ {
GtkStyleAnimationClass *klass; return animation->class->is_finished (animation);
}
g_return_val_if_fail (GTK_IS_STYLE_ANIMATION (animation), TRUE);
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation); GtkStyleAnimation *
gtk_style_animation_ref (GtkStyleAnimation *animation)
{
animation->ref_count++;
return animation;
}
return klass->is_finished (animation); GtkStyleAnimation *
gtk_style_animation_unref (GtkStyleAnimation *animation)
{
animation->ref_count--;
if (animation->ref_count == 0)
{
animation->class->free (animation);
return NULL;
}
return animation;
} }
/** /**
@ -115,9 +78,5 @@ _gtk_style_animation_is_finished (GtkStyleAnimation *animation)
gboolean gboolean
_gtk_style_animation_is_static (GtkStyleAnimation *animation) _gtk_style_animation_is_static (GtkStyleAnimation *animation)
{ {
GtkStyleAnimationClass *klass; return animation->class->is_static (animation);
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->is_static (animation);
} }

View File

@ -24,25 +24,19 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GTK_TYPE_STYLE_ANIMATION (_gtk_style_animation_get_type ())
#define GTK_STYLE_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_STYLE_ANIMATION, GtkStyleAnimation))
#define GTK_STYLE_ANIMATION_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_STYLE_ANIMATION, GtkStyleAnimationClass))
#define GTK_IS_STYLE_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_STYLE_ANIMATION))
#define GTK_IS_STYLE_ANIMATION_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_STYLE_ANIMATION))
#define GTK_STYLE_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STYLE_ANIMATION, GtkStyleAnimationClass))
typedef struct _GtkStyleAnimation GtkStyleAnimation; typedef struct _GtkStyleAnimation GtkStyleAnimation;
typedef struct _GtkStyleAnimationClass GtkStyleAnimationClass; typedef struct _GtkStyleAnimationClass GtkStyleAnimationClass;
struct _GtkStyleAnimation struct _GtkStyleAnimation
{ {
GObject parent; const GtkStyleAnimationClass *class;
guint ref_count;
}; };
struct _GtkStyleAnimationClass struct _GtkStyleAnimationClass
{ {
GObjectClass parent_class; const char *type_name;
void (* free) (GtkStyleAnimation *animation);
gboolean (* is_finished) (GtkStyleAnimation *animation); gboolean (* is_finished) (GtkStyleAnimation *animation);
gboolean (* is_static) (GtkStyleAnimation *animation); gboolean (* is_static) (GtkStyleAnimation *animation);
void (* apply_values) (GtkStyleAnimation *animation, void (* apply_values) (GtkStyleAnimation *animation,
@ -60,6 +54,9 @@ void _gtk_style_animation_apply_values (GtkStyleAnimation
gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation); gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation);
gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation); gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation);
GtkStyleAnimation * gtk_style_animation_ref (GtkStyleAnimation *animation);
GtkStyleAnimation * gtk_style_animation_unref (GtkStyleAnimation *animation);
G_END_DECLS G_END_DECLS