diff --git a/Sources/ewolOObject.h b/Sources/ewolOObject.h index 0105688c..605192ad 100644 --- a/Sources/ewolOObject.h +++ b/Sources/ewolOObject.h @@ -51,7 +51,10 @@ namespace ewol { void SetName(const char * name); etk::String GetName(void); public: - virtual void UpdateOrigin(float x, float y) {}; + // use to crop element outside the display + virtual void UpdateSize(float sizeX, float sizeY) { }; + // Move to the correct position display + virtual void UpdateOrigin(float x, float y) { }; private: etk::String m_name; }; diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp index 873138af..6b9ec356 100644 --- a/Sources/ewolOObject2DColored.cpp +++ b/Sources/ewolOObject2DColored.cpp @@ -78,6 +78,125 @@ void ewol::OObject2DColored::UpdateOrigin(float x, float y) } } +void generatePolyGone(etk::VectorType & input, etk::VectorType & output ) +{ + if (input.Size()<3) { + return; + } + coord2D_ts basePoint = input[0]; + for (int32_t iii=1; iii & input, etk::VectorType & output, float sx, float sy, float ex, float ey) +{ + // with Sutherland-Hodgman-Algorithm + if (input.Size() <0) { + return; + } + // last element : + coord2D_ts destPoint; + coord2D_ts lastElement = input[input.Size()-1]; + bool inside = true; + if (lastElement.x < 0) { + inside = false; + } + EWOL_DEBUG("generate an crop : "); + for(int32_t iii=0; iii OUT "); + //new point intersection ... + //y=aaax+bbb + //EWOL_DEBUG(" A (" << lastElement.x << "," << lastElement.y << ") A(" << input[iii].x << "," << input[iii].y << ")"); + float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x); + float bbb = lastElement.y - (aaa*lastElement.x); + //EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";"); + //==> intersection en x=0 : + destPoint.y = bbb; + destPoint.x = 0; + //EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")"); + output.PushBack(destPoint); + } else { + //EWOL_DEBUG("element OUT ==> OUT "); + } + inside = false; + } else { + if(true == inside) { + //EWOL_DEBUG("element IN ==> IN "); + //EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")"); + output.PushBack(input[iii]); + } else { + //EWOL_DEBUG("element OUT ==> IN "); + //new point intersection ... + //y=aaax+bbb + //EWOL_DEBUG(" A (" << lastElement.x << "," << lastElement.y << ") A(" << input[iii].x << "," << input[iii].y << ")"); + float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x); + float bbb = lastElement.y - (aaa*lastElement.x); + //EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";"); + //==> intersection en x=0 : + destPoint.y = bbb; + destPoint.x = 0; + //EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")"); + output.PushBack(destPoint); + //EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")"); + output.PushBack(input[iii]); + } + inside = true; + } + // update the last point position : + lastElement.x = input[iii].x; + lastElement.y = input[iii].y; + } + EWOL_DEBUG("generate an crop on element : " << input.Size()<< " ==> " << output.Size() ); +} + + +void ewol::OObject2DColored::UpdateSize(float sizeX, float sizeY) +{ + // copy the data + etk::VectorType coord = m_coord; + etk::VectorType color = m_coordColor; + // Clear the generated display ... + m_coord.Clear(); + m_coordColor.Clear(); + // Check if the triangle is in the area... + int32_t nbTriangle = coord.Size()/3; + for (int32_t iii=0; iii= 0.0 && coord[iii*3+0].x < sizeX + && coord[iii*3+0].y >= 0.0 && coord[iii*3+0].y < sizeY + && coord[iii*3+1].x >= 0.0 && coord[iii*3+1].x < sizeX + && coord[iii*3+1].y >= 0.0 && coord[iii*3+1].y < sizeY + && coord[iii*3+2].x >= 0.0 && coord[iii*3+2].x < sizeX + && coord[iii*3+2].y >= 0.0 && coord[iii*3+2].y < sizeY) + { + // point 1-2-3 inside + m_coord.PushBack(coord[iii*3+0]); + m_coordColor.PushBack(color[iii*3+0]); + m_coord.PushBack(coord[iii*3+1]); + m_coordColor.PushBack(color[iii*3+1]); + m_coord.PushBack(coord[iii*3+2]); + m_coordColor.PushBack(color[iii*3+2]); + } else { + etk::VectorType tmpCoord; + etk::VectorType tmpCoordOut; + tmpCoord.PushBack(coord[iii*3+0]); + tmpCoord.PushBack(coord[iii*3+1]); + tmpCoord.PushBack(coord[iii*3+2]); + + SutherlandHodgman(tmpCoord, tmpCoordOut, 0, 0, sizeX, sizeY); + tmpCoord.Clear(); + generatePolyGone(tmpCoordOut, tmpCoord); + for (int32_t jjj=0; jjjSetName(name); - //EWOL_INFO("UPDATE AT origin : (" << m_origin.x << "," << m_origin.y << ")"); + //EWOL_INFO("UPDATE AT size : (" << m_size.x << "," << m_size.y << ")"); + newObject->UpdateSize(m_size.x, m_size.y); + //EWOL_INFO("UPDATE AT origin : (" << m_origin.x << "," << m_origin.y << ")"); newObject->UpdateOrigin(m_origin.x, m_origin.y); m_listOObject.PushBack(newObject); } diff --git a/Sources/widget/ewolTest.cpp b/Sources/widget/ewolTest.cpp index a4799790..8d129b4c 100644 --- a/Sources/widget/ewolTest.cpp +++ b/Sources/widget/ewolTest.cpp @@ -57,8 +57,8 @@ void ewol::Test::OnRegenerateDisplay(void) { // clean the object list ... ClearOObjectList(); - ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; + tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0); tmpOObjects->Rectangle( 0, 0, m_size.x, m_size.y); tmpOObjects->SetColor(1.0, 1.0, 1.0, 1.0); @@ -146,6 +146,21 @@ void ewol::Test::OnRegenerateDisplay(void) size.x = m_size.x-6; size.y = m_size.y-6; AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventTestPressed); + + //tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0); + /* + tmpOObjects->SetPoint(-20, -20); + tmpOObjects->SetPoint(50, 50); + tmpOObjects->SetPoint(-20, 100); + */ + /* + tmpOObjects->SetPoint(20, -20); + tmpOObjects->SetPoint(50, 50); + tmpOObjects->SetPoint(-20, 100); + + AddOObject(tmpOObjects, "BouttonDecoration"); + */ + } bool ewol::Test::OnEventArea(const char * generateEventId, double x, double y)