Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/cmake/ui-widgets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ target_sources(
widgets/OBSProjector.hpp
widgets/OBSQTDisplay.cpp
widgets/OBSQTDisplay.hpp
widgets/OBSSourceWidget.cpp
widgets/OBSSourceWidget.hpp
widgets/OBSSourceWidgetView.cpp
widgets/OBSSourceWidgetView.hpp
widgets/StatusBarWidget.cpp
widgets/StatusBarWidget.hpp
)
76 changes: 6 additions & 70 deletions frontend/dialogs/OBSBasicFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <utility/display-helpers.hpp>
#include <utility/item-widget-helpers.hpp>
#include <widgets/OBSBasic.hpp>
#include <widgets/OBSSourceWidget.hpp>

#include <properties-view.hpp>
#include <qt-wrappers.hpp>
Expand Down Expand Up @@ -122,22 +123,13 @@ OBSBasicFilters::OBSBasicFilters(QWidget *parent, OBSSource source_)

obs_source_inc_showing(source);

auto addDrawCallback = [this]() {
obs_display_add_draw_callback(ui->preview->GetDisplay(), OBSBasicFilters::DrawPreview, this);
};
auto *previewWidget = new OBSSourceWidget(this, source_);
ui->rightLayout->insertWidget(0, previewWidget);

enum obs_source_type type = obs_source_get_type(source);
bool drawable_type = type == OBS_SOURCE_TYPE_INPUT || type == OBS_SOURCE_TYPE_SCENE;
previewWidget->resize(width(), ui->rightLayout->height() / 2);

if ((caps & OBS_SOURCE_VIDEO) != 0) {
ui->rightLayout->setContentsMargins(0, 0, 0, 0);
ui->preview->show();
if (drawable_type)
connect(ui->preview, &OBSQTDisplay::DisplayCreated, this, addDrawCallback);
} else {
ui->rightLayout->setContentsMargins(0, noPreviewMargin, 0, 0);
ui->preview->hide();
}
ui->rightLayout->setStretchFactor(0, 2);
ui->rightLayout->setStretchFactor(1, 3);

#ifdef __APPLE__
ui->actionRenameFilter->setShortcut({Qt::Key_Return});
Expand Down Expand Up @@ -589,33 +581,9 @@ void OBSBasicFilters::closeEvent(QCloseEvent *event)
if (!event->isAccepted())
return;

obs_display_remove_draw_callback(ui->preview->GetDisplay(), OBSBasicFilters::DrawPreview, this);

main->SaveProject();
}

bool OBSBasicFilters::nativeEvent(const QByteArray &, void *message, qintptr *)
{
#ifdef _WIN32
const MSG &msg = *static_cast<MSG *>(message);
switch (msg.message) {
case WM_MOVE:
for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
display->OnMove();
}
break;
case WM_DISPLAYCHANGE:
for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
display->OnDisplayChange();
}
}
#else
UNUSED_PARAMETER(message);
#endif

return false;
}

/* OBS Signals */

void OBSBasicFilters::OBSSourceFilterAdded(void *param, calldata_t *data)
Expand Down Expand Up @@ -652,38 +620,6 @@ void OBSBasicFilters::SourceRenamed(void *param, calldata_t *data)
QMetaObject::invokeMethod(static_cast<OBSBasicFilters *>(param), "setWindowTitle", Q_ARG(QString, title));
}

void OBSBasicFilters::DrawPreview(void *data, uint32_t cx, uint32_t cy)
{
OBSBasicFilters *window = static_cast<OBSBasicFilters *>(data);

if (!window->source)
return;

uint32_t sourceCX = max(obs_source_get_width(window->source), 1u);
uint32_t sourceCY = max(obs_source_get_height(window->source), 1u);

int x, y;
int newCX, newCY;
float scale;

GetScaleAndCenterPos(sourceCX, sourceCY, cx, cy, x, y, scale);

newCX = int(scale * float(sourceCX));
newCY = int(scale * float(sourceCY));

gs_viewport_push();
gs_projection_push();
const bool previous = gs_set_linear_srgb(true);

gs_ortho(0.0f, float(sourceCX), 0.0f, float(sourceCY), -100.0f, 100.0f);
gs_set_viewport(x, y, newCX, newCY);
obs_source_video_render(window->source);

gs_set_linear_srgb(previous);
gs_projection_pop();
gs_viewport_pop();
}

