Skip to content

Commit db1e174

Browse files
committed
Dear ImGui integration in Cinder (including python update script).
1 parent 0197794 commit db1e174

File tree

13 files changed

+940
-20
lines changed

13 files changed

+940
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ cinderConfig.cmake
7070
# CinderBlocks
7171
blocks/
7272
!blocks/[__AppTemplates,Box2D,Cairo,FMOD,LocationManager,MotionManager,OSC,QuickTime,TUIO]
73+
74+
#ImGui stored settings
75+
imgui.ini

include/cinder/CinderImGui.h

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
Copyright (c) 2010, The Cinder Project, All rights reserved.
3+
4+
This code is intended for use with the Cinder C++ library: http://libcinder.org
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7+
the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this list of conditions and
10+
the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12+
the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21+
POSSIBILITY OF SUCH DAMAGE.
22+
*/
23+
24+
#pragma once
25+
26+
#if ! defined( IMGUI_USER_CONFIG )
27+
#define IMGUI_USER_CONFIG "cinder/CinderImGuiConfig.h"
28+
#endif
29+
#include "imgui/imgui.h"
30+
#include "imgui/imgui_stdlib.h"
31+
32+
#include "cinder/Filesystem.h"
33+
#include "cinder/CinderGlm.h"
34+
#include "cinder/Noncopyable.h"
35+
36+
#include <vector>
37+
38+
namespace cinder {
39+
namespace app { typedef std::shared_ptr<class Window> WindowRef; }
40+
namespace gl { typedef std::shared_ptr<class Texture2d> Texture2dRef; }
41+
}
42+
43+
//! Additional convenience initializaiont and overloads for cinder types
44+
namespace ImGui {
45+
struct CI_API Options {
46+
//! Defaults to using the current window, the basic ImGui font and the dark theme
47+
Options();
48+
49+
//! Sets the window that will be used to connect the signals and render ImGui
50+
Options& window( const ci::app::WindowRef& window, int signalPriority = 1 );
51+
//! Returns the window that will be use to connect the signals and render ImGui
52+
ci::app::WindowRef getWindow() const { return mWindow; }
53+
54+
//! Specify whether the block should call ImGui::NewFrame and ImGui::Render automatically. Default to true.
55+
Options& autoRender( bool autoRender );
56+
//! returns whether the block should call ImGui::NewFrame and ImGui::Render automatically
57+
bool isAutoRenderEnabled() const { return mAutoRender; }
58+
59+
//! Sets imgui ini file path
60+
Options& iniPath( const ci::fs::path& path );
61+
//! Returns imgui ini file path
62+
const ci::fs::path& getIniPath() const { return mIniPath; }
63+
64+
//! Enables keyboard input. Default to true.
65+
Options& enableKeyboard( bool enable );
66+
//! Returns whether the keyboard input is enabled
67+
bool isKeyboardEnabled() const { return mKeyboardEnabled; }
68+
69+
//! Enables gamepad input. Default to true.
70+
Options& enableGamepad( bool enable );
71+
//! Returns whether the gamepad input is enabled
72+
bool isGamepadEnabled() const { return mGamepadEnabled; }
73+
74+
Options& signalPriority( int signalPriority );
75+
//! Returns the signal priority that will be use to connect the signals and render ImGui
76+
int getSignalPriority() const { return mSignalPriority; }
77+
protected:
78+
bool mAutoRender;
79+
bool mKeyboardEnabled;
80+
bool mGamepadEnabled;
81+
ci::app::WindowRef mWindow;
82+
ci::fs::path mIniPath;
83+
int mSignalPriority;
84+
};
85+
86+
//! Convenience ImGui initialization for cinder applications.
87+
//! By default, automatic rendering into ci::app::getWindow() will be used.
88+
//! In a multi-window context, only call ImGui in App::draw() if the active window matches the one
89+
//! used here for initialization, or in App::update() only if the this window is still open.
90+
CI_API void Initialize( const Options& options = Options() );
91+
92+
CI_API bool DragFloat2( const char* label, glm::vec2* v2, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f );
93+
CI_API bool DragFloat3( const char* label, glm::vec3* v2, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f );
94+
CI_API bool DragFloat4( const char* label, glm::vec4* v2, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f );
95+
96+
CI_API bool DragInt2( const char* label, glm::ivec2* v2, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%.3f" );
97+
CI_API bool DragInt3( const char* label, glm::ivec3* v2, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%.3f" );
98+
CI_API bool DragInt4( const char* label, glm::ivec4* v2, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%.3f" );
99+
100+
CI_API bool SliderFloat2( const char* label, glm::vec2* v2, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f );
101+
CI_API bool SliderFloat3( const char* label, glm::vec3* v2, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f );
102+
CI_API bool SliderFloat4( const char* label, glm::vec4* v2, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f );
103+
104+
CI_API bool SliderInt2( const char* label, glm::ivec2* v2, int v_min, int v_max, const char* format = "%.3f" );
105+
CI_API bool SliderInt3( const char* label, glm::ivec3* v2, int v_min, int v_max, const char* format = "%.3f" );
106+
CI_API bool SliderInt4( const char* label, glm::ivec4* v2, int v_min, int v_max, const char* format = "%.3f" );
107+
108+
CI_API bool InputInt2( const char* label, glm::ivec2* v2, ImGuiInputTextFlags flags = 0 );
109+
CI_API bool InputInt3( const char* label, glm::ivec3* v2, ImGuiInputTextFlags flags = 0 );
110+
CI_API bool InputInt4( const char* label, glm::ivec4* v2, ImGuiInputTextFlags flags = 0 );
111+
112+
CI_API bool ColorEdit3( const char* label, ci::Colorf* color, ImGuiColorEditFlags flags = 0 );
113+
CI_API bool ColorEdit4( const char* label, ci::ColorAf* color, ImGuiColorEditFlags flags = 0 );
114+
115+
CI_API bool ColorPicker3( const char* label, ci::Colorf* color, ImGuiColorEditFlags flags = 0 );
116+
CI_API bool ColorPicker4( const char* label, ci::ColorAf* color, ImGuiColorEditFlags flags = 0 );
117+
118+
CI_API bool Combo( const char* label, int* currIndex, std::vector<std::string>& values );
119+
CI_API bool ListBox( const char* label, int* currIndex, std::vector<std::string>& values );
120+
121+
CI_API void Image( const ci::gl::Texture2dRef& texture, const ci::vec2& size, const ci::vec2& uv0 = ci::vec2( 0, 0 ), const ci::vec2& uv1 = ci::vec2( 1, 1 ), const ci::vec4& tint_col = ci::vec4( 1, 1, 1, 1 ), const ci::vec4& border_col = ci::vec4( 0, 0, 0, 0 ) );
122+
123+
struct CI_API ScopedWindow : public ci::Noncopyable {
124+
ScopedWindow( const char* label );
125+
~ScopedWindow();
126+
};
127+
128+
struct CI_API ScopedGroup : public ci::Noncopyable {
129+
ScopedGroup();
130+
~ScopedGroup();
131+
};
132+
133+
struct CI_API ScopedTreeNode : public ci::Noncopyable {
134+
ScopedTreeNode( const std::string& name );
135+
~ScopedTreeNode();
136+
//! Returns true when tree node is not collapsed
137+
explicit operator bool() const { return mOpened; }
138+
protected:
139+
bool mOpened;
140+
};
141+
142+
struct CI_API ScopedId : public ci::Noncopyable {
143+
ScopedId( int int_id );
144+
ScopedId( const char* label );
145+
~ScopedId();
146+
};
147+
148+
struct CI_API ScopedMenuBar : public ci::Noncopyable {
149+
ScopedMenuBar();
150+
~ScopedMenuBar();
151+
protected:
152+
bool mOpened;
153+
};
154+
155+
struct CI_API ScopedMainMenuBar : public ci::Noncopyable {
156+
ScopedMainMenuBar();
157+
~ScopedMainMenuBar();
158+
protected:
159+
bool mOpened;
160+
};
161+
162+
struct CI_API ScopedColumns : public ci::Noncopyable {
163+
ScopedColumns( int count, const char* id = NULL, bool border = true );
164+
~ScopedColumns();
165+
};
166+
}

include/cinder/CinderImGuiConfig.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright (c) 2010, The Cinder Project, All rights reserved.
3+
4+
This code is intended for use with the Cinder C++ library: http://libcinder.org
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7+
the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this list of conditions and
10+
the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12+
the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21+
POSSIBILITY OF SUCH DAMAGE.
22+
*/
23+
24+
#pragma once
25+
26+
#include "cinder/Export.h"
27+
#include "cinder/Color.h"
28+
#include "cinder/Vector.h"
29+
#include "cinder/CinderAssert.h"
30+
#include "cinder/gl/platform.h"
31+
32+
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM "cinder/gl/platform.h"
33+
#if defined( CINDER_GL_ES_3 )
34+
#define IMGUI_IMPL_OPENGL_ES3
35+
#endif
36+
37+
//---- Define assertion handler. Defaults to calling assert().
38+
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
39+
#define IM_ASSERT(_EXPR) CI_ASSERT(_EXPR)
40+
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
41+
42+
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
43+
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
44+
#define IMGUI_API CI_API
45+
46+
// Custom implicit cast operators
47+
// Custom implicit cast operators
48+
#ifndef CINDER_IMGUI_NO_IMPLICIT_CASTS
49+
#define IM_VEC2_CLASS_EXTRA \
50+
ImVec2(const ci::vec2& f) { x = f.x; y = f.y; } \
51+
operator ci::vec2() const { return ci::vec2(x,y); } \
52+
ImVec2(const ci::ivec2& f) { x = static_cast<float>( f.x ); y = static_cast<float>( f.y ); } \
53+
operator ci::ivec2() const { return ci::ivec2(x,y); }
54+
55+
#define IM_VEC4_CLASS_EXTRA \
56+
ImVec4(const glm::vec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
57+
operator glm::vec4() const { return ci::vec4(x,y,z,w); } \
58+
ImVec4(const ci::ColorA& f) { x = f.r; y = f.g; z = f.b; w = f.a; } \
59+
operator ci::ColorA() const { return ci::ColorA(x,y,z,w); } \
60+
ImVec4(const ci::Color& f) { x = f.r; y = f.g; z = f.b; w = 1.0f; } \
61+
operator ci::Color() const { return ci::Color(x,y,z); }
62+
#endif

include/imgui/imgui_impl_opengl3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
2323

2424
#pragma once
25+
#include "cinder/CinderImGuiConfig.h"
26+
2527

2628
// Backend API
2729
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);

proj/cmake/configure.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option( BUILD_SHARED_LIBS "Build Cinder as a shared library. " OFF )
66
option( CINDER_DISABLE_AUDIO "Build Cinder without audio support. " OFF )
77
option( CINDER_DISABLE_VIDEO "Build Cinder without video support. " OFF )
88
option( CINDER_DISABLE_ANTTWEAKBAR "Build Cinder without AntTweakBar support. " OFF )
9+
option( CINDER_DISABLE_IMGUI "Build Cinder without imgui support. " OFF )
910

1011
include( ${CMAKE_CURRENT_LIST_DIR}/utilities.cmake )
1112

proj/cmake/libcinder_configure.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ list( APPEND CINDER_INCLUDE_USER_PRIVATE
2525
${CINDER_INC_DIR}
2626
${CINDER_INC_DIR}/jsoncpp
2727
${CINDER_INC_DIR}/tinyexr
28+
${CINDER_INC_DIR}/imgui
2829
${CINDER_SRC_DIR}/linebreak
2930
${CINDER_SRC_DIR}/oggvorbis/vorbis
3031
${CINDER_SRC_DIR}/r8brain
@@ -72,3 +73,9 @@ if( CINDER_GL_ES OR CINDER_DISABLE_ANTTWEAKBAR )
7273
else()
7374
set( CINDER_ANTTWEAKBAR_ENABLED TRUE )
7475
endif()
76+
77+
if( CINDER_DISABLE_IMGUI )
78+
set( CINDER_IMGUI_ENABLED FALSE )
79+
else()
80+
set( CINDER_IMGUI_ENABLED TRUE )
81+
endif()

proj/cmake/libcinder_source_files.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,26 @@ if( CINDER_ANTTWEAKBAR_ENABLED )
321321

322322
endif()
323323

324+
if( CINDER_IMGUI_ENABLED )
325+
list( APPEND SRC_SET_CINDER_IMGUI ${CINDER_SRC_DIR}/cinder/CinderImGui.cpp )
326+
list( APPEND SRC_SET_IMGUI
327+
${CINDER_SRC_DIR}/imgui/imgui.cpp
328+
${CINDER_SRC_DIR}/imgui/imgui_demo.cpp
329+
${CINDER_SRC_DIR}/imgui/imgui_draw.cpp
330+
${CINDER_SRC_DIR}/imgui/imgui_freetype.cpp
331+
${CINDER_SRC_DIR}/imgui/imgui_impl_opengl3.cpp
332+
${CINDER_SRC_DIR}/imgui/imgui_stdlib.cpp
333+
${CINDER_SRC_DIR}/imgui/imgui_widgets.cpp
334+
)
335+
336+
list( APPEND CINDER_SRC_FILES
337+
${SRC_SET_CINDER_IMGUI}
338+
${SRC_SET_IMGUI}
339+
)
340+
source_group( "cinder" FILES ${SRC_SET_CINDER_IMGUI} )
341+
source_group( "thirdparty\\imgui" FILES ${SRC_SET_IMGUI} )
342+
endif()
343+
324344
# ----------------------------------------------------------------------------------------------------------------------
325345
# FreeType
326346
# ----------------------------------------------------------------------------------------------------------------------

proj/cmake/platform_macosx.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ list( APPEND CINDER_SRC_FILES
8686
${SRC_SET_AUDIO_COCOA}
8787
)
8888

89-
list( APPEND CINDER_LIBS_DEPENDS
90-
${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}/libboost_system.a
91-
${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}/libboost_filesystem.a
92-
)
93-
9489
# link in system frameworks
9590
find_library( COCOA_FRAMEWORK Cocoa REQUIRED )
9691
find_library( OPENGL_FRAMEWORK OpenGL REQUIRED )
@@ -146,7 +141,6 @@ source_group( "cinder\\app\\cocoa" FILES ${SRC_SET_APP_COCOA} )
146141
source_group( "cinder\\audio\\cocoa" FILES ${SRC_SET_AUDIO_COCOA} )
147142

148143
set( MACOS_SUBFOLDER "${CINDER_PATH}/lib/${CINDER_TARGET_SUBFOLDER}" )
149-
set( CINDER_STATIC_LIBS_DEPENDS "${MACOS_SUBFOLDER}/libboost_filesystem.a ${MACOS_SUBFOLDER}/libboost_system.a" )
150144

151145
if( NOT ( "Xcode" STREQUAL "${CMAKE_GENERATOR}" ) )
152146
if(NOT CMAKE_LIBTOOL)

0 commit comments

Comments
 (0)