[Bf-blender-cvs] [c3e588455a3] custom-manipulators: Dial manipulator didn't have a modal callback

Campbell Barton noreply at git.blender.org
Thu Jun 15 12:17:38 CEST 2017


Commit: c3e588455a3bd406bb426fa7c01952f443a0deec
Author: Campbell Barton
Date:   Thu Jun 15 20:05:02 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rBc3e588455a3bd406bb426fa7c01952f443a0deec

Dial manipulator didn't have a modal callback

Until 3d-viewport manipulators change functionality we need to it
working how it already is.

So add modal operator which is called from draw when there are no
properties applied to the manipulator.

This will be needed to have a general rotation manipulator.

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

M	source/blender/editors/manipulator_library/dial3d_manipulator.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
M	source/blender/windowmanager/manipulators/wm_manipulator_fn.h

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

diff --git a/source/blender/editors/manipulator_library/dial3d_manipulator.c b/source/blender/editors/manipulator_library/dial3d_manipulator.c
index 7c26beafaac..1db87ac9a3d 100644
--- a/source/blender/editors/manipulator_library/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/dial3d_manipulator.c
@@ -64,6 +64,8 @@
 /* to use custom dials exported to geom_dial_manipulator.c */
 // #define USE_MANIPULATOR_CUSTOM_DIAL
 
+static void manipulator_dial_modal(bContext *C, wmManipulator *mpr, const wmEvent *event, const int flag);
+
 typedef struct DialManipulator {
 	wmManipulator manipulator;
 	int style;
@@ -77,11 +79,29 @@ typedef struct DialInteraction {
 	float last_angle;
 	/* number of full rotations */
 	int rotations;
+
+	/* final output values, used for drawing */
+	struct {
+		float angle_ofs;
+		float angle_delta;
+	} output;
 } DialInteraction;
 
 #define DIAL_WIDTH       1.0f
 #define DIAL_RESOLUTION 32
 
+
+static void dial_calc_matrix(const DialManipulator *dial, float mat[4][4])
+{
+	float rot[3][3];
+	const float up[3] = {0.0f, 0.0f, 1.0f};
+
+	rotation_between_vecs_to_mat3(rot, up, dial->direction);
+	copy_m4_m3(mat, rot);
+	copy_v3_v3(mat[3], dial->manipulator.origin);
+	mul_mat3_m4_fl(mat, dial->manipulator.scale);
+}
+
 /* -------------------------------------------------------------------- */
 
 static void dial_geom_draw(
@@ -219,31 +239,36 @@ static void dial_draw_intern(
         const bContext *C, DialManipulator *dial,
         const bool select, const bool highlight, float clip_plane[4])
 {
-	float rot[3][3];
 	float mat[4][4];
-	const float up[3] = {0.0f, 0.0f, 1.0f};
 	float col[4];
 
 	BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
 
 	manipulator_color_get(&dial->manipulator, highlight, col);
 
-	rotation_between_vecs_to_mat3(rot, up, dial->direction);
-	copy_m4_m3(mat, rot);
-	copy_v3_v3(mat[3], dial->manipulator.origin);
-	mul_mat3_m4_fl(mat, dial->manipulator.scale);
+	dial_calc_matrix(dial, mat);
 
 	gpuPushMatrix();
 	gpuMultMatrix(mat);
 	gpuTranslate3fv(dial->manipulator.offset);
 
 	/* draw rotation indicator arc first */
-	if ((dial->manipulator.flag & WM_MANIPULATOR_DRAW_VALUE) && (dial->manipulator.state & WM_MANIPULATOR_STATE_ACTIVE)) {
-		wmWindow *win = CTX_wm_window(C);
+	if ((dial->manipulator.flag & WM_MANIPULATOR_DRAW_VALUE) &&
+	    (dial->manipulator.state & WM_MANIPULATOR_STATE_ACTIVE))
+	{
 		const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; /* coordinate at which the arc drawing will be started */
-		float angle_ofs, angle_delta;
 
-		dial_ghostarc_get_angles(dial, win->eventstate, CTX_wm_region(C), mat, co_outer, &angle_ofs, &angle_delta);
+		DialInteraction *inter = dial->manipulator.interaction_data;
+
+		/* XXX, View3D rotation manipulator doesn't call modal. */
+		if (dial->manipulator.properties.first == NULL) {
+			wmWindow *win = CTX_wm_window(C);
+			manipulator_dial_modal((bContext *)C, &dial->manipulator, win->eventstate, 0);
+		}
+
+		const float angle_ofs = inter->output.angle_ofs;
+		const float angle_delta = inter->output.angle_delta;
+
 		/* draw! */
 		dial_ghostarc_draw(dial, angle_ofs, angle_delta, (const float [4]){0.8f, 0.8f, 0.8f, 0.4f});
 
@@ -310,6 +335,23 @@ static void manipulator_dial_draw(const bContext *C, wmManipulator *mpr)
 	}
 }
 
+static void manipulator_dial_modal(bContext *C, wmManipulator *mpr, const wmEvent *event, const int UNUSED(flag))
+{
+	DialManipulator *dial = (DialManipulator *)mpr;
+	const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; /* coordinate at which the arc drawing will be started */
+	float angle_ofs, angle_delta;
+
+	float mat[4][4];
+
+	dial_calc_matrix(dial, mat);
+
+	dial_ghostarc_get_angles(dial, event, CTX_wm_region(C), mat, co_outer, &angle_ofs, &angle_delta);
+
+	DialInteraction *inter = dial->manipulator.interaction_data;
+	inter->output.angle_delta = angle_delta;
+	inter->output.angle_ofs = angle_ofs;
+}
+
 static void manipulator_dial_invoke(
         bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
 {
@@ -362,6 +404,7 @@ static void MANIPULATOR_WT_dial_3d(wmManipulatorType *wt)
 	wt->draw = manipulator_dial_draw;
 	wt->draw_select = manipulator_dial_draw_select;
 	wt->invoke = manipulator_dial_invoke;
+	wt->modal = manipulator_dial_modal;
 
 	wt->struct_size = sizeof(DialManipulator);
 }
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
index 5ec3c3169eb..5a8eb1d68dc 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
@@ -102,7 +102,6 @@ void WM_manipulator_property_def_func(
 	mpr_prop->custom_func.value_get_fn = params->value_get_fn;
 	mpr_prop->custom_func.value_set_fn = params->value_set_fn;
 	mpr_prop->custom_func.range_get_fn = params->range_get_fn;
-	mpr_prop->custom_func.context = params->context;
 	mpr_prop->custom_func.user_data = params->user_data;
 
 	if (mpr->type->property_update) {
diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
index f8944e728ab..41e603fc521 100644
--- a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
+++ b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
@@ -71,7 +71,6 @@ typedef struct wmManipulatorPropertyFnParams {
 	wmManipulatorPropertyFnGet value_get_fn;
 	wmManipulatorPropertyFnSet value_set_fn;
 	wmManipulatorPropertyFnRangeGet range_get_fn;
-	const struct bContext *context;
 	void *user_data;
 } wmManipulatorPropertyFnParams;




More information about the Bf-blender-cvs mailing list