Create a better inteface for gnenerating triangle in the colored OObject system

This commit is contained in:
Edouard Dupin 2011-11-09 22:17:02 +01:00
parent 38ef1f5d9f
commit ffcaa34037
2 changed files with 107 additions and 110 deletions

View File

@ -33,6 +33,7 @@
ewol::OObject2DColored::OObject2DColored(void) ewol::OObject2DColored::OObject2DColored(void)
{ {
m_triElement = 0;
SetColor(1.0, 1.0, 1.0, 1.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) void ewol::OObject2DColored::UpdateOrigin(float x, float y)
{ {
for (int32_t iii=0; iii<m_coord.Size(); iii++) { for (int32_t iii=0; iii<m_coord.Size(); iii++) {
@ -77,18 +79,86 @@ void ewol::OObject2DColored::UpdateOrigin(float x, float y)
} }
void ewol::OObject2DColored::GenerateTriangle(void)
void ewol::OObject2DColored::SetColor( float red, float green, float blue, float alpha)
{ {
m_Color.red = red; m_triElement = 0;
m_Color.green = green;
m_Color.blue = blue; m_coord.PushBack(m_triangle[0]);
m_Color.alpha = alpha; m_coordColor.PushBack(m_color[0]);
m_coord.PushBack(m_triangle[1]);
m_coordColor.PushBack(m_color[1]);
m_coord.PushBack(m_triangle[2]);
m_coordColor.PushBack(m_color[2]);
} }
void ewol::OObject2DColored::SetColor(color_ts color)
{
if (m_triElement < 1) {
m_color[0] = color;
}
if (m_triElement < 2) {
m_color[1] = color;
}
if (m_triElement < 3) {
m_color[2] = color;
}
}
void ewol::OObject2DColored::SetColor(float red, float green, float blue, float alpha)
{
if (m_triElement < 1) {
m_color[0].red = red;
m_color[0].green = green;
m_color[0].blue = blue;
m_color[0].alpha = alpha;
}
if (m_triElement < 2) {
m_color[1].red = red;
m_color[1].green = green;
m_color[1].blue = blue;
m_color[1].alpha = alpha;
}
if (m_triElement < 3) {
m_color[2].red = red;
m_color[2].green = green;
m_color[2].blue = blue;
m_color[2].alpha = alpha;
}
}
void ewol::OObject2DColored::SetPoint(coord2D_ts point)
{
m_triangle[m_triElement] = point;
m_triElement++;
if (m_triElement>=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) void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float thickness)
{ {
ResetCount();
if (sx == ex && sy == ey) { if (sx == ex && sy == ey) {
EWOL_WARNING("Try to draw an line width 0"); EWOL_WARNING("Try to draw an line width 0");
return; 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." ); //EWOL_DEBUG("teta = " << (teta*180/(M_PI)) << " deg." );
double offsety = sin(teta-M_PI/2) * (thickness/2); double offsety = sin(teta-M_PI/2) * (thickness/2);
double offsetx = cos(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; SetPoint(sx - offsetx, sy - offsety);
point.y = sy - offsety; SetPoint(sx + offsetx, sy + offsety);
m_coord.PushBack(point); SetPoint(ex + offsetx, ey + offsety);
m_coordColor.PushBack(m_Color);
point.x = sx + offsetx; SetPoint(ex + offsetx, ey + offsety);
point.y = sy + offsety; SetPoint(ex - offsetx, ey - offsety);
m_coord.PushBack(point); SetPoint(sx - offsetx, sy - offsety);
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);
} }
void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h) void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h)
{ {
coord2D_ts point; ResetCount();
point.x = x; SetPoint(x , y + h);
point.y = y + h; SetPoint(x , y);
m_coord.PushBack(point); SetPoint(x + w, y);
m_coordColor.PushBack(m_Color);
point.x = x; SetPoint(x + w, y);
point.y = y; SetPoint(x + w, y + h);
m_coord.PushBack(point); SetPoint(x , y + h);
m_coordColor.PushBack(m_Color);
point.x = x + w;
point.y = y;
m_coord.PushBack(point);
m_coordColor.PushBack(m_Color);
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);
} }
void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickness) void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickness)
{ {
coord2D_ts point; ResetCount();
if (radius<0) { if (radius<0) {
radius *= -1; 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 offsetInt2y = sin(angleTwo) * (radius-thickness/2);
double offsetInt2x = cos(angleTwo) * (radius-thickness/2); double offsetInt2x = cos(angleTwo) * (radius-thickness/2);
point.x = x + offsetIntx; SetPoint(x + offsetIntx, y + offsetInty);
point.y = y + offsetInty; SetPoint(x + offsetExtx, y + offsetExty);
m_coord.PushBack(point); SetPoint(x + offsetExt2x, y + offsetExt2y);
m_coordColor.PushBack(m_Color);
point.x = x + offsetExtx; SetPoint(x + offsetExt2x, y + offsetExt2y);
point.y = y + offsetExty; SetPoint(x + offsetInt2x, y + offsetInt2y);
m_coord.PushBack(point); SetPoint(x + offsetIntx, y + offsetInty);
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);
} }
} }
void ewol::OObject2DColored::Disc(float x, float y, float radius) void ewol::OObject2DColored::Disc(float x, float y, float radius)
{ {
ResetCount();
coord2D_ts point; coord2D_ts point;
if (radius<0) { if (radius<0) {
radius *= -1; radius *= -1;
@ -254,28 +255,19 @@ void ewol::OObject2DColored::Disc(float x, float y, float radius)
} }
for (int32_t iii=0; iii<nbOcurence; iii++) { for (int32_t iii=0; iii<nbOcurence; iii++) {
point.x = x; SetPoint(x, y);
point.y = y;
m_coord.PushBack(point);
m_coordColor.PushBack(m_Color);
double angleOne = 2*M_PI* iii / nbOcurence ; double angleOne = 2*M_PI* iii / nbOcurence ;
double offsety = sin(angleOne) * radius; double offsety = sin(angleOne) * radius;
double offsetx = cos(angleOne) * radius; double offsetx = cos(angleOne) * radius;
point.x = x + offsetx; SetPoint(x + offsetx, y + offsety);
point.y = y + offsety;
m_coord.PushBack(point);
m_coordColor.PushBack(m_Color);
double angleTwo = 2*M_PI* (iii+1) / nbOcurence ; double angleTwo = 2*M_PI* (iii+1) / nbOcurence ;
offsety = sin(angleTwo) * radius; offsety = sin(angleTwo) * radius;
offsetx = cos(angleTwo) * radius; offsetx = cos(angleTwo) * radius;
point.x = x + offsetx; SetPoint(x + offsetx, y + offsety);
point.y = y + offsety;
m_coord.PushBack(point);
m_coordColor.PushBack(m_Color);
} }
} }

View File

@ -39,11 +39,16 @@ namespace ewol {
etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object
etk::VectorType<color_ts> m_coordColor; //!< internal color of the different point etk::VectorType<color_ts> m_coordColor; //!< internal color of the different point
//etk::VectorType<linkCoord_ts> m_linkCoord; //!< internal link between point to generate triangle //etk::VectorType<linkCoord_ts> 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: public:
void SetColor(float red, float green, float blue, float alpha = 1.0); void SetColor(float red, float green, float blue, float alpha = 1.0);
void SetColor(color_ts color); 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 Line(float sx, float sy, float ex, float ey, float thickness);
void Rectangle(float x, float y, float w, float h); void Rectangle(float x, float y, float w, float h);
//void RectangleAngle(float x, float y, float w, float h, float angle); //void RectangleAngle(float x, float y, float w, float h, float angle);