PRooFPS-dd Dev Doc 1.0
PRooFPS-dd Developer Documentation
Loading...
Searching...
No Matches
proofps_dd::InOutSlider Class Reference

In/Out Slider GUI Element for PRooFPS-dd. More...

Detailed Description

In/Out Slider GUI Element for PRooFPS-dd.

This class has the slide animation control logic only, does not know about the actual GUI element. The idea is that this can be used as a base for a more specific class that encapsulates the actual GUI element. Therefore, this class can be used for sliding not only PureObject3D instances but also Dear ImGui elements or anything else that can have 2D-coordinates.

See the animation logic described at enum AnimState.

Definition at line 30 of file InOutSlider.h.

#include <InOutSlider.h>

+ Inheritance diagram for proofps_dd::InOutSlider:

Public Types

enum class  AnimState { Finished , SlidingIn , WaitingForTimeout , SlidingOut }
 Initially, the animation is sitting in Finished state. More...
 

Public Member Functions

CConsole & getConsole () const
 
 InOutSlider ()=default
 
virtual ~InOutSlider ()
 
 InOutSlider (const InOutSlider &)=default
 
InOutSlideroperator= (const InOutSlider &)=default
 
 InOutSlider (InOutSlider &&)=default
 
InOutSlideroperator= (InOutSlider &&)=default
 
TXY & getScreenStartPos ()
 The user shall use this function to set the initial position of the slide-in animation.
 
const TXY & getScreenStartPos () const
 
TXY & getScreenFinishPos ()
 The user shall use this function to set the ending position of the slide-in animation.
 
const TXY & getScreenFinishPos () const
 
const TXY & getScreenCurrentPos () const
 
const AnimStategetState () const
 
const std::chrono::milliseconds::rep & getTimeoutInWaitingState () const
 
void setTimeoutInWaitingState (std::chrono::milliseconds::rep millisecs)
 Sets the duration for waiting in WaitingForTimeout state before transitioning to SlidingOut state.
 
void loadSoundForSlidingIn (pge_audio::PgeAudio &audio, const char *szFilename)
 
void show (pge_audio::PgeAudio &audio)
 Starts or resumes the slide-in animation from the Current position towards the Finish position.
 
void hide (pge_audio::PgeAudio &audio, bool forceStopAudio)
 Starts or resumes the slide-out animation from the Current position towards the Start position.
 
virtual void update (pge_audio::PgeAudio &audio)
 Steps the slide animation between the Start and Finish positions.
 
virtual void clear ()
 Frees up any loaded resource, like the sound that can be optionally loaded by loadSoundForSlidingIn().
 

Static Public Member Functions

static const char * getLoggerModuleName ()
 

Protected Member Functions

virtual void stateEntered (const AnimState &, const AnimState &)
 Invoked by stateEnter() after a successful state transition.
 

Private Member Functions

bool stateEnter (pge_audio::PgeAudio &audio, const AnimState &newState, bool forceStopAudio)
 Expected to be invoked only for events, such as explicit call to show(), hide(), or when update() detects an event.
 
void stateUpdate (pge_audio::PgeAudio &audio)
 Expected to be invoked periodically.
 

Private Attributes

TXY m_posScreenStart {}
 
TXY m_posScreenFinish {}
 
TXY m_posScreenTarget {}
 
TXY m_posScreenCurrent {}
 
AnimState m_state { AnimState::Finished }
 
std::chrono::milliseconds::rep m_durationTimeoutMillisecsInWaitingState { 0 }
 
std::chrono::time_point< std::chrono::steady_clock > m_timeEnteredWaitingState
 
SoLoud::Wav * m_sndPlayedInSlidingInState { nullptr }
 

Member Enumeration Documentation

◆ AnimState

Initially, the animation is sitting in Finished state.

The animation can be triggered at the beginning using show().

The animation is transitioning through states by periodic calls to update().

The animation can be instructed to go back to Finished state using hide(), but it will follow the state machine flow to do that gradually.

If a TimeOut is set, then between the SlidingIn and SlidingOut states, the animation will stay in WaitingForTimeout state for the TimeOut duration, otherwise the animation will stay in WaitingForTimeout until an explicit call to hide().

Summary: Therefore, the recommended way of controlling the animation is to always do periodical calls to update(), no need to explicitly check for states. The only additional explicit call that is needed only once is show(). If a TimeOut is set, no need to explicitly call hide().

                                             hide()
                         >--------------------->------------------------------>
                         |                                                     ¡
                         |          update():              update(): timeout,  |         update():
              show()     ^      FinishPos reached                hide()        ¡    FinishPos reached

