[Bf-blender-cvs] [1c20d194e1a] custom-manipulators: Manipulator Properties

Campbell Barton noreply at git.blender.org
Wed Jun 14 21:30:58 CEST 2017


Commit: 1c20d194e1a45cede608831cd25c793efacaa406
Author: Campbell Barton
Date:   Thu Jun 15 02:41:09 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB1c20d194e1a45cede608831cd25c793efacaa406

Manipulator Properties

- Add a different kind of properties that use function callbacks
  instead of RNA.
  Needed for situations when there isn't 1:1 correspondence
  between the manipulator's position and the internal value.
- Move manipulator properties into their own file.

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

M	build_files/cmake/macros.cmake
M	source/blender/editors/manipulator_library/arrow3d_manipulator.c
M	source/blender/editors/manipulator_library/cage2d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_library_intern.h
M	source/blender/editors/manipulator_library/manipulator_library_utils.c
M	source/blender/editors/space_node/node_manipulators.c
M	source/blender/editors/space_view3d/view3d_manipulators.c
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/manipulators/WM_manipulator_api.h
M	source/blender/windowmanager/manipulators/WM_manipulator_types.h
M	source/blender/windowmanager/manipulators/intern/wm_manipulator.c
A	source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
M	source/blender/windowmanager/manipulators/wm_manipulator_fn.h

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

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 836fd5f1a6b..43560ee82a6 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -612,6 +612,7 @@ function(SETUP_BLENDER_SORTED_LIBS)
 		bf_physics
 		bf_nodes
 		bf_rna
+		bf_windowmanager  # for bf_editor_manipulator_library below.
 		bf_editor_manipulator_library  # rna -> manipulator bad-level calls
 		bf_python
 		bf_imbuf
diff --git a/source/blender/editors/manipulator_library/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
index b4c8f0498c8..b8bf2669a39 100644
--- a/source/blender/editors/manipulator_library/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
@@ -343,18 +343,18 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
 	ManipulatorCommonData *data = &arrow->data;
 	const float ofs_new = facdir * len_v3(offset);
 
-	wmManipulatorProperty *mpr_prop = WM_manipulator_get_property(mpr, "offset");
+	wmManipulatorProperty *mpr_prop = WM_manipulator_property_find(mpr, "offset");
 
 	/* set the property for the operator and call its modal function */
