From ffcaa340372cf9cb64cbc9082326303bba2da109 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Wed, 9 Nov 2011 22:17:02 +0100 Subject: [PATCH] Create a better inteface for gnenerating triangle in the colored OObject system --- Sources/ewolOObject2DColored.cpp | 208 +++++++++++++++---------------- Sources/ewolOObject2DColored.h | 9 +- 2 files changed, 107 insertions(+), 110 deletions(-) diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp index 873bb9a4..873138af 100644 --- a/Sources/ewolOObject2DColored.cpp +++ b/Sources/ewolOObject2DColored.cpp @@ -33,6 +33,7 @@ ewol::OObject2DColored::OObject2DColored(void) { + m_triElement = 0; SetColor(1.0, 1.0, 1.0, 1.0); } @@ -68,6 +69,7 @@ void ewol::OObject2DColored::Draw(void) } + void ewol::OObject2DColored::UpdateOrigin(float x, float y) { for (int32_t iii=0; iii=3) { + GenerateTriangle(); + } +} + +void ewol::OObject2DColored::SetPoint(float x, float y) +{ + m_triangle[m_triElement].x = x; + m_triangle[m_triElement].y = y; + m_triElement++; + if (m_triElement>=3) { + GenerateTriangle(); + } +} + + +void ewol::OObject2DColored::ResetCount(void) +{ + m_triElement = 0; + m_color[1] = m_color[0]; + m_color[2] = m_color[0]; +} + void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float thickness) { + ResetCount(); if (sx == ex && sy == ey) { EWOL_WARNING("Try to draw an line width 0"); return; @@ -108,84 +178,34 @@ void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float //EWOL_DEBUG("teta = " << (teta*180/(M_PI)) << " deg." ); double offsety = sin(teta-M_PI/2) * (thickness/2); double offsetx = cos(teta-M_PI/2) * (thickness/2); - // just for debug ... - /*if (offsetx <= 0.001 && offsetx >= -0.001) { - offsetx = 0; - } - if (offsety <= 0.001 && offsety >= -0.001) { - offsety = 0; - } - EWOL_DEBUG("ofset (" << offsetx << "," << offsety << ")"); - */ - coord2D_ts point; - point.x = sx - offsetx; - point.y = sy - offsety; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(sx - offsetx, sy - offsety); + SetPoint(sx + offsetx, sy + offsety); + SetPoint(ex + offsetx, ey + offsety); - point.x = sx + offsetx; - point.y = sy + offsety; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = ex + offsetx; - point.y = ey + offsety; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = ex - offsetx; - point.y = ey - offsety; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = sx - offsetx; - point.y = sy - offsety; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(ex + offsetx, ey + offsety); + SetPoint(ex - offsetx, ey - offsety); + SetPoint(sx - offsetx, sy - offsety); } void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h) { - coord2D_ts point; + ResetCount(); - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x + w; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(x , y + h); + SetPoint(x , y); + SetPoint(x + w, y); - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x + w; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(x + w, y); + SetPoint(x + w, y + h); + SetPoint(x , y + h); } void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickness) { - coord2D_ts point; + ResetCount(); if (radius<0) { radius *= -1; } @@ -211,38 +231,19 @@ void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickn double offsetInt2y = sin(angleTwo) * (radius-thickness/2); double offsetInt2x = cos(angleTwo) * (radius-thickness/2); - point.x = x + offsetIntx; - point.y = y + offsetInty; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(x + offsetIntx, y + offsetInty); + SetPoint(x + offsetExtx, y + offsetExty); + SetPoint(x + offsetExt2x, y + offsetExt2y); - point.x = x + offsetExtx; - point.y = y + offsetExty; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x + offsetExt2x; - point.y = y + offsetExt2y; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x + offsetInt2x; - point.y = y + offsetInt2y; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); - - point.x = x + offsetIntx; - point.y = y + offsetInty; - m_coord.PushBack(point); - m_coordColor.PushBack(m_Color); + SetPoint(x + offsetExt2x, y + offsetExt2y); + SetPoint(x + offsetInt2x, y + offsetInt2y); + SetPoint(x + offsetIntx, y + offsetInty); } } void ewol::OObject2DColored::Disc(float x, float y, float radius) { + ResetCount(); coord2D_ts point; if (radius<0) { radius *= -1; @@ -254,28 +255,19 @@ void ewol::OObject2DColored::Disc(float x, float y, float radius) } for (int32_t iii=0; iii m_coord; //!< internal coord of the object etk::VectorType m_coordColor; //!< internal color of the different point //etk::VectorType m_linkCoord; //!< internal link between point to generate triangle - color_ts m_Color; + int32_t m_triElement; + color_ts m_color[3]; + coord2D_ts m_triangle[3]; + void GenerateTriangle(void); + void ResetCount(void); public: void SetColor(float red, float green, float blue, float alpha = 1.0); void SetColor(color_ts color); - //void SetPoint(coord2D_ts point); //==> for direct adding custum element ... + void SetPoint(coord2D_ts point); + void SetPoint(float x, float y); void Line(float sx, float sy, float ex, float ey, float thickness); void Rectangle(float x, float y, float w, float h); //void RectangleAngle(float x, float y, float w, float h, float angle);