diff --git a/Makefile b/Makefile index f8954a8c..a9b2208d 100644 --- a/Makefile +++ b/Makefile @@ -93,8 +93,8 @@ DEFINE+= -DVERSION_BUILD_TIME="\"$(VERSION_BUILD_TIME)\"" X11FLAGS= -lX11 -lGL -lGLU # some X11 mode availlable : -#X11FLAGS+= -DEWOL_X11_MODE__XF86V -lXxf86vm -X11FLAGS+= -DEWOL_X11_MODE__XRENDER -lXrandr +X11FLAGS+= -DEWOL_X11_MODE__XF86V -lXxf86vm +#X11FLAGS+= -DEWOL_X11_MODE__XRENDER -lXrandr ############################################################################### ### Basic C flags ### @@ -169,6 +169,7 @@ CXXFILES += ewol.cpp \ ewolDebug.cpp \ ewolOObject.cpp \ ewolTexture.cpp \ + ewolFont.cpp \ ewolWidget.cpp \ ewolWindows.cpp diff --git a/Sources/etk/etkTypes.h b/Sources/etk/etkTypes.h index caede1bc..0b40e213 100644 --- a/Sources/etk/etkTypes.h +++ b/Sources/etk/etkTypes.h @@ -47,8 +47,8 @@ typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; - //typedef unsigned long int uint64_t; - typedef unsigned long long int uint64_t; + typedef unsigned long int uint64_t; + //typedef unsigned long long int uint64_t; #endif #define etk_min(elemA, elemB) ((elemA)<(elemB)) ? (elemA) : (elemB) @@ -57,13 +57,20 @@ extern "C" { - struct etkPointAndPosition{ + struct etkPointAndPositionDouble{ double x; double y; }; - typedef etkPointAndPosition point_ts; - typedef etkPointAndPosition position_ts; - typedef etkPointAndPosition size_ts; + + struct etkPointAndPositionInt{ + int32_t x; + int32_t y; + }; + + typedef etkPointAndPositionDouble point_ts; + typedef etkPointAndPositionDouble position_ts; + typedef etkPointAndPositionDouble size_ts; + typedef etkPointAndPositionInt intSize_ts; } diff --git a/Sources/ewolFont.cpp b/Sources/ewolFont.cpp new file mode 100644 index 00000000..e2253359 --- /dev/null +++ b/Sources/ewolFont.cpp @@ -0,0 +1,200 @@ +/** + ******************************************************************************* + * @file ewolFont.cpp + * @brief ewol Font system (sources) + * @author Edouard DUPIN + * @date 29/10/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 + +extern "C" +{ + typedef struct { + position_ts posStart; + position_ts posStop; + intSize_ts size; + }UTF8Element_ts; +} + +static UTF8Element_ts listOfElement[0x80]; + +static int32_t TextureIdNormal = -1; +static int32_t TextureIdBold = -1; +static int32_t TextureIdBoldItalic = -1; +static int32_t TextureIdItalic = -1; + +static bool isInit = false; + +int32_t ewol::LoadFont(etk::File fontFileName) +{ + if (true == isInit) { + EWOL_ERROR("Font is already loaded..."); + return 0; + } + if (fontFileName.GetExtention() != "ebt") { + EWOL_ERROR("Not the coorect extention of the file" << fontFileName); + return 0; + } + if (false == fontFileName.Exist()) { + EWOL_ERROR("File does not Exist ... " << fontFileName); + return 0; + } + + FILE* File=fopen(fontFileName.GetCompleateName().c_str(),"r"); + if(NULL == File) { + EWOL_ERROR("Can not find the file name=\"" << fontFileName << "\""); + return 0; + } + + char elementLine[2048]; + int32_t lineID=1; + while (NULL != fgets(elementLine, 2048, File) ) + { + if ( '\n' != elementLine[0] // EOL + && '\0' != elementLine[0] // EOF + && '#' != elementLine[0] // Comment line + ) + { + if (0 == strncmp("name:", elementLine, 5)) { + char extractString[256] = ""; + sscanf(elementLine, "name:%s", extractString); + EWOL_INFO("Find font name : \"" << extractString << "\""); + } else if (0 == strncmp("normal:", elementLine, 7)) { + char extractString[256] = ""; + sscanf(elementLine, "normal:%s", extractString); + etk::String elementName = fontFileName.GetFolder(); + elementName += '/'; + elementName += extractString; + EWOL_INFO("Find normal font image : \"" << elementName << "\""); + TextureIdNormal = ewol::LoadTexture(elementName); + } else if (0 == strncmp("bold-italic:", elementLine, 12)) { + char extractString[256] = ""; + sscanf(elementLine, "bold-italic:%s", extractString); + etk::String elementName = fontFileName.GetFolder(); + elementName += '/'; + elementName += extractString; + EWOL_INFO("Find bold-italic font image : \"" << elementName << "\""); + TextureIdBoldItalic = ewol::LoadTexture(elementName); + } else if (0 == strncmp("bold:", elementLine, 5)) { + char extractString[256] = ""; + sscanf(elementLine, "bold:%s", extractString); + etk::String elementName = fontFileName.GetFolder(); + elementName += '/'; + elementName += extractString; + EWOL_INFO("Find bold font image : \"" << elementName << "\""); + TextureIdBold = ewol::LoadTexture(elementName); + } else if (0 == strncmp("italic:", elementLine, 7)) { + char extractString[256] = ""; + sscanf(elementLine, "italic:%s", extractString); + etk::String elementName = fontFileName.GetFolder(); + elementName += '/'; + elementName += extractString; + EWOL_INFO("Find italic font image : \"" << elementName << "\""); + TextureIdItalic = ewol::LoadTexture(elementName); + } else if (0 == strncmp("0x00", elementLine, 4)) { + int32_t GlyphPositionX; + int32_t GlyphPositionY; + int32_t GlyphSizeX; + int32_t GlyphSizeY; + sscanf(elementLine, "0x00 (%d,%d) (%d,%d)", &GlyphPositionX, &GlyphPositionY, &GlyphSizeX, &GlyphSizeY); + EWOL_INFO("Find default font glyph : (" << GlyphPositionX << "," << GlyphPositionY << ") (" << GlyphSizeX << "," << GlyphSizeY << ") "); + for (int32_t iii=0; iii< 0x80; iii++) { + listOfElement[iii].posStart.x = (double)GlyphPositionX / 512.0; + listOfElement[iii].posStart.y = (double)GlyphPositionY / 512.0; + listOfElement[iii].posStop.x = (double)(GlyphPositionX+GlyphSizeX) / 512.0; + listOfElement[iii].posStop.y = (double)(GlyphPositionY+GlyphSizeY) / 512.0; + listOfElement[iii].size.x = GlyphSizeX; + listOfElement[iii].size.y = GlyphSizeY; + } + } else if (0 == strncmp("0x", elementLine, 2)) { + uint32_t utf8Value; + int32_t GlyphPositionX; + int32_t GlyphPositionY; + int32_t GlyphSizeX; + int32_t GlyphSizeY; + sscanf(elementLine, "0x%x (%d,%d) (%d,%d)", &utf8Value, &GlyphPositionX, &GlyphPositionY, &GlyphSizeX, &GlyphSizeY); + //EWOL_INFO("Find pos font glyph : " << utf8Value << " (" << GlyphPositionX << "," << GlyphPositionY << ") (" << GlyphSizeX << "," << GlyphSizeY << ") "); + if (utf8Value < 0x80) { + listOfElement[utf8Value].posStart.x = (double)GlyphPositionX / 512.0; + listOfElement[utf8Value].posStart.y = (double)GlyphPositionY / 512.0; + listOfElement[utf8Value].posStop.x = (double)(GlyphPositionX+GlyphSizeX) / 512.0; + listOfElement[utf8Value].posStop.y = (double)(GlyphPositionY+GlyphSizeY) / 512.0; + listOfElement[utf8Value].size.x = GlyphSizeX; + listOfElement[utf8Value].size.y = GlyphSizeY; + } else { + EWOL_ERROR("not manage glyph with ID > 0x7F line : " << lineID << "\"" << elementLine << "\""); + } + } else { + EWOL_ERROR("error when parsing the line : " << lineID << "\"" << elementLine << "\""); + } + } + + lineID++; + } + + isInit = true; + // return the font Id : + return 0; +} + + +#include +#include +#include +#include +#if defined(EWOL_X11_MODE__XF86V) +# include +#elif defined(EWOL_X11_MODE__XRENDER) +# include +#endif + +void ewol::DrawText(double x, double y, const char * myString) +{ + char * tmpVal = (char*)myString; + glColor4f(1.0, 1.0, 1.0, 1.0); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, TextureIdBold); + + while(*tmpVal != '\0') { + char tmpChar = *tmpVal; + if (tmpChar >= 0x80) { + tmpChar = 0; + } + + glBegin(GL_QUADS); + glTexCoord2f(listOfElement[tmpChar].posStart.x, listOfElement[tmpChar].posStart.y); + glVertex3f(x, y, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStop.x, listOfElement[tmpChar].posStart.y); + glVertex3f(x + listOfElement[tmpChar].size.x, y, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStop.x, listOfElement[tmpChar].posStop.y); + glVertex3f(x + listOfElement[tmpChar].size.x, y + listOfElement[tmpChar].size.y, 0.0); + glTexCoord2f(listOfElement[tmpChar].posStart.x, listOfElement[tmpChar].posStop.y); + glVertex3f(x , y + listOfElement[tmpChar].size.y, 0.0); + glEnd(); + tmpVal++; + x += listOfElement[tmpChar].size.x; + } + glDisable(GL_TEXTURE_2D); +} + diff --git a/Sources/ewolFont.h b/Sources/ewolFont.h new file mode 100644 index 00000000..8d8f2069 --- /dev/null +++ b/Sources/ewolFont.h @@ -0,0 +1,40 @@ +/** + ******************************************************************************* + * @file ewolFont.h + * @brief ewol Font system (header) + * @author Edouard DUPIN + * @date 29/10/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_FONT_H__ +#define __EWOL_FONT_H__ + +#include +#include +#include + + +namespace ewol +{ + int32_t LoadFont(etk::File fontFileName); + void DrawText(double x, double y, const char * myString); +}; + +#endif + diff --git a/Sources/ewolTexture.cpp b/Sources/ewolTexture.cpp index 83931340..178bda38 100644 --- a/Sources/ewolTexture.cpp +++ b/Sources/ewolTexture.cpp @@ -260,7 +260,7 @@ class Bitmap return; } EWOL_DEBUG(" -----------------------------------------------------------"); - if (true) { + if (false) { EWOL_DEBUG("Display caracteristic of the bitmap : "); EWOL_DEBUG(" Header of file :"); EWOL_DEBUG(" bfType =" << m_FileHeader.bfType << " 19778 : must always be set to 'BM' to declare that this is a .bmp-file."); @@ -295,6 +295,9 @@ class Bitmap case BITS_32_X8R8G8B8: EWOL_DEBUG(" mode = 32 bits X8R8G8B8"); break; + case BITS_32_A8R8G8B8: + EWOL_DEBUG(" mode = 32 bits A8R8G8B8"); + break; default: EWOL_DEBUG(" mode = ERROR"); break; @@ -305,7 +308,7 @@ class Bitmap #include #include -int32_t ewol::LoadTexture(etk::File & fileName) +int32_t ewol::LoadTexture(etk::File fileName) { etk::String fileExtention = fileName.GetExtention(); if (fileExtention == "bmp") { diff --git a/Sources/ewolTexture.h b/Sources/ewolTexture.h index 5bbed713..108d9698 100644 --- a/Sources/ewolTexture.h +++ b/Sources/ewolTexture.h @@ -31,7 +31,7 @@ namespace ewol { - int32_t LoadTexture(etk::File & fileName); + int32_t LoadTexture(etk::File fileName); void UnLoadTexture(int32_t textureID); }; diff --git a/Sources/ewolWidget.h b/Sources/ewolWidget.h index ecd8b0a7..edd0392c 100644 --- a/Sources/ewolWidget.h +++ b/Sources/ewolWidget.h @@ -90,6 +90,7 @@ namespace ewol { FLAG_EVENT_INPUT_CLICKED = 1 << 25, FLAG_EVENT_INPUT_CLICKED_DOUBLE = 1 << 26, FLAG_EVENT_INPUT_CLICKED_TRIPLE = 1 << 27, + FLAG_EVENT_INPUT_CLICKED_ALL = FLAG_EVENT_INPUT_CLICKED + FLAG_EVENT_INPUT_CLICKED_DOUBLE + FLAG_EVENT_INPUT_CLICKED_TRIPLE, }; #define FLAG_EVENT_INPUT_BT_LEFT (FLAG_EVENT_INPUT_1) diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index dfde07d5..facbb61b 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -130,9 +131,9 @@ void ewol::Windows::SysDraw(void) myOObject.Rectangle(20, 0, 20, 20, 0.0, 1.0, 0.0, 1.0); // Reduce myOObject.Rectangle(40, 0, 20, 20, 0.0, 0.0, 1.0, 1.0); // Expend - Un-expend - AddEventArea({ 0.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED, ewolEventWindowsClose); - AddEventArea({20.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED, ewolEventWindowsMinimize); - AddEventArea({40.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED, ewolEventWindowsExpend); + AddEventArea({ 0.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsClose); + AddEventArea({20.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsMinimize); + AddEventArea({40.0,0.0}, {20, 20}, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventWindowsExpend); // Other ... myOObject.Rectangle(20, 30, 100, 50, 1.0, 0.0, 0.0, 1.0); @@ -148,13 +149,13 @@ void ewol::Windows::SysDraw(void) myFile = "dataTest/test_16b_x1r5g5b5.bmp"; texID2 = LoadTexture(myFile); myFile = "dataTest/test_24b_r8g8b8.bmp"; - //texID3 = LoadTexture(myFile); + texID3 = LoadTexture(myFile); myFile = "dataTest/test_32b_x8r8g8b8.bmp"; - //texID4 = LoadTexture(myFile); + texID4 = LoadTexture(myFile); myFile = "dataTest/test_16b_a1r5g5b5.bmp"; texID5 = LoadTexture(myFile); myFile = "dataTest/test_32b_a8r8g8b8.bmp"; - //texID6 = LoadTexture(myFile); + texID6 = LoadTexture(myFile); myOObject.Rectangle(300, 300, 50, 50, 1.0, 1.0, 1.0, 1.0); myOObject.Rectangle(350, 350, 50, 50, 1.0, 0.0, 0.0, 1.0); @@ -162,6 +163,9 @@ void ewol::Windows::SysDraw(void) myOObject.Rectangle(450, 450, 50, 50, 0.0, 0.0, 1.0, 1.0); myOObject.Rectangle(500, 500, 50, 50, 0.0, 0.0, 0.0, 1.0); + int32_t fontID = ewol::LoadFont("dataTest/TextMonospace.ebt"); + + } myOObject.Draw(); @@ -266,6 +270,10 @@ void ewol::Windows::SysDraw(void) glEnd(); glDisable(GL_TEXTURE_2D); } + + + ewol::DrawText(200, 300, "Ma chere Aurelie, je T'aime"); + } diff --git a/dataTest/TextMonospace.bmp b/dataTest/TextMonospace.bmp new file mode 100644 index 00000000..abbde028 Binary files /dev/null and b/dataTest/TextMonospace.bmp differ diff --git a/dataTest/TextMonospace.ebt b/dataTest/TextMonospace.ebt new file mode 100644 index 00000000..f67fe587 --- /dev/null +++ b/dataTest/TextMonospace.ebt @@ -0,0 +1,132 @@ +name:Monspace +normal:TextMonospace.bmp +bold:TextMonospaceBold.bmp +bold-italic:TextMonospaceBoldItalic.bmp +italic:TextMonospaceItalic.bmp +# comment line ... +# size 54 largeur 33 space between letter 12 +# unknow UTF8 code of the letter and start coordonate and size ==> 0x54 (33,45) (33,54) +0x00 (99,458) (33,54) # Error : Unknow the UTF8 element ... +# hexa UTF8 code of the letter and start coordonate and size ==> 0x54 (33,45) (33,54) +# ABCDEFGHIJKLMN +0x20 (0,3) (33,54) # space ... +0x41 (33,3) (33,54) # A +0x42 (66,3) (33,54) # B +0x43 (99,3) (33,54) # C +0x44 (132,3) (33,54) # D +0x45 (165,3) (33,54) # E +0x46 (198,3) (33,54) # F +0x47 (231,3) (33,54) # G +0x48 (264,3) (33,54) # H +0x49 (297,3) (33,54) # I +0x4A (330,3) (33,54) # J +0x4B (363,3) (33,54) # K +0x4C (396,3) (33,54) # L +0x4D (429,3) (33,54) # M +0x4E (462,3) (33,54) # N +#OPQRSTUVWXYZabc +0x4F (0,69) (33,54) # O +0x50 (33,69) (33,54) # P +0x51 (66,69) (33,54) # Q +0x52 (99,69) (33,54) # R +0x53 (132,69) (33,54) # S +0x54 (165,69) (33,54) # T +0x55 (198,69) (33,54) # U +0x56 (231,69) (33,54) # V +0x57 (264,69) (33,54) # W +0x58 (297,69) (33,54) # X +0x59 (330,69) (33,54) # Y +0x5A (363,69) (33,54) # Z +0x61 (396,69) (33,54) # a +0x62 (429,69) (33,54) # b +0x63 (462,69) (33,54) # c +#defghijklmnopqr +0x64 (0,135) (33,54) # d +0x65 (33,135) (33,54) # e +0x66 (66,135) (33,54) # f +0x67 (99,135) (33,54) # g +0x68 (132,135) (33,54) # h +0x69 (165,135) (33,54) # i +0x6A (198,135) (33,54) # j +0x6B (231,135) (33,54) # k +0x6C (264,135) (33,54) # l +0x6D (297,135) (33,54) # m +0x6E (330,135) (33,54) # n +0x6F (363,135) (33,54) # o +0x70 (396,135) (33,54) # p +0x71 (429,135) (33,54) # q +0x72 (462,135) (33,54) # r +#stuvwxyz1234567 +0x73 (0,201) (33,54) # s +0x74 (33,201) (33,54) # t +0x75 (66,201) (33,54) # u +0x76 (99,201) (33,54) # v +0x77 (132,201) (33,54) # w +0x78 (165,201) (33,54) # x +0x79 (198,201) (33,54) # y +0x7A (231,201) (33,54) # z +0x31 (264,201) (33,54) # 1 +0x32 (297,201) (33,54) # 2 +0x33 (330,201) (33,54) # 3 +0x34 (363,201) (33,54) # 4 +0x35 (396,201) (33,54) # 5 +0x36 (429,201) (33,54) # 6 +0x37 (462,201) (33,54) # 7 +#890&é~"#'{([-|è +0x38 (0,267) (33,54) # 8 +0x39 (33,267) (33,54) # 9 +0x30 (66,267) (33,54) # 0 +0x26 (99,267) (33,54) # & +#0x (132,267) (33,54) # é +0x7E (165,267) (33,54) # ~ +0x22 (198,267) (33,54) # " +0x23 (231,267) (33,54) # # +0x27 (264,267) (33,54) # ' +0x7B (297,267) (33,54) # { +0x28 (330,267) (33,54) # ( +0x5B (363,267) (33,54) # [ +0x2D (396,267) (33,54) # - +0x7C (429,267) (33,54) # | +#0x (462,267) (33,54) # è +#`_\ç^à@)]=} +0x60 (0,333) (33,54) # ` +0x5F (33,333) (33,54) # _ +0x5C (66,333) (33,54) # \ +#0x (99,333) (33,54) # ç +0x5E (132,333) (33,54) # ^ +#0x (165,333) (33,54) # à +0x40 (198,333) (33,54) # @ +0x29 (231,333) (33,54) # ) +0x5D (264,333) (33,54) # ] +0x3D (297,333) (33,54) # = +0x7D (330,333) (33,54) # } +#0x (363,333) (33,54) # +#0x (396,333) (33,54) # +#0x (429,333) (33,54) # +#0x (462,333) (33,54) # +#$£*µ%!§:/ +#0x (0,399) (33,54) # i chap +#0x (33,399) (33,54) # o trema +#0x (66,399) (33,54) # u trema +#0x (99,399) (33,54) # e trema +#0x (132,399) (33,54) # a trema +0x24 (165,399) (33,54) # $ +#0x (198,399) (33,54) # £ +0x2A (231,399) (33,54) # * +#0x (264,399) (33,54) # µ +#0x (297,399) (33,54) # ù +0x25 (330,399) (33,54) # % +0x21 (363,399) (33,54) # ! +#0x (396,399) (33,54) # § +0x3A (429,399) (33,54) # : +0x2F (462,399) (33,54) # / +#;.,?<>²!+ +0x3B (0,458) (33,54) # ; +0x2E (33,458) (33,54) # . +0x2C (66,458) (33,54) # , +0x3F (99,458) (33,54) # ? +0x3C (132,458) (33,54) # < +0x3E (165,458) (33,54) # > +#0x (198,458) (33,54) # ² +#0x21 (231,458) (33,54) # ! ==> doublon ... +0x2B (264,458) (33,54) # + diff --git a/dataTest/TextMonospace.xcf b/dataTest/TextMonospace.xcf new file mode 100644 index 00000000..8c4a031b Binary files /dev/null and b/dataTest/TextMonospace.xcf differ diff --git a/dataTest/TextMonospaceBold.bmp b/dataTest/TextMonospaceBold.bmp new file mode 100644 index 00000000..16c0ff89 Binary files /dev/null and b/dataTest/TextMonospaceBold.bmp differ diff --git a/dataTest/TextMonospaceBoldItalic.bmp b/dataTest/TextMonospaceBoldItalic.bmp new file mode 100644 index 00000000..354ba8bd Binary files /dev/null and b/dataTest/TextMonospaceBoldItalic.bmp differ diff --git a/dataTest/TextMonospaceItalic.bmp b/dataTest/TextMonospaceItalic.bmp new file mode 100644 index 00000000..8e6557b8 Binary files /dev/null and b/dataTest/TextMonospaceItalic.bmp differ