Commit ca782d2f authored by Tebjan Halm's avatar Tebjan Halm
Browse files

work on update events

parent 28b654f0
......@@ -50,6 +50,7 @@ namespace Svg
set
{
_x = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "x", Value = value });
IsPathDirty = true;
}
}
......@@ -64,6 +65,7 @@ namespace Svg
set
{
_y = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "y", Value = value });
IsPathDirty = true;
}
}
......@@ -78,6 +80,7 @@ namespace Svg
set
{
_width = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "width", Value = value });
IsPathDirty = true;
}
}
......@@ -92,6 +95,7 @@ namespace Svg
set
{
_height = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "height", Value = value });
IsPathDirty = true;
}
}
......
......@@ -94,6 +94,7 @@ namespace Svg
internal void OnPathUpdated()
{
this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "d", Value = this.PathData });
}
/// <summary>
......
......@@ -30,6 +30,7 @@ namespace Svg
public SvgAttributeAttribute Attribute;
}
//reflection cache
protected IEnumerable<PropertyAttributeTuple> _svgPropertyAttributes;
protected IEnumerable<EventAttributeTuple> _svgEventAttributes;
......@@ -68,10 +69,28 @@ namespace Svg
/// <summary>
/// Gets or sets the content of the element.
/// </summary>
private string _content;
public virtual string Content
{
get;
set;
get
{
return _content;
}
set
{
if(_content != null)
{
var oldVal = _content;
_content = value;
if(_content != oldVal)
OnAttributeChanged(new AttributeEventArgs{ Attribute = "", Value = value });
}
else
{
_content = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "", Value = value });
}
}
}
/// <summary>
......@@ -220,8 +239,15 @@ namespace Svg
[SvgAttribute("transform")]
public SvgTransformCollection Transforms
{
get { return (this.Attributes.GetAttribute<SvgTransformCollection>("Transforms") ?? new SvgTransformCollection()); }
set { this.Attributes["Transforms"] = value; }
get { return (this.Attributes.GetAttribute<SvgTransformCollection>("Transforms")); }
set
{
var old = this.Transforms;
if(old != null)
old.TransformChanged -= Attributes_AttributeChanged;
value.TransformChanged += Attributes_AttributeChanged;
this.Attributes["Transforms"] = value;
}
}
/// <summary>
......@@ -302,6 +328,8 @@ namespace Svg
this._elementName = string.Empty;
this._customAttributes = new SvgCustomAttributeCollection(this);
Transforms = new SvgTransformCollection();
//subscribe to attribute events
Attributes.AttributeChanged += Attributes_AttributeChanged;
CustomAttributes.AttributeChanged += Attributes_AttributeChanged;
......
......@@ -83,7 +83,12 @@ namespace Svg
public virtual SvgUnit X
{
get { return this._x; }
set { this._x = value; this.IsPathDirty = true; }
set
{
this._x = value;
this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "x", Value = value });
}
}
/// <summary>
......@@ -94,7 +99,12 @@ namespace Svg
public virtual SvgUnit Y
{
get { return this._y; }
set { this._y = value; this.IsPathDirty = true; }
set
{
this._y = value;
this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "y", Value = value });
}
}
/// <summary>
......
......@@ -46,7 +46,6 @@ namespace Svg.Transforms
this.scaleFactorY = y;
}
public override object Clone()
{
return new SvgScale(this.X, this.Y);
......
......@@ -10,6 +10,31 @@ namespace Svg.Transforms
[TypeConverter(typeof(SvgTransformConverter))]
public class SvgTransformCollection : List<SvgTransform>
{
public new void Add(SvgTransform item)
{
base.Add(item);
OnTransformChanged();
}
public new void AddRange(IEnumerable<SvgTransform> collection)
{
base.AddRange(collection);
OnTransformChanged();
}
public new void Remove(SvgTransform item)
{
base.Remove(item);
OnTransformChanged();
}
public new void RemoveAt(int index)
{
base.RemoveAt(index);
OnTransformChanged();
}
/// <summary>
/// Multiplies all matrices
/// </summary>
......@@ -32,13 +57,38 @@ namespace Svg.Transforms
return transformMatrix;
}
public override bool Equals(object obj)
{
if (this.Count == 0 && this.Count == this.Count) //default will be an empty list
if (this.Count == 0 && this.Count == base.Count) //default will be an empty list
return true;
return base.Equals(obj);
}
public new SvgTransform this[int i]
{
get { return base[i]; }
set
{
var oldVal = base[i];
base[i] = value;
if(oldVal != value)
OnTransformChanged();
}
}
/// <summary>
/// Fired when an SvgTransform has changed
/// </summary>
public event EventHandler<AttributeEventArgs> TransformChanged;
protected void OnTransformChanged()
{
var handler = TransformChanged;
if(handler != null)
{
handler(this, new AttributeEventArgs { Attribute = "transform", Value = this });
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment