123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- using System;
- using System.Reflection;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.Threading.Tasks;
- namespace ConsoleApplication
- {
- public class ShapeObject : SceneObjectDecorator
- {
- private float _alpha, _cornerRadius, _fillAlpha, _fillAlpha1, _fillAlpha2, _gradientAngle, _rotation, _rotationX, _rotationY, _rotationZ, _scaleZ;
- private int _lineAlpha, _lineSize, _x, _y, _z, _points, _radius;
- private Boolean _cacheAsBitmap, _fillEnable, _lineEnabled, _visible;
- private string _fillType, _gradientType, _fillColor, _lineColor, _fillColor1, _fillColor2;
- private float[] _gradientAlphas;
- private string[] _gradientFills;
- private string[] _attributes = new string[24]{ "alpha", "cacheAsBitmap", "cornerRadius", "gradientAngle", "gradientType", "fillAlpha", "fillColor",
- "fillEnable", "fillType", "lineAlpha", "lineColor", "lineEnabled", "lineSize", "points", "radius",
- "rotation", "rotationX", "rotationY", "rotationZ", "scaleZ", "visible", "x",
- "y", "z"};
- private List<String> _shapeObjectAccessorChild = new List<string>();
- private List<XmlElement> _accessorChildList;
- private Properties _properties;
- public enum shape_type{
- Rectangle,
- Circle,
- Polygon
- }
- public ShapeObject(SceneObject sceneobject, shape_type shapeType) : base(sceneobject)
- {
- _shapeObjectAccessorChild.AddRange(_attributes);
-
- string objectType = "";
- switch (shapeType)
- {
- case shape_type.Rectangle:
- objectType = "com.yooba.shapes.RoundedRectangleShape";
- _shapeObjectAccessorChild.Remove("radius");
- break;
- case shape_type.Circle:
- objectType = "com.yooba.shapes.CircleShape";
- _shapeObjectAccessorChild.Remove("cornerRadius");
- break;
- case shape_type.Polygon:
- objectType = "com.yooba.shapes.PolygonShape";
- _shapeObjectAccessorChild.Remove("radius");
- _shapeObjectAccessorChild.Remove("cornerRadius");
- break;
- }
- sceneobject.setObjectType(objectType);
- _accessorChildList = new List<XmlElement>();
- _alpha = 1;
- _cacheAsBitmap = false;
- _cornerRadius = 0;
- _gradientAngle = 90;
- _gradientType = "linear";
- _fillAlpha = 100000;
- _fillAlpha1 = 100000;
- _fillAlpha2 = 100000;
- _fillColor = "16743690";
- _fillEnable = true;
- _fillType = "solid";
- _lineAlpha = 1;
- _lineColor = "6426397";
- _lineEnabled = false;
- _lineSize = 0;
- _points = 3;
- _radius = 0;
- _rotation = 0;
- _rotationX = 0;
- _rotationY = 0;
- _rotationZ = 0;
- _scaleZ = 1;
- _visible = true;
- _x = 0;
- _y = 0;
- _z = 0;
- _gradientAlphas = new float[2];
- _gradientAlphas[0] = 100000;
- _gradientAlphas[1] = 100000;
- _gradientFills = new string[2];
- _fillColor1 = _fillColor;
- _fillColor2 = "10834182";
- _properties = new Properties(true,false,true,true,true,true,true,true,false,true,true,false,true,true,true);
- }
- public override XmlElement getXMLTree()
- {
- XmlElement parent = base.getXMLTree();
- parent.AppendChild(Properties.getNode(getXMLDocumentRoot()));
- XmlElement acce = getXMLDocumentRoot().CreateElement("accessors");
- foreach (string s in _shapeObjectAccessorChild)
- {
- XmlElement xmlChild = getXMLDocumentRoot().CreateElement(s);
- FieldInfo fieldInfo = GetType().GetField("_" + s, BindingFlags.NonPublic | BindingFlags.Instance);
- if (fieldInfo != null)
- xmlChild.InnerText = fieldInfo.GetValue(this).ToString().Replace(",",".").ToLower();
- acce.AppendChild(xmlChild);
- }
- XmlElement gradientColor = getXMLDocumentRoot().CreateElement("gradientFills");
- gradientColor.InnerText = _fillColor1.ToString() + ", " + _fillColor2.ToString();
- XmlElement gradientAlpha = getXMLDocumentRoot().CreateElement("gradientAlphas");
- gradientAlpha.InnerText = _fillAlpha1.ToString().Replace(",", ".") + ", " + _fillAlpha2.ToString().Replace(",", ".");
- acce.AppendChild(gradientColor);
- acce.AppendChild(gradientAlpha);
- parent.AppendChild(acce);
- return parent;
-
- }
- public override void ConvertToYoobaUnits(int width, int height)
- {
- base.ConvertToYoobaUnits(width, height);
- if (_fillType.Equals("solid"))
- {
- _fillColor = getColorAsInteger(_fillColor).ToString();
- _fillAlpha /= 100000;
- }
- if (_fillType.Equals("gradient"))
- {
- _fillColor = getColorAsInteger(_fillColor1).ToString();
- _fillAlpha1 /= 100000;
- _fillAlpha2 /= 100000;
- _fillColor1 = _fillColor;
- _fillColor2 = getColorAsInteger(_fillColor2).ToString();
-
- _gradientAngle /= 60000;
- }
- _lineSize = (int) Math.Round((double)_lineSize / 12700);
- if (_lineSize <= 0)
- _lineEnabled = false;
- else
- _lineEnabled = true;
- _lineColor = getColorAsInteger(_lineColor).ToString();
- _cornerRadius = (float) Math.Round((_cornerRadius / 100000) * 128 * 4);
- _rotation /= 60000;
-
- }
- public override XmlDocument getXMLDocumentRoot()
- {
- return base.getXMLDocumentRoot();
- }
- public override void setXMLDocumentRoot(ref XmlDocument xmldocument)
- {
- base.setXMLDocumentRoot(ref xmldocument);
- }
- public override Properties getProperties()
- {
- return base.getProperties();
- }
- public override void setProperties(Properties properties)
- {
- base.setProperties(properties);
- }
- public int getColorAsInteger(string color)
- {
- if (color != "")
- return int.Parse(color, System.Globalization.NumberStyles.HexNumber);
- else
- return 0;
- }
- public float CornerRadius
- {
- get { return _cornerRadius; }
- set { _cornerRadius = value; }
- }
- public float ScaleZ
- {
- get { return _scaleZ; }
- set { _scaleZ = value; }
- }
- public string FillColor2
- {
- get { return _fillColor2; }
- set { _fillColor2 = value; }
- }
- public string FillColor1
- {
- get { return _fillColor1; }
- set { _fillColor1 = value; }
- }
- public float RotationZ
- {
- get { return _rotationZ; }
- set { _rotationZ = value; }
- }
- public float RotationY
- {
- get { return _rotationY; }
- set { _rotationY = value; }
- }
- public float RotationX
- {
- get { return _rotationX; }
- set { _rotationX = value; }
- }
- public float Rotation
- {
- get { return _rotation; }
- set { _rotation = value; }
- }
- public float GradientAngle
- {
- get { return _gradientAngle; }
- set { _gradientAngle = value; }
- }
- public float FillAlpha
- {
- get { return _fillAlpha; }
- set { _fillAlpha = value; }
- }
- public float Alpha
- {
- get { return _alpha; }
- set { _alpha = value; }
- }
- public float[] GradientAlphas
- {
- get { return _gradientAlphas; }
- set { _gradientAlphas = value; }
- }
- public int Z
- {
- get { return _z; }
- set { _z = value; }
- }
- public int Y
- {
- get { return _y; }
- set { _y = value; }
- }
- public int X
- {
- get { return _x; }
- set { _x = value; }
- }
- public int LineSize
- {
- get { return _lineSize; }
- set { _lineSize = value; }
- }
- public string LineColor
- {
- get { return _lineColor; }
- set { _lineColor = value; }
- }
- public int LineAlpha
- {
- get { return _lineAlpha; }
- set { _lineAlpha = value; }
- }
- public string FillColor
- {
- get { return _fillColor; }
- set { _fillColor = value; }
- }
- public Boolean Visible
- {
- get { return _visible; }
- set { _visible = value; }
- }
- public Boolean LineEnabled
- {
- get { return _lineEnabled; }
- set { _lineEnabled = value; }
- }
- public Boolean FillEnable
- {
- get { return _fillEnable; }
- set { _fillEnable = value; }
- }
- public Boolean CacheAsBitmap
- {
- get { return _cacheAsBitmap; }
- set { _cacheAsBitmap = value; }
- }
- public string GradientType
- {
- get { return _gradientType; }
- set { _gradientType = value; }
- }
- public string FillType
- {
- get { return _fillType; }
- set { _fillType = value; }
- }
- public string[] GradientFills
- {
- get { return _gradientFills; }
- set { _gradientFills = value; }
- }
- public int Radius
- {
- get { return _radius; }
- set { _radius = value; }
- }
- public int Points
- {
- get { return _points; }
- set { _points = value; }
- }
- public float FillAlpha2
- {
- get { return _fillAlpha2; }
- set { _fillAlpha2 = value; }
- }
- public float FillAlpha1
- {
- get { return _fillAlpha1; }
- set { _fillAlpha1 = value; }
- }
- public Properties Properties
- {
- get { return _properties; }
- set { _properties = value; }
- }
- internal void setAttributes(TableStyle tableStyle)
- {
- if(tableStyle==null)
- return;
- FillAlpha = (tableStyle.FillAlpha != 0) ? tableStyle.FillAlpha : FillAlpha;
- FillColor = (tableStyle.FillColor != "") ? tableStyle.FillColor : FillColor;
- LineSize = (tableStyle.LineSize != 0) ? tableStyle.LineSize : LineSize;
- LineColor = (tableStyle.LineColor != "") ? tableStyle.LineColor : LineColor;
- }
- }
- }
|