/// <summary> /// Gets the Game View window's top left Position. /// </summary> /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks> protected virtual Vector2 GetWindowPosition() { var windowPosition = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(Hwnd, ref windowPosition); return(new Vector2(windowPosition.x, windowPosition.y)); }
/// <summary> /// Maps from logical pixels to physical desktop pixels. /// </summary> /// <param name="rect">Rectangle to be transformed.</param> /// <returns>Transformed rectangle.</returns> protected virtual Rect LogicalToPhysical(Rect rect) { var topLeft = new Win32Helpers.POINT { x = (int)rect.x, y = (int)rect.y }; Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref topLeft); var bottomRight = new Win32Helpers.POINT { x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height) }; Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref bottomRight); return new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); }
/// <summary> /// Gets the Game View window's top left position. /// </summary> /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks> protected virtual Vector2 GetWindowPosition() { if (IntPtr.Zero == _gameViewWindowHandle) { return(new Vector2(float.NaN, float.NaN)); } var windowPosition = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(_gameViewWindowHandle, ref windowPosition); return(new Vector2(windowPosition.x, windowPosition.y)); }
/// <summary> /// Gets the Game View window's bottom right corner Position. /// </summary> /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks> protected virtual Vector2 GetWindowBottomRight() { var clientRect = new Win32Helpers.RECT(); Win32Helpers.GetClientRect(Hwnd, ref clientRect); var bottomRight = new Win32Helpers.POINT { x = clientRect.right, y = clientRect.bottom }; Win32Helpers.ClientToScreen(Hwnd, ref bottomRight); return(new Vector2(bottomRight.x, bottomRight.y)); }
/// <summary> /// Maps from logical pixels to physical desktop pixels. /// </summary> /// <param name="rect">Rectangle to be transformed.</param> /// <returns>Transformed rectangle.</returns> protected virtual Rect LogicalToPhysical(Rect rect) { var topLeft = new Win32Helpers.POINT { x = (int)rect.x, y = (int)rect.y }; Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref topLeft); var bottomRight = new Win32Helpers.POINT { x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height) }; Win32Helpers.LogicalToPhysicalPoint(_hwnd, ref bottomRight); return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y)); }
protected override Rect GetViewportLogicalBounds() { var clientRect = new Win32Helpers.RECT(); Win32Helpers.GetClientRect(_hwnd, ref clientRect); var topLeft = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(_hwnd, ref topLeft); var bottomRight = new Win32Helpers.POINT { x = clientRect.right, y = clientRect.bottom }; Win32Helpers.ClientToScreen(_hwnd, ref bottomRight); return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y)); }
/// <summary> /// Gets the Game View window's bottom right corner position. /// </summary> /// <remarks>Overridden in test project. Do not remove without updating tests.</remarks> protected virtual Vector2 GetWindowBottomRight() { if (IntPtr.Zero == _gameViewWindowHandle) { return(new Vector2(float.NaN, float.NaN)); } var clientRect = new Win32Helpers.RECT(); Win32Helpers.GetClientRect(_gameViewWindowHandle, ref clientRect); var bottomRight = new Win32Helpers.POINT { x = clientRect.right, y = clientRect.bottom }; Win32Helpers.ClientToScreen(_gameViewWindowHandle, ref bottomRight); return(new Vector2(bottomRight.x, bottomRight.y)); }
/// <summary> /// Maps from logical pixels to physical desktop pixels. /// </summary> /// <param name="rect">Rectangle to be transformed.</param> /// <returns>Transformed rectangle.</returns> protected virtual Rect LogicalToPhysical(Rect rect) { if (float.IsNaN(rect.x)) { return(rect); } var topLeft = new Win32Helpers.POINT { x = (int)rect.x, y = (int)rect.y }; Win32Helpers.LogicalToPhysicalPoint(_gameViewWindowHandle, ref topLeft); var bottomRight = new Win32Helpers.POINT { x = (int)(rect.x + rect.width), y = (int)(rect.y + rect.height) }; Win32Helpers.LogicalToPhysicalPoint(_gameViewWindowHandle, ref bottomRight); return(new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y)); }
/// <summary> /// Gets the gameview's window position. /// </summary> /// <returns></returns> protected virtual Vector2 GetWindowPosition() { var windowPosition = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(_hwnd, ref windowPosition); return new Vector2(windowPosition.x, windowPosition.y); }
protected override Rect GetViewportLogicalBounds() { var clientRect = new Win32Helpers.RECT(); Win32Helpers.GetClientRect(_hwnd, ref clientRect); var topLeft = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(_hwnd, ref topLeft); var bottomRight = new Win32Helpers.POINT { x = clientRect.right, y = clientRect.bottom }; Win32Helpers.ClientToScreen(_hwnd, ref bottomRight); return new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); }
/// <summary> /// Returns the position of the game window in screen coordinates. /// </summary> public Vector2 GetGameWindowPosition() { #if UNITY_EDITOR var gameWindowPosition = _gameWindow.position; var heightOffset = gameWindowPosition.height - Screen.height; return new Vector2(gameWindowPosition.x, gameWindowPosition.y + heightOffset); #else var windowClientPosition = new Win32Helpers.POINT(); Win32Helpers.ClientToScreen(_hwnd, ref windowClientPosition); return new Vector2(windowClientPosition.x, windowClientPosition.y); #endif }