improved rectangle
This commit is contained in:
@@ -9,7 +9,8 @@ namespace Render {
|
|||||||
_screenSize(size),
|
_screenSize(size),
|
||||||
_screenBufferBackground(nullptr),
|
_screenBufferBackground(nullptr),
|
||||||
_screenBufferForeground(nullptr),
|
_screenBufferForeground(nullptr),
|
||||||
_rotation(rot)
|
_rotation(rot),
|
||||||
|
_full(true)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
_bufferDim = (_screenSize.x >> 3) * _screenSize.y;
|
_bufferDim = (_screenSize.x >> 3) * _screenSize.y;
|
||||||
@@ -49,7 +50,12 @@ namespace Render {
|
|||||||
if (d != nullptr)
|
if (d != nullptr)
|
||||||
d->render();
|
d->render();
|
||||||
};
|
};
|
||||||
|
if (!_full)
|
||||||
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
|
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
|
||||||
|
else {
|
||||||
|
EPD_2IN9_V2_Display(_screenBufferBackground);
|
||||||
|
_full = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mare::clearBuffer(uint8_t* buffer, uint16_t len, Color col){
|
void Mare::clearBuffer(uint8_t* buffer, uint16_t len, Color col){
|
||||||
@@ -126,7 +132,7 @@ namespace Render {
|
|||||||
void Mare::clearScreen() {
|
void Mare::clearScreen() {
|
||||||
EPD_2IN9_V2_Clear();
|
EPD_2IN9_V2_Clear();
|
||||||
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
|
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
|
||||||
EPD_2IN9_V2_Display(_screenBufferBackground);
|
_full = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -116,6 +116,7 @@ namespace Render{
|
|||||||
uint16_t _bufferDim;
|
uint16_t _bufferDim;
|
||||||
Drawables _drawables; // background drawables for all the pages
|
Drawables _drawables; // background drawables for all the pages
|
||||||
ScreenRotation _rotation;
|
ScreenRotation _rotation;
|
||||||
|
bool _full;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
uint8_t* bBuffer() { return _screenBufferBackground; }
|
uint8_t* bBuffer() { return _screenBufferBackground; }
|
||||||
@@ -188,7 +189,11 @@ namespace Render{
|
|||||||
~DrawableLine();
|
~DrawableLine();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setThickness(uint16_t thickness) {_thickness = thickness;};
|
void setThickness(uint16_t thickness) {
|
||||||
|
uint8_t d = thickness >> 1;
|
||||||
|
_thickness = thickness;
|
||||||
|
_ofst = (d % 2)==0 ? d + 1: d;
|
||||||
|
};
|
||||||
const uint16_t getThickness() {return _thickness;};
|
const uint16_t getThickness() {return _thickness;};
|
||||||
void setRotation(uint16_t rotation) {_rotation = rotation;};
|
void setRotation(uint16_t rotation) {_rotation = rotation;};
|
||||||
const uint16_t getRotation() {return _rotation;};
|
const uint16_t getRotation() {return _rotation;};
|
||||||
@@ -203,6 +208,7 @@ namespace Render{
|
|||||||
uint16_t _thickness;
|
uint16_t _thickness;
|
||||||
uint16_t _length;
|
uint16_t _length;
|
||||||
uint16_t _rotation;
|
uint16_t _rotation;
|
||||||
|
uint8_t _ofst;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawableRectangle: public Drawable {
|
class DrawableRectangle: public Drawable {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Render {
|
|||||||
_length(0),
|
_length(0),
|
||||||
_rotation(0)
|
_rotation(0)
|
||||||
{
|
{
|
||||||
|
setThickness(_thickness); // only to calc offset
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawableLine::~DrawableLine()
|
DrawableLine::~DrawableLine()
|
||||||
@@ -82,7 +82,7 @@ namespace Render {
|
|||||||
res.x = t-(_thickness>>1);
|
res.x = t-(_thickness>>1);
|
||||||
res.y = _rotation == 90 ? xx : _length-xx;
|
res.y = _rotation == 90 ? xx : _length-xx;
|
||||||
} else {
|
} else {
|
||||||
res = e->rotateXY(xx,t-(_thickness>>1),_rotation/180.0f*M_PI);
|
res = e->rotateXY(xx,t-_ofst,_rotation/180.0f*M_PI);
|
||||||
}
|
}
|
||||||
e->setPixel(buf,res.x+o.x,res.y+o.y,getBlendMode());
|
e->setPixel(buf,res.x+o.x,res.y+o.y,getBlendMode());
|
||||||
|
|
||||||
@@ -113,15 +113,13 @@ namespace Render {
|
|||||||
void DrawableRectangle::createOutline(){
|
void DrawableRectangle::createOutline(){
|
||||||
auto e = engine();
|
auto e = engine();
|
||||||
pos_t o = getOrigin();
|
pos_t o = getOrigin();
|
||||||
float cx,sx;
|
auto rf = (_rotation % 360)/180.0f*M_PI;
|
||||||
|
|
||||||
if (l1 == nullptr) l1 = e->addDrawable<DrawableLine>();
|
if (l1 == nullptr) l1 = e->addDrawable<DrawableLine>();
|
||||||
if (l2 == nullptr) l2 = e->addDrawable<DrawableLine>();
|
if (l2 == nullptr) l2 = e->addDrawable<DrawableLine>();
|
||||||
if (l3 == nullptr) l3 = e->addDrawable<DrawableLine>();
|
if (l3 == nullptr) l3 = e->addDrawable<DrawableLine>();
|
||||||
if (l4 == nullptr) l4 = e->addDrawable<DrawableLine>();
|
if (l4 == nullptr) l4 = e->addDrawable<DrawableLine>();
|
||||||
|
|
||||||
_rotation %= 360;
|
|
||||||
sincosf(_rotation/180.0f*M_PI, &sx, &cx);
|
|
||||||
|
|
||||||
l1->setRotation(_rotation);
|
l1->setRotation(_rotation);
|
||||||
l1->setLength(_dim.x);
|
l1->setLength(_dim.x);
|
||||||
l1->setThickness(_thickness);
|
l1->setThickness(_thickness);
|
||||||
@@ -135,10 +133,18 @@ namespace Render {
|
|||||||
l4->setLength(_dim.y);
|
l4->setLength(_dim.y);
|
||||||
l4->setThickness(_thickness);
|
l4->setThickness(_thickness);
|
||||||
|
|
||||||
|
uint8_t of = l2->_ofst;
|
||||||
|
pos_t res = {0,0};
|
||||||
l1->setOrigin(o);
|
l1->setOrigin(o);
|
||||||
l2->setOrigin({(p_t)(o.x+(_dim.x-_thickness+1)*cx), (p_t)(o.y+(_dim.x-_thickness+1)*sx)});
|
|
||||||
l3->setOrigin({(p_t)(o.x-(_dim.y-_thickness+1)*sx), (p_t)(o.y+(_dim.y-_thickness+1)*cx)});
|
res = e->rotateXY((_dim.x-of),0,rf);
|
||||||
l4->setOrigin(o);
|
l2->setOrigin({(p_t)(o.x+res.x), (p_t)(o.y+res.y)});
|
||||||
|
|
||||||
|
res = e->rotateXY(0,(_dim.y-of),rf);
|
||||||
|
l3->setOrigin({(p_t)(o.x+res.x), (p_t)(o.y+res.y)});
|
||||||
|
|
||||||
|
res = e->rotateXY(of,-of,rf);
|
||||||
|
l4->setOrigin({(p_t)(o.x+res.x), (p_t)(o.y+res.y)});
|
||||||
|
|
||||||
l1->setDirty();
|
l1->setDirty();
|
||||||
l2->setDirty();
|
l2->setDirty();
|
||||||
|
|||||||
14
src/main.cpp
14
src/main.cpp
@@ -37,17 +37,17 @@ int main(){
|
|||||||
line3->setOrigin(viewer.getCenter());
|
line3->setOrigin(viewer.getCenter());
|
||||||
line3->setBlendMode(Render::BlendMode::Add);
|
line3->setBlendMode(Render::BlendMode::Add);
|
||||||
|
|
||||||
rect->setDimension({48,32});
|
rect->setDimension({48,48});
|
||||||
rect->setOrigin({8,8});
|
rect->setOrigin(viewer.getCenter());
|
||||||
rect->setOutline(true);
|
rect->setOutline(true);
|
||||||
rect->setThickness(3);
|
rect->setThickness(6);
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
line3->setThickness(2);
|
line3->setThickness(2);
|
||||||
for (uint16_t a(0); a<=360; a+=360/32){
|
for (uint16_t a(0); a<=360; a+=360/36){
|
||||||
line3->setRotation(a);
|
//line3->setRotation(a);
|
||||||
//rect->setRotation(a);
|
rect->setRotation(a);
|
||||||
line3->setDirty();
|
//line3->setDirty();
|
||||||
c1->setDirty();
|
c1->setDirty();
|
||||||
c2->setDirty();
|
c2->setDirty();
|
||||||
rect->setDirty();
|
rect->setDirty();
|
||||||
|
|||||||
Reference in New Issue
Block a user