using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using GeoSigma.SigmaDrawerUtil;
namespace GeoSigma.SigmaDrawerStyle
{
///
/// 渐变充填效果
///
[XmlRoot("Effect")]
public class CurveEffect : CurveView
{
///
/// Initializes a new instance of the class.
///
public CurveEffect()
{
TypeName = "渐变色";
Mode = 1;
}
private GradientColors effectColor;
[Category("基础属性"), DisplayName("\t\t颜色"), Description("颜色")]
[XmlIgnoreAttribute]
[TypeConverter(typeof(SigmaDrawerStyle.Converter.BaseCollectionConverter))]
#if WEB_SERVICE
#else
[Editor("GeoSigma.SigmaDrawerStyle.PropertyEditorGradientColor, SigmaDrawerStyle", typeof(System.Drawing.Design.UITypeEditor))]
#endif
// [Editor("UCDraw.Editor.CurveGradientEditor, UCDraw", typeof(System.Drawing.Design.UITypeEditor))]
public GradientColors EffectColor
{
get
{
if (effectColor == null)
{
effectColor = new GradientColors();
effectColor.AddRange(GradientColorManager.DefaultColorTemplate.CloneColors());
}
if (effectColor != null && effectColor.Count > 0)
{
double dStep = 100D / (effectColor.Count - 1);
for (int i = 0; i < effectColor.Count; i++)
{
// effectColor[i].Z = $"{dStep * i}";
effectColor[i].Z = dStep * i;
}
}
return effectColor;
}
set
{
if (value == null)
{
effectColor = null;
}
else
{
effectColor.Clear();
effectColor.AddRange(value.Select(item => item.Clone()));
}
}
}
///
/// 颜色字符串
///
[Browsable(false)]
[XmlElement("Color")]
public ValueColor ColorString
{
get
{
if (effectColor == null || effectColor.Count == 0)
{
return null;
}
StringBuilder strbData = new StringBuilder();
foreach (GradientColorItem colorItem in effectColor)
{
Color color = Color.FromArgb(colorItem.R, colorItem.G, colorItem.B);
strbData.Append(ColorTranslator.ToHtml(color) + " ");
}
return new ValueColor(strbData.ToString().Trim());
}
set
{
string[] straColor = value.Value.Split(' ');
effectColor = new GradientColors();
int nCount = straColor.Length;
double dStep = 100.0 / (nCount - 1);
for (int i = 0; i < straColor.Length; i++)
{
Color color = ColorTranslator.FromHtml(straColor[i]);
effectColor.Add(new GradientColorItem()
{
R = color.R,
G = color.G,
B = color.B,
Z = dStep * i,
Smooth = GradientColorItem.SmoothMode.G,
//Value = ColorRGBtoInt.Color2LongString(color),
});
}
}
}
[Category("基础属性"), DisplayName("\t充填方式"), Description("充填方式")]
[XmlAttribute("Mode")]
[TypeConverter(typeof(Converter.GradientTypeConverter))]
public int Mode { get; set; }
[Category("基础属性"), DisplayName("显示方式"), Description("显示方式")]
[XmlAttribute("Style")]
[TypeConverter(typeof(Converter.LineTypeLiteConverter))]
public int Style { get; set; }
///
/// 颜色数量
///
[Browsable(false)]
[XmlAttribute("Number")]
public int Number
{
get
{
if (EffectColor == null || EffectColor.Count == 0)
{
return 0;
}
return EffectColor.Count;
}
set
{
}
}
///
/// 渐变颜色类
///
public class ValueColor
{
///
/// Initializes a new instance of the class.
///
public ValueColor()
{
return;
}
///
/// Initializes a new instance of the class.
///
/// 颜色数据
public ValueColor(string data)
{
Value = data;
}
///
/// 颜色属性字符串
///
[XmlAttribute]
public string Value
{
get;
set;
}
}
}
public class CurveEffectColor
{
//[Category("\t其他"), DisplayName("\t\t渐变色")]
[Browsable(false)]
[XmlAttribute("Value")]
public string Value { get; set; }
[Browsable(false)]
[XmlIgnore]
public string ZValue
{
get;
set;
}
[Browsable(false)]
[XmlIgnore]
public string Smooth
{
get;
set;
}
}
}