diff --git a/draw/Image.cpp b/draw/Image.cpp index 8267bb0..565c881 100644 --- a/draw/Image.cpp +++ b/draw/Image.cpp @@ -34,12 +34,12 @@ draw::Image::Image(void) : m_strokeColor(0,0,0,0), m_strokeSize(0) { - m_size.x = 32; - m_size.y = 32; + m_size.setX(32); + m_size.setY(32); Init(); } -draw::Image::Image(etk::Vector2D size) : +draw::Image::Image(ivec2 size) : m_renderingBuffer(NULL), m_pixFrame(NULL), m_renderBase(NULL), @@ -57,13 +57,13 @@ void draw::Image::Init(void) // basic element : draw::Color tmpBg(0,0,0,0); // preallocate data with a basic bg elements : - m_data.ReSize(m_size.x*m_size.y, tmpBg); - if (m_size.x*m_size.y > m_data.Size()) { + m_data.ReSize(m_size.x()*m_size.y(), tmpBg); + if (m_size.x()*m_size.y() > m_data.Size()) { DRAW_ERROR("Allocation of data buffer in error"); return; } // Allocate the AGG renderer system : - m_renderingBuffer = new agg::rendering_buffer((uint8_t*)&m_data[0], m_size.x, m_size.y, m_size.x*sizeof(draw::Color)); + m_renderingBuffer = new agg::rendering_buffer((uint8_t*)&m_data[0], m_size.x(), m_size.y(), m_size.x()*sizeof(draw::Color)); if (NULL == m_renderingBuffer) { DRAW_ERROR("Allocation of the m_renderingBuffer for SVG drawing error"); return; @@ -120,7 +120,7 @@ draw::Image::~Image(void) } } -void draw::Image::Resize(etk::Vector2D size) +void draw::Image::Resize(ivec2 size) { if (NULL != m_renderArea) { delete(m_renderArea); @@ -142,13 +142,13 @@ void draw::Image::Resize(etk::Vector2D size) // basic element : draw::Color tmpBg(0,0,0,0); // preallocate data with a basic bg elements : - m_data.ReSize(m_size.x*m_size.y, tmpBg); - if (m_size.x*m_size.y > m_data.Size()) { + m_data.ReSize(m_size.x()*m_size.y(), tmpBg); + if (m_size.x()*m_size.y() > m_data.Size()) { DRAW_ERROR("Allocation of data buffer in error"); return; } // Allocate the AGG renderer system : - m_renderingBuffer = new agg::rendering_buffer((uint8_t*)&m_data[0], m_size.x, m_size.y, m_size.x*sizeof(draw::Color)); + m_renderingBuffer = new agg::rendering_buffer((uint8_t*)&m_data[0], m_size.x(), m_size.y(), m_size.x()*sizeof(draw::Color)); if (NULL == m_renderingBuffer) { DRAW_ERROR("Allocation of the m_renderingBuffer for SVG drawing error"); return; @@ -196,22 +196,22 @@ void draw::Image::End(void) } -void draw::Image::MoveTo(etk::Vector2D pos) +void draw::Image::MoveTo(vec2 pos) { } -void draw::Image::MoveToAbs(etk::Vector2D pos) +void draw::Image::MoveToAbs(vec2 pos) { } -void draw::Image::LineTo(etk::Vector2D pos) +void draw::Image::LineTo(vec2 pos) { } -void draw::Image::LineToAbs(etk::Vector2D pos) +void draw::Image::LineToAbs(vec2 pos) { } @@ -226,7 +226,7 @@ void draw::Image::Draw(void) } -void draw::Image::Dot(etk::Vector2D pos) +void draw::Image::Dot(vec2 pos) { /* Begin(); @@ -237,7 +237,7 @@ void draw::Image::Dot(etk::Vector2D pos) Set(pos, m_fillColor); } -void draw::Image::Line(etk::Vector2D posStart, etk::Vector2D posEnd) +void draw::Image::Line(vec2 posStart, vec2 posEnd) { Begin(); MoveTo(posStart); @@ -245,27 +245,27 @@ void draw::Image::Line(etk::Vector2D posStart, etk::Vector2D posEn End(); } -void draw::Image::Rectangle(etk::Vector2D pos, etk::Vector2D size) +void draw::Image::Rectangle(vec2 pos, vec2 size) { Begin(); - etk::Vector2D tmp = pos; + vec2 tmp = pos; MoveTo(pos); - tmp.x += size.x; + tmp += vec2(size.x(),0); LineTo(tmp); - tmp.y += size.y; + tmp += vec2(0,size.y()); LineTo(tmp); - tmp.x -= size.x; + tmp -= vec2(size.x(),0); LineTo(tmp); Join(); End(); } -void draw::Image::Circle(etk::Vector2D pos, float radius, float angleStart, float angleStop) +void draw::Image::Circle(vec2 pos, float radius, float angleStart, float angleStop) { } -void draw::Image::Disc(etk::Vector2D pos, float radius, float angleStart, float angleStop) +void draw::Image::Disc(vec2 pos, float radius, float angleStart, float angleStop) { } @@ -274,34 +274,34 @@ void draw::Image::Disc(etk::Vector2D pos, float radius, float angleStart, void Grid::GenerateSDF() { // Pass 0 - etk::Vector2D tmpPos; - for (tmpPos.y=1 ; tmpPos.y p = Get(tmpPos); + ivec2 tmpPos(1,1); + for (tmpPos.setY(1) ; tmpPos.y()0 ; tmpPos.x--) { - etk::Vector2D p = Get(tmpPos); + for (tmpPos.setX(m_size.x()-2) ; tmpPos.x()>0 ; tmpPos-=vec2(1,0) ) { + ivec2 p = Get(tmpPos); Compare(p, tmpPos, 1, 0 ); Set(tmpPos, p ); } } // Pass 1 - for (tmpPos.y=m_size.y-2 ; tmpPos.y>0 ; tmpPos.y--) { - for (tmpPos.x=m_size.x-2 ; tmpPos.x>1 ; tmpPos.x--) { - etk::Vector2D p = Get(tmpPos); + for (tmpPos.setY(m_size.y()-2) ; tmpPos.y()>0 ; tmpPos-=vec2(0,1)) { + for (tmpPos.setX(m_size.x()-2) ; tmpPos.x()>1 ; tmpPos-=vec2(1,0)) { + ivec2 p = Get(tmpPos); Compare(p, tmpPos, 1, 0 ); Compare(p, tmpPos, 0, 1 ); Compare(p, tmpPos, -1, 1 ); Compare(p, tmpPos, 1, 1 ); Set(tmpPos, p); } - for (tmpPos.x=1 ; tmpPos.x p = Get(tmpPos); + for (tmpPos.setX(1) ; tmpPos.x()(0,0), m_size); + DistanceField(ivec2(0,0), m_size); } #endif #define META_DIST (8) -void draw::Image::DistanceField(etk::Vector2D pos, etk::Vector2D size, int32_t upscaler, int32_t startPos) +void draw::Image::DistanceField(ivec2 pos, ivec2 size, int32_t upscaler, int32_t startPos) { #ifndef BASIC_GRADIENT - float maxVal = 1/(1000.0*sqrt(META_DIST*META_DIST+META_DIST*META_DIST)); + float maxVal = 1/(1000.0*sqrtf(META_DIST*META_DIST+META_DIST*META_DIST)); etk::Vector2D tmpPos; // generate distance system ... matrix ... - Grid grid2(etk::Vector2D(META_DIST*2,META_DIST*2)); - for(tmpPos.y=0 ; tmpPos.y pos, etk::Vector2D tmpPos2; + ivec2 tmpPos2; int32_t newDist = 50000000; - for(tmpPos2.y=-META_DIST ; tmpPos2.y(META_DIST,META_DIST)); + int32_t tmpDist = grid2.Get(tmpPos2 + ivec2(META_DIST,META_DIST)); if (newDist > tmpDist) { newDist = tmpDist; } @@ -384,9 +384,9 @@ void draw::Image::DistanceField(etk::Vector2D pos, etk::Vector2D tmpPos; - for(tmpPos.y=0 ; tmpPos.y pos, etk::Vector2D elem1 = grid1.Get(tmpPos); - etk::Vector2D elem2 = grid2.Get(tmpPos); + for(tmpPos.setY(startPos) ; tmpPos.y() m_data; int32_t m_outsideVal; int32_t m_errorVal; - Grid(etk::Vector2D size) + Grid(ivec2 size) { m_size = size; m_outsideVal = 20; @@ -61,7 +61,7 @@ class Grid // basic element : int32_t tmpPoint = 0; // preallocate data with a basic bg elements : - m_data.ReSize(m_size.x*m_size.y, tmpPoint); + m_data.ReSize(m_size.x()*m_size.y(), tmpPoint); }; ~Grid(void) { }; void SetOutsideVal(int32_t newVal) @@ -74,34 +74,34 @@ class Grid } void SetInide(etk::Vector2D pos) { - if( pos.x>=0 && pos.x=0 && pos.y=0 && pos.x()=0 && pos.y() pos) { - if( pos.x>=0 && pos.x=0 && pos.y=0 && pos.x()=0 && pos.y() pos) { ; - if( pos.x>0 && pos.x0 && pos.y0 && pos.x()0 && pos.y() pos, int32_t val) { - if( pos.x>0 && pos.x0 && pos.y0 && pos.x()0 && pos.y() m_size; - etk::Vector > m_data; - int32_t m_outsideVal; - int32_t m_errorVal; - Grid(etk::Vector2D size) + ivec2 m_size; + etk::Vector m_data; + int32_t m_outsideVal; + int32_t m_errorVal; + Grid(ivec2 size) { m_size = size; m_outsideVal = 20; @@ -122,7 +122,7 @@ class Grid // basic element : etk::Vector2D tmpPoint(0,0); // preallocate data with a basic bg elements : - m_data.ReSize(m_size.x*m_size.y, tmpPoint); + m_data.ReSize(m_size.x()*m_size.y(), tmpPoint); }; ~Grid(void) { }; void SetOutsideVal(int32_t newVal) @@ -133,48 +133,46 @@ class Grid { m_errorVal = newVal; } - void SetInide(etk::Vector2D pos) + void SetInide(ivec2 pos) { //if( pos.x>=0 && pos.x=0 && pos.y pos) + void SetOutside(ivec2 pos) { //if( pos.x>=0 && pos.x=0 && pos.y Get(etk::Vector2D pos) + ivec2 Get(ivec2 pos) { //if( pos.x>0 && pos.x0 && pos.y(m_errorVal,m_errorVal); }; - void Set(etk::Vector2D pos, etk::Vector2D val) + void Set(ivec2 pos, ivec2 val) { //if( pos.x>0 && pos.x0 && pos.y &p, etk::Vector2D pos, int32_t offsetx, int32_t offsety ) + void Compare(ivec2 &p, ivec2 pos, int32_t offsetx, int32_t offsety ) { - pos.x += offsetx; - pos.y += offsety; - etk::Vector2D other = Get(pos); - other.x += offsetx; - other.y += offsety; - if (other.GetSquaredLength() < p.GetSquaredLength()) { + pos += ivec2(offsetx,offsety); + ivec2 other = Get(pos); + other += ivec2(offsetx,offsety); + if (other.dot(p) < p.dot(p)) { p = other; } }; @@ -192,7 +190,7 @@ namespace draw class Image { private: - etk::Vector2D m_size; + ivec2 m_size; etk::Vector m_data; agg::rendering_buffer * m_renderingBuffer; agg::pixfmt_rgba32 * m_pixFrame; @@ -206,7 +204,7 @@ namespace draw float m_strokeSize; public: // constructor : - Image(etk::Vector2D size); + Image(ivec2 size); Image(void); // destructor ~Image(void); @@ -221,20 +219,20 @@ namespace draw // -- basic tools : // ----------------------------------------------- public : - void Resize(etk::Vector2D size); + void Resize(ivec2 size); //void Resize(etk::Vector2D startPos, Vector2D size); - etk::Vector2D GetSize(void) const + ivec2 GetSize(void) const { return m_size; }; int32_t GetWidth(void) const { - return m_size.x; + return m_size.x(); }; int32_t GetHeight(void) const { - return m_size.y; + return m_size.y(); }; //void Move(etk::Vector2D pos); @@ -246,7 +244,7 @@ namespace draw void Clear(void) { - for (int32_t iii=0; iii pos) + draw::Color Get(ivec2 pos) { draw::Color outColor(0x00000000); - if( pos.x>0 && pos.x0 && pos.y0 && pos.x()0 && pos.y() pos, draw::Color newColor) + void Set(ivec2 pos, draw::Color newColor) { - if( pos.x>=0 && pos.x=0 && pos.y=0 && pos.x()=0 && pos.y() pos); - void MoveToAbs(etk::Vector2D pos); - void LineTo(etk::Vector2D pos); - void LineToAbs(etk::Vector2D pos); + void MoveTo(vec2 pos); + void MoveToAbs(vec2 pos); + void LineTo(vec2 pos); + void LineToAbs(vec2 pos); void Join(void); void Draw(void); - void Line(etk::Vector2D posStart, etk::Vector2D posEnd); - void Dot(etk::Vector2D pos); - void Rectangle(etk::Vector2D pos, etk::Vector2D size); - void Circle(etk::Vector2D pos, float radius, float angleStart=0, float angleStop=2*M_PI); - void Disc(etk::Vector2D pos, float radius, float angleStart=0, float angleStop=2*M_PI); + void Line(vec2 posStart, vec2 posEnd); + void Dot(vec2 pos); + void Rectangle(vec2 pos, vec2 size); + void Circle(vec2 pos, float radius, float angleStart=0, float angleStop=2*M_PI); + void Disc(vec2 pos, float radius, float angleStart=0, float angleStop=2*M_PI); // generate the distant field from the alpha value of the Image void DistanceField(void); - void DistanceField(etk::Vector2D pos, etk::Vector2D size, int32_t upscaler=1, int32_t startPos=0); + void DistanceField(ivec2 pos, ivec2 size, int32_t upscaler=1, int32_t startPos=0); void SaveFile(const char * file) {}; private: