Symphony Of Empires
UI::Context Class Reference

The UI context that handles all the ui widgets. More...

#include <ui.hpp>

Public Member Functions

 Context ()=delete
 
 Context (Eng3D::State &s)
 
 ~Context ()
 
void load_textures ()
 
void add_widget (UI::Widget *widget)
 
void remove_widget (UI::Widget *widget)
 
void render_all ()
 Render all widgets. More...
 
void resize (const int width, const int height)
 
void set_cursor_pos (glm::ivec2 pos)
 
bool check_hover (glm::ivec2 mouse_pos)
 Check for on_hover events If the mouse is above a widget call the widgets on_hover or show its tooltip if possible. More...
 
bool check_click (glm::ivec2 mouse_pos)
 Check for on_click events. Check if the mouse is above a widget and call the widgets on_click if possible. Also move the clicked window to the top, only works for Window widget with is_pinned = false. More...
 
bool check_mouse_released (glm::ivec2 mouse_pos)
 Release the dragging of the widget. More...
 
void check_drag (glm::ivec2 mouse_pos)
 Check for on_drag events, will move Window widgets with is_pinned = false. More...
 
bool check_wheel (glm::ivec2 mouse_pos, int y)
 Check if the mouse is above a widget and scroll widget. More...
 
bool check_text_input (const char *input)
 Will give keyboard input to Input Widget if one is selected. More...
 
void use_tooltip (Tooltip *tooltip, glm::ivec2 pos)
 
void do_tick ()
 Will call on_tick on all widgets. More...
 
void clear ()
 Removes all widgets. More...
 
void clear_dead ()
 Removes all widgets that have been killed. More...
 
void set_eval (UI::Widget &widget, bool eval)
 Moves a widget from evaluable to non-evaluable making a widget non-evaluable has side effects, don't delete widgets that have been set to not-evaluable, otherwise you risk destructing objects the UI manager thinks doesn't exist. Compare being non-evaluable with not existing. More...
 
void prompt (const std::string &title, const std::string &text)
 

Public Attributes

uint32_t hover_update = 1
 
std::shared_ptr< Eng3D::Textureforeground
 
std::shared_ptr< Eng3D::Texturebackground
 
std::shared_ptr< Eng3D::Texturewindow_top
 
std::shared_ptr< Eng3D::Texturebutton
 
std::shared_ptr< Eng3D::Texturetooltip_tex
 
std::shared_ptr< Eng3D::Texturepiechart_overlay
 
std::shared_ptr< Eng3D::Textureborder_tex
 
std::shared_ptr< Eng3D::Texturebutton_border
 
std::shared_ptr< Eng3D::Texturecursor_tex
 
std::shared_ptr< Eng3D::TrueType::Fontdefault_font
 
std::unique_ptr< Eng3D::OpenGL::Programobj_shader
 
std::unique_ptr< Eng3D::OpenGL::Programpiechart_shader
 
std::vector< std::pair< std::string, std::string > > prompt_queue
 
std::mutex prompt_queue_mutex
 
glm::mat4 projection
 
glm::mat4 view
 
glm::mat4 model
 

Friends

class Widget
 

Detailed Description

The UI context that handles all the ui widgets.

Definition at line 63 of file ui.hpp.

Constructor & Destructor Documentation

◆ Context() [1/2]

UI::Context::Context ( )
delete

◆ Context() [2/2]

UI::Context::Context ( Eng3D::State s)

Definition at line 64 of file ui.cpp.

Here is the call graph for this function:

◆ ~Context()

UI::Context::~Context ( )

Definition at line 104 of file ui.cpp.

Member Function Documentation

◆ add_widget()

void UI::Context::add_widget ( UI::Widget widget)

Definition at line 108 of file ui.cpp.

Here is the caller graph for this function:

◆ check_click()

bool UI::Context::check_click ( glm::ivec2  mouse_pos)

Check for on_click events. Check if the mouse is above a widget and call the widgets on_click if possible. Also move the clicked window to the top, only works for Window widget with is_pinned = false.

Parameters
mouse_posThe mouse position
Returns
true if the mouse position was above a ui widget

Definition at line 498 of file ui.cpp.

Here is the caller graph for this function:

◆ check_drag()

void UI::Context::check_drag ( glm::ivec2  mouse_pos)

Check for on_drag events, will move Window widgets with is_pinned = false.

Parameters
mouse_posThe mouse position

Definition at line 555 of file ui.cpp.

Here is the caller graph for this function:

◆ check_hover()

bool UI::Context::check_hover ( glm::ivec2  mouse_pos)

Check for on_hover events If the mouse is above a widget call the widgets on_hover or show its tooltip if possible.

Parameters
mouse_posThe mouse position
Returns
true if the mouse position was above a ui widget

Definition at line 400 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_mouse_released()

bool UI::Context::check_mouse_released ( glm::ivec2  mouse_pos)

Release the dragging of the widget.

Parameters
mouse_posThe mouse position

