Graphics/TextSprite: Add scale

Former-commit-id: 54bb42e83060730e8bd4784b1e24b479d21157f7
This commit is contained in:
Lynix 2015-06-12 00:45:52 +02:00
parent 2391d76332
commit 8c345964ef
2 changed files with 24 additions and 3 deletions

View File

@ -38,6 +38,7 @@ class NAZARA_API NzTextSprite : public NzRenderable
const NzColor& GetColor() const; const NzColor& GetColor() const;
NzMaterial* GetMaterial() const; NzMaterial* GetMaterial() const;
float GetScale() const;
void InvalidateVertices(); void InvalidateVertices();
bool IsDrawable() const; bool IsDrawable() const;
@ -45,6 +46,7 @@ class NAZARA_API NzTextSprite : public NzRenderable
void SetColor(const NzColor& color); void SetColor(const NzColor& color);
void SetDefaultMaterial(); void SetDefaultMaterial();
void SetMaterial(NzMaterial* material); void SetMaterial(NzMaterial* material);
void SetScale(float scale);
void Update(const NzAbstractTextDrawer& drawer); void Update(const NzAbstractTextDrawer& drawer);
@ -78,6 +80,7 @@ class NAZARA_API NzTextSprite : public NzRenderable
NzMaterialRef m_material; NzMaterialRef m_material;
NzRectui m_localBounds; NzRectui m_localBounds;
mutable bool m_verticesUpdated; mutable bool m_verticesUpdated;
float m_scale;
static NzTextSpriteLibrary::LibraryMap s_library; static NzTextSpriteLibrary::LibraryMap s_library;
}; };

View File

@ -12,7 +12,8 @@
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>
NzTextSprite::NzTextSprite() : NzTextSprite::NzTextSprite() :
m_color(NzColor::White) m_color(NzColor::White),
m_scale(1.f)
{ {
SetDefaultMaterial(); SetDefaultMaterial();
} }
@ -23,7 +24,8 @@ m_renderInfos(sprite.m_renderInfos),
m_localVertices(sprite.m_localVertices), m_localVertices(sprite.m_localVertices),
m_color(sprite.m_color), m_color(sprite.m_color),
m_material(sprite.m_material), m_material(sprite.m_material),
m_localBounds(sprite.m_localBounds) m_localBounds(sprite.m_localBounds),
m_scale(sprite.m_scale)
{ {
for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it) for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it)
{ {
@ -79,6 +81,11 @@ NzMaterial* NzTextSprite::GetMaterial() const
return m_material; return m_material;
} }
float NzTextSprite::GetScale() const
{
return m_scale;
}
void NzTextSprite::InvalidateVertices() void NzTextSprite::InvalidateVertices()
{ {
OnRenderableInvalidateInstanceData(this, 0); OnRenderableInvalidateInstanceData(this, 0);
@ -114,6 +121,13 @@ void NzTextSprite::SetMaterial(NzMaterial* material)
m_material = material; m_material = material;
} }
void NzTextSprite::SetScale(float scale)
{
m_scale = scale;
InvalidateInstanceData(0);
}
void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) void NzTextSprite::Update(const NzAbstractTextDrawer& drawer)
{ {
m_atlases.clear(); m_atlases.clear();
@ -239,6 +253,7 @@ NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text)
m_renderInfos = text.m_renderInfos; m_renderInfos = text.m_renderInfos;
m_localBounds = text.m_localBounds; m_localBounds = text.m_localBounds;
m_localVertices = text.m_localVertices; m_localVertices = text.m_localVertices;
m_scale = text.m_scale;
// Connect to the slots of the new atlases // Connect to the slots of the new atlases
for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it) for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it)
@ -345,7 +360,10 @@ void NzTextSprite::UpdateData(InstanceData* instanceData) const
{ {
for (unsigned int j = 0; j < 4; ++j) for (unsigned int j = 0; j < 4; ++j)
{ {
*pos++ = instanceData->transformMatrix.Transform(localVertex->position.x*NzVector3f::Right() + localVertex->position.y*NzVector3f::Down()); NzVector3f localPos = localVertex->position.x*NzVector3f::Right() + localVertex->position.y*NzVector3f::Down();
localPos *= m_scale;
*pos++ = instanceData->transformMatrix.Transform(localPos);
*color++ = m_color * localVertex->color; *color++ = m_color * localVertex->color;
*uv++ = localVertex->uv; *uv++ = localVertex->uv;