├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── crude_json.cpp ├── crude_json.h ├── docs ├── CHANGELOG.txt ├── README.md └── TODO.md ├── examples ├── CMakeLists.txt ├── application │ ├── CMakeLists.txt │ ├── include │ │ └── application.h │ ├── source │ │ ├── application.cpp │ │ ├── config.h.in │ │ ├── entry_point.cpp │ │ ├── imgui_extra_keys.h │ │ ├── imgui_impl_dx11.cpp │ │ ├── imgui_impl_dx11.h │ │ ├── imgui_impl_glfw.cpp │ │ ├── imgui_impl_glfw.h │ │ ├── imgui_impl_opengl3.cpp │ │ ├── imgui_impl_opengl3.h │ │ ├── imgui_impl_opengl3_loader.h │ │ ├── imgui_impl_win32.cpp │ │ ├── imgui_impl_win32.h │ │ ├── platform.h │ │ ├── platform_glfw.cpp │ │ ├── platform_win32.cpp │ │ ├── renderer.h │ │ ├── renderer_dx11.cpp │ │ ├── renderer_ogl3.cpp │ │ └── setup.h │ └── support │ │ ├── Icon.icns │ │ ├── Icon.ico │ │ ├── Icon.png │ │ ├── Info.plist.in │ │ └── Resource.rc.in ├── basic-interaction-example │ ├── CMakeLists.txt │ └── basic-interaction-example.cpp ├── blueprints-example │ ├── CMakeLists.txt │ ├── blueprints-example.cpp │ ├── data │ │ ├── BlueprintBackground.png │ │ ├── ic_restore_white_24dp.png │ │ └── ic_save_white_24dp.png │ └── utilities │ │ ├── builders.cpp │ │ ├── builders.h │ │ ├── drawing.cpp │ │ ├── drawing.h │ │ ├── widgets.cpp │ │ └── widgets.h ├── canvas-example │ ├── CMakeLists.txt │ └── canvas-example.cpp ├── data │ ├── Cuprum-Bold.ttf │ ├── Cuprum-OFL.txt │ ├── Oswald-OFL.txt │ ├── Oswald-Regular.ttf │ ├── Play-OFL.txt │ └── Play-Regular.ttf ├── simple-example │ ├── CMakeLists.txt │ └── simple-example.cpp └── widgets-example │ ├── CMakeLists.txt │ └── widgets-example.cpp ├── external ├── DXSDK │ ├── include │ │ ├── D3DX11.h │ │ ├── D3DX11async.h │ │ ├── D3DX11core.h │ │ ├── D3DX11tex.h │ │ └── dxerr.h │ ├── lib │ │ ├── x64 │ │ │ ├── d3dx11.lib │ │ │ └── d3dx11d.lib │ │ └── x86 │ │ │ ├── d3dx11.lib │ │ │ └── d3dx11d.lib │ └── src │ │ └── dxerr.cpp ├── ScopeGuard │ ├── CMakeLists.txt │ └── ScopeGuard.h ├── imgui │ ├── CMakeLists.txt │ ├── LICENSE.txt │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui.natvis │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h └── stb_image │ ├── CMakeLists.txt │ └── stb_image.h ├── imgui_bezier_math.h ├── imgui_bezier_math.inl ├── imgui_canvas.cpp ├── imgui_canvas.h ├── imgui_extra_math.h ├── imgui_extra_math.inl ├── imgui_node_editor.cpp ├── imgui_node_editor.h ├── imgui_node_editor_api.cpp ├── imgui_node_editor_internal.h ├── imgui_node_editor_internal.inl └── misc ├── cmake-modules ├── FindScopeGuard.cmake ├── Findgl3w.cmake ├── Findimgui.cmake ├── Findimgui_node_editor.cmake └── Findstb_image.cmake ├── crude_json.natvis └── imgui_node_editor.natvis /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_run: 7 | # Use a workflow as a trigger of scheduled builds. Forked repositories can disable scheduled builds by disabling 8 | # "scheduled" workflow, while maintaining ability to perform local CI builds. 9 | workflows: 10 | - scheduled 11 | branches: 12 | - master 13 | - develop 14 | types: 15 | - requested 16 | 17 | env: 18 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 19 | BUILD_TYPE: Release 20 | 21 | jobs: 22 | Windows: 23 | runs-on: windows-2019 24 | env: 25 | VS_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\ 26 | MSBUILD_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ 27 | 28 | steps: 29 | - uses: actions/checkout@v2 30 | - name: Configure CMake 31 | run: cmake -S examples -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 32 | - name: Build 33 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 34 | 35 | macOS: 36 | runs-on: macos-latest 37 | 38 | steps: 39 | - name: Install Dependencies 40 | run: | 41 | brew install glfw3 42 | - uses: actions/checkout@v2 43 | - name: Configure CMake 44 | run: cmake -S examples -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 45 | - name: Build 46 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 47 | 48 | Linux: 49 | runs-on: ubuntu-latest 50 | 51 | steps: 52 | - name: Install Dependencies 53 | run: | 54 | sudo apt-get update 55 | sudo apt-get install -y libglfw3-dev 56 | - uses: actions/checkout@v2 57 | - name: Configure CMake 58 | run: cmake -S examples -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 59 | - name: Build 60 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 61 | 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | .vscode 3 | .build* 4 | .DS_Store 5 | bin 6 | [Bb]uild 7 | *.VC.db 8 | *.VC.opendb 9 | *.user 10 | *.ini 11 | *.json 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Michał Cichoń 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Node Editor in ImGui 2 | 3 | [![build](https://github.com/thedmd/imgui-node-editor/actions/workflows/build.yml/badge.svg)](https://github.com/thedmd/imgui-node-editor/actions/workflows/build.yml) 4 | 5 | ## About 6 | 7 | An implementation of node editor with ImGui-like API. 8 | 9 | Project purpose is to serve as a basis for more complex solutions like blueprint editors. 10 | 11 | ![node_editor_overview](https://user-images.githubusercontent.com/1197433/89328475-c01bc680-d68d-11ea-88bf-8c4155480927.gif) 12 | 13 | Node Editor is build around an idea "draw your content, we do the rest", which mean interactions are handled by editor, content rendering is handled by user. Editor will take care of: 14 | * placing your node in the word 15 | * dragging nodes 16 | * zoom and scrolling 17 | * selection 18 | * various interaction that can be queried by API (creation, deletion, selection changes, etc.) 19 | 20 | Here are some highlights: 21 | * Node movement and selection is handled internally 22 | * Node and pin contents are fully customizable 23 | * Fully styled, default theme is modeled after UE4 blueprints 24 | - Flexible enough to produce such nodes: 25 | 26 | ![image](https://user-images.githubusercontent.com/1197433/60381408-c3895b00-9a54-11e9-8312-d9fc9af63347.png) 27 | ![image](https://user-images.githubusercontent.com/1197433/60381400-a3599c00-9a54-11e9-9c51-a88f25f7db07.png) 28 | ![image](https://user-images.githubusercontent.com/1197433/60381589-7d81c680-9a57-11e9-87b1-9f73ec33bea4.png) 29 | - Customizable links based on Bézier curves: 30 | 31 | ![image](https://user-images.githubusercontent.com/1197433/60381475-ac973880-9a55-11e9-9ad9-5862975cd2b8.png) 32 | ![image](https://user-images.githubusercontent.com/1197433/60381467-9db08600-9a55-11e9-9868-2ae849f67de9.png) 33 | ![image](https://user-images.githubusercontent.com/1197433/60381488-cd5f8e00-9a55-11e9-8346-1f4c8d6bea22.png) 34 | * Automatic highlights for nodes, pins and links: 35 | 36 | ![image](https://user-images.githubusercontent.com/1197433/60381536-9e95e780-9a56-11e9-80bb-dad0d3d9557a.png) 37 | * Smooth navigation and selection 38 | * Node state can be saved in user context, so layout will not break 39 | * Selection rectangles and group dragging 40 | * Context menu support 41 | * Basic shortcuts support (cut/copy/paste/delete) 42 | * ImGui style API 43 | 44 | Editor is used to implement blueprint editor in Spark CE engine, it proved itself there by allowing to do everything we needed. Therefore it is now slowly moving into stable state from beeing a prototype. 45 | 46 | Note: Project recently was restructured to mimic ImGui layout. 47 | 48 | Please report issues or questions if something isn't clear. 49 | 50 | ## Dependencies 51 | 52 | * Vanilla ImGui 1.72+ 53 | * C++14 54 | 55 | ### Dependencies for examples: 56 | * https://github.com/thedmd/imgui/tree/feature/layout (used in blueprints sample only) 57 | 58 | ### Optional extension you can pull into your local copy of ImGui node editor can take advantage of: 59 | * ~~https://github.com/thedmd/imgui/tree/feature/draw-list-fringe-scale (for sharp rendering, while zooming)~~ It is part of ImGui since 1.80 release 60 | * https://github.com/thedmd/imgui/tree/feature/extra-keys (for extra shortcuts) 61 | 62 | ## Building / Installing 63 | 64 | Node Editor sources are located in root project directory. To use it, simply copy&paste sources into your project. Exactly like you can do with ImGui. 65 | 66 | ### Examples 67 | [Examples](../examples) can be build with CMake: 68 | ``` 69 | Windows: 70 | cmake -S examples -B build -G "Visual Studio 15 2017 Win64" 71 | or 72 | cmake -S examples -B build -G "Visual Studio 16 2019" -A x64 73 | 74 | macOS: 75 | cmake -S examples -B build -G "Xcode" 76 | 77 | Linux: 78 | cmake -S examples -B build -G "Unix Makefiles" 79 | 80 | Build: 81 | cmake --build build --config Release 82 | ``` 83 | Executables will be located in `build\bin` directory. 84 | 85 | ### Quick Start 86 | 87 | Main node editor header is located in [imgui_node_editor.h](../imgui_node_editor.h). 88 | 89 | Minimal example of one node can be found in [simple-example.cpp](../examples/simple-example/simple-example.cpp). 90 | Press 'F' in editor to focus on editor content if you see only grid. 91 | ```cpp 92 | # include 93 | # include 94 | # include 95 | 96 | namespace ed = ax::NodeEditor; 97 | 98 | struct Example: 99 | public Application 100 | { 101 | using Application::Application; 102 | 103 | void OnStart() override 104 | { 105 | ed::Config config; 106 | config.SettingsFile = "Simple.json"; 107 | m_Context = ed::CreateEditor(&config); 108 | } 109 | 110 | void OnStop() override 111 | { 112 | ed::DestroyEditor(m_Context); 113 | } 114 | 115 | void OnFrame(float deltaTime) override 116 | { 117 | auto& io = ImGui::GetIO(); 118 | 119 | ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f); 120 | 121 | ImGui::Separator(); 122 | 123 | ed::SetCurrentEditor(m_Context); 124 | ed::Begin("My Editor", ImVec2(0.0, 0.0f)); 125 | int uniqueId = 1; 126 | // Start drawing nodes. 127 | ed::BeginNode(uniqueId++); 128 | ImGui::Text("Node A"); 129 | ed::BeginPin(uniqueId++, ed::PinKind::Input); 130 | ImGui::Text("-> In"); 131 | ed::EndPin(); 132 | ImGui::SameLine(); 133 | ed::BeginPin(uniqueId++, ed::PinKind::Output); 134 | ImGui::Text("Out ->"); 135 | ed::EndPin(); 136 | ed::EndNode(); 137 | ed::End(); 138 | ed::SetCurrentEditor(nullptr); 139 | 140 | //ImGui::ShowMetricsWindow(); 141 | } 142 | 143 | ed::EditorContext* m_Context = nullptr; 144 | }; 145 | 146 | int Main(int argc, char** argv) 147 | { 148 | Example exampe("Simple", argc, argv); 149 | 150 | if (exampe.Create()) 151 | return exampe.Run(); 152 | 153 | return 0; 154 | } 155 | ``` 156 | 157 | Result: 158 | 159 | ![00-Simple](https://user-images.githubusercontent.com/1197433/89328516-cca01f00-d68d-11ea-9959-2da159851101.png) 160 | 161 | For more details please visit [examples](../examples) folder. 162 | 163 | ### Blueprints Example 164 | 165 | ![Preview2](https://user-images.githubusercontent.com/1197433/60053458-2f2b9b00-96d8-11e9-92f9-08aff63b2023.png) 166 | 167 | ### Here is Node Editor at work in Spark CE 168 | ![image](https://user-images.githubusercontent.com/1197433/60381756-174a7300-9a5a-11e9-9a04-00f10565e05e.png) 169 | ![image](https://user-images.githubusercontent.com/1197433/60381760-2f21f700-9a5a-11e9-9053-c0547a9cc40a.png) 170 | -------------------------------------------------------------------------------- /docs/TODO.md: -------------------------------------------------------------------------------- 1 | In random order: 2 | * Documentation: Make one 3 | 4 | Done: 5 | * ~~ImGui: Factor out changes to ImGui to use vanilla version.~~ 6 | * ~~Editor: Fix variable naming (mainly add `m_` prefix)~~ 7 | * ~~Editor: Split NodeEditorImpl.cpp to multiple files, file has grown too big.~~ 8 | * ~~Editor: Factor out use of `picojson.h`~~ 9 | * ~~Editor: Move use of `` to optional code extensions~~ 10 | 11 | 12 | 13 | 14 | #57 - join `ax::NodeEditor::EditorContext` with `struct EditorContext` and remove `reinterpret_cast<>` -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | project(imgui-node-editor) 4 | 5 | # Define IMGUI_NODE_EDITOR_ROOT_DIR pointing to project root directory 6 | get_filename_component(IMGUI_NODE_EDITOR_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE CACHE) 7 | 8 | # Enable solution folders in Visual Studio and Folders in Xcode 9 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 10 | 11 | # Point CMake where to look for module files. 12 | list(APPEND CMAKE_MODULE_PATH ${IMGUI_NODE_EDITOR_ROOT_DIR}/misc/cmake-modules) 13 | 14 | # Node editor use C++14 15 | set(CMAKE_CXX_STANDARD 14) 16 | set(CMAKE_CXX_STANDARD_REQUIRED YES) 17 | 18 | 19 | 20 | 21 | 22 | # Macro that will configure an example application 23 | macro(add_example_executable name) 24 | project(${name}) 25 | 26 | set(_Example_Sources 27 | ${ARGN} 28 | ) 29 | 30 | #source_group("" FILES ${_Example_Sources}) 31 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${_Example_Sources}) 32 | 33 | file(GLOB _Example_CommonResources CONFIGURE_DEPENDS "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data/*") 34 | file(GLOB _Example_Resources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/data/*") 35 | #message(FATAL_ERROR "_Example_Resources = ${_Example_Resources}") 36 | 37 | set(_Example_Type) 38 | if (WIN32) 39 | set(_Example_Type WIN32) 40 | 41 | set(ApplicationIcon ${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Icon.ico) 42 | file(TO_NATIVE_PATH "${ApplicationIcon}" ApplicationIcon) 43 | string(REPLACE "\\" "\\\\" ApplicationIcon "${ApplicationIcon}") 44 | configure_file( 45 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Resource.rc.in 46 | ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc 47 | ) 48 | source_group(TREE "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples" FILES ${_Example_CommonResources}) 49 | source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_Example_Resources}) 50 | list(APPEND _Example_Resources 51 | ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc 52 | ${_Example_CommonResources} 53 | ) 54 | source_group("resources" FILES ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc) 55 | elseif (APPLE) 56 | set(_Example_Type MACOSX_BUNDLE) 57 | 58 | set_source_files_properties(${_Example_Resources} ${_Example_CommonResources} PROPERTIES 59 | MACOSX_PACKAGE_LOCATION "Resources/data" 60 | ) 61 | set(_Example_Icon "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Icon.icns") 62 | list(APPEND _Example_Resources ${_Example_Icon}) 63 | set_source_files_properties(${_Example_Icon} PROPERTIES 64 | MACOSX_PACKAGE_LOCATION "Resources" 65 | ) 66 | endif() 67 | 68 | add_executable(${name} ${_Example_Type} ${_Example_Sources} ${_Example_Resources} ${_Example_CommonResources}) 69 | 70 | find_package(imgui REQUIRED) 71 | find_package(imgui_node_editor REQUIRED) 72 | target_link_libraries(${name} PRIVATE imgui imgui_node_editor application) 73 | 74 | set(_ExampleBinDir ${CMAKE_BINARY_DIR}/bin) 75 | 76 | set_target_properties(${name} PROPERTIES 77 | FOLDER "examples" 78 | RUNTIME_OUTPUT_DIRECTORY "${_ExampleBinDir}" 79 | RUNTIME_OUTPUT_DIRECTORY_DEBUG "${_ExampleBinDir}" 80 | RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${_ExampleBinDir}" 81 | RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${_ExampleBinDir}" 82 | RUNTIME_OUTPUT_DIRECTORY_RELEASE "${_ExampleBinDir}" 83 | DEBUG_POSTFIX _d 84 | RELWITHDEBINGO_POSTFIX _rd 85 | MINSIZEREL_POSTFIX _r 86 | VS_DEBUGGER_WORKING_DIRECTORY ${_ExampleBinDir} 87 | MACOSX_BUNDLE_INFO_PLIST "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Info.plist.in" 88 | MACOSX_BUNDLE_BUNDLE_NAME "${PACKAGE_NAME}" 89 | MACOSX_BUNDLE_GUI_IDENTIFIER "com.sandbox.collisions" 90 | MACOSX_BUNDLE_LONG_VERSION_STRING "${PACKAGE_VERSION}" 91 | MACOSX_BUNDLE_SHORT_VERSION_STRING "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}" 92 | MACOSX_BUNDLE_ICON_FILE Icon.icns 93 | ) 94 | 95 | add_custom_command( 96 | TARGET ${name} 97 | PRE_BUILD 98 | COMMAND ${CMAKE_COMMAND} -E make_directory ARGS ${_ExampleBinDir}/data 99 | ) 100 | 101 | set(_ResourceRoot ${CMAKE_CURRENT_SOURCE_DIR}) 102 | foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources}) 103 | if (_Resource STREQUAL ROOT) 104 | set(_ResourceRoot FALSE) 105 | continue() 106 | elseif(NOT _ResourceRoot) 107 | set(_ResourceRoot ${_Resource}) 108 | continue() 109 | endif() 110 | 111 | if ("${_Resource}" MATCHES "\.DS_Store$") 112 | list(REMOVE_ITEM _Example_Resources ${_Resource}) 113 | list(REMOVE_ITEM _Example_CommonResources ${_Resource}) 114 | continue() 115 | endif() 116 | 117 | file(RELATIVE_PATH _RelResource ${_ResourceRoot} ${_Resource}) 118 | 119 | add_custom_command( 120 | TARGET ${name} 121 | PRE_BUILD 122 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ARGS ${_Resource} ${_ExampleBinDir}/data/${_RelResource} 123 | ) 124 | endforeach() 125 | 126 | endmacro() 127 | 128 | add_subdirectory(application) 129 | 130 | add_subdirectory(canvas-example) 131 | add_subdirectory(simple-example) 132 | add_subdirectory(widgets-example) 133 | add_subdirectory(basic-interaction-example) 134 | add_subdirectory(blueprints-example) 135 | -------------------------------------------------------------------------------- /examples/application/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(application) 2 | 3 | set(_Application_Sources 4 | include/application.h 5 | source/application.cpp 6 | source/entry_point.cpp 7 | source/imgui_extra_keys.h 8 | source/config.h.in 9 | source/setup.h 10 | source/platform.h 11 | source/platform_win32.cpp 12 | source/platform_glfw.cpp 13 | source/renderer.h 14 | source/renderer_dx11.cpp 15 | source/renderer_ogl3.cpp 16 | ) 17 | 18 | add_library(application STATIC) 19 | 20 | target_include_directories(application PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 21 | 22 | find_package(imgui REQUIRED) 23 | find_package(stb_image REQUIRED) 24 | find_package(ScopeGuard REQUIRED) 25 | target_link_libraries(application PUBLIC imgui) 26 | target_link_libraries(application PRIVATE stb_image ScopeGuard) 27 | 28 | if (WIN32) 29 | list(APPEND _Application_Sources 30 | source/imgui_impl_dx11.cpp 31 | source/imgui_impl_dx11.h 32 | source/imgui_impl_win32.cpp 33 | source/imgui_impl_win32.h 34 | ) 35 | 36 | set(_DXSDK_Dir ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/DXSDK) 37 | set(_DXSDK_Arch x86) 38 | if (${CMAKE_SIZEOF_VOID_P} EQUAL 8) 39 | set(_DXSDK_Arch x64) 40 | endif() 41 | 42 | add_library(dxerr STATIC ${_DXSDK_Dir}/src/dxerr.cpp) 43 | target_include_directories(dxerr PUBLIC "${_DXSDK_Dir}/include") 44 | set_property(TARGET dxerr PROPERTY FOLDER "external") 45 | 46 | add_library(d3dx11 UNKNOWN IMPORTED) 47 | set_target_properties(d3dx11 PROPERTIES 48 | IMPORTED_LOCATION "${_DXSDK_Dir}/lib/${_DXSDK_Arch}/d3dx11.lib" 49 | IMPORTED_LOCATION_DEBUG "${_DXSDK_Dir}/lib/${_DXSDK_Arch}/d3dx11d.lib" 50 | INTERFACE_INCLUDE_DIRECTORIES "${_DXSDK_Dir}/include" 51 | INTERFACE_LINK_LIBRARIES "$<$:dxerr>" 52 | ) 53 | 54 | target_link_libraries(application PRIVATE d3d11.lib d3dcompiler.lib d3dx11) 55 | else() 56 | find_package(OpenGL REQUIRED) 57 | find_package(glfw3 3 REQUIRED) 58 | 59 | if (APPLE) 60 | target_link_libraries(application PRIVATE 61 | "-framework CoreFoundation" 62 | "-framework Cocoa" 63 | "-framework IOKit" 64 | "-framework CoreVideo" 65 | ) 66 | endif() 67 | endif() 68 | 69 | if (OpenGL_FOUND) 70 | set(HAVE_OPENGL YES) 71 | 72 | target_include_directories(application PRIVATE ${OPENGL_INCLUDE_DIR}) 73 | target_link_libraries(application PRIVATE ${OPENGL_gl_LIBRARY}) 74 | list(APPEND _Application_Sources 75 | source/imgui_impl_opengl3.cpp 76 | source/imgui_impl_opengl3.h 77 | source/imgui_impl_opengl3_loader.h 78 | ) 79 | endif() 80 | 81 | if (glfw3_FOUND) 82 | set(HAVE_GLFW3 YES) 83 | 84 | list(APPEND _Application_Sources 85 | source/imgui_impl_glfw.cpp 86 | source/imgui_impl_glfw.h 87 | ) 88 | target_link_libraries(application PRIVATE 89 | glfw 90 | ) 91 | endif() 92 | 93 | configure_file( 94 | source/config.h.in 95 | ${CMAKE_CURRENT_BINARY_DIR}/source/config.h 96 | ) 97 | 98 | target_compile_definitions(application PRIVATE 99 | #BACKEND_CONFIG=IMGUI_GLFW 100 | #RENDERER_CONFIG=IMGUI_OGL3 101 | ) 102 | 103 | target_include_directories(application PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/source) 104 | 105 | source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_Application_Sources}) 106 | 107 | target_sources(application PRIVATE ${_Application_Sources}) 108 | 109 | set_property(TARGET application PROPERTY FOLDER "examples") -------------------------------------------------------------------------------- /examples/application/include/application.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include 3 | # include 4 | # include 5 | 6 | struct Platform; 7 | struct Renderer; 8 | 9 | struct Application 10 | { 11 | Application(const char* name); 12 | Application(const char* name, int argc, char** argv); 13 | ~Application(); 14 | 15 | bool Create(int width = -1, int height = -1); 16 | 17 | int Run(); 18 | 19 | void SetTitle(const char* title); 20 | 21 | bool Close(); 22 | void Quit(); 23 | 24 | const std::string& GetName() const; 25 | 26 | ImFont* DefaultFont() const; 27 | ImFont* HeaderFont() const; 28 | 29 | ImTextureID LoadTexture(const char* path); 30 | ImTextureID CreateTexture(const void* data, int width, int height); 31 | void DestroyTexture(ImTextureID texture); 32 | int GetTextureWidth(ImTextureID texture); 33 | int GetTextureHeight(ImTextureID texture); 34 | 35 | virtual void OnStart() {} 36 | virtual void OnStop() {} 37 | virtual void OnFrame(float deltaTime) {} 38 | 39 | virtual ImGuiWindowFlags GetWindowFlags() const; 40 | 41 | virtual bool CanClose() { return true; } 42 | 43 | private: 44 | void RecreateFontAtlas(); 45 | 46 | void Frame(); 47 | 48 | std::string m_Name; 49 | std::string m_IniFilename; 50 | std::unique_ptr m_Platform; 51 | std::unique_ptr m_Renderer; 52 | ImGuiContext* m_Context = nullptr; 53 | ImFont* m_DefaultFont = nullptr; 54 | ImFont* m_HeaderFont = nullptr; 55 | }; 56 | 57 | int Main(int argc, char** argv); -------------------------------------------------------------------------------- /examples/application/source/application.cpp: -------------------------------------------------------------------------------- 1 | # include "application.h" 2 | # include "setup.h" 3 | # include "platform.h" 4 | # include "renderer.h" 5 | 6 | extern "C" { 7 | #define STB_IMAGE_IMPLEMENTATION 8 | #define STB_IMAGE_STATIC 9 | #include "stb_image.h" 10 | } 11 | 12 | 13 | Application::Application(const char* name) 14 | : Application(name, 0, nullptr) 15 | { 16 | } 17 | 18 | Application::Application(const char* name, int argc, char** argv) 19 | : m_Name(name) 20 | , m_Platform(CreatePlatform(*this)) 21 | , m_Renderer(CreateRenderer()) 22 | { 23 | m_Platform->ApplicationStart(argc, argv); 24 | } 25 | 26 | Application::~Application() 27 | { 28 | m_Renderer->Destroy(); 29 | 30 | m_Platform->ApplicationStop(); 31 | 32 | if (m_Context) 33 | { 34 | ImGui::DestroyContext(m_Context); 35 | m_Context= nullptr; 36 | } 37 | } 38 | 39 | bool Application::Create(int width /*= -1*/, int height /*= -1*/) 40 | { 41 | m_Context = ImGui::CreateContext(); 42 | ImGui::SetCurrentContext(m_Context); 43 | 44 | if (!m_Platform->OpenMainWindow("Application", width, height)) 45 | return false; 46 | 47 | if (!m_Renderer->Create(*m_Platform)) 48 | return false; 49 | 50 | m_IniFilename = m_Name + ".ini"; 51 | 52 | ImGuiIO& io = ImGui::GetIO(); 53 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 54 | io.IniFilename = m_IniFilename.c_str(); 55 | io.LogFilename = nullptr; 56 | 57 | ImGui::StyleColorsDark(); 58 | 59 | RecreateFontAtlas(); 60 | 61 | m_Platform->AcknowledgeWindowScaleChanged(); 62 | m_Platform->AcknowledgeFramebufferScaleChanged(); 63 | 64 | OnStart(); 65 | 66 | Frame(); 67 | 68 | return true; 69 | } 70 | 71 | int Application::Run() 72 | { 73 | m_Platform->ShowMainWindow(); 74 | 75 | while (m_Platform->ProcessMainWindowEvents()) 76 | { 77 | if (!m_Platform->IsMainWindowVisible()) 78 | continue; 79 | 80 | Frame(); 81 | } 82 | 83 | OnStop(); 84 | 85 | return 0; 86 | } 87 | 88 | void Application::RecreateFontAtlas() 89 | { 90 | ImGuiIO& io = ImGui::GetIO(); 91 | 92 | IM_DELETE(io.Fonts); 93 | 94 | io.Fonts = IM_NEW(ImFontAtlas); 95 | 96 | ImFontConfig config; 97 | config.OversampleH = 4; 98 | config.OversampleV = 4; 99 | config.PixelSnapH = false; 100 | 101 | m_DefaultFont = io.Fonts->AddFontFromFileTTF("data/Play-Regular.ttf", 18.0f, &config); 102 | m_HeaderFont = io.Fonts->AddFontFromFileTTF("data/Cuprum-Bold.ttf", 20.0f, &config); 103 | 104 | io.Fonts->Build(); 105 | } 106 | 107 | void Application::Frame() 108 | { 109 | auto& io = ImGui::GetIO(); 110 | 111 | if (m_Platform->HasWindowScaleChanged()) 112 | m_Platform->AcknowledgeWindowScaleChanged(); 113 | 114 | if (m_Platform->HasFramebufferScaleChanged()) 115 | { 116 | RecreateFontAtlas(); 117 | m_Platform->AcknowledgeFramebufferScaleChanged(); 118 | } 119 | 120 | const float windowScale = m_Platform->GetWindowScale(); 121 | const float framebufferScale = m_Platform->GetFramebufferScale(); 122 | 123 | if (io.WantSetMousePos) 124 | { 125 | io.MousePos.x *= windowScale; 126 | io.MousePos.y *= windowScale; 127 | } 128 | 129 | m_Platform->NewFrame(); 130 | 131 | // Don't touch "uninitialized" mouse position 132 | if (io.MousePos.x > -FLT_MAX && io.MousePos.y > -FLT_MAX) 133 | { 134 | io.MousePos.x /= windowScale; 135 | io.MousePos.y /= windowScale; 136 | } 137 | io.DisplaySize.x /= windowScale; 138 | io.DisplaySize.y /= windowScale; 139 | 140 | io.DisplayFramebufferScale.x = framebufferScale; 141 | io.DisplayFramebufferScale.y = framebufferScale; 142 | 143 | m_Renderer->NewFrame(); 144 | 145 | ImGui::NewFrame(); 146 | 147 | ImGui::SetNextWindowPos(ImVec2(0, 0)); 148 | ImGui::SetNextWindowSize(io.DisplaySize); 149 | const auto windowBorderSize = ImGui::GetStyle().WindowBorderSize; 150 | const auto windowRounding = ImGui::GetStyle().WindowRounding; 151 | ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); 152 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); 153 | ImGui::Begin("Content", nullptr, GetWindowFlags()); 154 | ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, windowBorderSize); 155 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, windowRounding); 156 | 157 | OnFrame(io.DeltaTime); 158 | 159 | ImGui::PopStyleVar(2); 160 | ImGui::End(); 161 | ImGui::PopStyleVar(2); 162 | 163 | // Rendering 164 | m_Renderer->Clear(ImColor(32, 32, 32, 255)); 165 | ImGui::Render(); 166 | m_Renderer->RenderDrawData(ImGui::GetDrawData()); 167 | 168 | m_Platform->FinishFrame(); 169 | } 170 | 171 | void Application::SetTitle(const char* title) 172 | { 173 | m_Platform->SetMainWindowTitle(title); 174 | } 175 | 176 | bool Application::Close() 177 | { 178 | return m_Platform->CloseMainWindow(); 179 | } 180 | 181 | void Application::Quit() 182 | { 183 | m_Platform->Quit(); 184 | } 185 | 186 | const std::string& Application::GetName() const 187 | { 188 | return m_Name; 189 | } 190 | 191 | ImFont* Application::DefaultFont() const 192 | { 193 | return m_DefaultFont; 194 | } 195 | 196 | ImFont* Application::HeaderFont() const 197 | { 198 | return m_HeaderFont; 199 | } 200 | 201 | ImTextureID Application::LoadTexture(const char* path) 202 | { 203 | int width = 0, height = 0, component = 0; 204 | if (auto data = stbi_load(path, &width, &height, &component, 4)) 205 | { 206 | auto texture = CreateTexture(data, width, height); 207 | stbi_image_free(data); 208 | return texture; 209 | } 210 | else 211 | return nullptr; 212 | } 213 | 214 | ImTextureID Application::CreateTexture(const void* data, int width, int height) 215 | { 216 | return m_Renderer->CreateTexture(data, width, height); 217 | } 218 | 219 | void Application::DestroyTexture(ImTextureID texture) 220 | { 221 | m_Renderer->DestroyTexture(texture); 222 | } 223 | 224 | int Application::GetTextureWidth(ImTextureID texture) 225 | { 226 | return m_Renderer->GetTextureWidth(texture); 227 | } 228 | 229 | int Application::GetTextureHeight(ImTextureID texture) 230 | { 231 | return m_Renderer->GetTextureHeight(texture); 232 | } 233 | 234 | ImGuiWindowFlags Application::GetWindowFlags() const 235 | { 236 | return 237 | ImGuiWindowFlags_NoTitleBar | 238 | ImGuiWindowFlags_NoResize | 239 | ImGuiWindowFlags_NoMove | 240 | ImGuiWindowFlags_NoScrollbar | 241 | ImGuiWindowFlags_NoScrollWithMouse | 242 | ImGuiWindowFlags_NoSavedSettings | 243 | ImGuiWindowFlags_NoBringToFrontOnFocus; 244 | } 245 | -------------------------------------------------------------------------------- /examples/application/source/config.h.in: -------------------------------------------------------------------------------- 1 | # pragma once 2 | 3 | # cmakedefine01 HAVE_GLFW3 4 | # cmakedefine01 HAVE_OPENGL -------------------------------------------------------------------------------- /examples/application/source/entry_point.cpp: -------------------------------------------------------------------------------- 1 | # include "application.h" 2 | # include "platform.h" 3 | 4 | # if PLATFORM(WINDOWS) 5 | # define NOMINMAX 6 | # define WIN32_LEAN_AND_MEAN 7 | # include 8 | # include // __argc, argv 9 | # endif 10 | 11 | # if defined(_WIN32) && !defined(_CONSOLE) 12 | int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) 13 | { 14 | return Main(__argc, __argv); 15 | } 16 | # else 17 | int main(int argc, char** argv) 18 | { 19 | return Main(argc, argv); 20 | } 21 | # endif 22 | -------------------------------------------------------------------------------- /examples/application/source/imgui_extra_keys.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include 3 | 4 | # if !defined(IMGUI_VERSION_NUM) || (IMGUI_VERSION_NUM < 18822) 5 | 6 | # include 7 | 8 | // https://stackoverflow.com/a/8597498 9 | # define DECLARE_HAS_NESTED(Name, Member) \ 10 | \ 11 | template \ 12 | struct has_nested_ ## Name \ 13 | { \ 14 | typedef char yes; \ 15 | typedef yes(&no)[2]; \ 16 | \ 17 | template static yes test(decltype(U::Member)*); \ 18 | template static no test(...); \ 19 | \ 20 | static bool const value = sizeof(test(0)) == sizeof(yes); \ 21 | }; 22 | 23 | # define DECLARE_KEY_TESTER(Key) \ 24 | DECLARE_HAS_NESTED(Key, Key) \ 25 | struct KeyTester_ ## Key \ 26 | { \ 27 | template \ 28 | static int Get(typename std::enable_if::value, T>::type*) \ 29 | { \ 30 | return T::Key; \ 31 | } \ 32 | \ 33 | template \ 34 | static int Get(typename std::enable_if::value, T>::type*) \ 35 | { \ 36 | return -1; \ 37 | } \ 38 | } 39 | 40 | DECLARE_KEY_TESTER(ImGuiKey_F); 41 | DECLARE_KEY_TESTER(ImGuiKey_D); 42 | 43 | static inline int GetEnumValueForF() 44 | { 45 | return KeyTester_ImGuiKey_F::Get(nullptr); 46 | } 47 | 48 | static inline int GetEnumValueForD() 49 | { 50 | return KeyTester_ImGuiKey_D::Get(nullptr); 51 | } 52 | 53 | # else 54 | 55 | static inline ImGuiKey GetEnumValueForF() 56 | { 57 | return ImGuiKey_F; 58 | } 59 | 60 | static inline ImGuiKey GetEnumValueForD() 61 | { 62 | return ImGuiKey_D; 63 | } 64 | 65 | # endif -------------------------------------------------------------------------------- /examples/application/source/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for DirectX11 2 | // This needs to be used along with a Platform Binding (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 6 | 7 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 8 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 9 | // https://github.com/ocornut/imgui 10 | 11 | #pragma once 12 | 13 | struct ID3D11Device; 14 | struct ID3D11DeviceContext; 15 | 16 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 17 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 18 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 19 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 20 | 21 | // Use if you want to reset your rendering device without losing ImGui state. 22 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 23 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 24 | 25 | IMGUI_IMPL_API ImTextureID ImGui_LoadTexture(const char* path); 26 | IMGUI_IMPL_API ImTextureID ImGui_CreateTexture(const void* data, int width, int height); 27 | IMGUI_IMPL_API void ImGui_DestroyTexture(ImTextureID texture); 28 | IMGUI_IMPL_API int ImGui_GetTextureWidth(ImTextureID texture); 29 | IMGUI_IMPL_API int ImGui_GetTextureHeight(ImTextureID texture); 30 | -------------------------------------------------------------------------------- /examples/application/source/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. 9 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 10 | 11 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 12 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 13 | // https://github.com/ocornut/imgui 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 17 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 18 | 19 | #pragma once 20 | #include "imgui.h" // IMGUI_IMPL_API 21 | 22 | struct GLFWwindow; 23 | 24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForNone(GLFWwindow* window, bool install_callbacks); 25 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 26 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 27 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 28 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 29 | 30 | // GLFW callbacks 31 | // - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any. 32 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks. 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 36 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 37 | -------------------------------------------------------------------------------- /examples/application/source/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline 2 | // - Desktop GL: 2.x 3.x 4.x 3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) 4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 5 | 6 | // Implemented features: 7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 8 | // [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). 9 | 10 | // About WebGL/ES: 11 | // - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. 12 | // - This is done automatically on iOS, Android and Emscripten targets. 13 | // - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h. 14 | 15 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 16 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 17 | // Learn about Dear ImGui: 18 | // - FAQ https://dearimgui.com/faq 19 | // - Getting Started https://dearimgui.com/getting-started 20 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 21 | // - Introduction, links and more at the top of imgui.cpp 22 | 23 | // About GLSL version: 24 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. 25 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 26 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 27 | 28 | #pragma once 29 | #include "imgui.h" // IMGUI_IMPL_API 30 | #ifndef IMGUI_DISABLE 31 | 32 | // Backend API 33 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); 34 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 35 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 36 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 37 | 38 | // (Optional) Called by Init/NewFrame/Shutdown 39 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 40 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 41 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 42 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 43 | 44 | // Specific OpenGL ES versions 45 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 46 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 47 | 48 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. 49 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 50 | && !defined(IMGUI_IMPL_OPENGL_ES3) 51 | 52 | // Try to detect GLES on matching platforms 53 | #if defined(__APPLE__) 54 | #include 55 | #endif 56 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 57 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 58 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 59 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 60 | #else 61 | // Otherwise imgui_impl_opengl3_loader.h will be used. 62 | #endif 63 | 64 | #endif 65 | 66 | #endif // #ifndef IMGUI_DISABLE 67 | -------------------------------------------------------------------------------- /examples/application/source/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | 10 | #pragma once 11 | #include "imgui.h" // IMGUI_IMPL_API 12 | 13 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 14 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 15 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 16 | 17 | // Configuration 18 | // - Disable gamepad support or linking with xinput.lib 19 | //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 20 | //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT 21 | 22 | // Win32 message handler your application need to call. 23 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 24 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 25 | #if 0 26 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 27 | #endif 28 | 29 | // DPI-related helpers (optional) 30 | // - Use to enable DPI awareness without having to create an application manifest. 31 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 32 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 33 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 34 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 35 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 36 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 37 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 38 | -------------------------------------------------------------------------------- /examples/application/source/platform.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include "setup.h" 3 | # include 4 | 5 | struct Application; 6 | struct Renderer; 7 | 8 | struct Platform 9 | { 10 | virtual ~Platform() {}; 11 | 12 | virtual bool ApplicationStart(int argc, char** argv) = 0; 13 | virtual void ApplicationStop() = 0; 14 | 15 | virtual bool OpenMainWindow(const char* title, int width, int height) = 0; 16 | virtual bool CloseMainWindow() = 0; 17 | virtual void* GetMainWindowHandle() const = 0; 18 | virtual void SetMainWindowTitle(const char* title) = 0; 19 | virtual void ShowMainWindow() = 0; 20 | virtual bool ProcessMainWindowEvents() = 0; 21 | virtual bool IsMainWindowVisible() const = 0; 22 | 23 | virtual void SetRenderer(Renderer* renderer) = 0; 24 | 25 | virtual void NewFrame() = 0; 26 | virtual void FinishFrame() = 0; 27 | 28 | virtual void Quit() = 0; 29 | 30 | bool HasWindowScaleChanged() const { return m_WindowScaleChanged; } 31 | void AcknowledgeWindowScaleChanged() { m_WindowScaleChanged = false; } 32 | float GetWindowScale() const { return m_WindowScale; } 33 | void SetWindowScale(float windowScale) 34 | { 35 | if (windowScale == m_WindowScale) 36 | return; 37 | m_WindowScale = windowScale; 38 | m_WindowScaleChanged = true; 39 | } 40 | 41 | bool HasFramebufferScaleChanged() const { return m_FramebufferScaleChanged; } 42 | void AcknowledgeFramebufferScaleChanged() { m_FramebufferScaleChanged = false; } 43 | float GetFramebufferScale() const { return m_FramebufferScale; } 44 | void SetFramebufferScale(float framebufferScale) 45 | { 46 | if (framebufferScale == m_FramebufferScale) 47 | return; 48 | m_FramebufferScale = framebufferScale; 49 | m_FramebufferScaleChanged = true; 50 | } 51 | 52 | 53 | private: 54 | bool m_WindowScaleChanged = false; 55 | float m_WindowScale = 1.0f; 56 | bool m_FramebufferScaleChanged = false; 57 | float m_FramebufferScale = 1.0f; 58 | }; 59 | 60 | std::unique_ptr CreatePlatform(Application& application); 61 | -------------------------------------------------------------------------------- /examples/application/source/platform_glfw.cpp: -------------------------------------------------------------------------------- 1 | # include "platform.h" 2 | # include "setup.h" 3 | 4 | # if BACKEND(IMGUI_GLFW) 5 | 6 | # include "application.h" 7 | # include "renderer.h" 8 | 9 | # include 10 | 11 | # if PLATFORM(WINDOWS) 12 | # define GLFW_EXPOSE_NATIVE_WIN32 13 | # include 14 | # endif 15 | 16 | # include 17 | # include "imgui_impl_glfw.h" 18 | 19 | struct PlatformGLFW final 20 | : Platform 21 | { 22 | static PlatformGLFW* s_Instance; 23 | 24 | PlatformGLFW(Application& application); 25 | 26 | bool ApplicationStart(int argc, char** argv) override; 27 | void ApplicationStop() override; 28 | bool OpenMainWindow(const char* title, int width, int height) override; 29 | bool CloseMainWindow() override; 30 | void* GetMainWindowHandle() const override; 31 | void SetMainWindowTitle(const char* title) override; 32 | void ShowMainWindow() override; 33 | bool ProcessMainWindowEvents() override; 34 | bool IsMainWindowVisible() const override; 35 | void SetRenderer(Renderer* renderer) override; 36 | void NewFrame() override; 37 | void FinishFrame() override; 38 | void Quit() override; 39 | 40 | void UpdatePixelDensity(); 41 | 42 | Application& m_Application; 43 | GLFWwindow* m_Window = nullptr; 44 | bool m_QuitRequested = false; 45 | bool m_IsMinimized = false; 46 | bool m_WasMinimized = false; 47 | Renderer* m_Renderer = nullptr; 48 | }; 49 | 50 | std::unique_ptr CreatePlatform(Application& application) 51 | { 52 | return std::make_unique(application); 53 | } 54 | 55 | PlatformGLFW::PlatformGLFW(Application& application) 56 | : m_Application(application) 57 | { 58 | } 59 | 60 | bool PlatformGLFW::ApplicationStart(int argc, char** argv) 61 | { 62 | if (!glfwInit()) 63 | return false; 64 | 65 | return true; 66 | } 67 | 68 | void PlatformGLFW::ApplicationStop() 69 | { 70 | glfwTerminate(); 71 | } 72 | 73 | bool PlatformGLFW::OpenMainWindow(const char* title, int width, int height) 74 | { 75 | if (m_Window) 76 | return false; 77 | 78 | glfwWindowHint(GLFW_VISIBLE, 0); 79 | 80 | using InitializerType = bool (*)(GLFWwindow* window, bool install_callbacks); 81 | 82 | InitializerType initializer = nullptr; 83 | 84 | # if RENDERER(IMGUI_OGL3) 85 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 86 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 87 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 88 | # if PLATFORM(MACOS) 89 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 90 | # ifdef GLFW_COCOA_RETINA_FRAMEBUFFER 91 | glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GL_TRUE); 92 | # endif 93 | # ifdef GLFW_COCOA_GRAPHICS_SWITCHING 94 | glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, GL_TRUE); 95 | # endif 96 | # endif 97 | initializer = &ImGui_ImplGlfw_InitForOpenGL; 98 | # else 99 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 100 | initializer = &ImGui_ImplGlfw_InitForNone; 101 | # endif 102 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GL_TRUE); 103 | 104 | width = width < 0 ? 1440 : width; 105 | height = height < 0 ? 800 : height; 106 | 107 | m_Window = glfwCreateWindow(width, height, title, nullptr, nullptr); 108 | if (!m_Window) 109 | return false; 110 | 111 | if (!initializer || !initializer(m_Window, true)) 112 | { 113 | glfwDestroyWindow(m_Window); 114 | m_Window = nullptr; 115 | return false; 116 | } 117 | 118 | glfwSetWindowUserPointer(m_Window, this); 119 | 120 | glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window) 121 | { 122 | auto self = reinterpret_cast(glfwGetWindowUserPointer(window)); 123 | if (!self->m_QuitRequested) 124 | self->CloseMainWindow(); 125 | }); 126 | 127 | glfwSetWindowIconifyCallback(m_Window, [](GLFWwindow* window, int iconified) 128 | { 129 | auto self = reinterpret_cast(glfwGetWindowUserPointer(window)); 130 | if (iconified) 131 | { 132 | self->m_IsMinimized = true; 133 | self->m_WasMinimized = true; 134 | } 135 | else 136 | { 137 | self->m_IsMinimized = false; 138 | } 139 | }); 140 | 141 | auto onFramebuferSizeChanged = [](GLFWwindow* window, int width, int height) 142 | { 143 | auto self = reinterpret_cast(glfwGetWindowUserPointer(window)); 144 | if (self->m_Renderer) 145 | { 146 | self->m_Renderer->Resize(width, height); 147 | self->UpdatePixelDensity(); 148 | } 149 | }; 150 | 151 | glfwSetFramebufferSizeCallback(m_Window, onFramebuferSizeChanged); 152 | 153 | auto onWindowContentScaleChanged = [](GLFWwindow* window, float xscale, float yscale) 154 | { 155 | auto self = reinterpret_cast(glfwGetWindowUserPointer(window)); 156 | self->UpdatePixelDensity(); 157 | }; 158 | 159 | glfwSetWindowContentScaleCallback(m_Window, onWindowContentScaleChanged); 160 | 161 | UpdatePixelDensity(); 162 | 163 | glfwMakeContextCurrent(m_Window); 164 | 165 | glfwSwapInterval(1); // Enable vsync 166 | 167 | return true; 168 | } 169 | 170 | bool PlatformGLFW::CloseMainWindow() 171 | { 172 | if (m_Window == nullptr) 173 | return true; 174 | 175 | auto canClose = m_Application.CanClose(); 176 | 177 | glfwSetWindowShouldClose(m_Window, canClose ? 1 : 0); 178 | 179 | return canClose; 180 | } 181 | 182 | void* PlatformGLFW::GetMainWindowHandle() const 183 | { 184 | # if PLATFORM(WINDOWS) 185 | return m_Window ? glfwGetWin32Window(m_Window) : nullptr; 186 | # else 187 | return nullptr; 188 | # endif 189 | } 190 | 191 | void PlatformGLFW::SetMainWindowTitle(const char* title) 192 | { 193 | glfwSetWindowTitle(m_Window, title); 194 | } 195 | 196 | void PlatformGLFW::ShowMainWindow() 197 | { 198 | if (m_Window == nullptr) 199 | return; 200 | 201 | glfwShowWindow(m_Window); 202 | } 203 | 204 | bool PlatformGLFW::ProcessMainWindowEvents() 205 | { 206 | if (m_Window == nullptr) 207 | return false; 208 | 209 | if (m_IsMinimized) 210 | glfwWaitEvents(); 211 | else 212 | glfwPollEvents(); 213 | 214 | if (m_QuitRequested || glfwWindowShouldClose(m_Window)) 215 | { 216 | ImGui_ImplGlfw_Shutdown(); 217 | 218 | glfwDestroyWindow(m_Window); 219 | 220 | return false; 221 | } 222 | 223 | return true; 224 | } 225 | 226 | bool PlatformGLFW::IsMainWindowVisible() const 227 | { 228 | if (m_Window == nullptr) 229 | return false; 230 | 231 | if (m_IsMinimized) 232 | return false; 233 | 234 | return true; 235 | } 236 | 237 | void PlatformGLFW::SetRenderer(Renderer* renderer) 238 | { 239 | m_Renderer = renderer; 240 | } 241 | 242 | void PlatformGLFW::NewFrame() 243 | { 244 | ImGui_ImplGlfw_NewFrame(); 245 | 246 | if (m_WasMinimized) 247 | { 248 | ImGui::GetIO().DeltaTime = 0.1e-6f; 249 | m_WasMinimized = false; 250 | } 251 | } 252 | 253 | void PlatformGLFW::FinishFrame() 254 | { 255 | if (m_Renderer) 256 | m_Renderer->Present(); 257 | 258 | glfwSwapBuffers(m_Window); 259 | } 260 | 261 | void PlatformGLFW::Quit() 262 | { 263 | m_QuitRequested = true; 264 | 265 | glfwPostEmptyEvent(); 266 | } 267 | 268 | void PlatformGLFW::UpdatePixelDensity() 269 | { 270 | float xscale, yscale; 271 | glfwGetWindowContentScale(m_Window, &xscale, &yscale); 272 | float scale = xscale > yscale ? xscale : yscale; 273 | 274 | # if PLATFORM(WINDOWS) 275 | float windowScale = scale; 276 | float framebufferScale = scale; 277 | # else 278 | float windowScale = 1.0f; 279 | float framebufferScale = scale; 280 | # endif 281 | 282 | SetWindowScale(windowScale); // this is how windows is scaled, not window content 283 | 284 | SetFramebufferScale(framebufferScale); 285 | } 286 | 287 | # endif // BACKEND(IMGUI_GLFW) -------------------------------------------------------------------------------- /examples/application/source/platform_win32.cpp: -------------------------------------------------------------------------------- 1 | # include "platform.h" 2 | # include "setup.h" 3 | 4 | # if BACKEND(IMGUI_WIN32) 5 | 6 | # include "application.h" 7 | # include "renderer.h" 8 | 9 | # define NOMINMAX 10 | # define WIN32_LEAN_AND_MEAN 11 | # include 12 | # include 13 | # include 14 | 15 | # include 16 | # include "imgui_impl_win32.h" 17 | 18 | # if defined(_UNICODE) 19 | std::wstring Utf8ToNative(const std::string& str) 20 | { 21 | int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), nullptr, 0); 22 | std::wstring result(size, 0); 23 | MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), (wchar_t*)result.data(), size); 24 | return result; 25 | } 26 | # else 27 | std::string Utf8ToNative(const std::string& str) 28 | { 29 | return str; 30 | } 31 | # endif 32 | 33 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 34 | 35 | struct PlatformWin32 final 36 | : Platform 37 | { 38 | static PlatformWin32* s_Instance; 39 | 40 | PlatformWin32(Application& application); 41 | 42 | bool ApplicationStart(int argc, char** argv) override; 43 | void ApplicationStop() override; 44 | bool OpenMainWindow(const char* title, int width, int height) override; 45 | bool CloseMainWindow() override; 46 | void* GetMainWindowHandle() const override; 47 | void SetMainWindowTitle(const char* title) override; 48 | void ShowMainWindow() override; 49 | bool ProcessMainWindowEvents() override; 50 | bool IsMainWindowVisible() const override; 51 | void SetRenderer(Renderer* renderer) override; 52 | void NewFrame() override; 53 | void FinishFrame() override; 54 | void Quit() override; 55 | 56 | void SetDpiScale(float dpiScale); 57 | 58 | LRESULT WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 59 | 60 | Application& m_Application; 61 | WNDCLASSEX m_WindowClass = {}; 62 | HWND m_MainWindowHandle = nullptr; 63 | bool m_IsMinimized = false; 64 | bool m_WasMinimized = false; 65 | bool m_CanCloseResult = false; 66 | Renderer* m_Renderer = nullptr; 67 | }; 68 | 69 | std::unique_ptr CreatePlatform(Application& application) 70 | { 71 | return std::make_unique(application); 72 | } 73 | 74 | PlatformWin32* PlatformWin32::s_Instance = nullptr; 75 | 76 | PlatformWin32::PlatformWin32(Application& application) 77 | : m_Application(application) 78 | { 79 | } 80 | 81 | bool PlatformWin32::ApplicationStart(int argc, char** argv) 82 | { 83 | if (s_Instance) 84 | return false; 85 | 86 | s_Instance = this; 87 | 88 | auto winProc = [](HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -> LRESULT 89 | { 90 | return s_Instance->WinProc(hWnd, msg, wParam, lParam); 91 | }; 92 | 93 | m_WindowClass = 94 | { 95 | sizeof(WNDCLASSEX), 96 | CS_CLASSDC, 97 | winProc, 98 | 0L, 99 | 0L, 100 | GetModuleHandle(nullptr), 101 | LoadIcon(GetModuleHandle(nullptr), 102 | IDI_APPLICATION), 103 | LoadCursor(nullptr, IDC_ARROW), 104 | nullptr, 105 | nullptr, 106 | _T("imgui-node-editor-application"), 107 | LoadIcon(GetModuleHandle(nullptr), 108 | IDI_APPLICATION) 109 | }; 110 | 111 | if (!RegisterClassEx(&m_WindowClass)) 112 | { 113 | s_Instance = nullptr; 114 | return false; 115 | } 116 | 117 | ImGui_ImplWin32_EnableDpiAwareness(); 118 | 119 | return true; 120 | } 121 | 122 | void PlatformWin32::ApplicationStop() 123 | { 124 | if (!s_Instance) 125 | return; 126 | 127 | UnregisterClass(m_WindowClass.lpszClassName, m_WindowClass.hInstance); 128 | 129 | s_Instance = nullptr; 130 | } 131 | 132 | 133 | bool PlatformWin32::OpenMainWindow(const char* title, int width, int height) 134 | { 135 | if (m_MainWindowHandle) 136 | return false; 137 | 138 | m_MainWindowHandle = CreateWindow( 139 | m_WindowClass.lpszClassName, 140 | Utf8ToNative(title).c_str(), 141 | WS_OVERLAPPEDWINDOW, 142 | CW_USEDEFAULT, CW_USEDEFAULT, 143 | width < 0 ? CW_USEDEFAULT : width, 144 | height < 0 ? CW_USEDEFAULT : height, 145 | nullptr, nullptr, m_WindowClass.hInstance, nullptr); 146 | 147 | if (!m_MainWindowHandle) 148 | return false; 149 | 150 | if (!ImGui_ImplWin32_Init(m_MainWindowHandle)) 151 | { 152 | DestroyWindow(m_MainWindowHandle); 153 | m_MainWindowHandle = nullptr; 154 | return false; 155 | } 156 | 157 | SetDpiScale(ImGui_ImplWin32_GetDpiScaleForHwnd(m_MainWindowHandle)); 158 | 159 | return true; 160 | } 161 | 162 | bool PlatformWin32::CloseMainWindow() 163 | { 164 | if (m_MainWindowHandle == nullptr) 165 | return true; 166 | 167 | SendMessage(m_MainWindowHandle, WM_CLOSE, 0, 0); 168 | 169 | return m_CanCloseResult; 170 | } 171 | 172 | void* PlatformWin32::GetMainWindowHandle() const 173 | { 174 | return m_MainWindowHandle; 175 | } 176 | 177 | void PlatformWin32::SetMainWindowTitle(const char* title) 178 | { 179 | SetWindowText(m_MainWindowHandle, Utf8ToNative(title).c_str()); 180 | } 181 | 182 | void PlatformWin32::ShowMainWindow() 183 | { 184 | if (m_MainWindowHandle == nullptr) 185 | return; 186 | 187 | //ShowWindow(m_MainWindowHandle, SW_SHOWMAXIMIZED); 188 | ShowWindow(m_MainWindowHandle, SW_SHOW); 189 | UpdateWindow(m_MainWindowHandle); 190 | } 191 | 192 | bool PlatformWin32::ProcessMainWindowEvents() 193 | { 194 | if (m_MainWindowHandle == nullptr) 195 | return false; 196 | 197 | auto fetchMessage = [this](MSG* msg) -> bool 198 | { 199 | if (!m_IsMinimized) 200 | return PeekMessage(msg, nullptr, 0U, 0U, PM_REMOVE) != 0; 201 | else 202 | return GetMessage(msg, nullptr, 0U, 0U) != 0; 203 | }; 204 | 205 | MSG msg = {}; 206 | while (fetchMessage(&msg)) 207 | { 208 | if (msg.message == WM_KEYDOWN && (msg.wParam == VK_ESCAPE)) 209 | PostQuitMessage(0); 210 | 211 | if (msg.message == WM_QUIT) 212 | return false; 213 | 214 | TranslateMessage(&msg); 215 | DispatchMessage(&msg); 216 | } 217 | 218 | return true; 219 | } 220 | 221 | bool PlatformWin32::IsMainWindowVisible() const 222 | { 223 | if (m_MainWindowHandle == nullptr) 224 | return false; 225 | 226 | if (m_IsMinimized) 227 | return false; 228 | 229 | return true; 230 | } 231 | 232 | void PlatformWin32::SetRenderer(Renderer* renderer) 233 | { 234 | m_Renderer = renderer; 235 | } 236 | 237 | void PlatformWin32::NewFrame() 238 | { 239 | ImGui_ImplWin32_NewFrame(); 240 | 241 | if (m_WasMinimized) 242 | { 243 | ImGui::GetIO().DeltaTime = 0.1e-6f; 244 | m_WasMinimized = false; 245 | } 246 | } 247 | 248 | void PlatformWin32::FinishFrame() 249 | { 250 | if (m_Renderer) 251 | m_Renderer->Present(); 252 | } 253 | 254 | void PlatformWin32::Quit() 255 | { 256 | PostQuitMessage(0); 257 | } 258 | 259 | void PlatformWin32::SetDpiScale(float dpiScale) 260 | { 261 | SetWindowScale(dpiScale); 262 | SetFramebufferScale(dpiScale); 263 | } 264 | 265 | LRESULT PlatformWin32::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 266 | { 267 | if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) 268 | return 1; 269 | 270 | switch (msg) 271 | { 272 | case WM_CLOSE: 273 | m_CanCloseResult = m_Application.CanClose(); 274 | if (m_CanCloseResult) 275 | { 276 | ImGui_ImplWin32_Shutdown(); 277 | DestroyWindow(hWnd); 278 | } 279 | return 0; 280 | 281 | case WM_SIZE: 282 | if (wParam == SIZE_MINIMIZED) 283 | { 284 | m_IsMinimized = true; 285 | m_WasMinimized = true; 286 | } 287 | else if (wParam == SIZE_RESTORED && m_IsMinimized) 288 | { 289 | m_IsMinimized = false; 290 | } 291 | 292 | if (m_Renderer != nullptr && wParam != SIZE_MINIMIZED) 293 | m_Renderer->Resize(static_cast(LOWORD(lParam)), static_cast(HIWORD(lParam))); 294 | return 0; 295 | 296 | case WM_SYSCOMMAND: 297 | if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu 298 | return 0; 299 | break; 300 | 301 | case WM_DPICHANGED: 302 | SetDpiScale(ImGui_ImplWin32_GetDpiScaleForHwnd(hWnd)); 303 | return 0; 304 | 305 | case WM_DESTROY: 306 | PostQuitMessage(0); 307 | return 0; 308 | } 309 | 310 | return DefWindowProc(hWnd, msg, wParam, lParam); 311 | } 312 | 313 | # endif // BACKEND(IMGUI_WIN32) -------------------------------------------------------------------------------- /examples/application/source/renderer.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include "setup.h" 3 | # include 4 | 5 | struct Platform; 6 | struct ImDrawData; 7 | struct ImVec4; 8 | using ImTextureID= void*; 9 | 10 | struct Renderer 11 | { 12 | virtual ~Renderer() {}; 13 | 14 | virtual bool Create(Platform& platform) = 0; 15 | virtual void Destroy() = 0; 16 | 17 | virtual void NewFrame() = 0; 18 | 19 | virtual void RenderDrawData(ImDrawData* drawData) = 0; 20 | 21 | virtual void Clear(const ImVec4& color) = 0; 22 | virtual void Present() = 0; 23 | 24 | virtual void Resize(int width, int height) = 0; 25 | 26 | virtual ImTextureID CreateTexture(const void* data, int width, int height) = 0; 27 | virtual void DestroyTexture(ImTextureID texture) = 0; 28 | virtual int GetTextureWidth(ImTextureID texture) = 0; 29 | virtual int GetTextureHeight(ImTextureID texture) = 0; 30 | }; 31 | 32 | std::unique_ptr CreateRenderer(); 33 | -------------------------------------------------------------------------------- /examples/application/source/renderer_dx11.cpp: -------------------------------------------------------------------------------- 1 | # include "renderer.h" 2 | # include "setup.h" 3 | 4 | # if RENDERER(IMGUI_DX11) 5 | 6 | # include "platform.h" 7 | 8 | # if PLATFORM(WINDOWS) 9 | # define NOMINMAX 10 | # define WIN32_LEAN_AND_MEAN 11 | # include 12 | # endif 13 | 14 | # include 15 | # include "imgui_impl_dx11.h" 16 | # include 17 | 18 | 19 | struct RendererDX11 final 20 | : Renderer 21 | { 22 | bool Create(Platform& platform) override; 23 | void Destroy() override; 24 | void NewFrame() override; 25 | void RenderDrawData(ImDrawData* drawData) override; 26 | void Clear(const ImVec4& color) override; 27 | void Present() override; 28 | void Resize(int width, int height) override; 29 | 30 | ImTextureID CreateTexture(const void* data, int width, int height) override; 31 | void DestroyTexture(ImTextureID texture) override; 32 | int GetTextureWidth(ImTextureID texture) override; 33 | int GetTextureHeight(ImTextureID texture) override; 34 | 35 | HRESULT CreateDeviceD3D(HWND hWnd); 36 | void CleanupDeviceD3D(); 37 | 38 | void CreateRenderTarget(); 39 | void CleanupRenderTarget(); 40 | 41 | Platform* m_Platform = nullptr; 42 | ID3D11Device* m_device = nullptr; 43 | ID3D11DeviceContext* m_deviceContext = nullptr; 44 | IDXGISwapChain* m_swapChain = nullptr; 45 | ID3D11RenderTargetView* m_mainRenderTargetView = nullptr; 46 | }; 47 | 48 | std::unique_ptr CreateRenderer() 49 | { 50 | return std::make_unique(); 51 | } 52 | 53 | bool RendererDX11::Create(Platform& platform) 54 | { 55 | m_Platform = &platform; 56 | 57 | auto hr = CreateDeviceD3D(reinterpret_cast(platform.GetMainWindowHandle())); 58 | if (FAILED(hr)) 59 | return false; 60 | 61 | if (!ImGui_ImplDX11_Init(m_device, m_deviceContext)) 62 | { 63 | CleanupDeviceD3D(); 64 | return false; 65 | } 66 | 67 | m_Platform->SetRenderer(this); 68 | 69 | return true; 70 | } 71 | 72 | void RendererDX11::Destroy() 73 | { 74 | if (!m_Platform) 75 | return; 76 | 77 | m_Platform->SetRenderer(nullptr); 78 | 79 | ImGui_ImplDX11_Shutdown(); 80 | 81 | CleanupDeviceD3D(); 82 | } 83 | 84 | void RendererDX11::NewFrame() 85 | { 86 | ImGui_ImplDX11_NewFrame(); 87 | } 88 | 89 | void RendererDX11::RenderDrawData(ImDrawData* drawData) 90 | { 91 | ImGui_ImplDX11_RenderDrawData(drawData); 92 | } 93 | 94 | void RendererDX11::Clear(const ImVec4& color) 95 | { 96 | m_deviceContext->ClearRenderTargetView(m_mainRenderTargetView, (float*)&color.x); 97 | } 98 | 99 | void RendererDX11::Present() 100 | { 101 | m_swapChain->Present(1, 0); 102 | } 103 | 104 | void RendererDX11::Resize(int width, int height) 105 | { 106 | ImGui_ImplDX11_InvalidateDeviceObjects(); 107 | CleanupRenderTarget(); 108 | m_swapChain->ResizeBuffers(0, (UINT)width, (UINT)height, DXGI_FORMAT_UNKNOWN, 0); 109 | CreateRenderTarget(); 110 | } 111 | 112 | HRESULT RendererDX11::CreateDeviceD3D(HWND hWnd) 113 | { 114 | // Setup swap chain 115 | DXGI_SWAP_CHAIN_DESC sd; 116 | { 117 | ZeroMemory(&sd, sizeof(sd)); 118 | sd.BufferCount = 2; 119 | sd.BufferDesc.Width = 0; 120 | sd.BufferDesc.Height = 0; 121 | sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 122 | sd.BufferDesc.RefreshRate.Numerator = 60; 123 | sd.BufferDesc.RefreshRate.Denominator = 1; 124 | sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; 125 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 126 | sd.OutputWindow = hWnd; 127 | sd.SampleDesc.Count = 1; 128 | sd.SampleDesc.Quality = 0; 129 | sd.Windowed = TRUE; 130 | sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 131 | } 132 | 133 | UINT createDeviceFlags = 0; 134 | //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 135 | D3D_FEATURE_LEVEL featureLevel; 136 | const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, }; 137 | if (D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &m_swapChain, &m_device, &featureLevel, &m_deviceContext) != S_OK) 138 | return E_FAIL; 139 | 140 | CreateRenderTarget(); 141 | 142 | return S_OK; 143 | } 144 | 145 | void RendererDX11::CleanupDeviceD3D() 146 | { 147 | CleanupRenderTarget(); 148 | if (m_swapChain) { m_swapChain->Release(); m_swapChain = nullptr; } 149 | if (m_deviceContext) { m_deviceContext->Release(); m_deviceContext = nullptr; } 150 | if (m_device) { m_device->Release(); m_device = nullptr; } 151 | } 152 | 153 | void RendererDX11::CreateRenderTarget() 154 | { 155 | DXGI_SWAP_CHAIN_DESC sd; 156 | m_swapChain->GetDesc(&sd); 157 | 158 | // Create the render target 159 | ID3D11Texture2D* pBackBuffer; 160 | D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; 161 | ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); 162 | render_target_view_desc.Format = sd.BufferDesc.Format; 163 | render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; 164 | m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); 165 | m_device->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &m_mainRenderTargetView); 166 | m_deviceContext->OMSetRenderTargets(1, &m_mainRenderTargetView, nullptr); 167 | pBackBuffer->Release(); 168 | } 169 | 170 | void RendererDX11::CleanupRenderTarget() 171 | { 172 | if (m_mainRenderTargetView) { m_mainRenderTargetView->Release(); m_mainRenderTargetView = nullptr; } 173 | } 174 | 175 | ImTextureID RendererDX11::CreateTexture(const void* data, int width, int height) 176 | { 177 | return ImGui_CreateTexture(data, width, height); 178 | } 179 | 180 | void RendererDX11::DestroyTexture(ImTextureID texture) 181 | { 182 | return ImGui_DestroyTexture(texture); 183 | } 184 | 185 | int RendererDX11::GetTextureWidth(ImTextureID texture) 186 | { 187 | return ImGui_GetTextureWidth(texture); 188 | } 189 | 190 | int RendererDX11::GetTextureHeight(ImTextureID texture) 191 | { 192 | return ImGui_GetTextureHeight(texture); 193 | } 194 | 195 | # endif // RENDERER(IMGUI_DX11) -------------------------------------------------------------------------------- /examples/application/source/renderer_ogl3.cpp: -------------------------------------------------------------------------------- 1 | # include "renderer.h" 2 | 3 | # if RENDERER(IMGUI_OGL3) 4 | 5 | # include "platform.h" 6 | # include 7 | # include // std::intptr_t 8 | 9 | # if PLATFORM(WINDOWS) 10 | # define NOMINMAX 11 | # define WIN32_LEAN_AND_MEAN 12 | # include 13 | # endif 14 | 15 | # include "imgui_impl_opengl3.h" 16 | 17 | # if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) 18 | # include // Initialize with gl3wInit() 19 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) 20 | # include // Initialize with glewInit() 21 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) 22 | # include // Initialize with gladLoadGL() 23 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) 24 | # include // Initialize with gladLoadGL(...) or gladLoaderLoadGL() 25 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) 26 | # define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. 27 | # include // Initialize with glbinding::Binding::initialize() 28 | # include 29 | using namespace gl; 30 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) 31 | # define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. 32 | # include // Initialize with glbinding::initialize() 33 | # include 34 | using namespace gl; 35 | # elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) 36 | # include IMGUI_IMPL_OPENGL_LOADER_CUSTOM 37 | # else 38 | # include "imgui_impl_opengl3_loader.h" 39 | # endif 40 | 41 | struct ImTexture 42 | { 43 | GLuint TextureID = 0; 44 | int Width = 0; 45 | int Height = 0; 46 | }; 47 | 48 | struct RendererOpenGL3 final 49 | : Renderer 50 | { 51 | bool Create(Platform& platform) override; 52 | void Destroy() override; 53 | void NewFrame() override; 54 | void RenderDrawData(ImDrawData* drawData) override; 55 | void Clear(const ImVec4& color) override; 56 | void Present() override; 57 | void Resize(int width, int height) override; 58 | 59 | ImVector::iterator FindTexture(ImTextureID texture); 60 | ImTextureID CreateTexture(const void* data, int width, int height) override; 61 | void DestroyTexture(ImTextureID texture) override; 62 | int GetTextureWidth(ImTextureID texture) override; 63 | int GetTextureHeight(ImTextureID texture) override; 64 | 65 | Platform* m_Platform = nullptr; 66 | ImVector m_Textures; 67 | }; 68 | 69 | std::unique_ptr CreateRenderer() 70 | { 71 | return std::make_unique(); 72 | } 73 | 74 | bool RendererOpenGL3::Create(Platform& platform) 75 | { 76 | m_Platform = &platform; 77 | 78 | // Technically we should initialize OpenGL context here, 79 | // but for now we relay on one created by GLFW3 80 | 81 | #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) 82 | bool err = gl3wInit() != 0; 83 | #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) 84 | bool err = glewInit() != GLEW_OK; 85 | #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) 86 | bool err = gladLoadGL() == 0; 87 | #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) 88 | bool err = gladLoadGL(glfwGetProcAddress) == 0; // glad2 recommend using the windowing library loader instead of the (optionally) bundled one. 89 | #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) 90 | bool err = false; 91 | glbinding::Binding::initialize(); 92 | #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) 93 | bool err = false; 94 | glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)glfwGetProcAddress(name); }); 95 | #else 96 | bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. 97 | #endif 98 | if (err) 99 | return false; 100 | 101 | # if PLATFORM(MACOS) 102 | const char* glslVersion = "#version 150"; 103 | # else 104 | const char* glslVersion = "#version 130"; 105 | # endif 106 | 107 | if (!ImGui_ImplOpenGL3_Init(glslVersion)) 108 | return false; 109 | 110 | m_Platform->SetRenderer(this); 111 | 112 | return true; 113 | } 114 | 115 | void RendererOpenGL3::Destroy() 116 | { 117 | if (!m_Platform) 118 | return; 119 | 120 | m_Platform->SetRenderer(nullptr); 121 | 122 | ImGui_ImplOpenGL3_Shutdown(); 123 | } 124 | 125 | void RendererOpenGL3::NewFrame() 126 | { 127 | ImGui_ImplOpenGL3_NewFrame(); 128 | } 129 | 130 | void RendererOpenGL3::RenderDrawData(ImDrawData* drawData) 131 | { 132 | ImGui_ImplOpenGL3_RenderDrawData(drawData); 133 | } 134 | 135 | void RendererOpenGL3::Clear(const ImVec4& color) 136 | { 137 | glClearColor(color.x, color.y, color.z, color.w); 138 | glClear(GL_COLOR_BUFFER_BIT); 139 | } 140 | 141 | void RendererOpenGL3::Present() 142 | { 143 | } 144 | 145 | void RendererOpenGL3::Resize(int width, int height) 146 | { 147 | glViewport(0, 0, width, height); 148 | } 149 | 150 | ImTextureID RendererOpenGL3::CreateTexture(const void* data, int width, int height) 151 | { 152 | m_Textures.resize(m_Textures.size() + 1); 153 | ImTexture& texture = m_Textures.back(); 154 | 155 | // Upload texture to graphics system 156 | GLint last_texture = 0; 157 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); 158 | glGenTextures(1, &texture.TextureID); 159 | glBindTexture(GL_TEXTURE_2D, texture.TextureID); 160 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 161 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 162 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 163 | glBindTexture(GL_TEXTURE_2D, last_texture); 164 | 165 | texture.Width = width; 166 | texture.Height = height; 167 | 168 | return reinterpret_cast(static_cast(texture.TextureID)); 169 | } 170 | 171 | ImVector::iterator RendererOpenGL3::FindTexture(ImTextureID texture) 172 | { 173 | auto textureID = static_cast(reinterpret_cast(texture)); 174 | 175 | return std::find_if(m_Textures.begin(), m_Textures.end(), [textureID](ImTexture& texture) 176 | { 177 | return texture.TextureID == textureID; 178 | }); 179 | } 180 | 181 | void RendererOpenGL3::DestroyTexture(ImTextureID texture) 182 | { 183 | auto textureIt = FindTexture(texture); 184 | if (textureIt == m_Textures.end()) 185 | return; 186 | 187 | glDeleteTextures(1, &textureIt->TextureID); 188 | 189 | m_Textures.erase(textureIt); 190 | } 191 | 192 | int RendererOpenGL3::GetTextureWidth(ImTextureID texture) 193 | { 194 | auto textureIt = FindTexture(texture); 195 | if (textureIt != m_Textures.end()) 196 | return textureIt->Width; 197 | return 0; 198 | } 199 | 200 | int RendererOpenGL3::GetTextureHeight(ImTextureID texture) 201 | { 202 | auto textureIt = FindTexture(texture); 203 | if (textureIt != m_Textures.end()) 204 | return textureIt->Height; 205 | return 0; 206 | } 207 | 208 | # endif // RENDERER(IMGUI_OGL3) -------------------------------------------------------------------------------- /examples/application/source/setup.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include "config.h" 3 | 4 | # define DETAIL_PRIV_EXPAND(x) x 5 | # define EXPAND(x) DETAIL_PRIV_EXPAND(x) 6 | # define DETAIL_PRIV_CONCAT(x, y) x ## y 7 | # define CONCAT(x, y) DETAIL_PRIV_CONCAT(x, y) 8 | 9 | 10 | // Define PLATFORM(x) which evaluate to 0 or 1 when 11 | // 'x' is: WINDOWS, MACOS or LINUX 12 | # if defined(_WIN32) 13 | # define PLATFORM_PRIV_WINDOWS() 1 14 | # elif defined(__APPLE__) 15 | # define PLATFORM_PRIV_MACOS() 1 16 | # elif defined(__linux__) 17 | # define PLATFORM_PRIV_LINUX() 1 18 | # else 19 | # error Unsupported platform 20 | # endif 21 | 22 | # ifndef PLATFORM_PRIV_WINDOWS 23 | # define PLATFORM_PRIV_WINDOWS() 0 24 | # endif 25 | # ifndef PLATFORM_PRIV_MACOS 26 | # define PLATFORM_PRIV_MACOS() 0 27 | # endif 28 | # ifndef PLATFORM_PRIV_LINUX 29 | # define PLATFORM_PRIV_LINUX() 0 30 | # endif 31 | 32 | # define PLATFORM(x) (PLATFORM_PRIV_##x()) 33 | 34 | 35 | // Define BACKEND(x) which evaluate to 0 or 1 when 36 | // 'x' is: IMGUI_WIN32 or IMGUI_GLFW 37 | // 38 | // Use BACKEND_CONFIG to override desired backend 39 | // 40 | # if PLATFORM(WINDOWS) 41 | # define BACKEND_HAVE_IMGUI_WIN32() 1 42 | # endif 43 | # if HAVE_GLFW3 44 | # define BACKEND_HAVE_IMGUI_GLFW() 1 45 | # endif 46 | 47 | # ifndef BACKEND_HAVE_IMGUI_WIN32 48 | # define BACKEND_HAVE_IMGUI_WIN32() 0 49 | # endif 50 | # ifndef BACKEND_HAVE_IMGUI_GLFW 51 | # define BACKEND_HAVE_IMGUI_GLFW() 0 52 | # endif 53 | 54 | # define BACKEND_PRIV_IMGUI_WIN32() 1 55 | # define BACKEND_PRIV_IMGUI_GLFW() 2 56 | 57 | # if !defined(BACKEND_CONFIG) 58 | # if PLATFORM(WINDOWS) 59 | # define BACKEND_CONFIG IMGUI_WIN32 60 | # else 61 | # define BACKEND_CONFIG IMGUI_GLFW 62 | # endif 63 | # endif 64 | 65 | # define BACKEND(x) ((BACKEND_PRIV_##x()) == CONCAT(BACKEND_PRIV_, EXPAND(BACKEND_CONFIG))() && (BACKEND_HAVE_##x())) 66 | 67 | 68 | // Define RENDERER(x) which evaluate to 0 or 1 when 69 | // 'x' is: IMGUI_DX11 or IMGUI_OGL3 70 | // 71 | // Use RENDERER_CONFIG to override desired renderer 72 | // 73 | # if PLATFORM(WINDOWS) 74 | # define RENDERER_HAVE_IMGUI_DX11() 1 75 | # endif 76 | # if HAVE_OPENGL 77 | # define RENDERER_HAVE_IMGUI_OGL3() 1 78 | # endif 79 | 80 | # ifndef RENDERER_HAVE_IMGUI_DX11 81 | # define RENDERER_HAVE_IMGUI_DX11() 0 82 | # endif 83 | # ifndef RENDERER_HAVE_IMGUI_OGL3 84 | # define RENDERER_HAVE_IMGUI_OGL3() 0 85 | # endif 86 | 87 | # define RENDERER_PRIV_IMGUI_DX11() 1 88 | # define RENDERER_PRIV_IMGUI_OGL3() 2 89 | 90 | # if !defined(RENDERER_CONFIG) 91 | # if PLATFORM(WINDOWS) 92 | # define RENDERER_CONFIG IMGUI_DX11 93 | # else 94 | # define RENDERER_CONFIG IMGUI_OGL3 95 | # endif 96 | # endif 97 | 98 | # define RENDERER(x) ((RENDERER_PRIV_##x()) == CONCAT(RENDERER_PRIV_, EXPAND(RENDERER_CONFIG))() && (RENDERER_HAVE_##x())) 99 | -------------------------------------------------------------------------------- /examples/application/support/Icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/application/support/Icon.icns -------------------------------------------------------------------------------- /examples/application/support/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/application/support/Icon.ico -------------------------------------------------------------------------------- /examples/application/support/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/application/support/Icon.png -------------------------------------------------------------------------------- /examples/application/support/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | LSRequiresCarbon 32 | 33 | NSHumanReadableCopyright 34 | ${MACOSX_BUNDLE_COPYRIGHT} 35 | NSSupportsAutomaticGraphicsSwitching 36 | 37 | NSHighResolutionCapable 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/application/support/Resource.rc.in: -------------------------------------------------------------------------------- 1 | #define IDI_APPLICATION 32512 2 | 3 | IDI_APPLICATION ICON "${ApplicationIcon}" 4 | -------------------------------------------------------------------------------- /examples/basic-interaction-example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_example_executable(basic-interaction-example 2 | basic-interaction-example.cpp 3 | ) -------------------------------------------------------------------------------- /examples/basic-interaction-example/basic-interaction-example.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | namespace ed = ax::NodeEditor; 6 | 7 | struct Example: 8 | public Application 9 | { 10 | // Struct to hold basic information about connection between 11 | // pins. Note that connection (aka. link) has its own ID. 12 | // This is useful later with dealing with selections, deletion 13 | // or other operations. 14 | struct LinkInfo 15 | { 16 | ed::LinkId Id; 17 | ed::PinId InputId; 18 | ed::PinId OutputId; 19 | }; 20 | 21 | using Application::Application; 22 | 23 | void OnStart() override 24 | { 25 | ed::Config config; 26 | config.SettingsFile = "BasicInteraction.json"; 27 | m_Context = ed::CreateEditor(&config); 28 | } 29 | 30 | void OnStop() override 31 | { 32 | ed::DestroyEditor(m_Context); 33 | } 34 | 35 | void ImGuiEx_BeginColumn() 36 | { 37 | ImGui::BeginGroup(); 38 | } 39 | 40 | void ImGuiEx_NextColumn() 41 | { 42 | ImGui::EndGroup(); 43 | ImGui::SameLine(); 44 | ImGui::BeginGroup(); 45 | } 46 | 47 | void ImGuiEx_EndColumn() 48 | { 49 | ImGui::EndGroup(); 50 | } 51 | 52 | void OnFrame(float deltaTime) override 53 | { 54 | auto& io = ImGui::GetIO(); 55 | 56 | ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f); 57 | 58 | ImGui::Separator(); 59 | 60 | ed::SetCurrentEditor(m_Context); 61 | 62 | // Start interaction with editor. 63 | ed::Begin("My Editor", ImVec2(0.0, 0.0f)); 64 | 65 | int uniqueId = 1; 66 | 67 | // 68 | // 1) Commit known data to editor 69 | // 70 | 71 | // Submit Node A 72 | ed::NodeId nodeA_Id = uniqueId++; 73 | ed::PinId nodeA_InputPinId = uniqueId++; 74 | ed::PinId nodeA_OutputPinId = uniqueId++; 75 | 76 | if (m_FirstFrame) 77 | ed::SetNodePosition(nodeA_Id, ImVec2(10, 10)); 78 | ed::BeginNode(nodeA_Id); 79 | ImGui::Text("Node A"); 80 | ed::BeginPin(nodeA_InputPinId, ed::PinKind::Input); 81 | ImGui::Text("-> In"); 82 | ed::EndPin(); 83 | ImGui::SameLine(); 84 | ed::BeginPin(nodeA_OutputPinId, ed::PinKind::Output); 85 | ImGui::Text("Out ->"); 86 | ed::EndPin(); 87 | ed::EndNode(); 88 | 89 | // Submit Node B 90 | ed::NodeId nodeB_Id = uniqueId++; 91 | ed::PinId nodeB_InputPinId1 = uniqueId++; 92 | ed::PinId nodeB_InputPinId2 = uniqueId++; 93 | ed::PinId nodeB_OutputPinId = uniqueId++; 94 | 95 | if (m_FirstFrame) 96 | ed::SetNodePosition(nodeB_Id, ImVec2(210, 60)); 97 | ed::BeginNode(nodeB_Id); 98 | ImGui::Text("Node B"); 99 | ImGuiEx_BeginColumn(); 100 | ed::BeginPin(nodeB_InputPinId1, ed::PinKind::Input); 101 | ImGui::Text("-> In1"); 102 | ed::EndPin(); 103 | ed::BeginPin(nodeB_InputPinId2, ed::PinKind::Input); 104 | ImGui::Text("-> In2"); 105 | ed::EndPin(); 106 | ImGuiEx_NextColumn(); 107 | ed::BeginPin(nodeB_OutputPinId, ed::PinKind::Output); 108 | ImGui::Text("Out ->"); 109 | ed::EndPin(); 110 | ImGuiEx_EndColumn(); 111 | ed::EndNode(); 112 | 113 | // Submit Links 114 | for (auto& linkInfo : m_Links) 115 | ed::Link(linkInfo.Id, linkInfo.InputId, linkInfo.OutputId); 116 | 117 | // 118 | // 2) Handle interactions 119 | // 120 | 121 | // Handle creation action, returns true if editor want to create new object (node or link) 122 | if (ed::BeginCreate()) 123 | { 124 | ed::PinId inputPinId, outputPinId; 125 | if (ed::QueryNewLink(&inputPinId, &outputPinId)) 126 | { 127 | // QueryNewLink returns true if editor want to create new link between pins. 128 | // 129 | // Link can be created only for two valid pins, it is up to you to 130 | // validate if connection make sense. Editor is happy to make any. 131 | // 132 | // Link always goes from input to output. User may choose to drag 133 | // link from output pin or input pin. This determine which pin ids 134 | // are valid and which are not: 135 | // * input valid, output invalid - user started to drag new ling from input pin 136 | // * input invalid, output valid - user started to drag new ling from output pin 137 | // * input valid, output valid - user dragged link over other pin, can be validated 138 | 139 | if (inputPinId && outputPinId) // both are valid, let's accept link 140 | { 141 | // ed::AcceptNewItem() return true when user release mouse button. 142 | if (ed::AcceptNewItem()) 143 | { 144 | // Since we accepted new link, lets add one to our list of links. 145 | m_Links.push_back({ ed::LinkId(m_NextLinkId++), inputPinId, outputPinId }); 146 | 147 | // Draw new link. 148 | ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId); 149 | } 150 | 151 | // You may choose to reject connection between these nodes 152 | // by calling ed::RejectNewItem(). This will allow editor to give 153 | // visual feedback by changing link thickness and color. 154 | } 155 | } 156 | } 157 | ed::EndCreate(); // Wraps up object creation action handling. 158 | 159 | 160 | // Handle deletion action 161 | if (ed::BeginDelete()) 162 | { 163 | // There may be many links marked for deletion, let's loop over them. 164 | ed::LinkId deletedLinkId; 165 | while (ed::QueryDeletedLink(&deletedLinkId)) 166 | { 167 | // If you agree that link can be deleted, accept deletion. 168 | if (ed::AcceptDeletedItem()) 169 | { 170 | // Then remove link from your data. 171 | for (auto& link : m_Links) 172 | { 173 | if (link.Id == deletedLinkId) 174 | { 175 | m_Links.erase(&link); 176 | break; 177 | } 178 | } 179 | } 180 | 181 | // You may reject link deletion by calling: 182 | // ed::RejectDeletedItem(); 183 | } 184 | } 185 | ed::EndDelete(); // Wrap up deletion action 186 | 187 | 188 | 189 | // End of interaction with editor. 190 | ed::End(); 191 | 192 | if (m_FirstFrame) 193 | ed::NavigateToContent(0.0f); 194 | 195 | ed::SetCurrentEditor(nullptr); 196 | 197 | m_FirstFrame = false; 198 | 199 | // ImGui::ShowMetricsWindow(); 200 | } 201 | 202 | ed::EditorContext* m_Context = nullptr; // Editor context, required to trace a editor state. 203 | bool m_FirstFrame = true; // Flag set for first frame only, some action need to be executed once. 204 | ImVector m_Links; // List of live links. It is dynamic unless you want to create read-only view over nodes. 205 | int m_NextLinkId = 100; // Counter to help generate link ids. In real application this will probably based on pointer to user data structure. 206 | }; 207 | 208 | int Main(int argc, char** argv) 209 | { 210 | Example exampe("Basic Interaction", argc, argv); 211 | 212 | if (exampe.Create()) 213 | return exampe.Run(); 214 | 215 | return 0; 216 | } -------------------------------------------------------------------------------- /examples/blueprints-example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_example_executable(blueprints-example 2 | blueprints-example.cpp 3 | utilities/builders.h 4 | utilities/drawing.h 5 | utilities/widgets.h 6 | utilities/builders.cpp 7 | utilities/drawing.cpp 8 | utilities/widgets.cpp 9 | ) 10 | -------------------------------------------------------------------------------- /examples/blueprints-example/data/BlueprintBackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/blueprints-example/data/BlueprintBackground.png -------------------------------------------------------------------------------- /examples/blueprints-example/data/ic_restore_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/blueprints-example/data/ic_restore_white_24dp.png -------------------------------------------------------------------------------- /examples/blueprints-example/data/ic_save_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/blueprints-example/data/ic_save_white_24dp.png -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/builders.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // LICENSE 3 | // This software is dual-licensed to the public domain and under the following 4 | // license: you are granted a perpetual, irrevocable license to copy, modify, 5 | // publish, and distribute this file as you see fit. 6 | // 7 | // CREDITS 8 | // Written by Michal Cichon 9 | //------------------------------------------------------------------------------ 10 | # define IMGUI_DEFINE_MATH_OPERATORS 11 | # include "builders.h" 12 | # include 13 | 14 | 15 | //------------------------------------------------------------------------------ 16 | namespace ed = ax::NodeEditor; 17 | namespace util = ax::NodeEditor::Utilities; 18 | 19 | util::BlueprintNodeBuilder::BlueprintNodeBuilder(ImTextureID texture, int textureWidth, int textureHeight): 20 | HeaderTextureId(texture), 21 | HeaderTextureWidth(textureWidth), 22 | HeaderTextureHeight(textureHeight), 23 | CurrentNodeId(0), 24 | CurrentStage(Stage::Invalid), 25 | HasHeader(false) 26 | { 27 | } 28 | 29 | void util::BlueprintNodeBuilder::Begin(ed::NodeId id) 30 | { 31 | HasHeader = false; 32 | HeaderMin = HeaderMax = ImVec2(); 33 | 34 | ed::PushStyleVar(StyleVar_NodePadding, ImVec4(8, 4, 8, 8)); 35 | 36 | ed::BeginNode(id); 37 | 38 | ImGui::PushID(id.AsPointer()); 39 | CurrentNodeId = id; 40 | 41 | SetStage(Stage::Begin); 42 | } 43 | 44 | void util::BlueprintNodeBuilder::End() 45 | { 46 | SetStage(Stage::End); 47 | 48 | ed::EndNode(); 49 | 50 | if (ImGui::IsItemVisible()) 51 | { 52 | auto alpha = static_cast(255 * ImGui::GetStyle().Alpha); 53 | 54 | auto drawList = ed::GetNodeBackgroundDrawList(CurrentNodeId); 55 | 56 | const auto halfBorderWidth = ed::GetStyle().NodeBorderWidth * 0.5f; 57 | 58 | auto headerColor = IM_COL32(0, 0, 0, alpha) | (HeaderColor & IM_COL32(255, 255, 255, 0)); 59 | if ((HeaderMax.x > HeaderMin.x) && (HeaderMax.y > HeaderMin.y) && HeaderTextureId) 60 | { 61 | const auto uv = ImVec2( 62 | (HeaderMax.x - HeaderMin.x) / (float)(4.0f * HeaderTextureWidth), 63 | (HeaderMax.y - HeaderMin.y) / (float)(4.0f * HeaderTextureHeight)); 64 | 65 | drawList->AddImageRounded(HeaderTextureId, 66 | HeaderMin - ImVec2(8 - halfBorderWidth, 4 - halfBorderWidth), 67 | HeaderMax + ImVec2(8 - halfBorderWidth, 0), 68 | ImVec2(0.0f, 0.0f), uv, 69 | #if IMGUI_VERSION_NUM > 18101 70 | headerColor, GetStyle().NodeRounding, ImDrawFlags_RoundCornersTop); 71 | #else 72 | headerColor, GetStyle().NodeRounding, 1 | 2); 73 | #endif 74 | 75 | if (ContentMin.y > HeaderMax.y) 76 | { 77 | drawList->AddLine( 78 | ImVec2(HeaderMin.x - (8 - halfBorderWidth), HeaderMax.y - 0.5f), 79 | ImVec2(HeaderMax.x + (8 - halfBorderWidth), HeaderMax.y - 0.5f), 80 | ImColor(255, 255, 255, 96 * alpha / (3 * 255)), 1.0f); 81 | } 82 | } 83 | } 84 | 85 | CurrentNodeId = 0; 86 | 87 | ImGui::PopID(); 88 | 89 | ed::PopStyleVar(); 90 | 91 | SetStage(Stage::Invalid); 92 | } 93 | 94 | void util::BlueprintNodeBuilder::Header(const ImVec4& color) 95 | { 96 | HeaderColor = ImColor(color); 97 | SetStage(Stage::Header); 98 | } 99 | 100 | void util::BlueprintNodeBuilder::EndHeader() 101 | { 102 | SetStage(Stage::Content); 103 | } 104 | 105 | void util::BlueprintNodeBuilder::Input(ed::PinId id) 106 | { 107 | if (CurrentStage == Stage::Begin) 108 | SetStage(Stage::Content); 109 | 110 | const auto applyPadding = (CurrentStage == Stage::Input); 111 | 112 | SetStage(Stage::Input); 113 | 114 | if (applyPadding) 115 | ImGui::Spring(0); 116 | 117 | Pin(id, PinKind::Input); 118 | 119 | ImGui::BeginHorizontal(id.AsPointer()); 120 | } 121 | 122 | void util::BlueprintNodeBuilder::EndInput() 123 | { 124 | ImGui::EndHorizontal(); 125 | 126 | EndPin(); 127 | } 128 | 129 | void util::BlueprintNodeBuilder::Middle() 130 | { 131 | if (CurrentStage == Stage::Begin) 132 | SetStage(Stage::Content); 133 | 134 | SetStage(Stage::Middle); 135 | } 136 | 137 | void util::BlueprintNodeBuilder::Output(ed::PinId id) 138 | { 139 | if (CurrentStage == Stage::Begin) 140 | SetStage(Stage::Content); 141 | 142 | const auto applyPadding = (CurrentStage == Stage::Output); 143 | 144 | SetStage(Stage::Output); 145 | 146 | if (applyPadding) 147 | ImGui::Spring(0); 148 | 149 | Pin(id, PinKind::Output); 150 | 151 | ImGui::BeginHorizontal(id.AsPointer()); 152 | } 153 | 154 | void util::BlueprintNodeBuilder::EndOutput() 155 | { 156 | ImGui::EndHorizontal(); 157 | 158 | EndPin(); 159 | } 160 | 161 | bool util::BlueprintNodeBuilder::SetStage(Stage stage) 162 | { 163 | if (stage == CurrentStage) 164 | return false; 165 | 166 | auto oldStage = CurrentStage; 167 | CurrentStage = stage; 168 | 169 | ImVec2 cursor; 170 | switch (oldStage) 171 | { 172 | case Stage::Begin: 173 | break; 174 | 175 | case Stage::Header: 176 | ImGui::EndHorizontal(); 177 | HeaderMin = ImGui::GetItemRectMin(); 178 | HeaderMax = ImGui::GetItemRectMax(); 179 | 180 | // spacing between header and content 181 | ImGui::Spring(0, ImGui::GetStyle().ItemSpacing.y * 2.0f); 182 | 183 | break; 184 | 185 | case Stage::Content: 186 | break; 187 | 188 | case Stage::Input: 189 | ed::PopStyleVar(2); 190 | 191 | ImGui::Spring(1, 0); 192 | ImGui::EndVertical(); 193 | 194 | // #debug 195 | // ImGui::GetWindowDrawList()->AddRect( 196 | // ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255, 0, 0, 255)); 197 | 198 | break; 199 | 200 | case Stage::Middle: 201 | ImGui::EndVertical(); 202 | 203 | // #debug 204 | // ImGui::GetWindowDrawList()->AddRect( 205 | // ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255, 0, 0, 255)); 206 | 207 | break; 208 | 209 | case Stage::Output: 210 | ed::PopStyleVar(2); 211 | 212 | ImGui::Spring(1, 0); 213 | ImGui::EndVertical(); 214 | 215 | // #debug 216 | // ImGui::GetWindowDrawList()->AddRect( 217 | // ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255, 0, 0, 255)); 218 | 219 | break; 220 | 221 | case Stage::End: 222 | break; 223 | 224 | case Stage::Invalid: 225 | break; 226 | } 227 | 228 | switch (stage) 229 | { 230 | case Stage::Begin: 231 | ImGui::BeginVertical("node"); 232 | break; 233 | 234 | case Stage::Header: 235 | HasHeader = true; 236 | 237 | ImGui::BeginHorizontal("header"); 238 | break; 239 | 240 | case Stage::Content: 241 | if (oldStage == Stage::Begin) 242 | ImGui::Spring(0); 243 | 244 | ImGui::BeginHorizontal("content"); 245 | ImGui::Spring(0, 0); 246 | break; 247 | 248 | case Stage::Input: 249 | ImGui::BeginVertical("inputs", ImVec2(0, 0), 0.0f); 250 | 251 | ed::PushStyleVar(ed::StyleVar_PivotAlignment, ImVec2(0, 0.5f)); 252 | ed::PushStyleVar(ed::StyleVar_PivotSize, ImVec2(0, 0)); 253 | 254 | if (!HasHeader) 255 | ImGui::Spring(1, 0); 256 | break; 257 | 258 | case Stage::Middle: 259 | ImGui::Spring(1); 260 | ImGui::BeginVertical("middle", ImVec2(0, 0), 1.0f); 261 | break; 262 | 263 | case Stage::Output: 264 | if (oldStage == Stage::Middle || oldStage == Stage::Input) 265 | ImGui::Spring(1); 266 | else 267 | ImGui::Spring(1, 0); 268 | ImGui::BeginVertical("outputs", ImVec2(0, 0), 1.0f); 269 | 270 | ed::PushStyleVar(ed::StyleVar_PivotAlignment, ImVec2(1.0f, 0.5f)); 271 | ed::PushStyleVar(ed::StyleVar_PivotSize, ImVec2(0, 0)); 272 | 273 | if (!HasHeader) 274 | ImGui::Spring(1, 0); 275 | break; 276 | 277 | case Stage::End: 278 | if (oldStage == Stage::Input) 279 | ImGui::Spring(1, 0); 280 | if (oldStage != Stage::Begin) 281 | ImGui::EndHorizontal(); 282 | ContentMin = ImGui::GetItemRectMin(); 283 | ContentMax = ImGui::GetItemRectMax(); 284 | 285 | //ImGui::Spring(0); 286 | ImGui::EndVertical(); 287 | NodeMin = ImGui::GetItemRectMin(); 288 | NodeMax = ImGui::GetItemRectMax(); 289 | break; 290 | 291 | case Stage::Invalid: 292 | break; 293 | } 294 | 295 | return true; 296 | } 297 | 298 | void util::BlueprintNodeBuilder::Pin(ed::PinId id, ed::PinKind kind) 299 | { 300 | ed::BeginPin(id, kind); 301 | } 302 | 303 | void util::BlueprintNodeBuilder::EndPin() 304 | { 305 | ed::EndPin(); 306 | 307 | // #debug 308 | // ImGui::GetWindowDrawList()->AddRectFilled( 309 | // ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255, 0, 0, 64)); 310 | } 311 | -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/builders.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // LICENSE 3 | // This software is dual-licensed to the public domain and under the following 4 | // license: you are granted a perpetual, irrevocable license to copy, modify, 5 | // publish, and distribute this file as you see fit. 6 | // 7 | // CREDITS 8 | // Written by Michal Cichon 9 | //------------------------------------------------------------------------------ 10 | # pragma once 11 | 12 | 13 | //------------------------------------------------------------------------------ 14 | # include 15 | 16 | 17 | //------------------------------------------------------------------------------ 18 | namespace ax { 19 | namespace NodeEditor { 20 | namespace Utilities { 21 | 22 | 23 | //------------------------------------------------------------------------------ 24 | struct BlueprintNodeBuilder 25 | { 26 | BlueprintNodeBuilder(ImTextureID texture = nullptr, int textureWidth = 0, int textureHeight = 0); 27 | 28 | void Begin(NodeId id); 29 | void End(); 30 | 31 | void Header(const ImVec4& color = ImVec4(1, 1, 1, 1)); 32 | void EndHeader(); 33 | 34 | void Input(PinId id); 35 | void EndInput(); 36 | 37 | void Middle(); 38 | 39 | void Output(PinId id); 40 | void EndOutput(); 41 | 42 | 43 | private: 44 | enum class Stage 45 | { 46 | Invalid, 47 | Begin, 48 | Header, 49 | Content, 50 | Input, 51 | Output, 52 | Middle, 53 | End 54 | }; 55 | 56 | bool SetStage(Stage stage); 57 | 58 | void Pin(PinId id, ax::NodeEditor::PinKind kind); 59 | void EndPin(); 60 | 61 | ImTextureID HeaderTextureId; 62 | int HeaderTextureWidth; 63 | int HeaderTextureHeight; 64 | NodeId CurrentNodeId; 65 | Stage CurrentStage; 66 | ImU32 HeaderColor; 67 | ImVec2 NodeMin; 68 | ImVec2 NodeMax; 69 | ImVec2 HeaderMin; 70 | ImVec2 HeaderMax; 71 | ImVec2 ContentMin; 72 | ImVec2 ContentMax; 73 | bool HasHeader; 74 | }; 75 | 76 | 77 | 78 | //------------------------------------------------------------------------------ 79 | } // namespace Utilities 80 | } // namespace Editor 81 | } // namespace ax -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/drawing.cpp: -------------------------------------------------------------------------------- 1 | # define IMGUI_DEFINE_MATH_OPERATORS 2 | # include "drawing.h" 3 | # include 4 | 5 | void ax::Drawing::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor) 6 | { 7 | auto rect = ImRect(a, b); 8 | auto rect_x = rect.Min.x; 9 | auto rect_y = rect.Min.y; 10 | auto rect_w = rect.Max.x - rect.Min.x; 11 | auto rect_h = rect.Max.y - rect.Min.y; 12 | auto rect_center_x = (rect.Min.x + rect.Max.x) * 0.5f; 13 | auto rect_center_y = (rect.Min.y + rect.Max.y) * 0.5f; 14 | auto rect_center = ImVec2(rect_center_x, rect_center_y); 15 | const auto outline_scale = rect_w / 24.0f; 16 | const auto extra_segments = static_cast(2 * outline_scale); // for full circle 17 | 18 | if (type == IconType::Flow) 19 | { 20 | const auto origin_scale = rect_w / 24.0f; 21 | 22 | const auto offset_x = 1.0f * origin_scale; 23 | const auto offset_y = 0.0f * origin_scale; 24 | const auto margin = (filled ? 2.0f : 2.0f) * origin_scale; 25 | const auto rounding = 0.1f * origin_scale; 26 | const auto tip_round = 0.7f; // percentage of triangle edge (for tip) 27 | //const auto edge_round = 0.7f; // percentage of triangle edge (for corner) 28 | const auto canvas = ImRect( 29 | rect.Min.x + margin + offset_x, 30 | rect.Min.y + margin + offset_y, 31 | rect.Max.x - margin + offset_x, 32 | rect.Max.y - margin + offset_y); 33 | const auto canvas_x = canvas.Min.x; 34 | const auto canvas_y = canvas.Min.y; 35 | const auto canvas_w = canvas.Max.x - canvas.Min.x; 36 | const auto canvas_h = canvas.Max.y - canvas.Min.y; 37 | 38 | const auto left = canvas_x + canvas_w * 0.5f * 0.3f; 39 | const auto right = canvas_x + canvas_w - canvas_w * 0.5f * 0.3f; 40 | const auto top = canvas_y + canvas_h * 0.5f * 0.2f; 41 | const auto bottom = canvas_y + canvas_h - canvas_h * 0.5f * 0.2f; 42 | const auto center_y = (top + bottom) * 0.5f; 43 | //const auto angle = AX_PI * 0.5f * 0.5f * 0.5f; 44 | 45 | const auto tip_top = ImVec2(canvas_x + canvas_w * 0.5f, top); 46 | const auto tip_right = ImVec2(right, center_y); 47 | const auto tip_bottom = ImVec2(canvas_x + canvas_w * 0.5f, bottom); 48 | 49 | drawList->PathLineTo(ImVec2(left, top) + ImVec2(0, rounding)); 50 | drawList->PathBezierCubicCurveTo( 51 | ImVec2(left, top), 52 | ImVec2(left, top), 53 | ImVec2(left, top) + ImVec2(rounding, 0)); 54 | drawList->PathLineTo(tip_top); 55 | drawList->PathLineTo(tip_top + (tip_right - tip_top) * tip_round); 56 | drawList->PathBezierCubicCurveTo( 57 | tip_right, 58 | tip_right, 59 | tip_bottom + (tip_right - tip_bottom) * tip_round); 60 | drawList->PathLineTo(tip_bottom); 61 | drawList->PathLineTo(ImVec2(left, bottom) + ImVec2(rounding, 0)); 62 | drawList->PathBezierCubicCurveTo( 63 | ImVec2(left, bottom), 64 | ImVec2(left, bottom), 65 | ImVec2(left, bottom) - ImVec2(0, rounding)); 66 | 67 | if (!filled) 68 | { 69 | if (innerColor & 0xFF000000) 70 | drawList->AddConvexPolyFilled(drawList->_Path.Data, drawList->_Path.Size, innerColor); 71 | 72 | drawList->PathStroke(color, true, 2.0f * outline_scale); 73 | } 74 | else 75 | drawList->PathFillConvex(color); 76 | } 77 | else 78 | { 79 | auto triangleStart = rect_center_x + 0.32f * rect_w; 80 | 81 | auto rect_offset = -static_cast(rect_w * 0.25f * 0.25f); 82 | 83 | rect.Min.x += rect_offset; 84 | rect.Max.x += rect_offset; 85 | rect_x += rect_offset; 86 | rect_center_x += rect_offset * 0.5f; 87 | rect_center.x += rect_offset * 0.5f; 88 | 89 | if (type == IconType::Circle) 90 | { 91 | const auto c = rect_center; 92 | 93 | if (!filled) 94 | { 95 | const auto r = 0.5f * rect_w / 2.0f - 0.5f; 96 | 97 | if (innerColor & 0xFF000000) 98 | drawList->AddCircleFilled(c, r, innerColor, 12 + extra_segments); 99 | drawList->AddCircle(c, r, color, 12 + extra_segments, 2.0f * outline_scale); 100 | } 101 | else 102 | { 103 | drawList->AddCircleFilled(c, 0.5f * rect_w / 2.0f, color, 12 + extra_segments); 104 | } 105 | } 106 | 107 | if (type == IconType::Square) 108 | { 109 | if (filled) 110 | { 111 | const auto r = 0.5f * rect_w / 2.0f; 112 | const auto p0 = rect_center - ImVec2(r, r); 113 | const auto p1 = rect_center + ImVec2(r, r); 114 | 115 | #if IMGUI_VERSION_NUM > 18101 116 | drawList->AddRectFilled(p0, p1, color, 0, ImDrawFlags_RoundCornersAll); 117 | #else 118 | drawList->AddRectFilled(p0, p1, color, 0, 15); 119 | #endif 120 | } 121 | else 122 | { 123 | const auto r = 0.5f * rect_w / 2.0f - 0.5f; 124 | const auto p0 = rect_center - ImVec2(r, r); 125 | const auto p1 = rect_center + ImVec2(r, r); 126 | 127 | if (innerColor & 0xFF000000) 128 | { 129 | #if IMGUI_VERSION_NUM > 18101 130 | drawList->AddRectFilled(p0, p1, innerColor, 0, ImDrawFlags_RoundCornersAll); 131 | #else 132 | drawList->AddRectFilled(p0, p1, innerColor, 0, 15); 133 | #endif 134 | } 135 | 136 | #if IMGUI_VERSION_NUM > 18101 137 | drawList->AddRect(p0, p1, color, 0, ImDrawFlags_RoundCornersAll, 2.0f * outline_scale); 138 | #else 139 | drawList->AddRect(p0, p1, color, 0, 15, 2.0f * outline_scale); 140 | #endif 141 | } 142 | } 143 | 144 | if (type == IconType::Grid) 145 | { 146 | const auto r = 0.5f * rect_w / 2.0f; 147 | const auto w = ceilf(r / 3.0f); 148 | 149 | const auto baseTl = ImVec2(floorf(rect_center_x - w * 2.5f), floorf(rect_center_y - w * 2.5f)); 150 | const auto baseBr = ImVec2(floorf(baseTl.x + w), floorf(baseTl.y + w)); 151 | 152 | auto tl = baseTl; 153 | auto br = baseBr; 154 | for (int i = 0; i < 3; ++i) 155 | { 156 | tl.x = baseTl.x; 157 | br.x = baseBr.x; 158 | drawList->AddRectFilled(tl, br, color); 159 | tl.x += w * 2; 160 | br.x += w * 2; 161 | if (i != 1 || filled) 162 | drawList->AddRectFilled(tl, br, color); 163 | tl.x += w * 2; 164 | br.x += w * 2; 165 | drawList->AddRectFilled(tl, br, color); 166 | 167 | tl.y += w * 2; 168 | br.y += w * 2; 169 | } 170 | 171 | triangleStart = br.x + w + 1.0f / 24.0f * rect_w; 172 | } 173 | 174 | if (type == IconType::RoundSquare) 175 | { 176 | if (filled) 177 | { 178 | const auto r = 0.5f * rect_w / 2.0f; 179 | const auto cr = r * 0.5f; 180 | const auto p0 = rect_center - ImVec2(r, r); 181 | const auto p1 = rect_center + ImVec2(r, r); 182 | 183 | #if IMGUI_VERSION_NUM > 18101 184 | drawList->AddRectFilled(p0, p1, color, cr, ImDrawFlags_RoundCornersAll); 185 | #else 186 | drawList->AddRectFilled(p0, p1, color, cr, 15); 187 | #endif 188 | } 189 | else 190 | { 191 | const auto r = 0.5f * rect_w / 2.0f - 0.5f; 192 | const auto cr = r * 0.5f; 193 | const auto p0 = rect_center - ImVec2(r, r); 194 | const auto p1 = rect_center + ImVec2(r, r); 195 | 196 | if (innerColor & 0xFF000000) 197 | { 198 | #if IMGUI_VERSION_NUM > 18101 199 | drawList->AddRectFilled(p0, p1, innerColor, cr, ImDrawFlags_RoundCornersAll); 200 | #else 201 | drawList->AddRectFilled(p0, p1, innerColor, cr, 15); 202 | #endif 203 | } 204 | 205 | #if IMGUI_VERSION_NUM > 18101 206 | drawList->AddRect(p0, p1, color, cr, ImDrawFlags_RoundCornersAll, 2.0f * outline_scale); 207 | #else 208 | drawList->AddRect(p0, p1, color, cr, 15, 2.0f * outline_scale); 209 | #endif 210 | } 211 | } 212 | else if (type == IconType::Diamond) 213 | { 214 | if (filled) 215 | { 216 | const auto r = 0.607f * rect_w / 2.0f; 217 | const auto c = rect_center; 218 | 219 | drawList->PathLineTo(c + ImVec2( 0, -r)); 220 | drawList->PathLineTo(c + ImVec2( r, 0)); 221 | drawList->PathLineTo(c + ImVec2( 0, r)); 222 | drawList->PathLineTo(c + ImVec2(-r, 0)); 223 | drawList->PathFillConvex(color); 224 | } 225 | else 226 | { 227 | const auto r = 0.607f * rect_w / 2.0f - 0.5f; 228 | const auto c = rect_center; 229 | 230 | drawList->PathLineTo(c + ImVec2( 0, -r)); 231 | drawList->PathLineTo(c + ImVec2( r, 0)); 232 | drawList->PathLineTo(c + ImVec2( 0, r)); 233 | drawList->PathLineTo(c + ImVec2(-r, 0)); 234 | 235 | if (innerColor & 0xFF000000) 236 | drawList->AddConvexPolyFilled(drawList->_Path.Data, drawList->_Path.Size, innerColor); 237 | 238 | drawList->PathStroke(color, true, 2.0f * outline_scale); 239 | } 240 | } 241 | else 242 | { 243 | const auto triangleTip = triangleStart + rect_w * (0.45f - 0.32f); 244 | 245 | drawList->AddTriangleFilled( 246 | ImVec2(ceilf(triangleTip), rect_y + rect_h * 0.5f), 247 | ImVec2(triangleStart, rect_center_y + 0.15f * rect_h), 248 | ImVec2(triangleStart, rect_center_y - 0.15f * rect_h), 249 | color); 250 | } 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/drawing.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | # include 3 | 4 | namespace ax { 5 | namespace Drawing { 6 | 7 | enum class IconType: ImU32 { Flow, Circle, Square, Grid, RoundSquare, Diamond }; 8 | 9 | void DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor); 10 | 11 | } // namespace Drawing 12 | } // namespace ax -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/widgets.cpp: -------------------------------------------------------------------------------- 1 | # define IMGUI_DEFINE_MATH_OPERATORS 2 | # include "widgets.h" 3 | # include 4 | 5 | void ax::Widgets::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color/* = ImVec4(1, 1, 1, 1)*/, const ImVec4& innerColor/* = ImVec4(0, 0, 0, 0)*/) 6 | { 7 | if (ImGui::IsRectVisible(size)) 8 | { 9 | auto cursorPos = ImGui::GetCursorScreenPos(); 10 | auto drawList = ImGui::GetWindowDrawList(); 11 | ax::Drawing::DrawIcon(drawList, cursorPos, cursorPos + size, type, filled, ImColor(color), ImColor(innerColor)); 12 | } 13 | 14 | ImGui::Dummy(size); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/blueprints-example/utilities/widgets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "drawing.h" 4 | 5 | namespace ax { 6 | namespace Widgets { 7 | 8 | using Drawing::IconType; 9 | 10 | void Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color = ImVec4(1, 1, 1, 1), const ImVec4& innerColor = ImVec4(0, 0, 0, 0)); 11 | 12 | } // namespace Widgets 13 | } // namespace ax -------------------------------------------------------------------------------- /examples/canvas-example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_example_executable(canvas-example 2 | canvas-example.cpp 3 | ) 4 | 5 | #target_link_libraries(Canvas PRIVATE imgui_canvas) -------------------------------------------------------------------------------- /examples/canvas-example/canvas-example.cpp: -------------------------------------------------------------------------------- 1 | # define IMGUI_DEFINE_MATH_OPERATORS 2 | # include 3 | # include 4 | # include 5 | # include 6 | 7 | static void DrawScale(const ImVec2& from, const ImVec2& to, float majorUnit, float minorUnit, float labelAlignment, float sign = 1.0f) 8 | { 9 | auto drawList = ImGui::GetWindowDrawList(); 10 | auto direction = (to - from) * ImInvLength(to - from, 0.0f); 11 | auto normal = ImVec2(-direction.y, direction.x); 12 | auto distance = sqrtf(ImLengthSqr(to - from)); 13 | 14 | if (ImDot(direction, direction) < FLT_EPSILON) 15 | return; 16 | 17 | auto minorSize = 5.0f; 18 | auto majorSize = 10.0f; 19 | auto labelDistance = 8.0f; 20 | 21 | drawList->AddLine(from, to, IM_COL32(255, 255, 255, 255)); 22 | 23 | auto p = from; 24 | for (auto d = 0.0f; d <= distance; d += minorUnit, p += direction * minorUnit) 25 | drawList->AddLine(p - normal * minorSize, p + normal * minorSize, IM_COL32(255, 255, 255, 255)); 26 | 27 | for (auto d = 0.0f; d <= distance + majorUnit; d += majorUnit) 28 | { 29 | p = from + direction * d; 30 | 31 | drawList->AddLine(p - normal * majorSize, p + normal * majorSize, IM_COL32(255, 255, 255, 255)); 32 | 33 | if (d == 0.0f) 34 | continue; 35 | 36 | char label[16]; 37 | snprintf(label, 15, "%g", d * sign); 38 | auto labelSize = ImGui::CalcTextSize(label); 39 | 40 | auto labelPosition = p + ImVec2(fabsf(normal.x), fabsf(normal.y)) * labelDistance; 41 | auto labelAlignedSize = ImDot(labelSize, direction); 42 | labelPosition += direction * (-labelAlignedSize + labelAlignment * labelAlignedSize * 2.0f); 43 | labelPosition = ImFloor(labelPosition + ImVec2(0.5f, 0.5f)); 44 | 45 | drawList->AddText(labelPosition, IM_COL32(255, 255, 255, 255), label); 46 | } 47 | } 48 | 49 | static bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f) 50 | { 51 | using namespace ImGui; 52 | ImGuiContext& g = *GImGui; 53 | ImGuiWindow* window = g.CurrentWindow; 54 | ImGuiID id = window->GetID("##Splitter"); 55 | ImRect bb; 56 | bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1)); 57 | bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f); 58 | return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f); 59 | } 60 | 61 | struct Example: 62 | public Application 63 | { 64 | using Application::Application; 65 | 66 | void OnFrame(float deltaTime) override 67 | { 68 | auto& io = ImGui::GetIO(); 69 | 70 | ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f); 71 | 72 | ImGui::Separator(); 73 | 74 | auto availableRegion = ImGui::GetContentRegionAvail(); 75 | 76 | static float s_SplitterSize = 6.0f; 77 | static float s_SplitterArea = 0.0f; 78 | static float s_LeftPaneSize = 0.0f; 79 | static float s_RightPaneSize = 0.0f; 80 | 81 | if (s_SplitterArea != availableRegion.x) 82 | { 83 | if (s_SplitterArea == 0.0f) 84 | { 85 | s_SplitterArea = availableRegion.x; 86 | s_LeftPaneSize = ImFloor(availableRegion.x * 0.25f); 87 | s_RightPaneSize = availableRegion.x - s_LeftPaneSize - s_SplitterSize; 88 | } 89 | else 90 | { 91 | auto ratio = availableRegion.x / s_SplitterArea; 92 | s_SplitterArea = availableRegion.x; 93 | s_LeftPaneSize = s_LeftPaneSize * ratio; 94 | s_RightPaneSize = availableRegion.x - s_LeftPaneSize - s_SplitterSize; 95 | } 96 | } 97 | 98 | static ImGuiEx::Canvas canvas; 99 | static ImVec2 drawStartPoint; 100 | static bool isDragging = false; 101 | static ImRect panelRect; 102 | 103 | Splitter(true, s_SplitterSize, &s_LeftPaneSize, &s_RightPaneSize, 100.0f, 100.0f); 104 | 105 | auto canvasRect = canvas.Rect(); 106 | auto viewRect = canvas.ViewRect(); 107 | auto viewOrigin = canvas.ViewOrigin(); 108 | auto viewScale = canvas.ViewScale(); 109 | 110 | ImGui::BeginChild("##top", ImVec2(s_LeftPaneSize, -1), false, ImGuiWindowFlags_NoScrollWithMouse); 111 | 112 | ImGui::TextUnformatted("Rect:"); 113 | ImGui::BeginColumns("rect", 2, ImGuiOldColumnFlags_NoBorder); 114 | ImGui::SetColumnWidth(0, ImGui::CalcTextSize("\t\tL: 0000.00\t").x); 115 | ImGui::Text("\tL: %.2f", canvasRect.Min.x); ImGui::NextColumn(); 116 | ImGui::Text("\tT: %.2f", canvasRect.Min.y); ImGui::NextColumn(); 117 | ImGui::Text("\tR: %.2f", canvasRect.Max.x); ImGui::NextColumn(); 118 | ImGui::Text("\tB: %.2f", canvasRect.Max.y); ImGui::NextColumn(); 119 | ImGui::Text("\tW: %.2f", canvasRect.GetWidth()); ImGui::NextColumn(); 120 | ImGui::Text("\tH: %.2f", canvasRect.GetHeight()); ImGui::NextColumn(); 121 | ImGui::EndColumns(); 122 | 123 | ImGui::TextUnformatted("View Rect:"); 124 | ImGui::BeginColumns("viewrect", 2, ImGuiOldColumnFlags_NoBorder); 125 | ImGui::SetColumnWidth(0, ImGui::CalcTextSize("\t\tL: 0000.00\t").x); 126 | ImGui::Text("\tL: %.2f", viewRect.Min.x); ImGui::NextColumn(); 127 | ImGui::Text("\tT: %.2f", viewRect.Min.y); ImGui::NextColumn(); 128 | ImGui::Text("\tR: %.2f", viewRect.Max.x); ImGui::NextColumn(); 129 | ImGui::Text("\tB: %.2f", viewRect.Max.y); ImGui::NextColumn(); 130 | ImGui::Text("\tW: %.2f", viewRect.GetWidth()); ImGui::NextColumn(); 131 | ImGui::Text("\tH: %.2f", viewRect.GetHeight()); ImGui::NextColumn(); 132 | ImGui::EndColumns(); 133 | 134 | ImGui::TextUnformatted("Origin:"); 135 | ImGui::Indent(); 136 | auto originChanged = false; 137 | ImGui::PushItemWidth(-ImGui::GetStyle().IndentSpacing); 138 | originChanged |= ImGui::DragFloat("##originx", &viewOrigin.x, 1.0f); 139 | originChanged |= ImGui::DragFloat("##originy", &viewOrigin.y, 1.0f); 140 | if (originChanged) canvas.SetView(viewOrigin, viewScale); 141 | ImGui::PopItemWidth(); 142 | ImGui::Unindent(); 143 | 144 | ImGui::TextUnformatted("Scale:"); 145 | ImGui::Indent(); 146 | ImGui::PushItemWidth(-ImGui::GetStyle().IndentSpacing); 147 | if (ImGui::DragFloat("##scale", &viewScale, 0.01f, 0.01f, 15.0f)) 148 | canvas.SetView(viewOrigin, viewScale); 149 | ImGui::PopItemWidth(); 150 | ImGui::Unindent(); 151 | 152 | ImGui::Separator(); 153 | 154 | if (ImGui::Button("Center over Panel", ImVec2(s_LeftPaneSize, 0))) 155 | canvas.CenterView(panelRect.GetCenter()); 156 | 157 | if (ImGui::Button("Center and zoom to Panel", ImVec2(s_LeftPaneSize, 0))) 158 | canvas.CenterView(panelRect); 159 | 160 | ImGui::TextUnformatted("Panel Rect:"); 161 | ImGui::BeginColumns("panelrect", 2, ImGuiOldColumnFlags_NoBorder); 162 | ImGui::SetColumnWidth(0, ImGui::CalcTextSize("\t\tL: 0000.00\t").x); 163 | ImGui::Text("\tL: %.2f", panelRect.Min.x); ImGui::NextColumn(); 164 | ImGui::Text("\tT: %.2f", panelRect.Min.y); ImGui::NextColumn(); 165 | ImGui::Text("\tR: %.2f", panelRect.Max.x); ImGui::NextColumn(); 166 | ImGui::Text("\tB: %.2f", panelRect.Max.y); ImGui::NextColumn(); 167 | ImGui::Text("\tW: %.2f", panelRect.GetWidth()); ImGui::NextColumn(); 168 | ImGui::Text("\tH: %.2f", panelRect.GetHeight()); ImGui::NextColumn(); 169 | ImGui::EndColumns(); 170 | 171 | ImGui::EndChild(); 172 | 173 | ImGui::SameLine(0.0f, s_SplitterSize); 174 | 175 | 176 | if (canvas.Begin("##mycanvas", ImVec2(s_RightPaneSize, 0.0f))) 177 | { 178 | //auto drawList = ImGui::GetWindowDrawList(); 179 | 180 | if ((isDragging || ImGui::IsItemHovered()) && ImGui::IsMouseDragging(1, 0.0f)) 181 | { 182 | if (!isDragging) 183 | { 184 | isDragging = true; 185 | drawStartPoint = viewOrigin; 186 | } 187 | 188 | canvas.SetView(drawStartPoint + ImGui::GetMouseDragDelta(1, 0.0f) * viewScale, viewScale); 189 | } 190 | else if (isDragging) 191 | isDragging = false; 192 | 193 | viewRect = canvas.ViewRect(); 194 | 195 | if (viewRect.Max.x > 0.0f) 196 | DrawScale(ImVec2(0.0f, 0.0f), ImVec2(viewRect.Max.x, 0.0f), 100.0f, 10.0f, 0.6f); 197 | if (viewRect.Min.x < 0.0f) 198 | DrawScale(ImVec2(0.0f, 0.0f), ImVec2(viewRect.Min.x, 0.0f), 100.0f, 10.0f, 0.6f, -1.0f); 199 | if (viewRect.Max.y > 0.0f) 200 | DrawScale(ImVec2(0.0f, 0.0f), ImVec2(0.0f, viewRect.Max.y), 100.0f, 10.0f, 0.6f); 201 | if (viewRect.Min.y < 0.0f) 202 | DrawScale(ImVec2(0.0f, 0.0f), ImVec2(0.0f, viewRect.Min.y), 100.0f, 10.0f, 0.6f, -1.0f); 203 | 204 | ImGui::Text("Hovered: %d", ImGui::IsItemHovered() ? 1 : 0); 205 | 206 | ImGui::TextUnformatted("Hello World!"); 207 | 208 | ImGui::Bullet(); 209 | 210 | ImGui::Button("Panel", ImVec2(s_RightPaneSize * 0.75f, availableRegion.y * 0.5f) * 0.5f); 211 | panelRect.Min = ImGui::GetItemRectMin(); 212 | panelRect.Max = ImGui::GetItemRectMax(); 213 | 214 | canvas.End(); 215 | } 216 | 217 | 218 | 219 | 220 | 221 | 222 | //ed::SetCurrentEditor(g_Context); 223 | //ed::Begin("My Editor", ImVec2(0.0, 0.0f)); 224 | //int uniqueId = 1; 225 | //// Start drawing nodes. 226 | //ed::BeginNode(uniqueId++); 227 | // ImGui::Text("Node A"); 228 | // ed::BeginPin(uniqueId++, ed::PinKind::Input); 229 | // ImGui::Text("-> In"); 230 | // ed::EndPin(); 231 | // ImGui::SameLine(); 232 | // ed::BeginPin(uniqueId++, ed::PinKind::Output); 233 | // ImGui::Text("Out ->"); 234 | // ed::EndPin(); 235 | //ed::EndNode(); 236 | //ed::End(); 237 | //ed::SetCurrentEditor(nullptr); 238 | 239 | //ImGui::ShowMetricsWindow(); 240 | } 241 | }; 242 | 243 | int Main(int argc, char** argv) 244 | { 245 | Example exampe("Canvas", argc, argv); 246 | 247 | if (exampe.Create()) 248 | return exampe.Run(); 249 | 250 | return 0; 251 | } -------------------------------------------------------------------------------- /examples/data/Cuprum-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/data/Cuprum-Bold.ttf -------------------------------------------------------------------------------- /examples/data/Cuprum-OFL.txt: -------------------------------------------------------------------------------- 1 | Copyright 2010 The Cuprum Project Authors (lemonad@jovanny.ru), with Reserved Font Name "Cuprum". 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /examples/data/Oswald-OFL.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016 The Oswald Project Authors (https://github.com/googlefonts/OswaldFont) 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /examples/data/Oswald-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/data/Oswald-Regular.ttf -------------------------------------------------------------------------------- /examples/data/Play-OFL.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Jonas Hecksher, Playtypes, e-types AS (lasse@e-types.com), with Reserved Font Name 'Play', 'Playtype', 'Playtype Sans'. 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /examples/data/Play-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/examples/data/Play-Regular.ttf -------------------------------------------------------------------------------- /examples/simple-example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_example_executable(simple-example 2 | simple-example.cpp 3 | ) -------------------------------------------------------------------------------- /examples/simple-example/simple-example.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | namespace ed = ax::NodeEditor; 6 | 7 | struct Example: 8 | public Application 9 | { 10 | using Application::Application; 11 | 12 | void OnStart() override 13 | { 14 | ed::Config config; 15 | config.SettingsFile = "Simple.json"; 16 | m_Context = ed::CreateEditor(&config); 17 | } 18 | 19 | void OnStop() override 20 | { 21 | ed::DestroyEditor(m_Context); 22 | } 23 | 24 | void OnFrame(float deltaTime) override 25 | { 26 | auto& io = ImGui::GetIO(); 27 | 28 | ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f); 29 | 30 | ImGui::Separator(); 31 | 32 | ed::SetCurrentEditor(m_Context); 33 | ed::Begin("My Editor", ImVec2(0.0, 0.0f)); 34 | int uniqueId = 1; 35 | // Start drawing nodes. 36 | ed::BeginNode(uniqueId++); 37 | ImGui::Text("Node A"); 38 | ed::BeginPin(uniqueId++, ed::PinKind::Input); 39 | ImGui::Text("-> In"); 40 | ed::EndPin(); 41 | ImGui::SameLine(); 42 | ed::BeginPin(uniqueId++, ed::PinKind::Output); 43 | ImGui::Text("Out ->"); 44 | ed::EndPin(); 45 | ed::EndNode(); 46 | ed::End(); 47 | ed::SetCurrentEditor(nullptr); 48 | 49 | //ImGui::ShowMetricsWindow(); 50 | } 51 | 52 | ed::EditorContext* m_Context = nullptr; 53 | }; 54 | 55 | int Main(int argc, char** argv) 56 | { 57 | Example exampe("Simple", argc, argv); 58 | 59 | if (exampe.Create()) 60 | return exampe.Run(); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /examples/widgets-example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_example_executable(widgets-example 2 | widgets-example.cpp 3 | ) -------------------------------------------------------------------------------- /external/DXSDK/include/D3DX11.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx11.h 6 | // Content: D3DX11 utility library 7 | // 8 | ////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifdef __D3DX11_INTERNAL__ 11 | #error Incorrect D3DX11 header used 12 | #endif 13 | 14 | #ifndef __D3DX11_H__ 15 | #define __D3DX11_H__ 16 | 17 | 18 | // Defines 19 | #include 20 | #include 21 | 22 | #ifdef ALLOW_THROWING_NEW 23 | #include 24 | #endif 25 | 26 | #define D3DX11_DEFAULT ((UINT) -1) 27 | #define D3DX11_FROM_FILE ((UINT) -3) 28 | #define DXGI_FORMAT_FROM_FILE ((DXGI_FORMAT) -3) 29 | 30 | #ifndef D3DX11INLINE 31 | #ifdef _MSC_VER 32 | #if (_MSC_VER >= 1200) 33 | #define D3DX11INLINE __forceinline 34 | #else 35 | #define D3DX11INLINE __inline 36 | #endif 37 | #else 38 | #ifdef __cplusplus 39 | #define D3DX11INLINE inline 40 | #else 41 | #define D3DX11INLINE 42 | #endif 43 | #endif 44 | #endif 45 | 46 | 47 | 48 | // Includes 49 | #include "d3d11.h" 50 | #include "d3dx11.h" 51 | #include "d3dx11core.h" 52 | #include "d3dx11tex.h" 53 | #include "d3dx11async.h" 54 | 55 | 56 | // Errors 57 | #define _FACDD 0x876 58 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) 59 | 60 | enum _D3DX11_ERR { 61 | D3DX11_ERR_CANNOT_MODIFY_INDEX_BUFFER = MAKE_DDHRESULT(2900), 62 | D3DX11_ERR_INVALID_MESH = MAKE_DDHRESULT(2901), 63 | D3DX11_ERR_CANNOT_ATTR_SORT = MAKE_DDHRESULT(2902), 64 | D3DX11_ERR_SKINNING_NOT_SUPPORTED = MAKE_DDHRESULT(2903), 65 | D3DX11_ERR_TOO_MANY_INFLUENCES = MAKE_DDHRESULT(2904), 66 | D3DX11_ERR_INVALID_DATA = MAKE_DDHRESULT(2905), 67 | D3DX11_ERR_LOADED_MESH_HAS_NO_DATA = MAKE_DDHRESULT(2906), 68 | D3DX11_ERR_DUPLICATE_NAMED_FRAGMENT = MAKE_DDHRESULT(2907), 69 | D3DX11_ERR_CANNOT_REMOVE_LAST_ITEM = MAKE_DDHRESULT(2908), 70 | }; 71 | 72 | 73 | #endif //__D3DX11_H__ 74 | 75 | -------------------------------------------------------------------------------- /external/DXSDK/include/D3DX11async.h: -------------------------------------------------------------------------------- 1 | 2 | ////////////////////////////////////////////////////////////////////////////// 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | // 6 | // File: D3DX11Async.h 7 | // Content: D3DX11 Asynchronous Shader loaders / compilers 8 | // 9 | ////////////////////////////////////////////////////////////////////////////// 10 | 11 | #ifndef __D3DX11ASYNC_H__ 12 | #define __D3DX11ASYNC_H__ 13 | 14 | #include "d3dx11.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif //__cplusplus 19 | 20 | 21 | //---------------------------------------------------------------------------- 22 | // D3DX11Compile: 23 | // ------------------ 24 | // Compiles an effect or shader. 25 | // 26 | // Parameters: 27 | // pSrcFile 28 | // Source file name. 29 | // hSrcModule 30 | // Module handle. if NULL, current module will be used. 31 | // pSrcResource 32 | // Resource name in module. 33 | // pSrcData 34 | // Pointer to source code. 35 | // SrcDataLen 36 | // Size of source code, in bytes. 37 | // pDefines 38 | // Optional NULL-terminated array of preprocessor macro definitions. 39 | // pInclude 40 | // Optional interface pointer to use for handling #include directives. 41 | // If this parameter is NULL, #includes will be honored when compiling 42 | // from file, and will error when compiling from resource or memory. 43 | // pFunctionName 44 | // Name of the entrypoint function where execution should begin. 45 | // pProfile 46 | // Instruction set to be used when generating code. Currently supported 47 | // profiles are "vs_1_1", "vs_2_0", "vs_2_a", "vs_2_sw", "vs_3_0", 48 | // "vs_3_sw", "vs_4_0", "vs_4_1", 49 | // "ps_2_0", "ps_2_a", "ps_2_b", "ps_2_sw", "ps_3_0", 50 | // "ps_3_sw", "ps_4_0", "ps_4_1", 51 | // "gs_4_0", "gs_4_1", 52 | // "tx_1_0", 53 | // "fx_4_0", "fx_4_1" 54 | // Note that this entrypoint does not compile fx_2_0 targets, for that 55 | // you need to use the D3DX9 function. 56 | // Flags1 57 | // See D3D10_SHADER_xxx flags. 58 | // Flags2 59 | // See D3D10_EFFECT_xxx flags. 60 | // ppShader 61 | // Returns a buffer containing the created shader. This buffer contains 62 | // the compiled shader code, as well as any embedded debug and symbol 63 | // table info. (See D3D10GetShaderConstantTable) 64 | // ppErrorMsgs 65 | // Returns a buffer containing a listing of errors and warnings that were 66 | // encountered during the compile. If you are running in a debugger, 67 | // these are the same messages you will see in your debug output. 68 | // pHResult 69 | // Pointer to a memory location to receive the return value upon completion. 70 | // Maybe NULL if not needed. 71 | // If pPump != NULL, pHResult must be a valid memory location until the 72 | // the asynchronous execution completes. 73 | //---------------------------------------------------------------------------- 74 | 75 | HRESULT WINAPI D3DX11CompileFromFileA(LPCSTR pSrcFile,CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, 76 | LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 77 | 78 | HRESULT WINAPI D3DX11CompileFromFileW(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, 79 | LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 80 | 81 | #ifdef UNICODE 82 | #define D3DX11CompileFromFile D3DX11CompileFromFileW 83 | #else 84 | #define D3DX11CompileFromFile D3DX11CompileFromFileA 85 | #endif 86 | 87 | HRESULT WINAPI D3DX11CompileFromResourceA(HMODULE hSrcModule, LPCSTR pSrcResource, LPCSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines, 88 | LPD3D10INCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 89 | 90 | HRESULT WINAPI D3DX11CompileFromResourceW(HMODULE hSrcModule, LPCWSTR pSrcResource, LPCWSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines, 91 | LPD3D10INCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 92 | 93 | #ifdef UNICODE 94 | #define D3DX11CompileFromResource D3DX11CompileFromResourceW 95 | #else 96 | #define D3DX11CompileFromResource D3DX11CompileFromResourceA 97 | #endif 98 | 99 | HRESULT WINAPI D3DX11CompileFromMemory(LPCSTR pSrcData, SIZE_T SrcDataLen, LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, 100 | LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 101 | 102 | HRESULT WINAPI D3DX11PreprocessShaderFromFileA(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, 103 | LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 104 | 105 | HRESULT WINAPI D3DX11PreprocessShaderFromFileW(LPCWSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, 106 | LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 107 | 108 | HRESULT WINAPI D3DX11PreprocessShaderFromMemory(LPCSTR pSrcData, SIZE_T SrcDataSize, LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, 109 | LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 110 | 111 | HRESULT WINAPI D3DX11PreprocessShaderFromResourceA(HMODULE hModule, LPCSTR pResourceName, LPCSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines, 112 | LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 113 | 114 | HRESULT WINAPI D3DX11PreprocessShaderFromResourceW(HMODULE hModule, LPCWSTR pResourceName, LPCWSTR pSrcFileName, CONST D3D10_SHADER_MACRO* pDefines, 115 | LPD3D10INCLUDE pInclude, ID3DX11ThreadPump *pPump, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult); 116 | 117 | #ifdef UNICODE 118 | #define D3DX11PreprocessShaderFromFile D3DX11PreprocessShaderFromFileW 119 | #define D3DX11PreprocessShaderFromResource D3DX11PreprocessShaderFromResourceW 120 | #else 121 | #define D3DX11PreprocessShaderFromFile D3DX11PreprocessShaderFromFileA 122 | #define D3DX11PreprocessShaderFromResource D3DX11PreprocessShaderFromResourceA 123 | #endif 124 | 125 | //---------------------------------------------------------------------------- 126 | // Async processors 127 | //---------------------------------------------------------------------------- 128 | 129 | HRESULT WINAPI D3DX11CreateAsyncCompilerProcessor(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, 130 | LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, 131 | ID3D10Blob **ppCompiledShader, ID3D10Blob **ppErrorBuffer, ID3DX11DataProcessor **ppProcessor); 132 | 133 | HRESULT WINAPI D3DX11CreateAsyncShaderPreprocessProcessor(LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, 134 | ID3D10Blob** ppShaderText, ID3D10Blob **ppErrorBuffer, ID3DX11DataProcessor **ppProcessor); 135 | 136 | //---------------------------------------------------------------------------- 137 | // D3DX11 Asynchronous texture I/O (advanced mode) 138 | //---------------------------------------------------------------------------- 139 | 140 | HRESULT WINAPI D3DX11CreateAsyncFileLoaderW(LPCWSTR pFileName, ID3DX11DataLoader **ppDataLoader); 141 | HRESULT WINAPI D3DX11CreateAsyncFileLoaderA(LPCSTR pFileName, ID3DX11DataLoader **ppDataLoader); 142 | HRESULT WINAPI D3DX11CreateAsyncMemoryLoader(LPCVOID pData, SIZE_T cbData, ID3DX11DataLoader **ppDataLoader); 143 | HRESULT WINAPI D3DX11CreateAsyncResourceLoaderW(HMODULE hSrcModule, LPCWSTR pSrcResource, ID3DX11DataLoader **ppDataLoader); 144 | HRESULT WINAPI D3DX11CreateAsyncResourceLoaderA(HMODULE hSrcModule, LPCSTR pSrcResource, ID3DX11DataLoader **ppDataLoader); 145 | 146 | #ifdef UNICODE 147 | #define D3DX11CreateAsyncFileLoader D3DX11CreateAsyncFileLoaderW 148 | #define D3DX11CreateAsyncResourceLoader D3DX11CreateAsyncResourceLoaderW 149 | #else 150 | #define D3DX11CreateAsyncFileLoader D3DX11CreateAsyncFileLoaderA 151 | #define D3DX11CreateAsyncResourceLoader D3DX11CreateAsyncResourceLoaderA 152 | #endif 153 | 154 | HRESULT WINAPI D3DX11CreateAsyncTextureProcessor(ID3D11Device *pDevice, D3DX11_IMAGE_LOAD_INFO *pLoadInfo, ID3DX11DataProcessor **ppDataProcessor); 155 | HRESULT WINAPI D3DX11CreateAsyncTextureInfoProcessor(D3DX11_IMAGE_INFO *pImageInfo, ID3DX11DataProcessor **ppDataProcessor); 156 | HRESULT WINAPI D3DX11CreateAsyncShaderResourceViewProcessor(ID3D11Device *pDevice, D3DX11_IMAGE_LOAD_INFO *pLoadInfo, ID3DX11DataProcessor **ppDataProcessor); 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif //__cplusplus 161 | 162 | #endif //__D3DX11ASYNC_H__ 163 | 164 | 165 | -------------------------------------------------------------------------------- /external/DXSDK/include/D3DX11core.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx11core.h 6 | // Content: D3DX11 core types and functions 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx11.h" 11 | 12 | #ifndef __D3DX11CORE_H__ 13 | #define __D3DX11CORE_H__ 14 | 15 | // Current name of the DLL shipped in the same SDK as this header. 16 | 17 | 18 | #define D3DX11_DLL_W L"d3dx11_43.dll" 19 | #define D3DX11_DLL_A "d3dx11_43.dll" 20 | 21 | #ifdef UNICODE 22 | #define D3DX11_DLL D3DX11_DLL_W 23 | #else 24 | #define D3DX11_DLL D3DX11_DLL_A 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif //__cplusplus 30 | 31 | /////////////////////////////////////////////////////////////////////////// 32 | // D3DX11_SDK_VERSION: 33 | // ----------------- 34 | // This identifier is passed to D3DX11CheckVersion in order to ensure that an 35 | // application was built against the correct header files and lib files. 36 | // This number is incremented whenever a header (or other) change would 37 | // require applications to be rebuilt. If the version doesn't match, 38 | // D3DX11CreateVersion will return FALSE. (The number itself has no meaning.) 39 | /////////////////////////////////////////////////////////////////////////// 40 | 41 | 42 | #define D3DX11_SDK_VERSION 43 43 | 44 | 45 | #ifdef D3D_DIAG_DLL 46 | BOOL WINAPI D3DX11DebugMute(BOOL Mute); 47 | #endif 48 | HRESULT WINAPI D3DX11CheckVersion(UINT D3DSdkVersion, UINT D3DX11SdkVersion); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif //__cplusplus 53 | 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////////// 57 | // ID3DX11ThreadPump: 58 | ////////////////////////////////////////////////////////////////////////////// 59 | 60 | #undef INTERFACE 61 | #define INTERFACE ID3DX11DataLoader 62 | 63 | DECLARE_INTERFACE(ID3DX11DataLoader) 64 | { 65 | STDMETHOD(Load)(THIS) PURE; 66 | STDMETHOD(Decompress)(THIS_ void **ppData, SIZE_T *pcBytes) PURE; 67 | STDMETHOD(Destroy)(THIS) PURE; 68 | }; 69 | 70 | #undef INTERFACE 71 | #define INTERFACE ID3DX11DataProcessor 72 | 73 | DECLARE_INTERFACE(ID3DX11DataProcessor) 74 | { 75 | STDMETHOD(Process)(THIS_ void *pData, SIZE_T cBytes) PURE; 76 | STDMETHOD(CreateDeviceObject)(THIS_ void **ppDataObject) PURE; 77 | STDMETHOD(Destroy)(THIS) PURE; 78 | }; 79 | 80 | // {C93FECFA-6967-478a-ABBC-402D90621FCB} 81 | DEFINE_GUID(IID_ID3DX11ThreadPump, 82 | 0xc93fecfa, 0x6967, 0x478a, 0xab, 0xbc, 0x40, 0x2d, 0x90, 0x62, 0x1f, 0xcb); 83 | 84 | #undef INTERFACE 85 | #define INTERFACE ID3DX11ThreadPump 86 | 87 | DECLARE_INTERFACE_(ID3DX11ThreadPump, IUnknown) 88 | { 89 | // IUnknown 90 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 91 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 92 | STDMETHOD_(ULONG, Release)(THIS) PURE; 93 | 94 | // ID3DX11ThreadPump 95 | STDMETHOD(AddWorkItem)(THIS_ ID3DX11DataLoader *pDataLoader, ID3DX11DataProcessor *pDataProcessor, HRESULT *pHResult, void **ppDeviceObject) PURE; 96 | STDMETHOD_(UINT, GetWorkItemCount)(THIS) PURE; 97 | 98 | STDMETHOD(WaitForAllItems)(THIS) PURE; 99 | STDMETHOD(ProcessDeviceWorkItems)(THIS_ UINT iWorkItemCount); 100 | 101 | STDMETHOD(PurgeAllItems)(THIS) PURE; 102 | STDMETHOD(GetQueueStatus)(THIS_ UINT *pIoQueue, UINT *pProcessQueue, UINT *pDeviceQueue) PURE; 103 | 104 | }; 105 | 106 | #ifdef __cplusplus 107 | extern "C" { 108 | #endif //__cplusplus 109 | 110 | HRESULT WINAPI D3DX11CreateThreadPump(UINT cIoThreads, UINT cProcThreads, ID3DX11ThreadPump **ppThreadPump); 111 | 112 | HRESULT WINAPI D3DX11UnsetAllDeviceObjects(ID3D11DeviceContext *pContext); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif //__cplusplus 117 | 118 | /////////////////////////////////////////////////////////////////////////// 119 | 120 | #define _FACD3D 0x876 121 | #define MAKE_D3DHRESULT( code ) MAKE_HRESULT( 1, _FACD3D, code ) 122 | #define MAKE_D3DSTATUS( code ) MAKE_HRESULT( 0, _FACD3D, code ) 123 | 124 | #define D3DERR_INVALIDCALL MAKE_D3DHRESULT(2156) 125 | #define D3DERR_WASSTILLDRAWING MAKE_D3DHRESULT(540) 126 | 127 | #endif //__D3DX11CORE_H__ 128 | 129 | -------------------------------------------------------------------------------- /external/DXSDK/include/dxerr.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DXErr.h 3 | // 4 | // DirectX Error Library 5 | // 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 7 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 8 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 9 | // PARTICULAR PURPOSE. 10 | // 11 | // Copyright (c) Microsoft Corporation. All rights reserved. 12 | //-------------------------------------------------------------------------------------- 13 | 14 | // This version only supports UNICODE. 15 | 16 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | //-------------------------------------------------------------------------------------- 26 | // DXGetErrorString 27 | //-------------------------------------------------------------------------------------- 28 | const WCHAR* WINAPI DXGetErrorStringW( _In_ HRESULT hr ); 29 | 30 | #define DXGetErrorString DXGetErrorStringW 31 | 32 | //-------------------------------------------------------------------------------------- 33 | // DXGetErrorDescription has to be modified to return a copy in a buffer rather than 34 | // the original static string. 35 | //-------------------------------------------------------------------------------------- 36 | void WINAPI DXGetErrorDescriptionW( _In_ HRESULT hr, _Out_cap_(count) WCHAR* desc, _In_ size_t count ); 37 | 38 | #define DXGetErrorDescription DXGetErrorDescriptionW 39 | 40 | //-------------------------------------------------------------------------------------- 41 | // DXTrace 42 | // 43 | // Desc: Outputs a formatted error message to the debug stream 44 | // 45 | // Args: WCHAR* strFile The current file, typically passed in using the 46 | // __FILEW__ macro. 47 | // DWORD dwLine The current line number, typically passed in using the 48 | // __LINE__ macro. 49 | // HRESULT hr An HRESULT that will be traced to the debug stream. 50 | // CHAR* strMsg A string that will be traced to the debug stream (may be NULL) 51 | // BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. 52 | // 53 | // Return: The hr that was passed in. 54 | //-------------------------------------------------------------------------------------- 55 | HRESULT WINAPI DXTraceW( _In_z_ const WCHAR* strFile, _In_ DWORD dwLine, _In_ HRESULT hr, _In_opt_ const WCHAR* strMsg, _In_ bool bPopMsgBox ); 56 | 57 | #define DXTrace DXTraceW 58 | 59 | //-------------------------------------------------------------------------------------- 60 | // 61 | // Helper macros 62 | // 63 | //-------------------------------------------------------------------------------------- 64 | #if defined(DEBUG) || defined(_DEBUG) 65 | #define DXTRACE_MSG(str) DXTrace( __FILEW__, (DWORD)__LINE__, 0, str, false ) 66 | #define DXTRACE_ERR(str,hr) DXTrace( __FILEW__, (DWORD)__LINE__, hr, str, false ) 67 | #define DXTRACE_ERR_MSGBOX(str,hr) DXTrace( __FILEW__, (DWORD)__LINE__, hr, str, true ) 68 | #else 69 | #define DXTRACE_MSG(str) (0L) 70 | #define DXTRACE_ERR(str,hr) (hr) 71 | #define DXTRACE_ERR_MSGBOX(str,hr) (hr) 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif //__cplusplus 77 | -------------------------------------------------------------------------------- /external/DXSDK/lib/x64/d3dx11.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/external/DXSDK/lib/x64/d3dx11.lib -------------------------------------------------------------------------------- /external/DXSDK/lib/x64/d3dx11d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/external/DXSDK/lib/x64/d3dx11d.lib -------------------------------------------------------------------------------- /external/DXSDK/lib/x86/d3dx11.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/external/DXSDK/lib/x86/d3dx11.lib -------------------------------------------------------------------------------- /external/DXSDK/lib/x86/d3dx11d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedmd/imgui-node-editor/e78e447900909a051817a760efe13fe83e6e1afc/external/DXSDK/lib/x86/d3dx11d.lib -------------------------------------------------------------------------------- /external/ScopeGuard/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ScopeGuard) 2 | 3 | add_library(ScopeGuard INTERFACE) 4 | 5 | set(_ScopeGuard_Sources 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ScopeGuard.h 7 | ) 8 | 9 | target_include_directories(ScopeGuard INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 10 | target_sources(ScopeGuard INTERFACE ${_ScopeGuard_Sources}) 11 | 12 | source_group("ThirdParty\\ScopeGuard" FILES ${_ScopeGuard_Sources}) -------------------------------------------------------------------------------- /external/ScopeGuard/ScopeGuard.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | 3 | # include 4 | 5 | # define AX_CONCATENATE_IMPL(s1, s2) s1##s2 6 | # define AX_CONCATENATE(s1, s2) AX_CONCATENATE_IMPL(s1, s2) 7 | # ifdef __COUNTER__ 8 | # define AX_ANONYMOUS_VARIABLE(str) AX_CONCATENATE(str, __COUNTER__) 9 | # else 10 | # define AX_ANONYMOUS_VARIABLE(str) AX_CONCATENATE(str, __LINE__) 11 | # endif 12 | 13 | namespace ax { 14 | namespace scopeguard_detail { 15 | 16 | enum class ScopeGuardOnExit {}; 17 | template 18 | class ScopeGuard 19 | { 20 | F f_; 21 | bool active_; 22 | public: 23 | ScopeGuard() = delete; 24 | ScopeGuard(const ScopeGuard&) = delete; 25 | ScopeGuard& operator=(const ScopeGuard&) = delete; 26 | ScopeGuard(ScopeGuard&& rhs): f_(std::move(rhs.f_)), active_(rhs.active_) { rhs.dismiss(); } 27 | ScopeGuard(F f): f_(std::move(f)), active_(true) {} 28 | ~ScopeGuard() { if (active_) f_(); } 29 | void dismiss() { active_ = false; } 30 | }; 31 | template 32 | inline ScopeGuard operator+(ScopeGuardOnExit, F&& f) 33 | { 34 | return ScopeGuard(std::forward(f)); 35 | } 36 | 37 | } // namespace scopeguard_detail 38 | } // namespace ax 39 | 40 | # define AX_SCOPE_EXIT \ 41 | auto AX_ANONYMOUS_VARIABLE(AX_SCOPE_EXIT_STATE) \ 42 | = ::ax::scopeguard_detail::ScopeGuardOnExit() + [&]() 43 | -------------------------------------------------------------------------------- /external/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(imgui VERSION 1.76) 2 | 3 | set(_imgui_Sources 4 | imconfig.h 5 | imgui.cpp 6 | imgui.h 7 | imgui.natvis 8 | imgui_demo.cpp 9 | imgui_draw.cpp 10 | imgui_internal.h 11 | imgui_widgets.cpp 12 | imgui_tables.cpp 13 | imstb_rectpack.h 14 | imstb_textedit.h 15 | imstb_truetype.h 16 | LICENSE.txt 17 | ) 18 | 19 | add_library(${PROJECT_NAME} STATIC ${_imgui_Sources}) 20 | 21 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 22 | #target_compile_definitions(${PROJECT_NAME} PUBLIC "ImDrawIdx=unsigned int") 23 | target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS) 24 | 25 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${_imgui_Sources}) 26 | 27 | set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "external") 28 | 29 | -------------------------------------------------------------------------------- /external/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2020 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /external/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // 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. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // 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. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | 32 | //---- Disable all of Dear ImGui or don't implement standard windows. 33 | // It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. 34 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 35 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. 36 | //#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty. 37 | 38 | //---- Don't implement some functions to reduce linkage requirements. 39 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. (imm32.lib/.a) 41 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 42 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 43 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 44 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 45 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 46 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 47 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 48 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 49 | 50 | //---- Include imgui_user.h at the end of imgui.h as a convenience 51 | //#define IMGUI_INCLUDE_IMGUI_USER_H 52 | 53 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 54 | //#define IMGUI_USE_BGRA_PACKED_COLOR 55 | 56 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 57 | //#define IMGUI_USE_WCHAR32 58 | 59 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 60 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 61 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 62 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 63 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 64 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 65 | 66 | //---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 67 | // Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf. 68 | // #define IMGUI_USE_STB_SPRINTF 69 | 70 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 71 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 72 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 73 | //#define IMGUI_ENABLE_FREETYPE 74 | 75 | //---- Use stb_truetype to build and rasterize the font atlas (default) 76 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 77 | //#define IMGUI_ENABLE_STB_TRUETYPE 78 | 79 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 80 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 81 | /* 82 | #define IM_VEC2_CLASS_EXTRA \ 83 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 84 | operator MyVec2() const { return MyVec2(x,y); } 85 | 86 | #define IM_VEC4_CLASS_EXTRA \ 87 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 88 | operator MyVec4() const { return MyVec4(x,y,z,w); } 89 | */ 90 | 91 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 92 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 93 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 94 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 95 | //#define ImDrawIdx unsigned int 96 | 97 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 98 | //struct ImDrawList; 99 | //struct ImDrawCmd; 100 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 101 | //#define ImDrawCallback MyImDrawCallback 102 | 103 | //---- Debug Tools: Macro to break in Debugger 104 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 105 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 106 | //#define IM_DEBUG_BREAK __debugbreak() 107 | 108 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), 109 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) 110 | // This adds a small runtime cost which is why it is not enabled by default. 111 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX 112 | 113 | //---- Debug Tools: Enable slower asserts 114 | //#define IMGUI_DEBUG_PARANOID 115 | 116 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 117 | /* 118 | namespace ImGui 119 | { 120 | void MyFunction(const char* name, const MyMatrix44& v); 121 | } 122 | */ 123 | -------------------------------------------------------------------------------- /external/imgui/imgui.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{Size={Size} Capacity={Capacity}}} 9 | 10 | 11 | Size 12 | Data 13 | 14 | 15 | 16 | 17 | 18 | {{x={x,g} y={y,g}}} 19 | 20 | 21 | 22 | {{x={x,g} y={y,g} z={z,g} w={w,g}}} 23 | 24 | 25 | 26 | {{Min=({Min.x,g} {Min.y,g}) Max=({Max.x,g} {Max.y,g}) Size=({Max.x-Min.x,g} {Max.y-Min.y,g})}} 27 | 28 | Min 29 | Max 30 | Max.x - Min.x 31 | Max.y - Min.y 32 | 33 | 34 | 35 | 36 | {{Name {Name,s} Active {(Active||WasActive)?1:0,d} Child {(Flags & 0x01000000)?1:0,d} Popup {(Flags & 0x04000000)?1:0,d} Hidden {(Hidden)?1:0,d}} 37 | 38 | 39 | 40 | {{ID {ID,x} Pos=({Pos.x,g} {Pos.y,g}) Size=({Size.x,g} {Size.y,g}) Parent {(ParentNode==0)?0:ParentNode->ID,x} Childs {(ChildNodes[0] != 0)+(ChildNodes[1] != 0)} Windows {Windows.Size} } 41 | 42 | 43 | 44 | {{ Cmd={_CmdBuffer.Size} Idx={_IdxBuffer.Size} }} 45 | 46 | 47 | -------------------------------------------------------------------------------- /external/stb_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(stb_image) 2 | 3 | add_library(stb_image INTERFACE) 4 | 5 | set(_stb_image_Sources 6 | ${CMAKE_CURRENT_SOURCE_DIR}/stb_image.h 7 | ) 8 | 9 | target_include_directories(stb_image INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 10 | target_sources(stb_image INTERFACE ${_stb_image_Sources}) 11 | 12 | source_group("ThirdParty\\stb_image" FILES ${_stb_image_Sources}) -------------------------------------------------------------------------------- /imgui_bezier_math.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // VERSION 0.1 3 | // 4 | // LICENSE 5 | // This software is dual-licensed to the public domain and under the following 6 | // license: you are granted a perpetual, irrevocable license to copy, modify, 7 | // publish, and distribute this file as you see fit. 8 | // 9 | // CREDITS 10 | // Written by Michal Cichon 11 | //------------------------------------------------------------------------------ 12 | # ifndef __IMGUI_BEZIER_MATH_H__ 13 | # define __IMGUI_BEZIER_MATH_H__ 14 | # pragma once 15 | 16 | 17 | //------------------------------------------------------------------------------ 18 | # include "imgui_extra_math.h" 19 | 20 | 21 | //------------------------------------------------------------------------------ 22 | template 23 | struct ImCubicBezierPointsT 24 | { 25 | T P0; 26 | T P1; 27 | T P2; 28 | T P3; 29 | }; 30 | using ImCubicBezierPoints = ImCubicBezierPointsT; 31 | 32 | 33 | //------------------------------------------------------------------------------ 34 | // Low-level Bezier curve sampling. 35 | template inline T ImLinearBezier(const T& p0, const T& p1, float t); 36 | template inline T ImLinearBezierDt(const T& p0, const T& p1, float t); 37 | template inline T ImQuadraticBezier(const T& p0, const T& p1, const T& p2, float t); 38 | template inline T ImQuadraticBezierDt(const T& p0, const T& p1, const T& p2, float t); 39 | template inline T ImCubicBezier(const T& p0, const T& p1, const T& p2, const T& p3, float t); 40 | template inline T ImCubicBezierDt(const T& p0, const T& p1, const T& p2, const T& p3, float t); 41 | 42 | 43 | // High-level Bezier sampling, automatically collapse to lower level Bezier curves if control points overlap. 44 | template inline T ImCubicBezierSample(const T& p0, const T& p1, const T& p2, const T& p3, float t); 45 | template inline T ImCubicBezierSample(const ImCubicBezierPointsT& curve, float t); 46 | template inline T ImCubicBezierTangent(const T& p0, const T& p1, const T& p2, const T& p3, float t); 47 | template inline T ImCubicBezierTangent(const ImCubicBezierPointsT& curve, float t); 48 | 49 | 50 | // Calculate approximate length of Cubic Bezier curve. 51 | template inline float ImCubicBezierLength(const T& p0, const T& p1, const T& p2, const T& p3); 52 | template inline float ImCubicBezierLength(const ImCubicBezierPointsT& curve); 53 | 54 | 55 | // Splits Cubic Bezier curve into two curves. 56 | template 57 | struct ImCubicBezierSplitResultT 58 | { 59 | ImCubicBezierPointsT Left; 60 | ImCubicBezierPointsT Right; 61 | }; 62 | using ImCubicBezierSplitResult = ImCubicBezierSplitResultT; 63 | 64 | template inline ImCubicBezierSplitResultT ImCubicBezierSplit(const T& p0, const T& p1, const T& p2, const T& p3, float t); 65 | template inline ImCubicBezierSplitResultT ImCubicBezierSplit(const ImCubicBezierPointsT& curve, float t); 66 | 67 | 68 | // Returns bounding rectangle of Cubic Bezier curve. 69 | inline ImRect ImCubicBezierBoundingRect(const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3); 70 | inline ImRect ImCubicBezierBoundingRect(const ImCubicBezierPoints& curve); 71 | 72 | 73 | // Project point on Cubic Bezier curve. 74 | struct ImProjectResult 75 | { 76 | ImVec2 Point; // Point on curve 77 | float Time; // [0 - 1] 78 | float Distance; // Distance to curve 79 | }; 80 | 81 | inline ImProjectResult ImProjectOnCubicBezier(const ImVec2& p, const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const int subdivisions = 100); 82 | inline ImProjectResult ImProjectOnCubicBezier(const ImVec2& p, const ImCubicBezierPoints& curve, const int subdivisions = 100); 83 | 84 | 85 | // Calculate intersection between line and a Cubic Bezier curve. 86 | struct ImCubicBezierIntersectResult 87 | { 88 | int Count; 89 | ImVec2 Points[3]; 90 | }; 91 | 92 | inline ImCubicBezierIntersectResult ImCubicBezierLineIntersect(const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& a0, const ImVec2& a1); 93 | inline ImCubicBezierIntersectResult ImCubicBezierLineIntersect(const ImCubicBezierPoints& curve, const ImLine& line); 94 | 95 | 96 | // Adaptive Cubic Bezier subdivision. 97 | enum ImCubicBezierSubdivideFlags 98 | { 99 | ImCubicBezierSubdivide_None = 0, 100 | ImCubicBezierSubdivide_SkipFirst = 1 101 | }; 102 | 103 | struct ImCubicBezierSubdivideSample 104 | { 105 | ImVec2 Point; 106 | ImVec2 Tangent; 107 | }; 108 | 109 | using ImCubicBezierSubdivideCallback = void (*)(const ImCubicBezierSubdivideSample& p, void* user_pointer); 110 | 111 | inline void ImCubicBezierSubdivide(ImCubicBezierSubdivideCallback callback, void* user_pointer, const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float tess_tol = -1.0f, ImCubicBezierSubdivideFlags flags = ImCubicBezierSubdivide_None); 112 | inline void ImCubicBezierSubdivide(ImCubicBezierSubdivideCallback callback, void* user_pointer, const ImCubicBezierPoints& curve, float tess_tol = -1.0f, ImCubicBezierSubdivideFlags flags = ImCubicBezierSubdivide_None); 113 | 114 | 115 | // F has signature void(const ImCubicBezierSubdivideSample& p) 116 | template inline void ImCubicBezierSubdivide(F& callback, const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float tess_tol = -1.0f, ImCubicBezierSubdivideFlags flags = ImCubicBezierSubdivide_None); 117 | template inline void ImCubicBezierSubdivide(F& callback, const ImCubicBezierPoints& curve, float tess_tol = -1.0f, ImCubicBezierSubdivideFlags flags = ImCubicBezierSubdivide_None); 118 | 119 | // Fixed step Cubic Bezier subdivision. 120 | struct ImCubicBezierFixedStepSample 121 | { 122 | float T; 123 | float Length; 124 | ImVec2 Point; 125 | bool BreakSearch; 126 | }; 127 | 128 | using ImCubicBezierFixedStepCallback = void (*)(ImCubicBezierFixedStepSample& sample, void* user_pointer); 129 | 130 | inline void ImCubicBezierFixedStep(ImCubicBezierFixedStepCallback callback, void* user_pointer, const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float step, bool overshoot = false, float max_value_error = 1e-3f, float max_t_error = 1e-5f); 131 | inline void ImCubicBezierFixedStep(ImCubicBezierFixedStepCallback callback, void* user_pointer, const ImCubicBezierPoints& curve, float step, bool overshoot = false, float max_value_error = 1e-3f, float max_t_error = 1e-5f); 132 | 133 | 134 | // F has signature void(const ImCubicBezierFixedStepSample& p) 135 | template inline void ImCubicBezierFixedStep(F& callback, const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float step, bool overshoot = false, float max_value_error = 1e-3f, float max_t_error = 1e-5f); 136 | template inline void ImCubicBezierFixedStep(F& callback, const ImCubicBezierPoints& curve, float step, bool overshoot = false, float max_value_error = 1e-3f, float max_t_error = 1e-5f); 137 | 138 | 139 | //------------------------------------------------------------------------------ 140 | # include "imgui_bezier_math.inl" 141 | 142 | 143 | //------------------------------------------------------------------------------ 144 | # endif // __IMGUI_BEZIER_MATH_H__ 145 | -------------------------------------------------------------------------------- /imgui_canvas.h: -------------------------------------------------------------------------------- 1 | // Canvas widget - view over infinite virtual space. 2 | // 3 | // Canvas allows you to draw your widgets anywhere over infinite space and provide 4 | // view over it with support for panning and scaling. 5 | // 6 | // When you enter a canvas ImGui is moved to virtual space which mean: 7 | // - ImGui::GetCursorScreenPos() return (0, 0) and which correspond to top left corner 8 | // of the canvas on the screen (this can be changed using CanvasView()). 9 | // - Mouse input is brought to canvas space, so widgets works as usual. 10 | // - Everything you draw with ImDrawList will be in virtual space. 11 | // 12 | // By default origin point is on top left corner of canvas widget. It can be 13 | // changed with call to CanvasView() where you can specify what part of space 14 | // should be viewed by setting viewport origin point and scale. Current state 15 | // can be queried with CanvasViewOrigin() and CanvasViewScale(). 16 | // 17 | // Viewport size is controlled by 'size' parameter in BeginCanvas(). You can query 18 | // it using CanvasContentMin/Max/Size functions. They are useful if you to not specify 19 | // canvas size in which case all free space is used. 20 | // 21 | // Bounds of visible region of infinite space can be queried using CanvasViewMin/Max/Size 22 | // functions. Everything that is drawn outside of this region will be clipped 23 | // as usual in ImGui. 24 | // 25 | // While drawing inside canvas you can translate position from world (usual ImGui space) 26 | // to virtual space and back using CanvasFromWorld()/CanvasToWorld(). 27 | // 28 | // Canvas can be nested in each other (they are regular widgets after all). There 29 | // is a way to transform position between current and parent canvas with 30 | // CanvasFromParent()/CanvasToParent(). 31 | // 32 | // Sometimes in more elaborate scenarios you want to move out canvas virtual space, 33 | // do something and came back. You can do that with SuspendCanvas() and ResumeCanvas(). 34 | // 35 | // Note: 36 | // It is not valid to call canvas API outside of BeginCanvas() / EndCanvas() scope. 37 | // 38 | // VERSION 0.1 39 | // 40 | // LICENSE 41 | // This software is dual-licensed to the public domain and under the following 42 | // license: you are granted a perpetual, irrevocable license to copy, modify, 43 | // publish, and distribute this file as you see fit. 44 | // 45 | // CREDITS 46 | // Written by Michal Cichon 47 | # ifndef __IMGUI_EX_CANVAS_H__ 48 | # define __IMGUI_EX_CANVAS_H__ 49 | # pragma once 50 | 51 | # include 52 | # include // ImRect, ImFloor 53 | 54 | #ifndef IMGUIEX_CANVAS_API 55 | #define IMGUIEX_CANVAS_API 56 | #endif 57 | 58 | namespace ImGuiEx { 59 | 60 | struct CanvasView 61 | { 62 | ImVec2 Origin; 63 | float Scale = 1.0f; 64 | float InvScale = 1.0f; 65 | 66 | CanvasView() = default; 67 | CanvasView(const ImVec2& origin, float scale) 68 | : Origin(origin) 69 | , Scale(scale) 70 | , InvScale(scale ? 1.0f / scale : 0.0f) 71 | { 72 | } 73 | 74 | void Set(const ImVec2& origin, float scale) 75 | { 76 | *this = CanvasView(origin, scale); 77 | } 78 | }; 79 | 80 | // Canvas widget represent view over infinite plane. 81 | // 82 | // It acts like a child window without scroll bars with 83 | // ability to zoom to specific part of canvas plane. 84 | // 85 | // Widgets are clipped according to current view exactly 86 | // same way ImGui do. To avoid `missing widgets` artifacts first 87 | // setup visible region with SetView() then draw content. 88 | // 89 | // Everything drawn with ImDrawList betwen calls to Begin()/End() 90 | // will be drawn on canvas plane. This behavior can be suspended 91 | // by calling Suspend() and resumed by calling Resume(). 92 | // 93 | // Warning: 94 | // Please do not interleave canvas with use of channel splitter. 95 | // Keep channel splitter contained inside canvas or always 96 | // call canvas functions from same channel. 97 | struct Canvas 98 | { 99 | // Begins drawing content of canvas plane. 100 | // 101 | // When false is returned that mean canvas is not visible to the 102 | // user can drawing should be skipped and End() not called. 103 | // When true is returned drawing must be ended with call to End(). 104 | // 105 | // If any size component is equal to zero or less canvas will 106 | // automatically expand to all available area on that axis. 107 | // So (0, 300) will take horizontal space and have height 108 | // of 300 points. (0, 0) will take all remaining space of 109 | // the window. 110 | // 111 | // You can query size of the canvas while it is being drawn 112 | // by calling Rect(). 113 | IMGUIEX_CANVAS_API bool Begin(const char* id, const ImVec2& size); 114 | IMGUIEX_CANVAS_API bool Begin(ImGuiID id, const ImVec2& size); 115 | 116 | // Ends interaction with canvas plane. 117 | // 118 | // Must be called only when Begin() retuned true. 119 | IMGUIEX_CANVAS_API void End(); 120 | 121 | // Sets visible region of canvas plane. 122 | // 123 | // Origin is an offset of infinite plane origin from top left 124 | // corner of the canvas. 125 | // 126 | // Scale greater than 1 make canvas content be bigger, less than 1 smaller. 127 | IMGUIEX_CANVAS_API void SetView(const ImVec2& origin, float scale); 128 | IMGUIEX_CANVAS_API void SetView(const CanvasView& view); 129 | 130 | // Centers view over specific point on canvas plane. 131 | // 132 | // View will be centered on specific point by changing origin 133 | // but not scale. 134 | IMGUIEX_CANVAS_API void CenterView(const ImVec2& canvasPoint); 135 | 136 | // Calculates view over specific point on canvas plane. 137 | IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImVec2& canvasPoint) const; 138 | 139 | // Centers view over specific rectangle on canvas plane. 140 | // 141 | // Whole rectangle will fit in canvas view. This will affect both 142 | // origin and scale. 143 | IMGUIEX_CANVAS_API void CenterView(const ImRect& canvasRect); 144 | 145 | // Calculates view over specific rectangle on canvas plane. 146 | IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImRect& canvasRect) const; 147 | 148 | // Suspends canvas by returning to normal ImGui transformation space. 149 | // While suspended UI will not be drawn on canvas plane. 150 | // 151 | // Calls to Suspend()/Resume() are symetrical. Each call to Suspend() 152 | // must be matched with call to Resume(). 153 | IMGUIEX_CANVAS_API void Suspend(); 154 | IMGUIEX_CANVAS_API void Resume(); 155 | 156 | // Transforms point from canvas plane to ImGui. 157 | IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point) const; 158 | IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point, const CanvasView& view) const; 159 | 160 | // Transforms vector from canvas plant to ImGui. 161 | IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector) const; 162 | IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector, const CanvasView& view) const; 163 | 164 | // Transforms point from ImGui to canvas plane. 165 | IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point) const; 166 | IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point, const CanvasView& view) const; 167 | 168 | // Transforms vector from ImGui to canvas plane. 169 | IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector) const; 170 | IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector, const CanvasView& view) const; 171 | 172 | // Returns widget bounds. 173 | // 174 | // Note: 175 | // Rect is valid after call to Begin(). 176 | const ImRect& Rect() const { return m_WidgetRect; } 177 | 178 | // Returns visible region on canvas plane (in canvas plane coordinates). 179 | const ImRect& ViewRect() const { return m_ViewRect; } 180 | 181 | // Calculates visible region for view. 182 | IMGUIEX_CANVAS_API ImRect CalcViewRect(const CanvasView& view) const; 183 | 184 | // Returns current view. 185 | const CanvasView& View() const { return m_View; } 186 | 187 | // Returns origin of the view. 188 | // 189 | // Origin is an offset of infinite plane origin from top left 190 | // corner of the canvas. 191 | const ImVec2& ViewOrigin() const { return m_View.Origin; } 192 | 193 | // Returns scale of the view. 194 | float ViewScale() const { return m_View.Scale; } 195 | 196 | // Returns true if canvas is suspended. 197 | // 198 | // See: Suspend()/Resume() 199 | bool IsSuspended() const { return m_SuspendCounter > 0; } 200 | 201 | private: 202 | # define IMGUI_EX_CANVAS_DEFERED() 0 203 | 204 | # if IMGUI_EX_CANVAS_DEFERED() 205 | struct Range 206 | { 207 | int BeginVertexIndex = 0; 208 | int EndVertexIndex = 0; 209 | int BeginComandIndex = 0; 210 | int EndCommandIndex = 0; 211 | }; 212 | # endif 213 | 214 | void UpdateViewTransformPosition(); 215 | 216 | void SaveInputState(); 217 | void RestoreInputState(); 218 | 219 | void SaveViewportState(); 220 | void RestoreViewportState(); 221 | 222 | void EnterLocalSpace(); 223 | void LeaveLocalSpace(); 224 | 225 | bool m_InBeginEnd = false; 226 | 227 | ImVec2 m_WidgetPosition; 228 | ImVec2 m_WidgetSize; 229 | ImRect m_WidgetRect; 230 | 231 | ImDrawList* m_DrawList = nullptr; 232 | int m_ExpectedChannel = 0; 233 | 234 | # if IMGUI_EX_CANVAS_DEFERED() 235 | ImVector m_Ranges; 236 | Range* m_CurrentRange = nullptr; 237 | # endif 238 | 239 | int m_DrawListFirstCommandIndex = 0; 240 | int m_DrawListCommadBufferSize = 0; 241 | int m_DrawListStartVertexIndex = 0; 242 | 243 | CanvasView m_View; 244 | ImRect m_ViewRect; 245 | 246 | ImVec2 m_ViewTransformPosition; 247 | 248 | int m_SuspendCounter = 0; 249 | 250 | float m_LastFringeScale = 1.0f; 251 | 252 | ImVec2 m_MousePosBackup; 253 | ImVec2 m_MousePosPrevBackup; 254 | ImVec2 m_MouseClickedPosBackup[IM_ARRAYSIZE(ImGuiIO::MouseClickedPos)]; 255 | ImVec2 m_WindowCursorMaxBackup; 256 | 257 | # if defined(IMGUI_HAS_VIEWPORT) 258 | ImVec2 m_WindowPosBackup; 259 | ImVec2 m_ViewportPosBackup; 260 | ImVec2 m_ViewportSizeBackup; 261 | # if IMGUI_VERSION_NUM > 18002 262 | ImVec2 m_ViewportWorkPosBackup; 263 | ImVec2 m_ViewportWorkSizeBackup; 264 | # else 265 | ImVec2 m_ViewportWorkOffsetMinBackup; 266 | ImVec2 m_ViewportWorkOffsetMaxBackup; 267 | # endif 268 | # endif 269 | }; 270 | 271 | } // namespace ImGuiEx 272 | 273 | # endif // __IMGUI_EX_CANVAS_H__ -------------------------------------------------------------------------------- /imgui_extra_math.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // VERSION 0.9.1 3 | // 4 | // LICENSE 5 | // This software is dual-licensed to the public domain and under the following 6 | // license: you are granted a perpetual, irrevocable license to copy, modify, 7 | // publish, and distribute this file as you see fit. 8 | // 9 | // CREDITS 10 | // Written by Michal Cichon 11 | //------------------------------------------------------------------------------ 12 | # ifndef __IMGUI_EXTRA_MATH_H__ 13 | # define __IMGUI_EXTRA_MATH_H__ 14 | # pragma once 15 | 16 | 17 | //------------------------------------------------------------------------------ 18 | # ifndef IMGUI_DEFINE_MATH_OPERATORS 19 | # define IMGUI_DEFINE_MATH_OPERATORS 20 | # endif 21 | # include 22 | # include 23 | 24 | 25 | //------------------------------------------------------------------------------ 26 | struct ImLine 27 | { 28 | ImVec2 A, B; 29 | }; 30 | 31 | 32 | //------------------------------------------------------------------------------ 33 | # if IMGUI_VERSION_NUM < 19002 34 | inline bool operator==(const ImVec2& lhs, const ImVec2& rhs); 35 | inline bool operator!=(const ImVec2& lhs, const ImVec2& rhs); 36 | # endif 37 | inline ImVec2 operator*(const float lhs, const ImVec2& rhs); 38 | # if IMGUI_VERSION_NUM < 18955 39 | inline ImVec2 operator-(const ImVec2& lhs); 40 | # endif 41 | 42 | 43 | //------------------------------------------------------------------------------ 44 | inline float ImLength(float v); 45 | inline float ImLength(const ImVec2& v); 46 | inline float ImLengthSqr(float v); 47 | inline ImVec2 ImNormalized(const ImVec2& v); 48 | 49 | 50 | //------------------------------------------------------------------------------ 51 | inline bool ImRect_IsEmpty(const ImRect& rect); 52 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImVec2& p, bool snap_to_edge); 53 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImVec2& p, bool snap_to_edge, float radius); 54 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImRect& b); 55 | inline ImLine ImRect_ClosestLine(const ImRect& rect_a, const ImRect& rect_b); 56 | inline ImLine ImRect_ClosestLine(const ImRect& rect_a, const ImRect& rect_b, float radius_a, float radius_b); 57 | 58 | 59 | 60 | //------------------------------------------------------------------------------ 61 | namespace ImEasing { 62 | 63 | template 64 | inline V EaseOutQuad(V b, V c, T t) 65 | { 66 | return b - c * (t * (t - 2)); 67 | } 68 | 69 | } // namespace ImEasing 70 | 71 | 72 | //------------------------------------------------------------------------------ 73 | # include "imgui_extra_math.inl" 74 | 75 | 76 | //------------------------------------------------------------------------------ 77 | # endif // __IMGUI_EXTRA_MATH_H__ 78 | -------------------------------------------------------------------------------- /imgui_extra_math.inl: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // VERSION 0.9.1 3 | // 4 | // LICENSE 5 | // This software is dual-licensed to the public domain and under the following 6 | // license: you are granted a perpetual, irrevocable license to copy, modify, 7 | // publish, and distribute this file as you see fit. 8 | // 9 | // CREDITS 10 | // Written by Michal Cichon 11 | //------------------------------------------------------------------------------ 12 | # ifndef __IMGUI_EXTRA_MATH_INL__ 13 | # define __IMGUI_EXTRA_MATH_INL__ 14 | # pragma once 15 | 16 | 17 | //------------------------------------------------------------------------------ 18 | # include "imgui_extra_math.h" 19 | 20 | 21 | //------------------------------------------------------------------------------ 22 | # if IMGUI_VERSION_NUM < 19002 23 | inline bool operator==(const ImVec2& lhs, const ImVec2& rhs) 24 | { 25 | return lhs.x == rhs.x && lhs.y == rhs.y; 26 | } 27 | 28 | inline bool operator!=(const ImVec2& lhs, const ImVec2& rhs) 29 | { 30 | return lhs.x != rhs.x || lhs.y != rhs.y; 31 | } 32 | # endif 33 | 34 | inline ImVec2 operator*(const float lhs, const ImVec2& rhs) 35 | { 36 | return ImVec2(lhs * rhs.x, lhs * rhs.y); 37 | } 38 | 39 | # if IMGUI_VERSION_NUM < 18955 40 | inline ImVec2 operator-(const ImVec2& lhs) 41 | { 42 | return ImVec2(-lhs.x, -lhs.y); 43 | } 44 | # endif 45 | 46 | 47 | //------------------------------------------------------------------------------ 48 | inline float ImLength(float v) 49 | { 50 | return v; 51 | } 52 | 53 | inline float ImLength(const ImVec2& v) 54 | { 55 | return ImSqrt(ImLengthSqr(v)); 56 | } 57 | 58 | inline float ImLengthSqr(float v) 59 | { 60 | return v * v; 61 | } 62 | 63 | inline ImVec2 ImNormalized(const ImVec2& v) 64 | { 65 | return v * ImInvLength(v, 0.0f); 66 | } 67 | 68 | 69 | 70 | 71 | //------------------------------------------------------------------------------ 72 | inline bool ImRect_IsEmpty(const ImRect& rect) 73 | { 74 | return rect.Min.x >= rect.Max.x 75 | || rect.Min.y >= rect.Max.y; 76 | } 77 | 78 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImVec2& p, bool snap_to_edge) 79 | { 80 | if (!snap_to_edge && rect.Contains(p)) 81 | return p; 82 | 83 | return ImVec2( 84 | (p.x > rect.Max.x) ? rect.Max.x : (p.x < rect.Min.x ? rect.Min.x : p.x), 85 | (p.y > rect.Max.y) ? rect.Max.y : (p.y < rect.Min.y ? rect.Min.y : p.y) 86 | ); 87 | } 88 | 89 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImVec2& p, bool snap_to_edge, float radius) 90 | { 91 | auto point = ImRect_ClosestPoint(rect, p, snap_to_edge); 92 | 93 | const auto offset = p - point; 94 | const auto distance_sq = offset.x * offset.x + offset.y * offset.y; 95 | if (distance_sq <= 0) 96 | return point; 97 | 98 | const auto distance = ImSqrt(distance_sq); 99 | 100 | return point + offset * (ImMin(distance, radius) * (1.0f / distance)); 101 | } 102 | 103 | inline ImVec2 ImRect_ClosestPoint(const ImRect& rect, const ImRect& other) 104 | { 105 | ImVec2 result; 106 | if (other.Min.x >= rect.Max.x) 107 | result.x = rect.Max.x; 108 | else if (other.Max.x <= rect.Min.x) 109 | result.x = rect.Min.x; 110 | else 111 | result.x = (ImMax(rect.Min.x, other.Min.x) + ImMin(rect.Max.x, other.Max.x)) / 2; 112 | 113 | if (other.Min.y >= rect.Max.y) 114 | result.y = rect.Max.y; 115 | else if (other.Max.y <= rect.Min.y) 116 | result.y = rect.Min.y; 117 | else 118 | result.y = (ImMax(rect.Min.y, other.Min.y) + ImMin(rect.Max.y, other.Max.y)) / 2; 119 | 120 | return result; 121 | } 122 | 123 | inline ImLine ImRect_ClosestLine(const ImRect& rect_a, const ImRect& rect_b) 124 | { 125 | ImLine result; 126 | result.A = ImRect_ClosestPoint(rect_a, rect_b); 127 | result.B = ImRect_ClosestPoint(rect_b, rect_a); 128 | 129 | auto distribute = [](float& a, float& b, float a0, float a1, float b0, float b1) 130 | { 131 | if (a0 >= b1 || a1 <= b0) 132 | return; 133 | 134 | const auto aw = a1 - a0; 135 | const auto bw = b1 - b0; 136 | 137 | if (aw > bw) 138 | { 139 | b = b0 + bw - bw * (a - a0) / aw; 140 | a = b; 141 | } 142 | else if (aw < bw) 143 | { 144 | a = a0 + aw - aw * (b - b0) / bw; 145 | b = a; 146 | } 147 | }; 148 | 149 | distribute(result.A.x, result.B.x, rect_a.Min.x, rect_a.Max.x, rect_b.Min.x, rect_b.Max.x); 150 | distribute(result.A.y, result.B.y, rect_a.Min.y, rect_a.Max.y, rect_b.Min.y, rect_b.Max.y); 151 | 152 | return result; 153 | } 154 | 155 | inline ImLine ImRect_ClosestLine(const ImRect& rect_a, const ImRect& rect_b, float radius_a, float radius_b) 156 | { 157 | auto line = ImRect_ClosestLine(rect_a, rect_b); 158 | if (radius_a < 0) 159 | radius_a = 0; 160 | if (radius_b < 0) 161 | radius_b = 0; 162 | 163 | if (radius_a == 0 && radius_b == 0) 164 | return line; 165 | 166 | const auto offset = line.B - line.A; 167 | const auto length_sq = offset.x * offset.x + offset.y * offset.y; 168 | const auto radius_a_sq = radius_a * radius_a; 169 | const auto radius_b_sq = radius_b * radius_b; 170 | 171 | if (length_sq <= 0) 172 | return line; 173 | 174 | const auto length = ImSqrt(length_sq); 175 | const auto direction = ImVec2(offset.x / length, offset.y / length); 176 | 177 | const auto total_radius_sq = radius_a_sq + radius_b_sq; 178 | if (total_radius_sq > length_sq) 179 | { 180 | const auto scale = length / (radius_a + radius_b); 181 | radius_a *= scale; 182 | radius_b *= scale; 183 | } 184 | 185 | line.A = line.A + (direction * radius_a); 186 | line.B = line.B - (direction * radius_b); 187 | 188 | return line; 189 | } 190 | 191 | 192 | //------------------------------------------------------------------------------ 193 | # endif // __IMGUI_EXTRA_MATH_INL__ 194 | -------------------------------------------------------------------------------- /imgui_node_editor_internal.inl: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // VERSION 0.9.1 3 | // 4 | // LICENSE 5 | // This software is dual-licensed to the public domain and under the following 6 | // license: you are granted a perpetual, irrevocable license to copy, modify, 7 | // publish, and distribute this file as you see fit. 8 | // 9 | // CREDITS 10 | // Written by Michal Cichon 11 | //------------------------------------------------------------------------------ 12 | # ifndef __IMGUI_NODE_EDITOR_INTERNAL_INL__ 13 | # define __IMGUI_NODE_EDITOR_INTERNAL_INL__ 14 | # pragma once 15 | 16 | 17 | //------------------------------------------------------------------------------ 18 | # include "imgui_node_editor_internal.h" 19 | 20 | 21 | //------------------------------------------------------------------------------ 22 | namespace ax { 23 | namespace NodeEditor { 24 | namespace Detail { 25 | 26 | 27 | //------------------------------------------------------------------------------ 28 | //inline ImRect ToRect(const ax::rectf& rect) 29 | //{ 30 | // return ImRect( 31 | // to_imvec(rect.top_left()), 32 | // to_imvec(rect.bottom_right()) 33 | // ); 34 | //} 35 | // 36 | //inline ImRect ToRect(const ax::rect& rect) 37 | //{ 38 | // return ImRect( 39 | // to_imvec(rect.top_left()), 40 | // to_imvec(rect.bottom_right()) 41 | // ); 42 | //} 43 | 44 | inline ImRect ImGui_GetItemRect() 45 | { 46 | return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); 47 | } 48 | 49 | inline ImVec2 ImGui_GetMouseClickPos(ImGuiMouseButton buttonIndex) 50 | { 51 | if (ImGui::IsMouseDown(buttonIndex)) 52 | return ImGui::GetIO().MouseClickedPos[buttonIndex]; 53 | else 54 | return ImGui::GetMousePos(); 55 | } 56 | 57 | 58 | //------------------------------------------------------------------------------ 59 | } // namespace Detail 60 | } // namespace Editor 61 | } // namespace ax 62 | 63 | 64 | //------------------------------------------------------------------------------ 65 | # endif // __IMGUI_NODE_EDITOR_INTERNAL_INL__ 66 | -------------------------------------------------------------------------------- /misc/cmake-modules/FindScopeGuard.cmake: -------------------------------------------------------------------------------- 1 | if (TARGET ScopeGuard) 2 | return() 3 | endif() 4 | 5 | set(_ScopeGuard_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/ScopeGuard) 6 | set(_ScopeGuard_BinaryDir ${CMAKE_BINARY_DIR}/external/ScopeGuard) 7 | 8 | add_subdirectory(${_ScopeGuard_SourceDir} ${_ScopeGuard_BinaryDir}) 9 | 10 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 11 | 12 | find_package_handle_standard_args( 13 | ScopeGuard 14 | REQUIRED_VARS 15 | _ScopeGuard_SourceDir 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /misc/cmake-modules/Findgl3w.cmake: -------------------------------------------------------------------------------- 1 | if (TARGET gl3w) 2 | return() 3 | endif() 4 | 5 | set(_gl3w_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/gl3w) 6 | set(_gl3w_BinaryDir ${CMAKE_BINARY_DIR}/external/gl3w) 7 | 8 | add_subdirectory(${_gl3w_SourceDir} ${_gl3w_BinaryDir}) 9 | 10 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 11 | 12 | find_package_handle_standard_args( 13 | gl3w 14 | REQUIRED_VARS 15 | _gl3w_SourceDir 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /misc/cmake-modules/Findimgui.cmake: -------------------------------------------------------------------------------- 1 | if (TARGET imgui) 2 | return() 3 | endif() 4 | 5 | set(_imgui_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui) 6 | set(_imgui_BinaryDir ${CMAKE_BINARY_DIR}/external/imgui) 7 | 8 | add_subdirectory(${_imgui_SourceDir} ${_imgui_BinaryDir}) 9 | 10 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 11 | 12 | find_package_handle_standard_args( 13 | imgui 14 | REQUIRED_VARS 15 | _imgui_SourceDir 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /misc/cmake-modules/Findimgui_node_editor.cmake: -------------------------------------------------------------------------------- 1 | if (TARGET imgui_node_editor) 2 | return() 3 | endif() 4 | 5 | #set(_imgui_node_editor_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}) 6 | #set(_imgui_node_editor_BinaryDir ${CMAKE_BINARY_DIR}/NodeEditor) 7 | 8 | #add_subdirectory(${_imgui_node_editor_SourceDir} ${_imgui_node_editor_BinaryDir}) 9 | 10 | find_package(imgui REQUIRED) 11 | 12 | set(_imgui_node_editor_Sources 13 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/crude_json.cpp 14 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/crude_json.h 15 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_bezier_math.h 16 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_bezier_math.inl 17 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.cpp 18 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.cpp 19 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.h 20 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.h 21 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_extra_math.h 22 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_extra_math.inl 23 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_api.cpp 24 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_internal.h 25 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_internal.inl 26 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor.cpp 27 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor.h 28 | ${IMGUI_NODE_EDITOR_ROOT_DIR}/misc/imgui_node_editor.natvis 29 | ) 30 | 31 | add_library(imgui_node_editor STATIC 32 | ${_imgui_node_editor_Sources} 33 | ) 34 | 35 | target_include_directories(imgui_node_editor PUBLIC 36 | ${IMGUI_NODE_EDITOR_ROOT_DIR} 37 | ) 38 | 39 | target_link_libraries(imgui_node_editor PUBLIC imgui) 40 | 41 | source_group(TREE ${IMGUI_NODE_EDITOR_ROOT_DIR} FILES ${_imgui_node_editor_Sources}) 42 | 43 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 44 | 45 | find_package_handle_standard_args( 46 | imgui_node_editor 47 | REQUIRED_VARS 48 | IMGUI_NODE_EDITOR_ROOT_DIR 49 | ) -------------------------------------------------------------------------------- /misc/cmake-modules/Findstb_image.cmake: -------------------------------------------------------------------------------- 1 | if (TARGET stb_image) 2 | return() 3 | endif() 4 | 5 | set(_stb_image_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/stb_image) 6 | set(_stb_image_BinaryDir ${CMAKE_BINARY_DIR}/external/stb_image) 7 | 8 | add_subdirectory(${_stb_image_SourceDir} ${_stb_image_BinaryDir}) 9 | 10 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 11 | 12 | find_package_handle_standard_args( 13 | stb_image 14 | REQUIRED_VARS 15 | _stb_image_SourceDir 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /misc/crude_json.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {m_Type,en} {*(crude_json::object*)&m_Storage,view(simple)} 6 | {m_Type,en} {*(crude_json::array*)&m_Storage,view(simple)} 7 | {*(crude_json::string*)&m_Storage,view(simple)} 8 | {*(crude_json::boolean*)&m_Storage} 9 | {*(crude_json::number*)&m_Storage,g} 10 | {m_Type,en} 11 | *(crude_json::string*)&m_Storage 12 | 13 | *(crude_json::object*)&m_Storage,view(simple) 14 | *(crude_json::array*)&m_Storage,view(simple) 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /misc/imgui_node_editor.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {m_Value} 6 | 7 | m_Value 8 | ($T1*)m_Value 9 | 10 | 11 | 12 | 13 | Node {m_Value} 14 | 15 | m_Value 16 | 17 | 18 | 19 | 20 | Link {m_Value} 21 | 22 | m_Value 23 | 24 | 25 | 26 | 27 | Pin {m_Value} 28 | 29 | m_Value 30 | 31 | 32 | 33 | 34 | {second} 35 | 36 | second 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | null 48 | {*object_ptr()} : object 49 | {*array_ptr()} : array 50 | {*string_ptr()} : string 51 | {*boolean_ptr()} : boolean 52 | {*number_ptr(),g} : number 53 | discarded 54 | 55 | 56 | *object_ptr(),view(simple) 57 | *array_ptr(),view(simple) 58 | *string_ptr(),view(simple) 59 | *boolean_ptr() 60 | *number_ptr() 61 | 62 | 63 | 64 | 65 | --------------------------------------------------------------------------------