Skip to content

Commit

Permalink
Some quality of life improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Aug 22, 2024
1 parent c19db11 commit 569d1e7
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 121 deletions.
2 changes: 1 addition & 1 deletion data/scenes/sponza.aescene

Large diffs are not rendered by default.

207 changes: 119 additions & 88 deletions src/editor/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ namespace Atlas::Editor {

ContentDiscovery::Update();

SetDefaultWindowResolution();

auto icon = Atlas::Texture::Texture2D("icon.png");
window.SetIcon(&icon);

ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
(void) io;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

SetDefaultWindowResolution();

auto icon = Atlas::Texture::Texture2D("icon.png");
window.SetIcon(&icon);

// Add font with enlarged size and scale it down again
// This means we can use scaled text up to 2x the size
io.Fonts->AddFontFromFileTTF(
Expand Down Expand Up @@ -251,98 +251,135 @@ namespace Atlas::Editor {
// ImGui::ShowDemoWindow();

ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::SetNextWindowBgAlpha(0.0f);

ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("MainDockspace Window", nullptr, window_flags);
ImGui::PopStyleVar(3);

ImGuiID mainDsId = ImGui::GetID("MainDS");
if (!ImGui::DockBuilderGetNode(mainDsId) || resetDockspaceLayout) {
SetupMainDockspace(mainDsId);
}

ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
ImGui::DockSpace(mainDsId, ImVec2(0.0f, 0.0f), dockspace_flags);

if (ImGui::BeginMainMenuBar()) {
static bool openProject = false, saveProject = false, newScene = false, importFiles = false;
bool saveScene = false;
if (ImGui::BeginMenu("File")) {
/*
ImGui::MenuItem("Open project", nullptr, &openProject);
ImGui::MenuItem("Save project", nullptr, &saveProject);
ImGui::Separator();
*/
ImGui::MenuItem("New scene", nullptr, &newScene);
ImGui::MenuItem("Save scene", nullptr, &saveScene);
/*
ImGui::Separator();
ImGui::MenuItem("Import files", nullptr, &importFiles);
*/
ImGui::EndMenu();
bool playingMaximized = false;
auto activeSceneWindow = sceneWindows.empty() ? nullptr : sceneWindows[activeSceneIdx];
if (activeSceneWindow) {
playingMaximized = activeSceneWindow->isPlaying && activeSceneWindow->playMaximized;
}
if (!playingMaximized) {
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::SetNextWindowBgAlpha(0.0f);

ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("MainDockspace Window", nullptr, window_flags);
ImGui::PopStyleVar(3);

ImGuiID mainDsId = ImGui::GetID("MainDS");
if (!ImGui::DockBuilderGetNode(mainDsId) || resetDockspaceLayout) {
SetupMainDockspace(mainDsId);
}

if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Dark mode", nullptr, &config->darkMode)) {
if (config->darkMode)
ImGui::StyleColorsDark();
else
ImGui::StyleColorsLight();
ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
ImGui::DockSpace(mainDsId, ImVec2(0.0f, 0.0f), dockspace_flags);

if (ImGui::BeginMainMenuBar()) {
static bool openProject = false, saveProject = false, newScene = false, importFiles = false;
bool saveScene = false, exitEditor = false;
if (ImGui::BeginMenu("File")) {
/*
ImGui::MenuItem("Open project", nullptr, &openProject);
ImGui::MenuItem("Save project", nullptr, &saveProject);
ImGui::Separator();
*/
ImGui::MenuItem("New scene", nullptr, &newScene);
ImGui::MenuItem("Save scene", nullptr, &saveScene);
ImGui::MenuItem("Exit", nullptr, &exitEditor);
/*
ImGui::Separator();
ImGui::MenuItem("Import files", nullptr, &importFiles);
*/
ImGui::EndMenu();
}

ImGui::MenuItem("Reset layout", nullptr, &resetDockspaceLayout);
ImGui::MenuItem("Show logs", nullptr, &logWindow.show);
ImGui::MenuItem("Show content browser", nullptr, &contentBrowserWindow.show);
ImGui::MenuItem("Show profiler", nullptr, &profilerWindow.show);
ImGui::MenuItem("Show geometry brush", nullptr, &geometryBrushWindow.show);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Dark mode", nullptr, &config->darkMode)) {
if (config->darkMode)
ImGui::StyleColorsDark();
else
ImGui::StyleColorsLight();
}

ImGui::MenuItem("Reset layout", nullptr, &resetDockspaceLayout);
ImGui::MenuItem("Show logs", nullptr, &logWindow.show);
ImGui::MenuItem("Show content browser", nullptr, &contentBrowserWindow.show);
ImGui::MenuItem("Show profiler", nullptr, &profilerWindow.show);
ImGui::MenuItem("Show geometry brush", nullptr, &geometryBrushWindow.show);
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Renderer")) {
ImGui::MenuItem("VSync", nullptr, &config->vsync);
ImGui::MenuItem("Pathtracer", nullptr, &config->pathTrace);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Renderer")) {
ImGui::MenuItem("VSync", nullptr, &config->vsync);
ImGui::MenuItem("Pathtracer", nullptr, &config->pathTrace);
ImGui::EndMenu();
}

if (newScene) {
UI::PopupPanels::isNewScenePopupVisible = true;
newScene = false;
}

if (newScene) {
UI::PopupPanels::isNewScenePopupVisible = true;
newScene = false;
if (saveScene) {
auto activeSceneWindow = sceneWindows.empty() ? nullptr : sceneWindows[activeSceneIdx];
if (activeSceneWindow != nullptr)
activeSceneWindow->SaveScene();
}

if (exitEditor)
Exit();

ImGui::EndMainMenuBar();
}

if (saveScene) {
auto activeSceneWindow = sceneWindows.empty() ? nullptr : sceneWindows[activeSceneIdx];
if (activeSceneWindow != nullptr)
activeSceneWindow->SaveScene();
UI::PopupPanels::Render();

geometryBrushWindow.Render(activeSceneWindow);

for (auto& sceneWindow : sceneWindows) {
sceneWindow->Render();
}

ImGui::EndMainMenuBar();
contentBrowserWindow.Render();
logWindow.Render();
profilerWindow.Render();

ImGui::End();
}
else {
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove;

UI::PopupPanels::Render();
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

geometryBrushWindow.Render(sceneWindows.empty() ? nullptr : sceneWindows[activeSceneIdx]);
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
ImGui::Begin("RenderWindow", nullptr, window_flags);

for (auto& sceneWindow : sceneWindows) {
sceneWindow->Render();
}
auto renderArea = ImGui::GetContentRegionAvail();
activeSceneWindow->viewportPanel.RenderScene(activeSceneWindow->scene.Get(),
ivec2(0), ivec2(int32_t(renderArea.x), int32_t(renderArea.y)), true);
auto set = Singletons::imguiWrapper->GetTextureDescriptorSet(&activeSceneWindow->viewportPanel.viewportTexture);
ImGui::Image(set, renderArea);

contentBrowserWindow.Render();
logWindow.Render();
profilerWindow.Render();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
ImGui::PopStyleVar();

Notifications::Display();
ImGui::End();
}

ImGui::End();
Notifications::Display();

ImGui::Render();
Singletons::imguiWrapper->Render(true);
Expand Down Expand Up @@ -410,15 +447,9 @@ namespace Atlas::Editor {
void App::SetDefaultWindowResolution() {

auto resolution = GetScreenSize();
if (resolution.y <= 1080) {
window.SetSize(1280, 720);
}
else if (resolution.y <= 1440) {
window.SetSize(1920, 1080);
}
else {
window.SetSize(2560, 1440);
}

window.SetSize(resolution.x - 200, resolution.y - 200);
window.SetPosition(100, 100);

}

Expand Down
4 changes: 2 additions & 2 deletions src/editor/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace Atlas::Editor {

void Notifications::Display() {

const auto notificationWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDecoration;
const auto notificationWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing;

auto viewport = ImGui::GetMainViewport();
auto viewportSize = viewport->Size;
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace Atlas::Editor {
{ "cameraMovementSpeed", sceneWindow->cameraMovementSpeed },
{ "cameraRotationSpeed", sceneWindow->cameraRotationSpeed },
{ "depthTestBoundingVolumes", sceneWindow->depthTestBoundingVolumes },
{ "playMaximized", sceneWindow->playMaximized },
{ "camera", camera }
};

Expand Down Expand Up @@ -124,6 +125,7 @@ namespace Atlas::Editor {
try_get_json(j, "cameraMovementSpeed", sceneWindow->cameraMovementSpeed);
try_get_json(j, "cameraRotationSpeed", sceneWindow->cameraRotationSpeed);
try_get_json(j, "depthTestBoundingVolumes", sceneWindow->depthTestBoundingVolumes);
try_get_json(j, "playMaximized", sceneWindow->playMaximized);
try_get_json(j, "camera", camera);

sceneWindow->cameraEntity = sceneWindow->scene->CreateEntity();
Expand Down
61 changes: 34 additions & 27 deletions src/editor/ui/panels/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,44 @@ namespace Atlas::Editor::UI {
auto region = ImGui::GetContentRegionAvail();
auto windowPos = ImGui::GetWindowPos();

bool validRegion = region.x > 0.0f && region.y > 0.0f;
auto pos = ivec2(int32_t(windowPos.x), int32_t(windowPos.y));
auto size = ivec2(int32_t(region.x), int32_t(region.y));
RenderScene(scene, pos, size, isActiveWindow);

if ((viewportTexture.width != int32_t(region.x) ||
viewportTexture.height != int32_t(region.y)) && validRegion) {
viewport->Set(int32_t(windowPos.x), int32_t(windowPos.y), int32_t(region.x), int32_t(region.y));
viewportTexture.Resize(int32_t(region.x), int32_t(region.y));
if (viewportTexture.IsValid() && viewportTexture.image->layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
auto set = Singletons::imguiWrapper->GetTextureDescriptorSet(&viewportTexture);
ImGui::Image(set, region);
}

if (drawOverlayFunc && !isBlocked)
drawOverlayFunc();

ImGui::SetCursorPos(ImVec2(0.0f, 0.0f));

if (drawMenuBarFunc && !isBlocked) {
isFocused |= ImGui::IsWindowFocused();

drawMenuBarFunc();
}

ImGui::EndChild();

ImGui::End();

}

void ViewportPanel::RenderScene(Ref<Scene::Scene>& scene, ivec2 pos, ivec2 size, bool isActive) {

bool validSize = size.x > 0 && size.y > 0;

if ((viewportTexture.width != size.x ||
viewportTexture.height != size.y) && validSize) {
viewport->Set(pos.x, pos.y, size.x, size.y);
viewportTexture.Resize(size.x, size.y);
CreateRenderPass();
}

if (scene != nullptr && validRegion && isActiveWindow && !isBlocked) {
if (scene != nullptr && validSize && isActive && !Singletons::blockingOperation->block) {
auto& config = Singletons::config;

if (config->pathTrace) {
Expand Down Expand Up @@ -91,29 +119,8 @@ namespace Atlas::Editor::UI {
}

primitiveBatchWrapper.primitiveBatch->Clear();

}

if (viewportTexture.IsValid() && viewportTexture.image->layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
auto set = Singletons::imguiWrapper->GetTextureDescriptorSet(&viewportTexture);
ImGui::Image(set, region);
}

if (drawOverlayFunc && !isBlocked)
drawOverlayFunc();

ImGui::SetCursorPos(ImVec2(0.0f, 0.0f));

if (drawMenuBarFunc && !isBlocked) {
isFocused |= ImGui::IsWindowFocused();

drawMenuBarFunc();
}

ImGui::EndChild();

ImGui::End();

}

void ViewportPanel::RenderVisualization() {
Expand Down
2 changes: 2 additions & 0 deletions src/editor/ui/panels/ViewportPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Atlas::Editor::UI {

void Render(Ref<Scene::Scene>& scene, bool isActiveWindow);

void RenderScene(Ref<Scene::Scene>& scene, ivec2 pos, ivec2 size, bool isActive);

Ref<Viewport> viewport;
Texture::Texture2D viewportTexture;

Expand Down
10 changes: 10 additions & 0 deletions src/editor/ui/windows/SceneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace Atlas::Editor::UI {
SaveScene();
}

if (controlDown && playMaximized && isPlaying && ImGui::IsKeyPressed(ImGuiKey_Escape, false)) {
StopPlaying();
}

}

void SceneWindow::Render() {
Expand Down Expand Up @@ -356,6 +360,8 @@ namespace Atlas::Editor::UI {
ImGui::Text("Path traces samples");
ImGui::DragInt("Sample count", &Singletons::mainRenderer->pathTracingRenderer.realTimeSamplesPerFrame, 1, 1, 16);

ImGui::Checkbox("Play maximized", &playMaximized);

ImGui::EndPopup();
}

Expand Down Expand Up @@ -604,6 +610,10 @@ namespace Atlas::Editor::UI {

isPlaying = true;

if (playMaximized) {
Notifications::Push({ "To stop playing, press Ctrl + Esc" });
}

}

void SceneWindow::StopPlaying() {
Expand Down
Loading

0 comments on commit 569d1e7

Please sign in to comment.