[Bf-blender-cvs] [870b4b67351] master: WM: refactor gestures for use as tools

Campbell Barton noreply at git.blender.org
Mon Oct 16 13:20:15 CEST 2017


Commit: 870b4b673511094cf0beaeaf07305407ccdda47a
Author: Campbell Barton
Date:   Mon Oct 16 21:58:51 2017 +1100
Branches: master
https://developer.blender.org/rB870b4b673511094cf0beaeaf07305407ccdda47a

WM: refactor gestures for use as tools

Border and circle select wait for input by default.
This commit uses bool properties on the operators instead of
magic number (called "gesture_mode").

Keymaps that define 'deselect' for border/circle select
begin immediately, exiting when on button release.

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

M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/mask/mask_select.c
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/space_action/action_select.c
M	source/blender/editors/space_clip/clip_graph_ops.c
M	source/blender/editors/space_clip/tracking_select.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_graph/graph_select.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_info/info_report.c
M	source/blender/editors/space_nla/nla_select.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/node_select.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_sequencer/sequencer_select.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_gesture.c
M	source/blender/windowmanager/intern/wm_operator_props.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/wm_event_types.h

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

diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index da7b6b085c0..fc0c39e6295 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -2455,8 +2455,8 @@ static int animchannels_borderselect_exec(bContext *C, wmOperator *op)
 	bAnimContext ac;
 	rcti rect;
 	short selectmode = 0;
-	int gesture_mode;
-	bool extend;
+	const bool select = !RNA_boolean_get(op->ptr, "deselect");
+	const bool extend = RNA_boolean_get(op->ptr, "extend");
 	
 	/* get editor data */
 	if (ANIM_animdata_get_context(C, &ac) == 0)
@@ -2464,17 +2464,17 @@ static int animchannels_borderselect_exec(bContext *C, wmOperator *op)
 	
 	/* get settings from operator */
 	WM_operator_properties_border_to_rcti(op, &rect);
-	
-	gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
-	extend = RNA_boolean_get(op->ptr, "extend");
 
-	if (!extend)
+	if (!extend) {
 		ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, true, ACHANNEL_SETFLAG_CLEAR);
+	}
 
-	if (gesture_mode == GESTURE_MODAL_SELECT)
+	if (select) {
 		selectmode = ACHANNEL_SETFLAG_ADD;
-	else
+	}
+	else {
 		selectmode = ACHANNEL_SETFLAG_CLEAR;
+	}
 	
 	/* apply borderselect animation channels */
 	borderselect_anim_channels(&ac, &rect, selectmode);
@@ -2504,7 +2504,7 @@ static void ANIM_OT_channels_select_border(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 	
 	/* rna */
-	WM_operator_properties_gesture_border(ot, true);
+	WM_operator_properties_gesture_border_select(ot);
 }
 
 /* ******************* Rename Operator ***************************** */
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index 926a41dd7ab..30aaee8cbd9 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -1230,7 +1230,7 @@ static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
 	View2D *v2d = UI_view2d_fromcontext(C);
 	ListBase *markers = ED_context_get_markers(C);
 	TimeMarker *marker;
-	int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
+	bool select = !RNA_boolean_get(op->ptr, "deselect");
 	bool extend = RNA_boolean_get(op->ptr, "extend");
 	rctf rect;
 	
