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
|
|
|
|
|
|
|
|
|
private static List<Delegate> _registeredDelegates = new();
|
|
|
|
|
|
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-03-12 23:17:49 +01:00
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
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();
|
2023-07-15 14:29:14 +02:00
|
|
|
|
|
2024-03-12 23:17:49 +01:00
|
|
|
|
if (buffer.Length == 0 || buffer[0] == '\x00')
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
_registeredDelegates.Add(new DrawContentDelegate(function));
|
|
|
|
|
registerViewV1(
|
|
|
|
|
icon,
|
|
|
|
|
Encoding.UTF8.GetBytes(name),
|
|
|
|
|
Marshal.GetFunctionPointerForDelegate(_registeredDelegates[^1])
|
|
|
|
|
);
|
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)
|
|
|
|
|
{
|
|
|
|
|
_registeredDelegates.Add(new ActionDelegate(function));
|
|
|
|
|
addMenuItemV1(
|
|
|
|
|
icon,
|
|
|
|
|
Encoding.UTF8.GetBytes(menuName),
|
|
|
|
|
Encoding.UTF8.GetBytes(itemName),
|
|
|
|
|
Marshal.GetFunctionPointerForDelegate(_registeredDelegates[^1])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-15 14:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|