Add Inter Fonts

This commit is contained in:
2024-06-12 13:27:38 +02:00
parent b0ef96e390
commit 51f6fa6014
631 changed files with 117874 additions and 2514 deletions

View File

@ -0,0 +1,75 @@
/******************************************************************************
* Copyright (c) 2018(-2023) STMicroelectronics.
* All rights reserved.
*
* This file is part of the TouchGFX 4.22.0 distribution.
*
* This software is licensed under terms that can be found in the LICENSE file in
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*******************************************************************************/
/**
* @file touchgfx/mixins/ClickListener.hpp
*
* Declares the touchgfx::ClickListener class.
*/
#ifndef TOUCHGFX_CLICKLISTENER_HPP
#define TOUCHGFX_CLICKLISTENER_HPP
#include <touchgfx/Callback.hpp>
#include <touchgfx/events/ClickEvent.hpp>
namespace touchgfx
{
/**
* Mix-in class that extends a class with a click action event that is called when the class
* receives a click event.
*
* @tparam T specifies the type to extend with the ClickListener behavior.
*/
template <class T>
class ClickListener : public T
{
public:
/** Initializes a new instance of the ClickListener class. Make the object touchable. */
ClickListener()
: T(), clickAction(0)
{
T::setTouchable(true);
}
/**
* Ensures that the clickEvent is propagated to the super class T and to the clickAction
* listener.
*
* @param event Information about the click.
*/
virtual void handleClickEvent(const ClickEvent& event)
{
T::handleClickEvent(event);
if (clickAction && clickAction->isValid())
{
clickAction->execute(*this, event);
}
}
/**
* Associates an action to be performed when the class T is clicked.
*
* @param callback The callback to be executed. The callback will be given a reference
* to T.
*/
void setClickAction(GenericCallback<const T&, const ClickEvent&>& callback)
{
clickAction = &callback;
}
protected:
GenericCallback<const T&, const ClickEvent&>* clickAction; ///< The callback to be executed when T is clicked
};
} // namespace touchgfx
#endif // TOUCHGFX_CLICKLISTENER_HPP

View File

@ -0,0 +1,57 @@
/******************************************************************************
* Copyright (c) 2018(-2023) STMicroelectronics.
* All rights reserved.
*
* This file is part of the TouchGFX 4.22.0 distribution.
*
* This software is licensed under terms that can be found in the LICENSE file in
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*******************************************************************************/
/**
* @file touchgfx/mixins/Draggable.hpp
*
* Declares the touchgfx::Draggable class.
*/
#ifndef TOUCHGFX_DRAGGABLE_HPP
#define TOUCHGFX_DRAGGABLE_HPP
#include <touchgfx/events/DragEvent.hpp>
namespace touchgfx
{
/**
* Mix-in class that extends a class to become Draggable, which means that the object on screen
* can be freely moved around using the touch screen.
*
* @tparam T specifies the type to extend with the Draggable behavior.
*/
template <class T>
class Draggable : public T
{
public:
/** Initializes a new instance of the Draggable class. Make the object touchable. */
Draggable()
: T()
{
T::setTouchable(true);
}
/**
* Called when dragging the Draggable object. The object is moved according to the drag
* event.
*
* @param event The drag event.
*/
virtual void handleDragEvent(const DragEvent& event)
{
T::handleDragEvent(event);
T::moveRelative(event.getDeltaX(), event.getDeltaY());
}
};
} // namespace touchgfx
#endif // TOUCHGFX_DRAGGABLE_HPP

View File

