Plutonium framework API 1.0.0
Easy-to-use, SDL2-based UI framework for Nintendo Switch homebrew
|
Type that represents the basic object in this library, the general context for UI and rendering. More...
#include <ui_Application.hpp>
Public Types | |
using | DialogPrepareCallback = std::function<void(Dialog::Ref&)> |
Function type used to further customize a Dialog (setting fields) when using Application::CreateShowDialog. | |
using | OnInputCallback = std::function<void(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos)> |
Function type used to handle input events. | |
using | RenderCallback = std::function<void()> |
Function type to be called every rendering loop/frame. | |
using | RenderOverFunction = std::function<bool(render::Renderer::Ref&)> |
Function type to be called when rendering over the main rendering loop/frame. | |
Public Member Functions | |
Application (render::Renderer::Ref renderer) | |
Creates a new Application with the specified Renderer. | |
virtual | ~Application () |
void | LoadLayout (Layout::Ref lyt) |
Loads the Layout to be used by the Application. | |
template<typename L> | |
std::shared_ptr< L > | GetLayout () |
Gets the current Layout (of the specified type). | |
Result | Load () |
Loads the Application. | |
virtual void | OnLoad ()=0 |
Function to be implemented by child classes, called when the Application is loaded. | |
void | AddRenderCallback (RenderCallback render_cb) |
Adds a RenderCallback to the Application. | |
void | SetOnInput (OnInputCallback on_ipt_cb) |
Sets the OnInputCallback for the Application. | |
i32 | ShowDialog (Dialog::Ref &dialog) |
Shows a Dialog and waits for the user to interact with it. | |
i32 | CreateShowDialog (const std::string &title, const std::string &content, const std::vector< std::string > &opts, const bool use_last_opt_as_cancel, sdl2::TextureHandle::Ref icon={}, DialogPrepareCallback prepare_cb=nullptr) |
Wrapper function that creates a Dialog with the specified parameters and shows it. | |
void | StartOverlay (Overlay::Ref ovl) |
Starts an Overlay. | |
void | StartOverlayWithTimeout (Overlay::Ref ovl, const u64 ms) |
Starts an Overlay with a timeout. | |
void | EndOverlay () |
Ends the current Overlay. | |
void | Show () |
Shows the Application. | |
void | ShowWithFadeIn () |
Shows the Application with a fade-in effect. | |
bool | IsShown () |
Gets whether the Application is currently shown. | |
bool | CanBeShown () |
Gets whether the Application can be shown. | |
bool | CallForRender () |
Calls for rendering the Application. | |
bool | CallForRenderWithRenderOver (RenderOverFunction render_over_fn) |
Calls for rendering the Application with a custom RenderOverFunction. | |
void | LockRender () |
Locks the rendering mutex. | |
void | UnlockRender () |
Unlocks the rendering mutex. | |
void | FadeIn () |
Starts and waits for a fade-in effect. | |
void | FadeOut () |
Starts and waits for a fade-out effect. | |
bool | IsFadingOrFadedIn () |
Gets whether the Application is currently fading in or already faded in. | |
void | SetFadeAlphaIncrementStepCount (const u8 fade_alpha_increment_steps) |
Sets the number of steps for the fade-in and fade-out effects. | |
void | SetFadeBackgroundImage (sdl2::TextureHandle::Ref bg_tex) |
Sets the target background image for the fade effect. | |
void | ResetFadeBackgroundImage () |
Resets the background image used for the fade effect. | |
sdl2::TextureHandle::Ref & | GetFadeBackgroundImageTexture () |
Gets the background image used for the fade effect. | |
bool | HasFadeBackgroundImage () |
Gets whether the fade effect is using a background image. | |
void | SetFadeBackgroundColor (const Color clr) |
Sets the background color for the fade effect. | |
void | Close (const bool do_exit=false) |
Closes the Application. | |
void | CloseWithFadeOut (const bool do_exit=false) |
Closes the Application with a fade-out effect. | |
u64 | GetButtonsDown () |
Gets the currently pressed button keys. | |
u64 | GetButtonsUp () |
Gets the currently released button keys. | |
u64 | GetButtonsHeld () |
Gets the currently held button keys. | |
HidTouchScreenState | GetTouchState () |
Gets the currently pressed touch position. | |
Static Public Attributes | |
static constexpr u8 | DefaultFadeAlphaIncrementSteps = 20 |
Protected Attributes | |
bool | loaded |
bool | in_render_over |
RenderOverFunction | render_over_fn |
bool | is_shown |
u8 | fade_alpha_increment_steps |
SigmoidIncrementer< i32 > | fade_alpha_incr |
i32 | fade_alpha |
sdl2::TextureHandle::Ref | fade_bg_tex |
Color | fade_bg_clr |
Layout::Ref | lyt |
Overlay::Ref | ovl |
u64 | ovl_timeout_ms |
std::chrono::steady_clock::time_point | ovl_start_time |
std::vector< RenderCallback > | render_cbs |
OnInputCallback | on_ipt_cb |
render::Renderer::Ref | renderer |
RMutex | render_lock |
Type that represents the basic object in this library, the general context for UI and rendering.
using pu::ui::Application::DialogPrepareCallback = std::function<void(Dialog::Ref&)> |
Function type used to further customize a Dialog (setting fields) when using Application::CreateShowDialog.
using pu::ui::Application::OnInputCallback = std::function<void(const u64 keys_down, const u64 keys_up, const u64 keys_held, const TouchPoint touch_pos)> |
Function type used to handle input events.
keys_down | The keys that were pressed in this frame. |
keys_up | The keys that were released in this frame. |
keys_held | The keys that are being held in this frame. |
touch_pos | The position of the touch on the screen. |
using pu::ui::Application::RenderCallback = std::function<void()> |
Function type to be called every rendering loop/frame.
using pu::ui::Application::RenderOverFunction = std::function<bool(render::Renderer::Ref&)> |
Function type to be called when rendering over the main rendering loop/frame.
renderer | The Renderer instance to render over. |
pu::ui::Application::Application | ( | render::Renderer::Ref | renderer | ) |
Creates a new Application with the specified Renderer.
renderer | The Renderer to use for rendering. |
|
virtual |
|
inline |
Adds a RenderCallback to the Application.
render_cb | The RenderCallback to add. |
bool pu::ui::Application::CallForRender | ( | ) |
Calls for rendering the Application.
bool pu::ui::Application::CallForRenderWithRenderOver | ( | RenderOverFunction | render_over_fn | ) |
Calls for rendering the Application with a custom RenderOverFunction.
render_over_fn | The RenderOverFunction to use. |
|
inline |
Gets whether the Application can be shown.
void pu::ui::Application::Close | ( | const bool | do_exit = false | ) |
Closes the Application.
do_exit | Whether the program should fully exit after closing. |
exit(0)
.
|
inline |
Closes the Application with a fade-out effect.
do_exit | Whether the program should fully exit after closing. |
exit(0)
. i32 pu::ui::Application::CreateShowDialog | ( | const std::string & | title, |
const std::string & | content, | ||
const std::vector< std::string > & | opts, | ||
const bool | use_last_opt_as_cancel, | ||
sdl2::TextureHandle::Ref | icon = {}, | ||
DialogPrepareCallback | prepare_cb = nullptr ) |
Wrapper function that creates a Dialog with the specified parameters and shows it.
title | The title of the Dialog. |
content | The content of the Dialog. |
opts | The options of the Dialog. |
use_last_opt_as_cancel | Whether the last option should be used as a cancel option. |
icon | The icon of the Dialog. |
prepare_cb | The DialogPrepareCallback to further customize the Dialog. |
void pu::ui::Application::EndOverlay | ( | ) |
Ends the current Overlay.
void pu::ui::Application::FadeIn | ( | ) |
Starts and waits for a fade-in effect.
void pu::ui::Application::FadeOut | ( | ) |
Starts and waits for a fade-out effect.
|
inline |
Gets the currently pressed button keys.
|
inline |
Gets the currently held button keys.
|
inline |
Gets the currently released button keys.
|
inline |
Gets the background image used for the fade effect.
|
inline |
|
inline |
Gets the currently pressed touch position.
|
inline |
Gets whether the fade effect is using a background image.
|
inline |
Gets whether the Application is currently fading in or already faded in.
|
inline |
Gets whether the Application is currently shown.
Result pu::ui::Application::Load | ( | ) |
Loads the Application.
|
inline |
Loads the Layout to be used by the Application.
lyt | The Layout to load. |
|
inline |
Locks the rendering mutex.
|
pure virtual |
Function to be implemented by child classes, called when the Application is loaded.
void pu::ui::Application::ResetFadeBackgroundImage | ( | ) |
Resets the background image used for the fade effect.
|
inline |
Sets the number of steps for the fade-in and fade-out effects.
fade_alpha_increment_steps | The number of steps for the fade-in and fade-out effects. |
void pu::ui::Application::SetFadeBackgroundColor | ( | const Color | clr | ) |
Sets the background color for the fade effect.
clr | The background color to use for the fade effect. |
void pu::ui::Application::SetFadeBackgroundImage | ( | sdl2::TextureHandle::Ref | bg_tex | ) |
Sets the target background image for the fade effect.
bg_tex | The background image to use for the fade effect. |
|
inline |
Sets the OnInputCallback for the Application.
on_ipt_cb | The OnInputCallback to set. |
void pu::ui::Application::Show | ( | ) |
Shows the Application.
|
inline |
|
inline |
Shows the Application with a fade-in effect.
|
inline |
void pu::ui::Application::StartOverlayWithTimeout | ( | Overlay::Ref | ovl, |
const u64 | ms ) |
|
inline |
Unlocks the rendering mutex.
|
staticconstexpr |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |