From 81458d0523f507a433497c692a83a70c7746330a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 20 May 2013 22:09:16 +0200 Subject: [PATCH] [DEV] correct layer getWidgetAtPos and remove temporary debug to fing string error, and add functotion to remove sub element in delayed --- external/etk | 2 +- sources/ewol/eObject/EObject.cpp | 2 ++ .../ewol/renderer/resources/TexturedFont.cpp | 2 +- sources/ewol/widget/Button.cpp | 9 +++--- sources/ewol/widget/Container.cpp | 32 +++++++++++++------ sources/ewol/widget/Container.h | 4 +++ sources/ewol/widget/ContainerN.cpp | 21 ++++++++++-- sources/ewol/widget/ContainerN.h | 4 +++ sources/ewol/widget/Layer.cpp | 24 ++++++++++++++ sources/ewol/widget/Layer.h | 1 + sources/ewol/widget/Widget.cpp | 13 ++++---- 11 files changed, 90 insertions(+), 24 deletions(-) diff --git a/external/etk b/external/etk index 8acac891..b433625d 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 8acac8918b8899a4ededb35e99469ac7227465fe +Subproject commit b433625df8188ca5d27d5adb1eedbf42c4590744 diff --git a/sources/ewol/eObject/EObject.cpp b/sources/ewol/eObject/EObject.cpp index 2caf5ade..30e5b5c3 100644 --- a/sources/ewol/eObject/EObject.cpp +++ b/sources/ewol/eObject/EObject.cpp @@ -315,7 +315,9 @@ bool ewol::EObject::StoreXML(TiXmlNode* _node) const bool ewol::EObject::OnSetConfig(const ewol::EConfig& _conf) { + EWOL_DEBUG("[" << GetId() << "] {" << GetObjectType() << "} set config : " << _conf); if (_conf.GetConfig() == ewol::EObject::configName) { + EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} Set config name : \"" << _conf.GetData() << "\""); SetName(_conf.GetData()); return true; } diff --git a/sources/ewol/renderer/resources/TexturedFont.cpp b/sources/ewol/renderer/resources/TexturedFont.cpp index 397b93f1..e85e469f 100644 --- a/sources/ewol/renderer/resources/TexturedFont.cpp +++ b/sources/ewol/renderer/resources/TexturedFont.cpp @@ -192,7 +192,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) : } for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { - if (m_fileName[iiiFontId].IsEmpty()==false) { + if (m_fileName[iiiFontId].IsEmpty()==true) { EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" ==> size=" << m_size ); m_font[iiiFontId] = NULL; continue; diff --git a/sources/ewol/widget/Button.cpp b/sources/ewol/widget/Button.cpp index 65f23633..a50c2624 100644 --- a/sources/ewol/widget/Button.cpp +++ b/sources/ewol/widget/Button.cpp @@ -105,7 +105,7 @@ void widget::Button::SetSubWidget(ewol::Widget* _subWidget) m_subWidget[idWidget]=NULL; } } - EWOL_DEBUG("Add button : " << idWidget << " element : " << (int64_t)_subWidget); + EWOL_VERBOSE("Add button : " << idWidget << " element : " << (int64_t)_subWidget); m_subWidget[idWidget] = _subWidget; // element change ... We need to recalculate all the subElments : ewol::RequestUpdateSize(); @@ -123,7 +123,7 @@ void widget::Button::SetSubWidgetToggle(ewol::Widget* _subWidget) m_subWidget[idWidget]=NULL; } } - EWOL_DEBUG("Add button : " << idWidget << " element : " << (int64_t)_subWidget); + EWOL_VERBOSE("Add button : " << idWidget << " element : " << (int64_t)_subWidget); m_subWidget[idWidget] = _subWidget; // element change ... We need to recalculate all the subElments : ewol::RequestUpdateSize(); @@ -407,8 +407,9 @@ void widget::Button::PeriodicCall(int64_t _localTime) ewol::Widget* widget::Button::GetWidgetNamed(const etk::UString& _widgetName) { - if (GetName()==_widgetName) { - return this; + ewol::Widget* tmpUpperWidget = ewol::Widget::GetWidgetNamed(_widgetName); + if (NULL!=tmpUpperWidget) { + return tmpUpperWidget; } if (m_subWidget[0]!= NULL) { ewol::Widget* tmpWidget = m_subWidget[0]->GetWidgetNamed(_widgetName); diff --git a/sources/ewol/widget/Container.cpp b/sources/ewol/widget/Container.cpp index 41f38be6..de56cdb7 100644 --- a/sources/ewol/widget/Container.cpp +++ b/sources/ewol/widget/Container.cpp @@ -54,17 +54,29 @@ void widget::Container::SubWidgetRemove(void) delete(m_subWidget); // might have been destroy first here : if (m_subWidget!=NULL) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} An error Occured when removing main node"); + EWOL_ERROR("Composer : An error Occured when removing main node"); } MarkToRedraw(); ewol::RequestUpdateSize(); } } +void widget::Container::SubWidgetRemoveDelayed(void) +{ + if (NULL != m_subWidget) { + m_subWidget->RemoveUpperWidget(); + m_subWidget->RemoveObject(); + m_subWidget=NULL; + MarkToRedraw(); + ewol::RequestUpdateSize(); + } +} + ewol::Widget* widget::Container::GetWidgetNamed(const etk::UString& _widgetName) { - if (GetName()==_widgetName) { - return this; + ewol::Widget* tmpUpperWidget = ewol::Widget::GetWidgetNamed(_widgetName); + if (NULL!=tmpUpperWidget) { + return tmpUpperWidget; } if (NULL != m_subWidget) { return m_subWidget->GetWidgetNamed(_widgetName); @@ -133,7 +145,7 @@ void widget::Container::CalculateMinMaxSize(void) vec2 min = m_subWidget->GetCalculateMinSize(); m_minSize.setMax(min); } - //EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} Result min size : " << m_minSize); + //EWOL_ERROR("[" << GetId() << "] Result min size : " << m_minSize); } void widget::Container::OnRegenerateDisplay(void) @@ -162,7 +174,7 @@ bool widget::Container::LoadXML(TiXmlNode* _node) // parse generic properties : ewol::Widget::LoadXML(_node); // remove previous element : - SubWidgetRemove(); + SubWidgetRemoveDelayed(); // parse all the elements : for(TiXmlNode * pNode = _node->FirstChild() ; @@ -174,23 +186,23 @@ bool widget::Container::LoadXML(TiXmlNode* _node) } etk::UString widgetName = pNode->Value(); if (ewol::widgetManager::Exist(widgetName) == false) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} (l "<Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" ); + EWOL_ERROR("(l "<Row()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" ); continue; } if (NULL != GetSubWidget()) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} (l "<Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); + EWOL_ERROR("(l "<Row()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); continue; } - EWOL_DEBUG("[" << GetId() << "] {" << GetObjectType() << "} try to create subwidget : '" << widgetName << "'"); + EWOL_DEBUG("try to create subwidget : '" << widgetName << "'"); ewol::Widget* tmpWidget = ewol::widgetManager::Create(widgetName); if (tmpWidget == NULL) { - EWOL_ERROR ("[" << GetId() << "] {" << GetObjectType() << "} (l "<Row()<<") Can not create the widget : \"" << widgetName << "\""); + EWOL_ERROR ("(l "<Row()<<") Can not create the widget : \"" << widgetName << "\""); continue; } // add widget : SetSubWidget(tmpWidget); if (false == tmpWidget->LoadXML(pNode)) { - EWOL_ERROR ("[" << GetId() << "] {" << GetObjectType() << "} (l "<Row()<<") can not load widget properties : \"" << widgetName << "\""); + EWOL_ERROR ("(l "<Row()<<") can not load widget properties : \"" << widgetName << "\""); return false; } } diff --git a/sources/ewol/widget/Container.h b/sources/ewol/widget/Container.h index fc2de6cf..2ba9b57d 100644 --- a/sources/ewol/widget/Container.h +++ b/sources/ewol/widget/Container.h @@ -46,6 +46,10 @@ namespace widget * @brief Remove the subWidget node. */ void SubWidgetRemove(void); + /** + * @brief Remove the subWidget node (delayed to prevent remove in the callbback). + */ + virtual void SubWidgetRemoveDelayed(void); public: // Derived function virtual void SystemDraw(const ewol::DrawProperty& _displayProp); diff --git a/sources/ewol/widget/ContainerN.cpp b/sources/ewol/widget/ContainerN.cpp index dbf72d2e..2001f09a 100644 --- a/sources/ewol/widget/ContainerN.cpp +++ b/sources/ewol/widget/ContainerN.cpp @@ -144,11 +144,27 @@ void widget::ContainerN::SubWidgetRemoveAll(void) } m_subWidget.Clear(); } +void widget::ContainerN::SubWidgetRemoveAllDelayed(void) +{ + // the size automaticly decrement with the auto call of the OnObjectRemove function + for(int32_t iii=0; iiiRemoveUpperWidget(); + m_subWidget[iii]->RemoveObject(); + m_subWidget[iii] = NULL; + } else { + EWOL_WARNING("[" << GetId() << "] {" << GetObjectType() << "} Must not have null pointer on the subWidget list ..."); + } + } + m_subWidget.Clear(); +} + ewol::Widget* widget::ContainerN::GetWidgetNamed(const etk::UString& _widgetName) { - if (GetName()==_widgetName) { - return this; + ewol::Widget* tmpUpperWidget = ewol::Widget::GetWidgetNamed(_widgetName); + if (NULL!=tmpUpperWidget) { + return tmpUpperWidget; } for (int32_t iii=0; iiiRow()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << ewol::widgetManager::List() << "]" ); continue; } + EWOL_DEBUG("[" << GetId() << "] {" << GetObjectType() << "} load new element : \"" << widgetName << "\""); ewol::Widget *subWidget = ewol::widgetManager::Create(widgetName); if (subWidget == NULL) { EWOL_ERROR ("[" << GetId() << "] {" << GetObjectType() << "} (l "<Row()<<") Can not create the widget : \"" << widgetName << "\""); diff --git a/sources/ewol/widget/ContainerN.h b/sources/ewol/widget/ContainerN.h index f7ffa192..0f343e9e 100644 --- a/sources/ewol/widget/ContainerN.h +++ b/sources/ewol/widget/ContainerN.h @@ -47,6 +47,10 @@ namespace widget * @brief Remove all sub element from the widget. */ virtual void SubWidgetRemoveAll(void); + /** + * @brief Remove all sub element from the widget (delayed to prevent remove in the callbback). + */ + virtual void SubWidgetRemoveAllDelayed(void); /** * @brief Add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) * @param[in] _newWidget the element pointer diff --git a/sources/ewol/widget/Layer.cpp b/sources/ewol/widget/Layer.cpp index 883690d6..57c98bfe 100644 --- a/sources/ewol/widget/Layer.cpp +++ b/sources/ewol/widget/Layer.cpp @@ -39,3 +39,27 @@ widget::Layer::~Layer(void) EWOL_DEBUG("[" << GetId() << "] Layer : destroy"); } +ewol::Widget* widget::Layer::GetWidgetAtPos(const vec2& _pos) +{ + if (true == IsHide()) { + return NULL; + } + // for all element in the sizer ... + for (int32_t iii=0; iiiGetSize(); + vec2 tmpOrigin = m_subWidget[iii]->GetOrigin(); + if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) + && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) + { + ewol::Widget * tmpWidget = m_subWidget[iii]->GetWidgetAtPos(_pos); + if (NULL != tmpWidget) { + return tmpWidget; + } + // parse the next layer ... + } + } + } + return NULL; +}; + diff --git a/sources/ewol/widget/Layer.h b/sources/ewol/widget/Layer.h index 1a9ea2c5..9376ae01 100644 --- a/sources/ewol/widget/Layer.h +++ b/sources/ewol/widget/Layer.h @@ -36,6 +36,7 @@ namespace widget { virtual ~Layer(void); public: virtual const char * const GetObjectType(void) { return "Ewol::Layer"; }; + virtual ewol::Widget* GetWidgetAtPos(const vec2& _pos); }; }; diff --git a/sources/ewol/widget/Widget.cpp b/sources/ewol/widget/Widget.cpp index e49c4cb7..126c88e9 100644 --- a/sources/ewol/widget/Widget.cpp +++ b/sources/ewol/widget/Widget.cpp @@ -396,7 +396,7 @@ void ewol::Widget::SetOrigin(const vec2& _pos) #if DEBUG_LEVEL > 2 if( m_origin.x() < -5000 || m_origin.y() < -5000) { - EWOL_WARNING("[" << GetId() << "] {" << GetObjectType() << "} Set origin < 5000 : " << m_origin); + EWOL_WARNING("[" << GetId() << "] Set origin < 5000 : " << m_origin); } #endif m_origin = _pos; @@ -415,9 +415,9 @@ vec2 ewol::Widget::RelativePosition(const vec2& _pos) void ewol::Widget::CalculateMinMaxSize(void) { m_minSize = m_userMinSize.GetPixel(); + //EWOL_ERROR("[" << GetId() << "] convert in min size : " << m_userMinSize << " out=" << m_minSize); m_maxSize = m_userMaxSize.GetPixel(); MarkToRedraw(); - //EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} convert in min size : " << m_userMinSize << " out=" << m_minSize); } vec2 ewol::Widget::GetCalculateMinSize(void) @@ -449,7 +449,7 @@ void ewol::Widget::SetMinSize(const ewol::Dimension& _size) error=true; } if (error==true) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} Can not set a 'min Size' > 'max size' set nothing ..."); + EWOL_ERROR("Can not set a 'min Size' > 'max size' set nothing ..."); return; } m_userMinSize = _size; @@ -481,7 +481,7 @@ void ewol::Widget::SetMaxSize(const ewol::Dimension& _size) error=true; } if (error==true) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} Can not set a 'min Size' > 'max size' set nothing ..."); + EWOL_ERROR("Can not set a 'min Size' > 'max size' set nothing ..."); return; } m_userMaxSize = _size; @@ -551,13 +551,13 @@ void ewol::Widget::ShortCutAdd(const char * _descriptiveString, const char * _ge if( NULL==_descriptiveString || 0==strlen(_descriptiveString)) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} try to add shortcut with no descriptive string ..."); + EWOL_ERROR("try to add shortcut with no descriptive string ..."); return; } EventShortCut* tmpElement = new EventShortCut(); if (NULL == tmpElement) { - EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} allocation error ... Memory error ..."); + EWOL_ERROR("allocation error ... Memory error ..."); return; } tmpElement->broadcastEvent = _broadcast; @@ -736,6 +736,7 @@ bool ewol::Widget::LoadXML(TiXmlNode* _node) ewol::Widget* ewol::Widget::GetWidgetNamed(const etk::UString& _widgetName) { + EWOL_DEBUG("[" << GetId() << "] {" << GetObjectType() << "} compare : " << GetName() << "==" << _widgetName ); if (GetName()==_widgetName) { return this; }