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

work on update events

parent 28b654f0
...@@ -50,6 +50,7 @@ namespace Svg ...@@ -50,6 +50,7 @@ namespace Svg
set set
{ {
_x = value; _x = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "x", Value = value });
IsPathDirty = true; IsPathDirty = true;
} }
} }
...@@ -64,6 +65,7 @@ namespace Svg ...@@ -64,6 +65,7 @@ namespace Svg
set set
{ {
_y = value; _y = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "y", Value = value });
IsPathDirty = true; IsPathDirty = true;
} }
} }
...@@ -78,6 +80,7 @@ namespace Svg ...@@ -78,6 +80,7 @@ namespace Svg
set set
{ {
_width = value; _width = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "width", Value = value });
IsPathDirty = true; IsPathDirty = true;
} }
} }
...@@ -92,6 +95,7 @@ namespace Svg ...@@ -92,6 +95,7 @@ namespace Svg
set set
{ {
_height = value; _height = value;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "height", Value = value });
IsPathDirty = true; IsPathDirty = true;
} }
} }
......
...@@ -94,6 +94,7 @@ namespace Svg ...@@ -94,6 +94,7 @@ namespace Svg
internal void OnPathUpdated() internal void OnPathUpdated()
{ {
this.IsPathDirty = true; this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "d", Value = this.PathData });
} }
/// <summary> /// <summary>
......
...@@ -30,6 +30,7 @@ namespace Svg ...@@ -30,6 +30,7 @@ namespace Svg
public SvgAttributeAttribute Attribute; public SvgAttributeAttribute Attribute;
} }
//reflection cache
protected IEnumerable<PropertyAttributeTuple> _svgPropertyAttributes; protected IEnumerable<PropertyAttributeTuple> _svgPropertyAttributes;
protected IEnumerable<EventAttributeTuple> _svgEventAttributes; protected IEnumerable<EventAttributeTuple> _svgEventAttributes;
...@@ -68,10 +69,28 @@ namespace Svg ...@@ -68,10 +69,28 @@ namespace Svg
/// <summary> /// <summary>
/// Gets or sets the content of the element. /// Gets or sets the content of the element.
/// </summary> /// </summary>
private string _content;
public virtual string Content public virtual string Content
{ {
get; get
set; {
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> /// <summary>
...@@ -220,8 +239,15 @@ namespace Svg ...@@ -220,8 +239,15 @@ namespace Svg
[SvgAttribute("transform")] [SvgAttribute("transform")]
public SvgTransformCollection Transforms public SvgTransformCollection Transforms
{ {
get { return (this.Attributes.GetAttribute<SvgTransformCollection>("Transforms") ?? new SvgTransformCollection()); } get { return (this.Attributes.GetAttribute<SvgTransformCollection>("Transforms")); }
set { this.Attributes["Transforms"] = value; } set
{
var old = this.Transforms;
if(old != null)
old.TransformChanged -= Attributes_AttributeChanged;
value.TransformChanged += Attributes_AttributeChanged;
this.Attributes["Transforms"] = value;
}
} }
/// <summary> /// <summary>
...@@ -302,6 +328,8 @@ namespace Svg ...@@ -302,6 +328,8 @@ namespace Svg
this._elementName = string.Empty; this._elementName = string.Empty;
this._customAttributes = new SvgCustomAttributeCollection(this); this._customAttributes = new SvgCustomAttributeCollection(this);
Transforms = new SvgTransformCollection();
//subscribe to attribute events //subscribe to attribute events
Attributes.AttributeChanged += Attributes_AttributeChanged; Attributes.AttributeChanged += Attributes_AttributeChanged;
CustomAttributes.AttributeChanged += Attributes_AttributeChanged; CustomAttributes.AttributeChanged += Attributes_AttributeChanged;
......
...@@ -83,7 +83,12 @@ namespace Svg ...@@ -83,7 +83,12 @@ namespace Svg
public virtual SvgUnit X public virtual SvgUnit X
{ {
get { return this._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> /// <summary>
...@@ -94,7 +99,12 @@ namespace Svg ...@@ -94,7 +99,12 @@ namespace Svg
public virtual SvgUnit Y public virtual SvgUnit Y
{ {
get { return this._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> /// <summary>
......
...@@ -46,7 +46,6 @@ namespace Svg.Transforms ...@@ -46,7 +46,6 @@ namespace Svg.Transforms
this.scaleFactorY = y; this.scaleFactorY = y;
} }
public override object Clone() public override object Clone()
{ {
return new SvgScale(this.X, this.Y); return new SvgScale(this.X, this.Y);
......
...@@ -10,6 +10,31 @@ namespace Svg.Transforms ...@@ -10,6 +10,31 @@ namespace Svg.Transforms
[TypeConverter(typeof(SvgTransformConverter))] [TypeConverter(typeof(SvgTransformConverter))]
public class SvgTransformCollection : List<SvgTransform> 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> /// <summary>
/// Multiplies all matrices /// Multiplies all matrices
/// </summary> /// </summary>
...@@ -32,13 +57,38 @@ namespace Svg.Transforms ...@@ -32,13 +57,38 @@ namespace Svg.Transforms
return transformMatrix; return transformMatrix;
} }
public override bool Equals(object obj) 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 true;
return base.Equals(obj); 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