internal static bool DoOnKeyRepeat(Keys k, bool first = false) { if (OnKeyRepeat != null) { Delegate[] dels = OnKeyRepeat.GetInvocationList(); //ctrl+shift is considered a universal override. //it will reverse the order of event handling to allow global-level UI to handle keys/mouse before others. if (KeyboardHandler.ControlPressed && KeyboardHandler.ShiftPressed) { List <Delegate> temp = new List <Delegate>(dels); temp.Reverse(); dels = temp.ToArray(); } if (dels.Length == 0) { return(false); } for (int i = dels.Length - 1; i >= 0; i--) { RepeatKeyEventHandler d = dels[i] as RepeatKeyEventHandler; if (d == null) // cast error. should never happen. { continue; } if ((bool)d.DynamicInvoke(null, k, first)) { return(true); } } } return(false); }
internal void TriggerOnKeyRepeat(Keys key, float timeDown) { OnKeyRepeat?.Invoke(key, timeDown); }
public virtual void KeyRepeat(Key key) { OnKeyRepeat?.Invoke(key); }
static void InitEvents() { Log.Info("Registering window events"); window.RenderFrame += (sender, e) => { timer.Tick(); RenderState.SetupViewport(); OnRender?.Invoke(); State?.Render(); window.SwapBuffers(); FinalizeGLResources(); }; window.UpdateFrame += (sender, e) => { OnUpdate?.Invoke(e.Time); var state = State; if (state != null) { state.Update(e.Time); if (state.Closed) { State = null; } } if (State == null) { Kill(); } }; window.KeyDown += (sender, e) => { var key = (Key)e.Key; if (e.IsRepeat) { OnKeyRepeat?.Invoke(key); State?.KeyRepeat(key); } else { OnKeyDown?.Invoke(key); State?.KeyDown(key); } if (e.Key == OpenTK.Input.Key.F4 && e.Modifiers.HasFlag(OpenTK.Input.KeyModifiers.Alt)) { window.Close(); } }; window.KeyUp += (sender, e) => { OnKeyUp?.Invoke((Key)e.Key); State?.KeyUp((Key)e.Key); }; window.KeyPress += (sender, e) => { OnCharInput?.Invoke(e.KeyChar); State?.CharInput(e.KeyChar); }; window.MouseDown += (sender, e) => { OnMouseDown?.Invoke((MouseButton)e.Button, Mouse.Position); State?.MouseDown((MouseButton)e.Button, Mouse.Position); }; window.MouseUp += (sender, e) => { OnMouseUp?.Invoke((MouseButton)e.Button, Mouse.Position); State?.MouseUp((MouseButton)e.Button, Mouse.Position); }; window.MouseMove += (sender, e) => { OnMouseMove?.Invoke(Mouse.Position); State?.MouseMove(Mouse.Position); }; window.MouseWheel += (sender, e) => { OnMouseWheel?.Invoke(e.DeltaPrecise); State?.MouseWheel(e.DeltaPrecise); }; window.Resize += (sender, e) => { OpenTK.Graphics.OpenGL.GL.Viewport(0, 0, Width, Height); }; }
protected void Invoke_OnKeyRepeat(object sender, KeyArgs args) { OnKeyRepeat?.Invoke(sender, args); }