From a85028f8d5d44e02bbce2794cc6f326e4b363b94 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 16 Mar 2012 17:36:40 +0100 Subject: [PATCH] Change the XML saving and add an curent element id selected --- jni/Main.cpp | 26 ++--- jni/elementBase.cpp | 19 ++- jni/elementBase.h | 28 +++-- jni/elementCircle.cpp | 12 +- jni/elementCircle.h | 10 +- jni/elementDisk.cpp | 2 +- jni/elementDisk.h | 8 +- jni/elementManager.cpp | 244 +++++++++++++++++++++++++++++++++++++++ jni/elementManager.h | 13 +-- jni/elementMesh.cpp | 2 +- jni/elementPolygone.cpp | 2 +- jni/elementRectangle.cpp | 2 +- jni/elementRectangle.h | 11 +- jni/widgetDrawer.cpp | 216 +--------------------------------- jni/widgetDrawer.h | 6 +- 15 files changed, 338 insertions(+), 263 deletions(-) diff --git a/jni/Main.cpp b/jni/Main.cpp index 9e16c25..9b05d11 100644 --- a/jni/Main.cpp +++ b/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; } diff --git a/jni/elementBase.cpp b/jni/elementBase.cpp index 32c5c14..aad973a 100644 --- a/jni/elementBase.cpp +++ b/jni/elementBase.cpp @@ -16,7 +16,7 @@ #include #include -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 "??"; +} \ No newline at end of file diff --git a/jni/elementBase.h b/jni/elementBase.h index 690e95e..049e313 100644 --- a/jni/elementBase.h +++ b/jni/elementBase.h @@ -21,22 +21,30 @@ #include 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; }; diff --git a/jni/elementCircle.cpp b/jni/elementCircle.cpp index 50ae019..21d6a44 100644 --- a/jni/elementCircle.cpp +++ b/jni/elementCircle.cpp @@ -17,12 +17,12 @@ #include -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); } diff --git a/jni/elementCircle.h b/jni/elementCircle.h index f6e5709..033ec3e 100644 --- a/jni/elementCircle.h +++ b/jni/elementCircle.h @@ -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; }; diff --git a/jni/elementDisk.cpp b/jni/elementDisk.cpp index c9497ab..5a99308 100644 --- a/jni/elementDisk.cpp +++ b/jni/elementDisk.cpp @@ -19,7 +19,7 @@ -drawElement::Disk::Disk(void) : Base("Disk") +drawElement::Disk::Disk(void) : Base(DRAW_ELEMENT_TYPE_DISK) { } diff --git a/jni/elementDisk.h b/jni/elementDisk.h index e367f61..10399d9 100644 --- a/jni/elementDisk.h +++ b/jni/elementDisk.h @@ -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: diff --git a/jni/elementManager.cpp b/jni/elementManager.cpp index 156c5ec..d40f16e 100644 --- a/jni/elementManager.cpp +++ b/jni/elementManager.cpp @@ -20,6 +20,9 @@ #include static etk::VectorType 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; +} + + +/* + + + + + + + + + + #45F645FF +
+ 0.752 + 12 + 0.03 + 0.1 + 0.1 + + +*/ + +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 "<Row()<<") node not suported : \""<Value()<<"\" must be [dot,link]"); + } + } + */ + } else { + DRAW_ERROR("(l "<Row()<<") node not suported : \""<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; iiiSetAttribute( "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; iiiSetAttribute( "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() ); +} + diff --git a/jni/elementManager.h b/jni/elementManager.h index 689bede..8442b3c 100644 --- a/jni/elementManager.h +++ b/jni/elementManager.h @@ -19,13 +19,6 @@ #include 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 diff --git a/jni/elementMesh.cpp b/jni/elementMesh.cpp index 5b5c222..3f225d1 100644 --- a/jni/elementMesh.cpp +++ b/jni/elementMesh.cpp @@ -17,7 +17,7 @@ #include -drawElement::Mesh::Mesh(void) : Base("Mesh") +drawElement::Mesh::Mesh(void) : Base(DRAW_ELEMENT_TYPE_MESH) { } diff --git a/jni/elementPolygone.cpp b/jni/elementPolygone.cpp index 2dd5d81..e575eee 100644 --- a/jni/elementPolygone.cpp +++ b/jni/elementPolygone.cpp @@ -17,7 +17,7 @@ #include -drawElement::Polygone::Polygone(void) : Base("Polygone") +drawElement::Polygone::Polygone(void) : Base(DRAW_ELEMENT_TYPE_POLYGONE) { } diff --git a/jni/elementRectangle.cpp b/jni/elementRectangle.cpp index 941078a..bfaa0f0 100644 --- a/jni/elementRectangle.cpp +++ b/jni/elementRectangle.cpp @@ -17,7 +17,7 @@ #include -drawElement::Rectangle::Rectangle(void) : Base("Rectangle") +drawElement::Rectangle::Rectangle(void) : Base(DRAW_ELEMENT_TYPE_RECTANGLE) { } diff --git a/jni/elementRectangle.h b/jni/elementRectangle.h index 40f9763..4929aef 100644 --- a/jni/elementRectangle.h +++ b/jni/elementRectangle.h @@ -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: diff --git a/jni/widgetDrawer.cpp b/jni/widgetDrawer.cpp index 966e8da..bdf85d2 100644 --- a/jni/widgetDrawer.cpp +++ b/jni/widgetDrawer.cpp @@ -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 - - - - - - - - -*/ -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 "<Row()<<") node not suported : \""<Value()<<"\" must be [dot,link]"); - } - } - } else { - DRAW_ERROR("(l "<Row()<<") node not suported : \""<Value()<<"\" must be [element]"); - } - } - } - if (NULL != fileBuffer) { - delete[] fileBuffer; - } - MarkToReedraw(); -} -/* - - - - - - - - - -*/ -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; iiiSetAttribute( "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; iiiSetAttribute( "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() ); -} - diff --git a/jni/widgetDrawer.h b/jni/widgetDrawer.h index ed0378f..52fee00 100644 --- a/jni/widgetDrawer.h +++ b/jni/widgetDrawer.h @@ -112,16 +112,12 @@ class widgetDrawer :public ewol::Widget etk::VectorType 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)