Merge branch 'enha-point-from-to-screen' of git://github.com/stefnotch/FlaxEngine into stefnotch-enha-point-from-to-screen

This commit is contained in:
Wojtek Figat
2020-12-29 23:13:21 +01:00
8 changed files with 20 additions and 20 deletions

View File

@@ -58,7 +58,7 @@ namespace FlaxEditor.Content
public override bool OnMouseDoubleClick(Vector2 location, MouseButton button) public override bool OnMouseDoubleClick(Vector2 location, MouseButton button)
{ {
return Item.OnMouseDoubleClick(Item.ScreenToClient(ClientToScreen(location)), button); return Item.OnMouseDoubleClick(Item.PointFromScreen(PointToScreen(location)), button);
} }
} }

View File

@@ -1203,7 +1203,7 @@ namespace FlaxEditor
var win = Windows.GameWin.Root; var win = Windows.GameWin.Root;
if (win != null && win.RootWindow is WindowRootControl root && root.Window.IsFocused) if (win != null && win.RootWindow is WindowRootControl root && root.Window.IsFocused)
{ {
pos = Vector2.Round(Windows.GameWin.Viewport.PointFromWindow(root.ScreenToClient(pos))); pos = Vector2.Round(Windows.GameWin.Viewport.PointFromWindow(root.Window.ScreenToClient(pos)));
} }
else else
{ {

View File

@@ -114,7 +114,7 @@ namespace FlaxEditor.GUI.ContextMenu
// Check if show menu inside the other menu - then link as a child to prevent closing the calling menu window on lost focus // Check if show menu inside the other menu - then link as a child to prevent closing the calling menu window on lost focus
if (_parentCM == null && parentWin.ChildrenCount == 1 && parentWin.Children[0] is ContextMenuBase parentCM) if (_parentCM == null && parentWin.ChildrenCount == 1 && parentWin.Children[0] is ContextMenuBase parentCM)
{ {
parentCM.ShowChild(this, parentCM.ScreenToClient(parent.ClientToScreen(location)), false); parentCM.ShowChild(this, parentCM.PointFromScreen(parent.PointToScreen(location)), false);
return; return;
} }
@@ -126,7 +126,7 @@ namespace FlaxEditor.GUI.ContextMenu
var dpiScale = Platform.DpiScale; var dpiScale = Platform.DpiScale;
Vector2 dpiSize = Size * dpiScale; Vector2 dpiSize = Size * dpiScale;
Vector2 locationWS = parent.PointToWindow(location); Vector2 locationWS = parent.PointToWindow(location);
Vector2 locationSS = parentWin.ClientToScreen(locationWS * dpiScale); Vector2 locationSS = parentWin.PointToScreen(locationWS);
Location = Vector2.Zero; Location = Vector2.Zero;
Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS); Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS);
Vector2 rightBottomLocationSS = locationSS + dpiSize; Vector2 rightBottomLocationSS = locationSS + dpiSize;
@@ -303,7 +303,7 @@ namespace FlaxEditor.GUI.ContextMenu
if (_parentCM != null) if (_parentCM != null)
{ {
// Focus parent if user clicked over the parent popup // Focus parent if user clicked over the parent popup
var mouse = _parentCM.ScreenToClient(FlaxEngine.Input.MouseScreenPosition); var mouse = _parentCM.PointFromScreen(FlaxEngine.Input.MouseScreenPosition);
if (_parentCM.ContainsPoint(ref mouse)) if (_parentCM.ContainsPoint(ref mouse))
{ {
_parentCM._window.Focus(); _parentCM._window.Focus();

View File

@@ -125,7 +125,7 @@ namespace FlaxEditor.GUI.Docking
var control = _tabsProxy != null ? (Control)_tabsProxy : this; var control = _tabsProxy != null ? (Control)_tabsProxy : this;
var dpiScale = Platform.DpiScale; var dpiScale = Platform.DpiScale;
var clientPos = control.PointToWindow(Vector2.Zero); var clientPos = control.PointToWindow(Vector2.Zero);
return new Rectangle(parentWin.ClientToScreen(clientPos * dpiScale), control.Size * dpiScale); return new Rectangle(parentWin.PointToScreen(clientPos), control.Size * dpiScale);
} }
} }
@@ -310,7 +310,7 @@ namespace FlaxEditor.GUI.Docking
var parentWin = Root; var parentWin = Root;
if (parentWin == null) if (parentWin == null)
return null; return null;
Vector2 clientPos = parentWin.ScreenToClient(position); Vector2 clientPos = parentWin.PointFromScreen(position);
Vector2 localPos = PointFromWindow(clientPos); Vector2 localPos = PointFromWindow(clientPos);
// Early out // Early out

View File

@@ -359,13 +359,13 @@ namespace FlaxEditor.Modules
// Place dialog nearby the target control // Place dialog nearby the target control
if (targetControl != null) if (targetControl != null)
{ {
var targetControlDesktopCenter = targetControl.ClientToScreen(targetControl.Size * 0.5f); var targetControlDesktopCenter = targetControl.PointToScreen(targetControl.Size * 0.5f);
var desktopSize = Platform.GetMonitorBounds(targetControlDesktopCenter); var desktopSize = Platform.GetMonitorBounds(targetControlDesktopCenter);
var pos = targetControlDesktopCenter + new Vector2(10.0f, -dialog.Height * 0.5f); var pos = targetControlDesktopCenter + new Vector2(10.0f, -dialog.Height * 0.5f);
var dialogEnd = pos + dialog.Size; var dialogEnd = pos + dialog.Size;
var desktopEnd = desktopSize.BottomRight - new Vector2(10.0f); var desktopEnd = desktopSize.BottomRight - new Vector2(10.0f);
if (dialogEnd.X >= desktopEnd.X || dialogEnd.Y >= desktopEnd.Y) if (dialogEnd.X >= desktopEnd.X || dialogEnd.Y >= desktopEnd.Y)
pos = targetControl.ClientToScreen(Vector2.Zero) - new Vector2(10.0f + dialog.Width, dialog.Height); pos = targetControl.PointToScreen(Vector2.Zero) - new Vector2(10.0f + dialog.Width, dialog.Height);
var desktopBounds = Platform.VirtualDesktopBounds; var desktopBounds = Platform.VirtualDesktopBounds;
pos = Vector2.Clamp(pos, desktopBounds.UpperLeft, desktopBounds.BottomRight - dialog.Size); pos = Vector2.Clamp(pos, desktopBounds.UpperLeft, desktopBounds.BottomRight - dialog.Size);
dialog.RootWindow.Window.Position = pos; dialog.RootWindow.Window.Position = pos;

View File

@@ -323,7 +323,7 @@ namespace FlaxEngine.GUI
if (parentWin == null) if (parentWin == null)
throw new InvalidOperationException("Missing parent window."); throw new InvalidOperationException("Missing parent window.");
var clientPos = PointToWindow(Vector2.Zero); var clientPos = PointToWindow(Vector2.Zero);
return parentWin.ClientToScreen(clientPos); return parentWin.PointToScreen(clientPos);
} }
} }
@@ -1113,12 +1113,12 @@ namespace FlaxEngine.GUI
/// </summary> /// </summary>
/// <param name="location">Input location of the point to convert</param> /// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in screen coordinates</returns> /// <returns>Converted point location in screen coordinates</returns>
public virtual Vector2 ClientToScreen(Vector2 location) public virtual Vector2 PointToScreen(Vector2 location)
{ {
location = PointToParent(ref location); location = PointToParent(ref location);
if (_parent != null) if (_parent != null)
{ {
location = _parent.ClientToScreen(location); location = _parent.PointToScreen(location);
} }
return location; return location;
} }
@@ -1128,11 +1128,11 @@ namespace FlaxEngine.GUI
/// </summary> /// </summary>
/// <param name="location">Input location of the point to convert</param> /// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in local control's space</returns> /// <returns>Converted point location in local control's space</returns>
public virtual Vector2 ScreenToClient(Vector2 location) public virtual Vector2 PointFromScreen(Vector2 location)
{ {
if (_parent != null) if (_parent != null)
{ {
location = _parent.ScreenToClient(location); location = _parent.PointFromScreen(location);
} }
return PointFromParent(ref location); return PointFromParent(ref location);
} }

View File

@@ -71,7 +71,7 @@ namespace FlaxEngine.GUI
float dpiScale = Platform.DpiScale; float dpiScale = Platform.DpiScale;
Vector2 dpiSize = Size * dpiScale; Vector2 dpiSize = Size * dpiScale;
Vector2 locationWS = target.PointToWindow(location); Vector2 locationWS = target.PointToWindow(location);
Vector2 locationSS = parentWin.ClientToScreen(locationWS * dpiScale); Vector2 locationSS = parentWin.PointToScreen(locationWS);
Vector2 screenSize = Platform.VirtualDesktopSize; Vector2 screenSize = Platform.VirtualDesktopSize;
Vector2 rightBottomLocationSS = locationSS + dpiSize; Vector2 rightBottomLocationSS = locationSS + dpiSize;
if (screenSize.Y < rightBottomLocationSS.Y) if (screenSize.Y < rightBottomLocationSS.Y)
@@ -194,7 +194,7 @@ namespace FlaxEngine.GUI
{ {
// Auto hide if mouse leaves control area // Auto hide if mouse leaves control area
Vector2 mousePos = Input.MouseScreenPosition; Vector2 mousePos = Input.MouseScreenPosition;
Vector2 location = _showTarget.ScreenToClient(mousePos); Vector2 location = _showTarget.PointFromScreen(mousePos);
if (!_showTarget.OnTestTooltipOverControl(ref location)) if (!_showTarget.OnTestTooltipOverControl(ref location))
{ {
// Mouse left or sth // Mouse left or sth

View File

@@ -232,15 +232,15 @@ namespace FlaxEngine.GUI
} }
/// <inheritdoc /> /// <inheritdoc />
public override Vector2 ScreenToClient(Vector2 location) public override Vector2 PointFromScreen(Vector2 location)
{ {
return _window.ScreenToClient(location) / Platform.DpiScale; return _window.ScreenToClient(location) / _window._dpiScale;
} }
/// <inheritdoc /> /// <inheritdoc />
public override Vector2 ClientToScreen(Vector2 location) public override Vector2 PointToScreen(Vector2 location)
{ {
return _window.ClientToScreen(location); return _window.ClientToScreen(location * _window._dpiScale);
} }
/// <inheritdoc /> /// <inheritdoc />