imgui-java
imgui-java copied to clipboard
ImDrawList missing ImVec2 arguments
To learn the ImDrawList interface have recoded some of the FX drawing contests code to imgui-java from; https://github.com/ocornut/imgui/issues/3606
ImGuiIO io = ImGui.getIO();
ImVec2 size = new ImVec2(320f, 180f);
ImGui.begin("FX", ImGuiWindowFlags.AlwaysAutoResize);
ImGui.invisibleButton("canvas", size.x, size.y);
ImVec2 p0 = ImGui.getItemRectMin();
ImVec2 p1 = ImGui.getItemRectMax();
ImDrawList drawList = ImGui.getWindowDrawList();
drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y);
ImVec4 mouseData = new ImVec4();
mouseData.x = (io.getMousePosX() - p0.x) / size.x;
mouseData.y = (io.getMousePosY() - p0.y) / size.y;
mouseData.z = io.getMouseDoubleClickMaxDist(); // ??
mouseData.w = io.getMouseDragThreshold(); // ??
double imTime = ImGui.getTime();
FX(drawList, p0, p1, size, mouseData, (float)imTime);
drawList.popClipRect();
ImGui.end();
And two FX effects;
void FX(ImDrawList d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec4 mouse, float t)
{
float sx = 1.f / 16.f;
float sy = 1.f / 9.f;
for (float ty = 0.0f; ty < 1.0f; ty += sy) {
for (float tx = 0.0f; tx < 1.0f; tx += sx) {
ImVec2 c = new ImVec2((tx + 0.5f * sx), (ty + 0.5f * sy));
float k = 0.45f;
d.addRectFilled(
a.x + (c.x - k * sx) * sz.x, a.y + (c.y - k * sy) * sz.y,
a.x + (c.x + k * sx) * sz.x, a.y + (c.y + k * sy) * sz.y,
ImColor.intToColor((int)(ty * 200), (int)(tx * 255), 100, 255)
);
}
}
}
void FX(ImDrawList d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec4 mouse, float t)
{
for (int n = 0; n < (1.0f + Math.sin(t * 5.7f)) * 40.0f; n++) {
d.addCircle(a.x + sz.x * 0.5f, a.y + sz.y * 0.5f, sz.y * (0.01f + n * 0.03f),
ImColor.intToColor(255, 140 - n * 4, n * 3, 255)
);
}
}
It would be very nice to also have the ImVec2 arguments in the ImDrawList methods.