imgui (#10)
Co-authored-by: Persson-dev <sim16.prib@gmail.com> Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
@@ -13,6 +13,7 @@ import chess.view.DDDrender.world.World;
|
||||
import common.Signal1;
|
||||
import imgui.ImFontConfig;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
import imgui.gl3.ImGuiImplGl3;
|
||||
import imgui.glfw.ImGuiImplGlfw;
|
||||
|
||||
@@ -92,15 +93,6 @@ public class Window implements Closeable {
|
||||
ImGui.destroyContext();
|
||||
}
|
||||
|
||||
private void setCallbacks() {
|
||||
glfwSetMouseButtonCallback(this.window, (window, button, action, mods) -> {
|
||||
if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) {
|
||||
if (this.lastCell.isValid())
|
||||
this.OnCellClick.emit(this.lastCell);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initImGui() {
|
||||
ImGui.setCurrentContext(ImGui.createContext());
|
||||
|
||||
@@ -162,8 +154,6 @@ public class Window implements Closeable {
|
||||
|
||||
GL.createCapabilities();
|
||||
|
||||
setCallbacks();
|
||||
|
||||
initImGui();
|
||||
|
||||
renderer.Init();
|
||||
@@ -176,9 +166,13 @@ public class Window implements Closeable {
|
||||
}
|
||||
|
||||
private void render(float delta, float aspectRatio) {
|
||||
cam.setAspectRatio(aspectRatio);
|
||||
cam.setAspectRatio(1.0f);
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 1);
|
||||
glViewport(0, 0, 800, 800);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
|
||||
renderer.Update(cam);
|
||||
renderWorld();
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
private void renderWorld() {
|
||||
@@ -198,11 +192,8 @@ public class Window implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCursor(int windowWidth, int windowHeight) {
|
||||
double x[] = new double[1];
|
||||
double y[] = new double[1];
|
||||
glfwGetCursorPos(this.window, x, y);
|
||||
Vector2f cursorPos = this.cam.getCursorWorldFloorPos(new Vector2f((float) x[0], (float) y[0]), windowWidth,
|
||||
private void checkCursor(float cursorPosX, float cursorPosY, int windowWidth, int windowHeight) {
|
||||
Vector2f cursorPos = this.cam.getCursorWorldFloorPos(new Vector2f(cursorPosX, cursorPosY), windowWidth,
|
||||
windowHeight);
|
||||
Coordinate selectedCell = DDDPlacement.vectorToCoordinates(cursorPos);
|
||||
if (this.lastCell == null) {
|
||||
@@ -216,6 +207,11 @@ public class Window implements Closeable {
|
||||
this.OnCellEnter.emit(selectedCell);
|
||||
this.lastCell = selectedCell;
|
||||
}
|
||||
|
||||
if (ImGui.getIO().getMouseClicked(0)) {
|
||||
if (this.lastCell != null && this.lastCell.isValid())
|
||||
this.OnCellClick.emit(this.lastCell);
|
||||
}
|
||||
}
|
||||
|
||||
private void newFrame() {
|
||||
@@ -226,6 +222,18 @@ public class Window implements Closeable {
|
||||
ImGui.newFrame();
|
||||
}
|
||||
|
||||
private void renderWindow() {
|
||||
ImGui.showDemoWindow();
|
||||
|
||||
ImGui.begin("Hello");
|
||||
ImGui.text("FPS : " + ImGui.getIO().getFramerate());
|
||||
ImVec2 mousePos = ImGui.getIO().getMousePos();
|
||||
ImVec2 framePos = ImGui.getCursorScreenPos();
|
||||
checkCursor(mousePos.x - framePos.x, 800 - (mousePos.y - framePos.y), 800, 800);
|
||||
ImGui.image(1, new ImVec2(800, 800));
|
||||
ImGui.end();
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
|
||||
// Set the clear color
|
||||
@@ -255,7 +263,7 @@ public class Window implements Closeable {
|
||||
float deltaTime = (float) (currentTime - lastTime);
|
||||
render(deltaTime, (float) width[0] / (float) height[0]);
|
||||
|
||||
// ImGui.showDemoWindow();
|
||||
renderWindow();
|
||||
ImGui.render();
|
||||
implGl3.renderDrawData(ImGui.getDrawData());
|
||||
|
||||
@@ -267,8 +275,6 @@ public class Window implements Closeable {
|
||||
// invoked during this call.
|
||||
glfwPollEvents();
|
||||
|
||||
checkCursor(width[0], height[0]);
|
||||
|
||||
executeTasks(deltaTime);
|
||||
|
||||
glfwGetWindowSize(window, width, height);
|
||||
|
||||
Reference in New Issue
Block a user