add reader of e2d files and associated widget

This commit is contained in:
Edouard Dupin 2012-03-13 18:21:21 +01:00
parent 3e8b03ebf9
commit b67efa06c6
5 changed files with 478 additions and 0 deletions

View File

@ -0,0 +1,211 @@
/**
*******************************************************************************
* @file ewol/OObject/2DColored.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 <ewol/OObject/e2d.h>
#include <ewol/importgl.h>
#include "tinyXML/tinyxml.h"
#undef __class__
#define __class__ "OObject::e2d"
ewol::oobject::e2d::e2d(void)
{
m_size.x = 30;
m_size.y = 30;
}
ewol::oobject::e2d::e2d(etk::File file)
{
LoadFile(file);
}
ewol::oobject::e2d::~e2d(void)
{
}
void ewol::oobject::e2d::Draw(void)
{
if (m_coord.Size()<=0) {
return;
}
glPushMatrix();
// Enable Pointers
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
etkFloat_t minimum = etk_min(m_size.x, m_size.y);
glScalef( minimum, minimum, 1.0 );
//glScalef( 30.0, 30.0, 1.0 );
// Set the vertex pointer to our vertex data
glVertexPointer(2, oglTypeFloat_t, 0, &m_coord[0] );
glColorPointer(4, oglTypeFloat_t, 0, &m_coordColor[0] );
// Render : draw all of the triangles at once
glDrawArrays( GL_TRIANGLES, 0, m_coord.Size());
// Disable Pointers
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
glPopMatrix();
}
void ewol::oobject::e2d::LoadFile(etk::File file)
{
m_fileName = file;
// Remove all local elements :
m_dotList.Clear();
m_linkList.Clear();
EWOL_DEBUG("open file (e2d) \"" << m_fileName << "\"");
// allocate the document in the stack
TiXmlDocument XmlDocument;
if (false == m_fileName.Exist()) {
EWOL_ERROR("File Does not exist : " << m_fileName);
return;
}
int32_t fileSize = m_fileName.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << m_fileName);
return;
}
if (false == m_fileName.fOpenRead()) {
EWOL_ERROR("Can not open the file : " << m_fileName);
return;
}
// allocate data
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << m_fileName);
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
// load data from the file :
m_fileName.fRead(fileBuffer, 1, fileSize);
// close the file:
m_fileName.fClose();
// load the XML from the memory
XmlDocument.Parse((const char*)fileBuffer, 0, TIXML_ENCODING_UTF8);
TiXmlElement* root = XmlDocument.FirstChildElement( "e2d" );
if (NULL == root ) {
EWOL_ERROR("(l ?) main node not find: \"e2d\" in \"" << m_fileName << "\"");
return;
} else {
for(TiXmlNode * pNode = root->FirstChild();
NULL != pNode;
pNode = pNode->NextSibling() ) {
if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) {
// nothing to do, just proceed to next step
} else if (!strcmp(pNode->Value(), "element")) {
for(TiXmlNode * pGuiNode = pNode->FirstChild();
NULL != pGuiNode;
pGuiNode = pGuiNode->NextSibling()) {
if (pGuiNode->Type()==TiXmlNode::TINYXML_COMMENT) {
// nothing to do, just proceed to next step
} else if (!strcmp(pGuiNode->Value(), "dot")) {
const char *xxx = pGuiNode->ToElement()->Attribute("x");
const char *yyy = pGuiNode->ToElement()->Attribute("y");
if( NULL != xxx
&& NULL != yyy) {
coord2D_ts pos;
double posX, posY;
sscanf(xxx, "%lf", &posX);
sscanf(yyy, "%lf", &posY);
pos.x = posX;
pos.y = posY;
EWOL_DEBUG("load dot : " << xxx << "," << yyy << " ==>" << pos);
m_dotList.PushBack(pos);
}
} else if (!strcmp(pGuiNode->Value(), "link")) {
const char *id[3];
const char *color[3];
id[0] = pGuiNode->ToElement()->Attribute("id1");
id[1] = pGuiNode->ToElement()->Attribute("id2");
id[2] = pGuiNode->ToElement()->Attribute("id3");
color[0] = pGuiNode->ToElement()->Attribute("color1");
color[1] = pGuiNode->ToElement()->Attribute("color2");
color[2] = pGuiNode->ToElement()->Attribute("color3");
if( NULL != id[0]
&& NULL != id[1]
&& NULL != id[2]
&& NULL != color[0]
&& NULL != color[1]
&& NULL != color[2]) {
link_ts localLink;
int r=0;
int v=0;
int b=0;
int a=-1;
for(int32_t kkk=0; kkk<3; kkk++) {
sscanf(id[kkk], "%d", &localLink.dot[kkk]);
sscanf(color[kkk], "#%02x%02x%02x%02x", &r, &v, &b, &a);
localLink.color[kkk].red = (float)r/255.0;
localLink.color[kkk].green = (float)v/255.0;
localLink.color[kkk].blue = (float)b/255.0;
if (-1 == a) {
localLink.color[kkk].alpha = 1;
} else {
localLink.color[kkk].alpha = (float)a/255.0;
}
}
EWOL_DEBUG("load link : [" << localLink.dot[0] << "," << localLink.dot[1] << "," << localLink.dot[2] << "] ");
EWOL_DEBUG(" col: [" << localLink.color[0] << "," << localLink.color[1] << "," << localLink.color[2] << "] ");
m_linkList.PushBack(localLink);
}
} else {
EWOL_ERROR("(l "<<pGuiNode->Row()<<") node not suported : \""<<pGuiNode->Value()<<"\" must be [dot,link]");
}
}
} else {
EWOL_ERROR("(l "<<pNode->Row()<<") node not suported : \""<<pNode->Value()<<"\" must be [element]");
}
}
}
if (NULL != fileBuffer) {
delete[] fileBuffer;
}
// Generate the drawing :
for (int32_t iii=0; iii<m_linkList.Size(); iii++) {
for (int32_t jjj=0; jjj<3; jjj++) {
// set color
ewol::OObject2DColored::SetColor(m_linkList[iii].color[jjj]);
// Set the specific dot
ewol::OObject2DColored::SetPoint(m_dotList[m_linkList[iii].dot[jjj]]);
}
}
}

View File

@ -0,0 +1,59 @@
/**
*******************************************************************************
* @file ewol/OObject/e2d.h
* @brief ewol OpenGl e2d Object system (header)
* @author Edouard DUPIN
* @date 13/03/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_E2D_H__
#define __EWOL_O_OBJECT_E2D_H__
#include <ewol/OObject.h>
#include <ewol/OObject/2DColored.h>
typedef struct {
int32_t dot[3];
color_ts color[3];
} link_ts;
namespace ewol {
namespace oobject {
class e2d :public ewol::OObject2DColored
{
protected:
etk::VectorType<coord2D_ts> m_dotList; //!< list of all point in the buffer
etk::VectorType<link_ts> m_linkList; //!< List of all triangle in the mesh
etk::File m_fileName; //!< e2d file name ...
coord2D_ts m_size; //!< User requested Size ...
public:
e2d(void);
e2d(etk::File file);
virtual ~e2d(void);
void LoadFile(etk::File file);
void SetSize(coord2D_ts newSize) { m_size = newSize; m_size.x=etk_max(m_size.x,0); m_size.y=etk_max(m_size.y,0);};
virtual void Draw(void);
};
};
};
#endif

View File

@ -0,0 +1,131 @@
/**
*******************************************************************************
* @file ewol/widget/widgetE2D.cpp
* @brief ewol file e2d widget system (Sources)
* @author Edouard DUPIN
* @date 13/03/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/widget/widgetE2D.h>
#include <ewol/OObject.h>
#include <ewol/WidgetManager.h>
#include <ewol/OObject/e2d.h>
extern const char * const ewolEventE2DPressed = "ewol widget e2d Pressed";
#undef __class__
#define __class__ "widgetE2D"
ewol::widgetE2D::widgetE2D(void)
{
AddEventId(ewolEventE2DPressed);
m_fileName = "";
}
ewol::widgetE2D::~widgetE2D(void)
{
}
//!< EObject name :
extern const char * const ewol::TYPE_EOBJECT_WIDGET_E2D = "widgetE2D";
/**
* @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::widgetE2D::CheckObjectType(const char * const objectType)
{
if (NULL == objectType) {
EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_E2D << "\" != NULL(pointer) ");
return false;
}
if (objectType == ewol::TYPE_EOBJECT_WIDGET_E2D) {
return true;
} else {
if(true == ewol::Drawable::CheckObjectType(objectType)) {
return true;
}
EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_E2D << "\" != \"" << 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::widgetE2D::GetObjectType(void)
{
return ewol::TYPE_EOBJECT_WIDGET_E2D;
}
void ewol::widgetE2D::SetElement(etk::File fileName)
{
m_fileName = fileName;
MarkToReedraw();
}
void ewol::widgetE2D::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
// clean the object list ...
ClearOObjectList();
if (m_fileName != "") {
ewol::oobject::e2d * tmpE2D = new ewol::oobject::e2d(m_fileName);
tmpE2D->SetSize(m_size);
AddOObject(tmpE2D);
}
}
}
/**
* @brief Event on an input of this Widget
* @param[in] IdInput Id of the current Input (PC : left=1, right=2, middle=3, none=0 / Tactil : first finger=1 , second=2 (only on this widget, no knowledge at ouside finger))
* @param[in] typeEvent ewol type of event like EVENT_INPUT_TYPE_DOWN/EVENT_INPUT_TYPE_MOVE/EVENT_INPUT_TYPE_UP/EVENT_INPUT_TYPE_SINGLE/EVENT_INPUT_TYPE_DOUBLE/...
* @param[in] pos Absolute position of the event
* @return true the event is used
* @return false the event is not used
*/
bool ewol::widgetE2D::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, coord2D_ts pos)
{
//EWOL_DEBUG("Event on e2d object ...");
if (1 == IdInput) {
if( ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent
|| ewol::EVENT_INPUT_TYPE_DOUBLE == typeEvent
|| ewol::EVENT_INPUT_TYPE_TRIPLE == typeEvent) {
// nothing to do ...
//EWOL_DEBUG(" ==> generate event : " << ewolEventE2DPressed);
GenerateEventId(ewolEventE2DPressed);
return true;
}
}
return false;
}

