SvgElement.cs 41.9 KB
Newer Older
1001
        public event EventHandler<MouseArg> MouseMove;
1002

joreg's avatar
joreg committed
1003
        [SvgAttribute("onmousescroll")]
1004
        public event EventHandler<MouseScrollArg> MouseScroll;
joreg's avatar
joreg committed
1005
        
1006
        [SvgAttribute("onmouseover")]
1007
        public event EventHandler<MouseArg> MouseOver;
1008
1009

        [SvgAttribute("onmouseout")]
1010
        public event EventHandler<MouseArg> MouseOut;
1011
        
Eric Domke's avatar
Eric Domke committed
1012
#if Net4
1013
        protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)
Tebjan Halm's avatar
Tebjan Halm committed
1014
        {
1015
1016
        	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 });
1017
        }
Eric Domke's avatar
Eric Domke committed
1018
1019
#endif

1020
        //click
1021
1022
1023
1024
1025
1026
        protected void RaiseMouseClick(object sender, MouseArg e)
        {
        	var handler = Click;
        	if (handler != null)
        	{
        		handler(sender, e);
1027
1028
1029
            }
        }

1030
        //down
Tebjan Halm's avatar
Tebjan Halm committed
1031
1032
1033
        protected void RaiseMouseDown(object sender, MouseArg e)
        {
        	var handler = MouseDown;
1034
1035
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1036
                handler(sender, e);
1037
1038
1039
            }
        }

1040
1041
1042
1043
        //up
        protected void RaiseMouseUp(object sender, MouseArg e)
        {
        	var handler = MouseUp;
1044
1045
            if (handler != null)
            {
1046
                handler(sender, e);
1047
1048
            }
        }
1049
1050

        protected void RaiseMouseMove(object sender, MouseArg e)
1051
1052
        {
        	var handler = MouseMove;
1053
1054
            if (handler != null)
            {
1055
                handler(sender, e);
1056
1057
            }
        }
joreg's avatar
joreg committed
1058
        
1059
1060
        //over
        protected void RaiseMouseOver(object sender, MouseArg args)
1061
1062
        {
        	var handler = MouseOver;
1063
1064
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1065
                handler(sender, args);
Tebjan Halm's avatar
Tebjan Halm committed
1066
1067
1068
            }
        }

1069
        //out
1070
        protected void RaiseMouseOut(object sender, MouseArg args)
1071
        {
1072
        	var handler = MouseOut;
1073
1074
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1075
                handler(sender, args);
1076
1077
            }
        }
joreg's avatar
joreg committed
1078
        
1079
1080
        
        //scroll
1081
        protected void OnMouseScroll(int scroll, bool ctrlKey, bool shiftKey, bool altKey, string sessionID)
joreg's avatar
joreg committed
1082
        {
1083
        	RaiseMouseScroll(this, new MouseScrollArg { Scroll = scroll, AltKey = altKey, ShiftKey = shiftKey, CtrlKey = ctrlKey, SessionID = sessionID});
joreg's avatar
joreg committed
1084
1085
        }
        
1086
        protected void RaiseMouseScroll(object sender, MouseScrollArg e)
joreg's avatar
joreg committed
1087
        {
1088
        	var handler = MouseScroll;
joreg's avatar
joreg committed
1089
1090
            if (handler != null)
            {
1091
                handler(sender, e);
joreg's avatar
joreg committed
1092
1093
            }
        }
1094
        
Tebjan Halm's avatar
Tebjan Halm committed
1095
1096
        #endregion graphical EVENTS
    }
1097
    
Tebjan Halm's avatar
Tebjan Halm committed
1098
1099
1100
1101
1102
1103
    public class SVGArg : EventArgs
    {
    	public string SessionID;
    }
    	
    
1104
1105
1106
    /// <summary>
    /// Describes the Attribute which was set
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1107
    public class AttributeEventArgs : SVGArg
1108
1109
1110
1111
    {
    	public string Attribute;
    	public object Value;
    }
tebjan's avatar
tebjan committed
1112
    
