Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Graphics::UI::Element Class Referenceabstract

#include <element.h>

Inheritance diagram for Graphics::UI::Element:
Graphics::Renderable Component Events::Subject Events::Observer Graphics::UI::Area Graphics::UI::TextArea Graphics::UI::Button Graphics::UI::TextField Graphics::UI::QuitButton

Public Member Functions

 Element (VertexData vertex_data, std::shared_ptr< Skin > skin, const unsigned int layer)
 Element constructor. More...
 
virtual ~Element ()
 Destroys element. More...
 
std::shared_ptr< SkingetSkin () const noexcept
 Gets the UI skin. More...
 
void setSkin (std::shared_ptr< Skin > skin) noexcept
 Sets the UI skin. More...
 
glm::vec2 getAnchorPoint () const noexcept
 Gets the anchor point. More...
 
void setAnchorPoint (const glm::vec2 anchor_point)
 Sets the anchor point. More...
 
float getWidth () const noexcept
 Gets the width. More...
 
float getHeight () const noexcept
 Gets the height. More...
 
void setWidth (const float width) noexcept
 Sets the width. More...
 
void setHeight (const float height) noexcept
 Sets the height. More...
 
float getTextPadding () const noexcept
 Gets the text padding. More...
 
void setTextPadding (const float text_padding) noexcept
 Sets the text padding. More...
 
glm::vec4 getColor () const noexcept
 Gets the color. More...
 
void setColor (const glm::vec4 color) noexcept
 Sets the color. More...
 
virtual std::string to_string () const noexceptoverride
 Returns a string representation of the object. More...
 
bool isPointWithin (glm::vec2 point) noexcept
 Determines if point is within element. More...
 
virtual std::string className () const noexceptoverride
 Returns a string representing the class name. More...
 
virtual void onDestroy () override
 Called when the engine is shutting down. More...
 
virtual void onStart () override
 Called when the engine starts and when a new scene is loaded. More...
 
virtual bool onUpdate (const double delta) override
 Called every engine loop. More...
 
void handleQueuedEvent (std::shared_ptr< Events::Event > event) override
 HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received. More...
 
void onNotifyNow (std::shared_ptr< Events::Event > event) override
 When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure the object is notified before another engine loop. This is pure virtual and is implemented on a case by case basis in derived classes. More...
 
virtual unsigned long long getValueForSorting () const noexceptoverride
 Gets the value for sorting. More...
 
virtual void onLeftClick ()=0
 Called when element is left clicked. More...
 
virtual void onRightClick ()=0
 Called when element is right clicked. More...
 
virtual void onLeftClickRelease ()=0
 Called when element has left click released over it. More...
 
virtual void onRightClickRelease ()=0
 Called when element has right click released over it. More...
 
virtual void onCursorEnter ()=0
 Called when the mosue cursor goes over the element. More...
 
virtual void onCursorLeave ()=0
 Called when the mouse cursor goes off the element. More...
 
virtual void onKeyDown (const int key)=0
 Called when a key is pressed while element is in focus. More...
 
virtual void onKeyUp (const int key)=0
 Called when a key is released while element is in focus. More...
 
virtual void onKeyRepeat (const int key)=0
 Called when a key is repeated while element is in focus. More...
 
virtual void onScroll (const glm::dvec2 position_change)=0
 Called when the mouse wheel is scrolled while element is in focus. More...
 
virtual void log (el::base::type::ostream_t &os) const override
 
- Public Member Functions inherited from Graphics::Renderable
 Renderable (const unsigned int vertex_array_object, const VertexData &vertex_data)
 Renderable constructor. More...
 
 Renderable (const Renderable &)=delete
 
Renderable operator= (Renderable &)=delete
 
 Renderable (Renderable &&renderable)
 
Renderableoperator= (Renderable &&renderable)
 
virtual ~Renderable ()
 
void setShader (std::shared_ptr< Shader > shader_object) noexcept
 Sets the shader. More...
 
std::shared_ptr< ShadergetShader () const noexcept
 Gets the shader. More...
 
void addTexture (const unsigned int unit, const std::string uniform_name, std::shared_ptr< BaseTexture > texture_object) noexcept
 Adds a texture. More...
 
void removeTexture (const unsigned int unit)
 Removes a texture. More...
 
std::map< unsigned int,
std::shared_ptr< BaseTexture > > 
getTextures () const noexcept
 Gets the textures. More...
 
void setLightReactive (const bool reactive) noexcept
 Sets if the renderable should be light reactive. More...
 
bool isLightReactive () const noexcept
 Determines if light reactive. More...
 
void setAmbientLight (const glm::vec3 color) noexcept
 Sets the ambient light. More...
 
glm::vec3 getAmbientLight () const noexcept
 Gets the ambient light. More...
 
void setAmbientIntensity (const float intensity) noexcept
 Sets the ambient intensity. More...
 
