NAP
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RenderableTextComponentInstance Class Referenceabstract

#include <renderabletextcomponent.h>

Public Member Functions

 RenderableTextComponentInstance (EntityInstance &entity, Component &resource)
 
virtual bool init (utility::ErrorState &errorState) override
 
const FontInstancegetFont () const
 
bool setText (const std::string &text, utility::ErrorState &error)
 
void setColor (const glm::vec3 &color)
 
bool setText (int lineIndex, const std::string &text, utility::ErrorState &error)
 
bool addLine (const std::string &text, utility::ErrorState &error)
 
void setLineIndex (int index)
 
const std::string & getText ()
 
const std::string & getText (int index)
 
void resize (int lines)
 
int getCount () const
 
void clear ()
 
const math::RectgetBoundingBox () const
 
const math::RectgetBoundingBox (int index)
 
virtual RenderableGlyphgetRenderableGlyph (uint index, float scale, utility::ErrorState &error) const =0
 
const MaterialInstancegetMaterialInstance () const
 
MaterialInstancegetMaterialInstance ()
 
float getDPIScale () const
 
- Public Member Functions inherited from RenderableComponentInstance
 RenderableComponentInstance (EntityInstance &entity, Component &resource)
 
void draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix)
 
void setVisible (bool visible)
 
bool isVisible () const
 
const std::vector< ResourcePtr< RenderTag > > & getTags () const
 
RenderMask getMask () const
 
bool includesMask (RenderMask otherMask)
 
int getRank () const
 
const RenderLayergetLayer () const
 
virtual bool isSupported (nap::CameraComponentInstance &camera) const
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
virtual void update (double deltaTime)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Protected Member Functions

void draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, const glm::mat4 &modelMatrix)
 
bool hasTransform () const
 
const nap::TransformComponentInstancegetTransform () const
 
virtual bool setup (float scale, utility::ErrorState &errorState)
 
- Protected Member Functions inherited from RenderableComponentInstance
virtual void onDraw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix)=0
 

Protected Attributes

FontInstancemFont = nullptr
 Pointer to the font, set on initialization. More...
 
RenderServicemRenderService = nullptr
 Pointer to the Renderer. More...
 
- Protected Attributes inherited from RenderableComponentInstance
RenderServicemRenderService = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

Draws text into the currently active render target. This is the runtime version of the RenderableTextComponent resource. Use the Renderable2DTextComponent to render text in screen space and the Renderable3DTextComopnent to render text in 3D space.

It is possible to cache multiple lines at once, where each line can be selected and drawn individually inside a render loop. This is useful when you want the same component to render multiple lines of text, removing the need to declare a component for each individual line. You cannot update or add a line of text when rendering a frame: inside the render loop. Only update or add new lines of text on update. You can however change the position and line of text to draw inside the render loop.

Inheritance diagram for RenderableTextComponentInstance:
[legend]
Collaboration diagram for RenderableTextComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ RenderableTextComponentInstance()

Member Function Documentation

◆ addLine()

bool addLine ( const std::string &  text,
utility::ErrorState error 
)

Adds a new line of text to the end of the cache. Only allowed on app update, not render. Current selection will point to he newly added line after this call.

Parameters
textthe line of text to add
errorlist of unsupported characters
Returns
if all characters in the text are supported and can be drawn.

◆ clear()

void clear ( )

Clears the entire line cache.

◆ draw()

void draw ( IRenderTarget renderTarget,
VkCommandBuffer  commandBuffer,
const glm::mat4 &  viewMatrix,
const glm::mat4 &  projectionMatrix,
const glm::mat4 &  modelMatrix 
)
protected

Draws the text into to active render target using the provided matrices. Call this in derived classes based on extracted matrices.

Parameters
renderTargetbound render target
commandBufferactive command buffer
viewMatrixthe camera world space location
projectionMatrixthe camera projection matrix
modelMatrixthe location of the text in the world

◆ getBoundingBox() [1/2]

const math::Rect& getBoundingBox ( ) const

