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:
authorBastien Montagne <montagne29@wanadoo.fr>2012-06-01 21:28:09 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-06-01 21:28:09 +0400
commit14b1c408fd797198507a0580fad74a2a5420da5e (patch)
treea11de7bdaeeba16ebb3f30b3963c721faf2f8789 /source/blender/editors/space_image/image_ops.c
parent9efc294d457c974cc8626ec50c90f755ed25c9e5 (diff)
Make "Match Movie Length" into an operator (must be called inside a context having either a "texture" Tex, an "area" SpaceImage, or both "edit_image" Image and "edit_image_user" ImageUser).
Thanks to Campbell who pointed me to uiLayoutSetContextPointer() func!
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r--source/blender/editors/space_image/image_ops.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 31389bcb20c..2cb36841082 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -934,6 +934,52 @@ void IMAGE_OT_open(wmOperatorType *ot)
WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
}
+/******************** Match movie length operator ********************/
+static int image_match_len_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+ Image *ima = CTX_data_pointer_get_type(C, "edit_image", &RNA_Image).data;
+ ImageUser *iuser = CTX_data_pointer_get_type(C, "edit_image_user", &RNA_ImageUser).data;
+
+ if (!ima || !iuser) {
+ /* Try to get a Texture, or a SpaceImage from context... */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
+ if (tex && tex->type == TEX_IMAGE) {
+ ima = tex->ima;
+ iuser = &tex->iuser;
+ }
+ else if (sima) {
+ ima = sima->image;
+ iuser = &sima->iuser;
+ }
+
+ }
+
+ if (!ima || !iuser || !ima->anim)
+ return OPERATOR_CANCELLED;
+
+ iuser->frames = IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN);
+ BKE_image_user_frame_calc(iuser, scene->r.cfra, 0);
+
+ return OPERATOR_FINISHED;
+}
+
+/* called by other space types too */
+void IMAGE_OT_match_movie_length(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Match Movie Length";
+ ot->description = "Set image's users length to the one of this video";
+ ot->idname = "IMAGE_OT_match_movie_length";
+
+ /* api callbacks */
+ ot->exec = image_match_len_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER /* | OPTYPE_UNDO */; /* Don't think we need undo for that. */
+}
+
/******************** replace image operator ********************/
static int image_replace_exec(bContext *C, wmOperator *op)