@ -0,0 +1,222 @@
/******************************************************************************
* Copyright (c) 2018(-2023) STMicroelectronics.
* All rights reserved.
*
* This file is part of the TouchGFX 4.22.0 distribution.
*
* This software is licensed under terms that can be found in the LICENSE file in
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*******************************************************************************/
/**
* @file touchgfx/mixins/FadeAnimator.hpp
*
* Declares the touchgfx::FadeAnimator class.
*/
#ifndef TOUCHGFX_FADEANIMATOR_HPP
#define TOUCHGFX_FADEANIMATOR_HPP
#include <touchgfx/Application.hpp>
#include <touchgfx/Callback.hpp>
#include <touchgfx/EasingEquations.hpp>
#include <touchgfx/hal/Types.hpp>
namespace touchgfx
{
/**
* A FadeAnimator makes the template class T able to animate the alpha value from its current
* value to a specified end value. It is possible to use a fade in effect as well as
* fade out effect using FadeAnimator. The alpha progression can be described by
* supplying an EasingEquation. The FadeAnimator performs a callback when the animation
* has finished.
*
* This mixin can be used on any Drawable that has a 'void setAlpha(uint8_t)' and a
* 'uint8_t getAlpha()' method.
*
* @tparam T specifies the type to extend with the FadeAnimator behavior.
*/
template <class T>
class FadeAnimator : public T
{
public:
FadeAnimator()
: T(),
fadeAnimationRunning(false),
fadeAnimationCounter(0),
fadeAnimationDelay(0),
fadeAnimationEndedCallback(0)
{
}
/**
* Associates an action to be performed when the animation ends.
*
* @param callback The callback to be executed. The callback will be given a reference
* to the FadeAnimator.
*/
void setFadeAnimationEndedAction(GenericCallback<const FadeAnimator<T>&>& callback)
{
fadeAnimationEndedCallback = &callback;
}
/**
* Clears the fade animation ended action previously set by setFadeAnimationEndedAction.
*
* Clears the fade animation ended action previously set by setFadeAnimationEndedAction.
*
* @see setFadeAnimationEndedAction
*/
void clearFadeAnimationEndedAction()
{
fadeAnimationEndedCallback = 0;
}
/**
* Sets a delay before the actual animation starts for the animation done by the
* FadeAnimator.
*
* @param delay The delay in ticks.
*
* @see getFadeAnimationDelay
*/
virtual void setFadeAnimationDelay(uint16_t delay)
{
fadeAnimationDelay = delay;
}
/**
* Gets the current animation delay.
*
* @return The current animation delay.
*
* @see setFadeAnimationDelay
*/
virtual uint16_t getFadeAnimationDelay() const
{
return fadeAnimationDelay;
}
/**
* Gets whether or not the fade animation is running.
*
* @return true if the fade animation is running.
*/
bool isFadeAnimationRunning() const
{
return fadeAnimationRunning;
}
/**
* Starts the fade animation from the current alpha value to the specified end alpha
* value. The progression of the alpha value during the animation is described by the
* supplied EasingEquation.
*
* @param endAlpha The alpha value of T at animation end.
* @param duration The duration of the animation measured in ticks.
* @param alphaProgressionEquation (Optional) The equation that describes the
* development of the alpha value during the animation.
* Default is EasingEquations::linearEaseNone.
*/
void startFadeAnimation(uint8_t endAlpha, uint16_t duration, EasingEquation alphaProgressionEquation = &EasingEquations::linearEaseNone)
{
if (!fadeAnimationRunning)
{
Application::getInstance()->registerTimerWidget(this);
}
fadeAnimationCounter = 0;
fadeAnimationStartAlpha = T::getAlpha();
fadeAnimationEndAlpha = endAlpha;
fadeAnimationDuration = duration;
fadeAnimationAlphaEquation = alphaProgressionEquation;
fadeAnimationRunning = true;
if (fadeAnimationDelay == 0 && fadeAnimationDuration == 0)
{
nextFadeAnimationStep(); // Set end alpha and shut down
}
}
/**
* Cancel fade animation. The animation is stopped and the alpha value is left where it
* currently is.
*/
void cancelFadeAnimation()
{
if (fadeAnimationRunning)
{
Application::getInstance()->unregisterTimerWidget(this);
fadeAnimationRunning = false;
}
}
/** @copydoc Drawable::handleTickEvent */
virtual void handleTickEvent()
{
T::handleTickEvent();
nextFadeAnimationStep();
}
protected:
/** Execute next step in fade animation and stop the timer if necessary. */
void nextFadeAnimationStep()
{
if (fadeAnimationRunning)
{
fadeAnimationCounter++;
if (fadeAnimationCounter >= fadeAnimationDelay)
{
// Adjust the used animationCounter for the startup delay
uint32_t actualAnimationCounter = fadeAnimationCounter - fadeAnimationDelay;
int16_t newAlpha = fadeAnimationStartAlpha + (int16_t)fadeAnimationAlphaEquation(actualAnimationCounter, 0, fadeAnimationEndAlpha - fadeAnimationStartAlpha, fadeAnimationDuration);
if (T::getAlpha() != newAlpha)
{
if (newAlpha == 0)
{
// InvalidateContent before it becomes invisible
T::invalidateContent();
T::setAlpha((uint8_t)newAlpha);
}
else
{
// InvalidateContent after we are sure that it is visible
T::setAlpha((uint8_t)newAlpha);
T::invalidateContent();
}
}
if (fadeAnimationCounter >= (uint32_t)(fadeAnimationDelay + fadeAnimationDuration))
{
// End of animation
fadeAnimationRunning = false;
fadeAnimationDuration = 0;
Application::getInstance()->unregisterTimerWidget(this);
if (fadeAnimationEndedCallback && fadeAnimationEndedCallback->isValid())
{
fadeAnimationEndedCallback->execute(*this);
}
}
}
}
}
bool fadeAnimationRunning; ///< True if the animation is running.
uint16_t fadeAnimationCounter; ///< To the current step in the animation
uint16_t fadeAnimationDelay; ///< A delay that is applied before animation start. Expressed in ticks.
uint16_t fadeAnimationDuration; ///< The complete duration of the animation. Expressed in ticks.
int16_t fadeAnimationStartAlpha; ///< The alpha value at the beginning of the animation.
int16_t fadeAnimationEndAlpha; ///< The alpha value at the end of the animation.
EasingEquation fadeAnimationAlphaEquation; ///< EasingEquation expressing the progression of the alpha value during the animation.
GenericCallback<const FadeAnimator<T>&>* fadeAnimationEndedCallback; ///< Animation ended Callback.
};
} // namespace touchgfx
#endif // TOUCHGFX_FADEANIMATOR_HPP

