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

SDL-based software rendering. More...

#include <SdlDisplay.h>

+ Inheritance diagram for HoverRace::Display::SDL::SdlDisplay:

Public Member Functions

 SdlDisplay (const std::string &windowTitle="")
 Constructor. More...
 
virtual ~SdlDisplay ()
 
void AttachView (ActiveText &model) override
 Attach the display-specific view. More...
 
void AttachView (BaseContainer &model) override
 Attach the display-specific view. More...
 
void AttachView (Button &model) override
 Attach the display-specific view. More...
 
void AttachView (ClickRegion &model) override
 Attach the display-specific view. More...
 
void AttachView (FillBox &model) override
 Attach the display-specific view. More...
 
void AttachView (KeycapIcon &model) override
 Attach the display-specific view. More...
 
void AttachView (Label &model) override
 Attach the display-specific view. More...
 
void AttachView (Picture &model) override
 Attach the display-specific view. More...
 
void AttachView (RuleLine &model) override
 Attach the display-specific view. More...
 
void AttachView (ScreenFade &model) override
 Attach the display-specific view. More...
 
void AttachView (Slider &model) override
 Attach the display-specific view. More...
 
void AttachView (SymbolIcon &model) override
 Attach the display-specific view. More...
 
void AttachView (Wallpaper &model) override
 Attach the display-specific view. More...
 
void DrawUiTexture (SDL_Texture *texture, const Vec2 &relPos, uiLayoutFlags_t layoutFlags=0)
 Blit an SDL texture to the backbuffer with the current layout state. More...
 
void DrawUiTexture (SDL_Texture *texture, const Vec2 &relPos, const Vec2 &scale, uiLayoutFlags_t layoutFlags=0)
 Blit a scaled SDL texture to the backbuffer with the current layout state. More...
 
void Flip () override
 Rendering for the frame has completed; update the screen. More...
 
VideoServices::VideoBufferGetLegacyDisplay () const override
 Retrieve the legacy (8-bit) framebuffer. More...
 
SDL_Renderer * GetRenderer () const
 
int GetScreenHeight () const
 
int GetScreenWidth () const
 
SDL_Window * GetWindow () const
 
std::shared_ptr< SdlTextureLoadRes (std::shared_ptr< Res< Texture >> res)
 Loads a texture resource. More...
 
TTF_Font * LoadTtfFont (const UiFont &font, bool uiScale=true)
 Load the TTF font for a given name and size. More...
 
void OnDesktopModeChanged (int width, int height) override
 Reconfigure the display when the desktop resolution has changed. More...
 
void OnDisplayConfigChanged () override
 Reconfigure the display based on the new configuration. More...
 
void Screenshot () override
 Take a screenshot. More...
 
- Public Member Functions inherited from HoverRace::Display::Display
 Display ()
 
virtual ~Display ()
 
uiLayoutFlags_t AddUiLayoutFlags (uiLayoutFlags_t flags) noexcept
 Combine the current UI layout flags with new flags. More...
 
Vec2 AddUiOrigin (const Vec2 &vec) noexcept
 Shift the current UI origin coordinates by an offset. More...
 
void CleanTypeCaseCache ()
 Clean up the cache of TypeCase instances. More...
 
displayConfigChangedSignal_tGetDisplayConfigChangedSignal ()
 
std::shared_ptr< TypeCaseGetTypeCase (const UiFont &font)
 Retrieve or create the TypeCase for a particular font. More...
 
const Vec2GetUiOffset () const noexcept
 
const Vec2GetUiOrigin () const noexcept
 Retrieve the current UI origin coordinates. More...
 
double GetUiScale () const noexcept
 
uiScaleChangedSignal_tGetUiScaleChangedSignal ()
 
const Vec2GetUiScreenSize () const noexcept
 Retrieve the dimensions of the screen, in UI coordinates. More...
 