o--->-> Finished -------> SlidingIn ------------> WaitingForTimeout -------> SlidingOut ---------------> ^ ^ ¡ ^ ¡ ^ ^ ¡ ^ ¡ ¡ ¡ | |hide()| |show()| | |show()| |hide()| | | | ^---—< ^---—< | ^---—< ^---—< | | | | show() | | | ^-----------—<--------------—<--------------—< | | | ^-------—<------------—<------------—<--------------—<-----------------—<--------------—<

Enumerator
Finished 
SlidingIn 
WaitingForTimeout 
SlidingOut 

Definition at line 66 of file InOutSlider.h.

Constructor & Destructor Documentation

◆ InOutSlider() [1/3]

proofps_dd::InOutSlider::InOutSlider ( )
default

◆ ~InOutSlider()

virtual proofps_dd::InOutSlider::~InOutSlider ( )
inlinevirtual

Definition at line 88 of file InOutSlider.h.

◆ InOutSlider() [2/3]

proofps_dd::InOutSlider::InOutSlider ( const InOutSlider & )
default

◆ InOutSlider() [3/3]

proofps_dd::InOutSlider::InOutSlider ( InOutSlider && )
default

Member Function Documentation

◆ clear()

virtual void proofps_dd::InOutSlider::clear ( )
inlinevirtual

Frees up any loaded resource, like the sound that can be optionally loaded by loadSoundForSlidingIn().

Derived classes must extend this method by freeing up their loaded resources as well.

Reimplemented in proofps_dd::PureObject3dInOutSlider.

Definition at line 270 of file InOutSlider.h.

◆ getConsole()

CConsole & proofps_dd::InOutSlider::getConsole ( ) const
inline

Definition at line 81 of file InOutSlider.h.

◆ getLoggerModuleName()

static const char * proofps_dd::InOutSlider::getLoggerModuleName ( )
inlinestatic

Definition at line 74 of file InOutSlider.h.

◆ getScreenCurrentPos()

const TXY & proofps_dd::InOutSlider::getScreenCurrentPos ( ) const
inline
Returns
The current position of the GUI element, controlled by update(), somewhere between the Start and Finish positions.

Definition at line 145 of file InOutSlider.h.

◆ getScreenFinishPos() [1/2]

TXY & proofps_dd::InOutSlider::getScreenFinishPos ( )
inline

The user shall use this function to set the ending position of the slide-in animation.

This Finish position is the initial position in WaitingForTimeout and SlidingOut states. This Finish position is the initial position of the slide-out animation.

Returns
The ending position of the GUI element, to where it will slide in from the Start position.

Definition at line 129 of file InOutSlider.h.

◆ getScreenFinishPos() [2/2]

const TXY & proofps_dd::InOutSlider::getScreenFinishPos ( ) const
inline
Returns
The ending position of the GUI element, to where it will slide in from the Start position.

Definition at line 137 of file InOutSlider.h.

◆ getScreenStartPos() [1/2]

TXY & proofps_dd::InOutSlider::getScreenStartPos ( )
inline

The user shall use this function to set the initial position of the slide-in animation.

This Start position is the initial position in Finished and SlidingIn states. This Start position is the ending position of the slide-out animation.

Returns
The initial position of the GUI element, from where it will slide in towards the Finish position.

Definition at line 109 of file InOutSlider.h.

◆ getScreenStartPos() [2/2]

const TXY & proofps_dd::InOutSlider::getScreenStartPos ( ) const
inline
Returns
The initial position of the GUI element, from where it will slide in towards the Finish position.

Definition at line 117 of file InOutSlider.h.

◆ getState()

const AnimState & proofps_dd::InOutSlider::getState ( ) const
inline
Returns
The current animation state, controlled by show(), hide() and update().

Definition at line 153 of file InOutSlider.h.

◆ getTimeoutInWaitingState()

const std::chrono::milliseconds::rep & proofps_dd::InOutSlider::getTimeoutInWaitingState ( ) const
inline
Returns
The duration of waiting in milliseconds in WaitingForTimeout state before transitioning to SlidingOut state.

Definition at line 161 of file InOutSlider.h.

◆ hide()

void proofps_dd::InOutSlider::hide ( pge_audio::PgeAudio & audio,
bool forceStopAudio )
inline

Starts or resumes the slide-out animation from the Current position towards the Start position.

No visible effect if the animation is already in SlidingOut or Finished state.

A periodical call to update() is required to eventually reach the Start position. It is advised to call hide() only when you want to start the slide-out animation.

