mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-04 16:25:39 -05:00
Enable creating screenshots of scenes
This commit is contained in:
parent
cdefbf383c
commit
f70ae803a3
|
|
@ -498,8 +498,11 @@ AdvSceneSwitcher.action.systray.entry="Show notification: {{message}}"
|
|||
AdvSceneSwitcher.action.screenshot="Screenshot"
|
||||
AdvSceneSwitcher.action.screenshot.save.default="Default"
|
||||
AdvSceneSwitcher.action.screenshot.save.custom="Custom"
|
||||
AdvSceneSwitcher.action.screenshot.type.source="Source"
|
||||
AdvSceneSwitcher.action.screenshot.type.scene="Scene"
|
||||
AdvSceneSwitcher.action.screenshot.mainOutput="OBS's main output"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Screenshot {{sources}} and save to {{saveType}} location"
|
||||
AdvSceneSwitcher.action.screenshot.blackscreenNote="Sources or scenes, which are not always rendered, may result in some parts of screenshots to remain blank."
|
||||
AdvSceneSwitcher.action.screenshot.entry="Screenshot{{targetType}}{{sources}}{{scenes}}and save to{{saveType}}location"
|
||||
AdvSceneSwitcher.action.profile="Profile"
|
||||
AdvSceneSwitcher.action.profile.entry="Switch active profile to {{profiles}}"
|
||||
AdvSceneSwitcher.action.sceneCollection="Scene collection"
|
||||
|
|
@ -822,6 +825,7 @@ AdvSceneSwitcher.regex.extendedPattern="Enable Qt's ExtendedPatternSyntax"
|
|||
AdvSceneSwitcher.selectScene="--select scene--"
|
||||
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
|
||||
AdvSceneSwitcher.selectCurrentScene="Current Scene"
|
||||
AdvSceneSwitcher.selectPreviewScene="Preview Scene"
|
||||
AdvSceneSwitcher.selectAnyScene="Any Scene"
|
||||
AdvSceneSwitcher.currentTransition="Current Transition"
|
||||
AdvSceneSwitcher.anyTransition="Any Transition"
|
||||
|
|
@ -830,7 +834,7 @@ AdvSceneSwitcher.selectWindow="--select window--"
|
|||
AdvSceneSwitcher.selectSource="--select source--"
|
||||
AdvSceneSwitcher.selectAudioSource="--select audio source--"
|
||||
AdvSceneSwitcher.selectVideoSource="--select video source--"
|
||||
AdvSceneSwitcher.OBSVideoOutput="OBS video output"
|
||||
AdvSceneSwitcher.OBSVideoOutput="OBS's main output"
|
||||
AdvSceneSwitcher.selectMediaSource="--select media source--"
|
||||
AdvSceneSwitcher.selectProcess="--select process--"
|
||||
AdvSceneSwitcher.selectFilter="--select filter--"
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ bool MacroActionScreenshot::_registered = MacroActionFactory::Register(
|
|||
{MacroActionScreenshot::Create, MacroActionScreenshotEdit::Create,
|
||||
"AdvSceneSwitcher.action.screenshot"});
|
||||
|
||||
void MacroActionScreenshot::FrontendScreenshot()
|
||||
void MacroActionScreenshot::FrontendScreenshot(OBSWeakSource &source)
|
||||
{
|
||||
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(26, 0, 0)
|
||||
if (_source) {
|
||||
auto s = obs_weak_source_get_source(_source);
|
||||
if (source) {
|
||||
auto s = obs_weak_source_get_source(source);
|
||||
obs_frontend_take_source_screenshot(s);
|
||||
obs_source_release(s);
|
||||
} else {
|
||||
|
|
@ -22,9 +22,12 @@ void MacroActionScreenshot::FrontendScreenshot()
|
|||
#endif
|
||||
}
|
||||
|
||||
void MacroActionScreenshot::CustomScreenshot()
|
||||
void MacroActionScreenshot::CustomScreenshot(OBSWeakSource &source)
|
||||
{
|
||||
auto s = obs_weak_source_get_source(_source);
|
||||
if (!source && _targetType == TargetType::SCENE) {
|
||||
return;
|
||||
}
|
||||
auto s = obs_weak_source_get_source(source);
|
||||
_screenshot.~ScreenshotHelper();
|
||||
new (&_screenshot) ScreenshotHelper(s, false, 0, true, _path);
|
||||
obs_source_release(s);
|
||||
|
|
@ -32,12 +35,22 @@ void MacroActionScreenshot::CustomScreenshot()
|
|||
|
||||
bool MacroActionScreenshot::PerformAction()
|
||||
{
|
||||
OBSWeakSource source = nullptr;
|
||||
switch (_targetType) {
|
||||
case MacroActionScreenshot::TargetType::SOURCE:
|
||||
source = _source;
|
||||
break;
|
||||
case MacroActionScreenshot::TargetType::SCENE:
|
||||
source = _scene.GetScene(false);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (_saveType) {
|
||||
case MacroActionScreenshot::SaveType::OBS_DEFAULT:
|
||||
FrontendScreenshot();
|
||||
FrontendScreenshot(source);
|
||||
break;
|
||||
case MacroActionScreenshot::SaveType::CUSTOM:
|
||||
CustomScreenshot();
|
||||
CustomScreenshot(source);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -48,15 +61,19 @@ bool MacroActionScreenshot::PerformAction()
|
|||
|
||||
void MacroActionScreenshot::LogAction()
|
||||
{
|
||||
vblog(LOG_INFO, "trigger screenshot for source \"%s\"",
|
||||
GetWeakSourceName(_source).c_str());
|
||||
vblog(LOG_INFO, "trigger screenshot for \"%s\"",
|
||||
_targetType == TargetType::SOURCE
|
||||
? GetWeakSourceName(_source).c_str()
|
||||
: _scene.ToString().c_str());
|
||||
}
|
||||
|
||||
bool MacroActionScreenshot::Save(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Save(obj);
|
||||
_scene.Save(obj);
|
||||
obs_data_set_string(obj, "source", GetWeakSourceName(_source).c_str());
|
||||
obs_data_set_int(obj, "saveType", static_cast<int>(_saveType));
|
||||
obs_data_set_int(obj, "targetType", static_cast<int>(_targetType));
|
||||
obs_data_set_string(obj, "savePath", _path.c_str());
|
||||
return true;
|
||||
}
|
||||
|
|
@ -64,29 +81,27 @@ bool MacroActionScreenshot::Save(obs_data_t *obj)
|
|||
bool MacroActionScreenshot::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Load(obj);
|
||||
_scene.Load(obj);
|
||||
const char *sourceName = obs_data_get_string(obj, "source");
|
||||
_source = GetWeakSourceByName(sourceName);
|
||||
_saveType = static_cast<SaveType>(obs_data_get_int(obj, "saveType"));
|
||||
_targetType =
|
||||
static_cast<TargetType>(obs_data_get_int(obj, "targetType"));
|
||||
_path = obs_data_get_string(obj, "savePath");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string MacroActionScreenshot::GetShortDesc()
|
||||
{
|
||||
if (_source) {
|
||||
if (_targetType == TargetType::SCENE) {
|
||||
return _scene.ToString();
|
||||
} else {
|
||||
return GetWeakSourceName(_source);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void addOBSMainOutputEntry(QComboBox *cb)
|
||||
{
|
||||
cb->insertItem(
|
||||
0, obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.mainOutput"));
|
||||
}
|
||||
|
||||
void populateSaveTypeSelection(QComboBox *list)
|
||||
static void populateSaveTypeSelection(QComboBox *list)
|
||||
{
|
||||
list->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.save.default"));
|
||||
|
|
@ -94,28 +109,47 @@ void populateSaveTypeSelection(QComboBox *list)
|
|||
"AdvSceneSwitcher.action.screenshot.save.custom"));
|
||||
}
|
||||
|
||||
static void populateTargetTypeSelection(QComboBox *list)
|
||||
{
|
||||
list->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.type.source"));
|
||||
list->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.type.scene"));
|
||||
}
|
||||
|
||||
MacroActionScreenshotEdit::MacroActionScreenshotEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionScreenshot> entryData)
|
||||
: QWidget(parent),
|
||||
_scenes(new SceneSelectionWidget(this, true, false, true, true,
|
||||
true)),
|
||||
_sources(new QComboBox()),
|
||||
_saveType(new QComboBox()),
|
||||
_targetType(new QComboBox()),
|
||||
_savePath(new FileSelection(FileSelection::Type::WRITE, this))
|
||||
{
|
||||
populateVideoSelection(_sources, true, false);
|
||||
addOBSMainOutputEntry(_sources);
|
||||
setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.blackscreenNote"));
|
||||
populateVideoSelection(_sources, true);
|
||||
populateSaveTypeSelection(_saveType);
|
||||
populateTargetTypeSelection(_targetType);
|
||||
|
||||
QWidget::connect(_scenes, SIGNAL(SceneChanged(const SceneSelection &)),
|
||||
this, SLOT(SceneChanged(const SceneSelection &)));
|
||||
QWidget::connect(_sources, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SourceChanged(const QString &)));
|
||||
QWidget::connect(_saveType, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SaveTypeChanged(int)));
|
||||
QWidget::connect(_targetType, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(TargetTypeChanged(int)));
|
||||
QWidget::connect(_savePath, SIGNAL(PathChanged(const QString &)), this,
|
||||
SLOT(PathChanged(const QString &)));
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{sources}}", _sources},
|
||||
{"{{scenes}}", _scenes},
|
||||
{"{{saveType}}", _saveType},
|
||||
{"{{targetType}}", _targetType},
|
||||
};
|
||||
placeWidgets(
|
||||
obs_module_text("AdvSceneSwitcher.action.screenshot.entry"),
|
||||
|
|
@ -141,13 +175,27 @@ void MacroActionScreenshotEdit::UpdateEntryData()
|
|||
_sources->setCurrentText(
|
||||
GetWeakSourceName(_entryData->_source).c_str());
|
||||
} else {
|
||||
_sources->setCurrentIndex(0);
|
||||
_sources->setCurrentIndex(1);
|
||||
}
|
||||
_scenes->SetScene(_entryData->_scene);
|
||||
_saveType->setCurrentIndex(static_cast<int>(_entryData->_saveType));
|
||||
_targetType->setCurrentIndex(static_cast<int>(_entryData->_targetType));
|
||||
_savePath->SetPath(QString::fromStdString(_entryData->_path));
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::SceneChanged(const SceneSelection &s)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_scene = s;
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::SaveTypeChanged(int index)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
|
|
@ -158,6 +206,16 @@ void MacroActionScreenshotEdit::SaveTypeChanged(int index)
|
|||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::TargetTypeChanged(int index)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
}
|
||||
|
||||
_entryData->_targetType =
|
||||
static_cast<MacroActionScreenshot::TargetType>(index);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::PathChanged(const QString &text)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
|
|
@ -187,5 +245,10 @@ void MacroActionScreenshotEdit::SetWidgetVisibility()
|
|||
}
|
||||
_savePath->setVisible(_entryData->_saveType ==
|
||||
MacroActionScreenshot::SaveType::CUSTOM);
|
||||
_sources->setVisible(_entryData->_targetType ==
|
||||
MacroActionScreenshot::TargetType::SOURCE);
|
||||
_scenes->setVisible(_entryData->_targetType ==
|
||||
MacroActionScreenshot::TargetType::SCENE);
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "file-selection.hpp"
|
||||
#include "scene-selection.hpp"
|
||||
#include "screenshot-helper.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
|
@ -18,17 +19,23 @@ public:
|
|||
{
|
||||
return std::make_shared<MacroActionScreenshot>(m);
|
||||
}
|
||||
OBSWeakSource _source;
|
||||
enum class SaveType {
|
||||
OBS_DEFAULT,
|
||||
CUSTOM,
|
||||
};
|
||||
SaveType _saveType = SaveType::OBS_DEFAULT;
|
||||
enum class TargetType {
|
||||
SOURCE,
|
||||
SCENE,
|
||||
};
|
||||
TargetType _targetType = TargetType::SOURCE;
|
||||
SceneSelection _scene;
|
||||
OBSWeakSource _source;
|
||||
std::string _path = obs_module_text("AdvSceneSwitcher.enterPath");
|
||||
|
||||
private:
|
||||
void FrontendScreenshot();
|
||||
void CustomScreenshot();
|
||||
void FrontendScreenshot(OBSWeakSource &);
|
||||
void CustomScreenshot(OBSWeakSource &);
|
||||
|
||||
ScreenshotHelper _screenshot;
|
||||
static bool _registered;
|
||||
|
|
@ -52,15 +59,19 @@ public:
|
|||
action));
|
||||
}
|
||||
private slots:
|
||||
void SceneChanged(const SceneSelection &);
|
||||
void SourceChanged(const QString &text);
|
||||
void SaveTypeChanged(int index);
|
||||
void TargetTypeChanged(int index);
|
||||
void PathChanged(const QString &text);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
SceneSelectionWidget *_scenes;
|
||||
QComboBox *_sources;
|
||||
QComboBox *_saveType;
|
||||
QComboBox *_targetType;
|
||||
FileSelection *_savePath;
|
||||
std::shared_ptr<MacroActionScreenshot> _entryData;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user