draws wonky line
This commit is contained in:
@@ -4,9 +4,6 @@
|
|||||||
# 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)
|
||||||
include_directories(../epaper/Fonts)
|
include_directories(../epaper/Fonts)
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ 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);
|
if (x >= _screenSize.x) return;
|
||||||
assert(y <= _screenSize.y);
|
if (y >= _screenSize.y) return;
|
||||||
img += (sizeof(uint8_t)*y*(_screenSize.x/8) + sizeof(uint8_t)*(x/8));
|
img += (sizeof(uint8_t)*y*(_screenSize.x>>3) + sizeof(uint8_t)*(x>>3));
|
||||||
if (value) *img &= ~(0x80 >> (x%8));
|
if (value) *img &= ~(0x80 >> (x%8));
|
||||||
else *img |= (0x80 >> (x%8));
|
else *img |= (0x80 >> (x%8));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pico/stdlib.h>
|
#include <pico/stdlib.h>
|
||||||
|
#include <pico/float.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <DEV_Config.h>
|
#include <DEV_Config.h>
|
||||||
@@ -14,6 +15,7 @@ extern "C" {
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
namespace Render{
|
namespace Render{
|
||||||
|
|
||||||
@@ -94,6 +96,11 @@ namespace Render{
|
|||||||
public:
|
public:
|
||||||
void render();
|
void render();
|
||||||
void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value);
|
void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value);
|
||||||
|
void clearScreen() {
|
||||||
|
EPD_2IN9_V2_Clear();
|
||||||
|
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
|
||||||
|
EPD_2IN9_V2_Display_Base(_screenBufferBackground);
|
||||||
|
}
|
||||||
|
|
||||||
// members
|
// members
|
||||||
private:
|
private:
|
||||||
@@ -123,12 +130,19 @@ namespace Render{
|
|||||||
void setId(const size_t id) { _id = id; };
|
void setId(const size_t id) { _id = id; };
|
||||||
void setOrigin(const pos_t origin) { _origin = origin; };
|
void setOrigin(const pos_t origin) { _origin = origin; };
|
||||||
void setDirty() {_dirty = true;};
|
void setDirty() {_dirty = true;};
|
||||||
|
void resetDirty() {_dirty = false;};
|
||||||
void setBlendMode(const BlendMode mode) { _blendMode = BlendMode::Intersect; };
|
void setBlendMode(const BlendMode mode) { _blendMode = BlendMode::Intersect; };
|
||||||
|
|
||||||
|
const bool isDirty() {return _dirty;}
|
||||||
const pos_t getOrigin() { return _origin; };
|
const pos_t getOrigin() { return _origin; };
|
||||||
const bbox2d_t getBBox() { return _bbox; };
|
const bbox2d_t getBBox() { return _bbox; };
|
||||||
const BlendMode getBlendMode() { return _blendMode; };
|
const BlendMode getBlendMode() { return _blendMode; };
|
||||||
|
|
||||||
|
uint8_t* getBuffer() {
|
||||||
|
if (_parent == nullptr) return engine()->bBuffer();
|
||||||
|
else return engine()->fBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
Mare* engine() { return _engine; };
|
Mare* engine() { return _engine; };
|
||||||
Drawable* parent() { return _parent; };
|
Drawable* parent() { return _parent; };
|
||||||
|
|
||||||
@@ -162,26 +176,27 @@ namespace Render{
|
|||||||
};
|
};
|
||||||
|
|
||||||
class DrawableLine: public Drawable {
|
class DrawableLine: public Drawable {
|
||||||
|
|
||||||
DrawableLine();
|
public:
|
||||||
~DrawableLine();
|
DrawableLine(const size_t id, Drawable* parent, Mare* engine);
|
||||||
|
~DrawableLine();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setThickness(uint16_t thickness);
|
void setThickness(uint16_t thickness) {_thickness = thickness;};
|
||||||
const uint16_t getThickness();
|
const uint16_t getThickness() {return _thickness;};
|
||||||
void setRotation(float rotation);
|
void setRotation(float rotation) {_rotation = rotation;};
|
||||||
const float getRotation();
|
const float getRotation() {return _rotation;};
|
||||||
void setLength(uint16_t length);
|
void setLength(uint16_t length) {_lenght = length;};
|
||||||
const uint16_t getLength();
|
const uint16_t getLength() {return _lenght;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render(); // difficult business
|
void render(); // difficult business
|
||||||
|
|
||||||
// members
|
// members
|
||||||
private:
|
private:
|
||||||
uint16_t _thickness;
|
uint16_t _thickness;
|
||||||
uint16_t _lenght;
|
uint16_t _lenght;
|
||||||
float _rotation;
|
float _rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawableRectangle: public Drawable {
|
class DrawableRectangle: public Drawable {
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ namespace Render {
|
|||||||
Drawable::Drawable(const size_t id, Drawable* parent, Mare* engine):
|
Drawable::Drawable(const size_t id, Drawable* parent, Mare* engine):
|
||||||
_id(id),
|
_id(id),
|
||||||
_parent(parent),
|
_parent(parent),
|
||||||
_engine(engine)
|
_engine(engine),
|
||||||
|
_origin({0,0}),
|
||||||
|
_bbox({0,0,0,0}),
|
||||||
|
_blendMode(Render::BlendMode::Intersect),
|
||||||
|
_dirty(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,23 +32,58 @@ namespace Render {
|
|||||||
|
|
||||||
void DrawablePoint::render() {
|
void DrawablePoint::render() {
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
if (parent() == nullptr)
|
if (isDirty()){
|
||||||
buf = engine()->bBuffer();
|
buf = getBuffer();
|
||||||
else
|
//TODO: implement screen rotation and margin check
|
||||||
buf = engine()->fBuffer();
|
auto dx = engine()->getSize().x;
|
||||||
//TODO: implement screen rotation and margin check
|
auto dy = engine()->getSize().y;
|
||||||
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,dx-(getOrigin().x+xx),getOrigin().y+yy,true);
|
||||||
engine()->setPixel(buf,dx-(getOrigin().x+xx),getOrigin().y+yy,true);
|
}
|
||||||
}
|
}
|
||||||
|
resetDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||||
//Line
|
//Line
|
||||||
|
DrawableLine::DrawableLine(const size_t id, Drawable* parent, Mare* engine):
|
||||||
|
Drawable(id, parent,engine),
|
||||||
|
_thickness(1),
|
||||||
|
_lenght(0),
|
||||||
|
_rotation(0.0f)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawableLine::~DrawableLine(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawableLine::render(){
|
||||||
|
uint8_t* buf;
|
||||||
|
if (isDirty()) {
|
||||||
|
buf = getBuffer();
|
||||||
|
float cx,sx;
|
||||||
|
auto dx = engine()->getSize().x;
|
||||||
|
auto dy = engine()->getSize().y;
|
||||||
|
sincosf(_rotation,&sx,&cx); // use optimized float instructions
|
||||||
|
uint16_t endX = round(cx*(float)_lenght);
|
||||||
|
for(uint16_t yy(0); yy <= _thickness; ++yy){
|
||||||
|
for(uint16_t xx(0); xx <= endX; ++xx){
|
||||||
|
float dydx = cx == 0.0f ? 0 : (sx/cx);
|
||||||
|
float dxdy = sx == 0.0f ? 0 : (cx/sx);
|
||||||
|
uint16_t y = getOrigin().y+yy+xx*dydx;
|
||||||
|
uint16_t x = dx-(getOrigin().x+xx+yy);
|
||||||
|
engine()->setPixel(buf,x,y,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||||
//Rectangle
|
//Rectangle
|
||||||
|
|||||||
30
src/main.cpp
30
src/main.cpp
@@ -16,22 +16,30 @@ int main(){
|
|||||||
|
|
||||||
auto viewer = Render::Mare(ssize);
|
auto viewer = Render::Mare(ssize);
|
||||||
|
|
||||||
Render::dim_t ps; ps.x=0; ps.y=0;
|
Render::dim_t ps; ps.x=8; ps.y=8;
|
||||||
|
|
||||||
auto point = viewer.addDrawable<Render::DrawablePoint>(ps);
|
auto line = viewer.addDrawable<Render::DrawableLine>();
|
||||||
point->setSize({16,16});
|
line->setThickness(4);
|
||||||
for (auto d(0); d < 128-16; ++d){
|
line->setOrigin(ps);
|
||||||
ps.x=d; ps.y=d;
|
while (true){
|
||||||
point->setOrigin(ps);
|
line->setRotation(0);
|
||||||
viewer.render();
|
for (auto d(8); d < 128; d+=8){
|
||||||
|
line->setLength(d);
|
||||||
|
line->setDirty();
|
||||||
|
viewer.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (float a(0.0f); a<=M_PI_2; a+=0.1){
|
||||||
|
line->setRotation(a);
|
||||||
|
line->setDirty();
|
||||||
|
viewer.render();
|
||||||
|
}
|
||||||
|
viewer.clearScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
printf("[%u] Hello, world!\n",i++);
|
|
||||||
gpio_put(LED_PIN,s);
|
gpio_put(LED_PIN,s);
|
||||||
s = s ? false : true;
|
s = s ? false : true;
|
||||||
|
sleep_ms(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user