change: change code style to Linux style except indent.
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
|
||||
#include "node/math/merge/merge.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super Node
|
||||
|
||||
@@ -30,42 +31,47 @@ const QString GeneratorWithMerge::kBaseInput = QStringLiteral("base_in");
|
||||
|
||||
GeneratorWithMerge::GeneratorWithMerge()
|
||||
{
|
||||
AddInput(kBaseInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
SetEffectInput(kBaseInput);
|
||||
SetFlag(kVideoEffect);
|
||||
AddInput(kBaseInput, NodeValue::kTexture,
|
||||
InputFlags(kInputFlagNotKeyframable));
|
||||
SetEffectInput(kBaseInput);
|
||||
SetFlag(kVideoEffect);
|
||||
}
|
||||
|
||||
void GeneratorWithMerge::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kBaseInput, tr("Base"));
|
||||
SetInputName(kBaseInput, tr("Base"));
|
||||
}
|
||||
|
||||
ShaderCode GeneratorWithMerge::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
if (request.id == QStringLiteral("mrg")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
|
||||
}
|
||||
if (request.id == QStringLiteral("mrg")) {
|
||||
return ShaderCode(
|
||||
FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
|
||||
}
|
||||
|
||||
return ShaderCode();
|
||||
return ShaderCode();
|
||||
}
|
||||
|
||||
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const
|
||||
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value,
|
||||
TexturePtr job,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
if (TexturePtr base = value[kBaseInput].toTexture()) {
|
||||
// Push as merge node
|
||||
ShaderJob merge;
|
||||
if (TexturePtr base = value[kBaseInput].toTexture()) {
|
||||
// Push as merge node
|
||||
ShaderJob merge;
|
||||
|
||||
merge.SetShaderID(QStringLiteral("mrg"));
|
||||
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
|
||||
merge.Insert(MergeNode::kBlendIn, NodeValue(NodeValue::kTexture, job, this));
|
||||
merge.SetShaderID(QStringLiteral("mrg"));
|
||||
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
|
||||
merge.Insert(MergeNode::kBlendIn,
|
||||
NodeValue(NodeValue::kTexture, job, this));
|
||||
|
||||
table->Push(NodeValue::kTexture, base->toJob(merge), this);
|
||||
} else {
|
||||
// Just push generate job
|
||||
table->Push(NodeValue::kTexture, job, this);
|
||||
}
|
||||
table->Push(NodeValue::kTexture, base->toJob(merge), this);
|
||||
} else {
|
||||
// Just push generate job
|
||||
table->Push(NodeValue::kTexture, job, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,23 +23,24 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class GeneratorWithMerge : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class GeneratorWithMerge : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GeneratorWithMerge();
|
||||
GeneratorWithMerge();
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
|
||||
virtual ShaderCode
|
||||
GetShaderCode(const ShaderRequest &request) const override;
|
||||
|
||||
static const QString kBaseInput;
|
||||
static const QString kBaseInput;
|
||||
|
||||
protected:
|
||||
void PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const;
|
||||
|
||||
void PushMergableJob(const NodeValueRow &value, TexturePtr job,
|
||||
NodeValueTable *table) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include "shapenode.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super ShapeNodeBase
|
||||
|
||||
@@ -29,70 +30,81 @@ QString ShapeNode::kRadiusInput = QStringLiteral("radius_in");
|
||||
|
||||
ShapeNode::ShapeNode()
|
||||
{
|
||||
PrependInput(kTypeInput, NodeValue::kCombo);
|
||||
PrependInput(kTypeInput, NodeValue::kCombo);
|
||||
|
||||
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
|
||||
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
|
||||
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
|
||||
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
|
||||
}
|
||||
|
||||
QString ShapeNode::Name() const
|
||||
{
|
||||
return tr("Shape");
|
||||
return tr("Shape");
|
||||
}
|
||||
|
||||
QString ShapeNode::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.shape");
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.shape");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> ShapeNode::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
return { kCategoryGenerator };
|
||||
}
|
||||
|
||||
QString ShapeNode::Description() const
|
||||
{
|
||||
return tr("Generate a 2D primitive shape.");
|
||||
return tr("Generate a 2D primitive shape.");
|
||||
}
|
||||
|
||||
void ShapeNode::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTypeInput, tr("Type"));
|
||||
SetInputName(kRadiusInput, tr("Radius"));
|
||||
SetInputName(kTypeInput, tr("Type"));
|
||||
SetInputName(kRadiusInput, tr("Radius"));
|
||||
|
||||
// Coordinate with Type enum
|
||||
SetComboBoxStrings(kTypeInput, {tr("Rectangle"), tr("Ellipse"), tr("Rounded Rectangle")});
|
||||
// Coordinate with Type enum
|
||||
SetComboBoxStrings(kTypeInput, { tr("Rectangle"), tr("Ellipse"),
|
||||
tr("Rounded Rectangle") });
|
||||
}
|
||||
|
||||
ShaderCode ShapeNode::GetShaderCode(const ShaderRequest &request) const
|
||||
{
|
||||
if (request.id == QStringLiteral("shape")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/shape.frag")));
|
||||
} else {
|
||||
return super::GetShaderCode(request);
|
||||
}
|
||||
if (request.id == QStringLiteral("shape")) {
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(
|
||||
QStringLiteral(":/shaders/shape.frag")));
|
||||
} else {
|
||||
return super::GetShaderCode(request);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
TexturePtr base = value[kBaseInput].toTexture();
|
||||
TexturePtr base = value[kBaseInput].toTexture();
|
||||
|
||||
ShaderJob job(value);
|
||||
ShaderJob job(value);
|
||||
|
||||
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, base ? base->virtual_resolution() : globals.square_resolution(), this));
|
||||
job.SetShaderID(QStringLiteral("shape"));
|
||||
job.Insert(QStringLiteral("resolution_in"),
|
||||
NodeValue(NodeValue::kVec2,
|
||||
base ? base->virtual_resolution() :
|
||||
globals.square_resolution(),
|
||||
this));
|
||||
job.SetShaderID(QStringLiteral("shape"));
|
||||
|
||||
PushMergableJob(value, Texture::Job(base ? base->params() : globals.vparams(), job), table);
|
||||
PushMergableJob(
|
||||
value, Texture::Job(base ? base->params() : globals.vparams(), job),
|
||||
table);
|
||||
}
|
||||
|
||||
void ShapeNode::InputValueChangedEvent(const QString &input, int element)
|
||||
{
|
||||
if (input == kTypeInput) {
|
||||
SetInputFlag(kRadiusInput, kInputFlagHidden, (GetStandardValue(kTypeInput).toInt() != kRoundedRectangle));
|
||||
}
|
||||
super::InputValueChangedEvent(input, element);
|
||||
if (input == kTypeInput) {
|
||||
SetInputFlag(kRadiusInput, kInputFlagHidden,
|
||||
(GetStandardValue(kTypeInput).toInt() !=
|
||||
kRoundedRectangle));
|
||||
}
|
||||
super::InputValueChangedEvent(input, element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,38 +23,36 @@
|
||||
|
||||
#include "shapenodebase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ShapeNode : public ShapeNodeBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ShapeNode : public ShapeNodeBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShapeNode();
|
||||
ShapeNode();
|
||||
|
||||
enum Type {
|
||||
kRectangle,
|
||||
kEllipse,
|
||||
kRoundedRectangle
|
||||
};
|
||||
enum Type { kRectangle, kEllipse, kRoundedRectangle };
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(ShapeNode)
|
||||
NODE_DEFAULT_FUNCTIONS(ShapeNode)
|
||||
|
||||
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;
|
||||
|
||||
static QString kTypeInput;
|
||||
static QString kRadiusInput;
|
||||
static QString kTypeInput;
|
||||
static QString kRadiusInput;
|
||||
|
||||
protected:
|
||||
virtual void InputValueChangedEvent(const QString &input, int element) override;
|
||||
|
||||
virtual void InputValueChangedEvent(const QString &input,
|
||||
int element) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "core.h"
|
||||
#include "node/nodeundo.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super GeneratorWithMerge
|
||||
|
||||
@@ -37,287 +38,324 @@ const QString ShapeNodeBase::kColorInput = QStringLiteral("color_in");
|
||||
|
||||
ShapeNodeBase::ShapeNodeBase(bool create_color_input)
|
||||
{
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
|
||||
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
|
||||
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
|
||||
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
|
||||
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
|
||||
|
||||
if (create_color_input) {
|
||||
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
|
||||
}
|
||||
if (create_color_input) {
|
||||
AddInput(kColorInput, NodeValue::kColor,
|
||||
QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
|
||||
}
|
||||
|
||||
// Initiate gizmos
|
||||
QVector<NodeKeyframeTrackReference> pos_n_sz = {
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
|
||||
};
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
|
||||
}
|
||||
// Initiate gizmos
|
||||
QVector<NodeKeyframeTrackReference> pos_n_sz = {
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
|
||||
};
|
||||
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
|
||||
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
|
||||
});
|
||||
for (int i = 0; i < kGizmoScaleCount; i++) {
|
||||
point_gizmo_[i] =
|
||||
AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNodeBase::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kSizeInput, tr("Size"));
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kSizeInput, tr("Size"));
|
||||
|
||||
if (HasInputWithID(kColorInput)) {
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
}
|
||||
if (HasInputWithID(kColorInput)) {
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
// Use offsets to make the appearance of values that start in the top left, even though we
|
||||
// really anchor around the center
|
||||
QVector2D center_pt = globals.square_resolution() * 0.5;
|
||||
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
|
||||
// Use offsets to make the appearance of values that start in the top left, even though we
|
||||
// really anchor around the center
|
||||
QVector2D center_pt = globals.square_resolution() * 0.5;
|
||||
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
|
||||
|
||||
QVector2D pos = row[kPositionInput].toVec2();
|
||||
QVector2D sz = row[kSizeInput].toVec2();
|
||||
QVector2D half_sz = sz * 0.5;
|
||||
QVector2D pos = row[kPositionInput].toVec2();
|
||||
QVector2D sz = row[kSizeInput].toVec2();
|
||||
QVector2D half_sz = sz * 0.5;
|
||||
|
||||
double left_pt = pos.x() + center_pt.x() - half_sz.x();
|
||||
double top_pt = pos.y() + center_pt.y() - half_sz.y();
|
||||
double right_pt = left_pt + sz.x();
|
||||
double bottom_pt = top_pt + sz.y();
|
||||
double center_x_pt = mid(left_pt, right_pt);
|
||||
double center_y_pt = mid(top_pt, bottom_pt);
|
||||
double left_pt = pos.x() + center_pt.x() - half_sz.x();
|
||||
double top_pt = pos.y() + center_pt.y() - half_sz.y();
|
||||
double right_pt = left_pt + sz.x();
|
||||
double bottom_pt = top_pt + sz.y();
|
||||
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 ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command)
|
||||
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res,
|
||||
MultiUndoCommand *command)
|
||||
{
|
||||
// Normalize around center of sequence
|
||||
rect.translate(-sequence_res.width()*0.5, -sequence_res.height()*0.5);
|
||||
rect.translate(rect.width()*0.5, rect.height()*0.5);
|
||||
// Normalize around center of sequence
|
||||
rect.translate(-sequence_res.width() * 0.5, -sequence_res.height() * 0.5);
|
||||
rect.translate(rect.width() * 0.5, rect.height() * 0.5);
|
||||
|
||||
NodeInput pos(this, ShapeNodeBase::kPositionInput);
|
||||
NodeInput sz(this, ShapeNodeBase::kSizeInput);
|
||||
NodeInput pos(this, ShapeNodeBase::kPositionInput);
|
||||
NodeInput sz(this, ShapeNodeBase::kSizeInput);
|
||||
|
||||
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 0), rect.width()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 1), rect.height()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 0), rect.x()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 1), rect.y()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(
|
||||
NodeKeyframeTrackReference(sz, 0), rect.width()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(
|
||||
NodeKeyframeTrackReference(sz, 1), rect.height()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(
|
||||
NodeKeyframeTrackReference(pos, 0), rect.x()));
|
||||
command->add_child(new NodeParamSetStandardValueCommand(
|
||||
NodeKeyframeTrackReference(pos, 1), rect.y()));
|
||||
}
|
||||
|
||||
void ShapeNodeBase::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
void ShapeNodeBase::GizmoDragMove(double x, double y,
|
||||
const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
|
||||
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
|
||||
if (gizmo == poly_gizmo_) {
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
} else {
|
||||
bool from_center = modifiers & Qt::AltModifier;
|
||||
bool keep_ratio = modifiers & Qt::ShiftModifier;
|
||||
if (gizmo == poly_gizmo_) {
|
||||
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
|
||||
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
|
||||
} else {
|
||||
bool from_center = modifiers & Qt::AltModifier;
|
||||
bool keep_ratio = modifiers & Qt::ShiftModifier;
|
||||
|
||||
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
|
||||
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
|
||||
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
|
||||
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
|
||||
|
||||
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(), h_drag.GetStartValue().toDouble());
|
||||
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(), y_drag.GetStartValue().toDouble());
|
||||
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution()/2;
|
||||
QVector2D adjusted_pt(x, y);
|
||||
QVector2D new_size;
|
||||
QVector2D new_pos;
|
||||
QVector2D anchor;
|
||||
static const int kXYCount = 2;
|
||||
bool negative[kXYCount] = {false};
|
||||
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(),
|
||||
h_drag.GetStartValue().toDouble());
|
||||
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(),
|
||||
y_drag.GetStartValue().toDouble());
|
||||
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution() / 2;
|
||||
QVector2D adjusted_pt(x, y);
|
||||
QVector2D new_size;
|
||||
QVector2D new_pos;
|
||||
QVector2D anchor;
|
||||
static const int kXYCount = 2;
|
||||
bool negative[kXYCount] = { false };
|
||||
|
||||
double original_ratio;
|
||||
if (keep_ratio) {
|
||||
original_ratio = w_drag.GetStartValue().toDouble() / h_drag.GetStartValue().toDouble();
|
||||
}
|
||||
double original_ratio;
|
||||
if (keep_ratio) {
|
||||
original_ratio = w_drag.GetStartValue().toDouble() /
|
||||
h_drag.GetStartValue().toDouble();
|
||||
}
|
||||
|
||||
// Calculate new size
|
||||
if (from_center) {
|
||||
// Calculate new size by using distance from center and doubling it
|
||||
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
|
||||
// Calculate new size
|
||||
if (from_center) {
|
||||
// Calculate new size by using distance from center and doubling it
|
||||
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
|
||||
|
||||
if (IsGizmoTop(gizmo)) {
|
||||
new_size.setY(-new_size.y());
|
||||
}
|
||||
if (IsGizmoTop(gizmo)) {
|
||||
new_size.setY(-new_size.y());
|
||||
}
|
||||
|
||||
if (IsGizmoLeft(gizmo)) {
|
||||
new_size.setX(-new_size.x());
|
||||
}
|
||||
} else {
|
||||
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
|
||||
// from the gizmo being dragged
|
||||
adjusted_pt -= gizmo_half_res;
|
||||
if (IsGizmoLeft(gizmo)) {
|
||||
new_size.setX(-new_size.x());
|
||||
}
|
||||
} else {
|
||||
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
|
||||
// from the gizmo being dragged
|
||||
adjusted_pt -= gizmo_half_res;
|
||||
|
||||
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo, &adjusted_pt) + gizmo_half_res;
|
||||
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo,
|
||||
&adjusted_pt) +
|
||||
gizmo_half_res;
|
||||
|
||||
adjusted_pt += gizmo_half_res;
|
||||
adjusted_pt += gizmo_half_res;
|
||||
|
||||
// Calculate size and position
|
||||
new_size = adjusted_pt - anchor;
|
||||
// Calculate size and position
|
||||
new_size = adjusted_pt - anchor;
|
||||
|
||||
// Abs size so neither coord is negative
|
||||
for (int i=0; i<kXYCount; i++) {
|
||||
if (new_size[i] < 0) {
|
||||
negative[i] = true;
|
||||
new_size[i] = -new_size[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Abs size so neither coord is negative
|
||||
for (int i = 0; i < kXYCount; i++) {
|
||||
if (new_size[i] < 0) {
|
||||
negative[i] = true;
|
||||
new_size[i] = -new_size[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restrict sizes by constraints
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate width from new height
|
||||
new_size.setX(new_size.y() * original_ratio);
|
||||
} else {
|
||||
// Constrain to original width
|
||||
new_size.setX(gizmo_sz_start.x());
|
||||
}
|
||||
}
|
||||
// Restrict sizes by constraints
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate width from new height
|
||||
new_size.setX(new_size.y() * original_ratio);
|
||||
} else {
|
||||
// Constrain to original width
|
||||
new_size.setX(gizmo_sz_start.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate height from new width
|
||||
new_size.setY(new_size.x() / original_ratio);
|
||||
} else {
|
||||
// Constrain to original height
|
||||
new_size.setY(gizmo_sz_start.y());
|
||||
}
|
||||
}
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate height from new width
|
||||
new_size.setY(new_size.x() / original_ratio);
|
||||
} else {
|
||||
// Constrain to original height
|
||||
new_size.setY(gizmo_sz_start.y());
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGizmoCorner(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
float hypot = std::hypot(new_size.x(), new_size.y());
|
||||
if (IsGizmoCorner(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
float hypot = std::hypot(new_size.x(), new_size.y());
|
||||
|
||||
float original_angle = std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
|
||||
float original_angle =
|
||||
std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
|
||||
|
||||
// Calculate new size based on original angle and hypotenuse
|
||||
new_size.setX(std::sin(original_angle) * hypot);
|
||||
new_size.setY(std::cos(original_angle) * hypot);
|
||||
}
|
||||
}
|
||||
// Calculate new size based on original angle and hypotenuse
|
||||
new_size.setX(std::sin(original_angle) * hypot);
|
||||
new_size.setY(std::cos(original_angle) * hypot);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate position
|
||||
if (from_center) {
|
||||
new_pos = gizmo_pos_start;
|
||||
} else {
|
||||
QVector2D using_size = new_size;
|
||||
// Calculate position
|
||||
if (from_center) {
|
||||
new_pos = gizmo_pos_start;
|
||||
} else {
|
||||
QVector2D using_size = new_size;
|
||||
|
||||
// Un-abs size
|
||||
for (int i=0; i<kXYCount; i++) {
|
||||
if (negative[i]) {
|
||||
using_size[i] = -using_size[i];
|
||||
}
|
||||
}
|
||||
// Un-abs size
|
||||
for (int i = 0; i < kXYCount; i++) {
|
||||
if (negative[i]) {
|
||||
using_size[i] = -using_size[i];
|
||||
}
|
||||
}
|
||||
|
||||
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
using_size.setY(0);
|
||||
}
|
||||
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
using_size.setY(0);
|
||||
}
|
||||
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
using_size.setX(0);
|
||||
}
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
using_size.setX(0);
|
||||
}
|
||||
|
||||
new_pos = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) + using_size / 2;
|
||||
}
|
||||
new_pos =
|
||||
GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) +
|
||||
using_size / 2;
|
||||
}
|
||||
|
||||
x_drag.Drag(new_pos.x());
|
||||
y_drag.Drag(new_pos.y());
|
||||
w_drag.Drag(new_size.x());
|
||||
h_drag.Drag(new_size.y());
|
||||
}
|
||||
x_drag.Drag(new_pos.x());
|
||||
y_drag.Drag(new_pos.y());
|
||||
w_drag.Drag(new_size.x());
|
||||
h_drag.Drag(new_size.y());
|
||||
}
|
||||
}
|
||||
|
||||
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt) const
|
||||
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos,
|
||||
const QVector2D &size,
|
||||
NodeGizmo *gizmo,
|
||||
QVector2D *pt) const
|
||||
{
|
||||
QVector2D anchor = pos;
|
||||
QVector2D half_sz = size/2;
|
||||
QVector2D anchor = pos;
|
||||
QVector2D half_sz = size / 2;
|
||||
|
||||
if (IsGizmoLeft(gizmo)) {
|
||||
anchor.setX(anchor.x() + half_sz.x());
|
||||
if (pt && pt->x() > anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
if (IsGizmoLeft(gizmo)) {
|
||||
anchor.setX(anchor.x() + half_sz.x());
|
||||
if (pt && pt->x() > anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGizmoRight(gizmo)) {
|
||||
anchor.setX(anchor.x() - half_sz.x());
|
||||
if (pt && pt->x() < anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
if (IsGizmoRight(gizmo)) {
|
||||
anchor.setX(anchor.x() - half_sz.x());
|
||||
if (pt && pt->x() < anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGizmoTop(gizmo)) {
|
||||
anchor.setY(anchor.y() + half_sz.y());
|
||||
if (pt && pt->y() > anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
if (IsGizmoTop(gizmo)) {
|
||||
anchor.setY(anchor.y() + half_sz.y());
|
||||
if (pt && pt->y() > anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGizmoBottom(gizmo)) {
|
||||
anchor.setY(anchor.y() - half_sz.y());
|
||||
if (pt && pt->y() < anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
if (IsGizmoBottom(gizmo)) {
|
||||
anchor.setY(anchor.y() - half_sz.y());
|
||||
if (pt && pt->y() < anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
|
||||
return anchor;
|
||||
return anchor;
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoTop(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight];
|
||||
return g == point_gizmo_[kGizmoScaleTopCenter] ||
|
||||
g == point_gizmo_[kGizmoScaleTopLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleTopRight];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoBottom(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleBottomCenter] || g == point_gizmo_[kGizmoScaleBottomLeft] || g == point_gizmo_[kGizmoScaleBottomRight];
|
||||
return g == point_gizmo_[kGizmoScaleBottomCenter] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomRight];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoLeft(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleBottomLeft];
|
||||
return g == point_gizmo_[kGizmoScaleTopLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleCenterLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomLeft];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoRight(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleTopRight] || g == point_gizmo_[kGizmoScaleCenterRight] || g == point_gizmo_[kGizmoScaleBottomRight];
|
||||
return g == point_gizmo_[kGizmoScaleTopRight] ||
|
||||
g == point_gizmo_[kGizmoScaleCenterRight] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomRight];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoHorizontalCenter(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleCenterRight];
|
||||
return g == point_gizmo_[kGizmoScaleCenterLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleCenterRight];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoVerticalCenter(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleBottomCenter];
|
||||
return g == point_gizmo_[kGizmoScaleTopCenter] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomCenter];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoCorner(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight]
|
||||
|| g == point_gizmo_[kGizmoScaleBottomRight] || g == point_gizmo_[kGizmoScaleBottomLeft];
|
||||
return g == point_gizmo_[kGizmoScaleTopLeft] ||
|
||||
g == point_gizmo_[kGizmoScaleTopRight] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomRight] ||
|
||||
g == point_gizmo_[kGizmoScaleBottomLeft];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,49 +27,53 @@
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ShapeNodeBase : public GeneratorWithMerge
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class ShapeNodeBase : public GeneratorWithMerge {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShapeNodeBase(bool create_color_input = true);
|
||||
ShapeNodeBase(bool create_color_input = true);
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
void SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command);
|
||||
void SetRect(QRectF rect, const VideoParams &sequence_res,
|
||||
MultiUndoCommand *command);
|
||||
|
||||
static const QString kPositionInput;
|
||||
static const QString kSizeInput;
|
||||
static const QString kColorInput;
|
||||
static const QString kPositionInput;
|
||||
static const QString kSizeInput;
|
||||
static const QString kColorInput;
|
||||
|
||||
protected:
|
||||
PolygonGizmo *poly_gizmo() const
|
||||
{
|
||||
return poly_gizmo_;
|
||||
}
|
||||
PolygonGizmo *poly_gizmo() const
|
||||
{
|
||||
return poly_gizmo_;
|
||||
}
|
||||
|
||||
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:
|
||||
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt = nullptr) const;
|
||||
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size,
|
||||
NodeGizmo *gizmo,
|
||||
QVector2D *pt = nullptr) const;
|
||||
|
||||
bool IsGizmoTop(NodeGizmo *g) const;
|
||||
bool IsGizmoBottom(NodeGizmo *g) const;
|
||||
bool IsGizmoLeft(NodeGizmo *g) const;
|
||||
bool IsGizmoRight(NodeGizmo *g) const;
|
||||
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
|
||||
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
|
||||
bool IsGizmoCorner(NodeGizmo *g) const;
|
||||
|
||||
// Gizmo variables
|
||||
static const int kGizmoWholeRect = kGizmoScaleCount;
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
bool IsGizmoTop(NodeGizmo *g) const;
|
||||
bool IsGizmoBottom(NodeGizmo *g) const;
|
||||
bool IsGizmoLeft(NodeGizmo *g) const;
|
||||
bool IsGizmoRight(NodeGizmo *g) const;
|
||||
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
|
||||
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
|
||||
bool IsGizmoCorner(NodeGizmo *g) const;
|
||||
|
||||
// Gizmo variables
|
||||
static const int kGizmoWholeRect = kGizmoScaleCount;
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user