Skip to content

Commit

Permalink
Merge pull request #328 from BAndysc/coords_fix
Browse files Browse the repository at this point in the history
Fixed mixed screen/client position usage
  • Loading branch information
wieslawsoltes authored Mar 11, 2024
2 parents 331661c + 15c4311 commit ee9921b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/Dock.Avalonia/Controls/HostWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
}
}

private PixelPoint ClientPointToScreenRelativeToWindow(Point clientPoint)
{
var absScreenPoint = this.PointToScreen(clientPoint);
var absScreenWindowPoint = this.PointToScreen(new Point(0, 0));
var relativeScreenDiff = absScreenPoint - absScreenWindowPoint;
return relativeScreenDiff;
}

private void MoveDrag(PointerPressedEventArgs e)
{
if (Window?.Factory?.OnWindowMoveDragBegin(Window) != true)
Expand All @@ -97,7 +105,7 @@ private void MoveDrag(PointerPressedEventArgs e)
}

_mouseDown = true;
_hostWindowState.Process(e.GetPosition(this), EventType.Pressed);
_hostWindowState.Process(ClientPointToScreenRelativeToWindow(e.GetPosition(this)), EventType.Pressed);

PseudoClasses.Set(":dragging", true);
_draggingWindow = true;
Expand All @@ -109,7 +117,7 @@ private void EndDrag(PointerEventArgs e)
PseudoClasses.Set(":dragging", false);

Window?.Factory?.OnWindowMoveDragEnd(Window);
_hostWindowState.Process(e.GetPosition(this), EventType.Released);
_hostWindowState.Process(ClientPointToScreenRelativeToWindow(e.GetPosition(this)), EventType.Released);
_mouseDown = false;
_draggingWindow = false;
}
Expand Down Expand Up @@ -148,7 +156,7 @@ private void HostWindow_PositionChanged(object? sender, PixelPointEventArgs e)
if (_mouseDown)
{
Window.Factory?.OnWindowMoveDrag(Window);
_hostWindowState.Process(Position.ToPoint(1.0), EventType.Moved);
_hostWindowState.Process(Position, EventType.Moved);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Dock.Avalonia/Internal/HostWindowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace Dock.Avalonia.Internal;

internal class WindowDragState
{
public Point DragStartPoint { get; set; }
public PixelPoint DragStartPoint { get; set; }
public bool PointerPressed { get; set; }
public bool DoDragDrop { get; set; }
public DockControl? TargetDockControl { get; set; }
public Point TargetPoint { get; set; }
public Control? TargetDropControl { get; set; }
public DragAction DragAction { get; set; }

public void Start(Point point)
public void Start(PixelPoint point)
{
DragStartPoint = point;
PointerPressed = true;
Expand Down Expand Up @@ -162,7 +162,7 @@ private void Execute(Point point, DockOperation operation, DragAction dragAction
}
}

private bool IsMinimumDragDistance(Vector diff)
private bool IsMinimumDragDistance(PixelPoint diff)
{
return (Math.Abs(diff.X) > DockSettings.MinimumHorizontalDragDistance
|| Math.Abs(diff.Y) > DockSettings.MinimumVerticalDragDistance);
Expand All @@ -173,7 +173,7 @@ private bool IsMinimumDragDistance(Vector diff)
/// </summary>
/// <param name="point">The pointer position.</param>
/// <param name="eventType">The pointer event type.</param>
public void Process(Point point, EventType eventType)
public void Process(PixelPoint point, EventType eventType)
{
switch (eventType)
{
Expand Down Expand Up @@ -219,7 +219,7 @@ public void Process(Point point, EventType eventType)

if (_state.DoDragDrop == false)
{
Vector diff = _state.DragStartPoint - point;
var diff = _state.DragStartPoint - point;
var haveMinimumDragDistance = IsMinimumDragDistance(diff);
if (haveMinimumDragDistance)
{
Expand Down

0 comments on commit ee9921b

Please sign in to comment.