obs-studio/UI/window-basic-properties.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

552 lines
15 KiB
C++
Raw Normal View History

Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
/******************************************************************************
2023-05-19 00:37:26 +00:00
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "obs-app.hpp"
#include "window-basic-properties.hpp"
#include "window-basic-main.hpp"
#include "qt-wrappers.hpp"
#include "display-helpers.hpp"
#include "properties-view.hpp"
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
#include <QCloseEvent>
#include <QScreen>
#include <QWindow>
#include <QMessageBox>
#include <obs-data.h>
#include <obs.h>
#include <qpointer.h>
#include <util/c99defs.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
#endif
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
using namespace std;
2019-08-17 15:49:08 +00:00
static void CreateTransitionScene(OBSSource scene, const char *text,
uint32_t color);
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
: QDialog(parent),
ui(new Ui::OBSBasicProperties),
main(qobject_cast<OBSBasic *>(parent)),
acceptClicked(false),
source(source_),
removedSignal(obs_source_get_signal_handler(source), "remove",
OBSBasicProperties::SourceRemoved, this),
renamedSignal(obs_source_get_signal_handler(source), "rename",
OBSBasicProperties::SourceRenamed, this),
oldSettings(obs_data_create())
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
{
int cx = (int)config_get_int(App()->GlobalConfig(), "PropertiesWindow",
"cx");
int cy = (int)config_get_int(App()->GlobalConfig(), "PropertiesWindow",
"cy");
enum obs_source_type type = obs_source_get_type(source);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus();
if (cx > 400 && cy > 400)
resize(cx, cy);
/* The OBSData constructor increments the reference once */
obs_data_release(oldSettings);
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease nd_settings = obs_source_get_settings(source);
obs_data_apply(oldSettings, nd_settings);
view = new OBSPropertiesView(
2021-11-26 09:25:39 +00:00
nd_settings.Get(), source,
(PropertiesReloadCallback)obs_source_properties,
(PropertiesUpdateCallback) nullptr, // No special handling required for undo/redo
(PropertiesVisualUpdateCb)obs_source_update);
view->setMinimumHeight(150);
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
ui->propertiesLayout->addWidget(view);
if (type == OBS_SOURCE_TYPE_TRANSITION) {
connect(view, &OBSPropertiesView::PropertiesRefreshed, this,
&OBSBasicProperties::AddPreviewButton);
}
view->show();
2014-11-01 20:48:58 +00:00
installEventFilter(CreateShortcutFilter());
const char *name = obs_source_get_name(source);
2014-07-12 09:08:51 +00:00
setWindowTitle(QTStr("Basic.PropertiesWindow").arg(QT_UTF8(name)));
obs_source_inc_showing(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;
if (drawable_preview && drawable_type) {
ui->preview->show();
connect(ui->preview, &OBSQTDisplay::DisplayCreated,
addDrawCallback);
} else if (type == OBS_SOURCE_TYPE_TRANSITION) {
sourceA =
obs_source_create_private("scene", "sourceA", nullptr);
sourceB =
obs_source_create_private("scene", "sourceB", nullptr);
uint32_t colorA = 0xFFB26F52;
uint32_t colorB = 0xFF6FB252;
2021-11-26 09:25:39 +00:00
CreateTransitionScene(sourceA.Get(), "A", colorA);
CreateTransitionScene(sourceB.Get(), "B", colorB);
/**
* The cloned source is made from scratch, rather than using
* obs_source_duplicate, as the stinger transition would not
* play correctly otherwise.
*/
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings = obs_source_get_settings(source);
sourceClone = obs_source_create_private(
obs_source_get_id(source), "clone", settings);
obs_source_inc_active(sourceClone);
obs_transition_set(sourceClone, sourceA);
auto updateCallback = [=]() {
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings =
obs_source_get_settings(source);
obs_source_update(sourceClone, settings);
obs_transition_clear(sourceClone);
obs_transition_set(sourceClone, sourceA);
obs_transition_force_stop(sourceClone);
direction = true;
};
connect(view, &OBSPropertiesView::Changed, updateCallback);
ui->preview->show();
connect(ui->preview, &OBSQTDisplay::DisplayCreated,
addTransitionDrawCallback);
} else {
ui->preview->hide();
}
}
OBSBasicProperties::~OBSBasicProperties()
{
if (sourceClone) {
obs_source_dec_active(sourceClone);
}
obs_source_dec_showing(source);
2015-06-30 12:49:31 +00:00
main->SaveProject();
main->UpdateContextBarDeferred(true);
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
}
void OBSBasicProperties::AddPreviewButton()
{
QPushButton *playButton =
new QPushButton(QTStr("PreviewTransition"), this);
VScrollArea *area = view;
area->widget()->layout()->addWidget(playButton);
playButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
auto play = [=]() {
OBSSource start;
OBSSource end;
if (direction) {
start = sourceA;
end = sourceB;
} else {
start = sourceB;
end = sourceA;
}
obs_transition_set(sourceClone, start);
obs_transition_start(sourceClone, OBS_TRANSITION_MODE_AUTO,
main->GetTransitionDuration(), end);
direction = !direction;
start = nullptr;
end = nullptr;
};
connect(playButton, &QPushButton::clicked, play);
}
static obs_source_t *CreateLabel(const char *name, size_t h)
{
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings = obs_data_create();
OBSDataAutoRelease font = obs_data_create();
std::string text;
text += " ";
text += name;
text += " ";
#if defined(_WIN32)
obs_data_set_string(font, "face", "Arial");
#elif defined(__APPLE__)
obs_data_set_string(font, "face", "Helvetica");
#else
obs_data_set_string(font, "face", "Monospace");
#endif
obs_data_set_int(font, "flags", 1); // Bold text
obs_data_set_int(font, "size", min(int(h), 300));
obs_data_set_obj(settings, "font", font);
obs_data_set_string(settings, "text", text.c_str());
obs_data_set_bool(settings, "outline", false);
#ifdef _WIN32
const char *text_source_id = "text_gdiplus";
#else
const char *text_source_id = "text_ft2_source";
#endif
obs_source_t *txtSource =
obs_source_create_private(text_source_id, name, settings);
return txtSource;
}
2019-08-17 15:49:08 +00:00
static void CreateTransitionScene(OBSSource scene, const char *text,
uint32_t color)
{
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings = obs_data_create();
obs_data_set_int(settings, "width", obs_source_get_width(scene));
obs_data_set_int(settings, "height", obs_source_get_height(scene));
obs_data_set_int(settings, "color", color);
2021-11-26 09:25:39 +00:00
OBSSourceAutoRelease colorBG = obs_source_create_private(
"color_source", "background", settings);
obs_scene_add(obs_scene_from_source(scene), colorBG);
2021-11-26 09:25:39 +00:00
OBSSourceAutoRelease label =
CreateLabel(text, obs_source_get_height(scene));
obs_sceneitem_t *item =
obs_scene_add(obs_scene_from_source(scene), label);
vec2 size;
vec2_set(&size, obs_source_get_width(scene),
#ifdef _WIN32
obs_source_get_height(scene));
#else
obs_source_get_height(scene) * 0.8);
#endif
obs_sceneitem_set_bounds(item, &size);
obs_sceneitem_set_bounds_type(item, OBS_BOUNDS_SCALE_INNER);
}
void OBSBasicProperties::SourceRemoved(void *data, calldata_t *)
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
{
QMetaObject::invokeMethod(static_cast<OBSBasicProperties *>(data),
"close");
}
void OBSBasicProperties::SourceRenamed(void *data, calldata_t *params)
{
const char *name = calldata_string(params, "new_name");
QString title = QTStr("Basic.PropertiesWindow").arg(QT_UTF8(name));
QMetaObject::invokeMethod(static_cast<OBSBasicProperties *>(data),
"setWindowTitle", Q_ARG(QString, title));
}
void OBSBasicProperties::UpdateProperties(void *data, calldata_t *)
{
QMetaObject::invokeMethod(static_cast<OBSBasicProperties *>(data)->view,
"ReloadProperties");
}
static bool ConfirmReset(QWidget *parent)
{
QMessageBox::StandardButton button;
button = OBSMessageBox::question(parent, QTStr("ConfirmReset.Title"),
QTStr("ConfirmReset.Text"),
QMessageBox::Yes | QMessageBox::No);
return button == QMessageBox::Yes;
}
void OBSBasicProperties::on_buttonBox_clicked(QAbstractButton *button)
{
QDialogButtonBox::ButtonRole val = ui->buttonBox->buttonRole(button);
if (val == QDialogButtonBox::AcceptRole) {
2023-03-28 14:24:17 +00:00
std::string scene_uuid =
obs_source_get_uuid(main->GetCurrentSceneSource());
2023-03-28 14:24:17 +00:00
auto undo_redo = [scene_uuid](const std::string &data) {
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings =
obs_data_create_from_json(data.c_str());
2023-03-28 14:24:17 +00:00
OBSSourceAutoRelease source = obs_get_source_by_uuid(
obs_data_get_string(settings, "undo_uuid"));
obs_source_reset_settings(source, settings);
obs_source_update_properties(source);
2021-11-26 09:25:39 +00:00
OBSSourceAutoRelease scene_source =
2023-03-28 14:24:17 +00:00
obs_get_source_by_uuid(scene_uuid.c_str());
2021-11-26 09:25:39 +00:00
OBSBasic::Get()->SetCurrentScene(scene_source.Get(),
true);
};
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease new_settings = obs_data_create();
OBSDataAutoRelease curr_settings =
obs_source_get_settings(source);
obs_data_apply(new_settings, curr_settings);
2023-03-28 14:24:17 +00:00
obs_data_set_string(new_settings, "undo_uuid",
obs_source_get_uuid(source));
obs_data_set_string(oldSettings, "undo_uuid",
obs_source_get_uuid(source));
std::string undo_data(obs_data_get_json(oldSettings));
std::string redo_data(obs_data_get_json(new_settings));
if (undo_data.compare(redo_data) != 0)
main->undo_s.add_action(
QTStr("Undo.Properties")
.arg(obs_source_get_name(source)),
undo_redo, undo_redo, undo_data, redo_data);
acceptClicked = true;
close();
if (view->DeferUpdate())
view->UpdateSettings();
} else if (val == QDialogButtonBox::RejectRole) {
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings = obs_source_get_settings(source);
obs_data_clear(settings);
if (view->DeferUpdate())
obs_data_apply(settings, oldSettings);
else
obs_source_update(source, oldSettings);
close();
} else if (val == QDialogButtonBox::ResetRole) {
if (!ConfirmReset(this))
return;
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease settings = obs_source_get_settings(source);
obs_data_clear(settings);
if (!view->DeferUpdate())
obs_source_update(source, nullptr);
view->ReloadProperties();
}
}
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
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);
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
int x, y;
int newCX, newCY;
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
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);
(API Change) Improve graphics API consistency Summary: - Prefix all graphics subsystem names with gs_ or GS_ - Unsquish funciton names (for example _setfloat to _set_float) - Changed create functions to be more consistent with the rest of the API elsewhere. For exmaple, instead of gs_create_texture/gs_texture_destroy, it's now gs_texture_create/gs_texture_destroy - Renamed gs_stencil_op enum to gs_stencil_op_type From: To: ----------------------------------------------------------- tvertarray gs_tvertarray vb_data gs_vb_data vbdata_create gs_vbdata_create vbdata_destroy gs_vbdata_destroy shader_param gs_shader_param gs_effect gs_effect effect_technique gs_effect_technique effect_pass gs_effect_pass effect_param gs_effect_param texture_t gs_texture_t stagesurf_t gs_stagesurf_t zstencil_t gs_zstencil_t vertbuffer_t gs_vertbuffer_t indexbuffer_t gs_indexbuffer_t samplerstate_t gs_samplerstate_t swapchain_t gs_swapchain_t texrender_t gs_texrender_t shader_t gs_shader_t sparam_t gs_sparam_t effect_t gs_effect_t technique_t gs_technique_t eparam_t gs_eparam_t device_t gs_device_t graphics_t graphics_t shader_param_type gs_shader_param_type SHADER_PARAM_UNKNOWN GS_SHADER_PARAM_UNKNOWN SHADER_PARAM_BOOL GS_SHADER_PARAM_BOOL SHADER_PARAM_FLOAT GS_SHADER_PARAM_FLOAT SHADER_PARAM_INT GS_SHADER_PARAM_INT SHADER_PARAM_STRING GS_SHADER_PARAM_STRING SHADER_PARAM_VEC2 GS_SHADER_PARAM_VEC2 SHADER_PARAM_VEC3 GS_SHADER_PARAM_VEC3 SHADER_PARAM_VEC4 GS_SHADER_PARAM_VEC4 SHADER_PARAM_MATRIX4X4 GS_SHADER_PARAM_MATRIX4X4 SHADER_PARAM_TEXTURE GS_SHADER_PARAM_TEXTURE shader_param_info gs_shader_param_info shader_type gs_shader_type SHADER_VERTEX GS_SHADER_VERTEX SHADER_PIXEL GS_SHADER_PIXEL shader_destroy gs_shader_destroy shader_numparams gs_shader_get_num_params shader_getparambyidx gs_shader_get_param_by_idx shader_getparambyname gs_shader_get_param_by_name shader_getviewprojmatrix gs_shader_get_viewproj_matrix shader_getworldmatrix gs_shader_get_world_matrix shader_getparaminfo gs_shader_get_param_info shader_setbool gs_shader_set_bool shader_setfloat gs_shader_set_float shader_setint gs_shader_set_int shader_setmatrix3 gs_shader_setmatrix3 shader_setmatrix4 gs_shader_set_matrix4 shader_setvec2 gs_shader_set_vec2 shader_setvec3 gs_shader_set_vec3 shader_setvec4 gs_shader_set_vec4 shader_settexture gs_shader_set_texture shader_setval gs_shader_set_val shader_setdefault gs_shader_set_default effect_property_type gs_effect_property_type EFFECT_NONE GS_EFFECT_NONE EFFECT_BOOL GS_EFFECT_BOOL EFFECT_FLOAT GS_EFFECT_FLOAT EFFECT_COLOR GS_EFFECT_COLOR EFFECT_TEXTURE GS_EFFECT_TEXTURE effect_param_info gs_effect_param_info effect_destroy gs_effect_destroy effect_gettechnique gs_effect_get_technique technique_begin gs_technique_begin technique_end gs_technique_end technique_beginpass gs_technique_begin_pass technique_beginpassbyname gs_technique_begin_pass_by_name technique_endpass gs_technique_end_pass effect_numparams gs_effect_get_num_params effect_getparambyidx gs_effect_get_param_by_idx effect_getparambyname gs_effect_get_param_by_name effect_updateparams gs_effect_update_params effect_getviewprojmatrix gs_effect_get_viewproj_matrix effect_getworldmatrix gs_effect_get_world_matrix effect_getparaminfo gs_effect_get_param_info effect_setbool gs_effect_set_bool effect_setfloat gs_effect_set_float effect_setint gs_effect_set_int effect_setmatrix4 gs_effect_set_matrix4 effect_setvec2 gs_effect_set_vec2 effect_setvec3 gs_effect_set_vec3 effect_setvec4 gs_effect_set_vec4 effect_settexture gs_effect_set_texture effect_setval gs_effect_set_val effect_setdefault gs_effect_set_default texrender_create gs_texrender_create texrender_destroy gs_texrender_destroy texrender_begin gs_texrender_begin texrender_end gs_texrender_end texrender_reset gs_texrender_reset texrender_gettexture gs_texrender_get_texture GS_BUILDMIPMAPS GS_BUILD_MIPMAPS GS_RENDERTARGET GS_RENDER_TARGET gs_device_name gs_get_device_name gs_device_type gs_get_device_type gs_entercontext gs_enter_context gs_leavecontext gs_leave_context gs_getcontext gs_get_context gs_renderstart gs_render_start gs_renderstop gs_render_stop gs_rendersave gs_render_save gs_getinput gs_get_input gs_geteffect gs_get_effect gs_create_effect_from_file gs_effect_create_from_file gs_create_effect gs_effect_create gs_create_vertexshader_from_file gs_vertexshader_create_from_file gs_create_pixelshader_from_file gs_pixelshader_create_from_file gs_create_texture_from_file gs_texture_create_from_file gs_resetviewport gs_reset_viewport gs_set2dmode gs_set_2d_mode gs_set3dmode gs_set_3d_mode gs_create_swapchain gs_swapchain_create gs_getsize gs_get_size gs_getwidth gs_get_width gs_getheight gs_get_height gs_create_texture gs_texture_create gs_create_cubetexture gs_cubetexture_create gs_create_volumetexture gs_voltexture_create gs_create_zstencil gs_zstencil_create gs_create_stagesurface gs_stagesurface_create gs_create_samplerstate gs_samplerstate_create gs_create_vertexshader gs_vertexshader_create gs_create_pixelshader gs_pixelshader_create gs_create_vertexbuffer gs_vertexbuffer_create gs_create_indexbuffer gs_indexbuffer_create gs_gettexturetype gs_get_texture_type gs_load_defaultsamplerstate gs_load_default_samplerstate gs_getvertexshader gs_get_vertex_shader gs_getpixelshader gs_get_pixel_shader gs_getrendertarget gs_get_render_target gs_getzstenciltarget gs_get_zstencil_target gs_setrendertarget gs_set_render_target gs_setcuberendertarget gs_set_cube_render_target gs_beginscene gs_begin_scene gs_draw gs_draw gs_endscene gs_end_scene gs_setcullmode gs_set_cull_mode gs_getcullmode gs_get_cull_mode gs_enable_depthtest gs_enable_depth_test gs_enable_stenciltest gs_enable_stencil_test gs_enable_stencilwrite gs_enable_stencil_write gs_blendfunction gs_blend_function gs_depthfunction gs_depth_function gs_stencilfunction gs_stencil_function gs_stencilop gs_stencil_op gs_setviewport gs_set_viewport gs_getviewport gs_get_viewport gs_setscissorrect gs_set_scissor_rect gs_create_texture_from_iosurface gs_texture_create_from_iosurface gs_create_gdi_texture gs_texture_create_gdi gs_is_compressed_format gs_is_compressed_format gs_num_total_levels gs_get_total_levels texture_setimage gs_texture_set_image cubetexture_setimage gs_cubetexture_set_image swapchain_destroy gs_swapchain_destroy texture_destroy gs_texture_destroy texture_getwidth gs_texture_get_width texture_getheight gs_texture_get_height texture_getcolorformat gs_texture_get_color_format texture_map gs_texture_map texture_unmap gs_texture_unmap texture_isrect gs_texture_is_rect texture_getobj gs_texture_get_obj cubetexture_destroy gs_cubetexture_destroy cubetexture_getsize gs_cubetexture_get_size cubetexture_getcolorformat gs_cubetexture_get_color_format volumetexture_destroy gs_voltexture_destroy volumetexture_getwidth gs_voltexture_get_width volumetexture_getheight gs_voltexture_get_height volumetexture_getdepth gs_voltexture_getdepth volumetexture_getcolorformat gs_voltexture_get_color_format stagesurface_destroy gs_stagesurface_destroy stagesurface_getwidth gs_stagesurface_get_width stagesurface_getheight gs_stagesurface_get_height stagesurface_getcolorformat gs_stagesurface_get_color_format stagesurface_map gs_stagesurface_map stagesurface_unmap gs_stagesurface_unmap zstencil_destroy gs_zstencil_destroy samplerstate_destroy gs_samplerstate_destroy vertexbuffer_destroy gs_vertexbuffer_destroy vertexbuffer_flush gs_vertexbuffer_flush vertexbuffer_getdata gs_vertexbuffer_get_data indexbuffer_destroy gs_indexbuffer_destroy indexbuffer_flush gs_indexbuffer_flush indexbuffer_getdata gs_indexbuffer_get_data indexbuffer_numindices gs_indexbuffer_get_num_indices indexbuffer_gettype gs_indexbuffer_get_type texture_rebind_iosurface gs_texture_rebind_iosurface texture_get_dc gs_texture_get_dc texture_release_dc gs_texture_release_dc
2014-08-08 06:42:07 +00:00
gs_set_viewport(x, y, newCX, newCY);
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
obs_source_video_render(window->source);
gs_set_linear_srgb(previous);
gs_projection_pop();
gs_viewport_pop();
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
}
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()->GlobalConfig(), "PropertiesWindow", "cx",
width());
config_set_int(App()->GlobalConfig(), "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()
{
if (!acceptClicked && (CheckSettings() != 0)) {
if (!ConfirmQuit()) {
return;
}
}
Cleanup();
done(0);
}
void OBSBasicProperties::closeEvent(QCloseEvent *event)
{
QDialog::closeEvent(event);
if (event->isAccepted())
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;
}
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 08:07:54 +00:00
void OBSBasicProperties::Init()
{
show();
}
int OBSBasicProperties::CheckSettings()
{
2021-11-26 09:25:39 +00:00
OBSDataAutoRelease currentSettings = obs_source_get_settings(source);
const char *oldSettingsJson = obs_data_get_json(oldSettings);
const char *currentSettingsJson = obs_data_get_json(currentSettings);
2021-11-26 09:25:39 +00:00
return strcmp(currentSettingsJson, oldSettingsJson);
}
bool OBSBasicProperties::ConfirmQuit()
{
QMessageBox::StandardButton button;
button = OBSMessageBox::question(
this, QTStr("Basic.PropertiesWindow.ConfirmTitle"),
QTStr("Basic.PropertiesWindow.Confirm"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
switch (button) {
case QMessageBox::Save:
acceptClicked = true;
if (view->DeferUpdate())
view->UpdateSettings();
// Do nothing because the settings are already updated
break;
case QMessageBox::Discard:
obs_source_update(source, oldSettings);
break;
case QMessageBox::Cancel:
return false;
break;
default:
/* If somehow the dialog fails to show, just default to
* saving the settings. */
break;
}
return true;
}