From d8b95350168e3513e38307d74422fbd5bc9cfe3d Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Tue, 24 Jan 2012 23:51:21 +0100 Subject: [PATCH] Add clipping methode for the Rectangle diaplay --- Sources/libetk/etk/Types.h | 8 ++++ Sources/libewol/ewol/Font.h | 3 +- Sources/libewol/ewol/FontFreeType.cpp | 23 ++++------- Sources/libewol/ewol/OObject/2DColored.cpp | 41 +++++++++++++++++++ Sources/libewol/ewol/OObject/2DColored.h | 1 + .../libewol/ewol/OObject/2DTextColored.cpp | 4 +- Sources/libewol/ewol/OObject/2DTextColored.h | 2 +- 7 files changed, 63 insertions(+), 19 deletions(-) diff --git a/Sources/libetk/etk/Types.h b/Sources/libetk/etk/Types.h index 13390fec..b700a49a 100644 --- a/Sources/libetk/etk/Types.h +++ b/Sources/libetk/etk/Types.h @@ -100,6 +100,14 @@ extern "C" etkFloat_t u; etkFloat_t v; }texCoord_ts; + + typedef struct { + etkFloat_t x; + etkFloat_t y; + etkFloat_t w; + etkFloat_t h; + }clipping_ts; + typedef struct { etkFloat_t red; etkFloat_t green; diff --git a/Sources/libewol/ewol/Font.h b/Sources/libewol/ewol/Font.h index ece39724..20bc9ca8 100644 --- a/Sources/libewol/ewol/Font.h +++ b/Sources/libewol/ewol/Font.h @@ -96,8 +96,7 @@ namespace ewol etk::VectorType & coordTex); int32_t DrawText(int32_t fontID, coord2D_ts textPos, - coord2D_ts& drawOrigin, - coord2D_ts& drawSize, + clipping_ts & drawClipping, const uniChar_t * unicodeString, uint32_t & fontTextureId, etk::VectorType & coord, diff --git a/Sources/libewol/ewol/FontFreeType.cpp b/Sources/libewol/ewol/FontFreeType.cpp index 1d0334b0..ef28c9d5 100644 --- a/Sources/libewol/ewol/FontFreeType.cpp +++ b/Sources/libewol/ewol/FontFreeType.cpp @@ -675,8 +675,7 @@ int32_t ewol::DrawText(int32_t fontID, int32_t ewol::DrawText(int32_t fontID, coord2D_ts textPos, - coord2D_ts & drawOrigin, - coord2D_ts & drawSize, + clipping_ts & drawClipping, const uniChar_t * unicodeString, uint32_t & fontTextureId, etk::VectorType & coord, @@ -735,32 +734,28 @@ int32_t ewol::DrawText(int32_t fontID, // Clipping and drawing area - coord2D_ts drawStart = drawOrigin; - coord2D_ts drawStop; - drawStop.x = drawOrigin.x + drawSize.x; - drawStop.y = drawOrigin.y + drawSize.y; // TODO : clipping in Y too ... - if( dxB < drawStart.x - || dxA > drawStop.x) + if( dxB < drawClipping.x + || dxA > drawClipping.x + drawClipping.w) { // Nothing to diplay ... } else { // generata positions... etkFloat_t TexSizeX = tuB - tuA; - if (dxA < drawStart.x) { + if (dxA < drawClipping.x) { // clip display - etkFloat_t drawSize = drawStart.x - dxA; + etkFloat_t drawSize = drawClipping.x - dxA; // Update element start display - dxA = drawStart.x; + dxA = drawClipping.x; etkFloat_t addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; // update texture start X Pos tuA += addElement; } - if (dxB > drawStop.x) { + if (dxB > drawClipping.x + drawClipping.w) { // clip display - etkFloat_t drawSize = dxB - drawStop.x; + etkFloat_t drawSize = dxB - (drawClipping.x + drawClipping.w); // Update element start display - dxB = drawStop.x; + dxB = drawClipping.x + drawClipping.w; etkFloat_t addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; // update texture start X Pos tuB -= addElement; diff --git a/Sources/libewol/ewol/OObject/2DColored.cpp b/Sources/libewol/ewol/OObject/2DColored.cpp index b892c0c8..5c2d6e54 100644 --- a/Sources/libewol/ewol/OObject/2DColored.cpp +++ b/Sources/libewol/ewol/OObject/2DColored.cpp @@ -450,6 +450,47 @@ void ewol::OObject2DColored::Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, SetPoint(x , y + h); } + +void ewol::OObject2DColored::Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, clipping_ts& drawClipping) +{ + ResetCount(); + + /* Bitmap position + * xA xB + * yC *------* + * | | + * | | + * yD *------* + */ + etkFloat_t dxA = x; + etkFloat_t dxB = y; + etkFloat_t dyC = x + w; + etkFloat_t dyD = y + h; + + + if (dxA < drawClipping.x) { + dxA = drawClipping.x; + } + if (dxB > drawClipping.x + drawClipping.w) { + dxB = drawClipping.x + drawClipping.w; + } + if (dyC < drawClipping.y) { + dyC = drawClipping.y; + } + if (dyD > drawClipping.y + drawClipping.h) { + dyD = drawClipping.y + drawClipping.h; + } + + + SetPoint(dxA, dyD); + SetPoint(dxA, dxB); + SetPoint(dyC, dxB); + + SetPoint(dyC, dxB); + SetPoint(dyC, dyD); + SetPoint(dxA, dyD); +} + void ewol::OObject2DColored::RectangleBorder(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t thickness) { // TODO : This did not manage the thickness of the line ... diff --git a/Sources/libewol/ewol/OObject/2DColored.h b/Sources/libewol/ewol/OObject/2DColored.h index 3573c138..36fc67a5 100644 --- a/Sources/libewol/ewol/OObject/2DColored.h +++ b/Sources/libewol/ewol/OObject/2DColored.h @@ -51,6 +51,7 @@ namespace ewol { void SetPoint(etkFloat_t x, etkFloat_t y); void Line(etkFloat_t sx, etkFloat_t sy, etkFloat_t ex, etkFloat_t ey, etkFloat_t thickness); void Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h); + void Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, clipping_ts& drawClipping); //void RectangleAngle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t angle); void RectangleBorder(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t thickness); //void RectangleBorder(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t thickness, etkFloat_t angle); diff --git a/Sources/libewol/ewol/OObject/2DTextColored.cpp b/Sources/libewol/ewol/OObject/2DTextColored.cpp index 09923ba8..a3b5c701 100644 --- a/Sources/libewol/ewol/OObject/2DTextColored.cpp +++ b/Sources/libewol/ewol/OObject/2DTextColored.cpp @@ -111,7 +111,7 @@ int32_t ewol::OObject2DTextColored::TextAdd(etkFloat_t x, etkFloat_t y, const ch return size; } -int32_t ewol::OObject2DTextColored::TextAdd(coord2D_ts textPos, coord2D_ts drawOrigin, coord2D_ts drawSize, const uniChar_t* unicodeString) +int32_t ewol::OObject2DTextColored::TextAdd(coord2D_ts textPos, clipping_ts drawClipping, const uniChar_t* unicodeString) { m_FontTextureId = 0; if (m_FontId == -1) { @@ -119,7 +119,7 @@ int32_t ewol::OObject2DTextColored::TextAdd(coord2D_ts textPos, coord2D_ts drawO return 0; } int32_t nbElementInTheArray = m_coord.Size(); - int32_t size = ewol::DrawText(m_FontId, textPos, drawOrigin, drawSize, unicodeString, m_FontTextureId, m_coord, m_coordTex); + int32_t size = ewol::DrawText(m_FontId, textPos, drawClipping, unicodeString, m_FontTextureId, m_coord, m_coordTex); for (int32_t iii=nbElementInTheArray; iii