From 62c5dcf6eaf3f8bd41a16fb9433896be2f0431c8 Mon Sep 17 00:00:00 2001 From: shweet Date: Fri, 19 Sep 2025 22:19:48 -0400 Subject: [PATCH] fix git modules --- .clang-format | 4 +++ .gitmodules | 8 +++--- .vscode/settings.json | 5 ++++ CMakeLists.txt | 20 ++++++++------- include/glm | 1 - include/imgui | 1 - include/tinyxml2 | 1 - src/COMMON.h | 8 +++--- src/imgui.cpp | 60 ++++++++++++++++++++++++++++--------------- src/imgui.h | 5 +++- 10 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 .clang-format create mode 100644 .vscode/settings.json delete mode 160000 include/glm delete mode 160000 include/imgui delete mode 160000 include/tinyxml2 diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..01273ba --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: LLVM +ColumnLimit: 160 +PointerAlignment: Left +ReferenceAlignment: Left \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 8b36230..1d29dd3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,10 +1,10 @@ -[submodule "include/imgui"] - path = include/imgui - url = https://github.com/ocornut/imgui - branch = docking [submodule "include/glm"] path = include/glm url = https://github.com/g-truc/glm [submodule "include/tinyxml2"] path = include/tinyxml2 url = https://github.com/leethomason/tinyxml2 +[submodule "include/imgui"] + path = include/imgui + url = https://github.com/ocornut/imgui/tree/docking + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3991cfc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "C_Cpp.formatting": "clangFormat", + "editor.formatOnSave": true, + "clang-format.style": "file" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c0d633..e71e068 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,16 +15,16 @@ set(GLAD_SRC ) set(IMGUI_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/imgui.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/imgui_draw.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/imgui_widgets.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/imgui_tables.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/backends/imgui_impl_sdl3.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui/backends/imgui_impl_opengl3.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_draw.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_widgets.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_tables.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/backends/imgui_impl_sdl3.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/backends/imgui_impl_opengl3.cpp ) set(TINYXML2_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/include/tinyxml2/tinyxml2.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/tinyxml2.cpp ) file(GLOB PROJECT_SRC @@ -50,8 +50,10 @@ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/glad - ${CMAKE_CURRENT_SOURCE_DIR}/include/imgui - ${CMAKE_CURRENT_SOURCE_DIR}/include/tinyxml2 + ${CMAKE_CURRENT_SOURCE_DIR}/external + ${CMAKE_CURRENT_SOURCE_DIR}/external/imgui + ${CMAKE_CURRENT_SOURCE_DIR}/external/glm + ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 ${CMAKE_CURRENT_SOURCE_DIR}/src ) diff --git a/include/glm b/include/glm deleted file mode 160000 index 2d4c4b4..0000000 --- a/include/glm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2d4c4b4dd31fde06cfffad7915c2b3006402322f diff --git a/include/imgui b/include/imgui deleted file mode 160000 index d896eab..0000000 --- a/include/imgui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d896eab16620f80e3cae9b164eb62f71b47f6e45 diff --git a/include/tinyxml2 b/include/tinyxml2 deleted file mode 160000 index e6caeae..0000000 --- a/include/tinyxml2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e6caeae85799003f4ca74ff26ee16a789bc2af48 diff --git a/src/COMMON.h b/src/COMMON.h index 2c7999a..f93035a 100644 --- a/src/COMMON.h +++ b/src/COMMON.h @@ -222,12 +222,12 @@ template static inline void map_swap(Map& map, cons } }; -template static inline void map_insert_shift(std::map& map, int index, const T& value) { - const int insertIndex = index + 1; +template static inline void map_insert_shift(std::map& map, int id, const T& value) { + const int insertID = id + 1; std::vector> toShift; for (auto it = map.rbegin(); it != map.rend(); ++it) { - if (it->first < insertIndex) + if (it->first < insertID) break; toShift.emplace_back(it->first + 1, std::move(it->second)); } @@ -238,7 +238,7 @@ template static inline void map_insert_shift(std::map& map, for (auto& [newKey, val] : toShift) map[newKey] = std::move(val); - map[insertIndex] = value; + map[insertID] = value; } template static inline T* vector_find(std::vector& v, const T& value) { diff --git a/src/imgui.cpp b/src/imgui.cpp index c8b420f..37fc548 100644 --- a/src/imgui.cpp +++ b/src/imgui.cpp @@ -52,10 +52,14 @@ static bool _imgui_chord_pressed(ImGuiKeyChord chord) { static bool _imgui_is_focus_window(const std::string& focus) { ImGuiContext* context = ImGui::GetCurrentContext(); - if (!context || !context->NavWindow) + if (!context) return false; - std::string_view name(context->NavWindow->Name); + ImGuiWindow* window = context->NavWindow; + if (!window || !window->Name) + return false; + + std::string_view name(window->Name); return name.find(focus) != std::string_view::npos; } @@ -208,6 +212,7 @@ static void _imgui_item_pre(const ImguiItem& self, ImguiItemType type) { } static void _imgui_item_post(const ImguiItem& self, Imgui* imgui, ImguiItemType type, bool& isActivated) { + if (self.is_mnemonic() && !self.isMnemonicDisabled) { ImVec2 position = ImGui::GetItemRectMin(); ImFont* font = ImGui::GetFont(); @@ -387,7 +392,6 @@ IMGUI_ITEM_BOOL_FUNCTION(_imgui_button, IMGUI_BUTTON, ImGui::Button(self.label_g IMGUI_ITEM_BOOL_FUNCTION(_imgui_begin_table, IMGUI_TABLE, ImGui::BeginTable(self.label_get().c_str(), self.value, self.flags)); IMGUI_ITEM_BOOL_FUNCTION(_imgui_selectable, IMGUI_SELECTABLE, ImGui::Selectable(self.label_get().c_str(), self.isSelected, self.flags, _imgui_item_size_get(self, type))); -IMGUI_ITEM_BOOL_FUNCTION(_imgui_begin, IMGUI_WINDOW, ImGui::Begin(self.label_get().c_str(), nullptr, self.flags)); IMGUI_ITEM_VOID_FUNCTION(_imgui_image, IMGUI_IMAGE, ImGui::Image(self.textureID, _imgui_item_size_get(self, IMGUI_IMAGE), self.uvMin, self.uvMax)); IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_int, IMGUI_INPUT_INT, int, @@ -403,8 +407,11 @@ IMGUI_ITEM_VALUE_FUNCTION(_imgui_slider_float, IMGUI_SLIDER_FLOAT, float, IMGUI_ITEM_STRING_FUNCTION(_imgui_input_text, IMGUI_INPUT_TEXT, (value.resize(*self.max), ImGui::InputText(self.label_get().c_str(), value.data(), *self.max, self.flags))); -#define IMGUI_BEGIN_OR_RETURN(item, imgui) \ - if (!_imgui_begin(item, imgui)) { \ +static bool _imgui_begin(const ImguiItem& self) { return ImGui::Begin(self.label_get().c_str(), nullptr, self.flags); } +static void _imgui_end(void) { ImGui::End(); } + +#define IMGUI_BEGIN_OR_RETURN(item) \ + if (!_imgui_begin(item)) { \ _imgui_end(); \ return; \ } @@ -431,7 +438,6 @@ IMGUI_ITEM_CHECKBOX_VALUE_FUNCTION(_imgui_checkbox_color_edit3, vec3, _imgui_col IMGUI_ITEM_CHECKBOX_VALUE_FUNCTION(_imgui_checkbox_color_edit4, vec4, _imgui_color_edit4(self, imgui, value)); */ -static void _imgui_end(void) { ImGui::End(); } static void _imgui_end_table(void) { ImGui::EndTable(); } static void _imgui_table_setup_column(const char* text) { ImGui::TableSetupColumn(text); } static void _imgui_table_headers_row(void) { ImGui::TableHeadersRow(); } @@ -633,7 +639,7 @@ static void _imgui_timeline(Imgui* self) { static int frameTime{}; static int& itemID = self->reference->itemID; - IMGUI_BEGIN_OR_RETURN(IMGUI_TIMELINE, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_TIMELINE); _imgui_no_anm2_path_click_check(self); Anm2Animation* animation = anm2_animation_from_reference(self->anm2, *self->reference); @@ -744,7 +750,7 @@ static void _imgui_timeline(Imgui* self) { ImGui::SetNextWindowPos(ImGui::GetWindowPos()); ImGui::SetNextWindowSize(ImGui::GetWindowSize()); - _imgui_begin(IMGUI_PLAYHEAD, self); + _imgui_begin(IMGUI_PLAYHEAD); ImVec2& pos = playheadPos; @@ -1383,7 +1389,7 @@ static void _imgui_timeline(Imgui* self) { } static void _imgui_onionskin(Imgui* self) { - IMGUI_BEGIN_OR_RETURN(IMGUI_ONIONSKIN, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_ONIONSKIN); static auto& isEnabled = self->settings->onionskinIsEnabled; static auto& beforeCount = self->settings->onionskinBeforeCount; @@ -1423,7 +1429,7 @@ static void _imgui_taskbar(Imgui* self) { ImguiItem taskbar = IMGUI_TASKBAR; ImGui::SetNextWindowSize({viewport->Size.x, IMGUI_TASKBAR.size->y * displayScale}); ImGui::SetNextWindowPos(viewport->Pos); - _imgui_begin(taskbar, self); + _imgui_begin(taskbar); Anm2Animation* animation = anm2_animation_from_reference(self->anm2, *self->reference); Anm2Item* item = anm2_item_from_reference(self->anm2, *self->reference); @@ -1888,7 +1894,7 @@ static void _imgui_taskbar(Imgui* self) { static void _imgui_tools(Imgui* self) { ImGuiStyle style = ImGui::GetStyle(); - IMGUI_BEGIN_OR_RETURN(IMGUI_TOOLS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_TOOLS); float availableWidth = ImGui::GetContentRegionAvail().x; float usedWidth = style.FramePadding.x; @@ -1928,7 +1934,7 @@ static void _imgui_tools(Imgui* self) { static void _imgui_layers(Imgui* self) { static int selectedLayerID = ID_NONE; - IMGUI_BEGIN_OR_RETURN(IMGUI_LAYERS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_LAYERS); _imgui_no_anm2_path_click_check(self); ImVec2 size = ImGui::GetContentRegionAvail(); @@ -1973,7 +1979,7 @@ static void _imgui_layers(Imgui* self) { static void _imgui_nulls(Imgui* self) { static int selectedNullID = ID_NONE; - IMGUI_BEGIN_OR_RETURN(IMGUI_NULLS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_NULLS); _imgui_no_anm2_path_click_check(self); ImVec2 size = ImGui::GetContentRegionAvail(); @@ -2008,7 +2014,7 @@ static void _imgui_nulls(Imgui* self) { } static void _imgui_animations(Imgui* self) { - IMGUI_BEGIN_OR_RETURN(IMGUI_ANIMATIONS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_ANIMATIONS); _imgui_no_anm2_path_click_check(self); ImVec2 size = ImGui::GetContentRegionAvail(); @@ -2179,7 +2185,7 @@ static void _imgui_animations(Imgui* self) { static void _imgui_events(Imgui* self) { static int selectedID = ID_NONE; - IMGUI_BEGIN_OR_RETURN(IMGUI_EVENTS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_EVENTS); _imgui_no_anm2_path_click_check(self); ImVec2 windowSize = ImGui::GetContentRegionAvail(); @@ -2230,7 +2236,7 @@ static void _imgui_events(Imgui* self) { */ static void _imgui_spritesheets(Imgui* self) { - IMGUI_BEGIN_OR_RETURN(IMGUI_SPRITESHEETS, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_SPRITESHEETS); _imgui_no_anm2_path_click_check(self); static std::unordered_set selectedIDs; @@ -2385,7 +2391,7 @@ static void _imgui_animation_preview(Imgui* self) { std::string mousePositionString = std::format(IMGUI_POSITION_FORMAT, (int)mousePos.x, (int)mousePos.y); - IMGUI_BEGIN_OR_RETURN(IMGUI_ANIMATION_PREVIEW, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_ANIMATION_PREVIEW); _imgui_begin_child(IMGUI_CANVAS_GRID_CHILD, self); _imgui_checkbox(IMGUI_CANVAS_GRID, self, self->settings->previewIsGrid); @@ -2598,7 +2604,7 @@ static void _imgui_spritesheet_editor(Imgui* self) { std::string mousePositionString = std::format(IMGUI_POSITION_FORMAT, (int)mousePos.x, (int)mousePos.y); - IMGUI_BEGIN_OR_RETURN(IMGUI_SPRITESHEET_EDITOR, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_SPRITESHEET_EDITOR); _imgui_begin_child(IMGUI_CANVAS_GRID_CHILD, self); _imgui_checkbox(IMGUI_CANVAS_GRID, self, self->settings->editorIsGrid); @@ -2815,7 +2821,7 @@ static void _imgui_spritesheet_editor(Imgui* self) { static void _imgui_frame_properties(Imgui* self) { static Anm2Type& type = self->reference->itemType; - IMGUI_BEGIN_OR_RETURN(IMGUI_FRAME_PROPERTIES, self); + IMGUI_BEGIN_OR_RETURN(IMGUI_FRAME_PROPERTIES); Anm2Frame* frame = anm2_frame_from_reference(self->anm2, *self->reference); @@ -2896,7 +2902,7 @@ static void _imgui_log(Imgui* self) { ImGui::PushStyleColor(ImGuiCol_Text, textColor); ImGui::SetNextWindowBgAlpha(lifetime); - _imgui_begin(IMGUI_LOG_WINDOW.copy({.label = std::format(IMGUI_LOG_FORMAT, i)}), self); + _imgui_begin(IMGUI_LOG_WINDOW.copy({.label = std::format(IMGUI_LOG_FORMAT, i)})); ImGui::TextUnformatted(item.text.c_str()); ImVec2 windowSize = ImGui::GetWindowSize(); _imgui_end(); // IMGUI_LOG_WINDOW @@ -2915,7 +2921,7 @@ static void _imgui_dock(Imgui* self) { ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, viewport->Size.y - IMGUI_TASKBAR.size->y)); ImGui::SetNextWindowViewport(viewport->ID); - _imgui_begin(window, self); + _imgui_begin(window); _imgui_dockspace(IMGUI_DOCKSPACE_MAIN, self); //_imgui_tools(self); @@ -2936,6 +2942,7 @@ static void _imgui_dock(Imgui* self) { void imgui_init(Imgui* self, Dialog* dialog, Resources* resources, Anm2* anm2, Anm2Reference* reference, Editor* editor, Preview* preview, GeneratePreview* generatePreview, Settings* settings, Snapshots* snapshots, Clipboard* clipboard, SDL_Window* window, SDL_GLContext* glContext) { + self->dialog = dialog; self->resources = resources; self->anm2 = anm2; @@ -2951,9 +2958,12 @@ void imgui_init(Imgui* self, Dialog* dialog, Resources* resources, Anm2* anm2, A self->saveAnm2 = *anm2; + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGui::StyleColorsDark(); + log_info(std::format(IMGUI_LOG_INIT, ImGui::GetVersion())); + ImGui_ImplSDL3_InitForOpenGL(self->window, *self->glContext); ImGui_ImplOpenGL3_Init(IMGUI_OPENGL_VERSION); @@ -2983,6 +2993,13 @@ void imgui_update(Imgui* self) { ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); + auto* ctx = ImGui::GetCurrentContext(); + IM_ASSERT(ctx); + IM_ASSERT(ctx->WithinFrameScope); + IM_ASSERT(ctx->CurrentWindowStack.Size >= 1); + IM_ASSERT(ImGui::GetIO().BackendPlatformUserData && "SDL3 backend not initialized?"); + IM_ASSERT(ImGui::GetIO().BackendRendererUserData && "OpenGL3 backend not initialized?"); + _imgui_taskbar(self); _imgui_dock(self); _imgui_log(self); @@ -3052,6 +3069,7 @@ void imgui_free(void) { if (!ImGui::GetCurrentContext()) return; + log_info(IMGUI_LOG_FREE); ImGui_ImplSDL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown(); ImGui::SaveIniSettingsToDisk(settings_path_get().c_str()); diff --git a/src/imgui.h b/src/imgui.h index bf561a5..54c8272 100644 --- a/src/imgui.h +++ b/src/imgui.h @@ -116,6 +116,9 @@ #define IMGUI_POPUP_FLAGS ImGuiWindowFlags_NoMove #define IMGUI_POPUP_MODAL_FLAGS ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize +#define IMGUI_LOG_INIT "Initialized ImGui {}" +#define IMGUI_LOG_FREE "Freed ImGui" + #define IMGUI_LOG_NO_ANM2_PATH "Please save the .anm2 to a path first!" #define IMGUI_LOG_FILE_OPEN_FORMAT "Opened anm2: {}" #define IMGUI_LOG_FILE_SAVE_FORMAT "Saved anm2 to: {}" @@ -1092,7 +1095,7 @@ IMGUI_ITEM(IMGUI_EVENTS_REMOVE_UNUSED, self.label = "Remove Unused", // Spritesheets IMGUI_ITEM(IMGUI_SPRITESHEET_PREVIEW, self.label = "## Spritesheet Preview", self.size = {65, 65}); IMGUI_ITEM(IMGUI_SPRITESHEETS, self.label = "Spritesheets", self.flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); -IMGUI_ITEM(IMGUI_SPRITESHEETS_CHILD, self.label = "## Spritesheets Child", self.flags = true, self.itemSpacing = vec2(), self.windowPadding = vec2()); +IMGUI_ITEM(IMGUI_SPRITESHEETS_CHILD, self.label = "## Spritesheets Child", self.flags = true, self.windowPadding = vec2()); IMGUI_ITEM(IMGUI_SPRITESHEET_CHILD, self.label = "## Spritesheet Child", self.flags = true, self.itemSpacing = vec2(), self.windowPadding = vec2()); IMGUI_ITEM(IMGUI_SPRITESHEET, self.label = "## Spritesheet", self.dragDrop = "## Spritesheet Drag Drop"); IMGUI_ITEM(IMGUI_SPRITESHEET_TEXT, self.label = "## Spritesheet Text", self.atlas = ATLAS_SPRITESHEET, self.itemSpacing = vec2(8, 0));