[Bf-blender-cvs] [4380a92] wiggly-widgets: Sequencer operator that uses widgets and controls the placement of the backdrop is now functional.

Antony Riakiotakis noreply at git.blender.org
Wed Dec 10 21:03:16 CET 2014


Commit: 4380a92c05696fd006b6efa1d3c6ccd5819094a5
Author: Antony Riakiotakis
Date:   Wed Dec 10 19:47:18 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB4380a92c05696fd006b6efa1d3c6ccd5819094a5

Sequencer operator that uses widgets and controls the placement of the
backdrop is now functional.

The widget could communicate with the sequencer properties directly, but
here we set it to control the operator properties as a demonstration.

After some minor stress testing, time to give this to gooseberry team.

===================================================================

M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_view.c
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/wm_event_system.h

===================================================================

diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index f05e19b..8d1d1b5 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -447,6 +447,11 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 						SpaceNode *snode = (SpaceNode *)sl;
 						snode->backdrop_zoom = 1.0;
 					}
+					if (sl->spacetype == SPACE_SEQ) {
+						SpaceSeq *sseq = (SpaceSeq *)sl;
+						sseq->backdrop_zoom = 1.0;
+					}
+					
 				}
 			}
 		}
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 3cbcd2b..7805185 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1171,12 +1171,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
 
 	if (draw_backdrop) {
-		glMatrixMode(GL_PROJECTION);
-		glPushMatrix();
-		glLoadIdentity();
-		glMatrixMode(GL_MODELVIEW);
-		glPushMatrix();
-		glLoadIdentity();
+		UI_view2d_view_restore(C);
 	}
 	glBegin(GL_QUADS);
 
@@ -1201,22 +1196,15 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 		}
 	}
 	else if (draw_backdrop) {
-		float aspect = BLI_rcti_size_x(&ar->winrct) / (float)BLI_rcti_size_y(&ar->winrct);	
-		float image_aspect = viewrectx / viewrecty;
-		float imagex, imagey;
+		float imagex = (scene->r.size * scene->r.xsch) / 200.0f * sseq->backdrop_zoom;
+		float imagey = (scene->r.size * scene->r.ysch) / 200.0f * sseq->backdrop_zoom;
+		float xofs = BLI_rcti_size_x(&ar->winrct)/2.0f + sseq->backdrop_offset[0];
+		float yofs = BLI_rcti_size_y(&ar->winrct)/2.0f + sseq->backdrop_offset[1];
 		
-		if (aspect >= image_aspect) {
-			imagex = image_aspect / aspect;
-			imagey = 1.0f;
-		}
-		else {
-			imagex = 1.0f;
-			imagey = aspect / image_aspect;
-		}		
-		glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
-		glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
-		glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
-		glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
+		glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex + xofs, -imagey + yofs);
+		glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex + xofs, imagey + yofs);
+		glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex + xofs, imagey + yofs);
+		glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex + xofs, -imagey + yofs);
 	}
 	else {
 		glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
@@ -1226,13 +1214,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 	}
 	glEnd();
 	
-	if (draw_backdrop) {
-		glPopMatrix();
-		glMatrixMode(GL_PROJECTION);
-		glPopMatrix();
-		glMatrixMode(GL_MODELVIEW);
-	}
-	
 	glBindTexture(GL_TEXTURE_2D, last_texid);
 	glDisable(GL_TEXTURE_2D);
 	if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
@@ -1249,7 +1230,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 		IMB_freeImBuf(ibuf);
 	
 	if (draw_backdrop) {
-		UI_view2d_view_restore(C);
 		WM_widgets_draw(C, ar->widgetmaps.first);
 		return;
 	}
diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c
index 3691ca1..b19f5e5 100644
--- a/source/blender/editors/space_sequencer/sequencer_view.c
+++ b/source/blender/editors/space_sequencer/sequencer_view.c
@@ -33,6 +33,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_rect.h"
 
 #include "DNA_scene_types.h"
 #include "DNA_widget_types.h"
@@ -252,28 +253,35 @@ static int sequencer_backdrop_transform_poll(bContext *C)
 
 static void widgetgroup_backdrop_draw(const struct bContext *C, struct wmWidgetGroup *wgroup)
 {
+	ARegion *ar = CTX_wm_region(C);
 	wmOperator *op = wgroup->type->op;
-	ImBuf *ibuf;
-	Scene *scene = CTX_data_scene(C);
+	Scene *sce = CTX_data_scene(C);
+	int sizex = (sce->r.size * sce->r.xsch) / 100;
+	int sizey = (sce->r.size * sce->r.ysch) / 100;
+	float origin[3];	
 	
-	ibuf = sequencer_ibuf_get(CTX_data_main(C), scene, CTX_wm_space_seq(C), scene->r.cfra, 0);
+	wmWidget *cage = WIDGET_rect_transform_new(wgroup, WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM | 
+	                                           WIDGET_RECT_TRANSFORM_STYLE_TRANSLATE, sizex, sizey);
+	WM_widget_property(cage, RECT_TRANSFORM_SLOT_OFFSET, op->ptr, "offset");
+	WM_widget_property(cage, RECT_TRANSFORM_SLOT_SCALE, op->ptr, "scale");
 	
-	if (ibuf) {
-		wmWidget *cage = WIDGET_rect_transform_new(wgroup, WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM | 
-		                                           WIDGET_RECT_TRANSFORM_STYLE_TRANSLATE, ibuf->x, ibuf->y);
-		WM_widget_property(cage, RECT_TRANSFORM_SLOT_OFFSET, op->ptr, "offset");
-		WM_widget_property(cage, RECT_TRANSFORM_SLOT_SCALE, op->ptr, "scale");
-		
-		IMB_freeImBuf(ibuf);
-	}
+	origin[0] = BLI_rcti_size_x(&ar->winrct)/2.0f;
+	origin[1] = BLI_rcti_size_y(&ar->winrct)/2.0f;
+	
+	WM_widget_set_origin(cage, origin);
 }
 
 static int sequencer_backdrop_transform_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
