Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/upgrade libgdx imgui #465

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ihmc-graphics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ libgdxDependencies {
api("us.ihmc:ihmc-java-toolkit:source")
api("us.ihmc:ihmc-robotics-toolkit:source")

val gdxVersion = "1.12.1"
val gdxVersion = "1.13.0"
api("com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion")
api("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop")
api("com.github.mgsx-dev.gdx-gltf:core:2.2.1")

val lwjglVersion = "3.3.3"
val lwjglVersion = "3.3.4"
api("org.lwjgl:lwjgl-openvr:$lwjglVersion")
api("org.lwjgl:lwjgl-openvr:$lwjglVersion:natives-linux")
api("org.lwjgl:lwjgl-openvr:$lwjglVersion:natives-windows")
Expand All @@ -65,12 +65,12 @@ libgdxDependencies {
api("org.lwjgl:lwjgl-assimp:$lwjglVersion:natives-windows-x86")
api("org.lwjgl:lwjgl-assimp:$lwjglVersion:natives-macos")

val imguiVersion = "1.86.11"
val imguiVersion = "1.87.6"
api("io.github.spair:imgui-java-binding:$imguiVersion")
api("io.github.spair:imgui-java-lwjgl3:$imguiVersion")
api("io.github.spair:imgui-java-natives-linux-ft:$imguiVersion")
api("io.github.spair:imgui-java-natives-macos-ft:$imguiVersion")
api("io.github.spair:imgui-java-natives-windows-ft:$imguiVersion")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freetype is included by default now

api("io.github.spair:imgui-java-natives-linux:$imguiVersion")
api("io.github.spair:imgui-java-natives-macos:$imguiVersion")
api("io.github.spair:imgui-java-natives-windows:$imguiVersion")

val javaFXVersion = "17.0.9"
api(ihmc.javaFXModule("graphics", javaFXVersion)) // JFX Color
Expand Down
14 changes: 8 additions & 6 deletions ihmc-graphics/src/libgdx/java/us/ihmc/rdx/imgui/ImGuiTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,32 +252,32 @@ public static boolean volatileInputDouble(String label, ImDouble imDouble, doubl

public static boolean sliderDouble(String label, ImDouble imDouble, double minValue, double maxValue)
{
return ImGui.sliderScalar(label, ImGuiDataType.Double, imDouble, minValue, maxValue);
return ImGui.sliderScalar(label, imDouble.getData(), minValue, maxValue);
}

public static boolean sliderDouble(String label, ImDouble imDouble, double minValue, double maxValue, String format)
{
return ImGui.sliderScalar(label, ImGuiDataType.Double, imDouble, minValue, maxValue, format);
return ImGui.sliderScalar(label, imDouble.getData(), minValue, maxValue, format);
}

public static boolean sliderDouble(String label, ImDouble imDouble, double minValue, double maxValue, String format, int imGuiSliderFlags)
{
return ImGui.sliderScalar(label, ImGuiDataType.Double, imDouble, minValue, maxValue, format, imGuiSliderFlags);
return ImGui.sliderScalar(label, imDouble.getData(), minValue, maxValue, format, imGuiSliderFlags);
}

public static boolean sliderInt(String label, ImInt imInt, int minValue, int maxValue)
{
return ImGui.sliderScalar(label, ImGuiDataType.U32, imInt, minValue, maxValue);
return ImGui.sliderScalar(label, imInt.getData(), minValue, maxValue);
}

public static boolean sliderInt(String label, ImInt imInt, int minValue, int maxValue, String format)
{
return ImGui.sliderScalar(label, ImGuiDataType.U32, imInt, minValue, maxValue, format);
return ImGui.sliderScalar(label, imInt.getData(), minValue, maxValue, format);
}

public static boolean sliderInt(String label, ImInt imInt, int minValue, int maxValue, String format, int imGuiSliderFlags)
{
return ImGui.sliderScalar(label, ImGuiDataType.U32, imInt, minValue, maxValue, format, imGuiSliderFlags);
return ImGui.sliderScalar(label, imInt.getData(), minValue, maxValue, format, imGuiSliderFlags);
}

public static boolean smallCheckbox(String label, ImBoolean checked)
Expand Down Expand Up @@ -510,6 +510,8 @@ public static String uniqueLabel(Object thisObject, String label)
*/
public static void setupFonts(ImGuiIO io)
{
ImGui.getIO().getFonts().setFreeTypeRenderer(true);

if (SystemUtils.IS_OS_WINDOWS)
FONT_DIRECTORY = System.getenv("WINDIR") + "/Fonts";
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.ihmc.rdx.imgui;

import imgui.extension.implot.ImPlot;
import imgui.extension.implot.flag.ImPlotAxis;
import imgui.flag.ImGuiCond;

import java.text.DecimalFormat;
Expand Down Expand Up @@ -50,6 +51,6 @@ public void setLimitYMin(double minLimitY)
limitY = Math.max(doubleSwapBuffer.getValue(i), limitY);
}
}
ImPlot.setNextPlotLimitsY(0.0, limitY, ImGuiCond.Always);
ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, limitY, ImGuiCond.Always);
}
}
20 changes: 10 additions & 10 deletions ihmc-graphics/src/libgdx/java/us/ihmc/rdx/imgui/ImPlotPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ImPlotPlot(float plotHeight)
flags += ImPlotFlags.NoMenus;
flags += ImPlotFlags.NoBoxSelect;
flags += ImPlotFlags.NoTitle;
flags += ImPlotFlags.NoMousePos;
flags += ImPlotFlags.NoMouseText;

