Skip to content

Commit

Permalink
CommandPalette: support transform effects
Browse files Browse the repository at this point in the history
Ref: #214
  • Loading branch information
rodlie committed Jul 29, 2024
1 parent de35bbc commit cac5e32
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

#include "RasterEffects/rastereffectmenucreator.h"
#include "BlendEffects/blendeffectmenucreator.h"
#include "TransformEffects/transformeffectmenucreator.h"

MainWindow *MainWindow::sInstance = nullptr;

Expand Down Expand Up @@ -1322,8 +1323,17 @@ void MainWindow::setupMenuEffects()
{ // path TODO
// adapt PathEffectsMenu::addPathEffectsToBoxActionMenu(menu);
}
{ // transform TODO
// adapt TransformEffectCollection::prp_setupTreeViewMenu(menu);
{ // transform
const auto adder = [this, menu](const QString& name,
const TransformEffectMenuCreator::EffectCreator& creator) {
if (name.isEmpty()) { return; }
const auto act = menu->addAction(name);
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addTransformEffect(creator());
});
};
TransformEffectMenuCreator::forEveryEffect(adder);
}
{ // blend
const auto adder = [this, menu](const QString& name,
Expand Down Expand Up @@ -1363,6 +1373,18 @@ void MainWindow::addBlendEffect(const qsptr<BlendEffect> &effect)
mDocument.actionFinished();
}

void MainWindow::addTransformEffect(const qsptr<TransformEffect> &effect)
{
const auto scene = *mDocument.fActiveScene;
if (!scene) { return; }

const auto box = scene->getCurrentBox();
if (!box) { return; }

box->addTransformEffect(effect);
mDocument.actionFinished();
}

void MainWindow::setupExtraMenus()
{
const auto menu = new QMenu(this);
Expand Down
1 change: 1 addition & 0 deletions src/app/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ class MainWindow : public QMainWindow
void setupMenuEffects();
void addRasterEffect(const qsptr<RasterEffect> &effect);
void addBlendEffect(const qsptr<BlendEffect> &effect);
void addTransformEffect(const qsptr<TransformEffect> &effect);
void setupExtraMenus();

QList<SceneBoundGradient*> mLoadedGradientsList;
Expand Down
2 changes: 2 additions & 0 deletions src/core/BlendEffects/blendeffectmenucreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef BLENDEFFECTMENUCREATOR_H
#define BLENDEFFECTMENUCREATOR_H

#include "core_global.h"

#include <QString>
#include <functional>
#include "BlendEffects/moveblendeffect.h"
Expand Down
5 changes: 5 additions & 0 deletions src/core/Boxes/boundingbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,11 @@ void BoundingBox::addBlendEffect(const qsptr<BlendEffect> &blendEffect)
mBlendEffectCollection->addChild(blendEffect);
}

void BoundingBox::addTransformEffect(const qsptr<TransformEffect> &transformEffect)
{
mTransformEffectCollection->addChild(transformEffect);
}

//int BoundingBox::prp_getParentFrameShift() const {
// if(!mParentGroup) {
// return 0;
Expand Down
1 change: 1 addition & 0 deletions src/core/Boxes/boundingbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound {
void removeRasterEffect(const qsptr<RasterEffect> &effect);

void addBlendEffect(const qsptr<BlendEffect> &blendEffect);
void addTransformEffect(const qsptr<TransformEffect> &transformEffect);

void setBlendModeSk(const SkBlendMode blendMode);

Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ set(
TransformEffects/trackeffect.h
TransformEffects/transformeffect.h
TransformEffects/transformeffectcollection.h
TransformEffects/transformeffectmenucreator.h
XML/runtimewriteid.h
XML/xevexporter.h
XML/xevimporter.h
Expand Down
62 changes: 62 additions & 0 deletions src/core/TransformEffects/transformeffectmenucreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
#
# Friction - https://friction.graphics
#
# Copyright (c) Friction contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# See 'README.md' for more information.
#
*/

#ifndef TRANSFORMEFFECTMENUCREATOR_H
#define TRANSFORMEFFECTMENUCREATOR_H

#include "core_global.h"

#include <QString>
#include <functional>
#include "TransformEffects/followobjecteffect.h"
#include "TransformEffects/followobjectrelativeeffect.h"
#include "TransformEffects/followpatheffect.h"
#include "TransformEffects/parenteffect.h"
#include "TransformEffects/trackeffect.h"
#include "smartPointers/selfref.h"

class TransformEffect;

struct CORE_EXPORT TransformEffectMenuCreator
{
template <typename T> using Func = std::function<T>;
template <typename T> using Creator = Func<qsptr<T>()>;
using EffectCreator = Creator<TransformEffect>;
using EffectAdder = Func<void(const QString&,
const EffectCreator&)>;
static void forEveryEffect(const EffectAdder& add)
{
add(QObject::tr("Add Track Effect"),
[]() { return enve::make_shared<TrackEffect>(); });
add(QObject::tr("Add Follow Path Effect"),
[]() { return enve::make_shared<FollowPathEffect>(); });
add(QObject::tr("Add Follow Object Effect"),
[]() { return enve::make_shared<FollowObjectEffect>(); });
add(QObject::tr("Add Follow Object Relative Effect"),
[]() { return enve::make_shared<FollowObjectRelativeEffect>(); });
add(QObject::tr("Add Parent Effect"),
[]() { return enve::make_shared<ParentEffect>(); });
}
};

#endif // TRANSFORMEFFECTMENUCREATOR_H

0 comments on commit cac5e32

Please sign in to comment.