diff --git a/doc/tutorial/001_HelloWord.bb b/doc/tutorial/001_HelloWord.bb index 127942a2..5d0795c2 100644 --- a/doc/tutorial/001_HelloWord.bb +++ b/doc/tutorial/001_HelloWord.bb @@ -10,38 +10,50 @@ __________________________________________________ ==== Application Main: ==== +A generic Ewol application is manage by creating an [class[ewol::context::Application]] that is the basis of your application. -In all the application we need to have a main() -In This version the main neen only to call the ewol::run(void) that is the basic interface. -To be portable on Android, that have a java main the User might not set other things in this main. -[note]This basic main will change in the future to be more generic!!![/note] +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. + +Then we will create the application: + +[code style=c++] + class MainApplication : public ewol::context::Application { + public: + bool init(ewol::Context& _context, size_t _initId) { + APPL_INFO("==> Init APPL (START)"); + // nothing to do ... + APPL_INFO("==> Init APPL (END)"); + return true; + } + void unInit(ewol::Context& _context) { + APPL_INFO("==> Un-Init APPL (START)"); + // nothing to do ... + 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. + +What is done: +** When selected, it create an intance and when it is apply Android create a new instance and 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). [code style=c++] int main(int argc, const char *argv[]) { // only one things to do : - return ewol::run(argc, argv); + return ewol::run(new MainApplication(), _argc, _argv); } [/code] -Then the first question, is where is the start and stop of the application: - -[code style=c++] - // application start: - bool APP_Init(ewol::Context& _context) { - return true; - } - // application stop: - void APP_UnInit(ewol::Context& _context) { - // nothing to do. - } -[/code] - -The input [class[ewol::eContext]] is the main application context. -All the application globals have a reference in this element (and can get it everyware). -[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. -When selected, it create an intance and when it is apply Android create a new instance and remove the previous one... -[/note] ==== Some configuration are needed ==== @@ -99,7 +111,7 @@ For this point we will create a class that herited form the basic windows class: appl::Windows::Windows(void) { setTitle("example 001_HelloWord"); - ewol::widget::Label* tmpWidget = new ewol::widget::Label(); + ewol::object::Shared tmpWidget = new ewol::widget::Label(); if (NULL == tmpWidget) { APPL_ERROR("Can not allocate widget ==> display might be in error"); } else { @@ -118,7 +130,7 @@ 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::widget::Label* tmpWidget = new ewol::widget::Label(); + ewol::object::Shared tmpWidget = ewol::object::makeShared(new ewol::widget::Label()); tmpWidget->setLabel("Hello Word"); tmpWidget->setExpand(bvec2(true,true)); [/code] @@ -150,16 +162,17 @@ The last step is to add the widget on the windows : 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 APPL_init()): +Then we create windows and set it in the main contect main (in the MainApplication::init()): [code style=c++] - ewol::Windows* basicWindows = new appl::Windows(); + ewol::object::Shared basicWindows = ewol::object::makeShared(new appl::Windows()); // create the specific windows _context.setWindows(basicWindows); [/code] Then the init fuction is : [code style=c++] -bool APP_Init(ewol::Context& _context) { +bool MainApplication::init(ewol::Context& _context, size_t _initId) { + APPL_INFO("==> Init APPL (START)"); // select internal data for font ... _context.getFontDefault().setUseExternal(true); _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); @@ -167,15 +180,18 @@ bool APP_Init(ewol::Context& _context) { ewol::Windows* basicWindows = new appl::Windows(); // create the specific windows _context.setWindows(basicWindows); + APPL_INFO("==> Init APPL (END)"); return true; } [/code] -To un-init the application, the context call a generic function [b]APP_UnInit[/b]. +To un-init the application, the context call a generic function [b]MainApplication::unInit[/b]. In this function we just need to remove the windows and un-init all needed by the system. [code style=c++] -void APP_UnInit(ewol::Context& _context) { - // The main windows will be auto-remove after this call if it is not done... +void MainApplication::unInit(ewol::Context& _context) { + APPL_INFO("==> Un-Init APPL (START)"); + // Windows is auto-removed just before + APPL_INFO("==> Un-Init APPL (END)"); } [/code] diff --git a/doc/tutorial/010_ObjectModel.bb b/doc/tutorial/010_ObjectModel.bb index 82d57996..e32997ee 100644 --- a/doc/tutorial/010_ObjectModel.bb +++ b/doc/tutorial/010_ObjectModel.bb @@ -3,8 +3,8 @@ __________________________________________________ [left][tutorial[001_HelloWord | Previous: Hello Word]][/left] [right][tutorial[011_ObjectConfig | Next: Object config]][/right] === Objectif === -:** Understand ewol basic object -:** Use ewol::Object correctly +:** Understand ewol basic [class[ewol::Object]] +:** Use [class[ewol::Object]] correctly == Basis of the Object == @@ -13,7 +13,7 @@ This is designed to manage basis element of complexe structure: :** Unique ID :** Name -:** Config +:** Configuration (decriptive naming of parameters) :** Event generation and receving :** Xml configuration :** Delayed removing @@ -25,9 +25,11 @@ Please do not compare with the gObject basic class... == Create an Object: == -This is a really simple way to create an Object, simply generate a new on it : +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. + +It is really better to use the ewol::object::Shared<> declaration to auto manage it. (same as std::shared_ptr) [code style=c++] - widget::Label* tmpObject = new widget::Label(); + ewol::object::Shared tmpObject = ewol::object::makeShared(new widget::Label()); if (tmpObject == NULL) { APPL_ERROR("An error occured"); return; @@ -48,8 +50,6 @@ Force the set of the name : This is important to note that many element can have a reference on the Object. -And we did not use "ref-counting" for philosophic reasons ... - 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. @@ -60,23 +60,32 @@ Then to remove an object call: tmpObject->removeObject(); [/code] -On every object we can have an herited function: [b]virtual void onObjectRemove(ewol::Object * _removeObject);[/b] +On every object we can have an herited function: [b]virtual void onObjectRemove(const ewol::object::Shared& _removeObject);[/b] We need to implement this fuction to be notify an object is removed: [code style=c++] - void namespeceName::ClassName::onObjectRemove(ewol::Object * _removeObject) { + 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 = NULL; + m_object.reset(); markToRedraw(); // set only for graphical object ... } } [/code] [note] -If you have well follow the idea, you will never declare an object in local, just use pointer on them. +If you have well follow the idea, you will never declare an object in local, just use shared pointer on them. [/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: @@ -87,7 +96,7 @@ An object can remove itself, just use the function: == Retrieve an Object: == -In Ewol this is possible to get a widget with his name. +In Ewol this is possible to get a object with his name. This is really simple. === In an Object === @@ -99,7 +108,7 @@ Call a simple function define in the Object: ... - ewol::Object* tmpObject = getObjectManager().get("name of the object"); + ewol::object::Shared tmpObject = getObjectManager().get("name of the object"); if (tmpObject == NULL) { APPL_ERROR("The Object does not exist"); } @@ -115,13 +124,21 @@ In this case, we need to get the context manager and after the object manager: ... - ewol::Object* tmpObject = ewol::getContext().getObjectManager().get("name of the object"); + ewol::object::Shared tmpObject = ewol::getContext().getObjectManager().get("name of the object"); if (tmpObject == NULL) { APPL_ERROR("The Object does not exist"); } [/code] +=== Casting your object === +It could be really interesting to retrive your own instance: + +[code style=c++] + ewol::object::Shared tmpObject ...; + + ewol::object::Shared myObject = ewol::dynamic_pointer_cast(tmpObject); +[/code] == conclusion == @@ -129,6 +146,8 @@ If you follow these rules, you will not have memory leek and no segmentation fau [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] diff --git a/monk b/monk index aff1fdf8..895e1878 160000 --- a/monk +++ b/monk @@ -1 +1 @@ -Subproject commit aff1fdf89a04b8a4594c2742f875614e56cf8a31 +Subproject commit 895e18786ce732e8cc1c282863677c21e1806062 diff --git a/sources/ewol/widget/meta/FileChooser.h b/sources/ewol/widget/meta/FileChooser.h index 5e8d6c22..7907d85d 100644 --- a/sources/ewol/widget/meta/FileChooser.h +++ b/sources/ewol/widget/meta/FileChooser.h @@ -29,7 +29,7 @@ namespace ewol { * * The first step is to create the file chooser pop-up : * [code style=c++] - * ewol::widget::FileChooser* tmpWidget = new ewol::Widget::FileChooser(); + * ewol::object::Shared tmpWidget = ewol::object::makeShared(new ewol::Widget::FileChooser()); * if (tmpWidget == nullptr) { * APPL_ERROR("Can not open File chooser !!! "); * return -1;