diff --git a/Sources/libagg b/Sources/libagg index 6f05d8dc..b000e558 160000 --- a/Sources/libagg +++ b/Sources/libagg @@ -1 +1 @@ -Subproject commit 6f05d8dc715c3a8c022def84d63bed8bc255ca8d +Subproject commit b000e558d0025cb35ef3950f46f722c4167ed0ec diff --git a/Sources/libewol/ewol/font/Font.h b/Sources/libewol/ewol/font/Font.h index 0591228c..ff3b7403 100644 --- a/Sources/libewol/ewol/font/Font.h +++ b/Sources/libewol/ewol/font/Font.h @@ -28,57 +28,51 @@ #include #include #include +#include +#include namespace ewol { - // TODO : Create a subNameSpace: - /* - namespace font { - ... - }; - */ - // set default folder name of the font : - void SetFontFolder(etk::UString folderName); - void SetDefaultFont(etk::UString fontName, int32_t size); - // unload all font loaded - void InitFont(void); - void UnInitFont(void); - // load the fonts... - int32_t LoadFont(etk::UString fontName, int32_t size); // return ID of font - int32_t GetDefaultFontId(void); - void UnloadFont(int32_t id); + // show : http://www.freetype.org/freetype2/docs/tutorial/step2.html + typedef struct { + uniChar_t unicodeCharVal; + texCoord_ts posStart; + texCoord_ts posStop; + Vector2D bearing; + Vector2D size; + int32_t advance; + }freeTypeFontElement_ts; - // get the size of a long string in UTF8 (note that \n and \r represent unknown char...) - int32_t GetWidth(int32_t fontID, const etk::UString& unicodeString); - int32_t GetHeight(int32_t fontID); - int32_t DrawText(int32_t fontID, - Vector2D textPos, - clipping_ts & drawClipping, - const etk::UString & unicodeString, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex); - int32_t DrawText(int32_t fontID, - Vector2D textPos, - clipping_ts & drawClipping, - const uniChar_t unicodeChar, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex); - int32_t DrawText(int32_t fontID, - Vector2D textPos, - const etk::UString & unicodeString, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex); - int32_t DrawText(int32_t fontID, - Vector2D textPos, - const uniChar_t unicodeChar, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex); - int32_t LoadFont(etk::File fontFileName); + class Font { + private: + etk::UString m_name; + uint32_t m_counter; + public: + Font(etk::UString fontName) : + m_counter(1) + { + m_name = fontName; + }; + virtual ~Font(void) {}; + bool HasName(etk::UString& fileName) { return fileName==m_name; }; + etk::UString GetName(void) { return m_name; }; + void Increment(void) { m_counter++; }; + bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; }; + virtual int32_t Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const etk::UString& unicodeString, + draw::Color& textColor) = 0; + virtual int32_t Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const uniChar_t unicodeChar, + draw::Color& textColor) = 0; + virtual bool GenerateBitmapFont(int32_t size, int32_t& height, ewol::Texture& texture, etk::Vector& listElement) = 0; + virtual Vector2D GetSize(int32_t fontSize, const etk::UString & unicodeString) = 0; + virtual int32_t GetHeight(int32_t fontSize) = 0; + }; }; #endif diff --git a/Sources/libewol/ewol/font/FontFreeType.cpp b/Sources/libewol/ewol/font/FontFreeType.cpp index 435a1fcd..3ce759cf 100644 --- a/Sources/libewol/ewol/font/FontFreeType.cpp +++ b/Sources/libewol/ewol/font/FontFreeType.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include extern "C" { @@ -37,20 +38,6 @@ extern "C" { #define __class__ "ewol::FontFreeType" - -extern "C" -{ - // show : http://www.freetype.org/freetype2/docs/tutorial/step2.html - typedef struct { - uniChar_t unicodeCharVal; - texCoord_ts posStart; - texCoord_ts posStop; - Vector2D bearing; - Vector2D size; - int32_t advance; - }freeTypeFontElement_ts; -}; - // free Font hnadle of librairies ... entry for acces ... static FT_Library library; @@ -81,420 +68,16 @@ static int32_t simpleSQRT(int32_t value) } -// keep only one instance of every font in freetype -class FTFontInternal -{ - private: - void Display(void) - { - EWOL_INFO(" nuber of glyph = " << (int)m_fftFace->num_glyphs); - if ((FT_FACE_FLAG_SCALABLE & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_SCALABLE (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_SCALABLE (disable)"); - } - if ((FT_FACE_FLAG_FIXED_SIZES & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_FIXED_SIZES (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_FIXED_SIZES (disable)"); - } - if ((FT_FACE_FLAG_FIXED_WIDTH & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_FIXED_WIDTH (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_FIXED_WIDTH (disable)"); - } - if ((FT_FACE_FLAG_SFNT & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_SFNT (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_SFNT (disable)"); - } - if ((FT_FACE_FLAG_HORIZONTAL & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_HORIZONTAL (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_HORIZONTAL (disable)"); - } - if ((FT_FACE_FLAG_VERTICAL & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_VERTICAL (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_VERTICAL (disable)"); - } - if ((FT_FACE_FLAG_KERNING & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_KERNING (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_KERNING (disable)"); - } - /* Deprecated flag - if ((FT_FACE_FLAG_FAST_GLYPHS & face->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_FAST_GLYPHS (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_FAST_GLYPHS (disable)"); - } - */ - if ((FT_FACE_FLAG_MULTIPLE_MASTERS & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_MULTIPLE_MASTERS (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_MULTIPLE_MASTERS (disable)"); - } - if ((FT_FACE_FLAG_GLYPH_NAMES & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_GLYPH_NAMES (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_GLYPH_NAMES (disable)"); - } - if ((FT_FACE_FLAG_EXTERNAL_STREAM & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_EXTERNAL_STREAM (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_EXTERNAL_STREAM (disable)"); - } - if ((FT_FACE_FLAG_HINTER & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_HINTER (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_HINTER (disable)"); - } - if ((FT_FACE_FLAG_CID_KEYED & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_CID_KEYED (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_CID_KEYED (disable)"); - } - /* - if ((FT_FACE_FLAG_TRICKY & m_fftFace->face_flags) != 0) { - EWOL_INFO(" flags = FT_FACE_FLAG_TRICKY (enable)"); - } else { - EWOL_DEBUG(" flags = FT_FACE_FLAG_TRICKY (disable)"); - } - */ - EWOL_INFO(" unit per EM = " << m_fftFace->units_per_EM); - EWOL_INFO(" num of fixed sizes = " << m_fftFace->num_fixed_sizes); - //EWOL_INFO(" Availlable sizes = " << (int)m_fftFace->available_sizes); - - //EWOL_INFO(" Current size = " << (int)m_fftFace->size); - } - public: - FTFontInternal(etk::File fontFileName, etk::UString fontName) - { - m_fontName = fontName; - m_fileName = fontFileName; - m_FileBuffer = NULL; - m_FileSize = 0; - if (false == m_fileName.Exist()) { - EWOL_ERROR("File Does not exist : " << m_fileName); - return; - } - m_FileSize = m_fileName.Size(); - if (0==m_FileSize) { - EWOL_ERROR("This file is empty : " << m_fileName); - return; - } - if (false == m_fileName.fOpenRead()) { - EWOL_ERROR("Can not open the file : " << m_fileName); - return; - } - // allocate data - m_FileBuffer = new FT_Byte[m_FileSize]; - if (NULL == m_FileBuffer) { - EWOL_ERROR("Error Memory allocation size=" << m_FileSize); - return; - } - // load data from the file : - m_fileName.fRead(m_FileBuffer, 1, m_FileSize); - // close the file: - m_fileName.fClose(); - // load Face ... - int32_t error = FT_New_Memory_Face( library, m_FileBuffer, m_FileSize, 0, &m_fftFace ); - if( FT_Err_Unknown_File_Format == error) { - EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported"); - } else if (0 != error) { - 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 : \"" << m_fileName << "\" "); - //Display(); - } - } - ~FTFontInternal(void) - { - // clean the tmp memory - if (NULL != m_FileBuffer) { - delete[] m_FileBuffer; - m_FileBuffer = NULL; - } - } - public: - etk::UString GetFontName(void) {return m_fontName;}; - bool GenerateBitmapFont(int32_t size, int32_t &height, int32_t & textureId, etk::Vector & listElement) - { - // 300dpi (hight quality) 96 dpi (normal quality) - int32_t fontQuality = 96; - //int32_t fontQuality = 150; - //int32_t fontQuality = 300; - // Select Size ... - // note tha <<6==*64 corespond with the 1/64th of points calculation of freetype - int32_t error = FT_Set_Char_Size(m_fftFace, size<<6, size<<6, fontQuality, fontQuality); - // the line height to have a correct display - height = size*1.43f; - - // a small shortcut - FT_GlyphSlot slot = m_fftFace->glyph; - /* - EWOL_DEBUG("Max size for ths glyph size=" << size << - " is (" << m_fftFace->max_advance_width << "," << m_fftFace->max_advance_height << ")" << - "?=(" << (m_fftFace->max_advance_width>>6) << "," << (m_fftFace->max_advance_height>>6) << ")"); - */ - // retrieve glyph index from character code - int32_t glyph_index = FT_Get_Char_Index(m_fftFace, 'A' ); - // load glyph image into the slot (erase previous one) - error = FT_Load_Glyph(m_fftFace, // handle to face object - glyph_index, // glyph index - FT_LOAD_DEFAULT ); - if ( error ) { - EWOL_ERROR("FT_Load_Glyph"); - } - EWOL_DEBUG("linearHoriAdvance=" << (slot->linearHoriAdvance >> 6)); - EWOL_DEBUG("linearVertAdvance=" << (slot->linearVertAdvance >> 6)); - EWOL_DEBUG("metrics.horiAdvance=" << (slot->metrics.horiAdvance >> 6)); - EWOL_DEBUG("metrics.vertAdvance=" << (slot->metrics.vertAdvance >> 6)); - - int32_t nbElement = listElement.Size(); - int32_t coter = simpleSQRT(nbElement); - // note : +1 is for the overlapping of the glyph (Part 1) - int32_t glyphMaxWidth = /*(m_fftFace->max_advance_width>>6); */(slot->metrics.horiAdvance>>6) +1; - int32_t glyphMaxHeight = /*(m_fftFace->max_advance_height>>6); */(slot->metrics.vertAdvance>>6) +1; - int32_t textureWidth = nextP2(coter*glyphMaxWidth); - int32_t nbRaws = textureWidth / glyphMaxWidth; - if (nbRaws <= 0) { - EWOL_ERROR("devide by 0"); - nbRaws = 1; - } - int32_t nbLine = (nbElement / nbRaws) + 1; - int32_t textureHeight = nextP2(nbLine*glyphMaxHeight); - EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")"); - - // Allocate Memory For The Texture Data. - int32_t byfferDataSize = textureWidth * textureHeight; - GLubyte* expanded_data = new GLubyte[byfferDataSize]; - if (NULL == expanded_data) { - EWOL_ERROR("Allocation tmp data ERROR"); - return false; - } - // clean the data : - for(int j=0; j =nbRaws) { - tmpRowId = 0; - tmpLineId++; - } - } - */ - // retrieve glyph index from character code - glyph_index = FT_Get_Char_Index(m_fftFace, listElement[iii].unicodeCharVal ); - /* - if (glyph_index < 1) { - EWOL_WARNING("Can not load Glyph : " << listElement[iii].unicodeCharVal); - } - */ - // load glyph image into the slot (erase previous one) - error = FT_Load_Glyph(m_fftFace, // handle to face object - glyph_index, // glyph index - FT_LOAD_DEFAULT ); - if ( error ) { - EWOL_ERROR("FT_Load_Glyph"); - } - - // convert to an anti-aliased bitmap - error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL ); - if ( error ) { - EWOL_ERROR("FT_Render_Glyph"); - } - int32_t tmpWidth=slot->bitmap.width; - int32_t tmpHeight=slot->bitmap.rows; - // check if we have enought place on the bitmap to add the current element : - if (tmpRowStartPos+tmpWidth >= textureWidth) { - tmpRowStartPos = 0; - tmpLineStartPos += CurrentLineHigh; - CurrentLineHigh = 0; - EWOL_ASSERT(tmpLineStartPos+tmpHeight < textureHeight, "Texture dimention estimatiuon error for the current Font"); - } - - /* - EWOL_VERBOSE("elem=" << listElement[iii].unicodeCharVal - <<" size=(" << tmpWidth << "," << tmpHeight << ")" - << " for bitmap (left=" << slot->bitmap_left << ",top=" << slot->bitmap_top << ")"); - EWOL_VERBOSE(" BEARING=(" << (slot->metrics.horiBearingX>>6) << "," << (slot->metrics.vertBearingY>>6) << ")" ); - */ - for(int32_t j=0; j < tmpHeight;j++) { - for(int32_t i=0; i < tmpWidth; i++){ - int32_t position = (tmpRowStartPos + i ) - + (tmpLineStartPos + j ) * textureWidth; - expanded_data[position] = slot->bitmap.buffer[i + tmpWidth*j]; - } - } - listElement[iii].bearing.x = slot->metrics.horiBearingX>>6; - listElement[iii].bearing.y = slot->metrics.horiBearingY>>6; - listElement[iii].size.x = tmpWidth; - listElement[iii].size.y = tmpHeight; - listElement[iii].advance = slot->metrics.horiAdvance>>6; - listElement[iii].posStart.u = (float)(tmpRowStartPos) / (float)textureWidth; - listElement[iii].posStart.v = (float)(tmpLineStartPos) / (float)textureHeight; - listElement[iii].posStop.u = (float)(tmpRowStartPos + tmpWidth) / (float)textureWidth; - listElement[iii].posStop.v = (float)(tmpLineStartPos + tmpHeight) / (float)textureHeight; - - // update the maximum of the line hight : - if (CurrentLineHigh m_listLoadedTTFont; - - -static etk::UString s_currentFolderName = ""; -static etk::UString s_currentDefaultFontName = ""; -static int32_t s_currentDefaultFontId = -1; - -class FTFont{ - public: - FTFont(etk::File fontfileName, etk::UString fontName, int32_t size) - { - m_trueTypeFontId = -1; - for (int32_t iii=0; iii < m_listLoadedTTFont.Size(); iii++) { - if (m_listLoadedTTFont[iii]->GetFontName() == fontName) { - m_trueTypeFontId = iii; - } - } - if (-1==m_trueTypeFontId) { - // load a new one ... - FTFontInternal * tmpElement = new FTFontInternal(fontfileName, fontName); - m_listLoadedTTFont.PushBack(tmpElement); - m_trueTypeFontId = m_listLoadedTTFont.Size() -1; - } - // set the bassic charset: - m_elements.Clear(); - freeTypeFontElement_ts tmpchar1; - tmpchar1.unicodeCharVal = 0; - m_elements.PushBack(tmpchar1); - // TODO : dynamic generation of this : expected minimum of 0x20 => 0x7F .... - for (int32_t iii=0x20; iii<0xFF; iii++) { - freeTypeFontElement_ts tmpchar; - tmpchar.unicodeCharVal = iii; - m_elements.PushBack(tmpchar); - if (0x7F == iii) { - iii = 0x9F; - } - } - m_size = size; - m_listLoadedTTFont[m_trueTypeFontId]->GenerateBitmapFont(m_size, m_lineHeight, m_textureId, m_elements); - EWOL_DEBUG("plop"); - } - ~FTFont(void) - { - - } - bool Check(etk::UString fontName, int32_t size) - { - if (m_trueTypeFontId == -1) { - return false; - } - if( m_listLoadedTTFont[m_trueTypeFontId]->GetFontName() == fontName - && m_size == size) - { - return true; - } - return false; - }; - - etk::Vector & GetRefOnElement(void) - { - return m_elements; - }; - - uint32_t GetOglId(void) - { - return m_textureId; - }; - - int32_t GetSize(void) - { - return m_size; - }; - - int32_t GetHeight(void) - { - return m_lineHeight; - }; - - private: - int32_t m_trueTypeFontId; - int32_t m_textureId; // internal texture ID - int32_t m_size; // nb pixel height - int32_t m_lineHeight; // nb pixel height - int32_t m_interline; // nb pixel between 2 lines - etk::Vector m_elements; // -}; - -static etk::Vector m_listLoadedFont; - -#undef __class__ -#define __class__ "ewol::FontFreeType" - -void ewol::SetFontFolder(etk::UString folderName) -{ - if (s_currentFolderName != "") { - EWOL_WARNING("Change the FontFolder, old=\"" << s_currentFolderName << "\""); - } - EWOL_TODO("Check if folder exist"); - s_currentFolderName = folderName; - EWOL_INFO("New default font folder name=\"" << s_currentFolderName << "\""); -} - -void ewol::InitFont(void) +void ewol::FreeTypeInit(void) { EWOL_DEBUG("==> Init Font-Manager"); int32_t error = FT_Init_FreeType( &library ); if(0 != error) { EWOL_CRITICAL(" when loading FreeType Librairy ..."); } - // prevent android error ==> can create memory leak but I prefer - s_currentFolderName = ""; - s_currentDefaultFontName = ""; - m_listLoadedTTFont.Clear(); - s_currentDefaultFontId = -1; } -void ewol::UnInitFont(void) +void ewol::FreeTypeUnInit(void) { EWOL_DEBUG("==> Un-Init Font-Manager"); /*int32_t error = FT_Done_FreeType( library ); @@ -503,724 +86,313 @@ void ewol::UnInitFont(void) EWOL_CRITICAL(" when Un-loading FreeType Librairy ..."); } */ - s_currentFolderName = ""; - s_currentDefaultFontName = ""; - s_currentDefaultFontId = -1; - - // unload global font - for(int32_t iii=0; iiiCheck(fontName, size)) { - return iii; - } + if (false == myfile.fOpenRead()) { + EWOL_ERROR("Can not open the file : " << myfile); + return; } - FTFont * tmpFont = new FTFont(fileName, fontName, size); - m_listLoadedFont.PushBack(tmpFont); - return m_listLoadedFont.Size()-1; -} - -void ewol::UnloadFont(int32_t id) -{ - EWOL_TODO("I do not think it was a good idea... will be done later"); -} - -int32_t ewol::DrawText(int32_t fontID, - Vector2D textPos, - clipping_ts & drawClipping, - const etk::UString& unicodeString, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex) -{ - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 0; + // allocate data + m_FileBuffer = new FT_Byte[m_FileSize]; + if (NULL == m_FileBuffer) { + EWOL_ERROR("Error Memory allocation size=" << m_FileSize); + return; } - etk::Vector & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); - - fontTextureId = m_listLoadedFont[fontID]->GetOglId(); - int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); - int32_t fontHeight = m_listLoadedFont[fontID]->GetHeight(); - - float posDrawX = textPos.x; - - for(int32_t iii=0; iii drawClipping.x + drawClipping.w) - { - // Nothing to diplay ... - } else { - /* - // generata positions... - float TexSizeX = tuB - tuA; - if (dxA < drawClipping.x) { - // clip display - float drawSize = drawClipping.x - dxA; - // Update element start display - dxA = drawClipping.x; - float addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; - // update texture start X Pos - tuA += addElement; - } - if (dxB > drawClipping.x + drawClipping.w) { - // clip display - float drawSize = dxB - (drawClipping.x + drawClipping.w); - // Update element start display - dxB = drawClipping.x + drawClipping.w; - float addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; - // update texture start X Pos - tuB -= addElement; - } - float TexSizeY = tvD - tvC; - if (dyD < drawClipping.y) { - // clip display - float drawSize = drawClipping.y - dyD; - // Update element start display - dyD = drawClipping.y; - float addElement = TexSizeY * drawSize / listOfElement[charIndex].size.y; - // update texture start X Pos - tvD += addElement; - } - if (dyC > drawClipping.y + drawClipping.h) { - // clip display - float drawSize = dyC - (drawClipping.y + drawClipping.h); - // Update element start display - dyC = drawClipping.y + drawClipping.h; - float addElement = TexSizeX * drawSize / listOfElement[charIndex].size.y; - // update texture start X Pos - tvC -= addElement; - } - */ - if( dxB <= dxA - /*|| dyD >= dyC*/) { - // nothing to do ... - } else { - /* Bitmap position - * 0------1 - * | | - * | | - * 3------2 - */ - Vector2D bitmapDrawPos[4]; - bitmapDrawPos[0].x = (int32_t)dxA; - bitmapDrawPos[1].x = (int32_t)dxB; - bitmapDrawPos[2].x = (int32_t)dxB; - bitmapDrawPos[3].x = (int32_t)dxA; - - bitmapDrawPos[0].y = (int32_t)dyC; - bitmapDrawPos[1].y = (int32_t)dyC; - bitmapDrawPos[2].y = (int32_t)dyD; - bitmapDrawPos[3].y = (int32_t)dyD; - /* texture Position : - * 0------1 - * | | - * | | - * 3------2 - */ - texCoord_ts texturePos[4]; - texturePos[0].u = tuA; - texturePos[1].u = tuB; - texturePos[2].u = tuB; - texturePos[3].u = tuA; - - texturePos[0].v = tvC; - texturePos[1].v = tvC; - texturePos[2].v = tvD; - texturePos[3].v = tvD; - - // NOTE : Android does not support the Quads elements ... - /* Step 1 : - * ******** - * ****** - * **** - * ** - * - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[1]); - coordTex.PushBack(texturePos[2]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[1]); - coord.PushBack(bitmapDrawPos[2]); - - /* Step 2 : - * - * ** - * **** - * ****** - * ******** - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[2]); - coordTex.PushBack(texturePos[3]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[2]); - coord.PushBack(bitmapDrawPos[3]); - } - } - } - posDrawX += listOfElement[charIndex].advance; - } - int32_t sizeOut = posDrawX - textPos.x; - textPos.x = posDrawX; - return sizeOut; -} - -// TODO : Simplify this ... -int32_t ewol::DrawText(int32_t fontID, - Vector2D textPos, - clipping_ts & drawClipping, - const uniChar_t unicodeChar, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex) -{ -#if 0 - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 0; - } - etk::Vector & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); - - fontTextureId = m_listLoadedFont[fontID]->GetOglId(); - int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); - - float posDrawX = textPos.x; - int32_t charIndex; - - if (unicodeChar < 0x20) { - charIndex = 0; - } else if (unicodeChar < 0x80) { - charIndex = unicodeChar - 0x1F; + // load data from the file : + myfile.fRead(m_FileBuffer, 1, m_FileSize); + // close the file: + myfile.fClose(); + // load Face ... + int32_t error = FT_New_Memory_Face( library, m_FileBuffer, m_FileSize, 0, &m_fftFace ); + if( FT_Err_Unknown_File_Format == error) { + EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported"); + } else if (0 != error) { + EWOL_ERROR("... another error code means that the font file could not ... be opened or read, or simply that it is broken..."); } else { - charIndex = 0; - for (int32_t iii=0x80-0x20; iii < listOfElement.Size(); iii++) { - if (listOfElement[iii].unicodeCharVal == unicodeChar) { - charIndex = iii; - break; - } - } + // all OK + EWOL_INFO("load font : \"" << myfile << "\" "); + //Display(); } - // 0x01 == 0x20 == ' '; - if (unicodeChar != 0x01) { - /* Bitmap position - * xA xB - * yC *------* - * | | - * | | - * yD *------* - */ - float dxA = posDrawX + listOfElement[charIndex].bearing.x; - float dxB = posDrawX + listOfElement[charIndex].bearing.x + listOfElement[charIndex].size.x; - float dyC = textPos.y + listOfElement[charIndex].bearing.y - fontSize; - float dyD = dyC + listOfElement[charIndex].size.y; - - float tuA = listOfElement[charIndex].posStart.u; - float tuB = listOfElement[charIndex].posStop.u; - float tvC = listOfElement[charIndex].posStart.v; - float tvD = listOfElement[charIndex].posStop.v; - - - // Clipping and drawing area - // TODO : clipping in Y too ... - if( dxB < drawClipping.x - || dxA > drawClipping.x + drawClipping.w) - { - // Nothing to diplay ... - } else { - // generata positions... - float TexSizeX = tuB - tuA; - if (dxA < drawClipping.x) { - // clip display - float drawSize = drawClipping.x - dxA; - // Update element start display - dxA = drawClipping.x; - float addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; - // update texture start X Pos - tuA += addElement; - } - if (dxB > drawClipping.x + drawClipping.w) { - // clip display - float drawSize = dxB - (drawClipping.x + drawClipping.w); - // Update element start display - dxB = drawClipping.x + drawClipping.w; - float addElement = TexSizeX * drawSize / listOfElement[charIndex].size.x; - // update texture start X Pos - tuB -= addElement; - } - /* Bitmap position - * 0------1 - * | | - * | | - * 3------2 - */ - Vector2D bitmapDrawPos[4]; - bitmapDrawPos[0].x = (int32_t)dxA; - bitmapDrawPos[1].x = (int32_t)dxB; - bitmapDrawPos[2].x = (int32_t)dxB; - bitmapDrawPos[3].x = (int32_t)dxA; - - bitmapDrawPos[0].y = (int32_t)dyC; - bitmapDrawPos[1].y = (int32_t)dyC; - bitmapDrawPos[2].y = (int32_t)dyD; - bitmapDrawPos[3].y = (int32_t)dyD; - /* texture Position : - * 0------1 - * | | - * | | - * 3------2 - */ - texCoord_ts texturePos[4]; - texturePos[0].u = tuA; - texturePos[1].u = tuB; - texturePos[2].u = tuB; - texturePos[3].u = tuA; - - texturePos[0].v = tvC; - texturePos[1].v = tvC; - texturePos[2].v = tvD; - texturePos[3].v = tvD; - - // NOTE : Android does not support the Quads elements ... - /* Step 1 : - * ******** - * ****** - * **** - * ** - * - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[1]); - coordTex.PushBack(texturePos[2]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[1]); - coord.PushBack(bitmapDrawPos[2]); - - /* Step 2 : - * - * ** - * **** - * ****** - * ******** - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[2]); - coordTex.PushBack(texturePos[3]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[2]); - coord.PushBack(bitmapDrawPos[3]); - } - } - posDrawX += listOfElement[charIndex].advance; - int32_t sizeOut = posDrawX - textPos.x; - textPos.x = posDrawX; - return sizeOut; -#else - return 10; -#endif } - -int32_t ewol::DrawText(int32_t fontID, - Vector2D textPos, - const etk::UString& unicodeString, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex) +ewol::FontFreeType::~FontFreeType(void) { - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 0; + // clean the tmp memory + if (NULL != m_FileBuffer) { + delete[] m_FileBuffer; + m_FileBuffer = NULL; } - etk::Vector & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); - - fontTextureId = m_listLoadedFont[fontID]->GetOglId(); - int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); - int32_t fontHeight = m_listLoadedFont[fontID]->GetHeight(); - - float posDrawX = textPos.x; - - for(int32_t iii=0; iii= dyC) { - // nothing to do ... - } else { - /* Bitmap position - * 0------1 - * | | - * | | - * 3------2 - */ - Vector2D bitmapDrawPos[4]; - bitmapDrawPos[0].x = (int32_t)dxA; - bitmapDrawPos[1].x = (int32_t)dxB; - bitmapDrawPos[2].x = (int32_t)dxB; - bitmapDrawPos[3].x = (int32_t)dxA; - - bitmapDrawPos[0].y = (int32_t)dyC; - bitmapDrawPos[1].y = (int32_t)dyC; - bitmapDrawPos[2].y = (int32_t)dyD; - bitmapDrawPos[3].y = (int32_t)dyD; - /* texture Position : - * 0------1 - * | | - * | | - * 3------2 - */ - texCoord_ts texturePos[4]; - texturePos[0].u = tuA; - texturePos[1].u = tuB; - texturePos[2].u = tuB; - texturePos[3].u = tuA; - - texturePos[0].v = tvC; - texturePos[1].v = tvC; - texturePos[2].v = tvD; - texturePos[3].v = tvD; - - // NOTE : Android does not support the Quads elements ... - /* Step 1 : - * ******** - * ****** - * **** - * ** - * - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[1]); - coordTex.PushBack(texturePos[2]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[1]); - coord.PushBack(bitmapDrawPos[2]); - - /* Step 2 : - * - * ** - * **** - * ****** - * ******** - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[2]); - coordTex.PushBack(texturePos[3]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[2]); - coord.PushBack(bitmapDrawPos[3]); - - } - } - posDrawX += listOfElement[charIndex].advance; - } - int32_t sizeOut = posDrawX - textPos.x; - textPos.x = posDrawX; - return sizeOut; } -// TODO : Simplify this ... -int32_t ewol::DrawText(int32_t fontID, - Vector2D textPos, - const uniChar_t unicodeChar, - int32_t & fontTextureId, - etk::Vector > & coord, - etk::Vector & coordTex) +int32_t ewol::FontFreeType::Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const etk::UString& unicodeString, + draw::Color& textColor) { - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 0; - } - etk::Vector & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); + return 0; +} - fontTextureId = m_listLoadedFont[fontID]->GetOglId(); - int32_t fontSize = m_listLoadedFont[fontID]->GetSize(); +int32_t ewol::FontFreeType::Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const uniChar_t unicodeChar, + draw::Color& textColor) +{ + return 0; +} - float posDrawX = textPos.x; - int32_t charIndex; +Vector2D ewol::FontFreeType::GetSize(int32_t fontSize, const etk::UString & unicodeString) +{ + Vector2D outputSize(0,0); + return outputSize; +} + +int32_t ewol::FontFreeType::GetHeight(int32_t fontSize) +{ + return 0; +} + +bool ewol::FontFreeType::GenerateBitmapFont(int32_t size, int32_t &height, ewol::Texture & texture, etk::Vector & listElement) +{ + // get the pointer on the image : + draw::Image& myImage = texture.Get(); - if (unicodeChar < 0x20) { - charIndex = 0; - } else if (unicodeChar < 0x80) { - charIndex = unicodeChar - 0x1F; + // 300dpi (hight quality) 96 dpi (normal quality) + int32_t fontQuality = 96; + //int32_t fontQuality = 150; + //int32_t fontQuality = 300; + // Select Size ... + // note tha <<6==*64 corespond with the 1/64th of points calculation of freetype + int32_t error = FT_Set_Char_Size(m_fftFace, size<<6, size<<6, fontQuality, fontQuality); + // the line height to have a correct display + height = size*1.43f; + + // a small shortcut + FT_GlyphSlot slot = m_fftFace->glyph; + /* + EWOL_DEBUG("Max size for ths glyph size=" << size << + " is (" << m_fftFace->max_advance_width << "," << m_fftFace->max_advance_height << ")" << + "?=(" << (m_fftFace->max_advance_width>>6) << "," << (m_fftFace->max_advance_height>>6) << ")"); + */ + // retrieve glyph index from character code + int32_t glyph_index = FT_Get_Char_Index(m_fftFace, 'A' ); + // load glyph image into the slot (erase previous one) + error = FT_Load_Glyph(m_fftFace, // handle to face object + glyph_index, // glyph index + FT_LOAD_DEFAULT ); + if ( error ) { + EWOL_ERROR("FT_Load_Glyph"); + } + EWOL_DEBUG("linearHoriAdvance=" << (slot->linearHoriAdvance >> 6)); + EWOL_DEBUG("linearVertAdvance=" << (slot->linearVertAdvance >> 6)); + EWOL_DEBUG("metrics.horiAdvance=" << (slot->metrics.horiAdvance >> 6)); + EWOL_DEBUG("metrics.vertAdvance=" << (slot->metrics.vertAdvance >> 6)); + + int32_t nbElement = listElement.Size(); + int32_t coter = simpleSQRT(nbElement); + // note : +1 is for the overlapping of the glyph (Part 1) + int32_t glyphMaxWidth = /*(m_fftFace->max_advance_width>>6); */(slot->metrics.horiAdvance>>6) +1; + int32_t glyphMaxHeight = /*(m_fftFace->max_advance_height>>6); */(slot->metrics.vertAdvance>>6) +1; + int32_t textureWidth = nextP2(coter*glyphMaxWidth); + int32_t nbRaws = textureWidth / glyphMaxWidth; + if (nbRaws <= 0) { + EWOL_ERROR("devide by 0"); + nbRaws = 1; + } + int32_t nbLine = (nbElement / nbRaws) + 1; + int32_t textureHeight = nextP2(nbLine*glyphMaxHeight); + EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")"); + // resize must be done on the texture ... + texture.SetImageSize(Vector2D(textureWidth,textureHeight)); + // now we can acces directly on the image + myImage.SetFillColor(draw::Color(0xFFFFFF00)); + myImage.Clear(); + + int32_t tmpRowStartPos = 0; + int32_t tmpLineStartPos = 0; + int32_t CurrentLineHigh = 0; + // Generate for All Elements : + for (int32_t iii=0; iii=nbRaws) { + tmpRowId = 0; + tmpLineId++; + } + } + */ + // retrieve glyph index from character code + glyph_index = FT_Get_Char_Index(m_fftFace, listElement[iii].unicodeCharVal ); + /* + if (glyph_index < 1) { + EWOL_WARNING("Can not load Glyph : " << listElement[iii].unicodeCharVal); + } + */ + // load glyph image into the slot (erase previous one) + error = FT_Load_Glyph(m_fftFace, // handle to face object + glyph_index, // glyph index + FT_LOAD_DEFAULT ); + if ( error ) { + EWOL_ERROR("FT_Load_Glyph"); + } + + // convert to an anti-aliased bitmap + error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL ); + if ( error ) { + EWOL_ERROR("FT_Render_Glyph"); + } + int32_t tmpWidth=slot->bitmap.width; + int32_t tmpHeight=slot->bitmap.rows; + // check if we have enought place on the bitmap to add the current element : + if (tmpRowStartPos+tmpWidth >= textureWidth) { + tmpRowStartPos = 0; + tmpLineStartPos += CurrentLineHigh; + CurrentLineHigh = 0; + EWOL_ASSERT(tmpLineStartPos+tmpHeight < textureHeight, "Texture dimention estimatiuon error for the current Font"); + } + + /* + EWOL_VERBOSE("elem=" << listElement[iii].unicodeCharVal + <<" size=(" << tmpWidth << "," << tmpHeight << ")" + << " for bitmap (left=" << slot->bitmap_left << ",top=" << slot->bitmap_top << ")"); + EWOL_VERBOSE(" BEARING=(" << (slot->metrics.horiBearingX>>6) << "," << (slot->metrics.vertBearingY>>6) << ")" ); + */ + for(int32_t j=0; j < tmpHeight;j++) { + for(int32_t i=0; i < tmpWidth; i++){ + draw::Color tlpppp(0xFF,0xFF,0xFF,slot->bitmap.buffer[i + tmpWidth*j]); + EWOL_DEBUG(" plop : " << tlpppp); + myImage.Set(Vector2D(tmpRowStartPos+i, tmpLineStartPos+j), tlpppp ); + } + } + listElement[iii].bearing.x = slot->metrics.horiBearingX>>6; + listElement[iii].bearing.y = slot->metrics.horiBearingY>>6; + listElement[iii].size.x = tmpWidth; + listElement[iii].size.y = tmpHeight; + listElement[iii].advance = slot->metrics.horiAdvance>>6; + listElement[iii].posStart.u = (float)(tmpRowStartPos) / (float)textureWidth; + listElement[iii].posStart.v = (float)(tmpLineStartPos) / (float)textureHeight; + listElement[iii].posStop.u = (float)(tmpRowStartPos + tmpWidth) / (float)textureWidth; + listElement[iii].posStop.v = (float)(tmpLineStartPos + tmpHeight) / (float)textureHeight; + + // update the maximum of the line hight : + if (CurrentLineHigh bitmapDrawPos[4]; - bitmapDrawPos[0].x = (int32_t)dxA; - bitmapDrawPos[1].x = (int32_t)dxB; - bitmapDrawPos[2].x = (int32_t)dxB; - bitmapDrawPos[3].x = (int32_t)dxA; - - bitmapDrawPos[0].y = (int32_t)dyC; - bitmapDrawPos[1].y = (int32_t)dyC; - bitmapDrawPos[2].y = (int32_t)dyD; - bitmapDrawPos[3].y = (int32_t)dyD; - /* texture Position : - * 0------1 - * | | - * | | - * 3------2 - */ - texCoord_ts texturePos[4]; - texturePos[0].u = tuA; - texturePos[1].u = tuB; - texturePos[2].u = tuB; - texturePos[3].u = tuA; - - texturePos[0].v = tvC; - texturePos[1].v = tvC; - texturePos[2].v = tvD; - texturePos[3].v = tvD; - - // NOTE : Android does not support the Quads elements ... - /* Step 1 : - * ******** - * ****** - * **** - * ** - * - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[1]); - coordTex.PushBack(texturePos[2]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[1]); - coord.PushBack(bitmapDrawPos[2]); - - /* Step 2 : - * - * ** - * **** - * ****** - * ******** - */ - // set texture coordonates : - coordTex.PushBack(texturePos[0]); - coordTex.PushBack(texturePos[2]); - coordTex.PushBack(texturePos[3]); - // set display positions : - coord.PushBack(bitmapDrawPos[0]); - coord.PushBack(bitmapDrawPos[2]); - coord.PushBack(bitmapDrawPos[3]); - } + if ((FT_FACE_FLAG_FIXED_SIZES & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_FIXED_SIZES (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_FIXED_SIZES (disable)"); } - posDrawX += listOfElement[charIndex].advance; - int32_t sizeOut = posDrawX - textPos.x; - textPos.x = posDrawX; - return sizeOut; -} - - -int32_t ewol::GetWidth(int32_t fontID, const etk::UString& unicodeString) -{ - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 0; + if ((FT_FACE_FLAG_FIXED_WIDTH & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_FIXED_WIDTH (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_FIXED_WIDTH (disable)"); } - etk::Vector & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); + if ((FT_FACE_FLAG_SFNT & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_SFNT (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_SFNT (disable)"); + } + if ((FT_FACE_FLAG_HORIZONTAL & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_HORIZONTAL (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_HORIZONTAL (disable)"); + } + if ((FT_FACE_FLAG_VERTICAL & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_VERTICAL (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_VERTICAL (disable)"); + } + if ((FT_FACE_FLAG_KERNING & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_KERNING (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_KERNING (disable)"); + } + /* Deprecated flag + if ((FT_FACE_FLAG_FAST_GLYPHS & face->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_FAST_GLYPHS (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_FAST_GLYPHS (disable)"); + } + */ + if ((FT_FACE_FLAG_MULTIPLE_MASTERS & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_MULTIPLE_MASTERS (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_MULTIPLE_MASTERS (disable)"); + } + if ((FT_FACE_FLAG_GLYPH_NAMES & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_GLYPH_NAMES (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_GLYPH_NAMES (disable)"); + } + if ((FT_FACE_FLAG_EXTERNAL_STREAM & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_EXTERNAL_STREAM (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_EXTERNAL_STREAM (disable)"); + } + if ((FT_FACE_FLAG_HINTER & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_HINTER (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_HINTER (disable)"); + } + if ((FT_FACE_FLAG_CID_KEYED & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_CID_KEYED (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_CID_KEYED (disable)"); + } + /* + if ((FT_FACE_FLAG_TRICKY & m_fftFace->face_flags) != 0) { + EWOL_INFO(" flags = FT_FACE_FLAG_TRICKY (enable)"); + } else { + EWOL_DEBUG(" flags = FT_FACE_FLAG_TRICKY (disable)"); + } + */ + EWOL_INFO(" unit per EM = " << m_fftFace->units_per_EM); + EWOL_INFO(" num of fixed sizes = " << m_fftFace->num_fixed_sizes); + //EWOL_INFO(" Availlable sizes = " << (int)m_fftFace->available_sizes); - float posDrawX = 0.0; - for(int32_t iii=0; iii= 0x80) { - charIndex = 0; - } else if (tmpChar < 0x20) { - charIndex = 0; - } else if (tmpChar < 0x80) { - charIndex = tmpChar - 0x1F; - } else { - for (int32_t iii=0x80-0x20; iii < listOfElement.Size(); iii++) { - if (listOfElement[iii].unicodeCharVal == tmpChar) { - charIndex = iii; - break; - } - } - // TODO : Update if possible the mapping - charIndex = 0; - } - posDrawX += listOfElement[charIndex].advance; - } - return posDrawX; + //EWOL_INFO(" Current size = " << (int)m_fftFace->size); } -int32_t ewol::GetHeight(int32_t fontID) -{ - if(fontID>=m_listLoadedFont.Size() || fontID < 0) { - EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); - return 10; - } - return m_listLoadedFont[fontID]->GetHeight(); -} diff --git a/Sources/libewol/ewol/font/FontFreeType.h b/Sources/libewol/ewol/font/FontFreeType.h new file mode 100644 index 00000000..d88816e5 --- /dev/null +++ b/Sources/libewol/ewol/font/FontFreeType.h @@ -0,0 +1,67 @@ +/** + ******************************************************************************* + * @file ewol/font/FontFreeType.h + * @brief ewol Font freeType system (header) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_FONT_FREE_TYPE_H__ +#define __EWOL_FONT_FREE_TYPE_H__ + +#include + +extern "C" { + #include +} +#include FT_FREETYPE_H + +namespace ewol +{ + class FontFreeType : public ewol::Font + { + private: + FT_Byte * m_FileBuffer; + int32_t m_FileSize; + FT_Face m_fftFace; + void Display(void); + public: + FontFreeType(etk::UString fontName); + ~FontFreeType(void); + int32_t Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const etk::UString& unicodeString, + draw::Color& textColor); + int32_t Draw(draw::Image& imageOut, + int32_t fontSize, + Vector2D textPos, + const uniChar_t unicodeChar, + draw::Color& textColor); + bool GenerateBitmapFont(int32_t size, int32_t& height, ewol::Texture& texture, etk::Vector& listElement); + Vector2D GetSize(int32_t fontSize, const etk::UString & unicodeString); + int32_t GetHeight(int32_t fontSize); + }; + void FreeTypeInit(void); + void FreeTypeUnInit(void); + +}; + +#endif + diff --git a/Sources/libewol/ewol/font/FontManager.cpp b/Sources/libewol/ewol/font/FontManager.cpp new file mode 100644 index 00000000..1531031c --- /dev/null +++ b/Sources/libewol/ewol/font/FontManager.cpp @@ -0,0 +1,182 @@ +/** + ******************************************************************************* + * @file ewol/font/FontManager.cpp + * @brief ewol Font manager system (Sources) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include +#include +#include +#include +#include + +static etk::Vector l_fontList; +static etk::Vector l_fontTexturedList; +static etk::UString l_folderName = ""; +static etk::UString l_defaultFontName = ""; +static int32_t l_defaultFontSize = 10; + +void ewol::font::Init(void) +{ + // nothing to do in théory then, we clean the buffers : + // NOTE : If we do domething here, then the system does not work corectly + l_fontList.Clear(); + l_fontTexturedList.Clear(); + l_folderName = ""; + l_defaultFontName = ""; + l_defaultFontSize = 10; + // Specific for free Font + ewol::FreeTypeInit(); +} + +void ewol::font::UnInit(void) +{ + // remove textured font ... + for (int32_t iii=0; iii=0; iii--) { + if (l_fontList[iii] != NULL) { + if(l_fontList[iii]->HasName(tmpFileName)) { + l_fontList[iii]->Increment(); + return l_fontList[iii]; + } + } + } + ewol::FontFreeType* tmpResources = new ewol::FontFreeType(tmpFileName); + if (NULL == tmpResources) { + EWOL_ERROR("allocation error of a resource Font : " << tmpFileName); + return NULL; + } + l_fontList.PushBack(tmpResources); + return tmpResources; +} + +void ewol::font::Release(ewol::Font*& object) +{ + for (int32_t iii=l_fontList.Size()-1; iii>=0; iii--) { + if (l_fontList[iii] != NULL) { + if(l_fontList[iii] == object) { + if (true == l_fontList[iii]->Decrement()) { + // delete element + delete(l_fontList[iii]); + // remove element from the list : + l_fontList.Erase(iii); + } + // insidiously remove the pointer for the caller ... + object = NULL; + return; + } + } + } +} + + +ewol::TexturedFont* ewol::font::TexturedKeep(etk::UString fontName, int32_t size) +{ + etk::UString tmpFileName = l_folderName + "/" + fontName; + for (int32_t iii=l_fontTexturedList.Size()-1; iii>=0; iii--) { + if (l_fontTexturedList[iii] != NULL) { + if(l_fontTexturedList[iii]->HasName(tmpFileName, size)) { + l_fontTexturedList[iii]->Increment(); + return l_fontTexturedList[iii]; + } + } + } + ewol::TexturedFont* tmpResources = new ewol::TexturedFont(tmpFileName, size); + if (NULL == tmpResources) { + EWOL_ERROR("allocation error of a resource textured Font : " << tmpFileName); + return NULL; + } + l_fontTexturedList.PushBack(tmpResources); + return tmpResources; +} + +void ewol::font::TexturedRelease(ewol::TexturedFont*& object) +{ + for (int32_t iii=l_fontTexturedList.Size()-1; iii>=0; iii--) { + if (l_fontTexturedList[iii] != NULL) { + if(l_fontTexturedList[iii] == object) { + if (true == l_fontTexturedList[iii]->Decrement()) { + // delete element + delete(l_fontTexturedList[iii]); + // remove element from the list : + l_fontTexturedList.Erase(iii); + } + // insidiously remove the pointer for the caller ... + object = NULL; + return; + } + } + } +} \ No newline at end of file diff --git a/Sources/libewol/ewol/font/FontManager.h b/Sources/libewol/ewol/font/FontManager.h new file mode 100644 index 00000000..9e9384b5 --- /dev/null +++ b/Sources/libewol/ewol/font/FontManager.h @@ -0,0 +1,51 @@ +/** + ******************************************************************************* + * @file ewol/font/FontManager.h + * @brief ewol Font manager system (header) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_FONT_MANAGER_H__ +#define __EWOL_FONT_MANAGER_H__ + +#include +#include +#include + +namespace ewol +{ + namespace font { + void Init(void); + void UnInit(void); + void SetFontFolder(etk::UString folderName); + void SetDefaultFont(etk::UString fontName); + etk::UString& GetDefaultFont(void); + void SetDefaultSize(int32_t newSize); + int32_t GetDefaultSize(void); + + ewol::Font* Keep(etk::UString fontName); + void Release(ewol::Font*& object); + + ewol::TexturedFont* TexturedKeep(etk::UString fontName, int32_t size); + void TexturedRelease(ewol::TexturedFont*& object); + }; +}; + +#endif \ No newline at end of file diff --git a/Sources/libewol/ewol/font/TexturedFont.cpp b/Sources/libewol/ewol/font/TexturedFont.cpp new file mode 100644 index 00000000..e72b546a --- /dev/null +++ b/Sources/libewol/ewol/font/TexturedFont.cpp @@ -0,0 +1,291 @@ +/** + ******************************************************************************* + * @file ewol/font/TexturedFont.cpp + * @brief ewol Textured Font system (Sources) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include +#include +#include + + +ewol::TexturedFont::TexturedFont(etk::UString fontName, int32_t size) : + m_font(NULL), + m_counter(1) +{ + m_size = size; + m_font = ewol::font::Keep(fontName); + if (NULL == m_font) { + return; + } + // initilize the texture ... + // TODO : Do a better methode that not initialize with a stupid language ... like now ... + m_font->GenerateBitmapFont(m_size, m_height, m_texture, m_listElement); +} + +ewol::TexturedFont::~TexturedFont(void) +{ + ewol::font::Release(m_font); +} + +int32_t ewol::TexturedFont::Draw(Vector2D textPos, + const etk::UString& unicodeString, + etk::Vector > & coord, + etk::Vector & coordTex) +{ + float totalSize = 0; + Vector2D tmpPos = textPos; + for(int32_t iii=0; iii bitmapDrawPos[4]; + bitmapDrawPos[0].x = 10; + bitmapDrawPos[1].x = 400; + bitmapDrawPos[2].x = 400; + bitmapDrawPos[3].x = 10; + + bitmapDrawPos[0].y = 10; + bitmapDrawPos[1].y = 10; + bitmapDrawPos[2].y = 400; + bitmapDrawPos[3].y = 400; + /* texture Position : + * 0------1 + * | | + * | | + * 3------2 + */ + texCoord_ts texturePos[4]; + texturePos[0].u = 0; + texturePos[1].u = 1; + texturePos[2].u = 1; + texturePos[3].u = 0; + + texturePos[0].v = 0; + texturePos[1].v = 0; + texturePos[2].v = 1; + texturePos[3].v = 1; + + // NOTE : Android does not support the Quads elements ... + /* Step 1 : + * ******** + * ****** + * **** + * ** + * + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[1]); + coordTex.PushBack(texturePos[2]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[1]); + coord.PushBack(bitmapDrawPos[2]); + + /* Step 2 : + * + * ** + * **** + * ****** + * ******** + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[2]); + coordTex.PushBack(texturePos[3]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[2]); + coord.PushBack(bitmapDrawPos[3]); + } + #endif +} + +int32_t ewol::TexturedFont::Draw(Vector2D textPos, + const uniChar_t unicodeChar, + etk::Vector > & coord, + etk::Vector & coordTex) +{ + float posDrawX = textPos.x; + + int32_t charIndex; + if (unicodeChar < 0x20) { + charIndex = 0; + } else if (unicodeChar < 0x80) { + charIndex = unicodeChar - 0x1F; + } else { + charIndex = 0; + for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) { + if (m_listElement[iii].unicodeCharVal == unicodeChar) { + charIndex = iii; + break; + } + } + } + // 0x01 == 0x20 == ' '; + if (unicodeChar != 0x01) { + /* Bitmap position + * xA xB + * yC *------* + * | | + * | | + * yD *------* + */ + float dxA = posDrawX + m_listElement[charIndex].bearing.x; + float dxB = posDrawX + m_listElement[charIndex].bearing.x + m_listElement[charIndex].size.x; + float dyC = textPos.y + m_listElement[charIndex].bearing.y + m_height - m_size; + float dyD = dyC - m_listElement[charIndex].size.y; + + float tuA = m_listElement[charIndex].posStart.u; + float tuB = m_listElement[charIndex].posStop.u; + float tvC = m_listElement[charIndex].posStart.v; + float tvD = m_listElement[charIndex].posStop.v; + + + // Clipping and drawing area + if( dxB <= dxA + || dyD >= dyC) { + // nothing to do ... + } else { + /* Bitmap position + * 0------1 + * | | + * | | + * 3------2 + */ + Vector2D bitmapDrawPos[4]; + bitmapDrawPos[0].x = (int32_t)dxA; + bitmapDrawPos[1].x = (int32_t)dxB; + bitmapDrawPos[2].x = (int32_t)dxB; + bitmapDrawPos[3].x = (int32_t)dxA; + + bitmapDrawPos[0].y = (int32_t)dyC; + bitmapDrawPos[1].y = (int32_t)dyC; + bitmapDrawPos[2].y = (int32_t)dyD; + bitmapDrawPos[3].y = (int32_t)dyD; + /* texture Position : + * 0------1 + * | | + * | | + * 3------2 + */ + texCoord_ts texturePos[4]; + texturePos[0].u = tuA; + texturePos[1].u = tuB; + texturePos[2].u = tuB; + texturePos[3].u = tuA; + + texturePos[0].v = tvC; + texturePos[1].v = tvC; + texturePos[2].v = tvD; + texturePos[3].v = tvD; + + // NOTE : Android does not support the Quads elements ... + /* Step 1 : + * ******** + * ****** + * **** + * ** + * + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[1]); + coordTex.PushBack(texturePos[2]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[1]); + coord.PushBack(bitmapDrawPos[2]); + + /* Step 2 : + * + * ** + * **** + * ****** + * ******** + */ + // set texture coordonates : + coordTex.PushBack(texturePos[0]); + coordTex.PushBack(texturePos[2]); + coordTex.PushBack(texturePos[3]); + // set display positions : + coord.PushBack(bitmapDrawPos[0]); + coord.PushBack(bitmapDrawPos[2]); + coord.PushBack(bitmapDrawPos[3]); + + } + } + posDrawX += m_listElement[charIndex].advance; + int32_t sizeOut = posDrawX - textPos.x; + textPos.x = posDrawX; + return sizeOut; +} + +Vector2D ewol::TexturedFont::GetSize(const etk::UString & unicodeString) +{ + Vector2D outputSize(0,m_height); + for(int32_t iii=0; iii tmpp = GetSize(unicodeString[iii]); + outputSize.x += tmpp.x; + } + return outputSize; +} + + +Vector2D ewol::TexturedFont::GetSize(const uniChar_t unicodeChar) +{ + Vector2D outputSize(0,m_height); + int32_t charIndex; + if (unicodeChar >= 0x80) { + charIndex = 0; + } else if (unicodeChar < 0x20) { + charIndex = 0; + } else if (unicodeChar < 0x80) { + charIndex = unicodeChar - 0x1F; + } else { + for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) { + if (m_listElement[iii].unicodeCharVal == unicodeChar) { + charIndex = iii; + break; + } + } + // TODO : Update if possible the mapping + charIndex = 0; + } + outputSize.x = m_listElement[charIndex].advance; + return outputSize; +} + + diff --git a/Sources/libewol/ewol/font/TexturedFont.h b/Sources/libewol/ewol/font/TexturedFont.h new file mode 100644 index 00000000..b083a159 --- /dev/null +++ b/Sources/libewol/ewol/font/TexturedFont.h @@ -0,0 +1,68 @@ +/** + ******************************************************************************* + * @file ewol/font/TexturedFont.h + * @brief ewol Textured Font system (header) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + + +#ifndef __EWOL_TEXTURED_FONT_H__ +#define __EWOL_TEXTURED_FONT_H__ + +#include +#include + +namespace ewol +{ + class TexturedFont { + private: + int32_t m_size; + int32_t m_height; + ewol::Font* m_font; + ewol::Texture m_texture; + uint32_t m_counter; + etk::Vector m_listElement; + public: + TexturedFont(etk::UString fontName, int32_t size); + ~TexturedFont(void); + 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, + etk::Vector & coordTex); + int32_t Draw(Vector2D textPos, + const uniChar_t unicodeChar, + etk::Vector > & coord, + etk::Vector & coordTex); + Vector2D GetSize(const etk::UString & unicodeString); + Vector2D GetSize(const uniChar_t unicodeChar); + 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(); }; + }; + + +}; + +#endif \ No newline at end of file diff --git a/Sources/libewol/ewol/oObject/2DText.cpp b/Sources/libewol/ewol/oObject/2DText.cpp deleted file mode 100644 index 1a9c1b71..00000000 --- a/Sources/libewol/ewol/oObject/2DText.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/oObject/2DText.cpp - * @brief ewol OpenGl Object system (Sources) - * @author Edouard DUPIN - * @date 09/11/2011 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#include -#include -#include - -#undef __class__ -#define __class__ "ewol::OObject2DText" - -ewol::OObject2DText::OObject2DText(etk::UString FontName, int32_t size, draw::Color textColorFg) -{ - m_textColorFg = textColorFg; - if (FontName == "") { - m_FontId = GetDefaultFontId(); - } else { - EWOL_TODO("pas encore fait..."); - //m_FontId = GetFontIdWithName(FontName); - m_FontId = -1; - return; - } -} -// open with default font ... -ewol::OObject2DText::OObject2DText(void) -{ - m_textColorFg = 0x000000FF; - m_FontId = GetDefaultFontId(); -} - -ewol::OObject2DText::~OObject2DText(void) -{ - -} - -void ewol::OObject2DText::Draw(void) -{ - if (m_coord.Size()<=0) { - // TODO : a remètre ... - //EWOL_WARNING("Nothink to draw..."); - return; - } - glColor4ub(m_textColorFg.r, m_textColorFg.g, m_textColorFg.b, m_textColorFg.a); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_FontTextureId)); - glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays - glVertexPointer( 2, GL_FLOAT, 0, &m_coord[0] ); - glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] ); - glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); - //EWOL_DEBUG("request draw of " << m_coord.Size() << " elements"); - glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays - glDisable(GL_TEXTURE_2D); -} - -void ewol::OObject2DText::Clear(void) -{ - m_coord.Clear(); - m_coordTex.Clear(); -} - -int32_t ewol::OObject2DText::Text(Vector2D textPos, clipping_ts drawClipping, const etk::UString& unicodeString) -{ - m_FontTextureId = 0; - if (m_FontId == -1) { - EWOL_ERROR("Font Id is not corectly defined"); - return 0; - } - return ewol::DrawText(m_FontId, textPos, drawClipping, unicodeString, m_FontTextureId, m_coord, m_coordTex); -} - -int32_t ewol::OObject2DText::Text(Vector2D textPos, clipping_ts drawClipping, const uniChar_t unicodeChar) -{ - m_FontTextureId = 0; - if (m_FontId == -1) { - EWOL_ERROR("Font Id is not corectly defined"); - return 0; - } - return ewol::DrawText(m_FontId, textPos, drawClipping, unicodeChar, m_FontTextureId, m_coord, m_coordTex); -} - - - - diff --git a/Sources/libewol/ewol/oObject/2DText.h b/Sources/libewol/ewol/oObject/2DText.h deleted file mode 100644 index 506a1404..00000000 --- a/Sources/libewol/ewol/oObject/2DText.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/oObject/2DText.h - * @brief ewol OpenGl Object system (header) - * @author Edouard DUPIN - * @date 09/11/2011 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#ifndef __EWOL_O_OBJECT_2D_TEXT_H__ -#define __EWOL_O_OBJECT_2D_TEXT_H__ - -#include -#include - -namespace ewol { - class OObject2DText :public ewol::OObject - { - public: - OObject2DText(etk::UString FontName, int32_t size, draw::Color textColorFg); - OObject2DText(void); - virtual ~OObject2DText(void); - public: - virtual void Draw(void); - // set a specific text - void Clear(void); - int32_t Text(Vector2D textPos, clipping_ts drawClipping, const etk::UString& unicodeString); - int32_t Text(Vector2D textPos, clipping_ts drawClipping, const uniChar_t unicodeChar); - protected: - int32_t m_FontId; //!< font internal ID - draw::Color m_textColorFg; //!< text color ... - int32_t m_FontTextureId; //!< font internal Texture ID - etk::Vector > m_coord; //!< internal coord of the object - etk::Vector m_coordTex; //!< internal texture coordinate for every point - }; -}; - -#endif - diff --git a/Sources/libewol/ewol/oObject/2DTextColored.cpp b/Sources/libewol/ewol/oObject/2DTextColored.cpp index 2a7161c1..812704e7 100644 --- a/Sources/libewol/ewol/oObject/2DTextColored.cpp +++ b/Sources/libewol/ewol/oObject/2DTextColored.cpp @@ -25,59 +25,76 @@ #include #include #include +#include #undef __class__ #define __class__ "ewol::OObject2DTextColored" -ewol::OObject2DTextColored::OObject2DTextColored(etk::UString FontName, int32_t size) +void ewol::OObject2DTextColored::SetFontProperty(etk::UString fontName, int32_t fontSize) { - m_color = draw::color::black; - if (FontName == "") { - m_FontId = GetDefaultFontId(); - } else { - EWOL_TODO("pas encore fait..."); - //m_FontId = GetFontIdWithName(FontName); - m_FontId = -1; + // remove old one + if (NULL != m_font) { + ewol::font::TexturedRelease(m_font); + m_font = NULL; } - /* - m_coord.SetIncrement(50000); - m_coordTex.SetIncrement(50000); - m_coordColor.SetIncrement(50000); - */ + // link to new One + m_font = ewol::font::TexturedKeep(fontName, fontSize); } -ewol::OObject2DTextColored::OObject2DTextColored(int32_t fontID) +void ewol::OObject2DTextColored::SetFont(etk::UString fontName) +{ + // get old size + int32_t fontSize = ewol::font::GetDefaultSize(); + if (NULL != m_font) { + fontSize = m_font->GetFontSize(); + } + SetFontProperty(fontName, fontSize); +} + +void ewol::OObject2DTextColored::SetSize(int32_t fontSize) +{ + // get old size + etk::UString fontName = ewol::font::GetDefaultFont(); + if (NULL != m_font) { + fontName = m_font->GetFontName(); + } + SetFontProperty(fontName, fontSize); +} + +ewol::OObject2DTextColored::OObject2DTextColored(etk::UString fontName, int32_t size) : + m_font(NULL) { m_color = draw::color::black; - if (fontID < 0) { - m_FontId = GetDefaultFontId(); - } else { - m_FontId = fontID; - } + SetFontProperty(fontName, size); } // open with default font ... -ewol::OObject2DTextColored::OObject2DTextColored(void) +ewol::OObject2DTextColored::OObject2DTextColored(void) : + m_font(NULL) { m_color = draw::color::black; - m_FontId = GetDefaultFontId(); + SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize()); } + ewol::OObject2DTextColored::~OObject2DTextColored(void) { - + if (NULL != m_font) { + ewol::font::TexturedRelease(m_font); + m_font = NULL; + } } void ewol::OObject2DTextColored::Draw(void) { - if (m_coord.Size()<=0) { + if (m_coord.Size()<=0 || NULL == m_font) { // TODO : a remètre ... //EWOL_WARNING("Nothink to draw..."); return; } glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_FontTextureId)); + glBindTexture(GL_TEXTURE_2D, m_font->GetTex().GetId()); glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays @@ -101,18 +118,18 @@ void ewol::OObject2DTextColored::Clear(void) int32_t ewol::OObject2DTextColored::Text(Vector2D textPos, const etk::UString& unicodeString) { - m_FontTextureId = 0; - if (m_FontId == -1) { + if (m_font == NULL) { EWOL_ERROR("Font Id is not corectly defined"); return 0; } int32_t nbElementInTheArray = m_coord.Size(); int32_t size = 0; if (true==m_hasClipping) { - size = ewol::DrawText(m_FontId, textPos, m_clipping, unicodeString, m_FontTextureId, m_coord, m_coordTex); + size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex); } else { - size = ewol::DrawText(m_FontId, textPos, unicodeString, m_FontTextureId, m_coord, m_coordTex); + size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex); } + // set the color ... for (int32_t iii=nbElementInTheArray; iii textPos, const etk::USt int32_t ewol::OObject2DTextColored::Text(Vector2D textPos, const uniChar_t unicodeChar) { - m_FontTextureId = 0; - if (m_FontId == -1) { + if (m_font == NULL) { EWOL_ERROR("Font Id is not corectly defined"); return 0; } int32_t nbElementInTheArray = m_coord.Size(); int32_t size = 0; if (true==m_hasClipping) { - size = ewol::DrawText(m_FontId, textPos, m_clipping, unicodeChar, m_FontTextureId, m_coord, m_coordTex); + size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex); } else { - size = ewol::DrawText(m_FontId, textPos, unicodeChar, m_FontTextureId, m_coord, m_coordTex); + size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex); } for (int32_t iii=nbElementInTheArray; iii ewol::OObject2DTextColored::GetSize(const uniChar_t unicodeChar) +{ + if (m_font == NULL) { + EWOL_ERROR("Font Id is not corectly defined"); + return Vector2D(0,0); + } + return m_font->GetSize(unicodeChar); +} + +Vector2D ewol::OObject2DTextColored::GetSize(const etk::UString& unicodeString) +{ + if (m_font == NULL) { + EWOL_ERROR("Font Id is not corectly defined"); + return Vector2D(0,0); + } + return m_font->GetSize(unicodeString); +} diff --git a/Sources/libewol/ewol/oObject/2DTextColored.h b/Sources/libewol/ewol/oObject/2DTextColored.h index 21eaaac2..1be63a14 100644 --- a/Sources/libewol/ewol/oObject/2DTextColored.h +++ b/Sources/libewol/ewol/oObject/2DTextColored.h @@ -26,13 +26,13 @@ #define __EWOL_O_OBJECT_2D_TEXT_COLORED_H__ #include +#include namespace ewol { class OObject2DTextColored :public ewol::OObject { public: OObject2DTextColored(etk::UString FontName, int32_t size); - OObject2DTextColored(int32_t fontID); OObject2DTextColored(void); virtual ~OObject2DTextColored(void); public: @@ -44,15 +44,18 @@ namespace ewol { int32_t Text(Vector2D textPos, const etk::UString& unicodeString); int32_t Text(Vector2D textPos, const uniChar_t unicodeChar); protected: - int32_t m_FontId; //!< font internal ID - draw::Color m_color; //!< tmp text color ... - int32_t m_FontTextureId; //!< font internal Texture ID + ewol::TexturedFont* m_font; //!< ewol font system + draw::Color m_color; //!< tmp text color ... etk::Vector > m_coord; //!< internal coord of the object - etk::Vector m_coordTex; //!< internal texture coordinate for every point - etk::Vector m_coordColor; //!< internal color of the different point + etk::Vector m_coordTex; //!< internal texture coordinate for every point + etk::Vector m_coordColor; //!< internal color of the different point public: - void SetFontID(int32_t fontID) { m_FontId = fontID; }; - int32_t GetFontID(void) { return m_FontId; }; + void SetFont(etk::UString fontName); + void SetSize(int32_t fontSize); + void SetFontProperty(etk::UString fontName, int32_t fontSize); + int32_t GetHeight(void) { return (NULL!=m_font)?m_font->GetHeight():10; }; + Vector2D GetSize(const uniChar_t unicodeChar); + Vector2D GetSize(const etk::UString& unicodeString); }; }; diff --git a/Sources/libewol/ewol/oObject/2DTextured.cpp b/Sources/libewol/ewol/oObject/2DTextured.cpp index 058b743a..25e22cb8 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.cpp +++ b/Sources/libewol/ewol/oObject/2DTextured.cpp @@ -24,29 +24,24 @@ #include #include +#include #include #undef __class__ #define __class__ "ewol::OObject2DTextured" - -ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName) -{ - EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\""); - m_textureId = ewol::texture::Load(textureName); -} ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, float sizeX, float sizeY) { EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\""); - m_textureId = ewol::texture::Load(textureName, sizeX); + m_resource = ewol::textureManager::ImageKeep(textureName, Vector2D(sizeX,sizeY)); } ewol::OObject2DTextured::~OObject2DTextured(void) { - if (-1 != m_textureId) { - ewol::texture::UnLoad(m_textureId); + if (NULL != m_resource) { + ewol::textureManager::ImageRelease(m_resource); } } @@ -55,14 +50,14 @@ void ewol::OObject2DTextured::Draw(void) if (m_coord.Size()<=0) { return; } - if (m_textureId == -1) { + if (NULL == m_resource) { EWOL_WARNING("Texture does not exist ..."); return; } glColor4f(1.0, 1.0, 1.0, 1.0); glEnable(GL_TEXTURE_2D); //EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId)); - glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId)); + glBindTexture(GL_TEXTURE_2D, m_resource->GetId() ); glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays diff --git a/Sources/libewol/ewol/oObject/2DTextured.h b/Sources/libewol/ewol/oObject/2DTextured.h index aac4d34b..4feac448 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.h +++ b/Sources/libewol/ewol/oObject/2DTextured.h @@ -26,14 +26,13 @@ #define __EWOL_O_OBJECT_2D_TEXTURED_H__ #include -#include +#include namespace ewol { class OObject2DTextured :public ewol::OObject { public: - OObject2DTextured(etk::UString textureName); - OObject2DTextured(etk::UString textureName, float sizeX, float sizeY); + OObject2DTextured(etk::UString textureName, float sizeX=-1, float sizeY=-1); virtual ~OObject2DTextured(void); public: virtual void Draw(void); @@ -41,7 +40,7 @@ namespace ewol { void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0, draw::Color tmpColor=draw::color::white); void Rectangle(float x, float y, float w, float h, draw::Color tmpColor); protected: - ewol::Texture + ewol::Texture* m_resource; //!< texture resources etk::Vector > m_coord; //!< internal coord of the object etk::Vector m_coordTex; //!< internal texture coordinate for every point etk::Vector m_coordColor; //!< internal color of the different point diff --git a/Sources/libewol/ewol/oObject/OObject.h b/Sources/libewol/ewol/oObject/OObject.h index eeace492..9003eb45 100644 --- a/Sources/libewol/ewol/oObject/OObject.h +++ b/Sources/libewol/ewol/oObject/OObject.h @@ -73,6 +73,5 @@ namespace ewol { #include #include -#include #include diff --git a/Sources/libewol/ewol/oObject/Sprite.cpp b/Sources/libewol/ewol/oObject/Sprite.cpp index 3a94ea22..ddabd43c 100644 --- a/Sources/libewol/ewol/oObject/Sprite.cpp +++ b/Sources/libewol/ewol/oObject/Sprite.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -31,26 +32,18 @@ #define __class__ "Sprite" - -ewol::Sprite::Sprite(etk::UString spriteName) -{ - m_name = spriteName; - EWOL_VERBOSE("Create Sprite : \"" << m_name << "\""); - m_textureId = ewol::texture::Load(m_name); - -} ewol::Sprite::Sprite(etk::UString spriteName, float sizeX, float sizeY) { m_name = spriteName; EWOL_VERBOSE("Create Sprite : \"" << m_name << "\""); - m_textureId = ewol::texture::Load(m_name, sizeX); + m_resource = ewol::textureManager::ImageKeep(m_name, Vector2D(sizeX,sizeY)); } ewol::Sprite::~Sprite(void) { - if (-1 != m_textureId) { - ewol::texture::UnLoad(m_textureId); + if (NULL != m_resource) { + ewol::textureManager::ImageRelease(m_resource); } } @@ -60,13 +53,13 @@ void ewol::Sprite::Draw(void) //EWOL_WARNING("Nothink to draw..."); return; } - if (m_textureId == -1) { + if (NULL == m_resource) { EWOL_WARNING("Texture does not exist ..."); return; } glEnable(GL_TEXTURE_2D); //EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId)); - glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId)); + glBindTexture(GL_TEXTURE_2D, m_resource->GetId()); glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays diff --git a/Sources/libewol/ewol/oObject/Sprite.h b/Sources/libewol/ewol/oObject/Sprite.h index 0f23b84a..ec95b1b2 100644 --- a/Sources/libewol/ewol/oObject/Sprite.h +++ b/Sources/libewol/ewol/oObject/Sprite.h @@ -26,6 +26,7 @@ #define __EWOL_O_OBJECT_SPRITE_H__ #include +#include namespace ewol { class Sprite :public ewol::OObject @@ -33,8 +34,7 @@ namespace ewol { private: etk::UString m_name; public: - Sprite(etk::UString spriteName); - Sprite(etk::UString spriteName, float sizeX, float sizeY); + Sprite(etk::UString spriteName, float sizeX=-1, float sizeY=-1); virtual ~Sprite(void); virtual void Draw(void); void Clear(void); @@ -44,10 +44,10 @@ namespace ewol { void Element(Vector3D pos, float size, float angle, draw::Color tmpColor); bool HasName(etk::UString& name) { return name == m_name; }; protected: - int32_t m_textureId; //!< texture internal ID + ewol::Texture* m_resource; //!< texture resources etk::Vector > m_coord; //!< internal coord of the object etk::Vector m_coordTex; //!< internal texture coordinate for every point - etk::Vector m_coordColor; //!< internal color of the different point + etk::Vector m_coordColor; //!< internal color of the different point }; }; diff --git a/Sources/libewol/ewol/os/eSystem.cpp b/Sources/libewol/ewol/os/eSystem.cpp index 0516885d..5c2f6205 100644 --- a/Sources/libewol/ewol/os/eSystem.cpp +++ b/Sources/libewol/ewol/os/eSystem.cpp @@ -38,6 +38,7 @@ #include #include #include +#include static ewol::Windows* windowsCurrent = NULL; static Vector2D windowsSize(320, 480); @@ -244,7 +245,7 @@ void eSystem::Init(void) l_managementInput.Reset(); ewol::textureManager::Init(); ewol::widgetManager::Init(); - ewol::InitFont(); + ewol::font::Init(); ewol::shortCut::Init(); APP_Init(); isGlobalSystemInit = true; @@ -265,8 +266,8 @@ void eSystem::UnInit(void) // call application to uninit APP_UnInit(); ewol::shortCut::UnInit(); - ewol::UnInitFont(); ewol::widgetManager::UnInit(); + ewol::font::UnInit(); ewol::EObjectMessageMultiCast::UnInit(); ewol::EObjectManager::UnInit(); ewol::textureManager::UnInit(); diff --git a/Sources/libewol/ewol/resources/ResourcesImage.cpp b/Sources/libewol/ewol/resources/ResourcesImage.cpp deleted file mode 100644 index 49386e3f..00000000 --- a/Sources/libewol/ewol/resources/ResourcesImage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/resources/ResourcesImage.cpp - * @brief ewol Resources image system (sources) - * @author Edouard DUPIN - * @date 21/08/2012 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#include - -ewol::ResourcesImage::ResourcesImage(etk::UString fileName, Vector2D size) : - m_resourceID(0), - m_counter(1), - m_image(size) -{ - m_resourceID = ewol::resourcesManager::Add(this); -} - - -ewol::ResourcesImage::~ResourcesImage(void) -{ - ewol::resourcesManager::Rm(this); -} \ No newline at end of file diff --git a/Sources/libewol/ewol/resources/ResourcesManager.cpp b/Sources/libewol/ewol/resources/ResourcesManager.cpp deleted file mode 100644 index 63f2abec..00000000 --- a/Sources/libewol/ewol/resources/ResourcesManager.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/resources/ResourcesManager.cpp - * @brief ewol Resources manager system (Sources) - * @author Edouard DUPIN - * @date 21/08/2012 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#include -#include -#include -#include -#include - -static etk::Vector l_imageList; - -static uint32_t l_uniqueIdResources = 0; - -void ewol::resourcesManager::Init(void) -{ - // nothing to do in théory then, we clean the buffers : - // NOTE : If we do domething here, then the system does not work corectly - l_imageList.Clear(); - l_uniqueIdResources = 0; -} - -void ewol::resourcesManager::UnInit(void) -{ - for (int32_t iii=0; iii=0; iii--) { - if (l_imageList[iii] != NULL) { - if (l_imageList[iii] == object) { - // we find the texture : - l_imageList.Erase(iii); - return; - } - } - } - EWOL_CRITICAL("Try to remove an Image resources that is not present in the resources pool"); -} - - -ewol::ResourcesImage* ewol::resourcesManager::ImageKeep(etk::UString fileName, Vector2D size) -{ - for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { - if (l_imageList[iii] != NULL) { - if( l_imageList[iii]->HasName(fileName) - && l_imageList[iii]->Get().GetSize() == size) { - l_imageList[iii]->Increment(); - return l_imageList[iii]; - } - } - } - ewol::ResourcesImage* tmpResources = new ewol::ResourcesImage(fileName, size); - if (NULL == tmpResources) { - EWOL_ERROR("allocation error of a resource Image : " << fileName); - return NULL; - } - l_imageList.PushBack(tmpResources); - return tmpResources; -} - -void ewol::resourcesManager::ImageRelease(ewol::ResourcesImage* object) -{ - for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { - if (l_imageList[iii] != NULL) { - if(l_imageList[iii] == object) { - if (true == l_imageList[iii]->Decrement()) { - delete(l_imageList[iii]); - return; - } - } - } - } -} - diff --git a/Sources/libewol/ewol/resources/ResourcesManager.h b/Sources/libewol/ewol/resources/ResourcesManager.h deleted file mode 100644 index d421a101..00000000 --- a/Sources/libewol/ewol/resources/ResourcesManager.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/resources/ResourcesManager.h - * @brief ewol Resources manager system (header) - * @author Edouard DUPIN - * @date 21/08/2012 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#ifndef __EWOL_RESOURCES_MANAGER_H__ -#define __EWOL_RESOURCES_MANAGER_H__ - -#include -#include -#include -#include - -namespace ewol -{ - namespace resourcesManager { - void Init(void); - void UnInit(void); - uint32_t Add(ewol::ResourcesImage* object); - void Rm(ewol::ResourcesImage* object); - //uint32_t Add(audio::Track* object); - //void Rm(audio::Track* object); - - ewol::ResourcesImage* ImageKeep(etk::UString fileName, Vector2D size); - void ImageRelease(ewol::ResourcesImage* object); - //audio::Track* AudioKeep(etk::UString fileName, Vector2D size); - //void AudioRelease(audio::Track* object); - }; -}; - -#endif \ No newline at end of file diff --git a/Sources/libewol/ewol/texture/Texture.cpp b/Sources/libewol/ewol/texture/Texture.cpp index ed9b1802..ddb73e6c 100644 --- a/Sources/libewol/ewol/texture/Texture.cpp +++ b/Sources/libewol/ewol/texture/Texture.cpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -99,7 +100,7 @@ void ewol::Texture::UpdateContext(void) // now the data is loaded m_loaded = true; } else { - EWOL_TODO("UPDATE Texture ...") + EWOL_TODO("UPDATE Texture ..."); } } @@ -128,6 +129,12 @@ void ewol::Texture::Flush(void) } +void ewol::Texture::SetImageSize(Vector2D newSize) +{ + newSize.x = nextP2(newSize.x); + newSize.y = nextP2(newSize.y); + m_data.Resize(newSize); +} diff --git a/Sources/libewol/ewol/texture/Texture.h b/Sources/libewol/ewol/texture/Texture.h index 7396ca04..65483b16 100644 --- a/Sources/libewol/ewol/texture/Texture.h +++ b/Sources/libewol/ewol/texture/Texture.h @@ -31,10 +31,6 @@ #include namespace ewol { - // TODO : remove this deprecated element - namespace texture { - inline int32_t GetGLID(int32_t m_FontTextureId) { return 0; }; - }; class Texture { private: uint32_t m_uniqueId; @@ -59,6 +55,8 @@ namespace ewol { public: Texture(void); ~Texture(void); + // you must set the size here, because it will be set in multiple of pow(2) + void SetImageSize(Vector2D newSize); // get the reference on this image to draw nomething on it ... inline draw::Image& Get(void) { return m_data; }; // Flush the data to send it at the OpenGl system diff --git a/Sources/libewol/ewol/texture/TextureBMP.cpp b/Sources/libewol/ewol/texture/TextureBMP.cpp index 46b4b34c..91a5dadd 100644 --- a/Sources/libewol/ewol/texture/TextureBMP.cpp +++ b/Sources/libewol/ewol/texture/TextureBMP.cpp @@ -22,19 +22,54 @@ ******************************************************************************* */ - +#include +#include #include +#pragma pack(push,1) +typedef struct +{ + int16_t bfType; + int32_t bfSize; + int32_t bfReserved; + int32_t bfOffBits; +} bitmapFileHeader_ts; + +typedef struct +{ + int32_t biSize; + int32_t biWidth; + int32_t biHeight; + int16_t biPlanes; + int16_t biBitCount; + int32_t biCompression; + int32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + int32_t biClrUsed; + int32_t biClrImportant; +} bitmapInfoHeader_ts; +#pragma pack(pop) + +typedef enum { + BITS_16_R5G6B5, + BITS_16_X1R5G5B5, + BITS_24_R8G8B8, + BITS_32_X8R8G8B8, + BITS_32_A8R8G8B8 +} modeBitmap_te; + #undef __class__ #define __class__ "texture::TextureBMP" -ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_dataGenerate(NULL) +void ewol::imageBMP::GenerateImage(etk::File & fileName, draw::Image & ouputImage) { - m_dataMode = BITS_16_R5G6B5; - m_width = 0; - m_height = 0; - m_size = 0; + modeBitmap_te m_dataMode = BITS_16_R5G6B5; + int32_t m_width = 0; + int32_t m_height = 0; + bitmapFileHeader_ts m_FileHeader; + bitmapInfoHeader_ts m_InfoHeader; // Get the fileSize ... /*if (fileName.Size() < (int32_t)(sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) ) { @@ -99,17 +134,21 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da } m_width = m_InfoHeader.biWidth; m_height = m_InfoHeader.biHeight; + // reallocate the image + ouputImage.Resize(Vector2D(m_width,m_height)); + uint8_t* m_data = NULL; if(0 != m_InfoHeader.biSizeImage) { m_data=new uint8_t[m_InfoHeader.biSizeImage]; if (fileName.fRead(m_data,m_InfoHeader.biSizeImage,1) != 1){ EWOL_CRITICAL("Can not read the file with the good size..."); } - // allocate the destination data ... - m_dataGenerate=new uint8_t[m_width*m_height*4]; } fileName.fClose(); + + draw::Color tmpColor(0,0,0,0); + // need now to generate RGBA data ... switch(m_dataMode) { @@ -118,10 +157,11 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da uint16_t * pointer = (uint16_t*)m_data; for(int32_t yyy=0; yyy> 8); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x07E0) >> 3); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF; + tmpColor.r = (int8_t)((*pointer & 0xF800) >> 8); + tmpColor.g = (int8_t)((*pointer & 0x07E0) >> 3); + tmpColor.b = (int8_t)(*pointer << 3); + tmpColor.a = 0xFF; + ouputImage.Set(Vector2D(xxx,yyy), tmpColor); pointer++; } } @@ -132,10 +172,11 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da uint16_t * pointer = (uint16_t*)m_data; for(int32_t yyy=0; yyy> 7); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x03E0) >> 2); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3); - m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF; + tmpColor.r = (int8_t)((*pointer & 0x7C00) >> 7); + tmpColor.g = (int8_t)((*pointer & 0x03E0) >> 2); + tmpColor.b = (int8_t)(*pointer << 3); + tmpColor.a = 0xFF; + ouputImage.Set(Vector2D(xxx,yyy), tmpColor); pointer++; } } @@ -146,10 +187,11 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da uint8_t * pointer = m_data; for(int32_t yyy=0; yyy(xxx,yyy), tmpColor); } } } @@ -160,10 +202,11 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da for(int32_t yyy=0; yyy(xxx,yyy), tmpColor); } } } @@ -173,10 +216,11 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da uint8_t * pointer = m_data; for(int32_t yyy=0; yyy(xxx,yyy), tmpColor); } } } @@ -185,55 +229,12 @@ ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_da EWOL_DEBUG(" mode = ERROR"); break; } -} - -ewol::texture::TextureBMP::~TextureBMP(void) -{ if (NULL != m_data) { delete(m_data); - } - if (NULL != m_dataGenerate) { - delete(m_dataGenerate); + m_data=NULL; } } - -bool ewol::texture::TextureBMP::LoadOK(void) -{ - if (NULL != m_dataGenerate) { - return true; - } else { - return false; - } -}; - -int32_t ewol::texture::TextureBMP::Width(void) -{ - return m_width; -} - - -int32_t ewol::texture::TextureBMP::Height(void) -{ - return m_height; -} - -uint8_t * ewol::texture::TextureBMP::Data(void) -{ - return m_dataGenerate; -}; -uint8_t * ewol::texture::TextureBMP::RawData(void) -{ - return m_data; -}; - -uint32_t ewol::texture::TextureBMP::DataSize(void) -{ - if (NULL == m_dataGenerate) { - return 0; - } - return m_width*m_height*4; -} - +/* void ewol::texture::TextureBMP::Display(void) { if (NULL == m_data) { @@ -284,3 +285,4 @@ void ewol::texture::TextureBMP::Display(void) break; } } +*/ diff --git a/Sources/libewol/ewol/texture/TextureBMP.h b/Sources/libewol/ewol/texture/TextureBMP.h index f0f3980c..0b21da00 100644 --- a/Sources/libewol/ewol/texture/TextureBMP.h +++ b/Sources/libewol/ewol/texture/TextureBMP.h @@ -28,65 +28,13 @@ #include #include #include +#include namespace ewol { - namespace texture { - #pragma pack(push,1) - typedef struct - { - int16_t bfType; - int32_t bfSize; - int32_t bfReserved; - int32_t bfOffBits; - } bitmapFileHeader_ts; - - typedef struct - { - int32_t biSize; - int32_t biWidth; - int32_t biHeight; - int16_t biPlanes; - int16_t biBitCount; - int32_t biCompression; - int32_t biSizeImage; - int32_t biXPelsPerMeter; - int32_t biYPelsPerMeter; - int32_t biClrUsed; - int32_t biClrImportant; - } bitmapInfoHeader_ts; - #pragma pack(pop) - - typedef enum { - BITS_16_R5G6B5, - BITS_16_X1R5G5B5, - BITS_24_R8G8B8, - BITS_32_X8R8G8B8, - BITS_32_A8R8G8B8 - } modeBitmap_te; - - class TextureBMP - { - private: - modeBitmap_te m_dataMode; - int32_t m_width; - int32_t m_height; - int32_t m_size; - uint8_t * m_data; - uint8_t * m_dataGenerate; - bitmapFileHeader_ts m_FileHeader; - bitmapInfoHeader_ts m_InfoHeader; - public: - TextureBMP(etk::File & fileName); - ~TextureBMP(void); - bool LoadOK(void); - int32_t Width(void); - int32_t Height(void); - uint8_t * Data(void); - uint8_t * RawData(void); - uint32_t DataSize(void); - void Display(void); - }; + namespace imageBMP + { + void GenerateImage(etk::File & fileName, draw::Image & ouputImage); }; }; diff --git a/Sources/libewol/ewol/texture/TextureFile.cpp b/Sources/libewol/ewol/texture/TextureFile.cpp new file mode 100644 index 00000000..fc9521d9 --- /dev/null +++ b/Sources/libewol/ewol/texture/TextureFile.cpp @@ -0,0 +1,73 @@ +/** + ******************************************************************************* + * @file ewol/texture/TextureFile.cpp + * @brief ewol tecture file (sources) + * @author Edouard DUPIN + * @date 22/08/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include +#include + + +#include +#include +//#include + + +ewol::TextureFile::TextureFile(etk::UString tmpfileName, Vector2D size) : + m_counter(1), + m_fileName(tmpfileName) +{ + etk::File fileName(tmpfileName, etk::FILE_TYPE_DATA); + if (false == fileName.Exist()) { + EWOL_ERROR("File does not Exist ... " << fileName); + } else { + // get the upper paw2 ot the size requested... + if (size.x>0 && size.y>0) { + m_texture.SetImageSize(size); + } + + etk::UString fileExtention = fileName.GetExtention(); + if (fileExtention == "bmp") { + // generate the texture + ewol::imageBMP::GenerateImage(fileName, m_texture.Get()); + } else if (fileExtention == "svg") { + svg::Parser m_element(fileName); + if (false == m_element.IsLoadOk()) { + EWOL_ERROR("Error To load SVG file " << fileName.GetCompleateName() ); + } else { + m_element.GenerateAnImage(size, m_texture.Get()); + } + } else if (fileExtention == "png") { + EWOL_ERROR("Extention not supported now, but soon " << fileName ); + } else { + EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp / .svg / .png"); + } + m_texture.Flush(); + } +} + + +ewol::TextureFile::~TextureFile(void) +{ + +} + diff --git a/Sources/libewol/ewol/resources/ResourcesImage.h b/Sources/libewol/ewol/texture/TextureFile.h similarity index 66% rename from Sources/libewol/ewol/resources/ResourcesImage.h rename to Sources/libewol/ewol/texture/TextureFile.h index e9d47d76..0805b177 100644 --- a/Sources/libewol/ewol/resources/ResourcesImage.h +++ b/Sources/libewol/ewol/texture/TextureFile.h @@ -1,9 +1,9 @@ /** ******************************************************************************* - * @file ewol/resources/ResourcesImage.h - * @brief ewol Resources image system (header) + * @file ewol/texture/TextureFile.cpp + * @brief ewol tecture file (sources) * @author Edouard DUPIN - * @date 21/08/2012 + * @date 22/08/2012 * @par Project * ewol * @@ -22,28 +22,28 @@ ******************************************************************************* */ -#ifndef __EWOL_RESOURCES_IMAGE_H__ -#define __EWOL_RESOURCES_IMAGE_H__ +#ifndef __EWOL_TEXTURE_FILE_H__ +#define __EWOL_TEXTURE_FILE_H__ #include #include +#include namespace ewol { - class ResourcesImage + class TextureFile { private: - uint32_t m_resourceID; - uint32_t m_counter; - draw::Image m_image; - etk::UString m_fileName; + uint32_t m_counter; + ewol::Texture m_texture; + etk::UString m_fileName; public: - ResourcesImage(etk::UString fileName, Vector2D size); - ~ResourcesImage(void); + TextureFile(etk::UString fileName, Vector2D size); + ~TextureFile(void); bool HasName(etk::UString& fileName) { return fileName==m_fileName; }; void Increment(void) { m_counter++; }; bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; }; - draw::Image& Get(void) { return m_image; }; + ewol::Texture& Get(void) { return m_texture; }; }; }; diff --git a/Sources/libewol/ewol/texture/TextureManager.cpp b/Sources/libewol/ewol/texture/TextureManager.cpp index 15e41a91..62390559 100644 --- a/Sources/libewol/ewol/texture/TextureManager.cpp +++ b/Sources/libewol/ewol/texture/TextureManager.cpp @@ -27,10 +27,11 @@ #include #include #include +#include -static etk::Vector l_textureList; -static etk::Vector l_textureListToUpdate; +static etk::Vector l_textureList; +static etk::Vector l_textureListToUpdate; static uint32_t l_uniqueIdTexture = 0; static bool l_contextHasBeenRemoved = true; @@ -117,7 +118,7 @@ void ewol::textureManager::Update(ewol::Texture *object) } } // add it ... - l_textureListToUpdate.pushBack(object); + l_textureListToUpdate.PushBack(object); } // Specific to load or update the data in the openGl context ==> system use only @@ -153,3 +154,49 @@ void ewol::textureManager::OpenGlContextHasBeenDestroyed(void) l_contextHasBeenRemoved = true; } + +static etk::Vector l_imageList; + + +// this permit to keep a specific texture and prevent the multiple loading of this one ... +ewol::Texture* ewol::textureManager::ImageKeep(etk::UString fileName, Vector2D size) +{ + + for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { + if (l_imageList[iii] != NULL) { + if( l_imageList[iii]->HasName(fileName) + && l_imageList[iii]->Get().Get().GetWidth() == size.x + && l_imageList[iii]->Get().Get().GetHeight() == size.y) { + l_imageList[iii]->Increment(); + return &l_imageList[iii]->Get(); + } + } + } + ewol::TextureFile* tmpResources = new ewol::TextureFile(fileName, size); + if (NULL == tmpResources) { + EWOL_ERROR("allocation error of a resource Image : " << fileName); + return NULL; + } + l_imageList.PushBack(tmpResources); + return &tmpResources->Get(); +} + +void ewol::textureManager::ImageRelease(ewol::Texture*& object) +{ + for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) { + if (l_imageList[iii] != NULL) { + if(&l_imageList[iii]->Get() == object) { + if (true == l_imageList[iii]->Decrement()) { + // delete element + delete(l_imageList[iii]); + // remove element from the list : + l_imageList.Erase(iii); + } + // insidiously remove the pointer for the caller ... + object = NULL; + return; + } + } + } +} + diff --git a/Sources/libewol/ewol/texture/TextureManager.h b/Sources/libewol/ewol/texture/TextureManager.h index eaec0c0b..6525e6bb 100644 --- a/Sources/libewol/ewol/texture/TextureManager.h +++ b/Sources/libewol/ewol/texture/TextureManager.h @@ -41,6 +41,9 @@ namespace ewol // Specific to load or update the data in the openGl context ==> system use only void UpdateContext(void); void OpenGlContextHasBeenDestroyed(void); + // this permit to keep a specific texture and prevent the multiple loading of this one ... + ewol::Texture* ImageKeep(etk::UString fileName, Vector2D size); + void ImageRelease(ewol::Texture*& object); }; }; diff --git a/Sources/libewol/ewol/widget/Button.cpp b/Sources/libewol/ewol/widget/Button.cpp index 8edfeaa7..798a782b 100644 --- a/Sources/libewol/ewol/widget/Button.cpp +++ b/Sources/libewol/ewol/widget/Button.cpp @@ -52,6 +52,7 @@ void ewol::WIDGET_ButtonInit(void) void ewol::Button::Init(void) { + m_oObjectImage=NULL; AddEventId(ewolEventButtonPressed); AddEventId(ewolEventButtonDown); AddEventId(ewolEventButtonUp); @@ -112,16 +113,14 @@ void ewol::Button::SetPadding(Vector2D newPadding) bool ewol::Button::CalculateMinSize(void) { - int32_t fontId = GetDefaultFontId(); - int32_t minWidth = ewol::GetWidth(fontId, m_label); - int32_t minHeight = ewol::GetHeight(fontId); - m_minSize.x = m_padding.x*2 + minWidth; - m_minSize.y = m_padding.y*2 + minHeight; + Vector2D minSize = m_oObjectText.GetSize(m_label); + m_minSize.x = m_padding.x*2 + minSize.x; + m_minSize.y = m_padding.y*2 + minSize.y; // Add the image element ... if (true == m_hasAnImage) { //m_minSize.x += -m_padding.x + m_padding.y*2 + minHeight; //m_minSize.y += m_padding.y*2; - m_minSize.x += m_padding.x + minHeight; + m_minSize.x += m_padding.x + minSize.y; } MarkToRedraw(); @@ -152,12 +151,18 @@ bool ewol::Button::GetValue(void) return false; } +void ewol::Button::OnDraw(DrawProperty& displayProp) +{ + m_oObjectDecoration.Draw(); + if (NULL != m_oObjectImage) { + m_oObjectImage->Draw(); + } + m_oObjectText.Draw(); +} void ewol::Button::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { - // clean the object list ... - ClearOObjectList(); int32_t tmpSizeX = m_minSize.x; int32_t tmpSizeY = m_minSize.y; @@ -183,15 +188,9 @@ void ewol::Button::OnRegenerateDisplay(void) tmpSizeX -= 2*m_padding.x; tmpSizeY -= 2*m_padding.y; - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); - /* - int32_t fontId = GetDefaultFontId(); - int32_t fontHeight = ewol::GetHeight(fontId); - int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str()); - */ Vector2D textPos(tmpTextOriginX, tmpTextOriginY); - ewol::OObject2DTextured * tmpImage = NULL; + /*ewol::OObject2DTextured * tmpImage = NULL; if (true == m_hasAnImage) { int32_t fontId = GetDefaultFontId(); int32_t fontHeight = ewol::GetHeight(fontId); @@ -200,31 +199,21 @@ void ewol::Button::OnRegenerateDisplay(void) // update the text position ... textPos.x += m_padding.x + fontHeight; } + */ clipping_ts drawClipping; drawClipping.x = m_padding.x; drawClipping.y = m_padding.y; drawClipping.w = m_size.x - 2*m_padding.x; drawClipping.h = m_size.y - 2*m_padding.y; EWOL_DEBUG("draw tex at pos : " <Text(textPos, drawClipping, m_label); + m_oObjectText.Text(textPos/*, drawClipping*/, m_label); - ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->SetColor(m_textColorBg); + m_oObjectDecoration.SetColor(m_textColorBg); tmpOriginX -= m_padding.x/2; tmpOriginY -= m_padding.y/2; tmpSizeX += m_padding.x/1; tmpSizeY += m_padding.y/1; - tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); - // add all needed objects ... - if (NULL != tmpOObjects) { - AddOObject(tmpOObjects); - } - if (NULL != tmpImage) { - AddOObject(tmpImage); - } - if (NULL != tmpText) { - AddOObject(tmpText); - } + m_oObjectDecoration.Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); } } diff --git a/Sources/libewol/ewol/widget/Button.h b/Sources/libewol/ewol/widget/Button.h index ef4d8c17..4df3417f 100644 --- a/Sources/libewol/ewol/widget/Button.h +++ b/Sources/libewol/ewol/widget/Button.h @@ -27,7 +27,8 @@ #include #include -#include +#include +#include extern const char * const ewolEventButtonPressed; extern const char * const ewolEventButtonDown; @@ -40,7 +41,7 @@ namespace ewol { TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, } textAlignement_te; - class Button :public ewol::Drawable + class Button : public ewol::Widget { public: Button(void); @@ -65,15 +66,19 @@ namespace ewol { void SetColorBg(draw::Color newColor) { m_textColorBg = newColor; }; void SetColorFg(draw::Color newColor) { m_textColorFg = newColor; }; private: + ewol::OObject2DTextColored m_oObjectText; + ewol::OObject2DColored m_oObjectDecoration; + ewol::OObject2DTextured* m_oObjectImage; bool m_hasAnImage; etk::UString m_imageSelected; textAlignement_te m_alignement; Vector2D m_padding; etk::UString m_label; - draw::Color m_textColorFg; //!< Text color - draw::Color m_textColorBg; //!< Background color + draw::Color m_textColorFg; //!< Text color + draw::Color m_textColorBg; //!< Background color public: - virtual void OnRegenerateDisplay(void); + virtual void OnRegenerateDisplay(void); + virtual void OnDraw(DrawProperty& displayProp); /** * @brief Event on an input of this Widget * @param[in] type Type of the input (ewol::INPUT_TYPE_MOUSE/ewol::INPUT_TYPE_FINGER ...) diff --git a/Sources/libewol/ewol/widget/ButtonColor.cpp b/Sources/libewol/ewol/widget/ButtonColor.cpp index 79c0c0e7..3ce36b00 100644 --- a/Sources/libewol/ewol/widget/ButtonColor.cpp +++ b/Sources/libewol/ewol/widget/ButtonColor.cpp @@ -95,11 +95,9 @@ void ewol::ButtonColor::SetPadding(Vector2D newPadding) bool ewol::ButtonColor::CalculateMinSize(void) { - int32_t fontId = GetDefaultFontId(); - int32_t minWidth = ewol::GetWidth(fontId, m_label); - int32_t minHeight = ewol::GetHeight(fontId); - m_minSize.x = m_padding.x*2 + minWidth; - m_minSize.y = m_padding.y*2 + minHeight; + Vector2D minSize = m_oObjectText.GetSize(m_label); + m_minSize.x = m_padding.x*2 + minSize.x; + m_minSize.y = m_padding.y*2 + minSize.y; MarkToRedraw(); return true; } @@ -128,12 +126,16 @@ bool ewol::ButtonColor::GetValue(void) return false; } +void ewol::ButtonColor::OnDraw(DrawProperty& displayProp) +{ + m_oObjectDecoration.Draw(); + m_oObjectText.Draw(); +} + void ewol::ButtonColor::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { - // clean the object list ... - ClearOObjectList(); int32_t tmpSizeX = m_minSize.x; int32_t tmpSizeY = m_minSize.y; @@ -164,12 +166,6 @@ void ewol::ButtonColor::OnRegenerateDisplay(void) } else { m_textColorFg = draw::color::white; } - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); - /* - int32_t fontId = GetDefaultFontId(); - int32_t fontHeight = ewol::GetHeight(fontId); - int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str()); - */ Vector2D textPos; textPos.x = tmpTextOriginX; textPos.y = tmpTextOriginY; @@ -178,18 +174,14 @@ void ewol::ButtonColor::OnRegenerateDisplay(void) drawClipping.y = m_padding.y; drawClipping.w = m_size.x - 2*m_padding.x; drawClipping.h = m_size.y - 2*m_padding.y; - tmpText->Text(textPos, drawClipping, m_label); + m_oObjectText.Text(textPos/*, drawClipping*/, m_label); - ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->SetColor(m_textColorBg); + m_oObjectDecoration.SetColor(m_textColorBg); tmpOriginX -= m_padding.x/2; tmpOriginY -= m_padding.y/2; tmpSizeX += m_padding.x/1; tmpSizeY += m_padding.y/1; - tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); - AddOObject(tmpOObjects); - - AddOObject(tmpText); + m_oObjectDecoration.Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); } } diff --git a/Sources/libewol/ewol/widget/ButtonColor.h b/Sources/libewol/ewol/widget/ButtonColor.h index aa63276b..04edaf0c 100644 --- a/Sources/libewol/ewol/widget/ButtonColor.h +++ b/Sources/libewol/ewol/widget/ButtonColor.h @@ -27,14 +27,15 @@ #include #include -#include #include #include +#include +#include extern const char * const ewolEventButtonColorChange; namespace ewol { - class ButtonColor :public ewol::Drawable + class ButtonColor : public ewol::Widget { public: ButtonColor(void); @@ -56,15 +57,18 @@ namespace ewol { void SetAlignement(textAlignement_te typeAlign); void SetPadding(Vector2D newPadding); private: - textAlignement_te m_alignement; + ewol::OObject2DTextColored m_oObjectText; + ewol::OObject2DColored m_oObjectDecoration; + textAlignement_te m_alignement; Vector2D m_padding; - etk::UString m_label; - draw::Color m_textColorFg; //!< Text color - draw::Color m_textColorBg; //!< Background color - draw::Color m_selectedColor; //!< user current selected Color - ewol::ContextMenu* m_widgetContextMenu; + etk::UString m_label; + draw::Color m_textColorFg; //!< Text color + draw::Color m_textColorBg; //!< Background color + draw::Color m_selectedColor; //!< user current selected Color + ewol::ContextMenu* m_widgetContextMenu; public: - virtual void OnRegenerateDisplay(void); + virtual void OnRegenerateDisplay(void); + virtual void OnDraw(DrawProperty& displayProp); public: /** * @brief Event on an input of this Widget diff --git a/Sources/libewol/ewol/widget/ButtonImage.h b/Sources/libewol/ewol/widget/ButtonImage.h index 9f0fe224..dfb3da8d 100644 --- a/Sources/libewol/ewol/widget/ButtonImage.h +++ b/Sources/libewol/ewol/widget/ButtonImage.h @@ -55,15 +55,15 @@ namespace ewol { etk::UString m_image; bool m_resetNeeded; ewol::OObject2DTextured* m_OOImage; - draw::Color m_color; + draw::Color m_color; etk::UString m_imageBg1; ewol::OObject2DTextured* m_OOImageBg1; - draw::Color m_colorBg1; + draw::Color m_colorBg1; etk::UString m_imageBg2; ewol::OObject2DTextured* m_OOImageBG2; - draw::Color m_colorBg2; + draw::Color m_colorBg2; bool m_over; bool m_down; diff --git a/Sources/libewol/ewol/widget/CheckBox.cpp b/Sources/libewol/ewol/widget/CheckBox.cpp index aad8a6bd..d0fb201f 100644 --- a/Sources/libewol/ewol/widget/CheckBox.cpp +++ b/Sources/libewol/ewol/widget/CheckBox.cpp @@ -66,12 +66,10 @@ ewol::CheckBox::~CheckBox(void) bool ewol::CheckBox::CalculateMinSize(void) { - int32_t fontId = GetDefaultFontId(); - int32_t minWidth = ewol::GetWidth(fontId, m_label); - int32_t minHeight = ewol::GetHeight(fontId); - float boxSize = etk_max(20, minHeight) + 5; - m_minSize.x = boxSize+minWidth; - m_minSize.y = etk_max(boxSize, minHeight)+3; + Vector2D minSize = m_oObjectText.GetSize(m_label); + float boxSize = etk_max(20, minSize.y) + 5; + m_minSize.x = boxSize+minSize.x; + m_minSize.y = etk_max(boxSize, minSize.y)+3; MarkToRedraw(); return true; } @@ -80,6 +78,7 @@ bool ewol::CheckBox::CalculateMinSize(void) void ewol::CheckBox::SetLabel(etk::UString newLabel) { m_label = newLabel; + MarkToRedraw(); } void ewol::CheckBox::SetValue(bool val) @@ -96,22 +95,23 @@ bool ewol::CheckBox::GetValue(void) return m_value; } +void ewol::CheckBox::OnDraw(DrawProperty& displayProp) +{ + m_oObjectDecoration.Draw(); + m_oObjectText.Draw(); +} void ewol::CheckBox::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { - // clean the object list ... - ClearOObjectList(); int32_t borderWidth = 2; - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); - int32_t fontId = GetDefaultFontId(); - int32_t fontHeight = ewol::GetHeight(fontId); - float boxSize = etk_max(20, fontHeight); + Vector2D minSize = m_oObjectText.GetSize(m_label); + float boxSize = etk_max(20, minSize.y) + 5; //int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str()); - int32_t posy = (m_size.y - fontHeight - 6)/2 + 3; + int32_t posy = (m_size.y - minSize.y - 6)/2 + 3; //int32_t posx = (m_size.x - fontWidth - 6)/2 + 25; @@ -124,22 +124,18 @@ void ewol::CheckBox::OnRegenerateDisplay(void) // note : pb on the clipping properties ... drawClipping.w = m_size.x;// - (boxSize+5); drawClipping.h = m_size.y; - tmpText->Text(textPos, drawClipping, m_label); + m_oObjectText.Text(textPos/*, drawClipping*/, m_label); - ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->SetColor(m_textColorBg); - tmpOObjects->Rectangle( 2.5, 2.5, boxSize, boxSize); - tmpOObjects->SetColor(m_textColorFg); - tmpOObjects->RectangleBorder( 2.5, 2.5, boxSize, boxSize, borderWidth); + m_oObjectDecoration.SetColor(m_textColorBg); + m_oObjectDecoration.Rectangle( 2.5, 2.5, boxSize, boxSize); + m_oObjectDecoration.SetColor(m_textColorFg); + m_oObjectDecoration.RectangleBorder( 2.5, 2.5, boxSize, boxSize, borderWidth); if (m_value) { - tmpOObjects->Line( 2.5, 2.5, boxSize+2.5, boxSize+2.5, borderWidth); - tmpOObjects->Line( 2.5, boxSize+2.5, boxSize+2.5, 2.5, borderWidth); + m_oObjectDecoration.Line( 2.5, 2.5, boxSize+2.5, boxSize+2.5, borderWidth); + m_oObjectDecoration.Line( 2.5, boxSize+2.5, boxSize+2.5, 2.5, borderWidth); } - - AddOObject(tmpOObjects); - AddOObject(tmpText); } } diff --git a/Sources/libewol/ewol/widget/CheckBox.h b/Sources/libewol/ewol/widget/CheckBox.h index 1eb4cf14..06a3a16e 100644 --- a/Sources/libewol/ewol/widget/CheckBox.h +++ b/Sources/libewol/ewol/widget/CheckBox.h @@ -27,12 +27,13 @@ #include #include -#include +#include +#include extern const char* const ewolEventCheckBoxClicked; namespace ewol { - class CheckBox :public ewol::Drawable + class CheckBox : public ewol::Widget { public: CheckBox(void); @@ -51,12 +52,15 @@ namespace ewol { void SetValue(bool val); bool GetValue(void); private: + ewol::OObject2DTextColored m_oObjectText; + ewol::OObject2DColored m_oObjectDecoration; etk::UString m_label; bool m_value; draw::Color m_textColorFg; //!< Text color draw::Color m_textColorBg; //!< Background color public: - virtual void OnRegenerateDisplay(void); + virtual void OnRegenerateDisplay(void); + virtual void OnDraw(DrawProperty& displayProp); public: /** * @brief Event on an input of this Widget diff --git a/Sources/libewol/ewol/widget/Entry.cpp b/Sources/libewol/ewol/widget/Entry.cpp index ea6ad243..10c6ef33 100644 --- a/Sources/libewol/ewol/widget/Entry.cpp +++ b/Sources/libewol/ewol/widget/Entry.cpp @@ -83,8 +83,7 @@ ewol::Entry::~Entry(void) bool ewol::Entry::CalculateMinSize(void) { - int32_t fontId = GetDefaultFontId(); - int32_t minHeight = ewol::GetHeight(fontId); + int32_t minHeight = m_oObjectText.GetHeight(); m_minSize.x = m_userSize; m_minSize.y = minHeight + 2*(m_borderSize + 2*m_paddingSize); UpdateTextPosition(); @@ -106,15 +105,16 @@ etk::UString ewol::Entry::GetValue(void) return m_data; } +void ewol::Entry::OnDraw(DrawProperty& displayProp) +{ + m_oObjectDecoration.Draw(); + m_oObjectText.Draw(); +} void ewol::Entry::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { UpdateTextPosition(); - // clean the object list ... - ClearOObjectList(); - - // TODO later : Add this in the basic element of the widget ... int32_t tmpSizeX = m_minSize.x; int32_t tmpSizeY = m_minSize.y; @@ -137,7 +137,6 @@ void ewol::Entry::OnRegenerateDisplay(void) tmpSizeX -= 2*m_paddingSize; tmpSizeY -= 2*m_paddingSize; - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); Vector2D textPos; textPos.x = tmpTextOriginX + m_displayStartPosition; @@ -147,25 +146,20 @@ void ewol::Entry::OnRegenerateDisplay(void) drawClipping.y = 2*m_paddingSize + m_borderSize; drawClipping.w = m_size.x;// - (m_borderSize + 2*m_paddingSize); drawClipping.h = m_size.y; - tmpText->Text(textPos, drawClipping, m_data); + m_oObjectText.Text(textPos/*, drawClipping*/, m_data); - ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; - tmpOObjects->SetColor(m_textColorBg); - tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); - tmpOObjects->SetColor(m_textColorFg); - tmpOObjects->RectangleBorder( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY, m_borderSize); + m_oObjectDecoration.SetColor(m_textColorBg); + m_oObjectDecoration.Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY); + m_oObjectDecoration.SetColor(m_textColorFg); + m_oObjectDecoration.RectangleBorder( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY, m_borderSize); if (true == m_displayCursor) { - int32_t fontId = GetDefaultFontId(); - int32_t fontHeight = ewol::GetHeight(fontId); etk::UString tmpDisplay = m_data.Extract(0, m_displayCursorPos); - int32_t fontWidth = ewol::GetWidth(fontId, tmpDisplay); - int32_t XCursorPos = fontWidth + m_borderSize + 2*m_paddingSize + m_displayStartPosition; + Vector2D minSize = m_oObjectText.GetSize(tmpDisplay); + int32_t XCursorPos = minSize.x + m_borderSize + 2*m_paddingSize + m_displayStartPosition; if (XCursorPos >= m_borderSize + 2*m_paddingSize) { - tmpOObjects->Line(XCursorPos, tmpTextOriginY, XCursorPos, tmpTextOriginY + fontHeight, 1); + m_oObjectDecoration.Line(XCursorPos, tmpTextOriginY, XCursorPos, tmpTextOriginY + minSize.y, 1); } } - AddOObject(tmpOObjects); - AddOObject(tmpText); } } @@ -188,15 +182,14 @@ bool ewol::Entry::OnEventInput(ewol::inputType_te type, int32_t IdInput, eventIn MarkToRedraw(); Vector2D relPos = RelativePosition(pos); // try to find the new cursor position : - int32_t fontId = GetDefaultFontId(); etk::UString tmpDisplay = m_data.Extract(0, m_displayStartPosition); - int32_t displayHidenSize = ewol::GetWidth(fontId, tmpDisplay); + int32_t displayHidenSize = m_oObjectText.GetSize(tmpDisplay).x; //EWOL_DEBUG("hidenSize : " << displayHidenSize); int32_t newCursorPosition = -1; int32_t tmpTextOriginX = m_borderSize + 2*m_paddingSize; for (int32_t iii=0; iii=relPos.x-tmpTextOriginX) { newCursorPosition = iii; break; @@ -293,14 +286,12 @@ bool ewol::Entry::OnEventKbMove(eventKbType_te typeEvent, eventKbMoveType_te mov void ewol::Entry::UpdateTextPosition(void) { - int32_t fontId = GetDefaultFontId(); - int32_t tmpSizeX = m_minSize.x; if (true==m_userFillX) { tmpSizeX = m_size.x; } int32_t tmpUserSize = tmpSizeX - 2*(m_borderSize + 2*m_paddingSize); - int32_t totalWidth = ewol::GetWidth(fontId, m_data); + int32_t totalWidth = m_oObjectText.GetSize(m_data).x; if (totalWidth < tmpUserSize) { m_displayStartPosition = 0; } else { diff --git a/Sources/libewol/ewol/widget/Entry.h b/Sources/libewol/ewol/widget/Entry.h index 67e9465d..ad995aa0 100644 --- a/Sources/libewol/ewol/widget/Entry.h +++ b/Sources/libewol/ewol/widget/Entry.h @@ -27,14 +27,15 @@ #include #include -#include +#include +#include extern const char * const ewolEventEntryClick; extern const char * const ewolEventEntryEnter; extern const char * const ewolEventEntryModify; // return in the data the new string inside it ... namespace ewol { - class Entry :public ewol::Drawable + class Entry : public ewol::Widget { public: Entry(void); @@ -56,6 +57,8 @@ namespace ewol { m_userSize = width; } private: + ewol::OObject2DTextColored m_oObjectText; + ewol::OObject2DColored m_oObjectDecoration; etk::UString m_data; draw::Color m_textColorFg; //!< Text color draw::Color m_textColorBg; //!< Background color @@ -67,7 +70,8 @@ namespace ewol { void UpdateTextPosition(void); bool m_displayCursor; public: - virtual void OnRegenerateDisplay(void); + virtual void OnRegenerateDisplay(void); + virtual void OnDraw(DrawProperty& displayProp); public: /** * @brief Event on an input of this Widget diff --git a/Sources/libewol/ewol/widget/Label.cpp b/Sources/libewol/ewol/widget/Label.cpp index 89e00483..9abb1c5b 100644 --- a/Sources/libewol/ewol/widget/Label.cpp +++ b/Sources/libewol/ewol/widget/Label.cpp @@ -64,12 +64,9 @@ ewol::Label::~Label(void) bool ewol::Label::CalculateMinSize(void) { - int32_t fontId = GetDefaultFontId(); - int32_t minWidth = ewol::GetWidth(fontId, m_label); - int32_t minHeight = ewol::GetHeight(fontId); - m_minSize.x = 3+minWidth; - m_minSize.y = 3+minHeight; - MarkToRedraw(); + Vector2D minSize = m_oObjectText.GetSize(m_label); + m_minSize.x = 3 + minSize.x; + m_minSize.y = 3 + minSize.y; return true; } @@ -80,13 +77,15 @@ void ewol::Label::SetLabel(etk::UString newLabel) MarkToRedraw(); } +void ewol::Label::OnDraw(DrawProperty& displayProp) +{ + m_oObjectText.Draw(); +} + void ewol::Label::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { - // clean the object list ... - ClearOObjectList(); - int32_t paddingSize = 3; int32_t tmpOriginX = 0; @@ -101,7 +100,6 @@ void ewol::Label::OnRegenerateDisplay(void) tmpOriginX += paddingSize; tmpOriginY += paddingSize; - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg); Vector2D textPos(tmpOriginX, tmpOriginY); clipping_ts drawClipping; @@ -109,9 +107,7 @@ void ewol::Label::OnRegenerateDisplay(void) drawClipping.y = paddingSize; drawClipping.w = m_size.x - 2*paddingSize; drawClipping.h = m_size.y - 2*paddingSize; - tmpText->Text(textPos, drawClipping, m_label); - - AddOObject(tmpText); + m_oObjectText.Text(textPos/*, drawClipping*/, m_label); } } diff --git a/Sources/libewol/ewol/widget/Label.h b/Sources/libewol/ewol/widget/Label.h index 701b2b9e..a40ed6a3 100644 --- a/Sources/libewol/ewol/widget/Label.h +++ b/Sources/libewol/ewol/widget/Label.h @@ -27,12 +27,13 @@ #include #include -#include +#include +#include extern const char * const ewolEventLabelPressed; namespace ewol { - class Label :public ewol::Drawable + class Label : public ewol::Widget { public: Label(void); @@ -49,10 +50,12 @@ namespace ewol { virtual bool CalculateMinSize(void); void SetLabel(etk::UString newLabel); private: + ewol::OObject2DTextColored m_oObjectText; etk::UString m_label; draw::Color m_textColorFg; //!< Text color public: - virtual void OnRegenerateDisplay(void); + virtual void OnRegenerateDisplay(void); + virtual void OnDraw(DrawProperty& displayProp); public: /** * @brief Event on an input of this Widget diff --git a/Sources/libewol/ewol/widget/List.cpp b/Sources/libewol/ewol/widget/List.cpp index 21d186f7..52f3aad8 100644 --- a/Sources/libewol/ewol/widget/List.cpp +++ b/Sources/libewol/ewol/widget/List.cpp @@ -128,11 +128,13 @@ void ewol::List::OnRegenerateDisplay(void) }*/ tmpOriginX += m_paddingSizeX; tmpOriginY += m_paddingSizeY; - + // TODO : Rework this corectly ... + /* int32_t fontId = GetDefaultFontId(); //int32_t minWidth = ewol::GetWidth(fontId, m_label); int32_t minHeight = ewol::GetHeight(fontId); - + */ + int32_t minHeight = 25; //uint32_t nbColomn = GetNuberOfColomn(); int32_t nbRaw = GetNuberOfRaw(); @@ -178,12 +180,12 @@ void ewol::List::OnRegenerateDisplay(void) BGOObjects->SetColor(bg); BGOObjects->Rectangle(0, m_size.y - tmpOriginY, m_size.x, minHeight+2*m_paddingSizeY); - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, fg); + ewol::OObject2DTextColored * tmpText = new ewol::OObject2DTextColored(); Vector2D textPos; textPos.x = tmpOriginX; textPos.y = m_size.y - tmpOriginY + m_paddingSizeY; - tmpText->Text(textPos, drawClipping, myTextToWrite); + tmpText->Text(textPos/*, drawClipping*/, myTextToWrite); AddOObject(tmpText); tmpOriginY += minHeight + 2* m_paddingSizeY; @@ -215,9 +217,13 @@ bool ewol::List::OnEventInput(ewol::inputType_te type, int32_t IdInput, eventInp // nothing to do ... done on upper widet ... return true; } + // TODO : Rework this ... + /* int32_t fontId = GetDefaultFontId(); //int32_t minWidth = ewol::GetWidth(fontId, m_label.c_str()); int32_t minHeight = ewol::GetHeight(fontId); + */ + int32_t minHeight =20; int32_t rawID = (relativePos.y+m_originScrooled.y) / (minHeight + 2*m_paddingSizeY); //EWOL_DEBUG("OnEventInput(" << IdInput << "," << typeEvent << "," << 0 << "," << rawID << "," << x <<"," << y << ");"); diff --git a/Sources/libewol/ewol/widget/meta/ParameterList.cpp b/Sources/libewol/ewol/widget/meta/ParameterList.cpp index 601d4e3b..01608013 100644 --- a/Sources/libewol/ewol/widget/meta/ParameterList.cpp +++ b/Sources/libewol/ewol/widget/meta/ParameterList.cpp @@ -136,10 +136,13 @@ void ewol::ParameterList::OnRegenerateDisplay(void) tmpOriginX += m_paddingSizeX; tmpOriginY += m_paddingSizeY; + /* int32_t fontId = GetDefaultFontId(); //int32_t minWidth = ewol::GetWidth(fontId, m_label); int32_t minHeight = ewol::GetHeight(fontId); - + */ + // TODO : Rework this ... + int32_t minHeight=20; //uint32_t nbColomn = GetNuberOfColomn(); int32_t nbRaw = m_list.Size(); @@ -181,7 +184,7 @@ void ewol::ParameterList::OnRegenerateDisplay(void) myTextToWrite = m_list[iii]->m_label; } - ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, fg); + ewol::OObject2DTextColored * tmpText = new ewol::OObject2DTextColored(); Vector2D textPos; textPos.x = (int32_t)tmpOriginX; @@ -189,7 +192,7 @@ void ewol::ParameterList::OnRegenerateDisplay(void) textPos.x += minHeight; } textPos.y = (int32_t)(tmpOriginY + m_paddingSizeY); - tmpText->Text(textPos, drawClipping, myTextToWrite); + tmpText->Text(textPos/*, drawClipping*/, myTextToWrite); AddOObject(tmpText); tmpOriginY -= minHeight + 2* m_paddingSizeY; @@ -221,10 +224,13 @@ bool ewol::ParameterList::OnEventInput(ewol::inputType_te type, int32_t IdInput, Vector2D relativePos = RelativePosition(pos); // corection for the openGl abstraction relativePos.y = m_size.y - relativePos.y; + // TODO : Rework this ... + /* int32_t fontId = GetDefaultFontId(); //int32_t minWidth = ewol::GetWidth(fontId, m_label.c_str()); int32_t minHeight = ewol::GetHeight(fontId); - + */ + int32_t minHeight = 20; int32_t rawID = (relativePos.y+m_originScrooled.y) / (minHeight + 2*m_paddingSizeY); // generate an event on a rawId if the element request change and Select it ... if (rawID >=0 && rawID