Add colored Text for every character

This commit is contained in:
Edouard Dupin 2012-01-16 14:38:07 +01:00
parent 50ebb501c8
commit 3204e48c80
4 changed files with 195 additions and 0 deletions

View File

@ -81,4 +81,5 @@ namespace ewol {
#include <ewol/OObject/2DTextured.h>
#include <ewol/OObject/2DColored.h>
#include <ewol/OObject/2DText.h>
#include <ewol/OObject/2DTextColored.h>

View File

@ -0,0 +1,136 @@
/**
*******************************************************************************
* @file ewol/OObject/2DTextColored.cpp
* @brief ewol OpenGl Object system (Sources)
* @author Edouard DUPIN
* @date 16/01/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/OObject/2DTextColored.h>
#include <ewol/importgl.h>
#undef __class__
#define __class__ "ewol::OObject2DTextColored"
ewol::OObject2DTextColored::OObject2DTextColored(etk::String FontName, int32_t size)
{
m_color.red = 0.0;
m_color.green = 0.0;
m_color.blue = 0.0;
m_color.alpha = 1.0;
if (FontName == "") {
m_FontId = GetDefaultFontId();
} else {
EWOL_TODO("pas encore fait...");
//m_FontId = GetFontIdWithName(FontName);
m_FontId = -1;
return;
}
}
// open with default font ...
ewol::OObject2DTextColored::OObject2DTextColored(void)
{
m_color.red = 0.0;
m_color.green = 0.0;
m_color.blue = 0.0;
m_color.alpha = 1.0;
m_FontId = GetDefaultFontId();
}
ewol::OObject2DTextColored::~OObject2DTextColored(void)
{
}
void ewol::OObject2DTextColored::Draw(void)
{
if (m_coord.Size()<=0) {
// TODO : a remètre ...
//EWOL_WARNING("Nothink to draw...");
return;
}
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
glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays
glVertexPointer( 2, oglTypeFloat_t, 0, &m_coord[0] );
glTexCoordPointer( 2, oglTypeFloat_t, 0, &m_coordTex[0] );
glColorPointer( 4, oglTypeFloat_t, 0, &m_coordColor[0] );
glDrawArrays( GL_TRIANGLES, 0, m_coord.Size());
//EWOL_DEBUG("request draw of " << m_coord.Size() << " elements");
glDisableClientState( GL_COLOR_ARRAY ); // Disable Color Arrays
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
glDisable(GL_TEXTURE_2D);
}
void ewol::OObject2DTextColored::Text(etkFloat_t x, etkFloat_t y, const char* utf8String, int32_t clippingPositionX)
{
m_coord.Clear();
m_coordTex.Clear();
m_coordColor.Clear();
// normal adding text :
TextAdd(x, y, utf8String, clippingPositionX);
}
void ewol::OObject2DTextColored::TextAdd(etkFloat_t x, etkFloat_t y, const char* utf8String, int32_t clippingPositionX)
{
m_FontTextureId = 0;
if (m_FontId == -1) {
EWOL_ERROR("Font Id is not corectly defined");
return;
}
coord2D_ts drawPosition;
drawPosition.x = x;
drawPosition.y = y;
coord2D_ts clipSize;
clipSize.x = clippingPositionX;
clipSize.y = -1;
int32_t nbElementInTheArray = m_coord.Size();
ewol::DrawText(m_FontId, drawPosition, clipSize, utf8String, m_FontTextureId, m_coord, m_coordTex);
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color);
}
}
void ewol::OObject2DTextColored::UpdateOrigin(etkFloat_t x, etkFloat_t y)
{
for (int32_t iii=0; iii<m_coord.Size(); iii++) {
m_coord[iii].x += x;
m_coord[iii].y += y;
}
}
void ewol::OObject2DTextColored::SetColor(color_ts color)
{
m_color = color;
}
void ewol::OObject2DTextColored::SetColor(etkFloat_t red, etkFloat_t green, etkFloat_t blue, etkFloat_t alpha)
{
m_color.red = red;
m_color.green = green;
m_color.blue = blue;
m_color.alpha = alpha;
}

View File

@ -0,0 +1,57 @@
/**
*******************************************************************************
* @file ewol/OObject/2DTextColored.h
* @brief ewol OpenGl Object system (header)
* @author Edouard DUPIN
* @date 16/01/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_O_OBJECT_2D_TEXT_COLORED_H__
#define __EWOL_O_OBJECT_2D_TEXT_COLORED_H__
#include <ewol/OObject.h>
namespace ewol {
class OObject2DTextColored :public ewol::OObject
{
public:
OObject2DTextColored(etk::String FontName, int32_t size);
OObject2DTextColored(void);
virtual ~OObject2DTextColored(void);
public:
virtual void Draw(void);
void SetColor(etkFloat_t red, etkFloat_t green, etkFloat_t blue, etkFloat_t alpha = 1.0);
void SetColor(color_ts color);
// set a specific text
void Text(etkFloat_t x, etkFloat_t y, const char* utf8String, int32_t clippingPositionX);
void TextAdd(etkFloat_t x, etkFloat_t y, const char* utf8String, int32_t clippingPositionX);
protected:
int32_t m_FontId; //!< font internal ID
color_ts m_color; //!< tmp 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
etk::VectorType<color_ts> m_coordColor; //!< internal color of the different point
public:
virtual void UpdateOrigin(etkFloat_t x, etkFloat_t y);
};
};
#endif

View File

@ -5,6 +5,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/Debug.cpp \
ewol/OObject.cpp \
ewol/OObject/2DText.cpp \
ewol/OObject/2DTextColored.cpp \
ewol/OObject/2DColored.cpp \
ewol/OObject/2DTextured.cpp \
ewol/Texture.cpp \