[DEV] Multiline button is OK ==> gui display is not compleately ended

This commit is contained in:
Edouard DUPIN 2012-11-29 22:13:54 +01:00
parent d69a964459
commit fbcb6148ad
4 changed files with 366 additions and 218 deletions

View File

@ -165,14 +165,21 @@ void ewol::Text::Clear(void)
m_coordTex.Clear(); m_coordTex.Clear();
m_coordColor.Clear(); m_coordColor.Clear();
// Reset temporal variables : // Reset temporal variables :
Reset();
}
void ewol::Text::Reset(void)
{
m_position = etk::Vector3D<float>(0.0, 0.0, 0.0); m_position = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_clippingPosStart = etk::Vector3D<float>(0.0, 0.0, 0.0); m_clippingPosStart = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_clippingPosStop = etk::Vector3D<float>(0.0, 0.0, 0.0); m_clippingPosStop = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_sizeDisplayStart = m_position;
m_sizeDisplayStop = m_position;
m_nbCharDisplayed = 0;
m_clippingEnable = false; m_clippingEnable = false;
m_color = draw::color::black; m_color = draw::color::black;
m_colorBg = draw::color::none; m_colorBg = draw::color::none;
m_mode = ewol::font::Regular; m_mode = ewol::font::Regular;
m_kerning = false;
m_previousCharcode = 0; m_previousCharcode = 0;
m_startTextpos = 0; m_startTextpos = 0;
m_stopTextPos = 0; m_stopTextPos = 0;
@ -181,6 +188,8 @@ void ewol::Text::Clear(void)
m_selectionStartPos = -100; m_selectionStartPos = -100;
m_cursorPos = -100; m_cursorPos = -100;
m_htmlDecoration.Clear(); m_htmlDecoration.Clear();
m_needDisplay = true;
m_nbCharDisplayed = 0;
} }
@ -192,9 +201,33 @@ etk::Vector3D<float> ewol::Text::GetPos(void)
void ewol::Text::SetPos(etk::Vector3D<float> pos) void ewol::Text::SetPos(etk::Vector3D<float> pos)
{ {
// check min max for display area
if (m_nbCharDisplayed != 0) {
EWOL_VERBOSE("update size 1 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
EWOL_VERBOSE("update size 2 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
}
// update position
m_position = pos; m_position = pos;
m_previousCharcode = 0; m_previousCharcode = 0;
m_vectorialDraw.SetPos(m_position); m_vectorialDraw.SetPos(m_position);
// update min max of the display area:
if (m_nbCharDisplayed == 0) {
m_sizeDisplayStart = m_position;
m_sizeDisplayStop = m_position;
m_sizeDisplayStop.y += m_font->GetHeight(m_mode);
EWOL_VERBOSE("update size 0 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
} else {
EWOL_VERBOSE("update size 3 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
EWOL_VERBOSE("update size 4 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
}
} }
@ -380,80 +413,85 @@ void ewol::Text::Print(const etk::UString& text)
void ewol::Text::ParseHtmlNode(void* element2) void ewol::Text::ParseHtmlNode(void* element2)
{ {
// get the static real pointer
TiXmlNode* element = static_cast<TiXmlNode*>(element2); TiXmlNode* element = static_cast<TiXmlNode*>(element2);
if (NULL != element) { if (NULL != element) {
/*const char *myData = element->ToElement()->GetText(); for (TiXmlNode * child = element->FirstChild(); NULL != child ; child = child->NextSibling() ) {
if (NULL != myData) { if (child->Type()==TiXmlNode::TINYXML_COMMENT) {
etk::UString outputData(myData); // nothing to do ...
Print(myData); } else if (child->Type()==TiXmlNode::TINYXML_TEXT) {
} else { HtmlAddData(child->Value() );
*/ EWOL_VERBOSE("XML Add : " << child->Value());
for (TiXmlNode * child = element->FirstChild(); NULL != child ; child = child->NextSibling() ) { } else if (!strcmp(child->Value(), "br")) {
if (child->Type()==TiXmlNode::TINYXML_COMMENT) { HtmlFlush();
// nothing to do ... EWOL_VERBOSE("XML flush & newLine");
} else if (child->Type()==TiXmlNode::TINYXML_TEXT) { ForceLineReturn();
HtmlAddData(child->Value() ); } else if (!strcmp(child->Value(), "font")) {
} else if (!strcmp(child->Value(), "br")) { EWOL_VERBOSE("XML Font ...");
HtmlFlush(); TextDecoration tmpDeco = m_htmlDecoTmp;
ForceLineReturn(); const char *colorValue = child->ToElement()->Attribute("color");
} else if (!strcmp(child->Value(), "font")) { if (NULL != colorValue) {
TextDecoration tmpDeco = m_htmlDecoTmp; draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorFg);
const char *colorValue = child->ToElement()->Attribute("color");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorFg);
}
colorValue = child->ToElement()->Attribute("colorBg");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorBg);
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "b")) {
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Bold;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Italic) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "i")) {
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Italic;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Bold) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "u")) {
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "p")) {
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ForceLineReturn();
ParseHtmlNode(child);
ForceLineReturn();
} else if (!strcmp(child->Value(), "center")) {
HtmlFlush();
m_alignement = ewol::Text::alignCenter;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "left")) {
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "right")) {
HtmlFlush();
m_alignement = ewol::Text::alignRight;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "justify")) {
HtmlFlush();
m_alignement = ewol::Text::alignJustify;
ParseHtmlNode(child);
} else {
EWOL_ERROR("(l "<< child->Row() << ") node not suported type : " << child->Type() << " val=\""<< child->Value() << "\"" );
} }
//} colorValue = child->ToElement()->Attribute("colorBg");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorBg);
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "b")) {
EWOL_VERBOSE("XML b ...");
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Bold;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Italic) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "i")) {
EWOL_VERBOSE("XML i ...");
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Italic;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Bold) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "u")) {
EWOL_VERBOSE("XML u ...");
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "p")) {
EWOL_VERBOSE("XML p ...");
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ForceLineReturn();
ParseHtmlNode(child);
ForceLineReturn();
} else if (!strcmp(child->Value(), "center")) {
EWOL_VERBOSE("XML center ...");
HtmlFlush();
m_alignement = ewol::Text::alignCenter;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "left")) {
EWOL_VERBOSE("XML left ...");
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "right")) {
EWOL_VERBOSE("XML right ...");
HtmlFlush();
m_alignement = ewol::Text::alignRight;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "justify")) {
EWOL_VERBOSE("XML justify ...");
HtmlFlush();
m_alignement = ewol::Text::alignJustify;
ParseHtmlNode(child);
} else {
EWOL_ERROR("(l "<< child->Row() << ") node not suported type : " << child->Type() << " val=\""<< child->Value() << "\"" );
}
} }
} }
} }
@ -467,7 +505,7 @@ void ewol::Text::PrintDecorated(etk::UString& text)
PrintHTML(tmpData); PrintHTML(tmpData);
} }
void ewol::Text::PrintHTML(etk::UString& text) void ewol::Text::PrintHTML(etk::UString text)
{ {
TiXmlDocument XmlDocument; TiXmlDocument XmlDocument;
@ -490,7 +528,7 @@ void ewol::Text::PrintHTML(etk::UString& text)
return; return;
} }
TiXmlElement* bodyNode = root->FirstChildElement( "body" ); TiXmlElement* bodyNode = root->FirstChildElement( "body" );
ParseHtmlNode(bodyNode); (void)ParseHtmlNode(bodyNode);
HtmlFlush(); HtmlFlush();
} }
@ -503,10 +541,12 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
draw::Color tmpFg(m_color); draw::Color tmpFg(m_color);
draw::Color tmpBg(m_colorBg); draw::Color tmpBg(m_colorBg);
if (m_alignement == ewol::Text::alignDisable) { if (m_alignement == ewol::Text::alignDisable) {
if (0==m_cursorPos) { if (true == m_needDisplay) {
m_vectorialDraw.SetPos(m_position); if (0==m_cursorPos) {
SetColorBg(m_colorCursor); m_vectorialDraw.SetPos(m_position);
PrintCursor(false); SetColorBg(m_colorCursor);
PrintCursor(false);
}
} }
// note this is faster when nothing is requested ... // note this is faster when nothing is requested ...
for(int32_t iii=0; iii<text.Size(); iii++) { for(int32_t iii=0; iii<text.Size(); iii++) {
@ -515,34 +555,41 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
tmpBg = decoration[iii].m_colorBg; tmpBg = decoration[iii].m_colorBg;
SetFontMode(decoration[iii].m_mode); SetFontMode(decoration[iii].m_mode);
} }
if( ( m_selectionStartPos-1<iii if (true == m_needDisplay) {
&& iii <=m_cursorPos-1) if( ( m_selectionStartPos-1<iii
|| ( m_selectionStartPos-1>=iii && iii <=m_cursorPos-1)
&& iii > m_cursorPos-1) ) { || ( m_selectionStartPos-1>=iii
SetColor( 0x000000FF); && iii > m_cursorPos-1) ) {
SetColorBg(m_colorSelection); SetColor( 0x000000FF);
} else { SetColorBg(m_colorSelection);
SetColor( tmpFg); } else {
SetColorBg(tmpBg); SetColor( tmpFg);
SetColorBg(tmpBg);
}
} }
if (m_colorBg.a != 0) { if( true == m_needDisplay
&& m_colorBg.a != 0) {
etk::Vector3D<float> pos = m_position; etk::Vector3D<float> pos = m_position;
m_vectorialDraw.SetPos(pos); m_vectorialDraw.SetPos(pos);
Print(text[iii]); Print(text[iii]);
float fontHeigh = m_font->GetHeight(m_mode); float fontHeigh = m_font->GetHeight(m_mode);
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) ); m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) );
m_nbCharDisplayed++;
} else { } else {
Print(text[iii]); Print(text[iii]);
m_nbCharDisplayed++;
} }
if (iii==m_cursorPos-1) { if (true == m_needDisplay) {
m_vectorialDraw.SetPos(m_position); if (iii==m_cursorPos-1) {
SetColorBg(m_colorCursor); m_vectorialDraw.SetPos(m_position);
PrintCursor(false); SetColorBg(m_colorCursor);
PrintCursor(false);
}
} }
} }
} else { } else {
// special start case at the right of the endpoint : // special start case at the right of the endpoint :
if (m_stopTextPos <= m_position.x) { if (m_stopTextPos < m_position.x) {
ForceLineReturn(); ForceLineReturn();
} }
float basicSpaceWidth = CalculateSize(' ').x; float basicSpaceWidth = CalculateSize(' ').x;
@ -566,20 +613,25 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
// nothing to do ... // nothing to do ...
break; break;
case ewol::Text::alignRight: case ewol::Text::alignRight:
// Move the first char at the right : if (m_needDisplay == true) {
SetPos(etk::Vector3D<float>(m_position.x + freeSpace, // Move the first char at the right :
m_position.y, SetPos(etk::Vector3D<float>(m_position.x + freeSpace,
m_position.z) ); m_position.y,
m_position.z) );
}
break; break;
case ewol::Text::alignCenter: case ewol::Text::alignCenter:
// Move the first char at the right : if (m_needDisplay == true) {
SetPos(etk::Vector3D<float>(m_position.x + freeSpace/2, // Move the first char at the right :
m_position.y, SetPos(etk::Vector3D<float>(m_position.x + freeSpace/2,
m_position.z) ); m_position.y,
m_position.z) );
}
break; break;
} }
// display all the elements // display all the elements
if (0==m_cursorPos) { if( true == m_needDisplay
&& 0==m_cursorPos) {
m_vectorialDraw.SetPos(m_position); m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor); SetColorBg(m_colorCursor);
PrintCursor(false); PrintCursor(false);
@ -592,42 +644,53 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
tmpBg = decoration[iii].m_colorBg; tmpBg = decoration[iii].m_colorBg;
SetFontMode(decoration[iii].m_mode); SetFontMode(decoration[iii].m_mode);
} }
if( ( m_selectionStartPos-1<iii if (true == m_needDisplay) {
&& iii <=m_cursorPos-1) if( ( m_selectionStartPos-1<iii
|| ( m_selectionStartPos-1>=iii && iii <=m_cursorPos-1)
&& iii > m_cursorPos-1) ) { || ( m_selectionStartPos-1>=iii
SetColor( 0x000000FF); && iii > m_cursorPos-1) ) {
SetColorBg(m_colorSelection); SetColor( 0x000000FF);
} else { SetColorBg(m_colorSelection);
SetColor( tmpFg); } else {
SetColorBg(tmpBg); SetColor( tmpFg);
SetColorBg(tmpBg);
}
} }
// special for the justify mode // special for the justify mode
if (text[iii] == (uniChar_t)' ') { if (text[iii] == (uniChar_t)' ') {
if (m_colorBg.a != 0) { //EWOL_DEBUG(" generateString : \" \"");
if( true == m_needDisplay
&& m_colorBg.a != 0) {
m_vectorialDraw.SetPos(m_position); m_vectorialDraw.SetPos(m_position);
} }
// Must generate a dynamic space : // Must generate a dynamic space :
SetPos(etk::Vector3D<float>(m_position.x + interpolation, SetPos(etk::Vector3D<float>(m_position.x + interpolation,
m_position.y, m_position.y,
m_position.z) ); m_position.z) );
if (m_colorBg.a != 0) { if( true == m_needDisplay
&& m_colorBg.a != 0) {
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(interpolation,fontHeigh,0.0f) ); m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(interpolation,fontHeigh,0.0f) );
} }
} else { } else {
if (m_colorBg.a != 0) { //EWOL_DEBUG(" generateString : \"" << (char)text[iii] << "\"");
if( true == m_needDisplay
&& m_colorBg.a != 0) {
etk::Vector3D<float> pos = m_position; etk::Vector3D<float> pos = m_position;
m_vectorialDraw.SetPos(pos); m_vectorialDraw.SetPos(pos);
Print(text[iii]); Print(text[iii]);
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) ); m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) );
m_nbCharDisplayed++;
} else { } else {
Print(text[iii]); Print(text[iii]);
m_nbCharDisplayed++;
} }
} }
if (iii==m_cursorPos-1) { if (m_needDisplay == true) {
m_vectorialDraw.SetPos(m_position); if (iii==m_cursorPos-1) {
SetColorBg(m_colorCursor); m_vectorialDraw.SetPos(m_position);
PrintCursor(false); SetColorBg(m_colorCursor);
PrintCursor(false);
}
} }
} }
if (currentId == stop) { if (currentId == stop) {
@ -638,12 +701,14 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
SetPos(etk::Vector3D<float>(m_startTextpos, SetPos(etk::Vector3D<float>(m_startTextpos,
(float)(m_position.y - m_font->GetHeight(m_mode)), (float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) ); m_position.z) );
m_nbCharDisplayed++;
} else if(text[stop] == (uniChar_t)'\n') { } else if(text[stop] == (uniChar_t)'\n') {
currentId = stop+1; currentId = stop+1;
// Reset position : // Reset position :
SetPos(etk::Vector3D<float>(m_startTextpos, SetPos(etk::Vector3D<float>(m_startTextpos,
(float)(m_position.y - m_font->GetHeight(m_mode)), (float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) ); m_position.z) );
m_nbCharDisplayed++;
} else { } else {
currentId = stop; currentId = stop;
} }
@ -750,72 +815,74 @@ void ewol::Text::Print(const uniChar_t charcode)
* | | * | |
* 3------2 * 3------2
*/ */
etk::Vector2D<int32_t> bitmapDrawPos[4]; if (m_needDisplay == true) {
bitmapDrawPos[0].x = (int32_t)dxA; etk::Vector2D<int32_t> bitmapDrawPos[4];
bitmapDrawPos[1].x = (int32_t)dxB; bitmapDrawPos[0].x = (int32_t)dxA;
bitmapDrawPos[2].x = (int32_t)dxB; bitmapDrawPos[1].x = (int32_t)dxB;
bitmapDrawPos[3].x = (int32_t)dxA; bitmapDrawPos[2].x = (int32_t)dxB;
bitmapDrawPos[3].x = (int32_t)dxA;
bitmapDrawPos[0].y = (int32_t)dyC; bitmapDrawPos[0].y = (int32_t)dyC;
bitmapDrawPos[1].y = (int32_t)dyC; bitmapDrawPos[1].y = (int32_t)dyC;
bitmapDrawPos[2].y = (int32_t)dyD; bitmapDrawPos[2].y = (int32_t)dyD;
bitmapDrawPos[3].y = (int32_t)dyD; bitmapDrawPos[3].y = (int32_t)dyD;
/* texture Position : /* texture Position :
* 0------1 * 0------1
* | | * | |
* | | * | |
* 3------2 * 3------2
*/ */
etk::Vector2D<float> texturePos[4]; etk::Vector2D<float> texturePos[4];
texturePos[0].x = tuA+m_mode; texturePos[0].x = tuA+m_mode;
texturePos[1].x = tuB+m_mode; texturePos[1].x = tuB+m_mode;
texturePos[2].x = tuB+m_mode; texturePos[2].x = tuB+m_mode;
texturePos[3].x = tuA+m_mode; texturePos[3].x = tuA+m_mode;
texturePos[0].y = tvC; texturePos[0].y = tvC;
texturePos[1].y = tvC; texturePos[1].y = tvC;
texturePos[2].y = tvD; texturePos[2].y = tvD;
texturePos[3].y = tvD; texturePos[3].y = tvD;
// NOTE : Android does not support the Quads elements ... // NOTE : Android does not support the Quads elements ...
/* Step 1 : /* Step 1 :
* ******** * ********
* ****** * ******
* **** * ****
* ** * **
* *
*/ */
// set texture coordonates : // set texture coordonates :
m_coordTex.PushBack(texturePos[0]); m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[1]); m_coordTex.PushBack(texturePos[1]);
m_coordTex.PushBack(texturePos[2]); m_coordTex.PushBack(texturePos[2]);
// set display positions : // set display positions :
m_coord.PushBack(bitmapDrawPos[0]); m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[1]); m_coord.PushBack(bitmapDrawPos[1]);
m_coord.PushBack(bitmapDrawPos[2]); m_coord.PushBack(bitmapDrawPos[2]);
// set the color // set the color
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
/* Step 2 : /* Step 2 :
* *
* ** * **
* **** * ****
* ****** * ******
* ******** * ********
*/ */
// set texture coordonates : // set texture coordonates :
m_coordTex.PushBack(texturePos[0]); m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[2]); m_coordTex.PushBack(texturePos[2]);
m_coordTex.PushBack(texturePos[3]); m_coordTex.PushBack(texturePos[3]);
// set display positions : // set display positions :
m_coord.PushBack(bitmapDrawPos[0]); m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[2]); m_coord.PushBack(bitmapDrawPos[2]);
m_coord.PushBack(bitmapDrawPos[3]); m_coord.PushBack(bitmapDrawPos[3]);
// set the color // set the color
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
}
} }
} }
} }
@ -829,16 +896,14 @@ void ewol::Text::Print(const uniChar_t charcode)
void ewol::Text::ForceLineReturn(void) void ewol::Text::ForceLineReturn(void)
{ {
// Reset position : // Reset position :
SetPos(etk::Vector3D<float>(m_startTextpos, SetPos(etk::Vector3D<float>(m_startTextpos, m_position.y - m_font->GetHeight(m_mode), 0) );
(float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) );
} }
void ewol::Text::SetTextAlignement(float startTextpos, float stopTextPos, ewol::Text::aligneMode_te alignement) void ewol::Text::SetTextAlignement(float startTextpos, float stopTextPos, ewol::Text::aligneMode_te alignement)
{ {
m_startTextpos = startTextpos; m_startTextpos = startTextpos;
m_stopTextPos = stopTextPos; m_stopTextPos = stopTextPos+1;
m_alignement = alignement; m_alignement = alignement;
if (m_startTextpos >= m_stopTextPos) { if (m_startTextpos >= m_stopTextPos) {
EWOL_ERROR("Request allignement with Borne position error : " << startTextpos << " => " << stopTextPos); EWOL_ERROR("Request allignement with Borne position error : " << startTextpos << " => " << stopTextPos);
@ -857,6 +922,41 @@ void ewol::Text::DisableAlignement(void)
m_alignement = ewol::Text::alignDisable; m_alignement = ewol::Text::alignDisable;
} }
etk::Vector3D<float> ewol::Text::CalculateSizeHTML(const etk::UString& text)
{
// remove intermediate result
Reset();
// disable display system
m_needDisplay = false;
SetPos(etk::Vector3D<float>(0,0,0) );
// same as print without the end display ...
PrintHTML(text);
// get the last elements
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
// set back the display system
m_needDisplay = true;
return etk::Vector3D<float>( m_sizeDisplayStop.x-m_sizeDisplayStart.x,
m_sizeDisplayStop.y-m_sizeDisplayStart.y,
m_sizeDisplayStop.z-m_sizeDisplayStart.z);
}
etk::Vector3D<float> ewol::Text::CalculateSizeDecorated(const etk::UString& text)
{
etk::UString tmpData("<html><body>\n");
tmpData+=text;
tmpData+="\n</body></html>\n";
etk::Vector3D<float> tmpVal = CalculateSizeHTML(tmpData);
return tmpVal;
}
etk::Vector3D<float> ewol::Text::CalculateSize(const etk::UString& text) etk::Vector3D<float> ewol::Text::CalculateSize(const etk::UString& text)
{ {
if (m_font == NULL) { if (m_font == NULL) {
@ -925,10 +1025,17 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
float endPos = m_position.x; float endPos = m_position.x;
bool endOfLine = false; bool endOfLine = false;
float stopPosition = m_stopTextPos;
if( false == m_needDisplay
|| m_stopTextPos == m_startTextpos) {
stopPosition = m_startTextpos + 3999999999.0;
}
for (int32_t iii=start; iii<text.Size(); iii++) { for (int32_t iii=start; iii<text.Size(); iii++) {
etk::Vector3D<float> tmpSize = CalculateSize(text[iii]); etk::Vector3D<float> tmpSize = CalculateSize(text[iii]);
// check oveflow : // check oveflow :
if (endPos + tmpSize.x > m_stopTextPos) { if (endPos + tmpSize.x > stopPosition) {
stop = iii; stop = iii;
break; break;
} }
@ -936,7 +1043,7 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
if (text[iii] == (uniChar_t)' ') { if (text[iii] == (uniChar_t)' ') {
space++; space++;
lastSpacePosition = iii; lastSpacePosition = iii;
lastSpacefreeSize = m_stopTextPos - endPos; lastSpacefreeSize = stopPosition - endPos;
} else if (text[iii] == (uniChar_t)'\n') { } else if (text[iii] == (uniChar_t)'\n') {
stop = iii; stop = iii;
endOfLine = true; endOfLine = true;
@ -945,7 +1052,7 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
// update local size : // update local size :
endPos += tmpSize.x; endPos += tmpSize.x;
} }
freeSpace = m_stopTextPos - endPos; freeSpace = stopPosition - endPos;
// retore previous : // retore previous :
m_previousCharcode = storePrevious; m_previousCharcode = storePrevious;
// need to align left or right ... // need to align left or right ...

View File

@ -49,6 +49,11 @@ namespace ewol
private: private:
ewol::Drawing m_vectorialDraw; //!< This is used to draw background selection and other things ... ewol::Drawing m_vectorialDraw; //!< This is used to draw background selection and other things ...
private: private:
int32_t m_nbCharDisplayed; //!< prevent some error in calculation size.
etk::Vector3D<float> m_sizeDisplayStart; //!< The start windows of the display.
etk::Vector3D<float> m_sizeDisplayStop; //!< The end windows of the display.
bool m_needDisplay; //!< This just need the display and not the size rendering.
etk::Vector3D<float> m_position; //!< The current position to draw etk::Vector3D<float> m_position; //!< The current position to draw
etk::Vector3D<float> m_clippingPosStart; //!< Clipping start position etk::Vector3D<float> m_clippingPosStart; //!< Clipping start position
etk::Vector3D<float> m_clippingPosStop; //!< Clipping stop position etk::Vector3D<float> m_clippingPosStop; //!< Clipping stop position
@ -116,9 +121,13 @@ namespace ewol
*/ */
void Draw(void); void Draw(void);
/** /**
* @brief Clear alll tre registered element in the current element * @brief Clear all the registered element in the current element
*/ */
void Clear(void); void Clear(void);
/**
* @brief Clear all the intermediate result detween 2 prints
*/
void Reset(void);
/** /**
* @brief Get the current display position (sometime needed in the gui control) * @brief Get the current display position (sometime needed in the gui control)
* @return the current position. * @return the current position.
@ -273,7 +282,7 @@ namespace ewol
* @param[in] text The string to display. * @param[in] text The string to display.
* @TODO : implementation not done .... * @TODO : implementation not done ....
*/ */
void PrintHTML(etk::UString& text); void PrintHTML(etk::UString text);
/** /**
* @brief Display a compleat string in the current element whith specific decorations (advence mode). * @brief Display a compleat string in the current element whith specific decorations (advence mode).
* @param[in] text The string to display. * @param[in] text The string to display.
@ -289,11 +298,13 @@ namespace ewol
* @brief This Generate the line return ==> it return to the alignement position start and at the correct line position ==> it might be use to not know the line height * @brief This Generate the line return ==> it return to the alignement position start and at the correct line position ==> it might be use to not know the line height
*/ */
void ForceLineReturn(void); void ForceLineReturn(void);
private:
/** /**
* @brief This parse a tinyXML node (void pointer to permit to hide tiny XML in include) * @brief This parse a tinyXML node (void pointer to permit to hide tiny XML in include).
* @param[in] element the tynyXML element : TiXmlNode* * @param[in] element the tynyXML element : TiXmlNode* .
*/ */
void ParseHtmlNode( void* element); void ParseHtmlNode(void* element);
public:
/** /**
* @brief This generate the possibility to generate the big text property * @brief This generate the possibility to generate the big text property
* @param[in] startTextpos The x text start position of the display. * @param[in] startTextpos The x text start position of the display.
@ -311,6 +322,18 @@ namespace ewol
* @return the curent alignement type * @return the curent alignement type
*/ */
ewol::Text::aligneMode_te GetAlignement(void); ewol::Text::aligneMode_te GetAlignement(void);
/**
* @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention.
* @return The theoric size used.
*/
etk::Vector3D<float> CalculateSizeHTML(const etk::UString& text);
/**
* @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention.
* @return The theoric size used.
*/
etk::Vector3D<float> CalculateSizeDecorated(const etk::UString& text);
/** /**
* @brief Calculate a theoric text size * @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention. * @param[in] text The string to calculate dimention.

View File

@ -70,10 +70,12 @@ void widget::Button::SetImageToggle(etk::UString imageName)
bool widget::Button::CalculateMinSize(void) bool widget::Button::CalculateMinSize(void)
{ {
etk::Vector2D<float> padding = m_shaper.GetPadding(); etk::Vector2D<float> padding = m_shaper.GetPadding();
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize(m_label); m_displayText.Clear();
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSizeDecorated(m_label);
if( true == m_toggleMode if( true == m_toggleMode
&& m_labelToggle.Size()!=0) { && m_labelToggle.Size()!=0) {
etk::Vector3D<int32_t> minSizeToggle = m_displayText.CalculateSize(m_labelToggle); m_displayText.Clear();
etk::Vector3D<int32_t> minSizeToggle = m_displayText.CalculateSizeDecorated(m_labelToggle);
minSize.x = etk_max(minSize.x, minSizeToggle.x); minSize.x = etk_max(minSize.x, minSizeToggle.x);
minSize.y = etk_max(minSize.y, minSizeToggle.y); minSize.y = etk_max(minSize.y, minSizeToggle.y);
minSize.z = etk_max(minSize.z, minSizeToggle.z); minSize.z = etk_max(minSize.z, minSizeToggle.z);
@ -155,40 +157,55 @@ void widget::Button::OnRegenerateDisplay(void)
if (true == NeedRedraw()) { if (true == NeedRedraw()) {
etk::Vector2D<float> padding = m_shaper.GetPadding(); etk::Vector2D<float> padding = m_shaper.GetPadding();
// to know the size of one Line :
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize('A');
etk::Vector3D<int32_t> curentTextSize;
if( false == m_toggleMode
|| false == m_value) {
curentTextSize = m_displayText.CalculateSizeDecorated(m_label);
} else {
curentTextSize = m_displayText.CalculateSizeDecorated(m_labelToggle);
}
m_displayImage.Clear(); m_displayImage.Clear();
m_displayImageToggle.Clear(); m_displayImageToggle.Clear();
m_shaper.Clear(); m_shaper.Clear();
m_displayText.Clear();
etk::Vector2D<int32_t> localSize = m_minSize; etk::Vector2D<int32_t> localSize = m_minSize;
etk::Vector3D<float> tmpOrigin((float)((m_size.x - m_minSize.x) / 2.0), etk::Vector3D<float> tmpOrigin((m_size.x - m_minSize.x) / 2.0,
(float)((m_size.y - m_minSize.y) / 2.0), (m_size.y - m_minSize.y) / 2.0,
(float)(0.0)); 0.0);
// no change for the text orogin : // no change for the text orogin :
etk::Vector3D<float> tmpTextOrigin((float)((m_size.x - m_minSize.x) / 2.0 + padding.x), etk::Vector3D<float> tmpTextOrigin((m_size.x - m_minSize.x) / 2.0,
(float)((m_size.y - m_minSize.y) / 2.0 + padding.y), (m_size.y - m_minSize.y) / 2.0,
(float)(0.0)); 0.0);
if (true==m_userFill.x) { if (true==m_userFill.x) {
localSize.x = m_size.x; localSize.x = m_size.x;
tmpOrigin.x = 0.0; tmpOrigin.x = 0.0;
tmpTextOrigin.x = 0.0;
} }
if (true==m_userFill.y) { if (true==m_userFill.y) {
localSize.y = m_size.y; localSize.y = m_size.y;
//tmpOrigin.y = 0.0;
} }
tmpOrigin.x += padding.x; tmpOrigin.x += padding.x;
tmpOrigin.y += padding.y; tmpOrigin.y += padding.y;
tmpTextOrigin.x += padding.x;
tmpTextOrigin.y += padding.y;
localSize.x -= 2*padding.x; localSize.x -= 2*padding.x;
localSize.y -= 2*padding.y; localSize.y -= 2*padding.y;
etk::Vector2D<float> textPos(tmpTextOrigin.x, tmpTextOrigin.x); tmpTextOrigin.y += (m_minSize.y-2*padding.y) - minSize.y;
etk::Vector2D<float> textPos(tmpTextOrigin.x, tmpTextOrigin.y);
if( true == m_displayImage.HasSources() if( true == m_displayImage.HasSources()
|| true == m_displayImageToggle.HasSources()) { || true == m_displayImageToggle.HasSources()) {
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize(m_label); // TODO : Remove this size calculation ==> can regenrate siomme errro
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSizeDecorated(m_label);
etk::Vector3D<int32_t> imagePos(tmpTextOrigin.x-padding.x/4, tmpTextOrigin.y-padding.x/4, 0); etk::Vector3D<int32_t> imagePos(tmpTextOrigin.x-padding.x/4, tmpTextOrigin.y-padding.x/4, 0);
etk::Vector2D<int32_t> imageSize(minSize.y+padding.x/2, minSize.y+padding.x/2); etk::Vector2D<int32_t> imageSize(minSize.y+padding.x/2, minSize.y+padding.x/2);
if( false==m_toggleMode if( false==m_toggleMode
@ -203,14 +220,15 @@ void widget::Button::OnRegenerateDisplay(void)
tmpTextOrigin.x += padding.x/2 + minSize.y; tmpTextOrigin.x += padding.x/2 + minSize.y;
} }
etk::Vector3D<float> drawClippingPos(0.0, 0.0, -0.5); etk::Vector3D<float> drawClippingPos(padding.x, padding.y, -0.5);
etk::Vector3D<float> drawClippingSize((float)(m_size.x - 2*padding.x), etk::Vector3D<float> drawClippingSize((float)(m_size.x - padding.x),
(float)(m_size.y - 2*padding.y), (float)(m_size.y - padding.y),
(float)1.0); (float)1.0);
// clean the element // clean the element
m_displayText.Clear(); m_displayText.Reset();
m_displayText.SetTextAlignement(0, localSize.x + 2*padding.x, ewol::Text::alignCenter); m_displayText.SetPos(tmpTextOrigin);
m_displayText.SetTextAlignement(tmpTextOrigin.x, tmpTextOrigin.x+localSize.x, ewol::Text::alignCenter);
m_displayText.SetClipping(drawClippingPos, drawClippingSize); m_displayText.SetClipping(drawClippingPos, drawClippingSize);
if( false == m_toggleMode if( false == m_toggleMode
|| false == m_value) { || false == m_value) {
@ -218,7 +236,7 @@ void widget::Button::OnRegenerateDisplay(void)
} else { } else {
m_displayText.PrintDecorated(m_labelToggle); m_displayText.PrintDecorated(m_labelToggle);
} }
m_displayText.Translate(tmpOrigin); //m_displayText.Translate(tmpOrigin);
if (true==m_userFill.y) { if (true==m_userFill.y) {

View File

@ -55,17 +55,17 @@ MainWindows::MainWindows(void)
return; return;
} }
mySizerVert->SubWidgetAdd(mySizerHori); mySizerVert->SubWidgetAdd(mySizerHori);
myButton = new widget::Button("<center>Expend X (false)</center>"); myButton = new widget::Button("<center>Expend X <br/> (false)</center>");
if (NULL != myButton) { if (NULL != myButton) {
myButton->SetToggleMode(true); myButton->SetToggleMode(true);
myButton->SetLabelToggle("<center>Expend X (true)</center>"); myButton->SetLabelToggle("<center>Expend X <br/> (true)</center>");
myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendX); myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendX);
mySizerHori->SubWidgetAdd(myButton); mySizerHori->SubWidgetAdd(myButton);
} }
myButton = new widget::Button("<center>Expend Y (false)</center>"); myButton = new widget::Button("<center>Expend Y <br/> (false)</center>");
if (NULL != myButton) { if (NULL != myButton) {
myButton->SetToggleMode(true); myButton->SetToggleMode(true);
myButton->SetLabelToggle("<center>Expend Y (true)</center>"); myButton->SetLabelToggle("<center>Expend Y <br/> (true)</center>");
myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendY); myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendY);
mySizerHori->SubWidgetAdd(myButton); mySizerHori->SubWidgetAdd(myButton);
} }
@ -121,7 +121,7 @@ MainWindows::MainWindows(void)
mySizerHori->SubWidgetAdd(m_spacer[idSpacer]); mySizerHori->SubWidgetAdd(m_spacer[idSpacer]);
} }
m_button = new widget::Button("My <font color=\"#FF0000\">Button</font>"); m_button = new widget::Button("My <font color=\"#FF0000\">Button</font> <br/> And Some under line<br/> plop <br/> and an other super long line ...");
if (NULL != m_button) { if (NULL != m_button) {
m_button->SetExpendX(false); m_button->SetExpendX(false);
m_button->SetExpendY(false); m_button->SetExpendY(false);