mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-15 04:56:17 -05:00
Refresh pattern data when pattern file changes
This commit is contained in:
@@ -122,6 +122,12 @@ bool MacroConditionVideo::CheckShouldBeSkipped()
|
||||
return false;
|
||||
}
|
||||
|
||||
MacroConditionVideo::MacroConditionVideo(Macro *m)
|
||||
: QObject(),
|
||||
MacroCondition(m, true)
|
||||
{
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::CheckCondition()
|
||||
{
|
||||
if (!_video.ValidSelection()) {
|
||||
@@ -133,6 +139,10 @@ bool MacroConditionVideo::CheckCondition()
|
||||
return _lastMatchResult;
|
||||
}
|
||||
|
||||
if (!FileInputIsUpToDate()) {
|
||||
LoadImageFromFile();
|
||||
}
|
||||
|
||||
if (_blockUntilScreenshotDone) {
|
||||
GetScreenshot(true);
|
||||
}
|
||||
@@ -231,7 +241,10 @@ void MacroConditionVideo::GetScreenshot(bool blocking)
|
||||
|
||||
bool MacroConditionVideo::LoadImageFromFile()
|
||||
{
|
||||
if (!_matchImage.load(QString::fromStdString(_file))) {
|
||||
const QFileInfo info(QString::fromStdString(_file));
|
||||
_loadedFileLastModified = info.lastModified();
|
||||
_loadedFile = _file;
|
||||
if (!_matchImage.load(info.absoluteFilePath())) {
|
||||
blog(LOG_WARNING, "Cannot load image data from file '%s'",
|
||||
_file.c_str());
|
||||
(&_matchImage)->~QImage();
|
||||
@@ -244,6 +257,8 @@ bool MacroConditionVideo::LoadImageFromFile()
|
||||
_matchImage.convertToFormat(QImage::Format::Format_RGBA8888);
|
||||
_patternMatchParameters.image = _matchImage;
|
||||
_patternImageData = CreatePatternData(_matchImage);
|
||||
|
||||
emit InputFileChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -291,6 +306,16 @@ bool MacroConditionVideo::ScreenshotContainsPattern()
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::FileInputIsUpToDate() const
|
||||
{
|
||||
if (!requiresFileInput(_condition)) {
|
||||
return true;
|
||||
}
|
||||
const QFileInfo info(QString::fromStdString(_file));
|
||||
return (_loadedFileLastModified == info.lastModified()) &&
|
||||
(_file == _loadedFile);
|
||||
}
|
||||
|
||||
bool MacroConditionVideo::OutputChanged()
|
||||
{
|
||||
if (!_patternMatchParameters.useForChangedCheck) {
|
||||
@@ -1165,6 +1190,13 @@ MacroConditionVideoEdit::MacroConditionVideoEdit(
|
||||
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)),
|
||||
&_previewDialog, SLOT(ConditionChanged(int)));
|
||||
QWidget::connect(_area, SIGNAL(Resized()), this, SLOT(Resize()));
|
||||
QWidget::connect(entryData.get(),
|
||||
&MacroConditionVideo::InputFileChanged, this,
|
||||
[this]() {
|
||||
UpdatePreviewTooltip();
|
||||
_previewDialog.PatternMatchParametersChanged(
|
||||
_entryData->_patternMatchParameters);
|
||||
});
|
||||
|
||||
populateVideoInputSelection(_videoInputTypes);
|
||||
populateConditionSelection(_condition);
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
#pragma once
|
||||
#include "opencv-helpers.hpp"
|
||||
#include "area-selection.hpp"
|
||||
#include "preview-dialog.hpp"
|
||||
#include "paramerter-wrappers.hpp"
|
||||
#include "preview-dialog.hpp"
|
||||
|
||||
#include <macro-condition-edit.hpp>
|
||||
#include <file-selection.hpp>
|
||||
#include <screenshot-helper.hpp>
|
||||
#include <slider-spinbox.hpp>
|
||||
#include <variable-text-edit.hpp>
|
||||
#include <variable-line-edit.hpp>
|
||||
#include <variable-text-edit.hpp>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QDateTime>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QRect>
|
||||
#include <QWidget>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class PreviewDialog;
|
||||
|
||||
class MacroConditionVideo : public MacroCondition {
|
||||
class MacroConditionVideo : public QObject, public MacroCondition {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroConditionVideo(Macro *m) : MacroCondition(m, true){};
|
||||
MacroConditionVideo(Macro *m);
|
||||
bool CheckCondition();
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
@@ -66,7 +70,12 @@ public:
|
||||
bool _throttleEnabled = false;
|
||||
int _throttleCount = 3;
|
||||
|
||||
signals:
|
||||
void InputFileChanged();
|
||||
|
||||
private:
|
||||
bool FileInputIsUpToDate() const;
|
||||
|
||||
bool OutputChanged();
|
||||
bool ScreenshotContainsPattern();
|
||||
bool ScreenshotContainsObject();
|
||||
@@ -90,6 +99,9 @@ private:
|
||||
|
||||
double _currentBrightness = 0.;
|
||||
|
||||
std::string _loadedFile;
|
||||
QDateTime _loadedFileLastModified;
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
@@ -243,8 +255,6 @@ public:
|
||||
std::dynamic_pointer_cast<MacroConditionVideo>(cond));
|
||||
}
|
||||
|
||||
void UpdatePreviewTooltip();
|
||||
|
||||
private slots:
|
||||
void VideoInputTypeChanged(int);
|
||||
void SourceChanged(const SourceSelection &);
|
||||
@@ -272,6 +282,7 @@ signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
private:
|
||||
void UpdatePreviewTooltip();
|
||||
void HandleVideoInputUpdate();
|
||||
void SetupPreviewDialogParams();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user