change: change code style to Linux style except indent.
This commit is contained in:
@@ -24,155 +24,200 @@
|
||||
#include "core.h"
|
||||
#include "widget/slider/floatslider.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString CornerPinDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString CornerPinDistortNode::kTopLeftInput = QStringLiteral("top_left_in");
|
||||
const QString CornerPinDistortNode::kTopRightInput = QStringLiteral("top_right_in");
|
||||
const QString CornerPinDistortNode::kBottomRightInput = QStringLiteral("bottom_right_in");
|
||||
const QString CornerPinDistortNode::kBottomLeftInput = QStringLiteral("bottom_left_in");
|
||||
const QString CornerPinDistortNode::kPerspectiveInput = QStringLiteral("perspective_in");
|
||||
const QString CornerPinDistortNode::kTopLeftInput =
|
||||
QStringLiteral("top_left_in");
|
||||
const QString CornerPinDistortNode::kTopRightInput =
|
||||
QStringLiteral("top_right_in");
|
||||
const QString CornerPinDistortNode::kBottomRightInput =
|
||||
QStringLiteral("bottom_right_in");
|
||||
const QString CornerPinDistortNode::kBottomLeftInput =
|
||||
QStringLiteral("bottom_left_in");
|
||||
const QString CornerPinDistortNode::kPerspectiveInput =
|
||||
QStringLiteral("perspective_in");
|
||||
|
||||
#define super Node
|
||||
|
||||
CornerPinDistortNode::CornerPinDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kPerspectiveInput, NodeValue::kBoolean, true);
|
||||
AddInput(kTopLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kTopRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kBottomRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kBottomLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kPerspectiveInput, NodeValue::kBoolean, true);
|
||||
AddInput(kTopLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kTopRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kBottomRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
AddInput(kBottomLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
|
||||
|
||||
// Initiate gizmos
|
||||
gizmo_whole_rect_ = AddDraggableGizmo<PolygonGizmo>();
|
||||
gizmo_resize_handle_[0] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 0), NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 1)});
|
||||
gizmo_resize_handle_[1] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 0), NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 1)});
|
||||
gizmo_resize_handle_[2] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 0), NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 1)});
|
||||
gizmo_resize_handle_[3] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 0), NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 1)});
|
||||
// Initiate gizmos
|
||||
gizmo_whole_rect_ = AddDraggableGizmo<PolygonGizmo>();
|
||||
gizmo_resize_handle_[0] = AddDraggableGizmo<PointGizmo>(
|
||||
{ NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 1) });
|
||||
gizmo_resize_handle_[1] = AddDraggableGizmo<PointGizmo>(
|
||||
{ NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 1) });
|
||||
gizmo_resize_handle_[2] = AddDraggableGizmo<PointGizmo>(
|
||||
{ NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 1) });
|
||||
gizmo_resize_handle_[3] = AddDraggableGizmo<PointGizmo>(
|
||||
{ NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 1) });
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kPerspectiveInput, tr("Perspective"));
|
||||
SetInputName(kTopLeftInput, tr("Top Left"));
|
||||
SetInputName(kTopRightInput, tr("Top Right"));
|
||||
SetInputName(kBottomRightInput, tr("Bottom Right"));
|
||||
SetInputName(kBottomLeftInput, tr("Bottom Left"));
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kPerspectiveInput, tr("Perspective"));
|
||||
SetInputName(kTopLeftInput, tr("Top Left"));
|
||||
SetInputName(kTopRightInput, tr("Top Right"));
|
||||
SetInputName(kBottomRightInput, tr("Bottom Right"));
|
||||
SetInputName(kBottomLeftInput, tr("Bottom Left"));
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void CornerPinDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If no texture do nothing
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// In the special case that all sliders are in their default position just
|
||||
// push the texture.
|
||||
if (!(value[kTopLeftInput].toVec2().isNull()
|
||||
&& value[kTopRightInput].toVec2().isNull() &&
|
||||
value[kBottomRightInput].toVec2().isNull() &&
|
||||
value[kBottomLeftInput].toVec2().isNull())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
|
||||
// If no texture do nothing
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// In the special case that all sliders are in their default position just
|
||||
// push the texture.
|
||||
if (!(value[kTopLeftInput].toVec2().isNull() &&
|
||||
value[kTopRightInput].toVec2().isNull() &&
|
||||
value[kBottomRightInput].toVec2().isNull() &&
|
||||
value[kBottomLeftInput].toVec2().isNull())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
|
||||
this));
|
||||
|
||||
// Convert slider values to their pixel values and then convert to clip space (-1.0 ... 1.0) for overriding the
|
||||
// vertex coordinates.
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
QVector2D half_resolution = resolution * 0.5;
|
||||
QVector2D top_left = QVector2D(ValueToPixel(0, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
|
||||
QVector2D top_right = QVector2D(ValueToPixel(1, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
|
||||
QVector2D bottom_right = QVector2D(ValueToPixel(2, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
|
||||
QVector2D bottom_left = QVector2D(ValueToPixel(3, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
|
||||
// Convert slider values to their pixel values and then convert to clip space (-1.0 ... 1.0) for overriding the
|
||||
// vertex coordinates.
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
QVector2D half_resolution = resolution * 0.5;
|
||||
QVector2D top_left = QVector2D(ValueToPixel(0, value, resolution)) /
|
||||
half_resolution -
|
||||
QVector2D(1.0, 1.0);
|
||||
QVector2D top_right =
|
||||
QVector2D(ValueToPixel(1, value, resolution)) /
|
||||
half_resolution -
|
||||
QVector2D(1.0, 1.0);
|
||||
QVector2D bottom_right =
|
||||
QVector2D(ValueToPixel(2, value, resolution)) /
|
||||
half_resolution -
|
||||
QVector2D(1.0, 1.0);
|
||||
QVector2D bottom_left =
|
||||
QVector2D(ValueToPixel(3, value, resolution)) /
|
||||
half_resolution -
|
||||
QVector2D(1.0, 1.0);
|
||||
|
||||
// Override default vertex coordinates.
|
||||
QVector<float> adjusted_vertices = {top_left.x(), top_left.y(), 0.0f,
|
||||
top_right.x(), top_right.y(), 0.0f,
|
||||
bottom_right.x(), bottom_right.y(), 0.0f,
|
||||
// Override default vertex coordinates.
|
||||
QVector<float> adjusted_vertices = {
|
||||
top_left.x(), top_left.y(), 0.0f,
|
||||
top_right.x(), top_right.y(), 0.0f,
|
||||
bottom_right.x(), bottom_right.y(), 0.0f,
|
||||
|
||||
top_left.x(), top_left.y(), 0.0f,
|
||||
bottom_left.x(), bottom_left.y(), 0.0f,
|
||||
bottom_right.x(), bottom_right.y(), 0.0f};
|
||||
job.SetVertexCoordinates(adjusted_vertices);
|
||||
top_left.x(), top_left.y(), 0.0f,
|
||||
bottom_left.x(), bottom_left.y(), 0.0f,
|
||||
bottom_right.x(), bottom_right.y(), 0.0f
|
||||
};
|
||||
job.SetVertexCoordinates(adjusted_vertices);
|
||||
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShaderCode CornerPinDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
ShaderCode
|
||||
CornerPinDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
Q_UNUSED(request)
|
||||
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.frag")),
|
||||
FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.vert")));
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/cornerpin.frag")),
|
||||
FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/cornerpin.vert")));
|
||||
}
|
||||
|
||||
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow& row, const QVector2D &resolution) const
|
||||
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow &row,
|
||||
const QVector2D &resolution) const
|
||||
{
|
||||
Q_ASSERT(value >= 0 && value <= 3);
|
||||
Q_ASSERT(value >= 0 && value <= 3);
|
||||
|
||||
QVector2D v;
|
||||
QVector2D v;
|
||||
|
||||
switch (value) {
|
||||
case 0: // Top left
|
||||
v = row[kTopLeftInput].toVec2();
|
||||
return QPointF(v.x(), v.y());
|
||||
case 1: // Top right
|
||||
v = row[kTopRightInput].toVec2();
|
||||
return QPointF(resolution.x() + v.x(), v.y());
|
||||
case 2: // Bottom right
|
||||
v = row[kBottomRightInput].toVec2();
|
||||
return QPointF(resolution.x() + v.x(), resolution.y() + v.y());
|
||||
case 3: //Bottom left
|
||||
v = row[kBottomLeftInput].toVec2();
|
||||
return QPointF(v.x(), v.y() + resolution.y());
|
||||
default: // We should never get here
|
||||
return QPointF();
|
||||
}
|
||||
switch (value) {
|
||||
case 0: // Top left
|
||||
v = row[kTopLeftInput].toVec2();
|
||||
return QPointF(v.x(), v.y());
|
||||
case 1: // Top right
|
||||
v = row[kTopRightInput].toVec2();
|
||||
return QPointF(resolution.x() + v.x(), v.y());
|
||||
case 2: // Bottom right
|
||||
v = row[kBottomRightInput].toVec2();
|
||||
return QPointF(resolution.x() + v.x(), resolution.y() + v.y());
|
||||
case 3: //Bottom left
|
||||
v = row[kBottomLeftInput].toVec2();
|
||||
return QPointF(v.x(), v.y() + resolution.y());
|
||||
default: // We should never get here
|
||||
return QPointF();
|
||||
}
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void CornerPinDistortNode::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
|
||||
|
||||
if (gizmo != gizmo_whole_rect_) {
|
||||
gizmo->GetDraggers()[0].Drag(gizmo->GetDraggers()[0].GetStartValue().toDouble() + x);
|
||||
gizmo->GetDraggers()[1].Drag(gizmo->GetDraggers()[1].GetStartValue().toDouble() + y);
|
||||
}
|
||||
if (gizmo != gizmo_whole_rect_) {
|
||||
gizmo->GetDraggers()[0].Drag(
|
||||
gizmo->GetDraggers()[0].GetStartValue().toDouble() + x);
|
||||
gizmo->GetDraggers()[1].Drag(
|
||||
gizmo->GetDraggers()[1].GetStartValue().toDouble() + y);
|
||||
}
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void CornerPinDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
|
||||
QPointF top_left = ValueToPixel(0, row, resolution);
|
||||
QPointF top_right = ValueToPixel(1, row, resolution);
|
||||
QPointF bottom_right = ValueToPixel(2, row, resolution);
|
||||
QPointF bottom_left = ValueToPixel(3, row, resolution);
|
||||
QPointF top_left = ValueToPixel(0, row, resolution);
|
||||
QPointF top_right = ValueToPixel(1, row, resolution);
|
||||
QPointF bottom_right = ValueToPixel(2, row, resolution);
|
||||
QPointF bottom_left = ValueToPixel(3, row, resolution);
|
||||
|
||||
// Add the correct offset to each slider
|
||||
SetInputProperty(kTopLeftInput, QStringLiteral("offset"), QVector2D(0.0, 0.0));
|
||||
SetInputProperty(kTopRightInput, QStringLiteral("offset"), QVector2D(resolution.x() , 0.0));
|
||||
SetInputProperty(kBottomRightInput, QStringLiteral("offset"), resolution);
|
||||
SetInputProperty(kBottomLeftInput, QStringLiteral("offset"), QVector2D(0.0, resolution.y()));
|
||||
// Add the correct offset to each slider
|
||||
SetInputProperty(kTopLeftInput, QStringLiteral("offset"),
|
||||
QVector2D(0.0, 0.0));
|
||||
SetInputProperty(kTopRightInput, QStringLiteral("offset"),
|
||||
QVector2D(resolution.x(), 0.0));
|
||||
SetInputProperty(kBottomRightInput, QStringLiteral("offset"),
|
||||
resolution);
|
||||
SetInputProperty(kBottomLeftInput, QStringLiteral("offset"),
|
||||
QVector2D(0.0, resolution.y()));
|
||||
|
||||
// Draw bounding box
|
||||
gizmo_whole_rect_->SetPolygon(QPolygonF({top_left, top_right, bottom_right, bottom_left, top_left}));
|
||||
// Draw bounding box
|
||||
gizmo_whole_rect_->SetPolygon(QPolygonF(
|
||||
{ top_left, top_right, bottom_right, bottom_left, top_left }));
|
||||
|
||||
// Create handles
|
||||
gizmo_resize_handle_[0]->SetPoint(top_left);
|
||||
gizmo_resize_handle_[1]->SetPoint(top_right);
|
||||
gizmo_resize_handle_[2]->SetPoint(bottom_right);
|
||||
gizmo_resize_handle_[3]->SetPoint(bottom_left);
|
||||
}
|
||||
// Create handles
|
||||
gizmo_resize_handle_[0]->SetPoint(top_left);
|
||||
gizmo_resize_handle_[1]->SetPoint(top_right);
|
||||
gizmo_resize_handle_[2]->SetPoint(bottom_right);
|
||||
gizmo_resize_handle_[3]->SetPoint(bottom_left);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,68 +28,71 @@
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
class CornerPinDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
class CornerPinDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CornerPinDistortNode();
|
||||
CornerPinDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(CornerPinDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(CornerPinDistortNode)
|
||||
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Corner Pin");
|
||||
}
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Corner Pin");
|
||||
}
|
||||
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.cornerpin");
|
||||
}
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.cornerpin");
|
||||
}
|
||||
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
}
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Distort the image by dragging the corners.");
|
||||
}
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Distort the image by dragging the corners.");
|
||||
}
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Convenience function - converts the 2D slider values from being
|
||||
* an offset to the actual pixel value.
|
||||
*/
|
||||
QPointF ValueToPixel(int value, const NodeValueRow &row, const QVector2D &resolution) const;
|
||||
QPointF ValueToPixel(int value, const NodeValueRow &row,
|
||||
const QVector2D &resolution) const;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kPerspectiveInput;
|
||||
static const QString kTopLeftInput;
|
||||
static const QString kTopRightInput;
|
||||
static const QString kBottomRightInput;
|
||||
static const QString kBottomLeftInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kPerspectiveInput;
|
||||
static const QString kTopLeftInput;
|
||||
static const QString kTopRightInput;
|
||||
static const QString kBottomRightInput;
|
||||
static const QString kBottomLeftInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
// Gizmo variables
|
||||
static const int kGizmoCornerCount = 4;
|
||||
PointGizmo *gizmo_resize_handle_[kGizmoCornerCount];
|
||||
PolygonGizmo *gizmo_whole_rect_;
|
||||
|
||||
// Gizmo variables
|
||||
static const int kGizmoCornerCount = 4;
|
||||
PointGizmo *gizmo_resize_handle_[kGizmoCornerCount];
|
||||
PolygonGizmo *gizmo_whole_rect_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // CORNERPINDISTORTNODE_H
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include "core.h"
|
||||
#include "widget/slider/floatslider.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString CropDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString CropDistortNode::kLeftInput = QStringLiteral("left_in");
|
||||
@@ -37,124 +38,151 @@ const QString CropDistortNode::kFeatherInput = QStringLiteral("feather_in");
|
||||
|
||||
CropDistortNode::CropDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
CreateCropSideInput(kLeftInput);
|
||||
CreateCropSideInput(kTopInput);
|
||||
CreateCropSideInput(kRightInput);
|
||||
CreateCropSideInput(kBottomInput);
|
||||
CreateCropSideInput(kLeftInput);
|
||||
CreateCropSideInput(kTopInput);
|
||||
CreateCropSideInput(kRightInput);
|
||||
CreateCropSideInput(kBottomInput);
|
||||
|
||||
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
|
||||
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
|
||||
|
||||
// Initiate gizmos
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({kLeftInput, kTopInput, kRightInput, kBottomInput});
|
||||
// Initiate gizmos
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>(
|
||||
{ kLeftInput, kTopInput, kRightInput, kBottomInput });
|
||||
|
||||
point_gizmo_[kGizmoScaleTopLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput, kTopInput});
|
||||
point_gizmo_[kGizmoScaleTopCenter] = AddDraggableGizmo<PointGizmo>({kTopInput});
|
||||
point_gizmo_[kGizmoScaleTopRight] = AddDraggableGizmo<PointGizmo>({kRightInput, kTopInput});
|
||||
point_gizmo_[kGizmoScaleBottomLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput, kBottomInput});
|
||||
point_gizmo_[kGizmoScaleBottomCenter] = AddDraggableGizmo<PointGizmo>({kBottomInput});
|
||||
point_gizmo_[kGizmoScaleBottomRight] = AddDraggableGizmo<PointGizmo>({kRightInput, kBottomInput});
|
||||
point_gizmo_[kGizmoScaleCenterLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput});
|
||||
point_gizmo_[kGizmoScaleCenterRight] = AddDraggableGizmo<PointGizmo>({kRightInput});
|
||||
point_gizmo_[kGizmoScaleTopLeft] =
|
||||
AddDraggableGizmo<PointGizmo>({ kLeftInput, kTopInput });
|
||||
point_gizmo_[kGizmoScaleTopCenter] =
|
||||
AddDraggableGizmo<PointGizmo>({ kTopInput });
|
||||
point_gizmo_[kGizmoScaleTopRight] =
|
||||
AddDraggableGizmo<PointGizmo>({ kRightInput, kTopInput });
|
||||
point_gizmo_[kGizmoScaleBottomLeft] =
|
||||
AddDraggableGizmo<PointGizmo>({ kLeftInput, kBottomInput });
|
||||
point_gizmo_[kGizmoScaleBottomCenter] =
|
||||
AddDraggableGizmo<PointGizmo>({ kBottomInput });
|
||||
point_gizmo_[kGizmoScaleBottomRight] =
|
||||
AddDraggableGizmo<PointGizmo>({ kRightInput, kBottomInput });
|
||||
point_gizmo_[kGizmoScaleCenterLeft] =
|
||||
AddDraggableGizmo<PointGizmo>({ kLeftInput });
|
||||
point_gizmo_[kGizmoScaleCenterRight] =
|
||||
AddDraggableGizmo<PointGizmo>({ kRightInput });
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
}
|
||||
|
||||
void CropDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kLeftInput, tr("Left"));
|
||||
SetInputName(kTopInput, tr("Top"));
|
||||
SetInputName(kRightInput, tr("Right"));
|
||||
SetInputName(kBottomInput, tr("Bottom"));
|
||||
SetInputName(kFeatherInput, tr("Feather"));
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kLeftInput, tr("Left"));
|
||||
SetInputName(kTopInput, tr("Top"));
|
||||
SetInputName(kRightInput, tr("Right"));
|
||||
SetInputName(kBottomInput, tr("Bottom"));
|
||||
SetInputName(kFeatherInput, tr("Feather"));
|
||||
}
|
||||
|
||||
void CropDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void CropDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
ShaderJob job;
|
||||
job.Insert(value);
|
||||
ShaderJob job;
|
||||
job.Insert(value);
|
||||
|
||||
if (TexturePtr texture = job.Get(kTextureInput).toTexture()) {
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, QVector2D(texture->params().width(), texture->params().height()), this));
|
||||
if (TexturePtr texture = job.Get(kTextureInput).toTexture()) {
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2,
|
||||
QVector2D(texture->params().width(),
|
||||
texture->params().height()),
|
||||
this));
|
||||
|
||||
if (!qIsNull(job.Get(kLeftInput).toDouble())
|
||||
|| !qIsNull(job.Get(kRightInput).toDouble())
|
||||
|| !qIsNull(job.Get(kTopInput).toDouble())
|
||||
|| !qIsNull(job.Get(kBottomInput).toDouble())) {
|
||||
table->Push(NodeValue::kTexture, texture->toJob(job), this);
|
||||
} else {
|
||||
table->Push(job.Get(kTextureInput));
|
||||
}
|
||||
}
|
||||
if (!qIsNull(job.Get(kLeftInput).toDouble()) ||
|
||||
!qIsNull(job.Get(kRightInput).toDouble()) ||
|
||||
!qIsNull(job.Get(kTopInput).toDouble()) ||
|
||||
!qIsNull(job.Get(kBottomInput).toDouble())) {
|
||||
table->Push(NodeValue::kTexture, texture->toJob(job), this);
|
||||
} else {
|
||||
table->Push(job.Get(kTextureInput));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShaderCode CropDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/crop.frag")));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(
|
||||
FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/crop.frag")));
|
||||
}
|
||||
|
||||
void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
temp_resolution_ = resolution;
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
const QVector2D &resolution = tex->virtual_resolution();
|
||||
temp_resolution_ = resolution;
|
||||
|
||||
double left_pt = resolution.x() * row[kLeftInput].toDouble();
|
||||
double top_pt = resolution.y() * row[kTopInput].toDouble();
|
||||
double right_pt = resolution.x() * (1.0 - row[kRightInput].toDouble());
|
||||
double bottom_pt = resolution.y() * (1.0 - row[kBottomInput].toDouble());
|
||||
double center_x_pt = mid(left_pt, right_pt);
|
||||
double center_y_pt = mid(top_pt, bottom_pt);
|
||||
double left_pt = resolution.x() * row[kLeftInput].toDouble();
|
||||
double top_pt = resolution.y() * row[kTopInput].toDouble();
|
||||
double right_pt = resolution.x() * (1.0 - row[kRightInput].toDouble());
|
||||
double bottom_pt =
|
||||
resolution.y() * (1.0 - row[kBottomInput].toDouble());
|
||||
double center_x_pt = mid(left_pt, right_pt);
|
||||
double center_y_pt = mid(top_pt, bottom_pt);
|
||||
|
||||
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(QPointF(center_x_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(QPointF(right_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(QPointF(left_pt, center_y_pt));
|
||||
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(QPointF(right_pt, center_y_pt));
|
||||
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(
|
||||
QPointF(center_x_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
|
||||
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(
|
||||
QPointF(left_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
|
||||
QPointF(center_x_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
|
||||
QPointF(right_pt, bottom_pt));
|
||||
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
|
||||
QPointF(left_pt, center_y_pt));
|
||||
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
|
||||
QPointF(right_pt, center_y_pt));
|
||||
|
||||
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
|
||||
}
|
||||
poly_gizmo_->SetPolygon(
|
||||
QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
|
||||
}
|
||||
}
|
||||
|
||||
void CropDistortNode::GizmoDragMove(double x_diff, double y_diff, const Qt::KeyboardModifiers &modifiers)
|
||||
void CropDistortNode::GizmoDragMove(double x_diff, double y_diff,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
|
||||
|
||||
QVector2D res = temp_resolution_;
|
||||
x_diff /= res.x();
|
||||
y_diff /= res.y();
|
||||
QVector2D res = temp_resolution_;
|
||||
x_diff /= res.x();
|
||||
y_diff /= res.y();
|
||||
|
||||
for (int j=0; j<gizmo->GetDraggers().size(); j++) {
|
||||
NodeInputDragger& i = gizmo->GetDraggers()[j];
|
||||
double s = i.GetStartValue().toDouble();
|
||||
if (i.GetInput().input().input() == kLeftInput) {
|
||||
i.Drag(s + x_diff);
|
||||
} else if (i.GetInput().input().input() == kTopInput) {
|
||||
i.Drag(s + y_diff);
|
||||
} else if (i.GetInput().input().input() == kRightInput) {
|
||||
i.Drag(s - x_diff);
|
||||
} else if (i.GetInput().input().input() == kBottomInput) {
|
||||
i.Drag(s - y_diff);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < gizmo->GetDraggers().size(); j++) {
|
||||
NodeInputDragger &i = gizmo->GetDraggers()[j];
|
||||
double s = i.GetStartValue().toDouble();
|
||||
if (i.GetInput().input().input() == kLeftInput) {
|
||||
i.Drag(s + x_diff);
|
||||
} else if (i.GetInput().input().input() == kTopInput) {
|
||||
i.Drag(s + y_diff);
|
||||
} else if (i.GetInput().input().input() == kRightInput) {
|
||||
i.Drag(s - x_diff);
|
||||
} else if (i.GetInput().input().input() == kBottomInput) {
|
||||
i.Drag(s - y_diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CropDistortNode::CreateCropSideInput(const QString &id)
|
||||
{
|
||||
AddInput(id, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(id, QStringLiteral("min"), 0.0);
|
||||
SetInputProperty(id, QStringLiteral("max"), 1.0);
|
||||
SetInputProperty(id, QStringLiteral("view"), FloatSlider::kPercentage);
|
||||
AddInput(id, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(id, QStringLiteral("min"), 0.0);
|
||||
SetInputProperty(id, QStringLiteral("max"), 1.0);
|
||||
SetInputProperty(id, QStringLiteral("view"), FloatSlider::kPercentage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,62 +28,65 @@
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class CropDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class CropDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CropDistortNode();
|
||||
CropDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(CropDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(CropDistortNode)
|
||||
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Crop");
|
||||
}
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Crop");
|
||||
}
|
||||
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.crop");
|
||||
}
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.crop");
|
||||
}
|
||||
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
}
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Crop the edges of an image.");
|
||||
}
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Crop the edges of an image.");
|
||||
}
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kLeftInput;
|
||||
static const QString kTopInput;
|
||||
static const QString kRightInput;
|
||||
static const QString kBottomInput;
|
||||
static const QString kFeatherInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kLeftInput;
|
||||
static const QString kTopInput;
|
||||
static const QString kRightInput;
|
||||
static const QString kBottomInput;
|
||||
static const QString kFeatherInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double delta_x, double delta_y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double delta_x, double delta_y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
void CreateCropSideInput(const QString& id);
|
||||
|
||||
// Gizmo variables
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
QVector2D temp_resolution_;
|
||||
void CreateCropSideInput(const QString &id);
|
||||
|
||||
// Gizmo variables
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
QVector2D temp_resolution_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include "flipdistortnode.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString FlipDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString FlipDistortNode::kHorizontalInput = QStringLiteral("horiz_in");
|
||||
@@ -30,63 +31,68 @@ const QString FlipDistortNode::kVerticalInput = QStringLiteral("vert_in");
|
||||
|
||||
FlipDistortNode::FlipDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
AddInput(kHorizontalInput, NodeValue::kBoolean, false);
|
||||
AddInput(kHorizontalInput, NodeValue::kBoolean, false);
|
||||
|
||||
AddInput(kVerticalInput, NodeValue::kBoolean, false);
|
||||
AddInput(kVerticalInput, NodeValue::kBoolean, false);
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
}
|
||||
|
||||
QString FlipDistortNode::Name() const
|
||||
{
|
||||
return tr("Flip");
|
||||
return tr("Flip");
|
||||
}
|
||||
|
||||
QString FlipDistortNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.oliveeditor.Olive.flip");
|
||||
return QStringLiteral("org.oliveeditor.Olive.flip");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> FlipDistortNode::Category() const
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
QString FlipDistortNode::Description() const
|
||||
{
|
||||
return tr("Flips an image horizontally or vertically");
|
||||
return tr("Flips an image horizontally or vertically");
|
||||
}
|
||||
|
||||
void FlipDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kHorizontalInput, tr("Horizontal"));
|
||||
SetInputName(kVerticalInput, tr("Vertical"));
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kHorizontalInput, tr("Horizontal"));
|
||||
SetInputName(kVerticalInput, tr("Vertical"));
|
||||
}
|
||||
|
||||
ShaderCode FlipDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/flip.frag"));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/flip.frag"));
|
||||
}
|
||||
|
||||
void FlipDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void FlipDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (value[kHorizontalInput].toBool() || value[kVerticalInput].toBool()) {
|
||||
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (value[kHorizontalInput].toBool() ||
|
||||
value[kVerticalInput].toBool()) {
|
||||
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)),
|
||||
this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,30 +23,31 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class FlipDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class FlipDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FlipDistortNode();
|
||||
FlipDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(FlipDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(FlipDistortNode)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kHorizontalInput;
|
||||
static const QString kVerticalInput;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kHorizontalInput;
|
||||
static const QString kVerticalInput;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
#include "node/filter/blur/blur.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super PolygonGenerator
|
||||
|
||||
@@ -31,81 +32,101 @@ const QString MaskDistortNode::kInvertInput = QStringLiteral("invert_in");
|
||||
|
||||
MaskDistortNode::MaskDistortNode()
|
||||
{
|
||||
// Mask should always be (1.0, 1.0, 1.0) for multiply to work correctly
|
||||
SetInputFlag(kColorInput, kInputFlagHidden);
|
||||
// Mask should always be (1.0, 1.0, 1.0) for multiply to work correctly
|
||||
SetInputFlag(kColorInput, kInputFlagHidden);
|
||||
|
||||
AddInput(kInvertInput, NodeValue::kBoolean, false);
|
||||
AddInput(kInvertInput, NodeValue::kBoolean, false);
|
||||
|
||||
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
|
||||
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
|
||||
}
|
||||
|
||||
ShaderCode MaskDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
if (request.id == QStringLiteral("mrg")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/multiply.frag")));
|
||||
} else if (request.id == QStringLiteral("feather")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/blur.frag")));
|
||||
} else if (request.id == QStringLiteral("invert")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/invertrgba.frag")));
|
||||
} else {
|
||||
return super::GetShaderCode(request);
|
||||
}
|
||||
if (request.id == QStringLiteral("mrg")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/multiply.frag")));
|
||||
} else if (request.id == QStringLiteral("feather")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/blur.frag")));
|
||||
} else if (request.id == QStringLiteral("invert")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/invertrgba.frag")));
|
||||
} else {
|
||||
return super::GetShaderCode(request);
|
||||
}
|
||||
}
|
||||
|
||||
void MaskDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kBaseInput, tr("Texture"));
|
||||
SetInputName(kInvertInput, tr("Invert"));
|
||||
SetInputName(kFeatherInput, tr("Feather"));
|
||||
SetInputName(kBaseInput, tr("Texture"));
|
||||
SetInputName(kInvertInput, tr("Invert"));
|
||||
SetInputName(kFeatherInput, tr("Feather"));
|
||||
}
|
||||
|
||||
void MaskDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void MaskDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
TexturePtr texture = value[kBaseInput].toTexture();
|
||||
TexturePtr texture = value[kBaseInput].toTexture();
|
||||
|
||||
VideoParams job_params = texture ? texture->params() : globals.vparams();
|
||||
NodeValue job(NodeValue::kTexture, Texture::Job(job_params, GetGenerateJob(value, job_params)), this);
|
||||
VideoParams job_params = texture ? texture->params() : globals.vparams();
|
||||
NodeValue job(NodeValue::kTexture,
|
||||
Texture::Job(job_params, GetGenerateJob(value, job_params)),
|
||||
this);
|
||||
|
||||
if (value[kInvertInput].toBool()) {
|
||||
ShaderJob invert;
|
||||
invert.SetShaderID(QStringLiteral("invert"));
|
||||
invert.Insert(QStringLiteral("tex_in"), job);
|
||||
job.set_value(Texture::Job(job_params, invert));
|
||||
}
|
||||
if (value[kInvertInput].toBool()) {
|
||||
ShaderJob invert;
|
||||
invert.SetShaderID(QStringLiteral("invert"));
|
||||
invert.Insert(QStringLiteral("tex_in"), job);
|
||||
job.set_value(Texture::Job(job_params, invert));
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
// Push as merge node
|
||||
ShaderJob merge;
|
||||
if (texture) {
|
||||
// Push as merge node
|
||||
ShaderJob merge;
|
||||
|
||||
merge.SetShaderID(QStringLiteral("mrg"));
|
||||
merge.Insert(QStringLiteral("tex_a"), value[kBaseInput]);
|
||||
merge.SetShaderID(QStringLiteral("mrg"));
|
||||
merge.Insert(QStringLiteral("tex_a"), value[kBaseInput]);
|
||||
|
||||
if (value[kFeatherInput].toDouble() > 0.0) {
|
||||
// Nest a blur shader in there too
|
||||
ShaderJob feather;
|
||||
if (value[kFeatherInput].toDouble() > 0.0) {
|
||||
// Nest a blur shader in there too
|
||||
ShaderJob feather;
|
||||
|
||||
feather.SetShaderID(QStringLiteral("feather"));
|
||||
feather.Insert(BlurFilterNode::kTextureInput, job);
|
||||
feather.Insert(BlurFilterNode::kMethodInput, NodeValue(NodeValue::kInt, int(BlurFilterNode::kGaussian), this));
|
||||
feather.Insert(BlurFilterNode::kHorizInput, NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kVertInput, NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kRepeatEdgePixelsInput, NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kRadiusInput, NodeValue(NodeValue::kFloat, value[kFeatherInput].toDouble(), this));
|
||||
feather.SetIterations(2, BlurFilterNode::kTextureInput);
|
||||
feather.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, texture ? texture->virtual_resolution() : globals.square_resolution(), this));
|
||||
feather.SetShaderID(QStringLiteral("feather"));
|
||||
feather.Insert(BlurFilterNode::kTextureInput, job);
|
||||
feather.Insert(BlurFilterNode::kMethodInput,
|
||||
NodeValue(NodeValue::kInt,
|
||||
int(BlurFilterNode::kGaussian), this));
|
||||
feather.Insert(BlurFilterNode::kHorizInput,
|
||||
NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kVertInput,
|
||||
NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kRepeatEdgePixelsInput,
|
||||
NodeValue(NodeValue::kBoolean, true, this));
|
||||
feather.Insert(BlurFilterNode::kRadiusInput,
|
||||
NodeValue(NodeValue::kFloat,
|
||||
value[kFeatherInput].toDouble(), this));
|
||||
feather.SetIterations(2, BlurFilterNode::kTextureInput);
|
||||
feather.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2,
|
||||
texture ? texture->virtual_resolution() :
|
||||
globals.square_resolution(),
|
||||
this));
|
||||
|
||||
merge.Insert(QStringLiteral("tex_b"), NodeValue(NodeValue::kTexture, Texture::Job(job_params, feather), this));
|
||||
} else {
|
||||
merge.Insert(QStringLiteral("tex_b"), job);
|
||||
}
|
||||
merge.Insert(QStringLiteral("tex_b"),
|
||||
NodeValue(NodeValue::kTexture,
|
||||
Texture::Job(job_params, feather), this));
|
||||
} else {
|
||||
merge.Insert(QStringLiteral("tex_b"), job);
|
||||
}
|
||||
|
||||
table->Push(NodeValue::kTexture, Texture::Job(job_params, merge), this);
|
||||
} else {
|
||||
table->Push(job);
|
||||
}
|
||||
table->Push(NodeValue::kTexture, Texture::Job(job_params, merge), this);
|
||||
} else {
|
||||
table->Push(job);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,45 +23,46 @@
|
||||
|
||||
#include "node/generator/polygon/polygon.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class MaskDistortNode : public PolygonGenerator
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class MaskDistortNode : public PolygonGenerator {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MaskDistortNode();
|
||||
MaskDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(MaskDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(MaskDistortNode)
|
||||
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Mask");
|
||||
}
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Mask");
|
||||
}
|
||||
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.mask");
|
||||
}
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.mask");
|
||||
}
|
||||
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
}
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Apply a polygonal mask.");
|
||||
}
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Apply a polygonal mask.");
|
||||
}
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
|
||||
static const QString kInvertInput;
|
||||
static const QString kFeatherInput;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
static const QString kInvertInput;
|
||||
static const QString kFeatherInput;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,16 @@
|
||||
|
||||
#include "rippledistortnode.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString RippleDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString RippleDistortNode::kEvolutionInput = QStringLiteral("evolution_in");
|
||||
const QString RippleDistortNode::kIntensityInput = QStringLiteral("intensity_in");
|
||||
const QString RippleDistortNode::kFrequencyInput = QStringLiteral("frequency_in");
|
||||
const QString RippleDistortNode::kEvolutionInput =
|
||||
QStringLiteral("evolution_in");
|
||||
const QString RippleDistortNode::kIntensityInput =
|
||||
QStringLiteral("intensity_in");
|
||||
const QString RippleDistortNode::kFrequencyInput =
|
||||
QStringLiteral("frequency_in");
|
||||
const QString RippleDistortNode::kPositionInput = QStringLiteral("position_in");
|
||||
const QString RippleDistortNode::kStretchInput = QStringLiteral("stretch_in");
|
||||
|
||||
@@ -33,96 +37,104 @@ const QString RippleDistortNode::kStretchInput = QStringLiteral("stretch_in");
|
||||
|
||||
RippleDistortNode::RippleDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
|
||||
AddInput(kIntensityInput, NodeValue::kFloat, 100);
|
||||
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
|
||||
AddInput(kIntensityInput, NodeValue::kFloat, 100);
|
||||
|
||||
AddInput(kFrequencyInput, NodeValue::kFloat, 1);
|
||||
SetInputProperty(kFrequencyInput, QStringLiteral("base"), 0.01);
|
||||
AddInput(kFrequencyInput, NodeValue::kFloat, 1);
|
||||
SetInputProperty(kFrequencyInput, QStringLiteral("base"), 0.01);
|
||||
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kStretchInput, NodeValue::kBoolean, false);
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kStretchInput, NodeValue::kBoolean, false);
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
}
|
||||
|
||||
QString RippleDistortNode::Name() const
|
||||
{
|
||||
return tr("Ripple");
|
||||
return tr("Ripple");
|
||||
}
|
||||
|
||||
QString RippleDistortNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.oliveeditor.Olive.ripple");
|
||||
return QStringLiteral("org.oliveeditor.Olive.ripple");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> RippleDistortNode::Category() const
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
QString RippleDistortNode::Description() const
|
||||
{
|
||||
return tr("Distorts an image with a ripple effect.");
|
||||
return tr("Distorts an image with a ripple effect.");
|
||||
}
|
||||
|
||||
void RippleDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kFrequencyInput, tr("Frequency"));
|
||||
SetInputName(kIntensityInput, tr("Intensity"));
|
||||
SetInputName(kEvolutionInput, tr("Evolution"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kStretchInput, tr("Stretch"));
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kFrequencyInput, tr("Frequency"));
|
||||
SetInputName(kIntensityInput, tr("Intensity"));
|
||||
SetInputName(kEvolutionInput, tr("Evolution"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kStretchInput, tr("Stretch"));
|
||||
}
|
||||
|
||||
ShaderCode RippleDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/ripple.frag"));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/ripple.frag"));
|
||||
}
|
||||
|
||||
void RippleDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void RippleDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kIntensityInput].toDouble())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kIntensityInput].toDouble())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
|
||||
this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RippleDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void RippleDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
QPointF half_res(tex->virtual_resolution().x()/2, tex->virtual_resolution().y()/2);
|
||||
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
|
||||
}
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
QPointF half_res(tex->virtual_resolution().x() / 2,
|
||||
tex->virtual_resolution().y() / 2);
|
||||
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
|
||||
}
|
||||
}
|
||||
|
||||
void RippleDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void RippleDistortNode::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,41 +24,44 @@
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class RippleDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class RippleDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RippleDistortNode();
|
||||
RippleDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(RippleDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(RippleDistortNode)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kEvolutionInput;
|
||||
static const QString kIntensityInput;
|
||||
static const QString kFrequencyInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kStretchInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kEvolutionInput;
|
||||
static const QString kIntensityInput;
|
||||
static const QString kFrequencyInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kStretchInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
PointGizmo *gizmo_;
|
||||
|
||||
PointGizmo *gizmo_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include "swirldistortnode.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString SwirlDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString SwirlDistortNode::kRadiusInput = QStringLiteral("radius_in");
|
||||
@@ -31,92 +32,101 @@ const QString SwirlDistortNode::kPositionInput = QStringLiteral("pos_in");
|
||||
|
||||
SwirlDistortNode::SwirlDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
AddInput(kRadiusInput, NodeValue::kFloat, 200);
|
||||
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0);
|
||||
AddInput(kRadiusInput, NodeValue::kFloat, 200);
|
||||
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0);
|
||||
|
||||
AddInput(kAngleInput, NodeValue::kFloat, 10);
|
||||
SetInputProperty(kAngleInput, QStringLiteral("base"), 0.1);
|
||||
AddInput(kAngleInput, NodeValue::kFloat, 10);
|
||||
SetInputProperty(kAngleInput, QStringLiteral("base"), 0.1);
|
||||
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
}
|
||||
|
||||
QString SwirlDistortNode::Name() const
|
||||
{
|
||||
return tr("Swirl");
|
||||
return tr("Swirl");
|
||||
}
|
||||
|
||||
QString SwirlDistortNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.oliveeditor.Olive.swirl");
|
||||
return QStringLiteral("org.oliveeditor.Olive.swirl");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> SwirlDistortNode::Category() const
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
QString SwirlDistortNode::Description() const
|
||||
{
|
||||
return tr("Distorts an image along a sine wave.");
|
||||
return tr("Distorts an image along a sine wave.");
|
||||
}
|
||||
|
||||
void SwirlDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kRadiusInput, tr("Radius"));
|
||||
SetInputName(kAngleInput, tr("Angle"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kRadiusInput, tr("Radius"));
|
||||
SetInputName(kAngleInput, tr("Angle"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
}
|
||||
|
||||
ShaderCode SwirlDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/swirl.frag"));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/swirl.frag"));
|
||||
}
|
||||
|
||||
void SwirlDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void SwirlDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kAngleInput].toDouble()) && !qIsNull(value[kRadiusInput].toDouble())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kAngleInput].toDouble()) &&
|
||||
!qIsNull(value[kRadiusInput].toDouble())) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
|
||||
this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SwirlDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void SwirlDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
QPointF half_res(globals.square_resolution().x()/2, globals.square_resolution().y()/2);
|
||||
QPointF half_res(globals.square_resolution().x() / 2,
|
||||
globals.square_resolution().y() / 2);
|
||||
|
||||
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
|
||||
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
|
||||
}
|
||||
|
||||
void SwirlDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void SwirlDistortNode::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,39 +24,42 @@
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SwirlDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class SwirlDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SwirlDistortNode();
|
||||
SwirlDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(SwirlDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(SwirlDistortNode)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kRadiusInput;
|
||||
static const QString kAngleInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kRadiusInput;
|
||||
static const QString kAngleInput;
|
||||
static const QString kPositionInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
PointGizmo *gizmo_;
|
||||
|
||||
PointGizmo *gizmo_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
#include "widget/slider/floatslider.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString TileDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString TileDistortNode::kScaleInput = QStringLiteral("scale_in");
|
||||
@@ -35,130 +36,141 @@ const QString TileDistortNode::kMirrorYInput = QStringLiteral("mirrory_in");
|
||||
|
||||
TileDistortNode::TileDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
AddInput(kScaleInput, NodeValue::kFloat, 0.5);
|
||||
SetInputProperty(kScaleInput, QStringLiteral("min"), 0);
|
||||
SetInputProperty(kScaleInput, QStringLiteral("view"), FloatSlider::kPercentage);
|
||||
AddInput(kScaleInput, NodeValue::kFloat, 0.5);
|
||||
SetInputProperty(kScaleInput, QStringLiteral("min"), 0);
|
||||
SetInputProperty(kScaleInput, QStringLiteral("view"),
|
||||
FloatSlider::kPercentage);
|
||||
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
|
||||
AddInput(kAnchorInput, NodeValue::kCombo, kMiddleCenter);
|
||||
AddInput(kAnchorInput, NodeValue::kCombo, kMiddleCenter);
|
||||
|
||||
AddInput(kMirrorXInput, NodeValue::kBoolean, false);
|
||||
AddInput(kMirrorYInput, NodeValue::kBoolean, false);
|
||||
AddInput(kMirrorXInput, NodeValue::kBoolean, false);
|
||||
AddInput(kMirrorYInput, NodeValue::kBoolean, false);
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
gizmo_ = AddDraggableGizmo<PointGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
}
|
||||
|
||||
QString TileDistortNode::Name() const
|
||||
{
|
||||
return tr("Tile");
|
||||
return tr("Tile");
|
||||
}
|
||||
|
||||
QString TileDistortNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.oliveeditor.Olive.tile");
|
||||
return QStringLiteral("org.oliveeditor.Olive.tile");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TileDistortNode::Category() const
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
QString TileDistortNode::Description() const
|
||||
{
|
||||
return tr("Infinitely tile an image horizontally and vertically.");
|
||||
return tr("Infinitely tile an image horizontally and vertically.");
|
||||
}
|
||||
|
||||
void TileDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kScaleInput, tr("Scale"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kMirrorXInput, tr("Mirror Horizontally"));
|
||||
SetInputName(kMirrorYInput, tr("Mirror Vertically"));
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kScaleInput, tr("Scale"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kMirrorXInput, tr("Mirror Horizontally"));
|
||||
SetInputName(kMirrorYInput, tr("Mirror Vertically"));
|
||||
|
||||
SetInputName(kAnchorInput, tr("Anchor"));
|
||||
SetComboBoxStrings(kAnchorInput, {
|
||||
tr("Top-Left"),
|
||||
tr("Top-Center"),
|
||||
tr("Top-Right"),
|
||||
tr("Middle-Left"),
|
||||
tr("Middle-Center"),
|
||||
tr("Middle-Right"),
|
||||
tr("Bottom-Left"),
|
||||
tr("Bottom-Center"),
|
||||
tr("Bottom-Right"),
|
||||
});
|
||||
SetInputName(kAnchorInput, tr("Anchor"));
|
||||
SetComboBoxStrings(kAnchorInput, {
|
||||
tr("Top-Left"),
|
||||
tr("Top-Center"),
|
||||
tr("Top-Right"),
|
||||
tr("Middle-Left"),
|
||||
tr("Middle-Center"),
|
||||
tr("Middle-Right"),
|
||||
tr("Bottom-Left"),
|
||||
tr("Bottom-Center"),
|
||||
tr("Bottom-Right"),
|
||||
});
|
||||
}
|
||||
|
||||
ShaderCode TileDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/tile.frag"));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/tile.frag"));
|
||||
}
|
||||
|
||||
void TileDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TileDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qFuzzyCompare(value[kScaleInput].toDouble(), 1.0)) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr tex = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qFuzzyCompare(value[kScaleInput].toDouble(), 1.0)) {
|
||||
ShaderJob job(value);
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
|
||||
this));
|
||||
table->Push(NodeValue::kTexture, tex->toJob(job), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void TileDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
QPointF res = tex->virtual_resolution().toPointF();
|
||||
QPointF pos = row[kPositionInput].toVec2().toPointF();
|
||||
qreal x = pos.x();
|
||||
qreal y = pos.y();
|
||||
if (TexturePtr tex = row[kTextureInput].toTexture()) {
|
||||
QPointF res = tex->virtual_resolution().toPointF();
|
||||
QPointF pos = row[kPositionInput].toVec2().toPointF();
|
||||
qreal x = pos.x();
|
||||
qreal y = pos.y();
|
||||
|
||||
Anchor a = static_cast<Anchor>(row[kAnchorInput].toInt());
|
||||
if (a == kTopLeft || a == kTopCenter || a == kTopRight) {
|
||||
// Do nothing
|
||||
} else if (a == kMiddleLeft || a == kMiddleCenter || a == kMiddleRight) {
|
||||
y += res.y()/2;
|
||||
} else if (a == kBottomLeft || a == kBottomCenter || a == kBottomRight) {
|
||||
y += res.y();
|
||||
}
|
||||
if (a == kTopLeft || a == kMiddleLeft || a == kBottomLeft) {
|
||||
// Do nothing
|
||||
} else if (a == kTopCenter || a == kMiddleCenter || a == kBottomCenter) {
|
||||
x += res.x()/2;
|
||||
} else if (a == kTopRight || a == kMiddleRight || a == kBottomRight) {
|
||||
x += res.x();
|
||||
}
|
||||
Anchor a = static_cast<Anchor>(row[kAnchorInput].toInt());
|
||||
if (a == kTopLeft || a == kTopCenter || a == kTopRight) {
|
||||
// Do nothing
|
||||
} else if (a == kMiddleLeft || a == kMiddleCenter ||
|
||||
a == kMiddleRight) {
|
||||
y += res.y() / 2;
|
||||
} else if (a == kBottomLeft || a == kBottomCenter ||
|
||||
a == kBottomRight) {
|
||||
y += res.y();
|
||||
}
|
||||
if (a == kTopLeft || a == kMiddleLeft || a == kBottomLeft) {
|
||||
// Do nothing
|
||||
} else if (a == kTopCenter || a == kMiddleCenter ||
|
||||
a == kBottomCenter) {
|
||||
x += res.x() / 2;
|
||||
} else if (a == kTopRight || a == kMiddleRight || a == kBottomRight) {
|
||||
x += res.x();
|
||||
}
|
||||
|
||||
gizmo_->SetPoint(QPointF(x, y));
|
||||
}
|
||||
gizmo_->SetPoint(QPointF(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
void TileDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void TileDistortNode::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
|
||||
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,53 +24,56 @@
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TileDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TileDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TileDistortNode();
|
||||
TileDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TileDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(TileDistortNode)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kScaleInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kAnchorInput;
|
||||
static const QString kMirrorXInput;
|
||||
static const QString kMirrorYInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kScaleInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kAnchorInput;
|
||||
static const QString kMirrorXInput;
|
||||
static const QString kMirrorYInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
enum Anchor {
|
||||
kTopLeft,
|
||||
kTopCenter,
|
||||
kTopRight,
|
||||
kMiddleLeft,
|
||||
kMiddleCenter,
|
||||
kMiddleRight,
|
||||
kBottomLeft,
|
||||
kBottomCenter,
|
||||
kBottomRight
|
||||
};
|
||||
|
||||
PointGizmo *gizmo_;
|
||||
enum Anchor {
|
||||
kTopLeft,
|
||||
kTopCenter,
|
||||
kTopRight,
|
||||
kMiddleLeft,
|
||||
kMiddleCenter,
|
||||
kMiddleRight,
|
||||
kBottomLeft,
|
||||
kBottomCenter,
|
||||
kBottomRight
|
||||
};
|
||||
|
||||
PointGizmo *gizmo_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,428 +22,491 @@
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString TransformDistortNode::kParentInput = QStringLiteral("parent_in");
|
||||
const QString TransformDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString TransformDistortNode::kAutoscaleInput = QStringLiteral("autoscale_in");
|
||||
const QString TransformDistortNode::kInterpolationInput = QStringLiteral("interpolation_in");
|
||||
const QString TransformDistortNode::kAutoscaleInput =
|
||||
QStringLiteral("autoscale_in");
|
||||
const QString TransformDistortNode::kInterpolationInput =
|
||||
QStringLiteral("interpolation_in");
|
||||
|
||||
#define super MatrixGenerator
|
||||
|
||||
TransformDistortNode::TransformDistortNode()
|
||||
{
|
||||
AddInput(kParentInput, NodeValue::kMatrix);
|
||||
AddInput(kParentInput, NodeValue::kMatrix);
|
||||
|
||||
AddInput(kAutoscaleInput, NodeValue::kCombo, 0);
|
||||
AddInput(kAutoscaleInput, NodeValue::kCombo, 0);
|
||||
|
||||
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
|
||||
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
|
||||
|
||||
PrependInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
PrependInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
// Initiate gizmos
|
||||
rotation_gizmo_ = AddDraggableGizmo<ScreenGizmo>();
|
||||
rotation_gizmo_->AddInput(NodeInput(this, kRotationInput));
|
||||
rotation_gizmo_->SetDragValueBehavior(ScreenGizmo::kAbsolute);
|
||||
// Initiate gizmos
|
||||
rotation_gizmo_ = AddDraggableGizmo<ScreenGizmo>();
|
||||
rotation_gizmo_->AddInput(NodeInput(this, kRotationInput));
|
||||
rotation_gizmo_->SetDragValueBehavior(ScreenGizmo::kAbsolute);
|
||||
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>();
|
||||
poly_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
|
||||
poly_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>();
|
||||
poly_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
|
||||
poly_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
|
||||
|
||||
anchor_gizmo_ = AddDraggableGizmo<PointGizmo>();
|
||||
anchor_gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 0));
|
||||
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 1));
|
||||
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
|
||||
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
|
||||
anchor_gizmo_ = AddDraggableGizmo<PointGizmo>();
|
||||
anchor_gizmo_->SetShape(PointGizmo::kAnchorPoint);
|
||||
anchor_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 0));
|
||||
anchor_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 1));
|
||||
anchor_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
|
||||
anchor_gizmo_->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
|
||||
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>();
|
||||
point_gizmo_[i]->AddInput(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0));
|
||||
point_gizmo_[i]->AddInput(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1));
|
||||
point_gizmo_[i]->SetDragValueBehavior(PointGizmo::kAbsolute);
|
||||
}
|
||||
for (int i = 0; i < kGizmoScaleCount; i++) {
|
||||
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>();
|
||||
point_gizmo_[i]->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0));
|
||||
point_gizmo_[i]->AddInput(
|
||||
NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1));
|
||||
point_gizmo_[i]->SetDragValueBehavior(PointGizmo::kAbsolute);
|
||||
}
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
}
|
||||
|
||||
void TransformDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kParentInput, tr("Parent"));
|
||||
SetInputName(kAutoscaleInput, tr("Auto-Scale"));
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kInterpolationInput, tr("Interpolation"));
|
||||
SetInputName(kParentInput, tr("Parent"));
|
||||
SetInputName(kAutoscaleInput, tr("Auto-Scale"));
|
||||
SetInputName(kTextureInput, tr("Texture"));
|
||||
SetInputName(kInterpolationInput, tr("Interpolation"));
|
||||
|
||||
SetComboBoxStrings(kAutoscaleInput, {tr("None"), tr("Fit"), tr("Fill"), tr("Stretch")});
|
||||
SetComboBoxStrings(kInterpolationInput, {tr("Nearest Neighbor"), tr("Bilinear"), tr("Mipmapped Bilinear")});
|
||||
SetComboBoxStrings(kAutoscaleInput,
|
||||
{ tr("None"), tr("Fit"), tr("Fill"), tr("Stretch") });
|
||||
SetComboBoxStrings(kInterpolationInput,
|
||||
{ tr("Nearest Neighbor"), tr("Bilinear"),
|
||||
tr("Mipmapped Bilinear") });
|
||||
}
|
||||
|
||||
void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TransformDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// Generate matrix
|
||||
QMatrix4x4 generated_matrix = GenerateMatrix(value, false, false, false, value[kParentInput].toMatrix());
|
||||
// Generate matrix
|
||||
QMatrix4x4 generated_matrix = GenerateMatrix(
|
||||
value, false, false, false, value[kParentInput].toMatrix());
|
||||
|
||||
// Pop texture
|
||||
NodeValue texture_meta = value[kTextureInput];
|
||||
// Pop texture
|
||||
NodeValue texture_meta = value[kTextureInput];
|
||||
|
||||
TexturePtr job_to_push = nullptr;
|
||||
TexturePtr job_to_push = nullptr;
|
||||
|
||||
// If we have a texture, generate a matrix and make it happen
|
||||
if (TexturePtr texture = texture_meta.toTexture()) {
|
||||
// Adjust our matrix by the resolutions involved
|
||||
QMatrix4x4 real_matrix = GenerateAutoScaledMatrix(generated_matrix, value, globals, texture->params());
|
||||
// If we have a texture, generate a matrix and make it happen
|
||||
if (TexturePtr texture = texture_meta.toTexture()) {
|
||||
// Adjust our matrix by the resolutions involved
|
||||
QMatrix4x4 real_matrix = GenerateAutoScaledMatrix(
|
||||
generated_matrix, value, globals, texture->params());
|
||||
|
||||
if (!real_matrix.isIdentity()) {
|
||||
// The matrix will transform things
|
||||
ShaderJob job;
|
||||
job.Insert(QStringLiteral("ove_maintex"), texture_meta);
|
||||
job.Insert(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, real_matrix, this));
|
||||
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].toInt()));
|
||||
if (!real_matrix.isIdentity()) {
|
||||
// The matrix will transform things
|
||||
ShaderJob job;
|
||||
job.Insert(QStringLiteral("ove_maintex"), texture_meta);
|
||||
job.Insert(QStringLiteral("ove_mvpmat"),
|
||||
NodeValue(NodeValue::kMatrix, real_matrix, this));
|
||||
job.SetInterpolation(QStringLiteral("ove_maintex"),
|
||||
static_cast<Texture::Interpolation>(
|
||||
value[kInterpolationInput].toInt()));
|
||||
|
||||
// Use global resolution rather than texture resolution because this may result in a size change
|
||||
job_to_push = Texture::Job(globals.vparams(), job);
|
||||
}
|
||||
}
|
||||
// Use global resolution rather than texture resolution because this may result in a size change
|
||||
job_to_push = Texture::Job(globals.vparams(), job);
|
||||
}
|
||||
}
|
||||
|
||||
table->Push(NodeValue::kMatrix, QVariant::fromValue(generated_matrix), this);
|
||||
table->Push(NodeValue::kMatrix, QVariant::fromValue(generated_matrix),
|
||||
this);
|
||||
|
||||
if (!job_to_push) {
|
||||
// Re-push whatever value we received
|
||||
table->Push(texture_meta);
|
||||
} else {
|
||||
table->Push(NodeValue::kTexture, job_to_push, this);
|
||||
}
|
||||
if (!job_to_push) {
|
||||
// Re-push whatever value we received
|
||||
table->Push(texture_meta);
|
||||
} else {
|
||||
table->Push(NodeValue::kTexture, job_to_push, this);
|
||||
}
|
||||
}
|
||||
|
||||
ShaderCode TransformDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
ShaderCode
|
||||
TransformDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request);
|
||||
Q_UNUSED(request);
|
||||
|
||||
// Returns default frag and vert shader
|
||||
return ShaderCode();
|
||||
// Returns default frag and vert shader
|
||||
return ShaderCode();
|
||||
}
|
||||
|
||||
void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, double y, const rational &time)
|
||||
void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x,
|
||||
double y, const rational &time)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
|
||||
|
||||
if (gizmo == anchor_gizmo_) {
|
||||
if (gizmo == anchor_gizmo_) {
|
||||
gizmo_inverted_transform_ =
|
||||
GenerateMatrix(row, true, true, false, row[kParentInput].toMatrix())
|
||||
.toTransform()
|
||||
.inverted();
|
||||
|
||||
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, false, row[kParentInput].toMatrix()).toTransform().inverted();
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
// Dragging scale handle
|
||||
TexturePtr tex = row[kTextureInput].toTexture();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
gizmo_scale_uniform_ = row[kUniformScaleInput].toBool();
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() +
|
||||
gizmo->GetGlobals().nonsquare_resolution() / 2)
|
||||
.toPointF();
|
||||
|
||||
// Dragging scale handle
|
||||
TexturePtr tex = row[kTextureInput].toTexture();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
if (gizmo == point_gizmo_[kGizmoScaleTopLeft] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleTopRight] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleBottomLeft] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleBottomRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleBoth;
|
||||
} else if (gizmo == point_gizmo_[kGizmoScaleCenterLeft] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleXOnly;
|
||||
} else {
|
||||
gizmo_scale_axes_ = kGizmoScaleYOnly;
|
||||
}
|
||||
|
||||
gizmo_scale_uniform_ = row[kUniformScaleInput].toBool();
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().nonsquare_resolution()/2).toPointF();
|
||||
// Store texture size
|
||||
VideoParams texture_params = tex->params();
|
||||
QVector2D texture_sz(texture_params.square_pixel_width(),
|
||||
texture_params.height());
|
||||
gizmo_scale_anchor_ = row[kAnchorInput].toVec2() + texture_sz / 2;
|
||||
|
||||
if (gizmo == point_gizmo_[kGizmoScaleTopLeft] || gizmo == point_gizmo_[kGizmoScaleTopRight]
|
||||
|| gizmo == point_gizmo_[kGizmoScaleBottomLeft] || gizmo == point_gizmo_[kGizmoScaleBottomRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleBoth;
|
||||
} else if (gizmo == point_gizmo_[kGizmoScaleCenterLeft] || gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleXOnly;
|
||||
} else {
|
||||
gizmo_scale_axes_ = kGizmoScaleYOnly;
|
||||
}
|
||||
if (gizmo == point_gizmo_[kGizmoScaleTopRight] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleBottomRight] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
|
||||
// Right handles, flip X axis
|
||||
gizmo_scale_anchor_.setX(texture_sz.x() - gizmo_scale_anchor_.x());
|
||||
}
|
||||
|
||||
// Store texture size
|
||||
VideoParams texture_params = tex->params();
|
||||
QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height());
|
||||
gizmo_scale_anchor_ = row[kAnchorInput].toVec2() + texture_sz/2;
|
||||
if (gizmo == point_gizmo_[kGizmoScaleBottomLeft] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleBottomRight] ||
|
||||
gizmo == point_gizmo_[kGizmoScaleBottomCenter]) {
|
||||
// Bottom handles, flip Y axis
|
||||
gizmo_scale_anchor_.setY(texture_sz.y() - gizmo_scale_anchor_.y());
|
||||
}
|
||||
|
||||
if (gizmo == point_gizmo_[kGizmoScaleTopRight]
|
||||
|| gizmo == point_gizmo_[kGizmoScaleBottomRight]
|
||||
|| gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
|
||||
// Right handles, flip X axis
|
||||
gizmo_scale_anchor_.setX(texture_sz.x() - gizmo_scale_anchor_.x());
|
||||
}
|
||||
// Store current matrix
|
||||
gizmo_inverted_transform_ =
|
||||
GenerateMatrix(row, true, true, true, row[kParentInput].toMatrix())
|
||||
.toTransform()
|
||||
.inverted();
|
||||
|
||||
if (gizmo == point_gizmo_[kGizmoScaleBottomLeft]
|
||||
|| gizmo == point_gizmo_[kGizmoScaleBottomRight]
|
||||
|| gizmo == point_gizmo_[kGizmoScaleBottomCenter]) {
|
||||
// Bottom handles, flip Y axis
|
||||
gizmo_scale_anchor_.setY(texture_sz.y() - gizmo_scale_anchor_.y());
|
||||
}
|
||||
|
||||
// Store current matrix
|
||||
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, true, row[kParentInput].toMatrix()).toTransform().inverted();
|
||||
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().nonsquare_resolution()/2).toPointF();
|
||||
gizmo_start_angle_ = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
gizmo_last_angle_ = gizmo_start_angle_;
|
||||
gizmo_last_alt_angle_ = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
|
||||
gizmo_rotate_wrap_ = 0;
|
||||
gizmo_rotate_last_dir_ = kDirectionNone;
|
||||
|
||||
}
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() +
|
||||
gizmo->GetGlobals().nonsquare_resolution() / 2)
|
||||
.toPointF();
|
||||
gizmo_start_angle_ =
|
||||
std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
gizmo_last_angle_ = gizmo_start_angle_;
|
||||
gizmo_last_alt_angle_ =
|
||||
std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
|
||||
gizmo_rotate_wrap_ = 0;
|
||||
gizmo_rotate_last_dir_ = kDirectionNone;
|
||||
}
|
||||
}
|
||||
|
||||
void TransformDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void TransformDistortNode::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
|
||||
|
||||
if (gizmo == poly_gizmo_) {
|
||||
if (gizmo == poly_gizmo_) {
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
} else if (gizmo == anchor_gizmo_) {
|
||||
NodeInputDragger &x_anchor_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_anchor_drag = gizmo->GetDraggers()[1];
|
||||
NodeInputDragger &x_pos_drag = gizmo->GetDraggers()[2];
|
||||
NodeInputDragger &y_pos_drag = gizmo->GetDraggers()[3];
|
||||
|
||||
} else if (gizmo == anchor_gizmo_) {
|
||||
QPointF inverted_movement(gizmo_inverted_transform_.map(QPointF(x, y)));
|
||||
|
||||
NodeInputDragger &x_anchor_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_anchor_drag = gizmo->GetDraggers()[1];
|
||||
NodeInputDragger &x_pos_drag = gizmo->GetDraggers()[2];
|
||||
NodeInputDragger &y_pos_drag = gizmo->GetDraggers()[3];
|
||||
x_anchor_drag.Drag(x_anchor_drag.GetStartValue().toDouble() +
|
||||
inverted_movement.x());
|
||||
y_anchor_drag.Drag(y_anchor_drag.GetStartValue().toDouble() +
|
||||
inverted_movement.y());
|
||||
x_pos_drag.Drag(x_pos_drag.GetStartValue().toDouble() + x);
|
||||
y_pos_drag.Drag(y_pos_drag.GetStartValue().toDouble() + y);
|
||||
|
||||
QPointF inverted_movement(gizmo_inverted_transform_.map(QPointF(x, y)));
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
double raw_angle =
|
||||
std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
double alt_angle =
|
||||
std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
|
||||
|
||||
x_anchor_drag.Drag(x_anchor_drag.GetStartValue().toDouble() + inverted_movement.x());
|
||||
y_anchor_drag.Drag(y_anchor_drag.GetStartValue().toDouble() + inverted_movement.y());
|
||||
x_pos_drag.Drag(x_pos_drag.GetStartValue().toDouble() + x);
|
||||
y_pos_drag.Drag(y_pos_drag.GetStartValue().toDouble() + y);
|
||||
double current_angle = raw_angle;
|
||||
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
// Detect rotation wrap around
|
||||
RotationDirection this_dir =
|
||||
GetDirectionFromAngles(gizmo_last_angle_, raw_angle);
|
||||
RotationDirection alt_dir =
|
||||
GetDirectionFromAngles(gizmo_last_alt_angle_, alt_angle);
|
||||
|
||||
double raw_angle = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
double alt_angle = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
|
||||
if (gizmo_rotate_last_dir_ != kDirectionNone &&
|
||||
this_dir != gizmo_rotate_last_dir_) {
|
||||
if (alt_dir == gizmo_rotate_last_alt_dir_) {
|
||||
if ((raw_angle - gizmo_last_angle_) < 0) {
|
||||
gizmo_rotate_wrap_++;
|
||||
} else {
|
||||
gizmo_rotate_wrap_--;
|
||||
}
|
||||
|
||||
double current_angle = raw_angle;
|
||||
this_dir = gizmo_rotate_last_dir_;
|
||||
alt_dir = gizmo_rotate_last_alt_dir_;
|
||||
}
|
||||
}
|
||||
|
||||
// Detect rotation wrap around
|
||||
RotationDirection this_dir = GetDirectionFromAngles(gizmo_last_angle_, raw_angle);
|
||||
RotationDirection alt_dir = GetDirectionFromAngles(gizmo_last_alt_angle_, alt_angle);
|
||||
gizmo_rotate_last_dir_ = this_dir;
|
||||
gizmo_rotate_last_alt_dir_ = alt_dir;
|
||||
gizmo_last_angle_ = raw_angle;
|
||||
gizmo_last_alt_angle_ = alt_angle;
|
||||
|
||||
if (gizmo_rotate_last_dir_ != kDirectionNone && this_dir != gizmo_rotate_last_dir_) {
|
||||
if (alt_dir == gizmo_rotate_last_alt_dir_) {
|
||||
if ((raw_angle - gizmo_last_angle_) < 0) {
|
||||
gizmo_rotate_wrap_++;
|
||||
} else {
|
||||
gizmo_rotate_wrap_--;
|
||||
}
|
||||
current_angle += M_PI * 2 * gizmo_rotate_wrap_;
|
||||
|
||||
this_dir = gizmo_rotate_last_dir_;
|
||||
alt_dir = gizmo_rotate_last_alt_dir_;
|
||||
}
|
||||
}
|
||||
// Convert radians to degrees
|
||||
double rotation_difference =
|
||||
(current_angle - gizmo_start_angle_) * 57.2958;
|
||||
|
||||
gizmo_rotate_last_dir_ = this_dir;
|
||||
gizmo_rotate_last_alt_dir_ = alt_dir;
|
||||
gizmo_last_angle_ = raw_angle;
|
||||
gizmo_last_alt_angle_ = alt_angle;
|
||||
NodeInputDragger &d = gizmo->GetDraggers()[0];
|
||||
d.Drag(d.GetStartValue().toDouble() + rotation_difference);
|
||||
|
||||
current_angle += M_PI*2*gizmo_rotate_wrap_;
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
QPointF mouse_relative =
|
||||
gizmo_inverted_transform_.map(QPointF(x, y) - gizmo_anchor_pt_);
|
||||
|
||||
// Convert radians to degrees
|
||||
double rotation_difference = (current_angle - gizmo_start_angle_) * 57.2958;
|
||||
double x_scaled_movement =
|
||||
qAbs(mouse_relative.x() / gizmo_scale_anchor_.x());
|
||||
double y_scaled_movement =
|
||||
qAbs(mouse_relative.y() / gizmo_scale_anchor_.y());
|
||||
|
||||
NodeInputDragger &d = gizmo->GetDraggers()[0];
|
||||
d.Drag(d.GetStartValue().toDouble() + rotation_difference);
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
switch (gizmo_scale_axes_) {
|
||||
case kGizmoScaleXOnly:
|
||||
x_drag.Drag(x_scaled_movement);
|
||||
break;
|
||||
case kGizmoScaleYOnly:
|
||||
if (gizmo_scale_uniform_) {
|
||||
x_drag.Drag(y_scaled_movement);
|
||||
} else {
|
||||
y_drag.Drag(y_scaled_movement);
|
||||
}
|
||||
break;
|
||||
case kGizmoScaleBoth:
|
||||
if (gizmo_scale_uniform_) {
|
||||
double distance =
|
||||
std::hypot(mouse_relative.x(), mouse_relative.y());
|
||||
double texture_diag = std::hypot(gizmo_scale_anchor_.x(),
|
||||
gizmo_scale_anchor_.y());
|
||||
|
||||
QPointF mouse_relative = gizmo_inverted_transform_.map(QPointF(x, y) - gizmo_anchor_pt_);
|
||||
|
||||
double x_scaled_movement = qAbs(mouse_relative.x() / gizmo_scale_anchor_.x());
|
||||
double y_scaled_movement = qAbs(mouse_relative.y() / gizmo_scale_anchor_.y());
|
||||
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
|
||||
switch (gizmo_scale_axes_) {
|
||||
case kGizmoScaleXOnly:
|
||||
x_drag.Drag(x_scaled_movement);
|
||||
break;
|
||||
case kGizmoScaleYOnly:
|
||||
if (gizmo_scale_uniform_) {
|
||||
x_drag.Drag(y_scaled_movement);
|
||||
} else {
|
||||
y_drag.Drag(y_scaled_movement);
|
||||
}
|
||||
break;
|
||||
case kGizmoScaleBoth:
|
||||
if (gizmo_scale_uniform_) {
|
||||
double distance = std::hypot(mouse_relative.x(), mouse_relative.y());
|
||||
double texture_diag = std::hypot(gizmo_scale_anchor_.x(), gizmo_scale_anchor_.y());
|
||||
|
||||
x_drag.Drag(qAbs(distance / texture_diag));
|
||||
} else {
|
||||
x_drag.Drag(x_scaled_movement);
|
||||
y_drag.Drag(y_scaled_movement);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
x_drag.Drag(qAbs(distance / texture_diag));
|
||||
} else {
|
||||
x_drag.Drag(x_scaled_movement);
|
||||
y_drag.Drag(y_scaled_movement);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(const QMatrix4x4 &mat, const QVector2D &sequence_res, const QVector2D &texture_res, const QVector2D &offset, AutoScaleType autoscale_type)
|
||||
QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(
|
||||
const QMatrix4x4 &mat, const QVector2D &sequence_res,
|
||||
const QVector2D &texture_res, const QVector2D &offset,
|
||||
AutoScaleType autoscale_type)
|
||||
{
|
||||
// First, create an identity matrix
|
||||
QMatrix4x4 adjusted_matrix;
|
||||
// First, create an identity matrix
|
||||
QMatrix4x4 adjusted_matrix;
|
||||
|
||||
// Scale it to a square based on the sequence's resolution
|
||||
adjusted_matrix.scale(2.0 / sequence_res.x(), 2.0 / sequence_res.y(), 1.0);
|
||||
// Scale it to a square based on the sequence's resolution
|
||||
adjusted_matrix.scale(2.0 / sequence_res.x(), 2.0 / sequence_res.y(), 1.0);
|
||||
|
||||
// Apply offset if applicable
|
||||
adjusted_matrix.translate(offset.x(), offset.y());
|
||||
// Apply offset if applicable
|
||||
adjusted_matrix.translate(offset.x(), offset.y());
|
||||
|
||||
// Adjust by the matrix we generated earlier
|
||||
adjusted_matrix *= mat;
|
||||
// Adjust by the matrix we generated earlier
|
||||
adjusted_matrix *= mat;
|
||||
|
||||
// Scale back out to texture size (adjusted by pixel aspect)
|
||||
adjusted_matrix.scale(texture_res.x() * 0.5, texture_res.y() * 0.5, 1.0);
|
||||
// Scale back out to texture size (adjusted by pixel aspect)
|
||||
adjusted_matrix.scale(texture_res.x() * 0.5, texture_res.y() * 0.5, 1.0);
|
||||
|
||||
// If auto-scale is enabled, fit the texture to the sequence (without cropping)
|
||||
if (autoscale_type != kAutoScaleNone) {
|
||||
if (autoscale_type == kAutoScaleStretch) {
|
||||
adjusted_matrix.scale(sequence_res.x() / texture_res.x(),
|
||||
sequence_res.y() / texture_res.y(),
|
||||
1.0);
|
||||
} else {
|
||||
double footage_real_ar = texture_res.x() / texture_res.y();
|
||||
double sequence_real_ar = sequence_res.x() / sequence_res.y();
|
||||
// If auto-scale is enabled, fit the texture to the sequence (without cropping)
|
||||
if (autoscale_type != kAutoScaleNone) {
|
||||
if (autoscale_type == kAutoScaleStretch) {
|
||||
adjusted_matrix.scale(sequence_res.x() / texture_res.x(),
|
||||
sequence_res.y() / texture_res.y(), 1.0);
|
||||
} else {
|
||||
double footage_real_ar = texture_res.x() / texture_res.y();
|
||||
double sequence_real_ar = sequence_res.x() / sequence_res.y();
|
||||
|
||||
double scale_by_x = sequence_res.x() / texture_res.x();
|
||||
double scale_by_y = sequence_res.y() / texture_res.y();
|
||||
double autoscale_val;
|
||||
double scale_by_x = sequence_res.x() / texture_res.x();
|
||||
double scale_by_y = sequence_res.y() / texture_res.y();
|
||||
double autoscale_val;
|
||||
|
||||
if ((autoscale_type == kAutoScaleFit) == (sequence_real_ar > footage_real_ar)) {
|
||||
// Scale by height. Either the sequence is wider than the footage or we're using fill and
|
||||
// cutting off the sides
|
||||
autoscale_val = scale_by_y;
|
||||
} else {
|
||||
// Scale by width. Either the footage is wider than the sequence or we're using fill and
|
||||
// cutting off the top and bottom
|
||||
autoscale_val = scale_by_x;
|
||||
}
|
||||
if ((autoscale_type == kAutoScaleFit) ==
|
||||
(sequence_real_ar > footage_real_ar)) {
|
||||
// Scale by height. Either the sequence is wider than the footage or we're using fill and
|
||||
// cutting off the sides
|
||||
autoscale_val = scale_by_y;
|
||||
} else {
|
||||
// Scale by width. Either the footage is wider than the sequence or we're using fill and
|
||||
// cutting off the top and bottom
|
||||
autoscale_val = scale_by_x;
|
||||
}
|
||||
|
||||
adjusted_matrix.scale(autoscale_val, autoscale_val, 1.0);
|
||||
}
|
||||
}
|
||||
adjusted_matrix.scale(autoscale_val, autoscale_val, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return adjusted_matrix;
|
||||
return adjusted_matrix;
|
||||
}
|
||||
|
||||
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
TexturePtr tex = row[kTextureInput].toTexture();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
TexturePtr tex = row[kTextureInput].toTexture();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the sequence resolution
|
||||
const QVector2D &sequence_res = globals.nonsquare_resolution();
|
||||
QVector2D sequence_half_res = sequence_res * 0.5;
|
||||
QPointF sequence_half_res_pt = sequence_half_res.toPointF();
|
||||
// Get the sequence resolution
|
||||
const QVector2D &sequence_res = globals.nonsquare_resolution();
|
||||
QVector2D sequence_half_res = sequence_res * 0.5;
|
||||
QPointF sequence_half_res_pt = sequence_half_res.toPointF();
|
||||
|
||||
// GizmoTraverser just returns the sizes of the textures and no other data
|
||||
VideoParams tex_params = tex->params();
|
||||
QVector2D tex_sz(tex_params.square_pixel_width(), tex_params.height());
|
||||
QVector2D tex_offset = tex_params.offset();
|
||||
// GizmoTraverser just returns the sizes of the textures and no other data
|
||||
VideoParams tex_params = tex->params();
|
||||
QVector2D tex_sz(tex_params.square_pixel_width(), tex_params.height());
|
||||
QVector2D tex_offset = tex_params.offset();
|
||||
|
||||
// Retrieve autoscale value
|
||||
AutoScaleType autoscale = static_cast<AutoScaleType>(row[kAutoscaleInput].toInt());
|
||||
// Retrieve autoscale value
|
||||
AutoScaleType autoscale =
|
||||
static_cast<AutoScaleType>(row[kAutoscaleInput].toInt());
|
||||
|
||||
// Fold values into a matrix for the rectangle
|
||||
QMatrix4x4 rectangle_matrix;
|
||||
rectangle_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
|
||||
rectangle_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix()),
|
||||
sequence_res,
|
||||
tex_sz,
|
||||
tex_offset,
|
||||
autoscale);
|
||||
// Fold values into a matrix for the rectangle
|
||||
QMatrix4x4 rectangle_matrix;
|
||||
rectangle_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
|
||||
rectangle_matrix *= AdjustMatrixByResolutions(
|
||||
GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix()),
|
||||
sequence_res, tex_sz, tex_offset, autoscale);
|
||||
|
||||
// Create rect and transform it
|
||||
const QVector<QPointF> points = {QPointF(-1, -1),
|
||||
QPointF(1, -1),
|
||||
QPointF(1, 1),
|
||||
QPointF(-1, 1),
|
||||
QPointF(-1, -1)};
|
||||
QTransform rectangle_transform = rectangle_matrix.toTransform();
|
||||
QPolygonF r = rectangle_transform.map(points);
|
||||
r.translate(sequence_half_res_pt);
|
||||
poly_gizmo_->SetPolygon(r);
|
||||
// Create rect and transform it
|
||||
const QVector<QPointF> points = { QPointF(-1, -1), QPointF(1, -1),
|
||||
QPointF(1, 1), QPointF(-1, 1),
|
||||
QPointF(-1, -1) };
|
||||
QTransform rectangle_transform = rectangle_matrix.toTransform();
|
||||
QPolygonF r = rectangle_transform.map(points);
|
||||
r.translate(sequence_half_res_pt);
|
||||
poly_gizmo_->SetPolygon(r);
|
||||
|
||||
// Draw anchor point
|
||||
QMatrix4x4 anchor_matrix;
|
||||
anchor_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
|
||||
anchor_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, true, false, false, row[kParentInput].toMatrix()),
|
||||
sequence_res,
|
||||
tex_sz,
|
||||
tex_offset,
|
||||
autoscale);
|
||||
anchor_gizmo_->SetPoint(anchor_matrix.toTransform().map(QPointF(0, 0)) + sequence_half_res_pt);
|
||||
// Draw anchor point
|
||||
QMatrix4x4 anchor_matrix;
|
||||
anchor_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
|
||||
anchor_matrix *= AdjustMatrixByResolutions(
|
||||
GenerateMatrix(row, true, false, false, row[kParentInput].toMatrix()),
|
||||
sequence_res, tex_sz, tex_offset, autoscale);
|
||||
anchor_gizmo_->SetPoint(anchor_matrix.toTransform().map(QPointF(0, 0)) +
|
||||
sequence_half_res_pt);
|
||||
|
||||
// Draw scale handles
|
||||
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(CreateScalePoint(-1, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(CreateScalePoint( 0, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleTopRight]->SetPoint(CreateScalePoint( 1, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(CreateScalePoint(-1, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(CreateScalePoint( 0, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(CreateScalePoint( 1, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(CreateScalePoint(-1, 0, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(CreateScalePoint( 1, 0, sequence_half_res_pt, rectangle_matrix));
|
||||
// Draw scale handles
|
||||
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(
|
||||
CreateScalePoint(-1, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(
|
||||
CreateScalePoint(0, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleTopRight]->SetPoint(
|
||||
CreateScalePoint(1, -1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(
|
||||
CreateScalePoint(-1, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
|
||||
CreateScalePoint(0, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
|
||||
CreateScalePoint(1, 1, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
|
||||
CreateScalePoint(-1, 0, sequence_half_res_pt, rectangle_matrix));
|
||||
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
|
||||
CreateScalePoint(1, 0, sequence_half_res_pt, rectangle_matrix));
|
||||
|
||||
// Use offsets to make the appearance of values that start in the top left, even though we
|
||||
// really anchor around the center
|
||||
SetInputProperty(kPositionInput, QStringLiteral("offset"), sequence_half_res + tex_offset);
|
||||
SetInputProperty(kAnchorInput, QStringLiteral("offset"), tex_sz * 0.5);
|
||||
// Use offsets to make the appearance of values that start in the top left, even though we
|
||||
// really anchor around the center
|
||||
SetInputProperty(kPositionInput, QStringLiteral("offset"),
|
||||
sequence_half_res + tex_offset);
|
||||
SetInputProperty(kAnchorInput, QStringLiteral("offset"), tex_sz * 0.5);
|
||||
}
|
||||
|
||||
QTransform TransformDistortNode::GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const
|
||||
QTransform
|
||||
TransformDistortNode::GizmoTransformation(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) const
|
||||
{
|
||||
if (TexturePtr texture = row[kTextureInput].toTexture()) {
|
||||
//auto m = GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix());
|
||||
auto m = GenerateMatrix(row, false, false, false, QMatrix4x4());
|
||||
return GenerateAutoScaledMatrix(m, row, globals, texture->params()).toTransform();
|
||||
}
|
||||
return super::GizmoTransformation(row, globals);
|
||||
if (TexturePtr texture = row[kTextureInput].toTexture()) {
|
||||
//auto m = GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix());
|
||||
auto m = GenerateMatrix(row, false, false, false, QMatrix4x4());
|
||||
return GenerateAutoScaledMatrix(m, row, globals, texture->params())
|
||||
.toTransform();
|
||||
}
|
||||
return super::GizmoTransformation(row, globals);
|
||||
}
|
||||
|
||||
QPointF TransformDistortNode::CreateScalePoint(double x, double y, const QPointF &half_res, const QMatrix4x4 &mat)
|
||||
QPointF TransformDistortNode::CreateScalePoint(double x, double y,
|
||||
const QPointF &half_res,
|
||||
const QMatrix4x4 &mat)
|
||||
{
|
||||
return mat.map(QPointF(x, y)) + half_res;
|
||||
return mat.map(QPointF(x, y)) + half_res;
|
||||
}
|
||||
|
||||
QMatrix4x4 TransformDistortNode::GenerateAutoScaledMatrix(const QMatrix4x4& generated_matrix, const NodeValueRow& value, const NodeGlobals &globals, const VideoParams& texture_params) const
|
||||
QMatrix4x4 TransformDistortNode::GenerateAutoScaledMatrix(
|
||||
const QMatrix4x4 &generated_matrix, const NodeValueRow &value,
|
||||
const NodeGlobals &globals, const VideoParams &texture_params) const
|
||||
{
|
||||
const QVector2D &sequence_res = globals.nonsquare_resolution();
|
||||
QVector2D texture_res(texture_params.square_pixel_width(), texture_params.height());
|
||||
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].toInt());
|
||||
const QVector2D &sequence_res = globals.nonsquare_resolution();
|
||||
QVector2D texture_res(texture_params.square_pixel_width(),
|
||||
texture_params.height());
|
||||
AutoScaleType autoscale =
|
||||
static_cast<AutoScaleType>(value[kAutoscaleInput].toInt());
|
||||
|
||||
return AdjustMatrixByResolutions(generated_matrix,
|
||||
sequence_res,
|
||||
texture_res,
|
||||
texture_params.offset(),
|
||||
autoscale);
|
||||
return AdjustMatrixByResolutions(generated_matrix, sequence_res,
|
||||
texture_res, texture_params.offset(),
|
||||
autoscale);
|
||||
}
|
||||
|
||||
bool TransformDistortNode::IsAScaleGizmo(NodeGizmo *g) const
|
||||
{
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
if (point_gizmo_[i] == g) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < kGizmoScaleCount; i++) {
|
||||
if (point_gizmo_[i] == g) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
TransformDistortNode::RotationDirection TransformDistortNode::GetDirectionFromAngles(double last, double current)
|
||||
TransformDistortNode::RotationDirection
|
||||
TransformDistortNode::GetDirectionFromAngles(double last, double current)
|
||||
{
|
||||
return (current > last) ? kDirectionPositive : kDirectionNegative;
|
||||
return (current > last) ? kDirectionPositive : kDirectionNegative;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,115 +26,122 @@
|
||||
#include "node/gizmo/polygon.h"
|
||||
#include "node/gizmo/screen.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TransformDistortNode : public MatrixGenerator
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TransformDistortNode : public MatrixGenerator {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TransformDistortNode();
|
||||
TransformDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TransformDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(TransformDistortNode)
|
||||
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Transform");
|
||||
}
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Transform");
|
||||
}
|
||||
|
||||
virtual QString ShortName() const override
|
||||
{
|
||||
// Override MatrixGenerator's short name "Ortho"
|
||||
return Name();
|
||||
}
|
||||
virtual QString ShortName() const override
|
||||
{
|
||||
// Override MatrixGenerator's short name "Ortho"
|
||||
return Name();
|
||||
}
|
||||
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.transform");
|
||||
}
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.transform");
|
||||
}
|
||||
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
}
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Transform an image in 2D space. Equivalent to multiplying by an orthographic matrix.");
|
||||
}
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr(
|
||||
"Transform an image in 2D space. Equivalent to multiplying by an orthographic matrix.");
|
||||
}
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
|
||||
enum AutoScaleType {
|
||||
kAutoScaleNone,
|
||||
kAutoScaleFit,
|
||||
kAutoScaleFill,
|
||||
kAutoScaleStretch
|
||||
};
|
||||
enum AutoScaleType {
|
||||
kAutoScaleNone,
|
||||
kAutoScaleFit,
|
||||
kAutoScaleFill,
|
||||
kAutoScaleStretch
|
||||
};
|
||||
|
||||
static QMatrix4x4 AdjustMatrixByResolutions(const QMatrix4x4& mat,
|
||||
const QVector2D& sequence_res,
|
||||
const QVector2D& texture_res,
|
||||
const QVector2D& offset,
|
||||
AutoScaleType autoscale_type = kAutoScaleNone);
|
||||
static QMatrix4x4 AdjustMatrixByResolutions(
|
||||
const QMatrix4x4 &mat, const QVector2D &sequence_res,
|
||||
const QVector2D &texture_res, const QVector2D &offset,
|
||||
AutoScaleType autoscale_type = kAutoScaleNone);
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual QTransform GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
virtual QTransform
|
||||
GizmoTransformation(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) const override;
|
||||
|
||||
static const QString kParentInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kAutoscaleInput;
|
||||
static const QString kInterpolationInput;
|
||||
static const QString kParentInput;
|
||||
static const QString kTextureInput;
|
||||
static const QString kAutoscaleInput;
|
||||
static const QString kInterpolationInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time) override;
|
||||
virtual void GizmoDragStart(const olive::NodeValueRow &row, double x,
|
||||
double y, const olive::rational &time) override;
|
||||
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
static QPointF CreateScalePoint(double x, double y, const QPointF& half_res, const QMatrix4x4& mat);
|
||||
static QPointF CreateScalePoint(double x, double y, const QPointF &half_res,
|
||||
const QMatrix4x4 &mat);
|
||||
|
||||
QMatrix4x4 GenerateAutoScaledMatrix(const QMatrix4x4 &generated_matrix, const NodeValueRow &db, const NodeGlobals &globals, const VideoParams &texture_params) const;
|
||||
QMatrix4x4
|
||||
GenerateAutoScaledMatrix(const QMatrix4x4 &generated_matrix,
|
||||
const NodeValueRow &db, const NodeGlobals &globals,
|
||||
const VideoParams &texture_params) const;
|
||||
|
||||
bool IsAScaleGizmo(NodeGizmo *g) const;
|
||||
bool IsAScaleGizmo(NodeGizmo *g) const;
|
||||
|
||||
// Gizmo variables
|
||||
double gizmo_start_angle_;
|
||||
QTransform gizmo_inverted_transform_;
|
||||
QPointF gizmo_anchor_pt_;
|
||||
bool gizmo_scale_uniform_;
|
||||
double gizmo_last_angle_;
|
||||
double gizmo_last_alt_angle_;
|
||||
int gizmo_rotate_wrap_;
|
||||
// Gizmo variables
|
||||
double gizmo_start_angle_;
|
||||
QTransform gizmo_inverted_transform_;
|
||||
QPointF gizmo_anchor_pt_;
|
||||
bool gizmo_scale_uniform_;
|
||||
double gizmo_last_angle_;
|
||||
double gizmo_last_alt_angle_;
|
||||
int gizmo_rotate_wrap_;
|
||||
|
||||
enum RotationDirection {
|
||||
kDirectionNone,
|
||||
kDirectionPositive, // Clockwise
|
||||
kDirectionNegative // Counter-clockwise
|
||||
};
|
||||
enum RotationDirection {
|
||||
kDirectionNone,
|
||||
kDirectionPositive, // Clockwise
|
||||
kDirectionNegative // Counter-clockwise
|
||||
};
|
||||
|
||||
static RotationDirection GetDirectionFromAngles(double last, double current);
|
||||
RotationDirection gizmo_rotate_last_dir_;
|
||||
RotationDirection gizmo_rotate_last_alt_dir_;
|
||||
static RotationDirection GetDirectionFromAngles(double last,
|
||||
double current);
|
||||
RotationDirection gizmo_rotate_last_dir_;
|
||||
RotationDirection gizmo_rotate_last_alt_dir_;
|
||||
|
||||
enum GizmoScaleType {
|
||||
kGizmoScaleXOnly,
|
||||
kGizmoScaleYOnly,
|
||||
kGizmoScaleBoth
|
||||
};
|
||||
enum GizmoScaleType { kGizmoScaleXOnly, kGizmoScaleYOnly, kGizmoScaleBoth };
|
||||
|
||||
GizmoScaleType gizmo_scale_axes_;
|
||||
QVector2D gizmo_scale_anchor_;
|
||||
|
||||
// Gizmo on screen object storage
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PointGizmo *anchor_gizmo_;
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
ScreenGizmo *rotation_gizmo_;
|
||||
GizmoScaleType gizmo_scale_axes_;
|
||||
QVector2D gizmo_scale_anchor_;
|
||||
|
||||
// Gizmo on screen object storage
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PointGizmo *anchor_gizmo_;
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
ScreenGizmo *rotation_gizmo_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include "wavedistortnode.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
const QString WaveDistortNode::kTextureInput = QStringLiteral("tex_in");
|
||||
const QString WaveDistortNode::kFrequencyInput = QStringLiteral("frequency_in");
|
||||
@@ -32,69 +33,73 @@ const QString WaveDistortNode::kVerticalInput = QStringLiteral("vertical_in");
|
||||
|
||||
WaveDistortNode::WaveDistortNode()
|
||||
{
|
||||
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
AddInput(kTextureInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
AddInput(kFrequencyInput, NodeValue::kFloat, 10);
|
||||
AddInput(kIntensityInput, NodeValue::kFloat, 10);
|
||||
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
|
||||
AddInput(kFrequencyInput, NodeValue::kFloat, 10);
|
||||
AddInput(kIntensityInput, NodeValue::kFloat, 10);
|
||||
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
|
||||
|
||||
AddInput(kVerticalInput, NodeValue::kCombo, false);
|
||||
AddInput(kVerticalInput, NodeValue::kCombo, false);
|
||||
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
SetFlag(kVideoEffect);
|
||||
SetEffectInput(kTextureInput);
|
||||
}
|
||||
|
||||
QString WaveDistortNode::Name() const
|
||||
{
|
||||
return tr("Wave");
|
||||
return tr("Wave");
|
||||
}
|
||||
|
||||
QString WaveDistortNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.oliveeditor.Olive.wave");
|
||||
return QStringLiteral("org.oliveeditor.Olive.wave");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> WaveDistortNode::Category() const
|
||||
{
|
||||
return {kCategoryDistort};
|
||||
return { kCategoryDistort };
|
||||
}
|
||||
|
||||
QString WaveDistortNode::Description() const
|
||||
{
|
||||
return tr("Distorts an image along a sine wave.");
|
||||
return tr("Distorts an image along a sine wave.");
|
||||
}
|
||||
|
||||
void WaveDistortNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kFrequencyInput, tr("Frequency"));
|
||||
SetInputName(kIntensityInput, tr("Intensity"));
|
||||
SetInputName(kEvolutionInput, tr("Evolution"));
|
||||
SetInputName(kVerticalInput, tr("Direction"));
|
||||
SetComboBoxStrings(kVerticalInput, {tr("Horizontal"), tr("Vertical")});
|
||||
SetInputName(kTextureInput, tr("Input"));
|
||||
SetInputName(kFrequencyInput, tr("Frequency"));
|
||||
SetInputName(kIntensityInput, tr("Intensity"));
|
||||
SetInputName(kEvolutionInput, tr("Evolution"));
|
||||
SetInputName(kVerticalInput, tr("Direction"));
|
||||
SetComboBoxStrings(kVerticalInput, { tr("Horizontal"), tr("Vertical") });
|
||||
}
|
||||
|
||||
ShaderCode WaveDistortNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/wave.frag"));
|
||||
Q_UNUSED(request)
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/wave.frag"));
|
||||
}
|
||||
|
||||
void WaveDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void WaveDistortNode::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr texture = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kIntensityInput].toDouble())) {
|
||||
table->Push(NodeValue::kTexture, Texture::Job(texture->params(), ShaderJob(value)), this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no texture, no need to run an operation
|
||||
if (TexturePtr texture = value[kTextureInput].toTexture()) {
|
||||
// Only run shader if at least one of flip or flop are selected
|
||||
if (!qIsNull(value[kIntensityInput].toDouble())) {
|
||||
table->Push(NodeValue::kTexture,
|
||||
Texture::Job(texture->params(), ShaderJob(value)),
|
||||
this);
|
||||
} else {
|
||||
// If we're not flipping or flopping just push the texture
|
||||
table->Push(value[kTextureInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,32 +23,33 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class WaveDistortNode : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class WaveDistortNode : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
WaveDistortNode();
|
||||
WaveDistortNode();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(WaveDistortNode)
|
||||
NODE_DEFAULT_FUNCTIONS(WaveDistortNode)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kFrequencyInput;
|
||||
static const QString kIntensityInput;
|
||||
static const QString kEvolutionInput;
|
||||
static const QString kVerticalInput;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kFrequencyInput;
|
||||
static const QString kIntensityInput;
|
||||
static const QString kEvolutionInput;
|
||||
static const QString kVerticalInput;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user