Vec2 LayoutUiPosition (const Vec2 &relPos, uiLayoutFlags_t layoutFlags=0) noexcept
 
void SetUiLayoutFlags (uiLayoutFlags_t flags) noexcept
 Explicitly set the current UI layout flags. More...
 
void SetUiOrigin (const Vec2 &vec) noexcept
 Explicitly set the UI origin coordinates. More...
 

Protected Member Functions

std::shared_ptr< TypeCaseMakeTypeCase (const UiFont &font) override
 Create a new TypeCase for a given font. More...
 
- Protected Member Functions inherited from HoverRace::Display::Display
void FireDisplayConfigChangedSignal (int width, int height) const
 
void FireUiScaleChangedSignal (double scale) const
 

Private Types

using loadedFontKey = std::pair< std::string, int >
 
using loadedFonts_t = std::map< loadedFontKey, TTF_Font * >
 
using SUPER = Display
 

Private Member Functions

void ApplyVideoMode ()
 Apply the current video configuration to the display. More...
 

Private Attributes

int height
 
VideoServices::VideoBufferlegacyDisplay
 
loadedFonts_t loadedFonts
 
SDL_Renderer * renderer
 
int width
 
SDL_Window * window
 
std::string windowTitle
 

Additional Inherited Members

- Public Types inherited from HoverRace::Display::Display
using displayConfigChangedSignal_t = boost::signals2::signal< void(int, int)>
 
using uiScaleChangedSignal_t = boost::signals2::signal< void(double)>
 
- Public Attributes inherited from HoverRace::Display::Display
Styles styles
 

Detailed Description

SDL-based software rendering.

Author
Michael Imamura

Member Typedef Documentation

using HoverRace::Display::SDL::SdlDisplay::loadedFontKey = std::pair<std::string, int>
private

Constructor & Destructor Documentation

HoverRace::Display::SDL::SdlDisplay::SdlDisplay ( const std::string &  windowTitle = "")

Constructor.

This will create a new window with the specified title. Initial size and position will be pulled from the Config.

Parameters
windowTitleThe window title.
HoverRace::Display::SDL::SdlDisplay::~SdlDisplay ( )
virtual

Member Function Documentation

void HoverRace::Display::SDL::SdlDisplay::ApplyVideoMode ( )
private