View File

@ -0,0 +1,224 @@
/******************************************************************************
* Copyright (c) 2018(-2023) STMicroelectronics.
* All rights reserved.
*
* This file is part of the TouchGFX 4.22.0 distribution.
*
* This software is licensed under terms that can be found in the LICENSE file in
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*******************************************************************************/
/**
* @file touchgfx/mixins/MoveAnimator.hpp
*
* Declares the touchgfx::MoveAnimator class.
*/
#ifndef TOUCHGFX_MOVEANIMATOR_HPP
#define TOUCHGFX_MOVEANIMATOR_HPP
#include <touchgfx/Application.hpp>
#include <touchgfx/Callback.hpp>
#include <touchgfx/EasingEquations.hpp>
#include <touchgfx/hal/Types.hpp>
namespace touchgfx
{
/**
* A MoveAnimator makes the template class T able to animate a movement from its current
* position to a specified end position. The speed of the movement in both the X and Y
* direction can be controlled by supplying EasingEquations. The MoveAnimator performs a
* callback when the animation has finished.
*
* This mixin can be used on any Drawable.
*/
template <class T>
class MoveAnimator : public T
{
public:
MoveAnimator()
: T(),
moveAnimationRunning(false),
moveAnimationCounter(0),
moveAnimationDelay(0),
moveAnimationDuration(0),
moveAnimationStartX(0),
moveAnimationStartY(0),
moveAnimationEndX(0),
moveAnimationEndY(0),
moveAnimationXEquation(),
moveAnimationYEquation(),
moveAnimationEndedCallback(0)
{
}
/**
* Associates an action to be performed when the animation ends.
*
* @param callback The callback to be executed. The callback will be given a reference
* to the MoveAnimator.
*
* @see clearMoveAnimationEndedAction
*/
void setMoveAnimationEndedAction(GenericCallback<const MoveAnimator<T>&>& callback)
{
moveAnimationEndedCallback = &callback;
}
/**
* Clears the move animation ended action previously set by setMoveAnimationEndedAction.
* The effect is that any action set using setMoveAnimationEndedAction() will not be
* executed.
*
* @see setMoveAnimationEndedAction
*/
void clearMoveAnimationEndedAction()
{
moveAnimationEndedCallback = 0;
}
/**
* Sets a delay on animations done by the MoveAnimator.
*
* @param delay The delay in ticks.
*
* @see getMoveAnimationDelay
*/
virtual void setMoveAnimationDelay(uint16_t delay)
{
moveAnimationDelay = delay;
}
/**
* Gets the current animation delay.
*
* @return The current animation delay.
*
* @see setMoveAnimationDelay
*/
virtual uint16_t getMoveAnimationDelay() const
{
return moveAnimationDelay;
}
/**
* Gets whether or not the move animation is running.
*
* @return true if the move animation is running.
*/
bool isMoveAnimationRunning() const
{
return moveAnimationRunning;
}
/**
* Starts the move animation from the current position to the specified end position.
* The development of the position (X, Y) during the animation is described by the
* supplied EasingEquations. If no easing equation is given, the movement is performed
* linear.
*
* @param endX The X position at animation end.
* @param endY The Y position at animation end.
* @param duration The duration of the animation measured in ticks.
* @param xProgressionEquation (Optional) The equation that describes the development of the
* X position during the animation. Default is
* EasingEquations::linearEaseNone.
* @param yProgressionEquation (Optional) The equation that describes the development of the
* Y position during the animation. Default is
* EasingEquations::linearEaseNone.
*/
void startMoveAnimation(int16_t endX, int16_t endY, uint16_t duration, EasingEquation xProgressionEquation = &EasingEquations::linearEaseNone, EasingEquation yProgressionEquation = &EasingEquations::linearEaseNone)
{
if (!moveAnimationRunning)
{
Application::getInstance()->registerTimerWidget(this);
}
moveAnimationCounter = 0;
moveAnimationStartX = T::getX();
moveAnimationStartY = T::getY();
moveAnimationEndX = endX;
moveAnimationEndY = endY;
moveAnimationDuration = duration;
moveAnimationXEquation = xProgressionEquation;
moveAnimationYEquation = yProgressionEquation;
moveAnimationRunning = true;
if (moveAnimationDelay == 0 && moveAnimationDuration == 0)
{
nextMoveAnimationStep(); // Set end position and shut down
}
}
/**
* Cancel move animation and leave the Drawable in its current position. If the
* animation is not running, nothing is done.
*/
void cancelMoveAnimation()
{
if (moveAnimationRunning)
{
Application::getInstance()->unregisterTimerWidget(this);
moveAnimationRunning = false;
}
}
/** The tick handler that handles the actual animation steps. */
virtual void handleTickEvent()
{
T::handleTickEvent();
nextMoveAnimationStep();
}
protected:
/** Execute next step in move animation and stop the timer if the animation has finished. */
void nextMoveAnimationStep()
{
if (moveAnimationRunning)
{
moveAnimationCounter++;
if (moveAnimationCounter >= moveAnimationDelay)
{
// Adjust the used animationCounter for the startup delay
uint32_t actualAnimationCounter = moveAnimationCounter - moveAnimationDelay;
int16_t deltaX = moveAnimationXEquation(actualAnimationCounter, 0, moveAnimationEndX - moveAnimationStartX, moveAnimationDuration);
int16_t deltaY = moveAnimationYEquation(actualAnimationCounter, 0, moveAnimationEndY - moveAnimationStartY, moveAnimationDuration);
T::moveTo(moveAnimationStartX + deltaX, moveAnimationStartY + deltaY);
if (moveAnimationCounter >= (uint32_t)(moveAnimationDelay + moveAnimationDuration))
{
// End of animation
moveAnimationRunning = false;
moveAnimationCounter = 0;
Application::getInstance()->unregisterTimerWidget(this);
if (moveAnimationEndedCallback && moveAnimationEndedCallback->isValid())
{
moveAnimationEndedCallback->execute(*this);
}
}
}
}
}
bool moveAnimationRunning; ///< True if the animation is running
uint16_t moveAnimationCounter; ///< Counter that is equal to the current step in the animation
uint16_t moveAnimationDelay; ///< The delay applied before animation start. Expressed in ticks.
uint16_t moveAnimationDuration; ///< The complete duration of the actual animation. Expressed in ticks.
int16_t moveAnimationStartX; ///< The X value at the beginning of the animation.
int16_t moveAnimationStartY; ///< The Y value at the beginning of the animation.
int16_t moveAnimationEndX; ///< The X value at the end of the animation.
int16_t moveAnimationEndY; ///< The Y value at the end of the animation.
EasingEquation moveAnimationXEquation; ///< EasingEquation expressing the development of the X value during the animation.
EasingEquation moveAnimationYEquation; ///< EasingEquation expressing the development of the Y value during the animation.
GenericCallback<const MoveAnimator<T>&>* moveAnimationEndedCallback; ///< Animation ended Callback.
};
} // namespace touchgfx
#endif // TOUCHGFX_MOVEANIMATOR_HPP

