we render a point!!!

This commit is contained in:
Emanuele Trabattoni
2021-05-26 23:38:07 +02:00
parent 9f1990b977
commit 8325dcfdd8
6 changed files with 122 additions and 62 deletions

View File

@@ -46,6 +46,7 @@ namespace Render{
class Page;
class Drawable;
class DrawablePoint;
typedef pos_t dim_t;
typedef std::vector<std::shared_ptr<Page>> Pages;
@@ -62,26 +63,33 @@ namespace Render{
// getters, setters
public:
void setSize(const dim_t size);
const dim_t getSize();
const dim_t getSize() {return _screenSize;};
void setRotation(const ScreenRotation r);
const ScreenRotation getRotation();
const ScreenRotation getRotation() {return _rotation;};
void setCurrentPage(const uint8_t p);
const Page& getCurrentPage();
const Page& getCurrentPage() {return *_pages.at(0).get();};
// drawables, pages
public:
template <class T, class ... Args>
T* addDrawable(Args&&... args);
void removeDrawable(const size_t id);
void addPage();
void removePage(const uint8_t num);
const Drawables& getDrawables();
const Pages& getPages();
template <class T, class... Args>
T* addDrawable(Args... args) {
static size_t lastDrawableIndex(0);
static_assert(std::is_base_of_v<Drawable, T>, "Mare::addDrawable<T>() error, type T is not inherited from Drawable.");
auto newD = std::shared_ptr<T>(new T(lastDrawableIndex++, nullptr, this, args...));
_drawables.push_back(std::move(newD));
auto foo = _drawables.back().get();
return static_cast<T*>(foo);
}
void removeDrawable(const size_t id) {};
void addPage() {};
void removePage(const uint8_t num) {};
const Drawables& getDrawables() {return _drawables;};
const Pages& getPages() {return _pages;};
//render
private:
void clearBuffer(uint8_t* buffer, Color col);
void visitDrawables(Drawable* parent);
void clearBuffer(uint8_t* buffer, uint16_t len, Color col);
void visitDrawables(Drawable* parent) {};
public:
void render();
@@ -93,31 +101,33 @@ namespace Render{
Pages _pages;
uint8_t* _screenBufferForeground;
uint8_t* _screenBufferBackground;
uint16_t _bufferDim;
Drawables _drawables; // background drawables for all the pages
ScreenRotation _rotation;
public:
uint8_t* bBuffer() {return _screenBufferBackground;}
uint8_t* fBuffer() {return _screenBufferForeground;}
uint8_t* bBuffer() { return _screenBufferBackground; }
uint8_t* fBuffer() { return _screenBufferForeground; }
};
class Drawable {
public:
Drawable(const size_t id, Drawable* parent, Mare* engine);
~Drawable();
public:
virtual void render();
virtual void render() {};
public:
void setId(const size_t id);
void setOrigin(const pos_t origin);
void setDirty();
void setBlendMode(const BlendMode mode);
void setId(const size_t id) { _id = id; };
void setOrigin(const pos_t origin) { _origin = origin; };
void setDirty() {_dirty = true;};
void setBlendMode(const BlendMode mode) { _blendMode = BlendMode::Intersect; };
const pos_t getOrigin();
const bbox2d_t getBBox();
const BlendMode getBlendMode();
const pos_t getOrigin() { return _origin; };
const bbox2d_t getBBox() { return _bbox; };
const BlendMode getBlendMode() { return _blendMode; };
Mare* engine() { return _engine; };
Drawable* parent() { return _parent; };
@@ -129,17 +139,19 @@ namespace Render{
size_t _id;
pos_t _origin;
bbox2d_t _bbox;
BlendMode _blendMode;
Drawables _children;
};
class DrawablePoint: public Drawable {
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
~DrawablePoint();
public:
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
~DrawablePoint();
public:
void setSize(dim_t size);
const dim_t getSize();
void setSize(dim_t size) { _size = size; };
const dim_t getSize() { return _size; };
private:
void render();