@@ -1243,13 +1243,11 @@ static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
 	/* XXX marker context */
 	for (marker = markers->first; marker; marker = marker->next) {
 		if (BLI_rctf_isect_x(&rect, marker->frame)) {
-			switch (gesture_mode) {
-				case GESTURE_MODAL_SELECT:
-					marker->flag |= SELECT;
-					break;
-				case GESTURE_MODAL_DESELECT:
-					marker->flag &= ~SELECT;
-					break;
+			if (select) {
+				marker->flag |= SELECT;
+			}
+			else {
+				marker->flag &= ~SELECT;
 			}
 		}
 		else if (!extend) {
@@ -1287,7 +1285,7 @@ static void MARKER_OT_select_border(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 	
 	/* rna */
-	WM_operator_properties_gesture_border(ot, true);
+	WM_operator_properties_gesture_border_select(ot);
 }
 
 /* *********************** (de)select all ***************** */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index bea78156900..3d9689ab54f 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -769,8 +769,7 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
 	const int my = RNA_int_get(op->ptr, "y");
 	const int radius = RNA_int_get(op->ptr, "radius");
 	
-	const int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
-	const bool select = (gesture_mode == GESTURE_MODAL_SELECT);
+	bool select = !RNA_boolean_get(op->ptr, "deselect");
 	
 	GP_SpaceConversion gsc = {NULL};
 	rcti rect = {0};            /* for bounding rect around circle (for quicky intersection testing) */
@@ -830,7 +829,7 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 	
 	/* properties */
-	WM_operator_properties_gesture_circle(ot);
+	WM_operator_properties_gesture_circle_select(ot);
 }
 
 /* ********************************************** */
@@ -840,8 +839,7 @@ static int gpencil_border_select_exec(bContext *C, wmOperator *op)
 {
 	ScrArea *sa = CTX_wm_area(C);
 	
-	const int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
-	const bool select = (gesture_mode == GESTURE_MODAL_SELECT);
+	const bool select = !RNA_boolean_get(op->ptr, "deselect");
 	const bool extend = RNA_boolean_get(op->ptr, "extend");
 	
 	GP_SpaceConversion gsc = {NULL};
@@ -944,7 +942,7 @@ void GPENCIL_OT_select_border(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 	
 	/* rna */
-	WM_operator_properties_gesture_border(ot, true);
+	WM_operator_properties_gesture_border_select(ot);
 }
 
 /* ********************************************** */
@@ -1054,7 +1052,7 @@ void GPENCIL_OT_select_lasso(wmOperatorType *ot)
 	ot->flag = OPTYPE_UNDO;
 	
 	/* properties */
-	WM_operator_properties_gesture_lasso(ot);
+	WM_operator_properties_gesture_lasso_select(ot);
 }
 
 /* ********************************************** */
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index ab8ec60696b..b271b0b5bc6 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1223,7 +1223,6 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
 	View2D *v2d = &ar->v2d;
 	rctf rect;
 	rctf cur_new = v2d->cur;
-	int gesture_mode;
 	const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
 	
 	/* convert coordinates of rect to 'tot' rect coordinates */
@@ -1231,9 +1230,9 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
 	UI_view2d_region_to_view_rctf(v2d, &rect, &rect);
 	
 	/* check if zooming in/out view */
-	gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
+	const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
 	
-	if (gesture_mode == GESTURE_MODAL_IN) {
+	if (zoom_in) {
 		/* zoom in: 
 		 *	- 'cur' rect will be defined by the coordinates of the border region 
 		 *	- just set the 'cur' rect to have the same coordinates as the border region
@@ -1248,8 +1247,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
 			cur_new.ymax = rect.ymax;
 		}
 	}
-	else { /* if (gesture_mode == GESTURE_MODAL_OUT) */
-
+	else {
 		/* zoom out:
 		 *	- the current 'cur' rect coordinates are going to end up where the 'rect' ones are,
 		 *	  but the 'cur' rect coordinates will need to be adjusted to take in more of the view
@@ -1297,7 +1295,7 @@ static void VIEW2D_OT_zoom_border(wmOperatorType *ot)
 	ot->poll = view_zoom_poll;
 	
 	/* rna */
-	WM_operator_properties_gesture_border(ot, false);
+	WM_operator_properties_gesture_border_zoom(ot);
 }
 
 #ifdef WITH_INPUT_NDOF
@@ -1545,7 +1543,7 @@ static void VIEW2D_OT_smoothview(wmOperatorType *ot)
 	ot->flag = OPTYPE_INTERNAL;
 
 	/* rna */
-	WM_operator_properties_gesture_border(ot, false);
+	WM_operator_properties_gesture_border(ot);
 }
 
 /* ********************************************************* */
diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c
index 543b005236a..9f2f6de8a09 100644
--- a/source/blender/editors/mask/mask_select.c
+++ b/source/blender/editors/mask/mask_select.c
@@ -408,8 +408,9 @@ static int border_select_exec(bContext *C, wmOperator *op)
 
 	rcti rect;
 	rctf rectf;
-	int mode;
-	bool changed = false, extend;
+	bool changed = false;
+	const bool select = !RNA_boolean_get(op->ptr, "deselect");
+	const bool extend = RNA_boolean_get(op->ptr, "extend");
 
 	/* get rectangle from operator */
 	WM_operator_properties_border_to_rcti(op, &rect);
@@ -417,9 +418,6 @@ static int border_select_exec(bContext *C, wmOperator *op)
 	ED_mask_point_pos(sa, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
 	ED_mask_point_pos(sa, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
 
-	mode = RNA_int_get(op->ptr, "gesture_mode");
-	extend = RNA_boolean_get(op->ptr, "extend");
-
 	/* do actual selection */
 	for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
 		MaskSpline *spline;
@@ -439,8 +437,8 @@ static int border_select_exec(bContext *C, wmOperator *op)
 				/* TODO: uw? */
 
 				if (BLI_rctf_isect_pt_v(&rectf, point_deform->bezt.vec[1])) {
-					BKE_mask_point_select_set(point, mode == GESTURE_MODAL_SELECT);
-					BKE_mask_point_select_set_handle(point, MASK_WHICH_HANDLE_BOTH, mode == GESTURE_MODAL_SELECT);
+					BKE_mask_point_select_set(point, select);
+					BKE_mask_point_select_set_handle(point, MASK_WHICH_HANDLE_BOTH, select);
 				}
 				else if (!extend) {
 					BKE_mask_point_select_set(point, false);
@@ -480,7 +478,7 @@ void MASK_OT_select_border(wmOperatorType *ot)
 	ot->flag = OPTYPE_UNDO;
 
 	/* properties */
-	WM_operator_properties_gesture_border(ot, true);
+	WM_operator_properties_gesture_border_select(ot);
 }
 
 static bool do_lasso_select_mask(bContext *C, const int mcords[][2], short moves, short select)
@@ -580,7 +578,7 @@ void MASK_OT_select_lasso(wmOperatorType *ot)
 	ot->flag = OPTYPE_UNDO;
 
 	/* properties */
-	WM_operator_properties_gesture_lasso(ot);
+	WM_operator_properties_gesture_lasso_select(ot);
 }
 
 /********************** circle select operator *********************/
@@ -606,15 +604,15 @@ static int circle_select_exec(bContext *C, wmOperator *op)
 	int i;
 
 	float zoomx, zoomy, offset[2], ellipse[2];
-	int x, y, radius, width, height, mode;
+	int width, height;
 	bool changed = false;
 
 	/* get operator properties */
-	x = RNA_int_get(op->ptr, "x");
-	y = RNA_int_get(op->ptr, "y");
-	radius = RNA_int_get(op->ptr, "radius");
+	const int x = RNA_int_get(op->ptr, "x");
+	const int y = RNA_int_get(op->ptr, "y");
+	const int radius = RNA_int_get(op->ptr, "radius");
 
-	mode = RNA_int_get(op->ptr, "gesture_mode");
+	const bool select = !RNA_boolean_get(op->ptr, "deselect");
 
 	/* compute ellipse and position in unified coordinates */
 	ED_mask_get_size(sa, &width, &height);
@@ -642,8 +640,8 @@ static int circle_select_exec(bContext *C, wmOperator *op)
 				MaskSplinePoint *point_d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list