Browse Source

implement setting of window position.

pull/1977/head
Dan Walmsley 8 years ago
parent
commit
1d6ba00150
  1. 32
      src/Avalonia.Native.OSX/window.mm
  2. 8
      src/Avalonia.Native/Avalonia.Native.csproj
  3. 18
      src/Avalonia.Native/Helpers.cs
  4. 12
      src/Avalonia.Native/WindowImplBase.cs
  5. 2
      src/headers/avalonia-native.h

32
src/Avalonia.Native.OSX/window.mm

@ -83,6 +83,38 @@ public:
[Window performWindowDragWithEvent:lastEvent];
}
virtual AvnPoint GetPosition ()
{
auto frame = [Window frame];
AvnPoint bottomLeft;
bottomLeft.X = frame.origin.x;
bottomLeft.Y = frame.origin.y + frame.size.width;
NSRect screen = [NSScreen.screens objectAtIndex:0].frame;
auto t = MAX(screen.origin.y, screen.origin.y + screen.size.height);
bottomLeft.Y = t - bottomLeft.Y;
return bottomLeft;
}
virtual void SetPosition (AvnPoint point)
{
NSPoint nspoint;
nspoint.x = point.X;
nspoint.y = point.Y;
NSRect screen = [NSScreen.screens objectAtIndex:0].frame;
auto t = MAX(screen.origin.y, screen.origin.y + screen.size.height);
nspoint.y = t - nspoint.y;
[Window setFrameTopLeftPoint:nspoint];
}
protected:
virtual NSWindowStyleMask GetStyle()
{

8
src/Avalonia.Native/Avalonia.Native.csproj

@ -12,4 +12,12 @@
<PackageReference Include="Avalonia" Version="0.6.2-build6248-beta" />
<SharpGenMapping Include="Mappings.xml" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Generated\LocalInterop.cs" />
<Compile Remove="Generated\Structures.cs" />
<Compile Remove="Generated\Functions.cs" />
<Compile Remove="Generated\Interfaces.cs" />
<Compile Remove="Generated\LocalInterop.cs" />
<Compile Remove="Generated\Structures.cs" />
</ItemGroup>
</Project>

18
src/Avalonia.Native/Helpers.cs

@ -0,0 +1,18 @@
using System;
using Avalonia.Native.Interop;
namespace Avalonia.Native
{
public static class Helpers
{
public static Point ToAvaloniaPoint (this AvnPoint pt)
{
return new Point(pt.X, pt.Y);
}
public static AvnPoint ToAvnPoint (this Point pt)
{
return new AvnPoint { X = pt.X, Y = pt.Y };
}
}
}

12
src/Avalonia.Native/WindowImplBase.cs

@ -118,11 +118,11 @@ namespace Avalonia.Native
switch (type)
{
case AvnRawMouseEventType.Wheel:
Input?.Invoke(new RawMouseWheelEventArgs(_mouse, timeStamp, _inputRoot, new Point(point.X, point.Y), new Vector(delta.X, delta.Y), (InputModifiers)modifiers));
Input?.Invoke(new RawMouseWheelEventArgs(_mouse, timeStamp, _inputRoot, point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (InputModifiers)modifiers));
break;
default:
Input?.Invoke(new RawMouseEventArgs(_mouse, timeStamp, _inputRoot, (RawMouseEventType)type, new Point(point.X, point.Y), (InputModifiers)modifiers));
Input?.Invoke(new RawMouseEventArgs(_mouse, timeStamp, _inputRoot, (RawMouseEventType)type, point.ToAvaloniaPoint(), (InputModifiers)modifiers));
break;
}
}
@ -164,10 +164,16 @@ namespace Avalonia.Native
}
public Point Position
{
get => _native.GetPosition().ToAvaloniaPoint();
set => _native.SetPosition(value.ToAvnPoint());
}
#region Stubs
public double Scaling => 1;
public Point Position { get; set; }
public Action<Point> PositionChanged { get; set; }
public Action Deactivated { get; set; }
public Action Activated { get; set; }

2
src/headers/avalonia-native.h

@ -73,6 +73,8 @@ AVNCOM(IAvnWindowBase, 02) : virtual IUnknown
virtual HRESULT Resize(double width, double height) = 0;
virtual void Invalidate (AvnRect rect) = 0;
virtual void BeginMoveDrag () = 0;
virtual AvnPoint GetPosition () = 0;
virtual void SetPosition (AvnPoint point) = 0;
};
AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase

Loading…
Cancel
Save