Skip to content

Commit

Permalink
GUI changes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
angad-k committed Aug 25, 2024
1 parent 0492d5d commit e9624e5
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 25 deletions.
140 changes: 130 additions & 10 deletions ProcSDF/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,24 @@ void GUI::setupFrame()

ImGui::NewFrame();
{
#ifdef IMGUI_HAS_VIEWPORT
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->GetWorkPos());
ImGui::SetNextWindowSize(viewport->GetWorkSize());
ImGui::SetNextWindowViewport(viewport->ID);
#else
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
#endif
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::Begin("ProcSDF", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize);

static float w = 550.0f;
static float h = 500.0f;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::BeginChild("Scene and Inspector", ImVec2(w, -1), true);
{
ImGui::Begin("Scene");

ImGui::BeginChild("Scene", ImVec2(w, h));
ImVec2 l_vMin = ImGui::GetWindowContentRegionMin();
ImVec2 l_vMax = ImGui::GetWindowContentRegionMax();

Expand All @@ -53,17 +68,36 @@ void GUI::setupFrame()
m_renderSceneSize = ImVec2(l_vMax.x - l_vMin.x, l_vMax.y - l_vMin.y);

ImGui::Image((ImTextureID)m_renderer->getRenderTexture(), m_renderSceneSize, ImVec2(0, 1), ImVec2(1, 0));

ImGui::End();
}

{
ImGui::EndChild();

//ImGui::InvisibleButton("hsplitter", ImVec2(w, 8.0f));
ImGui::Button(" ", ImVec2(w, 12.0f));
//ImGui::ColorButton("hsplitter", ImVec4(0.3f, 0.3f, 0.4f, 1.00f), 0, ImVec2(w, 8.0f));
if (ImGui::IsItemActive())
h += ImGui::GetIO().MouseDelta.y;

m_inspector->draw();


}

ImGui::EndChild();

ImGui::SameLine();
//ImGui::InvisibleButton("vsplitter", ImVec2(8.0f, -1));
ImGui::Button(" ", ImVec2(12.0f, -1));
if (ImGui::IsItemActive())
w += ImGui::GetIO().MouseDelta.x;
ImGui::SameLine();
ImGui::BeginChild("child2", ImVec2(0, -1), false);
{
m_nodeEditor->draw();
}
ImGui::EndChild();

ImGui::PopStyleVar();

ImGui::PopStyleVar();
ImGui::End();
}
}

Expand Down Expand Up @@ -91,7 +125,11 @@ GLFWwindow* GUI::setupImguiGlfw()
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

GLFWwindow* l_window = glfwCreateWindow(1280, 720, "ProcSDF", NULL, NULL);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();

const GLFWvidmode* mode = glfwGetVideoMode(monitor);

GLFWwindow* l_window = glfwCreateWindow(mode->width, mode->height, "ProcSDF", monitor, nullptr);
if (l_window == NULL)
return NULL;
glfwMakeContextCurrent(l_window);
Expand All @@ -109,14 +147,96 @@ GLFWwindow* GUI::setupImguiGlfw()

io.ConfigDragClickToInputText = true;

ImGui::StyleColorsDark();
setupStyle();

ImGui_ImplGlfw_InitForOpenGL(l_window, true);
ImGui_ImplOpenGL3_Init(l_glslVersion);

return l_window;
}

void GUI::setupStyle()
{
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.19f, 0.19f, 0.19f, 0.92f);
colors[ImGuiCol_Border] = ImVec4(0.19f, 0.19f, 0.19f, 0.29f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.24f);
colors[ImGuiCol_FrameBg] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 0.54f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 0.54f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.40f, 0.54f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.54f);
colors[ImGuiCol_CheckMark] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.34f, 0.34f, 0.34f, 0.54f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.54f);
colors[ImGuiCol_Button] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 0.54f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.00f, 0.00f, 0.00f, 0.36f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.20f, 0.22f, 0.23f, 0.33f);
colors[ImGuiCol_Separator] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.44f, 0.44f, 0.44f, 0.29f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.40f, 0.44f, 0.47f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.44f, 0.44f, 0.44f, 0.29f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.40f, 0.44f, 0.47f, 1.00f);
colors[ImGuiCol_Tab] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_TabHovered] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 0.36f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
colors[ImGuiCol_DragDropTarget] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
colors[ImGuiCol_NavHighlight] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 0.00f, 0.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(1.00f, 0.00f, 0.00f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 0.00f, 0.00f, 0.35f);

ImGuiStyle& style = ImGui::GetStyle();
style.WindowPadding = ImVec2(8.00f, 8.00f);
style.FramePadding = ImVec2(5.00f, 2.00f);
style.CellPadding = ImVec2(6.00f, 6.00f);
style.ItemSpacing = ImVec2(6.00f, 6.00f);
style.ItemInnerSpacing = ImVec2(6.00f, 6.00f);
style.TouchExtraPadding = ImVec2(0.00f, 0.00f);
style.IndentSpacing = 25;
style.ScrollbarSize = 15;
style.GrabMinSize = 10;
style.WindowBorderSize = 1;
style.ChildBorderSize = 1;
style.PopupBorderSize = 1;
style.FrameBorderSize = 1;
style.TabBorderSize = 1;
style.WindowRounding = 7;
style.ChildRounding = 4;
style.FrameRounding = 3;
style.PopupRounding = 4;
style.ScrollbarRounding = 9;
style.GrabRounding = 3;
style.LogSliderDeadzone = 4;
style.TabRounding = 4;
}

