we render a point!!!
This commit is contained in:
49
.vscode/settings.json
vendored
49
.vscode/settings.json
vendored
@@ -19,5 +19,52 @@
|
||||
"cmake.buildBeforeRun": true,
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"cmake.configureOnOpen": true,
|
||||
"cortex-debug.gdbPath": "gdb-multiarch"
|
||||
"cortex-debug.gdbPath": "gdb-multiarch",
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"map": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
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,6 +101,7 @@ namespace Render{
|
||||
Pages _pages;
|
||||
uint8_t* _screenBufferForeground;
|
||||
uint8_t* _screenBufferBackground;
|
||||
uint16_t _bufferDim;
|
||||
Drawables _drawables; // background drawables for all the pages
|
||||
ScreenRotation _rotation;
|
||||
|
||||
@@ -102,22 +111,23 @@ namespace Render{
|
||||
};
|
||||
|
||||
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 {
|
||||
|
||||
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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -1,4 +1,3 @@
|
||||
#include <stdio.h>
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
// Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria
|
||||
@@ -17,12 +16,15 @@ int main(){
|
||||
|
||||
auto viewer = Render::Mare(ssize);
|
||||
|
||||
Render::dim_t ps;
|
||||
ps.x=10;
|
||||
ps.y=10;
|
||||
Render::dim_t ps; ps.x=0; ps.y=0;
|
||||
|
||||
auto point = viewer.addDrawable<Render::DrawablePoint>(ps);
|
||||
point->setSize({16,16});
|
||||
for (auto d(0); d < 128-16; ++d){
|
||||
ps.x=d; ps.y=d;
|
||||
point->setOrigin(ps);
|
||||
viewer.render();
|
||||
}
|
||||
|
||||
|
||||
while(true){
|
||||
|
||||
Reference in New Issue
Block a user