mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-22 01:44:49 -05:00
Add option to save screenshot to custom path
This commit is contained in:
parent
0d29fb2ee1
commit
c16b97e5cd
|
|
@ -481,8 +481,10 @@ AdvSceneSwitcher.action.random.entry="Randomly run any of the following macros (
|
|||
AdvSceneSwitcher.action.systray="System tray notification"
|
||||
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.mainOutput="OBS's main output"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Screenshot {{sources}}"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Screenshot {{sources}} and save to {{saveType}} location"
|
||||
AdvSceneSwitcher.action.profile="Profile"
|
||||
AdvSceneSwitcher.action.profile.entry="Switch active profile to {{profiles}}"
|
||||
AdvSceneSwitcher.action.sceneCollection="Scene collection"
|
||||
|
|
|
|||
|
|
@ -463,7 +463,6 @@ AdvSceneSwitcher.action.systray="Notificación de la bandeja del sistema"
|
|||
AdvSceneSwitcher.action.systray.entry="Mostrar notificación: {{message}}"
|
||||
AdvSceneSwitcher.action.screenshot="Captura de pantalla"
|
||||
AdvSceneSwitcher.action.screenshot.mainOutput="Salida principal de OBS"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Captura de pantalla {{sources}}"
|
||||
AdvSceneSwitcher.action.profile="Perfil"
|
||||
AdvSceneSwitcher.action.profile.entry="Cambiar perfil activo a {{profiles}}"
|
||||
AdvSceneSwitcher.action.sceneCollection="Colección de escenas"
|
||||
|
|
|
|||
|
|
@ -383,7 +383,6 @@ AdvSceneSwitcher.action.systray="Sistem tepsisi bildirimi"
|
|||
AdvSceneSwitcher.action.systray.entry="Bildirimleri göster: {{message}}"
|
||||
AdvSceneSwitcher.action.screenshot="Ekran görüntüsü"
|
||||
AdvSceneSwitcher.action.screenshot.mainOutput="OBS'nin ana çıkışı"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Ekran görüntüsü {{sources}}"
|
||||
AdvSceneSwitcher.action.profile="Profil"
|
||||
AdvSceneSwitcher.action.profile.entry="Aktif profili şununla değiştir: {{profiles}}"
|
||||
AdvSceneSwitcher.action.sceneCollection="Sahne koleksiyonu"
|
||||
|
|
|
|||
|
|
@ -424,7 +424,6 @@ AdvSceneSwitcher.action.systray="系统托盘通知"
|
|||
AdvSceneSwitcher.action.systray.entry="显示通知: {{message}}"
|
||||
AdvSceneSwitcher.action.screenshot="截图"
|
||||
AdvSceneSwitcher.action.screenshot.mainOutput="OBS 预览画面"
|
||||
AdvSceneSwitcher.action.screenshot.entry="截图 {{sources}}"
|
||||
AdvSceneSwitcher.action.profile="配置文件"
|
||||
AdvSceneSwitcher.action.profile.entry="将活动配置文件切换到 {{profiles}}"
|
||||
AdvSceneSwitcher.action.sceneCollection="场景集合"
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ bool MacroActionScreenshot::_registered = MacroActionFactory::Register(
|
|||
{MacroActionScreenshot::Create, MacroActionScreenshotEdit::Create,
|
||||
"AdvSceneSwitcher.action.screenshot"});
|
||||
|
||||
bool MacroActionScreenshot::PerformAction()
|
||||
void MacroActionScreenshot::FrontendScreenshot()
|
||||
{
|
||||
if (_source) {
|
||||
auto s = obs_weak_source_get_source(_source);
|
||||
|
|
@ -18,6 +18,29 @@ bool MacroActionScreenshot::PerformAction()
|
|||
} else {
|
||||
obs_frontend_take_screenshot();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionScreenshot::CustomScreenshot()
|
||||
{
|
||||
auto s = obs_weak_source_get_source(_source);
|
||||
_screenshot.~ScreenshotHelper();
|
||||
new (&_screenshot) ScreenshotHelper(s, true, _path);
|
||||
obs_source_release(s);
|
||||
}
|
||||
|
||||
bool MacroActionScreenshot::PerformAction()
|
||||
{
|
||||
switch (_saveType) {
|
||||
case MacroActionScreenshot::SaveType::OBS_DEFAULT:
|
||||
FrontendScreenshot();
|
||||
break;
|
||||
case MacroActionScreenshot::SaveType::CUSTOM:
|
||||
CustomScreenshot();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +54,8 @@ bool MacroActionScreenshot::Save(obs_data_t *obj)
|
|||
{
|
||||
MacroAction::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_string(obj, "savePath", _path.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +64,8 @@ bool MacroActionScreenshot::Load(obs_data_t *obj)
|
|||
MacroAction::Load(obj);
|
||||
const char *sourceName = obs_data_get_string(obj, "source");
|
||||
_source = GetWeakSourceByName(sourceName);
|
||||
_saveType = static_cast<SaveType>(obs_data_get_int(obj, "saveType"));
|
||||
_path = obs_data_get_string(obj, "savePath");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -57,25 +84,44 @@ void addOBSMainOutputEntry(QComboBox *cb)
|
|||
"AdvSceneSwitcher.action.screenshot.mainOutput"));
|
||||
}
|
||||
|
||||
void populateSaveTypeSelection(QComboBox *list)
|
||||
{
|
||||
list->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.save.default"));
|
||||
list->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.action.screenshot.save.custom"));
|
||||
}
|
||||
|
||||
MacroActionScreenshotEdit::MacroActionScreenshotEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionScreenshot> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
_sources(new QComboBox()),
|
||||
_saveType(new QComboBox()),
|
||||
_savePath(new FileSelection(FileSelection::Type::WRITE, this))
|
||||
{
|
||||
_sources = new QComboBox();
|
||||
populateVideoSelection(_sources, true, false);
|
||||
addOBSMainOutputEntry(_sources);
|
||||
populateSaveTypeSelection(_saveType);
|
||||
|
||||
QWidget::connect(_sources, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SourceChanged(const QString &)));
|
||||
QWidget::connect(_saveType, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SaveTypeChanged(int)));
|
||||
QWidget::connect(_savePath, SIGNAL(PathChanged(const QString &)), this,
|
||||
SLOT(PathChanged(const QString &)));
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{sources}}", _sources},
|
||||
{"{{saveType}}", _saveType},
|
||||
};
|
||||
placeWidgets(
|
||||
obs_module_text("AdvSceneSwitcher.action.screenshot.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
layout, widgetPlaceholders);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(layout);
|
||||
mainLayout->addWidget(_savePath);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
|
|
@ -95,6 +141,29 @@ void MacroActionScreenshotEdit::UpdateEntryData()
|
|||
} else {
|
||||
_sources->setCurrentIndex(0);
|
||||
}
|
||||
_saveType->setCurrentIndex(static_cast<int>(_entryData->_saveType));
|
||||
_savePath->SetPath(QString::fromStdString(_entryData->_path));
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::SaveTypeChanged(int index)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
}
|
||||
|
||||
_entryData->_saveType =
|
||||
static_cast<MacroActionScreenshot::SaveType>(index);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::PathChanged(const QString &text)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_path = text.toUtf8().constData();
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::SourceChanged(const QString &text)
|
||||
|
|
@ -108,3 +177,13 @@ void MacroActionScreenshotEdit::SourceChanged(const QString &text)
|
|||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
|
||||
void MacroActionScreenshotEdit::SetWidgetVisibility()
|
||||
{
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
_savePath->setVisible(_entryData->_saveType ==
|
||||
MacroActionScreenshot::SaveType::CUSTOM);
|
||||
adjustSize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "file-selection.hpp"
|
||||
#include "screenshot-helper.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
|
|
@ -17,8 +19,18 @@ public:
|
|||
return std::make_shared<MacroActionScreenshot>(m);
|
||||
}
|
||||
OBSWeakSource _source;
|
||||
enum class SaveType {
|
||||
OBS_DEFAULT,
|
||||
CUSTOM,
|
||||
};
|
||||
SaveType _saveType = SaveType::OBS_DEFAULT;
|
||||
std::string _path = obs_module_text("AdvSceneSwitcher.enterPath");
|
||||
|
||||
private:
|
||||
void FrontendScreenshot();
|
||||
void CustomScreenshot();
|
||||
|
||||
ScreenshotHelper _screenshot;
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
|
@ -41,13 +53,19 @@ public:
|
|||
}
|
||||
private slots:
|
||||
void SourceChanged(const QString &text);
|
||||
void SaveTypeChanged(int index);
|
||||
void PathChanged(const QString &text);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
QComboBox *_sources;
|
||||
QComboBox *_saveType;
|
||||
FileSelection *_savePath;
|
||||
std::shared_ptr<MacroActionScreenshot> _entryData;
|
||||
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
bool _loading = true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user