Skip to content

Commit

Permalink
SWIG: fix ImGui bindings for C# and Java
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 26, 2025
1 parent f8429eb commit 1ded2ef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Components/Bites/include/OgreBites.i
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
%include stdint.i
%import "Ogre.i"

#ifndef SWIGPYTHON
%import "OgreOverlay.i"
#endif

#define _OgreBitesExport

%include "OgreSGTechniqueResolverListener.h"
Expand Down
17 changes: 9 additions & 8 deletions Components/Csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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})

Expand Down
17 changes: 9 additions & 8 deletions Components/Java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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})

Expand Down
10 changes: 5 additions & 5 deletions Components/Overlay/include/ImGui.i
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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 };
Expand Down

0 comments on commit 1ded2ef

Please sign in to comment.