Browse Source

[MONOMAC] Fixed retina support

pull/1005/head
Nikita Tsukanov 10 years ago
parent
commit
f7011a3fd2
  1. 16
      src/OSX/Avalonia.MonoMac/EmulatedFramebuffer.cs

16
src/OSX/Avalonia.MonoMac/EmulatedFramebuffer.cs

@ -8,15 +8,15 @@ namespace Avalonia.MonoMac
{ {
class EmulatedFramebuffer : ILockedFramebuffer class EmulatedFramebuffer : ILockedFramebuffer
{ {
private readonly CGSize _logicalSize;
public EmulatedFramebuffer(NSView view) public EmulatedFramebuffer(NSView view)
{ {
//TODO: Check if this is correct _logicalSize = view.Frame.Size;
var factor = view.Window.UserSpaceScaleFactor; var pixelSize = view.ConvertSizeToBacking(_logicalSize);
var frame = view.Frame; Width = (int)pixelSize.Width;
Width = (int) (frame.Width * factor); Height = (int)pixelSize.Height;
Height = (int) (frame.Height * factor);
RowBytes = Width * 4; RowBytes = Width * 4;
Dpi = new Size(96, 96) * factor; Dpi = new Size(96 * pixelSize.Width / _logicalSize.Width, 96 * pixelSize.Height / _logicalSize.Height);
Format = PixelFormat.Rgba8888; Format = PixelFormat.Rgba8888;
Address = Marshal.AllocHGlobal(Height * RowBytes); Address = Marshal.AllocHGlobal(Height * RowBytes);
} }
@ -35,8 +35,8 @@ namespace Avalonia.MonoMac
using (var context = nscontext.GraphicsPort) using (var context = nscontext.GraphicsPort)
{ {
context.SetFillColor(255, 255, 255, 255); context.SetFillColor(255, 255, 255, 255);
context.FillRect(new CGRect(0, 0, Width, Height)); context.FillRect(new CGRect(default(CGPoint), _logicalSize));
context.DrawImage(new CGRect(0, 0, Width, Height), image); context.DrawImage(new CGRect(default(CGPoint), _logicalSize), image);
} }
Marshal.FreeHGlobal(Address); Marshal.FreeHGlobal(Address);
Address = IntPtr.Zero; Address = IntPtr.Zero;

Loading…
Cancel
Save