draws wonky line
This commit is contained in:
@@ -5,7 +5,11 @@ namespace Render {
|
||||
Drawable::Drawable(const size_t id, Drawable* parent, Mare* engine):
|
||||
_id(id),
|
||||
_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() {
|
||||
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,dx-(getOrigin().x+xx),getOrigin().y+yy,true);
|
||||
}
|
||||
if (isDirty()){
|
||||
buf = getBuffer();
|
||||
//TODO: implement screen rotation and margin check
|
||||
auto dx = engine()->getSize().x;
|
||||
auto dy = engine()->getSize().y;
|
||||
for (uint16_t xx(0); xx< _size.x; xx++){
|
||||
for (uint16_t yy(0); yy < _size.y; yy++)
|
||||
{
|
||||
engine()->setPixel(buf,dx-(getOrigin().x+xx),getOrigin().y+yy,true);
|
||||
}
|
||||
}
|
||||
resetDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||
//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
|
||||
|
||||
Reference in New Issue
Block a user