[DEV] add doc and better code

This commit is contained in:
Edouard DUPIN 2016-03-15 22:01:19 +01:00
parent 7bddada9b8
commit 34357ed6eb
7 changed files with 160 additions and 85 deletions

View File

@ -46,8 +46,9 @@ bool ewol::context::InputManager::localEventInput(enum gale::key::type _type,
int32_t _IdInput,
enum gale::key::status _status,
vec2 _pos) {
if (nullptr != _destWidget) {
if (_type == gale::key::type_mouse || _type == gale::key::type_finger) {
if (_destWidget != nullptr) {
if ( _type == gale::key::type_mouse
|| _type == gale::key::type_finger) {
// create the system Event :
ewol::event::InputSystem tmpEventSystem(_type, _status, _IdInput, _pos, _destWidget, 0, m_specialKey); // TODO : set the real ID ...
// generate the event :
@ -62,7 +63,7 @@ bool ewol::context::InputManager::localEventInput(enum gale::key::type _type,
void ewol::context::InputManager::abortElement(InputPoperty *_eventTable,
int32_t _idInput,
enum gale::key::type _type) {
if (nullptr == _eventTable) {
if (_eventTable == nullptr) {
return;
}
if (_eventTable[_idInput].isUsed == true) {
@ -76,7 +77,7 @@ void ewol::context::InputManager::abortElement(InputPoperty *_eventTable,
void ewol::context::InputManager::cleanElement(InputPoperty *_eventTable,
int32_t _idInput) {
if (nullptr == _eventTable) {
if (_eventTable == nullptr) {
return;
}
//EWOL_INFO("CleanElement[" << idInput << "] = @" << (int64_t)eventTable);
@ -215,7 +216,8 @@ void ewol::context::InputManager::motion(enum gale::key::type _type,
}
ewol::widget::WindowsShared tmpWindows = m_context.getWindows();
// special case for the mouse event 0 that represent the hover event of the system :
if (_type == gale::key::type_mouse && _pointerID == 0) {
if ( _type == gale::key::type_mouse
&& _pointerID == 0) {
// this event is all time on the good widget ... and manage the enter and leave ...
// NOTE : the "layer widget" force us to get the widget at the specific position all the time :
ewol::WidgetShared tmpWidget;
@ -223,12 +225,12 @@ void ewol::context::InputManager::motion(enum gale::key::type _type,
// grab all events ...
tmpWidget = m_grabWidget.lock();
} else {
if (nullptr != tmpWindows) {
if (tmpWindows != nullptr) {
tmpWidget = tmpWindows->getWidgetAtPos(_pos);
}
}
if( tmpWidget != eventTable[_pointerID].curentWidgetEvent.lock()
|| ( true == eventTable[_pointerID].isInside
|| ( eventTable[_pointerID].isInside == true
&& ( eventTable[_pointerID].origin.x() > _pos.x()
|| eventTable[_pointerID].origin.y() > _pos.y()
|| (eventTable[_pointerID].origin.x() + eventTable[_pointerID].size.x()) < _pos.x()
@ -273,8 +275,8 @@ void ewol::context::InputManager::motion(enum gale::key::type _type,
eventTable[_pointerID].destinationInputId,
gale::key::status_move,
_pos);
} else if (true == eventTable[_pointerID].isUsed) {
if (true == eventTable[_pointerID].isInside) {
} else if (eventTable[_pointerID].isUsed == true) {
if (eventTable[_pointerID].isInside == true) {
if( eventTable[_pointerID].origin.x() > _pos.x()
|| eventTable[_pointerID].origin.y() > _pos.y()
|| (eventTable[_pointerID].origin.x() + eventTable[_pointerID].size.x()) < _pos.x()
@ -322,9 +324,8 @@ void ewol::context::InputManager::motion(enum gale::key::type _type,
void ewol::context::InputManager::state(enum gale::key::type _type,
int _pointerID,
bool _isDown,
vec2 _pos)
{
if (MAX_MANAGE_INPUT <= _pointerID) {
vec2 _pos) {
if (_pointerID >= MAX_MANAGE_INPUT) {
// reject pointer == > out of IDs...
return;
}
@ -351,11 +352,11 @@ void ewol::context::InputManager::state(enum gale::key::type _type,
int64_t currentTime = ewol::getTime();
ewol::widget::WindowsShared tmpWindows = m_context.getWindows();
if (true == _isDown) {
if (_isDown == true) {
EVENT_DEBUG("GUI : Input ID=" << _pointerID
<< " == >" << eventTable[_pointerID].destinationInputId
<< " [DOWN] " << _pos);
if(true == eventTable[_pointerID].isUsed) {
if(eventTable[_pointerID].isUsed == true) {
// we have an event previously ... check delay between click and offset position
if (currentTime - eventTable[_pointerID].lastTimeEvent > localLimit.sepatateTime) {
cleanElement(eventTable, _pointerID);
@ -364,7 +365,7 @@ void ewol::context::InputManager::state(enum gale::key::type _type,
cleanElement(eventTable, _pointerID);
}
}
if(true == eventTable[_pointerID].isUsed) {
if(eventTable[_pointerID].isUsed == true) {
// save start time
eventTable[_pointerID].lastTimeEvent = currentTime;
// generate DOWN Event
@ -388,12 +389,18 @@ void ewol::context::InputManager::state(enum gale::key::type _type,
eventTable[_pointerID].isInside = true;
ewol::WidgetShared tmpWidget = m_grabWidget.lock();
// get destination widget :
if(nullptr != tmpWindows) {
if(tmpWindows != nullptr) {
if ( tmpWidget != nullptr
&& _type == gale::key::type_mouse) {
eventTable[_pointerID].curentWidgetEvent = tmpWidget;
} else {
eventTable[_pointerID].curentWidgetEvent = tmpWindows->getWidgetAtPos(_pos);
tmpWidget = tmpWindows->getWidgetAtPos(_pos);
eventTable[_pointerID].curentWidgetEvent = tmpWidget;
if (tmpWidget != nullptr) {
EVENT_DEBUG("Get widget at pos=" << _pos << " type: " << tmpWidget->getObjectType());
} else {
EVENT_DEBUG("Get widget at pos=" << _pos << " NO WIDGET");
}
}
} else {
eventTable[_pointerID].curentWidgetEvent.reset();
@ -421,15 +428,22 @@ void ewol::context::InputManager::state(enum gale::key::type _type,
EVENT_DEBUG("GUI : Input ID=" << _pointerID
<< " == >" << eventTable[_pointerID].destinationInputId
<< " [UP] " << _pos);
if(false == eventTable[_pointerID].isUsed) {
ewol::WidgetShared tmpWidget = eventTable[_pointerID].curentWidgetEvent.lock();
if(eventTable[_pointerID].isUsed == false) {
// bad case ... ???
EWOL_DEBUG("Up event without previous down ... ");
// Mark it un-used :
eventTable[_pointerID].isUsed = false;
// revove the widget ...
eventTable[_pointerID].curentWidgetEvent.reset();
} else if (tmpWidget == nullptr) {
// The widget has been removed:
EVENT_DEBUG(" Object Removed ...");
// Mark it un-used :
eventTable[_pointerID].isUsed = false;
// revove the widget ...
eventTable[_pointerID].curentWidgetEvent.reset();
} else {
ewol::WidgetShared tmpWidget = eventTable[_pointerID].curentWidgetEvent.lock();
// generate UP Event
EVENT_DEBUG("GUI : Input ID=" << _pointerID
<< " == >" << eventTable[_pointerID].destinationInputId

View File

@ -21,21 +21,34 @@ void ewol::Object::autoDestroy() {
EWOL_WARNING("try to auto destroy inside a constructor");
return;
}
EWOL_VERBOSE("Destroy object : [" << getId() << "] type:" << getObjectType());
EWOL_VERBOSE("Destroy object: [" << getId() << "] type:" << getObjectType());
ewol::ObjectShared parent = m_parent.lock();
// TODO : set a signal to do this ...
if (parent != nullptr) {
EWOL_VERBOSE("Destroy object: Call parrent");
parent->requestDestroyFromChild(shared_from_this());
}
//if no parent ==> noting to do ...
m_destroy = true;
}
bool ewol::Object::objectHasBeenCorectlyInit() {
return m_objectHasBeenInit;
}
void ewol::Object::requestDestroyFromChild(const ewol::ObjectShared& _child) {
EWOL_INFO("requestDestroyFromChild(...) is called when an object reference as a parent have a child that request quto-destroy ...");
EWOL_CRITICAL("Call From Child with no effects ==> must implement : requestDestroyFromChild(...)");
}
void ewol::Object::destroy() {
autoDestroy();
}
bool ewol::Object::isDestroyed() const {
return m_destroy;
}
void ewol::Object::setParent(const ewol::ObjectShared& _newParent) {
// TODO : Implement change of parent ...
m_parent = _newParent;

View File

@ -138,9 +138,7 @@ namespace ewol {
* @brief Destructor
*/
virtual ~Object();
bool objectHasBeenCorectlyInit() {
return m_objectHasBeenInit;
}
bool objectHasBeenCorectlyInit();
protected:
ewol::ObjectWeak m_parent; //!< Reference on the current parrent.
bool m_destroy; //!< Flag to know if the object is requesting has destroy.
@ -148,28 +146,25 @@ namespace ewol {
/**
* @brief Auto-destroy the object
*/
void autoDestroy();
virtual void autoDestroy();
public:
/**
* @brief Destroy the current object
*/
virtual void destroy() {
autoDestroy();
}
virtual void destroy();
/**
* @brief Check if the current objetc his destroy (in removing)
* @return true The object is removed
* @return false The object is not removed
*/
bool isDestroyed() const {
return m_destroy;
}
public:
bool isDestroyed() const;
protected:
/**
* @brief Called by a whild that want to remove pointer of itself from the current list of his parrent
* @param[in] _child Object of the child that want to remove itself
*/
virtual void requestDestroyFromChild(const ewol::ObjectShared& _child);
public:
/**
* @brief Set the Object has new parrent.
* @param[in] _newParent Object that requesting the parenting

View File

@ -35,7 +35,6 @@
#define __class__ "ewol::widget::Manager"
ewol::widget::Manager::Manager() :
m_havePeriodic(false),
m_haveRedraw(true) {
EWOL_DEBUG(" == > init Widget-Manager");
@ -137,30 +136,16 @@ void ewol::widget::Manager::focusRelease() {
}
m_focusWidgetCurrent = m_focusWidgetDefault;
focusWidgetCurrent = m_focusWidgetCurrent.lock();
if (nullptr != focusWidgetCurrent) {
if (focusWidgetCurrent != nullptr) {
EWOL_DEBUG("Set focus on WidgetID=" << focusWidgetCurrent->getId() );
focusWidgetCurrent->setFocus();
}
}
ewol::WidgetShared ewol::widget::Manager::focusGet() {
return m_focusWidgetCurrent.lock();
}
void ewol::widget::Manager::focusRemoveIfRemove(const ewol::WidgetShared& _newWidget) {
ewol::WidgetShared focusWidgetDefault = m_focusWidgetDefault.lock();
ewol::WidgetShared focusWidgetCurrent = m_focusWidgetCurrent.lock();
if (focusWidgetCurrent == _newWidget) {
EWOL_WARNING("Release focus when remove widget");
focusRelease();
}
if (focusWidgetDefault == _newWidget) {
EWOL_WARNING("Release default focus when remove widget");
focusSetDefault(nullptr);
}
}
void ewol::widget::Manager::setCallbackonRedrawNeeded(const std::function<void()>& _func) {
m_funcRedrawNeeded = _func;
}
@ -183,27 +168,28 @@ bool ewol::widget::Manager::isDrawingNeeded() {
// element that generate the list of elements
void ewol::widget::Manager::addWidgetCreator(const std::string& _name,
ewol::widget::Manager::creator_tf _pointer) {
if (nullptr == _pointer) {
ewol::widget::Manager::widgetCreatorFunction _pointer) {
if (_pointer == nullptr) {
return;
}
//Keep name in lower case :
std::string nameLower = etk::tolower(_name);
if (true == m_creatorList.exist(nameLower)) {
auto it = m_creatorList.find(nameLower);
if (it != m_creatorList.end()) {
EWOL_WARNING("Replace Creator of a specify widget : " << nameLower);
m_creatorList[nameLower] = _pointer;
it->second = _pointer;
return;
}
EWOL_INFO("Add Creator of a specify widget : " << nameLower);
m_creatorList.add(nameLower, _pointer);
m_creatorList.insert(make_pair(nameLower, _pointer));
}
ewol::WidgetShared ewol::widget::Manager::create(const std::string& _name) {
std::string nameLower = etk::tolower(_name);
if (m_creatorList.exist(nameLower) == true) {
ewol::widget::Manager::creator_tf pointerFunction = m_creatorList[nameLower];
if (pointerFunction != nullptr) {
return pointerFunction();
auto it = m_creatorList.find(nameLower);
if (it != m_creatorList.end()) {
if (it->second != nullptr) {
return it->second();
}
}
EWOL_WARNING("try to create an UnExistant widget : " << nameLower);
@ -212,14 +198,20 @@ ewol::WidgetShared ewol::widget::Manager::create(const std::string& _name) {
bool ewol::widget::Manager::exist(const std::string& _name) {
std::string nameLower = etk::tolower(_name);
return m_creatorList.exist(nameLower);
auto it = m_creatorList.find(nameLower);
if (it != m_creatorList.end()) {
return false;
}
return true;
}
std::string ewol::widget::Manager::list() {
std::string tmpVal;
for (int32_t iii=0; iii<m_creatorList.size() ; iii++) {
tmpVal += m_creatorList.getKey(iii);
tmpVal += ",";
for (auto &it : m_creatorList) {
if (tmpVal.size() != 0) {
tmpVal += ",";
}
tmpVal += it.first;
}
return tmpVal;
}

View File

@ -10,44 +10,98 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <vector>
#include <etk/Hash.h>
#include <unordered_map>
#include <ewol/widget/Widget.h>
namespace ewol {
namespace widget {
class Manager {
public:
using creator_tf = std::function<ewol::WidgetShared()>;
private:
// For the focus Management
ewol::WidgetWeak m_focusWidgetDefault;
ewol::WidgetWeak m_focusWidgetCurrent;
bool m_havePeriodic;
bool m_haveRedraw;
etk::Hash<creator_tf> m_creatorList;
public:
Manager();
virtual ~Manager();
void focusKeep(const ewol::WidgetShared& _newWidget); // set the focus at the specific widget
void focusSetDefault(const ewol::WidgetShared& _newWidget); // select the default focus getter
void focusRelease(); // release focus from the current widget to the default
// ---------------------------------------------
// -- Focus area
// ---------------------------------------------
private:
ewol::WidgetWeak m_focusWidgetDefault; //!< default focus when no current focus is set
ewol::WidgetWeak m_focusWidgetCurrent; //!< Currect focus selected
public:
/**
* @brief Request a focus on a specify widget.
* @param[in] _newWidget Widget that might get the focus.
*/
void focusKeep(const ewol::WidgetShared& _newWidget);
/**
* @brief Set the default focus when none selected.
* @param[in] _newWidget Widget that might get the focus (when nothing else).
*/
void focusSetDefault(const ewol::WidgetShared& _newWidget);
/**
* @brief Release the current focus (back on default if possible).
*/
void focusRelease();
/**
* @brief Get the current Focused widget.
* @return The pointer on the current focused element.
*/
ewol::WidgetShared focusGet();
void focusRemoveIfRemove(const ewol::WidgetShared& _newWidget);
// ---------------------------------------------
// -- Factory area
// ---------------------------------------------
public:
using widgetCreatorFunction = std::function<ewol::WidgetShared()>; //!< funtion factory basic definition
private:
std::unordered_map<std::string, widgetCreatorFunction> m_creatorList; //!< List of factory of a widget
public:
/**
* @brief add a factory of a specific widget.
* @param[in] _name Name of the widget that is associated of the factory.
* @param[in] _factory Function pointer to create the widget
*/
void addWidgetCreator(const std::string& _name, widgetCreatorFunction _factory);
/**
* @brief Create a widget with his name.
* @param[in] _name Name of the widget to create.
* @return The widget created (nullptr if it does not exist).
*/
ewol::WidgetShared create(const std::string& _name);
/**
* @brief Check if an Widget exist
* @param[in] _name Name of the widget to check.
* @return true The Widget exist.
* @return false The Widget Does NOT exist.
*/
bool exist(const std::string& _name);
/**
* @brief Get the list of all Widget that can be created.
* @return Separate with ',' string list.
*/
std::string list();
// ---------------------------------------------
// -- Something change area (TODO: maybe set it in the windows)
// ---------------------------------------------
private:
bool m_haveRedraw; //!< something request a redraw
private:
std::function<void()> m_funcRedrawNeeded;
public:
/**
* @brief Mark the display to redraw
*/
void markDrawingIsNeeded();
/**
* @brief Check if a redraw has been requested (set the local value back at false)
* @return true if something to be redraw
*/
bool isDrawingNeeded();
void setCallbackonRedrawNeeded(const std::function<void()>& _func);
// element that generate the list of elements
void addWidgetCreator(const std::string& _name, creator_tf _pointer);
ewol::WidgetShared create(const std::string& _name);
bool exist(const std::string& _name);
std::string list();
private:
void periodicCallUpdateCount();
/**
* @brief Set a callback when we need redraw the display (need by MacOs)
* @param[in] _func function to call
*/
void setCallbackonRedrawNeeded(const std::function<void()>& _func);
};
};
};

View File

@ -96,13 +96,16 @@ void ewol::Widget::onChangeSize() {
}
bool ewol::Widget::setFocus() {
EWOL_VERBOSE("set focus (start) *propertyCanFocus=" << *propertyCanFocus << " m_hasFocus=" << m_hasFocus);
if (*propertyCanFocus == true) {
if (m_hasFocus == false) {
m_hasFocus = true;
onGetFocus();
}
EWOL_VERBOSE("set focus (stop) ret true");
return true;
}
EWOL_VERBOSE("set focus (stop) ret false");
return false;
}

View File

@ -61,13 +61,14 @@ void ewol::widget::Windows::onChangeSize() {
}
ewol::WidgetShared ewol::widget::Windows::getWidgetAtPos(const vec2& _pos) {
EWOL_VERBOSE("Get widget at pos : " << _pos);
// calculate relative position
vec2 relativePos = relativePosition(_pos);
// event go directly on the pop-up
if (0 < m_popUpWidgetList.size()) {
if (m_popUpWidgetList.size() != 0) {
return m_popUpWidgetList.back()->getWidgetAtPos(_pos);
// otherwise in the normal windows
} else if (nullptr != m_subWidget) {
} else if (m_subWidget != nullptr) {
return m_subWidget->getWidgetAtPos(_pos);
}
// otherwise the event go to this widget ...
@ -239,9 +240,11 @@ void ewol::widget::Windows::createPopUpMessage(enum popUpMessageType _type, cons
}
void ewol::widget::Windows::requestDestroyFromChild(const ewol::ObjectShared& _child) {
EWOL_VERBOSE("A child has been removed");
auto it = m_popUpWidgetList.begin();
while (it != m_popUpWidgetList.end()) {
if (*it == _child) {
EWOL_VERBOSE(" Find it ...");
if (*it == nullptr) {
m_popUpWidgetList.erase(it);
it = m_popUpWidgetList.begin();
@ -257,6 +260,7 @@ void ewol::widget::Windows::requestDestroyFromChild(const ewol::ObjectShared& _c
++it;
}
if (m_subWidget == _child) {
EWOL_VERBOSE(" Find it ... 2");
if (m_subWidget == nullptr) {
return;
}