SvgElement.cs 41.4 KB
Newer Older
1001
        protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)
Tebjan Halm's avatar
Tebjan Halm committed
1002
        {
1003
1004
        	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 });
1005
        }
Eric Domke's avatar
Eric Domke committed
1006
1007
#endif

1008
        //click
1009
1010
1011
1012
1013
1014
        protected void RaiseMouseClick(object sender, MouseArg e)
        {
        	var handler = Click;
        	if (handler != null)
        	{
        		handler(sender, e);
1015
1016
1017
            }
        }

1018
        //down
Tebjan Halm's avatar
Tebjan Halm committed
1019
1020
1021
        protected void RaiseMouseDown(object sender, MouseArg e)
        {
        	var handler = MouseDown;
1022
1023
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1024
                handler(sender, e);
1025
1026
1027
            }
        }

1028
1029
1030
1031
        //up
        protected void RaiseMouseUp(object sender, MouseArg e)
        {
        	var handler = MouseUp;
1032
1033
            if (handler != null)
            {
1034
                handler(sender, e);
1035
1036
            }
        }
1037
1038

        protected void RaiseMouseMove(object sender, MouseArg e)
1039
1040
        {
        	var handler = MouseMove;
1041
1042
            if (handler != null)
            {
1043
                handler(sender, e);
1044
1045
            }
        }
joreg's avatar
joreg committed
1046
        
1047
1048
        //over
        protected void RaiseMouseOver(object sender, MouseArg args)
1049
1050
        {
        	var handler = MouseOver;
1051
1052
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1053
                handler(sender, args);
Tebjan Halm's avatar
Tebjan Halm committed
1054
1055
1056
            }
        }

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

Eric Domke's avatar
Eric Domke committed
1118
#if Net4
1119
1120
1121
    //deriving class registers event actions and calls the actions if the event occurs
    public interface ISvgEventCaller
    {
1122
        void RegisterAction(string rpcID, Action action);
1123
1124
1125
1126
        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
1127
        void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action);
1128
1129
1130
        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);
1131
        void UnregisterAction(string rpcID);
1132
    }
Eric Domke's avatar
Eric Domke committed
1133
#endif
1134

Tebjan Halm's avatar
Tebjan Halm committed
1135
1136
1137
    /// <summary>
    /// Represents the state of the mouse at the moment the event occured.
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1138
    public class MouseArg : SVGArg
Tebjan Halm's avatar
Tebjan Halm committed
1139
1140
1141
1142
1143
    {
        public float x;
        public float y;

        /// <summary>
1144
        /// 1 = left, 2 = middle, 3 = right
Tebjan Halm's avatar
Tebjan Halm committed
1145
        /// </summary>
1146
        public int Button;
1147
        
1148
1149
1150
        /// <summary>
        /// Amount of mouse clicks, e.g. 2 for double click
        /// </summary>
1151
        public int ClickCount = -1;
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
        
        /// <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;
1167
    }
joreg's avatar
joreg committed
1168
1169
1170
1171
    
    /// <summary>
    /// Represents a string argument
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1172
    public class StringArg : SVGArg
joreg's avatar
joreg committed
1173
1174
1175
    {
        public string s;
    }
1176
1177
1178
1179
    
    public class MouseScrollArg : SVGArg
    {
    	public int Scroll;
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
    	
    	/// <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;
1195
    }
1196

1197
1198
1199
1200
1201
    public interface ISvgNode
    {
        string Content { get; }
    }

1202
1203
1204
1205
    /// <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
1206
1207
    internal interface ISvgElement
    {
1208
1209
		SvgElement Parent {get;}
		SvgElementCollection Children { get; }
1210
        IList<ISvgNode> Nodes { get; }
1211

Eric Domke's avatar
Eric Domke committed
1212
        void Render(ISvgRenderer renderer);
davescriven's avatar
davescriven committed
1213
    }
Tebjan Halm's avatar
Tebjan Halm committed
1214
}