Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mixed screen/client position usage #328

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading