Squashed commit of the following:
commit 8619bb044081da81b4eef238d138bd051e678a4c Merge: 1a767e0c21c30c4d36Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun Mar 27 23:59:10 2022 -0700 Merge branch 'master' into gizmo-rework commit 1a767e0c2279cac3baf96a9028c1b78ec0491e00 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun Mar 27 17:23:07 2022 -0700 implement custom html parser/exporter commit bbd9361d345ce864d198f4340b3d59f526e642e5 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 9 22:27:17 2022 -0800 textgizmo: further improved behavior commit 27634d5d377f03cab009bca418765d73764893f2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 9 22:26:19 2022 -0800 textgizmo: improved double click behavior commit 0897ebfa36e676461c7a47305a3c1bf66e7a9fd1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 9 10:20:57 2022 -0800 text: added more features and improvements commit 9d6446a25d977ea0c66e5f5c69239aed0e92fe83 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 9 10:14:59 2022 -0800 text: don't create color input commit d1d3b9d46e74d8197ba3485a8e965068eb245166 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 9 09:10:23 2022 -0800 text: convert to reference space commit 3ba1565129a0bdd74b860b1869fec5ef30025abb Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon Mar 7 17:57:26 2022 -0800 finally got scaling to work holy shit I never thought it'd be this easy commit 081368cfac9b49a171db6c1d576e134903dffac0 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon Mar 7 11:25:58 2022 -0800 improved text behavior commit f3eda52eee29b7cd354d7d90b3ae1a819e1b1cf2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon Mar 7 11:08:31 2022 -0800 implemented font styles (weights and italics) commit 0898b613ec9b473ac93996536d00541e0a2a3f74 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon Mar 7 01:26:13 2022 -0800 implemented beginnings of text gizmo commit bffb8ede2d425e7391d16bc03e613d4d90367add Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun Mar 6 17:55:03 2022 -0800 conformed transform node to new gizmos commit 1a1f86fa9bec9ea6b67f77032748c04b6b4c95fd Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat Mar 5 11:16:34 2022 -0800 update polygon node commit 2388dd69164e8c57e0a1d221c7680a0d39173c2c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri Mar 4 15:31:39 2022 -0800 implement glsl hack for corner pin commit e96df6cb326fb278cc6555890ff0ac1d37ebf4bf Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu Mar 3 17:06:14 2022 -0800 updated corner pin commit c70aa0e72d4e83045c84259294608c1380e8929b Merge: 5afed6383780342881Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu Mar 3 17:04:40 2022 -0800 Merge branch 'master' into gizmo-rework commit 5afed6383952d7d936b5eeda2556339c854610af Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu Mar 3 16:55:57 2022 -0800 use float points for more precise math commit 159ade0d2812d556dee57f99e3f733ef1e838d01 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu Mar 3 16:55:40 2022 -0800 ported shape node commit 28f9500d7bc6cd2661ee9ea591db7b3f8d583196 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu Mar 3 15:50:19 2022 -0800 implemented enough dragging code to reimplement crop Requires far less boiler-plate code per node commit 5aeaa59227ad2f1dc3c7f499c636de843a262a88 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 2 19:45:04 2022 -0800 update just merged corner pin for new gizmos commit 8a2d041650d1b873c6d87664564ebcdf92a3760f Merge: c916e8e08f5b4729a1Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 2 19:38:36 2022 -0800 Merge branch 'master' into gizmo-rework commit c916e8e08016c1d0b72d85087db76e4137587d52 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed Mar 2 19:35:09 2022 -0800 gizmos: rewrote drawing into standard routines Work towards a far more maintainable gizmo system
This commit is contained in:
@@ -21,6 +21,7 @@ add_subdirectory(distort)
|
||||
add_subdirectory(effect)
|
||||
add_subdirectory(filter)
|
||||
add_subdirectory(generator)
|
||||
add_subdirectory(gizmo)
|
||||
add_subdirectory(group)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(math)
|
||||
|
||||
@@ -41,6 +41,13 @@ CornerPinDistortNode::CornerPinDistortNode()
|
||||
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)});
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::Retranslate()
|
||||
@@ -127,14 +134,20 @@ QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow& row, c
|
||||
}
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p)
|
||||
void CornerPinDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
{
|
||||
const QVector2D &resolution = globals.resolution();
|
||||
|
||||
const double handle_radius = GetGizmoHandleRadius(p->transform());
|
||||
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
|
||||
QPointF top_left = ValueToPixel(0, row, resolution);
|
||||
QPointF top_right = ValueToPixel(1, row, resolution);
|
||||
QPointF bottom_right = ValueToPixel(2, row, resolution);
|
||||
@@ -147,71 +160,13 @@ void CornerPinDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals
|
||||
SetInputProperty(kBottomLeftInput, QStringLiteral("offset"), QVector2D(0.0, resolution.y()));
|
||||
|
||||
// Draw bounding box
|
||||
p->drawLine(QLineF(top_left, top_right));
|
||||
p->drawLine(QLineF(top_right, bottom_right));
|
||||
p->drawLine(QLineF(bottom_right, bottom_left));
|
||||
p->drawLine(QLineF(bottom_left, top_left));
|
||||
gizmo_whole_rect_->SetPolygon(QPolygonF({top_left, top_right, bottom_right, bottom_left, top_left}));
|
||||
|
||||
// Create handles
|
||||
gizmo_resize_handle_[0] = CreateGizmoHandleRect(top_left, handle_radius);
|
||||
gizmo_resize_handle_[1] = CreateGizmoHandleRect(top_right, handle_radius);
|
||||
gizmo_resize_handle_[2] = CreateGizmoHandleRect(bottom_right, handle_radius);
|
||||
gizmo_resize_handle_[3] = CreateGizmoHandleRect(bottom_left, handle_radius);
|
||||
|
||||
// Draw handles
|
||||
DrawAndExpandGizmoHandles(p, handle_radius, gizmo_resize_handle_, kGizmoCornerCount);
|
||||
}
|
||||
|
||||
bool CornerPinDistortNode::GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p)
|
||||
{
|
||||
bool gizmo_active[kGizmoCornerCount] = {false};
|
||||
|
||||
for (int i = 0; i < kGizmoCornerCount; i++) {
|
||||
gizmo_active[i] = gizmo_resize_handle_[i].contains(p);
|
||||
|
||||
if (gizmo_active[i]) {
|
||||
gizmo_drag_start_ = p;
|
||||
gizmo_res_ = globals.resolution();
|
||||
gizmo_drag_ = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(2);
|
||||
if (gizmo_drag_ == 0) {
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 1), time);
|
||||
}
|
||||
if (gizmo_drag_ == 1) {
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 1), time);
|
||||
}
|
||||
if (gizmo_drag_ == 2) {
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 1), time);
|
||||
}
|
||||
if (gizmo_drag_ == 3) {
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 1), time);
|
||||
}
|
||||
}
|
||||
|
||||
QPointF diff = p - gizmo_drag_start_;
|
||||
gizmo_dragger_[0].Drag(gizmo_dragger_[0].GetStartValue().toDouble() + diff.x());
|
||||
gizmo_dragger_[1].Drag(gizmo_dragger_[1].GetStartValue().toDouble() + diff.y());
|
||||
}
|
||||
|
||||
void CornerPinDistortNode::GizmoRelease(MultiUndoCommand *command) {
|
||||
for (NodeInputDragger &i : gizmo_dragger_) {
|
||||
i.End(command);
|
||||
}
|
||||
gizmo_dragger_.clear();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/gizmo/polygon.h"
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
@@ -66,16 +68,7 @@ public:
|
||||
|
||||
virtual ShaderCode GetShaderCode(const QString &shader_id) const override;
|
||||
|
||||
virtual bool HasGizmos() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void DrawGizmos(const NodeValueRow& row, const NodeGlobals &globals, QPainter *p) override;
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
|
||||
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoRelease(MultiUndoCommand *command) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
/**
|
||||
* @brief Convenience function - converts the 2D slider values from being
|
||||
@@ -90,16 +83,14 @@ public:
|
||||
static const QString kBottomRightInput;
|
||||
static const QString kBottomLeftInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
// Gizmo variables
|
||||
static const int kGizmoCornerCount = 4;
|
||||
QRectF gizmo_resize_handle_[kGizmoCornerCount];
|
||||
QRectF gizmo_whole_rect_;
|
||||
|
||||
int gizmo_drag_;
|
||||
QVector<NodeInputDragger> gizmo_dragger_;
|
||||
QPointF gizmo_drag_start_;
|
||||
QVector2D gizmo_res_;
|
||||
PointGizmo *gizmo_resize_handle_[kGizmoCornerCount];
|
||||
PolygonGizmo *gizmo_whole_rect_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "cropdistortnode.h"
|
||||
|
||||
#include "common/lerp.h"
|
||||
#include "common/util.h"
|
||||
#include "core.h"
|
||||
#include "widget/slider/floatslider.h"
|
||||
|
||||
@@ -44,6 +44,18 @@ CropDistortNode::CropDistortNode()
|
||||
|
||||
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
|
||||
|
||||
// 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});
|
||||
}
|
||||
|
||||
void CropDistortNode::Retranslate()
|
||||
@@ -81,164 +93,50 @@ ShaderCode CropDistortNode::GetShaderCode(const QString &shader_id) const
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/crop.frag")));
|
||||
}
|
||||
|
||||
void CropDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p)
|
||||
void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
{
|
||||
const QVector2D &resolution = globals.resolution();
|
||||
|
||||
const double handle_radius = GetGizmoHandleRadius(p->transform());
|
||||
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
|
||||
double left_pt = resolution.x() * row[kLeftInput].data().toDouble();
|
||||
double top_pt = resolution.y() * row[kTopInput].data().toDouble();
|
||||
double right_pt = resolution.x() * (1.0 - row[kRightInput].data().toDouble());
|
||||
double bottom_pt = resolution.y() * (1.0 - row[kBottomInput].data().toDouble());
|
||||
double center_x_pt = lerp(left_pt, right_pt, 0.5);
|
||||
double center_y_pt = lerp(top_pt, bottom_pt, 0.5);
|
||||
double center_x_pt = mid(left_pt, right_pt);
|
||||
double center_y_pt = mid(top_pt, bottom_pt);
|
||||
|
||||
gizmo_whole_rect_ = QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt);
|
||||
p->drawRect(gizmo_whole_rect_);
|
||||
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));
|
||||
|
||||
gizmo_resize_handle_[kGizmoScaleTopLeft] = CreateGizmoHandleRect(QPointF(left_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleTopCenter] = CreateGizmoHandleRect(QPointF(center_x_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleTopRight] = CreateGizmoHandleRect(QPointF(right_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomLeft] = CreateGizmoHandleRect(QPointF(left_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomCenter] = CreateGizmoHandleRect(QPointF(center_x_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomRight] = CreateGizmoHandleRect(QPointF(right_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterLeft] = CreateGizmoHandleRect(QPointF(left_pt, center_y_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterRight] = CreateGizmoHandleRect(QPointF(right_pt, center_y_pt), handle_radius);
|
||||
|
||||
DrawAndExpandGizmoHandles(p, handle_radius, gizmo_resize_handle_, kGizmoScaleCount);
|
||||
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
|
||||
}
|
||||
|
||||
bool CropDistortNode::GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p)
|
||||
void CropDistortNode::GizmoDragMove(double x_diff, double y_diff, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
bool found_handle = false;
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
|
||||
bool gizmo_active[kGizmoScaleCount] = {false};
|
||||
QVector2D res = gizmo->GetGlobals().resolution();
|
||||
x_diff /= res.x();
|
||||
y_diff /= res.y();
|
||||
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
gizmo_active[i] = gizmo_resize_handle_[i].contains(p);
|
||||
|
||||
if (gizmo_active[i]) {
|
||||
found_handle = true;
|
||||
break;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool in_rect = found_handle ? false : gizmo_whole_rect_.contains(p);
|
||||
|
||||
gizmo_drag_ = kGizmoNone;
|
||||
|
||||
// Drag handle
|
||||
if (gizmo_active[kGizmoScaleTopLeft]
|
||||
|| gizmo_active[kGizmoScaleCenterLeft]
|
||||
|| gizmo_active[kGizmoScaleBottomLeft]
|
||||
|| in_rect) {
|
||||
gizmo_drag_ |= kGizmoLeft;
|
||||
|
||||
gizmo_start_.append(row[kLeftInput].data());
|
||||
}
|
||||
|
||||
if (gizmo_active[kGizmoScaleTopLeft]
|
||||
|| gizmo_active[kGizmoScaleTopCenter]
|
||||
|| gizmo_active[kGizmoScaleTopRight]
|
||||
|| in_rect) {
|
||||
gizmo_drag_ |= kGizmoTop;
|
||||
|
||||
gizmo_start_.append(row[kTopInput].data());
|
||||
}
|
||||
|
||||
if (gizmo_active[kGizmoScaleTopRight]
|
||||
|| gizmo_active[kGizmoScaleCenterRight]
|
||||
|| gizmo_active[kGizmoScaleBottomRight]
|
||||
|| in_rect) {
|
||||
gizmo_drag_ |= kGizmoRight;
|
||||
|
||||
gizmo_start_.append(row[kRightInput].data());
|
||||
}
|
||||
|
||||
if (gizmo_active[kGizmoScaleBottomLeft]
|
||||
|| gizmo_active[kGizmoScaleBottomCenter]
|
||||
|| gizmo_active[kGizmoScaleBottomRight]
|
||||
|| in_rect) {
|
||||
gizmo_drag_ |= kGizmoBottom;
|
||||
|
||||
gizmo_start_.append(row[kBottomInput].data());
|
||||
}
|
||||
|
||||
if (gizmo_drag_ > kGizmoNone) {
|
||||
gizmo_res_ = globals.resolution();
|
||||
gizmo_drag_start_ = p;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CropDistortNode::GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(gizmo_start_.size());
|
||||
|
||||
int counter = 0;
|
||||
|
||||
if (gizmo_drag_ & kGizmoLeft) {
|
||||
gizmo_dragger_[counter].Start(NodeInput(this, kLeftInput), time);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoTop) {
|
||||
gizmo_dragger_[counter].Start(NodeInput(this, kTopInput), time);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoRight) {
|
||||
gizmo_dragger_[counter].Start(NodeInput(this, kRightInput), time);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoBottom) {
|
||||
gizmo_dragger_[counter].Start(NodeInput(this, kBottomInput), time);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
|
||||
double x_diff = (p.x() - gizmo_drag_start_.x()) / gizmo_res_.x();
|
||||
double y_diff = (p.y() - gizmo_drag_start_.y()) / gizmo_res_.y();
|
||||
|
||||
if (gizmo_drag_ & kGizmoLeft) {
|
||||
gizmo_dragger_[counter].Drag(gizmo_start_[counter].toDouble() + x_diff);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoTop) {
|
||||
gizmo_dragger_[counter].Drag(gizmo_start_[counter].toDouble() + y_diff);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoRight) {
|
||||
gizmo_dragger_[counter].Drag(gizmo_start_[counter].toDouble() - x_diff);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ & kGizmoBottom) {
|
||||
gizmo_dragger_[counter].Drag(gizmo_start_[counter].toDouble() - y_diff);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
void CropDistortNode::GizmoRelease(MultiUndoCommand *command)
|
||||
{
|
||||
for (NodeInputDragger& i : gizmo_dragger_) {
|
||||
i.End(command);
|
||||
}
|
||||
gizmo_dragger_.clear();
|
||||
|
||||
gizmo_start_.clear();
|
||||
}
|
||||
|
||||
void CropDistortNode::CreateCropSideInput(const QString &id)
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/gizmo/polygon.h"
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
@@ -67,16 +69,7 @@ public:
|
||||
|
||||
virtual ShaderCode GetShaderCode(const QString &shader_id) const override;
|
||||
|
||||
virtual bool HasGizmos() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void DrawGizmos(const NodeValueRow& row, const NodeGlobals &globals, QPainter *p) override;
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
|
||||
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoRelease(MultiUndoCommand *command) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kLeftInput;
|
||||
@@ -85,27 +78,15 @@ public:
|
||||
static const QString kBottomInput;
|
||||
static const QString kFeatherInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double delta_x, double delta_y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
void CreateCropSideInput(const QString& id);
|
||||
|
||||
// Gizmo variables
|
||||
QRectF gizmo_resize_handle_[kGizmoScaleCount];
|
||||
QRectF gizmo_whole_rect_;
|
||||
|
||||
enum GizmoDragDirection {
|
||||
kGizmoNone = 0x0,
|
||||
kGizmoLeft = 0x1,
|
||||
kGizmoTop = 0x2,
|
||||
kGizmoRight = 0x4,
|
||||
kGizmoBottom = 0x8,
|
||||
kGizmoRectangle = 0xFF
|
||||
};
|
||||
|
||||
int gizmo_drag_;
|
||||
QVector<NodeInputDragger> gizmo_dragger_;
|
||||
QVector<QVariant> gizmo_start_;
|
||||
QPointF gizmo_drag_start_;
|
||||
QVector2D gizmo_res_;
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,29 @@ TransformDistortNode::TransformDistortNode()
|
||||
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
|
||||
|
||||
PrependInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
// 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));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void TransformDistortNode::Retranslate()
|
||||
@@ -101,218 +124,6 @@ ShaderCode TransformDistortNode::GetShaderCode(const QString &shader_id) const
|
||||
return ShaderCode();
|
||||
}
|
||||
|
||||
bool TransformDistortNode::GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p)
|
||||
{
|
||||
TexturePtr tex = row[kTextureInput].data().value<TexturePtr>();
|
||||
if (!tex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store cursor position
|
||||
gizmo_drag_pos_ = p;
|
||||
|
||||
// Check scaling
|
||||
bool gizmo_scale_active[kGizmoScaleCount] = {false};
|
||||
bool scaling = false;
|
||||
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
gizmo_scale_active[i] = gizmo_resize_handle_[i].contains(p);
|
||||
|
||||
if (gizmo_scale_active[i]) {
|
||||
scaling = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (scaling) {
|
||||
|
||||
// Dragging scale handle
|
||||
gizmo_start_ = {row[kScaleInput].data()};
|
||||
gizmo_drag_ = kScaleInput;
|
||||
|
||||
gizmo_scale_uniform_ = row[kUniformScaleInput].data().toBool();
|
||||
|
||||
if (gizmo_scale_active[kGizmoScaleTopLeft] || gizmo_scale_active[kGizmoScaleTopRight]
|
||||
|| gizmo_scale_active[kGizmoScaleBottomLeft] || gizmo_scale_active[kGizmoScaleBottomRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleBoth;
|
||||
} else if (gizmo_scale_active[kGizmoScaleCenterLeft] || gizmo_scale_active[kGizmoScaleCenterRight]) {
|
||||
gizmo_scale_axes_ = kGizmoScaleXOnly;
|
||||
} else {
|
||||
gizmo_scale_axes_ = kGizmoScaleYOnly;
|
||||
}
|
||||
|
||||
// Store texture size
|
||||
VideoParams texture_params = tex->params();
|
||||
QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height());
|
||||
gizmo_scale_anchor_ = row[kAnchorInput].data().value<QVector2D>() + texture_sz/2;
|
||||
|
||||
if (gizmo_scale_active[kGizmoScaleTopRight]
|
||||
|| gizmo_scale_active[kGizmoScaleBottomRight]
|
||||
|| gizmo_scale_active[kGizmoScaleCenterRight]) {
|
||||
// Right handles, flip X axis
|
||||
gizmo_scale_anchor_.setX(texture_sz.x() - gizmo_scale_anchor_.x());
|
||||
}
|
||||
|
||||
if (gizmo_scale_active[kGizmoScaleBottomLeft]
|
||||
|| gizmo_scale_active[kGizmoScaleBottomRight]
|
||||
|| gizmo_scale_active[kGizmoScaleBottomCenter]) {
|
||||
// Bottom handles, flip Y axis
|
||||
gizmo_scale_anchor_.setY(texture_sz.y() - gizmo_scale_anchor_.y());
|
||||
}
|
||||
|
||||
// Store current matrix
|
||||
gizmo_matrix_ = GenerateMatrix(row, false, true, true, true);
|
||||
|
||||
return true;
|
||||
|
||||
} else if (gizmo_anchor_pt_.contains(p)) {
|
||||
|
||||
// Dragging the anchor point specifically
|
||||
gizmo_start_ = {row[kAnchorInput].data(),
|
||||
row[kPositionInput].data()};
|
||||
gizmo_drag_ = kAnchorInput;
|
||||
|
||||
// Store current matrix
|
||||
gizmo_matrix_ = GenerateMatrix(row, false, true, true, false);
|
||||
|
||||
return true;
|
||||
|
||||
} else if (gizmo_rect_.containsPoint(p, Qt::OddEvenFill)) {
|
||||
|
||||
// Dragging the main rectangle
|
||||
gizmo_start_ = {row[kPositionInput].data()};
|
||||
gizmo_drag_ = kPositionInput;
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
// Dragging rotation
|
||||
gizmo_start_ = {row[kRotationInput].data()};
|
||||
gizmo_drag_ = kRotationInput;
|
||||
gizmo_start_angle_ = qAtan2(gizmo_drag_pos_.y() - gizmo_anchor_pt_.center().y(),
|
||||
gizmo_drag_pos_.x() - gizmo_anchor_pt_.center().x());
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TransformDistortNode::GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
QPointF movement = (p - gizmo_drag_pos_);
|
||||
QVector2D vec_movement(movement);
|
||||
|
||||
if (gizmo_drag_ == kAnchorInput) {
|
||||
|
||||
// Dragging the anchor point around
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(4);
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 1), time);
|
||||
gizmo_dragger_[2].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0), time);
|
||||
gizmo_dragger_[3].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1), time);
|
||||
}
|
||||
|
||||
QVector2D inverted_movement(gizmo_matrix_.toTransform().inverted().map(movement));
|
||||
QVector2D anchor_cont = gizmo_start_[0].value<QVector2D>() + inverted_movement;
|
||||
QVector2D position_cont = gizmo_start_[1].value<QVector2D>() + vec_movement;
|
||||
|
||||
gizmo_dragger_[0].Drag(anchor_cont.x());
|
||||
gizmo_dragger_[1].Drag(anchor_cont.y());
|
||||
gizmo_dragger_[2].Drag(position_cont.x());
|
||||
gizmo_dragger_[3].Drag(position_cont.y());
|
||||
|
||||
} else if (gizmo_drag_ == kPositionInput) {
|
||||
|
||||
// Dragging the main rectangle around
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(2);
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1), time);
|
||||
}
|
||||
|
||||
QVector2D position_cont = gizmo_start_[0].value<QVector2D>() + vec_movement;
|
||||
|
||||
gizmo_dragger_[0].Drag(position_cont.x());
|
||||
gizmo_dragger_[1].Drag(position_cont.y());
|
||||
|
||||
} else if (gizmo_drag_ == kScaleInput) {
|
||||
|
||||
// Dragging a resize handle
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
if (gizmo_scale_uniform_ || gizmo_scale_axes_ == kGizmoScaleXOnly) {
|
||||
gizmo_dragger_.resize(1);
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0), time);
|
||||
} else if (gizmo_scale_axes_ == kGizmoScaleYOnly) {
|
||||
gizmo_dragger_.resize(1);
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1), time);
|
||||
} else {
|
||||
gizmo_dragger_.resize(2);
|
||||
gizmo_dragger_[0].Start(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0), time);
|
||||
gizmo_dragger_[1].Start(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1), time);
|
||||
}
|
||||
}
|
||||
|
||||
QPointF mouse_relative = gizmo_matrix_.toTransform().inverted().map(QPointF(p - gizmo_anchor_pt_.center()));
|
||||
|
||||
double x_scaled_movement = qAbs(mouse_relative.x() / gizmo_scale_anchor_.x());
|
||||
double y_scaled_movement = qAbs(mouse_relative.y() / gizmo_scale_anchor_.y());
|
||||
|
||||
switch (gizmo_scale_axes_) {
|
||||
case kGizmoScaleXOnly:
|
||||
gizmo_dragger_[0].Drag(x_scaled_movement);
|
||||
break;
|
||||
case kGizmoScaleYOnly:
|
||||
gizmo_dragger_[0].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());
|
||||
|
||||
gizmo_dragger_[0].Drag(qAbs(distance / texture_diag));
|
||||
} else {
|
||||
gizmo_dragger_[0].Drag(x_scaled_movement);
|
||||
gizmo_dragger_[1].Drag(y_scaled_movement);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (gizmo_drag_ == kRotationInput) {
|
||||
|
||||
// Dragging outside the rectangle to rotate
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(1);
|
||||
gizmo_dragger_[0].Start(NodeInput(this, kRotationInput), time);
|
||||
}
|
||||
|
||||
double current_angle = qAtan2(p.y() - gizmo_anchor_pt_.center().y(),
|
||||
p.x() - gizmo_anchor_pt_.center().x());
|
||||
|
||||
double rotation_difference = (current_angle - gizmo_start_angle_) * 57.2958;
|
||||
|
||||
double rotation_cont = gizmo_start_[0].toDouble() + rotation_difference;
|
||||
|
||||
gizmo_dragger_[0].Drag(rotation_cont);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TransformDistortNode::GizmoRelease(MultiUndoCommand *command)
|
||||
{
|
||||
for (NodeInputDragger& i : gizmo_dragger_) {
|
||||
i.End(command);
|
||||
}
|
||||
gizmo_dragger_.clear();
|
||||
|
||||
gizmo_start_.clear();
|
||||
|
||||
gizmo_drag_ = nullptr;
|
||||
}
|
||||
|
||||
void TransformDistortNode::Hash(QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams &video_params) const
|
||||
{
|
||||
// If not connected to output, this will produce nothing
|
||||
@@ -342,6 +153,168 @@ void TransformDistortNode::Hash(QCryptographicHash &hash, const NodeGlobals &glo
|
||||
Node::Hash(out, GetValueHintForInput(kTextureInput), hash, globals, video_params);
|
||||
}
|
||||
|
||||
void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, double y, const rational &time)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
|
||||
if (gizmo == anchor_gizmo_) {
|
||||
|
||||
gizmo_inverted_transform_ = GenerateMatrix(row, false, true, true, false).toTransform().inverted();
|
||||
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
|
||||
// Dragging scale handle
|
||||
TexturePtr tex = row[kTextureInput].data().value<TexturePtr>();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
gizmo_scale_uniform_ = row[kUniformScaleInput].data().toBool();
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].data().value<QVector2D>() + gizmo->GetGlobals().resolution()/2).toPointF();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Store texture size
|
||||
VideoParams texture_params = tex->params();
|
||||
QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height());
|
||||
gizmo_scale_anchor_ = row[kAnchorInput].data().value<QVector2D>() + texture_sz/2;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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, false, true, true, true).toTransform().inverted();
|
||||
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
|
||||
gizmo_anchor_pt_ = (row[kAnchorInput].data().value<QVector2D>() + gizmo->GetGlobals().resolution()/2).toPointF();
|
||||
gizmo_start_angle_ = qAtan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
gizmo_last_angle_ = gizmo_start_angle_;
|
||||
gizmo_last_alt_angle_ = qAtan2(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)
|
||||
{
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
|
||||
if (gizmo == poly_gizmo_) {
|
||||
|
||||
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);
|
||||
|
||||
} 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];
|
||||
|
||||
QPointF inverted_movement(gizmo_inverted_transform_.map(QPointF(x, 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);
|
||||
|
||||
} else if (gizmo == rotation_gizmo_) {
|
||||
|
||||
double raw_angle = qAtan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
|
||||
double alt_angle = qAtan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
|
||||
|
||||
double current_angle = raw_angle;
|
||||
|
||||
// Detect rotation wrap around
|
||||
RotationDirection this_dir = GetDirectionFromAngles(gizmo_last_angle_, raw_angle);
|
||||
RotationDirection alt_dir = GetDirectionFromAngles(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_--;
|
||||
}
|
||||
|
||||
this_dir = gizmo_rotate_last_dir_;
|
||||
alt_dir = gizmo_rotate_last_alt_dir_;
|
||||
}
|
||||
}
|
||||
|
||||
gizmo_rotate_last_dir_ = this_dir;
|
||||
gizmo_rotate_last_alt_dir_ = alt_dir;
|
||||
gizmo_last_angle_ = raw_angle;
|
||||
gizmo_last_alt_angle_ = alt_angle;
|
||||
|
||||
current_angle += M_PI*2*gizmo_rotate_wrap_;
|
||||
|
||||
// Convert radians to degrees
|
||||
double rotation_difference = (current_angle - gizmo_start_angle_) * 57.2958;
|
||||
|
||||
NodeInputDragger &d = gizmo->GetDraggers()[0];
|
||||
d.Drag(d.GetStartValue().toDouble() + rotation_difference);
|
||||
|
||||
} else if (IsAScaleGizmo(gizmo)) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(const QMatrix4x4 &mat, const QVector2D &sequence_res, const QVector2D &texture_res, AutoScaleType autoscale_type)
|
||||
{
|
||||
// First, create an identity matrix
|
||||
@@ -387,33 +360,13 @@ QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(const QMatrix4x4 &mat
|
||||
return adjusted_matrix;
|
||||
}
|
||||
|
||||
QPointF TransformDistortNode::CreateScalePoint(double x, double y, const QPointF &half_res, const QMatrix4x4 &mat)
|
||||
{
|
||||
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
|
||||
{
|
||||
const QVector2D &sequence_res = globals.resolution();
|
||||
QVector2D texture_res(texture_params.square_pixel_width(), texture_params.height());
|
||||
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].data().toInt());
|
||||
|
||||
return AdjustMatrixByResolutions(generated_matrix,
|
||||
sequence_res,
|
||||
texture_res,
|
||||
autoscale);
|
||||
}
|
||||
|
||||
void TransformDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p)
|
||||
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
{
|
||||
TexturePtr tex = row[kTextureInput].data().value<TexturePtr>();
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 0 pen width is always 1px wide despite any transform
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
|
||||
// Get the sequence resolution
|
||||
const QVector2D &sequence_res = globals.resolution();
|
||||
QVector2D sequence_half_res = sequence_res * 0.5;
|
||||
@@ -441,14 +394,9 @@ void TransformDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals
|
||||
QPointF(-1, 1),
|
||||
QPointF(-1, -1)};
|
||||
QTransform rectangle_transform = rectangle_matrix.toTransform();
|
||||
gizmo_rect_ = rectangle_transform.map(points);
|
||||
gizmo_rect_.translate(sequence_half_res_pt);
|
||||
|
||||
// Draw rectangle
|
||||
p->drawPolyline(gizmo_rect_);
|
||||
|
||||
// Get handle size (relative to screen space rather than buffer space)
|
||||
const double resize_handle_rad = GetGizmoHandleRadius(p->transform());
|
||||
QPolygonF r = rectangle_transform.map(points);
|
||||
r.translate(sequence_half_res_pt);
|
||||
poly_gizmo_->SetPolygon(r);
|
||||
|
||||
// Draw anchor point
|
||||
QMatrix4x4 anchor_matrix;
|
||||
@@ -457,32 +405,17 @@ void TransformDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals
|
||||
sequence_res,
|
||||
tex_sz,
|
||||
autoscale);
|
||||
QPointF anchor_pt = anchor_matrix.toTransform().map(QPointF(0, 0)) + sequence_half_res_pt;
|
||||
const double anchor_pt_radius = resize_handle_rad * 2;
|
||||
|
||||
gizmo_anchor_pt_ = QRectF(anchor_pt.x() - anchor_pt_radius,
|
||||
anchor_pt.y() - anchor_pt_radius,
|
||||
anchor_pt_radius*2,
|
||||
anchor_pt_radius*2);
|
||||
|
||||
p->drawEllipse(anchor_pt, anchor_pt_radius, anchor_pt_radius);
|
||||
|
||||
p->drawLines({QLineF(anchor_pt.x() - anchor_pt_radius, anchor_pt.y(),
|
||||
anchor_pt.x() + anchor_pt_radius, anchor_pt.y()),
|
||||
QLineF(anchor_pt.x(), anchor_pt.y() - anchor_pt_radius,
|
||||
anchor_pt.x(), anchor_pt.y() + anchor_pt_radius)});
|
||||
anchor_gizmo_->SetPoint(anchor_matrix.toTransform().map(QPointF(0, 0)) + sequence_half_res_pt);
|
||||
|
||||
// Draw scale handles
|
||||
gizmo_resize_handle_[kGizmoScaleTopLeft] = CreateGizmoHandleRect(CreateScalePoint(-1, -1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleTopCenter] = CreateGizmoHandleRect(CreateScalePoint( 0, -1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleTopRight] = CreateGizmoHandleRect(CreateScalePoint( 1, -1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomLeft] = CreateGizmoHandleRect(CreateScalePoint(-1, 1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomCenter] = CreateGizmoHandleRect(CreateScalePoint( 0, 1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomRight] = CreateGizmoHandleRect(CreateScalePoint( 1, 1, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterLeft] = CreateGizmoHandleRect(CreateScalePoint(-1, 0, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterRight] = CreateGizmoHandleRect(CreateScalePoint( 1, 0, sequence_half_res_pt, rectangle_matrix), resize_handle_rad);
|
||||
|
||||
DrawAndExpandGizmoHandles(p, resize_handle_rad, gizmo_resize_handle_, kGizmoScaleCount);
|
||||
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
|
||||
@@ -490,4 +423,37 @@ void TransformDistortNode::DrawGizmos(const NodeValueRow &row, const NodeGlobals
|
||||
SetInputProperty(kAnchorInput, QStringLiteral("offset"), tex_sz * 0.5);
|
||||
}
|
||||
|
||||
QPointF TransformDistortNode::CreateScalePoint(double x, double y, const QPointF &half_res, const QMatrix4x4 &mat)
|
||||
{
|
||||
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
|
||||
{
|
||||
const QVector2D &sequence_res = globals.resolution();
|
||||
QVector2D texture_res(texture_params.square_pixel_width(), texture_params.height());
|
||||
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].data().toInt());
|
||||
|
||||
return AdjustMatrixByResolutions(generated_matrix,
|
||||
sequence_res,
|
||||
texture_res,
|
||||
autoscale);
|
||||
}
|
||||
|
||||
bool TransformDistortNode::IsAScaleGizmo(NodeGizmo *g) const
|
||||
{
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
if (point_gizmo_[i] == g) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TransformDistortNode::RotationDirection TransformDistortNode::GetDirectionFromAngles(double last, double current)
|
||||
{
|
||||
return (current > last) ? kDirectionPositive : kDirectionNegative;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#define TRANSFORMDISTORTNODE_H
|
||||
|
||||
#include "node/generator/matrix/matrix.h"
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/gizmo/polygon.h"
|
||||
#include "node/gizmo/screen.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -69,17 +72,6 @@ public:
|
||||
|
||||
virtual ShaderCode GetShaderCode(const QString& shader_id) const override;
|
||||
|
||||
virtual bool HasGizmos() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p) override;
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p) override;
|
||||
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoRelease(MultiUndoCommand *command) override;
|
||||
|
||||
enum AutoScaleType {
|
||||
kAutoScaleNone,
|
||||
kAutoScaleFit,
|
||||
@@ -92,6 +84,8 @@ public:
|
||||
const QVector2D& texture_res,
|
||||
AutoScaleType autoscale_type = kAutoScaleNone);
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextureInput;
|
||||
static const QString kAutoscaleInput;
|
||||
static const QString kInterpolationInput;
|
||||
@@ -99,18 +93,36 @@ public:
|
||||
protected:
|
||||
virtual void Hash(QCryptographicHash& hash, const NodeGlobals &globals, const VideoParams& video_params) const override;
|
||||
|
||||
protected slots:
|
||||
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;
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
bool IsAScaleGizmo(NodeGizmo *g) const;
|
||||
|
||||
// Gizmo variables
|
||||
QString gizmo_drag_;
|
||||
QVector<QVariant> gizmo_start_;
|
||||
QVector<NodeInputDragger> gizmo_dragger_;
|
||||
QPointF gizmo_drag_pos_;
|
||||
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
|
||||
};
|
||||
|
||||
static RotationDirection GetDirectionFromAngles(double last, double current);
|
||||
RotationDirection gizmo_rotate_last_dir_;
|
||||
RotationDirection gizmo_rotate_last_alt_dir_;
|
||||
|
||||
enum GizmoScaleType {
|
||||
kGizmoScaleXOnly,
|
||||
@@ -119,13 +131,13 @@ private:
|
||||
};
|
||||
|
||||
GizmoScaleType gizmo_scale_axes_;
|
||||
QMatrix4x4 gizmo_matrix_;
|
||||
QVector2D gizmo_scale_anchor_;
|
||||
|
||||
// Gizmo on screen object storage
|
||||
QPolygonF gizmo_rect_;
|
||||
QRectF gizmo_anchor_pt_;
|
||||
QRectF gizmo_resize_handle_[kGizmoScaleCount];
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PointGizmo *anchor_gizmo_;
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
ScreenGizmo *rotation_gizmo_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
+11
-7
@@ -39,8 +39,9 @@
|
||||
#include "generator/polygon/polygon.h"
|
||||
#include "generator/shape/shapenode.h"
|
||||
#include "generator/solid/solid.h"
|
||||
#include "generator/text/text.h"
|
||||
#include "generator/text/textlegacy.h"
|
||||
#include "generator/text/textv1.h"
|
||||
#include "generator/text/textv2.h"
|
||||
#include "generator/text/textv3.h"
|
||||
#include "filter/blur/blur.h"
|
||||
#include "filter/mosaic/mosaicfilternode.h"
|
||||
#include "filter/stroke/stroke.h"
|
||||
@@ -72,7 +73,8 @@ void NodeFactory::Initialize()
|
||||
library_.append(created_node);
|
||||
}
|
||||
|
||||
hidden_.append(kTextGeneratorLegacy);
|
||||
hidden_.append(kTextGeneratorV1);
|
||||
hidden_.append(kTextGeneratorV2);
|
||||
hidden_.append(kGroupNode);
|
||||
}
|
||||
|
||||
@@ -229,10 +231,12 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
|
||||
return new MergeNode();
|
||||
case kStrokeFilter:
|
||||
return new StrokeFilterNode();
|
||||
case kTextGeneratorLegacy:
|
||||
return new TextGeneratorLegacy();
|
||||
case kTextGenerator:
|
||||
return new TextGenerator();
|
||||
case kTextGeneratorV1:
|
||||
return new TextGeneratorV1();
|
||||
case kTextGeneratorV2:
|
||||
return new TextGeneratorV2();
|
||||
case kTextGeneratorV3:
|
||||
return new TextGeneratorV3();
|
||||
case kCrossDissolveTransition:
|
||||
return new CrossDissolveTransition();
|
||||
case kDipToColorTransition:
|
||||
|
||||
+3
-2
@@ -48,8 +48,9 @@ public:
|
||||
kSolidGenerator,
|
||||
kMerge,
|
||||
kStrokeFilter,
|
||||
kTextGeneratorLegacy,
|
||||
kTextGenerator,
|
||||
kTextGeneratorV1,
|
||||
kTextGeneratorV2,
|
||||
kTextGeneratorV3,
|
||||
kCrossDissolveTransition,
|
||||
kDipToColorTransition,
|
||||
kMosaicFilter,
|
||||
|
||||
@@ -54,6 +54,9 @@ PolygonGenerator::PolygonGenerator()
|
||||
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 3);
|
||||
SetSplitStandardValueOnTrack(kPointsInput, 0, -kMiddleX, 4);
|
||||
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 4);
|
||||
|
||||
// Initiate gizmos
|
||||
poly_gizmo_ = new PathGizmo(this);
|
||||
}
|
||||
|
||||
Node *PolygonGenerator::copy() const
|
||||
@@ -149,139 +152,93 @@ void PolygonGenerator::GenerateFrame(FramePtr frame, const GenerateJob &job) con
|
||||
}
|
||||
}
|
||||
|
||||
bool PolygonGenerator::HasGizmos() const
|
||||
template<typename T>
|
||||
void PolygonGenerator::ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int old_sz = vec.size();
|
||||
|
||||
void PolygonGenerator::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p)
|
||||
{
|
||||
const double handle_radius = GetGizmoHandleRadius(p->transform());
|
||||
const double bezier_radius = handle_radius/2;
|
||||
|
||||
p->setPen(Qt::white);
|
||||
p->setBrush(Qt::white);
|
||||
p->translate(globals.resolution_by_par().x()/2, globals.resolution_by_par().y()/2);
|
||||
|
||||
QVector<NodeValue> points = row[kPointsInput].data().value< QVector<NodeValue> >();
|
||||
|
||||
gizmo_position_handles_.resize(points.size());
|
||||
gizmo_bezier_handles_.resize(points.size() * 2);
|
||||
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
p->setBrush(Qt::NoBrush);
|
||||
|
||||
if (!points.isEmpty()) {
|
||||
QVector<QLineF> lines(points.size() * 2);
|
||||
|
||||
for (int i=0; i<points.size(); i++) {
|
||||
const Bezier &pt = points.at(i).data().value<Bezier>();
|
||||
|
||||
QPointF main = pt.ToPointF();
|
||||
QPointF cp1 = main + pt.ControlPoint1ToPointF();
|
||||
QPointF cp2 = main + pt.ControlPoint2ToPointF();
|
||||
|
||||
gizmo_position_handles_[i] = CreateGizmoHandleRect(main, handle_radius);
|
||||
|
||||
gizmo_bezier_handles_[i*2] = CreateGizmoHandleRect(cp1, bezier_radius);
|
||||
lines[i*2] = QLineF(main, cp1);
|
||||
|
||||
gizmo_bezier_handles_[i*2+1] = CreateGizmoHandleRect(cp2, bezier_radius);
|
||||
lines[i*2+1] = QLineF(main, cp2);
|
||||
}
|
||||
|
||||
p->drawLines(lines);
|
||||
}
|
||||
|
||||
gizmo_polygon_path_ = GeneratePath(points);
|
||||
p->drawPath(gizmo_polygon_path_);
|
||||
|
||||
DrawAndExpandGizmoHandles(p, handle_radius, gizmo_position_handles_.data(), gizmo_position_handles_.size());
|
||||
DrawAndExpandGizmoHandles(p, handle_radius, gizmo_bezier_handles_.data(), gizmo_bezier_handles_.size());
|
||||
}
|
||||
|
||||
bool PolygonGenerator::GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p)
|
||||
{
|
||||
QPointF adjusted = p - (globals.resolution_by_par() / 2).toPointF();
|
||||
|
||||
// First, look for main points
|
||||
|
||||
for (int i=0; i<gizmo_position_handles_.size(); i++) {
|
||||
if (gizmo_position_handles_.at(i).contains(adjusted)) {
|
||||
gizmo_x_active_.append(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 0));
|
||||
gizmo_y_active_.append(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, if no main points were found, look for beziers
|
||||
if (gizmo_x_active_.isEmpty() && gizmo_y_active_.isEmpty()) {
|
||||
for (int i=0; i<gizmo_bezier_handles_.size(); i++) {
|
||||
if (gizmo_bezier_handles_.at(i).contains(adjusted)) {
|
||||
int start = (i%2 == 0) ? 2 : 4;
|
||||
int element = i/2;
|
||||
gizmo_x_active_.append(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, element), start + 0));
|
||||
gizmo_y_active_.append(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, element), start + 1));
|
||||
break;
|
||||
if (old_sz != new_sz) {
|
||||
if (old_sz > new_sz) {
|
||||
for (int i=new_sz; i<old_sz; i++) {
|
||||
delete vec.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, see if the cursor is inside the polygon
|
||||
if (gizmo_x_active_.isEmpty() && gizmo_y_active_.isEmpty()) {
|
||||
if (gizmo_polygon_path_.contains(adjusted)) {
|
||||
gizmo_x_active_.resize(gizmo_position_handles_.size());
|
||||
gizmo_y_active_.resize(gizmo_position_handles_.size());
|
||||
for (int i=0; i<gizmo_position_handles_.size(); i++) {
|
||||
gizmo_x_active_[i] = NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 0);
|
||||
gizmo_y_active_[i] = NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 1);
|
||||
vec.resize(new_sz);
|
||||
|
||||
if (old_sz < new_sz) {
|
||||
for (int i=old_sz; i<new_sz; i++) {
|
||||
if constexpr(std::is_same_v<T, PointGizmo>) {
|
||||
vec[i] = AddDraggableGizmo<T>();
|
||||
} else {
|
||||
vec[i] = new T(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gizmo_drag_start_ = p;
|
||||
|
||||
return !gizmo_x_active_.isEmpty() || !gizmo_y_active_.isEmpty();
|
||||
}
|
||||
|
||||
void PolygonGenerator::GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers)
|
||||
void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
{
|
||||
if (gizmo_x_draggers_.isEmpty() && gizmo_y_draggers_.isEmpty()) {
|
||||
gizmo_x_draggers_.resize(gizmo_x_active_.size());
|
||||
gizmo_y_draggers_.resize(gizmo_y_active_.size());
|
||||
for (int i=0; i<gizmo_x_active_.size(); i++) {
|
||||
gizmo_x_draggers_[i].Start(gizmo_x_active_.at(i), time);
|
||||
}
|
||||
for (int i=0; i<gizmo_y_active_.size(); i++) {
|
||||
gizmo_y_draggers_[i].Start(gizmo_y_active_.at(i), time);
|
||||
QPointF half_res(globals.resolution_by_par().x()/2, globals.resolution_by_par().y()/2);
|
||||
|
||||
QVector<NodeValue> points = row[kPointsInput].data().value< QVector<NodeValue> >();
|
||||
|
||||
int current_pos_sz = gizmo_position_handles_.size();
|
||||
|
||||
ValidateGizmoVectorSize(gizmo_position_handles_, points.size());
|
||||
ValidateGizmoVectorSize(gizmo_bezier_handles_, points.size() * 2);
|
||||
ValidateGizmoVectorSize(gizmo_bezier_lines_, points.size() * 2);
|
||||
|
||||
for (int i=current_pos_sz; i<gizmo_position_handles_.size(); i++) {
|
||||
gizmo_position_handles_.at(i)->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 0));
|
||||
gizmo_position_handles_.at(i)->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 1));
|
||||
|
||||
PointGizmo *bez_gizmo1 = gizmo_bezier_handles_.at(i*2+0);
|
||||
bez_gizmo1->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 2));
|
||||
bez_gizmo1->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 3));
|
||||
bez_gizmo1->SetShape(PointGizmo::kCircle);
|
||||
bez_gizmo1->SetSmaller(true);
|
||||
|
||||
PointGizmo *bez_gizmo2 = gizmo_bezier_handles_.at(i*2+1);
|
||||
bez_gizmo2->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 4));
|
||||
bez_gizmo2->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 5));
|
||||
bez_gizmo2->SetShape(PointGizmo::kCircle);
|
||||
bez_gizmo2->SetSmaller(true);
|
||||
}
|
||||
|
||||
if (!points.isEmpty()) {
|
||||
for (int i=0; i<points.size(); i++) {
|
||||
const Bezier &pt = points.at(i).data().value<Bezier>();
|
||||
|
||||
QPointF main = pt.ToPointF() + half_res;
|
||||
QPointF cp1 = main + pt.ControlPoint1ToPointF();
|
||||
QPointF cp2 = main + pt.ControlPoint2ToPointF();
|
||||
|
||||
gizmo_position_handles_[i]->SetPoint(main);
|
||||
|
||||
gizmo_bezier_handles_[i*2]->SetPoint(cp1);
|
||||
gizmo_bezier_lines_[i*2]->SetLine(QLineF(main, cp1));
|
||||
gizmo_bezier_handles_[i*2+1]->SetPoint(cp2);
|
||||
gizmo_bezier_lines_[i*2+1]->SetLine(QLineF(main, cp2));
|
||||
}
|
||||
}
|
||||
|
||||
QPointF diff = p - gizmo_drag_start_;
|
||||
|
||||
for (NodeInputDragger &dragger : gizmo_x_draggers_) {
|
||||
dragger.Drag(dragger.GetStartValue().toDouble() + diff.x());
|
||||
}
|
||||
|
||||
for (NodeInputDragger &dragger : gizmo_y_draggers_) {
|
||||
dragger.Drag(dragger.GetStartValue().toDouble() + diff.y());
|
||||
}
|
||||
poly_gizmo_->SetPath(GeneratePath(points).translated(half_res));
|
||||
}
|
||||
|
||||
void PolygonGenerator::GizmoRelease(MultiUndoCommand *command)
|
||||
void PolygonGenerator::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
for (NodeInputDragger &dragger : gizmo_x_draggers_) {
|
||||
dragger.End(command);
|
||||
}
|
||||
gizmo_x_draggers_.clear();
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
|
||||
for (NodeInputDragger &dragger : gizmo_y_draggers_) {
|
||||
dragger.End(command);
|
||||
if (gizmo == poly_gizmo_) {
|
||||
// FIXME: Drag all points
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
gizmo_y_draggers_.clear();
|
||||
|
||||
gizmo_x_active_.clear();
|
||||
gizmo_y_active_.clear();
|
||||
}
|
||||
|
||||
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after)
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <QPainterPath>
|
||||
|
||||
#include "common/bezier.h"
|
||||
#include "node/gizmo/line.h"
|
||||
#include "node/gizmo/path.h"
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/node.h"
|
||||
#include "node/inputdragger.h"
|
||||
|
||||
@@ -50,30 +53,26 @@ public:
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
|
||||
|
||||
virtual bool HasGizmos() const override;
|
||||
virtual void DrawGizmos(const NodeValueRow& row, const NodeGlobals &globals, QPainter *p) override;
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
|
||||
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoRelease(MultiUndoCommand *command) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kPointsInput;
|
||||
static const QString kColorInput;
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
static void AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after);
|
||||
|
||||
static QPainterPath GeneratePath(const QVector<NodeValue> &points);
|
||||
|
||||
QPainterPath gizmo_polygon_path_;
|
||||
QVector<QRectF> gizmo_position_handles_;
|
||||
QVector<QRectF> gizmo_bezier_handles_;
|
||||
template<typename T>
|
||||
void ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz);
|
||||
|
||||
QVector<NodeKeyframeTrackReference> gizmo_x_active_;
|
||||
QVector<NodeKeyframeTrackReference> gizmo_y_active_;
|
||||
QVector<NodeInputDragger> gizmo_x_draggers_;
|
||||
QVector<NodeInputDragger> gizmo_y_draggers_;
|
||||
QPointF gizmo_drag_start_;
|
||||
PathGizmo *poly_gizmo_;
|
||||
QVector<PointGizmo*> gizmo_position_handles_;
|
||||
QVector<PointGizmo*> gizmo_bezier_handles_;
|
||||
QVector<LineGizmo*> gizmo_bezier_lines_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <QtMath>
|
||||
#include <QVector2D>
|
||||
|
||||
#include "common/lerp.h"
|
||||
#include "common/util.h"
|
||||
#include "core.h"
|
||||
|
||||
namespace olive {
|
||||
@@ -34,12 +34,30 @@ QString ShapeNodeBase::kPositionInput = QStringLiteral("pos_in");
|
||||
QString ShapeNodeBase::kSizeInput = QStringLiteral("size_in");
|
||||
QString ShapeNodeBase::kColorInput = QStringLiteral("color_in");
|
||||
|
||||
ShapeNodeBase::ShapeNodeBase()
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNodeBase::Retranslate()
|
||||
@@ -48,20 +66,19 @@ void ShapeNodeBase::Retranslate()
|
||||
|
||||
SetInputName(kPositionInput, tr("Position"));
|
||||
SetInputName(kSizeInput, tr("Size"));
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
|
||||
if (HasInputWithID(kColorInput)) {
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNodeBase::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p)
|
||||
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.resolution() * 0.5;
|
||||
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
|
||||
|
||||
const double handle_radius = GetGizmoHandleRadius(p->transform());
|
||||
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
|
||||
QVector2D pos = row[kPositionInput].data().value<QVector2D>();
|
||||
QVector2D sz = row[kSizeInput].data().value<QVector2D>();
|
||||
QVector2D half_sz = sz * 0.5;
|
||||
@@ -70,151 +87,73 @@ void ShapeNodeBase::DrawGizmos(const NodeValueRow &row, const NodeGlobals &globa
|
||||
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 = lerp(left_pt, right_pt, 0.5);
|
||||
double center_y_pt = lerp(top_pt, bottom_pt, 0.5);
|
||||
double center_x_pt = mid(left_pt, right_pt);
|
||||
double center_y_pt = mid(top_pt, bottom_pt);
|
||||
|
||||
gizmo_whole_rect_ = QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt);
|
||||
p->drawRect(gizmo_whole_rect_);
|
||||
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));
|
||||
|
||||
gizmo_resize_handle_[kGizmoScaleTopLeft] = CreateGizmoHandleRect(QPointF(left_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleTopCenter] = CreateGizmoHandleRect(QPointF(center_x_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleTopRight] = CreateGizmoHandleRect(QPointF(right_pt, top_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomLeft] = CreateGizmoHandleRect(QPointF(left_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomCenter] = CreateGizmoHandleRect(QPointF(center_x_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleBottomRight] = CreateGizmoHandleRect(QPointF(right_pt, bottom_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterLeft] = CreateGizmoHandleRect(QPointF(left_pt, center_y_pt), handle_radius);
|
||||
gizmo_resize_handle_[kGizmoScaleCenterRight] = CreateGizmoHandleRect(QPointF(right_pt, center_y_pt), handle_radius);
|
||||
|
||||
DrawAndExpandGizmoHandles(p, handle_radius, gizmo_resize_handle_, kGizmoScaleCount);
|
||||
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p)
|
||||
void ShapeNodeBase::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
gizmo_drag_ = -1;
|
||||
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
|
||||
|
||||
// See if any of our resize handles have the pointer
|
||||
for (int i=0; i<kGizmoScaleCount; i++) {
|
||||
if (gizmo_resize_handle_[i].contains(p)) {
|
||||
gizmo_drag_ = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
|
||||
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
|
||||
|
||||
// See if the rect has the pointer
|
||||
if (gizmo_drag_ == -1 && gizmo_whole_rect_.contains(p)) {
|
||||
gizmo_drag_ = kGizmoWholeRect;
|
||||
}
|
||||
|
||||
if (gizmo_drag_ >= 0) {
|
||||
gizmo_pos_start_ = row[kPositionInput].data().value<QVector2D>();
|
||||
gizmo_sz_start_ = row[kSizeInput].data().value<QVector2D>();
|
||||
gizmo_drag_start_ = p;
|
||||
gizmo_half_res_ = globals.resolution()/2;
|
||||
|
||||
// Get aspect ratio (avoiding potential zero)
|
||||
if (qFuzzyIsNull(gizmo_sz_start_.y())) {
|
||||
gizmo_aspect_ratio_ = 0;
|
||||
} else {
|
||||
gizmo_aspect_ratio_ = gizmo_sz_start_.x() / gizmo_sz_start_.y();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
enum {
|
||||
kGDPosX,
|
||||
kGDPosY,
|
||||
kGDSzX,
|
||||
kGDSzY,
|
||||
kGDCount
|
||||
};
|
||||
|
||||
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, int drag, QVector2D *pt = nullptr)
|
||||
{
|
||||
QVector2D anchor = pos;
|
||||
QVector2D half_sz = size/2;
|
||||
|
||||
if (drag == kGizmoScaleTopLeft || drag == kGizmoScaleCenterLeft || drag == kGizmoScaleBottomLeft) {
|
||||
anchor.setX(anchor.x() + half_sz.x());
|
||||
if (pt && pt->x() > anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (drag == kGizmoScaleTopRight || drag == kGizmoScaleCenterRight || drag == kGizmoScaleBottomRight) {
|
||||
anchor.setX(anchor.x() - half_sz.x());
|
||||
if (pt && pt->x() < anchor.x()) {
|
||||
pt->setX(anchor.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (drag == kGizmoScaleTopLeft || drag == kGizmoScaleTopCenter || drag == kGizmoScaleTopRight) {
|
||||
anchor.setY(anchor.y() + half_sz.y());
|
||||
if (pt && pt->y() > anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
|
||||
if (drag == kGizmoScaleBottomLeft || drag == kGizmoScaleBottomCenter || drag == kGizmoScaleBottomRight) {
|
||||
anchor.setY(anchor.y() - half_sz.y());
|
||||
if (pt && pt->y() < anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
|
||||
return anchor;
|
||||
}
|
||||
|
||||
void ShapeNodeBase::GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
if (gizmo_dragger_.isEmpty()) {
|
||||
gizmo_dragger_.resize(kGDCount);
|
||||
gizmo_dragger_[kGDPosX].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0), time);
|
||||
gizmo_dragger_[kGDPosY].Start(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1), time);
|
||||
gizmo_dragger_[kGDSzX].Start(NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0), time);
|
||||
gizmo_dragger_[kGDSzY].Start(NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1), time);
|
||||
}
|
||||
|
||||
bool from_center = modifiers & Qt::AltModifier;
|
||||
bool keep_ratio = modifiers & Qt::ShiftModifier;
|
||||
|
||||
QVector2D adjusted_pt(p.x(), p.y());
|
||||
QVector2D diff(adjusted_pt.x() - gizmo_drag_start_.x(), adjusted_pt.y() - gizmo_drag_start_.y());
|
||||
|
||||
if (gizmo_drag_ == kGizmoWholeRect) {
|
||||
// Simply move position by difference
|
||||
gizmo_dragger_[kGDPosX].Drag(gizmo_pos_start_.x() + diff.x());
|
||||
gizmo_dragger_[kGDPosY].Drag(gizmo_pos_start_.y() + diff.y());
|
||||
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];
|
||||
|
||||
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().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();
|
||||
}
|
||||
|
||||
// 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;
|
||||
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
|
||||
|
||||
if (gizmo_drag_ == kGizmoScaleTopCenter || gizmo_drag_ == kGizmoScaleTopLeft || gizmo_drag_ == kGizmoScaleTopRight) {
|
||||
if (IsGizmoTop(gizmo)) {
|
||||
new_size.setY(-new_size.y());
|
||||
}
|
||||
|
||||
if (gizmo_drag_ == kGizmoScaleTopLeft || gizmo_drag_ == kGizmoScaleCenterLeft || gizmo_drag_ == kGizmoScaleBottomLeft) {
|
||||
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_;
|
||||
adjusted_pt -= gizmo_half_res;
|
||||
|
||||
anchor = GenerateGizmoAnchor(gizmo_pos_start_, gizmo_sz_start_, gizmo_drag_, &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;
|
||||
@@ -229,32 +168,31 @@ void ShapeNodeBase::GizmoMove(const QPointF &p, const rational &time, const Qt::
|
||||
}
|
||||
|
||||
// Restrict sizes by constraints
|
||||
if (gizmo_drag_ == kGizmoScaleTopCenter || gizmo_drag_ == kGizmoScaleBottomCenter) {
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate width from new height
|
||||
new_size.setX(new_size.y() * gizmo_aspect_ratio_);
|
||||
new_size.setX(new_size.y() * original_ratio);
|
||||
} else {
|
||||
// Constrain to original width
|
||||
new_size.setX(gizmo_sz_start_.x());
|
||||
new_size.setX(gizmo_sz_start.x());
|
||||
}
|
||||
}
|
||||
|
||||
if (gizmo_drag_ == kGizmoScaleCenterLeft || gizmo_drag_ == kGizmoScaleCenterRight) {
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
if (keep_ratio) {
|
||||
// Calculate height from new width
|
||||
new_size.setY(new_size.x() / gizmo_aspect_ratio_);
|
||||
new_size.setY(new_size.x() / original_ratio);
|
||||
} else {
|
||||
// Constrain to original height
|
||||
new_size.setY(gizmo_sz_start_.y());
|
||||
new_size.setY(gizmo_sz_start.y());
|
||||
}
|
||||
}
|
||||
|
||||
if (gizmo_drag_ == kGizmoScaleTopLeft || gizmo_drag_ == kGizmoScaleTopRight
|
||||
|| gizmo_drag_ == kGizmoScaleBottomRight || gizmo_drag_ == kGizmoScaleBottomLeft) {
|
||||
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);
|
||||
@@ -264,7 +202,7 @@ void ShapeNodeBase::GizmoMove(const QPointF &p, const rational &time, const Qt::
|
||||
|
||||
// Calculate position
|
||||
if (from_center) {
|
||||
new_pos = gizmo_pos_start_;
|
||||
new_pos = gizmo_pos_start;
|
||||
} else {
|
||||
QVector2D using_size = new_size;
|
||||
|
||||
@@ -276,31 +214,94 @@ void ShapeNodeBase::GizmoMove(const QPointF &p, const rational &time, const Qt::
|
||||
}
|
||||
|
||||
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
|
||||
if (gizmo_drag_ == kGizmoScaleCenterLeft || gizmo_drag_ == kGizmoScaleCenterRight) {
|
||||
if (IsGizmoHorizontalCenter(gizmo)) {
|
||||
using_size.setY(0);
|
||||
}
|
||||
|
||||
if (gizmo_drag_ == kGizmoScaleTopCenter || gizmo_drag_ == kGizmoScaleBottomCenter) {
|
||||
if (IsGizmoVerticalCenter(gizmo)) {
|
||||
using_size.setX(0);
|
||||
}
|
||||
|
||||
new_pos = GenerateGizmoAnchor(gizmo_pos_start_, gizmo_sz_start_, gizmo_drag_) + using_size / 2;
|
||||
new_pos = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) + using_size / 2;
|
||||
}
|
||||
|
||||
gizmo_dragger_[kGDPosX].Drag(new_pos.x());
|
||||
gizmo_dragger_[kGDPosY].Drag(new_pos.y());
|
||||
gizmo_dragger_[kGDSzX].Drag(new_size.x());
|
||||
gizmo_dragger_[kGDSzY].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());
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeNodeBase::GizmoRelease(MultiUndoCommand *command)
|
||||
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt) const
|
||||
{
|
||||
for (NodeInputDragger& i : gizmo_dragger_) {
|
||||
i.End(command);
|
||||
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());
|
||||
}
|
||||
}
|
||||
gizmo_dragger_.clear();
|
||||
|
||||
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 (IsGizmoBottom(gizmo)) {
|
||||
anchor.setY(anchor.y() - half_sz.y());
|
||||
if (pt && pt->y() < anchor.y()) {
|
||||
pt->setY(anchor.y());
|
||||
}
|
||||
}
|
||||
|
||||
return anchor;
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoTop(NodeGizmo *g) const
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoLeft(NodeGizmo *g) const
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoHorizontalCenter(NodeGizmo *g) const
|
||||
{
|
||||
return g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleCenterRight];
|
||||
}
|
||||
|
||||
bool ShapeNodeBase::IsGizmoVerticalCenter(NodeGizmo *g) const
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef SHAPENODEBASE_H
|
||||
#define SHAPENODEBASE_H
|
||||
|
||||
#include "node/gizmo/point.h"
|
||||
#include "node/gizmo/polygon.h"
|
||||
#include "node/inputdragger.h"
|
||||
#include "node/node.h"
|
||||
|
||||
@@ -30,42 +32,42 @@ class ShapeNodeBase : public Node
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShapeNodeBase();
|
||||
ShapeNodeBase(bool create_color_input = true);
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(ShapeNodeBase)
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
static QString kPositionInput;
|
||||
static QString kSizeInput;
|
||||
static QString kColorInput;
|
||||
|
||||
virtual bool HasGizmos() const override
|
||||
protected:
|
||||
PolygonGizmo *poly_gizmo() const
|
||||
{
|
||||
return true;
|
||||
return poly_gizmo_;
|
||||
}
|
||||
|
||||
virtual void DrawGizmos(const NodeValueRow &row, const NodeGlobals &globals, QPainter *p) override;
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
|
||||
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
|
||||
virtual void GizmoRelease(MultiUndoCommand *command) override;
|
||||
protected slots:
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
|
||||
|
||||
private:
|
||||
static QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, int drag, QVector2D *pt);
|
||||
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;
|
||||
QRectF gizmo_resize_handle_[kGizmoScaleCount];
|
||||
QRectF gizmo_whole_rect_;
|
||||
|
||||
int gizmo_drag_;
|
||||
QVector<NodeInputDragger> gizmo_dragger_;
|
||||
QVector2D gizmo_pos_start_;
|
||||
QVector2D gizmo_sz_start_;
|
||||
QPointF gizmo_drag_start_;
|
||||
float gizmo_aspect_ratio_;
|
||||
QVector2D gizmo_half_res_;
|
||||
PointGizmo *point_gizmo_[kGizmoScaleCount];
|
||||
PolygonGizmo *poly_gizmo_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
node/generator/text/text.cpp
|
||||
node/generator/text/text.h
|
||||
node/generator/text/textlegacy.cpp
|
||||
node/generator/text/textlegacy.h
|
||||
node/generator/text/textv1.cpp
|
||||
node/generator/text/textv1.h
|
||||
node/generator/text/textv2.cpp
|
||||
node/generator/text/textv2.h
|
||||
node/generator/text/textv3.cpp
|
||||
node/generator/text/textv3.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
***/
|
||||
|
||||
#include "textlegacy.h"
|
||||
#include "textv1.h"
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextDocument>
|
||||
@@ -31,14 +31,14 @@ enum TextVerticalAlign {
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorLegacy::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorLegacy::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGeneratorLegacy::kColorInput = QStringLiteral("color_in");
|
||||
const QString TextGeneratorLegacy::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorLegacy::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGeneratorLegacy::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
const QString TextGeneratorV1::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV1::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV1::kColorInput = QStringLiteral("color_in");
|
||||
const QString TextGeneratorV1::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV1::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV1::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
|
||||
TextGeneratorLegacy::TextGeneratorLegacy()
|
||||
TextGeneratorV1::TextGeneratorV1()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
|
||||
@@ -53,27 +53,27 @@ TextGeneratorLegacy::TextGeneratorLegacy()
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
}
|
||||
|
||||
QString TextGeneratorLegacy::Name() const
|
||||
QString TextGeneratorV1::Name() const
|
||||
{
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
|
||||
QString TextGeneratorLegacy::id() const
|
||||
QString TextGeneratorV1::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorLegacy::Category() const
|
||||
QVector<Node::CategoryID> TextGeneratorV1::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
}
|
||||
|
||||
QString TextGeneratorLegacy::Description() const
|
||||
QString TextGeneratorV1::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorLegacy::Retranslate()
|
||||
void TextGeneratorV1::Retranslate()
|
||||
{
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kHtmlInput, tr("Enable HTML"));
|
||||
@@ -84,7 +84,7 @@ void TextGeneratorLegacy::Retranslate()
|
||||
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
|
||||
}
|
||||
|
||||
void TextGeneratorLegacy::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TextGeneratorV1::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
{
|
||||
GenerateJob job;
|
||||
job.InsertValue(value);
|
||||
@@ -95,7 +95,7 @@ void TextGeneratorLegacy::Value(const NodeValueRow &value, const NodeGlobals &gl
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorLegacy::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
void TextGeneratorV1::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
@@ -18,21 +18,21 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATORLEGACY_H
|
||||
#define TEXTGENERATORLEGACY_H
|
||||
#ifndef TEXTGENERATORV1_H
|
||||
#define TEXTGENERATORV1_H
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGeneratorLegacy : public Node
|
||||
class TextGeneratorV1 : public Node
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGeneratorLegacy();
|
||||
TextGeneratorV1();
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(TextGeneratorLegacy)
|
||||
NODE_COPY_FUNCTION(TextGeneratorLegacy)
|
||||
NODE_DEFAULT_DESTRUCTOR(TextGeneratorV1)
|
||||
NODE_COPY_FUNCTION(TextGeneratorV1)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
@@ -56,4 +56,4 @@ public:
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATORLEGACY_H
|
||||
#endif // TEXTGENERATORV1_H
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
***/
|
||||
|
||||
#include "text.h"
|
||||
#include "textv2.h"
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QDateTime>
|
||||
@@ -37,13 +37,13 @@ enum TextVerticalAlign {
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGenerator::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGenerator::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGenerator::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGenerator::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGenerator::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
const QString TextGeneratorV2::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV2::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV2::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV2::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV2::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
|
||||
TextGenerator::TextGenerator()
|
||||
TextGeneratorV2::TextGeneratorV2()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
|
||||
@@ -59,27 +59,27 @@ TextGenerator::TextGenerator()
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
}
|
||||
|
||||
QString TextGenerator::Name() const
|
||||
QString TextGeneratorV2::Name() const
|
||||
{
|
||||
return tr("Text");
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
|
||||
QString TextGenerator::id() const
|
||||
QString TextGeneratorV2::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text2");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGenerator::Category() const
|
||||
QVector<Node::CategoryID> TextGeneratorV2::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
}
|
||||
|
||||
QString TextGenerator::Description() const
|
||||
QString TextGeneratorV2::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGenerator::Retranslate()
|
||||
void TextGeneratorV2::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
|
||||
@@ -91,7 +91,7 @@ void TextGenerator::Retranslate()
|
||||
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
|
||||
}
|
||||
|
||||
void TextGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
{
|
||||
GenerateJob job;
|
||||
job.InsertValue(value);
|
||||
@@ -103,7 +103,7 @@ void TextGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
}
|
||||
}
|
||||
|
||||
void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
void TextGeneratorV2::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
@@ -18,21 +18,21 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATOR_H
|
||||
#define TEXTGENERATOR_H
|
||||
#ifndef TEXTGENERATORV2_H
|
||||
#define TEXTGENERATORV2_H
|
||||
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGenerator : public ShapeNodeBase
|
||||
class TextGeneratorV2 : public ShapeNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGenerator();
|
||||
TextGeneratorV2();
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(TextGenerator)
|
||||
NODE_COPY_FUNCTION(TextGenerator)
|
||||
NODE_DEFAULT_DESTRUCTOR(TextGeneratorV2)
|
||||
NODE_COPY_FUNCTION(TextGeneratorV2)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
@@ -55,4 +55,4 @@ public:
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATOR_H
|
||||
#endif // TEXTGENERATORV2_H
|
||||
@@ -0,0 +1,140 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "textv3.h"
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QDateTime>
|
||||
#include <QTextDocument>
|
||||
|
||||
#include "common/functiontimer.h"
|
||||
#include "common/html.h"
|
||||
#include "node/project/project.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
#define super ShapeNodeBase
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV3::kTextInput = QStringLiteral("text_in");
|
||||
|
||||
TextGeneratorV3::TextGeneratorV3() :
|
||||
ShapeNodeBase(false)
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>").arg(tr("Sample Text")));
|
||||
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
|
||||
text_gizmo_ = new TextGizmo(this);
|
||||
text_gizmo_->SetInput(NodeInput(this, kTextInput));
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Name() const
|
||||
{
|
||||
return tr("Text");
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text3");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV3::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
{
|
||||
GenerateJob job;
|
||||
job.InsertValue(value);
|
||||
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
|
||||
job.SetRequestedFormat(VideoParams::kFormatUnsigned8);
|
||||
|
||||
// FIXME: Provide user override for this
|
||||
job.SetColorspace(project()->color_manager()->GetDefaultInputColorSpace());
|
||||
|
||||
if (!job.GetValue(kTextInput).data().toString().isEmpty()) {
|
||||
table->Push(NodeValue::kGenerateJob, QVariant::fromValue(job), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
{
|
||||
QImage img(reinterpret_cast<uchar*>(frame->data()), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
// 96 DPI in DPM (96 / 2.54 * 100)
|
||||
const int dpm = 3780;
|
||||
img.setDotsPerMeterX(dpm);
|
||||
img.setDotsPerMeterY(dpm);
|
||||
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
|
||||
QString html = job.GetValue(kTextInput).data().toString();
|
||||
Html::HtmlToDoc(&text_doc, html);
|
||||
|
||||
QVector2D size = job.GetValue(kSizeInput).data().value<QVector2D>();
|
||||
text_doc.setTextWidth(size.x());
|
||||
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
|
||||
|
||||
QVector2D pos = job.GetValue(kPositionInput).data().value<QVector2D>();
|
||||
p.translate(pos.x() - size.x()/2, pos.y() - size.y()/2);
|
||||
p.translate(frame->video_params().width()/2, frame->video_params().height()/2);
|
||||
p.setClipRect(0, 0, size.x(), size.y());
|
||||
|
||||
// Ensure default text color is white
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
}
|
||||
|
||||
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
{
|
||||
super::UpdateGizmoPositions(row, globals);
|
||||
|
||||
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
|
||||
text_gizmo_->SetRect(rect);
|
||||
text_gizmo_->SetHtml(row[kTextInput].data().toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATORV3_H
|
||||
#define TEXTGENERATORV3_H
|
||||
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
#include "node/gizmo/text.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGeneratorV3 : public ShapeNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGeneratorV3();
|
||||
|
||||
NODE_DEFAULT_DESTRUCTOR(TextGeneratorV3)
|
||||
NODE_COPY_FUNCTION(TextGeneratorV3)
|
||||
|
||||
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 Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
|
||||
static const QString kTextInput;
|
||||
|
||||
private:
|
||||
TextGizmo *text_gizmo_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATORV3_H
|
||||
@@ -0,0 +1,36 @@
|
||||
# Olive - Non-Linear Video Editor
|
||||
# Copyright (C) 2021 Olive Team
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
node/gizmo/draggable.cpp
|
||||
node/gizmo/draggable.h
|
||||
node/gizmo/gizmo.cpp
|
||||
node/gizmo/gizmo.h
|
||||
node/gizmo/line.cpp
|
||||
node/gizmo/line.h
|
||||
node/gizmo/path.cpp
|
||||
node/gizmo/path.h
|
||||
node/gizmo/point.cpp
|
||||
node/gizmo/point.h
|
||||
node/gizmo/polygon.cpp
|
||||
node/gizmo/polygon.h
|
||||
node/gizmo/screen.cpp
|
||||
node/gizmo/screen.h
|
||||
node/gizmo/text.cpp
|
||||
node/gizmo/text.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,52 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "draggable.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
DraggableGizmo::DraggableGizmo(QObject *parent)
|
||||
: NodeGizmo{parent},
|
||||
drag_value_behavior_(kAbsolute)
|
||||
{
|
||||
}
|
||||
|
||||
void DraggableGizmo::DragStart(const NodeValueRow &row, double abs_x, double abs_y, const rational &time)
|
||||
{
|
||||
for (int i=0; i<draggers_.size(); i++) {
|
||||
draggers_[i].Start(inputs_[i], time);
|
||||
}
|
||||
|
||||
emit HandleStart(row, abs_x, abs_y, time);
|
||||
}
|
||||
|
||||
void DraggableGizmo::DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
emit HandleMovement(x, y, modifiers);
|
||||
}
|
||||
|
||||
void DraggableGizmo::DragEnd(MultiUndoCommand *command)
|
||||
{
|
||||
for (int i=0; i<draggers_.size(); i++) {
|
||||
draggers_[i].End(command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef DRAGGABLEGIZMO_H
|
||||
#define DRAGGABLEGIZMO_H
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "gizmo.h"
|
||||
#include "node/inputdragger.h"
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class DraggableGizmo : public NodeGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/// Changes what the X/Y coordinates emitted from HandleMovement specify
|
||||
enum DragValueBehavior {
|
||||
/// X/Y will be the exact mouse coordinates (in sequence pixels)
|
||||
kAbsolute,
|
||||
|
||||
/// X/Y will be the movement since the last time HandleMovement was called
|
||||
kDeltaFromPrevious,
|
||||
|
||||
/// X/Y will be the movement from the start of the drag
|
||||
kDeltaFromStart
|
||||
};
|
||||
|
||||
explicit DraggableGizmo(QObject *parent = nullptr);
|
||||
|
||||
void DragStart(const NodeValueRow &row, double abs_x, double abs_y, const olive::rational &time);
|
||||
|
||||
void DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers);
|
||||
|
||||
void DragEnd(olive::MultiUndoCommand *command);
|
||||
|
||||
void AddInput(const NodeKeyframeTrackReference &input)
|
||||
{
|
||||
inputs_.append(input);
|
||||
draggers_.append(NodeInputDragger());
|
||||
}
|
||||
|
||||
QVector<NodeInputDragger> &GetDraggers()
|
||||
{
|
||||
return draggers_;
|
||||
}
|
||||
|
||||
DragValueBehavior GetDragValueBehavior() const { return drag_value_behavior_; }
|
||||
void SetDragValueBehavior(DragValueBehavior d) { drag_value_behavior_ = d; }
|
||||
|
||||
signals:
|
||||
void HandleStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time);
|
||||
|
||||
void HandleMovement(double x, double y, const Qt::KeyboardModifiers &modifiers);
|
||||
|
||||
private:
|
||||
QVector<NodeKeyframeTrackReference> inputs_;
|
||||
|
||||
QVector<NodeInputDragger> draggers_;
|
||||
|
||||
DragValueBehavior drag_value_behavior_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DRAGGABLEGIZMO_H
|
||||
@@ -0,0 +1,30 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "gizmo.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
NodeGizmo::NodeGizmo(QObject *parent)
|
||||
{
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef NODEGIZMO_H
|
||||
#define NODEGIZMO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
#include "node/globals.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class NodeGizmo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NodeGizmo(QObject *parent = nullptr);
|
||||
|
||||
virtual void Draw(QPainter *p) const {}
|
||||
|
||||
const NodeGlobals &GetGlobals() const { return globals_; }
|
||||
void SetGlobals(const NodeGlobals &globals) { globals_ = globals; }
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
NodeGlobals globals_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEGIZMO_H
|
||||
@@ -0,0 +1,38 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "line.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
LineGizmo::LineGizmo(QObject *parent) :
|
||||
NodeGizmo(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void LineGizmo::Draw(QPainter *p) const
|
||||
{
|
||||
p->setBrush(Qt::NoBrush);
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
|
||||
p->drawLine(line_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef LINEGIZMO_H
|
||||
#define LINEGIZMO_H
|
||||
|
||||
#include <QLineF>
|
||||
|
||||
#include "gizmo.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class LineGizmo : public NodeGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LineGizmo(QObject *parent = nullptr);
|
||||
|
||||
const QLineF &GetLine() const { return line_; }
|
||||
void SetLine(const QLineF &line) { line_ = line; }
|
||||
|
||||
virtual void Draw(QPainter *p) const override;
|
||||
|
||||
private:
|
||||
QLineF line_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LINEGIZMO_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "path.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
PathGizmo::PathGizmo(QObject *parent) :
|
||||
DraggableGizmo{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PathGizmo::Draw(QPainter *p) const
|
||||
{
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
p->setBrush(Qt::NoBrush);
|
||||
|
||||
p->drawPath(path_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef PATHGIZMO_H
|
||||
#define PATHGIZMO_H
|
||||
|
||||
#include <QPainterPath>
|
||||
|
||||
#include "draggable.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class PathGizmo : public DraggableGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PathGizmo(QObject *parent = nullptr);
|
||||
|
||||
const QPainterPath &GetPath() const { return path_; }
|
||||
void SetPath(const QPainterPath &path) { path_ = path; }
|
||||
|
||||
virtual void Draw(QPainter *p) const override;
|
||||
|
||||
private:
|
||||
QPainterPath path_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PATHGIZMO_H
|
||||
@@ -0,0 +1,99 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "point.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
namespace olive {
|
||||
|
||||
PointGizmo::PointGizmo(const Shape &shape, bool smaller, QObject *parent) :
|
||||
DraggableGizmo{parent},
|
||||
shape_(shape),
|
||||
smaller_(smaller)
|
||||
{
|
||||
}
|
||||
|
||||
PointGizmo::PointGizmo(const Shape &shape, QObject *parent) :
|
||||
PointGizmo(shape, false, parent)
|
||||
{
|
||||
}
|
||||
|
||||
PointGizmo::PointGizmo(QObject *parent) :
|
||||
PointGizmo(kSquare, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void PointGizmo::Draw(QPainter *p) const
|
||||
{
|
||||
QRectF rect = GetDrawingRect(GetStandardRadius() / p->transform().m11());
|
||||
|
||||
if (shape_ != kAnchorPoint) {
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(Qt::white);
|
||||
}
|
||||
|
||||
switch (shape_) {
|
||||
case kSquare:
|
||||
p->drawRect(rect);
|
||||
break;
|
||||
case kCircle:
|
||||
p->drawEllipse(rect);
|
||||
break;
|
||||
case kAnchorPoint:
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
p->setBrush(Qt::NoBrush);
|
||||
|
||||
p->drawEllipse(rect);
|
||||
p->drawLines({QPointF(rect.left(), rect.center().y()),
|
||||
QPointF(rect.right(), rect.center().y()),
|
||||
QPointF(rect.center().x(), rect.top()),
|
||||
QPointF(rect.center().x(), rect.bottom())});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QRectF PointGizmo::GetClickingRect(const QTransform &t) const
|
||||
{
|
||||
return GetDrawingRect(GetStandardRadius() / t.m11() * 1.5);
|
||||
}
|
||||
|
||||
double PointGizmo::GetStandardRadius()
|
||||
{
|
||||
return QFontMetrics(qApp->font()).height() * 0.25;
|
||||
}
|
||||
|
||||
QRectF PointGizmo::GetDrawingRect(double radius) const
|
||||
{
|
||||
if (shape_ == kAnchorPoint) {
|
||||
radius *= 2;
|
||||
}
|
||||
|
||||
if (smaller_) {
|
||||
radius *= 0.5;
|
||||
}
|
||||
|
||||
return QRectF(point_.x() - radius,
|
||||
point_.y() - radius,
|
||||
2*radius,
|
||||
2*radius);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef POINTGIZMO_H
|
||||
#define POINTGIZMO_H
|
||||
|
||||
#include <QPointF>
|
||||
|
||||
#include "draggable.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class PointGizmo : public DraggableGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Shape {
|
||||
kSquare,
|
||||
kCircle,
|
||||
kAnchorPoint
|
||||
};
|
||||
|
||||
explicit PointGizmo(const Shape &shape, bool smaller, QObject *parent = nullptr);
|
||||
explicit PointGizmo(const Shape &shape, QObject *parent = nullptr);
|
||||
explicit PointGizmo(QObject *parent = nullptr);
|
||||
|
||||
const Shape &GetShape() const { return shape_; }
|
||||
void SetShape(const Shape &s) { shape_ = s; }
|
||||
|
||||
const QPointF &GetPoint() const { return point_; }
|
||||
void SetPoint(const QPointF &pt) { point_ = pt; }
|
||||
|
||||
bool GetSmaller() const { return smaller_; }
|
||||
void SetSmaller(bool e) { smaller_ = e; }
|
||||
|
||||
virtual void Draw(QPainter *p) const override;
|
||||
|
||||
QRectF GetClickingRect(const QTransform &t) const;
|
||||
|
||||
private:
|
||||
static double GetStandardRadius();
|
||||
|
||||
QRectF GetDrawingRect(double radius) const;
|
||||
|
||||
Shape shape_;
|
||||
|
||||
QPointF point_;
|
||||
|
||||
bool smaller_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // POINTGIZMO_H
|
||||
@@ -0,0 +1,38 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "polygon.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
PolygonGizmo::PolygonGizmo(QObject *parent)
|
||||
: DraggableGizmo{parent}
|
||||
{
|
||||
}
|
||||
|
||||
void PolygonGizmo::Draw(QPainter *p) const
|
||||
{
|
||||
p->setPen(QPen(Qt::white, 0));
|
||||
p->setBrush(Qt::NoBrush);
|
||||
|
||||
p->drawPolyline(polygon_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef POLYGONGIZMO_H
|
||||
#define POLYGONGIZMO_H
|
||||
|
||||
#include <QPolygonF>
|
||||
|
||||
#include "draggable.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class PolygonGizmo : public DraggableGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PolygonGizmo(QObject *parent = nullptr);
|
||||
|
||||
const QPolygonF &GetPolygon() const { return polygon_; }
|
||||
void SetPolygon(const QPolygonF &polygon) { polygon_ = polygon; }
|
||||
|
||||
virtual void Draw(QPainter *p) const override;
|
||||
|
||||
private:
|
||||
QPolygonF polygon_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // POLYGONGIZMO_H
|
||||
@@ -0,0 +1,31 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
ScreenGizmo::ScreenGizmo(QObject *parent)
|
||||
: DraggableGizmo{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef SCREENGIZMO_H
|
||||
#define SCREENGIZMO_H
|
||||
|
||||
#include "draggable.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class ScreenGizmo : public DraggableGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScreenGizmo(QObject *parent = nullptr);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SCREENGIZMO_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "text.h"
|
||||
|
||||
#include "core.h"
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
TextGizmo::TextGizmo(QObject *parent)
|
||||
: NodeGizmo{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TextGizmo::UpdateInputHtml(const QString &s, const rational &time)
|
||||
{
|
||||
if (input_.IsValid()) {
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
Node::SetValueAtTime(input_.input(), time, s, input_.track(), command, true);
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2021 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGIZMO_H
|
||||
#define TEXTGIZMO_H
|
||||
|
||||
#include "gizmo.h"
|
||||
#include "node/param.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGizmo : public NodeGizmo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextGizmo(QObject *parent = nullptr);
|
||||
|
||||
const QRectF &GetRect() const { return rect_; }
|
||||
void SetRect(const QRectF &r) { rect_ = r; }
|
||||
|
||||
const QString &GetHtml() const { return text_; }
|
||||
void SetHtml(const QString &t) { text_ = t; }
|
||||
|
||||
void SetInput(const NodeKeyframeTrackReference &input) { input_ = input; }
|
||||
|
||||
void UpdateInputHtml(const QString &s, const rational &time);
|
||||
|
||||
private:
|
||||
QRectF rect_;
|
||||
|
||||
QString text_;
|
||||
|
||||
NodeKeyframeTrackReference input_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGIZMO_H
|
||||
@@ -30,6 +30,8 @@ namespace olive {
|
||||
class NodeGlobals
|
||||
{
|
||||
public:
|
||||
NodeGlobals(){}
|
||||
|
||||
NodeGlobals(const QVector2D &resolution, const rational &pixel_aspect, const TimeRange &time) :
|
||||
resolution_(resolution),
|
||||
pixel_aspect_(pixel_aspect),
|
||||
|
||||
@@ -51,6 +51,16 @@ public:
|
||||
return start_value_;
|
||||
}
|
||||
|
||||
const NodeKeyframeTrackReference &GetInput() const
|
||||
{
|
||||
return input_;
|
||||
}
|
||||
|
||||
const rational &GetTime() const
|
||||
{
|
||||
return time_;
|
||||
}
|
||||
|
||||
private:
|
||||
NodeKeyframeTrackReference input_;
|
||||
|
||||
|
||||
+45
-58
@@ -1248,28 +1248,6 @@ void Node::IgnoreHashingFrom(const QString &input_id)
|
||||
ignore_when_hashing_.append(input_id);
|
||||
}
|
||||
|
||||
bool Node::HasGizmos() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Node::DrawGizmos(const NodeValueRow &, const NodeGlobals &, QPainter *)
|
||||
{
|
||||
}
|
||||
|
||||
bool Node::GizmoPress(const NodeValueRow &, const NodeGlobals &, const QPointF &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Node::GizmoMove(const QPointF &, const rational&, const Qt::KeyboardModifiers &)
|
||||
{
|
||||
}
|
||||
|
||||
void Node::GizmoRelease(MultiUndoCommand *)
|
||||
{
|
||||
}
|
||||
|
||||
const QString &Node::GetLabel() const
|
||||
{
|
||||
return label_;
|
||||
@@ -1760,39 +1738,6 @@ void Node::ClearElement(const QString& input, int index)
|
||||
SetSplitStandardValue(input, GetSplitDefaultValue(input), index);
|
||||
}
|
||||
|
||||
QRectF Node::CreateGizmoHandleRect(const QPointF &pt, int radius)
|
||||
{
|
||||
return QRectF(pt.x() - radius,
|
||||
pt.y() - radius,
|
||||
2*radius,
|
||||
2*radius);
|
||||
}
|
||||
|
||||
double Node::GetGizmoHandleRadius(const QTransform &transform)
|
||||
{
|
||||
double raw_value = QFontMetrics(qApp->font()).height() * 0.25;
|
||||
|
||||
raw_value /= transform.m11();
|
||||
|
||||
return raw_value;
|
||||
}
|
||||
|
||||
void Node::DrawAndExpandGizmoHandles(QPainter *p, int handle_radius, QRectF *rects, int count)
|
||||
{
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(Qt::white);
|
||||
|
||||
for (int i=0; i<count; i++) {
|
||||
QRectF& r = rects[i];
|
||||
|
||||
// Draw rect on screen
|
||||
p->drawRect(r);
|
||||
|
||||
// Extend rect so it's easier to drag with handle
|
||||
r.adjust(-handle_radius, -handle_radius, handle_radius, handle_radius);
|
||||
}
|
||||
}
|
||||
|
||||
void Node::InputValueChangedEvent(const QString &input, int element)
|
||||
{
|
||||
Q_UNUSED(input)
|
||||
@@ -1827,9 +1772,7 @@ void Node::childEvent(QChildEvent *event)
|
||||
{
|
||||
super::childEvent(event);
|
||||
|
||||
NodeKeyframe* key = dynamic_cast<NodeKeyframe*>(event->child());
|
||||
|
||||
if (key) {
|
||||
if (NodeKeyframe* key = dynamic_cast<NodeKeyframe*>(event->child())) {
|
||||
NodeInput i(this, key->input(), key->element());
|
||||
|
||||
if (event->type() == QEvent::ChildAdded) {
|
||||
@@ -1857,6 +1800,12 @@ void Node::childEvent(QChildEvent *event)
|
||||
GetImmediate(key->input(), key->element())->remove_keyframe(key);
|
||||
ParameterValueChanged(i, time_affected);
|
||||
}
|
||||
} else if (NodeGizmo *gizmo = dynamic_cast<NodeGizmo*>(event->child())) {
|
||||
if (event->type() == QEvent::ChildAdded) {
|
||||
gizmos_.append(gizmo);
|
||||
} else if (event->type() == QEvent::ChildRemoved) {
|
||||
gizmos_.removeOne(gizmo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1945,6 +1894,44 @@ void Node::InvalidateFromKeyframeTypeChanged()
|
||||
emit KeyframeTypeChanged(key);
|
||||
}
|
||||
|
||||
void Node::SetValueAtTime(const NodeInput &input, const rational &time, const QVariant &value, int track, MultiUndoCommand *command, bool insert_on_all_tracks_if_no_key)
|
||||
{
|
||||
if (input.IsKeyframing()) {
|
||||
rational node_time = time;
|
||||
|
||||
NodeKeyframe* existing_key = input.GetKeyframeAtTimeOnTrack(node_time, track);
|
||||
|
||||
if (existing_key) {
|
||||
command->add_child(new NodeParamSetKeyframeValueCommand(existing_key, value));
|
||||
} else {
|
||||
// No existing key, create a new one
|
||||
int nb_tracks = NodeValue::get_number_of_keyframe_tracks(input.node()->GetInputDataType(input.input()));
|
||||
for (int i=0; i<nb_tracks; i++) {
|
||||
QVariant track_value;
|
||||
|
||||
if (i == track) {
|
||||
track_value = value;
|
||||
} else if (!insert_on_all_tracks_if_no_key) {
|
||||
continue;
|
||||
} else {
|
||||
track_value = input.node()->GetSplitValueAtTimeOnTrack(input.input(), node_time, i, input.element());
|
||||
}
|
||||
|
||||
NodeKeyframe* new_key = new NodeKeyframe(node_time,
|
||||
track_value,
|
||||
input.node()->GetBestKeyframeTypeForTimeOnTrack(NodeKeyframeTrackReference(input, i), node_time),
|
||||
i,
|
||||
input.element(),
|
||||
input.input());
|
||||
|
||||
command->add_child(new NodeParamInsertKeyframeCommand(input.node(), new_key));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(input, track), value));
|
||||
}
|
||||
}
|
||||
|
||||
Project *Node::ArrayInsertCommand::GetRelevantProject() const
|
||||
{
|
||||
return node_->project();
|
||||
|
||||
+42
-11
@@ -35,6 +35,7 @@
|
||||
#include "common/rational.h"
|
||||
#include "common/timerange.h"
|
||||
#include "common/xmlutils.h"
|
||||
#include "node/gizmo/draggable.h"
|
||||
#include "node/globals.h"
|
||||
#include "node/keyframe.h"
|
||||
#include "node/inputimmediate.h"
|
||||
@@ -840,13 +841,17 @@ public:
|
||||
*/
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const;
|
||||
|
||||
virtual bool HasGizmos() const;
|
||||
bool HasGizmos() const
|
||||
{
|
||||
return !gizmos_.isEmpty();
|
||||
}
|
||||
|
||||
virtual void DrawGizmos(const NodeValueRow& row, const NodeGlobals &globals, QPainter* p);
|
||||
const QVector<NodeGizmo*> &GetGizmos() const
|
||||
{
|
||||
return gizmos_;
|
||||
}
|
||||
|
||||
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF& p);
|
||||
virtual void GizmoMove(const QPointF& p, const rational &time, const Qt::KeyboardModifiers &modifiers);
|
||||
virtual void GizmoRelease(MultiUndoCommand *command);
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals){}
|
||||
|
||||
const QString& GetLabel() const;
|
||||
void SetLabel(const QString& s);
|
||||
@@ -942,6 +947,8 @@ public:
|
||||
|
||||
InputFlags GetInputFlags(const QString& input) const;
|
||||
|
||||
static void SetValueAtTime(const NodeInput &input, const rational &time, const QVariant &value, int track, MultiUndoCommand *command, bool insert_on_all_tracks_if_no_key);
|
||||
|
||||
protected:
|
||||
virtual void Hash(QCryptographicHash& hash, const NodeGlobals &globals, const VideoParams& video_params) const;
|
||||
|
||||
@@ -1008,12 +1015,6 @@ protected:
|
||||
kGizmoScaleCount,
|
||||
};
|
||||
|
||||
static QRectF CreateGizmoHandleRect(const QPointF& pt, int radius);
|
||||
|
||||
static double GetGizmoHandleRadius(const QTransform& transform);
|
||||
|
||||
static void DrawAndExpandGizmoHandles(QPainter* p, int handle_radius, QRectF* rects, int count);
|
||||
|
||||
virtual void LinkChangeEvent(){}
|
||||
|
||||
virtual void InputValueChangedEvent(const QString& input, int element);
|
||||
@@ -1038,6 +1039,34 @@ protected:
|
||||
flags_ = f;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *AddDraggableGizmo(const QVector<NodeKeyframeTrackReference> &inputs = QVector<NodeKeyframeTrackReference>(), DraggableGizmo::DragValueBehavior behavior = DraggableGizmo::kDeltaFromStart)
|
||||
{
|
||||
T *gizmo = new T(this);
|
||||
gizmo->SetDragValueBehavior(behavior);
|
||||
foreach (const NodeKeyframeTrackReference &input, inputs) {
|
||||
gizmo->AddInput(input);
|
||||
}
|
||||
connect(gizmo, &DraggableGizmo::HandleStart, this, &Node::GizmoDragStart);
|
||||
connect(gizmo, &DraggableGizmo::HandleMovement, this, &Node::GizmoDragMove);
|
||||
return gizmo;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *AddDraggableGizmo(const QStringList &inputs, DraggableGizmo::DragValueBehavior behavior = DraggableGizmo::kDeltaFromStart)
|
||||
{
|
||||
QVector<NodeKeyframeTrackReference> refs(inputs.size());
|
||||
for (int i=0; i<refs.size(); i++) {
|
||||
refs[i] = NodeInput(this, inputs[i]);
|
||||
}
|
||||
return AddDraggableGizmo<T>(refs, behavior);
|
||||
}
|
||||
|
||||
protected slots:
|
||||
virtual void GizmoDragStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time){}
|
||||
|
||||
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers){}
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when SetLabel() is called
|
||||
@@ -1315,6 +1344,8 @@ private:
|
||||
|
||||
uint64_t flags_;
|
||||
|
||||
QVector<NodeGizmo*> gizmos_;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief Slot when a keyframe's time changes to keep the keyframes correctly sorted by time
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class Node;
|
||||
|
||||
Reference in New Issue
Block a user