[Bf-blender-cvs] [195788a] wiggly-widgets: Add flag so offset is applied in world, not screen space.

Antony Riakiotakis noreply at git.blender.org
Mon Nov 17 15:40:51 CET 2014


Commit: 195788a24ac0868018eb91cc560f2b959ced8071
Author: Antony Riakiotakis
Date:   Mon Nov 17 15:39:21 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB195788a24ac0868018eb91cc560f2b959ced8071

Add flag so offset is applied in world, not screen space.

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

M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_generic_widgets.c

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

diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index b47a3a5..06f491a 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -517,7 +517,9 @@ enum {
 	/* inverted offset during interaction - if set it also sets constrained below */
 	UI_ARROW_STYLE_INVERTED      = (1 << 2),
 	/* clamp arrow interaction to property width */
-	UI_ARROW_STYLE_CONSTRAINED   = (1 << 4)
+	UI_ARROW_STYLE_CONSTRAINED   = (1 << 3),
+	/* force offset to be in 3D space, even if widget system is not 3D */
+	UI_ARROW_STYLE_OFFSET_3D   = (1 << 4),
 };
 
 enum {
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index 460ff1c..e813d6c 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -162,8 +162,10 @@ static void arrow_draw_intern(ArrowWidget *arrow, bool select, bool highlight, f
 	float up[3] = {0.0f, 0.0f, 1.0f};
 	float final_pos[3];
 
-	copy_v3_v3(final_pos, arrow->direction);
-	mul_v3_fl(final_pos, scale * arrow->offset);
+	if (arrow->style & UI_ARROW_STYLE_OFFSET_3D)
+		mul_v3_v3fl(final_pos, arrow->direction, arrow->offset);
+	else
+		mul_v3_v3fl(final_pos, arrow->direction, scale * arrow->offset);
 	add_v3_v3(final_pos, arrow->widget.origin);
 
 	rotation_between_vecs_to_mat3(rot, up, arrow->direction);
@@ -186,8 +188,10 @@ static void arrow_draw_intern(ArrowWidget *arrow, bool select, bool highlight, f
 	if (arrow->widget.interaction_data) {
 		ArrowInteraction *data = arrow->widget.interaction_data;
 
-		copy_v3_v3(final_pos, arrow->direction);
-		mul_v3_fl(final_pos, scale * data->orig_offset);
+		if (arrow->style & UI_ARROW_STYLE_OFFSET_3D)
+			mul_v3_v3fl(final_pos, arrow->direction, data->orig_offset);
+		else
+			mul_v3_v3fl(final_pos, arrow->direction, scale * data->orig_offset);
 		add_v3_v3(final_pos, arrow->widget.origin);
 
 		copy_m4_m3(mat, rot);
@@ -231,9 +235,11 @@ static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event,
 	float offset[4];
 	float m_diff[2];
 	float dir_2d[2], dir2d_final[2];
-	float fac, zfac;
+	float fac, zfac, widget_scale;
 	float facdir = 1.0f;
 
+	widget_scale = (arrow->style & UI_ARROW_STYLE_OFFSET_3D) ? 1.0 : widget->scale;
+
 	copy_v3_v3(orig_origin, data->orig_origin);
 	orig_origin[3] = 1.0f;
 	add_v3_v3v3(offset, orig_origin, arrow->direction);
@@ -286,7 +292,7 @@ static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event,
 	else if (widget->prop) {
 		float value;
 
-		value = data->orig_offset + facdir / widget->scale * len_v3(offset);
+		value = data->orig_offset + facdir / widget_scale * len_v3(offset);
 		if (arrow->style & UI_ARROW_STYLE_CONSTRAINED) {
 			if (arrow->style & UI_ARROW_STYLE_INVERTED)
 				value = arrow->min + arrow->range - (value * arrow->range / ARROW_RANGE);
@@ -308,7 +314,7 @@ static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event,
 			arrow->offset = RNA_property_float_get(widget->ptr, widget->prop);
 	}
 	else {
-		arrow->offset = facdir / widget->scale * len_v3(offset);
+		arrow->offset = facdir / widget_scale * len_v3(offset);
 	}
 
 	/* tag the region for redraw */




More information about the Bf-blender-cvs mailing list