Ach sorry, wenn schon jemand die 'DiscTexture' möglicherweise anschauen sollte, sollte ich wenigstens noch die Basisklasse dazu zeigen. Also es ist eine Texture, in der mittels einen Pixelarray Pixel gesetzt werden und dann wird sie erstellt. Sie muss dann nur positionert werden, ohne das noch irgendwas gezeichnet wird.
#pragma once
#include <zp/Graphics/SDLPixelTexture.h>
#include <zp/Graphics/RenderRoutines/RenderBase.h>
namespace zp
{
class SDLPixelTextureObject : public RenderBase
{
public:
SDLPixelTextureObject() = default;
SDLPixelTextureObject(const std::shared_ptr<SDLRenderer>& renderer);
virtual ~SDLPixelTextureObject() = default;
private:
std::shared_ptr<SDLRenderer> m_Renderer;
std::shared_ptr<SDLPixelTexture> m_Texture;
PixelArray m_PixelArray;
fvec2 m_Center;
RGB m_Color;
protected:
ivec2 m_Bounds;
bool m_IsFilled = false;
bool m_PixelMode = false;
i32 m_PixelSize{ 1 };
public:
const std::shared_ptr<SDLPixelTexture>& texture() const;
std::shared_ptr<SDLPixelTexture>& texture();
constexpr const PixelArray& pixelArray() const { return m_PixelArray; }
constexpr PixelArray& pixelArray() { return m_PixelArray; }
constexpr const ivec2& position() const { return m_Texture->position(); }
constexpr ivec2& position() { return m_Texture->position(); }
constexpr frect boundingBox() const { return frect(m_Texture->boundingRect()); }
constexpr fvec2 center() const { return m_Texture->center(); }
constexpr const RGB& color() const { return m_Color; }
public:
void setColor(const RGB& color, const bool filled);
void render();
constexpr void scale(const fvec2& scale)
{
m_Texture->scale(scale);
}
constexpr void rotate(const f32 rotate)
{
m_Texture->rotate(rotate);
}
constexpr void translate(const fvec2& translate)
{
m_Texture->translate(translate);
}
protected:
virtual void setPixelSize(const i32 size);
virtual void computeBounds() {};
virtual void renderToPixelArray() {};
void initPixelArray();
void updateTexture();
protected:
/* render basics */
inline virtual void renderBasePoint(const i32 x, const i32 y, const RGB& color) override // from Abstract class RenderBase
{
if (m_PixelMode)
m_PixelArray.setPixel(x, y, color);
else
renderDot(x, y, color);
}
inline void renderDot(const i32 x, const i32 y, const RGB& color)
{
const i32 x0 = x;
const i32 y0 = y;
const i32 x1 = x0 + (m_PixelSize - 1);
const i32 y1 = y0 + (m_PixelSize - 1) ;
for (i32 py = y0; py <= y1; py++)
for (i32 px = x0; px <= x1; px++)
m_PixelArray.setPixel(px, py, color);
}
};
}
cpp
#include <zp/Graphics/SDLPixelTextureObject.h>
zp::SDLPixelTextureObject::SDLPixelTextureObject(const std::shared_ptr<SDLRenderer>& renderer) :
m_Renderer{ renderer }
{
m_Texture = std::make_shared<SDLPixelTexture>(renderer);
}
const std::shared_ptr<zp::SDLPixelTexture>& zp::SDLPixelTextureObject::texture() const
{
return m_Texture;
}
std::shared_ptr<zp::SDLPixelTexture>& zp::SDLPixelTextureObject::texture()
{
return m_Texture;
}
void zp::SDLPixelTextureObject::setColor(const RGB& color, const bool filled)
{
m_Color = color;
m_IsFilled = filled;
updateTexture();
}
void zp::SDLPixelTextureObject::setPixelSize(const i32 size) // to do
{
/*if (size < 2)
{
this->m_PixelMode = true;
this->m_PixelSize = 1;
}
else
{
this->m_PixelMode = false;
this->m_PixelSize = size;
}*/
}
void zp::SDLPixelTextureObject::initPixelArray()
{
m_PixelArray.init(m_Bounds.x + 1, m_Bounds.y + 1);
m_Texture->init(m_PixelArray.width(), m_PixelArray.height());
}
void zp::SDLPixelTextureObject::updateTexture()
{
renderToPixelArray();
m_Texture->update(m_PixelArray);
}
void zp::SDLPixelTextureObject::render()
{
m_Texture->render();
}
Grüße