Apply the current video configuration to the display.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( ActiveText model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< ActiveText >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( BaseContainer model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< BaseContainer >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( Button model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< Button >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( ClickRegion model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< ClickRegion >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( FillBox model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< FillBox >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( KeycapIcon model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< KeycapIcon >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( Label model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< Label >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( Picture model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< Picture >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( RuleLine model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< RuleLine >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( ScreenFade model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< ScreenFade >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( Slider model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< Slider >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( SymbolIcon model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< SymbolIcon >.

void HoverRace::Display::SDL::SdlDisplay::AttachView ( Wallpaper model)
overridevirtual

Attach the display-specific view.

Parameters
modelThe view model.

Implements HoverRace::Display::ViewAttacher< Wallpaper >.

void HoverRace::Display::SDL::SdlDisplay::DrawUiTexture ( SDL_Texture *  texture,
const Vec2 relPos,
uiLayoutFlags_t  layoutFlags = 0 
)

Blit an SDL texture to the backbuffer with the current layout state.

Parameters
textureThe texture to blit (may be NULL).
relPosThe UI-space position, relative to the current UI origin.
layoutFlagsOptional layout flags, from the view model.
void HoverRace::Display::SDL::SdlDisplay::DrawUiTexture ( SDL_Texture *  texture,
const Vec2 relPos,
const Vec2 scale,
uiLayoutFlags_t  layoutFlags = 0 
)

Blit a scaled SDL texture to the backbuffer with the current layout state.

Parameters
textureThe texture to blit (may be NULL).
relPosThe UI-space position, relative to the current UI origin.
scaleThe scaling to apply to the texture.
layoutFlagsOptional layout flags, from the view model.
void HoverRace::Display::SDL::SdlDisplay::Flip ( )
overridevirtual

Rendering for the frame has completed; update the screen.

Implements HoverRace::Display::Display.

VideoServices::VideoBuffer& HoverRace::Display::SDL::SdlDisplay::GetLegacyDisplay ( ) const
inlineoverridevirtual

Retrieve the legacy (8-bit) framebuffer.

The legacy framebuffer provides an 8-bit surface for drawing. This framebuffer is drawn as the background layer since it doesn't have an alpha channel.

Returns
The framebuffer.

Implements HoverRace::Display::Display.

SDL_Renderer* HoverRace::Display::SDL::SdlDisplay::GetRenderer ( ) const
inline
int HoverRace::Display::SDL::SdlDisplay::GetScreenHeight ( ) const
inline
int HoverRace::Display::SDL::SdlDisplay::GetScreenWidth ( ) const
inline
SDL_Window* HoverRace::Display::SDL::SdlDisplay::GetWindow ( ) const
inline
std::shared_ptr< SdlTexture > HoverRace::Display::SDL::SdlDisplay::LoadRes ( std::shared_ptr< Res< Texture >>  res)

Loads a texture resource.

Parameters
resThe resource (may be nullptr).
Returns
The loaded resource.
Exceptions
ResLoadExn
TTF_Font * HoverRace::Display::SDL::SdlDisplay::LoadTtfFont ( const UiFont font,
bool  uiScale = true 
)

Load the TTF font for a given name and size.

The font is cached for future retrievals.

Parameters
fontThe font specification.
uiScaleApply the user-selected scaling. False is useful if scaling will be applied later.
Returns
The loaded SDL_ttf font (never nullptr).
Exceptions
HoverRace::ExceptionThe font could not be loaded.
std::shared_ptr< TypeCase > HoverRace::Display::SDL::SdlDisplay::MakeTypeCase ( const UiFont font)
overrideprotectedvirtual

Create a new TypeCase for a given font.

This is called by GetTypeCase() when the TypeCase is not in the cache.

Parameters
fontThe normalized font.
Returns
The TypeCase, never nullptr.

Implements HoverRace::Display::Display.

void HoverRace::Display::SDL::SdlDisplay::OnDesktopModeChanged ( int  width,
int  height 
)
overridevirtual

Reconfigure the display when the desktop resolution has changed.

This should be called whenever the desktop resolution changes, so the aspect ratio can be maintained in windowed mode.

Parameters
widthThe width of the desktop in pixels.
heightThe height of the desktop in pixels.

Implements HoverRace::Display::Display.

void HoverRace::Display::SDL::SdlDisplay::OnDisplayConfigChanged ( )
overridevirtual

Reconfigure the display based on the new configuration.

This should be called whenever the video configuration of Util::Config changes.

Warning
Depending on the underlying API and what configuration options changed, this may trigger resources to be reloaded or regenerated.
Note
Subclasses should call the base class implementation to ensure that the UI scale is updated and views are notified.

Reimplemented from HoverRace::Display::Display.

void HoverRace::Display::SDL::SdlDisplay::Screenshot ( )
overridevirtual

Take a screenshot.

Implements HoverRace::Display::Display.

Member Data Documentation

int HoverRace::Display::SDL::SdlDisplay::height
private
VideoServices::VideoBuffer* HoverRace::Display::SDL::SdlDisplay::legacyDisplay
private
loadedFonts_t HoverRace::Display::SDL::SdlDisplay::loadedFonts
private
SDL_Renderer* HoverRace::Display::SDL::SdlDisplay::renderer
private
int HoverRace::Display::SDL::SdlDisplay::width
private
SDL_Window* HoverRace::Display::SDL::SdlDisplay::window
private
std::string HoverRace::Display::SDL::SdlDisplay::windowTitle
private

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