xFlags = ImPlotAxisFlags.None;
xFlags += ImPlotAxisFlags.NoDecorations;
Expand Down Expand Up @@ -78,13 +78,15 @@ public void render(float plotWidth, float plotHeight)

outerBoundsDimensionsPixels.x = plotWidth;
outerBoundsDimensionsPixels.y = plotHeight;
customBeforePlotLogic.run();
if (ImPlot.beginPlot(labels.get("Plot"), xLabel, yLabel, outerBoundsDimensionsPixels, flags, xFlags, yFlags))
if (ImPlot.beginPlot(labels.get("Plot"), outerBoundsDimensionsPixels, flags))
{
customDuringPlotLogic.run();
ImPlot.setupAxis(ImPlotAxis.X1, xLabel, xFlags);
ImPlot.setupAxis(ImPlotAxis.Y1, yLabel, yFlags);
customBeforePlotLogic.run();
ImPlot.setupLegend(ImPlotLocation.SouthWest, ImPlotLegendFlags.Horizontal | ImPlotLegendFlags.Outside);
ImPlot.setupFinish();

boolean outside = true;
ImPlot.setLegendLocation(ImPlotLocation.SouthWest, ImPlotOrientation.Horizontal, outside);
customDuringPlotLogic.run();

boolean showingLegendPopup = false;
for (ImPlotPlotLine plotLine : plotLines)
Expand All @@ -95,7 +97,7 @@ public void render(float plotWidth, float plotHeight)
if (!plotLines.isEmpty() && ImPlot.isPlotHovered())
{
ImPlotPoint plotMousePosition = ImPlot.getPlotMousePos(ImPlotTools.IMPLOT_AUTO);
int bufferIndex = (int) Math.round(plotMousePosition.getX());
int bufferIndex = (int) Math.round(plotMousePosition.x);

StringBuilder tooltipText = new StringBuilder();
for (ImPlotPlotLine plotLine : plotLines)
Expand All @@ -105,8 +107,6 @@ public void render(float plotWidth, float plotHeight)
tooltipText.append(plotLine.getValueString(bufferIndex)).append("\n");
}
ImGui.setTooltip(tooltipText.toString().trim());

plotMousePosition.destroy();
}

if (popupContextWindowImGuiRenderer != null && !showingLegendPopup && ImGui.beginPopupContextWindow())
Expand All @@ -117,7 +117,7 @@ public void render(float plotWidth, float plotHeight)

