diff --git a/build b/build index dd46d2d7..b1cbee3b 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit dd46d2d7b4100fd518cabe4de2468868d22a1adb +Subproject commit b1cbee3b4b65bacad8abbbbdc99cdf9e472b76e4 diff --git a/doc/001_bases.bb b/doc/001_bases.bb index 40c76b6f..8a6d9f62 100644 --- a/doc/001_bases.bb +++ b/doc/001_bases.bb @@ -5,7 +5,7 @@ __________________________________________________ === Overview:=== EWOL is an OpenGL library for creating graphical user interfaces. It works on many UNIX-like platforms, Windows, and OS X and some mobile platforms Android, iOs(soon). -EWOL is released under the BSD 3 clauses license (BSD v3), which allows for very flexible licensing of client applications. +EWOL is released under the APACHE-2 license, which allows for very flexible licensing of client applications. EWOL has a C++ architecture that allows for maximum flexibility. The main idea of EWOL is to create a complete abstraction of the platforms. @@ -21,7 +21,7 @@ To use ewol you need to know only C++ language. It could be usefull to know: One of the important point to know in this framwork is some of absurd things came from the multiple architecture type. I will Explain the main points: -:** IOs does [b]NOT[/b] simply support the shared object sub lib, this force ewol to be BSD, and depend on some sub-library with small license restriction. +:** IOs does [b]NOT[/b] simply support the shared object sub lib, this force ewol to be APACHE-2, and depend on some sub-library with small license restriction. :** Android have a JAVA main, then the application main will not be used with this platform :** Android event (keyboard, mouse, touch-screen and ...) will arrive in asynchron mode ==> need to be resynchronyse in one thread :** Only one graphyc framework is availlable on all platform. This is OpenGL diff --git a/doc/faq.bb b/doc/faq.bb new file mode 100644 index 00000000..4a760745 --- /dev/null +++ b/doc/faq.bb @@ -0,0 +1,36 @@ +=?= FAQ =?= + +== What is ewol licence == + +This is really simple : APACHE-2 : + +Copyright ewol Edouard DUPIN + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + [[http://www.apache.org/licenses/LICENSE-2.0]] + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + + + +== Why we use "DECLARE_FACTORY" Macro ? == + +For some reason!!! But everything might be clear: +:** In ewol we masively use std::shared_ptr (I have create my own but it is not "standard" (I like when we use genecic system)). +:** The main class : [class[ewol::Object]] herited from [i]std::enable_shared_from_this[/i] to permit to access at his own [i]std::shared_ptr[/i]. +:** Acces At his own [i]std::shared_ptr[/i] is not allowed in the class contructor/destructor. +:** Many time for meta-widget we need to propagate our [i]std::shared_ptr[/i] in child. + +Then for all these reasons, I have create a simple MACRO that create a static template funtion that create the object and just after +creation call the init(...) function to permit to create a complex widget or others with some writing convinience. + + + diff --git a/doc/index.bb b/doc/index.bb index eb617652..fd1d8095 100644 --- a/doc/index.bb +++ b/doc/index.bb @@ -7,10 +7,10 @@ EWOL, or Edn Widget OpenGl Layer, is a multi-platform library for creating graph ===Where can I use it?=== Everywhere! EWOL is cross-platform devolopped to support bases OS: : ** Linux (X11) (mouse) -: ** Windows (mouse) +: ** Windows (mouse) (not compile anymore ==> TODO) : ** MacOs (mouse) : ** Android (mouse + touch) -: ** IOs (in-progress) +: ** IOs (touch) ===What languages are supported?=== EWOL is written in C++ and is not (for now) supported for other languages. @@ -23,7 +23,7 @@ That allow you to use it for every program you want, including those developing [note]The static support is important for some platform like IOs, and this limit the external library use at some license like : :** BSD* :** MIT -:** APPACHE +:** APPACHE-2 :** PNG :** ZLIB This exclude the classical extern library with licence: @@ -31,33 +31,37 @@ This exclude the classical extern library with licence: :** GPL [/note] -==== License (BSD) ==== -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: +==== License (APACHE 2) ==== +Copyright ewol Edouard DUPIN -:** Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -:** Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -:** The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + [[http://www.apache.org/licenses/LICENSE-2.0]] + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. ==== Sub library: ==== ===== License: ===== -:** [b][lib[etk | e-tk]][/b] : BSD 3 clauses +:** [b][lib[etk | e-tk]][/b] : APACHE-2 ::** [b][lib[linearmath | Linear-Math]][/b] : z-lib (subset of bullet lib) -::** [b][lib[earchive | e-Archive]][/b] : BSD 3 clauses +::** [b][lib[earchive | e-Archive]][/b] : APACHE-2 :::** [b][lib[z | Z lib]][/b] : z-lib -:** [b][lib[egami | e-gami]][/b] : BSD 3 clauses -::** [b][lib[esvg | e-svg]][/b] : BSD 3 clauses +:** [b][lib[egami | e-gami]][/b] : APACHE-2 +::** [b][lib[esvg | e-svg]][/b] : APACHE-2 :::** [b][lib[agg | AGG]][/b] : BSD-like ::** [b][lib[png | libPNG]][/b] : PNG :** [b][lib[portaudio | portaudio]][/b] : MIT :** [b][lib[ogg | ogg]][/b] : BSD-like :** [b][lib[freetype | Free-Type]][/b] : BSD-like -:** [b][lib[ejson | e-json]][/b] : BSD 3 clauses -:** [b][lib[exml | e-xml]][/b] : BSD 3 clauses +:** [b][lib[ejson | e-json]][/b] : APACHE-2 +:** [b][lib[exml | e-xml]][/b] : APACHE-2 ==== Description : ==== diff --git a/doc/tutorial/000_Build.bb b/doc/tutorial/000_Build.bb index e81c1b1a..1024dac0 100644 --- a/doc/tutorial/000_Build.bb +++ b/doc/tutorial/000_Build.bb @@ -48,7 +48,7 @@ Compile software in debug for the curent platform : You can specify the platform with: [code style=shell] - ./ewol/build/lutin.py -mdebug -tAndroid + ./ewol/build/lutin.py -tAndroid -mdebug [/code] It coud be usefull to disable the package generation in local debug : diff --git a/doc/tutorial/001_HelloWord.bb b/doc/tutorial/001_HelloWord.bb index 5d0795c2..e48d38b9 100644 --- a/doc/tutorial/001_HelloWord.bb +++ b/doc/tutorial/001_HelloWord.bb @@ -1,6 +1,3 @@ -=?= Tutorial 1: Hello Word =?= -__________________________________________________ -[left][tutorial[000_Build | Previous: Download & Build]][/left] [right][tutorial[010_ObjectModel | Next: Object model]][/right] === Objectif === :** Understand basis of ewol @@ -12,12 +9,15 @@ __________________________________________________ A generic Ewol application is manage by creating an [class[ewol::context::Application]] that is the basis of your application. -Due to the fact the ewol librairy is a multi-platform framework, then you need to think all you will do with only one -application and only one windows displayable at the same time. +Due to the fact the ewol library is a multi-platform framework, you will have many contraint like: +:** One application at the same time +:** One Windows displayable at the time +:** Not a big CPU ... Then we will create the application: [code style=c++] +namespace appl { class MainApplication : public ewol::context::Application { public: bool init(ewol::Context& _context, size_t _initId) { @@ -32,42 +32,47 @@ Then we will create the application: APPL_INFO("==> Un-Init APPL (END)"); } }; +}; [/code] The input [class[ewol::Context]] is the main system context. [note] -It is important to know that the system can call your application in parallele, the basic exemple of this is the Wallpaper on Android. +It is important to know that the system can create your application multiple times, the basic exemple of this is the Wallpaper on Android. What is done: -** When selected, it create an intance and when it is apply Android create a new instance and remove the previous one... +** When we select the wallpaper it create a new application (to show an example) +** When applying your choice, it create the real one an remove the previous one. [/note] In all program we need to have a main() -To be portable on Android, that have a java main the User might the Wrapper call the generic main() (please do not add other things in this main). +To be portable on Android, the "main" in the java might call your main through the Android wrapper. + +To simplify compabilities between platform it is recommanded to not add other things in the application main: [code style=c++] int main(int argc, const char *argv[]) { // only one things to do : - return ewol::run(new MainApplication(), _argc, _argv); + return ewol::run(new appl::MainApplication(), _argc, _argv); } [/code] ==== Some configuration are needed ==== -In your application you can use many configuration, -none of them are set in static for compilation and interface reason, -then you will to set it on dynamic. +In your application you can use many configuration, it is really better to set all your configuration dynamic. +With this basic condiction will simplify the interface of the library if you would have many different application +(never forger the compilator garbage collector is really very efficient). -Select fonts: + +[b]Select fonts:[/b] This can be a problem when you design an application for some other operating system (OS), They do not have the same default font. -And we select an order to search the font names and the system basic size. +We select an order to search the font names and the system basic size. [code style=c++] // Use External font depending on the system (for specific application, it is better to provide fonts) _context.getFontDefault().setUseExternal(true); @@ -80,7 +85,7 @@ And we select an order to search the font names and the system basic size. Create the main Windows: -For this point we will create a class that herited form the basic windows class: +For this point we will create a class that herited form the basic [class[ewol::wiget::Windows]] class: [b]Windows.h[/b] [code style=c++] @@ -91,14 +96,19 @@ For this point we will create a class that herited form the basic windows class: namespace appl { class Windows : public ewol::widget::Windows { - public: + protected: Windows(void); + init() + public: + DECLARE_FACTORY(Windows); virtual ~Windows(void) {}; }; }; #endif [/code] +See [tutorial[010_ObjectModel | Next: Object model]] to understand why this structure is so complex. + [b]Windows.cpp[/b] [code style=c++] #include @@ -110,8 +120,13 @@ For this point we will create a class that herited form the basic windows class: #define __class__ "Windows" appl::Windows::Windows(void) { + // To simplify log (if you have a better solution, I am aware) + addObjectType("appl::Windows"); + } + appl::Windows::init(void) { + ewol::widget::Windows::init(); setTitle("example 001_HelloWord"); - ewol::object::Shared tmpWidget = new ewol::widget::Label(); + std::shared_ptr tmpWidget = ewol::widget::Label::create(); if (NULL == tmpWidget) { APPL_ERROR("Can not allocate widget ==> display might be in error"); } else { @@ -122,6 +137,11 @@ For this point we will create a class that herited form the basic windows class: } [/code] +The init function can not be virtual due to his polymorphic status, then we need to call parrent init +[code style=c++] + ewol::widget::Windows::init(); +[/code] + The fist basic property to set is the Title: [code style=c++] setTitle("example 001_HelloWord"); @@ -130,14 +150,17 @@ The fist basic property to set is the Title: After we simple create a [class[widget::Label]] in the main windows constructor. And we set the widget property (label). [code style=c++] - ewol::object::Shared tmpWidget = ewol::object::makeShared(new ewol::widget::Label()); - tmpWidget->setLabel("Hello Word"); + std::shared_ptr tmpWidget = ewol::widget::Label::create(); + tmpWidget->setLabel("Hello Word"); tmpWidget->setExpand(bvec2(true,true)); [/code] -We can se in this example that the label have some other property like the font color. +We can see in this example that the label have some other property like the font color. + The label can have decorated text based on the html generic writing but it is composed with really simple set of balise. -I will take a really long time to create a real html parser, the the availlable property is: +I will take a really long time to create a real html parser. + +The availlable property is: :** [b]
[/b] : New line :** [b] ... [/b] : change the font color. :** [b]
...
[/b] : center the text. @@ -156,6 +179,7 @@ The last step is to add the widget on the windows : [code style=c++] setSubWidget(tmpWidget); [/code] +When we call this function, it use the shard_from_this() function that create an exception if we are in constructor ==== Configure Ewol to have display the windows ==== @@ -164,10 +188,12 @@ At this point we have created the basic windows. But the system does not know it. Then we create windows and set it in the main contect main (in the MainApplication::init()): [code style=c++] - ewol::object::Shared basicWindows = ewol::object::makeShared(new appl::Windows()); + std::shared_ptr basicWindows = appl::Windows::create()); // create the specific windows _context.setWindows(basicWindows); [/code] +Her we call the create function that is created by the DECLARE_FACTORY macro + Then the init fuction is : [code style=c++] @@ -177,7 +203,7 @@ bool MainApplication::init(ewol::Context& _context, size_t _initId) { _context.getFontDefault().setUseExternal(true); _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); - ewol::Windows* basicWindows = new appl::Windows(); + std::shared_ptr basicWindows = appl::Windows::create(); // create the specific windows _context.setWindows(basicWindows); APPL_INFO("==> Init APPL (END)"); @@ -245,9 +271,9 @@ I do not explain again the lutin file, for next tutorial, show example sources . === Build your application === -go to your workspace folder and launch +Go to your workspace folder and launch [code style=shell] - ./ewol/build/lutin.py -C -mdebug -p 001_HelloWord + ./ewol/build/lutin.py -C -mdebug 001_HelloWord [/code] Your program example will build correctly... @@ -259,13 +285,14 @@ Launch it : The [b]-l6[/b] is used to specify the Log level of the application display (this log is synchronous) + The output compile in a separate folder depending on the compilation tool (gcc or clang) + It create a complete final tree in the ./out/Linux/debug/staging/gcc/001_HelloWord/ folder -The final folder contain the package generated -tree of the output +The final folder contain the package generated: :** out ::** MacOs ::** Android diff --git a/doc/tutorial/010_ObjectModel.bb b/doc/tutorial/010_ObjectModel.bb index e32997ee..b0725b76 100644 --- a/doc/tutorial/010_ObjectModel.bb +++ b/doc/tutorial/010_ObjectModel.bb @@ -1,22 +1,20 @@ -=?= Tutorial 2: Object Model =?= -__________________________________________________ -[left][tutorial[001_HelloWord | Previous: Hello Word]][/left] [right][tutorial[011_ObjectConfig | Next: Object config]][/right] === Objectif === :** Understand ewol basic [class[ewol::Object]] :** Use [class[ewol::Object]] correctly -== Basis of the Object == +== Basis of the ewol::Object == An object in Ewol is a simple class : [class[ewol::Object]] This object is the basis of all element in the ewol system. -This is designed to manage basis element of complexe structure: +This is designed to manage many common things: :** Unique ID :** Name -:** Configuration (decriptive naming of parameters) -:** Event generation and receving +:** Parameters +:** Signal generation :** Xml configuration -:** Delayed removing +:** Removing +:** Perodic calling [note] Please do not compare with the gObject basic class... @@ -25,130 +23,86 @@ Please do not compare with the gObject basic class... == Create an Object: == -In theory you can use a simple new on an object, but you need to remove the refcounting of this one by yoursef ... really awfull. +Creating an object is really simple: -It is really better to use the ewol::object::Shared<> declaration to auto manage it. (same as std::shared_ptr) [code style=c++] - ewol::object::Shared tmpObject = ewol::object::makeShared(new widget::Label()); - if (tmpObject == NULL) { - APPL_ERROR("An error occured"); - return; - } + std::shared_ptr tmpButon = ewol::Button::create(); + APPL_INFO("We just create a button widget with unique ID=" << tmpButon->getId() << " name='" << tmpButon->getName() << "'"); [/code] -The object register itself on the object manager, now it will have a specific Id and no name +Note that all object created are std::shared_ptr. -Force the set of the name : + +Set the name of the object: [code style=c++] - tmpObject->setName("my widget name"); - APPL_INFO("We just create an Object with ID=" << tmpObject->getId() << " name='" << tmpObject->getName() << "'"); + tmpButon->setName("my widget name"); + APPL_INFO("We just create an Object with ID=" << tmpButon->getId() << " name='" << tmpButon->getName() << "'"); [/code] == Remove an Object: == -This is important to note that many element can have a reference on the Object. - -Then we need to use the fuction: -[b]removeObject()[/b] to remove the Object, This will notify avery object in the system that this -specific object has been removed. - - -Then to remove an object call: +Simply use the function: [code style=c++] - tmpObject->removeObject(); + tmpButon->destroy(); [/code] -On every object we can have an herited function: [b]virtual void onObjectRemove(const ewol::object::Shared& _removeObject);[/b] +This function request his parrent to remove the std::shared_ptr it keep on it. +And when all std::shared_ptr is removed the object will be really removed. - -We need to implement this fuction to be notify an object is removed: -[code style=c++] - void namespeceName::ClassName::onObjectRemove(const ewol::object::Shared& _removeObject) { - // Never forget to call upper Object (otherwise many object will keep theire reference) - upperClass::onObjectRemove(_removeObject); - if (_removeObject == m_object) { - m_object.reset(); - markToRedraw(); // set only for graphical object ... - } - } -[/code] +At his point we can think an object is allive all the time someone keep a reference on it, then when you are not a parrent of the object, do not keep a std::shared_ptr but a std::weak_ptr. [note] -If you have well follow the idea, you will never declare an object in local, just use shared pointer on them. +If some Object is not removed when you close the application, the system inform you with displaying all object already alive. [/note] -[note] -For some case it could be interesting to see the [class[ewol::object::Owner]] class that provide an automatic auto remove of object. - -See [class[ewol::widget::Container]] for an example. -[/note] - - -=== Particularity === - -An object can remove itself, just use the function: -[code style=c++] - autoDestroy(); -[/code] - == Retrieve an Object: == In Ewol this is possible to get a object with his name. -This is really simple. -=== In an Object === - -Call a simple function define in the Object: +=== Find a global Object (ouside an Object) === [code style=c++] - #include - - ... - - ewol::object::Shared tmpObject = getObjectManager().get("name of the object"); - if (tmpObject == NULL) { - APPL_ERROR("The Object does not exist"); - } -[/code] - -=== Not in an Object === - -In this case, we need to get the context manager and after the object manager: - -[code style=c++] - #include #include - ... - - ewol::object::Shared tmpObject = ewol::getContext().getObjectManager().get("name of the object"); + std::shared_ptr tmpObject = ewol::getContext().getEObjectManager().getObjectNamed("obj Name"); if (tmpObject == NULL) { APPL_ERROR("The Object does not exist"); } [/code] -=== Casting your object === +=== Find a global Object (inside an Object) === + +[code style=c++] + std::shared_ptr tmpObject = getObjectNamed("obj Name"); + if (tmpObject == NULL) { + APPL_ERROR("The Object does not exist"); + } +[/code] + +=== Find a sub-object === + +[code style=c++] + std::shared_ptr tmpObject = getSubObjectNamed("obj Name"); + if (tmpObject == NULL) { + APPL_ERROR("The Object does not exist"); + } +[/code] + +=== retriving your object type === It could be really interesting to retrive your own instance: [code style=c++] - ewol::object::Shared tmpObject ...; + std::shared_ptr tmpObject ...; - ewol::object::Shared myObject = ewol::dynamic_pointer_cast(tmpObject); + std::shared_ptr myObject = std::dynamic_pointer_cast(tmpObject); [/code] == conclusion == -If you follow these rules, you will not have memory leek and no segmentation fault on the ewol system. - -[note] -To be sure that the name is unique, just add the current creator object Id in the name. - -See [class[ewol::widget::FileChooser]] class for an example. -[/note] - +TODO ... diff --git a/doc/tutorial/011_ObjectConfig.bb b/doc/tutorial/011_ObjectConfig.bb index 280c0a8d..0855fb92 100644 --- a/doc/tutorial/011_ObjectConfig.bb +++ b/doc/tutorial/011_ObjectConfig.bb @@ -1,153 +1,98 @@ -=?= Tutorial 3: Object Config =?= -__________________________________________________ -[left][tutorial[010_ObjectModel | Previous: Object model]][/left] [right][tutorial[012_ObjectMessage | Next: Object message]][/right] === Objectif === :** Understand ewol::Object configuration parameter :** Create an configurable object -== Use of Configuration == +== Configuration using == -Configuration are parameters to set some property on an object, -this is a really generic use in many system, -this is the reason why we implement one. +All [class[ewol::Object]] have a configuration of parameters (the object name is a parameter), Then we need to set get and use xml to update parameters. +=== Set a Parameter === -This is a generic interface to set and get parameter, -when you did not really know it, -but it generate many convertion to string search and many other things... +[note] + Using getter and setter is really better, and faster. +[/note] -If you know the object just interact with it with his own accessors (faster ond conpilation check). +==== With a string configuration ==== - -=== Set config === - -When you have the pointer on the object: [code style=c++] - if (tmpObject->setConfig("name", "new name of object") == false) { - APPL_ERROR("Can not set object property"); + if (tmpObject->parameterSet("name", "new name of object") == false) { + APPL_ERROR("Can not set object parameter"); } [/code] -A second methode is to request the name with his direct config name: -[code style=c++] - // to be sure that the name exist: - if (tmpObject->setConfig(ewol::Object::configName, "new name of object") == false) { - APPL_ERROR("Can not set object property"); - } -[/code] -The only aventage here is to have an automatic update on the name of the parameter. +==== whith the object name ==== -It is possible to configure an object whitout knowing his name: [code style=c++] - // in an ewol::Object only ... - if (setConfigNamed("object name", "ewol::Object::configName, "new name of object") == false) { - APPL_ERROR("Can not set object property"); + if (parameterSetOnWidgetNamed("objectName", "value", "16.2") == false) { + APPL_ERROR("Can not set object parameter"); } [/code] +=== Get Parameter === -=== Get config === - -Direct get the configuration: [code style=c++] - std::string val = tmpObject->getConfig("name"); + std::string val = tmpObject->parameterGet("name"); APPL_INFO("Get Object property : name='" << val << "'"); [/code] -Get with his direct definition name: -[code style=c++] - std::string val = tmpObject->getConfig(ewol::Object::configName); - APPL_INFO("Get Object property : " << ewol::Object::configName << "'" << val << "'"); -[/code] - - == Implement configuration == -=== Declare config === - -In the header file: [code style=c++] #include namespace appl { class MyObj : public ewol::Object { - public: - // Config list of properties - static const char* const configValue; - public: + protected: //! @brief Constructor - MyObj(void); + MyObj(void) : + m_value(*this, "value", false, "Value of the parameter (descrition string)") { + // nothing to do.. + } + void init() { + ewol::Object::init(); + } + public: //! @brief Destructor - virtual ~MyObj(void); + virtual ~MyObj(void) { } + DECLARE_FACTORY(MyObj); private: - bool m_value; //!< Internal Object value + ewol::object::Param m_value; //!< Internal Object value public: //! @brief Setter void setValue(bool _val) { - m_value = _val; + m_value.set(_val); } //! @brief Getter - bool getValue(void) const { - return m_value; + bool getValue() const { + return m_value.get(); } public: // herited function: - bool onSetConfig(const ewol::object::Config& _conf); + void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer) { + if (_paramPointer == m_value) { + APPL_DEBUG("The internal value has change, new value is : '" << m_value.get() << "'"); + } + } } } [/code] -[note] -By convention declare config started with "configXXXXXX" -[/note] - -In the source file: +In the contructor we need to add: [code style=c++] -// Declare the configuration Name: -const char* const appl::MyObj::configValue = "value"; - -appl::MyObj::MyObj(void) { - // declare the configuration on this object: - registerConfig(configValue, "bool", NULL, "object configuration description"); - // Note : This API is not compleately define ... -} -appl::MyObj::~MyObj(void) { - // nothing to do ... -} +m_value(*this, "value", false, "Value of the parameter (descrition string)") [/code] -Now an extern Object can register configure these parameter, otherwise, they will be rejected!!! +:** [b]'*this':[/b] Reference the main class to call it chen value change. +:** [b]"value":[/b] Is the name of the parameter. +:** [b]false:[/b] The default value. +:** [b]"....."[/b] Description of the parameter (optionnal). -=== Get and Set config === +The function [b]onParameterChangeValue[/b] is called only the parameter change (no historic has been registered) -You can see in these implementation that we not compare the string but just the pointer. -The ewol::Object convert the string in the correct pointer to be faster in many case. +The last point is that the m_value.get() is an inline fuction then it take no more CPU cycle to access the value than normal variable. -==== Set configuration ==== +Some other parameter are availlable : +:** ewol::object::Param Basic parameter. +:** ewol::object::ParamRange For numeric parameter that range value are check befor setting new value. +:** ewol::object::ParamList For List of parameter values. -[code style=c++] -bool appl::MyObj::onSetConfig(const ewol::object::Config& _conf) { - APPL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} set config : " << _conf); - if (_conf.getConfig() == configValue) { - setValue(std::stob(_conf.getData())); - return true; - } - return false; -} -[/code] - -==== Get configuration ==== - -[code style=c++] -bool appl::MyObj::onGetConfig(const char* _config, std::string& _result) const { - if (_config == configValue) { - _result = std::to_string(getValue()); - return true; - } - return false; -} -[/code] - -== Conclusion == - -Now you can choice the methode you want in your application to implement your basic configuration feature. diff --git a/doc/tutorial/012_ObjectMessage.bb b/doc/tutorial/012_ObjectMessage.bb index 9f62f5d6..bf405568 100644 --- a/doc/tutorial/012_ObjectMessage.bb +++ b/doc/tutorial/012_ObjectMessage.bb @@ -1,6 +1,3 @@ -=?= Tutorial 4: Object Message =?= -__________________________________________________ -[left][tutorial[011_ObjectConfig | Previous: Object config]][/left] [right][tutorial[020_FileAccess | Next: File Access]][/right] === Objectif === :** Understand ewol::Object Messaging system @@ -8,123 +5,164 @@ __________________________________________________ == Message system == -The message system is a simple message sending between Object. -This is composed with a pointer (const char* const) that represent the mesage ID (pointer, then unique) -and a value (std::string) +Message system is based on generic std::funtion and std::bind methode: -The message are broadcast or multicast on object watcher. +It permit to an object to generate some [b]'signals'[/b]. -== Receive Message from other object == +All signal are synchronous -=== Register on message === -We will se an example on the widget : [class[ewol::widget::Button]] +== Receive signals from other object == -By default the messageID is the event generated, But to overwrite this message Id just create a new one: +[todo] +Link with the signal name +[/todo] + +Register on the 'up' and 'value' signal of a button: + +Button header : [code style=c++] -// on the global on the file or in private class member: -static const char* const g_backMessage = "local-event-button-pressed"; -static const char* const g_backMessageValue = "local-event-button-value"; -static const char* const g_backMessageDataOverWritte = "local-event-button-data"; + ... + public: + ewol::object::Signal signalDown; + ewol::object::Signal signalUp; + ... + ewol::object::Signal signalValue; + ... [/code] - -Register with his name: -[code style=c++] -registerOnEvent(this, "pressed", g_backMessage); -[/code] - -Register with his direct name: -[code style=c++] -registerOnEvent(this, ewol::widget::Button::eventValue, g_backMessageValue); -[/code] - -It is possible to overwrote the data send by the Object : -[code style=c++] -registerOnEvent(this, ewol::widget::Button::eventPressed, g_backMessageDataOverWritte, "Data we want to receive"); -[/code] - - -=== Receive message === - -To receive message from other widget, just implement this function: +=== simple signal connection: === [code style=c++] - -void appl::ObjectName::onReceiveMessage(const ewol::object::Message& _msg) { - APPL_INFO("Receive Event : " << _msg); - if (_msg.getMessage() == g_backMessage) { - // process here - return; - } - if (_msg.getMessage() == g_backMessageValue) { - APPL_INFO("message value: '" << _msg.getData() << "'"); - return; - } - if (_msg.getMessage() == g_backMessageDataOverWritte) { - APPL_INFO("Overwrite message data: '" << _msg.getData() << "'"); - return; +#include +#include +namespace appl { + class MyObj : public ewol::Object { + private: + std::shared_ptr m_button; + protected: + //! @brief Constructor + MyObj(void) { + // nothing to do.. + } + void init() { + ewol::Object::init(); + m_button = ewol::widget::Button::Create(); + if (m_button == nullptr) { + APPL_ERROR("Can not create button..."); + return; + } + // We connect signals here : + m_button->signalUp.bind(shared_from_this(), &appl::MyObj::onCallbackUp); + m_button->signalValue.bind(shared_from_this(), &appl::MyObj::onCallbackValue); + } + public: + //! @brief Destructor + virtual ~MyObj(void) { } + DECLARE_FACTORY(MyObj); + private: + void onCallbackUp() { + APPL_INFO("button pressed: UP); + } + void onCallbackValue(const bool& _value) { + APPL_INFO("button value: " << _value); + } } } [/code] -== Declare Extern Message == +=== Advenced signal connection: === -=== Declare Message === +Here we will see how to connect an advance function on a signal -In the header file: [code style=c++] #include +#include +namespace appl { + class MyObj : public ewol::Object { + private: + std::shared_ptr m_button; + protected: + //! @brief Constructor + MyObj(void) { + // nothing to do.. + } + void init() { + ewol::Object::init(); + m_button = ewol::widget::Button::Create(); + if (m_button == nullptr) { + APPL_ERROR("Can not create button..."); + return; + } + // We connect signals here : + m_button->signalUp.register(shared_from_this(), std::bind(&appl::MyObj::onCallbackUp, this, std::string("tmpVariableToSend"))); + m_button->signalValue.register(shared_from_this(), std::bind(&appl::MyObj::onCallbackValue, this)); + } + public: + //! @brief Destructor + virtual ~MyObj(void) { } + DECLARE_FACTORY(MyObj); + private: + void onCallbackUp(const std::string& _value) { + APPL_INFO("button pressed: UP inputMessage: " << _value); + } + void onCallbackValue() { + APPL_INFO("button value: " << _value); + } + } +} +[/code] + +=== Connect to a signal with a named widget === + +TODO: documentation : +:** subBind(_type, _name, _event, _obj, _func) +:** globalBind(_type, _name, _event, _obj, _func) +:** externSubBind(_object, _type, _name, _event, _obj, _func) + + +== Declare Signal == + +=== source === + +[code style=c++] +#include +#include namespace appl { class MyObj : public ewol::Object { public: - // Event list of properties - static const char* const eventValue; - public: + ewol::object::Signal signalEmpty; + ewol::object::Signal signalBoolean; + ewol::object::Signal signalString; + protected: //! @brief Constructor - MyObj(void); + MyObj(void) : + signalEmpty(*this, "empty"), + signalBoolean(*this, "boolean"), + signalString(*this, "string") { + // nothing to do.. + } + void init() { + ewol::Object::init(); + } + public: //! @brief Destructor - virtual ~MyObj(void); + virtual ~MyObj(void) { } + DECLARE_FACTORY(MyObj); + private: + void process() { + signalEmpty.emit(); + signalBoolean.emit(false); + signalString.emit("plop... plop"); + } } } [/code] -[note] -By convention declare events started with "eventXXXXXX" -[/note] - -In the source file: -[code style=c++] -// Declare the configuration Name: -const char* const appl::MyObj::eventValue = "value"; - -appl::MyObj::MyObj(void) { - // declare Event generated on this object: - addEventId(eventValue); -} -appl::MyObj::~MyObj(void) { - // nothing to do ... -} -[/code] -Now an extern Object can register event on this object, otherwise, they will be rejected!!! - - -=== Generate Message === - -Now we have register object message, We need to have generated it, This is really simple : - -[code style=c++] - // with no data: - generateEventId(eventValue); - // With a custom data: - generateEventId(eventValue, "My sring custom data ..."); -[/code] - - == Conclusion == -You will now able to generate event between objects... +You will now able to reise signals between objects... diff --git a/doc/tutorial/020_FileAccess.bb b/doc/tutorial/020_FileAccess.bb index c8becf9d..6034022c 100644 --- a/doc/tutorial/020_FileAccess.bb +++ b/doc/tutorial/020_FileAccess.bb @@ -1,6 +1,3 @@ -=?= Tutorial 5: File Access =?= -__________________________________________________ -[left][tutorial[012_ObjectMessage | Previous: Object message]][/left] [right][tutorial[021_Resources | Next: Resources management]][/right] === Objectif === :** Understand why we wrap interface on file system diff --git a/doc/tutorial/021_Resources.bb b/doc/tutorial/021_Resources.bb index e69de29b..a386656f 100644 --- a/doc/tutorial/021_Resources.bb +++ b/doc/tutorial/021_Resources.bb @@ -0,0 +1,114 @@ + +=== Objectifs === +:** Understand What is a resource +:** Use resources + +=== What is a resource: === + +A resource is an usique element that can be used by manny element like: +:** An image (special resolution) +:** A configuration file +:** An application manager (special case) +:** A sound file +:** ... + +A resource have an other objective, form some platform, the graphic interface can be stopped, then we need to reload texture in the graphic inteface... +Then the texture is an other graphic interface. + +=== Get a resource: === + +For this example we will load a configuration file: +[code style=c++] +#include +#include +namespace appl { + class MyObj : public ewol::Object { + private: + std::shared_ptr m_config; + int32_t m_configValId; + protected: + //! @brief Constructor + MyObj(void) : + m_configValId(-1) { + // nothing to do.. + } + void init() { + ewol::Object::init(); + m_config = ewol::resource::ConfigFile::create("DATA:ExapleConfig.json"); + m_configValId = m_config->request("exampleConfigName"); + } + public: + //! @brief Destructor + virtual ~MyObj(void) { } + DECLARE_FACTORY(MyObj); + public: + void process() { + double value = m_config->getNumber(m_configValId); + APPL_DEBUG("example value : " << value); + } + } +} +[/code] + + +=== Create a new resource: === + +A resource is a generic [class[ewol::Resource]] that hrited form a generic [class[ewol::Object]], simply change the FACTORY macro in : +:** DECLARE_RESOURCE_FACTORY(className) To declare a resource with no name (unique for every creation) +:** DECLARE_RESOURCE_NAMED_FACTORY(className) To create a resource that have a specific name. When created, we will find the previous resource with the specify name in the fanctory. +:** DECLARE_RESOURCE_SINGLE_FACTORY(className,uniqueName) This is to have a unique resource for all the application (name is specify in the Macro) + +we have now some specific interface to compleate (if needed): + +==== The Resource Level ==== + +The resources can be reloaded, then we need to reaload in the good order (level [0 .. 5]) + +The resources are loaded fron 0 to 5. + +Then for basic resource : + +[code style=c++] +#include +namespace appl { + class MyResource : public ewol::Resource { + protected: + //! @brief Constructor + MyResource() : + m_configValId(-1) { + m_resourceLevel = 4; + addObjectType("ewol::MyResource"); + } + void init(const std::& _name) { + ewol::Resource::init(_name); + } + public: + //! @brief Destructor + virtual ~MyResource(void) { } + DECLARE_RESOURCE_NAMED_FACTORY(MyResource); + } +} +[/code] + +Now we need to implement somme functions: + +To send data on the hardware (openGL): +[code style=c++] + void updateContext(); +[/code] + +To remove data from the the hardware (openGL): +[code style=c++] + void removeContext(); +[/code] + +When loose hardware (juste update internal state): +[code style=c++] + void removeContextToLate(); +[/code] + +When user request to reload all resources (can be usefull when using file type : THEME:GUI:xxx) +[code style=c++] + void reload(); +[/code] + diff --git a/doc/tutorial/030_ConplexeXmlGui.bb b/doc/tutorial/030_ConplexeXmlGui.bb index e69de29b..9aeafd40 100644 --- a/doc/tutorial/030_ConplexeXmlGui.bb +++ b/doc/tutorial/030_ConplexeXmlGui.bb @@ -0,0 +1,24 @@ + +=== Objectif === +:** What is a Widget +:** Simply create a complex Gui + +=== What is a Widget === + +A widget is a simple entity of a graphical Object. It herited of every [class[ewol::Object]] class with many graphical interface to draw a complex gui. + +We can consider some widget: +:** Windows: Main gui interface to display the unique "windows". +:** Simple widget: all widget that display somthing. +:** Meta widget: Widget composed with some wodget. + +=== Simple load of a widget: === + + + +=== Create an interface with a XML form: === + + +=== Create in C++ the interface: === + + diff --git a/doc/tutorial/050_CreateCustomWidget.bb b/doc/tutorial/050_CreateCustomWidget.bb index 0477cd9e..c6dbd4eb 100644 --- a/doc/tutorial/050_CreateCustomWidget.bb +++ b/doc/tutorial/050_CreateCustomWidget.bb @@ -1,4 +1,3 @@ -=?=Create a custum widget=?= To create a custum widget, this is as simple as complex. The first things to do is to choice a methode to display you widget: diff --git a/doc/tutorial/051_AddWidgetCustumInXML.bb b/doc/tutorial/051_AddWidgetCustumInXML.bb index 33094160..12370b6f 100644 --- a/doc/tutorial/051_AddWidgetCustumInXML.bb +++ b/doc/tutorial/051_AddWidgetCustumInXML.bb @@ -1,7 +1,4 @@ - - - == Declare object in XML == Object can be declared in some XML, (like gui decription), then we need to declare the Object in the system recognition. diff --git a/sources/ewol/Dimension.cpp b/sources/ewol/Dimension.cpp index 52ccc211..b993327c 100644 --- a/sources/ewol/Dimension.cpp +++ b/sources/ewol/Dimension.cpp @@ -299,19 +299,18 @@ std::ostream& ewol::operator <<(std::ostream& _os, const ewol::Dimension& _obj) return _os; } - -template<> std::string etk::to_string(const ewol::Dimension& _obj) { - return _obj; -} -template<> std::u32string etk::to_u32string(const ewol::Dimension& _obj) { - return etk::to_u32string(etk::to_string(_obj)); -} - - -template<> bool etk::from_string(ewol::Dimension& _variableRet, const std::string& _value) { - _variableRet = ewol::Dimension(_value); - return true; -} -template<> bool etk::from_string(ewol::Dimension& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); -} +namespace etk { + template<> std::string to_string(const ewol::Dimension& _obj) { + return _obj; + } + template<> std::u32string to_u32string(const ewol::Dimension& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + template<> bool from_string(ewol::Dimension& _variableRet, const std::string& _value) { + _variableRet = ewol::Dimension(_value); + return true; + } + template<> bool from_string(ewol::Dimension& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } +}; diff --git a/sources/ewol/compositing/Shaper.cpp b/sources/ewol/compositing/Shaper.cpp index 0856d86a..781f5c46 100644 --- a/sources/ewol/compositing/Shaper.cpp +++ b/sources/ewol/compositing/Shaper.cpp @@ -623,20 +623,19 @@ const etk::Color& ewol::compositing::Shaper::getColor(int32_t _id) { return m_colorProperty->get(_id); } +namespace etk { + template<> std::string to_string(const ewol::compositing::Shaper& _obj) { + return _obj.getSource(); + } + template<> std::u32string to_u32string(const ewol::compositing::Shaper& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + template<> bool from_string(ewol::compositing::Shaper& _variableRet, const std::string& _value) { + _variableRet.setSource(_value); + return true; + } + template<> bool from_string(ewol::compositing::Shaper& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } +}; - -template<> std::string etk::to_string(const ewol::compositing::Shaper& _obj) { - return _obj.getSource(); -} - -template<> std::u32string etk::to_u32string(const ewol::compositing::Shaper& _obj) { - return etk::to_u32string(etk::to_string(_obj)); -} - -template<> bool etk::from_string(ewol::compositing::Shaper& _variableRet, const std::string& _value) { - _variableRet.setSource(_value); - return true; -} -template<> bool etk::from_string(ewol::compositing::Shaper& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); -} \ No newline at end of file diff --git a/sources/ewol/compositing/TextBasic.cpp b/sources/ewol/compositing/TextBasic.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/sources/ewol/compositing/TextBasic.h b/sources/ewol/compositing/TextBasic.h deleted file mode 100644 index e69de29b..00000000 diff --git a/sources/ewol/context/Application.cpp b/sources/ewol/context/Application.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/sources/ewol/context/Context.h b/sources/ewol/context/Context.h index 86002e47..4962b403 100644 --- a/sources/ewol/context/Context.h +++ b/sources/ewol/context/Context.h @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace ewol { diff --git a/sources/ewol/context/InputManager.h b/sources/ewol/context/InputManager.h index 5e9fcbdf..2e9a09d6 100644 --- a/sources/ewol/context/InputManager.h +++ b/sources/ewol/context/InputManager.h @@ -10,7 +10,6 @@ #define __EWOL_SYSTEM_INPUT_H__ #include -#include #define MAX_MANAGE_INPUT (15) diff --git a/sources/ewol/event/Input.cpp b/sources/ewol/event/Input.cpp index 702f47a4..39ca0b15 100644 --- a/sources/ewol/event/Input.cpp +++ b/sources/ewol/event/Input.cpp @@ -14,7 +14,7 @@ std::ostream& ewol::event::operator <<(std::ostream& _os, const ewol::event::Input& _obj) { _os << "{type=" << _obj.getType(); _os << " status=" << _obj.getStatus(); - _os << " id=" << _obj.getId(); + _os << " id=" << etk::to_string(_obj.getId()); _os << " pos=" << _obj.getPos(); _os << "}"; return _os; diff --git a/sources/ewol/object/Manager.cpp b/sources/ewol/object/Manager.cpp index 079d57f8..0f062c5a 100644 --- a/sources/ewol/object/Manager.cpp +++ b/sources/ewol/object/Manager.cpp @@ -53,7 +53,6 @@ void ewol::object::Manager::unInit() { if (m_eObjectList.size() != 0) { EWOL_ERROR("Have " << m_eObjectList.size() << " active Object"); } - m_multiCast.clear(); m_eObjectList.clear(); } @@ -101,19 +100,6 @@ std::shared_ptr ewol::object::Manager::get(const std::string& _nam } -void ewol::object::Manager::add(ewol::object::RemoveEvent* _class) { - m_removeEventList.push_back(_class); -} - -void ewol::object::Manager::rm(ewol::object::RemoveEvent* _class) { - for (size_t iii=0; iii ewol::object::Manager::getObjectNamed(const std::string& _name) { return ewol::object::Manager::get(_name); } diff --git a/sources/ewol/object/Manager.h b/sources/ewol/object/Manager.h index e55288ba..84f57b5a 100644 --- a/sources/ewol/object/Manager.h +++ b/sources/ewol/object/Manager.h @@ -11,15 +11,12 @@ #include #include -#include -#include namespace ewol { class Context; namespace object { class Manager { private: - std::vector m_removeEventList; std::vector> m_eObjectList; // all widget allocated == > all time increment ... never removed ... Context& m_context; public: @@ -47,15 +44,6 @@ namespace ewol { void cleanInternalRemoved(); std::shared_ptr get(const std::string& _name); - private: - ewol::object::MultiCast m_multiCast; //!< muticast manager - public: - ewol::object::MultiCast& multiCast() { - return m_multiCast; - }; - - void add(ewol::object::RemoveEvent* _class); - void rm(ewol::object::RemoveEvent* _class); public: /** diff --git a/sources/ewol/object/Message.cpp b/sources/ewol/object/Message.cpp deleted file mode 100644 index d303db6d..00000000 --- a/sources/ewol/object/Message.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#include - -#undef __class__ -#define __class__ "object/Message" - -std::ostream& ewol::object::operator <<(std::ostream& _os, const ewol::object::Message& _obj) { - _os << "{"; - if (nullptr != _obj.getMessage()) { - _os << "msg=\"" << _obj.getMessage() << "\""; - } else { - _os << "msg={nullptr}"; - } - _os << " data=\"" << _obj.getData() << "\"}"; - return _os; -} - diff --git a/sources/ewol/object/Message.h b/sources/ewol/object/Message.h deleted file mode 100644 index 8c4d60bf..00000000 --- a/sources/ewol/object/Message.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#ifndef __EWOL_OBJECT_MESSAGE_H__ -#define __EWOL_OBJECT_MESSAGE_H__ - -#include - -namespace ewol { - namespace object { - class Message { - private: - std::shared_ptr m_callerObject; //!< Caller class. - const char* m_event; //!< Event pointer == > unique Id define by the system ... - std::string m_data; //!< compositing additionnal message Value. - public: - Message(const std::shared_ptr& _caller, - const char* _message, - const std::string& _data) : - m_callerObject(_caller), - m_event(_message), - m_data(_data) { - - }; - void setCaller(const std::shared_ptr& _caller) { - m_callerObject = _caller; - }; - inline std::shared_ptr getCaller() const { - return m_callerObject; - }; - void setMessage(const char* _message) { - m_event = _message; - }; - inline const char* getMessage() const { - return m_event; - }; - void setData(const std::string& _data) { - m_data = _data; - }; - inline const std::string& getData() const { - return m_data; - }; - }; - std::ostream& operator <<(std::ostream& _os, const ewol::object::Message& _obj); - }; -}; - - -#endif - diff --git a/sources/ewol/object/MultiCast.cpp b/sources/ewol/object/MultiCast.cpp deleted file mode 100644 index e6166ef7..00000000 --- a/sources/ewol/object/MultiCast.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#include -#include -#include - -#undef __class__ -#define __class__ "object::MultiCast" - -ewol::object::MultiCast::MultiCast() { - EWOL_INFO("EObject message Multi-Cast"); -} - - -ewol::object::MultiCast::~MultiCast() { - EWOL_INFO("EObject message Multi-Cast"); - m_messageList.clear(); -} - -void ewol::object::MultiCast::clear() { - EWOL_INFO("EObject message Multi-Cast"); - m_messageList.clear(); -} - -void ewol::object::MultiCast::add(const std::shared_ptr& _object, const char* const _message) { - if (_object == nullptr) { - EWOL_ERROR("Add with nullptr object"); - return; - } - if (_message == nullptr) { - EWOL_ERROR("Add with nullptr Message"); - return; - } - m_messageList.push_back(MessageList(_message, _object)); - EWOL_DEBUG("SendMulticast ADD listener :" << _object->getId() << " on \"" << _message << "\"" ); -} - - -void ewol::object::MultiCast::rm(const std::shared_ptr& _object) { - if (_object == nullptr) { - EWOL_ERROR("Rm with nullptr object"); - return; - } - // send the message at all registered widget ... - auto it(m_messageList.begin()); - while (it != m_messageList.end()) { - std::shared_ptr obj = it->m_object.lock(); - if(obj == _object) { - EWOL_DEBUG("SendMulticast RM listener :" << _object->getId()); - m_messageList.erase(it); - it = m_messageList.begin(); - } else { - ++it; - } - } -} - -void ewol::object::MultiCast::send(const std::shared_ptr& _object, const char* const _message, const std::string& _data) { - EWOL_VERBOSE("SendMulticast message \"" << _message << "\" data=\"" << _data << "\" to:"); - // send the message at all registered widget ... - for (auto &it : m_messageList) { - std::shared_ptr obj = it.m_object.lock(); - if( it.m_message == _message - && obj != _object) { - if (obj != nullptr) { - EWOL_VERBOSE(" id = " << obj->getId() << " type=" << obj->getObjectType()); - // generate event ... (create message before ... - ewol::object::Message tmpMsg(_object, it.m_message, _data); - obj->onReceiveMessage(tmpMsg); - } - } - } -} - diff --git a/sources/ewol/object/MultiCast.h b/sources/ewol/object/MultiCast.h deleted file mode 100644 index 3579311c..00000000 --- a/sources/ewol/object/MultiCast.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#ifndef __EWOL_OBJECT_MULTICAST_H__ -#define __EWOL_OBJECT_MULTICAST_H__ - -#include -#include -#include -#include - -#include - -namespace ewol { - namespace object { - class MultiCast { - private: - class MessageList { - public: - MessageList(const char* _message=nullptr, std::shared_ptr _object=nullptr) : - m_message(_message), m_object(_object) { - - } - const char* m_message; - std::weak_ptr m_object; - }; - std::vector m_messageList; //!< List of all message ... - public: - MultiCast(); - virtual ~MultiCast(); - void clear(); - void anonymousSend(const char* const _messageId, const std::string& _data) { - send(nullptr, _messageId, _data); - }; - void send(const std::shared_ptr& _object, const char* const _message, const std::string& _data); - void rm(const std::shared_ptr& _object); - void add(const std::shared_ptr& _object, const char* const _message); - }; - }; -}; - -#endif diff --git a/sources/ewol/object/Object.cpp b/sources/ewol/object/Object.cpp index 66f5754a..c5aef84b 100644 --- a/sources/ewol/object/Object.cpp +++ b/sources/ewol/object/Object.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #undef __class__ #define __class__ "Object" @@ -57,15 +56,13 @@ ewol::Object::Object() : ewol::Object::~Object() { EWOL_DEBUG("delete Object : [" << m_uniqueId << "] : " << getTypeDescription()); - m_externEvent.clear(); - m_availlableEventId.clear(); m_uniqueId = -1; } void ewol::Object::init() { getObjectManager().add(shared_from_this()); - parameterDisplay(); + //parameterDisplay(); m_objectHasBeenInit = true; } @@ -109,161 +106,6 @@ bool ewol::Object::isTypeCompatible(const std::string& _type) { return false; } -void ewol::Object::addEventId(const char * _generateEventId) { - for (auto &it : m_availlableEventId) { - if (std::string(it) == _generateEventId) { - EWOL_WARNING("Event already existed : '" << it << "' == '" << _generateEventId << "'"); - return; - } - } - if (_generateEventId != nullptr) { - m_availlableEventId.push_back(_generateEventId); - } -} - -void ewol::Object::generateEventId(const char * _generateEventId, const std::string& _data) { - if (m_objectHasBeenInit == false) { - EWOL_WARNING("try to generate an event inside a constructor"); - return; - } - int32_t nbObject = getObjectManager().getNumberObject(); - EWOL_VERBOSE("try send message '" << _generateEventId << "'"); - // for every element registered ... - for (auto &it : m_externEvent) { - // if we find the event ... - if (it.localEventId != _generateEventId) { - EWOL_VERBOSE(" wrong event '" << it.localEventId << "' != '" << _generateEventId << "'"); - continue; - } - std::shared_ptr destObject = it.destObject.lock(); - if (destObject == nullptr) { - EWOL_VERBOSE(" nullptr dest"); - continue; - } - if (it.overloadData.size() <= 0){ - ewol::object::Message tmpMsg(shared_from_this(), it.destEventId, _data); - EWOL_VERBOSE("send message " << tmpMsg); - destObject->onReceiveMessage(tmpMsg); - } else { - // set the user requested data ... - ewol::object::Message tmpMsg(shared_from_this(), it.destEventId, it.overloadData); - EWOL_VERBOSE("send message " << tmpMsg); - destObject->onReceiveMessage(tmpMsg); - } - } - if (nbObject > getObjectManager().getNumberObject()) { - EWOL_CRITICAL("It if really dangerous ro remove (delete) element inside a callback ... use ->removObject() which is asynchronous"); - } -} - -void ewol::Object::sendMultiCast(const char* const _messageId, const std::string& _data) { - if (m_objectHasBeenInit == false) { - EWOL_WARNING("try to generate an multicast event inside a constructor"); - return; - } - int32_t nbObject = getObjectManager().getNumberObject(); - getMultiCast().send(shared_from_this(), _messageId, _data); - if (nbObject > getObjectManager().getNumberObject()) { - EWOL_CRITICAL("It if really dangerous ro remove (delete) element inside a callback ... use ->removObject() which is asynchronous"); - } -} - -void ewol::Object::registerMultiCast(const char* const _messageId) { - if (m_objectHasBeenInit == false) { - EWOL_ERROR("Try to Register multicast inside a constructor (move it in the init function)"); - return; - } - getMultiCast().add(shared_from_this(), _messageId); -} - -void ewol::Object::registerOnEvent(const std::shared_ptr& _destinationObject, - const char * _eventId, - const char * _eventIdgenerated, - const std::string& _overloadData) { - if (nullptr == _destinationObject) { - EWOL_ERROR("Input ERROR nullptr pointer Object ..."); - return; - } - if (nullptr == _eventId) { - EWOL_ERROR("Input ERROR nullptr pointer Event Id..."); - return; - } - if ( _eventId[0] == '*' - && _eventId[1] == '\0') { - EWOL_VERBOSE("Register on all event ..."); - for(auto &it : m_availlableEventId) { - ewol::object::EventExtGen tmpEvent; - tmpEvent.localEventId = it; - tmpEvent.destObject = _destinationObject; - tmpEvent.overloadData = _overloadData; - if (nullptr != _eventIdgenerated) { - tmpEvent.destEventId = _eventIdgenerated; - } else { - tmpEvent.destEventId = it; - } - m_externEvent.push_back(tmpEvent); - } - return; - } - // check if event existed : - bool findIt = false; - for(auto &it : m_availlableEventId) { - if (it == _eventId) { - findIt = true; - break; - } - } - if (false == findIt) { - EWOL_VERBOSE("Try to register with a NON direct string name"); - for(auto &it : m_availlableEventId) { - if (0 == strncmp(it, _eventId, 1024)) { - findIt = true; - _eventId = it; - EWOL_VERBOSE("find event ID : '" << _eventId << "' ==> '" << _eventIdgenerated << "'"); - break; - } - } - } - if (false == findIt) { - EWOL_ERROR("Can not register event on this Type=" << getObjectType() << " event=\"" << _eventId << "\" == > unknow event"); - return; - } - ewol::object::EventExtGen tmpEvent; - tmpEvent.localEventId = _eventId; - tmpEvent.destObject = _destinationObject; - tmpEvent.overloadData = _overloadData; - if (nullptr != _eventIdgenerated) { - tmpEvent.destEventId = _eventIdgenerated; - } else { - tmpEvent.destEventId = _eventId; - } - m_externEvent.push_back(tmpEvent); -} - -void ewol::Object::unRegisterOnEvent(const std::shared_ptr& _destinationObject, - const char * _eventId) { - if (_destinationObject == nullptr) { - EWOL_ERROR("Input ERROR nullptr pointer Object ..."); - return; - } - // check if event existed : - auto it(m_externEvent.begin()); - while(it != m_externEvent.end()) { - std::shared_ptr obj = it->destObject.lock(); - if (obj == nullptr) { - m_externEvent.erase(it); - it = m_externEvent.begin(); - } else if ( obj == _destinationObject - && it->localEventId == _eventId) { - m_externEvent.erase(it); - it = m_externEvent.begin(); - EWOL_INFO("[" << getId() << "] Remove extern event : to object id=" << _destinationObject->getId() << " event=" << _eventId); - } else { - ++it; - } - } -} - bool ewol::Object::loadXML(exml::Element* _node) { if (nullptr == _node) { return false; @@ -306,28 +148,17 @@ ewol::object::Manager& ewol::Object::getObjectManager() const { return tmp; } -ewol::object::MultiCast& ewol::Object::getMultiCast() const { - return ewol::getContext().getEObjectManager().multiCast(); -} - ewol::Context& ewol::Object::getContext() const { return ewol::getContext(); } - -void ewol::Object::registerOnObjectEvent(const std::shared_ptr& _destinationObject, - const std::string& _objectName, - const char * _eventId, - const char * _eventIdgenerated, - const std::string& _overloadData) { - std::shared_ptr tmpObject = getObjectManager().getObjectNamed(_objectName); - if (nullptr != tmpObject) { - EWOL_DEBUG("Find widget named : '" << _objectName << "' register event='" << _eventId << "'"); - tmpObject->registerOnEvent(_destinationObject, _eventId, _eventIdgenerated, _overloadData); - } else { - EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Can not register event : \"" << _eventId << "\" the object named=\"" << _objectName << "\" does not exist"); - } -} - std::shared_ptr ewol::Object::getObjectNamed(const std::string& _objectName) const { return getObjectManager().getObjectNamed(_objectName); } + +std::shared_ptr ewol::Object::getSubObjectNamed(const std::string& _objectName) { + if (_objectName == m_name.get()) { + return shared_from_this(); + } + return nullptr; +} + diff --git a/sources/ewol/object/Object.h b/sources/ewol/object/Object.h index 0ee75c03..8f083cc4 100644 --- a/sources/ewol/object/Object.h +++ b/sources/ewol/object/Object.h @@ -9,7 +9,6 @@ #ifndef __EWOL_OBJECT_H__ #define __EWOL_OBJECT_H__ -#include #include #include #include @@ -21,16 +20,16 @@ namespace ewol { class Object; namespace object { class Manager; - class MultiCast; }; class Context; }; -#include +#include #include #include #include #include +#include #define DECLARE_FACTORY(className) \ template static std::shared_ptr create( T&& ... all ) { \ @@ -47,24 +46,13 @@ namespace ewol { } namespace ewol { - namespace object { - /** - * local class for event generation - * @not-in-doc - */ - class EventExtGen { - public: - const char* localEventId; //!< local event Id generation - std::weak_ptr destObject; //!< destination widget that might be call - const char* destEventId; //!< generated event ID on the distant widget - std::string overloadData; //!< sometimes the user prefer to receive some specific data on an event (instead of the one sed by the widget) - }; - } /** * @brief Basic message classes for ewol system * this class mermit at every Object to communicate between them. */ - class Object : public std::enable_shared_from_this, public ewol::object::ParameterList { + class Object : public std::enable_shared_from_this, + public ewol::object::ParameterList, + public ewol::object::SignalList { private: static size_t m_valUID; //!< Static used for the unique ID definition private: @@ -75,6 +63,7 @@ namespace ewol { */ Object(); void init(); + //! @previous void init(const std::string& _name); public: /** @@ -148,58 +137,8 @@ namespace ewol { int32_t getId(){ return m_uniqueId; }; - private: - std::vector m_externEvent; //!< Generic list of event generation for output link - std::vector m_availlableEventId; //!< List of all event availlable for this widget - protected: - /** - * @brief add a specific event Id in the list to prevent wrong link on a Object - * @param[in] _generateEventId event Id to add - */ - void addEventId(const char * _generateEventId); - /** - * @brief generate event on all registered Object - * @param[in] _generateEventId event Id that is curetly generated - * @param[in] _data data associated with the event - */ - void generateEventId(const char * _generateEventId, const std::string& _data = ""); - /** - * @brief generate Multicast event on all Object requested the event - * @param[in] _messageId Event Id that is generated - * @param[in] _data String that is send at all the destinations - */ - void sendMultiCast(const char* const _messageId, const std::string& _data = ""); - /** - * @brief Register of the arrival of a Multicast message - * @param[in] _messageId Event Id waiting for... - */ - void registerMultiCast(const char* const _messageId); public: - /** - * @brief Register an Object over an other to get event on the second... - * @param[in] _destinationObject pointer on the object that might be call when an event is generated - * @param[in] _eventId Event generate inside the object (note : "*" event register on all event generated ) - * @param[in] _eventIdgenerated event generated when call the distant Object.onReceiveMessage(...) - * @param[in] _overloadData When the user prever to receive a data specificly for this event ... - */ - void registerOnEvent(const std::shared_ptr& _destinationObject, - const char * _eventId, - const char * _eventIdgenerated = nullptr, - const std::string& _overloadData = ""); - /** - * @brief Un-Register an Object over an other. - * @param[in] _destinationObject pointer on the object that might be call when an event is generated - * @param[in] _eventId Event generate inside the object (nullptr to remove all event on this object) - */ - void unRegisterOnEvent(const std::shared_ptr& _destinationObject, - const char * _eventId = nullptr); - /** - * @brief Receive a message from an other Object with a specific eventId and data - * @param[in] _msg Message handle - */ - virtual void onReceiveMessage(const ewol::object::Message& _msg) { }; - public: - // TODO : Rework the position on this function ... + // TODO : Rework the position on this function ... This is a convignent function ... bool parameterSetOnWidgetNamed(const std::string& _objectName, const std::string& _config, const std::string& _value); protected: ewol::object::Param m_name; //!< name of the element ... @@ -239,11 +178,6 @@ namespace ewol { * @return the requested object manager. */ ewol::object::Manager& getObjectManager() const; - /** - * @breif get the current Object Message Multicast manager. - * @return the requested object manager. - */ - ewol::object::MultiCast& getMultiCast() const; /** * @brief get the curent the system inteface. * @return current reference on the instance. @@ -267,30 +201,70 @@ namespace ewol { bool getStatusResource() const { return m_isResource; } - /** - * @brief Register an Event an named widget. @see registerOnEvent - * @param[in] _destinationObject pointer on the object that might be call when an event is generated - * @param[in] _objectName Name of the object. - * @param[in] _eventId Event generate inside the object. - * @param[in] _eventIdgenerated event generated when call the distant EObject.onReceiveMessage(...) - * @param[in] _overloadData When the user prever to receive a data specificly for this event ... - * @note : To used when NOT herited from this object. - */ - void registerOnObjectEvent(const std::shared_ptr& _destinationObject, - const std::string& _objectName, - const char * _eventId, - const char * _eventIdgenerated = nullptr, - const std::string& _overloadData=""); /** * @brief Retrive an object with his name (in the global list) * @param[in] _name Name of the object * @return the requested object or nullptr */ std::shared_ptr getObjectNamed(const std::string& _objectName) const; + /** + * @brief Retrive an object with his name (in the global list) + * @param[in] _name Name of the object + * @return the requested object or nullptr + */ + virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); + protected: + // TODO : Create a template ... + /** + * @brief link on an signal in the subwiget with his name + */ + #define subBind(_type, _name, _event, _obj, _func) do {\ + std::shared_ptr<_type> myObject = std::dynamic_pointer_cast<_type>(getSubObjectNamed(_name)); \ + if (myObject != nullptr) { \ + myObject->_event.bind(_obj, _func); \ + } else { \ + EWOL_ERROR("object named='" << _name << "' not exit or can not be cast in : " << #_type); \ + } \ + } while (false) + /* + template void bind(std::shared_ptr _obj, void (TYPE::*_func)()) { + std::shared_ptr obj2 = std::dynamic_pointer_cast(_obj); + if (obj2 == nullptr) { + EWOL_ERROR("Can not bind signal ..."); + return; + } + m_callerList.push_back(std::make_pair(std::weak_ptr(_obj), std::bind(_func, obj2.get()))); + } + */ }; }; +/** + * @brief link on an signal in the global object list with his name + */ +#define globalBind(_type, _name, _event, _obj, _func) do {\ + std::shared_ptr<_type> myObject = std::dynamic_pointer_cast<_type>(ewol::getContext().getEObjectManager().getObjectNamed(_name)); \ + if (myObject != nullptr) { \ + myObject->_event.bind(_obj, _func); \ + } else { \ + EWOL_ERROR("object named='" << _name << "' not exit or can not be cast in : " << #_type); \ + } \ +} while (false) + +/** + * @brief link on an signal in the subWidget of an object with his name + */ +#define externSubBind(_object, _type, _name, _event, _obj, _func) do {\ + std::shared_ptr<_type> myObject = std::dynamic_pointer_cast<_type>(_object->getObjectNamed(_name)); \ + if (myObject != nullptr) { \ + myObject->_event.bind(_obj, _func); \ + } else { \ + EWOL_ERROR("object named='" << _name << "' not exit or can not be cast in : " << #_type); \ + } \ +} while (false) +//#include + #endif diff --git a/sources/ewol/object/Param.cpp b/sources/ewol/object/Param.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/sources/ewol/object/Param.h b/sources/ewol/object/Param.h index f2da9ff4..77bcee18 100644 --- a/sources/ewol/object/Param.h +++ b/sources/ewol/object/Param.h @@ -135,7 +135,7 @@ namespace ewol { } }; - template std::ostream& operator <<(std::ostream& _os, const ewol::object::Param& _obj) { + template std::ostream& operator <<(std::ostream& _os, const ewol::object::Param& _obj) { _os << _obj.get(); return _os; } diff --git a/sources/ewol/object/ParamRange.cpp b/sources/ewol/object/ParamRange.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/sources/ewol/object/RemoveEvent.cpp b/sources/ewol/object/RemoveEvent.cpp deleted file mode 100644 index 2aca7d11..00000000 --- a/sources/ewol/object/RemoveEvent.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#include -#include - -ewol::object::RemoveEvent::RemoveEvent() { - EWOL_TODO("ewol::object::RemoveEvent::RemoveEvent()"); - /* - Context& tmp = ewol::getContext(); - ewol::object::Manager& manager = tmp.getEObjectManager(); - manager.add(this); - */ -} - -ewol::object::RemoveEvent::~RemoveEvent() { - EWOL_TODO("ewol::object::RemoveEvent::~RemoveEvent()"); - /* - Context& tmp = ewol::getContext(); - ewol::object::Manager& manager = tmp.getEObjectManager(); - manager.rm(this); - */ -} diff --git a/sources/ewol/object/RemoveEvent.h b/sources/ewol/object/RemoveEvent.h deleted file mode 100644 index e3da2dde..00000000 --- a/sources/ewol/object/RemoveEvent.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#ifndef __EWOL_OBJECT_REMOVE_EVENT_H__ -#define __EWOL_OBJECT_REMOVE_EVENT_H__ - -#include -#include - -namespace ewol { - namespace object { - class RemoveEvent { - public: - RemoveEvent(); - virtual ~RemoveEvent(); - }; - } -}; - -#endif diff --git a/sources/ewol/object/Signal.h b/sources/ewol/object/Signal.h new file mode 100644 index 00000000..1652848c --- /dev/null +++ b/sources/ewol/object/Signal.h @@ -0,0 +1,191 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#include + +#ifndef __EWOL_SIGNAL_H__ +#define __EWOL_SIGNAL_H__ + +#include +#include +#include +#include + +namespace ewol { + namespace object { + #undef __class__ + #define __class__ "object::Signal" + template class Signal : public SignalBase { + private: + std::vector, + std::function>> m_callerList; + public: + /** + * @brief Create a parameter with a specific type. + * @param[in] _objectLink reference on the parameter lister. + * @param[in] _name Static name of the parameter. + * @param[in] _defaultValue Default value of the parameter. + * @param[in] _min Minumum value. + * @param[in] _max Maximum value. + * @param[in] _description description of the parameter. + */ + Signal(ewol::object::SignalList& _objectLink, + const std::string& _name, + const std::string& _description = "") : + SignalBase(_objectLink, _name, _description) { + + }; + /** + * @brief Destructor. + */ + virtual ~Signal() { }; + /** + * @brief Bind a callback function to the current signal (generic methis (simplest)) + * @param[in] _obj Shared pointer on the caller object + * @param[in] _func Link on the fuction that might be called (inside a class) + * @example signalXXXX.bind(shared_from_this(), &ClassName::onCallbackXXX); + */ + template void bind(std::shared_ptr _obj, void (TYPE::*_func)(const T&)) { + std::shared_ptr obj2 = std::dynamic_pointer_cast(_obj); + if (obj2 == nullptr) { + EWOL_ERROR("Can not bind signal ..."); + return; + } + m_callerList.push_back(std::make_pair(std::weak_ptr(_obj), std::bind(_func, obj2.get(), std::placeholders::_1))); + } + /** + * @brief Advanced binding a callback function to the current signal. + * @param[in] _obj Shared pointer on the caller object + * @param[in] _func functor to call (do it yourself) + * @example signalXXXX.connect(shared_from_this(), std::bind(&ClassName::onCallbackXXX, this, std::placeholders::_1)); + */ + void connect(std::shared_ptr _obj, std::function _function ) { + m_callerList.push_back(std::make_pair(std::weak_ptr(_obj), _function)); + } + /** + * @brief remove link on the signal. + * @param[in] _obj shared pointer on the removing object + */ + void release(std::shared_ptr _obj) { + for (auto it(m_callerList.begin()) ; it != m_callerList.end(); ++it) { + if (it->first.lock() == _obj) { + m_callerList.erase(it); + it = m_callerList.begin(); + } + } + } + /** + * @brief Generate a signal on all interface listening. + * @param[in] _data data to emit + */ + void emit(const T& _data) { + for (auto &it : m_callerList) { + std::shared_ptr destObject = it.first.lock(); + if (destObject == nullptr) { + // TODO : Remove instance ... + EWOL_VERBOSE(" nullptr dest"); + continue; + } + #ifdef DEBUG + ewol::Object* srcObject = dynamic_cast(&m_objectLink); + if (srcObject != nullptr) { + EWOL_DEBUG("emit signal : " << srcObject->getObjectType() << " '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " data='" << etk::to_string(_data) << "'"); + } else { + EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " data='" << etk::to_string(_data) << "'"); + } + #endif + it.second(_data); + } + } + }; + #undef __class__ + #define __class__ "object::Signal" + template<> class Signal : public SignalBase { + private: + std::vector, std::function>> m_callerList; + public: + /** + * @brief Create a parameter with a specific type. + * @param[in] _objectLink reference on the parameter lister. + * @param[in] _name Static name of the parameter. + * @param[in] _defaultValue Default value of the parameter. + * @param[in] _min Minumum value. + * @param[in] _max Maximum value. + * @param[in] _description description of the parameter. + */ + Signal(ewol::object::SignalList& _objectLink, + const std::string& _name, + const std::string& _description = "") : + SignalBase(_objectLink, _name, _description) { + + }; + /** + * @brief Destructor. + */ + virtual ~Signal() { }; + + /** + * @brief Bind a callback function to the current signal (generic methis (simplest)) + * @param[in] _obj Shared pointer on the caller object + * @param[in] _func Link on the fuction that might be called (inside a class) + * @example signalXXXX.connect(shared_from_this(), &ClassName::onCallbackXXX); + */ + template void bind(std::shared_ptr _obj, void (TYPE::*_func)()) { + std::shared_ptr obj2 = std::dynamic_pointer_cast(_obj); + if (obj2 == nullptr) { + EWOL_ERROR("Can not bind signal ..."); + return; + } + m_callerList.push_back(std::make_pair(std::weak_ptr(_obj), std::bind(_func, obj2.get()))); + } + /** + * @brief Advanced binding a callback function to the current signal. + * @param[in] _obj Shared pointer on the caller object + * @param[in] _func functor to call (do it yourself) + * @example signalXXXX.connect(shared_from_this(), std::bind(&ClassName::onCallbackXXX, this, std::placeholders::_1)); + */ + void connect(std::shared_ptr _obj, std::function _function ) { + m_callerList.push_back(std::make_pair(std::weak_ptr(_obj), _function)); + } + /** + * @brief remove link on the signal. + * @param[in] _obj shared pointer on the removing object + */ + void release(std::shared_ptr _obj) { + for (auto it(m_callerList.begin()) ; it != m_callerList.end(); ++it) { + if (it->first.lock() == _obj) { + m_callerList.erase(it); + it = m_callerList.begin(); + } + } + } + void emit() { + for (auto &it : m_callerList) { + std::shared_ptr destObject = it.first.lock(); + if (destObject == nullptr) { + // TODO : Remove instance ... + EWOL_VERBOSE(" nullptr dest"); + continue; + } + #ifdef DEBUG + ewol::Object* srcObject = dynamic_cast(&m_objectLink); + if (srcObject != nullptr) { + EWOL_DEBUG("emit signal : " << srcObject->getObjectType() << " '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " BANG!!!"); + } else { + EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " BANG!!!"); + } + #endif + it.second(); + } + } + }; + #undef __class__ + #define __class__ nullptr + }; +}; +#endif diff --git a/sources/ewol/object/SignalBase.cpp b/sources/ewol/object/SignalBase.cpp new file mode 100644 index 00000000..11d2aac6 --- /dev/null +++ b/sources/ewol/object/SignalBase.cpp @@ -0,0 +1,29 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#include +#include +#include +#include +#include + +ewol::object::SignalBase::SignalBase(ewol::object::SignalList& _objectLink, + const std::string& _name, + const std::string& _description) : + m_objectLink(_objectLink), + m_name(_name), + m_description(_description) { + // add a reference on the current signal ... + m_objectLink.signalAdd(this); +} + +std::ostream& ewol::object::operator <<(std::ostream& _os, const ewol::object::SignalBase& _obj) { + _os << _obj.getName(); + return _os; +} + diff --git a/sources/ewol/object/SignalBase.h b/sources/ewol/object/SignalBase.h new file mode 100644 index 00000000..e45b4cac --- /dev/null +++ b/sources/ewol/object/SignalBase.h @@ -0,0 +1,50 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#ifndef __EWOL_SIGNAL_BASE_H__ +#define __EWOL_SIGNAL_BASE_H__ + +#include +#include +#include + + +namespace ewol { + namespace object { + class SignalBase { + protected: + ewol::object::SignalList& m_objectLink; + std::string m_name; + std::string m_description; + public: + /** + * @brief Create a parameter with a specific type. + * @param[in] _objectLink reference on the parameter lister. + * @param[in] _name Static name of the parameter. + * @param[in] _description description of the parameter. + */ + SignalBase(ewol::object::SignalList& _objectLink, + const std::string& _name, + const std::string& _description = ""); + /** + * @brief Destructor. + */ + virtual ~SignalBase() { }; + + const std::string& getName() const { + return m_name; + } + const std::string& getDescription() const { + return m_description; + } + virtual void release(std::shared_ptr _obj) = 0; + }; + std::ostream& operator <<(std::ostream& _os, const SignalBase& _obj); + }; +}; +#endif diff --git a/sources/ewol/object/SignalList.cpp b/sources/ewol/object/SignalList.cpp new file mode 100644 index 00000000..d34e378b --- /dev/null +++ b/sources/ewol/object/SignalList.cpp @@ -0,0 +1,54 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#include +#include +#include +#include +#include +#include + +ewol::object::SignalList::SignalList() { + +} + +ewol::object::SignalList::~SignalList() { + m_list.clear(); +} + +// note this pointer is not allocated and not free at the end of the class +void ewol::object::SignalList::signalAdd(SignalBase* _pointerOnSignal) { + if (_pointerOnSignal == nullptr) { + EWOL_ERROR("Try to link a nullptr parameters"); + return; + } + m_list.push_back(_pointerOnSignal); +} + +std::vector ewol::object::SignalList::signalGetAll() const { + std::vector out; + for (auto &it : m_list) { + if(it != nullptr) { + out.push_back(it->getName()); + } + } + return out; +} + +void ewol::object::SignalList::unBindAll(const std::shared_ptr& _object) { + if (_object == nullptr) { + EWOL_ERROR("Input ERROR nullptr pointer Object ..."); + return; + } + for(auto &it : m_list) { + if (it == nullptr) { + continue; + } + it->release(_object); + } +} diff --git a/sources/ewol/object/SignalList.h b/sources/ewol/object/SignalList.h new file mode 100644 index 00000000..bac84c74 --- /dev/null +++ b/sources/ewol/object/SignalList.h @@ -0,0 +1,52 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + + +#ifndef __EWOL_SIGNAL_LIST_H__ +#define __EWOL_SIGNAL_LIST_H__ + +#include +#include + +namespace ewol { + namespace object { + class SignalBase; + class SignalList { + friend class ewol::object::SignalBase; // to register parameter in the list. + private: + std::vector m_list; //!< list of availlable Parameters + public: + /** + * @brief Constructor. + */ + SignalList(); + /** + * @brief Destructor. + */ + virtual ~SignalList(); + /** + * @brief Register a parameter class pointer in the List of parameters + * @note This class does not destroy the parameter pointer!!! + * @param[in] pointerOnParameter Pointer on the parameter that might be added. + */ + void signalAdd(SignalBase* _pointerOnParameter); + /** + * @brief Get All the signal list: + * @return vector on all the signals names + */ + std::vector signalGetAll() const; + /** + * @brief Remove binding on all event class. + * @param[in] _object Object to unlink. + */ + void unBindAll(const std::shared_ptr& _object); + }; + }; +}; + +#endif diff --git a/sources/ewol/resource/Manager.h b/sources/ewol/resource/Manager.h index 9647fe9f..2a8bf023 100644 --- a/sources/ewol/resource/Manager.h +++ b/sources/ewol/resource/Manager.h @@ -14,7 +14,6 @@ #include #include #include -#include namespace ewol { namespace resource { diff --git a/sources/ewol/resource/Resource.h b/sources/ewol/resource/Resource.h index 66e367c7..a267374d 100644 --- a/sources/ewol/resource/Resource.h +++ b/sources/ewol/resource/Resource.h @@ -90,31 +90,69 @@ namespace ewol { namespace resource { class Manager; }; - // class resources is pure virtual + /** + * @brief A Resource is a generic interface to have an instance that have things that can be used by many people, ad have some hardware dependency. + * For example of resources : + * :** Shaders: openGL display interface. + * :** Texture: openGL imega interface. + * :** Font: Single file interface to store many glyphe ==> reduce the number of parallele loaded files. + * :** ConfigFile: simple widget configuration files + * :** ... + */ class Resource : public ewol::Object { protected: + /** + * @brief generic protected contructor (use factory to create this class) + */ Resource() : m_resourceLevel(MAX_RESOURCE_LEVEL-1) { addObjectType("ewol::Resource"); setStatusResource(true); }; + /** + * @brief Initialisation of the class and previous classes. + * @param[in] _name Name of the resource. + */ void init(); + //! @previous void init(const std::string& _name); public: - + //! geenric destructor virtual ~Resource() { }; protected: - uint8_t m_resourceLevel; //!< Level of the resource ==> for updata priority [0..5] 0 must be update first. + uint8_t m_resourceLevel; //!< Level of the resource ==> for update priority [0..5] 0 must be update first. public: - uint8_t getResourceLevel() { + /** + * @brief Get the current resource level; + * @return value in [0..5] + */ + uint8_t getResourceLevel() { return m_resourceLevel; }; + /** + * @brief Call when need to send data on the harware (openGL) + * @note This is done asynchronously with the create of the Resource. + */ virtual void updateContext(); + /** + * @brief The current OpenGl context is removing ==> remove yout own system data + */ virtual void removeContext(); + /** + * @brief The notification of the Context removing is too late, we have no more acces on the OpenGl context (thank you Android). + * Juste update your internal state + */ virtual void removeContextToLate(); + /** + * @brief User request the reload of all resources (usefull when the file depend on DATA:GUI:xxx ... + */ virtual void reload(); + protected: + /** + * @brief Get the current resource Manager + */ static ewol::resource::Manager& getManager(); }; }; diff --git a/sources/ewol/widget/Button.cpp b/sources/ewol/widget/Button.cpp index 13b59cab..bbd0371f 100644 --- a/sources/ewol/widget/Button.cpp +++ b/sources/ewol/widget/Button.cpp @@ -14,14 +14,6 @@ #define __class__ "Button" -const char* const ewol::widget::Button::eventPressed = "pressed"; -const char* const ewol::widget::Button::eventDown = "down"; -const char* const ewol::widget::Button::eventUp = "up"; -const char* const ewol::widget::Button::eventEnter = "enter"; -const char* const ewol::widget::Button::eventLeave = "leave"; -const char* const ewol::widget::Button::eventValue = "value"; - - // DEFINE for the shader display system : #define STATUS_UP (0) #define STATUS_HOVER (2) @@ -29,6 +21,12 @@ const char* const ewol::widget::Button::eventValue = "value"; #define STATUS_DOWN (3) ewol::widget::Button::Button() : + signalPressed(*this, "pressed", "Button is pressed"), + signalDown(*this, "down", "Button is DOWN"), + signalUp(*this, "up", "Button is UP"), + signalEnter(*this, "enter", "The cursor enter inside the button"), + signalLeave(*this, "leave", "the cursor leave the button"), + signalValue(*this, "value", "button value change"), m_shaper(*this, "shaper", "The display name for config file"), m_value(*this, "value", false, "Value of the Button"), m_lock(*this, "lock", lockNone, "Lock the button in a special state to permit changing state only by the coder"), @@ -39,13 +37,6 @@ ewol::widget::Button::Button() : m_selectableAreaPos(0,0), m_selectableAreaSize(0,0) { addObjectType("ewol::widget::Button"); - // add basic Event generated : - addEventId(eventPressed); - addEventId(eventDown); - addEventId(eventUp); - addEventId(eventEnter); - addEventId(eventLeave); - addEventId(eventValue); // set property list: m_lock.add(lockNone, "none"); @@ -130,36 +121,36 @@ bool ewol::widget::Button::onEventInput(const ewol::event::Input& _event) { if (true == m_mouseHover) { if (1 == _event.getId()) { if(ewol::key::statusDown == _event.getStatus()) { - EWOL_VERBOSE(getName() << " : Generate event : " << eventDown); - generateEventId(eventDown); + EWOL_VERBOSE(getName() << " : Generate event : " << signalDown); + signalDown.emit(); m_buttonPressed = true; markToRedraw(); } if(ewol::key::statusUp == _event.getStatus()) { - EWOL_VERBOSE(getName() << " : Generate event : " << eventUp); - generateEventId(eventUp); + EWOL_VERBOSE(getName() << " : Generate event : " << signalUp); + signalUp.emit(); m_buttonPressed = false; markToRedraw(); } if(ewol::key::statusSingle == _event.getStatus()) { - if( ( m_value == true + if( ( m_value.get() == true && ewol::widget::Button::lockWhenPressed == m_lock) - || ( m_value == false + || ( m_value.get() == false && ewol::widget::Button::lockWhenReleased == m_lock) ) { // nothing to do : Lock mode ... // user might set himself the new correct value with @ref setValue(xxx) } else { // inverse value : - setValue((m_value)?false:true); - EWOL_VERBOSE(getName() << " : Generate event : " << eventPressed); - generateEventId(eventPressed); - EWOL_VERBOSE(getName() << " : Generate event : " << eventValue << " val=" << m_value ); - generateEventId(eventValue, etk::to_string(m_value.get())); - if( false == m_toggleMode - && true == m_value) { + setValue((m_value.get())?false:true); + EWOL_VERBOSE(getName() << " : Generate event : " << signalPressed); + signalPressed.emit(); + EWOL_VERBOSE(getName() << " : Generate event : " << signalValue << " val=" << m_value ); + signalValue.emit(m_value.get()); + if( m_toggleMode.get() == false + && m_value.get() == true) { setValue(false); - EWOL_VERBOSE(getName() << " : Generate event : " << ewol::widget::Button::eventValue << " val=" << m_value); - generateEventId(eventValue, etk::to_string(m_value.get())); + EWOL_VERBOSE(getName() << " : Generate event : " << signalValue << " val=" << m_value); + signalValue.emit(m_value.get()); } } markToRedraw(); @@ -176,7 +167,7 @@ bool ewol::widget::Button::onEventEntry(const ewol::event::Entry& _event) { if( _event.getType() == ewol::key::keyboardChar && _event.getStatus() == ewol::key::statusDown && _event.getChar() == '\r') { - generateEventId(eventEnter); + signalEnter.emit(); return true; } return false; @@ -225,7 +216,7 @@ void ewol::widget::Button::onParameterChangeValue(const ewol::object::ParameterR markToRedraw(); } else if (_paramPointer == m_value) { if (m_toggleMode == true) { - if (m_value == false) { + if (m_value.get() == false) { m_idWidgetDisplayed = 0; } else { m_idWidgetDisplayed = 1; @@ -252,20 +243,20 @@ void ewol::widget::Button::onParameterChangeValue(const ewol::object::ParameterR CheckStatus(); markToRedraw(); } else if (_paramPointer == m_toggleMode) { - if (m_value == true) { - m_value = false; + if (m_value.get() == true) { + m_value.get() = false; // TODO : change display and send event ... } - if (m_toggleMode == false) { + if (m_toggleMode.get() == false) { m_idWidgetDisplayed = 0; } else { - if (m_value == false) { + if (m_value.get() == false) { m_idWidgetDisplayed = 0; } else { m_idWidgetDisplayed = 1; } } - if (m_enableSingle == true) { + if (m_enableSingle.get() == true) { if ( m_idWidgetDisplayed == 0 && m_subWidget[0] == nullptr && m_subWidget[1] != nullptr) { diff --git a/sources/ewol/widget/Button.h b/sources/ewol/widget/Button.h index 3a8498e5..8a06404b 100644 --- a/sources/ewol/widget/Button.h +++ b/sources/ewol/widget/Button.h @@ -17,6 +17,7 @@ #include #include #include +#include @@ -29,12 +30,12 @@ namespace ewol { class Button : public ewol::widget::Container2 { public: // Event list of properties - static const char* const eventPressed; - static const char* const eventDown; - static const char* const eventUp; - static const char* const eventEnter; - static const char* const eventLeave; - static const char* const eventValue; + ewol::object::Signal signalPressed; + ewol::object::Signal signalDown; + ewol::object::Signal signalUp; + ewol::object::Signal signalEnter; + ewol::object::Signal signalLeave; + ewol::object::Signal signalValue; enum buttonLock{ lockNone, //!< normal status of the button lockWhenPressed, //!< When the state is set in pressed, the status stay in this one diff --git a/sources/ewol/widget/ButtonColor.cpp b/sources/ewol/widget/ButtonColor.cpp index 088c155b..6424deff 100644 --- a/sources/ewol/widget/ButtonColor.cpp +++ b/sources/ewol/widget/ButtonColor.cpp @@ -15,9 +15,6 @@ #include #include -const char * const ewol::widget::ButtonColor::eventChange = "change"; - - // DEFINE for the shader display system : #define STATUS_UP (0) #define STATUS_HOVER (2) @@ -31,10 +28,10 @@ const char * const ewol::widget::ButtonColor::eventChange = "change"; static const char* const eventColorHasChange = "ewol-widget-ButtonColor-colorChange"; ewol::widget::ButtonColor::ButtonColor() : + signalChange(*this, "change", "Button color change value"), m_textColorFg(etk::color::black), m_widgetContextMenu(nullptr) { addObjectType("ewol::widget::ButtonColor"); - addEventId(eventChange); changeStatusIn(STATUS_UP); setCanHaveFocus(true); // Limit event at 1: @@ -185,7 +182,7 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) { myColorChooser->setColor(m_textColorFg); // set it in the pop-up-system : m_widgetContextMenu->setSubWidget(myColorChooser); - myColorChooser->registerOnEvent(shared_from_this(), "change", eventColorHasChange); + myColorChooser->signalChange.bind(shared_from_this(), &ewol::widget::ButtonColor::onCallbackColorChange); std::shared_ptr currentWindows = getWindows(); if (currentWindows == nullptr) { EWOL_ERROR("Can not get the curent Windows..."); @@ -212,9 +209,13 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) { return m_mouseHover; } +void ewol::widget::ButtonColor::onCallbackColorChange(const etk::Color<>& _color) { + setValue(_color); +} -void ewol::widget::ButtonColor::setValue(etk::Color<> _color) { +void ewol::widget::ButtonColor::setValue(const etk::Color<>& _color) { m_textColorFg = _color; + signalChange.emit(m_textColorFg); markToRedraw(); } @@ -222,17 +223,6 @@ etk::Color<> ewol::widget::ButtonColor::getValue() { return m_textColorFg; } - -void ewol::widget::ButtonColor::onReceiveMessage(const ewol::object::Message& _msg) { - EWOL_INFO("Receive MSG : " << _msg.getData()); - if (_msg.getMessage() == eventColorHasChange) { - m_textColorFg = _msg.getData(); - generateEventId(eventChange, _msg.getData()); - markToRedraw(); - } -} - - void ewol::widget::ButtonColor::changeStatusIn(int32_t _newStatusId) { if (true == m_shaper.changeStatusIn(_newStatusId) ) { periodicCallEnable(); @@ -240,8 +230,6 @@ void ewol::widget::ButtonColor::changeStatusIn(int32_t _newStatusId) { } } - - void ewol::widget::ButtonColor::periodicCall(const ewol::event::Time& _event) { if (false == m_shaper.periodicCall(_event) ) { periodicCallDisable(); diff --git a/sources/ewol/widget/ButtonColor.h b/sources/ewol/widget/ButtonColor.h index 53bd0bb7..2b096c1b 100644 --- a/sources/ewol/widget/ButtonColor.h +++ b/sources/ewol/widget/ButtonColor.h @@ -17,13 +17,14 @@ #include #include #include +#include namespace ewol { namespace widget { class ButtonColor : public ewol::Widget { public: // Event list of properties - static const char * const eventChange; + ewol::object::Signal> signalChange; private: ewol::compositing::Shaper m_shaper; //!< Compositing theme. ewol::compositing::Text m_text; //!< Compositing Test display. @@ -62,14 +63,13 @@ namespace ewol { * @brief Specify the current color. * @param[in] _color The new display color. */ - void setValue(etk::Color<> _color); + void setValue(const etk::Color<>& _color); protected: // Derived function virtual void onDraw(); public: // Derived function virtual void calculateMinMaxSize(); virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); - virtual void onReceiveMessage(const ewol::object::Message& _msg); private: /** * @brief internal system to change the property of the current status @@ -78,6 +78,8 @@ namespace ewol { void changeStatusIn(int32_t _newStatusId); // Derived function virtual void periodicCall(const ewol::event::Time& _event); + // Callback function: + void onCallbackColorChange(const etk::Color<>& _color); }; }; }; diff --git a/sources/ewol/widget/CheckBox.cpp b/sources/ewol/widget/CheckBox.cpp index 99fbabed..56d3e05d 100644 --- a/sources/ewol/widget/CheckBox.cpp +++ b/sources/ewol/widget/CheckBox.cpp @@ -9,13 +9,6 @@ #include #include -const char* const ewol::widget::CheckBox::eventPressed = "pressed"; -const char* const ewol::widget::CheckBox::eventDown = "down"; -const char* const ewol::widget::CheckBox::eventUp = "up"; -const char* const ewol::widget::CheckBox::eventEnter = "enter"; -const char* const ewol::widget::CheckBox::eventValue = "value"; - - // DEFINE for the shader display system : #define STATUS_UP (0) #define STATUS_HOVER (2) @@ -26,6 +19,11 @@ const char* const ewol::widget::CheckBox::eventValue = "value"; ewol::widget::CheckBox::CheckBox() : + signalPressed(*this, "pressed", "CheckBox is pressed"), + signalDown(*this, "down", "CheckBox is DOWN"), + signalUp(*this, "up", "CheckBox is UP"), + signalEnter(*this, "enter", "The cursor enter inside the CheckBox"), + signalValue(*this, "value", "CheckBox value change"), m_shaper(*this, "shaper", "The display name for config file"), m_mouseHover(false), m_buttonPressed(false), @@ -35,12 +33,6 @@ ewol::widget::CheckBox::CheckBox() : m_shaperIdSizeInsize(-1), m_value(*this, "value", false, "Basic value of the widget") { addObjectType("ewol::widget::CheckBox"); - // add basic Event generated : - addEventId(eventPressed); - addEventId(eventDown); - addEventId(eventUp); - addEventId(eventEnter); - addEventId(eventValue); m_shaperIdSize = m_shaper->requestConfig("box-size"); m_shaperIdSizeInsize = m_shaper->requestConfig("box-inside"); @@ -135,24 +127,24 @@ bool ewol::widget::CheckBox::onEventInput(const ewol::event::Input& _event) { if (true == m_mouseHover) { if (1 == _event.getId()) { if(ewol::key::statusDown == _event.getStatus()) { - EWOL_VERBOSE(getName() << " : Generate event : " << eventDown); - generateEventId(eventDown); + EWOL_VERBOSE(getName() << " : Generate event : " << signalDown); + signalDown.emit(); m_buttonPressed = true; markToRedraw(); } if(ewol::key::statusUp == _event.getStatus()) { - EWOL_VERBOSE(getName() << " : Generate event : " << eventUp); - generateEventId(eventUp); + EWOL_VERBOSE(getName() << " : Generate event : " << signalUp); + signalUp.emit(); m_buttonPressed = false; markToRedraw(); } if(ewol::key::statusSingle == _event.getStatus()) { // inverse value : setValue((m_value)?false:true); - EWOL_VERBOSE(getName() << " : Generate event : " << eventPressed); - generateEventId(eventPressed); - EWOL_VERBOSE(getName() << " : Generate event : " << eventValue << " val=" << m_value ); - generateEventId(eventValue, etk::to_string(m_value.get())); + EWOL_VERBOSE(getName() << " : Generate event : " << signalPressed); + signalPressed.emit(); + EWOL_VERBOSE(getName() << " : Generate event : " << signalValue << " val=" << m_value ); + signalValue.emit(m_value.get()); markToRedraw(); } } @@ -170,7 +162,7 @@ bool ewol::widget::CheckBox::onEventEntry(const ewol::event::Entry& _event) { if( _event.getType() == ewol::key::keyboardChar && _event.getStatus() == ewol::key::statusDown && _event.getChar() == '\r') { - generateEventId(eventEnter); + signalEnter.emit(); return true; } return false; @@ -208,7 +200,7 @@ void ewol::widget::CheckBox::onParameterChangeValue(const ewol::object::Paramete if (_paramPointer == m_shaper) { markToRedraw(); } else if (_paramPointer == m_value) { - if (m_value == false) { + if (m_value.get() == false) { m_idWidgetDisplayed = convertId(0); } else { m_idWidgetDisplayed = convertId(1); diff --git a/sources/ewol/widget/CheckBox.h b/sources/ewol/widget/CheckBox.h index 741ef2df..20cbfeee 100644 --- a/sources/ewol/widget/CheckBox.h +++ b/sources/ewol/widget/CheckBox.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace ewol { @@ -21,11 +22,11 @@ namespace ewol { class CheckBox : public ewol::widget::Container2 { public: // Event list of properties - static const char* const eventPressed; - static const char* const eventDown; - static const char* const eventUp; - static const char* const eventEnter; - static const char* const eventValue; + ewol::object::Signal signalPressed; + ewol::object::Signal signalDown; + ewol::object::Signal signalUp; + ewol::object::Signal signalEnter; + ewol::object::Signal signalValue; private: ewol::object::Param m_shaper; //!< Compositing theme. bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)). diff --git a/sources/ewol/widget/ColorBar.cpp b/sources/ewol/widget/ColorBar.cpp index b4e28ae1..4ba95fa6 100644 --- a/sources/ewol/widget/ColorBar.cpp +++ b/sources/ewol/widget/ColorBar.cpp @@ -13,16 +13,12 @@ #include -const char * const ewol::widget::ColorBar::eventChange = "change"; - - - #undef __class__ #define __class__ "ColorBar" -ewol::widget::ColorBar::ColorBar() { +ewol::widget::ColorBar::ColorBar() : + signalChange(*this, "change", "Color value change") { addObjectType("ewol::widget::ColorBar"); - addEventId(eventChange); m_currentUserPos.setValue(0,0); m_currentColor = etk::color::black; setCanHaveFocus(true); @@ -224,7 +220,7 @@ bool ewol::widget::ColorBar::onEventInput(const ewol::event::Input& _event) { } if(m_currentColor != estimateColor) { m_currentColor = estimateColor; - generateEventId(eventChange); + signalChange.emit(m_currentColor); } return true; } diff --git a/sources/ewol/widget/ColorBar.h b/sources/ewol/widget/ColorBar.h index 5597771a..98a1f7ab 100644 --- a/sources/ewol/widget/ColorBar.h +++ b/sources/ewol/widget/ColorBar.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace ewol { @@ -21,7 +22,7 @@ namespace ewol { class ColorBar : public ewol::Widget { public: // Event list of properties - static const char * const eventChange; + ewol::object::Signal> signalChange; protected: ColorBar(); void init(); diff --git a/sources/ewol/widget/Composer.cpp b/sources/ewol/widget/Composer.cpp index 8adcbee2..ec41cc39 100644 --- a/sources/ewol/widget/Composer.cpp +++ b/sources/ewol/widget/Composer.cpp @@ -88,25 +88,3 @@ bool ewol::widget::Composer::loadFromString(const std::string& _composerXmlStrin requestUpdateSize(); return true; } - - -void ewol::widget::Composer::registerOnEventNameWidget(const std::string& _subWidgetName, - const char * _eventId, - const char * _eventIdgenerated, - const std::string& _overloadData) { - registerOnEventNameWidget(shared_from_this(), _subWidgetName, _eventId, _eventIdgenerated, _overloadData); -} - -void ewol::widget::Composer::registerOnEventNameWidget(const std::shared_ptr& _destinationObject, - const std::string& _subWidgetName, - const char * _eventId, - const char * _eventIdgenerated, - const std::string& _overloadData) { - std::shared_ptr tmpWidget = getWidgetNamed(_subWidgetName); - if (tmpWidget != nullptr) { - EWOL_DEBUG("Find widget named : \"" << _subWidgetName << "\" register event=\"" << _eventId << "\""); - tmpWidget->registerOnEvent(_destinationObject, _eventId, _eventIdgenerated, _overloadData); - } else { - EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Can not register event : \"" << _eventId << "\" the widget named=\"" << _subWidgetName << "\" does not exist"); - } -} diff --git a/sources/ewol/widget/Composer.h b/sources/ewol/widget/Composer.h index 1ab54df4..0ff53061 100644 --- a/sources/ewol/widget/Composer.h +++ b/sources/ewol/widget/Composer.h @@ -57,34 +57,6 @@ namespace ewol { * @return false == > some error occured */ bool loadFromString(const std::string& _composerXmlString); - protected: - /** - * @brief Register an Event an named widget. @see registerOnEvent - * @param[in] _subWidgetName Name of the subWidget. - * @param[in] _eventId Event generate inside the object. - * @param[in] _eventIdgenerated event generated when call the distant EObject.onReceiveMessage(...) - * @param[in] _overloadData When the user prever to receive a data specificly for this event ... - * @note : To used when herited from this object. - */ - void registerOnEventNameWidget(const std::string& _subWidgetName, - const char * _eventId, - const char * _eventIdgenerated = nullptr, - const std::string& _overloadData=""); - public: - /** - * @brief Register an Event an named widget. @see registerOnEvent - * @param[in] _destinationObject pointer on the object that might be call when an event is generated - * @param[in] _subWidgetName Name of the subWidget. - * @param[in] _eventId Event generate inside the object. - * @param[in] _eventIdgenerated event generated when call the distant EObject.onReceiveMessage(...) - * @param[in] _overloadData When the user prever to receive a data specificly for this event ... - * @note : To used when NOT herited from this object. - */ - void registerOnEventNameWidget(const std::shared_ptr& _destinationObject, - const std::string& _subWidgetName, - const char * _eventId, - const char * _eventIdgenerated = nullptr, - const std::string& _overloadData=""); }; }; }; diff --git a/sources/ewol/widget/Container.cpp b/sources/ewol/widget/Container.cpp index 8e8c071f..957c766c 100644 --- a/sources/ewol/widget/Container.cpp +++ b/sources/ewol/widget/Container.cpp @@ -64,13 +64,13 @@ void ewol::widget::Container::subWidgetUnLink() { m_subWidget.reset(); } -std::shared_ptr ewol::widget::Container::getWidgetNamed(const std::string& _widgetName) { - std::shared_ptr tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); - if (nullptr!=tmpUpperWidget) { - return tmpUpperWidget; +std::shared_ptr ewol::widget::Container::getSubObjectNamed(const std::string& _objectName) { + std::shared_ptr tmpObject = ewol::Widget::getSubObjectNamed(_objectName); + if (nullptr!=tmpObject) { + return tmpObject; } if (nullptr != m_subWidget) { - return m_subWidget->getWidgetNamed(_widgetName); + return m_subWidget->getSubObjectNamed(_objectName); } return nullptr; } diff --git a/sources/ewol/widget/Container.h b/sources/ewol/widget/Container.h index f5ab7078..90045a79 100644 --- a/sources/ewol/widget/Container.h +++ b/sources/ewol/widget/Container.h @@ -58,7 +58,7 @@ namespace ewol { virtual void calculateSize(const vec2& _availlable); virtual void calculateMinMaxSize(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); - virtual std::shared_ptr getWidgetNamed(const std::string& _widgetName); + virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); virtual bool loadXML(exml::Element* _node); virtual void setOffset(const vec2& _newVal); virtual void requestDestroyFromChild(const std::shared_ptr& _child); diff --git a/sources/ewol/widget/Container2.cpp b/sources/ewol/widget/Container2.cpp index 0a3b7088..36f27270 100644 --- a/sources/ewol/widget/Container2.cpp +++ b/sources/ewol/widget/Container2.cpp @@ -63,16 +63,19 @@ void ewol::widget::Container2::subWidgetUnLink(int32_t _idWidget) { m_subWidget[_idWidget].reset(); } -std::shared_ptr ewol::widget::Container2::getWidgetNamed(const std::string& _widgetName) { - std::shared_ptr tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); - if (tmpUpperWidget != nullptr) { - return tmpUpperWidget; +std::shared_ptr ewol::widget::Container2::getSubObjectNamed(const std::string& _widgetName) { + std::shared_ptr tmpObject = ewol::Widget::getSubObjectNamed(_widgetName); + if (tmpObject != nullptr) { + return tmpObject; } if (m_subWidget[0] != nullptr) { - return m_subWidget[0]->getWidgetNamed(_widgetName); + tmpObject = m_subWidget[0]->getSubObjectNamed(_widgetName); + if (tmpObject != nullptr) { + return tmpObject; + } } if (m_subWidget[1] != nullptr) { - return m_subWidget[1]->getWidgetNamed(_widgetName); + return m_subWidget[1]->getSubObjectNamed(_widgetName); } return nullptr; } diff --git a/sources/ewol/widget/Container2.h b/sources/ewol/widget/Container2.h index d34a7370..4930d5d4 100644 --- a/sources/ewol/widget/Container2.h +++ b/sources/ewol/widget/Container2.h @@ -161,7 +161,7 @@ namespace ewol { calculateMinMaxSizePadded(); } //virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); - virtual std::shared_ptr getWidgetNamed(const std::string& _widgetName); + virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); virtual bool loadXML(exml::Element* _node); virtual void setOffset(const vec2& _newVal); virtual void requestDestroyFromChild(const std::shared_ptr& _child); diff --git a/sources/ewol/widget/ContainerN.cpp b/sources/ewol/widget/ContainerN.cpp index 4ba1bb36..ef1452d3 100644 --- a/sources/ewol/widget/ContainerN.cpp +++ b/sources/ewol/widget/ContainerN.cpp @@ -138,16 +138,16 @@ void ewol::widget::ContainerN::subWidgetRemoveAllDelayed() { subWidgetRemoveAll(); } -std::shared_ptr ewol::widget::ContainerN::getWidgetNamed(const std::string& _widgetName) { - std::shared_ptr tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); - if (tmpUpperWidget != nullptr) { - return tmpUpperWidget; +std::shared_ptr ewol::widget::ContainerN::getSubObjectNamed(const std::string& _objectName) { + std::shared_ptr tmpObject = ewol::Widget::getSubObjectNamed(_objectName); + if (tmpObject != nullptr) { + return tmpObject; } for (auto &it : m_subWidget) { if (it != nullptr) { - std::shared_ptr tmpWidget = it->getWidgetNamed(_widgetName); - if (tmpWidget != nullptr) { - return tmpWidget; + tmpObject = it->getSubObjectNamed(_objectName); + if (tmpObject != nullptr) { + return tmpObject; } } } diff --git a/sources/ewol/widget/ContainerN.h b/sources/ewol/widget/ContainerN.h index 4b84449e..2a7e6845 100644 --- a/sources/ewol/widget/ContainerN.h +++ b/sources/ewol/widget/ContainerN.h @@ -94,7 +94,7 @@ namespace ewol { virtual void calculateSize(const vec2& _availlable); virtual void calculateMinMaxSize(); virtual std::shared_ptr getWidgetAtPos(const vec2& _pos); - virtual std::shared_ptr getWidgetNamed(const std::string& _widgetName); + virtual std::shared_ptr getSubObjectNamed(const std::string& _objectName); virtual bool loadXML(exml::Element* _node); virtual void setOffset(const vec2& _newVal); virtual void requestDestroyFromChild(const std::shared_ptr& _child); diff --git a/sources/ewol/widget/Entry.cpp b/sources/ewol/widget/Entry.cpp index 4e9bb379..b3c5262e 100644 --- a/sources/ewol/widget/Entry.cpp +++ b/sources/ewol/widget/Entry.cpp @@ -13,14 +13,6 @@ #include #include - -const char * const ewolEventEntryCut = "ewol-widget-entry-event-internal-cut"; -const char * const ewolEventEntryCopy = "ewol-widget-entry-event-internal-copy"; -const char * const ewolEventEntryPaste = "ewol-widget-entry-event-internal-paste"; -const char * const ewolEventEntryClean = "ewol-widget-entry-event-internal-clean"; -const char * const ewolEventEntrySelect = "ewol-widget-entry-event-internal-select"; - - #undef __class__ #define __class__ "Entry" @@ -29,11 +21,10 @@ const char * const ewolEventEntrySelect = "ewol-widget-entry-event-internal-sele #define STATUS_HOVER (1) #define STATUS_SELECTED (2) -const char * const ewol::widget::Entry::eventClick = "click"; -const char * const ewol::widget::Entry::eventEnter = "enter"; -const char * const ewol::widget::Entry::eventModify = "modify"; - ewol::widget::Entry::Entry() : + signalClick(*this, "click", "the user Click on the Entry box"), + signalEnter(*this, "enter", "The cursor enter inside the button"), + signalModify(*this, "modify", "Entry box value change"), m_shaper(*this, "shaper", "Shaper to display the background"), m_data(*this, "value", "", "Value display in the entry (decorated text)"), m_maxCharacter(*this, "max", 0x7FFFFFFF, 0, 0x7FFFFFFF, "Maximum cgar that can be set on the Entry"), @@ -45,25 +36,24 @@ ewol::widget::Entry::Entry() : m_displayCursorPosSelection(0), m_textWhenNothing(*this, "emptytext", "", "Text that is displayed when the Entry is empty (decorated text)") { addObjectType("ewol::widget::Entry"); - setCanHaveFocus(true); - addEventId(eventClick); - addEventId(eventEnter); - addEventId(eventModify); - shortCutAdd("ctrl+w", ewolEventEntryClean); - shortCutAdd("ctrl+x", ewolEventEntryCut); - shortCutAdd("ctrl+c", ewolEventEntryCopy); - shortCutAdd("ctrl+v", ewolEventEntryPaste); - shortCutAdd("ctrl+a", ewolEventEntrySelect, "ALL"); - shortCutAdd("ctrl+shift+a", ewolEventEntrySelect, "NONE"); - m_regExp.setString(".*"); - markToRedraw(); } - void ewol::widget::Entry::init(const std::string& _newData) { ewol::Widget::init(); m_data.set(_newData); m_shaper.setString("THEME:GUI:Entry.json"); + setCanHaveFocus(true); + m_regExp.setString(".*"); + m_regExp.get().setMaximize(true); + markToRedraw(); + + shortCutAdd("ctrl+w", "clean"); + shortCutAdd("ctrl+x", "cut"); + shortCutAdd("ctrl+c", "copy"); + shortCutAdd("ctrl+v", "paste"); + shortCutAdd("ctrl+a", "select:all"); + shortCutAdd("ctrl+shift+a", "select:none"); + signalShortcut.bind(shared_from_this(), &ewol::widget::Entry::onCallbackShortCut); } @@ -71,6 +61,24 @@ ewol::widget::Entry::~Entry() { } +void ewol::widget::Entry::onCallbackShortCut(const std::string& _value) { + if (_value == "clean") { + onCallbackEntryClean(); + } else if (_value == "cut") { + onCallbackCut(); + } else if (_value == "copy") { + onCallbackCopy(); + } else if (_value == "paste") { + onCallbackPaste(); + } else if (_value == "select:all") { + onCallbackSelect(true); + } else if (_value == "select:none") { + onCallbackSelect(false); + } else { + EWOL_WARNING("Unknow event from ShortCut : " << _value); + } +} + void ewol::widget::Entry::calculateMinMaxSize() { // call main class ewol::Widget::calculateMinMaxSize(); @@ -244,7 +252,7 @@ bool ewol::widget::Entry::onEventInput(const ewol::event::Input& _event) { if (1 == _event.getId()) { if (ewol::key::statusSingle == _event.getStatus()) { keepFocus(); - generateEventId(eventClick); + signalClick.emit(); //nothing to do ... return true; } else if (ewol::key::statusDouble == _event.getStatus()) { @@ -335,13 +343,11 @@ bool ewol::widget::Entry::onEventInput(const ewol::event::Input& _event) { bool ewol::widget::Entry::onEventEntry(const ewol::event::Entry& _event) { if (_event.getType() == ewol::key::keyboardChar) { if(_event.getStatus() == ewol::key::statusDown) { - //EWOL_DEBUG("Entry input data ... : \"" << unicodeData << "\" " ); - //return GenEventInputExternal(eventEnter, -1, -1); // remove curent selected data ... removeSelected(); if( _event.getChar() == '\n' || _event.getChar() == '\r') { - generateEventId(eventEnter, m_data); + signalEnter.emit(m_data); return true; } else if (_event.getChar() == 0x7F) { // SUPPR : @@ -371,7 +377,7 @@ bool ewol::widget::Entry::onEventEntry(const ewol::event::Entry& _event) { } } } - generateEventId(eventModify, m_data); + signalModify.emit(m_data); markToRedraw(); return true; } @@ -408,7 +414,7 @@ void ewol::widget::Entry::setInternalValue(const std::string& _newData) { std::string previous = m_data; // check the RegExp : if (_newData.size()>0) { - if (false == m_regExp->processOneElement(_newData,0,_newData.size()) ) { + if (false == m_regExp->parse(_newData,0,_newData.size()) ) { EWOL_INFO("the input data does not match with the regExp \"" << _newData << "\" RegExp=\"" << m_regExp->getRegExp() << "\" start=" << m_regExp->start() << " stop=" << m_regExp->stop() ); return; } @@ -443,35 +449,39 @@ void ewol::widget::Entry::onEventClipboard(enum ewol::context::clipBoard::clipbo markToRedraw(); } } - generateEventId(eventModify, m_data); + signalModify.emit(m_data); } +void ewol::widget::Entry::onCallbackEntryClean() { + m_data = ""; + m_displayStartPosition = 0; + m_displayCursorPos = 0; + m_displayCursorPosSelection = m_displayCursorPos; + markToRedraw(); +} -void ewol::widget::Entry::onReceiveMessage(const ewol::object::Message& _msg) { - ewol::Widget::onReceiveMessage(_msg); - if(_msg.getMessage() == ewolEventEntryClean) { - m_data = ""; - m_displayStartPosition = 0; - m_displayCursorPos = 0; +void ewol::widget::Entry::onCallbackCut() { + copySelectionToClipBoard(ewol::context::clipBoard::clipboardStd); + removeSelected(); + signalModify.emit(m_data); +} + +void ewol::widget::Entry::onCallbackCopy() { + copySelectionToClipBoard(ewol::context::clipBoard::clipboardStd); +} + +void ewol::widget::Entry::onCallbackPaste() { + ewol::context::clipBoard::request(ewol::context::clipBoard::clipboardStd); +} + +void ewol::widget::Entry::onCallbackSelect(bool _all) { + if(_all == true) { + m_displayCursorPosSelection = 0; + m_displayCursorPos = m_data->size(); + } else { m_displayCursorPosSelection = m_displayCursorPos; - markToRedraw(); - } else if(_msg.getMessage() == ewolEventEntryCut) { - copySelectionToClipBoard(ewol::context::clipBoard::clipboardStd); - removeSelected(); - generateEventId(eventModify, m_data); - } else if(_msg.getMessage() == ewolEventEntryCopy) { - copySelectionToClipBoard(ewol::context::clipBoard::clipboardStd); - } else if(_msg.getMessage() == ewolEventEntryPaste) { - ewol::context::clipBoard::request(ewol::context::clipBoard::clipboardStd); - } else if(_msg.getMessage() == ewolEventEntrySelect) { - if(_msg.getData() == "ALL") { - m_displayCursorPosSelection = 0; - m_displayCursorPos = m_data->size(); - } else { - m_displayCursorPosSelection = m_displayCursorPos; - } - markToRedraw(); } + markToRedraw(); } void ewol::widget::Entry::markToUpdateTextPosition() { diff --git a/sources/ewol/widget/Entry.h b/sources/ewol/widget/Entry.h index 93024b50..f486d0f9 100644 --- a/sources/ewol/widget/Entry.h +++ b/sources/ewol/widget/Entry.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -33,10 +34,9 @@ namespace ewol { */ class Entry : public ewol::Widget { public: - // Event list of properties - static const char * const eventClick; - static const char * const eventEnter; - static const char * const eventModify; // return in the data the new string inside it ... + ewol::object::Signal signalClick; //!< bang on click the entry box + ewol::object::Signal signalEnter; //!< Enter key is pressed + ewol::object::Signal signalModify; //!< data change private: ewol::object::Param m_shaper; int32_t m_colorIdTextFg; //!< color property of the text foreground @@ -166,7 +166,6 @@ namespace ewol { virtual void onRegenerateDisplay(); virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventEntry(const ewol::event::Entry& _event); - virtual void onReceiveMessage(const ewol::object::Message& _msg); virtual void onEventClipboard(enum ewol::context::clipBoard::clipboardListe _clipboardID); virtual void calculateMinMaxSize(); protected: // Derived function @@ -176,6 +175,13 @@ namespace ewol { virtual void changeStatusIn(int32_t _newStatusId); virtual void periodicCall(const ewol::event::Time& _event); virtual void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer); + private: // callback functions + void onCallbackShortCut(const std::string& _value); + void onCallbackEntryClean(); + void onCallbackCut(); + void onCallbackCopy(); + void onCallbackPaste(); + void onCallbackSelect(bool _all); }; }; }; diff --git a/sources/ewol/widget/Image.cpp b/sources/ewol/widget/Image.cpp index 45b70b42..919dd241 100644 --- a/sources/ewol/widget/Image.cpp +++ b/sources/ewol/widget/Image.cpp @@ -16,9 +16,8 @@ #undef __class__ #define __class__ "Image" -const char * const ewol::widget::Image::eventPressed = "pressed"; - ewol::widget::Image::Image() : + signalPressed(*this, "pressed", "Image is pressed"), m_colorProperty(nullptr), m_colorId(-1), m_fileName(*this, "src", "", "Image source path"), @@ -29,7 +28,6 @@ ewol::widget::Image::Image() : m_posStop(*this, "part-stop", vec2(1.0f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 1.0f), "Start display position in the image"), m_distanceFieldMode(*this, "distance-field", false, "Distance field mode") { addObjectType("ewol::widget::Image"); - addEventId(eventPressed); m_colorProperty = ewol::resource::ColorFile::create("THEME:COLOR:Image.json"); if (m_colorProperty != nullptr) { m_colorId = m_colorProperty->request("foreground"); @@ -135,7 +133,7 @@ bool ewol::widget::Image::onEventInput(const ewol::event::Input& _event) { //EWOL_DEBUG("Event on BT ..."); if (1 == _event.getId()) { if(ewol::key::statusSingle == _event.getStatus()) { - generateEventId(eventPressed); + signalPressed.emit(); return true; } } diff --git a/sources/ewol/widget/Image.h b/sources/ewol/widget/Image.h index df2a07d7..0954722e 100644 --- a/sources/ewol/widget/Image.h +++ b/sources/ewol/widget/Image.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -25,7 +26,7 @@ namespace ewol { class Image :public ewol::Widget { public: // Event list of properties - static const char * const eventPressed; + ewol::object::Signal signalPressed; protected: ewol::compositing::Image m_compositing; //!< compositing element of the image. std::shared_ptr m_colorProperty; //!< theme color property diff --git a/sources/ewol/widget/Joystick.cpp b/sources/ewol/widget/Joystick.cpp index 73fd63a6..b4be3bea 100644 --- a/sources/ewol/widget/Joystick.cpp +++ b/sources/ewol/widget/Joystick.cpp @@ -12,10 +12,6 @@ #include #include -const char * const ewol::widget::Joystick::eventEnable = "enable"; -const char * const ewol::widget::Joystick::eventDisable = "disable"; -const char * const ewol::widget::Joystick::eventMove = "move"; - static bool l_displayBackground(true); static std::string l_background(""); static std::string l_foreground(""); @@ -24,11 +20,11 @@ static float l_ratio(1.0/7.0); #undef __class__ #define __class__ "Joystick" -ewol::widget::Joystick::Joystick() { +ewol::widget::Joystick::Joystick() : + signalEnable(*this, "enable"), + signalDisable(*this, "disable"), + signalMove(*this, "move") { addObjectType("ewol::widget::Joystick"); - addEventId(eventEnable); - addEventId(eventDisable); - addEventId(eventMove); // by default the joy does not lock when free out m_lock = false; m_displayMode = modeNormal; @@ -148,10 +144,10 @@ bool ewol::widget::Joystick::onEventInput(const ewol::event::Input& _event) { } markToRedraw(); if(ewol::key::statusDown == typeEvent) { - generateEventId(eventEnable); + signalEnable.emit(); } else { std::string tmp = std::string("distance=") + std::string(m_distance) + std::string("angle=") + std::string(m_angle+M_PI/2); - generateEventId(eventMove, tmp); + signalMove.emit(m_angle+M_PI/2); } //teta += M_PI/2; //EWOL_DEBUG("TETA = " << (m_angle*180/M_PI) << " deg distance = " << m_distance); @@ -167,7 +163,7 @@ bool ewol::widget::Joystick::onEventInput(const ewol::event::Input& _event) { m_distance = 0; } markToRedraw(); - generateEventId(eventDisable); + signalDisable.emit(); return true; } return false; diff --git a/sources/ewol/widget/Joystick.h b/sources/ewol/widget/Joystick.h index 5ead150b..a5cbff2d 100644 --- a/sources/ewol/widget/Joystick.h +++ b/sources/ewol/widget/Joystick.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace ewol { @@ -23,9 +24,9 @@ namespace ewol { class Joystick :public ewol::Widget { public: // Event list of properties - static const char * const eventEnable; - static const char * const eventDisable; - static const char * const eventMove; + ewol::object::Signal signalEnable; + ewol::object::Signal signalDisable; + ewol::object::Signal signalMove; public: enum joystickMode { modeNormal, @@ -34,7 +35,7 @@ namespace ewol { private: draw::Color m_colorFg; //!< Forground color draw::Color m_colorBg; //!< Background color - vec2 m_displayPos; //!< direction of the cursor ... + vec2 m_displayPos; //!< direction of the cursor ... float m_distance; //!< dintance from the center float m_angle; //!< angle of the arraw (if < 0 : No arraw...) 0 is the TOP ... bool m_lock; //!< flag to mark the lock when the cursor is free when we are outside the circle diff --git a/sources/ewol/widget/Label.cpp b/sources/ewol/widget/Label.cpp index 46424a74..c0e14fa9 100644 --- a/sources/ewol/widget/Label.cpp +++ b/sources/ewol/widget/Label.cpp @@ -15,10 +15,9 @@ #undef __class__ #define __class__ "Label" -const char * const ewol::widget::Label::eventPressed = "pressed"; - // TODO : Remove the label name in the constructor ... ewol::widget::Label::Label() : + signalPressed(*this, "pressed"), m_label(*this, "value", U"", "displayed value string"), m_colorProperty(nullptr), m_colorDefaultFgText(-1), @@ -29,7 +28,6 @@ ewol::widget::Label::Label() : m_colorDefaultFgText = m_colorProperty->request("foreground"); m_colorDefaultBgText = m_colorProperty->request("background"); } - addEventId(eventPressed); setCanHaveFocus(false); setMouseLimit(1); } @@ -126,7 +124,7 @@ bool ewol::widget::Label::onEventInput(const ewol::event::Input& _event) { if (1 == _event.getId()) { if (ewol::key::statusSingle == _event.getStatus()) { // nothing to do ... - generateEventId(eventPressed); + signalPressed.emit(); return true; } } diff --git a/sources/ewol/widget/Label.h b/sources/ewol/widget/Label.h index f1d9f887..3ee63a80 100644 --- a/sources/ewol/widget/Label.h +++ b/sources/ewol/widget/Label.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -24,7 +25,7 @@ namespace ewol { class Label : public ewol::Widget { public: // Event list of properties - static const char * const eventPressed; + ewol::object::Signal signalPressed; private: ewol::compositing::Text m_text; //!< Compositing text element. ewol::object::Param m_label; //!< decorated text to display. diff --git a/sources/ewol/widget/ListFileSystem.cpp b/sources/ewol/widget/ListFileSystem.cpp index 31b35f09..61f60a41 100644 --- a/sources/ewol/widget/ListFileSystem.cpp +++ b/sources/ewol/widget/ListFileSystem.cpp @@ -15,13 +15,11 @@ #undef __class__ #define __class__ "ListFileSystem" -const char * const ewol::widget::ListFileSystem::eventFileSelect = "file-select"; -const char * const ewol::widget::ListFileSystem::eventFileValidate = "file-validate"; -const char * const ewol::widget::ListFileSystem::eventFolderSelect = "folder-select"; -const char * const ewol::widget::ListFileSystem::eventFolderValidate = "folder-validate"; - - ewol::widget::ListFileSystem::ListFileSystem() : + signalFileSelect(*this, "file-select"), + signalFileValidate(*this, "file-validate"), + signalFolderSelect(*this, "folder-select"), + signalFolderValidate(*this, "folder-validate"), m_selectedLine(-1), m_folder(*this, "path", "/", "Path to display"), m_selectFile(*this, "select", "", "selection af a specific file"), @@ -40,11 +38,6 @@ ewol::widget::ListFileSystem::ListFileSystem() : m_colorIdBackground2 = m_colorProperty->request("background2"); m_colorIdBackgroundSelected = m_colorProperty->request("selected"); } - addEventId(eventFileSelect); - addEventId(eventFileValidate); - addEventId(eventFolderSelect); - addEventId(eventFolderValidate); - setMouseLimit(1); }; @@ -180,7 +173,7 @@ bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput, } } if (_typeEvent == ewol::key::statusSingle) { - EWOL_DEBUG("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw ); + EWOL_VERBOSE("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw ); if (1 == _IdInput) { int32_t previousRaw = m_selectedLine; if (_raw > (int32_t)m_list.size()+offset ) { @@ -192,21 +185,21 @@ bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput, if( m_showFolder == true && m_selectedLine == 0) { // "." folder - generateEventId(eventFolderSelect, "."); + signalFolderSelect.emit("."); } else if ( m_showFolder == true && m_selectedLine == 1) { // ".." folder - generateEventId(eventFolderSelect, ".."); + signalFolderSelect.emit(".."); } else if( m_selectedLine-offset >= 0 && m_selectedLine-offset < (int32_t)m_list.size() && nullptr != m_list[m_selectedLine-offset] ) { // generate event extern : switch(m_list[m_selectedLine-offset]->getNodeType()) { case etk::FSN_FILE : - generateEventId(eventFileSelect, m_list[m_selectedLine-offset]->getNameFile()); + signalFileSelect.emit(m_list[m_selectedLine-offset]->getNameFile()); break; case etk::FSN_FOLDER : - generateEventId(eventFolderSelect, m_list[m_selectedLine-offset]->getNameFile()); + signalFolderSelect.emit(m_list[m_selectedLine-offset]->getNameFile()); break; default: EWOL_ERROR("Can not generate event on an unknow type"); @@ -217,21 +210,20 @@ bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput, if( m_showFolder == true && m_selectedLine == 0) { // "." folder - generateEventId(eventFolderValidate, "."); + signalFolderValidate.emit("."); } else if ( m_showFolder == true && m_selectedLine == 1) { // ".." folder - generateEventId(eventFolderValidate, ".."); + signalFolderValidate.emit(".."); } else if( m_selectedLine-offset >= 0 && m_selectedLine-offset < (int32_t)m_list.size() && nullptr != m_list[m_selectedLine-offset] ) { - switch(m_list[m_selectedLine-offset]->getNodeType()) - { + switch(m_list[m_selectedLine-offset]->getNodeType()) { case etk::FSN_FILE : - generateEventId(eventFileValidate, m_list[m_selectedLine-offset]->getNameFile()); + signalFileValidate.emit(m_list[m_selectedLine-offset]->getNameFile()); break; case etk::FSN_FOLDER : - generateEventId(eventFolderValidate, m_list[m_selectedLine-offset]->getNameFile()); + signalFolderValidate.emit(m_list[m_selectedLine-offset]->getNameFile()); break; default: EWOL_ERROR("Can not generate event on an unknow type"); diff --git a/sources/ewol/widget/ListFileSystem.h b/sources/ewol/widget/ListFileSystem.h index 3de039bf..49ce10f5 100644 --- a/sources/ewol/widget/ListFileSystem.h +++ b/sources/ewol/widget/ListFileSystem.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -21,10 +22,10 @@ namespace ewol { class ListFileSystem : public ewol::widget::List { public: // Event list of properties - static const char * const eventFileSelect; //!< @event "file-select" Generated when a file is selected. - static const char * const eventFileValidate; //!< @event "file-validate" Generate when the user validate (return) or double click on the element - static const char * const eventFolderSelect; - static const char * const eventFolderValidate; + ewol::object::Signal signalFileSelect; //!< @event "file-select" Generated when a file is selected. + ewol::object::Signal signalFileValidate; //!< @event "file-validate" Generate when the user validate (return) or double click on the element + ewol::object::Signal signalFolderSelect; + ewol::object::Signal signalFolderValidate; protected: ListFileSystem(); void init(); diff --git a/sources/ewol/widget/Manager.h b/sources/ewol/widget/Manager.h index 60e02d71..1e8fce03 100644 --- a/sources/ewol/widget/Manager.h +++ b/sources/ewol/widget/Manager.h @@ -14,7 +14,6 @@ #include #include #include -#include namespace ewol { namespace widget { diff --git a/sources/ewol/widget/Menu.cpp b/sources/ewol/widget/Menu.cpp index 94d310c5..b1cb7936 100644 --- a/sources/ewol/widget/Menu.cpp +++ b/sources/ewol/widget/Menu.cpp @@ -18,9 +18,10 @@ #undef __class__ #define __class__ "Menu" -ewol::widget::Menu::Menu() { +ewol::widget::Menu::Menu() : + signalSelect(*this, "select") { addObjectType("ewol::widget::Menu"); - m_staticId = 0; + m_staticId = 666; } void ewol::widget::Menu::init() { @@ -53,24 +54,37 @@ void ewol::widget::Menu::clear() { m_listElement.clear(); } -int32_t ewol::widget::Menu::addTitle(std::string _label, - std::string _image, - const char * _generateEvent, - const std::string _message) { - return add(-1, _label, _image, _generateEvent, _message); +int32_t ewol::widget::Menu::addTitle(const std::string& _label, + const std::string& _image, + const std::string& _message) { + return add(-1, _label, _image, _message); +} + +static const char* eventButtonPressed = "menu-local-pressed"; + +int32_t ewol::widget::Menu::get(const std::string& _label) { + for (auto &it : m_listElement) { + if (it.m_label == _label) { + return it.m_localId; + } + } + return -1; } int32_t ewol::widget::Menu::add(int32_t _parent, - std::string _label, - std::string _image, - const char *_generateEvent, - const std::string _message) { + const std::string& _label, + const std::string& _image, + const std::string& _message) { + // try to find one already created : + int32_t previous = get(_label); + if (previous != -1) { + return previous; + } ewol::widget::MenuElement tmpObject; tmpObject.m_localId = m_staticId++; tmpObject.m_parentId = _parent; - tmpObject.m_label = std::string("") + _label + ""; + tmpObject.m_label = _label; tmpObject.m_image = _image; - tmpObject.m_generateEvent = _generateEvent; tmpObject.m_message = _message; if (-1 == tmpObject.m_parentId) { std::shared_ptr myButton = ewol::widget::Button::create(); @@ -85,155 +99,156 @@ int32_t ewol::widget::Menu::add(int32_t _parent, } else { composeString+=" \n"; } - composeString+=" \n"; + composeString+=" \n"; composeString+="\n"; myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, composeString)); } else { - myButton->setSubWidget(ewol::widget::Label::create(tmpObject.m_label) ); + myButton->setSubWidget(ewol::widget::Label::create("" + tmpObject.m_label + "") ); } - // add it in the widget list ewol::widget::Sizer::subWidgetAdd(myButton); // keep the specific event ... - myButton->registerOnEvent(shared_from_this(), ewol::widget::Button::eventPressed, widget::Button::eventPressed); + myButton->signalPressed.connect(shared_from_this(), std::bind(&ewol::widget::Menu::onButtonPressed, this, std::weak_ptr(myButton))); tmpObject.m_widgetPointer = myButton; } m_listElement.push_back(tmpObject); return tmpObject.m_localId; } -void ewol::widget::Menu::addSpacer() { - EWOL_TODO("NOT now..."); +void ewol::widget::Menu::remove(int32_t _id) { + EWOL_TODO("NOT remove..."); } -void ewol::widget::Menu::onReceiveMessage(const ewol::object::Message& _msg) { - /* - if (true == ewol::sizer::onReceiveMessage(_msg) { - return true; +int32_t ewol::widget::Menu::addSpacer() { + EWOL_TODO("NOT addSpacer..."); + return -1; +} + +void ewol::widget::Menu::onButtonPressed(std::weak_ptr _button) { + std::shared_ptr caller = _button.lock(); + if (caller == nullptr) { + return; } - */ - EWOL_ERROR(" receive message : " << _msg); - if (_msg.getMessage() == ewol::widget::Button::eventPressed) { - for (auto &it : m_listElement) { - if (_msg.getCaller() == it.m_widgetPointer.lock()) { - // 2 posible case (have a message or have a child ... - if (it.m_generateEvent != nullptr) { - EWOL_DEBUG("Menu == > generate Event"); - // Send a multicast event ... - sendMultiCast(it.m_generateEvent, it.m_message); - std::shared_ptr tmpContext = m_widgetContextMenu.lock(); - if (tmpContext != nullptr) { - EWOL_DEBUG("Mark the menu to remove ..."); - tmpContext->destroy(); - } - return; - } else{ - EWOL_DEBUG("Menu == > load Sub Menu"); - bool findChild = false; - for (auto &it2 : m_listElement) { - if (it.m_localId == it2.m_parentId) { - findChild = true; - break; - } - } - if (false == findChild) { - EWOL_WARNING("Event on menu element with no child an no event... label=" << it.m_label); - return; - } - // create a context menu : - std::shared_ptr tmpContext = ewol::widget::ContextMenu::create(); - m_widgetContextMenu = tmpContext; - if (tmpContext == nullptr) { - EWOL_ERROR("Allocation Error"); - return; - } - // get the button widget : - vec2 newPosition; - std::shared_ptr eventFromWidget = std::dynamic_pointer_cast(_msg.getCaller()); - if (eventFromWidget != nullptr) { - vec2 tmpOri = eventFromWidget->getOrigin(); - vec2 tmpSize = eventFromWidget->getSize(); - // calculate the correct position - newPosition.setValue(tmpOri.x() + tmpSize.x()/2, - tmpOri.y() ); - } - tmpContext->setPositionMark(ewol::widget::ContextMenu::markTop, newPosition ); - - std::shared_ptr mySizer; - std::shared_ptr myButton; - - mySizer = ewol::widget::Sizer::create(widget::Sizer::modeVert); - if (nullptr != mySizer) { - mySizer->lockExpand(vec2(true,true)); - // set it in the pop-up-system : - tmpContext->setSubWidget(mySizer); - - bool menuHaveImage = false; - for (auto &it2 : m_listElement) { - if (it.m_localId == it2.m_parentId) { - if (it2.m_image.size()!=0) { - menuHaveImage = true; - break; - } - } - } - for (auto it2=m_listElement.rbegin(); it2!=m_listElement.rend() ; ++it2) { - if (it.m_localId == it2->m_parentId) { - myButton = ewol::widget::Button::create(); - if (myButton == nullptr) { - EWOL_ERROR("Allocation Error"); - } else { - if (it2->m_image.size()!=0) { - std::string composeString = "\n"; - composeString+= " \n"; - if (etk::end_with(it2->m_image, ".edf") == true) { - composeString+=" m_image + "\" size=\"8,8mm\" distance-field='true'/>\n"; - } else { - composeString+=" m_image + "\" size=\"8,8mm\"/>\n"; - } - composeString+=" \n"; - composeString+=" \n"; - composeString+="\n"; - myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, composeString)); - } else { - if (true == menuHaveImage) { - myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, - std::string("\n") + - " \n" - " \n" - " \n" - " \n" - "\n")); - } else { - std::shared_ptr tmpLabel = widget::Label::create(std::string("") + it2->m_label + "\n"); - if (tmpLabel != nullptr) { - tmpLabel->setExpand(bvec2(true,false)); - tmpLabel->setFill(bvec2(true,true)); - myButton->setSubWidget(tmpLabel); - } - } - } - // set the image if one is present ... - myButton->registerOnEvent(shared_from_this(), ewol::widget::Button::eventPressed, widget::Button::eventPressed); - myButton->setExpand(bvec2(true,false)); - myButton->setFill(bvec2(true,false)); - // add it in the widget list - mySizer->subWidgetAdd(myButton); - it2->m_widgetPointer = myButton; - } - } - } - } - std::shared_ptr currentWindows = getWindows(); - if (currentWindows == nullptr) { - EWOL_ERROR("Can not get the curent Windows..."); - } else { - currentWindows->popUpWidgetPush(tmpContext); - } + for (auto &it : m_listElement) { + if (caller == it.m_widgetPointer.lock()) { + // 2 posible case (have a message or have a child ... + if (it.m_message.size() > 0) { + EWOL_DEBUG("Menu == > generate Event"); + // Send a multicast event ... + signalSelect.emit(it.m_message); + std::shared_ptr tmpContext = m_widgetContextMenu.lock(); + if (tmpContext != nullptr) { + EWOL_DEBUG("Mark the menu to remove ..."); + tmpContext->destroy(); } return; + } else{ + EWOL_DEBUG("Menu == > load Sub Menu"); + bool findChild = false; + for (auto &it2 : m_listElement) { + if (it.m_localId == it2.m_parentId) { + findChild = true; + break; + } + } + if (false == findChild) { + EWOL_WARNING("Event on menu element with no child an no event... label=" << it.m_label); + return; + } + // create a context menu : + std::shared_ptr tmpContext = ewol::widget::ContextMenu::create(); + m_widgetContextMenu = tmpContext; + if (tmpContext == nullptr) { + EWOL_ERROR("Allocation Error"); + return; + } + // get the button widget : + vec2 newPosition; + std::shared_ptr eventFromWidget = std::dynamic_pointer_cast(caller); + if (eventFromWidget != nullptr) { + vec2 tmpOri = eventFromWidget->getOrigin(); + vec2 tmpSize = eventFromWidget->getSize(); + // calculate the correct position + newPosition.setValue(tmpOri.x() + tmpSize.x()/2, + tmpOri.y() ); + } + tmpContext->setPositionMark(ewol::widget::ContextMenu::markTop, newPosition ); + + std::shared_ptr mySizer; + std::shared_ptr myButton; + + mySizer = ewol::widget::Sizer::create(widget::Sizer::modeVert); + if (nullptr != mySizer) { + mySizer->lockExpand(vec2(true,true)); + // set it in the pop-up-system : + tmpContext->setSubWidget(mySizer); + + bool menuHaveImage = false; + for (auto &it2 : m_listElement) { + if (it.m_localId == it2.m_parentId) { + if (it2.m_image.size()!=0) { + menuHaveImage = true; + break; + } + } + } + for (auto it2=m_listElement.rbegin(); it2!=m_listElement.rend() ; ++it2) { + if (it.m_localId == it2->m_parentId) { + myButton = ewol::widget::Button::create(); + if (myButton == nullptr) { + EWOL_ERROR("Allocation Error"); + } else { + if (it2->m_image.size()!=0) { + std::string composeString = "\n"; + composeString+= " \n"; + if (etk::end_with(it2->m_image, ".edf") == true) { + composeString+=" m_image + "\" size=\"8,8mm\" distance-field='true'/>\n"; + } else { + composeString+=" m_image + "\" size=\"8,8mm\"/>\n"; + } + composeString+=" \n"; + composeString+=" \n"; + composeString+="\n"; + myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, composeString)); + } else { + if (true == menuHaveImage) { + myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, + std::string("\n") + + " \n" + " \n" + " \n" + " \n" + "\n")); + } else { + std::shared_ptr tmpLabel = widget::Label::create(std::string("") + it2->m_label + "\n"); + if (tmpLabel != nullptr) { + tmpLabel->setExpand(bvec2(true,false)); + tmpLabel->setFill(bvec2(true,true)); + myButton->setSubWidget(tmpLabel); + } + } + } + // set the image if one is present ... + //myButton->registerOnEvent(shared_from_this(), "pressed", eventButtonPressed); + myButton->signalPressed.connect(shared_from_this(), std::bind(&ewol::widget::Menu::onButtonPressed, this, std::weak_ptr(myButton))); + myButton->setExpand(bvec2(true,false)); + myButton->setFill(bvec2(true,false)); + // add it in the widget list + mySizer->subWidgetAdd(myButton); + it2->m_widgetPointer = myButton; + } + } + } + } + std::shared_ptr currentWindows = getWindows(); + if (currentWindows == nullptr) { + EWOL_ERROR("Can not get the curent Windows..."); + } else { + currentWindows->popUpWidgetPush(tmpContext); + } } + return; } } } diff --git a/sources/ewol/widget/Menu.h b/sources/ewol/widget/Menu.h index eeb67f53..b0fce18e 100644 --- a/sources/ewol/widget/Menu.h +++ b/sources/ewol/widget/Menu.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -26,13 +27,14 @@ namespace ewol { std::weak_ptr m_widgetPointer; std::string m_label; std::string m_image; - const char* m_generateEvent; std::string m_message; }; /** * @ingroup ewolWidgetGroup */ class Menu :public ewol::widget::Sizer { + public: + ewol::object::Signal signalSelect; // event on a menu button or ... protected: Menu(); void init(); @@ -48,13 +50,15 @@ namespace ewol { std::vector m_listElement; int32_t m_staticId; // unique ID for every element of the menu ... std::weak_ptr m_widgetContextMenu; + int32_t get(const std::string& _label); public: void clear(); - int32_t addTitle(std::string _label, std::string _image="", const char * _generateEvent = nullptr, const std::string _message = ""); - int32_t add(int32_t _parent, std::string _label, std::string _image="", const char * _generateEvent = nullptr, const std::string _message = ""); - void addSpacer(); - // Derived function - virtual void onReceiveMessage(const ewol::object::Message& _msg); + int32_t addTitle(const std::string& _label, const std::string& _image="", const std::string& _message = ""); + int32_t add(int32_t _parent, const std::string& _label, const std::string& _image="", const std::string& _message = ""); + int32_t addSpacer(); + void remove(int32_t _id); + private: + void onButtonPressed(std::weak_ptr _button); }; }; }; diff --git a/sources/ewol/widget/Slider.cpp b/sources/ewol/widget/Slider.cpp index 0395da27..9b1cb3fc 100644 --- a/sources/ewol/widget/Slider.cpp +++ b/sources/ewol/widget/Slider.cpp @@ -10,16 +10,14 @@ #include -const char * const ewol::widget::Slider::eventChange = "change"; - #undef __class__ #define __class__ "Slider" const int32_t dotRadius = 6; -ewol::widget::Slider::Slider() { +ewol::widget::Slider::Slider() : + signalChange(*this, "change") { addObjectType("ewol::widget::Slider"); - addEventId(eventChange); m_value = 0; m_min = 0; @@ -109,7 +107,7 @@ bool ewol::widget::Slider::onEventInput(const ewol::event::Input& _event) { m_value = std::max(std::min(m_value, m_max), m_min); if (oldValue != m_value) { EWOL_DEBUG(" new value : " << m_value << " in [" << m_min << ".." << m_max << "]"); - generateEventId(eventChange, etk::to_string(m_value)); + signalChange.emit(m_value); markToRedraw(); } return true; diff --git a/sources/ewol/widget/Slider.h b/sources/ewol/widget/Slider.h index 4d3dd1ee..d6f02210 100644 --- a/sources/ewol/widget/Slider.h +++ b/sources/ewol/widget/Slider.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -23,7 +24,7 @@ namespace ewol { class Slider : public ewol::Widget { public: // Event list of properties - static const char * const eventChange; + ewol::object::Signal signalChange; protected: Slider(); void init(); diff --git a/sources/ewol/widget/WSlider.cpp b/sources/ewol/widget/WSlider.cpp index 3b3159d6..76aa3b82 100644 --- a/sources/ewol/widget/WSlider.cpp +++ b/sources/ewol/widget/WSlider.cpp @@ -23,11 +23,9 @@ std::ostream& operator <<(std::ostream& _os, const enum ewol::widget::WSlider::s #undef __class__ #define __class__ "WSlider" -// Event list of properties -const char* const ewol::widget::WSlider::eventStartSlide = "ewol-widget-wslider-event-start-slide"; -const char* const ewol::widget::WSlider::eventStopSlide = "ewol-widget-wslider-event-stop-slide"; - ewol::widget::WSlider::WSlider() : + signalStartSlide(*this, "start"), + signalStopSlide(*this, "stop"), m_windowsSources(0), m_windowsDestination(0), m_windowsRequested(-1), @@ -36,8 +34,6 @@ ewol::widget::WSlider::WSlider() : m_transitionSpeed(*this, "speed", 1.0f, 0.0f, 200.0f, "Transition speed of the slider"), m_transitionSlide(*this, "mode", sladingTransitionHori, "Transition mode of the slider") { addObjectType("ewol::widget::WSlider"); - addEventId(eventStartSlide); - addEventId(eventStopSlide); m_transitionSlide.add(sladingTransitionVert, "vert"); m_transitionSlide.add(sladingTransitionHori, "hori"); } @@ -105,7 +101,7 @@ void ewol::widget::WSlider::subWidgetSelectSetVectorId(int32_t _id) { } if (_id != m_windowsDestination) { m_windowsRequested = _id; - generateEventId(eventStartSlide); + signalStartSlide.emit(); periodicCallEnable(); markToRedraw(); } @@ -189,7 +185,7 @@ void ewol::widget::WSlider::periodicCall(const ewol::event::Time& _event) { } else { // end of periodic : periodicCallDisable(); - generateEventId(eventStopSlide); + signalStopSlide.emit(); } m_windowsRequested = -1; } diff --git a/sources/ewol/widget/WSlider.h b/sources/ewol/widget/WSlider.h index 5e56de7c..1deec94d 100644 --- a/sources/ewol/widget/WSlider.h +++ b/sources/ewol/widget/WSlider.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -22,8 +23,8 @@ namespace ewol { class WSlider :public ewol::widget::ContainerN { public: // Event list of properties - static const char* const eventStartSlide; - static const char* const eventStopSlide; + ewol::object::Signal signalStartSlide; + ewol::object::Signal signalStopSlide; enum sladingMode { sladingTransitionVert, sladingTransitionHori, diff --git a/sources/ewol/widget/Widget.cpp b/sources/ewol/widget/Widget.cpp index ef20011c..3899aa64 100644 --- a/sources/ewol/widget/Widget.cpp +++ b/sources/ewol/widget/Widget.cpp @@ -86,11 +86,6 @@ std::ostream& ewol::operator <<(std::ostream& _os, const enum ewol::gravity _obj #undef __class__ #define __class__ "Widget" -// event generated : -const char* const ewol::Widget::eventAnnimationStart = "annimation-start"; -const char* const ewol::Widget::eventAnnimationRatio = "annimation-ratio"; -const char* const ewol::Widget::eventAnnimationStop = "annimation-stop"; - ewol::Widget::Widget() : m_size(10,10), m_minSize(0,0), @@ -110,9 +105,13 @@ ewol::Widget::Widget() : m_allowRepeateKeyboardEvent(true), m_periodicCallDeltaTime(-1), m_periodicCallTime(0), + signalShortcut(*this, "shortcut"), m_needRegenerateDisplay(true), m_grabCursor(false), m_cursorDisplay(ewol::context::cursorArrow), + signalAnnimationStart(*this, "annimation-start"), + signalAnnimationRatio(*this, "annimation-ratio"), + signalAnnimationStop(*this, "annimation-stop"), m_annimationMode(annimationModeDisable), m_annimationratio(0.0f), m_annimationTypeStart(*this, "annimation-start-type", 0, "Annimation type, when adding/show a widget"), @@ -133,10 +132,6 @@ ewol::Widget::Widget() : m_gravity.add(ewol::gravityLeft, "left"); m_annimationTypeStart.add(0, "none"); m_annimationTypeStop.add(0, "none"); - - addEventId(eventAnnimationStart); - addEventId(eventAnnimationRatio); - addEventId(eventAnnimationStop); } void ewol::Widget::init() { @@ -431,12 +426,8 @@ const bvec2& ewol::Widget::canFill() { // -- Shortcut : management of the shortcut // ---------------------------------------------------------------------------------------------------------------- -void ewol::Widget::shortCutAdd(const char * _descriptiveString, - const char * _generateEventId, - std::string _data, - bool _broadcast) { - if ( _descriptiveString == nullptr - || strlen(_descriptiveString) == 0) { +void ewol::Widget::shortCutAdd(const std::string& _descriptiveString, const std::string& _message) { + if (_descriptiveString.size() == 0) { EWOL_ERROR("try to add shortcut with no descriptive string ..."); return; } @@ -445,94 +436,105 @@ void ewol::Widget::shortCutAdd(const char * _descriptiveString, EWOL_ERROR("allocation error ... Memory error ..."); return; } - tmpElement->broadcastEvent = _broadcast; - tmpElement->generateEventId = _generateEventId; - tmpElement->eventData = _data; + if (_message.size() == 0) { + tmpElement->message = _descriptiveString; + } else { + tmpElement->message = _message; + } // parsing of the string : //"ctrl+shift+alt+meta+s" - const char * tmp = strstr(_descriptiveString, "ctrl"); - if(nullptr != tmp) { + if(_descriptiveString.find("ctrl") != std::string::npos) { tmpElement->specialKey.setCtrl(true); } - tmp = strstr(_descriptiveString, "shift"); - if(nullptr != tmp) { + if(_descriptiveString.find("shift") != std::string::npos) { tmpElement->specialKey.setShift(true); } - tmp = strstr(_descriptiveString, "alt"); - if(nullptr != tmp) { + if(_descriptiveString.find("alt") != std::string::npos) { tmpElement->specialKey.setAlt(true); } - tmp = strstr(_descriptiveString, "meta"); - if(nullptr != tmp) { + if(_descriptiveString.find("meta") != std::string::npos) { tmpElement->specialKey.setMeta(true); } - if(nullptr != strstr(_descriptiveString, "F12") ) { + if(_descriptiveString.find("F12") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF12; - } else if(nullptr != strstr(_descriptiveString, "F11") ) { + } else if(_descriptiveString.find("F11") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF11; - } else if(nullptr != strstr(_descriptiveString, "F10") ) { + } else if(_descriptiveString.find("F10") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF10; - } else if(nullptr != strstr(_descriptiveString, "F9") ) { + } else if(_descriptiveString.find("F9") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF9; - } else if(nullptr != strstr(_descriptiveString, "F8") ) { + } else if(_descriptiveString.find("F8") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF8; - } else if(nullptr != strstr(_descriptiveString, "F7") ) { + } else if(_descriptiveString.find("F7") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF7; - } else if(nullptr != strstr(_descriptiveString, "F6") ) { + } else if(_descriptiveString.find("F6") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF6; - } else if(nullptr != strstr(_descriptiveString, "F5") ) { + } else if(_descriptiveString.find("F5") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF5; - } else if(nullptr != strstr(_descriptiveString, "F4") ) { + } else if(_descriptiveString.find("F4") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF4; - } else if(nullptr != strstr(_descriptiveString, "F3") ) { + } else if(_descriptiveString.find("F3") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF3; - } else if(nullptr != strstr(_descriptiveString, "F2") ) { + } else if(_descriptiveString.find("F2") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF2; - } else if(nullptr != strstr(_descriptiveString, "F1") ) { + } else if(_descriptiveString.find("F1") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardF1; - } else if(nullptr != strstr(_descriptiveString, "LEFT") ) { + } else if(_descriptiveString.find("LEFT") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardLeft; - } else if(nullptr != strstr(_descriptiveString, "RIGHT") ) { + } else if(_descriptiveString.find("RIGHT") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardRight; - } else if(nullptr != strstr(_descriptiveString, "UP") ) { + } else if(_descriptiveString.find("UP") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardUp; - } else if(nullptr != strstr(_descriptiveString, "DOWN") ) { + } else if(_descriptiveString.find("DOWN") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardDown; - } else if(nullptr != strstr(_descriptiveString, "PAGE_UP") ) { + } else if(_descriptiveString.find("PAGE_UP") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardPageUp; - } else if(nullptr != strstr(_descriptiveString, "PAGE_DOWN") ) { + } else if(_descriptiveString.find("PAGE_DOWN") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardPageDown; - } else if(nullptr != strstr(_descriptiveString, "START") ) { + } else if(_descriptiveString.find("START") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardStart; - } else if(nullptr != strstr(_descriptiveString, "END") ) { + } else if(_descriptiveString.find("END") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardEnd; - } else if(nullptr != strstr(_descriptiveString, "PRINT") ) { + } else if(_descriptiveString.find("PRINT") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardPrint; - } else if(nullptr != strstr(_descriptiveString, "ARRET_DEFIL") ) { + } else if(_descriptiveString.find("ARRET_DEFIL") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardStopDefil; - } else if(nullptr != strstr(_descriptiveString, "WAIT") ) { + } else if(_descriptiveString.find("WAIT") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardWait; - } else if(nullptr != strstr(_descriptiveString, "INSERT") ) { + } else if(_descriptiveString.find("INSERT") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardInsert; - } else if(nullptr != strstr(_descriptiveString, "CAPLOCK") ) { + } else if(_descriptiveString.find("CAPLOCK") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardCapLock; - } else if(nullptr != strstr(_descriptiveString, "CONTEXT_MENU") ) { + } else if(_descriptiveString.find("CONTEXT_MENU") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardContextMenu; - } else if(nullptr != strstr(_descriptiveString, "NUM_LOCK") ) { + } else if(_descriptiveString.find("NUM_LOCK") != std::string::npos) { tmpElement->keyboardMoveValue = ewol::key::keyboardNumLock; } else { - tmpElement->unicodeValue = _descriptiveString[strlen(_descriptiveString) -1]; + tmpElement->unicodeValue = _descriptiveString[_descriptiveString.size() -1]; } // add it on the List ... m_localShortcut.push_back(tmpElement); } -void ewol::Widget::shortCutClean() { - for (size_t iii=0; iiimessage != _message) { + ++it; + continue; } + delete(*it); + *it = nullptr; + m_localShortcut.erase(it); + it = m_localShortcut.begin(); + } +} + +void ewol::Widget::shortCutClean() { + for (auto &it : m_localShortcut) { + delete(it); + it = nullptr; } m_localShortcut.clear(); } @@ -557,14 +559,8 @@ bool ewol::Widget::onEventShortCut(ewol::key::Special& _special, && m_localShortcut[iii]->unicodeValue == 0) ) ) { if (_isDown) { - if (true == m_localShortcut[iii]->broadcastEvent) { - // send message at all the widget (exepted this one) - sendMultiCast(m_localShortcut[iii]->generateEventId, m_localShortcut[iii]->eventData); - } - // send message direct to the current widget (in every case, really useful for some generic windows shortcut) - ewol::object::Message tmpMsg(shared_from_this(), m_localShortcut[iii]->generateEventId, m_localShortcut[iii]->eventData); - onReceiveMessage(tmpMsg); - } // no else + signalShortcut.emit(m_localShortcut[iii]->message); + } return true; } } @@ -602,20 +598,11 @@ enum ewol::context::cursorDisplay ewol::Widget::getCursor() { } bool ewol::Widget::loadXML(exml::Element* _node) { - // Call EObject basic parser - ewol::Object::loadXML(_node); // note : load standard parameters (attribute in XML) + ewol::Object::loadXML(_node); markToRedraw(); return true; } -std::shared_ptr ewol::Widget::getWidgetNamed(const std::string& _widgetName) { - EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} compare : " << getName() << " == " << _widgetName ); - if (getName() == _widgetName) { - return std::dynamic_pointer_cast(shared_from_this()); - } - return nullptr; -} - bool ewol::Widget::systemEventEntry(ewol::event::EntrySystem& _event) { std::shared_ptr up = std::dynamic_pointer_cast(m_parent.lock()); if (up != nullptr) { diff --git a/sources/ewol/widget/Widget.h b/sources/ewol/widget/Widget.h index 2ec51867..800f28cd 100644 --- a/sources/ewol/widget/Widget.h +++ b/sources/ewol/widget/Widget.h @@ -31,6 +31,7 @@ namespace ewol { #include #include #include +#include #define ULTIMATE_MAX_SIZE (99999999) @@ -99,16 +100,12 @@ namespace ewol { */ class EventShortCut { public: - bool broadcastEvent; //!< if it is true, then the message is sent to all the system - const char* generateEventId; //!< Local generated event - std::string eventData; //!< data link with the event + std::string message; //!< data link with the event ewol::key::Special specialKey; //!< special board key char32_t unicodeValue; //!< 0 if not used enum ewol::key::keyboard keyboardMoveValue; //!< ewol::EVENT_KB_MOVE_TYPE_NONE if not used EventShortCut() { - broadcastEvent = false; - generateEventId = nullptr; - eventData = ""; + message = ""; unicodeValue = 0; keyboardMoveValue = ewol::key::keyboardUnknow; }; @@ -531,12 +528,6 @@ namespace ewol { } return nullptr; }; - /** - * @brief get the widget if it have this name or one of the subwidget with the same name - * @param[in] _widgetName name of the widget - * @return the requested pointer on the node (or nullptr pointer) - */ - virtual std::shared_ptr getWidgetNamed(const std::string& _widgetName); // event section: public: @@ -590,23 +581,27 @@ namespace ewol { // ---------------------------------------------------------------------------------------------------------------- // -- Shortcut : management of the shortcut // ---------------------------------------------------------------------------------------------------------------- + public: + ewol::object::Signal signalShortcut; //!< signal handle of the message private: std::vector m_localShortcut; //!< list of all shortcut in the widget protected: /** * @brief add a specific shortcut with his description * @param[in] _descriptiveString Description string of the shortcut - * @param[in] _generateEventId Event generic of the element - * @param[in] _data Associate data wit the event + * @param[in] _message massage to generate (or shortcut name) */ - virtual void shortCutAdd(const char * _descriptiveString, - const char * _generateEventId, - std::string _data="", - bool _broadcast=false); + virtual void shortCutAdd(const std::string& _descriptiveString, + const std::string& _message=""); /** * @brief remove all curent shortCut */ virtual void shortCutClean(); + /** + * @brief remove a specific shortCut whith his event name + * @param[in] _message renerated event name + */ + virtual void shortCutRemove(const std::string& _message); public: /** * @brief Event on a short-cut of this Widget (in case of return false, the event on the keyevent will arrive in the function @ref onEventKb). @@ -713,9 +708,9 @@ namespace ewol { */ public: // event generated : - static const char* const eventAnnimationStart; //!< event when start annimation - static const char* const eventAnnimationRatio; //!< event when % of annimation change (integer) - static const char* const eventAnnimationStop; //!< event when stop annimation + ewol::object::Signal signalAnnimationStart; //!< event when start annimation + ewol::object::Signal signalAnnimationRatio; //!< event when % of annimation change (integer) + ewol::object::Signal signalAnnimationStop; //!< event when stop annimation protected: enum annimationMode { annimationModeEnableAdd, diff --git a/sources/ewol/widget/meta/ColorChooser.cpp b/sources/ewol/widget/meta/ColorChooser.cpp index ffd47df2..f954d59b 100644 --- a/sources/ewol/widget/meta/ColorChooser.cpp +++ b/sources/ewol/widget/meta/ColorChooser.cpp @@ -22,24 +22,19 @@ extern "C" { #undef __class__ #define __class__ "ColorChooser" - -const char * const ewol::widget::ColorChooser::eventChange = "change"; - - static const char * const eventColorBarHasChange = "event-color-bar-has-change"; -static const char * const eventColorSpecificHasChange = "event-color-specific-has-change"; -ewol::widget::ColorChooser::ColorChooser() { +ewol::widget::ColorChooser::ColorChooser() : + signalChange(*this, "change") { addObjectType("ewol::widget::ColorChooser"); - addEventId(eventChange); } void ewol::widget::ColorChooser::init() { ewol::widget::Sizer::init(ewol::widget::Sizer::modeVert); lockExpand(bvec2(true,true)); m_widgetColorBar = ewol::widget::ColorBar::create(); - m_widgetColorBar->registerOnEvent(shared_from_this(), "change", eventColorBarHasChange); + m_widgetColorBar->signalChange.bind(shared_from_this(), &ewol::widget::ColorChooser::onCallbackColorChange); m_widgetColorBar->setFill(bvec2(true,true)); subWidgetAdd(m_widgetColorBar); @@ -47,7 +42,7 @@ void ewol::widget::ColorChooser::init() { sliderColor = etk::color::black; m_widgetRed = ewol::widget::Slider::create(); - m_widgetRed->registerOnEvent(shared_from_this(), "change", eventColorSpecificHasChange); + m_widgetRed->signalChange.bind(shared_from_this(), &ewol::widget::ColorChooser::onCallbackColorChangeRed); m_widgetRed->setExpand(bvec2(true,false)); m_widgetRed->setFill(bvec2(true,false)); m_widgetRed->setMin(0); @@ -56,7 +51,7 @@ void ewol::widget::ColorChooser::init() { m_widgetRed->setColor(sliderColor); subWidgetAdd(m_widgetRed); m_widgetGreen = ewol::widget::Slider::create(); - m_widgetGreen->registerOnEvent(shared_from_this(), "change", eventColorSpecificHasChange); + m_widgetGreen->signalChange.bind(shared_from_this(), &ewol::widget::ColorChooser::onCallbackColorChangeGreen); m_widgetGreen->setExpand(bvec2(true,false)); m_widgetGreen->setFill(bvec2(true,false)); m_widgetGreen->setMin(0); @@ -65,7 +60,7 @@ void ewol::widget::ColorChooser::init() { m_widgetGreen->setMax(255); subWidgetAdd(m_widgetGreen); m_widgetBlue = ewol::widget::Slider::create(); - m_widgetBlue->registerOnEvent(shared_from_this(), "change", eventColorSpecificHasChange); + m_widgetBlue->signalChange.bind(shared_from_this(), &ewol::widget::ColorChooser::onCallbackColorChangeBlue); m_widgetBlue->setExpand(bvec2(true,false)); m_widgetBlue->setFill(bvec2(true,false)); m_widgetBlue->setMin(0); @@ -74,7 +69,7 @@ void ewol::widget::ColorChooser::init() { m_widgetBlue->setMax(255); subWidgetAdd(m_widgetBlue); m_widgetAlpha = ewol::widget::Slider::create(); - m_widgetAlpha->registerOnEvent(shared_from_this(), "change", eventColorSpecificHasChange); + m_widgetAlpha->signalChange.bind(shared_from_this(), &ewol::widget::ColorChooser::onCallbackColorChangeAlpha); m_widgetAlpha->setExpand(bvec2(true,false)); m_widgetAlpha->setFill(bvec2(true,false)); m_widgetAlpha->setMin(0); @@ -114,51 +109,51 @@ etk::Color<> ewol::widget::ColorChooser::getColor() { return m_currentColor; } - -void ewol::widget::ColorChooser::onReceiveMessage(const ewol::object::Message& _msg) { - if (nullptr == _msg.getCaller()) { - return; +void ewol::widget::ColorChooser::onCallbackColorChangeRed(const int32_t& _newColor) { + m_currentColor.setR(_newColor); + if (nullptr != m_widgetColorBar) { + m_widgetColorBar->setCurrentColor(m_currentColor); } - //EWOL_INFO("Receive Extern Event ... : widgetPointer=" << CallerObject << "\"" << eventId << "\" == > data=\"" << data << "\"" ); - if (eventColorBarHasChange == _msg.getMessage()) { - // == > colorBar has change ... - uint8_t tmpAlpha = m_currentColor.a(); - // the colorbar has no notion of the alpha == > keep it ... - if (nullptr != m_widgetColorBar) { - m_currentColor = m_widgetColorBar->getCurrentColor(); - } - m_currentColor.setA(tmpAlpha); - if (nullptr != m_widgetRed) { - m_widgetRed->setValue(m_currentColor.r()); - } - if (nullptr != m_widgetGreen) { - m_widgetGreen->setValue(m_currentColor.g()); - } - if (nullptr != m_widgetBlue) { - m_widgetBlue->setValue(m_currentColor.b()); - } - if (nullptr != m_widgetAlpha) { - m_widgetAlpha->setValue(m_currentColor.a()); - } - generateEventId(eventChange, m_currentColor.getString()); - } else if (eventColorSpecificHasChange == _msg.getMessage()) { - // Slider has changes his color == > get the one change ... - if (_msg.getCaller() == m_widgetRed) { - m_currentColor.setR(m_widgetRed->getValue()); - } - if (_msg.getCaller() == m_widgetGreen) { - m_currentColor.setG(m_widgetGreen->getValue()); - } - if (_msg.getCaller() == m_widgetBlue) { - m_currentColor.setB(m_widgetBlue->getValue()); - } - if (_msg.getCaller() == m_widgetAlpha) { - m_currentColor.setA(m_widgetAlpha->getValue()); - } - if (nullptr != m_widgetColorBar) { - m_widgetColorBar->setCurrentColor(m_currentColor); - } - generateEventId(eventChange, m_currentColor.getString()); + signalChange.emit(m_currentColor); +} +void ewol::widget::ColorChooser::onCallbackColorChangeGreen(const int32_t& _newColor) { + m_currentColor.setG(_newColor); + if (nullptr != m_widgetColorBar) { + m_widgetColorBar->setCurrentColor(m_currentColor); } -}; - + signalChange.emit(m_currentColor); +} +void ewol::widget::ColorChooser::onCallbackColorChangeBlue(const int32_t& _newColor) { + m_currentColor.setB(_newColor); + if (nullptr != m_widgetColorBar) { + m_widgetColorBar->setCurrentColor(m_currentColor); + } + signalChange.emit(m_currentColor); +} +void ewol::widget::ColorChooser::onCallbackColorChangeAlpha(const int32_t& _newColor) { + m_currentColor.setA(_newColor); + if (nullptr != m_widgetColorBar) { + m_widgetColorBar->setCurrentColor(m_currentColor); + } + signalChange.emit(m_currentColor); +} +void ewol::widget::ColorChooser::onCallbackColorChange(const etk::Color<>& _newColor) { + m_currentColor = _newColor; + // == > colorBar has change ... + uint8_t tmpAlpha = m_currentColor.a(); + m_currentColor = _newColor; + m_currentColor.setA(tmpAlpha); + if (nullptr != m_widgetRed) { + m_widgetRed->setValue(m_currentColor.r()); + } + if (nullptr != m_widgetGreen) { + m_widgetGreen->setValue(m_currentColor.g()); + } + if (nullptr != m_widgetBlue) { + m_widgetBlue->setValue(m_currentColor.b()); + } + if (nullptr != m_widgetAlpha) { + m_widgetAlpha->setValue(m_currentColor.a()); + } + signalChange.emit(m_currentColor); +} \ No newline at end of file diff --git a/sources/ewol/widget/meta/ColorChooser.h b/sources/ewol/widget/meta/ColorChooser.h index 187f5731..c3044ece 100644 --- a/sources/ewol/widget/meta/ColorChooser.h +++ b/sources/ewol/widget/meta/ColorChooser.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -27,15 +28,13 @@ namespace ewol { class ColorChooser : public ewol::widget::Sizer { public: // Event list of properties - static const char * const eventChange; + ewol::object::Signal> signalChange; protected: ColorChooser(); void init(); public: DECLARE_WIDGET_FACTORY(ColorChooser, "ColorChooser"); virtual ~ColorChooser(); - public: // Derived function - virtual void onReceiveMessage(const ewol::object::Message& _msg); public: void setColor(etk::Color<> _newColor); etk::Color<> getColor(); @@ -46,6 +45,11 @@ namespace ewol { std::shared_ptr m_widgetBlue; std::shared_ptr m_widgetAlpha; etk::Color<> m_currentColor; + void onCallbackColorChangeRed(const int32_t& _newColor); + void onCallbackColorChangeGreen(const int32_t& _newColor); + void onCallbackColorChangeBlue(const int32_t& _newColor); + void onCallbackColorChangeAlpha(const int32_t& _newColor); + void onCallbackColorChange(const etk::Color<>& _newColor); }; }; }; diff --git a/sources/ewol/widget/meta/FileChooser.cpp b/sources/ewol/widget/meta/FileChooser.cpp index d716c73b..9283f09b 100644 --- a/sources/ewol/widget/meta/FileChooser.cpp +++ b/sources/ewol/widget/meta/FileChooser.cpp @@ -10,6 +10,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -29,25 +33,10 @@ extern "C" { #undef __class__ #define __class__ "FileChooser" - -const char * const ewol::widget::FileChooser::eventCancel = "cancel"; -const char * const ewol::widget::FileChooser::eventValidate = "validate"; - -static const char * const ewolEventFileChooserHidenFileChange = "ewol-event-file-chooser-Show/Hide-hiden-Files"; -static const char * const ewolEventFileChooserEntryFolder = "ewol-event-file-chooser-modify-entry-folder"; -static const char * const ewolEventFileChooserEntryFolderEnter = "ewol-event-file-chooser-modify-entry-folder-enter"; -static const char * const ewolEventFileChooserEntryFile = "ewol-event-file-chooser-modify-entry-file"; -static const char * const ewolEventFileChooserEntryFileEnter = "ewol-event-file-chooser-modify-entry-file-enter"; -static const char * const ewolEventFileChooserListFolder = "ewol-event-file-chooser-modify-list-folder"; -static const char * const ewolEventFileChooserListFile = "ewol-event-file-chooser-modify-list-file"; -static const char * const ewolEventFileChooserListFileValidate = "ewol-event-file-chooser-modify-list-file-validate"; -static const char * const ewolEventFileChooserHome = "ewol-event-file-chooser-home"; - - -ewol::widget::FileChooser::FileChooser() { +ewol::widget::FileChooser::FileChooser() : + signalCancel(*this, "cancel"), + signalValidate(*this, "validate") { addObjectType("ewol::widget::FileChooser"); - addEventId(eventCancel); - addEventId(eventValidate); } void ewol::widget::FileChooser::init() { @@ -106,17 +95,17 @@ void ewol::widget::FileChooser::init() { + " \n" + ""; loadFromString(myDescription); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:show-hiden-file", "value", ewolEventFileChooserHidenFileChange); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:button-validate", "pressed", eventValidate); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:button-cancel", "pressed", eventCancel); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:list-folder", "folder-validate", ewolEventFileChooserListFolder); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:list-files", "file-select", ewolEventFileChooserListFile); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:list-files", "file-validate", ewolEventFileChooserListFileValidate); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:entry-file", "modify", ewolEventFileChooserEntryFile); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:entry-file", "enter", ewolEventFileChooserEntryFileEnter); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:entry-folder", "modify", ewolEventFileChooserEntryFolder); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:entry-folder", "enter", ewolEventFileChooserEntryFolderEnter); - registerOnEventNameWidget("[" + etk::to_string(getId()) + "]file-shooser:img-home", "pressed", ewolEventFileChooserHome); + subBind(ewol::widget::CheckBox, "[" + etk::to_string(getId()) + "]file-shooser:show-hiden-file", signalValue, shared_from_this(), &ewol::widget::FileChooser::onCallbackHidenFileChangeChangeValue); + subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]file-shooser:button-validate", signalPressed, shared_from_this(), &ewol::widget::FileChooser::onCallbackListValidate); + subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]file-shooser:button-cancel", signalPressed, shared_from_this(), &ewol::widget::FileChooser::onCallbackButtonCancelPressed); + subBind(ewol::widget::ListFileSystem, "[" + etk::to_string(getId()) + "]file-shooser:list-folder", signalFolderValidate, shared_from_this(), &ewol::widget::FileChooser::onCallbackListFolderSelectChange); + subBind(ewol::widget::ListFileSystem, "[" + etk::to_string(getId()) + "]file-shooser:list-files", signalFileSelect, shared_from_this(), &ewol::widget::FileChooser::onCallbackListFileSelectChange); + subBind(ewol::widget::ListFileSystem, "[" + etk::to_string(getId()) + "]file-shooser:list-files", signalFileValidate, shared_from_this(), &ewol::widget::FileChooser::onCallbackListFileValidate); + subBind(ewol::widget::Entry, "[" + etk::to_string(getId()) + "]file-shooser:entry-file", signalModify, shared_from_this(), &ewol::widget::FileChooser::onCallbackEntryFileChangeValue); + subBind(ewol::widget::Entry, "[" + etk::to_string(getId()) + "]file-shooser:entry-file", signalEnter, shared_from_this(), &ewol::widget::FileChooser::onCallbackListFileValidate); + subBind(ewol::widget::Entry, "[" + etk::to_string(getId()) + "]file-shooser:entry-folder", signalModify, shared_from_this(), &ewol::widget::FileChooser::onCallbackEntryFolderChangeValue); + //composerBind(ewol::widget::CheckBox, "[" + etk::to_string(getId()) + "]file-shooser:entry-folder", signalEnter, shared_from_this(), &ewol::widget::FileChooser::); + subBind(ewol::widget::Image, "[" + etk::to_string(getId()) + "]file-shooser:img-home", signalPressed, shared_from_this(), &ewol::widget::FileChooser::onCallbackHomePressed); // set the default Folder properties: updateCurrentFolder(); setCanHaveFocus(true); @@ -153,62 +142,81 @@ void ewol::widget::FileChooser::setFileName(const std::string& _filename) { parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:entry-file", "value", _filename); } -void ewol::widget::FileChooser::onReceiveMessage(const ewol::object::Message& _msg) { - EWOL_INFO("Receive Event from the LIST ... : " << _msg); - if (_msg.getMessage() == ewolEventFileChooserEntryFolder) { - // == > change the folder name - // TODO : change the folder, if it exit ... - } else if (_msg.getMessage() == ewolEventFileChooserEntryFile) { - // == > change the file name - m_file = _msg.getData(); - // update the selected file in the list : - parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "select", m_file); - } else if (eventCancel == _msg.getMessage()) { - // == > Auto remove ... - generateEventId(_msg.getMessage()); - autoDestroy(); - } else if (_msg.getMessage() == ewolEventFileChooserHidenFileChange) { - if (_msg.getData() == "true") { - parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "true"); - parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "true"); - } else { - parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "false"); - parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "false"); - } - } else if (_msg.getMessage() == ewolEventFileChooserListFolder) { - // == > this is an internal event ... - EWOL_DEBUG(" old PATH : \"" << m_folder << "\" + \"" << _msg.getData() << "\""); - m_folder = m_folder + _msg.getData(); - EWOL_DEBUG("new PATH : \"" << m_folder << "\""); - m_folder = etk::simplifyPath(m_folder); - setFileName(""); - updateCurrentFolder(); - } else if (_msg.getMessage() == ewolEventFileChooserListFile) { - setFileName(_msg.getData()); - std::string tmpFileCompleatName = m_folder; - tmpFileCompleatName += m_file; - generateEventId(_msg.getMessage(), tmpFileCompleatName); - } else if( _msg.getMessage() == ewolEventFileChooserListFileValidate - || (_msg.getMessage() == eventValidate && m_file != "" ) - || (_msg.getMessage() == ewolEventFileChooserEntryFileEnter && m_file != "" ) ) { - // select the file == > generate a validate - if (_msg.getData() != "") { - setFileName(_msg.getData()); - } - EWOL_VERBOSE(" generate a fiel opening : \"" << m_folder << "\" / \"" << m_file << "\""); - generateEventId(eventValidate, getCompleateFileName()); - autoDestroy(); - } else if(_msg.getMessage() == ewolEventFileChooserHome) { - std::string tmpUserFolder = etk::getUserHomeFolder(); - EWOL_DEBUG("new PATH : \"" << tmpUserFolder << "\""); - - m_folder = etk::simplifyPath(tmpUserFolder); - - setFileName(""); - updateCurrentFolder(); + +void ewol::widget::FileChooser::onCallbackEntryFolderChangeValue(const std::string& _value) { + // == > change the folder name + // TODO : change the folder, if it exit ... +} + +void ewol::widget::FileChooser::onCallbackEntryFileChangeValue(const std::string& _value) { + // == > change the file name + m_file = _value; + // update the selected file in the list : + parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "select", m_file); +} + +void ewol::widget::FileChooser::onCallbackButtonCancelPressed() { + // == > Auto remove ... + signalCancel.emit(); + autoDestroy(); +} + +void ewol::widget::FileChooser::onCallbackHidenFileChangeChangeValue(const bool& _value) { + if (_value == true) { + parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "true"); + parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "true"); + } else { + parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "false"); + parameterSetOnWidgetNamed("[" + etk::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "false"); } - return; -}; +} + +void ewol::widget::FileChooser::onCallbackListFolderSelectChange(const std::string& _value) { + // == > this is an internal event ... + EWOL_DEBUG(" old PATH : \"" << m_folder << "\" + \"" << _value << "\""); + m_folder = m_folder + _value; + EWOL_DEBUG("new PATH : \"" << m_folder << "\""); + m_folder = etk::simplifyPath(m_folder); + setFileName(""); + updateCurrentFolder(); +} + +void ewol::widget::FileChooser::onCallbackListFileSelectChange(const std::string& _value) { + setFileName(_value); + /* + std::string tmpFileCompleatName = m_folder; + tmpFileCompleatName += m_file; + // TODO : generateEventId(_msg.getMessage(), tmpFileCompleatName); + */ +} + +void ewol::widget::FileChooser::onCallbackListFileValidate(const std::string& _value) { + // select the file == > generate a validate + setFileName(_value); + EWOL_VERBOSE(" generate a fiel opening : '" << m_folder << "' / '" << m_file << "'"); + signalValidate.emit(getCompleateFileName()); + autoDestroy(); +} + +void ewol::widget::FileChooser::onCallbackListValidate() { + if (m_file == "" ) { + EWOL_WARNING(" Validate : '" << m_folder << "' / '" << m_file << "' ==> error No name ..."); + return; + } + EWOL_DEBUG(" generate a file opening : '" << m_folder << "' / '" << m_file << "'"); + signalValidate.emit(getCompleateFileName()); + autoDestroy(); +} + +void ewol::widget::FileChooser::onCallbackHomePressed() { + std::string tmpUserFolder = etk::getUserHomeFolder(); + EWOL_DEBUG("new PATH : \"" << tmpUserFolder << "\""); + + m_folder = etk::simplifyPath(tmpUserFolder); + + setFileName(""); + updateCurrentFolder(); +} void ewol::widget::FileChooser::updateCurrentFolder() { if (m_folder != "" ) { diff --git a/sources/ewol/widget/meta/FileChooser.h b/sources/ewol/widget/meta/FileChooser.h index aab643b2..838c6a8c 100644 --- a/sources/ewol/widget/meta/FileChooser.h +++ b/sources/ewol/widget/meta/FileChooser.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -23,21 +24,19 @@ namespace ewol { * Fist global static declaration and inclusion: * [code style=c++] * #include - * static const char* const g_eventOpenFile = "appl-local-event-open-file"; - * static const char* const g_eventClosePopUp = "appl-local-event-close-pop-up"; * [/code] * - * The first step is to create the file chooser pop-up : + * The first step is to create the file chooser pop-up : (never in the constructor!!!) * [code style=c++] - * std::shared_ptr tmpWidget = ewol::object::makeShared(new ewol::Widget::FileChooser()); + * std::shared_ptr tmpWidget = ewol::Widget::FileChooser::create(); * if (tmpWidget == nullptr) { * APPL_ERROR("Can not open File chooser !!! "); * return -1; * } * // register on the Validate event: - * tmpWidget->registerOnEvent(this, "validate", g_eventOpenFile); + * tmpWidget->signalValidate.bind(shared_from_this(), &****::onCallbackOpenFile); * // no need of this event watching ... - * tmpWidget->registerOnEvent(this, "cancel", g_eventClosePopUp); + * tmpWidget->signalCancel.bind(shared_from_this(), &****::onCallbackClosePopUp); * // set the title: * tmpWidget->setTitle("Open files ..."); * // Set the validate Label: @@ -45,7 +44,7 @@ namespace ewol { * // simply set a folder (by default this is the home folder) * //tmpWidget->setFolder("/home/me"); * // add the widget as windows pop-up ... - * ewol::widget::Windows* tmpWindows = getWindows(); + * std::shared_ptr tmpWindows = getWindows(); * if (tmpWindows == nullptr) { * APPL_ERROR("Can not get the current windows !!! "); * return -1; @@ -56,17 +55,11 @@ namespace ewol { * Now we just need to wait the the open event message. * * [code style=c++] - * void ********::onReceiveMessage(const ewol::object::Message& _msg) { - * APPL_DEBUG("Receive Message: " << _msg ); - * if (_msg.getMessage() == g_eventOpenFile) { - * APPL_INFO("Request open file : '" << _msg.getData() << "'"); - * return; - * } - * if (_msg.getMessage() == g_eventClosePopUp) { - * APPL_INFO("The File chooser has been closed"); - * // generaly nothing to do ... - * return; - * } + * void ****::onCallbackOpenFile(const std::string& _value) { + * APPL_INFO("Request open file : '" << _value << "'"); + * } + * void ****::onCallbackClosePopUp() { + * APPL_INFO("The File chooser has been closed"); * } * [/code] * This is the best example of a Meta-widget. @@ -74,8 +67,8 @@ namespace ewol { class FileChooser : public ewol::widget::Composer { public: // Event list of properties - static const char* const eventCancel; - static const char* const eventValidate; + ewol::object::Signal signalCancel; + ewol::object::Signal signalValidate; protected: FileChooser(); void init(); @@ -94,8 +87,18 @@ namespace ewol { std::string getCompleateFileName(); void updateCurrentFolder(); public: // Derived function - virtual void onReceiveMessage(const ewol::object::Message& _msg); virtual void onGetFocus(); + private: + // callback functions: + void onCallbackEntryFolderChangeValue(const std::string& _value); + void onCallbackEntryFileChangeValue(const std::string& _value); + void onCallbackButtonCancelPressed(); + void onCallbackHidenFileChangeChangeValue(const bool& _value); + void onCallbackListFolderSelectChange(const std::string& _value); + void onCallbackListFileSelectChange(const std::string& _value); + void onCallbackListFileValidate(const std::string& _value); + void onCallbackListValidate(); + void onCallbackHomePressed(); }; }; }; diff --git a/sources/ewol/widget/meta/Parameter.cpp b/sources/ewol/widget/meta/Parameter.cpp index 7d84aae0..2be06985 100644 --- a/sources/ewol/widget/meta/Parameter.cpp +++ b/sources/ewol/widget/meta/Parameter.cpp @@ -21,18 +21,12 @@ #undef __class__ #define __class__ "Parameter" -const char * const ewol::widget::Parameter::eventClose = "close"; - -static const char * const ewolEventParameterValidate = "ewol-event-parameter-validate"; -static const char * const ewolEventParameterSave = "ewol-event-parameter-save"; -static const char * const l_eventMenuSelected = "local-event-menu-selected"; - ewol::widget::Parameter::Parameter() : + signalClose(*this, "close"), m_currentIdList(0), m_widgetTitle(), m_paramList() { addObjectType("ewol::widget::Parameter"); - addEventId(eventClose); } void ewol::widget::Parameter::init() { @@ -82,7 +76,7 @@ void ewol::widget::Parameter::init() { " \n" " \n" "\n")); - tmpButton->registerOnEvent(shared_from_this(), "pressed", ewolEventParameterSave); + tmpButton->signalPressed.bind(shared_from_this(), &ewol::widget::Parameter::onCallbackParameterSave); mySizerHori->subWidgetAdd(tmpButton); } @@ -106,7 +100,7 @@ void ewol::widget::Parameter::init() { " \n" " \n" "\n")); - tmpButton->registerOnEvent(shared_from_this(), "pressed", eventClose); + tmpButton->signalPressed.bind(shared_from_this(), &ewol::widget::Parameter::onCallbackMenuclosed); mySizerHori->subWidgetAdd(tmpButton); } } @@ -122,7 +116,7 @@ void ewol::widget::Parameter::init() { EWOL_ERROR("Can not allocate widget == > display might be in error"); } else { - m_paramList->registerOnEvent(shared_from_this(), "select", l_eventMenuSelected); + m_paramList->signalSelect.bind(shared_from_this(), &ewol::widget::Parameter::onCallbackMenuSelected); m_paramList->setFill(bvec2(false,true)); m_paramList->setExpand(bvec2(false,true)); mySizerHori->subWidgetAdd(m_paramList); @@ -197,26 +191,21 @@ void ewol::widget::Parameter::setTitle(std::string _label) { m_widgetTitle->setLabel(_label); } -void ewol::widget::Parameter::onReceiveMessage(const ewol::object::Message& _msg) { - ewol::widget::PopUp::onReceiveMessage(_msg); - EWOL_DEBUG("event on the parameter : " << _msg); - if (_msg.getMessage() == eventClose) { - // inform that the parameter windows is closed - generateEventId(eventClose); - // close this widget ... - autoDestroy(); - } else if (_msg.getMessage() == ewolEventParameterSave) { - //ewol::userConfig::Save(); - EWOL_TODO("Save Parameter !!! "); - } else if (_msg.getMessage() == l_eventMenuSelected) { - if (nullptr != m_wSlider) { - int32_t value = 0; - sscanf(_msg.getData().c_str(), "%d", &value); - EWOL_DEBUG("event on the parameter : " << _msg.getMessage() << " select ID=" << value << ""); - m_wSlider->subWidgetSelectSet(value); - } +void ewol::widget::Parameter::onCallbackMenuclosed() { + // inform that the parameter windows is closed + signalClose.emit(); + // close this widget ... + autoDestroy(); +} +void ewol::widget::Parameter::onCallbackParameterSave() { + //ewol::userConfig::Save(); + EWOL_TODO("Save Parameter !!! "); +} +void ewol::widget::Parameter::onCallbackMenuSelected(const int32_t& _value) { + if (m_wSlider != nullptr) { + EWOL_DEBUG("event on the parameter : Menu-select select ID=" << _value << ""); + m_wSlider->subWidgetSelectSet(_value); } - return; } void ewol::widget::Parameter::menuAdd(std::string _label, std::string _image, std::shared_ptr _associateWidget) { diff --git a/sources/ewol/widget/meta/Parameter.h b/sources/ewol/widget/meta/Parameter.h index 1adc531a..a9e5b703 100644 --- a/sources/ewol/widget/meta/Parameter.h +++ b/sources/ewol/widget/meta/Parameter.h @@ -29,15 +29,13 @@ namespace ewol { class Parameter : public ewol::widget::PopUp { public: // Event list of properties - static const char * const eventClose; + ewol::object::Signal signalClose; protected: Parameter(); void init(); public: DECLARE_WIDGET_FACTORY(Parameter, "Parameter"); virtual ~Parameter(); - public: // Derived function - virtual void onReceiveMessage(const ewol::object::Message& _msg); public: void setTitle(std::string _label); void menuAdd(std::string _label, std::string _image, std::shared_ptr _associateWidget); @@ -49,6 +47,10 @@ namespace ewol { std::shared_ptr m_widgetTitle; std::shared_ptr m_paramList; std::shared_ptr m_wSlider; + private: //callback functions: + void onCallbackMenuclosed(); + void onCallbackParameterSave(); + void onCallbackMenuSelected(const int32_t& _value); }; }; }; diff --git a/sources/ewol/widget/meta/ParameterList.cpp b/sources/ewol/widget/meta/ParameterList.cpp index b32286ec..4d3cd2c3 100644 --- a/sources/ewol/widget/meta/ParameterList.cpp +++ b/sources/ewol/widget/meta/ParameterList.cpp @@ -15,15 +15,13 @@ #include #include -const char * const ewol::widget::ParameterList::eventSelect = "select"; - #undef __class__ #define __class__ "List" -ewol::widget::ParameterList::ParameterList() { +ewol::widget::ParameterList::ParameterList() : + signalSelect(*this, "select") { addObjectType("ewol::widget::ParameterList"); - addEventId(eventSelect); m_idSelected = -1; m_paddingSizeX = 2; @@ -192,7 +190,7 @@ bool ewol::widget::ParameterList::onEventInput(const ewol::event::Input& _event) if (rawID >= 0 && (size_t)rawID < m_list.size()) { if (m_list[rawID]!=nullptr) { if (m_list[rawID]->m_refId >= 0) { - generateEventId(eventSelect, etk::to_string(m_list[rawID]->m_refId)); + signalSelect.emit(m_list[rawID]->m_refId); m_idSelected = rawID; markToRedraw(); return true; diff --git a/sources/ewol/widget/meta/ParameterList.h b/sources/ewol/widget/meta/ParameterList.h index 4def9ec2..df6d026b 100644 --- a/sources/ewol/widget/meta/ParameterList.h +++ b/sources/ewol/widget/meta/ParameterList.h @@ -39,7 +39,7 @@ namespace ewol { class ParameterList :public ewol::widget::WidgetScrolled { public: // Event list of properties - static const char * const eventSelect; + ewol::object::Signal signalSelect; private: int32_t m_idSelected; std::vector m_list; diff --git a/sources/ewol/widget/meta/StdPopUp.cpp b/sources/ewol/widget/meta/StdPopUp.cpp index 53b37a46..f607c43b 100644 --- a/sources/ewol/widget/meta/StdPopUp.cpp +++ b/sources/ewol/widget/meta/StdPopUp.cpp @@ -16,8 +16,6 @@ #undef __class__ #define __class__ "ewol::StdPopUp" -static const char * const eventButtonExit = "ewol-event-pop-up-exit-button"; - ewol::widget::StdPopUp::StdPopUp() : m_title(nullptr), m_comment(nullptr), @@ -107,17 +105,13 @@ std::shared_ptr ewol::widget::StdPopUp::addButton(const st } myButton->setSubWidget(ewol::widget::Label::create(_text)); if(_autoExit == true) { - myButton->registerOnEvent(shared_from_this(), ewol::widget::Button::eventPressed, eventButtonExit); + myButton->signalPressed.bind(shared_from_this(), &ewol::widget::StdPopUp::onCallBackButtonExit); } m_subBar->subWidgetAdd(myButton); markToRedraw(); return myButton; } -void ewol::widget::StdPopUp::onReceiveMessage(const ewol::object::Message& _msg) { - // call parent: - ewol::widget::PopUp::onReceiveMessage(_msg); - if (_msg.getMessage() == eventButtonExit) { - autoDestroy(); - } +void ewol::widget::StdPopUp::onCallBackButtonExit() { + autoDestroy(); } diff --git a/sources/ewol/widget/meta/StdPopUp.h b/sources/ewol/widget/meta/StdPopUp.h index ba1c255f..ddb62632 100644 --- a/sources/ewol/widget/meta/StdPopUp.h +++ b/sources/ewol/widget/meta/StdPopUp.h @@ -76,8 +76,8 @@ namespace ewol { * @param[in] _text Decorated text to diplay in button. */ std::shared_ptr addButton(const std::string& _text, bool _autoExit=false); - public: // Derived function - virtual void onReceiveMessage(const ewol::object::Message& _msg); + public: // callback function + void onCallBackButtonExit(); }; }; }; diff --git a/sources/lutin_ewol.py b/sources/lutin_ewol.py index 3044e27d..c79ddb49 100755 --- a/sources/lutin_ewol.py +++ b/sources/lutin_ewol.py @@ -89,15 +89,12 @@ def create(target): # object : myModule.add_src_file([ 'ewol/object/Manager.cpp', - 'ewol/object/Message.cpp', - 'ewol/object/MultiCast.cpp', 'ewol/object/Object.cpp', - 'ewol/object/RemoveEvent.cpp', 'ewol/object/Parameter.cpp', 'ewol/object/ParameterList.cpp', 'ewol/object/ParamList.cpp', - 'ewol/object/Param.cpp', - 'ewol/object/ParamRange.cpp' + 'ewol/object/SignalList.cpp', + 'ewol/object/SignalBase.cpp' ]) # OpenGL interface : diff --git a/sources/tag b/sources/tag index f76f9131..b3ec1638 100644 --- a/sources/tag +++ b/sources/tag @@ -1 +1 @@ -0.9.2 \ No newline at end of file +0.9.3 \ No newline at end of file