Commit 68bfb94f authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Change semantics of the methods to check whether an animation is running.

It actually messed up with the state being actually set, and having a
transition animation running for it. Now this dichotomy is removed, and
gtk_style_context_state_is_running() only checks whether an animation is
running, leaving state checking to flags & GTK_STATE_FLAG_*.
parent 96c16e24
......@@ -5382,7 +5382,7 @@ gtk_style_context_get_valist
gtk_style_context_has_class
gtk_style_context_has_region
gtk_style_context_invalidate
gtk_style_context_is_state_set
gtk_style_context_state_is_running
gtk_style_context_list_classes
gtk_style_context_list_regions
gtk_style_context_lookup_color
......@@ -5474,7 +5474,7 @@ gtk_theming_engine_get_style_valist
gtk_theming_engine_get_valist
gtk_theming_engine_has_class
gtk_theming_engine_has_region
gtk_theming_engine_is_state_set
gtk_theming_engine_state_is_running
gtk_theming_engine_load
gtk_theming_engine_register_property
<SUBSECTION Standard>
......
......@@ -1304,66 +1304,53 @@ context_has_animatable_region (GtkStyleContext *context,
return FALSE;
}
/**
* gtk_style_context_state_is_running:
* @context: a #GtkStyleContext
* @state: a widget state
* @progress: (out): return location for the transition progress
*
* Returns %TRUE if there is a transition animation running for the
* current region (see gtk_style_context_push_animatable_region()).
*
* If @progress is not %NULL, the animation progress will be returned
* there, 0.0 means the state is closest to being %FALSE, while 1.0 means
* it's closest to being %TRUE. This means transition animations will
* run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
* it's being set to %FALSE.
*
* Returns: %TRUE if there is a running transition animation for @state.
*
* Since: 3.0
**/
gboolean
gtk_style_context_is_state_set (GtkStyleContext *context,
GtkStateType state,
gdouble *progress)
gtk_style_context_state_is_running (GtkStyleContext *context,
GtkStateType state,
gdouble *progress)
{
GtkStyleContextPrivate *priv;
gboolean state_set;
AnimationInfo *info;
GSList *l;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
priv = context->priv;
switch (state)
{
case GTK_STATE_NORMAL:
state_set = (priv->state_flags == 0);
break;
case GTK_STATE_ACTIVE:
state_set = (priv->state_flags & GTK_STATE_FLAG_ACTIVE);
break;
case GTK_STATE_PRELIGHT:
state_set = (priv->state_flags & GTK_STATE_FLAG_PRELIGHT);
break;
case GTK_STATE_SELECTED:
state_set = (priv->state_flags & GTK_STATE_FLAG_SELECTED);
break;
case GTK_STATE_INSENSITIVE:
state_set = (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
break;
case GTK_STATE_INCONSISTENT:
state_set = (priv->state_flags & GTK_STATE_FLAG_INCONSISTENT);
break;
case GTK_STATE_FOCUSED:
state_set = (priv->state_flags & GTK_STATE_FLAG_FOCUSED);
break;
default:
g_assert_not_reached ();
}
if (progress)
for (l = priv->animations; l; l = l->next)
{
AnimationInfo *info;
GSList *l;
*progress = (state_set) ? 1 : 0;
info = l->data;
for (l = priv->animations; l; l = l->next)
if (info->state == state &&
context_has_animatable_region (context, info->region_id))
{
info = l->data;
if (info->state == state &&
context_has_animatable_region (context, info->region_id))
{
*progress = gtk_timeline_get_progress (info->timeline);
break;
}
if (progress)
*progress = gtk_timeline_get_progress (info->timeline);
return TRUE;
}
}
return state_set;
return FALSE;
}
/**
......
......@@ -82,9 +82,9 @@ void gtk_style_context_set_state (GtkStyleContext *context,
GtkStateFlags flags);
GtkStateFlags gtk_style_context_get_state (GtkStyleContext *context);
gboolean gtk_style_context_is_state_set (GtkStyleContext *context,
GtkStateType state,
gdouble *progress);
gboolean gtk_style_context_state_is_running (GtkStyleContext *context,
GtkStateType state,
gdouble *progress);
void gtk_style_context_set_path (GtkStyleContext *context,
GtkWidgetPath *path);
......@@ -146,6 +146,8 @@ void gtk_style_context_push_animatable_region (GtkStyleContext *context,
gpointer region_id);
void gtk_style_context_pop_animatable_region (GtkStyleContext *context);
void gtk_style_context_invalidate (GtkStyleContext *context);
void gtk_style_context_reset_widgets (GdkScreen *screen);
/* Semi-private API */
const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
......@@ -156,23 +158,6 @@ void _gtk_style_context_coalesce_animation_areas (GtkStyleContext *c
gint rel_x,
gint rel_y);
/* Animation for state changes */
void gtk_style_context_state_transition_start (GtkStyleContext *context,
gpointer identifier,
GtkWidget *widget,
GtkStateType state,
gboolean value,
GdkRectangle *rect);
void gtk_style_context_state_transition_update (GtkStyleContext *context,
gpointer identifier,
GdkRectangle *rect,
GtkStateType state);
void gtk_style_context_state_transition_stop (GtkStyleContext *context,
gpointer identifier);
void gtk_style_context_invalidate (GtkStyleContext *context);
void gtk_style_context_reset_widgets (GdkScreen *screen);
/* Paint methods */
void gtk_render_check (GtkStyleContext *context,
cairo_t *cr,
......
......@@ -445,17 +445,36 @@ gtk_theming_engine_get_state (GtkThemingEngine *engine)
return gtk_style_context_get_state (priv->context);
}
/**
* gtk_theming_engine_state_is_running:
* @engine: a #GtkThemingEngine
* @state: a widget state
* @progress: (out): return location for the transition progress
*
* Returns %TRUE if there is a transition animation running for the
* current region (see gtk_style_context_push_animatable_region()).
*
* If @progress is not %NULL, the animation progress will be returned
* there, 0.0 means the state is closest to being %FALSE, while 1.0 means
* it's closest to being %TRUE. This means transition animations will
* run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
* it's being set to %FALSE.
*
* Returns: %TRUE if there is a running transition animation for @state.
*
* Since: 3.0
**/
gboolean
gtk_theming_engine_is_state_set (GtkThemingEngine *engine,
GtkStateType state,
gdouble *progress)
gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
GtkStateType state,
gdouble *progress)
{
GtkThemingEnginePrivate *priv;
g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
priv = engine->priv;
return gtk_style_context_is_state_set (priv->context, state, progress);
return gtk_style_context_state_is_running (priv->context, state, progress);
}
/**
......@@ -766,7 +785,7 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
else
gdk_cairo_set_source_color (cr, text_color);
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_INCONSISTENT, NULL))
if (flags & GTK_STATE_FLAG_INCONSISTENT)
{
int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
......@@ -780,12 +799,15 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
else
{
gdouble progress;
gboolean active;
gboolean running;
active = gtk_theming_engine_is_state_set (engine, GTK_STATE_ACTIVE, &progress);
running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
if (active || progress > 0)
if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
{
if (!running)
progress = 1;
cairo_translate (cr,
x + pad, y + pad);
......@@ -887,7 +909,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
/* FIXME: thickness */
thickness = 1;
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_INCONSISTENT, NULL))
if (flags & GTK_STATE_FLAG_INCONSISTENT)
{
gint line_thickness;
......@@ -909,7 +931,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
line_thickness);
cairo_fill (cr);
}
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_ACTIVE, NULL))
if (flags & GTK_STATE_FLAG_ACTIVE)
{
pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
interior_size = MAX (1, exterior_size - 2 * pad);
......@@ -1100,7 +1122,7 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
GdkColor *bg_color, *base_color;
cairo_pattern_t *pattern;
GtkStateFlags flags;
gboolean prelight;
gboolean running;
gdouble progress, alpha = 1;
flags = gtk_theming_engine_get_state (engine);
......@@ -1121,19 +1143,19 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
"base-color", &base_color,
NULL);
prelight = gtk_theming_engine_is_state_set (engine, GTK_STATE_PRELIGHT, &progress);
running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
cairo_translate (cr, x, y);
cairo_scale (cr, width, height);
if (prelight || progress > 0 )
if (running)
{
cairo_pattern_t *other_pattern;
GtkStateFlags other_flags;
GdkColor *other_bg, *other_base;
cairo_pattern_t *new_pattern = NULL;
if (prelight)
if (flags & GTK_STATE_FLAG_PRELIGHT)
{
other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
progress = 1 - progress;
......@@ -1833,7 +1855,7 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
else
cairo_translate (cr, x, y);
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_INSENSITIVE, NULL))
if (flags & GTK_STATE_FLAG_INSENSITIVE)
{
cairo_save (cr);
cairo_set_source_rgb (cr, 1, 1, 1);
......
......@@ -192,10 +192,10 @@ gboolean gtk_theming_engine_has_region (GtkThemingEngine *engine,
const gchar *style_class,
GtkRegionFlags *flags);
GtkStateFlags gtk_theming_engine_get_state (GtkThemingEngine *engine);
gboolean gtk_theming_engine_is_state_set (GtkThemingEngine *engine,
GtkStateType state,
gdouble *progress);
GtkStateFlags gtk_theming_engine_get_state (GtkThemingEngine *engine);
gboolean gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
GtkStateType state,
gdouble *progress);
GtkTextDirection gtk_theming_engine_get_direction (GtkThemingEngine *engine);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment