gizmos fairly complete

This commit is contained in:
itsmattkc
2018-11-28 13:53:31 +11:00
parent f28427302e
commit 3069fb6f7c
7 changed files with 85 additions and 66 deletions
+4 -4
View File
@@ -59,10 +59,10 @@ void CornerPinEffect::process_shader(double timecode, GLTextureCoords &coords) {
}
void CornerPinEffect::gizmo_draw(double timecode, GLTextureCoords &coords) {
top_left_gizmo->set_pos(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_right_gizmo->set_pos(coords.vertexTopRightX, coords.vertexTopRightY);
bottom_right_gizmo->set_pos(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_left_gizmo->set_pos(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
top_left_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_right_gizmo->world_pos[0] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
bottom_right_gizmo->world_pos[0] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_left_gizmo->world_pos[0] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
}
void CornerPinEffect::gizmo_move(EffectGizmo *sender, int x_movement, int y_movement, double timecode) {
+23 -9
View File
@@ -72,7 +72,9 @@ TransformEffect::TransformEffect(Clip* c, const EffectMeta* em) : Effect(c, em)
bottom_center_gizmo = add_gizmo(GIZMO_TYPE_DOT);
bottom_right_gizmo = add_gizmo(GIZMO_TYPE_DOT);
left_center_gizmo = add_gizmo(GIZMO_TYPE_DOT);
right_center_gizmo = add_gizmo(GIZMO_TYPE_DOT);
right_center_gizmo = add_gizmo(GIZMO_TYPE_DOT);
rotate_gizmo = add_gizmo(GIZMO_TYPE_DOT);
rect_gizmo = add_gizmo(GIZMO_TYPE_POLY);
top_left_gizmo->set_cursor(Qt::SizeFDiagCursor);
top_center_gizmo->set_cursor(Qt::SizeVerCursor);
@@ -82,6 +84,8 @@ TransformEffect::TransformEffect(Clip* c, const EffectMeta* em) : Effect(c, em)
bottom_right_gizmo->set_cursor(Qt::SizeFDiagCursor);
left_center_gizmo->set_cursor(Qt::SizeHorCursor);
right_center_gizmo->set_cursor(Qt::SizeHorCursor);
rotate_gizmo->color = Qt::green;
rotate_gizmo->set_cursor(Qt::SizeAllCursor);
// set defaults
scale_y->set_enabled(false);
@@ -167,14 +171,21 @@ void TransformEffect::process_coords(double timecode, GLTextureCoords& coords, i
}
void TransformEffect::gizmo_draw(double timecode, GLTextureCoords& coords) {
top_left_gizmo->set_pos(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_center_gizmo->set_pos(lerp(coords.vertexTopLeftX, coords.vertexTopRightX, 0.5), lerp(coords.vertexTopLeftY, coords.vertexTopRightY, 0.5));
top_right_gizmo->set_pos(coords.vertexTopRightX, coords.vertexTopRightY);
right_center_gizmo->set_pos(lerp(coords.vertexTopRightX, coords.vertexBottomRightX, 0.5), lerp(coords.vertexTopRightY, coords.vertexBottomRightY, 0.5));
bottom_right_gizmo->set_pos(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_center_gizmo->set_pos(lerp(coords.vertexBottomRightX, coords.vertexBottomLeftX, 0.5), lerp(coords.vertexBottomRightY, coords.vertexBottomLeftY, 0.5));
bottom_left_gizmo->set_pos(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
left_center_gizmo->set_pos(lerp(coords.vertexBottomLeftX, coords.vertexTopLeftX, 0.5), lerp(coords.vertexBottomLeftY, coords.vertexTopLeftY, 0.5));
top_left_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexTopLeftX, coords.vertexTopRightX, 0.5), lerp(coords.vertexTopLeftY, coords.vertexTopRightY, 0.5));
top_right_gizmo->world_pos[0] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
right_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexTopRightX, coords.vertexBottomRightX, 0.5), lerp(coords.vertexTopRightY, coords.vertexBottomRightY, 0.5));
bottom_right_gizmo->world_pos[0] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexBottomRightX, coords.vertexBottomLeftX, 0.5), lerp(coords.vertexBottomRightY, coords.vertexBottomLeftY, 0.5));
bottom_left_gizmo->world_pos[0] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
left_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexBottomLeftX, coords.vertexTopLeftX, 0.5), lerp(coords.vertexBottomLeftY, coords.vertexTopLeftY, 0.5));
rotate_gizmo->world_pos[0] = QPoint(lerp(top_center_gizmo->world_pos[0].x(), bottom_center_gizmo->world_pos[0].x(), -0.1), lerp(top_center_gizmo->world_pos[0].y(), bottom_center_gizmo->world_pos[0].y(), -0.1));
rect_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
rect_gizmo->world_pos[1] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
rect_gizmo->world_pos[2] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
rect_gizmo->world_pos[3] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
}
void TransformEffect::gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode) {
@@ -209,6 +220,9 @@ void TransformEffect::gizmo_move(EffectGizmo* sender, int x_movement, int y_move
} else {
scale_y->set_double_value(scale_y->get_double_value(timecode) + y_percent);
}
} else if (sender == rotate_gizmo) {
// TODO make this perfectly circular
rotation->set_double_value(rotation->get_double_value(timecode) + x_percent);
} else {
position_x->set_double_value(position_x->get_double_value(timecode) + x_movement);
position_y->set_double_value(position_y->get_double_value(timecode) + y_movement);
+2
View File
@@ -34,6 +34,8 @@ private:
EffectGizmo* bottom_right_gizmo;
EffectGizmo* left_center_gizmo;
EffectGizmo* right_center_gizmo;
EffectGizmo* rotate_gizmo;
EffectGizmo* rect_gizmo;
int default_anchor_x;
int default_anchor_y;
+6 -5
View File
@@ -861,13 +861,14 @@ void Effect::gizmo_world_to_screen() {
for (int i=0;i<gizmos.size();i++) {
EffectGizmo* g = gizmos.at(i);
QVector4D world_pos(g->get_x(), g->get_y(), 0, 1.0);
QVector4D screen_pos = world_pos * (view_matrix * projection_matrix);
for (int j=0;j<g->get_point_count();j++) {
QVector4D screen_pos = QVector4D(g->world_pos[j].x(), g->world_pos[j].y(), 0, 1.0) * (view_matrix * projection_matrix);
int adjusted_sx = qRound(((screen_pos.x()*0.5)+0.5)*parent_clip->sequence->width);
int adjusted_sy = qRound((1.0-((screen_pos.y()*0.5)+0.5))*parent_clip->sequence->height);
int adjusted_sx1 = qRound(((screen_pos.x()*0.5f)+0.5f)*parent_clip->sequence->width);
int adjusted_sy1 = qRound((1.0f-((screen_pos.y()*0.5f)+0.5f))*parent_clip->sequence->height);
g->set_screen_pos(adjusted_sx, adjusted_sy);
g->screen_pos[j] = QPoint(adjusted_sx1, adjusted_sy1);
}
}
}
+7 -23
View File
@@ -3,38 +3,22 @@
EffectGizmo::EffectGizmo(int type) :
type(type),
cursor(-1)
{}
{
int point_count = (type == GIZMO_TYPE_POLY) ? 4 : 1;
world_pos.resize(point_count);
screen_pos.resize(point_count);
void EffectGizmo::set_pos(int ix, int iy) {
x = ix;
y = iy;
color = Qt::white;
}
int EffectGizmo::get_x() {
return x;
}
int EffectGizmo::get_y() {
return y;
int EffectGizmo::get_point_count() {
return world_pos.size();
}
int EffectGizmo::get_type() {
return type;
}
void EffectGizmo::set_screen_pos(int isx, int isy) {
sx = isx;
sy = isy;
}
int EffectGizmo::get_screen_x() {
return sx;
}
int EffectGizmo::get_screen_y() {
return sy;
}
int EffectGizmo::get_cursor() {
return cursor;
}
+9 -12
View File
@@ -2,35 +2,32 @@
#define EFFECTGIZMO_H
#define GIZMO_TYPE_DOT 0
#define GIZMO_TYPE_QUAD 1
#define GIZMO_TYPE_POLY 1
#define GIZMO_DOT_SIZE 2.5F
#include <QString>
#include <QRect>
#include <QPoint>
#include <QVector>
#include <QColor>
class EffectGizmo
{
public:
EffectGizmo(int type);
void set_pos(int ix, int iy);
int get_x();
int get_y();
int get_type();
QVector<QPoint> world_pos;
QVector<QPoint> screen_pos;
QColor color;
int get_point_count();
void set_screen_pos(int isx, int isy);
int get_screen_x();
int get_screen_y();
int get_type();
int get_cursor();
void set_cursor(int c);
private:
int type;
int x;
int y;
int sx;
int sy;
int cursor;
};
+34 -13
View File
@@ -30,6 +30,7 @@
#include <QMenu>
#include <QOffscreenSurface>
#include <QFileDialog>
#include <QPolygon>
extern "C" {
#include <libavformat/avformat.h>
@@ -137,19 +138,29 @@ double get_timecode(Clip* c, long playhead) {
}
EffectGizmo* ViewerWidget::get_gizmo_from_mouse(int x, int y) {
if (gizmos != NULL) {
double multiplier = (double) width() / (double) viewer->seq->width;
int dot_size = qRound(GIZMO_DOT_SIZE / width() * viewer->seq->width);
if (gizmos != NULL) {
double multiplier = (double) viewer->seq->width / (double) width();
QPoint mouse_pos(qRound(x*multiplier), qRound(y*multiplier));
int dot_size = 2 * qRound(GIZMO_DOT_SIZE * multiplier);
for (int i=0;i<gizmos->gizmo_count();i++) {
EffectGizmo* g = gizmos->gizmo(i);
if (x > g->get_screen_x()*multiplier - dot_size
&& y > g->get_screen_y()*multiplier - dot_size
&& x < g->get_screen_x()*multiplier + dot_size
&& y < g->get_screen_y()*multiplier + dot_size) {
return g;
switch (g->get_type()) {
case GIZMO_TYPE_DOT:
if (mouse_pos.x() > g->screen_pos[0].x() - dot_size
&& mouse_pos.y() > g->screen_pos[0].y() - dot_size
&& mouse_pos.x() < g->screen_pos[0].x() + dot_size
&& mouse_pos.y() < g->screen_pos[0].y() + dot_size) {
return g;
}
break;
case GIZMO_TYPE_POLY:
if (QPolygon(g->screen_pos).containsPoint(mouse_pos, Qt::OddEvenFill)) {
return g;
}
break;
}
}
}
return NULL;
@@ -630,14 +641,24 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
glOrtho(0, viewer->seq->width, viewer->seq->height, 0, -1, 1);
for (int j=0;j<gizmos->gizmo_count();j++) {
EffectGizmo* g = gizmos->gizmo(j);
glColor4f(g->color.redF(), g->color.greenF(), g->color.blueF(), 1.0);
switch (g->get_type()) {
case GIZMO_TYPE_DOT: // draw dot
glBegin(GL_QUADS);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(g->get_screen_x()-dot_size, g->get_screen_y()-dot_size);
glVertex2f(g->get_screen_x()+dot_size, g->get_screen_y()-dot_size);
glVertex2f(g->get_screen_x()+dot_size, g->get_screen_y()+dot_size);
glVertex2f(g->get_screen_x()-dot_size, g->get_screen_y()+dot_size);
glVertex2f(g->screen_pos[0].x()-dot_size, g->screen_pos[0].y()-dot_size);
glVertex2f(g->screen_pos[0].x()+dot_size, g->screen_pos[0].y()-dot_size);
glVertex2f(g->screen_pos[0].x()+dot_size, g->screen_pos[0].y()+dot_size);
glVertex2f(g->screen_pos[0].x()-dot_size, g->screen_pos[0].y()+dot_size);
glEnd();
break;
case GIZMO_TYPE_POLY: // draw lines
glBegin(GL_LINES);
for (int k=1;k<g->get_point_count();k++) {
glVertex2f(g->screen_pos[k-1].x(), g->screen_pos[k-1].y());
glVertex2f(g->screen_pos[k].x(), g->screen_pos[k].y());
}
glVertex2f(g->screen_pos[g->get_point_count()-1].x(), g->screen_pos[g->get_point_count()-1].y());
glVertex2f(g->screen_pos[0].x(), g->screen_pos[0].y());
glEnd();
break;
}