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,
|
"cmake.buildBeforeRun": true,
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||||
"cmake.configureOnOpen": true,
|
"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
|
# Find all source files in a single current directory
|
||||||
|
|
||||||
# Save the name to DIR_Config_SRCS
|
# Save the name to DIR_Config_SRCS
|
||||||
aux_source_directory(. DIR_Config_SRCS)
|
aux_source_directory(. DIR_Config_SRCS)
|
||||||
|
|
||||||
|
# Initialize the SDK
|
||||||
|
pico_sdk_init()
|
||||||
|
|
||||||
include_directories(../epaper/Config)
|
include_directories(../epaper/Config)
|
||||||
include_directories(../epaper/e-Paper)
|
include_directories(../epaper/e-Paper)
|
||||||
|
|||||||
@@ -11,15 +11,16 @@ namespace Render {
|
|||||||
_screenBufferForeground(nullptr)
|
_screenBufferForeground(nullptr)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
|
_bufferDim = (_screenSize.x >> 3) * _screenSize.y;
|
||||||
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
|
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
|
||||||
clearBuffer(_screenBufferBackground, Color::White);
|
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
|
||||||
clearBuffer(_screenBufferBackground, Color::White);
|
clearBuffer(_screenBufferForeground, _bufferDim, Color::White);
|
||||||
|
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
|
||||||
|
|
||||||
// init display
|
// init display
|
||||||
DEV_Delay_ms(500);
|
DEV_Delay_ms(500);
|
||||||
if((rv=DEV_Module_Init())!=0){
|
if((rv=DEV_Module_Init())!=0){
|
||||||
printf("Init Failed, %d",rv);
|
printf("Init Failed, %d\n",rv);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EPD_2IN9_V2_Init();
|
EPD_2IN9_V2_Init();
|
||||||
@@ -38,24 +39,11 @@ namespace Render {
|
|||||||
free(_screenBufferForeground);
|
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() {
|
void Mare::render() {
|
||||||
clearBuffer(_screenBufferBackground, Color::White);
|
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
|
||||||
for (auto &d: _drawables) {
|
for (auto d: _drawables) {
|
||||||
if (d != nullptr){
|
if (d != nullptr)
|
||||||
d->render();
|
d->render();
|
||||||
} else {
|
|
||||||
printf("Drawable is expired");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
|
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){
|
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){
|
||||||
assert(x <= _screenSize.x);
|
assert(x <= _screenSize.x);
|
||||||
assert(y <= _screenSize.y);
|
assert(y <= _screenSize.y);
|
||||||
img += (sizeof(uint8_t)*x*(_screenSize.y>>3)+ sizeof(uint8_t)*(y>>3));
|
img += (sizeof(uint8_t)*y*(_screenSize.x/8) + sizeof(uint8_t)*(x/8));
|
||||||
if (value) *img &= ~0x01 << (y%8);
|
if (value) *img &= ~(0x80 >> (x%8));
|
||||||
else *img |= 0x01 << y%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);
|
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 Page;
|
||||||
class Drawable;
|
class Drawable;
|
||||||
|
class DrawablePoint;
|
||||||
|
|
||||||
typedef pos_t dim_t;
|
typedef pos_t dim_t;
|
||||||
typedef std::vector<std::shared_ptr<Page>> Pages;
|
typedef std::vector<std::shared_ptr<Page>> Pages;
|
||||||
@@ -62,26 +63,33 @@ namespace Render{
|
|||||||
// getters, setters
|
// getters, setters
|
||||||
public:
|
public:
|
||||||
void setSize(const dim_t size);
|
void setSize(const dim_t size);
|
||||||
const dim_t getSize();
|
const dim_t getSize() {return _screenSize;};
|
||||||
void setRotation(const ScreenRotation r);
|
void setRotation(const ScreenRotation r);
|
||||||
const ScreenRotation getRotation();
|
const ScreenRotation getRotation() {return _rotation;};
|
||||||
void setCurrentPage(const uint8_t p);
|
void setCurrentPage(const uint8_t p);
|
||||||
const Page& getCurrentPage();
|
const Page& getCurrentPage() {return *_pages.at(0).get();};
|
||||||
|
|
||||||
// drawables, pages
|
// drawables, pages
|
||||||
public:
|
public:
|
||||||
template <class T, class... Args>
|
template <class T, class... Args>
|
||||||
T* addDrawable(Args&&... args);
|
T* addDrawable(Args... args) {
|
||||||
void removeDrawable(const size_t id);
|
static size_t lastDrawableIndex(0);
|
||||||
void addPage();
|
static_assert(std::is_base_of_v<Drawable, T>, "Mare::addDrawable<T>() error, type T is not inherited from Drawable.");
|
||||||
void removePage(const uint8_t num);
|
auto newD = std::shared_ptr<T>(new T(lastDrawableIndex++, nullptr, this, args...));
|
||||||
const Drawables& getDrawables();
|
_drawables.push_back(std::move(newD));
|
||||||
const Pages& getPages();
|
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
|
//render
|
||||||
private:
|
private:
|
||||||
void clearBuffer(uint8_t* buffer, Color col);
|
void clearBuffer(uint8_t* buffer, uint16_t len, Color col);
|
||||||
void visitDrawables(Drawable* parent);
|
void visitDrawables(Drawable* parent) {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void render();
|
void render();
|
||||||
@@ -93,6 +101,7 @@ namespace Render{
|
|||||||
Pages _pages;
|
Pages _pages;
|
||||||
uint8_t* _screenBufferForeground;
|
uint8_t* _screenBufferForeground;
|
||||||
uint8_t* _screenBufferBackground;
|
uint8_t* _screenBufferBackground;
|
||||||
|
uint16_t _bufferDim;
|
||||||
Drawables _drawables; // background drawables for all the pages
|
Drawables _drawables; // background drawables for all the pages
|
||||||
ScreenRotation _rotation;
|
ScreenRotation _rotation;
|
||||||
|
|
||||||
@@ -102,22 +111,23 @@ namespace Render{
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Drawable {
|
class Drawable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Drawable(const size_t id, Drawable* parent, Mare* engine);
|
Drawable(const size_t id, Drawable* parent, Mare* engine);
|
||||||
~Drawable();
|
~Drawable();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void render();
|
virtual void render() {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setId(const size_t id);
|
void setId(const size_t id) { _id = id; };
|
||||||
void setOrigin(const pos_t origin);
|
void setOrigin(const pos_t origin) { _origin = origin; };
|
||||||
void setDirty();
|
void setDirty() {_dirty = true;};
|
||||||
void setBlendMode(const BlendMode mode);
|
void setBlendMode(const BlendMode mode) { _blendMode = BlendMode::Intersect; };
|
||||||
|
|
||||||
const pos_t getOrigin();
|
const pos_t getOrigin() { return _origin; };
|
||||||
const bbox2d_t getBBox();
|
const bbox2d_t getBBox() { return _bbox; };
|
||||||
const BlendMode getBlendMode();
|
const BlendMode getBlendMode() { return _blendMode; };
|
||||||
|
|
||||||
Mare* engine() { return _engine; };
|
Mare* engine() { return _engine; };
|
||||||
Drawable* parent() { return _parent; };
|
Drawable* parent() { return _parent; };
|
||||||
@@ -129,17 +139,19 @@ namespace Render{
|
|||||||
size_t _id;
|
size_t _id;
|
||||||
pos_t _origin;
|
pos_t _origin;
|
||||||
bbox2d_t _bbox;
|
bbox2d_t _bbox;
|
||||||
|
BlendMode _blendMode;
|
||||||
Drawables _children;
|
Drawables _children;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawablePoint: public Drawable {
|
class DrawablePoint: public Drawable {
|
||||||
|
|
||||||
|
public:
|
||||||
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
|
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
|
||||||
~DrawablePoint();
|
~DrawablePoint();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setSize(dim_t size);
|
void setSize(dim_t size) { _size = size; };
|
||||||
const dim_t getSize();
|
const dim_t getSize() { return _size; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render();
|
void render();
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ namespace Render {
|
|||||||
_parent(parent),
|
_parent(parent),
|
||||||
_engine(engine)
|
_engine(engine)
|
||||||
{
|
{
|
||||||
printf("Created Drawable id: %d\n", _id);
|
}
|
||||||
|
|
||||||
|
Drawable::~Drawable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||||
@@ -19,17 +22,22 @@ namespace Render {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawablePoint::~DrawablePoint() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void DrawablePoint::render() {
|
void DrawablePoint::render() {
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
if (parent() == nullptr)
|
if (parent() == nullptr)
|
||||||
buf = engine()->bBuffer();
|
buf = engine()->bBuffer();
|
||||||
else
|
else
|
||||||
buf = engine()->fBuffer();
|
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 xx(0); xx< _size.x; xx++){
|
||||||
for (uint16_t yy(0); yy < _size.y; yy++)
|
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>
|
#include <pico/stdlib.h>
|
||||||
|
|
||||||
// Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria
|
// Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria
|
||||||
@@ -17,12 +16,15 @@ int main(){
|
|||||||
|
|
||||||
auto viewer = Render::Mare(ssize);
|
auto viewer = Render::Mare(ssize);
|
||||||
|
|
||||||
Render::dim_t ps;
|
Render::dim_t ps; ps.x=0; ps.y=0;
|
||||||
ps.x=10;
|
|
||||||
ps.y=10;
|
|
||||||
auto point = viewer.addDrawable<Render::DrawablePoint>(ps);
|
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);
|
point->setOrigin(ps);
|
||||||
viewer.render();
|
viewer.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
|
|||||||
Reference in New Issue
Block a user