From 185e85293d7fb7bdbdbd03f5a6d9c7fb9b22e2ad Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 13 Apr 2012 18:45:18 +0200 Subject: [PATCH] Change the policy to get widget at position and add stop/resume in the scene --- Sources/libewol/ewol/base/MainThread.cpp | 4 +-- Sources/libewol/ewol/base/gui.cpp | 9 +++--- Sources/libewol/ewol/base/guiAndroid.cpp | 8 ++--- Sources/libewol/ewol/base/guiX11.cpp | 8 ++--- Sources/libewol/ewol/widget/Layer.cpp | 5 ++- Sources/libewol/ewol/widget/Scene.cpp | 39 +++++++++++++++++------ Sources/libewol/ewol/widget/Scene.h | 35 ++++++++++++++++++-- Sources/libewol/ewol/widget/SizerHori.cpp | 12 +++++-- Sources/libewol/ewol/widget/SizerVert.cpp | 12 +++++-- Sources/libewol/ewol/widget/Spacer.h | 8 +++++ 10 files changed, 107 insertions(+), 33 deletions(-) diff --git a/Sources/libewol/ewol/base/MainThread.cpp b/Sources/libewol/ewol/base/MainThread.cpp index 12d9a4f8..c9297418 100644 --- a/Sources/libewol/ewol/base/MainThread.cpp +++ b/Sources/libewol/ewol/base/MainThread.cpp @@ -196,8 +196,8 @@ static void* BaseAppEntry(void* param) if (0 == ewol::threadMsg::WaitingMessage(androidJniMsg)) { if (countNbEvent > 0) { if(true == ewol::threadMsg::HasDisplayDone(androidJniMsg)) { - - ewol::widgetManager::PeriodicCall(0); + int64_t localTime = GetCurrentTime(); + ewol::widgetManager::PeriodicCall(localTime); } EWOL_NativeRegenerateDisplay(); countNbEvent = 0; diff --git a/Sources/libewol/ewol/base/gui.cpp b/Sources/libewol/ewol/base/gui.cpp index f36c1a68..07925290 100644 --- a/Sources/libewol/ewol/base/gui.cpp +++ b/Sources/libewol/ewol/base/gui.cpp @@ -158,7 +158,8 @@ void guiAbstraction::KeyboardHide(void) static int64_t startTime = -1; static int64_t nbCallTime = 0; static int64_t nbDisplayTime = 0; -#define DISPLAY_PERIODE_MS (1000) +// display every second ... +#define DISPLAY_PERIODE_US (1000000) void EWOL_GenericDraw(bool everyTime) @@ -170,9 +171,10 @@ void EWOL_GenericDraw(bool everyTime) } int64_t currentTime = GetCurrentTime(); //EWOL_DEBUG("current : " << currentTime << "time diff : " << (currentTime - startTime)); - if ( (currentTime - startTime) > DISPLAY_PERIODE_MS) { + if ( (currentTime - startTime) > DISPLAY_PERIODE_US) { display = true; } + // TODO : Remove this ... if (ewol::widgetManager::PeriodicCallHave()) { everyTime = true; } @@ -183,14 +185,13 @@ void EWOL_GenericDraw(bool everyTime) ewol::texture::UpdateContext(); nbDisplayTime++; gui_uniqueWindows->SysDraw(); - //EWOL_WARNING("DRAW..."); } ewol::widgetManager::DoubleBufferUnLock(); // send Message that we just finished a display ... EWOL_ThreadEventHasJustDisplay(); if (true == display) { - EWOL_DEBUG("display property : " << (int32_t)((double)nbDisplayTime/(double)DISPLAY_PERIODE_MS*(double)1000) << "/" << (int32_t)((double)nbCallTime/(double)DISPLAY_PERIODE_MS*(double)1000) << "fps"); + EWOL_DEBUG("display property : " << nbDisplayTime << "/" << nbCallTime << "fps"); nbCallTime = 0; nbDisplayTime = 0; startTime = -1; diff --git a/Sources/libewol/ewol/base/guiAndroid.cpp b/Sources/libewol/ewol/base/guiAndroid.cpp index 86c2159f..830c5051 100644 --- a/Sources/libewol/ewol/base/guiAndroid.cpp +++ b/Sources/libewol/ewol/base/guiAndroid.cpp @@ -41,9 +41,9 @@ #undef __class__ #define __class__ "AndroidJNI" -int32_t separateClickTime = 800; -int32_t offsetMoveClicked = 40; -int32_t offsetMoveClickedDouble = 300; +int32_t separateClickTime = 800000; +int32_t offsetMoveClicked = 40000; +int32_t offsetMoveClickedDouble = 300000; extern etkFloat_t gui_width; extern etkFloat_t gui_height; @@ -54,7 +54,7 @@ int64_t GetCurrentTime(void) struct timeval now; gettimeofday(&now, NULL); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); - return (int64_t)((int64_t)now.tv_sec*(int64_t)1000 + (int64_t)now.tv_usec/(int64_t)1000); + return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec); } diff --git a/Sources/libewol/ewol/base/guiX11.cpp b/Sources/libewol/ewol/base/guiX11.cpp index bdd49520..d4965bcb 100644 --- a/Sources/libewol/ewol/base/guiX11.cpp +++ b/Sources/libewol/ewol/base/guiX11.cpp @@ -55,7 +55,7 @@ int64_t GetCurrentTime(void) now.tv_nsec = 0; } //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); - return (int64_t)((int64_t)now.tv_sec*(int64_t)1000 + (int64_t)now.tv_nsec/(int64_t)1000000); + return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_nsec/(int64_t)1000); } #undef __class__ @@ -119,9 +119,9 @@ extern ewol::Windows* gui_uniqueWindows; extern etkFloat_t gui_width; extern etkFloat_t gui_height; -int32_t separateClickTime = 300; -int32_t offsetMoveClicked = 10; -int32_t offsetMoveClickedDouble = 20; +int32_t separateClickTime = 300000; +int32_t offsetMoveClicked = 10000; +int32_t offsetMoveClickedDouble = 20000; bool inputIsPressed[20]; diff --git a/Sources/libewol/ewol/widget/Layer.cpp b/Sources/libewol/ewol/widget/Layer.cpp index 1fd03a7e..3e5978f7 100644 --- a/Sources/libewol/ewol/widget/Layer.cpp +++ b/Sources/libewol/ewol/widget/Layer.cpp @@ -245,7 +245,10 @@ ewol::Widget * ewol::Layer::GetWidgetAtPos(coord2D_ts pos) 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); + ewol::Widget * tmpWidget = m_subWidget[m_currentCreateId][iii]->GetWidgetAtPos(pos); + if (NULL != tmpWidget) { + return tmpWidget; + } } } } diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp index 8ffe8ce8..9a404255 100644 --- a/Sources/libewol/ewol/widget/Scene.cpp +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -44,8 +44,11 @@ void ewol::WIDGET_SceneInit(void) ewol::Scene::Scene(void) { + m_isRunning = true; SetCanHaveFocus(true); PeriodicCallSet(true); + m_lastCallTime = -1; + m_sceneElement.id = 1; } @@ -160,7 +163,7 @@ int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement) return listAnimatedElements.Size()-1; } - +#define CYCLIC_CALL_PERIODE_US (10000) /** * @brief Periodic call of this widget * @param localTime curent system time @@ -168,14 +171,32 @@ int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement) */ void ewol::Scene::PeriodicCall(int64_t localTime) { - - //EWOL_ERROR("Periodic Call ... " << localTime); - for (int32_t iii=0; iiiProcess(localTime, 20000, m_sceneElement) ) { - delete(m_sceneElement.listAnimatedElements[iii]); - m_sceneElement.listAnimatedElements[iii] = NULL; + // First time : + if (-1 == m_lastCallTime) { + m_lastCallTime = localTime; + } + // check if the processing is availlable + if (false == m_isRunning) { + m_lastCallTime = localTime; + MarkToReedraw(); + return; + } + // cut the processing in small slot of time to prevent error in the real-time Display (Android call us between 30 to 60 fps) + int32_t deltaTime = (int32_t) (localTime - m_lastCallTime); + //EWOL_DEBUG(" currentTime = " << localTime << " last=" << m_lastCallTime << " delta=" << deltaTime); + while (deltaTime >= CYCLIC_CALL_PERIODE_US) { + //EWOL_DEBUG(" process = " << CYCLIC_CALL_PERIODE_US); + m_lastCallTime += CYCLIC_CALL_PERIODE_US; + deltaTime -= CYCLIC_CALL_PERIODE_US; + ScenePeriodicCall(m_lastCallTime, CYCLIC_CALL_PERIODE_US); + //EWOL_ERROR("Periodic Call ... " << localTime); + for (int32_t iii=0; iiiProcess(m_lastCallTime, CYCLIC_CALL_PERIODE_US, m_sceneElement) ) { + delete(m_sceneElement.listAnimatedElements[iii]); + m_sceneElement.listAnimatedElements[iii] = NULL; + } } } } diff --git a/Sources/libewol/ewol/widget/Scene.h b/Sources/libewol/ewol/widget/Scene.h index 20b30496..bfea2b86 100644 --- a/Sources/libewol/ewol/widget/Scene.h +++ b/Sources/libewol/ewol/widget/Scene.h @@ -36,9 +36,10 @@ namespace ewol { class SceneElement { public: etk::VectorType backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType listAnimatedElements; //!< generic element to display... + etk::VectorType animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType listAnimatedElements; //!< generic element to display... + int32_t id; //!< Unique element ID int32_t AddElement(ewol::GameElement* newElement); }; @@ -48,6 +49,8 @@ namespace ewol { // TODO : Set it in private ... protected: SceneElement m_sceneElement; //!< all element neede in the scene + bool m_isRunning; + int64_t m_lastCallTime; public: Scene(void); virtual ~Scene(void); @@ -80,6 +83,32 @@ namespace ewol { * @return --- */ virtual void OnDraw(void); + /** + * @brief Set the scene in pause for a while + * @param --- + * @return --- + */ + void Pause(void) { m_isRunning = false; }; + /** + * @brief Resume the scene activity + * @param --- + * @return --- + */ + void Resume(void) { m_isRunning = true; }; + /** + * @brief Toggle between pause and running + * @param --- + * @return --- + */ + void PauseToggle(void) { if(true==m_isRunning){ m_isRunning=false;}else{m_isRunning=true;} }; + protected: + /** + * @brief Periodic call in the sub element timed + * @param localTime curent system time + * @param deltaTime delta time while the previous call + * @return --- + */ + virtual void ScenePeriodicCall(int64_t localTime, int32_t deltaTime) { }; }; /** diff --git a/Sources/libewol/ewol/widget/SizerHori.cpp b/Sources/libewol/ewol/widget/SizerHori.cpp index 667bc5ac..068180bc 100644 --- a/Sources/libewol/ewol/widget/SizerHori.cpp +++ b/Sources/libewol/ewol/widget/SizerHori.cpp @@ -288,12 +288,18 @@ ewol::Widget * ewol::SizerHori::GetWidgetAtPos(coord2D_ts pos) 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); + ewol::Widget * tmpWidget = m_subWidget[m_currentCreateId][iii]->GetWidgetAtPos(pos); + if (NULL != tmpWidget) { + return tmpWidget; + } + // stop searching + break; } } } - // otherwise the event go to this widget ... - return this; + // TODO : Check if we have a mover, otherwire return NULL; + return NULL; + //return this; } diff --git a/Sources/libewol/ewol/widget/SizerVert.cpp b/Sources/libewol/ewol/widget/SizerVert.cpp index 6f82495b..2cf68e96 100644 --- a/Sources/libewol/ewol/widget/SizerVert.cpp +++ b/Sources/libewol/ewol/widget/SizerVert.cpp @@ -288,12 +288,18 @@ ewol::Widget * ewol::SizerVert::GetWidgetAtPos(coord2D_ts pos) 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); + ewol::Widget * tmpWidget = m_subWidget[m_currentCreateId][iii]->GetWidgetAtPos(pos); + if (NULL != tmpWidget) { + return tmpWidget; + } + // stop searching + break; } } } - // otherwise the event go to this widget ... - return this; + // TODO : Check if we have a mover, otherwire return NULL; + return NULL; + //return this; } diff --git a/Sources/libewol/ewol/widget/Spacer.h b/Sources/libewol/ewol/widget/Spacer.h index a1fa7d62..d53998e9 100644 --- a/Sources/libewol/ewol/widget/Spacer.h +++ b/Sources/libewol/ewol/widget/Spacer.h @@ -52,6 +52,14 @@ namespace ewol { virtual const char * const GetObjectType(void); virtual bool CalculateMinSize(void); void SetSize(etkFloat_t size); + /** + * @brief Get the widget at the specific windows absolute position + * @note the sizer return NULL, because nothing can be done inside nothing + * @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) { return NULL; }; private: etkFloat_t m_size; };