SkAnimator Class Reference
#include <SkAnimator.h>
Inherits SkEventSink.
List of all members.
Classes |
class | Timeline |
Public Types |
enum | DifferenceType { kNotDifferent,
kDifferent,
kPartiallyDifferent
} |
typedef void * | Handler |
Public Member Functions |
| SkAnimator () |
virtual | ~SkAnimator () |
void | addExtras (SkExtras *extras) |
bool | appendStream (SkStream *stream) |
bool | decodeMemory (const void *buffer, size_t size) |
virtual bool | decodeStream (SkStream *stream) |
virtual bool | decodeDOM (const SkDOM &, const SkDOMNode *) |
bool | decodeURI (const char uri[]) |
bool | doCharEvent (SkUnichar ch) |
bool | doClickEvent (int state, SkScalar x, SkScalar y) |
bool | doKeyEvent (SkKey code) |
bool | doKeyUpEvent (SkKey code) |
bool | doUserEvent (const SkEvent &evt) |
DifferenceType | draw (SkCanvas *canvas, SkPaint *paint, SkMSec time) |
DifferenceType | draw (SkCanvas *canvas, SkMSec time) |
bool | findClickEvent (SkScalar x, SkScalar y) |
const SkAnimator * | getAnimator (const SkDisplayable *element) const |
int32_t | getArrayInt (const SkDisplayable *element, const SkMemberInfo *field, int index) |
int32_t | getArrayInt (const char *elementID, const char *fieldName, int index) |
SkScalar | getArrayScalar (const SkDisplayable *element, const SkMemberInfo *field, int index) |
SkScalar | getArrayScalar (const char *elementID, const char *fieldName, int index) |
const char * | getArrayString (const SkDisplayable *element, const SkMemberInfo *field, int index) |
const char * | getArrayString (const char *elementID, const char *fieldName, int index) |
const SkDisplayable * | getElement (const char *elementID) |
SkElementType | getElementType (const SkDisplayable *element) |
SkElementType | getElementType (const char *elementID) |
const SkMemberInfo * | getField (const SkDisplayable *element, const char *fieldName) |
const SkMemberInfo * | getField (const char *elementID, const char *fieldName) |
SkFieldType | getFieldType (const SkMemberInfo *field) |
SkFieldType | getFieldType (const char *elementID, const char *fieldName) |
SkMSec | getInterval () |
void | getInvalBounds (SkRect *inval) |
const SkXMLParserError * | getParserError () |
const char * | getParserErrorString () |
int32_t | getInt (const SkDisplayable *element, const SkMemberInfo *field) |
int32_t | getInt (const char *elementID, const char *fieldName) |
SkScalar | getScalar (const SkDisplayable *element, const SkMemberInfo *field) |
SkScalar | getScalar (const char *elementID, const char *fieldName) |
const char * | getString (const SkDisplayable *element, const SkMemberInfo *field) |
const char * | getString (const char *elementID, const char *fieldName) |
const char * | getURIBase () |
void | initialize () |
void | reset () |
bool | setArrayInt (const char *elementID, const char *fieldName, const int *array, int count) |
bool | setArrayString (const char *elementID, const char *fieldName, const char **array, int count) |
bool | setInt (const char *elementID, const char *fieldName, int32_t data) |
bool | setScalar (const char *elementID, const char *fieldName, SkScalar data) |
bool | setString (const char *elementID, const char *fieldName, const char *data) |
void | setURIBase (const char *path) |
void | setHostHandler (Handler handler) |
void | setTimeline (const Timeline &) |
void | setHostEventSinkID (SkEventSinkID hostID) |
SkEventSinkID | getHostEventSinkID () const |
void | setHostEventSink (SkEventSink *sink) |
virtual void | setJavaOwner (Handler owner) |
Static Public Member Functions |
static void | Init (bool runUnitTests) |
static void | Term () |
Protected Member Functions |
virtual void | onSetHostHandler (Handler handler) |
virtual void | onEventPost (SkEvent *, SkEventSinkID) |
virtual void | onEventPostTime (SkEvent *, SkEventSinkID, SkMSec time) |
Friends |
class | SkAnimateMaker |
class | SkAnimatorScript |
class | SkAnimatorScript2 |
class | SkApply |
class | SkDisplayMovie |
class | SkDisplayType |
class | SkPost |
class | SkXMLAnimatorWriter |
Detailed Description
The SkAnimator class decodes an XML stream into a display list. The display list can be drawn statically as a picture, or can drawn different elements at different times to form a moving animation.
SkAnimator does not read the system time on its own; it relies on the caller to pass the current time. The caller can pause, speed up, or reverse the animation by varying the time passed in.
The XML describing the display list must conform to the schema described by SkAnimateSchema.xsd.
The XML must contain an <event> element to draw. Usually, it contains an <event kind="onload"> block to add some drawing elements to the display list when the document is first decoded.
Here's an "Hello World" XML sample:
<screenplay> <event kind="onload"> <text text="Hello World" y="20"> </event> </screenplay>
To read and draw this sample:
choose one of these two SkAnimator animator; // declare an animator instance on the stack SkAnimator* animator = new SkAnimator() // or one could instantiate the class
choose one of these three animator.decodeMemory(buffer, size); // to read from RAM animator.decodeStream(stream); // to read from a user-defined stream (e.g., a zip file) animator.decodeURI(filename); // to read from a web location, or from a local text file
to draw to the current window: SkCanvas canvas(getBitmap()); // create a canvas animator.draw(canvas, &paint, 0); // draw the scene
Definition at line 89 of file SkAnimator.h.
Member Typedef Documentation
Member Enumeration Documentation
The possible results from the draw function.
- Enumerator:
kNotDifferent |
|
kDifferent |
|
kPartiallyDifferent |
|
Definition at line 176 of file SkAnimator.h.
Constructor & Destructor Documentation
SkAnimator::SkAnimator |
( |
|
) |
|
virtual SkAnimator::~SkAnimator |
( |
|
) |
[virtual] |
Member Function Documentation
void SkAnimator::addExtras |
( |
SkExtras * |
extras |
) |
|
Add a drawable extension to the graphics engine. Experimental.
- Parameters:
-
| extras | A derived class that implements methods that identify and instantiate the class |
bool SkAnimator::appendStream |
( |
SkStream * |
stream |
) |
|
Read in XML from a stream, and append it to the current animator. Returns false if an error was encountered. Error diagnostics are stored in fErrorCode and fLineNumber.
- Parameters:
-
| stream | The stream to append. |
- Returns:
- true if the XML was parsed successfully.
virtual bool SkAnimator::decodeDOM |
( |
const SkDOM & |
, |
|
|
const SkDOMNode * |
| |
|
) |
| | [virtual] |
Parse the DOM tree starting at the specified node. Returns true if it can be parsed without error. Returns false if an error was encountered. Error diagnostics are stored in fErrorCode and fLineNumber.
- Returns:
- true if the DOM was parsed successfully.
bool SkAnimator::decodeMemory |
( |
const void * |
buffer, |
|
|
size_t |
size | |
|
) |
| | |
Read in XML from memory. Returns true if the file can be read without error. Returns false if an error was encountered. Error diagnostics are stored in fErrorCode and fLineNumber.
- Parameters:
-
| buffer | The XML text as UTF-8 characters. |
| size | The XML text length in bytes. |
- Returns:
- true if the XML was parsed successfully.
virtual bool SkAnimator::decodeStream |
( |
SkStream * |
stream |
) |
[virtual] |
Read in XML from a stream. Returns true if the file can be read without error. Returns false if an error was encountered. Error diagnostics are stored in fErrorCode and fLineNumber.
- Parameters:
-
| stream | The stream containg the XML text as UTF-8 characters. |
- Returns:
- true if the XML was parsed successfully.
bool SkAnimator::decodeURI |
( |
const char |
uri[] |
) |
|
Read in XML from a URI. Returns true if the file can be read without error. Returns false if an error was encountered. Error diagnostics are stored in fErrorCode and fLineNumber.
- Parameters:
-
| uri | The complete url path to be read (either ftp, http or https). |
- Returns:
- true if the XML was parsed successfully.
bool SkAnimator::doCharEvent |
( |
SkUnichar |
ch |
) |
|
Pass a char event, usually a keyboard symbol, to the animator. This triggers events of the form <event kind="keyChar" key="... />
@param ch The character to match against <event> element "key attributes.
- Returns:
- true if the event was dispatched successfully.
Experimental: Pass a mouse click event along with the mouse coordinates to the animator. This triggers events of the form <event kind="mouseDown" ... /> and other mouse events.
- Parameters:
-
| state | The mouse state, described by SkView::Click::State : values are down == 0, moved == 1, up == 2 |
| x | The x-position of the mouse |
| y | The y-position of the mouse |
- Returns:
- true if the event was dispatched successfully.
bool SkAnimator::doKeyEvent |
( |
SkKey |
code |
) |
|
Pass a meta-key event, such as an arrow , to the animator. This triggers events of the form <event kind="keyPress" code="... />
@param code The key to match against <event> element "code attributes.
- Returns:
- true if the event was dispatched successfully.
bool SkAnimator::doKeyUpEvent |
( |
SkKey |
code |
) |
|
bool SkAnimator::doUserEvent |
( |
const SkEvent & |
evt |
) |
|
Send an event to the animator. The animator's clock is set relative to the current time.
- Returns:
- true if the event was dispatched successfully.
Draws one frame of the animation, using a new Paint each time. The first call to draw always draws the initial frame of the animation. Subsequent calls draw the offset into the animation by subtracting the initial time from the current time.
- Parameters:
-
| canvas | The canvas to draw into. |
| time | The offset into the current animation. |
- Returns:
- kNotDifferent if there are no active animations; kDifferent if there are active animations; and kPartiallyDifferent if the document contains an active <bounds> element that specifies a minimal redraw area.
Draws one frame of the animation. The first call to draw always draws the initial frame of the animation. Subsequent calls draw the offset into the animation by subtracting the initial time from the current time.
- Parameters:
-
| canvas | The canvas to draw into. |
| paint | The paint to draw with. |
| time | The offset into the current animation. |
- Returns:
- kNotDifferent if there are no active animations; kDifferent if there are active animations; and kPartiallyDifferent if the document contains an active <bounds> element that specifies a minimal redraw area.
Experimental: Helper to choose whether to return a SkView::Click handler.
- Parameters:
-
- Returns:
- true if a mouseDown event handler is enabled.
const SkAnimator* SkAnimator::getAnimator |
( |
const SkDisplayable * |
element |
) |
const |
Get the nested animator associated with this element, if any. Use this to access a movie's event sink, to send events to movies.
- Parameters:
-
| element | the value returned by getElement |
- Returns:
- the internal animator.
int32_t SkAnimator::getArrayInt |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
int |
index | |
|
) |
| | |
Returns the scalar value of the specified element's attribute[index]
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| index | the array entry |
- Returns:
- the integer value to retrieve, or SK_NaN32 if unsuccessful
int32_t SkAnimator::getArrayInt |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field, |
|
|
int |
index | |
|
) |
| | |
Returns the scalar value of the specified element's attribute[index]
- Parameters:
-
| element | the value returned by getElement |
| field | the value returned by getField |
| index | the array entry |
- Returns:
- the integer value to retrieve, or SK_NaN32 if unsuccessful
SkScalar SkAnimator::getArrayScalar |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
int |
index | |
|
) |
| | |
Returns the scalar value of the specified element's attribute[index]
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| index | the array entry |
- Returns:
- the scalar value to retrieve, or SK_ScalarNaN if unsuccessful
SkScalar SkAnimator::getArrayScalar |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field, |
|
|
int |
index | |
|
) |
| | |
Returns the scalar value of the specified element's attribute[index]
- Parameters:
-
| element | the value returned by getElement |
| field | the value returned by getField |
| index | the array entry |
- Returns:
- the scalar value to retrieve, or SK_ScalarNaN if unsuccessful
const char* SkAnimator::getArrayString |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
int |
index | |
|
) |
| | |
Returns the string value of the specified element's attribute[index]
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| index | the array entry |
- Returns:
- the string value to retrieve, or null if unsuccessful
const char* SkAnimator::getArrayString |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field, |
|
|
int |
index | |
|
) |
| | |
Returns the string value of the specified element's attribute[index]
- Parameters:
-
| element | is a value returned by getElement |
| field | is a value returned by getField |
| index | the array entry |
- Returns:
- the string value to retrieve, or null if unsuccessful
const SkDisplayable* SkAnimator::getElement |
( |
const char * |
elementID |
) |
|
Returns the XML element corresponding to the given ID.
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
- Returns:
- the element matching the ID, or null if the element can't be found
SkElementType SkAnimator::getElementType |
( |
const char * |
elementID |
) |
|
Returns the element type corresponding to the given ID.
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
- Returns:
- element type, or 0 if the element can't be found
SkElementType SkAnimator::getElementType |
( |
const SkDisplayable * |
element |
) |
|
Returns the element type corresponding to the XML element. The element type matches the element name; for instance, <line> returns kElement_LineType
- Parameters:
-
| element | is a value returned by getElement |
- Returns:
- element type, or 0 if the element can't be found
const SkMemberInfo* SkAnimator::getField |
( |
const char * |
elementID, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the XML field of the named attribute in the XML element matching the elementID.
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | is the attribute to return |
- Returns:
- the attribute matching the fieldName, or null if the element can't be found
const SkMemberInfo* SkAnimator::getField |
( |
const SkDisplayable * |
element, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the XML field of the named attribute in the XML element.
- Parameters:
-
| element | is a value returned by getElement |
| fieldName | is the attribute to return |
- Returns:
- the attribute matching the fieldName, or null if the element can't be found
SkFieldType SkAnimator::getFieldType |
( |
const char * |
elementID, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the value type coresponding to the element's attribute.
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
- Returns:
- the attribute type, or 0 if the element can't be found
SkFieldType SkAnimator::getFieldType |
( |
const SkMemberInfo * |
field |
) |
|
Returns the value type coresponding to the element's attribute. The value type matches the XML schema: and may be kField_BooleanType, kField_ScalarType, etc.
- Parameters:
-
| field | is a value returned by getField |
- Returns:
- the attribute type, or 0 if the element can't be found
int32_t SkAnimator::getInt |
( |
const char * |
elementID, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
- Returns:
- the integer value to retrieve, or SK_NaN32 if not found
int32_t SkAnimator::getInt |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field | |
|
) |
| | |
Returns the scalar value of the specified element's attribute
- Parameters:
-
| element | is a value returned by getElement |
| field | is a value returned by getField |
- Returns:
- the integer value to retrieve, or SK_NaN32 if not found
SkMSec SkAnimator::getInterval |
( |
|
) |
|
Returns the recommended animation interval. Returns zero if no interval is specified.
void SkAnimator::getInvalBounds |
( |
SkRect * |
inval |
) |
|
Returns the partial rectangle to invalidate after drawing. Call after draw() returns kIsPartiallyDifferent to do a mimimal inval().
Returns the details of any error encountered while parsing the XML.
const char* SkAnimator::getParserErrorString |
( |
|
) |
|
Returns the details of any error encountered while parsing the XML as string.
SkScalar SkAnimator::getScalar |
( |
const char * |
elementID, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
- Returns:
- the scalar value to retrieve, or SK_ScalarNaN if not found
SkScalar SkAnimator::getScalar |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field | |
|
) |
| | |
Returns the scalar value of the specified element's attribute
- Parameters:
-
| element | is a value returned by getElement |
| field | is a value returned by getField |
- Returns:
- the scalar value to retrieve, or SK_ScalarNaN if not found
const char* SkAnimator::getString |
( |
const char * |
elementID, |
|
|
const char * |
fieldName | |
|
) |
| | |
Returns the string value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
- Returns:
- the string value to retrieve, or null if not found
const char* SkAnimator::getString |
( |
const SkDisplayable * |
element, |
|
|
const SkMemberInfo * |
field | |
|
) |
| | |
Returns the string value of the specified element's attribute
- Parameters:
-
| element | is a value returned by getElement |
| field | is a value returned by getField |
- Returns:
- the string value to retrieve, or null if not found
const char* SkAnimator::getURIBase |
( |
|
) |
|
Gets the file default directory of the URL base path set explicitly or by reading the last URL.
static void SkAnimator::Init |
( |
bool |
runUnitTests |
) |
[static] |
void SkAnimator::initialize |
( |
|
) |
|
Resets the animator to a newly created state with no animation data.
virtual void SkAnimator::onSetHostHandler |
( |
Handler |
handler |
) |
[protected, virtual] |
void SkAnimator::reset |
( |
|
) |
|
Experimental. Resets any active animations so that the next time passed is treated as time zero.
bool SkAnimator::setArrayInt |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
const int * |
array, |
|
|
int |
count | |
|
) |
| | |
Sets the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| array | is the c-style array of integers |
| count | is the length of the array |
- Returns:
- true if the value was set successfully
bool SkAnimator::setArrayString |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
const char ** |
array, |
|
|
int |
count | |
|
) |
| | |
Sets the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| array | is the c-style array of strings |
| count | is the length of the array |
- Returns:
- true if the value was set successfully
void SkAnimator::setHostEventSink |
( |
SkEventSink * |
sink |
) |
[inline] |
The event sink events generated by the animation are posted to. Screenplay also posts an inval event to this event sink after processing an event to force a redraw.
- Parameters:
-
void SkAnimator::setHostHandler |
( |
Handler |
handler |
) |
[inline] |
bool SkAnimator::setInt |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
int32_t |
data | |
|
) |
| | |
Sets the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| data | the integer value to set |
- Returns:
- true if the value was set successfully
virtual void SkAnimator::setJavaOwner |
( |
Handler |
owner |
) |
[virtual] |
bool SkAnimator::setScalar |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
SkScalar |
data | |
|
) |
| | |
Sets the scalar value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| data | the scalar value to set |
- Returns:
- true if the value was set successfully
bool SkAnimator::setString |
( |
const char * |
elementID, |
|
|
const char * |
fieldName, |
|
|
const char * |
data | |
|
) |
| | |
Sets the string value of the specified element's attribute
- Parameters:
-
| elementID | is the value of the id attribute in the XML of this element |
| fieldName | specifies the name of the attribute |
| data | the string value to set |
- Returns:
- true if the value was set successfully
void SkAnimator::setTimeline |
( |
const Timeline & |
|
) |
|
Sets a user class to return the current time to the animator. Optional; if not called, the system clock will be used by calling SkTime::GetMSecs instead.
- Parameters:
-
| callBack | the time function |
void SkAnimator::setURIBase |
( |
const char * |
path |
) |
|
Sets the file default directory of the URL base path
- Parameters:
-
static void SkAnimator::Term |
( |
|
) |
[static] |
Friends And Related Function Documentation
friend class SkAnimateMaker [friend] |
friend class SkAnimatorScript [friend] |
friend class SkAnimatorScript2 [friend] |
friend class SkApply [friend] |
friend class SkDisplayMovie [friend] |
friend class SkDisplayType [friend] |
friend class SkPost [friend] |
friend class SkXMLAnimatorWriter [friend] |
The documentation for this class was generated from the following file: