From bad7b78fe427666e8521e82efe04e30de124c6ea Mon Sep 17 00:00:00 2001 From: Aleks Todorov Date: Thu, 29 Feb 2024 21:03:14 +0000 Subject: [PATCH] UI: Fix text stacking in paused indicator Currently, the paused indicator is never undone, instead relying on the update timer to eventually erase it away when the recording duration is updated. If the user spams pause fast enough, the indicator will stack several times before it is erased - especially if the unpaused branch in the update timer never has a chance to run. Instead of mutating the recordTime text on pause and requiring an undo, extract the UI update to a separate function which computes the full text based on the current state. Call this function when pause is toggled, thereby forcing an accurate UI update that either does or does not incude the paused text. An added benefit is that the paused indicator now disappears immediately. --- UI/window-basic-status-bar.cpp | 35 +++++++++++++++++++++------------- UI/window-basic-status-bar.hpp | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/UI/window-basic-status-bar.cpp b/UI/window-basic-status-bar.cpp index f6e61ca78..02ff7f053 100644 --- a/UI/window-basic-status-bar.cpp +++ b/UI/window-basic-status-bar.cpp @@ -304,15 +304,6 @@ void OBSBasicStatusBar::UpdateRecordTime() if (!paused) { totalRecordSeconds++; - int seconds = totalRecordSeconds % 60; - int totalMinutes = totalRecordSeconds / 60; - int minutes = totalMinutes % 60; - int hours = totalMinutes / 60; - - QString text = QString::asprintf("%02d:%02d:%02d", hours, - minutes, seconds); - - statusWidget->ui->recordTime->setText(text); if (recordOutput && !statusWidget->ui->recordTime->isEnabled()) statusWidget->ui->recordTime->setDisabled(false); } else { @@ -322,6 +313,24 @@ void OBSBasicStatusBar::UpdateRecordTime() streamPauseIconToggle = !streamPauseIconToggle; } + + UpdateRecordTimeLabel(); +} + +void OBSBasicStatusBar::UpdateRecordTimeLabel() +{ + int seconds = totalRecordSeconds % 60; + int totalMinutes = totalRecordSeconds / 60; + int minutes = totalMinutes % 60; + int hours = totalMinutes / 60; + + QString text = + QString::asprintf("%02d:%02d:%02d", hours, minutes, seconds); + if (os_atomic_load_bool(&recording_paused)) { + text += QStringLiteral(" (PAUSED)"); + } + + statusWidget->ui->recordTime->setText(text); } void OBSBasicStatusBar::UpdateDroppedFrames() @@ -547,14 +556,12 @@ void OBSBasicStatusBar::RecordingStopped() void OBSBasicStatusBar::RecordingPaused() { - QString text = statusWidget->ui->recordTime->text() + - QStringLiteral(" (PAUSED)"); - statusWidget->ui->recordTime->setText(text); - if (recordOutput) { statusWidget->ui->recordIcon->setPixmap(recordingPausePixmap); streamPauseIconToggle = true; } + + UpdateRecordTimeLabel(); } void OBSBasicStatusBar::RecordingUnpaused() @@ -562,6 +569,8 @@ void OBSBasicStatusBar::RecordingUnpaused() if (recordOutput) { statusWidget->ui->recordIcon->setPixmap(recordingActivePixmap); } + + UpdateRecordTimeLabel(); } static QPixmap GetPixmap(const QString &filename) diff --git a/UI/window-basic-status-bar.hpp b/UI/window-basic-status-bar.hpp index a78199b4b..cd79f0db3 100644 --- a/UI/window-basic-status-bar.hpp +++ b/UI/window-basic-status-bar.hpp @@ -84,6 +84,7 @@ private: void UpdateBandwidth(); void UpdateStreamTime(); void UpdateRecordTime(); + void UpdateRecordTimeLabel(); void UpdateDroppedFrames(); static void OBSOutputReconnect(void *data, calldata_t *params);