Returns the bounding box of the current line selection in pixels.

Returns
the bounding box of the current line selection in pixels.

◆ getBoundingBox() [2/2]

const math::Rect& getBoundingBox ( int  index)
Parameters
indexthe line index to get the bounding box for.
Returns
bounding box in pixels, associated with the given line index.

◆ getCount()

int getCount ( ) const

Returns the total number of available lines to update or draw.

Returns
total number of available lines to update or draw.

◆ getDPIScale()

float getDPIScale ( ) const

Returns the font dpi scaling factor

Returns
font dpi scaling factor

◆ getFont()

const FontInstance& getFont ( ) const
Returns
the font used to display text.

◆ getMaterialInstance() [1/2]

MaterialInstance& getMaterialInstance ( )
Returns
the material instance used to render the text

◆ getMaterialInstance() [2/2]

const MaterialInstance& getMaterialInstance ( ) const
Returns
the material instance used to render the text

◆ getRenderableGlyph()

virtual RenderableGlyph* getRenderableGlyph ( uint  index,
float  scale,
utility::ErrorState error 
) const
pure virtual

Needs to be implemented by derived classes. Creates a Glyph that can be rendered using the given index and scaling factor.

Parameters
indexthe index to create the render-able glyph for.
scalethe render-able glyph scaling factor.
errorcontains the error if the glyph representation could not be created.
Returns
the render-able glyph for the given character index.

Implemented in Renderable2DTextComponentInstance, and Renderable3DTextComponentInstance.

◆ getText() [1/2]

const std::string& getText ( )

Returns the text associated with the current line index selection.

Returns
text associated with current line index.

◆ getText() [2/2]

const std::string& getText ( int  index)

Returns the text associated with the given line index.

Parameters
indexthe line index.
Returns
text associated with the given line index.

◆ getTransform()

const nap::TransformComponentInstance* getTransform ( ) const
protected
Returns
the transform component, nullptr if not initialized or not found

◆ hasTransform()

bool hasTransform ( ) const
protected
Returns
if this text has a transform component associated with it

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initialize this component

Parameters
errorStatecontains information if operation fails
Returns
if operation succeeded

Reimplemented from RenderableComponentInstance.

Reimplemented in Renderable2DTextComponentInstance, and Renderable3DTextComponentInstance.

◆ resize()

void resize ( int  lines)

Resizes the cache to the given number of lines. Lines can be drawn / updated individually.

Parameters
linesnew number of lines the cache can hold.

◆ setColor()

void setColor ( const glm::vec3 &  color)

Updates text color

Parameters
colornew text color

◆ setLineIndex()

void setLineIndex ( int  index)

Sets the current line index. The index controls what line of the cache is rendered on draw() and updated when calling setText(). A typical use case would be to set / cache a line of text on app update and draw every line at a different location on render.

Parameters
indexnew line index.

◆ setText() [1/2]

bool setText ( const std::string &  text,
utility::ErrorState error 
)

Set the text to draw at the current line index. Call setLineIndex() before this call to ensure the right index is updated. Only set or change text on app update, not render.

Parameters
textthe new line of text to draw.
errorlist of unsupported characters
Returns
if all characters in the text are supported and can be drawn.

◆ setText() [2/2]

bool setText ( int  lineIndex,
const std::string &  text,
utility::ErrorState error 
)

Set the text to draw at the given line index. Only set or change text on app update, not render.

Parameters
lineIndexthe line index
textthe new line of text
errorlist of unsupported characters
Returns
if all characters in the text are supported and can be drawn.

◆ setup()

virtual bool setup ( float  scale,
utility::ErrorState errorState 
)
protectedvirtual

Loads the shader and initializes this component, call this in a derived class on initialization.

Parameters
scalethe font scaling factor
errorStateholds the error message when initialization fails
Returns
if the component initialized successfully

Member Data Documentation

◆ mFont

FontInstance* mFont = nullptr
protected

Pointer to the font, set on initialization.

◆ mRenderService

RenderService* mRenderService = nullptr
protected

Pointer to the Renderer.