diff --git a/external/etk b/external/etk index c35e8832..1f9db255 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit c35e883279632dda8743a3d1f9bbe5ac2748146f +Subproject commit 1f9db2550cc2a08f9118ac1b2686f17ebd1e3a73 diff --git a/sources/ewol/compositing/Compositing.cpp b/sources/ewol/compositing/Compositing.cpp index a6c9678f..605afeea 100644 --- a/sources/ewol/compositing/Compositing.cpp +++ b/sources/ewol/compositing/Compositing.cpp @@ -30,17 +30,23 @@ void ewol::Compositing::ResetMatrix(void) void ewol::Compositing::Tranlate(etk::Vector3D vect) { - m_matrixApply *= etk::matrix::Translate(vect.x, vect.y, vect.z); + m_matrixApply *= etk::matrix::Translate(vect); } -void ewol::Compositing::Rotate(etk::Vector3D vect) +void ewol::Compositing::Rotate(etk::Vector3D vect, float angle) { - m_matrixApply *= etk::matrix::rotate(vect.x, vect.y, vect.z); + m_matrixApply *= etk::matrix::Rotate(vect, angle); } void ewol::Compositing::Scale(etk::Vector3D vect) { - m_matrixApply *= etk::matrix::Scale(vect.x, vect.y, vect.z); -} \ No newline at end of file + m_matrixApply *= etk::matrix::Scale(vect); +} + + +void ewol::Compositing::Clear(void) +{ + m_matrixApply.Identity(); +} diff --git a/sources/ewol/compositing/Compositing.h b/sources/ewol/compositing/Compositing.h index edada4f9..d26a6282 100644 --- a/sources/ewol/compositing/Compositing.h +++ b/sources/ewol/compositing/Compositing.h @@ -31,7 +31,11 @@ namespace ewol /** * @brief Virtal pure function that request the draw of all openGl elements */ - void virtual Draw(void)=0; + virtual void Draw(void)=0; + /** + * @brief Clear alll tre registered element in the current element + */ + virtual void Clear(void); /** * @brief Reset to the eye matrix the openGL mouving system */ @@ -45,7 +49,7 @@ namespace ewol * @brief Rotate the curent display of this element * @param[in] vect The rotation vector to apply at the transformation matrix */ - void Rotate(etk::Vector3D vect); + void Rotate(etk::Vector3D vect, float angle); /** * @brief Scale the current diaplsy of this element * @param[in] vect The scaling vector to apply at the transformation matrix diff --git a/sources/ewol/compositing/Text.cpp b/sources/ewol/compositing/Text.cpp index 8f7e6b00..f26bea6d 100644 --- a/sources/ewol/compositing/Text.cpp +++ b/sources/ewol/compositing/Text.cpp @@ -9,6 +9,7 @@ #include #include +#include /* @@ -23,23 +24,55 @@ */ ewol::Text::Text(void) : + m_position(0.0, 0.0, 0.0), + m_clippingPosition(0.0, 0.0, 0.0), + m_clippingSize(0.0, 0.0, 0.0), + m_clippingEnable(false), + m_color(draw::color::black), + m_colorBg(draw::color::none), + m_mode(ewol::font::Regular), + m_kerning(true), + m_distanceField(false), + m_previousCharcode(0), + m_startTextpos(0), + m_stopTextPos(0), + m_alignement(ewol::Text::alignDisable), m_GLprogram(NULL), + m_GLPosition(-1), + m_GLMatrix(-1), + m_GLColor(-1), + m_GLtexture(-1), + m_GLtexID(-1), m_font(NULL) { - m_color = draw::color::black; - m_colorBg = draw::color::none; - SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize()); + SetFont(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize()); LoadProgram(); } ewol::Text::Text(etk::UString fontName, int32_t fontSize) : + m_position(0.0, 0.0, 0.0), + m_clippingPosition(0.0, 0.0, 0.0), + m_clippingSize(0.0, 0.0, 0.0), + m_clippingEnable(false), + m_color(draw::color::black), + m_colorBg(draw::color::none), + m_mode(ewol::font::Regular), + m_kerning(true), + m_distanceField(false), + m_previousCharcode(0), + m_startTextpos(0), + m_stopTextPos(0), + m_alignement(ewol::Text::alignDisable), m_GLprogram(NULL), + m_GLPosition(-1), + m_GLMatrix(-1), + m_GLColor(-1), + m_GLtexture(-1), + m_GLtexID(-1), m_font(NULL) { - m_color = draw::color::black; - m_colorBg = draw::color::none; - SetFontProperty(fontName, fontSize); + SetFont(fontName, fontSize); LoadProgram(); } @@ -54,7 +87,7 @@ ewol::Text::~Text(void) ewol::resource::Release(m_GLprogram); } -void LoadProgram(void) +void ewol::Text::LoadProgram(void) { etk::UString tmpString("DATA:text.prog"); // get the shader resource : @@ -85,7 +118,7 @@ void ewol::Text::Draw(void) } m_GLprogram->Use(); // set Matrix : translation/positionMatrix - etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix(); + etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix()*m_matrixApply; m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); // TextureID m_GLprogram->SetTexture0(m_GLtexID, m_font->GetId()); @@ -103,45 +136,65 @@ void ewol::Text::Draw(void) void ewol::Text::Clear(void) { + // call upper class + ewol::Compositing::Clear(); + // Reset Buffer : m_coord.Clear(); m_coordTex.Clear(); m_coordColor.Clear(); + // Reset temporal variables : + m_position = etk::Vector3D(0.0, 0.0, 0.0); + m_clippingPosition = etk::Vector3D(0.0, 0.0, 0.0); + m_clippingSize = etk::Vector3D(0.0, 0.0, 0.0); + m_clippingEnable = false; + m_color = draw::color::black; + m_colorBg = draw::color::none; + m_mode = ewol::font::Regular; + m_kerning = false; + m_previousCharcode = 0; + m_startTextpos = 0; + m_stopTextPos = 0; + m_alignement = ewol::Text::alignDisable; } void ewol::Text::SetPos(etk::Vector3D pos) { - + m_position = pos; + m_previousCharcode = 0; } void ewol::Text::SetRelPos(etk::Vector3D pos) { - + m_position += pos; + m_previousCharcode = 0; } void ewol::Text::SetColor(draw::Color color) { - + m_color = color; } void ewol::Text::SetColorBG(draw::Color color) { - + m_colorBg = color; } void ewol::Text::SetClipping(etk::Vector3D pos, etk::Vector3D width) { - + m_clippingPosition = pos; + m_clippingSize = width; + m_clippingEnable = true; } void ewol::Text::SetClippingMode(bool newMode) { - + m_clippingEnable = newMode; } @@ -186,75 +239,379 @@ void ewol::Text::SetFont(etk::UString fontName, int32_t fontSize) void ewol::Text::SetFontMode(ewol::font::mode_te mode) { - + m_mode = mode; } void ewol::Text::SetKerningMode(bool newMode) { - + m_kerning = newMode; } void ewol::Text::SetDistanceFieldMode(bool newMode) { - + m_distanceField = newMode; + EWOL_TODO("The Distance field mode is not availlable for now ..."); } -void ewol::Text::Print(etk::UString& text) -{ - -} - - -void ewol::Text::PrintDecorated(etk::UString& text) +void ewol::Text::Print(const etk::UString& text) { if (m_font == NULL) { EWOL_ERROR("Font Id is not corectly defined"); - return 0; + return; } - int32_t nbElementInTheArray = m_coord.Size(); - int32_t size = 0; - size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode); - // set the color ... - for (int32_t iii=nbElementInTheArray; iii(m_position.x + interpolation, + m_position.y, + m_position.z) ); + } else { + Print(text[iii]); + } + } + if (currentId == stop) { + currentId++; + } else if( text[stop] == (uniChar_t)' ' + || text[stop] == (uniChar_t)'\n') { + currentId = stop+1; + } else { + currentId = stop; + } + // Reset position : + SetPos(etk::Vector3D(m_startTextpos, + (float)(m_position.y - m_font->GetHeight(m_mode)), + m_position.z) ); + } + } + break; } - return size; } -void ewol::Text::Print(etk::UString& text, etk::Vector& decoration) +void ewol::Text::PrintDecorated(const etk::UString& text) { - + EWOL_TODO("The Decorated print is not supported now ..."); + Print(text); } -void ewol::Text::Print(uniChar_t charcode) +void ewol::Text::Print(const etk::UString& text, const etk::Vector& decoration) +{ + EWOL_TODO("The Advenced print is not supported now ..."); + Print(text); +} + + +void ewol::Text::Print(const uniChar_t charcode) { if (m_font == NULL) { EWOL_ERROR("Font Id is not corectly defined"); - return 0; + return; } - int32_t nbElementInTheArray = m_coord.Size(); - int32_t size = 0; - size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode); - for (int32_t iii=nbElementInTheArray; iiiGetGlyphPointer(charcode, m_mode); + int32_t fontSize = m_font->GetFontSize(); + int32_t fontHeigh = m_font->GetHeight(m_mode); + + // Get the kerning ofset : + float kerningOffset = 0.0; + if (true==m_kerning) { + kerningOffset = myGlyph->KerningGet(m_previousCharcode); + if (kerningOffset != 0) { + //EWOL_DEBUG("Kerning between : '" << (char)m_previousCharcode << "'&'" << (char)myGlyph->m_UVal << "' value : " << kerningOffset); + } } - return size; + // 0x01 == 0x20 == ' '; + if (charcode != 0x01) { + /* Bitmap position + * xA xB + * yC *------* + * | | + * | | + * yD *------* + */ + float dxA = m_position.x + myGlyph->m_bearing.x + kerningOffset; + float dxB = dxA + myGlyph->m_sizeTexture.x; + float dyC = m_position.y + myGlyph->m_bearing.y + fontHeigh - fontSize; + float dyD = dyC - myGlyph->m_sizeTexture.y; + + float tuA = myGlyph->m_texturePosStart.u; + float tuB = myGlyph->m_texturePosStop.u; + float tvC = myGlyph->m_texturePosStart.v; + float tvD = myGlyph->m_texturePosStop.v; + + + // Clipping and drawing area + /* + if( true == hasClipping + && ( dxB < clipping.x + || dxA > clipping.x + clipping.w) ) { + // Nothing to diplay ... + } else { + if (true == hasClipping) { + // generata positions... + float TexSizeX = tuB - tuA; + if (dxA < clipping.x) { + // clip display + float drawSize = clipping.x - dxA; + // Update element start display + dxA = clipping.x; + float addElement = TexSizeX * drawSize / (float)myGlyph->m_sizeTexture.x; + // update texture start X Pos + tuA += addElement; + } + if (dxB > clipping.x + clipping.w) { + // clip display + float drawSize = dxB - (clipping.x + clipping.w); + // Update element start display + dxB = clipping.x + clipping.w; + float addElement = TexSizeX * drawSize / (float)myGlyph->m_sizeTexture.x; + // update texture start X Pos + tuB -= addElement; + } + float TexSizeY = tvD - tvC; + if (dyC < clipping.y) { + // clip display + float drawSize = clipping.y - dyC; + // Update element start display + dyC = clipping.y; + float addElement = TexSizeY * drawSize / (float)myGlyph->m_sizeTexture.x; + // update texture start X Pos + tvC += addElement; + } + if (dyD > clipping.y + clipping.h) { + // clip display + float drawSize = dyD - (clipping.y + clipping.h); + // Update element start display + dyD = clipping.y + clipping.h; + float addElement = TexSizeX * drawSize / (float)myGlyph->m_sizeTexture.x; + // update texture start X Pos + tvD -= addElement; + } + } + */ + if( dxB <= dxA + || dyD >= dyC) { + // nothing to do ... + } else { + /* Bitmap position + * 0------1 + * | | + * | | + * 3------2 + */ + etk::Vector2D bitmapDrawPos[4]; + bitmapDrawPos[0].x = (int32_t)dxA; + bitmapDrawPos[1].x = (int32_t)dxB; + bitmapDrawPos[2].x = (int32_t)dxB; + bitmapDrawPos[3].x = (int32_t)dxA; + + bitmapDrawPos[0].y = (int32_t)dyC; + bitmapDrawPos[1].y = (int32_t)dyC; + bitmapDrawPos[2].y = (int32_t)dyD; + bitmapDrawPos[3].y = (int32_t)dyD; + /* texture Position : + * 0------1 + * | | + * | | + * 3------2 + */ + texCoord_ts texturePos[4]; + texturePos[0].u = tuA+m_mode; + texturePos[1].u = tuB+m_mode; + texturePos[2].u = tuB+m_mode; + texturePos[3].u = tuA+m_mode; + + 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 : + m_coordTex.PushBack(texturePos[0]); + m_coordTex.PushBack(texturePos[1]); + m_coordTex.PushBack(texturePos[2]); + // set display positions : + m_coord.PushBack(bitmapDrawPos[0]); + m_coord.PushBack(bitmapDrawPos[1]); + m_coord.PushBack(bitmapDrawPos[2]); + // set the color + m_coordColor.PushBack(m_color); + m_coordColor.PushBack(m_color); + m_coordColor.PushBack(m_color); + + /* Step 2 : + * + * ** + * **** + * ****** + * ******** + */ + // set texture coordonates : + m_coordTex.PushBack(texturePos[0]); + m_coordTex.PushBack(texturePos[2]); + m_coordTex.PushBack(texturePos[3]); + // set display positions : + m_coord.PushBack(bitmapDrawPos[0]); + m_coord.PushBack(bitmapDrawPos[2]); + m_coord.PushBack(bitmapDrawPos[3]); + // set the color + m_coordColor.PushBack(m_color); + m_coordColor.PushBack(m_color); + m_coordColor.PushBack(m_color); + } + //} + } + // move the position : + m_position.x += myGlyph->m_advance.x + kerningOffset; + // Register the previous character + m_previousCharcode = charcode; + return; } void ewol::Text::SetTextAlignement(float startTextpos, float stopTextPos, aligneMode_te alignement) { - + m_startTextpos = startTextpos; + m_stopTextPos = stopTextPos; + m_alignement = alignement; + if (m_startTextpos >= m_stopTextPos) { + EWOL_ERROR("Request allignement with Borne position error : " << startTextpos << " => " << stopTextPos); + } } void ewol::Text::DisableAlignement(void) { - + m_alignement = ewol::Text::alignDisable; } +etk::Vector3D ewol::Text::CalculateSize(const etk::UString& text) +{ + if (m_font == NULL) { + EWOL_ERROR("Font Id is not corectly defined"); + return etk::Vector3D(0,0,0); + } + etk::Vector3D outputSize(0, 0, 0); + for(int32_t iii=0; iii tmpp = CalculateSize(text[iii]); + if (outputSize.y == 0) { + outputSize.y += tmpp.y; + } + outputSize.x += tmpp.x; + } + return outputSize; +} + +etk::Vector3D ewol::Text::CalculateSize(const uniChar_t charcode) +{ + if (m_font == NULL) { + EWOL_ERROR("Font Id is not corectly defined"); + return etk::Vector3D(0,0,0); + } + // get a pointer on the glyph property : + ewol::GlyphProperty * myGlyph = m_font->GetGlyphPointer(charcode, m_mode); + int32_t fontHeigh = m_font->GetHeight(m_mode); + + // Get the kerning ofset : + float kerningOffset = 0.0; + if (true==m_kerning) { + kerningOffset = myGlyph->KerningGet(m_previousCharcode); + } + + etk::Vector3D outputSize((float)(myGlyph->m_advance.x + kerningOffset), + (float)(fontHeigh), + (float)(0.0)); + // Register the previous character + m_previousCharcode = charcode; + return outputSize; +} + + +bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start, int32_t& stop, int32_t& space, int32_t& freeSpace) +{ + // store previous : + uniChar_t storePrevious = m_previousCharcode; + + stop = text.Size(); + space = 0; + + int32_t lastSpacePosition = start; + int32_t lastSpacefreeSize; + + float endPos = m_position.x; + bool endOfLine = false; + for (int32_t iii=start; iii tmpSize = CalculateSize(text[iii]); + // check oveflow : + if (endPos + tmpSize.x > m_stopTextPos) { + stop = iii; + break; + } + // update local size : + endPos += tmpSize.x; + // save number of space : + if (text[iii] == (uniChar_t)' ') { + space++; + lastSpacePosition = iii; + lastSpacefreeSize = m_stopTextPos - endPos; + } else if (text[iii] == (uniChar_t)'\n') { + stop = iii; + endOfLine = true; + break; + } + } + freeSpace = m_stopTextPos - endPos; + // retore previous : + m_previousCharcode = storePrevious; + // need to align left or right ... + if(stop == text.Size()) { + return true; + } else { + if (endOfLine) { + return true; + } else { + if (space == 0) { + return true; + } + stop = lastSpacePosition; + freeSpace = lastSpacefreeSize; + return false; + } + } +} + + diff --git a/sources/ewol/compositing/Text.h b/sources/ewol/compositing/Text.h index 86bded22..f70fec70 100644 --- a/sources/ewol/compositing/Text.h +++ b/sources/ewol/compositing/Text.h @@ -27,13 +27,14 @@ namespace ewol class Text : public ewol::Compositing { - typedef enum { - alignDisable, - alignRight, - alignLeft, - alignCenter, - alignJustify - } aligneMode_te; + public: + typedef enum { + alignDisable, + alignRight, + alignLeft, + alignCenter, + alignJustify + } aligneMode_te; private: // curent Drawing position @@ -45,7 +46,11 @@ namespace ewol // Basic color draw::Color m_color; draw::Color m_colorBg; - // font property : + // font property : + ewol::font::mode_te m_mode; + bool m_kerning; + bool m_distanceField; + uniChar_t m_previousCharcode; // alignement propoerty float m_startTextpos; float m_stopTextPos; @@ -55,7 +60,6 @@ namespace ewol int32_t m_GLPosition; int32_t m_GLMatrix; int32_t m_GLColor; - int32_t m_GLtextMode; int32_t m_GLtexture; int32_t m_GLtexID; // Font resource : @@ -162,7 +166,7 @@ namespace ewol * @brief Display a compleat string in the current element. * @param[in] text The string to display. */ - void Print(etk::UString& text); + void Print(const etk::UString& text); /** * @brief Display a compleat string in the current element with the generic decoration specification. * \ ... \ For bold text. @@ -174,18 +178,18 @@ namespace ewol * \ ... \ To align justify. * @param[in] text The string to display. */ - void PrintDecorated(etk::UString& text); + void PrintDecorated(const etk::UString& text); /** * @brief Display a compleat string in the current element whith specific decorations (advence mode). * @param[in] text The string to display. * @param[in] decoration The text decoration for the text that might be display (if the vector is smaller, the last parameter is get) */ - void Print(etk::UString& text, etk::Vector& decoration); + void Print(const etk::UString& text, const etk::Vector& decoration); /** * @brief Display the current char in the current element (note that the kerning is availlable if the position is not changed) * @param[in] char that might be dispalyed */ - void Print(uniChar_t charcode); + void Print(const uniChar_t charcode); /** * @brief This generate the possibility to generate the big text property * @param[in] startTextpos The x text start position of the display. @@ -198,6 +202,29 @@ namespace ewol * @brief Disable the alignement system */ void DisableAlignement(void); + /** + * @brief Calculate a theoric text size + * @param[in] text The string to calculate dimention. + * @return The theoric size used. + */ + etk::Vector3D CalculateSize(const etk::UString& text); + /** + * @brief Calculate a theoric charcode size + * @param[in] charcode The ľUnicode value to calculate dimention. + * @return The theoric size used. + */ + etk::Vector3D CalculateSize(const uniChar_t charcode); + private: + /** + * @brief Calculate the element number that is the first out the alignement range + * (start at the specify ID, and use start pos with current one) + * @param[in] text The string that might be parsed. + * @param[in] start The first elemnt that might be used to calculate. + * @param[out] stop The last Id availlable in the current string. + * @param[out] space Number of space in the string. + * @return true if need not alligne justify (end of string) + */ + bool ExtrapolateLastId(const etk::UString& text, const int32_t start, int32_t& stop, int32_t& space, int32_t& freeSpace); }; }; diff --git a/sources/ewol/font/TexturedFont.cpp b/sources/ewol/font/TexturedFont.cpp index e3cf083e..5733aaad 100644 --- a/sources/ewol/font/TexturedFont.cpp +++ b/sources/ewol/font/TexturedFont.cpp @@ -98,7 +98,9 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) : //EWOL_DEBUG(" file : " << output[iii]); if( true == output[iii].EndWith(m_name+"-"+"bold"+".ttf", false) || true == output[iii].EndWith(m_name+"-"+"b"+".ttf", false) + || true == output[iii].EndWith(m_name+"-"+"bd"+".ttf", false) || true == output[iii].EndWith(m_name+"bold"+".ttf", false) + || true == output[iii].EndWith(m_name+"bd"+".ttf", false) || true == output[iii].EndWith(m_name+"b"+".ttf", false)) { EWOL_INFO(" find Font [Bold] : " << output[iii]); m_fileName[ewol::font::Bold] = output[iii]; @@ -502,3 +504,25 @@ etk::Vector2D ewol::TexturedFont::GetSize(const uniChar_t unicodeChar, } +int32_t ewol::TexturedFont::GetIndex(const uniChar_t charcode, const ewol::font::mode_te displayMode) const +{ + if (charcode < 0x20) { + return 0; + } else if (charcode < 0x80) { + return charcode - 0x1F; + } else { + for (int32_t iii=0x80-0x20; iii < m_listElement[displayMode].Size(); iii++) { + if ((m_listElement[displayMode])[iii].m_UVal == charcode) { + return iii; + } + } + } + return 0; +} + + +ewol::GlyphProperty* ewol::TexturedFont::GetGlyphPointer(const uniChar_t charcode, const ewol::font::mode_te displayMode) +{ + int32_t index = GetIndex(charcode, displayMode); + return &((m_listElement[displayMode])[index]); +} diff --git a/sources/ewol/font/TexturedFont.h b/sources/ewol/font/TexturedFont.h index fa7c4779..0f808bd2 100644 --- a/sources/ewol/font/TexturedFont.h +++ b/sources/ewol/font/TexturedFont.h @@ -34,7 +34,9 @@ namespace ewol // ==> otherwise I can just generate italic ... // ==> Bold is a little more complicated (maybe with the bordersize) ewol::Font* m_font[4]; + public: etk::Vector m_listElement[4]; + private: // for the texture generation : etk::Vector2D m_lastGlyphPos[4]; int32_t m_lastRawHeigh[4]; @@ -44,6 +46,7 @@ namespace ewol virtual bool HasName(etk::UString& fileName); const char* GetType(void) { return "ewol::TexturedFont"; }; int32_t getFontSize(void) { return m_size; }; + // TODO : Remove : DEPRECATED ... int32_t Draw(etk::Vector2D textPos, const etk::UString& unicodeString, etk::Vector > & coord, @@ -53,6 +56,7 @@ namespace ewol clipping_ts& clipping, ewol::font::mode_te displayMode); + // TODO : Remove : DEPRECATED ... int32_t Draw(etk::Vector2D textPos, const uniChar_t unicodeChar, etk::Vector > & coord, @@ -63,6 +67,7 @@ namespace ewol ewol::font::mode_te displayMode, const uniChar_t unicodeCharPrevious = 0); + // TODO : Remove : DEPRECATED ... /** * @brief Get the size of the specified String * @param[in] unicodeString The string that we might calculate the display size @@ -72,6 +77,7 @@ namespace ewol etk::Vector2D GetSize(const etk::UString & unicodeString, const ewol::font::mode_te displayMode = ewol::font::Regular); + // TODO : Remove : DEPRECATED ... /** * @brief Get the size of the specified unicode value * @param[in] unicodeChar the char that might be displayed @@ -82,6 +88,7 @@ namespace ewol etk::Vector2D GetSize(const uniChar_t unicodeChar, const uniChar_t unicodeCharPrevious = 0, const ewol::font::mode_te displayMode = ewol::font::Regular); + /** * @brief Get the display height of this font * @param[in] displayMode Mode to display the currrent font @@ -93,6 +100,20 @@ namespace ewol * @return Dimention of the font the user requested */ int32_t GetFontSize(void) { return m_size; }; + /** + * @brief Get the ID of a unicode charcode + * @param[in] charcode The unicodeValue + * @param[in] displayMode Mode to display the currrent font + * @return The ID in the table (if it does not exist : return 0) + */ + int32_t GetIndex(const uniChar_t charcode, const ewol::font::mode_te displayMode) const; + /** + * @brief Get the pointer on the coresponding glyph + * @param[in] charcode The unicodeValue + * @param[in] displayMode Mode to display the currrent font + * @return The pointer on the glyph ==> never NULL + */ + ewol::GlyphProperty* GetGlyphPointer(const uniChar_t charcode, const ewol::font::mode_te displayMode); }; diff --git a/sources/ewol/widget/Button.cpp b/sources/ewol/widget/Button.cpp index 8e66e3b0..19806b5b 100644 --- a/sources/ewol/widget/Button.cpp +++ b/sources/ewol/widget/Button.cpp @@ -114,7 +114,8 @@ bool ewol::Button::CalculateMinSize(void) etk::Vector2D padding; padding.x = m_config->GetInteger(m_confIdPaddingX); padding.y = m_config->GetInteger(m_confIdPaddingY); - etk::Vector2D minSize = m_oObjectText.GetSize(m_label); + + etk::Vector3D minSize = m_displayText.CalculateSize(m_label); m_minSize.x = padding.x*2 + minSize.x; m_minSize.y = padding.y*2 + minSize.y; // Add the image element ... @@ -214,7 +215,8 @@ void ewol::Button::OnDraw(DrawProperty& displayProp) if (NULL != m_oObjectImage) { m_oObjectImage->Draw(); } - m_oObjectText.Draw(); + //m_oObjectText.Draw(); + m_displayText.Draw(); } void ewol::Button::OnRegenerateDisplay(void) @@ -225,35 +227,36 @@ void ewol::Button::OnRegenerateDisplay(void) padding.x = m_config->GetInteger(m_confIdPaddingX); padding.y = m_config->GetInteger(m_confIdPaddingY); - m_oObjectText.Clear(); if (NULL != m_oObjectImage) { m_oObjectImage->Clear(); } int32_t tmpSizeX = m_minSize.x; int32_t tmpSizeY = m_minSize.y; - int32_t tmpOriginX = (m_size.x - m_minSize.x) / 2; - int32_t tmpOriginY = (m_size.y - m_minSize.y) / 2; + etk::Vector3D tmpOrigin((float)((m_size.x - m_minSize.x) / 2.0), + (float)((m_size.y - m_minSize.y) / 2.0), + (float)(0.0)); // no change for the text orogin : - int32_t tmpTextOriginX = (m_size.x - m_minSize.x) / 2 + padding.x; - int32_t tmpTextOriginY = (m_size.y - m_minSize.y) / 2 + padding.y; + etk::Vector3D tmpTextOrigin((float)((m_size.x - m_minSize.x) / 2.0 + padding.x), + (float)((m_size.y - m_minSize.y) / 2.0 + padding.y), + (float)(0.0)); if (true==m_userFill.x) { tmpSizeX = m_size.x; - tmpOriginX = 0; + tmpOrigin.x = 0.0; if (m_alignement == ewol::TEXT_ALIGN_LEFT) { - tmpTextOriginX = padding.x; + tmpTextOrigin.x = padding.x; } } if (true==m_userFill.y) { tmpSizeY = m_size.y; - tmpOriginY = 0; + tmpOrigin.y = 0.0; } - tmpOriginX += padding.x; - tmpOriginY += padding.y; + tmpOrigin.x += padding.x; + tmpOrigin.x += padding.y; tmpSizeX -= 2*padding.x; tmpSizeY -= 2*padding.y; - etk::Vector2D textPos(tmpTextOriginX, tmpTextOriginY); + etk::Vector2D textPos(tmpTextOrigin.x, tmpTextOrigin.x); /*ewol::OObject2DTextured * tmpImage = NULL; if (true == m_hasAnImage) { @@ -265,16 +268,22 @@ void ewol::Button::OnRegenerateDisplay(void) textPos.x += m_padding.x + fontHeight; } */ - clipping_ts drawClipping; - drawClipping.x = padding.x; - drawClipping.y = padding.y; - drawClipping.w = m_size.x - 2*padding.x; - drawClipping.h = m_size.y - 2*padding.y; - //EWOL_DEBUG("draw tex at pos : " < drawClippingPos((float)padding.x, (float)padding.y, (float)-0.5); + etk::Vector3D drawClippingSize((float)(m_size.x - 2*padding.x), + (float)(m_size.y - 2*padding.y), + (float)1.0); + + // clean the element + m_displayText.Clear(); + m_displayText.SetClipping(drawClippingPos, drawClippingSize); + m_displayText.Print(m_label); + m_displayText.Tranlate(tmpTextOrigin); + m_widgetProperty.m_insidePos = textPos; - m_widgetProperty.m_insideSize = m_oObjectText.GetSize(m_label); + etk::Vector3D tmpp = m_displayText.CalculateSize(m_label); + etk::Vector2D tmpp2(tmpp.x, tmpp.y); + m_widgetProperty.m_insideSize = tmpp2; Rectangle(0, 0, m_size.x, m_size.y); } diff --git a/sources/ewol/widget/Button.h b/sources/ewol/widget/Button.h index fb6bb4aa..21dac7d5 100644 --- a/sources/ewol/widget/Button.h +++ b/sources/ewol/widget/Button.h @@ -14,6 +14,7 @@ #include #include #include +#include extern const char * const ewolEventButtonPressed; extern const char * const ewolEventButtonDown; @@ -85,7 +86,7 @@ namespace ewol { void SetPoint(float x, float y); void Rectangle(float x, float y, float w, float h); private: - ewol::OObject2DTextColored m_oObjectText; + ewol::Text m_displayText; ewol::OObject2DTextured* m_oObjectImage; bool m_hasAnImage; etk::UString m_imageSelected; diff --git a/sources/tag b/sources/tag index 2b7c5ae0..17b2ccd9 100644 --- a/sources/tag +++ b/sources/tag @@ -1 +1 @@ -0.4.2 +0.4.3