diff --git a/Makefile b/Makefile index 601b9ab2..d1c05276 100644 --- a/Makefile +++ b/Makefile @@ -178,6 +178,9 @@ CXXFILES += etk/etkDebug.cpp \ CXXFILES += ewol.cpp \ ewolDebug.cpp \ ewolOObject.cpp \ + ewolOObject2DText.cpp \ + ewolOObject2DColored.cpp \ + ewolOObject2DTextured.cpp \ ewolTexture.cpp ifeq ("$(FREETYPE_CFLAGS)", "") CXXFILES += ewolFontBitmap.cpp @@ -193,6 +196,8 @@ CXXFILES += widget/ewolButton.cpp \ widget/ewolList.cpp \ widget/ewolSizerHori.cpp \ widget/ewolSizerVert.cpp +# only to test son internal element ... +CXXFILES += widget/ewolTest.cpp # Ewol Test Software : diff --git a/Sources/Main.cpp b/Sources/Main.cpp index 2414b7cc..7854c77e 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,10 @@ class Plop :public ewol::Windows myButton->SetExpendX(true); //myButton->SetExpendY(true); mySizerVert->SubWidgetAdd(myButton); + + ewol::Test * myTest = new ewol::Test(); + mySizerVert->SubWidgetAdd(myTest); + myButton = new ewol::Button(" 4 4 BT"); //myButton->SetExpendY(true); mySizerVert->SubWidgetAdd(myButton); diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp index 56f0f074..1751835a 100644 --- a/Sources/ewolOObject.cpp +++ b/Sources/ewolOObject.cpp @@ -25,261 +25,39 @@ #include #include #include -#include #include #undef __class__ -#define __class__ "ewol::OObject2DColored" +#define __class__ "ewol::OObject" - -void ewol::OObject2DColored::Draw(void) +ewol::OObject::OObject(void) { - if (m_coord.Size()<=0) { - return; - } - // Enable Pointers - glEnableClientState( GL_VERTEX_ARRAY ); - glEnableClientState( GL_COLOR_ARRAY ); - - - // Set the vertex pointer to our vertex data - glVertexPointer(2, GL_FLOAT, 0, &m_coord[0] ); - glColorPointer(4, GL_FLOAT, 0, &m_coordColor[0] ); - // Render : draw all of the triangles at once - glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); - //glDrawElements( GL_TRIANGLES, 0, m_coord.Size()); - //EWOL_DEBUG("Draw ..." << m_coord.Size()/3 << " triangle(s)"); - - // Disable Pointers - glDisableClientState( GL_COLOR_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); - + m_name=""; } -void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha) -{ - //EWOL_DEBUG("Add rectangle : ..."); - coord2D_ts point; - color_ts color; - - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x + w; - point.y = y; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x + w; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - - point.x = x; - point.y = y + h; - m_coord.PushBack(point); - m_coordColor.PushBack(color); - -} - - -void ewol::OObject2DColored::UpdateOrigin(float x, float y) -{ - for (int32_t iii=0; iii m_coord; //!< internal coord of the object - etk::VectorType m_coordColor; //!< internal color of the different point - //etk::VectorType m_linkCoord; //!< internal link between point to generate triangle - public: - void Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha); - public: - virtual void UpdateOrigin(float x, float y); - }; /* class OObjectFile :public ewol::OObject { @@ -97,62 +70,12 @@ namespace ewol { bool m_isBinaryFile; //!< to know th mode of saving the file }; */ - - class OObject2DTextured :public ewol::OObject - { - public: - OObject2DTextured(etk::File textureName); - virtual ~OObject2DTextured(void); - public: - virtual void Draw(void); - void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0); - protected: - uint32_t m_textureId; //!< texture internal ID - etk::VectorType m_coord; //!< internal coord of the object - etk::VectorType m_coordTex; //!< internal texture coordinate for every point - public: - virtual void UpdateOrigin(float x, float y); - }; - - - 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 - public: - virtual void UpdateOrigin(float x, float y); - }; - - /* - 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 + +#include +#include +#include + diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp new file mode 100644 index 00000000..658d6a86 --- /dev/null +++ b/Sources/ewolOObject2DColored.cpp @@ -0,0 +1,108 @@ +/** + ******************************************************************************* + * @file ewolOObject2DColored.cpp + * @brief ewol OpenGl Object system (Sources) + * @author Edouard DUPIN + * @date 09/11/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 + + +#undef __class__ +#define __class__ "ewol::OObject2DColored" + + + +void ewol::OObject2DColored::Draw(void) +{ + if (m_coord.Size()<=0) { + return; + } + // Enable Pointers + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + + // Set the vertex pointer to our vertex data + glVertexPointer(2, GL_FLOAT, 0, &m_coord[0] ); + glColorPointer(4, GL_FLOAT, 0, &m_coordColor[0] ); + // Render : draw all of the triangles at once + glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); + //glDrawElements( GL_TRIANGLES, 0, m_coord.Size()); + //EWOL_DEBUG("Draw ..." << m_coord.Size()/3 << " triangle(s)"); + + // Disable Pointers + glDisableClientState( GL_COLOR_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); + +} + + +void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha) +{ + //EWOL_DEBUG("Add rectangle : ..."); + coord2D_ts point; + color_ts color; + + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x + w; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x + w; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + +} + + +void ewol::OObject2DColored::UpdateOrigin(float x, float y) +{ + for (int32_t iii=0; iii + +namespace ewol { + class OObject2DColored :public ewol::OObject + { + public: + OObject2DColored(void) {}; + virtual ~OObject2DColored(void) {}; + public: + virtual void Draw(void); + protected: + etk::VectorType m_coord; //!< internal coord of the object + etk::VectorType m_coordColor; //!< internal color of the different point + //etk::VectorType m_linkCoord; //!< internal link between point to generate triangle + public: + void Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha); + public: + virtual void UpdateOrigin(float x, float y); + }; +}; + +#endif + diff --git a/Sources/ewolOObject2DText.cpp b/Sources/ewolOObject2DText.cpp new file mode 100644 index 00000000..ad51250b --- /dev/null +++ b/Sources/ewolOObject2DText.cpp @@ -0,0 +1,96 @@ +/** + ******************************************************************************* + * @file ewolOObject2DText.cpp + * @brief ewol OpenGl Object system (Sources) + * @author Edouard DUPIN + * @date 09/11/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 + +#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 : + if (FontName == "") { + m_FontId = GetDefaultFontId(); + } else { + EWOL_TODO("pas encore fait..."); + //m_FontId = GetFontIdWithName(FontName); + return; + } + 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, drawPosition, utf8String, m_FontTextureId, m_coord, m_coordTex); +} + +void ewol::OObject2DText::UpdateOrigin(float x, float y) +{ + for (int32_t iii=0; iii + +namespace ewol { + 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 + public: + virtual void UpdateOrigin(float x, float y); + }; +}; + +#endif + diff --git a/Sources/ewolOObject2DTextured.cpp b/Sources/ewolOObject2DTextured.cpp new file mode 100644 index 00000000..de0d421d --- /dev/null +++ b/Sources/ewolOObject2DTextured.cpp @@ -0,0 +1,120 @@ +/** + ******************************************************************************* + * @file ewolOObject2DTextured.cpp + * @brief ewol OpenGl Object system (Sources) + * @author Edouard DUPIN + * @date 09/11/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 + +#undef __class__ +#define __class__ "ewol::OObject2DTextured" + + + +ewol::OObject2DTextured::OObject2DTextured(etk::File textureName) +{ + EWOL_DEBUG("Create OObject textured : \"" << textureName << "\""); + m_textureId = ewol::LoadTexture(textureName); +} + +ewol::OObject2DTextured::~OObject2DTextured(void) +{ + ewol::UnLoadTexture(m_textureId); +} + +void ewol::OObject2DTextured::Draw(void) +{ + if (m_coord.Size()<=0) { + EWOL_WARNING("Nothink to draw..."); + return; + } + + glColor4f(1.0, 1.0, 1.0, 1.0); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, m_textureId); + 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_TRIANGLES, 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::OObject2DTextured::Rectangle(float x, float y, float w, float h, float texX, float texY, float texSX, float texSY) +{ + //EWOL_DEBUG("Add rectangle : ..."); + coord2D_ts point; + texCoord_ts tex; + + tex.u = texX; + tex.v = texY; + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + + tex.u = texSX; + tex.v = texY; + point.x = x + w; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + + tex.u = texSX; + tex.v = texSY; + point.x = x + w; + point.y = y + h; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + tex.u = texX; + tex.v = texSY; + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + tex.u = texX; + tex.v = texY; + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); +} + +void ewol::OObject2DTextured::UpdateOrigin(float x, float y) +{ + for (int32_t iii=0; iii + +namespace ewol { + class OObject2DTextured :public ewol::OObject + { + public: + OObject2DTextured(etk::File textureName); + virtual ~OObject2DTextured(void); + public: + virtual void Draw(void); + void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0); + protected: + uint32_t m_textureId; //!< texture internal ID + etk::VectorType m_coord; //!< internal coord of the object + etk::VectorType m_coordTex; //!< internal texture coordinate for every point + public: + virtual void UpdateOrigin(float x, float y); + }; +}; + +#endif + diff --git a/Sources/widget/ewolTest.cpp b/Sources/widget/ewolTest.cpp new file mode 100644 index 00000000..28ac5bb8 --- /dev/null +++ b/Sources/widget/ewolTest.cpp @@ -0,0 +1,97 @@ +/** + ******************************************************************************* + * @file ewolTest.cpp + * @brief ewol Test widget system (Sources) + * @author Edouard DUPIN + * @date 07/11/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 + + + +//const char * ewolEventButtonPressed = "ewol Button Pressed"; + + + +#undef __class__ +#define __class__ "ewol::Test" + +ewol::Test::Test(void) +{ + +} + + +ewol::Test::~Test(void) +{ + +} + +bool ewol::Test::CalculateMinSize(void) +{ + m_minSize.x = 150; + m_minSize.y = 150; + return true; +} + +void ewol::Test::OnRegenerateDisplay(void) +{ + // clean the object list ... + ClearOObjectList(); + + ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored; + tmpOObjects->Rectangle( 0, 0, m_size.x, m_size.y, 1.0, 0.0, 0.0, 1.0); + tmpOObjects->Rectangle( 3, 3, m_size.x-6, m_size.y-6, 1.0, 1.0, 1.0, 1.0); + AddOObject(tmpOObjects, "BouttonDecoration"); + + color_ts textColorFg; + textColorFg.red = 0.0; + textColorFg.green = 0.0; + textColorFg.blue = 0.0; + textColorFg.alpha = 1.0; + + + // Regenerate the event Area: + /* + EventAreaRemoveAll(); + coord origin; + coord size; + origin.x = 3.0; + origin.y = 3.0; + size.x = m_size.x-6; + size.y = m_size.y-6; + AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventButtonPressed); + */ +} + +bool ewol::Test::OnEventArea(const char * generateEventId, double x, double y) +{ + bool eventIsOK = false; +/* + //EWOL_DEBUG("Receive event : \"" << generateEventId << "\""); + if(ewolEventButtonPressed == generateEventId) { + EWOL_INFO("BT pressed ... " << m_label); + eventIsOK = true; + } +*/ + return eventIsOK; +} diff --git a/Sources/widget/ewolTest.h b/Sources/widget/ewolTest.h new file mode 100644 index 00000000..0b0e9f23 --- /dev/null +++ b/Sources/widget/ewolTest.h @@ -0,0 +1,46 @@ +/** + ******************************************************************************* + * @file ewolTest.h + * @brief ewol test widget system (header) + * @author Edouard DUPIN + * @date 07/11/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_TEST_H__ +#define __EWOL_TEST_H__ + +#include +#include +#include + +namespace ewol { + class Test :public ewol::Widget + { + public: + Test(void); + virtual ~Test(void); + virtual bool CalculateMinSize(void); + public: + virtual void OnRegenerateDisplay(void); + public: + virtual bool OnEventArea(const char * generateEventId, double x, double y); + }; +}; + +#endif