[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47336] trunk/blender/source/blender/ editors/space_image: 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).

Bastien Montagne montagne29 at wanadoo.fr
Fri Jun 1 19:28:09 CEST 2012


Revision: 47336
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47336
Author:   mont29
Date:     2012-06-01 17:28:09 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
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!

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_image/image_buttons.c
    trunk/blender/source/blender/editors/space_image/image_intern.h
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/editors/space_image/space_image.c

Modified: trunk/blender/source/blender/editors/space_image/image_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_buttons.c	2012-06-01 16:50:12 UTC (rev 47335)
+++ trunk/blender/source/blender/editors/space_image/image_buttons.c	2012-06-01 17:28:09 UTC (rev 47336)
@@ -424,18 +424,6 @@
 	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 @@
 	Scene *scene = CTX_data_scene(C);
 	uiLayout *row, *split, *col;
 	uiBlock *block;
-	uiBut *but;
 	char str[128];
 	void *lock;
 
@@ -656,6 +643,7 @@
 	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 @@
 					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 @@
 
 			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);
 			}

Modified: trunk/blender/source/blender/editors/space_image/image_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_intern.h	2012-06-01 16:50:12 UTC (rev 47335)
+++ trunk/blender/source/blender/editors/space_image/image_intern.h	2012-06-01 17:28:09 UTC (rev 47336)
@@ -69,6 +69,7 @@
 
 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);

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-01 16:50:12 UTC (rev 47335)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-01 17:28:09 UTC (rev 47336)
@@ -934,6 +934,52 @@
 	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)

Modified: trunk/blender/source/blender/editors/space_image/space_image.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/space_image.c	2012-06-01 16:50:12 UTC (rev 47335)
+++ trunk/blender/source/blender/editors/space_image/space_image.c	2012-06-01 17:28:09 UTC (rev 47336)
@@ -473,6 +473,7 @@
 
 	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);




More information about the Bf-blender-cvs mailing list