Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-03-26 23:03:42 +0300
committerJulian Eisel <julian@blender.org>2020-03-26 23:18:45 +0300
commitc94b6209861ca7cc3985b53474feed7d94c0221a (patch)
tree752054f0dca1338cda5cf8ad4f6d18573fcca3b9 /source/blender/editors/mask/mask_add.c
parent357ed79cb93f9d655501a828c6cddd68282de62d (diff)
parentafb1a64ccb81b7ed792f64151986f40f53af8da5 (diff)
Merge branch 'master' into wm-drag-drop-rewrite
Diffstat (limited to 'source/blender/editors/mask/mask_add.c')
-rw-r--r--source/blender/editors/mask/mask_add.c168
1 files changed, 8 insertions, 160 deletions
diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c
index 5c730c74df7..5d461ffdb20 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -31,174 +31,22 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
+#include "DNA_mask_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
-#include "DNA_mask_types.h"
#include "WM_api.h"
#include "WM_types.h"
-#include "ED_select_utils.h"
#include "ED_mask.h" /* own include */
#include "ED_screen.h"
+#include "ED_select_utils.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "mask_intern.h" /* own include */
-bool ED_mask_find_nearest_diff_point(const bContext *C,
- struct Mask *mask_orig,
- const float normal_co[2],
- int threshold,
- bool feather,
- float tangent[2],
- const bool use_deform,
- const bool use_project,
- MaskLayer **mask_layer_r,
- MaskSpline **spline_r,
- MaskSplinePoint **point_r,
- float *u_r,
- float *score_r)
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
-
- MaskLayer *point_mask_layer;
- MaskSpline *point_spline;
- MaskSplinePoint *point = NULL;
- float dist_best_sq = FLT_MAX, co[2];
- int width, height;
- float u = 0.0f;
- float scalex, scaley;
-
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id);
-
- ED_mask_get_size(sa, &width, &height);
- ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley);
-
- co[0] = normal_co[0] * scalex;
- co[1] = normal_co[1] * scaley;
-
- for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first,
- *mask_layer_eval = mask_eval->masklayers.first;
- mask_layer_orig != NULL;
- mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next) {
- if (mask_layer_orig->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
- continue;
- }
-
- for (MaskSpline *spline_orig = mask_layer_orig->splines.first,
- *spline_eval = mask_layer_eval->splines.first;
- spline_orig != NULL;
- spline_orig = spline_orig->next, spline_eval = spline_eval->next) {
- int i;
- MaskSplinePoint *cur_point_eval;
-
- for (i = 0, cur_point_eval = use_deform ? spline_eval->points_deform : spline_eval->points;
- i < spline_eval->tot_point;
- i++, cur_point_eval++) {
- unsigned int tot_diff_point;
- float *diff_points = BKE_mask_point_segment_diff(
- spline_eval, cur_point_eval, width, height, &tot_diff_point);
-
- if (diff_points) {
- int j, tot_point;
- unsigned int tot_feather_point;
- float *feather_points = NULL, *points;
-
- if (feather) {
- feather_points = BKE_mask_point_segment_feather_diff(
- spline_eval, cur_point_eval, width, height, &tot_feather_point);
-
- points = feather_points;
- tot_point = tot_feather_point;
- }
- else {
- points = diff_points;
- tot_point = tot_diff_point;
- }
-
- for (j = 0; j < tot_point - 1; j++) {
- float dist_sq, a[2], b[2];
-
- a[0] = points[2 * j] * scalex;
- a[1] = points[2 * j + 1] * scaley;
-
- b[0] = points[2 * j + 2] * scalex;
- b[1] = points[2 * j + 3] * scaley;
-
- dist_sq = dist_squared_to_line_segment_v2(co, a, b);
-
- if (dist_sq < dist_best_sq) {
- if (tangent) {
- sub_v2_v2v2(tangent, &diff_points[2 * j + 2], &diff_points[2 * j]);
- }
-
- point_mask_layer = mask_layer_orig;
- point_spline = spline_orig;
- point = use_deform ?
- &spline_orig->points[(cur_point_eval - spline_eval->points_deform)] :
- &spline_orig->points[(cur_point_eval - spline_eval->points)];
- dist_best_sq = dist_sq;
- u = (float)j / tot_point;
- }
- }
-
- if (feather_points != NULL) {
- MEM_freeN(feather_points);
- }
- MEM_freeN(diff_points);
- }
- }
- }
- }
-
- if (point && dist_best_sq < threshold) {
- if (mask_layer_r) {
- *mask_layer_r = point_mask_layer;
- }
-
- if (spline_r) {
- *spline_r = point_spline;
- }
-
- if (point_r) {
- *point_r = point;
- }
-
- if (u_r) {
- /* TODO(sergey): Projection fails in some weirdo cases.. */
- if (use_project) {
- u = BKE_mask_spline_project_co(point_spline, point, u, normal_co, MASK_PROJ_ANY);
- }
-
- *u_r = u;
- }
-
- if (score_r) {
- *score_r = dist_best_sq;
- }
-
- return true;
- }
-
- if (mask_layer_r) {
- *mask_layer_r = NULL;
- }
-
- if (spline_r) {
- *spline_r = NULL;
- }
-
- if (point_r) {
- *point_r = NULL;
- }
-
- return false;
-}
-
/******************** add vertex *********************/
static void setup_vertex_point(Mask *mask,
@@ -598,10 +446,10 @@ static void mask_point_make_pixel_space(bContext *C,
float point_pixel[2])
{
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
float scalex, scaley;
- ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley);
+ ED_mask_pixelspace_factor(sa, region, &scalex, &scaley);
point_pixel[0] = point_normalized[0] * scalex;
point_pixel[1] = point_normalized[1] * scaley;
@@ -710,11 +558,11 @@ static int add_vertex_exec(bContext *C, wmOperator *op)
static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
float co[2];
- ED_mask_mouse_pos(sa, ar, event->mval, co);
+ ED_mask_mouse_pos(sa, region, event->mval, co);
RNA_float_set_array(op->ptr, "location", co);
@@ -802,11 +650,11 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op)
static int add_feather_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
+ ARegion *region = CTX_wm_region(C);
float co[2];
- ED_mask_mouse_pos(sa, ar, event->mval, co);
+ ED_mask_mouse_pos(sa, region, event->mval, co);
RNA_float_set_array(op->ptr, "location", co);