[DEV] change the periodic system (better model)

This commit is contained in:
Edouard DUPIN 2013-06-01 21:43:20 +02:00
parent d3ee207699
commit e12bea33e3
21 changed files with 233 additions and 92 deletions

View File

@ -121,12 +121,13 @@ void ewol::clipBoard::SetSystem(ewol::clipBoard::clipboardListe_te _clipboardID,
mesCopy[_clipboardID] = _data;
}
const etk::UString emptyString("");
const etk::UString& ewol::clipBoard::Get(ewol::clipBoard::clipboardListe_te _clipboardID)
{
if(_clipboardID >= ewol::clipBoard::clipboardCount) {
EWOL_WARNING("request ClickBoard id error");
return "";
return emptyString;
}
// Copy datas ...
return mesCopy[_clipboardID];

View File

@ -172,23 +172,23 @@ int32_t ewol::Shaper::GetNextDisplayedStatus(void)
return m_nextStatusRequested;
}
bool ewol::Shaper::PeriodicCall(int64_t _localTime)
bool ewol::Shaper::PeriodicCall(const ewol::EventTime& _event)
{
// start :
if (m_time == -1) {
m_time = _localTime;
m_time = _event.GetTime();
m_stateOld = m_stateNew;
m_stateNew = m_nextStatusRequested;
m_nextStatusRequested = -1;
m_stateTransition = 0.0;
EWOL_VERBOSE(" ##### START ##### ");
}
int64_t offset = _localTime - m_time;
int64_t offset = _event.GetTime() - m_time;
float timeRelativity = m_config->GetFloat(m_confIdChangeTime)*1000.0;
if (offset > timeRelativity) {
// check if no new state requested:
if (m_nextStatusRequested != -1) {
m_time = _localTime;
m_time =_event.GetTime();
m_stateOld = m_stateNew;
m_stateNew = m_nextStatusRequested;
m_nextStatusRequested = -1;

View File

@ -12,6 +12,7 @@
#include <ewol/debug.h>
#include <ewol/compositing/Compositing.h>
#include <ewol/renderer/ResourceManager.h>
#include <ewol/renderer/EventTime.h>
namespace ewol
{
@ -103,11 +104,11 @@ namespace ewol
int32_t GetNextDisplayedStatus(void);
/**
* @brief Same as the widfget periodic call (this is for change display)
* @param[in] _localTime The current time of the call.
* @param[in] _event The current time of the call.
* @return true The widget must call this fuction periodicly (and redraw itself)
* @return false No need to request the periodic call.
*/
bool PeriodicCall(int64_t _localTime);
bool PeriodicCall(const ewol::EventTime& _event);
/**
* @brief Set the widget origin (needed fot the display)
* @param[in] _newOri : the new widget origin

View File

@ -0,0 +1,22 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/widget/Widget.h>
#undef __class__
#define __class__ "EventTime"
etk::CCout& ewol::operator <<(etk::CCout& _os, const ewol::EventTime& _obj)
{
_os << "{time=" << _obj.GetTime();
_os << " uptime=" << _obj.GetApplUpTime();
_os << " delta=" << _obj.GetDelta();
_os << " deltaCall=" << _obj.GetDeltaCall();
_os << "}";
return _os;
}

View File

@ -0,0 +1,46 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_EVENT_CALL_TIME_H__
#define __EWOL_EVENT_CALL_TIME_H__
#include <etk/types.h>
namespace ewol {
class EventTime {
private:
int64_t m_timeSystem; //!< Current system time (micro-second)
int64_t m_timeUpAppl; //!< Current application wake up-time (micro-second)
float m_timeDelta; //!< Time from the last cycle call of the system (main appl tick) (second)
float m_timeDeltaCall; //!< Time from the last call (when we can manage periodic call with specifying periode) (second)
public:
EventTime(int64_t _timeSystem,
int64_t _timeUpAppl,
float _timeDelta,
float _timeDeltaCall) :
m_timeSystem(_timeSystem),
m_timeUpAppl(_timeUpAppl),
m_timeDelta(_timeDelta),
m_timeDeltaCall(_timeDeltaCall)
{ };
public:
void SetTime(int64_t _timeSystem) { m_timeSystem=_timeSystem; };
inline int64_t GetTime(void) const { return m_timeSystem; };
void SetApplWakeUpTime(int64_t _timeUpAppl) { m_timeUpAppl=_timeUpAppl; };
inline int64_t GetApplWakeUpTime(void) const { return m_timeUpAppl; };
inline int64_t GetApplUpTime(void) const { return m_timeSystem-m_timeUpAppl; };
void SetDelta(float _timeDelta) { m_timeDelta=_timeDelta; };
inline float GetDelta(void) const { return m_timeDelta; };
void SetDeltaCall(float _timeDeltaCall) { m_timeDeltaCall=_timeDeltaCall; };
inline float GetDeltaCall(void) const { return m_timeDeltaCall; };
};
etk::CCout& operator <<(etk::CCout& _os, const ewol::EventTime& _obj);
};
#endif

View File

@ -393,16 +393,16 @@ void widget::Button::CheckStatus(void)
void widget::Button::ChangeStatusIn(int32_t _newStatusId)
{
if (true == m_shaper.ChangeStatusIn(_newStatusId) ) {
PeriodicCallSet(true);
PeriodicCallEnable();
MarkToRedraw();
}
}
void widget::Button::PeriodicCall(int64_t _localTime)
void widget::Button::PeriodicCall(const ewol::EventTime& _event)
{
if (false == m_shaper.PeriodicCall(_localTime) ) {
PeriodicCallSet(false);
if (false == m_shaper.PeriodicCall(_event) ) {
PeriodicCallDisable();
}
MarkToRedraw();
}

View File

@ -157,7 +157,7 @@ namespace widget {
virtual bool LoadXML(TiXmlNode* _node);
virtual ewol::Widget* GetWidgetNamed(const etk::UString& _widgetName);
private: // derived function
virtual void PeriodicCall(int64_t _localTime);
virtual void PeriodicCall(const ewol::EventTime& _event);
};
};

View File

@ -250,17 +250,17 @@ void widget::ButtonColor::OnReceiveMessage(const ewol::EMessage& _msg)
void widget::ButtonColor::ChangeStatusIn(int32_t newStatusId)
{
if (true == m_shaper.ChangeStatusIn(newStatusId) ) {
PeriodicCallSet(true);
PeriodicCallEnable();
MarkToRedraw();
}
}
void widget::ButtonColor::PeriodicCall(int64_t localTime)
void widget::ButtonColor::PeriodicCall(const ewol::EventTime& _event)
{
if (false == m_shaper.PeriodicCall(localTime) ) {
PeriodicCallSet(false);
if (false == m_shaper.PeriodicCall(_event) ) {
PeriodicCallDisable();
}
MarkToRedraw();
}

View File

@ -76,7 +76,7 @@ namespace widget {
*/
void ChangeStatusIn(int32_t newStatusId);
// Derived function
virtual void PeriodicCall(int64_t localTime);
virtual void PeriodicCall(const ewol::EventTime& _event);
};
};

View File

@ -577,16 +577,16 @@ void widget::Entry::OnLostFocus(void)
void widget::Entry::ChangeStatusIn(int32_t _newStatusId)
{
if (true == m_shaper.ChangeStatusIn(_newStatusId) ) {
PeriodicCallSet(true);
PeriodicCallEnable();
MarkToRedraw();
}
}
void widget::Entry::PeriodicCall(int64_t _localTime)
void widget::Entry::PeriodicCall(const ewol::EventTime& _event)
{
if (false == m_shaper.PeriodicCall(_localTime) ) {
PeriodicCallSet(false);
if (false == m_shaper.PeriodicCall(_event) ) {
PeriodicCallDisable();
}
MarkToRedraw();
}

View File

@ -195,7 +195,7 @@ namespace widget {
virtual void OnGetFocus(void);
virtual void OnLostFocus(void);
virtual void ChangeStatusIn(int32_t _newStatusId);
virtual void PeriodicCall(int64_t _localTime);
virtual void PeriodicCall(const ewol::EventTime& _event);
virtual bool OnSetConfig(const ewol::EConfig& _conf);
virtual bool OnGetConfig(const char* _config, etk::UString& _result) const;
};

View File

@ -24,8 +24,7 @@ widget::Mesh::Mesh(const etk::UString& filename) :
m_position(0,0,0),
m_angle(0,0,0),
m_angleSpeed(0,0,0),
m_cameraDistance(10.0),
m_lastTime(-1)
m_cameraDistance(10.0)
{
AddEventId(ewolEventMeshPressed);
m_meshName = filename;
@ -85,17 +84,10 @@ void widget::Mesh::OnRegenerateDisplay(void)
}
}
void widget::Mesh::PeriodicCall(int64_t localTime)
void widget::Mesh::PeriodicCall(const ewol::EventTime& _event)
{
if (m_lastTime==-1) {
m_lastTime = localTime;
return;
}
float deltaTime = (float)(localTime - m_lastTime)/1000000.0f;;
m_angle += m_angleSpeed*deltaTime;
m_angle += m_angleSpeed*_event.GetDeltaCall();
MarkToRedraw();
m_lastTime = localTime;
}
bool widget::Mesh::OnEventInput(const ewol::EventInput& _event)
@ -139,11 +131,10 @@ void widget::Mesh::SetAngle(const vec3& angle)
void widget::Mesh::SetAngleSpeed(const vec3& speed)
{
if (speed!=vec3(0,0,0)) {
PeriodicCallSet(true);
PeriodicCallEnable();
} else {
PeriodicCallSet(false);
PeriodicCallDisable();
}
m_lastTime = -1;
m_angleSpeed = speed;
MarkToRedraw();
}

View File

@ -28,7 +28,6 @@ namespace widget {
vec3 m_angle;
vec3 m_angleSpeed;
float m_cameraDistance;
int64_t m_lastTime;
public:
Mesh(const etk::UString& filename); // automatic considering in the appl Data older
virtual ~Mesh(void);
@ -38,7 +37,7 @@ namespace widget {
virtual void SystemDraw(const ewol::DrawProperty& displayProp);
virtual void OnDraw(void);
virtual bool OnEventInput(const ewol::EventInput& _event);
virtual void PeriodicCall(int64_t localTime);
virtual void PeriodicCall(const ewol::EventTime& _event);
public:
/**
* @brief Set a mesh name file

View File

@ -73,22 +73,18 @@ void widget::PopUp::OnRegenerateDisplay(void)
if (true == NeedRedraw()) {
m_shaper.Clear();
vec2 padding = m_shaper.GetPadding();
vec2 tmpSize(0,0);
if (NULL != m_subWidget) {
vec2 tmpSize = m_subWidget->GetSize();
tmpSize.setMax(m_minSize);
vec2 tmpOrigin = m_origin + (m_size-tmpSize)/2.0f;
tmpOrigin = vec2ClipInt32(tmpOrigin);
m_shaper.SetOrigin(vec2ClipInt32(m_origin));
m_shaper.SetSize(vec2ClipInt32(m_size));
m_shaper.SetInsidePos(vec2ClipInt32(tmpOrigin-padding));
m_shaper.SetInsideSize(vec2ClipInt32(tmpSize + padding*2.0f));
} else {
m_shaper.SetOrigin(vec2ClipInt32(m_origin));
m_shaper.SetSize(vec2ClipInt32(m_size));
m_shaper.SetInsidePos(vec2ClipInt32(m_origin+padding));
m_shaper.SetInsideSize(vec2ClipInt32(m_size-padding*2.0f));
}
tmpSize.setMax(m_minSize);
vec2 tmpOrigin = m_origin + (m_size-tmpSize)/2.0f;
tmpOrigin = vec2ClipInt32(tmpOrigin);
m_shaper.SetOrigin(vec2ClipInt32(m_origin));
m_shaper.SetSize(vec2ClipInt32(m_size));
m_shaper.SetInsidePos(vec2ClipInt32(tmpOrigin-padding));
m_shaper.SetInsideSize(vec2ClipInt32(tmpSize + padding*2.0f));
}
// SUBwIDGET GENERATION ...
if (NULL != m_subWidget) {

View File

@ -38,10 +38,12 @@ namespace widget {
*/
void SetShaperName(const etk::UString& _shaperName);
private:
draw::Color m_colorBackGroung;
draw::Color m_colorBorder;
draw::Color m_colorEmptyArea;
ewol::Drawing m_compositing;
float m_slidingProgress; //!< ratio progression of a sliding
public:
/**
* @brief
*/
protected: // Derived function
virtual void OnDraw(void);
public: // Derived function

View File

@ -52,7 +52,8 @@ void widget::WSlider::UnInit(void)
widget::WSlider::WSlider(void) :
m_windowsSources(0),
m_windowsDestination(0),
m_slidingProgress(0.0f),
m_windowsRequested(-1),
m_slidingProgress(1.0f),
m_transitionSpeed(1.0f),
m_transitionSlide(sladingTransitionHori)
{
@ -125,11 +126,12 @@ void widget::WSlider::SubWidgetSelectSet(int32_t _id)
if (_id<0 || _id >= m_subWidget.Size()) {
EWOL_ERROR("Can not change to a widget not present");
}
m_windowsDestination = _id;
m_slidingProgress = 0;
GenerateEventId(eventStartSlide);
PeriodicCallSet(true);
MarkToRedraw();
if (_id != m_windowsDestination) {
m_windowsRequested = _id;
GenerateEventId(eventStartSlide);
PeriodicCallEnable();
MarkToRedraw();
}
}
void widget::WSlider::SubWidgetSelectSet(ewol::Widget* _widgetPointer)
@ -178,21 +180,35 @@ void widget::WSlider::SetTransitionMode(widget::WSlider::sladingMode_te _mode)
void widget::WSlider::PeriodicCall(int64_t _localTime)
void widget::WSlider::PeriodicCall(const ewol::EventTime& _event)
{
if (m_slidingProgress >= 1.0) {
// end of periodic :
PeriodicCallSet(false);
m_windowsSources = m_windowsDestination;
m_lastPeriodicCall = -1;
GenerateEventId(eventStopSlide);
} else {
if (m_lastPeriodicCall != -1) {
float delta = (double)(_localTime - m_lastPeriodicCall)/1000000.0;
m_slidingProgress += delta/m_transitionSpeed;
m_slidingProgress = etk_avg(0.0f, m_slidingProgress, 1.0f);
if( m_windowsRequested != -1
&& m_windowsRequested != m_windowsSources) {
m_windowsDestination = m_windowsRequested;
m_slidingProgress = 0.0;
} else {
// end of periodic :
PeriodicCallDisable();
GenerateEventId(eventStopSlide);
}
m_lastPeriodicCall = _localTime;
m_windowsRequested = -1;
}
if (m_slidingProgress < 1.0) {
if (m_windowsRequested != -1 && m_slidingProgress<0.5 ) {
// invert sources with destination
int32_t tmppp = m_windowsDestination;
m_windowsDestination = m_windowsSources;
m_windowsSources = tmppp;
m_slidingProgress = 1.0f - m_slidingProgress;
if (m_windowsRequested == m_windowsDestination) {
m_windowsRequested = -1;
}
}
m_slidingProgress += _event.GetDeltaCall()/m_transitionSpeed;
m_slidingProgress = etk_avg(0.0f, m_slidingProgress, 1.0f);
}
CalculateSize(m_size);
MarkToRedraw();

View File

@ -36,8 +36,8 @@ namespace widget {
private:
int32_t m_windowsSources; //!< widget source viewed
int32_t m_windowsDestination; //!< widget destinated viewed
int32_t m_windowsRequested; //!< widget destination requested when change in modification in progress
float m_slidingProgress; //!< ratio progression of a sliding
int64_t m_lastPeriodicCall;
public:
/**
* @brief Select a new subwidget to display
@ -85,7 +85,7 @@ namespace widget {
virtual void CalculateSize(const vec2& _availlable);
virtual void SystemDraw(const ewol::DrawProperty& _displayProp);
virtual void OnRegenerateDisplay(void);
virtual void PeriodicCall(int64_t _localTime);
virtual void PeriodicCall(const ewol::EventTime& _event);
virtual bool OnSetConfig(const ewol::EConfig& _conf);
virtual bool OnGetConfig(const char* _config, etk::UString& _result) const;
};

View File

@ -119,6 +119,8 @@ ewol::Widget::Widget(void) :
m_canFocus(false),
m_limitMouseEvent(3),
m_allowRepeateKeyboardEvent(true),
m_periodicCallDeltaTime(-1),
m_periodicCallTime(0),
m_needRegenerateDisplay(true),
m_grabCursor(false),
m_cursorDisplay(ewol::cursorArrow)
@ -355,13 +357,21 @@ void ewol::Widget::SystemDraw(const DrawProperty& _displayProp)
return;
}
void ewol::Widget::PeriodicCallSet(bool _statusToSet)
void ewol::Widget::PeriodicCallDisable(void)
{
if (true == _statusToSet) {
ewol::widgetManager::PeriodicCallAdd(this);
m_periodicCallDeltaTime=0;
m_periodicCallTime=-1;
ewol::widgetManager::PeriodicCallRm(this);
}
void ewol::Widget::PeriodicCallEnable(float _callInSecond)
{
if (_callInSecond < 0) {
PeriodicCallDisable();
} else {
ewol::widgetManager::PeriodicCallRm(this);
ewol::widgetManager::PeriodicCallAdd(this);
m_periodicCallDeltaTime = _callInSecond*1000000.0;
m_periodicCallTime = ewol::GetTime();
}
}

View File

@ -24,6 +24,7 @@ namespace ewol {
#include <ewol/cursor.h>
#include <ewol/renderer/EventInput.h>
#include <ewol/renderer/EventEntry.h>
#include <ewol/renderer/EventTime.h>
#define ULTIMATE_MAX_SIZE (99999999)
@ -424,19 +425,40 @@ namespace ewol {
// ----------------------------------------------------------------------------------------------------------------
// -- Periodic call Area
// ----------------------------------------------------------------------------------------------------------------
private:
int64_t m_periodicCallDeltaTime; //!< -1 : Disable / 0 : every time / else in US
int64_t m_periodicCallTime; //!< Last call time
protected:
/**
* @brief Request that the current widegt have a periodic call
* @param statusToSet true if the periodic call is needed
* @brief Disable the periodic call.
*/
virtual void PeriodicCallSet(bool statusToSet);
void PeriodicCallDisable(void);
/**
* @brief Disable the periodic call.
* @param[in] _callInSecond periodic call in second (float)
*/
void PeriodicCallEnable(float _callInSecond=0);
public:
/**
* @brief Periodic call of this widget
* @param _localTime curent system time
* @brief {SYSTEM} Get a reference of the periodic call delta time
* @return the perodic time delta call -1 : Disable / 0 : every time / else in US
*/
virtual void PeriodicCall(int64_t _localTime) { };
int64_t SystemGetCallDeltaTime(void) const { return m_periodicCallDeltaTime; };
/**
* @brief {SYSTEM} Get a reference of the periodic call time
* @return Last call from the periodic call
*/
int64_t SystemGetLastCallTime(void) const { return m_periodicCallTime; };
/**
* @brief {SYSTEM} Get a reference of the periodic call time
* @return Last call from the periodic call
*/
void SystemSetLastCallTime(int64_t _time) { m_periodicCallTime=_time; };
/**
* @brief Periodic call of this widget
* @param _event Current time property
*/
virtual void PeriodicCall(const ewol::EventTime& _event) { };
public:
/**
* @brief Get the widget at the specific windows absolute position
@ -456,7 +478,7 @@ namespace ewol {
// event section:
public:
/**
* @brief system event input (only meta widget might overwrite this function).
* @brief {SYSTEM} system event input (only meta widget might overwrite this function).
* @param[in] _event Event properties
* @return true the event is used
* @return false the event is not used
@ -472,7 +494,7 @@ namespace ewol {
virtual bool OnEventInput(const ewol::EventInput& _event) { return false; };
public:
/**
* @brief Entry event (only meta widget might overwrite this function).
* @brief {SYSTEM} Entry event (only meta widget might overwrite this function).
* @param[in] _event Event properties
* @return true if the event has been used
* @return false if the event has not been used
@ -543,7 +565,7 @@ namespace ewol {
virtual bool NeedRedraw(void) { bool tmpData=m_needRegenerateDisplay; m_needRegenerateDisplay=false; return tmpData; };
public:
/**
* @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* @brief {SYSTEM} extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget
* @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget
* @param[in] _displayProp properties of the current display

View File

@ -6,6 +6,7 @@
* @license BSD v3 (see license file)
*/
#include <ewol/ewol.h>
#include <ewol/widget/WidgetManager.h>
#include <ewol/widget/Joystick.h>
#include <ewol/widget/Button.h>
@ -47,11 +48,16 @@ class dataStructCreator
static etk::Vector<dataStructCreator> l_creatorList;
int64_t l_applWakeUpTime = 0; //!< Time of the application initialize
int64_t l_lastPeriodicCallTime = 0; //!< last call time ...
void ewol::widgetManager::Init(void)
{
EWOL_DEBUG("==> Init Widget-Manager");
// set the basic time properties :
l_applWakeUpTime = ewol::GetTime();
l_lastPeriodicCallTime = ewol::GetTime();
// prevent android error ==> can create memory leak but I prefer
m_focusWidgetDefault = NULL;
m_focusWidgetCurrent = NULL;
@ -231,11 +237,39 @@ void ewol::widgetManager::PeriodicCallRm(ewol::Widget * pWidget)
}
}
void ewol::widgetManager::PeriodicCall(int64_t localTime)
void ewol::widgetManager::PeriodicCall(int64_t _localTime)
{
int64_t previousTime = l_lastPeriodicCallTime;
l_lastPeriodicCallTime = _localTime;
if (l_listOfPeriodicWidget.Size() <= 0) {
return;
}
float deltaTime = (float)(_localTime - previousTime)/1000000.0;
EventTime myTime(_localTime, l_applWakeUpTime, deltaTime, deltaTime);
EWOL_VERBOSE("periodic : " << _localTime);
for (int32_t iii=l_listOfPeriodicWidget.Size()-1; iii>=0 ; iii--) {
if (NULL != l_listOfPeriodicWidget[iii]) {
l_listOfPeriodicWidget[iii]->PeriodicCall(localTime);
int64_t deltaTimeCallUser = l_listOfPeriodicWidget[iii]->SystemGetCallDeltaTime();
if (deltaTimeCallUser<=0) {
myTime.SetDeltaCall(deltaTime);
EWOL_VERBOSE("[" << iii << "] periodic : " << myTime);
l_listOfPeriodicWidget[iii]->SystemSetLastCallTime(_localTime);
l_listOfPeriodicWidget[iii]->PeriodicCall(myTime);
} else {
int64_t lastCallTime = l_listOfPeriodicWidget[iii]->SystemGetLastCallTime();
if (lastCallTime == 0) {
lastCallTime = _localTime;
}
float deltaLocalTime = (float)(_localTime-lastCallTime)/1000000.0;;
if (deltaLocalTime>= lastCallTime) {
myTime.SetDeltaCall(deltaLocalTime);
EWOL_VERBOSE("[" << iii << "] periodic : " << myTime);
l_listOfPeriodicWidget[iii]->SystemSetLastCallTime(_localTime);
l_listOfPeriodicWidget[iii]->PeriodicCall(myTime);
}
}
}
}
}

View File

@ -33,6 +33,7 @@ def Create(target):
'ewol/renderer/openGL.cpp',
'ewol/renderer/EventInput.cpp',
'ewol/renderer/EventEntry.cpp',
'ewol/renderer/EventTime.cpp',
'ewol/renderer/Light.cpp',
'ewol/renderer/Material.cpp'])