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

@@ -1,8 +1,11 @@
# Find all source files in a single current directory
# Save the name to DIR_Config_SRCS
aux_source_directory(. DIR_Config_SRCS)
# Initialize the SDK
pico_sdk_init()
include_directories(../epaper/Config)
include_directories(../epaper/e-Paper)

View File

@@ -11,15 +11,16 @@ namespace Render {
_screenBufferForeground(nullptr)
{
int rv;
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
clearBuffer(_screenBufferBackground, Color::White);
clearBuffer(_screenBufferBackground, Color::White);
_bufferDim = (_screenSize.x >> 3) * _screenSize.y;
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
clearBuffer(_screenBufferForeground, _bufferDim, Color::White);
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
// init display
DEV_Delay_ms(500);
if((rv=DEV_Module_Init())!=0){
printf("Init Failed, %d",rv);
printf("Init Failed, %d\n",rv);
return;
}
EPD_2IN9_V2_Init();
@@ -38,24 +39,11 @@ namespace Render {
free(_screenBufferForeground);
}
template <class T, class ... Args>
T* Mare::addDrawable(Args&&... args){
static size_t lastDrawableIndex(0);
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();
}
void Mare::render() {
clearBuffer(_screenBufferBackground, Color::White);
for (auto &d: _drawables) {
if (d != nullptr){
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
for (auto d: _drawables) {
if (d != nullptr)
d->render();
} else {
printf("Drawable is expired");
}
}
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
}
@@ -63,14 +51,14 @@ namespace Render {
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){
assert(x <= _screenSize.x);
assert(y <= _screenSize.y);
img += (sizeof(uint8_t)*x*(_screenSize.y>>3)+ sizeof(uint8_t)*(y>>3));
if (value) *img &= ~0x01 << (y%8);
else *img |= 0x01 << y%8;
img += (sizeof(uint8_t)*y*(_screenSize.x/8) + sizeof(uint8_t)*(x/8));
if (value) *img &= ~(0x80 >> (x%8));
else *img |= (0x80 >> (x%8));
}
void clearBuffer(uint8_t* buffer, Color col){
void Mare::clearBuffer(uint8_t* buffer, uint16_t len, Color col){
assert(buffer != nullptr);
std::memset(buffer, col == Color::White ? 0xff : 0x00, sizeof(buffer));
std::memset(buffer, col == Color::White ? 0xff : 0x00, len);
}
}

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();

View File

@@ -7,7 +7,10 @@ namespace Render {
_parent(parent),
_engine(engine)
{
printf("Created Drawable id: %d\n", _id);
}
Drawable::~Drawable() {
}
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
@@ -19,17 +22,22 @@ namespace Render {
}
DrawablePoint::~DrawablePoint() {
}
void DrawablePoint::render() {
uint8_t *buf;
if (parent() == nullptr)
buf = engine()->bBuffer();
else
buf = engine()->fBuffer();
//TODO: implement screen rotation and margin check
auto dx = engine()->getSize().x;
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);
engine()->setPixel(buf,dx-(getOrigin().x+xx),getOrigin().y+yy,true);
}
}
}