ZoomAnimationImage
Class for optimizing and wrapping move and zoom operations on a ScalableImage. The ZoomAnimationImage takes two bitmaps representing the same image but at a small and a large resolution. These bitmaps should be the sizes that are used when not animating the image. The ZoomAnimationImage will use an Image for displaying the Bitmap when its width and height matches either of them. When it does not match the size of one of the bitmaps, it will use a ScalableImage instead. The main idea is that the supplied bitmaps should be the end points of the zoom animation so that it ends up using an Image when not animating. This is, however, not a requirement. You can animate from and to sizes that are not equal the sizes of the bitmaps. The result is a container that has the high performance of an ordinary image when the size matches the pre-rendered bitmaps. Moreover it supplies easy to use animation functions that lets you zoom and move the image.
Note: Since this container uses the ScalableImage it has the same restrictions as a ScaleableImage, i.e. 1bpp is not supported.
Inherits from: Container, Drawable
Public Types
enum | ZoomMode { FIXED_CENTER, FIXED_LEFT, FIXED_RIGHT, FIXED_TOP, FIXED_BOTTOM, FIXED_LEFT_AND_TOP, FIXED_RIGHT_AND_TOP, FIXED_LEFT_AND_BOTTOM, FIXED_RIGHT_AND_BOTTOM } |
A ZoomMode describes in which direction the image will grow/shrink when do a zoom animation. | |
Protected Types
enum | States { ANIMATE_ZOOM, ANIMATE_ZOOM_AND_MOVE, NO_ANIMATION } |
Animation states. | |
Public Functions
void | cancelZoomAnimation() |
Cancel zoom animation. | |
virtual uint8_t | getAlpha() const |
Gets the current alpha value of the widget. | |
virtual uint16_t | getAnimationDelay() const |
Gets the current animation delay. | |
Bitmap | getLargeBitmap() const |
Gets the large bitmap. | |
virtual ScalableImage::ScalingAlgorithm | getScalingMode() |
Gets the scaling algorithm of the ScalableImage. | |
Bitmap | getSmallBitmap() const |
Gets the small bitmap. | |
virtual void | handleTickEvent() |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks. | |
bool | isZoomAnimationRunning() const |
Is there currently an animation running. | |
virtual void | setAlpha(uint8_t newAlpha) |
Sets the opacity (alpha value). | |
virtual void | setAnimationDelay(uint16_t delay) |
Sets a delay on animations done by the ZoomAnimationImage. | |
void | setAnimationEndedCallback(GenericCallback< const ZoomAnimationImage & > & callback) |
Associates an action to be performed when the animation ends. | |
void | setBitmaps(const Bitmap & smallBitmap, const Bitmap & largeBitmap) |
Initializes the bitmap of the image to be used. | |
virtual void | setHeight(int16_t height) |
Sets the height of this drawable. | |
virtual void | setScalingMode(ScalableImage::ScalingAlgorithm mode) |
Sets the algorithm to be used. | |
virtual void | setWidth(int16_t width) |
Sets the width of this drawable. | |
void | startZoomAndMoveAnimation(int16_t endX, int16_t endY, int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode =FIXED_LEFT_AND_TOP, EasingEquation xProgressionEquation =&EasingEquations::linearEaseNone, EasingEquation yProgressionEquation =&EasingEquations::linearEaseNone, EasingEquation widthProgressionEquation =&EasingEquations::linearEaseNone, EasingEquation heightProgressionEquation =&EasingEquations::linearEaseNone) |
Setup and starts the zoom and move animation. | |
void | startZoomAnimation(int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode =FIXED_LEFT_AND_TOP, EasingEquation widthProgressionEquation =&EasingEquations::linearEaseNone, EasingEquation heightProgressionEquation =&EasingEquations::linearEaseNone) |
Setup and starts the zoom animation. | |
ZoomAnimationImage() | |
Protected Functions
virtual void | setCurrentState(States state) |
Sets the current animation state and reset the animation counter. | |
void | startTimerAndSetParameters(int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode, EasingEquation widthProgressionEquation, EasingEquation heightProgressionEquation) |
Starts timer and set parameters. | |
virtual void | updateRenderingMethod() |
Chooses the optimal rendering of the image given the current width and height. | |
virtual void | updateZoomAnimationDeltaXY() |
Calculates the change in X and Y caused by the zoom animation given the current ZoomMode. | |
Protected Attributes
uint32_t | animationCounter |
The progress counter for the animation. | |
uint16_t | animationDuration |
Duration of the animation. | |
GenericCallback< const ZoomAnimationImage & > * | animationEndedAction |
The animation ended action. | |
States | currentState |
The current animation state. | |
ZoomMode | currentZoomMode |
The ZoomMode to use by the animation. | |
Image | image |
The image for displaying the bitmap when the width/height is equal one of the bitmaps. | |
Bitmap | largeBmp |
The bitmap representing the large image. | |
int16_t | moveAnimationEndX |
The move animation end x coordinate. | |
int16_t | moveAnimationEndY |
The move animation end y coordinate. | |
EasingEquation | moveAnimationXEquation |
The move animation x coordinate equation. | |
EasingEquation | moveAnimationYEquation |
The move animation y coordinate equation. | |
ScalableImage | scalableImage |
The scalable image for displaying the bitmap when the width/height is not equal one of the bitmaps. | |
Bitmap | smallBmp |
The bitmap representing the small image. | |
uint16_t | zoomAnimationDelay |
A delay that is applied before animation start. Expressed in ticks. | |
int16_t | zoomAnimationDeltaX |
The zoom animation delta x. | |
int16_t | zoomAnimationDeltaY |
The zoom animation delta y. | |
int16_t | zoomAnimationEndHeight |
Height of the zoom animation end. | |
int16_t | zoomAnimationEndWidth |
Width of the zoom animation end. | |
EasingEquation | zoomAnimationHeightEquation |
The zoom animation height equation. | |
int16_t | zoomAnimationStartHeight |
Height of the zoom animation start. | |
int16_t | zoomAnimationStartWidth |
Width of the zoom animation start. | |
int16_t | zoomAnimationStartX |
The zoom animation start x coordinate. | |
int16_t | zoomAnimationStartY |
The zoom animation start y coordinate. | |
EasingEquation | zoomAnimationWidthEquation |
The zoom animation width equation. | |
Additional inherited members
Public Functions inherited from Container
virtual void | add(Drawable & d) |
Adds a Drawable instance as child to this Container. | |
Container() | |
virtual bool | contains(const Drawable & d) |
Query if a given Drawable has been added directly to this Container. | |
virtual void | draw(const Rect & invalidatedArea) const |
Draw this drawable. | |
virtual void | forEachChild(GenericCallback< Drawable & > * function) |
Executes the specified callback function for each child in the Container. | |
virtual Drawable * | getFirstChild() |
Obtain a pointer to the first child of this container. | |
virtual void | getLastChild(int16_t x, int16_t y, Drawable ** last) |
Gets the last child in the list of children in this Container. | |
virtual Rect | getSolidRect() const |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
virtual void | insert(Drawable * previous, Drawable & d) |
Inserts a Drawable after a specific child node. | |
virtual void | remove(Drawable & d) |
Removes a Drawable from the container by removing it from the linked list of children. | |
virtual void | removeAll() |
Removes all children in the Container by resetting their parent and sibling pointers. | |
virtual void | unlink() |
Removes all children by unlinking the first child. | |
Protected Functions inherited from Container
virtual Rect | getContainedArea() const |
Gets a rectangle describing the total area covered by the children of this container. | |
virtual void | moveChildrenRelative(int16_t deltaX, int16_t deltaY) |
Calls moveRelative on all children. | |
Protected Attributes inherited from Container
Drawable * | firstChild |
Pointer to the first child of this container. Subsequent children can be found through firstChild's nextSibling. | |
Public Functions inherited from Drawable
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. | |
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 | 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. | |
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. | |
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 Types Documentation
ZoomMode
enum ZoomMode
A ZoomMode describes in which direction the image will grow/shrink when do a zoom animation.
FIXED_CENTER | The small image will grow from the center of the large image. |
FIXED_LEFT | The small image will grow from the middle of the left side of the large image. |
FIXED_RIGHT | The small image will grow from the middle of the right side of the large image. |
FIXED_TOP | The small image will grow from the middle of the top of the large image. |
FIXED_BOTTOM | The small image will grow from the middle of the bottom of the large image. |
FIXED_LEFT_AND_TOP | The small image will grow from the top left corner of the large image. |
FIXED_RIGHT_AND_TOP | The small image will grow from the top right corner of the large image. |
FIXED_LEFT_AND_BOTTOM | The small image will grow from the bottom left corner of the large image. |
FIXED_RIGHT_AND_BOTTOM | The small image will grow from the bottom right corner of the large image. |
Protected Types Documentation
States
enum States
Animation states.
ANIMATE_ZOOM | Zoom animation state. |
ANIMATE_ZOOM_AND_MOVE | Zoom and move animation state. |
NO_ANIMATION | No animation state. |
Public Functions Documentation
cancelZoomAnimation
void cancelZoomAnimation | ( | ) |
Cancel zoom animation.
The image is left in the position and size it is currently at.
getAlpha
virtual uint8_t getAlpha | ( | ) | const |
Gets the current alpha value of the widget.
The alpha value is in range 255 (solid) to 0 (invisible).
The current alpha value.
getAnimationDelay
virtual uint16_t getAnimationDelay | ( | ) | const |
Gets the current animation delay.
The current animation delay. Expressed in ticks.
getLargeBitmap
Bitmap getLargeBitmap | ( | ) | const |
getScalingMode
virtual ScalableImage::ScalingAlgorithm getScalingMode | ( | ) |
getSmallBitmap
Bitmap getSmallBitmap | ( | ) | const |
handleTickEvent
virtual void handleTickEvent | ( | ) |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
Reimplements: touchgfx::Drawable::handleTickEvent
isZoomAnimationRunning
bool isZoomAnimationRunning | ( | ) | const |
Is there currently an animation running.
true if there is an animation running.
setAlpha
virtual void setAlpha | ( | uint8_t | newAlpha | ) | |
Sets the opacity (alpha value).
This can be used to fade it away by gradually decreasing the alpha value from 255 (solid) to 0 (invisible).
newAlpha | The new alpha value. 255=solid, 0=invisible. |
Note
The user code must call invalidate() in order to update the display.
setAnimationDelay
virtual void setAnimationDelay | ( | uint16_t | delay | ) | |
Sets a delay on animations done by the ZoomAnimationImage.
Defaults to 0 which means that the animation starts immediately.
delay | The delay in ticks. |
setAnimationEndedCallback
void setAnimationEndedCallback | ( | GenericCallback< const ZoomAnimationImage & > & | callback | ) | |
Associates an action to be performed when the animation ends.
callback | The callback to be executed. The callback will be given a reference to the ZoomAnimationImage. |
setBitmaps
void setBitmaps | ( | const Bitmap & | smallBitmap , | ||
const Bitmap & | largeBitmap | ||||
) |
Initializes the bitmap of the image to be used.
The bitmaps should represent the same image in the two needed static resolutions.
smallBitmap | The image in the smallest resolution. |
largeBitmap | The image in the largest resolution. |
Note
The size of the bitmaps do not in any way limit the size of the ZoomAnimationImage and it is possible to scale the image beyond the sizes of these bitmaps.
setHeight
virtual void setHeight | ( | int16_t | height | ) | |
Sets the height of this drawable.
height | The new height. |
Note
For most Drawable widgets, changing this does normally not automatically yield a redraw.ZoomAnimationImage diverts from the normal behavior by automatically invalidating which causes a redraw.
Reimplements: touchgfx::Drawable::setHeight
setScalingMode
virtual void setScalingMode | ( | ScalableImage::ScalingAlgorithm | mode | ) | |
Sets the algorithm to be used.
In short, there is currently a value for fast (nearest neighbor) and a value for slow (bilinear interpolation). Default is ScalableImage::NEAREST_NEIGHBOR since moving images do not need to be of the best quality, until they stop moving. If the image moves only a little bit, or moves/resizes slowly, consider using ScaleableImage::BILINEAR_INTERPOLATION.
mode | The algorithm to use when rendering. |
setWidth
virtual void setWidth | ( | int16_t | width | ) | |
Sets the width of this drawable.
width | The new width. |
Note
For most Drawable widgets, changing this does normally not automatically yield a redraw.ZoomAnimationImage diverts from the normal behavior by automatically invalidating which causes a redraw.
Reimplements: touchgfx::Drawable::setWidth
startZoomAndMoveAnimation
void startZoomAndMoveAnimation | ( | int16_t | endX , | ||
int16_t | endY , | ||||
int16_t | endWidth , | ||||
int16_t | endHeight , | ||||
uint16_t | duration , | ||||
ZoomMode | zoomMode =FIXED_LEFT_AND_TOP, | ||||
EasingEquation | xProgressionEquation =&EasingEquations::linearEaseNone, | ||||
EasingEquation | yProgressionEquation =&EasingEquations::linearEaseNone, | ||||
EasingEquation | widthProgressionEquation =&EasingEquations::linearEaseNone, | ||||
EasingEquation | heightProgressionEquation =&EasingEquations::linearEaseNone | ||||
) |
Setup and starts the zoom and move animation.
At end of the animation the image will have been resized to the endWidth and endHeight and have moved from its original position to the endX and endY. Please note that the ZoomMode might influence the actual end position since the zoom transformation might change the X and Y of the image. The ZoomMode FIXED_LEFT_AND_TOP ensures that the endX and endY will be the actual end position.
The development of the width, height, X and Y during the animation is described by the supplied EasingEquations. The container is registered as a TimerWidget and automatically unregistered when the animation has finished.
endX | The X position of the image at animation end. Relative to the container or view that holds the ZoomAnimationImage. |
endY | The Y position of the image at animation end. Relative to the container or view that holds the ZoomAnimationImage. |
endWidth | The width of the image at animation end. |
endHeight | The height of the image at animation end. |
duration | The duration of the animation measured in ticks. |
zoomMode | (Optional) The zoom mode that will be used during the animation. Default is FIXED_LEFT_AND_TOP. |
xProgressionEquation | (Optional) The equation that describes the development of the X position during the animation. Default is EasingEquations::linearEaseNone. |
yProgressionEquation | (Optional) The equation that describes the development of the Y position during the animation. Default is EasingEquations::linearEaseNone. |
widthProgressionEquation | (Optional) The equation that describes the development of the width during the animation. Default is EasingEquations::linearEaseNone. |
heightProgressionEquation | (Optional) The equation that describes the development of the height during the animation. Default is EasingEquations::linearEaseNone. |
startZoomAnimation
void startZoomAnimation | ( | int16_t | endWidth , | ||
int16_t | endHeight , | ||||
uint16_t | duration , | ||||
ZoomMode | zoomMode =FIXED_LEFT_AND_TOP, | ||||
EasingEquation | widthProgressionEquation =&EasingEquations::linearEaseNone, | ||||
EasingEquation | heightProgressionEquation =&EasingEquations::linearEaseNone | ||||
) |
Setup and starts the zoom animation.
At end of the animation the image will have been resized to the endWidth and endHeight. The development of the width and height during the animation is described by the supplied EasingEquations. The container is registered as a TimerWidget and automatically unregistered when the animation has finished.
endWidth | The width of the image at animation end. |
endHeight | The height of the image at animation end. |
duration | The duration of the animation measured in ticks. |
zoomMode | (Optional) The zoom mode that will be used during the animation. Default is FIXED_LEFT_AND_TOP. |
widthProgressionEquation | (Optional) The equation that describes the development of the width during the animation. Default is EasingEquations::linearEaseNone. |
heightProgressionEquation | (Optional) The equation that describes the development of the height during the animation. Default is EasingEquations::linearEaseNone. |
Note
The animation follows the specified ZoomMode so the X and Y coordinates of the image might change during animation.
ZoomAnimationImage
Protected Functions Documentation
setCurrentState
virtual void setCurrentState | ( | States | state | ) | |
Sets the current animation state and reset the animation counter.
state | The new state. |
startTimerAndSetParameters
void startTimerAndSetParameters | ( | int16_t | endWidth , | ||
int16_t | endHeight , | ||||
uint16_t | duration , | ||||
ZoomMode | zoomMode , | ||||
EasingEquation | widthProgressionEquation , | ||||
EasingEquation | heightProgressionEquation | ||||
) |
Starts timer and set parameters.
Contains code shared between startZoomAnimation() and startZoomAndMoveAnimation(). If both delay and duration is zero, the end position and size is applied and the animation is ended immediately.
endWidth | The end width. |
endHeight | The end height. |
duration | The duration. |
zoomMode | The zoom mode. |
widthProgressionEquation | The width progression equation. |
heightProgressionEquation | The height progression equation. |
updateRenderingMethod
virtual void updateRenderingMethod | ( | ) |
Chooses the optimal rendering of the image given the current width and height.
If the dimensions match either the small or large bitmap, that will be used, otherwise the large image will be scaled using the defined scaling mode.
updateZoomAnimationDeltaXY
virtual void updateZoomAnimationDeltaXY | ( | ) |
Calculates the change in X and Y caused by the zoom animation given the current ZoomMode.
Protected Attributes Documentation
animationCounter
uint32_t animationCounter
The progress counter for the animation.
animationDuration
uint16_t animationDuration
Duration of the animation.
animationEndedAction
GenericCallback< const ZoomAnimationImage & > * animationEndedAction
The animation ended action.
currentState
States currentState
The current animation state.
currentZoomMode
ZoomMode currentZoomMode
The ZoomMode to use by the animation.
image
Image image
The image for displaying the bitmap when the width/height is equal one of the bitmaps.
largeBmp
Bitmap largeBmp
The bitmap representing the large image.
moveAnimationEndX
int16_t moveAnimationEndX
The move animation end x coordinate.
moveAnimationEndY
int16_t moveAnimationEndY
The move animation end y coordinate.
moveAnimationXEquation
EasingEquation moveAnimationXEquation
The move animation x coordinate equation.
moveAnimationYEquation
EasingEquation moveAnimationYEquation
The move animation y coordinate equation.
scalableImage
ScalableImage scalableImage
The scalable image for displaying the bitmap when the width/height is not equal one of the bitmaps.
smallBmp
Bitmap smallBmp
The bitmap representing the small image.
zoomAnimationDelay
uint16_t zoomAnimationDelay
A delay that is applied before animation start. Expressed in ticks.
zoomAnimationDeltaX
int16_t zoomAnimationDeltaX
The zoom animation delta x.
zoomAnimationDeltaY
int16_t zoomAnimationDeltaY
The zoom animation delta y.
zoomAnimationEndHeight
int16_t zoomAnimationEndHeight
Height of the zoom animation end.
zoomAnimationEndWidth
int16_t zoomAnimationEndWidth
Width of the zoom animation end.
zoomAnimationHeightEquation
EasingEquation zoomAnimationHeightEquation
The zoom animation height equation.
zoomAnimationStartHeight
int16_t zoomAnimationStartHeight
Height of the zoom animation start.
zoomAnimationStartWidth
int16_t zoomAnimationStartWidth
Width of the zoom animation start.
zoomAnimationStartX
int16_t zoomAnimationStartX
The zoom animation start x coordinate.
zoomAnimationStartY
int16_t zoomAnimationStartY
The zoom animation start y coordinate.
zoomAnimationWidthEquation
EasingEquation zoomAnimationWidthEquation
The zoom animation width equation.