imgui work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-03-26 23:53:01 -04:00
parent 7f3cad3064
commit 253a2461b6
4 changed files with 76 additions and 5 deletions

View File

@ -1330,6 +1330,8 @@ Setup scaffolding for drag-and-drop asset handling
Editor mode asset file drag and drop
Editor mode pauses simulation
Tabs for editor view
ImGui drag-and-drop into viewport functionality
Normalized mouse pos lookup function

View File

@ -51,6 +51,13 @@ public class ImGuiEditorWindows {
}
if(ImGui.beginTabItem("Assets")){
ImGui.text("asset selector here");
if(ImGui.button("testasset")){
}
if(ImGui.beginDragDropSource()){
ImGui.setDragDropPayload("asdf");
ImGui.endDragDropSource();
}
ImGui.endTabItem();
}
if(ImGui.beginTabItem("Hierarchy")){

View File

@ -14,6 +14,7 @@ import java.util.LinkedList;
import java.util.List;
import org.joml.Vector2f;
import org.lwjgl.glfw.GLFW;
import electrosphere.client.entity.camera.CameraEntityUtils;
import electrosphere.client.ui.menu.WindowStrings;
@ -509,10 +510,25 @@ public class ControlHandler {
public Vector2f getMousePosition(){
double posX[] = new double[1];
double posY[] = new double[1];
glfwGetCursorPos(Globals.window, posX, posY);
GLFW.glfwGetCursorPos(Globals.window, posX, posY);
Vector2f rVal = new Vector2f((float)posX[0],(float)posY[0]);
return rVal;
}
/**
* Gets the mouse position as a vector2f
* @return The vector containing the mouse position
*/
public Vector2f getMousePositionNormalized(){
double posX[] = new double[1];
double posY[] = new double[1];
GLFW.glfwGetCursorPos(Globals.window, posX, posY);
int sizeX[] = new int[1];
int sizeY[] = new int[1];
GLFW.glfwGetWindowSize(Globals.window, sizeX, sizeY);
Vector2f rVal = new Vector2f((float)((2.0 * posX[0] / sizeX[0]) - 1.0),(float)(1.0 - (2.0 * posY[0] / sizeY[0])));
return rVal;
}
/**
* Sets whether the engine should try to recapture window focus next frame or not
@ -544,10 +560,12 @@ public class ControlHandler {
*/
public void setIsThirdPerson(boolean isThirdPerson){
this.cameraIsThirdPerson = isThirdPerson;
CameraEntityUtils.initCamera();
ClientEquipState playerEquipState = ClientEquipState.getClientEquipState(Globals.playerEntity);
if(playerEquipState != null){
playerEquipState.evaluatePlayerAttachments();
if(Globals.playerEntity != null){
CameraEntityUtils.initCamera();
ClientEquipState playerEquipState = ClientEquipState.getClientEquipState(Globals.playerEntity);
if(playerEquipState != null){
playerEquipState.evaluatePlayerAttachments();
}
}
}

View File

@ -6,11 +6,14 @@ import java.util.concurrent.CopyOnWriteArrayList;
import electrosphere.client.ui.menu.debug.ImGuiWindowMacros;
import electrosphere.client.ui.menu.editor.ImGuiEditorWindows;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.ui.imgui.ImGuiWindow;
import imgui.ImGui;
import imgui.ImGuiViewport;
import imgui.extension.implot.ImPlot;
import imgui.flag.ImGuiWindowFlags;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
import imgui.internal.ImGuiContext;
@ -58,6 +61,9 @@ public class ImGuiPipeline implements RenderPipeline {
if(imGuiShouldRender){
imGuiGlfw.newFrame();
ImGui.newFrame();
if(ImGuiPipeline.shouldRenderDragAndDropTarget()){
ImGuiPipeline.renderDragAndDropTarget();
}
for(ImGuiWindow window : imGuiWindows){
window.draw();
}
@ -98,6 +104,44 @@ public class ImGuiPipeline implements RenderPipeline {
return false;
}
/**
* Renders the drag and drop target window
*/
private static void renderDragAndDropTarget(){
//drag and drop target
ImGui.begin("dndTargetWindow",
0
|
ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoBackground
| ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoDecoration
// | ImGuiWindowFlags.NoInputs
);
ImGuiViewport viewport = ImGui.getWindowViewport();
ImGui.setWindowSize(viewport.getSizeX(), viewport.getSizeY());
ImGui.setWindowPos(0, 0);
ImGui.invisibleButton("dndTargetButton", viewport.getSizeX(), viewport.getSizeY());
if(ImGui.beginDragDropTarget()){
Object payload = ImGui.getDragDropPayload();
if(payload != null){
String text = ImGui.acceptDragDropPayload(String.class);
if(text != null){
LoggerInterface.loggerUI.WARNING("ImGui received drag'n'drop: " + text + " - " + payload);
LoggerInterface.loggerUI.WARNING(Globals.controlHandler.getMousePositionNormalized() + "");
}
}
ImGui.endDragDropTarget();
}
ImGui.end();
}
/**
* Checks if the drag and drop target should be rendered
* @return true if it should be rendered, false otherwise
*/
private static boolean shouldRenderDragAndDropTarget(){
return ImGuiEditorWindows.getHierarchyWindow().isOpen();
}
}