2013-11-07 16:45:03 -07:00
|
|
|
/******************************************************************************
|
2023-05-18 17:37:26 -07:00
|
|
|
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
|
|
|
|
|
Zachary Lund <admin@computerquip.com>
|
|
|
|
|
Philippe Groarke <philippe.groarke@gmail.com>
|
2013-11-07 16:45:03 -07: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
|
2013-12-02 22:24:38 -07:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-11-07 16:45:03 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2013-11-09 00:19:38 -07:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-11-07 16:45:03 -07:00
|
|
|
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/>.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include "OBSBasic.hpp"
|
2013-12-29 09:17:00 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include <dialogs/OBSBasicFilters.hpp>
|
|
|
|
|
#include <dialogs/OBSBasicSourceSelect.hpp>
|
|
|
|
|
#include <widgets/VolControl.hpp>
|
2014-03-06 21:08:12 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
extern void undo_redo(const std::string &data);
|
2014-01-04 13:53:36 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionCopyTransform_triggered()
|
2019-04-23 15:56:30 +08:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSceneItem item = GetCurrentSceneItem();
|
2019-05-05 20:00:06 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
obs_sceneitem_get_info2(item, &copiedTransformInfo);
|
|
|
|
|
obs_sceneitem_get_crop(item, &copiedCropInfo);
|
2019-05-05 20:00:06 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
ui->actionPasteTransform->setEnabled(true);
|
|
|
|
|
hasCopiedTransform = true;
|
2019-05-05 20:00:06 -07:00
|
|
|
}
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionPasteTransform_triggered()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSDataAutoRelease wrapper = obs_scene_save_transform_states(GetCurrentScene(), false);
|
2025-01-25 20:21:42 -06:00
|
|
|
auto func = [](obs_scene_t *, obs_sceneitem_t *item, void *) {
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!obs_sceneitem_selected(item))
|
|
|
|
|
return true;
|
|
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
|
return true;
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2025-01-25 20:21:42 -06:00
|
|
|
OBSBasic *main = OBSBasic::Get();
|
2024-02-29 20:46:07 +00:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
obs_sceneitem_defer_update_begin(item);
|
|
|
|
|
obs_sceneitem_set_info2(item, &main->copiedTransformInfo);
|
|
|
|
|
obs_sceneitem_set_crop(item, &main->copiedCropInfo);
|
|
|
|
|
obs_sceneitem_defer_update_end(item);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
return true;
|
|
|
|
|
};
|
2020-04-14 20:16:33 +02:00
|
|
|
|
2025-01-25 20:21:42 -06:00
|
|
|
obs_scene_enum_items(GetCurrentScene(), func, nullptr);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSDataAutoRelease rwrapper = obs_scene_save_transform_states(GetCurrentScene(), false);
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
std::string undo_data(obs_data_get_json(wrapper));
|
|
|
|
|
std::string redo_data(obs_data_get_json(rwrapper));
|
|
|
|
|
undo_s.add_action(QTStr("Undo.Transform.Paste").arg(obs_source_get_name(GetCurrentSceneSource())), undo_redo,
|
|
|
|
|
undo_redo, undo_data, redo_data);
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionCopySource_triggered()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
clipboard.clear();
|
2024-02-29 20:46:07 +00:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
for (auto &selectedSource : GetAllSelectedSourceItems()) {
|
|
|
|
|
OBSSceneItem item = ui->sources->Get(selectedSource.row());
|
|
|
|
|
if (!item)
|
|
|
|
|
continue;
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource source = obs_sceneitem_get_source(item);
|
2020-04-14 20:16:33 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SourceCopyInfo copyInfo;
|
|
|
|
|
copyInfo.weak_source = OBSGetWeakRef(source);
|
|
|
|
|
obs_sceneitem_get_info2(item, ©Info.transform);
|
|
|
|
|
obs_sceneitem_get_crop(item, ©Info.crop);
|
|
|
|
|
copyInfo.blend_method = obs_sceneitem_get_blending_method(item);
|
|
|
|
|
copyInfo.blend_mode = obs_sceneitem_get_blending_mode(item);
|
|
|
|
|
copyInfo.visible = obs_sceneitem_visible(item);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
clipboard.push_back(copyInfo);
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
UpdateEditMenu();
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionPasteRef_triggered()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource scene_source = GetCurrentSceneSource();
|
|
|
|
|
OBSData undo_data = BackupScene(scene_source);
|
|
|
|
|
OBSScene scene = GetCurrentScene();
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
undo_s.push_disabled();
|
2024-04-03 17:08:14 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
for (size_t i = clipboard.size(); i > 0; i--) {
|
|
|
|
|
SourceCopyInfo ©Info = clipboard[i - 1];
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource source = OBSGetStrongRef(copyInfo.weak_source);
|
|
|
|
|
if (!source)
|
|
|
|
|
continue;
|
2019-09-27 15:04:07 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
const char *name = obs_source_get_name(source);
|
2019-09-27 15:04:07 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
/* do not allow duplicate refs of the same group in the same
|
|
|
|
|
* scene */
|
|
|
|
|
if (!!obs_scene_get_group(scene, name)) {
|
|
|
|
|
continue;
|
2019-09-27 15:04:07 +02:00
|
|
|
}
|
2019-12-27 17:12:31 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSBasicSourceSelect::SourcePaste(copyInfo, false);
|
2020-09-08 20:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
undo_s.pop_disabled();
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
QString action_name = QTStr("Undo.PasteSourceRef");
|
|
|
|
|
const char *scene_name = obs_source_get_name(scene_source);
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSData redo_data = BackupScene(scene_source);
|
|
|
|
|
CreateSceneUndoRedoAction(action_name.arg(scene_name), undo_data, redo_data);
|
2019-06-12 04:56:00 -05:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionPasteDup_triggered()
|
2019-06-12 04:56:00 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource scene_source = GetCurrentSceneSource();
|
|
|
|
|
OBSData undo_data = BackupScene(scene_source);
|
2019-10-10 20:12:20 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
undo_s.push_disabled();
|
2019-10-15 23:20:35 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
for (size_t i = clipboard.size(); i > 0; i--) {
|
|
|
|
|
SourceCopyInfo ©Info = clipboard[i - 1];
|
|
|
|
|
OBSBasicSourceSelect::SourcePaste(copyInfo, true);
|
2023-10-04 17:32:44 -04:00
|
|
|
}
|
2020-02-14 23:30:34 +11:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
undo_s.pop_disabled();
|
2022-02-22 00:40:17 +11:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
QString action_name = QTStr("Undo.PasteSource");
|
|
|
|
|
const char *scene_name = obs_source_get_name(scene_source);
|
2020-06-13 21:00:55 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSData redo_data = BackupScene(scene_source);
|
|
|
|
|
CreateSceneUndoRedoAction(action_name.arg(scene_name), undo_data, redo_data);
|
2020-06-13 21:00:55 -05:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::SourcePasteFilters(OBSSource source, OBSSource dstSource)
|
2020-06-13 21:00:55 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (source == dstSource)
|
|
|
|
|
return;
|
2018-08-23 20:43:44 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSDataArrayAutoRelease undo_array = obs_source_backup_filters(dstSource);
|
|
|
|
|
obs_source_copy_filters(dstSource, source);
|
|
|
|
|
OBSDataArrayAutoRelease redo_array = obs_source_backup_filters(dstSource);
|
2020-08-23 05:12:46 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
const char *srcName = obs_source_get_name(source);
|
|
|
|
|
const char *dstName = obs_source_get_name(dstSource);
|
|
|
|
|
QString text = QTStr("Undo.Filters.Paste.Multiple").arg(srcName, dstName);
|
2018-08-23 20:43:44 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
CreateFilterPasteUndoRedoAction(text, dstSource, undo_array, redo_array);
|
2018-08-23 20:43:44 -05:00
|
|
|
}
|
2021-01-11 23:26:02 -06:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::AudioMixerCopyFilters()
|
2022-09-09 07:20:48 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
QAction *action = reinterpret_cast<QAction *>(sender());
|
|
|
|
|
VolControl *vol = action->property("volControl").value<VolControl *>();
|
|
|
|
|
obs_source_t *source = vol->GetSource();
|
2022-09-09 07:20:48 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
copyFiltersSource = obs_source_get_weak_source(source);
|
|
|
|
|
ui->actionPasteFilters->setEnabled(true);
|
2022-09-09 07:20:48 -05:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::AudioMixerPasteFilters()
|
2021-01-11 23:26:02 -06:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
QAction *action = reinterpret_cast<QAction *>(sender());
|
|
|
|
|
VolControl *vol = action->property("volControl").value<VolControl *>();
|
|
|
|
|
obs_source_t *dstSource = vol->GetSource();
|
2021-02-04 06:01:35 -06:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSourceAutoRelease source = obs_weak_source_get_source(copyFiltersSource);
|
2021-08-19 23:56:49 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SourcePasteFilters(source.Get(), dstSource);
|
2021-08-19 23:56:49 -05:00
|
|
|
}
|
2020-06-27 02:31:08 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::SceneCopyFilters()
|
2023-02-10 13:27:08 +01:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
copyFiltersSource = obs_source_get_weak_source(GetCurrentSceneSource());
|
|
|
|
|
ui->actionPasteFilters->setEnabled(true);
|
2023-02-10 13:27:08 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ScenePasteFilters()
|
2020-06-27 02:31:08 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSourceAutoRelease source = obs_weak_source_get_source(copyFiltersSource);
|
2020-06-27 02:31:08 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource dstSource = GetCurrentSceneSource();
|
2022-01-27 02:37:32 +01:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SourcePasteFilters(source.Get(), dstSource);
|
2020-06-27 02:31:08 +02:00
|
|
|
}
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionCopyFilters_triggered()
|
2021-07-03 17:55:47 +12:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSceneItem item = GetCurrentSceneItem();
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!item)
|
|
|
|
|
return;
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSource source = obs_sceneitem_get_source(item);
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
copyFiltersSource = obs_source_get_weak_source(source);
|
2021-11-01 02:16:56 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
ui->actionPasteFilters->setEnabled(true);
|
2021-11-01 02:16:56 -05:00
|
|
|
}
|
2022-07-29 20:31:13 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::CreateFilterPasteUndoRedoAction(const QString &text, obs_source_t *source, obs_data_array_t *undo_array,
|
|
|
|
|
obs_data_array_t *redo_array)
|
2022-07-29 20:31:13 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
auto undo_redo = [this](const std::string &json) {
|
|
|
|
|
OBSDataAutoRelease data = obs_data_create_from_json(json.c_str());
|
|
|
|
|
OBSDataArrayAutoRelease array = obs_data_get_array(data, "array");
|
|
|
|
|
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(data, "uuid"));
|
2024-06-18 14:18:22 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
obs_source_restore_filters(source, array);
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (filters)
|
|
|
|
|
filters->UpdateSource(source);
|
|
|
|
|
};
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
const char *uuid = obs_source_get_uuid(source);
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSDataAutoRelease undo_data = obs_data_create();
|
|
|
|
|
OBSDataAutoRelease redo_data = obs_data_create();
|
|
|
|
|
obs_data_set_array(undo_data, "array", undo_array);
|
|
|
|
|
obs_data_set_array(redo_data, "array", redo_array);
|
|
|
|
|
obs_data_set_string(undo_data, "uuid", uuid);
|
|
|
|
|
obs_data_set_string(redo_data, "uuid", uuid);
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
undo_s.add_action(text, undo_redo, undo_redo, obs_data_get_json(undo_data), obs_data_get_json(redo_data));
|
2024-07-31 10:53:59 -04:00
|
|
|
}
|
2024-09-03 16:29:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::on_actionPasteFilters_triggered()
|
2024-09-03 16:29:30 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSourceAutoRelease source = obs_weak_source_get_source(copyFiltersSource);
|
2024-09-03 16:29:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSSceneItem sceneItem = GetCurrentSceneItem();
|
|
|
|
|
OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
|
2024-09-03 16:29:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SourcePasteFilters(source.Get(), dstSource);
|
2024-09-03 16:29:30 +02:00
|
|
|
}
|