Change the XML saving and add an curent element id selected
This commit is contained in:
parent
17fb56330b
commit
a85028f8d5
26
jni/Main.cpp
26
jni/Main.cpp
@ -57,21 +57,14 @@
|
||||
|
||||
class MaListExemple : public ewol::List
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
MaListExemple(void) {
|
||||
RegisterMultiCast(drawMsgListElementChange);
|
||||
};
|
||||
~MaListExemple(void) { };
|
||||
/*
|
||||
virtual color_ts GetBasicBG(void) {
|
||||
color_ts bg;
|
||||
bg.red = 1.0;
|
||||
bg.green = 0.0;
|
||||
bg.blue = 0.0;
|
||||
bg.alpha = 1.0;
|
||||
return bg;
|
||||
}
|
||||
*/
|
||||
|
||||
uint32_t GetNuberOfColomn(void) {
|
||||
return 1;
|
||||
};
|
||||
@ -83,6 +76,7 @@ class MaListExemple : public ewol::List
|
||||
return drawElement::Size();
|
||||
};
|
||||
bool GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, color_ts &fg, color_ts &bg) {
|
||||
int32_t idSelected = drawElement::SelectGet();
|
||||
drawElement::Base* elementLocal = drawElement::Get(raw);
|
||||
myTextToWrite = "[";
|
||||
myTextToWrite += raw;
|
||||
@ -90,7 +84,7 @@ class MaListExemple : public ewol::List
|
||||
if (NULL == elementLocal) {
|
||||
myTextToWrite += "????";
|
||||
} else {
|
||||
myTextToWrite += elementLocal->GetType();
|
||||
myTextToWrite += elementLocal->GetTypeChar();
|
||||
myTextToWrite += "-";
|
||||
myTextToWrite += elementLocal->GetName();
|
||||
}
|
||||
@ -98,7 +92,12 @@ class MaListExemple : public ewol::List
|
||||
fg.green = 0.0;
|
||||
fg.blue = 0.0;
|
||||
fg.alpha = 1.0;
|
||||
if (raw % 2) {
|
||||
if (raw == idSelected) {
|
||||
bg.red = 0.5;
|
||||
bg.green = 0.5;
|
||||
bg.blue = 1.0;
|
||||
bg.alpha = 1.0;
|
||||
} else if (raw % 2) {
|
||||
bg.red = 1.0;
|
||||
bg.green = 1.0;
|
||||
bg.blue = 1.0;
|
||||
@ -113,8 +112,9 @@ class MaListExemple : public ewol::List
|
||||
};
|
||||
|
||||
bool OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, etkFloat_t x, etkFloat_t y) {
|
||||
if (typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) {
|
||||
if (IdInput==1 && typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) {
|
||||
DRAW_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw );
|
||||
drawElement::SelectSet(raw);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <Debug.h>
|
||||
#include <elementBase.h>
|
||||
|
||||
drawElement::Base::Base(const char* type)
|
||||
drawElement::Base::Base(elementType_te type)
|
||||
{
|
||||
m_name = "NoName";
|
||||
m_type = type;
|
||||
@ -27,3 +27,20 @@ drawElement::Base::~Base(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const char* drawElement::Base::GetTypeChar(void)
|
||||
{
|
||||
switch(m_type) {
|
||||
case DRAW_ELEMENT_TYPE_CIRCLE:
|
||||
return "Circle";
|
||||
case DRAW_ELEMENT_TYPE_DISK:
|
||||
return "Disk";
|
||||
case DRAW_ELEMENT_TYPE_MESH:
|
||||
return "Mesh";
|
||||
case DRAW_ELEMENT_TYPE_POLYGONE:
|
||||
return "Polygone";
|
||||
case DRAW_ELEMENT_TYPE_RECTANGLE:
|
||||
return "Rectangle";
|
||||
}
|
||||
return "??";
|
||||
}
|
@ -21,22 +21,30 @@
|
||||
#include <ewol/OObject/2DColored.h>
|
||||
|
||||
namespace drawElement {
|
||||
typedef enum {
|
||||
DRAW_ELEMENT_TYPE_CIRCLE,
|
||||
DRAW_ELEMENT_TYPE_DISK,
|
||||
DRAW_ELEMENT_TYPE_MESH,
|
||||
DRAW_ELEMENT_TYPE_POLYGONE,
|
||||
DRAW_ELEMENT_TYPE_RECTANGLE,
|
||||
}elementType_te;
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
Base(const char* type);
|
||||
Base(elementType_te type);
|
||||
virtual ~Base(void);
|
||||
private:
|
||||
etk::UString m_name;
|
||||
const char* m_type;
|
||||
bool m_visible;
|
||||
etk::UString m_name;
|
||||
elementType_te m_type;
|
||||
bool m_visible;
|
||||
public:
|
||||
void SetName(etk::UString name) { m_name = name; };
|
||||
etk::UString GetName(void) { return m_name; };
|
||||
const char* GetType(void) { return m_type; };
|
||||
void Show(void) { m_visible = true; };
|
||||
void Hide(void) { m_visible = false; };
|
||||
bool GetVisible(void) { return m_visible; };
|
||||
void SetName(etk::UString name) { m_name = name; };
|
||||
etk::UString GetName(void) { return m_name; };
|
||||
elementType_te GetType(void) { return m_type; };
|
||||
const char* GetTypeChar(void);
|
||||
void Show(void) { m_visible = true; };
|
||||
void Hide(void) { m_visible = false; };
|
||||
bool GetVisible(void) { return m_visible; };
|
||||
public:
|
||||
virtual void Draw(ewol::OObject2DColored &OObjects)=0;
|
||||
};
|
||||
|
@ -17,12 +17,12 @@
|
||||
#include <elementBase.h>
|
||||
|
||||
|
||||
drawElement::Circle::Circle(void) : Base("Circle")
|
||||
drawElement::Circle::Circle(void) : Base(DRAW_ELEMENT_TYPE_CIRCLE)
|
||||
{
|
||||
m_color.red = 1.0;
|
||||
m_color.green = 1.0;
|
||||
m_color.blue = 1.0;
|
||||
m_color.alpha = 1.0;
|
||||
m_colorBorder.red = 1.0;
|
||||
m_colorBorder.green = 1.0;
|
||||
m_colorBorder.blue = 1.0;
|
||||
m_colorBorder.alpha = 1.0;
|
||||
m_center.x = 0;
|
||||
m_center.y = 0;
|
||||
m_ratio = 0.3;
|
||||
@ -36,7 +36,7 @@ drawElement::Circle::~Circle(void)
|
||||
|
||||
void drawElement::Circle::Draw(ewol::OObject2DColored &OObjects)
|
||||
{
|
||||
OObjects.SetColor(m_color);
|
||||
OObjects.SetColor(m_colorBorder);
|
||||
OObjects.Circle(m_center.x, m_center.y, m_ratio, m_thickness);
|
||||
}
|
||||
|
||||
|
@ -23,16 +23,20 @@ namespace drawElement {
|
||||
Circle(void);
|
||||
virtual ~Circle(void);
|
||||
private:
|
||||
color_ts m_color;
|
||||
color_ts m_colorBorder;
|
||||
color_ts m_colorInside;
|
||||
coord2D_ts m_center;
|
||||
int32_t m_nbRay;
|
||||
etkFloat_t m_ratio;
|
||||
bool m_fill
|
||||
etkFloat_t m_thickness;
|
||||
etkFloat_t m_shadowOutput;
|
||||
etkFloat_t m_shadowInput;
|
||||
etkFloat_t m_angle;
|
||||
etkFloat_t m_angleDisplayed;
|
||||
public:
|
||||
void ColorSet(color_ts color) { m_color = color; };
|
||||
color_ts ColorGet(void) { return m_color; };
|
||||
void ColorSet(color_ts color) { m_colorBorder = color; };
|
||||
color_ts ColorGet(void) { return m_colorBorder; };
|
||||
void CenterSet(coord2D_ts center) { m_center = center; };
|
||||
coord2D_ts CenterGet(void) { return m_center; };
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
|
||||
drawElement::Disk::Disk(void) : Base("Disk")
|
||||
drawElement::Disk::Disk(void) : Base(DRAW_ELEMENT_TYPE_DISK)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,13 @@ namespace drawElement {
|
||||
Disk(void);
|
||||
virtual ~Disk(void);
|
||||
private:
|
||||
|
||||
color_ts m_color;
|
||||
coord2D_ts m_center;
|
||||
int32_t m_nbRay;
|
||||
etkFloat_t m_ratio;
|
||||
etkFloat_t m_shadowOutput;
|
||||
//etkFloat_t m_angle;
|
||||
//etkFloat_t m_angleDisplayed;
|
||||
public:
|
||||
|
||||
public:
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include <globalMsg.h>
|
||||
|
||||
static etk::VectorType<drawElement::Base*> l_listElements;
|
||||
static int32_t l_selected = -1;
|
||||
//!< Basic filename
|
||||
etk::UString l_fileName;
|
||||
|
||||
void drawElement::RemoveAll(void)
|
||||
{
|
||||
@ -31,6 +34,7 @@ void drawElement::RemoveAll(void)
|
||||
}
|
||||
l_listElements.Clear();
|
||||
etk::UString tmpString("");
|
||||
l_selected = -1;
|
||||
ewol::EObjectMessageMultiCast::AnonymousSend(drawMsgListElementChange, tmpString);
|
||||
}
|
||||
|
||||
@ -55,6 +59,9 @@ void drawElement::Rm(int32_t id)
|
||||
l_listElements[id] = NULL;
|
||||
}
|
||||
l_listElements.Erase(id);
|
||||
if (l_selected == id) {
|
||||
l_selected = -1;
|
||||
}
|
||||
}
|
||||
etk::UString tmpString("");
|
||||
ewol::EObjectMessageMultiCast::AnonymousSend(drawMsgListElementChange, tmpString);
|
||||
@ -88,6 +95,7 @@ void drawElement::Add(elementType_te type)
|
||||
return;
|
||||
}
|
||||
l_listElements.PushBack(newElement);
|
||||
l_selected = l_listElements.Size()-1;
|
||||
etk::UString tmpString("");
|
||||
ewol::EObjectMessageMultiCast::AnonymousSend(drawMsgListElementChange, tmpString);
|
||||
}
|
||||
@ -105,3 +113,239 @@ void drawElement::Down(int32_t id)
|
||||
etk::UString tmpString("");
|
||||
ewol::EObjectMessageMultiCast::AnonymousSend(drawMsgListElementChange, tmpString);
|
||||
}
|
||||
|
||||
void drawElement::SelectSet(int32_t id)
|
||||
{
|
||||
if (id < l_listElements.Size() && id >=0) {
|
||||
l_selected = id;
|
||||
etk::UString tmpString("");
|
||||
ewol::EObjectMessageMultiCast::AnonymousSend(drawMsgListElementChange, tmpString);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t drawElement::SelectGet(void)
|
||||
{
|
||||
return l_selected;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void drawElement::SetFilename(etk::UString fileName)
|
||||
{
|
||||
l_fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
bool drawElement::HasName(void)
|
||||
{
|
||||
if(l_fileName=="") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
<e2d ratio="1.000">
|
||||
<element type="Mesh" name="hjhj">
|
||||
<dot id=1 x="0.2352" y="0.435634" />
|
||||
<dot id=2 x="0.6746" y="0.323467" />
|
||||
<dot id=3 x="0.4657" y="0.234131" />
|
||||
<dot id=3 x="0.00000" y="1.000000" />
|
||||
<link id1="1" color1="#45F645FF"
|
||||
id2="2" color2="#345635FF"
|
||||
id3="4" color3="#867757FF"/>
|
||||
</element>
|
||||
<element type="Circle" name="plop">
|
||||
<color>#45F645FF</color>
|
||||
<center x="0.2352" y="0.435634" />
|
||||
<ratio>0.752</ratio>
|
||||
<nbRay>12</nbRay>
|
||||
<thickness>0.03</thickness>
|
||||
<shadowOutput>0.1</shadowOutput>
|
||||
<shadowInput>0.1</shadowInput>
|
||||
</element>
|
||||
</e2d>
|
||||
*/
|
||||
|
||||
void drawElement::Load(etk::UString fileName)
|
||||
{
|
||||
drawElement::RemoveAll();
|
||||
SetFilename(newFileName);
|
||||
|
||||
DRAW_DEBUG("open file (DRAWER) \"" << l_fileName << "\"");
|
||||
|
||||
// allocate the document in the stack
|
||||
TiXmlDocument XmlDocument;
|
||||
// open the curent File
|
||||
etk::File fileName(l_fileName, etk::FILE_TYPE_DIRECT);
|
||||
if (false == fileName.Exist()) {
|
||||
DRAW_ERROR("File Does not exist : " << fileName);
|
||||
return;
|
||||
}
|
||||
int32_t fileSize = fileName.Size();
|
||||
if (0==fileSize) {
|
||||
DRAW_ERROR("This file is empty : " << fileName);
|
||||
return;
|
||||
}
|
||||
if (false == fileName.fOpenRead()) {
|
||||
DRAW_ERROR("Can not open the file : " << fileName);
|
||||
return;
|
||||
}
|
||||
// allocate data
|
||||
char * fileBuffer = new char[fileSize+5];
|
||||
if (NULL == fileBuffer) {
|
||||
DRAW_ERROR("Error Memory allocation size=" << fileSize);
|
||||
return;
|
||||
}
|
||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
fileName.fRead(fileBuffer, 1, fileSize);
|
||||
// close the file:
|
||||
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 ) {
|
||||
DRAW_ERROR("(l ?) main node not find: \"e2d\" in \"" << 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;
|
||||
DRAW_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;
|
||||
}
|
||||
}
|
||||
DRAW_DEBUG("load link : [" << localLink.dot[0] << "," << localLink.dot[1] << "," << localLink.dot[2] << "] ");
|
||||
DRAW_DEBUG(" col: [" << localLink.color[0] << "," << localLink.color[1] << "," << localLink.color[2] << "] ");
|
||||
m_linkList.PushBack(localLink);
|
||||
}
|
||||
} else {
|
||||
DRAW_ERROR("(l "<<pGuiNode->Row()<<") node not suported : \""<<pGuiNode->Value()<<"\" must be [dot,link]");
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
DRAW_ERROR("(l "<<pNode->Row()<<") node not suported : \""<<pNode->Value()<<"\" must be [element]");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NULL != fileBuffer) {
|
||||
delete[] fileBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void drawElement::Save(void)
|
||||
{
|
||||
if (l_fileName == "") {
|
||||
DRAW_ERROR("No filename set ...");
|
||||
return;
|
||||
}
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );
|
||||
doc.LinkEndChild( decl );
|
||||
TiXmlElement * mastertElement = new TiXmlElement( "e2d" );
|
||||
mastertElement->SetAttribute( "version", "0.1" );
|
||||
doc.LinkEndChild( mastertElement );
|
||||
|
||||
TiXmlElement * element = new TiXmlElement( "element" );
|
||||
element->SetAttribute( "name", "???" );
|
||||
element->SetAttribute( "type", "mesh" );
|
||||
mastertElement->LinkEndChild( element );
|
||||
|
||||
for(int32_t iii=0; iii<m_dotList.Size() ; iii++) {
|
||||
char tmpChar[256];
|
||||
TiXmlElement * elementDot = new TiXmlElement( "dot" );
|
||||
elementDot->SetAttribute( "id", iii );
|
||||
sprintf(tmpChar, "%f", m_dotList[iii].x);
|
||||
elementDot->SetAttribute( "x", tmpChar );
|
||||
sprintf(tmpChar, "%f", m_dotList[iii].y);
|
||||
elementDot->SetAttribute( "y", tmpChar );
|
||||
element->LinkEndChild( elementDot );
|
||||
}
|
||||
for(int32_t iii=0; iii<m_linkList.Size() ; iii++) {
|
||||
TiXmlElement * elementDot = new TiXmlElement( "link" );
|
||||
elementDot->SetAttribute( "id1", m_linkList[iii].dot[0] );
|
||||
char colorText[256];
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[0].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color1", colorText );
|
||||
elementDot->SetAttribute( "id2", m_linkList[iii].dot[1] );
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[1].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color2", colorText );
|
||||
elementDot->SetAttribute( "id3", m_linkList[iii].dot[2] );
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[2].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color3", colorText );
|
||||
element->LinkEndChild( elementDot );
|
||||
}
|
||||
//Save Document
|
||||
doc.SaveFile( l_fileName.Utf8Data() );
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,6 @@
|
||||
#include <elementBase.h>
|
||||
|
||||
namespace drawElement {
|
||||
typedef enum {
|
||||
DRAW_ELEMENT_TYPE_CIRCLE,
|
||||
DRAW_ELEMENT_TYPE_DISK,
|
||||
DRAW_ELEMENT_TYPE_MESH,
|
||||
DRAW_ELEMENT_TYPE_POLYGONE,
|
||||
DRAW_ELEMENT_TYPE_RECTANGLE,
|
||||
}elementType_te;
|
||||
|
||||
void RemoveAll(void);
|
||||
int32_t Size(void);
|
||||
@ -34,7 +27,13 @@ namespace drawElement {
|
||||
void Add(elementType_te type);
|
||||
void Up(int32_t id);
|
||||
void Down(int32_t id);
|
||||
void SelectSet(int32_t id);
|
||||
int32_t SelectGet(void);
|
||||
|
||||
void Load(etk::UString fileName);
|
||||
void Save(void);
|
||||
void SetFilename(etk::UString fileName);
|
||||
bool HasName(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <elementBase.h>
|
||||
|
||||
|
||||
drawElement::Mesh::Mesh(void) : Base("Mesh")
|
||||
drawElement::Mesh::Mesh(void) : Base(DRAW_ELEMENT_TYPE_MESH)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <elementBase.h>
|
||||
|
||||
|
||||
drawElement::Polygone::Polygone(void) : Base("Polygone")
|
||||
drawElement::Polygone::Polygone(void) : Base(DRAW_ELEMENT_TYPE_POLYGONE)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <elementBase.h>
|
||||
|
||||
|
||||
drawElement::Rectangle::Rectangle(void) : Base("Rectangle")
|
||||
drawElement::Rectangle::Rectangle(void) : Base(DRAW_ELEMENT_TYPE_RECTANGLE)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,16 @@ namespace drawElement {
|
||||
Rectangle(void);
|
||||
virtual ~Rectangle(void);
|
||||
private:
|
||||
|
||||
color_ts m_colorBorder;
|
||||
color_ts m_colorInside;
|
||||
coord2D_ts m_center;
|
||||
coord2D_ts m_size;
|
||||
bool m_fill
|
||||
etkFloat_t m_thickness;
|
||||
etkFloat_t m_shadowOutput;
|
||||
etkFloat_t m_shadowInput;
|
||||
//etkFloat_t m_angle;
|
||||
//etkFloat_t m_angleDisplayed;
|
||||
public:
|
||||
|
||||
public:
|
||||
|
@ -61,6 +61,7 @@ widgetDrawer::widgetDrawer(void)
|
||||
m_triangleColor.alpha = 1.0;
|
||||
|
||||
RegisterMultiCast(drawMsgGuiLinkNew);
|
||||
RegisterMultiCast(drawMsgListElementChange);
|
||||
SetCanHaveFocus(true);
|
||||
}
|
||||
|
||||
@ -179,6 +180,7 @@ void widgetDrawer::OnRegenerateDisplay(void)
|
||||
for (int32_t iii=0; iii<nbElement; iii++) {
|
||||
m_OObjectsColored[m_currentCreateId].Rectangle(drawPosStart.x, drawPosStart.y + iii*20, drawPosStop.x, 10);
|
||||
}
|
||||
m_OObjectsColored[m_currentCreateId].clippingDisable();
|
||||
coord2D_ts drawSize;
|
||||
drawSize.x = drawPosStop.x-drawPosStart.x;
|
||||
drawSize.y = drawPosStop.y-drawPosStart.y;
|
||||
@ -438,6 +440,8 @@ void widgetDrawer::OnReceiveMessage(ewol::EObject * CallerObject, const char * e
|
||||
m_linkList.PushBack(tmpLink);
|
||||
MarkToReedraw();
|
||||
}
|
||||
} else if (eventId == drawMsgListElementChange) {
|
||||
MarkToReedraw();
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,215 +481,3 @@ void widgetDrawer::SetColorOnSelected(color_ts newColor)
|
||||
MarkToReedraw();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
<e2d ratio="1.000">
|
||||
<element name="hjhj">
|
||||
<dot id=1 x="0.2352" y="0.435634" />
|
||||
<dot id=2 x="0.6746" y="0.323467" />
|
||||
<dot id=3 x="0.4657" y="0.234131" />
|
||||
<dot id=3 x="0.00000" y="1.000000" />
|
||||
<link id1="1" color1="#45F645FF"
|
||||
id2="2" color2="#345635FF"
|
||||
id3="4" color3="#867757FF"/>
|
||||
</element>
|
||||
</e2d>
|
||||
*/
|
||||
void widgetDrawer::Load(etk::UString newFileName)
|
||||
{
|
||||
|
||||
// Remove all local elements :
|
||||
m_dotList.Clear();
|
||||
m_linkList.Clear();
|
||||
m_selectedList.Clear();
|
||||
m_nearestDot = -1;
|
||||
m_movingPoint = false;
|
||||
m_fileName = newFileName;
|
||||
|
||||
DRAW_DEBUG("open file (DRAWER) \"" << m_fileName << "\"");
|
||||
|
||||
// allocate the document in the stack
|
||||
TiXmlDocument XmlDocument;
|
||||
// open the curent File
|
||||
etk::File fileName(m_fileName, etk::FILE_TYPE_DIRECT);
|
||||
if (false == fileName.Exist()) {
|
||||
DRAW_ERROR("File Does not exist : " << fileName);
|
||||
return;
|
||||
}
|
||||
int32_t fileSize = fileName.Size();
|
||||
if (0==fileSize) {
|
||||
DRAW_ERROR("This file is empty : " << fileName);
|
||||
return;
|
||||
}
|
||||
if (false == fileName.fOpenRead()) {
|
||||
DRAW_ERROR("Can not open the file : " << fileName);
|
||||
return;
|
||||
}
|
||||
// allocate data
|
||||
char * fileBuffer = new char[fileSize+5];
|
||||
if (NULL == fileBuffer) {
|
||||
DRAW_ERROR("Error Memory allocation size=" << fileSize);
|
||||
return;
|
||||
}
|
||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
fileName.fRead(fileBuffer, 1, fileSize);
|
||||
// close the file:
|
||||
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 ) {
|
||||
DRAW_ERROR("(l ?) main node not find: \"e2d\" in \"" << 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;
|
||||
DRAW_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;
|
||||
}
|
||||
}
|
||||
DRAW_DEBUG("load link : [" << localLink.dot[0] << "," << localLink.dot[1] << "," << localLink.dot[2] << "] ");
|
||||
DRAW_DEBUG(" col: [" << localLink.color[0] << "," << localLink.color[1] << "," << localLink.color[2] << "] ");
|
||||
m_linkList.PushBack(localLink);
|
||||
}
|
||||
} else {
|
||||
DRAW_ERROR("(l "<<pGuiNode->Row()<<") node not suported : \""<<pGuiNode->Value()<<"\" must be [dot,link]");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DRAW_ERROR("(l "<<pNode->Row()<<") node not suported : \""<<pNode->Value()<<"\" must be [element]");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NULL != fileBuffer) {
|
||||
delete[] fileBuffer;
|
||||
}
|
||||
MarkToReedraw();
|
||||
}
|
||||
/*
|
||||
<e2d ratio="1.000">
|
||||
<element name="hjhj">
|
||||
<dot id=1 x="0.2352" y="0.435634" />
|
||||
<dot id=2 x="0.6746" y="0.323467" />
|
||||
<dot id=3 x="0.4657" y="0.234131" />
|
||||
<dot id=3 x="0.00000" y="1.000000" />
|
||||
<link id1="1" color1="#45F645FF"
|
||||
id2="2" color2="#345635FF"
|
||||
id3="4" color3="#867757FF"/>
|
||||
</element>
|
||||
</e2d>
|
||||
*/
|
||||
void widgetDrawer::Save(void)
|
||||
{
|
||||
if (m_fileName == "") {
|
||||
DRAW_ERROR("No filename set ...");
|
||||
return;
|
||||
}
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );
|
||||
doc.LinkEndChild( decl );
|
||||
TiXmlElement * mastertElement = new TiXmlElement( "e2d" );
|
||||
mastertElement->SetAttribute( "version", "0.1" );
|
||||
doc.LinkEndChild( mastertElement );
|
||||
|
||||
TiXmlElement * element = new TiXmlElement( "element" );
|
||||
element->SetAttribute( "name", "???" );
|
||||
element->SetAttribute( "type", "mesh" );
|
||||
mastertElement->LinkEndChild( element );
|
||||
|
||||
for(int32_t iii=0; iii<m_dotList.Size() ; iii++) {
|
||||
char tmpChar[256];
|
||||
TiXmlElement * elementDot = new TiXmlElement( "dot" );
|
||||
elementDot->SetAttribute( "id", iii );
|
||||
sprintf(tmpChar, "%f", m_dotList[iii].x);
|
||||
elementDot->SetAttribute( "x", tmpChar );
|
||||
sprintf(tmpChar, "%f", m_dotList[iii].y);
|
||||
elementDot->SetAttribute( "y", tmpChar );
|
||||
element->LinkEndChild( elementDot );
|
||||
}
|
||||
for(int32_t iii=0; iii<m_linkList.Size() ; iii++) {
|
||||
TiXmlElement * elementDot = new TiXmlElement( "link" );
|
||||
elementDot->SetAttribute( "id1", m_linkList[iii].dot[0] );
|
||||
char colorText[256];
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[0].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[0].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color1", colorText );
|
||||
elementDot->SetAttribute( "id2", m_linkList[iii].dot[1] );
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[1].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[1].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color2", colorText );
|
||||
elementDot->SetAttribute( "id3", m_linkList[iii].dot[2] );
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(m_linkList[iii].color[2].red * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].green * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].blue * 0xFF),
|
||||
(uint8_t)(m_linkList[iii].color[2].alpha * 0xFF));
|
||||
elementDot->SetAttribute( "color3", colorText );
|
||||
element->LinkEndChild( elementDot );
|
||||
}
|
||||
//Save Document
|
||||
doc.SaveFile( m_fileName.Utf8Data() );
|
||||
}
|
||||
|
||||
|
@ -112,16 +112,12 @@ class widgetDrawer :public ewol::Widget
|
||||
etk::VectorType<int32_t> m_selectedList; //!< current selected points
|
||||
int32_t m_nearestDot; //!< nearest dot from the current cursor
|
||||
bool m_movingPoint;
|
||||
etk::UString m_fileName;
|
||||
|
||||
void removeDotId(int32_t id);
|
||||
int32_t GetNearestPoint(coord2D_ts pos);
|
||||
etkFloat_t QuadDistance(coord2D_ts aaa, coord2D_ts bbb);
|
||||
bool DotIsSelected(int32_t dotId);
|
||||
public:
|
||||
void Load(etk::UString fileName);
|
||||
void Save(void);
|
||||
void SetFilename(etk::UString fileName) {m_fileName = fileName; };
|
||||
bool HasName(void) { if(m_fileName=="") { return false;} return true; };
|
||||
};
|
||||
|
||||
#define DRAW_CAST_WIDGET_DRAWER(curentPointer) EWOL_CAST(TYPE_EOBJECT_WIDGET_DRAW_DRAWER,ewol::widgetDrawer,curentPointer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user