if (dragAndDropPayloadConsumer != null)
{
if (ImPlot.beginDragDropTarget())
if (ImPlot.beginDragDropTargetPlot())
{
String payload = ImGui.acceptDragDropPayload(String.class);

Expand Down
11 changes: 7 additions & 4 deletions ihmc-graphics/src/libgdx/java/us/ihmc/rdx/imgui/ImPlotTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import imgui.extension.implot.ImPlot;
import imgui.extension.implot.ImPlotContext;
import imgui.extension.implot.ImPlotStyle;
import imgui.extension.implot.flag.ImPlotAxis;
import imgui.extension.implot.flag.ImPlotAxisFlags;
import imgui.extension.implot.flag.ImPlotFlags;

Expand Down Expand Up @@ -60,11 +61,13 @@ public static void setSCSStyle()
public static void renderEmptyPlotArea(String label, float width, float height)
{
emptyPlotSize.set(width, height);
if (ImPlot.beginPlot(label, "", "", emptyPlotSize,
ImPlotFlags.NoMenus | ImPlotFlags.NoBoxSelect | ImPlotFlags.NoTitle | ImPlotFlags.NoMousePos,
ImPlotAxisFlags.NoDecorations | ImPlotAxisFlags.NoLabel,
ImPlotAxisFlags.NoDecorations | ImPlotAxisFlags.NoLabel))
if (ImPlot.beginPlot(label, emptyPlotSize,
ImPlotFlags.NoMenus | ImPlotFlags.NoBoxSelect | ImPlotFlags.NoTitle | ImPlotFlags.NoMouseText))
{
ImPlot.setupAxis(ImPlotAxis.X1, "", ImPlotAxisFlags.NoDecorations | ImPlotAxisFlags.NoLabel);
ImPlot.setupAxis(ImPlotAxis.Y1, "", ImPlotAxisFlags.NoDecorations | ImPlotAxisFlags.NoLabel);
ImPlot.setupFinish();

ImPlot.endPlot();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ public void afterWindowManagement()

public void dispose()
{
imGuiGl3.dispose();
imGuiGlfw.dispose();
imGuiGl3.shutdown();
imGuiGlfw.shutdown();

ImGui.destroyContext();
if (debugMessageCallback != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void render(String text, int linesOfSpaceToGiveAbove)

float textPositionX = drawStartX + 5.0f;
float textPositionY = drawStartY + 2.0f;
ImGui.getWindowDrawList().addText(font, font.getFontSize(), textPositionX, textPositionY, Color.WHITE.toIntBits(), text);
ImGui.getWindowDrawList().addText(font, (int) font.getFontSize(), textPositionX, textPositionY, Color.WHITE.toIntBits(), text);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.ihmc.rdx.ui.behavior.sequence;

import imgui.extension.implot.ImPlot;
import imgui.extension.implot.flag.ImPlotAxis;
import imgui.extension.implot.flag.ImPlotFlags;
import imgui.flag.ImGuiCond;
import imgui.internal.ImGui;
Expand Down Expand Up @@ -111,7 +112,7 @@ private void setupPlot(ImPlotPlot plot, double limitYMin, ImPlotBasicDoublePlotL
double plotMaxY = plotLine.getMaxYValue();
max = Double.isNaN(max) ? plotMaxY : Math.max(plotMaxY, max);
}
ImPlot.setNextPlotLimitsY(0.0, Double.isNaN(max) ? limitYMin : Double.max(limitYMin, max), ImGuiCond.Always);
ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, Double.isNaN(max) ? limitYMin : Double.max(limitYMin, max), ImGuiCond.Always);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.graphics.Color;
import imgui.ImGui;
import imgui.extension.implot.ImPlot;
import imgui.extension.implot.flag.ImPlotAxis;
import imgui.extension.implot.flag.ImPlotAxisFlags;
import imgui.extension.implot.flag.ImPlotFlags;
import imgui.flag.ImGuiCond;
Expand Down Expand Up @@ -80,17 +81,17 @@ public ImGuiMachine(UUID instanceId, String hostname, ROS2Node ros2Node)
cpuPlot.setFlags(plotFlags);
cpuPlot.setXFlags(plotAxisXFlags);
cpuPlot.setYFlags(plotAxisYFlags);
cpuPlot.setCustomBeforePlotLogic(() -> ImPlot.setNextPlotLimitsY(0.0, 103.0, ImGuiCond.Always));
cpuPlot.setCustomBeforePlotLogic(() -> ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, 103.0, ImGuiCond.Always));

ramPlot.setFlags(plotFlags);
ramPlot.setXFlags(plotAxisXFlags);
ramPlot.setYFlags(plotAxisYFlags);
ramPlot.setCustomBeforePlotLogic(() -> ImPlot.setNextPlotLimitsY(0.0, lastResourceUsageMessage.getMemoryTotal(), ImGuiCond.Always));
ramPlot.setCustomBeforePlotLogic(() -> ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, lastResourceUsageMessage.getMemoryTotal(), ImGuiCond.Always));

netPlot.setFlags(plotFlags);
netPlot.setXFlags(plotAxisXFlags);
netPlot.setYFlags(plotAxisYFlags);
netPlot.setCustomBeforePlotLogic(() -> ImPlot.setNextPlotLimitsY(-3000.0, 103000.0, ImGuiCond.Always));
netPlot.setCustomBeforePlotLogic(() -> ImPlot.setupAxisLimits(ImPlotAxis.Y1, -3000.0, 103000.0, ImGuiCond.Always));

this.ros2Node = ros2Node;

Expand Down Expand Up @@ -154,7 +155,7 @@ private void acceptSystemResourceUsageMessage(SystemResourceUsageMessage message
plot.setXFlags(plotAxisXFlags);
plot.setYFlags(plotAxisYFlags);
String gpuModel = message.getNvidiaGpuModels().getString(0);
plot.setCustomBeforePlotLogic(() -> ImPlot.setNextPlotLimitsY(0.0, 103.0, ImGuiCond.Always));
plot.setCustomBeforePlotLogic(() -> ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, 103.0, ImGuiCond.Always));
plot.getPlotLines()
.add(new ImPlotDoublePlotLine("GPU (" + gpuIndex + ", " + gpuModel + ") utilization %",
GRAPH_BUFFER_SIZE,
Expand All @@ -174,7 +175,7 @@ private void acceptSystemResourceUsageMessage(SystemResourceUsageMessage message
plot.setYFlags(plotAxisYFlags);
String gpuModel = message.getNvidiaGpuModels().getString(0);
float totalGpuMemory = message.getNvidiaGpuMemoryTotal().get(gpuIndex);
plot.setCustomBeforePlotLogic(() -> ImPlot.setNextPlotLimitsY(0.0, totalGpuMemory, ImGuiCond.Always));
plot.setCustomBeforePlotLogic(() -> ImPlot.setupAxisLimits(ImPlotAxis.Y1, 0.0, totalGpuMemory, ImGuiCond.Always));
plot.getPlotLines()
.add(new ImPlotDoublePlotLine("GPU (" + gpuIndex + ", " + gpuModel + ") memory usage (GiB)",
GRAPH_BUFFER_SIZE,
Expand Down
Loading