A ProperyAnimation animates the value of a "property" of a "subject" over time.
Currently there is only one specific type of property animation offered off-the-shelf, namely one to change the frame (property) of a layer (subject), see property_animation_create_layer_frame().
It is fairly simple to create your own variant of a PropertyAnimation.
Please refer to User Interface Layers chapter in the Pebble Developer Guides (chapter "Property Animations") for a conceptual overview of the animation framework and make sure you understand the underlying Animation, in case you are not familiar with it, before trying to implement a variation on PropertyAnimation.
To implement a custom property animation, use property_animation_create() and provide a function pointers to the accessors (getter and setter) and setup, update and teardown callbacks in the implementation argument. Note that the type of property to animate with PropertyAnimation is limited to int16_t, GPoint or GRect.
For each of these types, there are implementations provided for the necessary .update
handler of the animation: see property_animation_update_int16(), property_animation_update_gpoint() and property_animation_update_grect(). These update functions expect the .accessors
to conform to the following interface: Any getter needs to have the following function signature: __type__ getter(void *subject);
Any setter needs to have to following function signature: void setter(void *subject, __type__ value);
See Int16Getter, Int16Setter, GPointGetter, GPointSetter, GRectGetter, GRectSetter for the typedefs that accompany the update fuctions.
static const PropertyAnimationImplementation my_implementation = {
.base = {
// using the "stock" update callback:
.update = (AnimationUpdateImplementation) property_animation_update_gpoint,
},
.accessors = {
// my accessors that get/set a GPoint from/onto my subject:
.setter = { .gpoint = my_layer_set_corner_point, },
.getter = { .gpoint = (const GPointGetter) my_layer_get_corner_point, },
},
};
static PropertyAnimation* s_my_animation_ptr = NULL;
static GPoint s_to_point = GPointZero;
...
// Use NULL as 'from' value, this will make the animation framework call the getter
// to get the current value of the property and use that as the 'from' value:
s_my_animation_ptr = property_animation_create(&my_implementation, my_layer, NULL, &s_to_point);
animation_schedule(property_animation_get_animation(s_my_animation_ptr));
Convenience function to create and initialize a property animation that animates the frame of a Layer. It sets up the PropertyAnimation to use layer_set_frame() and layer_get_frame() as accessors and uses the layer
parameter as the subject for the animation. The same defaults are used as with animation_create().
Pass in NULL
as one of the frame arguments to have it set automatically to the layer's current frame. This will result in a call to layer_get_frame() to get the current frame of the layer.
the layer that will be animated
the frame that the layer should animate from
the frame that the layer should animate to
A handle to the property animation. NULL
if animation could not be created
Convenience function to create and initialize a property animation that animates the bound's origin of a Layer. It sets up the PropertyAnimation to use layer_set_bounds() and layer_get_bounds() as accessors and uses the layer
parameter as the subject for the animation. The same defaults are used as with animation_create().
the layer that will be animated
the origin that the bounds should animate from
the origin that the layer should animate to
A handle to the property animation. NULL
if animation could not be created
Creates a new PropertyAnimation on the heap and and initializes it with the specified values. The same defaults are used as with animation_create(). If the from_value
or the to_value
is NULL
, the getter accessor will be called to get the current value of the property and be used instead.
Pass in NULL
as one of the value arguments to have it set automatically to the subject's current property value, as returned by the getter function. Also note that passing in NULL
for both from_value
and to_value
, will result in the animation having the same from- and to- values, effectively not doing anything.
Pointer to the implementation of the animation. In most cases, it makes sense to pass in a static const
struct pointer.
Pointer to the "subject" being animated. This will be passed in when the getter/ setter accessors are called, see PropertyAnimationAccessors, GPointSetter, and friends. The value of this pointer will be copied into the .subject
field of the PropertyAnimation struct.
Pointer to the value that the subject should animate from
Pointer to the value that the subject should animate to
A handle to the property animation. NULL
if animation could not be created
Destroy a property animation allocated by property_animation_create() or relatives.
the return value from property_animation_create
Default update callback for a property animations to update a property of type int16_t. Assign this function to the .base.update
callback field of your PropertyAnimationImplementation, in combination with a .getter
and .setter
accessors of types Int16Getter and Int16Setter. The implementation of this function will calculate the next value of the animation and call the setter to set the new value upon the subject.
This function is not supposed to be called "manually", but will be called automatically when the animation is being run.
The property animation for which the update is requested.
The current normalized distance. See AnimationUpdateImplementation
Default update callback for a property animations to update a property of type uint32_t. Assign this function to the .base.update
callback field of your PropertyAnimationImplementation, in combination with a .getter
and .setter
accessors of types UInt32Getter and UInt32Setter. The implementation of this function will calculate the next value of the animation and call the setter to set the new value upon the subject.
This function is not supposed to be called "manually", but will be called automatically when the animation is being run.
The property animation for which the update is requested.
The current normalized distance. See AnimationUpdateImplementation
Default update callback for a property animations to update a property of type GPoint. Assign this function to the .base.update
callback field of your PropertyAnimationImplementation, in combination with a .getter
and .setter
accessors of types GPointGetter and GPointSetter. The implementation of this function will calculate the next point of the animation and call the setter to set the new point upon the subject.
This function is not supposed to be called "manually", but will be called automatically when the animation is being run.
The property animation for which the update is requested.
The current normalized distance. See AnimationUpdateImplementation
Default update callback for a property animations to update a property of type GRect. Assign this function to the .base.update
callback field of your PropertyAnimationImplementation, in combination with a .getter
and .setter
accessors of types GRectGetter and GRectSetter. The implementation of this function will calculate the next rectangle of the animation and call the setter to set the new rectangle upon the subject.
This function is not supposed to be called "manually", but will be called automatically when the animation is being run.
The property animation for which the update is requested.
The current normalized distance. See AnimationUpdateImplementation
Default update callback for a property animations to update a property of type GColor8. Assign this function to the .base.update
callback field of your PropertyAnimationImplementation, in combination with a .getter
and .setter
accessors of types GColor8Getter and GColor8Setter. The implementation of this function will calculate the next rectangle of the animation and call the setter to set the new value upon the subject.
This function is not supposed to be called "manually", but will be called automatically when the animation is being run.
The property animation for which the update is requested.
The current normalized distance. See AnimationUpdateImplementation
Convenience function to retrieve an animation instance from a property animation instance.
The property animation
The Animation within this PropertyAnimation
Helper function used by the property_animation_get|set_subject macros.
Handle to the property animation
The subject to get or set.
true to set new subject, false to retrieve existing value
true if successful, false on failure (usually a bad animation_h)
Helper function used by the property_animation_get|set_from_.* macros.
Handle to the property animation
Pointer to the value
Size of the from value
true to set new value, false to retrieve existing one
true if successful, false on failure (usually a bad animation_h)
Helper function used by the property_animation_get|set_to_.* macros.
handle to the property animation
Pointer to the value
Size of the to value
true to set new value, false to retrieve existing one
true if successful, false on failure (usually a bad animation_h)
Data structure containing the setter and getter function pointers that the property animation should use. The specified setter function will be used by the animation's update callback.
Based on the type of the property (int16_t, GPoint or GRect), the accompanying update callback should be used, see property_animation_update_int16(), property_animation_update_gpoint() and property_animation_update_grect().
The getter function is used when the animation is initialized, to assign the current value of the subject's property as "from" or "to" value, see property_animation_create().
Function pointer to the implementation of the function that sets the updated property value. This function will be called repeatedly for each animation frame.
Function pointer to the implementation of the function that gets the current property value. This function will be called during property_animation_create(), to get the current property value, in case the from_value
or to_value
argument is NULL
.
Data structure containing a collection of function pointers that form the implementation of the property animation. See the code example at the top (PropertyAnimation).
The "inherited" fields from the Animation "base class".
The accessors to set/get the property to be animated.
Function signature of a setter function to set a property of type int16_t onto the subject.
Function signature of a getter function to get the current property of type int16_t of the subject.
Function signature of a setter function to set a property of type uint32_t onto the subject.
Function signature of a getter function to get the current property of type uint32_t of the subject.
Function signature of a setter function to set a property of type GPoint onto the subject.
Function signature of a getter function to get the current property of type GPoint of the subject.
Function signature of a setter function to set a property of type GRect onto the subject.
Function signature of a getter function to get the current property of type GRect of the subject.
Function signature of a setter function to set a property of type GColor8 onto the subject.
Function signature of a getter function to get the current property of type GColor8 of the subject.
Convenience function to clone a property animation instance.
The property animation
A clone of the original Animation
Convenience function to retrieve the 'from' GRect value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'from' GRect value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Convenience function to retrieve the 'from' GPoint value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'from' GPoint value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Convenience function to retrieve the 'from' int16_t value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'from' int16_t value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Convenience function to retrieve the 'to' GRect value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'to' GRect value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Convenience function to retrieve the 'to' GPoint value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'to' GPoint value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Convenience function to retrieve the 'to' int16_t value from property animation handle.
The PropertyAnimation to be accessed
The value will be retrieved into this pointer
true on success, false on failure
Convenience function to set the 'to' int16_t value of property animation handle.
The PropertyAnimation to be accessed
Pointer to the new value
true on success, false on failure
Retrieve the subject of a property animation.
The PropertyAnimation to be accessed
Pointer used to store the subject of this property animation
The subject of this PropertyAnimation
Set the subject of a property animation.
The PropertyAnimation to be accessed
Pointer to the new subject value
Do you have questions about the Pebble SDK?
Do you need some help understanding something on this page?
You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!