HoverRace  2.0
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
HoverRace::Display::Hud Class Reference

The container for the heads-up display. More...

#include <Hud.h>

+ Inheritance diagram for HoverRace::Display::Hud:

Classes

struct  HudAlignment
 
struct  HudChild
 
class  HudLocProxy
 A reference to a HUD location; useful for adding new HUD elements. More...
 
struct  Props
 

Public Member Functions

 Hud (Display &display, std::shared_ptr< Player::Player > player, std::shared_ptr< Model::Track > track, uiLayoutFlags_t layoutFlags=0)
 Constructor. More...
 
virtual ~Hud ()
 
void Advance (Util::OS::timestamp_t tick)
 
HudLocProxy At (HudAlignment::type alignment)
 Access a HUD location. More...
 
virtual void Clear ()
 Remove all child elements. More...
 
HudCell GetCell () const
 
Model::TrackGetTrack () const
 
void OnScreenSizeChanged ()
 Fired when the screen size changes. More...
 
void SetCell (HudCell cell)
 Set the subsection of the screen where this HUD should be rendered. More...
 
void SetPlayer (std::shared_ptr< Player::Player > player)
 Change the player being targeted by the HUD. More...
 
void SetTrack (std::shared_ptr< Model::Track > track)
 Change the track being played. More...
 
std::shared_ptr< Model::TrackShareTrack () const
 
- Public Member Functions inherited from HoverRace::Display::BaseContainer
 BaseContainer (Display &display, uiLayoutFlags_t layoutFlags=0)
 Constructor for an unsized container without clipping. More...
 
 BaseContainer (Display &display, const Vec2 &size, bool clip=true, uiLayoutFlags_t layoutFlags=0)
 Constructor for a sized container. More...
 
virtual ~BaseContainer ()
 
void AttachView (Display &disp) override
 
template<class Fn >
void ForEachChild (Fn fn) const
 Iterate over each child widget. More...
 
template<class Fn >
void ForEachVisibleChild (Fn fn) const
 Iterate over each visible child widget. More...
 
const Vec2GetChildOffset () const
 Retrieve the offset to the position of the child widgets. More...
 
double GetOpacity () const
 Retrieve the opacity. More...
 
const Vec2GetSize () const
 Retrieve the size of the container. More...
 
bool IsClip () const
 Check if child elements are clipped to the container bounds. More...
 
bool IsEmpty () const
 Check if this container is devoid of child widgets. More...
 
bool IsVisible () const
 Check if the children of this container are shown. More...
 
Vec3 Measure () override
 Calculate the size of the component. More...
 
bool OnMouseMoved (const Vec2 &pos) override
 
bool OnMousePressed (const Control::Mouse::Click &click) override
 
bool OnMouseReleased (const Control::Mouse::Click &click) override
 
bool OnMouseScrolled (const Control::Mouse::Scroll &scroll) override
 
void SetClip (bool clip)
 Set whether child elements are clipped to the container bounds. More...
 
void SetOpacity (double opacity)
 Set the opacity of the container. More...
 
void SetSize (const Vec2 &size)
 Set the size of the container. More...
 
void SetSize (double w, double h)
 Convenience function for SetSize(const Vec2&). More...
 
void SetVisible (bool visible)
 Sets whether the widgets in this container are visible. More...
 
void ShrinkWrap ()
 Resize the container to the minimum size that will fit all of the child elements. More...
 
- Public Member Functions inherited from HoverRace::Display::UiViewModel
 UiViewModel (uiLayoutFlags_t layoutFlags=0)
 
virtual ~UiViewModel ()
 
virtual void DropFocus ()
 Force this widget to give up focus, if it is currently focused. More...
 
Vec2 GetAlignedPos (const Vec2 &pos, double w, double h) const
 Retrieve an arbitrary position adjusted by the current alignment. More...
 
Vec2 GetAlignedPos (double w, double h) const
 Retrieve the position adjusted by the current alignment. More...
 
Alignment GetAlignment () const
 Retrieve the alignment of the component. More...
 
focusRelinquishedSignal_tGetFocusRelinquishedSignal ()
 
focusRequestedSignal_tGetFocusRequestedSignal ()
 
uiLayoutFlags_t GetLayoutFlags () const
 Retrieve the layout flags. More...
 
const Vec2GetPos () const
 Get the position of the component. More...
 
const Vec2GetTranslation () const
 Retrieves the position translation. More...
 
bool IsFocused () const
 Check if this widget currently has input focus. More...
 
