private Thread(SmallBasicCallback callback, String name) { this.callback = callback; this.triggerCount = 0; System.Threading.Thread t = new System.Threading.Thread(run); t.Name = name; t.Start(); }
private static void _TextInputEvent(object sender, TextCompositionEventArgs e) { Type GraphicsWindowType = typeof(GraphicsWindow); SmallBasicCallback callback = (SmallBasicCallback)GraphicsWindowType.GetField("_textInput", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).GetValue(null); if (null != callback) { callback(); } e.Handled = true; }
private static void _MouseMoveEvent(object sender, MouseEventArgs e) { Type GraphicsWindowType = typeof(GraphicsWindow); SmallBasicCallback callback = (SmallBasicCallback)GraphicsWindowType.GetField("_mouseMove", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).GetValue(null); if (null != callback) { callback(); } e.Handled = true; }
private static void _KeyDownEvent(object sender, KeyEventArgs e) { if (e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right) { Type GraphicsWindowType = typeof(GraphicsWindow); GraphicsWindowType.GetField("_lastKey", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(null, e.Key); SmallBasicCallback callback = (SmallBasicCallback)GraphicsWindowType.GetField("_keyDown", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).GetValue(null); if (null != callback) { callback(); } e.Handled = !bKeyScroll; } }
/// <summary> /// Define a named function and its local variables/parameters with default values. Before this command is executed, the Start property needs to be set to a subroutine that will then be the starting point of the function. /// The local variables are also used for parameter passing when using a Call command: For any call with n parameters, these parameters will be assigned to the first n local variables. The rest of the local variables will be set to their defined initial value. /// </summary> /// <param name="name">The name for the function (needs to be a string literal)</param> /// <param name="parameterdefinitions">A string that holds a sequence of local variable names and initial values. This looks like for example "A B:5 T:hello". When no default is specified, 0 will be used.</param> public static void Function(Primitive name, Primitive parameterdefinitions) { String n = (name == null) ? "" : name.ToString().ToUpperInvariant(); String pd = (parameterdefinitions == null) ? "" : parameterdefinitions.ToString(); if (n.Length <= 0) { TextWindow.WriteLine("Can not define function with empty name"); return; } lock (functions) { if (start == null) { TextWindow.WriteLine("Need to specify a start subroutine before defining a function"); return; } string[] parameternames = pd.Split(new Char[] { ' ', '\t' }); Primitive[] defaults = new Primitive[parameternames.Length]; for (int i = 0; i < parameternames.Length; i++) { int colonidx = parameternames[i].IndexOf(':'); if (colonidx > 0) { defaults[i] = new Primitive(parameternames[i].Substring(colonidx + 1)); parameternames[i] = parameternames[i].Substring(0, colonidx).ToUpperInvariant(); } else { defaults[i] = new Primitive("0"); parameternames[i] = parameternames[i].ToUpperInvariant(); } } functions[n] = new FunctionDefinition(start, parameternames, defaults); start = null; // do not use same start subroutine twice } }
/// <summary> /// Set a callback subroutine for a previously included event. /// </summary> /// <param name="Event">The event name.</param> /// <param name="callBack">The callback subroutine.</param> public static void Event(Primitive Event, Primitive callBack) { try { foreach (EventInfo eventInfo in _events) { if (eventInfo.Name == Event || eventInfo.ReflectedType + "." + eventInfo.Name == Event) { MethodInfo methodInfo = mainModule.GetMethod(callBack, BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); SmallBasicCallback _callBack = (SmallBasicCallback)Delegate.CreateDelegate(typeof(SmallBasicCallback), methodInfo); eventInfo.GetAddMethod().Invoke(null, new Object[] { _callBack }); return; } } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
private Thread(SmallBasicCallback callback) { this.callback = callback; this.triggerCount = 0; (new System.Threading.Thread(run)).Start(); }
public FunctionDefinition(SmallBasicCallback start, String[] parameternames, Primitive[] defaults) { this.start = start; this.parameternames = parameternames; this.defaults = defaults; }