tebjan's avatar
tebjan committed
1113
1114
1115
1116
1117
1118
1119
1120
    /// <summary>
    /// Content of this whas was set
    /// </summary>
    public class ContentEventArgs : SVGArg
    {
    	public string Content;
    }
    
tebjan's avatar
tebjan committed
1121
1122
1123
1124
1125
1126
    /// <summary>
    /// Describes the Attribute which was set
    /// </summary>
    public class ChildAddedEventArgs : SVGArg
    {
    	public SvgElement NewChild;
1127
    	public SvgElement BeforeSibling;
tebjan's avatar
tebjan committed
1128
    }
Tebjan Halm's avatar
Tebjan Halm committed
1129

Eric Domke's avatar
Eric Domke committed
1130
#if Net4
1131
1132
1133
    //deriving class registers event actions and calls the actions if the event occurs
    public interface ISvgEventCaller
    {
1134
        void RegisterAction(string rpcID, Action action);
1135
1136
1137
1138
        void RegisterAction<T1>(string rpcID, Action<T1> action);
        void RegisterAction<T1, T2>(string rpcID, Action<T1, T2> 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);
Tebjan Halm's avatar
Tebjan Halm committed
1139
        void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action);
1140
1141
1142
        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);
1143
        void UnregisterAction(string rpcID);
1144
    }
Eric Domke's avatar
Eric Domke committed
1145
#endif
1146

Tebjan Halm's avatar
Tebjan Halm committed
1147
1148
1149
    /// <summary>
    /// Represents the state of the mouse at the moment the event occured.
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1150
    public class MouseArg : SVGArg
Tebjan Halm's avatar
Tebjan Halm committed
1151
1152
1153
1154
1155
    {
        public float x;
        public float y;

        /// <summary>
1156
        /// 1 = left, 2 = middle, 3 = right
Tebjan Halm's avatar
Tebjan Halm committed
1157
        /// </summary>
1158
        public int Button;
1159
        
1160
1161
1162
        /// <summary>
        /// Amount of mouse clicks, e.g. 2 for double click
        /// </summary>
1163
        public int ClickCount = -1;
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
        
        /// <summary>
        /// Alt modifier key pressed
        /// </summary>
        public bool AltKey;
        
        /// <summary>
        /// Shift modifier key pressed
        /// </summary>
        public bool ShiftKey;
        
        /// <summary>
        /// Control modifier key pressed
        /// </summary>
        public bool CtrlKey;
1179
    }
joreg's avatar
joreg committed
1180
1181
1182
1183
    
    /// <summary>
    /// Represents a string argument
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1184
    public class StringArg : SVGArg
joreg's avatar
joreg committed
1185
1186
1187
    {
        public string s;
    }
1188
1189
1190
1191
    
    public class MouseScrollArg : SVGArg
    {
    	public int Scroll;
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
    	
    	/// <summary>
        /// Alt modifier key pressed
        /// </summary>
        public bool AltKey;
        
        /// <summary>
        /// Shift modifier key pressed
        /// </summary>
        public bool ShiftKey;
        
        /// <summary>
        /// Control modifier key pressed
        /// </summary>
        public bool CtrlKey;
1207
    }
1208

1209
1210
1211
    public interface ISvgNode
    {
        string Content { get; }
1212
1213
1214
1215
1216
1217
        
        /// <summary>
        /// Create a deep copy of this <see cref="ISvgNode"/>.
        /// </summary>
        /// <returns>A deep copy of this <see cref="ISvgNode"/></returns>
        ISvgNode DeepCopy();
1218
1219
    }

1220
1221
1222
1223
    /// <summary>This interface mostly indicates that a node is not to be drawn when rendering the SVG.</summary>
    public interface ISvgDescriptiveElement {
    }

davescriven's avatar
davescriven committed
1224
1225
    internal interface ISvgElement
    {
1226
1227
		SvgElement Parent {get;}
		SvgElementCollection Children { get; }
1228
        IList<ISvgNode> Nodes { get; }
1229

Eric Domke's avatar
Eric Domke committed
1230
        void Render(ISvgRenderer renderer);
davescriven's avatar
davescriven committed
1231
    }
Tebjan Halm's avatar
Tebjan Halm committed
1232
}