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
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!
-rw-r--r--source/blender/editors/space_image/image_buttons.c42
-rw-r--r--source/blender/editors/space_image/image_intern.h1
-rw-r--r--source/blender/editors/space_image/image_ops.c46
-rw-r--r--source/blender/editors/space_image/space_image.c1
4 files changed, 64 insertions, 26 deletions
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index f8815c3865e..6e52056ff2b 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -424,18 +424,6 @@ static char *pass_menu(RenderLayer *rl, short *curpass)
return str;
}
-static void set_frames_cb(bContext *C, void *ima_v, void *iuser_v)
-{
- Scene *scene = CTX_data_scene(C);
- Image *ima = ima_v;
- ImageUser *iuser = iuser_v;
-
- if (ima->anim) {
- iuser->frames = IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN);
- BKE_image_user_frame_calc(iuser, scene->r.cfra, 0);
- }
-}
-
/* 5 layer button callbacks... */
static void image_multi_cb(bContext *C, void *rr_v, void *iuser_v)
{
@@ -624,7 +612,6 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
Scene *scene = CTX_data_scene(C);
uiLayout *row, *split, *col;
uiBlock *block;
- uiBut *but;
char str[128];
void *lock;
@@ -656,6 +643,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
cb->iuser = iuser;
uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
+ uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
if (!compact)
uiTemplateID(layout, C, ptr, propname, "IMAGE_OT_new", "IMAGE_OT_open", NULL);
@@ -746,7 +734,18 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
split = uiLayoutSplit(layout, 0, 0);
col = uiLayoutColumn(split, 0);
- uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NONE);
+ /* XXX Why only display fields_per_frame only for video image types?
+ * And why allow fields for non-video image types at all??? */
+ if (ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
+ uiLayout *subsplit = uiLayoutSplit(col, 0, 0);
+ uiLayout *subcol = uiLayoutColumn(subsplit, 0);
+ uiItemR(subcol, &imaptr, "use_fields", 0, NULL, ICON_NONE);
+ subcol = uiLayoutColumn(subsplit, 0);
+ uiLayoutSetActive(subcol, RNA_boolean_get(&imaptr, "use_fields"));
+ uiItemR(subcol, userptr, "fields_per_frame", 0, IFACE_("Fields"), ICON_NONE);
+ }
+ else
+ uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NONE);
row = uiLayoutRow(col, 0);
uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
@@ -759,27 +758,18 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
if (ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
uiItemS(layout);
-
+
split = uiLayoutSplit(layout, 0, 0);
col = uiLayoutColumn(split, 0);
-
+
BLI_snprintf(str, sizeof(str), IFACE_("(%d) Frames"), iuser->framenr);
uiItemR(col, userptr, "frame_duration", 0, str, ICON_NONE);
- if (ima->anim) {
- block = uiLayoutGetBlock(col);
- but = uiDefBut(block, BUT, 0, IFACE_("Match Movie Length"), 0, 0, UI_UNIT_X * 2, UI_UNIT_Y,
- NULL, 0, 0, 0, 0, TIP_("Set the number of frames to match the movie or sequence"));
- uiButSetFunc(but, set_frames_cb, ima, iuser);
- }
-
uiItemR(col, userptr, "frame_start", 0, IFACE_("Start"), ICON_NONE);
uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NONE);
col = uiLayoutColumn(split, 0);
- row = uiLayoutRow(col, 0);
- uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
- uiItemR(row, userptr, "fields_per_frame", 0, IFACE_("Fields"), ICON_NONE);
+ uiItemO(col, NULL, ICON_NONE, "IMAGE_OT_match_movie_length");
uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NONE);
uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NONE);
}
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h
index ca3f543f3b9..121130ec536 100644
--- a/source/blender/editors/space_image/image_intern.h
+++ b/source/blender/editors/space_image/image_intern.h
@@ -69,6 +69,7 @@ void IMAGE_OT_view_ndof(struct wmOperatorType *ot);
void IMAGE_OT_new(struct wmOperatorType *ot);
void IMAGE_OT_open(struct wmOperatorType *ot);
+void IMAGE_OT_match_movie_length(struct wmOperatorType *ot);
void IMAGE_OT_replace(struct wmOperatorType *ot);
void IMAGE_OT_reload(struct wmOperatorType *ot);
void IMAGE_OT_save(struct wmOperatorType *ot);
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)
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 9e0f538056c..a8d83500cc1 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -473,6 +473,7 @@ static void image_operatortypes(void)
WM_operatortype_append(IMAGE_OT_new);
WM_operatortype_append(IMAGE_OT_open);
+ WM_operatortype_append(IMAGE_OT_match_movie_length);
WM_operatortype_append(IMAGE_OT_replace);
WM_operatortype_append(IMAGE_OT_reload);
WM_operatortype_append(IMAGE_OT_save);