Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mask/mask_draw.c
| Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | static void draw_single_handle(const MaskLayer *mask_layer, | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| /* return non-zero if spline is selected */ | /* return non-zero if spline is selected */ | ||||
| static void draw_spline_points(const bContext *C, | static void draw_spline_points(const bContext *C, | ||||
| MaskLayer *mask_layer, | MaskLayer *mask_layer, | ||||
| MaskSpline *spline, | MaskSpline *spline, | ||||
| const char draw_flag, | |||||
| const char draw_type) | const char draw_type) | ||||
| { | { | ||||
| const bool is_spline_sel = (spline->flag & SELECT) && | const bool is_spline_sel = (spline->flag & SELECT) && | ||||
| (mask_layer->visibility_flag & MASK_HIDE_SELECT) == 0; | (mask_layer->visibility_flag & MASK_HIDE_SELECT) == 0; | ||||
| const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0; | |||||
| uchar rgb_spline[4]; | uchar rgb_spline[4]; | ||||
| MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | ||||
| SpaceClip *sc = CTX_wm_space_clip(C); | SpaceClip *sc = CTX_wm_space_clip(C); | ||||
| bool undistort = false; | bool undistort = false; | ||||
| int tot_feather_point; | int tot_feather_point; | ||||
| float(*feather_points)[2], (*fp)[2]; | float(*feather_points)[2], (*fp)[2]; | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | for (int j = 0; j <= point->tot_uw; j++) { | ||||
| fp++; | fp++; | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(feather_points); | MEM_freeN(feather_points); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| if (is_smooth) { | |||||
| GPU_line_smooth(true); | GPU_line_smooth(true); | ||||
| } | |||||
| /* control points */ | /* control points */ | ||||
| INIT_MINMAX2(min, max); | INIT_MINMAX2(min, max); | ||||
| for (int i = 0; i < spline->tot_point; i++) { | for (int i = 0; i < spline->tot_point; i++) { | ||||
| /* watch it! this is intentionally not the deform array, only check for sel */ | /* watch it! this is intentionally not the deform array, only check for sel */ | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| MaskSplinePoint *point_deform = &points_array[i]; | MaskSplinePoint *point_deform = &points_array[i]; | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | for (int i = 0; i < spline->tot_point; i++) { | ||||
| immVertex2fv(pos, vert); | immVertex2fv(pos, vert); | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| minmax_v2v2_v2(min, max, vert); | minmax_v2v2_v2(min, max, vert); | ||||
| } | } | ||||
| if (is_smooth) { | |||||
| GPU_line_smooth(false); | GPU_line_smooth(false); | ||||
| } | |||||
| if (is_spline_sel) { | if (is_spline_sel) { | ||||
| float x = (min[0] + max[0]) * 0.5f; | float x = (min[0] + max[0]) * 0.5f; | ||||
| float y = (min[1] + max[1]) * 0.5f; | float y = (min[1] + max[1]) * 0.5f; | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA); | immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA); | ||||
| immUniform1f("outlineWidth", 1.5f); | immUniform1f("outlineWidth", 1.5f); | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | static void mask_draw_curve_type(const bContext *C, | ||||
| if (points != orig_points) { | if (points != orig_points) { | ||||
| MEM_freeN(points); | MEM_freeN(points); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_spline_curve(const bContext *C, | static void draw_spline_curve(const bContext *C, | ||||
| MaskLayer *mask_layer, | MaskLayer *mask_layer, | ||||
| MaskSpline *spline, | MaskSpline *spline, | ||||
| const char draw_flag, | |||||
| const char draw_type, | const char draw_type, | ||||
| const bool is_active, | const bool is_active, | ||||
| const int width, | const int width, | ||||
| const int height) | const int height) | ||||
| { | { | ||||
| const uint resol = max_ii(BKE_mask_spline_feather_resolution(spline, width, height), | const uint resol = max_ii(BKE_mask_spline_feather_resolution(spline, width, height), | ||||
| BKE_mask_spline_resolution(spline, width, height)); | BKE_mask_spline_resolution(spline, width, height)); | ||||
| uchar rgb_tmp[4]; | uchar rgb_tmp[4]; | ||||
| const bool is_spline_sel = (spline->flag & SELECT) && | const bool is_spline_sel = (spline->flag & SELECT) && | ||||
| (mask_layer->visibility_flag & MASK_HIDE_SELECT) == 0; | (mask_layer->visibility_flag & MASK_HIDE_SELECT) == 0; | ||||
| const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0; | |||||
| const bool is_fill = (spline->flag & MASK_SPLINE_NOFILL) == 0; | const bool is_fill = (spline->flag & MASK_SPLINE_NOFILL) == 0; | ||||
| uint tot_diff_point; | uint tot_diff_point; | ||||
| float(*diff_points)[2]; | float(*diff_points)[2]; | ||||
| uint tot_feather_point; | uint tot_feather_point; | ||||
| float(*feather_points)[2]; | float(*feather_points)[2]; | ||||
| diff_points = BKE_mask_spline_differentiate_with_resolution(spline, resol, &tot_diff_point); | diff_points = BKE_mask_spline_differentiate_with_resolution(spline, resol, &tot_diff_point); | ||||
| if (!diff_points) { | if (!diff_points) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (is_smooth) { | |||||
| GPU_line_smooth(true); | GPU_line_smooth(true); | ||||
| } | |||||
| feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution( | feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution( | ||||
| spline, resol, (is_fill != false), &tot_feather_point); | spline, resol, (is_fill != false), &tot_feather_point); | ||||
| /* draw feather */ | /* draw feather */ | ||||
| mask_spline_feather_color_get(mask_layer, spline, is_spline_sel, rgb_tmp); | mask_spline_feather_color_get(mask_layer, spline, is_spline_sel, rgb_tmp); | ||||
| mask_draw_curve_type( | mask_draw_curve_type( | ||||
| C, spline, feather_points, tot_feather_point, true, is_active, rgb_tmp, draw_type); | C, spline, feather_points, tot_feather_point, true, is_active, rgb_tmp, draw_type); | ||||
| Show All 18 Lines | static void draw_spline_curve(const bContext *C, | ||||
| MEM_freeN(feather_points); | MEM_freeN(feather_points); | ||||
| /* draw main curve */ | /* draw main curve */ | ||||
| mask_spline_color_get(mask_layer, spline, is_spline_sel, rgb_tmp); | mask_spline_color_get(mask_layer, spline, is_spline_sel, rgb_tmp); | ||||
| mask_draw_curve_type( | mask_draw_curve_type( | ||||
| C, spline, diff_points, tot_diff_point, false, is_active, rgb_tmp, draw_type); | C, spline, diff_points, tot_diff_point, false, is_active, rgb_tmp, draw_type); | ||||
| MEM_freeN(diff_points); | MEM_freeN(diff_points); | ||||
| if (is_smooth) { | |||||
| GPU_line_smooth(false); | GPU_line_smooth(false); | ||||
| } | } | ||||
| } | |||||
| static void draw_layer_splines(const bContext *C, | static void draw_layer_splines(const bContext *C, | ||||
| MaskLayer *layer, | MaskLayer *layer, | ||||
| const char draw_flag, | |||||
| const char draw_type, | const char draw_type, | ||||
| const int width, | const int width, | ||||
| const int height, | const int height, | ||||
| const bool is_active) | const bool is_active) | ||||
| { | { | ||||
| LISTBASE_FOREACH (MaskSpline *, spline, &layer->splines) { | LISTBASE_FOREACH (MaskSpline *, spline, &layer->splines) { | ||||
| /* draw curve itself first... */ | /* draw curve itself first... */ | ||||
| draw_spline_curve(C, layer, spline, draw_flag, draw_type, is_active, width, height); | draw_spline_curve(C, layer, spline, draw_type, is_active, width, height); | ||||
| if (!(layer->visibility_flag & MASK_HIDE_SELECT)) { | if (!(layer->visibility_flag & MASK_HIDE_SELECT)) { | ||||
| /* ...and then handles over the curve so they're nicely visible */ | /* ...and then handles over the curve so they're nicely visible */ | ||||
| draw_spline_points(C, layer, spline, draw_flag, draw_type); | draw_spline_points(C, layer, spline, draw_type); | ||||
| } | } | ||||
| /* show undeform for testing */ | /* show undeform for testing */ | ||||
| if (0) { | if (0) { | ||||
| void *back = spline->points_deform; | void *back = spline->points_deform; | ||||
| spline->points_deform = NULL; | spline->points_deform = NULL; | ||||
| draw_spline_curve(C, layer, spline, draw_flag, draw_type, is_active, width, height); | draw_spline_curve(C, layer, spline, draw_type, is_active, width, height); | ||||
| draw_spline_points(C, layer, spline, draw_flag, draw_type); | draw_spline_points(C, layer, spline, draw_type); | ||||
| spline->points_deform = back; | spline->points_deform = back; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void draw_mask_layers(const bContext *C, | static void draw_mask_layers( | ||||
| Mask *mask, | const bContext *C, Mask *mask, const char draw_type, const int width, const int height) | ||||
| const char draw_flag, | |||||
| const char draw_type, | |||||
| const int width, | |||||
| const int height) | |||||
| { | { | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| GPU_program_point_size(true); | GPU_program_point_size(true); | ||||
| MaskLayer *mask_layer; | MaskLayer *mask_layer; | ||||
| int i; | int i; | ||||
| MaskLayer *active = NULL; | MaskLayer *active = NULL; | ||||
| for (mask_layer = mask->masklayers.first, i = 0; mask_layer != NULL; | for (mask_layer = mask->masklayers.first, i = 0; mask_layer != NULL; | ||||
| mask_layer = mask_layer->next, i++) { | mask_layer = mask_layer->next, i++) { | ||||
| const bool is_active = (i == mask->masklay_act); | const bool is_active = (i == mask->masklay_act); | ||||
| if (mask_layer->visibility_flag & MASK_HIDE_VIEW) { | if (mask_layer->visibility_flag & MASK_HIDE_VIEW) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (is_active) { | if (is_active) { | ||||
| active = mask_layer; | active = mask_layer; | ||||
| continue; | continue; | ||||
| } | } | ||||
| draw_layer_splines(C, mask_layer, draw_flag, draw_type, width, height, is_active); | draw_layer_splines(C, mask_layer, draw_type, width, height, is_active); | ||||
| } | } | ||||
| if (active != NULL) { | if (active != NULL) { | ||||
| draw_layer_splines(C, active, draw_flag, draw_type, width, height, true); | draw_layer_splines(C, active, draw_type, width, height, true); | ||||
| } | } | ||||
| GPU_program_point_size(false); | GPU_program_point_size(false); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| static float *mask_rasterize(Mask *mask, const int width, const int height) | static float *mask_rasterize(Mask *mask, const int width, const int height) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | void ED_mask_draw_region( | ||||
| GPU_matrix_scale_2f(maxdim, maxdim); | GPU_matrix_scale_2f(maxdim, maxdim); | ||||
| if (do_draw_cb) { | if (do_draw_cb) { | ||||
| ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW); | ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW); | ||||
| } | } | ||||
| /* draw! */ | /* draw! */ | ||||
| if (draw_flag & MASK_DRAWFLAG_SPLINE) { | if (draw_flag & MASK_DRAWFLAG_SPLINE) { | ||||
| draw_mask_layers(C, mask_eval, draw_flag, draw_type, width, height); | draw_mask_layers(C, mask_eval, draw_type, width, height); | ||||
| } | } | ||||
| if (do_draw_cb) { | if (do_draw_cb) { | ||||
| ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW); | ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW); | ||||
| } | } | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||