Sculpt: Preview the active side of the line gestures
This adds a small gradient to the right side of the line to preview which side of the mesh is going to be affected by the gesture operation. Reviewed By: Severin Differential Revision: https://developer.blender.org/D9106
This commit is contained in:
parent
ca38bce46a
commit
628dc91c48
|
@ -1419,7 +1419,7 @@ void PAINT_OT_mask_line_gesture(wmOperatorType *ot)
|
|||
ot->idname = "PAINT_OT_mask_line_gesture";
|
||||
ot->description = "Add mask to the right of a line as you move the brush";
|
||||
|
||||
ot->invoke = WM_gesture_straightline_invoke;
|
||||
ot->invoke = WM_gesture_straightline_active_side_invoke;
|
||||
ot->modal = WM_gesture_straightline_oneshot_modal;
|
||||
ot->exec = paint_mask_gesture_line_exec;
|
||||
|
||||
|
@ -1516,7 +1516,7 @@ void SCULPT_OT_project_line_gesture(wmOperatorType *ot)
|
|||
ot->idname = "SCULPT_OT_project_line_gesture";
|
||||
ot->description = "Project the geometry onto a plane defined by a line";
|
||||
|
||||
ot->invoke = WM_gesture_straightline_invoke;
|
||||
ot->invoke = WM_gesture_straightline_active_side_invoke;
|
||||
ot->modal = WM_gesture_straightline_oneshot_modal;
|
||||
ot->exec = project_gesture_line_exec;
|
||||
|
||||
|
|
|
@ -636,6 +636,9 @@ const int (*WM_gesture_lasso_path_to_array(struct bContext *C,
|
|||
int WM_gesture_straightline_invoke(struct bContext *C,
|
||||
struct wmOperator *op,
|
||||
const struct wmEvent *event);
|
||||
int WM_gesture_straightline_active_side_invoke(struct bContext *C,
|
||||
struct wmOperator *op,
|
||||
const struct wmEvent *event);
|
||||
int WM_gesture_straightline_modal(struct bContext *C,
|
||||
struct wmOperator *op,
|
||||
const struct wmEvent *event);
|
||||
|
|
|
@ -485,6 +485,8 @@ typedef struct wmGesture {
|
|||
/** optional, maximum amount of points stored. */
|
||||
int points_alloc;
|
||||
int modal_state;
|
||||
/** optional, draw the active side of the straightline gesture. */
|
||||
bool draw_active_side;
|
||||
|
||||
/**
|
||||
* For modal operators which may be running idle, waiting for an event to activate the gesture.
|
||||
|
|
|
@ -199,10 +199,61 @@ int wm_gesture_evaluate(wmGesture *gesture, const wmEvent *event)
|
|||
|
||||
/* ******************* gesture draw ******************* */
|
||||
|
||||
static void wm_gesture_draw_line_active_side(rcti *rect)
|
||||
{
|
||||
GPUVertFormat *format = immVertexFormat();
|
||||
uint shdr_pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
uint shdr_col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
||||
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
|
||||
|
||||
const float gradient_length = 150.0f * U.pixelsize;
|
||||
float line_dir[2];
|
||||
float gradient_dir[2];
|
||||
float gradient_point[2][2];
|
||||
|
||||
const float line_start[2] = {rect->xmin, rect->ymin};
|
||||
const float line_end[2] = {rect->xmax, rect->ymax};
|
||||
const float color_line_gradient_start[4] = {0.2f, 0.2f, 0.2f, 0.4f};
|
||||
const float color_line_gradient_end[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
immBegin(GPU_PRIM_TRIS, 6);
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_start));
|
||||
immVertex2f(shdr_pos, line_start[0], line_start[1]);
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_start));
|
||||
immVertex2f(shdr_pos, line_end[0], line_end[1]);
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_end));
|
||||
immVertex2f(shdr_pos, gradient_point[1][0], gradient_point[1][1]);
|
||||
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_start));
|
||||
immVertex2f(shdr_pos, line_start[0], line_start[1]);
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_end));
|
||||
immVertex2f(shdr_pos, gradient_point[1][0], gradient_point[1][1]);
|
||||
immAttr4f(shdr_col, UNPACK4(color_line_gradient_end));
|
||||
immVertex2f(shdr_pos, gradient_point[0][0], gradient_point[0][1]);
|
||||
immEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
uint shdr_pos = GPU_vertformat_attr_add(
|
||||
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
|
||||
|
|
|
@ -849,6 +849,17 @@ int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *e
|
|||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
/**
|
||||
* This invoke callback starts the straightline gesture with a viewport preview to the right side
|
||||
* of the line.
|
||||
*/
|
||||
int WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
WM_gesture_straightline_invoke(C, op, event);
|
||||
wmGesture *gesture = op->customdata;
|
||||
gesture->draw_active_side = true;
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This modal callback calls exec once per mouse move event while the gesture is active with the
|
||||
|
|
Loading…
Reference in New Issue