Page MenuHome

sequencerpreview_translation.diff

File Metadata

Author
Jehan Pagès (jehan)
Created
Nov 13 2013, 4:40 PM

sequencerpreview_translation.diff

Index: source/blender/editors/space_sequencer/sequencer_ops.c
===================================================================
--- source/blender/editors/space_sequencer/sequencer_ops.c (révision 54219)
+++ source/blender/editors/space_sequencer/sequencer_ops.c (copie de travail)
@@ -124,6 +124,7 @@
/* sequencer_view.h */
WM_operatortype_append(SEQUENCER_OT_sample);
+ WM_operatortype_append(SEQUENCER_OT_transform_preview);
}
@@ -343,6 +344,10 @@
/* sample */
WM_keymap_add_item(keymap, "SEQUENCER_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
+
+ /* Transformation */
+ WM_keymap_add_item(keymap, "SEQUENCER_OT_transform_preview", SELECTMOUSE, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "SEQUENCER_OT_transform_preview", GKEY, KM_PRESS, 0, 0);
}
void ED_operatormacros_sequencer(void)
Index: source/blender/editors/space_sequencer/sequencer_intern.h
===================================================================
--- source/blender/editors/space_sequencer/sequencer_intern.h (révision 54219)
+++ source/blender/editors/space_sequencer/sequencer_intern.h (copie de travail)
@@ -184,6 +184,7 @@
/* sequencer_view.c */
void SEQUENCER_OT_sample(struct wmOperatorType *ot);
+void SEQUENCER_OT_transform_preview(struct wmOperatorType *ot);
#endif /* __SEQUENCER_INTERN_H__ */
Index: source/blender/editors/space_sequencer/sequencer_view.c
===================================================================
--- source/blender/editors/space_sequencer/sequencer_view.c (révision 54219)
+++ source/blender/editors/space_sequencer/sequencer_view.c (copie de travail)
@@ -29,11 +29,14 @@
* \ingroup spseq
*/
+#include <pthread.h>
+
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
#include "BKE_context.h"
#include "BKE_main.h"
@@ -232,3 +235,204 @@
/* flags */
ot->flag = OPTYPE_BLOCKING;
}
+
+/******************** sequence visual transformation operator ********************/
+
+typedef struct SequenceTransformInfo {
+ pthread_mutex_t transform_lock;
+ int previous_event_x;
+ int previous_event_y;
+ int transformed_x;
+ int transformed_y;
+ bool invoked_by_mouse;
+} SequenceTransformInfo;
+
+static void sequencer_refresh_all(bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
+
+ BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
+}
+
+/* Cancel the on-going transformation. */
+static int sequencer_transform_preview_cancel(bContext *C, wmOperator *op)
+{
+ SequenceTransformInfo *info = op->customdata;
+ Scene *scene = CTX_data_scene(C);
+ Sequence *seq;
+ Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
+
+ pthread_mutex_lock(&info->transform_lock);
+ for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+ if (!(seq->flag & SELECT) || !(seq->flag & SEQ_USE_TRANSFORM)
+ || scene->r.cfra < BKE_sequence_tx_get_final_left(seq, 0)
+ || scene->r.cfra >= BKE_sequence_tx_get_final_right(seq, 0))
+ continue;
+ seq->strip->transform->xofs -= (seq->flag & SEQ_FLIPX? -1 : 1) * info->transformed_x;
+ seq->strip->transform->yofs -= (seq->flag & SEQ_FLIPY? -1 : 1) * info->transformed_y;
+ }
+ pthread_mutex_unlock(&info->transform_lock);
+ pthread_mutex_destroy(&info->transform_lock);
+ sequencer_refresh_all(C);
+ MEM_freeN(op->customdata);
+
+ return OPERATOR_CANCELLED;
+}
+
+static void sequencer_select_apply(bContext *C, wmOperator *op, wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+ float fx, fy;
+ float scale;
+ Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
+ Sequence *seq;
+ Strip *strip;
+ StripTransform *transform;
+ SequenceTransformInfo *info = op->customdata;
+ int transform_x, transform_y;
+
+ scale = (float) scene->r.size / 100.0f;
+ scale = scale == 0? 0.01f : scale;
+
+ pthread_mutex_lock(&info->transform_lock);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
+ transform_x = (int) ((fx - (float) info->previous_event_x) / scale);
+ transform_y = (int) ((fy - (float) info->previous_event_y) / scale);
+
+ for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+ if (!(seq->flag & SELECT) || !(seq->flag & SEQ_USE_TRANSFORM)
+ || scene->r.cfra < BKE_sequence_tx_get_final_left(seq, 0)
+ || scene->r.cfra >= BKE_sequence_tx_get_final_right(seq, 0))
+ continue;
+ if (seq->strip == NULL) {
+ seq->strip = MEM_callocN(sizeof(struct Strip), "Strip");
+ }
+ strip = seq->strip;
+ if (strip->transform == NULL) {
+ strip->transform = MEM_callocN(sizeof(struct StripTransform), "StripTransform");
+ }
+ transform = strip->transform;
+
+ transform->xofs += (seq->flag & SEQ_FLIPX? -1 : 1) * transform_x;
+ transform->yofs += (seq->flag & SEQ_FLIPY? -1 : 1) * transform_y;
+ }
+
+ info->transformed_x += transform_x;
+ info->transformed_y += transform_y;
+ info->previous_event_x = (int) fx;
+ info->previous_event_y = (int) fy;
+ pthread_mutex_unlock(&info->transform_lock);
+
+ if (pthread_mutex_trylock(&info->transform_lock) == 0)
+ {
+ sequencer_refresh_all(C);
+ pthread_mutex_unlock(&info->transform_lock);
+ }
+}
+
+static int sequencer_transform_preview_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ Sequence *seq = BKE_sequencer_active_get(scene);
+ ARegion *ar = CTX_wm_region(C);
+ float fx, fy;
+ SequenceTransformInfo *info;
+
+ if (! (seq && seq->flag & SEQ_USE_TRANSFORM && seq->strip && seq->strip->transform))
+ return OPERATOR_CANCELLED;
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
+
+ info = MEM_callocN(sizeof(SequenceTransformInfo), "SequenceTransformInfo");
+ info->previous_event_x = fx;
+ info->previous_event_y = fy;
+ info->transformed_x = 0;
+ info->transformed_y = 0;
+ pthread_mutex_init(&info->transform_lock, NULL);
+ op->customdata = info;
+
+ switch (event->type) {
+ case RIGHTMOUSE:
+ case LEFTMOUSE:
+ info->invoked_by_mouse = TRUE;
+ break;
+ default:
+ info->invoked_by_mouse = FALSE;
+ }
+
+ sequencer_select_apply(C, op, event);
+ WM_event_add_modal_handler(C, op);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int sequencer_transform_preview_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ SequenceTransformInfo *info = op->customdata;
+
+ switch (event->type) {
+ case RIGHTMOUSE:
+ {
+ if (!info->invoked_by_mouse)
+ return sequencer_transform_preview_cancel(C, op);
+ }
+ case LEFTMOUSE:
+ if (!info->invoked_by_mouse
+ || (event->type == LEFTMOUSE && U.flag & USER_LMOUSESELECT)
+ || (event->type == RIGHTMOUSE && !(U.flag & USER_LMOUSESELECT)))
+ {
+ if (info->invoked_by_mouse && event->val == KM_RELEASE && !(U.flag & USER_RELEASECONFIRM))
+ {
+ sequencer_select_apply(C, op, event);
+ break;
+ }
+
+ sequencer_select_apply(C, op, event);
+ MEM_freeN(op->customdata);
+ return OPERATOR_FINISHED;
+ }
+ case ESCKEY:
+ return sequencer_transform_preview_cancel(C, op);
+ case MOUSEMOVE:
+ sequencer_select_apply(C, op, event);
+ break;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int sequencer_transform_preview_poll(bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
+ Sequence *seq;
+
+ for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+ if (seq->flag & SELECT && seq->flag & SEQ_USE_TRANSFORM
+ && scene->r.cfra >= BKE_sequence_tx_get_final_left(seq, 0)
+ && scene->r.cfra < BKE_sequence_tx_get_final_right(seq, 0))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void SEQUENCER_OT_transform_preview(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Translate Selected Sequences";
+ ot->idname = "SEQUENCER_OT_transform_preview";
+ ot->description = "Use mouse to move selected translatable sequences in current frame";
+
+ /* api callbacks */
+ ot->invoke = sequencer_transform_preview_invoke;
+ ot->modal = sequencer_transform_preview_modal;
+ ot->cancel = sequencer_transform_preview_cancel;
+ ot->poll = sequencer_transform_preview_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING;
+}

Event Timeline