View File

@ -0,0 +1,133 @@
/******************************************************************************
* Copyright (c) 2018(-2023) STMicroelectronics.
* All rights reserved.
*
* This file is part of the TouchGFX 4.22.0 distribution.
*
* This software is licensed under terms that can be found in the LICENSE file in
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
*******************************************************************************/
/**
* @file touchgfx/mixins/Snapper.hpp
*
* Declares the touchgfx::Snapper class.
*/
#ifndef TOUCHGFX_SNAPPER_HPP
#define TOUCHGFX_SNAPPER_HPP
#include <touchgfx/Callback.hpp>
#include <touchgfx/events/ClickEvent.hpp>
#include <touchgfx/events/DragEvent.hpp>
#include <touchgfx/hal/Types.hpp>
#include <touchgfx/mixins/Draggable.hpp>
namespace touchgfx
{
/**
* A mix-in that will make class T draggable and able to snap to a position when a drag
* operation has ended. The mix-in is able to perform callbacks when the snapper gets
* dragged and when the Snapper snaps to its snap position.
*
* @see Draggable<T>
*
* @tparam T specifies the type to enable the Snap behavior to.
*/
template <class T>
class Snapper : public Draggable<T>
{
public:
Snapper()
: Draggable<T>(), snapPositionX(0), snapPositionY(0), dragAction(0), snappedAction(0)
{
}
virtual void handleDragEvent(const DragEvent& event)
{
Draggable<T>::handleDragEvent(event);
if (dragAction && dragAction->isValid())
{
dragAction->execute(event);
}
}
/**
* Handles the click events when the Snapper is clicked. It saves its current position
* as the snap position if the Snapper is pressed. This happens when the drag operation
* starts.
*
* The snapper will then move to the snap position when the click is released. This
* happens when the drag operation ends.
*
* @param event The click event.
*/
virtual void handleClickEvent(const ClickEvent& event)
{
T::handleClickEvent(event);
if (event.getType() == ClickEvent::RELEASED)
{
if (snappedAction && snappedAction->isValid())
{
snappedAction->execute();
}
T::moveTo(snapPositionX, snapPositionY);
}
else if (event.getType() == ClickEvent::PRESSED)
{
snapPositionX = T::getX();
snapPositionY = T::getY();
}
}
/**
* Sets the position the Snapper should snap to. This position will be overridden with
* the Snappers current position when the Snapper is pressed.
*
* @param x The x coordinate.
* @param y The y coordinate.
*/
void setSnapPosition(int16_t x, int16_t y)
{
snapPositionX = x;
snapPositionY = y;
}
/**
* Associates an action to be performed when the Snapper is dragged.
*
* @param callback The callback will be executed with the DragEvent.
*
* @see GenericCallback
*/
void setDragAction(GenericCallback<const DragEvent&>& callback)
{
dragAction = &callback;
}
/**
* Associates an action to be performed when the Snapper is snapped.
*
* @param [in] callback The callback to be executed on snap.
*
* @see GenericCallback
*/
void setSnappedAction(GenericCallback<>& callback)
{
snappedAction = &callback;
}
private:
int16_t snapPositionX;
int16_t snapPositionY;
GenericCallback<const DragEvent&>* dragAction;
GenericCallback<>* snappedAction;
};
} // namespace touchgfx
#endif // TOUCHGFX_SNAPPER_HPP