Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r--source/blender/editors/space_clip/CMakeLists.txt78
-rw-r--r--source/blender/editors/space_clip/clip_buttons.c1182
-rw-r--r--source/blender/editors/space_clip/clip_dopesheet_draw.c695
-rw-r--r--source/blender/editors/space_clip/clip_dopesheet_ops.c242
-rw-r--r--source/blender/editors/space_clip/clip_draw.c3076
-rw-r--r--source/blender/editors/space_clip/clip_editor.c1566
-rw-r--r--source/blender/editors/space_clip/clip_graph_draw.c487
-rw-r--r--source/blender/editors/space_clip/clip_graph_ops.c1002
-rw-r--r--source/blender/editors/space_clip/clip_intern.h74
-rw-r--r--source/blender/editors/space_clip/clip_ops.c1978
-rw-r--r--source/blender/editors/space_clip/clip_toolbar.c130
-rw-r--r--source/blender/editors/space_clip/clip_utils.c398
-rw-r--r--source/blender/editors/space_clip/space_clip.c2030
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c3333
-rw-r--r--source/blender/editors/space_clip/tracking_ops_detect.c203
-rw-r--r--source/blender/editors/space_clip/tracking_ops_intern.h3
-rw-r--r--source/blender/editors/space_clip/tracking_ops_orient.c1374
-rw-r--r--source/blender/editors/space_clip/tracking_ops_plane.c584
-rw-r--r--source/blender/editors/space_clip/tracking_ops_solve.c460
-rw-r--r--source/blender/editors/space_clip/tracking_ops_stabilize.c421
-rw-r--r--source/blender/editors/space_clip/tracking_ops_track.c707
-rw-r--r--source/blender/editors/space_clip/tracking_ops_utils.c46
-rw-r--r--source/blender/editors/space_clip/tracking_select.c1440
23 files changed, 10967 insertions, 10542 deletions
diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt
index 49d7efb5669..ed98dcdc159 100644
--- a/source/blender/editors/space_clip/CMakeLists.txt
+++ b/source/blender/editors/space_clip/CMakeLists.txt
@@ -18,60 +18,60 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- ../include
- ../../blenfont
- ../../blenkernel
- ../../blenlib
- ../../blentranslation
- ../../depsgraph
- ../../imbuf
- ../../gpu
- ../../makesdna
- ../../makesrna
- ../../windowmanager
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
+ ../include
+ ../../blenfont
+ ../../blenkernel
+ ../../blenlib
+ ../../blentranslation
+ ../../depsgraph
+ ../../imbuf
+ ../../gpu
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+ ../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
)
set(INC_SYS
- ${GLEW_INCLUDE_PATH}
+ ${GLEW_INCLUDE_PATH}
)
set(SRC
- clip_buttons.c
- clip_dopesheet_draw.c
- clip_dopesheet_ops.c
- clip_draw.c
- clip_editor.c
- clip_graph_draw.c
- clip_graph_ops.c
- clip_ops.c
- clip_toolbar.c
- clip_utils.c
- space_clip.c
- tracking_ops.c
- tracking_ops_detect.c
- tracking_ops_orient.c
- tracking_ops_plane.c
- tracking_ops_solve.c
- tracking_ops_stabilize.c
- tracking_ops_track.c
- tracking_ops_utils.c
- tracking_select.c
+ clip_buttons.c
+ clip_dopesheet_draw.c
+ clip_dopesheet_ops.c
+ clip_draw.c
+ clip_editor.c
+ clip_graph_draw.c
+ clip_graph_ops.c
+ clip_ops.c
+ clip_toolbar.c
+ clip_utils.c
+ space_clip.c
+ tracking_ops.c
+ tracking_ops_detect.c
+ tracking_ops_orient.c
+ tracking_ops_plane.c
+ tracking_ops_solve.c
+ tracking_ops_stabilize.c
+ tracking_ops_track.c
+ tracking_ops_utils.c
+ tracking_select.c
- clip_intern.h
- tracking_ops_intern.h
+ clip_intern.h
+ tracking_ops_intern.h
)
set(LIB
- bf_blenkernel
- bf_blenlib
+ bf_blenkernel
+ bf_blenlib
)
add_definitions(${GL_DEFINITIONS})
if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
+ add_definitions(-DWITH_INTERNATIONAL)
endif()
blender_add_lib(bf_editor_space_clip "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index 6e4b98af93b..6f950ec5bc4 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -60,554 +60,806 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-#include "clip_intern.h" /* own include */
+#include "clip_intern.h" /* own include */
/* Panels */
static bool metadata_panel_context_poll(const bContext *C, PanelType *UNUSED(pt))
{
- return ED_space_clip_poll((bContext *)C);
+ return ED_space_clip_poll((bContext *)C);
}
static void metadata_panel_context_draw(const bContext *C, Panel *panel)
{
- SpaceClip *space_clip = CTX_wm_space_clip(C);
- /* NOTE: This might not be exactly the same image buffer as shown in the
- * clip editor itself, since that might be coming from proxy, or being
- * postprocessed (stabilized or undistored).
- * Ideally we need to query metadata from an original image or movie without
- * reading actual pixels to speed up the process. */
- ImBuf *ibuf = ED_space_clip_get_buffer(space_clip);
- if (ibuf != NULL) {
- ED_region_image_metadata_panel_draw(ibuf, panel->layout);
- IMB_freeImBuf(ibuf);
- }
+ SpaceClip *space_clip = CTX_wm_space_clip(C);
+ /* NOTE: This might not be exactly the same image buffer as shown in the
+ * clip editor itself, since that might be coming from proxy, or being
+ * postprocessed (stabilized or undistored).
+ * Ideally we need to query metadata from an original image or movie without
+ * reading actual pixels to speed up the process. */
+ ImBuf *ibuf = ED_space_clip_get_buffer(space_clip);
+ if (ibuf != NULL) {
+ ED_region_image_metadata_panel_draw(ibuf, panel->layout);
+ IMB_freeImBuf(ibuf);
+ }
}
void ED_clip_buttons_register(ARegionType *art)
{
- PanelType *pt;
-
- pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel metadata");
- strcpy(pt->idname, "CLIP_PT_metadata");
- strcpy(pt->label, N_("Metadata"));
- strcpy(pt->category, "Footage");
- strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
- pt->poll = metadata_panel_context_poll;
- pt->draw = metadata_panel_context_draw;
- pt->flag |= PNL_DEFAULT_CLOSED;
- BLI_addtail(&art->paneltypes, pt);
+ PanelType *pt;
+
+ pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel metadata");
+ strcpy(pt->idname, "CLIP_PT_metadata");
+ strcpy(pt->label, N_("Metadata"));
+ strcpy(pt->category, "Footage");
+ strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+ pt->poll = metadata_panel_context_poll;
+ pt->draw = metadata_panel_context_draw;
+ pt->flag |= PNL_DEFAULT_CLOSED;
+ BLI_addtail(&art->paneltypes, pt);
}
/********************* MovieClip Template ************************/
-void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, bool compact)
+void uiTemplateMovieClip(
+ uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, bool compact)
{
- PropertyRNA *prop;
- PointerRNA clipptr;
- MovieClip *clip;
- uiLayout *row, *split;
- uiBlock *block;
-
- if (!ptr->data)
- return;
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- printf("%s: property not found: %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- if (RNA_property_type(prop) != PROP_POINTER) {
- printf("%s: expected pointer property for %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- clipptr = RNA_property_pointer_get(ptr, prop);
- clip = clipptr.data;
-
- uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
-
- if (!compact)
- uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
-
- if (clip) {
- uiLayout *col;
-
- row = uiLayoutRow(layout, false);
- block = uiLayoutGetBlock(row);
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("File Path:"), 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
-
- row = uiLayoutRow(layout, false);
- split = uiLayoutSplit(row, 0.0f, false);
- row = uiLayoutRow(split, true);
-
- uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
- uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
-
- col = uiLayoutColumn(layout, false);
- uiTemplateColorspaceSettings(col, &clipptr, "colorspace_settings");
- }
+ PropertyRNA *prop;
+ PointerRNA clipptr;
+ MovieClip *clip;
+ uiLayout *row, *split;
+ uiBlock *block;
+
+ if (!ptr->data)
+ return;
+
+ prop = RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf(
+ "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+
+ if (RNA_property_type(prop) != PROP_POINTER) {
+ printf("%s: expected pointer property for %s.%s\n",
+ __func__,
+ RNA_struct_identifier(ptr->type),
+ propname);
+ return;
+ }
+
+ clipptr = RNA_property_pointer_get(ptr, prop);
+ clip = clipptr.data;
+
+ uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
+
+ if (!compact)
+ uiTemplateID(
+ layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
+
+ if (clip) {
+ uiLayout *col;
+
+ row = uiLayoutRow(layout, false);
+ block = uiLayoutGetBlock(row);
+ uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("File Path:"), 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
+
+ row = uiLayoutRow(layout, false);
+ split = uiLayoutSplit(row, 0.0f, false);
+ row = uiLayoutRow(split, true);
+
+ uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
+ uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
+
+ col = uiLayoutColumn(layout, false);
+ uiTemplateColorspaceSettings(col, &clipptr, "colorspace_settings");
+ }
}
/********************* Track Template ************************/
void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
- PropertyRNA *prop;
- PointerRNA scopesptr;
- uiBlock *block;
- uiLayout *col;
- MovieClipScopes *scopes;
-
- if (!ptr->data)
- return;
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- printf("%s: property not found: %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- if (RNA_property_type(prop) != PROP_POINTER) {
- printf("%s: expected pointer property for %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- scopesptr = RNA_property_pointer_get(ptr, prop);
- scopes = (MovieClipScopes *)scopesptr.data;
-
- if (scopes->track_preview_height < UI_UNIT_Y) {
- scopes->track_preview_height = UI_UNIT_Y;
- }
- else if (scopes->track_preview_height > UI_UNIT_Y * 20) {
- scopes->track_preview_height = UI_UNIT_Y * 20;
- }
-
- col = uiLayoutColumn(layout, true);
- block = uiLayoutGetBlock(col);
-
- uiDefBut(block, UI_BTYPE_TRACK_PREVIEW, 0, "", 0, 0, UI_UNIT_X * 10, scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
-
- /* Resize grip. */
- uiDefIconButI(block, UI_BTYPE_GRIP, 0, ICON_GRIP, 0, 0, UI_UNIT_X * 10, (short)(UI_UNIT_Y * 0.8f),
- &scopes->track_preview_height, UI_UNIT_Y, UI_UNIT_Y * 20.0f, 0.0f, 0.0f, "");
+ PropertyRNA *prop;
+ PointerRNA scopesptr;
+ uiBlock *block;
+ uiLayout *col;
+ MovieClipScopes *scopes;
+
+ if (!ptr->data)
+ return;
+
+ prop = RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf(
+ "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+
+ if (RNA_property_type(prop) != PROP_POINTER) {
+ printf("%s: expected pointer property for %s.%s\n",
+ __func__,
+ RNA_struct_identifier(ptr->type),
+ propname);
+ return;
+ }
+
+ scopesptr = RNA_property_pointer_get(ptr, prop);
+ scopes = (MovieClipScopes *)scopesptr.data;
+
+ if (scopes->track_preview_height < UI_UNIT_Y) {
+ scopes->track_preview_height = UI_UNIT_Y;
+ }
+ else if (scopes->track_preview_height > UI_UNIT_Y * 20) {
+ scopes->track_preview_height = UI_UNIT_Y * 20;
+ }
+
+ col = uiLayoutColumn(layout, true);
+ block = uiLayoutGetBlock(col);
+
+ uiDefBut(block,
+ UI_BTYPE_TRACK_PREVIEW,
+ 0,
+ "",
+ 0,
+ 0,
+ UI_UNIT_X * 10,
+ scopes->track_preview_height,
+ scopes,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+
+ /* Resize grip. */
+ uiDefIconButI(block,
+ UI_BTYPE_GRIP,
+ 0,
+ ICON_GRIP,
+ 0,
+ 0,
+ UI_UNIT_X * 10,
+ (short)(UI_UNIT_Y * 0.8f),
+ &scopes->track_preview_height,
+ UI_UNIT_Y,
+ UI_UNIT_Y * 20.0f,
+ 0.0f,
+ 0.0f,
+ "");
}
/********************* Marker Template ************************/
-#define B_MARKER_POS 3
-#define B_MARKER_OFFSET 4
-#define B_MARKER_PAT_DIM 5
-#define B_MARKER_SEARCH_POS 6
-#define B_MARKER_SEARCH_DIM 7
-#define B_MARKER_FLAG 8
+#define B_MARKER_POS 3
+#define B_MARKER_OFFSET 4
+#define B_MARKER_PAT_DIM 5
+#define B_MARKER_SEARCH_POS 6
+#define B_MARKER_SEARCH_DIM 7
+#define B_MARKER_FLAG 8
typedef struct {
- /** compact mode */
- int compact;
-
- MovieClip *clip;
- /** user of clip */
- MovieClipUser *user;
- MovieTrackingTrack *track;
- MovieTrackingMarker *marker;
-
- /** current frame number */
- int framenr;
- /** position of marker in pixel coords */
- float marker_pos[2];
- /** position and dimensions of marker pattern in pixel coords */
- float marker_pat[2];
- /** offset of "parenting" point */
- float track_offset[2];
- /** position and dimensions of marker search in pixel coords */
- float marker_search_pos[2], marker_search[2];
- /** marker's flags */
- int marker_flag;
+ /** compact mode */
+ int compact;
+
+ MovieClip *clip;
+ /** user of clip */
+ MovieClipUser *user;
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
+
+ /** current frame number */
+ int framenr;
+ /** position of marker in pixel coords */
+ float marker_pos[2];
+ /** position and dimensions of marker pattern in pixel coords */
+ float marker_pat[2];
+ /** offset of "parenting" point */
+ float track_offset[2];
+ /** position and dimensions of marker search in pixel coords */
+ float marker_search_pos[2], marker_search[2];
+ /** marker's flags */
+ int marker_flag;
} MarkerUpdateCb;
static void to_pixel_space(float r[2], float a[2], int width, int height)
{
- copy_v2_v2(r, a);
- r[0] *= width;
- r[1] *= height;
+ copy_v2_v2(r, a);
+ r[0] *= width;
+ r[1] *= height;
}
static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
{
- MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
- MovieTrackingMarker *marker;
+ MarkerUpdateCb *cb = (MarkerUpdateCb *)arg_cb;
+ MovieTrackingMarker *marker;
- if (!cb->compact)
- return;
+ if (!cb->compact)
+ return;
- marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
+ marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
- marker->flag = cb->marker_flag;
+ marker->flag = cb->marker_flag;
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
}
static void marker_block_handler(bContext *C, void *arg_cb, int event)
{
- MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
- MovieTrackingMarker *marker;
- int width, height;
- bool ok = false;
+ MarkerUpdateCb *cb = (MarkerUpdateCb *)arg_cb;
+ MovieTrackingMarker *marker;
+ int width, height;
+ bool ok = false;
- BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
+ BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
- marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
+ marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
- if (event == B_MARKER_POS) {
- marker->pos[0] = cb->marker_pos[0] / width;
- marker->pos[1] = cb->marker_pos[1] / height;
+ if (event == B_MARKER_POS) {
+ marker->pos[0] = cb->marker_pos[0] / width;
+ marker->pos[1] = cb->marker_pos[1] / height;
- /* to update position of "parented" objects */
- DEG_id_tag_update(&cb->clip->id, 0);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ /* to update position of "parented" objects */
+ DEG_id_tag_update(&cb->clip->id, 0);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- ok = true;
- }
- else if (event == B_MARKER_PAT_DIM) {
- float dim[2], pat_dim[2], pat_min[2], pat_max[2];
- float scale_x, scale_y;
- int a;
+ ok = true;
+ }
+ else if (event == B_MARKER_PAT_DIM) {
+ float dim[2], pat_dim[2], pat_min[2], pat_max[2];
+ float scale_x, scale_y;
+ int a;
- BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
+ BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
- sub_v2_v2v2(pat_dim, pat_max, pat_min);
+ sub_v2_v2v2(pat_dim, pat_max, pat_min);
- dim[0] = cb->marker_pat[0] / width;
- dim[1] = cb->marker_pat[1] / height;
+ dim[0] = cb->marker_pat[0] / width;
+ dim[1] = cb->marker_pat[1] / height;
- scale_x = dim[0] / pat_dim[0];
- scale_y = dim[1] / pat_dim[1];
+ scale_x = dim[0] / pat_dim[0];
+ scale_y = dim[1] / pat_dim[1];
- for (a = 0; a < 4; a++) {
- cb->marker->pattern_corners[a][0] *= scale_x;
- cb->marker->pattern_corners[a][1] *= scale_y;
- }
+ for (a = 0; a < 4; a++) {
+ cb->marker->pattern_corners[a][0] *= scale_x;
+ cb->marker->pattern_corners[a][1] *= scale_y;
+ }
- BKE_tracking_marker_clamp(cb->marker, CLAMP_PAT_DIM);
+ BKE_tracking_marker_clamp(cb->marker, CLAMP_PAT_DIM);
- ok = true;
- }
- else if (event == B_MARKER_SEARCH_POS) {
- float delta[2], side[2];
+ ok = true;
+ }
+ else if (event == B_MARKER_SEARCH_POS) {
+ float delta[2], side[2];
- sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
- mul_v2_fl(side, 0.5f);
+ sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
+ mul_v2_fl(side, 0.5f);
- delta[0] = cb->marker_search_pos[0] / width;
- delta[1] = cb->marker_search_pos[1] / height;
+ delta[0] = cb->marker_search_pos[0] / width;
+ delta[1] = cb->marker_search_pos[1] / height;
- sub_v2_v2v2(cb->marker->search_min, delta, side);
- add_v2_v2v2(cb->marker->search_max, delta, side);
+ sub_v2_v2v2(cb->marker->search_min, delta, side);
+ add_v2_v2v2(cb->marker->search_max, delta, side);
- BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_POS);
+ BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_POS);
- ok = true;
- }
- else if (event == B_MARKER_SEARCH_DIM) {
- float dim[2], search_dim[2];
+ ok = true;
+ }
+ else if (event == B_MARKER_SEARCH_DIM) {
+ float dim[2], search_dim[2];
- sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
+ sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
- dim[0] = cb->marker_search[0] / width;
- dim[1] = cb->marker_search[1] / height;
+ dim[0] = cb->marker_search[0] / width;
+ dim[1] = cb->marker_search[1] / height;
- sub_v2_v2(dim, search_dim);
- mul_v2_fl(dim, 0.5f);
+ sub_v2_v2(dim, search_dim);
+ mul_v2_fl(dim, 0.5f);
- cb->marker->search_min[0] -= dim[0];
- cb->marker->search_min[1] -= dim[1];
+ cb->marker->search_min[0] -= dim[0];
+ cb->marker->search_min[1] -= dim[1];
- cb->marker->search_max[0] += dim[0];
- cb->marker->search_max[1] += dim[1];
+ cb->marker->search_max[0] += dim[0];
+ cb->marker->search_max[1] += dim[1];
- BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_DIM);
+ BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_DIM);
- ok = true;
- }
- else if (event == B_MARKER_FLAG) {
- marker->flag = cb->marker_flag;
+ ok = true;
+ }
+ else if (event == B_MARKER_FLAG) {
+ marker->flag = cb->marker_flag;
- ok = true;
- }
- else if (event == B_MARKER_OFFSET) {
- float offset[2], delta[2];
- int i;
+ ok = true;
+ }
+ else if (event == B_MARKER_OFFSET) {
+ float offset[2], delta[2];
+ int i;
- offset[0] = cb->track_offset[0] / width;
- offset[1] = cb->track_offset[1] / height;
+ offset[0] = cb->track_offset[0] / width;
+ offset[1] = cb->track_offset[1] / height;
- sub_v2_v2v2(delta, offset, cb->track->offset);
- copy_v2_v2(cb->track->offset, offset);
+ sub_v2_v2v2(delta, offset, cb->track->offset);
+ copy_v2_v2(cb->track->offset, offset);
- for (i = 0; i < cb->track->markersnr; i++)
- sub_v2_v2(cb->track->markers[i].pos, delta);
+ for (i = 0; i < cb->track->markersnr; i++)
+ sub_v2_v2(cb->track->markers[i].pos, delta);
- /* to update position of "parented" objects */
- DEG_id_tag_update(&cb->clip->id, 0);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ /* to update position of "parented" objects */
+ DEG_id_tag_update(&cb->clip->id, 0);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- ok = true;
- }
+ ok = true;
+ }
- if (ok)
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
+ if (ok)
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
}
-void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr,
- PointerRNA *trackptr, bool compact)
+void uiTemplateMarker(uiLayout *layout,
+ PointerRNA *ptr,
+ const char *propname,
+ PointerRNA *userptr,
+ PointerRNA *trackptr,
+ bool compact)
{
- PropertyRNA *prop;
- uiBlock *block;
- uiBut *bt;
- PointerRNA clipptr;
- MovieClip *clip;
- MovieClipUser *user;
- MovieTrackingTrack *track;
- MovieTrackingMarker *marker;
- MarkerUpdateCb *cb;
- const char *tip;
- float pat_min[2], pat_max[2];
-
- if (!ptr->data)
- return;
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- printf("%s: property not found: %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- if (RNA_property_type(prop) != PROP_POINTER) {
- printf("%s: expected pointer property for %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- clipptr = RNA_property_pointer_get(ptr, prop);
- clip = (MovieClip *)clipptr.data;
- user = userptr->data;
- track = trackptr->data;
-
- marker = BKE_tracking_marker_get(track, user->framenr);
-
- cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
- cb->compact = compact;
- cb->clip = clip;
- cb->user = user;
- cb->track = track;
- cb->marker = marker;
- cb->marker_flag = marker->flag;
- cb->framenr = user->framenr;
-
- if (compact) {
- block = uiLayoutGetBlock(layout);
-
- if (cb->marker_flag & MARKER_DISABLED)
- tip = TIP_("Marker is disabled at current frame");
- else
- tip = TIP_("Marker is enabled at current frame");
-
- bt = uiDefIconButBitI(block, UI_BTYPE_TOGGLE_N, MARKER_DISABLED, 0, ICON_HIDE_OFF, 0, 0, UI_UNIT_X, UI_UNIT_Y,
- &cb->marker_flag, 0, 0, 1, 0, tip);
- UI_but_funcN_set(bt, marker_update_cb, cb, NULL);
- UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
- }
- else {
- int width, height, step, digits;
- float pat_dim[2], search_dim[2], search_pos[2];
- uiLayout *col;
-
- BKE_movieclip_get_size(clip, user, &width, &height);
-
- if (track->flag & TRACK_LOCKED) {
- uiLayoutSetActive(layout, false);
- block = uiLayoutAbsoluteBlock(layout);
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Track is locked"), 0, 0, UI_UNIT_X * 15.0f, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
-
- return;
- }
-
- step = 100;
- digits = 2;
-
- BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
-
- sub_v2_v2v2(pat_dim, pat_max, pat_min);
- sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
-
- add_v2_v2v2(search_pos, marker->search_max, marker->search_min);
- mul_v2_fl(search_pos, 0.5);
-
- to_pixel_space(cb->marker_pos, marker->pos, width, height);
- to_pixel_space(cb->marker_pat, pat_dim, width, height);
- to_pixel_space(cb->marker_search, search_dim, width, height);
- to_pixel_space(cb->marker_search_pos, search_pos, width, height);
- to_pixel_space(cb->track_offset, track->offset, width, height);
-
- cb->marker_flag = marker->flag;
-
- block = uiLayoutAbsoluteBlock(layout);
- UI_block_func_handle_set(block, marker_block_handler, cb);
- UI_block_funcN_set(block, marker_update_cb, cb, NULL);
-
- if (cb->marker_flag & MARKER_DISABLED)
- tip = TIP_("Marker is disabled at current frame");
- else
- tip = TIP_("Marker is enabled at current frame");
-
- uiDefButBitI(block, UI_BTYPE_CHECKBOX_N, MARKER_DISABLED, B_MARKER_FLAG, IFACE_("Enabled"), 0.5 * UI_UNIT_X, 9.5 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y,
- &cb->marker_flag, 0, 0, 0, 0, tip);
-
- col = uiLayoutColumn(layout, true);
- uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0);
-
- block = uiLayoutAbsoluteBlock(col);
- UI_block_align_begin(block);
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Position:"), 0, 10 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_POS, IFACE_("X:"), 0.5 * UI_UNIT_X, 9 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_pos[0],
- -10 * width, 10.0 * width, step, digits, TIP_("X-position of marker at frame in screen coordinates"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_POS, IFACE_("Y:"), 8.25 * UI_UNIT_X, 9 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_pos[1],
- -10 * height, 10.0 * height, step, digits,
- TIP_("Y-position of marker at frame in screen coordinates"));
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Offset:"), 0, 8 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_OFFSET, IFACE_("X:"), 0.5 * UI_UNIT_X, 7 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->track_offset[0],
- -10 * width, 10.0 * width, step, digits, TIP_("X-offset to parenting point"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_OFFSET, IFACE_("Y:"), 8.25 * UI_UNIT_X, 7 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->track_offset[1],
- -10 * height, 10.0 * height, step, digits, TIP_("Y-offset to parenting point"));
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Pattern Area:"), 0, 6 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_PAT_DIM, IFACE_("Width:"), 0.5 * UI_UNIT_X, 5 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_pat[0], 3.0f,
- 10.0 * width, step, digits, TIP_("Width of marker's pattern in screen coordinates"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_PAT_DIM, IFACE_("Height:"), 0.5 * UI_UNIT_X, 4 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_pat[1], 3.0f,
- 10.0 * height, step, digits, TIP_("Height of marker's pattern in screen coordinates"));
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Search Area:"), 0, 3 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_SEARCH_POS, IFACE_("X:"), 0.5 * UI_UNIT_X, 2 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_search_pos[0],
- -width, width, step, digits, TIP_("X-position of search at frame relative to marker's position"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_SEARCH_POS, IFACE_("Y:"), 8.25 * UI_UNIT_X, 2 * UI_UNIT_Y, 7.25 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_search_pos[1],
- -height, height, step, digits, TIP_("Y-position of search at frame relative to marker's position"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_SEARCH_DIM, IFACE_("Width:"), 0.5 * UI_UNIT_X, 1 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_search[0], 3.0f,
- 10.0 * width, step, digits, TIP_("Width of marker's search in screen coordinates"));
- uiDefButF(block, UI_BTYPE_NUM, B_MARKER_SEARCH_DIM, IFACE_("Height:"), 0.5 * UI_UNIT_X, 0 * UI_UNIT_Y, 15 * UI_UNIT_X, UI_UNIT_Y, &cb->marker_search[1], 3.0f,
- 10.0 * height, step, digits, TIP_("Height of marker's search in screen coordinates"));
-
- UI_block_align_end(block);
- }
+ PropertyRNA *prop;
+ uiBlock *block;
+ uiBut *bt;
+ PointerRNA clipptr;
+ MovieClip *clip;
+ MovieClipUser *user;
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
+ MarkerUpdateCb *cb;
+ const char *tip;
+ float pat_min[2], pat_max[2];
+
+ if (!ptr->data)
+ return;
+
+ prop = RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf(
+ "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+
+ if (RNA_property_type(prop) != PROP_POINTER) {
+ printf("%s: expected pointer property for %s.%s\n",
+ __func__,
+ RNA_struct_identifier(ptr->type),
+ propname);
+ return;
+ }
+
+ clipptr = RNA_property_pointer_get(ptr, prop);
+ clip = (MovieClip *)clipptr.data;
+ user = userptr->data;
+ track = trackptr->data;
+
+ marker = BKE_tracking_marker_get(track, user->framenr);
+
+ cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
+ cb->compact = compact;
+ cb->clip = clip;
+ cb->user = user;
+ cb->track = track;
+ cb->marker = marker;
+ cb->marker_flag = marker->flag;
+ cb->framenr = user->framenr;
+
+ if (compact) {
+ block = uiLayoutGetBlock(layout);
+
+ if (cb->marker_flag & MARKER_DISABLED)
+ tip = TIP_("Marker is disabled at current frame");
+ else
+ tip = TIP_("Marker is enabled at current frame");
+
+ bt = uiDefIconButBitI(block,
+ UI_BTYPE_TOGGLE_N,
+ MARKER_DISABLED,
+ 0,
+ ICON_HIDE_OFF,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_flag,
+ 0,
+ 0,
+ 1,
+ 0,
+ tip);
+ UI_but_funcN_set(bt, marker_update_cb, cb, NULL);
+ UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
+ }
+ else {
+ int width, height, step, digits;
+ float pat_dim[2], search_dim[2], search_pos[2];
+ uiLayout *col;
+
+ BKE_movieclip_get_size(clip, user, &width, &height);
+
+ if (track->flag & TRACK_LOCKED) {
+ uiLayoutSetActive(layout, false);
+ block = uiLayoutAbsoluteBlock(layout);
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Track is locked"),
+ 0,
+ 0,
+ UI_UNIT_X * 15.0f,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+
+ return;
+ }
+
+ step = 100;
+ digits = 2;
+
+ BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+ sub_v2_v2v2(pat_dim, pat_max, pat_min);
+ sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
+
+ add_v2_v2v2(search_pos, marker->search_max, marker->search_min);
+ mul_v2_fl(search_pos, 0.5);
+
+ to_pixel_space(cb->marker_pos, marker->pos, width, height);
+ to_pixel_space(cb->marker_pat, pat_dim, width, height);
+ to_pixel_space(cb->marker_search, search_dim, width, height);
+ to_pixel_space(cb->marker_search_pos, search_pos, width, height);
+ to_pixel_space(cb->track_offset, track->offset, width, height);
+
+ cb->marker_flag = marker->flag;
+
+ block = uiLayoutAbsoluteBlock(layout);
+ UI_block_func_handle_set(block, marker_block_handler, cb);
+ UI_block_funcN_set(block, marker_update_cb, cb, NULL);
+
+ if (cb->marker_flag & MARKER_DISABLED)
+ tip = TIP_("Marker is disabled at current frame");
+ else
+ tip = TIP_("Marker is enabled at current frame");
+
+ uiDefButBitI(block,
+ UI_BTYPE_CHECKBOX_N,
+ MARKER_DISABLED,
+ B_MARKER_FLAG,
+ IFACE_("Enabled"),
+ 0.5 * UI_UNIT_X,
+ 9.5 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_flag,
+ 0,
+ 0,
+ 0,
+ 0,
+ tip);
+
+ col = uiLayoutColumn(layout, true);
+ uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0);
+
+ block = uiLayoutAbsoluteBlock(col);
+ UI_block_align_begin(block);
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Position:"),
+ 0,
+ 10 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_POS,
+ IFACE_("X:"),
+ 0.5 * UI_UNIT_X,
+ 9 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_pos[0],
+ -10 * width,
+ 10.0 * width,
+ step,
+ digits,
+ TIP_("X-position of marker at frame in screen coordinates"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_POS,
+ IFACE_("Y:"),
+ 8.25 * UI_UNIT_X,
+ 9 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_pos[1],
+ -10 * height,
+ 10.0 * height,
+ step,
+ digits,
+ TIP_("Y-position of marker at frame in screen coordinates"));
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Offset:"),
+ 0,
+ 8 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_OFFSET,
+ IFACE_("X:"),
+ 0.5 * UI_UNIT_X,
+ 7 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->track_offset[0],
+ -10 * width,
+ 10.0 * width,
+ step,
+ digits,
+ TIP_("X-offset to parenting point"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_OFFSET,
+ IFACE_("Y:"),
+ 8.25 * UI_UNIT_X,
+ 7 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->track_offset[1],
+ -10 * height,
+ 10.0 * height,
+ step,
+ digits,
+ TIP_("Y-offset to parenting point"));
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Pattern Area:"),
+ 0,
+ 6 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_PAT_DIM,
+ IFACE_("Width:"),
+ 0.5 * UI_UNIT_X,
+ 5 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_pat[0],
+ 3.0f,
+ 10.0 * width,
+ step,
+ digits,
+ TIP_("Width of marker's pattern in screen coordinates"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_PAT_DIM,
+ IFACE_("Height:"),
+ 0.5 * UI_UNIT_X,
+ 4 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_pat[1],
+ 3.0f,
+ 10.0 * height,
+ step,
+ digits,
+ TIP_("Height of marker's pattern in screen coordinates"));
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Search Area:"),
+ 0,
+ 3 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_SEARCH_POS,
+ IFACE_("X:"),
+ 0.5 * UI_UNIT_X,
+ 2 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_search_pos[0],
+ -width,
+ width,
+ step,
+ digits,
+ TIP_("X-position of search at frame relative to marker's position"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_SEARCH_POS,
+ IFACE_("Y:"),
+ 8.25 * UI_UNIT_X,
+ 2 * UI_UNIT_Y,
+ 7.25 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_search_pos[1],
+ -height,
+ height,
+ step,
+ digits,
+ TIP_("Y-position of search at frame relative to marker's position"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_SEARCH_DIM,
+ IFACE_("Width:"),
+ 0.5 * UI_UNIT_X,
+ 1 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_search[0],
+ 3.0f,
+ 10.0 * width,
+ step,
+ digits,
+ TIP_("Width of marker's search in screen coordinates"));
+ uiDefButF(block,
+ UI_BTYPE_NUM,
+ B_MARKER_SEARCH_DIM,
+ IFACE_("Height:"),
+ 0.5 * UI_UNIT_X,
+ 0 * UI_UNIT_Y,
+ 15 * UI_UNIT_X,
+ UI_UNIT_Y,
+ &cb->marker_search[1],
+ 3.0f,
+ 10.0 * height,
+ step,
+ digits,
+ TIP_("Height of marker's search in screen coordinates"));
+
+ UI_block_align_end(block);
+ }
}
/********************* Footage Information Template ************************/
-void uiTemplateMovieclipInformation(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr)
+void uiTemplateMovieclipInformation(uiLayout *layout,
+ PointerRNA *ptr,
+ const char *propname,
+ PointerRNA *userptr)
{
- PropertyRNA *prop;
- PointerRNA clipptr;
- MovieClip *clip;
- MovieClipUser *user;
- uiLayout *col;
- char str[1024];
- int width, height, framenr;
- ImBuf *ibuf;
- size_t ofs = 0;
-
- if (!ptr->data)
- return;
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- printf("%s: property not found: %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- if (RNA_property_type(prop) != PROP_POINTER) {
- printf("%s: expected pointer property for %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- clipptr = RNA_property_pointer_get(ptr, prop);
- clip = (MovieClip *)clipptr.data;
- user = userptr->data;
-
- col = uiLayoutColumn(layout, false);
-
- ibuf = BKE_movieclip_get_ibuf_flag(clip, user, clip->flag, MOVIECLIP_CACHE_SKIP);
-
- /* Display frame dimensions, channels number and byffer type. */
- BKE_movieclip_get_size(clip, user, &width, &height);
- ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Size %d x %d"), width, height);
-
- if (ibuf) {
- if (ibuf->rect_float) {
- if (ibuf->channels != 4)
- ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_(", %d float channel(s)"), ibuf->channels);
- else if (ibuf->planes == R_IMF_PLANES_RGBA)
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA float"), sizeof(str) - ofs);
- else
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB float"), sizeof(str) - ofs);
- }
- else {
- if (ibuf->planes == R_IMF_PLANES_RGBA)
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA byte"), sizeof(str) - ofs);
- else
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB byte"), sizeof(str) - ofs);
- }
-
- if (clip->anim != NULL) {
- short frs_sec;
- float frs_sec_base;
- if (IMB_anim_get_fps(clip->anim, &frs_sec, &frs_sec_base, true)) {
- ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs,
- IFACE_(", %.2f fps"),
- (float)frs_sec / frs_sec_base);
- }
- }
- }
- else {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", failed to load"), sizeof(str) - ofs);
- }
-
- uiItemL(col, str, ICON_NONE);
-
- /* Display current frame number. */
- framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
- if (framenr <= clip->len)
- BLI_snprintf(str, sizeof(str), IFACE_("Frame: %d / %d"), framenr, clip->len);
- else
- BLI_snprintf(str, sizeof(str), IFACE_("Frame: - / %d"), clip->len);
- uiItemL(col, str, ICON_NONE);
-
- /* Display current file name if it's a sequence clip. */
- if (clip->source == MCLIP_SRC_SEQUENCE) {
- char filepath[FILE_MAX];
- const char *file;
-
- if (framenr <= clip->len) {
- BKE_movieclip_filename_for_frame(clip, user, filepath);
- file = BLI_last_slash(filepath);
- }
- else {
- file = "-";
- }
-
- BLI_snprintf(str, sizeof(str), IFACE_("File: %s"), file);
-
- uiItemL(col, str, ICON_NONE);
- }
-
- IMB_freeImBuf(ibuf);
+ PropertyRNA *prop;
+ PointerRNA clipptr;
+ MovieClip *clip;
+ MovieClipUser *user;
+ uiLayout *col;
+ char str[1024];
+ int width, height, framenr;
+ ImBuf *ibuf;
+ size_t ofs = 0;
+
+ if (!ptr->data)
+ return;
+
+ prop = RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf(
+ "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+
+ if (RNA_property_type(prop) != PROP_POINTER) {
+ printf("%s: expected pointer property for %s.%s\n",
+ __func__,
+ RNA_struct_identifier(ptr->type),
+ propname);
+ return;
+ }
+
+ clipptr = RNA_property_pointer_get(ptr, prop);
+ clip = (MovieClip *)clipptr.data;
+ user = userptr->data;
+
+ col = uiLayoutColumn(layout, false);
+
+ ibuf = BKE_movieclip_get_ibuf_flag(clip, user, clip->flag, MOVIECLIP_CACHE_SKIP);
+
+ /* Display frame dimensions, channels number and byffer type. */
+ BKE_movieclip_get_size(clip, user, &width, &height);
+ ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Size %d x %d"), width, height);
+
+ if (ibuf) {
+ if (ibuf->rect_float) {
+ if (ibuf->channels != 4)
+ ofs += BLI_snprintf(
+ str + ofs, sizeof(str) - ofs, IFACE_(", %d float channel(s)"), ibuf->channels);
+ else if (ibuf->planes == R_IMF_PLANES_RGBA)
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA float"), sizeof(str) - ofs);
+ else
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB float"), sizeof(str) - ofs);
+ }
+ else {
+ if (ibuf->planes == R_IMF_PLANES_RGBA)
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA byte"), sizeof(str) - ofs);
+ else
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB byte"), sizeof(str) - ofs);
+ }
+
+ if (clip->anim != NULL) {
+ short frs_sec;
+ float frs_sec_base;
+ if (IMB_anim_get_fps(clip->anim, &frs_sec, &frs_sec_base, true)) {
+ ofs += BLI_snprintf(
+ str + ofs, sizeof(str) - ofs, IFACE_(", %.2f fps"), (float)frs_sec / frs_sec_base);
+ }
+ }
+ }
+ else {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", failed to load"), sizeof(str) - ofs);
+ }
+
+ uiItemL(col, str, ICON_NONE);
+
+ /* Display current frame number. */
+ framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
+ if (framenr <= clip->len)
+ BLI_snprintf(str, sizeof(str), IFACE_("Frame: %d / %d"), framenr, clip->len);
+ else
+ BLI_snprintf(str, sizeof(str), IFACE_("Frame: - / %d"), clip->len);
+ uiItemL(col, str, ICON_NONE);
+
+ /* Display current file name if it's a sequence clip. */
+ if (clip->source == MCLIP_SRC_SEQUENCE) {
+ char filepath[FILE_MAX];
+ const char *file;
+
+ if (framenr <= clip->len) {
+ BKE_movieclip_filename_for_frame(clip, user, filepath);
+ file = BLI_last_slash(filepath);
+ }
+ else {
+ file = "-";
+ }
+
+ BLI_snprintf(str, sizeof(str), IFACE_("File: %s"), file);
+
+ uiItemL(col, str, ICON_NONE);
+ }
+
+ IMB_freeImBuf(ibuf);
}
diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c
index ef2e5b4ea3a..8ac0870f7f1 100644
--- a/source/blender/editors/space_clip/clip_dopesheet_draw.c
+++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c
@@ -48,360 +48,381 @@
#include "GPU_immediate.h"
#include "GPU_state.h"
-#include "clip_intern.h" /* own include */
+#include "clip_intern.h" /* own include */
static void track_channel_color(MovieTrackingTrack *track, float default_color[3], float color[3])
{
- if (track->flag & TRACK_CUSTOMCOLOR) {
- float bg[3];
- UI_GetThemeColor3fv(TH_HEADER, bg);
-
- interp_v3_v3v3(color, track->color, bg, 0.5);
- }
- else {
- if (default_color)
- copy_v3_v3(color, default_color);
- else
- UI_GetThemeColor3fv(TH_HEADER, color);
- }
+ if (track->flag & TRACK_CUSTOMCOLOR) {
+ float bg[3];
+ UI_GetThemeColor3fv(TH_HEADER, bg);
+
+ interp_v3_v3v3(color, track->color, bg, 0.5);
+ }
+ else {
+ if (default_color)
+ copy_v3_v3(color, default_color);
+ else
+ UI_GetThemeColor3fv(TH_HEADER, color);
+ }
}
-static void draw_keyframe_shape(float x, float y, bool sel, float alpha,
- unsigned int pos_id, unsigned int color_id)
+static void draw_keyframe_shape(
+ float x, float y, bool sel, float alpha, unsigned int pos_id, unsigned int color_id)
{
- float color[4] = { 0.91f, 0.91f, 0.91f, alpha };
- if (sel) {
- UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
- }
+ float color[4] = {0.91f, 0.91f, 0.91f, alpha};
+ if (sel) {
+ UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
+ }
- immAttr4fv(color_id, color);
- immVertex2f(pos_id, x, y);
+ immAttr4fv(color_id, color);
+ immVertex2f(pos_id, x, y);
}
static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip, unsigned int pos_id)
{
- View2D *v2d = &ar->v2d;
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
- MovieTrackingDopesheetCoverageSegment *coverage_segment;
-
- for (coverage_segment = dopesheet->coverage_segments.first;
- coverage_segment;
- coverage_segment = coverage_segment->next)
- {
- if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
- int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->start_frame);
- int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
-
- if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
- immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
- }
- else {
- immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
- }
-
- immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
- }
- }
+ View2D *v2d = &ar->v2d;
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ MovieTrackingDopesheetCoverageSegment *coverage_segment;
+
+ for (coverage_segment = dopesheet->coverage_segments.first; coverage_segment;
+ coverage_segment = coverage_segment->next) {
+ if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
+ int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
+ coverage_segment->start_frame);
+ int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
+
+ if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
+ immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
+ }
+ else {
+ immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
+ }
+
+ immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
+ }
+ }
}
void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- View2D *v2d = &ar->v2d;
-
- /* frame range */
- clip_draw_sfra_efra(v2d, scene);
-
- if (clip) {
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
- MovieTrackingDopesheetChannel *channel;
- float strip[4], selected_strip[4];
- float height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
-
- uint keyframe_len = 0;
-
- GPUVertFormat *format = immVertexFormat();
- uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- /* don't use totrect set, as the width stays the same
- * (NOTE: this is ok here, the configuration is pretty straightforward)
- */
- v2d->tot.ymin = (float)(-height);
-
- float y = (float) CHANNEL_FIRST;
-
- /* setup colors for regular and selected strips */
- UI_GetThemeColor3fv(TH_STRIP, strip);
- UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
-
- strip[3] = 0.5f;
- selected_strip[3] = 1.0f;
-
- GPU_blend(true);
-
- clip_draw_dopesheet_background(ar, clip, pos_id);
-
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
- float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
-
- /* check if visible */
- if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
- IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
- {
- MovieTrackingTrack *track = channel->track;
- int i;
- bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
-
- /* selection background */
- if (sel) {
- float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
- float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
-
- track_channel_color(track, default_color, color);
- immUniformColor4fv(color);
-
- immRectf(pos_id, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
- v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
- }
-
- /* tracked segments */
- for (i = 0; i < channel->tot_segment; i++) {
- int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]);
- int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]);
-
- immUniformColor4fv(sel ? selected_strip : strip);
-
- if (start_frame != end_frame) {
- immRectf(pos_id, start_frame, (float) y - STRIP_HEIGHT_HALF,
- end_frame, (float) y + STRIP_HEIGHT_HALF);
- keyframe_len += 2;
- }
- else {
- keyframe_len++;
- }
- }
-
- /* keyframes */
- i = 0;
- while (i < track->markersnr) {
- MovieTrackingMarker *marker = &track->markers[i];
-
- if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
- keyframe_len++;
- }
-
- i++;
- }
- }
-
- /* adjust y-position for next one */
- y -= CHANNEL_STEP;
- }
-
- immUnbindProgram();
-
- if (keyframe_len > 0) {
- /* draw keyframe markers */
- format = immVertexFormat();
- pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
- uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
- uint outline_color_id = GPU_vertformat_attr_add(format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
-
- immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
- GPU_enable_program_point_size();
- immUniform2f("ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
- immBegin(GPU_PRIM_POINTS, keyframe_len);
-
- /* all same size with black outline */
- immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
- immAttr4ub(outline_color_id, 0, 0, 0, 255);
- immAttr1u(flags_id, 0);
-
- y = (float) CHANNEL_FIRST; /* start again at the top */
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
- float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
-
- /* check if visible */
- if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
- IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
- {
- MovieTrackingTrack *track = channel->track;
- int i;
- bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
- float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
-
- /* tracked segments */
- for (i = 0; i < channel->tot_segment; i++) {
- int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]);
- int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]);
-
- if (start_frame != end_frame) {
- draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
- draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
- }
- else {
- draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
- }
- }
-
- /* keyframes */
- i = 0;
- while (i < track->markersnr) {
- MovieTrackingMarker *marker = &track->markers[i];
-
- if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
- int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
-
- draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
- }
-
- i++;
- }
- }
-
- /* adjust y-position for next one */
- y -= CHANNEL_STEP;
- }
-
- immEnd();
- GPU_disable_program_point_size();
- immUnbindProgram();
- }
-
- GPU_blend(false);
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ View2D *v2d = &ar->v2d;
+
+ /* frame range */
+ clip_draw_sfra_efra(v2d, scene);
+
+ if (clip) {
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ MovieTrackingDopesheetChannel *channel;
+ float strip[4], selected_strip[4];
+ float height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
+
+ uint keyframe_len = 0;
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* don't use totrect set, as the width stays the same
+ * (NOTE: this is ok here, the configuration is pretty straightforward)
+ */
+ v2d->tot.ymin = (float)(-height);
+
+ float y = (float)CHANNEL_FIRST;
+
+ /* setup colors for regular and selected strips */
+ UI_GetThemeColor3fv(TH_STRIP, strip);
+ UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
+
+ strip[3] = 0.5f;
+ selected_strip[3] = 1.0f;
+
+ GPU_blend(true);
+
+ clip_draw_dopesheet_background(ar, clip, pos_id);
+
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
+ MovieTrackingTrack *track = channel->track;
+ int i;
+ bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
+
+ /* selection background */
+ if (sel) {
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
+ float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
+
+ track_channel_color(track, default_color, color);
+ immUniformColor4fv(color);
+
+ immRectf(pos_id,
+ v2d->cur.xmin,
+ (float)y - CHANNEL_HEIGHT_HALF,
+ v2d->cur.xmax + EXTRA_SCROLL_PAD,
+ (float)y + CHANNEL_HEIGHT_HALF);
+ }
+
+ /* tracked segments */
+ for (i = 0; i < channel->tot_segment; i++) {
+ int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
+ channel->segments[2 * i]);
+ int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
+ channel->segments[2 * i + 1]);
+
+ immUniformColor4fv(sel ? selected_strip : strip);
+
+ if (start_frame != end_frame) {
+ immRectf(pos_id,
+ start_frame,
+ (float)y - STRIP_HEIGHT_HALF,
+ end_frame,
+ (float)y + STRIP_HEIGHT_HALF);
+ keyframe_len += 2;
+ }
+ else {
+ keyframe_len++;
+ }
+ }
+
+ /* keyframes */
+ i = 0;
+ while (i < track->markersnr) {
+ MovieTrackingMarker *marker = &track->markers[i];
+
+ if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
+ keyframe_len++;
+ }
+
+ i++;
+ }
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+
+ immUnbindProgram();
+
+ if (keyframe_len > 0) {
+ /* draw keyframe markers */
+ format = immVertexFormat();
+ pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+ uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+ uint outline_color_id = GPU_vertformat_attr_add(
+ format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
+
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ GPU_enable_program_point_size();
+ immUniform2f(
+ "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
+ immBegin(GPU_PRIM_POINTS, keyframe_len);
+
+ /* all same size with black outline */
+ immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
+ immAttr4ub(outline_color_id, 0, 0, 0, 255);
+ immAttr1u(flags_id, 0);
+
+ y = (float)CHANNEL_FIRST; /* start again at the top */
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
+ MovieTrackingTrack *track = channel->track;
+ int i;
+ bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
+ float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
+
+ /* tracked segments */
+ for (i = 0; i < channel->tot_segment; i++) {
+ int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
+ channel->segments[2 * i]);
+ int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
+ channel->segments[2 * i + 1]);
+
+ if (start_frame != end_frame) {
+ draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
+ draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
+ }
+ else {
+ draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
+ }
+ }
+
+ /* keyframes */
+ i = 0;
+ while (i < track->markersnr) {
+ MovieTrackingMarker *marker = &track->markers[i];
+
+ if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
+ int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
+
+ draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
+ }
+
+ i++;
+ }
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+
+ immEnd();
+ GPU_disable_program_point_size();
+ immUnbindProgram();
+ }
+
+ GPU_blend(false);
+ }
}
void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
{
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- View2D *v2d = &ar->v2d;
- MovieClip *clip = ED_space_clip_get_clip(sc);
- uiStyle *style = UI_style_get();
- int fontid = style->widget.uifont_id;
-
- if (!clip)
- return;
-
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
- int height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
-
- if (height > BLI_rcti_size_y(&v2d->mask)) {
- /* don't use totrect set, as the width stays the same
- * (NOTE: this is ok here, the configuration is pretty straightforward)
- */
- v2d->tot.ymin = (float)(-height);
- }
-
- /* need to do a view-sync here, so that the keys area doesn't jump around
- * (it must copy this) */
- UI_view2d_sync(NULL, sa, v2d, V2D_LOCK_COPY);
-
- /* loop through channels, and set up drawing depending on their type
- * first pass: just the standard GL-drawing for backdrop + text
- */
- float y = (float) CHANNEL_FIRST;
-
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- MovieTrackingDopesheetChannel *channel;
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
- float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
-
- /* check if visible */
- if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
- IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
- {
- MovieTrackingTrack *track = channel->track;
- float color[3];
- track_channel_color(track, NULL, color);
- immUniformColor3fv(color);
-
- immRectf(pos, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
- v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
- }
-
- /* adjust y-position for next one */
- y -= CHANNEL_STEP;
- }
- immUnbindProgram();
-
- /* second pass: text */
- y = (float) CHANNEL_FIRST;
-
- BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
-
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
- float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
-
- /* check if visible */
- if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
- IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
- {
- MovieTrackingTrack *track = channel->track;
- bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
-
- UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
-
- float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
- BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD,
- y - font_height / 2.0f, 0.0f);
- BLF_draw(fontid, channel->name, strlen(channel->name));
- }
-
- /* adjust y-position for next one */
- y -= CHANNEL_STEP;
- }
-
- /* third pass: widgets */
- uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
- y = (float) CHANNEL_FIRST;
-
- /* get RNA properties (once) */
- PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
- BLI_assert(chan_prop_lock);
-
- GPU_blend(true);
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
- float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
-
- /* check if visible */
- if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
- IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
- {
- MovieTrackingTrack *track = channel->track;
- const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
- PointerRNA ptr;
-
- RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr);
-
- UI_block_emboss_set(block, UI_EMBOSS_NONE);
- uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 1, icon,
- v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD, y - UI_UNIT_Y / 2.0f,
- UI_UNIT_X, UI_UNIT_Y, &ptr, chan_prop_lock, 0, 0, 0, 0, 0, NULL);
- UI_block_emboss_set(block, UI_EMBOSS);
- }
-
- /* adjust y-position for next one */
- y -= CHANNEL_STEP;
- }
- GPU_blend(false);
-
- UI_block_end(C, block);
- UI_block_draw(C, block);
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ View2D *v2d = &ar->v2d;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ uiStyle *style = UI_style_get();
+ int fontid = style->widget.uifont_id;
+
+ if (!clip)
+ return;
+
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ int height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
+
+ if (height > BLI_rcti_size_y(&v2d->mask)) {
+ /* don't use totrect set, as the width stays the same
+ * (NOTE: this is ok here, the configuration is pretty straightforward)
+ */
+ v2d->tot.ymin = (float)(-height);
+ }
+
+ /* need to do a view-sync here, so that the keys area doesn't jump around
+ * (it must copy this) */
+ UI_view2d_sync(NULL, sa, v2d, V2D_LOCK_COPY);
+
+ /* loop through channels, and set up drawing depending on their type
+ * first pass: just the standard GL-drawing for backdrop + text
+ */
+ float y = (float)CHANNEL_FIRST;
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ MovieTrackingDopesheetChannel *channel;
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
+ MovieTrackingTrack *track = channel->track;
+ float color[3];
+ track_channel_color(track, NULL, color);
+ immUniformColor3fv(color);
+
+ immRectf(pos,
+ v2d->cur.xmin,
+ (float)y - CHANNEL_HEIGHT_HALF,
+ v2d->cur.xmax + EXTRA_SCROLL_PAD,
+ (float)y + CHANNEL_HEIGHT_HALF);
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+ immUnbindProgram();
+
+ /* second pass: text */
+ y = (float)CHANNEL_FIRST;
+
+ BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
+ MovieTrackingTrack *track = channel->track;
+ bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
+
+ UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
+
+ float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
+ BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
+ BLF_draw(fontid, channel->name, strlen(channel->name));
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+
+ /* third pass: widgets */
+ uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
+ y = (float)CHANNEL_FIRST;
+
+ /* get RNA properties (once) */
+ PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
+ BLI_assert(chan_prop_lock);
+
+ GPU_blend(true);
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
+ MovieTrackingTrack *track = channel->track;
+ const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
+ PointerRNA ptr;
+
+ RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr);
+
+ UI_block_emboss_set(block, UI_EMBOSS_NONE);
+ uiDefIconButR_prop(block,
+ UI_BTYPE_ICON_TOGGLE,
+ 1,
+ icon,
+ v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
+ y - UI_UNIT_Y / 2.0f,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ &ptr,
+ chan_prop_lock,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ NULL);
+ UI_block_emboss_set(block, UI_EMBOSS);
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+ GPU_blend(false);
+
+ UI_block_end(C, block);
+ UI_block_draw(C, block);
}
diff --git a/source/blender/editors/space_clip/clip_dopesheet_ops.c b/source/blender/editors/space_clip/clip_dopesheet_ops.c
index e2689706452..e7f0f8c3fcc 100644
--- a/source/blender/editors/space_clip/clip_dopesheet_ops.c
+++ b/source/blender/editors/space_clip/clip_dopesheet_ops.c
@@ -43,160 +43,170 @@
#include "UI_view2d.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
static bool space_clip_dopesheet_poll(bContext *C)
{
- if (ED_space_clip_tracking_poll(C)) {
- SpaceClip *sc = CTX_wm_space_clip(C);
+ if (ED_space_clip_tracking_poll(C)) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc->view == SC_VIEW_DOPESHEET) {
- ARegion *ar = CTX_wm_region(C);
+ if (sc->view == SC_VIEW_DOPESHEET) {
+ ARegion *ar = CTX_wm_region(C);
- return ar->regiontype == RGN_TYPE_PREVIEW;
- }
- }
+ return ar->regiontype == RGN_TYPE_PREVIEW;
+ }
+ }
- return false;
+ return false;
}
/********************** select channel operator *********************/
static bool dopesheet_select_channel_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc && sc->clip)
- return sc->view == SC_VIEW_DOPESHEET;
+ if (sc && sc->clip)
+ return sc->view == SC_VIEW_DOPESHEET;
- return false;
+ return false;
}
static int dopesheet_select_channel_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
- MovieTrackingDopesheetChannel *channel;
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
- float location[2];
- const bool extend = RNA_boolean_get(op->ptr, "extend");
- int current_channel_index = 0, channel_index;
- const bool show_selected_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0;
-
- RNA_float_get_array(op->ptr, "location", location);
- channel_index = -(location[1] - (CHANNEL_FIRST + CHANNEL_HEIGHT_HALF)) / CHANNEL_STEP;
-
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- MovieTrackingTrack *track = channel->track;
-
- if (current_channel_index == channel_index) {
- if (extend)
- track->flag ^= TRACK_DOPE_SEL;
- else
- track->flag |= TRACK_DOPE_SEL;
-
- if (track->flag & TRACK_DOPE_SEL) {
- tracking->act_track = track;
- BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, true);
- }
- else if (show_selected_only == false) {
- BKE_tracking_track_deselect(track, TRACK_AREA_ALL);
- }
- }
- else if (!extend)
- track->flag &= ~TRACK_DOPE_SEL;
-
- current_channel_index++;
- }
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ MovieTrackingDopesheetChannel *channel;
+ ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
+ float location[2];
+ const bool extend = RNA_boolean_get(op->ptr, "extend");
+ int current_channel_index = 0, channel_index;
+ const bool show_selected_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0;
+
+ RNA_float_get_array(op->ptr, "location", location);
+ channel_index = -(location[1] - (CHANNEL_FIRST + CHANNEL_HEIGHT_HALF)) / CHANNEL_STEP;
+
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ MovieTrackingTrack *track = channel->track;
+
+ if (current_channel_index == channel_index) {
+ if (extend)
+ track->flag ^= TRACK_DOPE_SEL;
+ else
+ track->flag |= TRACK_DOPE_SEL;
+
+ if (track->flag & TRACK_DOPE_SEL) {
+ tracking->act_track = track;
+ BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, true);
+ }
+ else if (show_selected_only == false) {
+ BKE_tracking_track_deselect(track, TRACK_AREA_ALL);
+ }
+ }
+ else if (!extend)
+ track->flag &= ~TRACK_DOPE_SEL;
+
+ current_channel_index++;
+ }
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+
+ return OPERATOR_FINISHED;
}
static int dopesheet_select_channel_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- float location[2];
+ ARegion *ar = CTX_wm_region(C);
+ float location[2];
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
- RNA_float_set_array(op->ptr, "location", location);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
+ RNA_float_set_array(op->ptr, "location", location);
- return dopesheet_select_channel_exec(C, op);
+ return dopesheet_select_channel_exec(C, op);
}
void CLIP_OT_dopesheet_select_channel(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select Channel";
- ot->description = "Select movie tracking channel";
- ot->idname = "CLIP_OT_dopesheet_select_channel";
-
- /* api callbacks */
- ot->invoke = dopesheet_select_channel_invoke;
- ot->exec = dopesheet_select_channel_exec;
- ot->poll = dopesheet_select_channel_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Mouse location to select channel", -100.0f, 100.0f);
- RNA_def_boolean(ot->srna, "extend", 0,
- "Extend", "Extend selection rather than clearing the existing selection");
+ /* identifiers */
+ ot->name = "Select Channel";
+ ot->description = "Select movie tracking channel";
+ ot->idname = "CLIP_OT_dopesheet_select_channel";
+
+ /* api callbacks */
+ ot->invoke = dopesheet_select_channel_invoke;
+ ot->exec = dopesheet_select_channel_exec;
+ ot->poll = dopesheet_select_channel_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Mouse location to select channel",
+ -100.0f,
+ 100.0f);
+ RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
}
/********************** View All operator *********************/
static int dopesheet_view_all_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
- View2D *v2d = &ar->v2d;
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
- MovieTrackingDopesheetChannel *channel;
- int frame_min = INT_MAX, frame_max = INT_MIN;
-
- for (channel = dopesheet->channels.first; channel; channel = channel->next) {
- frame_min = min_ii(frame_min, channel->segments[0]);
- frame_max = max_ii(frame_max, channel->segments[channel->tot_segment]);
- }
-
- if (frame_min < frame_max) {
- float extra;
-
- v2d->cur.xmin = frame_min;
- v2d->cur.xmax = frame_max;
-
- /* we need an extra "buffer" factor on either side so that the endpoints are visible */
- extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
- v2d->cur.xmin -= extra;
- v2d->cur.xmax += extra;
-
- ED_region_tag_redraw(ar);
- }
-
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+ View2D *v2d = &ar->v2d;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ MovieTrackingDopesheetChannel *channel;
+ int frame_min = INT_MAX, frame_max = INT_MIN;
+
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ frame_min = min_ii(frame_min, channel->segments[0]);
+ frame_max = max_ii(frame_max, channel->segments[channel->tot_segment]);
+ }
+
+ if (frame_min < frame_max) {
+ float extra;
+
+ v2d->cur.xmin = frame_min;
+ v2d->cur.xmax = frame_max;
+
+ /* we need an extra "buffer" factor on either side so that the endpoints are visible */
+ extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
+ v2d->cur.xmin -= extra;
+ v2d->cur.xmax += extra;
+
+ ED_region_tag_redraw(ar);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_dopesheet_view_all(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View All";
- ot->description = "Reset viewable area to show full keyframe range";
- ot->idname = "CLIP_OT_dopesheet_view_all";
+ /* identifiers */
+ ot->name = "View All";
+ ot->description = "Reset viewable area to show full keyframe range";
+ ot->idname = "CLIP_OT_dopesheet_view_all";
- /* api callbacks */
- ot->exec = dopesheet_view_all_exec;
- ot->poll = space_clip_dopesheet_poll;
+ /* api callbacks */
+ ot->exec = dopesheet_view_all_exec;
+ ot->poll = space_clip_dopesheet_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index 7c400f8a417..a3aa4f4bed5 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -62,1829 +62,1943 @@
#include "BLF_api.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
/*********************** main area drawing *************************/
-static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width, unsigned int pos)
+static void draw_keyframe(
+ int frame, int cfra, int sfra, float framelen, int width, unsigned int pos)
{
- int height = (frame == cfra) ? 22 : 10;
- int x = (frame - sfra) * framelen;
-
- if (width == 1) {
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2i(pos, x, 0);
- immVertex2i(pos, x, height * UI_DPI_FAC);
- immEnd();
- }
- else {
- immRecti(pos, x, 0, x + width, height * UI_DPI_FAC);
- }
+ int height = (frame == cfra) ? 22 : 10;
+ int x = (frame - sfra) * framelen;
+
+ if (width == 1) {
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex2i(pos, x, 0);
+ immVertex2i(pos, x, height * UI_DPI_FAC);
+ immEnd();
+ }
+ else {
+ immRecti(pos, x, 0, x + width, height * UI_DPI_FAC);
+ }
}
-static int generic_track_get_markersnr(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track)
+static int generic_track_get_markersnr(MovieTrackingTrack *track,
+ MovieTrackingPlaneTrack *plane_track)
{
- if (track) {
- return track->markersnr;
- }
- else if (plane_track) {
- return plane_track->markersnr;
- }
-
- return 0;
+ if (track) {
+ return track->markersnr;
+ }
+ else if (plane_track) {
+ return plane_track->markersnr;
+ }
+
+ return 0;
}
-static int generic_track_get_marker_framenr(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track,
+static int generic_track_get_marker_framenr(MovieTrackingTrack *track,
+ MovieTrackingPlaneTrack *plane_track,
int marker_index)
{
- if (track) {
- BLI_assert(marker_index < track->markersnr);
- return track->markers[marker_index].framenr;
- }
- else if (plane_track) {
- BLI_assert(marker_index < plane_track->markersnr);
- return plane_track->markers[marker_index].framenr;
- }
-
- return 0;
+ if (track) {
+ BLI_assert(marker_index < track->markersnr);
+ return track->markers[marker_index].framenr;
+ }
+ else if (plane_track) {
+ BLI_assert(marker_index < plane_track->markersnr);
+ return plane_track->markers[marker_index].framenr;
+ }
+
+ return 0;
}
-static bool generic_track_is_marker_enabled(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track,
+static bool generic_track_is_marker_enabled(MovieTrackingTrack *track,
+ MovieTrackingPlaneTrack *plane_track,
int marker_index)
{
- if (track) {
- BLI_assert(marker_index < track->markersnr);
- return (track->markers[marker_index].flag & MARKER_DISABLED) == 0;
- }
- else if (plane_track) {
- return true;
- }
-
- return false;
+ if (track) {
+ BLI_assert(marker_index < track->markersnr);
+ return (track->markers[marker_index].flag & MARKER_DISABLED) == 0;
+ }
+ else if (plane_track) {
+ return true;
+ }
+
+ return false;
}
-static bool generic_track_is_marker_keyframed(MovieTrackingTrack *track, MovieTrackingPlaneTrack *plane_track,
+static bool generic_track_is_marker_keyframed(MovieTrackingTrack *track,
+ MovieTrackingPlaneTrack *plane_track,
int marker_index)
{
- if (track) {
- BLI_assert(marker_index < track->markersnr);
- return (track->markers[marker_index].flag & MARKER_TRACKED) == 0;
- }
- else if (plane_track) {
- BLI_assert(marker_index < plane_track->markersnr);
- return (plane_track->markers[marker_index].flag & PLANE_MARKER_TRACKED) == 0;
- }
-
- return false;
+ if (track) {
+ BLI_assert(marker_index < track->markersnr);
+ return (track->markers[marker_index].flag & MARKER_TRACKED) == 0;
+ }
+ else if (plane_track) {
+ BLI_assert(marker_index < plane_track->markersnr);
+ return (plane_track->markers[marker_index].flag & PLANE_MARKER_TRACKED) == 0;
+ }
+
+ return false;
}
static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene)
{
- float x;
- int *points, totseg, i, a;
- float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *act_object = BKE_tracking_object_get_active(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking);
- MovieTrackingPlaneTrack *act_plane_track = BKE_tracking_plane_track_get_active(&clip->tracking);
- MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
-
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
-
- /* cache background */
- ED_region_cache_draw_background(ar);
-
- /* cached segments -- could be usefu lto debug caching strategies */
- BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
- ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra);
-
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- /* track */
- if (act_track || act_plane_track) {
- for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) {
- int framenr;
- int markersnr = generic_track_get_markersnr(act_track, act_plane_track);
-
- while (a < markersnr) {
- int marker_framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
-
- if (marker_framenr >= i)
- break;
-
- if (a < markersnr - 1 && generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i)
- break;
-
- a++;
- }
-
- a = min_ii(a, markersnr - 1);
-
- if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) {
- framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
-
- if (framenr != i) {
- immUniformColor4ub(128, 128, 0, 96);
- }
- else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) {
- immUniformColor4ub(255, 255, 0, 196);
- }
- else {
- immUniformColor4ub(255, 255, 0, 96);
- }
-
- immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC);
- }
- }
- }
-
- /* failed frames */
- if (reconstruction->flag & TRACKING_RECONSTRUCTED) {
- int n = reconstruction->camnr;
- MovieReconstructedCamera *cameras = reconstruction->cameras;
-
- immUniformColor4ub(255, 0, 0, 96);
-
- for (i = sfra, a = 0; i <= efra; i++) {
- bool ok = false;
-
- while (a < n) {
- if (cameras[a].framenr == i) {
- ok = true;
- break;
- }
- else if (cameras[a].framenr > i) {
- break;
- }
-
- a++;
- }
-
- if (!ok) {
- immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC);
- }
- }
- }
-
- GPU_blend(false);
-
- /* current frame */
- x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx;
-
- immUniformThemeColor(TH_CFRAME);
- immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
-
- immUnbindProgram();
-
- ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
-
- pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- /* solver keyframes */
- immUniformColor4ub(175, 255, 0, 255);
- draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
- draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
-
- immUnbindProgram();
-
- /* movie clip animation */
- if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) {
- ED_mask_draw_frames(sc->mask_info.mask, ar, CFRA, sfra, efra);
- }
+ float x;
+ int *points, totseg, i, a;
+ float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *act_object = BKE_tracking_object_get_active(tracking);
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking);
+ MovieTrackingPlaneTrack *act_plane_track = BKE_tracking_plane_track_get_active(&clip->tracking);
+ MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
+
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+
+ /* cache background */
+ ED_region_cache_draw_background(ar);
+
+ /* cached segments -- could be usefu lto debug caching strategies */
+ BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
+ ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra);
+
+ uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* track */
+ if (act_track || act_plane_track) {
+ for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) {
+ int framenr;
+ int markersnr = generic_track_get_markersnr(act_track, act_plane_track);
+
+ while (a < markersnr) {
+ int marker_framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
+
+ if (marker_framenr >= i)
+ break;
+
+ if (a < markersnr - 1 &&
+ generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i)
+ break;
+
+ a++;
+ }
+
+ a = min_ii(a, markersnr - 1);
+
+ if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) {
+ framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
+
+ if (framenr != i) {
+ immUniformColor4ub(128, 128, 0, 96);
+ }
+ else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) {
+ immUniformColor4ub(255, 255, 0, 196);
+ }
+ else {
+ immUniformColor4ub(255, 255, 0, 96);
+ }
+
+ immRecti(pos,
+ (i - sfra + clip->start_frame - 1) * framelen,
+ 0,
+ (i - sfra + clip->start_frame) * framelen,
+ 4 * UI_DPI_FAC);
+ }
+ }
+ }
+
+ /* failed frames */
+ if (reconstruction->flag & TRACKING_RECONSTRUCTED) {
+ int n = reconstruction->camnr;
+ MovieReconstructedCamera *cameras = reconstruction->cameras;
+
+ immUniformColor4ub(255, 0, 0, 96);
+
+ for (i = sfra, a = 0; i <= efra; i++) {
+ bool ok = false;
+
+ while (a < n) {
+ if (cameras[a].framenr == i) {
+ ok = true;
+ break;
+ }
+ else if (cameras[a].framenr > i) {
+ break;
+ }
+
+ a++;
+ }
+
+ if (!ok) {
+ immRecti(pos,
+ (i - sfra + clip->start_frame - 1) * framelen,
+ 0,
+ (i - sfra + clip->start_frame) * framelen,
+ 8 * UI_DPI_FAC);
+ }
+ }
+ }
+
+ GPU_blend(false);
+
+ /* current frame */
+ x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx;
+
+ immUniformThemeColor(TH_CFRAME);
+ immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+
+ immUnbindProgram();
+
+ ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
+
+ pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* solver keyframes */
+ immUniformColor4ub(175, 255, 0, 255);
+ draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
+ draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
+
+ immUnbindProgram();
+
+ /* movie clip animation */
+ if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) {
+ ED_mask_draw_frames(sc->mask_info.mask, ar, CFRA, sfra, efra);
+ }
}
static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- char str[256] = {0};
- bool full_redraw = false;
-
- if (tracking->stats) {
- BLI_strncpy(str, tracking->stats->message, sizeof(str));
- full_redraw = true;
- }
- else {
- if (sc->flag & SC_LOCK_SELECTION)
- strcpy(str, "Locked");
- }
-
- if (str[0]) {
- float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.6f};
- ED_region_info_draw(ar, str, fill_color, full_redraw);
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ char str[256] = {0};
+ bool full_redraw = false;
+
+ if (tracking->stats) {
+ BLI_strncpy(str, tracking->stats->message, sizeof(str));
+ full_redraw = true;
+ }
+ else {
+ if (sc->flag & SC_LOCK_SELECTION)
+ strcpy(str, "Locked");
+ }
+
+ if (str[0]) {
+ float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.6f};
+ ED_region_info_draw(ar, str, fill_color, full_redraw);
+ }
}
static void draw_movieclip_muted(ARegion *ar, int width, int height, float zoomx, float zoomy)
{
- int x, y;
+ int x, y;
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- /* find window pixel coordinates of origin */
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+ /* find window pixel coordinates of origin */
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
- immUniformColor3f(0.0f, 0.0f, 0.0f);
- immRectf(pos, x, y, x + zoomx * width, y + zoomy * height);
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+ immRectf(pos, x, y, x + zoomx * width, y + zoomy * height);
- immUnbindProgram();
+ immUnbindProgram();
}
-static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
- int width, int height, float zoomx, float zoomy)
+static void draw_movieclip_buffer(const bContext *C,
+ SpaceClip *sc,
+ ARegion *ar,
+ ImBuf *ibuf,
+ int width,
+ int height,
+ float zoomx,
+ float zoomy)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int filter = GL_LINEAR;
- int x, y;
-
- /* find window pixel coordinates of origin */
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
-
- /* checkerboard for case alpha */
- if (ibuf->planes == 32) {
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
-
- imm_draw_box_checker_2d(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
- }
-
- /* non-scaled proxy shouldn't use filtering */
- if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
- ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100))
- {
- filter = GL_NEAREST;
- }
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
-
- if (ibuf->planes == 32) {
- GPU_blend(false);
- }
-
- if (sc->flag & SC_SHOW_METADATA) {
- rctf frame;
- BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
- ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int filter = GL_LINEAR;
+ int x, y;
+
+ /* find window pixel coordinates of origin */
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+ /* checkerboard for case alpha */
+ if (ibuf->planes == 32) {
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+
+ imm_draw_box_checker_2d(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
+ }
+
+ /* non-scaled proxy shouldn't use filtering */
+ if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
+ ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100)) {
+ filter = GL_NEAREST;
+ }
+
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
+
+ if (ibuf->planes == 32) {
+ GPU_blend(false);
+ }
+
+ if (sc->flag & SC_SHOW_METADATA) {
+ rctf frame;
+ BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
+ ED_region_image_metadata_draw(
+ x, y, ibuf, &frame, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
+ }
}
-static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int height, float zoomx, float zoomy)
+static void draw_stabilization_border(
+ SpaceClip *sc, ARegion *ar, int width, int height, float zoomx, float zoomy)
{
- int x, y;
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ int x, y;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- /* find window pixel coordinates of origin */
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+ /* find window pixel coordinates of origin */
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
- /* draw boundary border for frame if stabilization is enabled */
- if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
- const uint shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ /* draw boundary border for frame if stabilization is enabled */
+ if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
+ const uint shdr_pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- /* Exclusive OR allows to get orig value when second operand is 0,
- * and negative of orig value when second operand is 1. */
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_XOR);
+ /* Exclusive OR allows to get orig value when second operand is 0,
+ * and negative of orig value when second operand is 1. */
+ glEnable(GL_COLOR_LOGIC_OP);
+ glLogicOp(GL_XOR);
- GPU_matrix_push();
- GPU_matrix_translate_2f(x, y);
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(x, y);
- GPU_matrix_scale_2f(zoomx, zoomy);
- GPU_matrix_mul(sc->stabmat);
+ GPU_matrix_scale_2f(zoomx, zoomy);
+ GPU_matrix_mul(sc->stabmat);
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- float viewport_size[4];
- GPU_viewport_size_get_f(viewport_size);
- immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- immUniform1i("colors_len", 0); /* "simple" mode */
- immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
- immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_factor", 0.5f);
+ immUniform1i("colors_len", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- imm_draw_box_wire_2d(shdr_pos, 0.0f, 0.0f, width, height);
+ imm_draw_box_wire_2d(shdr_pos, 0.0f, 0.0f, width, height);
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
- glDisable(GL_COLOR_LOGIC_OP);
- }
+ glDisable(GL_COLOR_LOGIC_OP);
+ }
}
static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackingTrack *track)
{
#define MAX_STATIC_PATH 64
- int count = sc->path_length;
- int i, a, b, curindex = -1;
- float path_static[(MAX_STATIC_PATH + 1) * 2][2];
- float (*path)[2];
- int tiny = sc->flag & SC_SHOW_TINY_MARKER, framenr, start_frame;
- MovieTrackingMarker *marker;
+ int count = sc->path_length;
+ int i, a, b, curindex = -1;
+ float path_static[(MAX_STATIC_PATH + 1) * 2][2];
+ float(*path)[2];
+ int tiny = sc->flag & SC_SHOW_TINY_MARKER, framenr, start_frame;
+ MovieTrackingMarker *marker;
- if (count == 0)
- return;
+ if (count == 0)
+ return;
- start_frame = framenr = ED_space_clip_get_clip_frame_number(sc);
+ start_frame = framenr = ED_space_clip_get_clip_frame_number(sc);
- marker = BKE_tracking_marker_get(track, framenr);
- if (marker->framenr != framenr || marker->flag & MARKER_DISABLED)
- return;
+ marker = BKE_tracking_marker_get(track, framenr);
+ if (marker->framenr != framenr || marker->flag & MARKER_DISABLED)
+ return;
- if (count < MAX_STATIC_PATH) {
- path = path_static;
- }
- else {
- path = MEM_mallocN(sizeof(*path) * (count + 1) * 2, "path");
- }
+ if (count < MAX_STATIC_PATH) {
+ path = path_static;
+ }
+ else {
+ path = MEM_mallocN(sizeof(*path) * (count + 1) * 2, "path");
+ }
- a = count;
- i = framenr - 1;
- while (i >= framenr - count) {
- marker = BKE_tracking_marker_get(track, i);
+ a = count;
+ i = framenr - 1;
+ while (i >= framenr - count) {
+ marker = BKE_tracking_marker_get(track, i);
- if (!marker || marker->flag & MARKER_DISABLED)
- break;
+ if (!marker || marker->flag & MARKER_DISABLED)
+ break;
- if (marker->framenr == i) {
- add_v2_v2v2(path[--a], marker->pos, track->offset);
- ED_clip_point_undistorted_pos(sc, path[a], path[a]);
+ if (marker->framenr == i) {
+ add_v2_v2v2(path[--a], marker->pos, track->offset);
+ ED_clip_point_undistorted_pos(sc, path[a], path[a]);
- if (marker->framenr == start_frame)
- curindex = a;
- }
- else {
- break;
- }
+ if (marker->framenr == start_frame)
+ curindex = a;
+ }
+ else {
+ break;
+ }
- i--;
- }
+ i--;
+ }
- b = count;
- i = framenr;
- while (i <= framenr + count) {
- marker = BKE_tracking_marker_get(track, i);
+ b = count;
+ i = framenr;
+ while (i <= framenr + count) {
+ marker = BKE_tracking_marker_get(track, i);
- if (!marker || marker->flag & MARKER_DISABLED)
- break;
+ if (!marker || marker->flag & MARKER_DISABLED)
+ break;
- if (marker->framenr == i) {
- if (marker->framenr == start_frame)
- curindex = b;
+ if (marker->framenr == i) {
+ if (marker->framenr == start_frame)
+ curindex = b;
- add_v2_v2v2(path[b++], marker->pos, track->offset);
- ED_clip_point_undistorted_pos(sc, path[b - 1], path[b - 1]);
- }
- else
- break;
+ add_v2_v2v2(path[b++], marker->pos, track->offset);
+ ED_clip_point_undistorted_pos(sc, path[b - 1], path[b - 1]);
+ }
+ else
+ break;
- i++;
- }
+ i++;
+ }
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- if (!tiny) {
- immUniformThemeColor(TH_MARKER_OUTLINE);
+ if (!tiny) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
- if (TRACK_VIEW_SELECTED(sc, track)) {
- if ((b - a - 1) >= 1) {
- GPU_point_size(5.0f);
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ if ((b - a - 1) >= 1) {
+ GPU_point_size(5.0f);
- immBegin(GPU_PRIM_POINTS, b - a - 1);
+ immBegin(GPU_PRIM_POINTS, b - a - 1);
- for (i = a; i < b; i++) {
- if (i != curindex) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
- }
+ for (i = a; i < b; i++) {
+ if (i != curindex) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
+ }
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
- if ((b - a) >= 2) {
- GPU_line_width(3.0f);
+ if ((b - a) >= 2) {
+ GPU_line_width(3.0f);
- immBegin(GPU_PRIM_LINE_STRIP, b - a);
+ immBegin(GPU_PRIM_LINE_STRIP, b - a);
- for (i = a; i < b; i++) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
+ for (i = a; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
- if (TRACK_VIEW_SELECTED(sc, track)) {
- GPU_point_size(3.0f);
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ GPU_point_size(3.0f);
- if ((curindex - a) >= 1) {
- immUniformThemeColor(TH_PATH_BEFORE);
+ if ((curindex - a) >= 1) {
+ immUniformThemeColor(TH_PATH_BEFORE);
- immBegin(GPU_PRIM_POINTS, curindex - a);
+ immBegin(GPU_PRIM_POINTS, curindex - a);
- for (i = a; i < curindex; i++) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
+ for (i = a; i < curindex; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- immEnd();
- }
+ immEnd();
+ }
- if ((b - curindex - 1) >= 1) {
- immUniformThemeColor(TH_PATH_AFTER);
+ if ((b - curindex - 1) >= 1) {
+ immUniformThemeColor(TH_PATH_AFTER);
- immBegin(GPU_PRIM_POINTS, b - curindex - 1);
+ immBegin(GPU_PRIM_POINTS, b - curindex - 1);
- for (i = curindex + 1; i < b; i++) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
+ for (i = curindex + 1; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
- GPU_line_width(1);
+ GPU_line_width(1);
- if ((curindex - a + 1) >= 2) {
- immUniformThemeColor(TH_PATH_BEFORE);
+ if ((curindex - a + 1) >= 2) {
+ immUniformThemeColor(TH_PATH_BEFORE);
- immBegin(GPU_PRIM_LINE_STRIP, curindex - a + 1);
+ immBegin(GPU_PRIM_LINE_STRIP, curindex - a + 1);
- for (i = a; i <= curindex; i++) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
+ for (i = a; i <= curindex; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- immEnd();
- }
+ immEnd();
+ }
- if ((b - curindex) >= 2) {
- immUniformThemeColor(TH_PATH_AFTER);
+ if ((b - curindex) >= 2) {
+ immUniformThemeColor(TH_PATH_AFTER);
- immBegin(GPU_PRIM_LINE_STRIP, b - curindex);
+ immBegin(GPU_PRIM_LINE_STRIP, b - curindex);
- for (i = curindex; i < b; i++) {
- immVertex2f(pos, path[i][0], path[i][1]);
- }
+ for (i = curindex; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- immEnd();
- }
+ immEnd();
+ }
- immUnbindProgram();
+ immUnbindProgram();
- if (path != path_static) {
- MEM_freeN(path);
- }
+ if (path != path_static) {
+ MEM_freeN(path);
+ }
#undef MAX_STATIC_PATH
}
-static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int width, int height, unsigned int position)
+static void draw_marker_outline(SpaceClip *sc,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ const float marker_pos[2],
+ int width,
+ int height,
+ unsigned int position)
{
- int tiny = sc->flag & SC_SHOW_TINY_MARKER;
- bool show_search = false;
- float px[2];
+ int tiny = sc->flag & SC_SHOW_TINY_MARKER;
+ bool show_search = false;
+ float px[2];
- px[0] = 1.0f / width / sc->zoom;
- px[1] = 1.0f / height / sc->zoom;
+ px[0] = 1.0f / width / sc->zoom;
+ px[1] = 1.0f / height / sc->zoom;
- GPU_line_width(tiny ? 1.0f : 3.0f);
+ GPU_line_width(tiny ? 1.0f : 3.0f);
- immUniformThemeColor(TH_MARKER_OUTLINE);
+ immUniformThemeColor(TH_MARKER_OUTLINE);
- if ((marker->flag & MARKER_DISABLED) == 0) {
- float pos[2];
- float p[2];
+ if ((marker->flag & MARKER_DISABLED) == 0) {
+ float pos[2];
+ float p[2];
- add_v2_v2v2(pos, marker->pos, track->offset);
+ add_v2_v2v2(pos, marker->pos, track->offset);
- ED_clip_point_undistorted_pos(sc, pos, pos);
+ ED_clip_point_undistorted_pos(sc, pos, pos);
- sub_v2_v2v2(p, pos, marker_pos);
+ sub_v2_v2v2(p, pos, marker_pos);
- if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
- marker->pattern_corners[2], marker->pattern_corners[3]))
- {
- GPU_point_size(tiny ? 3.0f : 4.0f);
+ if (isect_point_quad_v2(p,
+ marker->pattern_corners[0],
+ marker->pattern_corners[1],
+ marker->pattern_corners[2],
+ marker->pattern_corners[3])) {
+ GPU_point_size(tiny ? 3.0f : 4.0f);
- immBegin(GPU_PRIM_POINTS, 1);
- immVertex2f(position, pos[0], pos[1]);
- immEnd();
- }
- else {
- immBegin(GPU_PRIM_LINES, 8);
+ immBegin(GPU_PRIM_POINTS, 1);
+ immVertex2f(position, pos[0], pos[1]);
+ immEnd();
+ }
+ else {
+ immBegin(GPU_PRIM_LINES, 8);
- immVertex2f(position, pos[0] + px[0] * 2, pos[1]);
- immVertex2f(position, pos[0] + px[0] * 8, pos[1]);
+ immVertex2f(position, pos[0] + px[0] * 2, pos[1]);
+ immVertex2f(position, pos[0] + px[0] * 8, pos[1]);
- immVertex2f(position, pos[0] - px[0] * 2, pos[1]);
- immVertex2f(position, pos[0] - px[0] * 8, pos[1]);
+ immVertex2f(position, pos[0] - px[0] * 2, pos[1]);
+ immVertex2f(position, pos[0] - px[0] * 8, pos[1]);
- immVertex2f(position, pos[0], pos[1] - px[1] * 2);
- immVertex2f(position, pos[0], pos[1] - px[1] * 8);
+ immVertex2f(position, pos[0], pos[1] - px[1] * 2);
+ immVertex2f(position, pos[0], pos[1] - px[1] * 8);
- immVertex2f(position, pos[0], pos[1] + px[1] * 2);
- immVertex2f(position, pos[0], pos[1] + px[1] * 8);
+ immVertex2f(position, pos[0], pos[1] + px[1] * 2);
+ immVertex2f(position, pos[0], pos[1] + px[1] * 8);
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
- /* pattern and search outline */
- GPU_matrix_push();
- GPU_matrix_translate_2fv(marker_pos);
+ /* pattern and search outline */
+ GPU_matrix_push();
+ GPU_matrix_translate_2fv(marker_pos);
- if (sc->flag & SC_SHOW_MARKER_PATTERN) {
- immBegin(GPU_PRIM_LINE_LOOP, 4);
- immVertex2fv(position, marker->pattern_corners[0]);
- immVertex2fv(position, marker->pattern_corners[1]);
- immVertex2fv(position, marker->pattern_corners[2]);
- immVertex2fv(position, marker->pattern_corners[3]);
- immEnd();
- }
+ if (sc->flag & SC_SHOW_MARKER_PATTERN) {
+ immBegin(GPU_PRIM_LINE_LOOP, 4);
+ immVertex2fv(position, marker->pattern_corners[0]);
+ immVertex2fv(position, marker->pattern_corners[1]);
+ immVertex2fv(position, marker->pattern_corners[2]);
+ immVertex2fv(position, marker->pattern_corners[3]);
+ immEnd();
+ }
- show_search = (TRACK_VIEW_SELECTED(sc, track) &&
- ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0;
+ show_search = (TRACK_VIEW_SELECTED(sc, track) && ((marker->flag & MARKER_DISABLED) == 0 ||
+ (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) !=
+ 0;
- if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
- imm_draw_box_wire_2d(position, marker->search_min[0],
- marker->search_min[1],
- marker->search_max[0],
- marker->search_max[1]);
- }
+ if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
+ imm_draw_box_wire_2d(position,
+ marker->search_min[0],
+ marker->search_min[1],
+ marker->search_max[0],
+ marker->search_max[1]);
+ }
- GPU_matrix_pop();
+ GPU_matrix_pop();
}
static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
{
- if (track->flag & TRACK_CUSTOMCOLOR) {
- if (act)
- UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
- else
- copy_v3_v3(scol, track->color);
-
- mul_v3_v3fl(col, track->color, 0.5f);
- }
- else {
- UI_GetThemeColor3fv(TH_MARKER, col);
-
- if (act)
- UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
- else
- UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
- }
+ if (track->flag & TRACK_CUSTOMCOLOR) {
+ if (act)
+ UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+ else
+ copy_v3_v3(scol, track->color);
+
+ mul_v3_v3fl(col, track->color, 0.5f);
+ }
+ else {
+ UI_GetThemeColor3fv(TH_MARKER, col);
+
+ if (act)
+ UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+ else
+ UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
+ }
}
-static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int width, int height, int act, int sel, const uint shdr_pos)
+static void draw_marker_areas(SpaceClip *sc,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ const float marker_pos[2],
+ int width,
+ int height,
+ int act,
+ int sel,
+ const uint shdr_pos)
{
- int tiny = sc->flag & SC_SHOW_TINY_MARKER;
- bool show_search = false;
- float col[3], scol[3];
- float px[2];
+ int tiny = sc->flag & SC_SHOW_TINY_MARKER;
+ bool show_search = false;
+ float col[3], scol[3];
+ float px[2];
- track_colors(track, act, col, scol);
+ track_colors(track, act, col, scol);
- px[0] = 1.0f / width / sc->zoom;
- px[1] = 1.0f / height / sc->zoom;
-
- GPU_line_width(1.0f);
-
- /* Since we are switching solid and dashed lines in rather complex logic here,
- * just always go with dashed shader. */
- immUnbindProgram();
-
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
-
- float viewport_size[4];
- GPU_viewport_size_get_f(viewport_size);
- immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
-
- immUniform1i("colors_len", 0); /* "simple" mode */
-
- /* marker position and offset position */
- if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
- float pos[2], p[2];
-
- if (track->flag & TRACK_LOCKED) {
- if (act) {
- immUniformThemeColor(TH_ACT_MARKER);
- }
- else if (track->flag & SELECT) {
- immUniformThemeColorShade(TH_LOCK_MARKER, 64);
- }
- else {
- immUniformThemeColor(TH_LOCK_MARKER);
- }
- }
- else {
- immUniformColor3fv((track->flag & SELECT) ? scol : col);
- }
-
- add_v2_v2v2(pos, marker->pos, track->offset);
- ED_clip_point_undistorted_pos(sc, pos, pos);
-
- sub_v2_v2v2(p, pos, marker_pos);
-
- if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
- marker->pattern_corners[2], marker->pattern_corners[3]))
- {
- GPU_point_size(tiny ? 1.0f : 2.0f);
-
- immUniform1f("dash_factor", 2.0f); /* Solid "line" */
-
- immBegin(GPU_PRIM_POINTS, 1);
- immVertex2f(shdr_pos, pos[0], pos[1]);
- immEnd();
- }
- else {
- immUniform1f("dash_factor", 2.0f); /* Solid line */
-
- immBegin(GPU_PRIM_LINES, 8);
-
- immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]);
- immVertex2f(shdr_pos, pos[0] + px[0] * 7, pos[1]);
-
- immVertex2f(shdr_pos, pos[0] - px[0] * 3, pos[1]);
- immVertex2f(shdr_pos, pos[0] - px[0] * 7, pos[1]);
-
- immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 3);
- immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 7);
-
- immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 3);
- immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 7);
-
- immEnd();
-
- immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
- immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_factor", 0.5f);
-
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_XOR);
-
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2fv(shdr_pos, pos);
- immVertex2fv(shdr_pos, marker_pos);
- immEnd();
-
- glDisable(GL_COLOR_LOGIC_OP);
- }
- }
-
- /* pattern */
- GPU_matrix_push();
- GPU_matrix_translate_2fv(marker_pos);
-
- if (track->flag & TRACK_LOCKED) {
- if (act) {
- immUniformThemeColor(TH_ACT_MARKER);
- }
- else if (track->pat_flag & SELECT) {
- immUniformThemeColorShade(TH_LOCK_MARKER, 64);
- }
- else {
- immUniformThemeColor(TH_LOCK_MARKER);
- }
- }
- else if (marker->flag & MARKER_DISABLED) {
- if (act) {
- immUniformThemeColor(TH_ACT_MARKER);
- }
- else if (track->pat_flag & SELECT) {
- immUniformThemeColorShade(TH_DIS_MARKER, 128);
- }
- else {
- immUniformThemeColor(TH_DIS_MARKER);
- }
- }
- else {
- immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
- }
-
- if (tiny) {
- immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_factor", 0.5f);
- }
- else {
- immUniform1f("dash_factor", 2.0f); /* Solid line */
- }
-
- if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
- immBegin(GPU_PRIM_LINE_LOOP, 4);
- immVertex2fv(shdr_pos, marker->pattern_corners[0]);
- immVertex2fv(shdr_pos, marker->pattern_corners[1]);
- immVertex2fv(shdr_pos, marker->pattern_corners[2]);
- immVertex2fv(shdr_pos, marker->pattern_corners[3]);
- immEnd();
- }
-
- /* search */
- show_search = (TRACK_VIEW_SELECTED(sc, track) &&
- ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0;
-
- if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
- imm_draw_box_wire_2d(shdr_pos, marker->search_min[0], marker->search_min[1],
- marker->search_max[0], marker->search_max[1]);
- }
-
- GPU_matrix_pop();
-
- /* Restore default shader */
- immUnbindProgram();
-
- const uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- BLI_assert(pos == shdr_pos);
- UNUSED_VARS_NDEBUG(pos);
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ px[0] = 1.0f / width / sc->zoom;
+ px[1] = 1.0f / height / sc->zoom;
+
+ GPU_line_width(1.0f);
+
+ /* Since we are switching solid and dashed lines in rather complex logic here,
+ * just always go with dashed shader. */
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("colors_len", 0); /* "simple" mode */
+
+ /* marker position and offset position */
+ if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
+ float pos[2], p[2];
+
+ if (track->flag & TRACK_LOCKED) {
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
+ }
+ else if (track->flag & SELECT) {
+ immUniformThemeColorShade(TH_LOCK_MARKER, 64);
+ }
+ else {
+ immUniformThemeColor(TH_LOCK_MARKER);
+ }
+ }
+ else {
+ immUniformColor3fv((track->flag & SELECT) ? scol : col);
+ }
+
+ add_v2_v2v2(pos, marker->pos, track->offset);
+ ED_clip_point_undistorted_pos(sc, pos, pos);
+
+ sub_v2_v2v2(p, pos, marker_pos);
+
+ if (isect_point_quad_v2(p,
+ marker->pattern_corners[0],
+ marker->pattern_corners[1],
+ marker->pattern_corners[2],
+ marker->pattern_corners[3])) {
+ GPU_point_size(tiny ? 1.0f : 2.0f);
+
+ immUniform1f("dash_factor", 2.0f); /* Solid "line" */
+
+ immBegin(GPU_PRIM_POINTS, 1);
+ immVertex2f(shdr_pos, pos[0], pos[1]);
+ immEnd();
+ }
+ else {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+
+ immBegin(GPU_PRIM_LINES, 8);
+
+ immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]);
+ immVertex2f(shdr_pos, pos[0] + px[0] * 7, pos[1]);
+
+ immVertex2f(shdr_pos, pos[0] - px[0] * 3, pos[1]);
+ immVertex2f(shdr_pos, pos[0] - px[0] * 7, pos[1]);
+
+ immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 3);
+ immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 7);
+
+ immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 3);
+ immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 7);
+
+ immEnd();
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ glEnable(GL_COLOR_LOGIC_OP);
+ glLogicOp(GL_XOR);
+
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex2fv(shdr_pos, pos);
+ immVertex2fv(shdr_pos, marker_pos);
+ immEnd();
+
+ glDisable(GL_COLOR_LOGIC_OP);
+ }
+ }
+
+ /* pattern */
+ GPU_matrix_push();
+ GPU_matrix_translate_2fv(marker_pos);
+
+ if (track->flag & TRACK_LOCKED) {
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
+ }
+ else if (track->pat_flag & SELECT) {
+ immUniformThemeColorShade(TH_LOCK_MARKER, 64);
+ }
+ else {
+ immUniformThemeColor(TH_LOCK_MARKER);
+ }
+ }
+ else if (marker->flag & MARKER_DISABLED) {
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
+ }
+ else if (track->pat_flag & SELECT) {
+ immUniformThemeColorShade(TH_DIS_MARKER, 128);
+ }
+ else {
+ immUniformThemeColor(TH_DIS_MARKER);
+ }
+ }
+ else {
+ immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
+ }
+
+ if (tiny) {
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+ }
+ else {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+ }
+
+ if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
+ immBegin(GPU_PRIM_LINE_LOOP, 4);
+ immVertex2fv(shdr_pos, marker->pattern_corners[0]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[1]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[2]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[3]);
+ immEnd();
+ }
+
+ /* search */
+ show_search = (TRACK_VIEW_SELECTED(sc, track) && ((marker->flag & MARKER_DISABLED) == 0 ||
+ (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) !=
+ 0;
+
+ if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
+ imm_draw_box_wire_2d(shdr_pos,
+ marker->search_min[0],
+ marker->search_min[1],
+ marker->search_max[0],
+ marker->search_max[1]);
+ }
+
+ GPU_matrix_pop();
+
+ /* Restore default shader */
+ immUnbindProgram();
+
+ const uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ BLI_assert(pos == shdr_pos);
+ UNUSED_VARS_NDEBUG(pos);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
}
static float get_shortest_pattern_side(MovieTrackingMarker *marker)
{
- int i, next;
- float len_sq = FLT_MAX;
+ int i, next;
+ float len_sq = FLT_MAX;
- for (i = 0; i < 4; i++) {
- float cur_len;
+ for (i = 0; i < 4; i++) {
+ float cur_len;
- next = (i + 1) % 4;
+ next = (i + 1) % 4;
- cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]);
+ cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]);
- len_sq = min_ff(cur_len, len_sq);
- }
+ len_sq = min_ff(cur_len, len_sq);
+ }
- return sqrtf(len_sq);
+ return sqrtf(len_sq);
}
-static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
+static void draw_marker_slide_square(
+ float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
{
- float tdx, tdy;
+ float tdx, tdy;
- tdx = dx;
- tdy = dy;
+ tdx = dx;
+ tdy = dy;
- if (outline) {
- tdx += px[0];
- tdy += px[1];
- }
+ if (outline) {
+ tdx += px[0];
+ tdy += px[1];
+ }
- immRectf(pos, x - tdx, y - tdy, x + tdx, y + tdy);
+ immRectf(pos, x - tdx, y - tdy, x + tdx, y + tdy);
}
-static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
+static void draw_marker_slide_triangle(
+ float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
{
- float tdx, tdy;
+ float tdx, tdy;
- tdx = dx * 2.0f;
- tdy = dy * 2.0f;
+ tdx = dx * 2.0f;
+ tdy = dy * 2.0f;
- if (outline) {
- tdx += px[0];
- tdy += px[1];
- }
+ if (outline) {
+ tdx += px[0];
+ tdy += px[1];
+ }
- immBegin(GPU_PRIM_TRIS, 3);
- immVertex2f(pos, x, y);
- immVertex2f(pos, x - tdx, y);
- immVertex2f(pos, x, y + tdy);
- immEnd();
+ immBegin(GPU_PRIM_TRIS, 3);
+ immVertex2f(pos, x, y);
+ immVertex2f(pos, x - tdx, y);
+ immVertex2f(pos, x, y + tdy);
+ immEnd();
}
-static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int outline, int sel, int act,
- int width, int height, unsigned int pos)
+static void draw_marker_slide_zones(SpaceClip *sc,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ const float marker_pos[2],
+ int outline,
+ int sel,
+ int act,
+ int width,
+ int height,
+ unsigned int pos)
{
- float dx, dy, patdx, patdy, searchdx, searchdy;
- int tiny = sc->flag & SC_SHOW_TINY_MARKER;
- float col[3], scol[3], px[2], side;
+ float dx, dy, patdx, patdy, searchdx, searchdy;
+ int tiny = sc->flag & SC_SHOW_TINY_MARKER;
+ float col[3], scol[3], px[2], side;
- if ((tiny && outline) || (marker->flag & MARKER_DISABLED))
- return;
+ if ((tiny && outline) || (marker->flag & MARKER_DISABLED))
+ return;
- if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED)
- return;
+ if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED)
+ return;
- track_colors(track, act, col, scol);
+ track_colors(track, act, col, scol);
- if (outline) {
- immUniformThemeColor(TH_MARKER_OUTLINE);
- }
+ if (outline) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+ }
- GPU_matrix_push();
- GPU_matrix_translate_2fv(marker_pos);
+ GPU_matrix_push();
+ GPU_matrix_translate_2fv(marker_pos);
- dx = 6.0f / width / sc->zoom;
- dy = 6.0f / height / sc->zoom;
+ dx = 6.0f / width / sc->zoom;
+ dy = 6.0f / height / sc->zoom;
- side = get_shortest_pattern_side(marker);
- patdx = min_ff(dx * 2.0f / 3.0f, side / 6.0f) * UI_DPI_FAC;
- patdy = min_ff(dy * 2.0f / 3.0f, side * width / height / 6.0f) * UI_DPI_FAC;
+ side = get_shortest_pattern_side(marker);
+ patdx = min_ff(dx * 2.0f / 3.0f, side / 6.0f) * UI_DPI_FAC;
+ patdy = min_ff(dy * 2.0f / 3.0f, side * width / height / 6.0f) * UI_DPI_FAC;
- searchdx = min_ff(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f) * UI_DPI_FAC;
- searchdy = min_ff(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f) * UI_DPI_FAC;
+ searchdx = min_ff(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f) * UI_DPI_FAC;
+ searchdy = min_ff(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f) * UI_DPI_FAC;
- px[0] = 1.0f / sc->zoom / width / sc->scale;
- px[1] = 1.0f / sc->zoom / height / sc->scale;
+ px[0] = 1.0f / sc->zoom / width / sc->scale;
+ px[1] = 1.0f / sc->zoom / height / sc->scale;
- if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
- if (!outline) {
- immUniformColor3fv((track->search_flag & SELECT) ? scol : col);
- }
+ if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
+ if (!outline) {
+ immUniformColor3fv((track->search_flag & SELECT) ? scol : col);
+ }
- /* search offset square */
- draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px, pos);
+ /* search offset square */
+ draw_marker_slide_square(
+ marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px, pos);
- /* search re-sizing triangle */
- draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px, pos);
- }
+ /* search re-sizing triangle */
+ draw_marker_slide_triangle(
+ marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px, pos);
+ }
- if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) {
- int i;
- float pat_min[2], pat_max[2];
-/* float dx = 12.0f / width, dy = 12.0f / height;*/ /* XXX UNUSED */
- float tilt_ctrl[2];
+ if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) {
+ int i;
+ float pat_min[2], pat_max[2];
+ /* float dx = 12.0f / width, dy = 12.0f / height;*/ /* XXX UNUSED */
+ float tilt_ctrl[2];
- if (!outline) {
- immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
- }
+ if (!outline) {
+ immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
+ }
- /* pattern's corners sliding squares */
- for (i = 0; i < 4; i++) {
- draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1],
- patdx / 1.5f, patdy / 1.5f, outline, px, pos);
- }
+ /* pattern's corners sliding squares */
+ for (i = 0; i < 4; i++) {
+ draw_marker_slide_square(marker->pattern_corners[i][0],
+ marker->pattern_corners[i][1],
+ patdx / 1.5f,
+ patdy / 1.5f,
+ outline,
+ px,
+ pos);
+ }
- /* ** sliders to control overall pattern ** */
- add_v2_v2v2(tilt_ctrl, marker->pattern_corners[1], marker->pattern_corners[2]);
+ /* ** sliders to control overall pattern ** */
+ add_v2_v2v2(tilt_ctrl, marker->pattern_corners[1], marker->pattern_corners[2]);
- BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+ BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
- GPU_line_width(outline ? 3.0f : 1.0f);
+ GPU_line_width(outline ? 3.0f : 1.0f);
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2f(pos, 0.0f, 0.0f);
- immVertex2fv(pos, tilt_ctrl);
- immEnd();
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex2f(pos, 0.0f, 0.0f);
+ immVertex2fv(pos, tilt_ctrl);
+ immEnd();
- /* slider to control pattern tilt */
- draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px, pos);
- }
+ /* slider to control pattern tilt */
+ draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px, pos);
+ }
- GPU_matrix_pop();
+ GPU_matrix_pop();
}
-static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int act, int width, int height, float zoomx, float zoomy)
+static void draw_marker_texts(SpaceClip *sc,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ const float marker_pos[2],
+ int act,
+ int width,
+ int height,
+ float zoomx,
+ float zoomy)
{
- char str[128] = {0}, state[64] = {0};
- float dx = 0.0f, dy = 0.0f, fontsize, pos[3];
- uiStyle *style = U.uistyles.first;
- int fontid = style->widget.uifont_id;
-
- if (!TRACK_VIEW_SELECTED(sc, track))
- return;
-
- BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
- fontsize = BLF_height_max(fontid);
-
- if (marker->flag & MARKER_DISABLED) {
- if (act) {
- UI_FontThemeColor(fontid, TH_ACT_MARKER);
- }
- else {
- unsigned char color[4];
- UI_GetThemeColorShade4ubv(TH_DIS_MARKER, 128, color);
- BLF_color4ubv(fontid, color);
- }
- }
- else {
- UI_FontThemeColor(fontid, act ? TH_ACT_MARKER : TH_SEL_MARKER);
- }
-
- if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
- ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0))
- {
- dx = marker->search_min[0];
- dy = marker->search_min[1];
- }
- else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
- float pat_min[2], pat_max[2];
-
- BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
- dx = pat_min[0];
- dy = pat_min[1];
- }
-
- pos[0] = (marker_pos[0] + dx) * width;
- pos[1] = (marker_pos[1] + dy) * height;
- pos[2] = 0.0f;
-
- mul_m4_v3(sc->stabmat, pos);
-
- pos[0] = pos[0] * zoomx;
- pos[1] = pos[1] * zoomy - fontsize;
-
- if (marker->flag & MARKER_DISABLED)
- strcpy(state, "disabled");
- else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc))
- strcpy(state, "estimated");
- else if (marker->flag & MARKER_TRACKED)
- strcpy(state, "tracked");
- else
- strcpy(state, "keyframed");
-
- if (state[0])
- BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
- else
- BLI_strncpy(str, track->name, sizeof(str));
-
- BLF_position(fontid, pos[0], pos[1], 0.0f);
- BLF_draw(fontid, str, sizeof(str));
- pos[1] -= fontsize;
-
- if (track->flag & TRACK_HAS_BUNDLE) {
- BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
- BLF_position(fontid, pos[0], pos[1], 0.0f);
- BLF_draw(fontid, str, sizeof(str));
- pos[1] -= fontsize;
- }
-
- if (track->flag & TRACK_LOCKED) {
- BLF_position(fontid, pos[0], pos[1], 0.0f);
- BLF_draw(fontid, "locked", 6);
- }
+ char str[128] = {0}, state[64] = {0};
+ float dx = 0.0f, dy = 0.0f, fontsize, pos[3];
+ uiStyle *style = U.uistyles.first;
+ int fontid = style->widget.uifont_id;
+
+ if (!TRACK_VIEW_SELECTED(sc, track))
+ return;
+
+ BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+ fontsize = BLF_height_max(fontid);
+
+ if (marker->flag & MARKER_DISABLED) {
+ if (act) {
+ UI_FontThemeColor(fontid, TH_ACT_MARKER);
+ }
+ else {
+ unsigned char color[4];
+ UI_GetThemeColorShade4ubv(TH_DIS_MARKER, 128, color);
+ BLF_color4ubv(fontid, color);
+ }
+ }
+ else {
+ UI_FontThemeColor(fontid, act ? TH_ACT_MARKER : TH_SEL_MARKER);
+ }
+
+ if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
+ ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) {
+ dx = marker->search_min[0];
+ dy = marker->search_min[1];
+ }
+ else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
+ float pat_min[2], pat_max[2];
+
+ BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+ dx = pat_min[0];
+ dy = pat_min[1];
+ }
+
+ pos[0] = (marker_pos[0] + dx) * width;
+ pos[1] = (marker_pos[1] + dy) * height;
+ pos[2] = 0.0f;
+
+ mul_m4_v3(sc->stabmat, pos);
+
+ pos[0] = pos[0] * zoomx;
+ pos[1] = pos[1] * zoomy - fontsize;
+
+ if (marker->flag & MARKER_DISABLED)
+ strcpy(state, "disabled");
+ else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc))
+ strcpy(state, "estimated");
+ else if (marker->flag & MARKER_TRACKED)
+ strcpy(state, "tracked");
+ else
+ strcpy(state, "keyframed");
+
+ if (state[0])
+ BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
+ else
+ BLI_strncpy(str, track->name, sizeof(str));
+
+ BLF_position(fontid, pos[0], pos[1], 0.0f);
+ BLF_draw(fontid, str, sizeof(str));
+ pos[1] -= fontsize;
+
+ if (track->flag & TRACK_HAS_BUNDLE) {
+ BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
+ BLF_position(fontid, pos[0], pos[1], 0.0f);
+ BLF_draw(fontid, str, sizeof(str));
+ pos[1] -= fontsize;
+ }
+
+ if (track->flag & TRACK_LOCKED) {
+ BLF_position(fontid, pos[0], pos[1], 0.0f);
+ BLF_draw(fontid, "locked", 6);
+ }
}
static void plane_track_colors(bool is_active, float color[3], float selected_color[3])
{
- UI_GetThemeColor3fv(TH_MARKER, color);
+ UI_GetThemeColor3fv(TH_MARKER, color);
- UI_GetThemeColor3fv(is_active ? TH_ACT_MARKER : TH_SEL_MARKER, selected_color);
+ UI_GetThemeColor3fv(is_active ? TH_ACT_MARKER : TH_SEL_MARKER, selected_color);
}
-static void getArrowEndPoint(const int width, const int height, const float zoom,
- const float start_corner[2], const float end_corner[2],
+static void getArrowEndPoint(const int width,
+ const int height,
+ const float zoom,
+ const float start_corner[2],
+ const float end_corner[2],
float end_point[2])
{
- float direction[2];
- float max_length;
+ float direction[2];
+ float max_length;
- sub_v2_v2v2(direction, end_corner, start_corner);
+ sub_v2_v2v2(direction, end_corner, start_corner);
- direction[0] *= width;
- direction[1] *= height;
- max_length = normalize_v2(direction);
- mul_v2_fl(direction, min_ff(32.0f / zoom, max_length));
- direction[0] /= width;
- direction[1] /= height;
+ direction[0] *= width;
+ direction[1] *= height;
+ max_length = normalize_v2(direction);
+ mul_v2_fl(direction, min_ff(32.0f / zoom, max_length));
+ direction[0] /= width;
+ direction[1] /= height;
- add_v2_v2v2(end_point, start_corner, direction);
+ add_v2_v2v2(end_point, start_corner, direction);
}
-static void homogeneous_2d_to_gl_matrix(/*const*/ float matrix[3][3],
- float gl_matrix[4][4])
+static void homogeneous_2d_to_gl_matrix(/*const*/ float matrix[3][3], float gl_matrix[4][4])
{
- gl_matrix[0][0] = matrix[0][0];
- gl_matrix[0][1] = matrix[0][1];
- gl_matrix[0][2] = 0.0f;
- gl_matrix[0][3] = matrix[0][2];
-
- gl_matrix[1][0] = matrix[1][0];
- gl_matrix[1][1] = matrix[1][1];
- gl_matrix[1][2] = 0.0f;
- gl_matrix[1][3] = matrix[1][2];
-
- gl_matrix[2][0] = 0.0f;
- gl_matrix[2][1] = 0.0f;
- gl_matrix[2][2] = 1.0f;
- gl_matrix[2][3] = 0.0f;
-
- gl_matrix[3][0] = matrix[2][0];
- gl_matrix[3][1] = matrix[2][1];
- gl_matrix[3][2] = 0.0f;
- gl_matrix[3][3] = matrix[2][2];
+ gl_matrix[0][0] = matrix[0][0];
+ gl_matrix[0][1] = matrix[0][1];
+ gl_matrix[0][2] = 0.0f;
+ gl_matrix[0][3] = matrix[0][2];
+
+ gl_matrix[1][0] = matrix[1][0];
+ gl_matrix[1][1] = matrix[1][1];
+ gl_matrix[1][2] = 0.0f;
+ gl_matrix[1][3] = matrix[1][2];
+
+ gl_matrix[2][0] = 0.0f;
+ gl_matrix[2][1] = 0.0f;
+ gl_matrix[2][2] = 1.0f;
+ gl_matrix[2][3] = 0.0f;
+
+ gl_matrix[3][0] = matrix[2][0];
+ gl_matrix[3][1] = matrix[2][1];
+ gl_matrix[3][2] = 0.0f;
+ gl_matrix[3][3] = matrix[2][2];
}
static void draw_plane_marker_image(Scene *scene,
MovieTrackingPlaneTrack *plane_track,
MovieTrackingPlaneMarker *plane_marker)
{
- Image *image = plane_track->image;
- ImBuf *ibuf;
- void *lock;
+ Image *image = plane_track->image;
+ ImBuf *ibuf;
+ void *lock;
- if (image == NULL) {
- return;
- }
+ if (image == NULL) {
+ return;
+ }
- ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
+ ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
- if (ibuf) {
- unsigned char *display_buffer;
- void *cache_handle;
+ if (ibuf) {
+ unsigned char *display_buffer;
+ void *cache_handle;
- if (image->flag & IMA_VIEW_AS_RENDER) {
- display_buffer = IMB_display_buffer_acquire(ibuf,
- &scene->view_settings,
- &scene->display_settings,
- &cache_handle);
- }
- else {
- display_buffer = IMB_display_buffer_acquire(ibuf, NULL,
- &scene->display_settings,
- &cache_handle);
- }
+ if (image->flag & IMA_VIEW_AS_RENDER) {
+ display_buffer = IMB_display_buffer_acquire(
+ ibuf, &scene->view_settings, &scene->display_settings, &cache_handle);
+ }
+ else {
+ display_buffer = IMB_display_buffer_acquire(
+ ibuf, NULL, &scene->display_settings, &cache_handle);
+ }
- if (display_buffer) {
- GLuint texid;
- float frame_corners[4][2] = {{0.0f, 0.0f},
- {1.0f, 0.0f},
- {1.0f, 1.0f},
- {0.0f, 1.0f}};
- float perspective_matrix[3][3];
- float gl_matrix[4][4];
- bool transparent = false;
- BKE_tracking_homography_between_two_quads(frame_corners,
- plane_marker->corners,
- perspective_matrix);
+ if (display_buffer) {
+ GLuint texid;
+ float frame_corners[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
+ float perspective_matrix[3][3];
+ float gl_matrix[4][4];
+ bool transparent = false;
+ BKE_tracking_homography_between_two_quads(
+ frame_corners, plane_marker->corners, perspective_matrix);
- homogeneous_2d_to_gl_matrix(perspective_matrix, gl_matrix);
+ homogeneous_2d_to_gl_matrix(perspective_matrix, gl_matrix);
- if (plane_track->image_opacity != 1.0f || ibuf->planes == 32) {
- transparent = true;
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
- }
+ if (plane_track->image_opacity != 1.0f || ibuf->planes == 32) {
+ transparent = true;
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+ }
- glGenTextures(1, (GLuint *)&texid);
+ glGenTextures(1, (GLuint *)&texid);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, texid);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texid);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, display_buffer);
+ glTexImage2D(GL_TEXTURE_2D,
+ 0,
+ GL_RGBA8,
+ ibuf->x,
+ ibuf->y,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ display_buffer);
- GPU_matrix_push();
- GPU_matrix_mul(gl_matrix);
+ GPU_matrix_push();
+ GPU_matrix_mul(gl_matrix);
- GPUVertFormat *imm_format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(imm_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint texCoord = GPU_vertformat_attr_add(imm_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ GPUVertFormat *imm_format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(imm_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint texCoord = GPU_vertformat_attr_add(
+ imm_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
- immUniformColor4f(1.0f, 1.0f, 1.0f, plane_track->image_opacity);
- immUniform1i("image", 0);
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, plane_track->image_opacity);
+ immUniform1i("image", 0);
- immBegin(GPU_PRIM_TRI_FAN, 4);
+ immBegin(GPU_PRIM_TRI_FAN, 4);
- immAttr2f(texCoord, 0.0f, 0.0f);
- immVertex2f(pos, 0.0f, 0.0f);
+ immAttr2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, 0.0f);
- immAttr2f(texCoord, 1.0f, 0.0f);
- immVertex2f(pos, 1.0f, 0.0f);
+ immAttr2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, 1.0f, 0.0f);
- immAttr2f(texCoord, 1.0f, 1.0f);
- immVertex2f(pos, 1.0f, 1.0f);
+ immAttr2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, 1.0f, 1.0f);
- immAttr2f(texCoord, 0.0f, 1.0f);
- immVertex2f(pos, 0.0f, 1.0f);
+ immAttr2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, 0.0f, 1.0f);
- immEnd();
+ immEnd();
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
- glBindTexture(GL_TEXTURE_2D, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
- if (transparent) {
- GPU_blend(false);
- }
- }
+ if (transparent) {
+ GPU_blend(false);
+ }
+ }
- IMB_display_buffer_release(cache_handle);
- }
+ IMB_display_buffer_release(cache_handle);
+ }
- BKE_image_release_ibuf(image, ibuf, lock);
+ BKE_image_release_ibuf(image, ibuf, lock);
}
-static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track,
- MovieTrackingPlaneMarker *plane_marker, bool is_active_track,
- bool draw_outline, int width, int height)
+static void draw_plane_marker_ex(SpaceClip *sc,
+ Scene *scene,
+ MovieTrackingPlaneTrack *plane_track,
+ MovieTrackingPlaneMarker *plane_marker,
+ bool is_active_track,
+ bool draw_outline,
+ int width,
+ int height)
{
- bool tiny = (sc->flag & SC_SHOW_TINY_MARKER) != 0;
- bool is_selected_track = (plane_track->flag & SELECT) != 0;
- const bool has_image = plane_track->image != NULL &&
- BKE_image_has_ibuf(plane_track->image, NULL);
- const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f;
- float px[2];
- float color[3], selected_color[3];
-
- px[0] = 1.0f / width / sc->zoom;
- px[1] = 1.0f / height / sc->zoom;
-
- /* Draw image */
- if (draw_outline == false) {
- draw_plane_marker_image(scene, plane_track, plane_marker);
- }
-
- if (draw_plane_quad || is_selected_track) {
- const uint shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
-
- float viewport_size[4];
- GPU_viewport_size_get_f(viewport_size);
- immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
-
- immUniform1i("colors_len", 0); /* "simple" mode */
-
- if (draw_plane_quad) {
- const bool stipple = !draw_outline && tiny;
- const bool thick = draw_outline && !tiny;
-
- GPU_line_width(thick ? 3.0f : 1.0f);
-
- if (stipple) {
- immUniform1f("dash_width", 6.0f);
- immUniform1f("dash_factor", 0.5f);
- }
- else {
- immUniform1f("dash_factor", 2.0f); /* Solid line */
- }
-
- if (draw_outline) {
- immUniformThemeColor(TH_MARKER_OUTLINE);
- }
- else {
- plane_track_colors(is_active_track, color, selected_color);
- immUniformColor3fv(is_selected_track ? selected_color : color);
- }
-
- /* Draw rectangle itself. */
- immBegin(GPU_PRIM_LINE_LOOP, 4);
- immVertex2fv(shdr_pos, plane_marker->corners[0]);
- immVertex2fv(shdr_pos, plane_marker->corners[1]);
- immVertex2fv(shdr_pos, plane_marker->corners[2]);
- immVertex2fv(shdr_pos, plane_marker->corners[3]);
- immEnd();
-
- /* Draw axis. */
- if (!draw_outline) {
- float end_point[2];
-
- immUniformColor3f(1.0f, 0.0f, 0.0f);
-
- immBegin(GPU_PRIM_LINES, 2);
-
- getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point);
- immVertex2fv(shdr_pos, plane_marker->corners[0]);
- immVertex2fv(shdr_pos, end_point);
-
- immEnd();
-
- immUniformColor3f(0.0f, 1.0f, 0.0f);
-
- immBegin(GPU_PRIM_LINES, 2);
-
- getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point);
- immVertex2fv(shdr_pos, plane_marker->corners[0]);
- immVertex2fv(shdr_pos, end_point);
-
- immEnd();
- }
- }
-
- /* Draw sliders. */
- if (is_selected_track) {
- immUniform1f("dash_factor", 2.0f); /* Solid line */
-
- if (draw_outline) {
- immUniformThemeColor(TH_MARKER_OUTLINE);
- }
- else {
- immUniformColor3fv(selected_color);
- }
-
- int i;
- for (i = 0; i < 4; i++) {
- draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1],
- 3.0f * px[0], 3.0f * px[1], draw_outline, px, shdr_pos);
- }
- }
-
- immUnbindProgram();
- }
+ bool tiny = (sc->flag & SC_SHOW_TINY_MARKER) != 0;
+ bool is_selected_track = (plane_track->flag & SELECT) != 0;
+ const bool has_image = plane_track->image != NULL &&
+ BKE_image_has_ibuf(plane_track->image, NULL);
+ const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f;
+ float px[2];
+ float color[3], selected_color[3];
+
+ px[0] = 1.0f / width / sc->zoom;
+ px[1] = 1.0f / height / sc->zoom;
+
+ /* Draw image */
+ if (draw_outline == false) {
+ draw_plane_marker_image(scene, plane_track, plane_marker);
+ }
+
+ if (draw_plane_quad || is_selected_track) {
+ const uint shdr_pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("colors_len", 0); /* "simple" mode */
+
+ if (draw_plane_quad) {
+ const bool stipple = !draw_outline && tiny;
+ const bool thick = draw_outline && !tiny;
+
+ GPU_line_width(thick ? 3.0f : 1.0f);
+
+ if (stipple) {
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+ }
+ else {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+ }
+
+ if (draw_outline) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+ }
+ else {
+ plane_track_colors(is_active_track, color, selected_color);
+ immUniformColor3fv(is_selected_track ? selected_color : color);
+ }
+
+ /* Draw rectangle itself. */
+ immBegin(GPU_PRIM_LINE_LOOP, 4);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, plane_marker->corners[1]);
+ immVertex2fv(shdr_pos, plane_marker->corners[2]);
+ immVertex2fv(shdr_pos, plane_marker->corners[3]);
+ immEnd();
+
+ /* Draw axis. */
+ if (!draw_outline) {
+ float end_point[2];
+
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
+
+ immBegin(GPU_PRIM_LINES, 2);
+
+ getArrowEndPoint(width,
+ height,
+ sc->zoom,
+ plane_marker->corners[0],
+ plane_marker->corners[1],
+ end_point);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, end_point);
+
+ immEnd();
+
+ immUniformColor3f(0.0f, 1.0f, 0.0f);
+
+ immBegin(GPU_PRIM_LINES, 2);
+
+ getArrowEndPoint(width,
+ height,
+ sc->zoom,
+ plane_marker->corners[0],
+ plane_marker->corners[3],
+ end_point);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, end_point);
+
+ immEnd();
+ }
+ }
+
+ /* Draw sliders. */
+ if (is_selected_track) {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+
+ if (draw_outline) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+ }
+ else {
+ immUniformColor3fv(selected_color);
+ }
+
+ int i;
+ for (i = 0; i < 4; i++) {
+ draw_marker_slide_square(plane_marker->corners[i][0],
+ plane_marker->corners[i][1],
+ 3.0f * px[0],
+ 3.0f * px[1],
+ draw_outline,
+ px,
+ shdr_pos);
+ }
+ }
+
+ immUnbindProgram();
+ }
}
-static void draw_plane_marker_outline(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track,
- MovieTrackingPlaneMarker *plane_marker, int width, int height)
+static void draw_plane_marker_outline(SpaceClip *sc,
+ Scene *scene,
+ MovieTrackingPlaneTrack *plane_track,
+ MovieTrackingPlaneMarker *plane_marker,
+ int width,
+ int height)
{
- draw_plane_marker_ex(sc, scene, plane_track, plane_marker, false, true, width, height);
+ draw_plane_marker_ex(sc, scene, plane_track, plane_marker, false, true, width, height);
}
-static void draw_plane_marker(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track,
- MovieTrackingPlaneMarker *plane_marker, bool is_active_track,
- int width, int height)
+static void draw_plane_marker(SpaceClip *sc,
+ Scene *scene,
+ MovieTrackingPlaneTrack *plane_track,
+ MovieTrackingPlaneMarker *plane_marker,
+ bool is_active_track,
+ int width,
+ int height)
{
- draw_plane_marker_ex(sc, scene, plane_track, plane_marker, is_active_track, false, width, height);
+ draw_plane_marker_ex(
+ sc, scene, plane_track, plane_marker, is_active_track, false, width, height);
}
-static void draw_plane_track(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track,
- int framenr, bool is_active_track, int width, int height)
+static void draw_plane_track(SpaceClip *sc,
+ Scene *scene,
+ MovieTrackingPlaneTrack *plane_track,
+ int framenr,
+ bool is_active_track,
+ int width,
+ int height)
{
- MovieTrackingPlaneMarker *plane_marker;
+ MovieTrackingPlaneMarker *plane_marker;
- plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
+ plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
- draw_plane_marker_outline(sc, scene, plane_track, plane_marker, width, height);
- draw_plane_marker(sc, scene, plane_track, plane_marker, is_active_track, width, height);
+ draw_plane_marker_outline(sc, scene, plane_track, plane_marker, width, height);
+ draw_plane_marker(sc, scene, plane_track, plane_marker, is_active_track, width, height);
}
/* Draw all kind of tracks. */
-static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, MovieClip *clip,
- int width, int height, float zoomx, float zoomy)
+static void draw_tracking_tracks(SpaceClip *sc,
+ Scene *scene,
+ ARegion *ar,
+ MovieClip *clip,
+ int width,
+ int height,
+ float zoomx,
+ float zoomy)
{
- float x, y;
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- MovieTrackingTrack *track, *act_track;
- MovieTrackingPlaneTrack *plane_track, *active_plane_track;
- MovieTrackingMarker *marker;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- int undistort = sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
- float *marker_pos = NULL, *fp, *active_pos = NULL, cur_pos[2];
-
- /* ** find window pixel coordinates of origin ** */
-
- /* UI_view2d_view_to_region_no_clip return integer values, this could
- * lead to 1px flickering when view is locked to selection during playback.
- * to avoid this flickering, calculate base point in the same way as it happens
- * in UI_view2d_view_to_region_no_clip, but do it in floats here */
-
- UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
-
- GPU_matrix_push();
- GPU_matrix_translate_2f(x, y);
-
- GPU_matrix_push();
- GPU_matrix_scale_2f(zoomx, zoomy);
- GPU_matrix_mul(sc->stabmat);
- GPU_matrix_scale_2f(width, height);
-
- act_track = BKE_tracking_track_get_active(tracking);
-
- /* Draw plane tracks */
- active_plane_track = BKE_tracking_plane_track_get_active(tracking);
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
- draw_plane_track(sc, scene, plane_track, framenr, plane_track == active_plane_track, width, height);
- }
- }
-
- if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
- int count = 0;
-
- /* count */
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker))
- count++;
- }
-
- track = track->next;
- }
-
- /* undistort */
- if (count) {
- marker_pos = MEM_callocN(2 * sizeof(float) * count, "draw_tracking_tracks marker_pos");
-
- track = tracksbase->first;
- fp = marker_pos;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- ED_clip_point_undistorted_pos(sc, marker->pos, fp);
-
- if (track == act_track)
- active_pos = fp;
-
- fp += 2;
- }
- }
-
- track = track->next;
- }
- }
- }
-
- if (sc->flag & SC_SHOW_TRACK_PATH) {
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0)
- draw_track_path(sc, clip, track);
-
- track = track->next;
- }
- }
-
- uint position = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- /* markers outline and non-selected areas */
- track = tracksbase->first;
- fp = marker_pos;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- copy_v2_v2(cur_pos, fp ? fp : marker->pos);
-
- draw_marker_outline(sc, track, marker, cur_pos, width, height, position);
- draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0, position);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position);
-
- if (fp)
- fp += 2;
- }
- }
-
- track = track->next;
- }
-
- /* selected areas only, so selection wouldn't be overlapped by
- * non-selected areas */
- track = tracksbase->first;
- fp = marker_pos;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- int act = track == act_track;
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- if (!act) {
- copy_v2_v2(cur_pos, fp ? fp : marker->pos);
-
- draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1, position);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position);
- }
-
- if (fp)
- fp += 2;
- }
- }
-
- track = track->next;
- }
+ float x, y;
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ MovieTrackingTrack *track, *act_track;
+ MovieTrackingPlaneTrack *plane_track, *active_plane_track;
+ MovieTrackingMarker *marker;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ int undistort = sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
+ float *marker_pos = NULL, *fp, *active_pos = NULL, cur_pos[2];
+
+ /* ** find window pixel coordinates of origin ** */
+
+ /* UI_view2d_view_to_region_no_clip return integer values, this could
+ * lead to 1px flickering when view is locked to selection during playback.
+ * to avoid this flickering, calculate base point in the same way as it happens
+ * in UI_view2d_view_to_region_no_clip, but do it in floats here */
+
+ UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(x, y);
+
+ GPU_matrix_push();
+ GPU_matrix_scale_2f(zoomx, zoomy);
+ GPU_matrix_mul(sc->stabmat);
+ GPU_matrix_scale_2f(width, height);
+
+ act_track = BKE_tracking_track_get_active(tracking);
+
+ /* Draw plane tracks */
+ active_plane_track = BKE_tracking_plane_track_get_active(tracking);
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
+ draw_plane_track(
+ sc, scene, plane_track, framenr, plane_track == active_plane_track, width, height);
+ }
+ }
+
+ if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
+ int count = 0;
+
+ /* count */
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker))
+ count++;
+ }
+
+ track = track->next;
+ }
+
+ /* undistort */
+ if (count) {
+ marker_pos = MEM_callocN(2 * sizeof(float) * count, "draw_tracking_tracks marker_pos");
+
+ track = tracksbase->first;
+ fp = marker_pos;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ ED_clip_point_undistorted_pos(sc, marker->pos, fp);
+
+ if (track == act_track)
+ active_pos = fp;
+
+ fp += 2;
+ }
+ }
+
+ track = track->next;
+ }
+ }
+ }
+
+ if (sc->flag & SC_SHOW_TRACK_PATH) {
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0)
+ draw_track_path(sc, clip, track);
+
+ track = track->next;
+ }
+ }
+
+ uint position = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* markers outline and non-selected areas */
+ track = tracksbase->first;
+ fp = marker_pos;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ copy_v2_v2(cur_pos, fp ? fp : marker->pos);
+
+ draw_marker_outline(sc, track, marker, cur_pos, width, height, position);
+ draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position);
+
+ if (fp)
+ fp += 2;
+ }
+ }
+
+ track = track->next;
+ }
- /* active marker would be displayed on top of everything else */
- if (act_track) {
- if ((act_track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(act_track, framenr);
+ /* selected areas only, so selection wouldn't be overlapped by
+ * non-selected areas */
+ track = tracksbase->first;
+ fp = marker_pos;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ int act = track == act_track;
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ if (!act) {
+ copy_v2_v2(cur_pos, fp ? fp : marker->pos);
+
+ draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position);
+ }
+
+ if (fp)
+ fp += 2;
+ }
+ }
+
+ track = track->next;
+ }
+
+ /* active marker would be displayed on top of everything else */
+ if (act_track) {
+ if ((act_track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(act_track, framenr);
- if (MARKER_VISIBLE(sc, act_track, marker)) {
- copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
+ if (MARKER_VISIBLE(sc, act_track, marker)) {
+ copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
- draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1, position);
- draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height, position);
- }
- }
- }
+ draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1, position);
+ draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height, position);
+ }
+ }
+ }
- if (sc->flag & SC_SHOW_BUNDLES) {
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- float pos[4], vec[4], mat[4][4], aspy;
+ if (sc->flag & SC_SHOW_BUNDLES) {
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ float pos[4], vec[4], mat[4][4], aspy;
- GPU_point_size(3.0f);
+ GPU_point_size(3.0f);
- aspy = 1.0f / clip->tracking.camera.pixel_aspect;
- BKE_tracking_get_projection_matrix(tracking, object, framenr, width, height, mat);
+ aspy = 1.0f / clip->tracking.camera.pixel_aspect;
+ BKE_tracking_get_projection_matrix(tracking, object, framenr, width, height, mat);
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0 && track->flag & TRACK_HAS_BUNDLE) {
- marker = BKE_tracking_marker_get(track, framenr);
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0 && track->flag & TRACK_HAS_BUNDLE) {
+ marker = BKE_tracking_marker_get(track, framenr);
- if (MARKER_VISIBLE(sc, track, marker)) {
- float npos[2];
- copy_v3_v3(vec, track->bundle_pos);
- vec[3] = 1;
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ float npos[2];
+ copy_v3_v3(vec, track->bundle_pos);
+ vec[3] = 1;
- mul_v4_m4v4(pos, mat, vec);
+ mul_v4_m4v4(pos, mat, vec);
- pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
- pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
+ pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
+ pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
- BKE_tracking_distort_v2(tracking, pos, npos);
+ BKE_tracking_distort_v2(tracking, pos, npos);
- if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
- vec[0] = (marker->pos[0] + track->offset[0]) * width;
- vec[1] = (marker->pos[1] + track->offset[1]) * height * aspy;
+ if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
+ vec[0] = (marker->pos[0] + track->offset[0]) * width;
+ vec[1] = (marker->pos[1] + track->offset[1]) * height * aspy;
- sub_v2_v2(vec, npos);
+ sub_v2_v2(vec, npos);
- if (len_squared_v2(vec) < (3.0f * 3.0f)) {
- immUniformColor3f(0.0f, 1.0f, 0.0f);
- }
- else {
- immUniformColor3f(1.0f, 0.0f, 0.0f);
- }
+ if (len_squared_v2(vec) < (3.0f * 3.0f)) {
+ immUniformColor3f(0.0f, 1.0f, 0.0f);
+ }
+ else {
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
+ }
- immBegin(GPU_PRIM_POINTS, 1);
+ immBegin(GPU_PRIM_POINTS, 1);
- if (undistort) {
- immVertex2f(position, pos[0] / width, pos[1] / (height * aspy));
- }
- else {
- immVertex2f(position, npos[0] / width, npos[1] / (height * aspy));
- }
+ if (undistort) {
+ immVertex2f(position, pos[0] / width, pos[1] / (height * aspy));
+ }
+ else {
+ immVertex2f(position, npos[0] / width, npos[1] / (height * aspy));
+ }
- immEnd();
- }
- }
- }
+ immEnd();
+ }
+ }
+ }
- track = track->next;
- }
- }
+ track = track->next;
+ }
+ }
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
- if (sc->flag & SC_SHOW_NAMES) {
- /* scaling should be cleared before drawing texts, otherwise font would also be scaled */
- track = tracksbase->first;
- fp = marker_pos;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(track, framenr);
+ if (sc->flag & SC_SHOW_NAMES) {
+ /* scaling should be cleared before drawing texts, otherwise font would also be scaled */
+ track = tracksbase->first;
+ fp = marker_pos;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(track, framenr);
- if (MARKER_VISIBLE(sc, track, marker)) {
- int act = track == act_track;
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ int act = track == act_track;
- copy_v2_v2(cur_pos, fp ? fp : marker->pos);
+ copy_v2_v2(cur_pos, fp ? fp : marker->pos);
- draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
+ draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
- if (fp)
- fp += 2;
- }
- }
+ if (fp)
+ fp += 2;
+ }
+ }
- track = track->next;
- }
- }
+ track = track->next;
+ }
+ }
- GPU_matrix_pop();
+ GPU_matrix_pop();
- if (marker_pos)
- MEM_freeN(marker_pos);
+ if (marker_pos)
+ MEM_freeN(marker_pos);
}
-static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
- int width, int height, float zoomx, float zoomy)
+static void draw_distortion(
+ SpaceClip *sc, ARegion *ar, MovieClip *clip, int width, int height, float zoomx, float zoomy)
{
- float x, y;
- const int n = 10;
- int i, j, a;
- float pos[2], tpos[2], grid[11][11][2];
- MovieTracking *tracking = &clip->tracking;
- bGPdata *gpd = NULL;
- float aspy = 1.0f / tracking->camera.pixel_aspect;
- float dx = (float)width / n, dy = (float)height / n * aspy;
- float offsx = 0.0f, offsy = 0.0f;
+ float x, y;
+ const int n = 10;
+ int i, j, a;
+ float pos[2], tpos[2], grid[11][11][2];
+ MovieTracking *tracking = &clip->tracking;
+ bGPdata *gpd = NULL;
+ float aspy = 1.0f / tracking->camera.pixel_aspect;
+ float dx = (float)width / n, dy = (float)height / n * aspy;
+ float offsx = 0.0f, offsy = 0.0f;
- if (!tracking->camera.focal)
- return;
+ if (!tracking->camera.focal)
+ return;
- if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0)
- return;
+ if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0)
+ return;
- UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
+ UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
- GPU_matrix_push();
- GPU_matrix_translate_2f(x, y);
- GPU_matrix_scale_2f(zoomx, zoomy);
- GPU_matrix_mul(sc->stabmat);
- GPU_matrix_scale_2f(width, height);
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(x, y);
+ GPU_matrix_scale_2f(zoomx, zoomy);
+ GPU_matrix_mul(sc->stabmat);
+ GPU_matrix_scale_2f(width, height);
- uint position = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint position = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- /* grid */
- if (sc->flag & SC_SHOW_GRID) {
- float val[4][2], idx[4][2];
- float min[2], max[2];
+ /* grid */
+ if (sc->flag & SC_SHOW_GRID) {
+ float val[4][2], idx[4][2];
+ float min[2], max[2];
- for (a = 0; a < 4; a++) {
- if (a < 2)
- val[a][a % 2] = FLT_MAX;
- else
- val[a][a % 2] = -FLT_MAX;
- }
+ for (a = 0; a < 4; a++) {
+ if (a < 2)
+ val[a][a % 2] = FLT_MAX;
+ else
+ val[a][a % 2] = -FLT_MAX;
+ }
- zero_v2(pos);
- for (i = 0; i <= n; i++) {
- for (j = 0; j <= n; j++) {
- if (i == 0 || j == 0 || i == n || j == n) {
- BKE_tracking_distort_v2(tracking, pos, tpos);
+ zero_v2(pos);
+ for (i = 0; i <= n; i++) {
+ for (j = 0; j <= n; j++) {
+ if (i == 0 || j == 0 || i == n || j == n) {
+ BKE_tracking_distort_v2(tracking, pos, tpos);
- for (a = 0; a < 4; a++) {
- int ok;
+ for (a = 0; a < 4; a++) {
+ int ok;
- if (a < 2)
- ok = tpos[a % 2] < val[a][a % 2];
- else
- ok = tpos[a % 2] > val[a][a % 2];
+ if (a < 2)
+ ok = tpos[a % 2] < val[a][a % 2];
+ else
+ ok = tpos[a % 2] > val[a][a % 2];
- if (ok) {
- copy_v2_v2(val[a], tpos);
- idx[a][0] = j;
- idx[a][1] = i;
- }
- }
- }
+ if (ok) {
+ copy_v2_v2(val[a], tpos);
+ idx[a][0] = j;
+ idx[a][1] = i;
+ }
+ }
+ }
- pos[0] += dx;
- }
+ pos[0] += dx;
+ }
- pos[0] = 0.0f;
- pos[1] += dy;
- }
+ pos[0] = 0.0f;
+ pos[1] += dy;
+ }
- INIT_MINMAX2(min, max);
+ INIT_MINMAX2(min, max);
- for (a = 0; a < 4; a++) {
- pos[0] = idx[a][0] * dx;
- pos[1] = idx[a][1] * dy;
+ for (a = 0; a < 4; a++) {
+ pos[0] = idx[a][0] * dx;
+ pos[1] = idx[a][1] * dy;
- BKE_tracking_undistort_v2(tracking, pos, tpos);
+ BKE_tracking_undistort_v2(tracking, pos, tpos);
- minmax_v2v2_v2(min, max, tpos);
- }
+ minmax_v2v2_v2(min, max, tpos);
+ }
- copy_v2_v2(pos, min);
- dx = (max[0] - min[0]) / n;
- dy = (max[1] - min[1]) / n;
+ copy_v2_v2(pos, min);
+ dx = (max[0] - min[0]) / n;
+ dy = (max[1] - min[1]) / n;
- for (i = 0; i <= n; i++) {
- for (j = 0; j <= n; j++) {
- BKE_tracking_distort_v2(tracking, pos, grid[i][j]);
+ for (i = 0; i <= n; i++) {
+ for (j = 0; j <= n; j++) {
+ BKE_tracking_distort_v2(tracking, pos, grid[i][j]);
- grid[i][j][0] /= width;
- grid[i][j][1] /= height * aspy;
+ grid[i][j][0] /= width;
+ grid[i][j][1] /= height * aspy;
- pos[0] += dx;
- }
+ pos[0] += dx;
+ }
- pos[0] = min[0];
- pos[1] += dy;
- }
+ pos[0] = min[0];
+ pos[1] += dy;
+ }
- immUniformColor3f(1.0f, 0.0f, 0.0f);
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
- for (i = 0; i <= n; i++) {
- immBegin(GPU_PRIM_LINE_STRIP, n + 1);
+ for (i = 0; i <= n; i++) {
+ immBegin(GPU_PRIM_LINE_STRIP, n + 1);
- for (j = 0; j <= n; j++) {
- immVertex2fv(position, grid[i][j]);
- }
+ for (j = 0; j <= n; j++) {
+ immVertex2fv(position, grid[i][j]);
+ }
- immEnd();
- }
+ immEnd();
+ }
- for (j = 0; j <= n; j++) {
- immBegin(GPU_PRIM_LINE_STRIP, n + 1);
+ for (j = 0; j <= n; j++) {
+ immBegin(GPU_PRIM_LINE_STRIP, n + 1);
- for (i = 0; i <= n; i++) {
- immVertex2fv(position, grid[i][j]);
- }
+ for (i = 0; i <= n; i++) {
+ immVertex2fv(position, grid[i][j]);
+ }
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
- if (sc->gpencil_src != SC_GPENCIL_SRC_TRACK) {
- gpd = clip->gpd;
- }
+ if (sc->gpencil_src != SC_GPENCIL_SRC_TRACK) {
+ gpd = clip->gpd;
+ }
- if (sc->flag & SC_MANUAL_CALIBRATION && gpd) {
- bGPDlayer *layer = gpd->layers.first;
+ if (sc->flag & SC_MANUAL_CALIBRATION && gpd) {
+ bGPDlayer *layer = gpd->layers.first;
- while (layer) {
- bGPDframe *frame = layer->frames.first;
+ while (layer) {
+ bGPDframe *frame = layer->frames.first;
- if (layer->flag & GP_LAYER_HIDE) {
- layer = layer->next;
- continue;
- }
+ if (layer->flag & GP_LAYER_HIDE) {
+ layer = layer->next;
+ continue;
+ }
- immUniformColor4fv(layer->color);
+ immUniformColor4fv(layer->color);
- GPU_line_width(layer->thickness);
- GPU_point_size((float)(layer->thickness + 2));
+ GPU_line_width(layer->thickness);
+ GPU_point_size((float)(layer->thickness + 2));
- while (frame) {
- bGPDstroke *stroke = frame->strokes.first;
+ while (frame) {
+ bGPDstroke *stroke = frame->strokes.first;
- while (stroke) {
- if (stroke->flag & GP_STROKE_2DSPACE) {
- if (stroke->totpoints > 1) {
- for (i = 0; i < stroke->totpoints - 1; i++) {
- float npos[2], dpos[2], len;
- int steps;
+ while (stroke) {
+ if (stroke->flag & GP_STROKE_2DSPACE) {
+ if (stroke->totpoints > 1) {
+ for (i = 0; i < stroke->totpoints - 1; i++) {
+ float npos[2], dpos[2], len;
+ int steps;
- pos[0] = (stroke->points[i].x + offsx) * width;
- pos[1] = (stroke->points[i].y + offsy) * height * aspy;
+ pos[0] = (stroke->points[i].x + offsx) * width;
+ pos[1] = (stroke->points[i].y + offsy) * height * aspy;
- npos[0] = (stroke->points[i + 1].x + offsx) * width;
- npos[1] = (stroke->points[i + 1].y + offsy) * height * aspy;
+ npos[0] = (stroke->points[i + 1].x + offsx) * width;
+ npos[1] = (stroke->points[i + 1].y + offsy) * height * aspy;
- len = len_v2v2(pos, npos);
- steps = ceil(len / 5.0f);
+ len = len_v2v2(pos, npos);
+ steps = ceil(len / 5.0f);
- /* we want to distort only long straight lines */
- if (stroke->totpoints == 2) {
- BKE_tracking_undistort_v2(tracking, pos, pos);
- BKE_tracking_undistort_v2(tracking, npos, npos);
- }
+ /* we want to distort only long straight lines */
+ if (stroke->totpoints == 2) {
+ BKE_tracking_undistort_v2(tracking, pos, pos);
+ BKE_tracking_undistort_v2(tracking, npos, npos);
+ }
- sub_v2_v2v2(dpos, npos, pos);
- mul_v2_fl(dpos, 1.0f / steps);
+ sub_v2_v2v2(dpos, npos, pos);
+ mul_v2_fl(dpos, 1.0f / steps);
- immBegin(GPU_PRIM_LINE_STRIP, steps + 1);
+ immBegin(GPU_PRIM_LINE_STRIP, steps + 1);
- for (j = 0; j <= steps; j++) {
- BKE_tracking_distort_v2(tracking, pos, tpos);
- immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy));
+ for (j = 0; j <= steps; j++) {
+ BKE_tracking_distort_v2(tracking, pos, tpos);
+ immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy));
- add_v2_v2(pos, dpos);
- }
+ add_v2_v2(pos, dpos);
+ }
- immEnd();
- }
- }
- else if (stroke->totpoints == 1) {
- immBegin(GPU_PRIM_POINTS, 1);
- immVertex2f(position, stroke->points[0].x + offsx, stroke->points[0].y + offsy);
- immEnd();
- }
- }
+ immEnd();
+ }
+ }
+ else if (stroke->totpoints == 1) {
+ immBegin(GPU_PRIM_POINTS, 1);
+ immVertex2f(position, stroke->points[0].x + offsx, stroke->points[0].y + offsy);
+ immEnd();
+ }
+ }
- stroke = stroke->next;
- }
+ stroke = stroke->next;
+ }
- frame = frame->next;
- }
+ frame = frame->next;
+ }
- layer = layer->next;
- }
- }
+ layer = layer->next;
+ }
+ }
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
}
void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- Scene *scene = CTX_data_scene(C);
- ImBuf *ibuf = NULL;
- int width, height;
- float zoomx, zoomy;
-
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
-
- /* if no clip, nothing to do */
- if (!clip) {
- ED_region_grid_draw(ar, zoomx, zoomy);
- return;
- }
-
- if (sc->flag & SC_SHOW_STABLE) {
- float translation[2];
- float aspect = clip->tracking.camera.pixel_aspect;
- float smat[4][4], ismat[4][4];
-
- if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
- ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc,
- &sc->scale, &sc->angle);
- }
-
- if (ibuf != NULL && width != ibuf->x)
- mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x);
- else
- copy_v2_v2(translation, sc->loc);
-
- BKE_tracking_stabilization_data_to_mat4(width, height, aspect, translation,
- sc->scale, sc->angle, sc->stabmat);
-
- unit_m4(smat);
- smat[0][0] = 1.0f / width;
- smat[1][1] = 1.0f / height;
- invert_m4_m4(ismat, smat);
-
- mul_m4_series(sc->unistabmat, smat, sc->stabmat, ismat);
- }
- else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
- ibuf = ED_space_clip_get_buffer(sc);
-
- zero_v2(sc->loc);
- sc->scale = 1.0f;
- unit_m4(sc->stabmat);
- unit_m4(sc->unistabmat);
- }
-
- if (ibuf) {
- draw_movieclip_buffer(C, sc, ar, ibuf, width, height, zoomx, zoomy);
- IMB_freeImBuf(ibuf);
- }
- else if (sc->flag & SC_MUTE_FOOTAGE) {
- draw_movieclip_muted(ar, width, height, zoomx, zoomy);
- }
- else {
- ED_region_grid_draw(ar, zoomx, zoomy);
- }
-
- if (width && height) {
- draw_stabilization_border(sc, ar, width, height, zoomx, zoomy);
- draw_tracking_tracks(sc, scene, ar, clip, width, height, zoomx, zoomy);
- draw_distortion(sc, ar, clip, width, height, zoomx, zoomy);
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ Scene *scene = CTX_data_scene(C);
+ ImBuf *ibuf = NULL;
+ int width, height;
+ float zoomx, zoomy;
+
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+
+ /* if no clip, nothing to do */
+ if (!clip) {
+ ED_region_grid_draw(ar, zoomx, zoomy);
+ return;
+ }
+
+ if (sc->flag & SC_SHOW_STABLE) {
+ float translation[2];
+ float aspect = clip->tracking.camera.pixel_aspect;
+ float smat[4][4], ismat[4][4];
+
+ if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
+ ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
+ }
+
+ if (ibuf != NULL && width != ibuf->x)
+ mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x);
+ else
+ copy_v2_v2(translation, sc->loc);
+
+ BKE_tracking_stabilization_data_to_mat4(
+ width, height, aspect, translation, sc->scale, sc->angle, sc->stabmat);
+
+ unit_m4(smat);
+ smat[0][0] = 1.0f / width;
+ smat[1][1] = 1.0f / height;
+ invert_m4_m4(ismat, smat);
+
+ mul_m4_series(sc->unistabmat, smat, sc->stabmat, ismat);
+ }
+ else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
+ ibuf = ED_space_clip_get_buffer(sc);
+
+ zero_v2(sc->loc);
+ sc->scale = 1.0f;
+ unit_m4(sc->stabmat);
+ unit_m4(sc->unistabmat);
+ }
+
+ if (ibuf) {
+ draw_movieclip_buffer(C, sc, ar, ibuf, width, height, zoomx, zoomy);
+ IMB_freeImBuf(ibuf);
+ }
+ else if (sc->flag & SC_MUTE_FOOTAGE) {
+ draw_movieclip_muted(ar, width, height, zoomx, zoomy);
+ }
+ else {
+ ED_region_grid_draw(ar, zoomx, zoomy);
+ }
+
+ if (width && height) {
+ draw_stabilization_border(sc, ar, width, height, zoomx, zoomy);
+ draw_tracking_tracks(sc, scene, ar, clip, width, height, zoomx, zoomy);
+ draw_distortion(sc, ar, clip, width, height, zoomx, zoomy);
+ }
}
void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *ar)
{
- Scene *scene = CTX_data_scene(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- if (clip) {
- draw_movieclip_cache(sc, ar, clip, scene);
- draw_movieclip_notes(sc, ar);
- }
+ Scene *scene = CTX_data_scene(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (clip) {
+ draw_movieclip_cache(sc, ar, clip, scene);
+ draw_movieclip_notes(sc, ar);
+ }
}
/* draw grease pencil */
void clip_draw_grease_pencil(bContext *C, int onlyv2d)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
-
- if (!clip)
- return;
-
- if (onlyv2d) {
- bool is_track_source = sc->gpencil_src == SC_GPENCIL_SRC_TRACK;
- /* if manual calibration is used then grease pencil data
- * associated with the clip is already drawn in draw_distortion
- */
- if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || is_track_source) {
- GPU_matrix_push();
- GPU_matrix_mul(sc->unistabmat);
-
- if (is_track_source) {
- MovieTrackingTrack *track = BKE_tracking_track_get_active(&sc->clip->tracking);
-
- if (track) {
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
-
- GPU_matrix_translate_2fv(marker->pos);
- }
- }
-
- ED_annotation_draw_2dimage(C);
-
- GPU_matrix_pop();
- }
- }
- else {
- ED_annotation_draw_view2d(C, 0);
- }
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+
+ if (!clip)
+ return;
+
+ if (onlyv2d) {
+ bool is_track_source = sc->gpencil_src == SC_GPENCIL_SRC_TRACK;
+ /* if manual calibration is used then grease pencil data
+ * associated with the clip is already drawn in draw_distortion
+ */
+ if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || is_track_source) {
+ GPU_matrix_push();
+ GPU_matrix_mul(sc->unistabmat);
+
+ if (is_track_source) {
+ MovieTrackingTrack *track = BKE_tracking_track_get_active(&sc->clip->tracking);
+
+ if (track) {
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+
+ GPU_matrix_translate_2fv(marker->pos);
+ }
+ }
+
+ ED_annotation_draw_2dimage(C);
+
+ GPU_matrix_pop();
+ }
+ }
+ else {
+ ED_annotation_draw_view2d(C, 0);
+ }
}
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index 7cfc5257792..8351f79aac7 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -50,7 +50,6 @@
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
-
#include "IMB_colormanagement.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -65,1062 +64,1093 @@
#include "UI_view2d.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
/* ******** operactor poll functions ******** */
bool ED_space_clip_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc && sc->clip)
- return true;
+ if (sc && sc->clip)
+ return true;
- return false;
+ return false;
}
bool ED_space_clip_view_clip_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc) {
- return sc->view == SC_VIEW_CLIP;
- }
+ if (sc) {
+ return sc->view == SC_VIEW_CLIP;
+ }
- return false;
+ return false;
}
bool ED_space_clip_tracking_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc && sc->clip)
- return ED_space_clip_check_show_trackedit(sc);
+ if (sc && sc->clip)
+ return ED_space_clip_check_show_trackedit(sc);
- return false;
+ return false;
}
bool ED_space_clip_maskedit_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc && sc->clip) {
- return ED_space_clip_check_show_maskedit(sc);
- }
+ if (sc && sc->clip) {
+ return ED_space_clip_check_show_maskedit(sc);
+ }
- return false;
+ return false;
}
bool ED_space_clip_maskedit_mask_poll(bContext *C)
{
- if (ED_space_clip_maskedit_poll(C)) {
- MovieClip *clip = CTX_data_edit_movieclip(C);
+ if (ED_space_clip_maskedit_poll(C)) {
+ MovieClip *clip = CTX_data_edit_movieclip(C);
- if (clip) {
- SpaceClip *sc = CTX_wm_space_clip(C);
+ if (clip) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
- return sc->mask_info.mask != NULL;
- }
- }
+ return sc->mask_info.mask != NULL;
+ }
+ }
- return false;
+ return false;
}
/* ******** common editing functions ******** */
void ED_space_clip_get_size(SpaceClip *sc, int *width, int *height)
{
- if (sc->clip) {
- BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
- }
- else {
- *width = *height = IMG_SIZE_FALLBACK;
- }
+ if (sc->clip) {
+ BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
+ }
+ else {
+ *width = *height = IMG_SIZE_FALLBACK;
+ }
}
void ED_space_clip_get_size_fl(SpaceClip *sc, float size[2])
{
- int size_i[2];
- ED_space_clip_get_size(sc, &size_i[0], &size_i[1]);
- size[0] = size_i[0];
- size[1] = size_i[1];
+ int size_i[2];
+ ED_space_clip_get_size(sc, &size_i[0], &size_i[1]);
+ size[0] = size_i[0];
+ size[1] = size_i[1];
}
void ED_space_clip_get_zoom(SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy)
{
- int width, height;
+ int width, height;
- ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_size(sc, &width, &height);
- *zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / (BLI_rctf_size_x(&ar->v2d.cur) * width);
- *zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / (BLI_rctf_size_y(&ar->v2d.cur) * height);
+ *zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / (BLI_rctf_size_x(&ar->v2d.cur) * width);
+ *zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / (BLI_rctf_size_y(&ar->v2d.cur) * height);
}
void ED_space_clip_get_aspect(SpaceClip *sc, float *aspx, float *aspy)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
-
- if (clip)
- BKE_movieclip_get_aspect(clip, aspx, aspy);
- else
- *aspx = *aspy = 1.0f;
-
- if (*aspx < *aspy) {
- *aspy = *aspy / *aspx;
- *aspx = 1.0f;
- }
- else {
- *aspx = *aspx / *aspy;
- *aspy = 1.0f;
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+
+ if (clip)
+ BKE_movieclip_get_aspect(clip, aspx, aspy);
+ else
+ *aspx = *aspy = 1.0f;
+
+ if (*aspx < *aspy) {
+ *aspy = *aspy / *aspx;
+ *aspx = 1.0f;
+ }
+ else {
+ *aspx = *aspx / *aspy;
+ *aspy = 1.0f;
+ }
}
void ED_space_clip_get_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy)
{
- int w, h;
-
- /* most of tools does not require aspect to be returned with dimensions correction
- * due to they're invariant to this stuff, but some transformation tools like rotation
- * should be aware of aspect correction caused by different resolution in different
- * directions.
- * mainly this is sued for transformation stuff
- */
-
- if (!sc->clip) {
- *aspx = 1.0f;
- *aspy = 1.0f;
-
- return;
- }
-
- ED_space_clip_get_aspect(sc, aspx, aspy);
- BKE_movieclip_get_size(sc->clip, &sc->user, &w, &h);
-
- *aspx *= (float) w;
- *aspy *= (float) h;
-
- if (*aspx < *aspy) {
- *aspy = *aspy / *aspx;
- *aspx = 1.0f;
- }
- else {
- *aspx = *aspx / *aspy;
- *aspy = 1.0f;
- }
+ int w, h;
+
+ /* most of tools does not require aspect to be returned with dimensions correction
+ * due to they're invariant to this stuff, but some transformation tools like rotation
+ * should be aware of aspect correction caused by different resolution in different
+ * directions.
+ * mainly this is sued for transformation stuff
+ */
+
+ if (!sc->clip) {
+ *aspx = 1.0f;
+ *aspy = 1.0f;
+
+ return;
+ }
+
+ ED_space_clip_get_aspect(sc, aspx, aspy);
+ BKE_movieclip_get_size(sc->clip, &sc->user, &w, &h);
+
+ *aspx *= (float)w;
+ *aspy *= (float)h;
+
+ if (*aspx < *aspy) {
+ *aspy = *aspy / *aspx;
+ *aspx = 1.0f;
+ }
+ else {
+ *aspx = *aspx / *aspy;
+ *aspy = 1.0f;
+ }
}
/* return current frame number in clip space */
int ED_space_clip_get_clip_frame_number(SpaceClip *sc)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- /* Caller must ensure space does have a valid clip, otherwise it will crash, see T45017. */
- return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr);
+ /* Caller must ensure space does have a valid clip, otherwise it will crash, see T45017. */
+ return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr);
}
ImBuf *ED_space_clip_get_buffer(SpaceClip *sc)
{
- if (sc->clip) {
- ImBuf *ibuf;
+ if (sc->clip) {
+ ImBuf *ibuf;
- ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag);
+ ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag);
- if (ibuf && (ibuf->rect || ibuf->rect_float))
- return ibuf;
+ if (ibuf && (ibuf->rect || ibuf->rect_float))
+ return ibuf;
- if (ibuf)
- IMB_freeImBuf(ibuf);
- }
+ if (ibuf)
+ IMB_freeImBuf(ibuf);
+ }
- return NULL;
+ return NULL;
}
ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale, float *angle)
{
- if (sc->clip) {
- ImBuf *ibuf;
+ if (sc->clip) {
+ ImBuf *ibuf;
- ibuf = BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag);
+ ibuf = BKE_movieclip_get_stable_ibuf(
+ sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag);
- if (ibuf && (ibuf->rect || ibuf->rect_float))
- return ibuf;
+ if (ibuf && (ibuf->rect || ibuf->rect_float))
+ return ibuf;
- if (ibuf)
- IMB_freeImBuf(ibuf);
- }
+ if (ibuf)
+ IMB_freeImBuf(ibuf);
+ }
- return NULL;
+ return NULL;
}
/* Returns color in linear space, matching ED_space_image_color_sample(). */
bool ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3])
{
- ImBuf *ibuf;
- float fx, fy, co[2];
- bool ret = false;
-
- ibuf = ED_space_clip_get_buffer(sc);
- if (!ibuf) {
- return false;
- }
-
- /* map the mouse coords to the backdrop image space */
- ED_clip_mouse_pos(sc, ar, mval, co);
-
- fx = co[0];
- fy = co[1];
-
- if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
- const float *fp;
- unsigned char *cp;
- int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
-
- CLAMP(x, 0, ibuf->x - 1);
- CLAMP(y, 0, ibuf->y - 1);
-
- if (ibuf->rect_float) {
- fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
- copy_v3_v3(r_col, fp);
- ret = true;
- }
- else if (ibuf->rect) {
- cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
- rgb_uchar_to_float(r_col, cp);
- IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace);
- ret = true;
- }
- }
-
- IMB_freeImBuf(ibuf);
-
- return ret;
+ ImBuf *ibuf;
+ float fx, fy, co[2];
+ bool ret = false;
+
+ ibuf = ED_space_clip_get_buffer(sc);
+ if (!ibuf) {
+ return false;
+ }
+
+ /* map the mouse coords to the backdrop image space */
+ ED_clip_mouse_pos(sc, ar, mval, co);
+
+ fx = co[0];
+ fy = co[1];
+
+ if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
+ const float *fp;
+ unsigned char *cp;
+ int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
+
+ CLAMP(x, 0, ibuf->x - 1);
+ CLAMP(y, 0, ibuf->y - 1);
+
+ if (ibuf->rect_float) {
+ fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
+ copy_v3_v3(r_col, fp);
+ ret = true;
+ }
+ else if (ibuf->rect) {
+ cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
+ rgb_uchar_to_float(r_col, cp);
+ IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace);
+ ret = true;
+ }
+ }
+
+ IMB_freeImBuf(ibuf);
+
+ return ret;
}
void ED_clip_update_frame(const Main *mainp, int cfra)
{
- /* image window, compo node users */
- for (wmWindowManager *wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
- for (wmWindow *win = wm->windows.first; win; win = win->next) {
- bScreen *screen = WM_window_get_active_screen(win);
-
- for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype == SPACE_CLIP) {
- SpaceClip *sc = sa->spacedata.first;
-
- sc->scopes.ok = false;
-
- BKE_movieclip_user_set_frame(&sc->user, cfra);
- }
- }
- }
- }
+ /* image window, compo node users */
+ for (wmWindowManager *wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ if (sa->spacetype == SPACE_CLIP) {
+ SpaceClip *sc = sa->spacedata.first;
+
+ sc->scopes.ok = false;
+
+ BKE_movieclip_user_set_frame(&sc->user, cfra);
+ }
+ }
+ }
+ }
}
static bool selected_tracking_boundbox(SpaceClip *sc, float min[2], float max[2])
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTrackingTrack *track;
- int width, height;
- bool ok = false;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTrackingTrack *track;
+ int width, height;
+ bool ok = false;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
- INIT_MINMAX2(min, max);
+ INIT_MINMAX2(min, max);
- ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_size(sc, &width, &height);
- track = tracksbase->first;
- while (track) {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ track = tracksbase->first;
+ while (track) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
- if (marker) {
- float pos[3];
+ if (marker) {
+ float pos[3];
- pos[0] = marker->pos[0] + track->offset[0];
- pos[1] = marker->pos[1] + track->offset[1];
- pos[2] = 0.0f;
+ pos[0] = marker->pos[0] + track->offset[0];
+ pos[1] = marker->pos[1] + track->offset[1];
+ pos[2] = 0.0f;
- /* undistortion happens for normalized coords */
- if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
- /* undistortion happens for normalized coords */
- ED_clip_point_undistorted_pos(sc, pos, pos);
- }
+ /* undistortion happens for normalized coords */
+ if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
+ /* undistortion happens for normalized coords */
+ ED_clip_point_undistorted_pos(sc, pos, pos);
+ }
- pos[0] *= width;
- pos[1] *= height;
+ pos[0] *= width;
+ pos[1] *= height;
- mul_v3_m4v3(pos, sc->stabmat, pos);
+ mul_v3_m4v3(pos, sc->stabmat, pos);
- minmax_v2v2_v2(min, max, pos);
+ minmax_v2v2_v2(min, max, pos);
- ok = true;
- }
- }
+ ok = true;
+ }
+ }
- track = track->next;
- }
+ track = track->next;
+ }
- return ok;
+ return ok;
}
static bool selected_boundbox(const bContext *C, float min[2], float max[2])
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc->mode == SC_MODE_TRACKING) {
- return selected_tracking_boundbox(sc, min, max);
- }
- else {
- if (ED_mask_selected_minmax(C, min, max)) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int width, height;
- ED_space_clip_get_size(sc, &width, &height);
- BKE_mask_coord_to_movieclip(clip, &sc->user, min, min);
- BKE_mask_coord_to_movieclip(clip, &sc->user, max, max);
- min[0] *= width;
- min[1] *= height;
- max[0] *= width;
- max[1] *= height;
- return true;
- }
- return false;
- }
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ if (sc->mode == SC_MODE_TRACKING) {
+ return selected_tracking_boundbox(sc, min, max);
+ }
+ else {
+ if (ED_mask_selected_minmax(C, min, max)) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int width, height;
+ ED_space_clip_get_size(sc, &width, &height);
+ BKE_mask_coord_to_movieclip(clip, &sc->user, min, min);
+ BKE_mask_coord_to_movieclip(clip, &sc->user, max, max);
+ min[0] *= width;
+ min[1] *= height;
+ max[0] *= width;
+ max[1] *= height;
+ return true;
+ }
+ return false;
+ }
}
bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- int w, h, frame_width, frame_height;
- float min[2], max[2];
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ int w, h, frame_width, frame_height;
+ float min[2], max[2];
- ED_space_clip_get_size(sc, &frame_width, &frame_height);
+ ED_space_clip_get_size(sc, &frame_width, &frame_height);
- if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL))
- return false;
+ if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL))
+ return false;
- if (!selected_boundbox(C, min, max))
- return false;
+ if (!selected_boundbox(C, min, max))
+ return false;
- /* center view */
- clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width),
- (max[1] + min[1]) / (2 * frame_height));
+ /* center view */
+ clip_view_center_to_point(
+ sc, (max[0] + min[0]) / (2 * frame_width), (max[1] + min[1]) / (2 * frame_height));
- w = max[0] - min[0];
- h = max[1] - min[1];
+ w = max[0] - min[0];
+ h = max[1] - min[1];
- /* set zoom to see all selection */
- if (w > 0 && h > 0) {
- int width, height;
- float zoomx, zoomy, newzoom, aspx, aspy;
+ /* set zoom to see all selection */
+ if (w > 0 && h > 0) {
+ int width, height;
+ float zoomx, zoomy, newzoom, aspx, aspy;
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
- width = BLI_rcti_size_x(&ar->winrct) + 1;
- height = BLI_rcti_size_y(&ar->winrct) + 1;
+ width = BLI_rcti_size_x(&ar->winrct) + 1;
+ height = BLI_rcti_size_y(&ar->winrct) + 1;
- zoomx = (float)width / w / aspx;
- zoomy = (float)height / h / aspy;
+ zoomx = (float)width / w / aspx;
+ zoomy = (float)height / h / aspy;
- newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy));
+ newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy));
- if (fit || sc->zoom > newzoom)
- sc->zoom = newzoom;
- }
+ if (fit || sc->zoom > newzoom)
+ sc->zoom = newzoom;
+ }
- return true;
+ return true;
}
void ED_clip_select_all(SpaceClip *sc, int action, bool *r_has_selection)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- const int framenr = ED_space_clip_get_clip_frame_number(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *track = NULL; /* selected track */
- MovieTrackingPlaneTrack *plane_track = NULL; /* selected plane track */
- MovieTrackingMarker *marker;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- bool has_selection = false;
-
- if (action == SEL_TOGGLE) {
- action = SEL_SELECT;
-
- for (track = tracksbase->first; track; track = track->next) {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- action = SEL_DESELECT;
- break;
- }
- }
- }
-
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- action = SEL_DESELECT;
- break;
- }
- }
- }
-
- for (track = tracksbase->first; track; track = track->next) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- switch (action) {
- case SEL_SELECT:
- track->flag |= SELECT;
- track->pat_flag |= SELECT;
- track->search_flag |= SELECT;
- break;
- case SEL_DESELECT:
- track->flag &= ~SELECT;
- track->pat_flag &= ~SELECT;
- track->search_flag &= ~SELECT;
- break;
- case SEL_INVERT:
- track->flag ^= SELECT;
- track->pat_flag ^= SELECT;
- track->search_flag ^= SELECT;
- break;
- }
- }
- }
-
- if (TRACK_VIEW_SELECTED(sc, track))
- has_selection = true;
- }
-
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
- switch (action) {
- case SEL_SELECT:
- plane_track->flag |= SELECT;
- break;
- case SEL_DESELECT:
- plane_track->flag &= ~SELECT;
- break;
- case SEL_INVERT:
- plane_track->flag ^= SELECT;
- break;
- }
- if (plane_track->flag & SELECT) {
- has_selection = true;
- }
- }
- }
-
- if (r_has_selection) {
- *r_has_selection = has_selection;
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ const int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *track = NULL; /* selected track */
+ MovieTrackingPlaneTrack *plane_track = NULL; /* selected plane track */
+ MovieTrackingMarker *marker;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ bool has_selection = false;
+
+ if (action == SEL_TOGGLE) {
+ action = SEL_SELECT;
+
+ for (track = tracksbase->first; track; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ action = SEL_DESELECT;
+ break;
+ }
+ }
+ }
+
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ action = SEL_DESELECT;
+ break;
+ }
+ }
+ }
+
+ for (track = tracksbase->first; track; track = track->next) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ switch (action) {
+ case SEL_SELECT:
+ track->flag |= SELECT;
+ track->pat_flag |= SELECT;
+ track->search_flag |= SELECT;
+ break;
+ case SEL_DESELECT:
+ track->flag &= ~SELECT;
+ track->pat_flag &= ~SELECT;
+ track->search_flag &= ~SELECT;
+ break;
+ case SEL_INVERT:
+ track->flag ^= SELECT;
+ track->pat_flag ^= SELECT;
+ track->search_flag ^= SELECT;
+ break;
+ }
+ }
+ }
+
+ if (TRACK_VIEW_SELECTED(sc, track))
+ has_selection = true;
+ }
+
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
+ switch (action) {
+ case SEL_SELECT:
+ plane_track->flag |= SELECT;
+ break;
+ case SEL_DESELECT:
+ plane_track->flag &= ~SELECT;
+ break;
+ case SEL_INVERT:
+ plane_track->flag ^= SELECT;
+ break;
+ }
+ if (plane_track->flag & SELECT) {
+ has_selection = true;
+ }
+ }
+ }
+
+ if (r_has_selection) {
+ *r_has_selection = has_selection;
+ }
}
void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[2])
{
- copy_v2_v2(r_co, co);
+ copy_v2_v2(r_co, co);
- if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
- float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
- int width, height;
+ if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
+ int width, height;
- BKE_movieclip_get_size(sc->clip, &sc->user, &width, &height);
+ BKE_movieclip_get_size(sc->clip, &sc->user, &width, &height);
- r_co[0] *= width;
- r_co[1] *= height * aspy;
+ r_co[0] *= width;
+ r_co[1] *= height * aspy;
- BKE_tracking_undistort_v2(&clip->tracking, r_co, r_co);
+ BKE_tracking_undistort_v2(&clip->tracking, r_co, r_co);
- r_co[0] /= width;
- r_co[1] /= height * aspy;
- }
+ r_co[0] /= width;
+ r_co[1] /= height * aspy;
+ }
}
void ED_clip_point_stable_pos(SpaceClip *sc, ARegion *ar, float x, float y, float *xr, float *yr)
{
- int sx, sy, width, height;
- float zoomx, zoomy, pos[3], imat[4][4];
+ int sx, sy, width, height;
+ float zoomx, zoomy, pos[3], imat[4][4];
- ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
- ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+ ED_space_clip_get_size(sc, &width, &height);
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
- pos[0] = (x - sx) / zoomx;
- pos[1] = (y - sy) / zoomy;
- pos[2] = 0.0f;
+ pos[0] = (x - sx) / zoomx;
+ pos[1] = (y - sy) / zoomy;
+ pos[2] = 0.0f;
- invert_m4_m4(imat, sc->stabmat);
- mul_v3_m4v3(pos, imat, pos);
+ invert_m4_m4(imat, sc->stabmat);
+ mul_v3_m4v3(pos, imat, pos);
- *xr = pos[0] / width;
- *yr = pos[1] / height;
+ *xr = pos[0] / width;
+ *yr = pos[1] / height;
- if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- float aspy = 1.0f / tracking->camera.pixel_aspect;
- float tmp[2] = {*xr * width, *yr * height * aspy};
+ if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ float aspy = 1.0f / tracking->camera.pixel_aspect;
+ float tmp[2] = {*xr * width, *yr * height * aspy};
- BKE_tracking_distort_v2(tracking, tmp, tmp);
+ BKE_tracking_distort_v2(tracking, tmp, tmp);
- *xr = tmp[0] / width;
- *yr = tmp[1] / (height * aspy);
- }
+ *xr = tmp[0] / width;
+ *yr = tmp[1] / (height * aspy);
+ }
}
/**
* \brief the reverse of #ED_clip_point_stable_pos(), gets the marker region coords.
* better name here? view_to_track / track_to_view or so?
*/
-void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[2])
+void ED_clip_point_stable_pos__reverse(SpaceClip *sc,
+ ARegion *ar,
+ const float co[2],
+ float r_co[2])
{
- float zoomx, zoomy;
- float pos[3];
- int width, height;
- int sx, sy;
+ float zoomx, zoomy;
+ float pos[3];
+ int width, height;
+ int sx, sy;
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
- ED_clip_point_undistorted_pos(sc, co, pos);
- pos[2] = 0.0f;
+ ED_clip_point_undistorted_pos(sc, co, pos);
+ pos[2] = 0.0f;
- /* untested */
- mul_v3_m4v3(pos, sc->stabmat, pos);
+ /* untested */
+ mul_v3_m4v3(pos, sc->stabmat, pos);
- r_co[0] = (pos[0] * width * zoomx) + (float)sx;
- r_co[1] = (pos[1] * height * zoomy) + (float)sy;
+ r_co[0] = (pos[0] * width * zoomx) + (float)sx;
+ r_co[1] = (pos[1] * height * zoomy) + (float)sy;
}
/* takes event->mval */
void ED_clip_mouse_pos(SpaceClip *sc, ARegion *ar, const int mval[2], float co[2])
{
- ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &co[0], &co[1]);
+ ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &co[0], &co[1]);
}
bool ED_space_clip_check_show_trackedit(SpaceClip *sc)
{
- if (sc) {
- return sc->mode == SC_MODE_TRACKING;
- }
+ if (sc) {
+ return sc->mode == SC_MODE_TRACKING;
+ }
- return false;
+ return false;
}
bool ED_space_clip_check_show_maskedit(SpaceClip *sc)
{
- if (sc) {
- return sc->mode == SC_MODE_MASKEDIT;
- }
+ if (sc) {
+ return sc->mode == SC_MODE_MASKEDIT;
+ }
- return false;
+ return false;
}
/* ******** clip editing functions ******** */
MovieClip *ED_space_clip_get_clip(SpaceClip *sc)
{
- return sc->clip;
+ return sc->clip;
}
void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
{
- MovieClip *old_clip;
- bool old_clip_visible = false;
-
- if (!screen && C)
- screen = CTX_wm_screen(C);
-
- old_clip = sc->clip;
- sc->clip = clip;
-
- id_us_ensure_real((ID *)sc->clip);
-
- if (screen && sc->view == SC_VIEW_CLIP) {
- ScrArea *area;
- SpaceLink *sl;
-
- for (area = screen->areabase.first; area; area = area->next) {
- for (sl = area->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_CLIP) {
- SpaceClip *cur_sc = (SpaceClip *) sl;
-
- if (cur_sc != sc) {
- if (cur_sc->view == SC_VIEW_CLIP) {
- if (cur_sc->clip == old_clip)
- old_clip_visible = true;
- }
- else {
- if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
- cur_sc->clip = clip;
- }
- }
- }
- }
- }
- }
- }
-
- /* If clip is no longer visible on screen, free memory used by it's cache */
- if (old_clip && old_clip != clip && !old_clip_visible) {
- BKE_movieclip_clear_cache(old_clip);
- }
-
- if (C)
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
+ MovieClip *old_clip;
+ bool old_clip_visible = false;
+
+ if (!screen && C)
+ screen = CTX_wm_screen(C);
+
+ old_clip = sc->clip;
+ sc->clip = clip;
+
+ id_us_ensure_real((ID *)sc->clip);
+
+ if (screen && sc->view == SC_VIEW_CLIP) {
+ ScrArea *area;
+ SpaceLink *sl;
+
+ for (area = screen->areabase.first; area; area = area->next) {
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_CLIP) {
+ SpaceClip *cur_sc = (SpaceClip *)sl;
+
+ if (cur_sc != sc) {
+ if (cur_sc->view == SC_VIEW_CLIP) {
+ if (cur_sc->clip == old_clip)
+ old_clip_visible = true;
+ }
+ else {
+ if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
+ cur_sc->clip = clip;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* If clip is no longer visible on screen, free memory used by it's cache */
+ if (old_clip && old_clip != clip && !old_clip_visible) {
+ BKE_movieclip_clear_cache(old_clip);
+ }
+
+ if (C)
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
}
/* ******** masking editing functions ******** */
Mask *ED_space_clip_get_mask(SpaceClip *sc)
{
- return sc->mask_info.mask;
+ return sc->mask_info.mask;
}
void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask)
{
- sc->mask_info.mask = mask;
+ sc->mask_info.mask = mask;
- id_us_ensure_real((ID *)sc->mask_info.mask);
+ id_us_ensure_real((ID *)sc->mask_info.mask);
- if (C) {
- WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
- }
+ if (C) {
+ WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
+ }
}
/* ******** pre-fetching functions ******** */
typedef struct PrefetchJob {
- MovieClip *clip;
- int start_frame, current_frame, end_frame;
- short render_size, render_flag;
+ MovieClip *clip;
+ int start_frame, current_frame, end_frame;
+ short render_size, render_flag;
} PrefetchJob;
typedef struct PrefetchQueue {
- int initial_frame, current_frame, start_frame, end_frame;
- short render_size, render_flag;
+ int initial_frame, current_frame, start_frame, end_frame;
+ short render_size, render_flag;
- /* If true prefecthing goes forward in time,
- * otherwise it goes backwards in time (starting from current frame).
- */
- bool forward;
+ /* If true prefecthing goes forward in time,
+ * otherwise it goes backwards in time (starting from current frame).
+ */
+ bool forward;
- SpinLock spin;
+ SpinLock spin;
- short *stop;
- short *do_update;
- float *progress;
+ short *stop;
+ short *do_update;
+ float *progress;
} PrefetchQueue;
/* check whether pre-fetching is allowed */
static bool check_prefetch_break(void)
{
- return G.is_break;
+ return G.is_break;
}
/* read file for specified frame number to the memory */
static unsigned char *prefetch_read_file_to_memory(
- MovieClip *clip, int current_frame, short render_size, short render_flag,
- size_t *r_size)
+ MovieClip *clip, int current_frame, short render_size, short render_flag, size_t *r_size)
{
- MovieClipUser user = {0};
- user.framenr = current_frame;
- user.render_size = render_size;
- user.render_flag = render_flag;
-
- char name[FILE_MAX];
- BKE_movieclip_filename_for_frame(clip, &user, name);
-
- int file = BLI_open(name, O_BINARY | O_RDONLY, 0);
- if (file == -1) {
- return NULL;
- }
-
- const size_t size = BLI_file_descriptor_size(file);
- if (size < 1) {
- close(file);
- return NULL;
- }
-
- unsigned char *mem = MEM_mallocN(size, "movieclip prefetch memory file");
- if (mem == NULL) {
- close(file);
- return NULL;
- }
-
- if (read(file, mem, size) != size) {
- close(file);
- MEM_freeN(mem);
- return NULL;
- }
-
- *r_size = size;
-
- close(file);
-
- return mem;
+ MovieClipUser user = {0};
+ user.framenr = current_frame;
+ user.render_size = render_size;
+ user.render_flag = render_flag;
+
+ char name[FILE_MAX];
+ BKE_movieclip_filename_for_frame(clip, &user, name);
+
+ int file = BLI_open(name, O_BINARY | O_RDONLY, 0);
+ if (file == -1) {
+ return NULL;
+ }
+
+ const size_t size = BLI_file_descriptor_size(file);
+ if (size < 1) {
+ close(file);
+ return NULL;
+ }
+
+ unsigned char *mem = MEM_mallocN(size, "movieclip prefetch memory file");
+ if (mem == NULL) {
+ close(file);
+ return NULL;
+ }
+
+ if (read(file, mem, size) != size) {
+ close(file);
+ MEM_freeN(mem);
+ return NULL;
+ }
+
+ *r_size = size;
+
+ close(file);
+
+ return mem;
}
/* find first uncached frame within prefetching frame range */
-static int prefetch_find_uncached_frame(MovieClip *clip, int from_frame, int end_frame,
- short render_size, short render_flag, short direction)
+static int prefetch_find_uncached_frame(MovieClip *clip,
+ int from_frame,
+ int end_frame,
+ short render_size,
+ short render_flag,
+ short direction)
{
- int current_frame;
- MovieClipUser user = {0};
-
- user.render_size = render_size;
- user.render_flag = render_flag;
-
- if (direction > 0) {
- for (current_frame = from_frame; current_frame <= end_frame; current_frame++) {
- user.framenr = current_frame;
-
- if (!BKE_movieclip_has_cached_frame(clip, &user))
- break;
- }
- }
- else {
- for (current_frame = from_frame; current_frame >= end_frame; current_frame--) {
- user.framenr = current_frame;
-
- if (!BKE_movieclip_has_cached_frame(clip, &user))
- break;
- }
- }
-
- return current_frame;
+ int current_frame;
+ MovieClipUser user = {0};
+
+ user.render_size = render_size;
+ user.render_flag = render_flag;
+
+ if (direction > 0) {
+ for (current_frame = from_frame; current_frame <= end_frame; current_frame++) {
+ user.framenr = current_frame;
+
+ if (!BKE_movieclip_has_cached_frame(clip, &user))
+ break;
+ }
+ }
+ else {
+ for (current_frame = from_frame; current_frame >= end_frame; current_frame--) {
+ user.framenr = current_frame;
+
+ if (!BKE_movieclip_has_cached_frame(clip, &user))
+ break;
+ }
+ }
+
+ return current_frame;
}
/* get memory buffer for first uncached frame within prefetch frame range */
-static unsigned char *prefetch_thread_next_frame(
- PrefetchQueue *queue, MovieClip *clip,
- size_t *r_size, int *r_current_frame)
+static unsigned char *prefetch_thread_next_frame(PrefetchQueue *queue,
+ MovieClip *clip,
+ size_t *r_size,
+ int *r_current_frame)
{
- unsigned char *mem = NULL;
-
- BLI_spin_lock(&queue->spin);
- if (!*queue->stop && !check_prefetch_break() &&
- IN_RANGE_INCL(queue->current_frame, queue->start_frame, queue->end_frame))
- {
- int current_frame;
-
- if (queue->forward) {
- current_frame = prefetch_find_uncached_frame(clip, queue->current_frame + 1, queue->end_frame,
- queue->render_size, queue->render_flag, 1);
- /* switch direction if read frames from current up to scene end frames */
- if (current_frame > queue->end_frame) {
- queue->current_frame = queue->initial_frame;
- queue->forward = false;
- }
- }
-
- if (!queue->forward) {
- current_frame = prefetch_find_uncached_frame(clip, queue->current_frame - 1, queue->start_frame,
- queue->render_size, queue->render_flag, -1);
- }
-
- if (IN_RANGE_INCL(current_frame, queue->start_frame, queue->end_frame)) {
- int frames_processed;
-
- mem = prefetch_read_file_to_memory(clip, current_frame, queue->render_size,
- queue->render_flag, r_size);
-
- *r_current_frame = current_frame;
-
- queue->current_frame = current_frame;
-
- if (queue->forward) {
- frames_processed = queue->current_frame - queue->initial_frame;
- }
- else {
- frames_processed = (queue->end_frame - queue->initial_frame) +
- (queue->initial_frame - queue->current_frame);
- }
-
- *queue->do_update = 1;
- *queue->progress = (float)frames_processed / (queue->end_frame - queue->start_frame);
- }
- }
- BLI_spin_unlock(&queue->spin);
-
- return mem;
+ unsigned char *mem = NULL;
+
+ BLI_spin_lock(&queue->spin);
+ if (!*queue->stop && !check_prefetch_break() &&
+ IN_RANGE_INCL(queue->current_frame, queue->start_frame, queue->end_frame)) {
+ int current_frame;
+
+ if (queue->forward) {
+ current_frame = prefetch_find_uncached_frame(clip,
+ queue->current_frame + 1,
+ queue->end_frame,
+ queue->render_size,
+ queue->render_flag,
+ 1);
+ /* switch direction if read frames from current up to scene end frames */
+ if (current_frame > queue->end_frame) {
+ queue->current_frame = queue->initial_frame;
+ queue->forward = false;
+ }
+ }
+
+ if (!queue->forward) {
+ current_frame = prefetch_find_uncached_frame(clip,
+ queue->current_frame - 1,
+ queue->start_frame,
+ queue->render_size,
+ queue->render_flag,
+ -1);
+ }
+
+ if (IN_RANGE_INCL(current_frame, queue->start_frame, queue->end_frame)) {
+ int frames_processed;
+
+ mem = prefetch_read_file_to_memory(
+ clip, current_frame, queue->render_size, queue->render_flag, r_size);
+
+ *r_current_frame = current_frame;
+
+ queue->current_frame = current_frame;
+
+ if (queue->forward) {
+ frames_processed = queue->current_frame - queue->initial_frame;
+ }
+ else {
+ frames_processed = (queue->end_frame - queue->initial_frame) +
+ (queue->initial_frame - queue->current_frame);
+ }
+
+ *queue->do_update = 1;
+ *queue->progress = (float)frames_processed / (queue->end_frame - queue->start_frame);
+ }
+ }
+ BLI_spin_unlock(&queue->spin);
+
+ return mem;
}
-static void prefetch_task_func(TaskPool * __restrict pool, void *task_data, int UNUSED(threadid))
+static void prefetch_task_func(TaskPool *__restrict pool, void *task_data, int UNUSED(threadid))
{
- PrefetchQueue *queue = (PrefetchQueue *)BLI_task_pool_userdata(pool);
- MovieClip *clip = (MovieClip *)task_data;
- unsigned char *mem;
- size_t size;
- int current_frame;
-
- while ((mem = prefetch_thread_next_frame(queue, clip, &size, &current_frame))) {
- ImBuf *ibuf;
- MovieClipUser user = {0};
- int flag = IB_rect | IB_multilayer | IB_alphamode_detect | IB_metadata;
- int result;
- char *colorspace_name = NULL;
- const bool use_proxy = (clip->flag & MCLIP_USE_PROXY) &&
- (queue->render_size != MCLIP_PROXY_RENDER_SIZE_FULL);
-
- user.framenr = current_frame;
- user.render_size = queue->render_size;
- user.render_flag = queue->render_flag;
-
- /* Proxies are stored in the display space. */
- if (!use_proxy) {
- colorspace_name = clip->colorspace_settings.name;
- }
-
- ibuf = IMB_ibImageFromMemory(mem, size, flag, colorspace_name, "prefetch frame");
- if (ibuf == NULL) {
- continue;
- }
- BKE_movieclip_convert_multilayer_ibuf(ibuf);
-
- result = BKE_movieclip_put_frame_if_possible(clip, &user, ibuf);
-
- IMB_freeImBuf(ibuf);
-
- MEM_freeN(mem);
-
- if (!result) {
- /* no more space in the cache, stop reading frames */
- *queue->stop = 1;
- break;
- }
- }
+ PrefetchQueue *queue = (PrefetchQueue *)BLI_task_pool_userdata(pool);
+ MovieClip *clip = (MovieClip *)task_data;
+ unsigned char *mem;
+ size_t size;
+ int current_frame;
+
+ while ((mem = prefetch_thread_next_frame(queue, clip, &size, &current_frame))) {
+ ImBuf *ibuf;
+ MovieClipUser user = {0};
+ int flag = IB_rect | IB_multilayer | IB_alphamode_detect | IB_metadata;
+ int result;
+ char *colorspace_name = NULL;
+ const bool use_proxy = (clip->flag & MCLIP_USE_PROXY) &&
+ (queue->render_size != MCLIP_PROXY_RENDER_SIZE_FULL);
+
+ user.framenr = current_frame;
+ user.render_size = queue->render_size;
+ user.render_flag = queue->render_flag;
+
+ /* Proxies are stored in the display space. */
+ if (!use_proxy) {
+ colorspace_name = clip->colorspace_settings.name;
+ }
+
+ ibuf = IMB_ibImageFromMemory(mem, size, flag, colorspace_name, "prefetch frame");
+ if (ibuf == NULL) {
+ continue;
+ }
+ BKE_movieclip_convert_multilayer_ibuf(ibuf);
+
+ result = BKE_movieclip_put_frame_if_possible(clip, &user, ibuf);
+
+ IMB_freeImBuf(ibuf);
+
+ MEM_freeN(mem);
+
+ if (!result) {
+ /* no more space in the cache, stop reading frames */
+ *queue->stop = 1;
+ break;
+ }
+ }
}
-static void start_prefetch_threads(MovieClip *clip, int start_frame, int current_frame, int end_frame,
- short render_size, short render_flag, short *stop, short *do_update,
+static void start_prefetch_threads(MovieClip *clip,
+ int start_frame,
+ int current_frame,
+ int end_frame,
+ short render_size,
+ short render_flag,
+ short *stop,
+ short *do_update,
float *progress)
{
- PrefetchQueue queue;
- TaskScheduler *task_scheduler = BLI_task_scheduler_get();
- TaskPool *task_pool;
- int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
-
- /* initialize queue */
- BLI_spin_init(&queue.spin);
-
- queue.current_frame = current_frame;
- queue.initial_frame = current_frame;
- queue.start_frame = start_frame;
- queue.end_frame = end_frame;
- queue.render_size = render_size;
- queue.render_flag = render_flag;
- queue.forward = 1;
-
- queue.stop = stop;
- queue.do_update = do_update;
- queue.progress = progress;
-
- task_pool = BLI_task_pool_create(task_scheduler, &queue);
- for (i = 0; i < tot_thread; i++) {
- BLI_task_pool_push(task_pool,
- prefetch_task_func,
- clip,
- false,
- TASK_PRIORITY_LOW);
- }
- BLI_task_pool_work_and_wait(task_pool);
- BLI_task_pool_free(task_pool);
-
- BLI_spin_end(&queue.spin);
+ PrefetchQueue queue;
+ TaskScheduler *task_scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
+
+ /* initialize queue */
+ BLI_spin_init(&queue.spin);
+
+ queue.current_frame = current_frame;
+ queue.initial_frame = current_frame;
+ queue.start_frame = start_frame;
+ queue.end_frame = end_frame;
+ queue.render_size = render_size;
+ queue.render_flag = render_flag;
+ queue.forward = 1;
+
+ queue.stop = stop;
+ queue.do_update = do_update;
+ queue.progress = progress;
+
+ task_pool = BLI_task_pool_create(task_scheduler, &queue);
+ for (i = 0; i < tot_thread; i++) {
+ BLI_task_pool_push(task_pool, prefetch_task_func, clip, false, TASK_PRIORITY_LOW);
+ }
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
+
+ BLI_spin_end(&queue.spin);
}
-static bool prefetch_movie_frame(MovieClip *clip, int frame, short render_size,
- short render_flag, short *stop)
+static bool prefetch_movie_frame(
+ MovieClip *clip, int frame, short render_size, short render_flag, short *stop)
{
- MovieClipUser user = {0};
- ImBuf *ibuf;
+ MovieClipUser user = {0};
+ ImBuf *ibuf;
- if (check_prefetch_break() || *stop)
- return false;
+ if (check_prefetch_break() || *stop)
+ return false;
- user.framenr = frame;
- user.render_size = render_size;
- user.render_flag = render_flag;
+ user.framenr = frame;
+ user.render_size = render_size;
+ user.render_flag = render_flag;
- if (!BKE_movieclip_has_cached_frame(clip, &user)) {
- ibuf = BKE_movieclip_anim_ibuf_for_frame(clip, &user);
+ if (!BKE_movieclip_has_cached_frame(clip, &user)) {
+ ibuf = BKE_movieclip_anim_ibuf_for_frame(clip, &user);
- if (ibuf) {
- int result;
+ if (ibuf) {
+ int result;
- result = BKE_movieclip_put_frame_if_possible(clip, &user, ibuf);
+ result = BKE_movieclip_put_frame_if_possible(clip, &user, ibuf);
- if (!result) {
- /* no more space in the cache, we could stop prefetching here */
- *stop = 1;
- }
+ if (!result) {
+ /* no more space in the cache, we could stop prefetching here */
+ *stop = 1;
+ }
- IMB_freeImBuf(ibuf);
- }
- else {
- /* error reading frame, fair enough stop attempting further reading */
- *stop = 1;
- }
- }
+ IMB_freeImBuf(ibuf);
+ }
+ else {
+ /* error reading frame, fair enough stop attempting further reading */
+ *stop = 1;
+ }
+ }
- return true;
+ return true;
}
-static void do_prefetch_movie(MovieClip *clip, int start_frame, int current_frame, int end_frame,
- short render_size, short render_flag, short *stop, short *do_update,
+static void do_prefetch_movie(MovieClip *clip,
+ int start_frame,
+ int current_frame,
+ int end_frame,
+ short render_size,
+ short render_flag,
+ short *stop,
+ short *do_update,
float *progress)
{
- int frame;
- int frames_processed = 0;
+ int frame;
+ int frames_processed = 0;
- /* read frames starting from current frame up to scene end frame */
- for (frame = current_frame; frame <= end_frame; frame++) {
- if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop))
- return;
+ /* read frames starting from current frame up to scene end frame */
+ for (frame = current_frame; frame <= end_frame; frame++) {
+ if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop))
+ return;
- frames_processed++;
+ frames_processed++;
- *do_update = 1;
- *progress = (float) frames_processed / (end_frame - start_frame);
- }
+ *do_update = 1;
+ *progress = (float)frames_processed / (end_frame - start_frame);
+ }
- /* read frames starting from current frame up to scene start frame */
- for (frame = current_frame; frame >= start_frame; frame--) {
- if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop))
- return;
+ /* read frames starting from current frame up to scene start frame */
+ for (frame = current_frame; frame >= start_frame; frame--) {
+ if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop))
+ return;
- frames_processed++;
+ frames_processed++;
- *do_update = 1;
- *progress = (float) frames_processed / (end_frame - start_frame);
- }
+ *do_update = 1;
+ *progress = (float)frames_processed / (end_frame - start_frame);
+ }
}
static void prefetch_startjob(void *pjv, short *stop, short *do_update, float *progress)
{
- PrefetchJob *pj = pjv;
-
- if (pj->clip->source == MCLIP_SRC_SEQUENCE) {
- /* read sequence files in multiple threads */
- start_prefetch_threads(pj->clip, pj->start_frame, pj->current_frame, pj->end_frame,
- pj->render_size, pj->render_flag,
- stop, do_update, progress);
- }
- else if (pj->clip->source == MCLIP_SRC_MOVIE) {
- /* read movie in a single thread */
- do_prefetch_movie(pj->clip, pj->start_frame, pj->current_frame, pj->end_frame,
- pj->render_size, pj->render_flag,
- stop, do_update, progress);
- }
- else {
- BLI_assert(!"Unknown movie clip source when prefetching frames");
- }
+ PrefetchJob *pj = pjv;
+
+ if (pj->clip->source == MCLIP_SRC_SEQUENCE) {
+ /* read sequence files in multiple threads */
+ start_prefetch_threads(pj->clip,
+ pj->start_frame,
+ pj->current_frame,
+ pj->end_frame,
+ pj->render_size,
+ pj->render_flag,
+ stop,
+ do_update,
+ progress);
+ }
+ else if (pj->clip->source == MCLIP_SRC_MOVIE) {
+ /* read movie in a single thread */
+ do_prefetch_movie(pj->clip,
+ pj->start_frame,
+ pj->current_frame,
+ pj->end_frame,
+ pj->render_size,
+ pj->render_flag,
+ stop,
+ do_update,
+ progress);
+ }
+ else {
+ BLI_assert(!"Unknown movie clip source when prefetching frames");
+ }
}
static void prefetch_freejob(void *pjv)
{
- PrefetchJob *pj = pjv;
+ PrefetchJob *pj = pjv;
- MEM_freeN(pj);
+ MEM_freeN(pj);
}
static int prefetch_get_start_frame(const bContext *C)
{
- Scene *scene = CTX_data_scene(C);
+ Scene *scene = CTX_data_scene(C);
- return SFRA;
+ return SFRA;
}
static int prefetch_get_final_frame(const bContext *C)
{
- Scene *scene = CTX_data_scene(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int end_frame;
+ Scene *scene = CTX_data_scene(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int end_frame;
- /* check whether all the frames from prefetch range are cached */
- end_frame = EFRA;
+ /* check whether all the frames from prefetch range are cached */
+ end_frame = EFRA;
- if (clip->len) {
- end_frame = min_ii(end_frame, SFRA + clip->len - 1);
- }
+ if (clip->len) {
+ end_frame = min_ii(end_frame, SFRA + clip->len - 1);
+ }
- return end_frame;
+ return end_frame;
}
/* returns true if early out is possible */
static bool prefetch_check_early_out(const bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int first_uncached_frame, end_frame;
- int clip_len;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int first_uncached_frame, end_frame;
+ int clip_len;
- if (clip == NULL) {
- return true;
- }
+ if (clip == NULL) {
+ return true;
+ }
- clip_len = BKE_movieclip_get_duration(clip);
+ clip_len = BKE_movieclip_get_duration(clip);
- /* check whether all the frames from prefetch range are cached */
- end_frame = prefetch_get_final_frame(C);
+ /* check whether all the frames from prefetch range are cached */
+ end_frame = prefetch_get_final_frame(C);
- first_uncached_frame =
- prefetch_find_uncached_frame(clip, sc->user.framenr, end_frame,
- sc->user.render_size, sc->user.render_flag, 1);
+ first_uncached_frame = prefetch_find_uncached_frame(
+ clip, sc->user.framenr, end_frame, sc->user.render_size, sc->user.render_flag, 1);
- if (first_uncached_frame > end_frame || first_uncached_frame == clip_len) {
- int start_frame = prefetch_get_start_frame(C);
+ if (first_uncached_frame > end_frame || first_uncached_frame == clip_len) {
+ int start_frame = prefetch_get_start_frame(C);
- first_uncached_frame =
- prefetch_find_uncached_frame(clip, sc->user.framenr, start_frame,
- sc->user.render_size, sc->user.render_flag, -1);
+ first_uncached_frame = prefetch_find_uncached_frame(
+ clip, sc->user.framenr, start_frame, sc->user.render_size, sc->user.render_flag, -1);
- if (first_uncached_frame < start_frame)
- return true;
- }
+ if (first_uncached_frame < start_frame)
+ return true;
+ }
- return false;
+ return false;
}
void clip_start_prefetch_job(const bContext *C)
{
- wmJob *wm_job;
- PrefetchJob *pj;
- SpaceClip *sc = CTX_wm_space_clip(C);
-
- if (prefetch_check_early_out(C))
- return;
-
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), CTX_wm_area(C), "Prefetching",
- WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_PREFETCH);
-
- /* create new job */
- pj = MEM_callocN(sizeof(PrefetchJob), "prefetch job");
- pj->clip = ED_space_clip_get_clip(sc);
- pj->start_frame = prefetch_get_start_frame(C);
- pj->current_frame = sc->user.framenr;
- pj->end_frame = prefetch_get_final_frame(C);
- pj->render_size = sc->user.render_size;
- pj->render_flag = sc->user.render_flag;
-
- WM_jobs_customdata_set(wm_job, pj, prefetch_freejob);
- WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
- WM_jobs_callbacks(wm_job, prefetch_startjob, NULL, NULL, NULL);
-
- G.is_break = false;
-
- /* and finally start the job */
- WM_jobs_start(CTX_wm_manager(C), wm_job);
+ wmJob *wm_job;
+ PrefetchJob *pj;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+
+ if (prefetch_check_early_out(C))
+ return;
+
+ wm_job = WM_jobs_get(CTX_wm_manager(C),
+ CTX_wm_window(C),
+ CTX_wm_area(C),
+ "Prefetching",
+ WM_JOB_PROGRESS,
+ WM_JOB_TYPE_CLIP_PREFETCH);
+
+ /* create new job */
+ pj = MEM_callocN(sizeof(PrefetchJob), "prefetch job");
+ pj->clip = ED_space_clip_get_clip(sc);
+ pj->start_frame = prefetch_get_start_frame(C);
+ pj->current_frame = sc->user.framenr;
+ pj->end_frame = prefetch_get_final_frame(C);
+ pj->render_size = sc->user.render_size;
+ pj->render_flag = sc->user.render_flag;
+
+ WM_jobs_customdata_set(wm_job, pj, prefetch_freejob);
+ WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
+ WM_jobs_callbacks(wm_job, prefetch_startjob, NULL, NULL, NULL);
+
+ G.is_break = false;
+
+ /* and finally start the job */
+ WM_jobs_start(CTX_wm_manager(C), wm_job);
}
diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c
index 63d9a45fa2e..c7602907954 100644
--- a/source/blender/editors/space_clip/clip_graph_draw.c
+++ b/source/blender/editors/space_clip/clip_graph_draw.c
@@ -45,301 +45,328 @@
#include "UI_resources.h"
#include "UI_view2d.h"
-
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
typedef struct TrackMotionCurveUserData {
- MovieTrackingTrack *act_track;
- bool sel;
- float xscale, yscale, hsize;
- unsigned int pos;
+ MovieTrackingTrack *act_track;
+ bool sel;
+ float xscale, yscale, hsize;
+ unsigned int pos;
} TrackMotionCurveUserData;
-static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *UNUSED(track),
- MovieTrackingMarker *UNUSED(marker), int UNUSED(coord),
- int scene_framenr, float val)
+static void tracking_segment_point_cb(void *userdata,
+ MovieTrackingTrack *UNUSED(track),
+ MovieTrackingMarker *UNUSED(marker),
+ int UNUSED(coord),
+ int scene_framenr,
+ float val)
{
- TrackMotionCurveUserData *data = (TrackMotionCurveUserData *) userdata;
+ TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata;
- immVertex2f(data->pos, scene_framenr, val);
+ immVertex2f(data->pos, scene_framenr, val);
}
-static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord, bool is_point)
+static void tracking_segment_start_cb(void *userdata,
+ MovieTrackingTrack *track,
+ int coord,
+ bool is_point)
{
- TrackMotionCurveUserData *data = (TrackMotionCurveUserData *) userdata;
- float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
- col[coord] = 1.0f;
-
- if (track == data->act_track) {
- col[3] = 1.0f;
- GPU_line_width(2.0f);
- }
- else {
- col[3] = 0.5f;
- GPU_line_width(1.0f);
- }
-
- immUniformColor4fv(col);
-
- if (is_point) {
- immBeginAtMost(GPU_PRIM_POINTS, 1);
- }
- else {
- /* Graph can be composed of smaller segments, if any marker is disabled */
- immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr);
- }
+ TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata;
+ float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ col[coord] = 1.0f;
+
+ if (track == data->act_track) {
+ col[3] = 1.0f;
+ GPU_line_width(2.0f);
+ }
+ else {
+ col[3] = 0.5f;
+ GPU_line_width(1.0f);
+ }
+
+ immUniformColor4fv(col);
+
+ if (is_point) {
+ immBeginAtMost(GPU_PRIM_POINTS, 1);
+ }
+ else {
+ /* Graph can be composed of smaller segments, if any marker is disabled */
+ immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr);
+ }
}
static void tracking_segment_end_cb(void *UNUSED(userdata), int UNUSED(coord))
{
- immEnd();
+ immEnd();
}
-static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, int coord, int scene_framenr, float val)
+static void tracking_segment_knot_cb(void *userdata,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val)
{
- TrackMotionCurveUserData *data = (TrackMotionCurveUserData *) userdata;
- int sel = 0, sel_flag;
+ TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata;
+ int sel = 0, sel_flag;
- if (track != data->act_track)
- return;
+ if (track != data->act_track)
+ return;
- sel_flag = coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
- sel = (marker->flag & sel_flag) ? 1 : 0;
+ sel_flag = coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
+ sel = (marker->flag & sel_flag) ? 1 : 0;
- if (sel == data->sel) {
- immUniformThemeColor(sel ? TH_HANDLE_VERTEX_SELECT : TH_HANDLE_VERTEX);
+ if (sel == data->sel) {
+ immUniformThemeColor(sel ? TH_HANDLE_VERTEX_SELECT : TH_HANDLE_VERTEX);
- GPU_matrix_push();
- GPU_matrix_translate_2f(scene_framenr, val);
- GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(scene_framenr, val);
+ GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
- imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
+ imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
- GPU_matrix_pop();
- }
+ GPU_matrix_pop();
+ }
}
static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int pos)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- int width, height;
- TrackMotionCurveUserData userdata;
-
- BKE_movieclip_get_size(clip, &sc->user, &width, &height);
-
- if (!width || !height)
- return;
-
- /* non-selected knot handles */
- userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
- userdata.sel = false;
- userdata.act_track = act_track;
- userdata.pos = pos;
- UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &userdata, tracking_segment_knot_cb, NULL, NULL);
- /* draw graph lines */
- GPU_blend(true);
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &userdata, tracking_segment_point_cb, tracking_segment_start_cb,
- tracking_segment_end_cb);
- GPU_blend(false);
-
- /* selected knot handles on top of curves */
- userdata.sel = true;
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &userdata, tracking_segment_knot_cb, NULL, NULL);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ int width, height;
+ TrackMotionCurveUserData userdata;
+
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+ if (!width || !height)
+ return;
+
+ /* non-selected knot handles */
+ userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
+ userdata.sel = false;
+ userdata.act_track = act_track;
+ userdata.pos = pos;
+ UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &userdata,
+ tracking_segment_knot_cb,
+ NULL,
+ NULL);
+ /* draw graph lines */
+ GPU_blend(true);
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &userdata,
+ tracking_segment_point_cb,
+ tracking_segment_start_cb,
+ tracking_segment_end_cb);
+ GPU_blend(false);
+
+ /* selected knot handles on top of curves */
+ userdata.sel = true;
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &userdata,
+ tracking_segment_knot_cb,
+ NULL,
+ NULL);
}
typedef struct TrackErrorCurveUserData {
- MovieClip *clip;
- MovieTracking *tracking;
- MovieTrackingObject *tracking_object;
- MovieTrackingTrack *active_track;
- bool matrix_initialized;
- int matrix_frame;
- float projection_matrix[4][4];
- int width, height;
- float aspy;
- unsigned int pos;
+ MovieClip *clip;
+ MovieTracking *tracking;
+ MovieTrackingObject *tracking_object;
+ MovieTrackingTrack *active_track;
+ bool matrix_initialized;
+ int matrix_frame;
+ float projection_matrix[4][4];
+ int width, height;
+ float aspy;
+ unsigned int pos;
} TrackErrorCurveUserData;
static void tracking_error_segment_point_cb(void *userdata,
- MovieTrackingTrack *track, MovieTrackingMarker *marker,
- int coord, int scene_framenr, float UNUSED(value))
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float UNUSED(value))
{
- if (coord == 1) {
- TrackErrorCurveUserData *data = (TrackErrorCurveUserData *) userdata;
- float reprojected_position[4], bundle_position[4], marker_position[2], delta[2];
- float reprojection_error;
- float weight = BKE_tracking_track_get_weight_for_marker(data->clip, track, marker);
-
- if (!data->matrix_initialized || data->matrix_frame != scene_framenr) {
- BKE_tracking_get_projection_matrix(data->tracking, data->tracking_object,
- scene_framenr, data->width, data->height,
- data->projection_matrix);
- }
-
- copy_v3_v3(bundle_position, track->bundle_pos);
- bundle_position[3] = 1;
-
- mul_v4_m4v4(reprojected_position, data->projection_matrix, bundle_position);
- reprojected_position[0] = (reprojected_position[0] /
- (reprojected_position[3] * 2.0f) + 0.5f) * data->width;
- reprojected_position[1] = (reprojected_position[1] /
- (reprojected_position[3] * 2.0f) + 0.5f) * data->height * data->aspy;
-
- BKE_tracking_distort_v2(data->tracking, reprojected_position, reprojected_position);
-
- marker_position[0] = (marker->pos[0] + track->offset[0]) * data->width;
- marker_position[1] = (marker->pos[1] + track->offset[1]) * data->height * data->aspy;
-
- sub_v2_v2v2(delta, reprojected_position, marker_position);
- reprojection_error = len_v2(delta) * weight;
-
- immVertex2f(data->pos, scene_framenr, reprojection_error);
- }
+ if (coord == 1) {
+ TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata;
+ float reprojected_position[4], bundle_position[4], marker_position[2], delta[2];
+ float reprojection_error;
+ float weight = BKE_tracking_track_get_weight_for_marker(data->clip, track, marker);
+
+ if (!data->matrix_initialized || data->matrix_frame != scene_framenr) {
+ BKE_tracking_get_projection_matrix(data->tracking,
+ data->tracking_object,
+ scene_framenr,
+ data->width,
+ data->height,
+ data->projection_matrix);
+ }
+
+ copy_v3_v3(bundle_position, track->bundle_pos);
+ bundle_position[3] = 1;
+
+ mul_v4_m4v4(reprojected_position, data->projection_matrix, bundle_position);
+ reprojected_position[0] = (reprojected_position[0] / (reprojected_position[3] * 2.0f) + 0.5f) *
+ data->width;
+ reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) *
+ data->height * data->aspy;
+
+ BKE_tracking_distort_v2(data->tracking, reprojected_position, reprojected_position);
+
+ marker_position[0] = (marker->pos[0] + track->offset[0]) * data->width;
+ marker_position[1] = (marker->pos[1] + track->offset[1]) * data->height * data->aspy;
+
+ sub_v2_v2v2(delta, reprojected_position, marker_position);
+ reprojection_error = len_v2(delta) * weight;
+
+ immVertex2f(data->pos, scene_framenr, reprojection_error);
+ }
}
-static void tracking_error_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord, bool is_point)
+static void tracking_error_segment_start_cb(void *userdata,
+ MovieTrackingTrack *track,
+ int coord,
+ bool is_point)
{
- if (coord == 1) {
- TrackErrorCurveUserData *data = (TrackErrorCurveUserData *) userdata;
- float col[4] = {0.0f, 0.0f, 1.0f, 1.0f};
-
- if (track == data->active_track) {
- col[3] = 1.0f;
- GPU_line_width(2.0f);
- }
- else {
- col[3] = 0.5f;
- GPU_line_width(1.0f);
- }
-
- immUniformColor4fv(col);
-
- if (is_point) { /* This probably never happens here, but just in case... */
- immBeginAtMost(GPU_PRIM_POINTS, 1);
- }
- else {
- /* Graph can be composed of smaller segments, if any marker is disabled */
- immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr);
- }
- }
+ if (coord == 1) {
+ TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata;
+ float col[4] = {0.0f, 0.0f, 1.0f, 1.0f};
+
+ if (track == data->active_track) {
+ col[3] = 1.0f;
+ GPU_line_width(2.0f);
+ }
+ else {
+ col[3] = 0.5f;
+ GPU_line_width(1.0f);
+ }
+
+ immUniformColor4fv(col);
+
+ if (is_point) { /* This probably never happens here, but just in case... */
+ immBeginAtMost(GPU_PRIM_POINTS, 1);
+ }
+ else {
+ /* Graph can be composed of smaller segments, if any marker is disabled */
+ immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr);
+ }
+ }
}
static void tracking_error_segment_end_cb(void *UNUSED(userdata), int coord)
{
- if (coord == 1) {
- immEnd();
- }
+ if (coord == 1) {
+ immEnd();
+ }
}
static void draw_tracks_error_curves(SpaceClip *sc, unsigned int pos)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- TrackErrorCurveUserData data;
-
- data.clip = clip;
- data.tracking = tracking;
- data.tracking_object = BKE_tracking_object_get_active(tracking);
- data.active_track = BKE_tracking_track_get_active(tracking);
- data.matrix_initialized = false;
- data.pos = pos;
- BKE_movieclip_get_size(clip, &sc->user, &data.width, &data.height);
- data.aspy = 1.0f / tracking->camera.pixel_aspect;
-
- if (!data.width || !data.height) {
- return;
- }
-
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &data,
- tracking_error_segment_point_cb,
- tracking_error_segment_start_cb,
- tracking_error_segment_end_cb);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ TrackErrorCurveUserData data;
+
+ data.clip = clip;
+ data.tracking = tracking;
+ data.tracking_object = BKE_tracking_object_get_active(tracking);
+ data.active_track = BKE_tracking_track_get_active(tracking);
+ data.matrix_initialized = false;
+ data.pos = pos;
+ BKE_movieclip_get_size(clip, &sc->user, &data.width, &data.height);
+ data.aspy = 1.0f / tracking->camera.pixel_aspect;
+
+ if (!data.width || !data.height) {
+ return;
+ }
+
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &data,
+ tracking_error_segment_point_cb,
+ tracking_error_segment_start_cb,
+ tracking_error_segment_end_cb);
}
static void draw_frame_curves(SpaceClip *sc, unsigned int pos)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
- int i, lines = 0, prevfra = 0;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
+ int i, lines = 0, prevfra = 0;
- immUniformColor3f(0.0f, 0.0f, 1.0f);
+ immUniformColor3f(0.0f, 0.0f, 1.0f);
- for (i = 0; i < reconstruction->camnr; i++) {
- MovieReconstructedCamera *camera = &reconstruction->cameras[i];
- int framenr;
+ for (i = 0; i < reconstruction->camnr; i++) {
+ MovieReconstructedCamera *camera = &reconstruction->cameras[i];
+ int framenr;
- if (lines && camera->framenr != prevfra + 1) {
- immEnd();
- lines = 0;
- }
+ if (lines && camera->framenr != prevfra + 1) {
+ immEnd();
+ lines = 0;
+ }
- if (!lines) {
- immBeginAtMost(GPU_PRIM_LINE_STRIP, reconstruction->camnr);
- lines = 1;
- }
+ if (!lines) {
+ immBeginAtMost(GPU_PRIM_LINE_STRIP, reconstruction->camnr);
+ lines = 1;
+ }
- framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
- immVertex2f(pos, framenr, camera->error);
+ framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
+ immVertex2f(pos, framenr, camera->error);
- prevfra = camera->framenr;
- }
+ prevfra = camera->framenr;
+ }
- if (lines) {
- immEnd();
- }
+ if (lines) {
+ immEnd();
+ }
}
void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- View2D *v2d = &ar->v2d;
- View2DGrid *grid;
- short unitx = V2D_UNIT_FRAMESCALE, unity = V2D_UNIT_VALUES;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ View2D *v2d = &ar->v2d;
+ View2DGrid *grid;
+ short unitx = V2D_UNIT_FRAMESCALE, unity = V2D_UNIT_VALUES;
- /* grid */
- grid = UI_view2d_grid_calc(scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
- UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
- UI_view2d_grid_free(grid);
+ /* grid */
+ grid = UI_view2d_grid_calc(
+ scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
+ UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
+ UI_view2d_grid_free(grid);
- if (clip) {
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ if (clip) {
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- GPU_point_size(3.0f);
+ GPU_point_size(3.0f);
- if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) {
- draw_tracks_motion_curves(v2d, sc, pos);
- }
+ if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) {
+ draw_tracks_motion_curves(v2d, sc, pos);
+ }
- if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) {
- draw_tracks_error_curves(sc, pos);
- }
+ if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) {
+ draw_tracks_error_curves(sc, pos);
+ }
- if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
- draw_frame_curves(sc, pos);
- }
+ if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
+ draw_frame_curves(sc, pos);
+ }
- immUnbindProgram();
- }
+ immUnbindProgram();
+ }
- /* frame range */
- clip_draw_sfra_efra(v2d, scene);
+ /* frame range */
+ clip_draw_sfra_efra(v2d, scene);
}
diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c
index 8a8cb4b8dcb..7a61aced8b5 100644
--- a/source/blender/editors/space_clip/clip_graph_ops.c
+++ b/source/blender/editors/space_clip/clip_graph_ops.c
@@ -44,676 +44,706 @@
#include "UI_view2d.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
/******************** common graph-editing utilities ********************/
static bool ED_space_clip_graph_poll(bContext *C)
{
- if (ED_space_clip_tracking_poll(C)) {
- SpaceClip *sc = CTX_wm_space_clip(C);
+ if (ED_space_clip_tracking_poll(C)) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
- return sc->view == SC_VIEW_GRAPH;
- }
+ return sc->view == SC_VIEW_GRAPH;
+ }
- return false;
+ return false;
}
static bool clip_graph_knots_poll(bContext *C)
{
- if (ED_space_clip_graph_poll(C)) {
- SpaceClip *sc = CTX_wm_space_clip(C);
+ if (ED_space_clip_graph_poll(C)) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
- return (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
- }
- return false;
+ return (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
+ }
+ return false;
}
typedef struct {
- int action;
+ int action;
} SelectUserData;
static void toggle_selection_cb(void *userdata, MovieTrackingMarker *marker)
{
- SelectUserData *data = (SelectUserData *)userdata;
-
- switch (data->action) {
- case SEL_SELECT:
- marker->flag |= MARKER_GRAPH_SEL;
- break;
- case SEL_DESELECT:
- marker->flag &= ~MARKER_GRAPH_SEL;
- break;
- case SEL_INVERT:
- marker->flag ^= MARKER_GRAPH_SEL;
- break;
- }
+ SelectUserData *data = (SelectUserData *)userdata;
+
+ switch (data->action) {
+ case SEL_SELECT:
+ marker->flag |= MARKER_GRAPH_SEL;
+ break;
+ case SEL_DESELECT:
+ marker->flag &= ~MARKER_GRAPH_SEL;
+ break;
+ case SEL_INVERT:
+ marker->flag ^= MARKER_GRAPH_SEL;
+ break;
+ }
}
/******************** mouse select operator ********************/
typedef struct {
- int coord; /* coordinate index of found entuty (0 = X-axis, 1 = Y-axis) */
- bool has_prev; /* if there's valid coordinate of previous point of curve segment */
+ int coord; /* coordinate index of found entuty (0 = X-axis, 1 = Y-axis) */
+ bool has_prev; /* if there's valid coordinate of previous point of curve segment */
- float min_dist_sq, /* minimal distance between mouse and currently found entity */
- mouse_co[2], /* mouse coordinate */
- prev_co[2], /* coordinate of previeous point of segment */
- min_co[2]; /* coordinate of entity with minimal distance */
+ float min_dist_sq, /* minimal distance between mouse and currently found entity */
+ mouse_co[2], /* mouse coordinate */
+ prev_co[2], /* coordinate of previeous point of segment */
+ min_co[2]; /* coordinate of entity with minimal distance */
- MovieTrackingTrack *track; /* nearest found track */
- MovieTrackingMarker *marker; /* nearest found marker */
+ MovieTrackingTrack *track; /* nearest found track */
+ MovieTrackingMarker *marker; /* nearest found marker */
} MouseSelectUserData;
-static void find_nearest_tracking_segment_cb(void *userdata, MovieTrackingTrack *track,
+static void find_nearest_tracking_segment_cb(void *userdata,
+ MovieTrackingTrack *track,
MovieTrackingMarker *UNUSED(marker),
- int coord, int scene_framenr, float val)
+ int coord,
+ int scene_framenr,
+ float val)
{
- MouseSelectUserData *data = userdata;
- float co[2] = {scene_framenr, val};
-
- if (data->has_prev) {
- float dist_sq = dist_squared_to_line_segment_v2(data->mouse_co, data->prev_co, co);
-
- if (data->track == NULL || dist_sq < data->min_dist_sq) {
- data->track = track;
- data->min_dist_sq = dist_sq;
- data->coord = coord;
- copy_v2_v2(data->min_co, co);
- }
- }
-
- data->has_prev = true;
- copy_v2_v2(data->prev_co, co);
+ MouseSelectUserData *data = userdata;
+ float co[2] = {scene_framenr, val};
+
+ if (data->has_prev) {
+ float dist_sq = dist_squared_to_line_segment_v2(data->mouse_co, data->prev_co, co);
+
+ if (data->track == NULL || dist_sq < data->min_dist_sq) {
+ data->track = track;
+ data->min_dist_sq = dist_sq;
+ data->coord = coord;
+ copy_v2_v2(data->min_co, co);
+ }
+ }
+
+ data->has_prev = true;
+ copy_v2_v2(data->prev_co, co);
}
static void find_nearest_tracking_segment_end_cb(void *userdata, int UNUSED(coord))
{
- MouseSelectUserData *data = userdata;
+ MouseSelectUserData *data = userdata;
- data->has_prev = false;
+ data->has_prev = false;
}
-static void find_nearest_tracking_knot_cb(void *userdata, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, int coord, int scene_framenr, float val)
+static void find_nearest_tracking_knot_cb(void *userdata,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val)
{
- MouseSelectUserData *data = userdata;
- float mdiff[2] = {scene_framenr - data->mouse_co[0], val - data->mouse_co[1]};
- float dist_sq = len_squared_v2(mdiff);
-
- if (data->marker == NULL || dist_sq < data->min_dist_sq) {
- float co[2] = {scene_framenr, val};
-
- data->track = track;
- data->marker = marker;
- data->min_dist_sq = dist_sq;
- data->coord = coord;
- copy_v2_v2(data->min_co, co);
- }
-
+ MouseSelectUserData *data = userdata;
+ float mdiff[2] = {scene_framenr - data->mouse_co[0], val - data->mouse_co[1]};
+ float dist_sq = len_squared_v2(mdiff);
+
+ if (data->marker == NULL || dist_sq < data->min_dist_sq) {
+ float co[2] = {scene_framenr, val};
+
+ data->track = track;
+ data->marker = marker;
+ data->min_dist_sq = dist_sq;
+ data->coord = coord;
+ copy_v2_v2(data->min_co, co);
+ }
}
static void mouse_select_init_data(MouseSelectUserData *userdata, const float co[2])
{
- memset(userdata, 0, sizeof(MouseSelectUserData));
- userdata->min_dist_sq = FLT_MAX;
- copy_v2_v2(userdata->mouse_co, co);
+ memset(userdata, 0, sizeof(MouseSelectUserData));
+ userdata->min_dist_sq = FLT_MAX;
+ copy_v2_v2(userdata->mouse_co, co);
}
static bool mouse_select_knot(bContext *C, float co[2], bool extend)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- ARegion *ar = CTX_wm_region(C);
- View2D *v2d = &ar->v2d;
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- static const int delta = 6;
-
- if (act_track) {
- MouseSelectUserData userdata;
-
- mouse_select_init_data(&userdata, co);
- clip_graph_tracking_values_iterate_track(sc, act_track, &userdata,
- find_nearest_tracking_knot_cb, NULL, NULL);
-
- if (userdata.marker) {
- int x1, y1, x2, y2;
-
- if (UI_view2d_view_to_region_clip(v2d, co[0], co[1], &x1, &y1) &&
- UI_view2d_view_to_region_clip(v2d, userdata.min_co[0], userdata.min_co[1], &x2, &y2) &&
- (abs(x2 - x1) <= delta && abs(y2 - y1) <= delta))
- {
- if (!extend) {
- SelectUserData selectdata = {SEL_DESELECT};
-
- clip_graph_tracking_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &selectdata,
- toggle_selection_cb);
- }
-
- if (userdata.coord == 0) {
- if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0)
- userdata.marker->flag &= ~MARKER_GRAPH_SEL_X;
- else
- userdata.marker->flag |= MARKER_GRAPH_SEL_X;
- }
- else {
- if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0)
- userdata.marker->flag &= ~MARKER_GRAPH_SEL_Y;
- else
- userdata.marker->flag |= MARKER_GRAPH_SEL_Y;
- }
-
- return true;
- }
- }
- }
-
- return false;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ ARegion *ar = CTX_wm_region(C);
+ View2D *v2d = &ar->v2d;
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ static const int delta = 6;
+
+ if (act_track) {
+ MouseSelectUserData userdata;
+
+ mouse_select_init_data(&userdata, co);
+ clip_graph_tracking_values_iterate_track(
+ sc, act_track, &userdata, find_nearest_tracking_knot_cb, NULL, NULL);
+
+ if (userdata.marker) {
+ int x1, y1, x2, y2;
+
+ if (UI_view2d_view_to_region_clip(v2d, co[0], co[1], &x1, &y1) &&
+ UI_view2d_view_to_region_clip(v2d, userdata.min_co[0], userdata.min_co[1], &x2, &y2) &&
+ (abs(x2 - x1) <= delta && abs(y2 - y1) <= delta)) {
+ if (!extend) {
+ SelectUserData selectdata = {SEL_DESELECT};
+
+ clip_graph_tracking_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &selectdata,
+ toggle_selection_cb);
+ }
+
+ if (userdata.coord == 0) {
+ if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0)
+ userdata.marker->flag &= ~MARKER_GRAPH_SEL_X;
+ else
+ userdata.marker->flag |= MARKER_GRAPH_SEL_X;
+ }
+ else {
+ if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0)
+ userdata.marker->flag &= ~MARKER_GRAPH_SEL_Y;
+ else
+ userdata.marker->flag |= MARKER_GRAPH_SEL_Y;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ return false;
}
static bool mouse_select_curve(bContext *C, float co[2], bool extend)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- MouseSelectUserData userdata;
-
- mouse_select_init_data(&userdata, co);
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &userdata, find_nearest_tracking_segment_cb,
- NULL, find_nearest_tracking_segment_end_cb);
-
- if (userdata.track) {
- if (extend) {
- if (act_track == userdata.track) {
- /* currently only single curve can be selected
- * (selected curve represents active track) */
- act_track = NULL;
- }
- }
- else if (act_track != userdata.track) {
- SelectUserData selectdata = {SEL_DESELECT};
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
-
- tracking->act_track = userdata.track;
- if ((sc->flag & SC_SHOW_GRAPH_SEL_ONLY) == 0) {
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
- BKE_tracking_track_select(tracksbase, userdata.track, TRACK_AREA_ALL, false);
- }
-
- /* deselect all knots on newly selected curve */
- clip_graph_tracking_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &selectdata, toggle_selection_cb);
- }
-
- return true;
- }
-
- return false;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ MouseSelectUserData userdata;
+
+ mouse_select_init_data(&userdata, co);
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &userdata,
+ find_nearest_tracking_segment_cb,
+ NULL,
+ find_nearest_tracking_segment_end_cb);
+
+ if (userdata.track) {
+ if (extend) {
+ if (act_track == userdata.track) {
+ /* currently only single curve can be selected
+ * (selected curve represents active track) */
+ act_track = NULL;
+ }
+ }
+ else if (act_track != userdata.track) {
+ SelectUserData selectdata = {SEL_DESELECT};
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+
+ tracking->act_track = userdata.track;
+ if ((sc->flag & SC_SHOW_GRAPH_SEL_ONLY) == 0) {
+ ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
+ BKE_tracking_track_select(tracksbase, userdata.track, TRACK_AREA_ALL, false);
+ }
+
+ /* deselect all knots on newly selected curve */
+ clip_graph_tracking_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &selectdata,
+ toggle_selection_cb);
+ }
+
+ return true;
+ }
+
+ return false;
}
static int mouse_select(bContext *C, float co[2], bool extend)
{
- bool sel = false;
+ bool sel = false;
- /* first try to select knot on selected curves */
- sel = mouse_select_knot(C, co, extend);
+ /* first try to select knot on selected curves */
+ sel = mouse_select_knot(C, co, extend);
- if (!sel) {
- /* if there's no close enough knot to mouse osition, select nearest curve */
- sel = mouse_select_curve(C, co, extend);
- }
+ if (!sel) {
+ /* if there's no close enough knot to mouse osition, select nearest curve */
+ sel = mouse_select_curve(C, co, extend);
+ }
- if (sel)
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ if (sel)
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int select_exec(bContext *C, wmOperator *op)
{
- float co[2];
- bool extend = RNA_boolean_get(op->ptr, "extend");
+ float co[2];
+ bool extend = RNA_boolean_get(op->ptr, "extend");
- RNA_float_get_array(op->ptr, "location", co);
+ RNA_float_get_array(op->ptr, "location", co);
- return mouse_select(C, co, extend);
+ return mouse_select(C, co, extend);
}
static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- float co[2];
+ ARegion *ar = CTX_wm_region(C);
+ float co[2];
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
- RNA_float_set_array(op->ptr, "location", co);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+ RNA_float_set_array(op->ptr, "location", co);
- return select_exec(C, op);
+ return select_exec(C, op);
}
void CLIP_OT_graph_select(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select";
- ot->description = "Select graph curves";
- ot->idname = "CLIP_OT_graph_select";
-
- /* api callbacks */
- ot->exec = select_exec;
- ot->invoke = select_invoke;
- ot->poll = clip_graph_knots_poll;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Mouse location to select nearest entity", -100.0f, 100.0f);
- RNA_def_boolean(ot->srna, "extend", 0,
- "Extend", "Extend selection rather than clearing the existing selection");
+ /* identifiers */
+ ot->name = "Select";
+ ot->description = "Select graph curves";
+ ot->idname = "CLIP_OT_graph_select";
+
+ /* api callbacks */
+ ot->exec = select_exec;
+ ot->invoke = select_invoke;
+ ot->poll = clip_graph_knots_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Mouse location to select nearest entity",
+ -100.0f,
+ 100.0f);
+ RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
}
/********************** box select operator *********************/
typedef struct BoxSelectuserData {
- rctf rect;
- bool select, extend, changed;
+ rctf rect;
+ bool select, extend, changed;
} BoxSelectuserData;
-static void box_select_cb(void *userdata, MovieTrackingTrack *UNUSED(track),
- MovieTrackingMarker *marker, int coord, int scene_framenr, float val)
+static void box_select_cb(void *userdata,
+ MovieTrackingTrack *UNUSED(track),
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val)
{
- BoxSelectuserData *data = (BoxSelectuserData *) userdata;
-
- if (BLI_rctf_isect_pt(&data->rect, scene_framenr, val)) {
- int flag = 0;
-
- if (coord == 0)
- flag = MARKER_GRAPH_SEL_X;
- else
- flag = MARKER_GRAPH_SEL_Y;
-
- if (data->select) {
- marker->flag |= flag;
- }
- else {
- marker->flag &= ~flag;
- }
- data->changed = true;
- }
- else if (!data->extend) {
- marker->flag &= ~MARKER_GRAPH_SEL;
- }
+ BoxSelectuserData *data = (BoxSelectuserData *)userdata;
+
+ if (BLI_rctf_isect_pt(&data->rect, scene_framenr, val)) {
+ int flag = 0;
+
+ if (coord == 0)
+ flag = MARKER_GRAPH_SEL_X;
+ else
+ flag = MARKER_GRAPH_SEL_Y;
+
+ if (data->select) {
+ marker->flag |= flag;
+ }
+ else {
+ marker->flag &= ~flag;
+ }
+ data->changed = true;
+ }
+ else if (!data->extend) {
+ marker->flag &= ~MARKER_GRAPH_SEL;
+ }
}
static int box_select_graph_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- BoxSelectuserData userdata;
- rctf rect;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ BoxSelectuserData userdata;
+ rctf rect;
- if (act_track == NULL) {
- return OPERATOR_CANCELLED;
- }
+ if (act_track == NULL) {
+ return OPERATOR_CANCELLED;
+ }
- /* get rectangle from operator */
- WM_operator_properties_border_to_rctf(op, &rect);
- UI_view2d_region_to_view_rctf(&ar->v2d, &rect, &userdata.rect);
+ /* get rectangle from operator */
+ WM_operator_properties_border_to_rctf(op, &rect);
+ UI_view2d_region_to_view_rctf(&ar->v2d, &rect, &userdata.rect);
- userdata.changed = false;
- userdata.select = !RNA_boolean_get(op->ptr, "deselect");
- userdata.extend = RNA_boolean_get(op->ptr, "extend");
+ userdata.changed = false;
+ userdata.select = !RNA_boolean_get(op->ptr, "deselect");
+ userdata.extend = RNA_boolean_get(op->ptr, "extend");
- clip_graph_tracking_values_iterate_track(sc, act_track, &userdata, box_select_cb, NULL, NULL);
+ clip_graph_tracking_values_iterate_track(sc, act_track, &userdata, box_select_cb, NULL, NULL);
- if (userdata.changed) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ if (userdata.changed) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
+ }
- return OPERATOR_CANCELLED;
+ return OPERATOR_CANCELLED;
}
void CLIP_OT_graph_select_box(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Box Select";
- ot->description = "Select curve points using box selection";
- ot->idname = "CLIP_OT_graph_select_box";
-
- /* api callbacks */
- ot->invoke = WM_gesture_box_invoke;
- ot->exec = box_select_graph_exec;
- ot->modal = WM_gesture_box_modal;
- ot->poll = clip_graph_knots_poll;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_gesture_box_select(ot);
+ /* identifiers */
+ ot->name = "Box Select";
+ ot->description = "Select curve points using box selection";
+ ot->idname = "CLIP_OT_graph_select_box";
+
+ /* api callbacks */
+ ot->invoke = WM_gesture_box_invoke;
+ ot->exec = box_select_graph_exec;
+ ot->modal = WM_gesture_box_modal;
+ ot->poll = clip_graph_knots_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_gesture_box_select(ot);
}
/********************** select all operator *********************/
static int graph_select_all_markers_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- MovieTrackingMarker *marker;
- int action = RNA_enum_get(op->ptr, "action");
- int a;
-
- if (!act_track)
- return OPERATOR_CANCELLED;
-
- if (action == SEL_TOGGLE) {
- action = SEL_SELECT;
-
- for (a = 0; a < act_track->markersnr; a++) {
- marker = &act_track->markers[a];
-
- if (marker->flag & MARKER_GRAPH_SEL) {
- action = SEL_DESELECT;
- break;
- }
- }
- }
-
- for (a = 0; a < act_track->markersnr; a++) {
- marker = &act_track->markers[a];
-
- switch (action) {
- case SEL_SELECT:
- marker->flag |= MARKER_GRAPH_SEL;
- break;
- case SEL_DESELECT:
- marker->flag &= ~MARKER_GRAPH_SEL;
- break;
- case SEL_INVERT:
- marker->flag ^= MARKER_GRAPH_SEL;
- break;
- }
- }
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ MovieTrackingMarker *marker;
+ int action = RNA_enum_get(op->ptr, "action");
+ int a;
+
+ if (!act_track)
+ return OPERATOR_CANCELLED;
+
+ if (action == SEL_TOGGLE) {
+ action = SEL_SELECT;
+
+ for (a = 0; a < act_track->markersnr; a++) {
+ marker = &act_track->markers[a];
+
+ if (marker->flag & MARKER_GRAPH_SEL) {
+ action = SEL_DESELECT;
+ break;
+ }
+ }
+ }
+
+ for (a = 0; a < act_track->markersnr; a++) {
+ marker = &act_track->markers[a];
+
+ switch (action) {
+ case SEL_SELECT:
+ marker->flag |= MARKER_GRAPH_SEL;
+ break;
+ case SEL_DESELECT:
+ marker->flag &= ~MARKER_GRAPH_SEL;
+ break;
+ case SEL_INVERT:
+ marker->flag ^= MARKER_GRAPH_SEL;
+ break;
+ }
+ }
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_select_all_markers(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "(De)select All Markers";
- ot->description = "Change selection of all markers of active track";
- ot->idname = "CLIP_OT_graph_select_all_markers";
+ /* identifiers */
+ ot->name = "(De)select All Markers";
+ ot->description = "Change selection of all markers of active track";
+ ot->idname = "CLIP_OT_graph_select_all_markers";
- /* api callbacks */
- ot->exec = graph_select_all_markers_exec;
- ot->poll = clip_graph_knots_poll;
+ /* api callbacks */
+ ot->exec = graph_select_all_markers_exec;
+ ot->poll = clip_graph_knots_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- WM_operator_properties_select_all(ot);
+ WM_operator_properties_select_all(ot);
}
/******************** delete curve operator ********************/
static int delete_curve_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- if (!act_track)
- return OPERATOR_CANCELLED;
+ if (!act_track)
+ return OPERATOR_CANCELLED;
- clip_delete_track(C, clip, act_track);
+ clip_delete_track(C, clip, act_track);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_delete_curve(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete Curve";
- ot->description = "Delete track corresponding to the selected curve";
- ot->idname = "CLIP_OT_graph_delete_curve";
-
- /* api callbacks */
- ot->invoke = WM_operator_confirm;
- ot->exec = delete_curve_exec;
- ot->poll = clip_graph_knots_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* identifiers */
+ ot->name = "Delete Curve";
+ ot->description = "Delete track corresponding to the selected curve";
+ ot->idname = "CLIP_OT_graph_delete_curve";
+
+ /* api callbacks */
+ ot->invoke = WM_operator_confirm;
+ ot->exec = delete_curve_exec;
+ ot->poll = clip_graph_knots_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** delete knot operator ********************/
static int delete_knot_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- if (act_track) {
- int a = 0;
+ if (act_track) {
+ int a = 0;
- while (a < act_track->markersnr) {
- MovieTrackingMarker *marker = &act_track->markers[a];
+ while (a < act_track->markersnr) {
+ MovieTrackingMarker *marker = &act_track->markers[a];
- if (marker->flag & MARKER_GRAPH_SEL)
- clip_delete_marker(C, clip, act_track, marker);
- else
- a++;
- }
- }
+ if (marker->flag & MARKER_GRAPH_SEL)
+ clip_delete_marker(C, clip, act_track, marker);
+ else
+ a++;
+ }
+ }
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_delete_knot(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete Knot";
- ot->description = "Delete curve knots";
- ot->idname = "CLIP_OT_graph_delete_knot";
+ /* identifiers */
+ ot->name = "Delete Knot";
+ ot->description = "Delete curve knots";
+ ot->idname = "CLIP_OT_graph_delete_knot";
- /* api callbacks */
- ot->exec = delete_knot_exec;
- ot->poll = clip_graph_knots_poll;
+ /* api callbacks */
+ ot->exec = delete_knot_exec;
+ ot->poll = clip_graph_knots_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** view all operator ********************/
typedef struct {
- float min, max;
+ float min, max;
} ViewAllUserData;
-static void view_all_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker),
- int UNUSED(coord), int UNUSED(scene_framenr), float val)
+static void view_all_cb(void *userdata,
+ MovieTrackingTrack *UNUSED(track),
+ MovieTrackingMarker *UNUSED(marker),
+ int UNUSED(coord),
+ int UNUSED(scene_framenr),
+ float val)
{
- ViewAllUserData *data = (ViewAllUserData *) userdata;
+ ViewAllUserData *data = (ViewAllUserData *)userdata;
- if (val < data->min)
- data->min = val;
+ if (val < data->min)
+ data->min = val;
- if (val > data->max)
- data->max = val;
+ if (val > data->max)
+ data->max = val;
}
static int view_all_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- View2D *v2d = &ar->v2d;
- ViewAllUserData userdata;
- float extra;
-
- userdata.max = -FLT_MAX;
- userdata.min = FLT_MAX;
-
- clip_graph_tracking_values_iterate(sc,
- (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
- (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- &userdata, view_all_cb, NULL, NULL);
-
- /* set extents of view to start/end frames */
- v2d->cur.xmin = (float) SFRA;
- v2d->cur.xmax = (float) EFRA;
-
- if (userdata.min < userdata.max) {
- v2d->cur.ymin = userdata.min;
- v2d->cur.ymax = userdata.max;
- }
- else {
- v2d->cur.ymin = -10;
- v2d->cur.ymax = 10;
- }
-
- /* we need an extra "buffer" factor on either side so that the endpoints are visible */
- extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
- v2d->cur.xmin -= extra;
- v2d->cur.xmax += extra;
-
- extra = 0.01f * BLI_rctf_size_y(&v2d->cur);
- v2d->cur.ymin -= extra;
- v2d->cur.ymax += extra;
-
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ View2D *v2d = &ar->v2d;
+ ViewAllUserData userdata;
+ float extra;
+
+ userdata.max = -FLT_MAX;
+ userdata.min = FLT_MAX;
+
+ clip_graph_tracking_values_iterate(sc,
+ (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
+ (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
+ &userdata,
+ view_all_cb,
+ NULL,
+ NULL);
+
+ /* set extents of view to start/end frames */
+ v2d->cur.xmin = (float)SFRA;
+ v2d->cur.xmax = (float)EFRA;
+
+ if (userdata.min < userdata.max) {
+ v2d->cur.ymin = userdata.min;
+ v2d->cur.ymax = userdata.max;
+ }
+ else {
+ v2d->cur.ymin = -10;
+ v2d->cur.ymax = 10;
+ }
+
+ /* we need an extra "buffer" factor on either side so that the endpoints are visible */
+ extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
+ v2d->cur.xmin -= extra;
+ v2d->cur.xmax += extra;
+
+ extra = 0.01f * BLI_rctf_size_y(&v2d->cur);
+ v2d->cur.ymin -= extra;
+ v2d->cur.ymax += extra;
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_view_all(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View All";
- ot->description = "View all curves in editor";
- ot->idname = "CLIP_OT_graph_view_all";
-
- /* api callbacks */
- ot->exec = view_all_exec;
- ot->poll = ED_space_clip_graph_poll;
+ /* identifiers */
+ ot->name = "View All";
+ ot->description = "View all curves in editor";
+ ot->idname = "CLIP_OT_graph_view_all";
+
+ /* api callbacks */
+ ot->exec = view_all_exec;
+ ot->poll = ED_space_clip_graph_poll;
}
/******************** jump to current frame operator ********************/
void ED_clip_graph_center_current_frame(Scene *scene, ARegion *ar)
{
- View2D *v2d = &ar->v2d;
- float extra = BLI_rctf_size_x(&v2d->cur) / 2.0f;
+ View2D *v2d = &ar->v2d;
+ float extra = BLI_rctf_size_x(&v2d->cur) / 2.0f;
- /* set extents of view to start/end frames */
- v2d->cur.xmin = (float)CFRA - extra;
- v2d->cur.xmax = (float)CFRA + extra;
+ /* set extents of view to start/end frames */
+ v2d->cur.xmin = (float)CFRA - extra;
+ v2d->cur.xmax = (float)CFRA + extra;
}
static int center_current_frame_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
- ED_clip_graph_center_current_frame(scene, ar);
+ ED_clip_graph_center_current_frame(scene, ar);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_center_current_frame(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Center Current Frame";
- ot->description = "Scroll view so current frame would be centered";
- ot->idname = "CLIP_OT_graph_center_current_frame";
-
- /* api callbacks */
- ot->exec = center_current_frame_exec;
- ot->poll = ED_space_clip_graph_poll;
+ /* identifiers */
+ ot->name = "Center Current Frame";
+ ot->description = "Scroll view so current frame would be centered";
+ ot->idname = "CLIP_OT_graph_center_current_frame";
+
+ /* api callbacks */
+ ot->exec = center_current_frame_exec;
+ ot->poll = ED_space_clip_graph_poll;
}
/********************** disable markers operator *********************/
static int graph_disable_markers_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- MovieTrackingMarker *marker;
- int action = RNA_enum_get(op->ptr, "action");
- int a;
-
- if (!act_track || (act_track->flag & TRACK_LOCKED))
- return OPERATOR_CANCELLED;
-
- for (a = 0; a < act_track->markersnr; a++) {
- marker = &act_track->markers[a];
-
- if (marker->flag & MARKER_GRAPH_SEL) {
- if (action == 0)
- marker->flag |= MARKER_DISABLED;
- else if (action == 1)
- marker->flag &= ~MARKER_DISABLED;
- else
- marker->flag ^= MARKER_DISABLED;
- }
- }
-
- DEG_id_tag_update(&clip->id, 0);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ MovieTrackingMarker *marker;
+ int action = RNA_enum_get(op->ptr, "action");
+ int a;
+
+ if (!act_track || (act_track->flag & TRACK_LOCKED))
+ return OPERATOR_CANCELLED;
+
+ for (a = 0; a < act_track->markersnr; a++) {
+ marker = &act_track->markers[a];
+
+ if (marker->flag & MARKER_GRAPH_SEL) {
+ if (action == 0)
+ marker->flag |= MARKER_DISABLED;
+ else if (action == 1)
+ marker->flag &= ~MARKER_DISABLED;
+ else
+ marker->flag ^= MARKER_DISABLED;
+ }
+ }
+
+ DEG_id_tag_update(&clip->id, 0);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_graph_disable_markers(wmOperatorType *ot)
{
- static const EnumPropertyItem actions_items[] = {
- {0, "DISABLE", 0, "Disable", "Disable selected markers"},
- {1, "ENABLE", 0, "Enable", "Enable selected markers"},
- {2, "TOGGLE", 0, "Toggle", "Toggle disabled flag for selected markers"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Disable Markers";
- ot->description = "Disable/enable selected markers";
- ot->idname = "CLIP_OT_graph_disable_markers";
-
- /* api callbacks */
- ot->exec = graph_disable_markers_exec;
- ot->poll = ED_space_clip_graph_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Disable action to execute");
+ static const EnumPropertyItem actions_items[] = {
+ {0, "DISABLE", 0, "Disable", "Disable selected markers"},
+ {1, "ENABLE", 0, "Enable", "Enable selected markers"},
+ {2, "TOGGLE", 0, "Toggle", "Toggle disabled flag for selected markers"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Disable Markers";
+ ot->description = "Disable/enable selected markers";
+ ot->idname = "CLIP_OT_graph_disable_markers";
+
+ /* api callbacks */
+ ot->exec = graph_disable_markers_exec;
+ ot->poll = ED_space_clip_graph_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Disable action to execute");
}
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index e85d68431d4..8ecf596fac7 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -35,18 +35,18 @@ struct bContext;
struct wmOperatorType;
/* channel heights */
-#define CHANNEL_FIRST (-0.8f * U.widget_unit)
-#define CHANNEL_HEIGHT (0.8f * U.widget_unit)
-#define CHANNEL_HEIGHT_HALF (0.4f * U.widget_unit)
-#define CHANNEL_SKIP (0.1f * U.widget_unit)
-#define CHANNEL_STEP (CHANNEL_HEIGHT + CHANNEL_SKIP)
+#define CHANNEL_FIRST (-0.8f * U.widget_unit)
+#define CHANNEL_HEIGHT (0.8f * U.widget_unit)
+#define CHANNEL_HEIGHT_HALF (0.4f * U.widget_unit)
+#define CHANNEL_SKIP (0.1f * U.widget_unit)
+#define CHANNEL_STEP (CHANNEL_HEIGHT + CHANNEL_SKIP)
-#define CHANNEL_PAD 4
+#define CHANNEL_PAD 4
/* extra padding for lengths (to go under scrollers) */
-#define EXTRA_SCROLL_PAD 100.0f
+#define EXTRA_SCROLL_PAD 100.0f
-#define STRIP_HEIGHT_HALF (0.25f * UI_UNIT_Y)
+#define STRIP_HEIGHT_HALF (0.25f * UI_UNIT_Y)
/* internal exports only */
@@ -114,31 +114,61 @@ void CLIP_OT_tools(struct wmOperatorType *ot);
void CLIP_OT_properties(struct wmOperatorType *ot);
/* clip_utils.c */
-void clip_graph_tracking_values_iterate_track(struct SpaceClip *sc, struct MovieTrackingTrack *track, void *userdata,
- void (*func)(void *userdata, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point),
- void (*segment_end)(void *userdata, int coord));
-
-void clip_graph_tracking_values_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
- void (*func)(void *userdata, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point),
+void clip_graph_tracking_values_iterate_track(
+ struct SpaceClip *sc,
+ struct MovieTrackingTrack *track,
+ void *userdata,
+ void (*func)(void *userdata,
+ struct MovieTrackingTrack *track,
+ struct MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val),
+ void (*segment_start)(
+ void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point),
+ void (*segment_end)(void *userdata, int coord));
+
+void clip_graph_tracking_values_iterate(struct SpaceClip *sc,
+ bool selected_only,
+ bool include_hidden,
+ void *userdata,
+ void (*func)(void *userdata,
+ struct MovieTrackingTrack *track,
+ struct MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val),
+ void (*segment_start)(void *userdata,
+ struct MovieTrackingTrack *track,
+ int coord,
+ bool is_point),
void (*segment_end)(void *userdata, int coord));
-void clip_graph_tracking_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
+void clip_graph_tracking_iterate(struct SpaceClip *sc,
+ bool selected_only,
+ bool include_hidden,
+ void *userdata,
void (*func)(void *userdata, struct MovieTrackingMarker *marker));
-void clip_delete_track(struct bContext *C, struct MovieClip *clip, struct MovieTrackingTrack *track);
-void clip_delete_marker(struct bContext *C, struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
+void clip_delete_track(struct bContext *C,
+ struct MovieClip *clip,
+ struct MovieTrackingTrack *track);
+void clip_delete_marker(struct bContext *C,
+ struct MovieClip *clip,
+ struct MovieTrackingTrack *track,
+ struct MovieTrackingMarker *marker);
-void clip_delete_plane_track(struct bContext *C, struct MovieClip *clip, struct MovieTrackingPlaneTrack *plane_track);
+void clip_delete_plane_track(struct bContext *C,
+ struct MovieClip *clip,
+ struct MovieTrackingPlaneTrack *plane_track);
void clip_view_center_to_point(SpaceClip *sc, float x, float y);
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene);
/* tracking_ops.c */
-struct MovieTrackingTrack *tracking_marker_check_slide(struct bContext *C, const struct wmEvent *event,
- int *area_r, int *action_r, int *corner_r);
+struct MovieTrackingTrack *tracking_marker_check_slide(
+ struct bContext *C, const struct wmEvent *event, int *area_r, int *action_r, int *corner_r);
void CLIP_OT_add_marker(struct wmOperatorType *ot);
void CLIP_OT_add_marker_at_click(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index a86dd7ceb2d..3cebb53d31e 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -34,7 +34,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
-#include "DNA_scene_types.h" /* min/max frames */
+#include "DNA_scene_types.h" /* min/max frames */
#include "BLI_utildefines.h"
#include "BLI_fileops.h"
@@ -76,1035 +76,1080 @@
#include "DEG_depsgraph_build.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
/******************** view navigation utilities *********************/
static void sclip_zoom_set(const bContext *C, float zoom, float location[2])
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- float oldzoom = sc->zoom;
- int width, height;
+ float oldzoom = sc->zoom;
+ int width, height;
- sc->zoom = zoom;
+ sc->zoom = zoom;
- if (sc->zoom < 0.1f || sc->zoom > 4.0f) {
- /* check zoom limits */
- ED_space_clip_get_size(sc, &width, &height);
+ if (sc->zoom < 0.1f || sc->zoom > 4.0f) {
+ /* check zoom limits */
+ ED_space_clip_get_size(sc, &width, &height);
- width *= sc->zoom;
- height *= sc->zoom;
+ width *= sc->zoom;
+ height *= sc->zoom;
- if ((width < 4) && (height < 4) && sc->zoom < oldzoom)
- sc->zoom = oldzoom;
- else if (BLI_rcti_size_x(&ar->winrct) <= sc->zoom)
- sc->zoom = oldzoom;
- else if (BLI_rcti_size_y(&ar->winrct) <= sc->zoom)
- sc->zoom = oldzoom;
- }
+ if ((width < 4) && (height < 4) && sc->zoom < oldzoom)
+ sc->zoom = oldzoom;
+ else if (BLI_rcti_size_x(&ar->winrct) <= sc->zoom)
+ sc->zoom = oldzoom;
+ else if (BLI_rcti_size_y(&ar->winrct) <= sc->zoom)
+ sc->zoom = oldzoom;
+ }
- if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
- float aspx, aspy, w, h, dx, dy;
+ if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
+ float aspx, aspy, w, h, dx, dy;
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
- w = width * aspx;
- h = height * aspy;
+ w = width * aspx;
+ h = height * aspy;
- dx = ((location[0] - 0.5f) * w - sc->xof) * (sc->zoom - oldzoom) / sc->zoom;
- dy = ((location[1] - 0.5f) * h - sc->yof) * (sc->zoom - oldzoom) / sc->zoom;
+ dx = ((location[0] - 0.5f) * w - sc->xof) * (sc->zoom - oldzoom) / sc->zoom;
+ dy = ((location[1] - 0.5f) * h - sc->yof) * (sc->zoom - oldzoom) / sc->zoom;
- if (sc->flag & SC_LOCK_SELECTION) {
- sc->xlockof += dx;
- sc->ylockof += dy;
- }
- else {
- sc->xof += dx;
- sc->yof += dy;
- }
- }
+ if (sc->flag & SC_LOCK_SELECTION) {
+ sc->xlockof += dx;
+ sc->ylockof += dy;
+ }
+ else {
+ sc->xof += dx;
+ sc->yof += dy;
+ }
+ }
}
static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float location[2])
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- sclip_zoom_set(C, sc->zoom * zoomfac, location);
+ sclip_zoom_set(C, sc->zoom * zoomfac, location);
}
static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *ar = CTX_wm_region(C);
- float location[2], *mpos = NULL;
+ float location[2], *mpos = NULL;
- if (event) {
- SpaceClip *sc = CTX_wm_space_clip(C);
+ if (event) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
- ED_clip_mouse_pos(sc, ar, event->mval, location);
- mpos = location;
- }
+ ED_clip_mouse_pos(sc, ar, event->mval, location);
+ mpos = location;
+ }
- sclip_zoom_set_factor(C, factor, mpos);
+ sclip_zoom_set_factor(C, factor, mpos);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
}
/******************** open clip operator ********************/
static void clip_filesel(bContext *C, wmOperator *op, const char *path)
{
- RNA_string_set(op->ptr, "directory", path);
+ RNA_string_set(op->ptr, "directory", path);
- WM_event_add_fileselect(C, op);
+ WM_event_add_fileselect(C, op);
}
static void open_init(bContext *C, wmOperator *op)
{
- PropertyPointerRNA *pprop;
+ PropertyPointerRNA *pprop;
- op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
- UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
+ op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
+ UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
}
static void open_cancel(bContext *UNUSED(C), wmOperator *op)
{
- MEM_freeN(op->customdata);
- op->customdata = NULL;
+ MEM_freeN(op->customdata);
+ op->customdata = NULL;
}
static int open_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- bScreen *screen = CTX_wm_screen(C);
- Main *bmain = CTX_data_main(C);
- PropertyPointerRNA *pprop;
- PointerRNA idptr;
- MovieClip *clip = NULL;
- char str[FILE_MAX];
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ bScreen *screen = CTX_wm_screen(C);
+ Main *bmain = CTX_data_main(C);
+ PropertyPointerRNA *pprop;
+ PointerRNA idptr;
+ MovieClip *clip = NULL;
+ char str[FILE_MAX];
- if (RNA_collection_length(op->ptr, "files")) {
- PointerRNA fileptr;
- PropertyRNA *prop;
- char dir_only[FILE_MAX], file_only[FILE_MAX];
- bool relative = RNA_boolean_get(op->ptr, "relative_path");
+ if (RNA_collection_length(op->ptr, "files")) {
+ PointerRNA fileptr;
+ PropertyRNA *prop;
+ char dir_only[FILE_MAX], file_only[FILE_MAX];
+ bool relative = RNA_boolean_get(op->ptr, "relative_path");
- RNA_string_get(op->ptr, "directory", dir_only);
- if (relative) {
- BLI_path_rel(dir_only, CTX_data_main(C)->name);
- }
+ RNA_string_get(op->ptr, "directory", dir_only);
+ if (relative) {
+ BLI_path_rel(dir_only, CTX_data_main(C)->name);
+ }
- prop = RNA_struct_find_property(op->ptr, "files");
- RNA_property_collection_lookup_int(op->ptr, prop, 0, &fileptr);
- RNA_string_get(&fileptr, "name", file_only);
+ prop = RNA_struct_find_property(op->ptr, "files");
+ RNA_property_collection_lookup_int(op->ptr, prop, 0, &fileptr);
+ RNA_string_get(&fileptr, "name", file_only);
- BLI_join_dirfile(str, sizeof(str), dir_only, file_only);
- }
- else {
- BKE_report(op->reports, RPT_ERROR, "No files selected to be opened");
+ BLI_join_dirfile(str, sizeof(str), dir_only, file_only);
+ }
+ else {
+ BKE_report(op->reports, RPT_ERROR, "No files selected to be opened");
- return OPERATOR_CANCELLED;
- }
+ return OPERATOR_CANCELLED;
+ }
- /* default to frame 1 if there's no scene in context */
+ /* default to frame 1 if there's no scene in context */
- errno = 0;
+ errno = 0;
- clip = BKE_movieclip_file_add_exists(bmain, str);
+ clip = BKE_movieclip_file_add_exists(bmain, str);
- if (!clip) {
- if (op->customdata)
- MEM_freeN(op->customdata);
+ if (!clip) {
+ if (op->customdata)
+ MEM_freeN(op->customdata);
- BKE_reportf(op->reports, RPT_ERROR, "Cannot read '%s': %s", str,
- errno ? strerror(errno) : TIP_("unsupported movie clip format"));
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "Cannot read '%s': %s",
+ str,
+ errno ? strerror(errno) : TIP_("unsupported movie clip format"));
- return OPERATOR_CANCELLED;
- }
+ return OPERATOR_CANCELLED;
+ }
- if (!op->customdata)
- open_init(C, op);
+ if (!op->customdata)
+ open_init(C, op);
- /* hook into UI */
- pprop = op->customdata;
+ /* hook into UI */
+ pprop = op->customdata;
- if (pprop->prop) {
- /* when creating new ID blocks, use is already 1, but RNA
- * pointer use also increases user, so this compensates it */
- id_us_min(&clip->id);
+ if (pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer use also increases user, so this compensates it */
+ id_us_min(&clip->id);
- RNA_id_pointer_create(&clip->id, &idptr);
- RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
- RNA_property_update(C, &pprop->ptr, pprop->prop);
- }
- else if (sc) {
- ED_space_clip_set_clip(C, screen, sc, clip);
- }
+ RNA_id_pointer_create(&clip->id, &idptr);
+ RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+ RNA_property_update(C, &pprop->ptr, pprop->prop);
+ }
+ else if (sc) {
+ ED_space_clip_set_clip(C, screen, sc, clip);
+ }
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
- DEG_relations_tag_update(bmain);
- MEM_freeN(op->customdata);
+ DEG_relations_tag_update(bmain);
+ MEM_freeN(op->customdata);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- char path[FILE_MAX];
- MovieClip *clip = NULL;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ char path[FILE_MAX];
+ MovieClip *clip = NULL;
- if (sc)
- clip = ED_space_clip_get_clip(sc);
+ if (sc)
+ clip = ED_space_clip_get_clip(sc);
- if (clip) {
- BLI_strncpy(path, clip->name, sizeof(path));
+ if (clip) {
+ BLI_strncpy(path, clip->name, sizeof(path));
- BLI_path_abs(path, CTX_data_main(C)->name);
- BLI_parent_dir(path);
- }
- else {
- BLI_strncpy(path, U.textudir, sizeof(path));
- }
+ BLI_path_abs(path, CTX_data_main(C)->name);
+ BLI_parent_dir(path);
+ }
+ else {
+ BLI_strncpy(path, U.textudir, sizeof(path));
+ }
- if (RNA_struct_property_is_set(op->ptr, "files"))
- return open_exec(C, op);
+ if (RNA_struct_property_is_set(op->ptr, "files"))
+ return open_exec(C, op);
- if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
- RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
+ if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
+ RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
- open_init(C, op);
+ open_init(C, op);
- clip_filesel(C, op, path);
+ clip_filesel(C, op, path);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void CLIP_OT_open(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Open Clip";
- ot->description = "Load a sequence of frames or a movie file";
- ot->idname = "CLIP_OT_open";
+ /* identifiers */
+ ot->name = "Open Clip";
+ ot->description = "Load a sequence of frames or a movie file";
+ ot->idname = "CLIP_OT_open";
- /* api callbacks */
- ot->exec = open_exec;
- ot->invoke = open_invoke;
- ot->cancel = open_cancel;
+ /* api callbacks */
+ ot->exec = open_exec;
+ ot->invoke = open_invoke;
+ ot->cancel = open_cancel;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE,
- WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+ /* properties */
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE,
+ FILE_SPECIAL,
+ FILE_OPENFILE,
+ WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
}
/******************* reload clip operator *********************/
static int reload_exec(bContext *C, wmOperator *UNUSED(op))
{
- MovieClip *clip = CTX_data_edit_movieclip(C);
+ MovieClip *clip = CTX_data_edit_movieclip(C);
- if (!clip)
- return OPERATOR_CANCELLED;
+ if (!clip)
+ return OPERATOR_CANCELLED;
- WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_CLIP_PREFETCH);
- BKE_movieclip_reload(CTX_data_main(C), clip);
+ WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_CLIP_PREFETCH);
+ BKE_movieclip_reload(CTX_data_main(C), clip);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_reload(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Reload Clip";
- ot->description = "Reload clip";
- ot->idname = "CLIP_OT_reload";
+ /* identifiers */
+ ot->name = "Reload Clip";
+ ot->description = "Reload clip";
+ ot->idname = "CLIP_OT_reload";
- /* api callbacks */
- ot->exec = reload_exec;
+ /* api callbacks */
+ ot->exec = reload_exec;
}
/********************** view pan operator *********************/
typedef struct ViewPanData {
- float x, y;
- float xof, yof, xorig, yorig;
- int event_type;
- float *vec;
+ float x, y;
+ float xof, yof, xorig, yorig;
+ int event_type;
+ float *vec;
} ViewPanData;
static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ViewPanData *vpd;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ViewPanData *vpd;
- op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ClipViewPanData");
- WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+ op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ClipViewPanData");
+ WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
- vpd->x = event->x;
- vpd->y = event->y;
+ vpd->x = event->x;
+ vpd->y = event->y;
- if (sc->flag & SC_LOCK_SELECTION)
- vpd->vec = &sc->xlockof;
- else
- vpd->vec = &sc->xof;
+ if (sc->flag & SC_LOCK_SELECTION)
+ vpd->vec = &sc->xlockof;
+ else
+ vpd->vec = &sc->xof;
- copy_v2_v2(&vpd->xof, vpd->vec);
- copy_v2_v2(&vpd->xorig, &vpd->xof);
+ copy_v2_v2(&vpd->xof, vpd->vec);
+ copy_v2_v2(&vpd->xorig, &vpd->xof);
- vpd->event_type = event->type;
+ vpd->event_type = event->type;
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
}
static void view_pan_exit(bContext *C, wmOperator *op, bool cancel)
{
- ViewPanData *vpd = op->customdata;
+ ViewPanData *vpd = op->customdata;
- if (cancel) {
- copy_v2_v2(vpd->vec, &vpd->xorig);
+ if (cancel) {
+ copy_v2_v2(vpd->vec, &vpd->xorig);
- ED_region_tag_redraw(CTX_wm_region(C));
- }
+ ED_region_tag_redraw(CTX_wm_region(C));
+ }
- WM_cursor_modal_restore(CTX_wm_window(C));
- MEM_freeN(op->customdata);
+ WM_cursor_modal_restore(CTX_wm_window(C));
+ MEM_freeN(op->customdata);
}
static int view_pan_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- float offset[2];
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ float offset[2];
- RNA_float_get_array(op->ptr, "offset", offset);
+ RNA_float_get_array(op->ptr, "offset", offset);
- if (sc->flag & SC_LOCK_SELECTION) {
- sc->xlockof += offset[0];
- sc->ylockof += offset[1];
- }
- else {
- sc->xof += offset[0];
- sc->yof += offset[1];
- }
+ if (sc->flag & SC_LOCK_SELECTION) {
+ sc->xlockof += offset[0];
+ sc->ylockof += offset[1];
+ }
+ else {
+ sc->xof += offset[0];
+ sc->yof += offset[1];
+ }
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (event->type == MOUSEPAN) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- float offset[2];
+ if (event->type == MOUSEPAN) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ float offset[2];
- offset[0] = (event->prevx - event->x) / sc->zoom;
- offset[1] = (event->prevy - event->y) / sc->zoom;
+ offset[0] = (event->prevx - event->x) / sc->zoom;
+ offset[1] = (event->prevy - event->y) / sc->zoom;
- RNA_float_set_array(op->ptr, "offset", offset);
+ RNA_float_set_array(op->ptr, "offset", offset);
- view_pan_exec(C, op);
+ view_pan_exec(C, op);
- return OPERATOR_FINISHED;
- }
- else {
- view_pan_init(C, op, event);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ view_pan_init(C, op, event);
- return OPERATOR_RUNNING_MODAL;
- }
+ return OPERATOR_RUNNING_MODAL;
+ }
}
static int view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ViewPanData *vpd = op->customdata;
- float offset[2];
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ViewPanData *vpd = op->customdata;
+ float offset[2];
- switch (event->type) {
- case MOUSEMOVE:
- copy_v2_v2(vpd->vec, &vpd->xorig);
- offset[0] = (vpd->x - event->x) / sc->zoom;
- offset[1] = (vpd->y - event->y) / sc->zoom;
- RNA_float_set_array(op->ptr, "offset", offset);
- view_pan_exec(C, op);
- break;
- case ESCKEY:
- view_pan_exit(C, op, 1);
+ switch (event->type) {
+ case MOUSEMOVE:
+ copy_v2_v2(vpd->vec, &vpd->xorig);
+ offset[0] = (vpd->x - event->x) / sc->zoom;
+ offset[1] = (vpd->y - event->y) / sc->zoom;
+ RNA_float_set_array(op->ptr, "offset", offset);
+ view_pan_exec(C, op);
+ break;
+ case ESCKEY:
+ view_pan_exit(C, op, 1);
- return OPERATOR_CANCELLED;
- case SPACEKEY:
- view_pan_exit(C, op, 0);
+ return OPERATOR_CANCELLED;
+ case SPACEKEY:
+ view_pan_exit(C, op, 0);
- return OPERATOR_FINISHED;
- default:
- if (event->type == vpd->event_type && event->val == KM_RELEASE) {
- view_pan_exit(C, op, 0);
+ return OPERATOR_FINISHED;
+ default:
+ if (event->type == vpd->event_type && event->val == KM_RELEASE) {
+ view_pan_exit(C, op, 0);
- return OPERATOR_FINISHED;
- }
- break;
- }
+ return OPERATOR_FINISHED;
+ }
+ break;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void view_pan_cancel(bContext *C, wmOperator *op)
{
- view_pan_exit(C, op, true);
+ view_pan_exit(C, op, true);
}
void CLIP_OT_view_pan(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Pan View";
- ot->idname = "CLIP_OT_view_pan";
- ot->description = "Pan the view";
-
- /* api callbacks */
- ot->exec = view_pan_exec;
- ot->invoke = view_pan_invoke;
- ot->modal = view_pan_modal;
- ot->cancel = view_pan_cancel;
- ot->poll = ED_space_clip_view_clip_poll;
-
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR;
-
- /* properties */
- RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
- "Offset", "Offset in floating point units, 1.0 is the width and height of the image", -FLT_MAX, FLT_MAX);
+ /* identifiers */
+ ot->name = "Pan View";
+ ot->idname = "CLIP_OT_view_pan";
+ ot->description = "Pan the view";
+
+ /* api callbacks */
+ ot->exec = view_pan_exec;
+ ot->invoke = view_pan_invoke;
+ ot->modal = view_pan_modal;
+ ot->cancel = view_pan_cancel;
+ ot->poll = ED_space_clip_view_clip_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR;
+
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "offset",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Offset",
+ "Offset in floating point units, 1.0 is the width and height of the image",
+ -FLT_MAX,
+ FLT_MAX);
}
/********************** view zoom operator *********************/
typedef struct ViewZoomData {
- float x, y;
- float zoom;
- int event_type;
- float location[2];
- wmTimer *timer;
- double timer_lastdraw;
+ float x, y;
+ float zoom;
+ int event_type;
+ float location[2];
+ wmTimer *timer;
+ double timer_lastdraw;
} ViewZoomData;
static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
- ViewZoomData *vpd;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+ ViewZoomData *vpd;
- op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData");
- WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+ op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData");
+ WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
- if (U.viewzoom == USER_ZOOM_CONT) {
- /* needs a timer to continue redrawing */
- vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
- vpd->timer_lastdraw = PIL_check_seconds_timer();
- }
+ if (U.viewzoom == USER_ZOOM_CONT) {
+ /* needs a timer to continue redrawing */
+ vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
+ vpd->timer_lastdraw = PIL_check_seconds_timer();
+ }
- vpd->x = event->x;
- vpd->y = event->y;
- vpd->zoom = sc->zoom;
- vpd->event_type = event->type;
+ vpd->x = event->x;
+ vpd->y = event->y;
+ vpd->zoom = sc->zoom;
+ vpd->event_type = event->type;
- ED_clip_mouse_pos(sc, ar, event->mval, vpd->location);
+ ED_clip_mouse_pos(sc, ar, event->mval, vpd->location);
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
}
static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ViewZoomData *vpd = op->customdata;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ViewZoomData *vpd = op->customdata;
- if (cancel) {
- sc->zoom = vpd->zoom;
- ED_region_tag_redraw(CTX_wm_region(C));
- }
+ if (cancel) {
+ sc->zoom = vpd->zoom;
+ ED_region_tag_redraw(CTX_wm_region(C));
+ }
- if (vpd->timer) {
- WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
- }
+ if (vpd->timer) {
+ WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
+ }
- WM_cursor_modal_restore(CTX_wm_window(C));
- MEM_freeN(op->customdata);
+ WM_cursor_modal_restore(CTX_wm_window(C));
+ MEM_freeN(op->customdata);
}
static int view_zoom_exec(bContext *C, wmOperator *op)
{
- sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL);
+ sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL);
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (event->type == MOUSEZOOM || event->type == MOUSEPAN) {
- float delta, factor;
+ if (event->type == MOUSEZOOM || event->type == MOUSEPAN) {
+ float delta, factor;
- delta = event->prevx - event->x + event->prevy - event->y;
+ delta = event->prevx - event->x + event->prevy - event->y;
- if (U.uiflag & USER_ZOOM_INVERT)
- delta *= -1;
+ if (U.uiflag & USER_ZOOM_INVERT)
+ delta *= -1;
- factor = 1.0f + delta / 300.0f;
- RNA_float_set(op->ptr, "factor", factor);
+ factor = 1.0f + delta / 300.0f;
+ RNA_float_set(op->ptr, "factor", factor);
- sclip_zoom_set_factor_exec(C, event, factor);
+ sclip_zoom_set_factor_exec(C, event, factor);
- return OPERATOR_FINISHED;
- }
- else {
- view_zoom_init(C, op, event);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ view_zoom_init(C, op, event);
- return OPERATOR_RUNNING_MODAL;
- }
+ return OPERATOR_RUNNING_MODAL;
+ }
}
-static void view_zoom_apply(bContext *C,
- ViewZoomData *vpd,
- wmOperator *op,
- const wmEvent *event)
+static void view_zoom_apply(bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event)
{
- float factor;
+ float factor;
- if (U.viewzoom == USER_ZOOM_CONT) {
- SpaceClip *sclip = CTX_wm_space_clip(C);
- double time = PIL_check_seconds_timer();
- float time_step = (float)(time - vpd->timer_lastdraw);
- float fac;
- float zfac;
+ if (U.viewzoom == USER_ZOOM_CONT) {
+ SpaceClip *sclip = CTX_wm_space_clip(C);
+ double time = PIL_check_seconds_timer();
+ float time_step = (float)(time - vpd->timer_lastdraw);
+ float fac;
+ float zfac;
- if (U.uiflag & USER_ZOOM_HORIZ) {
- fac = (float)(event->x - vpd->x);
- }
- else {
- fac = (float)(event->y - vpd->y);
- }
+ if (U.uiflag & USER_ZOOM_HORIZ) {
+ fac = (float)(event->x - vpd->x);
+ }
+ else {
+ fac = (float)(event->y - vpd->y);
+ }
- if (U.uiflag & USER_ZOOM_INVERT) {
- fac = -fac;
- }
+ if (U.uiflag & USER_ZOOM_INVERT) {
+ fac = -fac;
+ }
- zfac = 1.0f + ((fac / 20.0f) * time_step);
- vpd->timer_lastdraw = time;
- factor = (sclip->zoom * zfac) / vpd->zoom;
- }
- else {
- float delta = event->x - vpd->x + event->y - vpd->y;
+ zfac = 1.0f + ((fac / 20.0f) * time_step);
+ vpd->timer_lastdraw = time;
+ factor = (sclip->zoom * zfac) / vpd->zoom;
+ }
+ else {
+ float delta = event->x - vpd->x + event->y - vpd->y;
- if (U.uiflag & USER_ZOOM_INVERT) {
- delta *= -1;
- }
+ if (U.uiflag & USER_ZOOM_INVERT) {
+ delta *= -1;
+ }
- factor = 1.0f + delta / 300.0f;
- }
+ factor = 1.0f + delta / 300.0f;
+ }
- RNA_float_set(op->ptr, "factor", factor);
- sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
- ED_region_tag_redraw(CTX_wm_region(C));
+ RNA_float_set(op->ptr, "factor", factor);
+ sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
+ ED_region_tag_redraw(CTX_wm_region(C));
}
static int view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- ViewZoomData *vpd = op->customdata;
- switch (event->type) {
- case TIMER:
- if (event->customdata == vpd->timer) {
- view_zoom_apply(C, vpd, op, event);
- }
- break;
- case MOUSEMOVE:
- view_zoom_apply(C, vpd, op, event);
- break;
- default:
- if (event->type == vpd->event_type && event->val == KM_RELEASE) {
- view_zoom_exit(C, op, 0);
+ ViewZoomData *vpd = op->customdata;
+ switch (event->type) {
+ case TIMER:
+ if (event->customdata == vpd->timer) {
+ view_zoom_apply(C, vpd, op, event);
+ }
+ break;
+ case MOUSEMOVE:
+ view_zoom_apply(C, vpd, op, event);
+ break;
+ default:
+ if (event->type == vpd->event_type && event->val == KM_RELEASE) {
+ view_zoom_exit(C, op, 0);
- return OPERATOR_FINISHED;
- }
- break;
- }
+ return OPERATOR_FINISHED;
+ }
+ break;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void view_zoom_cancel(bContext *C, wmOperator *op)
{
- view_zoom_exit(C, op, true);
+ view_zoom_exit(C, op, true);
}
void CLIP_OT_view_zoom(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View Zoom";
- ot->idname = "CLIP_OT_view_zoom";
- ot->description = "Zoom in/out the view";
+ /* identifiers */
+ ot->name = "View Zoom";
+ ot->idname = "CLIP_OT_view_zoom";
+ ot->description = "Zoom in/out the view";
- /* api callbacks */
- ot->exec = view_zoom_exec;
- ot->invoke = view_zoom_invoke;
- ot->modal = view_zoom_modal;
- ot->cancel = view_zoom_cancel;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_zoom_exec;
+ ot->invoke = view_zoom_invoke;
+ ot->modal = view_zoom_modal;
+ ot->cancel = view_zoom_cancel;
+ ot->poll = ED_space_clip_view_clip_poll;
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR;
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR;
- /* properties */
- prop = RNA_def_float(ot->srna, "factor", 0.0f, -FLT_MAX, FLT_MAX, "Factor",
- "Zoom factor, values higher than 1.0 zoom in, lower values zoom out", -FLT_MAX, FLT_MAX);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float(ot->srna,
+ "factor",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Factor",
+ "Zoom factor, values higher than 1.0 zoom in, lower values zoom out",
+ -FLT_MAX,
+ FLT_MAX);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
/********************** view zoom in/out operator *********************/
static int view_zoom_in_exec(bContext *C, wmOperator *op)
{
- float location[2];
+ float location[2];
- RNA_float_get_array(op->ptr, "location", location);
+ RNA_float_get_array(op->ptr, "location", location);
- sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location);
+ sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location);
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int view_zoom_in_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- float location[2];
+ float location[2];
- ED_clip_mouse_pos(sc, ar, event->mval, location);
- RNA_float_set_array(op->ptr, "location", location);
+ ED_clip_mouse_pos(sc, ar, event->mval, location);
+ RNA_float_set_array(op->ptr, "location", location);
- return view_zoom_in_exec(C, op);
+ return view_zoom_in_exec(C, op);
}
void CLIP_OT_view_zoom_in(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View Zoom In";
- ot->idname = "CLIP_OT_view_zoom_in";
- ot->description = "Zoom in the view";
+ /* identifiers */
+ ot->name = "View Zoom In";
+ ot->idname = "CLIP_OT_view_zoom_in";
+ ot->description = "Zoom in the view";
- /* api callbacks */
- ot->exec = view_zoom_in_exec;
- ot->invoke = view_zoom_in_invoke;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_zoom_in_exec;
+ ot->invoke = view_zoom_in_invoke;
+ ot->poll = ED_space_clip_view_clip_poll;
- /* properties */
- prop = RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location",
- "Cursor location in screen coordinates", -10.0f, 10.0f);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Cursor location in screen coordinates",
+ -10.0f,
+ 10.0f);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
static int view_zoom_out_exec(bContext *C, wmOperator *op)
{
- float location[2];
+ float location[2];
- RNA_float_get_array(op->ptr, "location", location);
+ RNA_float_get_array(op->ptr, "location", location);
- sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), location);
+ sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), location);
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int view_zoom_out_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- float location[2];
+ float location[2];
- ED_clip_mouse_pos(sc, ar, event->mval, location);
- RNA_float_set_array(op->ptr, "location", location);
+ ED_clip_mouse_pos(sc, ar, event->mval, location);
+ RNA_float_set_array(op->ptr, "location", location);
- return view_zoom_out_exec(C, op);
+ return view_zoom_out_exec(C, op);
}
void CLIP_OT_view_zoom_out(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View Zoom Out";
- ot->idname = "CLIP_OT_view_zoom_out";
- ot->description = "Zoom out the view";
+ /* identifiers */
+ ot->name = "View Zoom Out";
+ ot->idname = "CLIP_OT_view_zoom_out";
+ ot->description = "Zoom out the view";
- /* api callbacks */
- ot->exec = view_zoom_out_exec;
- ot->invoke = view_zoom_out_invoke;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_zoom_out_exec;
+ ot->invoke = view_zoom_out_invoke;
+ ot->poll = ED_space_clip_view_clip_poll;
- /* properties */
- prop = RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location",
- "Cursor location in normalized (0.0-1.0) coordinates", -10.0f, 10.0f);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Cursor location in normalized (0.0-1.0) coordinates",
+ -10.0f,
+ 10.0f);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
/********************** view zoom ratio operator *********************/
static int view_zoom_ratio_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL);
+ sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL);
- /* ensure pixel exact locations for draw */
- sc->xof = (int) sc->xof;
- sc->yof = (int) sc->yof;
+ /* ensure pixel exact locations for draw */
+ sc->xof = (int)sc->xof;
+ sc->yof = (int)sc->yof;
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_view_zoom_ratio(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View Zoom Ratio";
- ot->idname = "CLIP_OT_view_zoom_ratio";
- ot->description = "Set the zoom ratio (based on clip size)";
+ /* identifiers */
+ ot->name = "View Zoom Ratio";
+ ot->idname = "CLIP_OT_view_zoom_ratio";
+ ot->description = "Set the zoom ratio (based on clip size)";
- /* api callbacks */
- ot->exec = view_zoom_ratio_exec;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_zoom_ratio_exec;
+ ot->poll = ED_space_clip_view_clip_poll;
- /* properties */
- RNA_def_float(ot->srna, "ratio", 0.0f, -FLT_MAX, FLT_MAX,
- "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out", -FLT_MAX, FLT_MAX);
+ /* properties */
+ RNA_def_float(ot->srna,
+ "ratio",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Ratio",
+ "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
+ -FLT_MAX,
+ FLT_MAX);
}
/********************** view all operator *********************/
static int view_all_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc;
- ARegion *ar;
- int w, h, width, height;
- float aspx, aspy;
- bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
- float zoomx, zoomy;
+ SpaceClip *sc;
+ ARegion *ar;
+ int w, h, width, height;
+ float aspx, aspy;
+ bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
+ float zoomx, zoomy;
- /* retrieve state */
- sc = CTX_wm_space_clip(C);
- ar = CTX_wm_region(C);
+ /* retrieve state */
+ sc = CTX_wm_space_clip(C);
+ ar = CTX_wm_region(C);
- ED_space_clip_get_size(sc, &w, &h);
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
+ ED_space_clip_get_size(sc, &w, &h);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
- w = w * aspx;
- h = h * aspy;
+ w = w * aspx;
+ h = h * aspy;
- /* check if the image will fit in the image with zoom == 1 */
- width = BLI_rcti_size_x(&ar->winrct) + 1;
- height = BLI_rcti_size_y(&ar->winrct) + 1;
+ /* check if the image will fit in the image with zoom == 1 */
+ width = BLI_rcti_size_x(&ar->winrct) + 1;
+ height = BLI_rcti_size_y(&ar->winrct) + 1;
- if (fit_view) {
- const int margin = 5; /* margin from border */
+ if (fit_view) {
+ const int margin = 5; /* margin from border */
- zoomx = (float) width / (w + 2 * margin);
- zoomy = (float) height / (h + 2 * margin);
+ zoomx = (float)width / (w + 2 * margin);
+ zoomy = (float)height / (h + 2 * margin);
- sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL);
- }
- else {
- if ((w >= width || h >= height) && (width > 0 && height > 0)) {
- zoomx = (float) width / w;
- zoomy = (float) height / h;
+ sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL);
+ }
+ else {
+ if ((w >= width || h >= height) && (width > 0 && height > 0)) {
+ zoomx = (float)width / w;
+ zoomy = (float)height / h;
- /* find the zoom value that will fit the image in the image space */
- sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
- }
- else
- sclip_zoom_set(C, 1.0f, NULL);
- }
+ /* find the zoom value that will fit the image in the image space */
+ sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
+ }
+ else
+ sclip_zoom_set(C, 1.0f, NULL);
+ }
- sc->xof = sc->yof = 0.0f;
+ sc->xof = sc->yof = 0.0f;
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_view_all(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View All";
- ot->idname = "CLIP_OT_view_all";
- ot->description = "View whole image with markers";
+ /* identifiers */
+ ot->name = "View All";
+ ot->idname = "CLIP_OT_view_all";
+ ot->description = "View whole image with markers";
- /* api callbacks */
- ot->exec = view_all_exec;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_all_exec;
+ ot->poll = ED_space_clip_view_clip_poll;
- /* properties */
- prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ /* properties */
+ prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/********************** view selected operator *********************/
static int view_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- sc->xlockof = 0.0f;
- sc->ylockof = 0.0f;
+ sc->xlockof = 0.0f;
+ sc->ylockof = 0.0f;
- ED_clip_view_selection(C, ar, 1);
- ED_region_tag_redraw(ar);
+ ED_clip_view_selection(C, ar, 1);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_view_selected(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View Selected";
- ot->idname = "CLIP_OT_view_selected";
- ot->description = "View all selected elements";
+ /* identifiers */
+ ot->name = "View Selected";
+ ot->idname = "CLIP_OT_view_selected";
+ ot->description = "View all selected elements";
- /* api callbacks */
- ot->exec = view_selected_exec;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->exec = view_selected_exec;
+ ot->poll = ED_space_clip_view_clip_poll;
}
/********************** change frame operator *********************/
static bool change_frame_poll(bContext *C)
{
- /* prevent changes during render */
- if (G.is_rendering)
- return 0;
+ /* prevent changes during render */
+ if (G.is_rendering)
+ return 0;
- return ED_space_clip_poll(C);
+ return ED_space_clip_poll(C);
}
static void change_frame_apply(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
+ Scene *scene = CTX_data_scene(C);
- /* set the new frame number */
- CFRA = RNA_int_get(op->ptr, "frame");
- FRAMENUMBER_MIN_CLAMP(CFRA);
- SUBFRA = 0.0f;
+ /* set the new frame number */
+ CFRA = RNA_int_get(op->ptr, "frame");
+ FRAMENUMBER_MIN_CLAMP(CFRA);
+ SUBFRA = 0.0f;
- /* do updates */
- BKE_sound_seek_scene(CTX_data_main(C), scene);
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+ /* do updates */
+ BKE_sound_seek_scene(CTX_data_main(C), scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
}
static int change_frame_exec(bContext *C, wmOperator *op)
{
- change_frame_apply(C, op);
+ change_frame_apply(C, op);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int frame_from_event(bContext *C, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- int framenr = 0;
+ ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ int framenr = 0;
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
- framenr = sfra + event->mval[0] / framelen;
- }
- else {
- float viewx, viewy;
+ framenr = sfra + event->mval[0] / framelen;
+ }
+ else {
+ float viewx, viewy;
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
- framenr = round_fl_to_int(viewx);
- }
+ framenr = round_fl_to_int(viewx);
+ }
- return framenr;
+ return framenr;
}
static int change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *ar = CTX_wm_region(C);
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- if (event->mval[1] > 16)
- return OPERATOR_PASS_THROUGH;
- }
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ if (event->mval[1] > 16)
+ return OPERATOR_PASS_THROUGH;
+ }
- RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
+ RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
- change_frame_apply(C, op);
+ change_frame_apply(C, op);
- /* add temp handler */
- WM_event_add_modal_handler(C, op);
+ /* add temp handler */
+ WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static int change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- switch (event->type) {
- case ESCKEY:
- return OPERATOR_FINISHED;
+ switch (event->type) {
+ case ESCKEY:
+ return OPERATOR_FINISHED;
- case MOUSEMOVE:
- RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
- change_frame_apply(C, op);
- break;
+ case MOUSEMOVE:
+ RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
+ change_frame_apply(C, op);
+ break;
- case LEFTMOUSE:
- case RIGHTMOUSE:
- if (event->val == KM_RELEASE)
- return OPERATOR_FINISHED;
- break;
- }
+ case LEFTMOUSE:
+ case RIGHTMOUSE:
+ if (event->val == KM_RELEASE)
+ return OPERATOR_FINISHED;
+ break;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void CLIP_OT_change_frame(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Change Frame";
- ot->idname = "CLIP_OT_change_frame";
- ot->description = "Interactively change the current frame number";
+ /* identifiers */
+ ot->name = "Change Frame";
+ ot->idname = "CLIP_OT_change_frame";
+ ot->description = "Interactively change the current frame number";
- /* api callbacks */
- ot->exec = change_frame_exec;
- ot->invoke = change_frame_invoke;
- ot->modal = change_frame_modal;
- ot->poll = change_frame_poll;
+ /* api callbacks */
+ ot->exec = change_frame_exec;
+ ot->invoke = change_frame_invoke;
+ ot->modal = change_frame_modal;
+ ot->poll = change_frame_poll;
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
- /* rna */
- RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
+ /* rna */
+ RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
}
/********************** rebuild proxies operator *********************/
typedef struct ProxyBuildJob {
- Scene *scene;
- struct Main *main;
- MovieClip *clip;
- int clip_flag;
- bool stop;
- struct IndexBuildContext *index_context;
+ Scene *scene;
+ struct Main *main;
+ MovieClip *clip;
+ int clip_flag;
+ bool stop;
+ struct IndexBuildContext *index_context;
} ProxyJob;
static void proxy_freejob(void *pjv)
{
- ProxyJob *pj = pjv;
+ ProxyJob *pj = pjv;
- MEM_freeN(pj);
+ MEM_freeN(pj);
}
static int proxy_bitflag_to_array(int size_flag, int build_sizes[4], int undistort)
{
- int build_count = 0;
- int size_flags[2][4] = {{MCLIP_PROXY_SIZE_25,
- MCLIP_PROXY_SIZE_50,
- MCLIP_PROXY_SIZE_75,
- MCLIP_PROXY_SIZE_100},
- {MCLIP_PROXY_UNDISTORTED_SIZE_25,
- MCLIP_PROXY_UNDISTORTED_SIZE_50,
- MCLIP_PROXY_UNDISTORTED_SIZE_75,
- MCLIP_PROXY_UNDISTORTED_SIZE_100}};
- int size_nr = undistort ? 1 : 0;
+ int build_count = 0;
+ int size_flags[2][4] = {
+ {MCLIP_PROXY_SIZE_25, MCLIP_PROXY_SIZE_50, MCLIP_PROXY_SIZE_75, MCLIP_PROXY_SIZE_100},
+ {MCLIP_PROXY_UNDISTORTED_SIZE_25,
+ MCLIP_PROXY_UNDISTORTED_SIZE_50,
+ MCLIP_PROXY_UNDISTORTED_SIZE_75,
+ MCLIP_PROXY_UNDISTORTED_SIZE_100}};
+ int size_nr = undistort ? 1 : 0;
- if (size_flag & size_flags[size_nr][0])
- build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_25;
+ if (size_flag & size_flags[size_nr][0])
+ build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_25;
- if (size_flag & size_flags[size_nr][1])
- build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_50;
+ if (size_flag & size_flags[size_nr][1])
+ build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_50;
- if (size_flag & size_flags[size_nr][2])
- build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_75;
+ if (size_flag & size_flags[size_nr][2])
+ build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_75;
- if (size_flag & size_flags[size_nr][3])
- build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_100;
+ if (size_flag & size_flags[size_nr][3])
+ build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_100;
- return build_count;
+ return build_count;
}
/* simple case for movies -- handle frame-by-frame, do threading within single frame */
-static void do_movie_proxy(void *pjv, int *UNUSED(build_sizes), int UNUSED(build_count),
- int *build_undistort_sizes, int build_undistort_count,
- short *stop, short *do_update, float *progress)
+static void do_movie_proxy(void *pjv,
+ int *UNUSED(build_sizes),
+ int UNUSED(build_count),
+ int *build_undistort_sizes,
+ int build_undistort_count,
+ short *stop,
+ short *do_update,
+ float *progress)
{
- ProxyJob *pj = pjv;
- Scene *scene = pj->scene;
- MovieClip *clip = pj->clip;
- struct MovieDistortion *distortion = NULL;
- int cfra, sfra = SFRA, efra = EFRA;
+ ProxyJob *pj = pjv;
+ Scene *scene = pj->scene;
+ MovieClip *clip = pj->clip;
+ struct MovieDistortion *distortion = NULL;
+ int cfra, sfra = SFRA, efra = EFRA;
- if (pj->index_context)
- IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress);
+ if (pj->index_context)
+ IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress);
- if (!build_undistort_count) {
- if (*stop)
- pj->stop = 1;
+ if (!build_undistort_count) {
+ if (*stop)
+ pj->stop = 1;
- return;
- }
- else {
- sfra = 1;
- efra = clip->len;
- }
+ return;
+ }
+ else {
+ sfra = 1;
+ efra = clip->len;
+ }
- if (build_undistort_count) {
- int threads = BLI_system_thread_count();
- int width, height;
+ if (build_undistort_count) {
+ int threads = BLI_system_thread_count();
+ int width, height;
- BKE_movieclip_get_size(clip, NULL, &width, &height);
+ BKE_movieclip_get_size(clip, NULL, &width, &height);
- distortion = BKE_tracking_distortion_new(&clip->tracking, width, height);
- BKE_tracking_distortion_set_threads(distortion, threads);
- }
+ distortion = BKE_tracking_distortion_new(&clip->tracking, width, height);
+ BKE_tracking_distortion_set_threads(distortion, threads);
+ }
- for (cfra = sfra; cfra <= efra; cfra++) {
- BKE_movieclip_build_proxy_frame(clip, pj->clip_flag, distortion, cfra,
- build_undistort_sizes, build_undistort_count, 1);
+ for (cfra = sfra; cfra <= efra; cfra++) {
+ BKE_movieclip_build_proxy_frame(
+ clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, 1);
- if (*stop || G.is_break)
- break;
+ if (*stop || G.is_break)
+ break;
- *do_update = true;
- *progress = ((float) cfra - sfra) / (efra - sfra);
- }
+ *do_update = true;
+ *progress = ((float)cfra - sfra) / (efra - sfra);
+ }
- if (distortion)
- BKE_tracking_distortion_free(distortion);
+ if (distortion)
+ BKE_tracking_distortion_free(distortion);
- if (*stop)
- pj->stop = 1;
+ if (*stop)
+ pj->stop = 1;
}
/* *****
@@ -1114,296 +1159,325 @@ static void do_movie_proxy(void *pjv, int *UNUSED(build_sizes), int UNUSED(build
*/
typedef struct ProxyQueue {
- int cfra;
- int sfra;
- int efra;
- SpinLock spin;
-
- const short *stop;
- short *do_update;
- float *progress;
+ int cfra;
+ int sfra;
+ int efra;
+ SpinLock spin;
+
+ const short *stop;
+ short *do_update;
+ float *progress;
} ProxyQueue;
typedef struct ProxyThread {
- MovieClip *clip;
- struct MovieDistortion *distortion;
- int *build_sizes, build_count;
- int *build_undistort_sizes, build_undistort_count;
+ MovieClip *clip;
+ struct MovieDistortion *distortion;
+ int *build_sizes, build_count;
+ int *build_undistort_sizes, build_undistort_count;
} ProxyThread;
-static unsigned char *proxy_thread_next_frame(ProxyQueue *queue, MovieClip *clip, size_t *size_r, int *cfra_r)
-{
- unsigned char *mem = NULL;
-
- BLI_spin_lock(&queue->spin);
- if (!*queue->stop && queue->cfra <= queue->efra) {
- MovieClipUser user = {0};
- char name[FILE_MAX];
- size_t size;
- int file;
-
- user.framenr = queue->cfra;
-
- BKE_movieclip_filename_for_frame(clip, &user, name);
-
- file = BLI_open(name, O_BINARY | O_RDONLY, 0);
- if (file < 0) {
- BLI_spin_unlock(&queue->spin);
- return NULL;
- }
-
- size = BLI_file_descriptor_size(file);
- if (size < 1) {
- close(file);
- BLI_spin_unlock(&queue->spin);
- return NULL;
- }
-
- mem = MEM_mallocN(size, "movieclip proxy memory file");
+static unsigned char *proxy_thread_next_frame(ProxyQueue *queue,
+ MovieClip *clip,
+ size_t *size_r,
+ int *cfra_r)
+{
+ unsigned char *mem = NULL;
+
+ BLI_spin_lock(&queue->spin);
+ if (!*queue->stop && queue->cfra <= queue->efra) {
+ MovieClipUser user = {0};
+ char name[FILE_MAX];
+ size_t size;
+ int file;
- if (read(file, mem, size) != size) {
- close(file);
- BLI_spin_unlock(&queue->spin);
- MEM_freeN(mem);
- return NULL;
- }
+ user.framenr = queue->cfra;
+
+ BKE_movieclip_filename_for_frame(clip, &user, name);
+
+ file = BLI_open(name, O_BINARY | O_RDONLY, 0);
+ if (file < 0) {
+ BLI_spin_unlock(&queue->spin);
+ return NULL;
+ }
+
+ size = BLI_file_descriptor_size(file);
+ if (size < 1) {
+ close(file);
+ BLI_spin_unlock(&queue->spin);
+ return NULL;
+ }
+
+ mem = MEM_mallocN(size, "movieclip proxy memory file");
+
+ if (read(file, mem, size) != size) {
+ close(file);
+ BLI_spin_unlock(&queue->spin);
+ MEM_freeN(mem);
+ return NULL;
+ }
+
+ *size_r = size;
+ *cfra_r = queue->cfra;
+
+ queue->cfra++;
+ close(file);
- *size_r = size;
- *cfra_r = queue->cfra;
+ *queue->do_update = 1;
+ *queue->progress = (float)(queue->cfra - queue->sfra) / (queue->efra - queue->sfra);
+ }
+ BLI_spin_unlock(&queue->spin);
+
+ return mem;
+}
- queue->cfra++;
- close(file);
-
- *queue->do_update = 1;
- *queue->progress = (float)(queue->cfra - queue->sfra) / (queue->efra - queue->sfra);
- }
- BLI_spin_unlock(&queue->spin);
-
- return mem;
-}
-
-static void proxy_task_func(TaskPool * __restrict pool, void *task_data, int UNUSED(threadid))
+static void proxy_task_func(TaskPool *__restrict pool, void *task_data, int UNUSED(threadid))
{
- ProxyThread *data = (ProxyThread *)task_data;
- ProxyQueue *queue = (ProxyQueue *)BLI_task_pool_userdata(pool);
- unsigned char *mem;
- size_t size;
- int cfra;
+ ProxyThread *data = (ProxyThread *)task_data;
+ ProxyQueue *queue = (ProxyQueue *)BLI_task_pool_userdata(pool);
+ unsigned char *mem;
+ size_t size;
+ int cfra;
- while ((mem = proxy_thread_next_frame(queue, data->clip, &size, &cfra))) {
- ImBuf *ibuf;
+ while ((mem = proxy_thread_next_frame(queue, data->clip, &size, &cfra))) {
+ ImBuf *ibuf;
- ibuf = IMB_ibImageFromMemory(mem, size, IB_rect | IB_multilayer | IB_alphamode_detect,
- data->clip->colorspace_settings.name, "proxy frame");
+ ibuf = IMB_ibImageFromMemory(mem,
+ size,
+ IB_rect | IB_multilayer | IB_alphamode_detect,
+ data->clip->colorspace_settings.name,
+ "proxy frame");
- BKE_movieclip_build_proxy_frame_for_ibuf(data->clip, ibuf, NULL, cfra,
- data->build_sizes, data->build_count, false);
+ BKE_movieclip_build_proxy_frame_for_ibuf(
+ data->clip, ibuf, NULL, cfra, data->build_sizes, data->build_count, false);
- BKE_movieclip_build_proxy_frame_for_ibuf(data->clip, ibuf, data->distortion, cfra,
- data->build_undistort_sizes, data->build_undistort_count, true);
+ BKE_movieclip_build_proxy_frame_for_ibuf(data->clip,
+ ibuf,
+ data->distortion,
+ cfra,
+ data->build_undistort_sizes,
+ data->build_undistort_count,
+ true);
- IMB_freeImBuf(ibuf);
+ IMB_freeImBuf(ibuf);
- MEM_freeN(mem);
- }
+ MEM_freeN(mem);
+ }
}
-static void do_sequence_proxy(void *pjv, int *build_sizes, int build_count,
- int *build_undistort_sizes, int build_undistort_count,
- short *stop, short *do_update, float *progress)
+static void do_sequence_proxy(void *pjv,
+ int *build_sizes,
+ int build_count,
+ int *build_undistort_sizes,
+ int build_undistort_count,
+ short *stop,
+ short *do_update,
+ float *progress)
{
- ProxyJob *pj = pjv;
- MovieClip *clip = pj->clip;
- Scene *scene = pj->scene;
- TaskScheduler *task_scheduler = BLI_task_scheduler_get();
- TaskPool *task_pool;
- int sfra = SFRA, efra = EFRA;
- ProxyThread *handles;
- int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
- int width, height;
- ProxyQueue queue;
-
- if (build_undistort_count) {
- BKE_movieclip_get_size(clip, NULL, &width, &height);
- }
+ ProxyJob *pj = pjv;
+ MovieClip *clip = pj->clip;
+ Scene *scene = pj->scene;
+ TaskScheduler *task_scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ int sfra = SFRA, efra = EFRA;
+ ProxyThread *handles;
+ int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
+ int width, height;
+ ProxyQueue queue;
+
+ if (build_undistort_count) {
+ BKE_movieclip_get_size(clip, NULL, &width, &height);
+ }
- BLI_spin_init(&queue.spin);
+ BLI_spin_init(&queue.spin);
- queue.cfra = sfra;
- queue.sfra = sfra;
- queue.efra = efra;
- queue.stop = stop;
- queue.do_update = do_update;
- queue.progress = progress;
+ queue.cfra = sfra;
+ queue.sfra = sfra;
+ queue.efra = efra;
+ queue.stop = stop;
+ queue.do_update = do_update;
+ queue.progress = progress;
- task_pool = BLI_task_pool_create(task_scheduler, &queue);
- handles = MEM_callocN(sizeof(ProxyThread) * tot_thread,
- "proxy threaded handles");
- for (i = 0; i < tot_thread; i++) {
- ProxyThread *handle = &handles[i];
+ task_pool = BLI_task_pool_create(task_scheduler, &queue);
+ handles = MEM_callocN(sizeof(ProxyThread) * tot_thread, "proxy threaded handles");
+ for (i = 0; i < tot_thread; i++) {
+ ProxyThread *handle = &handles[i];
- handle->clip = clip;
+ handle->clip = clip;
- handle->build_count = build_count;
- handle->build_sizes = build_sizes;
+ handle->build_count = build_count;
+ handle->build_sizes = build_sizes;
- handle->build_undistort_count = build_undistort_count;
- handle->build_undistort_sizes = build_undistort_sizes;
+ handle->build_undistort_count = build_undistort_count;
+ handle->build_undistort_sizes = build_undistort_sizes;
- if (build_undistort_count) {
- handle->distortion = BKE_tracking_distortion_new(&clip->tracking,
- width, height);
- }
+ if (build_undistort_count) {
+ handle->distortion = BKE_tracking_distortion_new(&clip->tracking, width, height);
+ }
- BLI_task_pool_push(task_pool,
- proxy_task_func,
- handle,
- false,
- TASK_PRIORITY_LOW);
- }
+ BLI_task_pool_push(task_pool, proxy_task_func, handle, false, TASK_PRIORITY_LOW);
+ }
- BLI_task_pool_work_and_wait(task_pool);
- BLI_task_pool_free(task_pool);
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
- if (build_undistort_count) {
- for (i = 0; i < tot_thread; i++) {
- ProxyThread *handle = &handles[i];
- BKE_tracking_distortion_free(handle->distortion);
- }
- }
+ if (build_undistort_count) {
+ for (i = 0; i < tot_thread; i++) {
+ ProxyThread *handle = &handles[i];
+ BKE_tracking_distortion_free(handle->distortion);
+ }
+ }
- BLI_spin_end(&queue.spin);
- MEM_freeN(handles);
+ BLI_spin_end(&queue.spin);
+ MEM_freeN(handles);
}
static void proxy_startjob(void *pjv, short *stop, short *do_update, float *progress)
{
- ProxyJob *pj = pjv;
- MovieClip *clip = pj->clip;
-
- short size_flag;
- int build_sizes[4], build_count = 0;
- int build_undistort_sizes[4], build_undistort_count = 0;
-
- size_flag = clip->proxy.build_size_flag;
-
- build_count = proxy_bitflag_to_array(size_flag, build_sizes, 0);
- build_undistort_count = proxy_bitflag_to_array(size_flag, build_undistort_sizes, 1);
-
- if (clip->source == MCLIP_SRC_MOVIE) {
- do_movie_proxy(pjv, build_sizes, build_count, build_undistort_sizes,
- build_undistort_count, stop, do_update, progress);
- }
- else {
- do_sequence_proxy(pjv, build_sizes, build_count, build_undistort_sizes,
- build_undistort_count, stop, do_update, progress);
- }
+ ProxyJob *pj = pjv;
+ MovieClip *clip = pj->clip;
+
+ short size_flag;
+ int build_sizes[4], build_count = 0;
+ int build_undistort_sizes[4], build_undistort_count = 0;
+
+ size_flag = clip->proxy.build_size_flag;
+
+ build_count = proxy_bitflag_to_array(size_flag, build_sizes, 0);
+ build_undistort_count = proxy_bitflag_to_array(size_flag, build_undistort_sizes, 1);
+
+ if (clip->source == MCLIP_SRC_MOVIE) {
+ do_movie_proxy(pjv,
+ build_sizes,
+ build_count,
+ build_undistort_sizes,
+ build_undistort_count,
+ stop,
+ do_update,
+ progress);
+ }
+ else {
+ do_sequence_proxy(pjv,
+ build_sizes,
+ build_count,
+ build_undistort_sizes,
+ build_undistort_count,
+ stop,
+ do_update,
+ progress);
+ }
}
static void proxy_endjob(void *pjv)
{
- ProxyJob *pj = pjv;
+ ProxyJob *pj = pjv;
- if (pj->clip->anim)
- IMB_close_anim_proxies(pj->clip->anim);
+ if (pj->clip->anim)
+ IMB_close_anim_proxies(pj->clip->anim);
- if (pj->index_context)
- IMB_anim_index_rebuild_finish(pj->index_context, pj->stop);
+ if (pj->index_context)
+ IMB_anim_index_rebuild_finish(pj->index_context, pj->stop);
- if (pj->clip->source == MCLIP_SRC_MOVIE) {
- /* Timecode might have changed, so do a full reload to deal with this. */
- BKE_movieclip_reload(pj->main, pj->clip);
- }
- else {
- /* For image sequences we'll preserve original cache. */
- BKE_movieclip_clear_proxy_cache(pj->clip);
- }
+ if (pj->clip->source == MCLIP_SRC_MOVIE) {
+ /* Timecode might have changed, so do a full reload to deal with this. */
+ BKE_movieclip_reload(pj->main, pj->clip);
+ }
+ else {
+ /* For image sequences we'll preserve original cache. */
+ BKE_movieclip_clear_proxy_cache(pj->clip);
+ }
- WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, pj->clip);
+ WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, pj->clip);
}
static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
{
- wmJob *wm_job;
- ProxyJob *pj;
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ wmJob *wm_job;
+ ProxyJob *pj;
+ Scene *scene = CTX_data_scene(C);
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- if ((clip->flag & MCLIP_USE_PROXY) == 0)
- return OPERATOR_CANCELLED;
+ if ((clip->flag & MCLIP_USE_PROXY) == 0)
+ return OPERATOR_CANCELLED;
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Building Proxies",
- WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_BUILD_PROXY);
+ wm_job = WM_jobs_get(CTX_wm_manager(C),
+ CTX_wm_window(C),
+ sa,
+ "Building Proxies",
+ WM_JOB_PROGRESS,
+ WM_JOB_TYPE_CLIP_BUILD_PROXY);
- pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
- pj->scene = scene;
- pj->main = CTX_data_main(C);
- pj->clip = clip;
- pj->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
+ pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
+ pj->scene = scene;
+ pj->main = CTX_data_main(C);
+ pj->clip = clip;
+ pj->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
- if (clip->anim) {
- pj->index_context = IMB_anim_index_rebuild_context(clip->anim, clip->proxy.build_tc_flag,
- clip->proxy.build_size_flag, clip->proxy.quality,
- true, NULL);
- }
+ if (clip->anim) {
+ pj->index_context = IMB_anim_index_rebuild_context(clip->anim,
+ clip->proxy.build_tc_flag,
+ clip->proxy.build_size_flag,
+ clip->proxy.quality,
+ true,
+ NULL);
+ }
- WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
- WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
- WM_jobs_callbacks(wm_job, proxy_startjob, NULL, NULL, proxy_endjob);
+ WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
+ WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
+ WM_jobs_callbacks(wm_job, proxy_startjob, NULL, NULL, proxy_endjob);
- G.is_break = false;
- WM_jobs_start(CTX_wm_manager(C), wm_job);
+ G.is_break = false;
+ WM_jobs_start(CTX_wm_manager(C), wm_job);
- ED_area_tag_redraw(sa);
+ ED_area_tag_redraw(sa);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_rebuild_proxy(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Rebuild Proxy and Timecode Indices";
- ot->idname = "CLIP_OT_rebuild_proxy";
- ot->description = "Rebuild all selected proxies and timecode indices in the background";
+ /* identifiers */
+ ot->name = "Rebuild Proxy and Timecode Indices";
+ ot->idname = "CLIP_OT_rebuild_proxy";
+ ot->description = "Rebuild all selected proxies and timecode indices in the background";
- /* api callbacks */
- ot->exec = clip_rebuild_proxy_exec;
- ot->poll = ED_space_clip_poll;
+ /* api callbacks */
+ ot->exec = clip_rebuild_proxy_exec;
+ ot->poll = ED_space_clip_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
}
/********************** mode set operator *********************/
static int mode_set_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- int mode = RNA_enum_get(op->ptr, "mode");
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ int mode = RNA_enum_get(op->ptr, "mode");
- sc->mode = mode;
+ sc->mode = mode;
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CLIP, NULL);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CLIP, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_mode_set(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Clip Mode";
- ot->description = "Set the clip interaction mode";
- ot->idname = "CLIP_OT_mode_set";
+ /* identifiers */
+ ot->name = "Set Clip Mode";
+ ot->description = "Set the clip interaction mode";
+ ot->idname = "CLIP_OT_mode_set";
- /* api callbacks */
- ot->exec = mode_set_exec;
+ /* api callbacks */
+ ot->exec = mode_set_exec;
- ot->poll = ED_space_clip_poll;
+ ot->poll = ED_space_clip_poll;
- /* properties */
- RNA_def_enum(ot->srna, "mode", rna_enum_clip_editor_mode_items, SC_MODE_TRACKING, "Mode", "");
+ /* properties */
+ RNA_def_enum(ot->srna, "mode", rna_enum_clip_editor_mode_items, SC_MODE_TRACKING, "Mode", "");
}
#ifdef WITH_INPUT_NDOF
@@ -1417,41 +1491,41 @@ void CLIP_OT_mode_set(wmOperatorType *ot)
static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- if (event->type != NDOF_MOTION)
- return OPERATOR_CANCELLED;
- else {
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
- float pan_vec[3];
+ if (event->type != NDOF_MOTION)
+ return OPERATOR_CANCELLED;
+ else {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+ float pan_vec[3];
- const wmNDOFMotionData *ndof = event->customdata;
- const float speed = NDOF_PIXELS_PER_SECOND;
+ const wmNDOFMotionData *ndof = event->customdata;
+ const float speed = NDOF_PIXELS_PER_SECOND;
- WM_event_ndof_pan_get(ndof, pan_vec, true);
+ WM_event_ndof_pan_get(ndof, pan_vec, true);
- mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom);
- pan_vec[2] *= -ndof->dt;
+ mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom);
+ pan_vec[2] *= -ndof->dt;
- sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL);
- sc->xof += pan_vec[0];
- sc->yof += pan_vec[1];
+ sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL);
+ sc->xof += pan_vec[0];
+ sc->yof += pan_vec[1];
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
+ }
}
void CLIP_OT_view_ndof(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "NDOF Pan/Zoom";
- ot->idname = "CLIP_OT_view_ndof";
- ot->description = "Use a 3D mouse device to pan/zoom the view";
+ /* identifiers */
+ ot->name = "NDOF Pan/Zoom";
+ ot->idname = "CLIP_OT_view_ndof";
+ ot->description = "Use a 3D mouse device to pan/zoom the view";
- /* api callbacks */
- ot->invoke = clip_view_ndof_invoke;
- ot->poll = ED_space_clip_view_clip_poll;
+ /* api callbacks */
+ ot->invoke = clip_view_ndof_invoke;
+ ot->poll = ED_space_clip_view_clip_poll;
}
#endif /* WITH_INPUT_NDOF */
@@ -1459,147 +1533,159 @@ void CLIP_OT_view_ndof(wmOperatorType *ot)
static int clip_prefetch_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- /* no running blender, remove handler and pass through */
- if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH))
- return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+ /* no running blender, remove handler and pass through */
+ if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH))
+ return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
- /* running render */
- switch (event->type) {
- case ESCKEY:
- return OPERATOR_RUNNING_MODAL;
- }
+ /* running render */
+ switch (event->type) {
+ case ESCKEY:
+ return OPERATOR_RUNNING_MODAL;
+ }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_PASS_THROUGH;
}
static int clip_prefetch_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(_event))
{
- clip_start_prefetch_job(C);
+ clip_start_prefetch_job(C);
- /* add modal handler for ESC */
- WM_event_add_modal_handler(C, op);
+ /* add modal handler for ESC */
+ WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void CLIP_OT_prefetch(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Prefetch Frames";
- ot->idname = "CLIP_OT_prefetch";
- ot->description = "Prefetch frames from disk for faster playback/tracking";
+ /* identifiers */
+ ot->name = "Prefetch Frames";
+ ot->idname = "CLIP_OT_prefetch";
+ ot->description = "Prefetch frames from disk for faster playback/tracking";
- /* api callbacks */
- ot->poll = ED_space_clip_view_clip_poll;
- ot->invoke = clip_prefetch_invoke;
- ot->modal = clip_prefetch_modal;
+ /* api callbacks */
+ ot->poll = ED_space_clip_view_clip_poll;
+ ot->invoke = clip_prefetch_invoke;
+ ot->modal = clip_prefetch_modal;
}
/********************** Set scene frames *********************/
static int clip_set_scene_frames_exec(bContext *C, wmOperator *UNUSED(op))
{
- MovieClip *clip = CTX_data_edit_movieclip(C);
- Scene *scene = CTX_data_scene(C);
- int clip_length;
+ MovieClip *clip = CTX_data_edit_movieclip(C);
+ Scene *scene = CTX_data_scene(C);
+ int clip_length;
- if (ELEM(NULL, scene, clip))
- return OPERATOR_CANCELLED;
+ if (ELEM(NULL, scene, clip))
+ return OPERATOR_CANCELLED;
- clip_length = BKE_movieclip_get_duration(clip);
+ clip_length = BKE_movieclip_get_duration(clip);
- scene->r.sfra = clip->start_frame;
- scene->r.efra = scene->r.sfra + clip_length - 1;
+ scene->r.sfra = clip->start_frame;
+ scene->r.efra = scene->r.sfra + clip_length - 1;
- scene->r.efra = max_ii(scene->r.sfra, scene->r.efra);
+ scene->r.efra = max_ii(scene->r.sfra, scene->r.efra);
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_scene_frames(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Scene Frames";
- ot->idname = "CLIP_OT_set_scene_frames";
- ot->description = "Set scene's start and end frame to match clip's start frame and length";
+ /* identifiers */
+ ot->name = "Set Scene Frames";
+ ot->idname = "CLIP_OT_set_scene_frames";
+ ot->description = "Set scene's start and end frame to match clip's start frame and length";
- /* api callbacks */
- ot->poll = ED_space_clip_view_clip_poll;
- ot->exec = clip_set_scene_frames_exec;
+ /* api callbacks */
+ ot->poll = ED_space_clip_view_clip_poll;
+ ot->exec = clip_set_scene_frames_exec;
}
/******************** set 3d cursor operator ********************/
static int clip_set_2d_cursor_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sclip = CTX_wm_space_clip(C);
- bool show_cursor = false;
+ SpaceClip *sclip = CTX_wm_space_clip(C);
+ bool show_cursor = false;
- show_cursor |= sclip->mode == SC_MODE_MASKEDIT;
- show_cursor |= sclip->around == V3D_AROUND_CURSOR;
+ show_cursor |= sclip->mode == SC_MODE_MASKEDIT;
+ show_cursor |= sclip->around == V3D_AROUND_CURSOR;
- if (!show_cursor) {
- return OPERATOR_CANCELLED;
- }
+ if (!show_cursor) {
+ return OPERATOR_CANCELLED;
+ }
- RNA_float_get_array(op->ptr, "location", sclip->cursor);
+ RNA_float_get_array(op->ptr, "location", sclip->cursor);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CLIP, NULL);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CLIP, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int clip_set_2d_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- SpaceClip *sclip = CTX_wm_space_clip(C);
- float location[2];
+ ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sclip = CTX_wm_space_clip(C);
+ float location[2];
- ED_clip_mouse_pos(sclip, ar, event->mval, location);
- RNA_float_set_array(op->ptr, "location", location);
+ ED_clip_mouse_pos(sclip, ar, event->mval, location);
+ RNA_float_set_array(op->ptr, "location", location);
- return clip_set_2d_cursor_exec(C, op);
+ return clip_set_2d_cursor_exec(C, op);
}
void CLIP_OT_cursor_set(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set 2D Cursor";
- ot->description = "Set 2D cursor location";
- ot->idname = "CLIP_OT_cursor_set";
+ /* identifiers */
+ ot->name = "Set 2D Cursor";
+ ot->description = "Set 2D cursor location";
+ ot->idname = "CLIP_OT_cursor_set";
- /* api callbacks */
- ot->exec = clip_set_2d_cursor_exec;
- ot->invoke = clip_set_2d_cursor_invoke;
- ot->poll = ED_space_clip_poll;
+ /* api callbacks */
+ ot->exec = clip_set_2d_cursor_exec;
+ ot->invoke = clip_set_2d_cursor_invoke;
+ ot->poll = ED_space_clip_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location",
- "Cursor location in normalized clip coordinates", -10.0f, 10.0f);
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Cursor location in normalized clip coordinates",
+ -10.0f,
+ 10.0f);
}
/********************** macros *********************/
void ED_operatormacros_clip(void)
{
- wmOperatorType *ot;
- wmOperatorTypeMacro *otmacro;
-
- ot = WM_operatortype_append_macro("CLIP_OT_add_marker_move", "Add Marker and Move",
- "Add new marker and move it on movie", OPTYPE_UNDO | OPTYPE_REGISTER);
- WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
- otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
- RNA_struct_idprops_unset(otmacro->ptr, "release_confirm");
-
- ot = WM_operatortype_append_macro("CLIP_OT_add_marker_slide", "Add Marker and Slide",
- "Add new marker and slide it with mouse until mouse button release",
- OPTYPE_UNDO | OPTYPE_REGISTER);
- WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
- otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
- RNA_boolean_set(otmacro->ptr, "release_confirm", true);
+ wmOperatorType *ot;
+ wmOperatorTypeMacro *otmacro;
+
+ ot = WM_operatortype_append_macro("CLIP_OT_add_marker_move",
+ "Add Marker and Move",
+ "Add new marker and move it on movie",
+ OPTYPE_UNDO | OPTYPE_REGISTER);
+ WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
+ otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
+ RNA_struct_idprops_unset(otmacro->ptr, "release_confirm");
+
+ ot = WM_operatortype_append_macro(
+ "CLIP_OT_add_marker_slide",
+ "Add Marker and Slide",
+ "Add new marker and slide it with mouse until mouse button release",
+ OPTYPE_UNDO | OPTYPE_REGISTER);
+ WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
+ otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
+ RNA_boolean_set(otmacro->ptr, "release_confirm", true);
}
diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c
index 3f16982e2c6..acb05e7d542 100644
--- a/source/blender/editors/space_clip/clip_toolbar.c
+++ b/source/blender/editors/space_clip/clip_toolbar.c
@@ -55,118 +55,118 @@
ARegion *ED_clip_has_properties_region(ScrArea *sa)
{
- ARegion *ar, *arnew;
+ ARegion *ar, *arnew;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
- if (ar)
- return ar;
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
+ if (ar)
+ return ar;
- /* add subdiv level; after header */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
+ /* add subdiv level; after header */
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
- /* is error! */
- if (ar == NULL)
- return NULL;
+ /* is error! */
+ if (ar == NULL)
+ return NULL;
- arnew = MEM_callocN(sizeof(ARegion), "clip properties region");
+ arnew = MEM_callocN(sizeof(ARegion), "clip properties region");
- BLI_insertlinkafter(&sa->regionbase, ar, arnew);
- arnew->regiontype = RGN_TYPE_UI;
- arnew->alignment = RGN_ALIGN_RIGHT;
+ BLI_insertlinkafter(&sa->regionbase, ar, arnew);
+ arnew->regiontype = RGN_TYPE_UI;
+ arnew->alignment = RGN_ALIGN_RIGHT;
- arnew->flag = RGN_FLAG_HIDDEN;
+ arnew->flag = RGN_FLAG_HIDDEN;
- return arnew;
+ return arnew;
}
static bool properties_poll(bContext *C)
{
- return (CTX_wm_space_clip(C) != NULL);
+ return (CTX_wm_space_clip(C) != NULL);
}
static int properties_exec(bContext *C, wmOperator *UNUSED(op))
{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = ED_clip_has_properties_region(sa);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = ED_clip_has_properties_region(sa);
- if (ar && ar->alignment != RGN_ALIGN_NONE)
- ED_region_toggle_hidden(C, ar);
+ if (ar && ar->alignment != RGN_ALIGN_NONE)
+ ED_region_toggle_hidden(C, ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_properties(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Toggle Sidebar";
- ot->description = "Toggle the properties region visibility";
- ot->idname = "CLIP_OT_properties";
-
- /* api callbacks */
- ot->exec = properties_exec;
- ot->poll = properties_poll;
+ /* identifiers */
+ ot->name = "Toggle Sidebar";
+ ot->description = "Toggle the properties region visibility";
+ ot->idname = "CLIP_OT_properties";
+
+ /* api callbacks */
+ ot->exec = properties_exec;
+ ot->poll = properties_poll;
}
/************************** tools ******************************/
static ARegion *clip_has_tools_region(ScrArea *sa)
{
- ARegion *ar, *artool = NULL, *arhead;
+ ARegion *ar, *artool = NULL, *arhead;
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_TOOLS)
- artool = ar;
- }
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_TOOLS)
+ artool = ar;
+ }
- /* tool region hide/unhide also hides props */
- if (artool) {
- return artool;
- }
+ /* tool region hide/unhide also hides props */
+ if (artool) {
+ return artool;
+ }
- if (artool == NULL) {
- /* add subdiv level; after header */
- arhead = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
+ if (artool == NULL) {
+ /* add subdiv level; after header */
+ arhead = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
- /* is error! */
- if (arhead == NULL)
- return NULL;
+ /* is error! */
+ if (arhead == NULL)
+ return NULL;
- artool = MEM_callocN(sizeof(ARegion), "clip tools region");
+ artool = MEM_callocN(sizeof(ARegion), "clip tools region");
- BLI_insertlinkafter(&sa->regionbase, arhead, artool);
- artool->regiontype = RGN_TYPE_TOOLS;
- artool->alignment = RGN_ALIGN_LEFT;
+ BLI_insertlinkafter(&sa->regionbase, arhead, artool);
+ artool->regiontype = RGN_TYPE_TOOLS;
+ artool->alignment = RGN_ALIGN_LEFT;
- artool->flag = RGN_FLAG_HIDDEN;
- }
+ artool->flag = RGN_FLAG_HIDDEN;
+ }
- return artool;
+ return artool;
}
static bool tools_poll(bContext *C)
{
- return (CTX_wm_space_clip(C) != NULL);
+ return (CTX_wm_space_clip(C) != NULL);
}
static int tools_exec(bContext *C, wmOperator *UNUSED(op))
{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = clip_has_tools_region(sa);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = clip_has_tools_region(sa);
- if (ar && ar->alignment != RGN_ALIGN_NONE)
- ED_region_toggle_hidden(C, ar);
+ if (ar && ar->alignment != RGN_ALIGN_NONE)
+ ED_region_toggle_hidden(C, ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_tools(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Toggle Toolbar";
- ot->description = "Toggle clip tools panel";
- ot->idname = "CLIP_OT_tools";
-
- /* api callbacks */
- ot->exec = tools_exec;
- ot->poll = tools_poll;
+ /* identifiers */
+ ot->name = "Toggle Toolbar";
+ ot->description = "Toggle clip tools panel";
+ ot->idname = "CLIP_OT_tools";
+
+ /* api callbacks */
+ ot->exec = tools_exec;
+ ot->poll = tools_poll;
}
diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c
index 882cafae5f6..37a28e6189a 100644
--- a/source/blender/editors/space_clip/clip_utils.c
+++ b/source/blender/editors/space_clip/clip_utils.c
@@ -50,245 +50,259 @@
#include "UI_resources.h"
#include "UI_view2d.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
void clip_graph_tracking_values_iterate_track(
- SpaceClip *sc, MovieTrackingTrack *track, void *userdata,
- void (*func)(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, int coord,
- int scene_framenr, float val),
- void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
- void (*segment_end)(void *userdata, int coord))
+ SpaceClip *sc,
+ MovieTrackingTrack *track,
+ void *userdata,
+ void (*func)(void *userdata,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val),
+ void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
+ void (*segment_end)(void *userdata, int coord))
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int width, height, coord;
-
- BKE_movieclip_get_size(clip, &sc->user, &width, &height);
-
- for (coord = 0; coord < 2; coord++) {
- int i, prevfra = track->markers[0].framenr;
- bool open = false;
- float prevval = 0.0f;
-
- for (i = 0; i < track->markersnr; i++) {
- MovieTrackingMarker *marker = &track->markers[i];
- float val;
-
- if (marker->flag & MARKER_DISABLED) {
- if (open) {
- if (segment_end)
- segment_end(userdata, coord);
-
- open = false;
- }
-
- continue;
- }
-
- if (!open) {
- if (segment_start) {
- if ((i + 1) == track->markersnr) {
- segment_start(userdata, track, coord, true);
- }
- else {
- segment_start(userdata, track, coord, (track->markers[i + 1].flag & MARKER_DISABLED));
- }
- }
-
- open = true;
- prevval = marker->pos[coord];
- }
-
- /* value is a pixels per frame speed */
- val = (marker->pos[coord] - prevval) * ((coord == 0) ? (width) : (height));
- val /= marker->framenr - prevfra;
-
- if (func) {
- int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
-
- func(userdata, track, marker, coord, scene_framenr, val);
- }
-
- prevval = marker->pos[coord];
- prevfra = marker->framenr;
- }
-
- if (open) {
- if (segment_end)
- segment_end(userdata, coord);
- }
- }
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int width, height, coord;
+
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+ for (coord = 0; coord < 2; coord++) {
+ int i, prevfra = track->markers[0].framenr;
+ bool open = false;
+ float prevval = 0.0f;
+
+ for (i = 0; i < track->markersnr; i++) {
+ MovieTrackingMarker *marker = &track->markers[i];
+ float val;
+
+ if (marker->flag & MARKER_DISABLED) {
+ if (open) {
+ if (segment_end)
+ segment_end(userdata, coord);
+
+ open = false;
+ }
+
+ continue;
+ }
+
+ if (!open) {
+ if (segment_start) {
+ if ((i + 1) == track->markersnr) {
+ segment_start(userdata, track, coord, true);
+ }
+ else {
+ segment_start(userdata, track, coord, (track->markers[i + 1].flag & MARKER_DISABLED));
+ }
+ }
+
+ open = true;
+ prevval = marker->pos[coord];
+ }
+
+ /* value is a pixels per frame speed */
+ val = (marker->pos[coord] - prevval) * ((coord == 0) ? (width) : (height));
+ val /= marker->framenr - prevfra;
+
+ if (func) {
+ int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
+
+ func(userdata, track, marker, coord, scene_framenr, val);
+ }
+
+ prevval = marker->pos[coord];
+ prevfra = marker->framenr;
+ }
+
+ if (open) {
+ if (segment_end)
+ segment_end(userdata, coord);
+ }
+ }
}
void clip_graph_tracking_values_iterate(
- SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
- void (*func)(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
- void (*segment_end)(void *userdata, int coord))
+ SpaceClip *sc,
+ bool selected_only,
+ bool include_hidden,
+ void *userdata,
+ void (*func)(void *userdata,
+ MovieTrackingTrack *track,
+ MovieTrackingMarker *marker,
+ int coord,
+ int scene_framenr,
+ float val),
+ void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
+ void (*segment_end)(void *userdata, int coord))
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *track;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingTrack *track;
- for (track = tracksbase->first; track; track = track->next) {
- if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
- continue;
+ for (track = tracksbase->first; track; track = track->next) {
+ if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
+ continue;
- if (selected_only && !TRACK_SELECTED(track))
- continue;
+ if (selected_only && !TRACK_SELECTED(track))
+ continue;
- clip_graph_tracking_values_iterate_track(sc, track, userdata, func, segment_start, segment_end);
- }
+ clip_graph_tracking_values_iterate_track(
+ sc, track, userdata, func, segment_start, segment_end);
+ }
}
-void clip_graph_tracking_iterate(SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
+void clip_graph_tracking_iterate(SpaceClip *sc,
+ bool selected_only,
+ bool include_hidden,
+ void *userdata,
void (*func)(void *userdata, MovieTrackingMarker *marker))
{
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *track;
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingTrack *track;
- for (track = tracksbase->first; track; track = track->next) {
- int i;
+ for (track = tracksbase->first; track; track = track->next) {
+ int i;
- if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
- continue;
+ if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
+ continue;
- if (selected_only && !TRACK_SELECTED(track))
- continue;
+ if (selected_only && !TRACK_SELECTED(track))
+ continue;
- for (i = 0; i < track->markersnr; i++) {
- MovieTrackingMarker *marker = &track->markers[i];
+ for (i = 0; i < track->markersnr; i++) {
+ MovieTrackingMarker *marker = &track->markers[i];
- if (marker->flag & MARKER_DISABLED)
- continue;
+ if (marker->flag & MARKER_DISABLED)
+ continue;
- if (func)
- func(userdata, marker);
- }
- }
+ if (func)
+ func(userdata, marker);
+ }
+ }
}
void clip_delete_track(bContext *C, MovieClip *clip, MovieTrackingTrack *track)
{
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- bool has_bundle = false;
- const bool used_for_stabilization =
- (track->flag & (TRACK_USE_2D_STAB | TRACK_USE_2D_STAB_ROT)) != 0;
- if (track == act_track) {
- tracking->act_track = NULL;
- }
- /* Handle reconstruction display in 3d viewport. */
- if (track->flag & TRACK_HAS_BUNDLE) {
- has_bundle = true;
- }
- /* Make sure no plane will use freed track */
- BKE_tracking_plane_tracks_remove_point_track(tracking, track);
- /* Delete f-curves associated with the track (such as weight, i.e.) */
- /* Escaped object name, escaped track name, rest of the path. */
- char rna_path[MAX_NAME * 4 + 64];
- BKE_tracking_get_rna_path_for_track(tracking,
- track,
- rna_path, sizeof(rna_path));
- if (BKE_animdata_fix_paths_remove(&clip->id, rna_path)) {
- DEG_relations_tag_update(CTX_data_main(C));
- }
- /* Delete track itself. */
- BKE_tracking_track_free(track);
- BLI_freelinkN(tracksbase, track);
- /* Send notifiers. */
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- if (used_for_stabilization) {
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
- /* Inform dependency graph. */
- DEG_id_tag_update(&clip->id, 0);
- if (has_bundle) {
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- }
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ bool has_bundle = false;
+ const bool used_for_stabilization = (track->flag &
+ (TRACK_USE_2D_STAB | TRACK_USE_2D_STAB_ROT)) != 0;
+ if (track == act_track) {
+ tracking->act_track = NULL;
+ }
+ /* Handle reconstruction display in 3d viewport. */
+ if (track->flag & TRACK_HAS_BUNDLE) {
+ has_bundle = true;
+ }
+ /* Make sure no plane will use freed track */
+ BKE_tracking_plane_tracks_remove_point_track(tracking, track);
+ /* Delete f-curves associated with the track (such as weight, i.e.) */
+ /* Escaped object name, escaped track name, rest of the path. */
+ char rna_path[MAX_NAME * 4 + 64];
+ BKE_tracking_get_rna_path_for_track(tracking, track, rna_path, sizeof(rna_path));
+ if (BKE_animdata_fix_paths_remove(&clip->id, rna_path)) {
+ DEG_relations_tag_update(CTX_data_main(C));
+ }
+ /* Delete track itself. */
+ BKE_tracking_track_free(track);
+ BLI_freelinkN(tracksbase, track);
+ /* Send notifiers. */
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ if (used_for_stabilization) {
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+ /* Inform dependency graph. */
+ DEG_id_tag_update(&clip->id, 0);
+ if (has_bundle) {
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ }
}
-void clip_delete_marker(bContext *C, MovieClip *clip, MovieTrackingTrack *track,
+void clip_delete_marker(bContext *C,
+ MovieClip *clip,
+ MovieTrackingTrack *track,
MovieTrackingMarker *marker)
{
- if (track->markersnr == 1) {
- clip_delete_track(C, clip, track);
- }
- else {
- BKE_tracking_marker_delete(track, marker->framenr);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- }
+ if (track->markersnr == 1) {
+ clip_delete_track(C, clip, track);
+ }
+ else {
+ BKE_tracking_marker_delete(track, marker->framenr);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ }
}
-void clip_delete_plane_track(bContext *C,
- MovieClip *clip,
- MovieTrackingPlaneTrack *plane_track)
+void clip_delete_plane_track(bContext *C, MovieClip *clip, MovieTrackingPlaneTrack *plane_track)
{
- MovieTracking *tracking = &clip->tracking;
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- /* Delete f-curves associated with the track (such as weight, i.e.) */
- /* Escaped object name, escaped track name, rest of the path. */
- char rna_path[MAX_NAME * 4 + 64];
- BKE_tracking_get_rna_path_for_plane_track(tracking,
- plane_track,
- rna_path, sizeof(rna_path));
- if (BKE_animdata_fix_paths_remove(&clip->id, rna_path)) {
- DEG_relations_tag_update(CTX_data_main(C));
- }
- /* Delete the plane track itself. */
- BKE_tracking_plane_track_free(plane_track);
- BLI_freelinkN(plane_tracks_base, plane_track);
- /* TODO(sergey): Any notifiers to be sent here? */
- (void) C;
- /* Inform dependency graph. */
- DEG_id_tag_update(&clip->id, 0);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ /* Delete f-curves associated with the track (such as weight, i.e.) */
+ /* Escaped object name, escaped track name, rest of the path. */
+ char rna_path[MAX_NAME * 4 + 64];
+ BKE_tracking_get_rna_path_for_plane_track(tracking, plane_track, rna_path, sizeof(rna_path));
+ if (BKE_animdata_fix_paths_remove(&clip->id, rna_path)) {
+ DEG_relations_tag_update(CTX_data_main(C));
+ }
+ /* Delete the plane track itself. */
+ BKE_tracking_plane_track_free(plane_track);
+ BLI_freelinkN(plane_tracks_base, plane_track);
+ /* TODO(sergey): Any notifiers to be sent here? */
+ (void)C;
+ /* Inform dependency graph. */
+ DEG_id_tag_update(&clip->id, 0);
}
void clip_view_center_to_point(SpaceClip *sc, float x, float y)
{
- int width, height;
- float aspx, aspy;
+ int width, height;
+ float aspx, aspy;
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
- sc->xof = (x - 0.5f) * width * aspx;
- sc->yof = (y - 0.5f) * height * aspy;
+ sc->xof = (x - 0.5f) * width * aspx;
+ sc->yof = (y - 0.5f) * height * aspy;
}
void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
{
- UI_view2d_view_ortho(v2d);
+ UI_view2d_view_ortho(v2d);
- /* currently clip editor supposes that editing clip length is equal to scene frame range */
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
- GPU_blend(true);
+ /* currently clip editor supposes that editing clip length is equal to scene frame range */
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+ GPU_blend(true);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
- immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
- immRectf(pos, (float)EFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
+ immRectf(pos, (float)EFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
- GPU_blend(false);
+ GPU_blend(false);
- immUniformThemeColorShade(TH_BACK, -60);
+ immUniformThemeColorShade(TH_BACK, -60);
- /* thin lines where the actual frames are */
- GPU_line_width(1.0f);
+ /* thin lines where the actual frames are */
+ GPU_line_width(1.0f);
- immBegin(GPU_PRIM_LINES, 4);
- immVertex2f(pos, (float)SFRA, v2d->cur.ymin);
- immVertex2f(pos, (float)SFRA, v2d->cur.ymax);
- immVertex2f(pos, (float)EFRA, v2d->cur.ymin);
- immVertex2f(pos, (float)EFRA, v2d->cur.ymax);
- immEnd();
+ immBegin(GPU_PRIM_LINES, 4);
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymax);
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymax);
+ immEnd();
- immUnbindProgram();
+ immUnbindProgram();
}
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index b84a5fc90ed..7c62af80a0f 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -27,7 +27,7 @@
#include "DNA_scene_types.h"
#include "DNA_mask_types.h"
#include "DNA_movieclip_types.h"
-#include "DNA_view3d_types.h" /* for pivot point */
+#include "DNA_view3d_types.h" /* for pivot point */
#include "MEM_guardedalloc.h"
@@ -50,7 +50,7 @@
#include "ED_select_utils.h"
#include "ED_clip.h"
#include "ED_transform.h"
-#include "ED_uvedit.h" /* just for ED_image_draw_cursor */
+#include "ED_uvedit.h" /* just for ED_image_draw_cursor */
#include "IMB_imbuf.h"
@@ -67,725 +67,730 @@
#include "RNA_access.h"
+#include "clip_intern.h" /* own include */
-#include "clip_intern.h" /* own include */
-
-static void init_preview_region(const Scene *scene, const ScrArea *sa, const SpaceClip *sc, ARegion *ar)
+static void init_preview_region(const Scene *scene,
+ const ScrArea *sa,
+ const SpaceClip *sc,
+ ARegion *ar)
{
- ar->regiontype = RGN_TYPE_PREVIEW;
- ar->alignment = RGN_ALIGN_TOP;
- ar->flag |= RGN_FLAG_HIDDEN;
-
- if (sc->view == SC_VIEW_DOPESHEET) {
- ar->v2d.tot.xmin = -10.0f;
- ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
- ar->v2d.tot.xmax = (float)(sa->winx);
- ar->v2d.tot.ymax = 0.0f;
-
- ar->v2d.cur = ar->v2d.tot;
-
- ar->v2d.min[0] = 0.0f;
- ar->v2d.min[1] = 0.0f;
-
- ar->v2d.max[0] = MAXFRAMEF;
- ar->v2d.max[1] = FLT_MAX;
-
- ar->v2d.minzoom = 0.01f;
- ar->v2d.maxzoom = 50;
- ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
- ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
- ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
- ar->v2d.keepofs = V2D_KEEPOFS_Y;
- ar->v2d.align = V2D_ALIGN_NO_POS_Y;
- ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
- }
- else {
- ar->v2d.tot.xmin = 0.0f;
- ar->v2d.tot.ymin = -10.0f;
- ar->v2d.tot.xmax = (float)scene->r.efra;
- ar->v2d.tot.ymax = 10.0f;
-
- ar->v2d.cur = ar->v2d.tot;
-
- ar->v2d.min[0] = FLT_MIN;
- ar->v2d.min[1] = FLT_MIN;
-
- ar->v2d.max[0] = MAXFRAMEF;
- ar->v2d.max[1] = FLT_MAX;
-
- ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
- ar->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_SCALE_VERTICAL);
-
- ar->v2d.minzoom = 0.0f;
- ar->v2d.maxzoom = 0.0f;
- ar->v2d.keepzoom = 0;
- ar->v2d.keepofs = 0;
- ar->v2d.align = 0;
- ar->v2d.flag = 0;
-
- ar->v2d.keeptot = 0;
- }
+ ar->regiontype = RGN_TYPE_PREVIEW;
+ ar->alignment = RGN_ALIGN_TOP;
+ ar->flag |= RGN_FLAG_HIDDEN;
+
+ if (sc->view == SC_VIEW_DOPESHEET) {
+ ar->v2d.tot.xmin = -10.0f;
+ ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
+ ar->v2d.tot.xmax = (float)(sa->winx);
+ ar->v2d.tot.ymax = 0.0f;
+
+ ar->v2d.cur = ar->v2d.tot;
+
+ ar->v2d.min[0] = 0.0f;
+ ar->v2d.min[1] = 0.0f;
+
+ ar->v2d.max[0] = MAXFRAMEF;
+ ar->v2d.max[1] = FLT_MAX;
+
+ ar->v2d.minzoom = 0.01f;
+ ar->v2d.maxzoom = 50;
+ ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
+ ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
+ ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
+ ar->v2d.keepofs = V2D_KEEPOFS_Y;
+ ar->v2d.align = V2D_ALIGN_NO_POS_Y;
+ ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
+ }
+ else {
+ ar->v2d.tot.xmin = 0.0f;
+ ar->v2d.tot.ymin = -10.0f;
+ ar->v2d.tot.xmax = (float)scene->r.efra;
+ ar->v2d.tot.ymax = 10.0f;
+
+ ar->v2d.cur = ar->v2d.tot;
+
+ ar->v2d.min[0] = FLT_MIN;
+ ar->v2d.min[1] = FLT_MIN;
+
+ ar->v2d.max[0] = MAXFRAMEF;
+ ar->v2d.max[1] = FLT_MAX;
+
+ ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
+ ar->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_SCALE_VERTICAL);
+
+ ar->v2d.minzoom = 0.0f;
+ ar->v2d.maxzoom = 0.0f;
+ ar->v2d.keepzoom = 0;
+ ar->v2d.keepofs = 0;
+ ar->v2d.align = 0;
+ ar->v2d.flag = 0;
+
+ ar->v2d.keeptot = 0;
+ }
}
static void reinit_preview_region(const bContext *C, ARegion *ar)
{
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
-
- if (sc->view == SC_VIEW_DOPESHEET) {
- if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0)
- init_preview_region(scene, sa, sc, ar);
- }
- else {
- if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL)
- init_preview_region(scene, sa, sc, ar);
- }
+ Scene *scene = CTX_data_scene(C);
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+
+ if (sc->view == SC_VIEW_DOPESHEET) {
+ if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0)
+ init_preview_region(scene, sa, sc, ar);
+ }
+ else {
+ if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL)
+ init_preview_region(scene, sa, sc, ar);
+ }
}
static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa)
{
- ARegion *ar, *arnew;
+ ARegion *ar, *arnew;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
- if (ar)
- return ar;
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
+ if (ar)
+ return ar;
- /* add subdiv level; after header */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+ /* add subdiv level; after header */
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
- /* is error! */
- if (ar == NULL)
- return NULL;
+ /* is error! */
+ if (ar == NULL)
+ return NULL;
- arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
+ arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
- BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
- init_preview_region(CTX_data_scene(C), sa, CTX_wm_space_clip(C), arnew);
+ BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
+ init_preview_region(CTX_data_scene(C), sa, CTX_wm_space_clip(C), arnew);
- return arnew;
+ return arnew;
}
static ARegion *ED_clip_has_channels_region(ScrArea *sa)
{
- ARegion *ar, *arnew;
+ ARegion *ar, *arnew;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
- if (ar)
- return ar;
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
+ if (ar)
+ return ar;
- /* add subdiv level; after header */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
+ /* add subdiv level; after header */
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
- /* is error! */
- if (ar == NULL)
- return NULL;
+ /* is error! */
+ if (ar == NULL)
+ return NULL;
- arnew = MEM_callocN(sizeof(ARegion), "clip channels region");
+ arnew = MEM_callocN(sizeof(ARegion), "clip channels region");
- BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
- arnew->regiontype = RGN_TYPE_CHANNELS;
- arnew->alignment = RGN_ALIGN_LEFT;
+ BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
+ arnew->regiontype = RGN_TYPE_CHANNELS;
+ arnew->alignment = RGN_ALIGN_LEFT;
- arnew->v2d.scroll = V2D_SCROLL_BOTTOM;
- arnew->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
+ arnew->v2d.scroll = V2D_SCROLL_BOTTOM;
+ arnew->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
- return arnew;
+ return arnew;
}
static void clip_scopes_tag_refresh(ScrArea *sa)
{
- SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
- ARegion *ar;
+ SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
+ ARegion *ar;
- if (sc->mode != SC_MODE_TRACKING)
- return;
+ if (sc->mode != SC_MODE_TRACKING)
+ return;
- /* only while properties are visible */
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
- return;
- }
+ /* only while properties are visible */
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
+ return;
+ }
- sc->scopes.ok = false;
+ sc->scopes.ok = false;
}
static void clip_scopes_check_gpencil_change(ScrArea *sa)
{
- SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
+ SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
- if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
- clip_scopes_tag_refresh(sa);
- }
+ if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
+ clip_scopes_tag_refresh(sa);
+ }
}
static void clip_area_sync_frame_from_scene(ScrArea *sa, Scene *scene)
{
- SpaceClip *space_clip = (SpaceClip *)sa->spacedata.first;
- BKE_movieclip_user_set_frame(&space_clip->user, scene->r.cfra);
+ SpaceClip *space_clip = (SpaceClip *)sa->spacedata.first;
+ BKE_movieclip_user_set_frame(&space_clip->user, scene->r.cfra);
}
/* ******************** default callbacks for clip space ***************** */
static SpaceLink *clip_new(const ScrArea *sa, const Scene *scene)
{
- ARegion *ar;
- SpaceClip *sc;
+ ARegion *ar;
+ SpaceClip *sc;
- sc = MEM_callocN(sizeof(SpaceClip), "initclip");
- sc->spacetype = SPACE_CLIP;
- sc->flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH |
- SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION;
- sc->zoom = 1.0f;
- sc->path_length = 20;
- sc->scopes.track_preview_height = 120;
- sc->around = V3D_AROUND_LOCAL_ORIGINS;
+ sc = MEM_callocN(sizeof(SpaceClip), "initclip");
+ sc->spacetype = SPACE_CLIP;
+ sc->flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH | SC_SHOW_GRAPH_TRACKS_MOTION |
+ SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION;
+ sc->zoom = 1.0f;
+ sc->path_length = 20;
+ sc->scopes.track_preview_height = 120;
+ sc->around = V3D_AROUND_LOCAL_ORIGINS;
- /* header */
- ar = MEM_callocN(sizeof(ARegion), "header for clip");
+ /* header */
+ ar = MEM_callocN(sizeof(ARegion), "header for clip");
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_HEADER;
- ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
+ BLI_addtail(&sc->regionbase, ar);
+ ar->regiontype = RGN_TYPE_HEADER;
+ ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
- /* tools view */
- ar = MEM_callocN(sizeof(ARegion), "tools for clip");
+ /* tools view */
+ ar = MEM_callocN(sizeof(ARegion), "tools for clip");
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_TOOLS;
- ar->alignment = RGN_ALIGN_LEFT;
+ BLI_addtail(&sc->regionbase, ar);
+ ar->regiontype = RGN_TYPE_TOOLS;
+ ar->alignment = RGN_ALIGN_LEFT;
- /* properties view */
- ar = MEM_callocN(sizeof(ARegion), "properties for clip");
+ /* properties view */
+ ar = MEM_callocN(sizeof(ARegion), "properties for clip");
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_UI;
- ar->alignment = RGN_ALIGN_RIGHT;
+ BLI_addtail(&sc->regionbase, ar);
+ ar->regiontype = RGN_TYPE_UI;
+ ar->alignment = RGN_ALIGN_RIGHT;
- /* channels view */
- ar = MEM_callocN(sizeof(ARegion), "channels for clip");
+ /* channels view */
+ ar = MEM_callocN(sizeof(ARegion), "channels for clip");
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_CHANNELS;
- ar->alignment = RGN_ALIGN_LEFT;
+ BLI_addtail(&sc->regionbase, ar);
+ ar->regiontype = RGN_TYPE_CHANNELS;
+ ar->alignment = RGN_ALIGN_LEFT;
- ar->v2d.scroll = V2D_SCROLL_BOTTOM;
- ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
+ ar->v2d.scroll = V2D_SCROLL_BOTTOM;
+ ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
- /* preview view */
- ar = MEM_callocN(sizeof(ARegion), "preview for clip");
+ /* preview view */
+ ar = MEM_callocN(sizeof(ARegion), "preview for clip");
- BLI_addtail(&sc->regionbase, ar);
- init_preview_region(scene, sa, sc, ar);
+ BLI_addtail(&sc->regionbase, ar);
+ init_preview_region(scene, sa, sc, ar);
- /* main region */
- ar = MEM_callocN(sizeof(ARegion), "main region for clip");
+ /* main region */
+ ar = MEM_callocN(sizeof(ARegion), "main region for clip");
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_WINDOW;
+ BLI_addtail(&sc->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
- return (SpaceLink *) sc;
+ return (SpaceLink *)sc;
}
/* not spacelink itself */
static void clip_free(SpaceLink *sl)
{
- SpaceClip *sc = (SpaceClip *) sl;
+ SpaceClip *sc = (SpaceClip *)sl;
- sc->clip = NULL;
+ sc->clip = NULL;
- if (sc->scopes.track_preview)
- IMB_freeImBuf(sc->scopes.track_preview);
+ if (sc->scopes.track_preview)
+ IMB_freeImBuf(sc->scopes.track_preview);
- if (sc->scopes.track_search)
- IMB_freeImBuf(sc->scopes.track_search);
+ if (sc->scopes.track_search)
+ IMB_freeImBuf(sc->scopes.track_search);
}
/* spacetype; init callback */
static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
{
- ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
+ ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
- /* add drop boxes */
- WM_event_add_dropbox_handler(&sa->handlers, lb);
+ /* add drop boxes */
+ WM_event_add_dropbox_handler(&sa->handlers, lb);
}
static SpaceLink *clip_duplicate(SpaceLink *sl)
{
- SpaceClip *scn = MEM_dupallocN(sl);
+ SpaceClip *scn = MEM_dupallocN(sl);
- /* clear or remove stuff from old */
- scn->scopes.track_search = NULL;
- scn->scopes.track_preview = NULL;
- scn->scopes.ok = false;
+ /* clear or remove stuff from old */
+ scn->scopes.track_search = NULL;
+ scn->scopes.track_preview = NULL;
+ scn->scopes.ok = false;
- return (SpaceLink *)scn;
+ return (SpaceLink *)scn;
}
static void clip_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *wmn, Scene *scene)
{
- /* context changes */
- switch (wmn->category) {
- case NC_SCENE:
- switch (wmn->data) {
- case ND_FRAME:
- clip_scopes_tag_refresh(sa);
- ATTR_FALLTHROUGH;
-
- case ND_FRAME_RANGE:
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- case NC_MOVIECLIP:
- switch (wmn->data) {
- case ND_DISPLAY:
- case ND_SELECT:
- clip_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- }
- switch (wmn->action) {
- case NA_REMOVED:
- case NA_EDITED:
- case NA_EVALUATED:
- /* fall-through */
-
- case NA_SELECTED:
- clip_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- case NC_MASK:
- switch (wmn->data) {
- case ND_SELECT:
- case ND_DATA:
- case ND_DRAW:
- ED_area_tag_redraw(sa);
- break;
- }
- switch (wmn->action) {
- case NA_SELECTED:
- ED_area_tag_redraw(sa);
- break;
- case NA_EDITED:
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- case NC_GEOM:
- switch (wmn->data) {
- case ND_SELECT:
- clip_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- case NC_SCREEN:
- switch (wmn->data) {
- case ND_ANIMPLAY:
- ED_area_tag_redraw(sa);
- break;
- case ND_LAYOUTSET:
- clip_area_sync_frame_from_scene(sa, scene);
- break;
- }
- break;
- case NC_SPACE:
- if (wmn->data == ND_SPACE_CLIP) {
- clip_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- }
- break;
- case NC_GPENCIL:
- if (wmn->action == NA_EDITED) {
- clip_scopes_check_gpencil_change(sa);
- ED_area_tag_redraw(sa);
- }
- else if (wmn->data & ND_GPENCIL_EDITMODE) {
- ED_area_tag_redraw(sa);
- }
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SCENE:
+ switch (wmn->data) {
+ case ND_FRAME:
+ clip_scopes_tag_refresh(sa);
+ ATTR_FALLTHROUGH;
+
+ case ND_FRAME_RANGE:
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ case NC_MOVIECLIP:
+ switch (wmn->data) {
+ case ND_DISPLAY:
+ case ND_SELECT:
+ clip_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ switch (wmn->action) {
+ case NA_REMOVED:
+ case NA_EDITED:
+ case NA_EVALUATED:
+ /* fall-through */
+
+ case NA_SELECTED:
+ clip_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ case NC_MASK:
+ switch (wmn->data) {
+ case ND_SELECT:
+ case ND_DATA:
+ case ND_DRAW:
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ switch (wmn->action) {
+ case NA_SELECTED:
+ ED_area_tag_redraw(sa);
+ break;
+ case NA_EDITED:
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ case NC_GEOM:
+ switch (wmn->data) {
+ case ND_SELECT:
+ clip_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ case NC_SCREEN:
+ switch (wmn->data) {
+ case ND_ANIMPLAY:
+ ED_area_tag_redraw(sa);
+ break;
+ case ND_LAYOUTSET:
+ clip_area_sync_frame_from_scene(sa, scene);
+ break;
+ }
+ break;
+ case NC_SPACE:
+ if (wmn->data == ND_SPACE_CLIP) {
+ clip_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ }
+ break;
+ case NC_GPENCIL:
+ if (wmn->action == NA_EDITED) {
+ clip_scopes_check_gpencil_change(sa);
+ ED_area_tag_redraw(sa);
+ }
+ else if (wmn->data & ND_GPENCIL_EDITMODE) {
+ ED_area_tag_redraw(sa);
+ }
+ break;
+ }
}
static void clip_operatortypes(void)
{
- /* ** clip_ops.c ** */
- WM_operatortype_append(CLIP_OT_open);
- WM_operatortype_append(CLIP_OT_reload);
- WM_operatortype_append(CLIP_OT_view_pan);
- WM_operatortype_append(CLIP_OT_view_zoom);
- WM_operatortype_append(CLIP_OT_view_zoom_in);
- WM_operatortype_append(CLIP_OT_view_zoom_out);
- WM_operatortype_append(CLIP_OT_view_zoom_ratio);
- WM_operatortype_append(CLIP_OT_view_all);
- WM_operatortype_append(CLIP_OT_view_selected);
- WM_operatortype_append(CLIP_OT_change_frame);
- WM_operatortype_append(CLIP_OT_rebuild_proxy);
- WM_operatortype_append(CLIP_OT_mode_set);
+ /* ** clip_ops.c ** */
+ WM_operatortype_append(CLIP_OT_open);
+ WM_operatortype_append(CLIP_OT_reload);
+ WM_operatortype_append(CLIP_OT_view_pan);
+ WM_operatortype_append(CLIP_OT_view_zoom);
+ WM_operatortype_append(CLIP_OT_view_zoom_in);
+ WM_operatortype_append(CLIP_OT_view_zoom_out);
+ WM_operatortype_append(CLIP_OT_view_zoom_ratio);
+ WM_operatortype_append(CLIP_OT_view_all);
+ WM_operatortype_append(CLIP_OT_view_selected);
+ WM_operatortype_append(CLIP_OT_change_frame);
+ WM_operatortype_append(CLIP_OT_rebuild_proxy);
+ WM_operatortype_append(CLIP_OT_mode_set);
#ifdef WITH_INPUT_NDOF
- WM_operatortype_append(CLIP_OT_view_ndof);
+ WM_operatortype_append(CLIP_OT_view_ndof);
#endif
- WM_operatortype_append(CLIP_OT_prefetch);
- WM_operatortype_append(CLIP_OT_set_scene_frames);
- WM_operatortype_append(CLIP_OT_cursor_set);
-
- /* ** clip_toolbar.c ** */
- WM_operatortype_append(CLIP_OT_tools);
- WM_operatortype_append(CLIP_OT_properties);
+ WM_operatortype_append(CLIP_OT_prefetch);
+ WM_operatortype_append(CLIP_OT_set_scene_frames);
+ WM_operatortype_append(CLIP_OT_cursor_set);
+
+ /* ** clip_toolbar.c ** */
+ WM_operatortype_append(CLIP_OT_tools);
+ WM_operatortype_append(CLIP_OT_properties);
- /* ** tracking_ops.c ** */
+ /* ** tracking_ops.c ** */
- /* navigation */
- WM_operatortype_append(CLIP_OT_frame_jump);
+ /* navigation */
+ WM_operatortype_append(CLIP_OT_frame_jump);
- /* set optical center to frame center */
- WM_operatortype_append(CLIP_OT_set_center_principal);
+ /* set optical center to frame center */
+ WM_operatortype_append(CLIP_OT_set_center_principal);
- /* selection */
- WM_operatortype_append(CLIP_OT_select);
- WM_operatortype_append(CLIP_OT_select_all);
- WM_operatortype_append(CLIP_OT_select_box);
- WM_operatortype_append(CLIP_OT_select_lasso);
- WM_operatortype_append(CLIP_OT_select_circle);
- WM_operatortype_append(CLIP_OT_select_grouped);
+ /* selection */
+ WM_operatortype_append(CLIP_OT_select);
+ WM_operatortype_append(CLIP_OT_select_all);
+ WM_operatortype_append(CLIP_OT_select_box);
+ WM_operatortype_append(CLIP_OT_select_lasso);
+ WM_operatortype_append(CLIP_OT_select_circle);
+ WM_operatortype_append(CLIP_OT_select_grouped);
- /* markers */
- WM_operatortype_append(CLIP_OT_add_marker);
- WM_operatortype_append(CLIP_OT_add_marker_at_click);
- WM_operatortype_append(CLIP_OT_slide_marker);
- WM_operatortype_append(CLIP_OT_delete_track);
- WM_operatortype_append(CLIP_OT_delete_marker);
+ /* markers */
+ WM_operatortype_append(CLIP_OT_add_marker);
+ WM_operatortype_append(CLIP_OT_add_marker_at_click);
+ WM_operatortype_append(CLIP_OT_slide_marker);
+ WM_operatortype_append(CLIP_OT_delete_track);
+ WM_operatortype_append(CLIP_OT_delete_marker);
- /* track */
- WM_operatortype_append(CLIP_OT_track_markers);
- WM_operatortype_append(CLIP_OT_refine_markers);
+ /* track */
+ WM_operatortype_append(CLIP_OT_track_markers);
+ WM_operatortype_append(CLIP_OT_refine_markers);
- /* solving */
- WM_operatortype_append(CLIP_OT_solve_camera);
- WM_operatortype_append(CLIP_OT_clear_solution);
+ /* solving */
+ WM_operatortype_append(CLIP_OT_solve_camera);
+ WM_operatortype_append(CLIP_OT_clear_solution);
- WM_operatortype_append(CLIP_OT_disable_markers);
- WM_operatortype_append(CLIP_OT_hide_tracks);
- WM_operatortype_append(CLIP_OT_hide_tracks_clear);
- WM_operatortype_append(CLIP_OT_lock_tracks);
+ WM_operatortype_append(CLIP_OT_disable_markers);
+ WM_operatortype_append(CLIP_OT_hide_tracks);
+ WM_operatortype_append(CLIP_OT_hide_tracks_clear);
+ WM_operatortype_append(CLIP_OT_lock_tracks);
- WM_operatortype_append(CLIP_OT_set_solver_keyframe);
+ WM_operatortype_append(CLIP_OT_set_solver_keyframe);
- /* orientation */
- WM_operatortype_append(CLIP_OT_set_origin);
- WM_operatortype_append(CLIP_OT_set_plane);
- WM_operatortype_append(CLIP_OT_set_axis);
- WM_operatortype_append(CLIP_OT_set_scale);
- WM_operatortype_append(CLIP_OT_set_solution_scale);
- WM_operatortype_append(CLIP_OT_apply_solution_scale);
+ /* orientation */
+ WM_operatortype_append(CLIP_OT_set_origin);
+ WM_operatortype_append(CLIP_OT_set_plane);
+ WM_operatortype_append(CLIP_OT_set_axis);
+ WM_operatortype_append(CLIP_OT_set_scale);
+ WM_operatortype_append(CLIP_OT_set_solution_scale);
+ WM_operatortype_append(CLIP_OT_apply_solution_scale);
- /* detect */
- WM_operatortype_append(CLIP_OT_detect_features);
+ /* detect */
+ WM_operatortype_append(CLIP_OT_detect_features);
- /* stabilization */
- WM_operatortype_append(CLIP_OT_stabilize_2d_add);
- WM_operatortype_append(CLIP_OT_stabilize_2d_remove);
- WM_operatortype_append(CLIP_OT_stabilize_2d_select);
- WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_add);
- WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_remove);
- WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_select);
+ /* stabilization */
+ WM_operatortype_append(CLIP_OT_stabilize_2d_add);
+ WM_operatortype_append(CLIP_OT_stabilize_2d_remove);
+ WM_operatortype_append(CLIP_OT_stabilize_2d_select);
+ WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_add);
+ WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_remove);
+ WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_select);
- /* clean-up */
- WM_operatortype_append(CLIP_OT_clear_track_path);
- WM_operatortype_append(CLIP_OT_join_tracks);
- WM_operatortype_append(CLIP_OT_track_copy_color);
+ /* clean-up */
+ WM_operatortype_append(CLIP_OT_clear_track_path);
+ WM_operatortype_append(CLIP_OT_join_tracks);
+ WM_operatortype_append(CLIP_OT_track_copy_color);
- WM_operatortype_append(CLIP_OT_clean_tracks);
+ WM_operatortype_append(CLIP_OT_clean_tracks);
- /* object tracking */
- WM_operatortype_append(CLIP_OT_tracking_object_new);
- WM_operatortype_append(CLIP_OT_tracking_object_remove);
+ /* object tracking */
+ WM_operatortype_append(CLIP_OT_tracking_object_new);
+ WM_operatortype_append(CLIP_OT_tracking_object_remove);
- /* clipboard */
- WM_operatortype_append(CLIP_OT_copy_tracks);
- WM_operatortype_append(CLIP_OT_paste_tracks);
+ /* clipboard */
+ WM_operatortype_append(CLIP_OT_copy_tracks);
+ WM_operatortype_append(CLIP_OT_paste_tracks);
- /* Plane tracker */
- WM_operatortype_append(CLIP_OT_create_plane_track);
- WM_operatortype_append(CLIP_OT_slide_plane_marker);
+ /* Plane tracker */
+ WM_operatortype_append(CLIP_OT_create_plane_track);
+ WM_operatortype_append(CLIP_OT_slide_plane_marker);
- WM_operatortype_append(CLIP_OT_keyframe_insert);
- WM_operatortype_append(CLIP_OT_keyframe_delete);
+ WM_operatortype_append(CLIP_OT_keyframe_insert);
+ WM_operatortype_append(CLIP_OT_keyframe_delete);
- /* ** clip_graph_ops.c ** */
+ /* ** clip_graph_ops.c ** */
- /* graph editing */
+ /* graph editing */
- /* selection */
- WM_operatortype_append(CLIP_OT_graph_select);
- WM_operatortype_append(CLIP_OT_graph_select_box);
- WM_operatortype_append(CLIP_OT_graph_select_all_markers);
+ /* selection */
+ WM_operatortype_append(CLIP_OT_graph_select);
+ WM_operatortype_append(CLIP_OT_graph_select_box);
+ WM_operatortype_append(CLIP_OT_graph_select_all_markers);
- WM_operatortype_append(CLIP_OT_graph_delete_curve);
- WM_operatortype_append(CLIP_OT_graph_delete_knot);
- WM_operatortype_append(CLIP_OT_graph_view_all);
- WM_operatortype_append(CLIP_OT_graph_center_current_frame);
+ WM_operatortype_append(CLIP_OT_graph_delete_curve);
+ WM_operatortype_append(CLIP_OT_graph_delete_knot);
+ WM_operatortype_append(CLIP_OT_graph_view_all);
+ WM_operatortype_append(CLIP_OT_graph_center_current_frame);
- WM_operatortype_append(CLIP_OT_graph_disable_markers);
+ WM_operatortype_append(CLIP_OT_graph_disable_markers);
- /* ** clip_dopesheet_ops.c ** */
+ /* ** clip_dopesheet_ops.c ** */
- WM_operatortype_append(CLIP_OT_dopesheet_select_channel);
- WM_operatortype_append(CLIP_OT_dopesheet_view_all);
+ WM_operatortype_append(CLIP_OT_dopesheet_select_channel);
+ WM_operatortype_append(CLIP_OT_dopesheet_view_all);
}
static void clip_keymap(struct wmKeyConfig *keyconf)
{
- /* ******** Global hotkeys avalaible for all regions ******** */
- WM_keymap_ensure(keyconf, "Clip", SPACE_CLIP, 0);
+ /* ******** Global hotkeys avalaible for all regions ******** */
+ WM_keymap_ensure(keyconf, "Clip", SPACE_CLIP, 0);
- /* ******** Hotkeys avalaible for main region only ******** */
- WM_keymap_ensure(keyconf, "Clip Editor", SPACE_CLIP, 0);
-// keymap->poll = ED_space_clip_tracking_poll;
+ /* ******** Hotkeys avalaible for main region only ******** */
+ WM_keymap_ensure(keyconf, "Clip Editor", SPACE_CLIP, 0);
+ // keymap->poll = ED_space_clip_tracking_poll;
- /* ******** Hotkeys avalaible for preview region only ******** */
- WM_keymap_ensure(keyconf, "Clip Graph Editor", SPACE_CLIP, 0);
+ /* ******** Hotkeys avalaible for preview region only ******** */
+ WM_keymap_ensure(keyconf, "Clip Graph Editor", SPACE_CLIP, 0);
- /* ******** Hotkeys avalaible for channels region only ******** */
- WM_keymap_ensure(keyconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
+ /* ******** Hotkeys avalaible for channels region only ******** */
+ WM_keymap_ensure(keyconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
}
/* DO NOT make this static, this hides the symbol and breaks API generation script. */
-extern const char *clip_context_dir[]; /* quiet warning. */
+extern const char *clip_context_dir[]; /* quiet warning. */
const char *clip_context_dir[] = {"edit_movieclip", "edit_mask", NULL};
static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
-
- if (CTX_data_dir(member)) {
- CTX_data_dir_set(result, clip_context_dir);
-
- return true;
- }
- else if (CTX_data_equals(member, "edit_movieclip")) {
- if (sc->clip)
- CTX_data_id_pointer_set(result, &sc->clip->id);
- return true;
- }
- else if (CTX_data_equals(member, "edit_mask")) {
- if (sc->mask_info.mask)
- CTX_data_id_pointer_set(result, &sc->mask_info.mask->id);
- return true;
- }
-
- return false;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+
+ if (CTX_data_dir(member)) {
+ CTX_data_dir_set(result, clip_context_dir);
+
+ return true;
+ }
+ else if (CTX_data_equals(member, "edit_movieclip")) {
+ if (sc->clip)
+ CTX_data_id_pointer_set(result, &sc->clip->id);
+ return true;
+ }
+ else if (CTX_data_equals(member, "edit_mask")) {
+ if (sc->mask_info.mask)
+ CTX_data_id_pointer_set(result, &sc->mask_info.mask->id);
+ return true;
+ }
+
+ return false;
}
/* dropboxes */
-static bool clip_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
+static bool clip_drop_poll(bContext *UNUSED(C),
+ wmDrag *drag,
+ const wmEvent *UNUSED(event),
+ const char **UNUSED(tooltip))
{
- if (drag->type == WM_DRAG_PATH) {
- /* rule might not work? */
- if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) {
- return true;
- }
- }
-
- return false;
+ if (drag->type == WM_DRAG_PATH) {
+ /* rule might not work? */
+ if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) {
+ return true;
+ }
+ }
+
+ return false;
}
static void clip_drop_copy(wmDrag *drag, wmDropBox *drop)
{
- PointerRNA itemptr;
- char dir[FILE_MAX], file[FILE_MAX];
+ PointerRNA itemptr;
+ char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
+ BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
- RNA_string_set(drop->ptr, "directory", dir);
+ RNA_string_set(drop->ptr, "directory", dir);
- RNA_collection_clear(drop->ptr, "files");
- RNA_collection_add(drop->ptr, "files", &itemptr);
- RNA_string_set(&itemptr, "name", file);
+ RNA_collection_clear(drop->ptr, "files");
+ RNA_collection_add(drop->ptr, "files", &itemptr);
+ RNA_string_set(&itemptr, "name", file);
}
/* area+region dropbox definition */
static void clip_dropboxes(void)
{
- ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
+ ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
- WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
+ WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
}
static void clip_refresh(const bContext *C, ScrArea *sa)
{
- wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *window = CTX_wm_window(C);
- Scene *scene = CTX_data_scene(C);
- SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
- ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
- ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
- ARegion *ar_preview = ED_clip_has_preview_region(C, sa);
- ARegion *ar_properties = ED_clip_has_properties_region(sa);
- ARegion *ar_channels = ED_clip_has_channels_region(sa);
- bool main_visible = false, preview_visible = false, tools_visible = false;
- bool properties_visible = false, channels_visible = false;
- bool view_changed = false;
-
- switch (sc->view) {
- case SC_VIEW_CLIP:
- main_visible = true;
- preview_visible = false;
- tools_visible = true;
- properties_visible = true;
- channels_visible = false;
- break;
- case SC_VIEW_GRAPH:
- main_visible = false;
- preview_visible = true;
- tools_visible = false;
- properties_visible = false;
- channels_visible = false;
-
- reinit_preview_region(C, ar_preview);
- break;
- case SC_VIEW_DOPESHEET:
- main_visible = false;
- preview_visible = true;
- tools_visible = false;
- properties_visible = false;
- channels_visible = true;
-
- reinit_preview_region(C, ar_preview);
- break;
- }
-
- if (main_visible) {
- if (ar_main && (ar_main->flag & RGN_FLAG_HIDDEN)) {
- ar_main->flag &= ~RGN_FLAG_HIDDEN;
- ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
- view_changed = true;
- }
-
- if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
- ar_main->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
- else {
- if (ar_main && !(ar_main->flag & RGN_FLAG_HIDDEN)) {
- ar_main->flag |= RGN_FLAG_HIDDEN;
- ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_main->handlers);
- view_changed = true;
- }
- if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
- ar_main->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
- if (properties_visible) {
- if (ar_properties && (ar_properties->flag & RGN_FLAG_HIDDEN)) {
- ar_properties->flag &= ~RGN_FLAG_HIDDEN;
- ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
- view_changed = true;
- }
- if (ar_properties && ar_properties->alignment != RGN_ALIGN_RIGHT) {
- ar_properties->alignment = RGN_ALIGN_RIGHT;
- view_changed = true;
- }
- }
- else {
- if (ar_properties && !(ar_properties->flag & RGN_FLAG_HIDDEN)) {
- ar_properties->flag |= RGN_FLAG_HIDDEN;
- ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_properties->handlers);
- view_changed = true;
- }
- if (ar_properties && ar_properties->alignment != RGN_ALIGN_NONE) {
- ar_properties->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
- if (tools_visible) {
- if (ar_tools && (ar_tools->flag & RGN_FLAG_HIDDEN)) {
- ar_tools->flag &= ~RGN_FLAG_HIDDEN;
- ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
- view_changed = true;
- }
- if (ar_tools && ar_tools->alignment != RGN_ALIGN_LEFT) {
- ar_tools->alignment = RGN_ALIGN_LEFT;
- view_changed = true;
- }
- }
- else {
- if (ar_tools && !(ar_tools->flag & RGN_FLAG_HIDDEN)) {
- ar_tools->flag |= RGN_FLAG_HIDDEN;
- ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_tools->handlers);
- view_changed = true;
- }
- if (ar_tools && ar_tools->alignment != RGN_ALIGN_NONE) {
- ar_tools->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
- if (preview_visible) {
- if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
- ar_preview->flag &= ~RGN_FLAG_HIDDEN;
- ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
- ar_preview->v2d.cur = ar_preview->v2d.tot;
- view_changed = true;
- }
- if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
- ar_preview->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
- else {
- if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) {
- ar_preview->flag |= RGN_FLAG_HIDDEN;
- ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_preview->handlers);
- view_changed = true;
- }
- if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
- ar_preview->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
- if (channels_visible) {
- if (ar_channels && (ar_channels->flag & RGN_FLAG_HIDDEN)) {
- ar_channels->flag &= ~RGN_FLAG_HIDDEN;
- ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
- view_changed = true;
- }
- if (ar_channels && ar_channels->alignment != RGN_ALIGN_LEFT) {
- ar_channels->alignment = RGN_ALIGN_LEFT;
- view_changed = true;
- }
- }
- else {
- if (ar_channels && !(ar_channels->flag & RGN_FLAG_HIDDEN)) {
- ar_channels->flag |= RGN_FLAG_HIDDEN;
- ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_channels->handlers);
- view_changed = true;
- }
- if (ar_channels && ar_channels->alignment != RGN_ALIGN_NONE) {
- ar_channels->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
- if (view_changed) {
- ED_area_initialize(wm, window, sa);
- ED_area_tag_redraw(sa);
- }
-
- BKE_movieclip_user_set_frame(&sc->user, scene->r.cfra);
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmWindow *window = CTX_wm_window(C);
+ Scene *scene = CTX_data_scene(C);
+ SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
+ ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+ ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
+ ARegion *ar_preview = ED_clip_has_preview_region(C, sa);
+ ARegion *ar_properties = ED_clip_has_properties_region(sa);
+ ARegion *ar_channels = ED_clip_has_channels_region(sa);
+ bool main_visible = false, preview_visible = false, tools_visible = false;
+ bool properties_visible = false, channels_visible = false;
+ bool view_changed = false;
+
+ switch (sc->view) {
+ case SC_VIEW_CLIP:
+ main_visible = true;
+ preview_visible = false;
+ tools_visible = true;
+ properties_visible = true;
+ channels_visible = false;
+ break;
+ case SC_VIEW_GRAPH:
+ main_visible = false;
+ preview_visible = true;
+ tools_visible = false;
+ properties_visible = false;
+ channels_visible = false;
+
+ reinit_preview_region(C, ar_preview);
+ break;
+ case SC_VIEW_DOPESHEET:
+ main_visible = false;
+ preview_visible = true;
+ tools_visible = false;
+ properties_visible = false;
+ channels_visible = true;
+
+ reinit_preview_region(C, ar_preview);
+ break;
+ }
+
+ if (main_visible) {
+ if (ar_main && (ar_main->flag & RGN_FLAG_HIDDEN)) {
+ ar_main->flag &= ~RGN_FLAG_HIDDEN;
+ ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
+ view_changed = true;
+ }
+
+ if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
+ ar_main->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+ else {
+ if (ar_main && !(ar_main->flag & RGN_FLAG_HIDDEN)) {
+ ar_main->flag |= RGN_FLAG_HIDDEN;
+ ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
+ WM_event_remove_handlers((bContext *)C, &ar_main->handlers);
+ view_changed = true;
+ }
+ if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
+ ar_main->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+
+ if (properties_visible) {
+ if (ar_properties && (ar_properties->flag & RGN_FLAG_HIDDEN)) {
+ ar_properties->flag &= ~RGN_FLAG_HIDDEN;
+ ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
+ view_changed = true;
+ }
+ if (ar_properties && ar_properties->alignment != RGN_ALIGN_RIGHT) {
+ ar_properties->alignment = RGN_ALIGN_RIGHT;
+ view_changed = true;
+ }
+ }
+ else {
+ if (ar_properties && !(ar_properties->flag & RGN_FLAG_HIDDEN)) {
+ ar_properties->flag |= RGN_FLAG_HIDDEN;
+ ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
+ WM_event_remove_handlers((bContext *)C, &ar_properties->handlers);
+ view_changed = true;
+ }
+ if (ar_properties && ar_properties->alignment != RGN_ALIGN_NONE) {
+ ar_properties->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+
+ if (tools_visible) {
+ if (ar_tools && (ar_tools->flag & RGN_FLAG_HIDDEN)) {
+ ar_tools->flag &= ~RGN_FLAG_HIDDEN;
+ ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
+ view_changed = true;
+ }
+ if (ar_tools && ar_tools->alignment != RGN_ALIGN_LEFT) {
+ ar_tools->alignment = RGN_ALIGN_LEFT;
+ view_changed = true;
+ }
+ }
+ else {
+ if (ar_tools && !(ar_tools->flag & RGN_FLAG_HIDDEN)) {
+ ar_tools->flag |= RGN_FLAG_HIDDEN;
+ ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
+ WM_event_remove_handlers((bContext *)C, &ar_tools->handlers);
+ view_changed = true;
+ }
+ if (ar_tools && ar_tools->alignment != RGN_ALIGN_NONE) {
+ ar_tools->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+
+ if (preview_visible) {
+ if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
+ ar_preview->flag &= ~RGN_FLAG_HIDDEN;
+ ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
+ ar_preview->v2d.cur = ar_preview->v2d.tot;
+ view_changed = true;
+ }
+ if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
+ ar_preview->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+ else {
+ if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) {
+ ar_preview->flag |= RGN_FLAG_HIDDEN;
+ ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
+ WM_event_remove_handlers((bContext *)C, &ar_preview->handlers);
+ view_changed = true;
+ }
+ if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
+ ar_preview->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+
+ if (channels_visible) {
+ if (ar_channels && (ar_channels->flag & RGN_FLAG_HIDDEN)) {
+ ar_channels->flag &= ~RGN_FLAG_HIDDEN;
+ ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
+ view_changed = true;
+ }
+ if (ar_channels && ar_channels->alignment != RGN_ALIGN_LEFT) {
+ ar_channels->alignment = RGN_ALIGN_LEFT;
+ view_changed = true;
+ }
+ }
+ else {
+ if (ar_channels && !(ar_channels->flag & RGN_FLAG_HIDDEN)) {
+ ar_channels->flag |= RGN_FLAG_HIDDEN;
+ ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
+ WM_event_remove_handlers((bContext *)C, &ar_channels->handlers);
+ view_changed = true;
+ }
+ if (ar_channels && ar_channels->alignment != RGN_ALIGN_NONE) {
+ ar_channels->alignment = RGN_ALIGN_NONE;
+ view_changed = true;
+ }
+ }
+
+ if (view_changed) {
+ ED_area_initialize(wm, window, sa);
+ ED_area_tag_redraw(sa);
+ }
+
+ BKE_movieclip_user_set_frame(&sc->user, scene->r.cfra);
}
/********************* main region ********************/
@@ -793,300 +798,314 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
/* sets up the fields of the View2D from zoom and offset */
static void movieclip_main_area_set_view2d(const bContext *C, ARegion *ar)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- float x1, y1, w, h, aspx, aspy;
- int width, height, winx, winy;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ float x1, y1, w, h, aspx, aspy;
+ int width, height, winx, winy;
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
- w = width * aspx;
- h = height * aspy;
+ w = width * aspx;
+ h = height * aspy;
- winx = BLI_rcti_size_x(&ar->winrct) + 1;
- winy = BLI_rcti_size_y(&ar->winrct) + 1;
+ winx = BLI_rcti_size_x(&ar->winrct) + 1;
+ winy = BLI_rcti_size_y(&ar->winrct) + 1;
- ar->v2d.tot.xmin = 0;
- ar->v2d.tot.ymin = 0;
- ar->v2d.tot.xmax = w;
- ar->v2d.tot.ymax = h;
+ ar->v2d.tot.xmin = 0;
+ ar->v2d.tot.ymin = 0;
+ ar->v2d.tot.xmax = w;
+ ar->v2d.tot.ymax = h;
- ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
- ar->v2d.mask.xmax = winx;
- ar->v2d.mask.ymax = winy;
+ ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
+ ar->v2d.mask.xmax = winx;
+ ar->v2d.mask.ymax = winy;
- /* which part of the image space do we see? */
- x1 = ar->winrct.xmin + (winx - sc->zoom * w) / 2.0f;
- y1 = ar->winrct.ymin + (winy - sc->zoom * h) / 2.0f;
+ /* which part of the image space do we see? */
+ x1 = ar->winrct.xmin + (winx - sc->zoom * w) / 2.0f;
+ y1 = ar->winrct.ymin + (winy - sc->zoom * h) / 2.0f;
- x1 -= sc->zoom * sc->xof;
- y1 -= sc->zoom * sc->yof;
+ x1 -= sc->zoom * sc->xof;
+ y1 -= sc->zoom * sc->yof;
- /* relative display right */
- ar->v2d.cur.xmin = (ar->winrct.xmin - (float)x1) / sc->zoom;
- ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sc->zoom);
+ /* relative display right */
+ ar->v2d.cur.xmin = (ar->winrct.xmin - (float)x1) / sc->zoom;
+ ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sc->zoom);
- /* relative display left */
- ar->v2d.cur.ymin = (ar->winrct.ymin - (float)y1) / sc->zoom;
- ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sc->zoom);
+ /* relative display left */
+ ar->v2d.cur.ymin = (ar->winrct.ymin - (float)y1) / sc->zoom;
+ ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sc->zoom);
- /* normalize 0.0..1.0 */
- ar->v2d.cur.xmin /= w;
- ar->v2d.cur.xmax /= w;
- ar->v2d.cur.ymin /= h;
- ar->v2d.cur.ymax /= h;
+ /* normalize 0.0..1.0 */
+ ar->v2d.cur.xmin /= w;
+ ar->v2d.cur.xmax /= w;
+ ar->v2d.cur.ymin /= h;
+ ar->v2d.cur.ymax /= h;
}
/* add handlers, stuff you only do once or on area/region changes */
static void clip_main_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
+ UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
- /* mask polls mode */
- keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* mask polls mode */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- /* own keymap */
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* own keymap */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
static void clip_main_region_draw(const bContext *C, ARegion *ar)
{
- /* draw entirely, view changes should be handled here */
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- float aspx, aspy, zoomx, zoomy, x, y;
- int width, height;
- bool show_cursor = false;
-
- /* if tracking is in progress, we should synchronize framenr from clipuser
- * so latest tracked frame would be shown */
- if (clip && clip->tracking_context)
- BKE_autotrack_context_sync_user(clip->tracking_context, &sc->user);
-
- if (sc->flag & SC_LOCK_SELECTION) {
- ImBuf *tmpibuf = NULL;
-
- if (clip && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
- tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL);
- }
-
- if (ED_clip_view_selection(C, ar, 0)) {
- sc->xof += sc->xlockof;
- sc->yof += sc->ylockof;
- }
-
- if (tmpibuf)
- IMB_freeImBuf(tmpibuf);
- }
-
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- GPU_clear(GPU_COLOR_BIT);
-
- /* data... */
- movieclip_main_area_set_view2d(C, ar);
-
- /* callback */
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
- clip_draw_main(C, sc, ar);
-
- /* TODO(sergey): would be nice to find a way to de-duplicate all this space conversions */
- UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
- ED_space_clip_get_aspect(sc, &aspx, &aspy);
-
- if (sc->mode == SC_MODE_MASKEDIT) {
- Mask *mask = CTX_data_edit_mask(C);
- if (mask && clip) {
- ScrArea *sa = CTX_wm_area(C);
- int mask_width, mask_height;
- ED_mask_get_size(sa, &mask_width, &mask_height);
- ED_mask_draw_region(mask, ar,
- sc->mask_info.draw_flag,
- sc->mask_info.draw_type,
- sc->mask_info.overlay_mode,
- mask_width, mask_height,
- aspx, aspy,
- true, true,
- sc->stabmat, C);
- }
- }
-
- show_cursor |= sc->mode == SC_MODE_MASKEDIT;
- show_cursor |= sc->around == V3D_AROUND_CURSOR;
-
- if (show_cursor) {
- GPU_matrix_push();
- GPU_matrix_translate_2f(x, y);
- GPU_matrix_scale_2f(zoomx, zoomy);
- GPU_matrix_mul(sc->stabmat);
- GPU_matrix_scale_2f(width, height);
- ED_image_draw_cursor(ar, sc->cursor);
- GPU_matrix_pop();
- }
-
- clip_draw_cache_and_notes(C, sc, ar);
-
- if (sc->flag & SC_SHOW_ANNOTATION) {
- /* Grease Pencil */
- clip_draw_grease_pencil((bContext *)C, true);
- }
-
- /* callback */
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
-
- /* reset view matrix */
- UI_view2d_view_restore(C);
-
- if (sc->flag & SC_SHOW_ANNOTATION) {
- /* draw Grease Pencil - screen space only */
- clip_draw_grease_pencil((bContext *)C, false);
- }
+ /* draw entirely, view changes should be handled here */
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ float aspx, aspy, zoomx, zoomy, x, y;
+ int width, height;
+ bool show_cursor = false;
+
+ /* if tracking is in progress, we should synchronize framenr from clipuser
+ * so latest tracked frame would be shown */
+ if (clip && clip->tracking_context)
+ BKE_autotrack_context_sync_user(clip->tracking_context, &sc->user);
+
+ if (sc->flag & SC_LOCK_SELECTION) {
+ ImBuf *tmpibuf = NULL;
+
+ if (clip && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
+ tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL);
+ }
+
+ if (ED_clip_view_selection(C, ar, 0)) {
+ sc->xof += sc->xlockof;
+ sc->yof += sc->ylockof;
+ }
+
+ if (tmpibuf)
+ IMB_freeImBuf(tmpibuf);
+ }
+
+ /* clear and setup matrix */
+ UI_ThemeClearColor(TH_BACK);
+ GPU_clear(GPU_COLOR_BIT);
+
+ /* data... */
+ movieclip_main_area_set_view2d(C, ar);
+
+ /* callback */
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
+
+ clip_draw_main(C, sc, ar);
+
+ /* TODO(sergey): would be nice to find a way to de-duplicate all this space conversions */
+ UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+ ED_space_clip_get_aspect(sc, &aspx, &aspy);
+
+ if (sc->mode == SC_MODE_MASKEDIT) {
+ Mask *mask = CTX_data_edit_mask(C);
+ if (mask && clip) {
+ ScrArea *sa = CTX_wm_area(C);
+ int mask_width, mask_height;
+ ED_mask_get_size(sa, &mask_width, &mask_height);
+ ED_mask_draw_region(mask,
+ ar,
+ sc->mask_info.draw_flag,
+ sc->mask_info.draw_type,
+ sc->mask_info.overlay_mode,
+ mask_width,
+ mask_height,
+ aspx,
+ aspy,
+ true,
+ true,
+ sc->stabmat,
+ C);
+ }
+ }
+
+ show_cursor |= sc->mode == SC_MODE_MASKEDIT;
+ show_cursor |= sc->around == V3D_AROUND_CURSOR;
+
+ if (show_cursor) {
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(x, y);
+ GPU_matrix_scale_2f(zoomx, zoomy);
+ GPU_matrix_mul(sc->stabmat);
+ GPU_matrix_scale_2f(width, height);
+ ED_image_draw_cursor(ar, sc->cursor);
+ GPU_matrix_pop();
+ }
+
+ clip_draw_cache_and_notes(C, sc, ar);
+
+ if (sc->flag & SC_SHOW_ANNOTATION) {
+ /* Grease Pencil */
+ clip_draw_grease_pencil((bContext *)C, true);
+ }
+
+ /* callback */
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
+
+ /* reset view matrix */
+ UI_view2d_view_restore(C);
+
+ if (sc->flag & SC_SHOW_ANNOTATION) {
+ /* draw Grease Pencil - screen space only */
+ clip_draw_grease_pencil((bContext *)C, false);
+ }
}
-static void clip_main_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void clip_main_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_GPENCIL:
- if (wmn->action == NA_EDITED)
- ED_region_tag_redraw(ar);
- else if (wmn->data & ND_GPENCIL_EDITMODE)
- ED_region_tag_redraw(ar);
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_GPENCIL:
+ if (wmn->action == NA_EDITED)
+ ED_region_tag_redraw(ar);
+ else if (wmn->data & ND_GPENCIL_EDITMODE)
+ ED_region_tag_redraw(ar);
+ break;
+ }
}
/****************** preview region ******************/
static void clip_preview_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
+ UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
- /* own keymap */
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* own keymap */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
static void graph_region_draw(const bContext *C, ARegion *ar)
{
- View2D *v2d = &ar->v2d;
- View2DScrollers *scrollers;
- SpaceClip *sc = CTX_wm_space_clip(C);
- Scene *scene = CTX_data_scene(C);
- short unitx, unity;
- short cfra_flag = 0;
-
- if (sc->flag & SC_LOCK_TIMECURSOR)
- ED_clip_graph_center_current_frame(scene, ar);
-
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- GPU_clear(GPU_COLOR_BIT);
-
- UI_view2d_view_ortho(v2d);
-
- /* data... */
- clip_draw_graph(sc, ar, scene);
-
- /* current frame indicator line */
- if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
- ANIM_draw_cfra(C, v2d, cfra_flag);
-
- /* reset view matrix */
- UI_view2d_view_restore(C);
-
- /* scrollers */
- unitx = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
- unity = V2D_UNIT_VALUES;
- scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
-
- /* current frame indicator */
- if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
- UI_view2d_view_orthoSpecial(ar, v2d, 1);
- ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ View2D *v2d = &ar->v2d;
+ View2DScrollers *scrollers;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ Scene *scene = CTX_data_scene(C);
+ short unitx, unity;
+ short cfra_flag = 0;
+
+ if (sc->flag & SC_LOCK_TIMECURSOR)
+ ED_clip_graph_center_current_frame(scene, ar);
+
+ /* clear and setup matrix */
+ UI_ThemeClearColor(TH_BACK);
+ GPU_clear(GPU_COLOR_BIT);
+
+ UI_view2d_view_ortho(v2d);
+
+ /* data... */
+ clip_draw_graph(sc, ar, scene);
+
+ /* current frame indicator line */
+ if (sc->flag & SC_SHOW_SECONDS)
+ cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
+
+ /* reset view matrix */
+ UI_view2d_view_restore(C);
+
+ /* scrollers */
+ unitx = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
+ unity = V2D_UNIT_VALUES;
+ scrollers = UI_view2d_scrollers_calc(
+ C, v2d, NULL, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
+ UI_view2d_scrollers_draw(C, v2d, scrollers);
+ UI_view2d_scrollers_free(scrollers);
+
+ /* current frame indicator */
+ if (sc->flag & SC_SHOW_SECONDS)
+ cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
static void dopesheet_region_draw(const bContext *C, ARegion *ar)
{
- Scene *scene = CTX_data_scene(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- View2D *v2d = &ar->v2d;
- View2DGrid *grid;
- View2DScrollers *scrollers;
- short unit = 0, cfra_flag = 0;
-
- if (clip)
- BKE_tracking_dopesheet_update(&clip->tracking);
-
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- GPU_clear(GPU_COLOR_BIT);
-
- UI_view2d_view_ortho(v2d);
-
- /* time grid */
- unit = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
- grid = UI_view2d_grid_calc(scene, v2d, unit, V2D_GRID_CLAMP,
- V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
- UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
- UI_view2d_grid_free(grid);
-
- /* data... */
- clip_draw_dopesheet_main(sc, ar, scene);
-
- /* current frame indicator line */
- if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
- ANIM_draw_cfra(C, v2d, cfra_flag);
-
- /* reset view matrix */
- UI_view2d_view_restore(C);
-
- /* scrollers */
- scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
-
- /* current frame number indicator */
- UI_view2d_view_orthoSpecial(ar, v2d, 1);
- ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ Scene *scene = CTX_data_scene(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ View2D *v2d = &ar->v2d;
+ View2DGrid *grid;
+ View2DScrollers *scrollers;
+ short unit = 0, cfra_flag = 0;
+
+ if (clip)
+ BKE_tracking_dopesheet_update(&clip->tracking);
+
+ /* clear and setup matrix */
+ UI_ThemeClearColor(TH_BACK);
+ GPU_clear(GPU_COLOR_BIT);
+
+ UI_view2d_view_ortho(v2d);
+
+ /* time grid */
+ unit = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
+ grid = UI_view2d_grid_calc(
+ scene, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
+ UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
+ UI_view2d_grid_free(grid);
+
+ /* data... */
+ clip_draw_dopesheet_main(sc, ar, scene);
+
+ /* current frame indicator line */
+ if (sc->flag & SC_SHOW_SECONDS)
+ cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
+
+ /* reset view matrix */
+ UI_view2d_view_restore(C);
+
+ /* scrollers */
+ scrollers = UI_view2d_scrollers_calc(
+ C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+ UI_view2d_scrollers_draw(C, v2d, scrollers);
+ UI_view2d_scrollers_free(scrollers);
+
+ /* current frame number indicator */
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
static void clip_preview_region_draw(const bContext *C, ARegion *ar)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc->view == SC_VIEW_GRAPH)
- graph_region_draw(C, ar);
- else if (sc->view == SC_VIEW_DOPESHEET)
- dopesheet_region_draw(C, ar);
+ if (sc->view == SC_VIEW_GRAPH)
+ graph_region_draw(C, ar);
+ else if (sc->view == SC_VIEW_DOPESHEET)
+ dopesheet_region_draw(C, ar);
}
-static void clip_preview_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
- wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
+static void clip_preview_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn),
+ const Scene *UNUSED(scene))
{
}
@@ -1094,42 +1113,44 @@ static void clip_preview_region_listener(
static void clip_channels_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- /* ensure the 2d view sync works - main region has bottom scroller */
- ar->v2d.scroll = V2D_SCROLL_BOTTOM;
+ /* ensure the 2d view sync works - main region has bottom scroller */
+ ar->v2d.scroll = V2D_SCROLL_BOTTOM;
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
+ UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
static void clip_channels_region_draw(const bContext *C, ARegion *ar)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- View2D *v2d = &ar->v2d;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ View2D *v2d = &ar->v2d;
- if (clip)
- BKE_tracking_dopesheet_update(&clip->tracking);
+ if (clip)
+ BKE_tracking_dopesheet_update(&clip->tracking);
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- GPU_clear(GPU_COLOR_BIT);
+ /* clear and setup matrix */
+ UI_ThemeClearColor(TH_BACK);
+ GPU_clear(GPU_COLOR_BIT);
- UI_view2d_view_ortho(v2d);
+ UI_view2d_view_ortho(v2d);
- /* data... */
- clip_draw_dopesheet_channels(C, ar);
+ /* data... */
+ clip_draw_dopesheet_channels(C, ar);
- /* reset view matrix */
- UI_view2d_view_restore(C);
+ /* reset view matrix */
+ UI_view2d_view_restore(C);
}
-static void clip_channels_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
- wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
+static void clip_channels_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn),
+ const Scene *UNUSED(scene))
{
}
@@ -1138,79 +1159,82 @@ static void clip_channels_region_listener(
/* add handlers, stuff you only do once or on area/region changes */
static void clip_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
{
- ED_region_header_init(ar);
+ ED_region_header_init(ar);
}
static void clip_header_region_draw(const bContext *C, ARegion *ar)
{
- ED_region_header(C, ar);
+ ED_region_header(C, ar);
}
-static void clip_header_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void clip_header_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_SCENE:
- switch (wmn->data) {
- /* for proportional editmode only */
- case ND_TOOLSETTINGS:
- /* TODO - should do this when in mask mode only but no datas available */
- // if (sc->mode == SC_MODE_MASKEDIT)
- {
- ED_region_tag_redraw(ar);
- break;
- }
- }
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SCENE:
+ switch (wmn->data) {
+ /* for proportional editmode only */
+ case ND_TOOLSETTINGS:
+ /* TODO - should do this when in mask mode only but no datas available */
+ // if (sc->mode == SC_MODE_MASKEDIT)
+ {
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ }
+ break;
+ }
}
-
/****************** tools region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void clip_tools_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- ED_region_panels_init(wm, ar);
+ ED_region_panels_init(wm, ar);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
}
static void clip_tools_region_draw(const bContext *C, ARegion *ar)
{
- ED_region_panels(C, ar);
+ ED_region_panels(C, ar);
}
/****************** tool properties region ******************/
-static void clip_props_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void clip_props_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_WM:
- if (wmn->data == ND_HISTORY)
- ED_region_tag_redraw(ar);
- break;
- case NC_SCENE:
- if (wmn->data == ND_MODE)
- ED_region_tag_redraw(ar);
- break;
- case NC_SPACE:
- if (wmn->data == ND_SPACE_CLIP)
- ED_region_tag_redraw(ar);
- break;
- case NC_GPENCIL:
- if (wmn->action == NA_EDITED)
- ED_region_tag_redraw(ar);
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_WM:
+ if (wmn->data == ND_HISTORY)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SCENE:
+ if (wmn->data == ND_MODE)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SPACE:
+ if (wmn->data == ND_SPACE_CLIP)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_GPENCIL:
+ if (wmn->action == NA_EDITED)
+ ED_region_tag_redraw(ar);
+ break;
+ }
}
/****************** properties region ******************/
@@ -1218,151 +1242,153 @@ static void clip_props_region_listener(
/* add handlers, stuff you only do once or on area/region changes */
static void clip_properties_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- ED_region_panels_init(wm, ar);
+ ED_region_panels_init(wm, ar);
- keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
}
static void clip_properties_region_draw(const bContext *C, ARegion *ar)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
+ BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
- ED_region_panels(C, ar);
+ ED_region_panels(C, ar);
}
-static void clip_properties_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void clip_properties_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_GPENCIL:
- if (ELEM(wmn->data, ND_DATA, ND_GPENCIL_EDITMODE))
- ED_region_tag_redraw(ar);
- break;
- case NC_BRUSH:
- if (wmn->action == NA_EDITED)
- ED_region_tag_redraw(ar);
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_GPENCIL:
+ if (ELEM(wmn->data, ND_DATA, ND_GPENCIL_EDITMODE))
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_BRUSH:
+ if (wmn->action == NA_EDITED)
+ ED_region_tag_redraw(ar);
+ break;
+ }
}
/********************* registration ********************/
static void clip_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
{
- SpaceClip *sclip = (SpaceClip *)slink;
+ SpaceClip *sclip = (SpaceClip *)slink;
- if (!ELEM(GS(old_id->name), ID_MC, ID_MSK)) {
- return;
- }
+ if (!ELEM(GS(old_id->name), ID_MC, ID_MSK)) {
+ return;
+ }
- if ((ID *)sclip->clip == old_id) {
- sclip->clip = (MovieClip *)new_id;
- id_us_ensure_real(new_id);
- }
+ if ((ID *)sclip->clip == old_id) {
+ sclip->clip = (MovieClip *)new_id;
+ id_us_ensure_real(new_id);
+ }
- if ((ID *)sclip->mask_info.mask == old_id) {
- sclip->mask_info.mask = (Mask *)new_id;
- id_us_ensure_real(new_id);
- }
+ if ((ID *)sclip->mask_info.mask == old_id) {
+ sclip->mask_info.mask = (Mask *)new_id;
+ id_us_ensure_real(new_id);
+ }
}
/* only called once, from space/spacetypes.c */
void ED_spacetype_clip(void)
{
- SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype clip");
- ARegionType *art;
-
- st->spaceid = SPACE_CLIP;
- strncpy(st->name, "Clip", BKE_ST_MAXNAME);
-
- st->new = clip_new;
- st->free = clip_free;
- st->init = clip_init;
- st->duplicate = clip_duplicate;
- st->operatortypes = clip_operatortypes;
- st->keymap = clip_keymap;
- st->listener = clip_listener;
- st->context = clip_context;
- st->dropboxes = clip_dropboxes;
- st->refresh = clip_refresh;
- st->id_remap = clip_id_remap;
-
- /* regions: main window */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
- art->regionid = RGN_TYPE_WINDOW;
- art->init = clip_main_region_init;
- art->draw = clip_main_region_draw;
- art->listener = clip_main_region_listener;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_GPENCIL;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* preview */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip region preview");
- art->regionid = RGN_TYPE_PREVIEW;
- art->prefsizey = 240;
- art->init = clip_preview_region_init;
- art->draw = clip_preview_region_draw;
- art->listener = clip_preview_region_listener;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: properties */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
- art->regionid = RGN_TYPE_UI;
- art->prefsizex = UI_COMPACT_PANEL_WIDTH;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
- art->init = clip_properties_region_init;
- art->draw = clip_properties_region_draw;
- art->listener = clip_properties_region_listener;
- BLI_addhead(&st->regiontypes, art);
- ED_clip_buttons_register(art);
-
- /* regions: tools */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
- art->regionid = RGN_TYPE_TOOLS;
- art->prefsizex = UI_COMPACT_PANEL_WIDTH;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
- art->listener = clip_props_region_listener;
- art->init = clip_tools_region_init;
- art->draw = clip_tools_region_draw;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: header */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
- art->regionid = RGN_TYPE_HEADER;
- art->prefsizey = HEADERY;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
-
- art->init = clip_header_region_init;
- art->draw = clip_header_region_draw;
- art->listener = clip_header_region_listener;
-
- BLI_addhead(&st->regiontypes, art);
-
- BKE_spacetype_register(st);
-
- /* channels */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip channels region");
- art->regionid = RGN_TYPE_CHANNELS;
- art->prefsizex = UI_COMPACT_PANEL_WIDTH;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
- art->listener = clip_channels_region_listener;
- art->init = clip_channels_region_init;
- art->draw = clip_channels_region_draw;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: hud */
- art = ED_area_type_hud(st->spaceid);
- BLI_addhead(&st->regiontypes, art);
+ SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype clip");
+ ARegionType *art;
+
+ st->spaceid = SPACE_CLIP;
+ strncpy(st->name, "Clip", BKE_ST_MAXNAME);
+
+ st->new = clip_new;
+ st->free = clip_free;
+ st->init = clip_init;
+ st->duplicate = clip_duplicate;
+ st->operatortypes = clip_operatortypes;
+ st->keymap = clip_keymap;
+ st->listener = clip_listener;
+ st->context = clip_context;
+ st->dropboxes = clip_dropboxes;
+ st->refresh = clip_refresh;
+ st->id_remap = clip_id_remap;
+
+ /* regions: main window */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
+ art->regionid = RGN_TYPE_WINDOW;
+ art->init = clip_main_region_init;
+ art->draw = clip_main_region_draw;
+ art->listener = clip_main_region_listener;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_GPENCIL;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* preview */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip region preview");
+ art->regionid = RGN_TYPE_PREVIEW;
+ art->prefsizey = 240;
+ art->init = clip_preview_region_init;
+ art->draw = clip_preview_region_draw;
+ art->listener = clip_preview_region_listener;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: properties */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
+ art->regionid = RGN_TYPE_UI;
+ art->prefsizex = UI_COMPACT_PANEL_WIDTH;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
+ art->init = clip_properties_region_init;
+ art->draw = clip_properties_region_draw;
+ art->listener = clip_properties_region_listener;
+ BLI_addhead(&st->regiontypes, art);
+ ED_clip_buttons_register(art);
+
+ /* regions: tools */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
+ art->regionid = RGN_TYPE_TOOLS;
+ art->prefsizex = UI_COMPACT_PANEL_WIDTH;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
+ art->listener = clip_props_region_listener;
+ art->init = clip_tools_region_init;
+ art->draw = clip_tools_region_draw;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: header */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
+ art->regionid = RGN_TYPE_HEADER;
+ art->prefsizey = HEADERY;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
+
+ art->init = clip_header_region_init;
+ art->draw = clip_header_region_draw;
+ art->listener = clip_header_region_listener;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ BKE_spacetype_register(st);
+
+ /* channels */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype clip channels region");
+ art->regionid = RGN_TYPE_CHANNELS;
+ art->prefsizex = UI_COMPACT_PANEL_WIDTH;
+ art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
+ art->listener = clip_channels_region_listener;
+ art->init = clip_channels_region_init;
+ art->draw = clip_channels_region_draw;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: hud */
+ art = ED_area_type_hud(st->spaceid);
+ BLI_addhead(&st->regiontypes, art);
}
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index 68d13b63804..ce1ade80823 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -57,329 +57,319 @@
static bool add_marker(const bContext *C, float x, float y)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- MovieTrackingTrack *track;
- int width, height;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ MovieTrackingTrack *track;
+ int width, height;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
- ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_size(sc, &width, &height);
- if (width == 0 || height == 0) {
- return false;
- }
+ if (width == 0 || height == 0) {
+ return false;
+ }
- track = BKE_tracking_track_add(tracking, tracksbase, x, y, framenr, width, height);
+ track = BKE_tracking_track_add(tracking, tracksbase, x, y, framenr, width, height);
- BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, 0);
- BKE_tracking_plane_tracks_deselect_all(plane_tracks_base);
+ BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, 0);
+ BKE_tracking_plane_tracks_deselect_all(plane_tracks_base);
- clip->tracking.act_track = track;
- clip->tracking.act_plane_track = NULL;
+ clip->tracking.act_track = track;
+ clip->tracking.act_plane_track = NULL;
- return true;
+ return true;
}
static int add_marker_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- float pos[2];
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ float pos[2];
- RNA_float_get_array(op->ptr, "location", pos);
+ RNA_float_get_array(op->ptr, "location", pos);
- if (!add_marker(C, pos[0], pos[1])) {
- return OPERATOR_CANCELLED;
- }
+ if (!add_marker(C, pos[0], pos[1])) {
+ return OPERATOR_CANCELLED;
+ }
- /* Reset offset from locked position, so frame jumping wouldn't be so
- * confusing.
- */
- sc->xlockof = 0;
- sc->ylockof = 0;
+ /* Reset offset from locked position, so frame jumping wouldn't be so
+ * confusing.
+ */
+ sc->xlockof = 0;
+ sc->ylockof = 0;
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int add_marker_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- if (!RNA_struct_property_is_set(op->ptr, "location")) {
- /* If location is not set, use mouse positio nas default. */
- float co[2];
- ED_clip_mouse_pos(sc, ar, event->mval, co);
- RNA_float_set_array(op->ptr, "location", co);
- }
+ if (!RNA_struct_property_is_set(op->ptr, "location")) {
+ /* If location is not set, use mouse positio nas default. */
+ float co[2];
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
+ RNA_float_set_array(op->ptr, "location", co);
+ }
- return add_marker_exec(C, op);
+ return add_marker_exec(C, op);
}
void CLIP_OT_add_marker(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Marker";
- ot->idname = "CLIP_OT_add_marker";
- ot->description = "Place new marker at specified location";
+ /* identifiers */
+ ot->name = "Add Marker";
+ ot->idname = "CLIP_OT_add_marker";
+ ot->description = "Place new marker at specified location";
- /* api callbacks */
- ot->invoke = add_marker_invoke;
- ot->exec = add_marker_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->invoke = add_marker_invoke;
+ ot->exec = add_marker_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Location of marker on frame", -1.0f, 1.0f);
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Location of marker on frame",
+ -1.0f,
+ 1.0f);
}
/********************** add marker operator *********************/
-static int add_marker_at_click_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int add_marker_at_click_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- ED_workspace_status_text(
- C,
- IFACE_("Use LMB click to define location where place the marker"));
+ ED_workspace_status_text(C, IFACE_("Use LMB click to define location where place the marker"));
- /* Add modal handler for ESC. */
- WM_event_add_modal_handler(C, op);
+ /* Add modal handler for ESC. */
+ WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static int add_marker_at_click_modal(bContext *C,
- wmOperator *UNUSED(op),
- const wmEvent *event)
+static int add_marker_at_click_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- switch (event->type) {
- case MOUSEMOVE:
- return OPERATOR_RUNNING_MODAL;
+ switch (event->type) {
+ case MOUSEMOVE:
+ return OPERATOR_RUNNING_MODAL;
- case LEFTMOUSE:
- {
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- ARegion *ar = CTX_wm_region(C);
- float pos[2];
+ case LEFTMOUSE: {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ ARegion *ar = CTX_wm_region(C);
+ float pos[2];
- ED_workspace_status_text(C, NULL);
+ ED_workspace_status_text(C, NULL);
- ED_clip_point_stable_pos(sc, ar,
- event->x - ar->winrct.xmin,
- event->y - ar->winrct.ymin,
- &pos[0], &pos[1]);
+ ED_clip_point_stable_pos(
+ sc, ar, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, &pos[0], &pos[1]);
- if (!add_marker(C, pos[0], pos[1])) {
- return OPERATOR_CANCELLED;
- }
+ if (!add_marker(C, pos[0], pos[1])) {
+ return OPERATOR_CANCELLED;
+ }
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
- }
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ return OPERATOR_FINISHED;
+ }
- case ESCKEY:
- ED_workspace_status_text(C, NULL);
- return OPERATOR_CANCELLED;
- }
+ case ESCKEY:
+ ED_workspace_status_text(C, NULL);
+ return OPERATOR_CANCELLED;
+ }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_PASS_THROUGH;
}
void CLIP_OT_add_marker_at_click(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Marker at Click";
- ot->idname = "CLIP_OT_add_marker_at_click";
- ot->description = "Place new marker at the desired (clicked) position";
+ /* identifiers */
+ ot->name = "Add Marker at Click";
+ ot->idname = "CLIP_OT_add_marker_at_click";
+ ot->description = "Place new marker at the desired (clicked) position";
- /* api callbacks */
- ot->invoke = add_marker_at_click_invoke;
- ot->poll = ED_space_clip_tracking_poll;
- ot->modal = add_marker_at_click_modal;
+ /* api callbacks */
+ ot->invoke = add_marker_at_click_invoke;
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->modal = add_marker_at_click_modal;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
}
/********************** delete track operator *********************/
static int delete_track_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- bool changed = false;
- /* Delete selected plane tracks. */
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first,
- *next_plane_track;
- plane_track != NULL;
- plane_track = next_plane_track)
- {
- next_plane_track = plane_track->next;
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- clip_delete_plane_track(C, clip, plane_track);
- changed = true;
- }
- }
- /* Remove selected point tracks (they'll also be removed from planes which
- * uses them).
- */
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- for (MovieTrackingTrack *track = tracksbase->first, *next_track;
- track != NULL;
- track = next_track)
- {
- next_track = track->next;
- if (TRACK_VIEW_SELECTED(sc, track)) {
- clip_delete_track(C, clip, track);
- changed = true;
- }
- }
- /* Nothing selected now, unlock view so it can be scrolled nice again. */
- sc->flag &= ~SC_LOCK_SELECTION;
- if (changed) {
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- }
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ bool changed = false;
+ /* Delete selected plane tracks. */
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first, *next_plane_track;
+ plane_track != NULL;
+ plane_track = next_plane_track) {
+ next_plane_track = plane_track->next;
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ clip_delete_plane_track(C, clip, plane_track);
+ changed = true;
+ }
+ }
+ /* Remove selected point tracks (they'll also be removed from planes which
+ * uses them).
+ */
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ for (MovieTrackingTrack *track = tracksbase->first, *next_track; track != NULL;
+ track = next_track) {
+ next_track = track->next;
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ clip_delete_track(C, clip, track);
+ changed = true;
+ }
+ }
+ /* Nothing selected now, unlock view so it can be scrolled nice again. */
+ sc->flag &= ~SC_LOCK_SELECTION;
+ if (changed) {
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ }
+ return OPERATOR_FINISHED;
}
void CLIP_OT_delete_track(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete Track";
- ot->idname = "CLIP_OT_delete_track";
- ot->description = "Delete selected tracks";
+ /* identifiers */
+ ot->name = "Delete Track";
+ ot->idname = "CLIP_OT_delete_track";
+ ot->description = "Delete selected tracks";
- /* api callbacks */
- ot->invoke = WM_operator_confirm;
- ot->exec = delete_track_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->invoke = WM_operator_confirm;
+ ot->exec = delete_track_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** delete marker operator *********************/
static int delete_marker_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- const int framenr = ED_space_clip_get_clip_frame_number(sc);
- bool has_selection = false;
- bool changed = false;
-
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- for (MovieTrackingTrack *track = tracksbase->first, *next_track;
- track != NULL;
- track = next_track)
- {
- next_track = track->next;
- if (TRACK_VIEW_SELECTED(sc, track)) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
- if (marker != NULL) {
- has_selection |= track->markersnr > 1;
- clip_delete_marker(C, clip, track, marker);
- changed = true;
- }
- }
- }
-
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first,
- *plane_track_next;
- plane_track != NULL;
- plane_track = plane_track_next)
- {
- plane_track_next = plane_track->next;
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get_exact(plane_track, framenr);
- if (plane_marker != NULL) {
- if (plane_track->markersnr == 1) {
- BKE_tracking_plane_track_free(plane_track);
- BLI_freelinkN(plane_tracks_base, plane_track);
- }
- else {
- BKE_tracking_plane_marker_delete(plane_track, framenr);
- }
- changed = true;
- }
- }
- }
-
- if (!has_selection) {
- /* Nothing selected now, unlock view so it can be scrolled nice again. */
- sc->flag &= ~SC_LOCK_SELECTION;
- }
-
- if (!changed) {
- return OPERATOR_CANCELLED;
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ const int framenr = ED_space_clip_get_clip_frame_number(sc);
+ bool has_selection = false;
+ bool changed = false;
+
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ for (MovieTrackingTrack *track = tracksbase->first, *next_track; track != NULL;
+ track = next_track) {
+ next_track = track->next;
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
+ if (marker != NULL) {
+ has_selection |= track->markersnr > 1;
+ clip_delete_marker(C, clip, track, marker);
+ changed = true;
+ }
+ }
+ }
+
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first, *plane_track_next;
+ plane_track != NULL;
+ plane_track = plane_track_next) {
+ plane_track_next = plane_track->next;
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get_exact(plane_track,
+ framenr);
+ if (plane_marker != NULL) {
+ if (plane_track->markersnr == 1) {
+ BKE_tracking_plane_track_free(plane_track);
+ BLI_freelinkN(plane_tracks_base, plane_track);
+ }
+ else {
+ BKE_tracking_plane_marker_delete(plane_track, framenr);
+ }
+ changed = true;
+ }
+ }
+ }
+
+ if (!has_selection) {
+ /* Nothing selected now, unlock view so it can be scrolled nice again. */
+ sc->flag &= ~SC_LOCK_SELECTION;
+ }
+
+ if (!changed) {
+ return OPERATOR_CANCELLED;
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_delete_marker(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete Marker";
- ot->idname = "CLIP_OT_delete_marker";
- ot->description = "Delete marker for current frame from selected tracks";
+ /* identifiers */
+ ot->name = "Delete Marker";
+ ot->idname = "CLIP_OT_delete_marker";
+ ot->description = "Delete marker for current frame from selected tracks";
- /* api callbacks */
- ot->invoke = WM_operator_confirm;
- ot->exec = delete_marker_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->invoke = WM_operator_confirm;
+ ot->exec = delete_marker_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** slide marker operator *********************/
enum {
- SLIDE_ACTION_POS = 0,
- SLIDE_ACTION_SIZE,
- SLIDE_ACTION_OFFSET,
- SLIDE_ACTION_TILT_SIZE,
+ SLIDE_ACTION_POS = 0,
+ SLIDE_ACTION_SIZE,
+ SLIDE_ACTION_OFFSET,
+ SLIDE_ACTION_TILT_SIZE,
};
typedef struct {
- short area, action;
- MovieTrackingTrack *track;
- MovieTrackingMarker *marker;
+ short area, action;
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
- int mval[2];
- int width, height;
- float *min, *max, *pos, *offset, (*corners)[2];
- float spos[2];
+ int mval[2];
+ int width, height;
+ float *min, *max, *pos, *offset, (*corners)[2];
+ float spos[2];
- bool lock, accurate;
+ bool lock, accurate;
- /* Data to restore on cancel. */
- float old_search_min[2], old_search_max[2], old_pos[2], old_offset[2];
- float old_corners[4][2];
- float (*old_markers)[2];
+ /* Data to restore on cancel. */
+ float old_search_min[2], old_search_max[2], old_pos[2], old_offset[2];
+ float old_corners[4][2];
+ float (*old_markers)[2];
} SlideMarkerData;
-static void slide_marker_tilt_slider(const MovieTrackingMarker *marker,
- float r_slider[2])
+static void slide_marker_tilt_slider(const MovieTrackingMarker *marker, float r_slider[2])
{
- add_v2_v2v2(r_slider, marker->pattern_corners[1], marker->pattern_corners[2]);
- add_v2_v2(r_slider, marker->pos);
+ add_v2_v2v2(r_slider, marker->pattern_corners[1], marker->pattern_corners[2]);
+ add_v2_v2(r_slider, marker->pos);
}
static SlideMarkerData *create_slide_marker_data(SpaceClip *sc,
@@ -392,124 +382,107 @@ static SlideMarkerData *create_slide_marker_data(SpaceClip *sc,
int width,
int height)
{
- SlideMarkerData *data = MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- marker = BKE_tracking_marker_ensure(track, framenr);
-
- data->area = area;
- data->action = action;
- data->track = track;
- data->marker = marker;
-
- if (area == TRACK_AREA_POINT) {
- data->pos = marker->pos;
- data->offset = track->offset;
- }
- else if (area == TRACK_AREA_PAT) {
- if (action == SLIDE_ACTION_SIZE) {
- data->corners = marker->pattern_corners;
- }
- else if (action == SLIDE_ACTION_OFFSET) {
- data->pos = marker->pos;
- data->offset = track->offset;
- data->old_markers = MEM_callocN(
- sizeof(*data->old_markers) * track->markersnr,
- "slide marekrs");
- for (int a = 0; a < track->markersnr; a++) {
- copy_v2_v2(data->old_markers[a], track->markers[a].pos);
- }
- }
- else if (action == SLIDE_ACTION_POS) {
- data->corners = marker->pattern_corners;
- data->pos = marker->pattern_corners[corner];
- copy_v2_v2(data->spos, data->pos);
- }
- else if (action == SLIDE_ACTION_TILT_SIZE) {
- data->corners = marker->pattern_corners;
- slide_marker_tilt_slider(marker, data->spos);
- }
- }
- else if (area == TRACK_AREA_SEARCH) {
- data->min = marker->search_min;
- data->max = marker->search_max;
- }
-
- data->mval[0] = event->mval[0];
- data->mval[1] = event->mval[1];
-
- data->width = width;
- data->height = height;
-
- if (action == SLIDE_ACTION_SIZE) {
- data->lock = true;
- }
-
- /* Backup marker's settings. */
- memcpy(data->old_corners, marker->pattern_corners, sizeof(data->old_corners));
- copy_v2_v2(data->old_search_min, marker->search_min);
- copy_v2_v2(data->old_search_max, marker->search_max);
- copy_v2_v2(data->old_pos, marker->pos);
- copy_v2_v2(data->old_offset, track->offset);
-
- return data;
-}
-
-static float mouse_to_slide_zone_distance_squared(
- const float co[2],
- const float slide_zone[2],
- int width,
- int height)
-{
- float pixel_co[2] = {co[0] * width, co[1] * height},
- pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
- return SQUARE(pixel_co[0] - pixel_slide_zone[0]) +
- SQUARE(pixel_co[1] - pixel_slide_zone[1]);
+ SlideMarkerData *data = MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ marker = BKE_tracking_marker_ensure(track, framenr);
+
+ data->area = area;
+ data->action = action;
+ data->track = track;
+ data->marker = marker;
+
+ if (area == TRACK_AREA_POINT) {
+ data->pos = marker->pos;
+ data->offset = track->offset;
+ }
+ else if (area == TRACK_AREA_PAT) {
+ if (action == SLIDE_ACTION_SIZE) {
+ data->corners = marker->pattern_corners;
+ }
+ else if (action == SLIDE_ACTION_OFFSET) {
+ data->pos = marker->pos;
+ data->offset = track->offset;
+ data->old_markers = MEM_callocN(sizeof(*data->old_markers) * track->markersnr,
+ "slide marekrs");
+ for (int a = 0; a < track->markersnr; a++) {
+ copy_v2_v2(data->old_markers[a], track->markers[a].pos);
+ }
+ }
+ else if (action == SLIDE_ACTION_POS) {
+ data->corners = marker->pattern_corners;
+ data->pos = marker->pattern_corners[corner];
+ copy_v2_v2(data->spos, data->pos);
+ }
+ else if (action == SLIDE_ACTION_TILT_SIZE) {
+ data->corners = marker->pattern_corners;
+ slide_marker_tilt_slider(marker, data->spos);
+ }
+ }
+ else if (area == TRACK_AREA_SEARCH) {
+ data->min = marker->search_min;
+ data->max = marker->search_max;
+ }
+
+ data->mval[0] = event->mval[0];
+ data->mval[1] = event->mval[1];
+
+ data->width = width;
+ data->height = height;
+
+ if (action == SLIDE_ACTION_SIZE) {
+ data->lock = true;
+ }
+
+ /* Backup marker's settings. */
+ memcpy(data->old_corners, marker->pattern_corners, sizeof(data->old_corners));
+ copy_v2_v2(data->old_search_min, marker->search_min);
+ copy_v2_v2(data->old_search_max, marker->search_max);
+ copy_v2_v2(data->old_pos, marker->pos);
+ copy_v2_v2(data->old_offset, track->offset);
+
+ return data;
+}
+
+static float mouse_to_slide_zone_distance_squared(const float co[2],
+ const float slide_zone[2],
+ int width,
+ int height)
+{
+ float pixel_co[2] = {co[0] * width, co[1] * height},
+ pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
+ return SQUARE(pixel_co[0] - pixel_slide_zone[0]) + SQUARE(pixel_co[1] - pixel_slide_zone[1]);
}
static float mouse_to_search_corner_distance_squared(
- const MovieTrackingMarker *marker,
- const float co[2],
- int corner,
- int width,
- int height)
-{
- float side_zone[2];
- if (corner == 0) {
- side_zone[0] = marker->pos[0] + marker->search_max[0];
- side_zone[1] = marker->pos[1] + marker->search_min[1];
- }
- else {
- side_zone[0] = marker->pos[0] + marker->search_min[0];
- side_zone[1] = marker->pos[1] + marker->search_max[1];
- }
- return mouse_to_slide_zone_distance_squared(co,
- side_zone,
- width,
- height);
+ const MovieTrackingMarker *marker, const float co[2], int corner, int width, int height)
+{
+ float side_zone[2];
+ if (corner == 0) {
+ side_zone[0] = marker->pos[0] + marker->search_max[0];
+ side_zone[1] = marker->pos[1] + marker->search_min[1];
+ }
+ else {
+ side_zone[0] = marker->pos[0] + marker->search_min[0];
+ side_zone[1] = marker->pos[1] + marker->search_max[1];
+ }
+ return mouse_to_slide_zone_distance_squared(co, side_zone, width, height);
}
static float mouse_to_closest_pattern_corner_distance_squared(
- const MovieTrackingMarker *marker,
- const float co[2],
- int width,
- int height,
- int *r_corner)
-{
- float min_distance_squared = FLT_MAX;
- for (int i = 0; i < 4; i++) {
- float corner_co[2];
- add_v2_v2v2(corner_co, marker->pattern_corners[i], marker->pos);
- float distance_squared = mouse_to_slide_zone_distance_squared(co,
- corner_co,
- width,
- height);
- if (distance_squared < min_distance_squared) {
- min_distance_squared = distance_squared;
- *r_corner = i;
- }
- }
- return min_distance_squared;
+ const MovieTrackingMarker *marker, const float co[2], int width, int height, int *r_corner)
+{
+ float min_distance_squared = FLT_MAX;
+ for (int i = 0; i < 4; i++) {
+ float corner_co[2];
+ add_v2_v2v2(corner_co, marker->pattern_corners[i], marker->pos);
+ float distance_squared = mouse_to_slide_zone_distance_squared(co, corner_co, width, height);
+ if (distance_squared < min_distance_squared) {
+ min_distance_squared = distance_squared;
+ *r_corner = i;
+ }
+ }
+ return min_distance_squared;
}
static float mouse_to_offset_distance_squared(const MovieTrackingTrack *track,
@@ -518,12 +491,9 @@ static float mouse_to_offset_distance_squared(const MovieTrackingTrack *track,
int width,
int height)
{
- float pos[2];
- add_v2_v2v2(pos, marker->pos, track->offset);
- return mouse_to_slide_zone_distance_squared(co,
- pos,
- width,
- height);
+ float pos[2];
+ add_v2_v2v2(pos, marker->pos, track->offset);
+ return mouse_to_slide_zone_distance_squared(co, pos, width, height);
}
static int mouse_to_tilt_distance_squared(const MovieTrackingMarker *marker,
@@ -531,1719 +501,1614 @@ static int mouse_to_tilt_distance_squared(const MovieTrackingMarker *marker,
int width,
int height)
{
- float slider[2];
- slide_marker_tilt_slider(marker, slider);
- return mouse_to_slide_zone_distance_squared(co,
- slider,
- width,
- height);
+ float slider[2];
+ slide_marker_tilt_slider(marker, slider);
+ return mouse_to_slide_zone_distance_squared(co, slider, width, height);
}
static bool slide_check_corners(float (*corners)[2])
{
- int i, next, prev;
- float cross = 0.0f;
- float p[2] = {0.0f, 0.0f};
-
- if (!isect_point_quad_v2(p, corners[0], corners[1], corners[2], corners[3]))
- return false;
-
- for (i = 0; i < 4; i++) {
- float v1[2], v2[2], cur_cross;
-
- next = (i + 1) % 4;
- prev = (4 + i - 1) % 4;
-
- sub_v2_v2v2(v1, corners[i], corners[prev]);
- sub_v2_v2v2(v2, corners[next], corners[i]);
-
- cur_cross = cross_v2v2(v1, v2);
-
- if (fabsf(cur_cross) > FLT_EPSILON) {
- if (cross == 0.0f) {
- cross = cur_cross;
- }
- else if (cross * cur_cross < 0.0f) {
- return false;
- }
- }
- }
-
- return true;
-}
-
-MovieTrackingTrack *tracking_marker_check_slide(bContext *C,
- const wmEvent *event,
- int *area_r,
- int *action_r,
- int *corner_r)
-{
- const float distance_clip_squared = 12.0f * 12.0f;
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
-
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTrackingTrack *track;
- int width, height;
- float co[2];
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- float global_min_distance_squared = FLT_MAX;
-
- /* Sliding zone designator which is the closest to the mouse
- * across all the tracks.
- */
- int min_action = -1, min_area = 0, min_corner = -1;
- MovieTrackingTrack *min_track = NULL;
-
- ED_space_clip_get_size(sc, &width, &height);
-
- if (width == 0 || height == 0)
- return NULL;
-
- ED_clip_mouse_pos(sc, ar, event->mval, co);
-
- track = tracksbase->first;
- while (track) {
- if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
- const MovieTrackingMarker *marker = BKE_tracking_marker_get(track,
- framenr);
- /* Sliding zone designator which is the closest to the mouse for
- * the current tracks.
- */
- float min_distance_squared = FLT_MAX;
- int action = -1, area = 0, corner = -1;
-
- if ((marker->flag & MARKER_DISABLED) == 0) {
- float distance_squared;
-
- /* We start checking with whether the mouse is close enough
- * to the pattern offset area.
- */
- distance_squared = mouse_to_offset_distance_squared(track,
- marker,
- co,
- width,
- height);
- area = TRACK_AREA_POINT;
- action = SLIDE_ACTION_POS;
-
- /* NOTE: All checks here are assuming there's no maximum distance
- * limit, so checks are quite simple here.
- * Actual distance clipping happens later once all the sliding
- * zones are checked.
- */
- min_distance_squared = distance_squared;
-
- /* If search area is visible, check how close to it's sliding
- * zones mouse is.
- */
- if (sc->flag & SC_SHOW_MARKER_SEARCH) {
- distance_squared = mouse_to_search_corner_distance_squared(
- marker,
- co,
- 1,
- width,
- height);
- if (distance_squared < min_distance_squared) {
- area = TRACK_AREA_SEARCH;
- action = SLIDE_ACTION_OFFSET;
- min_distance_squared = distance_squared;
- }
-
- distance_squared = mouse_to_search_corner_distance_squared(
- marker,
- co,
- 0,
- width,
- height);
- if (distance_squared < min_distance_squared) {
- area = TRACK_AREA_SEARCH;
- action = SLIDE_ACTION_SIZE;
- min_distance_squared = distance_squared;
- }
- }
-
- /* If pattern area is visible, check which corner is closest to
- * the mouse.
- */
- if (sc->flag & SC_SHOW_MARKER_PATTERN) {
- int current_corner = -1;
- distance_squared =
- mouse_to_closest_pattern_corner_distance_squared(
- marker,
- co,
- width,
- height,
- &current_corner);
- if (distance_squared < min_distance_squared) {
- area = TRACK_AREA_PAT;
- action = SLIDE_ACTION_POS;
- corner = current_corner;
- min_distance_squared = distance_squared;
- }
-
- /* Here we also check whether the mouse is actually closer to
- * the widget which controls scale and tilt.
- */
- distance_squared = mouse_to_tilt_distance_squared(marker,
- co,
- width,
- height);
- if (distance_squared < min_distance_squared) {
- area = TRACK_AREA_PAT;
- action = SLIDE_ACTION_TILT_SIZE;
- min_distance_squared = distance_squared;
- }
- }
-
- if (min_distance_squared < global_min_distance_squared) {
- min_area = area;
- min_action = action;
- min_corner = corner;
- min_track = track;
- global_min_distance_squared = min_distance_squared;
- }
- }
- }
-
- track = track->next;
- }
-
- if (global_min_distance_squared < distance_clip_squared / sc->zoom) {
- if (area_r) {
- *area_r = min_area;
- }
- if (action_r) {
- *action_r = min_action;
- }
- if (corner_r) {
- *corner_r = min_corner;
- }
- return min_track;
- }
- return NULL;
+ int i, next, prev;
+ float cross = 0.0f;
+ float p[2] = {0.0f, 0.0f};
+
+ if (!isect_point_quad_v2(p, corners[0], corners[1], corners[2], corners[3]))
+ return false;
+
+ for (i = 0; i < 4; i++) {
+ float v1[2], v2[2], cur_cross;
+
+ next = (i + 1) % 4;
+ prev = (4 + i - 1) % 4;
+
+ sub_v2_v2v2(v1, corners[i], corners[prev]);
+ sub_v2_v2v2(v2, corners[next], corners[i]);
+
+ cur_cross = cross_v2v2(v1, v2);
+
+ if (fabsf(cur_cross) > FLT_EPSILON) {
+ if (cross == 0.0f) {
+ cross = cur_cross;
+ }
+ else if (cross * cur_cross < 0.0f) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+MovieTrackingTrack *tracking_marker_check_slide(
+ bContext *C, const wmEvent *event, int *area_r, int *action_r, int *corner_r)
+{
+ const float distance_clip_squared = 12.0f * 12.0f;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTrackingTrack *track;
+ int width, height;
+ float co[2];
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ float global_min_distance_squared = FLT_MAX;
+
+ /* Sliding zone designator which is the closest to the mouse
+ * across all the tracks.
+ */
+ int min_action = -1, min_area = 0, min_corner = -1;
+ MovieTrackingTrack *min_track = NULL;
+
+ ED_space_clip_get_size(sc, &width, &height);
+
+ if (width == 0 || height == 0)
+ return NULL;
+
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
+
+ track = tracksbase->first;
+ while (track) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
+ const MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ /* Sliding zone designator which is the closest to the mouse for
+ * the current tracks.
+ */
+ float min_distance_squared = FLT_MAX;
+ int action = -1, area = 0, corner = -1;
+
+ if ((marker->flag & MARKER_DISABLED) == 0) {
+ float distance_squared;
+
+ /* We start checking with whether the mouse is close enough
+ * to the pattern offset area.
+ */
+ distance_squared = mouse_to_offset_distance_squared(track, marker, co, width, height);
+ area = TRACK_AREA_POINT;
+ action = SLIDE_ACTION_POS;
+
+ /* NOTE: All checks here are assuming there's no maximum distance
+ * limit, so checks are quite simple here.
+ * Actual distance clipping happens later once all the sliding
+ * zones are checked.
+ */
+ min_distance_squared = distance_squared;
+
+ /* If search area is visible, check how close to it's sliding
+ * zones mouse is.
+ */
+ if (sc->flag & SC_SHOW_MARKER_SEARCH) {
+ distance_squared = mouse_to_search_corner_distance_squared(marker, co, 1, width, height);
+ if (distance_squared < min_distance_squared) {
+ area = TRACK_AREA_SEARCH;
+ action = SLIDE_ACTION_OFFSET;
+ min_distance_squared = distance_squared;
+ }
+
+ distance_squared = mouse_to_search_corner_distance_squared(marker, co, 0, width, height);
+ if (distance_squared < min_distance_squared) {
+ area = TRACK_AREA_SEARCH;
+ action = SLIDE_ACTION_SIZE;
+ min_distance_squared = distance_squared;
+ }
+ }
+
+ /* If pattern area is visible, check which corner is closest to
+ * the mouse.
+ */
+ if (sc->flag & SC_SHOW_MARKER_PATTERN) {
+ int current_corner = -1;
+ distance_squared = mouse_to_closest_pattern_corner_distance_squared(
+ marker, co, width, height, &current_corner);
+ if (distance_squared < min_distance_squared) {
+ area = TRACK_AREA_PAT;
+ action = SLIDE_ACTION_POS;
+ corner = current_corner;
+ min_distance_squared = distance_squared;
+ }
+
+ /* Here we also check whether the mouse is actually closer to
+ * the widget which controls scale and tilt.
+ */
+ distance_squared = mouse_to_tilt_distance_squared(marker, co, width, height);
+ if (distance_squared < min_distance_squared) {
+ area = TRACK_AREA_PAT;
+ action = SLIDE_ACTION_TILT_SIZE;
+ min_distance_squared = distance_squared;
+ }
+ }
+
+ if (min_distance_squared < global_min_distance_squared) {
+ min_area = area;
+ min_action = action;
+ min_corner = corner;
+ min_track = track;
+ global_min_distance_squared = min_distance_squared;
+ }
+ }
+ }
+
+ track = track->next;
+ }
+
+ if (global_min_distance_squared < distance_clip_squared / sc->zoom) {
+ if (area_r) {
+ *area_r = min_area;
+ }
+ if (action_r) {
+ *action_r = min_action;
+ }
+ if (corner_r) {
+ *corner_r = min_corner;
+ }
+ return min_track;
+ }
+ return NULL;
}
static void *slide_marker_customdata(bContext *C, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- MovieTrackingTrack *track;
- int width, height;
- float co[2];
- void *customdata = NULL;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- int area, action, corner;
+ MovieTrackingTrack *track;
+ int width, height;
+ float co[2];
+ void *customdata = NULL;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ int area, action, corner;
- ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_size(sc, &width, &height);
- if (width == 0 || height == 0) {
- return NULL;
- }
+ if (width == 0 || height == 0) {
+ return NULL;
+ }
- ED_clip_mouse_pos(sc, ar, event->mval, co);
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
- track = tracking_marker_check_slide(C, event, &area, &action, &corner);
- if (track != NULL) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
- customdata = create_slide_marker_data(sc,
- track,
- marker,
- event,
- area,
- corner,
- action,
- width,
- height);
- }
+ track = tracking_marker_check_slide(C, event, &area, &action, &corner);
+ if (track != NULL) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ customdata = create_slide_marker_data(
+ sc, track, marker, event, area, corner, action, width, height);
+ }
- return customdata;
+ return customdata;
}
static int slide_marker_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SlideMarkerData *slidedata = slide_marker_customdata(C, event);
- if (slidedata != NULL) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
+ SlideMarkerData *slidedata = slide_marker_customdata(C, event);
+ if (slidedata != NULL) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
- tracking->act_track = slidedata->track;
- tracking->act_plane_track = NULL;
+ tracking->act_track = slidedata->track;
+ tracking->act_plane_track = NULL;
- op->customdata = slidedata;
+ op->customdata = slidedata;
- clip_tracking_hide_cursor(C);
- WM_event_add_modal_handler(C, op);
+ clip_tracking_hide_cursor(C);
+ WM_event_add_modal_handler(C, op);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- return OPERATOR_RUNNING_MODAL;
- }
+ return OPERATOR_RUNNING_MODAL;
+ }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_PASS_THROUGH;
}
static void cancel_mouse_slide(SlideMarkerData *data)
{
- MovieTrackingTrack *track = data->track;
- MovieTrackingMarker *marker = data->marker;
+ MovieTrackingTrack *track = data->track;
+ MovieTrackingMarker *marker = data->marker;
- memcpy(marker->pattern_corners,
- data->old_corners,
- sizeof(marker->pattern_corners));
- copy_v2_v2(marker->search_min, data->old_search_min);
- copy_v2_v2(marker->search_max, data->old_search_max);
- copy_v2_v2(marker->pos, data->old_pos);
- copy_v2_v2(track->offset, data->old_offset);
+ memcpy(marker->pattern_corners, data->old_corners, sizeof(marker->pattern_corners));
+ copy_v2_v2(marker->search_min, data->old_search_min);
+ copy_v2_v2(marker->search_max, data->old_search_max);
+ copy_v2_v2(marker->pos, data->old_pos);
+ copy_v2_v2(track->offset, data->old_offset);
- if (data->old_markers != NULL) {
- for (int a = 0; a < data->track->markersnr; a++) {
- copy_v2_v2(data->track->markers[a].pos, data->old_markers[a]);
- }
- }
+ if (data->old_markers != NULL) {
+ for (int a = 0; a < data->track->markersnr; a++) {
+ copy_v2_v2(data->track->markers[a].pos, data->old_markers[a]);
+ }
+ }
}
static void apply_mouse_slide(bContext *C, SlideMarkerData *data)
{
- if (data->area == TRACK_AREA_POINT) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) {
- if (BKE_tracking_plane_track_has_point_track(plane_track,
- data->track))
- {
- BKE_tracking_track_plane_from_existing_motion(plane_track,
- framenr);
- }
- }
- }
- }
+ if (data->area == TRACK_AREA_POINT) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) {
+ if (BKE_tracking_plane_track_has_point_track(plane_track, data->track)) {
+ BKE_tracking_track_plane_from_existing_motion(plane_track, framenr);
+ }
+ }
+ }
+ }
}
static void free_slide_data(SlideMarkerData *data)
{
- if (data->old_markers != NULL) {
- MEM_freeN(data->old_markers);
- }
- MEM_freeN(data);
+ if (data->old_markers != NULL) {
+ MEM_freeN(data->old_markers);
+ }
+ MEM_freeN(data);
}
static int slide_marker_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
-
- SlideMarkerData *data = (SlideMarkerData *)op->customdata;
- float dx, dy, mdelta[2];
-
- switch (event->type) {
- case LEFTCTRLKEY:
- case RIGHTCTRLKEY:
- case LEFTSHIFTKEY:
- case RIGHTSHIFTKEY:
- if (data->action == SLIDE_ACTION_SIZE) {
- if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY)) {
- data->lock = event->val == KM_RELEASE;
- }
- }
-
- if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) {
- data->accurate = event->val == KM_PRESS;
- }
- ATTR_FALLTHROUGH;
- case MOUSEMOVE:
- mdelta[0] = event->mval[0] - data->mval[0];
- mdelta[1] = event->mval[1] - data->mval[1];
-
- dx = mdelta[0] / data->width / sc->zoom;
-
- if (data->lock) {
- dy = -dx / data->height * data->width;
- }
- else {
- dy = mdelta[1] / data->height / sc->zoom;
- }
-
- if (data->accurate) {
- dx /= 5.0f;
- dy /= 5.0f;
- }
-
- if (data->area == TRACK_AREA_POINT) {
- if (data->action == SLIDE_ACTION_OFFSET) {
- data->offset[0] = data->old_offset[0] + dx;
- data->offset[1] = data->old_offset[1] + dy;
- }
- else {
- data->pos[0] = data->old_pos[0] + dx;
- data->pos[1] = data->old_pos[1] + dy;
- }
-
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- DEG_id_tag_update(&sc->clip->id, 0);
- }
- else if (data->area == TRACK_AREA_PAT) {
- if (data->action == SLIDE_ACTION_SIZE) {
- float start[2], end[2];
- float scale;
-
- ED_clip_point_stable_pos(sc,
- ar,
- data->mval[0],
- data->mval[1],
- &start[0],
- &start[1]);
-
- sub_v2_v2(start, data->old_pos);
-
- if (len_squared_v2(start) != 0.0f) {
- float mval[2];
-
- if (data->accurate) {
- mval[0] = data->mval[0] + (event->mval[0] - data->mval[0]) / 5.0f;
- mval[1] = data->mval[1] + (event->mval[1] - data->mval[1]) / 5.0f;
- }
- else {
- mval[0] = event->mval[0];
- mval[1] = event->mval[1];
- }
-
- ED_clip_point_stable_pos(sc,
- ar,
- mval[0],
- mval[1],
- &end[0],
- &end[1]);
-
- sub_v2_v2(end, data->old_pos);
- scale = len_v2(end) / len_v2(start);
-
- if (scale > 0.0f) {
- for (int a = 0; a < 4; a++) {
- mul_v2_v2fl(data->corners[a],
- data->old_corners[a],
- scale);
- }
- }
- }
-
- BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
- }
- else if (data->action == SLIDE_ACTION_OFFSET) {
- float d[2] = {dx, dy};
- for (int a = 0; a < data->track->markersnr; a++) {
- add_v2_v2v2(data->track->markers[a].pos,
- data->old_markers[a],
- d);
- }
- sub_v2_v2v2(data->offset, data->old_offset, d);
- }
- else if (data->action == SLIDE_ACTION_POS) {
- float spos[2];
-
- copy_v2_v2(spos, data->pos);
-
- data->pos[0] = data->spos[0] + dx;
- data->pos[1] = data->spos[1] + dy;
-
- if (!slide_check_corners(data->corners)) {
- copy_v2_v2(data->pos, spos);
- }
-
- /* Currently only patterns are allowed to have such
- * combination of event and data.
- */
- BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
- }
- else if (data->action == SLIDE_ACTION_TILT_SIZE) {
- float start[2], end[2];
- float scale = 1.0f, angle = 0.0f;
- float mval[2];
-
- if (data->accurate) {
- mval[0] = data->mval[0] + (event->mval[0] - data->mval[0]) / 5.0f;
- mval[1] = data->mval[1] + (event->mval[1] - data->mval[1]) / 5.0f;
- }
- else {
- mval[0] = event->mval[0];
- mval[1] = event->mval[1];
- }
-
- sub_v2_v2v2(start, data->spos, data->old_pos);
-
- ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &end[0], &end[1]);
- sub_v2_v2(end, data->old_pos);
-
- if (len_squared_v2(start) != 0.0f) {
- scale = len_v2(end) / len_v2(start);
-
- if (scale < 0.0f) {
- scale = 0.0;
- }
- }
-
- angle = -angle_signed_v2v2(start, end);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ SlideMarkerData *data = (SlideMarkerData *)op->customdata;
+ float dx, dy, mdelta[2];
+
+ switch (event->type) {
+ case LEFTCTRLKEY:
+ case RIGHTCTRLKEY:
+ case LEFTSHIFTKEY:
+ case RIGHTSHIFTKEY:
+ if (data->action == SLIDE_ACTION_SIZE) {
+ if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY)) {
+ data->lock = event->val == KM_RELEASE;
+ }
+ }
+
+ if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) {
+ data->accurate = event->val == KM_PRESS;
+ }
+ ATTR_FALLTHROUGH;
+ case MOUSEMOVE:
+ mdelta[0] = event->mval[0] - data->mval[0];
+ mdelta[1] = event->mval[1] - data->mval[1];
+
+ dx = mdelta[0] / data->width / sc->zoom;
+
+ if (data->lock) {
+ dy = -dx / data->height * data->width;
+ }
+ else {
+ dy = mdelta[1] / data->height / sc->zoom;
+ }
+
+ if (data->accurate) {
+ dx /= 5.0f;
+ dy /= 5.0f;
+ }
+
+ if (data->area == TRACK_AREA_POINT) {
+ if (data->action == SLIDE_ACTION_OFFSET) {
+ data->offset[0] = data->old_offset[0] + dx;
+ data->offset[1] = data->old_offset[1] + dy;
+ }
+ else {
+ data->pos[0] = data->old_pos[0] + dx;
+ data->pos[1] = data->old_pos[1] + dy;
+ }
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ DEG_id_tag_update(&sc->clip->id, 0);
+ }
+ else if (data->area == TRACK_AREA_PAT) {
+ if (data->action == SLIDE_ACTION_SIZE) {
+ float start[2], end[2];
+ float scale;
+
+ ED_clip_point_stable_pos(sc, ar, data->mval[0], data->mval[1], &start[0], &start[1]);
+
+ sub_v2_v2(start, data->old_pos);
+
+ if (len_squared_v2(start) != 0.0f) {
+ float mval[2];
+
+ if (data->accurate) {
+ mval[0] = data->mval[0] + (event->mval[0] - data->mval[0]) / 5.0f;
+ mval[1] = data->mval[1] + (event->mval[1] - data->mval[1]) / 5.0f;
+ }
+ else {
+ mval[0] = event->mval[0];
+ mval[1] = event->mval[1];
+ }
+
+ ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &end[0], &end[1]);
+
+ sub_v2_v2(end, data->old_pos);
+ scale = len_v2(end) / len_v2(start);
+
+ if (scale > 0.0f) {
+ for (int a = 0; a < 4; a++) {
+ mul_v2_v2fl(data->corners[a], data->old_corners[a], scale);
+ }
+ }
+ }
+
+ BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
+ }
+ else if (data->action == SLIDE_ACTION_OFFSET) {
+ float d[2] = {dx, dy};
+ for (int a = 0; a < data->track->markersnr; a++) {
+ add_v2_v2v2(data->track->markers[a].pos, data->old_markers[a], d);
+ }
+ sub_v2_v2v2(data->offset, data->old_offset, d);
+ }
+ else if (data->action == SLIDE_ACTION_POS) {
+ float spos[2];
+
+ copy_v2_v2(spos, data->pos);
+
+ data->pos[0] = data->spos[0] + dx;
+ data->pos[1] = data->spos[1] + dy;
+
+ if (!slide_check_corners(data->corners)) {
+ copy_v2_v2(data->pos, spos);
+ }
+
+ /* Currently only patterns are allowed to have such
+ * combination of event and data.
+ */
+ BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
+ }
+ else if (data->action == SLIDE_ACTION_TILT_SIZE) {
+ float start[2], end[2];
+ float scale = 1.0f, angle = 0.0f;
+ float mval[2];
+
+ if (data->accurate) {
+ mval[0] = data->mval[0] + (event->mval[0] - data->mval[0]) / 5.0f;
+ mval[1] = data->mval[1] + (event->mval[1] - data->mval[1]) / 5.0f;
+ }
+ else {
+ mval[0] = event->mval[0];
+ mval[1] = event->mval[1];
+ }
+
+ sub_v2_v2v2(start, data->spos, data->old_pos);
+
+ ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &end[0], &end[1]);
+ sub_v2_v2(end, data->old_pos);
- for (int a = 0; a < 4; a++) {
- float vec[2];
+ if (len_squared_v2(start) != 0.0f) {
+ scale = len_v2(end) / len_v2(start);
- mul_v2_v2fl(data->corners[a], data->old_corners[a], scale);
+ if (scale < 0.0f) {
+ scale = 0.0;
+ }
+ }
- copy_v2_v2(vec, data->corners[a]);
- vec[0] *= data->width;
- vec[1] *= data->height;
+ angle = -angle_signed_v2v2(start, end);
- data->corners[a][0] = (vec[0] * cosf(angle) - vec[1] * sinf(angle)) / data->width;
- data->corners[a][1] = (vec[1] * cosf(angle) + vec[0] * sinf(angle)) / data->height;
- }
+ for (int a = 0; a < 4; a++) {
+ float vec[2];
- BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
+ mul_v2_v2fl(data->corners[a], data->old_corners[a], scale);
- }
- }
- else if (data->area == TRACK_AREA_SEARCH) {
- if (data->action == SLIDE_ACTION_SIZE) {
- data->min[0] = data->old_search_min[0] - dx;
- data->max[0] = data->old_search_max[0] + dx;
+ copy_v2_v2(vec, data->corners[a]);
+ vec[0] *= data->width;
+ vec[1] *= data->height;
- data->min[1] = data->old_search_min[1] + dy;
- data->max[1] = data->old_search_max[1] - dy;
+ data->corners[a][0] = (vec[0] * cosf(angle) - vec[1] * sinf(angle)) / data->width;
+ data->corners[a][1] = (vec[1] * cosf(angle) + vec[0] * sinf(angle)) / data->height;
+ }
- BKE_tracking_marker_clamp(data->marker, CLAMP_SEARCH_DIM);
- }
- else if (data->area == TRACK_AREA_SEARCH) {
- float d[2] = {dx, dy};
- add_v2_v2v2(data->min, data->old_search_min, d);
- add_v2_v2v2(data->max, data->old_search_max, d);
- }
+ BKE_tracking_marker_clamp(data->marker, CLAMP_PAT_DIM);
+ }
+ }
+ else if (data->area == TRACK_AREA_SEARCH) {
+ if (data->action == SLIDE_ACTION_SIZE) {
+ data->min[0] = data->old_search_min[0] - dx;
+ data->max[0] = data->old_search_max[0] + dx;
- BKE_tracking_marker_clamp(data->marker, CLAMP_SEARCH_POS);
- }
+ data->min[1] = data->old_search_min[1] + dy;
+ data->max[1] = data->old_search_max[1] - dy;
- data->marker->flag &= ~MARKER_TRACKED;
+ BKE_tracking_marker_clamp(data->marker, CLAMP_SEARCH_DIM);
+ }
+ else if (data->area == TRACK_AREA_SEARCH) {
+ float d[2] = {dx, dy};
+ add_v2_v2v2(data->min, data->old_search_min, d);
+ add_v2_v2v2(data->max, data->old_search_max, d);
+ }
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+ BKE_tracking_marker_clamp(data->marker, CLAMP_SEARCH_POS);
+ }
- break;
+ data->marker->flag &= ~MARKER_TRACKED;
- case LEFTMOUSE:
- if (event->val == KM_RELEASE) {
- apply_mouse_slide(C, op->customdata);
- free_slide_data(op->customdata);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
- clip_tracking_show_cursor(C);
+ break;
- return OPERATOR_FINISHED;
- }
+ case LEFTMOUSE:
+ if (event->val == KM_RELEASE) {
+ apply_mouse_slide(C, op->customdata);
+ free_slide_data(op->customdata);
- break;
+ clip_tracking_show_cursor(C);
- case ESCKEY:
- cancel_mouse_slide(op->customdata);
+ return OPERATOR_FINISHED;
+ }
- free_slide_data(op->customdata);
+ break;
- clip_tracking_show_cursor(C);
+ case ESCKEY:
+ cancel_mouse_slide(op->customdata);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+ free_slide_data(op->customdata);
- return OPERATOR_CANCELLED;
- }
+ clip_tracking_show_cursor(C);
- return OPERATOR_RUNNING_MODAL;
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+
+ return OPERATOR_CANCELLED;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
}
void CLIP_OT_slide_marker(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Slide Marker";
- ot->description = "Slide marker areas";
- ot->idname = "CLIP_OT_slide_marker";
+ /* identifiers */
+ ot->name = "Slide Marker";
+ ot->description = "Slide marker areas";
+ ot->idname = "CLIP_OT_slide_marker";
- /* api callbacks */
- ot->poll = ED_space_clip_tracking_poll;
- ot->invoke = slide_marker_invoke;
- ot->modal = slide_marker_modal;
+ /* api callbacks */
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->invoke = slide_marker_invoke;
+ ot->modal = slide_marker_modal;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
- /* properties */
- RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
- "Offset",
- "Offset in floating point units, 1.0 is the width and height of the image",
- -FLT_MAX, FLT_MAX);
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "offset",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Offset",
+ "Offset in floating point units, 1.0 is the width and height of the image",
+ -FLT_MAX,
+ FLT_MAX);
}
/********************** clear track operator *********************/
static int clear_track_path_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int action = RNA_enum_get(op->ptr, "action");
- const bool clear_active = RNA_boolean_get(op->ptr, "clear_active");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- if (clear_active) {
- MovieTrackingTrack *track = BKE_tracking_track_get_active(tracking);
- if (track != NULL) {
- BKE_tracking_track_path_clear(track, framenr, action);
- }
- }
- else {
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- BKE_tracking_track_path_clear(track, framenr, action);
- }
- }
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int action = RNA_enum_get(op->ptr, "action");
+ const bool clear_active = RNA_boolean_get(op->ptr, "clear_active");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ if (clear_active) {
+ MovieTrackingTrack *track = BKE_tracking_track_get_active(tracking);
+ if (track != NULL) {
+ BKE_tracking_track_path_clear(track, framenr, action);
+ }
+ }
+ else {
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ BKE_tracking_track_path_clear(track, framenr, action);
+ }
+ }
+ }
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_clear_track_path(wmOperatorType *ot)
{
- static const EnumPropertyItem clear_path_actions[] = {
- {TRACK_CLEAR_UPTO, "UPTO", 0, "Clear up-to", "Clear path up to current frame"},
- {TRACK_CLEAR_REMAINED, "REMAINED", 0, "Clear remained", "Clear path at remaining frames (after current)"},
- {TRACK_CLEAR_ALL, "ALL", 0, "Clear all", "Clear the whole path"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Clear Track Path";
- ot->description = "Clear tracks after/before current position or clear the whole track";
- ot->idname = "CLIP_OT_clear_track_path";
-
- /* api callbacks */
- ot->exec = clear_track_path_exec;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "action", clear_path_actions, TRACK_CLEAR_REMAINED, "Action", "Clear action to execute");
- RNA_def_boolean(ot->srna, "clear_active", 0, "Clear Active", "Clear active track only instead of all selected tracks");
+ static const EnumPropertyItem clear_path_actions[] = {
+ {TRACK_CLEAR_UPTO, "UPTO", 0, "Clear up-to", "Clear path up to current frame"},
+ {TRACK_CLEAR_REMAINED,
+ "REMAINED",
+ 0,
+ "Clear remained",
+ "Clear path at remaining frames (after current)"},
+ {TRACK_CLEAR_ALL, "ALL", 0, "Clear all", "Clear the whole path"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Clear Track Path";
+ ot->description = "Clear tracks after/before current position or clear the whole track";
+ ot->idname = "CLIP_OT_clear_track_path";
+
+ /* api callbacks */
+ ot->exec = clear_track_path_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(ot->srna,
+ "action",
+ clear_path_actions,
+ TRACK_CLEAR_REMAINED,
+ "Action",
+ "Clear action to execute");
+ RNA_def_boolean(ot->srna,
+ "clear_active",
+ 0,
+ "Clear Active",
+ "Clear active track only instead of all selected tracks");
}
/********************** disable markers operator *********************/
enum {
- MARKER_OP_DISABLE = 0,
- MARKER_OP_ENABLE = 1,
- MARKER_OP_TOGGLE = 2,
+ MARKER_OP_DISABLE = 0,
+ MARKER_OP_ENABLE = 1,
+ MARKER_OP_TOGGLE = 2,
};
static int disable_markers_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int action = RNA_enum_get(op->ptr, "action");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) &&
- (track->flag & TRACK_LOCKED) == 0)
- {
- MovieTrackingMarker *marker = BKE_tracking_marker_ensure(track, framenr);
- switch (action) {
- case MARKER_OP_DISABLE:
- marker->flag |= MARKER_DISABLED;
- break;
- case MARKER_OP_ENABLE:
- marker->flag &= ~MARKER_DISABLED;
- break;
- case MARKER_OP_TOGGLE:
- marker->flag ^= MARKER_DISABLED;
- break;
- }
- }
- }
-
- DEG_id_tag_update(&clip->id, 0);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int action = RNA_enum_get(op->ptr, "action");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_ensure(track, framenr);
+ switch (action) {
+ case MARKER_OP_DISABLE:
+ marker->flag |= MARKER_DISABLED;
+ break;
+ case MARKER_OP_ENABLE:
+ marker->flag &= ~MARKER_DISABLED;
+ break;
+ case MARKER_OP_TOGGLE:
+ marker->flag ^= MARKER_DISABLED;
+ break;
+ }
+ }
+ }
+
+ DEG_id_tag_update(&clip->id, 0);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_disable_markers(wmOperatorType *ot)
{
- static const EnumPropertyItem actions_items[] = {
- {MARKER_OP_DISABLE, "DISABLE", 0, "Disable",
- "Disable selected markers"},
- {MARKER_OP_ENABLE, "ENABLE", 0, "Enable",
- "Enable selected markers"},
- {MARKER_OP_TOGGLE, "TOGGLE", 0, "Toggle",
- "Toggle disabled flag for selected markers"},
- {0, NULL, 0, NULL, NULL},
- };
+ static const EnumPropertyItem actions_items[] = {
+ {MARKER_OP_DISABLE, "DISABLE", 0, "Disable", "Disable selected markers"},
+ {MARKER_OP_ENABLE, "ENABLE", 0, "Enable", "Enable selected markers"},
+ {MARKER_OP_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle disabled flag for selected markers"},
+ {0, NULL, 0, NULL, NULL},
+ };
- /* identifiers */
- ot->name = "Disable Markers";
- ot->description = "Disable/enable selected markers";
- ot->idname = "CLIP_OT_disable_markers";
+ /* identifiers */
+ ot->name = "Disable Markers";
+ ot->description = "Disable/enable selected markers";
+ ot->idname = "CLIP_OT_disable_markers";
- /* api callbacks */
- ot->exec = disable_markers_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = disable_markers_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Disable action to execute");
+ /* properties */
+ RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Disable action to execute");
}
/********************** set principal center operator *********************/
static int set_center_principal_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int width, height;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int width, height;
- BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
- if (width == 0 || height == 0) {
- return OPERATOR_CANCELLED;
- }
+ if (width == 0 || height == 0) {
+ return OPERATOR_CANCELLED;
+ }
- clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
- clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
+ clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
+ clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_center_principal(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Principal to Center";
- ot->description = "Set optical center to center of footage";
- ot->idname = "CLIP_OT_set_center_principal";
+ /* identifiers */
+ ot->name = "Set Principal to Center";
+ ot->description = "Set optical center to center of footage";
+ ot->idname = "CLIP_OT_set_center_principal";
- /* api callbacks */
- ot->exec = set_center_principal_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = set_center_principal_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** hide tracks operator *********************/
static int hide_tracks_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- int unselected;
-
- unselected = RNA_boolean_get(op->ptr, "unselected");
-
- /* Hide point tracks. */
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (unselected == 0 && TRACK_VIEW_SELECTED(sc, track)) {
- track->flag |= TRACK_HIDDEN;
- }
- else if (unselected == 1 && !TRACK_VIEW_SELECTED(sc, track)) {
- track->flag |= TRACK_HIDDEN;
- }
- }
-
- if (act_track != NULL && act_track->flag & TRACK_HIDDEN) {
- clip->tracking.act_track = NULL;
- }
-
- /* Hide place tracks. */
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- MovieTrackingPlaneTrack *act_plane_track =
- BKE_tracking_plane_track_get_active(tracking);
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- if (unselected == 0 && plane_track->flag & SELECT) {
- plane_track->flag |= PLANE_TRACK_HIDDEN;
- }
- else if (unselected == 1 && (plane_track->flag & SELECT) == 0) {
- plane_track->flag |= PLANE_TRACK_HIDDEN;
- }
- }
- if (act_plane_track != NULL && act_plane_track->flag & TRACK_HIDDEN) {
- clip->tracking.act_plane_track = NULL;
- }
-
- if (unselected == 0) {
- /* No selection on screen now, unlock view so it can be
- * scrolled nice again.
- */
- sc->flag &= ~SC_LOCK_SELECTION;
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ int unselected;
+
+ unselected = RNA_boolean_get(op->ptr, "unselected");
+
+ /* Hide point tracks. */
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (unselected == 0 && TRACK_VIEW_SELECTED(sc, track)) {
+ track->flag |= TRACK_HIDDEN;
+ }
+ else if (unselected == 1 && !TRACK_VIEW_SELECTED(sc, track)) {
+ track->flag |= TRACK_HIDDEN;
+ }
+ }
+
+ if (act_track != NULL && act_track->flag & TRACK_HIDDEN) {
+ clip->tracking.act_track = NULL;
+ }
+
+ /* Hide place tracks. */
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ MovieTrackingPlaneTrack *act_plane_track = BKE_tracking_plane_track_get_active(tracking);
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ if (unselected == 0 && plane_track->flag & SELECT) {
+ plane_track->flag |= PLANE_TRACK_HIDDEN;
+ }
+ else if (unselected == 1 && (plane_track->flag & SELECT) == 0) {
+ plane_track->flag |= PLANE_TRACK_HIDDEN;
+ }
+ }
+ if (act_plane_track != NULL && act_plane_track->flag & TRACK_HIDDEN) {
+ clip->tracking.act_plane_track = NULL;
+ }
+
+ if (unselected == 0) {
+ /* No selection on screen now, unlock view so it can be
+ * scrolled nice again.
+ */
+ sc->flag &= ~SC_LOCK_SELECTION;
+ }
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_hide_tracks(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Hide Tracks";
- ot->description = "Hide selected tracks";
- ot->idname = "CLIP_OT_hide_tracks";
+ /* identifiers */
+ ot->name = "Hide Tracks";
+ ot->description = "Hide selected tracks";
+ ot->idname = "CLIP_OT_hide_tracks";
- /* api callbacks */
- ot->exec = hide_tracks_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = hide_tracks_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected tracks");
+ /* properties */
+ RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected tracks");
}
/********************** hide tracks clear operator *********************/
static int hide_tracks_clear_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
- /* Unhide point tracks. */
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- track->flag &= ~TRACK_HIDDEN;
- }
+ /* Unhide point tracks. */
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ track->flag &= ~TRACK_HIDDEN;
+ }
- /* Unhide plane tracks. */
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- plane_track->flag &= ~PLANE_TRACK_HIDDEN;
- }
+ /* Unhide plane tracks. */
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ plane_track->flag &= ~PLANE_TRACK_HIDDEN;
+ }
- BKE_tracking_dopesheet_tag_update(tracking);
+ BKE_tracking_dopesheet_tag_update(tracking);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_hide_tracks_clear(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Hide Tracks Clear";
- ot->description = "Clear hide selected tracks";
- ot->idname = "CLIP_OT_hide_tracks_clear";
+ /* identifiers */
+ ot->name = "Hide Tracks Clear";
+ ot->description = "Clear hide selected tracks";
+ ot->idname = "CLIP_OT_hide_tracks_clear";
- /* api callbacks */
- ot->exec = hide_tracks_clear_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = hide_tracks_clear_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** frame jump operator *********************/
static int frame_jump_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- int pos = RNA_enum_get(op->ptr, "position");
- int delta;
-
- if (pos <= 1) { /* jump to path */
- MovieTrackingTrack *track = BKE_tracking_track_get_active(tracking);
- if (track == NULL) {
- return OPERATOR_CANCELLED;
- }
-
- delta = pos == 1 ? 1 : -1;
- while (sc->user.framenr + delta >= SFRA &&
- sc->user.framenr + delta <= EFRA)
- {
- int framenr = BKE_movieclip_remap_scene_to_clip_frame(
- clip,
- sc->user.framenr + delta);
- MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track,
- framenr);
-
- if (marker == NULL || marker->flag & MARKER_DISABLED) {
- break;
- }
-
- sc->user.framenr += delta;
- }
- }
- else { /* to failed frame */
- if (tracking->reconstruction.flag & TRACKING_RECONSTRUCTED) {
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
-
- delta = pos == 3 ? 1 : -1;
- framenr += delta;
-
- while (framenr + delta >= SFRA &&
- framenr + delta <= EFRA)
- {
- MovieReconstructedCamera *cam =
- BKE_tracking_camera_get_reconstructed(tracking,
- object,
- framenr);
-
- if (cam == NULL) {
- sc->user.framenr =
- BKE_movieclip_remap_clip_to_scene_frame(clip,
- framenr);
- break;
- }
-
- framenr += delta;
- }
- }
- }
-
- if (CFRA != sc->user.framenr) {
- CFRA = sc->user.framenr;
- BKE_sound_seek_scene(CTX_data_main(C), scene);
-
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
-
- return OPERATOR_FINISHED;
+ Scene *scene = CTX_data_scene(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ int pos = RNA_enum_get(op->ptr, "position");
+ int delta;
+
+ if (pos <= 1) { /* jump to path */
+ MovieTrackingTrack *track = BKE_tracking_track_get_active(tracking);
+ if (track == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ delta = pos == 1 ? 1 : -1;
+ while (sc->user.framenr + delta >= SFRA && sc->user.framenr + delta <= EFRA) {
+ int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr + delta);
+ MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
+
+ if (marker == NULL || marker->flag & MARKER_DISABLED) {
+ break;
+ }
+
+ sc->user.framenr += delta;
+ }
+ }
+ else { /* to failed frame */
+ if (tracking->reconstruction.flag & TRACKING_RECONSTRUCTED) {
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+
+ delta = pos == 3 ? 1 : -1;
+ framenr += delta;
+
+ while (framenr + delta >= SFRA && framenr + delta <= EFRA) {
+ MovieReconstructedCamera *cam = BKE_tracking_camera_get_reconstructed(
+ tracking, object, framenr);
+
+ if (cam == NULL) {
+ sc->user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, framenr);
+ break;
+ }
+
+ framenr += delta;
+ }
+ }
+ }
+
+ if (CFRA != sc->user.framenr) {
+ CFRA = sc->user.framenr;
+ BKE_sound_seek_scene(CTX_data_main(C), scene);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_frame_jump(wmOperatorType *ot)
{
- static const EnumPropertyItem position_items[] = {
- {0, "PATHSTART", 0, "Path Start", "Jump to start of current path"},
- {1, "PATHEND", 0, "Path End", "Jump to end of current path"},
- {2, "FAILEDPREV", 0, "Previous Failed", "Jump to previous failed frame"},
- {2, "FAILNEXT", 0, "Next Failed", "Jump to next failed frame"},
- {0, NULL, 0, NULL, NULL},
- };
+ static const EnumPropertyItem position_items[] = {
+ {0, "PATHSTART", 0, "Path Start", "Jump to start of current path"},
+ {1, "PATHEND", 0, "Path End", "Jump to end of current path"},
+ {2, "FAILEDPREV", 0, "Previous Failed", "Jump to previous failed frame"},
+ {2, "FAILNEXT", 0, "Next Failed", "Jump to next failed frame"},
+ {0, NULL, 0, NULL, NULL},
+ };
- /* identifiers */
- ot->name = "Jump to Frame";
- ot->description = "Jump to special frame";
- ot->idname = "CLIP_OT_frame_jump";
+ /* identifiers */
+ ot->name = "Jump to Frame";
+ ot->description = "Jump to special frame";
+ ot->idname = "CLIP_OT_frame_jump";
- /* api callbacks */
- ot->exec = frame_jump_exec;
- ot->poll = ED_space_clip_poll;
+ /* api callbacks */
+ ot->exec = frame_jump_exec;
+ ot->poll = ED_space_clip_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_enum(ot->srna, "position", position_items, 0, "Position",
- "Position to jump to");
+ /* properties */
+ RNA_def_enum(ot->srna, "position", position_items, 0, "Position", "Position to jump to");
}
/********************** join tracks operator *********************/
static int join_tracks_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingStabilization *stab = &tracking->stabilization;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- bool update_stabilization = false;
-
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- if (act_track == NULL) {
- BKE_report(op->reports, RPT_ERROR, "No active track to join to");
- return OPERATOR_CANCELLED;
- }
-
- GSet *point_tracks = BLI_gset_ptr_new(__func__);
-
- for (MovieTrackingTrack *track = tracksbase->first, *next_track;
- track != NULL;
- track = next_track)
- {
- next_track = track->next;
- if (TRACK_VIEW_SELECTED(sc, track) && track != act_track) {
- BKE_tracking_tracks_join(tracking, act_track, track);
-
- if (track->flag & TRACK_USE_2D_STAB) {
- update_stabilization = true;
- if ((act_track->flag & TRACK_USE_2D_STAB) == 0) {
- act_track->flag |= TRACK_USE_2D_STAB;
- }
- else {
- stab->tot_track--;
- }
- BLI_assert(0 <= stab->tot_track);
- }
- if (track->flag & TRACK_USE_2D_STAB_ROT) {
- update_stabilization = true;
- if ((act_track->flag & TRACK_USE_2D_STAB_ROT) == 0) {
- act_track->flag |= TRACK_USE_2D_STAB_ROT;
- }
- else {
- stab->tot_rot_track--;
- }
- BLI_assert(0 <= stab->tot_rot_track);
- }
-
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- if (BKE_tracking_plane_track_has_point_track(plane_track, track)) {
- BKE_tracking_plane_track_replace_point_track(plane_track,
- track,
- act_track);
- if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) {
- BLI_gset_insert(point_tracks, plane_track);
- }
- }
- }
-
- BKE_tracking_track_free(track);
- BLI_freelinkN(tracksbase, track);
- }
- }
-
- if (update_stabilization) {
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
-
- GSetIterator gs_iter;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- GSET_ITER (gs_iter, point_tracks) {
- MovieTrackingPlaneTrack *plane_track = BLI_gsetIterator_getKey(&gs_iter);
- BKE_tracking_track_plane_from_existing_motion( plane_track, framenr);
- }
-
- BLI_gset_free(point_tracks, NULL);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingStabilization *stab = &tracking->stabilization;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ bool update_stabilization = false;
+
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ if (act_track == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No active track to join to");
+ return OPERATOR_CANCELLED;
+ }
+
+ GSet *point_tracks = BLI_gset_ptr_new(__func__);
+
+ for (MovieTrackingTrack *track = tracksbase->first, *next_track; track != NULL;
+ track = next_track) {
+ next_track = track->next;
+ if (TRACK_VIEW_SELECTED(sc, track) && track != act_track) {
+ BKE_tracking_tracks_join(tracking, act_track, track);
+
+ if (track->flag & TRACK_USE_2D_STAB) {
+ update_stabilization = true;
+ if ((act_track->flag & TRACK_USE_2D_STAB) == 0) {
+ act_track->flag |= TRACK_USE_2D_STAB;
+ }
+ else {
+ stab->tot_track--;
+ }
+ BLI_assert(0 <= stab->tot_track);
+ }
+ if (track->flag & TRACK_USE_2D_STAB_ROT) {
+ update_stabilization = true;
+ if ((act_track->flag & TRACK_USE_2D_STAB_ROT) == 0) {
+ act_track->flag |= TRACK_USE_2D_STAB_ROT;
+ }
+ else {
+ stab->tot_rot_track--;
+ }
+ BLI_assert(0 <= stab->tot_rot_track);
+ }
+
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ if (BKE_tracking_plane_track_has_point_track(plane_track, track)) {
+ BKE_tracking_plane_track_replace_point_track(plane_track, track, act_track);
+ if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) {
+ BLI_gset_insert(point_tracks, plane_track);
+ }
+ }
+ }
+
+ BKE_tracking_track_free(track);
+ BLI_freelinkN(tracksbase, track);
+ }
+ }
+
+ if (update_stabilization) {
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+
+ GSetIterator gs_iter;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ GSET_ITER (gs_iter, point_tracks) {
+ MovieTrackingPlaneTrack *plane_track = BLI_gsetIterator_getKey(&gs_iter);
+ BKE_tracking_track_plane_from_existing_motion(plane_track, framenr);
+ }
+
+ BLI_gset_free(point_tracks, NULL);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_join_tracks(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Join Tracks";
- ot->description = "Join selected tracks";
- ot->idname = "CLIP_OT_join_tracks";
+ /* identifiers */
+ ot->name = "Join Tracks";
+ ot->description = "Join selected tracks";
+ ot->idname = "CLIP_OT_join_tracks";
- /* api callbacks */
- ot->exec = join_tracks_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = join_tracks_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** lock tracks operator *********************/
enum {
- TRACK_ACTION_LOCK = 0,
- TRACK_ACTION_UNLOCK = 1,
- TRACK_ACTION_TOGGLE = 2,
+ TRACK_ACTION_LOCK = 0,
+ TRACK_ACTION_UNLOCK = 1,
+ TRACK_ACTION_TOGGLE = 2,
};
static int lock_tracks_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int action = RNA_enum_get(op->ptr, "action");
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- switch (action) {
- case TRACK_ACTION_LOCK:
- track->flag |= TRACK_LOCKED;
- break;
- case TRACK_ACTION_UNLOCK:
- track->flag &= ~TRACK_LOCKED;
- break;
- case TRACK_ACTION_TOGGLE:
- track->flag ^= TRACK_LOCKED;
- break;
- }
- }
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int action = RNA_enum_get(op->ptr, "action");
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ switch (action) {
+ case TRACK_ACTION_LOCK:
+ track->flag |= TRACK_LOCKED;
+ break;
+ case TRACK_ACTION_UNLOCK:
+ track->flag &= ~TRACK_LOCKED;
+ break;
+ case TRACK_ACTION_TOGGLE:
+ track->flag ^= TRACK_LOCKED;
+ break;
+ }
+ }
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_lock_tracks(wmOperatorType *ot)
{
- static const EnumPropertyItem actions_items[] = {
- {TRACK_ACTION_LOCK, "LOCK", 0, "Lock", "Lock selected tracks"},
- {TRACK_ACTION_UNLOCK, "UNLOCK", 0, "Unlock", "Unlock selected tracks"},
- {TRACK_ACTION_TOGGLE, "TOGGLE", 0, "Toggle",
- "Toggle locked flag for selected tracks"},
- {0, NULL, 0, NULL, NULL},
- };
+ static const EnumPropertyItem actions_items[] = {
+ {TRACK_ACTION_LOCK, "LOCK", 0, "Lock", "Lock selected tracks"},
+ {TRACK_ACTION_UNLOCK, "UNLOCK", 0, "Unlock", "Unlock selected tracks"},
+ {TRACK_ACTION_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle locked flag for selected tracks"},
+ {0, NULL, 0, NULL, NULL},
+ };
- /* identifiers */
- ot->name = "Lock Tracks";
- ot->description = "Lock/unlock selected tracks";
- ot->idname = "CLIP_OT_lock_tracks";
+ /* identifiers */
+ ot->name = "Lock Tracks";
+ ot->description = "Lock/unlock selected tracks";
+ ot->idname = "CLIP_OT_lock_tracks";
- /* api callbacks */
- ot->exec = lock_tracks_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = lock_tracks_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_enum(ot->srna, "action", actions_items, 0, "Action",
- "Lock action to execute");
+ /* properties */
+ RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Lock action to execute");
}
/********************** set keyframe operator *********************/
enum {
- SOLVER_KEYFRAME_A = 0,
- SOLVER_KEYFRAME_B = 1,
+ SOLVER_KEYFRAME_A = 0,
+ SOLVER_KEYFRAME_B = 1,
};
static int set_solver_keyframe_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- int keyframe = RNA_enum_get(op->ptr, "keyframe");
- int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip,
- sc->user.framenr);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ int keyframe = RNA_enum_get(op->ptr, "keyframe");
+ int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr);
- if (keyframe == SOLVER_KEYFRAME_A) {
- object->keyframe1 = framenr;
- }
- else {
- object->keyframe2 = framenr;
- }
+ if (keyframe == SOLVER_KEYFRAME_A) {
+ object->keyframe1 = framenr;
+ }
+ else {
+ object->keyframe2 = framenr;
+ }
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_solver_keyframe(wmOperatorType *ot)
{
- static const EnumPropertyItem keyframe_items[] = {
- {SOLVER_KEYFRAME_A, "KEYFRAME_A", 0, "Keyframe A", ""},
- {SOLVER_KEYFRAME_B, "KEYFRAME_B", 0, "Keyframe B", ""},
- {0, NULL, 0, NULL, NULL},
- };
+ static const EnumPropertyItem keyframe_items[] = {
+ {SOLVER_KEYFRAME_A, "KEYFRAME_A", 0, "Keyframe A", ""},
+ {SOLVER_KEYFRAME_B, "KEYFRAME_B", 0, "Keyframe B", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
- /* identifiers */
- ot->name = "Set Solver Keyframe";
- ot->description = "Set keyframe used by solver";
- ot->idname = "CLIP_OT_set_solver_keyframe";
+ /* identifiers */
+ ot->name = "Set Solver Keyframe";
+ ot->description = "Set keyframe used by solver";
+ ot->idname = "CLIP_OT_set_solver_keyframe";
- /* api callbacks */
- ot->exec = set_solver_keyframe_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = set_solver_keyframe_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_enum(ot->srna, "keyframe", keyframe_items, 0, "Keyframe",
- "Keyframe to set");
+ /* properties */
+ RNA_def_enum(ot->srna, "keyframe", keyframe_items, 0, "Keyframe", "Keyframe to set");
}
/********************** track copy color operator *********************/
static int track_copy_color_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- if (act_track == NULL) {
- return OPERATOR_CANCELLED;
- }
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ if (act_track == NULL) {
+ return OPERATOR_CANCELLED;
+ }
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) && track != act_track) {
- track->flag &= ~TRACK_CUSTOMCOLOR;
- if (act_track->flag & TRACK_CUSTOMCOLOR) {
- copy_v3_v3(track->color, act_track->color);
- track->flag |= TRACK_CUSTOMCOLOR;
- }
- }
- }
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && track != act_track) {
+ track->flag &= ~TRACK_CUSTOMCOLOR;
+ if (act_track->flag & TRACK_CUSTOMCOLOR) {
+ copy_v3_v3(track->color, act_track->color);
+ track->flag |= TRACK_CUSTOMCOLOR;
+ }
+ }
+ }
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_track_copy_color(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Copy Color";
- ot->description = "Copy color to all selected tracks";
- ot->idname = "CLIP_OT_track_copy_color";
+ /* identifiers */
+ ot->name = "Copy Color";
+ ot->description = "Copy color to all selected tracks";
+ ot->idname = "CLIP_OT_track_copy_color";
- /* api callbacks */
- ot->exec = track_copy_color_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = track_copy_color_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** clean tracks operator *********************/
static bool is_track_clean(MovieTrackingTrack *track, int frames, int del)
{
- bool ok = true;
- int prev = -1, count = 0;
- MovieTrackingMarker *markers = track->markers, *new_markers = NULL;
- int start_disabled = 0;
- int markersnr = track->markersnr;
-
- if (del) {
- new_markers = MEM_callocN(markersnr * sizeof(MovieTrackingMarker),
- "track cleaned markers");
- }
-
- for (int a = 0; a < markersnr; a++) {
- int end = 0;
-
- if (prev == -1) {
- if ((markers[a].flag & MARKER_DISABLED) == 0) {
- prev = a;
- }
- else {
- start_disabled = 1;
- }
- }
-
- if (prev >= 0) {
- end = a == markersnr - 1;
- end |= (a < markersnr - 1) && (markers[a].framenr != markers[a + 1].framenr - 1 ||
- markers[a].flag & MARKER_DISABLED);
- }
-
- if (end) {
- int segok = 1, len = 0;
-
- if (a != prev && markers[a].framenr != markers[a - 1].framenr + 1) {
- len = a - prev;
- }
- else if (markers[a].flag & MARKER_DISABLED) {
- len = a - prev;
- }
- else {
- len = a - prev + 1;
- }
-
- if (frames) {
- if (len < frames) {
- segok = 0;
- ok = 0;
-
- if (!del) {
- break;
- }
- }
- }
-
- if (del) {
- if (segok) {
- int t = len;
-
- if (markers[a].flag & MARKER_DISABLED) {
- t++;
- }
-
- /* Place disabled marker in front of current segment. */
- if (start_disabled) {
- memcpy(new_markers + count,
- markers + prev,
- sizeof(MovieTrackingMarker));
- new_markers[count].framenr--;
- new_markers[count].flag |= MARKER_DISABLED;
-
- count++;
- start_disabled = 0;
- }
-
- memcpy(new_markers + count,
- markers + prev,
- t * sizeof(MovieTrackingMarker));
- count += t;
- }
- else if (markers[a].flag & MARKER_DISABLED) {
- /* Current segment which would be deleted was finished by
- * disabled marker, so next segment should be started from
- * disabled marker.
- */
- start_disabled = 1;
- }
- }
-
- prev = -1;
- }
- }
-
- if (del && count == 0) {
- ok = 0;
- }
-
- if (del) {
- MEM_freeN(track->markers);
-
- if (count) {
- track->markers = new_markers;
- }
- else {
- track->markers = NULL;
- MEM_freeN(new_markers);
- }
-
- track->markersnr = count;
- }
-
- return ok;
+ bool ok = true;
+ int prev = -1, count = 0;
+ MovieTrackingMarker *markers = track->markers, *new_markers = NULL;
+ int start_disabled = 0;
+ int markersnr = track->markersnr;
+
+ if (del) {
+ new_markers = MEM_callocN(markersnr * sizeof(MovieTrackingMarker), "track cleaned markers");
+ }
+
+ for (int a = 0; a < markersnr; a++) {
+ int end = 0;
+
+ if (prev == -1) {
+ if ((markers[a].flag & MARKER_DISABLED) == 0) {
+ prev = a;
+ }
+ else {
+ start_disabled = 1;
+ }
+ }
+
+ if (prev >= 0) {
+ end = a == markersnr - 1;
+ end |= (a < markersnr - 1) && (markers[a].framenr != markers[a + 1].framenr - 1 ||
+ markers[a].flag & MARKER_DISABLED);
+ }
+
+ if (end) {
+ int segok = 1, len = 0;
+
+ if (a != prev && markers[a].framenr != markers[a - 1].framenr + 1) {
+ len = a - prev;
+ }
+ else if (markers[a].flag & MARKER_DISABLED) {
+ len = a - prev;
+ }
+ else {
+ len = a - prev + 1;
+ }
+
+ if (frames) {
+ if (len < frames) {
+ segok = 0;
+ ok = 0;
+
+ if (!del) {
+ break;
+ }
+ }
+ }
+
+ if (del) {
+ if (segok) {
+ int t = len;
+
+ if (markers[a].flag & MARKER_DISABLED) {
+ t++;
+ }
+
+ /* Place disabled marker in front of current segment. */
+ if (start_disabled) {
+ memcpy(new_markers + count, markers + prev, sizeof(MovieTrackingMarker));
+ new_markers[count].framenr--;
+ new_markers[count].flag |= MARKER_DISABLED;
+
+ count++;
+ start_disabled = 0;
+ }
+
+ memcpy(new_markers + count, markers + prev, t * sizeof(MovieTrackingMarker));
+ count += t;
+ }
+ else if (markers[a].flag & MARKER_DISABLED) {
+ /* Current segment which would be deleted was finished by
+ * disabled marker, so next segment should be started from
+ * disabled marker.
+ */
+ start_disabled = 1;
+ }
+ }
+
+ prev = -1;
+ }
+ }
+
+ if (del && count == 0) {
+ ok = 0;
+ }
+
+ if (del) {
+ MEM_freeN(track->markers);
+
+ if (count) {
+ track->markers = new_markers;
+ }
+ else {
+ track->markers = NULL;
+ MEM_freeN(new_markers);
+ }
+
+ track->markersnr = count;
+ }
+
+ return ok;
}
static int clean_tracks_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- int frames = RNA_int_get(op->ptr, "frames");
- int action = RNA_enum_get(op->ptr, "action");
- float error = RNA_float_get(op->ptr, "error");
-
- if (error && action == TRACKING_CLEAN_DELETE_SEGMENT) {
- action = TRACKING_CLEAN_DELETE_TRACK;
- }
-
- for (MovieTrackingTrack *track = tracksbase->first, *next_track;
- track != NULL;
- track = next_track)
- {
- next_track = track->next;
-
- if ((track->flag & TRACK_HIDDEN) == 0 &&
- (track->flag & TRACK_LOCKED) == 0)
- {
- bool ok;
-
- ok = (is_track_clean(track,
- frames,
- action == TRACKING_CLEAN_DELETE_SEGMENT)) &&
- ((error == 0.0f) ||
- (track->flag & TRACK_HAS_BUNDLE) == 0 ||
- (track->error < error));
-
- if (!ok) {
- if (action == TRACKING_CLEAN_SELECT) {
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- }
- else if (action == TRACKING_CLEAN_DELETE_TRACK) {
- if (track == act_track) {
- clip->tracking.act_track = NULL;
- }
- BKE_tracking_track_free(track);
- BLI_freelinkN(tracksbase, track);
- track = NULL;
- }
-
- /* Happens when all tracking segments are not long enough. */
- if (track && track->markersnr == 0) {
- if (track == act_track) {
- clip->tracking.act_track = NULL;
- }
- BKE_tracking_track_free(track);
- BLI_freelinkN(tracksbase, track);
- }
- }
- }
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
-
- return OPERATOR_FINISHED;
-}
-
-static int clean_tracks_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
-{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
-
- if (!RNA_struct_property_is_set(op->ptr, "frames")) {
- RNA_int_set(op->ptr, "frames", clip->tracking.settings.clean_frames);
- }
-
- if (!RNA_struct_property_is_set(op->ptr, "error")) {
- RNA_float_set(op->ptr, "error", clip->tracking.settings.clean_error);
- }
-
- if (!RNA_struct_property_is_set(op->ptr, "action")) {
- RNA_enum_set(op->ptr, "action", clip->tracking.settings.clean_action);
- }
-
- return clean_tracks_exec(C, op);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ int frames = RNA_int_get(op->ptr, "frames");
+ int action = RNA_enum_get(op->ptr, "action");
+ float error = RNA_float_get(op->ptr, "error");
+
+ if (error && action == TRACKING_CLEAN_DELETE_SEGMENT) {
+ action = TRACKING_CLEAN_DELETE_TRACK;
+ }
+
+ for (MovieTrackingTrack *track = tracksbase->first, *next_track; track != NULL;
+ track = next_track) {
+ next_track = track->next;
+
+ if ((track->flag & TRACK_HIDDEN) == 0 && (track->flag & TRACK_LOCKED) == 0) {
+ bool ok;
+
+ ok = (is_track_clean(track, frames, action == TRACKING_CLEAN_DELETE_SEGMENT)) &&
+ ((error == 0.0f) || (track->flag & TRACK_HAS_BUNDLE) == 0 || (track->error < error));
+
+ if (!ok) {
+ if (action == TRACKING_CLEAN_SELECT) {
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ }
+ else if (action == TRACKING_CLEAN_DELETE_TRACK) {
+ if (track == act_track) {
+ clip->tracking.act_track = NULL;
+ }
+ BKE_tracking_track_free(track);
+ BLI_freelinkN(tracksbase, track);
+ track = NULL;
+ }
+
+ /* Happens when all tracking segments are not long enough. */
+ if (track && track->markersnr == 0) {
+ if (track == act_track) {
+ clip->tracking.act_track = NULL;
+ }
+ BKE_tracking_track_free(track);
+ BLI_freelinkN(tracksbase, track);
+ }
+ }
+ }
+ }
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
+
+ return OPERATOR_FINISHED;
+}
+
+static int clean_tracks_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+
+ if (!RNA_struct_property_is_set(op->ptr, "frames")) {
+ RNA_int_set(op->ptr, "frames", clip->tracking.settings.clean_frames);
+ }
+
+ if (!RNA_struct_property_is_set(op->ptr, "error")) {
+ RNA_float_set(op->ptr, "error", clip->tracking.settings.clean_error);
+ }
+
+ if (!RNA_struct_property_is_set(op->ptr, "action")) {
+ RNA_enum_set(op->ptr, "action", clip->tracking.settings.clean_action);
+ }
+
+ return clean_tracks_exec(C, op);
}
void CLIP_OT_clean_tracks(wmOperatorType *ot)
{
- static const EnumPropertyItem actions_items[] = {
- {TRACKING_CLEAN_SELECT, "SELECT", 0, "Select",
- "Select unclean tracks"},
- {TRACKING_CLEAN_DELETE_TRACK, "DELETE_TRACK", 0, "Delete Track",
- "Delete unclean tracks"},
- {TRACKING_CLEAN_DELETE_SEGMENT, "DELETE_SEGMENTS", 0, "Delete Segments",
- "Delete unclean segments of tracks"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Clean Tracks";
- ot->description = "Clean tracks with high error values or few frames";
- ot->idname = "CLIP_OT_clean_tracks";
-
- /* api callbacks */
- ot->exec = clean_tracks_exec;
- ot->invoke = clean_tracks_invoke;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_int(ot->srna, "frames", 0, 0, INT_MAX, "Tracked Frames",
- "Effect on tracks which are tracked less than "
- "specified amount of frames",
- 0, INT_MAX);
- RNA_def_float(ot->srna, "error", 0.0f, 0.0f, FLT_MAX, "Reprojection Error",
- "Effect on tracks which have got larger re-projection error",
- 0.0f, 100.0f);
- RNA_def_enum(ot->srna, "action", actions_items, 0, "Action",
- "Cleanup action to execute");
+ static const EnumPropertyItem actions_items[] = {
+ {TRACKING_CLEAN_SELECT, "SELECT", 0, "Select", "Select unclean tracks"},
+ {TRACKING_CLEAN_DELETE_TRACK, "DELETE_TRACK", 0, "Delete Track", "Delete unclean tracks"},
+ {TRACKING_CLEAN_DELETE_SEGMENT,
+ "DELETE_SEGMENTS",
+ 0,
+ "Delete Segments",
+ "Delete unclean segments of tracks"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Clean Tracks";
+ ot->description = "Clean tracks with high error values or few frames";
+ ot->idname = "CLIP_OT_clean_tracks";
+
+ /* api callbacks */
+ ot->exec = clean_tracks_exec;
+ ot->invoke = clean_tracks_invoke;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_int(ot->srna,
+ "frames",
+ 0,
+ 0,
+ INT_MAX,
+ "Tracked Frames",
+ "Effect on tracks which are tracked less than "
+ "specified amount of frames",
+ 0,
+ INT_MAX);
+ RNA_def_float(ot->srna,
+ "error",
+ 0.0f,
+ 0.0f,
+ FLT_MAX,
+ "Reprojection Error",
+ "Effect on tracks which have got larger re-projection error",
+ 0.0f,
+ 100.0f);
+ RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Cleanup action to execute");
}
/********************** add tracking object *********************/
static int tracking_object_new_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
- BKE_tracking_object_add(tracking, "Object");
+ BKE_tracking_object_add(tracking, "Object");
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_tracking_object_new(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Tracking Object";
- ot->description = "Add new object for tracking";
- ot->idname = "CLIP_OT_tracking_object_new";
+ /* identifiers */
+ ot->name = "Add Tracking Object";
+ ot->description = "Add new object for tracking";
+ ot->idname = "CLIP_OT_tracking_object_new";
- /* api callbacks */
- ot->exec = tracking_object_new_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = tracking_object_new_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** remove tracking object *********************/
static int tracking_object_remove_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object;
- object = BKE_tracking_object_get_active(tracking);
+ object = BKE_tracking_object_get_active(tracking);
- if (object->flag & TRACKING_OBJECT_CAMERA) {
- BKE_report(op->reports,
- RPT_WARNING,
- "Object used for camera tracking cannot be deleted");
- return OPERATOR_CANCELLED;
- }
+ if (object->flag & TRACKING_OBJECT_CAMERA) {
+ BKE_report(op->reports, RPT_WARNING, "Object used for camera tracking cannot be deleted");
+ return OPERATOR_CANCELLED;
+ }
- BKE_tracking_object_delete(tracking, object);
+ BKE_tracking_object_delete(tracking, object);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_tracking_object_remove(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Remove Tracking Object";
- ot->description = "Remove object for tracking";
- ot->idname = "CLIP_OT_tracking_object_remove";
+ /* identifiers */
+ ot->name = "Remove Tracking Object";
+ ot->description = "Remove object for tracking";
+ ot->idname = "CLIP_OT_tracking_object_remove";
- /* api callbacks */
- ot->exec = tracking_object_remove_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = tracking_object_remove_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** copy tracks to clipboard operator *********************/
static int copy_tracks_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- clip_tracking_clear_invisible_track_selection(sc, clip);
+ clip_tracking_clear_invisible_track_selection(sc, clip);
- BKE_tracking_clipboard_copy_tracks(tracking, object);
+ BKE_tracking_clipboard_copy_tracks(tracking, object);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_copy_tracks(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Copy Tracks";
- ot->description = "Copy selected tracks to clipboard";
- ot->idname = "CLIP_OT_copy_tracks";
+ /* identifiers */
+ ot->name = "Copy Tracks";
+ ot->description = "Copy selected tracks to clipboard";
+ ot->idname = "CLIP_OT_copy_tracks";
- /* api callbacks */
- ot->exec = copy_tracks_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = copy_tracks_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
}
/********************* paste tracks from clipboard operator ********************/
static bool paste_tracks_poll(bContext *C)
{
- if (ED_space_clip_tracking_poll(C)) {
- return BKE_tracking_clipboard_has_tracks();
- }
+ if (ED_space_clip_tracking_poll(C)) {
+ return BKE_tracking_clipboard_has_tracks();
+ }
- return 0;
+ return 0;
}
static int paste_tracks_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- ListBase *tracks_base = BKE_tracking_object_get_tracks(tracking, object);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ ListBase *tracks_base = BKE_tracking_object_get_tracks(tracking, object);
- BKE_tracking_tracks_deselect_all(tracks_base);
- BKE_tracking_clipboard_paste_tracks(tracking, object);
+ BKE_tracking_tracks_deselect_all(tracks_base);
+ BKE_tracking_clipboard_paste_tracks(tracking, object);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_paste_tracks(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Paste Tracks";
- ot->description = "Paste tracks from clipboard";
- ot->idname = "CLIP_OT_paste_tracks";
+ /* identifiers */
+ ot->name = "Paste Tracks";
+ ot->description = "Paste tracks from clipboard";
+ ot->idname = "CLIP_OT_paste_tracks";
- /* api callbacks */
- ot->exec = paste_tracks_exec;
- ot->poll = paste_tracks_poll;
+ /* api callbacks */
+ ot->exec = paste_tracks_exec;
+ ot->poll = paste_tracks_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** Insert track keyframe operator *********************/
static void keyframe_set_flag(bContext *C, bool set)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- ListBase *tracks_base = BKE_tracking_get_active_tracks(tracking);
- for (MovieTrackingTrack *track = tracks_base->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- if (set) {
- MovieTrackingMarker *marker =
- BKE_tracking_marker_ensure(track, framenr);
- marker->flag &= ~MARKER_TRACKED;
- }
- else {
- MovieTrackingMarker *marker =
- BKE_tracking_marker_get_exact(track, framenr);
- if (marker != NULL) {
- marker->flag |= MARKER_TRACKED;
- }
- }
- }
- }
-
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- if (set) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_ensure(plane_track, framenr);
- if (plane_marker->flag & PLANE_MARKER_TRACKED) {
- plane_marker->flag &= ~PLANE_MARKER_TRACKED;
- BKE_tracking_track_plane_from_existing_motion(
- plane_track,
- plane_marker->framenr);
- }
- }
- else {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get_exact(plane_track,
- framenr);
- if (plane_marker) {
- if ((plane_marker->flag & PLANE_MARKER_TRACKED) == 0) {
- plane_marker->flag |= PLANE_MARKER_TRACKED;
- BKE_tracking_retrack_plane_from_existing_motion_at_segment(
- plane_track,
- plane_marker->framenr);
- }
- }
- }
- }
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ ListBase *tracks_base = BKE_tracking_get_active_tracks(tracking);
+ for (MovieTrackingTrack *track = tracks_base->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ if (set) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_ensure(track, framenr);
+ marker->flag &= ~MARKER_TRACKED;
+ }
+ else {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
+ if (marker != NULL) {
+ marker->flag |= MARKER_TRACKED;
+ }
+ }
+ }
+ }
+
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ if (set) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_ensure(plane_track,
+ framenr);
+ if (plane_marker->flag & PLANE_MARKER_TRACKED) {
+ plane_marker->flag &= ~PLANE_MARKER_TRACKED;
+ BKE_tracking_track_plane_from_existing_motion(plane_track, plane_marker->framenr);
+ }
+ }
+ else {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get_exact(plane_track,
+ framenr);
+ if (plane_marker) {
+ if ((plane_marker->flag & PLANE_MARKER_TRACKED) == 0) {
+ plane_marker->flag |= PLANE_MARKER_TRACKED;
+ BKE_tracking_retrack_plane_from_existing_motion_at_segment(plane_track,
+ plane_marker->framenr);
+ }
+ }
+ }
+ }
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
}
static int keyframe_insert_exec(bContext *C, wmOperator *UNUSED(op))
{
- keyframe_set_flag(C, true);
- return OPERATOR_FINISHED;
+ keyframe_set_flag(C, true);
+ return OPERATOR_FINISHED;
}
void CLIP_OT_keyframe_insert(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Insert keyframe";
- ot->description = "Insert a keyframe to selected tracks at current frame";
- ot->idname = "CLIP_OT_keyframe_insert";
+ /* identifiers */
+ ot->name = "Insert keyframe";
+ ot->description = "Insert a keyframe to selected tracks at current frame";
+ ot->idname = "CLIP_OT_keyframe_insert";
- /* api callbacks */
- ot->poll = ED_space_clip_tracking_poll;
- ot->exec = keyframe_insert_exec;
+ /* api callbacks */
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->exec = keyframe_insert_exec;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** Delete track keyframe operator *********************/
static int keyframe_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
- keyframe_set_flag(C, false);
- return OPERATOR_FINISHED;
+ keyframe_set_flag(C, false);
+ return OPERATOR_FINISHED;
}
void CLIP_OT_keyframe_delete(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete keyframe";
- ot->description = "Delete a keyframe from selected tracks at current frame";
- ot->idname = "CLIP_OT_keyframe_delete";
+ /* identifiers */
+ ot->name = "Delete keyframe";
+ ot->description = "Delete a keyframe from selected tracks at current frame";
+ ot->idname = "CLIP_OT_keyframe_delete";
- /* api callbacks */
- ot->poll = ED_space_clip_tracking_poll;
- ot->exec = keyframe_delete_exec;
+ /* api callbacks */
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->exec = keyframe_delete_exec;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
diff --git a/source/blender/editors/space_clip/tracking_ops_detect.c b/source/blender/editors/space_clip/tracking_ops_detect.c
index 131ccc05d35..ead150bba7f 100644
--- a/source/blender/editors/space_clip/tracking_ops_detect.c
+++ b/source/blender/editors/space_clip/tracking_ops_detect.c
@@ -52,105 +52,122 @@
static bGPDlayer *detect_get_layer(MovieClip *clip)
{
- if (clip->gpd == NULL) {
- return NULL;
- }
- for (bGPDlayer *layer = clip->gpd->layers.first;
- layer != NULL;
- layer = layer->next)
- {
- if (layer->flag & GP_LAYER_ACTIVE) {
- return layer;
- }
- }
- return NULL;
+ if (clip->gpd == NULL) {
+ return NULL;
+ }
+ for (bGPDlayer *layer = clip->gpd->layers.first; layer != NULL; layer = layer->next) {
+ if (layer->flag & GP_LAYER_ACTIVE) {
+ return layer;
+ }
+ }
+ return NULL;
}
static int detect_features_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
- ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip,
- &sc->user,
- clip_flag,
- MOVIECLIP_CACHE_SKIP);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int placement = RNA_enum_get(op->ptr, "placement");
- int margin = RNA_int_get(op->ptr, "margin");
- int min_distance = RNA_int_get(op->ptr, "min_distance");
- float threshold = RNA_float_get(op->ptr, "threshold");
- int place_outside_layer = 0;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- bGPDlayer *layer = NULL;
-
- if (!ibuf) {
- BKE_report(op->reports,
- RPT_ERROR,
- "Feature detection requires valid clip frame");
- return OPERATOR_CANCELLED;
- }
-
- if (placement != 0) {
- layer = detect_get_layer(clip);
- place_outside_layer = placement == 2;
- }
-
- /* Deselect existing tracks. */
- ed_tracking_delect_all_tracks(tracksbase);
- /* Run detector. */
- BKE_tracking_detect_harris(tracking,
- tracksbase,
- ibuf,
- framenr,
- margin,
- threshold / 100000.0f,
- min_distance,
- layer,
- place_outside_layer);
-
- IMB_freeImBuf(ibuf);
-
- BKE_tracking_dopesheet_tag_update(tracking);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
+ ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip, &sc->user, clip_flag, MOVIECLIP_CACHE_SKIP);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int placement = RNA_enum_get(op->ptr, "placement");
+ int margin = RNA_int_get(op->ptr, "margin");
+ int min_distance = RNA_int_get(op->ptr, "min_distance");
+ float threshold = RNA_float_get(op->ptr, "threshold");
+ int place_outside_layer = 0;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ bGPDlayer *layer = NULL;
+
+ if (!ibuf) {
+ BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
+ return OPERATOR_CANCELLED;
+ }
+
+ if (placement != 0) {
+ layer = detect_get_layer(clip);
+ place_outside_layer = placement == 2;
+ }
+
+ /* Deselect existing tracks. */
+ ed_tracking_delect_all_tracks(tracksbase);
+ /* Run detector. */
+ BKE_tracking_detect_harris(tracking,
+ tracksbase,
+ ibuf,
+ framenr,
+ margin,
+ threshold / 100000.0f,
+ min_distance,
+ layer,
+ place_outside_layer);
+
+ IMB_freeImBuf(ibuf);
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_detect_features(wmOperatorType *ot)
{
- static const EnumPropertyItem placement_items[] = {
- {0, "FRAME", 0, "Whole Frame",
- "Place markers across the whole frame"},
- {1, "INSIDE_GPENCIL", 0, "Inside Grease Pencil",
- "Place markers only inside areas outlined with Grease Pencil"},
- {2, "OUTSIDE_GPENCIL", 0, "Outside Grease Pencil",
- "Place markers only outside areas outlined with Grease Pencil"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Detect Features";
- ot->description = "Automatically detect features and place markers to track";
- ot->idname = "CLIP_OT_detect_features";
-
- /* api callbacks */
- ot->exec = detect_features_exec;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "placement", placement_items, 0, "Placement",
- "Placement for detected features");
- RNA_def_int(ot->srna, "margin", 16, 0, INT_MAX, "Margin",
- "Only features further than margin pixels from the image "
- "edges are considered", 0, 300);
- RNA_def_float(ot->srna, "threshold", 0.5f, 0.0001f, FLT_MAX, "Threshold",
- "Threshold level to consider feature good enough for tracking",
- 0.0001f, FLT_MAX);
- RNA_def_int(ot->srna, "min_distance", 120, 0, INT_MAX, "Distance",
- "Minimal distance accepted between two features", 0, 300);
+ static const EnumPropertyItem placement_items[] = {
+ {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
+ {1,
+ "INSIDE_GPENCIL",
+ 0,
+ "Inside Grease Pencil",
+ "Place markers only inside areas outlined with Grease Pencil"},
+ {2,
+ "OUTSIDE_GPENCIL",
+ 0,
+ "Outside Grease Pencil",
+ "Place markers only outside areas outlined with Grease Pencil"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Detect Features";
+ ot->description = "Automatically detect features and place markers to track";
+ ot->idname = "CLIP_OT_detect_features";
+
+ /* api callbacks */
+ ot->exec = detect_features_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(
+ ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
+ RNA_def_int(ot->srna,
+ "margin",
+ 16,
+ 0,
+ INT_MAX,
+ "Margin",
+ "Only features further than margin pixels from the image "
+ "edges are considered",
+ 0,
+ 300);
+ RNA_def_float(ot->srna,
+ "threshold",
+ 0.5f,
+ 0.0001f,
+ FLT_MAX,
+ "Threshold",
+ "Threshold level to consider feature good enough for tracking",
+ 0.0001f,
+ FLT_MAX);
+ RNA_def_int(ot->srna,
+ "min_distance",
+ 120,
+ 0,
+ INT_MAX,
+ "Distance",
+ "Minimal distance accepted between two features",
+ 0,
+ 300);
}
diff --git a/source/blender/editors/space_clip/tracking_ops_intern.h b/source/blender/editors/space_clip/tracking_ops_intern.h
index adf0285540a..8d2d61f050e 100644
--- a/source/blender/editors/space_clip/tracking_ops_intern.h
+++ b/source/blender/editors/space_clip/tracking_ops_intern.h
@@ -31,8 +31,7 @@ struct bContext;
/* tracking_utils.c */
-void clip_tracking_clear_invisible_track_selection(struct SpaceClip *sc,
- struct MovieClip *clip);
+void clip_tracking_clear_invisible_track_selection(struct SpaceClip *sc, struct MovieClip *clip);
void clip_tracking_show_cursor(struct bContext *C);
void clip_tracking_hide_cursor(struct bContext *C);
diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c
index 2df74240241..e13598b0322 100644
--- a/source/blender/editors/space_clip/tracking_ops_orient.c
+++ b/source/blender/editors/space_clip/tracking_ops_orient.c
@@ -24,7 +24,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_constraint_types.h"
-#include "DNA_object_types.h" /* SELECT */
+#include "DNA_object_types.h" /* SELECT */
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
@@ -54,218 +54,200 @@
static Object *get_camera_with_movieclip(Scene *scene, MovieClip *clip)
{
- Object *camera = scene->camera;
-
- if (camera != NULL &&
- BKE_object_movieclip_get(scene, camera, false) == clip)
- {
- return camera;
- }
-
- FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
- {
- if (ob->type == OB_CAMERA) {
- if (BKE_object_movieclip_get(scene, ob, false) == clip) {
- camera = ob;
- break;
- }
- }
- }
- FOREACH_SCENE_OBJECT_END;
-
- return camera;
+ Object *camera = scene->camera;
+
+ if (camera != NULL && BKE_object_movieclip_get(scene, camera, false) == clip) {
+ return camera;
+ }
+
+ FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
+ if (ob->type == OB_CAMERA) {
+ if (BKE_object_movieclip_get(scene, ob, false) == clip) {
+ camera = ob;
+ break;
+ }
+ }
+ }
+ FOREACH_SCENE_OBJECT_END;
+
+ return camera;
}
static Object *get_orientation_object(bContext *C)
{
- Scene *scene = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
- Object *object = NULL;
-
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- object = get_camera_with_movieclip(scene, clip);
- }
- else {
- object = OBACT(view_layer);
- }
-
- if (object != NULL && object->parent != NULL) {
- object = object->parent;
- }
-
- return object;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ Object *object = NULL;
+
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ object = get_camera_with_movieclip(scene, clip);
+ }
+ else {
+ object = OBACT(view_layer);
+ }
+
+ if (object != NULL && object->parent != NULL) {
+ object = object->parent;
+ }
+
+ return object;
}
static bool set_orientation_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc != NULL) {
- ViewLayer *view_layer = CTX_data_view_layer(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- if (clip != NULL) {
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- return true;
- }
- else {
- return OBACT(view_layer) != NULL;
- }
- }
- }
- return false;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ if (sc != NULL) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (clip != NULL) {
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ return true;
+ }
+ else {
+ return OBACT(view_layer) != NULL;
+ }
+ }
+ }
+ return false;
}
static int count_selected_bundles(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- int tot = 0;
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_HAS_BUNDLE)) {
- tot++;
- }
- }
- return tot;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int tot = 0;
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_HAS_BUNDLE)) {
+ tot++;
+ }
+ }
+ return tot;
}
-static void object_solver_inverted_matrix(Scene *scene,
- Object *ob,
- float invmat[4][4])
+static void object_solver_inverted_matrix(Scene *scene, Object *ob, float invmat[4][4])
{
- bool found = false;
- for (bConstraint *con = ob->constraints.first;
- con != NULL;
- con = con->next)
- {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- if (cti == NULL) {
- continue;
- }
- if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
- bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
- if (!found) {
- Object *cam = data->camera ? data->camera : scene->camera;
- BKE_object_where_is_calc_mat4(cam, invmat);
- }
- mul_m4_m4m4(invmat, invmat, data->invmat);
- found = true;
- }
- }
- if (found) {
- invert_m4(invmat);
- }
- else {
- unit_m4(invmat);
- }
+ bool found = false;
+ for (bConstraint *con = ob->constraints.first; con != NULL; con = con->next) {
+ const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
+ if (cti == NULL) {
+ continue;
+ }
+ if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
+ bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
+ if (!found) {
+ Object *cam = data->camera ? data->camera : scene->camera;
+ BKE_object_where_is_calc_mat4(cam, invmat);
+ }
+ mul_m4_m4m4(invmat, invmat, data->invmat);
+ found = true;
+ }
+ }
+ if (found) {
+ invert_m4(invmat);
+ }
+ else {
+ unit_m4(invmat);
+ }
}
static Object *object_solver_camera(Scene *scene, Object *ob)
{
- for (bConstraint *con = ob->constraints.first;
- con != NULL;
- con = con->next)
- {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- if (cti == NULL) {
- continue;
- }
- if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
- bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
- return (data->camera != NULL) ? data->camera : scene->camera;
- }
- }
- return NULL;
+ for (bConstraint *con = ob->constraints.first; con != NULL; con = con->next) {
+ const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
+ if (cti == NULL) {
+ continue;
+ }
+ if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
+ bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
+ return (data->camera != NULL) ? data->camera : scene->camera;
+ }
+ }
+ return NULL;
}
static int set_origin_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- Scene *scene = CTX_data_scene(C);
- Object *camera = get_camera_with_movieclip(scene, clip);
- int selected_count = count_selected_bundles(C);
-
- if (selected_count == 0) {
- BKE_report(op->reports,
- RPT_ERROR,
- "At least one track with bundle should be selected to "
- "define origin position");
-
- return OPERATOR_CANCELLED;
- }
-
- Object *object = get_orientation_object(C);
- if (object == NULL) {
- BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
- return OPERATOR_CANCELLED;
- }
-
- MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
-
- float median[3] = {0.0f, 0.0f, 0.0f};
- zero_v3(median);
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) &&
- (track->flag & TRACK_HAS_BUNDLE))
- {
- add_v3_v3(median, track->bundle_pos);
- }
- }
- mul_v3_fl(median, 1.0f / selected_count);
-
- float mat[4][4], vec[3];
- BKE_tracking_get_camera_object_matrix(scene, camera, mat);
- mul_v3_m4v3(vec, mat, median);
-
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- sub_v3_v3(object->loc, vec);
- }
- else {
- object_solver_inverted_matrix(scene, object, mat);
- mul_v3_m4v3(vec, mat, vec);
- copy_v3_v3(object->loc, vec);
- }
-
- DEG_id_tag_update(&clip->id, 0);
- DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ Scene *scene = CTX_data_scene(C);
+ Object *camera = get_camera_with_movieclip(scene, clip);
+ int selected_count = count_selected_bundles(C);
+
+ if (selected_count == 0) {
+ BKE_report(op->reports,
+ RPT_ERROR,
+ "At least one track with bundle should be selected to "
+ "define origin position");
+
+ return OPERATOR_CANCELLED;
+ }
+
+ Object *object = get_orientation_object(C);
+ if (object == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
+ return OPERATOR_CANCELLED;
+ }
+
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
+
+ float median[3] = {0.0f, 0.0f, 0.0f};
+ zero_v3(median);
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_HAS_BUNDLE)) {
+ add_v3_v3(median, track->bundle_pos);
+ }
+ }
+ mul_v3_fl(median, 1.0f / selected_count);
+
+ float mat[4][4], vec[3];
+ BKE_tracking_get_camera_object_matrix(scene, camera, mat);
+ mul_v3_m4v3(vec, mat, median);
+
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ sub_v3_v3(object->loc, vec);
+ }
+ else {
+ object_solver_inverted_matrix(scene, object, mat);
+ mul_v3_m4v3(vec, mat, vec);
+ copy_v3_v3(object->loc, vec);
+ }
+
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_origin(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Origin";
- ot->description = "Set active marker as origin by moving camera (or its parent if present) in 3D space";
- ot->idname = "CLIP_OT_set_origin";
-
- /* api callbacks */
- ot->exec = set_origin_exec;
- ot->poll = set_orientation_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean(ot->srna, "use_median", 0, "Use Median",
- "Set origin to median point of selected bundles");
+ /* identifiers */
+ ot->name = "Set Origin";
+ ot->description =
+ "Set active marker as origin by moving camera (or its parent if present) in 3D space";
+ ot->idname = "CLIP_OT_set_origin";
+
+ /* api callbacks */
+ ot->exec = set_origin_exec;
+ ot->poll = set_orientation_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(
+ ot->srna, "use_median", 0, "Use Median", "Set origin to median point of selected bundles");
}
/********************** set floor operator *********************/
@@ -277,578 +259,596 @@ static void set_axis(Scene *scene,
MovieTrackingTrack *track,
char axis)
{
- Object *camera = get_camera_with_movieclip(scene, clip);
- const bool is_camera = (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
- bool flip = false;
- float mat[4][4], vec[3], obmat[4][4], dvec[3];
-
- BKE_object_to_mat4(ob, obmat);
-
- BKE_tracking_get_camera_object_matrix(scene, camera, mat);
- mul_v3_m4v3(vec, mat, track->bundle_pos);
- copy_v3_v3(dvec, vec);
-
- if (!is_camera) {
- float imat[4][4];
-
- object_solver_inverted_matrix(scene, ob, imat);
- mul_v3_m4v3(vec, imat, vec);
-
- invert_m4_m4(imat, obmat);
- mul_v3_m4v3(dvec, imat, vec);
-
- sub_v3_v3(vec, obmat[3]);
- }
-
- if (len_squared_v2(vec) < (1e-3f * 1e-3f)) {
- return;
- }
-
- unit_m4(mat);
-
- if (axis == 'X') {
- if (fabsf(dvec[1]) < 1e-3f) {
- flip = true;
-
- mat[0][0] = -1.0f; mat[0][1] = 0.0f; mat[0][2] = 0.0f;
- mat[1][0] = 0.0f; mat[1][1] = -1.0f; mat[1][2] = 0.0f;
- mat[2][0] = 0.0f; mat[2][1] = 0.0f; mat[2][2] = 1.0f;
- }
- else {
- copy_v3_v3(mat[0], vec);
-
- if (is_camera || fabsf(vec[2]) < 1e-3f) {
- mat[0][2] = 0.0f;
- mat[2][0] = 0.0f; mat[2][1] = 0.0f; mat[2][2] = 1.0f;
- cross_v3_v3v3(mat[1], mat[2], mat[0]);
- }
- else {
- vec[2] = 0.0f;
-
- cross_v3_v3v3(mat[1], mat[0], vec);
- cross_v3_v3v3(mat[2], mat[0], mat[1]);
- }
- }
- }
- else {
- if (fabsf(dvec[0]) < 1e-3f) {
- flip = true;
-
- mat[0][0] = -1.0f; mat[0][1] = 0.0f; mat[0][2] = 0.0f;
- mat[1][0] = 0.0f; mat[1][1] = -1.0f; mat[1][2] = 0.0f;
- mat[2][0] = 0.0f; mat[2][1] = 0.0f; mat[2][2] = 1.0f;
- }
- else {
- copy_v3_v3(mat[1], vec);
-
- if (is_camera || fabsf(vec[2]) < 1e-3f) {
- mat[1][2] = 0.0f;
- mat[2][0] = 0.0f; mat[2][1] = 0.0f; mat[2][2] = 1.0f;
- cross_v3_v3v3(mat[0], mat[1], mat[2]);
- }
- else {
- vec[2] = 0.0f;
-
- cross_v3_v3v3(mat[0], vec, mat[1]);
- cross_v3_v3v3(mat[2], mat[0], mat[1]);
- }
- }
- }
-
- normalize_v3(mat[0]);
- normalize_v3(mat[1]);
- normalize_v3(mat[2]);
-
- if (is_camera) {
- invert_m4(mat);
-
- mul_m4_m4m4(mat, mat, obmat);
- }
- else {
- if (!flip) {
- float lmat[4][4], ilmat[4][4], rmat[3][3];
-
- BKE_object_rot_to_mat3(ob, rmat, true);
- invert_m3(rmat);
- mul_m4_m4m3(mat, mat, rmat);
-
- unit_m4(lmat);
- copy_v3_v3(lmat[3], obmat[3]);
- invert_m4_m4(ilmat, lmat);
-
- mul_m4_series(mat, lmat, mat, ilmat, obmat);
- }
- else {
- mul_m4_m4m4(mat, obmat, mat);
- }
- }
-
- BKE_object_apply_mat4(ob, mat, 0, 0);
+ Object *camera = get_camera_with_movieclip(scene, clip);
+ const bool is_camera = (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
+ bool flip = false;
+ float mat[4][4], vec[3], obmat[4][4], dvec[3];
+
+ BKE_object_to_mat4(ob, obmat);
+
+ BKE_tracking_get_camera_object_matrix(scene, camera, mat);
+ mul_v3_m4v3(vec, mat, track->bundle_pos);
+ copy_v3_v3(dvec, vec);
+
+ if (!is_camera) {
+ float imat[4][4];
+
+ object_solver_inverted_matrix(scene, ob, imat);
+ mul_v3_m4v3(vec, imat, vec);
+
+ invert_m4_m4(imat, obmat);
+ mul_v3_m4v3(dvec, imat, vec);
+
+ sub_v3_v3(vec, obmat[3]);
+ }
+
+ if (len_squared_v2(vec) < (1e-3f * 1e-3f)) {
+ return;
+ }
+
+ unit_m4(mat);
+
+ if (axis == 'X') {
+ if (fabsf(dvec[1]) < 1e-3f) {
+ flip = true;
+
+ mat[0][0] = -1.0f;
+ mat[0][1] = 0.0f;
+ mat[0][2] = 0.0f;
+ mat[1][0] = 0.0f;
+ mat[1][1] = -1.0f;
+ mat[1][2] = 0.0f;
+ mat[2][0] = 0.0f;
+ mat[2][1] = 0.0f;
+ mat[2][2] = 1.0f;
+ }
+ else {
+ copy_v3_v3(mat[0], vec);
+
+ if (is_camera || fabsf(vec[2]) < 1e-3f) {
+ mat[0][2] = 0.0f;
+ mat[2][0] = 0.0f;
+ mat[2][1] = 0.0f;
+ mat[2][2] = 1.0f;
+ cross_v3_v3v3(mat[1], mat[2], mat[0]);
+ }
+ else {
+ vec[2] = 0.0f;
+
+ cross_v3_v3v3(mat[1], mat[0], vec);
+ cross_v3_v3v3(mat[2], mat[0], mat[1]);
+ }
+ }
+ }
+ else {
+ if (fabsf(dvec[0]) < 1e-3f) {
+ flip = true;
+
+ mat[0][0] = -1.0f;
+ mat[0][1] = 0.0f;
+ mat[0][2] = 0.0f;
+ mat[1][0] = 0.0f;
+ mat[1][1] = -1.0f;
+ mat[1][2] = 0.0f;
+ mat[2][0] = 0.0f;
+ mat[2][1] = 0.0f;
+ mat[2][2] = 1.0f;
+ }
+ else {
+ copy_v3_v3(mat[1], vec);
+
+ if (is_camera || fabsf(vec[2]) < 1e-3f) {
+ mat[1][2] = 0.0f;
+ mat[2][0] = 0.0f;
+ mat[2][1] = 0.0f;
+ mat[2][2] = 1.0f;
+ cross_v3_v3v3(mat[0], mat[1], mat[2]);
+ }
+ else {
+ vec[2] = 0.0f;
+
+ cross_v3_v3v3(mat[0], vec, mat[1]);
+ cross_v3_v3v3(mat[2], mat[0], mat[1]);
+ }
+ }
+ }
+
+ normalize_v3(mat[0]);
+ normalize_v3(mat[1]);
+ normalize_v3(mat[2]);
+
+ if (is_camera) {
+ invert_m4(mat);
+
+ mul_m4_m4m4(mat, mat, obmat);
+ }
+ else {
+ if (!flip) {
+ float lmat[4][4], ilmat[4][4], rmat[3][3];
+
+ BKE_object_rot_to_mat3(ob, rmat, true);
+ invert_m3(rmat);
+ mul_m4_m4m3(mat, mat, rmat);
+
+ unit_m4(lmat);
+ copy_v3_v3(lmat[3], obmat[3]);
+ invert_m4_m4(ilmat, lmat);
+
+ mul_m4_series(mat, lmat, mat, ilmat, obmat);
+ }
+ else {
+ mul_m4_m4m4(mat, obmat, mat);
+ }
+ }
+
+ BKE_object_apply_mat4(ob, mat, 0, 0);
}
static int set_plane_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- Scene *scene = CTX_data_scene(C);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object;
- MovieTrackingTrack *track, *axis_track = NULL, *act_track;
- ListBase *tracksbase;
- Object *object;
- Object *camera = get_camera_with_movieclip(scene, clip);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int tot = 0;
- float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f};
- int plane = RNA_enum_get(op->ptr, "plane");
- float rot[4][4] = {{0.0f, 0.0f, -1.0f, 0.0f},
- {0.0f, 1.0f, 0.0f, 0.0f},
- {1.0f, 0.0f, 0.0f, 0.0f},
- {0.0f, 0.0f, 0.0f, 1.0f}}; /* 90 degrees Y-axis rotation matrix */
-
- if (count_selected_bundles(C) != 3) {
- BKE_report(op->reports, RPT_ERROR, "Three tracks with bundles are needed to orient the floor");
-
- return OPERATOR_CANCELLED;
- }
-
- tracking_object = BKE_tracking_object_get_active(tracking);
- tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
- act_track = BKE_tracking_track_get_active(tracking);
-
- object = get_orientation_object(C);
- if (object == NULL) {
- BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
- return OPERATOR_CANCELLED;
- }
-
- BKE_tracking_get_camera_object_matrix(scene, camera, mat);
-
- /* Get 3 bundles to use as reference. */
- track = tracksbase->first;
- while (track && tot < 3) {
- if (track->flag & TRACK_HAS_BUNDLE && TRACK_VIEW_SELECTED(sc, track)) {
- mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
- if (tot == 0 || track == act_track) {
- copy_v3_v3(orig, vec[tot]);
- }
- else {
- axis_track = track;
- }
- tot++;
- }
- track = track->next;
- }
-
- sub_v3_v3(vec[1], vec[0]);
- sub_v3_v3(vec[2], vec[0]);
-
- /* Construct ortho-normal basis. */
- unit_m4(mat);
- if (plane == 0) { /* floor */
- cross_v3_v3v3(mat[0], vec[1], vec[2]);
- copy_v3_v3(mat[1], vec[1]);
- cross_v3_v3v3(mat[2], mat[0], mat[1]);
- }
- else if (plane == 1) { /* wall */
- cross_v3_v3v3(mat[2], vec[1], vec[2]);
- copy_v3_v3(mat[1], vec[1]);
- cross_v3_v3v3(mat[0], mat[1], mat[2]);
- }
-
- normalize_v3(mat[0]);
- normalize_v3(mat[1]);
- normalize_v3(mat[2]);
-
- /* Move to origin point. */
- mat[3][0] = orig[0];
- mat[3][1] = orig[1];
- mat[3][2] = orig[2];
-
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- invert_m4(mat);
-
- BKE_object_to_mat4(object, obmat);
- mul_m4_m4m4(mat, mat, obmat);
- mul_m4_m4m4(newmat, rot, mat);
- BKE_object_apply_mat4(object, newmat, 0, 0);
-
- /* Make camera have positive z-coordinate. */
- if (object->loc[2] < 0) {
- invert_m4(rot);
- mul_m4_m4m4(newmat, rot, mat);
- BKE_object_apply_mat4(object, newmat, 0, 0);
- }
- }
- else {
- BKE_object_apply_mat4(object, mat, 0, 0);
- }
-
- BKE_object_where_is_calc(depsgraph, scene, object);
- set_axis(scene, object, clip, tracking_object, axis_track, 'X');
-
- DEG_id_tag_update(&clip->id, 0);
- DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ Scene *scene = CTX_data_scene(C);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object;
+ MovieTrackingTrack *track, *axis_track = NULL, *act_track;
+ ListBase *tracksbase;
+ Object *object;
+ Object *camera = get_camera_with_movieclip(scene, clip);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ int tot = 0;
+ float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f};
+ int plane = RNA_enum_get(op->ptr, "plane");
+ float rot[4][4] = {{0.0f, 0.0f, -1.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f, 0.0f},
+ {1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}}; /* 90 degrees Y-axis rotation matrix */
+
+ if (count_selected_bundles(C) != 3) {
+ BKE_report(op->reports, RPT_ERROR, "Three tracks with bundles are needed to orient the floor");
+
+ return OPERATOR_CANCELLED;
+ }
+
+ tracking_object = BKE_tracking_object_get_active(tracking);
+ tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
+ act_track = BKE_tracking_track_get_active(tracking);
+
+ object = get_orientation_object(C);
+ if (object == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_tracking_get_camera_object_matrix(scene, camera, mat);
+
+ /* Get 3 bundles to use as reference. */
+ track = tracksbase->first;
+ while (track && tot < 3) {
+ if (track->flag & TRACK_HAS_BUNDLE && TRACK_VIEW_SELECTED(sc, track)) {
+ mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
+ if (tot == 0 || track == act_track) {
+ copy_v3_v3(orig, vec[tot]);
+ }
+ else {
+ axis_track = track;
+ }
+ tot++;
+ }
+ track = track->next;
+ }
+
+ sub_v3_v3(vec[1], vec[0]);
+ sub_v3_v3(vec[2], vec[0]);
+
+ /* Construct ortho-normal basis. */
+ unit_m4(mat);
+ if (plane == 0) { /* floor */
+ cross_v3_v3v3(mat[0], vec[1], vec[2]);
+ copy_v3_v3(mat[1], vec[1]);
+ cross_v3_v3v3(mat[2], mat[0], mat[1]);
+ }
+ else if (plane == 1) { /* wall */
+ cross_v3_v3v3(mat[2], vec[1], vec[2]);
+ copy_v3_v3(mat[1], vec[1]);
+ cross_v3_v3v3(mat[0], mat[1], mat[2]);
+ }
+
+ normalize_v3(mat[0]);
+ normalize_v3(mat[1]);
+ normalize_v3(mat[2]);
+
+ /* Move to origin point. */
+ mat[3][0] = orig[0];
+ mat[3][1] = orig[1];
+ mat[3][2] = orig[2];
+
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ invert_m4(mat);
+
+ BKE_object_to_mat4(object, obmat);
+ mul_m4_m4m4(mat, mat, obmat);
+ mul_m4_m4m4(newmat, rot, mat);
+ BKE_object_apply_mat4(object, newmat, 0, 0);
+
+ /* Make camera have positive z-coordinate. */
+ if (object->loc[2] < 0) {
+ invert_m4(rot);
+ mul_m4_m4m4(newmat, rot, mat);
+ BKE_object_apply_mat4(object, newmat, 0, 0);
+ }
+ }
+ else {
+ BKE_object_apply_mat4(object, mat, 0, 0);
+ }
+
+ BKE_object_where_is_calc(depsgraph, scene, object);
+ set_axis(scene, object, clip, tracking_object, axis_track, 'X');
+
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_plane(wmOperatorType *ot)
{
- static const EnumPropertyItem plane_items[] = {
- {0, "FLOOR", 0, "Floor", "Set floor plane"},
- {1, "WALL", 0, "Wall", "Set wall plane"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Set Plane";
- ot->description = "Set plane based on 3 selected bundles by moving camera "
- "(or its parent if present) in 3D space";
- ot->idname = "CLIP_OT_set_plane";
-
- /* api callbacks */
- ot->exec = set_plane_exec;
- ot->poll = set_orientation_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "plane", plane_items, 0, "Plane",
- "Plane to be used for orientation");
+ static const EnumPropertyItem plane_items[] = {
+ {0, "FLOOR", 0, "Floor", "Set floor plane"},
+ {1, "WALL", 0, "Wall", "Set wall plane"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Set Plane";
+ ot->description =
+ "Set plane based on 3 selected bundles by moving camera "
+ "(or its parent if present) in 3D space";
+ ot->idname = "CLIP_OT_set_plane";
+
+ /* api callbacks */
+ ot->exec = set_plane_exec;
+ ot->poll = set_orientation_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(ot->srna, "plane", plane_items, 0, "Plane", "Plane to be used for orientation");
}
/********************** set axis operator *********************/
static int set_axis_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
- Scene *scene = CTX_data_scene(C);
- Object *object;
- int axis = RNA_enum_get(op->ptr, "axis");
-
- if (count_selected_bundles(C) != 1) {
- BKE_report(op->reports,
- RPT_ERROR,
- "Single track with bundle should be selected to define axis");
- return OPERATOR_CANCELLED;
- }
-
- object = get_orientation_object(C);
- if (object == NULL) {
- BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
- return OPERATOR_CANCELLED;
- }
-
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking,
- tracking_object);
- MovieTrackingTrack *track = tracksbase->first;
- while (track) {
- if (TRACK_VIEW_SELECTED(sc, track) &&
- (track->flag & TRACK_HAS_BUNDLE))
- {
- break;
- }
- track = track->next;
- }
-
- set_axis(scene, object, clip, tracking_object, track, axis == 0 ? 'X' : 'Y');
-
- DEG_id_tag_update(&clip->id, 0);
- DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ Scene *scene = CTX_data_scene(C);
+ Object *object;
+ int axis = RNA_enum_get(op->ptr, "axis");
+
+ if (count_selected_bundles(C) != 1) {
+ BKE_report(
+ op->reports, RPT_ERROR, "Single track with bundle should be selected to define axis");
+ return OPERATOR_CANCELLED;
+ }
+
+ object = get_orientation_object(C);
+ if (object == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
+ return OPERATOR_CANCELLED;
+ }
+
+ ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
+ MovieTrackingTrack *track = tracksbase->first;
+ while (track) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_HAS_BUNDLE)) {
+ break;
+ }
+ track = track->next;
+ }
+
+ set_axis(scene, object, clip, tracking_object, track, axis == 0 ? 'X' : 'Y');
+
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_set_axis(wmOperatorType *ot)
{
- static const EnumPropertyItem axis_actions[] = {
- {0, "X", 0, "X", "Align bundle align X axis"},
- {1, "Y", 0, "Y", "Align bundle align Y axis"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Set Axis";
- ot->description = "Set direction of scene axis rotating camera "
- "(or its parent if present) and assume selected track "
- "lies on real axis, joining it with the origin";
- ot->idname = "CLIP_OT_set_axis";
-
- /* api callbacks */
- ot->exec = set_axis_exec;
- ot->poll = set_orientation_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "axis", axis_actions, 0, "Axis",
- "Axis to use to align bundle along");
+ static const EnumPropertyItem axis_actions[] = {
+ {0, "X", 0, "X", "Align bundle align X axis"},
+ {1, "Y", 0, "Y", "Align bundle align Y axis"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Set Axis";
+ ot->description =
+ "Set direction of scene axis rotating camera "
+ "(or its parent if present) and assume selected track "
+ "lies on real axis, joining it with the origin";
+ ot->idname = "CLIP_OT_set_axis";
+
+ /* api callbacks */
+ ot->exec = set_axis_exec;
+ ot->poll = set_orientation_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(ot->srna, "axis", axis_actions, 0, "Axis", "Axis to use to align bundle along");
}
/********************** set scale operator *********************/
-static int do_set_scale(bContext *C,
- wmOperator *op,
- bool scale_solution,
- bool apply_scale)
+static int do_set_scale(bContext *C, wmOperator *op, bool scale_solution, bool apply_scale)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
- MovieTrackingTrack *track;
- Scene *scene = CTX_data_scene(C);
- Object *object = NULL;
- Object *camera = get_camera_with_movieclip(scene, clip);
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int tot = 0;
- float vec[2][3], mat[4][4], scale;
- float dist = RNA_float_get(op->ptr, "distance");
-
- if (count_selected_bundles(C) != 2) {
- BKE_report(op->reports,
- RPT_ERROR,
- "Two tracks with bundles should be selected to set scale");
- return OPERATOR_CANCELLED;
- }
-
- if (!scale_solution && !apply_scale) {
- object = get_orientation_object(C);
- if (object == NULL) {
- BKE_report(op->reports,
- RPT_ERROR,
- "No object to apply orientation on");
- return OPERATOR_CANCELLED;
- }
- }
-
- BKE_tracking_get_camera_object_matrix(scene, camera, mat);
-
- track = tracksbase->first;
- while (track) {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
- tot++;
- }
- track = track->next;
- }
-
- sub_v3_v3(vec[0], vec[1]);
-
- if (len_v3(vec[0]) > 1e-5f) {
- scale = dist / len_v3(vec[0]);
- if (apply_scale) {
- /* Apply scale on reconstructed scene itself. */
- MovieTrackingReconstruction *reconstruction =
- BKE_tracking_get_active_reconstruction(tracking);
- MovieReconstructedCamera *reconstructed_cameras;
- int i;
-
- for (track = tracksbase->first; track; track = track->next) {
- mul_v3_fl(track->bundle_pos, scale);
- }
-
- reconstructed_cameras = reconstruction->cameras;
- for (i = 0; i < reconstruction->camnr; i++) {
- mul_v3_fl(reconstructed_cameras[i].mat[3], scale);
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- }
- else {
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- mul_v3_fl(object->scale, scale);
- mul_v3_fl(object->loc, scale);
- }
- else if (!scale_solution) {
- Object *solver_camera = object_solver_camera(scene, object);
-
- object->scale[0] = object->scale[1] = object->scale[2] = 1.0f / scale;
-
- if (solver_camera) {
- object->scale[0] /= solver_camera->scale[0];
- object->scale[1] /= solver_camera->scale[1];
- object->scale[2] /= solver_camera->scale[2];
- }
- }
- else {
- tracking_object->scale = scale;
- }
-
- DEG_id_tag_update(&clip->id, 0);
-
- if (object)
- DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- }
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ MovieTrackingTrack *track;
+ Scene *scene = CTX_data_scene(C);
+ Object *object = NULL;
+ Object *camera = get_camera_with_movieclip(scene, clip);
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int tot = 0;
+ float vec[2][3], mat[4][4], scale;
+ float dist = RNA_float_get(op->ptr, "distance");
+
+ if (count_selected_bundles(C) != 2) {
+ BKE_report(op->reports, RPT_ERROR, "Two tracks with bundles should be selected to set scale");
+ return OPERATOR_CANCELLED;
+ }
+
+ if (!scale_solution && !apply_scale) {
+ object = get_orientation_object(C);
+ if (object == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
+ return OPERATOR_CANCELLED;
+ }
+ }
+
+ BKE_tracking_get_camera_object_matrix(scene, camera, mat);
+
+ track = tracksbase->first;
+ while (track) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
+ tot++;
+ }
+ track = track->next;
+ }
+
+ sub_v3_v3(vec[0], vec[1]);
+
+ if (len_v3(vec[0]) > 1e-5f) {
+ scale = dist / len_v3(vec[0]);
+ if (apply_scale) {
+ /* Apply scale on reconstructed scene itself. */
+ MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(
+ tracking);
+ MovieReconstructedCamera *reconstructed_cameras;
+ int i;
+
+ for (track = tracksbase->first; track; track = track->next) {
+ mul_v3_fl(track->bundle_pos, scale);
+ }
+
+ reconstructed_cameras = reconstruction->cameras;
+ for (i = 0; i < reconstruction->camnr; i++) {
+ mul_v3_fl(reconstructed_cameras[i].mat[3], scale);
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ }
+ else {
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ mul_v3_fl(object->scale, scale);
+ mul_v3_fl(object->loc, scale);
+ }
+ else if (!scale_solution) {
+ Object *solver_camera = object_solver_camera(scene, object);
+
+ object->scale[0] = object->scale[1] = object->scale[2] = 1.0f / scale;
+
+ if (solver_camera) {
+ object->scale[0] /= solver_camera->scale[0];
+ object->scale[1] /= solver_camera->scale[1];
+ object->scale[2] /= solver_camera->scale[2];
+ }
+ }
+ else {
+ tracking_object->scale = scale;
+ }
+
+ DEG_id_tag_update(&clip->id, 0);
+
+ if (object)
+ DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ }
+ }
+
+ return OPERATOR_FINISHED;
}
static int set_scale_exec(bContext *C, wmOperator *op)
{
- return do_set_scale(C, op, false, false);
+ return do_set_scale(C, op, false, false);
}
-static int set_scale_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int set_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- if (!RNA_struct_property_is_set(op->ptr, "distance"))
- RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
+ if (!RNA_struct_property_is_set(op->ptr, "distance"))
+ RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
- return set_scale_exec(C, op);
+ return set_scale_exec(C, op);
}
void CLIP_OT_set_scale(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Scale";
- ot->description = "Set scale of scene by scaling camera (or its parent if present)";
- ot->idname = "CLIP_OT_set_scale";
-
- /* api callbacks */
- ot->exec = set_scale_exec;
- ot->invoke = set_scale_invoke;
- ot->poll = set_orientation_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_float(ot->srna, "distance", 0.0f, -FLT_MAX, FLT_MAX,
- "Distance", "Distance between selected tracks", -100.0f, 100.0f);
+ /* identifiers */
+ ot->name = "Set Scale";
+ ot->description = "Set scale of scene by scaling camera (or its parent if present)";
+ ot->idname = "CLIP_OT_set_scale";
+
+ /* api callbacks */
+ ot->exec = set_scale_exec;
+ ot->invoke = set_scale_invoke;
+ ot->poll = set_orientation_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_float(ot->srna,
+ "distance",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Distance",
+ "Distance between selected tracks",
+ -100.0f,
+ 100.0f);
}
/********************** set solution scale operator *********************/
static bool set_solution_scale_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc != NULL) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
- if (clip != NULL) {
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object =
- BKE_tracking_object_get_active(tracking);
- return (tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0;
- }
- }
- return false;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ if (sc != NULL) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (clip != NULL) {
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ return (tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0;
+ }
+ }
+ return false;
}
static int set_solution_scale_exec(bContext *C, wmOperator *op)
{
- return do_set_scale(C, op, true, false);
+ return do_set_scale(C, op, true, false);
}
-static int set_solution_scale_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int set_solution_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- if (!RNA_struct_property_is_set(op->ptr, "distance")) {
- RNA_float_set(op->ptr,
- "distance",
- clip->tracking.settings.object_distance);
- }
+ if (!RNA_struct_property_is_set(op->ptr, "distance")) {
+ RNA_float_set(op->ptr, "distance", clip->tracking.settings.object_distance);
+ }
- return set_solution_scale_exec(C, op);
+ return set_solution_scale_exec(C, op);
}
void CLIP_OT_set_solution_scale(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Solution Scale";
- ot->description = "Set object solution scale using distance between "
- "two selected tracks";
- ot->idname = "CLIP_OT_set_solution_scale";
-
- /* api callbacks */
- ot->exec = set_solution_scale_exec;
- ot->invoke = set_solution_scale_invoke;
- ot->poll = set_solution_scale_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_float(ot->srna, "distance", 0.0f, -FLT_MAX, FLT_MAX,
- "Distance", "Distance between selected tracks",
- -100.0f, 100.0f);
+ /* identifiers */
+ ot->name = "Set Solution Scale";
+ ot->description =
+ "Set object solution scale using distance between "
+ "two selected tracks";
+ ot->idname = "CLIP_OT_set_solution_scale";
+
+ /* api callbacks */
+ ot->exec = set_solution_scale_exec;
+ ot->invoke = set_solution_scale_invoke;
+ ot->poll = set_solution_scale_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_float(ot->srna,
+ "distance",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Distance",
+ "Distance between selected tracks",
+ -100.0f,
+ 100.0f);
}
/********************** apply solution scale operator *********************/
static bool apply_solution_scale_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc != NULL) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
- if (clip != NULL) {
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object =
- BKE_tracking_object_get_active(tracking);
- return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
- }
- }
- return 0;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ if (sc != NULL) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (clip != NULL) {
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+ return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
+ }
+ }
+ return 0;
}
static int apply_solution_scale_exec(bContext *C, wmOperator *op)
{
- return do_set_scale(C, op, false, true);
+ return do_set_scale(C, op, false, true);
}
static int apply_solution_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- if (!RNA_struct_property_is_set(op->ptr, "distance")) {
- RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
- }
- return apply_solution_scale_exec(C, op);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (!RNA_struct_property_is_set(op->ptr, "distance")) {
+ RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
+ }
+ return apply_solution_scale_exec(C, op);
}
void CLIP_OT_apply_solution_scale(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Apply Solution Scale";
- ot->description = "Apply scale on solution itself to make distance between "
- "selected tracks equals to desired";
- ot->idname = "CLIP_OT_apply_solution_scale";
-
- /* api callbacks */
- ot->exec = apply_solution_scale_exec;
- ot->invoke = apply_solution_scale_invoke;
- ot->poll = apply_solution_scale_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_float(ot->srna, "distance", 0.0f, -FLT_MAX, FLT_MAX,
- "Distance", "Distance between selected tracks",
- -100.0f, 100.0f);
+ /* identifiers */
+ ot->name = "Apply Solution Scale";
+ ot->description =
+ "Apply scale on solution itself to make distance between "
+ "selected tracks equals to desired";
+ ot->idname = "CLIP_OT_apply_solution_scale";
+
+ /* api callbacks */
+ ot->exec = apply_solution_scale_exec;
+ ot->invoke = apply_solution_scale_invoke;
+ ot->poll = apply_solution_scale_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_float(ot->srna,
+ "distance",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Distance",
+ "Distance between selected tracks",
+ -100.0f,
+ 100.0f);
}
diff --git a/source/blender/editors/space_clip/tracking_ops_plane.c b/source/blender/editors/space_clip/tracking_ops_plane.c
index a12e03a252c..238410da5e1 100644
--- a/source/blender/editors/space_clip/tracking_ops_plane.c
+++ b/source/blender/editors/space_clip/tracking_ops_plane.c
@@ -47,377 +47,349 @@
static int create_plane_track_tracks_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingPlaneTrack *plane_track;
- ListBase *tracks_base = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- plane_track = BKE_tracking_plane_track_add(tracking,
- plane_tracks_base,
- tracks_base,
- framenr);
-
- if (plane_track == NULL) {
- BKE_report(op->reports, RPT_ERROR, "Need at least 4 selected point tracks to create a plane");
- return OPERATOR_CANCELLED;
- }
- else {
- BKE_tracking_tracks_deselect_all(tracks_base);
-
- plane_track->flag |= SELECT;
- clip->tracking.act_track = NULL;
- clip->tracking.act_plane_track = plane_track;
-
- /* Compute homoraphies and apply them on marker's corner, so we've got
- * quite nice motion from the very beginning.
- */
- BKE_tracking_track_plane_from_existing_motion(plane_track, framenr);
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingPlaneTrack *plane_track;
+ ListBase *tracks_base = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ plane_track = BKE_tracking_plane_track_add(tracking, plane_tracks_base, tracks_base, framenr);
+
+ if (plane_track == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Need at least 4 selected point tracks to create a plane");
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ BKE_tracking_tracks_deselect_all(tracks_base);
+
+ plane_track->flag |= SELECT;
+ clip->tracking.act_track = NULL;
+ clip->tracking.act_plane_track = plane_track;
+
+ /* Compute homoraphies and apply them on marker's corner, so we've got
+ * quite nice motion from the very beginning.
+ */
+ BKE_tracking_track_plane_from_existing_motion(plane_track, framenr);
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_create_plane_track(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Create Plane Track";
- ot->description = "Create new plane track out of selected point tracks";
- ot->idname = "CLIP_OT_create_plane_track";
+ /* identifiers */
+ ot->name = "Create Plane Track";
+ ot->description = "Create new plane track out of selected point tracks";
+ ot->idname = "CLIP_OT_create_plane_track";
- /* api callbacks */
- ot->exec = create_plane_track_tracks_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = create_plane_track_tracks_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** Slide plane marker corner operator *********************/
typedef struct SlidePlaneMarkerData {
- int event_type;
- MovieTrackingPlaneTrack *plane_track;
- MovieTrackingPlaneMarker *plane_marker;
- int width, height;
- int corner_index;
- float *corner;
- int previous_mval[2];
- float previous_corner[2];
- float old_corner[2];
- bool accurate;
+ int event_type;
+ MovieTrackingPlaneTrack *plane_track;
+ MovieTrackingPlaneMarker *plane_marker;
+ int width, height;
+ int corner_index;
+ float *corner;
+ int previous_mval[2];
+ float previous_corner[2];
+ float old_corner[2];
+ bool accurate;
} SlidePlaneMarkerData;
-static float mouse_to_plane_slide_zone_distance_squared(
- const float co[2],
- const float slide_zone[2],
- int width,
- int height)
+static float mouse_to_plane_slide_zone_distance_squared(const float co[2],
+ const float slide_zone[2],
+ int width,
+ int height)
{
- float pixel_co[2] = {co[0] * width, co[1] * height},
- pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
- return SQUARE(pixel_co[0] - pixel_slide_zone[0]) +
- SQUARE(pixel_co[1] - pixel_slide_zone[1]);
+ float pixel_co[2] = {co[0] * width, co[1] * height},
+ pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
+ return SQUARE(pixel_co[0] - pixel_slide_zone[0]) + SQUARE(pixel_co[1] - pixel_slide_zone[1]);
}
-static MovieTrackingPlaneTrack *tracking_plane_marker_check_slide(
- bContext *C,
- const wmEvent *event,
- int *corner_r)
+static MovieTrackingPlaneTrack *tracking_plane_marker_check_slide(bContext *C,
+ const wmEvent *event,
+ int *corner_r)
{
- const float distance_clip_squared = 12.0f * 12.0f;
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- int width, height;
- float co[2];
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- ED_space_clip_get_size(sc, &width, &height);
- if (width == 0 || height == 0) {
- return NULL;
- }
-
- ED_clip_mouse_pos(sc, ar, event->mval, co);
-
- float min_distance_squared = FLT_MAX;
- int min_corner = -1;
- MovieTrackingPlaneTrack *min_plane_track = NULL;
- for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get(plane_track, framenr);
- for (int i = 0; i < 4; i++) {
- float distance_squared =
- mouse_to_plane_slide_zone_distance_squared(
- co,
- plane_marker->corners[i],
- width,
- height);
-
- if (distance_squared < min_distance_squared) {
- min_distance_squared = distance_squared;
- min_corner = i;
- min_plane_track = plane_track;
- }
- }
- }
- }
-
- if (min_distance_squared < distance_clip_squared / sc->zoom) {
- if (corner_r != NULL) {
- *corner_r = min_corner;
- }
- return min_plane_track;
- }
-
- return NULL;
+ const float distance_clip_squared = 12.0f * 12.0f;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ int width, height;
+ float co[2];
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ ED_space_clip_get_size(sc, &width, &height);
+ if (width == 0 || height == 0) {
+ return NULL;
+ }
+
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
+
+ float min_distance_squared = FLT_MAX;
+ int min_corner = -1;
+ MovieTrackingPlaneTrack *min_plane_track = NULL;
+ for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
+ for (int i = 0; i < 4; i++) {
+ float distance_squared = mouse_to_plane_slide_zone_distance_squared(
+ co, plane_marker->corners[i], width, height);
+
+ if (distance_squared < min_distance_squared) {
+ min_distance_squared = distance_squared;
+ min_corner = i;
+ min_plane_track = plane_track;
+ }
+ }
+ }
+ }
+
+ if (min_distance_squared < distance_clip_squared / sc->zoom) {
+ if (corner_r != NULL) {
+ *corner_r = min_corner;
+ }
+ return min_plane_track;
+ }
+
+ return NULL;
}
static void *slide_plane_marker_customdata(bContext *C, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
- MovieTrackingPlaneTrack *plane_track;
- int width, height;
- float co[2];
- SlidePlaneMarkerData *customdata = NULL;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- int corner;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+ MovieTrackingPlaneTrack *plane_track;
+ int width, height;
+ float co[2];
+ SlidePlaneMarkerData *customdata = NULL;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ int corner;
- ED_space_clip_get_size(sc, &width, &height);
- if (width == 0 || height == 0) {
- return NULL;
- }
+ ED_space_clip_get_size(sc, &width, &height);
+ if (width == 0 || height == 0) {
+ return NULL;
+ }
- ED_clip_mouse_pos(sc, ar, event->mval, co);
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
- plane_track = tracking_plane_marker_check_slide(C, event, &corner);
- if (plane_track) {
- MovieTrackingPlaneMarker *plane_marker;
+ plane_track = tracking_plane_marker_check_slide(C, event, &corner);
+ if (plane_track) {
+ MovieTrackingPlaneMarker *plane_marker;
- customdata = MEM_callocN(sizeof(SlidePlaneMarkerData), "slide plane marker data");
+ customdata = MEM_callocN(sizeof(SlidePlaneMarkerData), "slide plane marker data");
- customdata->event_type = event->type;
+ customdata->event_type = event->type;
- plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr);
+ plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr);
- customdata->plane_track = plane_track;
- customdata->plane_marker = plane_marker;
- customdata->width = width;
- customdata->height = height;
+ customdata->plane_track = plane_track;
+ customdata->plane_marker = plane_marker;
+ customdata->width = width;
+ customdata->height = height;
- customdata->previous_mval[0] = event->mval[0];
- customdata->previous_mval[1] = event->mval[1];
+ customdata->previous_mval[0] = event->mval[0];
+ customdata->previous_mval[1] = event->mval[1];
- customdata->corner_index = corner;
- customdata->corner = plane_marker->corners[corner];
+ customdata->corner_index = corner;
+ customdata->corner = plane_marker->corners[corner];
- copy_v2_v2(customdata->previous_corner, customdata->corner);
- copy_v2_v2(customdata->old_corner, customdata->corner);
- }
+ copy_v2_v2(customdata->previous_corner, customdata->corner);
+ copy_v2_v2(customdata->old_corner, customdata->corner);
+ }
- return customdata;
+ return customdata;
}
-static int slide_plane_marker_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *event)
+static int slide_plane_marker_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SlidePlaneMarkerData *slidedata = slide_plane_marker_customdata(C, event);
+ SlidePlaneMarkerData *slidedata = slide_plane_marker_customdata(C, event);
- if (slidedata) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
+ if (slidedata) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
- tracking->act_plane_track = slidedata->plane_track;
- tracking->act_track = NULL;
+ tracking->act_plane_track = slidedata->plane_track;
+ tracking->act_track = NULL;
- op->customdata = slidedata;
+ op->customdata = slidedata;
- clip_tracking_hide_cursor(C);
- WM_event_add_modal_handler(C, op);
+ clip_tracking_hide_cursor(C);
+ WM_event_add_modal_handler(C, op);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- return OPERATOR_RUNNING_MODAL;
- }
+ return OPERATOR_RUNNING_MODAL;
+ }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_PASS_THROUGH;
}
static void cancel_mouse_slide_plane_marker(SlidePlaneMarkerData *data)
{
- copy_v2_v2(data->corner, data->old_corner);
+ copy_v2_v2(data->corner, data->old_corner);
}
static void free_slide_plane_marker_data(SlidePlaneMarkerData *data)
{
- MEM_freeN(data);
+ MEM_freeN(data);
}
-static void slide_plane_marker_update_homographies(SpaceClip *sc,
- SlidePlaneMarkerData *data)
+static void slide_plane_marker_update_homographies(SpaceClip *sc, SlidePlaneMarkerData *data)
{
- int framenr = ED_space_clip_get_clip_frame_number(sc);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
- BKE_tracking_track_plane_from_existing_motion(data->plane_track, framenr);
+ BKE_tracking_track_plane_from_existing_motion(data->plane_track, framenr);
}
-static int slide_plane_marker_modal(bContext *C,
- wmOperator *op,
- const wmEvent *event)
+static int slide_plane_marker_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- SlidePlaneMarkerData *data = (SlidePlaneMarkerData *) op->customdata;
- float dx, dy, mdelta[2];
- int next_corner_index, prev_corner_index, diag_corner_index;
- const float *next_corner, *prev_corner, *diag_corner;
- float next_edge[2], prev_edge[2], next_diag_edge[2], prev_diag_edge[2];
-
- switch (event->type) {
- case LEFTCTRLKEY:
- case RIGHTCTRLKEY:
- case LEFTSHIFTKEY:
- case RIGHTSHIFTKEY:
- if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) {
- data->accurate = event->val == KM_PRESS;
- }
- ATTR_FALLTHROUGH;
- case MOUSEMOVE:
- mdelta[0] = event->mval[0] - data->previous_mval[0];
- mdelta[1] = event->mval[1] - data->previous_mval[1];
-
- dx = mdelta[0] / data->width / sc->zoom;
- dy = mdelta[1] / data->height / sc->zoom;
-
- if (data->accurate) {
- dx /= 5.0f;
- dy /= 5.0f;
- }
-
- data->corner[0] = data->previous_corner[0] + dx;
- data->corner[1] = data->previous_corner[1] + dy;
-
-
- /*
- prev_edge
- (Corner 3, current) <----------------------- (Corner 2, previous)
- | ^
- | |
- | |
- | |
- next_edge | | next_diag_edge
- | |
- | |
- | |
- v |
- (Corner 0, next) -----------------------> (Corner 1, diagonal)
- prev_diag_edge
- */
-
- next_corner_index = (data->corner_index + 1) % 4;
- prev_corner_index = (data->corner_index + 3) % 4;
- diag_corner_index = (data->corner_index + 2) % 4;
-
- next_corner = data->plane_marker->corners[next_corner_index];
- prev_corner = data->plane_marker->corners[prev_corner_index];
- diag_corner = data->plane_marker->corners[diag_corner_index];
-
- sub_v2_v2v2(next_edge, next_corner, data->corner);
- sub_v2_v2v2(prev_edge, data->corner, prev_corner);
- sub_v2_v2v2(next_diag_edge, prev_corner, diag_corner);
- sub_v2_v2v2(prev_diag_edge, diag_corner, next_corner);
-
- if (cross_v2v2(prev_edge, next_edge) < 0.0f) {
- closest_to_line_v2(data->corner,
- data->corner,
- prev_corner,
- next_corner);
- }
-
- if (cross_v2v2(next_diag_edge, prev_edge) < 0.0f) {
- closest_to_line_v2(data->corner,
- data->corner,
- prev_corner,
- diag_corner);
- }
-
- if (cross_v2v2(next_edge, prev_diag_edge) < 0.0f) {
- closest_to_line_v2(data->corner,
- data->corner,
- next_corner,
- diag_corner);
- }
-
- data->previous_mval[0] = event->mval[0];
- data->previous_mval[1] = event->mval[1];
- copy_v2_v2(data->previous_corner, data->corner);
-
- DEG_id_tag_update(&sc->clip->id, 0);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
-
- break;
-
- case LEFTMOUSE:
- case RIGHTMOUSE:
- if (event->type == data->event_type && event->val == KM_RELEASE) {
- /* Marker is now keyframed. */
- data->plane_marker->flag &= ~PLANE_MARKER_TRACKED;
-
- slide_plane_marker_update_homographies(sc, data);
-
- free_slide_plane_marker_data(op->customdata);
-
- clip_tracking_show_cursor(C);
-
- DEG_id_tag_update(&sc->clip->id, 0);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ SlidePlaneMarkerData *data = (SlidePlaneMarkerData *)op->customdata;
+ float dx, dy, mdelta[2];
+ int next_corner_index, prev_corner_index, diag_corner_index;
+ const float *next_corner, *prev_corner, *diag_corner;
+ float next_edge[2], prev_edge[2], next_diag_edge[2], prev_diag_edge[2];
+
+ switch (event->type) {
+ case LEFTCTRLKEY:
+ case RIGHTCTRLKEY:
+ case LEFTSHIFTKEY:
+ case RIGHTSHIFTKEY:
+ if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) {
+ data->accurate = event->val == KM_PRESS;
+ }
+ ATTR_FALLTHROUGH;
+ case MOUSEMOVE:
+ mdelta[0] = event->mval[0] - data->previous_mval[0];
+ mdelta[1] = event->mval[1] - data->previous_mval[1];
+
+ dx = mdelta[0] / data->width / sc->zoom;
+ dy = mdelta[1] / data->height / sc->zoom;
+
+ if (data->accurate) {
+ dx /= 5.0f;
+ dy /= 5.0f;
+ }
+
+ data->corner[0] = data->previous_corner[0] + dx;
+ data->corner[1] = data->previous_corner[1] + dy;
+
+ /*
+ prev_edge
+ (Corner 3, current) <----------------------- (Corner 2, previous)
+ | ^
+ | |
+ | |
+ | |
+ next_edge | | next_diag_edge
+ | |
+ | |
+ | |
+ v |
+ (Corner 0, next) -----------------------> (Corner 1, diagonal)
+ prev_diag_edge
+ */
+
+ next_corner_index = (data->corner_index + 1) % 4;
+ prev_corner_index = (data->corner_index + 3) % 4;
+ diag_corner_index = (data->corner_index + 2) % 4;
+
+ next_corner = data->plane_marker->corners[next_corner_index];
+ prev_corner = data->plane_marker->corners[prev_corner_index];
+ diag_corner = data->plane_marker->corners[diag_corner_index];
+
+ sub_v2_v2v2(next_edge, next_corner, data->corner);
+ sub_v2_v2v2(prev_edge, data->corner, prev_corner);
+ sub_v2_v2v2(next_diag_edge, prev_corner, diag_corner);
+ sub_v2_v2v2(prev_diag_edge, diag_corner, next_corner);
+
+ if (cross_v2v2(prev_edge, next_edge) < 0.0f) {
+ closest_to_line_v2(data->corner, data->corner, prev_corner, next_corner);
+ }
+
+ if (cross_v2v2(next_diag_edge, prev_edge) < 0.0f) {
+ closest_to_line_v2(data->corner, data->corner, prev_corner, diag_corner);
+ }
+
+ if (cross_v2v2(next_edge, prev_diag_edge) < 0.0f) {
+ closest_to_line_v2(data->corner, data->corner, next_corner, diag_corner);
+ }
+
+ data->previous_mval[0] = event->mval[0];
+ data->previous_mval[1] = event->mval[1];
+ copy_v2_v2(data->previous_corner, data->corner);
+
+ DEG_id_tag_update(&sc->clip->id, 0);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+
+ break;
+
+ case LEFTMOUSE:
+ case RIGHTMOUSE:
+ if (event->type == data->event_type && event->val == KM_RELEASE) {
+ /* Marker is now keyframed. */
+ data->plane_marker->flag &= ~PLANE_MARKER_TRACKED;
+
+ slide_plane_marker_update_homographies(sc, data);
+
+ free_slide_plane_marker_data(op->customdata);
+
+ clip_tracking_show_cursor(C);
+
+ DEG_id_tag_update(&sc->clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+
+ return OPERATOR_FINISHED;
+ }
+
+ break;
- return OPERATOR_FINISHED;
- }
-
- break;
+ case ESCKEY:
+ cancel_mouse_slide_plane_marker(op->customdata);
- case ESCKEY:
- cancel_mouse_slide_plane_marker(op->customdata);
+ free_slide_plane_marker_data(op->customdata);
- free_slide_plane_marker_data(op->customdata);
+ clip_tracking_show_cursor(C);
- clip_tracking_show_cursor(C);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+ return OPERATOR_CANCELLED;
+ }
- return OPERATOR_CANCELLED;
- }
-
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void CLIP_OT_slide_plane_marker(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Slide Plane Marker";
- ot->description = "Slide plane marker areas";
- ot->idname = "CLIP_OT_slide_plane_marker";
-
- /* api callbacks */
- ot->poll = ED_space_clip_tracking_poll;
- ot->invoke = slide_plane_marker_invoke;
- ot->modal = slide_plane_marker_modal;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
+ /* identifiers */
+ ot->name = "Slide Plane Marker";
+ ot->description = "Slide plane marker areas";
+ ot->idname = "CLIP_OT_slide_plane_marker";
+
+ /* api callbacks */
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->invoke = slide_plane_marker_invoke;
+ ot->modal = slide_plane_marker_modal;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
}
diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c
index 03e03f94a66..ca57b3ea57f 100644
--- a/source/blender/editors/space_clip/tracking_ops_solve.c
+++ b/source/blender/editors/space_clip/tracking_ops_solve.c
@@ -24,7 +24,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_camera_types.h"
-#include "DNA_object_types.h" /* SELECT */
+#include "DNA_object_types.h" /* SELECT */
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
@@ -45,300 +45,270 @@
#include "ED_clip.h"
-
#include "clip_intern.h"
/********************** solve camera operator *********************/
typedef struct {
- Scene *scene;
- MovieClip *clip;
- MovieClipUser user;
+ Scene *scene;
+ MovieClip *clip;
+ MovieClipUser user;
- ReportList *reports;
+ ReportList *reports;
- char stats_message[256];
+ char stats_message[256];
- struct MovieReconstructContext *context;
+ struct MovieReconstructContext *context;
} SolveCameraJob;
-static bool solve_camera_initjob(bContext *C,
- SolveCameraJob *scj,
- wmOperator *op,
- char *error_msg,
- int max_error)
+static bool solve_camera_initjob(
+ bContext *C, SolveCameraJob *scj, wmOperator *op, char *error_msg, int max_error)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- Scene *scene = CTX_data_scene(C);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
- int width, height;
-
- if (!BKE_tracking_reconstruction_check(tracking,
- object,
- error_msg,
- max_error))
- {
- return false;
- }
-
- /* Could fail if footage uses images with different sizes. */
- BKE_movieclip_get_size(clip, &sc->user, &width, &height);
-
- scj->clip = clip;
- scj->scene = scene;
- scj->reports = op->reports;
- scj->user = sc->user;
-
- scj->context = BKE_tracking_reconstruction_context_new(clip,
- object,
- object->keyframe1,
- object->keyframe2,
- width,
- height);
-
- tracking->stats = MEM_callocN(sizeof(MovieTrackingStats), "solve camera stats");
-
- return true;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ Scene *scene = CTX_data_scene(C);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
+ int width, height;
+
+ if (!BKE_tracking_reconstruction_check(tracking, object, error_msg, max_error)) {
+ return false;
+ }
+
+ /* Could fail if footage uses images with different sizes. */
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+ scj->clip = clip;
+ scj->scene = scene;
+ scj->reports = op->reports;
+ scj->user = sc->user;
+
+ scj->context = BKE_tracking_reconstruction_context_new(
+ clip, object, object->keyframe1, object->keyframe2, width, height);
+
+ tracking->stats = MEM_callocN(sizeof(MovieTrackingStats), "solve camera stats");
+
+ return true;
}
static void solve_camera_updatejob(void *scv)
{
- SolveCameraJob *scj = (SolveCameraJob *)scv;
- MovieTracking *tracking = &scj->clip->tracking;
+ SolveCameraJob *scj = (SolveCameraJob *)scv;
+ MovieTracking *tracking = &scj->clip->tracking;
- BLI_strncpy(tracking->stats->message,
- scj->stats_message,
- sizeof(tracking->stats->message));
+ BLI_strncpy(tracking->stats->message, scj->stats_message, sizeof(tracking->stats->message));
}
static void solve_camera_startjob(void *scv, short *stop, short *do_update, float *progress)
{
- SolveCameraJob *scj = (SolveCameraJob *)scv;
- BKE_tracking_reconstruction_solve(scj->context,
- stop,
- do_update,
- progress,
- scj->stats_message,
- sizeof(scj->stats_message));
+ SolveCameraJob *scj = (SolveCameraJob *)scv;
+ BKE_tracking_reconstruction_solve(
+ scj->context, stop, do_update, progress, scj->stats_message, sizeof(scj->stats_message));
}
static void solve_camera_freejob(void *scv)
{
- SolveCameraJob *scj = (SolveCameraJob *)scv;
- MovieTracking *tracking = &scj->clip->tracking;
- Scene *scene = scj->scene;
- MovieClip *clip = scj->clip;
- int solved;
-
- if (!scj->context) {
- /* job weren't fully initialized due to some error */
- MEM_freeN(scj);
- return;
- }
-
- solved = BKE_tracking_reconstruction_finish(scj->context, tracking);
- if (!solved) {
- BKE_report(scj->reports,
- RPT_WARNING,
- "Some data failed to reconstruct (see console for details)");
- }
- else {
- BKE_reportf(scj->reports,
- RPT_INFO,
- "Average re-projection error: %.3f",
- tracking->reconstruction.error);
- }
-
- /* Set currently solved clip as active for scene. */
- if (scene->clip != NULL) {
- id_us_min(&clip->id);
- }
- scene->clip = clip;
- id_us_plus(&clip->id);
-
- /* Set blender camera focal length so result would look fine there. */
- if (scene->camera != NULL &&
- scene->camera->data &&
- GS(((ID *) scene->camera->data)->name) == ID_CA)
- {
- Camera *camera = (Camera *)scene->camera->data;
- int width, height;
- BKE_movieclip_get_size(clip, &scj->user, &width, &height);
- BKE_tracking_camera_to_blender(tracking, scene, camera, width, height);
- WM_main_add_notifier(NC_OBJECT, camera);
- }
-
- MEM_freeN(tracking->stats);
- tracking->stats = NULL;
-
- DEG_id_tag_update(&clip->id, 0);
-
- WM_main_add_notifier(NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, NULL);
-
- /* Update active clip displayed in scene buttons. */
- WM_main_add_notifier(NC_SCENE, scene);
-
- BKE_tracking_reconstruction_context_free(scj->context);
- MEM_freeN(scj);
+ SolveCameraJob *scj = (SolveCameraJob *)scv;
+ MovieTracking *tracking = &scj->clip->tracking;
+ Scene *scene = scj->scene;
+ MovieClip *clip = scj->clip;
+ int solved;
+
+ if (!scj->context) {
+ /* job weren't fully initialized due to some error */
+ MEM_freeN(scj);
+ return;
+ }
+
+ solved = BKE_tracking_reconstruction_finish(scj->context, tracking);
+ if (!solved) {
+ BKE_report(
+ scj->reports, RPT_WARNING, "Some data failed to reconstruct (see console for details)");
+ }
+ else {
+ BKE_reportf(scj->reports,
+ RPT_INFO,
+ "Average re-projection error: %.3f",
+ tracking->reconstruction.error);
+ }
+
+ /* Set currently solved clip as active for scene. */
+ if (scene->clip != NULL) {
+ id_us_min(&clip->id);
+ }
+ scene->clip = clip;
+ id_us_plus(&clip->id);
+
+ /* Set blender camera focal length so result would look fine there. */
+ if (scene->camera != NULL && scene->camera->data &&
+ GS(((ID *)scene->camera->data)->name) == ID_CA) {
+ Camera *camera = (Camera *)scene->camera->data;
+ int width, height;
+ BKE_movieclip_get_size(clip, &scj->user, &width, &height);
+ BKE_tracking_camera_to_blender(tracking, scene, camera, width, height);
+ WM_main_add_notifier(NC_OBJECT, camera);
+ }
+
+ MEM_freeN(tracking->stats);
+ tracking->stats = NULL;
+
+ DEG_id_tag_update(&clip->id, 0);
+
+ WM_main_add_notifier(NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, NULL);
+
+ /* Update active clip displayed in scene buttons. */
+ WM_main_add_notifier(NC_SCENE, scene);
+
+ BKE_tracking_reconstruction_context_free(scj->context);
+ MEM_freeN(scj);
}
static int solve_camera_exec(bContext *C, wmOperator *op)
{
- SolveCameraJob *scj;
- char error_msg[256] = "\0";
- scj = MEM_callocN(sizeof(SolveCameraJob), "SolveCameraJob data");
- if (!solve_camera_initjob(C, scj, op, error_msg, sizeof(error_msg))) {
- if (error_msg[0]) {
- BKE_report(op->reports, RPT_ERROR, error_msg);
- }
- solve_camera_freejob(scj);
- return OPERATOR_CANCELLED;
- }
- solve_camera_startjob(scj, NULL, NULL, NULL);
- solve_camera_freejob(scj);
- return OPERATOR_FINISHED;
+ SolveCameraJob *scj;
+ char error_msg[256] = "\0";
+ scj = MEM_callocN(sizeof(SolveCameraJob), "SolveCameraJob data");
+ if (!solve_camera_initjob(C, scj, op, error_msg, sizeof(error_msg))) {
+ if (error_msg[0]) {
+ BKE_report(op->reports, RPT_ERROR, error_msg);
+ }
+ solve_camera_freejob(scj);
+ return OPERATOR_CANCELLED;
+ }
+ solve_camera_startjob(scj, NULL, NULL, NULL);
+ solve_camera_freejob(scj);
+ return OPERATOR_FINISHED;
}
-static int solve_camera_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int solve_camera_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SolveCameraJob *scj;
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingReconstruction *reconstruction =
- BKE_tracking_get_active_reconstruction(tracking);
- wmJob *wm_job;
- char error_msg[256] = "\0";
-
- if (WM_jobs_test(CTX_wm_manager(C), sa, WM_JOB_TYPE_ANY)) {
- /* only one solve is allowed at a time */
- return OPERATOR_CANCELLED;
- }
-
- scj = MEM_callocN(sizeof(SolveCameraJob), "SolveCameraJob data");
- if (!solve_camera_initjob(C, scj, op, error_msg, sizeof(error_msg))) {
- if (error_msg[0]) {
- BKE_report(op->reports, RPT_ERROR, error_msg);
- }
- solve_camera_freejob(scj);
- return OPERATOR_CANCELLED;
- }
-
- BLI_strncpy(tracking->stats->message,
- "Solving camera | Preparing solve",
- sizeof(tracking->stats->message));
-
- /* Hide reconstruction statistics from previous solve. */
- reconstruction->flag &= ~TRACKING_RECONSTRUCTED;
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- /* Setup job. */
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Solve Camera",
- WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_SOLVE_CAMERA);
- WM_jobs_customdata_set(wm_job, scj, solve_camera_freejob);
- WM_jobs_timer(wm_job, 0.1, NC_MOVIECLIP | NA_EVALUATED, 0);
- WM_jobs_callbacks(wm_job,
- solve_camera_startjob,
- NULL,
- solve_camera_updatejob,
- NULL);
-
- G.is_break = false;
-
- WM_jobs_start(CTX_wm_manager(C), wm_job);
- WM_cursor_wait(0);
-
- /* add modal handler for ESC */
- WM_event_add_modal_handler(C, op);
-
- return OPERATOR_RUNNING_MODAL;
+ SolveCameraJob *scj;
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
+ wmJob *wm_job;
+ char error_msg[256] = "\0";
+
+ if (WM_jobs_test(CTX_wm_manager(C), sa, WM_JOB_TYPE_ANY)) {
+ /* only one solve is allowed at a time */
+ return OPERATOR_CANCELLED;
+ }
+
+ scj = MEM_callocN(sizeof(SolveCameraJob), "SolveCameraJob data");
+ if (!solve_camera_initjob(C, scj, op, error_msg, sizeof(error_msg))) {
+ if (error_msg[0]) {
+ BKE_report(op->reports, RPT_ERROR, error_msg);
+ }
+ solve_camera_freejob(scj);
+ return OPERATOR_CANCELLED;
+ }
+
+ BLI_strncpy(tracking->stats->message,
+ "Solving camera | Preparing solve",
+ sizeof(tracking->stats->message));
+
+ /* Hide reconstruction statistics from previous solve. */
+ reconstruction->flag &= ~TRACKING_RECONSTRUCTED;
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ /* Setup job. */
+ wm_job = WM_jobs_get(CTX_wm_manager(C),
+ CTX_wm_window(C),
+ sa,
+ "Solve Camera",
+ WM_JOB_PROGRESS,
+ WM_JOB_TYPE_CLIP_SOLVE_CAMERA);
+ WM_jobs_customdata_set(wm_job, scj, solve_camera_freejob);
+ WM_jobs_timer(wm_job, 0.1, NC_MOVIECLIP | NA_EVALUATED, 0);
+ WM_jobs_callbacks(wm_job, solve_camera_startjob, NULL, solve_camera_updatejob, NULL);
+
+ G.is_break = false;
+
+ WM_jobs_start(CTX_wm_manager(C), wm_job);
+ WM_cursor_wait(0);
+
+ /* add modal handler for ESC */
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
}
-static int solve_camera_modal(bContext *C,
- wmOperator *UNUSED(op),
- const wmEvent *event)
+static int solve_camera_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- /* No running solver, remove handler and pass through. */
- if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY))
- return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+ /* No running solver, remove handler and pass through. */
+ if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY))
+ return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
- /* Running solver. */
- switch (event->type) {
- case ESCKEY:
- return OPERATOR_RUNNING_MODAL;
- }
+ /* Running solver. */
+ switch (event->type) {
+ case ESCKEY:
+ return OPERATOR_RUNNING_MODAL;
+ }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_PASS_THROUGH;
}
void CLIP_OT_solve_camera(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Solve Camera";
- ot->description = "Solve camera motion from tracks";
- ot->idname = "CLIP_OT_solve_camera";
-
- /* api callbacks */
- ot->exec = solve_camera_exec;
- ot->invoke = solve_camera_invoke;
- ot->modal = solve_camera_modal;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* identifiers */
+ ot->name = "Solve Camera";
+ ot->description = "Solve camera motion from tracks";
+ ot->idname = "CLIP_OT_solve_camera";
+
+ /* api callbacks */
+ ot->exec = solve_camera_exec;
+ ot->invoke = solve_camera_invoke;
+ ot->modal = solve_camera_modal;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** clear solution operator *********************/
static int clear_solution_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- MovieTrackingReconstruction *reconstruction =
- BKE_tracking_get_active_reconstruction(tracking);
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- track->flag &= ~TRACK_HAS_BUNDLE;
- }
-
- if (reconstruction->cameras != NULL) {
- MEM_freeN(reconstruction->cameras);
- reconstruction->cameras = NULL;
- }
-
- reconstruction->camnr = 0;
- reconstruction->flag &= ~TRACKING_RECONSTRUCTED;
-
- DEG_id_tag_update(&clip->id, 0);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ track->flag &= ~TRACK_HAS_BUNDLE;
+ }
+
+ if (reconstruction->cameras != NULL) {
+ MEM_freeN(reconstruction->cameras);
+ reconstruction->cameras = NULL;
+ }
+
+ reconstruction->camnr = 0;
+ reconstruction->flag &= ~TRACKING_RECONSTRUCTED;
+
+ DEG_id_tag_update(&clip->id, 0);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_clear_solution(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Clear Solution";
- ot->description = "Clear all calculated data";
- ot->idname = "CLIP_OT_clear_solution";
+ /* identifiers */
+ ot->name = "Clear Solution";
+ ot->description = "Clear all calculated data";
+ ot->idname = "CLIP_OT_clear_solution";
- /* api callbacks */
- ot->exec = clear_solution_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = clear_solution_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
diff --git a/source/blender/editors/space_clip/tracking_ops_stabilize.c b/source/blender/editors/space_clip/tracking_ops_stabilize.c
index ab7585cbf57..5e43b7c7ec6 100644
--- a/source/blender/editors/space_clip/tracking_ops_stabilize.c
+++ b/source/blender/editors/space_clip/tracking_ops_stabilize.c
@@ -44,296 +44,273 @@
static bool stabilize_2d_poll(bContext *C)
{
- if (ED_space_clip_tracking_poll(C)) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTrackingObject *tracking_object =
- BKE_tracking_object_get_active(&clip->tracking);
- return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
- }
- return 0;
+ if (ED_space_clip_tracking_poll(C)) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
+ return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
+ }
+ return 0;
}
static int stabilize_2d_add_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingStabilization *stab = &tracking->stabilization;
-
- bool update = false;
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) &&
- (track->flag & TRACK_USE_2D_STAB) == 0)
- {
- track->flag |= TRACK_USE_2D_STAB;
- stab->tot_track++;
- update = true;
- }
- }
-
- if (update) {
- DEG_id_tag_update(&clip->id, 0);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingStabilization *stab = &tracking->stabilization;
+
+ bool update = false;
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_USE_2D_STAB) == 0) {
+ track->flag |= TRACK_USE_2D_STAB;
+ stab->tot_track++;
+ update = true;
+ }
+ }
+
+ if (update) {
+ DEG_id_tag_update(&clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_add(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Stabilization Tracks";
- ot->description = "Add selected tracks to 2D translation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_add";
+ /* identifiers */
+ ot->name = "Add Stabilization Tracks";
+ ot->description = "Add selected tracks to 2D translation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_add";
- /* api callbacks */
- ot->exec = stabilize_2d_add_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_add_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* remove 2d stabilization tracks operator ******************/
static int stabilize_2d_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingStabilization *stab = &tracking->stabilization;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int a = 0;
- bool update = false;
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (track->flag & TRACK_USE_2D_STAB) {
- if (a == stab->act_track) {
- track->flag &= ~TRACK_USE_2D_STAB;
- stab->act_track--;
- stab->tot_track--;
- if (stab->act_track < 0) {
- stab->act_track = 0;
- }
- update = true;
- break;
- }
- a++;
- }
- }
-
- if (update) {
- DEG_id_tag_update(&clip->id, 0);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingStabilization *stab = &tracking->stabilization;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int a = 0;
+ bool update = false;
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (track->flag & TRACK_USE_2D_STAB) {
+ if (a == stab->act_track) {
+ track->flag &= ~TRACK_USE_2D_STAB;
+ stab->act_track--;
+ stab->tot_track--;
+ if (stab->act_track < 0) {
+ stab->act_track = 0;
+ }
+ update = true;
+ break;
+ }
+ a++;
+ }
+ }
+
+ if (update) {
+ DEG_id_tag_update(&clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_remove(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Remove Stabilization Track";
- ot->description = "Remove selected track from translation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_remove";
+ /* identifiers */
+ ot->name = "Remove Stabilization Track";
+ ot->description = "Remove selected track from translation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_remove";
- /* api callbacks */
- ot->exec = stabilize_2d_remove_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_remove_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* select 2d stabilization tracks operator ******************/
static int stabilize_2d_select_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- bool update = false;
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (track->flag & TRACK_USE_2D_STAB) {
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- update = true;
- }
- }
-
- if (update) {
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ bool update = false;
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (track->flag & TRACK_USE_2D_STAB) {
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ update = true;
+ }
+ }
+
+ if (update) {
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_select(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select Stabilization Tracks";
- ot->description = "Select tracks which are used for translation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_select";
+ /* identifiers */
+ ot->name = "Select Stabilization Tracks";
+ ot->description = "Select tracks which are used for translation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_select";
- /* api callbacks */
- ot->exec = stabilize_2d_select_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_select_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** add 2d stabilization tracks for rotation operator ****************/
static int stabilize_2d_rotation_add_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingStabilization *stab = &tracking->stabilization;
-
- bool update = false;
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track) &&
- (track->flag & TRACK_USE_2D_STAB_ROT) == 0)
- {
- track->flag |= TRACK_USE_2D_STAB_ROT;
- stab->tot_rot_track++;
- update = true;
- }
- }
-
- if (update) {
- DEG_id_tag_update(&clip->id, 0);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingStabilization *stab = &tracking->stabilization;
+
+ bool update = false;
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_USE_2D_STAB_ROT) == 0) {
+ track->flag |= TRACK_USE_2D_STAB_ROT;
+ stab->tot_rot_track++;
+ update = true;
+ }
+ }
+
+ if (update) {
+ DEG_id_tag_update(&clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_rotation_add(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Stabilization Rotation Tracks";
- ot->description = "Add selected tracks to 2D rotation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_rotation_add";
+ /* identifiers */
+ ot->name = "Add Stabilization Rotation Tracks";
+ ot->description = "Add selected tracks to 2D rotation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_rotation_add";
- /* api callbacks */
- ot->exec = stabilize_2d_rotation_add_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_rotation_add_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** remove 2d stabilization tracks for rotation operator *************/
static int stabilize_2d_rotation_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingStabilization *stab = &tracking->stabilization;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int a = 0;
- bool update = false;
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (track->flag & TRACK_USE_2D_STAB_ROT) {
- if (a == stab->act_rot_track) {
- track->flag &= ~TRACK_USE_2D_STAB_ROT;
- stab->act_rot_track--;
- stab->tot_rot_track--;
- if (stab->act_rot_track < 0) {
- stab->act_rot_track = 0;
- }
- update = true;
- break;
- }
- a++;
- }
- }
-
- if (update) {
- DEG_id_tag_update(&clip->id, 0);
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingStabilization *stab = &tracking->stabilization;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int a = 0;
+ bool update = false;
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (track->flag & TRACK_USE_2D_STAB_ROT) {
+ if (a == stab->act_rot_track) {
+ track->flag &= ~TRACK_USE_2D_STAB_ROT;
+ stab->act_rot_track--;
+ stab->tot_rot_track--;
+ if (stab->act_rot_track < 0) {
+ stab->act_rot_track = 0;
+ }
+ update = true;
+ break;
+ }
+ a++;
+ }
+ }
+
+ if (update) {
+ DEG_id_tag_update(&clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_rotation_remove(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Remove Stabilization Rotation Track";
- ot->description = "Remove selected track from rotation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_rotation_remove";
+ /* identifiers */
+ ot->name = "Remove Stabilization Rotation Track";
+ ot->description = "Remove selected track from rotation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_rotation_remove";
- /* api callbacks */
- ot->exec = stabilize_2d_rotation_remove_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_rotation_remove_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************** select 2d stabilization rotation tracks operator *****************/
static int stabilize_2d_rotation_select_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- bool update = false;
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (track->flag & TRACK_USE_2D_STAB_ROT) {
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- update = true;
- }
- }
-
- if (update) {
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
- }
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ bool update = false;
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (track->flag & TRACK_USE_2D_STAB_ROT) {
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ update = true;
+ }
+ }
+
+ if (update) {
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
+ }
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_rotation_select(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select Stabilization Rotation Tracks";
- ot->description = "Select tracks which are used for rotation stabilization";
- ot->idname = "CLIP_OT_stabilize_2d_rotation_select";
+ /* identifiers */
+ ot->name = "Select Stabilization Rotation Tracks";
+ ot->description = "Select tracks which are used for rotation stabilization";
+ ot->idname = "CLIP_OT_stabilize_2d_rotation_select";
- /* api callbacks */
- ot->exec = stabilize_2d_rotation_select_exec;
- ot->poll = stabilize_2d_poll;
+ /* api callbacks */
+ ot->exec = stabilize_2d_rotation_select_exec;
+ ot->poll = stabilize_2d_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
diff --git a/source/blender/editors/space_clip/tracking_ops_track.c b/source/blender/editors/space_clip/tracking_ops_track.c
index 4c14049865b..d985e82fd1a 100644
--- a/source/blender/editors/space_clip/tracking_ops_track.c
+++ b/source/blender/editors/space_clip/tracking_ops_track.c
@@ -44,441 +44,410 @@
#include "PIL_time.h"
-#include "clip_intern.h" // own include
+#include "clip_intern.h" // own include
#include "tracking_ops_intern.h"
/********************** Track operator *********************/
typedef struct TrackMarkersJob {
- struct AutoTrackContext *context; /* Tracking context */
- int sfra, efra, lastfra; /* Start, end and recently tracked frames */
- int backwards; /* Backwards tracking flag */
- MovieClip *clip; /* Clip which is tracking */
- float delay; /* Delay in milliseconds to allow
- * tracking at fixed FPS */
-
- struct Main *main;
- struct Scene *scene;
- struct bScreen *screen;
+ struct AutoTrackContext *context; /* Tracking context */
+ int sfra, efra, lastfra; /* Start, end and recently tracked frames */
+ int backwards; /* Backwards tracking flag */
+ MovieClip *clip; /* Clip which is tracking */
+ float delay; /* Delay in milliseconds to allow
+ * tracking at fixed FPS */
+
+ struct Main *main;
+ struct Scene *scene;
+ struct bScreen *screen;
} TrackMarkersJob;
static bool track_markers_testbreak(void)
{
- return G.is_break;
+ return G.is_break;
}
-static int track_count_markers(SpaceClip *sc,
- MovieClip *clip,
- int framenr)
+static int track_count_markers(SpaceClip *sc, MovieClip *clip, int framenr)
{
- int tot = 0;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- bool selected = (sc != NULL) ? TRACK_VIEW_SELECTED(sc, track)
- : TRACK_SELECTED(track);
- if (selected && (track->flag & TRACK_LOCKED) == 0) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track,
- framenr);
- if (!marker || (marker->flag & MARKER_DISABLED) == 0) {
- tot++;
- }
- }
- }
- return tot;
+ int tot = 0;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ bool selected = (sc != NULL) ? TRACK_VIEW_SELECTED(sc, track) : TRACK_SELECTED(track);
+ if (selected && (track->flag & TRACK_LOCKED) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ if (!marker || (marker->flag & MARKER_DISABLED) == 0) {
+ tot++;
+ }
+ }
+ }
+ return tot;
}
-static void track_init_markers(SpaceClip *sc,
- MovieClip *clip,
- int framenr,
- int *frames_limit_r)
+static void track_init_markers(SpaceClip *sc, MovieClip *clip, int framenr, int *frames_limit_r)
{
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- int frames_limit = 0;
- if (sc != NULL) {
- clip_tracking_clear_invisible_track_selection(sc, clip);
- }
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- bool selected = (sc != NULL) ? TRACK_VIEW_SELECTED(sc, track)
- : TRACK_SELECTED(track);
- if (selected) {
- if ((track->flag & TRACK_HIDDEN) == 0 &&
- (track->flag & TRACK_LOCKED) == 0)
- {
- BKE_tracking_marker_ensure(track, framenr);
- if (track->frames_limit) {
- if (frames_limit == 0) {
- frames_limit = track->frames_limit;
- }
- else {
- frames_limit = min_ii(frames_limit,
- (int)track->frames_limit);
- }
- }
- }
- }
- }
- *frames_limit_r = frames_limit;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int frames_limit = 0;
+ if (sc != NULL) {
+ clip_tracking_clear_invisible_track_selection(sc, clip);
+ }
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ bool selected = (sc != NULL) ? TRACK_VIEW_SELECTED(sc, track) : TRACK_SELECTED(track);
+ if (selected) {
+ if ((track->flag & TRACK_HIDDEN) == 0 && (track->flag & TRACK_LOCKED) == 0) {
+ BKE_tracking_marker_ensure(track, framenr);
+ if (track->frames_limit) {
+ if (frames_limit == 0) {
+ frames_limit = track->frames_limit;
+ }
+ else {
+ frames_limit = min_ii(frames_limit, (int)track->frames_limit);
+ }
+ }
+ }
+ }
+ }
+ *frames_limit_r = frames_limit;
}
static bool track_markers_check_direction(int backwards, int curfra, int efra)
{
- if (backwards) {
- if (curfra < efra) {
- return false;
- }
- }
- else {
- if (curfra > efra) {
- return false;
- }
- }
-
- return true;
+ if (backwards) {
+ if (curfra < efra) {
+ return false;
+ }
+ }
+ else {
+ if (curfra > efra) {
+ return false;
+ }
+ }
+
+ return true;
}
-static int track_markers_initjob(bContext *C,
- TrackMarkersJob *tmj,
- bool backwards,
- bool sequence)
+static int track_markers_initjob(bContext *C, TrackMarkersJob *tmj, bool backwards, bool sequence)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- Scene *scene = CTX_data_scene(C);
- MovieTrackingSettings *settings = &clip->tracking.settings;
- int frames_limit;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- track_init_markers(sc, clip, framenr, &frames_limit);
-
- tmj->sfra = framenr;
- tmj->clip = clip;
- tmj->backwards = backwards;
-
- if (sequence) {
- if (backwards) {
- tmj->efra = SFRA;
- }
- else {
- tmj->efra = EFRA;
- }
- tmj->efra = BKE_movieclip_remap_scene_to_clip_frame(clip, tmj->efra);
- }
- else {
- if (backwards) {
- tmj->efra = tmj->sfra - 1;
- }
- else {
- tmj->efra = tmj->sfra + 1;
- }
- }
-
- /* Limit frames to be tracked by user setting. */
- if (frames_limit) {
- if (backwards) {
- tmj->efra = MAX2(tmj->efra, tmj->sfra - frames_limit);
- }
- else {
- tmj->efra = MIN2(tmj->efra, tmj->sfra + frames_limit);
- }
- }
-
- if (settings->speed != TRACKING_SPEED_FASTEST) {
- tmj->delay = 1.0f / scene->r.frs_sec * 1000.0f;
-
- if (settings->speed == TRACKING_SPEED_HALF) {
- tmj->delay *= 2;
- }
- else if (settings->speed == TRACKING_SPEED_QUARTER) {
- tmj->delay *= 4;
- }
- else if (settings->speed == TRACKING_SPEED_DOUBLE) {
- tmj->delay /= 2;
- }
- }
-
- tmj->context = BKE_autotrack_context_new(clip, &sc->user, backwards, true);
-
- clip->tracking_context = tmj->context;
-
- tmj->lastfra = tmj->sfra;
-
- /* XXX: silly to store this, but this data is needed to update scene and
- * movie-clip numbers when tracking is finished. This introduces
- * better feedback for artists.
- * Maybe there's another way to solve this problem, but can't think
- * better way atm.
- * Anyway, this way isn't more unstable as animation rendering
- * animation which uses the same approach (except storing screen).
- */
- tmj->scene = scene;
- tmj->main = CTX_data_main(C);
- tmj->screen = CTX_wm_screen(C);
-
- return track_markers_check_direction(backwards, tmj->sfra, tmj->efra);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ Scene *scene = CTX_data_scene(C);
+ MovieTrackingSettings *settings = &clip->tracking.settings;
+ int frames_limit;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ track_init_markers(sc, clip, framenr, &frames_limit);
+
+ tmj->sfra = framenr;
+ tmj->clip = clip;
+ tmj->backwards = backwards;
+
+ if (sequence) {
+ if (backwards) {
+ tmj->efra = SFRA;
+ }
+ else {
+ tmj->efra = EFRA;
+ }
+ tmj->efra = BKE_movieclip_remap_scene_to_clip_frame(clip, tmj->efra);
+ }
+ else {
+ if (backwards) {
+ tmj->efra = tmj->sfra - 1;
+ }
+ else {
+ tmj->efra = tmj->sfra + 1;
+ }
+ }
+
+ /* Limit frames to be tracked by user setting. */
+ if (frames_limit) {
+ if (backwards) {
+ tmj->efra = MAX2(tmj->efra, tmj->sfra - frames_limit);
+ }
+ else {
+ tmj->efra = MIN2(tmj->efra, tmj->sfra + frames_limit);
+ }
+ }
+
+ if (settings->speed != TRACKING_SPEED_FASTEST) {
+ tmj->delay = 1.0f / scene->r.frs_sec * 1000.0f;
+
+ if (settings->speed == TRACKING_SPEED_HALF) {
+ tmj->delay *= 2;
+ }
+ else if (settings->speed == TRACKING_SPEED_QUARTER) {
+ tmj->delay *= 4;
+ }
+ else if (settings->speed == TRACKING_SPEED_DOUBLE) {
+ tmj->delay /= 2;
+ }
+ }
+
+ tmj->context = BKE_autotrack_context_new(clip, &sc->user, backwards, true);
+
+ clip->tracking_context = tmj->context;
+
+ tmj->lastfra = tmj->sfra;
+
+ /* XXX: silly to store this, but this data is needed to update scene and
+ * movie-clip numbers when tracking is finished. This introduces
+ * better feedback for artists.
+ * Maybe there's another way to solve this problem, but can't think
+ * better way atm.
+ * Anyway, this way isn't more unstable as animation rendering
+ * animation which uses the same approach (except storing screen).
+ */
+ tmj->scene = scene;
+ tmj->main = CTX_data_main(C);
+ tmj->screen = CTX_wm_screen(C);
+
+ return track_markers_check_direction(backwards, tmj->sfra, tmj->efra);
}
-static void track_markers_startjob(void *tmv,
- short *stop,
- short *do_update,
- float *progress)
+static void track_markers_startjob(void *tmv, short *stop, short *do_update, float *progress)
{
- TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
- int framenr = tmj->sfra;
-
- while (framenr != tmj->efra) {
- if (tmj->delay > 0) {
- /* Tracking should happen with fixed fps. Calculate time
- * using current timer value before tracking frame and after.
- *
- * Small (and maybe unneeded optimization): do not calculate
- * exec_time for "Fastest" tracking
- */
-
- double start_time = PIL_check_seconds_timer(), exec_time;
-
- if (!BKE_autotrack_context_step(tmj->context)) {
- break;
- }
-
- exec_time = PIL_check_seconds_timer() - start_time;
- if (tmj->delay > (float)exec_time) {
- PIL_sleep_ms(tmj->delay - (float)exec_time);
- }
- }
- else if (!BKE_autotrack_context_step(tmj->context)) {
- break;
- }
-
- *do_update = true;
- *progress = (float)(framenr - tmj->sfra) / (tmj->efra - tmj->sfra);
-
- if (tmj->backwards) {
- framenr--;
- }
- else {
- framenr++;
- }
-
- tmj->lastfra = framenr;
-
- if (*stop || track_markers_testbreak()) {
- break;
- }
- }
+ TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
+ int framenr = tmj->sfra;
+
+ while (framenr != tmj->efra) {
+ if (tmj->delay > 0) {
+ /* Tracking should happen with fixed fps. Calculate time
+ * using current timer value before tracking frame and after.
+ *
+ * Small (and maybe unneeded optimization): do not calculate
+ * exec_time for "Fastest" tracking
+ */
+
+ double start_time = PIL_check_seconds_timer(), exec_time;
+
+ if (!BKE_autotrack_context_step(tmj->context)) {
+ break;
+ }
+
+ exec_time = PIL_check_seconds_timer() - start_time;
+ if (tmj->delay > (float)exec_time) {
+ PIL_sleep_ms(tmj->delay - (float)exec_time);
+ }
+ }
+ else if (!BKE_autotrack_context_step(tmj->context)) {
+ break;
+ }
+
+ *do_update = true;
+ *progress = (float)(framenr - tmj->sfra) / (tmj->efra - tmj->sfra);
+
+ if (tmj->backwards) {
+ framenr--;
+ }
+ else {
+ framenr++;
+ }
+
+ tmj->lastfra = framenr;
+
+ if (*stop || track_markers_testbreak()) {
+ break;
+ }
+ }
}
static void track_markers_updatejob(void *tmv)
{
- TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
- BKE_autotrack_context_sync(tmj->context);
+ TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
+ BKE_autotrack_context_sync(tmj->context);
}
static void track_markers_endjob(void *tmv)
{
- TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
- wmWindowManager *wm = tmj->main->wm.first;
+ TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
+ wmWindowManager *wm = tmj->main->wm.first;
- tmj->clip->tracking_context = NULL;
- tmj->scene->r.cfra = BKE_movieclip_remap_clip_to_scene_frame(tmj->clip,
- tmj->lastfra);
- if (wm != NULL) {
- // XXX: ...
- // ED_update_for_newframe(tmj->main, tmj->scene);
- }
+ tmj->clip->tracking_context = NULL;
+ tmj->scene->r.cfra = BKE_movieclip_remap_clip_to_scene_frame(tmj->clip, tmj->lastfra);
+ if (wm != NULL) {
+ // XXX: ...
+ // ED_update_for_newframe(tmj->main, tmj->scene);
+ }
- BKE_autotrack_context_sync(tmj->context);
- BKE_autotrack_context_finish(tmj->context);
+ BKE_autotrack_context_sync(tmj->context);
+ BKE_autotrack_context_finish(tmj->context);
- WM_main_add_notifier(NC_SCENE | ND_FRAME, tmj->scene);
+ WM_main_add_notifier(NC_SCENE | ND_FRAME, tmj->scene);
}
static void track_markers_freejob(void *tmv)
{
- TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
- tmj->clip->tracking_context = NULL;
- BKE_autotrack_context_free(tmj->context);
- MEM_freeN(tmj);
+ TrackMarkersJob *tmj = (TrackMarkersJob *)tmv;
+ tmj->clip->tracking_context = NULL;
+ BKE_autotrack_context_free(tmj->context);
+ MEM_freeN(tmj);
}
static int track_markers(bContext *C, wmOperator *op, bool use_job)
{
- TrackMarkersJob *tmj;
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- wmJob *wm_job;
- bool backwards = RNA_boolean_get(op->ptr, "backwards");
- bool sequence = RNA_boolean_get(op->ptr, "sequence");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- if (WM_jobs_test(CTX_wm_manager(C), sa, WM_JOB_TYPE_ANY)) {
- /* Only one tracking is allowed at a time. */
- return OPERATOR_CANCELLED;
- }
-
- if (clip->tracking_context) {
- return OPERATOR_CANCELLED;
- }
-
- if (track_count_markers(sc, clip, framenr) == 0) {
- return OPERATOR_CANCELLED;
- }
-
- tmj = MEM_callocN(sizeof(TrackMarkersJob), "TrackMarkersJob data");
- if (!track_markers_initjob(C, tmj, backwards, sequence)) {
- track_markers_freejob(tmj);
- return OPERATOR_CANCELLED;
- }
-
- /* Setup job. */
- if (use_job && sequence) {
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa,
- "Track Markers",
- WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_TRACK_MARKERS);
- WM_jobs_customdata_set(wm_job, tmj, track_markers_freejob);
-
- /* If there's delay set in tracking job, tracking should happen
- * with fixed FPS. To deal with editor refresh we have to synchronize
- * tracks from job and tracks in clip. Do this in timer callback
- * to prevent threading conflicts. */
- if (tmj->delay > 0) {
- WM_jobs_timer(wm_job,
- tmj->delay / 1000.0f, NC_MOVIECLIP | NA_EVALUATED, 0);
- }
- else {
- WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | NA_EVALUATED, 0);
- }
-
- WM_jobs_callbacks(wm_job,
- track_markers_startjob,
- NULL,
- track_markers_updatejob,
- track_markers_endjob);
-
- G.is_break = false;
-
- WM_jobs_start(CTX_wm_manager(C), wm_job);
- WM_cursor_wait(0);
-
- /* Add modal handler for ESC. */
- WM_event_add_modal_handler(C, op);
-
- return OPERATOR_RUNNING_MODAL;
- }
- else {
- short stop = 0, do_update = 0;
- float progress = 0.0f;
- track_markers_startjob(tmj, &stop, &do_update, &progress);
- track_markers_endjob(tmj);
- track_markers_freejob(tmj);
- return OPERATOR_FINISHED;
- }
+ TrackMarkersJob *tmj;
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ wmJob *wm_job;
+ bool backwards = RNA_boolean_get(op->ptr, "backwards");
+ bool sequence = RNA_boolean_get(op->ptr, "sequence");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ if (WM_jobs_test(CTX_wm_manager(C), sa, WM_JOB_TYPE_ANY)) {
+ /* Only one tracking is allowed at a time. */
+ return OPERATOR_CANCELLED;
+ }
+
+ if (clip->tracking_context) {
+ return OPERATOR_CANCELLED;
+ }
+
+ if (track_count_markers(sc, clip, framenr) == 0) {
+ return OPERATOR_CANCELLED;
+ }
+
+ tmj = MEM_callocN(sizeof(TrackMarkersJob), "TrackMarkersJob data");
+ if (!track_markers_initjob(C, tmj, backwards, sequence)) {
+ track_markers_freejob(tmj);
+ return OPERATOR_CANCELLED;
+ }
+
+ /* Setup job. */
+ if (use_job && sequence) {
+ wm_job = WM_jobs_get(CTX_wm_manager(C),
+ CTX_wm_window(C),
+ sa,
+ "Track Markers",
+ WM_JOB_PROGRESS,
+ WM_JOB_TYPE_CLIP_TRACK_MARKERS);
+ WM_jobs_customdata_set(wm_job, tmj, track_markers_freejob);
+
+ /* If there's delay set in tracking job, tracking should happen
+ * with fixed FPS. To deal with editor refresh we have to synchronize
+ * tracks from job and tracks in clip. Do this in timer callback
+ * to prevent threading conflicts. */
+ if (tmj->delay > 0) {
+ WM_jobs_timer(wm_job, tmj->delay / 1000.0f, NC_MOVIECLIP | NA_EVALUATED, 0);
+ }
+ else {
+ WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | NA_EVALUATED, 0);
+ }
+
+ WM_jobs_callbacks(
+ wm_job, track_markers_startjob, NULL, track_markers_updatejob, track_markers_endjob);
+
+ G.is_break = false;
+
+ WM_jobs_start(CTX_wm_manager(C), wm_job);
+ WM_cursor_wait(0);
+
+ /* Add modal handler for ESC. */
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+ }
+ else {
+ short stop = 0, do_update = 0;
+ float progress = 0.0f;
+ track_markers_startjob(tmj, &stop, &do_update, &progress);
+ track_markers_endjob(tmj);
+ track_markers_freejob(tmj);
+ return OPERATOR_FINISHED;
+ }
}
static int track_markers_exec(bContext *C, wmOperator *op)
{
- return track_markers(C, op, false);
+ return track_markers(C, op, false);
}
-static int track_markers_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int track_markers_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- return track_markers(C, op, true);
+ return track_markers(C, op, true);
}
-static int track_markers_modal(bContext *C,
- wmOperator *UNUSED(op),
- const wmEvent *event)
+static int track_markers_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- /* No running tracking, remove handler and pass through. */
- if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY)) {
- return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
- }
-
- /* Running tracking. */
- switch (event->type) {
- case ESCKEY:
- return OPERATOR_RUNNING_MODAL;
- }
-
- return OPERATOR_PASS_THROUGH;
+ /* No running tracking, remove handler and pass through. */
+ if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY)) {
+ return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+ }
+
+ /* Running tracking. */
+ switch (event->type) {
+ case ESCKEY:
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ return OPERATOR_PASS_THROUGH;
}
void CLIP_OT_track_markers(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Track Markers";
- ot->description = "Track selected markers";
- ot->idname = "CLIP_OT_track_markers";
-
- /* api callbacks */
- ot->exec = track_markers_exec;
- ot->invoke = track_markers_invoke;
- ot->modal = track_markers_modal;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean(ot->srna, "backwards", 0, "Backwards",
- "Do backwards tracking");
- RNA_def_boolean(ot->srna, "sequence", 0, "Track Sequence",
- "Track marker during image sequence rather than "
- "single image");
+ /* identifiers */
+ ot->name = "Track Markers";
+ ot->description = "Track selected markers";
+ ot->idname = "CLIP_OT_track_markers";
+
+ /* api callbacks */
+ ot->exec = track_markers_exec;
+ ot->invoke = track_markers_invoke;
+ ot->modal = track_markers_modal;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "backwards", 0, "Backwards", "Do backwards tracking");
+ RNA_def_boolean(ot->srna,
+ "sequence",
+ 0,
+ "Track Sequence",
+ "Track marker during image sequence rather than "
+ "single image");
}
/********************** Refine track position operator *********************/
static int refine_marker_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- bool backwards = RNA_boolean_get(op->ptr, "backwards");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if (TRACK_VIEW_SELECTED(sc, track)) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track,
- framenr);
- BKE_tracking_refine_marker(clip, track, marker, backwards);
- }
- }
-
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ bool backwards = RNA_boolean_get(op->ptr, "backwards");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if (TRACK_VIEW_SELECTED(sc, track)) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ BKE_tracking_refine_marker(clip, track, marker, backwards);
+ }
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_refine_markers(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Refine Markers";
- ot->description = "Refine selected markers positions "
- "by running the tracker from track's reference "
- "to current frame";
- ot->idname = "CLIP_OT_refine_markers";
-
- /* api callbacks */
- ot->exec = refine_marker_exec;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean(ot->srna, "backwards", 0, "Backwards",
- "Do backwards tracking");
+ /* identifiers */
+ ot->name = "Refine Markers";
+ ot->description =
+ "Refine selected markers positions "
+ "by running the tracker from track's reference "
+ "to current frame";
+ ot->idname = "CLIP_OT_refine_markers";
+
+ /* api callbacks */
+ ot->exec = refine_marker_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "backwards", 0, "Backwards", "Do backwards tracking");
}
diff --git a/source/blender/editors/space_clip/tracking_ops_utils.c b/source/blender/editors/space_clip/tracking_ops_utils.c
index 8974f6f7ee0..3970f1381bf 100644
--- a/source/blender/editors/space_clip/tracking_ops_utils.c
+++ b/source/blender/editors/space_clip/tracking_ops_utils.c
@@ -33,39 +33,35 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "tracking_ops_intern.h" // own include
+#include "tracking_ops_intern.h" // own include
-void clip_tracking_clear_invisible_track_selection(SpaceClip *sc,
- MovieClip *clip)
+void clip_tracking_clear_invisible_track_selection(SpaceClip *sc, MovieClip *clip)
{
- ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
- int hidden = 0;
- if ((sc->flag & SC_SHOW_MARKER_PATTERN) == 0) {
- hidden |= TRACK_AREA_PAT;
- }
- if ((sc->flag & SC_SHOW_MARKER_SEARCH) == 0) {
- hidden |= TRACK_AREA_SEARCH;
- }
- if (hidden) {
- for (MovieTrackingTrack *track = tracksbase->first;
- track != NULL;
- track = track->next)
- {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- BKE_tracking_track_flag_clear(track, hidden, SELECT);
- }
- }
- }
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int hidden = 0;
+ if ((sc->flag & SC_SHOW_MARKER_PATTERN) == 0) {
+ hidden |= TRACK_AREA_PAT;
+ }
+ if ((sc->flag & SC_SHOW_MARKER_SEARCH) == 0) {
+ hidden |= TRACK_AREA_SEARCH;
+ }
+ if (hidden) {
+ for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ BKE_tracking_track_flag_clear(track, hidden, SELECT);
+ }
+ }
+ }
}
void clip_tracking_hide_cursor(bContext *C)
{
- wmWindow *win = CTX_wm_window(C);
- WM_cursor_set(win, CURSOR_NONE);
+ wmWindow *win = CTX_wm_window(C);
+ WM_cursor_set(win, CURSOR_NONE);
}
void clip_tracking_show_cursor(bContext *C)
{
- wmWindow *win = CTX_wm_window(C);
- WM_cursor_set(win, CURSOR_STD);
+ wmWindow *win = CTX_wm_window(C);
+ WM_cursor_set(win, CURSOR_STD);
}
diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c
index 0c0fe60108f..24282ce0e96 100644
--- a/source/blender/editors/space_clip/tracking_select.c
+++ b/source/blender/editors/space_clip/tracking_select.c
@@ -48,887 +48,907 @@
#include "DEG_depsgraph.h"
-#include "tracking_ops_intern.h" /* own include */
-#include "clip_intern.h" /* own include */
+#include "tracking_ops_intern.h" /* own include */
+#include "clip_intern.h" /* own include */
static float dist_to_crns(float co[2], float pos[2], float crns[4][2]);
/********************** mouse select operator *********************/
-static int mouse_on_side(float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy)
+static int mouse_on_side(
+ float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy)
{
- if (x1 > x2)
- SWAP(float, x1, x2);
+ if (x1 > x2)
+ SWAP(float, x1, x2);
- if (y1 > y2)
- SWAP(float, y1, y2);
+ if (y1 > y2)
+ SWAP(float, y1, y2);
- return (co[0] >= x1 - epsx && co[0] <= x2 + epsx) && (co[1] >= y1 - epsy && co[1] <= y2 + epsy);
+ return (co[0] >= x1 - epsx && co[0] <= x2 + epsx) && (co[1] >= y1 - epsy && co[1] <= y2 + epsy);
}
-static int mouse_on_rect(float co[2], float pos[2], float min[2], float max[2], float epsx, float epsy)
+static int mouse_on_rect(
+ float co[2], float pos[2], float min[2], float max[2], float epsx, float epsy)
{
- return mouse_on_side(co, pos[0] + min[0], pos[1] + min[1], pos[0] + max[0], pos[1] + min[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + min[0], pos[1] + min[1], pos[0] + min[0], pos[1] + max[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + min[0], pos[1] + max[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + max[0], pos[1] + min[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy);
+ return mouse_on_side(
+ co, pos[0] + min[0], pos[1] + min[1], pos[0] + max[0], pos[1] + min[1], epsx, epsy) ||
+ mouse_on_side(
+ co, pos[0] + min[0], pos[1] + min[1], pos[0] + min[0], pos[1] + max[1], epsx, epsy) ||
+ mouse_on_side(
+ co, pos[0] + min[0], pos[1] + max[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy) ||
+ mouse_on_side(
+ co, pos[0] + max[0], pos[1] + min[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy);
}
static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx, float epsy)
{
- float dist = dist_to_crns(co, pos, crns);
+ float dist = dist_to_crns(co, pos, crns);
- return dist < max_ff(epsx, epsy);
+ return dist < max_ff(epsx, epsy);
}
static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack *track)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- int framenr = ED_space_clip_get_clip_frame_number(sc);
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
- float pat_min[2], pat_max[2];
- float epsx, epsy;
- int width, height;
-
- ED_space_clip_get_size(sc, &width, &height);
-
- BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
-
- epsx = min_ffff(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0],
- fabsf(pat_min[0]), fabsf(pat_max[0])) / 2;
- epsy = min_ffff(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1],
- fabsf(pat_min[1]), fabsf(pat_max[1])) / 2;
-
- epsx = max_ff(epsx, 2.0f / width);
- epsy = max_ff(epsy, 2.0f / height);
-
- if (sc->flag & SC_SHOW_MARKER_SEARCH) {
- if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy))
- return TRACK_AREA_SEARCH;
- }
-
- if ((marker->flag & MARKER_DISABLED) == 0) {
- if (sc->flag & SC_SHOW_MARKER_PATTERN)
- if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy))
- return TRACK_AREA_PAT;
-
- epsx = 12.0f / width;
- epsy = 12.0f / height;
-
- if (fabsf(co[0] - marker->pos[0] - track->offset[0]) < epsx &&
- fabsf(co[1] - marker->pos[1] - track->offset[1]) <= epsy)
- {
- return TRACK_AREA_POINT;
- }
- }
-
- return TRACK_AREA_NONE;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ float pat_min[2], pat_max[2];
+ float epsx, epsy;
+ int width, height;
+
+ ED_space_clip_get_size(sc, &width, &height);
+
+ BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+ epsx = min_ffff(pat_min[0] - marker->search_min[0],
+ marker->search_max[0] - pat_max[0],
+ fabsf(pat_min[0]),
+ fabsf(pat_max[0])) /
+ 2;
+ epsy = min_ffff(pat_min[1] - marker->search_min[1],
+ marker->search_max[1] - pat_max[1],
+ fabsf(pat_min[1]),
+ fabsf(pat_max[1])) /
+ 2;
+
+ epsx = max_ff(epsx, 2.0f / width);
+ epsy = max_ff(epsy, 2.0f / height);
+
+ if (sc->flag & SC_SHOW_MARKER_SEARCH) {
+ if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy))
+ return TRACK_AREA_SEARCH;
+ }
+
+ if ((marker->flag & MARKER_DISABLED) == 0) {
+ if (sc->flag & SC_SHOW_MARKER_PATTERN)
+ if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy))
+ return TRACK_AREA_PAT;
+
+ epsx = 12.0f / width;
+ epsy = 12.0f / height;
+
+ if (fabsf(co[0] - marker->pos[0] - track->offset[0]) < epsx &&
+ fabsf(co[1] - marker->pos[1] - track->offset[1]) <= epsy) {
+ return TRACK_AREA_POINT;
+ }
+ }
+
+ return TRACK_AREA_NONE;
}
static float dist_to_rect(float co[2], float pos[2], float min[2], float max[2])
{
- float d1, d2, d3, d4;
- float p[2] = {co[0] - pos[0], co[1] - pos[1]};
- float v1[2] = {min[0], min[1]}, v2[2] = {max[0], min[1]};
- float v3[2] = {max[0], max[1]}, v4[2] = {min[0], max[1]};
+ float d1, d2, d3, d4;
+ float p[2] = {co[0] - pos[0], co[1] - pos[1]};
+ float v1[2] = {min[0], min[1]}, v2[2] = {max[0], min[1]};
+ float v3[2] = {max[0], max[1]}, v4[2] = {min[0], max[1]};
- d1 = dist_squared_to_line_segment_v2(p, v1, v2);
- d2 = dist_squared_to_line_segment_v2(p, v2, v3);
- d3 = dist_squared_to_line_segment_v2(p, v3, v4);
- d4 = dist_squared_to_line_segment_v2(p, v4, v1);
+ d1 = dist_squared_to_line_segment_v2(p, v1, v2);
+ d2 = dist_squared_to_line_segment_v2(p, v2, v3);
+ d3 = dist_squared_to_line_segment_v2(p, v3, v4);
+ d4 = dist_squared_to_line_segment_v2(p, v4, v1);
- return sqrtf(min_ffff(d1, d2, d3, d4));
+ return sqrtf(min_ffff(d1, d2, d3, d4));
}
/* Distance to quad defined by it's corners, corners are relative to pos */
static float dist_to_crns(float co[2], float pos[2], float crns[4][2])
{
- float d1, d2, d3, d4;
- float p[2] = {co[0] - pos[0], co[1] - pos[1]};
- const float *v1 = crns[0], *v2 = crns[1];
- const float *v3 = crns[2], *v4 = crns[3];
+ float d1, d2, d3, d4;
+ float p[2] = {co[0] - pos[0], co[1] - pos[1]};
+ const float *v1 = crns[0], *v2 = crns[1];
+ const float *v3 = crns[2], *v4 = crns[3];
- d1 = dist_squared_to_line_segment_v2(p, v1, v2);
- d2 = dist_squared_to_line_segment_v2(p, v2, v3);
- d3 = dist_squared_to_line_segment_v2(p, v3, v4);
- d4 = dist_squared_to_line_segment_v2(p, v4, v1);
+ d1 = dist_squared_to_line_segment_v2(p, v1, v2);
+ d2 = dist_squared_to_line_segment_v2(p, v2, v3);
+ d3 = dist_squared_to_line_segment_v2(p, v3, v4);
+ d4 = dist_squared_to_line_segment_v2(p, v4, v1);
- return sqrtf(min_ffff(d1, d2, d3, d4));
+ return sqrtf(min_ffff(d1, d2, d3, d4));
}
/* Same as above, but all the coordinates are absolute */
static float dist_to_crns_abs(float co[2], float corners[4][2])
{
- float d1, d2, d3, d4;
- const float *v1 = corners[0], *v2 = corners[1];
- const float *v3 = corners[2], *v4 = corners[3];
+ float d1, d2, d3, d4;
+ const float *v1 = corners[0], *v2 = corners[1];
+ const float *v3 = corners[2], *v4 = corners[3];
- d1 = dist_squared_to_line_segment_v2(co, v1, v2);
- d2 = dist_squared_to_line_segment_v2(co, v2, v3);
- d3 = dist_squared_to_line_segment_v2(co, v3, v4);
- d4 = dist_squared_to_line_segment_v2(co, v4, v1);
+ d1 = dist_squared_to_line_segment_v2(co, v1, v2);
+ d2 = dist_squared_to_line_segment_v2(co, v2, v3);
+ d3 = dist_squared_to_line_segment_v2(co, v3, v4);
+ d4 = dist_squared_to_line_segment_v2(co, v4, v1);
- return sqrtf(min_ffff(d1, d2, d3, d4));
+ return sqrtf(min_ffff(d1, d2, d3, d4));
}
-static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2], float *distance_r)
+static MovieTrackingTrack *find_nearest_track(SpaceClip *sc,
+ ListBase *tracksbase,
+ float co[2],
+ float *distance_r)
{
- MovieTrackingTrack *track = NULL, *cur;
- float mindist = 0.0f;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
+ MovieTrackingTrack *track = NULL, *cur;
+ float mindist = 0.0f;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
- cur = tracksbase->first;
- while (cur) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(cur, framenr);
+ cur = tracksbase->first;
+ while (cur) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(cur, framenr);
- if (((cur->flag & TRACK_HIDDEN) == 0) && MARKER_VISIBLE(sc, cur, marker)) {
- float dist, d1, d2 = FLT_MAX, d3 = FLT_MAX;
+ if (((cur->flag & TRACK_HIDDEN) == 0) && MARKER_VISIBLE(sc, cur, marker)) {
+ float dist, d1, d2 = FLT_MAX, d3 = FLT_MAX;
- /* distance to marker point */
- d1 = sqrtf((co[0] - marker->pos[0] - cur->offset[0]) * (co[0] - marker->pos[0] - cur->offset[0]) +
- (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
+ /* distance to marker point */
+ d1 = sqrtf(
+ (co[0] - marker->pos[0] - cur->offset[0]) * (co[0] - marker->pos[0] - cur->offset[0]) +
+ (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
- /* distance to pattern boundbox */
- if (sc->flag & SC_SHOW_MARKER_PATTERN)
- d2 = dist_to_crns(co, marker->pos, marker->pattern_corners);
+ /* distance to pattern boundbox */
+ if (sc->flag & SC_SHOW_MARKER_PATTERN)
+ d2 = dist_to_crns(co, marker->pos, marker->pattern_corners);
- /* distance to search boundbox */
- if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur))
- d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max);
+ /* distance to search boundbox */
+ if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur))
+ d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max);
- /* choose minimal distance. useful for cases of overlapped markers. */
- dist = min_fff(d1, d2, d3);
+ /* choose minimal distance. useful for cases of overlapped markers. */
+ dist = min_fff(d1, d2, d3);
- if (track == NULL || dist < mindist) {
- track = cur;
- mindist = dist;
- }
- }
+ if (track == NULL || dist < mindist) {
+ track = cur;
+ mindist = dist;
+ }
+ }
- cur = cur->next;
- }
+ cur = cur->next;
+ }
- *distance_r = mindist;
+ *distance_r = mindist;
- return track;
+ return track;
}
-static MovieTrackingPlaneTrack *find_nearest_plane_track(SpaceClip *sc, ListBase *plane_tracks_base,
- float co[2], float *distance_r)
+static MovieTrackingPlaneTrack *find_nearest_plane_track(SpaceClip *sc,
+ ListBase *plane_tracks_base,
+ float co[2],
+ float *distance_r)
{
- MovieTrackingPlaneTrack *plane_track = NULL, *current_plane_track;
- float min_distance = 0.0f;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- for (current_plane_track = plane_tracks_base->first;
- current_plane_track;
- current_plane_track = current_plane_track->next)
- {
- MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(current_plane_track, framenr);
-
- if ((current_plane_track->flag & TRACK_HIDDEN) == 0) {
- float distance = dist_to_crns_abs(co, plane_marker->corners);
- if (plane_track == NULL || distance < min_distance) {
- plane_track = current_plane_track;
- min_distance = distance;
- }
- }
- }
-
- *distance_r = min_distance;
-
- return plane_track;
+ MovieTrackingPlaneTrack *plane_track = NULL, *current_plane_track;
+ float min_distance = 0.0f;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ for (current_plane_track = plane_tracks_base->first; current_plane_track;
+ current_plane_track = current_plane_track->next) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(current_plane_track,
+ framenr);
+
+ if ((current_plane_track->flag & TRACK_HIDDEN) == 0) {
+ float distance = dist_to_crns_abs(co, plane_marker->corners);
+ if (plane_track == NULL || distance < min_distance) {
+ plane_track = current_plane_track;
+ min_distance = distance;
+ }
+ }
+ }
+
+ *distance_r = min_distance;
+
+ return plane_track;
}
void ed_tracking_delect_all_tracks(ListBase *tracks_base)
{
- MovieTrackingTrack *track;
- for (track = tracks_base->first;
- track != NULL;
- track = track->next)
- {
- BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
- }
+ MovieTrackingTrack *track;
+ for (track = tracks_base->first; track != NULL; track = track->next) {
+ BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
+ }
}
void ed_tracking_delect_all_plane_tracks(ListBase *plane_tracks_base)
{
- MovieTrackingPlaneTrack *plane_track;
- for (plane_track = plane_tracks_base->first;
- plane_track != NULL;
- plane_track = plane_track->next)
- {
- plane_track->flag &= ~SELECT;
- }
+ MovieTrackingPlaneTrack *plane_track;
+ for (plane_track = plane_tracks_base->first; plane_track != NULL;
+ plane_track = plane_track->next) {
+ plane_track->flag &= ~SELECT;
+ }
}
static int mouse_select(bContext *C, float co[2], int extend)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- MovieTrackingTrack *track;
- MovieTrackingPlaneTrack *plane_track;
- float distance_to_track, distance_to_plane_track;
-
- track = find_nearest_track(sc, tracksbase, co, &distance_to_track);
- plane_track = find_nearest_plane_track(sc, plane_tracks_base, co, &distance_to_plane_track);
-
- /* Between track and plane we choose closest to the mouse for selection here. */
- if (track && plane_track) {
- if (distance_to_track < distance_to_plane_track) {
- plane_track = NULL;
- }
- else {
- track = NULL;
- }
- }
-
- if (!extend) {
- ed_tracking_delect_all_plane_tracks(plane_tracks_base);
- }
-
- if (track) {
- int area = track_mouse_area(C, co, track);
-
- if (!extend || !TRACK_VIEW_SELECTED(sc, track))
- area = TRACK_AREA_ALL;
-
- if (extend && TRACK_AREA_SELECTED(track, area)) {
- if (track == act_track) {
- BKE_tracking_track_deselect(track, area);
- }
- else {
- clip->tracking.act_track = track;
- clip->tracking.act_plane_track = NULL;
- }
- }
- else {
- if (area == TRACK_AREA_POINT)
- area = TRACK_AREA_ALL;
-
- BKE_tracking_track_select(tracksbase, track, area, extend);
- clip->tracking.act_track = track;
- clip->tracking.act_plane_track = NULL;
- }
- }
- else if (plane_track) {
- if (!extend) {
- ed_tracking_delect_all_tracks(tracksbase);
- }
-
- if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- if (extend) {
- plane_track->flag &= ~SELECT;
- }
- }
- else {
- plane_track->flag |= SELECT;
- }
-
- clip->tracking.act_track = NULL;
- clip->tracking.act_plane_track = plane_track;
- }
-
- if (!extend) {
- sc->xlockof = 0.0f;
- sc->ylockof = 0.0f;
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+ MovieTrackingTrack *track;
+ MovieTrackingPlaneTrack *plane_track;
+ float distance_to_track, distance_to_plane_track;
+
+ track = find_nearest_track(sc, tracksbase, co, &distance_to_track);
+ plane_track = find_nearest_plane_track(sc, plane_tracks_base, co, &distance_to_plane_track);
+
+ /* Between track and plane we choose closest to the mouse for selection here. */
+ if (track && plane_track) {
+ if (distance_to_track < distance_to_plane_track) {
+ plane_track = NULL;
+ }
+ else {
+ track = NULL;
+ }
+ }
+
+ if (!extend) {
+ ed_tracking_delect_all_plane_tracks(plane_tracks_base);
+ }
+
+ if (track) {
+ int area = track_mouse_area(C, co, track);
+
+ if (!extend || !TRACK_VIEW_SELECTED(sc, track))
+ area = TRACK_AREA_ALL;
+
+ if (extend && TRACK_AREA_SELECTED(track, area)) {
+ if (track == act_track) {
+ BKE_tracking_track_deselect(track, area);
+ }
+ else {
+ clip->tracking.act_track = track;
+ clip->tracking.act_plane_track = NULL;
+ }
+ }
+ else {
+ if (area == TRACK_AREA_POINT)
+ area = TRACK_AREA_ALL;
+
+ BKE_tracking_track_select(tracksbase, track, area, extend);
+ clip->tracking.act_track = track;
+ clip->tracking.act_plane_track = NULL;
+ }
+ }
+ else if (plane_track) {
+ if (!extend) {
+ ed_tracking_delect_all_tracks(tracksbase);
+ }
+
+ if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
+ if (extend) {
+ plane_track->flag &= ~SELECT;
+ }
+ }
+ else {
+ plane_track->flag |= SELECT;
+ }
+
+ clip->tracking.act_track = NULL;
+ clip->tracking.act_plane_track = plane_track;
+ }
+
+ if (!extend) {
+ sc->xlockof = 0.0f;
+ sc->ylockof = 0.0f;
+ }
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+
+ return OPERATOR_FINISHED;
}
static bool select_poll(bContext *C)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
- if (sc) {
- return sc->clip && sc->view == SC_VIEW_CLIP;
- }
+ if (sc) {
+ return sc->clip && sc->view == SC_VIEW_CLIP;
+ }
- return false;
+ return false;
}
static int select_exec(bContext *C, wmOperator *op)
{
- float co[2];
- int extend;
+ float co[2];
+ int extend;
- RNA_float_get_array(op->ptr, "location", co);
- extend = RNA_boolean_get(op->ptr, "extend");
+ RNA_float_get_array(op->ptr, "location", co);
+ extend = RNA_boolean_get(op->ptr, "extend");
- return mouse_select(C, co, extend);
+ return mouse_select(C, co, extend);
}
static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
- float co[2];
- const bool extend = RNA_boolean_get(op->ptr, "extend");
+ float co[2];
+ const bool extend = RNA_boolean_get(op->ptr, "extend");
- if (!extend) {
- MovieTrackingTrack *track = tracking_marker_check_slide(C, event, NULL, NULL, NULL);
+ if (!extend) {
+ MovieTrackingTrack *track = tracking_marker_check_slide(C, event, NULL, NULL, NULL);
- if (track) {
- MovieClip *clip = ED_space_clip_get_clip(sc);
+ if (track) {
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- clip->tracking.act_track = track;
+ clip->tracking.act_track = track;
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
- return OPERATOR_PASS_THROUGH;
- }
- }
+ return OPERATOR_PASS_THROUGH;
+ }
+ }
- ED_clip_mouse_pos(sc, ar, event->mval, co);
- RNA_float_set_array(op->ptr, "location", co);
+ ED_clip_mouse_pos(sc, ar, event->mval, co);
+ RNA_float_set_array(op->ptr, "location", co);
- return select_exec(C, op);
+ return select_exec(C, op);
}
void CLIP_OT_select(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select";
- ot->description = "Select tracking markers";
- ot->idname = "CLIP_OT_select";
-
- /* api callbacks */
- ot->exec = select_exec;
- ot->invoke = select_invoke;
- ot->poll = select_poll;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean(ot->srna, "extend", 0,
- "Extend", "Extend selection rather than clearing the existing selection");
- RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f);
+ /* identifiers */
+ ot->name = "Select";
+ ot->description = "Select tracking markers";
+ ot->idname = "CLIP_OT_select";
+
+ /* api callbacks */
+ ot->exec = select_exec;
+ ot->invoke = select_invoke;
+ ot->poll = select_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
+ RNA_def_float_vector(
+ ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
+ -100.0f,
+ 100.0f);
}
/********************** box select operator *********************/
static int box_select_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
-
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *track;
- MovieTrackingPlaneTrack *plane_track;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- rcti rect;
- rctf rectf;
- bool changed = false;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- /* get rectangle from operator */
- WM_operator_properties_border_to_rcti(op, &rect);
-
- ED_clip_point_stable_pos(sc, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
- ED_clip_point_stable_pos(sc, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
-
- const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
- const bool select = (sel_op != SEL_OP_SUB);
- if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- ED_clip_select_all(sc, SEL_DESELECT, NULL);
- changed = true;
- }
-
- /* do actual selection */
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- if (BLI_rctf_isect_pt_v(&rectf, marker->pos)) {
- if (select) {
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- }
- else {
- BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
- }
- }
- changed = true;
- }
- }
-
- track = track->next;
- }
-
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get(plane_track, framenr);
- int i;
-
- for (i = 0; i < 4; i++) {
- if (BLI_rctf_isect_pt_v(&rectf, plane_marker->corners[i])) {
- if (select) {
- plane_track->flag |= SELECT;
- }
- else {
- plane_track->flag &= ~SELECT;
- }
- }
- }
- changed = true;
- }
- }
-
- if (changed) {
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
-
- return OPERATOR_FINISHED;
- }
-
- return OPERATOR_CANCELLED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *track;
+ MovieTrackingPlaneTrack *plane_track;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ rcti rect;
+ rctf rectf;
+ bool changed = false;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ /* get rectangle from operator */
+ WM_operator_properties_border_to_rcti(op, &rect);
+
+ ED_clip_point_stable_pos(sc, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
+ ED_clip_point_stable_pos(sc, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
+
+ const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ const bool select = (sel_op != SEL_OP_SUB);
+ if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
+ ED_clip_select_all(sc, SEL_DESELECT, NULL);
+ changed = true;
+ }
+
+ /* do actual selection */
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ if (BLI_rctf_isect_pt_v(&rectf, marker->pos)) {
+ if (select) {
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ }
+ else {
+ BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
+ }
+ }
+ changed = true;
+ }
+ }
+
+ track = track->next;
+ }
+
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ if (BLI_rctf_isect_pt_v(&rectf, plane_marker->corners[i])) {
+ if (select) {
+ plane_track->flag |= SELECT;
+ }
+ else {
+ plane_track->flag &= ~SELECT;
+ }
+ }
+ }
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
}
void CLIP_OT_select_box(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Box Select";
- ot->description = "Select markers using box selection";
- ot->idname = "CLIP_OT_select_box";
-
- /* api callbacks */
- ot->invoke = WM_gesture_box_invoke;
- ot->exec = box_select_exec;
- ot->modal = WM_gesture_box_modal;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_gesture_box(ot);
- WM_operator_properties_select_operation_simple(ot);
+ /* identifiers */
+ ot->name = "Box Select";
+ ot->description = "Select markers using box selection";
+ ot->idname = "CLIP_OT_select_box";
+
+ /* api callbacks */
+ ot->invoke = WM_gesture_box_invoke;
+ ot->exec = box_select_exec;
+ ot->modal = WM_gesture_box_modal;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_gesture_box(ot);
+ WM_operator_properties_select_operation_simple(ot);
}
/********************** lasso select operator *********************/
-static int do_lasso_select_marker(bContext *C, const int mcords[][2], const short moves, bool select)
+static int do_lasso_select_marker(bContext *C,
+ const int mcords[][2],
+ const short moves,
+ bool select)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
-
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *track;
- MovieTrackingPlaneTrack *plane_track;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- rcti rect;
- bool changed = false;
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- /* get rectangle from operator */
- BLI_lasso_boundbox(&rect, mcords, moves);
-
- /* do actual selection */
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker)) {
- float screen_co[2];
-
- /* marker in screen coords */
- ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co);
-
- if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
- BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED))
- {
- if (select)
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- else
- BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
- }
-
- changed = true;
- }
- }
-
- track = track->next;
- }
-
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get(plane_track, framenr);
- int i;
-
- for (i = 0; i < 4; i++) {
- float screen_co[2];
-
- /* marker in screen coords */
- ED_clip_point_stable_pos__reverse(sc, ar, plane_marker->corners[i], screen_co);
-
- if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
- BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED))
- {
- if (select) {
- plane_track->flag |= SELECT;
- }
- else {
- plane_track->flag &= ~SELECT;
- }
- }
- }
-
- changed = true;
- }
- }
-
- if (changed) {
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
- }
-
- return changed;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *track;
+ MovieTrackingPlaneTrack *plane_track;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ rcti rect;
+ bool changed = false;
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ /* get rectangle from operator */
+ BLI_lasso_boundbox(&rect, mcords, moves);
+
+ /* do actual selection */
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker)) {
+ float screen_co[2];
+
+ /* marker in screen coords */
+ ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co);
+
+ if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
+ BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) {
+ if (select)
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ else
+ BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
+ }
+
+ changed = true;
+ }
+ }
+
+ track = track->next;
+ }
+
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ float screen_co[2];
+
+ /* marker in screen coords */
+ ED_clip_point_stable_pos__reverse(sc, ar, plane_marker->corners[i], screen_co);
+
+ if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
+ BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) {
+ if (select) {
+ plane_track->flag |= SELECT;
+ }
+ else {
+ plane_track->flag &= ~SELECT;
+ }
+ }
+ }
+
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+ }
+
+ return changed;
}
static int clip_lasso_select_exec(bContext *C, wmOperator *op)
{
- int mcords_tot;
- const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot);
+ int mcords_tot;
+ const int(*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot);
+ if (mcords) {
+ const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ const bool select = (sel_op != SEL_OP_SUB);
+ if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ED_clip_select_all(sc, SEL_DESELECT, NULL);
+ }
- if (mcords) {
- const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
- const bool select = (sel_op != SEL_OP_SUB);
- if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- SpaceClip *sc = CTX_wm_space_clip(C);
- ED_clip_select_all(sc, SEL_DESELECT, NULL);
- }
+ do_lasso_select_marker(C, mcords, mcords_tot, select);
- do_lasso_select_marker(C, mcords, mcords_tot, select);
+ MEM_freeN((void *)mcords);
- MEM_freeN((void *)mcords);
-
- return OPERATOR_FINISHED;
- }
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_FINISHED;
+ }
+ return OPERATOR_PASS_THROUGH;
}
void CLIP_OT_select_lasso(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Lasso Select";
- ot->description = "Select markers using lasso selection";
- ot->idname = "CLIP_OT_select_lasso";
-
- /* api callbacks */
- ot->invoke = WM_gesture_lasso_invoke;
- ot->modal = WM_gesture_lasso_modal;
- ot->exec = clip_lasso_select_exec;
- ot->poll = ED_space_clip_tracking_poll;
- ot->cancel = WM_gesture_lasso_cancel;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_gesture_lasso(ot);
- WM_operator_properties_select_operation_simple(ot);
+ /* identifiers */
+ ot->name = "Lasso Select";
+ ot->description = "Select markers using lasso selection";
+ ot->idname = "CLIP_OT_select_lasso";
+
+ /* api callbacks */
+ ot->invoke = WM_gesture_lasso_invoke;
+ ot->modal = WM_gesture_lasso_modal;
+ ot->exec = clip_lasso_select_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+ ot->cancel = WM_gesture_lasso_cancel;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_gesture_lasso(ot);
+ WM_operator_properties_select_operation_simple(ot);
}
/********************** circle select operator *********************/
static int point_inside_ellipse(float point[2], float offset[2], float ellipse[2])
{
- /* normalized ellipse: ell[0] = scaleX, ell[1] = scaleY */
- float x, y;
+ /* normalized ellipse: ell[0] = scaleX, ell[1] = scaleY */
+ float x, y;
- x = (point[0] - offset[0]) * ellipse[0];
- y = (point[1] - offset[1]) * ellipse[1];
+ x = (point[0] - offset[0]) * ellipse[0];
+ y = (point[1] - offset[1]) * ellipse[1];
- return x * x + y * y < 1.0f;
+ return x * x + y * y < 1.0f;
}
static int marker_inside_ellipse(MovieTrackingMarker *marker, float offset[2], float ellipse[2])
{
- return point_inside_ellipse(marker->pos, offset, ellipse);
+ return point_inside_ellipse(marker->pos, offset, ellipse);
}
static int circle_select_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- ARegion *ar = CTX_wm_region(C);
-
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *track;
- MovieTrackingPlaneTrack *plane_track;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
- int width, height;
- bool changed = false;
- float zoomx, zoomy, offset[2], ellipse[2];
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- /* get operator properties */
- const int x = RNA_int_get(op->ptr, "x");
- const int y = RNA_int_get(op->ptr, "y");
- const int radius = RNA_int_get(op->ptr, "radius");
-
- const eSelectOp sel_op = ED_select_op_modal(
- RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
- const bool select = (sel_op != SEL_OP_SUB);
- if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- ED_clip_select_all(sc, SEL_DESELECT, NULL);
- changed = true;
- }
-
- /* compute ellipse and position in unified coordinates */
- ED_space_clip_get_size(sc, &width, &height);
- ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
-
- ellipse[0] = width * zoomx / radius;
- ellipse[1] = height * zoomy / radius;
-
- ED_clip_point_stable_pos(sc, ar, x, y, &offset[0], &offset[1]);
-
- /* do selection */
- track = tracksbase->first;
- while (track) {
- if ((track->flag & TRACK_HIDDEN) == 0) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
-
- if (MARKER_VISIBLE(sc, track, marker) && marker_inside_ellipse(marker, offset, ellipse)) {
- if (select) {
- BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
- }
- else {
- BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
- }
- changed = true;
- }
- }
-
- track = track->next;
- }
-
- for (plane_track = plane_tracks_base->first;
- plane_track;
- plane_track = plane_track->next)
- {
- if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
- MovieTrackingPlaneMarker *plane_marker =
- BKE_tracking_plane_marker_get(plane_track, framenr);
- int i;
-
- for (i = 0; i < 4; i++) {
- if (point_inside_ellipse(plane_marker->corners[i], offset, ellipse)) {
- if (select) {
- plane_track->flag |= SELECT;
- }
- else {
- plane_track->flag &= ~SELECT;
- }
- }
- }
-
- changed = true;
- }
- }
-
- if (changed) {
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
-
- return OPERATOR_FINISHED;
- }
-
- return OPERATOR_CANCELLED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingTrack *track;
+ MovieTrackingPlaneTrack *plane_track;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
+ int width, height;
+ bool changed = false;
+ float zoomx, zoomy, offset[2], ellipse[2];
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ /* get operator properties */
+ const int x = RNA_int_get(op->ptr, "x");
+ const int y = RNA_int_get(op->ptr, "y");
+ const int radius = RNA_int_get(op->ptr, "radius");
+
+ const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"),
+ WM_gesture_is_modal_first(op->customdata));
+ const bool select = (sel_op != SEL_OP_SUB);
+ if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
+ ED_clip_select_all(sc, SEL_DESELECT, NULL);
+ changed = true;
+ }
+
+ /* compute ellipse and position in unified coordinates */
+ ED_space_clip_get_size(sc, &width, &height);
+ ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+
+ ellipse[0] = width * zoomx / radius;
+ ellipse[1] = height * zoomy / radius;
+
+ ED_clip_point_stable_pos(sc, ar, x, y, &offset[0], &offset[1]);
+
+ /* do selection */
+ track = tracksbase->first;
+ while (track) {
+ if ((track->flag & TRACK_HIDDEN) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+
+ if (MARKER_VISIBLE(sc, track, marker) && marker_inside_ellipse(marker, offset, ellipse)) {
+ if (select) {
+ BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
+ }
+ else {
+ BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
+ }
+ changed = true;
+ }
+ }
+
+ track = track->next;
+ }
+
+ for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
+ if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
+ MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr);
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ if (point_inside_ellipse(plane_marker->corners[i], offset, ellipse)) {
+ if (select) {
+ plane_track->flag |= SELECT;
+ }
+ else {
+ plane_track->flag &= ~SELECT;
+ }
+ }
+ }
+
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
}
void CLIP_OT_select_circle(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Circle Select";
- ot->description = "Select markers using circle selection";
- ot->idname = "CLIP_OT_select_circle";
-
- /* api callbacks */
- ot->invoke = WM_gesture_circle_invoke;
- ot->modal = WM_gesture_circle_modal;
- ot->exec = circle_select_exec;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_gesture_circle(ot);
- WM_operator_properties_select_operation_simple(ot);
+ /* identifiers */
+ ot->name = "Circle Select";
+ ot->description = "Select markers using circle selection";
+ ot->idname = "CLIP_OT_select_circle";
+
+ /* api callbacks */
+ ot->invoke = WM_gesture_circle_invoke;
+ ot->modal = WM_gesture_circle_modal;
+ ot->exec = circle_select_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_gesture_circle(ot);
+ WM_operator_properties_select_operation_simple(ot);
}
/********************** select all operator *********************/
static int select_all_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking = &clip->tracking;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTracking *tracking = &clip->tracking;
- int action = RNA_enum_get(op->ptr, "action");
+ int action = RNA_enum_get(op->ptr, "action");
- bool has_selection = false;
+ bool has_selection = false;
- ED_clip_select_all(sc, action, &has_selection);
+ ED_clip_select_all(sc, action, &has_selection);
- if (!has_selection)
- sc->flag &= ~SC_LOCK_SELECTION;
+ if (!has_selection)
+ sc->flag &= ~SC_LOCK_SELECTION;
- BKE_tracking_dopesheet_tag_update(tracking);
+ BKE_tracking_dopesheet_tag_update(tracking);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CLIP_OT_select_all(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "(De)select All";
- ot->description = "Change selection of all tracking markers";
- ot->idname = "CLIP_OT_select_all";
+ /* identifiers */
+ ot->name = "(De)select All";
+ ot->description = "Change selection of all tracking markers";
+ ot->idname = "CLIP_OT_select_all";
- /* api callbacks */
- ot->exec = select_all_exec;
- ot->poll = ED_space_clip_tracking_poll;
+ /* api callbacks */
+ ot->exec = select_all_exec;
+ ot->poll = ED_space_clip_tracking_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- WM_operator_properties_select_all(ot);
+ WM_operator_properties_select_all(ot);
}
/********************** select grouped operator *********************/
static int select_grouped_exec(bContext *C, wmOperator *op)
{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTrackingTrack *track;
- MovieTrackingMarker *marker;
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- int group = RNA_enum_get(op->ptr, "group");
- int framenr = ED_space_clip_get_clip_frame_number(sc);
-
- track = tracksbase->first;
- while (track) {
- bool ok = false;
-
- marker = BKE_tracking_marker_get(track, framenr);
-
- if (group == 0) { /* Keyframed */
- ok = marker->framenr == framenr && (marker->flag & MARKER_TRACKED) == 0;
- }
- else if (group == 1) { /* Estimated */
- ok = marker->framenr != framenr;
- }
- else if (group == 2) { /* tracked */
- ok = marker->framenr == framenr && (marker->flag & MARKER_TRACKED);
- }
- else if (group == 3) { /* locked */
- ok = track->flag & TRACK_LOCKED;
- }
- else if (group == 4) { /* disabled */
- ok = marker->flag & MARKER_DISABLED;
- }
- else if (group == 5) { /* color */
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
-
- if (act_track) {
- ok = (track->flag & TRACK_CUSTOMCOLOR) == (act_track->flag & TRACK_CUSTOMCOLOR);
-
- if (ok && track->flag & TRACK_CUSTOMCOLOR)
- ok = equals_v3v3(track->color, act_track->color);
- }
- }
- else if (group == 6) { /* failed */
- ok = (track->flag & TRACK_HAS_BUNDLE) == 0;
- }
-
- if (ok) {
- track->flag |= SELECT;
- if (sc->flag & SC_SHOW_MARKER_PATTERN)
- track->pat_flag |= SELECT;
- if (sc->flag & SC_SHOW_MARKER_SEARCH)
- track->search_flag |= SELECT;
- }
-
- track = track->next;
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
-
- WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
- DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
-
- return OPERATOR_FINISHED;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
+ MovieTracking *tracking = &clip->tracking;
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
+ int group = RNA_enum_get(op->ptr, "group");
+ int framenr = ED_space_clip_get_clip_frame_number(sc);
+
+ track = tracksbase->first;
+ while (track) {
+ bool ok = false;
+
+ marker = BKE_tracking_marker_get(track, framenr);
+
+ if (group == 0) { /* Keyframed */
+ ok = marker->framenr == framenr && (marker->flag & MARKER_TRACKED) == 0;
+ }
+ else if (group == 1) { /* Estimated */
+ ok = marker->framenr != framenr;
+ }
+ else if (group == 2) { /* tracked */
+ ok = marker->framenr == framenr && (marker->flag & MARKER_TRACKED);
+ }
+ else if (group == 3) { /* locked */
+ ok = track->flag & TRACK_LOCKED;
+ }
+ else if (group == 4) { /* disabled */
+ ok = marker->flag & MARKER_DISABLED;
+ }
+ else if (group == 5) { /* color */
+ MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
+
+ if (act_track) {
+ ok = (track->flag & TRACK_CUSTOMCOLOR) == (act_track->flag & TRACK_CUSTOMCOLOR);
+
+ if (ok && track->flag & TRACK_CUSTOMCOLOR)
+ ok = equals_v3v3(track->color, act_track->color);
+ }
+ }
+ else if (group == 6) { /* failed */
+ ok = (track->flag & TRACK_HAS_BUNDLE) == 0;
+ }
+
+ if (ok) {
+ track->flag |= SELECT;
+ if (sc->flag & SC_SHOW_MARKER_PATTERN)
+ track->pat_flag |= SELECT;
+ if (sc->flag & SC_SHOW_MARKER_SEARCH)
+ track->search_flag |= SELECT;
+ }
+
+ track = track->next;
+ }
+
+ BKE_tracking_dopesheet_tag_update(tracking);
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
+ DEG_id_tag_update(&clip->id, ID_RECALC_SELECT);
+
+ return OPERATOR_FINISHED;
}
void CLIP_OT_select_grouped(wmOperatorType *ot)
{
- static const EnumPropertyItem select_group_items[] = {
- {0, "KEYFRAMED", 0, "Keyframed tracks", "Select all keyframed tracks"},
- {1, "ESTIMATED", 0, "Estimated tracks", "Select all estimated tracks"},
- {2, "TRACKED", 0, "Tracked tracks", "Select all tracked tracks"},
- {3, "LOCKED", 0, "Locked tracks", "Select all locked tracks"},
- {4, "DISABLED", 0, "Disabled tracks", "Select all disabled tracks"},
- {5, "COLOR", 0, "Tracks with same color", "Select all tracks with same color as active track"},
- {6, "FAILED", 0, "Failed Tracks", "Select all tracks which failed to be reconstructed"},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Select Grouped";
- ot->description = "Select all tracks from specified group";
- ot->idname = "CLIP_OT_select_grouped";
-
- /* api callbacks */
- ot->exec = select_grouped_exec;
- ot->poll = ED_space_clip_tracking_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "group", select_group_items, TRACK_CLEAR_REMAINED, "Action", "Clear action to execute");
+ static const EnumPropertyItem select_group_items[] = {
+ {0, "KEYFRAMED", 0, "Keyframed tracks", "Select all keyframed tracks"},
+ {1, "ESTIMATED", 0, "Estimated tracks", "Select all estimated tracks"},
+ {2, "TRACKED", 0, "Tracked tracks", "Select all tracked tracks"},
+ {3, "LOCKED", 0, "Locked tracks", "Select all locked tracks"},
+ {4, "DISABLED", 0, "Disabled tracks", "Select all disabled tracks"},
+ {5,
+ "COLOR",
+ 0,
+ "Tracks with same color",
+ "Select all tracks with same color as active track"},
+ {6, "FAILED", 0, "Failed Tracks", "Select all tracks which failed to be reconstructed"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Select Grouped";
+ ot->description = "Select all tracks from specified group";
+ ot->idname = "CLIP_OT_select_grouped";
+
+ /* api callbacks */
+ ot->exec = select_grouped_exec;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_enum(ot->srna,
+ "group",
+ select_group_items,
+ TRACK_CLEAR_REMAINED,
+ "Action",
+ "Clear action to execute");
}