8 #include "imgui/imgui.h"
12 #include <nap/service.h>
13 #include <renderwindow.h>
14 #include <inputevent.h>
15 #include <nap/resourceptr.h>
16 #include <descriptorsetallocator.h>
17 #include <nap/signalslot.h>
42 inline constexpr
const char*
save =
"save.png";
43 inline constexpr
const char*
saveAs =
"save_as.png";
44 inline constexpr
const char*
cancel =
"cancel.png";
45 inline constexpr
const char*
ok =
"ok.png";
46 inline constexpr
const char*
del =
"delete.png";
47 inline constexpr
const char*
file =
"file.png";
48 inline constexpr
const char*
help =
"help.png";
49 inline constexpr
const char*
settings =
"settings.png";
50 inline constexpr
const char*
reload =
"reload.png";
51 inline constexpr
const char*
folder =
"folder.png";
52 inline constexpr
const char*
load =
"load.png";
53 inline constexpr
const char*
info =
"info.png";
54 inline constexpr
const char*
warning =
"warning.png";
55 inline constexpr
const char*
error =
"error.png";
56 inline constexpr
const char*
copy =
"copy.png";
57 inline constexpr
const char*
paste =
"paste.png";
58 inline constexpr
const char*
insert =
"insert.png";
59 inline constexpr
const char*
edit =
"edit.png";
60 inline constexpr
const char*
remove =
"remove.png";
61 inline constexpr
const char*
add =
"add.png";
62 inline constexpr
const char*
change =
"change.png";
63 inline constexpr
const char*
subtract =
"subtract.png";
70 inline constexpr
float dpi = 96.0f;
104 bool mInvertIcon =
false;
113 bool mAntiAliasedLines =
true;
114 bool mAntiAliasedFill =
true;
115 glm::vec2 mWindowPadding = { 10.0, 10.0f };
116 float mWindowRounding = 0.0f;
117 glm::vec2 mFramePadding = { 5.0f, 5.0f };
118 float mFrameRounding = 0.0f;
119 glm::vec2 mItemSpacing = { 12.0f, 6.0f };
120 glm::vec2 mItemInnerSpacing = { 8.0f, 6.0f };
121 float mIndentSpacing = 25.0f;
122 float mScrollbarSize = 13.0f;
123 float mScrollbarRounding = 0.0f;
124 float mGrabMinSize = 5.0f;
125 float mGrabRounding = 0.0f;
126 float mWindowBorderSize = 0.0f;
127 float mPopupRounding = 0.0f;
128 float mChildRounding = 0.0f;
129 glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f };
130 float mPopupBorderSize = 0.0f;
131 float mTabRounding = 0.0f;
132 glm::vec2 mTouchExtraPadding = { 0.0f, 0.0f };
145 float mFontSize = 17.0f;
147 std::string mFontFile =
"";
148 glm::ivec2 mFontOversampling = { 5, 3 };
149 float mFontSpacing = 0.25f;
168 friend class GuiWindow;
233 ImGuiContext* findContext(
int windowID);
241 float getScale() const;
250 float getScale(const ImGuiContext* context) const;
256 const gui::ColorPalette& getPalette() const;
262 ImGuiContext* processInputEvent(const
InputEvent& event);
267 bool isCapturingKeyboard(ImGuiContext* context);
272 bool isCapturingMouse(ImGuiContext* context);
287 ImTextureID getTextureHandle(const
nap::
Texture2D& texture) const;
302 nap::
Icon& getIcon(std::
string&& name);
326 bool loadIcon(const std::
string& name, const
nap::
Module& module, utility::ErrorState& error);
335 virtual
bool init(utility::ErrorState& error) override;
341 virtual
void getDependentServices(std::vector<rtti::
TypeInfo>& dependencies) override;
347 virtual
void update(
double deltaTime) override;
352 virtual
void postUpdate(
double deltaTime) override;
357 virtual
void preShutdown() override;
362 virtual
void shutdown() override;
367 virtual
void registerObjectCreators(rtti::
Factory& factory) override;
375 struct NAPAPI GUIContext
377 GUIContext(ImGuiContext* context, ImGuiStyle* style);
381 static constexpr
int keyCount = 512;
382 using KeyArray = std::array<bool, keyCount>;
384 std::array<bool,3> mMousePressed = {
false };
385 std::array<bool,3> mMouseRelease = {
false };
386 std::array<bool,3> mModPressed = {
false };
387 std::array<bool,3> mModRelease = {
false };
389 KeyArray mKeyPressed = {
false };
390 std::vector<int> mKeyRelease;
391 glm::ivec2 mMousePosition = { 0, 0 };
392 float mMouseWheel = 0.0f;
394 const Display* mDisplay =
nullptr;
395 ImGuiContext* mContext =
nullptr;
396 ImGuiContext* mPreviousContext =
nullptr;
397 ImGuiStyle* mStyle =
nullptr;
415 void onWindowRemoved(RenderWindow& window);
421 void onWindowEvent(
const WindowEvent& windowEvent);
432 void newFrame(RenderWindow& window, GUIContext& context,
double deltaTime);
437 void pushScale(GUIContext& context,
const Display& display);
442 void handleKeyEvent(
const KeyEvent& keyEvent, GUIContext& context);
447 void handlePointerEvent(
const PointerEvent& pointerEvent, GUIContext& context);
452 void handleTouchEvent(
const TouchEvent& touchEvent, GUIContext& context);
455 RenderService* mRenderService =
nullptr;
456 mutable std::unordered_map<const Texture2D*, VkDescriptorSet> mDescriptors;
457 std::unique_ptr<DescriptorSetAllocator> mAllocator;
458 std::unordered_map<RenderWindow*, std::unique_ptr<GUIContext>> mContexts;
459 std::unique_ptr<ImFontAtlas> mFontAtlas =
nullptr;
460 std::unique_ptr<ImGuiStyle> mStyle =
nullptr;
461 float mGuiScale = 1.0f;
462 float mDPIScale = 1.0f;
465 IMGuiServiceConfiguration* mConfiguration =
nullptr;
466 const gui::ColorPalette* mColorPalette =
nullptr;
469 std::unordered_map<std::string, std::unique_ptr<Icon>> mIcons;