polygon node: early crude implementation

This commit is contained in:
itsmattkc
2020-05-05 00:22:49 +10:00
parent b6696f3161
commit c387ce1cd7
38 changed files with 611 additions and 93 deletions
+2 -2
View File
@@ -20,8 +20,8 @@ set(OLIVE_SOURCES
widget/viewer/audiowaveformview.cpp
widget/viewer/footageviewer.h
widget/viewer/footageviewer.cpp
widget/viewer/pixelsamplerwidget.h
widget/viewer/pixelsamplerwidget.cpp
widget/viewer/gizmotraverser.h
widget/viewer/gizmotraverser.cpp
widget/viewer/viewer.h
widget/viewer/viewer.cpp
widget/viewer/viewerdisplay.h
+39
View File
@@ -0,0 +1,39 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "gizmotraverser.h"
OLIVE_NAMESPACE_ENTER
void GizmoTraverser::FootageProcessingEvent(StreamPtr stream, const TimeRange &/*input_time*/, NodeValueTable *table)
{
if (stream->type() == Stream::kVideo || stream->type() == Stream::kAudio) {
ImageStreamPtr image_stream = std::static_pointer_cast<ImageStream>(stream);
table->Push(NodeParam::kTexture, QSize(image_stream->width(),
image_stream->height()));
} else if (stream->type() == Stream::kAudio) {
// FIXME: Get samples
}
}
OLIVE_NAMESPACE_EXIT
@@ -18,51 +18,23 @@
***/
#ifndef PIXELSAMPLERWIDGET_H
#define PIXELSAMPLERWIDGET_H
#ifndef GIZMOTRAVERSER_H
#define GIZMOTRAVERSER_H
#include <QLabel>
#include <QGroupBox>
#include <QWidget>
#include "render/color.h"
#include "node/traverser.h"
OLIVE_NAMESPACE_ENTER
class PixelSamplerWidget : public QGroupBox
class GizmoTraverser : public NodeTraverser
{
Q_OBJECT
public:
PixelSamplerWidget(QWidget* parent = nullptr);
GizmoTraverser() = default;
public slots:
void SetValues(const Color& color);
private:
void UpdateLabelInternal();
Color color_;
QLabel* label_;
};
class ManagedPixelSamplerWidget : public QWidget
{
Q_OBJECT
public:
ManagedPixelSamplerWidget(QWidget* parent = nullptr);
public slots:
void SetValues(const Color& reference, const Color& display);
private:
PixelSamplerWidget* reference_view_;
PixelSamplerWidget* display_view_;
protected:
virtual void FootageProcessingEvent(StreamPtr stream, const TimeRange &input_time, NodeValueTable* table) override;
};
OLIVE_NAMESPACE_EXIT
#endif // PIXELSAMPLERWIDGET_H
#endif // GIZMOTRAVERSER_H
-80
View File
@@ -1,80 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "pixelsamplerwidget.h"
#include <QVBoxLayout>
OLIVE_NAMESPACE_ENTER
PixelSamplerWidget::PixelSamplerWidget(QWidget *parent) :
QGroupBox(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
label_ = new QLabel();
layout->addWidget(label_);
setTitle(tr("Color"));
UpdateLabelInternal();
}
void PixelSamplerWidget::SetValues(const Color &color)
{
color_ = color;
UpdateLabelInternal();
}
void PixelSamplerWidget::UpdateLabelInternal()
{
label_->setText(tr("<html>"
"<font color='#FF8080'>R: %1</font><br>"
"<font color='#80FF80'>G: %2</font><br>"
"<font color='#8080FF'>B: %3</font><br>"
"A: %4"
"</html>").arg(QString::number(color_.red()),
QString::number(color_.green()),
QString::number(color_.blue()),
QString::number(color_.alpha())));
}
ManagedPixelSamplerWidget::ManagedPixelSamplerWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
display_view_ = new PixelSamplerWidget();
display_view_->setTitle(tr("Display"));
layout->addWidget(display_view_);
reference_view_ = new PixelSamplerWidget();
reference_view_->setTitle(tr("Reference"));
layout->addWidget(reference_view_);
}
void ManagedPixelSamplerWidget::SetValues(const Color &reference, const Color &display)
{
reference_view_->SetValues(reference);
display_view_->SetValues(display);
}
OLIVE_NAMESPACE_EXIT
+5
View File
@@ -130,6 +130,8 @@ void ViewerWidget::TimeChangedEvent(const int64_t &i)
UpdateTextureFromNode(time_set);
PushScrubbedAudio();
main_gl_widget()->SetTime(time_set);
}
last_time_ = i;
@@ -335,6 +337,7 @@ ColorManager *ViewerWidget::color_manager() const
void ViewerWidget::SetGizmos(Node *node)
{
main_gl_widget()->SetTimeTarget(GetConnectedNode());
main_gl_widget()->SetGizmos(node);
}
@@ -537,6 +540,8 @@ void ViewerWidget::UpdateRendererParameters()
video_renderer_->InvalidateCache(TimeRange(0, GetConnectedNode()->Length()), nullptr);
}
main_gl_widget()->SetVideoParams(vparam);
AudioRenderingParams aparam(GetConnectedNode()->audio_params(),
SampleFormat::kInternalFormat);
+74 -3
View File
@@ -30,6 +30,7 @@
#include <QPainter>
#include "common/define.h"
#include "gizmotraverser.h"
#include "render/backend/opengl/openglrenderfunctions.h"
#include "render/backend/opengl/openglshader.h"
#include "render/pixelformat.h"
@@ -44,7 +45,8 @@ ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
ManagedDisplayWidget(parent),
has_image_(false),
signal_cursor_color_(false),
gizmos_(nullptr)
gizmos_(nullptr),
gizmo_click_(false)
{
}
@@ -169,8 +171,33 @@ void ViewerDisplayWidget::SetGizmos(Node *node)
update();
}
void ViewerDisplayWidget::SetVideoParams(const VideoRenderingParams &params)
{
gizmo_params_ = params;
if (gizmos_) {
update();
}
}
void ViewerDisplayWidget::SetTime(const rational &time)
{
time_ = time;
if (gizmos_) {
update();
}
}
void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
{
if (gizmos_) {
if (gizmos_->GizmoPress(GetTexturePosition(event->pos()))) {
gizmo_click_ = true;
return;
}
}
QOpenGLWidget::mousePressEvent(event);
emit DragStarted();
@@ -178,6 +205,11 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
{
if (gizmo_click_) {
gizmos_->GizmoMove(GetTexturePosition(event->pos()));
return;
}
QOpenGLWidget::mouseMoveEvent(event);
if (signal_cursor_color_) {
@@ -201,6 +233,18 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
}
}
void ViewerDisplayWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (gizmo_click_) {
gizmos_->GizmoRelease(GetTexturePosition(event->pos()));
gizmo_click_ = false;
return;
}
QOpenGLWidget::mouseReleaseEvent(event);
}
void ViewerDisplayWidget::initializeGL()
{
ManagedDisplayWidget::initializeGL();
@@ -233,7 +277,7 @@ void ViewerDisplayWidget::paintGL()
f->glClear(GL_COLOR_BUFFER_BIT);
// We only draw if we have a pipeline
if (has_image_ && color_service() && texture_.IsCreated()) {
if (has_image_ && color_service()) {
// Bind retrieved texture
f->glBindTexture(GL_TEXTURE_2D, texture_.texture());
@@ -248,8 +292,19 @@ void ViewerDisplayWidget::paintGL()
// Draw gizmos if we have any
if (gizmos_) {
GizmoTraverser gt;
rational node_time = GetAdjustedTime(GetTimeTarget(), gizmos_, time_, NodeParam::kInput);
NodeValueDatabase db = gt.GenerateDatabase(gizmos_, TimeRange(node_time, node_time));
QPainter p(this);
gizmos_->DrawGizmos(&p, rect());
// Scale so that gizmos can just draw on the buffer
QPointF tex_point = GetTexturePosition(size());
p.scale(tex_point.x(), tex_point.y());
gizmos_->DrawGizmos(db, &p);
}
// Draw action/title safe areas
@@ -285,6 +340,22 @@ void ViewerDisplayWidget::paintGL()
}
}
QPointF ViewerDisplayWidget::GetTexturePosition(const QPoint &screen_pos)
{
return GetTexturePosition(screen_pos.x(), screen_pos.y());
}
QPointF ViewerDisplayWidget::GetTexturePosition(const QSize &size)
{
return GetTexturePosition(size.width(), size.height());
}
QPointF ViewerDisplayWidget::GetTexturePosition(const double &x, const double &y)
{
return QPointF(x / gizmo_params_.width(),
y / gizmo_params_.height());
}
#ifdef Q_OS_LINUX
void ViewerDisplayWidget::ShowNouveauWarning()
{
+21 -3
View File
@@ -32,6 +32,7 @@
#include "render/colormanager.h"
#include "viewersafemargininfo.h"
#include "widget/manageddisplay/manageddisplay.h"
#include "widget/timetarget/timetarget.h"
OLIVE_NAMESPACE_ENTER
@@ -50,7 +51,7 @@ OLIVE_NAMESPACE_ENTER
* the same texture object, use SetTexture() since it will nearly always be faster to just set it than to check *and*
* set it.
*/
class ViewerDisplayWidget : public ManagedDisplayWidget
class ViewerDisplayWidget : public ManagedDisplayWidget, public TimeTargetObject
{
Q_OBJECT
public:
@@ -78,6 +79,8 @@ public:
void SetSafeMargins(const ViewerSafeMarginInfo& safe_margin);
void SetGizmos(Node* node);
void SetVideoParams(const VideoRenderingParams& params);
void SetTime(const rational& time);
public slots:
/**
@@ -126,15 +129,20 @@ signals:
protected:
/**
* @brief Override the mouse press event simply to emit the DragStarted() signal
* @brief Override the mouse press event for the DragStarted() signal and gizmos
*/
virtual void mousePressEvent(QMouseEvent* event) override;
/**
* @brief Override mouse move to provide functionality for
* @brief Override mouse move to signal for the pixel sampler and gizmos
*/
virtual void mouseMoveEvent(QMouseEvent* event) override;
/**
* @brief Override mouse release event for gizmos
*/
virtual void mouseReleaseEvent(QMouseEvent* event) override;
/**
* @brief Initialize function to set up the OpenGL context upon its construction
*
@@ -150,6 +158,10 @@ protected:
virtual void paintGL() override;
private:
QPointF GetTexturePosition(const QPoint& screen_pos);
QPointF GetTexturePosition(const QSize& size);
QPointF GetTexturePosition(const double& x, const double& y);
/**
* @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL().
*/
@@ -177,6 +189,12 @@ private:
Node* gizmos_;
VideoRenderingParams gizmo_params_;
bool gizmo_click_;
rational time_;
private slots:
/**
* @brief Slot to connect just before the OpenGL context is destroyed to clean up resources