/// <summary> /// Send event /// </summary> /// <param name="el_name">name of control</param> /// <param name="id">Event type</param> /// <param name="lparam">long value</param> /// <param name="dparam">double value</param> /// <param name="sparam">string value</param> public static void SendEvent(string el_name, int id, long lparam, double dparam, string sparam) { try { foreach (var kvp in m_controllers) { GuiController controller = kvp.Value; if (controller.IsDiposed) { m_controllers.Remove(kvp.Key); return; } if (!controller.m_controls.ContainsKey(el_name)) { continue; } Control control = null; if (!controller.m_controls.TryGetValue(el_name, out control)) { return; } GuiEventType event_type = (GuiEventType)id; switch (event_type) { case GuiEventType.TextChange: control.Invoke((MethodInvoker) delegate { control.Text = sparam; }); break; } } } catch (Exception ex) { SendExceptionEvent(ex); } }
public GuiEvent(GuiDisplayObject sender,GuiEventType type, SortedList parameter) { Sender = sender; Type = type; _params = parameter; }
public void Subscribe(GuiEvent.EventHandler callback,GuiEventType type, SortedList parameter) { GuiKeyEvent e = new GuiKeyEvent(null ,type, parameter); e.Handler += callback; // if (_events == null) _events = new List<GuiKeyEvent>(); _events.Add(e); }
public void Invoke(GuiEventType type) { //invalid type if(type != Type) return; //fire Handler(this); }
public new void Invoke(GuiEventType type) { //invalid button if(_params.ContainsKey("button")){ if(!checkKey(Type,"GetButton",new object[] {_params["button"]})) return; } //invalid key if(_params.ContainsKey("key")){ if(!checkKey(Type,"GetKey",new object[] {_params["key"]})) return; } base.Invoke(type); }
private bool checkKey(GuiEventType type,string methodName, object[] args) { //convert the args Type[] types = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { types[i] = args[i].GetType(); } //Find the right method MethodInfo method = null; if(type == GuiEventType.KEY) method = typeof (Input).GetMethod(methodName, types); else if(type == GuiEventType.KEYDOWN) method = typeof (Input).GetMethod(methodName + "Down", types); //invoke method if(method != null) return (bool)method.Invoke(null,args); //worng parameters return false; }
/// <summary> /// Send event /// </summary> /// <param name="el_name">name of control</param> /// <param name="id">Event type</param> /// <param name="lparam">long value</param> /// <param name="dparam">double value</param> /// <param name="sparam">string value</param> public static void SendEventRef(string el_name, ref int id, ref long lparam, ref double dparam, string sparam) { try { foreach (var kvp in m_controllers) { GuiController controller = kvp.Value; if (controller.IsDiposed) { m_controllers.Remove(kvp.Key); return; } Control control = null; if (!controller.m_controls.TryGetValue(el_name, out control)) { SendExceptionEvent(new Exception("SendEvent: element with name '" + el_name + "' not find")); continue; } GuiEventType event_type = (GuiEventType)id; switch (event_type) { case GuiEventType.TextChange: control.Invoke((MethodInvoker) delegate { control.Text = sparam; }); break; case GuiEventType.CheckBoxChange: { CheckBox checkBox = (CheckBox)control; CheckState state = (CheckState)lparam; control.Invoke((MethodInvoker) delegate { checkBox.CheckState = state; }); break; } case GuiEventType.RadioButtonChange: RadioButton radio_btn = (RadioButton)control; bool check = lparam == 0 ? false : true; control.Invoke((MethodInvoker) delegate { radio_btn.Checked = check; }); break; case GuiEventType.ComboBoxChange: ComboBox combo_box = (ComboBox)control; if (combo_box.SelectedIndex != (int)lparam) { combo_box.SelectedIndex = (int)lparam; } break; case GuiEventType.NumericChange: NumericUpDown numeric = (NumericUpDown)control; if (numeric.Value != (decimal)dparam) { numeric.Value = (decimal)dparam; } break; case GuiEventType.NumericFormatChange: if (control.GetType() != typeof(NumericUpDown)) { SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericStepsChange' event")); break; } NumericUpDown num = (NumericUpDown)control; num.DecimalPlaces = (int)lparam; num.Increment = (decimal)dparam; break; case GuiEventType.NumericMaxChange: if (control.GetType() != typeof(NumericUpDown)) { SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericMaxChange' event")); break; } NumericUpDown nummax = (NumericUpDown)control; nummax.Maximum = (decimal)dparam; break; case GuiEventType.NumericMinChange: if (control.GetType() != typeof(NumericUpDown)) { SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericMinChange' event")); break; } NumericUpDown nummin = (NumericUpDown)control; nummin.Minimum = (decimal)dparam; break; case GuiEventType.ElementHide: if (lparam != 0) { control.Hide(); } else { control.Show(); } break; case GuiEventType.DateTimePickerChange: DateTimePicker picker = (DateTimePicker)control; picker.Value = MtConverter.ToSharpDateTime(lparam); break; case GuiEventType.ElementEnable: { bool enable = lparam == 0 ? false : true; if (enable != control.Enabled) { control.Invoke((MethodInvoker) delegate { control.Enabled = enable; }); controller.OnEnableChange(control, new EventArgs()); } break; } case GuiEventType.MessageBox: { if (lparam == 1) { control.Enabled = false; } string[] nodes = sparam.Split('|'); MessageBoxButtons buttons; if (dparam == 0.0) { buttons = MessageBoxButtons.OK; } else { buttons = (MessageBoxButtons)(int)dparam; } if (nodes.Length == 1) { MessageBox.Show(sparam, sparam, buttons); } else if (nodes.Length == 2) { var icon = ParseIcon(nodes[0]); if (icon == MessageBoxIcon.None) { MessageBox.Show(nodes[0], nodes[1], buttons); } else { MessageBox.Show(nodes[1], nodes[1], buttons, icon); } } else { var icon = ParseIcon(nodes[0]); MessageBox.Show(nodes[1], nodes[2], buttons, icon); } control.Enabled = true; break; } case GuiEventType.AddItem: if (control.GetType() != typeof(ComboBox)) { SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'Add Item' event")); break; } ComboBox box = (ComboBox)control; box.Items.Add(sparam); break; } } } catch (Exception ex) { SendExceptionEvent(ex); } }
public GuiEvent(GuiEventType type, Vector2 mousePosition) { this.type = type; this.mousePosition = mousePosition; }
public void Subscribe(GuiEvent.EventHandler callback,GuiEventType type) { Subscribe(callback,type,null); }
public GuiEvent(GuiEventType type) => Type = type;
public GuiKeyEvent(GuiDisplayObject sender, GuiEventType type, SortedList paremater) : base(sender, type, paremater) { }
protected void InvokeEvent(GuiEventType type) { if (_events == null) return; //early out foreach (GuiEvent guiEvent in _events) { guiEvent.Invoke(type); } }