From afae43697d08d60b6694ad1352ab8eaaf94871db Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Wed, 11 Apr 2012 22:11:25 +0200 Subject: [PATCH] add layer widget --- Sources/libewol/ewol/widget/Layer.cpp | 301 ++++++++++++++++++++++++++ Sources/libewol/ewol/widget/Layer.h | 103 +++++++++ Sources/libewol/file.mk | 1 + 3 files changed, 405 insertions(+) create mode 100644 Sources/libewol/ewol/widget/Layer.cpp create mode 100644 Sources/libewol/ewol/widget/Layer.h diff --git a/Sources/libewol/ewol/widget/Layer.cpp b/Sources/libewol/ewol/widget/Layer.cpp new file mode 100644 index 00000000..1fd03a7e --- /dev/null +++ b/Sources/libewol/ewol/widget/Layer.cpp @@ -0,0 +1,301 @@ +/** + ******************************************************************************* + * @file ewol/widget/Layer.cpp + * @brief ewol layer widget system (Sources) + * @author Edouard DUPIN + * @date 11/04/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + +#include +#include + + +#undef __class__ +#define __class__ "Layer" + + +ewol::Layer::Layer(void) +{ + // set contamination enable + LockExpendContamination(); +} + +ewol::Layer::~Layer(void) +{ + SubWidgetRemoveAll(); +} + + +//!< EObject name : +extern const char * const ewol::TYPE_EOBJECT_WIDGET_LAYER = "Layer"; + +/** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ +bool ewol::Layer::CheckObjectType(const char * const objectType) +{ + if (NULL == objectType) { + EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_LAYER << "\" != NULL(pointer) "); + return false; + } + if (objectType == ewol::TYPE_EOBJECT_WIDGET_LAYER) { + return true; + } else { + if(true == ewol::Widget::CheckObjectType(objectType)) { + return true; + } + EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_LAYER << "\" != \"" << objectType << "\""); + return false; + } +} + +/** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ +const char * const ewol::Layer::GetObjectType(void) +{ + return ewol::TYPE_EOBJECT_WIDGET_LAYER; +} + + + +bool ewol::Layer::CalculateSize(etkFloat_t availlableX, etkFloat_t availlableY) +{ + //EWOL_DEBUG("Update Size"); + m_size.x = availlableX; + m_size.y = availlableY; + for (int32_t iii=0; iiiSetOrigin(m_origin.x, m_origin.y); + m_subWidget[m_currentCreateId][iii]->CalculateSize(m_size.x, m_size.y); + } + } + MarkToReedraw(); + return true; +} + + +bool ewol::Layer::CalculateMinSize(void) +{ + m_userExpendX=false; + m_userExpendY=false; + m_minSize.x = 0.0; + m_minSize.y = 0.0; + for (int32_t iii=0; iiiCalculateMinSize(); + if (true == m_subWidget[m_currentCreateId][iii]->CanExpentX()) { + m_userExpendX = true; + } + if (true == m_subWidget[m_currentCreateId][iii]->CanExpentY()) { + m_userExpendY = true; + } + coord2D_ts tmpSize = m_subWidget[m_currentCreateId][iii]->GetMinSize(); + m_minSize.x = etk_max(tmpSize.x, m_minSize.x); + m_minSize.y = etk_max(tmpSize.y, m_minSize.y); + } + } + return true; +} + +void ewol::Layer::SetMinSise(etkFloat_t x, etkFloat_t y) +{ + EWOL_ERROR("Layer can not have a user Minimum size (herited from under elements)"); +} + +void ewol::Layer::SetExpendX(bool newExpend) +{ + EWOL_ERROR("Layer can not have a user expend settings X (herited from under elements)"); +} + +bool ewol::Layer::CanExpentX(void) +{ + if (true == m_lockExpendContamination) { + return false; + } + return m_userExpendX; +} + +void ewol::Layer::SetExpendY(bool newExpend) +{ + EWOL_ERROR("Sizer can not have a user expend settings Y (herited from under elements)"); +} + +bool ewol::Layer::CanExpentY(void) +{ + if (true == m_lockExpendContamination) { + return false; + } + return m_userExpendY; +} + +void ewol::Layer::LockExpendContamination(bool lockExpend) +{ + m_lockExpendContamination = lockExpend; +} + +//etk::VectorType m_SubWidget; + +void ewol::Layer::SubWidgetRemoveAll(void) +{ + for (int32_t iii=0; iiiMarkToRemove(); + m_subWidget[m_currentCreateId][iii] = NULL; + } + m_subWidget[m_currentCreateId].Clear(); +} + + +void ewol::Layer::SubWidgetAdd(ewol::Widget* newWidget) +{ + if (NULL == newWidget) { + return; + } + m_subWidget[m_currentCreateId].PushBack(newWidget); +} + + +void ewol::Layer::SubWidgetRemove(ewol::Widget* newWidget) +{ + if (NULL == newWidget) { + return; + } + for (int32_t iii=0; iiiMarkToRemove(); + m_subWidget[m_currentCreateId][iii] = NULL; + m_subWidget[m_currentCreateId].Erase(iii); + return; + } + } +} + +void ewol::Layer::SubWidgetUnLink(ewol::Widget* newWidget) +{ + if (NULL == newWidget) { + return; + } + for (int32_t iii=0; iiiGenDraw(); + } + } +} + + + +void ewol::Layer::OnRegenerateDisplay(void) +{ + for (int32_t iii=0; iiiOnRegenerateDisplay(); + } + } +} + + +/** + * @brief Get the widget at the specific windows absolute position + * @param[in] pos gAbsolute position of the requested widget knowledge + * @return NULL No widget found + * @return pointer on the widget found + */ +ewol::Widget * ewol::Layer::GetWidgetAtPos(coord2D_ts pos) +{ + // for all element in the sizer ... + for (int32_t iii=0; iiiGetSize(); + coord2D_ts tmpOrigin = m_subWidget[m_currentCreateId][iii]->GetOrigin(); + if( (tmpOrigin.x <= pos.x && tmpOrigin.x + tmpSize.x >= pos.x) + && (tmpOrigin.y <= pos.y && tmpOrigin.y + tmpSize.y >= pos.y) ) + { + return m_subWidget[m_currentCreateId][iii]->GetWidgetAtPos(pos); + } + } + } + // otherwise the event go to this widget ... + return this; +} + + +/** + * @brief Event generated to inform a flip-flop has occured on the current widget + * @param --- + * @return --- + */ +void ewol::Layer::OnFlipFlopEvent(void) +{ + bool needFlipFlop = m_needFlipFlop; + // call herited classes + ewol::Widget::OnFlipFlopEvent(); + // internal saving + if (true == needFlipFlop) { + m_subWidget[m_currentCreateId] = m_subWidget[m_currentDrawId]; + } + // in every case, we propagate the flip-flop EVENT + for(int32_t iii=0; iiiOnFlipFlopEvent(); + } + } +} + + +/** + * @brief Inform object that an other object is removed ... + * @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject + * @note : Sub classes must call this class + * @return --- + */ +void ewol::Layer::OnObjectRemove(ewol::EObject * removeObject) +{ + // First step call parrent : + ewol::Widget::OnObjectRemove(removeObject); + // second step find if in all the elements ... + for(int32_t iii=m_subWidget[m_currentCreateId].Size()-1; iii>=0; iii--) { + if(m_subWidget[m_currentCreateId][iii] == removeObject) { + EWOL_DEBUG("Remove sizer sub Element [" << iii << "] ==> destroyed object"); + m_subWidget[m_currentCreateId][iii] = NULL; + m_subWidget[m_currentCreateId].Erase(iii); + m_needFlipFlop = true; + } + } +} + + diff --git a/Sources/libewol/ewol/widget/Layer.h b/Sources/libewol/ewol/widget/Layer.h new file mode 100644 index 00000000..0974cdd7 --- /dev/null +++ b/Sources/libewol/ewol/widget/Layer.h @@ -0,0 +1,103 @@ +/** + ******************************************************************************* + * @file ewol/widget/Layer.h + * @brief ewol layer widget system (Header) + * @author Edouard DUPIN + * @date 11/04/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_LAYER_H__ +#define __EWOL_LAYER_H__ + +#include +#include +#include + +namespace ewol { + class Layer :public ewol::Widget + { + public: + Layer(void); + virtual ~Layer(void); + /** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ + virtual bool CheckObjectType(const char * const objectType); + + /** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ + virtual const char * const GetObjectType(void); + public: + virtual bool CalculateSize(etkFloat_t availlableX, etkFloat_t availlableY); // this generate the current size ... + virtual bool CalculateMinSize(void); //update the min Size ... and the expend parameters for the sizer + virtual void SetMinSise(etkFloat_t x=-1, etkFloat_t y=-1); + virtual void SetExpendX(bool newExpend=false); + virtual bool CanExpentX(void); + virtual void SetExpendY(bool newExpend=false); + virtual bool CanExpentY(void); + void LockExpendContamination(bool lockExpend=false); + private: + bool m_lockExpendContamination; + etk::VectorType m_subWidget[NB_BOUBLE_BUFFER]; + public: + virtual void SubWidgetRemoveAll(void); + virtual void SubWidgetAdd(ewol::Widget* newWidget); + virtual void SubWidgetRemove(ewol::Widget* newWidget); + virtual void SubWidgetUnLink(ewol::Widget* newWidget); + protected: + virtual void OnDraw(void); + public: + virtual void OnRegenerateDisplay(void); + public: + /** + * @brief Get the widget at the specific windows absolute position + * @param[in] pos gAbsolute position of the requested widget knowledge + * @return NULL No widget found + * @return pointer on the widget found + */ + virtual ewol::Widget * GetWidgetAtPos(coord2D_ts pos); + /** + * @brief Event generated to inform a flip-flop has occured on the current widget + * @param --- + * @return --- + */ + virtual void OnFlipFlopEvent(void); + /** + * @brief Inform object that an other object is removed ... + * @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject + * @note : Sub classes must call this class + * @return --- + */ + virtual void OnObjectRemove(ewol::EObject * removeObject); + }; + + extern const char * const TYPE_EOBJECT_WIDGET_LAYER; + +}; + +#define EWOL_CAST_WIDGET_LAYER(curentPointer) EWOL_CAST(ewol::TYPE_EOBJECT_WIDGET_LAYER,ewol::Layer,curentPointer) + +#endif diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 0588987c..d0fbb8fd 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -36,6 +36,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/widget/Joystick.cpp \ ewol/widget/Label.cpp \ ewol/widget/List.cpp \ + ewol/widget/Layer.cpp \ ewol/widget/Menu.cpp \ ewol/widget/PopUp.cpp \ ewol/widget/Scene.cpp \