Game Development Reference
In-Depth Information
The use of the factory within the Add function of the containers allows us to write very
clean, straightforward code to create user interface controls.
auto uiContainer = std::unique_ptr<ui::container>((new ui::container(m_coreUI, spriteFont)));
auto exampleLabel = uiContainer->Add<ui::label>();
By default, a container will have the dimensions of the screen resolution, setting a position
or size will change the container's viewport and the placement of any controls within the
container will be relative to the new viewport. We can do this by overriding the Refresh
function.
virtual void Refresh()
{
m_viewport = render::viewport(m_rectangle.Left(), m_rectangle.Top(), m_rectangle.Right(), m_rectangle.Bottom(), 0.f, 1.f);
}
This way, if the size or position of the container changes, the container's viewport will be
placed or resized accordingly.
4.3.4 Labels
A label is used as a way to display text, it cannot be interacted with and has noactual func-
tionality except to convey information. Labels provide us with a text field on which to dis-
playinformationtousers,theinformationcanbestatic,meaningthelabeldoesnotchange;
for example when displaying titles or captions. Or, it can be dynamic, the content of the
label may be a game variable, scores, player names or an active game state, a dynamic la-
bel's value will be provided by some external source and may change every frame.
Figure 53 - A label's two main parts, the background and the text field.
Search WWH ::




Custom Search