NAP
renderable2dtextcomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "renderabletextcomponent.h"
9 
10 // External Includes
11 #include <fontutils.h>
12 
13 namespace nap
14 {
15  // Forward Declares
16  class Renderable2DTextComponentInstance;
17  class RenderService;
18 
66  {
67  RTTI_ENABLE(RenderableTextComponent)
69 
70  public:
72  glm::ivec2 mLocation = { 0,0 };
74  bool mIgnoreTransform = true;
75  bool mDPIAware = true;
76  };
77 
78 
125  {
127  public:
129  RenderableTextComponentInstance(entity, resource) { }
130 
136  virtual bool init(utility::ErrorState& errorState) override;
137 
142  virtual void update(double deltaTime) override;
143 
153  void draw(IRenderTarget& target);
154 
158  utility::ETextOrientation getOrientation() const { return mOrientation; }
159 
164  void setOrientation(utility::ETextOrientation orientation) { mOrientation = orientation; }
165 
172  const glm::ivec2& getLocation() const { return mLocation; }
173 
180  void setLocation(const glm::ivec2& coordinates) { mLocation = coordinates; }
181 
188  glm::ivec2 getTextPosition(float scale);
189 
197  virtual RenderableGlyph* getRenderableGlyph(uint index, float scale, utility::ErrorState& error) const override;
198 
203  virtual bool isSupported(nap::CameraComponentInstance& camera) const override;
204 
205  protected:
218  virtual void onDraw(IRenderTarget& renderTarget, VkCommandBuffer commandBuffer, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) override;
219 
220  private:
222 
227  void computeTextModelMatrix(glm::mat4x4& outMatrix);
228 
229  glm::ivec2 mLocation = { 0,0 };
230  RenderService* mService = nullptr;
231  bool mIgnoreTransform = true;
232  bool mDPIAware = true;
233  float mDisplayScale = 1.0f;
234  };
235 }
nap::RenderableTextComponentInstance
Definition: renderabletextcomponent.h:53
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::Renderable2DTextComponentInstance::Renderable2DTextComponentInstance
Renderable2DTextComponentInstance(EntityInstance &entity, Component &resource)
Definition: renderable2dtextcomponent.h:128
nap::Renderable2DTextComponentInstance::setLocation
void setLocation(const glm::ivec2 &coordinates)
Definition: renderable2dtextcomponent.h:180
nap::IRenderTarget
Definition: irendertarget.h:21
nap::Renderable2DTextComponent
Definition: renderable2dtextcomponent.h:65
nap::EDepthMode::NoReadWrite
@ NoReadWrite
Neither read or write depth.
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::Renderable2DTextComponentInstance::getLocation
const glm::ivec2 & getLocation() const
Definition: renderable2dtextcomponent.h:172
nap::EDepthMode
EDepthMode
Definition: materialcommon.h:40
nap::Renderable2DTextComponentInstance
Definition: renderable2dtextcomponent.h:124
nap::utility::ErrorState
Definition: errorstate.h:19
nap::RenderableTextComponent
Definition: renderabletextcomponent.h:32
nap::Renderable2DTextComponentInstance::getOrientation
utility::ETextOrientation getOrientation() const
Definition: renderable2dtextcomponent.h:158
nap::EntityInstance
Definition: entity.h:34
nap::Component
Definition: component.h:151
nap::utility::ETextOrientation
ETextOrientation
Definition: fontutils.h:15
nap::RenderableGlyph
Definition: renderableglyph.h:24
nap
Definition: templateapp.h:17
nap::utility::ETextOrientation::Left
@ Left
Draws text to the right of the horizontal coordinate.
nap::Renderable2DTextComponentInstance::setOrientation
void setOrientation(utility::ETextOrientation orientation)
Definition: renderable2dtextcomponent.h:164