From 1ded2efe59c9632c4a5f81aad1844c9f02b3bf7f Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sun, 26 Jan 2025 17:21:06 +0100 Subject: [PATCH] SWIG: fix ImGui bindings for C# and Java --- Components/Bites/include/OgreBites.i | 4 ++++ Components/Csharp/CMakeLists.txt | 17 +++++++++-------- Components/Java/CMakeLists.txt | 17 +++++++++-------- Components/Overlay/include/ImGui.i | 10 +++++----- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Components/Bites/include/OgreBites.i b/Components/Bites/include/OgreBites.i index 5a40d3dd0a6..b4b939bd18e 100644 --- a/Components/Bites/include/OgreBites.i +++ b/Components/Bites/include/OgreBites.i @@ -21,6 +21,10 @@ %include stdint.i %import "Ogre.i" +#ifndef SWIGPYTHON +%import "OgreOverlay.i" +#endif + #define _OgreBitesExport %include "OgreSGTechniqueResolverListener.h" diff --git a/Components/Csharp/CMakeLists.txt b/Components/Csharp/CMakeLists.txt index 36d4e1e3442..6e3b32816c4 100644 --- a/Components/Csharp/CMakeLists.txt +++ b/Components/Csharp/CMakeLists.txt @@ -52,7 +52,15 @@ if(OGRE_BUILD_COMPONENT_TERRAIN) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreTerrain") endif() +if(OGRE_BUILD_COMPONENT_BULLET) + include_directories("${BULLET_INCLUDE_DIRS}") + set_source_files_properties(../Bullet/include/OgreBullet.i PROPERTIES CPLUSPLUS ON) + list(APPEND SWIG_INPUT_MODULES ../Bullet/include/OgreBullet.i) + list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBullet") +endif() + if(OGRE_BUILD_COMPONENT_OVERLAY) + include_directories("${PROJECT_SOURCE_DIR}/Components/Overlay/include") set_source_files_properties(../Overlay/include/OgreOverlay.i PROPERTIES CPLUSPLUS ON) list(APPEND SWIG_INPUT_MODULES ../Overlay/include/OgreOverlay.i) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreOverlay") @@ -62,7 +70,7 @@ if(OGRE_BUILD_COMPONENT_OVERLAY_IMGUI) include_directories("${IMGUI_DIR}") list(APPEND CMAKE_SWIG_FLAGS -DHAVE_IMGUI -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS) set_source_files_properties(../Overlay/include/ImGui.i PROPERTIES CPLUSPLUS ON) - list(APPEND SWIG_INPUT_MODULE ../Overlay/include/ImGui.i) + list(APPEND SWIG_INPUT_MODULES ../Overlay/include/ImGui.i) endif() if(OGRE_BUILD_COMPONENT_BITES) @@ -71,13 +79,6 @@ if(OGRE_BUILD_COMPONENT_BITES) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBites") endif() -if(OGRE_BUILD_COMPONENT_BULLET) - include_directories("${BULLET_INCLUDE_DIRS}") - set_source_files_properties(../Bullet/include/OgreBullet.i PROPERTIES CPLUSPLUS ON) - list(APPEND SWIG_INPUT_MODULES ../Bullet/include/OgreBullet.i) - list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBullet") -endif() - swig_add_library(libOgre LANGUAGE csharp SOURCES ${SWIG_INPUT_MODULES}) SWIG_LINK_LIBRARIES(libOgre ${SWIG_COMPONENT_LIBRARIES}) diff --git a/Components/Java/CMakeLists.txt b/Components/Java/CMakeLists.txt index baa72dcddc1..be3363c24cd 100644 --- a/Components/Java/CMakeLists.txt +++ b/Components/Java/CMakeLists.txt @@ -63,7 +63,15 @@ if(OGRE_BUILD_COMPONENT_TERRAIN) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreTerrain") endif() +if(OGRE_BUILD_COMPONENT_BULLET) + include_directories("${BULLET_INCLUDE_DIRS}") + set_source_files_properties(../Bullet/include/OgreBullet.i PROPERTIES CPLUSPLUS ON) + list(APPEND SWIG_INPUT_MODULES ../Bullet/include/OgreBullet.i) + list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBullet") +endif() + if(OGRE_BUILD_COMPONENT_OVERLAY) + include_directories("${PROJECT_SOURCE_DIR}/Components/Overlay/include") set_source_files_properties(../Overlay/include/OgreOverlay.i PROPERTIES CPLUSPLUS ON) list(APPEND SWIG_INPUT_MODULES ../Overlay/include/OgreOverlay.i) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreOverlay") @@ -73,7 +81,7 @@ if(OGRE_BUILD_COMPONENT_OVERLAY_IMGUI) include_directories("${IMGUI_DIR}") list(APPEND CMAKE_SWIG_FLAGS -DHAVE_IMGUI -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS) set_source_files_properties(../Overlay/include/ImGui.i PROPERTIES CPLUSPLUS ON) - list(APPEND SWIG_INPUT_MODULE ../Overlay/include/ImGui.i) + list(APPEND SWIG_INPUT_MODULES ../Overlay/include/ImGui.i) endif() if(OGRE_BUILD_COMPONENT_BITES) @@ -87,13 +95,6 @@ if(OGRE_BUILD_COMPONENT_BITES) list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBites") endif() -if(OGRE_BUILD_COMPONENT_BULLET) - include_directories("${BULLET_INCLUDE_DIRS}") - set_source_files_properties(../Bullet/include/OgreBullet.i PROPERTIES CPLUSPLUS ON) - list(APPEND SWIG_INPUT_MODULES ../Bullet/include/OgreBullet.i) - list(APPEND SWIG_COMPONENT_LIBRARIES "OgreBullet") -endif() - swig_add_library(OgreJNI LANGUAGE java SOURCES ${SWIG_INPUT_MODULES}) swig_link_libraries(OgreJNI ${SWIG_COMPONENT_LIBRARIES} ${JNI_LIBRARIES}) diff --git a/Components/Overlay/include/ImGui.i b/Components/Overlay/include/ImGui.i index d6d90e30f62..33dcdd67e4d 100644 --- a/Components/Overlay/include/ImGui.i +++ b/Components/Overlay/include/ImGui.i @@ -20,10 +20,13 @@ %ignore ImGui::TreeNodeExV; %ignore ImGui::SetTooltipV; %ignore ImGui::SetItemTooltipV; -%ignore ImGuiTextBuffer::appendfv; %ignore ImGui::DebugLogV; %ignore ImGuiSelectionBasicStorage; +// not needed in high level languages +%ignore ImGuiTextBuffer; + +#ifdef SWIGPYTHON %typemap(in) ImTextureID { size_t argp; int res = SWIG_AsVal_size_t($input, &argp); @@ -46,7 +49,6 @@ } } -#ifdef SWIGPYTHON // match the signature of the by value variants %typemap(argout) float[4], float[3], float[2] { $result = SWIG_AppendOutput($result, SWIG_NewPointerObj($1, $descriptor(ImVec4*), 0)); @@ -73,18 +75,16 @@ %typecheck(SWIG_TYPECHECK_STRING) (const float* values, int values_count) { $1 = true; // actual check in the typemap } -#endif %typecheck(SWIG_TYPECHECK_STRING) float[4], float[3], float[2] { $1 = true; // actual check in the typemap } -#ifdef SWIGPYTHON %rename("__version__") "IMGUI_VERSION"; -#endif // strip duplicate namespace for ImGuiSomething_FlagName flags %rename("%(strip:[ImGui])s", regextarget=1) "^ImGui.+_.+"; +#endif %apply bool* INOUT { bool* p_open }; %apply bool* INOUT { bool* v };