Add rendering implementation for LWJGL

This commit is contained in:
SpaiR committed 2019-12-29 23:59:34 +03:00
1 parent b01fe59dbb
commit dc59810566
59 files changed
+6728 -16

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
root = true
[*]
end_of_line = lf
indent_style = space
insert_final_newline = true
[*.{groovy,java}]
indent_size = 4
max_line_length = 160
trim_trailing_whitespace = true
+7 -15
View File
@@ -1,16 +1,8 @@
plugins {
id 'java'
}
group 'imgui'
version '1.0'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
allprojects {
group 'imgui-java'
version property('version')
repositories {
jcenter()
mavenCentral()
}
}
+19
View File
@@ -0,0 +1,19 @@
plugins {
id 'groovy'
}
repositories {
jcenter()
mavenCentral()
}
ext {
jnigenVersion = '1.9.10'
}
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation "com.badlogicgames.gdx:gdx-jnigen:$jnigenVersion"
}
@@ -0,0 +1,43 @@
package imgui.generate
import com.badlogic.gdx.jnigen.*
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.file.CopySpec
import org.gradle.api.tasks.TaskAction
@CompileStatic
class GenerateLibs extends DefaultTask {
String description = 'Generates native libraries using classes under ":imgui-binding" and Dear-ImGui itself from "imgui" submodule.'
private final String sourceDir = project.file('src/main/java')
private final String classpath = project.file('build/classes/java/main')
private final String jniDir = project.buildDir.path + '/jni'
private final String tmpFolder = project.buildDir.path + '/tmp'
private final String libsFolder = 'libsNative'
@TaskAction
void generate() {
// Generate h/cpp files for JNI
new NativeCodeGenerator().generate(sourceDir, classpath, jniDir)
// Copy ImGui h/cpp files
project.copy { CopySpec spec ->
spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') }
spec.from(project.file('src/main/native'))
spec.into(jniDir)
}
// Generate platform dependant ant configs and header files
def buildConfig = new BuildConfig('imgui-java', tmpFolder, libsFolder, jniDir)
def win64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Windows, true)
new AntScriptGenerator().generate(buildConfig, win64)
// Generate native libraries
BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', '-v', '-Dhas-compiler=true', '-Drelease=true', 'clean', 'postcompile')
BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
// Ant creates this folder in the root of the project. Since it will be empty we delete it
project.rootProject.file(libsFolder).deleteDir()
}
}
+1
View File
@@ -0,0 +1 @@
version=0.0.1
+1 -1
View File
@@ -1,4 +1,4 @@
#Sat Dec 14 21:13:09 MSK 2019
#Sat Dec 14 22:33:02 MSK 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+10
View File
@@ -0,0 +1,10 @@
import imgui.generate.GenerateLibs
plugins {
id 'java'
}
sourceCompatibility = 1.8
assemble.dependsOn clean
task generateLibs(type: GenerateLibs, dependsOn: assemble)
@@ -0,0 +1,38 @@
package imgui;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public final class DrawData {
public final static int vBufferSize = (4 + 1) * 4;
public final static int iBufferSize = 2;
public final static int cmdBufferSize = (1 + 4 + 1) * 4;
public int cmdListsCount; // Number of ImDrawList* to render
public int totalIdxCount; // For convenience, sum of all ImDrawList's IdxBuffer.Size
public int totalVtxCount;
public int totalCmdCount;
public float displayPosX;
public float displayPosY;
public float displaySizeX;
public float displaySizeY;
public float framebufferScaleX;
public float framebufferScaleY;
public ByteBuffer vByteBuffer;
public ByteBuffer iByteBuffer;
public ByteBuffer cmdByteBuffer;
public DrawData(ByteBuffer vByteBuffer, ByteBuffer iByteBuffer, ByteBuffer cmdByteBuffer) {
this.vByteBuffer = vByteBuffer;
this.iByteBuffer = iByteBuffer;
this.cmdByteBuffer = cmdByteBuffer;
}
public DrawData(int maxVertice, int maxIndices, int maxCmd) {
this.vByteBuffer = ByteBuffer.allocateDirect(maxVertice * vBufferSize);
this.iByteBuffer = ByteBuffer.allocateDirect(maxIndices * iBufferSize);
this.cmdByteBuffer = ByteBuffer.allocateDirect(maxCmd * cmdBufferSize);
vByteBuffer.order(ByteOrder.nativeOrder());
iByteBuffer.order(ByteOrder.nativeOrder());
cmdByteBuffer.order(ByteOrder.nativeOrder());
}
}
@@ -0,0 +1,128 @@
package imgui;
import imgui.enums.ImDrawCornerFlags;
public class ImDrawList {
public final static int TYPE_DEFAULT = 0;
public final static int TYPE_BACKGROUND = 1;
public final static int TYPE_FOREGROUND = 2;
private int type = TYPE_DEFAULT;
public ImDrawList(int type) {
this.type = type;
}
public void AddLine(float a_x, float a_y, float b_x, float b_y, int col) {
Native.AddLine(type, a_x, a_y, b_x, b_y, col);
}
public void AddLine(float a_x, float a_y, float b_x, float b_y, int col, float thinkness) {
Native.AddLine(type, a_x, a_y, b_x, b_y, col, thinkness);
}
public void AddRect(float a_x, float a_y, float b_x, float b_y, int col) {
Native.AddRect(type, a_x, a_y, b_x, b_y, col);
}
public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding) {
Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding);
}
public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags) {
Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue());
}
public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags, float thickness) {
Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue(), thickness);
}
public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col) {
Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col);
}
public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col, float rounding) {
Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col, rounding);
}
public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags) {
Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue());
}
public void AddRectFilledMultiColor(float a_x, float a_y, float b_x, float b_y, int col_upr_left, float col_upr_right, int col_bot_right, int col_bot_left) {
Native.AddRectFilledMultiColor(type, a_x, a_y, b_x, b_y, col_upr_left, col_upr_right, col_bot_right, col_bot_left);
}
public void AddQuad(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) {
Native.AddQuad(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col);
}
public void AddQuad(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col, float thickness) {
Native.AddQuad(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col, thickness);
}
public void AddQuadFilled(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) {
Native.AddQuadFilled(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col);
}
public void AddTriangle(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) {
Native.AddTriangle(type, a_x, a_y, b_x, b_y, c_x, c_y, col);
}
public void AddTriangle(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col, float thickness) {
Native.AddTriangle(type, a_x, a_y, b_x, b_y, c_x, c_y, col, thickness);
}
public void AddTriangleFilled(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) {
Native.AddTriangleFilled(type, a_x, a_y, b_x, b_y, c_x, c_y, col);
}
public void AddCircle(float centre_x, float centre_y, float radius, float col, int num_segments, float thickness) {
Native.AddCircle(type, centre_x, centre_y, radius, col, num_segments, thickness);
}
public void AddCircleFilled(float centre_x, float centre_y, float radius, float col) {
Native.AddCircleFilled(type, centre_x, centre_y, radius, col);
}
public void AddCircleFilled(float centre_x, float centre_y, float radius, float col, int num_segments) {
Native.AddCircleFilled(type, centre_x, centre_y, radius, col, num_segments);
}
public void AddText(float pos_x, float pos_y, int col, String text_begin) {
Native.AddText(type, pos_x, pos_y, col, text_begin);
}
public void AddText(float pos_x, float pos_y, int col, String text_begin, String text_end) {
Native.AddText(type, pos_x, pos_y, col, text_begin, text_end);
}
// TODO AddText
public void AddImage(int textureID, float a_x, float a_y, float b_x, float b_y) {
Native.AddImage(type, textureID, a_x, a_y, b_x, b_y);
}
public void AddImage(int textureID, float a_x, float a_y, float b_x, float b_y, float uv_a_x, float uv_a_y, float uv_b_x, float uv_b_y) {
Native.AddImage(type, textureID, a_x, a_y, b_x, b_y, uv_a_x, uv_a_y, uv_b_x, uv_b_y);
}
//TODO AddImageQuad, AddImageRounded, AddPolyline, AddConvexPolyFilled
public void AddBezierCurve(float pos0_x, float pos0_y, float cp0_x, float cp0_y, float cp1_x, float cp1_y, float pos1_x, float pos1_y, float col, float thickness) {
Native.AddBezierCurve(type, pos0_x, pos0_y, cp0_x, cp0_y, cp1_x, cp1_y, pos1_x, pos1_y, col, thickness);
}
public void ChannelsSplit(int count) {
Native.ChannelsSplit(type, count);
}
public void ChannelsMerge() {
Native.ChannelsMerge(type);
}
public void ChannelsSetCurrent(int n) {
Native.ChannelsSetCurrent(type, n);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,27 @@
package imgui;
public class ImGuiBoolean {
public static ImGuiBoolean TMP = new ImGuiBoolean();
boolean[] data = new boolean[]{false};
public ImGuiBoolean() {
}
public ImGuiBoolean(boolean value) {
setValue(value);
}
public boolean getValue() {
return this.data[0];
}
public void setValue(boolean value) {
this.data[0] = value;
}
@Override
public String toString() {
return String.valueOf(getValue());
}
}
@@ -0,0 +1,27 @@
package imgui;
public class ImGuiDouble {
public static ImGuiDouble TMP = new ImGuiDouble();
double[] data = new double[]{0.0d};
public ImGuiDouble() {
}
public ImGuiDouble(double value) {
setValue(value);
}
public double getValue() {
return this.data[0];
}
public void setValue(double value) {
this.data[0] = value;
}
@Override
public String toString() {
return String.valueOf(getValue());
}
}
@@ -0,0 +1,103 @@
package imgui;
import imgui.NativeCustomWidget.ImGuiCollapseLayoutOptions;
public class ImGuiEx {
protected ImGuiEx() {
}
public static void ShowLayoutDebug() {
NativeCustomWidget.ShowLayoutDebug();
}
public static void BeginLayout(String id, float sizeX, float sizeY) {
NativeCustomWidget.BeginLayout(id, sizeX, sizeY);
}
public static void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom) {
NativeCustomWidget.BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
}
public static void EndLayout() {
NativeCustomWidget.EndLayout();
}
public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY) {
return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
}
public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, options);
}
public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) {
NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
}
public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, options);
}
public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY) {
return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
}
public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, options);
}
public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) {
NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions);
}
public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) {
NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, options);
}
public static void EndCollapseFrameLayout() {
NativeCustomWidget.EndCollapseFrameLayout();
}
public static void EndCollapseLayout() {
NativeCustomWidget.EndCollapseLayout();
}
public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) {
NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY);
}
public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) {
NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY);
}
public static void EndAlign() {
NativeCustomWidget.EndAlign();
}
public static void AlignLayout(float alignX, float alignY) {
NativeCustomWidget.AlignLayout(alignX, alignY);
}
public static void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) {
NativeCustomWidget.AlignLayout(alignX, alignY, offsetX, offsetY);
}
// Helper methods
/**
* Packs the color components into a 32-bit integer with the format ABGR. Note that no range checking is performed for higher
* performance.
*
* @param r the red component, 0 - 255
* @param g the green component, 0 - 255
* @param b the blue component, 0 - 255
* @param a the alpha component, 0 - 255
* @return the packed color as a 32-bit int
*/
public static int colorToIntBits(int r, int g, int b, int a) {
return (a << 24) | (b << 16) | (g << 8) | r;
}
}
@@ -0,0 +1,27 @@
package imgui;
public class ImGuiFloat {
public static ImGuiFloat TMP = new ImGuiFloat();
float[] data = new float[]{0.0f};
public ImGuiFloat() {
}
public ImGuiFloat(float value) {
setValue(value);
}
public float getValue() {
return this.data[0];
}
public void setValue(float value) {
this.data[0] = value;
}
@Override
public String toString() {
return String.valueOf(getValue());
}
}
@@ -0,0 +1,35 @@
package imgui;
import imgui.enums.ImGuiConfigFlags;
public class ImGuiIO {
//------------------------------------------------------------------
// Output - Retrieve after calling NewFrame()
//------------------------------------------------------------------
public boolean WantCaptureMouse; // When io.WantCaptureMouse is true, imgui will use the mouse inputs, do not dispatch them to your main game/application (in both cases, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.).
public boolean WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, imgui will use the keyboard inputs, do not dispatch them to your main game/application (in both cases, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.).
public boolean WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active).
public boolean WantSetMousePos; // MousePos has been altered, back-end should reposition mouse on next frame. Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled.
public boolean WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. IMPORTANT: You need to clear io.WantSaveIniSettings yourself.
public boolean NavActive; // Directional navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag.
public boolean NavVisible; // Directional navigation is visible and allowed (will handle ImGuiKey_NavXXX events).
public float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames
public int MetricsRenderVertices; // Vertices output during last call to Render()
public int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3
public int MetricsRenderWindows; // Number of visible windows
public int MetricsActiveWindows; // Number of active windows
public int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts.
public float MouseDeltaX; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta.
public float MouseDeltaY;
public void SetConfigFlags(ImGuiConfigFlags flags) {
Native.SetConfigFlags(flags.getValue());
}
// TODO: Available after docking comes from BETA
// public void SetDockingFlags(boolean ConfigDockingNoSplit, boolean ConfigDockingWithShift, boolean ConfigDockingAlwaysTabBar, boolean ConfigDockingTransparentPayload) {
// Native.SetDockingFlags(ConfigDockingNoSplit, ConfigDockingWithShift, ConfigDockingAlwaysTabBar, ConfigDockingTransparentPayload);
// }
}
@@ -0,0 +1,8 @@
package imgui;
public class ImGuiInputTextData {
public int size;
public int maxChar = -1;
public String allowedChar = "";
boolean isDirty;
}
@@ -0,0 +1,27 @@
package imgui;
public class ImGuiInt {
public static ImGuiInt TMP = new ImGuiInt();
int[] data = new int[]{0};
public ImGuiInt() {
}
public ImGuiInt(int value) {
setValue(value);
}
public int getValue() {
return this.data[0];
}
public void setValue(int value) {
this.data[0] = value;
}
@Override
public String toString() {
return String.valueOf(getValue());
}
}
@@ -0,0 +1,42 @@
package imgui;
public class ImGuiString {
public static ImGuiString TMP = new ImGuiString();
final ImGuiInputTextData inputData = new ImGuiInputTextData();
byte[] data;
private String text;
public ImGuiString() {
this(100);
}
public ImGuiString(int size) {
data = new byte[size];
}
public ImGuiString(String text) {
this(100);
setValue(text);
}
public String getValue() {
if (inputData.isDirty) {
inputData.isDirty = false;
text = new String(data, 0, inputData.size);
}
return text;
}
public void setValue(String value) {
inputData.size = value.length();
text = value;
for (int i = 0; i < inputData.size; i++) {
data[i] = (byte) value.charAt(i);
}
}
@Override
public String toString() {
return getValue();
}
}
@@ -0,0 +1,7 @@
package imgui;
public class ImGuiStyle {
public float ItemInnerSpacingX;
public float ItemInnerSpacingY;
}
@@ -0,0 +1,15 @@
package imgui;
public class ImVec2 {
public static ImVec2 TMP = new ImVec2();
public float x;
public float y;
public ImVec2() {
}
public ImVec2(float x, float y) {
this.x = x;
this.y = y;
}
}
@@ -0,0 +1,8 @@
package imgui;
public class ImVec4 extends ImVec2 {
public static ImVec4 TMP = new ImVec4();
public float z;
public float w;
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,168 @@
package imgui;
import imgui.enums.ImDrawCornerFlags;
class NativeCustomWidget {
public static ImGuiCollapseLayoutOptions defaultOptions = new ImGuiCollapseLayoutOptions();
// @formatter:off
/*JNI
#include <imgui_layout_widget.h>
jfieldID paddingLeftID;
jfieldID paddingRightID;
jfieldID paddingTopID;
jfieldID paddingBottomID;
jfieldID arrowColorID;
jfieldID arrowBackgroundHoveredColorID;
jfieldID arrowBackgroundClickedColorID;
jfieldID frameColorID;
jfieldID borderColorID;
jfieldID borderRoundID;
jfieldID roundingCornersID;
*/
static native void init() /*-{ }-*/; /*
jclass jLayoutOptionsClass = env->FindClass("imgui/NativeCustomWidget");
paddingLeftID = env->GetFieldID(jLayoutOptionsClass, "paddingLeft", "F");
paddingRightID = env->GetFieldID(jLayoutOptionsClass, "paddingRight", "F");
paddingTopID = env->GetFieldID(jLayoutOptionsClass, "paddingTop", "F");
paddingBottomID = env->GetFieldID(jLayoutOptionsClass, "paddingBottom", "F");
arrowColorID = env->GetFieldID(jLayoutOptionsClass, "arrowColor", "I");
arrowBackgroundHoveredColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundHoveredColor", "I");
arrowBackgroundClickedColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundClickedColor", "I");
frameColorID = env->GetFieldID(jLayoutOptionsClass, "frameColor", "I");
borderColorID = env->GetFieldID(jLayoutOptionsClass, "borderColor", "I");
borderRoundID = env->GetFieldID(jLayoutOptionsClass, "borderRound", "I");
roundingCornersID = env->GetFieldID(jLayoutOptionsClass, "roundingCorners", "I");
*/
static {
init();
}
static native void ShowLayoutDebug() /*-{ }-*/; /*
ImGuiEx::ShowLayoutDebug();
*/
static native void BeginLayout(String id, float sizeX, float sizeY); /*-{ }-*/; /*
ImGuiEx::BeginLayout(id, sizeX, sizeY);
*/
static native void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom); /*-{ }-*/; /*
ImGuiEx::BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
*/
static native void EndLayout(); /*-{ }-*/; /*
ImGuiEx::EndLayout();
*/
static native boolean BeginCollapseLayoutEx2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
ImGuiCollapseLayoutOptions options;
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
options.frameColor = env->GetIntField (jOptions, frameColorID);
options.borderColor = env->GetIntField (jOptions, borderColorID);
options.borderRound = env->GetIntField (jOptions, borderRoundID);
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
return ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options);
*/
static native void BeginCollapseLayoutEx(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
ImGuiCollapseLayoutOptions options;
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
options.frameColor = env->GetIntField (jOptions, frameColorID);
options.borderColor = env->GetIntField (jOptions, borderColorID);
options.borderRound = env->GetIntField (jOptions, borderRoundID);
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
ImGuiEx::BeginCollapseLayoutEx(&isOpen[0], title, sizeX, sizeY, options);
*/
static native boolean BeginCollapseLayout2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
ImGuiCollapseLayoutOptions options;
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
options.frameColor = env->GetIntField (jOptions, frameColorID);
options.borderColor = env->GetIntField (jOptions, borderColorID);
options.borderRound = env->GetIntField (jOptions, borderRoundID);
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
return ImGuiEx::BeginCollapseLayout(title, sizeX, sizeY, options);
*/
static native void BeginCollapseLayout(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /*
ImGuiCollapseLayoutOptions options;
options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID);
options.paddingRight = env->GetFloatField (jOptions, paddingRightID);
options.paddingTop = env->GetFloatField (jOptions, paddingTopID);
options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID);
options.arrowColor = env->GetIntField (jOptions, arrowColorID);
options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID);
options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID);
options.frameColor = env->GetIntField (jOptions, frameColorID);
options.borderColor = env->GetIntField (jOptions, borderColorID);
options.borderRound = env->GetIntField (jOptions, borderRoundID);
options.roundingCorners = env->GetIntField (jOptions, roundingCornersID);
ImGuiEx::BeginCollapseLayout(&isOpen[0], title, sizeX, sizeY, options);
*/
static native void EndCollapseFrameLayout(); /*-{ }-*/; /*
ImGuiEx::EndCollapseFrameLayout();
*/
static native void EndCollapseLayout(); /*-{ }-*/; /*
ImGuiEx::EndCollapseLayout();
*/
static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) /*-{ }-*/; /*
ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY);
*/
static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /*
ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY);
*/
static native void EndAlign() /*-{ }-*/; /*
ImGuiEx::EndAlign();
*/
static native void AlignLayout(float alignX, float alignY) /*-{ }-*/; /*
ImGuiEx::AlignLayout(alignX, alignY);
*/
static native void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /*
ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY);
*/
// @formatter:on
public static class ImGuiCollapseLayoutOptions {
public float paddingLeft = 2;
public float paddingRight = 2;
public float paddingTop = 2;
public float paddingBottom = 2;
public int arrowColor = ImGuiEx.colorToIntBits(0xFF, 0xFF, 0xFF, 0xFF);
public int arrowBackgroundHoveredColor = ImGuiEx.colorToIntBits(0x77, 0x77, 0x77, 0xFF);
public int arrowBackgroundClickedColor = ImGuiEx.colorToIntBits(0x55, 0x55, 0x55, 0xFF);
public int frameColor = ImGuiEx.colorToIntBits(0x24, 0x24, 0x24, 0xFF);
public int borderColor = ImGuiEx.colorToIntBits(0x40, 0x40, 0x49, 0xFF);
public int borderRound = 4;
public int roundingCorners = ImDrawCornerFlags.TopLeft.or(ImDrawCornerFlags.TopRight).getValue();
}
}
@@ -0,0 +1,28 @@
package imgui;
/**
* Same as {@link Native} but "imgui_internal.h" API.
*/
class NativeInternal {
// @formatter:off
/*JNI
#include <imgui.h>
#include <imgui_internal.h>
*/
public static native void PushMultiItemsWidths(int components, float w_full) /*-{ }-*/; /*
ImGui::PushMultiItemsWidths(components, w_full);
*/
public static native boolean ItemAdd(float x1, float y1, float x2, float y2, String id) /*-{ }-*/; /*
ImGuiID imGuiID = ImGui::GetID(id);
return ImGui::ItemAdd(ImRect(x1, y1, x2, y2), imGuiID);
*/
public static native void ItemSize(float x1, float y1, float x2, float y2, float text_offset_y) /*-{ }-*/; /*
ImGui::ItemSize(ImRect(x1, y1, x2, y2), text_offset_y);
*/
// @formatter:on
}
@@ -0,0 +1,18 @@
package imgui;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class TexDataRGBA32 {
public int width;
public int height;
public ByteBuffer pixelBuffer;
public TexDataRGBA32() {
int pixelMax = 131072;
ByteBuffer buffer = ByteBuffer.allocateDirect(pixelMax);
buffer.order(ByteOrder.nativeOrder());
pixelBuffer = buffer;
}
}
@@ -0,0 +1,28 @@
package imgui.enums;
public class ImDrawCornerFlags {
public static ImDrawCornerFlags TopLeft = new ImDrawCornerFlags(1 << 0);
public static ImDrawCornerFlags TopRight = new ImDrawCornerFlags(1 << 1);
public static ImDrawCornerFlags BotLeft = new ImDrawCornerFlags(1 << 2);
public static ImDrawCornerFlags BotRight = new ImDrawCornerFlags(1 << 3);
public static ImDrawCornerFlags Top = new ImDrawCornerFlags(TopLeft.getValue() | TopRight.getValue());
public static ImDrawCornerFlags Bot = new ImDrawCornerFlags(BotLeft.getValue() | BotRight.getValue());
public static ImDrawCornerFlags Left = new ImDrawCornerFlags(TopLeft.getValue() | BotLeft.getValue());
public static ImDrawCornerFlags Right = new ImDrawCornerFlags(TopRight.getValue() | BotRight.getValue());
public static ImDrawCornerFlags All = new ImDrawCornerFlags(0xF);
private static ImDrawCornerFlags Custom = new ImDrawCornerFlags(0);
int value;
private ImDrawCornerFlags(int code) {
value = code;
}
public ImDrawCornerFlags or(ImDrawCornerFlags otherEnum) {
ImDrawCornerFlags.Custom.value = value | otherEnum.value;
return ImDrawCornerFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,26 @@
package imgui.enums;
/**
* Back-end capabilities flags stored in io.BackendFlags. Set by imgui_impl_xxx or custom back-end.
*/
public class ImGuiBackendFlags {
public static ImGuiBackendFlags None = new ImGuiBackendFlags(0);
public static ImGuiBackendFlags HasGamepad = new ImGuiBackendFlags(1 << 0);
public static ImGuiBackendFlags HasMouseCursors = new ImGuiBackendFlags(1 << 1);
public static ImGuiBackendFlags HasSetMousePos = new ImGuiBackendFlags(1 << 2);
private static ImGuiBackendFlags Custom = new ImGuiBackendFlags(0);
int value;
private ImGuiBackendFlags(int code) {
value = code;
}
public ImGuiBackendFlags or(ImGuiBackendFlags otherEnum) {
ImGuiBackendFlags.Custom.value = value | otherEnum.value;
return ImGuiBackendFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,89 @@
package imgui.enums;
public enum ImGuiCol {
Text(0),
TextDisabled(1),
/**
* Background of normal windows
*/
WindowBg(2),
/**
* Background of child windows
*/
ChildBg(3),
/**
* Background of popups, menus, tooltips windows
*/
PopupBg(4),
Border(5),
BorderShadow(6),
/**
* Background of checkbox, radio button, plot, slider, text input
*/
FrameBg(7),
FrameBgHovered(8),
FrameBgActive(9),
TitleBg(10),
TitleBgActive(11),
TitleBgCollapsed(12),
MenuBarBg(13),
ScrollbarBg(14),
ScrollbarGrab(15),
ScrollbarGrabHovered(16),
ScrollbarGrabActive(17),
CheckMark(18),
SliderGrab(19),
SliderGrabActive(20),
Button(21),
ButtonHovered(22),
ButtonActive(23),
Header(24),
HeaderHovered(25),
HeaderActive(26),
Separator(27),
SeparatorHovered(28),
SeparatorActive(29),
ResizeGrip(30),
ResizeGripHovered(31),
ResizeGripActive(32),
Tab(33),
TabHovered(34),
TabActive(35),
TabUnfocused(36),
TabUnfocusedActive(37),
DockingPrevie(38),
DockingEmptyBg(39),
PlotLines(40),
PlotLinesHovered(41),
PlotHistogram(42),
PlotHistogramHovered(43),
TextSelectedBg(44),
DragDropTarget(45),
/**
* Gamepad/keyboard: current highlighted item
*/
NavHighlight(46),
/**
* Highlight window when using CTRL+TAB
*/
NavWindowingHighlight(47),
/**
* Darken/colorize entire screen behind the CTRL+TAB window list, when active
*/
NavWindowingDimBg(48),
/**
* Darken/colorize entire screen behind a modal window, when one is active
*/
ModalWindowDimBg(49),
COUNT(48);
int value;
ImGuiCol(int code) {
value = code;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,47 @@
package imgui.enums;
/**
* Enumeration for GetMouseCursor()
* User code may request binding to display given cursor by calling SetMouseCursor(), which is why we have some cursors that are marked unused here
*/
public class ImGuiColorEditFlags {
public static ImGuiColorEditFlags None = new ImGuiColorEditFlags(0);
public static ImGuiColorEditFlags NoAlpha = new ImGuiColorEditFlags(1 << 1);
public static ImGuiColorEditFlags NoPicker = new ImGuiColorEditFlags(1 << 2);
public static ImGuiColorEditFlags NoOptions = new ImGuiColorEditFlags(1 << 3);
public static ImGuiColorEditFlags NoSmallPreview = new ImGuiColorEditFlags(1 << 4);
public static ImGuiColorEditFlags NoInputs = new ImGuiColorEditFlags(1 << 5);
public static ImGuiColorEditFlags NoTooltip = new ImGuiColorEditFlags(1 << 6);
public static ImGuiColorEditFlags NoLabel = new ImGuiColorEditFlags(1 << 7);
public static ImGuiColorEditFlags NoSidePreview = new ImGuiColorEditFlags(1 << 8);
public static ImGuiColorEditFlags NoDragDrop = new ImGuiColorEditFlags(1 << 9);
public static ImGuiColorEditFlags AlphaBar = new ImGuiColorEditFlags(1 << 16);
public static ImGuiColorEditFlags AlphaPreview = new ImGuiColorEditFlags(1 << 17);
public static ImGuiColorEditFlags AlphaPreviewHalf = new ImGuiColorEditFlags(1 << 18);
public static ImGuiColorEditFlags HDR = new ImGuiColorEditFlags(1 << 19);
public static ImGuiColorEditFlags DisplayRGB = new ImGuiColorEditFlags(1 << 20);
public static ImGuiColorEditFlags DisplayHSV = new ImGuiColorEditFlags(1 << 21);
public static ImGuiColorEditFlags DisplayHex = new ImGuiColorEditFlags(1 << 22);
public static ImGuiColorEditFlags Uint8 = new ImGuiColorEditFlags(1 << 23);
public static ImGuiColorEditFlags Float = new ImGuiColorEditFlags(1 << 24);
public static ImGuiColorEditFlags PickerHueBar = new ImGuiColorEditFlags(1 << 25);
public static ImGuiColorEditFlags PickerHueWheel = new ImGuiColorEditFlags(1 << 26);
public static ImGuiColorEditFlags InputRGB = new ImGuiColorEditFlags(1 << 27);
public static ImGuiColorEditFlags InputHSV = new ImGuiColorEditFlags(1 << 28);
public static ImGuiColorEditFlags OptionsDefault = new ImGuiColorEditFlags(Uint8.getValue() | DisplayRGB.getValue() | InputRGB.getValue() | PickerHueBar.getValue());
private static ImGuiColorEditFlags Custom = new ImGuiColorEditFlags(0);
int value;
private ImGuiColorEditFlags(int code) {
value = code;
}
public ImGuiColorEditFlags or(ImGuiColorEditFlags otherEnum) {
ImGuiColorEditFlags.Custom.value = value | otherEnum.value;
return ImGuiColorEditFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,31 @@
package imgui.enums;
/**
* Flags for ImGui::BeginCombo()
*/
public class ImGuiComboFlags {
public static ImGuiComboFlags None = new ImGuiComboFlags(0);
public static ImGuiComboFlags PopupAlignLeft = new ImGuiComboFlags(1 << 0);
public static ImGuiComboFlags HeightSmall = new ImGuiComboFlags(1 << 1);
public static ImGuiComboFlags HeightRegular = new ImGuiComboFlags(1 << 2);
public static ImGuiComboFlags HeightLarge = new ImGuiComboFlags(1 << 3);
public static ImGuiComboFlags HeightLargest = new ImGuiComboFlags(1 << 4);
public static ImGuiComboFlags NoArrowButton = new ImGuiComboFlags(1 << 5);
public static ImGuiComboFlags NoPreview = new ImGuiComboFlags(1 << 6);
public static ImGuiComboFlags HeightMask = new ImGuiComboFlags(HeightSmall.getValue() | HeightRegular.getValue() | HeightLarge.getValue() | HeightLargest.getValue());
private static ImGuiComboFlags Custom = new ImGuiComboFlags(0);
int value;
private ImGuiComboFlags(int code) {
value = code;
}
public ImGuiComboFlags or(ImGuiComboFlags otherEnum) {
ImGuiComboFlags.Custom.value = value | otherEnum.value;
return ImGuiComboFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,28 @@
package imgui.enums;
/**
* Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
* Represent a condition.
* Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always.
*/
public class ImGuiCond {
public static ImGuiCond Always = new ImGuiCond(1 << 0);
public static ImGuiCond Once = new ImGuiCond(1 << 1);
public static ImGuiCond FirstUseEver = new ImGuiCond(1 << 2);
public static ImGuiCond Appearing = new ImGuiCond(1 << 3);
private static ImGuiCond Custom = new ImGuiCond(0);
int value;
private ImGuiCond(int code) {
value = code;
}
public ImGuiCond or(ImGuiCond otherEnum) {
ImGuiCond.Custom.value = value | otherEnum.value;
return ImGuiCond.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,32 @@
package imgui.enums;
/**
* Configuration flags stored in io.ConfigFlags. Set by user/application.
*/
public class ImGuiConfigFlags {
public static ImGuiConfigFlags None = new ImGuiConfigFlags(0);
public static ImGuiConfigFlags NavEnableKeyboard = new ImGuiConfigFlags(1 << 0);
public static ImGuiConfigFlags NavEnableGamepad = new ImGuiConfigFlags(1 << 1);
public static ImGuiConfigFlags NavEnableSetMousePos = new ImGuiConfigFlags(1 << 2);
public static ImGuiConfigFlags NavNoCaptureKeyboard = new ImGuiConfigFlags(1 << 3);
public static ImGuiConfigFlags NoMouse = new ImGuiConfigFlags(1 << 4);
public static ImGuiConfigFlags NoMouseCursorChange = new ImGuiConfigFlags(1 << 5);
public static ImGuiConfigFlags DockingEnable = new ImGuiConfigFlags(1 << 6);
public static ImGuiConfigFlags IsSRGB = new ImGuiConfigFlags(1 << 20);
public static ImGuiConfigFlags IsTouchScreen = new ImGuiConfigFlags(1 << 21);
private static ImGuiConfigFlags Custom = new ImGuiConfigFlags(0);
int value;
private ImGuiConfigFlags(int code) {
value = code;
}
public ImGuiConfigFlags or(ImGuiConfigFlags otherEnum) {
ImGuiConfigFlags.Custom.value = value | otherEnum.value;
return ImGuiConfigFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,28 @@
package imgui.enums;
/**
* A primary data type
*/
public enum ImGuiDataType {
S8(0),
U8(1),
S16(2),
U16(3),
S32(4),
U32(5),
S64(6),
U64(7),
Float(8),
Double(9),
COUNT(10);
int value;
ImGuiDataType(int code) {
value = code;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,20 @@
package imgui.enums;
public enum ImGuiDir {
None(-1),
Left(0),
Right(1),
Up(2),
Down(3),
COUNT(4);
private final int code;
ImGuiDir(int code) {
this.code = code;
}
public int toInt() {
return code;
}
}
@@ -0,0 +1,25 @@
package imgui.enums;
public class ImGuiDockNodeFlags {
public static ImGuiDockNodeFlags KeepAliveOnly = new ImGuiDockNodeFlags(1 << 0);
public static ImGuiDockNodeFlags NoDockingInCentralNode = new ImGuiDockNodeFlags(1 << 2);
public static ImGuiDockNodeFlags PassthruCentralNode = new ImGuiDockNodeFlags(1 << 3);
public static ImGuiDockNodeFlags NoSplit = new ImGuiDockNodeFlags(1 << 4);
public static ImGuiDockNodeFlags NoResize = new ImGuiDockNodeFlags(1 << 5);
public static ImGuiDockNodeFlags AutoHideTabBar = new ImGuiDockNodeFlags(1 << 6);
private static ImGuiDockNodeFlags Custom = new ImGuiDockNodeFlags(0);
int value;
private ImGuiDockNodeFlags(int code) {
value = code;
}
public ImGuiDockNodeFlags or(ImGuiDockNodeFlags otherEnum) {
ImGuiDockNodeFlags.Custom.value = value | otherEnum.value;
return ImGuiDockNodeFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,37 @@
package imgui.enums;
/**
* Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered()
* Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ!
* Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls.
*/
public class ImGuiDragDropFlags {
public static ImGuiDragDropFlags None = new ImGuiDragDropFlags(0);
// BeginDragDropSource() flags
public static ImGuiDragDropFlags SourceNoPreviewTooltip = new ImGuiDragDropFlags(1 << 0);
public static ImGuiDragDropFlags SourceNoDisableHover = new ImGuiDragDropFlags(1 << 1);
public static ImGuiDragDropFlags SourceNoHoldToOpenOthers = new ImGuiDragDropFlags(1 << 2);
public static ImGuiDragDropFlags SourceAllowNullID = new ImGuiDragDropFlags(1 << 3);
public static ImGuiDragDropFlags SourceExtern = new ImGuiDragDropFlags(1 << 4);
public static ImGuiDragDropFlags SourceAutoExpirePayload = new ImGuiDragDropFlags(1 << 5);
// AcceptDragDropPayload() flags
public static ImGuiDragDropFlags AcceptBeforeDelivery = new ImGuiDragDropFlags(1 << 10);
public static ImGuiDragDropFlags AcceptNoDrawDefaultRect = new ImGuiDragDropFlags(1 << 11);
public static ImGuiDragDropFlags AcceptNoPreviewTooltip = new ImGuiDragDropFlags(1 << 12);
public static ImGuiDragDropFlags AcceptPeekOnly = new ImGuiDragDropFlags(AcceptBeforeDelivery.getValue() | AcceptNoDrawDefaultRect.getValue());
private static ImGuiDragDropFlags Custom = new ImGuiDragDropFlags(0);
int value;
private ImGuiDragDropFlags(int code) {
value = code;
}
public ImGuiDragDropFlags or(ImGuiDragDropFlags otherEnum) {
ImGuiDragDropFlags.Custom.value = value | otherEnum.value;
return ImGuiDragDropFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,27 @@
package imgui.enums;
/**
* Flags for ImGui::IsWindowFocused()
*/
public class ImGuiFocusedFlags {
public static ImGuiFocusedFlags None = new ImGuiFocusedFlags(0);
public static ImGuiFocusedFlags ChildWindows = new ImGuiFocusedFlags(1 << 0);
public static ImGuiFocusedFlags RootWindow = new ImGuiFocusedFlags(1 << 1);
public static ImGuiFocusedFlags AnyWindow = new ImGuiFocusedFlags(1 << 2);
public static ImGuiFocusedFlags RootAndChildWindows = new ImGuiFocusedFlags(RootWindow.getValue() | ChildWindows.getValue());
private static ImGuiFocusedFlags Custom = new ImGuiFocusedFlags(0);
int value;
private ImGuiFocusedFlags(int code) {
value = code;
}
public ImGuiFocusedFlags or(ImGuiFocusedFlags otherEnum) {
ImGuiFocusedFlags.Custom.value = value | otherEnum.value;
return ImGuiFocusedFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,35 @@
package imgui.enums;
/**
* Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered()
* Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ!
* Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls.
*/
public class ImGuiHoveredFlags {
public static ImGuiHoveredFlags None = new ImGuiHoveredFlags(0);
public static ImGuiHoveredFlags ChildWindows = new ImGuiHoveredFlags(1 << 0);
public static ImGuiHoveredFlags RootWindow = new ImGuiHoveredFlags(1 << 1);
public static ImGuiHoveredFlags AnyWindow = new ImGuiHoveredFlags(1 << 2);
public static ImGuiHoveredFlags AllowWhenBlockedByPopup = new ImGuiHoveredFlags(1 << 3);
// public static ImGuiHoveredFlags AllowWhenBlockedByModal = new ImGuiHoveredFlags(1 << 4);
public static ImGuiHoveredFlags AllowWhenBlockedByActiveItem = new ImGuiHoveredFlags(1 << 5);
public static ImGuiHoveredFlags AllowWhenOverlapped = new ImGuiHoveredFlags(1 << 6);
public static ImGuiHoveredFlags AllowWhenDisabled = new ImGuiHoveredFlags(1 << 7);
public static ImGuiHoveredFlags RectOnly = new ImGuiHoveredFlags(AllowWhenBlockedByPopup.getValue() | AllowWhenBlockedByActiveItem.getValue() | AllowWhenOverlapped.getValue());
public static ImGuiHoveredFlags RootAndChildWindows = new ImGuiHoveredFlags(RootWindow.getValue() | ChildWindows.getValue());
private static ImGuiHoveredFlags Custom = new ImGuiHoveredFlags(0);
int value;
private ImGuiHoveredFlags(int code) {
value = code;
}
public ImGuiHoveredFlags or(ImGuiHoveredFlags otherEnum) {
ImGuiHoveredFlags.Custom.value = value | otherEnum.value;
return ImGuiHoveredFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,99 @@
package imgui.enums;
/**
* Flags for ImGui::InputText()
*/
public class ImGuiInputTextFlags {
public static ImGuiInputTextFlags None = new ImGuiInputTextFlags(0);
/**
* Allow 0123456789.+-*
*/
public static ImGuiInputTextFlags CharsDecimal = new ImGuiInputTextFlags(1 << 0);
/**
* Allow 0123456789ABCDEFabcdef
*/
public static ImGuiInputTextFlags CharsHexadecimal = new ImGuiInputTextFlags(1 << 1);
/**
* Turn a..z into A..Z
*/
public static ImGuiInputTextFlags CharsUppercase = new ImGuiInputTextFlags(1 << 2);
/**
* Filter out spaces, tabs
*/
public static ImGuiInputTextFlags CharsNoBlank = new ImGuiInputTextFlags(1 << 3);
/**
* Select entire text when first taking mouse focus
*/
public static ImGuiInputTextFlags AutoSelectAll = new ImGuiInputTextFlags(1 << 4);
/**
* Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
*/
public static ImGuiInputTextFlags EnterReturnsTrue = new ImGuiInputTextFlags(1 << 5);
/**
* Callback on pressing TAB (for completion handling)
*/
public static ImGuiInputTextFlags CallbackCompletion = new ImGuiInputTextFlags(1 << 6);
/**
* Callback on pressing Up/Down arrows (for history handling)
*/
public static ImGuiInputTextFlags CallbackHistory = new ImGuiInputTextFlags(1 << 7);
/**
* Callback on each iteration. User code may query cursor position, modify text buffer.
*/
public static ImGuiInputTextFlags CallbackAlways = new ImGuiInputTextFlags(1 << 8);
/**
* Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
*/
public static ImGuiInputTextFlags CallbackCharFilter = new ImGuiInputTextFlags(1 << 9);
/**
* Pressing TAB input a '\t' character into the text field
*/
public static ImGuiInputTextFlags AllowTabInput = new ImGuiInputTextFlags(1 << 10);
/**
* In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter).
*/
public static ImGuiInputTextFlags CtrlEnterForNewLine = new ImGuiInputTextFlags(1 << 11);
/**
* Disable following the cursor horizontally
*/
public static ImGuiInputTextFlags NoHorizontalScroll = new ImGuiInputTextFlags(1 << 12);
/**
* Insert mode
*/
public static ImGuiInputTextFlags AlwaysInsertMode = new ImGuiInputTextFlags(1 << 13);
/**
* Read-only mode
*/
public static ImGuiInputTextFlags ReadOnly = new ImGuiInputTextFlags(1 << 14);
/**
* Password mode, display all characters as '*'
*/
public static ImGuiInputTextFlags Password = new ImGuiInputTextFlags(1 << 15);
/**
* Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
*/
public static ImGuiInputTextFlags NoUndoRedo = new ImGuiInputTextFlags(1 << 16);
/**
* Allow 0123456789.+-*\\/eE (Scientific notation input)
*/
public static ImGuiInputTextFlags CharsScientific = new ImGuiInputTextFlags(1 << 17);
/**
* Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
*/
public static ImGuiInputTextFlags CallbackResize = new ImGuiInputTextFlags(1 << 18);
private static ImGuiInputTextFlags Custom = new ImGuiInputTextFlags(0);
public int data;
private ImGuiInputTextFlags(int code) {
data = code;
}
public ImGuiInputTextFlags or(ImGuiInputTextFlags otherEnum) {
ImGuiInputTextFlags.Custom.data = data | otherEnum.data;
return ImGuiInputTextFlags.Custom;
}
public int getValue() {
return data;
}
}
@@ -0,0 +1,39 @@
package imgui.enums;
/**
* User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
*/
public enum ImGuiKey {
Tab(0),
LeftArrow(1),
RightArrow(2),
UpArrow(3),
DownArrow(4),
PageUp(5),
PageDown(6),
Home(7),
End(8),
Insert(9),
Delete(10),
Backspace(11),
Space(12),
Enter(13),
Escape(14),
A(15),
C(16),
V(17),
X(18),
Y(19),
Z(20),
COUNT(21);
private final int code;
ImGuiKey(int code) {
this.code = code;
}
public int getValue() {
return code;
}
}
@@ -0,0 +1,28 @@
package imgui.enums;
/**
* Enumeration for GetMouseCursor()
* User code may request binding to display given cursor by calling SetMouseCursor(), which is why we have some cursors that are marked unused here
*/
public enum ImGuiMouseCursor {
None(-1),
Arrow(0),
TextInput(1),
ResizeAll(2),
ResizeNS(3),
ResizeEW(4),
ResizeNESW(5),
ResizeNWSE(6),
Hand(7),
COUNT(8);
int value;
ImGuiMouseCursor(int code) {
value = code;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,36 @@
package imgui.enums;
/**
* Gamepad/Keyboard directional navigation
* Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays.
* Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Back-end: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame().
* Read instructions in imgui.cpp for more details. Download PNG/PSD at http://goo.gl/9LgVZW.
**/
public enum ImGuiNavInput {
Activate(0),
Cancel(1),
Input(2),
Menu(3),
DpadLeft(4),
DpadRight(5),
DpadUp(6),
DpadDown(7),
LStickLeft(8),
LStickRight(9),
LStickUp(10),
LStickDown(11),
FocusPrev(12),
FocusNext(13),
TweakSlow(14),
TweakFast(15);
private final int code;
ImGuiNavInput(int code) {
this.code = code;
}
public int toInt() {
return code;
}
}
@@ -0,0 +1,27 @@
package imgui.enums;
/**
* Flags for ImGui::Selectable()
*/
public class ImGuiSelectableFlags {
public static ImGuiSelectableFlags None = new ImGuiSelectableFlags(0);
public static ImGuiSelectableFlags DontClosePopups = new ImGuiSelectableFlags(1 << 0);
public static ImGuiSelectableFlags SpanAllColumns = new ImGuiSelectableFlags(1 << 1);
public static ImGuiSelectableFlags AllowDoubleClick = new ImGuiSelectableFlags(1 << 2);
public static ImGuiSelectableFlags Disabled = new ImGuiSelectableFlags(1 << 3);
private static ImGuiSelectableFlags Custom = new ImGuiSelectableFlags(0);
int value;
private ImGuiSelectableFlags(int code) {
value = code;
}
public ImGuiSelectableFlags or(ImGuiSelectableFlags otherEnum) {
ImGuiSelectableFlags.Custom.value = value | otherEnum.value;
return ImGuiSelectableFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,38 @@
package imgui.enums;
public enum ImGuiStyleVar {
Alpha(0),
WindowPadding(1),
WindowRounding(2),
WindowBorderSize(3),
WindowMinSize(4),
WindowTitleAlign(5),
ChildRounding(6),
ChildBorderSize(7),
PopupRounding(8),
PopupBorderSize(9),
FramePadding(10),
FrameRounding(11),
ImGuiStyleVar_FrameBorderSize(12),
ItemSpacing(13),
ItemInnerSpacing(14),
IndentSpacing(15),
ScrollbarSize(16),
ScrollbarRounding(17),
GrabMinSize(18),
GrabRounding(19),
TabRounding(20),
ButtonTextAlign(21),
SelectableTextAlign(22),
COUNT(23);
int value;
ImGuiStyleVar(int code) {
value = code;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,33 @@
package imgui.enums;
/**
* Flags for ImGui::BeginTabBar()
*/
public class ImGuiTabBarFlags {
public static ImGuiTabBarFlags None = new ImGuiTabBarFlags(0);
public static ImGuiTabBarFlags Reorderable = new ImGuiTabBarFlags(1 << 0);
public static ImGuiTabBarFlags AutoSelectNewTabs = new ImGuiTabBarFlags(1 << 1);
public static ImGuiTabBarFlags TabListPopupButton = new ImGuiTabBarFlags(1 << 2);
public static ImGuiTabBarFlags NoCloseWithMiddleMouseButton = new ImGuiTabBarFlags(1 << 3);
public static ImGuiTabBarFlags NoTabListScrollingButtons = new ImGuiTabBarFlags(1 << 4);
public static ImGuiTabBarFlags NoTooltip = new ImGuiTabBarFlags(1 << 5);
public static ImGuiTabBarFlags FittingPolicyResizeDown = new ImGuiTabBarFlags(1 << 6);
public static ImGuiTabBarFlags FittingPolicyScroll = new ImGuiTabBarFlags(1 << 7);
public static ImGuiTabBarFlags FittingPolicyMask = new ImGuiTabBarFlags(FittingPolicyResizeDown.getValue() | FittingPolicyScroll.getValue());
public static ImGuiTabBarFlags FittingPolicyDefault = new ImGuiTabBarFlags(FittingPolicyResizeDown.getValue());
private static ImGuiTabBarFlags Custom = new ImGuiTabBarFlags(0);
int value;
private ImGuiTabBarFlags(int code) {
value = code;
}
public ImGuiTabBarFlags or(ImGuiTabBarFlags otherEnum) {
ImGuiTabBarFlags.Custom.value = value | otherEnum.value;
return ImGuiTabBarFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,27 @@
package imgui.enums;
/**
* Flags for ImGui::BeginTabItem()
*/
public class ImGuiTabItemFlags {
public static ImGuiTabItemFlags None = new ImGuiTabItemFlags(0);
public static ImGuiTabItemFlags UnsavedDocument = new ImGuiTabItemFlags(1 << 0);
public static ImGuiTabItemFlags SetSelected = new ImGuiTabItemFlags(1 << 1);
public static ImGuiTabItemFlags NoCloseWithMiddleMouseButton = new ImGuiTabItemFlags(1 << 2);
public static ImGuiTabItemFlags NoPushId = new ImGuiTabItemFlags(1 << 3);
private static ImGuiTabItemFlags Custom = new ImGuiTabItemFlags(0);
int value;
private ImGuiTabItemFlags(int code) {
value = code;
}
public ImGuiTabItemFlags or(ImGuiTabItemFlags otherEnum) {
ImGuiTabItemFlags.Custom.value = value | otherEnum.value;
return ImGuiTabItemFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,38 @@
package imgui.enums;
/**
* Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*()
*/
public class ImGuiTreeNodeFlags {
public static ImGuiTreeNodeFlags None = new ImGuiTreeNodeFlags(0);
public static ImGuiTreeNodeFlags Selected = new ImGuiTreeNodeFlags(1 << 0);
public static ImGuiTreeNodeFlags Framed = new ImGuiTreeNodeFlags(1 << 1);
public static ImGuiTreeNodeFlags AllowItemOverlap = new ImGuiTreeNodeFlags(1 << 2);
public static ImGuiTreeNodeFlags NoTreePushOnOpen = new ImGuiTreeNodeFlags(1 << 3);
public static ImGuiTreeNodeFlags NoAutoOpenOnLog = new ImGuiTreeNodeFlags(1 << 4);
public static ImGuiTreeNodeFlags DefaultOpen = new ImGuiTreeNodeFlags(1 << 5);
public static ImGuiTreeNodeFlags OpenOnDoubleClick = new ImGuiTreeNodeFlags(1 << 6);
public static ImGuiTreeNodeFlags OpenOnArrow = new ImGuiTreeNodeFlags(1 << 7);
public static ImGuiTreeNodeFlags Leaf = new ImGuiTreeNodeFlags(1 << 8);
public static ImGuiTreeNodeFlags Bullet = new ImGuiTreeNodeFlags(1 << 9);
public static ImGuiTreeNodeFlags FramePadding = new ImGuiTreeNodeFlags(1 << 10);
// public static ImGuiTreeNodeFlags SpanAllAvailWidth = new ImGuiTreeNodeFlags(1 << 11);
// public static ImGuiTreeNodeFlags NoScrollOnOpen = new ImGuiTreeNodeFlags(1 << 12);
public static ImGuiTreeNodeFlags NavLeftJumpsBackHere = new ImGuiTreeNodeFlags(1 << 13);
public static ImGuiTreeNodeFlags CollapsingHeader = new ImGuiTreeNodeFlags(Framed.getValue() | NoTreePushOnOpen.getValue() | NoAutoOpenOnLog.getValue());
private static ImGuiTreeNodeFlags Custom = new ImGuiTreeNodeFlags(0);
int value;
private ImGuiTreeNodeFlags(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public ImGuiTreeNodeFlags or(ImGuiTreeNodeFlags otherEnum) {
ImGuiTreeNodeFlags.Custom.value = value | otherEnum.value;
return ImGuiTreeNodeFlags.Custom;
}
}
@@ -0,0 +1,47 @@
package imgui.enums;
/**
* Flags for ImGui::Begin()
*/
public class ImGuiWindowFlags {
public static ImGuiWindowFlags None = new ImGuiWindowFlags(0);
public static ImGuiWindowFlags NoTitleBar = new ImGuiWindowFlags(1 << 0);
public static ImGuiWindowFlags NoResize = new ImGuiWindowFlags(1 << 1);
public static ImGuiWindowFlags NoMove = new ImGuiWindowFlags(1 << 2);
public static ImGuiWindowFlags NoScrollbar = new ImGuiWindowFlags(1 << 3);
public static ImGuiWindowFlags NoScrollWithMouse = new ImGuiWindowFlags(1 << 4);
public static ImGuiWindowFlags NoCollapse = new ImGuiWindowFlags(1 << 5);
public static ImGuiWindowFlags AlwaysAutoResize = new ImGuiWindowFlags(1 << 6);
public static ImGuiWindowFlags NoBackground = new ImGuiWindowFlags(1 << 7);
public static ImGuiWindowFlags NoSavedSettings = new ImGuiWindowFlags(1 << 8);
public static ImGuiWindowFlags NoMouseInputs = new ImGuiWindowFlags(1 << 9);
public static ImGuiWindowFlags MenuBar = new ImGuiWindowFlags(1 << 10);
public static ImGuiWindowFlags HorizontalScrollbar = new ImGuiWindowFlags(1 << 11);
public static ImGuiWindowFlags NoFocusOnAppearing = new ImGuiWindowFlags(1 << 12);
public static ImGuiWindowFlags NoBringToFrontOnFocus = new ImGuiWindowFlags(1 << 13);
public static ImGuiWindowFlags AlwaysVerticalScrollbar = new ImGuiWindowFlags(1 << 14);
public static ImGuiWindowFlags AlwaysHorizontalScrollbar = new ImGuiWindowFlags(1 << 15);
public static ImGuiWindowFlags AlwaysUseWindowPadding = new ImGuiWindowFlags(1 << 16);
public static ImGuiWindowFlags NoNavInputs = new ImGuiWindowFlags(1 << 18);
public static ImGuiWindowFlags NoNavFocus = new ImGuiWindowFlags(1 << 19);
public static ImGuiWindowFlags UnsavedDocument = new ImGuiWindowFlags(1 << 20);
public static ImGuiWindowFlags NoDocking = new ImGuiWindowFlags(1 << 21);
public static ImGuiWindowFlags NoNav = new ImGuiWindowFlags(NoNavInputs.getValue() | NoNavFocus.getValue());
public static ImGuiWindowFlags NoDecoration = new ImGuiWindowFlags(NoTitleBar.getValue() | NoResize.getValue() | NoScrollbar.getValue() | NoCollapse.getValue());
public static ImGuiWindowFlags NoInputs = new ImGuiWindowFlags(NoMouseInputs.getValue() | NoNavInputs.getValue() | NoNavFocus.getValue());
private static ImGuiWindowFlags Custom = new ImGuiWindowFlags(0);
int value;
private ImGuiWindowFlags(int code) {
value = code;
}
public ImGuiWindowFlags or(ImGuiWindowFlags otherEnum) {
ImGuiWindowFlags.Custom.value = value | otherEnum.value;
return ImGuiWindowFlags.Custom;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,6 @@
package imgui.enums;
public class ImLayout {
public static float MATCH_PARENT = -0.1f;
public static float WRAP_PARENT = 0.0f;
}
@@ -0,0 +1,512 @@
#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_layout_widget.h"
static ImVector<ImGuiLayout *> layoutStack;
static ImGuiLayout *createOrFind(const char *id)
{
ImGuiContext &g = *GImGui;
ImGuiLayout *childLayout = NULL;
ImGuiID hashID = ImHashStr(id);
childLayout = (ImGuiLayout *)g.WindowsById.GetVoidPtr(hashID);
if (childLayout == NULL)
{
childLayout = IM_NEW(ImGuiLayout)(id);
g.WindowsById.SetVoidPtr(childLayout->id, childLayout);
}
return childLayout;
}
static ImGuiLayout *pushLayout(const char *id)
{
ImGuiLayout *parentLayout = NULL;
if (!layoutStack.empty())
parentLayout = layoutStack.back();
ImGuiLayout *childLayout = createOrFind(id);
childLayout->parentLayout = parentLayout;
layoutStack.push_back(childLayout);
return childLayout;
}
ImGuiLayout *ImGuiEx::GetCurrentLayout()
{
if (layoutStack.empty())
return NULL;
return layoutStack.back();
}
static void popLayout()
{
layoutStack.pop_back();
}
void ImGuiEx::ShowLayoutDebug()
{
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
if (curLayout != NULL)
{
curLayout->debug = true;
}
}
void ImGuiEx::BeginLayoutEx(const char *strID)
{
ImGuiLayout *parentLayout = ImGuiEx::GetCurrentLayout();
ImGuiID id = ImHashStr(strID);
char title[256];
if (parentLayout)
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s_%08X", parentLayout->idStr, strID, id);
else
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", strID, id);
pushLayout(title);
}
bool ImGuiEx::PrepareLayout(float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom)
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
bool ret = true;
// Update layout
// Backup windows data
curLayout->DC = window->DC;
curLayout->WorkRect = window->WorkRect;
curLayout->skipping = window->SkipItems;
curLayout->AutoFitChildAxises = window->AutoFitChildAxises;
curLayout->Pos = window->Pos;
curLayout->ContentRegionRect = window->ContentRegionRect;
// ******** End Backup windows data
curLayout->sizeParam.x = sizeX;
curLayout->sizeParam.y = sizeY;
curLayout->paddingLeft = paddingLeft;
curLayout->paddingRight = paddingRight;
curLayout->paddingTop = paddingTop;
curLayout->paddingBottom = paddingBottom;
curLayout->position = window->DC.CursorPos;
ImVec2 contentPosition = curLayout->getPositionPadding();
curLayout->positionContents = curLayout->position;
const ImVec2 content_avail = ImGui::GetContentRegionAvail();
ImVec2 sizeItem = ImFloor(curLayout->sizeParam);
if (curLayout->sizeParam.x < 0.0f)
{
float sizeX = ImMax(content_avail.x + sizeItem.x, 4.0f);
curLayout->size.x = sizeX;
}
if (curLayout->sizeParam.y < 0.0f)
{
float sizeY = ImMax(content_avail.y + sizeItem.y, 4.0f);
curLayout->size.y = sizeY;
}
// ***** End Update Layout
// Write to window object
window->Pos.x = contentPosition.x;
window->Pos.y = contentPosition.y;
window->DC.Indent.x = 0;
//window->DC.CursorMaxPos.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
//window->DC.CursorMaxPos.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
window->DC.CursorMaxPos.x = contentPosition.x;
window->DC.CursorMaxPos.y = contentPosition.y;
window->DC.CursorStartPos.x = contentPosition.x;
window->DC.CursorStartPos.y = contentPosition.y;
window->DC.CurrLineSize.y = 0; // necessary to keep position inside layout
window->DC.CurrLineTextBaseOffset = 0;
window->DC.CursorPos.x = contentPosition.x;
window->DC.CursorPos.y = contentPosition.y;
window->WorkRect.Min.x = contentPosition.x;
window->WorkRect.Min.y = contentPosition.y;
window->WorkRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
window->WorkRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
window->ContentRegionRect.Min.x = contentPosition.x;
window->ContentRegionRect.Min.y = contentPosition.y;
window->ContentRegionRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight;
window->ContentRegionRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom;
// ***** End Write to window object
if (curLayout->clipping)
{
ImVec2 min = curLayout->getPositionPadding();
ImVec2 max = curLayout->getAbsoluteSizePadding();
//ImGui::drawBoundingBox(min, max, 255, 0, 0);
ImGui::PushClipRect(min, max, true);
}
bool skip_items = false;
if (window->Collapsed || !window->Active || window->Hidden)
/* if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesCannotSkipItems <= 0)*/
skip_items = true;
window->SkipItems = skip_items;
ret = !skip_items;
return true;
}
bool ImGuiEx::BeginLayout(const char *strID, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom)
{
BeginLayoutEx(strID);
return PrepareLayout(sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom);
}
void ImGuiEx::EndLayout()
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
if (curLayout == NULL)
return;
if (curLayout->clipping)
ImGui::PopClipRect();
float x = window->DC.CursorPos.x;
float y = window->DC.CursorPos.y;
curLayout->sizeContents.x = window->DC.CursorMaxPos.x - x;
//curLayout->sizeContents.y = y - curLayout->position.y - g.Style.ItemSpacing.y;
//curLayout->sizeContents.x = window->DC.CursorMaxPos.x - curLayout->positionContents.x;
curLayout->sizeContents.y = y - curLayout->positionContents.y - g.Style.ItemSpacing.y;
// Restore windows data
window->DC = curLayout->DC;
window->WorkRect = curLayout->WorkRect;
window->SkipItems = curLayout->skipping;
window->AutoFitChildAxises = curLayout->AutoFitChildAxises;
window->Pos = curLayout->Pos;
window->ContentRegionRect = curLayout->ContentRegionRect;
// ********************
//const ImVec2 content_avail = GetContentRegionAvail();
ImVec2 sizeItem = curLayout->sizeParam;
if (sizeItem.x < 0.0f)
{
sizeItem.x = curLayout->size.x;
if (curLayout->size.x < curLayout->sizeContents.x || curLayout->size.x > curLayout->sizeContents.x)
{
//special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size.
/* curLayout->error = true;
sizeItem.x = 10;*/
}
}
else if (sizeItem.x == 0.0f)
sizeItem.x = curLayout->sizeContents.x + curLayout->paddingLeft + curLayout->paddingRight;
if (sizeItem.y < 0.0f)
{
sizeItem.y = curLayout->size.y;
if (curLayout->size.y < curLayout->sizeContents.y)
{
//special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size.
//curLayout->error = true;
//sizeItem.y = curLayout->sizeContents.y;
}
}
else if (sizeItem.y == 0.0f)
sizeItem.y = curLayout->sizeContents.y + curLayout->paddingBottom;
curLayout->size = sizeItem;
ImGui::ItemSize(sizeItem);
if (curLayout->debug)
{
curLayout->drawContentDebug();
curLayout->drawPaddingAreaDebug();
curLayout->drawSizeDebug();
curLayout->debug = false;
}
if (curLayout->error)
{
curLayout->error = false;
curLayout->drawError();
}
popLayout();
}
static bool renderFrameArrow(bool *value, int arrowColor, int arrowBackgroundHoveredColor, int arrowBackgroundClickedColor)
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImDrawList *drawList = ImGui::GetWindowDrawList();
float getFrameHeight = ImGui::GetFrameHeight();
float removedSize = 5.5f; // reduce few pixels
float halfSize = (getFrameHeight) / 2.0f - removedSize;
ImVec2 vec = ImGui::GetCursorScreenPos();
float screenPosX = vec.x;
float screenPosY = vec.y;
float arrowPaddingLeft = 6;
float x = screenPosX + halfSize + arrowPaddingLeft;
float y = screenPosY + getFrameHeight / 2.0f;
bool hovered = ImGui::IsMouseHoveringRect(ImVec2(x - halfSize - removedSize, y - halfSize - removedSize), ImVec2(x + halfSize + removedSize, y + halfSize + removedSize));
ImU32 hoveredColor = arrowBackgroundHoveredColor;
bool isWindowHovered = ImGui::IsWindowHovered();
if (isWindowHovered)
{
if (hovered)
{
if (ImGui::IsMouseDown(0))
hoveredColor = arrowBackgroundClickedColor;
if (ImGui::IsMouseReleased(0))
*value = !*value;
}
if (hovered)
drawList->AddCircleFilled(ImVec2(x, y), halfSize * 2, hoveredColor);
}
float triA_X = 0;
float triA_Y = 0;
float triB_X = 0;
float triB_Y = 0;
float triC_X = 0;
float triC_Y = 0;
if (*value)
{
// arrow down
float offset = -0.5f;
triA_X = x - halfSize + offset;
triA_Y = y - halfSize;
triB_X = x + halfSize + offset;
triB_Y = y - halfSize;
triC_X = x + offset;
triC_Y = y + halfSize;
}
else
{
// arrow right
triA_X = x - halfSize;
triA_Y = y - halfSize;
triB_X = x + halfSize;
triB_Y = y;
triC_X = x - halfSize;
triC_Y = y + halfSize;
}
drawList->AddTriangleFilled(ImVec2(triA_X, triA_Y), ImVec2(triB_X, triB_Y), ImVec2(triC_X, triC_Y), arrowColor);
float bk = g.Style.ItemSpacing.y;
g.Style.ItemSpacing.y = 0;
ImGui::ItemSize(ImVec2(halfSize * 2 + 3, getFrameHeight));
g.Style.ItemSpacing.y = bk;
return *value;
}
static int OPEN_KEY = 13213;
bool ImGuiEx::PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImDrawList *drawList = window->DrawList;
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
float frameHeight = ImGui::GetFrameHeight();
bool flag = rootLayout->map.GetBool(OPEN_KEY, false);
bool *isOpen = &flag;
sizeY = *isOpen ? sizeY : ImLayout::WRAP_PARENT;
ImGuiEx::PrepareLayout(sizeX, sizeY, 1, 1, 1, 1);
rootLayout->map.SetFloat(120, options.paddingLeft);
rootLayout->map.SetFloat(121, options.paddingRight);
rootLayout->map.SetFloat(122, options.paddingTop);
rootLayout->map.SetFloat(123, options.paddingBottom);
ImGuiEx::BeginLayout("frame", ImLayout::MATCH_PARENT, frameHeight, 0, 0, 0, 0);
ImGuiLayout *frameLayout = ImGuiEx::GetCurrentLayout();
ImVec2 mousePos = ImGui::GetMousePos();
drawList->AddRectFilled(rootLayout->position, ImVec2(rootLayout->getAbsoluteSize().x, frameLayout->getAbsoluteSize().y), options.frameColor, options.borderRound, options.roundingCorners);
renderFrameArrow(isOpen, options.arrowColor, options.arrowBackgroundHoveredColor, options.arrowBackgroundClickedColor);
rootLayout->map.SetBool(OPEN_KEY, *isOpen);
ImGui::SameLine();
ImGuiEx::BeginAlign("align", ImLayout::WRAP_PARENT, ImLayout::MATCH_PARENT, 0, 0.5f, 0, 0);
ImGui::Text(title);
ImGuiEx::EndAlign();
ImGui::SameLine();
return *isOpen;
}
void ImGuiEx::BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
{
ImGuiEx::BeginLayoutEx(title);
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
rootLayout->map.SetBool(OPEN_KEY, *isOpen);
bool flag = ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options);
*isOpen = flag;
}
bool ImGuiEx::BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
{
ImGuiEx::BeginLayoutEx(title);
return ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options);
}
bool ImGuiEx::BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
{
bool flag = ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options);
ImGuiEx::EndCollapseFrameLayout();
return flag;
}
void ImGuiEx::BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options)
{
ImGuiEx::BeginCollapseLayoutEx(isOpen, title, sizeX, sizeY, options);
ImGuiEx::EndCollapseFrameLayout();
}
void ImGuiEx::EndCollapseFrameLayout()
{
ImGuiContext &g = *GImGui;
float bk = g.Style.ItemSpacing.y;
g.Style.ItemSpacing.y = 0;
ImGuiEx::EndLayout(); // end frame
g.Style.ItemSpacing.y = bk;
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
float paddingLeft = rootLayout->map.GetFloat(120, 0.0f);
float paddingRight = rootLayout->map.GetFloat(121, 0.0f);
float paddingTop = rootLayout->map.GetFloat(122, 0.0f);
float paddingBottom = rootLayout->map.GetFloat(123, 0.0f);
ImGuiEx::BeginLayout("content", ImLayout::MATCH_PARENT, ImLayout::WRAP_PARENT, paddingLeft, paddingRight, paddingTop, paddingBottom);
ImGuiLayout *collapseLayout = ImGuiEx::GetCurrentLayout();
}
void ImGuiEx::EndCollapseLayout()
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImDrawList *drawList = window->DrawList;
ImU32 borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f));
int borderRound = 4;
int roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight;
ImGuiEx::EndLayout(); // end content
ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout();
ImGuiEx::EndLayout(); // end root
ImVec2 borderPosition = rootLayout->position;
ImVec2 borderSize = rootLayout->getAbsoluteSize();
drawList->AddRect(borderPosition, borderSize, borderColor, borderRound, roundingCorners, 1.0f);
}
void ImGuiEx::BeginAlign(const char *strID, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY)
{
ImGuiEx::BeginLayout(strID, sizeX, sizeY);
ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY);
}
void ImGuiEx::AlignLayout(float alignX, float alignY, float offsetX, float offsetY)
{
ImGuiContext &g = *GImGui;
ImGuiWindow *window = g.CurrentWindow;
ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout();
if (curLayout == NULL)
return;
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
float totalX = regionAvail.x;
float totalY = regionAvail.y;
ImVec2 posPad = curLayout->getPositionPadding();
ImVec2 absSizePad = curLayout->getAbsoluteSizePadding();
if (alignX >= 0.0f && curLayout->sizeParam.x != ImLayout::WRAP_PARENT)
{
float addX = ImFloor((totalX - curLayout->sizeContents.x) * alignX);
float newX = posPad.x + addX + offsetX;
if (newX < posPad.x)
{
curLayout->error = true;
newX = posPad.x;
}
else if (newX + curLayout->sizeContents.x > absSizePad.x)
{
curLayout->error = true;
newX = absSizePad.x - curLayout->sizeContents.x;
}
curLayout->positionContents.x = newX;
}
if (alignY >= 0.0f && curLayout->sizeParam.y != ImLayout::WRAP_PARENT)
{
float addY = ImFloor((totalY - curLayout->sizeContents.y) * alignY);
float newY = posPad.y + addY + offsetY;
if (newY < posPad.y)
{
curLayout->error = true;
newY = posPad.y;
}
else if (newY + curLayout->sizeContents.y > absSizePad.y)
{
curLayout->error = true;
newY = absSizePad.y - curLayout->sizeContents.y;
}
curLayout->positionContents.y = newY;
}
window->DC.CursorMaxPos.x = curLayout->positionContents.x;
window->DC.CursorMaxPos.y = curLayout->positionContents.y;
window->DC.CursorStartPos.x = curLayout->positionContents.x;
window->DC.CursorStartPos.y = curLayout->positionContents.y;
window->Pos.x = curLayout->positionContents.x;
window->Pos.y = curLayout->positionContents.y;
window->DC.CursorPos.x = curLayout->positionContents.x;
window->DC.CursorPos.y = curLayout->positionContents.y;
}
void ImGuiEx::EndAlign()
{
ImGuiEx::EndLayout();
}
@@ -0,0 +1,182 @@
#pragma once
#include "imgui.h"
#include "imgui_internal.h"
namespace ImGuiEx
{
inline void drawBoundingBox(float x1, float y1, float x2, float y2, int r, int g, int b, bool clipping = false)
{
ImDrawList *drawList = clipping ? ImGui::GetWindowDrawList() : ImGui::GetForegroundDrawList();
float rounding = 0;
int color = ImGui::GetColorU32(ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 205.0f / 255.0f));
drawList->AddRect(ImVec2(x1, y1), ImVec2(x2, y2), color, rounding);
}
inline void drawBoundingBox(ImVec2 min, ImVec2 max, int r, int g, int b, bool clipping = false)
{
ImGuiEx::drawBoundingBox(min.x, min.y, max.x, max.y, r, g, b, clipping);
}
}; // namespace ImGuiEx
struct ImGuiLayout
{
public:
char *idStr;
ImGuiID id;
ImGuiLayout *parentLayout;
bool clipping;
bool debug;
ImGuiStorage map;
ImVec2 position; // Position of the layout
ImVec2 size; // Size of the layout
ImVec2 sizeParam; // Size parameter used when calling beginLayout
float paddingLeft;
float paddingRight;
float paddingTop;
float paddingBottom;
ImVec2 positionContents; // Position of contents.
ImVec2 sizeContents; // Size of contents. calculated after the first frame
bool error;
// Window Backup data
ImGuiWindowTempData DC;
ImRect WorkRect;
bool skipping;
int AutoFitChildAxises;
ImVec2 Pos;
ImRect ContentRegionRect;
ImGuiLayout(const char *idStr)
{
this->idStr = ImStrdup(idStr);
this->id = ImHashStr(idStr);
paddingLeft = 0;
paddingRight = 0;
paddingTop = 0;
paddingBottom = 0;
clipping = true;
debug = false;
error = false;
skipping = false;
}
bool haveParent() { return parentLayout != NULL; }
ImVec2 getAbsoluteSize()
{
return ImVec2(position.x + size.x, position.y + size.y);
}
ImVec2 getContentSize()
{
return ImVec2(position.x + sizeContents.x, position.y + sizeContents.y);
}
ImVec2 getAbsoluteSizePadding()
{
return ImVec2(position.x + size.x - paddingRight, position.y + size.y - paddingBottom);
}
ImVec2 getContentSizePadding()
{
return ImVec2(position.x + sizeContents.x + paddingLeft, position.y + sizeContents.y);
}
ImVec2 getPositionPadding()
{
return ImVec2(position.x + paddingLeft, position.y + paddingTop);
}
void drawSizeDebug()
{
// Render layout space
//Green
ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 0, 255, 0);
}
inline void drawContentDebug()
{
// Render content space
// Blue
ImVec2 max = ImVec2(positionContents.x + sizeContents.x, positionContents.y + sizeContents.y);
ImGuiEx::drawBoundingBox(positionContents, max, 0, 0, 255);
}
void drawPaddingAreaDebug()
{
// Render size with padding
ImGuiEx::drawBoundingBox(getPositionPadding(), getAbsoluteSizePadding(), 255, 255, 255);
}
void drawError()
{
ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 255, 0, 0, true);
}
};
struct ImGuiCollapseLayoutOptions
{
public:
float paddingLeft;
float paddingRight;
float paddingTop;
float paddingBottom;
ImU32 arrowColor;
ImU32 arrowBackgroundHoveredColor;
ImU32 arrowBackgroundClickedColor;
ImU32 frameColor;
ImU32 borderColor;
int borderRound;
int roundingCorners;
ImGuiCollapseLayoutOptions()
{
paddingLeft = 2;
paddingRight = 2;
paddingTop = 2;
paddingBottom = 2;
arrowColor = ImGui::GetColorU32(ImVec4(0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f));
arrowBackgroundHoveredColor = ImGui::GetColorU32(ImVec4(0x77 / 255.0f, 0x77 / 255.0f, 0x77 / 255.0f, 0xFF / 255.0f));
arrowBackgroundClickedColor = ImGui::GetColorU32(ImVec4(0x55 / 255.0f, 0x55 / 255.0f, 0x55 / 255.0f, 0xFF / 255.0f));
frameColor = ImGui::GetColorU32(ImVec4(0x24 / 255.0f, 0x24 / 255.0f, 0x24 / 255.0f, 255 / 255.0f));
borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f));
borderRound = 4;
roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight;
}
};
namespace ImGuiEx
{
void ShowLayoutDebug();
void BeginLayoutEx(const char *id);
bool PrepareLayout(float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0);
bool BeginLayout(const char *id, float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0);
void EndLayout();
ImGuiLayout *GetCurrentLayout();
bool BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
void BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
bool PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
bool BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
void BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions());
void EndCollapseFrameLayout();
void EndCollapseLayout();
void BeginAlign(const char *id, float sizeX, float sizeY, float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0);
void AlignLayout(float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0);
void EndAlign();
}; // namespace ImGuiEx
namespace ImLayout
{
static float WRAP_PARENT = 0;
static float MATCH_PARENT = -0.1f;
} // namespace ImLayout
+33
View File
@@ -0,0 +1,33 @@
import org.gradle.internal.os.OperatingSystem
plugins {
id 'java'
}
sourceCompatibility = 1.8
ext {
lwjglVersion = '3.2.3'
}
switch (OperatingSystem.current()) {
case OperatingSystem.LINUX:
project.ext.lwjglNatives = 'natives-linux'
break
case OperatingSystem.WINDOWS:
project.ext.lwjglNatives = System.getProperty('os.arch').contains('64') ? 'natives-windows' : 'natives-windows-x86'
break
}
dependencies {
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
implementation 'org.lwjgl:lwjgl'
implementation 'org.lwjgl:lwjgl-glfw'
implementation 'org.lwjgl:lwjgl-opengl'
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
implementation project(':imgui-binding')
}
@@ -0,0 +1,125 @@
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import static org.lwjgl.glfw.GLFW.*;
public class InputHandler {
private static long window;
private static final int KEYBOARD_SIZE = 512;
private static final int MOUSE_SIZE = 16;
private static int[] keyStates = new int[KEYBOARD_SIZE];
private static boolean[] activeKeys = new boolean[KEYBOARD_SIZE];
private static int[] mouseButtonStates = new int[MOUSE_SIZE];
private static boolean[] activeMouseButtons = new boolean[MOUSE_SIZE];
private static long lastMouseNS = 0;
private static long mouseDoubleClickPeriodNS = 1000000000 / 5; //5th of a second for double click.
private static int NO_STATE = -1;
protected static GLFWKeyCallback keyboard = new GLFWKeyCallback()
{
@Override
public void invoke(long window, int key, int scancode, int action, int mods)
{
activeKeys[key] = action != GLFW_RELEASE;
keyStates[key] = action;
}
};
protected static GLFWMouseButtonCallback mouse = new GLFWMouseButtonCallback()
{
@Override
public void invoke(long window, int button, int action, int mods)
{
activeMouseButtons[button] = action != GLFW_RELEASE;
mouseButtonStates[button] = action;
}
};
protected static void init(long window)
{
InputHandler.window = window;
resetKeyboard();
resetMouse();
}
protected static void update()
{
resetKeyboard();
resetMouse();
}
private static void resetKeyboard()
{
for (int i = 0; i < keyStates.length; i++)
{
keyStates[i] = NO_STATE;
}
}
private static void resetMouse()
{
for (int i = 0; i < mouseButtonStates.length; i++)
{
mouseButtonStates[i] = NO_STATE;
}
long now = System.nanoTime();
if (now - lastMouseNS > mouseDoubleClickPeriodNS)
lastMouseNS = 0;
}
public static boolean keyDown(int key)
{
return activeKeys[key];
}
public static boolean keyPressed(int key)
{
return keyStates[key] == GLFW_PRESS;
}
public static boolean keyReleased(int key)
{
return keyStates[key] == GLFW_RELEASE;
}
public static boolean mouseButtonDown(int button)
{
return activeMouseButtons[button];
}
public static boolean mouseButtonPressed(int button)
{
return mouseButtonStates[button] == GLFW_RELEASE;
}
public static boolean mouseButtonReleased(int button)
{
boolean flag = mouseButtonStates[button] == GLFW_RELEASE;
if (flag)
lastMouseNS = System.nanoTime();
return flag;
}
public static boolean mouseButtonDoubleClicked(int button)
{
long last = lastMouseNS;
boolean flag = mouseButtonReleased(button);
long now = System.nanoTime();
if (flag && now - last < mouseDoubleClickPeriodNS)
{
lastMouseNS = 0;
return true;
}
return false;
}
}
+156
View File
@@ -0,0 +1,156 @@
import imgui.DrawData;
import imgui.ImGui;
import imgui.gl3.ImGuiImplGl3;
import org.lwjgl.BufferUtils;
import org.lwjgl.Version;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryStack;
import java.nio.DoubleBuffer;
import java.nio.IntBuffer;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.system.MemoryUtil.NULL;
public class Main {
// The window handle
private long window;
private ImGuiImplGl3 imGuiGl = new ImGuiImplGl3();
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
// Create the window
window = glfwCreateWindow(1024, 768, "Hello World!", NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
glfwSetMouseButtonCallback(window, InputHandler.mouse);
// Get the thread stack and push a new frame
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
InputHandler.init(window);
// Make the window visible
glfwShowWindow(window);
}
long lastFrame = System.nanoTime();
public float getDelta() {
long time = System.nanoTime();
int delta_time = (int) ((time - lastFrame) / 1000000);
lastFrame = time;
return delta_time;
}
private void loop() {
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the GLCapabilities instance and makes the OpenGL
// bindings available for use.
GL.createCapabilities();
ImGui.init();
imGuiGl.init();
// Set the clear color
glClearColor(.5f, 0.0f, 0f, 0.0f);
int[] win_width = new int[1], win_height = new int[1];
int[] width = new int[1], height = new int[1];
DoubleBuffer xBuffer = BufferUtils.createDoubleBuffer(1);
DoubleBuffer yBuffer = BufferUtils.createDoubleBuffer(1);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while (!glfwWindowShouldClose(window)) {
xBuffer.clear();
yBuffer.clear();
InputHandler.update();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwGetWindowSize(window, win_width, win_height);
glfwGetFramebufferSize(window, width, height);
glfwGetCursorPos(window, xBuffer, yBuffer);
int mX = (int) xBuffer.get();
int mY = (int) yBuffer.get();
ImGui.UpdateDisplayAndInputAndFrame(getDelta(), win_width[0], win_height[0], width[0], height[0], mX, mY, InputHandler.mouseButtonDown(0), false, false);
ImGui.ShowDemoWindow();
ImGui.Render();
imGuiGl.render(ImGui.GetDrawData());
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new Main().run();
}
}
@@ -0,0 +1,341 @@
package imgui.gl3;
import imgui.DrawData;
import imgui.ImGui;
import imgui.TexDataRGBA32;
import java.io.*;
import java.util.Objects;
import static org.lwjgl.opengl.GL30.*;
/**
* This class mostly a straightforward port of the https://raw.githubusercontent.com/ocornut/imgui/v1.74/examples/imgui_impl_opengl3.cpp adapted to Java and LWJGL realms.
* <p>
* It do support a backup of the current GL state before rendering and restoring of its initial state after.
* But some specific state variables may be missed (all which are hidden under '#ifdef' macros in the original imgui file).
* <p>
* By default this implementation uses shaders with 130 version of GLSL (OpenGL 3.0).
* You can provide your own shaders into the {@link ImGuiImplGl3#init(CharSequence, CharSequence)} method.
*/
public class ImGuiImplGl3 {
private int vBufferHandle = 0;
private int iBufferHandle = 0;
private boolean isFontInitialized = false;
// Shader stuff
private int programId = 0;
private int fragmentShaderId = 0;
private int vertexShaderId = 0;
// Texture used by fonts
private int gFontTexture = 0;
// Projection matrix for ImGui
private final float[] projMatrix = new float[4 * 4];
// Variables used to backup GL state before and after rendering of ImGui
private final int[] lastActiveTexture = new int[1];
private final int[] lastProgram = new int[1];
private final int[] lastTexture = new int[1];
private final int[] lastArrayBuffer = new int[1];
private final int[] lastViewport = new int[4];
private final int[] lastScissorBox = new int[4];
private final int[] lastBlendSrcRgb = new int[1];
private final int[] lastBlendDstRgb = new int[1];
private final int[] lastBlendSrcAlpha = new int[1];
private final int[] lastBlendDstAlpha = new int[1];
private final int[] lastBlendEquationRgb = new int[1];
private final int[] lastBlendEquationAlpha = new int[1];
private boolean lastEnableBlend = false;
private boolean lastEnableCullFace = false;
private boolean lastEnableDepthTest = false;
private boolean lastEnableScissorTest = false;
/**
* This method SHOULD be called before calling of {@link ImGuiImplGl3#render(DrawData)} method.
* By using this method shaders with 130 version of GLSL will be used for render.
*/
public void init() {
final CharSequence fragShaderSource = readFromResources("default.frag");
final CharSequence vertShaderSource = readFromResources("default.vert");
prepareShader(fragShaderSource, vertShaderSource);
prepareFont();
}
/**
* This method SHOULD be called before calling of {@link ImGuiImplGl3#render(DrawData)} method.
*
* @param fragShaderSource fragment shader to use for render
* @param vertShaderSource vertex shader to use for render
*/
public void init(final CharSequence fragShaderSource, final CharSequence vertShaderSource) {
prepareShader(fragShaderSource, vertShaderSource);
prepareFont();
}
/**
* Method which renders {@link DrawData} from ImGui.
*
* @param drawData data used to draw ImGui interface to your current OpenGL context
*/
public void render(final DrawData drawData) {
if (drawData.cmdListsCount <= 0) {
return;
}
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
int fbWidth = (int) (drawData.displaySizeX * drawData.framebufferScaleX);
int fbHeight = (int) (drawData.displaySizeY * drawData.framebufferScaleY);
if (fbWidth <= 0 || fbHeight <= 0) {
return;
}
if (!isFontInitialized) {
isFontInitialized = true;
vBufferHandle = glGenBuffers();
iBufferHandle = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferHandle);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, drawData.iByteBuffer.capacity(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
backupGlState();
bind(drawData);
int verticesOffset = 0;
int indexOffset = 0;
for (int i = 0; i < drawData.cmdListsCount; i++) {
drawData.vByteBuffer.limit(verticesOffset + 4);
final int verticesSize = (int) drawData.vByteBuffer.getFloat(verticesOffset);
drawData.iByteBuffer.limit(indexOffset + 2);
final short indexSize = drawData.iByteBuffer.getShort(indexOffset);
final int cmdSize = (int) drawData.cmdByteBuffer.getFloat();
final int verticesStartOffset = verticesOffset + 4;
final int indexStartOffset = indexOffset + 2;
drawData.vByteBuffer.position(verticesStartOffset);
drawData.iByteBuffer.position(indexStartOffset);
final int newVlimit = verticesStartOffset + verticesSize * DrawData.vBufferSize;
final int newIlimit = indexStartOffset + indexSize * DrawData.iBufferSize;
drawData.vByteBuffer.limit(newVlimit);
drawData.iByteBuffer.limit(newIlimit);
glBufferData(GL_ARRAY_BUFFER, drawData.vByteBuffer, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, drawData.iByteBuffer, GL_STATIC_DRAW);
verticesOffset += ((verticesSize) * DrawData.vBufferSize) + 4;
indexOffset += ((indexSize) * DrawData.iBufferSize) + 2;
final float clipOffX = drawData.displayPosX; // (0,0) unless using multi-viewports
final float clipOffY = drawData.displayPosY;
final float clipScaleX = drawData.framebufferScaleX; // (1,1) unless using retina display which are often (2,2)
final float clipScaleY = drawData.framebufferScaleY;
int idxBufferOffset = 0;
for (int j = 0; j < cmdSize; j++) {
final int elemCount = (int) drawData.cmdByteBuffer.getFloat();
float clipRectX = drawData.cmdByteBuffer.getFloat();
float clipRectY = drawData.cmdByteBuffer.getFloat();
float clipRectZ = drawData.cmdByteBuffer.getFloat();
float clipRectW = drawData.cmdByteBuffer.getFloat();
final int textureID = (int) drawData.cmdByteBuffer.getFloat();
clipRectX = (clipRectX - clipOffX) * clipScaleX;
clipRectY = (clipRectY - clipOffY) * clipScaleY;
clipRectZ = (clipRectZ - clipOffX) * clipScaleX;
clipRectW = (clipRectW - clipOffY) * clipScaleY;
if (clipRectX < fbWidth && clipRectY < fbHeight && clipRectZ >= 0.0f && clipRectW >= 0.0f) {
glScissor((int) clipRectX, (int) (fbHeight - clipRectW), (int) (clipRectZ - clipRectX), (int) (clipRectW - clipRectY));
glBindTexture(GL_TEXTURE_2D, textureID);
glDrawElements(GL_TRIANGLES, elemCount, GL_UNSIGNED_SHORT, idxBufferOffset);
}
idxBufferOffset += elemCount * 2;
}
}
unbind();
restoreModifiedGlState();
}
/**
* Call this method in the end of your app working state to clear used resources.
*/
public void dispose() {
glDeleteTextures(gFontTexture);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(iBufferHandle);
glDeleteBuffers(vBufferHandle);
glDetachShader(programId, vertexShaderId);
glDetachShader(programId, fragmentShaderId);
glDeleteProgram(programId);
}
private void prepareShader(final CharSequence fragShaderSource, final CharSequence vertShaderSource) {
fragmentShaderId = loadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderSource);
vertexShaderId = loadAndCompileShader(GL_VERTEX_SHADER, vertShaderSource);
programId = glCreateProgram();
glAttachShader(programId, fragmentShaderId);
glAttachShader(programId, vertexShaderId);
glLinkProgram(programId);
if (glGetProgrami(programId, GL_LINK_STATUS) != GL_TRUE) {
throw new IllegalStateException(glGetProgramInfoLog(programId));
}
}
private void prepareFont() {
TexDataRGBA32 texData = new TexDataRGBA32();
ImGui.GetTexDataAsRGBA32(texData, texData.pixelBuffer);
gFontTexture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, gFontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texData.width, texData.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.pixelBuffer);
ImGui.SetFontTexID(gFontTexture);
}
private void backupGlState() {
glGetIntegerv(GL_ACTIVE_TEXTURE, lastActiveTexture);
glGetIntegerv(GL_CURRENT_PROGRAM, lastProgram);
glGetIntegerv(GL_TEXTURE_BINDING_2D, lastTexture);
// int[] last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); // do it by yourself if needed
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, lastArrayBuffer);
// int[] last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object); // do it by yourself if needed
// int[] last_polygon_mode; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); // do it by yourself if needed
glGetIntegerv(GL_VIEWPORT, lastViewport);
glGetIntegerv(GL_SCISSOR_BOX, lastScissorBox);
glGetIntegerv(GL_BLEND_SRC_RGB, lastBlendSrcRgb);
glGetIntegerv(GL_BLEND_DST_RGB, lastBlendDstRgb);
glGetIntegerv(GL_BLEND_SRC_ALPHA, lastBlendSrcAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, lastBlendDstAlpha);
glGetIntegerv(GL_BLEND_EQUATION_RGB, lastBlendEquationRgb);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, lastBlendEquationAlpha);
lastEnableBlend = glIsEnabled(GL_BLEND);
lastEnableCullFace = glIsEnabled(GL_CULL_FACE);
lastEnableDepthTest = glIsEnabled(GL_DEPTH_TEST);
lastEnableScissorTest = glIsEnabled(GL_SCISSOR_TEST);
}
private void restoreModifiedGlState() {
glUseProgram(lastProgram[0]);
glBindTexture(GL_TEXTURE_2D, lastTexture[0]);
glActiveTexture(lastActiveTexture[0]);
glBindBuffer(GL_ARRAY_BUFFER, lastArrayBuffer[0]);
glBlendEquationSeparate(lastBlendEquationRgb[0], lastBlendEquationAlpha[0]);
glBlendFuncSeparate(lastBlendSrcRgb[0], lastBlendDstRgb[0], lastBlendSrcAlpha[0], lastBlendDstAlpha[0]);
// @formatter:off
if (lastEnableBlend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (lastEnableCullFace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (lastEnableDepthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (lastEnableScissorTest) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
// @formatter:on
glViewport(lastViewport[0], lastViewport[1], lastViewport[2], lastViewport[3]);
glScissor(lastScissorBox[0], lastScissorBox[1], lastScissorBox[2], lastScissorBox[3]);
}
private void bind(final DrawData drawData) {
glViewport(0, 0, (int) drawData.displaySizeX, (int) drawData.displaySizeY);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
final float L = drawData.displayPosX;
final float R = drawData.displayPosX + drawData.displaySizeX;
final float T = drawData.displayPosY;
final float B = drawData.displayPosY + drawData.displaySizeY;
// Orthographic matrix projection
projMatrix[0] = 2.0f / (R - L);
projMatrix[5] = 2.0f / (T - B);
projMatrix[10] = -1.0f;
projMatrix[12] = (R + L) / (L - R);
projMatrix[13] = (T + B) / (B - T);
projMatrix[15] = 1.0f;
// Bind vertices
glBindBuffer(GL_ARRAY_BUFFER, vBufferHandle);
int location = glGetAttribLocation(programId, "Position");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 2, GL_FLOAT, false, 20, 0);
location = glGetAttribLocation(programId, "UV");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 2, GL_FLOAT, false, 20, 8);
location = glGetAttribLocation(programId, "Color");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 4, GL_UNSIGNED_BYTE, true, 20, 16);
//Bind index
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferHandle);
// Bind shader
glUseProgram(programId);
glUniformMatrix4fv(glGetUniformLocation(programId, "ProjMtx"), false, projMatrix);
glUniform1i(glGetUniformLocation(programId, "Texture"), 0);
}
private void unbind() {
// Unbind vertices
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(glGetAttribLocation(programId, "Position"));
glDisableVertexAttribArray(glGetAttribLocation(programId, "UV"));
glDisableVertexAttribArray(glGetAttribLocation(programId, "Color"));
// Unbind index
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glFlush();
// Unbind shader
glUseProgram(0);
}
private int loadAndCompileShader(final int type, final CharSequence source) {
int id = glCreateShader(type);
glShaderSource(id, source);
glCompileShader(id);
if (glGetShaderi(id, GL_COMPILE_STATUS) != GL_TRUE) {
throw new IllegalStateException(glGetShaderInfoLog(id));
}
return id;
}
private CharSequence readFromResources(final String path) {
StringBuilder builder = new StringBuilder();
try (InputStream in = getClass().getClassLoader().getResourceAsStream(path);
BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(in)))) {
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append('\n');
}
} catch (IOException ex) {
throw new UncheckedIOException("Failed to read from resources!", ex);
}
return builder.toString();
}
}
@@ -0,0 +1,14 @@
#version 130
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D Texture;
in vec2 Frag_UV;
in vec4 Frag_Color;
void main()
{
gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);
}
@@ -0,0 +1,15 @@
#version 130
uniform mat4 ProjMtx;
in vec2 Position;
in vec2 UV;
in vec4 Color;
out vec2 Frag_UV;
out vec4 Frag_Color;
void main()
{
Frag_UV = UV;
Frag_Color = Color;
gl_Position = ProjMtx * vec4(Position.xy, 0, 1);
}
Binary file not shown.
+2
View File
@@ -1,2 +1,4 @@
rootProject.name = 'imgui-java'
include 'imgui-binding'
include 'imgui-lwjgl3'