Add widgets (WIP)
This commit is contained in:
@@ -27,17 +27,28 @@ namespace Nz
|
||||
|
||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline const Color& GetCornerColor(RectCorner corner) const;
|
||||
const std::shared_ptr<Material>& GetMaterial(std::size_t i) const;
|
||||
std::size_t GetMaterialCount() 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);
|
||||
|
||||
Sprite& operator=(const Sprite&) = delete;
|
||||
Sprite& operator=(Sprite&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void UpdateVertices();
|
||||
|
||||
std::array<Color, RectCornerCount> m_cornerColor;
|
||||
std::array<VertexStruct_XYZ_Color_UV, 4> m_vertices;
|
||||
std::shared_ptr<Material> m_material;
|
||||
Color m_color;
|
||||
Rectf m_textureCoords;
|
||||
Vector2f m_size;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,57 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void Sprite::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
UpdateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetCornerColor(RectCorner corner, const Color& color)
|
||||
{
|
||||
m_cornerColor[UnderlyingCast(corner)] = color;
|
||||
|
||||
UpdateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::SetMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
}
|
||||
|
||||
inline void Sprite::SetSize(const Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
UpdateVertices();
|
||||
}
|
||||
|
||||
inline void Sprite::UpdateVertices()
|
||||
{
|
||||
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
|
||||
|
||||
Vector3f origin = Vector3f::Zero();
|
||||
|
||||
vertices->color = m_color * m_cornerColor[UnderlyingCast(RectCorner::LeftTop)];
|
||||
vertices->position = Vector3f(-origin);
|
||||
vertices->uv = m_textureCoords.GetCorner(RectCorner::LeftTop);
|
||||
vertices++;
|
||||
|
||||
vertices->color = m_color * m_cornerColor[UnderlyingCast(RectCorner::RightTop)];
|
||||
vertices->position = m_size.x * Vector3f::Right() - origin;
|
||||
vertices->uv = m_textureCoords.GetCorner(RectCorner::RightTop);
|
||||
vertices++;
|
||||
|
||||
vertices->color = m_color * m_cornerColor[UnderlyingCast(RectCorner::LeftBottom)];
|
||||
vertices->position = m_size.y * Vector3f::Down() - origin;
|
||||
vertices->uv = m_textureCoords.GetCorner(RectCorner::LeftBottom);
|
||||
vertices++;
|
||||
|
||||
vertices->color = m_color * m_cornerColor[UnderlyingCast(RectCorner::RightBottom)];
|
||||
vertices->position = m_size.x * Vector3f::Right() + m_size.y * Vector3f::Down() - origin;
|
||||
vertices->uv = m_textureCoords.GetCorner(RectCorner::RightBottom);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user