implementation continues...
This commit is contained in:
@@ -5,8 +5,68 @@
|
||||
|
||||
namespace Render {
|
||||
|
||||
Mare::Mare(){
|
||||
Mare::Mare(dim_t size) :
|
||||
_screenSize(size),
|
||||
_screenBufferBackground(nullptr),
|
||||
_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);
|
||||
|
||||
// init display
|
||||
DEV_Delay_ms(500);
|
||||
if((rv=DEV_Module_Init())!=0){
|
||||
printf("Init Failed, %d",rv);
|
||||
return;
|
||||
}
|
||||
EPD_2IN9_V2_Init();
|
||||
EPD_2IN9_V2_Clear();
|
||||
printf("Mare render engine created\n");
|
||||
}
|
||||
|
||||
Mare::~Mare(){
|
||||
for (auto &d :_drawables) {
|
||||
d.reset();
|
||||
}
|
||||
for (auto &p : _pages){
|
||||
p.reset();
|
||||
}
|
||||
free(_screenBufferBackground);
|
||||
free(_screenBufferForeground);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Mare::addDrawable(T){
|
||||
static size_t lastDrawableIndex(0);
|
||||
auto newD = std::make_shared<T>(lastDrawableIndex++, )
|
||||
}
|
||||
|
||||
|
||||
void Mare::render() {
|
||||
clearBuffer(_screenBufferBackground, Color::White);
|
||||
for (auto &d: _drawables) {
|
||||
if (d != nullptr){
|
||||
d->render();
|
||||
} else {
|
||||
printf("Drawable is expired");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void clearBuffer(uint8_t* buffer, Color col){
|
||||
assert(buffer != nullptr);
|
||||
std::memset(buffer, col == Color::White ? 0xff : 0x00, sizeof(buffer));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user