Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
e7a0604e
Commit
e7a0604e
authored
Mar 13, 2014
by
tebjan
Browse files
unified mouse events and added modifier keys. fixes #52
parent
8fcbf5e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Source/SvgElement.cs
View file @
e7a0604e
...
@@ -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
<
Point
Arg
>
MouseMove
;
public
event
EventHandler
<
Mouse
Arg
>
MouseMove
;
[
SvgAttribute
(
"onmousescroll"
)]
[
SvgAttribute
(
"onmousescroll"
)]
public
event
EventHandler
<
Point
Arg
>
MouseScroll
;
public
event
EventHandler
<
MouseScroll
Arg
>
MouseScroll
;
[
SvgAttribute
(
"onmouseover"
)]
[
SvgAttribute
(
"onmouseover"
)]
public
event
EventHandler
<
SVG
Arg
>
MouseOver
;
public
event
EventHandler
<
Mouse
Arg
>
MouseOver
;
[
SvgAttribute
(
"onmouseout"
)]
[
SvgAttribute
(
"onmouseout"
)]
public
event
EventHandler
<
SVG
Arg
>
MouseOut
;
public
event
EventHandler
<
Mouse
Arg
>
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
)
{
{
Raise
Change
(
this
,
new
StringArg
{
s
=
newString
,
SessionID
=
sessionID
});
Raise
MouseScroll
(
this
,
new
MouseScrollArg
{
Scroll
=
scroll
,
SessionID
=
sessionID
});
}
}
protected
void
Raise
Change
(
object
sender
,
String
Arg
s
)
protected
void
Raise
MouseScroll
(
object
sender
,
MouseScroll
Arg
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
;}
...
...
Source/Text/SvgText.cs
View file @
e7a0604e
...
@@ -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
()
{
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment