feat: Change docking settings, refactor code and add comments
This commit is contained in:
parent
813c744a12
commit
b23af2882c
@ -5,9 +5,9 @@
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
||||
// Global variables
|
||||
std::string log_message;
|
||||
bool show_demo_window = true;
|
||||
bool show_another_window = false;
|
||||
int display_w = 800, display_h = 600;
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
|
||||
void debug(std::string message){
|
||||
@ -17,9 +17,9 @@ void debug(std::string message){
|
||||
void show_menu(){
|
||||
if(ImGui::BeginMainMenuBar()){
|
||||
if(ImGui::BeginMenu("File")){
|
||||
if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */ }
|
||||
if (ImGui::MenuItem("Close", "Ctrl+W")) { show_another_window = false; }
|
||||
if (ImGui::MenuItem("Open..", "Ctrl+O")) { }
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) { }
|
||||
if (ImGui::MenuItem("Close", "Ctrl+W")) { }
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
@ -70,14 +70,12 @@ void show_inspector(){
|
||||
|
||||
ImGui::Begin("Inspector");
|
||||
|
||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
ImGui::Text("This is some useful text.");
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color);
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
if (ImGui::Button("Button"))
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
@ -86,12 +84,10 @@ void show_inspector(){
|
||||
}
|
||||
|
||||
int main(void){
|
||||
GLFWwindow* window;
|
||||
|
||||
if(!glfwInit())
|
||||
return -1;
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Ferx", NULL, NULL);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(display_w, display_h, "Ferx", NULL, NULL);
|
||||
if(!window){
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
@ -108,72 +104,55 @@ int main(void){
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4* colors = style.Colors;
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
while(!glfwWindowShouldClose(window)){
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwPollEvents();
|
||||
|
||||
// Set up draw data for rendering
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::DockSpaceOverViewport();
|
||||
// Setup docking
|
||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||
colors[ImGuiCol_DockingEmptyBg] = clear_color;
|
||||
|
||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||
// if (show_demo_window)
|
||||
// ImGui::ShowDemoWindow(&show_demo_window);
|
||||
|
||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
|
||||
show_menu();
|
||||
|
||||
// Show windows
|
||||
show_menu();
|
||||
show_hierarchy();
|
||||
|
||||
show_scene();
|
||||
|
||||
show_project();
|
||||
|
||||
show_console();
|
||||
|
||||
show_inspector();
|
||||
|
||||
// 3. Show another simple window.
|
||||
if (show_another_window)
|
||||
{
|
||||
ImGui::Begin("Another Window", &show_another_window,ImGuiWindowFlags_MenuBar); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */ }
|
||||
if (ImGui::MenuItem("Close", "Ctrl+W")) { show_another_window = false; }
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::Text("Hello from another window!");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
int display_w, display_h;
|
||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||
glViewport(0, 0, display_w, display_h);
|
||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
ImGui::EndFrame();
|
||||
|
||||
glfwTerminate();
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user