|
| 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 | +} |
0 commit comments