Example #1
0
        private int ReadRectangle(XmlNode rectNode)
        {
            float  x = 0f, y = 0f, w = 0f, h = 0f, rx = -1f, ry = -1f;
            string attribute = GetAttributeContent(rectNode, "x");

            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out x);
            attribute = GetAttributeContent(rectNode, "y");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out y);
            attribute = GetAttributeContent(rectNode, "width");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out w);
            attribute = GetAttributeContent(rectNode, "height");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out h);
            attribute = GetAttributeContent(rectNode, "rx");
            if (attribute != "ERROR")
            {
                float.TryParse(attribute, out rx);
            }
            attribute = GetAttributeContent(rectNode, "ry");
            if (attribute != "ERROR")
            {
                float.TryParse(attribute, out ry);
            }
            else
            {
                ry = rx;
            }
            string elementName = GetAttributeContent(rectNode, "id");

            if (rx == -1f && ry == -1f)
            {
                Rectangle rect = new Rectangle();
                rect.offset = new Vector2(x + w / 2f, -y - h / 2f);
                rect.size   = new Vector2(w, h);
                if (elementName == "ERROR")
                {
                    elementName = fileName + "_rectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(elementName, rect.CreateSpline());
            }
            else
            {
                RoundedRectangle rect = new RoundedRectangle();
                rect.offset  = new Vector2(x + w / 2f, -y - h / 2f);
                rect.size    = new Vector2(w, h);
                rect.xRadius = rx;
                rect.yRadius = ry;
                if (elementName == "ERROR")
                {
                    elementName = fileName + "_roundedRectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(elementName, rect.CreateSpline());
            }
            int addedTransforms = ParseTransformation(rectNode);

            WriteBufferTo(rectangles);
            return(addedTransforms);
        }