diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2020-10-05 18:19:28 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-10-05 20:35:11 +0300 |
commit | 628dc91c485afd45881e3df03c5005c92791e5ad (patch) | |
tree | c025eab7bddb8c8717addeb2fdf35e77ea2ef003 /source/blender/windowmanager/intern/wm_gesture.c | |
parent | ca38bce46aa292654451fa34fc33b88fc5ca72f0 (diff) |
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
Diffstat (limited to 'source/blender/windowmanager/intern/wm_gesture.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index b245bbe054d..6d36000abb4 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -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); |