AnalogClock
An analog clock. Should be supplied with images for the background, hour hand, minute hand and the optional second hand. You setup the AnalogClock by specifying the rotation point of each hand as well as the global rotation point of the clock. You can customize the behavior of the AnalogClock in respect to animations and relations between the hands e.g. if the hour hand should move gradually towards the next hour as the minute hand progresses (setHourHandMinuteCorrection())
Inherits from: AbstractClock, Container, Drawable
Public Functions
AnalogClock() | |
virtual uint8_t | getAlpha() const |
Gets the current alpha value of the widget. | |
virtual uint16_t | getAnimationDuration() |
Gets the animation duration. | |
virtual bool | getHourHandMinuteCorrection() const |
Gets hour hand minute correction. | |
virtual bool | getMinuteHandSecondCorrection() const |
Gets minute hand second correction. | |
virtual void | initializeTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am) |
Sets the time with input format as 12H. | |
virtual void | initializeTime24Hour(uint8_t hour, uint8_t minute, uint8_t second) |
Sets the time with input format as 24H. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
virtual void | setAlpha(uint8_t newAlpha) |
Sets the opacity (alpha value). | |
virtual void | setAnimation(uint16_t duration =10, EasingEquation animationProgressionEquation =EasingEquations::backEaseInOut) |
Setup the clock to use animation for hand movements. | |
virtual void | setBackground(const BitmapId backgroundBitmapId) |
Sets the background image of the clock. | |
virtual void | setBackground(const BitmapId backgroundBitmapId, int16_t rotationCenterX, int16_t rotationCenterY) |
Sets the background image of the clock and the rotation center of the clock. | |
virtual void | setHourHandMinuteCorrection(bool active) |
Sets whether hour hand minute correction should be active. | |
virtual void | setMinuteHandSecondCorrection(bool active) |
Sets whether minute hand second correction should be active. | |
virtual void | setRotationCenter(int16_t rotationCenterX, int16_t rotationCenterY) |
Sets the rotation center of the clock. | |
virtual void | setupHourHand(const BitmapId hourHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY) |
Sets up the hour hand. | |
virtual void | setupMinuteHand(const BitmapId minuteHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY) |
Sets up the minute hand. | |
virtual void | setupSecondHand(const BitmapId secondHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY) |
Sets up the second hand. | |
Protected Functions
virtual bool | animationEnabled() const |
Is animation enabled for the hands? | |
virtual float | convertHandValueToAngle(uint8_t steps, uint8_t handValue, uint8_t secondHandValue =0) const |
Convert hand value to angle. | |
virtual void | setupHand(TextureMapper & hand, const BitmapId bitmapId, int16_t rotationCenterX, int16_t rotationCenterY) |
Sets up a given the hand. | |
virtual void | updateClock() |
Update the visual representation of the clock on the display. | |
Protected Attributes
uint16_t | animationDuration |
The duration of hand animations. If 0 animations are disabled. | |
EasingEquation | animationEquation |
The easing equation used by hand animations. | |
Image | background |
The background image of the AnalogClock. | |
int16_t | clockRotationCenterX |
The x coordinate of the rotation point of the hands. | |
int16_t | clockRotationCenterY |
The y coordinate of the rotation point of the hands. | |
AnimationTextureMapper | hourHand |
TextureMapper used for drawing the hourHand. | |
bool | hourHandMinuteCorrectionActive |
Is hour hand minute correction active. | |
uint8_t | lastHour |
The last know hour value. | |
uint8_t | lastMinute |
The last know minute value. | |
uint8_t | lastSecond |
The last know second value. | |
AnimationTextureMapper | minuteHand |
TextureMapper used for drawing the minuteHand. | |
bool | minuteHandSecondCorrectionActive |
Is minute hand second correction active. | |
AnimationTextureMapper | secondHand |
TextureMapper used for drawing the secondHand. | |
Additional inherited members
Public Functions inherited from AbstractClock
AbstractClock() | |
bool | getCurrentAM() const |
Is the current time a.m. | |
uint8_t | getCurrentHour() const |
Gets the current hour. | |
uint8_t | getCurrentHour12() const |
Gets current hour 12, i.e. | |
uint8_t | getCurrentHour24() const |
Gets current hour 24, i.e. | |
uint8_t | getCurrentMinute() const |
Gets the current minute. | |
uint8_t | getCurrentSecond() const |
Gets the current second. | |
virtual void | setTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am) |
Sets the time with input format as 12H. | |
virtual void | setTime24Hour(uint8_t hour, uint8_t minute, uint8_t second) |
Sets the time with input format as 24H. | |
Protected Attributes inherited from AbstractClock
uint8_t | currentHour |
Local copy of the current hour. | |
uint8_t | currentMinute |
Local copy of the current minute. | |
uint8_t | currentSecond |
Local copy of the current second. | |
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 void | getLastChildNear(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 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
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 | handleTickEvent() |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks. | |
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. | |
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 & other) |
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
AnalogClock
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.
getAnimationDuration
virtual uint16_t getAnimationDuration | ( | ) |
getHourHandMinuteCorrection
virtual bool getHourHandMinuteCorrection | ( | ) | const |
Gets hour hand minute correction.
true if hour hand minute correction is active.
getMinuteHandSecondCorrection
virtual bool getMinuteHandSecondCorrection | ( | ) | const |
Gets minute hand second correction.
true if minute hand second correction is active.
initializeTime12Hour
virtual void initializeTime12Hour | ( | uint8_t | hour , | ||
uint8_t | minute , | ||||
uint8_t | second , | ||||
bool | am | ||||
) |
Sets the time with input format as 12H.
No animations are performed regardless of the animation settings. This is often useful when setting up the AnalogClock where you do not want an initial animation.
hour | The hours, value should be between 1 and 12. |
minute | The minutes, value should be between 0 and 59. |
second | The seconds, value should be between 0 and 59. |
am | AM/PM setting. True = AM, false = PM. |
Note
that this does not affect any selected presentation formats.
initializeTime24Hour
virtual void initializeTime24Hour | ( | uint8_t | hour , | ||
uint8_t | minute , | ||||
uint8_t | second | ||||
) |
Sets the time with input format as 24H.
No animations are performed regardless of the animation settings. This is often useful when setting up the AnalogClock where you do not want an initial animation.
hour | The hours, value should be between 0 and 23. |
minute | The minutes, value should be between 0 and 59. |
second | The seconds, value should be between 0 and 59. |
Note
that this does not affect any selected presentation formats.
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
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. The alpha value is reflected in the background image
setAnimation
virtual void setAnimation | ( | uint16_t | duration =10, | ||
EasingEquation | animationProgressionEquation =EasingEquations::backEaseInOut | ||||
) |
Setup the clock to use animation for hand movements.
duration | (Optional) The animation duration, default is 10. |
animationProgressionEquation | (Optional) The animation progression equation, default is EasingEquations::backEaseInOut. |
setBackground
virtual void setBackground | ( | const BitmapId | backgroundBitmapId | ) | |
Sets the background image of the clock.
The clock rotation center is automatically set to the background image center. The clock rotation center is the point that the clock hands rotates around. The size of the AnalocClock widget is set to the size of the bitmap.
backgroundBitmapId | Identifier for the background bitmap. |
setBackground
virtual void setBackground | ( | const BitmapId | backgroundBitmapId , | ||
int16_t | rotationCenterX , | ||||
int16_t | rotationCenterY | ||||
) |
Sets the background image of the clock and the rotation center of the clock.
The clock rotation center is the point that the clock hands rotates around. The size of the AnalocClock widget is set to the size of the bitmap.
backgroundBitmapId | Identifier for the background bitmap. |
rotationCenterX | The rotation center x coordinate. |
rotationCenterY | The rotation center y coordinate. |
setHourHandMinuteCorrection
virtual void setHourHandMinuteCorrection | ( | bool | active | ) | |
Sets whether hour hand minute correction should be active.
If set to true the hour hand will be positioned between the current hour and the next depending on the minute hands position.
active | true to use hour hand correction. |
setMinuteHandSecondCorrection
virtual void setMinuteHandSecondCorrection | ( | bool | active | ) | |
Sets whether minute hand second correction should be active.
If set to true the minute hand will be positioned between the current minute and the next depending on the second hands position.
active | true to use. |
setRotationCenter
virtual void setRotationCenter | ( | int16_t | rotationCenterX , | ||
int16_t | rotationCenterY | ||||
) |
Sets the rotation center of the clock.
The clock rotation center is the point that the clock hands rotates around.
rotationCenterX | The rotation center x coordinate. |
rotationCenterY | The rotation center y coordinate. |
setupHourHand
virtual void setupHourHand | ( | const BitmapId | hourHandBitmapId , | ||
int16_t | rotationCenterX , | ||||
int16_t | rotationCenterY | ||||
) |
Sets up the hour hand.
The specified rotation center is the point of the hand that is to be placed on top of the clock rotation center. That is the point that the hand rotates around. The rotation point is relative to the supplied bitmap and can be placed outside of it.
hourHandBitmapId | Identifier for the hour hand bitmap. |
rotationCenterX | The hand rotation center x coordinate. |
rotationCenterY | The hand rotation center y coordinate. |
Note
If no hour hand is setup it will just be omitted.
setupMinuteHand
virtual void setupMinuteHand | ( | const BitmapId | minuteHandBitmapId , | ||
int16_t | rotationCenterX , | ||||
int16_t | rotationCenterY | ||||
) |
Sets up the minute hand.
The specified rotation center is the point of the hand that is to be placed on top of the clock rotation center. That is the point that the hand rotates around. The rotation point is relative to the supplied bitmap but can be placed outside of it.
minuteHandBitmapId | Identifier for the minute hand bitmap. |
rotationCenterX | The hand rotation center x coordinate. |
rotationCenterY | The hand rotation center y coordinate. |
Note
If no minute hand is setup it will just be omitted.
setupSecondHand
virtual void setupSecondHand | ( | const BitmapId | secondHandBitmapId , | ||
int16_t | rotationCenterX , | ||||
int16_t | rotationCenterY | ||||
) |
Sets up the second hand.
The specified rotation center is the point of the hand that is to be placed on top of the clock rotation center. That is the point that the hand rotates around. The rotation point is relative to the supplied bitmap but can be placed outside of it.
secondHandBitmapId | Identifier for the second hand bitmap. |
rotationCenterX | The hand rotation center x coordinate. |
rotationCenterY | The hand rotation center y coordinate. |
Note
If no second hand is setup it will just be omitted.
Protected Functions Documentation
animationEnabled
virtual bool animationEnabled | ( | ) | const |
Is animation enabled for the hands?
true if animation is enabled.
convertHandValueToAngle
virtual float convertHandValueToAngle | ( | uint8_t | steps , | const | |
uint8_t | handValue , | const | |||
uint8_t | secondHandValue =0 | const | |||
) | const |
Convert hand value to angle.
steps | Number of steps the primary hand value is divided into, i.e. 60 for minutes/seconds and 12 for hour. |
handValue | The actual value for the hand in question (in the range [0; steps]). |
secondHandValue | (Optional) If the angle should be corrected for a secondary hand its value should be specified here (in the range [0; 60]). This is the case when setHourHandMinuteCorrection(true) or setMinuteHandSecondCorrection(true) is selected. |
The converted value to angle.
setupHand
virtual void setupHand | ( | TextureMapper & | hand , | ||
const BitmapId | bitmapId , | ||||
int16_t | rotationCenterX , | ||||
int16_t | rotationCenterY | ||||
) |
Sets up a given the hand.
hand | Reference to the hand being setup. |
bitmapId | The bitmap identifier for the given hand. |
rotationCenterX | The hand rotation center x coordinate. |
rotationCenterY | The hand rotation center y coordinate. |
updateClock
virtual void updateClock | ( | ) |
Update the visual representation of the clock on the display.
Reimplements: touchgfx::AbstractClock::updateClock
Protected Attributes Documentation
animationDuration
uint16_t animationDuration
The duration of hand animations. If 0 animations are disabled.
animationEquation
EasingEquation animationEquation
The easing equation used by hand animations.
background
Image background
The background image of the AnalogClock.
clockRotationCenterX
int16_t clockRotationCenterX
The x coordinate of the rotation point of the hands.
clockRotationCenterY
int16_t clockRotationCenterY
The y coordinate of the rotation point of the hands.
hourHand
AnimationTextureMapper hourHand
TextureMapper used for drawing the hourHand.
hourHandMinuteCorrectionActive
bool hourHandMinuteCorrectionActive
Is hour hand minute correction active.
lastHour
uint8_t lastHour
The last know hour value.
lastMinute
uint8_t lastMinute
The last know minute value.
lastSecond
uint8_t lastSecond
The last know second value.
minuteHand
AnimationTextureMapper minuteHand
TextureMapper used for drawing the minuteHand.
minuteHandSecondCorrectionActive
bool minuteHandSecondCorrectionActive
Is minute hand second correction active.
secondHand
AnimationTextureMapper secondHand
TextureMapper used for drawing the secondHand.