Definition at line 530 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_text_input()

bool UI::Context::check_text_input ( const char *  input)

Will give keyboard input to Input Widget if one is selected.

Parameters
inputThe input characters
Returns
true if there is a currently selected input widget

Definition at line 573 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_wheel()

bool UI::Context::check_wheel ( glm::ivec2  mouse_pos,
int  y 
)

Check if the mouse is above a widget and scroll widget.

Parameters
mouse_posThe mouse position
yThe mouse scroll wheel amount
Returns
true if the mouse position was above a ui widget

Definition at line 625 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void UI::Context::clear ( )

Removes all widgets.

Definition at line 121 of file ui.cpp.

Here is the caller graph for this function:

◆ clear_dead()

void UI::Context::clear_dead ( )

Removes all widgets that have been killed.

Definition at line 146 of file ui.cpp.

◆ do_tick()

void UI::Context::do_tick ( )

Will call on_tick on all widgets.

These functions are called on each world tick - this is to allow to update widgets on each world tick, and are also framerate independent and thus more reliable than doing the usual if (tick % ticks_per_month == 24) {}, which can cause issues on slow PCs or very fast hosts.

Definition at line 635 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_textures()

void UI::Context::load_textures ( )

◆ prompt()

void UI::Context::prompt ( const std::string &  title,
const std::string &  text 
)

Definition at line 183 of file ui.cpp.

Here is the caller graph for this function:

◆ remove_widget()

void UI::Context::remove_widget ( UI::Widget widget)

Definition at line 115 of file ui.cpp.

◆ render_all()

void UI::Context::render_all ( )

Render all widgets.

Definition at line 323 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

void UI::Context::resize ( const int  width,
const int  height 
)

Definition at line 265 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_cursor_pos()

void UI::Context::set_cursor_pos ( glm::ivec2  pos)

Definition at line 275 of file ui.cpp.

Here is the caller graph for this function:

◆ set_eval()

void UI::Context::set_eval ( UI::Widget widget,
bool  eval 
)

Moves a widget from evaluable to non-evaluable making a widget non-evaluable has side effects, don't delete widgets that have been set to not-evaluable, otherwise you risk destructing objects the UI manager thinks doesn't exist. Compare being non-evaluable with not existing.

Definition at line 165 of file ui.cpp.

◆ use_tooltip()

void UI::Context::use_tooltip ( UI::Tooltip tooltip,
glm::ivec2  pos 
)

Definition at line 580 of file ui.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Widget

friend class Widget
friend

Definition at line 169 of file ui.hpp.

Member Data Documentation

◆ background

std::shared_ptr<Eng3D::Texture> UI::Context::background

Definition at line 148 of file ui.hpp.

◆ border_tex

std::shared_ptr<Eng3D::Texture> UI::Context::border_tex

Definition at line 153 of file ui.hpp.

◆ button

std::shared_ptr<Eng3D::Texture> UI::Context::button

Definition at line 150 of file ui.hpp.

◆ button_border

std::shared_ptr<Eng3D::Texture> UI::Context::button_border

Definition at line 154 of file ui.hpp.

◆ cursor_tex

std::shared_ptr<Eng3D::Texture> UI::Context::cursor_tex

Definition at line 155 of file ui.hpp.

◆ default_font

std::shared_ptr<Eng3D::TrueType::Font> UI::Context::default_font

Definition at line 157 of file ui.hpp.

◆ foreground

std::shared_ptr<Eng3D::Texture> UI::Context::foreground

Definition at line 147 of file ui.hpp.

◆ hover_update

uint32_t UI::Context::hover_update = 1

Definition at line 109 of file ui.hpp.

◆ model

glm::mat4 UI::Context::model

Definition at line 167 of file ui.hpp.

◆ obj_shader

std::unique_ptr<Eng3D::OpenGL::Program> UI::Context::obj_shader

Definition at line 159 of file ui.hpp.

◆ piechart_overlay

std::shared_ptr<Eng3D::Texture> UI::Context::piechart_overlay

Definition at line 152 of file ui.hpp.

◆ piechart_shader

std::unique_ptr<Eng3D::OpenGL::Program> UI::Context::piechart_shader

Definition at line 160 of file ui.hpp.

◆ projection

glm::mat4 UI::Context::projection

Definition at line 165 of file ui.hpp.

◆ prompt_queue

std::vector<std::pair<std::string, std::string> > UI::Context::prompt_queue

Definition at line 162 of file ui.hpp.

◆ prompt_queue_mutex

std::mutex UI::Context::prompt_queue_mutex

Definition at line 163 of file ui.hpp.

◆ tooltip_tex

std::shared_ptr<Eng3D::Texture> UI::Context::tooltip_tex

Definition at line 151 of file ui.hpp.

◆ view

glm::mat4 UI::Context::view

Definition at line 166 of file ui.hpp.

◆ window_top

std::shared_ptr<Eng3D::Texture> UI::Context::window_top

Definition at line 149 of file ui.hpp.


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