change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+75 -69
View File
@@ -25,136 +25,142 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString MatrixGenerator::kPositionInput = QStringLiteral("pos_in");
const QString MatrixGenerator::kRotationInput = QStringLiteral("rot_in");
const QString MatrixGenerator::kScaleInput = QStringLiteral("scale_in");
const QString MatrixGenerator::kUniformScaleInput = QStringLiteral("uniform_scale_in");
const QString MatrixGenerator::kUniformScaleInput =
QStringLiteral("uniform_scale_in");
const QString MatrixGenerator::kAnchorInput = QStringLiteral("anchor_in");
#define super Node
MatrixGenerator::MatrixGenerator()
{
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kRotationInput, NodeValue::kFloat, 0.0);
AddInput(kRotationInput, NodeValue::kFloat, 0.0);
AddInput(kScaleInput, NodeValue::kVec2, QVector2D(1.0f, 1.0f));
SetInputProperty(kScaleInput, QStringLiteral("min"), QVector2D(0, 0));
SetInputProperty(kScaleInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kScaleInput, QStringLiteral("disable1"), true);
AddInput(kScaleInput, NodeValue::kVec2, QVector2D(1.0f, 1.0f));
SetInputProperty(kScaleInput, QStringLiteral("min"), QVector2D(0, 0));
SetInputProperty(kScaleInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kScaleInput, QStringLiteral("disable1"), true);
AddInput(kUniformScaleInput, NodeValue::kBoolean, true, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kUniformScaleInput, NodeValue::kBoolean, true,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kAnchorInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kAnchorInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
}
QString MatrixGenerator::Name() const
{
return tr("Orthographic Matrix");
return tr("Orthographic Matrix");
}
QString MatrixGenerator::ShortName() const
{
return tr("Ortho");
return tr("Ortho");
}
QString MatrixGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.ortho");
return QStringLiteral("org.olivevideoeditor.Olive.ortho");
}
QVector<Node::CategoryID> MatrixGenerator::Category() const
{
return {kCategoryGenerator, kCategoryMath};
return { kCategoryGenerator, kCategoryMath };
}
QString MatrixGenerator::Description() const
{
return tr("Generate an orthographic matrix using position, rotation, and scale.");
return tr(
"Generate an orthographic matrix using position, rotation, and scale.");
}
void MatrixGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPositionInput, tr("Position"));
SetInputName(kRotationInput, tr("Rotation"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kUniformScaleInput, tr("Uniform Scale"));
SetInputName(kAnchorInput, tr("Anchor Point"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kRotationInput, tr("Rotation"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kUniformScaleInput, tr("Uniform Scale"));
SetInputName(kAnchorInput, tr("Anchor Point"));
}
void MatrixGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void MatrixGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value, false, false, false, QMatrix4x4());
table->Push(NodeValue::kMatrix, mat, this);
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value, false, false, false, QMatrix4x4());
table->Push(NodeValue::kMatrix, mat, this);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value,
bool ignore_anchor,
bool ignore_position,
bool ignore_scale,
const QMatrix4x4 &mat) const
{
QVector2D anchor;
QVector2D position;
QVector2D scale;
QVector2D anchor;
QVector2D position;
QVector2D scale;
if (!ignore_anchor) {
anchor = value[kAnchorInput].toVec2();
}
if (!ignore_anchor) {
anchor = value[kAnchorInput].toVec2();
}
if (!ignore_scale) {
scale = value[kScaleInput].toVec2();
}
if (!ignore_scale) {
scale = value[kScaleInput].toVec2();
}
if (!ignore_position) {
position = value[kPositionInput].toVec2();
}
if (!ignore_position) {
position = value[kPositionInput].toVec2();
}
return GenerateMatrix(position,
value[kRotationInput].toDouble(),
scale,
value[kUniformScaleInput].toBool(),
anchor,
mat);
return GenerateMatrix(position, value[kRotationInput].toDouble(), scale,
value[kUniformScaleInput].toBool(), anchor, mat);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const QVector2D& pos,
const float& rot,
const QVector2D& scale,
bool uniform_scale,
const QVector2D& anchor,
QMatrix4x4 mat)
QMatrix4x4
MatrixGenerator::GenerateMatrix(const QVector2D &pos, const float &rot,
const QVector2D &scale, bool uniform_scale,
const QVector2D &anchor, QMatrix4x4 mat)
{
// Position
mat.translate(pos.x(), pos.y());
// Position
mat.translate(pos.x(), pos.y());
// Rotation
mat.rotate(rot, 0, 0, 1);
// Rotation
mat.rotate(rot, 0, 0, 1);
// Scale (convert to a QVector3D so that the identity matrix is preserved if all values are 1.0f)
QVector3D full_scale;
if (uniform_scale) {
full_scale = QVector3D(scale.x(), scale.x(), 1.0f);
} else {
full_scale = QVector3D(scale, 1.0f);
}
mat.scale(full_scale);
// Scale (convert to a QVector3D so that the identity matrix is preserved if all values are 1.0f)
QVector3D full_scale;
if (uniform_scale) {
full_scale = QVector3D(scale.x(), scale.x(), 1.0f);
} else {
full_scale = QVector3D(scale, 1.0f);
}
mat.scale(full_scale);
// Anchor Point
mat.translate(-anchor.x(), -anchor.y());
// Anchor Point
mat.translate(-anchor.x(), -anchor.y());
return mat;
return mat;
}
void MatrixGenerator::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element)
Q_UNUSED(element)
if (input == kUniformScaleInput) {
SetInputProperty(kScaleInput, QStringLiteral("disable1"), GetStandardValue(kUniformScaleInput).toBool());
}
if (input == kUniformScaleInput) {
SetInputProperty(kScaleInput, QStringLiteral("disable1"),
GetStandardValue(kUniformScaleInput).toBool());
}
}
}
+27 -27
View File
@@ -26,43 +26,43 @@
#include "node/node.h"
#include "node/inputdragger.h"
namespace olive {
class MatrixGenerator : public Node
namespace olive
{
Q_OBJECT
class MatrixGenerator : public Node {
Q_OBJECT
public:
MatrixGenerator();
MatrixGenerator();
NODE_DEFAULT_FUNCTIONS(MatrixGenerator)
NODE_DEFAULT_FUNCTIONS(MatrixGenerator)
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kPositionInput;
static const QString kRotationInput;
static const QString kScaleInput;
static const QString kUniformScaleInput;
static const QString kAnchorInput;
static const QString kPositionInput;
static const QString kRotationInput;
static const QString kScaleInput;
static const QString kUniformScaleInput;
static const QString kAnchorInput;
protected:
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const;
static QMatrix4x4 GenerateMatrix(const QVector2D &pos,
const float &rot,
const QVector2D &scale,
bool uniform_scale,
const QVector2D &anchor,
QMatrix4x4 mat);
virtual void InputValueChangedEvent(const QString& input, int element) override;
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor,
bool ignore_position, bool ignore_scale,
const QMatrix4x4 &mat) const;
static QMatrix4x4 GenerateMatrix(const QVector2D &pos, const float &rot,
const QVector2D &scale, bool uniform_scale,
const QVector2D &anchor, QMatrix4x4 mat);
virtual void InputValueChangedEvent(const QString &input,
int element) override;
};
}
+34 -24
View File
@@ -22,71 +22,81 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString NoiseGeneratorNode::kBaseIn = QStringLiteral("base_in");
const QString NoiseGeneratorNode::kColorInput = QStringLiteral("color_in");
const QString NoiseGeneratorNode::kStrengthInput = QStringLiteral("strength_in");
const QString NoiseGeneratorNode::kStrengthInput =
QStringLiteral("strength_in");
#define super Node
NoiseGeneratorNode::NoiseGeneratorNode()
{
AddInput(kBaseIn, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kBaseIn, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kStrengthInput, NodeValue::kFloat, 0.2);
SetInputProperty(kStrengthInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kStrengthInput, QStringLiteral("min"), 0);
AddInput(kStrengthInput, NodeValue::kFloat, 0.2);
SetInputProperty(kStrengthInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kStrengthInput, QStringLiteral("min"), 0);
AddInput(kColorInput, NodeValue::kBoolean, false);
AddInput(kColorInput, NodeValue::kBoolean, false);
SetEffectInput(kBaseIn);
SetFlag(kVideoEffect);
SetEffectInput(kBaseIn);
SetFlag(kVideoEffect);
}
QString NoiseGeneratorNode::Name() const
{
return tr("Noise");
return tr("Noise");
}
QString NoiseGeneratorNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.noise");
return QStringLiteral("org.olivevideoeditor.Olive.noise");
}
QVector<Node::CategoryID> NoiseGeneratorNode::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString NoiseGeneratorNode::Description() const
{
return tr("Generates noise patterns");
return tr("Generates noise patterns");
}
void NoiseGeneratorNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBaseIn, tr("Base"));
SetInputName(kStrengthInput, tr("Strength"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kBaseIn, tr("Base"));
SetInputName(kStrengthInput, tr("Strength"));
SetInputName(kColorInput, tr("Color"));
}
ShaderCode NoiseGeneratorNode::GetShaderCode(const ShaderRequest &request) const
{
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/noise.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/noise.frag"));
}
void NoiseGeneratorNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void NoiseGeneratorNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
ShaderJob job(value);
ShaderJob job(value);
job.Insert(value);
job.Insert(QStringLiteral("time_in"), NodeValue(NodeValue::kFloat, globals.time().in().toDouble(), this));
job.Insert(value);
job.Insert(QStringLiteral("time_in"),
NodeValue(NodeValue::kFloat, globals.time().in().toDouble(),
this));
TexturePtr base = value[kBaseIn].toTexture();
TexturePtr base = value[kBaseIn].toTexture();
table->Push(NodeValue::kTexture, Texture::Job(base ? base->params() : globals.vparams(), job), this);
table->Push(NodeValue::kTexture,
Texture::Job(base ? base->params() : globals.vparams(), job),
this);
}
}
+20 -18
View File
@@ -23,31 +23,33 @@
#include "node/node.h"
namespace olive {
namespace olive
{
class NoiseGeneratorNode : public Node {
Q_OBJECT
public:
NoiseGeneratorNode();
Q_OBJECT
public:
NoiseGeneratorNode();
NODE_DEFAULT_FUNCTIONS(NoiseGeneratorNode)
NODE_DEFAULT_FUNCTIONS(NoiseGeneratorNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kBaseIn;
static const QString kColorInput;
static const QString kStrengthInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kBaseIn;
static const QString kColorInput;
static const QString kStrengthInput;
};
} // namespace olive
} // namespace olive
#endif // NOISEGENERATORNODE_H
#endif // NOISEGENERATORNODE_H
+180 -153
View File
@@ -23,7 +23,8 @@
#include <QGuiApplication>
#include <QVector2D>
namespace olive {
namespace olive
{
const QString PolygonGenerator::kPointsInput = QStringLiteral("points_in");
const QString PolygonGenerator::kColorInput = QStringLiteral("color_in");
@@ -32,244 +33,270 @@ const QString PolygonGenerator::kColorInput = QStringLiteral("color_in");
PolygonGenerator::PolygonGenerator()
{
AddInput(kPointsInput, NodeValue::kBezier, QVector2D(0, 0), InputFlags(kInputFlagArray));
AddInput(kPointsInput, NodeValue::kBezier, QVector2D(0, 0),
InputFlags(kInputFlagArray));
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0, 1.0, 1.0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0, 1.0, 1.0)));
const int kMiddleX = 135;
const int kMiddleY = 45;
const int kBottomX = 90;
const int kBottomY = 120;
const int kTopY = 135;
const int kMiddleX = 135;
const int kMiddleY = 45;
const int kBottomX = 90;
const int kBottomY = 120;
const int kTopY = 135;
// The Default Pentagon(tm)
InputArrayResize(kPointsInput, 5);
SetSplitStandardValueOnTrack(kPointsInput, 0, 0, 0);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kTopY, 0);
SetSplitStandardValueOnTrack(kPointsInput, 0, kMiddleX, 1);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 1);
SetSplitStandardValueOnTrack(kPointsInput, 0, kBottomX, 2);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 2);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kBottomX, 3);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 3);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kMiddleX, 4);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 4);
// The Default Pentagon(tm)
InputArrayResize(kPointsInput, 5);
SetSplitStandardValueOnTrack(kPointsInput, 0, 0, 0);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kTopY, 0);
SetSplitStandardValueOnTrack(kPointsInput, 0, kMiddleX, 1);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 1);
SetSplitStandardValueOnTrack(kPointsInput, 0, kBottomX, 2);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 2);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kBottomX, 3);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 3);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kMiddleX, 4);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 4);
// Initiate gizmos
poly_gizmo_ = new PathGizmo(this);
// Initiate gizmos
poly_gizmo_ = new PathGizmo(this);
}
QString PolygonGenerator::Name() const
{
return tr("Polygon");
return tr("Polygon");
}
QString PolygonGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.polygon");
return QStringLiteral("org.olivevideoeditor.Olive.polygon");
}
QVector<Node::CategoryID> PolygonGenerator::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString PolygonGenerator::Description() const
{
return tr("Generate a 2D polygon of any amount of points.");
return tr("Generate a 2D polygon of any amount of points.");
}
void PolygonGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPointsInput, tr("Points"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kPointsInput, tr("Points"));
SetInputName(kColorInput, tr("Color"));
}
ShaderJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value, const VideoParams &params) const
ShaderJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value,
const VideoParams &params) const
{
VideoParams p = params;
p.set_format(PixelFormat::U8);
auto job = Texture::Job(p, GenerateJob(value));
VideoParams p = params;
p.set_format(PixelFormat::U8);
auto job = Texture::Job(p, GenerateJob(value));
// Conversion to RGB
ShaderJob rgb;
rgb.SetShaderID(QStringLiteral("rgb"));
rgb.Insert(QStringLiteral("texture_in"), NodeValue(NodeValue::kTexture, job, this));
rgb.Insert(QStringLiteral("color_in"), value[kColorInput]);
// Conversion to RGB
ShaderJob rgb;
rgb.SetShaderID(QStringLiteral("rgb"));
rgb.Insert(QStringLiteral("texture_in"),
NodeValue(NodeValue::kTexture, job, this));
rgb.Insert(QStringLiteral("color_in"), value[kColorInput]);
return rgb;
return rgb;
}
void PolygonGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void PolygonGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
PushMergableJob(value, Texture::Job(globals.vparams(), GetGenerateJob(value, globals.vparams())), table);
PushMergableJob(value,
Texture::Job(globals.vparams(),
GetGenerateJob(value, globals.vparams())),
table);
}
void PolygonGenerator::GenerateFrame(FramePtr frame, const GenerateJob &job) const
void PolygonGenerator::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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img((uchar *) frame->data(), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
// 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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img((uchar *)frame->data(), frame->width(), frame->height(),
frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
auto points = job.Get(kPointsInput).toArray();
auto points = job.Get(kPointsInput).toArray();
QPainterPath path = GeneratePath(points, InputArraySize(kPointsInput));
QPainterPath path = GeneratePath(points, InputArraySize(kPointsInput));
QPainter p(&img);
double par = frame->video_params().pixel_aspect_ratio().toDouble();
p.scale(1.0 / frame->video_params().divider() / par, 1.0 / frame->video_params().divider());
p.translate(frame->video_params().width()/2 * par, frame->video_params().height()/2);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
QPainter p(&img);
double par = frame->video_params().pixel_aspect_ratio().toDouble();
p.scale(1.0 / frame->video_params().divider() / par,
1.0 / frame->video_params().divider());
p.translate(frame->video_params().width() / 2 * par,
frame->video_params().height() / 2);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
p.drawPath(path);
p.drawPath(path);
}
template<typename T>
NodeGizmo *PolygonGenerator::CreateAppropriateGizmo()
template <typename T> NodeGizmo *PolygonGenerator::CreateAppropriateGizmo()
{
return new T(this);
return new T(this);
}
template<>
NodeGizmo *PolygonGenerator::CreateAppropriateGizmo<PointGizmo>()
template <> NodeGizmo *PolygonGenerator::CreateAppropriateGizmo<PointGizmo>()
{
return AddDraggableGizmo<PointGizmo>();
return AddDraggableGizmo<PointGizmo>();
}
template<typename T>
void PolygonGenerator::ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz)
template <typename T>
void PolygonGenerator::ValidateGizmoVectorSize(QVector<T *> &vec, int new_sz)
{
int old_sz = vec.size();
int old_sz = vec.size();
if (old_sz != new_sz) {
if (old_sz > new_sz) {
for (int i=new_sz; i<old_sz; i++) {
delete vec.at(i);
}
}
if (old_sz != new_sz) {
if (old_sz > new_sz) {
for (int i = new_sz; i < old_sz; i++) {
delete vec.at(i);
}
}
vec.resize(new_sz);
vec.resize(new_sz);
if (old_sz < new_sz) {
for (int i=old_sz; i<new_sz; i++) {
vec[i] = static_cast<T*>(CreateAppropriateGizmo<T>());
}
}
}
if (old_sz < new_sz) {
for (int i = old_sz; i < new_sz; i++) {
vec[i] = static_cast<T *>(CreateAppropriateGizmo<T>());
}
}
}
}
void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
QVector2D res;
if (TexturePtr tex = row[kBaseInput].toTexture()) {
res = tex->virtual_resolution();
} else {
res = globals.square_resolution();
}
QVector2D res;
if (TexturePtr tex = row[kBaseInput].toTexture()) {
res = tex->virtual_resolution();
} else {
res = globals.square_resolution();
}
Imath::V2d half_res(res.x()/2, res.y()/2);
Imath::V2d half_res(res.x() / 2, res.y() / 2);
auto points = row[kPointsInput].toArray();
auto points = row[kPointsInput].toArray();
int current_pos_sz = gizmo_position_handles_.size();
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);
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));
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_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);
}
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);
}
int pts_sz = InputArraySize(kPointsInput);
if (!points.empty()) {
for (int i=0; i<pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
int pts_sz = InputArraySize(kPointsInput);
if (!points.empty()) {
for (int i = 0; i < pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
Imath::V2d main = pt.to_vec() + half_res;
Imath::V2d cp1 = main + pt.control_point_1_to_vec();
Imath::V2d cp2 = main + pt.control_point_2_to_vec();
Imath::V2d main = pt.to_vec() + half_res;
Imath::V2d cp1 = main + pt.control_point_1_to_vec();
Imath::V2d cp2 = main + pt.control_point_2_to_vec();
gizmo_position_handles_[i]->SetPoint(QPointF(main.x, main.y));
gizmo_position_handles_[i]->SetPoint(QPointF(main.x, main.y));
gizmo_bezier_handles_[i*2]->SetPoint(QPointF(cp1.x, cp1.y));
gizmo_bezier_lines_[i*2]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp1.x, cp1.y)));
gizmo_bezier_handles_[i*2+1]->SetPoint(QPointF(cp2.x, cp2.y));
gizmo_bezier_lines_[i*2+1]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp2.x, cp2.y)));
}
}
gizmo_bezier_handles_[i * 2]->SetPoint(QPointF(cp1.x, cp1.y));
gizmo_bezier_lines_[i * 2]->SetLine(
QLineF(QPointF(main.x, main.y), QPointF(cp1.x, cp1.y)));
gizmo_bezier_handles_[i * 2 + 1]->SetPoint(QPointF(cp2.x, cp2.y));
gizmo_bezier_lines_[i * 2 + 1]->SetLine(
QLineF(QPointF(main.x, main.y), QPointF(cp2.x, cp2.y)));
}
}
poly_gizmo_->SetPath(GeneratePath(points, pts_sz).translated(QPointF(half_res.x, half_res.y)));
poly_gizmo_->SetPath(GeneratePath(points, pts_sz)
.translated(QPointF(half_res.x, half_res.y)));
}
ShaderCode PolygonGenerator::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("rgb")) {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/rgb.frag"));
} else {
return super::GetShaderCode(request);
}
if (request.id == QStringLiteral("rgb")) {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/rgb.frag"));
} else {
return super::GetShaderCode(request);
}
}
void PolygonGenerator::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void PolygonGenerator::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo == poly_gizmo_) {
// 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);
}
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);
}
}
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after)
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before,
const Bezier &after)
{
Imath::V2d a = before.to_vec() + before.control_point_2_to_vec();
Imath::V2d b = after.to_vec() + after.control_point_1_to_vec();
Imath::V2d c = after.to_vec();
Imath::V2d a = before.to_vec() + before.control_point_2_to_vec();
Imath::V2d b = after.to_vec() + after.control_point_1_to_vec();
Imath::V2d c = after.to_vec();
path->cubicTo(QPointF(a.x, a.y), QPointF(b.x, b.y), QPointF(c.x, c.y));
path->cubicTo(QPointF(a.x, a.y), QPointF(b.x, b.y), QPointF(c.x, c.y));
}
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points, int size)
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points,
int size)
{
QPainterPath path;
QPainterPath path;
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
Imath::V2d v = first_pt.to_vec();
path.moveTo(QPointF(v.x, v.y));
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
Imath::V2d v = first_pt.to_vec();
path.moveTo(QPointF(v.x, v.y));
for (int i=1; i<size; i++) {
AddPointToPath(&path, points.at(i-1).toBezier(), points.at(i).toBezier());
}
for (int i = 1; i < size; i++) {
AddPointToPath(&path, points.at(i - 1).toBezier(),
points.at(i).toBezier());
}
AddPointToPath(&path, points.at(size-1).toBezier(), first_pt);
}
AddPointToPath(&path, points.at(size - 1).toBezier(), first_pt);
}
return path;
return path;
}
}
+35 -30
View File
@@ -30,56 +30,61 @@
#include "node/node.h"
#include "node/inputdragger.h"
namespace olive {
class PolygonGenerator : public GeneratorWithMerge
namespace olive
{
Q_OBJECT
class PolygonGenerator : public GeneratorWithMerge {
Q_OBJECT
public:
PolygonGenerator();
PolygonGenerator();
NODE_DEFAULT_FUNCTIONS(PolygonGenerator)
NODE_DEFAULT_FUNCTIONS(PolygonGenerator)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kPointsInput;
static const QString kColorInput;
static const QString kPointsInput;
static const QString kColorInput;
protected:
ShaderJob GetGenerateJob(const NodeValueRow &value, const VideoParams &params) const;
ShaderJob GetGenerateJob(const NodeValueRow &value,
const VideoParams &params) const;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
static void AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after);
static void AddPointToPath(QPainterPath *path, const Bezier &before,
const Bezier &after);
static QPainterPath GeneratePath(const NodeValueArray &points, int size);
static QPainterPath GeneratePath(const NodeValueArray &points, int size);
template<typename T>
void ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz);
template <typename T>
void ValidateGizmoVectorSize(QVector<T *> &vec, int new_sz);
template<typename T>
NodeGizmo *CreateAppropriateGizmo();
PathGizmo *poly_gizmo_;
QVector<PointGizmo*> gizmo_position_handles_;
QVector<PointGizmo*> gizmo_bezier_handles_;
QVector<LineGizmo*> gizmo_bezier_lines_;
template <typename T> NodeGizmo *CreateAppropriateGizmo();
PathGizmo *poly_gizmo_;
QVector<PointGizmo *> gizmo_position_handles_;
QVector<PointGizmo *> gizmo_bezier_handles_;
QVector<LineGizmo *> gizmo_bezier_lines_;
};
}
+28 -22
View File
@@ -22,7 +22,8 @@
#include "node/math/merge/merge.h"
namespace olive {
namespace olive
{
#define super Node
@@ -30,42 +31,47 @@ const QString GeneratorWithMerge::kBaseInput = QStringLiteral("base_in");
GeneratorWithMerge::GeneratorWithMerge()
{
AddInput(kBaseInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
SetEffectInput(kBaseInput);
SetFlag(kVideoEffect);
AddInput(kBaseInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
SetEffectInput(kBaseInput);
SetFlag(kVideoEffect);
}
void GeneratorWithMerge::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBaseInput, tr("Base"));
SetInputName(kBaseInput, tr("Base"));
}
ShaderCode GeneratorWithMerge::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
}
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
}
return ShaderCode();
return ShaderCode();
}
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value,
TexturePtr job,
NodeValueTable *table) const
{
if (TexturePtr base = value[kBaseInput].toTexture()) {
// Push as merge node
ShaderJob merge;
if (TexturePtr base = value[kBaseInput].toTexture()) {
// Push as merge node
ShaderJob merge;
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
merge.Insert(MergeNode::kBlendIn, NodeValue(NodeValue::kTexture, job, this));
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
merge.Insert(MergeNode::kBlendIn,
NodeValue(NodeValue::kTexture, job, this));
table->Push(NodeValue::kTexture, base->toJob(merge), this);
} else {
// Just push generate job
table->Push(NodeValue::kTexture, job, this);
}
table->Push(NodeValue::kTexture, base->toJob(merge), this);
} else {
// Just push generate job
table->Push(NodeValue::kTexture, job, this);
}
}
}
+11 -10
View File
@@ -23,23 +23,24 @@
#include "node/node.h"
namespace olive {
class GeneratorWithMerge : public Node
namespace olive
{
Q_OBJECT
class GeneratorWithMerge : public Node {
Q_OBJECT
public:
GeneratorWithMerge();
GeneratorWithMerge();
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kBaseInput;
static const QString kBaseInput;
protected:
void PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const;
void PushMergableJob(const NodeValueRow &value, TexturePtr job,
NodeValueTable *table) const;
};
}
+40 -28
View File
@@ -20,7 +20,8 @@
#include "shapenode.h"
namespace olive {
namespace olive
{
#define super ShapeNodeBase
@@ -29,70 +30,81 @@ QString ShapeNode::kRadiusInput = QStringLiteral("radius_in");
ShapeNode::ShapeNode()
{
PrependInput(kTypeInput, NodeValue::kCombo);
PrependInput(kTypeInput, NodeValue::kCombo);
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
}
QString ShapeNode::Name() const
{
return tr("Shape");
return tr("Shape");
}
QString ShapeNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.shape");
return QStringLiteral("org.olivevideoeditor.Olive.shape");
}
QVector<Node::CategoryID> ShapeNode::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString ShapeNode::Description() const
{
return tr("Generate a 2D primitive shape.");
return tr("Generate a 2D primitive shape.");
}
void ShapeNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTypeInput, tr("Type"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kTypeInput, tr("Type"));
SetInputName(kRadiusInput, tr("Radius"));
// Coordinate with Type enum
SetComboBoxStrings(kTypeInput, {tr("Rectangle"), tr("Ellipse"), tr("Rounded Rectangle")});
// Coordinate with Type enum
SetComboBoxStrings(kTypeInput, { tr("Rectangle"), tr("Ellipse"),
tr("Rounded Rectangle") });
}
ShaderCode ShapeNode::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("shape")) {
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/shape.frag")));
} else {
return super::GetShaderCode(request);
}
if (request.id == QStringLiteral("shape")) {
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/shape.frag")));
} else {
return super::GetShaderCode(request);
}
}
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
TexturePtr base = value[kBaseInput].toTexture();
TexturePtr base = value[kBaseInput].toTexture();
ShaderJob job(value);
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, base ? base->virtual_resolution() : globals.square_resolution(), this));
job.SetShaderID(QStringLiteral("shape"));
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2,
base ? base->virtual_resolution() :
globals.square_resolution(),
this));
job.SetShaderID(QStringLiteral("shape"));
PushMergableJob(value, Texture::Job(base ? base->params() : globals.vparams(), job), table);
PushMergableJob(
value, Texture::Job(base ? base->params() : globals.vparams(), job),
table);
}
void ShapeNode::InputValueChangedEvent(const QString &input, int element)
{
if (input == kTypeInput) {
SetInputFlag(kRadiusInput, kInputFlagHidden, (GetStandardValue(kTypeInput).toInt() != kRoundedRectangle));
}
super::InputValueChangedEvent(input, element);
if (input == kTypeInput) {
SetInputFlag(kRadiusInput, kInputFlagHidden,
(GetStandardValue(kTypeInput).toInt() !=
kRoundedRectangle));
}
super::InputValueChangedEvent(input, element);
}
}
+20 -22
View File
@@ -23,38 +23,36 @@
#include "shapenodebase.h"
namespace olive {
class ShapeNode : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class ShapeNode : public ShapeNodeBase {
Q_OBJECT
public:
ShapeNode();
ShapeNode();
enum Type {
kRectangle,
kEllipse,
kRoundedRectangle
};
enum Type { kRectangle, kEllipse, kRoundedRectangle };
NODE_DEFAULT_FUNCTIONS(ShapeNode)
NODE_DEFAULT_FUNCTIONS(ShapeNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static QString kTypeInput;
static QString kRadiusInput;
static QString kTypeInput;
static QString kRadiusInput;
protected:
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
};
}
+238 -200
View File
@@ -27,7 +27,8 @@
#include "core.h"
#include "node/nodeundo.h"
namespace olive {
namespace olive
{
#define super GeneratorWithMerge
@@ -37,287 +38,324 @@ const QString ShapeNodeBase::kColorInput = QStringLiteral("color_in");
ShapeNodeBase::ShapeNodeBase(bool create_color_input)
{
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
if (create_color_input) {
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
}
if (create_color_input) {
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
}
// Initiate gizmos
QVector<NodeKeyframeTrackReference> pos_n_sz = {
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
};
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
for (int i=0; i<kGizmoScaleCount; i++) {
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
}
// Initiate gizmos
QVector<NodeKeyframeTrackReference> pos_n_sz = {
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
};
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
for (int i = 0; i < kGizmoScaleCount; i++) {
point_gizmo_[i] =
AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
}
}
void ShapeNodeBase::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPositionInput, tr("Position"));
SetInputName(kSizeInput, tr("Size"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kSizeInput, tr("Size"));
if (HasInputWithID(kColorInput)) {
SetInputName(kColorInput, tr("Color"));
}
if (HasInputWithID(kColorInput)) {
SetInputName(kColorInput, tr("Color"));
}
}
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
QVector2D center_pt = globals.square_resolution() * 0.5;
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
QVector2D center_pt = globals.square_resolution() * 0.5;
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
QVector2D pos = row[kPositionInput].toVec2();
QVector2D sz = row[kSizeInput].toVec2();
QVector2D half_sz = sz * 0.5;
QVector2D pos = row[kPositionInput].toVec2();
QVector2D sz = row[kSizeInput].toVec2();
QVector2D half_sz = sz * 0.5;
double left_pt = pos.x() + center_pt.x() - half_sz.x();
double top_pt = pos.y() + center_pt.y() - half_sz.y();
double right_pt = left_pt + sz.x();
double bottom_pt = top_pt + sz.y();
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
double left_pt = pos.x() + center_pt.x() - half_sz.x();
double top_pt = pos.y() + center_pt.y() - half_sz.y();
double right_pt = left_pt + sz.x();
double bottom_pt = top_pt + sz.y();
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(QPointF(right_pt, center_y_pt));
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
QPointF(right_pt, center_y_pt));
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
poly_gizmo_->SetPolygon(
QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
}
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command)
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res,
MultiUndoCommand *command)
{
// Normalize around center of sequence
rect.translate(-sequence_res.width()*0.5, -sequence_res.height()*0.5);
rect.translate(rect.width()*0.5, rect.height()*0.5);
// Normalize around center of sequence
rect.translate(-sequence_res.width() * 0.5, -sequence_res.height() * 0.5);
rect.translate(rect.width() * 0.5, rect.height() * 0.5);
NodeInput pos(this, ShapeNodeBase::kPositionInput);
NodeInput sz(this, ShapeNodeBase::kSizeInput);
NodeInput pos(this, ShapeNodeBase::kPositionInput);
NodeInput sz(this, ShapeNodeBase::kSizeInput);
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 1), rect.y()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(pos, 1), rect.y()));
}
void ShapeNodeBase::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void ShapeNodeBase::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
if (gizmo == poly_gizmo_) {
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
} else {
bool from_center = modifiers & Qt::AltModifier;
bool keep_ratio = modifiers & Qt::ShiftModifier;
if (gizmo == poly_gizmo_) {
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
} else {
bool from_center = modifiers & Qt::AltModifier;
bool keep_ratio = modifiers & Qt::ShiftModifier;
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(), h_drag.GetStartValue().toDouble());
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(), y_drag.GetStartValue().toDouble());
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution()/2;
QVector2D adjusted_pt(x, y);
QVector2D new_size;
QVector2D new_pos;
QVector2D anchor;
static const int kXYCount = 2;
bool negative[kXYCount] = {false};
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(),
h_drag.GetStartValue().toDouble());
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(),
y_drag.GetStartValue().toDouble());
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution() / 2;
QVector2D adjusted_pt(x, y);
QVector2D new_size;
QVector2D new_pos;
QVector2D anchor;
static const int kXYCount = 2;
bool negative[kXYCount] = { false };
double original_ratio;
if (keep_ratio) {
original_ratio = w_drag.GetStartValue().toDouble() / h_drag.GetStartValue().toDouble();
}
double original_ratio;
if (keep_ratio) {
original_ratio = w_drag.GetStartValue().toDouble() /
h_drag.GetStartValue().toDouble();
}
// Calculate new size
if (from_center) {
// Calculate new size by using distance from center and doubling it
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
// Calculate new size
if (from_center) {
// Calculate new size by using distance from center and doubling it
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
if (IsGizmoTop(gizmo)) {
new_size.setY(-new_size.y());
}
if (IsGizmoTop(gizmo)) {
new_size.setY(-new_size.y());
}
if (IsGizmoLeft(gizmo)) {
new_size.setX(-new_size.x());
}
} else {
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
// from the gizmo being dragged
adjusted_pt -= gizmo_half_res;
if (IsGizmoLeft(gizmo)) {
new_size.setX(-new_size.x());
}
} else {
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
// from the gizmo being dragged
adjusted_pt -= gizmo_half_res;
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo, &adjusted_pt) + gizmo_half_res;
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo,
&adjusted_pt) +
gizmo_half_res;
adjusted_pt += gizmo_half_res;
adjusted_pt += gizmo_half_res;
// Calculate size and position
new_size = adjusted_pt - anchor;
// Calculate size and position
new_size = adjusted_pt - anchor;
// Abs size so neither coord is negative
for (int i=0; i<kXYCount; i++) {
if (new_size[i] < 0) {
negative[i] = true;
new_size[i] = -new_size[i];
}
}
}
// Abs size so neither coord is negative
for (int i = 0; i < kXYCount; i++) {
if (new_size[i] < 0) {
negative[i] = true;
new_size[i] = -new_size[i];
}
}
}
// Restrict sizes by constraints
if (IsGizmoVerticalCenter(gizmo)) {
if (keep_ratio) {
// Calculate width from new height
new_size.setX(new_size.y() * original_ratio);
} else {
// Constrain to original width
new_size.setX(gizmo_sz_start.x());
}
}
// Restrict sizes by constraints
if (IsGizmoVerticalCenter(gizmo)) {
if (keep_ratio) {
// Calculate width from new height
new_size.setX(new_size.y() * original_ratio);
} else {
// Constrain to original width
new_size.setX(gizmo_sz_start.x());
}
}
if (IsGizmoHorizontalCenter(gizmo)) {
if (keep_ratio) {
// Calculate height from new width
new_size.setY(new_size.x() / original_ratio);
} else {
// Constrain to original height
new_size.setY(gizmo_sz_start.y());
}
}
if (IsGizmoHorizontalCenter(gizmo)) {
if (keep_ratio) {
// Calculate height from new width
new_size.setY(new_size.x() / original_ratio);
} else {
// Constrain to original height
new_size.setY(gizmo_sz_start.y());
}
}
if (IsGizmoCorner(gizmo)) {
if (keep_ratio) {
float hypot = std::hypot(new_size.x(), new_size.y());
if (IsGizmoCorner(gizmo)) {
if (keep_ratio) {
float hypot = std::hypot(new_size.x(), new_size.y());
float original_angle = std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
float original_angle =
std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
// Calculate new size based on original angle and hypotenuse
new_size.setX(std::sin(original_angle) * hypot);
new_size.setY(std::cos(original_angle) * hypot);
}
}
// Calculate new size based on original angle and hypotenuse
new_size.setX(std::sin(original_angle) * hypot);
new_size.setY(std::cos(original_angle) * hypot);
}
}
// Calculate position
if (from_center) {
new_pos = gizmo_pos_start;
} else {
QVector2D using_size = new_size;
// Calculate position
if (from_center) {
new_pos = gizmo_pos_start;
} else {
QVector2D using_size = new_size;
// Un-abs size
for (int i=0; i<kXYCount; i++) {
if (negative[i]) {
using_size[i] = -using_size[i];
}
}
// Un-abs size
for (int i = 0; i < kXYCount; i++) {
if (negative[i]) {
using_size[i] = -using_size[i];
}
}
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
if (IsGizmoHorizontalCenter(gizmo)) {
using_size.setY(0);
}
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
if (IsGizmoHorizontalCenter(gizmo)) {
using_size.setY(0);
}
if (IsGizmoVerticalCenter(gizmo)) {
using_size.setX(0);
}
if (IsGizmoVerticalCenter(gizmo)) {
using_size.setX(0);
}
new_pos = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) + using_size / 2;
}
new_pos =
GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) +
using_size / 2;
}
x_drag.Drag(new_pos.x());
y_drag.Drag(new_pos.y());
w_drag.Drag(new_size.x());
h_drag.Drag(new_size.y());
}
x_drag.Drag(new_pos.x());
y_drag.Drag(new_pos.y());
w_drag.Drag(new_size.x());
h_drag.Drag(new_size.y());
}
}
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt) const
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos,
const QVector2D &size,
NodeGizmo *gizmo,
QVector2D *pt) const
{
QVector2D anchor = pos;
QVector2D half_sz = size/2;
QVector2D anchor = pos;
QVector2D half_sz = size / 2;
if (IsGizmoLeft(gizmo)) {
anchor.setX(anchor.x() + half_sz.x());
if (pt && pt->x() > anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoLeft(gizmo)) {
anchor.setX(anchor.x() + half_sz.x());
if (pt && pt->x() > anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoRight(gizmo)) {
anchor.setX(anchor.x() - half_sz.x());
if (pt && pt->x() < anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoRight(gizmo)) {
anchor.setX(anchor.x() - half_sz.x());
if (pt && pt->x() < anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoTop(gizmo)) {
anchor.setY(anchor.y() + half_sz.y());
if (pt && pt->y() > anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoTop(gizmo)) {
anchor.setY(anchor.y() + half_sz.y());
if (pt && pt->y() > anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoBottom(gizmo)) {
anchor.setY(anchor.y() - half_sz.y());
if (pt && pt->y() < anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoBottom(gizmo)) {
anchor.setY(anchor.y() - half_sz.y());
if (pt && pt->y() < anchor.y()) {
pt->setY(anchor.y());
}
}
return anchor;
return anchor;
}
bool ShapeNodeBase::IsGizmoTop(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight];
return g == point_gizmo_[kGizmoScaleTopCenter] ||
g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleTopRight];
}
bool ShapeNodeBase::IsGizmoBottom(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleBottomCenter] || g == point_gizmo_[kGizmoScaleBottomLeft] || g == point_gizmo_[kGizmoScaleBottomRight];
return g == point_gizmo_[kGizmoScaleBottomCenter] ||
g == point_gizmo_[kGizmoScaleBottomLeft] ||
g == point_gizmo_[kGizmoScaleBottomRight];
}
bool ShapeNodeBase::IsGizmoLeft(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleBottomLeft];
return g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleCenterLeft] ||
g == point_gizmo_[kGizmoScaleBottomLeft];
}
bool ShapeNodeBase::IsGizmoRight(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopRight] || g == point_gizmo_[kGizmoScaleCenterRight] || g == point_gizmo_[kGizmoScaleBottomRight];
return g == point_gizmo_[kGizmoScaleTopRight] ||
g == point_gizmo_[kGizmoScaleCenterRight] ||
g == point_gizmo_[kGizmoScaleBottomRight];
}
bool ShapeNodeBase::IsGizmoHorizontalCenter(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleCenterRight];
return g == point_gizmo_[kGizmoScaleCenterLeft] ||
g == point_gizmo_[kGizmoScaleCenterRight];
}
bool ShapeNodeBase::IsGizmoVerticalCenter(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleBottomCenter];
return g == point_gizmo_[kGizmoScaleTopCenter] ||
g == point_gizmo_[kGizmoScaleBottomCenter];
}
bool ShapeNodeBase::IsGizmoCorner(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight]
|| g == point_gizmo_[kGizmoScaleBottomRight] || g == point_gizmo_[kGizmoScaleBottomLeft];
return g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleTopRight] ||
g == point_gizmo_[kGizmoScaleBottomRight] ||
g == point_gizmo_[kGizmoScaleBottomLeft];
}
}
+33 -29
View File
@@ -27,49 +27,53 @@
#include "node/inputdragger.h"
#include "node/node.h"
namespace olive {
class ShapeNodeBase : public GeneratorWithMerge
namespace olive
{
Q_OBJECT
class ShapeNodeBase : public GeneratorWithMerge {
Q_OBJECT
public:
ShapeNodeBase(bool create_color_input = true);
ShapeNodeBase(bool create_color_input = true);
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
void SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command);
void SetRect(QRectF rect, const VideoParams &sequence_res,
MultiUndoCommand *command);
static const QString kPositionInput;
static const QString kSizeInput;
static const QString kColorInput;
static const QString kPositionInput;
static const QString kSizeInput;
static const QString kColorInput;
protected:
PolygonGizmo *poly_gizmo() const
{
return poly_gizmo_;
}
PolygonGizmo *poly_gizmo() const
{
return poly_gizmo_;
}
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt = nullptr) const;
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size,
NodeGizmo *gizmo,
QVector2D *pt = nullptr) const;
bool IsGizmoTop(NodeGizmo *g) const;
bool IsGizmoBottom(NodeGizmo *g) const;
bool IsGizmoLeft(NodeGizmo *g) const;
bool IsGizmoRight(NodeGizmo *g) const;
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
bool IsGizmoCorner(NodeGizmo *g) const;
// Gizmo variables
static const int kGizmoWholeRect = kGizmoScaleCount;
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
bool IsGizmoTop(NodeGizmo *g) const;
bool IsGizmoBottom(NodeGizmo *g) const;
bool IsGizmoLeft(NodeGizmo *g) const;
bool IsGizmoRight(NodeGizmo *g) const;
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
bool IsGizmoCorner(NodeGizmo *g) const;
// Gizmo variables
static const int kGizmoWholeRect = kGizmoScaleCount;
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
};
}
+18 -13
View File
@@ -20,7 +20,8 @@
#include "solid.h"
namespace olive {
namespace olive
{
const QString SolidGenerator::kColorInput = QStringLiteral("color_in");
@@ -28,47 +29,51 @@ const QString SolidGenerator::kColorInput = QStringLiteral("color_in");
SolidGenerator::SolidGenerator()
{
// Default to a color that isn't black
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 0.0f, 0.0f, 1.0f)));
// Default to a color that isn't black
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0f, 0.0f, 0.0f, 1.0f)));
}
QString SolidGenerator::Name() const
{
return tr("Solid");
return tr("Solid");
}
QString SolidGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.solidgenerator");
return QStringLiteral("org.olivevideoeditor.Olive.solidgenerator");
}
QVector<Node::CategoryID> SolidGenerator::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString SolidGenerator::Description() const
{
return tr("Generate a solid color.");
return tr("Generate a solid color.");
}
void SolidGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kColorInput, tr("Color"));
SetInputName(kColorInput, tr("Color"));
}
void SolidGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void SolidGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
table->Push(NodeValue::kTexture, Texture::Job(globals.vparams(), ShaderJob(value)), this);
table->Push(NodeValue::kTexture,
Texture::Job(globals.vparams(), ShaderJob(value)), this);
}
ShaderCode SolidGenerator::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag"));
}
}
+16 -15
View File
@@ -23,28 +23,29 @@
#include "node/node.h"
namespace olive {
class SolidGenerator : public Node
namespace olive
{
Q_OBJECT
class SolidGenerator : public Node {
Q_OBJECT
public:
SolidGenerator();
SolidGenerator();
NODE_DEFAULT_FUNCTIONS(SolidGenerator)
NODE_DEFAULT_FUNCTIONS(SolidGenerator)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
static const QString kColorInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kColorInput;
};
}
+96 -85
View File
@@ -23,12 +23,13 @@
#include <QAbstractTextDocumentLayout>
#include <QTextDocument>
namespace olive {
namespace olive
{
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV1::kTextInput = QStringLiteral("text_in");
@@ -42,132 +43,142 @@ const QString TextGeneratorV1::kFontSizeInput = QStringLiteral("font_size_in");
TextGeneratorV1::TextGeneratorV1()
{
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
AddInput(kVAlignInput, NodeValue::kCombo, 1);
AddInput(kVAlignInput, NodeValue::kCombo, 1);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
SetFlag(kDontShowInCreateMenu);
SetFlag(kDontShowInCreateMenu);
}
QString TextGeneratorV1::Name() const
{
return tr("Text (Legacy)");
return tr("Text (Legacy)");
}
QString TextGeneratorV1::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
}
QVector<Node::CategoryID> TextGeneratorV1::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV1::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV1::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
}
void TextGeneratorV1::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV1::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (!value[kTextInput].toString().isEmpty()) {
table->Push(NodeValue::kTexture, Texture::Job(globals.vparams(), GenerateJob(value)), this);
}
if (!value[kTextInput].toString().isEmpty()) {
table->Push(NodeValue::kTexture,
Texture::Job(globals.vparams(), GenerateJob(value)), this);
}
}
void TextGeneratorV1::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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(0);
// 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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(0);
QTextDocument text_doc;
QTextDocument text_doc;
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Center by default
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
// Center by default
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
// Align to 80% width because that's considered the "title safe" area
int tenth_of_width = frame->video_params().width() / 10;
text_doc.setTextWidth(tenth_of_width * 8);
// Align to 80% width because that's considered the "title safe" area
int tenth_of_width = frame->video_params().width() / 10;
text_doc.setTextWidth(tenth_of_width * 8);
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(),
1.0 / frame->video_params().divider());
// Push 10% inwards to compensate for title safe area
p.translate(tenth_of_width, 0);
// Push 10% inwards to compensate for title safe area
p.translate(tenth_of_width, 0);
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
TextVerticalAlign valign =
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
switch (valign) {
case kVerticalAlignTop:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() / 10);
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() - doc_height - frame->video_params().height() / 10);
break;
}
switch (valign) {
case kVerticalAlignTop:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() / 10);
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() - doc_height -
frame->video_params().height() / 10);
break;
}
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
// Transplant alpha channel to frame
Color rgb = job.Get(kColorInput).toColor();
for (int x=0; x<frame->width(); x++) {
for (int y=0; y<frame->height(); y++) {
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
float alpha = float(src_alpha) / 255.0f;
// Transplant alpha channel to frame
Color rgb = job.Get(kColorInput).toColor();
for (int x = 0; x < frame->width(); x++) {
for (int y = 0; y < frame->height(); y++) {
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
float alpha = float(src_alpha) / 255.0f;
frame->set_pixel(x, y, Color(rgb.red() * alpha, rgb.green() * alpha, rgb.blue() * alpha, alpha));
}
}
frame->set_pixel(x, y,
Color(rgb.red() * alpha, rgb.green() * alpha,
rgb.blue() * alpha, alpha));
}
}
}
}
+21 -20
View File
@@ -23,34 +23,35 @@
#include "node/node.h"
namespace olive {
class TextGeneratorV1 : public Node
namespace olive
{
Q_OBJECT
class TextGeneratorV1 : public Node {
Q_OBJECT
public:
TextGeneratorV1();
TextGeneratorV1();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kColorInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kColorInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
};
}
+107 -100
View File
@@ -25,14 +25,15 @@
#include <QDateTime>
#include <QTextDocument>
namespace olive {
namespace olive
{
#define super ShapeNodeBase
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV2::kTextInput = QStringLiteral("text_in");
@@ -43,156 +44,162 @@ const QString TextGeneratorV2::kFontSizeInput = QStringLiteral("font_size_in");
TextGeneratorV2::TextGeneratorV2()
{
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetFlag(kDontShowInCreateMenu);
SetFlag(kDontShowInCreateMenu);
}
QString TextGeneratorV2::Name() const
{
return tr("Text (Legacy)");
return tr("Text (Legacy)");
}
QString TextGeneratorV2::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.text2");
return QStringLiteral("org.olivevideoeditor.Olive.text2");
}
QVector<Node::CategoryID> TextGeneratorV2::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV2::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV2::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
}
void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV2::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (!value[kTextInput].toString().isEmpty()) {
GenerateJob job(value);
auto text_params = globals.vparams();
text_params.set_format(PixelFormat::F32);
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
}
if (!value[kTextInput].toString().isEmpty()) {
GenerateJob job(value);
auto text_params = globals.vparams();
text_params.set_format(PixelFormat::F32);
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
}
}
void TextGeneratorV2::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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(Qt::transparent);
// 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
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(Qt::transparent);
// 72 DPI in DPM (72 / 2.54 * 100)
const int dpm = 2835;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
// 72 DPI in DPM (72 / 2.54 * 100)
const int dpm = 2835;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
QVector2D size = job.Get(kSizeInput).toVec2();
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());
// 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.Get(kPositionInput).toVec2();
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());
QVector2D pos = job.Get(kPositionInput).toVec2();
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());
TextVerticalAlign valign =
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
switch (valign) {
case kVerticalAlignTop:
// Do nothing
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, size.y() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
p.translate(0, size.y() - doc_height);
break;
}
switch (valign) {
case kVerticalAlignTop:
// Do nothing
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, size.y() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
p.translate(0, size.y() - doc_height);
break;
}
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
text_doc.documentLayout()->draw(&p, ctx);
// Transplant alpha channel to frame
Color rgba = job.Get(kColorInput).toColor();
// Transplant alpha channel to frame
Color rgba = job.Get(kColorInput).toColor();
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
__m128 sse_color = _mm_loadu_ps(rgba.data());
__m128 sse_color = _mm_loadu_ps(rgba.data());
#endif
float *frame_dst = reinterpret_cast<float*>(frame->data());
for (int y=0; y<frame->height(); y++) {
uchar *src_y = img.bits() + img.bytesPerLine() * y;
float *dst_y = frame_dst + y*frame->linesize_pixels()*VideoParams::kRGBAChannelCount;
float *frame_dst = reinterpret_cast<float *>(frame->data());
for (int y = 0; y < frame->height(); y++) {
uchar *src_y = img.bits() + img.bytesPerLine() * y;
float *dst_y = frame_dst + y * frame->linesize_pixels() *
VideoParams::kRGBAChannelCount;
for (int x=0; x<frame->width(); x++) {
float alpha = float(src_y[x]) / 255.0f;
float *dst = dst_y + x*VideoParams::kRGBAChannelCount;
for (int x = 0; x < frame->width(); x++) {
float alpha = float(src_y[x]) / 255.0f;
float *dst = dst_y + x * VideoParams::kRGBAChannelCount;
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
__m128 sse_alpha = _mm_load1_ps(&alpha);
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
__m128 sse_alpha = _mm_load1_ps(&alpha);
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
_mm_store_ps(dst, sse_res);
_mm_store_ps(dst, sse_res);
#else
for (int i=0; i<VideoParams::kRGBAChannelCount; i++) {
dst[i] = rgba.data()[i] * alpha;
}
for (int i = 0; i < VideoParams::kRGBAChannelCount; i++) {
dst[i] = rgba.data()[i] * alpha;
}
#endif
}
}
}
}
}
}
+20 -19
View File
@@ -23,33 +23,34 @@
#include "node/generator/shape/shapenodebase.h"
namespace olive {
class TextGeneratorV2 : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class TextGeneratorV2 : public ShapeNodeBase {
Q_OBJECT
public:
TextGeneratorV2();
TextGeneratorV2();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
};
}
+182 -154
View File
@@ -29,253 +29,281 @@
#include "node/project.h"
#include "node/nodeundo.h"
namespace olive {
namespace olive
{
#define super ShapeNodeBase
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV3::kTextInput = QStringLiteral("text_in");
const QString TextGeneratorV3::kVerticalAlignmentInput = QStringLiteral("valign_in");
const QString TextGeneratorV3::kVerticalAlignmentInput =
QStringLiteral("valign_in");
const QString TextGeneratorV3::kUseArgsInput = QStringLiteral("use_args_in");
const QString TextGeneratorV3::kArgsInput = QStringLiteral("args_in");
TextGeneratorV3::TextGeneratorV3() :
ShapeNodeBase(false),
dont_emit_valign_(false)
TextGeneratorV3::TextGeneratorV3()
: ShapeNodeBase(false)
, dont_emit_valign_(false)
{
AddInput(kTextInput, NodeValue::kText, QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>").arg(tr("Sample Text")));
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
AddInput(kTextInput, NodeValue::kText,
QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>")
.arg(tr("Sample Text")));
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetStandardValue(kSizeInput, QVector2D(400, 300));
AddInput(kVerticalAlignmentInput, NodeValue::kCombo, InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kVerticalAlignmentInput, NodeValue::kCombo,
InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kUseArgsInput, NodeValue::kBoolean, true, InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kUseArgsInput, NodeValue::kBoolean, true,
InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
text_gizmo_ = new TextGizmo(this);
text_gizmo_->SetInput(NodeInput(this, kTextInput));
connect(text_gizmo_, &TextGizmo::Activated, this, &TextGeneratorV3::GizmoActivated);
connect(text_gizmo_, &TextGizmo::Deactivated, this, &TextGeneratorV3::GizmoDeactivated);
text_gizmo_ = new TextGizmo(this);
text_gizmo_->SetInput(NodeInput(this, kTextInput));
connect(text_gizmo_, &TextGizmo::Activated, this,
&TextGeneratorV3::GizmoActivated);
connect(text_gizmo_, &TextGizmo::Deactivated, this,
&TextGeneratorV3::GizmoDeactivated);
}
QString TextGeneratorV3::Name() const
{
return tr("Text");
return tr("Text");
}
QString TextGeneratorV3::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.text3");
return QStringLiteral("org.olivevideoeditor.Olive.text3");
}
QVector<Node::CategoryID> TextGeneratorV3::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV3::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV3::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
SetComboBoxStrings(kVerticalAlignmentInput, {tr("Top"), tr("Middle"), tr("Bottom")});
SetInputName(kArgsInput, tr("Arguments"));
SetInputName(kTextInput, tr("Text"));
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
SetComboBoxStrings(kVerticalAlignmentInput,
{ tr("Top"), tr("Middle"), tr("Bottom") });
SetInputName(kArgsInput, tr("Arguments"));
}
void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV3::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
QString text = value[kTextInput].toString();
QString text = value[kTextInput].toString();
if (value[kUseArgsInput].toBool()) {
auto args = value[kArgsInput].toArray();
if (!args.empty()) {
QStringList list;
list.reserve(args.size());
for (size_t i=0; i<args.size(); i++) {
list.append(args[i].toString());
}
if (value[kUseArgsInput].toBool()) {
auto args = value[kArgsInput].toArray();
if (!args.empty()) {
QStringList list;
list.reserve(args.size());
for (size_t i = 0; i < args.size(); i++) {
list.append(args[i].toString());
}
text = FormatString(text, list);
}
}
text = FormatString(text, list);
}
}
if (!text.isEmpty()) {
TexturePtr base = value[kTextInput].toTexture();
if (!text.isEmpty()) {
TexturePtr base = value[kTextInput].toTexture();
VideoParams text_params = base ? base->params() : globals.vparams();
text_params.set_format(PixelFormat::U8);
text_params.set_colorspace(project()->color_manager()->GetDefaultInputColorSpace());
VideoParams text_params = base ? base->params() : globals.vparams();
text_params.set_format(PixelFormat::U8);
text_params.set_colorspace(
project()->color_manager()->GetDefaultInputColorSpace());
GenerateJob job(value);
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
GenerateJob job(value);
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
PushMergableJob(value, Texture::Job(text_params, job), table);
} else if (value[kBaseInput].toTexture()) {
table->Push(value[kBaseInput]);
}
PushMergableJob(value, Texture::Job(text_params, job), table);
} else if (value[kBaseInput].toTexture()) {
table->Push(value[kBaseInput]);
}
}
void TextGeneratorV3::GenerateFrame(FramePtr frame, const GenerateJob& job) const
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);
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);
// 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);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
QString html = job.Get(kTextInput).toString();
Html::HtmlToDoc(&text_doc, html);
QString html = job.Get(kTextInput).toString();
Html::HtmlToDoc(&text_doc, html);
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
QVector2D size = job.Get(kSizeInput).toVec2();
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());
// 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.Get(kPositionInput).toVec2();
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());
QVector2D pos = job.Get(kPositionInput).toVec2();
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());
switch (static_cast<VerticalAlignment>(job.Get(kVerticalAlignmentInput).toInt())) {
case kVAlignTop:
// Do nothing
break;
case kVAlignMiddle:
p.translate(0, size.y()/2-text_doc.size().height()/2);
break;
case kVAlignBottom:
p.translate(0, size.y()-text_doc.size().height());
break;
}
switch (static_cast<VerticalAlignment>(
job.Get(kVerticalAlignmentInput).toInt())) {
case kVAlignTop:
// Do nothing
break;
case kVAlignMiddle:
p.translate(0, size.y() / 2 - text_doc.size().height() / 2);
break;
case kVAlignBottom:
p.translate(0, size.y() - text_doc.size().height());
break;
}
// Ensure default text color is white
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
// Ensure default text color is white
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
text_doc.documentLayout()->draw(&p, ctx);
}
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
super::UpdateGizmoPositions(row, globals);
super::UpdateGizmoPositions(row, globals);
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
text_gizmo_->SetRect(rect);
text_gizmo_->SetHtml(row[kTextInput].toString());
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
text_gizmo_->SetRect(rect);
text_gizmo_->SetHtml(row[kTextInput].toString());
}
Qt::Alignment TextGeneratorV3::GetQtAlignmentFromOurs(VerticalAlignment v)
{
switch (v) {
case kVAlignTop:
return Qt::AlignTop;
case kVAlignMiddle:
return Qt::AlignVCenter;
case kVAlignBottom:
return Qt::AlignBottom;
}
return Qt::Alignment();
switch (v) {
case kVAlignTop:
return Qt::AlignTop;
case kVAlignMiddle:
return Qt::AlignVCenter;
case kVAlignBottom:
return Qt::AlignBottom;
}
return Qt::Alignment();
}
TextGeneratorV3::VerticalAlignment TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
TextGeneratorV3::VerticalAlignment
TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
{
switch (v) {
case Qt::AlignTop:
return kVAlignTop;
case Qt::AlignVCenter:
return kVAlignMiddle;
case Qt::AlignBottom:
return kVAlignBottom;
}
switch (v) {
case Qt::AlignTop:
return kVAlignTop;
case Qt::AlignVCenter:
return kVAlignMiddle;
case Qt::AlignBottom:
return kVAlignBottom;
}
return kVAlignTop;
return kVAlignTop;
}
QString TextGeneratorV3::FormatString(const QString &input, const QStringList &args)
QString TextGeneratorV3::FormatString(const QString &input,
const QStringList &args)
{
QString output;
output.reserve(input.size());
QString output;
output.reserve(input.size());
for (int i=0; i<input.size(); i++) {
const QChar &this_char = input.at(i);
for (int i = 0; i < input.size(); i++) {
const QChar &this_char = input.at(i);
if (i < input.size()-1 && this_char == '%') {
const QChar &next_char = input.at(i+1);
if (next_char == '%') {
// Double percent, append a single percent
output.append('%');
i++;
} else if (next_char.isDigit()) {
// Find length of number
QString num;
i++;
while (i < input.size() && input.at(i).isDigit()) {
num.append(input.at(i));
i++;
}
i--;
int index = num.toInt()-1;
if (index >= 0 && index < args.size()) {
output.append(args.at(index));
}
} else {
output.append(this_char);
}
} else {
output.append(this_char);
}
}
if (i < input.size() - 1 && this_char == '%') {
const QChar &next_char = input.at(i + 1);
if (next_char == '%') {
// Double percent, append a single percent
output.append('%');
i++;
} else if (next_char.isDigit()) {
// Find length of number
QString num;
i++;
while (i < input.size() && input.at(i).isDigit()) {
num.append(input.at(i));
i++;
}
i--;
int index = num.toInt() - 1;
if (index >= 0 && index < args.size()) {
output.append(args.at(index));
}
} else {
output.append(this_char);
}
} else {
output.append(this_char);
}
}
return output;
return output;
}
void TextGeneratorV3::InputValueChangedEvent(const QString &input, int element)
{
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
text_gizmo_->SetVerticalAlignment(GetQtAlignmentFromOurs(GetVerticalAlignment()));
}
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
text_gizmo_->SetVerticalAlignment(
GetQtAlignmentFromOurs(GetVerticalAlignment()));
}
super::InputValueChangedEvent(input, element);
super::InputValueChangedEvent(input, element);
}
void TextGeneratorV3::GizmoActivated()
{
SetStandardValue(kUseArgsInput, false);
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
SetStandardValue(kUseArgsInput, false);
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
&TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
}
void TextGeneratorV3::GizmoDeactivated()
{
SetStandardValue(kUseArgsInput, true);
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
SetStandardValue(kUseArgsInput, true);
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
&TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
}
void TextGeneratorV3::SetVerticalAlignmentUndoable(Qt::Alignment a)
{
Core::instance()->undo_stack()->push(new NodeParamSetStandardValueCommand(NodeInput(this, kVerticalAlignmentInput), GetOurAlignmentFromQts(a)), tr("Set Text Vertical Alignment"));
Core::instance()->undo_stack()->push(
new NodeParamSetStandardValueCommand(NodeInput(this,
kVerticalAlignmentInput),
GetOurAlignmentFromQts(a)),
tr("Set Text Vertical Alignment"));
}
}
+37 -38
View File
@@ -24,64 +24,63 @@
#include "node/generator/shape/shapenodebase.h"
#include "node/gizmo/text.h"
namespace olive {
class TextGeneratorV3 : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class TextGeneratorV3 : public ShapeNodeBase {
Q_OBJECT
public:
TextGeneratorV3();
TextGeneratorV3();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
enum VerticalAlignment
{
kVAlignTop,
kVAlignMiddle,
kVAlignBottom
};
enum VerticalAlignment { kVAlignTop, kVAlignMiddle, kVAlignBottom };
VerticalAlignment GetVerticalAlignment() const
{
return static_cast<VerticalAlignment>(GetStandardValue(kVerticalAlignmentInput).toInt());
}
VerticalAlignment GetVerticalAlignment() const
{
return static_cast<VerticalAlignment>(
GetStandardValue(kVerticalAlignmentInput).toInt());
}
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
static const QString kTextInput;
static const QString kVerticalAlignmentInput;
static const QString kUseArgsInput;
static const QString kArgsInput;
static const QString kTextInput;
static const QString kVerticalAlignmentInput;
static const QString kUseArgsInput;
static const QString kArgsInput;
static QString FormatString(const QString &input, const QStringList &args);
static QString FormatString(const QString &input, const QStringList &args);
protected:
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
private:
TextGizmo *text_gizmo_;
TextGizmo *text_gizmo_;
bool dont_emit_valign_;
bool dont_emit_valign_;
private slots:
void GizmoActivated();
void GizmoDeactivated();
void SetVerticalAlignmentUndoable(Qt::Alignment a);
void GizmoActivated();
void GizmoDeactivated();
void SetVerticalAlignmentUndoable(Qt::Alignment a);
};
}