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

ImDrawList missing ImVec2 arguments #106

Closed
immetoo2 opened this issue Jan 20, 2022 · 0 comments · Fixed by #240
Closed

ImDrawList missing ImVec2 arguments #106

immetoo2 opened this issue Jan 20, 2022 · 0 comments · Fixed by #240
Labels
feat New feature or request

Comments

@immetoo2
Copy link

immetoo2 commented Jan 20, 2022

To learn the ImDrawList interface have recoded some of the FX drawing contests code to imgui-java from;
ocornut/imgui#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.

@SpaiR SpaiR added api feat New feature or request labels Feb 23, 2022
@SpaiR SpaiR mentioned this issue Aug 8, 2024
5 tasks
@SpaiR SpaiR closed this as completed in #240 Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants