[API] Remove lazy-created sructs and add methods to verify struct pointer
This commit is contained in:
1 parent
c33331e13b
commit
91d636a659
8 files changed
+60
-75
No files matched your search
@@ -7,8 +7,8 @@ import imgui.binding.ImGuiStructDestroyable;
|
||||
* ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
||||
*/
|
||||
public final class ImFont extends ImGuiStructDestroyable {
|
||||
private ImFontGlyph fallbackGlyph = null;
|
||||
private ImFontGlyph foundGlyph = new ImFontGlyph(0);
|
||||
private final ImFontGlyph fallbackGlyph = new ImFontGlyph(0);
|
||||
private final ImFontGlyph foundGlyph = new ImFontGlyph(0);
|
||||
|
||||
public ImFont() {
|
||||
}
|
||||
@@ -64,9 +64,7 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
* = FindGlyph(FontFallbackChar)
|
||||
*/
|
||||
public ImFontGlyph getFallbackGlyph() {
|
||||
if (fallbackGlyph == null) {
|
||||
fallbackGlyph = new ImFontGlyph(nGetFallbackGlyphPtr());
|
||||
}
|
||||
fallbackGlyph.ptr = nGetFallbackGlyphPtr();
|
||||
return fallbackGlyph;
|
||||
}
|
||||
|
||||
@@ -172,11 +170,7 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
// Methods
|
||||
|
||||
public ImFontGlyph findGlyph(final int c) {
|
||||
final long ptr = nFindGlyph(c);
|
||||
if (ptr == 0) {
|
||||
return null;
|
||||
}
|
||||
foundGlyph.ptr = ptr;
|
||||
foundGlyph.ptr = nFindGlyph(c);
|
||||
return foundGlyph;
|
||||
}
|
||||
|
||||
@@ -185,11 +179,7 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
*/
|
||||
|
||||
public ImFontGlyph findGlyphNoFallback(final int c) {
|
||||
final long ptr = nFindGlyphNoFallback(c);
|
||||
if (ptr == 0) {
|
||||
return null;
|
||||
}
|
||||
foundGlyph.ptr = ptr;
|
||||
foundGlyph.ptr = nFindGlyphNoFallback(c);
|
||||
return foundGlyph;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,11 +32,11 @@ public class ImGui {
|
||||
private static final ImGuiViewport WINDOW_VIEWPORT;
|
||||
private static final ImGuiViewport FIND_VIEWPORT;
|
||||
|
||||
private static ImDrawData drawData;
|
||||
private static ImFont font;
|
||||
private static ImGuiStyle style;
|
||||
private static ImGuiViewport mainViewport;
|
||||
private static ImGuiPlatformIO platformIO;
|
||||
private static final ImDrawData DRAW_DATA;
|
||||
private static final ImFont FONT;
|
||||
private static final ImGuiStyle STYLE;
|
||||
private static final ImGuiViewport MAIN_VIEWPORT;
|
||||
private static final ImGuiPlatformIO PLATFORM_IO;
|
||||
|
||||
static {
|
||||
final String libPath = System.getProperty(LIB_PATH_PROP);
|
||||
@@ -61,6 +61,12 @@ public class ImGui {
|
||||
WINDOW_VIEWPORT = new ImGuiViewport(0);
|
||||
FIND_VIEWPORT = new ImGuiViewport(0);
|
||||
|
||||
DRAW_DATA = new ImDrawData(0);
|
||||
FONT = new ImFont(0);
|
||||
STYLE = new ImGuiStyle(0);
|
||||
MAIN_VIEWPORT = new ImGuiViewport(0);
|
||||
PLATFORM_IO = new ImGuiPlatformIO(0);
|
||||
|
||||
nInitJni();
|
||||
ImFontAtlas.nInit();
|
||||
ImGuiPlatformIO.init();
|
||||
@@ -164,10 +170,8 @@ public class ImGui {
|
||||
* Access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame!
|
||||
*/
|
||||
public static ImGuiStyle getStyle() {
|
||||
if (style == null) {
|
||||
style = new ImGuiStyle(nGetStyle());
|
||||
}
|
||||
return style;
|
||||
STYLE.ptr = nGetStyle();
|
||||
return STYLE;
|
||||
}
|
||||
|
||||
private static native long nGetStyle(); /*
|
||||
@@ -200,10 +204,8 @@ public class ImGui {
|
||||
* Valid after Render() and until the next call to NewFrame(). this is what you have to render.
|
||||
*/
|
||||
public static ImDrawData getDrawData() {
|
||||
if (drawData == null) {
|
||||
drawData = new ImDrawData(nGetDrawData());
|
||||
}
|
||||
return drawData;
|
||||
DRAW_DATA.ptr = nGetDrawData();
|
||||
return DRAW_DATA;
|
||||
}
|
||||
|
||||
private static native long nGetDrawData(); /*
|
||||
@@ -1094,10 +1096,8 @@ public class ImGui {
|
||||
* Get current font.
|
||||
*/
|
||||
public static ImFont getFont() {
|
||||
if (font == null) {
|
||||
font = new ImFont(nGetFont());
|
||||
}
|
||||
return font;
|
||||
FONT.ptr = nGetFont();
|
||||
return FONT;
|
||||
}
|
||||
|
||||
private static native long nGetFont(); /*
|
||||
@@ -5121,10 +5121,8 @@ public class ImGui {
|
||||
* Return primary/default viewport.
|
||||
*/
|
||||
public static ImGuiViewport getMainViewport() {
|
||||
if (mainViewport == null) {
|
||||
mainViewport = new ImGuiViewport(nGetMainViewport());
|
||||
}
|
||||
return mainViewport;
|
||||
MAIN_VIEWPORT.ptr = nGetMainViewport();
|
||||
return MAIN_VIEWPORT;
|
||||
}
|
||||
|
||||
private static native long nGetMainViewport(); /*
|
||||
@@ -5682,10 +5680,8 @@ public class ImGui {
|
||||
* Platform/renderer functions, for backend to setup + viewports list.
|
||||
*/
|
||||
public static ImGuiPlatformIO getPlatformIO() {
|
||||
if (platformIO == null) {
|
||||
platformIO = new ImGuiPlatformIO(nGetPlatformIO());
|
||||
}
|
||||
return platformIO;
|
||||
PLATFORM_IO.ptr = nGetPlatformIO();
|
||||
return PLATFORM_IO;
|
||||
}
|
||||
|
||||
private static native long nGetPlatformIO(); /*
|
||||
|
||||
@@ -8,7 +8,7 @@ import imgui.callback.ImStrSupplier;
|
||||
* Access via ImGui::GetIO(). Read 'Programmer guide' section in .cpp file for general usage.
|
||||
*/
|
||||
public final class ImGuiIO {
|
||||
private ImFontAtlas imFontAtlas;
|
||||
private final ImFontAtlas imFontAtlas = new ImFontAtlas(0);
|
||||
|
||||
ImGuiIO() {
|
||||
}
|
||||
@@ -240,9 +240,7 @@ public final class ImGuiIO {
|
||||
* Font atlas: load, rasterize and pack one or more fonts into a single texture.
|
||||
*/
|
||||
public ImFontAtlas getFonts() {
|
||||
if (imFontAtlas == null) {
|
||||
imFontAtlas = new ImFontAtlas(nGetFonts());
|
||||
}
|
||||
imFontAtlas.ptr = nGetFonts();
|
||||
return imFontAtlas;
|
||||
}
|
||||
|
||||
@@ -256,7 +254,6 @@ public final class ImGuiIO {
|
||||
* BINDING NOTICE: You SHOULD manually destroy previously used ImFontAtlas.
|
||||
*/
|
||||
public void setFonts(final ImFontAtlas imFontAtlas) {
|
||||
this.imFontAtlas = imFontAtlas;
|
||||
nSetFonts(imFontAtlas.ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package imgui.binding;
|
||||
import imgui.ImGui;
|
||||
|
||||
/**
|
||||
* Class provides a communication layer between binding and Dear ImGui library though the "pointer" field.
|
||||
* Class provides a communication layer between binding and Dear ImGui library through the "pointer" field.
|
||||
*/
|
||||
public abstract class ImGuiStruct {
|
||||
/**
|
||||
* Pointer to the natively allocated object,
|
||||
* Pointer to the natively allocated object.
|
||||
* Could be zero if JNI returned NULL instead of the real object.
|
||||
* For such cases methods {@link #isValidPtr()} and {@link #isNotValidPtr()} could be used to verify that object points to the real object.
|
||||
*/
|
||||
public long ptr;
|
||||
|
||||
@@ -15,4 +17,22 @@ public abstract class ImGuiStruct {
|
||||
ImGui.init();
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows if object pointer is valid and does it point to the existing object.
|
||||
*
|
||||
* @return true, if pointer is valid
|
||||
*/
|
||||
public final boolean isValidPtr() {
|
||||
return ptr != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows if object pointer is valid and does it point to the existing object.
|
||||
*
|
||||
* @return true, if pointer is invalid
|
||||
*/
|
||||
public final boolean isNotValidPtr() {
|
||||
return !isValidPtr();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import imgui.type.ImInt;
|
||||
* Refer to the library's Github page for examples and support
|
||||
*/
|
||||
public final class ImNodes {
|
||||
private static ImNodesStyle style;
|
||||
private static final ImNodesStyle STYLE = new ImNodesStyle(0);
|
||||
|
||||
private ImNodes() {
|
||||
}
|
||||
@@ -61,10 +61,8 @@ public final class ImNodes {
|
||||
* Returns the global style struct. See the struct declaration for default values.
|
||||
*/
|
||||
public static ImNodesStyle getStyle() {
|
||||
if (style == null) {
|
||||
style = new ImNodesStyle(nGetStyle());
|
||||
}
|
||||
return style;
|
||||
STYLE.ptr = nGetStyle();
|
||||
return STYLE;
|
||||
}
|
||||
|
||||
private static native long nGetStyle(); /*
|
||||
|
||||
@@ -3,7 +3,6 @@ package imgui.extension.imnodes;
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
public final class ImNodesContext extends ImGuiStructDestroyable {
|
||||
|
||||
public ImNodesContext() {
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class NodeEditor {
|
||||
private static final ImDrawList HINT_BACKGROUND_DRAW_LIST = new ImDrawList(0);
|
||||
private static final ImDrawList NODE_BACKGROUND_DRAW_LIST = new ImDrawList(0);
|
||||
|
||||
private static NodeEditorStyle style;
|
||||
private static final NodeEditorStyle STYLE = new NodeEditorStyle(0);
|
||||
|
||||
private NodeEditor() {
|
||||
}
|
||||
@@ -128,10 +128,8 @@ public final class NodeEditor {
|
||||
*/
|
||||
|
||||
public static NodeEditorStyle getStyle() {
|
||||
if (style == null) {
|
||||
style = new NodeEditorStyle(nGetStyle());
|
||||
}
|
||||
return style;
|
||||
STYLE.ptr = nGetStyle();
|
||||
return STYLE;
|
||||
}
|
||||
|
||||
private static native long nGetStyle(); /*
|
||||
@@ -198,13 +196,8 @@ public final class NodeEditor {
|
||||
}
|
||||
|
||||
public static ImDrawList getNodeBackgroundDrawList(final long nodeId) {
|
||||
final long ptr = nGetNodeBackgroundDrawList(nodeId);
|
||||
if (ptr == 0) {
|
||||
return null;
|
||||
} else {
|
||||
NODE_BACKGROUND_DRAW_LIST.ptr = ptr;
|
||||
return NODE_BACKGROUND_DRAW_LIST;
|
||||
}
|
||||
NODE_BACKGROUND_DRAW_LIST.ptr = nGetNodeBackgroundDrawList(nodeId);
|
||||
return NODE_BACKGROUND_DRAW_LIST;
|
||||
}
|
||||
|
||||
private static native long nGetHintForegroundDrawList(); /*
|
||||
|
||||
@@ -51,11 +51,7 @@ public final class ImGui extends imgui.ImGui {
|
||||
*/
|
||||
|
||||
public static ImGuiDockNode dockBuilderGetNode(final int nodeId) {
|
||||
final long ptr = nDockBuilderGetNode(nodeId);
|
||||
if (ptr == 0) {
|
||||
return null;
|
||||
}
|
||||
DOCK_NODE.ptr = ptr;
|
||||
DOCK_NODE.ptr = nDockBuilderGetNode(nodeId);
|
||||
return DOCK_NODE;
|
||||
}
|
||||
|
||||
@@ -64,11 +60,7 @@ public final class ImGui extends imgui.ImGui {
|
||||
*/
|
||||
|
||||
public static ImGuiDockNode dockBuilderGetCentralNode(final int nodeId) {
|
||||
final long ptr = nDockBuilderGetCentralNode(nodeId);
|
||||
if (ptr == 0) {
|
||||
return null;
|
||||
}
|
||||
DOCK_NODE.ptr = ptr;
|
||||
DOCK_NODE.ptr = nDockBuilderGetCentralNode(nodeId);
|
||||
return DOCK_NODE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user