diff --git a/.gitmodules b/.gitmodules index 94badad0..0923cb14 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "include/imgui-node-editor"] path = include/imgui-node-editor url = https://github.com/thedmd/imgui-node-editor +[submodule "include/imgui_club"] + path = include/imgui_club + url = https://github.com/ocornut/imgui_club diff --git a/README.md b/README.md index a8fb2191..a801b772 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,8 @@ If using Java 9 modules, imgui-java has Automatic Module Names: Syntax highlighting text editor for ImGui. - [ImGuiFileDialog](https://github.com/aiekick/ImGuiFileDialog/tree/4d42dfba125cbd4780a90fbc5f75e7dfbae64060) | [Example](https://github.com/SpaiR/imgui-java/blob/v1.86.1/example/src/main/java/ExampleImGuiFileDialog.java)
A file selection dialog built for ImGui. +- [ImGui Club MemoryEditor](https://github.com/ocornut/imgui_club/tree/d4cd9896e15a03e92702a578586c3f91bbde01e8) | [Example](https://github.com/SpaiR/imgui-java/blob/master/example/src/main/java/ExampleImGuiMemoryEditor.java)
+ Memory editor and viewer for ImGui. ## Freetype By default, Dear ImGui uses stb-truetype to render fonts. Yet there is an option to use FreeType font renderer. Go to the [imgui_freetype](https://github.com/ocornut/imgui/tree/256594575d95d56dda616c544c509740e74906b4/misc/freetype) to read about the difference. diff --git a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy index bce85209..bb2d3234 100644 --- a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy +++ b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy @@ -49,7 +49,7 @@ class GenerateLibs extends DefaultTask { project.copy { CopySpec spec -> ['include/imgui', 'include/imnodes', 'include/imgui-node-editor', 'include/imguizmo', 'include/implot', 'include/ImGuiColorTextEdit', - 'include/ImGuiFileDialog'].each { + 'include/ImGuiFileDialog', 'include/imgui_club/imgui_memory_editor'].each { spec.from(project.rootProject.file(it)) { CopySpec s -> s.include('*.h', '*.cpp', '*.inl') } } spec.from(project.rootProject.file('imgui-binding/src/main/native')) diff --git a/example/src/main/java/ExampleImGuiMemoryEditor.java b/example/src/main/java/ExampleImGuiMemoryEditor.java new file mode 100644 index 00000000..a90b010a --- /dev/null +++ b/example/src/main/java/ExampleImGuiMemoryEditor.java @@ -0,0 +1,48 @@ +import imgui.extension.memedit.MemoryEditor; +import imgui.flag.ImGuiCond; +import imgui.internal.ImGui; +import imgui.type.ImBoolean; +import org.lwjgl.system.MemoryUtil; + +import java.awt.*; +import java.net.URI; +import java.nio.ByteBuffer; + +public class ExampleImGuiMemoryEditor { + private static final String URL = "https://github.com/ocornut/imgui_club"; + private static ByteBuffer demoData; + private static MemoryEditor memoryEditor; + private static ImBoolean showingMemoryEditor = new ImBoolean(false); + + static { + demoData = MemoryUtil.memASCII("Welcome to the demo for Dear ImGui Memory Editor." + + "\n The git repo is located at " + URL + "." + + "You can use this memory editor to view the raw memory values at some pointer location."); + + memoryEditor = new MemoryEditor(); + } + + public static void show(ImBoolean showImGuiMemoryEditor) { + ImGui.setNextWindowSize(400, 200, ImGuiCond.Once); + ImGui.setNextWindowPos(ImGui.getMainViewport().getPosX() + 100, ImGui.getMainViewport().getPosY() + 100, ImGuiCond.Once); + if (ImGui.begin("ImGuiMemoryEditor Demo", showImGuiMemoryEditor)) { + ImGui.text("This a demo for ImGui MemoryEditor"); + + ImGui.alignTextToFramePadding(); + ImGui.text("Repo:"); + ImGui.sameLine(); + if (ImGui.button(URL)) { + try { + Desktop.getDesktop().browse(new URI(URL)); + } catch (Exception e) { + e.printStackTrace(); + } + } + ImGui.checkbox("Memory Editor", showingMemoryEditor); + if (showingMemoryEditor.get()) { + memoryEditor.drawWindow("Example Data", MemoryUtil.memAddress(demoData), demoData.capacity()); + } + } + ImGui.end(); + } +} diff --git a/example/src/main/java/Extra.java b/example/src/main/java/Extra.java index 3953f128..03d5c399 100644 --- a/example/src/main/java/Extra.java +++ b/example/src/main/java/Extra.java @@ -11,6 +11,7 @@ public class Extra { private static final ImBoolean SHOW_IMGUIZMO_DEMO = new ImBoolean(false); private static final ImBoolean SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW = new ImBoolean(false); private static final ImBoolean SHOW_IMGUI_FILE_DIALOG_WINDOW = new ImBoolean(false); + private static final ImBoolean SHOW_IMGUI_MEMORY_EDITOR_WINDOW = new ImBoolean(false); private static final Graph GRAPH = new Graph(); @@ -24,6 +25,7 @@ public static void show(final Application app) { ImGui.checkbox("Show ImGuizmo Demo Window", SHOW_IMGUIZMO_DEMO); ImGui.checkbox("Show ImGuiColorTextEdit Demo Window", SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW); ImGui.checkbox("Show ImGuiFileDialog Demo Window", SHOW_IMGUI_FILE_DIALOG_WINDOW); + ImGui.checkbox("Show ImGui MemoryEditor Demo Window", SHOW_IMGUI_MEMORY_EDITOR_WINDOW); if (SHOW_DEMO_WINDOW.get()) { ImGui.showDemoWindow(SHOW_DEMO_WINDOW); @@ -56,5 +58,9 @@ public static void show(final Application app) { if (SHOW_IMGUI_FILE_DIALOG_WINDOW.get()) { ExampleImGuiFileDialog.show(SHOW_IMGUI_FILE_DIALOG_WINDOW); } + + if (SHOW_IMGUI_MEMORY_EDITOR_WINDOW.get()) { + ExampleImGuiMemoryEditor.show(SHOW_IMGUI_MEMORY_EDITOR_WINDOW); + } } } diff --git a/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditor.java b/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditor.java new file mode 100644 index 00000000..793b56de --- /dev/null +++ b/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditor.java @@ -0,0 +1,77 @@ +package imgui.extension.memedit; + +import imgui.binding.ImGuiStructDestroyable; + +/** + * ImGui Club Memory Editor extension for ImGui + * Repo: https://github.com/ocornut/imgui_club + */ +public final class MemoryEditor extends ImGuiStructDestroyable { + + /*JNI + #include "_memedit.h" + + #define MEMORY_EDITOR ((MemoryEditor*)STRUCT_PTR) + */ + + public MemoryEditor() { + + } + + public MemoryEditor(final long ptr) { + super(ptr); + } + + @Override + protected long create() { + return nCreate(); + } + + private native long nCreate(); /* + return (intptr_t)(new MemoryEditor()); + */ + + public native void gotoAddrAndHighlight(long addrMin, long addrMax); /* + MEMORY_EDITOR->GotoAddrAndHighlight(addrMin, addrMax); + */ + + public void calcSizes(final MemoryEditorSizes s, final long memSize, final long baseDisplayAddr) { + nCalcSizes(s.ptr, memSize, baseDisplayAddr); + } + + public native void nCalcSizes(long ptr, long memSize, long baseDisplayAddr); /* + MEMORY_EDITOR->CalcSizes(*((MemoryEditor::Sizes*)ptr), static_cast(memSize), static_cast(baseDisplayAddr)); + */ + + public void drawWindow(final String title, final long memData, final long memSize) { + drawWindow(title, memData, memSize, 0x000); + } + + public native void drawWindow(String title, long memData, long memSize, long baseDisplayAddr); /* + MEMORY_EDITOR->DrawWindow(title, reinterpret_cast(memData), static_cast(memSize), static_cast(baseDisplayAddr)); + */ + + public void drawContents(final long memData, final long memSize) { + drawContents(memData, memSize, 0x0000); + } + + public native void drawContents(long memData, long memSize, long baseDisplayAddr); /* + MEMORY_EDITOR->DrawContents(reinterpret_cast(memData), static_cast(memSize), static_cast(baseDisplayAddr)); + */ + + public void drawOptionsLine(final MemoryEditorSizes s, final long memData, final long memSize, final long baseDisplayAddr) { + nDrawOptionsLine(s.ptr, memData, memSize, baseDisplayAddr); + } + + public native void nDrawOptionsLine(long ptr, long memData, long memSize, long baseDisplayAddr); /* + MEMORY_EDITOR->DrawOptionsLine(*((MemoryEditor::Sizes*)ptr), reinterpret_cast(memData), static_cast(memSize), static_cast(baseDisplayAddr)); + */ + + public void drawPreviewLine(final MemoryEditorSizes s, final long memDataVoid, final long memSize, final long baseDisplayAddr) { + nDrawPreviewLine(s.ptr, memDataVoid, memSize, baseDisplayAddr); + } + + public native void nDrawPreviewLine(long ptr, long memDataVoid, long memSize, long baseDisplayAddr); /* + MEMORY_EDITOR->DrawPreviewLine(*((MemoryEditor::Sizes*)ptr), reinterpret_cast(memDataVoid), static_cast(memSize), static_cast(baseDisplayAddr)); + */ +} diff --git a/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditorSizes.java b/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditorSizes.java new file mode 100644 index 00000000..18da4136 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/extension/memedit/MemoryEditorSizes.java @@ -0,0 +1,109 @@ +package imgui.extension.memedit; + +import imgui.binding.ImGuiStructDestroyable; + +public final class MemoryEditorSizes extends ImGuiStructDestroyable { + + /*JNI + #include "_memedit.h" + + #define MEMORY_EDITOR_SIZES ((MemoryEditor::Sizes*)STRUCT_PTR) + */ + + public MemoryEditorSizes() { + + } + + public MemoryEditorSizes(final long ptr) { + super(ptr); + } + + @Override + protected long create() { + return nCreate(); + } + + private native long nCreate(); /* + return (intptr_t)(new MemoryEditor::Sizes()); + */ + + public native void setAddrDigitsCount(int addrDigitsCount); /* + MEMORY_EDITOR_SIZES->AddrDigitsCount = addrDigitsCount; + */ + + public native int getAddrDigitsCount(); /* + return MEMORY_EDITOR_SIZES->AddrDigitsCount; + */ + + public native void setLineHeight(float lineHeight); /* + MEMORY_EDITOR_SIZES->LineHeight = lineHeight; + */ + + public native float getLineHeight(); /* + return MEMORY_EDITOR_SIZES->LineHeight; + */ + + public native void setGlyphWidth(float glyphWidth); /* + MEMORY_EDITOR_SIZES->GlyphWidth = glyphWidth; + */ + + public native float getGlyphWidth(); /* + return MEMORY_EDITOR_SIZES->GlyphWidth; + */ + + public native void setHexCellWidth(float hexCellWidth); /* + MEMORY_EDITOR_SIZES->HexCellWidth = hexCellWidth; + */ + + public native float getHexCellWidth(); /* + return MEMORY_EDITOR_SIZES->HexCellWidth; + */ + + public native void setSpacingBetweenMidCols(float spacingBetweenMidCols); /* + MEMORY_EDITOR_SIZES->SpacingBetweenMidCols = spacingBetweenMidCols; + */ + + public native float getSpacingBetweenMidCols(); /* + return MEMORY_EDITOR_SIZES->SpacingBetweenMidCols; + */ + + public native void setPosHexStart(float posHexStart); /* + MEMORY_EDITOR_SIZES->PosHexStart = posHexStart; + */ + + public native float getPosHexStart(); /* + return MEMORY_EDITOR_SIZES->PosHexStart; + */ + + public native void setPosHexEnd(float posHexEnd); /* + MEMORY_EDITOR_SIZES->PosHexEnd = posHexEnd; + */ + + public native float getPosHexEnd(); /* + return MEMORY_EDITOR_SIZES->PosHexEnd; + */ + + public native void setPosAsciiStart(float posAsciiStart); /* + MEMORY_EDITOR_SIZES->PosAsciiStart = posAsciiStart; + */ + + public native float getPosAsciiStart(); /* + return MEMORY_EDITOR_SIZES->PosAsciiStart; + */ + + public native void setPosAsciiEnd(float posAsciiEnd); /* + MEMORY_EDITOR_SIZES->PosAsciiEnd = posAsciiEnd; + */ + + public native float getPosAsciiEnd(); /* + return MEMORY_EDITOR_SIZES->PosAsciiEnd; + */ + + public native void setWindowWidth(float windowWidth); /* + MEMORY_EDITOR_SIZES->WindowWidth = windowWidth; + */ + + public native float getWindowWidth(); /* + return MEMORY_EDITOR_SIZES->WindowWidth; + */ +} diff --git a/imgui-binding/src/main/native/_memedit.h b/imgui-binding/src/main/native/_memedit.h new file mode 100644 index 00000000..02c0898a --- /dev/null +++ b/imgui-binding/src/main/native/_memedit.h @@ -0,0 +1,4 @@ +#pragma once + +#include "_common.h" +#include "imgui_memory_editor.h" diff --git a/include/imgui_club b/include/imgui_club new file mode 160000 index 00000000..d4cd9896 --- /dev/null +++ b/include/imgui_club @@ -0,0 +1 @@ +Subproject commit d4cd9896e15a03e92702a578586c3f91bbde01e8