Commit: 4c57f07a0fde0ca067e5b0e6609ded6c0e170cc2
Author: Campbell Barton
Date:   Wed Mar 25 19:06:17 2020 +1100
Branches: master
https://developer.blender.org/rB4c57f07a0fde0ca067e5b0e6609ded6c0e170cc2

Cleanup: move mask queries into own file

Similar functions to lookup nearest mask points were in mask_add.c
& mask_edit.c

===================================================================

M       source/blender/editors/include/ED_mask.h
M       source/blender/editors/mask/CMakeLists.txt
M       source/blender/editors/mask/mask_add.c
M       source/blender/editors/mask/mask_edit.c
M       source/blender/editors/mask/mask_intern.h
M       source/blender/editors/mask/mask_ops.c
A       source/blender/editors/mask/mask_query.c

===================================================================

diff --git a/source/blender/editors/include/ED_mask.h 
b/source/blender/editors/include/ED_mask.h
index 6abefa98c1a..7d314c0c462 100644
--- a/source/blender/editors/include/ED_mask.h
+++ b/source/blender/editors/include/ED_mask.h
@@ -36,6 +36,13 @@ struct bContext;
 struct wmKeyConfig;
 
 /* mask_edit.c */
+void ED_mask_deselect_all(const struct bContext *C);
+
+void ED_operatortypes_mask(void);
+void ED_keymap_mask(struct wmKeyConfig *keyconf);
+void ED_operatormacros_mask(void);
+
+/* mask_query.c */
 void ED_mask_get_size(struct ScrArea *sa, int *width, int *height);
 void ED_mask_zoom(struct ScrArea *sa, struct ARegion *region, float *zoomx, 
float *zoomy);
 void ED_mask_get_aspect(struct ScrArea *sa, struct ARegion *region, float 
*aspx, float *aspy);
@@ -54,12 +61,6 @@ void ED_mask_point_pos__reverse(
 void ED_mask_cursor_location_get(struct ScrArea *sa, float cursor[2]);
 bool ED_mask_selected_minmax(const struct bContext *C, float min[2], float 
max[2]);
 
-void ED_mask_deselect_all(const struct bContext *C);
-
-void ED_operatortypes_mask(void);
-void ED_keymap_mask(struct wmKeyConfig *keyconf);
-void ED_operatormacros_mask(void);
-
 /* mask_draw.c */
 void ED_mask_draw(const struct bContext *C, const char draw_flag, const char 
draw_type);
 void ED_mask_draw_region(struct Depsgraph *depsgraph,
diff --git a/source/blender/editors/mask/CMakeLists.txt 
b/source/blender/editors/mask/CMakeLists.txt
index 81c861ab4e4..66c055d9426 100644
--- a/source/blender/editors/mask/CMakeLists.txt
+++ b/source/blender/editors/mask/CMakeLists.txt
@@ -40,6 +40,7 @@ set(SRC
   mask_edit.c
   mask_editaction.c
   mask_ops.c
+  mask_query.c
   mask_relationships.c
   mask_select.c
   mask_shapekey.c
diff --git a/source/blender/editors/mask/mask_add.c 
b/source/blender/editors/mask/mask_add.c
index a190b048ee3..5d461ffdb20 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -47,158 +47,6 @@
 
 #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 **r_mask_layer,
-                                     MaskSpline **r_spline,
-                                     MaskSplinePoint **r_point,
-                                     float *r_u,
-                                     float *r_score)
-{
-  ScrArea *sa = CTX_wm_area(C);
-  ARegion *region = 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, region, &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 (r_mask_layer) {
-      *r_mask_layer = point_mask_layer;
-    }
-
-    if (r_spline) {
-      *r_spline = point_spline;
-    }
-
-    if (r_point) {
-      *r_point = point;
-    }
-
-    if (r_u) {
-      /* 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);
-      }
-
-      *r_u = u;
-    }
-
-    if (r_score) {
-      *r_score = dist_best_sq;
-    }
-
-    return true;
-  }
-
-  if (r_mask_layer) {
-    *r_mask_layer = NULL;
-  }
-
-  if (r_spline) {
-    *r_spline = NULL;
-  }
-
-  if (r_point) {
-    *r_point = NULL;
-  }
-
-  return false;
-}
-
 /******************** add vertex *********************/
 
 static void setup_vertex_point(Mask *mask,
diff --git a/source/blender/editors/mask/mask_edit.c 
b/source/blender/editors/mask/mask_edit.c
index 1606d079462..e18c4992671 100644
--- a/source/blender/editors/mask/mask_edit.c
+++ b/source/blender/editors/mask/mask_edit.c
@@ -47,7 +47,9 @@
 
 #include "mask_intern.h" /* own include */
 
-/********************** generic poll functions *********************/
+/* -------------------------------------------------------------------- */
+/** \name Poll Functions
+ * \{ */
 
 bool ED_maskedit_poll(bContext *C)
 {
@@ -81,344 +83,11 @@ bool ED_maskedit_mask_poll(bContext *C)
   return false;
 }
 
-/********************** registration *********************/
+/** \} */
 
-/* takes event->mval */
-void ED_mask_mouse_pos(ScrArea *sa, ARegion *region, const int mval[2], float 
co[2])
-{
-  if (sa) {
-    switch (sa->spacetype) {
-      case SPACE_CLIP: {
-        SpaceClip *sc = sa->spacedata.first;
-        ED_clip_mouse_pos(sc, region, mval, co);
-        BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
-        break;
-      }
-      case SPACE_SEQ: {
-        UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &co[0], 
&co[1]);
-        break;
-      }
-      case SPACE_IMAGE: {
-        SpaceImage *sima = sa->spacedata.first;
-        ED_image_mouse_pos(sima, region, mval, co);
-        BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co);
-        break;
-      }
-      default:
-        /* possible other spaces from which mask editing is available */
-        BLI_assert(0);
-        zero_v2(co);
-        break;
-    }
-  }
-  else {
-    BLI_assert(0);
-    zero_v2(co);
-  }
-}
-
-/* input:  x/y   - mval space
- * output: xr/yr - mask point space */
-void ED_mask_point_pos(ScrArea *sa, ARegion *region, float x, float y, float 
*xr, float *yr)
-{
-  float co[2];
-
-  if (sa) {
-    switch (sa->spacetype) {
-      case SPACE_CLIP: {
-        SpaceClip *sc = sa->spacedata.first;
-        ED_clip_point_stable_pos(sc, region, x, y, &co[0], &co[1]);
-        BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
-        break;
-      }
-      case SPACE_SEQ:
-        zero_v2(co); /* MASKTODO */
-        break;
-      case SPACE_IMAGE: {
-        SpaceImage *sima = sa->spacedata.first;
-        ED_image_point_pos(sima, region, x, y, &co[0], &co[1]);
-        BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co);
-        break;
-      }
-      default:
-        /* possible other spaces from which mask editing is available */
-        BLI_assert(0);
-        zero_v2(co);
-        break;
-    }
-  }
-  else {
-    BLI_assert(0);
-    zero_v2(co);
-  }
-
-  *xr = co[0];
-  *yr = co[1];
-}
-
-void ED_mask_point_pos__reverse(
-    ScrArea *sa, ARegion *region, float x, float y, float *xr, float *yr)
-{
-  float co[2];
-
-  if (sa) {
-    switch (sa->spacetype) {
-      case SPACE_CLIP: {
-        SpaceClip *sc = sa->spacedata.first;
-        co[0] = x;
-        co[1] = y;
-        BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co);
-        ED_clip_point_stable_pos__reverse(sc, region, co, co);
-        break;
-      }
-      case SPACE_SEQ:
-        zero_v2(co); /* MASKTODO */
-        break;
-      case SPACE_IMAGE: {
-        SpaceImage *sima = sa->spacedata.first;
-        co[0] = x;
-        co[1] = y;
-        BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co);
-        ED_i

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to