feat: Added option to create menu items from scripts
This commit is contained in:
parent
458584d778
commit
e786cb8180
@ -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));
|
||||
}
|
@ -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])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user