does not link, we are close..

This commit is contained in:
Emanuele Trabattoni
2021-05-25 22:35:25 +02:00
parent f5ce925153
commit 9f1990b977
6 changed files with 64 additions and 45 deletions

View File

@@ -10,4 +10,4 @@ include_directories(../epaper/Fonts)
# Generate the link library
add_library(Mare ${DIR_Config_SRCS})
target_link_libraries(Mare PUBLIC Config ePaper pico_stdlib hardware_spi)
target_link_libraries(Mare PUBLIC Config ePaper Fonts pico_stdlib hardware_spi)

View File

@@ -38,10 +38,13 @@ namespace Render {
free(_screenBufferForeground);
}
template <class T>
void Mare::addDrawable(T){
template <class T, class ... Args>
T* Mare::addDrawable(Args&&... args){
static size_t lastDrawableIndex(0);
auto newD = std::make_shared<T>(lastDrawableIndex++, )
static_assert(std::is_base_of_v<Drawable, T>, "Scene::createDrawable<T>() error, type T is not inherited from Drawable.");
auto newD = std::make_shared<T>(lastDrawableIndex++, nullptr, this, std::forward<Args>(args)...);
_drawables.push_back(newD);
return newD.get();
}
@@ -54,6 +57,7 @@ namespace Render {
printf("Drawable is expired");
}
}
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
}
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){

View File

@@ -1,12 +1,13 @@
/*******************************************
* Most Awesome Renderer Ever
*******************************************/
#pragma once
#include <stdio.h>
#include <pico/stdlib.h>
extern "C" {
#include <DEV_Config.h>
#include <EPD_2in9_V2.h>
#include <fonts.h>
}
#include <vector>
@@ -52,9 +53,11 @@ namespace Render{
class Mare {
friend class Drawable;
friend class Page;
Mare(dim_t size);
~Mare();
public:
Mare(dim_t size);
~Mare();
// getters, setters
public:
@@ -67,8 +70,8 @@ namespace Render{
// drawables, pages
public:
template <class T>
void addDrawable(T);
template <class T, class ... Args>
T* addDrawable(Args&&... args);
void removeDrawable(const size_t id);
void addPage();
void removePage(const uint8_t num);
@@ -77,9 +80,11 @@ namespace Render{
//render
private:
void render();
void clearBuffer(uint8_t* buffer, Color col);
void visitDrawables(Drawable* parent);
public:
void render();
void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value);
// members
@@ -90,11 +95,15 @@ namespace Render{
uint8_t* _screenBufferBackground;
Drawables _drawables; // background drawables for all the pages
ScreenRotation _rotation;
public:
uint8_t* bBuffer() {return _screenBufferBackground;}
uint8_t* fBuffer() {return _screenBufferForeground;}
};
class Drawable {
public:
Drawable(const size_t id, const Drawable* parent, const Mare* engine);
Drawable(const size_t id, Drawable* parent, Mare* engine);
~Drawable();
public:
@@ -106,12 +115,16 @@ namespace Render{
void setDirty();
void setBlendMode(const BlendMode mode);
const pos_t getOrigin();
const bbox2d_t getBBox();
const BlendMode getBlendMode();
Mare* engine() { return _engine; };
Drawable* parent() { return _parent; };
private:
const Drawable* _parent;
const Mare* _engine;
Drawable* _parent;
Mare* _engine;
bool _dirty;
size_t _id;
pos_t _origin;
@@ -121,7 +134,7 @@ namespace Render{
class DrawablePoint: public Drawable {
DrawablePoint(const size_t id, const Drawable* parent, const Mare* engine, dim_t size);
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
~DrawablePoint();
public:
@@ -240,6 +253,5 @@ namespace Render{
private:
Drawables _backDrawables;
Drawables _frontDrawables;
};
}

View File

@@ -2,7 +2,7 @@
namespace Render {
Drawable::Drawable(const size_t id, const Drawable* parent, const Mare* engine):
Drawable::Drawable(const size_t id, Drawable* parent, Mare* engine):
_id(id),
_parent(parent),
_engine(engine)
@@ -12,13 +12,28 @@ namespace Render {
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
//Point
DrawablePoint::DrawablePoint(const size_t id, const Drawable* parent, const Mare* engine, dim_t size):
DrawablePoint::DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size):
Drawable(id, parent,engine),
_size(size)
{
}
void DrawablePoint::render() {
uint8_t *buf;
if (parent() == nullptr)
buf = engine()->bBuffer();
else
buf = engine()->fBuffer();
for (uint16_t xx(0); xx< _size.x; xx++){
for (uint16_t yy(0); yy < _size.y; yy++)
{
engine()->setPixel(buf,getOrigin().x+xx,getOrigin().y+yy,true);
}
}
}
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
//Line