Compare commits

...

4 Commits

Author SHA1 Message Date
Emmanuele Bassi e59f2cafe4 future: Fix version boundaries for comparison 2012-06-04 22:26:45 +01:00
Emmanuele Bassi a5210c45dd future: Allow enabling future features
Before calling clutter_init(), given that future features may change the
way Clutter is initialized.
2012-06-04 22:25:16 +01:00
Emmanuele Bassi 0714a4b503 Add future feature support
Python has an interesting concept: a __future__ module that defines
optional language features that are going to be mandatory, or dropped,
after a certain version is released. These features can be enabled by
the adventurous developers.

A similar mechanism for altering the default behaviour of Clutter would
complement nicely the deprecation mechanisms we have already in place.
2012-06-04 22:25:16 +01:00
Emmanuele Bassi c4a42671b3 actor: Do not transition unmapped actors
If an actor is not mapped then we can immediately set the final value of
the transition.

This avoids queuing up a bunch of transitions when building the scene,
just to have them start when we reach clutter_main() and start the main
loop.
2012-06-04 22:24:38 +01:00
10 changed files with 213 additions and 9 deletions

View File

@ -163,6 +163,7 @@ source_c = \
$(srcdir)/clutter-fixed-layout.c \
$(srcdir)/clutter-flatten-effect.c \
$(srcdir)/clutter-flow-layout.c \
$(srcdir)/clutter-future.c \
$(srcdir)/clutter-gesture-action.c \
$(srcdir)/clutter-image.c \
$(srcdir)/clutter-input-device.c \
@ -220,6 +221,7 @@ source_h_priv = \
$(srcdir)/clutter-event-translator.h \
$(srcdir)/clutter-event-private.h \
$(srcdir)/clutter-flatten-effect.h \
$(srcdir)/clutter-future-private.h \
$(srcdir)/clutter-id-pool.h \
$(srcdir)/clutter-master-clock.h \
$(srcdir)/clutter-model-private.h \

View File

