From 8c345964ef970c650b789b0500a63ecd6a25c7de Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 12 Jun 2015 00:45:52 +0200 Subject: [PATCH] Graphics/TextSprite: Add scale Former-commit-id: 54bb42e83060730e8bd4784b1e24b479d21157f7 --- include/Nazara/Graphics/TextSprite.hpp | 3 +++ src/Nazara/Graphics/TextSprite.cpp | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Graphics/TextSprite.hpp b/include/Nazara/Graphics/TextSprite.hpp index fe6494560..ae2850e53 100644 --- a/include/Nazara/Graphics/TextSprite.hpp +++ b/include/Nazara/Graphics/TextSprite.hpp @@ -38,6 +38,7 @@ class NAZARA_API NzTextSprite : public NzRenderable const NzColor& GetColor() const; NzMaterial* GetMaterial() const; + float GetScale() const; void InvalidateVertices(); bool IsDrawable() const; @@ -45,6 +46,7 @@ class NAZARA_API NzTextSprite : public NzRenderable void SetColor(const NzColor& color); void SetDefaultMaterial(); void SetMaterial(NzMaterial* material); + void SetScale(float scale); void Update(const NzAbstractTextDrawer& drawer); @@ -78,6 +80,7 @@ class NAZARA_API NzTextSprite : public NzRenderable NzMaterialRef m_material; NzRectui m_localBounds; mutable bool m_verticesUpdated; + float m_scale; static NzTextSpriteLibrary::LibraryMap s_library; }; diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 5a8f7d57c..417fe20c7 100644 --- a/src/Nazara/Graphics/TextSprite.cpp +++ b/src/Nazara/Graphics/TextSprite.cpp @@ -12,7 +12,8 @@ #include NzTextSprite::NzTextSprite() : -m_color(NzColor::White) +m_color(NzColor::White), +m_scale(1.f) { SetDefaultMaterial(); } @@ -23,7 +24,8 @@ m_renderInfos(sprite.m_renderInfos), m_localVertices(sprite.m_localVertices), m_color(sprite.m_color), 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) { @@ -79,6 +81,11 @@ NzMaterial* NzTextSprite::GetMaterial() const return m_material; } +float NzTextSprite::GetScale() const +{ + return m_scale; +} + void NzTextSprite::InvalidateVertices() { OnRenderableInvalidateInstanceData(this, 0); @@ -114,6 +121,13 @@ void NzTextSprite::SetMaterial(NzMaterial* material) m_material = material; } +void NzTextSprite::SetScale(float scale) +{ + m_scale = scale; + + InvalidateInstanceData(0); +} + void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) { m_atlases.clear(); @@ -239,6 +253,7 @@ NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text) m_renderInfos = text.m_renderInfos; m_localBounds = text.m_localBounds; m_localVertices = text.m_localVertices; + m_scale = text.m_scale; // Connect to the slots of the new atlases 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) { - *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; *uv++ = localVertex->uv;