float getAmbientIntensity () const noexcept
 Gets the ambient intensity. More...
 
void addInfluencingLight (std::shared_ptr< Light > light) noexcept
 Adds an influencing light. More...
 
void clearInfluencingLights ()
 Clears all influencing lights. More...
 
float highestZ () const noexcept
 The highest possible z value in the renderable. More...
 
unsigned int getVertexArrayBinding () const noexcept
 Gets the vertex array binding. More...
 
VertexData getVertexData () const noexcept
 Gets the vertex data. More...
 
- Public Member Functions inherited from Component
 Component ()
 Component constructor. More...
 
void setTransform (std::shared_ptr< Transform > transform)
 Sets the transform. More...
 
std::shared_ptr< TransformgetTransform () const noexcept
 Gets the transform. More...
 
void setActive (const bool active) noexcept
 Sets the component active or inactive. More...
 
bool isActive () const noexcept
 Determines if active. More...
 
unsigned int getId () const noexcept
 Gets the identifier. More...
 
bool operator< (Component &other) noexcept
 Operator < using getValueForSorting. More...
 
virtual ~Component ()
 Destroys the object. More...
 
- Public Member Functions inherited from Events::Subject
virtual ~Subject ()=default
 
virtual void notify (std::shared_ptr< Event > event)
 notify is used to tell observers of an event. More...
 
virtual void notifyNow (std::shared_ptr< Event > event)
 notifyNow is used to tell observers of an event as an interrupt. More...
 
virtual void addObserver (std::shared_ptr< Observer > observer)
 Adds an observer. More...
 
virtual void removeObserver (std::shared_ptr< Observer > observer)
 Removes an observer. More...
 
- Public Member Functions inherited from Events::Observer
virtual ~Observer ()
 
void onNotify (std::shared_ptr< Event > event)
 When receiving an event that is non-immediate, onNotify is used. The event is added to the event queue that is processed when processEventQueue is called. More...
 
void processEventQueue ()
 This should be called once ever loop for every Observer to properly use queued events. More...
 

Static Protected Member Functions

static std::vector< glm::vec3 > generateRect (float screen_width, float screen_height, float x_pos, float y_pos, float width, float height) noexcept
 
static std::vector< glm::vec2 > basisTexCoords () noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from Graphics::Renderable
static std::shared_ptr
< Renderable
create (const VertexData &vertex_data)
 Renderable factory function. More...
 
- Protected Member Functions inherited from Graphics::Renderable
void setUniform (const Uniform &uniform) noexcept
 
 Renderable ()
 
- Protected Member Functions inherited from Events::Observer
std::shared_ptr< EventgetEvent ()
 
bool eventsWaiting () const noexcept
 
- Protected Attributes inherited from Graphics::Renderable
std::set< Uniformuniforms
 
- Protected Attributes inherited from Component
std::weak_ptr< Entityentity
 
std::shared_ptr< Transformtransform
 
bool active
 
unsigned int id
 
- Static Protected Attributes inherited from Component
static unsigned int next_id = 0
 

Constructor & Destructor Documentation

Graphics::UI::Element::Element ( VertexData  vertex_data,
std::shared_ptr< Skin skin,
const unsigned int  layer 
)

Element constructor.

Parameters
[in]vertex_dataThe vertex data
[in]skinThe UI skin

References Graphics::Renderable::addTexture(), Component::getTransform(), and Graphics::Renderable::setShader().

Graphics::UI::Element::~Element ( )
virtual

Destroys element.

Member Function Documentation

std::vector< glm::vec2 > Graphics::UI::Element::basisTexCoords ( )
staticprotectednoexcept
std::string Graphics::UI::Element::className ( ) const
overridevirtualnoexcept

Returns a string representing the class name.

Returns
The class name

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, Graphics::UI::Area, and Graphics::UI::QuitButton.

Referenced by generated::getElementModule().

std::vector< glm::vec3 > Graphics::UI::Element::generateRect ( float  screen_width,
float  screen_height,
float  x_pos,
float  y_pos,
float  width,
float  height 
)
staticprotectednoexcept
glm::vec2 Graphics::UI::Element::getAnchorPoint ( ) const
noexcept

Gets the anchor point.

Returns
The anchor point.

Referenced by generated::getElementModule(), and Graphics::UI::TextArea::onStart().

glm::vec4 Graphics::UI::Element::getColor ( ) const
noexcept
float Graphics::UI::Element::getHeight ( ) const
noexcept

Gets the height.

Returns
The height.

Referenced by generated::getElementModule().

std::shared_ptr< Skin > Graphics::UI::Element::getSkin ( ) const
noexcept

Gets the UI skin.

Returns
The skin.

Referenced by generated::getElementModule().

float Graphics::UI::Element::getTextPadding ( ) const
noexcept

Gets the text padding.

Returns
The text padding.

Referenced by generated::getElementModule().

