[Bf-blender-cvs] [71f1a3b] wiggly-widgets: Make projection code for arrow widget better. Also add some code to allow tweaking of properties

Antony Riakiotakis noreply at git.blender.org
Wed Nov 5 18:10:11 CET 2014


Commit: 71f1a3b1e217b912ac0171f424705834f2d4cbb7
Author: Antony Riakiotakis
Date:   Wed Nov 5 18:09:56 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB71f1a3b1e217b912ac0171f424705834f2d4cbb7

Make projection code for arrow widget better. Also add some code to
allow tweaking of properties

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_generic_widgets.c
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/wm.h

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index ee20a43..a92f4ad 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -710,7 +710,7 @@ static void view3d_widgets(void)
 	                       WIDGET_manipulator_render_3d_intersect,
 	                       NULL,
 	                       WIDGET_manipulator_handler,
-	                       NULL, NULL, false, NULL, NULL);
+	                       NULL, NULL, false, NULL, NULL, NULL);
 	
 	WM_widget_register(wgroup_manipulator, widget);
 
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 2380809..a2fe94b 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1662,7 +1662,6 @@ void WIDGET_manipulator_draw(wmWidget *UNUSED(widget), const bContext *C, float
 	View3D *v3d = sa->spacedata.first;
 	RegionView3D *rv3d = ar->regiondata;
 
-
 	if (v3d->twflag & V3D_DRAW_MANIPULATOR) {
 
 		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1833,7 +1832,7 @@ void WIDGET_manipulator_render_3d_intersect(const bContext *C, wmWidget *UNUSED(
 }
 
 /* return 0; nothing happened */
-int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidget *UNUSED(widget), struct PointerRNA *opptr)
+int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidget *UNUSED(widget), struct PointerRNA *UNUSED(opptr))
 {
 	ScrArea *sa = CTX_wm_area(C);
 	View3D *v3d = sa->spacedata.first;
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index a2be4be..eca4875 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -71,7 +71,6 @@ struct ImBuf;
 struct ImageFormatData;
 struct ARegion;
 struct wmNDOFMotionData;
-struct PointerRNA;
 
 typedef struct wmJob wmJob;
 
@@ -477,7 +476,7 @@ struct wmWidget *WM_widget_new(void (*draw)(struct wmWidget *, const struct bCon
 							   int  (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *customdata),
                                int  (*initialize_op)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct PointerRNA *),
                                int  (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct wmOperator *op),
-                               void *customdata, bool free_data, char *opname, char *prop);
+                               void *customdata, bool free_data, char *opname, char *prop, struct PointerRNA *ptr);
 
 void WM_widgets_draw(const struct bContext *C, struct ARegion *ar);
 void WM_event_add_widget_handler(struct ARegion *ar);
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index a5fabbd..8bfb867 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -194,40 +194,54 @@ static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event,
 	ARegion *ar = CTX_wm_region(C);
 	RegionView3D *rv3d = ar->regiondata;
 
-	float homogenous_coord;
 	float orig_origin[4];
+	float offset[4];
 	float m_diff[2];
+	float dir_2d[2], dir2d_final[2];
+	float fac;
 
 	copy_v3_v3(orig_origin, data->orig_origin);
 	orig_origin[3] = 1.0f;
+	add_v3_v3v3(offset, orig_origin, arrow->direction);
+	offset[3] = 1.0f;
 
 	/* multiply to projection space */
 	mul_m4_v4(rv3d->persmat, orig_origin);
+	mul_m4_v4(rv3d->persmat, offset);
 
-	homogenous_coord = orig_origin[3];
+	mul_v4_fl(orig_origin, 1.0f/orig_origin[3]);
+	mul_v4_fl(offset, 1.0f/offset[3]);
+	sub_v2_v2v2(dir_2d, offset, orig_origin);
+	normalize_v2(dir_2d);
 
-	mul_v2_fl(orig_origin, 1.0f/homogenous_coord);
+	dir_2d[0] *= BLI_rcti_size_x(&ar->winrct) * 0.5f;
+	dir_2d[1] *= BLI_rcti_size_y(&ar->winrct) * 0.5f;
 
 	/* find mouse difference */
 	m_diff[0] = event->mval[0] - data->orig_mouse[0];
 	m_diff[1] = event->mval[1] - data->orig_mouse[1];
 
-	/* express it as difference in normalized screen space */
-	m_diff[0] /= (BLI_rcti_size_x(&ar->winrct) * 0.5f);
-	m_diff[1] /= (BLI_rcti_size_y(&ar->winrct) * 0.5f);
+	/* project the displacement on the screen space arrow direction */
+	project_v2_v2v2(dir2d_final, m_diff, dir_2d);
 
-	/* now mouse difference is in normalized coordinates, add it to orig_origin */
-	add_v2_v2(orig_origin, m_diff);
+	dir2d_final[0] /= (BLI_rcti_size_x(&ar->winrct) * 0.5f);
+	dir2d_final[1] /= (BLI_rcti_size_y(&ar->winrct) * 0.5f);
 
-	mul_v2_fl(orig_origin, homogenous_coord);
+	add_v2_v2(orig_origin, dir2d_final);
 
-	/* project back to world space */
+	/* project back to world space and find world space displacement direction */
 	mul_m4_v4(rv3d->persinv, orig_origin);
+	mul_v4_fl(orig_origin, 1.0f/orig_origin[3]);
 
-	/* project to the line formed by original point and direction */
 	sub_v3_v3(orig_origin, data->orig_origin);
-	project_v3_v3v3(orig_origin, orig_origin, arrow->direction);
-	add_v3_v3v3(widget->origin, orig_origin, data->orig_origin);
+
+	/* reuse offset, project direction to displacement */
+	project_v3_v3v3(offset, arrow->direction, orig_origin);
+	fac = len_v3(orig_origin) / len_v3(offset);
+	if (dot_v3v3(offset, orig_origin) < 0.0f)
+		fac *= -1.0;
+	mul_v3_v3fl(widget->origin, offset, fac);
+	add_v3_v3(widget->origin, data->orig_origin);
 
 	/* set the property for the operator and call its modal function */
 	if (op && widget->prop) {
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index b94e262..331d961 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -140,7 +140,7 @@ wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct b
 						int  (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget),
                         int  (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *),
                         int  (*handler)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct wmOperator *op),
-                        void *customdata, bool free_data, char *opname, char *prop)
+                        void *customdata, bool free_data, char *opname, char *prop, PointerRNA *ptr)
 {
 	wmWidget *widget;
 	
@@ -153,8 +153,10 @@ wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct b
 	widget->render_3d_intersection = render_3d_intersection;
 	widget->customdata = customdata;
 	
-	widget->opname = opname;
+	if (!ptr)
+		widget->opname = opname;
 	widget->prop = prop;
+	widget->ptr = ptr;
 
 	if (free_data)
 		widget->flag |= WM_WIDGET_FREE_DATA;
@@ -525,7 +527,7 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 {
 	if (widget) {
 		if (widget->opname && widget->handler) {
-			wmOperatorType *ot = widget->ot = WM_operatortype_find(widget->opname, 0);
+			wmOperatorType *ot = WM_operatortype_find(widget->opname, 0);
 
 			if (ot) {
 				widget->flag |= WM_WIDGET_ACTIVE;
@@ -534,15 +536,15 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 					widget->activate_state(C, event, widget, WIDGET_ACTIVATE);
 				}
 
-				WM_operator_properties_create_ptr(&widget->propptr, ot);
+				WM_operator_properties_alloc(&widget->ptr, &widget->properties, widget->opname);
 
 				/* time to initialize those properties now */
 				if (widget->initialize_op) {
-					widget->initialize_op(C, event, widget, &widget->propptr);
+					widget->initialize_op(C, event, widget, widget->ptr);
 				}
 
 				CTX_wm_widget_set(C, widget);
-				WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &widget->propptr);
+				WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, widget->ptr);
 				wmap->active_widget = widget;
 				return;
 			}
@@ -569,13 +571,19 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 				widget->activate_state(C, event, widget, WIDGET_DEACTIVATE);
 			}
 