+	SpaceSeq *sseq = CTX_wm_space_seq(C);
 	/* no poll, lives always for the duration of the operator */
 	wmWidgetGroupType *cagetype = WM_widgetgrouptype_new(NULL, widgetgroup_backdrop_draw, CTX_data_main(C), "Seq_Canvas", SPACE_SEQ, RGN_TYPE_WINDOW, false);
 	struct wmEventHandler *handler = WM_event_add_modal_handler(C, op);
 	WM_modal_handler_attach_widgetgroup(handler, cagetype, op);
+	WM_event_add_mousemove(C);
+	
+	RNA_float_set_array(op->ptr, "offset", sseq->backdrop_offset);
+	RNA_float_set(op->ptr, "scale", sseq->backdrop_zoom);
 	
 	op->customdata = cagetype;
 	return OPERATOR_RUNNING_MODAL;
@@ -282,12 +290,36 @@ static int sequencer_backdrop_transform_invoke(bContext *C, wmOperator *op, cons
 static int sequencer_backdrop_transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	switch (event->type) {
-		case EVT_WIDGET_UPDATE:
+		case EVT_WIDGET_UPDATE: {
+			SpaceSeq *sseq = CTX_wm_space_seq(C);
+			RNA_float_get_array(op->ptr, "offset", sseq->backdrop_offset);
+			sseq->backdrop_zoom = RNA_float_get(op->ptr, "scale");
 			break;
+		}
 			
+		case RKEY: 
+		{
+			SpaceSeq *sseq = CTX_wm_space_seq(C);
+			ARegion *ar = CTX_wm_region(C);
+			float zero[2] = {0.0f};
+			RNA_float_set_array(op->ptr, "offset", zero);
+			RNA_float_set(op->ptr, "scale", 1.0f);
+			copy_v2_v2(sseq->backdrop_offset, zero);
+			sseq->backdrop_zoom = 1.0;
+			ED_region_tag_redraw(ar);
+			/* add a mousemove to refresh the widget */
+			WM_event_add_mousemove(C);
+			break;
+		}
 		case RETKEY:
+		case PADENTER:
 			WM_widgetgrouptype_unregister(CTX_data_main(C), op->customdata);
 			return OPERATOR_FINISHED;
+			
+		case ESCKEY:
+		case RIGHTMOUSE:
+			WM_widgetgrouptype_unregister(CTX_data_main(C), op->customdata);
+			return OPERATOR_CANCELLED;
 	}
 	
 	return OPERATOR_RUNNING_MODAL;
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 076f6bb..7c05a74 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -121,6 +121,9 @@ static SpaceLink *sequencer_new(const bContext *C)
 	sseq->mainb = SEQ_DRAW_IMG_IMBUF;
 	sseq->flag = SEQ_SHOW_GPENCIL | SEQ_USE_ALPHA;
 
+	/* backdrop */
+	sseq->backdrop_zoom = 1.0f;
+	
 	/* header */
 	ar = MEM_callocN(sizeof(ARegion), "header for sequencer");
 	
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 0b85c94..c88c07e 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -499,7 +499,8 @@ typedef struct SpaceSeq {
 	int view; /* see SEQ_VIEW_* below */
 	int overlay_type;
 	int draw_flag; /* overlay an image of the editing on below the strips */
-	int pad;
+	float backdrop_zoom;
+	float backdrop_offset[2];
 
 	struct bGPdata *gpd;        /* grease-pencil data */
 
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 77dcc0b..452e5c4 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2630,6 +2630,18 @@ static void rna_def_space_sequencer(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "draw_flag", SEQ_DRAW_BACKDROP);
 	RNA_def_property_ui_text(prop, "Use Backdrop", "Display result under strips");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, NULL);
+	
+	prop = RNA_def_property(srna, "backdrop_zoom", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_range(prop, 0.01f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.01, 100, 1, 2);
+	RNA_def_property_ui_text(prop, "Backdrop Zoom", "Backdrop zoom factor");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
+	
+	prop = RNA_def_property(srna, "backdrop_offset", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_array(prop, 2);
+	RNA_def_property_ui_text(prop, "Backdrop Offset", "Backdrop offset");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
 }
 
 static void rna_def_space_text(BlenderRNA *brna)
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 6c16dfe..67db22a 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2007,17 +2007,17 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 				struct wmWidgetMap *wmap = handler->widgetmap;
 				unsigned char part;
 				short event_processed = 0;
-				short val_processed = event->val;
 				wmWidget *widget = wm_widgetmap_get_active_widget(wmap);
 				ScrArea *area = CTX_wm_area(C);
 				ARegion *region = CTX_wm_region(C);
 				
 				wm_handler_widgetmap_context(C, handler);
+				wm_region_mouse_co(C, event);
 				
 				switch (event->type) {
 					case MOU

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list