/* Qt Slots */

static bool QueryRemove(QWidget *parent, obs_source_t *source)
Expand Down
4 changes: 2 additions & 2 deletions frontend/dialogs/OBSBasicFilters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "ui_OBSBasicFilters.h"

#include <obs.hpp>

#include <QDialog>

class OBSBasic;
Expand Down Expand Up @@ -50,7 +52,6 @@ class OBSBasicFilters : public QDialog {
static void SourceRemoved(void *param, calldata_t *data);
static void SourceRenamed(void *param, calldata_t *data);
static void UpdateProperties(void *data, calldata_t *params);
static void DrawPreview(void *data, uint32_t cx, uint32_t cy);

QMenu *CreateAddFilterPopupMenu(bool async);

Expand Down Expand Up @@ -121,5 +122,4 @@ private slots:

protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
};
121 changes: 17 additions & 104 deletions frontend/dialogs/OBSBasicProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <utility/display-helpers.hpp>
#include <widgets/OBSBasic.hpp>
#include <widgets/OBSSourceWidget.hpp>

#include <properties-view.hpp>
#include <qt-wrappers.hpp>
Expand Down Expand Up @@ -59,8 +60,9 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus();

if (cx > 400 && cy > 400)
if (cx > 400 && cy > 400) {
resize(cx, cy);
}

/* The OBSData constructor increments the reference once */
obs_data_release(oldSettings);
Expand Down Expand Up @@ -94,21 +96,15 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
updatePropertiesSignal.Connect(obs_source_get_signal_handler(source), "update_properties",
OBSBasicProperties::UpdateProperties, this);

auto addDrawCallback = [this]() {
obs_display_add_draw_callback(ui->preview->GetDisplay(), OBSBasicProperties::DrawPreview, this);
};
auto addTransitionDrawCallback = [this]() {
obs_display_add_draw_callback(ui->preview->GetDisplay(), OBSBasicProperties::DrawTransitionPreview,
this);
};
uint32_t caps = obs_source_get_output_flags(source);
bool drawable_type = type == OBS_SOURCE_TYPE_INPUT || type == OBS_SOURCE_TYPE_SCENE;
bool drawable_preview = (caps & OBS_SOURCE_VIDEO) != 0;
bool isSourceType = type == OBS_SOURCE_TYPE_INPUT || type == OBS_SOURCE_TYPE_SCENE;
bool hasVideo = (caps & OBS_SOURCE_VIDEO) != 0;

if (drawable_preview && drawable_type) {
ui->preview->show();
connect(ui->preview, &OBSQTDisplay::DisplayCreated, this, addDrawCallback);
auto *previewWidget = new OBSSourceWidget(this);
ui->windowSplitter->insertWidget(0, previewWidget);

if (hasVideo && isSourceType) {
previewWidget->setSource(source_);
} else if (type == OBS_SOURCE_TYPE_TRANSITION) {
sourceA = obs_source_create_private("scene", "sourceA", nullptr);
sourceB = obs_source_create_private("scene", "sourceB", nullptr);
Expand Down Expand Up @@ -145,13 +141,17 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)

connect(view, &OBSPropertiesView::Changed, this, updateCallback);

ui->preview->show();
connect(ui->preview, &OBSQTDisplay::DisplayCreated, this, addTransitionDrawCallback);

previewWidget->setSource(sourceClone);
previewWidget->setForceLinearSRGB(true);
} else {
ui->preview->hide();
previewWidget->hide();
}

previewWidget->resize(width(), ui->windowSplitter->height() / 2);

ui->windowSplitter->setStretchFactor(0, 2);
ui->windowSplitter->setStretchFactor(1, 3);

connect(ui->defaultsButton, &QPushButton::clicked, this, &OBSBasicProperties::restoreDefaultsClicked);
}

Expand Down Expand Up @@ -344,75 +344,10 @@ void OBSBasicProperties::on_buttonBox_clicked(QAbstractButton *button)
}
}