GUI::~GUI()
{
ImGui_ImplOpenGL3_Shutdown();
Expand Down
2 changes: 2 additions & 0 deletions ProcSDF/GUI/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class GUI
GLFWwindow* m_window;
GLFWwindow* setupImguiGlfw();

void setupStyle();

Renderer* m_renderer;
Inspector* m_inspector;
NodeEditor* m_nodeEditor;
Expand Down
5 changes: 3 additions & 2 deletions ProcSDF/GUI/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline Node* Inspector::addNode()

void Inspector::draw()
{
ImGui::Begin("Inspector");
ImGui::BeginChild("Inspector");

Tab l_oldTab = m_openedTab;

Expand Down Expand Up @@ -85,6 +85,7 @@ void Inspector::draw()
}

ImGui::Separator();
ImGui::Dummy(ImVec2(0.0f, 5.0f));

switch (m_openedTab)
{
Expand All @@ -102,7 +103,7 @@ void Inspector::draw()
break;
}

ImGui::End();
ImGui::EndChild();
}

void Inspector::drawWorldSettings()
Expand Down
52 changes: 42 additions & 10 deletions ProcSDF/GUI/NodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
#include "Common/constant.h"
#include "Common/ProjectSaver.h"
#include "Common/logger.h"
#include "GUI.h"

void NodeEditor::draw()
{
ImGui::Begin("Nodes workspace");
if (ImGui::Button("Recompile"))
ImGui::BeginChild("Nodes workspace");

if (ImGui::Button("Load Project"))
{
NodeGraph::getSingleton()->recompileNodeGraph();
bool isParseSucessful = ProjectSaver::loadProject();
if (!isParseSucessful) {
ERR("Error in parsing uploaded file");
}
}

ImGui::SameLine();

if (ImGui::Button("Save Project"))
Expand All @@ -22,12 +27,9 @@ void NodeEditor::draw()

ImGui::SameLine();

if (ImGui::Button("Load Project"))
if (ImGui::Button("Recompile"))
{
bool isParseSucessful = ProjectSaver::loadProject();
if (!isParseSucessful) {
ERR("Error in parsing uploaded file");
}
NodeGraph::getSingleton()->recompileNodeGraph();
}

ImGui::SameLine();
Expand Down Expand Up @@ -64,6 +66,36 @@ void NodeEditor::draw()
ImGui::PopStyleColor();
// ImNodes workspace starts from here.

ImGui::SameLine();

ImGuiStyle style = ImGui::GetStyle();
float widthNeeded = ImGui::CalcTextSize("Quit").x + style.FramePadding.x * 2.f;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - widthNeeded);
ImGui::PushStyleColor(ImGuiCol_Button, imgui_colors::RED);
if (ImGui::Button("Quit"))
{
ImGui::OpenPopup("Confirmation");
}
ImGui::PopStyleColor();
if (ImGui::BeginPopupModal("Confirmation")) {
ImGui::Text("Are you sure you want to quit? Unsaved changes would be lost.");

ImGui::Spacing();

if (ImGui::Button("Yes"))
{
glfwSetWindowShouldClose(GUI::getSingleton()->getWindow(), GL_TRUE);

}
ImGui::SameLine();
if (ImGui::Button("No"))
{
ImGui::CloseCurrentPopup();
}

ImGui::EndPopup();
}

ImNodes::BeginNodeEditor();

ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
Expand Down Expand Up @@ -108,5 +140,5 @@ void NodeEditor::draw()
ImNodes::GetSelectedNodes(m_selectedNodes.data());
}

ImGui::End();
ImGui::EndChild();
}
2 changes: 2 additions & 0 deletions ProcSDF/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "Rendering/ShaderGenerator.h"
#include "GUI/NodeGraph.h"

static bool should_close = false;

// This is just a one-liner I found online that increases the code's affinity to Nvidia's GPU and so,
// doesn't run on the integrated card by default.
extern "C" {
Expand Down
16 changes: 13 additions & 3 deletions ProcSDF/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ Size=657,566
Collapsed=0

[Window][Inspector]
Pos=-5,639
Size=703,361
Pos=-1,634
Size=708,369
Collapsed=0

[Window][Nodes workspace]
Pos=706,-2
Pos=39,295
Size=1221,998
Collapsed=0

[Window][ProcSDF]
Pos=0,0
Size=1920,1080
Collapsed=0

[Window][Confirmation]
Pos=738,508
Size=444,63
Collapsed=0

0 comments on commit e9624e5

Please sign in to comment.