50 lines
1.8 KiB
C++
50 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "vertex.hpp"
|
|
#include <cstdint>
|
|
|
|
namespace gz::vk {
|
|
// defined in texture_manager.hpp
|
|
class TextureManager;
|
|
class Shape {
|
|
public:
|
|
const std::vector<Vertex2D>& getVertices() const { return vertices; }
|
|
const std::vector<uint32_t>& getIndices() const { return indices; }
|
|
const std::string& getTexture() const { return texture; }
|
|
/**
|
|
* @brief Add an offset to all indices
|
|
*/
|
|
void setIndexOffset(uint32_t offset);
|
|
/**
|
|
* @brief Normalize the vertices, so that (1, 1) is (width, height)
|
|
*/
|
|
void normalizeVertices(float width, float height);
|
|
virtual void setTextureCoordinates(glm::vec2 topLeft, glm::vec2 bottomRight) {};
|
|
virtual void setTextureCoordinates(TextureManager& textureManager) {};
|
|
virtual ~Shape() {};
|
|
protected:
|
|
std::string texture = "texture.png";
|
|
std::vector<Vertex2D> vertices;
|
|
std::vector<uint32_t> indices;
|
|
|
|
};
|
|
|
|
class Rectangle : public Shape {
|
|
public:
|
|
Rectangle(float top, float left, uint32_t width, uint32_t height, glm::vec3 color, std::string&& texture);
|
|
void setTextureCoordinates(glm::vec2 topLeft, glm::vec2 bottomRight) override;
|
|
/**
|
|
* @brief Get the correct texture coordinates from a TextureManager
|
|
* @details
|
|
* If the texture is "atlas", the texture coordinates will remain at (0,0), (0,1), (1, 1), (1, 0) and
|
|
* thus show the entire atlas.
|
|
*/
|
|
void setTextureCoordinates(TextureManager& textureManager) override;
|
|
private:
|
|
float top, left;
|
|
uint32_t width, height;
|
|
glm::vec3 color;
|
|
void generateVertices();
|
|
};
|
|
} // namespace gz::vk
|