-	if (mpr_prop->prop != NULL) {
+	if (WM_manipulator_property_is_valid(mpr_prop)) {
 		const bool constrained = arrow->style & ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED;
 		const bool inverted = arrow->style & ED_MANIPULATOR_ARROW_STYLE_INVERTED;
 		const bool use_precision = flag & WM_MANIPULATOR_TWEAK_PRECISE;
 		float value = manipulator_value_from_offset(data, inter, ofs_new, constrained, inverted, use_precision);
 
-		manipulator_property_value_set(C, mpr, mpr_prop, value);
+		WM_manipulator_property_value_set(C, mpr, mpr_prop, value);
 		/* get clamped value */
-		value = manipulator_property_value_get(mpr, mpr_prop);
+		value = WM_manipulator_property_value_get(mpr, mpr_prop);
 
 		data->offset = manipulator_offset_from_value(data, value, constrained, inverted);
 	}
@@ -373,11 +373,11 @@ static void manipulator_arrow_invoke(
 {
 	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
 	ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
-	wmManipulatorProperty *mpr_prop = WM_manipulator_get_property(mpr, "offset");
+	wmManipulatorProperty *mpr_prop = WM_manipulator_property_find(mpr, "offset");
 
 	/* Some manipulators don't use properties. */
-	if (mpr_prop && mpr_prop->prop) {
-		inter->init_value = RNA_property_float_get(&mpr_prop->ptr, mpr_prop->prop);
+	if (mpr_prop && WM_manipulator_property_is_valid(mpr_prop)) {
+		inter->init_value = WM_manipulator_property_value_get(mpr, mpr_prop);
 	}
 
 	inter->init_offset = arrow->data.offset;
@@ -410,7 +410,7 @@ static void manipulator_arrow_exit(bContext *C, wmManipulator *mpr, const bool c
 	ManipulatorCommonData *data = &arrow->data;
 	ManipulatorInteraction *inter = mpr->interaction_data;
 
-	wmManipulatorProperty *mpr_prop = WM_manipulator_get_property(mpr, "offset");
+	wmManipulatorProperty *mpr_prop = WM_manipulator_property_find(mpr, "offset");
 	manipulator_property_value_reset(C, mpr, inter, mpr_prop);
 	data->offset = inter->init_offset;
 }
@@ -485,15 +485,15 @@ void ED_manipulator_arrow3d_set_line_len(wmManipulator *mpr, const float len)
 /**
  * Define a custom property UI range
  *
- * \note Needs to be called before WM_manipulator_def_property!
+ * \note Needs to be called before WM_manipulator_property_def_rna!
  */
 void ED_manipulator_arrow3d_set_ui_range(wmManipulator *mpr, const float min, const float max)
 {
 	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
 
 	BLI_assert(min < max);
-	BLI_assert(!(WM_manipulator_get_property(mpr, "offset") && "Make sure this function "
-	           "is called before WM_manipulator_def_property"));
+	BLI_assert(!(WM_manipulator_property_find(mpr, "offset") && "Make sure this function "
+	           "is called before WM_manipulator_property_def_rna"));
 
 	arrow->data.range = max - min;
 	arrow->data.min = min;
@@ -503,13 +503,13 @@ void ED_manipulator_arrow3d_set_ui_range(wmManipulator *mpr, const float min, co
 /**
  * Define a custom factor for arrow min/max distance
  *
- * \note Needs to be called before WM_manipulator_def_property!
+ * \note Needs to be called before WM_manipulator_property_def_rna!
  */
 void ED_manipulator_arrow3d_set_range_fac(wmManipulator *mpr, const float range_fac)
 {
 	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
-	BLI_assert(!(WM_manipulator_get_property(mpr, "offset") && "Make sure this function "
-	           "is called before WM_manipulator_def_property"));
+	BLI_assert(!(WM_manipulator_property_find(mpr, "offset") && "Make sure this function "
+	           "is called before WM_manipulator_property_def_rna"));
 
 	arrow->data.range_fac = range_fac;
 }
diff --git a/source/blender/editors/manipulator_library/cage2d_manipulator.c b/source/blender/editors/manipulator_library/cage2d_manipulator.c
index 0f45db8b9ef..3a2bfdad406 100644
--- a/source/blender/editors/manipulator_library/cage2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/cage2d_manipulator.c
@@ -486,13 +486,13 @@ static void manipulator_rect_transform_modal(
 
 	wmManipulatorProperty *mpr_prop;
 
-	mpr_prop = WM_manipulator_get_property(mpr, "offset");
+	mpr_prop = WM_manipulator_property_find(mpr, "offset");
 	if (mpr_prop->prop != NULL) {
 		RNA_property_float_set_array(&mpr_prop->ptr, mpr_prop->prop, mpr->offset);
 		RNA_property_update(C, &mpr_prop->ptr, mpr_prop->prop);
 	}
 
-	mpr_prop = WM_manipulator_get_property(mpr, "scale");
+	mpr_prop = WM_manipulator_property_find(mpr, "scale");
 	if (mpr_prop->prop != NULL) {
 		if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) {
 			RNA_property_float_set(&mpr_prop->ptr, mpr_prop->prop, cage->scale[0]);
@@ -533,13 +533,13 @@ static void manipulator_rect_transform_exit(bContext *C, wmManipulator *mpr, con
 	wmManipulatorProperty *mpr_prop;
 
 	/* reset properties */
-	mpr_prop = WM_manipulator_get_property(mpr, "offset");
+	mpr_prop = WM_manipulator_property_find(mpr, "offset");
 	if (mpr_prop->prop != NULL) {
 		RNA_property_float_set_array(&mpr_prop->ptr, mpr_prop->prop, data->orig_offset);
 		RNA_property_update(C, &mpr_prop->ptr, mpr_prop->prop);
 	}
 
-	mpr_prop = WM_manipulator_get_property(mpr, "scale");
+	mpr_prop = WM_manipulator_property_find(mpr, "scale");
 	if (mpr_prop->prop != NULL) {
 		if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) {
 			RNA_property_float_set(&mpr_prop->ptr, mpr_prop->prop, data->orig_scale[0]);
diff --git a/source/blender/editors/manipulator_library/manipulator_library_intern.h b/source/blender/editors/manipulator_library/manipulator_library_intern.h
index 8a187f5f9ba..74060cba59c 100644
--- a/source/blender/editors/manipulator_library/manipulator_library_intern.h
+++ b/source/blender/editors/manipulator_library/manipulator_library_intern.h
@@ -79,10 +79,6 @@ void manipulator_property_data_update(
         struct wmManipulator *mnp, ManipulatorCommonData *data, wmManipulatorProperty *mpr_prop,
         const bool constrained, const bool inverted);
 
-void  manipulator_property_value_set(
-        bContext *C, const struct wmManipulator *mnp, wmManipulatorProperty *mpr_prop, const float value);
-float manipulator_property_value_get(
-        const struct wmManipulator *mnp, wmManipulatorProperty *mpr_prop);
 void  manipulator_property_value_reset(
         bContext *C, const struct wmManipulator *mnp, ManipulatorInteraction *inter, wmManipulatorProperty *mpr_prop);
 
diff --git a/source/blender/editors/manipulator_library/manipulator_library_utils.c b/source/blender/editors/manipulator_library/manipulator_library_utils.c
index be437c0acc1..d7da66f97b5 100644
--- a/source/blender/editors/manipulator_library/manipulator_library_utils.c
+++ b/source/blender/editors/manipulator_library/manipulator_library_utils.c
@@ -105,20 +105,25 @@ void manipulator_property_data_update(
         wmManipulator *mpr, ManipulatorCommonData *data, wmManipulatorProperty *mpr_prop,
         const bool constrained, const bool inverted)
 {
-	if (mpr_prop->prop == NULL) {
+	if (mpr_prop->custom_func.value_get_fn != NULL) {
+		/* pass  */
+	}
+	else if (mpr_prop->prop != NULL) {
+		/* pass  */
+	}
+	else {
 		data->offset = 0.0f;
 		return;
 	}
 
-	float value = manipulator_property_value_get(mpr, mpr_prop);
+	float value = WM_manipulator_property_value_get(mpr, mpr_prop);
 
 	if (constrained) {
 		if ((data->flag & MANIPULATOR_CUSTOM_RANGE_SET) == 0) {
-			float step, precision;
-			float min, max;
-			RNA_property_float_ui_range(&mpr_prop->ptr, mpr_prop->prop, &min, &max, &step, &precision);
-			data->range = max - min;
-			data->min = min;
+			float range[2];
+			WM_manipulator_property_range_get(mpr, mpr_prop, range);
+			data->range = range[1] - range[0];
+			data->min = range[0];
 		}
 		data->offset = manipulator_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted);
 	}
@@ -127,40 +132,13 @@ void manipulator_property_data_update(
 	}
 }
 
-void manipulator_property_value_set(
-        bContext *C, const wmManipulator *UNUSED(mnp),
-        wmManipulatorProperty *mpr_prop, const float value)
-{
-	/* reset property */
-	if (mpr_prop->index == -1) {
-		RNA_property_float_set(&mpr_prop->ptr, mpr_prop->prop, value);
-	}
-	else {
-		RNA_property_float_set_index(&mpr_prop->ptr, mpr_prop->prop, mpr_prop->index, value);
-	}
-	RNA_property_update(C, &mpr_prop->ptr, mpr_prop->prop);
-}
-
-float manipulator_property_value_get(
-        const wmManipulator *UNUSED(mnp),
-        wmManipulatorProperty *mpr_prop)
-{
-	if (mpr_prop->index == -1) {
-		return RNA_property_float_get(&mpr_prop->ptr, mpr_prop->prop);
-	}
-	else {
-		return RNA_property_float_get_index(&mpr_prop->ptr, mpr_prop->prop, mpr_prop->index);
-	}
-}
-
 void manipulator_property_value_reset(
         bContext *C, const wmManipulator *mnp, ManipulatorInteraction *inter,
         wmManipulatorProperty *mpr_prop)
 {
-	manipulator_property_value_set(C, mnp, mpr_prop, inter->init_value);
+	WM_manipulator_property_value_set(C, mnp, mpr_prop, inter->init_value);
 }
 
-
 /* ----------------------------------------------------------

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list