OObject: add simple text object
This commit is contained in:
parent
c2615456a0
commit
8bf5263e22
@ -24,6 +24,7 @@
|
||||
|
||||
|
||||
#include <ewol.h>
|
||||
#include <ewolFont.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<FONT_MODE_NUMBER; iii++) {
|
||||
for (int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) {
|
||||
m_textureId[iii] = 0;
|
||||
m_textureLoaded[iii] = false;
|
||||
}
|
||||
@ -142,7 +140,11 @@ namespace ewol
|
||||
|
||||
~Font(void)
|
||||
{
|
||||
|
||||
for(int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) {
|
||||
if (true == m_textureLoaded[iii]) {
|
||||
ewol::UnLoadTexture(m_textureId[iii]);
|
||||
}
|
||||
}
|
||||
};
|
||||
bool loadedOK(void) { return m_loadedOK; };
|
||||
private:
|
||||
@ -150,12 +152,10 @@ namespace ewol
|
||||
{
|
||||
EWOL_DEBUG("Find default font glyph : (" << x << "," << y << ") (" << w << "," << h << ") ");
|
||||
for (int32_t iii=0; iii< 0x80; iii++) {
|
||||
m_listOfElement[iii].posStart.x = (double)x / 512.0;
|
||||
m_listOfElement[iii].posStart.y = (double)y / 512.0;
|
||||
m_listOfElement[iii].posStop.x = (double)(x+w) / 512.0;
|
||||
m_listOfElement[iii].posStop.y = (double)(y+h) / 512.0;
|
||||
m_listOfElement[iii].size.x = w;
|
||||
m_listOfElement[iii].size.y = h;
|
||||
m_listOfElement[iii].posStart.u = (double)x / 512.0;
|
||||
m_listOfElement[iii].posStart.v = (double)y / 512.0;
|
||||
m_listOfElement[iii].posStop.u = (double)(x+w) / 512.0;
|
||||
m_listOfElement[iii].posStop.v = (double)(y+h) / 512.0;
|
||||
m_listOfElement[iii].ratio = (float)w/(float)h;
|
||||
}
|
||||
};
|
||||
@ -163,12 +163,10 @@ namespace ewol
|
||||
{
|
||||
EWOL_DEBUG("Add font glyph : "<< utf8Value << " (" << x << "," << y << ") (" << w << "," << h << ") ");
|
||||
if (utf8Value < 0x80) {
|
||||
m_listOfElement[utf8Value].posStart.x = (double)x / 512.0;
|
||||
m_listOfElement[utf8Value].posStart.y = (double)y / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.x = (double)(x+w) / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.y = (double)(y+h) / 512.0;
|
||||
m_listOfElement[utf8Value].size.x = w;
|
||||
m_listOfElement[utf8Value].size.y = h;
|
||||
m_listOfElement[utf8Value].posStart.u = (double)x / 512.0;
|
||||
m_listOfElement[utf8Value].posStart.v = (double)y / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.u = (double)(x+w) / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.v = (double)(y+h) / 512.0;
|
||||
m_listOfElement[utf8Value].ratio = (float)w/(float)h;
|
||||
} else {
|
||||
EWOL_ERROR("not manage glyph with ID > 0x7F line : " << lineID);
|
||||
@ -237,7 +235,14 @@ namespace ewol
|
||||
|
||||
static etk::VectorType<ewol::Font*> listLoadedFonts;
|
||||
|
||||
|
||||
void ewol::UnInitFont(void)
|
||||
{
|
||||
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) {
|
||||
delete(listLoadedFonts[iii]);
|
||||
listLoadedFonts[iii] = NULL;
|
||||
}
|
||||
listLoadedFonts.Clear();
|
||||
}
|
||||
|
||||
// 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 ewol::AddFont(etk::File fontFileName, bool bold, bool italic, bool boldItalic)
|
||||
@ -354,18 +359,13 @@ void ewol::DrawText(int32_t fontID,
|
||||
}
|
||||
float sizeWidth = size * listOfElement[tmpChar].ratio;
|
||||
if (tmpChar != 0x20) {
|
||||
/*
|
||||
EWOL_DEBUG(" Draw TEX (" << listOfElement[tmpChar].posStart.x*512 << "," << listOfElement[tmpChar].posStart.y*512 << ")");
|
||||
EWOL_DEBUG(" (" << listOfElement[tmpChar].posStop.x*512 << "," << listOfElement[tmpChar].posStop.y*512 << ")");
|
||||
EWOL_DEBUG(" display (" << drawPosition.x << "," << drawPosition.y << ")");
|
||||
EWOL_DEBUG(" (" << drawPosition.x + listOfElement[tmpChar].size.x << "," << drawPosition.y + listOfElement[tmpChar].size.y << ")");
|
||||
*/
|
||||
// TODO : this is really not availlable in the OpenGL ES ==> 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<coord2D_ts> & coord,
|
||||
etk::VectorType<texCoord_ts> & 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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<coord2D_ts> & coord,
|
||||
etk::VectorType<texCoord_ts> & coordTex);
|
||||
|
||||
int32_t LoadFont(etk::File fontFileName);
|
||||
void DrawText(double x, double y, const char * myString);
|
||||
|
@ -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<coord2D_ts> m_coord; //!< internal coord of the object
|
||||
etk::VectorType<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <etkTypes.h>
|
||||
#include <etkFile.h>
|
||||
#include <ewolDebug.h>
|
||||
#include <ewolFont.h>
|
||||
#include <etkVectorType.h>
|
||||
|
||||
namespace ewol {
|
||||
@ -106,6 +107,43 @@ namespace ewol {
|
||||
etk::VectorType<coord2D_ts> m_coord; //!< internal coord of the object
|
||||
etk::VectorType<texCoord_ts> 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<coord2D_ts> m_coord; //!< internal coord of the object
|
||||
etk::VectorType<texCoord_ts> 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<coord2D_ts> m_coord[FONT_MODE_NUMBER]; //!< internal coord of the object
|
||||
etk::VectorType<texCoord_ts> m_coordTex[FONT_MODE_NUMBER]; //!< internal texture coordinate for every point
|
||||
};
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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");
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name:Monspace
|
||||
name:Monospace
|
||||
normal:TextMonospace.bmp
|
||||
bold:TextMonospaceBold.bmp
|
||||
bold-italic:TextMonospaceBoldItalic.bmp
|
||||
|
Loading…
x
Reference in New Issue
Block a user