Skip to main content

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

enumZoomMode { 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

enumStates { ANIMATE_ZOOM, ANIMATE_ZOOM_AND_MOVE, NO_ANIMATION }
Animation states.

Public Functions

voidcancelZoomAnimation()
Cancel zoom animation.
virtual uint8_tgetAlpha() const
Gets the current alpha value of the widget.
virtual uint16_tgetAnimationDelay() const
Gets the current animation delay.
BitmapgetLargeBitmap() const
Gets the large bitmap.
virtual ScalableImage::ScalingAlgorithmgetScalingMode()
Gets the scaling algorithm of the ScalableImage.
BitmapgetSmallBitmap() const
Gets the small bitmap.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidateContent() const
Tell the framework that the contents of the Drawable needs to be redrawn.
boolisZoomAnimationRunning() const
Is there currently an animation running.
virtual voidsetAlpha(uint8_t newAlpha)
Sets the opacity (alpha value).
virtual voidsetAnimationDelay(uint16_t delay)
Sets a delay on animations done by the ZoomAnimationImage.
voidsetAnimationEndedCallback(GenericCallback< const ZoomAnimationImage & > & callback)
Associates an action to be performed when the animation ends.
voidsetBitmaps(const Bitmap & smallBitmap, const Bitmap & largeBitmap)
Initializes the bitmap of the image to be used.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
virtual voidsetScalingMode(ScalableImage::ScalingAlgorithm mode)
Sets the algorithm to be used.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
voidstartZoomAndMoveAnimation(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.
voidstartZoomAnimation(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 voidsetCurrentState(States state)
Sets the current animation state and reset the animation counter.
voidstartTimerAndSetParameters(int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode, EasingEquation widthProgressionEquation, EasingEquation heightProgressionEquation)
Starts timer and set parameters.
virtual voidupdateRenderingMethod()
Chooses the optimal rendering of the image given the current width and height.
virtual voidupdateZoomAnimationDeltaXY()
Calculates the change in X and Y caused by the zoom animation given the current ZoomMode.

Protected Attributes

uint16_tanimationCounter
The progress counter for the animation.
uint16_tanimationDuration
Duration of the animation.
GenericCallback< const ZoomAnimationImage & > *animationEndedAction
The animation ended action.
StatescurrentState
The current animation state.
ZoomModecurrentZoomMode
The ZoomMode to use by the animation.
Imageimage
The image for displaying the bitmap when the width/height is equal one of the bitmaps.
BitmaplargeBmp
The bitmap representing the large image.
int16_tmoveAnimationEndX
The move animation end x coordinate.
int16_tmoveAnimationEndY
The move animation end y coordinate.
EasingEquationmoveAnimationXEquation
The move animation x coordinate equation.
EasingEquationmoveAnimationYEquation
The move animation y coordinate equation.
ScalableImagescalableImage
The scalable image for displaying the bitmap when the width/height is not equal one of the bitmaps.
BitmapsmallBmp
The bitmap representing the small image.
uint16_tzoomAnimationDelay
A delay that is applied before animation start. Expressed in ticks.
int16_tzoomAnimationDeltaX
The zoom animation delta x.
int16_tzoomAnimationDeltaY
The zoom animation delta y.
int16_tzoomAnimationEndHeight
Height of the zoom animation end.
int16_tzoomAnimationEndWidth
Width of the zoom animation end.
EasingEquationzoomAnimationHeightEquation
The zoom animation height equation.
int16_tzoomAnimationStartHeight
Height of the zoom animation start.
int16_tzoomAnimationStartWidth
Width of the zoom animation start.
int16_tzoomAnimationStartX
The zoom animation start x coordinate.
int16_tzoomAnimationStartY
The zoom animation start y coordinate.
EasingEquationzoomAnimationWidthEquation
The zoom animation width equation.

Additional inherited members

Public Functions inherited from Container

virtual voidadd(Drawable & d)
Adds a Drawable instance as child to this Container.
Container()
virtual boolcontains(const Drawable & d)
Query if a given Drawable has been added directly to this Container.
virtual voiddraw(const Rect & invalidatedArea) const
Draw this drawable.
virtual voidforEachChild(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 voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Gets the last child in the list of children in this Container.
virtual voidgetLastChildNear(int16_t x, int16_t y, Drawable * last, int16_t fingerAdjustmentX, int16_t * fingerAdjustmentY)
Works similar to getLastChild() but also considers the current set finger size in HAL.
virtual RectgetSolidRect() const
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual voidinsert(Drawable * previous, Drawable & d)
Inserts a Drawable after a specific child node.
virtual voidremove(Drawable & d)
Removes a Drawable from the container by removing it from the linked list of children.
virtual voidremoveAll()
Removes all children in the Container by resetting their parent and sibling pointers.
virtual voidunlink()
Removes all children by unlinking the first child.

Protected Functions inherited from Container

virtual RectgetContainedArea() const
Gets a rectangle describing the total area covered by the children of this container.
virtual voidmoveChildrenRelative(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

voidcenter()
Centers the Drawable inside its parent.
voidcenterX()
Center the Drawable horizontally inside its parent.
voidcenterY()
Center the Drawable vertically inside its parent.
virtual voidchildGeometryChanged()
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 voiddraw(const Rect & invalidatedArea) const =0
Draw this drawable.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
voidexpand(int margin =0)
Expands the Drawable to have the same size as its parent with a given margin around the edge.
RectgetAbsoluteRect() 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_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(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 RectgetSolidRect() const =0
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleClickEvent(const ClickEvent & event)
Defines the event handler interface for ClickEvents.
virtual voidhandleDragEvent(const DragEvent & event)
Defines the event handler interface for DragEvents.
virtual voidhandleGestureEvent(const GestureEvent & event)
Defines the event handler interface for GestureEvents.
virtual voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & other)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(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.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Public Types Documentation

ZoomMode

A ZoomMode describes in which direction the image will grow/shrink when do a zoom animation.

FIXED_CENTERThe small image will grow from the center of the large image.
FIXED_LEFTThe small image will grow from the middle of the left side of the large image.
FIXED_RIGHTThe small image will grow from the middle of the right side of the large image.
FIXED_TOPThe small image will grow from the middle of the top of the large image.
FIXED_BOTTOMThe small image will grow from the middle of the bottom of the large image.
FIXED_LEFT_AND_TOPThe small image will grow from the top left corner of the large image.
FIXED_RIGHT_AND_TOPThe small image will grow from the top right corner of the large image.
FIXED_LEFT_AND_BOTTOMThe small image will grow from the bottom left corner of the large image.
FIXED_RIGHT_AND_BOTTOMThe small image will grow from the bottom right corner of the large image.

Protected Types Documentation

States

enum States

Animation states.

ANIMATE_ZOOMZoom animation state.
ANIMATE_ZOOM_AND_MOVEZoom and move animation state.
NO_ANIMATIONNo animation state.

Public Functions Documentation

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).

Returns:

The current alpha value.

See also:

getAnimationDelay

virtual uint16_t getAnimationDelay()const

Gets the current animation delay.

Returns:

The current animation delay. Expressed in ticks.

See also:

getLargeBitmap

Bitmap getLargeBitmap()const

Gets the large bitmap.

Returns:

the large bitmap.

See also:

getScalingMode

virtual ScalableImage::ScalingAlgorithm getScalingMode()

Gets the scaling algorithm of the ScalableImage.

Returns:

the scaling algorithm used.

See also:

getSmallBitmap

Bitmap getSmallBitmap()const

Gets the small bitmap.

Returns:

the small bitmap.

See also:

handleTickEvent

virtual void handleTickEvent()

Called periodically by the framework if the Drawable instance has subscribed to timer ticks.

See also:

Reimplements: touchgfx::Drawable::handleTickEvent

invalidateContent

virtual void invalidateContent()const

Tell the framework that the contents of the Drawable needs to be redrawn.

If the Drawable is invisible, nothing happens. Subclasses of Drawable are encouraged to implement this function and invalidate as little as possible, i.e. the smallest rectangle covering the visual element(s) drawn by the widget.

Reimplements: touchgfx::Container::invalidateContent

isZoomAnimationRunning

Is there currently an animation running.

Returns:

true if there is an animation running.

setAlpha

virtual void setAlpha(uint8_tnewAlpha)

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).

Parameters:
newAlphaThe new alpha value. 255=solid, 0=invisible.
Note

The user code must call invalidate() in order to update the display.

See also:

setAnimationDelay

virtual void setAnimationDelay(uint16_tdelay)

Sets a delay on animations done by the ZoomAnimationImage.

Defaults to 0 which means that the animation starts immediately.

Parameters:
delayThe delay in ticks.
See also:

setAnimationEndedCallback

Associates an action to be performed when the animation ends.

Parameters:
callbackThe callback to be executed. The callback will be given a reference to the ZoomAnimationImage.
See also:

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.

Parameters:
smallBitmapThe image in the smallest resolution.
largeBitmapThe 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.

See also:

setHeight

virtual void setHeight(int16_theight)

Sets the height of this drawable.

Parameters:
heightThe 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

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.

Parameters:
modeThe algorithm to use when rendering.
See also:

setWidth

virtual void setWidth(int16_twidth)

Sets the width of this drawable.

Parameters:
widthThe 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_tendX ,
int16_tendY ,
int16_tendWidth ,
int16_tendHeight ,
uint16_tduration ,
ZoomModezoomMode =FIXED_LEFT_AND_TOP,
EasingEquationxProgressionEquation =&EasingEquations::linearEaseNone,
EasingEquationyProgressionEquation =&EasingEquations::linearEaseNone,
EasingEquationwidthProgressionEquation =&EasingEquations::linearEaseNone,
EasingEquationheightProgressionEquation =&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.

Parameters:
endXThe X position of the image at animation end. Relative to the container or view that holds the ZoomAnimationImage.
endYThe Y position of the image at animation end. Relative to the container or view that holds the ZoomAnimationImage.
endWidthThe width of the image at animation end.
endHeightThe height of the image at animation end.
durationThe 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_tendWidth ,
int16_tendHeight ,
uint16_tduration ,
ZoomModezoomMode =FIXED_LEFT_AND_TOP,
EasingEquationwidthProgressionEquation =&EasingEquations::linearEaseNone,
EasingEquationheightProgressionEquation =&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.

Parameters:
endWidthThe width of the image at animation end.
endHeightThe height of the image at animation end.
durationThe 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(Statesstate)

Sets the current animation state and reset the animation counter.

Parameters:
stateThe new state.

startTimerAndSetParameters

void startTimerAndSetParameters(int16_tendWidth ,
int16_tendHeight ,
uint16_tduration ,
ZoomModezoomMode ,
EasingEquationwidthProgressionEquation ,
EasingEquationheightProgressionEquation
)

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.

Parameters:
endWidthThe end width.
endHeightThe end height.
durationThe duration.
zoomModeThe zoom mode.
widthProgressionEquationThe width progression equation.
heightProgressionEquationThe 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.

See also:

updateZoomAnimationDeltaXY

Calculates the change in X and Y caused by the zoom animation given the current ZoomMode.

Protected Attributes Documentation

animationCounter

uint16_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.