Files
NazaraEngine/include/Nazara/Graphics/TextSprite.inl
Lynix 76818335ff Revert "Core/RefCounted: Remove persistent boolean"
This reverts commit db2ef3e90c3871290d114a9e6437b412e96c65aa [formerly a3f6ff88a25e63374eb6ce5b18269da2ba743b06] [formerly cfa12604fbb0da76fc27288b210ee1254a8b3a38 [formerly dee6ce858398e2de38ef1af00c1c630fd0126e09]] [formerly 1a23f0fddcd80ac33030061b7a00a3cfd43cb7fe [formerly d3cb17069c71449ae3f1cba6de55ea70f509e7a4] [formerly b2f8f82e9f3427310204f2e8a61d7bdfd96202d2 [formerly 5d117720d08d6d6243b3428d4b3f8aea1abef845]]].


Former-commit-id: fcbfc6cb2fac86f6f10ff5def148cc5635082c83 [formerly 6bcf746c9b6f35aff6786da950001da11cedfc48] [formerly 9d219f350ddebbfa60eaa9c382d8d811d963ac15 [formerly 75f534e850802526877b811e8f6ca510bb7f2c16]]
Former-commit-id: b5ca8fa1bde036ccb4f7be17a98ef8275ab5cf2a [formerly ee166858dad5c8cd00249894266b13e8ce1a153e]
Former-commit-id: 2a601076664aebc1107654dd80f3b53f7acbc044
2016-08-02 13:20:34 +02:00

220 lines
4.9 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
/*!
* \brief Constructs a TextSprite object by default
*/
inline TextSprite::TextSprite() :
m_color(Color::White),
m_scale(1.f)
{
SetDefaultMaterial();
}
/*!
* \brief Constructs a TextSprite object with a drawer
*
* \param drawer Drawer used to compose text on the sprite
*/
inline TextSprite::TextSprite(const AbstractTextDrawer& drawer) :
TextSprite()
{
Update(drawer);
}
/*!
* \brief Constructs a TextSprite object by assignation
*
* \param sprite TextSprite to copy into this
*/
inline TextSprite::TextSprite(const TextSprite& sprite) :
InstancedRenderable(sprite),
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_scale(sprite.m_scale)
{
for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it)
{
const AbstractAtlas* atlas = it->first;
AtlasSlots& atlasSlots = m_atlases[atlas];
atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
}
}
/*!
* \brief Clears the data
*/
inline void TextSprite::Clear()
{
m_atlases.clear();
m_boundingVolume.MakeNull();
m_localVertices.clear();
m_renderInfos.clear();
}
/*!
* \brief Gets the color of the text sprite
* \return Current color
*/
inline const Color& TextSprite::GetColor() const
{
return m_color;
}
/*!
* \brief Gets the material of the text sprite
* \return Current material
*/
inline const MaterialRef& TextSprite::GetMaterial() const
{
return m_material;
}
/*!
* \brief Gets the current scale of the text sprite
* \return Current scale
*/
inline float TextSprite::GetScale() const
{
return m_scale;
}
/*!
* \brief Sets the color of the text sprite
*
* \param color Color for the text sprite
*/
inline void TextSprite::SetColor(const Color& color)
{
m_color = color;
InvalidateVertices();
}
/*!
* \brief Sets the default material of the text sprite (just default material)
*/
inline void TextSprite::SetDefaultMaterial()
{
MaterialRef material = Material::New();
material->Enable(RendererParameter_Blend, true);
material->Enable(RendererParameter_DepthWrite, false);
material->Enable(RendererParameter_FaceCulling, false);
material->EnableLighting(false);
material->SetDstBlend(BlendFunc_InvSrcAlpha);
material->SetSrcBlend(BlendFunc_SrcAlpha);
SetMaterial(material);
}
/*!
* \brief Sets the material of the text sprite
*
* \param material Material for the text sprite
*/
inline void TextSprite::SetMaterial(MaterialRef material)
{
m_material = std::move(material);
}
/*!
* \brief Sets the current scale of the text sprite
*
* \param scale Scale of the text sprite
*/
inline void TextSprite::SetScale(float scale)
{
m_scale = scale;
InvalidateVertices();
}
/*!
* \brief Sets the current text sprite with the content of the other one
* \return A reference to this
*
* \param text sprite The other TextSprite
*/
inline TextSprite& TextSprite::operator=(const TextSprite& text)
{
InstancedRenderable::operator=(text);
m_atlases.clear();
m_color = text.m_color;
m_material = text.m_material;
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)
{
const AbstractAtlas* atlas = it->first;
AtlasSlots& atlasSlots = m_atlases[atlas];
atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated);
atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange);
atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated);
}
InvalidateBoundingVolume();
InvalidateVertices();
return *this;
}
/*!
* \brief Invalidates the vertices
*/
inline void TextSprite::InvalidateVertices()
{
InvalidateInstanceData(0);
}
/*!
* \brief Creates a new text sprite from the arguments
* \return A reference to the newly created text sprite
*
* \param args Arguments for the text sprite
*/
template<typename... Args>
TextSpriteRef TextSprite::New(Args&&... args)
{
std::unique_ptr<TextSprite> object(new TextSprite(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Renderer/DebugOff.hpp>