#include <renderable2dtextcomponent.h>
Public Member Functions | |
Renderable2DTextComponentInstance (EntityInstance &entity, Component &resource) | |
virtual bool | init (utility::ErrorState &errorState) override |
void | draw (IRenderTarget &target) |
utility::ETextOrientation | getOrientation () const |
void | setOrientation (utility::ETextOrientation orientation) |
const glm::ivec2 & | getLocation () const |
void | setLocation (const glm::ivec2 &coordinates) |
glm::ivec2 | getTextPosition (float scale) |
virtual RenderableGlyph * | getRenderableGlyph (uint index, float scale, utility::ErrorState &error) const override |
virtual bool | isSupported (nap::CameraComponentInstance &camera) const override |
![]() | |
RenderableTextComponentInstance (EntityInstance &entity, Component &resource) | |
const FontInstance & | getFont () 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::Rect & | getBoundingBox () const |
const math::Rect & | getBoundingBox (int index) |
const MaterialInstance & | getMaterialInstance () const |
MaterialInstance & | getMaterialInstance () |
float | getDPIScale () const |
![]() | |
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 |
![]() | |
ComponentInstance (EntityInstance &entity, Component &resource) | |
virtual void | update (double deltaTime) |
nap::EntityInstance * | getEntityInstance () const |
nap::Component * | getComponent () const |
template<typename T > | |
T * | getComponent () const |
virtual bool | init (utility::ErrorState &errorState) |
![]() | |
Object () | |
virtual | ~Object () |
virtual void | onDestroy () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Protected Member Functions | |
virtual void | onDraw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix) override |
![]() | |
void | draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, const glm::mat4 &modelMatrix) |
bool | hasTransform () const |
const nap::TransformComponentInstance * | getTransform () const |
virtual bool | setup (float scale, utility::ErrorState &errorState) |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
![]() | |
FontInstance * | mFont = nullptr |
Pointer to the font, set on initialization. More... | |
RenderService * | mRenderService = nullptr |
Pointer to the Renderer. More... | |
Allows you to render text at a specific location in screen space. Use this component when you want to render text at a specific location on screen or in a render-target.
Call draw() in the render part of your application to render text to a specific location on screen or a render-target. It is also possible to render the text using RenderService::renderObjects(), this is similar to how meshes are rendered. In that case the x/y location of the camera influences the final location of the text.
When the parent entity has a transform component attached to it and 'IgnoreTransform' is set to false, the x/y Translate values are used as offset in pixel space. 2D text cannot be scaled or rotated, this ensures that every Glyph is rendered in it's native resolution. When rendering this component through the render interface of the render service it is advised to use an orthographic camera.
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.
For example, on update:
And on render:
Renderable2DTextComponentInstance | ( | EntityInstance & | entity, |
Component & | resource | ||
) |
void draw | ( | IRenderTarget & | target | ) |
Draws the current text into the active target using the stored coordinates in screen space. This is a convenience function that calls RenderableTextComponentInstance::draw using a custom view and projection matrix. These matrices are created based on on the size of your render target. Only Call this function in the render part of your application. Set text in the update part of your application. The x and y coordinates of the TransformComponent are used as an offset (in pixels) if the parent entity has a transform component. When using this function the orientation of the text is taken into account.
target | render target that defines the screen space bounds |
const glm::ivec2& getLocation | ( | ) | const |
Returns the current text coordinates in screen space. This is not the final position of the text! To get the actual start position of the text use getTextPosition() The final location is based on the orientation and transformation of this component.
utility::ETextOrientation getOrientation | ( | ) | const |
|
overridevirtual |
Creates a Renderable2DGlyph for the given index and scale in the font.
index | the index to create the render-able glyph for. |
scale | the render-able glyph scaling factor. |
error | contains the error if the glyph representation could not be created. |
Implements RenderableTextComponentInstance.
glm::ivec2 getTextPosition | ( | float | scale | ) |
Returns the text position based on the stored location, orientation mode and text transformation. The return value is the actual position of the text in the world and most likely screen. Actual screen space position still depends on camera location, orientation and shader effects.
|
overridevirtual |
Initialize Renderable2DTextComponentInstance based on the Renderable2DTextComponent resource
errorState | should hold the error message when initialization fails |
Reimplemented from RenderableTextComponentInstance.
|
overridevirtual |
This component can only be rendered with an orthographic camera!
Reimplemented from RenderableComponentInstance.
|
overrideprotectedvirtual |
Draws the text to the currently active render target using the render service. This function is called by the render service when text is rendered with a user defined camera. In that case the viewMatrix is the world space camera location and the the projection matrix is defined by the camera type. You can only use an orthographic camera when rendering 2D text. The x/y location of the parent entity is taken into account if there is a transform component. Note that the orientation mode is also taken into account when rendering this way.
renderTarget | bound target to render to |
commandBuffer | current command buffer |
viewMatrix | the camera world space location |
projectionMatrix | the camera projection matrix, orthographic or perspective |
Implements RenderableComponentInstance.
void setLocation | ( | const glm::ivec2 & | coordinates | ) |
Sets the new text coordinates in screen space. This is not the final position of the text! To get the actual start position of the text use getTextPosition() The final location is based on the orientation and transformation of this component.
coordinates | the new text location in pixel space coordinates |
void setOrientation | ( | utility::ETextOrientation | orientation | ) |
Sets the text draw orientation
orientation | new text orientation |