From 971905b0d593e0c207b72872bffc55502a45f6fe Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 14 Nov 2013 21:40:30 +0100 Subject: [PATCH] [DEBUG work again --- external/ejson | 2 +- external/etk | 2 +- sources/ewol/compositing/Text.cpp | 257 ++++++++++++++++++++++++++ sources/ewol/compositing/Text.h | 4 + sources/ewol/renderer/EObject.cpp | 2 + sources/ewol/resources/ConfigFile.cpp | 15 +- sources/ewol/resources/Image.cpp | 4 +- sources/ewol/widget/Button.cpp | 18 +- sources/ewol/widget/ButtonColor.cpp | 118 ++++++------ 9 files changed, 343 insertions(+), 79 deletions(-) diff --git a/external/ejson b/external/ejson index 66660541..564ec313 160000 --- a/external/ejson +++ b/external/ejson @@ -1 +1 @@ -Subproject commit 666605419cfab90d858f5687659a10e28146d97e +Subproject commit 564ec3130f3874c3bcc2235976f2d85996c4f770 diff --git a/external/etk b/external/etk index d2a3fcaa..4f25fd3d 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit d2a3fcaa63f1d942fcaafb205b806b37ad804090 +Subproject commit 4f25fd3ddc690dc066d81b601b9287c260a447fe diff --git a/sources/ewol/compositing/Text.cpp b/sources/ewol/compositing/Text.cpp index e71001d4..c6e19f47 100644 --- a/sources/ewol/compositing/Text.cpp +++ b/sources/ewol/compositing/Text.cpp @@ -362,11 +362,17 @@ void ewol::Text::setDistanceFieldMode(bool _newMode) { EWOL_TODO("The Distance field mode is not availlable for now ..."); } +void ewol::Text::print(const std::u32string& _text) { + std::vector decorationEmpty; + print(_text, decorationEmpty); +} + void ewol::Text::print(const std::string& _text) { std::vector decorationEmpty; print(_text, decorationEmpty); } + void ewol::Text::parseHtmlNode(exml::Element* _element) { // get the static real pointer if (_element == NULL) { @@ -686,6 +692,194 @@ void ewol::Text::print(const std::string& _text, const std::vector tmpFg(m_color); + etk::Color<> tmpBg(m_colorBg); + if (m_alignement == ewol::Text::alignDisable) { + //EWOL_DEBUG(" 1 print in not alligned mode : start=" << m_sizeDisplayStart << " stop=" << m_sizeDisplayStop << " pos=" << m_position); + // display the cursor if needed (if it is at the start position...) + if (m_needDisplay == true) { + if (0 == m_cursorPos) { + m_vectorialDraw.setPos(m_position); + setColorBg(m_colorCursor); + printCursor(false); + } + } + // note this is faster when nothing is requested ... + for(int32_t iii=0; iii<_text.size(); iii++) { + // check if ve have decoration + if (iii<_decoration.size()) { + tmpFg = _decoration[iii].m_colorFg; + tmpBg = _decoration[iii].m_colorBg; + setFontMode(_decoration[iii].m_mode); + } + // if real display : ( not display is for size calculation) + if (m_needDisplay == true) { + if( ( m_selectionStartPos-1= iii + && iii > m_cursorPos-1) ) { + setColor( 0x000000FF); + setColorBg(m_colorSelection); + } else { + setColor( tmpFg); + setColorBg(tmpBg); + } + } + if( m_needDisplay == true + && m_colorBg.a() != 0) { + vec3 pos = m_position; + m_vectorialDraw.setPos(pos); + print(_text[iii]); + float fontHeigh = m_font->getHeight(m_mode); + m_vectorialDraw.rectangleWidth(vec3(m_position.x()-pos.x(),fontHeigh,0.0f) ); + m_nbCharDisplayed++; + } else { + print(_text[iii]); + m_nbCharDisplayed++; + } + // display the cursor if needed (if it is at the other position...) + if (m_needDisplay == true) { + if (iii == m_cursorPos-1) { + m_vectorialDraw.setPos(m_position); + setColorBg(m_colorCursor); + printCursor(false); + } + } + } + //EWOL_DEBUG(" 2 print in not alligned mode : start=" << m_sizeDisplayStart << " stop=" << m_sizeDisplayStop << " pos=" << m_position); + } else { + //EWOL_DEBUG(" 3 print in not alligned mode : start=" << m_sizeDisplayStart << " stop=" << m_sizeDisplayStop << " pos=" << m_position); + // special start case at the right of the endpoint : + if (m_stopTextPos < m_position.x()) { + forceLineReturn(); + } + float basicSpaceWidth = calculateSize(char32_t(' ')).x(); + int32_t currentId = 0; + int32_t stop; + int32_t space; + int32_t freeSpace; + while (currentId < _text.size()) { + bool needNoJustify = extrapolateLastId(_text, currentId, stop, space, freeSpace); + float interpolation = basicSpaceWidth; + switch (m_alignement) { + case ewol::Text::alignJustify: + if (needNoJustify == false) { + interpolation += (float)freeSpace / (float)(space-1); + } + break; + case ewol::Text::alignDisable: // must not came from here ... + case ewol::Text::alignLeft: + // nothing to do ... + break; + case ewol::Text::alignRight: + if (m_needDisplay == true) { + // Move the first char at the right : + setPos(vec3(m_position.x() + freeSpace, + m_position.y(), + m_position.z()) ); + } + break; + case ewol::Text::alignCenter: + if (m_needDisplay == true) { + // Move the first char at the right : + setPos(vec3(m_position.x() + freeSpace/2, + m_position.y(), + m_position.z()) ); + } + break; + } + // display all the elements + if( m_needDisplay == true + && m_cursorPos == 0) { + m_vectorialDraw.setPos(m_position); + setColorBg(m_colorCursor); + printCursor(false); + } + for(int32_t iii=currentId; iiigetHeight(m_mode); + // get specific decoration if provided + if (iii<_decoration.size()) { + tmpFg = _decoration[iii].m_colorFg; + tmpBg = _decoration[iii].m_colorBg; + setFontMode(_decoration[iii].m_mode); + } + if (m_needDisplay == true) { + if( ( m_selectionStartPos-1= iii + && iii > m_cursorPos-1) ) { + setColor( 0x000000FF); + setColorBg(m_colorSelection); + } else { + setColor( tmpFg); + setColorBg(tmpBg); + } + } + // special for the justify mode + if (_text[iii] == etk::UChar::Space) { + //EWOL_DEBUG(" generateString : \" \""); + if( m_needDisplay == true + && m_colorBg.a() != 0) { + m_vectorialDraw.setPos(m_position); + } + // Must generate a dynamic space : + setPos(vec3(m_position.x() + interpolation, + m_position.y(), + m_position.z()) ); + if( m_needDisplay == true + && m_colorBg.a() != 0) { + m_vectorialDraw.rectangleWidth(vec3(interpolation,fontHeigh,0.0f) ); + } + } else { + //EWOL_DEBUG(" generateString : \"" << (char)text[iii] << "\""); + if( m_needDisplay == true + && m_colorBg.a() != 0) { + vec3 pos = m_position; + m_vectorialDraw.setPos(pos); + print(_text[iii]); + m_vectorialDraw.rectangleWidth(vec3(m_position.x()-pos.x(),fontHeigh,0.0f) ); + m_nbCharDisplayed++; + } else { + print(_text[iii]); + m_nbCharDisplayed++; + } + } + if (m_needDisplay == true) { + if (iii == m_cursorPos-1) { + m_vectorialDraw.setPos(m_position); + setColorBg(m_colorCursor); + printCursor(false); + } + } + } + if (currentId == stop) { + currentId++; + } else if(_text[stop] == etk::UChar::Space) { + currentId = stop+1; + // reset position : + setPos(vec3(m_startTextpos, + (float)(m_position.y() - m_font->getHeight(m_mode)), + m_position.z()) ); + m_nbCharDisplayed++; + } else if(_text[stop] == etk::UChar::Return) { + currentId = stop+1; + // reset position : + setPos(vec3(m_startTextpos, + (float)(m_position.y() - m_font->getHeight(m_mode)), + m_position.z()) ); + m_nbCharDisplayed++; + } else { + currentId = stop; + } + } + //EWOL_DEBUG(" 4 print in not alligned mode : start=" << m_sizeDisplayStart << " stop=" << m_sizeDisplayStop << " pos=" << m_position); + } +} void ewol::Text::print(const char32_t& _charcode) { @@ -1038,6 +1232,69 @@ bool ewol::Text::extrapolateLastId(const std::string& _text, } } +bool ewol::Text::extrapolateLastId(const std::u32string& _text, + const int32_t _start, + int32_t& _stop, + int32_t& _space, + int32_t& _freeSpace) { + // store previous : + char32_t storePrevious = m_previousCharcode; + + _stop = _text.size(); + _space = 0; + + int32_t lastSpacePosition = _start; + int32_t lastSpacefreeSize; + + float endPos = m_position.x(); + bool endOfLine = false; + + float stopPosition = m_stopTextPos; + if( m_needDisplay == false + || m_stopTextPos == m_startTextpos) { + stopPosition = m_startTextpos + 3999999999.0; + } + + for (int32_t iii=_start; iii<_text.size(); iii++) { + vec3 tmpSize = calculateSize(_text[iii]); + // check oveflow : + if (endPos + tmpSize.x() > stopPosition) { + _stop = iii; + break; + } + // save number of space : + if (_text[iii] == etk::UChar::Space) { + _space++; + lastSpacePosition = iii; + lastSpacefreeSize = stopPosition - endPos; + } else if (_text[iii] == etk::UChar::Return) { + _stop = iii; + endOfLine = true; + break; + } + // update local size : + endPos += tmpSize.x(); + } + _freeSpace = stopPosition - 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; + } + } +} + void ewol::Text::htmlAddData(const std::string& _data) { if( m_htmlCurrrentLine.size()>0 && m_htmlCurrrentLine[m_htmlCurrrentLine.size()-1] != ' ') { diff --git a/sources/ewol/compositing/Text.h b/sources/ewol/compositing/Text.h index c08ffe89..7abe810f 100644 --- a/sources/ewol/compositing/Text.h +++ b/sources/ewol/compositing/Text.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace ewol { /** @@ -236,6 +237,7 @@ namespace ewol { * @param[in] _text The string to display. */ void print(const std::string& _text); + void print(const std::u32string& _text); /** * @brief display a compleat string in the current element with the generic decoration specification. (basic html data) *
@@ -302,6 +304,7 @@ namespace ewol {
 			 * @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(const std::string& _text, const std::vector& _decoration);
+			void print(const std::u32string& _text, const std::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] _charcode Char that might be dispalyed
@@ -376,6 +379,7 @@ namespace ewol {
 			 * @return true if the rifht has free space that can be use for jystify (return false if we find \n
 			 */
 			bool extrapolateLastId(const std::string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace);
+			bool extrapolateLastId(const std::u32string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace);
 		private:
 			// this section is reserved for HTML parsing and display:
 			std::string m_htmlCurrrentLine; //!< current line for HTML display
diff --git a/sources/ewol/renderer/EObject.cpp b/sources/ewol/renderer/EObject.cpp
index 5287b99d..537c582e 100644
--- a/sources/ewol/renderer/EObject.cpp
+++ b/sources/ewol/renderer/EObject.cpp
@@ -67,10 +67,12 @@ void ewol::EObject::generateEventId(const char * _generateEventId, const std::st
 				if (NULL != m_externEvent[iii]->destEObject) {
 					if (m_externEvent[iii]->overloadData.size() <= 0){
 						ewol::EMessage tmpMsg(this, m_externEvent[iii]->destEventId, _data);
+						EWOL_VERBOSE("send message " << tmpMsg);
 						m_externEvent[iii]->destEObject->onReceiveMessage(tmpMsg);
 					} else {
 						// set the user requested data ...
 						ewol::EMessage tmpMsg(this, m_externEvent[iii]->destEventId, m_externEvent[iii]->overloadData);
+						EWOL_VERBOSE("send message " << tmpMsg);
 						m_externEvent[iii]->destEObject->onReceiveMessage(tmpMsg);
 					}
 				}
diff --git a/sources/ewol/resources/ConfigFile.cpp b/sources/ewol/resources/ConfigFile.cpp
index 9260f07f..0f998d15 100644
--- a/sources/ewol/resources/ConfigFile.cpp
+++ b/sources/ewol/resources/ConfigFile.cpp
@@ -10,15 +10,22 @@
 #include 
 #include 
 #include 
+#include 
 
 #undef __class__
 #define __class__	"ConfigFile"
 
 
-void ewol::SimpleConfigElement::parse(const std::string& value) {
-	m_valueInt = std::stoi(value);
-	m_valuefloat = std::stof(value);
-	m_value = value;
+void ewol::SimpleConfigElement::parse(const std::string& _value) {
+	m_value = _value;
+	try {
+		m_valueInt = std::stoi(_value);
+		m_valuefloat = std::stof(_value);
+	} catch (const std::invalid_argument& ia) {
+		EWOL_VERBOSE(" invalid argument= " << ia.what() << "val='" << _value << "'");
+		m_valueInt = 0;
+		m_valuefloat = 0;
+	}
 }
 
 
diff --git a/sources/ewol/resources/Image.cpp b/sources/ewol/resources/Image.cpp
index 01babe77..1f8c7168 100644
--- a/sources/ewol/resources/Image.cpp
+++ b/sources/ewol/resources/Image.cpp
@@ -88,9 +88,9 @@ ewol::TextureFile* ewol::TextureFile::keep(const std::string& _filename, ivec2 _
 			_size.setValue(nextP2(_size.x()), nextP2(_size.y()));
 		#endif
 		TmpFilename += ":";
-		TmpFilename += _size.x();
+		TmpFilename += std::to_string(_size.x());
 		TmpFilename += "x";
-		TmpFilename += _size.y();
+		TmpFilename += std::to_string(_size.y());
 	}
 	
 	EWOL_VERBOSE("KEEP: TextureFile: '" << TmpFilename << "' new size=" << _size);
diff --git a/sources/ewol/widget/Button.cpp b/sources/ewol/widget/Button.cpp
index 78f57134..8cf38579 100644
--- a/sources/ewol/widget/Button.cpp
+++ b/sources/ewol/widget/Button.cpp
@@ -89,12 +89,8 @@ void widget::Button::setShaperName(const std::string& _shaperName) {
 void widget::Button::setSubWidget(ewol::Widget* _subWidget) {
 	int32_t idWidget=0;
 	if (NULL!=m_subWidget[idWidget]) {
-		delete(m_subWidget[idWidget]);
-		// the pointer might already set at NULL:
-		if (NULL != m_subWidget[idWidget]) {
-			EWOL_ERROR("error while removing previous widget...");
-			m_subWidget[idWidget]=NULL;
-		}
+		m_subWidget[idWidget]->removeObject();
+		m_subWidget[idWidget]=NULL;
 	}
 	EWOL_VERBOSE("Add button : " << idWidget << " element : " << (int64_t)_subWidget);
 	m_subWidget[idWidget] = _subWidget;
@@ -106,12 +102,8 @@ void widget::Button::setSubWidget(ewol::Widget* _subWidget) {
 void widget::Button::setSubWidgetToggle(ewol::Widget* _subWidget) {
 	int32_t idWidget=1;
 	if (NULL!=m_subWidget[idWidget]) {
-		delete(m_subWidget[idWidget]);
-		// the pointer might already set at NULL:
-		if (NULL != m_subWidget[idWidget]) {
-			EWOL_ERROR("error while removing previous widget...");
-			m_subWidget[idWidget]=NULL;
-		}
+		m_subWidget[idWidget]->removeObject();
+		m_subWidget[idWidget]=NULL;
 	}
 	EWOL_VERBOSE("Add button : " << idWidget << " element : " << (int64_t)_subWidget);
 	m_subWidget[idWidget] = _subWidget;
@@ -318,7 +310,7 @@ bool widget::Button::onEventInput(const ewol::EventInput& _event) {
 					m_value = (m_value)?false:true;
 					//EWOL_DEBUG("Generate event : " << eventPressed);
 					generateEventId(eventPressed);
-					EWOL_CRITICAL("Generate event : " << eventValue << " val=" << m_value << " plop : " << std::to_string(m_value));
+					//EWOL_DEBUG("Generate event : " << eventValue << " val=" << m_value );
 					generateEventId(eventValue, std::to_string(m_value));
 					if(    false == m_toggleMode
 					    && true == m_value) {
diff --git a/sources/ewol/widget/ButtonColor.cpp b/sources/ewol/widget/ButtonColor.cpp
index 9ccdfc81..19cbb5ab 100644
--- a/sources/ewol/widget/ButtonColor.cpp
+++ b/sources/ewol/widget/ButtonColor.cpp
@@ -78,65 +78,67 @@ void widget::ButtonColor::onDraw(void) {
 
 
 void widget::ButtonColor::onRegenerateDisplay(void) {
-	if (true == needRedraw()) {
-		m_text.clear();
-		m_shaper.clear();
-		
-		vec2 padding = m_shaper.getPadding();
-		
-		std::string label = m_textColorFg.getString();
-		
-		ivec2 localSize = m_minSize;
-		
-		vec3 tmpOrigin((m_size.x() - m_minSize.x()) / 2.0,
-		               (m_size.y() - m_minSize.y()) / 2.0,
-		               0);
-		// no change for the text orogin : 
-		vec3 tmpTextOrigin((m_size.x() - m_minSize.x()) / 2.0,
-		                   (m_size.y() - m_minSize.y()) / 2.0,
-		                   0);
-		
-		if (true == m_userFill.x()) {
-			localSize.setX(m_size.x());
-			tmpOrigin.setX(0);
-			tmpTextOrigin.setX(0);
-		}
-		if (true == m_userFill.y()) {
-			localSize.setY(m_size.y());
-		}
-		tmpOrigin += vec3(padding.x(), padding.y(), 0);
-		tmpTextOrigin += vec3(padding.x(), padding.y(), 0);
-		localSize -= ivec2(2*padding.x(), 2*padding.y());
-		
-		// clean the element
-		m_text.reset();
-		if(    m_textColorFg.r() < 100
-		    || m_textColorFg.g() < 100
-		    || m_textColorFg.b() < 100) {
-			m_text.setColor(etk::color::white);
-		} else {
-			m_text.setColor(etk::color::black);
-		}
-		m_text.setPos(tmpTextOrigin);
-		m_text.setColorBg(m_textColorFg);
-		m_text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::Text::alignCenter);
-		m_text.print(label);
-		
-		
-		if (true == m_userFill.y()) {
-			tmpOrigin.setY(padding.y());
-		}
-		
-		// selection area :
-		m_selectableAreaPos = vec2(tmpOrigin.x()-padding.x(), tmpOrigin.y()-padding.y());
-		m_selectableAreaSize = localSize + vec2(2,2)*padding;
-		m_shaper.setOrigin(m_selectableAreaPos );
-		m_shaper.setSize(m_selectableAreaSize);
-		m_shaper.setInsidePos(vec2(tmpTextOrigin.x(), tmpTextOrigin.y()) );
-		vec3 tmpp = m_text.calculateSize(label);
-		vec2 tmpp2(tmpp.x(), tmpp.y());
-		m_shaper.setInsideSize(tmpp2);
+	if (needRedraw() == false) {
+		return;
 	}
+	EWOL_DEBUG("redraw");
+	m_text.clear();
+	m_shaper.clear();
+	
+	vec2 padding = m_shaper.getPadding();
+	
+	std::string label = m_textColorFg.getString();
+	
+	ivec2 localSize = m_minSize;
+	
+	vec3 tmpOrigin((m_size.x() - m_minSize.x()) / 2.0,
+	               (m_size.y() - m_minSize.y()) / 2.0,
+	               0);
+	// no change for the text orogin : 
+	vec3 tmpTextOrigin((m_size.x() - m_minSize.x()) / 2.0,
+	                   (m_size.y() - m_minSize.y()) / 2.0,
+	                   0);
+	
+	if (true == m_userFill.x()) {
+		localSize.setX(m_size.x());
+		tmpOrigin.setX(0);
+		tmpTextOrigin.setX(0);
+	}
+	if (true == m_userFill.y()) {
+		localSize.setY(m_size.y());
+	}
+	tmpOrigin += vec3(padding.x(), padding.y(), 0);
+	tmpTextOrigin += vec3(padding.x(), padding.y(), 0);
+	localSize -= ivec2(2*padding.x(), 2*padding.y());
+	
+	// clean the element
+	m_text.reset();
+	if(    m_textColorFg.r() < 100
+	    || m_textColorFg.g() < 100
+	    || m_textColorFg.b() < 100) {
+		m_text.setColor(etk::color::white);
+	} else {
+		m_text.setColor(etk::color::black);
+	}
+	m_text.setPos(tmpTextOrigin);
+	m_text.setColorBg(m_textColorFg);
+	m_text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::Text::alignCenter);
+	m_text.print(label);
+	
+	
+	if (true == m_userFill.y()) {
+		tmpOrigin.setY(padding.y());
+	}
+	
+	// selection area :
+	m_selectableAreaPos = vec2(tmpOrigin.x()-padding.x(), tmpOrigin.y()-padding.y());
+	m_selectableAreaSize = localSize + vec2(2,2)*padding;
+	m_shaper.setOrigin(m_selectableAreaPos );
+	m_shaper.setSize(m_selectableAreaSize);
+	m_shaper.setInsidePos(vec2(tmpTextOrigin.x(), tmpTextOrigin.y()) );
+	vec3 tmpp = m_text.calculateSize(label);
+	vec2 tmpp2(tmpp.x(), tmpp.y());
+	m_shaper.setInsideSize(tmpp2);
 }