[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39136] branches/soc-2011-tomato/source/ blender/editors/space_clip: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Sun Aug 7 14:09:56 CEST 2011


Revision: 39136
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39136
Author:   nazgul
Date:     2011-08-07 12:09:56 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Camera tracking integration
===========================

Request from some artists and initial idea: own frame scrubber for clip editor.

- Display current frame number in small rectangle near current frame marker
  in clip editor.
- Mouse can be used to change current frame. It is almost the same as
  for timeline. Changing of frame happens when mouse is slidding in 16px
  height area in the bottom of clip editor.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c	2011-08-07 12:08:58 UTC (rev 39135)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c	2011-08-07 12:09:56 UTC (rev 39136)
@@ -73,9 +73,11 @@
 {
 	float x;
 	int *points, totseg, sel_type, i, a;
-	float sfra= SFRA, efra= EFRA;
+	float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1), fontsize, fontwidth;
 	void *sel;
-	float framelen= ar->winx/(efra-sfra+1);
+	uiStyle *style= U.uistyles.first;
+	int fontid= style->widget.uifont_id;
+	char str[32];
 
 	BKE_movieclip_last_selection(clip, &sel_type, &sel);
 
@@ -166,6 +168,26 @@
 
 	UI_ThemeColor(TH_CFRAME);
 	glRecti(x, 0, x+framelen, 8);
+
+	/* frame number */
+	BLF_size(fontid, 11.f, U.dpi);
+	BLI_snprintf(str, sizeof(str), "%d", sc->user.framenr);
+	fontsize= BLF_height(fontid, str);
+	fontwidth= BLF_width(fontid, str);
+
+	if(x+fontwidth+6.f<=ar->winx) {
+		glRecti(x, 8.f, x+fontwidth+6.f, 12.f+fontsize);
+
+		glColor3f(0.f, 0.f, 0.f);
+		BLF_position(fontid, x+2.f, 10.f, 0.f);
+		BLF_draw(fontid, str, strlen(str));
+	} else {
+		glRecti(x+framelen, 8.f, x+framelen-fontwidth-6.f, 12.f+fontsize);
+
+		glColor3f(0.f, 0.f, 0.f);
+		BLF_position(fontid, x-2.f-fontwidth+framelen, 10.f, 0.f);
+		BLF_draw(fontid, str, strlen(str));
+	}
 }
 
 static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf, float zoomx, float zoomy)

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h	2011-08-07 12:08:58 UTC (rev 39135)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h	2011-08-07 12:09:56 UTC (rev 39136)
@@ -54,6 +54,7 @@
 void CLIP_OT_view_zoom_ratio(struct wmOperatorType *ot);
 void CLIP_OT_view_all(struct wmOperatorType *ot);
 void CLIP_OT_view_selected(struct wmOperatorType *ot);
+void CLIP_OT_change_frame(wmOperatorType *ot);
 
 /* tracking_ops.c */
 void CLIP_OT_select(struct wmOperatorType *ot);

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_ops.c	2011-08-07 12:08:58 UTC (rev 39135)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_ops.c	2011-08-07 12:09:56 UTC (rev 39136)
@@ -32,15 +32,18 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_userdef_types.h"
+#include "DNA_scene_types.h"	/* min/max frames */
 
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
 
 #include "BKE_context.h"
+#include "BKE_global.h"
 #include "BKE_report.h"
 #include "BKE_main.h"
 #include "BKE_library.h"
 #include "BKE_movieclip.h"
+#include "BKE_sound.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -730,6 +733,104 @@
 	ot->poll= ED_space_clip_poll;
 }
 
+/********************** change frame operator *********************/
+
+static int change_frame_poll(bContext *C)
+{
+	/* prevent changes during render */
+	if(G.rendering)
+		return 0;
+
+	return ED_space_clip_poll(C);
+}
+
+static void change_frame_apply(bContext *C, wmOperator *op)
+{
+	Scene *scene= CTX_data_scene(C);
+
+	/* set the new frame number */
+	CFRA= RNA_int_get(op->ptr, "frame");
+	FRAMENUMBER_MIN_CLAMP(CFRA);
+	SUBFRA = 0.f;
+
+	/* do updates */
+	sound_seek_scene(C);
+	WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+}
+
+static int change_frame_exec(bContext *C, wmOperator *op)
+{
+	change_frame_apply(C, op);
+
+	return OPERATOR_FINISHED;
+}
+
+static int frame_from_event(bContext *C, wmEvent *event)
+{
+	ARegion *ar= CTX_wm_region(C);
+	Scene *scene= CTX_data_scene(C);
+
+	float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1);
+
+	return sfra+event->mval[0]/framelen;
+}
+
+static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	if(event->mval[1]>16)
+		return OPERATOR_PASS_THROUGH;
+
+	RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
+
+	change_frame_apply(C, op);
+
+	/* add temp handler */
+	WM_event_add_modal_handler(C, op);
+
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+	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 LEFTMOUSE:
+		case RIGHTMOUSE:
+			if (event->val==KM_RELEASE)
+				return OPERATOR_FINISHED;
+			break;
+	}
+
+	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";
+
+	/* 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;
+
+	/* rna */
+	RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
+}
+
 /********************** macroses *********************/
 
 void ED_operatormacros_clip(void)

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2011-08-07 12:08:58 UTC (rev 39135)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2011-08-07 12:09:56 UTC (rev 39136)
@@ -249,6 +249,7 @@
 	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_select);
 	WM_operatortype_append(CLIP_OT_select_all);
@@ -406,6 +407,8 @@
 	kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0);
 	RNA_string_set(kmi->ptr, "data_path", "space_data.use_mute_footage");
 
+	WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
+
 	transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
 }
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-08-07 12:08:58 UTC (rev 39135)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-08-07 12:09:56 UTC (rev 39136)
@@ -485,7 +485,7 @@
 		return OPERATOR_RUNNING_MODAL;
 	}
 
-	return OPERATOR_CANCELLED;
+	return OPERATOR_PASS_THROUGH;
 }
 
 static void cancel_mouse_slide(SlideMarkerData *data)




More information about the Bf-blender-cvs mailing list