-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e13067
commit 80c652c
Showing
4 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "macro-condition-screenshot.hpp" | ||
#include "layout-helpers.hpp" | ||
|
||
#include <obs-frontend-api.h> | ||
#include <thread> | ||
|
||
namespace advss { | ||
|
||
const std::string MacroConditionScreenshot::id = "screenshot"; | ||
|
||
bool MacroConditionScreenshot::_registered = MacroConditionFactory::Register( | ||
MacroConditionScreenshot::id, | ||
{MacroConditionScreenshot::Create, MacroConditionScreenshotEdit::Create, | ||
"AdvSceneSwitcher.condition.screenshot"}); | ||
|
||
static std::chrono::high_resolution_clock::time_point screenshotTakenTime{}; | ||
static bool setupScreenshotTakenEventHandler(); | ||
static bool setupDone = setupScreenshotTakenEventHandler(); | ||
|
||
static bool setupScreenshotTakenEventHandler() | ||
{ | ||
static auto handleScreenshotEvent = [](enum obs_frontend_event event, | ||
void *) { | ||
switch (event) { | ||
case OBS_FRONTEND_EVENT_SCREENSHOT_TAKEN: | ||
screenshotTakenTime = | ||
std::chrono::high_resolution_clock::now(); | ||
break; | ||
default: | ||
break; | ||
}; | ||
}; | ||
obs_frontend_add_event_callback(handleScreenshotEvent, nullptr); | ||
return true; | ||
} | ||
|
||
bool MacroConditionScreenshot::CheckCondition() | ||
{ | ||
if (!_screenshotTimeInitialized) { | ||
_screenshotTime = screenshotTakenTime; | ||
_screenshotTimeInitialized = true; | ||
return false; | ||
} | ||
|
||
auto lastScreenshotPath = obs_frontend_get_last_screenshot(); | ||
SetTempVarValue("lastScreenshotPath", lastScreenshotPath); | ||
bfree(lastScreenshotPath); | ||
|
||
bool newSaveOccurred = _screenshotTime != screenshotTakenTime; | ||
_screenshotTime = screenshotTakenTime; | ||
return newSaveOccurred; | ||
} | ||
|
||
bool MacroConditionScreenshot::Save(obs_data_t *obj) const | ||
{ | ||
MacroCondition::Save(obj); | ||
return true; | ||
} | ||
|
||
bool MacroConditionScreenshot::Load(obs_data_t *obj) | ||
{ | ||
MacroCondition::Load(obj); | ||
return true; | ||
} | ||
|
||
void MacroConditionScreenshot::SetupTempVars() | ||
{ | ||
MacroCondition::SetupTempVars(); | ||
AddTempvar( | ||
"lastScreenshotPath", | ||
obs_module_text( | ||
"AdvSceneSwitcher.tempVar.screenshot.lastScreenshotPath"), | ||
obs_module_text( | ||
"AdvSceneSwitcher.tempVar.screenshot.lastScreenshotPath.description")); | ||
} | ||
|
||
MacroConditionScreenshotEdit::MacroConditionScreenshotEdit( | ||
QWidget *parent, std::shared_ptr<MacroConditionScreenshot> entryData) | ||
: QWidget(parent) | ||
{ | ||
auto layout = new QHBoxLayout; | ||
PlaceWidgets( | ||
obs_module_text("AdvSceneSwitcher.condition.screenshot.entry"), | ||
layout, {}); | ||
setLayout(layout); | ||
|
||
_entryData = entryData; | ||
} | ||
|
||
} // namespace advss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
#include "macro-condition-edit.hpp" | ||
|
||
#include <QWidget> | ||
#include <QComboBox> | ||
|
||
namespace advss { | ||
|
||
class MacroConditionScreenshot : public MacroCondition { | ||
public: | ||
MacroConditionScreenshot(Macro *m) : MacroCondition(m) {} | ||
bool CheckCondition(); | ||
bool Save(obs_data_t *obj) const; | ||
bool Load(obs_data_t *obj); | ||
std::string GetId() const { return id; }; | ||
static std::shared_ptr<MacroCondition> Create(Macro *m) | ||
{ | ||
return std::make_shared<MacroConditionScreenshot>(m); | ||
} | ||
|
||
private: | ||
void SetupTempVars(); | ||
|
||
bool _screenshotTimeInitialized = false; | ||
std::chrono::high_resolution_clock::time_point _screenshotTime = {}; | ||
static bool _registered; | ||
static const std::string id; | ||
}; | ||
|
||
class MacroConditionScreenshotEdit : public QWidget { | ||
Q_OBJECT | ||
|
||
public: | ||
MacroConditionScreenshotEdit( | ||
QWidget *parent, | ||
std::shared_ptr<MacroConditionScreenshot> cond = nullptr); | ||
static QWidget *Create(QWidget *parent, | ||
std::shared_ptr<MacroCondition> cond) | ||
{ | ||
return new MacroConditionScreenshotEdit( | ||
parent, | ||
std::dynamic_pointer_cast<MacroConditionScreenshot>( | ||
cond)); | ||
} | ||
|
||
private: | ||
std::shared_ptr<MacroConditionScreenshot> _entryData; | ||
}; | ||
|
||
} // namespace advss |