diff --git a/Sources/libewol/ewol/Resource.h b/Sources/libewol/ewol/Resource.h index 8d883315..f6ea0312 100644 --- a/Sources/libewol/ewol/Resource.h +++ b/Sources/libewol/ewol/Resource.h @@ -26,6 +26,7 @@ #define __RESOURCES_H__ #include +#include #include namespace ewol diff --git a/Sources/libewol/ewol/ResourceManager.cpp b/Sources/libewol/ewol/ResourceManager.cpp index cbee6b4a..1a103dbd 100644 --- a/Sources/libewol/ewol/ResourceManager.cpp +++ b/Sources/libewol/ewol/ResourceManager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include static etk::Vector l_resourceList; @@ -53,7 +54,7 @@ void ewol::resource::UnInit(void) } // internal generic keeper ... -static ewol::Resource* Keep(etk::UString name) +static ewol::Resource* LocalKeep(etk::UString& name) { for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) { if (l_resourceList[iii] != NULL) { @@ -74,12 +75,12 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object, i object = NULL; for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) { if (l_resourceList[iii] != NULL) { - if(l_resourceList[iii]->HasName(name)) { + if(l_resourceList[iii]->HasName(filename)) { ewol::TexturedFont* tmpObject = static_cast(l_resourceList[iii]); if (NULL!=tmpObject) { if (tmpObject->getFontSize() == size) { l_resourceList[iii]->Increment(); - object = static_castl_resourceList[iii] + object = static_cast(l_resourceList[iii]); return false; } } @@ -100,12 +101,12 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object, i bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object) { - object = static_cast(Keep(filename)); + object = static_cast(LocalKeep(filename)); if (NULL != object) { return true; } // need to crate a new one ... - object = new ewol::Font(filename, size); + object = new ewol::FontFreeType(filename); if (NULL == object) { EWOL_ERROR("allocation error of a resource : " << filename); return false; @@ -117,12 +118,12 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object) bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object) { - object = static_cast(Keep(filename)); + object = static_cast(LocalKeep(filename)); if (NULL != object) { return true; } // need to crate a new one ... - object = new ewol::Program(filename, size); + object = new ewol::Program(filename); if (NULL == object) { EWOL_ERROR("allocation error of a resource : " << filename); return false; @@ -134,12 +135,12 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object) bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object) { - object = static_cast(Keep(filename)); + object = static_cast(LocalKeep(filename)); if (NULL != object) { return true; } // need to crate a new one ... - object = new ewol::Shader(filename, size); + object = new ewol::Shader(filename); if (NULL == object) { EWOL_ERROR("allocation error of a resource : " << filename); return false; @@ -151,7 +152,7 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object) void ewol::resource::Release(ewol::Resource*& object) { - if (NUUL == object) { + if (NULL == object) { EWOL_ERROR("Try to remove a resource that have null pointer ..."); return; } @@ -175,3 +176,28 @@ void ewol::resource::Release(ewol::Resource*& object) object = NULL; } + +void ewol::resource::Release(ewol::TexturedFont*& object) +{ + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; +} +void ewol::resource::Release(ewol::Font*& object) +{ + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; +} +void ewol::resource::Release(ewol::Program*& object) +{ + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; +} +void ewol::resource::Release(ewol::Shader*& object) +{ + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; +} \ No newline at end of file diff --git a/Sources/libewol/ewol/ResourceManager.h b/Sources/libewol/ewol/ResourceManager.h index c5b41d6d..b8be1445 100644 --- a/Sources/libewol/ewol/ResourceManager.h +++ b/Sources/libewol/ewol/ResourceManager.h @@ -45,7 +45,11 @@ namespace ewol bool Keep(etk::UString& filename, ewol::Program*& object); bool Keep(etk::UString& filename, ewol::Shader*& object); - void Release(ewol::resource*& object); + void Release(ewol::Resource*& object); + void Release(ewol::TexturedFont*& object); + void Release(ewol::Font*& object); + void Release(ewol::Program*& object); + void Release(ewol::Shader*& object); } }; diff --git a/Sources/libewol/ewol/font/Font.h b/Sources/libewol/ewol/font/Font.h index e7ce33b1..55c91f97 100644 --- a/Sources/libewol/ewol/font/Font.h +++ b/Sources/libewol/ewol/font/Font.h @@ -78,9 +78,11 @@ namespace ewol } GlyphProperty; class Font : public ewol::Resource + { public: - Font(etk::UString fontFolder, etk::UString fontName) : ewol::Resource(fontName) {}; + Font(etk::UString fontName) : ewol::Resource(fontName) {}; virtual ~Font(void) {}; + const char* GetType(void) { return "ewol::Font"; }; virtual int32_t Draw(draw::Image& imageOut, int32_t fontSize, Vector2D textPos, diff --git a/Sources/libewol/ewol/font/FontFreeType.cpp b/Sources/libewol/ewol/font/FontFreeType.cpp index bbba3b5c..46d80cb6 100644 --- a/Sources/libewol/ewol/font/FontFreeType.cpp +++ b/Sources/libewol/ewol/font/FontFreeType.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include extern "C" { #include } @@ -63,15 +63,14 @@ void ewol::FreeTypeUnInit(void) -ewol::FontFreeType::FontFreeType(etk::UString fontFolder, etk::UString fontName) : - Font(fontFolder, fontName) +ewol::FontFreeType::FontFreeType(etk::UString fontName) : + Font(fontName) { m_init = false; m_FileBuffer = NULL; m_FileSize = 0; - etk::UString tmpFileName = fontFolder + "/" + fontName; - etk::File myfile(tmpFileName, etk::FILE_TYPE_DATA); + etk::File myfile(fontName, etk::FILE_TYPE_DATA); if (false == myfile.Exist()) { EWOL_ERROR("File Does not exist : " << myfile); return; @@ -88,7 +87,7 @@ ewol::FontFreeType::FontFreeType(etk::UString fontFolder, etk::UString fontName) // allocate data m_FileBuffer = new FT_Byte[m_FileSize]; if (NULL == m_FileBuffer) { - EWOL_ERROR("Error Memory allocation size=" << tmpFileName); + EWOL_ERROR("Error Memory allocation size=" << fontName); return; } // load data from the file : @@ -103,7 +102,7 @@ ewol::FontFreeType::FontFreeType(etk::UString fontFolder, etk::UString fontName) EWOL_ERROR("... another error code means that the font file could not ... be opened or read, or simply that it is broken..."); } else { // all OK - EWOL_INFO("load font : \"" << tmpFileName << "\" "); + EWOL_INFO("load font : \"" << fontName << "\" "); //Display(); m_init = true; } diff --git a/Sources/libewol/ewol/font/FontFreeType.h b/Sources/libewol/ewol/font/FontFreeType.h index 7c4c6776..2cbe730c 100644 --- a/Sources/libewol/ewol/font/FontFreeType.h +++ b/Sources/libewol/ewol/font/FontFreeType.h @@ -44,7 +44,7 @@ namespace ewol bool m_init; void Display(void); public: - FontFreeType(etk::UString fontFolder, etk::UString fontName); + FontFreeType(etk::UString fontName); ~FontFreeType(void); int32_t Draw(draw::Image& imageOut, int32_t fontSize, diff --git a/Sources/libewol/ewol/font/TexturedFont.cpp b/Sources/libewol/ewol/font/TexturedFont.cpp index c4e4871f..999fb66b 100644 --- a/Sources/libewol/ewol/font/TexturedFont.cpp +++ b/Sources/libewol/ewol/font/TexturedFont.cpp @@ -26,6 +26,7 @@ #include #include #include +#include static int32_t nextP2(int32_t value) @@ -56,13 +57,13 @@ static int32_t simpleSQRT(int32_t value) ewol::TexturedFont::TexturedFont(etk::UString fontName, int32_t size) : + ewol::Resource(fontName), + m_size(size), m_font(NULL), - m_counter(1), m_lastGlyphPos(0,0), m_lastRawHeigh(0) { - m_size = size; - m_font = ewol::font::Keep(fontName); + ewol::resource::Keep(fontName, m_font); if (NULL == m_font) { return; } @@ -183,7 +184,9 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName, int32_t size) : ewol::TexturedFont::~TexturedFont(void) { - ewol::font::Release(m_font); + if (NULL!= m_font) { + ewol::resource::Release(m_font); + } } int32_t ewol::TexturedFont::Draw(Vector2D textPos, diff --git a/Sources/libewol/ewol/font/TexturedFont.h b/Sources/libewol/ewol/font/TexturedFont.h index e59d918c..087ffc96 100644 --- a/Sources/libewol/ewol/font/TexturedFont.h +++ b/Sources/libewol/ewol/font/TexturedFont.h @@ -29,10 +29,11 @@ #include #include +#include namespace ewol { - class TexturedFont { + class TexturedFont : public ewol::Resource { typedef struct { GlyphProperty property; @@ -44,7 +45,6 @@ namespace ewol int32_t m_height; ewol::Font* m_font; ewol::Texture m_texture; - uint32_t m_counter; etk::Vector m_listElement; // for the texture generation : Vector2D m_lastGlyphPos; @@ -52,10 +52,8 @@ namespace ewol public: TexturedFont(etk::UString fontName, int32_t size); ~TexturedFont(void); + const char* GetType(void) { return "ewol::TexturedFont"; }; int32_t getFontSize(void) { return m_size; }; - bool HasName(etk::UString& fileName, int32_t size) { return (m_size!=size)?false:((m_font==NULL)?false:m_font->HasName(fileName)); }; - void Increment(void) { m_counter++; }; - bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; }; int32_t Draw(Vector2D textPos, const etk::UString& unicodeString, etk::Vector > & coord, @@ -70,7 +68,6 @@ namespace ewol int32_t GetHeight(void) { return m_height; }; int32_t GetFontSize(void) { return m_size; }; ewol::Texture& GetTex(void) { return m_texture; }; - etk::UString GetFontName(void) { if(NULL==m_font) { return "error"; } return m_font->GetName(); }; }; diff --git a/Sources/libewol/ewol/oObject/2DColored.cpp b/Sources/libewol/ewol/oObject/2DColored.cpp index 505c2c7d..d2e6afcb 100644 --- a/Sources/libewol/ewol/oObject/2DColored.cpp +++ b/Sources/libewol/ewol/oObject/2DColored.cpp @@ -23,7 +23,7 @@ */ #include -#include +#include #include diff --git a/Sources/libewol/ewol/oObject/2DTextColored.cpp b/Sources/libewol/ewol/oObject/2DTextColored.cpp index 812704e7..b3bf8868 100644 --- a/Sources/libewol/ewol/oObject/2DTextColored.cpp +++ b/Sources/libewol/ewol/oObject/2DTextColored.cpp @@ -23,9 +23,10 @@ */ #include -#include +#include #include #include +#include #undef __class__ #define __class__ "ewol::OObject2DTextColored" @@ -34,11 +35,13 @@ void ewol::OObject2DTextColored::SetFontProperty(etk::UString fontName, int32_t { // remove old one if (NULL != m_font) { - ewol::font::TexturedRelease(m_font); + ewol::resource::Release(m_font); m_font = NULL; } // link to new One - m_font = ewol::font::TexturedKeep(fontName, fontSize); + if (false == ewol::resource::Keep(fontName, m_font, fontSize)) { + + } } void ewol::OObject2DTextColored::SetFont(etk::UString fontName) @@ -56,7 +59,7 @@ void ewol::OObject2DTextColored::SetSize(int32_t fontSize) // get old size etk::UString fontName = ewol::font::GetDefaultFont(); if (NULL != m_font) { - fontName = m_font->GetFontName(); + fontName = m_font->GetName(); } SetFontProperty(fontName, fontSize); } @@ -81,7 +84,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(void) : ewol::OObject2DTextColored::~OObject2DTextColored(void) { if (NULL != m_font) { - ewol::font::TexturedRelease(m_font); + ewol::resource::Release(m_font); m_font = NULL; } } diff --git a/Sources/libewol/ewol/oObject/2DTextured.cpp b/Sources/libewol/ewol/oObject/2DTextured.cpp index 25e22cb8..28eb1829 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.cpp +++ b/Sources/libewol/ewol/oObject/2DTextured.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #undef __class__ #define __class__ "ewol::OObject2DTextured" diff --git a/Sources/libewol/ewol/oObject/Sprite.cpp b/Sources/libewol/ewol/oObject/Sprite.cpp index ddabd43c..d5227bf7 100644 --- a/Sources/libewol/ewol/oObject/Sprite.cpp +++ b/Sources/libewol/ewol/oObject/Sprite.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #undef __class__ diff --git a/Sources/libewol/ewol/openGL/Program.cpp b/Sources/libewol/ewol/openGL/Program.cpp index 6c62fad3..5123fb1e 100644 --- a/Sources/libewol/ewol/openGL/Program.cpp +++ b/Sources/libewol/ewol/openGL/Program.cpp @@ -26,7 +26,8 @@ #include #include -ewol::Program::Program(etk::UString& filename) : ewol::Resource(filename) +ewol::Program::Program(etk::UString& filename) : + ewol::Resource(filename), m_program(0), m_needToReleaseShader(false) { diff --git a/Sources/libewol/ewol/openGL/Program.h b/Sources/libewol/ewol/openGL/Program.h index 1563dd68..801dcc4a 100644 --- a/Sources/libewol/ewol/openGL/Program.h +++ b/Sources/libewol/ewol/openGL/Program.h @@ -28,10 +28,11 @@ #include #include #include +#include namespace ewol { - Class Program : public ewol::Resource + class Program : public ewol::Resource { private : GLuint m_program; @@ -39,6 +40,7 @@ namespace ewol public: Program(etk::UString& filename); virtual ~Program(void); + const char* GetType(void) { return "ewol::Program"; }; GLuint GetGL_ID(void) { return m_program; }; }; }; diff --git a/Sources/libewol/ewol/openGL/Shader.h b/Sources/libewol/ewol/openGL/Shader.h index 4c994d03..96442372 100644 --- a/Sources/libewol/ewol/openGL/Shader.h +++ b/Sources/libewol/ewol/openGL/Shader.h @@ -28,10 +28,11 @@ #include #include #include +#include namespace ewol { - Class Shader : public ewol::Resource + class Shader : public ewol::Resource { private : GLuint m_shader; @@ -39,6 +40,7 @@ namespace ewol public: Shader(etk::UString& filename); virtual ~Shader(void); + const char* GetType(void) { return "ewol::Shader"; }; GLuint GetGL_ID(void) { return m_shader; }; GLenum GetShaderType(void) { return m_type; }; }; diff --git a/Sources/libewol/ewol/openGL/openGL.cpp b/Sources/libewol/ewol/openGL/openGL.cpp index 28c84122..e542392a 100644 --- a/Sources/libewol/ewol/openGL/openGL.cpp +++ b/Sources/libewol/ewol/openGL/openGL.cpp @@ -23,7 +23,7 @@ */ #include -#include +#include void glOrthoEwol(GLfloat left, diff --git a/Sources/libewol/ewol/os/eSystem.cpp b/Sources/libewol/ewol/os/eSystem.cpp index a6fc8ff8..084caeb8 100644 --- a/Sources/libewol/ewol/os/eSystem.cpp +++ b/Sources/libewol/ewol/os/eSystem.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include diff --git a/Sources/libewol/ewol/os/gui.Android.cpp b/Sources/libewol/ewol/os/gui.Android.cpp index b40f2286..21c425c1 100644 --- a/Sources/libewol/ewol/os/gui.Android.cpp +++ b/Sources/libewol/ewol/os/gui.Android.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include #undef __class__ diff --git a/Sources/libewol/ewol/os/gui.Windows.cpp b/Sources/libewol/ewol/os/gui.Windows.cpp index 816d180a..ad1e2465 100644 --- a/Sources/libewol/ewol/os/gui.Windows.cpp +++ b/Sources/libewol/ewol/os/gui.Windows.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include diff --git a/Sources/libewol/ewol/texture/Texture.cpp b/Sources/libewol/ewol/texture/Texture.cpp index ddb73e6c..b81c7d36 100644 --- a/Sources/libewol/ewol/texture/Texture.cpp +++ b/Sources/libewol/ewol/texture/Texture.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/Sources/libewol/ewol/texture/Texture.h b/Sources/libewol/ewol/texture/Texture.h index 65483b16..453679ab 100644 --- a/Sources/libewol/ewol/texture/Texture.h +++ b/Sources/libewol/ewol/texture/Texture.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace ewol { class Texture { diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp index 0b86f078..1192e1ec 100644 --- a/Sources/libewol/ewol/widget/Scene.cpp +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include /** * @brief Initilise the basic widget property ==> due to the android system diff --git a/Sources/libewol/ewol/widget/Widget.cpp b/Sources/libewol/ewol/widget/Widget.cpp index cf11bcd9..527b824a 100644 --- a/Sources/libewol/ewol/widget/Widget.cpp +++ b/Sources/libewol/ewol/widget/Widget.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include char* ewol::GetCharTypeMoveEvent(eventKbMoveType_te type) { diff --git a/Sources/libewol/ewol/widget/WidgetScrolled.cpp b/Sources/libewol/ewol/widget/WidgetScrolled.cpp index 0c386150..e9dc5421 100644 --- a/Sources/libewol/ewol/widget/WidgetScrolled.cpp +++ b/Sources/libewol/ewol/widget/WidgetScrolled.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/Sources/libewol/ewol/widget/Windows.cpp b/Sources/libewol/ewol/widget/Windows.cpp index c964e0f8..a6eedcab 100644 --- a/Sources/libewol/ewol/widget/Windows.cpp +++ b/Sources/libewol/ewol/widget/Windows.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 19a3abeb..c27ab521 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -1,10 +1,15 @@ # Basic elements FILE_LIST = ewol/ewol.cpp \ - ewol/openGl.cpp \ ewol/ClipBoard.cpp \ ewol/Debug.cpp \ - ewol/ShortCutManager.cpp + ewol/ShortCutManager.cpp \ + ewol/ResourceManager.cpp + +FILE_LIST+= ewol/openGL/openGL.cpp \ + ewol/openGL/Shader.cpp \ + ewol/openGL/Program.cpp + # Gui interface FILE_LIST+= ewol/os/eSystem.cpp \