From 70ffd01a6102e79f680f32aef51dcea00b4019c2 Mon Sep 17 00:00:00 2001 From: Matthew Laux Date: Sat, 9 Jul 2022 17:09:29 -0500 Subject: [PATCH] customize example for emulator --- cli/imgui_example.cpp | 84 +++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/cli/imgui_example.cpp b/cli/imgui_example.cpp index b541281..e64d757 100644 --- a/cli/imgui_example.cpp +++ b/cli/imgui_example.cpp @@ -13,6 +13,17 @@ #else #include #endif +#include + +static const char *A_FORMAT = "A: 0x%02x"; +static const char *B_FORMAT = "B: 0x%02x"; +static const char *C_FORMAT = "C: 0x%02x"; +static const char *D_FORMAT = "D: 0x%02x"; +static const char *E_FORMAT = "E: 0x%02x"; +static const char *H_FORMAT = "H: 0x%02x"; +static const char *L_FORMAT = "L: 0x%02x"; +static const char *SP_FORMAT = "SP: 0x%02x"; +static const char *PC_FORMAT = "PC: 0x%02x"; // Main code int main(int, char**) @@ -55,7 +66,7 @@ int main(int, char**) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); + SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, window_flags); SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, gl_context); SDL_GL_SetSwapInterval(1); // Enable vsync @@ -64,7 +75,7 @@ int main(int, char**) IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls // Setup Dear ImGui style @@ -75,26 +86,14 @@ int main(int, char**) ImGui_ImplSDL2_InitForOpenGL(window, gl_context); ImGui_ImplOpenGL3_Init(glsl_version); - // Load Fonts - // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. - // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. - // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). - // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'docs/FONTS.md' for more instructions and details. - // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! - //io.Fonts->AddFontDefault(); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); - //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); - //IM_ASSERT(font != NULL); - // Our state - bool show_demo_window = true; - bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + bool z_flag = false; + bool n_flag = false; + bool h_flag = false; + bool c_flag = false; + // Main loop bool done = false; while (!done) @@ -119,40 +118,39 @@ int main(int, char**) ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - // 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. { - static float f = 0.0f; - static int counter = 0; + ImGui::Begin("State"); // Create a window called "Hello, world!" and append into it. - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. - - 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::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 - - if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) - counter++; + ImGui::Text(A_FORMAT); + ImGui::Text(B_FORMAT); ImGui::SameLine(); - ImGui::Text("counter = %d", counter); + ImGui::Text(C_FORMAT); + ImGui::Text(D_FORMAT); + ImGui::SameLine(); + ImGui::Text(E_FORMAT); + ImGui::Text(H_FORMAT); + ImGui::SameLine(); + ImGui::Text(L_FORMAT); + ImGui::Text(SP_FORMAT); + ImGui::SameLine(); + ImGui::Text(PC_FORMAT); + + ImGui::Checkbox("Z", &z_flag); + ImGui::SameLine(); + ImGui::Checkbox("N", &n_flag); + ImGui::SameLine(); + ImGui::Checkbox("H", &h_flag); + ImGui::SameLine(); + ImGui::Checkbox("C", &c_flag); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } - // 3. Show another simple window. - if (show_another_window) { - ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) - ImGui::Text("Hello from another window!"); - if (ImGui::Button("Close Me")) - show_another_window = false; + ImGui::Begin("Output"); + ImGui::End(); }