|
| 1 | +#ifndef NBL_EXT_IMGUI_UI_H |
| 2 | +#define NBL_EXT_IMGUI_UI_H |
| 3 | + |
| 4 | +#include <glm/vec3.hpp> |
| 5 | + |
| 6 | +namespace nbl::ext::imgui |
| 7 | +{ |
| 8 | + class NBL_API2 UI final : public core::IReferenceCounted{ |
| 9 | + public: |
| 10 | + |
| 11 | + explicit UI( |
| 12 | + core::smart_refctd_ptr<video::ILogicalDevice> device, |
| 13 | + int maxFramesInFlight, |
| 14 | + core::smart_refctd_ptr<video::IGPURenderpass>& renderPass, |
| 15 | + video::IGPUPipelineCache* pipelineCache, |
| 16 | + video::IGPUObjectFromAssetConverter::SParams& cpu2GpuParams, |
| 17 | + core::smart_refctd_ptr<ui::IWindow> window |
| 18 | + ); |
| 19 | + |
| 20 | + ~UI() override; |
| 21 | + |
| 22 | + bool Render(nbl::video::IGPUCommandBuffer& commandBuffer, int frameIndex); |
| 23 | + |
| 24 | + void Update( |
| 25 | + float deltaTimeInSec, |
| 26 | + float mousePosX, |
| 27 | + float mousePosY, |
| 28 | + size_t mouseEventsCount, |
| 29 | + ui::SMouseEvent const * mouseEvents |
| 30 | + // TODO: Keyboard events |
| 31 | + ); |
| 32 | + |
| 33 | + void BeginWindow(char const* windowName); |
| 34 | + |
| 35 | + void EndWindow(); |
| 36 | + |
| 37 | + int Register(std::function<void()> const& listener); |
| 38 | + |
| 39 | + bool UnRegister(int listenerId); |
| 40 | + |
| 41 | + void SetNextItemWidth(float nextItemWidth); |
| 42 | + |
| 43 | + void SetWindowSize(float width, float height); |
| 44 | + |
| 45 | + void Text(char const* label, ...); |
| 46 | + |
| 47 | + void InputFloat(char const* label, float* value); |
| 48 | + |
| 49 | + void InputFloat2(char const* label, float* value); |
| 50 | + |
| 51 | + void InputFloat3(char const* label, float* value); |
| 52 | + |
| 53 | + void InputFloat4(char const* label, float* value); |
| 54 | + |
| 55 | + void InputFloat3(char const* label, glm::vec3& value); |
| 56 | + |
| 57 | + bool Combo( |
| 58 | + char const* label, |
| 59 | + int32_t* selectedItemIndex, |
| 60 | + char const** items, |
| 61 | + int32_t itemsCount |
| 62 | + ); |
| 63 | + |
| 64 | + bool Combo( |
| 65 | + const char* label, |
| 66 | + int* selectedItemIndex, |
| 67 | + std::vector<std::string>& values |
| 68 | + ); |
| 69 | + |
| 70 | + void SliderInt( |
| 71 | + char const* label, |
| 72 | + int* value, |
| 73 | + int minValue, |
| 74 | + int maxValue |
| 75 | + ); |
| 76 | + |
| 77 | + void SliderFloat( |
| 78 | + char const* label, |
| 79 | + float* value, |
| 80 | + float minValue, |
| 81 | + float maxValue |
| 82 | + ); |
| 83 | + |
| 84 | + void Checkbox( |
| 85 | + char const* label, |
| 86 | + bool* value |
| 87 | + ); |
| 88 | + |
| 89 | + void Spacing(); |
| 90 | + |
| 91 | + void Button( |
| 92 | + char const* label, |
| 93 | + std::function<void()> const& onPress |
| 94 | + ); |
| 95 | + |
| 96 | + void InputText( |
| 97 | + char const* label, |
| 98 | + std::string& outValue |
| 99 | + ); |
| 100 | + |
| 101 | + [[nodiscard]] |
| 102 | + bool HasFocus(); |
| 103 | + |
| 104 | + [[nodiscard]] |
| 105 | + bool IsItemActive(); |
| 106 | + |
| 107 | + [[nodiscard]] |
| 108 | + bool TreeNode(char const* name); |
| 109 | + |
| 110 | + void TreePop(); |
| 111 | + |
| 112 | + private: |
| 113 | + |
| 114 | + core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> CreateDescriptorSetLayout(); |
| 115 | + |
| 116 | + void CreatePipeline( |
| 117 | + core::smart_refctd_ptr<video::IGPURenderpass>& renderPass, |
| 118 | + video::IGPUPipelineCache* pipelineCache |
| 119 | + ); |
| 120 | + |
| 121 | + void CreateFontTexture(video::IGPUObjectFromAssetConverter::SParams& cpu2GpuParams); |
| 122 | + |
| 123 | + void UpdateDescriptorSets(); |
| 124 | + |
| 125 | + void CreateFontSampler(); |
| 126 | + |
| 127 | + void CreateDescriptorPool(); |
| 128 | + |
| 129 | + void HandleMouseEvents( |
| 130 | + float mousePosX, |
| 131 | + float mousePosY, |
| 132 | + size_t mouseEventsCount, |
| 133 | + ui::SMouseEvent const * mouseEvents |
| 134 | + ) const; |
| 135 | + |
| 136 | + core::smart_refctd_ptr<video::ILogicalDevice> m_device{}; |
| 137 | + core::smart_refctd_ptr<video::IGPUSampler> m_fontSampler{}; |
| 138 | + core::smart_refctd_ptr<video::IDescriptorPool> m_descriptorPool{}; |
| 139 | + core::smart_refctd_ptr<video::IGPUDescriptorSet> m_gpuDescriptorSet{}; |
| 140 | + core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> m_independentPipeline{}; |
| 141 | + core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_pipeline{}; |
| 142 | + core::smart_refctd_ptr<video::IGPUImageView> m_fontTexture{}; |
| 143 | + core::smart_refctd_ptr<ui::IWindow> m_window{}; |
| 144 | + std::vector<core::smart_refctd_ptr<video::IGPUBuffer>> m_vertexBuffers{}; |
| 145 | + std::vector<core::smart_refctd_ptr<video::IGPUBuffer>> m_indexBuffers{}; |
| 146 | + bool hasFocus = false; |
| 147 | + |
| 148 | + // TODO: Use a signal class instead like Signal<> UIRecordSignal{}; |
| 149 | + struct Subscriber { |
| 150 | + int id = -1; |
| 151 | + std::function<void()> listener = nullptr; |
| 152 | + }; |
| 153 | + std::vector<Subscriber> m_subscribers{}; |
| 154 | + |
| 155 | + }; |
| 156 | +}; |
| 157 | + |
| 158 | +#endif // NBL_EXT_IMGUI_UI_H |
0 commit comments