uiLayoutFlags_t IsLayoutFloating () const
 
uiLayoutFlags_t IsLayoutUnscaled () const
 
virtual bool OnAction ()
 
virtual bool OnNavigate (const Control::Nav &)
 
void RequestFocus ()
 Attempt to hand over the input focus to this widget. More...
 
void SetAlignment (Alignment alignment)
 Set the alignment of the component. More...
 
void SetPos (const Vec2 &pos)
 Set the position of the component. More...
 
void SetPos (double x, double y)
 Convenience function for SetPos(const Vec2&). More...
 
void SetTranslation (const Vec2 &translation)
 Sets the position translation. More...
 
void SetTranslation (double x, double y)
 Convenience function for SetTranslation(const Vec2&). More...
 
virtual bool TryFocus (const Control::Nav &nav=Control::Nav::NEUTRAL)
 Attempts to give this widget focus. More...
 
- Public Member Functions inherited from HoverRace::Display::ViewModel
 ViewModel ()
 
virtual ~ViewModel ()
 
ViewGetView () const
 
void PrepareRender ()
 
void Render ()
 
void SetView (std::unique_ptr< View > &&view)
 

Protected Member Functions

template<typename Fn >
void ForEachHudChild (Fn fn)
 
virtual void Layout ()
 Adjust the size and position of any child elements. More...
 
- Protected Member Functions inherited from HoverRace::Display::BaseContainer
children_tGetChildren ()
 
template<class T , class... Args>
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type NewChild (Args &&...args)
 Create and append a new child widget to the end of the list. More...
 
virtual void OnChildRelinquishedFocus (UiViewModel &child, const Control::Nav &nav)
 Called when a child widget passes input focus to another widget. More...
 
virtual void OnChildRequestedFocus (UiViewModel &child)
 Called when a child widget requests input focus. More...
 
template<typename T >
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type RemoveChild (const std::shared_ptr< T > &child)
 Remove a child element. More...
 
template<class T >
std::enable_if< std::is_base_of< UiViewModel, T >::value, std::shared_ptr< T > >::type ReorderChild (const std::shared_ptr< T > &child, size_t idx)
 Move a widget to a different position in the list. More...
 
virtual void Reserve (size_t capacity)
 Increase the capacity of the of this container. More...
 
void SetChildOffset (const Vec2 &offset)
 Sets the position offset of child widgets. More...
 
bool TestHit (const Vec2 &pos)
 Check if the coordinates of an event are within the bounds of this component. More...
 
- Protected Member Functions inherited from HoverRace::Display::UiViewModel
void RelinquishFocus (const Control::Nav &nav)
 Voluntarily give up input focus, passing it on to the next widget. More...
 
void SetFocused (bool focused)
 Set the focused state. More...
 
- Protected Member Functions inherited from HoverRace::Display::ViewModel
template<class T >
void AttachViewDynamic (Display &disp, T *self)
 
virtual void FireModelUpdate (int prop)
 Indicate that a model property has changed. More...
 
void RequestLayout ()
 Indicate that the current layout is out-of-date and needs to be adjusted. More...
 

Private Types

typedef std::vector< HudChildhudChildList_t
 
using SUPER = BaseContainer
 

Private Member Functions

void LayoutCorner (HudAlignment::type alignCorner, HudAlignment::type alignH, HudAlignment::type alignV, double startX, double startY, double scaleX, double scaleY)
 
void LayoutStacked (HudAlignment::type align, double startX, double startY, double scaleX, double scaleY)
 
template<class T , class... Args>
std::enable_if< std::is_base_of< HudDecor, T >::value, std::shared_ptr< T > >::type NewHudChild (HudAlignment::type alignment, Args &&...args)
 Append a child element to the end of the list. More...
 

Private Attributes

HudCell cell
 
boost::signals2::scoped_connection displayConfigChangedConn
 
std::array< hudChildList_t, HudAlignment::NUMhudChildren
 
Vec2 hudScale
 
std::shared_ptr< Player::Playerplayer
 
std::shared_ptr< Model::Tracktrack
 

Additional Inherited Members

- Public Types inherited from HoverRace::Display::UiViewModel
enum  Alignment {
  Alignment::NW, Alignment::N, Alignment::NE, Alignment::E,
  Alignment::SE, Alignment::S, Alignment::SW, Alignment::W,
  Alignment::CENTER
}
 Imagine the component pinned to the container with a thumbtack. More...
 
