private int HandleSdlEvent(IntPtr userData, IntPtr ptr) { SDL_Event *sdlEvent = (SDL_Event *)ptr; if (Plugin.ProcessWndProc(sdlEvent) != 0) { if (sdlEvent->type == SDL_EventType.SDL_MOUSEMOTION) { if (UIManager.GameCursor != null) { UIManager.GameCursor.AllowDrawSDLCursor = false; } } return(0); } switch (sdlEvent->type) { case SDL_EventType.SDL_AUDIODEVICEADDED: Console.WriteLine("AUDIO ADDED: {0}", sdlEvent->adevice.which); break; case SDL_EventType.SDL_AUDIODEVICEREMOVED: Console.WriteLine("AUDIO REMOVED: {0}", sdlEvent->adevice.which); break; case SDL_EventType.SDL_WINDOWEVENT: switch (sdlEvent->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(); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: Plugin.OnFocusLost(); break; } break; case SDL_EventType.SDL_KEYDOWN: Keyboard.OnKeyDown(sdlEvent->key); if (Plugin.ProcessHotkeys((int)sdlEvent->key.keysym.sym, (int)sdlEvent->key.keysym.mod, true)) { _ignoreNextTextInput = false; UIManager.KeyboardFocusControl?.InvokeKeyDown(sdlEvent->key.keysym.sym, sdlEvent->key.keysym.mod); Scene.OnKeyDown(sdlEvent->key); } else { _ignoreNextTextInput = true; } break; case SDL_EventType.SDL_KEYUP: Keyboard.OnKeyUp(sdlEvent->key); UIManager.KeyboardFocusControl?.InvokeKeyUp(sdlEvent->key.keysym.sym, sdlEvent->key.keysym.mod); Scene.OnKeyUp(sdlEvent->key); Plugin.ProcessHotkeys(0, 0, false); if (sdlEvent->key.keysym.sym == SDL_Keycode.SDLK_PRINTSCREEN) { TakeScreenshot(); } break; case SDL_EventType.SDL_TEXTINPUT: if (_ignoreNextTextInput) { break; } // Fix for linux OS: https://github.com/andreakarasho/ClassicUO/pull/1263 if (Keyboard.Alt || Keyboard.Ctrl) { break; } string s = UTF8_ToManaged((IntPtr)sdlEvent->text.text, false); if (!string.IsNullOrEmpty(s)) { UIManager.KeyboardFocusControl?.InvokeTextInput(s); Scene.OnTextInput(s); } break; case SDL_EventType.SDL_MOUSEMOTION: if (UIManager.GameCursor != null && !UIManager.GameCursor.AllowDrawSDLCursor) { UIManager.GameCursor.AllowDrawSDLCursor = true; UIManager.GameCursor.Graphic = 0xFFFF; } Mouse.Update(); if (Mouse.IsDragging) { if (!Scene.OnMouseDragging()) { UIManager.OnMouseDragging(); } } if (Mouse.IsDragging && !_dragStarted) { _dragStarted = true; } break; case SDL_EventType.SDL_MOUSEWHEEL: Mouse.Update(); bool isScrolledUp = sdlEvent->wheel.y > 0; Plugin.ProcessMouse(0, sdlEvent->wheel.y); if (!Scene.OnMouseWheel(isScrolledUp)) { UIManager.OnMouseWheel(isScrolledUp); } break; case SDL_EventType.SDL_MOUSEBUTTONDOWN: { Mouse.Update(); SDL_MouseButtonEvent mouse = sdlEvent->button; // The values in MouseButtonType are chosen to exactly match the SDL values MouseButtonType buttonType = (MouseButtonType)mouse.button; uint lastClickTime = 0; switch (buttonType) { case MouseButtonType.Left: lastClickTime = Mouse.LastLeftButtonClickTime; break; case MouseButtonType.Middle: lastClickTime = Mouse.LastMidButtonClickTime; break; case MouseButtonType.Right: lastClickTime = Mouse.LastRightButtonClickTime; break; } Mouse.ButtonPress(buttonType); uint ticks = Time.Ticks; if (lastClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks) { lastClickTime = 0; bool res = Scene.OnMouseDoubleClick(buttonType) || UIManager.OnMouseDoubleClick(buttonType); if (!res) { if (!Scene.OnMouseDown(buttonType)) { UIManager.OnMouseButtonDown(buttonType); } } else { lastClickTime = 0xFFFF_FFFF; } } else { if (buttonType != MouseButtonType.Left && buttonType != MouseButtonType.Right) { Plugin.ProcessMouse(sdlEvent->button.button, 0); } if (!Scene.OnMouseDown(buttonType)) { UIManager.OnMouseButtonDown(buttonType); } lastClickTime = Mouse.CancelDoubleClick ? 0 : ticks; } switch (buttonType) { case MouseButtonType.Left: Mouse.LastLeftButtonClickTime = lastClickTime; break; case MouseButtonType.Middle: Mouse.LastMidButtonClickTime = lastClickTime; break; case MouseButtonType.Right: Mouse.LastRightButtonClickTime = lastClickTime; break; } break; } case SDL_EventType.SDL_MOUSEBUTTONUP: { Mouse.Update(); if (_dragStarted) { _dragStarted = false; } SDL_MouseButtonEvent mouse = sdlEvent->button; // The values in MouseButtonType are chosen to exactly match the SDL values MouseButtonType buttonType = (MouseButtonType)mouse.button; uint lastClickTime = 0; switch (buttonType) { case MouseButtonType.Left: lastClickTime = Mouse.LastLeftButtonClickTime; break; case MouseButtonType.Middle: lastClickTime = Mouse.LastMidButtonClickTime; break; case MouseButtonType.Right: lastClickTime = Mouse.LastRightButtonClickTime; break; } if (lastClickTime != 0xFFFF_FFFF) { if (!Scene.OnMouseUp(buttonType) || UIManager.LastControlMouseDown(buttonType) != null) { UIManager.OnMouseButtonUp(buttonType); } } Mouse.ButtonRelease(buttonType); break; } } return(0); }