diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-06-05 11:52:21 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-06-05 16:11:08 +0300 |
commit | abeda01ac6da28564ad1b37d8ac09af75da96eba (patch) | |
tree | ee6e75977341f16930264602dd1b03042dc2022c /source/blender/editors/gpencil/gpencil_utils.c | |
parent | 67b17684e699edc3bbd303420c86e31b6af7007f (diff) |
GPencil: Improve Vertex Paint in filled areas
When use the Tint tool, it was very difficult to tint the filled areas if the strokes had very few points or the area was big.
Differential Revision: https://developer.blender.org/D7936
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_utils.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_utils.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 1962eba5017..876fa7c9874 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -31,6 +31,7 @@ #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_hash.h" +#include "BLI_lasso_2d.h" #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" @@ -2799,3 +2800,49 @@ bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc, /* Check collision between both rectangles. */ return BLI_rcti_isect(&rect_stroke, &rect_mouse, NULL); } + +/** + * Check if a point is inside of the stroke + * \param gps: Stroke to check + * \param gsc: SpaceConversion data + * \param mouse: Mouse position + * \param diff_mat: View matrix + * \return True if the point is inside + */ +bool ED_gpencil_stroke_point_is_inside(bGPDstroke *gps, + GP_SpaceConversion *gsc, + int mouse[2], + const float diff_mat[4][4]) +{ + bool hit = false; + if (gps->totpoints == 0) { + return hit; + } + + int(*mcoords)[2] = NULL; + int len = gps->totpoints; + mcoords = MEM_mallocN(sizeof(int) * 2 * len, __func__); + + /* Convert stroke to 2D array of points. */ + bGPDspoint *pt; + int i; + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + bGPDspoint pt2; + gp_point_to_parent_space(pt, diff_mat, &pt2); + gp_point_to_xy(gsc, gps, &pt2, &mcoords[i][0], &mcoords[i][1]); + } + + /* Compute boundbox of lasso (for faster testing later). */ + rcti rect; + BLI_lasso_boundbox(&rect, mcoords, len); + + /* Test if point inside stroke. */ + hit = ((!ELEM(V2D_IS_CLIPPED, mouse[0], mouse[1])) && + BLI_rcti_isect_pt(&rect, mouse[0], mouse[1]) && + BLI_lasso_is_point_inside(mcoords, len, mouse[0], mouse[1], INT_MAX)); + + /* Free memory. */ + MEM_SAFE_FREE(mcoords); + + return hit; +} |