-			WM_operator_properties_free(&widget->propptr);
+			if (widget->opname && widget->ptr) {
+				WM_operator_properties_free(widget->ptr);
+				MEM_freeN(widget->ptr);
+				widget->properties = NULL;
+				widget->ptr = NULL;
+			}
 		}
 
 		CTX_wm_widget_set(C, NULL);
 
 		wmap->active_widget = NULL;
 		ED_region_tag_redraw(ar);
+		WM_event_add_mousemove(C);
 	}
 }
 
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index d7c235d..95cbe5d 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -63,7 +63,7 @@ typedef struct wmWidget {
 	void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *widget, float scale, int selectionbase);
 
 	/* initialize the operator properties when the user clicks the widget */
-	int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *propptr);
+	int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr);
 
 	/* handler used by the widget. Usually handles interaction tied to a widget type */
 	int  (*handler)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct wmOperator *op);
@@ -82,14 +82,12 @@ typedef struct wmWidget {
 	/* name of operator to spawn when activating the widget */
 	const char *opname;
 
-	/* property name of the operator that the widget controls */
+	/* property name of the operator or pointer that the widget controls */
 	const char *prop;
 
-	/* operator type that will be called */
-	wmOperatorType *ot;
-
-	/* operator properties, stored if widget spawns and controls an operator */
-	struct PointerRNA propptr;
+	/* operator properties if widget spawns and controls an operator, or owner pointer if widget spawns and controls a property */
+	struct PointerRNA *ptr;
+	struct IDProperty *properties;	/* operator properti

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list