void OBSBasicProperties::DrawPreview(void *data, uint32_t cx, uint32_t cy)
{
OBSBasicProperties *window = static_cast<OBSBasicProperties *>(data);

if (!window->source)
return;

uint32_t sourceCX = max(obs_source_get_width(window->source), 1u);
uint32_t sourceCY = max(obs_source_get_height(window->source), 1u);

int x, y;
int newCX, newCY;
float scale;

GetScaleAndCenterPos(sourceCX, sourceCY, cx, cy, x, y, scale);

newCX = int(scale * float(sourceCX));
newCY = int(scale * float(sourceCY));

gs_viewport_push();
gs_projection_push();
const bool previous = gs_set_linear_srgb(true);

gs_ortho(0.0f, float(sourceCX), 0.0f, float(sourceCY), -100.0f, 100.0f);
gs_set_viewport(x, y, newCX, newCY);
obs_source_video_render(window->source);

gs_set_linear_srgb(previous);
gs_projection_pop();
gs_viewport_pop();
}

void OBSBasicProperties::DrawTransitionPreview(void *data, uint32_t cx, uint32_t cy)
{
OBSBasicProperties *window = static_cast<OBSBasicProperties *>(data);

if (!window->sourceClone)
return;

uint32_t sourceCX = max(obs_source_get_width(window->sourceClone), 1u);
uint32_t sourceCY = max(obs_source_get_height(window->sourceClone), 1u);

int x, y;
int newCX, newCY;
float scale;

GetScaleAndCenterPos(sourceCX, sourceCY, cx, cy, x, y, scale);

newCX = int(scale * float(sourceCX));
newCY = int(scale * float(sourceCY));

gs_viewport_push();
gs_projection_push();
gs_ortho(0.0f, float(sourceCX), 0.0f, float(sourceCY), -100.0f, 100.0f);
gs_set_viewport(x, y, newCX, newCY);

obs_source_video_render(window->sourceClone);

gs_projection_pop();
gs_viewport_pop();
}

void OBSBasicProperties::Cleanup()
{
config_set_int(App()->GetAppConfig(), "PropertiesWindow", "cx", width());
config_set_int(App()->GetAppConfig(), "PropertiesWindow", "cy", height());

obs_display_remove_draw_callback(ui->preview->GetDisplay(), OBSBasicProperties::DrawPreview, this);
obs_display_remove_draw_callback(ui->preview->GetDisplay(), OBSBasicProperties::DrawTransitionPreview, this);
}

void OBSBasicProperties::reject()
Expand All @@ -434,28 +369,6 @@ void OBSBasicProperties::closeEvent(QCloseEvent *event)
Cleanup();
}

bool OBSBasicProperties::nativeEvent(const QByteArray &, void *message, qintptr *)
{
#ifdef _WIN32
const MSG &msg = *static_cast<MSG *>(message);
switch (msg.message) {
case WM_MOVE:
for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
display->OnMove();
}
break;
case WM_DISPLAYCHANGE:
for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
display->OnDisplayChange();
}
}
#else
UNUSED_PARAMETER(message);
#endif

return false;
}

void OBSBasicProperties::Init()
{
show();
Expand Down
5 changes: 2 additions & 3 deletions frontend/dialogs/OBSBasicProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "ui_OBSBasicProperties.h"

#include <obs.hpp>

#include <QDialog>

class OBSBasic;
Expand Down Expand Up @@ -49,8 +51,6 @@ class OBSBasicProperties : public QDialog {
static void SourceRemoved(void *data, calldata_t *params);
static void SourceRenamed(void *data, calldata_t *params);
static void UpdateProperties(void *data, calldata_t *params);
static void DrawPreview(void *data, uint32_t cx, uint32_t cy);
static void DrawTransitionPreview(void *data, uint32_t cx, uint32_t cy);
void UpdateCallback(void *obj, obs_data_t *settings);
bool ConfirmQuit();
int CheckSettings();
Expand All @@ -69,6 +69,5 @@ private slots:

protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
virtual void reject() override;
};
Loading
Loading