mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 01:45:37 +00:00
Implement PointToClient for MacOS.
This commit is contained in:
parent
768528ca81
commit
5817a46f65
|
@ -383,6 +383,14 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
|
||||
#endregion
|
||||
|
||||
enum HICoordinateSpace
|
||||
{
|
||||
_72DPIGlobal = 1,
|
||||
ScreenPixel = 2,
|
||||
Window = 3,
|
||||
View = 4
|
||||
};
|
||||
|
||||
#region --- Carbon API Methods ---
|
||||
|
||||
public partial class API
|
||||
|
@ -883,27 +891,52 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
internal unsafe static extern OSStatus DMGetGDeviceByDisplayID(
|
||||
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
||||
|
||||
[DllImport(carbon, EntryPoint = "HIViewConvertPoint")]
|
||||
extern static OSStatus _HIViewConvertPoint(ref HIPoint point, IntPtr pView, IntPtr cView);
|
||||
#region Nonworking HIPointConvert routines
|
||||
|
||||
internal static HIPoint HIViewConvertPoint(IntPtr handle, HIPoint point)
|
||||
{
|
||||
Carbon.Rect window_bounds = new Carbon.Rect();
|
||||
Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds);
|
||||
// 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.
|
||||
|
||||
point.X -= window_bounds.X;
|
||||
point.Y -= window_bounds.Y;
|
||||
//[DllImport(carbon, EntryPoint="HIPointConvert")]
|
||||
//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)
|
||||
{
|
||||
throw new MacOSException(error);
|
||||
}
|
||||
// if (error != OSStatus.NoError)
|
||||
// {
|
||||
// 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";
|
||||
|
||||
|
|
|
@ -600,15 +600,10 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
IntPtr handle = window.WindowRef;
|
||||
|
||||
HIPoint native_point = new HIPoint();
|
||||
native_point.X = (float)point.X;
|
||||
native_point.Y = (float)point.Y;
|
||||
native_point = Carbon.API.HIViewConvertPoint(handle, native_point);
|
||||
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
||||
Console.WriteLine("Rect: {0}", r);
|
||||
|
||||
point.X = (int)native_point.X;
|
||||
point.Y = (int)native_point.Y;
|
||||
|
||||
return point;
|
||||
return new System.Drawing.Point(point.X - r.X, point.Y - r.Y);
|
||||
}
|
||||
public System.Drawing.Point PointToScreen(System.Drawing.Point point)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace OpenTK.Platform.MacOS
|
|||
public MacOSException()
|
||||
{}
|
||||
public MacOSException(OSStatus errorCode)
|
||||
: base("Error Code: " + errorCode.ToString())
|
||||
: base("Error Code " + ((int)errorCode).ToString() + ": " + errorCode.ToString())
|
||||
{
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue