From ad28d3859372221c63d6122642cc1d39ec5a75d6 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 5 Dec 2024 19:20:32 +0100 Subject: [PATCH 1/6] replace fips-imgui and fips-cimgui with dcimgui --- CMakeLists.txt | 7 +++---- fips.yml | 6 ++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6e22512..052cf0db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,13 +2,13 @@ # project: sokol-samples # cmake_minimum_required(VERSION 3.21) -set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) if (FIPS_IOS) set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "") else() set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "") endif() -set(CMAKE_CXX_STANDARD 17) project(sokol-samples) if (SOKOL_USE_WGPU_DAWN) @@ -24,8 +24,7 @@ fips_ide_group("Imports") if (NOT USE_SOKOL_APP AND NOT SOKOL_USE_WGPU_DAWN AND NOT SOKOL_USE_D3D11 AND NOT SOKOL_USE_METAL) fips_import_fips_glfw_glfw3() endif() -fips_import_fips_imgui_imgui() -fips_import_fips_cimgui_cimgui() +fips_import_dcimgui_dcimgui() fips_import_fips_imgui_dock_imgui_dock() if (NOT FIPS_UWP) fips_import_fips_libmodplug_libmodplug() diff --git a/fips.yml b/fips.yml index bbf1562d..aff76b74 100644 --- a/fips.yml +++ b/fips.yml @@ -11,10 +11,6 @@ imports: git: https://github.com/floooh/sokol-tools-bin fips-glfw: git: https://github.com/fips-libs/fips-glfw - fips-cimgui: - git: https://github.com/fips-libs/fips-cimgui.git - fips-imgui: - git: https://github.com/fips-libs/fips-imgui.git fips-imgui-dock: git: https://github.com/fips-libs/fips-imgui-dock.git fips-libmodplug: @@ -23,3 +19,5 @@ imports: git: https://github.com/fips-libs/fips-utils fips-dawn: git: https://github.com/fips-libs/fips-dawn + dcimgui: + git: https://github.com/floooh/dcimgui From 3c8518d15b25451044f5005dd0697d43b73f300d Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 5 Dec 2024 19:21:04 +0100 Subject: [PATCH 2/6] fix sapp cimgui samples --- libs/cdbgui/CMakeLists.txt | 2 +- libs/cdbgui/cdbgui.c | 3 +- sapp/CMakeLists.txt | 24 +++---- sapp/cimgui-sapp.c | 11 ++-- sapp/customresolve-sapp.c | 17 +++-- sapp/drawcallperf-sapp.c | 9 ++- sapp/droptest-sapp.c | 24 ++++--- sapp/dyntex3d-sapp.c | 7 +- sapp/imgui-images-sapp.c | 13 ++-- sapp/imgui-perf-sapp.c | 12 ++-- sapp/imgui-usercallback-sapp.c | 15 ++--- sapp/pixelformats-sapp.c | 37 ++++++----- sapp/shdfeatures-sapp.c | 39 ++++++------ sapp/spine-inspector-sapp.c | 113 ++++++++++++++++----------------- 14 files changed, 157 insertions(+), 169 deletions(-) diff --git a/libs/cdbgui/CMakeLists.txt b/libs/cdbgui/CMakeLists.txt index 10c91de2..aac9858b 100644 --- a/libs/cdbgui/CMakeLists.txt +++ b/libs/cdbgui/CMakeLists.txt @@ -1,4 +1,4 @@ fips_begin_lib(cdbgui) fips_files(cdbgui.c cdbgui.h) - fips_deps(cimgui) + fips_deps(imgui) fips_end_lib(cdbgui) diff --git a/libs/cdbgui/cdbgui.c b/libs/cdbgui/cdbgui.c index 3b896c3d..027c6c66 100644 --- a/libs/cdbgui/cdbgui.c +++ b/libs/cdbgui/cdbgui.c @@ -7,8 +7,7 @@ #include "sokol_gfx.h" #include "sokol_app.h" #include "sokol_log.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #define SOKOL_GFX_IMGUI_IMPL diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index cf27bce3..280d2246 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -283,7 +283,7 @@ fips_end_app() fips_begin_app(dyntex3d-sapp windowed) fips_files(dyntex3d-sapp.c) sokol_shader(dyntex3d-sapp.glsl ${slang}) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) fips_end_app() fips_ide_group(Samples) @@ -318,7 +318,7 @@ fips_ide_group(Samples) fips_begin_app(customresolve-sapp windowed) fips_files(customresolve-sapp.c) sokol_shader_debuggable(customresolve-sapp.glsl ${slang}) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) fips_end_app() fips_ide_group(Samples) @@ -443,7 +443,7 @@ fips_end_app() fips_ide_group(Samples) fips_begin_app(cimgui-sapp windowed) fips_files(cimgui-sapp.c) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -453,7 +453,7 @@ fips_ide_group(Samples) fips_begin_app(imgui-usercallback-sapp windowed) fips_files(imgui-usercallback-sapp.c) sokol_shader(imgui-usercallback-sapp.glsl ${slang}) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -462,7 +462,7 @@ fips_end_app() fips_ide_group(Samples) fips_begin_app(imgui-images-sapp windowed) fips_files(imgui-images-sapp.c) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -471,7 +471,7 @@ fips_end_app() fips_ide_group(Samples) fips_begin_app(imgui-perf-sapp windowed) fips_files(imgui-perf-sapp.c) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -490,7 +490,7 @@ fips_ide_group(Samples) fips_begin_app(pixelformats-sapp windowed) fips_files(pixelformats-sapp.c) sokol_shader(pixelformats-sapp.glsl ${slang}) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -553,7 +553,7 @@ fips_end_app() fips_ide_group(SamplesWithDebugUI) fips_begin_app(sgl-microui-sapp-ui windowed) fips_files(sgl-microui-sapp.c) - fips_deps(sokol cdbgui cimgui microui) + fips_deps(sokol cdbgui imgui microui) target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() @@ -683,7 +683,7 @@ fips_ide_group(Samples) fips_begin_app(drawcallperf-sapp windowed) fips_files(drawcallperf-sapp.c) sokol_shader(drawcallperf-sapp.glsl ${slang}) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) fips_end_app() fips_ide_group(Samples) @@ -766,7 +766,7 @@ fips_end_app() fips_ide_group(Samples) fips_begin_app(droptest-sapp windowed) fips_files(droptest-sapp.c) - fips_deps(sokol cimgui) + fips_deps(sokol imgui) if (FIPS_IOS) fips_files(ios-info.plist) endif() @@ -901,7 +901,7 @@ fips_begin_app(spine-inspector-sapp windowed) fips_files(spine-inspector-sapp.c) fips_dir(data) fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil cimgui) + fips_deps(sokol spine-c stb fileutil imgui) fips_end_app() fips_ide_group(Samples) @@ -1004,7 +1004,7 @@ fips_begin_app(shdfeatures-sapp windowed) sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "l" "LIGHTING") fips_dir(data) fipsutil_copy(ozz-skin-assets.yml) - fips_deps(sokol fileutil ozzutil cimgui) + fips_deps(sokol fileutil ozzutil imgui) fips_end_app() if (NOT FIPS_ANDROID) diff --git a/sapp/cimgui-sapp.c b/sapp/cimgui-sapp.c index fbc3a104..67390f7d 100644 --- a/sapp/cimgui-sapp.c +++ b/sapp/cimgui-sapp.c @@ -8,8 +8,7 @@ #include "sokol_gfx.h" #include "sokol_log.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" @@ -60,10 +59,10 @@ void frame(void) { // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" static float f = 0.0f; igText("Hello, world!"); - igSliderFloat("float", &f, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_None); + igSliderFloatEx("float", &f, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_None); igColorEdit3("clear color", (float*)&state.pass_action.colors[0].clear_value, 0); - if (igButton("Test Window", (ImVec2) { 0.0f, 0.0f})) state.show_test_window ^= 1; - if (igButton("Another Window", (ImVec2) { 0.0f, 0.0f })) state.show_another_window ^= 1; + if (igButton("Test Window")) state.show_test_window ^= 1; + if (igButton("Another Window")) state.show_another_window ^= 1; igText("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / igGetIO()->Framerate, igGetIO()->Framerate); // 2. Show another simple window, this time using an explicit Begin/End pair @@ -76,7 +75,7 @@ void frame(void) { // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowDemoWindow() if (state.show_test_window) { - igSetNextWindowPos((ImVec2){460,20}, ImGuiCond_FirstUseEver, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){460,20}, ImGuiCond_FirstUseEver); igShowDemoWindow(0); } diff --git a/sapp/customresolve-sapp.c b/sapp/customresolve-sapp.c index 623e763e..e01aeb42 100644 --- a/sapp/customresolve-sapp.c +++ b/sapp/customresolve-sapp.c @@ -10,8 +10,7 @@ #include "sokol_glue.h" #define SOKOL_IMGUI_IMPL #define SOKOL_GFX_IMGUI_IMPL -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #include "sokol_imgui.h" #include "sokol_gfx_imgui.h" #include "customresolve-sapp.glsl.h" @@ -198,16 +197,16 @@ static void draw_ui(void) { } sgimgui_draw(&state.ui.sgimgui); - igSetNextWindowPos((ImVec2){10, 20}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){10, 20}, ImGuiCond_Once); if (igBegin("#window", 0, ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoBackground)) { if (sg_query_features().msaa_image_bindings) { igText("Sample Weights:"); - igSliderFloat("0", &state.resolve.fs_params.weight0, 0.0f, 1.0f, "%.2f", 0); - igSliderFloat("1", &state.resolve.fs_params.weight1, 0.0f, 1.0f, "%.2f", 0); - igSliderFloat("2", &state.resolve.fs_params.weight2, 0.0f, 1.0f, "%.2f", 0); - igSliderFloat("3", &state.resolve.fs_params.weight3, 0.0f, 1.0f, "%.2f", 0); - igCheckboxFlags_IntPtr("show complex pixels", &state.resolve.fs_params.coverage, 1); - if (igButton("Reset", (ImVec2){0,0})) { + igSliderFloatEx("0", &state.resolve.fs_params.weight0, 0.0f, 1.0f, "%.2f", 0); + igSliderFloatEx("1", &state.resolve.fs_params.weight1, 0.0f, 1.0f, "%.2f", 0); + igSliderFloatEx("2", &state.resolve.fs_params.weight2, 0.0f, 1.0f, "%.2f", 0); + igSliderFloatEx("3", &state.resolve.fs_params.weight3, 0.0f, 1.0f, "%.2f", 0); + igCheckboxFlagsIntPtr("show complex pixels", &state.resolve.fs_params.coverage, 1); + if (igButton("Reset")) { state.resolve.fs_params = default_weights; } } else { diff --git a/sapp/drawcallperf-sapp.c b/sapp/drawcallperf-sapp.c index 2a6d0eeb..03eade6b 100644 --- a/sapp/drawcallperf-sapp.c +++ b/sapp/drawcallperf-sapp.c @@ -6,8 +6,7 @@ #include "sokol_log.h" #include "sokol_time.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #define SOKOL_GFX_IMGUI_IMPL @@ -214,13 +213,13 @@ static void frame(void) { } // control ui - igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){600,200}, ImGuiCond_Once); if (igBegin("Controls", 0, ImGuiWindowFlags_NoResize)) { igText("Each cube/instance is 1 16-byte uniform update and 1 draw call\n"); igText("DC/texture is the number of adjacent draw calls with the same texture binding\n"); - igSliderInt("Num Instances", &state.num_instances, 100, MAX_INSTANCES, "%d", ImGuiSliderFlags_Logarithmic); - igSliderInt("DC/texture", &state.bind_frequency, 1, MAX_BIND_FREQUENCY, "%d", ImGuiSliderFlags_Logarithmic); + igSliderIntEx("Num Instances", &state.num_instances, 100, MAX_INSTANCES, "%d", ImGuiSliderFlags_Logarithmic); + igSliderIntEx("DC/texture", &state.bind_frequency, 1, MAX_BIND_FREQUENCY, "%d", ImGuiSliderFlags_Logarithmic); igText("Backend: %s", state.backend); igText("Frame duration: %.4fms", frame_measured_time * 1000.0); igText("sg_apply_bindings(): %d\n", state.stats.num_binding_updates); diff --git a/sapp/droptest-sapp.c b/sapp/droptest-sapp.c index b3b62755..6d045d19 100644 --- a/sapp/droptest-sapp.c +++ b/sapp/droptest-sapp.c @@ -7,8 +7,7 @@ #include "sokol_fetch.h" #include "sokol_log.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" @@ -52,11 +51,11 @@ static void render_file_content(void) { const int bytes_per_line = 16; // keep this 2^N const int num_lines = (state.size + (bytes_per_line - 1)) / bytes_per_line; - igBeginChild_Str("##scrolling", (ImVec2){0,0}, false, ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoNav); - ImGuiListClipper* clipper = ImGuiListClipper_ImGuiListClipper(); - ImGuiListClipper_Begin(clipper, num_lines, igGetTextLineHeight()); - ImGuiListClipper_Step(clipper); - for (int line_i = clipper->DisplayStart; line_i < clipper->DisplayEnd; line_i++) { + igBeginChild("##scrolling", (ImVec2){0,0}, false, ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoNav); + ImGuiListClipper clipper = {0}; + ImGuiListClipper_Begin(&clipper, num_lines, igGetTextLineHeight()); + ImGuiListClipper_Step(&clipper); + for (int line_i = clipper.DisplayStart; line_i < clipper.DisplayEnd; line_i++) { int start_offset = line_i * bytes_per_line; int end_offset = start_offset + bytes_per_line; if (end_offset >= state.size) { @@ -64,13 +63,13 @@ static void render_file_content(void) { } igText("%04X: ", start_offset); for (int i = start_offset; i < end_offset; i++) { - igSameLine(0.0f, 0.0f); + igSameLine(); igText("%02X ", state.buffer[i]); } - igSameLine((6 * 7.0f) + (bytes_per_line * 3 * 7.0f) + (2 * 7.0f), 0.0f); + igSameLineEx((6 * 7.0f) + (bytes_per_line * 3 * 7.0f) + (2 * 7.0f), 0.0f); for (int i = start_offset; i < end_offset; i++) { if (i != start_offset) { - igSameLine(0.0f, 0.0f); + igSameLine(); } uint8_t c = state.buffer[i]; if ((c < 32) || (c > 127)) { @@ -80,8 +79,7 @@ static void render_file_content(void) { } } igText("EOF\n"); - ImGuiListClipper_End(clipper); - ImGuiListClipper_destroy(clipper); + ImGuiListClipper_End(&clipper); igEndChild(); } @@ -99,7 +97,7 @@ static void frame(void) { .dpi_scale = sapp_dpi_scale() }); - igSetNextWindowPos((ImVec2){10, 10}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){10, 10}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){600,500}, ImGuiCond_Once); igBegin("Drop a file!", 0, 0); if (state.load_state != LOADSTATE_UNKNOWN) { diff --git a/sapp/dyntex3d-sapp.c b/sapp/dyntex3d-sapp.c index ec5fabab..1b1e93f2 100644 --- a/sapp/dyntex3d-sapp.c +++ b/sapp/dyntex3d-sapp.c @@ -9,8 +9,7 @@ #include "sokol_log.h" #include "sokol_glue.h" #include "dyntex3d-sapp.glsl.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #define SOKOL_GFX_IMGUI_IMPL @@ -121,11 +120,11 @@ static void draw_ui(void) { sgimgui_draw_menu(&state.sgimgui, "sokol-gfx"); igEndMainMenuBar(); } - igSetNextWindowPos((ImVec2){20, 40}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){20, 40}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){220, 150}, ImGuiCond_Once); igSetNextWindowBgAlpha(0.35f); if (igBegin("Controls", 0, ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_AlwaysAutoResize)) { - if (igSliderInt("Size", &state.width_height, MIN_WIDTH_HEIGHT, MAX_WIDTH_HEIGHT, "%d", ImGuiSliderFlags_Logarithmic)) { + if (igSliderIntEx("Size", &state.width_height, MIN_WIDTH_HEIGHT, MAX_WIDTH_HEIGHT, "%d", ImGuiSliderFlags_Logarithmic)) { recreate_image(); } if (igCheckbox("Immutable", &state.immutable)) { diff --git a/sapp/imgui-images-sapp.c b/sapp/imgui-images-sapp.c index 7d719985..80b04e19 100644 --- a/sapp/imgui-images-sapp.c +++ b/sapp/imgui-images-sapp.c @@ -11,8 +11,7 @@ #include "sokol_gfx.h" #include "sokol_log.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #define SOKOL_GL_IMPL @@ -177,7 +176,7 @@ static void frame(void) { .delta_time = sapp_frame_duration(), .dpi_scale = sapp_dpi_scale(), }); - igSetNextWindowPos((ImVec2){20, 20}, ImGuiCond_Once, (ImVec2){0, 0}); + igSetNextWindowPos((ImVec2){20, 20}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){540, 560}, ImGuiCond_Once); if (igBegin("Sokol + Dear ImGui Image Test", 0, 0)) { const ImVec4 white = { 1, 1, 1, 1 }; @@ -185,10 +184,10 @@ static void frame(void) { const ImVec2 uv0 = { 0, 0 }; const ImVec2 uv1 = { 1, 1 }; const ImVec2 uv2 = { 4, 4 }; - igImage(simgui_imtextureid(state.ui.img_nearest_clamp), size, uv0, uv1, white, white); igSameLine(0, 4); - igImage(simgui_imtextureid(state.ui.img_linear_clamp), size, uv0, uv1, white, white); - igImage(simgui_imtextureid(state.ui.img_nearest_repeat), size, uv0, uv2, white, white); igSameLine(0, 4); - igImage(simgui_imtextureid(state.ui.img_linear_mirror), size, uv0, uv2, white, white); + igImageEx(simgui_imtextureid(state.ui.img_nearest_clamp), size, uv0, uv1, white, white); igSameLineEx(0, 4); + igImageEx(simgui_imtextureid(state.ui.img_linear_clamp), size, uv0, uv1, white, white); + igImageEx(simgui_imtextureid(state.ui.img_nearest_repeat), size, uv0, uv2, white, white); igSameLineEx(0, 4); + igImageEx(simgui_imtextureid(state.ui.img_linear_mirror), size, uv0, uv2, white, white); } igEnd(); diff --git a/sapp/imgui-perf-sapp.c b/sapp/imgui-perf-sapp.c index cae84b05..af9c29d1 100644 --- a/sapp/imgui-perf-sapp.c +++ b/sapp/imgui-perf-sapp.c @@ -8,12 +8,12 @@ #include "sokol_time.h" #include "sokol_log.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #include // sinf, cosf +#include // snprintf static const int max_windows = 128; @@ -88,10 +88,10 @@ static void frame(void) { }); // controls window - igSetNextWindowPos((ImVec2){ 10, 10 }, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){ 10, 10 }, ImGuiCond_Once); igSetNextWindowSize((ImVec2){ 500, 0 }, ImGuiCond_Once); igBegin("Controls", 0, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoScrollbar); - igSliderInt("Num Windows", &state.num_windows, 1, max_windows, "%d", ImGuiSliderFlags_None); + igSliderInt("Num Windows", &state.num_windows, 1, max_windows); igText("raw frame time: %.3fms (min: %.3f, max: %.3f)", raw_frame_time * 1000.0, state.min_raw_frame_time * 1000.0, @@ -100,7 +100,7 @@ static void frame(void) { rounded_frame_time * 1000.0, state.min_rounded_frame_time * 1000.0, state.max_rounded_frame_time * 1000.0); - if (igButton("Reset min/max times", (ImVec2){0,0})) { + if (igButton("Reset min/max times")) { reset_minmax_frametimes(); } igEnd(); @@ -114,7 +114,7 @@ static void frame(void) { const float y = fheight * (0.5f + (r * 0.5f * 0.75f * cosf(t * 0.05f))); char name[64]; snprintf(name, sizeof(name), "Hello ImGui %d", i); - igSetNextWindowPos((ImVec2){x,y}, ImGuiCond_Always, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){x,y}, ImGuiCond_Always); igSetNextWindowSize((ImVec2){100, 10}, ImGuiCond_Always); igBegin(name, 0, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoFocusOnAppearing); igEnd(); diff --git a/sapp/imgui-usercallback-sapp.c b/sapp/imgui-usercallback-sapp.c index e902ecff..f55123a1 100644 --- a/sapp/imgui-usercallback-sapp.c +++ b/sapp/imgui-usercallback-sapp.c @@ -14,8 +14,7 @@ #define HANDMADE_MATH_IMPLEMENTATION #define HANDMADE_MATH_NO_SSE #include "HandmadeMath.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #include "imgui-usercallback-sapp.glsl.h" @@ -283,18 +282,18 @@ void frame(void) { .dpi_scale = sapp_dpi_scale() }); - igSetNextWindowPos((ImVec2){20, 20}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){20, 20}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){800, 400}, ImGuiCond_Once); if (igBegin("Dear ImGui", 0, 0)) { - if (igBeginChild_Str("sokol-gfx", (ImVec2){360, 360}, true, ImGuiWindowFlags_None)) { + if (igBeginChild("sokol-gfx", (ImVec2){360, 360}, true, ImGuiWindowFlags_None)) { ImDrawList* dl = igGetWindowDrawList(); - ImDrawList_AddCallback(dl, draw_scene_1, 0, 0); + ImDrawList_AddCallback(dl, draw_scene_1, 0); } igEndChild(); - igSameLine(0, 10); - if (igBeginChild_Str("sokol-gl", (ImVec2){360, 360}, true, ImGuiWindowFlags_None)) { + igSameLineEx(0, 10); + if (igBeginChild("sokol-gl", (ImVec2){360, 360}, true, ImGuiWindowFlags_None)) { ImDrawList* dl = igGetWindowDrawList(); - ImDrawList_AddCallback(dl, draw_scene_2, 0, 0); + ImDrawList_AddCallback(dl, draw_scene_2, 0); } igEndChild(); } diff --git a/sapp/pixelformats-sapp.c b/sapp/pixelformats-sapp.c index b50249e8..8b6348b8 100644 --- a/sapp/pixelformats-sapp.c +++ b/sapp/pixelformats-sapp.c @@ -6,8 +6,7 @@ #include "sokol_app.h" #include "sokol_log.h" #include "sokol_glue.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" #define HANDMADE_MATH_IMPLEMENTATION @@ -360,31 +359,31 @@ static void frame(void) { }); igSetNextWindowSize((ImVec2){640, 480}, ImGuiCond_Once); if (igBegin("Pixel Formats (without UINT and SINT formats)", 0, 0)) { - igText("format"); igSameLine(264, 0); - igText("sample"); igSameLine(264 + 1*66, 0); - igText("filter"); igSameLine(264 + 2*66, 0); - igText("render"); igSameLine(264 + 3*66, 0); - igText("blend"); igSameLine(264 + 4*66, 0); + igText("format"); igSameLineEx(264, 0); + igText("sample"); igSameLineEx(264 + 1*66, 0); + igText("filter"); igSameLineEx(264 + 2*66, 0); + igText("render"); igSameLineEx(264 + 3*66, 0); + igText("blend"); igSameLineEx(264 + 4*66, 0); igText("msaa"); igSeparator(); - igBeginChild_Str("#scrollregion", (ImVec2){0,0}, false, ImGuiWindowFlags_None); + igBeginChild("#scrollregion", (ImVec2){0,0}, false, ImGuiWindowFlags_None); for (int i = SG_PIXELFORMAT_NONE+1; i < SG_PIXELFORMAT_DEPTH; i++) { if (!state.fmt[i].valid) { continue; } const char* fmt_string = pixelformat_string((sg_pixel_format)i); - if (igBeginChild_Str(fmt_string, (ImVec2){0,80}, false, ImGuiWindowFlags_NoMouseInputs|ImGuiWindowFlags_NoScrollbar)) { + if (igBeginChild(fmt_string, (ImVec2){0,80}, false, ImGuiWindowFlags_NoMouseInputs|ImGuiWindowFlags_NoScrollbar)) { igText("%s", fmt_string); - igSameLine(256, 0); - igImage(simgui_imtextureid(state.fmt[i].unfiltered), (ImVec2){64,64}, (ImVec2){0,0}, (ImVec2){1,1}, (ImVec4){1,1,1,1}, (ImVec4){1,1,1,1}); - igSameLine(0,0); - igImage(simgui_imtextureid(state.fmt[i].filtered), (ImVec2){64,64}, (ImVec2){0,0}, (ImVec2){1,1}, (ImVec4){1,1,1,1}, (ImVec4){1,1,1,1}); - igSameLine(0,0); - igImage(simgui_imtextureid(state.fmt[i].render), (ImVec2){64,64}, (ImVec2){0,0}, (ImVec2){1,1}, (ImVec4){1,1,1,1}, (ImVec4){1,1,1,1}); - igSameLine(0,0); - igImage(simgui_imtextureid(state.fmt[i].blend), (ImVec2){64,64}, (ImVec2){0,0}, (ImVec2){1,1}, (ImVec4){1,1,1,1}, (ImVec4){1,1,1,1}); - igSameLine(0,0); - igImage(simgui_imtextureid(state.fmt[i].msaa_resolve), (ImVec2){64,64}, (ImVec2){0,0}, (ImVec2){1,1}, (ImVec4){1,1,1,1}, (ImVec4){1,1,1,1}); + igSameLineEx(256, 0); + igImage(simgui_imtextureid(state.fmt[i].unfiltered), (ImVec2){64,64}); + igSameLine(); + igImage(simgui_imtextureid(state.fmt[i].filtered), (ImVec2){64,64}); + igSameLine(); + igImage(simgui_imtextureid(state.fmt[i].render), (ImVec2){64,64}); + igSameLine(); + igImage(simgui_imtextureid(state.fmt[i].blend), (ImVec2){64,64}); + igSameLine(); + igImage(simgui_imtextureid(state.fmt[i].msaa_resolve), (ImVec2){64,64}); } igEndChild(); } diff --git a/sapp/shdfeatures-sapp.c b/sapp/shdfeatures-sapp.c index c5f96470..86d39012 100644 --- a/sapp/shdfeatures-sapp.c +++ b/sapp/shdfeatures-sapp.c @@ -39,8 +39,7 @@ #define SOKOL_GL_IMPL #include "sokol_gl.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h" @@ -664,7 +663,7 @@ static float* uniform_ptr_float(const shader_variation_t* var, uint8_t* base_ptr } static void draw_ui(void) { - igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){220,150 }, ImGuiCond_Once); if (igBegin("Controls", 0, ImGuiWindowFlags_AlwaysAutoResize)) { if (ozz_load_failed(state.ozz)) { @@ -674,44 +673,44 @@ static void draw_ui(void) { igText("Camera Controls:"); igText(" LMB + Mouse Move: Look"); igText(" Mouse Wheel: Zoom"); - igPushID_Str("camera"); - igSliderFloat("Distance", &state.camera.distance, state.camera.min_dist, state.camera.max_dist, "%.1f", ImGuiSliderFlags_None); - igSliderFloat("Latitude", &state.camera.latitude, state.camera.min_lat, state.camera.max_lat, "%.1f", ImGuiSliderFlags_None); - igSliderFloat("Longitude", &state.camera.longitude, 0.0f, 360.0f, "%.1f", ImGuiSliderFlags_None); + igPushID("camera"); + igSliderFloatEx("Distance", &state.camera.distance, state.camera.min_dist, state.camera.max_dist, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Latitude", &state.camera.latitude, state.camera.min_lat, state.camera.max_lat, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Longitude", &state.camera.longitude, 0.0f, 360.0f, "%.1f", ImGuiSliderFlags_None); igPopID(); igSeparator(); - igPushStyleColor_U32(ImGuiCol_CheckMark, green); + igPushStyleColor(ImGuiCol_CheckMark, green); igCheckbox("Enable Skinning", &state.skinning.enabled); - igPopStyleColor(1); + igPopStyleColor(); if (state.skinning.enabled) { igSeparator(); igCheckbox("Paused", &state.skinning.paused); - igSliderFloat("Time Factor", &state.skinning.time_factor, 0.0f, 10.0f, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Time Factor", &state.skinning.time_factor, 0.0f, 10.0f, "%.1f", ImGuiSliderFlags_None); } igSeparator(); - igPushStyleColor_U32(ImGuiCol_CheckMark, green); + igPushStyleColor(ImGuiCol_CheckMark, green); igCheckbox("Enable Lighting", &state.light.enabled); - igPopStyleColor(1); + igPopStyleColor(); if (state.light.enabled) { - igPushID_Str("light"); + igPushID("light"); igSeparator(); igCheckbox("Draw Light Vector", &state.light.dbg_draw); - igSliderFloat("Latitude", &state.light.latitude, -85.0f, 85.0f, "%.1f", ImGuiSliderFlags_None); - igSliderFloat("Longitude", &state.light.longitude, 0.0f, 360.0f, "%.1f", ImGuiSliderFlags_None); - igSliderFloat("Intensity", &state.light.intensity, 0.0f, 10.0f, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Latitude", &state.light.latitude, -85.0f, 85.0f, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Longitude", &state.light.longitude, 0.0f, 360.0f, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Intensity", &state.light.intensity, 0.0f, 10.0f, "%.1f", ImGuiSliderFlags_None); igColorEdit3("Color", &state.light.color.X, ImGuiColorEditFlags_None); igPopID(); } igSeparator(); - igPushStyleColor_U32(ImGuiCol_CheckMark, green); + igPushStyleColor(ImGuiCol_CheckMark, green); igCheckbox("Enable Material", &state.material.enabled); - igPopStyleColor(1); + igPopStyleColor(); if (state.material.enabled) { - igPushID_Str("material"); + igPushID("material"); igSeparator(); igColorEdit3("Diffuse", &state.material.diffuse.X, ImGuiColorEditFlags_None); igColorEdit3("Specular", &state.material.specular.X, ImGuiColorEditFlags_None); - igSliderFloat("Spec Pwr", &state.material.spec_power, 1.0f, 64.0f, "%.1f", ImGuiSliderFlags_None); + igSliderFloatEx("Spec Pwr", &state.material.spec_power, 1.0f, 64.0f, "%.1f", ImGuiSliderFlags_None); igPopID(); } } diff --git a/sapp/spine-inspector-sapp.c b/sapp/spine-inspector-sapp.c index f89036f0..fa986856 100644 --- a/sapp/spine-inspector-sapp.c +++ b/sapp/spine-inspector-sapp.c @@ -15,8 +15,7 @@ #include "sokol_gl.h" #define SOKOL_IMGUI_IMPL #define SOKOL_GFX_IMGUI_IMPL -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #include "sokol_imgui.h" #include "sokol_gfx_imgui.h" #include "stb/stb_image.h" @@ -504,37 +503,37 @@ static const char* ui_sgwrap_name(sg_wrap w) { static void ui_draw(void) { if (igBeginMainMenuBar()) { - if (igBeginMenu("sokol-spine", true)) { - if (igBeginMenu("Load", true)) { + if (igBeginMenu("sokol-spine")) { + if (igBeginMenu("Load")) { for (int i = 0; i < MAX_SPINE_SCENES; i++) { if (spine_scenes[i].ui_name) { - if (igMenuItem_Bool(spine_scenes[i].ui_name, 0, (i == state.load_status.scene_index), true)) { + if (igMenuItemEx(spine_scenes[i].ui_name, 0, (i == state.load_status.scene_index), true)) { load_spine_scene(i); } } } igEndMenu(); } - igMenuItem_BoolPtr("Draw Bones", 0, &state.ui.draw_bones_enabled, true); - igMenuItem_BoolPtr("Atlas...", 0, &state.ui.atlas_open, true); - igMenuItem_BoolPtr("Bones...", 0, &state.ui.bones_open, true); - igMenuItem_BoolPtr("Slots...", 0, &state.ui.slots_open, true); - igMenuItem_BoolPtr("Anims...", 0, &state.ui.anims_open, true); - igMenuItem_BoolPtr("Events...", 0, &state.ui.events_open, true); - igMenuItem_BoolPtr("Skins...", 0, &state.ui.skins_open, true); - igMenuItem_BoolPtr("IK Targets...", 0, &state.ui.iktargets_open, true); + igMenuItemBoolPtr("Draw Bones", 0, &state.ui.draw_bones_enabled, true); + igMenuItemBoolPtr("Atlas...", 0, &state.ui.atlas_open, true); + igMenuItemBoolPtr("Bones...", 0, &state.ui.bones_open, true); + igMenuItemBoolPtr("Slots...", 0, &state.ui.slots_open, true); + igMenuItemBoolPtr("Anims...", 0, &state.ui.anims_open, true); + igMenuItemBoolPtr("Events...", 0, &state.ui.events_open, true); + igMenuItemBoolPtr("Skins...", 0, &state.ui.skins_open, true); + igMenuItemBoolPtr("IK Targets...", 0, &state.ui.iktargets_open, true); igEndMenu(); } sgimgui_draw_menu(&state.ui.sgimgui, "sokol-gfx"); - if (igBeginMenu("options", true)) { + if (igBeginMenu("options")) { static int theme = 0; - if (igRadioButton_IntPtr("Dark Theme", &theme, 0)) { + if (igRadioButtonIntPtr("Dark Theme", &theme, 0)) { igStyleColorsDark(0); } - if (igRadioButton_IntPtr("Light Theme", &theme, 1)) { + if (igRadioButtonIntPtr("Light Theme", &theme, 1)) { igStyleColorsLight(0); } - if (igRadioButton_IntPtr("Classic Theme", &theme, 2)) { + if (igRadioButtonIntPtr("Classic Theme", &theme, 2)) { igStyleColorsClassic(0); } igEndMenu(); @@ -545,7 +544,7 @@ static void ui_draw(void) { ImVec2 pos = IMVEC2(30, 30); if (state.ui.atlas_open) { igSetNextWindowSize(IMVEC2(300, 330), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Spine Atlas", &state.ui.atlas_open, 0)) { if (!sspine_atlas_valid(state.atlas)) { igText("No Spine data loaded."); @@ -582,30 +581,30 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.bones_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Bones", &state.ui.bones_open, 0)) { if (!sspine_instance_valid(state.instance)) { igText("No Spine data loaded."); } else { const int num_bones = sspine_num_bones(state.skeleton); igText("Num Bones: %d", num_bones); - igBeginChild_Str("bones_list", IMVEC2(128, 0), true, 0); + igBeginChild("bones_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_bones; i++) { const sspine_bone bone = sspine_bone_by_index(state.skeleton, i); const sspine_bone_info info = sspine_get_bone_info(bone); assert(info.valid); - igPushID_Int(bone.index); - if (igSelectable_Bool(info.name.cstr, sspine_bone_equal(state.ui.selected.bone, bone), 0, IMVEC2(0,0))) { + igPushIDInt(bone.index); + if (igSelectableEx(info.name.cstr, sspine_bone_equal(state.ui.selected.bone, bone), 0, IMVEC2(0,0))) { state.ui.selected.bone = bone; } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_bone_valid(state.ui.selected.bone)) { const sspine_bone_info info = sspine_get_bone_info(state.ui.selected.bone); assert(info.valid); - igBeginChild_Str("bone_info", IMVEC2(0,0), false, 0); + igBeginChild("bone_info", IMVEC2(0,0), false, 0); igText("Index: %d", info.index); igText("Parent Bone: %s", sspine_bone_valid(info.parent_bone) ? sspine_get_bone_info(info.parent_bone).name.cstr : "---"); igText("Name: %s", info.name.cstr); @@ -631,32 +630,32 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.slots_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Slots", &state.ui.slots_open, 0)) { if (!sspine_instance_valid(state.instance)) { igText("No Spine data loaded."); } else { const int num_slots = sspine_num_slots(state.skeleton); igText("Num Slots: %d", num_slots); - igBeginChild_Str("slot_list", IMVEC2(128, 0), true, 0); + igBeginChild("slot_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_slots; i++) { const sspine_slot slot = sspine_slot_by_index(state.skeleton, i); const sspine_slot_info info = sspine_get_slot_info(slot); assert(info.valid); - igPushID_Int(slot.index); - if (igSelectable_Bool(info.name.cstr, sspine_slot_equal(state.ui.selected.slot, slot), 0, IMVEC2(0,0))) { + igPushIDInt(slot.index); + if (igSelectableEx(info.name.cstr, sspine_slot_equal(state.ui.selected.slot, slot), 0, IMVEC2(0,0))) { state.ui.selected.slot = slot; } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_slot_valid(state.ui.selected.slot)) { const sspine_slot_info slot_info = sspine_get_slot_info(state.ui.selected.slot); assert(slot_info.valid); const sspine_bone_info bone_info = sspine_get_bone_info(slot_info.bone); assert(bone_info.valid); - igBeginChild_Str("slot_info", IMVEC2(0,0), false, 0); + igBeginChild("slot_info", IMVEC2(0,0), false, 0); igText("Index: %d", slot_info.index); igText("Name: %s", slot_info.name.cstr); igText("Attachment: %s", slot_info.attachment_name.valid ? slot_info.attachment_name.cstr : "-"); @@ -671,31 +670,31 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.anims_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Anims", &state.ui.anims_open, 0)) { if (!sspine_instance_valid(state.instance)) { igText("No Spine data loaded."); } else { const int num_anims = sspine_num_anims(state.skeleton); igText("Num Anims: %d", num_anims); - igBeginChild_Str("anim_list", IMVEC2(128, 0), true, 0); + igBeginChild("anim_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_anims; i++) { const sspine_anim anim = sspine_anim_by_index(state.skeleton, i); const sspine_anim_info info = sspine_get_anim_info(anim); assert(info.valid); - igPushID_Int(anim.index); - if (igSelectable_Bool(info.name.cstr, sspine_anim_equal(state.ui.selected.anim, anim), 0, IMVEC2(0,0))) { + igPushIDInt(anim.index); + if (igSelectableEx(info.name.cstr, sspine_anim_equal(state.ui.selected.anim, anim), 0, IMVEC2(0,0))) { state.ui.selected.anim = anim; sspine_set_animation(state.instance, anim, 0, true); } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_anim_valid(state.ui.selected.anim)) { const sspine_anim_info info = sspine_get_anim_info(state.ui.selected.anim); assert(info.valid); - igBeginChild_Str("anim_info", IMVEC2(0,0), false, 0); + igBeginChild("anim_info", IMVEC2(0,0), false, 0); igText("Index: %d", info.index); igText("Name: %s", info.name.cstr); igText("Duration: %.3f", info.duration); @@ -708,30 +707,30 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.events_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Events", &state.ui.events_open, 0)) { if (!sspine_skeleton_valid(state.skeleton)) { igText("No Spine data loaded"); } else { const int num_events = sspine_num_events(state.skeleton); igText("Num Events: %d", num_events); - igBeginChild_Str("event_list", IMVEC2(128, 0), true, 0); + igBeginChild("event_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_events; i++) { const sspine_event event = sspine_event_by_index(state.skeleton, i); const sspine_event_info info = sspine_get_event_info(event); assert(info.valid); - igPushID_Int(event.index); - if (igSelectable_Bool(info.name.cstr, sspine_event_equal(state.ui.selected.event, event), 0, IMVEC2(0,0))) { + igPushIDInt(event.index); + if (igSelectableEx(info.name.cstr, sspine_event_equal(state.ui.selected.event, event), 0, IMVEC2(0,0))) { state.ui.selected.event = event; } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_event_valid(state.ui.selected.event)) { const sspine_event_info info = sspine_get_event_info(state.ui.selected.event); assert(info.valid); - igBeginChild_Str("event_info", IMVEC2(0,0), false, 0); + igBeginChild("event_info", IMVEC2(0,0), false, 0); igText("Index: %d", info.index); igText("Name: %s", info.name.cstr); igText("Int Value: %d\n", info.int_value); @@ -749,31 +748,31 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.skins_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("Skins", &state.ui.skins_open, 0)) { if (!sspine_skeleton_valid(state.skeleton)) { igText("No Spine data loaded"); } else { const int num_skins = sspine_num_skins(state.skeleton); igText("Num Skins: %d", num_skins); - igBeginChild_Str("skin_list", IMVEC2(128, 0), true, 0); + igBeginChild("skin_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_skins; i++) { const sspine_skin skin = sspine_skin_by_index(state.skeleton, i); const sspine_skin_info info = sspine_get_skin_info(skin); assert(info.valid); - igPushID_Int(skin.index); - if (igSelectable_Bool(info.name.cstr, sspine_skin_equal(state.ui.selected.skin, skin), 0, IMVEC2(0,0))) { + igPushIDInt(skin.index); + if (igSelectableEx(info.name.cstr, sspine_skin_equal(state.ui.selected.skin, skin), 0, IMVEC2(0,0))) { state.ui.selected.skin = skin; sspine_set_skin(state.instance, skin); } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_skin_valid(state.ui.selected.skin)) { const sspine_skin_info info = sspine_get_skin_info(state.ui.selected.skin); assert(info.valid); - igBeginChild_Str("skin_info", IMVEC2(0,0), false, 0); + igBeginChild("skin_info", IMVEC2(0,0), false, 0); igText("Index: %d", info.index); igText("Name: %s", info.name.cstr); igEndChild(); @@ -785,30 +784,30 @@ static void ui_draw(void) { pos.x += 20; pos.y += 20; if (state.ui.iktargets_open) { igSetNextWindowSize(IMVEC2(300, 300), ImGuiCond_Once); - igSetNextWindowPos(pos, ImGuiCond_Once, IMVEC2(0,0)); + igSetNextWindowPos(pos, ImGuiCond_Once); if (igBegin("IK Targets", &state.ui.iktargets_open, 0)) { if (!sspine_skeleton_valid(state.skeleton)) { igText("No Spine data loaded"); } else { const int num_iktargets = sspine_num_iktargets(state.skeleton); igText("Num IK Targets: %d", num_iktargets); - igBeginChild_Str("iktarget_list", IMVEC2(128, 0), true, 0); + igBeginChild("iktarget_list", IMVEC2(128, 0), true, 0); for (int i = 0; i < num_iktargets; i++) { const sspine_iktarget iktarget = sspine_iktarget_by_index(state.skeleton, i); const sspine_iktarget_info info = sspine_get_iktarget_info(iktarget); assert(info.valid); - igPushID_Int(iktarget.index); - if (igSelectable_Bool(info.name.cstr, sspine_iktarget_equal(state.ui.selected.iktarget, iktarget), 0, IMVEC2(0,0))) { + igPushIDInt(iktarget.index); + if (igSelectableEx(info.name.cstr, sspine_iktarget_equal(state.ui.selected.iktarget, iktarget), 0, IMVEC2(0,0))) { state.ui.selected.iktarget = iktarget; } igPopID(); } igEndChild(); - igSameLine(0, -1); + igSameLine(); if (sspine_iktarget_valid(state.ui.selected.iktarget)) { const sspine_iktarget_info info = sspine_get_iktarget_info(state.ui.selected.iktarget); assert(info.valid); - igBeginChild_Str("iktarget_info", IMVEC2(0,0), false, 0); + igBeginChild("iktarget_info", IMVEC2(0,0), false, 0); igText("Index: %d", info.index); igText("Name: %s", info.name.cstr); igText("Target Bone: %s", sspine_get_bone_info(info.target_bone).name.cstr); @@ -827,13 +826,13 @@ static void ui_draw(void) { if (event_info.valid) { const float alpha = (float) (1.0 - ((state.ui.cur_time - event_time) / triggered_event_fade_time)); igSetNextWindowBgAlpha(alpha); - igSetNextWindowPos(IMVEC2(sapp_widthf() * 0.5f, sapp_heightf() - 50.0f), ImGuiCond_Always, IMVEC2(0.5f,0.5f)); - igPushStyleColor_U32(ImGuiCol_WindowBg, 0xFF0000FF); + igSetNextWindowPosEx(IMVEC2(sapp_widthf() * 0.5f, sapp_heightf() - 50.0f), ImGuiCond_Always, IMVEC2(0.5f,0.5f)); + igPushStyleColor(ImGuiCol_WindowBg, 0xFF0000FF); if (igBegin("Triggered Events", 0, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_NoFocusOnAppearing|ImGuiWindowFlags_NoNav)) { igText("%s: %.3f (age: %.3f)", event_info.name.cstr, event_time, state.ui.cur_time - event_time); } igEnd(); - igPopStyleColor(1); + igPopStyleColor(); } } sgimgui_draw(&state.ui.sgimgui); From af4d923b9cce1eab38bb3fcaba705b54496c5f69 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 5 Dec 2024 19:21:25 +0100 Subject: [PATCH 3/6] fix imgui-glfw for ImGui 1.91.5 --- glfw/imgui-glfw.cc | 156 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 130 insertions(+), 26 deletions(-) diff --git a/glfw/imgui-glfw.cc b/glfw/imgui-glfw.cc index 2d7d724a..f5340f58 100644 --- a/glfw/imgui-glfw.cc +++ b/glfw/imgui-glfw.cc @@ -29,6 +29,7 @@ typedef struct { } vs_params_t; static void draw_imgui(ImDrawData*); +static ImGuiKey glfw_key_to_imgui_key(int glfw_key); int main() { @@ -42,22 +43,19 @@ int main() { // GLFW to ImGui input forwarding glfwSetMouseButtonCallback(w, [](GLFWwindow*, int btn, int action, int /*mods*/) { - if ((btn >= 0) && (btn < 3)) { - ImGui::GetIO().MouseDown[btn] = (action == GLFW_PRESS); + if ((btn >= 0) && (btn < ImGuiMouseButton_COUNT)) { + ImGui::GetIO().AddMouseButtonEvent(btn, action == GLFW_PRESS); } }); glfwSetCursorPosCallback(w, [](GLFWwindow*, double pos_x, double pos_y) { - ImGui::GetIO().MousePos.x = float(pos_x); - ImGui::GetIO().MousePos.y = float(pos_y); + ImGui::GetIO().AddMousePosEvent((float)pos_x, (float)pos_y); }); - glfwSetScrollCallback(w, [](GLFWwindow*, double /*pos_x*/, double pos_y){ - ImGui::GetIO().MouseWheel = float(pos_y); + glfwSetScrollCallback(w, [](GLFWwindow*, double wheel_x, double wheel_y){ + ImGui::GetIO().AddMouseWheelEvent((float)wheel_x, (float)wheel_y); }); glfwSetKeyCallback(w, [](GLFWwindow*, int key, int /*scancode*/, int action, int mods){ ImGuiIO& io = ImGui::GetIO(); - if ((key >= 0) && (key < 512)) { - io.KeysDown[key] = (action==GLFW_PRESS)||(action==GLFW_REPEAT); - } + io.AddKeyEvent(glfw_key_to_imgui_key(key), (action == GLFW_PRESS)); io.KeyCtrl = (0 != (mods & GLFW_MOD_CONTROL)); io.KeyAlt = (0 != (mods & GLFW_MOD_ALT)); io.KeyShift = (0 != (mods & GLFW_MOD_SHIFT)); @@ -80,23 +78,6 @@ int main() { ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; io.Fonts->AddFontDefault(); - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; - io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; - io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; - io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; - io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; - io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; - io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; - io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; - io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; - io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; - io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; - io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; - io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; - io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; // dynamic vertex- and index-buffers for imgui-generated geometry sg_buffer_desc vbuf_desc = { }; @@ -287,3 +268,126 @@ void draw_imgui(ImDrawData* draw_data) { } } } + +static ImGuiKey glfw_key_to_imgui_key(int glfw_key) { + switch (glfw_key) { + case GLFW_KEY_TAB: return ImGuiKey_Tab; + case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow; + case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow; + case GLFW_KEY_UP: return ImGuiKey_UpArrow; + case GLFW_KEY_DOWN: return ImGuiKey_DownArrow; + case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp; + case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown; + case GLFW_KEY_HOME: return ImGuiKey_Home; + case GLFW_KEY_END: return ImGuiKey_End; + case GLFW_KEY_INSERT: return ImGuiKey_Insert; + case GLFW_KEY_DELETE: return ImGuiKey_Delete; + case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace; + case GLFW_KEY_SPACE: return ImGuiKey_Space; + case GLFW_KEY_ENTER: return ImGuiKey_Enter; + case GLFW_KEY_ESCAPE: return ImGuiKey_Escape; + case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe; + case GLFW_KEY_COMMA: return ImGuiKey_Comma; + case GLFW_KEY_MINUS: return ImGuiKey_Minus; + case GLFW_KEY_PERIOD: return ImGuiKey_Period; + case GLFW_KEY_SLASH: return ImGuiKey_Slash; + case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon; + case GLFW_KEY_EQUAL: return ImGuiKey_Equal; + case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket; + case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash; + case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket; + case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent; + case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock; + case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock; + case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock; + case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen; + case GLFW_KEY_PAUSE: return ImGuiKey_Pause; + case GLFW_KEY_KP_0: return ImGuiKey_Keypad0; + case GLFW_KEY_KP_1: return ImGuiKey_Keypad1; + case GLFW_KEY_KP_2: return ImGuiKey_Keypad2; + case GLFW_KEY_KP_3: return ImGuiKey_Keypad3; + case GLFW_KEY_KP_4: return ImGuiKey_Keypad4; + case GLFW_KEY_KP_5: return ImGuiKey_Keypad5; + case GLFW_KEY_KP_6: return ImGuiKey_Keypad6; + case GLFW_KEY_KP_7: return ImGuiKey_Keypad7; + case GLFW_KEY_KP_8: return ImGuiKey_Keypad8; + case GLFW_KEY_KP_9: return ImGuiKey_Keypad9; + case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal; + case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide; + case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply; + case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract; + case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd; + case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter; + case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual; + case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift; + case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl; + case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt; + case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper; + case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift; + case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl; + case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt; + case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper; + case GLFW_KEY_MENU: return ImGuiKey_Menu; + case GLFW_KEY_0: return ImGuiKey_0; + case GLFW_KEY_1: return ImGuiKey_1; + case GLFW_KEY_2: return ImGuiKey_2; + case GLFW_KEY_3: return ImGuiKey_3; + case GLFW_KEY_4: return ImGuiKey_4; + case GLFW_KEY_5: return ImGuiKey_5; + case GLFW_KEY_6: return ImGuiKey_6; + case GLFW_KEY_7: return ImGuiKey_7; + case GLFW_KEY_8: return ImGuiKey_8; + case GLFW_KEY_9: return ImGuiKey_9; + case GLFW_KEY_A: return ImGuiKey_A; + case GLFW_KEY_B: return ImGuiKey_B; + case GLFW_KEY_C: return ImGuiKey_C; + case GLFW_KEY_D: return ImGuiKey_D; + case GLFW_KEY_E: return ImGuiKey_E; + case GLFW_KEY_F: return ImGuiKey_F; + case GLFW_KEY_G: return ImGuiKey_G; + case GLFW_KEY_H: return ImGuiKey_H; + case GLFW_KEY_I: return ImGuiKey_I; + case GLFW_KEY_J: return ImGuiKey_J; + case GLFW_KEY_K: return ImGuiKey_K; + case GLFW_KEY_L: return ImGuiKey_L; + case GLFW_KEY_M: return ImGuiKey_M; + case GLFW_KEY_N: return ImGuiKey_N; + case GLFW_KEY_O: return ImGuiKey_O; + case GLFW_KEY_P: return ImGuiKey_P; + case GLFW_KEY_Q: return ImGuiKey_Q; + case GLFW_KEY_R: return ImGuiKey_R; + case GLFW_KEY_S: return ImGuiKey_S; + case GLFW_KEY_T: return ImGuiKey_T; + case GLFW_KEY_U: return ImGuiKey_U; + case GLFW_KEY_V: return ImGuiKey_V; + case GLFW_KEY_W: return ImGuiKey_W; + case GLFW_KEY_X: return ImGuiKey_X; + case GLFW_KEY_Y: return ImGuiKey_Y; + case GLFW_KEY_Z: return ImGuiKey_Z; + case GLFW_KEY_F1: return ImGuiKey_F1; + case GLFW_KEY_F2: return ImGuiKey_F2; + case GLFW_KEY_F3: return ImGuiKey_F3; + case GLFW_KEY_F4: return ImGuiKey_F4; + case GLFW_KEY_F5: return ImGuiKey_F5; + case GLFW_KEY_F6: return ImGuiKey_F6; + case GLFW_KEY_F7: return ImGuiKey_F7; + case GLFW_KEY_F8: return ImGuiKey_F8; + case GLFW_KEY_F9: return ImGuiKey_F9; + case GLFW_KEY_F10: return ImGuiKey_F10; + case GLFW_KEY_F11: return ImGuiKey_F11; + case GLFW_KEY_F12: return ImGuiKey_F12; + case GLFW_KEY_F13: return ImGuiKey_F13; + case GLFW_KEY_F14: return ImGuiKey_F14; + case GLFW_KEY_F15: return ImGuiKey_F15; + case GLFW_KEY_F16: return ImGuiKey_F16; + case GLFW_KEY_F17: return ImGuiKey_F17; + case GLFW_KEY_F18: return ImGuiKey_F18; + case GLFW_KEY_F19: return ImGuiKey_F19; + case GLFW_KEY_F20: return ImGuiKey_F20; + case GLFW_KEY_F21: return ImGuiKey_F21; + case GLFW_KEY_F22: return ImGuiKey_F22; + case GLFW_KEY_F23: return ImGuiKey_F23; + case GLFW_KEY_F24: return ImGuiKey_F24; + default: return ImGuiKey_None; + } +} From 25c3f60cce0449a0950206e1c4ad5d8b48cfb937 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 5 Dec 2024 19:59:48 +0100 Subject: [PATCH 4/6] fix metal, wgpu and html5 raw samples for Dear ImGui 1.91.5 --- html5/imgui-emsc.cc | 93 +++++++++++----------------------------- metal/imgui-metal.cc | 51 +++++++++++----------- wgpu/CMakeLists.txt | 2 +- wgpu/drawcallperf-wgpu.c | 9 ++-- wgpu/imgui-wgpu.cc | 47 ++++++++++---------- 5 files changed, 78 insertions(+), 124 deletions(-) diff --git a/html5/imgui-emsc.cc b/html5/imgui-emsc.cc index 344a5848..14213ecd 100644 --- a/html5/imgui-emsc.cc +++ b/html5/imgui-emsc.cc @@ -28,8 +28,6 @@ static bool show_another_window = false; static sg_pass_action pass_action; static sg_pipeline pip; static sg_bindings bind; -static bool btn_down[3]; -static bool btn_up[3]; typedef struct { ImVec2 disp_size; @@ -37,6 +35,7 @@ typedef struct { static EM_BOOL draw(double time, void* userdata); static void draw_imgui(ImDrawData*); +static ImGuiKey as_imgui_key(int keycode); int main() { // setup WebGL context @@ -58,38 +57,18 @@ int main() { ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; io.Fonts->AddFontDefault(); - // emscripten has no clearly defined key code constants - io.KeyMap[ImGuiKey_Tab] = 9; - io.KeyMap[ImGuiKey_LeftArrow] = 37; - io.KeyMap[ImGuiKey_RightArrow] = 39; - io.KeyMap[ImGuiKey_UpArrow] = 38; - io.KeyMap[ImGuiKey_DownArrow] = 40; - io.KeyMap[ImGuiKey_Home] = 36; - io.KeyMap[ImGuiKey_End] = 35; - io.KeyMap[ImGuiKey_Delete] = 46; - io.KeyMap[ImGuiKey_Backspace] = 8; - io.KeyMap[ImGuiKey_Enter] = 13; - io.KeyMap[ImGuiKey_Escape] = 27; - io.KeyMap[ImGuiKey_A] = 65; - io.KeyMap[ImGuiKey_C] = 67; - io.KeyMap[ImGuiKey_V] = 86; - io.KeyMap[ImGuiKey_X] = 88; - io.KeyMap[ImGuiKey_Y] = 89; - io.KeyMap[ImGuiKey_Z] = 90; // emscripten to ImGui input forwarding emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, true, [](int, const EmscriptenKeyboardEvent* e, void*)->EM_BOOL { - if (e->keyCode < 512) { - ImGui::GetIO().KeysDown[e->keyCode] = true; - } + ImGui::GetIO().AddKeyEvent(as_imgui_key(e->keyCode), true); // only forward alpha-numeric keys to browser return e->keyCode < 32; }); emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, true, [](int, const EmscriptenKeyboardEvent* e, void*)->EM_BOOL { if (e->keyCode < 512) { - ImGui::GetIO().KeysDown[e->keyCode] = false; + ImGui::GetIO().AddKeyEvent(as_imgui_key(e->keyCode), false); } // only forward alpha-numeric keys to browser return e->keyCode < 32; @@ -101,48 +80,22 @@ int main() { }); emscripten_set_mousedown_callback("canvas", nullptr, true, [](int, const EmscriptenMouseEvent* e, void*)->EM_BOOL { - switch (e->button) { - case 0: btn_down[0] = true; break; - case 2: btn_down[1] = true; break; - } + ImGui::GetIO().AddMouseButtonEvent(e->button, true); return true; }); emscripten_set_mouseup_callback("canvas", nullptr, true, [](int, const EmscriptenMouseEvent* e, void*)->EM_BOOL { - switch (e->button) { - case 0: btn_up[0] = true; break; - case 2: btn_up[1] = true; break; - } - return true; - }); - emscripten_set_mouseenter_callback("canvas", nullptr, true, - [](int, const EmscriptenMouseEvent*, void*)->EM_BOOL { - auto& io = ImGui::GetIO(); - for (int i = 0; i < 3; i++) { - btn_down[i] = btn_up[i] = false; - io.MouseDown[i] = false; - } - return true; - }); - emscripten_set_mouseleave_callback("canvas", nullptr, true, - [](int, const EmscriptenMouseEvent*, void*)->EM_BOOL { - auto& io = ImGui::GetIO(); - for (int i = 0; i < 3; i++) { - btn_down[i] = btn_up[i] = false; - io.MouseDown[i] = false; - } + ImGui::GetIO().AddMouseButtonEvent(e->button, false); return true; }); emscripten_set_mousemove_callback("canvas", nullptr, true, [](int, const EmscriptenMouseEvent* e, void*)->EM_BOOL { - ImGui::GetIO().MousePos.x = (float) e->targetX; - ImGui::GetIO().MousePos.y = (float) e->targetY; + ImGui::GetIO().AddMousePosEvent((float)e->targetX, (float)e->targetY); return true; }); emscripten_set_wheel_callback("canvas", nullptr, true, [](int, const EmscriptenWheelEvent* e, void*)->EM_BOOL { - ImGui::GetIO().MouseWheelH = -0.1f * (float)e->deltaX; - ImGui::GetIO().MouseWheel = -0.1f * (float)e->deltaY; + ImGui::GetIO().AddMouseWheelEvent(-0.1f * (float)e->deltaX, -0.1f * (float)e->deltaY); return true; }); @@ -254,21 +207,6 @@ static EM_BOOL draw(double time, void* userdata) { ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2(float(emsc_width()), float(emsc_height())); io.DeltaTime = (float) stm_sec(stm_laptime(&last_time)); - // this mouse button handling fixes the problem when down- and up-events happen in the same frame - for (int i = 0; i < 3; i++) { - if (io.MouseDown[i]) { - if (btn_up[i]) { - io.MouseDown[i] = false; - btn_up[i] = false; - } - } - else { - if (btn_down[i]) { - io.MouseDown[i] = true; - btn_down[i] = false; - } - } - } ImGui::NewFrame(); // 1. Show a simple window @@ -356,3 +294,20 @@ void draw_imgui(ImDrawData* draw_data) { } } } + +ImGuiKey as_imgui_key(int keycode) { + switch (keycode) { + case 9: return ImGuiKey_Tab; + case 37: return ImGuiKey_LeftArrow; + case 39: return ImGuiKey_RightArrow; + case 38: return ImGuiKey_UpArrow; + case 40: return ImGuiKey_DownArrow; + case 36: return ImGuiKey_Home; + case 35: return ImGuiKey_End; + case 46: return ImGuiKey_Delete; + case 8: return ImGuiKey_Backspace; + case 13: return ImGuiKey_Enter; + case 27: return ImGuiKey_Escape; + default: return ImGuiKey_None; + }; +} diff --git a/metal/imgui-metal.cc b/metal/imgui-metal.cc index b352a46b..0ae08e78 100644 --- a/metal/imgui-metal.cc +++ b/metal/imgui-metal.cc @@ -25,6 +25,8 @@ static bool show_test_window = true; static bool show_another_window = false; static sg_pass_action pass_action; +static ImGuiKey as_imgui_key(int keycode); + void init() { // setup sokol_gfx and sokol_time const sg_desc desc = { @@ -40,33 +42,13 @@ void init() { }; simgui_setup(&simgui_desc); - // setup the imgui environment - ImGuiIO& io = ImGui::GetIO(); - io.KeyMap[ImGuiKey_Tab] = 0x30; - io.KeyMap[ImGuiKey_LeftArrow] = 0x7B; - io.KeyMap[ImGuiKey_RightArrow] = 0x7C; - io.KeyMap[ImGuiKey_DownArrow] = 0x7D; - io.KeyMap[ImGuiKey_UpArrow] = 0x7E; - io.KeyMap[ImGuiKey_Home] = 0x73; - io.KeyMap[ImGuiKey_End] = 0x77; - io.KeyMap[ImGuiKey_Delete] = 0x75; - io.KeyMap[ImGuiKey_Backspace] = 0x33; - io.KeyMap[ImGuiKey_Enter] = 0x24; - io.KeyMap[ImGuiKey_Escape] = 0x35; - io.KeyMap[ImGuiKey_A] = 0x00; - io.KeyMap[ImGuiKey_C] = 0x08; - io.KeyMap[ImGuiKey_V] = 0x09; - io.KeyMap[ImGuiKey_X] = 0x07; - io.KeyMap[ImGuiKey_Y] = 0x10; - io.KeyMap[ImGuiKey_Z] = 0x06; - // OSX => ImGui input forwarding - osx_mouse_pos([] (float x, float y) { ImGui::GetIO().MousePos = ImVec2(x, y); }); - osx_mouse_btn_down([] (int btn) { ImGui::GetIO().MouseDown[btn] = true; }); - osx_mouse_btn_up([] (int btn) { ImGui::GetIO().MouseDown[btn] = false; }); - osx_mouse_wheel([] (float v) { ImGui::GetIO().MouseWheel = 0.25f * v; }); - osx_key_down([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = true; }); - osx_key_up([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = false; }); + osx_mouse_pos([] (float x, float y) { ImGui::GetIO().AddMousePosEvent(x, y); }); + osx_mouse_btn_down([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, true); }); + osx_mouse_btn_up([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, false); }); + osx_mouse_wheel([] (float v) { ImGui::GetIO().AddMouseWheelEvent(0.0f, 0.25f * v); }); + osx_key_down([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), true); }); + osx_key_up([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), false); }); osx_char([] (wchar_t c) { ImGui::GetIO().AddInputCharacter(c); }); // initial clear color @@ -120,3 +102,20 @@ int main() { osx_start(WIDTH, HEIGHT, 1, SG_PIXELFORMAT_NONE, "Sokol Dear ImGui (Metal)", init, frame, shutdown); return 0; } + +static ImGuiKey as_imgui_key(int keycode) { + switch (keycode) { + case 0x30: return ImGuiKey_Tab; + case 0x7B: return ImGuiKey_LeftArrow; + case 0x7C: return ImGuiKey_RightArrow; + case 0x7D: return ImGuiKey_DownArrow; + case 0x7E: return ImGuiKey_UpArrow; + case 0x73: return ImGuiKey_Home; + case 0x77: return ImGuiKey_End; + case 0x75: return ImGuiKey_Delete; + case 0x33: return ImGuiKey_Backspace; + case 0x24: return ImGuiKey_Enter; + case 0x35: return ImGuiKey_Escape; + default: return ImGuiKey_None; + } +} diff --git a/wgpu/CMakeLists.txt b/wgpu/CMakeLists.txt index adf76225..9edc174e 100644 --- a/wgpu/CMakeLists.txt +++ b/wgpu/CMakeLists.txt @@ -95,7 +95,7 @@ fips_end_app() fips_begin_app(drawcallperf-wgpu windowed) fips_files(drawcallperf-wgpu.c) - fips_deps(wgpu_entry cimgui) + fips_deps(wgpu_entry imgui) fips_end_app() fips_begin_app(vertexpulling-wgpu windowed) diff --git a/wgpu/drawcallperf-wgpu.c b/wgpu/drawcallperf-wgpu.c index 2f61ee62..19d6dd1a 100644 --- a/wgpu/drawcallperf-wgpu.c +++ b/wgpu/drawcallperf-wgpu.c @@ -10,8 +10,7 @@ #include "sokol_gfx.h" #include "sokol_log.h" #include "sokol_time.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include "cimgui/cimgui.h" +#include "cimgui.h" #define SOKOL_IMGUI_IMPL #define SOKOL_IMGUI_NO_SOKOL_APP #include "sokol_imgui.h" @@ -278,13 +277,13 @@ static void frame(void) { }); // control ui - igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once, (ImVec2){0,0}); + igSetNextWindowPos((ImVec2){20,20}, ImGuiCond_Once); igSetNextWindowSize((ImVec2){600,200}, ImGuiCond_Once); if (igBegin("Controls", 0, ImGuiWindowFlags_NoResize)) { igText("Each cube/instance is 1 16-byte uniform update and 1 draw call\n"); igText("DC/texture is the number of adjacent draw calls with the same texture binding\n"); - igSliderInt("Num Instances", &state.num_instances, 100, MAX_INSTANCES, "%d", ImGuiSliderFlags_Logarithmic); - igSliderInt("DC/texture", &state.bind_frequency, 1, MAX_BIND_FREQUENCY, "%d", ImGuiSliderFlags_Logarithmic); + igSliderIntEx("Num Instances", &state.num_instances, 100, MAX_INSTANCES, "%d", ImGuiSliderFlags_Logarithmic); + igSliderIntEx("DC/texture", &state.bind_frequency, 1, MAX_BIND_FREQUENCY, "%d", ImGuiSliderFlags_Logarithmic); igText("Frame duration: %.4fms", frame_measured_time * 1000.0); igText("sg_apply_bindings(): %d\n", state.stats.num_binding_updates); igText("sg_apply_uniforms(): %d\n", state.stats.num_uniform_updates); diff --git a/wgpu/imgui-wgpu.cc b/wgpu/imgui-wgpu.cc index 9b4c6f0b..31435024 100644 --- a/wgpu/imgui-wgpu.cc +++ b/wgpu/imgui-wgpu.cc @@ -30,6 +30,7 @@ typedef struct { } vs_params_t; static void draw_imgui(ImDrawData*); +static ImGuiKey as_imgui_key(uint32_t keycode); static void init(void) { // setup sokol-gfx, sokol-time and sokol-imgui @@ -40,13 +41,13 @@ static void init(void) { stm_setup(); // input forwarding - wgpu_mouse_pos([] (float x, float y) { ImGui::GetIO().MousePos = ImVec2(x, y); }); - wgpu_mouse_btn_down([] (int btn) { ImGui::GetIO().MouseDown[btn] = true; }); - wgpu_mouse_btn_up([] (int btn) { ImGui::GetIO().MouseDown[btn] = false; }); - wgpu_mouse_wheel([](float v) { ImGui::GetIO().MouseWheel = v; }); + wgpu_mouse_pos([] (float x, float y) { ImGui::GetIO().AddMousePosEvent(x, y); }); + wgpu_mouse_btn_down([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, true); }); + wgpu_mouse_btn_up([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, false); }); + wgpu_mouse_wheel([](float v) { ImGui::GetIO().AddMouseWheelEvent(0, v); }); wgpu_char([] (uint32_t c) { ImGui::GetIO().AddInputCharacter(c); }); - wgpu_key_down([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = true; }); - wgpu_key_up([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = false; }); + wgpu_key_down([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), true); }); + wgpu_key_up([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), false); }); // setup Dear Imgui ImGui::CreateContext(); @@ -54,23 +55,6 @@ static void init(void) { ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; io.Fonts->AddFontDefault(); - io.KeyMap[ImGuiKey_Tab] = WGPU_KEY_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = WGPU_KEY_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = WGPU_KEY_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = WGPU_KEY_UP; - io.KeyMap[ImGuiKey_DownArrow] = WGPU_KEY_DOWN; - io.KeyMap[ImGuiKey_Home] = WGPU_KEY_HOME; - io.KeyMap[ImGuiKey_End] = WGPU_KEY_END; - io.KeyMap[ImGuiKey_Delete] = WGPU_KEY_DELETE; - io.KeyMap[ImGuiKey_Backspace] = WGPU_KEY_BACKSPACE; - io.KeyMap[ImGuiKey_Enter] = WGPU_KEY_ENTER; - io.KeyMap[ImGuiKey_Escape] = WGPU_KEY_ESCAPE; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; // dynamic vertex- and index-buffers for imgui-generated geometry sg_buffer_desc vbuf_desc = { }; @@ -260,6 +244,23 @@ void draw_imgui(ImDrawData* draw_data) { } } +static ImGuiKey as_imgui_key(uint32_t keycode) { + switch (keycode) { + case WGPU_KEY_TAB: return ImGuiKey_Tab; + case WGPU_KEY_LEFT: return ImGuiKey_LeftArrow; + case WGPU_KEY_RIGHT: return ImGuiKey_RightArrow; + case WGPU_KEY_UP: return ImGuiKey_UpArrow; + case WGPU_KEY_DOWN: return ImGuiKey_DownArrow; + case WGPU_KEY_HOME: return ImGuiKey_Home; + case WGPU_KEY_END: return ImGuiKey_End; + case WGPU_KEY_DELETE: return ImGuiKey_Delete; + case WGPU_KEY_BACKSPACE: return ImGuiKey_Backspace; + case WGPU_KEY_ENTER: return ImGuiKey_Enter; + case WGPU_KEY_ESCAPE: return ImGuiKey_Escape; + default: return ImGuiKey_None; + } +} + int main() { wgpu_desc_t desc = { }; desc.init_cb = init; From 21c1814385003f3c2b5768b91e8da6f2c204a66d Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Fri, 6 Dec 2024 18:41:56 +0100 Subject: [PATCH 5/6] fix d3d11 raw samples for Dear ImGui 1.91.5 --- d3d11/imgui-d3d11.cc | 47 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/d3d11/imgui-d3d11.cc b/d3d11/imgui-d3d11.cc index 27e82188..854718bb 100644 --- a/d3d11/imgui-d3d11.cc +++ b/d3d11/imgui-d3d11.cc @@ -28,6 +28,7 @@ typedef struct { } vs_params_t; static void draw_imgui(ImDrawData*); +static ImGuiKey as_imgui_key(int keycode); int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow; @@ -44,13 +45,13 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ stm_setup(); // input forwarding - d3d11_mouse_pos([] (float x, float y) { ImGui::GetIO().MousePos = ImVec2(x, y); }); - d3d11_mouse_btn_down([] (int btn) { ImGui::GetIO().MouseDown[btn] = true; }); - d3d11_mouse_btn_up([] (int btn) { ImGui::GetIO().MouseDown[btn] = false; }); - d3d11_mouse_wheel([](float v) { ImGui::GetIO().MouseWheel = v; }); + d3d11_mouse_pos([] (float x, float y) { ImGui::GetIO().AddMousePosEvent(x, y); }); + d3d11_mouse_btn_down([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, true); }); + d3d11_mouse_btn_up([] (int btn) { ImGui::GetIO().AddMouseButtonEvent(btn, false); }); + d3d11_mouse_wheel([](float v) { ImGui::GetIO().AddMouseWheelEvent(0, v); }); d3d11_char([] (wchar_t c) { ImGui::GetIO().AddInputCharacter(c); }); - d3d11_key_down([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = true; }); - d3d11_key_up([] (int key) { if (key < 512) ImGui::GetIO().KeysDown[key] = false; }); + d3d11_key_down([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), true); }); + d3d11_key_up([] (int key) { ImGui::GetIO().AddKeyEvent(as_imgui_key(key), false); }); // setup Dear Imgui ImGui::CreateContext(); @@ -58,23 +59,6 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; io.Fonts->AddFontDefault(); - io.KeyMap[ImGuiKey_Tab] = VK_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = VK_UP; - io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; - io.KeyMap[ImGuiKey_Home] = VK_HOME; - io.KeyMap[ImGuiKey_End] = VK_END; - io.KeyMap[ImGuiKey_Delete] = VK_DELETE; - io.KeyMap[ImGuiKey_Backspace] = VK_BACK; - io.KeyMap[ImGuiKey_Enter] = VK_RETURN; - io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; // dynamic vertex- and index-buffers for imgui-generated geometry sg_buffer_desc vbuf_desc = { }; @@ -269,3 +253,20 @@ void draw_imgui(ImDrawData* draw_data) { } } } + +static ImGuiKey as_imgui_key(int keycode) { + switch (keycode) { + case VK_TAB: return ImGuiKey_Tab; + case VK_LEFT: return ImGuiKey_LeftArrow; + case VK_RIGHT: return ImGuiKey_RightArrow; + case VK_UP: return ImGuiKey_UpArrow; + case VK_DOWN: return ImGuiKey_DownArrow; + case VK_HOME: return ImGuiKey_Home; + case VK_END: return ImGuiKey_End; + case VK_DELETE: return ImGuiKey_Delete; + case VK_BACK: return ImGuiKey_Backspace; + case VK_RETURN: return ImGuiKey_Enter; + case VK_ESCAPE: return ImGuiKey_Escape; + default: return ImGuiKey_None; + } +} \ No newline at end of file From 955bdfd6d9d9e5f1dd761a0d9ddace880b536041 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Fri, 6 Dec 2024 19:40:51 +0100 Subject: [PATCH 6/6] replace fips-imgui-dock with dcimgui --- CMakeLists.txt | 1 - fips.yml | 2 -- sapp/CMakeLists.txt | 2 +- sapp/imgui-dock-sapp.cc | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 052cf0db..d75ba4ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ if (NOT USE_SOKOL_APP AND NOT SOKOL_USE_WGPU_DAWN AND NOT SOKOL_USE_D3D11 AND NO fips_import_fips_glfw_glfw3() endif() fips_import_dcimgui_dcimgui() -fips_import_fips_imgui_dock_imgui_dock() if (NOT FIPS_UWP) fips_import_fips_libmodplug_libmodplug() endif() diff --git a/fips.yml b/fips.yml index aff76b74..84ebf560 100644 --- a/fips.yml +++ b/fips.yml @@ -11,8 +11,6 @@ imports: git: https://github.com/floooh/sokol-tools-bin fips-glfw: git: https://github.com/fips-libs/fips-glfw - fips-imgui-dock: - git: https://github.com/fips-libs/fips-imgui-dock.git fips-libmodplug: git: https://github.com/fips-libs/fips-libmodplug fips-utils: diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 280d2246..2d3a09be 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -425,7 +425,7 @@ fips_ide_group(Samples) fips_begin_app(imgui-dock-sapp windowed) fips_files(imgui-dock-sapp.cc) # use sokol-cpp for testing here, this isn't required though - fips_deps(sokol-cpp imgui-dock) + fips_deps(sokol-cpp imgui-docking) if (FIPS_IOS) fips_files(ios-info.plist) endif() diff --git a/sapp/imgui-dock-sapp.cc b/sapp/imgui-dock-sapp.cc index 1af9d6b1..2e4e2c04 100644 --- a/sapp/imgui-dock-sapp.cc +++ b/sapp/imgui-dock-sapp.cc @@ -7,7 +7,7 @@ #include "sokol_gfx.h" #include "sokol_log.h" #include "sokol_glue.h" -#include "imgui-dock/imgui.h" +#include "imgui.h" #define SOKOL_IMGUI_IMPL #include "sokol_imgui.h"