mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-26 03:11:11 +00:00
Implement PointToClient for MacOS.
This commit is contained in:
parent
043421c7bc
commit
721e45a5d4
|
@ -383,6 +383,14 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
enum HICoordinateSpace
|
||||||
|
{
|
||||||
|
_72DPIGlobal = 1,
|
||||||
|
ScreenPixel = 2,
|
||||||
|
Window = 3,
|
||||||
|
View = 4
|
||||||
|
};
|
||||||
|
|
||||||
#region --- Carbon API Methods ---
|
#region --- Carbon API Methods ---
|
||||||
|
|
||||||
public partial class API
|
public partial class API
|
||||||
|
@ -883,27 +891,52 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
internal unsafe static extern OSStatus DMGetGDeviceByDisplayID(
|
internal unsafe static extern OSStatus DMGetGDeviceByDisplayID(
|
||||||
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
||||||
|
|
||||||
[DllImport(carbon, EntryPoint = "HIViewConvertPoint")]
|
#region Nonworking HIPointConvert routines
|
||||||
extern static OSStatus _HIViewConvertPoint(ref HIPoint point, IntPtr pView, IntPtr cView);
|
|
||||||
|
|
||||||
internal static HIPoint HIViewConvertPoint(IntPtr handle, HIPoint point)
|
// These seem to crash when called, and I haven't figured out why.
|
||||||
{
|
// Currently a workaround is used to convert from screen to client coordinates.
|
||||||
Carbon.Rect window_bounds = new Carbon.Rect();
|
|
||||||
Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds);
|
|
||||||
|
|
||||||
point.X -= window_bounds.X;
|
//[DllImport(carbon, EntryPoint="HIPointConvert")]
|
||||||
point.Y -= window_bounds.Y;
|
//extern static OSStatus _HIPointConvert(ref HIPoint ioPoint,
|
||||||
|
// HICoordinateSpace inSourceSpace, IntPtr inSourceObject,
|
||||||
|
// HICoordinateSpace inDestinationSpace, IntPtr inDestinationObject);
|
||||||
|
|
||||||
OSStatus error = _HIViewConvertPoint(ref point, IntPtr.Zero, handle);
|
//internal static HIPoint HIPointConvert(HIPoint inPoint,
|
||||||
|
// HICoordinateSpace inSourceSpace, IntPtr inSourceObject,
|
||||||
|
// HICoordinateSpace inDestinationSpace, IntPtr inDestinationObject)
|
||||||
|
//{
|
||||||
|
// OSStatus error = _HIPointConvert(ref inPoint, inSourceSpace, inSourceObject, inDestinationSpace, inDestinationObject);
|
||||||
|
|
||||||
if (error != OSStatus.NoError)
|
// if (error != OSStatus.NoError)
|
||||||
{
|
// {
|
||||||
throw new MacOSException(error);
|
// throw new MacOSException(error);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return point;
|
// return inPoint;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
//[DllImport(carbon, EntryPoint = "HIViewConvertPoint")]
|
||||||
|
//extern static OSStatus _HIViewConvertPoint(ref HIPoint inPoint, IntPtr inSourceView, IntPtr inDestView);
|
||||||
|
|
||||||
|
//internal static HIPoint HIViewConvertPoint( HIPoint point, IntPtr sourceHandle, IntPtr destHandle)
|
||||||
|
//{
|
||||||
|
// //Carbon.Rect window_bounds = new Carbon.Rect();
|
||||||
|
// //Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds);
|
||||||
|
|
||||||
|
// //point.X -= window_bounds.X;
|
||||||
|
// //point.Y -= window_bounds.Y;
|
||||||
|
|
||||||
|
// OSStatus error = _HIViewConvertPoint(ref point, sourceHandle, destHandle);
|
||||||
|
|
||||||
|
// if (error != OSStatus.NoError)
|
||||||
|
// {
|
||||||
|
// throw new MacOSException(error);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return point;
|
||||||
|
//}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
|
const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
|
||||||
|
|
||||||
|
|
|
@ -600,15 +600,10 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
IntPtr handle = window.WindowRef;
|
IntPtr handle = window.WindowRef;
|
||||||
|
|
||||||
HIPoint native_point = new HIPoint();
|
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
||||||
native_point.X = (float)point.X;
|
Console.WriteLine("Rect: {0}", r);
|
||||||
native_point.Y = (float)point.Y;
|
|
||||||
native_point = Carbon.API.HIViewConvertPoint(handle, native_point);
|
|
||||||
|
|
||||||
point.X = (int)native_point.X;
|
return new System.Drawing.Point(point.X - r.X, point.Y - r.Y);
|
||||||
point.Y = (int)native_point.Y;
|
|
||||||
|
|
||||||
return point;
|
|
||||||
}
|
}
|
||||||
public System.Drawing.Point PointToScreen(System.Drawing.Point point)
|
public System.Drawing.Point PointToScreen(System.Drawing.Point point)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
public MacOSException()
|
public MacOSException()
|
||||||
{}
|
{}
|
||||||
public MacOSException(OSStatus errorCode)
|
public MacOSException(OSStatus errorCode)
|
||||||
: base("Error Code: " + errorCode.ToString())
|
: base("Error Code " + ((int)errorCode).ToString() + ": " + errorCode.ToString())
|
||||||
{
|
{
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue