Skip to content

Commit c657ebe

Browse files
authored
Merge pull request #1873 from malucard/rework-docking
Add intuitive dockspace
2 parents c7d263b + 05501d7 commit c657ebe

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/core/arguments.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ PCSX::Arguments::Arguments(const CommandLine::args& args) {
3333
auto portablePath = args.get<std::string_view>("portable");
3434
if (portablePath.has_value()) m_portablePath = portablePath.value();
3535
if (std::filesystem::exists("pcsx.json")) m_portable = true;
36-
if (std::filesystem::exists("Makefile")) m_portable = true;
36+
if (std::filesystem::exists(std::filesystem::path("vsprojects") / "pcsx-redux.sln")) m_portable = true;
3737
if (std::filesystem::exists(std::filesystem::path("..") / "pcsx-redux.sln")) m_portable = true;
3838
if (args.get<bool>("safe") || args.get<bool>("testmode") || args.get<bool>("cli")) m_safeModeEnabled = true;
3939
if (args.get<bool>("resetui")) m_uiResetRequested = true;

src/gui/gui.cc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,13 @@ void PCSX::GUI::endFrame() {
11271127
m_offscreenShaderEditor.configure(this);
11281128
m_outputShaderEditor.configure(this);
11291129

1130+
ImGuiID dockspaceId = ImGui::DockSpaceOverViewport(0, nullptr, ImGuiDockNodeFlags_PassthruCentralNode);
1131+
ImGuiContext* context = ImGui::GetCurrentContext();
1132+
ImGuiDockNode* dockspaceNode = ImGui::DockContextFindNodeByID(context, dockspaceId);
1133+
if (m_fullWindowRender && !dockspaceNode->IsEmpty()) {
1134+
m_fullWindowRender = false;
1135+
ImGui::SetNextWindowDockID(dockspaceId);
1136+
}
11301137
if (m_fullWindowRender) {
11311138
ImTextureID texture = m_offscreenTextures[m_currentTexture];
11321139
const auto basePos = ImGui::GetMainViewport()->Pos;
@@ -1152,16 +1159,24 @@ void PCSX::GUI::endFrame() {
11521159
} else {
11531160
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
11541161
ImGui::SetNextWindowSize(ImVec2(640, 480), ImGuiCond_FirstUseEver);
1155-
bool outputShown = true;
1162+
bool outputWindowShown = true;
11561163
if (ImGui::Begin(
1157-
_("Output"), &outputShown,
1164+
_("Output"), &outputWindowShown,
11581165
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse)) {
1159-
ImVec2 textureSize = ImGui::GetContentRegionAvail();
1166+
ImGuiDockNode* outputNode = ImGui::GetWindowDockNode();
1167+
if (outputNode && dockspaceNode->OnlyNodeWithWindows == outputNode
1168+
&& (!outputNode->TabBar || outputNode->TabBar->Tabs.size() == 1)) {
1169+
// if output is the only visible window in dockspace, switch to full window render mode automatically
1170+
outputWindowShown = false;
1171+
}
1172+
ImVec2 contentRegion = ImGui::GetContentRegionAvail();
1173+
ImVec2 textureSize = contentRegion;
11601174
if ((m_outputWindowSize.x != textureSize.x) || (m_outputWindowSize.y != textureSize.y)) {
11611175
m_outputWindowSize = textureSize;
11621176
m_setupScreenSize = true;
11631177
}
11641178
ImGuiHelpers::normalizeDimensions(textureSize, renderRatio);
1179+
ImGui::SetCursorPos(ImGui::GetCursorPos() + (contentRegion - textureSize) * 0.5f);
11651180
ImTextureID texture = m_offscreenTextures[m_currentTexture];
11661181
if (g_system->getArgs().isShadersDisabled()) {
11671182
ImGui::Image(texture, textureSize, ImVec2(0, 0), ImVec2(1, 1));
@@ -1170,7 +1185,11 @@ void PCSX::GUI::endFrame() {
11701185
}
11711186
}
11721187
ImGui::End();
1173-
if (!outputShown) m_fullWindowRender = true;
1188+
if (!outputWindowShown) {
1189+
m_fullWindowRender = true;
1190+
// full window render mode can't have anything docked in the dockspace
1191+
ImGui::DockContextClearNodes(context, dockspaceId, true);
1192+
}
11741193
}
11751194

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

0 commit comments

Comments
 (0)