-#region License
+#region License
//
// CocoaNativeWindow.cs
//
namespace OpenTK.Platform.MacOS
{
- class CocoaNativeWindow : INativeWindow
+ class CocoaNativeWindow : NativeWindowBase
{
static int UniqueId;
- public event EventHandler<EventArgs> Move = delegate { };
- public event EventHandler<EventArgs> Resize = delegate { };
- public event EventHandler<System.ComponentModel.CancelEventArgs> Closing = delegate { };
- public event EventHandler<EventArgs> Closed = delegate { };
- public event EventHandler<EventArgs> Disposed = delegate { };
- public event EventHandler<EventArgs> IconChanged = delegate { };
- public event EventHandler<EventArgs> TitleChanged = delegate { };
- public event EventHandler<EventArgs> VisibleChanged = delegate { };
- public event EventHandler<EventArgs> FocusedChanged = delegate { };
- public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
- public event EventHandler<EventArgs> WindowStateChanged = delegate { };
- public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyDown = delegate { };
- public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
- public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyUp = delegate { };
- public event EventHandler<EventArgs> MouseLeave = delegate { };
- public event EventHandler<EventArgs> MouseEnter = delegate { };
-
static readonly IntPtr selNextEventMatchingMask = Selector.Get("nextEventMatchingMask:untilDate:inMode:dequeue:");
static readonly IntPtr selSendEvent = Selector.Get("sendEvent:");
//static readonly IntPtr selUpdateWindows = Selector.Get("updateWindows");
static readonly IntPtr selHide = Selector.Get("hide");
static readonly IntPtr selUnhide = Selector.Get("unhide");
static readonly IntPtr selScrollingDeltaY = Selector.Get("scrollingDeltaY");
+ static readonly IntPtr selDeltaX = Selector.Get("deltaX");
+ static readonly IntPtr selDeltaY = Selector.Get("deltaY");
static readonly IntPtr selButtonNumber = Selector.Get("buttonNumber");
static readonly IntPtr selSetStyleMask = Selector.Get("setStyleMask:");
static readonly IntPtr selStyleMask = Selector.Get("styleMask");
private bool exists;
private bool cursorVisible = true;
private System.Drawing.Icon icon;
- private LegacyInputDriver inputDriver = new LegacyInputDriver();
private WindowBorder windowBorder = WindowBorder.Resizable;
private Nullable<WindowBorder> deferredWindowBorder;
private Nullable<WindowBorder> previousWindowBorder;
Cocoa.SendVoid(owner, selAddTrackingArea, trackingArea);
}
- public void Close()
+ public override void Close()
{
shouldClose = true;
}
return (MouseButton)cocoaButtonIndex;
}
- public void ProcessEvents()
+ public override void ProcessEvents()
{
while (true)
{
case NSEventType.OtherMouseDragged:
case NSEventType.MouseMoved:
{
- var pf = Cocoa.SendPoint(e, selLocationInWindowOwner);
+ Point p = InputDriver.Mouse[0].Position;
+ if (CursorVisible)
+ {
+ // Use absolute coordinates
+ var pf = Cocoa.SendPoint(e, selLocationInWindowOwner);
- // Convert from points to pixel coordinates
- var rf = Cocoa.SendRect(windowInfo.Handle, selConvertRectToBacking,
- new RectangleF(pf.X, pf.Y, 0, 0));
+ // Convert from points to pixel coordinates
+ var rf = Cocoa.SendRect(windowInfo.Handle, selConvertRectToBacking,
+ new RectangleF(pf.X, pf.Y, 0, 0));
- // See CocoaDrawingGuide under "Converting from Window to View Coordinates"
- var p = new Point(
- MathHelper.Clamp((int)Math.Round(rf.X), 0, Width),
- MathHelper.Clamp((int)Math.Round(Height - rf.Y), 0, Height));
+ // See CocoaDrawingGuide under "Converting from Window to View Coordinates"
+ p = new Point(
+ MathHelper.Clamp((int)Math.Round(rf.X), 0, Width),
+ MathHelper.Clamp((int)Math.Round(Height - rf.Y), 0, Height));
+ }
+ else
+ {
+ // Mouse has been disassociated,
+ // use relative coordinates
+ var dx = Cocoa.SendFloat(e, selDeltaX);
+ var dy = Cocoa.SendFloat(e, selDeltaY);
+
+ p = new Point(
+ MathHelper.Clamp((int)Math.Round(p.X + dx)),
+ MathHelper.Clamp((int)Math.Round(p.Y - dy)));
+ }
InputDriver.Mouse[0].Position = p;
}
}
}
- public System.Drawing.Point PointToClient(System.Drawing.Point point)
+ public override System.Drawing.Point PointToClient(System.Drawing.Point point)
{
var r = Cocoa.SendRect(windowInfo.Handle, selConvertRectFromScreen, new RectangleF(point.X, point.Y, 0, 0));
return new Point((int)r.X, (int)(GetContentViewFrame().Height - GetCurrentScreenFrame().Height - r.Y));
}
- public System.Drawing.Point PointToScreen(System.Drawing.Point point)
+ public override System.Drawing.Point PointToScreen(System.Drawing.Point point)
{
var r = Cocoa.SendRect(windowInfo.Handle, selConvertRectToScreen, new RectangleF(point.X, point.Y, 0, 0));
return new Point((int)r.X, (int)(-GetContentViewFrame().Height + GetCurrentScreenFrame().Height - r.Y));
}
- public System.Drawing.Icon Icon
+ public override System.Drawing.Icon Icon
{
get { return icon; }
set
}
}
- public string Title
+ public override string Title
{
get
{
}
}
- public bool Focused
+ public override bool Focused
{
get
{
}
}
- public bool Visible
+ public override bool Visible
{
get
{
}
}
- public bool Exists
+ public override bool Exists
{
get
{
}
}
- public IWindowInfo WindowInfo
+ public override IWindowInfo WindowInfo
{
get
{
previousWindowBorder = null;
}
- public WindowState WindowState
+ public override WindowState WindowState
{
get
{
}
}
- public WindowBorder WindowBorder
+ public override WindowBorder WindowBorder
{
get
{
return (NSWindowStyle)0;
}
- public System.Drawing.Rectangle Bounds
+ public override System.Drawing.Rectangle Bounds
{
get
{
}
}
- public System.Drawing.Point Location
- {
- get
- {
- return Bounds.Location;
- }
- set
- {
- var b = Bounds;
- b.Location = value;
- Bounds = b;
- }
- }
-
- public System.Drawing.Size Size
+ public override System.Drawing.Size ClientSize
{
get
- {
- return Bounds.Size;
- }
- set
- {
- var b = Bounds;
- b.Y -= Bounds.Height;
- b.Y += value.Height;
- b.Size = value;
- Bounds = b;
- }
- }
-
- public int X
- {
- get
- {
- return Bounds.X;
- }
- set
- {
- var b = Bounds;
- b.X = value;
- Bounds = b;
- }
- }
-
- public int Y
- {
- get
- {
- return Bounds.Y;
- }
- set
- {
- var b = Bounds;
- b.Y = value;
- Bounds = b;
- }
- }
-
- public int Width
- {
- get { return ClientRectangle.Width; }
- set
- {
- var s = ClientSize;
- s.Width = value;
- ClientSize = s;
- }
- }
-
- public int Height
- {
- get { return ClientRectangle.Height; }
- set
- {
- var s = ClientSize;
- s.Height = value;
- ClientSize = s;
- }
- }
-
- public System.Drawing.Rectangle ClientRectangle
- {
- get
{
var contentViewBounds = Cocoa.SendRect(windowInfo.ViewHandle, selBounds);
var bounds = Cocoa.SendRect(windowInfo.Handle, selConvertRectToBacking, contentViewBounds);
- return new Rectangle((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height);
- }
- set
- {
- ClientSize = value.Size; // Just set size, to be consistent with WinGLNative.
- }
- }
-
- public System.Drawing.Size ClientSize
- {
- get
- {
- return ClientRectangle.Size;
+ return new Size(0, 0, (int)bounds.Width, (int)bounds.Height);
}
set
{
}
}
- public OpenTK.Input.IInputDriver InputDriver
- {
- get
- {
- return inputDriver;
- }
- }
-
public MouseCursor Cursor
{
get
}
}
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
+ protected override void Dispose(bool disposing)
{
if (disposed)
return;
Disposed(this, EventArgs.Empty);
}
- ~CocoaNativeWindow()
+ public static IntPtr GetView(IntPtr windowHandle)
{
- Dispose(false);
+ return Cocoa.SendIntPtr(windowHandle, selContentView);
}
private RectangleF GetContentViewFrame()