From 6cbe46a105d87c3668689cb1f50b4ddb6589050f Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Thu, 23 Feb 2012 22:29:51 +0100 Subject: [PATCH] change oobject properties --- Sources/libewol/ewol/Font.h | 12 + Sources/libewol/ewol/FontFreeType.cpp | 263 ++++++++++++++++++ Sources/libewol/ewol/OObject.cpp | 1 + Sources/libewol/ewol/OObject.h | 5 +- .../libewol/ewol/OObject/2DTextColored.cpp | 18 +- Sources/libewol/ewol/OObject/2DTextColored.h | 4 +- 6 files changed, 295 insertions(+), 8 deletions(-) diff --git a/Sources/libewol/ewol/Font.h b/Sources/libewol/ewol/Font.h index 94582632..db7352ec 100644 --- a/Sources/libewol/ewol/Font.h +++ b/Sources/libewol/ewol/Font.h @@ -66,6 +66,18 @@ namespace ewol int32_t & fontTextureId, etk::VectorType & coord, etk::VectorType & coordTex); + int32_t DrawText(int32_t fontID, + coord2D_ts textPos, + const etk::UString & unicodeString, + int32_t & fontTextureId, + etk::VectorType & coord, + etk::VectorType & coordTex); + int32_t DrawText(int32_t fontID, + coord2D_ts textPos, + const uniChar_t unicodeChar, + int32_t & fontTextureId, + etk::VectorType & coord, + etk::VectorType & coordTex); int32_t LoadFont(etk::File fontFileName); }; diff --git a/Sources/libewol/ewol/FontFreeType.cpp b/Sources/libewol/ewol/FontFreeType.cpp index eebac918..83a16981 100644 --- a/Sources/libewol/ewol/FontFreeType.cpp +++ b/Sources/libewol/ewol/FontFreeType.cpp @@ -907,6 +907,269 @@ int32_t ewol::DrawText(int32_t fontID, } +int32_t ewol::DrawText(int32_t fontID, + coord2D_ts textPos, + const etk::UString& unicodeString, + int32_t & fontTextureId, + etk::VectorType & coord, + etk::VectorType & coordTex) +{ + if(fontID>=m_listLoadedFont.Size() || fontID < 0) { + EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); + return 0; + } + etk::VectorType & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); + + fontTextureId = m_listLoadedFont[fontID]->GetOglId(); + int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); + + etkFloat_t posDrawX = textPos.x; + + for(int32_t iii=0; iii & coord, + etk::VectorType & coordTex) +{ + if(fontID>=m_listLoadedFont.Size() || fontID < 0) { + EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); + return 0; + } + etk::VectorType & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); + + fontTextureId = m_listLoadedFont[fontID]->GetOglId(); + int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); + + etkFloat_t posDrawX = textPos.x; + int32_t charIndex; + + if (unicodeChar < 0x20) { + charIndex = 0; + } else if (unicodeChar < 0x80) { + charIndex = unicodeChar - 0x1F; + } else { + charIndex = 0; + for (int32_t iii=0x80-0x20; iii < listOfElement.Size(); iii++) { + if (listOfElement[iii].unicodeCharVal == unicodeChar) { + charIndex = iii; + break; + } + } + } + // 0x01 == 0x20 == ' '; + if (unicodeChar != 0x01) { + /* Bitmap position + * xA xB + * yC *------* + * | | + * | | + * yD *------* + */ + etkFloat_t dxA = posDrawX + listOfElement[charIndex].bearing.x; + etkFloat_t dxB = posDrawX + listOfElement[charIndex].bearing.x + listOfElement[charIndex].size.x; + etkFloat_t dyC = textPos.y + fontSize - listOfElement[charIndex].bearing.y; + etkFloat_t dyD = textPos.y + fontSize - listOfElement[charIndex].bearing.y + listOfElement[charIndex].size.y; + + etkFloat_t tuA = listOfElement[charIndex].posStart.u; + etkFloat_t tuB = listOfElement[charIndex].posStop.u; + etkFloat_t tvC = listOfElement[charIndex].posStart.v; + etkFloat_t tvD = listOfElement[charIndex].posStop.v; + + if( dxB <= dxA + || dyD <= dyC) { + // nothing to do ... + } else { + /* Bitmap position + * 0------1 + * | | + * | | + * 3------2 + */ + coord2D_ts bitmapDrawPos[4]; + bitmapDrawPos[0].x = dxA; + bitmapDrawPos[1].x = dxB; + bitmapDrawPos[2].x = dxB; + bitmapDrawPos[3].x = dxA; + + bitmapDrawPos[0].y = dyC; + bitmapDrawPos[1].y = dyC; + bitmapDrawPos[2].y = dyD; + bitmapDrawPos[3].y = dyD; + /* texture Position : + * 0------1 + * | | + * | | + * 3------2 + */ + texCoord_ts texturePos[4]; + texturePos[0].u = tuA; + texturePos[1].u = tuB; + texturePos[2].u = tuB; + texturePos[3].u = tuA; + + texturePos[0].v = tvC; + texturePos[1].v = tvC; + texturePos[2].v = tvD; + texturePos[3].v = tvD; + + // NOTE : Android does not support the Quads elements ... + /* Step 1 : + * ******** + * ****** + * **** + * ** + * + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[1]); + coordTex.PushBack(texturePos[2]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[1]); + coord.PushBack(bitmapDrawPos[2]); + + /* Step 2 : + * + * ** + * **** + * ****** + * ******** + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[2]); + coordTex.PushBack(texturePos[3]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[2]); + coord.PushBack(bitmapDrawPos[3]); + } + } + posDrawX += listOfElement[charIndex].advance; + int32_t sizeOut = posDrawX - textPos.x; + textPos.x = posDrawX; + return sizeOut; +} + + int32_t ewol::GetWidth(int32_t fontID, const etk::UString& unicodeString) { if(fontID>=m_listLoadedFont.Size() || fontID < 0) { diff --git a/Sources/libewol/ewol/OObject.cpp b/Sources/libewol/ewol/OObject.cpp index 2e8c2f49..13a7437c 100644 --- a/Sources/libewol/ewol/OObject.cpp +++ b/Sources/libewol/ewol/OObject.cpp @@ -34,6 +34,7 @@ ewol::OObject::OObject(void) { + m_hasClipping = false; // nothing to do ... } diff --git a/Sources/libewol/ewol/OObject.h b/Sources/libewol/ewol/OObject.h index d1912895..dc60896b 100644 --- a/Sources/libewol/ewol/OObject.h +++ b/Sources/libewol/ewol/OObject.h @@ -48,8 +48,9 @@ namespace ewol { public: OObject(void); virtual ~OObject(void); - void SetClipping(clipping_ts clip) {m_clipping = clip; m_hasClipping = true;}; - void RmClipping(void) {m_hasClipping = false;}; + void clippingSet(clipping_ts clip) {m_clipping = clip; m_hasClipping = true;}; + void clippingDisable(void) {m_hasClipping = false;}; + void clippingEnable(void) {m_hasClipping = true;}; virtual void Draw(void) = 0; }; }; diff --git a/Sources/libewol/ewol/OObject/2DTextColored.cpp b/Sources/libewol/ewol/OObject/2DTextColored.cpp index 02735d12..3bd2b94a 100644 --- a/Sources/libewol/ewol/OObject/2DTextColored.cpp +++ b/Sources/libewol/ewol/OObject/2DTextColored.cpp @@ -108,7 +108,7 @@ void ewol::OObject2DTextColored::Clear(void) m_coordColor.Clear(); } -int32_t ewol::OObject2DTextColored::Text(coord2D_ts textPos, clipping_ts drawClipping, const etk::UString& unicodeString) +int32_t ewol::OObject2DTextColored::Text(coord2D_ts textPos, const etk::UString& unicodeString) { m_FontTextureId = 0; if (m_FontId == -1) { @@ -116,14 +116,19 @@ int32_t ewol::OObject2DTextColored::Text(coord2D_ts textPos, clipping_ts drawCli return 0; } int32_t nbElementInTheArray = m_coord.Size(); - int32_t size = ewol::DrawText(m_FontId, textPos, drawClipping, unicodeString, m_FontTextureId, m_coord, m_coordTex); + int32_t size = 0; + if (true==m_hasClipping) { + size = ewol::DrawText(m_FontId, textPos, m_clipping, unicodeString, m_FontTextureId, m_coord, m_coordTex); + } else { + size = ewol::DrawText(m_FontId, textPos, unicodeString, m_FontTextureId, m_coord, m_coordTex); + } for (int32_t iii=nbElementInTheArray; iii