From 3204e48c809bc62c5bfcf2d46ff069154f7c408b Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Mon, 16 Jan 2012 14:38:07 +0100 Subject: [PATCH] Add colored Text for every character --- Sources/libewol/ewol/OObject.h | 1 + .../libewol/ewol/OObject/2DTextColored.cpp | 136 ++++++++++++++++++ Sources/libewol/ewol/OObject/2DTextColored.h | 57 ++++++++ Sources/libewol/file.mk | 1 + 4 files changed, 195 insertions(+) create mode 100644 Sources/libewol/ewol/OObject/2DTextColored.cpp create mode 100644 Sources/libewol/ewol/OObject/2DTextColored.h diff --git a/Sources/libewol/ewol/OObject.h b/Sources/libewol/ewol/OObject.h index 40e4a020..1e68a11f 100644 --- a/Sources/libewol/ewol/OObject.h +++ b/Sources/libewol/ewol/OObject.h @@ -81,4 +81,5 @@ namespace ewol { #include #include #include +#include diff --git a/Sources/libewol/ewol/OObject/2DTextColored.cpp b/Sources/libewol/ewol/OObject/2DTextColored.cpp new file mode 100644 index 00000000..5e8fd34a --- /dev/null +++ b/Sources/libewol/ewol/OObject/2DTextColored.cpp @@ -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 +#include + +#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 + +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 m_coord; //!< internal coord of the object + etk::VectorType m_coordTex; //!< internal texture coordinate for every point + etk::VectorType m_coordColor; //!< internal color of the different point + public: + virtual void UpdateOrigin(etkFloat_t x, etkFloat_t y); + }; +}; + +#endif + diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index a5b81f53..50b38f6f 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -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 \