@ -5270,6 +5270,9 @@ clutter_actor_finalize (GObject *object)
priv->id,
g_type_name (G_OBJECT_TYPE (object)));
if (clutter_future_is_enabled (CLUTTER_FUTURE_DEFAULT_EASING_STATE))
clutter_actor_restore_easing_state (CLUTTER_ACTOR (object));
_clutter_context_release_id (priv->id);
g_free (priv->name);
@ -7379,6 +7382,9 @@ clutter_actor_init (ClutterActor *self)
* when building up a scene.
*/
priv->needs_compute_expand = FALSE;
if (clutter_future_is_enabled (CLUTTER_FUTURE_DEFAULT_EASING_STATE))
clutter_actor_save_easing_state (self);
}
/**
@ -17472,8 +17478,12 @@ _clutter_actor_create_transition (ClutterActor *actor,
* directly on the actor; we don't go through the Animatable
* interface because we know we got here through an animatable
* property.
*
* this also applies to unmapped actors, so that we don't transition
* actors as soon as the main loop starts
*/
if (info->cur_state->easing_duration == 0)
if (info->cur_state->easing_duration == 0 ||
!CLUTTER_ACTOR_IS_MAPPED (actor))
{
clutter_actor_set_animatable_property (actor,
pspec->param_id,

View File

@ -1237,6 +1237,27 @@ typedef enum { /*< prefix=CLUTTER_SCROLL >*/
CLUTTER_SCROLL_BOTH = CLUTTER_SCROLL_HORIZONTALLY | CLUTTER_SCROLL_VERTICALLY
} ClutterScrollMode;
/**
* ClutterFutureFeature:
* @CLUTTER_FUTURE_DEFAULT_EASING_STATE: Enables a default easing state
* on #ClutterActor. Optional since 1.12, mandatory since 2.0
* @CLUTTER_FUTURE_N_FEATURES: The number of available future features
*
* A set of future features that can be enabled when using Clutter.
*
* Each future feature has a defined optional version, which defines the
* version of Clutter that introduced the feature, and a mandatory version,
* which defines the version of Clutter that makes the feature part of
* the standard behaviour.
*
* Since: 1.12
*/
typedef enum { /*< prefix=CLUTTER_FEATURE >*/
CLUTTER_FUTURE_DEFAULT_EASING_STATE,
CLUTTER_FUTURE_N_FEATURES
} ClutterFutureFeature;
G_END_DECLS
#endif /* __CLUTTER_ENUMS_H__ */

View File

@ -0,0 +1,60 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2012 Intel Corp.
*
* 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/>.
*/
#ifndef __CLUTTER_FUTURE_PRIVATE_H__
#define __CLUTTER_FUTURE_PRIVATE_H__
#include <clutter/clutter-types.h>
G_BEGIN_DECLS
typedef struct _ClutterFuture ClutterFuture;
struct _ClutterFuture
{
/* symbolic name of the feature, for debugging purposes */
const char *name;
/* Clutter versions encoded using CLUTTER_ENCODE_VERSION */
guint optional_version;
guint mandatory_version;
guint is_enabled : 1;
};
G_GNUC_INTERNAL
const char * clutter_future_get_name (ClutterFutureFeature feature);
G_GNUC_INTERNAL
guint clutter_future_get_optional_version (ClutterFutureFeature feature);
G_GNUC_INTERNAL
guint clutter_future_get_mandatory_version (ClutterFutureFeature feature);
G_GNUC_INTERNAL
gboolean clutter_future_is_enabled (ClutterFutureFeature feature);
G_GNUC_INTERNAL
void clutter_future_enable (ClutterFutureFeature feature);
G_END_DECLS
#endif /* __CLUTTER_FUTURE_PRIVATE_H__ */

68
clutter/clutter-future.c Normal file
View File

@ -0,0 +1,68 @@
#include "config.h"
#include "clutter-future-private.h"
#define CLUTTER_DEFINE_FUTURE(_Name,_Optional,_Mandatory) \
{ \
_Name, \
_Optional, \
_Mandatory, \
}
static const ClutterFuture __clutter_futures[CLUTTER_FUTURE_N_FEATURES] = {
CLUTTER_DEFINE_FUTURE ("default-easing-state",
G_ENCODE_VERSION (1, 11),
G_ENCODE_VERSION (2, 0)),
};
static gboolean __clutter_enabled_futures[CLUTTER_FUTURE_N_FEATURES] = { FALSE, };
const char *
clutter_future_get_name (ClutterFutureFeature feature)
{
g_assert (feature < CLUTTER_FUTURE_N_FEATURES);
return __clutter_futures[feature].name;
}
guint
clutter_future_get_optional_version (ClutterFutureFeature feature)
{
g_assert (feature < CLUTTER_FUTURE_N_FEATURES);
return __clutter_futures[feature].optional_version;
}
guint
clutter_future_get_mandatory_version (ClutterFutureFeature feature)
{
g_assert (feature < CLUTTER_FUTURE_N_FEATURES);
return __clutter_futures[feature].mandatory_version;
}
gboolean
clutter_future_is_enabled (ClutterFutureFeature feature)
{
guint version;
g_assert (feature < CLUTTER_FUTURE_N_FEATURES);
version = G_ENCODE_VERSION (CLUTTER_MAJOR_VERSION, CLUTTER_MINOR_VERSION);
if (__clutter_futures[feature].optional_version > version)
return FALSE;
if (__clutter_futures[feature].mandatory_version <= version)
return TRUE;
return __clutter_enabled_futures[feature];
}
void
clutter_future_enable (ClutterFutureFeature feature)
{
g_assert (feature < CLUTTER_FUTURE_N_FEATURES);
__clutter_enabled_futures[feature] = TRUE;
}

View File

@ -105,6 +105,7 @@
#include "clutter-event-private.h"
#include "clutter-feature.h"
#include "clutter-frame-source.h"
#include "clutter-future-private.h"
#include "clutter-main.h"
#include "clutter-master-clock.h"
#include "clutter-private.h"
@ -3873,3 +3874,39 @@ _clutter_diagnostic_message (const char *format, ...)
g_free (fmt);
}
/**
* clutter_enable_future:
* @feature: a future feature to enable
*
* Enables @feature from the list of available future features of
* Clutter.
*
* Future features are optional features that can modify the behaviour
* of Clutter; each future feature has an optional version, which identifies
* the version of Clutter that introduced it, and a mandatory version, which
* identifies the version of Clutter in which the feature became part of the
* default behaviour.
*
* This function can only be called prior to the initialization of Clutter.
*
* Since: 1.12
*/
void
clutter_enable_future (ClutterFutureFeature feature)
{
g_return_if_fail (feature < CLUTTER_FUTURE_N_FEATURES);
if (_clutter_context_is_initialized ())
{
g_warning ("Calling clutter_enable_future() is only allowed before "
"Clutter has been initialized.");
return;
}
CLUTTER_NOTE (MISC, "Enabling feature '%s' [%d]",
clutter_future_get_name (feature),
feature);
clutter_future_enable (feature);
}

View File

@ -90,6 +90,9 @@ ClutterInitError clutter_init_with_args (int *a
GOptionGroup * clutter_get_option_group (void);
GOptionGroup * clutter_get_option_group_without_init (void);
/* Future support */
void clutter_enable_future (ClutterFutureFeature feature);
/* Mainloop */
void clutter_main (void);
void clutter_main_quit (void);

View File

@ -36,6 +36,7 @@
#include "clutter-effect.h"
#include "clutter-event.h"
#include "clutter-feature.h"
#include "clutter-future-private.h"
#include "clutter-id-pool.h"
#include "clutter-layout-manager.h"
#include "clutter-master-clock.h"

View File

@ -622,6 +622,7 @@ clutter_drop_action_get_type
clutter_drop_action_new
clutter_effect_get_type
clutter_effect_paint_flags_get_type
clutter_enable_future
clutter_effect_queue_repaint
clutter_events_pending
clutter_event_copy
@ -698,6 +699,7 @@ clutter_fog_get_type
clutter_font_flags_get_type
clutter_frame_source_add
clutter_frame_source_add_full
clutter_future_feature_get_type
#ifdef CLUTTER_WINDOWING_GDK
clutter_gdk_disable_event_retrieval
clutter_gdk_get_default_display

View File

@ -77,7 +77,11 @@ on_button_press (ClutterActor *actor,
}
else if (event->button == CLUTTER_BUTTON_MIDDLE)
{
/* middle click jumps to position */
clutter_actor_save_easing_state (rectangle);
clutter_actor_set_easing_duration (rectangle, 0);
clutter_actor_set_position (rectangle, event->x, event->y);
clutter_actor_restore_easing_state (rectangle);
}
else if (event->button == CLUTTER_BUTTON_PRIMARY)
{
@ -85,15 +89,8 @@ on_button_press (ClutterActor *actor,
cur_mode = easing_modes[current_mode].mode;
clutter_actor_save_easing_state (rectangle);
/* tween the actor using the current easing mode */
clutter_actor_set_easing_mode (rectangle, cur_mode);
clutter_actor_set_easing_duration (rectangle, duration * 1000);
clutter_actor_set_position (rectangle, event->x, event->y);
clutter_actor_restore_easing_state (rectangle);
}
return CLUTTER_EVENT_STOP;
@ -187,6 +184,8 @@ main (int argc, char *argv[])
gfloat stage_width, stage_height;
GError *error = NULL;
clutter_enable_future (CLUTTER_FUTURE_DEFAULT_EASING_STATE);
if (clutter_init_with_args (&argc, &argv,
NULL,
test_easing_entries,
@ -204,8 +203,8 @@ main (int argc, char *argv[])
/* create the actor that we want to tween */
rect = make_bouncer (50, 50);
clutter_actor_add_child (stage, rect);
clutter_actor_set_position (rect, stage_width / 2, stage_height / 2);
clutter_actor_add_child (stage, rect);
text = g_strdup_printf (HELP_TEXT,
easing_modes[current_mode].name,
@ -218,6 +217,7 @@ main (int argc, char *argv[])
clutter_text_set_line_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_RIGHT);
clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.95));
clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.95));
clutter_actor_add_child (stage, label);
easing_mode_label = label;
g_free (text);