using focusRelinquishedSignal_t = boost::signals2::signal< void(UiViewModel &, const Control::Nav &)>
 
using focusRequestedSignal_t = boost::signals2::signal< void(UiViewModel &)>
 
- Protected Types inherited from HoverRace::Display::BaseContainer
using children_t = std::vector< std::unique_ptr< Child >>
 
- Protected Attributes inherited from HoverRace::Display::BaseContainer
Displaydisplay
 

Detailed Description

The container for the heads-up display.

Author
Michael Imamura

Member Typedef Documentation

typedef std::vector<HudChild> HoverRace::Display::Hud::hudChildList_t
private

Constructor & Destructor Documentation

HoverRace::Display::Hud::Hud ( Display display,
std::shared_ptr< Player::Player player,
std::shared_ptr< Model::Track track,
uiLayoutFlags_t  layoutFlags = 0 
)

Constructor.

Parameters
displayThe display child elements will be attached to.
playerThe target player this HUD is viewing.
trackThe track being played.
layoutFlagsOptional layout flags.
virtual HoverRace::Display::Hud::~Hud ( )
inlinevirtual

Member Function Documentation

void HoverRace::Display::Hud::Advance ( Util::OS::timestamp_t  tick)
HudLocProxy HoverRace::Display::Hud::At ( HudAlignment::type  alignment)
inline

Access a HUD location.

This is usually used to add new widgets to the HUD.

Parameters
alignmentThe HUD location.
Returns
A reference to the location.
virtual void HoverRace::Display::Hud::Clear ( )
inlinevirtual

Remove all child elements.

Reimplemented from HoverRace::Display::BaseContainer.

template<typename Fn >
void HoverRace::Display::Hud::ForEachHudChild ( Fn  fn)
inlineprotected
HudCell HoverRace::Display::Hud::GetCell ( ) const
inline
Model::Track* HoverRace::Display::Hud::GetTrack ( ) const
inline
void HoverRace::Display::Hud::Layout ( )
protectedvirtual

Adjust the size and position of any child elements.

Subclasses with child elements should override this function.

This is called automatically during the PrepareRender() phase if RequestLayout() has been called. It is also called the first time PrepareRender() is invoked. After this function is called, it will not be called again until another call to RequestLayout().

Reimplemented from HoverRace::Display::ViewModel.

void HoverRace::Display::Hud::LayoutCorner ( HudAlignment::type  alignCorner,
HudAlignment::type  alignH,
HudAlignment::type  alignV,
double  startX,
double  startY,
double  scaleX,
double  scaleY 
)
private
void HoverRace::Display::Hud::LayoutStacked ( HudAlignment::type  align,
double  startX,
double  startY,
double  scaleX,
double  scaleY 
)
private
template<class T , class... Args>
std::enable_if< std::is_base_of<HudDecor, T>::value, std::shared_ptr<T> >::type HoverRace::Display::Hud::NewHudChild ( HudAlignment::type  alignment,
Args &&...  args 
)
inlineprivate

Append a child element to the end of the list.

Template Parameters
TThe type of the child widget.
ArgsThe types of the arguments.
Parameters
alignmentWhere to place the child element in the HUD.
argsThe arguments to pass to the child widget's constructor.
Returns
The child element, wrapped in a std::shared_ptr.
void HoverRace::Display::Hud::OnScreenSizeChanged ( )

Fired when the screen size changes.

void HoverRace::Display::Hud::SetCell ( HudCell  cell)

Set the subsection of the screen where this HUD should be rendered.

void HoverRace::Display::Hud::SetPlayer ( std::shared_ptr< Player::Player player)

Change the player being targeted by the HUD.

Parameters
playerThe target player (may be nullptr).
void HoverRace::Display::Hud::SetTrack ( std::shared_ptr< Model::Track track)

Change the track being played.

Parameters
trackThe track (may not be nullptr).
std::shared_ptr<Model::Track> HoverRace::Display::Hud::ShareTrack ( ) const
inline

Member Data Documentation

HudCell HoverRace::Display::Hud::cell
private
boost::signals2::scoped_connection HoverRace::Display::Hud::displayConfigChangedConn
private
std::array<hudChildList_t, HudAlignment::NUM> HoverRace::Display::Hud::hudChildren
private
Vec2 HoverRace::Display::Hud::hudScale
private
std::shared_ptr<Player::Player> HoverRace::Display::Hud::player
private
std::shared_ptr<Model::Track> HoverRace::Display::Hud::track
private

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