VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
DialogWindow.cpp
1#include "DialogWindow.hpp"
3
4#include <imgui.h>
5#include <imgui_internal.h>
6
10#include "components/ErrorUtils.hpp"
11
16
17namespace vex {
18
19 DialogWindow::DialogWindow(const char* title, GameInfo gInfo) : Engine(title, 800, 600, gInfo) {
20 }
21
22 DialogWindow::~DialogWindow() {
23 log("DialogWindow destroyed");
24 }
25
29 }
30
31 if(getInputMode() != InputMode::UI){
32 setInputMode(InputMode::UI);
33 }
34
35 try {
36 SceneRenderData renderData{};
37 if (!m_interface->getRenderer().beginFrame(m_resolutionManager->getWindowResolution(), renderData)) {
38 log("Skipping frame.");
39 return;
40 }
41 renderData.imguiTextureID = m_interface->getRenderer().getImGuiTextureID(*m_imgui);
42 m_imgui->beginFrame();
43 m_imgui->executeUIFunctions();
44
45 glm::uvec2 newRes = m_resolutionManager->getWindowResolution();
46 drawDialogWindowLayout(renderData, newRes);
47
48 m_imgui->endFrame();
49 m_interface->getRenderer().composeFrame(renderData, *m_imgui, true);
50 m_interface->getRenderer().endFrame(renderData);
51
52 } catch (const std::exception& e) {
53 log(LogLevel::ERROR, "Dialogwindow render failed");
55 }
56 }
57
58 void DialogWindow::drawDialogWindowLayout(const SceneRenderData& data, glm::uvec2& outNewResolution) {
59 ImGuiViewport* viewport = ImGui::GetMainViewport();
60 ImGui::SetNextWindowPos(viewport->Pos);
61 ImGui::SetNextWindowSize(viewport->Size);
62 ImGui::SetNextWindowViewport(viewport->ID);
63
64 ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
65 ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
66 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus |
67 ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBackground;
68
69 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
70 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
71 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
72
73 ImGui::Begin("DialogWindowkSpace", nullptr, windowFlags);
74 ImGui::PopStyleVar(3);
75
76 ImGuiID dockspaceId = ImGui::GetID("MyDialogDockSpace");
77
78 ImGuiDockNodeFlags dockFlags = ImGuiDockNodeFlags_None;
79
80 if (!ImGui::DockBuilderGetNode(dockspaceId)) {
81 ImGui::DockBuilderRemoveNode(dockspaceId);
82 ImGui::DockBuilderAddNode(dockspaceId, ImGuiDockNodeFlags_DockSpace);
83 ImGui::DockBuilderSetNodeSize(dockspaceId, viewport->Size);
84
85 ImGuiID dockMainId = dockspaceId;
86 ImGuiID dockRightId = ImGui::DockBuilderSplitNode(dockMainId, ImGuiDir_Right, 0.2f, nullptr, &dockMainId);
87
88 ImGui::DockBuilderDockWindow("Dialog", dockMainId);
89
90 ImGui::DockBuilderFinish(dockspaceId);
91 }
92
93 ImGui::DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), dockFlags);
94 ImGui::End();
95
96 ImGuiDockNode* node = ImGui::DockBuilderGetNode(dockspaceId);
97 if (node) {
98 node->LocalFlags |= ImGuiDockNodeFlags_NoTabBar;
99 }
100
101 ImGui::SetNextWindowPos(viewport->Pos);
102 ImGui::SetNextWindowSize(viewport->Size);
103
104 ImGuiWindowFlags childFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
105 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking;
106
107 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
108 ImGui::Begin("Dialog", nullptr, childFlags);
109
110 ImVec2 viewportPanelSize = ImGui::GetContentRegionAvail();
111 outNewResolution = { (uint32_t)viewportPanelSize.x, (uint32_t)viewportPanelSize.y };
112
113 ImGui::Text("%s", m_dialogContent.c_str());
114
115 ImGui::End();
116 ImGui::PopStyleVar();
117 }
118}
A specialized Engine class for creating and managing modal dialog windows.
A specialized ImGUI wrapper for the editor, inheriting from VulkanImGUIWrapper.
This file defines InputSystem class.
This file defines interface Class for vulkan backend.
This file defines Renderer Class.
This file defines ResolutionManager class and ResolutionMode struct.
This file defines SceneManager class.
This file defines class with Imgui for vulkan backend definition.
This file defines Window class.
void drawDialogWindowLayout(const SceneRenderData &data, glm::uvec2 &outNewResolution)
Internal helper to draw the ImGUI layout for the dialog window.
void render() override
Overrides the Engine's render function to draw the dialog content.
DialogWindow(const char *title, GameInfo gInfo)
Constructs a DialogWindow.
void setInputMode(InputMode mode)
Function allowing for changing input mode at runtime.
Definition Engine.hpp:126
InputMode getInputMode() const
Returns the current input mode.
Definition Engine.hpp:130
void setResolutionMode(ResolutionMode mode)
Sets the resolution mode and updates the resolution manager.
Definition Engine.cpp:238
ResolutionMode getResolutionMode() const
Returns the current resolution mode.
Definition Engine.hpp:118
Engine(const char *title, int width, int height, GameInfo gInfo)
Constructor for the Engine class.
Definition Engine.cpp:46
@ NATIVE
Use window resolution.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
void VEX_EXPORT handle_critical_exception(const std::exception &e)
Handles a critical exception, forcing termination.
this struct contains information about the game. like project name and version.
Definition GameInfo.hpp:15
Data structure to pass state between render stages.
Definition Renderer.hpp:57