Implement PointToClient for MacOS.

This commit is contained in:
kanato 2009-05-11 01:10:09 +00:00
parent 768528ca81
commit 5817a46f65
3 changed files with 52 additions and 24 deletions

View file

@ -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";

View file

@ -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);
point.X = (int)native_point.X;
point.Y = (int)native_point.Y;
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
Console.WriteLine("Rect: {0}", r);
return point;
return new System.Drawing.Point(point.X - r.X, point.Y - r.Y);
}
public System.Drawing.Point PointToScreen(System.Drawing.Point point)
{

View file

@ -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;
}