Graphics/Sprite: Add [Get|Set]TextureCoords & SetTextureRect
This commit is contained in:
@@ -22,6 +22,8 @@ namespace Nz
|
||||
inline void AddPass(std::size_t passIndex, std::shared_ptr<MaterialPass> pass);
|
||||
inline void AddPass(std::string passName, std::shared_ptr<MaterialPass> pass);
|
||||
|
||||
inline const std::shared_ptr<MaterialPass>& FindPass(const std::string& passName) const;
|
||||
|
||||
inline const std::shared_ptr<MaterialPass>& GetPass(std::size_t passIndex) const;
|
||||
|
||||
inline bool HasPass(std::size_t passIndex) const;
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Nz
|
||||
return AddPass(registry.GetPassIndex(passName), std::move(pass));
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<MaterialPass>& Material::FindPass(const std::string& passName) const
|
||||
{
|
||||
auto& registry = Graphics::Instance()->GetMaterialPassRegistry();
|
||||
return GetPass(registry.GetPassIndex(passName));
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<MaterialPass>& Material::GetPass(std::size_t passIndex) const
|
||||
{
|
||||
if (passIndex >= m_passes.size())
|
||||
|
||||
@@ -29,13 +29,17 @@ namespace Nz
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline const Color& GetCornerColor(RectCorner corner) const;
|
||||
const std::shared_ptr<Material>& GetMaterial(std::size_t i) const;
|
||||
const std::shared_ptr<Material>& GetMaterial(std::size_t i = 0) const;
|
||||
std::size_t GetMaterialCount() const;
|
||||
inline const Rectf& GetTextureCoords() const;
|
||||
Vector3ui GetTextureSize() const;
|
||||
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetCornerColor(RectCorner corner, const Color& color);
|
||||
inline void SetMaterial(std::shared_ptr<Material> material);
|
||||
inline void SetSize(const Vector2f& size);
|
||||
inline void SetTextureCoords(const Rectf& textureCoords);
|
||||
inline void SetTextureRect(const Rectf& textureRect);
|
||||
|
||||
Sprite& operator=(const Sprite&) = delete;
|
||||
Sprite& operator=(Sprite&&) noexcept = default;
|
||||
|
||||
@@ -8,6 +8,21 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const Color& Sprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const Color& Sprite::GetCornerColor(RectCorner corner) const
|
||||
{
|
||||
return m_cornerColor[UnderlyingCast(corner)];
|
||||
}
|
||||
|
||||
inline const Rectf& Sprite::GetTextureCoords() const
|
||||
{
|
||||
return m_textureCoords;
|
||||
}
|
||||
|
||||
inline void Sprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
@@ -24,6 +39,8 @@ namespace Nz
|
||||
|
||||
inline void Sprite::SetMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
assert(material);
|
||||
|
||||
m_material = std::move(material);
|
||||
}
|
||||
|
||||
@@ -34,6 +51,19 @@ namespace Nz
|
||||
UpdateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetTextureCoords(const Rectf& textureCoords)
|
||||
{
|
||||
m_textureCoords = textureCoords;
|
||||
|
||||
UpdateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetTextureRect(const Rectf& textureRect)
|
||||
{
|
||||
Vector2ui textureSize(GetTextureSize());
|
||||
return SetTextureCoords(textureRect / Vector2f(textureSize));
|
||||
}
|
||||
|
||||
inline void Sprite::UpdateVertices()
|
||||
{
|
||||
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
|
||||
|
||||
Reference in New Issue
Block a user