AnimatedImage
A widget capable of basic animation using a range of bitmaps. The AnimatedImage is capable of running the animation from start to end or, in reverse order, end to start. It is capable of doing a single animation or looping the animation until stopped or paused.
Inherits from: Image, Widget, Drawable
Public Functions
AnimatedImage(const BitmapId & start, const BitmapId & end, const uint8_t & updateInterval =1) | |
Constructs an AnimatedImage. | |
AnimatedImage(const uint8_t & updateInterval =1) | |
Constructs an AnimatedImage without initializing bitmaps. | |
virtual void | handleTickEvent() |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks. | |
bool | isAnimatedImageRunning() const |
Gets the running state of the AnimatedImage. | |
bool | isReverse() |
Query if this object is running in reverse. | |
virtual void | pauseAnimation() |
Toggles the running state of an animation. | |
virtual void | setBitmap(const Bitmap & bmp) |
Sets the bitmap for this Image and updates the width and height of this widget to match those of the Bitmap. | |
virtual void | setBitmapEnd(const Bitmap & bmp) |
Sets the end bitmap for this AnimatedImage sequence. | |
void | setBitmaps(BitmapId start, BitmapId end) |
Sets the bitmaps that are used by the animation. | |
void | setDoneAction(GenericCallback< const AnimatedImage & > & callback) |
Associates an action to be performed when the animation of the AnimatedImage is done. | |
void | setUpdateTicksInterval(uint8_t updateInterval) |
Sets the update interval. | |
virtual void | startAnimation(const bool rev, const bool reset =false, const bool loop =false) |
Starts the animation with the given parameters for animation direction, normal or reverse, whether to restart the animation and finally if the animation should loop automatically upon completion. | |
virtual void | stopAnimation() |
Stops and resets the animation. | |
Protected Attributes
GenericCallback< const AnimatedImage & > * | animationDoneAction |
Pointer to the callback to be executed when animation is done. | |
BitmapId | endId |
Id of last bitmap in animation. | |
bool | loopAnimation |
If true, continuously loop animation. | |
bool | reverse |
If true, run in reverse direction (last to first). | |
bool | running |
If true, animation is running. | |
BitmapId | startId |
Id of first bitmap in animation. | |
uint8_t | ticksSinceUpdate |
Number of ticks since last animation update. | |
uint8_t | updateTicksInterval |
Number of ticks between each animation update (image change). | |
Additional inherited members
Public Functions inherited from Image
virtual void | draw(const Rect & invalidatedArea) const |
Draw this drawable. | |
uint8_t | getAlpha() const |
Gets the current alpha value of the widget. | |
Bitmap | getBitmap() const |
Gets the Bitmap currently assigned to the Image widget. | |
BitmapId | getBitmapId() const |
Gets the BitmapId currently assigned to the Image widget. | |
virtual Rect | getSolidRect() const |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
Image(const Bitmap & bmp =Bitmap()) | |
Constructs a new Image with a default alpha value of 255 (solid) and a default Bitmap (undefined) if none is specified. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
void | setAlpha(uint8_t newAlpha) |
Sets the opacity (alpha value). | |
Protected Attributes inherited from Image
Public Functions inherited from Widget
virtual void | getLastChild(int16_t x, int16_t y, Drawable ** last) |
Since a Widget is only one Drawable, Widget::getLastChild simply yields itself as result, but only if the Widget isVisible and isTouchable. | |
Public Functions inherited from Drawable
void | center() |
Centers the Drawable inside its parent. | |
void | centerX() |
Center the Drawable horizontally inside its parent. | |
void | centerY() |
Center the Drawable vertically inside its parent. | |
virtual void | childGeometryChanged() |
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed. | |
virtual void | draw(const Rect & invalidatedArea) const =0 |
Draw this drawable. | |
Drawable() | |
Initializes a new instance of the Drawable class. | |
void | drawToDynamicBitmap(BitmapId id) |
Render the Drawable object into a dynamic bitmap. | |
void | expand(int margin =0) |
Expands the Drawable to have the same size as its parent with a given margin around the edge. | |
Rect | getAbsoluteRect() const |
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates. | |
virtual Drawable * | getFirstChild() |
Function for obtaining the first child of this drawable if any. | |
int16_t | getHeight() const |
Gets the height of this Drawable. | |
virtual void | getLastChild(int16_t x, int16_t y, Drawable ** last) =0 |
Function for obtaining the the last child of this drawable that intersects with the specified point. | |
Drawable * | getNextSibling() |
Gets the next sibling node. | |
Drawable * | getParent() const |
Returns the parent node. | |
const Rect & | getRect() const |
Gets the rectangle this Drawable covers, in coordinates relative to its parent. | |
virtual Rect | getSolidRect() const =0 |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
virtual Rect | getSolidRectAbsolute() |
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates. | |
virtual void | getVisibleRect(Rect & rect) const |
Function for finding the visible part of this drawable. | |
int16_t | getWidth() const |
Gets the width of this Drawable. | |
int16_t | getX() const |
Gets the x coordinate of this Drawable, relative to its parent. | |
int16_t | getY() const |
Gets the y coordinate of this Drawable, relative to its parent. | |
virtual void | handleClickEvent(const ClickEvent & event) |
Defines the event handler interface for ClickEvents. | |
virtual void | handleDragEvent(const DragEvent & event) |
Defines the event handler interface for DragEvents. | |
virtual void | handleGestureEvent(const GestureEvent & event) |
Defines the event handler interface for GestureEvents. | |
virtual void | invalidate() const |
Tell the framework that this entire Drawable needs to be redrawn. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
virtual void | invalidateRect(Rect & invalidatedArea) const |
Request that a region of this drawable is redrawn. | |
bool | isTouchable() const |
Gets whether this Drawable receives touch events or not. | |
bool | isVisible() const |
Gets whether this Drawable is visible. | |
virtual void | moveRelative(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | moveTo(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | setHeight(int16_t height) |
Sets the height of this drawable. | |
void | setPosition(const Drawable & drawable) |
Sets the position of the Drawable to the same as the given Drawable. | |
void | setPosition(int16_t x, int16_t y, int16_t width, int16_t height) |
Sets the size and position of this Drawable, relative to its parent. | |
void | setTouchable(bool touch) |
Controls whether this Drawable receives touch events or not. | |
void | setVisible(bool vis) |
Controls whether this Drawable should be visible. | |
virtual void | setWidth(int16_t width) |
Sets the width of this drawable. | |
void | setWidthHeight(const Bitmap & bitmap) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Drawable & drawable) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Rect & rect) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(int16_t width, int16_t height) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
virtual void | setX(int16_t x) |
Sets the x coordinate of this Drawable, relative to its parent. | |
void | setXY(const Drawable & drawable) |
Sets the x and y coordinates of this Drawable. | |
void | setXY(int16_t x, int16_t y) |
Sets the x and y coordinates of this Drawable, relative to its parent. | |
virtual void | setY(int16_t y) |
Sets the y coordinate of this Drawable, relative to its parent. | |
virtual void | translateRectToAbsolute(Rect & r) const |
Helper function for converting a region of this Drawable to absolute coordinates. | |
virtual | ~Drawable() |
Finalizes an instance of the Drawable class. | |
Protected Attributes inherited from Drawable
Drawable * | nextSibling |
Pointer to the next Drawable. | |
Drawable * | parent |
Pointer to this drawable's parent. | |
Rect | rect |
The coordinates of this Drawable, relative to its parent. | |
bool | touchable |
True if this drawable should receive touch events. | |
bool | visible |
True if this drawable should be drawn. | |
Public Functions Documentation
AnimatedImage
AnimatedImage | ( | const BitmapId & | start , | ||
const BitmapId & | end , | ||||
const uint8_t & | updateInterval =1 | ||||
) |
Constructs an AnimatedImage.
The start and the end specifies the range of bitmaps to be used for animation. The update interval defines how often the animation should be updated. The animation will iterate over the bitmaps that lies between the IDs of start and end, both included.
start | Defines the start of the range of images in the animation. |
end | Defines the end of the range of images in the animation. |
updateInterval | (Optional) Defines the number of ticks between each animation step. Higher value results in a slower animation. Default is to update the image on every tick. |
AnimatedImage
AnimatedImage | ( | const uint8_t & | updateInterval =1 | ) | |
Constructs an AnimatedImage without initializing bitmaps.
updateInterval | (Optional) Defines the number of ticks between each animation step. Higher value results in a slower animation. |
Note
The bitmaps to display must be configured through set setBitmaps function before this widget displays anything.
handleTickEvent
virtual void handleTickEvent | ( | ) |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
Reimplements: touchgfx::Drawable::handleTickEvent
isAnimatedImageRunning
bool isAnimatedImageRunning | ( | ) | const |
Gets the running state of the AnimatedImage.
true if the animation is currently running, false otherwise.
isReverse
bool isReverse | ( | ) |
Query if this object is running in reverse.
true if the animation is performed in reverse order.
pauseAnimation
virtual void pauseAnimation | ( | ) |
Toggles the running state of an animation.
Pauses the animation if the animation is running. Continues the animation if previously paused.
setBitmap
Sets the bitmap for this Image and updates the width and height of this widget to match those of the Bitmap.
bmp | The bitmap instance. |
Note
The user code must call invalidate() in order to update the image on the display.This only sets the start image.
Reimplements: touchgfx::Image::setBitmap
setBitmapEnd
virtual void setBitmapEnd | ( | const Bitmap & | bmp | ) | |
setBitmaps
void setBitmaps | ( | BitmapId | start , | ||
BitmapId | end | ||||
) |
Sets the bitmaps that are used by the animation.
The animation will iterate over the bitmaps that lies between the IDs of start and end, both inclusive.
start | Defines the start of the range of images in the animation. |
end | Defines the end of the range of images in the animation. |
setDoneAction
void setDoneAction | ( | GenericCallback< const AnimatedImage & > & | callback | ) | |
Associates an action to be performed when the animation of the AnimatedImage is done.
If the animation is set to loop at the end, the action is also triggered when the animation starts over.
callback | The callback is executed when done. The callback is given the animated image. |
setUpdateTicksInterval
void setUpdateTicksInterval | ( | uint8_t | updateInterval | ) | |
Sets the update interval.
The value specifies the number of ticks between each step of the animation. The default update interval for animated images is 1, which means results in the fastest possible animation.
updateInterval | Defines the number of ticks between each animation step. Higher value results in a slower animation. |
startAnimation
virtual void startAnimation | ( | const bool | rev , | ||
const bool | reset =false, | ||||
const bool | loop =false | ||||
) |
Starts the animation with the given parameters for animation direction, normal or reverse, whether to restart the animation and finally if the animation should loop automatically upon completion.
rev | Defines if the animation should be performed in reverse order. |
reset | (Optional) Defines if the animation should reset and start from the first (or last if reverse order) bitmap. |
loop | (Optional) Defines if the animation should loop or do a single animation. |
stopAnimation
virtual void stopAnimation | ( | ) |
Stops and resets the animation.
If the animation should not reset to the first image in the animation sequence, use pauseAnimation().
Protected Attributes Documentation
animationDoneAction
GenericCallback< const AnimatedImage & > * animationDoneAction
Pointer to the callback to be executed when animation is done.
endId
BitmapId endId
Id of last bitmap in animation.
loopAnimation
bool loopAnimation
If true, continuously loop animation.
reverse
bool reverse
If true, run in reverse direction (last to first).
running
bool running
If true, animation is running.
startId
BitmapId startId
Id of first bitmap in animation.
ticksSinceUpdate
uint8_t ticksSinceUpdate
Number of ticks since last animation update.
updateTicksInterval
uint8_t updateTicksInterval
Number of ticks between each animation update (image change).