Skip to content

Commit

Permalink
Merge pull request #1873 from malucard/rework-docking
Browse files Browse the repository at this point in the history
Add intuitive dockspace
  • Loading branch information
nicolasnoble authored Mar 1, 2025
2 parents c7d263b + 05501d7 commit c657ebe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PCSX::Arguments::Arguments(const CommandLine::args& args) {
auto portablePath = args.get<std::string_view>("portable");
if (portablePath.has_value()) m_portablePath = portablePath.value();
if (std::filesystem::exists("pcsx.json")) m_portable = true;
if (std::filesystem::exists("Makefile")) m_portable = true;
if (std::filesystem::exists(std::filesystem::path("vsprojects") / "pcsx-redux.sln")) m_portable = true;
if (std::filesystem::exists(std::filesystem::path("..") / "pcsx-redux.sln")) m_portable = true;
if (args.get<bool>("safe") || args.get<bool>("testmode") || args.get<bool>("cli")) m_safeModeEnabled = true;
if (args.get<bool>("resetui")) m_uiResetRequested = true;
Expand Down
29 changes: 25 additions & 4 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,13 @@ void PCSX::GUI::endFrame() {
m_offscreenShaderEditor.configure(this);
m_outputShaderEditor.configure(this);

ImGuiID dockspaceId = ImGui::DockSpaceOverViewport(0, nullptr, ImGuiDockNodeFlags_PassthruCentralNode);
ImGuiContext* context = ImGui::GetCurrentContext();
ImGuiDockNode* dockspaceNode = ImGui::DockContextFindNodeByID(context, dockspaceId);
if (m_fullWindowRender && !dockspaceNode->IsEmpty()) {
m_fullWindowRender = false;
ImGui::SetNextWindowDockID(dockspaceId);
}
if (m_fullWindowRender) {
ImTextureID texture = m_offscreenTextures[m_currentTexture];
const auto basePos = ImGui::GetMainViewport()->Pos;
Expand All @@ -1152,16 +1159,24 @@ void PCSX::GUI::endFrame() {
} else {
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(640, 480), ImGuiCond_FirstUseEver);
bool outputShown = true;
bool outputWindowShown = true;
if (ImGui::Begin(
_("Output"), &outputShown,
_("Output"), &outputWindowShown,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse)) {
ImVec2 textureSize = ImGui::GetContentRegionAvail();
ImGuiDockNode* outputNode = ImGui::GetWindowDockNode();
if (outputNode && dockspaceNode->OnlyNodeWithWindows == outputNode
&& (!outputNode->TabBar || outputNode->TabBar->Tabs.size() == 1)) {
// if output is the only visible window in dockspace, switch to full window render mode automatically
outputWindowShown = false;
}
ImVec2 contentRegion = ImGui::GetContentRegionAvail();
ImVec2 textureSize = contentRegion;
if ((m_outputWindowSize.x != textureSize.x) || (m_outputWindowSize.y != textureSize.y)) {
m_outputWindowSize = textureSize;
m_setupScreenSize = true;
}
ImGuiHelpers::normalizeDimensions(textureSize, renderRatio);
ImGui::SetCursorPos(ImGui::GetCursorPos() + (contentRegion - textureSize) * 0.5f);
ImTextureID texture = m_offscreenTextures[m_currentTexture];
if (g_system->getArgs().isShadersDisabled()) {
ImGui::Image(texture, textureSize, ImVec2(0, 0), ImVec2(1, 1));
Expand All @@ -1170,7 +1185,11 @@ void PCSX::GUI::endFrame() {
}
}
ImGui::End();
if (!outputShown) m_fullWindowRender = true;
if (!outputWindowShown) {
m_fullWindowRender = true;
// full window render mode can't have anything docked in the dockspace
ImGui::DockContextClearNodes(context, dockspaceId, true);
}
}

bool showOpenIsoFileDialog = false;
Expand Down Expand Up @@ -1433,6 +1452,8 @@ in Configuration->Emulation, restart PCSX-Redux, then try again.)"));
if (ImGui::BeginMenu(_("Rendering"))) {
if (ImGui::MenuItem(_("Full window render"), nullptr, &m_fullWindowRender)) {
m_setupScreenSize = true;
// full window render mode can't have anything docked in the dockspace
ImGui::DockContextClearNodes(context, dockspaceId, true);
}
if (ImGui::MenuItem(_("Fullscreen"), nullptr, &m_fullscreen)) {
setFullscreen(m_fullscreen);
Expand Down

0 comments on commit c657ebe

Please sign in to comment.