Skip to content

Commit

Permalink
ui: Remember debug video size, position and state across restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
7oxicshadow authored Oct 16, 2023
1 parent 1e73bf5 commit 51b0cda
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
20 changes: 20 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ display:
auto_scale:
type: bool
default: true
debug:
video:
transparency:
type: bool
default: false
x_pos:
type: number
default: 100.0
y_pos:
type: number
default: 100.0
x_winsize:
type: number
default: 600.0
y_winsize:
type: number
default: 150.0
advanced_tree_state:
type: bool
default: false

audio:
use_dsp: bool
Expand Down
39 changes: 37 additions & 2 deletions ui/xui/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,35 @@ DebugVideoWindow::DebugVideoWindow()
{
m_is_open = false;
m_transparent = false;
m_position_restored = false;
m_resize_init_complete = false;
m_prev_scale = g_viewport_mgr.m_scale;
}

void DebugVideoWindow::Draw()
{
if (!m_is_open)
return;

if (!m_position_restored) {
ImGui::SetNextWindowPos(ImVec2(g_config.display.debug.video.x_pos,
g_config.display.debug.video.y_pos),
ImGuiCond_Once, ImVec2(0, 0));
m_transparent = g_config.display.debug.video.transparency;
m_position_restored = true;
}

float alpha = m_transparent ? 0.2 : 1.0;
PushWindowTransparencySettings(m_transparent, 0.2);
ImGui::SetNextWindowSize(ImVec2(600.0f*g_viewport_mgr.m_scale, 150.0f*g_viewport_mgr.m_scale), ImGuiCond_Once);

if (!m_resize_init_complete || (g_viewport_mgr.m_scale != m_prev_scale)) {
ImGui::SetNextWindowSize(ImVec2(
g_config.display.debug.video.x_winsize * g_viewport_mgr.m_scale,
g_config.display.debug.video.y_winsize * g_viewport_mgr.m_scale));
m_resize_init_complete = true;
}
m_prev_scale = g_viewport_mgr.m_scale;

if (ImGui::Begin("Video Debug", &m_is_open)) {
double x_start, x_end;
static ImPlotAxisFlags rt_axis = ImPlotAxisFlags_NoTickLabels;
Expand Down Expand Up @@ -287,7 +306,12 @@ void DebugVideoWindow::Draw()
}
ImPlot::PopStyleColor();

if (ImGui::TreeNode("Advanced")) {
ImGui::SetNextItemOpen(g_config.display.debug.video.advanced_tree_state,
ImGuiCond_Once);
g_config.display.debug.video.advanced_tree_state =
ImGui::TreeNode("Advanced");

if (g_config.display.debug.video.advanced_tree_state) {
ImGui::SetNextWindowBgAlpha(alpha);
if (ImPlot::BeginPlot("##ScrollingDraws", ImVec2(-1,-1))) {
ImPlot::SetupAxes(NULL, NULL, ImPlotAxisFlags_None, ImPlotAxisFlags_AutoFit);
Expand Down Expand Up @@ -326,6 +350,17 @@ void DebugVideoWindow::Draw()
}

ImPlot::PopStyleVar(2);

ImVec2 debug_window_pos = ImGui::GetWindowPos();
g_config.display.debug.video.x_pos = debug_window_pos.x;
g_config.display.debug.video.y_pos = debug_window_pos.y;

ImVec2 debug_window_size = ImGui::GetWindowSize();
g_config.display.debug.video.x_winsize =
debug_window_size.x / g_viewport_mgr.m_scale;
g_config.display.debug.video.y_winsize =
debug_window_size.y / g_viewport_mgr.m_scale;
g_config.display.debug.video.transparency = m_transparent;
}
ImGui::End();
ImGui::PopStyleColor(5);
Expand Down
3 changes: 3 additions & 0 deletions ui/xui/debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class DebugVideoWindow
public:
bool m_is_open;
bool m_transparent;
bool m_position_restored;
bool m_resize_init_complete;
float m_prev_scale;

DebugVideoWindow();
void Draw();
Expand Down

0 comments on commit 51b0cda

Please sign in to comment.