change version 0.9.0

This commit is contained in:
Edouard DUPIN 2014-06-03 21:42:17 +02:00
commit 46b5eca2cb
136 changed files with 2617 additions and 2390 deletions

2
build

@ -1 +1 @@
Subproject commit 2985efea70b5bff3bda00e948a072a63e1bc3d96 Subproject commit c73da6c4aca375ba3d9ed391d7052e119daa9a90

2
external/airtaudio vendored

@ -1 +1 @@
Subproject commit bb547a72d99802ac5d9a99c843549f175c856826 Subproject commit b0eb151df0802a1d63a5cb6b6812a4460ddd09a1

View File

@ -39,6 +39,8 @@ def create(target):
'bullet/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp', 'bullet/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp',
'bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp', 'bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp',
'bullet/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp', 'bullet/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp',
'bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp',
'bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp',
'bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp', 'bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp',
'bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp', 'bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp',
'bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp', 'bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp',

2
external/egami vendored

@ -1 +1 @@
Subproject commit bb58a8c06e30cf141a59f8a09a544919c1f695ed Subproject commit 34eac48f5114151bab137e9cb177513c7cf42d96

2
external/ege vendored

@ -1 +1 @@
Subproject commit ba20ab59f74866367fb8efa260fc6eb26889422b Subproject commit 73455cc61be78fd2a76466fb8c6a1aaabe68bf61

2
external/etk vendored

@ -1 +1 @@
Subproject commit b60324928a7d69d2abc7afe4ab726676f560d317 Subproject commit cfc4d435b433fba9414330815b29e26cfe82927d

View File

@ -15,13 +15,13 @@
ewol::compositing::Area::Area(const ivec2& _size) : ewol::compositing::Area::Area(const ivec2& _size) :
m_position(0.0, 0.0, 0.0), m_position(0.0, 0.0, 0.0),
m_color(etk::color::white), m_color(etk::color::white),
m_GLprogram(NULL), m_GLprogram(nullptr),
m_GLPosition(-1), m_GLPosition(-1),
m_GLMatrix(-1), m_GLMatrix(-1),
m_GLColor(-1), m_GLColor(-1),
m_GLtexture(-1), m_GLtexture(-1),
m_GLtexID(-1), m_GLtexID(-1),
m_resource(NULL) { m_resource(nullptr) {
m_resource = ewol::resource::Texture::keep(); m_resource = ewol::resource::Texture::keep();
m_resource->setImageSize(_size); m_resource->setImageSize(_size);
m_resource->flush(); m_resource->flush();
@ -29,15 +29,14 @@ ewol::compositing::Area::Area(const ivec2& _size) :
} }
ewol::compositing::Area::~Area() { ewol::compositing::Area::~Area() {
ewol::resource::Texture::release(m_resource);
ewol::resource::Program::release(m_GLprogram);
} }
void ewol::compositing::Area::loadProgram() { void ewol::compositing::Area::loadProgram() {
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
m_GLprogram = ewol::resource::Program::keep("DATA:textured3D.prog"); m_GLprogram = ewol::resource::Program::keep("DATA:textured3D.prog");
if (NULL != m_GLprogram) { if (nullptr != m_GLprogram) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getAttribute("EW_color"); m_GLColor = m_GLprogram->getAttribute("EW_color");
m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); m_GLtexture = m_GLprogram->getAttribute("EW_texture2d");
@ -51,11 +50,11 @@ void ewol::compositing::Area::draw(bool _disableDepthTest) {
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_resource == NULL) { if (m_resource == nullptr) {
// this is a normale case ... the user can choice to have no image ... // this is a normale case ... the user can choice to have no image ...
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }

View File

@ -22,14 +22,14 @@ namespace ewol {
vec3 m_position; //!< The current position to draw vec3 m_position; //!< The current position to draw
etk::Color<> m_color; //!< The text foreground color etk::Color<> m_color; //!< The text foreground color
private: private:
ewol::resource::Program* m_GLprogram; //!< pointer on the opengl display program ewol::object::Shared<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
int32_t m_GLColor; //!< openGL id on the element (color buffer) int32_t m_GLColor; //!< openGL id on the element (color buffer)
int32_t m_GLtexture; //!< openGL id on the element (Texture position) int32_t m_GLtexture; //!< openGL id on the element (Texture position)
int32_t m_GLtexID; //!< openGL id on the element (texture ID) int32_t m_GLtexID; //!< openGL id on the element (texture ID)
private: private:
ewol::resource::Texture* m_resource; //!< texture resources ewol::object::Shared<ewol::resource::Texture> m_resource; //!< texture resources
std::vector<vec3 > m_coord; //!< internal coord of the object std::vector<vec3 > m_coord; //!< internal coord of the object
std::vector<vec2 > m_coordTex; //!< internal texture coordinate for every point std::vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
std::vector<etk::Color<float> > m_coordColor; //!< internal color of the different point std::vector<etk::Color<float> > m_coordColor; //!< internal color of the different point
@ -47,7 +47,7 @@ namespace ewol {
/** /**
* @brief generic destructor * @brief generic destructor
*/ */
~Area(); virtual ~Area();
public: public:
/** /**
* @brief draw All the refistered text in the current element on openGL * @brief draw All the refistered text in the current element on openGL

View File

@ -224,7 +224,7 @@ ewol::compositing::Drawing::Drawing() :
m_clippingEnable(false), m_clippingEnable(false),
m_color(etk::color::black), m_color(etk::color::black),
m_colorBg(etk::color::none), m_colorBg(etk::color::none),
m_GLprogram(NULL), m_GLprogram(nullptr),
m_GLPosition(-1), m_GLPosition(-1),
m_GLMatrix(-1), m_GLMatrix(-1),
m_GLColor(-1), m_GLColor(-1),
@ -277,7 +277,7 @@ void ewol::compositing::Drawing::resetCount() {
} }
void ewol::compositing::Drawing::unLoadProgram() { void ewol::compositing::Drawing::unLoadProgram() {
ewol::resource::Program::release(m_GLprogram); m_GLprogram.reset();
} }
void ewol::compositing::Drawing::loadProgram() { void ewol::compositing::Drawing::loadProgram() {
@ -286,7 +286,7 @@ void ewol::compositing::Drawing::loadProgram() {
// oad the new ... // oad the new ...
m_GLprogram = ewol::resource::Program::keep("DATA:color3.prog"); m_GLprogram = ewol::resource::Program::keep("DATA:color3.prog");
// get the shader resource : // get the shader resource :
if (NULL != m_GLprogram ) { if (nullptr != m_GLprogram ) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getAttribute("EW_color"); m_GLColor = m_GLprogram->getAttribute("EW_color");
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
@ -299,7 +299,7 @@ void ewol::compositing::Drawing::draw(bool _disableDepthTest) {
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }

View File

@ -28,7 +28,7 @@ namespace ewol {
etk::Color<> m_color; //!< The text foreground color etk::Color<> m_color; //!< The text foreground color
etk::Color<> m_colorBg; //!< The text background color etk::Color<> m_colorBg; //!< The text background color
private: private:
ewol::resource::Program* m_GLprogram; //!< pointer on the opengl display program ewol::object::Shared<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
int32_t m_GLColor; //!< openGL id on the element (color buffer) int32_t m_GLColor; //!< openGL id on the element (color buffer)
@ -43,7 +43,7 @@ namespace ewol {
/** /**
* @brief Basic destructor * @brief Basic destructor
*/ */
~Drawing(); virtual ~Drawing();
private: private:
/** /**
* @brief load the openGL program and get all the ID needed * @brief load the openGL program and get all the ID needed

View File

@ -21,35 +21,33 @@ ewol::compositing::Image::Image(const std::string& _imageName, bool _df) :
m_clippingEnable(false), m_clippingEnable(false),
m_color(etk::color::white), m_color(etk::color::white),
m_angle(0.0), m_angle(0.0),
m_GLprogram(NULL), m_GLprogram(nullptr),
m_GLPosition(-1), m_GLPosition(-1),
m_GLMatrix(-1), m_GLMatrix(-1),
m_GLColor(-1), m_GLColor(-1),
m_GLtexture(-1), m_GLtexture(-1),
m_GLtexID(-1), m_GLtexID(-1),
m_distanceFieldMode(_df), m_distanceFieldMode(_df),
m_resource(NULL), m_resource(nullptr),
m_resourceDF(NULL) { m_resourceDF(nullptr) {
setSource(_imageName); setSource(_imageName);
loadProgram(); loadProgram();
} }
ewol::compositing::Image::~Image() { ewol::compositing::Image::~Image() {
ewol::resource::TextureFile::release(m_resource);
ewol::resource::ImageDF::release(m_resourceDF);
ewol::resource::Program::release(m_GLprogram);
} }
void ewol::compositing::Image::loadProgram() { void ewol::compositing::Image::loadProgram() {
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
ewol::resource::Program::release(m_GLprogram); m_GLprogram.reset();
if (m_distanceFieldMode == true) { if (m_distanceFieldMode == true) {
m_GLprogram = ewol::resource::Program::keep("DATA:texturedDF.prog"); m_GLprogram = ewol::resource::Program::keep("DATA:texturedDF.prog");
} else { } else {
m_GLprogram = ewol::resource::Program::keep("DATA:textured3D.prog"); m_GLprogram = ewol::resource::Program::keep("DATA:textured3D.prog");
} }
if (m_GLprogram != NULL) { if (m_GLprogram != nullptr) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getAttribute("EW_color"); m_GLColor = m_GLprogram->getAttribute("EW_color");
m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); m_GLtexture = m_GLprogram->getAttribute("EW_texture2d");
@ -63,12 +61,12 @@ void ewol::compositing::Image::draw(bool _disableDepthTest) {
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if ( m_resource == NULL if ( m_resource == nullptr
&& m_resourceDF == NULL) { && m_resourceDF == nullptr) {
// this is a normale case ... the user can choice to have no image ... // this is a normale case ... the user can choice to have no image ...
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -82,7 +80,7 @@ void ewol::compositing::Image::draw(bool _disableDepthTest) {
m_GLprogram->use(); m_GLprogram->use();
m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// TextureID // TextureID
if (m_resource != NULL) { if (m_resource != nullptr) {
if (m_distanceFieldMode == true) { if (m_distanceFieldMode == true) {
EWOL_ERROR("FONT type error Request distance field and display normal ..."); EWOL_ERROR("FONT type error Request distance field and display normal ...");
} }
@ -249,58 +247,55 @@ void ewol::compositing::Image::printPart(const vec2& _size,
void ewol::compositing::Image::setSource(const std::string& _newFile, const vec2& _size) { void ewol::compositing::Image::setSource(const std::string& _newFile, const vec2& _size) {
clear(); clear();
ewol::resource::TextureFile* resource = m_resource; ewol::object::Shared<ewol::resource::TextureFile> resource(m_resource);
ewol::resource::ImageDF* resourceDF = m_resourceDF; ewol::object::Shared<ewol::resource::ImageDF> resourceDF(m_resourceDF);
m_filename = _newFile; m_filename = _newFile;
m_requestSize = _size; m_requestSize = _size;
m_resource = NULL; m_resource.reset();
m_resourceDF = NULL; m_resourceDF.reset();
ivec2 tmpSize(_size.x(),_size.y()); ivec2 tmpSize(_size.x(),_size.y());
// note that no image can be loaded... // note that no image can be loaded...
if (_newFile != "") { if (_newFile != "") {
// link to new one // link to new one
if (m_distanceFieldMode == false) { if (m_distanceFieldMode == false) {
m_resource = ewol::resource::TextureFile::keep(m_filename, tmpSize); m_resource = ewol::resource::TextureFile::keep(m_filename, tmpSize);
if (NULL == m_resource) { if (m_resource == nullptr) {
EWOL_ERROR("Can not get Image resource"); EWOL_ERROR("Can not get Image resource");
} }
} else { } else {
m_resourceDF = ewol::resource::ImageDF::keep(m_filename, tmpSize); m_resourceDF = ewol::resource::ImageDF::keep(m_filename, tmpSize);
if (NULL == m_resourceDF) { if (m_resourceDF == nullptr) {
EWOL_ERROR("Can not get Image resource DF"); EWOL_ERROR("Can not get Image resource DF");
} }
} }
} }
if ( m_resource == NULL if ( m_resource == nullptr
&& m_resourceDF == NULL) { && m_resourceDF == nullptr) {
if (resource != NULL) { if (resource != nullptr) {
EWOL_WARNING("Retrive previous resource"); EWOL_WARNING("Retrive previous resource");
m_resource = resource; m_resource = resource;
} }
if (resourceDF != NULL) { if (resourceDF != nullptr) {
EWOL_WARNING("Retrive previous resource (DF)"); EWOL_WARNING("Retrive previous resource (DF)");
m_resourceDF = resourceDF; m_resourceDF = resourceDF;
} }
} else {
ewol::resource::TextureFile::release(resource);
ewol::resource::ImageDF::release(resourceDF);
} }
} }
bool ewol::compositing::Image::hasSources() { bool ewol::compositing::Image::hasSources() {
return (m_resource != NULL || m_resourceDF != NULL); return (m_resource != nullptr || m_resourceDF != nullptr);
} }
vec2 ewol::compositing::Image::getRealSize() { vec2 ewol::compositing::Image::getRealSize() {
if ( m_resource == NULL if ( m_resource == nullptr
&& m_resourceDF == NULL) { && m_resourceDF == nullptr) {
return vec2(0,0); return vec2(0,0);
} }
if (m_resource != NULL) { if (m_resource != nullptr) {
return m_resource->getRealSize(); return m_resource->getRealSize();
} }
if (m_resourceDF != NULL) { if (m_resourceDF != nullptr) {
return m_resourceDF->getRealSize(); return m_resourceDF->getRealSize();
} }
return vec2(0,0); return vec2(0,0);

View File

@ -29,7 +29,7 @@ namespace ewol {
etk::Color<> m_color; //!< The text foreground color etk::Color<> m_color; //!< The text foreground color
float m_angle; //!< Angle to set at the axes float m_angle; //!< Angle to set at the axes
private: private:
ewol::resource::Program* m_GLprogram; //!< pointer on the opengl display program ewol::object::Shared<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
int32_t m_GLColor; //!< openGL id on the element (color buffer) int32_t m_GLColor; //!< openGL id on the element (color buffer)
@ -37,8 +37,8 @@ namespace ewol {
int32_t m_GLtexID; //!< openGL id on the element (texture ID) int32_t m_GLtexID; //!< openGL id on the element (texture ID)
private: private:
bool m_distanceFieldMode; //!< select distance field mode bool m_distanceFieldMode; //!< select distance field mode
ewol::resource::TextureFile* m_resource; //!< texture resources ewol::object::Shared<ewol::resource::TextureFile> m_resource; //!< texture resources
ewol::resource::ImageDF* m_resourceDF; //!< texture resources ewol::object::Shared<ewol::resource::ImageDF> m_resourceDF; //!< texture resources
std::vector<vec3 > m_coord; //!< internal coord of the object std::vector<vec3 > m_coord; //!< internal coord of the object
std::vector<vec2 > m_coordTex; //!< internal texture coordinate for every point std::vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
std::vector<etk::Color<float> > m_coordColor; //!< internal color of the different point std::vector<etk::Color<float> > m_coordColor; //!< internal color of the different point

View File

@ -15,21 +15,21 @@
ewol::compositing::Shaper::Shaper(const std::string& _shaperName) : ewol::compositing::Shaper::Shaper(const std::string& _shaperName) :
m_name(_shaperName), m_name(_shaperName),
m_config(NULL), m_config(nullptr),
m_confIdMode(-1), m_confIdMode(-1),
m_confIdDisplayOutside(-1), m_confIdDisplayOutside(-1),
m_confIdChangeTime(-1), m_confIdChangeTime(-1),
m_confProgramFile(-1), m_confProgramFile(-1),
m_confColorFile(-1), m_confColorFile(-1),
m_confImageFile(-1), m_confImageFile(-1),
m_GLprogram(NULL), m_GLprogram(nullptr),
m_GLPosition(-1), m_GLPosition(-1),
m_GLMatrix(-1), m_GLMatrix(-1),
m_GLStateActivate(-1), m_GLStateActivate(-1),
m_GLStateOld(-1), m_GLStateOld(-1),
m_GLStateNew(-1), m_GLStateNew(-1),
m_GLStateTransition(-1), m_GLStateTransition(-1),
m_resourceTexture(NULL), m_resourceTexture(nullptr),
m_nextStatusRequested(-1), m_nextStatusRequested(-1),
m_propertyOrigin(0,0), m_propertyOrigin(0,0),
m_propertySize(0,0), m_propertySize(0,0),
@ -57,10 +57,10 @@ ewol::compositing::Shaper::~Shaper() {
} }
void ewol::compositing::Shaper::unLoadProgram() { void ewol::compositing::Shaper::unLoadProgram() {
ewol::resource::Program::release(m_GLprogram); m_GLprogram.reset();
ewol::resource::TextureFile::release(m_resourceTexture); m_resourceTexture.reset();
ewol::resource::ConfigFile::release(m_config); m_config.reset();
ewol::resource::ColorFile::release(m_colorProperty); m_colorProperty.reset();
for (size_t iii=0; iii<shaperPosCount; ++iii) { for (size_t iii=0; iii<shaperPosCount; ++iii) {
m_confIdPaddingOut[iii] = -1; m_confIdPaddingOut[iii] = -1;
m_confIdBorder[iii] = -1; m_confIdBorder[iii] = -1;
@ -85,7 +85,7 @@ void ewol::compositing::Shaper::loadProgram() {
return; return;
} }
m_config = ewol::resource::ConfigFile::keep(m_name); m_config = ewol::resource::ConfigFile::keep(m_name);
if (NULL != m_config) { if (nullptr != m_config) {
m_confIdMode = m_config->request("mode"); m_confIdMode = m_config->request("mode");
m_confIdDisplayOutside = m_config->request("display-outside"); m_confIdDisplayOutside = m_config->request("display-outside");
m_confIdPaddingOut[shaperPosLeft] = m_config->request("padding-out-left"); m_confIdPaddingOut[shaperPosLeft] = m_config->request("padding-out-left");
@ -119,7 +119,7 @@ void ewol::compositing::Shaper::loadProgram() {
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
m_GLprogram = ewol::resource::Program::keep(tmpFilename); m_GLprogram = ewol::resource::Program::keep(tmpFilename);
if (m_GLprogram != NULL) { if (m_GLprogram != nullptr) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord2d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord2d");
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
// Widget property == > for the Vertex shader // Widget property == > for the Vertex shader
@ -159,8 +159,8 @@ void ewol::compositing::Shaper::loadProgram() {
EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "'"); EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "'");
} }
m_colorProperty = ewol::resource::ColorFile::keep(tmpFilename); m_colorProperty = ewol::resource::ColorFile::keep(tmpFilename);
if ( m_GLprogram != NULL if ( m_GLprogram != nullptr
&& m_colorProperty != NULL) { && m_colorProperty != nullptr) {
std::vector<std::string> listColor = m_colorProperty->getColors(); std::vector<std::string> listColor = m_colorProperty->getColors();
for (auto tmpColor : listColor) { for (auto tmpColor : listColor) {
int32_t glId = m_GLprogram->getUniform(tmpColor); int32_t glId = m_GLprogram->getUniform(tmpColor);
@ -172,11 +172,11 @@ void ewol::compositing::Shaper::loadProgram() {
} }
void ewol::compositing::Shaper::draw(bool _disableDepthTest) { void ewol::compositing::Shaper::draw(bool _disableDepthTest) {
if (m_config == NULL) { if (m_config == nullptr) {
// this is a normale case ... the user can choice to have no config basic file ... // this is a normale case ... the user can choice to have no config basic file ...
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -197,7 +197,7 @@ void ewol::compositing::Shaper::draw(bool _disableDepthTest) {
for (auto element : m_listAssiciatedId) { for (auto element : m_listAssiciatedId) {
m_GLprogram->uniform(element.x(), m_colorProperty->get(element.y())); m_GLprogram->uniform(element.x(), m_colorProperty->get(element.y()));
} }
if (NULL!=m_resourceTexture) { if (nullptr!=m_resourceTexture) {
// TextureID // TextureID
m_GLprogram->setTexture0(m_GLtexID, m_resourceTexture->getId()); m_GLprogram->setTexture0(m_GLtexID, m_resourceTexture->getId());
} }
@ -471,7 +471,7 @@ void ewol::compositing::Shaper::setShape(const vec2& _origin, const vec2& _size,
EWOL_ERROR(" inside = " << inside); EWOL_ERROR(" inside = " << inside);
*/ */
int32_t mode = 0; int32_t mode = 0;
if (m_config != NULL) { if (m_config != nullptr) {
mode = m_config->getNumber(m_confIdMode); mode = m_config->getNumber(m_confIdMode);
} }
bool displayOutside = m_config->getBoolean(m_confIdDisplayOutside); bool displayOutside = m_config->getBoolean(m_confIdDisplayOutside);
@ -572,7 +572,7 @@ ewol::Padding ewol::compositing::Shaper::getPadding() {
ewol::Padding ewol::compositing::Shaper::getPaddingIn() { ewol::Padding ewol::compositing::Shaper::getPaddingIn() {
ewol::Padding padding(0,0,0,0); ewol::Padding padding(0,0,0,0);
if (m_config != NULL) { if (m_config != nullptr) {
padding.setValue(m_config->getNumber(m_confIdPaddingIn[shaperPosLeft]), padding.setValue(m_config->getNumber(m_confIdPaddingIn[shaperPosLeft]),
m_config->getNumber(m_confIdPaddingIn[shaperPosTop]), m_config->getNumber(m_confIdPaddingIn[shaperPosTop]),
m_config->getNumber(m_confIdPaddingIn[shaperPosRight]), m_config->getNumber(m_confIdPaddingIn[shaperPosRight]),
@ -583,7 +583,7 @@ ewol::Padding ewol::compositing::Shaper::getPaddingIn() {
ewol::Padding ewol::compositing::Shaper::getPaddingOut() { ewol::Padding ewol::compositing::Shaper::getPaddingOut() {
ewol::Padding padding(0,0,0,0); ewol::Padding padding(0,0,0,0);
if (m_config != NULL) { if (m_config != nullptr) {
padding.setValue(m_config->getNumber(m_confIdPaddingOut[shaperPosLeft]), padding.setValue(m_config->getNumber(m_confIdPaddingOut[shaperPosLeft]),
m_config->getNumber(m_confIdPaddingOut[shaperPosTop]), m_config->getNumber(m_confIdPaddingOut[shaperPosTop]),
m_config->getNumber(m_confIdPaddingOut[shaperPosRight]), m_config->getNumber(m_confIdPaddingOut[shaperPosRight]),
@ -594,7 +594,7 @@ ewol::Padding ewol::compositing::Shaper::getPaddingOut() {
ewol::Padding ewol::compositing::Shaper::getBorder() { ewol::Padding ewol::compositing::Shaper::getBorder() {
ewol::Padding padding(0,0,0,0); ewol::Padding padding(0,0,0,0);
if (m_config != NULL) { if (m_config != nullptr) {
padding.setValue(m_config->getNumber(m_confIdBorder[shaperPosLeft]), padding.setValue(m_config->getNumber(m_confIdBorder[shaperPosLeft]),
m_config->getNumber(m_confIdBorder[shaperPosTop]), m_config->getNumber(m_confIdBorder[shaperPosTop]),
m_config->getNumber(m_confIdBorder[shaperPosRight]), m_config->getNumber(m_confIdBorder[shaperPosRight]),
@ -611,13 +611,13 @@ void ewol::compositing::Shaper::setSource(const std::string& _newFile) {
} }
bool ewol::compositing::Shaper::hasSources() { bool ewol::compositing::Shaper::hasSources() {
return m_GLprogram!=NULL; return m_GLprogram!=nullptr;
} }
const etk::Color<float>& ewol::compositing::Shaper::getColor(int32_t _id) { const etk::Color<float>& ewol::compositing::Shaper::getColor(int32_t _id) {
static const etk::Color<float> errorValue(0,0,0,0); static const etk::Color<float> errorValue(0,0,0,0);
if (m_colorProperty == NULL) { if (m_colorProperty == nullptr) {
return errorValue; return errorValue;
} }
return m_colorProperty->get(_id); return m_colorProperty->get(_id);

View File

@ -44,7 +44,7 @@ namespace ewol {
private: private:
std::string m_name; //!< Name of the configuration of the shaper. std::string m_name; //!< Name of the configuration of the shaper.
// External theme config: // External theme config:
ewol::resource::ConfigFile* m_config; //!< pointer on the config file resources ewol::object::Shared<ewol::resource::ConfigFile> m_config; //!< pointer on the config file resources
int32_t m_confIdDisplayExternal; //!< Display external border int32_t m_confIdDisplayExternal; //!< Display external border
int32_t m_confIdPaddingOut[shaperPosCount]; //!< Padding out property : X-left X-right Y-top Y-buttom int32_t m_confIdPaddingOut[shaperPosCount]; //!< Padding out property : X-left X-right Y-top Y-buttom
int32_t m_confIdBorder[shaperPosCount]; //!< border property : X-left X-right Y-top Y-buttom int32_t m_confIdBorder[shaperPosCount]; //!< border property : X-left X-right Y-top Y-buttom
@ -56,7 +56,7 @@ namespace ewol {
int32_t m_confColorFile; //!< ConfigFile opengGl color file Name int32_t m_confColorFile; //!< ConfigFile opengGl color file Name
int32_t m_confImageFile; //!< ConfigFile opengGl program Name int32_t m_confImageFile; //!< ConfigFile opengGl program Name
// openGL shaders programs: // openGL shaders programs:
ewol::resource::Program* m_GLprogram; //!< pointer on the opengl display program ewol::object::Shared<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
int32_t m_GLPropertyPos; //!< openGL id on the element (simple ratio position in the widget : ____/-----\_____ on vec2(X,Y)) int32_t m_GLPropertyPos; //!< openGL id on the element (simple ratio position in the widget : ____/-----\_____ on vec2(X,Y))
@ -66,7 +66,7 @@ namespace ewol {
int32_t m_GLStateTransition; //!< openGL id on the element (transition ofset [0.0..1.0] ) int32_t m_GLStateTransition; //!< openGL id on the element (transition ofset [0.0..1.0] )
int32_t m_GLtexID; //!< openGL id on the element (texture image) int32_t m_GLtexID; //!< openGL id on the element (texture image)
// For the Image : // For the Image :
ewol::resource::TextureFile* m_resourceTexture; //!< texture resources (for the image) ewol::object::Shared<ewol::resource::TextureFile> m_resourceTexture; //!< texture resources (for the image)
// internal needed data : // internal needed data :
int32_t m_nextStatusRequested; //!< when status is changing, this represent the next step of it int32_t m_nextStatusRequested; //!< when status is changing, this represent the next step of it
vec2 m_propertyOrigin; //!< widget origin vec2 m_propertyOrigin; //!< widget origin
@ -81,7 +81,7 @@ namespace ewol {
vec2 m_pos[SHAPER_NB_MAX_VERTEX]; //!< podition to display property vec2 m_pos[SHAPER_NB_MAX_VERTEX]; //!< podition to display property
int32_t m_nbVertexToDisplay; int32_t m_nbVertexToDisplay;
// color management theme: // color management theme:
ewol::resource::ColorFile* m_colorProperty; //!< input resource for color management ewol::object::Shared<ewol::resource::ColorFile> m_colorProperty; //!< input resource for color management
std::vector<ivec2> m_listAssiciatedId; //!< Corellation ID between ColorProperty (Y) and OpenGL Program (X) std::vector<ivec2> m_listAssiciatedId; //!< Corellation ID between ColorProperty (Y) and OpenGL Program (X)
private: private:
/** /**
@ -101,7 +101,7 @@ namespace ewol {
/** /**
* @brief generic destructor * @brief generic destructor
*/ */
~Shaper(); virtual ~Shaper();
public: public:
/** /**
* @brief draw All the refistered text in the current element on openGL * @brief draw All the refistered text in the current element on openGL
@ -233,7 +233,7 @@ namespace ewol {
* @return The Id of the color * @return The Id of the color
*/ */
int32_t requestColor(const std::string& _name) { int32_t requestColor(const std::string& _name) {
if (m_colorProperty == NULL) { if (m_colorProperty == nullptr) {
return -1; return -1;
} }
return m_colorProperty->request(_name); return m_colorProperty->request(_name);
@ -251,7 +251,7 @@ namespace ewol {
* @return The Id of the element * @return The Id of the element
*/ */
int32_t requestConfig(const std::string& _name) { int32_t requestConfig(const std::string& _name) {
if (m_config == NULL) { if (m_config == nullptr) {
return -1; return -1;
} }
return m_config->request(_name); return m_config->request(_name);
@ -263,7 +263,7 @@ namespace ewol {
*/ */
double getConfigNumber(int32_t _id) { double getConfigNumber(int32_t _id) {
if ( _id == -1 if ( _id == -1
|| m_config == NULL) { || m_config == nullptr) {
return 0.0; return 0.0;
} }
return m_config->getNumber(_id); return m_config->getNumber(_id);

View File

@ -16,13 +16,13 @@
ewol::compositing::Text::Text(const std::string& _fontName, int32_t _fontSize) : ewol::compositing::Text::Text(const std::string& _fontName, int32_t _fontSize) :
m_font(NULL) { m_font(nullptr) {
setFont(_fontName, _fontSize); setFont(_fontName, _fontSize);
} }
ewol::compositing::Text::~Text() { ewol::compositing::Text::~Text() {
ewol::resource::TexturedFont::release(m_font);
} }
void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _enableDepthTest) { void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _enableDepthTest) {
@ -30,16 +30,16 @@ void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _en
// draw BG in any case: // draw BG in any case:
m_vectorialDraw.draw(); m_vectorialDraw.draw();
if (m_coord.size() <= 0 || m_font == NULL) { if (m_coord.size() <= 0 || m_font == nullptr) {
// TODO : a remÃtre ... // TODO : a remÃtre ...
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -74,16 +74,16 @@ void ewol::compositing::Text::drawD(bool _disableDepthTest) {
// draw BG in any case: // draw BG in any case:
m_vectorialDraw.draw(); m_vectorialDraw.draw();
if (m_coord.size() <= 0 || m_font == NULL) { if (m_coord.size() <= 0 || m_font == nullptr) {
// TODO : a remèe ... // TODO : a remèe ...
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -107,23 +107,23 @@ void ewol::compositing::Text::drawD(bool _disableDepthTest) {
} }
float ewol::compositing::Text::getSize() { float ewol::compositing::Text::getSize() {
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return 1.0f; return 1.0f;
} }
return m_font->getFontSize(); return m_font->getFontSize();
} }
float ewol::compositing::Text::getHeight() { float ewol::compositing::Text::getHeight() {
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return 10.0f; return 10.0f;
} }
return m_font->getHeight(m_mode); return m_font->getHeight(m_mode);
} }
ewol::GlyphProperty * ewol::compositing::Text::getGlyphPointer(char32_t _charcode) { ewol::GlyphProperty * ewol::compositing::Text::getGlyphPointer(char32_t _charcode) {
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return NULL; return nullptr;
} }
return m_font->getGlyphPointer(_charcode, m_mode); return m_font->getGlyphPointer(_charcode, m_mode);
} }
@ -131,7 +131,7 @@ ewol::GlyphProperty * ewol::compositing::Text::getGlyphPointer(char32_t _charcod
void ewol::compositing::Text::setFontSize(int32_t _fontSize) { void ewol::compositing::Text::setFontSize(int32_t _fontSize) {
// get old size // get old size
std::string fontName = ""; std::string fontName = "";
if (m_font != NULL) { if (m_font != nullptr) {
fontName = m_font->getName(); fontName = m_font->getName();
// Remove the :XX for the size ... // Remove the :XX for the size ...
size_t pos = fontName.rfind(':'); size_t pos = fontName.rfind(':');
@ -143,7 +143,7 @@ void ewol::compositing::Text::setFontSize(int32_t _fontSize) {
void ewol::compositing::Text::setFontName(const std::string& _fontName) { void ewol::compositing::Text::setFontName(const std::string& _fontName) {
// get old size // get old size
int32_t fontSize = -1; int32_t fontSize = -1;
if (m_font != NULL) { if (m_font != nullptr) {
fontSize = m_font->getFontSize(); fontSize = m_font->getFontSize();
} }
setFont(_fontName, fontSize); setFont(_fontName, fontSize);
@ -152,7 +152,7 @@ void ewol::compositing::Text::setFontName(const std::string& _fontName) {
void ewol::compositing::Text::setFont(std::string _fontName, int32_t _fontSize) { void ewol::compositing::Text::setFont(std::string _fontName, int32_t _fontSize) {
clear(); clear();
// remove old one // remove old one
ewol::resource::TexturedFont * previousFont = m_font; ewol::object::Shared<ewol::resource::TexturedFont> previousFont = m_font;
if (_fontSize <= 0) { if (_fontSize <= 0) {
_fontSize = ewol::getContext().getFontDefault().getSize(); _fontSize = ewol::getContext().getFontDefault().getSize();
} }
@ -164,16 +164,14 @@ void ewol::compositing::Text::setFont(std::string _fontName, int32_t _fontSize)
EWOL_VERBOSE("plop : " << _fontName << " size=" << _fontSize << " result :" << _fontName); EWOL_VERBOSE("plop : " << _fontName << " size=" << _fontSize << " result :" << _fontName);
// link to new one // link to new one
m_font = ewol::resource::TexturedFont::keep(_fontName); m_font = ewol::resource::TexturedFont::keep(_fontName);
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_ERROR("Can not get font resource"); EWOL_ERROR("Can not get font resource");
m_font = previousFont; m_font = previousFont;
} else {
ewol::resource::TexturedFont::release(previousFont);
} }
} }
void ewol::compositing::Text::setFontMode(enum ewol::font::mode _mode) { void ewol::compositing::Text::setFontMode(enum ewol::font::mode _mode) {
if (m_font != NULL) { if (m_font != nullptr) {
m_mode = m_font->getWrappingMode(_mode); m_mode = m_font->getWrappingMode(_mode);
} }
} }
@ -181,7 +179,7 @@ void ewol::compositing::Text::setFontMode(enum ewol::font::mode _mode) {
void ewol::compositing::Text::printChar(const char32_t& _charcode) { void ewol::compositing::Text::printChar(const char32_t& _charcode) {
// get a pointer on the glyph property : // get a pointer on the glyph property :
ewol::GlyphProperty* myGlyph = getGlyphPointer(_charcode); ewol::GlyphProperty* myGlyph = getGlyphPointer(_charcode);
if (NULL == myGlyph) { if (nullptr == myGlyph) {
EWOL_ERROR(" font does not really existed ..."); EWOL_ERROR(" font does not really existed ...");
return; return;
} }

View File

@ -25,7 +25,7 @@ namespace ewol {
namespace compositing { namespace compositing {
class Text : public ewol::compositing::TextBase { class Text : public ewol::compositing::TextBase {
protected: protected:
ewol::resource::TexturedFont* m_font; //!< Font resources ewol::object::Shared<ewol::resource::TexturedFont> m_font; //!< Font resources
public: public:
/** /**
* @brief generic constructor * @brief generic constructor

View File

@ -32,7 +32,7 @@ ewol::compositing::TextBase::TextBase(const std::string& _shaderName, bool _load
m_startTextpos(0), m_startTextpos(0),
m_stopTextPos(0), m_stopTextPos(0),
m_alignement(alignDisable), m_alignement(alignDisable),
m_GLprogram(NULL), m_GLprogram(nullptr),
m_GLPosition(-1), m_GLPosition(-1),
m_GLMatrix(-1), m_GLMatrix(-1),
m_GLColor(-1), m_GLColor(-1),
@ -47,15 +47,15 @@ ewol::compositing::TextBase::TextBase(const std::string& _shaderName, bool _load
ewol::compositing::TextBase::~TextBase() { ewol::compositing::TextBase::~TextBase() {
ewol::resource::Program::release(m_GLprogram);
} }
void ewol::compositing::TextBase::loadProgram(const std::string& _shaderName) { void ewol::compositing::TextBase::loadProgram(const std::string& _shaderName) {
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
ewol::resource::Program* old = m_GLprogram; ewol::object::Shared<ewol::resource::Program> old = m_GLprogram;
m_GLprogram = ewol::resource::Program::keep(_shaderName); m_GLprogram = ewol::resource::Program::keep(_shaderName);
if (m_GLprogram != NULL) { if (m_GLprogram != nullptr) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getAttribute("EW_color"); m_GLColor = m_GLprogram->getAttribute("EW_color");
m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); m_GLtexture = m_GLprogram->getAttribute("EW_texture2d");
@ -66,10 +66,8 @@ void ewol::compositing::TextBase::loadProgram(const std::string& _shaderName) {
} else { } else {
EWOL_ERROR("Can not load the program => keep previous one..."); EWOL_ERROR("Can not load the program => keep previous one...");
m_GLprogram = old; m_GLprogram = old;
old = NULL; old = nullptr;
} }
// Release old program if needed ...
ewol::resource::Program::release(old);
} }
void ewol::compositing::TextBase::translate(const vec3& _vect) { void ewol::compositing::TextBase::translate(const vec3& _vect) {
@ -249,7 +247,7 @@ void ewol::compositing::TextBase::print(const std::string& _text) {
void ewol::compositing::TextBase::parseHtmlNode(exml::Element* _element) { void ewol::compositing::TextBase::parseHtmlNode(exml::Element* _element) {
// get the static real pointer // get the static real pointer
if (_element == NULL) { if (_element == nullptr) {
EWOL_ERROR( "Error Input node does not existed ..."); EWOL_ERROR( "Error Input node does not existed ...");
} }
for(size_t iii=0; iii< _element->size(); iii++) { for(size_t iii=0; iii< _element->size(); iii++) {
@ -265,7 +263,7 @@ void ewol::compositing::TextBase::parseHtmlNode(exml::Element* _element) {
continue; continue;
} }
exml::Element* elem = _element->getElement(iii); exml::Element* elem = _element->getElement(iii);
if (elem == NULL) { if (elem == nullptr) {
EWOL_ERROR("Cast error ..."); EWOL_ERROR("Cast error ...");
continue; continue;
} }
@ -372,13 +370,13 @@ void ewol::compositing::TextBase::printHTML(const std::string& _text) {
} }
exml::Element* root = (exml::Element*)doc.getNamed( "html" ); exml::Element* root = (exml::Element*)doc.getNamed( "html" );
if (root == NULL) { if (root == nullptr) {
EWOL_ERROR( "can not load XML: main node not find: \"html\""); EWOL_ERROR( "can not load XML: main node not find: \"html\"");
doc.display(); doc.display();
return; return;
} }
exml::Element* bodyNode = (exml::Element*)root->getNamed( "body" ); exml::Element* bodyNode = (exml::Element*)root->getNamed( "body" );
if (root == NULL) { if (root == nullptr) {
EWOL_ERROR( "can not load XML: main node not find: \"body\""); EWOL_ERROR( "can not load XML: main node not find: \"body\"");
return; return;
} }
@ -400,13 +398,13 @@ void ewol::compositing::TextBase::printHTML(const std::u32string& _text) {
} }
exml::Element* root = (exml::Element*)doc.getNamed( "html" ); exml::Element* root = (exml::Element*)doc.getNamed( "html" );
if (root == NULL) { if (root == nullptr) {
EWOL_ERROR( "can not load XML: main node not find: \"html\""); EWOL_ERROR( "can not load XML: main node not find: \"html\"");
doc.display(); doc.display();
return; return;
} }
exml::Element* bodyNode = (exml::Element*)root->getNamed( "body" ); exml::Element* bodyNode = (exml::Element*)root->getNamed( "body" );
if (root == NULL) { if (root == nullptr) {
EWOL_ERROR( "can not load XML: main node not find: \"body\""); EWOL_ERROR( "can not load XML: main node not find: \"body\"");
return; return;
} }

View File

@ -77,7 +77,7 @@ namespace ewol {
float m_stopTextPos; //!< end of the alignement (when a string is too hight it cut at the word previously this virtual line and the center is perform with this one) float m_stopTextPos; //!< end of the alignement (when a string is too hight it cut at the word previously this virtual line and the center is perform with this one)
enum aligneMode m_alignement; //!< Current Alignement mode (justify/left/right ...) enum aligneMode m_alignement; //!< Current Alignement mode (justify/left/right ...)
protected: protected:
ewol::resource::Program* m_GLprogram; //!< pointer on the opengl display program ewol::object::Shared<ewol::resource::Program> m_GLprogram; //!< pointer on the opengl display program
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
int32_t m_GLColor; //!< openGL id on the element (color buffer) int32_t m_GLColor; //!< openGL id on the element (color buffer)

View File

@ -17,7 +17,7 @@
ewol::compositing::TextDF::TextDF(const std::string& _fontName, int32_t _fontSize) : ewol::compositing::TextDF::TextDF(const std::string& _fontName, int32_t _fontSize) :
ewol::compositing::TextBase("", false), ewol::compositing::TextBase("", false),
m_fontDF(NULL), m_fontDF(nullptr),
m_GLglyphLevel(-1), m_GLglyphLevel(-1),
m_size(12.0) { m_size(12.0) {
setFont(_fontName, _fontSize); setFont(_fontName, _fontSize);
@ -26,12 +26,12 @@ ewol::compositing::TextDF::TextDF(const std::string& _fontName, int32_t _fontSiz
ewol::compositing::TextDF::~TextDF() { ewol::compositing::TextDF::~TextDF() {
ewol::resource::DistanceFieldFont::release(m_fontDF);
} }
void ewol::compositing::TextDF::updateSizeToRender(const vec2& _size) { void ewol::compositing::TextDF::updateSizeToRender(const vec2& _size) {
float minSize = etk_min(_size.x(), _size.y()); float minSize = etk_min(_size.x(), _size.y());
if (m_fontDF != NULL) { if (m_fontDF != nullptr) {
setFontSize(m_fontDF->getSize(minSize)); setFontSize(m_fontDF->getSize(minSize));
} }
} }
@ -42,15 +42,15 @@ void ewol::compositing::TextDF::drawMT(const mat4& _transformationMatrix, bool _
// draw BG in any case: // draw BG in any case:
m_vectorialDraw.draw(); m_vectorialDraw.draw();
if (m_coord.size() <= 0 || m_fontDF == NULL) { if (m_coord.size() <= 0 || m_fontDF == nullptr) {
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_fontDF == NULL) { if (m_fontDF == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -84,16 +84,16 @@ void ewol::compositing::TextDF::drawD(bool _disableDepthTest) {
// draw BG in any case: // draw BG in any case:
m_vectorialDraw.draw(); m_vectorialDraw.draw();
if (m_coord.size() <= 0 || m_fontDF == NULL) { if (m_coord.size() <= 0 || m_fontDF == nullptr) {
// TODO : a remètre ... // TODO : a remètre ...
//EWOL_WARNING("Nothink to draw..."); //EWOL_WARNING("Nothink to draw...");
return; return;
} }
if (m_fontDF == NULL) { if (m_fontDF == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -120,14 +120,14 @@ void ewol::compositing::TextDF::clear() {
} }
void ewol::compositing::TextDF::loadProgram(const std::string& _shaderName) { void ewol::compositing::TextDF::loadProgram(const std::string& _shaderName) {
ewol::compositing::TextBase::loadProgram(_shaderName); ewol::compositing::TextBase::loadProgram(_shaderName);
if (m_GLprogram != NULL) { if (m_GLprogram != nullptr) {
m_GLglyphLevel = m_GLprogram->getAttribute("EW_glyphLevel"); m_GLglyphLevel = m_GLprogram->getAttribute("EW_glyphLevel");
} }
} }
float ewol::compositing::TextDF::getHeight() { float ewol::compositing::TextDF::getHeight() {
if (m_fontDF == NULL) { if (m_fontDF == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return 1; return 1;
} }
@ -135,9 +135,9 @@ float ewol::compositing::TextDF::getHeight() {
} }
ewol::GlyphProperty * ewol::compositing::TextDF::getGlyphPointer(char32_t _charcode) { ewol::GlyphProperty * ewol::compositing::TextDF::getGlyphPointer(char32_t _charcode) {
if (m_fontDF == NULL) { if (m_fontDF == nullptr) {
EWOL_WARNING("no font..."); EWOL_WARNING("no font...");
return NULL; return nullptr;
} }
return m_fontDF->getGlyphPointer(_charcode); return m_fontDF->getGlyphPointer(_charcode);
} }
@ -155,7 +155,7 @@ void ewol::compositing::TextDF::setFontSize(int32_t _fontSize) {
void ewol::compositing::TextDF::setFontName(const std::string& _fontName) { void ewol::compositing::TextDF::setFontName(const std::string& _fontName) {
clear(); clear();
// remove old one // remove old one
ewol::resource::DistanceFieldFont* previousFont = m_fontDF; ewol::object::Shared<ewol::resource::DistanceFieldFont> previousFont = m_fontDF;
std::string fontName; std::string fontName;
if (_fontName == "") { if (_fontName == "") {
fontName = ewol::getContext().getFontDefault().getName(); fontName = ewol::getContext().getFontDefault().getName();
@ -165,11 +165,9 @@ void ewol::compositing::TextDF::setFontName(const std::string& _fontName) {
EWOL_VERBOSE("Set font name: '" << fontName << "'"); EWOL_VERBOSE("Set font name: '" << fontName << "'");
// link to new one // link to new one
m_fontDF = ewol::resource::DistanceFieldFont::keep(fontName); m_fontDF = ewol::resource::DistanceFieldFont::keep(fontName);
if (m_fontDF == NULL) { if (m_fontDF == nullptr) {
EWOL_ERROR("Can not get find resource"); EWOL_ERROR("Can not get find resource");
m_fontDF = previousFont; m_fontDF = previousFont;
} else {
ewol::resource::DistanceFieldFont::release(previousFont);
} }
} }
@ -189,7 +187,7 @@ void ewol::compositing::TextDF::setFontMode(enum ewol::font::mode _mode) {
void ewol::compositing::TextDF::printChar(const char32_t& _charcode) { void ewol::compositing::TextDF::printChar(const char32_t& _charcode) {
// get a pointer on the glyph property : // get a pointer on the glyph property :
ewol::GlyphProperty* myGlyph = getGlyphPointer(_charcode); ewol::GlyphProperty* myGlyph = getGlyphPointer(_charcode);
if (NULL == myGlyph) { if (nullptr == myGlyph) {
EWOL_ERROR(" font does not really existed ..."); EWOL_ERROR(" font does not really existed ...");
return; return;
} }

View File

@ -23,7 +23,7 @@ namespace ewol {
namespace compositing { namespace compositing {
class TextDF : public ewol::compositing::TextBase { class TextDF : public ewol::compositing::TextBase {
protected: protected:
ewol::resource::DistanceFieldFont* m_fontDF; //!< Font resources ewol::object::Shared<ewol::resource::DistanceFieldFont> m_fontDF; //!< Font resources
std::vector<float> m_glyphLevel; //!< Level of display of the glyph (notmal : 0.50, bold : 0.40, super bold : 0.30 ...) std::vector<float> m_glyphLevel; //!< Level of display of the glyph (notmal : 0.50, bold : 0.40, super bold : 0.30 ...)
protected: protected:
int32_t m_GLglyphLevel; //!< openGL Id on the glyph level display int32_t m_GLglyphLevel; //!< openGL Id on the glyph level display

View File

@ -23,7 +23,7 @@
int64_t ewol::getTime() { int64_t ewol::getTime() {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, nullptr);
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec); return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec);
} }
@ -31,7 +31,7 @@ int64_t ewol::getTime() {
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include // jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
static JavaVM* g_JavaVM=NULL; // global acces on the unique JVM !!! static JavaVM* g_JavaVM=nullptr; // global acces on the unique JVM !!!
etk::Mutex g_interfaceMutex; etk::Mutex g_interfaceMutex;
etk::Mutex g_interfaceAudioMutex; etk::Mutex g_interfaceAudioMutex;
@ -78,10 +78,10 @@ class AndroidContext : public ewol::Context {
private: private:
bool safeInitMethodID(jmethodID& _mid, jclass& _cls, const char* _name, const char* _sign) { bool safeInitMethodID(jmethodID& _mid, jclass& _cls, const char* _name, const char* _sign) {
_mid = m_JavaVirtualMachinePointer->GetMethodID(_cls, _name, _sign); _mid = m_JavaVirtualMachinePointer->GetMethodID(_cls, _name, _sign);
if(_mid == NULL) { if(_mid == nullptr) {
EWOL_ERROR("C->java : Can't find the method " << _name); EWOL_ERROR("C->java : Can't find the method " << _name);
/* remove access on the virtual machine : */ /* remove access on the virtual machine : */
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
return false; return false;
} }
return true; return true;
@ -89,7 +89,7 @@ class AndroidContext : public ewol::Context {
public: public:
AndroidContext(JNIEnv* _env, jclass _classBase, jobject _objCallback, enum application _typeAPPL) : AndroidContext(JNIEnv* _env, jclass _classBase, jobject _objCallback, enum application _typeAPPL) :
m_javaApplicationType(_typeAPPL), m_javaApplicationType(_typeAPPL),
m_JavaVirtualMachinePointer(NULL), m_JavaVirtualMachinePointer(nullptr),
m_javaClassEwol(0), m_javaClassEwol(0),
m_javaClassEwolCallback(0), m_javaClassEwolCallback(0),
m_javaObjectEwolCallback(0), m_javaObjectEwolCallback(0),
@ -108,8 +108,8 @@ class AndroidContext : public ewol::Context {
m_javaDefaultClassString(0), m_javaDefaultClassString(0),
m_currentHeight(0), m_currentHeight(0),
m_clipBoardOwnerStd(false), m_clipBoardOwnerStd(false),
m_audioCallBack(NULL), m_audioCallBack(nullptr),
m_audioCallBackUserData(NULL) { m_audioCallBackUserData(nullptr) {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if (m_javaApplicationType == appl_application) { if (m_javaApplicationType == appl_application) {
EWOL_DEBUG("** set JVM Pointer (application) **"); EWOL_DEBUG("** set JVM Pointer (application) **");
@ -119,21 +119,21 @@ class AndroidContext : public ewol::Context {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
m_JavaVirtualMachinePointer = _env; m_JavaVirtualMachinePointer = _env;
// get default needed all time elements : // get default needed all time elements :
if (NULL != m_JavaVirtualMachinePointer) { if (nullptr != m_JavaVirtualMachinePointer) {
EWOL_DEBUG("C->java : try load org/ewol/Ewol class"); EWOL_DEBUG("C->java : try load org/ewol/Ewol class");
m_javaClassEwol = m_JavaVirtualMachinePointer->FindClass("org/ewol/Ewol" ); m_javaClassEwol = m_JavaVirtualMachinePointer->FindClass("org/ewol/Ewol" );
if (m_javaClassEwol == 0) { if (m_javaClassEwol == 0) {
EWOL_ERROR("C->java : Can't find org/ewol/Ewol class"); EWOL_ERROR("C->java : Can't find org/ewol/Ewol class");
// remove access on the virtual machine : // remove access on the virtual machine :
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
return; return;
} }
/* The object field extends Activity and implement EwolCallback */ /* The object field extends Activity and implement EwolCallback */
m_javaClassEwolCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback); m_javaClassEwolCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
if(m_javaClassEwolCallback == NULL) { if(m_javaClassEwolCallback == nullptr) {
EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class"); EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class");
// remove access on the virtual machine : // remove access on the virtual machine :
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
return; return;
} }
bool functionCallbackIsMissing = false; bool functionCallbackIsMissing = false;
@ -258,7 +258,7 @@ class AndroidContext : public ewol::Context {
m_javaObjectEwolCallback = _env->NewGlobalRef(_objCallback); m_javaObjectEwolCallback = _env->NewGlobalRef(_objCallback);
//javaObjectEwolCallbackAndActivity = objCallback; //javaObjectEwolCallbackAndActivity = objCallback;
if (m_javaObjectEwolCallback == NULL) { if (m_javaObjectEwolCallback == nullptr) {
functionCallbackIsMissing = true; functionCallbackIsMissing = true;
} }
@ -266,7 +266,7 @@ class AndroidContext : public ewol::Context {
if (m_javaDefaultClassString == 0) { if (m_javaDefaultClassString == 0) {
EWOL_ERROR("C->java : Can't find java/lang/String" ); EWOL_ERROR("C->java : Can't find java/lang/String" );
// remove access on the virtual machine : // remove access on the virtual machine :
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
functionCallbackIsMissing = true; functionCallbackIsMissing = true;
} }
if (functionCallbackIsMissing == true) { if (functionCallbackIsMissing == true) {
@ -281,7 +281,7 @@ class AndroidContext : public ewol::Context {
void unInit(JNIEnv* _env) { void unInit(JNIEnv* _env) {
_env->DeleteGlobalRef(m_javaObjectEwolCallback); _env->DeleteGlobalRef(m_javaObjectEwolCallback);
m_javaObjectEwolCallback = NULL; m_javaObjectEwolCallback = nullptr;
} }
int32_t run() { int32_t run() {
@ -387,7 +387,7 @@ class AndroidContext : public ewol::Context {
} }
//Call java ... //Call java ...
jstring returnString = (jstring) m_JavaVirtualMachinePointer->CallObjectMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioGetDeviceProperty, _idDevice); jstring returnString = (jstring) m_JavaVirtualMachinePointer->CallObjectMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioGetDeviceProperty, _idDevice);
const char *js = m_JavaVirtualMachinePointer->GetStringUTFChars(returnString, NULL); const char *js = m_JavaVirtualMachinePointer->GetStringUTFChars(returnString, nullptr);
std::string retString(js); std::string retString(js);
m_JavaVirtualMachinePointer->ReleaseStringUTFChars(returnString, js); m_JavaVirtualMachinePointer->ReleaseStringUTFChars(returnString, js);
//m_JavaVirtualMachinePointer->DeleteLocalRef(returnString); //m_JavaVirtualMachinePointer->DeleteLocalRef(returnString);
@ -410,7 +410,7 @@ class AndroidContext : public ewol::Context {
int32_t _format, int32_t _format,
AndroidAudioCallback _callback, AndroidAudioCallback _callback,
void* _userData) { void* _userData) {
if (m_audioCallBack != NULL) { if (m_audioCallBack != nullptr) {
EWOL_ERROR("AudioCallback already started ..."); EWOL_ERROR("AudioCallback already started ...");
return false; return false;
} }
@ -437,7 +437,7 @@ class AndroidContext : public ewol::Context {
return false; return false;
} }
bool audioCloseDevice(int32_t _idDevice) { bool audioCloseDevice(int32_t _idDevice) {
if (m_audioCallBack == NULL) { if (m_audioCallBack == nullptr) {
EWOL_ERROR("AudioCallback Not started ..."); EWOL_ERROR("AudioCallback Not started ...");
return false; return false;
} }
@ -453,8 +453,8 @@ class AndroidContext : public ewol::Context {
// manage execption : // manage execption :
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
java_detach_current_thread(status); java_detach_current_thread(status);
m_audioCallBack = NULL; m_audioCallBack = nullptr;
m_audioCallBackUserData = NULL; m_audioCallBackUserData = nullptr;
return (bool)ret; return (bool)ret;
} else { } else {
EWOL_ERROR("C->java : can not get audio device count"); EWOL_ERROR("C->java : can not get audio device count");
@ -464,9 +464,9 @@ class AndroidContext : public ewol::Context {
private: private:
bool java_attach_current_thread(int *_rstatus) { bool java_attach_current_thread(int *_rstatus) {
EWOL_DEBUG("C->java : call java"); EWOL_DEBUG("C->java : call java");
if (g_JavaVM == NULL) { if (g_JavaVM == nullptr) {
EWOL_ERROR("C->java : JVM not initialised"); EWOL_ERROR("C->java : JVM not initialised");
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
return false; return false;
} }
*_rstatus = g_JavaVM->GetEnv((void **) &m_JavaVirtualMachinePointer, JNI_VERSION_1_6); *_rstatus = g_JavaVM->GetEnv((void **) &m_JavaVirtualMachinePointer, JNI_VERSION_1_6);
@ -474,12 +474,12 @@ class AndroidContext : public ewol::Context {
JavaVMAttachArgs lJavaVMAttachArgs; JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "EwolNativeThread"; lJavaVMAttachArgs.name = "EwolNativeThread";
lJavaVMAttachArgs.group = NULL; lJavaVMAttachArgs.group = nullptr;
int status = g_JavaVM->AttachCurrentThread(&m_JavaVirtualMachinePointer, &lJavaVMAttachArgs); int status = g_JavaVM->AttachCurrentThread(&m_JavaVirtualMachinePointer, &lJavaVMAttachArgs);
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
if (status != JNI_OK) { if (status != JNI_OK) {
EWOL_ERROR("C->java : AttachCurrentThread failed : " << status); EWOL_ERROR("C->java : AttachCurrentThread failed : " << status);
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
return false; return false;
} }
} }
@ -489,7 +489,7 @@ class AndroidContext : public ewol::Context {
void java_detach_current_thread(int _status) { void java_detach_current_thread(int _status) {
if(_status == JNI_EDETACHED) { if(_status == JNI_EDETACHED) {
g_JavaVM->DetachCurrentThread(); g_JavaVM->DetachCurrentThread();
m_JavaVirtualMachinePointer = NULL; m_JavaVirtualMachinePointer = nullptr;
} }
} }
@ -568,7 +568,7 @@ class AndroidContext : public ewol::Context {
return; return;
} }
EWOL_DEBUG("C->java : 222"); EWOL_DEBUG("C->java : 222");
if (NULL == _dataString) { if (nullptr == _dataString) {
EWOL_ERROR("C->java : No data to send ..."); EWOL_ERROR("C->java : No data to send ...");
return; return;
} }
@ -631,7 +631,7 @@ class AndroidContext : public ewol::Context {
} }
void audioPlayback(void* _dataOutput, int32_t _frameRate) { void audioPlayback(void* _dataOutput, int32_t _frameRate) {
if (m_audioCallBack != NULL) { if (m_audioCallBack != nullptr) {
//EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate); //EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate);
m_audioCallBack(_dataOutput, _frameRate, m_audioCallBackUserData); m_audioCallBack(_dataOutput, _frameRate, m_audioCallBackUserData);
} }
@ -654,7 +654,7 @@ extern "C" {
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* _vm, void *_reserved) { JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* _vm, void *_reserved) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
etk::AutoLockMutex myLock2(g_interfaceAudioMutex); etk::AutoLockMutex myLock2(g_interfaceAudioMutex);
g_JavaVM = NULL; g_JavaVM = nullptr;
EWOL_DEBUG("JNI-> Un-load the jvm ..." ); EWOL_DEBUG("JNI-> Un-load the jvm ..." );
} }
@ -665,9 +665,9 @@ extern "C" {
jint _mode, jint _mode,
jstring _myString) { jstring _myString) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -680,7 +680,7 @@ extern "C" {
if (isCopy == JNI_TRUE) { if (isCopy == JNI_TRUE) {
// from here str is reset ... // from here str is reset ...
_env->ReleaseStringUTFChars(_myString, str); _env->ReleaseStringUTFChars(_myString, str);
str = NULL; str = nullptr;
} }
} }
@ -692,7 +692,7 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Creating EWOL context **"); EWOL_DEBUG("** Creating EWOL context **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
AndroidContext* tmpContext = NULL; AndroidContext* tmpContext = nullptr;
if (org_ewol_EwolConstants_EWOL_APPL_TYPE_ACTIVITY == _typeApplication) { if (org_ewol_EwolConstants_EWOL_APPL_TYPE_ACTIVITY == _typeApplication) {
tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application); tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application);
} else if (org_ewol_EwolConstants_EWOL_APPL_TYPE_WALLPAPER == _typeApplication) { } else if (org_ewol_EwolConstants_EWOL_APPL_TYPE_WALLPAPER == _typeApplication) {
@ -701,7 +701,7 @@ extern "C" {
EWOL_CRITICAL(" try to create an instance with no apply type: " << _typeApplication); EWOL_CRITICAL(" try to create an instance with no apply type: " << _typeApplication);
return -1; return -1;
} }
if (NULL == tmpContext) { if (nullptr == tmpContext) {
EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1)); EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1));
return -1; return -1;
} }
@ -716,25 +716,25 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** remove JVM Pointer **"); EWOL_DEBUG("** remove JVM Pointer **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0) { || _id<0) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
return; return;
} }
if (NULL == s_listInstance[_id]) { if (nullptr == s_listInstance[_id]) {
EWOL_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ..."); EWOL_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ...");
return; return;
} }
s_listInstance[_id]->unInit(_env); s_listInstance[_id]->unInit(_env);
delete(s_listInstance[_id]); delete(s_listInstance[_id]);
s_listInstance[_id]=NULL; s_listInstance[_id]=nullptr;
} }
void Java_org_ewol_Ewol_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) { void Java_org_ewol_Ewol_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
EWOL_DEBUG(" == > Touch Event"); EWOL_DEBUG(" == > Touch Event");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -747,9 +747,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on Create **"); EWOL_DEBUG("** Activity on Create **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -762,9 +762,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on Start **"); EWOL_DEBUG("** Activity on Start **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -776,9 +776,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on Re-Start **"); EWOL_DEBUG("** Activity on Re-Start **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -789,9 +789,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on resume **"); EWOL_DEBUG("** Activity on resume **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -803,9 +803,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on pause **"); EWOL_DEBUG("** Activity on pause **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -819,9 +819,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on Stop **"); EWOL_DEBUG("** Activity on Stop **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -833,9 +833,9 @@ extern "C" {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity on Destroy **"); EWOL_DEBUG("** Activity on Destroy **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -855,9 +855,9 @@ extern "C" {
jfloat _x, jfloat _x,
jfloat _y) { jfloat _y) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -873,9 +873,9 @@ extern "C" {
jfloat _x, jfloat _x,
jfloat _y) { jfloat _y) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -890,9 +890,9 @@ extern "C" {
jfloat _x, jfloat _x,
jfloat _y) { jfloat _y) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -908,9 +908,9 @@ extern "C" {
jfloat _x, jfloat _x,
jfloat _y) { jfloat _y) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -923,9 +923,9 @@ extern "C" {
jint _id, jint _id,
jint _pointerID) { jint _pointerID) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -939,9 +939,9 @@ extern "C" {
jint _type, jint _type,
jboolean _isdown) { jboolean _isdown) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -956,9 +956,9 @@ extern "C" {
jint _uniChar, jint _uniChar,
jboolean _isdown) { jboolean _isdown) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -973,9 +973,9 @@ extern "C" {
jfloat _ratioX, jfloat _ratioX,
jfloat _ratioY) { jfloat _ratioY) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -991,9 +991,9 @@ extern "C" {
jint _keyVal, jint _keyVal,
jboolean _isdown) { jboolean _isdown) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return false; return false;
@ -1035,9 +1035,9 @@ extern "C" {
jobject _thiz, jobject _thiz,
jint _id) { jint _id) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -1050,9 +1050,9 @@ extern "C" {
jint _w, jint _w,
jint _h) { jint _h) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -1065,9 +1065,9 @@ extern "C" {
jobject _thiz, jobject _thiz,
jint _id) { jint _id) {
etk::AutoLockMutex myLock(g_interfaceMutex); etk::AutoLockMutex myLock(g_interfaceMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -1082,9 +1082,9 @@ extern "C" {
jint _frameRate, jint _frameRate,
jint _nbChannels) { jint _nbChannels) {
etk::AutoLockMutex myLock(g_interfaceAudioMutex); etk::AutoLockMutex myLock(g_interfaceAudioMutex);
if( _id >= s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id<0
|| NULL == s_listInstance[_id] ) { || nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -1092,7 +1092,7 @@ extern "C" {
// get the short* pointer from the Java array // get the short* pointer from the Java array
jboolean isCopy; jboolean isCopy;
jshort* dst = _env->GetShortArrayElements(_location, &isCopy); jshort* dst = _env->GetShortArrayElements(_location, &isCopy);
if (NULL != dst) { if (nullptr != dst) {
memset(dst, sizeof(jshort), _frameRate*_nbChannels); memset(dst, sizeof(jshort), _frameRate*_nbChannels);
//EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate << " channels=" << _nbChannels); //EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate << " channels=" << _nbChannels);
s_listInstance[_id]->audioPlayback(dst, _frameRate); s_listInstance[_id]->audioPlayback(dst, _frameRate);

View File

@ -19,7 +19,7 @@ namespace ewol {
* Constructor / destructor * Constructor / destructor
*/ */
ConfigFont(); ConfigFont();
~ConfigFont(); virtual ~ConfigFont();
private: private:
std::string m_folder; std::string m_folder;
public: public:

View File

@ -20,15 +20,17 @@
#include <ewol/Dimension.h> #include <ewol/Dimension.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/translate.h>
#include <ewol/openGL/openGL.h>
#include <ewol/object/Object.h> #include <ewol/object/Object.h>
#include <ewol/object/Manager.h> #include <ewol/object/Manager.h>
#include <ewol/widget/Widget.h>
#include <ewol/widget/Windows.h>
#include <ewol/widget/Manager.h>
#include <ewol/context/Context.h> #include <ewol/context/Context.h>
#include <ewol/resource/Manager.h> #include <ewol/resource/Manager.h>
#include <ewol/openGL/openGL.h>
#include <ewol/widget/Manager.h>
#include <ewol/translate.h>
@ -43,10 +45,10 @@ static etk::Mutex& mutexInterface() {
} }
static ewol::Context* l_curentInterface=NULL; static ewol::Context* l_curentInterface=nullptr;
ewol::Context& ewol::getContext() { ewol::Context& ewol::getContext() {
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if(NULL == l_curentInterface){ if(nullptr == l_curentInterface){
EWOL_CRITICAL("[CRITICAL] try acces at an empty interface"); EWOL_CRITICAL("[CRITICAL] try acces at an empty interface");
} }
#endif #endif
@ -71,11 +73,11 @@ void ewol::Context::lockContext() {
} }
/** /**
* @brief set the curent interface at NULL. * @brief set the curent interface at nullptr.
* @note this un-lock the main mutex * @note this un-lock the main mutex
*/ */
void ewol::Context::unLockContext() { void ewol::Context::unLockContext() {
l_curentInterface = NULL; l_curentInterface = nullptr;
mutexInterface().unLock(); mutexInterface().unLock();
} }
@ -133,13 +135,13 @@ namespace ewol {
}; };
void ewol::Context::inputEventTransfertWidget(ewol::Widget* _source, void ewol::Context::inputEventTransfertWidget(ewol::object::Shared<ewol::Widget> _source,
ewol::Widget* _destination) { ewol::object::Shared<ewol::Widget> _destination) {
m_input.transfertEvent(_source, _destination); m_input.transfertEvent(_source, _destination);
} }
void ewol::Context::inputEventGrabPointer(ewol::Widget* _widget) { void ewol::Context::inputEventGrabPointer(ewol::object::Shared<ewol::Widget> _widget) {
m_input.grabPointer(_widget); m_input.grabPointer(_widget);
} }
@ -150,12 +152,12 @@ void ewol::Context::inputEventUnGrabPointer() {
void ewol::Context::processEvents() { void ewol::Context::processEvents() {
int32_t nbEvent = 0; int32_t nbEvent = 0;
//EWOL_DEBUG(" ******** Event"); //EWOL_DEBUG(" ******** Event");
ewol::eSystemMessage* data = NULL; ewol::eSystemMessage* data = nullptr;
while (m_msgSystem.count()>0) { while (m_msgSystem.count()>0) {
nbEvent++; nbEvent++;
if (data != NULL) { if (data != nullptr) {
delete(data); delete(data);
data = NULL; data = nullptr;
} }
m_msgSystem.wait(data); m_msgSystem.wait(data);
//EWOL_DEBUG("EVENT"); //EWOL_DEBUG("EVENT");
@ -188,14 +190,14 @@ void ewol::Context::processEvents() {
//EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_KEY"); //EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_KEY");
// store the keyboard special key status for mouse event... // store the keyboard special key status for mouse event...
m_input.setLastKeyboardSpecial(data->keyboardSpecial); m_input.setLastKeyboardSpecial(data->keyboardSpecial);
if (NULL != m_windowsCurrent) { if (nullptr != m_windowsCurrent) {
if (false == m_windowsCurrent->onEventShortCut(data->keyboardSpecial, if (false == m_windowsCurrent->onEventShortCut(data->keyboardSpecial,
data->keyboardChar, data->keyboardChar,
data->keyboardMove, data->keyboardMove,
data->stateIsDown) ) { data->stateIsDown) ) {
// get the current focused Widget : // get the current focused Widget :
ewol::Widget * tmpWidget = m_widgetManager.focusGet(); ewol::object::Shared<ewol::Widget> tmpWidget = m_widgetManager.focusGet();
if (NULL != tmpWidget) { if (nullptr != tmpWidget) {
// check if the widget allow repeating key events. // check if the widget allow repeating key events.
//EWOL_DEBUG("repeating test :" << data->repeateKey << " widget=" << tmpWidget->getKeyboardRepeate() << " state=" << data->stateIsDown); //EWOL_DEBUG("repeating test :" << data->repeateKey << " widget=" << tmpWidget->getKeyboardRepeate() << " state=" << data->stateIsDown);
if( false == data->repeateKey if( false == data->repeateKey
@ -237,8 +239,8 @@ void ewol::Context::processEvents() {
break; break;
case eSystemMessage::msgClipboardArrive: case eSystemMessage::msgClipboardArrive:
{ {
ewol::Widget * tmpWidget = m_widgetManager.focusGet(); ewol::object::Shared<ewol::Widget> tmpWidget = m_widgetManager.focusGet();
if (tmpWidget != NULL) { if (tmpWidget != nullptr) {
tmpWidget->onEventClipboard(data->clipboardID); tmpWidget->onEventClipboard(data->clipboardID);
} }
} }
@ -286,6 +288,7 @@ void ewol::Context::setArchiveDir(int _mode, const char* _str) {
ewol::Context::Context(int32_t _argc, const char* _argv[]) : ewol::Context::Context(int32_t _argc, const char* _argv[]) :
m_objectManager(*this),
m_previousDisplayTime(0), m_previousDisplayTime(0),
m_input(*this), m_input(*this),
#if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__IOs)) #if (defined(__TARGET_OS__Android) || defined(__TARGET_OS__IOs))
@ -297,7 +300,7 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) :
m_FpsSystemContext("Context ", false), m_FpsSystemContext("Context ", false),
m_FpsSystem( "Draw ", true), m_FpsSystem( "Draw ", true),
m_FpsFlush( "Flush ", false), m_FpsFlush( "Flush ", false),
m_windowsCurrent(NULL), m_windowsCurrent(nullptr),
m_windowsSize(320,480), m_windowsSize(320,480),
m_initStepId(0), m_initStepId(0),
m_initTotalStep(1) { m_initTotalStep(1) {
@ -352,7 +355,7 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) :
// request the init of the application in the main context of openGL ... // request the init of the application in the main context of openGL ...
{ {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
} else { } else {
data->TypeMessage = eSystemMessage::msgInit; data->TypeMessage = eSystemMessage::msgInit;
@ -378,18 +381,27 @@ ewol::Context::~Context() {
// TODO : Clean the message list ... // TODO : Clean the message list ...
// set the curent interface : // set the curent interface :
lockContext(); lockContext();
// Remove current windows
m_windowsCurrent.reset();
// clean all widget and sub widget with their resources:
do {
m_objectManager.removeAllRemovedObject();
} while (m_resourceManager.checkResourceToRemove() == true);
// call application to uninit // call application to uninit
APP_UnInit(*this); APP_UnInit(*this);
if (m_windowsCurrent != NULL) { // clean all messages
EWOL_DEBUG("Main windows has not been auto-removed...");
m_windowsCurrent->removeObject();
m_windowsCurrent = NULL;
}
// unset all windows
m_msgSystem.clean(); m_msgSystem.clean();
// an other cycle of removing ...
do {
m_objectManager.removeAllRemovedObject();
} while (m_resourceManager.checkResourceToRemove() == true);
m_objectManager.unInit(); EWOL_INFO("List of all widget of this context must be equal at 0 ==> otherwise some remove is missing");
m_objectManager.displayListObject();
// Resource is an lower element as objects ...
m_resourceManager.unInit(); m_resourceManager.unInit();
// now All must be removed !!!
m_objectManager.unInit();
// release the curent interface : // release the curent interface :
unLockContext(); unLockContext();
EWOL_INFO(" == > Ewol system Un-Init (END)"); EWOL_INFO(" == > Ewol system Un-Init (END)");
@ -397,7 +409,7 @@ ewol::Context::~Context() {
void ewol::Context::requestUpdateSize() { void ewol::Context::requestUpdateSize() {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -409,7 +421,7 @@ void ewol::Context::OS_Resize(const vec2& _size) {
// TODO : Better in the thread ... == > but generate some init error ... // TODO : Better in the thread ... == > but generate some init error ...
ewol::Dimension::setPixelWindowsSize(_size); ewol::Dimension::setPixelWindowsSize(_size);
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -429,7 +441,7 @@ void ewol::Context::OS_Move(const vec2& _pos) {
void ewol::Context::OS_SetInputMotion(int _pointerID, const vec2& _pos ) { void ewol::Context::OS_SetInputMotion(int _pointerID, const vec2& _pos ) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -442,7 +454,7 @@ void ewol::Context::OS_SetInputMotion(int _pointerID, const vec2& _pos ) {
void ewol::Context::OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos ) { void ewol::Context::OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos ) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -456,7 +468,7 @@ void ewol::Context::OS_SetInputState(int _pointerID, bool _isDown, const vec2& _
void ewol::Context::OS_SetMouseMotion(int _pointerID, const vec2& _pos ) { void ewol::Context::OS_SetMouseMotion(int _pointerID, const vec2& _pos ) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -469,7 +481,7 @@ void ewol::Context::OS_SetMouseMotion(int _pointerID, const vec2& _pos ) {
void ewol::Context::OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos ) { void ewol::Context::OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos ) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -486,7 +498,7 @@ void ewol::Context::OS_SetKeyboard(ewol::key::Special& _special,
bool _isDown, bool _isDown,
bool _isARepeateKey) { bool _isARepeateKey) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -503,7 +515,7 @@ void ewol::Context::OS_SetKeyboardMove(ewol::key::Special& _special,
bool _isDown, bool _isDown,
bool _isARepeateKey) { bool _isARepeateKey) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -517,7 +529,7 @@ void ewol::Context::OS_SetKeyboardMove(ewol::key::Special& _special,
void ewol::Context::OS_Hide() { void ewol::Context::OS_Hide() {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -527,7 +539,7 @@ void ewol::Context::OS_Hide() {
void ewol::Context::OS_Show() { void ewol::Context::OS_Show() {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -538,7 +550,7 @@ void ewol::Context::OS_Show() {
void ewol::Context::OS_ClipBoardArrive(enum ewol::context::clipBoard::clipboardListe _clipboardID) { void ewol::Context::OS_ClipBoardArrive(enum ewol::context::clipBoard::clipboardListe _clipboardID) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocationerror of message"); EWOL_ERROR("allocationerror of message");
return; return;
} }
@ -570,7 +582,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
processEvents(); processEvents();
if (m_initStepId < m_initTotalStep) { if (m_initStepId < m_initTotalStep) {
ewol::eSystemMessage *data = new ewol::eSystemMessage(); ewol::eSystemMessage *data = new ewol::eSystemMessage();
if (data == NULL) { if (data == nullptr) {
EWOL_ERROR("allocation error of message"); EWOL_ERROR("allocation error of message");
} else { } else {
data->TypeMessage = eSystemMessage::msgInit; data->TypeMessage = eSystemMessage::msgInit;
@ -578,13 +590,9 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
} }
} }
// call all the widget that neded to do something periodicly // call all the widget that neded to do something periodicly
//! ewol::widgetManager::periodicCall(currentTime);
m_widgetManager.periodicCall(currentTime); m_widgetManager.periodicCall(currentTime);
// remove all widget that they are no more usefull (these who decided to destroy themself)
//! ewol::ObjectManager::removeAllAutoRemove();
m_objectManager.removeAllAutoRemove();
// check if the user selected a windows // check if the user selected a windows
if (NULL != m_windowsCurrent) { if (nullptr != m_windowsCurrent) {
// Redraw all needed elements // Redraw all needed elements
m_windowsCurrent->onRegenerateDisplay(); m_windowsCurrent->onRegenerateDisplay();
} }
@ -605,7 +613,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
if (m_displayFps == true) { if (m_displayFps == true) {
m_FpsSystemContext.tic(); m_FpsSystemContext.tic();
} }
if (NULL != m_windowsCurrent) { if (nullptr != m_windowsCurrent) {
if( true == needRedraw if( true == needRedraw
|| true == _displayEveryTime) { || true == _displayEveryTime) {
m_resourceManager.updateContext(); m_resourceManager.updateContext();
@ -618,7 +626,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
m_FpsSystemContext.toc(); m_FpsSystemContext.toc();
m_FpsSystem.tic(); m_FpsSystem.tic();
} }
if (NULL != m_windowsCurrent) { if (nullptr != m_windowsCurrent) {
if( true == needRedraw if( true == needRedraw
|| true == _displayEveryTime) { || true == _displayEveryTime) {
m_FpsSystem.incrementCounter(); m_FpsSystem.incrementCounter();
@ -645,12 +653,33 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) {
m_FpsSystem.draw(); m_FpsSystem.draw();
m_FpsFlush.draw(); m_FpsFlush.draw();
} }
{
// set the curent interface :
lockContext();
// release open GL Context
ewol::openGL::lock();
// while The Gui is drawing in OpenGl, we do some not realTime things
m_resourceManager.updateContext();
// release open GL Context
ewol::openGL::unLock();
do {
m_objectManager.removeAllRemovedObject();
} while (m_resourceManager.checkResourceToRemove() == true);
// release the curent interface :
unLockContext();
}
return hasDisplayDone; return hasDisplayDone;
} }
void ewol::Context::onObjectRemove(ewol::Object * _removeObject) { void ewol::Context::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
//EWOL_CRITICAL("element removed"); //EWOL_CRITICAL("element removed");
m_input.onObjectRemove(_removeObject); if (m_windowsCurrent == _object) {
m_windowsCurrent.reset(); // This might never arrived, the owner is the current element (expected when the widget auto remove itself)
}
// inform all manager that can not be directly linked with the object manager
m_input.onObjectRemove(_object);
m_widgetManager.onObjectRemove(_object);
m_resourceManager.checkResourceToRemove();
} }
void ewol::Context::resetIOEvent() { void ewol::Context::resetIOEvent() {
@ -661,9 +690,9 @@ void ewol::Context::OS_OpenGlContextDestroy() {
m_resourceManager.contextHasBeenDestroyed(); m_resourceManager.contextHasBeenDestroyed();
} }
void ewol::Context::setWindows(ewol::widget::Windows* _windows) { void ewol::Context::setWindows(const ewol::object::Shared<ewol::widget::Windows>& _windows) {
// remove current focus : // remove current focus :
m_widgetManager.focusSetDefault(NULL); m_widgetManager.focusSetDefault(nullptr);
m_widgetManager.focusRelease(); m_widgetManager.focusRelease();
// set the new pointer as windows system // set the new pointer as windows system
m_windowsCurrent = _windows; m_windowsCurrent = _windows;
@ -673,8 +702,12 @@ void ewol::Context::setWindows(ewol::widget::Windows* _windows) {
forceRedrawAll(); forceRedrawAll();
} }
ewol::object::Shared<ewol::widget::Windows> ewol::Context::getWindows() {
return m_windowsCurrent;
};
void ewol::Context::forceRedrawAll() { void ewol::Context::forceRedrawAll() {
if (m_windowsCurrent == NULL) { if (m_windowsCurrent == nullptr) {
return; return;
} }
m_windowsCurrent->calculateSize(vec2(m_windowsSize.x(), m_windowsSize.y())); m_windowsCurrent->calculateSize(vec2(m_windowsSize.x(), m_windowsSize.y()));
@ -684,7 +717,7 @@ void ewol::Context::OS_Stop() {
// set the curent interface : // set the curent interface :
lockContext(); lockContext();
EWOL_INFO("OS_Stop..."); EWOL_INFO("OS_Stop...");
if (m_windowsCurrent != NULL) { if (m_windowsCurrent != nullptr) {
m_windowsCurrent->sysOnKill(); m_windowsCurrent->sysOnKill();
} }
// release the curent interface : // release the curent interface :
@ -696,7 +729,7 @@ void ewol::Context::OS_Suspend() {
lockContext(); lockContext();
EWOL_INFO("OS_Suspend..."); EWOL_INFO("OS_Suspend...");
m_previousDisplayTime = -1; m_previousDisplayTime = -1;
if (m_windowsCurrent != NULL) { if (m_windowsCurrent != nullptr) {
m_windowsCurrent->onStateSuspend(); m_windowsCurrent->onStateSuspend();
} }
// release the curent interface : // release the curent interface :
@ -709,7 +742,7 @@ void ewol::Context::OS_Resume() {
EWOL_INFO("OS_Resume..."); EWOL_INFO("OS_Resume...");
m_previousDisplayTime = ewol::getTime(); m_previousDisplayTime = ewol::getTime();
m_widgetManager.periodicCallResume(m_previousDisplayTime); m_widgetManager.periodicCallResume(m_previousDisplayTime);
if (m_windowsCurrent != NULL) { if (m_windowsCurrent != nullptr) {
m_windowsCurrent->onStateResume(); m_windowsCurrent->onStateResume();
} }
// release the curent interface : // release the curent interface :
@ -719,7 +752,7 @@ void ewol::Context::OS_Foreground() {
// set the curent interface : // set the curent interface :
lockContext(); lockContext();
EWOL_INFO("OS_Foreground..."); EWOL_INFO("OS_Foreground...");
if (m_windowsCurrent != NULL) { if (m_windowsCurrent != nullptr) {
m_windowsCurrent->onStateForeground(); m_windowsCurrent->onStateForeground();
} }
// release the curent interface : // release the curent interface :
@ -730,7 +763,7 @@ void ewol::Context::OS_Background() {
// set the curent interface : // set the curent interface :
lockContext(); lockContext();
EWOL_INFO("OS_Background..."); EWOL_INFO("OS_Background...");
if (m_windowsCurrent != NULL) { if (m_windowsCurrent != nullptr) {
m_windowsCurrent->onStateBackground(); m_windowsCurrent->onStateBackground();
} }
// release the curent interface : // release the curent interface :
@ -773,7 +806,7 @@ void ewol::Context::keyboardHide() {
bool ewol::Context::systemKeyboradEvent(enum ewol::key::keyboardSystem _key, bool _down) { bool ewol::Context::systemKeyboradEvent(enum ewol::key::keyboardSystem _key, bool _down) {
if (m_windowsCurrent == NULL) { if (m_windowsCurrent == nullptr) {
return false; return false;
} }
lockContext(); lockContext();

View File

@ -22,6 +22,7 @@
#include <ewol/context/commandLine.h> #include <ewol/context/commandLine.h>
#include <ewol/context/InputManager.h> #include <ewol/context/InputManager.h>
#include <ewol/context/Fps.h> #include <ewol/context/Fps.h>
#include <ewol/object/RemoveEvent.h>
namespace ewol { namespace ewol {
/** /**
@ -37,7 +38,7 @@ namespace ewol {
screenPortrait screenPortrait
}; };
class Context { class Context/* : private ewol::object::RemoveEvent */{
private: private:
ewol::context::CommandLine m_commandLine; //!< Start command line information ewol::context::CommandLine m_commandLine; //!< Start command line information
public: public:
@ -50,18 +51,18 @@ namespace ewol {
ewol::context::ConfigFont& getFontDefault() { ewol::context::ConfigFont& getFontDefault() {
return m_configFont; return m_configFont;
}; };
private:
ewol::widget::Manager m_widgetManager; //!< global widget manager
public:
ewol::widget::Manager& getWidgetManager() {
return m_widgetManager;
};
private: private:
ewol::object::Manager m_objectManager; //!< Object Manager main instance ewol::object::Manager m_objectManager; //!< Object Manager main instance
public: public:
ewol::object::Manager& getEObjectManager() { ewol::object::Manager& getEObjectManager() {
return m_objectManager; return m_objectManager;
}; };
private:
ewol::widget::Manager m_widgetManager; //!< global widget manager
public:
ewol::widget::Manager& getWidgetManager() {
return m_widgetManager;
};
private: private:
ewol::resource::Manager m_resourceManager; //!< global resources Manager ewol::resource::Manager m_resourceManager; //!< global resources Manager
public: public:
@ -69,7 +70,7 @@ namespace ewol {
return m_resourceManager; return m_resourceManager;
}; };
public: public:
Context(int32_t _argc=0, const char* _argv[]=NULL); Context(int32_t _argc=0, const char* _argv[]=nullptr);
virtual ~Context(); virtual ~Context();
protected: protected:
/** /**
@ -78,7 +79,7 @@ namespace ewol {
*/ */
void lockContext(); void lockContext();
/** /**
* @brief set the curent interface at NULL. * @brief set the curent interface at nullptr.
* @note this un-lock the main mutex * @note this un-lock the main mutex
*/ */
void unLockContext(); void unLockContext();
@ -135,12 +136,9 @@ namespace ewol {
// return true if a flush is needed // return true if a flush is needed
bool OS_Draw(bool _displayEveryTime); bool OS_Draw(bool _displayEveryTime);
/**
* @brief Inform object that an other object is removed ... virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject);
* @param[in] removeObject Pointer on the EObject removed == > the user must remove all reference on this EObject public:
* @note : Sub classes must call this class
*/
void onObjectRemove(ewol::Object* _removeObject);
/** /**
* @brief reset event management for the IO like Input ou Mouse or keyborad * @brief reset event management for the IO like Input ou Mouse or keyborad
*/ */
@ -158,20 +156,18 @@ namespace ewol {
*/ */
virtual void stop(); virtual void stop();
private: private:
ewol::widget::Windows* m_windowsCurrent; //!< curent displayed windows ewol::object::Owner<ewol::widget::Windows> m_windowsCurrent; //!< curent displayed windows
public: public:
/** /**
* @brief set the current windows to display : * @brief set the current windows to display :
* @param _windows Windows that might be displayed * @param _windows Windows that might be displayed
*/ */
void setWindows(ewol::widget::Windows* _windows); void setWindows(const ewol::object::Shared<ewol::widget::Windows>& _windows);
/** /**
* @brief get the current windows that is displayed * @brief get the current windows that is displayed
* @return the current handle on the windows (can be null) * @return the current handle on the windows (can be null)
*/ */
ewol::widget::Windows* getWindows() { ewol::object::Shared<ewol::widget::Windows> getWindows();
return m_windowsCurrent;
};
private: private:
vec2 m_windowsSize; //!< current size of the system vec2 m_windowsSize; //!< current size of the system
public: public:
@ -229,12 +225,12 @@ namespace ewol {
* @param source the widget where the event came from * @param source the widget where the event came from
* @param destination the widget where the event mitgh be generated now * @param destination the widget where the event mitgh be generated now
*/ */
void inputEventTransfertWidget(ewol::Widget* _source, ewol::Widget* _destination); void inputEventTransfertWidget(ewol::object::Shared<ewol::Widget> _source, ewol::object::Shared<ewol::Widget> _destination);
/** /**
* @brief This fonction lock the pointer properties to move in relative instead of absolute * @brief This fonction lock the pointer properties to move in relative instead of absolute
* @param[in] widget The widget that lock the pointer events * @param[in] widget The widget that lock the pointer events
*/ */
void inputEventGrabPointer(ewol::Widget* _widget); void inputEventGrabPointer(ewol::object::Shared<ewol::Widget> _widget);
/** /**
* @brief This fonction un-lock the pointer properties to move in relative instead of absolute * @brief This fonction un-lock the pointer properties to move in relative instead of absolute
*/ */

View File

@ -128,19 +128,19 @@ public:
}; };
MacOSInterface* interface = NULL; MacOSInterface* interface = nullptr;
bool IOs::draw(bool _displayEveryTime) { bool IOs::draw(bool _displayEveryTime) {
if (interface == NULL) { if (interface == nullptr) {
return false; return false;
} }
return interface->MAC_Draw(_displayEveryTime); return interface->MAC_Draw(_displayEveryTime);
} }
void IOs::resize(float _x, float _y) { void IOs::resize(float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_Resize(_x, _y); interface->MAC_Resize(_x, _y);
@ -148,82 +148,82 @@ void IOs::resize(float _x, float _y) {
void IOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) { void IOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetMouseState(_id, _isDown, _x, _y); interface->MAC_SetMouseState(_id, _isDown, _x, _y);
} }
void IOs::setMouseMotion(int32_t _id, float _x, float _y) { void IOs::setMouseMotion(int32_t _id, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetMouseMotion(_id, _x, _y); interface->MAC_SetMouseMotion(_id, _x, _y);
} }
void IOs::setInputState(int32_t _id, bool _isDown, float _x, float _y) { void IOs::setInputState(int32_t _id, bool _isDown, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetInputState(_id, _isDown, _x, _y); interface->MAC_SetInputState(_id, _isDown, _x, _y);
} }
void IOs::setInputMotion(int32_t _id, float _x, float _y) { void IOs::setInputMotion(int32_t _id, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetInputMotion(_id, _x, _y); interface->MAC_SetInputMotion(_id, _x, _y);
} }
void IOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) { void IOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey); interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey);
} }
void IOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) { void IOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown); interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown);
} }
void IOs::start() { void IOs::start() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
//interface->OS_Start(); //interface->OS_Start();
} }
void IOs::resume() { void IOs::resume() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->OS_Resume(); interface->OS_Resume();
} }
void IOs::suspend() { void IOs::suspend() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->OS_Suspend(); interface->OS_Suspend();
} }
void IOs::stop() { void IOs::stop() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->OS_Stop(); interface->OS_Stop();
} }
void IOs::background() { void IOs::background() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->OS_Background(); interface->OS_Background();
} }
void IOs::foreground() { void IOs::foreground() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->OS_Foreground(); interface->OS_Foreground();
@ -231,7 +231,7 @@ void IOs::foreground() {
static int l_argc = 0; static int l_argc = 0;
static const char **l_argv = NULL; static const char **l_argv = nullptr;
/** /**
* @brief Main of the program * @brief Main of the program
* @param std IO * @param std IO
@ -248,19 +248,19 @@ void IOs::createInterface() {
etk::setArgZero(l_argv[0]); etk::setArgZero(l_argv[0]);
EWOL_INFO("Create new interface"); EWOL_INFO("Create new interface");
interface = new MacOSInterface(l_argc, l_argv); interface = new MacOSInterface(l_argc, l_argv);
if (NULL == interface) { if (nullptr == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return; return;
} }
} }
void IOs::releaseInterface() { void IOs::releaseInterface() {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
EWOL_INFO("Remove interface"); EWOL_INFO("Remove interface");
delete(interface); delete(interface);
interface = NULL; interface = nullptr;
} }

View File

@ -17,7 +17,6 @@
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/ */
@interface OpenglView : UIView { @interface OpenglView : UIView {
@private @private
CAEAGLLayer* _eaglLayer; CAEAGLLayer* _eaglLayer;

View File

@ -42,11 +42,11 @@ void ewol::context::InputManager::setDpi(int32_t newDPI) {
} }
bool ewol::context::InputManager::localEventInput(enum ewol::key::type _type, bool ewol::context::InputManager::localEventInput(enum ewol::key::type _type,
ewol::Widget* _destWidget, ewol::object::Shared<ewol::Widget> _destWidget,
int32_t _IdInput, int32_t _IdInput,
enum ewol::key::status _status, enum ewol::key::status _status,
vec2 _pos) { vec2 _pos) {
if (NULL != _destWidget) { if (nullptr != _destWidget) {
if (_type == ewol::key::typeMouse || _type == ewol::key::typeFinger) { if (_type == ewol::key::typeMouse || _type == ewol::key::typeFinger) {
// create the system Event : // create the system Event :
ewol::event::InputSystem tmpEventSystem(_type, _status, _IdInput, _pos, _destWidget, 0, m_specialKey); // TODO : set the real ID ... ewol::event::InputSystem tmpEventSystem(_type, _status, _IdInput, _pos, _destWidget, 0, m_specialKey); // TODO : set the real ID ...
@ -62,7 +62,7 @@ bool ewol::context::InputManager::localEventInput(enum ewol::key::type _type,
void ewol::context::InputManager::abortElement(InputPoperty *_eventTable, void ewol::context::InputManager::abortElement(InputPoperty *_eventTable,
int32_t _idInput, int32_t _idInput,
enum ewol::key::type _type) { enum ewol::key::type _type) {
if (NULL == _eventTable) { if (nullptr == _eventTable) {
return; return;
} }
if (_eventTable[_idInput].isUsed == true) { if (_eventTable[_idInput].isUsed == true) {
@ -76,14 +76,14 @@ void ewol::context::InputManager::abortElement(InputPoperty *_eventTable,
void ewol::context::InputManager::cleanElement(InputPoperty *_eventTable, void ewol::context::InputManager::cleanElement(InputPoperty *_eventTable,
int32_t _idInput) { int32_t _idInput) {
if (NULL == _eventTable) { if (nullptr == _eventTable) {
return; return;
} }
//EWOL_INFO("CleanElement[" << idInput << "] = @" << (int64_t)eventTable); //EWOL_INFO("CleanElement[" << idInput << "] = @" << (int64_t)eventTable);
_eventTable[_idInput].isUsed = false; _eventTable[_idInput].isUsed = false;
_eventTable[_idInput].destinationInputId = 0; _eventTable[_idInput].destinationInputId = 0;
_eventTable[_idInput].lastTimeEvent = 0; _eventTable[_idInput].lastTimeEvent = 0;
_eventTable[_idInput].curentWidgetEvent = NULL; _eventTable[_idInput].curentWidgetEvent.reset();
_eventTable[_idInput].origin.setValue(0,0); _eventTable[_idInput].origin.setValue(0,0);
_eventTable[_idInput].size.setValue(99999999,99999999); _eventTable[_idInput].size.setValue(99999999,99999999);
_eventTable[_idInput].downStart.setValue(0,0); _eventTable[_idInput].downStart.setValue(0,0);
@ -93,9 +93,9 @@ void ewol::context::InputManager::cleanElement(InputPoperty *_eventTable,
_eventTable[_idInput].posEvent.setValue(0,0); _eventTable[_idInput].posEvent.setValue(0,0);
} }
void ewol::context::InputManager::transfertEvent(ewol::Widget* _source, ewol::Widget* _destination) { void ewol::context::InputManager::transfertEvent(ewol::object::Shared<ewol::Widget> _source, ewol::object::Shared<ewol::Widget> _destination) {
if( NULL == _source if( _source == nullptr
|| NULL == _destination) { || _destination == nullptr) {
// prevent errors ... // prevent errors ...
return; return;
} }
@ -123,8 +123,8 @@ void ewol::context::InputManager::transfertEvent(ewol::Widget* _source, ewol::Wi
} }
} }
void ewol::context::InputManager::grabPointer(ewol::Widget* _widget) { void ewol::context::InputManager::grabPointer(ewol::object::Shared<ewol::Widget> _widget) {
if(NULL == _widget) { if(nullptr == _widget) {
return; return;
} }
m_grabWidget = _widget; m_grabWidget = _widget;
@ -134,21 +134,27 @@ void ewol::context::InputManager::grabPointer(ewol::Widget* _widget) {
} }
void ewol::context::InputManager::unGrabPointer() { void ewol::context::InputManager::unGrabPointer() {
m_grabWidget = NULL; m_grabWidget = nullptr;
m_context.grabPointerEvents(false, vec2(0,0)); m_context.grabPointerEvents(false, vec2(0,0));
} }
void ewol::context::InputManager::onObjectRemove(ewol::Object * removeObject) { void ewol::context::InputManager::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) { for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
if (m_eventInputSaved[iii].curentWidgetEvent == removeObject) { if (m_eventInputSaved[iii].curentWidgetEvent == _object) {
// remove the property of this input ... // remove the property of this input ...
EWOL_VERBOSE("Remove object ==> rm Input Event !!!");
cleanElement(m_eventInputSaved, iii); cleanElement(m_eventInputSaved, iii);
} }
if (m_eventMouseSaved[iii].curentWidgetEvent == removeObject) { if (m_eventMouseSaved[iii].curentWidgetEvent == _object) {
// remove the property of this input ... // remove the property of this input ...
EWOL_VERBOSE("Remove object ==> rm Mouse Event !!!");
cleanElement(m_eventMouseSaved, iii); cleanElement(m_eventMouseSaved, iii);
} }
} }
if (m_grabWidget == _object) {
EWOL_VERBOSE("Remove object ==> rm Grab widget !!!");
m_grabWidget.reset();
}
} }
void ewol::context::InputManager::newLayerSet() { void ewol::context::InputManager::newLayerSet() {
@ -162,7 +168,7 @@ void ewol::context::InputManager::newLayerSet() {
} }
ewol::context::InputManager::InputManager(ewol::Context& _context) : ewol::context::InputManager::InputManager(ewol::Context& _context) :
m_grabWidget(NULL), m_grabWidget(nullptr),
m_context(_context) { m_context(_context) {
setDpi(200); setDpi(200);
EWOL_INFO("Init (start)"); EWOL_INFO("Init (start)");
@ -180,7 +186,7 @@ ewol::context::InputManager::~InputManager() {
} }
int32_t ewol::context::InputManager::localGetDestinationId(enum ewol::key::type _type, int32_t ewol::context::InputManager::localGetDestinationId(enum ewol::key::type _type,
ewol::Widget* _destWidget, ewol::object::Shared<ewol::Widget> _destWidget,
int32_t _realInputId) { int32_t _realInputId) {
if (_type == ewol::key::typeFinger) { if (_type == ewol::key::typeFinger) {
int32_t lastMinimum = 0; int32_t lastMinimum = 0;
@ -207,7 +213,7 @@ void ewol::context::InputManager::motion(enum ewol::key::type _type,
// reject pointer == > out of IDs... // reject pointer == > out of IDs...
return; return;
} }
InputPoperty *eventTable = NULL; InputPoperty *eventTable = nullptr;
if (_type == ewol::key::typeMouse) { if (_type == ewol::key::typeMouse) {
eventTable = m_eventMouseSaved; eventTable = m_eventMouseSaved;
} else if (_type == ewol::key::typeFinger) { } else if (_type == ewol::key::typeFinger) {
@ -221,17 +227,17 @@ void ewol::context::InputManager::motion(enum ewol::key::type _type,
// not manage input // not manage input
return; return;
} }
ewol::widget::Windows* tmpWindows = m_context.getWindows(); ewol::object::Shared<ewol::widget::Windows> tmpWindows = m_context.getWindows();
// special case for the mouse event 0 that represent the hover event of the system : // special case for the mouse event 0 that represent the hover event of the system :
if (_type == ewol::key::typeMouse && _pointerID == 0) { if (_type == ewol::key::typeMouse && _pointerID == 0) {
// this event is all time on the good widget ... and manage the enter and leave ... // this event is all time on the good widget ... and manage the enter and leave ...
// NOTE : the "layer widget" force us to get the widget at the specific position all the time : // NOTE : the "layer widget" force us to get the widget at the specific position all the time :
ewol::Widget* tmpWidget = NULL; ewol::object::Shared<ewol::Widget> tmpWidget = nullptr;
if (m_grabWidget != NULL) { if (m_grabWidget != nullptr) {
// grab all events ... // grab all events ...
tmpWidget = m_grabWidget; tmpWidget = m_grabWidget;
} else { } else {
if (NULL != tmpWindows) { if (nullptr != tmpWindows) {
tmpWidget = tmpWindows->getWidgetAtPos(_pos); tmpWidget = tmpWindows->getWidgetAtPos(_pos);
} }
} }
@ -255,10 +261,10 @@ void ewol::context::InputManager::motion(enum ewol::key::type _type,
eventTable[_pointerID].isInside = true; eventTable[_pointerID].isInside = true;
// get destination widget : // get destination widget :
eventTable[_pointerID].curentWidgetEvent = tmpWidget; eventTable[_pointerID].curentWidgetEvent = tmpWidget;
if (NULL == eventTable[_pointerID].curentWidgetEvent) { if (nullptr == eventTable[_pointerID].curentWidgetEvent) {
eventTable[_pointerID].isInside = false; eventTable[_pointerID].isInside = false;
} }
if (NULL != eventTable[_pointerID].curentWidgetEvent) { if (nullptr != eventTable[_pointerID].curentWidgetEvent) {
eventTable[_pointerID].origin = eventTable[_pointerID].curentWidgetEvent->getOrigin(); eventTable[_pointerID].origin = eventTable[_pointerID].curentWidgetEvent->getOrigin();
eventTable[_pointerID].size = eventTable[_pointerID].curentWidgetEvent->getSize(); eventTable[_pointerID].size = eventTable[_pointerID].curentWidgetEvent->getSize();
} }
@ -339,7 +345,7 @@ void ewol::context::InputManager::state(enum ewol::key::type _type,
} }
EVENT_DEBUG("event pointerId=" << _pointerID); EVENT_DEBUG("event pointerId=" << _pointerID);
// convert position in open-GL coordonates ... // convert position in open-GL coordonates ...
InputPoperty *eventTable = NULL; InputPoperty *eventTable = nullptr;
InputLimit localLimit; InputLimit localLimit;
if (_type == ewol::key::typeMouse) { if (_type == ewol::key::typeMouse) {
eventTable = m_eventMouseSaved; eventTable = m_eventMouseSaved;
@ -358,7 +364,7 @@ void ewol::context::InputManager::state(enum ewol::key::type _type,
} }
// get the curent time ... // get the curent time ...
int64_t currentTime = ewol::getTime(); int64_t currentTime = ewol::getTime();
ewol::widget::Windows* tmpWindows = m_context.getWindows(); ewol::object::Shared<ewol::widget::Windows> tmpWindows = m_context.getWindows();
if (true == _isDown) { if (true == _isDown) {
EVENT_DEBUG("GUI : Input ID=" << _pointerID EVENT_DEBUG("GUI : Input ID=" << _pointerID
@ -396,16 +402,16 @@ void ewol::context::InputManager::state(enum ewol::key::type _type,
// set the element inside ... // set the element inside ...
eventTable[_pointerID].isInside = true; eventTable[_pointerID].isInside = true;
// get destination widget : // get destination widget :
if(NULL != tmpWindows) { if(nullptr != tmpWindows) {
if (m_grabWidget != NULL && _type == ewol::key::typeMouse) { if (m_grabWidget != nullptr && _type == ewol::key::typeMouse) {
eventTable[_pointerID].curentWidgetEvent = m_grabWidget; eventTable[_pointerID].curentWidgetEvent = m_grabWidget;
} else { } else {
eventTable[_pointerID].curentWidgetEvent = tmpWindows->getWidgetAtPos(_pos); eventTable[_pointerID].curentWidgetEvent = tmpWindows->getWidgetAtPos(_pos);
} }
} else { } else {
eventTable[_pointerID].curentWidgetEvent = NULL; eventTable[_pointerID].curentWidgetEvent = nullptr;
} }
if (NULL != eventTable[_pointerID].curentWidgetEvent) { if (nullptr != eventTable[_pointerID].curentWidgetEvent) {
eventTable[_pointerID].origin = eventTable[_pointerID].curentWidgetEvent->getOrigin(); eventTable[_pointerID].origin = eventTable[_pointerID].curentWidgetEvent->getOrigin();
eventTable[_pointerID].size = eventTable[_pointerID].curentWidgetEvent->getSize(); eventTable[_pointerID].size = eventTable[_pointerID].curentWidgetEvent->getSize();
eventTable[_pointerID].destinationInputId = localGetDestinationId(_type, eventTable[_pointerID].curentWidgetEvent, _pointerID); eventTable[_pointerID].destinationInputId = localGetDestinationId(_type, eventTable[_pointerID].curentWidgetEvent, _pointerID);
@ -433,7 +439,7 @@ void ewol::context::InputManager::state(enum ewol::key::type _type,
// Mark it un-used : // Mark it un-used :
eventTable[_pointerID].isUsed = false; eventTable[_pointerID].isUsed = false;
// revove the widget ... // revove the widget ...
eventTable[_pointerID].curentWidgetEvent = NULL; eventTable[_pointerID].curentWidgetEvent = nullptr;
} else { } else {
// generate UP Event // generate UP Event
EVENT_DEBUG("GUI : Input ID=" << _pointerID EVENT_DEBUG("GUI : Input ID=" << _pointerID
@ -454,14 +460,14 @@ void ewol::context::InputManager::state(enum ewol::key::type _type,
// save start time // save start time
eventTable[_pointerID].lastTimeEvent = currentTime; eventTable[_pointerID].lastTimeEvent = currentTime;
int32_t nbClickMax = 0; int32_t nbClickMax = 0;
if(eventTable[_pointerID].curentWidgetEvent != NULL) { if(eventTable[_pointerID].curentWidgetEvent != nullptr) {
nbClickMax = eventTable[_pointerID].curentWidgetEvent->getMouseLimit(); nbClickMax = eventTable[_pointerID].curentWidgetEvent->getMouseLimit();
if (nbClickMax>5) { if (nbClickMax>5) {
nbClickMax = 5; nbClickMax = 5;
} }
} }
// in grab mode the single to quinte event are not generated .... // in grab mode the single to quinte event are not generated ....
if( ( m_grabWidget == NULL if( ( m_grabWidget == nullptr
|| _type != ewol::key::typeMouse ) || _type != ewol::key::typeMouse )
&& eventTable[_pointerID].nbClickEvent < nbClickMax) { && eventTable[_pointerID].nbClickEvent < nbClickMax) {
// generate event SINGLE : // generate event SINGLE :

View File

@ -10,6 +10,7 @@
#define __EWOL_SYSTEM_INPUT_H__ #define __EWOL_SYSTEM_INPUT_H__
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <ewol/object/RemoveEvent.h>
#define MAX_MANAGE_INPUT (15) #define MAX_MANAGE_INPUT (15)
@ -24,7 +25,7 @@ namespace ewol {
bool isUsed; bool isUsed;
int32_t destinationInputId; int32_t destinationInputId;
int64_t lastTimeEvent; int64_t lastTimeEvent;
ewol::Widget* curentWidgetEvent; ewol::object::Shared<ewol::Widget> curentWidgetEvent;
vec2 origin; vec2 origin;
vec2 size; vec2 size;
vec2 downStart; vec2 downStart;
@ -44,10 +45,10 @@ namespace ewol {
int32_t DpiOffset; int32_t DpiOffset;
}; };
class Context; class Context;
class InputManager { class InputManager{
// special grab pointer mode : // special grab pointer mode :
private: private:
ewol::Widget* m_grabWidget; //!< widget that grab the curent pointer. ewol::object::Shared<ewol::Widget> m_grabWidget; //!< widget that grab the curent pointer.
private: private:
int32_t m_dpi; int32_t m_dpi;
InputLimit m_eventInputLimit; InputLimit m_eventInputLimit;
@ -67,7 +68,7 @@ namespace ewol {
* @return true if event has been greped * @return true if event has been greped
*/ */
bool localEventInput(enum ewol::key::type _type, bool localEventInput(enum ewol::key::type _type,
ewol::Widget* _destWidget, ewol::object::Shared<ewol::Widget> _destWidget,
int32_t _IdInput, int32_t _IdInput,
enum ewol::key::status _typeEvent, enum ewol::key::status _typeEvent,
vec2 _pos); vec2 _pos);
@ -81,7 +82,7 @@ namespace ewol {
* @return the ewol input id * @return the ewol input id
*/ */
int32_t localGetDestinationId(enum ewol::key::type _type, int32_t localGetDestinationId(enum ewol::key::type _type,
ewol::Widget* _destWidget, ewol::object::Shared<ewol::Widget> _destWidget,
int32_t _realInputId); int32_t _realInputId);
private: private:
ewol::Context& m_context; ewol::Context& m_context;
@ -94,12 +95,8 @@ namespace ewol {
void motion(enum ewol::key::type _type, int _pointerID, vec2 _pos ); void motion(enum ewol::key::type _type, int _pointerID, vec2 _pos );
void state(enum ewol::key::type _type, int _pointerID, bool _isDown, vec2 _pos); void state(enum ewol::key::type _type, int _pointerID, bool _isDown, vec2 _pos);
/** void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
* @brief Inform object that an other object is removed ... public:
* @param[in] removeObject Pointer on the Object remeved == > the user must remove all reference on this Object
* @note : Sub classes must call this class
*/
void onObjectRemove(ewol::Object* _removeObject);
/** /**
* @brief a new layer on the windows is set == > might remove all the property of the current element ... * @brief a new layer on the windows is set == > might remove all the property of the current element ...
*/ */
@ -109,12 +106,12 @@ namespace ewol {
* @param _source the widget where the event came from * @param _source the widget where the event came from
* @param _destination the widget where the event mitgh be generated now * @param _destination the widget where the event mitgh be generated now
*/ */
void transfertEvent(ewol::Widget* _source, ewol::Widget* _destination); void transfertEvent(ewol::object::Shared<ewol::Widget> _source, ewol::object::Shared<ewol::Widget> _destination);
/** /**
* @brief This fonction lock the pointer properties to move in relative instead of absolute * @brief This fonction lock the pointer properties to move in relative instead of absolute
* @param[in] _widget The widget that lock the pointer events * @param[in] _widget The widget that lock the pointer events
*/ */
void grabPointer(ewol::Widget* _widget); void grabPointer(ewol::object::Shared<ewol::Widget> _widget);
/** /**
* @brief This fonction un-lock the pointer properties to move in relative instead of absolute * @brief This fonction un-lock the pointer properties to move in relative instead of absolute
*/ */

View File

@ -119,19 +119,19 @@ class MacOSInterface : public ewol::Context {
}; };
MacOSInterface* interface = NULL; MacOSInterface* interface = nullptr;
bool MacOs::draw(bool _displayEveryTime) { bool MacOs::draw(bool _displayEveryTime) {
if (interface == NULL) { if (interface == nullptr) {
return false; return false;
} }
return interface->MAC_Draw(_displayEveryTime); return interface->MAC_Draw(_displayEveryTime);
} }
void MacOs::resize(float _x, float _y) { void MacOs::resize(float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_Resize(_x, _y); interface->MAC_Resize(_x, _y);
@ -139,28 +139,28 @@ void MacOs::resize(float _x, float _y) {
void MacOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) { void MacOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetMouseState(_id, _isDown, _x, _y); interface->MAC_SetMouseState(_id, _isDown, _x, _y);
} }
void MacOs::setMouseMotion(int32_t _id, float _x, float _y) { void MacOs::setMouseMotion(int32_t _id, float _x, float _y) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetMouseMotion(_id, _x, _y); interface->MAC_SetMouseMotion(_id, _x, _y);
} }
void MacOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) { void MacOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey); interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey);
} }
void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) { void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) {
if (interface == NULL) { if (interface == nullptr) {
return; return;
} }
interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown); interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown);
@ -175,14 +175,14 @@ void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::k
int ewol::run(int _argc, const char *_argv[]) { int ewol::run(int _argc, const char *_argv[]) {
etk::setArgZero(_argv[0]); etk::setArgZero(_argv[0]);
interface = new MacOSInterface(_argc, _argv); interface = new MacOSInterface(_argc, _argv);
if (NULL == interface) { if (nullptr == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return -2; return -2;
} }
int32_t retValue = interface->Run(); int32_t retValue = interface->Run();
delete(interface); delete(interface);
interface = NULL; interface = nullptr;
return retValue; return retValue;
} }

View File

@ -29,7 +29,7 @@
int64_t ewol::getTime() { int64_t ewol::getTime() {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, nullptr);
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec); return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec);
} }
@ -72,10 +72,10 @@ class WindowsContext : public ewol::eContext {
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = hInstance; wc.hInstance = hInstance;
wc.hIcon = loadIcon( NULL, IDI_APPLICATION ); wc.hIcon = loadIcon( nullptr, IDI_APPLICATION );
wc.hCursor = loadCursor( NULL, IDC_ARROW ); wc.hCursor = loadCursor( nullptr, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL; wc.lpszMenuName = nullptr;
wc.lpszClassName = "EwolMainWindows"; wc.lpszClassName = "EwolMainWindows";
RegisterClass( &wc ); RegisterClass( &wc );
@ -83,7 +83,7 @@ class WindowsContext : public ewol::eContext {
hWnd = CreateWindow( "EwolMainWindows", "Ewol ... TODO Title", hWnd = CreateWindow( "EwolMainWindows", "Ewol ... TODO Title",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX,
0, 0, 800, 600, 0, 0, 800, 600,
NULL, NULL, hInstance, NULL ); nullptr, NULL, hInstance, NULL );
int border_thickness = getSystemMetrics(SM_CXSIZEFRAME); int border_thickness = getSystemMetrics(SM_CXSIZEFRAME);
int title_size = getSystemMetrics(SM_CYCAPTION); int title_size = getSystemMetrics(SM_CYCAPTION);
m_currentHeight = 600-2*border_thickness -title_size; m_currentHeight = 600-2*border_thickness -title_size;
@ -95,7 +95,7 @@ class WindowsContext : public ewol::eContext {
// program main loop // program main loop
while(true == m_run) { while(true == m_run) {
// check for messages // check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) { if ( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE )) {
// handle or dispatch messages // handle or dispatch messages
if ( msg.message == WM_QUIT ) { if ( msg.message == WM_QUIT ) {
m_run = false; m_run = false;
@ -204,7 +204,7 @@ class WindowsContext : public ewol::eContext {
// disable openGL // disable openGL
void disableOpenGL(HWND _hWnd, HDC _hDC, HGLRC _hRC) { void disableOpenGL(HWND _hWnd, HDC _hDC, HGLRC _hRC) {
wglMakeCurrent( NULL, NULL ); wglMakeCurrent( nullptr, NULL );
wglDeleteContext( _hRC ); wglDeleteContext( _hRC );
releaseDC( _hWnd, _hDC ); releaseDC( _hWnd, _hDC );
} }
@ -256,7 +256,7 @@ class WindowsContext : public ewol::eContext {
*/ */
case WM_WINDOWPOSCHANGING: { case WM_WINDOWPOSCHANGING: {
WINDOWPOS* tmpVal = (WINDOWPOS*)_lParam; WINDOWPOS* tmpVal = (WINDOWPOS*)_lParam;
if (NULL != tmpVal) { if (nullptr != tmpVal) {
//EWOL_DEBUG("WM_WINDOWPOSCHANGING : : (" << tmpVal->x << "," << tmpVal->y << ") ( " << tmpVal->cx << "," << tmpVal->cy << ")"); //EWOL_DEBUG("WM_WINDOWPOSCHANGING : : (" << tmpVal->x << "," << tmpVal->y << ") ( " << tmpVal->cx << "," << tmpVal->cy << ")");
// in windows system, we need to remove the size of the border elements : // in windows system, we need to remove the size of the border elements :
int border_thickness = getSystemMetrics(SM_CXSIZEFRAME); int border_thickness = getSystemMetrics(SM_CXSIZEFRAME);
@ -465,14 +465,14 @@ int ewol::Run(int _argc, const char *_argv[]) {
//return 1; //return 1;
} }
WindowsContext* interface = new WindowsContext(_argc, _argv); WindowsContext* interface = new WindowsContext(_argc, _argv);
if (NULL == interface) { if (nullptr == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return -2; return -2;
} }
int32_t retValue = interface->Run(); int32_t retValue = interface->Run();
delete(interface); delete(interface);
interface = NULL; interface = nullptr;
return retValue; return retValue;
} }

View File

@ -58,7 +58,7 @@ int64_t ewol::getTime() {
int ret = clock_gettime(CLOCK_REALTIME, &now); int ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) { if (ret != 0) {
// Error to get the time ... // Error to get the time ...
now.tv_sec = time(NULL); now.tv_sec = time(nullptr);
now.tv_nsec = 0; now.tv_nsec = 0;
} }
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
@ -144,14 +144,14 @@ class X11Interface : public ewol::Context {
public: public:
X11Interface(int32_t _argc, const char* _argv[]) : X11Interface(int32_t _argc, const char* _argv[]) :
ewol::Context(_argc, _argv), ewol::Context(_argc, _argv),
m_display(NULL), m_display(nullptr),
m_originX(0), m_originX(0),
m_originY(0), m_originY(0),
m_cursorEventX(0), m_cursorEventX(0),
m_cursorEventY(0), m_cursorEventY(0),
m_currentHeight(0), m_currentHeight(0),
m_currentWidth(0), m_currentWidth(0),
m_visual(NULL), m_visual(nullptr),
m_doubleBuffered(0), m_doubleBuffered(0),
m_run(false), m_run(false),
m_grabAllEvent(false), m_grabAllEvent(false),
@ -225,21 +225,21 @@ class X11Interface : public ewol::Context {
{ {
XSelectionRequestEvent *req=&(event.xselectionrequest); XSelectionRequestEvent *req=&(event.xselectionrequest);
if (req->property == 0) { if (req->property == 0) {
EWOL_ERROR("Get NULL ATOM ... property"); EWOL_ERROR("Get nullptr ATOM ... property");
break; break;
} }
if (req->target == 0) { if (req->target == 0) {
EWOL_ERROR("Get NULL ATOM ... target"); EWOL_ERROR("Get nullptr ATOM ... target");
break; break;
} }
char * atomNameProperty = XGetAtomName(m_display, req->property); char * atomNameProperty = XGetAtomName(m_display, req->property);
char * atomNameTarget = XGetAtomName(m_display, req->target); char * atomNameTarget = XGetAtomName(m_display, req->target);
EWOL_INFO("X11 property: \"" << atomNameProperty << "\""); EWOL_INFO("X11 property: \"" << atomNameProperty << "\"");
EWOL_INFO("X11 target: \"" << atomNameTarget << "\""); EWOL_INFO("X11 target: \"" << atomNameTarget << "\"");
if (atomNameProperty != NULL) { if (atomNameProperty != nullptr) {
XFree(atomNameProperty); XFree(atomNameProperty);
} }
if (atomNameTarget != NULL) { if (atomNameTarget != nullptr) {
XFree(atomNameTarget); XFree(atomNameTarget);
} }
} }
@ -294,24 +294,24 @@ class X11Interface : public ewol::Context {
#ifdef DEBUG_X11_EVENT #ifdef DEBUG_X11_EVENT
{ {
if (req->property == 0) { if (req->property == 0) {
EWOL_ERROR("Get NULL ATOM ... property"); EWOL_ERROR("Get nullptr ATOM ... property");
break; break;
} }
if (req->selection == 0) { if (req->selection == 0) {
EWOL_ERROR("Get NULL ATOM ... selection"); EWOL_ERROR("Get nullptr ATOM ... selection");
break; break;
} }
if (req->target == 0) { if (req->target == 0) {
EWOL_ERROR("Get NULL ATOM ... target"); EWOL_ERROR("Get nullptr ATOM ... target");
break; break;
} }
char * atomNameProperty = XGetAtomName(m_display, req->property); char * atomNameProperty = XGetAtomName(m_display, req->property);
char * atomNameSelection = XGetAtomName(m_display, req->selection); char * atomNameSelection = XGetAtomName(m_display, req->selection);
char * atomNameTarget = XGetAtomName(m_display, req->target); char * atomNameTarget = XGetAtomName(m_display, req->target);
EWOL_INFO(" from: " << atomNameProperty << " request=" << atomNameSelection << " in " << atomNameTarget); EWOL_INFO(" from: " << atomNameProperty << " request=" << atomNameSelection << " in " << atomNameTarget);
if (NULL != atomNameProperty) { XFree(atomNameProperty); } if (nullptr != atomNameProperty) { XFree(atomNameProperty); }
if (NULL != atomNameSelection) { XFree(atomNameSelection); } if (nullptr != atomNameSelection) { XFree(atomNameSelection); }
if (NULL != atomNameTarget) { XFree(atomNameTarget); } if (nullptr != atomNameTarget) { XFree(atomNameTarget); }
} }
#endif #endif
@ -920,8 +920,8 @@ class X11Interface : public ewol::Context {
static char *title = (char*)"Ewol"; static char *title = (char*)"Ewol";
// Connect to the X server // Connect to the X server
m_display = XOpenDisplay(NULL); m_display = XOpenDisplay(nullptr);
if(NULL == m_display) { if(nullptr == m_display) {
EWOL_CRITICAL("Could not open display X."); EWOL_CRITICAL("Could not open display X.");
exit(-1); exit(-1);
} else { } else {
@ -934,7 +934,7 @@ class X11Interface : public ewol::Context {
ewol::Dimension::Millimeter); ewol::Dimension::Millimeter);
// get an appropriate visual // get an appropriate visual
m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl); m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl);
if (NULL == m_visual) { if (nullptr == m_visual) {
m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl); m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl);
m_doubleBuffered = false; m_doubleBuffered = false;
EWOL_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available"); EWOL_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available");
@ -1012,10 +1012,10 @@ class X11Interface : public ewol::Context {
StartupState->flags = StateHint; StartupState->flags = StateHint;
XSetWMProperties(m_display, m_WindowHandle,&textprop, &textprop,/* Window title/icon title*/ XSetWMProperties(m_display, m_WindowHandle,&textprop, &textprop,/* Window title/icon title*/
NULL, 0,/* Argv[], argc for program*/ nullptr, 0,/* Argv[], argc for program*/
&hints, /* Start position/size*/ &hints, /* Start position/size*/
StartupState,/* Iconised/not flag */ StartupState,/* Iconised/not flag */
NULL); nullptr);
XFree(StartupState); XFree(StartupState);
@ -1024,15 +1024,15 @@ class X11Interface : public ewol::Context {
//XIfEvent(m_display, &event, WaitForMapNotify, (char*)&m_WindowHandle); //XIfEvent(m_display, &event, WaitForMapNotify, (char*)&m_WindowHandle);
m_xim = XOpenIM(m_display, NULL, NULL, NULL); m_xim = XOpenIM(m_display, nullptr, NULL, NULL);
if (m_xim == NULL) { if (m_xim == nullptr) {
EWOL_ERROR("Could not open input method"); EWOL_ERROR("Could not open input method");
return false; return false;
} }
/* /*
XIMStyles *styles=NULL; XIMStyles *styles=nullptr;
char* failed_arg = XGetIMValues(m_xim, XNQueryInputStyle, &styles, NULL); char* failed_arg = XGetIMValues(m_xim, XNQueryInputStyle, &styles, nullptr);
if (failed_arg != NULL) { if (failed_arg != nullptr) {
EWOL_ERROR("XIM Can't get styles"); EWOL_ERROR("XIM Can't get styles");
return false; return false;
} }
@ -1040,8 +1040,8 @@ class X11Interface : public ewol::Context {
EWOL_INFO("style " << styles->supported_styles[iii]); EWOL_INFO("style " << styles->supported_styles[iii]);
} }
*/ */
m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_WindowHandle, NULL); m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_WindowHandle, nullptr);
if (m_xic == NULL) { if (m_xic == nullptr) {
EWOL_ERROR("Could not open IC"); EWOL_ERROR("Could not open IC");
return false; return false;
} }
@ -1083,7 +1083,7 @@ class X11Interface : public ewol::Context {
return; return;
} }
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()]; char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()];
if (NULL == tmpVal) { if (nullptr == tmpVal) {
EWOL_CRITICAL("Allocation error ..."); EWOL_CRITICAL("Allocation error ...");
return; return;
} }
@ -1191,7 +1191,7 @@ class X11Interface : public ewol::Context {
// Note when we free the pixmap ... the icon is removed ... == > this is a real memory leek ... // Note when we free the pixmap ... the icon is removed ... == > this is a real memory leek ...
//XFreePixmap(m_display, tmpPixmap); //XFreePixmap(m_display, tmpPixmap);
myImage->data = NULL; myImage->data = nullptr;
XDestroyImage(myImage); XDestroyImage(myImage);
delete[] tmpVal; delete[] tmpVal;
@ -1346,12 +1346,12 @@ class X11Interface : public ewol::Context {
int ewol::run(int _argc, const char *_argv[]) { int ewol::run(int _argc, const char *_argv[]) {
etk::setArgZero(_argv[0]); etk::setArgZero(_argv[0]);
X11Interface* interface = new X11Interface(_argc, _argv); X11Interface* interface = new X11Interface(_argc, _argv);
if (NULL == interface) { if (nullptr == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return -2; return -2;
} }
int32_t retValue = interface->run(); int32_t retValue = interface->run();
delete(interface); delete(interface);
interface = NULL; interface = nullptr;
return retValue; return retValue;
} }

View File

@ -52,7 +52,7 @@ int64_t guiInterface::getTime() {
int ret = clock_gettime(CLOCK_REALTIME, &now); int ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) { if (ret != 0) {
// Error to get the time ... // Error to get the time ...
now.tv_sec = time(NULL); now.tv_sec = time(nullptr);
now.tv_nsec = 0; now.tv_nsec = 0;
} }
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
@ -71,16 +71,16 @@ bool m_grabAllEvent = false;
// the super interface // the super interface
IDirectFB *dfb = NULL; IDirectFB *dfb = nullptr;
// the primary surface (surface of primary layer) // the primary surface (surface of primary layer)
IDirectFBSurface *primary = NULL; IDirectFBSurface *primary = nullptr;
// the GL context // the GL context
IDirectFBGL *primary_gl = NULL; IDirectFBGL *primary_gl = nullptr;
// event buffer // event buffer
IDirectFBEventBuffer *events = NULL; IDirectFBEventBuffer *events = nullptr;
static int screen_width =800; static int screen_width =800;
static int screen_height = 600; static int screen_height = 600;
@ -152,7 +152,7 @@ void DirectFB_Init(int argc, const char *argv[]) {
primary->setDstBlendFunction(primary, DSBF_SRCALPHA); primary->setDstBlendFunction(primary, DSBF_SRCALPHA);
primary->setDrawingFlags(primary, DSDRAW_BLEND); primary->setDrawingFlags(primary, DSDRAW_BLEND);
primary->Blit(primary, primary, NULL, 0, 0); primary->Blit(primary, primary, nullptr, 0, 0);
EWOL_INFO("call getSize"); EWOL_INFO("call getSize");
@ -175,7 +175,7 @@ void DirectFB_Init(int argc, const char *argv[]) {
} }
EWOL_INFO("call Flip"); EWOL_INFO("call Flip");
primary->Flip(primary, NULL, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC); primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
// NOTE : we need to force it on X11 display ... // NOTE : we need to force it on X11 display ...
EWOL_INFO("call getGL"); EWOL_INFO("call getGL");
@ -212,7 +212,7 @@ void DirectFB_Run() {
primary->FillRectangle(primary, 0, 0, screen_width, screen_height); primary->FillRectangle(primary, 0, 0, screen_width, screen_height);
primary->setColor (primary, 0xFF, (uint8_t)position, 0x00, 0xFF); primary->setColor (primary, 0xFF, (uint8_t)position, 0x00, 0xFF);
primary->FillRectangle(primary, position, position, 300, 300); primary->FillRectangle(primary, position, position, 300, 300);
primary->Flip(primary, NULL, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC); primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
position++; position++;
if (position>600) { if (position>600) {
position = 0; position = 0;
@ -234,7 +234,7 @@ void DirectFB_Run() {
EWOL_ERROR("primary_gl->Unlock"); EWOL_ERROR("primary_gl->Unlock");
DirectFBErrorFatal("primary_gl->Unlock", err); DirectFBErrorFatal("primary_gl->Unlock", err);
} }
primary->Flip(primary, NULL, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC); primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
} }
while (events->getEvent(events, DFB_EVENT(&evt)) == DFB_OK) { while (events->getEvent(events, DFB_EVENT(&evt)) == DFB_OK) {

View File

@ -78,7 +78,7 @@ namespace ewol {
enum ewol::key::status _status, enum ewol::key::status _status,
uint8_t _id, uint8_t _id,
const vec2& _pos, const vec2& _pos,
ewol::Widget* _dest, ewol::object::Shared<ewol::Widget> _dest,
int32_t _realIdEvent, int32_t _realIdEvent,
ewol::key::Special _specialKey) : ewol::key::Special _specialKey) :
m_event(_type, _status, _id, _pos, _specialKey), m_event(_type, _status, _id, _pos, _specialKey),
@ -86,13 +86,13 @@ namespace ewol {
m_realIdEvent(_realIdEvent) { }; m_realIdEvent(_realIdEvent) { };
ewol::event::Input m_event; ewol::event::Input m_event;
private: private:
ewol::Widget* m_dest; ewol::object::Shared<ewol::Widget> m_dest;
int32_t m_realIdEvent; int32_t m_realIdEvent;
public: public:
void setDestWidget(ewol::Widget* _dest) { void setDestWidget(ewol::object::Shared<ewol::Widget> _dest) {
m_dest = _dest; m_dest = _dest;
}; };
inline ewol::Widget* getDestWidget() const { inline ewol::object::Shared<ewol::Widget> getDestWidget() const {
return m_dest; return m_dest;
}; };
void setRealId(int32_t _realIdEvent) { void setRealId(int32_t _realIdEvent) {

View File

@ -13,19 +13,19 @@
std::ostream& ewol::operator <<(std::ostream& _os, const ewol::object::ConfigElement& _obj) { std::ostream& ewol::operator <<(std::ostream& _os, const ewol::object::ConfigElement& _obj) {
_os << "{"; _os << "{";
if (NULL != _obj.getConfig()) { if (nullptr != _obj.getConfig()) {
_os << "config=\"" << _obj.getConfig() << "\""; _os << "config=\"" << _obj.getConfig() << "\"";
} }
if (NULL != _obj.getType()) { if (nullptr != _obj.getType()) {
_os << " type=\"" << _obj.getType() << "\""; _os << " type=\"" << _obj.getType() << "\"";
} }
if (NULL != _obj.getControl()) { if (nullptr != _obj.getControl()) {
_os << " ctrl=\"" << _obj.getControl() << "\""; _os << " ctrl=\"" << _obj.getControl() << "\"";
} }
if (NULL != _obj.getDescription()) { if (nullptr != _obj.getDescription()) {
_os << " desc=\"" << _obj.getDescription() << "\""; _os << " desc=\"" << _obj.getDescription() << "\"";
} }
if (NULL != _obj.getDefault()) { if (nullptr != _obj.getDefault()) {
_os << " default=\"" << _obj.getDefault() << "\""; _os << " default=\"" << _obj.getDefault() << "\"";
} }
_os << "}"; _os << "}";

View File

@ -22,11 +22,11 @@ namespace ewol {
const char* m_default; //!< default value ... const char* m_default; //!< default value ...
public: public:
// note : no parameter capability is needed to create element in case of vector stoarage. // note : no parameter capability is needed to create element in case of vector stoarage.
ConfigElement(const char* _config = NULL, ConfigElement(const char* _config = nullptr,
const char* _type = NULL, const char* _type = nullptr,
const char* _control = NULL, const char* _control = nullptr,
const char* _description = NULL, const char* _description = nullptr,
const char* _default = NULL) : const char* _default = nullptr) :
m_config(_config), m_config(_config),
m_type(_type), m_type(_type),
m_control(_control), m_control(_control),

View File

@ -9,21 +9,20 @@
#include <ewol/object/Manager.h> #include <ewol/object/Manager.h>
#include <ewol/context/Context.h> #include <ewol/context/Context.h>
#include <ewol/ewol.h> #include <ewol/ewol.h>
#include <etk/stdTools.h>
#include <unistd.h> #include <unistd.h>
#undef __class__ #undef __class__
#define __class__ "ewol::object::Manager" #define __class__ "ewol::object::Manager"
ewol::object::Manager::Manager() { ewol::object::Manager::Manager(ewol::Context& _context) :
m_context(_context) {
EWOL_DEBUG(" == > init Object-Manager"); EWOL_DEBUG(" == > init Object-Manager");
// Can create mlemory leak ... == > but not predictable comportement otherwise ...
m_eObjectAutoRemoveList.clear();
m_eObjectList.clear();
} }
ewol::object::Manager::~Manager() { ewol::object::Manager::~Manager() {
bool hasError = false; bool hasError = false;
if (m_eObjectAutoRemoveList.size()!=0) { if (m_eObjectListActive.size()!=0) {
EWOL_ERROR("Must not have anymore eObject to auto-remove !!!"); EWOL_ERROR("Must not have anymore eObject to auto-remove !!!");
hasError = true; hasError = true;
} }
@ -34,168 +33,148 @@ ewol::object::Manager::~Manager() {
if (true == hasError) { if (true == hasError) {
EWOL_ERROR("Check if the function UnInit has been called !!!"); EWOL_ERROR("Check if the function UnInit has been called !!!");
} }
displayListObject();
}
void ewol::object::Manager::displayListObject() {
EWOL_INFO("List loaded object : ");
for (auto &it : m_eObjectList) {
EWOL_INFO(" Ref=" << it->getRefCount() << " remove=" << it->isDestroyed() << " name='" << it->getName() << "' type=" << it->getObjectType());
}
} }
void ewol::object::Manager::unInit() { void ewol::object::Manager::unInit() {
EWOL_DEBUG(" == > Un-Init Object-Manager"); EWOL_DEBUG(" == > Un-Init Object-Manager");
removeAllAutoRemove(); for (auto &it : m_eObjectList) {
EWOL_INFO(" remove missing user widget"); if (it != nullptr) {
size_t iii=0; //it->removeObject();
while(iii < m_eObjectList.size()) {
if (m_eObjectList[iii] != NULL) {
if ( m_eObjectList[iii]->getStatic() == true
|| m_eObjectList[iii]->getStatusResource() == true) {
iii++;
} else {
EWOL_WARNING("Un-INIT : remove Object type=\"" << m_eObjectList[iii]->getObjectType() << "\"");
m_eObjectList[iii].reset();
m_eObjectList[iii] = NULL;
}
} else {
m_eObjectList.erase(m_eObjectList.begin()+iii);
} }
} }
removeAllAutoRemove(); removeAllRemovedObject();
EWOL_INFO(" remove resources user widgets"); EWOL_INFO(" remove missing user object");
while(iii < m_eObjectList.size()) { if (m_eObjectListActive.size() != 0) {
if (m_eObjectList[iii] != NULL) { EWOL_ERROR("Have " << m_eObjectListActive.size() << " active Object");
if (m_eObjectList[iii]->getStatic() == true) {
iii++;
} else {
EWOL_WARNING("Un-INIT : remove Object type=\"" << m_eObjectList[iii]->getObjectType() << "\"");
m_eObjectList[iii].reset();
}
} else {
m_eObjectList.erase(m_eObjectList.begin()+iii);
}
}
removeAllAutoRemove();
EWOL_INFO(" remove static user widgets");
while(iii < m_eObjectList.size()) {
if (m_eObjectList[iii] != NULL) {
EWOL_WARNING("Un-INIT : remove Object type=\"" << m_eObjectList[iii]->getObjectType() << "\"");
m_eObjectList[iii].reset();
} else {
m_eObjectList.erase(m_eObjectList.begin()+iii);
}
} }
m_multiCast.clear();
m_eObjectListActive.clear();
m_eObjectList.clear();
removeAllRemovedObject();
} }
void ewol::object::Manager::add(ewol::Object* _object) { void ewol::object::Manager::add(const ewol::object::Shared<ewol::Object>& _object) {
if (_object == NULL) { if (_object == nullptr) {
EWOL_ERROR("try to add an inexistant Object in manager"); EWOL_ERROR("try to add an inexistant Object in manager");
} }
// ! < it might benerate a shared object !!!
m_eObjectList.push_back(_object); m_eObjectList.push_back(_object);
m_eObjectListActive.push_back(_object);
} }
int32_t ewol::object::Manager::getNumberObject() { int32_t ewol::object::Manager::getNumberObject() {
return m_eObjectList.size() + m_eObjectAutoRemoveList.size(); return m_eObjectList.size();
} }
void ewol::object::Manager::informOneObjectIsRemoved(ewol::Object* _object) { void ewol::object::Manager::informOneObjectIsRemoved(const ewol::object::Shared<ewol::Object>& _object) {
size_t mbElement = m_eObjectList.size(); for (auto &it : m_eObjectList) {
for (int64_t iii=0; iii<(int64_t)m_eObjectList.size(); ++iii) { if ( it != nullptr
if ( m_eObjectList[iii] != NULL && it != _object) {
&& m_eObjectList[iii] != _object) { EWOL_VERBOSE("[" << _object->getId() << "] onObjectRemove() : " << it->getId() << " type=" << it->getObjectType() << " name='" << it->getName() << "'");
//EWOL_DEBUG("inform " << iii+1 << "/" << m_eObjectList.size()); it->onObjectRemove(_object);
//EWOL_DEBUG(" id=" << m_eObjectList[iii]->getId() << " named '" << m_eObjectList[iii]->getName() << "' type=" << m_eObjectList[iii]->getObjectType());
m_eObjectList[iii]->onObjectRemove(_object);
if (mbElement != m_eObjectList.size()) {
iii = -1;
mbElement = m_eObjectList.size();
} }
} }
// inform context that n object is removed ...
m_context.onObjectRemove(_object);
m_multiCast.onObjectRemove(_object);
EWOL_VERBOSE("m_removeEventList.size() = " << m_removeEventList.size());
for (auto &it : m_removeEventList) {
EWOL_VERBOSE("[" << _object->getId() << "] Inform Event Remove Object List : ...");
it->onObjectRemove(_object);
} }
//EWOL_DEBUG("inform active done");
mbElement = m_eObjectAutoRemoveList.size();
for (size_t iii=0; iii<m_eObjectAutoRemoveList.size(); iii++) {
if( m_eObjectAutoRemoveList[iii] != NULL
&& m_eObjectAutoRemoveList[iii] != _object) {
//EWOL_DEBUG("inform2 " << iii+1 << "/" << m_eObjectAutoRemoveList.size());
m_eObjectAutoRemoveList[iii]->onObjectRemove(_object);
if (mbElement != m_eObjectAutoRemoveList.size()) {
iii = -1;
mbElement = m_eObjectAutoRemoveList.size();
}
}
}
//EWOL_DEBUG("inform in-active done");
// call input event manager to remove linked widget ...
ewol::getContext().onObjectRemove(_object);
} }
void ewol::object::Manager::rm(ewol::Object* _object) { void ewol::object::Manager::respown(const ewol::object::Shared<ewol::Object>& _object){
if (NULL == _object) { if (_object == nullptr) {
EWOL_ERROR("Try to remove (NULL) Object"); EWOL_ERROR("Try to respown nullptr Object");
return; return;
} }
for (size_t iii=0; iii<m_eObjectList.size(); iii++) { for (auto it : m_eObjectListActive) {
if (m_eObjectList[iii] == _object) { if (it == _object) {
EWOL_ERROR("try to respawn an existing active Object : [" << _object->getId() << "] type='" << _object->getObjectType() << "'");
return;
}
}
m_eObjectListActive.push_back(_object);
}
void ewol::object::Manager::remove(const ewol::object::Shared<ewol::Object>& _object) {
if (_object == nullptr) {
EWOL_ERROR("Try to Auto-Remove (nullptr) Object");
return;
}
int32_t count = 0;
auto it(m_eObjectListActive.begin());
while (it != m_eObjectListActive.end()) {
if (*it == _object) {
m_eObjectListActive.erase(it);
// remove Element // remove Element
m_eObjectList[iii] = NULL; EWOL_DEBUG("Auto-Remove Object : [" << _object->getId() << "] type='" << _object->getObjectType() << "' name=" << _object->getName());
m_eObjectList.erase(m_eObjectList.begin()+iii);
informOneObjectIsRemoved(_object); informOneObjectIsRemoved(_object);
return;
}
}
// check if the object has not been auto removed ... or remove in defered time ...
for (size_t iii=0; iii<m_eObjectAutoRemoveList.size(); iii++) {
if( m_eObjectAutoRemoveList[iii] != NULL
&& m_eObjectAutoRemoveList[iii] == _object) {
return;
}
}
// in this case, we have an error ...
EWOL_ERROR("Try to remove Object that is not referenced ...");
}
void ewol::object::Manager::autoRemove(ewol::Object* _object) {
if (NULL == _object) {
EWOL_ERROR("Try to Auto-Remove (NULL) Object");
return;
}
for (size_t iii=0; iii<m_eObjectList.size(); iii++) {
if (m_eObjectList[iii] == _object) {
// remove Element
m_eObjectList[iii] = NULL;
m_eObjectList.erase(m_eObjectList.begin()+iii);
EWOL_DEBUG("Auto-Remove Object : [" << _object->getId() << "] type='" << _object->getObjectType() << "'");
if (_object->getStatusResource() == false) {
informOneObjectIsRemoved(_object);
}
m_eObjectAutoRemoveList.push_back(_object);
ewol::getContext().forceRedrawAll(); ewol::getContext().forceRedrawAll();
EWOL_DEBUG("Auto-Remove Object ... done"); EWOL_VERBOSE("Auto-Remove Object ... done (have " << _object->getRefCount() << " references)");
return; it = m_eObjectListActive.begin();
count++;
} else {
++it;
} }
} }
if (count == 0) {
EWOL_ERROR("Try to Auto-Remove Object that is not referenced ..."); EWOL_ERROR("Try to Auto-Remove Object that is not referenced ...");
} else if ( count>1
|| count<0) {
EWOL_ERROR("Remove more than one object in the system list ==> this is a real problem ...");
}
} }
// clean all Object that request an autoRemove ... // clean all Object that request an autoRemove ...
void ewol::object::Manager::removeAllAutoRemove() { void ewol::object::Manager::removeAllRemovedObject() {
//EWOL_DEBUG("Auto-Remove Object section : " << m_eObjectAutoRemoveList.size() << " elemeents"); EWOL_VERBOSE("Clean Object List (if needed) : " << m_eObjectListActive.size() << "/" << m_eObjectList.size() << " elemeents");
while(0<m_eObjectAutoRemoveList.size()) { auto it(m_eObjectList.begin());
if (m_eObjectAutoRemoveList[0] != NULL) { while (it != m_eObjectList.end()) {
EWOL_DEBUG("Real Auto-Remove Object [" << m_eObjectAutoRemoveList[0]->getId() << "]type='" << m_eObjectAutoRemoveList[0]->getObjectType() << "'"); if ( *it != nullptr
&& (*it)->getRefCount() <= 1) {
EWOL_DEBUG("remove definitly : [" << (*it)->getId() << "] type='" << (*it)->getObjectType() << "'");
m_eObjectList.erase(it);
it = m_eObjectList.begin();
} else {
++it;
} }
m_eObjectAutoRemoveList.erase(m_eObjectAutoRemoveList.begin());
} }
m_eObjectAutoRemoveList.clear();
} }
ewol::Object* ewol::object::Manager::get(const std::string& _name) { ewol::object::Shared<ewol::Object> ewol::object::Manager::get(const std::string& _name) {
if (_name == "") { if (_name == "") {
return NULL; return nullptr;
} }
for (size_t iii=0; iii<m_eObjectList.size(); iii++) { for (auto &it : m_eObjectList) {
if (m_eObjectList[iii] != NULL) { if ( it != nullptr
if (m_eObjectList[iii]->getName() == _name) { && it->getName() == _name) {
return m_eObjectList[iii].get(); return it;
}
}
return nullptr;
}
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<m_removeEventList.size(); ++iii) {
if (m_removeEventList[iii] == _class) {
m_removeEventList.erase(m_removeEventList.begin() + iii);
return;
} }
} }
}
return NULL;
} }

View File

@ -12,37 +12,63 @@
#include <etk/types.h> #include <etk/types.h>
#include <ewol/object/Object.h> #include <ewol/object/Object.h>
#include <ewol/object/MultiCast.h> #include <ewol/object/MultiCast.h>
#include <ewol/object/RemoveEvent.h>
namespace ewol { namespace ewol {
class Context;
namespace object { namespace object {
class Manager { class Manager {
private: private:
std::vector<ewol::Object::Shared<ewol::Object>> m_eObjectList; // all widget allocated == > all time increment ... never removed ... std::vector<ewol::object::RemoveEvent*> m_removeEventList;
std::vector<ewol::Object::Shared<ewol::Object>> m_eObjectAutoRemoveList; // all widget allocated std::vector<ewol::object::Shared<ewol::Object>> m_eObjectList; // all widget allocated == > all time increment ... never removed ...
std::vector<ewol::object::Shared<ewol::Object>> m_eObjectListActive; // all active widget
Context& m_context;
public: public:
Manager(); Manager(Context& _context);
~Manager(); virtual ~Manager();
/** /**
* @brief remove all resources (un-init) out of the destructor (due to the system implementation) * @brief remove all resources (un-init) out of the destructor (due to the system implementation)
*/ */
void unInit(); void unInit();
/**
void add(ewol::Object* _object); * @brief Get the number of loaded object in the system
void rm(ewol::Object* _object); * @return number of Object
*/
int32_t getNumberObject(); int32_t getNumberObject();
void displayListObject();
void autoRemove(ewol::Object* _object);
void removeAllAutoRemove();
ewol::Object* get(const std::string& _name);
private: private:
void informOneObjectIsRemoved(ewol::Object* _object); friend class ewol::Object;
/**
* @brief Internal API that used only with Object toi reference itself in the manager.
* @note The manager remove the object when the refecence Low down 1 (last keeper)
* @param[in] _object Reference shared pointer on the object
*/
void add(const ewol::object::Shared<ewol::Object>& _object);
/**
* @brief Called when an object request to be removed
* @param[in] _object Reference shared pointer on the object
*/
void remove(const ewol::object::Shared<ewol::Object>& _object);
/**
* @brief Called when a user want to reuse an object that have been removed previously
* @param[in] _object Reference shared pointer on the object
*/
void respown(const ewol::object::Shared<ewol::Object>& _object);
public:
void removeAllRemovedObject();
ewol::object::Shared<ewol::Object> get(const std::string& _name);
private:
void informOneObjectIsRemoved(const ewol::object::Shared<ewol::Object>& _object);
private: private:
ewol::object::MultiCast m_multiCast; //!< muticast manager ewol::object::MultiCast m_multiCast; //!< muticast manager
public: public:
ewol::object::MultiCast& multiCast() { ewol::object::MultiCast& multiCast() {
return m_multiCast; return m_multiCast;
}; };
void add(ewol::object::RemoveEvent* _class);
void rm(ewol::object::RemoveEvent* _class);
}; };
}; };
}; };

View File

@ -13,10 +13,10 @@
std::ostream& ewol::object::operator <<(std::ostream& _os, const ewol::object::Message& _obj) { std::ostream& ewol::object::operator <<(std::ostream& _os, const ewol::object::Message& _obj) {
_os << "{"; _os << "{";
if (NULL != _obj.getMessage()) { if (nullptr != _obj.getMessage()) {
_os << "msg=\"" << _obj.getMessage() << "\""; _os << "msg=\"" << _obj.getMessage() << "\"";
} else { } else {
_os << "msg={NULL}"; _os << "msg={nullptr}";
} }
_os << " data=\"" << _obj.getData() << "\"}"; _os << " data=\"" << _obj.getData() << "\"}";
return _os; return _os;

View File

@ -15,11 +15,11 @@ namespace ewol {
namespace object { namespace object {
class Message { class Message {
private: private:
ewol::Object* m_callerObject; //!< Caller class. ewol::object::Shared<ewol::Object> m_callerObject; //!< Caller class.
const char* m_event; //!< Event pointer == > unique Id define by the system ... const char* m_event; //!< Event pointer == > unique Id define by the system ...
std::string m_data; //!< compositing additionnal message Value. std::string m_data; //!< compositing additionnal message Value.
public: public:
Message(ewol::Object* _caller, Message(const ewol::object::Shared<ewol::Object>& _caller,
const char* _message, const char* _message,
const std::string& _data) : const std::string& _data) :
m_callerObject(_caller), m_callerObject(_caller),
@ -27,10 +27,10 @@ namespace ewol {
m_data(_data) { m_data(_data) {
}; };
void setCaller(ewol::Object* _caller) { void setCaller(const ewol::object::Shared<ewol::Object>& _caller) {
m_callerObject = _caller; m_callerObject = _caller;
}; };
inline ewol::Object* getCaller() const { inline ewol::object::Shared<ewol::Object> getCaller() const {
return m_callerObject; return m_callerObject;
}; };
void setMessage(const char* _message) { void setMessage(const char* _message) {

View File

@ -23,14 +23,30 @@ ewol::object::MultiCast::~MultiCast() {
m_messageList.clear(); m_messageList.clear();
} }
void ewol::object::MultiCast::clear() {
EWOL_INFO("EObject message Multi-Cast");
m_messageList.clear();
}
void ewol::object::MultiCast::add(ewol::Object* _object, const char* const _message) { void ewol::object::MultiCast::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
if (NULL == _object) { auto it(m_messageList.begin());
EWOL_ERROR("Add with NULL object"); while (it != m_messageList.end()) {
if (it->m_object == _object) {
m_messageList.erase(it);
it = m_messageList.begin();
} else {
++it;
}
}
}
void ewol::object::MultiCast::add(const ewol::object::Shared<ewol::Object>& _object, const char* const _message) {
if (nullptr == _object) {
EWOL_ERROR("Add with nullptr object");
return; return;
} }
if (NULL == _message) { if (nullptr == _message) {
EWOL_ERROR("Add with NULL Message"); EWOL_ERROR("Add with nullptr Message");
return; return;
} }
m_messageList.push_back(MessageList(_message, _object)); m_messageList.push_back(MessageList(_message, _object));
@ -38,35 +54,36 @@ void ewol::object::MultiCast::add(ewol::Object* _object, const char* const _mess
} }
void ewol::object::MultiCast::rm(ewol::Object* _object) { void ewol::object::MultiCast::rm(const ewol::object::Shared<ewol::Object>& _object) {
if (NULL == _object) { if (nullptr == _object) {
EWOL_ERROR("Rm with NULL object"); EWOL_ERROR("Rm with nullptr object");
return; return;
} }
// send the message at all registered widget ... // send the message at all registered widget ...
for (int32_t iii=m_messageList.size()-1; iii >= 0; iii--) { auto it(m_messageList.begin());
if(m_messageList[iii].m_object == _object) { while (it != m_messageList.end()) {
if(it->m_object == _object) {
EWOL_DEBUG("SendMulticast RM listener :" << _object->getId()); EWOL_DEBUG("SendMulticast RM listener :" << _object->getId());
m_messageList[iii].m_message = NULL; m_messageList.erase(it);
m_messageList[iii].m_object = NULL; it = m_messageList.begin();
m_messageList.erase(m_messageList.begin()+iii); } else {
++it;
} }
} }
} }
void ewol::object::MultiCast::send(ewol::Object* _object, const char* const _message, const std::string& _data) { void ewol::object::MultiCast::send(const ewol::object::Shared<ewol::Object>& _object, const char* const _message, const std::string& _data) {
EWOL_VERBOSE("SendMulticast message \"" << _message << "\" data=\"" << _data << "\" to :"); EWOL_VERBOSE("SendMulticast message \"" << _message << "\" data=\"" << _data << "\" to :");
// send the message at all registered widget ... // send the message at all registered widget ...
for (size_t iii=0; iii<m_messageList.size(); iii++) { for (auto &it : m_messageList) {
if( m_messageList[iii].m_message == _message if( it.m_message == _message
&& m_messageList[iii].m_object != _object) && it.m_object != _object) {
{ if (it.m_object != nullptr) {
if (NULL != m_messageList[iii].m_object) { EWOL_VERBOSE(" id = " << it.m_object->getId() << " type=" << it.m_object->getObjectType());
EWOL_VERBOSE(" id = " << m_messageList[iii].m_object->getId() << " type=" << m_messageList[iii].m_object->getObjectType());
// generate event ... (create message before ... // generate event ... (create message before ...
ewol::object::Message tmpMsg(_object, m_messageList[iii].m_message, _data); ewol::object::Message tmpMsg(_object, it.m_message, _data);
m_messageList[iii].m_object->onReceiveMessage(tmpMsg); it.m_object->onReceiveMessage(tmpMsg);
} }
} }
} }

View File

@ -22,23 +22,25 @@ namespace ewol {
private: private:
class MessageList { class MessageList {
public: public:
MessageList(const char* _message=NULL, ewol::Object* _object=NULL) : MessageList(const char* _message=nullptr, ewol::object::Shared<ewol::Object> _object=nullptr) :
m_message(_message), m_object(_object) { m_message(_message), m_object(_object) {
} }
const char* m_message; const char* m_message;
ewol::Object* m_object; ewol::object::Shared<ewol::Object> m_object;
}; };
std::vector<MessageList> m_messageList; //!< List of all message ... std::vector<MessageList> m_messageList; //!< List of all message ...
public: public:
MultiCast(); MultiCast();
~MultiCast(); virtual ~MultiCast();
void clear();
void anonymousSend(const char* const _messageId, const std::string& _data) { void anonymousSend(const char* const _messageId, const std::string& _data) {
send(NULL, _messageId, _data); send(nullptr, _messageId, _data);
}; };
void send(ewol::Object* _object, const char* const _message, const std::string& _data); void send(const ewol::object::Shared<ewol::Object>& _object, const char* const _message, const std::string& _data);
void rm(ewol::Object* _object); void rm(const ewol::object::Shared<ewol::Object>& _object);
void add(ewol::Object* _object, const char* const _message); void add(const ewol::object::Shared<ewol::Object>& _object, const char* const _message);
void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
}; };
}; };
}; };

View File

@ -13,7 +13,7 @@
#include <ewol/object/MultiCast.h> #include <ewol/object/MultiCast.h>
#undef __class__ #undef __class__
#define __class__ "ewol::Object" #define __class__ "Object"
const char* const ewol::Object::configName = "name"; const char* const ewol::Object::configName = "name";
@ -21,22 +21,37 @@ size_t ewol::Object::m_valUID = 0;
void ewol::Object::objRefCountIncrement() { void ewol::Object::objRefCountIncrement() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
/*
if (std::string("ewol::widget::Windows") == getObjectType()) {
EWOL_ERROR("increment Windows count ++" << m_objRefCount);
//etk::log::displayBacktrace();
}
*/
m_objRefCount++; m_objRefCount++;
} }
void ewol::Object::objRefCountDecrement() { void ewol::Object::objRefCountDecrement() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
/*
if (std::string("ewol::widget::Windows") == getObjectType()) {
EWOL_ERROR("Decrement Windows count --" << m_objRefCount);
//etk::log::displayBacktrace();
}
*/
m_objRefCount--; m_objRefCount--;
} }
void ewol::Object::operator delete(void* _ptr, std::size_t _sz) { void ewol::Object::operator delete(void* _ptr, std::size_t _sz) {
EWOL_DEBUG("custom delete for size " << _sz); EWOL_VERBOSE("custom delete for size " << _sz);
ewol::Object* obj = (ewol::Object*)_ptr; ewol::Object* obj = (ewol::Object*)_ptr;
obj->objRefCountDecrement(); obj->objRefCountDecrement();
if (obj->m_objRefCount <= 0) { if (obj->m_objRefCount <= 0) {
EWOL_DEBUG(" ==> real remove"); EWOL_VERBOSE(" ==> real remove");
::operator delete(_ptr); ::operator delete(_ptr);
} else { } else {
EWOL_DEBUG(" ==> Some user is link on it ..."); EWOL_ERROR(" ==> Some user is link on it : " << obj->m_objRefCount);
etk::log::displayBacktrace();
} }
} }
@ -44,21 +59,76 @@ void ewol::Object::operator delete[](void* _ptr, std::size_t _sz) {
EWOL_CRITICAL("custom delete for size ==> not implemented ..." << _sz); EWOL_CRITICAL("custom delete for size ==> not implemented ..." << _sz);
::operator delete(_ptr); ::operator delete(_ptr);
} }
#ifdef DEBUG
void ewol::Object::incOwnerCount() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
m_ownerCount++;
if (m_ownerCount>1) {
EWOL_CRITICAL("Multiple Owner on one Object ==> very bad ... " << m_ownerCount);
}
}
void ewol::Object::decOwnerCount() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
m_ownerCount--;
if (m_ownerCount<0) {
EWOL_CRITICAL("Owner remove the owner counter under 1 ==> very bad ... " << m_ownerCount);
}
}
#endif
void ewol::Object::autoDestroy() {
EWOL_VERBOSE("Destroy object : [" << getId() << "] type:" << getObjectType());
bool needRemove = false;
{
std::unique_lock<std::mutex> lock(m_lockRefCount);
if (m_isDestroyed == true) {
EWOL_WARNING("Request remove of a removed object");
return;
} else {
m_isDestroyed = true;
needRemove = true;
}
}
if (needRemove == true) {
getObjectManager().remove(this);
}
}
void ewol::Object::removeObject() {
autoDestroy();
}
void ewol::Object::respownObject() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
if (m_isDestroyed == false) {
EWOL_WARNING("Respawn an alive object");
return;
}
m_isDestroyed = false;
getObjectManager().respown(this);
}
ewol::Object::Object() : ewol::Object::Object() :
m_objRefCount(1), m_objRefCount(1),
#ifdef DEBUG
m_ownerCount(0),
#endif
m_isDestroyed(false),
m_static(false), m_static(false),
m_isResource(false) { m_isResource(false) {
// note this is nearly atomic ... (but it is enough) // note this is nearly atomic ... (but it is enough)
m_uniqueId = m_valUID++; m_uniqueId = m_valUID++;
EWOL_DEBUG("new Object : [" << m_uniqueId << "]"); EWOL_DEBUG("new Object : [" << m_uniqueId << "]");
getObjectManager().add(this); getObjectManager().add(this);
registerConfig(configName, "string", NULL, "Object name, might be a unique reference in all the program"); registerConfig(configName, "string", nullptr, "Object name, might be a unique reference in all the program");
} }
ewol::Object::Object(const std::string& _name) : ewol::Object::Object(const std::string& _name) :
m_objRefCount(1), m_objRefCount(1),
#ifdef DEBUG
m_ownerCount(0),
#endif
m_isDestroyed(false),
m_static(false), m_static(false),
m_name(_name), m_name(_name),
m_isResource(false) { m_isResource(false) {
@ -66,19 +136,12 @@ ewol::Object::Object(const std::string& _name) :
m_uniqueId = m_valUID++; m_uniqueId = m_valUID++;
EWOL_DEBUG("new Object : [" << m_uniqueId << "]"); EWOL_DEBUG("new Object : [" << m_uniqueId << "]");
getObjectManager().add(this); getObjectManager().add(this);
registerConfig(configName, "string", NULL, "Object name, might be a unique reference in all the program"); registerConfig(configName, "string", nullptr, "Object name, might be a unique reference in all the program");
} }
ewol::Object::~Object() { ewol::Object::~Object() {
EWOL_DEBUG("delete Object : [" << m_uniqueId << "] : " << getTypeDescription()); EWOL_DEBUG("delete Object : [" << m_uniqueId << "] : " << getTypeDescription() << " refcount=" << m_objRefCount);
getObjectManager().rm(this);
getMultiCast().rm(this); getMultiCast().rm(this);
for (size_t iii=0; iii<m_externEvent.size(); iii++) {
if (NULL!=m_externEvent[iii]) {
delete(m_externEvent[iii]);
m_externEvent[iii] = NULL;
}
}
m_externEvent.clear(); m_externEvent.clear();
m_availlableEventId.clear(); m_availlableEventId.clear();
m_uniqueId = -1; m_uniqueId = -1;
@ -92,7 +155,7 @@ const char * const ewol::Object::getObjectType() {
} }
void ewol::Object::addObjectType(const char* _type) { void ewol::Object::addObjectType(const char* _type) {
if (_type == NULL) { if (_type == nullptr) {
EWOL_ERROR(" try to add a type with no value..."); EWOL_ERROR(" try to add a type with no value...");
return; return;
} }
@ -119,16 +182,14 @@ bool ewol::Object::isTypeCompatible(const std::string& _type) {
return false; return false;
} }
void ewol::Object::autoDestroy() {
getObjectManager().autoRemove(this);
}
void ewol::Object::removeObject() {
getObjectManager().autoRemove(this);
}
void ewol::Object::addEventId(const char * _generateEventId) { void ewol::Object::addEventId(const char * _generateEventId) {
if (NULL != _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); m_availlableEventId.push_back(_generateEventId);
} }
} }
@ -137,29 +198,25 @@ void ewol::Object::generateEventId(const char * _generateEventId, const std::str
int32_t nbObject = getObjectManager().getNumberObject(); int32_t nbObject = getObjectManager().getNumberObject();
EWOL_VERBOSE("try send message '" << _generateEventId << "'"); EWOL_VERBOSE("try send message '" << _generateEventId << "'");
// for every element registered ... // for every element registered ...
for (size_t iii=0; iii<m_externEvent.size(); iii++) { for (auto &it : m_externEvent) {
if (NULL==m_externEvent[iii]) {
EWOL_VERBOSE(" Null pointer");
continue;
}
// if we find the event ... // if we find the event ...
if (m_externEvent[iii]->localEventId != _generateEventId) { if (it.localEventId != _generateEventId) {
EWOL_VERBOSE(" wrong event '" << m_externEvent[iii]->localEventId << "' != '" << _generateEventId << "'"); EWOL_VERBOSE(" wrong event '" << it.localEventId << "' != '" << _generateEventId << "'");
continue; continue;
} }
if (m_externEvent[iii]->destObject == NULL) { if (it.destObject == nullptr) {
EWOL_VERBOSE(" NULL dest"); EWOL_VERBOSE(" nullptr dest");
continue; continue;
} }
if (m_externEvent[iii]->overloadData.size() <= 0){ if (it.overloadData.size() <= 0){
ewol::object::Message tmpMsg(this, m_externEvent[iii]->destEventId, _data); ewol::object::Message tmpMsg(this, it.destEventId, _data);
EWOL_VERBOSE("send message " << tmpMsg); EWOL_VERBOSE("send message " << tmpMsg);
m_externEvent[iii]->destObject->onReceiveMessage(tmpMsg); it.destObject->onReceiveMessage(tmpMsg);
} else { } else {
// set the user requested data ... // set the user requested data ...
ewol::object::Message tmpMsg(this, m_externEvent[iii]->destEventId, m_externEvent[iii]->overloadData); ewol::object::Message tmpMsg(this, it.destEventId, it.overloadData);
EWOL_VERBOSE("send message " << tmpMsg); EWOL_VERBOSE("send message " << tmpMsg);
m_externEvent[iii]->destObject->onReceiveMessage(tmpMsg); it.destObject->onReceiveMessage(tmpMsg);
} }
} }
if (nbObject > getObjectManager().getNumberObject()) { if (nbObject > getObjectManager().getNumberObject()) {
@ -179,34 +236,30 @@ void ewol::Object::registerMultiCast(const char* const _messageId) {
getMultiCast().add(this, _messageId); getMultiCast().add(this, _messageId);
} }
void ewol::Object::registerOnEvent(ewol::Object * _destinationObject, void ewol::Object::registerOnEvent(const ewol::object::Shared<ewol::Object>& _destinationObject,
const char * _eventId, const char * _eventId,
const char * _eventIdgenerated, const char * _eventIdgenerated,
const std::string& _overloadData) { const std::string& _overloadData) {
if (NULL == _destinationObject) { if (nullptr == _destinationObject) {
EWOL_ERROR("Input ERROR NULL pointer Object ..."); EWOL_ERROR("Input ERROR nullptr pointer Object ...");
return; return;
} }
if (NULL == _eventId) { if (nullptr == _eventId) {
EWOL_ERROR("Input ERROR NULL pointer Event Id..."); EWOL_ERROR("Input ERROR nullptr pointer Event Id...");
return; return;
} }
if ( _eventId[0] == '*' if ( _eventId[0] == '*'
&& _eventId[1] == '\0') { && _eventId[1] == '\0') {
EWOL_VERBOSE("Register on all event ..."); EWOL_VERBOSE("Register on all event ...");
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) { for(auto &it : m_availlableEventId) {
ewol::object::EventExtGen * tmpEvent = new ewol::object::EventExtGen(); ewol::object::EventExtGen tmpEvent;
if (NULL == tmpEvent) { tmpEvent.localEventId = it;
EWOL_ERROR("Allocation error in Register Event..."); tmpEvent.destObject = _destinationObject;
continue; tmpEvent.overloadData = _overloadData;
} if (nullptr != _eventIdgenerated) {
tmpEvent->localEventId = m_availlableEventId[iii]; tmpEvent.destEventId = _eventIdgenerated;
tmpEvent->destObject = _destinationObject;
tmpEvent->overloadData = _overloadData;
if (NULL != _eventIdgenerated) {
tmpEvent->destEventId = _eventIdgenerated;
} else { } else {
tmpEvent->destEventId = m_availlableEventId[iii]; tmpEvent.destEventId = it;
} }
m_externEvent.push_back(tmpEvent); m_externEvent.push_back(tmpEvent);
} }
@ -214,18 +267,18 @@ void ewol::Object::registerOnEvent(ewol::Object * _destinationObject,
} }
// check if event existed : // check if event existed :
bool findIt = false; bool findIt = false;
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) { for(auto &it : m_availlableEventId) {
if (m_availlableEventId[iii] == _eventId) { if (it == _eventId) {
findIt = true; findIt = true;
break; break;
} }
} }
if (false == findIt) { if (false == findIt) {
EWOL_VERBOSE("Try to register with a NON direct string name"); EWOL_VERBOSE("Try to register with a NON direct string name");
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) { for(auto &it : m_availlableEventId) {
if (0 == strncmp(m_availlableEventId[iii], _eventId, 1024)) { if (0 == strncmp(it, _eventId, 1024)) {
findIt = true; findIt = true;
_eventId = m_availlableEventId[iii]; _eventId = it;
EWOL_VERBOSE("find event ID : '" << _eventId << "' ==> '" << _eventIdgenerated << "'"); EWOL_VERBOSE("find event ID : '" << _eventId << "' ==> '" << _eventIdgenerated << "'");
break; break;
} }
@ -235,50 +288,54 @@ void ewol::Object::registerOnEvent(ewol::Object * _destinationObject,
EWOL_ERROR("Can not register event on this Type=" << getObjectType() << " event=\"" << _eventId << "\" == > unknow event"); EWOL_ERROR("Can not register event on this Type=" << getObjectType() << " event=\"" << _eventId << "\" == > unknow event");
return; return;
} }
ewol::object::EventExtGen * tmpEvent = new ewol::object::EventExtGen(); ewol::object::EventExtGen tmpEvent;
if (NULL == tmpEvent) { tmpEvent.localEventId = _eventId;
EWOL_ERROR("Allocation error in Register Event..."); tmpEvent.destObject = _destinationObject;
return; tmpEvent.overloadData = _overloadData;
} if (nullptr != _eventIdgenerated) {
tmpEvent->localEventId = _eventId; tmpEvent.destEventId = _eventIdgenerated;
tmpEvent->destObject = _destinationObject;
tmpEvent->overloadData = _overloadData;
if (NULL != _eventIdgenerated) {
tmpEvent->destEventId = _eventIdgenerated;
} else { } else {
tmpEvent->destEventId = _eventId; tmpEvent.destEventId = _eventId;
} }
m_externEvent.push_back(tmpEvent); m_externEvent.push_back(tmpEvent);
} }
void ewol::Object::unRegisterOnEvent(ewol::Object * _destinationObject, void ewol::Object::unRegisterOnEvent(const ewol::object::Shared<ewol::Object>& _destinationObject,
const char * _eventId) { const char * _eventId) {
if (NULL == _destinationObject) { if (_destinationObject == nullptr) {
EWOL_ERROR("Input ERROR NULL pointer Object ..."); EWOL_ERROR("Input ERROR nullptr pointer Object ...");
return; return;
} }
// check if event existed : // check if event existed :
for(int64_t iii = m_externEvent.size()-1; iii >= 0; --iii) { auto it(m_externEvent.begin());
if (m_externEvent[iii] == NULL) { while(it != m_externEvent.end()) {
continue; if (it->destObject == nullptr) {
} m_externEvent.erase(it);
if (m_externEvent[iii]->destObject != _destinationObject) { it = m_externEvent.begin();
continue; } else if ( it->destObject == _destinationObject
} && it->localEventId == _eventId) {
if (_eventId == NULL) { m_externEvent.erase(it);
m_externEvent.erase(m_externEvent.begin()+iii); it = m_externEvent.begin();
} else if (m_externEvent[iii]->localEventId == _eventId) { EWOL_INFO("[" << getId() << "] Remove extern event : to object id=" << _destinationObject->getId() << " event=" << _eventId);
m_externEvent.erase(m_externEvent.begin()+iii); } else {
++it;
} }
} }
} }
void ewol::Object::onObjectRemove(ewol::Object * _removObject) { void ewol::Object::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
for(int32_t iii=m_externEvent.size()-1; iii >= 0; iii--) { EWOL_VERBOSE("[" << getId() << "] onObjectRemove(" << _object->getId() << ")");
if (NULL == m_externEvent[iii]) { auto it(m_externEvent.begin());
m_externEvent.erase(m_externEvent.begin()+iii); while(it != m_externEvent.end()) {
} else if (m_externEvent[iii]->destObject == _removObject) { if (it->destObject == nullptr) {
m_externEvent.erase(m_externEvent.begin()+iii); m_externEvent.erase(it);
it = m_externEvent.begin();
} else if (it->destObject == _object) {
m_externEvent.erase(it);
it = m_externEvent.begin();
EWOL_INFO("[" << getId() << "] Remove extern event : to object id=" << _object->getId());
} else {
++it;
} }
} }
} }
@ -289,12 +346,12 @@ void ewol::Object::registerConfig(const char* _config,
const char* _control, const char* _control,
const char* _description, const char* _description,
const char* _default) { const char* _default) {
if (NULL == _config) { if (nullptr == _config) {
EWOL_ERROR("Try to add NULL config"); EWOL_ERROR("Try to add nullptr config");
return; return;
} }
for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) { for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) {
if (NULL != m_listConfig[iii].getConfig()) { if (nullptr != m_listConfig[iii].getConfig()) {
if (0 == strcmp(m_listConfig[iii].getConfig(), _config) ) { if (0 == strcmp(m_listConfig[iii].getConfig(), _config) ) {
EWOL_ERROR("Try to add config already added : " << _config << " at pos=" << iii); EWOL_ERROR("Try to add config already added : " << _config << " at pos=" << iii);
} }
@ -305,12 +362,12 @@ void ewol::Object::registerConfig(const char* _config,
bool ewol::Object::loadXML(exml::Element* _node) { bool ewol::Object::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
bool errorOccured = true; bool errorOccured = true;
for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) { for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) {
if (m_listConfig[iii].getConfig() == NULL) { if (m_listConfig[iii].getConfig() == nullptr) {
continue; continue;
} }
if (_node->existAttribute(m_listConfig[iii].getConfig()) == false) { if (_node->existAttribute(m_listConfig[iii].getConfig()) == false) {
@ -325,16 +382,16 @@ bool ewol::Object::loadXML(exml::Element* _node) {
} }
bool ewol::Object::storeXML(exml::Element* _node) const { bool ewol::Object::storeXML(exml::Element* _node) const {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
bool errorOccured = true; bool errorOccured = true;
for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) { for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) {
if (m_listConfig[iii].getConfig() == NULL) { if (m_listConfig[iii].getConfig() == nullptr) {
continue; continue;
} }
std::string value = getConfig(m_listConfig[iii].getConfig()); std::string value = getConfig(m_listConfig[iii].getConfig());
if (NULL != m_listConfig[iii].getDefault() ) { if (nullptr != m_listConfig[iii].getDefault() ) {
if (value == m_listConfig[iii].getDefault() ) { if (value == m_listConfig[iii].getDefault() ) {
// nothing to add on the XML : // nothing to add on the XML :
continue; continue;
@ -367,7 +424,7 @@ bool ewol::Object::onGetConfig(const char* _config, std::string& _result) const
bool ewol::Object::setConfig(const std::string& _config, const std::string& _value) { bool ewol::Object::setConfig(const std::string& _config, const std::string& _value) {
for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) { for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) {
if (NULL != m_listConfig[iii].getConfig()) { if (nullptr != m_listConfig[iii].getConfig()) {
if (_config == m_listConfig[iii].getConfig() ) { if (_config == m_listConfig[iii].getConfig() ) {
// call config with standard parameter // call config with standard parameter
return setConfig(ewol::object::Config(m_listConfig[iii].getConfig(), _value)); return setConfig(ewol::object::Config(m_listConfig[iii].getConfig(), _value));
@ -380,7 +437,7 @@ bool ewol::Object::setConfig(const std::string& _config, const std::string& _val
std::string ewol::Object::getConfig(const char* _config) const { std::string ewol::Object::getConfig(const char* _config) const {
std::string res=""; std::string res="";
if (NULL != _config) { if (nullptr != _config) {
onGetConfig(_config, res); onGetConfig(_config, res);
} }
return res; return res;
@ -388,7 +445,7 @@ std::string ewol::Object::getConfig(const char* _config) const {
std::string ewol::Object::getConfig(const std::string& _config) const { std::string ewol::Object::getConfig(const std::string& _config) const {
for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) { for(size_t iii=0 ; iii<m_listConfig.size() ; iii++) {
if (NULL != m_listConfig[iii].getConfig()) { if (nullptr != m_listConfig[iii].getConfig()) {
if (_config == m_listConfig[iii].getConfig() ) { if (_config == m_listConfig[iii].getConfig() ) {
// call config with standard parameter // call config with standard parameter
return getConfig(m_listConfig[iii].getConfig()); return getConfig(m_listConfig[iii].getConfig());
@ -400,16 +457,16 @@ std::string ewol::Object::getConfig(const std::string& _config) const {
} }
bool ewol::Object::setConfigNamed(const std::string& _objectName, const ewol::object::Config& _conf) { bool ewol::Object::setConfigNamed(const std::string& _objectName, const ewol::object::Config& _conf) {
ewol::Object* object = getObjectManager().get(_objectName); ewol::object::Shared<ewol::Object> object = getObjectManager().get(_objectName);
if (object == NULL) { if (object == nullptr) {
return false; return false;
} }
return object->setConfig(_conf); return object->setConfig(_conf);
} }
bool ewol::Object::setConfigNamed(const std::string& _objectName, const std::string& _config, const std::string& _value) { bool ewol::Object::setConfigNamed(const std::string& _objectName, const std::string& _config, const std::string& _value) {
ewol::Object* object = getObjectManager().get(_objectName); ewol::object::Shared<ewol::Object> object = getObjectManager().get(_objectName);
if (object == NULL) { if (object == nullptr) {
return false; return false;
} }
return object->setConfig(_config, _value); return object->setConfig(_config, _value);

View File

@ -13,7 +13,10 @@
#include <etk/types.h> #include <etk/types.h>
#include <vector> #include <vector>
#include <exml/exml.h> #include <exml/exml.h>
#include <vector> #include <mutex>
#include <ewol/object/Shared.h>
#include <ewol/object/Owner.h>
namespace ewol { namespace ewol {
// some class need to define element befor other ... // some class need to define element befor other ...
class Object; class Object;
@ -37,7 +40,7 @@ namespace ewol {
class EventExtGen { class EventExtGen {
public: public:
const char* localEventId; //!< local event Id generation const char* localEventId; //!< local event Id generation
ewol::Object* destObject; //!< destination widget that might be call ewol::object::Shared<ewol::Object> destObject; //!< destination widget that might be call
const char* destEventId; //!< generated event ID on the distant widget 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) std::string overloadData; //!< sometimes the user prefer to receive some specific data on an event (instead of the one sed by the widget)
}; };
@ -47,92 +50,31 @@ namespace ewol {
* this class mermit at every Object to communicate between them. * this class mermit at every Object to communicate between them.
*/ */
class Object { class Object {
public: template<typename T> friend class ewol::object::Shared;
template<typename T, typename = typename std::enable_if<std::is_convertible<T*, Object*>::value>::type> template<typename T> friend class ewol::object::Owner;
class Shared {
private: private:
T* m_pointer; //! @not-in-doc
public: std::mutex m_lockRefCount;
Shared() : //! @not-in-doc
m_pointer(nullptr) {
// nothing to do ...
}
Shared(T* _pointer) :
m_pointer(_pointer) {
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
}
~Shared() {
reset();
}
// copy constructor
Shared(const Shared& _obj) :
m_pointer(nullptr) {
m_pointer = _obj.get();
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
}
// Move Constructor
Shared(Shared&& _obj) :
m_pointer(nullptr) {
// transfert pointer
m_pointer = _obj.m_pointer;
_obj.m_pointer = nullptr;
}
Shared& operator=(const Shared<T>& _obj) noexcept {
if(this == &_obj) {
return *this;
}
reset();
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
}
return *this;
}
void reset() {
if (m_pointer == nullptr) {
return;
}
if (m_pointer->m_objRefCount <= 0) {
TK_ERROR("Object is already removed");
} else if (m_pointer->m_objRefCount == 1) {
TK_ERROR("Remove object (in shared)");
delete m_pointer;
} else {
m_pointer->objRefCountDecrement();
}
m_pointer = nullptr;
}
T* get() noexcept {
return m_pointer;
}
T* get() const noexcept {
return m_pointer;
}
T& operator*() const noexcept {
return *m_pointer;
}
T* operator->() const noexcept {
return m_pointer;
}
};
template<typename T> Shared<T> makeShared(T* _pointer) {
return Shared<T>(_pointer);
}
private:
// TODO : Lock Refcounting ...
int32_t m_objRefCount; int32_t m_objRefCount;
public: public:
//! @not-in-doc
void objRefCountIncrement(); void objRefCountIncrement();
//! @not-in-doc
void objRefCountDecrement(); void objRefCountDecrement();
int32_t getRefCount() {
return m_objRefCount;
}
//! @not-in-doc
static void operator delete(void* _ptr, std::size_t _sz); static void operator delete(void* _ptr, std::size_t _sz);
//! @not-in-doc
static void operator delete[](void* _ptr, std::size_t _sz); static void operator delete[](void* _ptr, std::size_t _sz);
#ifdef DEBUG
public:
int32_t m_ownerCount;
void incOwnerCount();
void decOwnerCount();
#endif
private: private:
static size_t m_valUID; //!< stic used for the unique ID definition static size_t m_valUID; //!< stic used for the unique ID definition
public: public:
@ -152,6 +94,8 @@ namespace ewol {
* @brief Destructor * @brief Destructor
*/ */
virtual ~Object(); virtual ~Object();
private:
bool m_isDestroyed;
protected: protected:
/** /**
* @brief Auto-destroy the object * @brief Auto-destroy the object
@ -162,6 +106,17 @@ namespace ewol {
* @brief Asynchronous removing the object * @brief Asynchronous removing the object
*/ */
void removeObject(); void removeObject();
/**
* @brief Respown a removed object
*/
void respownObject();
/**
* @brief Get if the element is destroyed or not
* @return true The element in destroyed
*/
bool isDestroyed() {
return m_isDestroyed;
}
private: private:
std::vector<const char*> m_listType; std::vector<const char*> m_listType;
public: public:
@ -208,7 +163,7 @@ namespace ewol {
return m_uniqueId; return m_uniqueId;
}; };
private: private:
std::vector<object::EventExtGen*> m_externEvent; //!< Generic list of event generation for output link std::vector<object::EventExtGen> m_externEvent; //!< Generic list of event generation for output link
std::vector<const char*> m_availlableEventId; //!< List of all event availlable for this widget std::vector<const char*> m_availlableEventId; //!< List of all event availlable for this widget
protected: protected:
/** /**
@ -241,23 +196,22 @@ namespace ewol {
* @param[in] _eventIdgenerated event generated when call the distant Object.onReceiveMessage(...) * @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 ... * @param[in] _overloadData When the user prever to receive a data specificly for this event ...
*/ */
void registerOnEvent(ewol::Object * _destinationObject, void registerOnEvent(const ewol::object::Shared<ewol::Object>& _destinationObject,
const char * _eventId, const char * _eventId,
const char * _eventIdgenerated = NULL, const char * _eventIdgenerated = nullptr,
const std::string& _overloadData = ""); const std::string& _overloadData = "");
/** /**
* @brief Un-Register an Object over an other. * @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] _destinationObject pointer on the object that might be call when an event is generated
* @param[in] _eventId Event generate inside the object (NULL to remove all event on this object) * @param[in] _eventId Event generate inside the object (nullptr to remove all event on this object)
*/ */
void unRegisterOnEvent(ewol::Object * _destinationObject, void unRegisterOnEvent(const ewol::object::Shared<ewol::Object>& _destinationObject,
const char * _eventId = NULL); const char * _eventId = nullptr);
/** /**
* @brief Inform object that an other object is removed ... * @brief Inform object that an other object is removed ...
* @param[in] _removObject Pointer on the Object remeved == > the user must remove all reference on this Object
* @note : Sub classes must call this class * @note : Sub classes must call this class
*/ */
virtual void onObjectRemove(ewol::Object * _removeObject); virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
/** /**
* @brief Receive a message from an other Object with a specific eventId and data * @brief Receive a message from an other Object with a specific eventId and data
* @param[in] _msg Message handle * @param[in] _msg Message handle
@ -277,10 +231,10 @@ namespace ewol {
* @param[in] _default Default value of this parameter. * @param[in] _default Default value of this parameter.
*/ */
void registerConfig(const char* _config, void registerConfig(const char* _config,
const char* _type = NULL, const char* _type = nullptr,
const char* _control = NULL, const char* _control = nullptr,
const char* _description = NULL, const char* _description = nullptr,
const char* _default = NULL); const char* _default = nullptr);
/** /**
* @brief Configuration requested to the curent Object * @brief Configuration requested to the curent Object
* @param[in] _conf Configuration handle. * @param[in] _conf Configuration handle.
@ -388,91 +342,6 @@ namespace ewol {
return m_isResource; return m_isResource;
} }
}; };
// section to compare shared pointer of an object with an other
//! @not in doc
template<typename T, typename T2>
inline bool operator==(const Object::Shared<T>& _obj, const Object::Shared<T2>& _obj2) noexcept {
return _obj.get() == _obj2.get();
}
//! @not in doc
template<typename T2>
inline bool operator==(const Object::Shared<T2>& _obj, std::nullptr_t) noexcept {
return _obj.get() == NULL;
}
//! @not in doc
template<typename T2>
inline bool operator==(std::nullptr_t, const Object::Shared<T2>& _obj) noexcept {
return _obj.get() == NULL;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const Object::Shared<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() == _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const T* _obj, const Object::Shared<T2>& _obj2) noexcept {
return _obj == _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator!=(const Object::Shared<T>& _obj, const Object::Shared<T2>& _obj2) noexcept {
return _obj.get() != _obj2.get();
}
//! @not in doc
template<typename T>
inline bool operator!=(const Object::Shared<T>& _obj, std::nullptr_t) noexcept {
return _obj.get() != NULL;
}
//! @not in doc
template<typename T>
inline bool operator!=(std::nullptr_t, const Object::Shared<T>& _obj) noexcept {
return _obj.get() != NULL;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const Object::Shared<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() != _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const T* _obj, const Object::Shared<T2>& _obj2) noexcept {
return _obj != _obj2.get();
}
//! @not in doc
template<typename T>
inline void swap(Object::Shared<T>& _obj, Object::Shared<T>& _obj2) noexcept {
_obj2.swap(_obj);
}
//! @not in doc
template<typename T2, typename T>
inline Object::Shared<T2> static_pointer_cast(const Object::Shared<T>& _obj) noexcept {
return Object::Shared<T2>(_obj, static_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline Object::Shared<T2> const_pointer_cast(const Object::Shared<T>& _obj) noexcept {
return Object::Shared<T2>(_obj, const_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline Object::Shared<T2> dynamic_pointer_cast(const Object::Shared<T>& _obj) noexcept {
if (T2* obj = dynamic_cast<T2*>(_obj.get())) {
return Object::Shared<T2>(_obj, obj);
}
return Object::Shared<T2>();
}
}; };
#endif #endif

262
sources/ewol/object/Owner.h Normal file
View File

@ -0,0 +1,262 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOL_OBJECT_OWNER_H__
#define __EWOL_OBJECT_OWNER_H__
#include <ewol/debug.h>
namespace ewol {
namespace object {
template<typename T>
class Owner {
private:
T* m_pointer;
public:
Owner() :
m_pointer(nullptr) {
// nothing to do ...
}
Owner(T* _pointer) :
m_pointer(_pointer) {
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
}
~Owner() {
reset();
}
// copy constructor
Owner(const Owner& _obj) :
m_pointer(nullptr) {
EWOL_CRITICAL("You can not user copy operator for Owner reference...");
}
// Move Constructor
Owner(Owner&& _obj) :
m_pointer(nullptr) {
// transfert pointer
m_pointer = _obj.m_pointer;
_obj.m_pointer = nullptr;
}
// shared to private constructor
template<typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
Owner(const Shared<T2>& _obj) :
m_pointer(nullptr) {
m_pointer = _obj.get();
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
template<typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
Owner& operator=(const Owner<T2>& _obj) noexcept {
if(this == &_obj) {
return *this;
}
reset();
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
return *this;
}
template<typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
Owner& operator=(const Shared<T2>& _obj) noexcept {
reset();
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
return *this;
}
void reset() {
if (m_pointer == nullptr) {
return;
}
//etk::log::displayBacktrace();
// To prevent cyclisme
T* tmp = m_pointer;
m_pointer = nullptr;
tmp->removeObject();
if (tmp->m_objRefCount <= 0) {
EWOL_WARNING("Object will be already removed");
} else if (tmp->m_objRefCount == 1) {
EWOL_VERBOSE("Remove object (in Owner)");
delete tmp;
} else {
tmp->objRefCountDecrement();
#ifdef DEBUG
tmp->decOwnerCount();
#endif
}
}
void resetShared() {
if (m_pointer == nullptr) {
return;
}
// To prevent cyclisme
T* tmp = m_pointer;
m_pointer = nullptr;
if (tmp->m_objRefCount <= 0) {
EWOL_WARNING("Object will be already removed");
} else if (tmp->m_objRefCount == 1) {
EWOL_VERBOSE("Remove object (in Owner)");
delete tmp;
} else {
tmp->objRefCountDecrement();
#ifdef DEBUG
tmp->decOwnerCount();
#endif
}
}
T* get() noexcept {
return m_pointer;
}
T* get() const noexcept {
return m_pointer;
}
T& operator*() const noexcept {
return *m_pointer;
}
T* operator->() const noexcept {
return m_pointer;
}
operator ewol::object::Shared<T>() const noexcept {
return m_pointer;
}
};
};
// section to compare Owner pointer of an object with an other
//! @not in doc
template<typename T, typename T2>
inline bool operator==(const object::Owner<T>& _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj.get() == _obj2.get();
}
//! @not in doc
template<typename T2>
inline bool operator==(const object::Owner<T2>& _obj, std::nullptr_t) noexcept {
return _obj.get() == nullptr;
}
//! @not in doc
template<typename T2>
inline bool operator==(std::nullptr_t, const object::Owner<T2>& _obj) noexcept {
return _obj.get() == nullptr;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const object::Owner<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() == _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const T* _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj == _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator==(const object::Owner<T>& _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj.get() == _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator==(const object::Shared<T>& _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj.get() == _obj2.get();
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const object::Owner<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() != _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const T* _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj != _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator!=(const object::Owner<T>& _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj.get() != _obj2.get();
}
//! @not in doc
template<typename T>
inline bool operator!=(const object::Owner<T>& _obj, std::nullptr_t) noexcept {
return _obj.get() != nullptr;
}
//! @not in doc
template<typename T>
inline bool operator!=(std::nullptr_t, const object::Owner<T>& _obj) noexcept {
return _obj.get() != nullptr;
}
//! @not in doc
template<typename T, typename T2>
inline bool operator!=(const object::Owner<T>& _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj.get() != _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator!=(const object::Shared<T>& _obj, const object::Owner<T2>& _obj2) noexcept {
return _obj.get() != _obj2.get();
}
/*
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
object::Shared<T> operator=(const object::Owner<T2>& _obj) {
return _obj.get();
}
*/
//! @not in doc
template<typename T>
inline void swap(object::Owner<T>& _obj, object::Owner<T>& _obj2) noexcept {
_obj2.swap(_obj);
}
//! @not in doc
template<typename T2, typename T>
inline object::Owner<T2> static_pointer_cast(const object::Owner<T>& _obj) noexcept {
return object::Owner<T2>(_obj, static_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline object::Owner<T2> const_pointer_cast(const object::Owner<T>& _obj) noexcept {
return object::Owner<T2>(_obj, const_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline object::Owner<T2> dynamic_pointer_cast(const object::Owner<T>& _obj) noexcept {
if (T2* obj = dynamic_cast<T2*>(_obj.get())) {
return object::Owner<T2>(_obj, obj);
}
return object::Owner<T2>();
}
};
#endif

View File

@ -0,0 +1,23 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <ewol/object/RemoveEvent.h>
#include <ewol/context/Context.h>
ewol::object::RemoveEvent::RemoveEvent() {
Context& tmp = ewol::getContext();
ewol::object::Manager& manager = tmp.getEObjectManager();
manager.add(this);
}
ewol::object::RemoveEvent::~RemoveEvent() {
Context& tmp = ewol::getContext();
ewol::object::Manager& manager = tmp.getEObjectManager();
manager.rm(this);
}

View File

@ -0,0 +1,27 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOL_OBJECT_REMOVE_EVENT_H__
#define __EWOL_OBJECT_REMOVE_EVENT_H__
#include <etk/types.h>
#include <ewol/object/Object.h>
namespace ewol {
namespace object {
class RemoveEvent {
public:
virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) = 0;
public:
RemoveEvent();
virtual ~RemoveEvent();
};
}
};
#endif

View File

@ -0,0 +1,190 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOL_OBJECT_SHARED_H__
#define __EWOL_OBJECT_SHARED_H__
#include <ewol/debug.h>
namespace ewol {
namespace object {
template<typename T>
class Shared {
private:
T* m_pointer;
public:
Shared() :
m_pointer(nullptr) {
// nothing to do ...
}
Shared(T* _pointer) :
m_pointer(_pointer) {
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
}
~Shared() {
reset();
}
// copy constructor
Shared(const Shared& _obj) :
m_pointer(nullptr) {
m_pointer = _obj.get();
if (m_pointer == nullptr) {
return;
}
m_pointer->objRefCountIncrement();
}
// Move Constructor
Shared(Shared&& _obj) :
m_pointer(nullptr) {
// transfert pointer
m_pointer = _obj.m_pointer;
_obj.m_pointer = nullptr;
}
Shared& operator=(const Shared<T>& _obj) noexcept {
if(this == &_obj) {
return *this;
}
reset();
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
}
return *this;
}
void reset() {
if (m_pointer == nullptr) {
return;
}
// To prevent cyclisme
T* tmp = m_pointer;
m_pointer = nullptr;
if (tmp->m_objRefCount <= 0) {
EWOL_WARNING("Object is already removed");
} else if (tmp->m_objRefCount == 1) {
EWOL_VERBOSE("Remove object (in shared)");
delete tmp;
} else {
tmp->objRefCountDecrement();
}
}
T* get() const noexcept {
return m_pointer;
}
T& operator*() const noexcept {
return *m_pointer;
}
T* operator->() const noexcept {
return m_pointer;
}
template<typename T2> operator ewol::object::Shared<T2>() const noexcept {
return m_pointer;
}
};
// after calling this function, you might never call a delete on this pointer. (if you want to be able to use a delete, simply Shared<>(pointer)
template<typename T> Shared<T> makeShared(T* _pointer) {
if (_pointer == nullptr) {
return Shared<T>();
}
Shared<T> tmp(_pointer);
// remove one element to permit to remove at the last instance
_pointer->objRefCountDecrement();
return tmp;
}
};
// section to compare shared pointer of an object with an other
//! @not in doc
template<typename T, typename T2>
inline bool operator==(const object::Shared<T>& _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj.get() == _obj2.get();
}
//! @not in doc
template<typename T2>
inline bool operator==(const object::Shared<T2>& _obj, std::nullptr_t) noexcept {
return _obj.get() == nullptr;
}
//! @not in doc
template<typename T2>
inline bool operator==(std::nullptr_t, const object::Shared<T2>& _obj) noexcept {
return _obj.get() == nullptr;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const object::Shared<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() == _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator==(const T* _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj == _obj2.get();
}
//! @not in doc
template<typename T, typename T2>
inline bool operator!=(const object::Shared<T>& _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj.get() != _obj2.get();
}
//! @not in doc
template<typename T>
inline bool operator!=(const object::Shared<T>& _obj, std::nullptr_t) noexcept {
return _obj.get() != nullptr;
}
//! @not in doc
template<typename T>
inline bool operator!=(std::nullptr_t, const object::Shared<T>& _obj) noexcept {
return _obj.get() != nullptr;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const object::Shared<T>& _obj, const T2* _obj2) noexcept {
return _obj.get() != _obj2;
}
//! @not in doc
template<typename T, typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
inline bool operator!=(const T* _obj, const object::Shared<T2>& _obj2) noexcept {
return _obj != _obj2.get();
}
//! @not in doc
template<typename T>
inline void swap(object::Shared<T>& _obj, object::Shared<T>& _obj2) noexcept {
_obj2.swap(_obj);
}
//! @not in doc
template<typename T2, typename T>
inline object::Shared<T2> static_pointer_cast(const object::Shared<T>& _obj) noexcept {
return object::Shared<T2>(_obj, static_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline object::Shared<T2> const_pointer_cast(const object::Shared<T>& _obj) noexcept {
return object::Shared<T2>(_obj, const_cast<T2*>(_obj.get()));
}
//! @not in doc
template<typename T2, typename T>
inline object::Shared<T2> dynamic_pointer_cast(const object::Shared<T>& _obj) noexcept {
if (T2* obj = dynamic_cast<T2*>(_obj.get())) {
return ewol::object::Shared<T2>(obj);
}
return ewol::object::Shared<T2>();
}
};
#endif

View File

@ -44,13 +44,13 @@ void ewol::resource::ColorFile::reload() {
return; return;
} }
ejson::Array* baseArray = doc.getArray("color"); ejson::Array* baseArray = doc.getArray("color");
if (baseArray == NULL) { if (baseArray == nullptr) {
EWOL_ERROR("Can not get basic array : 'color'"); EWOL_ERROR("Can not get basic array : 'color'");
return; return;
} }
for (int32_t iii = 0; iii < baseArray->size(); ++iii) { for (size_t iii = 0; iii < baseArray->size(); ++iii) {
ejson::Object* tmpObj = baseArray->getObject(iii); ejson::Object* tmpObj = baseArray->getObject(iii);
if (tmpObj == NULL) { if (tmpObj == nullptr) {
EWOL_DEBUG(" can not get object in 'color' id=" << iii); EWOL_DEBUG(" can not get object in 'color' id=" << iii);
continue; continue;
} }
@ -75,38 +75,27 @@ int32_t ewol::resource::ColorFile::request(const std::string& _paramName) {
} }
ewol::resource::ColorFile* ewol::resource::ColorFile::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::ColorFile> ewol::resource::ColorFile::keep(const std::string& _filename) {
EWOL_INFO("KEEP : ColorFile : file : \"" << _filename << "\""); EWOL_INFO("KEEP : ColorFile : file : \"" << _filename << "\"");
ewol::resource::ColorFile* object = NULL; ewol::object::Shared<ewol::resource::ColorFile> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::ColorFile*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::ColorFile>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// this element create a new one every time .... // this element create a new one every time ....
object = new ewol::resource::ColorFile(_filename); object = ewol::object::makeShared(new ewol::resource::ColorFile(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::ColorFile::release(ewol::resource::ColorFile*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -30,6 +30,7 @@ namespace ewol {
* @param[in] _filename Name of the file needed * @param[in] _filename Name of the file needed
*/ */
ColorFile(const std::string& _filename); ColorFile(const std::string& _filename);
public:
/** /**
* @brief Simple Destructor of this class (nothing specific ...) * @brief Simple Destructor of this class (nothing specific ...)
*/ */
@ -73,14 +74,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file. * @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::ColorFile* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::ColorFile> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::ColorFile*& _object);
}; };
}; };
}; };

View File

@ -15,12 +15,12 @@
ewol::resource::Colored3DObject::Colored3DObject() : ewol::resource::Colored3DObject::Colored3DObject() :
m_GLprogram(NULL) { m_GLprogram(nullptr) {
addObjectType("ewol::Colored3DObject"); addObjectType("ewol::Colored3DObject");
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
m_GLprogram = ewol::resource::Program::keep("DATA:simple3D.prog"); m_GLprogram = ewol::resource::Program::keep("DATA:simple3D.prog");
if (NULL != m_GLprogram ) { if (nullptr != m_GLprogram ) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getUniform("EW_color"); m_GLColor = m_GLprogram->getUniform("EW_color");
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
@ -28,8 +28,7 @@ ewol::resource::Colored3DObject::Colored3DObject() :
} }
ewol::resource::Colored3DObject::~Colored3DObject() { ewol::resource::Colored3DObject::~Colored3DObject() {
// remove dynamics dependencies :
ewol::resource::Program::release(m_GLprogram);
} }
@ -40,7 +39,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
if (_vertices.size() <= 0) { if (_vertices.size() <= 0) {
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -83,7 +82,7 @@ void ewol::resource::Colored3DObject::draw(std::vector<vec3>& _vertices,
if (_vertices.size() <= 0) { if (_vertices.size() <= 0) {
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -123,7 +122,7 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
if (_vertices.size() <= 0) { if (_vertices.size() <= 0) {
return; return;
} }
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
} }
@ -155,23 +154,15 @@ void ewol::resource::Colored3DObject::drawLine(std::vector<vec3>& _vertices,
} }
} }
ewol::resource::Colored3DObject* ewol::resource::Colored3DObject::keep() { ewol::object::Shared<ewol::resource::Colored3DObject> ewol::resource::Colored3DObject::keep() {
EWOL_VERBOSE("KEEP : direct Colored3DObject"); EWOL_VERBOSE("KEEP : direct Colored3DObject");
// need to crate a new one ... // need to crate a new one ...
ewol::resource::Colored3DObject* object = new ewol::resource::Colored3DObject(); ewol::object::Shared<ewol::resource::Colored3DObject> object = ewol::object::makeShared(new ewol::resource::Colored3DObject());
if (NULL == object) { if (object == nullptr) {
EWOL_ERROR("allocation error of a resource : ???Colored3DObject??? "); EWOL_ERROR("allocation error of a resource : ???Colored3DObject??? ");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::Colored3DObject::release(ewol::resource::Colored3DObject*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -19,12 +19,13 @@ namespace ewol {
namespace resource { namespace resource {
class Colored3DObject : public ewol::Resource { class Colored3DObject : public ewol::Resource {
protected: protected:
ewol::resource::Program* m_GLprogram; ewol::object::Shared<ewol::resource::Program> m_GLprogram;
int32_t m_GLPosition; int32_t m_GLPosition;
int32_t m_GLMatrix; int32_t m_GLMatrix;
int32_t m_GLColor; int32_t m_GLColor;
protected: protected:
Colored3DObject(); Colored3DObject();
public:
virtual ~Colored3DObject(); virtual ~Colored3DObject();
public: public:
virtual void draw(std::vector<vec3>& _vertices, virtual void draw(std::vector<vec3>& _vertices,
@ -45,14 +46,9 @@ namespace ewol {
/** /**
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::Colored3DObject* keep(); static ewol::object::Shared<ewol::resource::Colored3DObject> keep();
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::Colored3DObject*& _object);
}; };
}; };
}; };

View File

@ -29,10 +29,10 @@ ewol::resource::ConfigFile::ConfigFile(const std::string& _filename) :
ewol::resource::ConfigFile::~ConfigFile() { ewol::resource::ConfigFile::~ConfigFile() {
// remove all element // remove all element
for (size_t iii=0; iii<m_list.size(); iii++){ for (int32_t iii=0; iii<m_list.size(); iii++){
if (NULL != m_list[iii]) { if (nullptr != m_list[iii]) {
delete(m_list[iii]); delete(m_list[iii]);
m_list[iii] = NULL; m_list[iii] = nullptr;
} }
} }
m_list.clear(); m_list.clear();
@ -40,9 +40,9 @@ ewol::resource::ConfigFile::~ConfigFile() {
void ewol::resource::ConfigFile::reload() { void ewol::resource::ConfigFile::reload() {
// reset all parameters // reset all parameters
for (size_t iii=0; iii<m_list.size(); iii++){ for (int32_t iii=0; iii<m_list.size(); iii++){
if (NULL != m_list[iii]) { if (nullptr != m_list[iii]) {
m_list[iii] = NULL; m_list[iii] = nullptr;
} }
} }
m_doc.load(m_name); m_doc.load(m_name);
@ -58,7 +58,7 @@ void ewol::resource::ConfigFile::reload() {
int32_t ewol::resource::ConfigFile::request(const std::string& _paramName) { int32_t ewol::resource::ConfigFile::request(const std::string& _paramName) {
// check if the parameters existed : // check if the parameters existed :
if (m_list.exist(_paramName) == false) { if (m_list.exist(_paramName) == false) {
m_list.add(_paramName, NULL); m_list.add(_paramName, nullptr);
} }
if (m_doc.exist(_paramName) == true) { if (m_doc.exist(_paramName) == true) {
m_list[_paramName] = m_doc[_paramName]; m_list[_paramName] = m_doc[_paramName];
@ -69,11 +69,11 @@ int32_t ewol::resource::ConfigFile::request(const std::string& _paramName) {
double ewol::resource::ConfigFile::getNumber(int32_t _id) { double ewol::resource::ConfigFile::getNumber(int32_t _id) {
if ( _id < 0 if ( _id < 0
|| m_list[_id] == NULL) { || m_list[_id] == nullptr) {
return 0.0; return 0.0;
} }
ejson::Number* tmp = m_list[_id]->toNumber(); ejson::Number* tmp = m_list[_id]->toNumber();
if (tmp == NULL) { if (tmp == nullptr) {
return 0.0; return 0.0;
} }
return tmp->get(); return tmp->get();
@ -82,11 +82,11 @@ double ewol::resource::ConfigFile::getNumber(int32_t _id) {
const std::string& ewol::resource::ConfigFile::getString(int32_t _id) { const std::string& ewol::resource::ConfigFile::getString(int32_t _id) {
static const std::string& errorString(""); static const std::string& errorString("");
if ( _id < 0 if ( _id < 0
|| m_list[_id] == NULL) { || m_list[_id] == nullptr) {
return errorString; return errorString;
} }
ejson::String* tmp = m_list[_id]->toString(); ejson::String* tmp = m_list[_id]->toString();
if (tmp == NULL) { if (tmp == nullptr) {
return errorString; return errorString;
} }
return tmp->get(); return tmp->get();
@ -94,48 +94,39 @@ const std::string& ewol::resource::ConfigFile::getString(int32_t _id) {
bool ewol::resource::ConfigFile::getBoolean(int32_t _id) { bool ewol::resource::ConfigFile::getBoolean(int32_t _id) {
if ( _id < 0 if ( _id < 0
|| m_list[_id] == NULL) { || m_list[_id] == nullptr) {
return false; return false;
} }
ejson::Boolean* tmp = m_list[_id]->toBoolean(); ejson::Boolean* tmp = m_list[_id]->toBoolean();
if (tmp == NULL) { if (tmp == nullptr) {
return false; return false;
} }
return tmp->get(); return tmp->get();
} }
ewol::resource::ConfigFile* ewol::resource::ConfigFile::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::ConfigFile> ewol::resource::ConfigFile::keep(const std::string& _filename) {
EWOL_INFO("KEEP : SimpleConfig : file : \"" << _filename << "\""); EWOL_INFO("KEEP : SimpleConfig : file : \"" << _filename << "\"");
ewol::resource::ConfigFile* object = NULL; ewol::object::Shared<ewol::resource::ConfigFile> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::ConfigFile*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::ConfigFile>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// this element create a new one every time .... // this element create a new one every time ....
object = new ewol::resource::ConfigFile(_filename); object = ewol::object::makeShared(new ewol::resource::ConfigFile(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : '" << _filename << "'"); EWOL_ERROR("allocation error of a resource : '" << _filename << "'");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::ConfigFile::release(ewol::resource::ConfigFile*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -23,6 +23,7 @@ namespace ewol {
etk::Hash<ejson::Value*> m_list; etk::Hash<ejson::Value*> m_list;
protected: protected:
ConfigFile(const std::string& _filename); ConfigFile(const std::string& _filename);
public:
virtual ~ConfigFile(); virtual ~ConfigFile();
public: public:
void reload(); void reload();
@ -37,14 +38,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file. * @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::ConfigFile* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::ConfigFile> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::ConfigFile*& _object);
}; };
}; };
}; };

View File

@ -29,7 +29,7 @@ ewol::resource::DistanceFieldFont::DistanceFieldFont(const std::string& _fontNam
m_borderSize(10), m_borderSize(10),
m_textureBorderSize(0,0) { m_textureBorderSize(0,0) {
addObjectType("ewol::resource::DistanceFieldFont"); addObjectType("ewol::resource::DistanceFieldFont");
m_font = NULL; m_font = nullptr;
m_lastGlyphPos.setValue(1,1); m_lastGlyphPos.setValue(1,1);
m_lastRawHeigh = 0; m_lastRawHeigh = 0;
m_sizeRatio = 1.0f; m_sizeRatio = 1.0f;
@ -84,18 +84,18 @@ ewol::resource::DistanceFieldFont::DistanceFieldFont(const std::string& _fontNam
if (m_fileName.size() == 0) { if (m_fileName.size() == 0) {
EWOL_ERROR("can not load FONT name : '" << m_fileName << "'" ); EWOL_ERROR("can not load FONT name : '" << m_fileName << "'" );
m_font = NULL; m_font = nullptr;
return; return;
} }
EWOL_INFO("Load FONT name : '" << m_fileName << "'"); EWOL_INFO("Load FONT name : '" << m_fileName << "'");
m_font = ewol::resource::FontFreeType::keep(m_fileName); m_font = ewol::resource::FontFreeType::keep(m_fileName);
if (m_font == NULL) { if (m_font == nullptr) {
EWOL_ERROR("Pb Loading FONT name : '" << m_fileName << "'" ); EWOL_ERROR("Pb Loading FONT name : '" << m_fileName << "'" );
} }
// set the bassic charset: // set the bassic charset:
m_listElement.clear(); m_listElement.clear();
if (m_font == NULL) { if (m_font == nullptr) {
return; return;
} }
if (importFromFile() == true) { if (importFromFile() == true) {
@ -121,7 +121,7 @@ ewol::resource::DistanceFieldFont::DistanceFieldFont(const std::string& _fontNam
} }
ewol::resource::DistanceFieldFont::~DistanceFieldFont() { ewol::resource::DistanceFieldFont::~DistanceFieldFont() {
ewol::resource::FontFreeType::release(m_font);
} }
@ -211,7 +211,7 @@ void ewol::resource::DistanceFieldFont::generateDistanceField(const egami::Image
bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) { bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) {
bool hasChange = false; bool hasChange = false;
if (m_font == NULL) { if (m_font == nullptr) {
return false; return false;
} }
// add the curent "char" // add the curent "char"
@ -325,7 +325,7 @@ ewol::GlyphProperty* ewol::resource::DistanceFieldFont::getGlyphPointer(const ch
if (m_listElement.size() > 0) { if (m_listElement.size() > 0) {
return &((m_listElement)[0]); return &((m_listElement)[0]);
} }
return NULL; return nullptr;
} }
//EWOL_ERROR(" index=" << index); //EWOL_ERROR(" index=" << index);
//EWOL_ERROR(" m_UVal=" << m_listElement[_displayMode][index].m_UVal); //EWOL_ERROR(" m_UVal=" << m_listElement[_displayMode][index].m_UVal);
@ -335,56 +335,43 @@ ewol::GlyphProperty* ewol::resource::DistanceFieldFont::getGlyphPointer(const ch
return &((m_listElement)[index]); return &((m_listElement)[index]);
} }
ewol::resource::DistanceFieldFont* ewol::resource::DistanceFieldFont::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::DistanceFieldFont> ewol::resource::DistanceFieldFont::keep(const std::string& _filename) {
EWOL_VERBOSE("KEEP : DistanceFieldFont : file : '" << _filename << "'"); EWOL_VERBOSE("KEEP : DistanceFieldFont : file : '" << _filename << "'");
ewol::resource::DistanceFieldFont* object = NULL; ewol::object::Shared<ewol::resource::DistanceFieldFont> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::DistanceFieldFont*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::DistanceFieldFont>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// need to crate a new one ... // need to crate a new one ...
EWOL_DEBUG("CREATE: DistanceFieldFont : file : '" << _filename << "'"); EWOL_DEBUG("CREATE: DistanceFieldFont : file : '" << _filename << "'");
object = new ewol::resource::DistanceFieldFont(_filename); object = ewol::object::makeShared(new ewol::resource::DistanceFieldFont(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::DistanceFieldFont::release(ewol::resource::DistanceFieldFont*& _object) {
if (NULL == _object) {
return;
}
std::string name = _object->getName();
int32_t count = _object->getCounter() - 1;
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
if (getManager().release(object2) == true) {
EWOL_DEBUG("REMOVE: DistanceFieldFont : file : '" << name << "' count=" << count);
//etk::displayBacktrace(false);
}
_object = NULL;
}
void ewol::resource::DistanceFieldFont::exportOnFile() { void ewol::resource::DistanceFieldFont::exportOnFile() {
EWOL_DEBUG("EXPORT: DistanceFieldFont : file : '" << m_fileName << ".json'"); EWOL_DEBUG("EXPORT: DistanceFieldFont : file : '" << m_fileName << ".json'");
ejson::Document doc; ejson::Document doc;
ejson::Array* tmpList = new ejson::Array(); ejson::Array* tmpList = new ejson::Array();
if (tmpList == NULL) { if (tmpList == nullptr) {
EWOL_ERROR("NULL pointer"); EWOL_ERROR("nullptr pointer");
return; return;
} }
for (size_t iii=0; iii<m_listElement.size(); ++iii) { for (size_t iii=0; iii<m_listElement.size(); ++iii) {
ejson::Object* tmpObj = new ejson::Object(); ejson::Object* tmpObj = new ejson::Object();
if (tmpObj == NULL) { if (tmpObj == nullptr) {
continue; continue;
} }
tmpObj->addString("m_UVal", std::to_string(m_listElement[iii].m_UVal)); tmpObj->addString("m_UVal", std::to_string(m_listElement[iii].m_UVal));
@ -427,14 +414,14 @@ bool ewol::resource::DistanceFieldFont::importFromFile() {
m_borderSize = doc.getNumberValue("m_borderSize", 2); m_borderSize = doc.getNumberValue("m_borderSize", 2);
m_textureBorderSize = doc.addString("m_textureBorderSize", "0,0"); m_textureBorderSize = doc.addString("m_textureBorderSize", "0,0");
ejson::Array* tmpList = doc.getArray("m_listElement"); ejson::Array* tmpList = doc.getArray("m_listElement");
if (tmpList == NULL) { if (tmpList == nullptr) {
EWOL_ERROR("NULL pointer array"); EWOL_ERROR("nullptr pointer array");
return false; return false;
} }
m_listElement.clear(); m_listElement.clear();
for (size_t iii=0; iii<tmpList->size(); ++iii) { for (size_t iii=0; iii<tmpList->size(); ++iii) {
ejson::Object* tmpObj = tmpList->getObject(iii); ejson::Object* tmpObj = tmpList->getObject(iii);
if (tmpObj == NULL) { if (tmpObj == nullptr) {
continue; continue;
} }
GlyphProperty prop; GlyphProperty prop;

View File

@ -23,7 +23,7 @@ namespace ewol {
// specific element to have the the know if the specify element is known... // specific element to have the the know if the specify element is known...
// == > otherwise I can just generate italic ... // == > otherwise I can just generate italic ...
// == > Bold is a little more complicated (maybe with the bordersize) // == > Bold is a little more complicated (maybe with the bordersize)
ewol::resource::FontBase* m_font; ewol::object::Shared<ewol::resource::FontBase> m_font;
public: public:
std::vector<GlyphProperty> m_listElement; std::vector<GlyphProperty> m_listElement;
private: private:
@ -32,7 +32,8 @@ namespace ewol {
int32_t m_lastRawHeigh; int32_t m_lastRawHeigh;
protected: protected:
DistanceFieldFont(const std::string& _fontName); DistanceFieldFont(const std::string& _fontName);
~DistanceFieldFont(); public:
virtual ~DistanceFieldFont();
public: public:
float getDisplayRatio(float _size); float getDisplayRatio(float _size);
/** /**
@ -60,7 +61,7 @@ namespace ewol {
/** /**
* @brief get the pointer on the coresponding glyph * @brief get the pointer on the coresponding glyph
* @param[in] _charcode The unicodeValue * @param[in] _charcode The unicodeValue
* @return The pointer on the glyph == > never NULL * @return The pointer on the glyph == > never nullptr
*/ */
ewol::GlyphProperty* getGlyphPointer(const char32_t& _charcode); ewol::GlyphProperty* getGlyphPointer(const char32_t& _charcode);
public: public:
@ -68,14 +69,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the texture font. * @param[in] _filename Name of the texture font.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::DistanceFieldFont* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::DistanceFieldFont> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::DistanceFieldFont*& _object);
private: private:
/** /**
* @brief add a glyph in a texture font. * @brief add a glyph in a texture font.

View File

@ -46,7 +46,7 @@ void ewol::resource::freeTypeUnInit() {
return; return;
} }
int32_t error = FT_Done_FreeType( library ); int32_t error = FT_Done_FreeType( library );
library = NULL; library = nullptr;
if(0 != error) { if(0 != error) {
EWOL_CRITICAL(" when Un-loading FreeType Librairy ..."); EWOL_CRITICAL(" when Un-loading FreeType Librairy ...");
} }
@ -56,7 +56,7 @@ ewol::resource::FontFreeType::FontFreeType(const std::string& _fontName) :
FontBase(_fontName) { FontBase(_fontName) {
addObjectType("ewol::FontFreeType"); addObjectType("ewol::FontFreeType");
m_init = false; m_init = false;
m_FileBuffer = NULL; m_FileBuffer = nullptr;
m_FileSize = 0; m_FileSize = 0;
etk::FSNode myfile(_fontName); etk::FSNode myfile(_fontName);
@ -75,7 +75,7 @@ ewol::resource::FontFreeType::FontFreeType(const std::string& _fontName) :
} }
// allocate data // allocate data
m_FileBuffer = new FT_Byte[m_FileSize]; m_FileBuffer = new FT_Byte[m_FileSize];
if (NULL == m_FileBuffer) { if (nullptr == m_FileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << _fontName); EWOL_ERROR("Error Memory allocation size=" << _fontName);
return; return;
} }
@ -99,9 +99,9 @@ ewol::resource::FontFreeType::FontFreeType(const std::string& _fontName) :
ewol::resource::FontFreeType::~FontFreeType() { ewol::resource::FontFreeType::~FontFreeType() {
// clean the tmp memory // clean the tmp memory
if (NULL != m_FileBuffer) { if (nullptr != m_FileBuffer) {
delete[] m_FileBuffer; delete[] m_FileBuffer;
m_FileBuffer = NULL; m_FileBuffer = nullptr;
} }
// must be deleted fftFace // must be deleted fftFace
FT_Done_Face( m_fftFace ); FT_Done_Face( m_fftFace );
@ -390,36 +390,26 @@ void ewol::resource::FontFreeType::display() {
//EWOL_INFO(" Current size = " << (int)m_fftFace->size); //EWOL_INFO(" Current size = " << (int)m_fftFace->size);
} }
ewol::resource::FontBase* ewol::resource::FontFreeType::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::FontBase> ewol::resource::FontFreeType::keep(const std::string& _filename) {
EWOL_VERBOSE("KEEP : Font : file : \"" << _filename << "\""); EWOL_VERBOSE("KEEP : Font : file : \"" << _filename << "\"");
ewol::resource::FontBase* object = NULL; ewol::object::Shared<ewol::resource::FontBase> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::FontBase*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::FontBase>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// need to crate a new one ... // need to crate a new one ...
object = new ewol::resource::FontFreeType(_filename); object = ewol::object::makeShared(new ewol::resource::FontFreeType(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::FontFreeType::release(ewol::resource::FontBase*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -30,7 +30,8 @@ namespace ewol {
void display(); void display();
protected: protected:
FontFreeType(const std::string& _fontName); FontFreeType(const std::string& _fontName);
~FontFreeType(); public:
virtual ~FontFreeType();
public: public:
bool getGlyphProperty(int32_t _fontSize, bool getGlyphProperty(int32_t _fontSize,
@ -58,14 +59,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the base font. * @param[in] _filename Name of the base font.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::FontBase* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::FontBase> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::FontBase*& _object);
}; };
void freeTypeInit(); void freeTypeInit();
void freeTypeUnInit(); void freeTypeUnInit();

View File

@ -62,13 +62,13 @@ static int32_t nextP2(int32_t _value) {
ewol::resource::TextureFile* ewol::resource::TextureFile::keep(const std::string& _filename, ivec2 _size) { ewol::object::Shared<ewol::resource::TextureFile> ewol::resource::TextureFile::keep(const std::string& _filename, ivec2 _size) {
EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size); EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size);
if (_filename == "") { if (_filename == "") {
ewol::resource::TextureFile* object = new ewol::resource::TextureFile(""); ewol::object::Shared<ewol::resource::TextureFile> object = ewol::object::makeShared(new ewol::resource::TextureFile(""));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??"); EWOL_ERROR("allocation error of a resource : ??TEX??");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
@ -101,36 +101,25 @@ ewol::resource::TextureFile* ewol::resource::TextureFile::keep(const std::string
} }
EWOL_VERBOSE("KEEP: TextureFile: '" << TmpFilename << "' new size=" << _size); EWOL_VERBOSE("KEEP: TextureFile: '" << TmpFilename << "' new size=" << _size);
ewol::resource::TextureFile* object = NULL; ewol::object::Shared<ewol::resource::TextureFile> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(TmpFilename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(TmpFilename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::TextureFile*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::TextureFile>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << TmpFilename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << TmpFilename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
EWOL_INFO("CREATE: TextureFile: '" << TmpFilename << "' size=" << _size); EWOL_INFO("CREATE: TextureFile: '" << TmpFilename << "' size=" << _size);
// need to crate a new one ... // need to crate a new one ...
object = new ewol::resource::TextureFile(TmpFilename, _filename, _size); object = ewol::object::makeShared(new ewol::resource::TextureFile(TmpFilename, _filename, _size));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::TextureFile::release(ewol::resource::TextureFile*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -23,6 +23,7 @@ namespace ewol {
private: private:
TextureFile(const std::string& _genName); TextureFile(const std::string& _genName);
TextureFile(std::string _genName, const std::string& _fileName, const ivec2& _size); TextureFile(std::string _genName, const std::string& _fileName, const ivec2& _size);
public:
virtual ~TextureFile() { }; virtual ~TextureFile() { };
public: public:
const vec2& getRealSize() { const vec2& getRealSize() {
@ -34,14 +35,9 @@ namespace ewol {
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the image file. * @param[in] _filename Name of the image file.
* @param[in] _requested size of the image (usefull when loading .svg to automatic rescale) * @param[in] _requested size of the image (usefull when loading .svg to automatic rescale)
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::TextureFile* keep(const std::string& _filename, ivec2 _size=ivec2(-1,-1)); static ewol::object::Shared<ewol::resource::TextureFile> keep(const std::string& _filename, ivec2 _size=ivec2(-1,-1));
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::TextureFile*& _object);
}; };
}; };
}; };

View File

@ -151,13 +151,13 @@ static int32_t nextP2(int32_t _value) {
ewol::resource::ImageDF* ewol::resource::ImageDF::keep(const std::string& _filename, ivec2 _size) { ewol::object::Shared<ewol::resource::ImageDF> ewol::resource::ImageDF::keep(const std::string& _filename, ivec2 _size) {
EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size); EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size);
if (_filename == "") { if (_filename == "") {
ewol::resource::ImageDF* object = new ewol::resource::ImageDF(""); ewol::object::Shared<ewol::resource::ImageDF> object = ewol::object::makeShared(new ewol::resource::ImageDF(""));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??"); EWOL_ERROR("allocation error of a resource : ??TEX??");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
@ -190,36 +190,26 @@ ewol::resource::ImageDF* ewol::resource::ImageDF::keep(const std::string& _filen
} }
EWOL_VERBOSE("KEEP: TextureFile: '" << TmpFilename << "' new size=" << _size); EWOL_VERBOSE("KEEP: TextureFile: '" << TmpFilename << "' new size=" << _size);
ewol::resource::ImageDF* object = NULL; ewol::object::Shared<ewol::resource::ImageDF> object = nullptr;
ewol::Resource* object2 = getManager().localKeep("DF__" + TmpFilename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep("DF__" + TmpFilename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::ImageDF*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::ImageDF>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << TmpFilename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << TmpFilename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
EWOL_INFO("CREATE: ImageDF: '" << TmpFilename << "' size=" << _size); EWOL_INFO("CREATE: ImageDF: '" << TmpFilename << "' size=" << _size);
// need to crate a new one ... // need to crate a new one ...
object = new ewol::resource::ImageDF("DF__" + TmpFilename, _filename, _size); object = ewol::object::makeShared(new ewol::resource::ImageDF("DF__" + TmpFilename, _filename, _size));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::ImageDF::release(ewol::resource::ImageDF*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -24,7 +24,9 @@ namespace ewol {
protected: protected:
ImageDF(const std::string& _genName); ImageDF(const std::string& _genName);
ImageDF(std::string _genName, const std::string& _fileName, const ivec2& _size); ImageDF(std::string _genName, const std::string& _fileName, const ivec2& _size);
public:
virtual ~ImageDF() { }; virtual ~ImageDF() { };
protected:
/** /**
* @brief Generate distance field of this Image input. * @brief Generate distance field of this Image input.
* @param[in] _input Input image to change in distance field mode. * @param[in] _input Input image to change in distance field mode.
@ -41,14 +43,9 @@ namespace ewol {
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the image file. * @param[in] _filename Name of the image file.
* @param[in] _requested size of the image (usefull when loading .svg to automatic rescale) * @param[in] _requested size of the image (usefull when loading .svg to automatic rescale)
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::ImageDF* keep(const std::string& _filename, ivec2 _size=ivec2(-1,-1)); static ewol::object::Shared<ewol::resource::ImageDF> keep(const std::string& _filename, ivec2 _size=ivec2(-1,-1));
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::ImageDF*& _object);
}; };
}; };
}; };

View File

@ -40,14 +40,15 @@ void ewol::resource::Manager::unInit() {
display(); display();
m_resourceListToUpdate.clear(); m_resourceListToUpdate.clear();
// remove all resources ... // remove all resources ...
for (int64_t iii=m_resourceList.size()-1; iii >= 0; iii--) { auto it(m_resourceList.begin());
if (m_resourceList[iii] != NULL) { while(it != m_resourceList.end()) {
EWOL_WARNING("Find a resource that is not removed : [" << m_resourceList[iii]->getId() << "]" if ((*it) != nullptr) {
<< "=\"" << m_resourceList[iii]->getName() << "\" " EWOL_WARNING("Find a resource that is not removed : [" << (*it)->getId() << "]"
<< m_resourceList[iii]->getCounter() << " elements"); << "=\"" << (*it)->getName() << "\" "
delete(m_resourceList[iii]); << (*it)->getRefCount() << " elements");
m_resourceList[iii] = NULL;
} }
m_resourceList.erase(it);
it = m_resourceList.begin();
} }
m_resourceList.clear(); m_resourceList.clear();
} }
@ -55,12 +56,12 @@ void ewol::resource::Manager::unInit() {
void ewol::resource::Manager::display() { void ewol::resource::Manager::display() {
EWOL_INFO("Resources loaded : "); EWOL_INFO("Resources loaded : ");
// remove all resources ... // remove all resources ...
for (int64_t iii=m_resourceList.size()-1; iii >= 0; iii--) { for (auto &it : m_resourceList) {
if (m_resourceList[iii] != NULL) { if (it != nullptr) {
EWOL_INFO(" [" << m_resourceList[iii]->getId() << "]" EWOL_INFO(" [" << it->getId() << "]"
<< m_resourceList[iii]->getObjectType() << it->getObjectType()
<< "=\"" << m_resourceList[iii]->getName() << "\" " << "=\"" << it->getName() << "\" "
<< m_resourceList[iii]->getCounter() << " elements"); << it->getRefCount() << " elements");
} }
} }
EWOL_INFO("Resources ---"); EWOL_INFO("Resources ---");
@ -72,11 +73,11 @@ void ewol::resource::Manager::reLoadResources() {
if (m_resourceList.size() != 0) { if (m_resourceList.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) { for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1)); EWOL_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (int64_t iii=m_resourceList.size()-1; iii >= 0; iii--) { for (auto &it : m_resourceList) {
if(m_resourceList[iii] != NULL) { if(it != nullptr) {
if (jjj == m_resourceList[iii]->getResourceLevel()) { if (jjj == it->getResourceLevel()) {
m_resourceList[iii]->reload(); it->reload();
EWOL_INFO(" [" << m_resourceList[iii]->getId() << "]="<< m_resourceList[iii]->getObjectType()); EWOL_INFO(" [" << it->getId() << "]="<< it->getObjectType());
} }
} }
} }
@ -87,47 +88,44 @@ void ewol::resource::Manager::reLoadResources() {
EWOL_INFO("------------- Resources -------------"); EWOL_INFO("------------- Resources -------------");
} }
void ewol::resource::Manager::update(ewol::Resource* _object) { void ewol::resource::Manager::update(const ewol::object::Shared<ewol::Resource>& _object) {
// chek if not added before // chek if not added before
for (size_t iii=0; iii<m_resourceListToUpdate.size(); iii++) { for (auto &it : m_resourceListToUpdate) {
if (m_resourceListToUpdate[iii] != NULL) { if ( it != nullptr
if (m_resourceListToUpdate[iii] == _object) { && it == _object) {
// just prevent some double add ... // just prevent some double add ...
return; return;
} }
} }
}
// add it ... // add it ...
m_resourceListToUpdate.push_back(_object); m_resourceListToUpdate.push_back(_object);
} }
// Specific to load or update the data in the openGl context == > system use only // Specific to load or update the data in the openGl context == > system use only
void ewol::resource::Manager::updateContext() { void ewol::resource::Manager::updateContext() {
if (true == m_contextHasBeenRemoved) { if (m_contextHasBeenRemoved == true) {
// need to update all ... // need to update all ...
m_contextHasBeenRemoved = false; m_contextHasBeenRemoved = false;
if (m_resourceList.size() != 0) { if (m_resourceList.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) { for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1)); EWOL_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (size_t iii=0; iii<m_resourceList.size(); iii++) { for (auto &it : m_resourceList) {
if(m_resourceList[iii] != NULL) { if( it != nullptr
if (jjj == m_resourceList[iii]->getResourceLevel()) { && jjj == it->getResourceLevel()) {
//EWOL_DEBUG("Update context of " << iii << " named : " << l_resourceList[iii]->getName()); //EWOL_DEBUG("Update context named : " << l_resourceList[iii]->getName());
m_resourceList[iii]->updateContext(); it->updateContext();
} }
} }
} }
} }
} } else {
}else {
if (m_resourceListToUpdate.size() != 0) { if (m_resourceListToUpdate.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) { for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" updateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1)); EWOL_INFO(" updateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (size_t iii=0; iii<m_resourceListToUpdate.size(); iii++) { for (auto &it : m_resourceListToUpdate) {
if(m_resourceListToUpdate[iii] != NULL) { if ( it != nullptr
if (jjj == m_resourceListToUpdate[iii]->getResourceLevel()) { && jjj == it->getResourceLevel()) {
m_resourceListToUpdate[iii]->updateContext(); it->updateContext();
}
} }
} }
} }
@ -139,9 +137,9 @@ void ewol::resource::Manager::updateContext() {
// in this case, it is really too late ... // in this case, it is really too late ...
void ewol::resource::Manager::contextHasBeenDestroyed() { void ewol::resource::Manager::contextHasBeenDestroyed() {
for (size_t iii=0; iii<m_resourceList.size(); iii++) { for (auto &it : m_resourceList) {
if (m_resourceList[iii] != NULL) { if (it != nullptr) {
m_resourceList[iii]->removeContextToLate(); it->removeContextToLate();
} }
} }
// no context preent ... // no context preent ...
@ -149,26 +147,24 @@ void ewol::resource::Manager::contextHasBeenDestroyed() {
} }
// internal generic keeper ... // internal generic keeper ...
ewol::Resource* ewol::resource::Manager::localKeep(const std::string& _filename) { ewol::object::Shared<ewol::Resource> ewol::resource::Manager::localKeep(const std::string& _filename) {
EWOL_VERBOSE("KEEP (DEFAULT) : file : \"" << _filename << "\""); EWOL_VERBOSE("KEEP (DEFAULT) : file : \"" << _filename << "\"");
for (size_t iii=0; iii<m_resourceList.size(); iii++) { for (auto &it : m_resourceList) {
if (m_resourceList[iii] != NULL) { if ( it != nullptr
if(m_resourceList[iii]->getName() == _filename) { && it->getName() == _filename) {
m_resourceList[iii]->increment(); return it;
return m_resourceList[iii];
}
} }
} }
// we did not find it ... // we did not find it ...
return NULL; return nullptr;
} }
// internal generic keeper ... // internal generic keeper ...
void ewol::resource::Manager::localAdd(ewol::Resource* _object) { void ewol::resource::Manager::localAdd(const ewol::object::Shared<ewol::Resource>& _object) {
//Add ... find empty slot //Add ... find empty slot
for (size_t iii=0; iii<m_resourceList.size(); iii++) { for (auto &it : m_resourceList) {
if (m_resourceList[iii] == NULL) { if (it == nullptr) {
m_resourceList[iii] = _object; it = _object;
return; return;
} }
} }
@ -176,56 +172,24 @@ void ewol::resource::Manager::localAdd(ewol::Resource* _object) {
m_resourceList.push_back(_object); m_resourceList.push_back(_object);
} }
bool ewol::resource::Manager::release(ewol::Resource*& _object) {
if (NULL == _object) {
EWOL_ERROR("Try to remove a resource that have null pointer ...");
return false;
}
for (size_t iii=0; iii<m_resourceListToUpdate.size(); iii++) {
if (m_resourceListToUpdate[iii] == _object) {
m_resourceListToUpdate[iii] = NULL;
//l_resourceListToUpdate.Erase(iii);
}
}
EWOL_VERBOSE("RELEASE (default) : file : \"" << _object->getName() << "\"");
for (int64_t iii=m_resourceList.size()-1; iii >= 0; iii--) {
if (m_resourceList[iii] == NULL) {
continue;
}
if(m_resourceList[iii] != _object) {
continue;
}
if (m_resourceList[iii]->decrement() == true) {
// remove element from the list :
m_resourceList[iii] = NULL;
// delete element
_object->removeObject();
// insidiously remove the pointer for the caller ...
_object = NULL;
return true; // object really removed
}
// insidiously remove the pointer for the caller ...
_object = NULL;
return false; // just decrement ...
}
EWOL_ERROR("Can not find the resources in the list : " << (int64_t)_object);
// insidiously remove the pointer for the caller ...
_object = NULL;
return false;
}
// in case of error ... // in case of error ...
void ewol::resource::Manager::onObjectRemove(ewol::Object * _removeObject) { bool ewol::resource::Manager::checkResourceToRemove() {
for (size_t iii=0; iii<m_resourceList.size(); ++iii) { //EWOL_INFO("remove object in Manager");
if (m_resourceList[iii] == _removeObject) { updateContext();
EWOL_WARNING("Remove Resource that is not removed ... "); for (auto it(m_resourceList.begin()); it!=m_resourceList.end(); ++it) {
m_resourceList[iii] = NULL; if ((*it) == nullptr) {
m_resourceList.erase(it);
it = m_resourceList.begin();
continue;
} }
// 1 in object list, 1 in reference active list, and one here
if ((*it)->getRefCount() > 3) {
continue;
} }
for (size_t iii=0; iii<m_resourceListToUpdate.size(); ++iii) { EWOL_DEBUG("Request remove of an resource (refcount in Low : " << (*it)->getRefCount() << ")");
if (m_resourceListToUpdate[iii] == _removeObject) { m_resourceList.erase(it);
EWOL_WARNING("Remove Resource that is not removed .2. "); it = m_resourceList.begin();
m_resourceListToUpdate[iii] = NULL; return true;
}
} }
return false;
} }

View File

@ -9,16 +9,19 @@
#ifndef __RESOURCES_MANAGER_H__ #ifndef __RESOURCES_MANAGER_H__
#define __RESOURCES_MANAGER_H__ #define __RESOURCES_MANAGER_H__
#include <list>
#include <vector>
#include <etk/types.h> #include <etk/types.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/resource/Resource.h> #include <ewol/resource/Resource.h>
#include <ewol/object/RemoveEvent.h>
namespace ewol { namespace ewol {
namespace resource { namespace resource {
class Manager { class Manager{
private: private:
std::vector<ewol::Resource*> m_resourceList; std::list<ewol::object::Owner<ewol::Resource>> m_resourceList;
std::vector<ewol::Resource*> m_resourceListToUpdate; std::vector<ewol::object::Shared<ewol::Resource>> m_resourceListToUpdate;
bool m_contextHasBeenRemoved; bool m_contextHasBeenRemoved;
public: public:
/** /**
@ -29,7 +32,7 @@ namespace ewol {
* @brief Uninitiamize the resource manager, free all resources previously requested * @brief Uninitiamize the resource manager, free all resources previously requested
* @note when not free == > generate warning, because the segfault can appear after... * @note when not free == > generate warning, because the segfault can appear after...
*/ */
~Manager(); virtual ~Manager();
/** /**
* @brief remove all resources (un-init) out of the destructor (due to the system implementation) * @brief remove all resources (un-init) out of the destructor (due to the system implementation)
*/ */
@ -47,7 +50,7 @@ namespace ewol {
* @brief Call by the system to send all the needed data on the graphic card chen they change ... * @brief Call by the system to send all the needed data on the graphic card chen they change ...
* @param[in] _object The resources that might be updated * @param[in] _object The resources that might be updated
*/ */
void update(ewol::Resource* _object); void update(const ewol::object::Shared<ewol::Resource>& _object);
/** /**
* @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other .... * @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
*/ */
@ -58,17 +61,9 @@ namespace ewol {
void contextHasBeenDestroyed(); void contextHasBeenDestroyed();
public: public:
// internal API to extent eResources in extern Soft // internal API to extent eResources in extern Soft
ewol::Resource* localKeep(const std::string& _filename); ewol::object::Shared<ewol::Resource> localKeep(const std::string& _filename);
void localAdd(ewol::Resource* _object); void localAdd(const ewol::object::Shared<ewol::Resource>& _object);
public: virtual bool checkResourceToRemove();
/**
* @brief release a resources and free it if the Last release is call.
* @param[in,out] _object element to realease == > is return at NULL value.
* @return true, if element is removed, and false for just decreasing counter
*/
bool release(ewol::Resource*& _object);
public: // herited function
virtual void onObjectRemove(ewol::Object * _removeObject);
}; };
}; };
}; };

View File

@ -36,8 +36,8 @@ ewol::resource::Program::Program(const std::string& _filename) :
std::string tmpFilename = m_name; std::string tmpFilename = m_name;
// remove extention ... // remove extention ...
tmpFilename.erase(tmpFilename.size()-4, 4); tmpFilename.erase(tmpFilename.size()-4, 4);
ewol::resource::Shader* tmpShader = ewol::resource::Shader::keep(tmpFilename+"vert"); ewol::object::Shared<ewol::resource::Shader> tmpShader = ewol::resource::Shader::keep(tmpFilename+"vert");
if (NULL == tmpShader) { if (nullptr == tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename); EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
return; return;
} else { } else {
@ -45,7 +45,7 @@ ewol::resource::Program::Program(const std::string& _filename) :
m_shaderList.push_back(tmpShader); m_shaderList.push_back(tmpShader);
} }
tmpShader = ewol::resource::Shader::keep(tmpFilename+"frag"); tmpShader = ewol::resource::Shader::keep(tmpFilename+"frag");
if (NULL == tmpShader) { if (nullptr == tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename); EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
return; return;
} else { } else {
@ -64,7 +64,7 @@ ewol::resource::Program::Program(const std::string& _filename) :
} }
#define MAX_LINE_SIZE (2048) #define MAX_LINE_SIZE (2048)
char tmpData[MAX_LINE_SIZE]; char tmpData[MAX_LINE_SIZE];
while (file.fileGets(tmpData, MAX_LINE_SIZE) != NULL) { while (file.fileGets(tmpData, MAX_LINE_SIZE) != nullptr) {
int32_t len = strlen(tmpData); int32_t len = strlen(tmpData);
if( tmpData[len-1] == '\n' if( tmpData[len-1] == '\n'
|| tmpData[len-1] == '\r') { || tmpData[len-1] == '\r') {
@ -80,8 +80,8 @@ ewol::resource::Program::Program(const std::string& _filename) :
} }
// get it with relative position : // get it with relative position :
std::string tmpFilename = file.getRelativeFolder() + tmpData; std::string tmpFilename = file.getRelativeFolder() + tmpData;
ewol::resource::Shader* tmpShader = ewol::resource::Shader::keep(tmpFilename); ewol::object::Shared<ewol::resource::Shader> tmpShader = ewol::resource::Shader::keep(tmpFilename);
if (NULL == tmpShader) { if (nullptr == tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename); EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
} else { } else {
EWOL_DEBUG("Add shader on program : "<< tmpFilename); EWOL_DEBUG("Add shader on program : "<< tmpFilename);
@ -96,10 +96,6 @@ ewol::resource::Program::Program(const std::string& _filename) :
} }
ewol::resource::Program::~Program() { ewol::resource::Program::~Program() {
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
ewol::resource::Shader::release(m_shaderList[iii]);
m_shaderList[iii] = 0;
}
m_shaderList.clear(); m_shaderList.clear();
removeContext(); removeContext();
m_elementList.clear(); m_elementList.clear();
@ -173,7 +169,7 @@ void ewol::resource::Program::updateContext() {
EWOL_DEBUG("Create program with oglID=" << m_program); EWOL_DEBUG("Create program with oglID=" << m_program);
// first attach vertex shader, and after fragment shader // first attach vertex shader, and after fragment shader
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (NULL != m_shaderList[iii]) { if (nullptr != m_shaderList[iii]) {
if (m_shaderList[iii]->getShaderType() == GL_VERTEX_SHADER) { if (m_shaderList[iii]->getShaderType() == GL_VERTEX_SHADER) {
glAttachShader(m_program, m_shaderList[iii]->getGL_ID()); glAttachShader(m_program, m_shaderList[iii]->getGL_ID());
checkGlError("glAttachShader", __LINE__); checkGlError("glAttachShader", __LINE__);
@ -181,7 +177,7 @@ void ewol::resource::Program::updateContext() {
} }
} }
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (NULL != m_shaderList[iii]) { if (nullptr != m_shaderList[iii]) {
if (m_shaderList[iii]->getShaderType() == GL_FRAGMENT_SHADER) { if (m_shaderList[iii]->getShaderType() == GL_FRAGMENT_SHADER) {
glAttachShader(m_program, m_shaderList[iii]->getGL_ID()); glAttachShader(m_program, m_shaderList[iii]->getGL_ID());
checkGlError("glAttachShader", __LINE__); checkGlError("glAttachShader", __LINE__);
@ -280,13 +276,13 @@ void ewol::resource::Program::reload() {
return; return;
} }
// remove previous data ... // remove previous data ...
if (NULL != m_fileData) { if (nullptr != m_fileData) {
delete[] m_fileData; delete[] m_fileData;
m_fileData = 0; m_fileData = 0;
} }
// allocate data // allocate data
m_fileData = new char[fileSize+5]; m_fileData = new char[fileSize+5];
if (NULL == m_fileData) { if (nullptr == m_fileData) {
EWOL_ERROR("Error Memory allocation size=" << fileSize); EWOL_ERROR("Error Memory allocation size=" << fileSize);
return; return;
} }
@ -331,7 +327,7 @@ void ewol::resource::Program::sendAttribute(int32_t _idElem,
void ewol::resource::Program::sendAttributePointer(int32_t _idElem, void ewol::resource::Program::sendAttributePointer(int32_t _idElem,
int32_t _nbElement, int32_t _nbElement,
ewol::resource::VirtualBufferObject* _vbo, const ewol::object::Shared<ewol::resource::VirtualBufferObject>& _vbo,
int32_t _index, int32_t _index,
int32_t _jumpBetweenSample, int32_t _jumpBetweenSample,
int32_t _offset) { int32_t _offset) {
@ -514,8 +510,8 @@ void ewol::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform1fv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform1fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -536,8 +532,8 @@ void ewol::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform2fv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform2fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -558,8 +554,8 @@ void ewol::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform3fv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform3fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -580,8 +576,8 @@ void ewol::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform4fv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform4fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -605,8 +601,8 @@ void ewol::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform1iv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform1iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -627,8 +623,8 @@ void ewol::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform2iv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform2iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -649,8 +645,8 @@ void ewol::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform3iv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform3iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -671,8 +667,8 @@ void ewol::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
EWOL_ERROR("No element to send at open GL ..."); EWOL_ERROR("No element to send at open GL ...");
return; return;
} }
if (NULL == _value) { if (nullptr == _value) {
EWOL_ERROR("NULL Input pointer to send at open GL ..."); EWOL_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
glUniform4iv(m_elementList[_idElem].m_elementId, _nbElement, _value); glUniform4iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
@ -775,36 +771,26 @@ void ewol::resource::Program::unUse() {
ewol::resource::Program* ewol::resource::Program::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::Program> ewol::resource::Program::keep(const std::string& _filename) {
EWOL_VERBOSE("KEEP : Program : file : \"" << _filename << "\""); EWOL_VERBOSE("KEEP : Program : file : \"" << _filename << "\"");
ewol::resource::Program* object = NULL; ewol::object::Shared<ewol::resource::Program> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::Program*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::Program>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// need to crate a new one ... // need to crate a new one ...
object = new ewol::resource::Program(_filename); object = ewol::object::makeShared(new ewol::resource::Program(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::Program::release(ewol::resource::Program*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -50,7 +50,7 @@ namespace ewol {
private : private :
bool m_exist; //!< the file existed bool m_exist; //!< the file existed
GLuint m_program; //!< openGL id of the current program GLuint m_program; //!< openGL id of the current program
std::vector<ewol::resource::Shader*> m_shaderList; //!< List of all the shader loaded std::vector<ewol::object::Shared<ewol::resource::Shader>> m_shaderList; //!< List of all the shader loaded
std::vector<ewol::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user std::vector<ewol::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
bool m_hasTexture; //!< A texture has been set to the current shader bool m_hasTexture; //!< A texture has been set to the current shader
bool m_hasTexture1; //!< A texture has been set to the current shader bool m_hasTexture1; //!< A texture has been set to the current shader
@ -60,6 +60,7 @@ namespace ewol {
* @param[in] filename Standard file name format. see @ref etk::FSNode * @param[in] filename Standard file name format. see @ref etk::FSNode
*/ */
Program(const std::string& filename); Program(const std::string& filename);
public:
/** /**
* @brief Destructor, remove the current Program. * @brief Destructor, remove the current Program.
*/ */
@ -85,7 +86,7 @@ namespace ewol {
int32_t _jumpBetweenSample=0); int32_t _jumpBetweenSample=0);
void sendAttributePointer(int32_t _idElem, void sendAttributePointer(int32_t _idElem,
int32_t _nbElement, int32_t _nbElement,
ewol::resource::VirtualBufferObject* _vbo, const ewol::object::Shared<ewol::resource::VirtualBufferObject>& _vbo,
int32_t _index, int32_t _index,
int32_t _jumpBetweenSample=0, int32_t _jumpBetweenSample=0,
int32_t _offset=0); int32_t _offset=0);
@ -297,14 +298,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the openGL program. * @param[in] _filename Name of the openGL program.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::Program* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::Program> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::Program*& _object);
}; };
}; };
}; };

View File

@ -15,19 +15,19 @@
void ewol::Resource::updateContext() { void ewol::Resource::updateContext() {
EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << m_counter << " time(s)"); EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << getRefCount() << " time(s)");
} }
void ewol::Resource::removeContext() { void ewol::Resource::removeContext() {
EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << m_counter << " time(s)"); EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << getRefCount() << " time(s)");
} }
void ewol::Resource::removeContextToLate() { void ewol::Resource::removeContextToLate() {
EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << m_counter << " time(s)"); EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << getRefCount() << " time(s)");
} }
void ewol::Resource::reload() { void ewol::Resource::reload() {
EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << m_counter << " time(s)"); EWOL_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << getRefCount() << " time(s)");
} }
ewol::resource::Manager& ewol::Resource::getManager() { ewol::resource::Manager& ewol::Resource::getManager() {

View File

@ -25,14 +25,12 @@ namespace ewol {
class Resource : public ewol::Object { class Resource : public ewol::Object {
public: public:
Resource() : Resource() :
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1) { m_resourceLevel(MAX_RESOURCE_LEVEL-1) {
addObjectType("ewol::Resource"); addObjectType("ewol::Resource");
setStatusResource(true); setStatusResource(true);
}; };
Resource(const std::string& _name) : Resource(const std::string& _name) :
ewol::Object(_name), ewol::Object(_name),
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1) { m_resourceLevel(MAX_RESOURCE_LEVEL-1) {
addObjectType("ewol::Resource"); addObjectType("ewol::Resource");
setStatusResource(true); setStatusResource(true);
@ -40,19 +38,6 @@ namespace ewol {
virtual ~Resource() { virtual ~Resource() {
}; };
private:
uint32_t m_counter; //!< number of time the element was loaded.
public:
void increment() {
m_counter++;
};
bool decrement() {
m_counter--;
return (m_counter == 0)?true:false;
};
int32_t getCounter() {
return m_counter;
};
protected: 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 updata priority [0..5] 0 must be update first.
public: public:

View File

@ -18,7 +18,7 @@
ewol::resource::Shader::Shader(const std::string& _filename) : ewol::resource::Shader::Shader(const std::string& _filename) :
ewol::Resource(_filename), ewol::Resource(_filename),
m_exist(false), m_exist(false),
m_fileData(NULL), m_fileData(nullptr),
m_shader(0), m_shader(0),
m_type(0) { m_type(0) {
addObjectType("ewol::Shader"); addObjectType("ewol::Shader");
@ -38,9 +38,9 @@ ewol::resource::Shader::Shader(const std::string& _filename) :
} }
ewol::resource::Shader::~Shader() { ewol::resource::Shader::~Shader() {
if (NULL != m_fileData) { if (nullptr != m_fileData) {
delete [] m_fileData; delete [] m_fileData;
m_fileData = NULL; m_fileData = nullptr;
} }
if (0!=m_shader) { if (0!=m_shader) {
glDeleteShader(m_shader); glDeleteShader(m_shader);
@ -62,7 +62,7 @@ void ewol::resource::Shader::updateContext() {
// Do nothing == > too dangerous ... // Do nothing == > too dangerous ...
} else { } else {
// create the Shader // create the Shader
if (NULL == m_fileData) { if (nullptr == m_fileData) {
m_shader = 0; m_shader = 0;
return; return;
} }
@ -73,7 +73,7 @@ void ewol::resource::Shader::updateContext() {
return; return;
} else { } else {
//EWOL_INFO("Creater shader with GLID=" << m_shader); //EWOL_INFO("Creater shader with GLID=" << m_shader);
glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL); glShaderSource(m_shader, 1, (const char**)&m_fileData, nullptr);
glCompileShader(m_shader); glCompileShader(m_shader);
GLint compiled = 0; GLint compiled = 0;
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled); glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
@ -128,13 +128,13 @@ void ewol::resource::Shader::reload() {
return; return;
} }
// remove previous data ... // remove previous data ...
if (NULL != m_fileData) { if (nullptr != m_fileData) {
delete[] m_fileData; delete[] m_fileData;
m_fileData = 0; m_fileData = 0;
} }
// allocate data // allocate data
m_fileData = new char[fileSize+5]; m_fileData = new char[fileSize+5];
if (NULL == m_fileData) { if (nullptr == m_fileData) {
EWOL_ERROR("Error Memory allocation size=" << fileSize); EWOL_ERROR("Error Memory allocation size=" << fileSize);
return; return;
} }
@ -149,35 +149,26 @@ void ewol::resource::Shader::reload() {
updateContext(); updateContext();
} }
ewol::resource::Shader* ewol::resource::Shader::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::Shader> ewol::resource::Shader::keep(const std::string& _filename) {
EWOL_VERBOSE("KEEP : Simpleshader : file : \"" << _filename << "\""); EWOL_VERBOSE("KEEP : Simpleshader : file : \"" << _filename << "\"");
ewol::resource::Shader* object = NULL; ewol::object::Shared<ewol::resource::Shader> object = nullptr;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::Shader*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::Shader>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// need to crate a new one ... // need to crate a new one ...
object = new ewol::resource::Shader(_filename); object = ewol::object::makeShared(new ewol::resource::Shader(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::Shader::release(ewol::resource::Shader*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -31,6 +31,7 @@ namespace ewol {
* @param[in] filename Standard file name format. see @ref etk::FSNode * @param[in] filename Standard file name format. see @ref etk::FSNode
*/ */
Shader(const std::string& _filename); Shader(const std::string& _filename);
public:
/** /**
* @brief Destructor, remove the current Shader * @brief Destructor, remove the current Shader
*/ */
@ -72,14 +73,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the openGL Shader. * @param[in] _filename Name of the openGL Shader.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::Shader* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::Shader> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::Shader*& _object);
}; };
}; };
}; };

View File

@ -107,22 +107,14 @@ void ewol::resource::Texture::setImageSize(ivec2 _newSize) {
m_data.resize(_newSize); m_data.resize(_newSize);
} }
ewol::resource::Texture* ewol::resource::Texture::keep() { ewol::object::Shared<ewol::resource::Texture> ewol::resource::Texture::keep() {
// this element create a new one every time .... // this element create a new one every time ....
ewol::resource::Texture* object = new ewol::resource::Texture(); ewol::object::Shared<ewol::resource::Texture> object = ewol::object::makeShared(new ewol::resource::Texture());
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??"); EWOL_ERROR("allocation error of a resource : ??TEX??");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::Texture::release(ewol::resource::Texture*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -47,7 +47,8 @@ namespace ewol {
protected: protected:
Texture(const std::string& _filename); Texture(const std::string& _filename);
Texture(); Texture();
~Texture(); public:
virtual ~Texture();
public: public:
// you must set the size here, because it will be set in multiple of pow(2) // you must set the size here, because it will be set in multiple of pow(2)
void setImageSize(ivec2 newSize); void setImageSize(ivec2 newSize);
@ -61,14 +62,9 @@ namespace ewol {
/** /**
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::Texture* keep(); static ewol::object::Shared<ewol::resource::Texture> keep();
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::Texture*& _object);
}; };
}; };
}; };

View File

@ -47,10 +47,10 @@ ewol::resource::TexturedFont::TexturedFont(const std::string& _fontName) :
addObjectType("ewol::resource::TexturedFont"); addObjectType("ewol::resource::TexturedFont");
EWOL_DEBUG("Load font : '" << _fontName << "'" ); EWOL_DEBUG("Load font : '" << _fontName << "'" );
m_font[0] = NULL; m_font[0] = nullptr;
m_font[1] = NULL; m_font[1] = nullptr;
m_font[2] = NULL; m_font[2] = nullptr;
m_font[3] = NULL; m_font[3] = nullptr;
m_modeWraping[0] = ewol::font::Regular; m_modeWraping[0] = ewol::font::Regular;
m_modeWraping[1] = ewol::font::Regular; m_modeWraping[1] = ewol::font::Regular;
@ -72,7 +72,7 @@ ewol::resource::TexturedFont::TexturedFont(const std::string& _fontName) :
const char * tmpData = _fontName.c_str(); const char * tmpData = _fontName.c_str();
const char * tmpPos = strchr(tmpData, ':'); const char * tmpPos = strchr(tmpData, ':');
if (tmpPos == NULL) { if (tmpPos == nullptr) {
m_size = 1; m_size = 1;
EWOL_CRITICAL("Can not parse the font name : \"" << _fontName << "\" ??? ':' " ); EWOL_CRITICAL("Can not parse the font name : \"" << _fontName << "\" ??? ':' " );
return; return;
@ -188,19 +188,19 @@ ewol::resource::TexturedFont::TexturedFont(const std::string& _fontName) :
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
if (m_fileName[iiiFontId].size() == 0) { if (m_fileName[iiiFontId].size() == 0) {
EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size ); EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size );
m_font[iiiFontId] = NULL; m_font[iiiFontId] = nullptr;
continue; continue;
} }
EWOL_INFO("Load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size); EWOL_INFO("Load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size);
m_font[iiiFontId] = ewol::resource::FontFreeType::keep(m_fileName[iiiFontId]); m_font[iiiFontId] = ewol::resource::FontFreeType::keep(m_fileName[iiiFontId]);
if (m_font[iiiFontId] == NULL) { if (m_font[iiiFontId] == nullptr) {
EWOL_DEBUG("error in loading FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size ); EWOL_DEBUG("error in loading FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size );
} }
} }
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
// set the bassic charset: // set the bassic charset:
m_listElement[iiiFontId].clear(); m_listElement[iiiFontId].clear();
if (m_font[iiiFontId] == NULL) { if (m_font[iiiFontId] == nullptr) {
continue; continue;
} }
m_height[iiiFontId] = m_font[iiiFontId]->getHeight(m_size); m_height[iiiFontId] = m_font[iiiFontId]->getHeight(m_size);
@ -225,16 +225,14 @@ ewol::resource::TexturedFont::TexturedFont(const std::string& _fontName) :
} }
ewol::resource::TexturedFont::~TexturedFont() { ewol::resource::TexturedFont::~TexturedFont() {
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
ewol::resource::FontFreeType::release(m_font[iiiFontId]);
}
} }
bool ewol::resource::TexturedFont::addGlyph(const char32_t& _val) { bool ewol::resource::TexturedFont::addGlyph(const char32_t& _val) {
bool hasChange = false; bool hasChange = false;
// for each font : // for each font :
for (int32_t iii=0; iii<4 ; iii++) { for (int32_t iii=0; iii<4 ; iii++) {
if (m_font[iii] == NULL) { if (m_font[iii] == nullptr) {
continue; continue;
} }
// add the curent "char" // add the curent "char"
@ -333,7 +331,7 @@ ewol::GlyphProperty* ewol::resource::TexturedFont::getGlyphPointer(const char32_
if (m_listElement[_displayMode].size() > 0) { if (m_listElement[_displayMode].size() > 0) {
return &((m_listElement[_displayMode])[0]); return &((m_listElement[_displayMode])[0]);
} }
return NULL; return nullptr;
} }
//EWOL_ERROR(" index=" << index); //EWOL_ERROR(" index=" << index);
//EWOL_ERROR(" m_UVal=" << m_listElement[_displayMode][index].m_UVal); //EWOL_ERROR(" m_UVal=" << m_listElement[_displayMode][index].m_UVal);
@ -343,42 +341,27 @@ ewol::GlyphProperty* ewol::resource::TexturedFont::getGlyphPointer(const char32_
return &((m_listElement[_displayMode])[index]); return &((m_listElement[_displayMode])[index]);
} }
ewol::resource::TexturedFont* ewol::resource::TexturedFont::keep(const std::string& _filename) { ewol::object::Shared<ewol::resource::TexturedFont> ewol::resource::TexturedFont::keep(const std::string& _filename) {
EWOL_VERBOSE("KEEP : TexturedFont : file : '" << _filename << "'"); EWOL_VERBOSE("KEEP : TexturedFont : file : '" << _filename << "'");
ewol::resource::TexturedFont* object = NULL; ewol::object::Shared<ewol::resource::TexturedFont> object;
ewol::Resource* object2 = getManager().localKeep(_filename); ewol::object::Shared<ewol::Resource> object2 = getManager().localKeep(_filename);
if (NULL != object2) { if (nullptr != object2) {
object = dynamic_cast<ewol::resource::TexturedFont*>(object2); object = ewol::dynamic_pointer_cast<ewol::resource::TexturedFont>(object2);
if (NULL == object) { if (nullptr == object) {
EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)"); EWOL_CRITICAL("Request resource file : '" << _filename << "' With the wrong type (dynamic cast error)");
return NULL; return nullptr;
} }
} }
if (NULL != object) { if (nullptr != object) {
return object; return object;
} }
// need to crate a new one ... // need to crate a new one ...
EWOL_INFO("CREATE: TexturedFont : file : '" << _filename << "'"); EWOL_INFO("CREATE: TexturedFont : file : '" << _filename << "'");
object = new ewol::resource::TexturedFont(_filename); object = ewol::object::makeShared(new ewol::resource::TexturedFont(_filename));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : " << _filename); EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::TexturedFont::release(ewol::resource::TexturedFont*& _object) {
if (NULL == _object) {
return;
}
EWOL_VERBOSE("RELEASE: TexturedFont : file : '" << _object->getName() << "' count=" << _object->getCounter());
std::string name = _object->getName();
int32_t count = _object->getCounter() - 1;
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
if (getManager().release(object2) == true) {
EWOL_ERROR("REMOVE: TexturedFont : file : '" << name << "' count=" << count);
//etk::displayBacktrace(false);
}
_object = NULL;
}

View File

@ -36,7 +36,7 @@ namespace ewol {
// specific element to have the the know if the specify element is known... // specific element to have the the know if the specify element is known...
// == > otherwise I can just generate italic ... // == > otherwise I can just generate italic ...
// == > Bold is a little more complicated (maybe with the bordersize) // == > Bold is a little more complicated (maybe with the bordersize)
ewol::resource::FontBase* m_font[4]; ewol::object::Shared<ewol::resource::FontBase> m_font[4];
enum ewol::font::mode m_modeWraping[4]; //!< This is a wrapping mode to prevent the fact that no font is define for a specific mode enum ewol::font::mode m_modeWraping[4]; //!< This is a wrapping mode to prevent the fact that no font is define for a specific mode
public: public:
std::vector<GlyphProperty> m_listElement[4]; std::vector<GlyphProperty> m_listElement[4];
@ -46,7 +46,8 @@ namespace ewol {
int32_t m_lastRawHeigh[4]; int32_t m_lastRawHeigh[4];
protected: protected:
TexturedFont(const std::string& _fontName); TexturedFont(const std::string& _fontName);
~TexturedFont(); public:
virtual ~TexturedFont();
public: public:
/** /**
* @brief get the display height of this font * @brief get the display height of this font
@ -74,7 +75,7 @@ namespace ewol {
* @brief get the pointer on the coresponding glyph * @brief get the pointer on the coresponding glyph
* @param[in] _charcode The unicodeValue * @param[in] _charcode The unicodeValue
* @param[in] _displayMode Mode to display the currrent font * @param[in] _displayMode Mode to display the currrent font
* @return The pointer on the glyph == > never NULL * @return The pointer on the glyph == > never nullptr
*/ */
ewol::GlyphProperty* getGlyphPointer(const char32_t& _charcode, const enum ewol::font::mode _displayMode); ewol::GlyphProperty* getGlyphPointer(const char32_t& _charcode, const enum ewol::font::mode _displayMode);
/** /**
@ -91,14 +92,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the texture font. * @param[in] _filename Name of the texture font.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::TexturedFont* keep(const std::string& _filename); static ewol::object::Shared<ewol::resource::TexturedFont> keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::TexturedFont*& _object);
private: private:
/** /**
* @brief add a glyph in a texture font. * @brief add a glyph in a texture font.

View File

@ -123,22 +123,13 @@ int32_t ewol::resource::VirtualBufferObject::sizeOnBufferVec2(int32_t _id) {
return m_buffer[_id].size()/2; return m_buffer[_id].size()/2;
} }
ewol::resource::VirtualBufferObject* ewol::resource::VirtualBufferObject::keep(int32_t _number) { ewol::object::Shared<ewol::resource::VirtualBufferObject> ewol::resource::VirtualBufferObject::keep(int32_t _number) {
// this element create a new one every time .... // this element create a new one every time ....
ewol::resource::VirtualBufferObject* object = new ewol::resource::VirtualBufferObject(_number); ewol::object::Shared<ewol::resource::VirtualBufferObject> object = ewol::object::makeShared(new ewol::resource::VirtualBufferObject(_number));
if (NULL == object) { if (nullptr == object) {
EWOL_ERROR("allocation error of a resource : ??VBO??"); EWOL_ERROR("allocation error of a resource : ??VBO??");
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ewol::resource::VirtualBufferObject::release(ewol::resource::VirtualBufferObject*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -35,6 +35,7 @@ namespace ewol {
* @param[in] accesMode Acces mode : ??? * @param[in] accesMode Acces mode : ???
*/ */
VirtualBufferObject(int32_t _number); VirtualBufferObject(int32_t _number);
public:
/** /**
* @brief Destructor of this VBO. * @brief Destructor of this VBO.
*/ */
@ -97,14 +98,9 @@ namespace ewol {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _number Number of VBO needed * @param[in] _number Number of VBO needed
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ewol::resource::VirtualBufferObject* keep(int32_t _number); static ewol::object::Shared<ewol::resource::VirtualBufferObject> keep(int32_t _number);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ewol::resource::VirtualBufferObject*& _object);
}; };
}; };
}; };

View File

@ -212,7 +212,7 @@ void ewol::translate::autoDetectLanguage() {
EWOL_INFO("Auto-detect language of system"); EWOL_INFO("Auto-detect language of system");
#if defined(__TARGET_OS__Linux) #if defined(__TARGET_OS__Linux)
char *s = getenv("LANG"); char *s = getenv("LANG");
if (s == NULL || strlen(s) < 2) { if (s == nullptr || strlen(s) < 2) {
EWOL_INFO("Try to determine system language FAIL ..."); EWOL_INFO("Try to determine system language FAIL ...");
} else { } else {
std::string lang; std::string lang;

View File

@ -34,12 +34,12 @@ const char* const ewol::widget::Button::configShaper = "shaper";
#define STATUS_DOWN (3) #define STATUS_DOWN (3)
static ewol::Widget* Create() { static ewol::Widget* create() {
return new ewol::widget::Button(); return new ewol::widget::Button();
} }
void ewol::widget::Button::init(ewol::widget::Manager& _widgetManager) { void ewol::widget::Button::init(ewol::widget::Manager& _widgetManager) {
_widgetManager.addWidgetCreator(__class__, &Create); _widgetManager.addWidgetCreator(__class__, &create);
} }
ewol::widget::Button::Button(const std::string& _shaperName) : ewol::widget::Button::Button(const std::string& _shaperName) :
@ -60,10 +60,10 @@ ewol::widget::Button::Button(const std::string& _shaperName) :
addEventId(eventLeave); addEventId(eventLeave);
addEventId(eventValue); addEventId(eventValue);
// add configuration // add configuration
registerConfig(configToggle, "bool", NULL, "The Button can toogle"); registerConfig(configToggle, "bool", nullptr, "The Button can toogle");
registerConfig(configValue, "bool", NULL, "Basic value of the widget"); registerConfig(configValue, "bool", nullptr, "Basic value of the widget");
registerConfig(configLock, "list", "none;true;released;pressed", "Lock the button in a special state to permit changing state only by the coder"); registerConfig(configLock, "list", "none;true;released;pressed", "Lock the button in a special state to permit changing state only by the coder");
registerConfig(configShaper, "string", NULL, "the display name for config file"); registerConfig(configShaper, "string", nullptr, "the display name for config file");
// shaper satatus update: // shaper satatus update:
CheckStatus(); CheckStatus();

View File

@ -30,18 +30,18 @@ const char * const ewol::widget::ButtonColor::eventChange = "change";
static const char* const eventColorHasChange = "ewol-widget-ButtonColor-colorChange"; static const char* const eventColorHasChange = "ewol-widget-ButtonColor-colorChange";
static ewol::Widget* Create() { static ewol::Widget* create() {
return new ewol::widget::ButtonColor(); return new ewol::widget::ButtonColor();
} }
void ewol::widget::ButtonColor::init(ewol::widget::Manager& _widgetManager) { void ewol::widget::ButtonColor::init(ewol::widget::Manager& _widgetManager) {
_widgetManager.addWidgetCreator(__class__,&Create); _widgetManager.addWidgetCreator(__class__, &create);
} }
ewol::widget::ButtonColor::ButtonColor(etk::Color<> _baseColor, std::string _shaperName) : ewol::widget::ButtonColor::ButtonColor(etk::Color<> _baseColor, std::string _shaperName) :
m_shaper(_shaperName), m_shaper(_shaperName),
m_textColorFg(_baseColor), m_textColorFg(_baseColor),
m_widgetContextMenu(NULL) { m_widgetContextMenu(nullptr) {
addObjectType("ewol::widget::ButtonColor"); addObjectType("ewol::widget::ButtonColor");
addEventId(eventChange); addEventId(eventChange);
changeStatusIn(STATUS_UP); changeStatusIn(STATUS_UP);
@ -177,7 +177,7 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) {
m_mouseHover = false; m_mouseHover = false;
// create a context menu : // create a context menu :
m_widgetContextMenu = new ewol::widget::ContextMenu(); m_widgetContextMenu = new ewol::widget::ContextMenu();
if (NULL == m_widgetContextMenu) { if (nullptr == m_widgetContextMenu) {
EWOL_ERROR("Allocation Error"); EWOL_ERROR("Allocation Error");
return true; return true;
} }
@ -190,13 +190,12 @@ bool ewol::widget::ButtonColor::onEventInput(const ewol::event::Input& _event) {
// set it in the pop-up-system : // set it in the pop-up-system :
m_widgetContextMenu->setSubWidget(myColorChooser); m_widgetContextMenu->setSubWidget(myColorChooser);
myColorChooser->registerOnEvent(this, "change", eventColorHasChange); myColorChooser->registerOnEvent(this, "change", eventColorHasChange);
ewol::widget::Windows* currentWindows = getWindows(); ewol::object::Shared<ewol::widget::Windows> currentWindows = getWindows();
if (NULL == currentWindows) { if (currentWindows == nullptr) {
EWOL_ERROR("Can not get the curent Windows..."); EWOL_ERROR("Can not get the curent Windows...");
delete(m_widgetContextMenu); m_widgetContextMenu.reset();
m_widgetContextMenu=NULL;
} else { } else {
currentWindows->popUpWidgetPush(m_widgetContextMenu); currentWindows->popUpWidgetPush(m_widgetContextMenu.get());
} }
markToRedraw(); markToRedraw();
} }

View File

@ -30,7 +30,7 @@ namespace ewol {
ewol::compositing::Shaper m_shaper; //!< Compositing theme. ewol::compositing::Shaper m_shaper; //!< Compositing theme.
ewol::compositing::Text m_text; //!< Compositing Test display. ewol::compositing::Text m_text; //!< Compositing Test display.
etk::Color<> m_textColorFg; //!< Current color. etk::Color<> m_textColorFg; //!< Current color.
ewol::widget::ContextMenu* m_widgetContextMenu; //!< Specific context menu. ewol::object::Shared<ewol::widget::ContextMenu> m_widgetContextMenu; //!< Specific context menu.
bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)). bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)).
bool m_buttonPressed; //!< Flag to know if the button is curently pressed. bool m_buttonPressed; //!< Flag to know if the button is curently pressed.
// hover area : // hover area :

View File

@ -27,12 +27,12 @@ const char* const ewol::widget::CheckBox::configShaper = "shaper";
#undef __class__ #undef __class__
#define __class__ "CheckBox" #define __class__ "CheckBox"
static ewol::Widget* Create() { static ewol::Widget* create() {
return new ewol::widget::CheckBox(); return new ewol::widget::CheckBox();
} }
void ewol::widget::CheckBox::init(ewol::widget::Manager& _widgetManager) { void ewol::widget::CheckBox::init(ewol::widget::Manager& _widgetManager) {
_widgetManager.addWidgetCreator(__class__,&Create); _widgetManager.addWidgetCreator(__class__, &create);
} }
ewol::widget::CheckBox::CheckBox(const std::string& _shaperName) : ewol::widget::CheckBox::CheckBox(const std::string& _shaperName) :
@ -52,8 +52,8 @@ ewol::widget::CheckBox::CheckBox(const std::string& _shaperName) :
addEventId(eventEnter); addEventId(eventEnter);
addEventId(eventValue); addEventId(eventValue);
// add configuration // add configuration
registerConfig(configValue, "bool", NULL, "Basic value of the widget"); registerConfig(configValue, "bool", nullptr, "Basic value of the widget");
registerConfig(configShaper, "string", NULL, "the display name for config file"); registerConfig(configShaper, "string", nullptr, "the display name for config file");
m_shaperIdSize = m_shaper.requestConfig("box-size"); m_shaperIdSize = m_shaper.requestConfig("box-size");
m_shaperIdSizeInsize = m_shaper.requestConfig("box-inside"); m_shaperIdSizeInsize = m_shaper.requestConfig("box-inside");

View File

@ -18,7 +18,7 @@
namespace ewol { namespace ewol {
namespace widget { namespace widget {
class ColorBar :public ewol::Widget { class ColorBar : public ewol::Widget {
public: public:
// Event list of properties // Event list of properties
static const char * const eventChange; static const char * const eventChange;

View File

@ -45,10 +45,10 @@ bool ewol::widget::Composer::loadFromFile(const std::string& _fileName) {
return false; return false;
} }
exml::Element* root = (exml::Element*)doc.getNamed("composer"); exml::Element* root = (exml::Element*)doc.getNamed("composer");
if (NULL == root ) { if (nullptr == root ) {
// Maybe a multiple node XML for internal config: // Maybe a multiple node XML for internal config:
root = doc.toElement(); root = doc.toElement();
if (NULL == root ) { if (nullptr == root ) {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: \"composer\" ..."); EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: \"composer\" ...");
return false; return false;
} }
@ -70,10 +70,10 @@ bool ewol::widget::Composer::loadFromString(const std::string& _composerXmlStrin
return false; return false;
} }
exml::Element* root = (exml::Element*)doc.getNamed("composer"); exml::Element* root = (exml::Element*)doc.getNamed("composer");
if (NULL == root ) { if (nullptr == root ) {
// Maybe a multiple node XML for internal config: // Maybe a multiple node XML for internal config:
root = doc.toElement(); root = doc.toElement();
if (NULL == root ) { if (nullptr == root ) {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: \"composer\" ..."); EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} (l ?) main node not find: \"composer\" ...");
return false; return false;
} }
@ -96,13 +96,13 @@ void ewol::widget::Composer::registerOnEventNameWidget(const std::string& _subWi
registerOnEventNameWidget(this, _subWidgetName, _eventId, _eventIdgenerated, _overloadData); registerOnEventNameWidget(this, _subWidgetName, _eventId, _eventIdgenerated, _overloadData);
} }
void ewol::widget::Composer::registerOnEventNameWidget(ewol::Object * _destinationObject, void ewol::widget::Composer::registerOnEventNameWidget(const ewol::object::Shared<ewol::Object>& _destinationObject,
const std::string& _subWidgetName, const std::string& _subWidgetName,
const char * _eventId, const char * _eventId,
const char * _eventIdgenerated, const char * _eventIdgenerated,
const std::string& _overloadData) { const std::string& _overloadData) {
ewol::Widget* tmpWidget = getWidgetNamed(_subWidgetName); ewol::object::Shared<ewol::Widget> tmpWidget = getWidgetNamed(_subWidgetName);
if (NULL != tmpWidget) { if (nullptr != tmpWidget) {
EWOL_DEBUG("Find widget named : \"" << _subWidgetName << "\" register event=\"" << _eventId << "\""); EWOL_DEBUG("Find widget named : \"" << _subWidgetName << "\" register event=\"" << _eventId << "\"");
tmpWidget->registerOnEvent(_destinationObject, _eventId, _eventIdgenerated, _overloadData); tmpWidget->registerOnEvent(_destinationObject, _eventId, _eventIdgenerated, _overloadData);
} else { } else {

View File

@ -40,7 +40,7 @@ namespace ewol {
/** /**
* @brief Destructor * @brief Destructor
*/ */
~Composer(); virtual ~Composer();
/** /**
* @brief load a composition with a file * @brief load a composition with a file
* @param[in] _fileName Name of the file * @param[in] _fileName Name of the file
@ -66,7 +66,7 @@ namespace ewol {
*/ */
void registerOnEventNameWidget(const std::string& _subWidgetName, void registerOnEventNameWidget(const std::string& _subWidgetName,
const char * _eventId, const char * _eventId,
const char * _eventIdgenerated = NULL, const char * _eventIdgenerated = nullptr,
const std::string& _overloadData=""); const std::string& _overloadData="");
public: public:
/** /**
@ -78,10 +78,10 @@ namespace ewol {
* @param[in] _overloadData When the user prever to receive a data specificly for this event ... * @param[in] _overloadData When the user prever to receive a data specificly for this event ...
* @note : To used when NOT herited from this object. * @note : To used when NOT herited from this object.
*/ */
void registerOnEventNameWidget(ewol::Object * _destinationObject, void registerOnEventNameWidget(const ewol::object::Shared<ewol::Object>& _destinationObject,
const std::string& _subWidgetName, const std::string& _subWidgetName,
const char * _eventId, const char * _eventId,
const char * _eventIdgenerated = NULL, const char * _eventIdgenerated = nullptr,
const std::string& _overloadData=""); const std::string& _overloadData="");
}; };
}; };

View File

@ -16,7 +16,7 @@
#define __class__ "Container" #define __class__ "Container"
ewol::widget::Container::Container(ewol::Widget* _subElement) : ewol::widget::Container::Container(ewol::object::Shared<ewol::Widget> _subElement) :
m_subWidget(_subElement) { m_subWidget(_subElement) {
addObjectType("ewol::widget::Container"); addObjectType("ewol::widget::Container");
// nothing to do ... // nothing to do ...
@ -26,17 +26,17 @@ ewol::widget::Container::~Container() {
subWidgetRemove(); subWidgetRemove();
} }
ewol::Widget* ewol::widget::Container::getSubWidget() { ewol::object::Shared<ewol::Widget> ewol::widget::Container::getSubWidget() {
return m_subWidget; return m_subWidget;
} }
void ewol::widget::Container::setSubWidget(ewol::Widget* _newWidget) { void ewol::widget::Container::setSubWidget(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
return; return;
} }
subWidgetRemove(); subWidgetRemove();
m_subWidget = _newWidget; m_subWidget = _newWidget;
if (m_subWidget!=NULL) { if (m_subWidget!=nullptr) {
m_subWidget->setUpperWidget(this); m_subWidget->setUpperWidget(this);
} }
markToRedraw(); markToRedraw();
@ -44,36 +44,37 @@ void ewol::widget::Container::setSubWidget(ewol::Widget* _newWidget) {
} }
void ewol::widget::Container::subWidgetRemove() { void ewol::widget::Container::subWidgetRemove() {
if (NULL != m_subWidget) { if (nullptr != m_subWidget) {
m_subWidget->removeUpperWidget(); m_subWidget->removeUpperWidget();
m_subWidget->removeObject(); m_subWidget->removeObject();
m_subWidget=NULL; m_subWidget.reset();
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
} }
void ewol::widget::Container::subWidgetUnLink() { void ewol::widget::Container::subWidgetUnLink() {
if (NULL != m_subWidget) { if (nullptr != m_subWidget) {
m_subWidget->removeUpperWidget(); m_subWidget->removeUpperWidget();
} }
m_subWidget=NULL; m_subWidget.reset();
} }
ewol::Widget* ewol::widget::Container::getWidgetNamed(const std::string& _widgetName) { ewol::object::Shared<ewol::Widget> ewol::widget::Container::getWidgetNamed(const std::string& _widgetName) {
ewol::Widget* tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); ewol::object::Shared<ewol::Widget> tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName);
if (NULL!=tmpUpperWidget) { if (nullptr!=tmpUpperWidget) {
return tmpUpperWidget; return tmpUpperWidget;
} }
if (NULL != m_subWidget) { if (nullptr != m_subWidget) {
return m_subWidget->getWidgetNamed(_widgetName); return m_subWidget->getWidgetNamed(_widgetName);
} }
return NULL; return nullptr;
} }
void ewol::widget::Container::onObjectRemove(ewol::Object* _removeObject) { void ewol::widget::Container::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
if (m_subWidget == _removeObject) { ewol::Widget::onObjectRemove(_object);
m_subWidget=NULL; if (m_subWidget == _object) {
m_subWidget.reset();
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
@ -85,7 +86,7 @@ void ewol::widget::Container::systemDraw(const ewol::DrawProperty& _displayProp)
return; return;
} }
ewol::Widget::systemDraw(_displayProp); ewol::Widget::systemDraw(_displayProp);
if (NULL!=m_subWidget) { if (nullptr!=m_subWidget) {
ewol::DrawProperty prop = _displayProp; ewol::DrawProperty prop = _displayProp;
prop.limit(m_origin, m_size); prop.limit(m_origin, m_size);
m_subWidget->systemDraw(prop); m_subWidget->systemDraw(prop);
@ -93,7 +94,7 @@ void ewol::widget::Container::systemDraw(const ewol::DrawProperty& _displayProp)
} }
void ewol::widget::Container::calculateSize(const vec2& _availlable) { void ewol::widget::Container::calculateSize(const vec2& _availlable) {
if (NULL!=m_subWidget) { if (nullptr!=m_subWidget) {
vec2 origin = m_origin+m_offset; vec2 origin = m_origin+m_offset;
vec2 minSize = m_subWidget->getCalculateMinSize(); vec2 minSize = m_subWidget->getCalculateMinSize();
bvec2 expand = m_subWidget->getExpand(); bvec2 expand = m_subWidget->getExpand();
@ -123,7 +124,7 @@ void ewol::widget::Container::calculateMinMaxSize() {
// call main class // call main class
ewol::Widget::calculateMinMaxSize(); ewol::Widget::calculateMinMaxSize();
// call sub classes // call sub classes
if (NULL!=m_subWidget) { if (nullptr!=m_subWidget) {
m_subWidget->calculateMinMaxSize(); m_subWidget->calculateMinMaxSize();
vec2 min = m_subWidget->getCalculateMinSize(); vec2 min = m_subWidget->getCalculateMinSize();
m_minSize.setMax(min); m_minSize.setMax(min);
@ -132,23 +133,23 @@ void ewol::widget::Container::calculateMinMaxSize() {
} }
void ewol::widget::Container::onRegenerateDisplay() { void ewol::widget::Container::onRegenerateDisplay() {
if (NULL!=m_subWidget) { if (nullptr!=m_subWidget) {
m_subWidget->onRegenerateDisplay(); m_subWidget->onRegenerateDisplay();
} }
} }
ewol::Widget* ewol::widget::Container::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::Container::getWidgetAtPos(const vec2& _pos) {
if (false == isHide()) { if (false == isHide()) {
if (NULL!=m_subWidget) { if (nullptr!=m_subWidget) {
return m_subWidget->getWidgetAtPos(_pos); return m_subWidget->getWidgetAtPos(_pos);
} }
} }
return NULL; return nullptr;
}; };
bool ewol::widget::Container::loadXML(exml::Element* _node) { bool ewol::widget::Container::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
// parse generic properties : // parse generic properties :
@ -159,7 +160,7 @@ bool ewol::widget::Container::loadXML(exml::Element* _node) {
// parse all the elements : // parse all the elements :
for(size_t iii=0; iii< _node->size(); iii++) { for(size_t iii=0; iii< _node->size(); iii++) {
exml::Element* pNode = _node->getElement(iii); exml::Element* pNode = _node->getElement(iii);
if (pNode == NULL) { if (pNode == nullptr) {
// trash here all that is not element // trash here all that is not element
continue; continue;
} }
@ -168,13 +169,13 @@ bool ewol::widget::Container::loadXML(exml::Element* _node) {
EWOL_ERROR("(l "<<pNode->getPos()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << getWidgetManager().list() << "]" ); EWOL_ERROR("(l "<<pNode->getPos()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << getWidgetManager().list() << "]" );
continue; continue;
} }
if (NULL != getSubWidget()) { if (nullptr != getSubWidget()) {
EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue; continue;
} }
EWOL_DEBUG("try to create subwidget : '" << widgetName << "'"); EWOL_DEBUG("try to create subwidget : '" << widgetName << "'");
ewol::Widget* tmpWidget = getWidgetManager().create(widgetName); ewol::object::Shared<ewol::Widget> tmpWidget = getWidgetManager().create(widgetName);
if (tmpWidget == NULL) { if (tmpWidget == nullptr) {
EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\""); EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\"");
continue; continue;
} }

View File

@ -21,27 +21,27 @@ namespace ewol {
*/ */
class Container : public ewol::Widget { class Container : public ewol::Widget {
protected: protected:
ewol::Widget* m_subWidget; ewol::object::Owner<ewol::Widget> m_subWidget;
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
Container(ewol::Widget* _subElement=NULL); Container(ewol::object::Shared<ewol::Widget> _subElement=nullptr);
/** /**
* @brief Destructor * @brief Destructor
*/ */
~Container(); virtual ~Container();
public: public:
/** /**
* @brief get the main node widget * @brief get the main node widget
* @return the requested pointer on the node * @return the requested pointer on the node
*/ */
ewol::Widget* getSubWidget(); ewol::object::Shared<ewol::Widget> getSubWidget();
/** /**
* @brief set the subWidget node widget. * @brief set the subWidget node widget.
* @param[in] _newWidget The widget to add. * @param[in] _newWidget The widget to add.
*/ */
void setSubWidget(ewol::Widget* _newWidget); void setSubWidget(ewol::object::Shared<ewol::Widget> _newWidget);
/** /**
* @brief remove the subWidget node (async). * @brief remove the subWidget node (async).
*/ */
@ -54,11 +54,11 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void onObjectRemove(ewol::Object* _removeObject); virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
virtual void calculateSize(const vec2& _availlable); virtual void calculateSize(const vec2& _availlable);
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual ewol::Widget* getWidgetAtPos(const vec2& _pos); virtual ewol::object::Shared<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual ewol::Widget* getWidgetNamed(const std::string& _widgetName); virtual ewol::object::Shared<ewol::Widget> getWidgetNamed(const std::string& _widgetName);
virtual bool loadXML(exml::Element* _node); virtual bool loadXML(exml::Element* _node);
virtual void setOffset(const vec2& _newVal); virtual void setOffset(const vec2& _newVal);
}; };

View File

@ -16,7 +16,7 @@
#define __class__ "Container2" #define __class__ "Container2"
ewol::widget::Container2::Container2(ewol::Widget* _subElement, ewol::Widget* _subElementToggle) : ewol::widget::Container2::Container2(ewol::object::Shared<ewol::Widget> _subElement, ewol::object::Shared<ewol::Widget> _subElementToggle) :
m_idWidgetDisplayed(0) { m_idWidgetDisplayed(0) {
m_subWidget[0] = _subElement; m_subWidget[0] = _subElement;
m_subWidget[1] = _subElementToggle; m_subWidget[1] = _subElementToggle;
@ -29,10 +29,10 @@ ewol::widget::Container2::~Container2() {
subWidgetRemoveToggle(); subWidgetRemoveToggle();
} }
void ewol::widget::Container2::setSubWidget(ewol::Widget* _newWidget, int32_t _idWidget) { void ewol::widget::Container2::setSubWidget(ewol::object::Shared<ewol::Widget> _newWidget, int32_t _idWidget) {
subWidgetRemove(_idWidget); subWidgetRemove(_idWidget);
m_subWidget[_idWidget] = _newWidget; m_subWidget[_idWidget] = _newWidget;
if (m_subWidget[_idWidget] != NULL) { if (m_subWidget[_idWidget] != nullptr) {
EWOL_VERBOSE("Add widget : " << _idWidget); EWOL_VERBOSE("Add widget : " << _idWidget);
m_subWidget[_idWidget]->setUpperWidget(this); m_subWidget[_idWidget]->setUpperWidget(this);
} }
@ -42,46 +42,46 @@ void ewol::widget::Container2::setSubWidget(ewol::Widget* _newWidget, int32_t _i
void ewol::widget::Container2::subWidgetRemove(int32_t _idWidget) { void ewol::widget::Container2::subWidgetRemove(int32_t _idWidget) {
if (m_subWidget[_idWidget] != NULL) { if (m_subWidget[_idWidget] != nullptr) {
EWOL_VERBOSE("Remove widget : " << _idWidget); EWOL_VERBOSE("Remove widget : " << _idWidget);
m_subWidget[_idWidget]->removeUpperWidget(); m_subWidget[_idWidget]->removeUpperWidget();
m_subWidget[_idWidget]->removeObject(); m_subWidget[_idWidget].reset();
m_subWidget[_idWidget] = NULL;
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
} }
void ewol::widget::Container2::subWidgetUnLink(int32_t _idWidget) { void ewol::widget::Container2::subWidgetUnLink(int32_t _idWidget) {
if (m_subWidget[_idWidget] != NULL) { if (m_subWidget[_idWidget] != nullptr) {
m_subWidget[_idWidget]->removeUpperWidget(); m_subWidget[_idWidget]->removeUpperWidget();
EWOL_VERBOSE("Unlink widget : " << _idWidget); EWOL_VERBOSE("Unlink widget : " << _idWidget);
} }
m_subWidget[_idWidget] = NULL; m_subWidget[_idWidget].resetShared();
} }
ewol::Widget* ewol::widget::Container2::getWidgetNamed(const std::string& _widgetName) { ewol::object::Shared<ewol::Widget> ewol::widget::Container2::getWidgetNamed(const std::string& _widgetName) {
ewol::Widget* tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); ewol::object::Shared<ewol::Widget> tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName);
if (tmpUpperWidget != NULL) { if (tmpUpperWidget != nullptr) {
return tmpUpperWidget; return tmpUpperWidget;
} }
if (m_subWidget[0] != NULL) { if (m_subWidget[0] != nullptr) {
return m_subWidget[0]->getWidgetNamed(_widgetName); return m_subWidget[0]->getWidgetNamed(_widgetName);
} }
if (m_subWidget[1] != NULL) { if (m_subWidget[1] != nullptr) {
return m_subWidget[1]->getWidgetNamed(_widgetName); return m_subWidget[1]->getWidgetNamed(_widgetName);
} }
return NULL; return nullptr;
} }
void ewol::widget::Container2::onObjectRemove(ewol::Object* _removeObject) { void ewol::widget::Container2::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
if (m_subWidget[0] == _removeObject) { ewol::Widget::onObjectRemove(_object);
m_subWidget[0] = NULL; if (m_subWidget[0] == _object) {
m_subWidget[0].reset();
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
if (m_subWidget[1] == _removeObject) { if (m_subWidget[1] == _object) {
m_subWidget[1] = NULL; m_subWidget[1].reset();
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
@ -93,7 +93,7 @@ void ewol::widget::Container2::systemDraw(const ewol::DrawProperty& _displayProp
return; return;
} }
ewol::Widget::systemDraw(_displayProp); ewol::Widget::systemDraw(_displayProp);
if (m_subWidget[m_idWidgetDisplayed] != NULL) { if (m_subWidget[m_idWidgetDisplayed] != nullptr) {
m_subWidget[m_idWidgetDisplayed]->systemDraw(_displayProp); m_subWidget[m_idWidgetDisplayed]->systemDraw(_displayProp);
} }
} }
@ -119,7 +119,7 @@ ewol::Padding ewol::widget::Container2::calculateSizePadded(const vec2& _availla
vec2 origin = (m_size - subElementSize)*0.5f + vec2(_padding.xLeft(), _padding.yButtom()); vec2 origin = (m_size - subElementSize)*0.5f + vec2(_padding.xLeft(), _padding.yButtom());
subElementSize -= vec2(_padding.x(), _padding.y()); subElementSize -= vec2(_padding.x(), _padding.y());
for (size_t iii = 0; iii < 2; ++iii) { for (size_t iii = 0; iii < 2; ++iii) {
if (m_subWidget[iii] != NULL) { if (m_subWidget[iii] != nullptr) {
vec2 origin2 = origin+m_offset; vec2 origin2 = origin+m_offset;
vec2 minSize = m_subWidget[iii]->getCalculateMinSize(); vec2 minSize = m_subWidget[iii]->getCalculateMinSize();
bvec2 expand = m_subWidget[iii]->getExpand(); bvec2 expand = m_subWidget[iii]->getExpand();
@ -154,7 +154,7 @@ void ewol::widget::Container2::calculateMinMaxSizePadded(const ewol::Padding& _p
m_minSize = vec2(0,0); m_minSize = vec2(0,0);
// call sub classes // call sub classes
for (size_t iii = 0; iii < 2; ++iii) { for (size_t iii = 0; iii < 2; ++iii) {
if (m_subWidget[iii] != NULL) { if (m_subWidget[iii] != nullptr) {
m_subWidget[iii]->calculateMinMaxSize(); m_subWidget[iii]->calculateMinMaxSize();
vec2 min = m_subWidget[iii]->getCalculateMinSize(); vec2 min = m_subWidget[iii]->getCalculateMinSize();
m_minSize.setMax(min); m_minSize.setMax(min);
@ -168,23 +168,23 @@ void ewol::widget::Container2::calculateMinMaxSizePadded(const ewol::Padding& _p
} }
void ewol::widget::Container2::onRegenerateDisplay() { void ewol::widget::Container2::onRegenerateDisplay() {
if (m_subWidget[m_idWidgetDisplayed] != NULL) { if (m_subWidget[m_idWidgetDisplayed] != nullptr) {
m_subWidget[m_idWidgetDisplayed]->onRegenerateDisplay(); m_subWidget[m_idWidgetDisplayed]->onRegenerateDisplay();
} }
} }
/* /*
ewol::Widget* ewol::widget::Container2::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::Container2::getWidgetAtPos(const vec2& _pos) {
if (isHide() == false) { if (isHide() == false) {
if (m_subWidget[m_idWidgetDisplayed] != NULL) { if (m_subWidget[m_idWidgetDisplayed] != nullptr) {
return m_subWidget[m_idWidgetDisplayed]->getWidgetAtPos(_pos); return m_subWidget[m_idWidgetDisplayed]->getWidgetAtPos(_pos);
} }
} }
return NULL; return nullptr;
} }
*/ */
bool ewol::widget::Container2::loadXML(exml::Element* _node) { bool ewol::widget::Container2::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
// parse generic properties : // parse generic properties :
@ -195,7 +195,7 @@ bool ewol::widget::Container2::loadXML(exml::Element* _node) {
// parse all the elements : // parse all the elements :
for(size_t iii=0; iii< _node->size(); iii++) { for(size_t iii=0; iii< _node->size(); iii++) {
exml::Element* pNode = _node->getElement(iii); exml::Element* pNode = _node->getElement(iii);
if (pNode == NULL) { if (pNode == nullptr) {
// trash here all that is not element // trash here all that is not element
continue; continue;
} }
@ -205,16 +205,16 @@ bool ewol::widget::Container2::loadXML(exml::Element* _node) {
continue; continue;
} }
bool toogleMode=false; bool toogleMode=false;
if (NULL != getSubWidget()) { if (nullptr != getSubWidget()) {
toogleMode=true; toogleMode=true;
if (NULL != getSubWidgetToggle()) { if (nullptr != getSubWidgetToggle()) {
EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" );
continue; continue;
} }
} }
EWOL_DEBUG("try to create subwidget : '" << widgetName << "'"); EWOL_DEBUG("try to create subwidget : '" << widgetName << "'");
ewol::Widget* tmpWidget = getWidgetManager().create(widgetName); ewol::object::Shared<ewol::Widget> tmpWidget = getWidgetManager().create(widgetName);
if (tmpWidget == NULL) { if (tmpWidget == nullptr) {
EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\""); EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\"");
continue; continue;
} }

View File

@ -22,7 +22,7 @@ namespace ewol {
*/ */
class Container2 : public ewol::Widget { class Container2 : public ewol::Widget {
protected: protected:
ewol::Widget* m_subWidget[2]; //!< 2 subwidget possible ewol::object::Owner<ewol::Widget> m_subWidget[2]; //!< 2 subwidget possible
int32_t m_idWidgetDisplayed; //!< current widget displayed int32_t m_idWidgetDisplayed; //!< current widget displayed
public: public:
/** /**
@ -30,31 +30,31 @@ namespace ewol {
* @param[in] _subElement Widget to set on the normal position * @param[in] _subElement Widget to set on the normal position
* @param[in] _subElementToggle Widget to set on the toggle position * @param[in] _subElementToggle Widget to set on the toggle position
*/ */
Container2(ewol::Widget* _subElement = NULL, ewol::Widget* _subElementToggle = NULL); Container2(ewol::object::Shared<ewol::Widget> _subElement = nullptr, ewol::object::Shared<ewol::Widget> _subElementToggle = nullptr);
/** /**
* @brief Destructor * @brief Destructor
*/ */
~Container2(); virtual ~Container2();
private: private:
/** /**
* @brief Specify the current widget * @brief Specify the current widget
* @param[in] _subWidget Widget to add normal * @param[in] _subWidget Widget to add normal
* @param[in] _idWidget Id of the widget to set * @param[in] _idWidget Id of the widget to set
*/ */
void setSubWidget(ewol::Widget* _subWidget, int32_t _idWidget); void setSubWidget(ewol::object::Shared<ewol::Widget> _subWidget, int32_t _idWidget);
public: public:
/** /**
* @brief Specify the current widget * @brief Specify the current widget
* @param[in] _subWidget Widget to add normal * @param[in] _subWidget Widget to add normal
*/ */
void setSubWidget(ewol::Widget* _subWidget) { void setSubWidget(ewol::object::Shared<ewol::Widget> _subWidget) {
setSubWidget(_subWidget, 0); setSubWidget(_subWidget, 0);
} }
/** /**
* @brief Specify the current toggle widget * @brief Specify the current toggle widget
* @param[in] _subWidget Widget to add Toggle * @param[in] _subWidget Widget to add Toggle
*/ */
void setSubWidgetToggle(ewol::Widget* _subWidget) { void setSubWidgetToggle(ewol::object::Shared<ewol::Widget> _subWidget) {
setSubWidget(_subWidget, 1); setSubWidget(_subWidget, 1);
} }
private: private:
@ -63,7 +63,7 @@ namespace ewol {
* @param[in] _idWidget Id of the widget to set * @param[in] _idWidget Id of the widget to set
* @return The base widget * @return The base widget
*/ */
ewol::Widget* getSubWidget(int32_t _idWidget) const { ewol::object::Shared<ewol::Widget> getSubWidget(int32_t _idWidget) const {
return m_subWidget[_idWidget]; return m_subWidget[_idWidget];
}; };
public: public:
@ -71,14 +71,14 @@ namespace ewol {
* @brief get the current displayed composition * @brief get the current displayed composition
* @return The base widget * @return The base widget
*/ */
ewol::Widget* getSubWidget() const { ewol::object::Shared<ewol::Widget> getSubWidget() const {
return getSubWidget(0); return getSubWidget(0);
}; };
/** /**
* @brief get the current displayed composition * @brief get the current displayed composition
* @return The toggle widget * @return The toggle widget
*/ */
ewol::Widget* getSubWidgetToggle() const { ewol::object::Shared<ewol::Widget> getSubWidgetToggle() const {
return getSubWidget(1); return getSubWidget(1);
}; };
private: private:
@ -144,7 +144,7 @@ namespace ewol {
* @return the id of the widget displayable * @return the id of the widget displayable
*/ */
int32_t convertId(int32_t _id) { int32_t convertId(int32_t _id) {
if (m_subWidget[_id] == NULL) { if (m_subWidget[_id] == nullptr) {
return (_id+1)%2; return (_id+1)%2;
} }
return _id; return _id;
@ -152,15 +152,15 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void onObjectRemove(ewol::Object* _removeObject); virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
virtual void calculateSize(const vec2& _availlable) { virtual void calculateSize(const vec2& _availlable) {
calculateSizePadded(_availlable); calculateSizePadded(_availlable);
} }
virtual void calculateMinMaxSize() { virtual void calculateMinMaxSize() {
calculateMinMaxSizePadded(); calculateMinMaxSizePadded();
} }
//virtual ewol::Widget* getWidgetAtPos(const vec2& _pos); //virtual ewol::object::Shared<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual ewol::Widget* getWidgetNamed(const std::string& _widgetName); virtual ewol::object::Shared<ewol::Widget> getWidgetNamed(const std::string& _widgetName);
virtual bool loadXML(exml::Element* _node); virtual bool loadXML(exml::Element* _node);
virtual void setOffset(const vec2& _newVal); virtual void setOffset(const vec2& _newVal);
}; };

View File

@ -52,12 +52,12 @@ void ewol::widget::ContainerN::lockExpand(const bvec2& _lockExpand) {
} }
int32_t ewol::widget::ContainerN::subWidgetAdd(ewol::Widget* _newWidget) { int32_t ewol::widget::ContainerN::subWidgetAdd(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} Try to add An empty Widget ... "); EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} Try to add An empty Widget ... ");
return -1; return -1;
} }
if (_newWidget!=NULL) { if (_newWidget!=nullptr) {
_newWidget->setUpperWidget(this); _newWidget->setUpperWidget(this);
} }
m_subWidget.push_back(_newWidget); m_subWidget.push_back(_newWidget);
@ -67,12 +67,12 @@ int32_t ewol::widget::ContainerN::subWidgetAdd(ewol::Widget* _newWidget) {
return _newWidget->getId(); return _newWidget->getId();
} }
int32_t ewol::widget::ContainerN::subWidgetAddStart(ewol::Widget* _newWidget) { int32_t ewol::widget::ContainerN::subWidgetAddStart(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} Try to add start An empty Widget ... "); EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} Try to add start An empty Widget ... ");
return -1; return -1;
} }
if (_newWidget!=NULL) { if (_newWidget!=nullptr) {
_newWidget->setUpperWidget(this); _newWidget->setUpperWidget(this);
} }
m_subWidget.insert(m_subWidget.begin(), _newWidget); m_subWidget.insert(m_subWidget.begin(), _newWidget);
@ -81,21 +81,15 @@ int32_t ewol::widget::ContainerN::subWidgetAddStart(ewol::Widget* _newWidget) {
return _newWidget->getId(); return _newWidget->getId();
} }
void ewol::widget::ContainerN::subWidgetRemove(ewol::Widget* _newWidget) { void ewol::widget::ContainerN::subWidgetRemove(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
return; return;
} }
size_t errorControl = m_subWidget.size(); size_t errorControl = m_subWidget.size();
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto it(m_subWidget.begin()) ; it != m_subWidget.end() ; ++it) {
if (_newWidget == m_subWidget[iii]) { if (_newWidget == *it) {
m_subWidget[iii]->removeUpperWidget(); (*it)->removeUpperWidget();
m_subWidget[iii]->removeObject(); m_subWidget.erase(it);
// no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ...
if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] {" << getObjectType() << "} The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii] = NULL;
m_subWidget.erase(m_subWidget.begin()+iii);
}
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
return; return;
@ -103,15 +97,15 @@ void ewol::widget::ContainerN::subWidgetRemove(ewol::Widget* _newWidget) {
} }
} }
void ewol::widget::ContainerN::subWidgetUnLink(ewol::Widget* _newWidget) { void ewol::widget::ContainerN::subWidgetUnLink(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
return; return;
} }
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto it(m_subWidget.begin()) ; it != m_subWidget.end() ; ++it) {
if (_newWidget == m_subWidget[iii]) { if (_newWidget == *it) {
m_subWidget[iii]->removeUpperWidget(); (*it)->removeUpperWidget();
m_subWidget[iii] = NULL; (*it).resetShared();
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(it);
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
return; return;
@ -120,65 +114,45 @@ void ewol::widget::ContainerN::subWidgetUnLink(ewol::Widget* _newWidget) {
} }
void ewol::widget::ContainerN::subWidgetRemoveAll() { void ewol::widget::ContainerN::subWidgetRemoveAll() {
size_t errorControl = m_subWidget.size(); for (auto &it : m_subWidget) {
// the size automaticly decrement with the auto call of the onObjectRemove function if (it != nullptr) {
while (m_subWidget.size() > 0 ) { it->removeUpperWidget();
if (NULL != m_subWidget[0]) {
m_subWidget[0]->removeUpperWidget();
m_subWidget[0]->removeObject();
// no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ...
if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] {" << getObjectType() << "} The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[0] = NULL;
} }
} else {
EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Must not have null pointer on the subWidget list ...");
m_subWidget.erase(m_subWidget.begin());
}
errorControl = m_subWidget.size();
} }
m_subWidget.clear(); m_subWidget.clear();
} }
void ewol::widget::ContainerN::subWidgetRemoveAllDelayed() { void ewol::widget::ContainerN::subWidgetRemoveAllDelayed() {
// the size automaticly decrement with the auto call of the onObjectRemove function subWidgetRemoveAll();
for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (NULL != m_subWidget[iii]) {
m_subWidget[iii]->removeUpperWidget();
m_subWidget[iii]->removeObject();
m_subWidget[iii] = NULL;
} else {
EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Must not have null pointer on the subWidget list ...");
}
}
m_subWidget.clear();
} }
ewol::Widget* ewol::widget::ContainerN::getWidgetNamed(const std::string& _widgetName) { ewol::object::Shared<ewol::Widget> ewol::widget::ContainerN::getWidgetNamed(const std::string& _widgetName) {
ewol::Widget* tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName); ewol::object::Shared<ewol::Widget> tmpUpperWidget = ewol::Widget::getWidgetNamed(_widgetName);
if (NULL!=tmpUpperWidget) { if (tmpUpperWidget != nullptr) {
return tmpUpperWidget; return tmpUpperWidget;
} }
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it != nullptr) {
ewol::Widget* tmpWidget = m_subWidget[iii]->getWidgetNamed(_widgetName); ewol::object::Shared<ewol::Widget> tmpWidget = it->getWidgetNamed(_widgetName);
if (NULL != tmpWidget) { if (tmpWidget != nullptr) {
return tmpWidget; return tmpWidget;
} }
} }
} }
return NULL; return nullptr;
} }
void ewol::widget::ContainerN::onObjectRemove(ewol::Object* _removeObject) { void ewol::widget::ContainerN::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
// First step call parrent : // First step call parrent :
ewol::Widget::onObjectRemove(_removeObject); ewol::Widget::onObjectRemove(_object);
// second step find if in all the elements ... // second step find if in all the elements ...
for (int64_t iii=m_subWidget.size()-1; iii >= 0; iii--) { auto it(m_subWidget.begin());
if(m_subWidget[iii] == _removeObject) { while (it != m_subWidget.end()) {
EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} remove sizer sub Element [" << iii << "/" << m_subWidget.size()-1 << "] == > destroyed object"); if(*it == _object) {
m_subWidget[iii] = NULL; m_subWidget.erase(it);
m_subWidget.erase(m_subWidget.begin()+iii); it = m_subWidget.begin();
} else {
++it;
} }
} }
} }
@ -193,19 +167,19 @@ void ewol::widget::ContainerN::systemDraw(const ewol::DrawProperty& _displayProp
// subwidget draw // subwidget draw
ewol::DrawProperty prop = _displayProp; ewol::DrawProperty prop = _displayProp;
prop.limit(m_origin, m_size); prop.limit(m_origin, m_size);
for (int64_t iii=m_subWidget.size()-1; iii >= 0; iii--) { for (auto it(m_subWidget.rbegin()); it!=m_subWidget.rend(); ++it) {
if (NULL != m_subWidget[iii]) { if (*it != nullptr) {
m_subWidget[iii]->systemDraw(prop); (*it)->systemDraw(prop);
} }
} }
} }
void ewol::widget::ContainerN::calculateSize(const vec2& _availlable) { void ewol::widget::ContainerN::calculateSize(const vec2& _availlable) {
m_size = _availlable; m_size = _availlable;
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it != nullptr) {
m_subWidget[iii]->setOrigin(m_origin+m_offset); it->setOrigin(m_origin+m_offset);
m_subWidget[iii]->calculateSize(m_size); it->calculateSize(m_size);
} }
} }
markToRedraw(); markToRedraw();
@ -216,17 +190,17 @@ void ewol::widget::ContainerN::calculateMinMaxSize() {
m_minSize.setValue(0,0); m_minSize.setValue(0,0);
m_maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE); m_maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE);
//EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} set min size : " << m_minSize); //EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} set min size : " << m_minSize);
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it != nullptr) {
m_subWidget[iii]->calculateMinMaxSize(); it->calculateMinMaxSize();
bvec2 subExpendProp = m_subWidget[iii]->canExpand(); bvec2 subExpendProp = it->canExpand();
if (true == subExpendProp.x()) { if (true == subExpendProp.x()) {
m_subExpend.setX(true); m_subExpend.setX(true);
} }
if (true == subExpendProp.y()) { if (true == subExpendProp.y()) {
m_subExpend.setY(true); m_subExpend.setY(true);
} }
vec2 tmpSize = m_subWidget[iii]->getCalculateMinSize(); vec2 tmpSize = it->getCalculateMinSize();
m_minSize.setValue( etk_max(tmpSize.x(), m_minSize.x()), m_minSize.setValue( etk_max(tmpSize.x(), m_minSize.x()),
etk_max(tmpSize.y(), m_minSize.y()) ); etk_max(tmpSize.y(), m_minSize.y()) );
} }
@ -235,27 +209,27 @@ void ewol::widget::ContainerN::calculateMinMaxSize() {
} }
void ewol::widget::ContainerN::onRegenerateDisplay() { void ewol::widget::ContainerN::onRegenerateDisplay() {
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it != nullptr) {
m_subWidget[iii]->onRegenerateDisplay(); it->onRegenerateDisplay();
} }
} }
} }
ewol::Widget* ewol::widget::ContainerN::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::ContainerN::getWidgetAtPos(const vec2& _pos) {
if (true == isHide()) { if (true == isHide()) {
return NULL; return nullptr;
} }
// for all element in the sizer ... // for all element in the sizer ...
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it != nullptr) {
vec2 tmpSize = m_subWidget[iii]->getSize(); vec2 tmpSize = it->getSize();
vec2 tmpOrigin = m_subWidget[iii]->getOrigin(); vec2 tmpOrigin = it->getOrigin();
if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x())
&& (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) )
{ {
ewol::Widget * tmpWidget = m_subWidget[iii]->getWidgetAtPos(_pos); ewol::object::Shared<ewol::Widget> tmpWidget = it->getWidgetAtPos(_pos);
if (NULL != tmpWidget) { if (nullptr != tmpWidget) {
return tmpWidget; return tmpWidget;
} }
// stop searching // stop searching
@ -263,12 +237,12 @@ ewol::Widget* ewol::widget::ContainerN::getWidgetAtPos(const vec2& _pos) {
} }
} }
} }
return NULL; return nullptr;
}; };
bool ewol::widget::ContainerN::loadXML(exml::Element* _node) { bool ewol::widget::ContainerN::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
// parse generic properties : // parse generic properties :
@ -288,7 +262,7 @@ bool ewol::widget::ContainerN::loadXML(exml::Element* _node) {
// parse all the elements : // parse all the elements :
for (size_t iii=0; iii < _node->size(); iii++) { for (size_t iii=0; iii < _node->size(); iii++) {
exml::Element* pNode = _node->getElement(iii); exml::Element* pNode = _node->getElement(iii);
if (pNode == NULL) { if (pNode == nullptr) {
// trash here all that is not element // trash here all that is not element
continue; continue;
} }
@ -298,8 +272,8 @@ bool ewol::widget::ContainerN::loadXML(exml::Element* _node) {
continue; continue;
} }
EWOL_DEBUG("[" << getId() << "] {" << getObjectType() << "} load new element : \"" << widgetName << "\""); EWOL_DEBUG("[" << getId() << "] {" << getObjectType() << "} load new element : \"" << widgetName << "\"");
ewol::Widget *subWidget = getWidgetManager().create(widgetName); ewol::object::Shared<ewol::Widget> subWidget = getWidgetManager().create(widgetName);
if (subWidget == NULL) { if (subWidget == nullptr) {
EWOL_ERROR ("[" << getId() << "] {" << getObjectType() << "} (l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\""); EWOL_ERROR ("[" << getId() << "] {" << getObjectType() << "} (l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\"");
continue; continue;
} }

View File

@ -12,6 +12,7 @@
#include <etk/types.h> #include <etk/types.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <list>
namespace ewol { namespace ewol {
namespace widget { namespace widget {
@ -21,7 +22,7 @@ namespace ewol {
*/ */
class ContainerN : public ewol::Widget { class ContainerN : public ewol::Widget {
protected: protected:
std::vector<ewol::Widget*> m_subWidget; std::list<ewol::object::Owner<ewol::Widget>> m_subWidget;
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -30,7 +31,7 @@ namespace ewol {
/** /**
* @brief Destructor * @brief Destructor
*/ */
~ContainerN(); virtual ~ContainerN();
protected: protected:
bvec2 m_lockExpand; //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget bvec2 m_lockExpand; //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget
bvec2 m_subExpend; //!< reference of the sub element expention requested. bvec2 m_subExpend; //!< reference of the sub element expention requested.
@ -56,13 +57,13 @@ namespace ewol {
* @param[in] _newWidget the element pointer * @param[in] _newWidget the element pointer
* @return the ID of the set element * @return the ID of the set element
*/ */
virtual int32_t subWidgetAdd(ewol::Widget* _newWidget); virtual int32_t subWidgetAdd(ewol::object::Shared<ewol::Widget> _newWidget);
//! @previous //! @previous
inline int32_t subWidgetAddBack(ewol::Widget* _newWidget) { inline int32_t subWidgetAddBack(ewol::object::Shared<ewol::Widget> _newWidget) {
return subWidgetAdd(_newWidget); return subWidgetAdd(_newWidget);
}; };
//! @previous //! @previous
inline int32_t subWidgetAddEnd(ewol::Widget* _newWidget) { inline int32_t subWidgetAddEnd(ewol::object::Shared<ewol::Widget> _newWidget) {
return subWidgetAdd(_newWidget); return subWidgetAdd(_newWidget);
}; };
/** /**
@ -70,29 +71,29 @@ namespace ewol {
* @param[in] _newWidget the element pointer * @param[in] _newWidget the element pointer
* @return the ID of the set element * @return the ID of the set element
*/ */
virtual int32_t subWidgetAddStart(ewol::Widget* _newWidget); virtual int32_t subWidgetAddStart(ewol::object::Shared<ewol::Widget> _newWidget);
//! @previous //! @previous
inline int32_t subWidgetAddFront(ewol::Widget* _newWidget) { inline int32_t subWidgetAddFront(ewol::object::Shared<ewol::Widget> _newWidget) {
return subWidgetAddStart(_newWidget); return subWidgetAddStart(_newWidget);
}; };
/** /**
* @brief remove definitly a widget from the system and this layer. * @brief remove definitly a widget from the system and this layer.
* @param[in] _newWidget the element pointer. * @param[in] _newWidget the element pointer.
*/ */
virtual void subWidgetRemove(ewol::Widget* _newWidget); virtual void subWidgetRemove(ewol::object::Shared<ewol::Widget> _newWidget);
/** /**
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...) * @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...)
* @param[in] _newWidget the element pointer. * @param[in] _newWidget the element pointer.
*/ */
virtual void subWidgetUnLink(ewol::Widget* _newWidget); virtual void subWidgetUnLink(ewol::object::Shared<ewol::Widget> _newWidget);
public:// Derived function public:// Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual void onObjectRemove(ewol::Object* _removeObject); virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object);
virtual void calculateSize(const vec2& _availlable); virtual void calculateSize(const vec2& _availlable);
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual ewol::Widget* getWidgetAtPos(const vec2& _pos); virtual ewol::object::Shared<ewol::Widget> getWidgetAtPos(const vec2& _pos);
virtual ewol::Widget* getWidgetNamed(const std::string& _widgetName); virtual ewol::object::Shared<ewol::Widget> getWidgetNamed(const std::string& _widgetName);
virtual bool loadXML(exml::Element* _node); virtual bool loadXML(exml::Element* _node);
virtual void setOffset(const vec2& _newVal); virtual void setOffset(const vec2& _newVal);
}; };

View File

@ -21,12 +21,12 @@ const char* const ewol::widget::ContextMenu::configArrowPosition = "arrow-positi
const char* const ewol::widget::ContextMenu::configArrowMode = "arrow-mode"; const char* const ewol::widget::ContextMenu::configArrowMode = "arrow-mode";
const char* const ewol::widget::ContextMenu::configShaper = "shaper"; const char* const ewol::widget::ContextMenu::configShaper = "shaper";
static ewol::Widget* Create() { static ewol::Widget* create() {
return new ewol::widget::ContextMenu(); return new ewol::widget::ContextMenu();
} }
void ewol::widget::ContextMenu::init(ewol::widget::Manager& _widgetManager) { void ewol::widget::ContextMenu::init(ewol::widget::Manager& _widgetManager) {
_widgetManager.addWidgetCreator(__class__,&Create); _widgetManager.addWidgetCreator(__class__, &create);
} }
@ -35,9 +35,9 @@ ewol::widget::ContextMenu::ContextMenu(const std::string& _shaperName) :
m_shaper(_shaperName) { m_shaper(_shaperName) {
addObjectType("ewol::widget::ContextMenu"); addObjectType("ewol::widget::ContextMenu");
// add basic configurations : // add basic configurations :
registerConfig(configArrowPosition, "vec2", NULL, "position of the arrow"); registerConfig(configArrowPosition, "vec2", nullptr, "position of the arrow");
registerConfig(configArrowMode, "list", "none;left;buttom;right;top", "Position of the arrow in the pop-up"); registerConfig(configArrowMode, "list", "none;left;buttom;right;top", "Position of the arrow in the pop-up");
registerConfig(configShaper, "string", NULL, "the display name for config file"); registerConfig(configShaper, "string", nullptr, "the display name for config file");
m_userExpand.setValue(false,false); m_userExpand.setValue(false,false);
@ -69,7 +69,7 @@ void ewol::widget::ContextMenu::calculateSize(const vec2& _availlable) {
m_size = _availlable; m_size = _availlable;
ewol::Padding padding = m_shaper.getPadding(); ewol::Padding padding = m_shaper.getPadding();
EWOL_VERBOSE("our origin=" << m_origin << " size=" << m_size); EWOL_VERBOSE("our origin=" << m_origin << " size=" << m_size);
if (NULL != m_subWidget) { if (nullptr != m_subWidget) {
vec2 subWidgetSize; vec2 subWidgetSize;
vec2 subWidgetOrigin; vec2 subWidgetOrigin;
subWidgetSize = m_subWidget->getCalculateMinSize(); subWidgetSize = m_subWidget->getCalculateMinSize();
@ -158,7 +158,7 @@ void ewol::widget::ContextMenu::onRegenerateDisplay() {
m_shaper.clear(); m_shaper.clear();
ewol::Padding padding = m_shaper.getPadding(); ewol::Padding padding = m_shaper.getPadding();
if (m_subWidget == NULL) { if (m_subWidget == nullptr) {
return; return;
} }
vec2 tmpSize = m_subWidget->getSize(); vec2 tmpSize = m_subWidget->getSize();
@ -216,7 +216,7 @@ void ewol::widget::ContextMenu::onRegenerateDisplay() {
bool ewol::widget::ContextMenu::onEventInput(const ewol::event::Input& _event) { bool ewol::widget::ContextMenu::onEventInput(const ewol::event::Input& _event) {
if (_event.getId() > 0) { if (_event.getId() > 0) {
if (NULL != ewol::widget::Container::getWidgetAtPos(_event.getPos())) { if (nullptr != ewol::widget::Container::getWidgetAtPos(_event.getPos())) {
return false; return false;
} }
if( _event.getStatus() == ewol::key::statusDown if( _event.getStatus() == ewol::key::statusDown
@ -241,9 +241,9 @@ void ewol::widget::ContextMenu::setPositionMark(enum markPosition _position, vec
markToRedraw(); markToRedraw();
} }
ewol::Widget* ewol::widget::ContextMenu::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::ContextMenu::getWidgetAtPos(const vec2& _pos) {
ewol::Widget* val = ewol::widget::Container::getWidgetAtPos(_pos); ewol::object::Shared<ewol::Widget> val = ewol::widget::Container::getWidgetAtPos(_pos);
if (NULL != val) { if (nullptr != val) {
return val; return val;
} }
return this; return this;

View File

@ -67,9 +67,9 @@ namespace ewol {
public: // Derived function public: // Derived function
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual bool onEventInput(const ewol::event::Input& _event); virtual bool onEventInput(const ewol::event::Input& _event);
virtual void calculateSize(const vec2& availlable); virtual void calculateSize(const vec2& _availlable);
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
virtual ewol::Widget* getWidgetAtPos(const vec2& pos); virtual ewol::object::Shared<ewol::Widget> getWidgetAtPos(const vec2& _pos);
}; };
}; };
}; };

View File

@ -73,10 +73,10 @@ ewol::widget::Entry::Entry(std::string _newData) :
shortCutAdd("ctrl+a", ewolEventEntrySelect, "ALL"); shortCutAdd("ctrl+a", ewolEventEntrySelect, "ALL");
shortCutAdd("ctrl+shift+a", ewolEventEntrySelect, "NONE"); shortCutAdd("ctrl+shift+a", ewolEventEntrySelect, "NONE");
registerConfig(configMaxChar, "int", NULL, "Maximum cgar that can be set on the Entry"); registerConfig(configMaxChar, "int", nullptr, "Maximum cgar that can be set on the Entry");
registerConfig(configRegExp, "string", NULL, "Control what it is write with a regular expression"); registerConfig(configRegExp, "string", nullptr, "Control what it is write with a regular expression");
registerConfig(configEmptyMessage, "string", NULL, "Text that is displayed when the Entry is empty (decorated text)"); registerConfig(configEmptyMessage, "string", nullptr, "Text that is displayed when the Entry is empty (decorated text)");
registerConfig(configValue, "string", NULL, "Value display in the entry (decorated text)"); registerConfig(configValue, "string", nullptr, "Value display in the entry (decorated text)");
setValue(_newData); setValue(_newData);
markToRedraw(); markToRedraw();

View File

@ -26,7 +26,7 @@ void ewol::widget::Gird::init(ewol::widget::Manager& _widgetManager) {
ewol::widget::Gird::Gird(int32_t _colNumber) : ewol::widget::Gird::Gird(int32_t _colNumber) :
m_sizeRow(0), m_sizeRow(0),
m_tmpWidget(NULL), m_tmpWidget(nullptr),
m_gavityButtom(true), m_gavityButtom(true),
m_borderSize(0,0) { m_borderSize(0,0) {
addObjectType("ewol::widget::Gird"); addObjectType("ewol::widget::Gird");
@ -59,7 +59,7 @@ void ewol::widget::Gird::calculateSize(const vec2& _availlable) {
m_size -= m_borderSize*2; m_size -= m_borderSize*2;
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (NULL != m_subWidget[iii].widget) { if (nullptr != m_subWidget[iii].widget) {
//calculate the origin : //calculate the origin :
vec2 tmpOrigin = m_origin + m_borderSize; vec2 tmpOrigin = m_origin + m_borderSize;
if (false == m_gavityButtom) { if (false == m_gavityButtom) {
@ -108,7 +108,7 @@ void ewol::widget::Gird::calculateMinMaxSize() {
// change of line : // change of line :
lastLineID = m_subWidget[iii].row; lastLineID = m_subWidget[iii].row;
} }
if (NULL != m_subWidget[iii].widget) { if (nullptr != m_subWidget[iii].widget) {
m_subWidget[iii].widget->calculateMinMaxSize(); m_subWidget[iii].widget->calculateMinMaxSize();
vec2 tmpSize = m_subWidget[iii].widget->getCalculateMinSize(); vec2 tmpSize = m_subWidget[iii].widget->getCalculateMinSize();
EWOL_DEBUG(" [" << iii << "] subWidgetMinSize=" << tmpSize); EWOL_DEBUG(" [" << iii << "] subWidgetMinSize=" << tmpSize);
@ -144,12 +144,11 @@ void ewol::widget::Gird::setColNumber(int32_t _colNumber) {
for (int64_t iii=m_subWidget.size(); iii >= 0; iii--) { for (int64_t iii=m_subWidget.size(); iii >= 0; iii--) {
if (m_subWidget[iii].col>(_colNumber-1)) { if (m_subWidget[iii].col>(_colNumber-1)) {
// out of bounds : must remove it ... // out of bounds : must remove it ...
if (m_subWidget[iii].widget != NULL) { if (m_subWidget[iii].widget != nullptr) {
delete (m_subWidget[iii].widget); m_subWidget[iii].widget.reset();
// no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ... // no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ...
if (errorControl == m_subWidget.size()) { if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function..."); EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii].widget = NULL;
} }
} else { } else {
EWOL_WARNING("[" << getId() << "] Must not have null pointer on the subWidget list ..."); EWOL_WARNING("[" << getId() << "] Must not have null pointer on the subWidget list ...");
@ -201,12 +200,11 @@ void ewol::widget::Gird::subWidgetRemoveAll() {
size_t errorControl = m_subWidget.size(); size_t errorControl = m_subWidget.size();
// the size automaticly decrement with the auto call of the onObjectRemove function // the size automaticly decrement with the auto call of the onObjectRemove function
while (m_subWidget.size() > 0 ) { while (m_subWidget.size() > 0 ) {
if (NULL != m_subWidget[0].widget) { if (nullptr != m_subWidget[0].widget) {
delete(m_subWidget[0].widget); m_subWidget[0].widget.reset();
// no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ... // no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ...
if (errorControl == m_subWidget.size()) { if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function..."); EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[0].widget = NULL;
} }
} else { } else {
EWOL_WARNING("[" << getId() << "] Must not have null pointer on the subWidget list ..."); EWOL_WARNING("[" << getId() << "] Must not have null pointer on the subWidget list ...");
@ -218,8 +216,8 @@ void ewol::widget::Gird::subWidgetRemoveAll() {
} }
void ewol::widget::Gird::subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::Widget* _newWidget) { void ewol::widget::Gird::subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
return; return;
} }
GirdProperties prop; GirdProperties prop;
@ -246,11 +244,11 @@ void ewol::widget::Gird::subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::Widg
// The element already exist == > replace it ... // The element already exist == > replace it ...
m_tmpWidget = m_subWidget[iii].widget; m_tmpWidget = m_subWidget[iii].widget;
m_subWidget[iii].widget = _newWidget; m_subWidget[iii].widget = _newWidget;
if (NULL != m_tmpWidget) { if (nullptr != m_tmpWidget) {
delete(m_tmpWidget); m_tmpWidget.reset();
if (m_tmpWidget != NULL) { if (m_tmpWidget != nullptr) {
EWOL_CRITICAL("[" << getId() << "] Error while replacing a widget ... == > never call when free"); EWOL_CRITICAL("[" << getId() << "] Error while replacing a widget ... == > never call when free");
m_tmpWidget = NULL; m_tmpWidget = nullptr;
} }
} }
} }
@ -260,21 +258,10 @@ void ewol::widget::Gird::subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::Widg
m_subWidget.push_back(prop); m_subWidget.push_back(prop);
} }
void ewol::widget::Gird::subWidgetRemove(ewol::Widget* _newWidget) void ewol::widget::Gird::subWidgetRemove(ewol::object::Shared<ewol::Widget> _newWidget) {
{
if (NULL == _newWidget) {
return;
}
size_t errorControl = m_subWidget.size();
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (_newWidget == m_subWidget[iii].widget) { if (_newWidget == m_subWidget[iii].widget) {
delete(m_subWidget[iii].widget);
// no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ...
if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii].widget = NULL;
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(m_subWidget.begin()+iii);
}
return; return;
} }
} }
@ -291,33 +278,19 @@ void ewol::widget::Gird::subWidgetRemove(int32_t _colId, int32_t _rowId) {
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if( m_subWidget[iii].row == _rowId if( m_subWidget[iii].row == _rowId
&& m_subWidget[iii].col == _colId) { && m_subWidget[iii].col == _colId) {
if (m_subWidget[iii].widget == NULL) {
EWOL_WARNING("[" << getId() << "] remove NULL widget");
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(m_subWidget.begin()+iii);
} else {
// The element already exist == > replace it ...
if (m_subWidget[iii].widget != NULL) {
delete(m_subWidget[iii].widget);
if (errorControl == m_subWidget.size()) {
EWOL_CRITICAL("[" << getId() << "] The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function...");
m_subWidget[iii].widget = NULL;
m_subWidget.erase(m_subWidget.begin()+iii);
}
}
}
return; return;
} }
} }
EWOL_WARNING("[" << getId() << "] Can not remove unExistant widget"); EWOL_WARNING("[" << getId() << "] Can not remove unExistant widget");
} }
void ewol::widget::Gird::subWidgetUnLink(ewol::Widget* _newWidget) { void ewol::widget::Gird::subWidgetUnLink(ewol::object::Shared<ewol::Widget> _newWidget) {
if (NULL == _newWidget) { if (nullptr == _newWidget) {
return; return;
} }
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (_newWidget == m_subWidget[iii].widget) { if (_newWidget == m_subWidget[iii].widget) {
m_subWidget[iii].widget = NULL;
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(m_subWidget.begin()+iii);
return; return;
} }
@ -333,7 +306,6 @@ void ewol::widget::Gird::subWidgetUnLink(int32_t _colId, int32_t _rowId) {
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if( m_subWidget[iii].row == _rowId if( m_subWidget[iii].row == _rowId
&& m_subWidget[iii].col == _colId) { && m_subWidget[iii].col == _colId) {
m_subWidget[iii].widget = NULL;
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(m_subWidget.begin()+iii);
return; return;
} }
@ -344,7 +316,7 @@ void ewol::widget::Gird::subWidgetUnLink(int32_t _colId, int32_t _rowId) {
void ewol::widget::Gird::systemDraw(const ewol::DrawProperty& _displayProp) { void ewol::widget::Gird::systemDraw(const ewol::DrawProperty& _displayProp) {
ewol::Widget::systemDraw(_displayProp); ewol::Widget::systemDraw(_displayProp);
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (NULL != m_subWidget[iii].widget) { if (nullptr != m_subWidget[iii].widget) {
m_subWidget[iii].widget->systemDraw(_displayProp); m_subWidget[iii].widget->systemDraw(_displayProp);
} }
} }
@ -352,26 +324,26 @@ void ewol::widget::Gird::systemDraw(const ewol::DrawProperty& _displayProp) {
void ewol::widget::Gird::onRegenerateDisplay() { void ewol::widget::Gird::onRegenerateDisplay() {
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (NULL != m_subWidget[iii].widget) { if (nullptr != m_subWidget[iii].widget) {
m_subWidget[iii].widget->onRegenerateDisplay(); m_subWidget[iii].widget->onRegenerateDisplay();
} }
} }
} }
ewol::Widget * ewol::widget::Gird::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::Gird::getWidgetAtPos(const vec2& _pos) {
if (true == isHide()) { if (true == isHide()) {
return NULL; return nullptr;
} }
// for all element in the sizer ... // for all element in the sizer ...
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (size_t iii=0; iii<m_subWidget.size(); iii++) {
if (NULL != m_subWidget[iii].widget) { if (nullptr != m_subWidget[iii].widget) {
vec2 tmpSize = m_subWidget[iii].widget->getSize(); vec2 tmpSize = m_subWidget[iii].widget->getSize();
vec2 tmpOrigin = m_subWidget[iii].widget->getOrigin(); vec2 tmpOrigin = m_subWidget[iii].widget->getOrigin();
if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x())
&& (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) )
{ {
ewol::Widget * tmpWidget = m_subWidget[iii].widget->getWidgetAtPos(_pos); ewol::object::Shared<ewol::Widget> tmpWidget = m_subWidget[iii].widget->getWidgetAtPos(_pos);
if (NULL != tmpWidget) { if (nullptr != tmpWidget) {
return tmpWidget; return tmpWidget;
} }
// stop searching // stop searching
@ -379,21 +351,21 @@ ewol::Widget * ewol::widget::Gird::getWidgetAtPos(const vec2& _pos) {
} }
} }
} }
return NULL; return nullptr;
} }
void ewol::widget::Gird::onObjectRemove(ewol::Object * _removeObject) { void ewol::widget::Gird::onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject) {
// First step call parrent : // First step call parrent :
ewol::Widget::onObjectRemove(_removeObject); ewol::Widget::onObjectRemove(_removeObject);
// second step find if in all the elements ... // second step find if in all the elements ...
for(int32_t iii=m_subWidget.size()-1; iii >= 0; iii--) { for(int32_t iii=m_subWidget.size()-1; iii >= 0; iii--) {
if(m_subWidget[iii].widget == _removeObject) { if(m_subWidget[iii].widget == _removeObject) {
EWOL_VERBOSE("[" << getId() << "]={" << getObjectType() << "} remove sizer sub Element [" << iii << "/" << m_subWidget.size()-1 << "] == > destroyed object"); EWOL_VERBOSE("[" << getId() << "]={" << getObjectType() << "} remove sizer sub Element [" << iii << "/" << m_subWidget.size()-1 << "] == > destroyed object");
m_subWidget[iii].widget = NULL; m_subWidget[iii].widget = nullptr;
m_subWidget.erase(m_subWidget.begin()+iii); m_subWidget.erase(m_subWidget.begin()+iii);
} }
} }
if (m_tmpWidget == _removeObject) { if (m_tmpWidget == _removeObject) {
m_tmpWidget = NULL; m_tmpWidget.reset();
} }
} }

View File

@ -26,7 +26,7 @@ namespace ewol {
private: private:
class GirdProperties { class GirdProperties {
public: public:
ewol::Widget* widget; ewol::object::Shared<ewol::Widget> widget;
int32_t row; int32_t row;
int32_t col; int32_t col;
}; };
@ -34,7 +34,7 @@ namespace ewol {
int32_t m_uniformSizeRow; int32_t m_uniformSizeRow;
std::vector<int32_t> m_sizeCol; //!< size of all colomn (if set (otherwise 0)) std::vector<int32_t> m_sizeCol; //!< size of all colomn (if set (otherwise 0))
std::vector<GirdProperties> m_subWidget; //!< all sub widget are contained in this element std::vector<GirdProperties> m_subWidget; //!< all sub widget are contained in this element
ewol::Widget* m_tmpWidget; //!< use when replace a widget ... ewol::object::Shared<ewol::Widget> m_tmpWidget; //!< use when replace a widget ...
bool m_gavityButtom; bool m_gavityButtom;
public: public:
/** /**
@ -97,12 +97,12 @@ namespace ewol {
* @param[in] _rowId Id of the row [0..y]. * @param[in] _rowId Id of the row [0..y].
* @param[in] _newWidget the element pointer * @param[in] _newWidget the element pointer
*/ */
virtual void subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::Widget* _newWidget); virtual void subWidgetAdd(int32_t _colId, int32_t _rowId, ewol::object::Shared<ewol::Widget> _newWidget);
/** /**
* @brief remove definitly a widget from the system and this Gird. * @brief remove definitly a widget from the system and this Gird.
* @param[in] _newWidget the element pointer. * @param[in] _newWidget the element pointer.
*/ */
virtual void subWidgetRemove(ewol::Widget* _newWidget); virtual void subWidgetRemove(ewol::object::Shared<ewol::Widget> _newWidget);
/** /**
* @brief remove definitly a widget from the system and this Gird. * @brief remove definitly a widget from the system and this Gird.
* @param[in] _colId Id of the colomn [0..x]. * @param[in] _colId Id of the colomn [0..x].
@ -113,7 +113,7 @@ namespace ewol {
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...). * @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...).
* @param[in] _newWidget the element pointer. * @param[in] _newWidget the element pointer.
*/ */
virtual void subWidgetUnLink(ewol::Widget* _newWidget); virtual void subWidgetUnLink(ewol::object::Shared<ewol::Widget> _newWidget);
/** /**
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...). * @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...).
* @param[in] _colId Id of the colomn [0..x]. * @param[in] _colId Id of the colomn [0..x].
@ -132,12 +132,14 @@ namespace ewol {
* @brief get the current border size of the current element: * @brief get the current border size of the current element:
* @return the border size (0 if not used) * @return the border size (0 if not used)
*/ */
const ivec2& getBorderSize() { return m_borderSize; }; const ivec2& getBorderSize() {
return m_borderSize;
};
public: // Derived function public: // Derived function
virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void systemDraw(const ewol::DrawProperty& _displayProp);
virtual void onRegenerateDisplay(); virtual void onRegenerateDisplay();
virtual ewol::Widget* getWidgetAtPos(const vec2& pos); virtual ewol::object::Shared<ewol::Widget> getWidgetAtPos(const vec2& pos);
virtual void onObjectRemove(ewol::Object* _removeObject); virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject);
virtual void calculateSize(const vec2& _availlable); virtual void calculateSize(const vec2& _availlable);
virtual void calculateMinMaxSize(); virtual void calculateMinMaxSize();
}; };

View File

@ -36,7 +36,7 @@ const char * const ewol::widget::Image::configPartStart = "part-start";
const char * const ewol::widget::Image::configPartStop = "part-stop"; const char * const ewol::widget::Image::configPartStop = "part-stop";
ewol::widget::Image::Image(const std::string& _file, const ewol::Dimension& _border) : ewol::widget::Image::Image(const std::string& _file, const ewol::Dimension& _border) :
m_colorProperty(NULL), m_colorProperty(nullptr),
m_colorId(-1), m_colorId(-1),
m_imageSize(vec2(0.0f,0.0f)), m_imageSize(vec2(0.0f,0.0f)),
m_keepRatio(true), m_keepRatio(true),
@ -44,22 +44,22 @@ ewol::widget::Image::Image(const std::string& _file, const ewol::Dimension& _bor
m_posStop(1.0f,1.0f) { m_posStop(1.0f,1.0f) {
addObjectType("ewol::widget::Image"); addObjectType("ewol::widget::Image");
addEventId(eventPressed); addEventId(eventPressed);
registerConfig(configRatio, "bool", NULL, "Keep ratio of the image"); registerConfig(configRatio, "bool", nullptr, "Keep ratio of the image");
registerConfig(configSize, "Dimension", NULL, "Basic display size of the image"); registerConfig(configSize, "Dimension", nullptr, "Basic display size of the image");
registerConfig(configBorder, "Dimension", NULL, "Border of the image"); registerConfig(configBorder, "Dimension", nullptr, "Border of the image");
registerConfig(configSource, "string", "Image source path"); registerConfig(configSource, "string", "Image source path");
registerConfig(configDistanceField, "bool", "Distance field mode"); registerConfig(configDistanceField, "bool", "Distance field mode");
registerConfig(configPartStart, "vec2", NULL, "Start display position in the image [0.0 .. 1.0]"); registerConfig(configPartStart, "vec2", nullptr, "Start display position in the image [0.0 .. 1.0]");
registerConfig(configPartStop, "vec2", NULL, "Stop display position in the image [0.0 .. 1.0]"); registerConfig(configPartStop, "vec2", nullptr, "Stop display position in the image [0.0 .. 1.0]");
m_colorProperty = ewol::resource::ColorFile::keep("THEME:COLOR:Image.json"); m_colorProperty = ewol::resource::ColorFile::keep("THEME:COLOR:Image.json");
if (m_colorProperty != NULL) { if (m_colorProperty != nullptr) {
m_colorId = m_colorProperty->request("foreground"); m_colorId = m_colorProperty->request("foreground");
} }
set(_file, _border); set(_file, _border);
} }
ewol::widget::Image::~Image() { ewol::widget::Image::~Image() {
ewol::resource::ColorFile::release(m_colorProperty);
} }
void ewol::widget::Image::setFile(const std::string& _file) { void ewol::widget::Image::setFile(const std::string& _file) {
@ -147,7 +147,7 @@ void ewol::widget::Image::onRegenerateDisplay() {
if (true == needRedraw()) { if (true == needRedraw()) {
// remove data of the previous composition : // remove data of the previous composition :
m_compositing.clear(); m_compositing.clear();
if (m_colorProperty != NULL) { if (m_colorProperty != nullptr) {
m_compositing.setColor(m_colorProperty->get(m_colorId)); m_compositing.setColor(m_colorProperty->get(m_colorId));
} }
// calculate the new position and size : // calculate the new position and size :
@ -230,7 +230,7 @@ bool ewol::widget::Image::onEventInput(const ewol::event::Input& _event) {
} }
bool ewol::widget::Image::loadXML(exml::Element* _node) { bool ewol::widget::Image::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
ewol::Widget::loadXML(_node); ewol::Widget::loadXML(_node);

View File

@ -41,7 +41,7 @@ namespace ewol {
static void init(ewol::widget::Manager& _widgetManager); static void init(ewol::widget::Manager& _widgetManager);
protected: protected:
ewol::compositing::Image m_compositing; //!< compositing element of the image. ewol::compositing::Image m_compositing; //!< compositing element of the image.
ewol::resource::ColorFile* m_colorProperty; //!< theme color property ewol::object::Shared<ewol::resource::ColorFile> m_colorProperty; //!< theme color property
int32_t m_colorId; //!< Color of the image. int32_t m_colorId; //!< Color of the image.
public: public:
/** /**

View File

@ -67,9 +67,9 @@ void ewol::widget::Joystick::onRegenerateDisplay() {
// clean the object list ... // clean the object list ...
/* /*
ewol::OObject2DColored * tmpOObjects = NULL; ewol::OObject2DColored * tmpOObjects = nullptr;
ewol::OObject2DTextured * tmpOOtexBg = NULL; ewol::OObject2DTextured * tmpOOtexBg = nullptr;
ewol::OObject2DTextured * tmpOOtexFg = NULL; ewol::OObject2DTextured * tmpOOtexFg = nullptr;
// set background // set background
if (true == m_displayBackground) { if (true == m_displayBackground) {
if (m_background == "") { if (m_background == "") {
@ -84,7 +84,7 @@ void ewol::widget::Joystick::onRegenerateDisplay() {
// set cursor point // set cursor point
float sizeElement = m_size.x*m_ratio; float sizeElement = m_size.x*m_ratio;
if (m_foreground == "") { if (m_foreground == "") {
if (NULL == tmpOObjects) { if (nullptr == tmpOObjects) {
tmpOObjects = new ewol::OObject2DColored; tmpOObjects = new ewol::OObject2DColored;
} }
tmpOObjects->setColor(m_colorFg); tmpOObjects->setColor(m_colorFg);
@ -96,13 +96,13 @@ void ewol::widget::Joystick::onRegenerateDisplay() {
((m_displayPos.y+1.0)/2.0)*(m_size.y-2*sizeElement), sizeElement*2, sizeElement*2); ((m_displayPos.y+1.0)/2.0)*(m_size.y-2*sizeElement), sizeElement*2, sizeElement*2);
} }
// add all needed objects ... // add all needed objects ...
if (NULL != tmpOObjects) { if (nullptr != tmpOObjects) {
addOObject(tmpOObjects); addOObject(tmpOObjects);
} }
if (NULL != tmpOOtexBg) { if (nullptr != tmpOOtexBg) {
addOObject(tmpOOtexBg); addOObject(tmpOOtexBg);
} }
if (NULL != tmpOOtexFg) { if (nullptr != tmpOOtexFg) {
addOObject(tmpOOtexFg); addOObject(tmpOOtexFg);
} }
*/ */

View File

@ -27,12 +27,12 @@ void ewol::widget::Label::init(ewol::widget::Manager& _widgetManager) {
} }
// TODO : Remove the label name in the constructor ... // TODO : Remove the label name in the constructor ...
ewol::widget::Label::Label(std::string _newLabel) : ewol::widget::Label::Label(std::string _newLabel) :
m_colorProperty(NULL), m_colorProperty(nullptr),
m_colorDefaultFgText(-1), m_colorDefaultFgText(-1),
m_colorDefaultBgText(-1){ m_colorDefaultBgText(-1){
addObjectType("ewol::widget::Label"); addObjectType("ewol::widget::Label");
m_colorProperty = ewol::resource::ColorFile::keep("THEME:COLOR:Label.json"); m_colorProperty = ewol::resource::ColorFile::keep("THEME:COLOR:Label.json");
if (m_colorProperty != NULL) { if (m_colorProperty != nullptr) {
m_colorDefaultFgText = m_colorProperty->request("foreground"); m_colorDefaultFgText = m_colorProperty->request("foreground");
m_colorDefaultBgText = m_colorProperty->request("background"); m_colorDefaultBgText = m_colorProperty->request("background");
} }
@ -40,11 +40,11 @@ ewol::widget::Label::Label(std::string _newLabel) :
addEventId(eventPressed); addEventId(eventPressed);
setCanHaveFocus(false); setCanHaveFocus(false);
setMouseLimit(1); setMouseLimit(1);
registerConfig(configValue, "string", NULL, "displayed value string"); // TODO : do not store in attibute... registerConfig(configValue, "string", nullptr, "displayed value string"); // TODO : do not store in attibute...
} }
ewol::widget::Label::~Label() { ewol::widget::Label::~Label() {
ewol::resource::ColorFile::release(m_colorProperty);
} }
void ewol::widget::Label::calculateMinMaxSize() { void ewol::widget::Label::calculateMinMaxSize() {
@ -124,7 +124,7 @@ void ewol::widget::Label::onRegenerateDisplay() {
// clean the element // clean the element
m_text.reset(); m_text.reset();
if (m_colorProperty != NULL) { if (m_colorProperty != nullptr) {
m_text.setDefaultColorFg(m_colorProperty->get(m_colorDefaultFgText)); m_text.setDefaultColorFg(m_colorProperty->get(m_colorDefaultFgText));
m_text.setDefaultColorBg(m_colorProperty->get(m_colorDefaultBgText)); m_text.setDefaultColorBg(m_colorProperty->get(m_colorDefaultBgText));
} }
@ -148,7 +148,7 @@ bool ewol::widget::Label::onEventInput(const ewol::event::Input& _event) {
} }
bool ewol::widget::Label::loadXML(exml::Element* _node) { bool ewol::widget::Label::loadXML(exml::Element* _node) {
if (NULL == _node) { if (nullptr == _node) {
return false; return false;
} }
ewol::Widget::loadXML(_node); ewol::Widget::loadXML(_node);

View File

@ -34,7 +34,7 @@ namespace ewol {
private: private:
ewol::compositing::Text m_text; //!< Compositing text element. ewol::compositing::Text m_text; //!< Compositing text element.
std::u32string m_label; //!< decorated text to display. std::u32string m_label; //!< decorated text to display.
ewol::resource::ColorFile* m_colorProperty; //!< theme color property ewol::object::Shared<ewol::resource::ColorFile> m_colorProperty; //!< theme color property
int32_t m_colorDefaultFgText; //!< Default color of the text int32_t m_colorDefaultFgText; //!< Default color of the text
int32_t m_colorDefaultBgText; //!< Default Background color of the text int32_t m_colorDefaultBgText; //!< Default Background color of the text
public: public:

View File

@ -29,26 +29,27 @@ ewol::widget::Layer::~Layer() {
EWOL_DEBUG("[" << getId() << "] Layer : destroy"); EWOL_DEBUG("[" << getId() << "] Layer : destroy");
} }
ewol::Widget* ewol::widget::Layer::getWidgetAtPos(const vec2& _pos) { ewol::object::Shared<ewol::Widget> ewol::widget::Layer::getWidgetAtPos(const vec2& _pos) {
if (true == isHide()) { if (true == isHide()) {
return NULL; return nullptr;
} }
// for all element in the sizer ... // for all element in the sizer ...
for (size_t iii=0; iii<m_subWidget.size(); iii++) { for (auto &it : m_subWidget) {
if (NULL != m_subWidget[iii]) { if (it == nullptr) {
vec2 tmpSize = m_subWidget[iii]->getSize(); continue;
vec2 tmpOrigin = m_subWidget[iii]->getOrigin(); }
vec2 tmpSize = it->getSize();
vec2 tmpOrigin = it->getOrigin();
if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x())
&& (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) )
{ {
ewol::Widget * tmpWidget = m_subWidget[iii]->getWidgetAtPos(_pos); ewol::object::Shared<ewol::Widget> tmpWidget = it->getWidgetAtPos(_pos);
if (NULL != tmpWidget) { if (nullptr != tmpWidget) {
return tmpWidget; return tmpWidget;
} }
// parse the next layer ... // parse the next layer ...
} }
} }
} return nullptr;
return NULL;
}; };

Some files were not shown because too many files have changed in this diff Show More