2024-03-12 23:17:49 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2023-07-15 14:29:14 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace ImHex
|
|
|
|
|
{
|
2024-03-12 23:17:49 +01:00
|
|
|
|
public partial class UI
|
2023-07-15 14:29:14 +02:00
|
|
|
|
{
|
2024-03-11 21:09:45 +01:00
|
|
|
|
private delegate void DrawContentDelegate();
|
2024-03-13 19:50:05 +01:00
|
|
|
|
private delegate void ActionDelegate();
|
2024-03-11 21:09:45 +01:00
|
|
|
|
|
2024-05-17 20:24:28 +02:00
|
|
|
|
private static readonly List<Delegate> RegisteredDelegates = new();
|
2024-03-11 21:09:45 +01:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static partial void showMessageBoxV1(byte[] message);
|
2023-07-15 14:29:14 +02:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static unsafe partial void showInputTextBoxV1(byte[] title, byte[] message, IntPtr buffer, int bufferSize);
|
2023-07-15 14:29:14 +02:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static unsafe partial void showYesNoQuestionBoxV1(byte[] title, byte[] message, bool* result);
|
2024-03-11 21:09:45 +01:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static partial void showToastV1(byte[] message, UInt32 type);
|
2024-03-11 21:09:45 +01:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static partial IntPtr getImGuiContextV1();
|
2024-03-11 21:09:45 +01:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static partial void registerViewV1(byte[] icon, byte[] name, IntPtr drawFunction);
|
2023-07-15 14:29:14 +02:00
|
|
|
|
|
2024-03-13 19:50:05 +01:00
|
|
|
|
[LibraryImport("ImHex")]
|
|
|
|
|
private static partial void addMenuItemV1(byte[] icon, byte[] menuName, byte[] itemName, IntPtr drawFunction);
|
|
|
|
|
|
2023-07-15 14:29:14 +02:00
|
|
|
|
public static void ShowMessageBox(string message)
|
|
|
|
|
{
|
2024-03-11 21:09:45 +01:00
|
|
|
|
showMessageBoxV1(Encoding.UTF8.GetBytes(message));
|
2023-07-15 14:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ShowYesNoQuestionBox(string title, string message)
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
2024-03-11 21:09:45 +01:00
|
|
|
|
showYesNoQuestionBoxV1(Encoding.UTF8.GetBytes(title), Encoding.UTF8.GetBytes(message), &result);
|
2023-07-15 14:29:14 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string? ShowInputTextBox(string title, string message, int maxSize)
|
|
|
|
|
{
|
2024-05-17 20:24:28 +02:00
|
|
|
|
var buffer = new byte[maxSize];
|
|
|
|
|
GCHandle pinnedArray = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
|
|
|
|
showInputTextBoxV1(Encoding.UTF8.GetBytes(title), Encoding.UTF8.GetBytes(message), pinnedArray.AddrOfPinnedObject(), maxSize);
|
|
|
|
|
pinnedArray.Free();
|
|
|
|
|
|
|
|
|
|
if (buffer.Length == 0 || buffer[0] == '\x00')
|
2024-03-12 23:17:49 +01:00
|
|
|
|
{
|
2024-05-17 20:24:28 +02:00
|
|
|
|
return null;
|
2024-03-12 23:17:49 +01:00
|
|
|
|
}
|
2024-05-17 20:24:28 +02:00
|
|
|
|
|
|
|
|
|
return Encoding.UTF8.GetString(buffer);
|
2024-03-11 21:09:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ToastType
|
|
|
|
|
{
|
|
|
|
|
Info = 0,
|
|
|
|
|
Warning = 1,
|
|
|
|
|
Error = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ShowToast(string message, ToastType type = ToastType.Info)
|
|
|
|
|
{
|
|
|
|
|
showToastV1(Encoding.UTF8.GetBytes(message), (UInt32)type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IntPtr GetImGuiContext()
|
|
|
|
|
{
|
|
|
|
|
return getImGuiContextV1();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RegisterView(byte[] icon, string name, Action function)
|
|
|
|
|
{
|
2024-05-17 20:24:28 +02:00
|
|
|
|
RegisteredDelegates.Add(new DrawContentDelegate(function));
|
2024-03-11 21:09:45 +01:00
|
|
|
|
registerViewV1(
|
|
|
|
|
icon,
|
|
|
|
|
Encoding.UTF8.GetBytes(name),
|
2024-05-17 20:24:28 +02:00
|
|
|
|
Marshal.GetFunctionPointerForDelegate(RegisteredDelegates[^1])
|
2024-03-11 21:09:45 +01:00
|
|
|
|
);
|
2023-07-15 14:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 19:50:05 +01:00
|
|
|
|
public static void AddMenuItem(byte[] icon, string menuName, string itemName, Action function)
|
|
|
|
|
{
|
2024-05-17 20:24:28 +02:00
|
|
|
|
RegisteredDelegates.Add(new ActionDelegate(function));
|
2024-03-13 19:50:05 +01:00
|
|
|
|
addMenuItemV1(
|
|
|
|
|
icon,
|
|
|
|
|
Encoding.UTF8.GetBytes(menuName),
|
|
|
|
|
Encoding.UTF8.GetBytes(itemName),
|
2024-05-17 20:24:28 +02:00
|
|
|
|
Marshal.GetFunctionPointerForDelegate(RegisteredDelegates[^1])
|
2024-03-13 19:50:05 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-15 14:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|