Skip to content

Commit

Permalink
UI: Remove usage of controls UI elements in OBSBasic
Browse files Browse the repository at this point in the history
OBSBasic now no longer rely on UI element from the controls dock.
  • Loading branch information
tytan652 committed Oct 18, 2022
1 parent 07f54a5 commit 5d5a20e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
3 changes: 0 additions & 3 deletions UI/basic-controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class OBSBasicControlsButton;
class OBSBasicControls : public QFrame {
Q_OBJECT

// XXX: OBSBasic still require access to buttons state
friend class OBSBasic;

OBSBasic *main;
std::unique_ptr<Ui::OBSBasicControls> ui;

Expand Down
66 changes: 43 additions & 23 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ OBSBasic::OBSBasic(QWidget *parent)
ui->previewDisabledWidget->setVisible(false);
ui->contextContainer->setStyle(new OBSContextBarProxyStyle);

// Setup streaming connections
connect(this, &OBSBasic::StreamingStarting, this,
[this] { this->streamActionEnabled = false; });
connect(this, &OBSBasic::StreamingStarted, this,
[this] { this->streamActionEnabled = true; });
connect(this, &OBSBasic::StreamingStopped, this,
[this] { this->streamActionEnabled = true; });

// Setup recording connections
connect(this, &OBSBasic::RecordingStartAborted, this,
[this]() { this->recordingEnabled = false; });
connect(this, &OBSBasic::RecordingStarted, this, [this]() {
this->recordingEnabled = true;
this->recordingPaused = false;
});
connect(this, &OBSBasic::RecordingStopAborted, this,
[this]() { this->recordingEnabled = true; });
connect(this, &OBSBasic::RecordingStopped, this,
[this]() { this->recordingEnabled = false; });
connect(this, &OBSBasic::RecordingPaused, this,
[this]() { this->recordingPaused = true; });
connect(this, &OBSBasic::RecordingUnpaused, this,
[this]() { this->recordingPaused = false; });

/* Add controls dock */
controls = new OBSBasicControls(this);
controlsDock = new OBSDock(this);
Expand Down Expand Up @@ -2413,14 +2437,12 @@ void OBSBasic::CreateHotkeys()
streamingHotkeys = obs_hotkey_pair_register_frontend(
"OBSBasic.StartStreaming", Str("Basic.Main.StartStreaming"),
"OBSBasic.StopStreaming", Str("Basic.Main.StopStreaming"),
MAKE_CALLBACK(
!basic.outputHandler->StreamingActive() &&
basic.controls->ui->streamButton->isEnabled(),
basic.StartStreaming, "Starting stream"),
MAKE_CALLBACK(
basic.outputHandler->StreamingActive() &&
basic.controls->ui->streamButton->isEnabled(),
basic.StopStreaming, "Stopping stream"),
MAKE_CALLBACK(!basic.outputHandler->StreamingActive() &&
basic.streamActionEnabled,
basic.StartStreaming, "Starting stream"),
MAKE_CALLBACK(basic.outputHandler->StreamingActive() &&
basic.streamActionEnabled,
basic.StopStreaming, "Stopping stream"),
this, this);
LoadHotkeyPair(streamingHotkeys, "OBSBasic.StartStreaming",
"OBSBasic.StopStreaming");
Expand All @@ -2440,26 +2462,24 @@ void OBSBasic::CreateHotkeys()
recordingHotkeys = obs_hotkey_pair_register_frontend(
"OBSBasic.StartRecording", Str("Basic.Main.StartRecording"),
"OBSBasic.StopRecording", Str("Basic.Main.StopRecording"),
MAKE_CALLBACK(
!basic.outputHandler->RecordingActive() &&
!basic.controls->ui->recordButton->isChecked(),
basic.StartRecording, "Starting recording"),
MAKE_CALLBACK(
basic.outputHandler->RecordingActive() &&
basic.controls->ui->recordButton->isChecked(),
basic.StopRecording, "Stopping recording"),
MAKE_CALLBACK(!basic.outputHandler->RecordingActive() &&
!basic.recordingEnabled,
basic.StartRecording, "Starting recording"),
MAKE_CALLBACK(basic.outputHandler->RecordingActive() &&
basic.recordingEnabled,
basic.StopRecording, "Stopping recording"),
this, this);
LoadHotkeyPair(recordingHotkeys, "OBSBasic.StartRecording",
"OBSBasic.StopRecording");

pauseHotkeys = obs_hotkey_pair_register_frontend(
"OBSBasic.PauseRecording", Str("Basic.Main.PauseRecording"),
"OBSBasic.UnpauseRecording", Str("Basic.Main.UnpauseRecording"),
MAKE_CALLBACK(basic.controls->pauseButton &&
!basic.controls->pauseButton->isChecked(),
MAKE_CALLBACK(basic.IsRecordingPausable() &&
!basic.recordingPaused,
basic.PauseRecording, "Pausing recording"),
MAKE_CALLBACK(basic.controls->pauseButton &&
basic.controls->pauseButton->isChecked(),
MAKE_CALLBACK(basic.IsRecordingPausable() &&
basic.recordingPaused,
basic.UnpauseRecording, "Unpausing recording"),
this, this);
LoadHotkeyPair(pauseHotkeys, "OBSBasic.PauseRecording",
Expand Down Expand Up @@ -9852,7 +9872,7 @@ void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)

void OBSBasic::PauseRecording()
{
if (!controls->pauseButton || !outputHandler ||
if (!IsRecordingPausable() || !outputHandler ||
!outputHandler->fileOutput ||
os_atomic_load_bool(&recording_paused))
return;
Expand Down Expand Up @@ -9890,7 +9910,7 @@ void OBSBasic::PauseRecording()

void OBSBasic::UnpauseRecording()
{
if (!controls->pauseButton || !outputHandler ||
if (!IsRecordingPausable() || !outputHandler ||
!outputHandler->fileOutput ||
!os_atomic_load_bool(&recording_paused))
return;
Expand Down Expand Up @@ -9925,7 +9945,7 @@ void OBSBasic::UnpauseRecording()

void OBSBasic::PauseToggled()
{
if (!controls->pauseButton || !outputHandler ||
if (!IsRecordingPausable() || !outputHandler ||
!outputHandler->fileOutput)
return;

Expand Down
4 changes: 4 additions & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ class OBSBasic : public OBSMainWindow {

float GetDevicePixelRatio();

bool streamActionEnabled = true;
bool recordingEnabled = false;
bool recordingPaused = false;

bool IsRecordingPausable();

public slots:
Expand Down

0 comments on commit 5d5a20e

Please sign in to comment.