public override bool Initialize(GameHost host) { if (!base.Initialize(host)) { return(false); } if (!(host.Window is SDL2DesktopWindow desktopWindow)) { return(false); } window = desktopWindow; isActive = window.IsActive.GetBoundCopy(); isActive.BindValueChanged(_ => updateRelativeMode()); cursorInWindow = host.Window.CursorInWindow.GetBoundCopy(); cursorInWindow.BindValueChanged(_ => updateRelativeMode()); cursorState = desktopWindow.CursorStateBindable.GetBoundCopy(); cursorState.BindValueChanged(_ => updateRelativeMode()); UseRelativeMode.BindValueChanged(_ => { if (window != null) { updateRelativeMode(); } }); Enabled.BindValueChanged(enabled => { updateRelativeMode(); if (enabled.NewValue) { window.MouseMove += HandleMouseMove; window.MouseMoveRelative += HandleMouseMoveRelative; window.MouseDown += handleMouseDown; window.MouseUp += handleMouseUp; window.MouseWheel += handleMouseWheel; } else { window.MouseMove -= HandleMouseMove; window.MouseMoveRelative -= HandleMouseMoveRelative; window.MouseDown -= handleMouseDown; window.MouseUp -= handleMouseUp; window.MouseWheel -= handleMouseWheel; } }, true); return(true); }
public override bool Initialize(GameHost host) { if (!(host.Window is SDL2DesktopWindow desktopWindow)) { return(false); } window = desktopWindow; callback = (ptr, wnd, u, param, l) => onWndProc(ptr, wnd, u, param, l); Enabled.BindValueChanged(enabled => { host.InputThread.Scheduler.Add(() => SDL.SDL_SetWindowsMessageHook(enabled.NewValue ? callback : null, IntPtr.Zero)); }, true); return(base.Initialize(host)); }
private void load(FrameworkConfigManager config, GameHost host) { window = host.Window as SDL2DesktopWindow; config.BindWith(FrameworkSetting.WindowMode, windowMode); if (window == null) { Logger.Log("No suitable window found"); return; } refreshScreens(); AddStep("set up screens", refreshScreens); const string desc2 = "Check whether the window size is one pixel wider than the screen in each direction"; Point originalWindowPosition = Point.Empty; foreach (var display in window.Displays) { AddLabel($"Steps for display {display.Index}"); // set up window AddStep("switch to windowed", () => windowMode.Value = WindowMode.Windowed); AddStep($"move window to display {display.Index}", () => window.CurrentDisplayBindable.Value = window.Displays.ElementAt(display.Index)); AddStep("set client size to 1280x720", () => config.SetValue(FrameworkSetting.WindowedSize, new Size(1280, 720))); AddStep("store window position", () => originalWindowPosition = window.Position); // borderless alignment tests AddStep("switch to borderless", () => windowMode.Value = WindowMode.Borderless); AddAssert("check window position", () => new Point(window.Position.X, window.Position.Y) == display.Bounds.Location); AddAssert("check window size", () => new Size(window.Size.Width, window.Size.Height) == display.Bounds.Size, desc2); AddAssert("check current screen", () => window.CurrentDisplayBindable.Value.Index == display.Index); // verify the window size is restored correctly AddStep("switch to windowed", () => windowMode.Value = WindowMode.Windowed); AddAssert("check client size", () => window.ClientSize == new Size(1280, 720)); AddAssert("check window position", () => originalWindowPosition == window.Position); AddAssert("check current screen", () => window.CurrentDisplayBindable.Value.Index == display.Index); } }
public SDL2DesktopWindowTextInput(SDL2DesktopWindow window) { this.window = window; }
public override bool Initialize(GameHost host) { if (!base.Initialize(host)) { return(false); } if (!(host.Window is SDL2DesktopWindow desktopWindow)) { return(false); } window = desktopWindow; isActive = window.IsActive.GetBoundCopy(); isActive.BindValueChanged(_ => updateRelativeMode()); cursorInWindow = host.Window.CursorInWindow.GetBoundCopy(); cursorInWindow.BindValueChanged(e => { if (e.NewValue) { // don't immediately update if the cursor has just entered the window pendingUpdateRelativeMode = true; } else { updateRelativeMode(); } }); cursorState = desktopWindow.CursorStateBindable.GetBoundCopy(); cursorState.BindValueChanged(_ => updateRelativeMode()); UseRelativeMode.BindValueChanged(_ => { if (window != null) { updateRelativeMode(); } }); Enabled.BindValueChanged(enabled => { updateRelativeMode(); if (enabled.NewValue) { window.MouseMove += HandleMouseMove; window.MouseMoveRelative += HandleMouseMoveRelative; window.MouseDown += handleMouseDown; window.MouseUp += handleMouseUp; window.MouseWheel += handleMouseWheel; } else { window.MouseMove -= HandleMouseMove; window.MouseMoveRelative -= HandleMouseMoveRelative; window.MouseDown -= handleMouseDown; window.MouseUp -= handleMouseUp; window.MouseWheel -= handleMouseWheel; } }, true); window.Exited += () => { if (window.RelativeMouseMode && cursorCaptured) { window.RelativeMouseMode = false; transferLastPositionToHostCursor(); } }; return(true); }
private void load() { sdlWindow = (SDL2DesktopWindow)host.Window; }