Commit e7a0604e authored by tebjan's avatar tebjan
Browse files

unified mouse events and added modifier keys. fixes #52

parent 8fcbf5e9
...@@ -707,8 +707,8 @@ namespace Svg ...@@ -707,8 +707,8 @@ namespace Svg
newObj.MouseScroll += delegate { }; newObj.MouseScroll += delegate { };
else if (attr.Event.Name == "Click") else if (attr.Event.Name == "Click")
newObj.Click += delegate { }; newObj.Click += delegate { };
else if (attr.Event.Name == "Change") else if (attr.Event.Name == "Change") //text element
newObj.Change += delegate { }; (newObj as SvgText).Change += delegate { };
} }
} }
...@@ -768,22 +768,22 @@ namespace Svg ...@@ -768,22 +768,22 @@ namespace Svg
/// <summary> /// <summary>
/// Use this method to provide your implementation ISvgEventCaller which can register Actions /// Use this method to provide your implementation ISvgEventCaller which can register Actions
/// and call them if one of the events occurs. Make sure, that your SvgElement has a unique ID. /// and call them if one of the events occurs. Make sure, that your SvgElement has a unique ID.
/// The SvgTextElement overwrites this and regsiters the Change event tor its text content.
/// </summary> /// </summary>
/// <param name="caller"></param> /// <param name="caller"></param>
public void RegisterEvents(ISvgEventCaller caller) public virtual void RegisterEvents(ISvgEventCaller caller)
{ {
if (caller != null && !string.IsNullOrEmpty(this.ID)) if (caller != null && !string.IsNullOrEmpty(this.ID))
{ {
var rpcID = this.ID + "/"; var rpcID = this.ID + "/";
caller.RegisterAction<float, float, int, int, string>(rpcID + "onclick", OnClick); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onclick", CreateMouseEventAction(RaiseMouseClick));
caller.RegisterAction<float, float, int, int, string>(rpcID + "onmousedown", OnMouseDown); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onmousedown", CreateMouseEventAction(RaiseMouseDown));
caller.RegisterAction<float, float, int, string>(rpcID + "onmouseup", OnMouseUp); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onmouseup", CreateMouseEventAction(RaiseMouseUp));
caller.RegisterAction<float, float, string>(rpcID + "onmousemove", OnMouseMove); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onmousemove", CreateMouseEventAction(RaiseMouseMove));
caller.RegisterAction<float, string>(rpcID + "onmousescroll", OnMouseScroll); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onmouseover", CreateMouseEventAction(RaiseMouseOver));
caller.RegisterAction<string>(rpcID + "onmouseover", OnMouseOver); caller.RegisterAction<float, float, int, int, bool, bool, bool, string>(rpcID + "onmouseout", CreateMouseEventAction(RaiseMouseOut));
caller.RegisterAction<string>(rpcID + "onmouseout", OnMouseOut); caller.RegisterAction<int, string>(rpcID + "onmousescroll", OnMouseScroll);
caller.RegisterAction<string, string>(rpcID + "onchange", OnChange);
} }
} }
...@@ -791,7 +791,7 @@ namespace Svg ...@@ -791,7 +791,7 @@ namespace Svg
/// Use this method to provide your implementation ISvgEventCaller to unregister Actions /// Use this method to provide your implementation ISvgEventCaller to unregister Actions
/// </summary> /// </summary>
/// <param name="caller"></param> /// <param name="caller"></param>
public void UnregisterEvents(ISvgEventCaller caller) public virtual void UnregisterEvents(ISvgEventCaller caller)
{ {
if (caller != null && !string.IsNullOrEmpty(this.ID)) if (caller != null && !string.IsNullOrEmpty(this.ID))
{ {
...@@ -804,7 +804,6 @@ namespace Svg ...@@ -804,7 +804,6 @@ namespace Svg
caller.UnregisterAction(rpcID + "onmousescroll"); caller.UnregisterAction(rpcID + "onmousescroll");
caller.UnregisterAction(rpcID + "onmouseover"); caller.UnregisterAction(rpcID + "onmouseover");
caller.UnregisterAction(rpcID + "onmouseout"); caller.UnregisterAction(rpcID + "onmouseout");
caller.UnregisterAction(rpcID + "onchange");
} }
} }
...@@ -818,26 +817,24 @@ namespace Svg ...@@ -818,26 +817,24 @@ namespace Svg
public event EventHandler<MouseArg> MouseUp; public event EventHandler<MouseArg> MouseUp;
[SvgAttribute("onmousemove")] [SvgAttribute("onmousemove")]
public event EventHandler<PointArg> MouseMove; public event EventHandler<MouseArg> MouseMove;
[SvgAttribute("onmousescroll")] [SvgAttribute("onmousescroll")]
public event EventHandler<PointArg> MouseScroll; public event EventHandler<MouseScrollArg> MouseScroll;
[SvgAttribute("onmouseover")] [SvgAttribute("onmouseover")]
public event EventHandler<SVGArg> MouseOver; public event EventHandler<MouseArg> MouseOver;
[SvgAttribute("onmouseout")] [SvgAttribute("onmouseout")]
public event EventHandler<SVGArg> MouseOut; public event EventHandler<MouseArg> MouseOut;
[SvgAttribute("onchange")] protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)
public event EventHandler<StringArg> Change;
//click
protected void OnClick(float x, float y, int button, int clickCount, string sessionID)
{ {
RaiseMouseClick(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount, SessionID = sessionID }); return (x, y, button, clickCount, altKey, shiftKey, ctrlKey, sessionID) =>
eventRaiser(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount, AltKey = altKey, ShiftKey = shiftKey, CtrlKey = ctrlKey, SessionID = sessionID });
} }
//click
protected void RaiseMouseClick(object sender, MouseArg e) protected void RaiseMouseClick(object sender, MouseArg e)
{ {
var handler = Click; var handler = Click;
...@@ -848,11 +845,6 @@ namespace Svg ...@@ -848,11 +845,6 @@ namespace Svg
} }
//down //down
protected void OnMouseDown(float x, float y, int button, int clickCount, string sessionID)
{
RaiseMouseDown(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount, SessionID = sessionID });
}
protected void RaiseMouseDown(object sender, MouseArg e) protected void RaiseMouseDown(object sender, MouseArg e)
{ {
var handler = MouseDown; var handler = MouseDown;
...@@ -863,11 +855,6 @@ namespace Svg ...@@ -863,11 +855,6 @@ namespace Svg
} }
//up //up
protected void OnMouseUp(float x, float y, int button, string sessionID)
{
RaiseMouseUp(this, new MouseArg { x = x, y = y, Button = button, SessionID = sessionID });
}
protected void RaiseMouseUp(object sender, MouseArg e) protected void RaiseMouseUp(object sender, MouseArg e)
{ {
var handler = MouseUp; var handler = MouseUp;
...@@ -877,13 +864,7 @@ namespace Svg ...@@ -877,13 +864,7 @@ namespace Svg
} }
} }
//move protected void RaiseMouseMove(object sender, MouseArg e)
protected void OnMouseMove(float x, float y, string sessionID)
{
RaiseMouseMove(this, new PointArg { x = x, y = y, SessionID = sessionID });
}
protected void RaiseMouseMove(object sender, PointArg e)
{ {
var handler = MouseMove; var handler = MouseMove;
if (handler != null) if (handler != null)
...@@ -892,28 +873,8 @@ namespace Svg ...@@ -892,28 +873,8 @@ namespace Svg
} }
} }
//scroll
protected void OnMouseScroll(float y, string sessionID)
{
RaiseMouseScroll(this, new PointArg { x = 0, y = y, SessionID = sessionID});
}
protected void RaiseMouseScroll(object sender, PointArg e)
{
var handler = MouseScroll;
if (handler != null)
{
handler(sender, e);
}
}
//over //over
protected void OnMouseOver(string sessionID) protected void RaiseMouseOver(object sender, MouseArg args)
{
RaiseMouseOver(this, new SVGArg{ SessionID = sessionID });
}
protected void RaiseMouseOver(object sender, SVGArg args)
{ {
var handler = MouseOver; var handler = MouseOver;
if (handler != null) if (handler != null)
...@@ -923,12 +884,7 @@ namespace Svg ...@@ -923,12 +884,7 @@ namespace Svg
} }
//out //out
protected void OnMouseOut(string sessionID) protected void RaiseMouseOut(object sender, MouseArg args)
{
RaiseMouseOut(this, new SVGArg{ SessionID = sessionID });
}
protected void RaiseMouseOut(object sender, SVGArg args)
{ {
var handler = MouseOut; var handler = MouseOut;
if (handler != null) if (handler != null)
...@@ -937,18 +893,19 @@ namespace Svg ...@@ -937,18 +893,19 @@ namespace Svg
} }
} }
//change
protected void OnChange(string newString, string sessionID) //scroll
protected void OnMouseScroll(int scroll, string sessionID)
{ {
RaiseChange(this, new StringArg {s = newString, SessionID = sessionID}); RaiseMouseScroll(this, new MouseScrollArg { Scroll = scroll, SessionID = sessionID});
} }
protected void RaiseChange(object sender, StringArg s) protected void RaiseMouseScroll(object sender, MouseScrollArg e)
{ {
var handler = Change; var handler = MouseScroll;
if (handler != null) if (handler != null)
{ {
handler(sender, s); handler(sender, e);
} }
} }
...@@ -997,6 +954,9 @@ namespace Svg ...@@ -997,6 +954,9 @@ namespace Svg
void RegisterAction<T1, T2, T3>(string rpcID, Action<T1, T2, T3> action); void RegisterAction<T1, T2, T3>(string rpcID, Action<T1, T2, T3> action);
void RegisterAction<T1, T2, T3, T4>(string rpcID, Action<T1, T2, T3, T4> action); void RegisterAction<T1, T2, T3, T4>(string rpcID, Action<T1, T2, T3, T4> action);
void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action); void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action);
void RegisterAction<T1, T2, T3, T4, T5, T6>(string rpcID, Action<T1, T2, T3, T4, T5, T6> action);
void RegisterAction<T1, T2, T3, T4, T5, T6, T7>(string rpcID, Action<T1, T2, T3, T4, T5, T6, T7> action);
void RegisterAction<T1, T2, T3, T4, T5, T6, T7, T8>(string rpcID, Action<T1, T2, T3, T4, T5, T6, T7, T8> action);
void UnregisterAction(string rpcID); void UnregisterAction(string rpcID);
} }
...@@ -1013,16 +973,25 @@ namespace Svg ...@@ -1013,16 +973,25 @@ namespace Svg
/// </summary> /// </summary>
public int Button; public int Button;
/// <summary>
/// Amount of mouse clicks, e.g. 2 for double click
/// </summary>
public int ClickCount = -1; public int ClickCount = -1;
}
/// <summary> /// <summary>
/// Represents the mouse position at the moment the event occured. /// Alt modifier key pressed
/// </summary> /// </summary>
public class PointArg : SVGArg public bool AltKey;
{
public float x; /// <summary>
public float y; /// Shift modifier key pressed
/// </summary>
public bool ShiftKey;
/// <summary>
/// Control modifier key pressed
/// </summary>
public bool CtrlKey;
} }
/// <summary> /// <summary>
...@@ -1033,6 +1002,11 @@ namespace Svg ...@@ -1033,6 +1002,11 @@ namespace Svg
public string s; public string s;
} }
public class MouseScrollArg : SVGArg
{
public int Scroll;
}
internal interface ISvgElement internal interface ISvgElement
{ {
SvgElement Parent {get;} SvgElement Parent {get;}
......
...@@ -394,6 +394,42 @@ namespace Svg ...@@ -394,6 +394,42 @@ namespace Svg
} }
[SvgAttribute("onchange")]
public event EventHandler<StringArg> Change;
//change
protected void OnChange(string newString, string sessionID)
{
RaiseChange(this, new StringArg {s = newString, SessionID = sessionID});
}
protected void RaiseChange(object sender, StringArg s)
{
var handler = Change;
if (handler != null)
{
handler(sender, s);
}
}
public override void RegisterEvents(ISvgEventCaller caller)
{
//register basic events
base.RegisterEvents(caller);
//add change event for text
caller.RegisterAction<string, string>(this.ID + "/onchange", OnChange);
}
public override void UnregisterEvents(ISvgEventCaller caller)
{
//unregister base events
base.UnregisterEvents(caller);
//unregister change event
caller.UnregisterAction(this.ID + "/onchange");
}
public override SvgElement DeepCopy() public override SvgElement DeepCopy()
{ {
......
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