[Binding] Fix ImNodeEditor minor probs and add Style and Config struct

This commit is contained in:
SpaiR committed 2021-01-23 16:04:57 +02:00
1 parent 5beb896b50
commit bb472b9fe9
8 files changed
+403 -62

No files matched your search

@@ -21,22 +21,16 @@ import imgui.type.ImLong;
* we use longs to reduce boilerplate and garbage production
*/
public final class ImNodeEditor {
private static final ImDrawList HINT_FOREGROUND_DRAW_LIST = new ImDrawList(0);
private static final ImDrawList HINT_BACKGROUND_DRAW_LIST = new ImDrawList(0);
private static final ImDrawList NODE_BACKGROUND_DRAW_LIST = new ImDrawList(0);
private static final ImDrawList HINT_FOREGROUND_DRAW_LIST;
private static final ImDrawList HINT_BACKGROUND_DRAW_LIST;
private static final ImDrawList NODE_BACKGROUND_DRAW_LIST;
private static ImNodeEditorStyle style;
static {
HINT_FOREGROUND_DRAW_LIST = new ImDrawList(0);
HINT_BACKGROUND_DRAW_LIST = new ImDrawList(0);
NODE_BACKGROUND_DRAW_LIST = new ImDrawList(0);
private ImNodeEditor() {
}
private ImNodeEditor() { }
/*JNI
#pragma warning (disable:4244)
#include <imgui.h>
#include <imgui_node_editor.h>
#include <imgui_node_editor_internal.h>
@@ -46,7 +40,6 @@ public final class ImNodeEditor {
namespace ed = ax::NodeEditor;
*/
/**
* This method exists for api consistency and you can just call NodeEditorContext manually
*/
@@ -54,6 +47,10 @@ public final class ImNodeEditor {
return new ImNodeEditorContext();
}
public static ImNodeEditorContext createEditor(final ImNodeEditorConfig config) {
return new ImNodeEditorContext(config);
}
/**
* This method exists for api consistency and you can just call NodeEditorContext.destroy() manually
*/
@@ -130,6 +127,17 @@ public final class ImNodeEditor {
return ed::CanvasToScreen(ImVec2(0.0f, canvasSpacePosY)).y;
*/
public static ImNodeEditorStyle getStyle() {
if (style == null) {
style = new ImNodeEditorStyle(nGetStyle());
}
return style;
}
private static native long nGetStyle(); /*
return (intptr_t)&ed::GetStyle();
*/
public static native String getStyleColorName(int imNodeEditorStyleColor); /*
return env->NewStringUTF(ed::GetStyleColorName((ed::StyleColor)imNodeEditorStyleColor));
*/
@@ -158,7 +166,6 @@ public final class ImNodeEditor {
ed::PopStyleVar(count);
*/
public static native float getGroupMinX(); /*
return ed::GetGroupMin().x;
*/
@@ -192,7 +199,7 @@ public final class ImNodeEditor {
public static ImDrawList getNodeBackgroundDrawList(final long nodeId) {
final long ptr = nGetNodeBackgroundDrawList(nodeId);
if (ptr == 0L) {
if (ptr == 0) {
return null;
} else {
NODE_BACKGROUND_DRAW_LIST.ptr = ptr;
@@ -201,27 +208,27 @@ public final class ImNodeEditor {
}
private static native long nGetHintForegroundDrawList(); /*
return (jlong)(intptr_t)ed::GetHintForegroundDrawList();
return (intptr_t)(uintptr_t)ed::GetHintForegroundDrawList();
*/
private static native long nGetHintBackgroundDrawList(); /*
return (jlong)(intptr_t)ed::GetHintBackgroundDrawList();
return (intptr_t)(uintptr_t)ed::GetHintBackgroundDrawList();
*/
private static native long nGetNodeBackgroundDrawList(long nodeId); /*
return (jlong)(intptr_t)ed::GetNodeBackgroundDrawList(nodeId);
return (intptr_t)(uintptr_t)ed::GetNodeBackgroundDrawList(nodeId);
*/
public static native long getDoubleClickedNode(); /*
return (jlong)(uintptr_t)ed::GetDoubleClickedNode();
return (intptr_t)(uintptr_t)ed::GetDoubleClickedNode();
*/
public static native long getDoubleClickedPin(); /*
return (jlong)(uintptr_t)ed::GetDoubleClickedPin();
return (intptr_t)(uintptr_t)ed::GetDoubleClickedPin();
*/
public static native long getDoubleClickedLink(); /*
return (jlong)(uintptr_t)ed::GetDoubleClickedLink();
return (intptr_t)(uintptr_t)ed::GetDoubleClickedLink();
*/
public static native boolean isBackgroundClicked(); /*
@@ -264,47 +271,47 @@ public final class ImNodeEditor {
return nShowNodeContextMenu(nodeId.getData());
}
private static native boolean nShowNodeContextMenu(long[] nodeId); /*
return ed::ShowNodeContextMenu((ed::NodeId*)&nodeId[0]);
*/
public static boolean showPinContextMenu(final ImLong pinId) {
return nShowPinContextMenu(pinId.getData());
}
private static native boolean nShowPinContextMenu(long[] pinId); /*
return ed::ShowPinContextMenu((ed::PinId*)&pinId[0]);
*/
public static boolean showLinkContextMenu(final ImLong linkId) {
return nShowLinkContextMenu(linkId.getData());
}
private static native boolean nShowLinkContextMenu(long[] linkId); /*
return ed::ShowLinkContextMenu((ed::LinkId*)&linkId[0]);
*/
/**
* Binding notice: getNodeWithContextMenu(), getPinWithContextMenu() and getLinkWithContextMenu()
* return id of the object for which context menu should be shown. If there is no such object -1 will be returned.
*
* <p>
* These methods implemented as convenient alternative to showNodeContextMenu(ImLong), showPinContextMenu(ImLong) and
* showLinkContextMenu(ImLong)
*/
public static native long getNodeWithContextMenu(); /*
ed::NodeId id;
return ed::ShowNodeContextMenu(&id) ? (jlong)(uintptr_t)id : -1;
return ed::ShowNodeContextMenu(&id) ? (intptr_t)(uintptr_t)id : -1;
*/
public static native long getPinWithContextMenu(); /*
ed::PinId id;
return ed::ShowPinContextMenu(&id) ? (jlong)(uintptr_t)id : -1;
return ed::ShowPinContextMenu(&id) ? (intptr_t)(uintptr_t)id : -1;
*/
public static native long getLinkWithContextMenu(); /*
ed::LinkId id;
return ed::ShowLinkContextMenu(&id) ? (jlong)(uintptr_t)id : -1;
*/
private static native boolean nShowNodeContextMenu(long[] nodeId); /*
return ed::ShowNodeContextMenu((ed::NodeId*)&nodeId[0]);
*/
private static native boolean nShowPinContextMenu(long[] pinId); /*
return ed::ShowPinContextMenu((ed::PinId*)&pinId[0]);
*/
private static native boolean nShowLinkContextMenu(long[] linkId); /*
return ed::ShowLinkContextMenu((ed::LinkId*)&linkId[0]);
return ed::ShowLinkContextMenu(&id) ? (intptr_t)(uintptr_t)id : -1;
*/
public static native boolean showBackgroundContextMenu(); /*
@@ -336,7 +343,7 @@ public final class ImNodeEditor {
*/
public static void link(final long id, final long startPinId, final long endPinId) {
link(id, startPinId, endPinId, 1F, 1F, 1F, 1F, 1F);
link(id, startPinId, endPinId, 1, 1, 1, 1, 1);
}
public static native void link(long id, long startPinId, long endPinId, float r, float g, float b, float a,
@@ -349,7 +356,7 @@ public final class ImNodeEditor {
*/
public static boolean beginCreate() {
return beginCreate(1F, 1F, 1F, 1F, 1F);
return beginCreate(1, 1, 1, 1, 1);
}
public static native boolean beginCreate(float r, float g, float b, float a, float thickness); /*
@@ -357,7 +364,7 @@ public final class ImNodeEditor {
*/
public static boolean queryNewLink(final ImLong startId, final ImLong endId) {
return nQueryNewLink(startId.getData(), endId.getData(), 1F, 1F, 1F, 1F, 1F);
return nQueryNewLink(startId.getData(), endId.getData(), 1, 1, 1, 1, 1);
}
public static boolean queryNewLink(final ImLong startId, final ImLong endId, final float r, final float g, final float b, final float a, final float thickness) {
@@ -369,7 +376,7 @@ public final class ImNodeEditor {
*/
public static boolean acceptNewItem() {
return acceptNewItem(1F, 1F, 1F, 1F, 1F);
return acceptNewItem(1, 1, 1, 1, 1);
}
public static native boolean acceptNewItem(float r, float g, float b, float a, float thickness); /*
@@ -377,7 +384,7 @@ public final class ImNodeEditor {
*/
public static void rejectNewItem() {
rejectNewItem(1F, 1F, 1F, 1F, 1F);
rejectNewItem(1, 1, 1, 1, 1);
}
public static native void rejectNewItem(float r, float g, float b, float a, float thickness); /*
@@ -544,5 +551,4 @@ public final class ImNodeEditor {
public static native void endShortcut(); /*
ed::EndShortcut();
*/
}
@@ -0,0 +1,41 @@
package imgui.nodeditor;
import imgui.binding.ImGuiStructDestroyable;
public final class ImNodeEditorConfig extends ImGuiStructDestroyable {
public ImNodeEditorConfig() {
}
public ImNodeEditorConfig(final long ptr) {
super(ptr);
}
/*JNI
#include <stdint.h>
#include <imgui.h>
#include <imgui_node_editor.h>
#include <imgui_node_editor_internal.h>
#include "jni_binding_struct.h"
namespace ed = ax::NodeEditor;
#define IM_NODE_EDITOR_CONFIG ((ed::Config*)STRUCT_PTR)
*/
@Override
protected long create() {
return nCreate();
}
private native long nCreate(); /*
return (intptr_t)(new ed::Config());
*/
public native String getSettingsFile(); /*
return env->NewStringUTF(IM_NODE_EDITOR_CONFIG->SettingsFile);
*/
public native void setSettingsFile(String settingsFile); /*MANUAL
IM_NODE_EDITOR_CONFIG->SettingsFile = obj_settingsFile == NULL ? NULL : (char*)env->GetStringUTFChars(obj_settingsFile, JNI_FALSE);
*/
}
@@ -3,25 +3,27 @@ package imgui.nodeditor;
import imgui.binding.ImGuiStructDestroyable;
public final class ImNodeEditorContext extends ImGuiStructDestroyable {
/*JNI
#include <imgui.h>
#include <imgui_node_editor.h>
#include "jni_common.h"
#include "jni_binding_struct.h"
namespace ed = ax::NodeEditor;
#define IM_NODE_EDITOR_CONTEXT ((ed::EditorContext*)STRUCT_PTR)
*/
public ImNodeEditorContext() {
super();
}
public ImNodeEditorContext(final ImNodeEditorConfig config) {
this(nCreate(config.ptr));
}
public ImNodeEditorContext(final long ptr) {
super(ptr);
}
/*JNI
#include <imgui.h>
#include <imgui_node_editor.h>
#include "jni_binding_struct.h"
namespace ed = ax::NodeEditor;
#define IM_NODE_EDITOR_CONTEXT ((ed::EditorContext*)STRUCT_PTR)
*/
@Override
protected long create() {
return nCreate();
@@ -33,7 +35,11 @@ public final class ImNodeEditorContext extends ImGuiStructDestroyable {
}
private native long nCreate(); /*
return (jlong)ed::CreateEditor();
return (intptr_t)ed::CreateEditor();
*/
private static native long nCreate(long cfgPtr); /*
return (intptr_t)ed::CreateEditor((ed::Config*)cfgPtr);
*/
private native void nDestroyEditorContext(); /*
@@ -1,11 +1,9 @@
package imgui.nodeditor;
public final class ImNodeEditorPinKind {
private ImNodeEditorPinKind() {
}
public static final int Input = 0;
public static final int Output = 1;
}
@@ -0,0 +1,291 @@
package imgui.nodeditor;
import imgui.ImVec2;
import imgui.ImVec4;
import imgui.binding.ImGuiStruct;
public final class ImNodeEditorStyle extends ImGuiStruct {
public ImNodeEditorStyle(final long ptr) {
super(ptr);
}
/*JNI
#include <stdint.h>
#include <imgui.h>
#include <imgui_node_editor.h>
#include <imgui_node_editor_internal.h>
#include "jni_common.h"
#include "jni_binding_struct.h"
namespace ed = ax::NodeEditor;
#define IM_NODE_EDITOR_STYLE ((ed::Style*)STRUCT_PTR)
*/
public native void getNodePadding(ImVec4 dstImVec4); /*
Jni::ImVec4Cpy(env, IM_NODE_EDITOR_STYLE->NodePadding, dstImVec4);
*/
public native void setNodePadding(float x, float y, float z, float w); /*
IM_NODE_EDITOR_STYLE->NodePadding.x = x;
IM_NODE_EDITOR_STYLE->NodePadding.y = y;
IM_NODE_EDITOR_STYLE->NodePadding.z = z;
IM_NODE_EDITOR_STYLE->NodePadding.w = w;
*/
public native float getNodeRounding(); /*
return IM_NODE_EDITOR_STYLE->NodeRounding;
*/
public native void setNodeRounding(float nodeRounding); /*
IM_NODE_EDITOR_STYLE->NodeRounding = nodeRounding;
*/
public native float getNodeBorderWidth(); /*
return IM_NODE_EDITOR_STYLE->NodeBorderWidth;
*/
public native void setNodeBorderWidth(float nodeBorderWidth); /*
IM_NODE_EDITOR_STYLE->NodeBorderWidth = nodeBorderWidth;
*/
public native float getHoveredNodeBorderWidth(); /*
return IM_NODE_EDITOR_STYLE->HoveredNodeBorderWidth;
*/
public native void setHoveredNodeBorderWidth(float hoveredNodeBorderWidth); /*
IM_NODE_EDITOR_STYLE->HoveredNodeBorderWidth = hoveredNodeBorderWidth;
*/
public native float getSelectedNodeBorderWidth(); /*
return IM_NODE_EDITOR_STYLE->SelectedNodeBorderWidth;
*/
public native void setSelectedNodeBorderWidth(float selectedNodeBorderWidth); /*
IM_NODE_EDITOR_STYLE->SelectedNodeBorderWidth = selectedNodeBorderWidth;
*/
public native float getPinRounding(); /*
return IM_NODE_EDITOR_STYLE->PinRounding;
*/
public native void setPinRounding(float pinRounding); /*
IM_NODE_EDITOR_STYLE->PinRounding = pinRounding;
*/
public native float getPinBorderWidth(); /*
return IM_NODE_EDITOR_STYLE->PinBorderWidth;
*/
public native void setPinBorderWidth(float pinBorderWidth); /*
IM_NODE_EDITOR_STYLE->PinBorderWidth = pinBorderWidth;
*/
public native float getLinkStrength(); /*
return IM_NODE_EDITOR_STYLE->LinkStrength;
*/
public native void setLinkStrength(float linkStrength); /*
IM_NODE_EDITOR_STYLE->LinkStrength = linkStrength;
*/
public native void getSourceDirection(ImVec2 dstImVec2); /*
Jni::ImVec2Cpy(env, &IM_NODE_EDITOR_STYLE->SourceDirection, dstImVec2);
*/
public native float getSourceDirectionX(); /*
return IM_NODE_EDITOR_STYLE->SourceDirection.x;
*/
public native float getSourceDirectionY(); /*
return IM_NODE_EDITOR_STYLE->SourceDirection.y;
*/
public native void setSourceDirection(float x, float y); /*
IM_NODE_EDITOR_STYLE->SourceDirection.x = x;
IM_NODE_EDITOR_STYLE->SourceDirection.y = y;
*/
public native void getTargetDirection(ImVec2 dstImVec2); /*
Jni::ImVec2Cpy(env, &IM_NODE_EDITOR_STYLE->TargetDirection, dstImVec2);
*/
public native float getTargetDirectionX(); /*
return IM_NODE_EDITOR_STYLE->TargetDirection.x;
*/
public native float getTargetDirectionY(); /*
return IM_NODE_EDITOR_STYLE->TargetDirection.y;
*/
public native void setTargetDirection(float x, float y); /*
IM_NODE_EDITOR_STYLE->TargetDirection.x = x;
IM_NODE_EDITOR_STYLE->TargetDirection.y = y;
*/
public native float getScrollDuration(); /*
return IM_NODE_EDITOR_STYLE->ScrollDuration;
*/
public native void setScrollDuration(float scrollDuration); /*
IM_NODE_EDITOR_STYLE->ScrollDuration = scrollDuration;
*/
public native float getFlowMarkerDistance(); /*
return IM_NODE_EDITOR_STYLE->FlowMarkerDistance;
*/
public native void setFlowMarkerDistance(float flowMarkerDistance); /*
IM_NODE_EDITOR_STYLE->FlowMarkerDistance = flowMarkerDistance;
*/
public native float getFlowSpeed(); /*
return IM_NODE_EDITOR_STYLE->FlowSpeed;
*/
public native void setFlowSpeed(float flowSpeed); /*
IM_NODE_EDITOR_STYLE->FlowSpeed = flowSpeed;
*/
public native float getFlowDuration(); /*
return IM_NODE_EDITOR_STYLE->FlowDuration;
*/
public native void setFlowDuration(float flowDuration); /*
IM_NODE_EDITOR_STYLE->FlowDuration = flowDuration;
*/
public native void getPivotAlignment(ImVec2 dstImVec2); /*
Jni::ImVec2Cpy(env, &IM_NODE_EDITOR_STYLE->PivotAlignment, dstImVec2);
*/
public native float getPivotAlignmentX(); /*
return IM_NODE_EDITOR_STYLE->PivotAlignment.x;
*/
public native float getPivotAlignmentY(); /*
return IM_NODE_EDITOR_STYLE->PivotAlignment.y;
*/
public native void setPivotAlignment(float x, float y); /*
IM_NODE_EDITOR_STYLE->PivotAlignment.x = x;
IM_NODE_EDITOR_STYLE->PivotAlignment.y = y;
*/
public native void getPivotSize(ImVec2 dstImVec2); /*
Jni::ImVec2Cpy(env, &IM_NODE_EDITOR_STYLE->PivotSize, dstImVec2);
*/
public native float getPivotSizeX(); /*
return IM_NODE_EDITOR_STYLE->PivotSize.x;
*/
public native float getPivotSizeY(); /*
return IM_NODE_EDITOR_STYLE->PivotSize.y;
*/
public native void setPivotSize(float x, float y); /*
IM_NODE_EDITOR_STYLE->PivotSize.x = x;
IM_NODE_EDITOR_STYLE->PivotSize.y = y;
*/
public native void getPivotScale(ImVec2 dstImVec2); /*
Jni::ImVec2Cpy(env, &IM_NODE_EDITOR_STYLE->PivotScale, dstImVec2);
*/
public native float getPivotScaleX(); /*
return IM_NODE_EDITOR_STYLE->PivotScale.x;
*/
public native float getPivotScaleY(); /*
return IM_NODE_EDITOR_STYLE->PivotScale.y;
*/
public native void setPivotScale(float x, float y); /*
IM_NODE_EDITOR_STYLE->PivotScale.x = x;
IM_NODE_EDITOR_STYLE->PivotScale.y = y;
*/
public native float getPinCorners(); /*
return IM_NODE_EDITOR_STYLE->PinCorners;
*/
public native void setPinCorners(float pinCorners); /*
IM_NODE_EDITOR_STYLE->PinCorners = pinCorners;
*/
public native float getPinRadius(); /*
return IM_NODE_EDITOR_STYLE->PinRadius;
*/
public native void setPinRadius(float pinRadius); /*
IM_NODE_EDITOR_STYLE->PinRadius = pinRadius;
*/
public native float getPinArrowSize(); /*
return IM_NODE_EDITOR_STYLE->PinArrowSize;
*/
public native void setPinArrowSize(float pinArrowSize); /*
IM_NODE_EDITOR_STYLE->PinArrowSize = pinArrowSize;
*/
public native float getPinArrowWidth(); /*
return IM_NODE_EDITOR_STYLE->PinArrowWidth;
*/
public native void setPinArrowWidth(float pinArrowWidth); /*
IM_NODE_EDITOR_STYLE->PinArrowWidth = pinArrowWidth;
*/
public native float getGroupRounding(); /*
return IM_NODE_EDITOR_STYLE->GroupRounding;
*/
public native void setGroupRounding(float groupRounding); /*
IM_NODE_EDITOR_STYLE->GroupRounding = groupRounding;
*/
public native float getGroupBorderWidth(); /*
return IM_NODE_EDITOR_STYLE->GroupBorderWidth;
*/
public native void setGroupBorderWidth(float groupBorderWidth); /*
IM_NODE_EDITOR_STYLE->GroupBorderWidth = groupBorderWidth;
*/
/**
* BINDING NOTICE: colors is a 2d array with sizes: [StyleColor_Count][4]
*/
public native void setColors(float[][] colors); /*
for (int i = 0; i < ed::StyleColor_Count; i++) {
jfloatArray jColors = (jfloatArray)env->GetObjectArrayElement(colors, i);
jfloat* jColor = env->GetFloatArrayElements(jColors, 0);
IM_NODE_EDITOR_STYLE->Colors[i].x = jColor[0];
IM_NODE_EDITOR_STYLE->Colors[i].y = jColor[1];
IM_NODE_EDITOR_STYLE->Colors[i].z = jColor[2];
IM_NODE_EDITOR_STYLE->Colors[i].w = jColor[3];
env->ReleaseFloatArrayElements(jColors, jColor, 0);
env->DeleteLocalRef(jColors);
}
*/
public native void getColor(int styleColor, ImVec4 dstImVec4); /*
Jni::ImVec4Cpy(env, IM_NODE_EDITOR_STYLE->Colors[styleColor], dstImVec4);
*/
public native void setColor(int styleColor, float r, float g, float b, float a); /*
IM_NODE_EDITOR_STYLE->Colors[styleColor] = ImColor((float)r, (float)g, (float)b, (float)a);
*/
public native void setColor(int styleColor, int r, int g, int b, int a); /*
IM_NODE_EDITOR_STYLE->Colors[styleColor] = ImColor((int)r, (int)g, (int)b, (int)a);
*/
public native void setColor(int styleColor, int col); /*
IM_NODE_EDITOR_STYLE->Colors[styleColor] = ImColor(col);
*/
}
@@ -1,7 +1,6 @@
package imgui.nodeditor;
public final class ImNodeEditorStyleColor {
private ImNodeEditorStyleColor() {
}
@@ -23,5 +22,4 @@ public final class ImNodeEditorStyleColor {
public static final int FlowMarker = 15;
public static final int GroupBg = 16;
public static final int GroupBorder = 17;
}
@@ -1,7 +1,6 @@
package imgui.nodeditor;
public final class ImNodeEditorStyleVar {
private ImNodeEditorStyleVar() {
}
@@ -28,5 +27,4 @@ public final class ImNodeEditorStyleVar {
public static final int PinArrowWidth = 20;
public static final int GroupRounding = 21;
public static final int GroupBorderWidth = 22;
}