diff --git a/Sources/Main.cpp b/Sources/Main.cpp index dce4176b..b36bd409 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -24,6 +24,7 @@ #include +#include #include #include @@ -55,6 +56,11 @@ int main(int argc, char *argv[]) ewol::Init(argc, argv); + + if (true == ewol::AddFont("dataTest/TextMonospace.ebt", true, true, true) ) { + //fontID = GetFontIdWithFileName("dataTest/TextMonospace.ebt"); + } + // create the specific windows ewol::DisplayWindows(myWindowsExample); diff --git a/Sources/ewol.cpp b/Sources/ewol.cpp index 0a26817c..e04c7a7a 100644 --- a/Sources/ewol.cpp +++ b/Sources/ewol.cpp @@ -24,6 +24,7 @@ #include "ewol.h" +#include "ewolFont.h" #if __PLATFORM__ == X11 #include "guiX11.h" @@ -59,6 +60,7 @@ void ewol::Run(void) void ewol::UnInit(void) { guiAbstraction::UnInit(); + ewol::UnInitFont(); } diff --git a/Sources/ewolFont.cpp b/Sources/ewolFont.cpp index 432dc788..dcd352b1 100644 --- a/Sources/ewolFont.cpp +++ b/Sources/ewolFont.cpp @@ -46,11 +46,9 @@ extern "C" { typedef struct { - position_ts posStart; - position_ts posStop; - intSize_ts size; + texCoord_ts posStart; + texCoord_ts posStop; float ratio; - }UTF8Element_ts; } @@ -64,7 +62,7 @@ namespace ewol { m_loadedOK = false; m_filename = newFile; - for (int32_t iii; iii 0x7F line : " << lineID); @@ -237,7 +235,14 @@ namespace ewol static etk::VectorType listLoadedFonts; - +void ewol::UnInitFont(void) +{ + for (int32_t iii=0; iii make with vertex system ... glBegin(GL_QUADS); //m_listOfElement[utf8Value].ratio = (float)w/(float)h; - glTexCoord2f(listOfElement[tmpChar].posStart.x, listOfElement[tmpChar].posStart.y); glVertex3f(posDrawX, drawPosition.y, 0.0); - glTexCoord2f(listOfElement[tmpChar].posStop.x, listOfElement[tmpChar].posStart.y); glVertex3f(posDrawX + sizeWidth, drawPosition.y, 0.0); - glTexCoord2f(listOfElement[tmpChar].posStop.x, listOfElement[tmpChar].posStop.y); glVertex3f(posDrawX + sizeWidth, drawPosition.y + size, 0.0); - glTexCoord2f(listOfElement[tmpChar].posStart.x, listOfElement[tmpChar].posStop.y); glVertex3f(posDrawX, drawPosition.y + size, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStart.u, listOfElement[tmpChar].posStart.v); glVertex3f(posDrawX, drawPosition.y, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStop.u, listOfElement[tmpChar].posStart.v); glVertex3f(posDrawX + sizeWidth, drawPosition.y, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStop.u, listOfElement[tmpChar].posStop.v); glVertex3f(posDrawX + sizeWidth, drawPosition.y + size, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStart.u, listOfElement[tmpChar].posStop.v); glVertex3f(posDrawX, drawPosition.y + size, 0.0); glEnd(); } tmpVal++; @@ -374,7 +374,7 @@ void ewol::DrawText(int32_t fontID, drawPosition.x = posDrawX; glDisable(GL_TEXTURE_2D); } -// draw the text with a sp\Ufffffffffy background +// draw the text with a specify background void ewol::DrawTextWithBg( int32_t fontID, ewol::fontMode_te displayMode, int32_t size, @@ -386,7 +386,65 @@ void ewol::DrawTextWithBg( int32_t fontID, } - +void ewol::DrawText(int32_t fontID, + ewol::fontMode_te displayMode, + int32_t size, + coord2D_ts & drawPosition, + const char * utf8String, + uint32_t & fontTextureId, + etk::VectorType & coord, + etk::VectorType & coordTex) +{ + if(fontID>=listLoadedFonts.Size() || fontID < 0) { + EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); + return; + } + if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) { + listLoadedFonts[fontID]->LoadMode(displayMode); + if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) { + EWOL_ERROR("Can not load Font mode : " << displayMode << "of font " << listLoadedFonts[fontID]->GetName() ); + return; + } + } + UTF8Element_ts * listOfElement = listLoadedFonts[fontID]->GetPointerOnElement(); + char * tmpVal = (char*)utf8String; + + // set id of texture ... (i kwnow it was a little dangerous, but this ID is never remove while the program is running... + fontTextureId = listLoadedFonts[fontID]->GetOglId(displayMode); + + float posDrawX = drawPosition.x; + while(*tmpVal != '\0') { + int32_t tmpChar = (int32_t)*tmpVal; + if (tmpChar >= 0x80) { + tmpChar = 0; + } + float sizeWidth = size * listOfElement[tmpChar].ratio; + if (tmpChar != 0x20) { + coordTex.PushBack(listOfElement[tmpChar].posStart); + texCoord_ts tmpTex; + tmpTex.u = listOfElement[tmpChar].posStop.u; + tmpTex.v = listOfElement[tmpChar].posStart.v; + coordTex.PushBack(tmpTex); + coordTex.PushBack(listOfElement[tmpChar].posStop); + tmpTex.u = listOfElement[tmpChar].posStart.u; + tmpTex.v = listOfElement[tmpChar].posStop.v; + coordTex.PushBack(tmpTex); + coord2D_ts tmpCoord; + tmpCoord.x = posDrawX; + tmpCoord.y = drawPosition.y; + coord.PushBack(tmpCoord); + tmpCoord.x = posDrawX + sizeWidth; + coord.PushBack(tmpCoord); + tmpCoord.y = drawPosition.y + size; + coord.PushBack(tmpCoord); + tmpCoord.x = posDrawX; + coord.PushBack(tmpCoord); + } + tmpVal++; + posDrawX += sizeWidth; + } + drawPosition.x = posDrawX; +} diff --git a/Sources/ewolFont.h b/Sources/ewolFont.h index 648bb626..6c399d50 100644 --- a/Sources/ewolFont.h +++ b/Sources/ewolFont.h @@ -40,6 +40,7 @@ namespace ewol FONT_MODE_NUMBER, }fontMode_te; + void UnInitFont(void); // load a font in momory, can be done many time for a specific fontname, if you specify true the font will be loaded in memory, otherwise, font is loaded only when needed the first time bool AddFont(etk::File fontFileName, bool bold=false, bool italic=false, bool boldItalic=false); // get the name of the font @@ -67,6 +68,15 @@ namespace ewol color_ts textColorBg, const char * utf8String); + // draw the text without background + void DrawText( int32_t fontID, + ewol::fontMode_te displayMode, + int32_t size, + coord2D_ts & drawPosition, + const char * utf8String, + uint32_t & fontTextureId, + etk::VectorType & coord, + etk::VectorType & coordTex); int32_t LoadFont(etk::File fontFileName); void DrawText(double x, double y, const char * myString); diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp index 5f6faeb7..d46c6e6d 100644 --- a/Sources/ewolOObject.cpp +++ b/Sources/ewolOObject.cpp @@ -188,3 +188,67 @@ void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, floa } +#undef __class__ +#define __class__ "ewol::OObject2DText" + +ewol::OObject2DText::OObject2DText(float x, float y, etk::String FontName, int32_t size, fontMode_te mode, color_ts textColorFg, const char* utf8String) +{ + Text(x, y, FontName, size, mode, textColorFg, utf8String); +} + +ewol::OObject2DText::~OObject2DText(void) +{ + +} + +void ewol::OObject2DText::Draw(void) +{ + if (m_coord.Size()<=0) { + EWOL_WARNING("Nothink to draw..."); + return; + } + + glColor4f(m_textColorFg.red, m_textColorFg.green, m_textColorFg.blue, m_textColorFg.alpha); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 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_QUADS, 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::Text(float x, float y, etk::String FontName, int32_t size, fontMode_te mode, color_ts textColorFg, const char* utf8String) +{ + m_FontTextureId = 0; + m_coord.Clear(); + m_coordTex.Clear(); + // get font Name : + m_FontId = GetFontIdWithName(FontName); + if (m_FontId == -1) { + EWOL_ERROR("Can not find the font with the name : " << FontName); + } + EWOL_DEBUG("Font name : " << FontName << " id=" << m_FontId); + m_textColorFg = textColorFg; + coord2D_ts drawPosition; + drawPosition.x = x; + drawPosition.y = y; + ewol::DrawText(m_FontId, mode, size, drawPosition, utf8String, m_FontTextureId, m_coord, m_coordTex); +} + + +/* +uint32_t m_FontId; //!< font internal ID +uint32_t m_FontTextureId; //!< font internal Texture ID +etk::VectorType m_coord; //!< internal coord of the object +etk::VectorType m_coordTex; //!< internal texture coordinate for every point +*/ + + + + + diff --git a/Sources/ewolOObject.h b/Sources/ewolOObject.h index e36bf16e..b8964bd8 100644 --- a/Sources/ewolOObject.h +++ b/Sources/ewolOObject.h @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace ewol { @@ -106,6 +107,43 @@ namespace ewol { etk::VectorType m_coord; //!< internal coord of the object etk::VectorType m_coordTex; //!< internal texture coordinate for every point }; + + + class OObject2DText :public ewol::OObject + { + public: + OObject2DText(float x, float y, etk::String FontName, int32_t size, fontMode_te mode, color_ts textColorFg, const char* utf8String); + virtual ~OObject2DText(void); + public: + virtual void Draw(void); + // set a specific text + void Text(float x, float y, etk::String FontName, int32_t size, fontMode_te mode, color_ts textColorFg, const char* utf8String); + protected: + int32_t m_FontId; //!< font internal ID + color_ts m_textColorFg; //!< text color ... + uint32_t m_FontTextureId; //!< font internal Texture ID + etk::VectorType m_coord; //!< internal coord of the object + etk::VectorType m_coordTex; //!< internal texture coordinate for every point + }; + + /* + class OObject2DTextMultiple :public ewol::OObject + { + public: + OObject2DText(etk::String FontName); + virtual ~OObject2DText(void); + public: + virtual void Draw(void); + // set a specific text + void TextAdd(float x, float y, int32_t size, fontMode_te mode, const char* utf8String); + void Clear(void); + protected: + int32_t m_FontId; //!< font internal ID + uint32_t m_FontTextureId[FONT_MODE_NUMBER]; //!< font internal Texture ID + etk::VectorType m_coord[FONT_MODE_NUMBER]; //!< internal coord of the object + etk::VectorType m_coordTex[FONT_MODE_NUMBER]; //!< internal texture coordinate for every point + }; + */ }; #endif diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index cf48d1ef..6b2d9df6 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -126,6 +126,12 @@ void ewol::Windows::SysDraw(void) static ewol::OObject2DTextured myOObjectTex_r8g8b8 ("dataTest/test_24b_r8g8b8.bmp"); static ewol::OObject2DTextured myOObjectTex_x8r8g8b8("dataTest/test_32b_x8r8g8b8.bmp"); static ewol::OObject2DTextured myOObjectTex_a8r8g8b8("dataTest/test_32b_a8r8g8b8.bmp"); + color_ts textColorFg; + textColorFg.red = .0; + textColorFg.green = .0; + textColorFg.blue = .0; + textColorFg.alpha = 1.0; + static ewol::OObject2DText myOObjectText(200, 300, "Monospace", 22, FONT_MODE_NORMAL, textColorFg, "Exemple de test ..."); static bool isinit = false; static int32_t fontID = 0; @@ -150,17 +156,14 @@ void ewol::Windows::SysDraw(void) myOObject.Rectangle(200, 343, 900, 11, 1.0, 0.0, 0.0, 1.0); */ - myOObjectTex_r5g6b5.Rectangle( 300, 0, 100, 100); + myOObjectTex_r5g6b5.Rectangle( 300, 0, 100, 100); myOObjectTex_x1r5g5b5.Rectangle(300, 100, 100, 100); myOObjectTex_r8g8b8.Rectangle( 300, 200, 100, 100); - myOObjectTex_x8r8g8b8.Rectangle(400, 0, 100, 100); + myOObjectTex_x8r8g8b8.Rectangle(400, 0, 100, 100); myOObjectTex_a8r8g8b8.Rectangle(400, 100, 100, 100); - if (true == ewol::AddFont("dataTest/TextMonospace.ebt", true, true, true) ) { - fontID = GetFontIdWithFileName("dataTest/TextMonospace.ebt"); - } } @@ -170,8 +173,8 @@ void ewol::Windows::SysDraw(void) myOObjectTex_r8g8b8.Draw(); myOObjectTex_x8r8g8b8.Draw(); myOObjectTex_a8r8g8b8.Draw(); - - + myOObjectText.Draw(); + /* coord3D_ts drawPosition = { 200.0, 300.0, 0.0}; color_ts textColorFg = { 1.0, 1.0, 1.0, 1.0}; ewol::DrawText(fontID, FONT_MODE_NORMAL, 54, drawPosition, textColorFg,"APet9_$*:/?,>< \"#',;KkgGyYf"); @@ -187,7 +190,7 @@ void ewol::Windows::SysDraw(void) drawPosition = { 200.0, 450.0, 0.0}; textColorFg = { 0.0, 0.0, 1.0, 1.0}; ewol::DrawText(fontID, FONT_MODE_BOLD_ITALIC, 105, drawPosition, textColorFg,"APet9_$*:/?,>< \"#',;KkgGyYf"); - + */ } diff --git a/dataTest/TextMonospace.ebt b/dataTest/TextMonospace.ebt index 8bfca011..cc516acb 100644 --- a/dataTest/TextMonospace.ebt +++ b/dataTest/TextMonospace.ebt @@ -1,4 +1,4 @@ -name:Monspace +name:Monospace normal:TextMonospace.bmp bold:TextMonospaceBold.bmp bold-italic:TextMonospaceBoldItalic.bmp