unsigned long long Graphics::UI::Element::getValueForSorting ( ) const
overridevirtualnoexcept

Gets the value for sorting.

Returns
The value for sorting.

Reimplemented from Graphics::Renderable.

References Component::getTransform().

float Graphics::UI::Element::getWidth ( ) const
noexcept

Gets the width.

Returns
The width.

Referenced by generated::getElementModule().

void Graphics::UI::Element::handleQueuedEvent ( std::shared_ptr< Events::Event event)
overridevirtual
bool Graphics::UI::Element::isPointWithin ( glm::vec2  point)
noexcept

Determines if point is within element.

Parameters
[in]pointThe point
Returns
True if point within, False otherwise.

Referenced by generated::getElementModule(), and handleQueuedEvent().

void Graphics::UI::Element::log ( el::base::type::ostream_t &  os) const
overridevirtual
virtual void Graphics::UI::Element::onCursorEnter ( )
pure virtual

Called when the mosue cursor goes over the element.

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onCursorLeave ( )
pure virtual

Called when the mouse cursor goes off the element.

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

void Graphics::UI::Element::onDestroy ( )
overridevirtual

Called when the engine is shutting down.

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextField, Graphics::UI::TextArea, and Graphics::UI::Area.

Referenced by Graphics::UI::Area::onDestroy().

virtual void Graphics::UI::Element::onKeyDown ( const int  key)
pure virtual

Called when a key is pressed while element is in focus.

Parameters
[in]keyThe key

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onKeyRepeat ( const int  key)
pure virtual

Called when a key is repeated while element is in focus.

Parameters
[in]keyThe key

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onKeyUp ( const int  key)
pure virtual

Called when a key is released while element is in focus.

Parameters
[in]keyThe key

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onLeftClick ( )
pure virtual
virtual void Graphics::UI::Element::onLeftClickRelease ( )
pure virtual

Called when element has left click released over it.

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

void Graphics::UI::Element::onNotifyNow ( std::shared_ptr< Events::Event event)
overridevirtual

When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure the object is notified before another engine loop. This is pure virtual and is implemented on a case by case basis in derived classes.

Parameters
[in]eventThe event

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextArea, and Graphics::UI::TextField.

References handleQueuedEvent().

virtual void Graphics::UI::Element::onRightClick ( )
pure virtual

Called when element is right clicked.

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onRightClickRelease ( )
pure virtual

Called when element has right click released over it.

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

virtual void Graphics::UI::Element::onScroll ( const glm::dvec2  position_change)
pure virtual

Called when the mouse wheel is scrolled while element is in focus.

Parameters
[in]position_changeThe position change

Implemented in Graphics::UI::TextArea, Graphics::UI::TextField, Graphics::UI::Button, and Graphics::UI::Area.

Referenced by handleQueuedEvent().

void Graphics::UI::Element::onStart ( )
overridevirtual

Called when the engine starts and when a new scene is loaded.

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextField, Graphics::UI::TextArea, and Graphics::UI::Area.

Referenced by Graphics::UI::Area::onStart().

bool Graphics::UI::Element::onUpdate ( const double  delta)
overridevirtual

Called every engine loop.

Parameters
[in]deltaThe delta
Returns
true if active

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextField, Graphics::UI::TextArea, and Graphics::UI::Area.

References Graphics::Renderable::onUpdate().

Referenced by Graphics::UI::Area::onUpdate().

void Graphics::UI::Element::setAnchorPoint ( const glm::vec2  anchor_point)

Sets the anchor point.

Parameters
[in]anchor_pointThe anchor point

References Graphics::Renderable::setUniform().

Referenced by generated::getElementModule().

void Graphics::UI::Element::setHeight ( const float  height)
noexcept

Sets the height.

Parameters
[in]heightThe height

Referenced by generated::getElementModule().

void Graphics::UI::Element::setSkin ( std::shared_ptr< Skin skin)
noexcept

Sets the UI skin.

Parameters
[in]skinThe skin

Referenced by generated::getElementModule().

void Graphics::UI::Element::setTextPadding ( const float  text_padding)
noexcept

Sets the text padding.

Parameters
[in]text_paddingThe text padding

Referenced by generated::getElementModule(), and Graphics::UI::QuitButton::QuitButton().

void Graphics::UI::Element::setWidth ( const float  width)
noexcept

Sets the width.

Parameters
[in]widthThe width

Referenced by generated::getElementModule().

std::string Graphics::UI::Element::to_string ( ) const
overridevirtualnoexcept

Returns a string representation of the object.

Returns
String representation of the object.

Reimplemented from Graphics::Renderable.

Reimplemented in Graphics::UI::TextArea, Graphics::UI::TextField, and Graphics::UI::Area.

References Graphics::Renderable::to_string().

Referenced by generated::getElementModule(), log(), and Graphics::UI::Area::to_string().


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