Refactor mapping to the native structs
This commit is contained in:
1 parent
1209caa518
commit
1dcf2328a4
17 files changed
+194
-251
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStruct;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@@ -11,36 +13,28 @@ import java.nio.ByteOrder;
|
||||
* BINDING NOTICE: Since it's impossible to do a 1:1 mapping with JNI, current class provides "getCmdList*()" methods.
|
||||
* Those are used to get the data needed to do a rendering.
|
||||
*/
|
||||
public final class ImDrawData {
|
||||
public final class ImDrawData extends ImGuiStruct {
|
||||
public static final int SIZEOF_IM_DRAW_IDX = 2;
|
||||
public static final int SIZEOF_IM_DRAW_VERT = (4 + 1) * 4;
|
||||
|
||||
private static final int FACTOR = 5_000;
|
||||
|
||||
final long ptr;
|
||||
|
||||
private ByteBuffer idxBuffer = ByteBuffer.allocateDirect(SIZEOF_IM_DRAW_IDX * FACTOR).order(ByteOrder.nativeOrder());
|
||||
private ByteBuffer vtxBuffer = ByteBuffer.allocateDirect(SIZEOF_IM_DRAW_VERT * FACTOR).order(ByteOrder.nativeOrder());
|
||||
|
||||
ImDrawData(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
public ImDrawData(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imDrawDataPtrID;
|
||||
|
||||
#define IM_DRAW_DATA ((ImDrawData*)env->GetLongField(object, imDrawDataPtrID))
|
||||
#define IM_DRAW_DATA ((ImDrawData*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImDrawDataClass = env->FindClass("imgui/ImDrawData");
|
||||
imDrawDataPtrID = env->GetFieldID(jImDrawDataClass, "ptr", "J");
|
||||
*/
|
||||
|
||||
///////// Start of Render Methods | Binding
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStruct;
|
||||
|
||||
/**
|
||||
* Draw command list
|
||||
* This is the low-level list of polygons that ImGui:: functions are filling. At the end of the frame,
|
||||
@@ -11,28 +13,20 @@ package imgui;
|
||||
* but you are totally free to apply whatever transformation matrix to want to the data (if you apply such transformation you'll want to apply it to ClipRect as well)
|
||||
* Important: Primitives are always added to the list and not culled (culling is done at higher-level by ImGui:: functions), if you use this API a lot consider coarse culling your drawn objects.
|
||||
*/
|
||||
public final class ImDrawList {
|
||||
long ptr;
|
||||
|
||||
ImDrawList(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
public final class ImDrawList extends ImGuiStruct {
|
||||
public ImDrawList(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imDrawListPtrID;
|
||||
|
||||
#define IM_DRAW_LIST ((ImDrawList*)env->GetLongField(object, imDrawListPtrID))
|
||||
#define IM_DRAW_LIST ((ImDrawList*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImDrawListClass = env->FindClass("imgui/ImDrawList");
|
||||
imDrawListPtrID = env->GetFieldID(jImDrawListClass, "ptr", "J");
|
||||
*/
|
||||
|
||||
/**
|
||||
* Flags, you may poke into these to adjust anti-aliasing settings per-primitive.
|
||||
*/
|
||||
|
||||
@@ -1,54 +1,37 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
/**
|
||||
* Font runtime data and rendering
|
||||
* ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
||||
*/
|
||||
public final class ImFont implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
|
||||
public final class ImFont extends ImGuiStructDestroyable {
|
||||
private ImFontGlyph fallbackGlyph = null;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public ImFont() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImFont(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImFont(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imFontPtrID;
|
||||
|
||||
#define IM_FONT ((ImFont*)env->GetLongField(object, imFontPtrID))
|
||||
#define IM_FONT ((ImFont*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImFontClass = env->FindClass("imgui/ImFont");
|
||||
imFontPtrID = env->GetFieldID(jImFontClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImFont* imFont = new ImFont();
|
||||
return (intptr_t)imFont;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImFont*)ptr;
|
||||
return (intptr_t)(new ImFont());
|
||||
*/
|
||||
|
||||
// TODO IndexAdvanceX
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
import imgui.type.ImInt;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -24,37 +25,23 @@ import java.nio.ByteOrder;
|
||||
* - Even though many functions are suffixed with "TTF", OTF data is supported just as well.
|
||||
* - This is an old API and it is currently awkward for those and and various other reasons! We will address them in the future!
|
||||
*/
|
||||
public final class ImFontAtlas implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
|
||||
public final class ImFontAtlas extends ImGuiStructDestroyable {
|
||||
private ByteBuffer alpha8pixels = null;
|
||||
private ByteBuffer rgba32pixels = null;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public ImFontAtlas() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImFontAtlas(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImFontAtlas(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imFontAtlasPtrID;
|
||||
|
||||
#define IM_FONT_ATLAS ((ImFontAtlas*)env->GetLongField(object, imFontAtlasPtrID))
|
||||
#define IM_FONT_ATLAS ((ImFontAtlas*)STRUCT_PTR)
|
||||
|
||||
jmethodID jImFontAtlasCreateAlpha8PixelsMID;
|
||||
jmethodID jImFontAtlasCreateRgba32PixelsMID;
|
||||
@@ -62,19 +49,18 @@ public final class ImFontAtlas implements ImGuiDestroyableStruct {
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImFontAtlasClass = env->FindClass("imgui/ImFontAtlas");
|
||||
imFontAtlasPtrID = env->GetFieldID(jImFontAtlasClass, "ptr", "J");
|
||||
|
||||
jImFontAtlasCreateAlpha8PixelsMID = env->GetMethodID(jImFontAtlasClass, "createAlpha8Pixels", "(I)Ljava/nio/ByteBuffer;");
|
||||
jImFontAtlasCreateRgba32PixelsMID = env->GetMethodID(jImFontAtlasClass, "createRgba32Pixels", "(I)Ljava/nio/ByteBuffer;");
|
||||
*/
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImFontAtlas* imFontAtlas = new ImFontAtlas();
|
||||
return (intptr_t)imFontAtlas;
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImFontAtlas*)ptr;
|
||||
private native long nCreate(); /*
|
||||
return (intptr_t)(new ImFontConfig());
|
||||
*/
|
||||
|
||||
public ImFont addFont(final ImFontConfig imFontConfig) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package imgui;
|
||||
|
||||
public final class ImFontConfig implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
public final class ImFontConfig extends ImGuiStructDestroyable {
|
||||
private short[] glyphRanges;
|
||||
|
||||
/**
|
||||
@@ -10,43 +10,31 @@ public final class ImFontConfig implements ImGuiDestroyableStruct {
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public ImFontConfig() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
super();
|
||||
setFontDataOwnedByAtlas(false); // Read method javadoc
|
||||
}
|
||||
|
||||
ImFontConfig(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
super(ptr);
|
||||
setFontDataOwnedByAtlas(false); // Read method javadoc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imFontConfigPtrID;
|
||||
|
||||
#define IM_FONT_CONFIG ((ImFontConfig*)env->GetLongField(object, imFontConfigPtrID))
|
||||
#define IM_FONT_CONFIG ((ImFontConfig*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImFontConfigClass = env->FindClass("imgui/ImFontConfig");
|
||||
imFontConfigPtrID = env->GetFieldID(jImFontConfigClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImFontConfig* imFontConfig = new ImFontConfig();
|
||||
return (intptr_t)imFontConfig;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImFontConfig*)ptr;
|
||||
return (intptr_t)(new ImFontConfig());
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,51 +1,34 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
/**
|
||||
* Hold rendering data for one glyph.
|
||||
* (Note: some language parsers may fail to convert the 31+1 bitfield members, in this case maybe drop store a single u32 or we can rework this)
|
||||
*/
|
||||
public final class ImFontGlyph implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public final class ImFontGlyph extends ImGuiStructDestroyable {
|
||||
public ImFontGlyph() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImFontGlyph(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImFontGlyph(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imFontGlyphPtrID;
|
||||
|
||||
#define IM_FONT_GLYPH ((ImFontGlyph*)env->GetLongField(object, imFontGlyphPtrID))
|
||||
#define IM_FONT_GLYPH ((ImFontGlyph*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImFontGlyphClass = env->FindClass("imgui/ImFontGlyph");
|
||||
imFontGlyphPtrID = env->GetFieldID(jImFontGlyphClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImFontConfig* imFontConfig = new ImFontConfig();
|
||||
return (intptr_t)imFontConfig;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImFontConfig*)ptr;
|
||||
return (intptr_t)(new ImFontGlyph());
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,16 +56,7 @@ public final class ImGui {
|
||||
IMGUI_STORAGE = new ImGuiStorage(0);
|
||||
|
||||
nInitJni();
|
||||
ImDrawList.nInit();
|
||||
ImDrawData.nInit();
|
||||
ImFontAtlas.nInit();
|
||||
ImFontConfig.nInit();
|
||||
ImFontGlyph.nInit();
|
||||
ImFont.nInit();
|
||||
ImGuiStyle.nInit();
|
||||
ImGuiWindowClass.nInit();
|
||||
ImGuiStorage.nInit();
|
||||
ImGuiViewport.nInit();
|
||||
nInitInputTextData();
|
||||
}
|
||||
|
||||
@@ -113,7 +104,7 @@ public final class ImGui {
|
||||
* Method is used to initiate static instantiation (loading of the native libraries etc.).
|
||||
* Otherwise native libraries will be loaded on demand and natively mapped objects won't work.
|
||||
*/
|
||||
static void touch() {
|
||||
public static void touch() {
|
||||
}
|
||||
|
||||
private ImGui() {
|
||||
@@ -124,11 +115,13 @@ public final class ImGui {
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_callbacks.h"
|
||||
#include "jni_binding_struct.h"
|
||||
*/
|
||||
|
||||
private static native void nInitJni(); /*
|
||||
Jni::InitCommon(env);
|
||||
Jni::InitCallbacks(env);
|
||||
Jni::InitBindingStruct(env);
|
||||
*/
|
||||
|
||||
// Context creation and access
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package imgui;
|
||||
|
||||
/**
|
||||
* When implement, class could be manually destroyed (free allocated memory on the JNI side).
|
||||
*/
|
||||
interface ImGuiDestroyableStruct {
|
||||
void destroy();
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
/**
|
||||
* Helper: Key-Value storage
|
||||
* Typically you don't have to worry about this since a storage is held within each Window.
|
||||
@@ -10,48 +12,29 @@ package imgui;
|
||||
* - You want to store custom debug data easily without adding or editing structures in your code (probably not efficient, but convenient)
|
||||
* Types are NOT stored, so it is up to you to make sure your Key don't collide with different types.
|
||||
*/
|
||||
public final class ImGuiStorage implements ImGuiDestroyableStruct {
|
||||
long ptr;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public final class ImGuiStorage extends ImGuiStructDestroyable {
|
||||
public ImGuiStorage() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImGuiStorage(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImGuiStorage(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imGuiStoragePtrID;
|
||||
|
||||
#define IMGUI_STORAGE ((ImGuiStorage*)env->GetLongField(object, imGuiStoragePtrID))
|
||||
#define IMGUI_STORAGE ((ImGuiStorage*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImGuiStorageClass = env->FindClass("imgui/ImGuiStorage");
|
||||
imGuiStoragePtrID = env->GetFieldID(jImGuiStorageClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImGuiStorage* imGuiStorage = new ImGuiStorage();
|
||||
return (intptr_t)imGuiStorage;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImGuiStorage*)ptr;
|
||||
return (intptr_t)(new ImGuiStorage());
|
||||
*/
|
||||
|
||||
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
|
||||
|
||||
@@ -1,53 +1,36 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
/**
|
||||
* You may modify the ImGui::GetStyle() main instance during initialization and before NewFrame().
|
||||
* During the frame, use ImGui::PushStyleVar(ImGuiStyleVar_XXXX)/PopStyleVar() to alter the main style values,
|
||||
* and ImGui::PushStyleColor(ImGuiCol_XXX)/PopStyleColor() for colors.
|
||||
*/
|
||||
public final class ImGuiStyle implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public final class ImGuiStyle extends ImGuiStructDestroyable {
|
||||
public ImGuiStyle() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImGuiStyle(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImGuiStyle(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <imgui.h>
|
||||
#include <stdint.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imGuiStylePtrID;
|
||||
|
||||
#define IMGUI_STYLE ((ImGuiStyle*)env->GetLongField(object, imGuiStylePtrID))
|
||||
#define IMGUI_STYLE ((ImGuiStyle*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImGuiStyleClass = env->FindClass("imgui/ImGuiStyle");
|
||||
imGuiStylePtrID = env->GetFieldID(jImGuiStyleClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImGuiStyle* imGuiStyle = new ImGuiStyle();
|
||||
return (intptr_t)imGuiStyle;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImGuiStyle*)ptr;
|
||||
return (intptr_t)(new ImGuiStyle());
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStruct;
|
||||
|
||||
/**
|
||||
* The viewports created and managed by Dear ImGui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
|
||||
* - Main Area = entire viewport.
|
||||
* - Work Area = entire viewport minus sections optionally used by menu bars, status bars. Some positioning code will prefer to use this. Window are also trying to stay within this area.
|
||||
*/
|
||||
public final class ImGuiViewport {
|
||||
final long ptr;
|
||||
|
||||
ImGuiViewport(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
public final class ImGuiViewport extends ImGuiStruct {
|
||||
public ImGuiViewport(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_common.h"
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imGuiViewportPtrID;
|
||||
|
||||
#define IMGUI_VIEWPORT ((ImGuiViewport*)env->GetLongField(object, imGuiViewportPtrID))
|
||||
#define IMGUI_VIEWPORT ((ImGuiViewport*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImGuiViewportClass = env->FindClass("imgui/ImGuiViewport");
|
||||
imGuiViewportPtrID = env->GetFieldID(jImGuiViewportClass, "ptr", "J");
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unique identifier for the viewport.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
/**
|
||||
* [ALPHA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions.
|
||||
* Important: the content of this class is still highly WIP and likely to change and be refactored
|
||||
@@ -9,48 +11,29 @@ package imgui;
|
||||
* - To the platform back-end for OS level parent/child relationships of viewport.
|
||||
* - To the docking system for various options and filtering.
|
||||
*/
|
||||
public final class ImGuiWindowClass implements ImGuiDestroyableStruct {
|
||||
final long ptr;
|
||||
|
||||
/**
|
||||
* This class will create a native structure.
|
||||
* Call {@link #destroy()} method to manually free used memory.
|
||||
*/
|
||||
public final class ImGuiWindowClass extends ImGuiStructDestroyable {
|
||||
public ImGuiWindowClass() {
|
||||
ImGui.touch();
|
||||
ptr = nCreate();
|
||||
}
|
||||
|
||||
ImGuiWindowClass(final long ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
public ImGuiWindowClass(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include <stdint.h>
|
||||
#include <imgui.h>
|
||||
#include "jni_binding_struct.h"
|
||||
|
||||
jfieldID imGuiWindowClassPtrID;
|
||||
|
||||
#define IMGUI_WINDOW_CLASS ((ImGuiWindowClass*)env->GetLongField(object, imGuiWindowClassPtrID))
|
||||
#define IMGUI_WINDOW_CLASS ((ImGuiWindowClass*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
static native void nInit(); /*
|
||||
jclass jImGuiWindowClassClass = env->FindClass("imgui/ImGuiWindowClass");
|
||||
imGuiWindowClassPtrID = env->GetFieldID(jImGuiWindowClassClass, "ptr", "J");
|
||||
*/
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
ImGuiWindowClass* imGuiWindowClass = new ImGuiWindowClass();
|
||||
return (intptr_t)imGuiWindowClass;
|
||||
*/
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (ImGuiWindowClass*)ptr;
|
||||
return (intptr_t)(new ImGuiWindowClass());
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package imgui.binding;
|
||||
|
||||
import imgui.ImGui;
|
||||
|
||||
/**
|
||||
* Class provides a communication layer between binding and Dear ImGui library though the "pointer" field.
|
||||
*/
|
||||
public abstract class ImGuiStruct {
|
||||
/**
|
||||
* Pointer to the natively allocated object,
|
||||
*/
|
||||
public long ptr;
|
||||
|
||||
public ImGuiStruct(final long ptr) {
|
||||
ImGui.touch();
|
||||
this.ptr = ptr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package imgui.binding;
|
||||
|
||||
/**
|
||||
* Class extends {@link ImGuiStruct} and provides additional API to allocated and de-allocate native objects.
|
||||
*/
|
||||
public abstract class ImGuiStructDestroyable extends ImGuiStruct {
|
||||
/**
|
||||
* Constructor, which creates natively allocated struct. Those structs should be manually disposed with {@link #destroy()} method.
|
||||
*/
|
||||
public ImGuiStructDestroyable() {
|
||||
this(0);
|
||||
ptr = create();
|
||||
}
|
||||
|
||||
public ImGuiStructDestroyable(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
protected abstract long create();
|
||||
|
||||
/**
|
||||
* Method to free natively allocated memory for the struct mapped with pointer.
|
||||
*/
|
||||
public void destroy() {
|
||||
nDestroy(ptr);
|
||||
}
|
||||
|
||||
private native void nDestroy(long ptr); /*
|
||||
delete (void*)ptr;
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user