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:
authorTianwei Shen <shentianweipku@gmail.com>2016-07-20 14:31:41 +0300
committerTianwei Shen <shentianweipku@gmail.com>2016-07-20 14:31:41 +0300
commit45628cc8b6610d955ee453e3b9cfd2590737371a (patch)
tree9a01c64f5d20478a3c881c1d246060e26737a676 /source/blender/editors/space_clip
parentaaa745d3d5f60ff5c165324ea314b3ac68a9c361 (diff)
make a open secondary clip button
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r--source/blender/editors/space_clip/clip_buttons.c4
-rw-r--r--source/blender/editors/space_clip/clip_editor.c52
-rw-r--r--source/blender/editors/space_clip/clip_intern.h1
-rw-r--r--source/blender/editors/space_clip/clip_ops.c127
-rw-r--r--source/blender/editors/space_clip/space_clip.c5
5 files changed, 188 insertions, 1 deletions
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index 0378c68d12c..91f28f82ca0 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -105,8 +105,10 @@ void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const c
uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
- if (!compact)
+ if (!compact) {
uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
+ uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open_secondary", NULL);
+ }
if (clip) {
uiLayout *col;
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index e8cca390533..dbc4c2ef551 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -576,6 +576,11 @@ MovieClip *ED_space_clip_get_clip(SpaceClip *sc)
return sc->clip;
}
+MovieClip *ED_space_clip_get_secondary_clip(SpaceClip *sc)
+{
+ return sc->secondary_clip;
+}
+
void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
{
MovieClip *old_clip;
@@ -623,6 +628,53 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl
WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
}
+void ED_space_clip_set_secondary_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *secondary_clip)
+{
+ MovieClip *old_clip;
+ bool old_clip_visible = false;
+
+ if (!screen && C)
+ screen = CTX_wm_screen(C);
+
+ old_clip = sc->secondary_clip;
+ sc->secondary_clip = secondary_clip;
+
+ id_us_ensure_real((ID *)sc->secondary_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->secondary_clip == old_clip)
+ old_clip_visible = true;
+ }
+ else {
+ if (cur_sc->secondary_clip == old_clip || cur_sc->clip == NULL) {
+ cur_sc->secondary_clip = secondary_clip;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* If clip is no longer visible on screen, free memory used by it's cache */
+ if (old_clip && old_clip != secondary_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)
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 76383cb5584..69f39e17313 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -94,6 +94,7 @@ void CLIP_OT_graph_disable_markers(struct wmOperatorType *ot);
/* clip_ops.c */
void CLIP_OT_open(struct wmOperatorType *ot);
+void CLIP_OT_open_secondary(struct wmOperatorType *ot);
void CLIP_OT_reload(struct wmOperatorType *ot);
void CLIP_OT_view_pan(struct wmOperatorType *ot);
void CLIP_OT_view_zoom(wmOperatorType *ot);
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 17cd9bed5c9..a7ec84964b5 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -305,6 +305,133 @@ void CLIP_OT_open(wmOperatorType *ot)
WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
}
+/******************** open a secondary clip in Correspondence mode operator ********************/
+static int open_secondary_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];
+
+ 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, G.main->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);
+
+ 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;
+ }
+
+ /* default to frame 1 if there's no scene in context */
+
+ errno = 0;
+
+ clip = BKE_movieclip_file_add_exists(bmain, str);
+
+ 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"));
+
+ return OPERATOR_CANCELLED;
+ }
+
+ if (!op->customdata)
+ open_init(C, op);
+
+ /* hook into UI */
+ pprop = op->customdata;
+
+ if (pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se 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_secondary_clip(C, screen, sc, clip);
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
+
+ MEM_freeN(op->customdata);
+
+ return OPERATOR_FINISHED;
+}
+
+static int open_secondary_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ char path[FILE_MAX];
+ MovieClip *secondary_clip = NULL;
+
+ if (sc)
+ secondary_clip = ED_space_clip_get_secondary_clip(sc);
+
+ if (secondary_clip) {
+ BLI_strncpy(path, secondary_clip->name, sizeof(path));
+
+ BLI_path_abs(path, G.main->name);
+ BLI_parent_dir(path);
+ }
+ else {
+ BLI_strncpy(path, U.textudir, sizeof(path));
+ }
+
+ if (RNA_struct_property_is_set(op->ptr, "files"))
+ return open_secondary_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);
+
+ open_init(C, op);
+
+ clip_filesel(C, op, path);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void CLIP_OT_open_secondary(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Open Secondary Clip";
+ ot->description = "Load a sequence of frames or a movie file in correspondence mode";
+ ot->idname = "CLIP_OT_open_secondary";
+
+ /* api callbacks */
+ ot->exec = open_secondary_exec;
+ ot->invoke = open_secondary_invoke;
+ ot->cancel = open_cancel;
+
+ /* 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);
+}
/******************* reload clip operator *********************/
static int reload_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 508821a896d..18c6ef8203d 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -432,6 +432,7 @@ static void clip_operatortypes(void)
{
/* ** clip_ops.c ** */
WM_operatortype_append(CLIP_OT_open);
+ WM_operatortype_append(CLIP_OT_open_secondary);
WM_operatortype_append(CLIP_OT_reload);
WM_operatortype_append(CLIP_OT_view_pan);
WM_operatortype_append(CLIP_OT_view_zoom);
@@ -566,6 +567,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
keymap = WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0);
WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
+ //TODO(tianwei): think about a shortcut for open_secondary clip
+ //WM_keymap_add_item(keymap, "CLIP_OT_open_secondary", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
@@ -885,6 +888,8 @@ static void clip_dropboxes(void)
ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
+ //TODO(tianwei): think about dropbox for secondary clip
+ //WM_dropbox_add(lb, "CLIP_OT_open_secondary", clip_drop_poll, clip_drop_copy);
}
static void clip_refresh(const bContext *C, ScrArea *sa)