[Bf-blender-cvs] [754eaf4] transform-manipulators: Make transform manipulators of multiple types work together nicely

Julian Eisel noreply at git.blender.org
Mon Oct 24 02:38:26 CEST 2016


Commit: 754eaf45ffb00bc48b6395568a071fc6cbd915f3
Author: Julian Eisel
Date:   Mon Oct 24 02:36:35 2016 +0200
Branches: transform-manipulators
https://developer.blender.org/rB754eaf45ffb00bc48b6395568a071fc6cbd915f3

Make transform manipulators of multiple types work together nicely

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

M	source/blender/editors/space_view3d/view3d_transform_manipulators.c
M	source/blender/windowmanager/manipulators/WM_manipulator_library.h
M	source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c

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

diff --git a/source/blender/editors/space_view3d/view3d_transform_manipulators.c b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
index 59206dd..34107b7 100644
--- a/source/blender/editors/space_view3d/view3d_transform_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
@@ -128,6 +128,54 @@ static wmManipulator *manipulator_dial_init(TranformAxisManipulator *axis, wmMan
 	return WM_dial_manipulator_new(mgroup, axis->name, axis->manipulator_style);
 }
 
+/**
+ * Sets up \a r_start and \a r_len to define arrow line range.
+ * Needed to adjust line drawing for combined manipulator axis types.
+ */
+static void manipulator_line_range(
+        const TranformAxisManipulator *axis, const View3D *v3d,
+        float *r_start, float *r_len)
+{
+	const float ofs = 0.2f;
+
+	*r_start = 0.2f;
+	*r_len = 1.0f;
+
+	switch (axis->transform_type) {
+		case V3D_MANIP_TRANSLATE:
+			if (v3d->twtype & V3D_MANIP_SCALE) {
+				*r_start = *r_len - ofs + 0.075f;
+			}
+			if (v3d->twtype & V3D_MANIP_ROTATE) {
+				*r_len += ofs;
+			}
+			break;
+		case V3D_MANIP_SCALE:
+			if (v3d->twtype & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE)) {
+				*r_len -= ofs + 0.025f;
+			}
+			break;
+	}
+
+	*r_len -= *r_start;
+}
+
+static void manipulator_arrow_update_line_range(const View3D *v3d, const TranformAxisManipulator *axis)
+{
+	float start[3] = {0.0f};
+	float len;
+
+	manipulator_line_range(axis, v3d, &start[2], &len);
+	WM_manipulator_set_offset(axis->manipulator, start);
+	WM_arrow_manipulator_set_length(axis->manipulator, len);
+}
+
+static void manipulator_arrow_refresh(
+        const bContext *C, const TransformManipulatorsInfo *UNUSED(info), const TranformAxisManipulator *axis)
+{
+	manipulator_arrow_update_line_range(CTX_wm_view3d(C), axis);
+}
+
 static void manipulator_dial_refresh(
         const bContext *UNUSED(C), const TransformManipulatorsInfo *info, const TranformAxisManipulator *axis)
 {
@@ -160,19 +208,19 @@ static void manipulator_view_dial_draw_prepare(
 static TranformAxisManipulator tman_axes[] = {
 	{
 		TRANSFORM_AXIS_X, V3D_MANIP_TRANSLATE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"translate_x", {1, 0, 0}, OB_LOCK_LOCX,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_X, MANIPULATOR_ARROW_STYLE_CONE,
 	},
 	{
 		TRANSFORM_AXIS_Y, V3D_MANIP_TRANSLATE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"translate_y", {0, 1, 0}, OB_LOCK_LOCY,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Y, MANIPULATOR_ARROW_STYLE_CONE,
 	},
 	{
 		TRANSFORM_AXIS_Z, V3D_MANIP_TRANSLATE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"translate_z", {0, 0, 1}, OB_LOCK_LOCZ,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Z, MANIPULATOR_ARROW_STYLE_CONE,
 	},
@@ -208,19 +256,19 @@ static TranformAxisManipulator tman_axes[] = {
 	},
 	{
 		TRANSFORM_AXIS_X, V3D_MANIP_SCALE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"scale_x", {1, 0, 0}, OB_LOCK_SCALEX,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_X, MANIPULATOR_ARROW_STYLE_CUBE,
 	},
 	{
 		TRANSFORM_AXIS_Y, V3D_MANIP_SCALE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"scale_y", {0, 1, 0}, OB_LOCK_SCALEY,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Y, MANIPULATOR_ARROW_STYLE_CUBE,
 	},
 	{
 		TRANSFORM_AXIS_Z, V3D_MANIP_SCALE,
-		manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
+		manipulator_arrow_init, manipulator_arrow_refresh, manipulator_arrow_draw_prepare,
 		"scale_y", {0, 0, 1}, OB_LOCK_SCALEZ,
 		1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Z, MANIPULATOR_ARROW_STYLE_CUBE,
 	},
@@ -233,6 +281,12 @@ static TranformAxisManipulator tman_axes[] = {
 	{0, 0, NULL}
 };
 
+static void transform_manipulators_info_init(TransformManipulatorsInfo *info)
+{
+	info->axes = MEM_callocN(sizeof(tman_axes), STRINGIFY(TranformAxisManipulator));
+	memcpy(info->axes, tman_axes, sizeof(tman_axes));
+}
+
 static void transform_manipulators_info_free(void *customdata)
 {
 	TransformManipulatorsInfo *info = customdata;
@@ -306,9 +360,7 @@ static void transform_axis_manipulator_init(TranformAxisManipulator *axis, wmMan
 static void transform_manipulatorgroup_init(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
 {
 	TransformManipulatorsInfo *info = MEM_callocN(sizeof(*info), __func__);
-
-	info->axes = MEM_callocN(sizeof(tman_axes), STRINGIFY(TranformAxisManipulator));
-	memcpy(info->axes, tman_axes, sizeof(tman_axes));
+	transform_manipulators_info_init(info);
 
 	for (int i = 0; info->axes[i].name; i++) {
 		transform_axis_manipulator_init(&info->axes[i], mgroup);
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_library.h b/source/blender/windowmanager/manipulators/WM_manipulator_library.h
index 592db65..4abeb72 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_library.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_library.h
@@ -47,6 +47,7 @@ enum ArrowManipulatorStyle {
 struct wmManipulator *WM_arrow_manipulator_new(
         struct wmManipulatorGroup *mgroup, const char *name, const enum ArrowManipulatorStyle style);
 void WM_arrow_manipulator_set_direction(struct wmManipulator *manipulator, const float direction[3]);
+void WM_arrow_manipulator_set_length(struct wmManipulator *manipulator, const float length);
 
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
index cef7b57..ae3febf 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -56,6 +56,7 @@ typedef struct ArrowManipulator {
 	int style;
 
 	float direction[3];
+	float length;
 } ArrowManipulator;
 
 
@@ -126,7 +127,7 @@ static void arrow_draw_head(const ArrowManipulator *arrow, const float col[4], c
 
 static void arrow_draw_geom(const ArrowManipulator *arrow, const float col[4], const bool select)
 {
-	const float len = 1.0f; /* TODO arrow->len */
+	const float len = arrow->length;
 	const bool use_lighting = /*select == false && ((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0)*/ false;
 
 	glTranslate3fv(arrow->manipulator.offset);
@@ -241,6 +242,7 @@ wmManipulator *WM_arrow_manipulator_new(
 	arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE;
 
 	arrow->style = style;
+	arrow->length = 1.0f;
 
 	wm_manipulator_register(mgroup, &arrow->manipulator, idname);
 
@@ -258,6 +260,13 @@ void WM_arrow_manipulator_set_direction(wmManipulator *manipulator, const float
 	normalize_v3(arrow->direction);
 }
 
+void WM_arrow_manipulator_set_length(wmManipulator *manipulator, const float length)
+{
+	ArrowManipulator *arrow = (ArrowManipulator *)manipulator;
+
+	arrow->length = length;
+}
+
 /** \} */ /* Arrow Manipulator API */




More information about the Bf-blender-cvs mailing list