internal LinuxGameHost(string gameName, bool bindIPC = false) : base(gameName, bindIPC) { Window = new DesktopGameWindow(); Window.WindowStateChanged += (sender, e) => { if (Window.WindowState != OpenTK.WindowState.Minimized) { OnActivated(); } else { OnDeactivated(); } }; }
internal LinuxGameHost(GraphicsContextFlags flags, string gameName, bool bindIPC = false) : base(gameName, bindIPC) { Window = new DesktopGameWindow(); Window.WindowStateChanged += (sender, e) => { if (Window.WindowState != OpenTK.WindowState.Minimized) { OnActivated(); } else { OnDeactivated(); } }; Dependencies.Cache(Storage = new LinuxStorage(gameName)); }
private void load(FrameworkConfigManager config, GameHost host) { window = (DesktopGameWindow)host.Window; config.BindWith(FrameworkSetting.SizeFullscreen, sizeFullscreen); config.BindWith(FrameworkSetting.WindowMode, windowMode); // so the test case doesn't change fullscreen size just when you enter it AddStep("nothing", () => { }); // I'll assume that most monitors are compatible with 1280x720, and this is just for testing anyways testResolution(1280, 720); AddStep("change to fullscreen", () => windowMode.Value = WindowMode.Fullscreen); testResolution(1920, 1080); testResolution(1280, 960); AddStep("go back to windowed", () => windowMode.Value = WindowMode.Windowed); }
private void load(FrameworkConfigManager config, GameHost host) { window = host.Window as DesktopGameWindow; config.BindWith(FrameworkSetting.WindowMode, windowMode); if (window == null) { Console.WriteLine("No suitable window found"); return; } refreshScreens(); AddStep("set up screens", refreshScreens); const string desc1 = "Check whether the borderless window is properly set to the top left corner, even if it is obstructed by the taskbar"; const string desc2 = "Check whether the window size is one pixel wider than the screen in each direction"; for (int i = 0;; i++) { var display = DisplayDevice.GetDisplay((DisplayIndex)i); if (display == null) { break; } // set up window AddStep("switch to windowed", () => windowMode.Value = WindowMode.Windowed); AddStep("set client size to 1280x720", () => window.ClientSize = new Size(1280, 720)); AddStep("center window on screen " + i, () => window.CentreToScreen(display)); // borderless alignment tests AddStep("switch to borderless", () => windowMode.Value = WindowMode.Borderless); AddAssert("check window location", () => window.Location == display.Bounds.Location, desc1); AddAssert("check window size", () => new Size(window.Width - 1, window.Height - 1) == display.Bounds.Size, desc2); AddAssert("check current screen", () => window.CurrentDisplay == display); // 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", () => Math.Abs(window.Position.X - 0.5f) < 0.01 && Math.Abs(window.Position.Y - 0.5f) < 0.01); AddAssert("check current screen", () => window.CurrentDisplay == display); } }
public override bool Initialize(GameHost host) { host.Window.MouseEnter += window_MouseEnter; host.Window.MouseLeave += window_MouseLeave; mouseInWindow = host.Window.CursorInWindow; // Get the bindables we need to determine whether to confine the mouse to window or not DesktopGameWindow desktopWindow = host.Window as DesktopGameWindow; if (desktopWindow != null) { confineMode.BindTo(desktopWindow.ConfineMouseMode); windowMode.BindTo(desktopWindow.WindowMode); } Enabled.ValueChanged += enabled => { if (enabled) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (!host.Window.Visible) { return; } bool useRawInput = mouseInWindow && host.Window.Focused; var state = useRawInput ? OpenTK.Input.Mouse.GetState() : OpenTK.Input.Mouse.GetCursorState(); if (state.Equals(lastState)) { return; } if (useRawInput) { if (!lastState.HasValue) { // when we return from being outside of the window, we want to set the new position of our game cursor // to where the OS cursor is, just once. var cursorState = OpenTK.Input.Mouse.GetCursorState(); var screenPoint = host.Window.PointToClient(new Point(cursorState.X, cursorState.Y)); currentPosition = new Vector2(screenPoint.X, screenPoint.Y); } else { currentPosition += new Vector2(state.X - lastState.Value.X, state.Y - lastState.Value.Y) * (float)sensitivity.Value; // When confining, clamp to the window size. if (confineMode.Value == ConfineMouseMode.Always || confineMode.Value == ConfineMouseMode.Fullscreen && windowMode.Value == WindowMode.Fullscreen) { currentPosition = Vector2.Clamp(currentPosition, Vector2.Zero, new Vector2(host.Window.Width, host.Window.Height)); } // update the windows cursor to match our raw cursor position. // this is important when sensitivity is decreased below 1.0, where we need to ensure the cursor stays withing the window. var screenPoint = host.Window.PointToScreen(new Point((int)currentPosition.X, (int)currentPosition.Y)); OpenTK.Input.Mouse.SetPosition(screenPoint.X, screenPoint.Y); } } else { var screenPoint = host.Window.PointToClient(new Point(state.X, state.Y)); currentPosition = new Vector2(screenPoint.X, screenPoint.Y); } IMouseState newState; // While not focused, let's silently ignore everything but position. if (host.IsActive) { lastState = state; newState = new OpenTKPollMouseState(state, host.IsActive, currentPosition); } else { lastState = null; newState = new UnfocusedMouseState(new OpenTK.Input.MouseState(), host.IsActive, currentPosition); } PendingStates.Enqueue(new InputState { Mouse = newState }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); }, 0, 0)); } else { scheduled?.Cancel(); lastState = null; } }; Enabled.TriggerChange(); return(true); }
public override bool Initialize(GameHost host) { host.Window.MouseEnter += window_MouseEnter; host.Window.MouseLeave += window_MouseLeave; this.host = host; mouseInWindow = host.Window.CursorInWindow; // Get the bindables we need to determine whether to confine the mouse to window or not DesktopGameWindow desktopWindow = host.Window as DesktopGameWindow; if (desktopWindow != null) { confineMode.BindTo(desktopWindow.ConfineMouseMode); windowMode.BindTo(desktopWindow.WindowMode); mapAbsoluteInputToWindow.BindTo(desktopWindow.MapAbsoluteInputToWindow); } Enabled.ValueChanged += enabled => { if (enabled) { host.InputThread.Scheduler.Add(scheduled = new ScheduledDelegate(delegate { if (!host.Window.Visible || host.Window.WindowState == WindowState.Minimized) { return; } if ((mouseInWindow || lastStates.Any(s => s.HasAnyButtonPressed)) && host.Window.Focused) { var newStates = new List <OpenTK.Input.MouseState>(mostSeenStates + 1); for (int i = 0; i <= mostSeenStates + 1; i++) { var s = OpenTK.Input.Mouse.GetState(i); if (s.IsConnected || i < mostSeenStates) { newStates.Add(s); mostSeenStates = i; } } while (lastStates.Count < newStates.Count) { lastStates.Add(null); } for (int i = 0; i < newStates.Count; i++) { if (newStates[i].IsConnected != true) { lastStates[i] = null; continue; } var state = newStates[i]; var lastState = lastStates[i]; if (lastState != null && state.Equals(lastState.RawState)) { continue; } var newState = new OpenTKPollMouseState(state, host.IsActive, getUpdatedPosition(state, lastState)) { LastState = lastState }; lastStates[i] = newState; if (lastState != null) { PendingStates.Enqueue(new InputState { Mouse = newState }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); } } } else { var state = OpenTK.Input.Mouse.GetCursorState(); var screenPoint = host.Window.PointToClient(new Point(state.X, state.Y)); PendingStates.Enqueue(new InputState { Mouse = new UnfocusedMouseState(new OpenTK.Input.MouseState(), host.IsActive, new Vector2(screenPoint.X, screenPoint.Y)) }); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); lastStates.Clear(); } }, 0, 0)); } else { scheduled?.Cancel(); lastStates.Clear(); } }; Enabled.TriggerChange(); return(true); }