diff --git a/libs/mare/CMakeLists.txt b/libs/mare/CMakeLists.txt index d9ad5ce..011895e 100644 --- a/libs/mare/CMakeLists.txt +++ b/libs/mare/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(Mare PUBLIC Config ePaper Fonts pico_stdlib hardware_spi) \ No newline at end of file diff --git a/libs/mare/mare.cpp b/libs/mare/mare.cpp index be2d289..5eb7d32 100644 --- a/libs/mare/mare.cpp +++ b/libs/mare/mare.cpp @@ -38,10 +38,13 @@ namespace Render { free(_screenBufferForeground); } - template - void Mare::addDrawable(T){ + template + T* Mare::addDrawable(Args&&... args){ static size_t lastDrawableIndex(0); - auto newD = std::make_shared(lastDrawableIndex++, ) + static_assert(std::is_base_of_v, "Scene::createDrawable() error, type T is not inherited from Drawable."); + auto newD = std::make_shared(lastDrawableIndex++, nullptr, this, std::forward(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){ diff --git a/libs/mare/mare.h b/libs/mare/mare.h index 04a7bea..79e7dfb 100644 --- a/libs/mare/mare.h +++ b/libs/mare/mare.h @@ -1,12 +1,13 @@ /******************************************* * Most Awesome Renderer Ever *******************************************/ -#pragma once +#include +#include + extern "C" { #include #include - #include } #include @@ -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 - void addDrawable(T); + template + 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; - }; } \ No newline at end of file diff --git a/libs/mare/mare_drawables.cpp b/libs/mare/mare_drawables.cpp index 0f29d44..aece3c1 100644 --- a/libs/mare/mare_drawables.cpp +++ b/libs/mare/mare_drawables.cpp @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 828fda7..ce0500a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,11 +18,6 @@ pico_add_extra_outputs(emon) # Pull in our pico_stdlib which aggregates commonly used features target_link_libraries(emon - hardware_spi pico_stdlib - Config - ePaper - GUI - Fonts - MyLibs + Mare ) diff --git a/src/main.cpp b/src/main.cpp index b937962..5510f4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,29 +2,8 @@ #include // Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria -extern "C" { - #include -} - -#include #include -void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){ - img += (sizeof(uint8_t)*x*(EPD_2IN9_V2_WIDTH>>3)+ sizeof(uint8_t)*(y>>3)); - if (value) *img &= ~0x01 << (y%8); - else *img |= 0x01 << y%8; -} - -void drawSquare(uint8_t* img, uint16_t x, uint16_t y, uint16_t dimX, uint16_t dimY, bool col){ - for (auto xx(0); xx< dimX; xx++){ - for (auto yy(0); yy < dimY; yy++) - { - setPixel(img,x+xx,y+yy,col); - } - - } -} - int main(){ stdio_init_all(); const uint LED_PIN = PICO_DEFAULT_LED_PIN; @@ -32,11 +11,25 @@ int main(){ gpio_set_dir(LED_PIN, GPIO_OUT); bool s=false; uint i(0); + Render::dim_t ssize; + ssize.x = EPD_2IN9_V2_WIDTH; + ssize.y = EPD_2IN9_V2_HEIGHT; + + auto viewer = Render::Mare(ssize); + + Render::dim_t ps; + ps.x=10; + ps.y=10; + auto point = viewer.addDrawable(ps); + point->setOrigin(ps); + viewer.render(); + while(true){ printf("[%u] Hello, world!\n",i++); gpio_put(LED_PIN,s); s = s ? false : true; + } return 0;