If current state is WaitingForTimeout, we are transitioning to SlidingOut even if a non-zero timeout duration is not yet elapsed.

Parameters
forceStopAudioSet it to true to immediately stop the optionally playing audio that was previously loaded by loadSoundForSlidingIn().

Definition at line 239 of file InOutSlider.h.

◆ loadSoundForSlidingIn()

void proofps_dd::InOutSlider::loadSoundForSlidingIn ( pge_audio::PgeAudio & audio,
const char * szFilename )
inline

Definition at line 184 of file InOutSlider.h.

◆ operator=() [1/2]

InOutSlider & proofps_dd::InOutSlider::operator= ( const InOutSlider & )
default

◆ operator=() [2/2]

InOutSlider & proofps_dd::InOutSlider::operator= ( InOutSlider && )
default

◆ setTimeoutInWaitingState()

void proofps_dd::InOutSlider::setTimeoutInWaitingState ( std::chrono::milliseconds::rep millisecs)
inline

Sets the duration for waiting in WaitingForTimeout state before transitioning to SlidingOut state.

Setting 0 means waiting in WaitingForTimeout state without time limit, until an explicit call to hide().

Parameters
millisecsThe duration expressed in milliseconds for waiting in WaitingForTimeout state.

Definition at line 173 of file InOutSlider.h.

◆ show()

void proofps_dd::InOutSlider::show ( pge_audio::PgeAudio & audio)
inline

Starts or resumes the slide-in animation from the Current position towards the Finish position.

No visible effect if the animation is already in SlidingIn or WaitingForTimeout state.

A periodical call to update() is required to eventually reach the Finish position. It is advised to call show() only when you want to start the slide-in animation.

Definition at line 209 of file InOutSlider.h.

◆ stateEnter()

bool proofps_dd::InOutSlider::stateEnter ( pge_audio::PgeAudio & audio,
const AnimState & newState,
bool forceStopAudio )
inlineprivate

Expected to be invoked only for events, such as explicit call to show(), hide(), or when update() detects an event.

Definition at line 303 of file InOutSlider.h.

◆ stateEntered()

virtual void proofps_dd::InOutSlider::stateEntered ( const AnimState & ,
const AnimState &  )
inlineprotectedvirtual

Invoked by stateEnter() after a successful state transition.

Reimplemented in proofps_dd::PureObject3dInOutSlider.

Definition at line 284 of file InOutSlider.h.

◆ stateUpdate()

void proofps_dd::InOutSlider::stateUpdate ( pge_audio::PgeAudio & audio)
inlineprivate

Expected to be invoked periodically.

Definition at line 377 of file InOutSlider.h.

◆ update()

virtual void proofps_dd::InOutSlider::update ( pge_audio::PgeAudio & audio)
inlinevirtual

Steps the slide animation between the Start and Finish positions.

Direction and speed depends on the Current position and the SlidingIn state. Derived class may extend this function by using the updated Current position.

Reimplemented in proofps_dd::PureObject3dInOutSlider.

Definition at line 261 of file InOutSlider.h.

Member Data Documentation

◆ m_durationTimeoutMillisecsInWaitingState

std::chrono::milliseconds::rep proofps_dd::InOutSlider::m_durationTimeoutMillisecsInWaitingState { 0 }
private

Definition at line 294 of file InOutSlider.h.

◆ m_posScreenCurrent

TXY proofps_dd::InOutSlider::m_posScreenCurrent {}
private

Definition at line 292 of file InOutSlider.h.

◆ m_posScreenFinish

TXY proofps_dd::InOutSlider::m_posScreenFinish {}
private

Definition at line 290 of file InOutSlider.h.

◆ m_posScreenStart

TXY proofps_dd::InOutSlider::m_posScreenStart {}
private

Definition at line 289 of file InOutSlider.h.

◆ m_posScreenTarget

TXY proofps_dd::InOutSlider::m_posScreenTarget {}
private

Definition at line 291 of file InOutSlider.h.

◆ m_sndPlayedInSlidingInState

SoLoud::Wav* proofps_dd::InOutSlider::m_sndPlayedInSlidingInState { nullptr }
private

Definition at line 296 of file InOutSlider.h.

◆ m_state

AnimState proofps_dd::InOutSlider::m_state { AnimState::Finished }
private

Definition at line 293 of file InOutSlider.h.

◆ m_timeEnteredWaitingState

std::chrono::time_point<std::chrono::steady_clock> proofps_dd::InOutSlider::m_timeEnteredWaitingState
private

Definition at line 295 of file InOutSlider.h.


The documentation for this class was generated from the following file: