diff --git a/effects/internal/transformeffect.cpp b/effects/internal/transformeffect.cpp index 517e21cda..48a4eed65 100644 --- a/effects/internal/transformeffect.cpp +++ b/effects/internal/transformeffect.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "ui/collapsiblewidget.h" #include "project/clip.h" @@ -143,6 +144,44 @@ void TransformEffect::process_coords(double timecode, GLTextureCoords& coords, i glColor4f(1.0, 1.0, 1.0, color[3]*(opacity->get_double_value(timecode)*0.01)); } -void TransformEffect::process_gizmos() { - // TODO put gizmo code here +void TransformEffect::gizmo_draw(double timecode, GLTextureCoords& coords) { + // proof of concept drawing pattern + + /*float color[4]; + glGetFloatv(GL_CURRENT_COLOR, color); + + glBegin(GL_TRIANGLES); + glColor4f(1.0, 0.0, 0.0, 0.5); + glVertex3f(coords.vertexTopLeftX, coords.vertexTopLeftY, 1); + glVertex3f(coords.vertexTopRightX, coords.vertexTopRightY, 1); + glVertex3f(coords.vertexBottomLeftX, coords.vertexBottomLeftY, 1); + glColor4f(0.0, 0.0, 1.0, 0.5); + glVertex3f(coords.vertexTopRightX, coords.vertexTopRightY, 1); + glVertex3f(coords.vertexBottomLeftX, coords.vertexBottomLeftY, 1); + glVertex3f(coords.vertexBottomRightX, coords.vertexBottomRightY, 1); + glEnd(); + + glColor4f(color[0], color[1], color[2], color[3]);*/ +} + +void TransformEffect::gizmo_down(QMouseEvent *event, double) { + dragging = true; + drag_start_x = event->pos().x(); + drag_start_y = event->pos().y(); +} + +void TransformEffect::gizmo_move(QMouseEvent *event, double timecode) { + if (dragging) { + position_x->set_double_value(position_x->get_double_value(timecode) + (event->pos().x() - drag_start_x)); + position_y->set_double_value(position_y->get_double_value(timecode) + (event->pos().y() - drag_start_y)); + + drag_start_x = event->pos().x(); + drag_start_y = event->pos().y(); + + field_changed(); + } +} + +void TransformEffect::gizmo_up(QMouseEvent *event, double) { + dragging = false; } diff --git a/effects/internal/transformeffect.h b/effects/internal/transformeffect.h index b9e3704ac..38834c45d 100644 --- a/effects/internal/transformeffect.h +++ b/effects/internal/transformeffect.h @@ -9,7 +9,11 @@ public: TransformEffect(Clip* c, const EffectMeta* em); void refresh(); void process_coords(double timecode, GLTextureCoords& coords, int data); - void process_gizmos(); + + void gizmo_draw(double timecode, GLTextureCoords& coords); + void gizmo_down(QMouseEvent *event, double); + void gizmo_move(QMouseEvent *event, double); + void gizmo_up(QMouseEvent *event, double); EffectField* position_x; EffectField* position_y; @@ -26,6 +30,10 @@ public slots: private: int default_anchor_x; int default_anchor_y; + + bool dragging; + int drag_start_x; + int drag_start_y; }; #endif // TRANSFORMEFFECT_H diff --git a/project/effect.cpp b/project/effect.cpp index 0731d3336..4b0150c83 100644 --- a/project/effect.cpp +++ b/project/effect.cpp @@ -833,7 +833,10 @@ void Effect::process_audio(double, double, quint8*, int, int) { }*/ } -void Effect::process_gizmos() {} +void Effect::gizmo_draw(double, GLTextureCoords &) {} +void Effect::gizmo_down(QMouseEvent *, double) {} +void Effect::gizmo_move(QMouseEvent *, double) {} +void Effect::gizmo_up(QMouseEvent *, double) {} void Effect::redraw(double) { /* diff --git a/project/effect.h b/project/effect.h index 62f8ba53d..ecf2cff05 100644 --- a/project/effect.h +++ b/project/effect.h @@ -15,6 +15,7 @@ class QWidget; class CollapsibleWidget; class QGridLayout; class QPushButton; +class QMouseEvent; struct Clip; class QXmlStreamReader; @@ -152,7 +153,11 @@ public: virtual void process_coords(double timecode, GLTextureCoords& coords, int data); virtual GLuint process_superimpose(double timecode); virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); - virtual void process_gizmos(); + + virtual void gizmo_draw(double timecode, GLTextureCoords& coords); + virtual void gizmo_down(QMouseEvent* event, double); + virtual void gizmo_move(QMouseEvent* event, double); + virtual void gizmo_up(QMouseEvent* event, double); public slots: void field_changed(); private slots: diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index 30203983a..8f01b761d 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -130,9 +130,14 @@ void ViewerWidget::seek_from_click(int x) { viewer->seek(getFrameFromScreenPoint((double) width() / (double) waveform_clip->timeline_out, x)); } +double get_timecode(Clip* c, long playhead) { + return ((double)(playhead-c->get_timeline_in_with_transition()+c->get_clip_in_with_transition())/(double)c->sequence->frame_rate); +} + void ViewerWidget::mousePressEvent(QMouseEvent* event) { if (waveform) seek_from_click(event->x()); dragging = true; + if (gizmos != NULL) gizmos->gizmo_down(event, get_timecode(gizmos->parent_clip, gizmos->parent_clip->sequence->playhead)); } void ViewerWidget::mouseMoveEvent(QMouseEvent* event) { @@ -147,10 +152,12 @@ void ViewerWidget::mouseMoveEvent(QMouseEvent* event) { drag->exec(); } } + if (gizmos != NULL) gizmos->gizmo_move(event, get_timecode(gizmos->parent_clip, gizmos->parent_clip->sequence->playhead)); } -void ViewerWidget::mouseReleaseEvent(QMouseEvent *) { +void ViewerWidget::mouseReleaseEvent(QMouseEvent *event) { dragging = false; + if (gizmos != NULL) gizmos->gizmo_up(event, get_timecode(gizmos->parent_clip, gizmos->parent_clip->sequence->playhead)); } void ViewerWidget::drawTitleSafeArea() { @@ -168,7 +175,7 @@ void ViewerWidget::drawTitleSafeArea() { } glLoadIdentity(); - glOrtho(-halfWidth, halfWidth, halfHeight, -halfHeight, -1, 1); + glOrtho(-halfWidth, halfWidth, halfHeight, -halfHeight, 0, 1); glColor4f(0.66f, 0.66f, 0.66f, 1.0f); glBegin(GL_LINES); @@ -437,6 +444,8 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) fbo_switcher = !fbo_switcher; + bool draw_gizmos = false; + GLTextureCoords coords; coords.grid_size = 1; coords.vertexTopLeftX = coords.vertexBottomLeftX = -video_width/2; @@ -456,13 +465,14 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) } // EFFECT CODE START - double timecode = ((double)(playhead-c->get_timeline_in_with_transition()+c->get_clip_in_with_transition())/(double)c->sequence->frame_rate); + double timecode = get_timecode(c, playhead); for (int j=0;jeffects.size();j++) { Effect* e = c->effects.at(j); process_effect(c, e, timecode, coords, composite_texture, fbo_switcher, TA_NO_TRANSITION); - if (gizmos == NULL && e->enable_gizmos && (e->container->selected || panel_timeline->is_clip_selected(c, true))) { + if (!rendering && gizmos == NULL && e->enable_gizmos && (e->container->selected || panel_timeline->is_clip_selected(c, true))) { gizmos = e; + draw_gizmos = true; } } @@ -551,6 +561,10 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) glBindTexture(GL_TEXTURE_2D, 0); // unbind texture + if (draw_gizmos) { + gizmos->gizmo_draw(timecode, coords); + } + if (!nests.isEmpty()) { nests.last()->fbo[0]->release(); if (default_fbo != NULL) default_fbo->bind(); @@ -678,10 +692,6 @@ void ViewerWidget::paintGL() { drawTitleSafeArea(); } - if (gizmos != NULL && !rendering) { - gizmos->process_gizmos(); - } - glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); } while (loop);