private unsafe int HookFunc(IntPtr userdata, IntPtr ev) { SDL_Event *e = (SDL_Event *)ev; switch (e->type) { case SDL_EventType.SDL_WINDOWEVENT: switch (e->window.windowEvent) { case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: Mouse.MouseInWindow = true; break; case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: Mouse.MouseInWindow = false; break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: // SDL_CaptureMouse(SDL_bool.SDL_TRUE); //Log.Message(LogTypes.Debug, "FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: //Log.Message(LogTypes.Debug, "NO FOCUS"); //SDL_CaptureMouse(SDL_bool.SDL_FALSE); break; case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS: //Log.Message(LogTypes.Debug, "TAKE FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST: break; } break; case SDL_EventType.SDL_SYSWMEVENT: break; case SDL_EventType.SDL_KEYDOWN: KeyDown?.Raise(e->key); break; case SDL_EventType.SDL_KEYUP: KeyUp.Raise(e->key); break; case SDL_EventType.SDL_TEXTINPUT: string s = StringHelper.ReadUTF8(e->text.text); if (!string.IsNullOrEmpty(s)) { TextInput.Raise(s); } break; case SDL_EventType.SDL_MOUSEMOTION: Mouse.Update(); if (Mouse.IsDragging) { MouseDragging.Raise(); } if (Mouse.IsDragging && !_dragStarted) { DragBegin.Raise(); _dragStarted = true; } break; case SDL_EventType.SDL_MOUSEWHEEL: Mouse.Update(); bool isup = e->wheel.y > 0; MouseWheel.Raise(isup); break; case SDL_EventType.SDL_MOUSEBUTTONUP: case SDL_EventType.SDL_MOUSEBUTTONDOWN: Mouse.Update(); bool isDown = e->type == SDL_EventType.SDL_MOUSEBUTTONDOWN; if (_dragStarted && !isDown) { DragEnd.Raise(); _dragStarted = false; } SDL_MouseButtonEvent mouse = e->button; switch ((uint)mouse.button) { case SDL_BUTTON_LEFT: Mouse.LButtonPressed = isDown; if (isDown) { Mouse.Begin(); Mouse.LDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastLeftButtonClickTime = 0; if (LeftMouseDoubleClick != null && !LeftMouseDoubleClick.Invoke()) { LeftMouseButtonDown.Raise(); } else { Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF; } break; } LeftMouseButtonDown.Raise(); Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF) { LeftMouseButtonUp.Raise(); } Mouse.End(); } break; case SDL_BUTTON_MIDDLE: Mouse.MButtonPressed = isDown; if (isDown) { Mouse.Begin(); Mouse.MDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastMidButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { if (MidMouseDoubleClick != null && !MidMouseDoubleClick.Invoke()) { MidMouseButtonDown.Raise(); } Mouse.LastMidButtonClickTime = 0; break; } MidMouseButtonDown.Raise(); Mouse.LastMidButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { MidMouseButtonUp.Raise(); Mouse.End(); } break; case SDL_BUTTON_RIGHT: Mouse.RButtonPressed = isDown; if (isDown) { Mouse.Begin(); Mouse.RDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastRightButtonClickTime = 0; if (RightMouseDoubleClick != null && !RightMouseDoubleClick.Invoke()) { RightMouseButtonDown.Raise(); } else { Mouse.LastRightButtonClickTime = 0xFFFF_FFFF; } break; } RightMouseButtonDown.Raise(); Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF) { RightMouseButtonUp.Raise(); } Mouse.End(); } break; case SDL_BUTTON_X1: break; case SDL_BUTTON_X2: break; } break; } //switch (e->type) //{ // // KEYBOARD // case SDL_EventType.SDL_KEYDOWN: // OnKeyDown(new InputKeyboardEvent(KeyboardEvent.Down, e->key.keysym.sym, 0, e->key.keysym.mod)); // break; // case SDL_EventType.SDL_KEYUP: // OnKeyUp(new InputKeyboardEvent(KeyboardEvent.Up, e->key.keysym.sym, 0, e->key.keysym.mod)); // break; // case SDL_EventType.SDL_TEXTINPUT: // string s = StringHelper.ReadUTF8(e->text.text); // if (!string.IsNullOrEmpty(s)) // OnTextInput(new InputKeyboardEvent(KeyboardEvent.TextInput, SDL_Keycode.SDLK_UNKNOWN, 0, SDL_Keymod.KMOD_NONE) {KeyChar = s}); // break; // // MOUSE // case SDL_EventType.SDL_MOUSEBUTTONDOWN: // MouseDown.Raise(); // OnMouseDown(new InputMouseEvent(MouseEvent.Down, CovertMouseButton(e->button.button), e->button.clicks, e->button.x, e->button.y, 0, SDL_Keymod.KMOD_NONE)); // break; // case SDL_EventType.SDL_MOUSEBUTTONUP: // MouseUp.Raise(); // OnMouseUp(new InputMouseEvent(MouseEvent.Up, CovertMouseButton(e->button.button), e->button.clicks, e->button.x, e->button.y, 0, SDL_Keymod.KMOD_NONE)); // switch (e->button.clicks) // { // case 1: // MouseClick.Raise(); // break; // case 2: // MouseDoubleClick.Raise(); // break; // } // break; // case SDL_EventType.SDL_MOUSEMOTION: // MouseMove.Raise(); // OnMouseMove(new InputMouseEvent(MouseEvent.Move, CovertMouseButton(e->button.button), 0, e->motion.x, e->motion.y, 0, SDL_Keymod.KMOD_NONE)); // break; // case SDL_EventType.SDL_MOUSEWHEEL: // OnMouseWheel(new InputMouseEvent(MouseEvent.WheelScroll, MouseButton.Middle, 0, e->wheel.x, e->wheel.y, 0, SDL_Keymod.KMOD_NONE)); // break; //} return(1); }
private unsafe int HookFunc(IntPtr userdata, IntPtr ev) { SDL_Event *e = (SDL_Event *)ev; switch (e->type) { case SDL_EventType.SDL_WINDOWEVENT: switch (e->window.windowEvent) { case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: Mouse.MouseInWindow = true; break; case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: Mouse.MouseInWindow = false; break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: Plugin.OnFocusGained(); // SDL_CaptureMouse(SDL_bool.SDL_TRUE); //Log.Message(LogTypes.Debug, "FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: Plugin.OnFocusLost(); //Log.Message(LogTypes.Debug, "NO FOCUS"); //SDL_CaptureMouse(SDL_bool.SDL_FALSE); break; case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS: //Log.Message(LogTypes.Debug, "TAKE FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST: break; } break; case SDL_EventType.SDL_SYSWMEVENT: break; case SDL_EventType.SDL_KEYDOWN: if (Plugin.ProcessHotkeys((int)e->key.keysym.sym, (int)e->key.keysym.mod, true)) { Keyboard.IgnoreNextTextInput = false; KeyDown?.Raise(e->key); } else { Keyboard.IgnoreNextTextInput = true; } break; case SDL_EventType.SDL_KEYUP: //if (Plugin.ProcessHotkeys((int)e->key.keysym.sym, (int)e->key.keysym.mod, false)) KeyUp.Raise(e->key); break; case SDL_EventType.SDL_TEXTINPUT: if (Keyboard.IgnoreNextTextInput) { break; } string s = StringHelper.ReadUTF8(e->text.text); if (!string.IsNullOrEmpty(s)) { TextInput.Raise(s); } break; case SDL_EventType.SDL_MOUSEMOTION: Mouse.Update(); MouseMoving.Raise(); if (Mouse.IsDragging) { MouseDragging.Raise(); } if (Mouse.IsDragging && !_dragStarted) { DragBegin.Raise(); _dragStarted = true; } break; case SDL_EventType.SDL_MOUSEWHEEL: Mouse.Update(); bool isup = e->wheel.y > 0; Plugin.ProcessMouse(0, e->wheel.y); MouseWheel.Raise(isup); break; case SDL_EventType.SDL_MOUSEBUTTONUP: case SDL_EventType.SDL_MOUSEBUTTONDOWN: Mouse.Update(); bool isDown = e->type == SDL_EventType.SDL_MOUSEBUTTONDOWN; if (_dragStarted && !isDown) { DragEnd.Raise(); _dragStarted = false; } SDL_MouseButtonEvent mouse = e->button; switch ((uint)mouse.button) { case SDL_BUTTON_LEFT: if (isDown) { Mouse.Begin(); Mouse.LButtonPressed = true; Mouse.LDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastLeftButtonClickTime = 0; MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Left); LeftMouseDoubleClick.Raise(arg); if (!arg.Result) { LeftMouseButtonDown.Raise(); } else { Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF; } break; } LeftMouseButtonDown.Raise(); Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF) { LeftMouseButtonUp.Raise(); } Mouse.LButtonPressed = false; Mouse.End(); } break; case SDL_BUTTON_MIDDLE: if (isDown) { Mouse.Begin(); Mouse.MButtonPressed = true; Mouse.MDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastMidButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Middle); MidMouseDoubleClick.Raise(arg); if (!arg.Result) { MidMouseButtonDown.Raise(); } Mouse.LastMidButtonClickTime = 0; break; } Plugin.ProcessMouse(e->button.button, 0); MidMouseButtonDown.Raise(); Mouse.LastMidButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { MidMouseButtonUp.Raise(); Mouse.MButtonPressed = false; Mouse.End(); } break; case SDL_BUTTON_RIGHT: if (isDown) { Mouse.Begin(); Mouse.RButtonPressed = true; Mouse.RDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastRightButtonClickTime = 0; MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Middle); RightMouseDoubleClick.Raise(arg); if (!arg.Result) { RightMouseButtonDown.Raise(); } else { Mouse.LastRightButtonClickTime = 0xFFFF_FFFF; } break; } RightMouseButtonDown.Raise(); Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF) { RightMouseButtonUp.Raise(); } Mouse.RButtonPressed = false; Mouse.End(); } break; case SDL_BUTTON_X1: if (isDown) { Plugin.ProcessMouse(e->button.button, 0); } break; case SDL_BUTTON_X2: if (isDown) { Plugin.ProcessMouse(e->button.button, 0); } break; } break; } return(1); }
/// <summary> /// Handling aller Eingaben, Mausbewegungen und Updaten aller Screens und Controls. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { if (Game.IsActive) { #region Mouse Interaction if (MouseEnabled) { MouseState mouse; Point mousePosition; if (MouseMode == MouseMode.Captured) { mouse = Mouse.GetState(); mousePosition = new Point( mouse.X - (lastMousePosition.X), mouse.Y - (lastMousePosition.Y)); } else { mouse = Mouse.GetCursorState(); mousePosition = Game.Window.PointToClient(mouse.Location); } // Mausposition anhand des Mouse Modes ermitteln MouseEventArgs mouseEventArgs = MouseEventArgsPool.Instance.Take(); mouseEventArgs.MouseMode = MouseMode; mouseEventArgs.GlobalPosition = mousePosition; mouseEventArgs.LocalPosition = mousePosition; // Mouse Move if (mousePosition != lastMousePosition) { mouseEventArgs.Handled = false; root.InternalMouseMove(mouseEventArgs); if (!mouseEventArgs.Handled) { MouseMove?.Invoke(mouseEventArgs); } // Start Drag Handling if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs == null) { DraggingArgs = DragEventArgsPool.Instance.Take(); DraggingArgs.GlobalPosition = mousePosition; DraggingArgs.LocalPosition = mousePosition; draggingId = null; root.InternalStartDrag(DraggingArgs); if (!DraggingArgs.Handled) { StartDrag?.Invoke(DraggingArgs); } } // Drop move if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs != null && draggingId == null && DraggingArgs.Handled) { //TODO: perhaps pool single object? DragEventArgs args = DragEventArgsPool.Instance.Take(); args.GlobalPosition = mousePosition; args.LocalPosition = mousePosition; args.Content = DraggingArgs.Content; args.Icon = DraggingArgs.Icon; args.Sender = DraggingArgs.Sender; root.InternalDropMove(args); if (!args.Handled) { DropMove?.Invoke(args); } } } // Linke Maustaste if (mouse.LeftButton == ButtonState.Pressed) { if (!lastLeftMouseButtonPressed) { mouseEventArgs.Handled = false; // Linke Maustaste wurde neu gedrückt root.InternalLeftMouseDown(mouseEventArgs); if (!mouseEventArgs.Handled) { LeftMouseDown?.Invoke(mouseEventArgs); } } lastLeftMouseButtonPressed = true; } else { if (lastLeftMouseButtonPressed) { // Handle Drop if (DraggingArgs != null && DraggingArgs.Handled) { DragEventArgs args = DragEventArgsPool.Instance.Take(); args.GlobalPosition = mousePosition; args.LocalPosition = mousePosition; args.Content = DraggingArgs.Content; args.Icon = DraggingArgs.Icon; args.Sender = DraggingArgs.Sender; root.InternalEndDrop(args); if (!args.Handled) { EndDrop?.Invoke(args); } } // Discard Dragging Infos DragEventArgsPool.Instance.Release(DraggingArgs); DraggingArgs = null; draggingId = null; // Linke Maustaste wurde losgelassen mouseEventArgs.Handled = false; root.InternalLeftMouseClick(mouseEventArgs); if (!mouseEventArgs.Handled) { LeftMouseClick?.Invoke(mouseEventArgs); } if (lastLeftClick.HasValue && gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click mouseEventArgs.Handled = false; root.InternalLeftMouseDoubleClick(mouseEventArgs); if (!mouseEventArgs.Handled) { LeftMouseDoubleClick?.Invoke(mouseEventArgs); } lastLeftClick = null; } else { lastLeftClick = gameTime.TotalGameTime; } // Mouse Up mouseEventArgs.Handled = false; root.InternalLeftMouseUp(mouseEventArgs); if (!mouseEventArgs.Handled) { LeftMouseUp?.Invoke(mouseEventArgs); } } lastLeftMouseButtonPressed = false; } // Rechte Maustaste if (mouse.RightButton == ButtonState.Pressed) { if (!lastRightMouseButtonPressed) { // Rechte Maustaste neu gedrückt mouseEventArgs.Handled = false; root.InternalRightMouseDown(mouseEventArgs); if (!mouseEventArgs.Handled) { RightMouseDown?.Invoke(mouseEventArgs); } } lastRightMouseButtonPressed = true; } else { if (lastRightMouseButtonPressed) { // Rechte Maustaste losgelassen mouseEventArgs.Handled = false; root.InternalRightMouseClick(mouseEventArgs); if (!mouseEventArgs.Handled) { RightMouseClick?.Invoke(mouseEventArgs); } if (lastRightClick.HasValue && gameTime.TotalGameTime - lastRightClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click mouseEventArgs.Handled = false; root.InternalRightMouseDoubleClick(mouseEventArgs); if (!mouseEventArgs.Handled) { RightMouseDoubleClick?.Invoke(mouseEventArgs); } lastRightClick = null; } else { lastRightClick = gameTime.TotalGameTime; } mouseEventArgs.Handled = false; root.InternalRightMouseUp(mouseEventArgs); if (!mouseEventArgs.Handled) { RightMouseUp?.Invoke(mouseEventArgs); } } lastRightMouseButtonPressed = false; } // Mousewheel if (lastMouseWheelValue != mouse.ScrollWheelValue) { int diff = (mouse.ScrollWheelValue - lastMouseWheelValue); MouseScrollEventArgs scrollArgs = new MouseScrollEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition, Steps = diff }; root.InternalMouseScroll(scrollArgs); if (!scrollArgs.Handled) { MouseScroll?.Invoke(scrollArgs); } lastMouseWheelValue = mouse.ScrollWheelValue; } // Potentieller Positionsreset if (MouseMode == MouseMode.Free) { lastMousePosition = mousePosition; } else if (mousePosition.X != 0 || mousePosition.Y != 0) { lastMousePosition = mouse.Location; } MouseEventArgsPool.Instance.Release(mouseEventArgs); } #endregion #region Keyboard Interaction if (KeyboardEnabled) { KeyboardState keyboard = Keyboard.GetState(); bool shift = keyboard.IsKeyDown(Keys.LeftShift) | keyboard.IsKeyDown(Keys.RightShift); bool ctrl = keyboard.IsKeyDown(Keys.LeftControl) | keyboard.IsKeyDown(Keys.RightControl); bool alt = keyboard.IsKeyDown(Keys.LeftAlt) | keyboard.IsKeyDown(Keys.RightAlt); KeyEventArgs args; for (int i = 0; i < _pressedKeys.Length; i++) { var key = (Keys)i; if (keyboard.IsKeyDown(key)) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (_pressedKeys[i] == UnpressedKeyTimestamp) { // Taste ist neu args = KeyEventArgsPool.Take(); args.Key = key; args.Shift = shift; args.Ctrl = ctrl; args.Alt = alt; root.InternalKeyDown(args); if (!args.Handled) { KeyDown?.Invoke(args); } KeyEventArgsPool.Release(args); args = KeyEventArgsPool.Take(); args.Key = key; args.Shift = shift; args.Ctrl = ctrl; args.Alt = alt; root.InternalKeyPress(args); _pressedKeys[i] = gameTime.TotalGameTime.TotalMilliseconds + 500; KeyEventArgsPool.Release(args); // Spezialfall Tab-Taste (falls nicht verarbeitet wurde) if (key == Keys.Tab && !args.Handled) { if (shift) { root.InternalTabbedBackward(); } else { root.InternalTabbedForward(); } } } else { // Taste ist immernoch gedrückt if (_pressedKeys[i] <= gameTime.TotalGameTime.TotalMilliseconds) { args = KeyEventArgsPool.Take(); args.Key = key; args.Shift = shift; args.Ctrl = ctrl; args.Alt = alt; root.InternalKeyPress(args); if (!args.Handled) { KeyPress?.Invoke(args); } KeyEventArgsPool.Release(args); _pressedKeys[i] = gameTime.TotalGameTime.TotalMilliseconds + 50; } } } else { // ReSharper disable once CompareOfFloatsByEqualityOperator if (_pressedKeys[i] != UnpressedKeyTimestamp) { // Taste losgelassen args = KeyEventArgsPool.Take(); args.Key = key; args.Shift = shift; args.Ctrl = ctrl; args.Alt = alt; root.InternalKeyUp(args); _pressedKeys[i] = UnpressedKeyTimestamp; if (!args.Handled) { KeyUp?.Invoke(args); } KeyEventArgsPool.Release(args); } } } } #endregion #region Touchpanel Interaction //if (TouchEnabled) //{ // TouchCollection touchPoints = TouchPanel.GetState(); // foreach (var touchPoint in touchPoints) // { // Point point = touchPoint.Position.ToPoint(); // TouchEventArgs args = new TouchEventArgs() // { // TouchId = touchPoint.Id, // GlobalPosition = point, // LocalPosition = point // }; // switch (touchPoint.State) // { // case TouchLocationState.Pressed: // root.InternalTouchDown(args); // if (!args.Handled && TouchDown != null) // TouchDown(args); // break; // case TouchLocationState.Moved: // // Touch Move // root.InternalTouchMove(args); // if (!args.Handled && TouchMove != null) // TouchMove(args); // // Start Dragging // if (DraggingArgs == null) // { // DraggingArgs = new DragEventArgs() // { // GlobalPosition = point, // LocalPosition = point, // }; // draggingId = touchPoint.Id; // root.InternalStartDrag(DraggingArgs); // if (!DraggingArgs.Handled && StartDrag != null) // StartDrag(DraggingArgs); // } // // Drop move // if (DraggingArgs != null && // draggingId == touchPoint.Id && // DraggingArgs.Handled) // { // DragEventArgs moveArgs = new DragEventArgs() // { // GlobalPosition = point, // LocalPosition = point, // Content = DraggingArgs.Content, // Icon = DraggingArgs.Icon, // Sender = DraggingArgs.Sender // }; // root.InternalDropMove(moveArgs); // if (!args.Handled && DropMove != null) // DropMove(moveArgs); // } // break; // case TouchLocationState.Released: // // Handle Drop // if (DraggingArgs != null && // draggingId == touchPoint.Id && // DraggingArgs.Handled) // { // DragEventArgs dropArgs = new DragEventArgs() // { // GlobalPosition = point, // LocalPosition = point, // Content = DraggingArgs.Content, // Icon = DraggingArgs.Icon, // Sender = DraggingArgs.Sender // }; // root.InternalEndDrop(dropArgs); // if (!args.Handled && EndDrop != null) // EndDrop(dropArgs); // } // // Discard Dragging Infos // DraggingArgs = null; // draggingId = null; // // Linke Maustaste wurde losgelassen // TouchEventArgs tapArgs = new TouchEventArgs // { // TouchId = touchPoint.Id, // GlobalPosition = point, // LocalPosition = point // }; // root.InternalTouchTap(tapArgs); // if (!tapArgs.Handled && TouchTap != null) // TouchTap(tapArgs); // if (lastTouchTap.HasValue && // gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) // { // // Double Tap // TouchEventArgs doubleTapArgs = new TouchEventArgs // { // TouchId = touchPoint.Id, // GlobalPosition = point, // LocalPosition = point // }; // root.InternalTouchDoubleTap(doubleTapArgs); // if (!doubleTapArgs.Handled && TouchDoubleTap != null) // TouchDoubleTap(doubleTapArgs); // lastTouchTap = null; // } // else // { // lastTouchTap = gameTime.TotalGameTime; // } // root.InternalTouchUp(args); // if (!args.Handled && TouchUp != null) // TouchUp(args); // break; // } // } //} #endregion } #region Recalculate Sizes if (root.HasInvalidDimensions()) { Point available = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Point required = root.GetExpectedSize(available); root.SetActualSize(available); } root.Update(gameTime); #endregion #region Form anpassen if (_titleDirty || (ActiveScreen?.Title != _lastActiveScreenTitle)) { string screentitle = ActiveScreen?.Title ?? string.Empty; string windowtitle = TitlePrefix + (string.IsNullOrEmpty(screentitle) ? string.Empty : " - " + screentitle); if (Game.Window != null && Game.Window.Title != windowtitle) { Game.Window.Title = windowtitle; } _titleDirty = false; _lastActiveScreenTitle = ActiveScreen?.Title; } #endregion }
//private unsafe int HookFunc(IntPtr userdata, IntPtr ev) public unsafe void EventHandler(ref SDL_Event e) { // SDL_Event* e = (SDL_Event*) ev; switch (e.type) { case SDL_EventType.SDL_AUDIODEVICEADDED: Console.WriteLine("AUDIO ADDED: {0}", e.adevice.which); break; case SDL_EventType.SDL_AUDIODEVICEREMOVED: Console.WriteLine("AUDIO REMOVED: {0}", e.adevice.which); break; case SDL_EventType.SDL_WINDOWEVENT: switch (e.window.windowEvent) { case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: Mouse.MouseInWindow = true; break; case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: Mouse.MouseInWindow = false; break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: Plugin.OnFocusGained(); // SDL_CaptureMouse(SDL_bool.SDL_TRUE); //Log.Message(LogTypes.Debug, "FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: Plugin.OnFocusLost(); //Log.Message(LogTypes.Debug, "NO FOCUS"); //SDL_CaptureMouse(SDL_bool.SDL_FALSE); break; case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS: //Log.Message(LogTypes.Debug, "TAKE FOCUS"); break; case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST: break; } break; case SDL_EventType.SDL_SYSWMEVENT: break; case SDL_EventType.SDL_KEYDOWN: if (Plugin.ProcessHotkeys((int)e.key.keysym.sym, (int)e.key.keysym.mod, true)) { _ignoreNextTextInput = false; Engine.SceneManager.CurrentScene.OnKeyDown(e.key); KeyDown?.Raise(e.key); } else { _ignoreNextTextInput = true; } break; case SDL_EventType.SDL_KEYUP: Engine.SceneManager.CurrentScene.OnKeyUp(e.key); KeyUp.Raise(e.key); break; case SDL_EventType.SDL_TEXTINPUT: if (_ignoreNextTextInput) break; fixed(SDL_Event *ev = &e) { string s = StringHelper.ReadUTF8(ev->text.text); if (!string.IsNullOrEmpty(s)) { Engine.SceneManager.CurrentScene.OnTextInput(s); TextInput.Raise(s); } } break; case SDL_EventType.SDL_MOUSEMOTION: Mouse.Update(); if (Mouse.IsDragging) { Engine.SceneManager.CurrentScene.OnMouseDragging(); MouseDragging.Raise(); } if (Mouse.IsDragging && !_dragStarted) { DragBegin.Raise(); _dragStarted = true; } break; case SDL_EventType.SDL_MOUSEWHEEL: Mouse.Update(); bool isup = e.wheel.y > 0; Plugin.ProcessMouse(0, e.wheel.y); Engine.SceneManager.CurrentScene.OnMouseWheel(isup); MouseWheel.Raise(isup); break; case SDL_EventType.SDL_MOUSEBUTTONUP: case SDL_EventType.SDL_MOUSEBUTTONDOWN: Mouse.Update(); bool isDown = e.type == SDL_EventType.SDL_MOUSEBUTTONDOWN; if (_dragStarted && !isDown) { DragEnd.Raise(); _dragStarted = false; } SDL_MouseButtonEvent mouse = e.button; switch ((uint)mouse.button) { case SDL_BUTTON_LEFT: if (isDown) { Mouse.Begin(); Mouse.LButtonPressed = true; Mouse.LDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastLeftButtonClickTime = 0; var res = Engine.SceneManager.CurrentScene.OnLeftMouseDoubleClick(); MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Left); LeftMouseDoubleClick.Raise(arg); if (!arg.Result && !res) { Engine.SceneManager.CurrentScene.OnLeftMouseDown(); LeftMouseButtonDown.Raise(); } else { Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF; } break; } Engine.SceneManager.CurrentScene.OnLeftMouseDown(); LeftMouseButtonDown.Raise(); Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF) { Engine.SceneManager.CurrentScene.OnLeftMouseUp(); LeftMouseButtonUp.Raise(); } Mouse.LButtonPressed = false; Mouse.End(); Mouse.LastClickPosition = Mouse.Position; } break; case SDL_BUTTON_MIDDLE: if (isDown) { Mouse.Begin(); Mouse.MButtonPressed = true; Mouse.MDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastMidButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastMidButtonClickTime = 0; var res = Engine.SceneManager.CurrentScene.OnMiddleMouseDoubleClick(); MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Middle); MidMouseDoubleClick.Raise(arg); if (!arg.Result && !res) { Engine.SceneManager.CurrentScene.OnMiddleMouseDown(); MidMouseButtonDown.Raise(); } break; } Plugin.ProcessMouse(e.button.button, 0); Engine.SceneManager.CurrentScene.OnMiddleMouseDown(); MidMouseButtonDown.Raise(); Mouse.LastMidButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { MidMouseButtonUp.Raise(); Mouse.MButtonPressed = false; Mouse.End(); } break; case SDL_BUTTON_RIGHT: if (isDown) { Mouse.Begin(); Mouse.RButtonPressed = true; Mouse.RDropPosition = Mouse.Position; Mouse.CancelDoubleClick = false; uint ticks = SDL_GetTicks(); if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { Mouse.LastRightButtonClickTime = 0; var res = Engine.SceneManager.CurrentScene.OnRightMouseDoubleClick(); MouseDoubleClickEventArgs arg = new MouseDoubleClickEventArgs(Mouse.Position.X, Mouse.Position.Y, MouseButton.Right); RightMouseDoubleClick.Raise(arg); if (!arg.Result && !res) { Engine.SceneManager.CurrentScene.OnRightMouseDown(); RightMouseButtonDown.Raise(); } else { Mouse.LastRightButtonClickTime = 0xFFFF_FFFF; } break; } Engine.SceneManager.CurrentScene.OnRightMouseDown(); RightMouseButtonDown.Raise(); Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } else { if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF) { Engine.SceneManager.CurrentScene.OnRightMouseUp(); RightMouseButtonUp.Raise(); } Mouse.RButtonPressed = false; Mouse.End(); } break; case SDL_BUTTON_X1: if (isDown) { Plugin.ProcessMouse(e.button.button, 0); } break; case SDL_BUTTON_X2: if (isDown) { Plugin.ProcessMouse(e.button.button, 0); } break; } break; } }