Move transition type definition

This commit is contained in:
WarmUpTill 2022-10-01 10:49:04 +02:00 committed by WarmUpTill
parent f70ae803a3
commit d2d042bae3
3 changed files with 23 additions and 24 deletions

View File

@ -54,7 +54,7 @@ bool MacroConditionTransition::CheckCondition()
bool transitionStarted = false;
bool transitionEnded = false;
if (_transition.GetType() == TransitionSelectionType::ANY) {
if (_transition.GetType() == TransitionSelection::Type::ANY) {
transitionStarted = anyTransitionStarted;
transitionEnded = anyTransitionEnded;
} else {

View File

@ -7,7 +7,7 @@ void TransitionSelection::Save(obs_data_t *obj, const char *name,
obs_data_set_int(obj, typeName, static_cast<int>(_type));
switch (_type) {
case TransitionSelectionType::TRANSITION:
case Type::TRANSITION:
obs_data_set_string(obj, name,
GetWeakSourceName(_transition).c_str());
break;
@ -19,11 +19,10 @@ void TransitionSelection::Save(obs_data_t *obj, const char *name,
void TransitionSelection::Load(obs_data_t *obj, const char *name,
const char *typeName)
{
_type = static_cast<TransitionSelectionType>(
obs_data_get_int(obj, typeName));
_type = static_cast<Type>(obs_data_get_int(obj, typeName));
auto target = obs_data_get_string(obj, name);
switch (_type) {
case TransitionSelectionType::TRANSITION:
case Type::TRANSITION:
_transition = GetWeakTransitionByName(target);
break;
default:
@ -34,9 +33,9 @@ void TransitionSelection::Load(obs_data_t *obj, const char *name,
OBSWeakSource TransitionSelection::GetTransition()
{
switch (_type) {
case TransitionSelectionType::TRANSITION:
case Type::TRANSITION:
return _transition;
case TransitionSelectionType::CURRENT: {
case Type::CURRENT: {
auto source = obs_frontend_get_current_transition();
auto weakSource = obs_source_get_weak_source(source);
obs_weak_source_release(weakSource);
@ -52,11 +51,11 @@ OBSWeakSource TransitionSelection::GetTransition()
std::string TransitionSelection::ToString()
{
switch (_type) {
case TransitionSelectionType::TRANSITION:
case Type::TRANSITION:
return GetWeakSourceName(_transition);
case TransitionSelectionType::CURRENT:
case Type::CURRENT:
return obs_module_text("AdvSceneSwitcher.currentTransition");
case TransitionSelectionType::ANY:
case Type::ANY:
return obs_module_text("AdvSceneSwitcher.anyTransition");
default:
break;
@ -85,17 +84,17 @@ void TransitionSelectionWidget::SetTransition(TransitionSelection &t)
int idx;
switch (t.GetType()) {
case TransitionSelectionType::TRANSITION:
case TransitionSelection::Type::TRANSITION:
setCurrentText(QString::fromStdString(t.ToString()));
break;
case TransitionSelectionType::CURRENT:
case TransitionSelection::Type::CURRENT:
idx = findText(QString::fromStdString(
obs_module_text("AdvSceneSwitcher.currentTransition")));
if (idx != -1) {
setCurrentIndex(idx);
}
break;
case TransitionSelectionType::ANY:
case TransitionSelection::Type::ANY:
idx = findText(QString::fromStdString(
obs_module_text("AdvSceneSwitcher.anyTransition")));
if (idx != -1) {
@ -155,16 +154,16 @@ void TransitionSelectionWidget::SelectionChanged(const QString &name)
TransitionSelection t;
auto transition = GetWeakTransitionByQString(name);
if (transition) {
t._type = TransitionSelectionType::TRANSITION;
t._type = TransitionSelection::Type::TRANSITION;
t._transition = transition;
}
if (!transition) {
if (IsCurrentTransitionSelected(name)) {
t._type = TransitionSelectionType::CURRENT;
t._type = TransitionSelection::Type::CURRENT;
}
if (IsAnyTransitionSelected(name)) {
t._type = TransitionSelectionType::ANY;
t._type = TransitionSelection::Type::ANY;
}
}

View File

@ -3,12 +3,6 @@
#include <QComboBox>
enum class TransitionSelectionType {
TRANSITION,
CURRENT,
ANY,
};
class TransitionSelection {
public:
void Save(obs_data_t *obj, const char *name = "transition",
@ -16,13 +10,19 @@ public:
void Load(obs_data_t *obj, const char *name = "transition",
const char *typeName = "transitionType");
TransitionSelectionType GetType() { return _type; }
enum class Type {
TRANSITION,
CURRENT,
ANY,
};
Type GetType() { return _type; }
OBSWeakSource GetTransition();
std::string ToString();
private:
OBSWeakSource _transition;
TransitionSelectionType _type = TransitionSelectionType::TRANSITION;
Type _type = Type::TRANSITION;
friend class TransitionSelectionWidget;
};