[DEV] change periodic call ==> remove from widget manager to Object manager and set signal instead of virtual function
This commit is contained in:
parent
5024c51379
commit
9cc1b47a2a
@ -592,7 +592,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
|
||||
}
|
||||
}
|
||||
// call all the widget that neded to do something periodicly
|
||||
m_widgetManager.periodicCall(currentTime);
|
||||
m_objectManager.timeCall(currentTime);
|
||||
// check if the user selected a windows
|
||||
if (nullptr != m_windowsCurrent) {
|
||||
// Redraw all needed elements
|
||||
@ -731,7 +731,7 @@ void ewol::Context::OS_Resume() {
|
||||
lockContext();
|
||||
EWOL_INFO("OS_Resume...");
|
||||
m_previousDisplayTime = ewol::getTime();
|
||||
m_widgetManager.periodicCallResume(m_previousDisplayTime);
|
||||
m_objectManager.timeCallResume(m_previousDisplayTime);
|
||||
if (m_windowsCurrent != nullptr) {
|
||||
m_windowsCurrent->onStateResume();
|
||||
}
|
||||
|
@ -19,3 +19,13 @@ std::ostream& ewol::event::operator <<(std::ostream& _os, const ewol::event::Tim
|
||||
_os << "}";
|
||||
return _os;
|
||||
}
|
||||
|
||||
template<> std::string etk::to_string<ewol::event::Time>(ewol::event::Time const& _obj) {
|
||||
std::string out;
|
||||
out = "{[ewol::event::Time]time=" + etk::to_string(_obj.getTime());
|
||||
out += ";uptime=" + etk::to_string(_obj.getApplUpTime());
|
||||
out += ";delta=" + etk::to_string(_obj.getDelta());
|
||||
out += ";deltaCall=" + etk::to_string(_obj.getDeltaCall());
|
||||
out += "}";
|
||||
return out;
|
||||
}
|
@ -16,8 +16,14 @@
|
||||
#define __class__ "ewol::object::Manager"
|
||||
|
||||
ewol::object::Manager::Manager(ewol::Context& _context) :
|
||||
m_context(_context) {
|
||||
m_context(_context),
|
||||
periodicCall(*this, "periodic", "Call every time system render"),
|
||||
m_applWakeUpTime(0),
|
||||
m_lastPeriodicCallTime(0) {
|
||||
EWOL_DEBUG(" == > init Object-Manager");
|
||||
// set the basic time properties :
|
||||
m_applWakeUpTime = ewol::getTime();
|
||||
m_lastPeriodicCallTime = ewol::getTime();
|
||||
}
|
||||
|
||||
ewol::object::Manager::~Manager() {
|
||||
@ -122,4 +128,23 @@ void ewol::object::Manager::workerRemove(const std::shared_ptr<ewol::Object>& _w
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::object::Manager::timeCall(int64_t _localTime) {
|
||||
int64_t previousTime = m_lastPeriodicCallTime;
|
||||
m_lastPeriodicCallTime = _localTime;
|
||||
if (periodicCall.getNumberConnected() <= 0) {
|
||||
return;
|
||||
}
|
||||
float deltaTime = (float)(_localTime - previousTime)/1000000.0;
|
||||
ewol::event::Time myTime(_localTime, m_applWakeUpTime, deltaTime, deltaTime);
|
||||
periodicCall.emit(myTime);
|
||||
}
|
||||
|
||||
void ewol::object::Manager::timeCallResume(int64_t _localTime) {
|
||||
m_lastPeriodicCallTime = _localTime;
|
||||
}
|
||||
|
||||
bool ewol::object::Manager::timeCallHave() {
|
||||
return periodicCall.getNumberConnected() > 0;
|
||||
}
|
||||
|
@ -11,11 +11,13 @@
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/object/Object.h>
|
||||
#include <ewol/object/Signal.h>
|
||||
#include <ewol/event/Time.h>
|
||||
|
||||
namespace ewol {
|
||||
class Context;
|
||||
namespace object {
|
||||
class Manager {
|
||||
class Manager : public ewol::object::SignalList {
|
||||
private:
|
||||
std::vector<std::weak_ptr<ewol::Object>> m_eObjectList; // all widget allocated == > all time increment ... never removed ...
|
||||
Context& m_context;
|
||||
@ -75,6 +77,28 @@ namespace ewol {
|
||||
* @param[in] _worker Worker to add in the list.
|
||||
*/
|
||||
void workerRemove(const std::shared_ptr<ewol::Object>& _worker);
|
||||
public:
|
||||
ewol::object::Signal<ewol::event::Time> periodicCall;
|
||||
private:
|
||||
int64_t m_applWakeUpTime; //!< Time of the application initialize
|
||||
int64_t m_lastPeriodicCallTime; //!< last call time ...
|
||||
public: // ewol system internal :
|
||||
/**
|
||||
* @brief Call every time we can with the current time
|
||||
* @param[in] _localTime Current system Time.
|
||||
*/
|
||||
void timeCall(int64_t _localTime);
|
||||
/**
|
||||
* @brief If the application is suspended The Ewol Object manager does not know it, just call this to update delta call
|
||||
* @param[in] _localTime Current system Time.
|
||||
*/
|
||||
void timeCallResume(int64_t _localTime);
|
||||
/**
|
||||
* @breif check if the Interface have some user that request a periodic call
|
||||
* @return true, have some periodic event...
|
||||
*/
|
||||
bool timeCallHave();
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -208,6 +208,9 @@ namespace ewol {
|
||||
m_callerListInCallback.clear();
|
||||
}
|
||||
}
|
||||
size_t getNumberConnected() {
|
||||
return m_callerList.size();
|
||||
}
|
||||
};
|
||||
#undef __class__
|
||||
#define __class__ "object::Signal<void>"
|
||||
@ -269,7 +272,7 @@ namespace ewol {
|
||||
}
|
||||
}
|
||||
template<class TYPE, class TYPE2, class TYPE3>
|
||||
void bind2(std::shared_ptr<ewol::Object> _obj, void (TYPE::*_func)(TYPE2, TYPE2), TYPE2 _param1, TYPE3 _param2) {
|
||||
void bind2(std::shared_ptr<ewol::Object> _obj, void (TYPE::*_func)(TYPE2, TYPE3), TYPE2 _param1, TYPE3 _param2) {
|
||||
std::shared_ptr<TYPE> obj2 = std::dynamic_pointer_cast<TYPE>(_obj);
|
||||
if (obj2 == nullptr) {
|
||||
EWOL_ERROR("Can not bind signal ...");
|
||||
@ -386,6 +389,9 @@ namespace ewol {
|
||||
m_callerListInCallback.clear();
|
||||
}
|
||||
}
|
||||
size_t getNumberConnected() {
|
||||
return m_callerList.size();
|
||||
}
|
||||
};
|
||||
#undef __class__
|
||||
#define __class__ nullptr
|
||||
|
@ -92,6 +92,7 @@ void ewol::widget::Button::onRegenerateDisplay() {
|
||||
m_size,
|
||||
vec2ClipInt32(m_selectableAreaPos+vec2(padding.xLeft(),padding.yButtom()) ),
|
||||
vec2ClipInt32(m_selectableAreaSize-vec2(padding.x(),padding.y()) ) );
|
||||
//EWOL_ERROR("pos=" << m_origin << " size=" << m_size);
|
||||
}
|
||||
|
||||
bool ewol::widget::Button::onEventInput(const ewol::event::Input& _event) {
|
||||
|
@ -34,13 +34,8 @@
|
||||
|
||||
ewol::widget::Manager::Manager() :
|
||||
m_havePeriodic(false),
|
||||
m_haveRedraw(true),
|
||||
m_applWakeUpTime(0),
|
||||
m_lastPeriodicCallTime(0) {
|
||||
m_haveRedraw(true) {
|
||||
EWOL_DEBUG(" == > init Widget-Manager");
|
||||
// set the basic time properties :
|
||||
m_applWakeUpTime = ewol::getTime();
|
||||
m_lastPeriodicCallTime = ewol::getTime();
|
||||
|
||||
ewol::widget::Button::createManagerWidget(*this);
|
||||
ewol::widget::ButtonColor::createManagerWidget(*this);
|
||||
@ -68,7 +63,6 @@ ewol::widget::Manager::~Manager() {
|
||||
focusSetDefault(nullptr);
|
||||
focusRelease();
|
||||
|
||||
m_listOfPeriodicWidget.clear();
|
||||
m_creatorList.clear();
|
||||
}
|
||||
|
||||
@ -163,53 +157,7 @@ void ewol::widget::Manager::focusRemoveIfRemove(const std::shared_ptr<ewol::Widg
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::Manager::periodicCallAdd(const std::shared_ptr<ewol::Widget>& _pWidget) {
|
||||
if (_pWidget == nullptr) {
|
||||
return;
|
||||
}
|
||||
m_havePeriodic = true;
|
||||
for (auto &it : m_listOfPeriodicWidget) {
|
||||
if (it.lock() == _pWidget) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto &it : m_listOfPeriodicWidget) {
|
||||
if (it.expired() == true) {
|
||||
it = _pWidget;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_listOfPeriodicWidget.push_back(_pWidget);
|
||||
}
|
||||
|
||||
void ewol::widget::Manager::periodicCallRm(const std::shared_ptr<ewol::Widget>& _pWidget) {
|
||||
for (auto &it : m_listOfPeriodicWidget) {
|
||||
if (it.lock() == _pWidget) {
|
||||
it.reset();
|
||||
}
|
||||
}
|
||||
periodicCallUpdateCount();
|
||||
}
|
||||
|
||||
void ewol::widget::Manager::periodicCallUpdateCount() {
|
||||
int32_t nbElement = 0;
|
||||
for (auto &it : m_listOfPeriodicWidget) {
|
||||
if (it.expired() == false) {
|
||||
nbElement++;
|
||||
}
|
||||
}
|
||||
if (0 == nbElement) {
|
||||
m_havePeriodic = false;
|
||||
} else {
|
||||
m_havePeriodic = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ewol::widget::Manager::periodicCallResume(int64_t _localTime) {
|
||||
m_lastPeriodicCallTime = _localTime;
|
||||
}
|
||||
|
||||
/*
|
||||
void ewol::widget::Manager::periodicCall(int64_t _localTime) {
|
||||
int64_t previousTime = m_lastPeriodicCallTime;
|
||||
m_lastPeriodicCallTime = _localTime;
|
||||
@ -246,10 +194,8 @@ void ewol::widget::Manager::periodicCall(int64_t _localTime) {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool ewol::widget::Manager::periodicCallHave() {
|
||||
return m_havePeriodic;
|
||||
}
|
||||
|
||||
void ewol::widget::Manager::markDrawingIsNeeded() {
|
||||
m_haveRedraw = true;
|
||||
|
@ -24,12 +24,9 @@ namespace ewol {
|
||||
// For the focus Management
|
||||
std::weak_ptr<ewol::Widget> m_focusWidgetDefault;
|
||||
std::weak_ptr<ewol::Widget> m_focusWidgetCurrent;
|
||||
std::vector<std::weak_ptr<ewol::Widget>> m_listOfPeriodicWidget;
|
||||
bool m_havePeriodic;
|
||||
bool m_haveRedraw;
|
||||
etk::Hash<creator_tf> m_creatorList;
|
||||
int64_t m_applWakeUpTime; //!< Time of the application initialize
|
||||
int64_t m_lastPeriodicCallTime; //!< last call time ...
|
||||
public:
|
||||
Manager();
|
||||
virtual ~Manager();
|
||||
@ -40,12 +37,6 @@ namespace ewol {
|
||||
std::shared_ptr<ewol::Widget> focusGet();
|
||||
void focusRemoveIfRemove(const std::shared_ptr<ewol::Widget>& _newWidget);
|
||||
|
||||
void periodicCallAdd(const std::shared_ptr<ewol::Widget>& _pWidget);
|
||||
void periodicCallRm(const std::shared_ptr<ewol::Widget>& _pWidget);
|
||||
void periodicCall(int64_t _localTime);
|
||||
void periodicCallResume(int64_t _localTime);
|
||||
bool periodicCallHave();
|
||||
|
||||
void markDrawingIsNeeded();
|
||||
bool isDrawingNeeded();
|
||||
|
||||
|
@ -103,8 +103,6 @@ ewol::Widget::Widget() :
|
||||
m_canFocus(*this, "focus", false, "enable the widget to have the focus capacity"), // TODO : je pense que c'est une erreur, c'st surement un event to get the cocus ...
|
||||
m_limitMouseEvent(3),
|
||||
m_allowRepeateKeyboardEvent(true),
|
||||
m_periodicCallDeltaTime(-1),
|
||||
m_periodicCallTime(0),
|
||||
signalShortcut(*this, "shortcut"),
|
||||
m_needRegenerateDisplay(true),
|
||||
m_grabCursor(false),
|
||||
@ -310,19 +308,11 @@ void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) {
|
||||
}
|
||||
|
||||
void ewol::Widget::periodicCallDisable() {
|
||||
m_periodicCallDeltaTime=0;
|
||||
m_periodicCallTime=-1;
|
||||
getWidgetManager().periodicCallRm(std::dynamic_pointer_cast<ewol::Widget>(shared_from_this()));
|
||||
getObjectManager().periodicCall.release(shared_from_this());
|
||||
}
|
||||
|
||||
void ewol::Widget::periodicCallEnable(float _callInSecond) {
|
||||
if (_callInSecond < 0) {
|
||||
periodicCallDisable();
|
||||
} else {
|
||||
getWidgetManager().periodicCallAdd(std::dynamic_pointer_cast<ewol::Widget>(shared_from_this()));
|
||||
m_periodicCallDeltaTime = _callInSecond*1000000.0;
|
||||
m_periodicCallTime = ewol::getTime();
|
||||
}
|
||||
void ewol::Widget::periodicCallEnable() {
|
||||
getObjectManager().periodicCall.bind(shared_from_this(), &ewol::Widget::periodicCall);
|
||||
}
|
||||
|
||||
void ewol::Widget::markToRedraw() {
|
||||
|
@ -472,41 +472,17 @@ 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:
|
||||
// TODO : Remove this API ==> deprecated since 28/10/2014
|
||||
/**
|
||||
* @brief disable the periodic call.
|
||||
*/
|
||||
void periodicCallDisable();
|
||||
/**
|
||||
* @brief disable the periodic call.
|
||||
* @param[in] _callInSecond periodic call in second (float)
|
||||
*/
|
||||
void periodicCallEnable(float _callInSecond=0);
|
||||
void periodicCallEnable();
|
||||
public:
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
int64_t systemGetCallDeltaTime() const {
|
||||
return m_periodicCallDeltaTime;
|
||||
};
|
||||
/**
|
||||
* @brief {SYSTEM} get a reference of the periodic call time
|
||||
* @return Last call from the periodic call
|
||||
*/
|
||||
int64_t systemGetLastCallTime() 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user