public override void Close() { lock (sync) { if (Exists && !must_destroy && !is_in_closing_event) { Debug.Print("SDL2 closing window {0}", window.Handle); Event e = new Event(); e.Type = EventType.WINDOWEVENT; e.Window.Event = WindowEventID.CLOSE; e.Window.WindowID = window_id; lock (SDL.Sync) { SDL.PushEvent(ref e); } } } }
public static int PeepEvents(ref Event e, EventAction action, EventType min, EventType max) { unsafe { fixed (Event* pe = &e) { return PeepEvents(pe, 1, action, min, max); } } }
int ProcessEvent(ref Event ev) { bool processed = false; try { Sdl2NativeWindow window = null; switch (ev.Type) { case EventType.WINDOWEVENT: if (windows.TryGetValue(ev.Window.WindowID, out window)) { ProcessWindowEvent(window, ev.Window); processed = true; } break; case EventType.TEXTINPUT: if (windows.TryGetValue(ev.Text.WindowID, out window)) { ProcessTextInputEvent(window, ev.Text); processed = true; } break; case EventType.KEYDOWN: case EventType.KEYUP: if (windows.TryGetValue(ev.Key.WindowID, out window)) { ProcessKeyEvent(window, ev); processed = true; } break; case EventType.MOUSEBUTTONDOWN: case EventType.MOUSEBUTTONUP: if (windows.TryGetValue(ev.Button.WindowID, out window)) { ProcessMouseButtonEvent(window, ev.Button); processed = true; } break; case EventType.MOUSEMOTION: if (windows.TryGetValue(ev.Motion.WindowID, out window)) { ProcessMouseMotionEvent(window, ev.Motion); processed = true; } break; case EventType.MOUSEWHEEL: if (windows.TryGetValue(ev.Wheel.WindowID, out window)) { ProcessMouseWheelEvent(window, ev.Wheel); processed = true; } break; case EventType.QUIT: Debug.WriteLine("Sdl2 application quit"); break; } } catch (Exception ex) { Debug.Print(ex.ToString()); } return processed ? 0 : 1; }
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev) { bool key_pressed = ev.Key.State == State.Pressed; Key key = TranslateKey(ev.Key.Keysym.Scancode); if (key_pressed) { window.OnKeyDown(key, ev.Key.Repeat > 0); } else { window.OnKeyUp(key); } }
public void Close() { lock (sync) { if (Exists) { Debug.Print("SDL2 destroying window {0}", window.Handle); Event e = new Event(); e.Type = EventType.WINDOWEVENT; e.Window.Event = WindowEventID.CLOSE; e.Window.WindowID = window_id; lock (SDL.Sync) { SDL.PushEvent(ref e); } } } }
static void ProcessWheelEvent(Sdl2NativeWindow window, Event ev) { //window.mouse.Wheel += ev.wheel.y; }
static void ProcessButtonEvent(Sdl2NativeWindow window, Event ev) { bool button_pressed = ev.Button.State == State.Pressed; // We need MouseUp events to be reported even if they occur // outside the window. SetWindowGrab ensures we get them. if (window.CursorVisible) { SDL.SetWindowGrab(window.window.Handle, button_pressed ? true : false); } }
public static extern int PollEvent(out Event e);
extern public static int WaitEventTimeout(out Event _event, int timeout);
extern public static int PushEvent(ref Event _event);
extern public static int WaitEvent(out Event _event);
extern public static int PollEvent(out Event _event);
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev) { bool key_pressed = ev.Key.State == State.Pressed; var key = ev.Key.Keysym; var args = new KeyboardKeyEventArgs() { Key = TranslateKey(key.Scancode), ScanCode = (uint)key.Scancode }; if (key_pressed) window.KeyDown(window, args); else window.KeyUp(window, args); //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed); }
public static int PeepEvents(Event[] e, int count, EventAction action, EventType min, EventType max) { if (e == null) throw new ArgumentNullException(); if (count <= 0 || count > e.Length) throw new ArgumentOutOfRangeException(); unsafe { fixed (Event *pe = e) { return PeepEvents(pe, count, action, min, max); } } }
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev) { bool key_pressed = ev.Key.State == State.Pressed; var key = ev.Key.Keysym; window.key_args.Key = TranslateKey(key.Scancode); window.key_args.ScanCode = (uint)key.Scancode; window.key_args.Modifiers = window.input_driver.Keyboard[0].GetModifiers(); if (key_pressed) { window.KeyDown(window, window.key_args); } else { window.KeyUp(window, window.key_args); } //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed); }
unsafe static extern int PeepEvents(Event* e, int count, EventAction action, EventType min, EventType max);
static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev) { float scale = window.ClientSize.Width / (float)window.Size.Width; //window.mouse.Position = new Point( // (int)(ev.motion.x * scale), (int)(ev.motion.y * scale)); }
public static extern int PushEvent(ref Event @event);
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev) { bool key_pressed = ev.Key.State == State.Pressed; var key = ev.Key.Keysym; //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed); }