![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
World structure that contains and renders Widgets.
More...
#include <ui.hpp>
Public Member Functions | |
| UI (Engine &engine, UPoint resolution=UPoint(10, 10), std::string name="") | |
Construct a UI. | |
| virtual | ~UI () |
Remove all Widgets from itself, and itself from Memory. | |
| auto | AddWidget (const ID< Widget > &widget) -> bool |
Add a Widget. | |
| auto | RemoveWidget (const ID< Widget > &widget) -> bool |
Remove a Widget. | |
| auto | RemoveAllWidgets () -> bool |
Remove all contained Widget. | |
| void | Resize (UPoint resolution) |
| Resize the image's resolution. | |
| void | Render () |
Render all contained Widgets. | |
| void | Draw (Point position=Point(0, 0), UPoint start=UPoint(0, 0), UPoint end=UPoint(0, 0), uint8_t alpha=std::numeric_limits< uint8_t >::max()) |
Draw the rendered image (UI::m_image) to Output so it can be printed to the terminal. | |
| void | RenderClearDrawPrint () |
Shortcut for UI::Render(), Output::Clear(), UI::Draw() and Output::Print(). | |
Public Attributes | |
| Engine & | engine |
Parent Engine. | |
| const ID< UI > | m_id {ID<UI>::Unique()} |
Personal ID. | |
| std::string | m_name |
| String name. | |
| std::vector< ID< Widget > > | m_widgets |
Contained Widgets. | |
| UPoint | m_res |
| Image's resolution. | |
| CellA | m_background = CellA(' ', RGBA(0, 0, 0, 0), RGBA(0, 0, 0, 0)) |
| The background to render upon. | |
| uint8_t | m_alpha = std::numeric_limits<uint8_t>::max() |
Opacity for all rendered Widgets. | |
| RGBA | m_frgba = RGBAColors::transparent |
Foreground color added after rendering Widgets. | |
| RGBA | m_brgba = RGBAColors::transparent |
Background color added after rendering Widgets. | |
| std::vector< CellA > | m_image |
CellA-based rendered image. | |
Protected Member Functions | |
| virtual auto | OnTick () -> bool |
| Virtual function called once each tick. | |
Friends | |
| class | KTech::Memory |
World structure that contains and renders Widgets.
This class is like a combined Layer and Camera, but for Widgets.
Unlike how Objects are rendered, rendering Widgets doesn't involve multiple "layers" (UI is a single layer itself).
Also, UI's image is CellA-based in contrary to Camera's Cell-based image. The alpha channels maintain the total opacity of the rendered image. This allows UI's image to be drawn like a HUD on top of Camera's image in Output::Draw().
| void KTech::UI::Draw | ( | Point | position = Point(0, 0), |
| UPoint | start = UPoint(0, 0), | ||
| UPoint | end = UPoint(0, 0), | ||
| uint8_t | alpha = std::numeric_limits<uint8_t>::max() ) |
Draw the rendered image (UI::m_image) to Output so it can be printed to the terminal.
This function redirects to Output::Draw() and passes the given parameters verbatim.
Output::Draw() for parameters explanation.
|
protectedvirtual |
Virtual function called once each tick.
You can override this in your inherited class to add whatever functionality you want.
Called by Memory::CallOnTicks().
bool value, which is explained in Output::ShouldRenderThisTick().| auto KTech::UI::RemoveAllWidgets | ( | ) | -> bool |
| void KTech::UI::RenderClearDrawPrint | ( | ) |
Shortcut for UI::Render(), Output::Clear(), UI::Draw() and Output::Print().
This function calls the above functions with respect to "render on demand" (by checking Output::ShouldRenderThisTick() and Output::ShouldPrintThisTick()). So, you can use this function in your game loop to avoid boilerplate code while still maintaining good performance, unless you want more functionality in your graphics portion of your game loop. This function is especially convenient for testing in no-game-loop mode.
| void KTech::UI::Resize | ( | UPoint | resolution | ) |
Resize the image's resolution.
| resolution | The new size of the image. |