1
0
mirror of synced 2025-01-18 00:56:49 +01:00

feat: Added option to create menu items from scripts

This commit is contained in:
WerWolv 2024-03-13 19:50:05 +01:00
parent 458584d778
commit e786cb8180
2 changed files with 20 additions and 0 deletions

View File

@ -179,4 +179,9 @@ private:
SCRIPT_API(void registerView, const char *icon, const char *name, void *drawFunction) {
ContentRegistry::Views::add<ScriptView>(icon, name, ScriptView::DrawFunction(drawFunction));
}
SCRIPT_API(void addMenuItem, const char *icon, const char *menuName, const char *itemName, void *function) {
using MenuFunction = void(*)();
ContentRegistry::Interface::addMenuItem({ menuName, itemName }, icon, 9999, Shortcut::None, reinterpret_cast<MenuFunction>(function));
}

View File

@ -6,6 +6,7 @@ namespace ImHex
public partial class UI
{
private delegate void DrawContentDelegate();
private delegate void ActionDelegate();
private static List<Delegate> _registeredDelegates = new();
@ -27,6 +28,9 @@ namespace ImHex
[LibraryImport("ImHex")]
private static partial void registerViewV1(byte[] icon, byte[] name, IntPtr drawFunction);
[LibraryImport("ImHex")]
private static partial void addMenuItemV1(byte[] icon, byte[] menuName, byte[] itemName, IntPtr drawFunction);
public static void ShowMessageBox(string message)
{
showMessageBoxV1(Encoding.UTF8.GetBytes(message));
@ -89,5 +93,16 @@ namespace ImHex
);
}
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])
);
}
}
}