From 88f9340ee035c076ca2386e94dff8b92fc0100a8 Mon Sep 17 00:00:00 2001 From: Tebjan Halm Date: Thu, 25 Jul 2013 22:14:55 +0200 Subject: [PATCH] added missing raise event methods --- Source/SvgElement.cs | 89 ++++++++++++++++++++++++++++------------- Source/SvgExtentions.cs | 5 +++ 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/Source/SvgElement.cs b/Source/SvgElement.cs index 3746757..b4c8fb1 100644 --- a/Source/SvgElement.cs +++ b/Source/SvgElement.cs @@ -417,14 +417,16 @@ namespace Svg //events if(AutoPublishEvents) - foreach (var attr in _svgEventAttributes) { - var evt = attr.Event.GetValue(this); - - if (evt != null && !string.IsNullOrWhiteSpace(this.ID)) - { - writer.WriteAttributeString(attr.Attribute.Name, this.ID + "/" + attr.Attribute.Name); - } + foreach (var attr in _svgEventAttributes) + { + var evt = attr.Event.GetValue(this); + + if (evt != null && !string.IsNullOrWhiteSpace(this.ID)) + { + writer.WriteAttributeString(attr.Attribute.Name, this.ID + "/" + attr.Attribute.Name); + } + } } //add the custom attributes @@ -655,9 +657,9 @@ namespace Svg caller.RegisterAction(rpcID + "onclick", OnClick); caller.RegisterAction(rpcID + "onmousedown", OnMouseDown); caller.RegisterAction(rpcID + "onmouseup", OnMouseUp); + caller.RegisterAction(rpcID + "onmousemove", OnMouseMove); caller.RegisterAction(rpcID + "onmouseover", OnMouseOver); caller.RegisterAction(rpcID + "onmouseout", OnMouseOut); - caller.RegisterAction(rpcID + "onmousemove", OnMouseMove); } } @@ -669,28 +671,35 @@ namespace Svg [SvgAttribute("onmouseup")] public event EventHandler MouseUp; + + [SvgAttribute("onmousemove")] + public event EventHandler MouseMove; [SvgAttribute("onmouseover")] public event EventHandler MouseOver; - [SvgAttribute("onmousemove")] - public event EventHandler MouseMove; - [SvgAttribute("onmouseout")] public event EventHandler MouseOut; + //click protected void OnClick(float x, float y, int button, int clickCount) { - var handler = Click; - if(handler != null) - { - handler(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount}); + RaiseMouseClick(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount}); + } + + protected void RaiseMouseClick(object sender, MouseArg e) + { + var handler = Click; + if (handler != null) + { + handler(sender, e); } } + //down protected void OnMouseDown(float x, float y, int button, int clickCount) { - RaiseMouseDown(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount}); + RaiseMouseDown(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount}); } protected void RaiseMouseDown(object sender, MouseArg e) @@ -702,39 +711,63 @@ namespace Svg } } + //up protected void OnMouseUp(float x, float y, int button) { - var handler = MouseUp; + RaiseMouseUp(this, new MouseArg { x = x, y = y, Button = button}); + } + + protected void RaiseMouseUp(object sender, MouseArg e) + { + var handler = MouseUp; if (handler != null) { - handler(this, new MouseArg { x = x, y = y, Button = button}); + handler(sender, e); } } - - protected void OnMouseOver() + + //move + protected void OnMouseMove(float x, float y) { - var handler = MouseOver; + RaiseMouseMove(this, new PointArg { x = x, y = y}); + } + + protected void RaiseMouseMove(object sender, PointArg e) + { + var handler = MouseMove; if (handler != null) { - handler(this, new EventArgs()); + handler(sender, e); } } - protected void OnMouseOut() + //over + protected void OnMouseOver() { - var handler = MouseOut; + RaiseMouseOver(this); + } + + protected void RaiseMouseOver(object sender) + { + var handler = MouseOver; if (handler != null) { - handler(this, new EventArgs()); + handler(sender, new EventArgs()); } } - protected void OnMouseMove(float x, float y) + //out + protected void OnMouseOut() + { + RaiseMouseOut(this); + } + + protected void RaiseMouseOut(object sender) { - var handler = MouseMove; + var handler = MouseOut; if (handler != null) { - handler(this, new PointArg { x = x, y = y}); + handler(sender, new EventArgs()); } } diff --git a/Source/SvgExtentions.cs b/Source/SvgExtentions.cs index c9daf7f..589a33c 100644 --- a/Source/SvgExtentions.cs +++ b/Source/SvgExtentions.cs @@ -47,5 +47,10 @@ namespace Svg } } + + public static bool HasNonEmptyCustomAttribute(this SvgElement element, string name) + { + return element.CustomAttributes.ContainsKey(name) && !string.IsNullOrEmpty(element.CustomAttributes[name]); + } } } -- GitLab