2023-02-09 03:08:15 +00:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
2024-02-11 02:09:18 +00:00
|
|
|
namespace Ryujinx.UI.Common.Helper
|
2023-02-09 03:08:15 +00:00
|
|
|
{
|
|
|
|
[SupportedOSPlatform("macos")]
|
|
|
|
public static partial class ObjectiveC
|
|
|
|
{
|
|
|
|
private const string ObjCRuntime = "/usr/lib/libobjc.A.dylib";
|
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial IntPtr sel_getUid(string name);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial IntPtr objc_getClass(string name);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial void objc_msgSend(IntPtr receiver, Selector selector);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial void objc_msgSend(IntPtr receiver, Selector selector, byte value);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial void objc_msgSend(IntPtr receiver, Selector selector, NSRect point);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial void objc_msgSend(IntPtr receiver, Selector selector, double value);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend", StringMarshalling = StringMarshalling.Utf8)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, string param);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
|
|
|
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
2023-06-29 00:39:22 +00:00
|
|
|
private static partial bool bool_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param);
|
2023-02-09 03:08:15 +00:00
|
|
|
|
2023-06-29 00:39:22 +00:00
|
|
|
public readonly struct Object
|
|
|
|
{
|
|
|
|
public readonly IntPtr ObjPtr;
|
|
|
|
|
|
|
|
private Object(IntPtr pointer)
|
|
|
|
{
|
|
|
|
ObjPtr = pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object(string name)
|
|
|
|
{
|
|
|
|
ObjPtr = objc_getClass(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendMessage(Selector selector)
|
|
|
|
{
|
|
|
|
objc_msgSend(ObjPtr, selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendMessage(Selector selector, byte value)
|
|
|
|
{
|
|
|
|
objc_msgSend(ObjPtr, selector, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendMessage(Selector selector, Object obj)
|
|
|
|
{
|
|
|
|
objc_msgSend(ObjPtr, selector, obj.ObjPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendMessage(Selector selector, NSRect point)
|
|
|
|
{
|
|
|
|
objc_msgSend(ObjPtr, selector, point);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendMessage(Selector selector, double value)
|
|
|
|
{
|
|
|
|
objc_msgSend(ObjPtr, selector, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object GetFromMessage(Selector selector)
|
|
|
|
{
|
|
|
|
return new Object(IntPtr_objc_msgSend(ObjPtr, selector));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object GetFromMessage(Selector selector, Object obj)
|
|
|
|
{
|
|
|
|
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, obj.ObjPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object GetFromMessage(Selector selector, NSString nsString)
|
|
|
|
{
|
|
|
|
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, nsString.StrPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object GetFromMessage(Selector selector, string param)
|
|
|
|
{
|
|
|
|
return new Object(IntPtr_objc_msgSend(ObjPtr, selector, param));
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetBoolFromMessage(Selector selector, Object obj)
|
|
|
|
{
|
|
|
|
return bool_objc_msgSend(ObjPtr, selector, obj.ObjPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public readonly struct Selector
|
2023-02-09 03:08:15 +00:00
|
|
|
{
|
|
|
|
public readonly IntPtr SelPtr;
|
|
|
|
|
2023-06-29 00:39:22 +00:00
|
|
|
private Selector(string name)
|
2023-02-09 03:08:15 +00:00
|
|
|
{
|
|
|
|
SelPtr = sel_getUid(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator Selector(string value) => new(value);
|
|
|
|
}
|
|
|
|
|
2023-06-29 00:39:22 +00:00
|
|
|
public readonly struct NSString
|
2023-02-09 03:08:15 +00:00
|
|
|
{
|
|
|
|
public readonly IntPtr StrPtr;
|
|
|
|
|
|
|
|
public NSString(string aString)
|
|
|
|
{
|
|
|
|
IntPtr nsString = objc_getClass("NSString");
|
|
|
|
StrPtr = IntPtr_objc_msgSend(nsString, "stringWithUTF8String:", aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator IntPtr(NSString nsString) => nsString.StrPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readonly struct NSPoint
|
|
|
|
{
|
|
|
|
public readonly double X;
|
|
|
|
public readonly double Y;
|
|
|
|
|
|
|
|
public NSPoint(double x, double y)
|
|
|
|
{
|
|
|
|
X = x;
|
|
|
|
Y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public readonly struct NSRect
|
|
|
|
{
|
|
|
|
public readonly NSPoint Pos;
|
|
|
|
public readonly NSPoint Size;
|
|
|
|
|
|
|
|
public NSRect(double x, double y, double width, double height)
|
|
|
|
{
|
|
|
|
Pos = new NSPoint(x, y);
|
|
|
|
Size = new NSPoint(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 00:39:22 +00:00
|
|
|
}
|