UI: Allow changing the active side of line gestures

Line gesture use always the right side of the line as active (the area
of the mesh that is going to be modified) by default.
This adds the ability to change the active side when the line gesture is
active by pressing the F key.
This allows more freedom to position the line after starting the
gestures, as it won't be required to cancel the operation or undo if the
line was used in the wrong direction.

Reviewed By: Severin

Differential Revision: https://developer.blender.org/D9301
This commit is contained in:
Pablo Dobarro 2020-10-21 17:44:00 +02:00
parent 15cebd8565
commit 9216b8d6cb
8 changed files with 36 additions and 3 deletions

@ -5135,6 +5135,7 @@ def km_gesture_straight_line(_params):
("SELECT", {"type": 'LEFTMOUSE', "value": 'RELEASE', "any": True}, None),
("MOVE", {"type": 'SPACE', "value": 'ANY', "repeat": False, "any": True}, None),
("SNAP", {"type": 'LEFT_CTRL', "value": 'ANY', "any": True, "repeat": False}, None),
("FLIP", {"type": 'F', "value": 'PRESS', "any": True, "repeat": False}, None),
])
return keymap

@ -248,6 +248,7 @@ typedef struct LassoGestureData {
typedef struct LineGestureData {
float true_plane[4];
float plane[4];
bool flip;
} LineGestureData;
struct SculptGestureOperation;
@ -461,6 +462,8 @@ static SculptGestureContext *sculpt_gesture_init_from_line(bContext *C, wmOperat
line_points[1][0] = RNA_int_get(op->ptr, "xend");
line_points[1][1] = RNA_int_get(op->ptr, "yend");
sgcontext->line.flip = RNA_boolean_get(op->ptr, "flip");
float depth_point[3];
float plane_points[3][3];
@ -481,6 +484,12 @@ static SculptGestureContext *sculpt_gesture_init_from_line(bContext *C, wmOperat
if (!sgcontext->vc.rv3d->is_persp) {
mul_v3_fl(normal, -1.0f);
}
/* Apply flip. */
if (sgcontext->line.flip) {
mul_v3_fl(normal, -1.0f);
}
mul_v3_mat3_m4v3(normal, sgcontext->vc.obact->imat, normal);
float plane_point_object_space[3];
mul_v3_m4v3(plane_point_object_space, sgcontext->vc.obact->imat, plane_points[0]);

@ -503,6 +503,9 @@ typedef struct wmGesture {
/** For gestures that support snapping, stores if snapping is enabled using the modal keymap
* toggle. */
uint use_snap : 1;
/** For gestures that support flip, stores if flip is enabled using the modal keymap
* toggle. */
uint use_flip : 1;
/**
* customdata

@ -200,7 +200,7 @@ int wm_gesture_evaluate(wmGesture *gesture, const wmEvent *event)
/* ******************* gesture draw ******************* */
static void wm_gesture_draw_line_active_side(rcti *rect)
static void wm_gesture_draw_line_active_side(rcti *rect, const bool flip)
{
GPUVertFormat *format = immVertexFormat();
uint shdr_pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
@ -222,7 +222,9 @@ static void wm_gesture_draw_line_active_side(rcti *rect)
sub_v2_v2v2(line_dir, line_end, line_start);
normalize_v2(line_dir);
ortho_v2_v2(gradient_dir, line_dir);
mul_v2_fl(gradient_dir, -1.0f);
if (!flip) {
mul_v2_fl(gradient_dir, -1.0f);
}
mul_v2_fl(gradient_dir, gradient_length);
add_v2_v2v2(gradient_point[0], line_start, gradient_dir);
add_v2_v2v2(gradient_point[1], line_end, gradient_dir);
@ -252,7 +254,7 @@ static void wm_gesture_draw_line(wmGesture *gt)
rcti *rect = (rcti *)gt->customdata;
if (gt->draw_active_side) {
wm_gesture_draw_line_active_side(rect);
wm_gesture_draw_line_active_side(rect, gt->use_flip);
}
uint shdr_pos = GPU_vertformat_attr_add(

@ -851,6 +851,7 @@ static bool gesture_straightline_apply(bContext *C, wmOperator *op)
RNA_int_set(op->ptr, "ystart", rect->ymin);
RNA_int_set(op->ptr, "xend", rect->xmax);
RNA_int_set(op->ptr, "yend", rect->ymax);
RNA_boolean_set(op->ptr, "flip", gesture->use_flip);
if (op->type->exec) {
int retval = op->type->exec(C, op);
@ -892,6 +893,7 @@ int WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, cons
WM_gesture_straightline_invoke(C, op, event);
wmGesture *gesture = op->customdata;
gesture->draw_active_side = true;
gesture->use_flip = false;
return OPERATOR_RUNNING_MODAL;
}
@ -950,6 +952,11 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev
gesture->use_snap = !gesture->use_snap;
break;
}
case GESTURE_MODAL_FLIP: {
/* Toggle snapping on/off. */
gesture->use_flip = !gesture->use_flip;
break;
}
case GESTURE_MODAL_SELECT: {
if (gesture_straightline_apply(C, op)) {
gesture_modal_end(C, op);
@ -1029,6 +1036,11 @@ int WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmE
gesture->use_snap = !gesture->use_snap;
break;
}
case GESTURE_MODAL_FLIP: {
/* Toggle flip on/off. */
gesture->use_flip = !gesture->use_flip;
break;
}
case GESTURE_MODAL_SELECT:
case GESTURE_MODAL_DESELECT:
case GESTURE_MODAL_IN:

@ -498,6 +498,8 @@ void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_int(ot->srna, "yend", 0, INT_MIN, INT_MAX, "Y End", "", INT_MIN, INT_MAX);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_boolean(ot->srna, "flip", false, "Flip", "");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
if (cursor) {
prop = RNA_def_int(ot->srna,

@ -3807,6 +3807,7 @@ static void gesture_straightline_modal_keymap(wmKeyConfig *keyconf)
{GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
{GESTURE_MODAL_MOVE, "MOVE", 0, "Move", ""},
{GESTURE_MODAL_SNAP, "SNAP", 0, "Snap", ""},
{GESTURE_MODAL_FLIP, "FLIP", 0, "Flip", ""},
{0, NULL, 0, NULL, NULL},
};

@ -496,6 +496,9 @@ enum {
/** Toggle to activate snapping (angle snapping for straight line). */
GESTURE_MODAL_SNAP = 13,
/** Toggle to activate flip (flip the active side of a straight line). */
GESTURE_MODAL_FLIP = 14,
};
#ifdef __cplusplus