View File

@ -0,0 +1,75 @@
/**
*******************************************************************************
* @file ewol/widget/widgetE2D.h
* @brief ewol file e2d widget system (header)
* @author Edouard DUPIN
* @date 13/03/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_WIDGET_E2D_H__
#define __EWOL_WIDGET_E2D_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/widget/Drawable.h>
extern const char * const ewolEventE2DPressed;
namespace ewol {
class widgetE2D : public ewol::Drawable
{
protected:
etk::File m_fileName;
public:
widgetE2D(void);
virtual ~widgetE2D(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);
void SetElement(etk::File filename);
virtual void OnRegenerateDisplay(void);
/**
* @brief Event on an input of this Widget
* @param[in] IdInput Id of the current Input (PC : left=1, right=2, middle=3, none=0 / Tactil : first finger=1 , second=2 (only on this widget, no knowledge at ouside finger))
* @param[in] typeEvent ewol type of event like EVENT_INPUT_TYPE_DOWN/EVENT_INPUT_TYPE_MOVE/EVENT_INPUT_TYPE_UP/EVENT_INPUT_TYPE_SINGLE/EVENT_INPUT_TYPE_DOUBLE/...
* @param[in] pos Absolute position of the event
* @return true the event is used
* @return false the event is not used
*/
virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, coord2D_ts pos);
};
extern const char * const TYPE_EOBJECT_WIDGET_E2D;
};
#define EWOL_CAST_WIDGET_E2D(curentPointer) EWOL_CAST(ewol::TYPE_EOBJECT_WIDGET_E2D,ewol::widgetE2D,curentPointer)
#endif

View File

@ -13,6 +13,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/OObject/2DTextColored.cpp \
ewol/OObject/2DColored.cpp \
ewol/OObject/2DTextured.cpp \
ewol/OObject/e2d.cpp \
ewol/Texture.cpp \
ewol/FontBitmap.cpp \
ewol/FontFreeType.cpp \
@ -36,6 +37,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/widget/SizerVert.cpp \
ewol/widget/Slider.cpp \
ewol/widget/Spacer.cpp \
ewol/widget/widgetE2D.cpp \
ewol/widgetMeta/FileChooser.cpp \
ewol/widgetMeta/ColorChooser.cpp \
ewol/widgetMeta/Keyboard.cpp \