diff --git a/Sources/libewol/ewol/OObject/Sprite.cpp b/Sources/libewol/ewol/OObject/Sprite.cpp new file mode 100644 index 00000000..6ed81b9b --- /dev/null +++ b/Sources/libewol/ewol/OObject/Sprite.cpp @@ -0,0 +1,130 @@ +/** + ******************************************************************************* + * @file ewol/OObject/Sprite.cpp + * @brief ewol OpenGl Object system (Sources) + * @author Edouard DUPIN + * @date 04/04/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 +#include + +#undef __class__ +#define __class__ "Sprite" + + + +ewol::Sprite::Sprite(etk::UString spriteName) +{ + EWOL_VERBOSE("Create Sprite : \"" << spriteName << "\""); + m_textureId = ewol::texture::Load(spriteName); +} +ewol::Sprite::Sprite(etk::UString spriteName, etkFloat_t sizeX, etkFloat_t sizeY) +{ + EWOL_VERBOSE("Create Sprite : \"" << spriteName << "\""); + m_textureId = ewol::texture::Load(spriteName, sizeX); +} + + +ewol::Sprite::~Sprite(void) +{ + if (-1 != m_textureId) { + ewol::texture::UnLoad(m_textureId); + } +} + +void ewol::Sprite::Draw(void) +{ + if (m_coord.Size()<=0) { + EWOL_WARNING("Nothink to draw..."); + return; + } + if (m_textureId == -1) { + EWOL_WARNING("Texture does not exist ..."); + return; + } + glColor4f(1.0, 1.0, 1.0, 1.0); + glEnable(GL_TEXTURE_2D); + //EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId)); + glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId)); + glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays + glVertexPointer( 2, oglTypeFloat_t, 0, &m_coord[0] ); + glTexCoordPointer( 2, oglTypeFloat_t, 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::Sprite::Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t texX, etkFloat_t texY, etkFloat_t texSX, etkFloat_t 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 Element(coord2D_ts pos, etkFloat_t size, etkFloat_t angle) +{ + +} + diff --git a/Sources/libewol/ewol/OObject/Sprite.h b/Sources/libewol/ewol/OObject/Sprite.h new file mode 100644 index 00000000..b187abad --- /dev/null +++ b/Sources/libewol/ewol/OObject/Sprite.h @@ -0,0 +1,51 @@ +/** + ******************************************************************************* + * @file ewol/OObject/Sprite.h + * @brief ewol OpenGl Object system (header) + * @author Edouard DUPIN + * @date 04/04/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_SPRITE_H__ +#define __EWOL_O_OBJECT_SPRITE_H__ + +#include + +namespace ewol { + class Sprite :public ewol::OObject + { + private: + etk::UString m_name; + public: + Sprite(etk::UString spriteName); + Sprite(etk::UString spriteName, etkFloat_t sizeX, etkFloat_t sizeY); + virtual ~Sprite(void); + public: + virtual void Draw(void); + void Rectangle(etkFloat_t x, etkFloat_t y, etkFloat_t w, etkFloat_t h, etkFloat_t texX=0.0, etkFloat_t texY=0.0, etkFloat_t texSX=1.0, etkFloat_t texSY=1.0); + void Element(coord2D_ts pos, etkFloat_t size, etkFloat_t angle); + protected: + int32_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 + }; +}; + +#endif + diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp new file mode 100644 index 00000000..3d1efd08 --- /dev/null +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -0,0 +1,99 @@ +/** + ******************************************************************************* + * @file ewol/widget/Scene.cpp + * @brief ewol Scene widget system (Sources) + * @author Edouard DUPIN + * @date 01/04/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 + +#include +#include + +/** + * @brief Initilise the basic widget property ==> due to the android system + * @note all widget that have template might have this initializer ... + * @param --- + * @return --- + */ +void ewol::WIDGET_SceneInit(void) +{ + +} + +#undef __class__ +#define __class__ "Scene" + +ewol::Scene::Scene(void) +{ + SetCanHaveFocus(true); +} + + +ewol::Scene::~Scene(void) +{ + +} + +//!< EObject name : +extern const char * const ewol::TYPE_EOBJECT_WIDGET_SCENE = "Scene"; + +/** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ +bool ewol::Scene::CheckObjectType(const char * const objectType) +{ + if (NULL == objectType) { + EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_SCENE << "\" != NULL(pointer) "); + return false; + } + if (objectType == ewol::TYPE_EOBJECT_WIDGET_SCENE) { + return true; + } else { + if(true == ewol::WidgetScrooled::CheckObjectType(objectType)) { + return true; + } + EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_SCENE << "\" != \"" << objectType << "\""); + return false; + } +} + +/** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ +const char * const ewol::Scene::GetObjectType(void) +{ + return ewol::TYPE_EOBJECT_WIDGET_SCENE; +} + + + +void ewol::Scene::OnRegenerateDisplay(void) +{ + if (true == NeedRedraw()) { + } +} diff --git a/Sources/libewol/ewol/widget/Scene.h b/Sources/libewol/ewol/widget/Scene.h new file mode 100644 index 00000000..2dbe9c7d --- /dev/null +++ b/Sources/libewol/ewol/widget/Scene.h @@ -0,0 +1,87 @@ +/** + ******************************************************************************* + * @file ewol/widget/Scene.h + * @brief ewol Scene widget system (header) + * @author Edouard DUPIN + * @date 01/04/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_SCENE_H__ +#define __EWOL_SCENE_H__ + +#include +#include +#include +#include + + +namespace ewol { + class GameElement + { + private: + bool m_visible; + coord2D_ts m_position; + public: + GameElement(void) { m_visible = true; m_position.x=0.0; m_position.y=0.0;}; + virtual ~GameElement(void) {}; + }; + + class Scene :public ewol::WidgetScrooled + { + // TODO : Set it in private ... + protected: + etk::VectorType m_backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType m_backgrouanimatedElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType m_listAnimatedElements; //!< generic element to display... + public: + Scene(void); + virtual ~Scene(void); + /** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ + virtual bool CheckObjectType(const char * const objectType); + + /** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ + virtual const char * const GetObjectType(void); + virtual void OnRegenerateDisplay(void); + }; + + /** + * @brief Initilise the basic widget property ==> due to the android system + * @note all widget that have template might have this initializer ... + * @param --- + * @return --- + */ + void WIDGET_SceneInit(void); + + extern const char * const TYPE_EOBJECT_WIDGET_SCENE; + +}; +#define EWOL_CAST_WIDGET_SCENE(curentPointer) EWOL_CAST(ewol::TYPE_EOBJECT_WIDGET_SCENE,ewol::Scene,curentPointer) + + +#endif diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 4de218ba..161e0166 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -14,6 +14,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/OObject/2DTextColored.cpp \ ewol/OObject/2DColored.cpp \ ewol/OObject/2DTextured.cpp \ + ewol/OObject/Sprite.cpp \ ewol/OObject/e2d.cpp \ ewol/Texture.cpp \ ewol/Texture/TextureBMP.cpp \ @@ -36,6 +37,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/widget/List.cpp \ ewol/widget/Menu.cpp \ ewol/widget/PopUp.cpp \ + ewol/widget/Scene.cpp \ ewol/widget/SizerHori.cpp \ ewol/widget/SizerVert.cpp \ ewol/widget/Slider.cpp \