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:
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/CMakeLists.txt4
-rw-r--r--source/blender/editors/gpencil/annotate_draw.c342
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c202
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c90
-rw-r--r--source/blender/editors/gpencil/editaction_gpencil.c84
-rw-r--r--source/blender/editors/gpencil/gpencil_add_stroke.c3
-rw-r--r--source/blender/editors/gpencil/gpencil_armature.c14
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c73
-rw-r--r--source/blender/editors/gpencil/gpencil_convert.c86
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c142
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c194
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c17
-rw-r--r--source/blender/editors/gpencil/gpencil_interpolate.c6
-rw-r--r--source/blender/editors/gpencil/gpencil_merge.c6
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c207
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c48
-rw-r--r--source/blender/editors/gpencil/gpencil_select.c56
-rw-r--r--source/blender/editors/gpencil/gpencil_undo.c9
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c155
20 files changed, 1102 insertions, 640 deletions
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 5573c88c710..21f1801f7eb 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -22,13 +22,13 @@ set(INC
../../blenlib
../../blentranslation
../../depsgraph
- ../../imbuf
../../gpu
+ ../../imbuf
../../makesdna
../../makesrna
../../windowmanager
- ../../../../intern/guardedalloc
../../../../intern/glew-mx
+ ../../../../intern/guardedalloc
)
set(INC_SYS
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index a7fa51350ba..f325422fec7 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -91,22 +91,24 @@ typedef enum eDrawStrokeFlags {
/* ----- Tool Buffer Drawing ------ */
/* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */
-static void gp_draw_stroke_buffer(const tGPspoint *points,
- int totpoints,
- short thickness,
- short dflag,
- short sflag,
- float ink[4])
+static void annotation_draw_stroke_buffer(const tGPspoint *points,
+ int totpoints,
+ short thickness,
+ short dflag,
+ short sflag,
+ float ink[4])
{
int draw_points = 0;
/* error checking */
- if ((points == NULL) || (totpoints <= 0))
+ if ((points == NULL) || (totpoints <= 0)) {
return;
+ }
/* check if buffer can be drawn */
- if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D))
+ if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) {
return;
+ }
if (sflag & GP_STROKE_ERASER) {
/* don't draw stroke at all! */
@@ -138,8 +140,9 @@ static void gp_draw_stroke_buffer(const tGPspoint *points,
immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints);
for (int i = 0; i < totpoints; i++, pt++) {
- /* if there was a significant pressure change, stop the curve, change the thickness of the stroke,
- * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP)
+ /* If there was a significant pressure change,
+ * stop the curve, change the thickness of the stroke,
+ * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP).
*/
if (fabsf(pt->pressure - oldpressure) > 0.2f) {
/* need to have 2 points to avoid immEnd assert error */
@@ -178,7 +181,7 @@ static void gp_draw_stroke_buffer(const tGPspoint *points,
/* --------- 2D Stroke Drawing Helpers --------- */
/* change in parameter list */
-static void gp_calc_2d_stroke_fxy(
+static void annotation_calc_2d_stroke_fxy(
const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2])
{
if (sflag & GP_STROKE_2DSPACE) {
@@ -204,15 +207,15 @@ static void gp_calc_2d_stroke_fxy(
/* ----- Existing Strokes Drawing (3D and Point) ------ */
/* draw a given stroke - just a single dot (only one point) */
-static void gp_draw_stroke_point(const bGPDspoint *points,
- short thickness,
- short UNUSED(dflag),
- short sflag,
- int offsx,
- int offsy,
- int winx,
- int winy,
- const float ink[4])
+static void annotation_draw_stroke_point(const bGPDspoint *points,
+ short thickness,
+ short UNUSED(dflag),
+ short sflag,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ const float ink[4])
{
const bGPDspoint *pt = points;
@@ -231,7 +234,7 @@ static void gp_draw_stroke_point(const bGPDspoint *points,
/* get 2D coordinates of point */
float co[3] = {0.0f};
- gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
+ annotation_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
copy_v3_v3(fpt, co);
}
@@ -249,12 +252,12 @@ static void gp_draw_stroke_point(const bGPDspoint *points,
}
/* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */
-static void gp_draw_stroke_3d(const bGPDspoint *points,
- int totpoints,
- short thickness,
- short UNUSED(sflag),
- const float ink[4],
- bool cyclic)
+static void annotation_draw_stroke_3d(const bGPDspoint *points,
+ int totpoints,
+ short thickness,
+ short UNUSED(sflag),
+ const float ink[4],
+ bool cyclic)
{
float curpressure = points[0].pressure;
float cyclic_fpt[3];
@@ -277,8 +280,9 @@ static void gp_draw_stroke_3d(const bGPDspoint *points,
immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints + cyclic_add);
const bGPDspoint *pt = points;
for (int i = 0; i < totpoints; i++, pt++) {
- /* if there was a significant pressure change, stop the curve, change the thickness of the stroke,
- * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP)
+ /* If there was a significant pressure change, stop the curve,
+ * change the thickness of the stroke, and continue drawing again
+ * (since line-width cannot change in middle of GL_LINE_STRIP)
* Note: we want more visible levels of pressures when thickness is bigger.
*/
if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) {
@@ -332,16 +336,16 @@ static void gp_draw_stroke_3d(const bGPDspoint *points,
/* ----- Fancy 2D-Stroke Drawing ------ */
/* draw a given stroke in 2d */
-static void gp_draw_stroke_2d(const bGPDspoint *points,
- int totpoints,
- short thickness_s,
- short dflag,
- short sflag,
- int offsx,
- int offsy,
- int winx,
- int winy,
- const float ink[4])
+static void annotation_draw_stroke_2d(const bGPDspoint *points,
+ int totpoints,
+ short thickness_s,
+ short dflag,
+ short sflag,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ const float ink[4])
{
/* otherwise thickness is twice that of the 3D view */
float thickness = (float)thickness_s * 0.5f;
@@ -352,8 +356,9 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
scalefac = 0.001f;
}
- /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) with connection
- * edges rotated to minimize shrinking artifacts, and rounded endcaps
+ /* Tessellation code - draw stroke as series of connected quads
+ * (triangle strips in fact) with connection edges rotated to minimize shrinking artifacts,
+ * and rounded endcaps.
*/
{
const bGPDspoint *pt1, *pt2;
@@ -369,7 +374,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
immBegin(GPU_PRIM_TRI_STRIP, totpoints * 2 + 4);
/* get x and y coordinates from first point */
- gp_calc_2d_stroke_fxy(&points->x, sflag, offsx, offsy, winx, winy, s0);
+ annotation_calc_2d_stroke_fxy(&points->x, sflag, offsx, offsy, winx, winy, s0);
for (i = 0, pt1 = points, pt2 = points + 1; i < (totpoints - 1); i++, pt1++, pt2++) {
float t0[2], t1[2]; /* tessellated coordinates */
@@ -377,8 +382,9 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
float mt[2], sc[2]; /* gradient for thickness, point for end-cap */
float pthick; /* thickness at segment point */
- /* get x and y coordinates from point2 (point1 has already been computed in previous iteration). */
- gp_calc_2d_stroke_fxy(&pt2->x, sflag, offsx, offsy, winx, winy, s1);
+ /* Get x and y coordinates from point2
+ * (point1 has already been computed in previous iteration). */
+ annotation_calc_2d_stroke_fxy(&pt2->x, sflag, offsx, offsy, winx, winy, s1);
/* calculate gradient and normal - 'angle'=(ny/nx) */
m1[1] = s1[1] - s0[1];
@@ -507,52 +513,59 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
/* ----- Strokes Drawing ------ */
/* Helper for doing all the checks on whether a stroke can be drawn */
-static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag)
+static bool annotation_can_draw_stroke(const bGPDstroke *gps, const int dflag)
{
/* skip stroke if it isn't in the right display space for this drawing context */
/* 1) 3D Strokes */
- if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE))
+ if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) {
return false;
+ }
/* 2) Screen Space 2D Strokes */
- if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE))
+ if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) {
return false;
+ }
/* 3) Image Space (2D) */
- if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
+ if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) {
return false;
+ }
/* skip stroke if it doesn't have any valid data */
- if ((gps->points == NULL) || (gps->totpoints < 1))
+ if ((gps->points == NULL) || (gps->totpoints < 1)) {
return false;
+ }
/* stroke can be drawn */
return true;
}
/* draw a set of strokes */
-static void gp_draw_strokes(bGPdata *UNUSED(gpd),
- bGPDlayer *UNUSED(gpl),
- const bGPDframe *gpf,
- int offsx,
- int offsy,
- int winx,
- int winy,
- int dflag,
- short lthick,
- const float color[4])
+static void annotation_draw_strokes(bGPdata *UNUSED(gpd),
+ bGPDlayer *UNUSED(gpl),
+ const bGPDframe *gpf,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ int dflag,
+ short lthick,
+ const float color[4])
{
GPU_enable_program_point_size();
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* check if stroke can be drawn */
- if (gp_can_draw_stroke(gps, dflag) == false) {
+ if (annotation_can_draw_stroke(gps, dflag) == false) {
continue;
}
@@ -573,11 +586,11 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd),
/* 3D Lines - OpenGL primitives-based */
if (gps->totpoints == 1) {
- gp_draw_stroke_point(
+ annotation_draw_stroke_point(
gps->points, lthick, dflag, gps->flag, offsx, offsy, winx, winy, color);
}
else {
- gp_draw_stroke_3d(
+ annotation_draw_stroke_3d(
gps->points, gps->totpoints, lthick, gps->flag, color, gps->flag & GP_STROKE_CYCLIC);
}
@@ -591,20 +604,20 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd),
else {
/* 2D Strokes... */
if (gps->totpoints == 1) {
- gp_draw_stroke_point(
+ annotation_draw_stroke_point(
gps->points, lthick, dflag, gps->flag, offsx, offsy, winx, winy, color);
}
else {
- gp_draw_stroke_2d(gps->points,
- gps->totpoints,
- lthick,
- dflag,
- gps->flag,
- offsx,
- offsy,
- winx,
- winy,
- color);
+ annotation_draw_stroke_2d(gps->points,
+ gps->totpoints,
+ lthick,
+ dflag,
+ gps->flag,
+ offsx,
+ offsy,
+ winx,
+ winy,
+ color);
}
}
}
@@ -613,20 +626,21 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd),
}
/* Draw selected verts for strokes being edited */
-static void gp_draw_strokes_edit(bGPdata *gpd,
- bGPDlayer *gpl,
- const bGPDframe *gpf,
- int offsx,
- int offsy,
- int winx,
- int winy,
- short dflag,
- short UNUSED(lflag),
- float alpha)
+static void annotation_draw_strokes_edit(bGPdata *gpd,
+ bGPDlayer *gpl,
+ const bGPDframe *gpf,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ short dflag,
+ short UNUSED(lflag),
+ float alpha)
{
/* if alpha 0 do not draw */
- if (alpha == 0.0f)
+ if (alpha == 0.0f) {
return;
+ }
const bool no_xray = (dflag & GP_DRAWDATA_NO_XRAY) != 0;
int mask_orig = 0;
@@ -649,15 +663,17 @@ static void gp_draw_strokes_edit(bGPdata *gpd,
/* draw stroke verts */
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* check if stroke can be drawn */
- if (gp_can_draw_stroke(gps, dflag) == false)
+ if (annotation_can_draw_stroke(gps, dflag) == false) {
continue;
+ }
/* Optimisation: only draw points for selected strokes
* We assume that selected points can only occur in
* strokes that are selected too.
*/
- if ((gps->flag & GP_STROKE_SELECT) == 0)
+ if ((gps->flag & GP_STROKE_SELECT) == 0) {
continue;
+ }
/* Get size of verts:
* - The selected state needs to be larger than the unselected state so that
@@ -726,7 +742,7 @@ static void gp_draw_strokes_edit(bGPdata *gpd,
}
else {
float co[2];
- gp_calc_2d_stroke_fxy(&pt->x, gps->flag, offsx, offsy, winx, winy, co);
+ annotation_calc_2d_stroke_fxy(&pt->x, gps->flag, offsx, offsy, winx, winy, co);
immVertex2fv(pos, co);
}
}
@@ -754,15 +770,15 @@ static void gp_draw_strokes_edit(bGPdata *gpd,
/* ----- General Drawing ------ */
/* draw onion-skinning for a layer */
-static void gp_draw_onionskins(bGPdata *gpd,
- bGPDlayer *gpl,
- bGPDframe *gpf,
- int offsx,
- int offsy,
- int winx,
- int winy,
- int UNUSED(cfra),
- int dflag)
+static void annotation_draw_onionskins(bGPdata *gpd,
+ bGPDlayer *gpl,
+ bGPDframe *gpf,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ int UNUSED(cfra),
+ int dflag)
{
const float alpha = 1.0f;
float color[4];
@@ -781,17 +797,20 @@ static void gp_draw_onionskins(bGPdata *gpd,
/* alpha decreases with distance from curframe index */
fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1));
color[3] = alpha * fac * 0.66f;
- gp_draw_strokes(gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
+ annotation_draw_strokes(
+ gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
}
- else
+ else {
break;
+ }
}
}
else if (gpl->gstep == 0) {
/* draw the strokes for the ghost frames (at half of the alpha set by user) */
if (gpf->prev) {
color[3] = (alpha / 7);
- gp_draw_strokes(gpd, gpl, gpf->prev, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
+ annotation_draw_strokes(
+ gpd, gpl, gpf->prev, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
}
}
else {
@@ -812,17 +831,20 @@ static void gp_draw_onionskins(bGPdata *gpd,
/* alpha decreases with distance from curframe index */
fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1));
color[3] = alpha * fac * 0.66f;
- gp_draw_strokes(gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
+ annotation_draw_strokes(
+ gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
}
- else
+ else {
break;
+ }
}
}
else if (gpl->gstep_next == 0) {
/* draw the strokes for the ghost frames (at half of the alpha set by user) */
if (gpf->next) {
color[3] = (alpha / 4);
- gp_draw_strokes(gpd, gpl, gpf->next, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
+ annotation_draw_strokes(
+ gpd, gpl, gpf->next, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
}
}
else {
@@ -831,7 +853,7 @@ static void gp_draw_onionskins(bGPdata *gpd,
}
/* loop over gpencil data layers, drawing them */
-static void gp_draw_data_layers(
+static void annotation_draw_data_layers(
bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag, float alpha)
{
float ink[4];
@@ -846,13 +868,15 @@ static void gp_draw_data_layers(
ink[3] = gpl->opacity;
/* don't draw layer if hidden */
- if (gpl->flag & GP_LAYER_HIDE)
+ if (gpl->flag & GP_LAYER_HIDE) {
continue;
+ }
/* get frame to draw */
bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, GP_GETFRAME_USE_PREV);
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* set basic stroke thickness */
GPU_line_width(lthick);
@@ -867,23 +891,25 @@ static void gp_draw_data_layers(
/* Draw 'onionskins' (frame left + right) */
if (gpl->onion_flag & GP_LAYER_ONIONSKIN) {
- gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag);
+ annotation_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag);
}
/* draw the strokes already in active frame */
- gp_draw_strokes(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, lthick, ink);
+ annotation_draw_strokes(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, lthick, ink);
- /* Draw verts of selected strokes
+ /* Draw verts of selected strokes:
* - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering
* - locked layers can't be edited, so there's no point showing these verts
* as they will have no bearings on what gets edited
* - only show when in editmode, since operators shouldn't work otherwise
- * (NOTE: doing it this way means that the toggling editmode shows visible change immediately)
+ * (NOTE: doing it this way means that the toggling editmode
+ * shows visible change immediately).
*/
/* XXX: perhaps we don't want to show these when users are drawing... */
if ((G.f & G_FLAG_RENDER_VIEWPORT) == 0 && (gpl->flag & GP_LAYER_LOCKED) == 0 &&
(gpd->flag & GP_DATA_STROKE_EDITMODE)) {
- gp_draw_strokes_edit(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, alpha);
+ annotation_draw_strokes_edit(
+ gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, alpha);
}
/* Check if may need to draw the active stroke cache, only if this layer is the active layer
@@ -897,24 +923,25 @@ static void gp_draw_data_layers(
* It should also be noted that sbuffer contains temporary point types
* i.e. tGPspoints NOT bGPDspoints
*/
- gp_draw_stroke_buffer(gpd->runtime.sbuffer,
- gpd->runtime.sbuffer_size,
- lthick,
- dflag,
- gpd->runtime.sbuffer_sflag,
- ink);
+ annotation_draw_stroke_buffer(gpd->runtime.sbuffer,
+ gpd->runtime.sbuffer_size,
+ lthick,
+ dflag,
+ gpd->runtime.sbuffer_sflag,
+ ink);
}
}
}
/* draw a short status message in the top-right corner */
-static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar)
+static void annotation_draw_status_text(const bGPdata *gpd, ARegion *ar)
{
rcti rect;
/* Cannot draw any status text when drawing OpenGL Renders */
- if (G.f & G_FLAG_RENDER_VIEWPORT)
+ if (G.f & G_FLAG_RENDER_VIEWPORT) {
return;
+ }
/* Get bounds of region - Necessary to avoid problems with region overlap */
ED_region_visible_rect(ar, &rect);
@@ -956,7 +983,7 @@ static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar)
}
/* draw grease-pencil datablock */
-static void gp_draw_data(
+static void annotation_draw_data(
bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag, float alpha)
{
/* turn on smooth lines (i.e. anti-aliasing) */
@@ -968,7 +995,7 @@ static void gp_draw_data(
GPU_blend(true);
/* draw! */
- gp_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha);
+ annotation_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha);
/* turn off alpha blending, then smooth lines */
GPU_blend(false); // alpha blending
@@ -977,15 +1004,15 @@ static void gp_draw_data(
/* if we have strokes for scenes (3d view)/clips (movie clip editor)
* and objects/tracks, multiple data blocks have to be drawn */
-static void gp_draw_data_all(Scene *scene,
- bGPdata *gpd,
- int offsx,
- int offsy,
- int winx,
- int winy,
- int cfra,
- int dflag,
- const char spacetype)
+static void annotation_draw_data_all(Scene *scene,
+ bGPdata *gpd,
+ int offsx,
+ int offsy,
+ int winx,
+ int winy,
+ int cfra,
+ int dflag,
+ const char spacetype)
{
bGPdata *gpd_source = NULL;
float alpha = 1.0f;
@@ -1001,14 +1028,14 @@ static void gp_draw_data_all(Scene *scene,
}
if (gpd_source) {
- gp_draw_data(gpd_source, offsx, offsy, winx, winy, cfra, dflag, alpha);
+ annotation_draw_data(gpd_source, offsx, offsy, winx, winy, cfra, dflag, alpha);
}
}
/* scene/clip data has already been drawn, only object/track data is drawn here
* if gpd_source == gpd, we don't have any object/track data and we can skip */
if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) {
- gp_draw_data(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha);
+ annotation_draw_data(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha);
}
}
@@ -1032,8 +1059,9 @@ void ED_annotation_draw_2dimage(const bContext *C)
int dflag = GP_DRAWDATA_NOSTATUS;
bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
- if (gpd == NULL)
+ if (gpd == NULL) {
return;
+ }
/* calculate rect */
switch (sa->spacetype) {
@@ -1041,7 +1069,8 @@ void ED_annotation_draw_2dimage(const bContext *C)
case SPACE_CLIP: /* clip */
{
/* just draw using standard scaling (settings here are currently ignored anyways) */
- /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */
+ /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way,
+ * so disabled. */
offsx = 0;
offsy = 0;
sizex = ar->winx;
@@ -1083,12 +1112,16 @@ void ED_annotation_draw_2dimage(const bContext *C)
}
/* draw it! */
- gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype);
+ annotation_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype);
}
-/* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly
- * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes,
- * second time with onlyv2d=false for screen-aligned strokes */
+/**
+ * Draw grease-pencil sketches to specified 2d-view
+ * assuming that matrices are already set correctly.
+ *
+ * \note This gets called twice - first time with onlyv2d=true to draw 'canvas' strokes,
+ * second time with onlyv2d=false for screen-aligned strokes.
+ */
void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
{
wmWindowManager *wm = CTX_wm_manager(C);
@@ -1098,28 +1131,34 @@ void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
int dflag = 0;
/* check that we have grease-pencil stuff to draw */
- if (sa == NULL)
+ if (sa == NULL) {
return;
+ }
bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
- if (gpd == NULL)
+ if (gpd == NULL) {
return;
+ }
/* special hack for Image Editor */
- /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */
- if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP))
+ /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way,
+ * so disabled. */
+ if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
dflag |= GP_DRAWDATA_IEDITHACK;
+ }
/* draw it! */
- if (onlyv2d)
+ if (onlyv2d) {
dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS);
- if (ED_screen_animation_playing(wm))
+ }
+ if (ED_screen_animation_playing(wm)) {
dflag |= GP_DRAWDATA_NO_ONIONS;
+ }
- gp_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype);
+ annotation_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype);
/* draw status text (if in screen/pixel-space) */
if (!onlyv2d) {
- gp_draw_status_text(gpd, ar);
+ annotation_draw_status_text(gpd, ar);
}
}
@@ -1136,8 +1175,9 @@ void ED_annotation_draw_view3d(
/* check that we have grease-pencil stuff to draw */
/* XXX: Hardcoded reference here may get out of sync if we change how we fetch annotation data */
bGPdata *gpd = scene->gpd;
- if (gpd == NULL)
+ if (gpd == NULL) {
return;
+ }
/* when rendering to the offscreen buffer we don't want to
* deal with the camera border, otherwise map the coords to the camera border. */
@@ -1172,7 +1212,7 @@ void ED_annotation_draw_view3d(
}
/* draw it! */
- gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
+ annotation_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
}
void ED_annotation_draw_ex(
@@ -1180,7 +1220,7 @@ void ED_annotation_draw_ex(
{
int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D;
- gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype);
+ annotation_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype);
}
/* ************************************************** */
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 4933f081790..73230e5fb0e 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -160,7 +160,8 @@ typedef struct tGPsdata {
/* These need to be doubles, as (at least under unix) they are in seconds since epoch,
* float (and its 7 digits precision) is definitively not enough here!
- * double, with its 15 digits precision, ensures us millisecond precision for a few centuries at least.
+ * double, with its 15 digits precision,
+ * ensures us millisecond precision for a few centuries at least.
*/
/** Used when converting to path. */
double inittime;
@@ -231,10 +232,12 @@ static bool gpencil_draw_poll(bContext *C)
/* check if current context can support GPencil data */
if (ED_gpencil_data_get_pointers(C, NULL) != NULL) {
/* check if Grease Pencil isn't already running */
- if (ED_gpencil_session_active() == 0)
+ if (ED_gpencil_session_active() == 0) {
return true;
- else
+ }
+ else {
CTX_wm_operator_poll_msg_set(C, "Annotation operator is already active");
+ }
}
else {
CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into");
@@ -278,25 +281,30 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float pmval[2
int dy = (int)fabsf(mval[1] - pmval[1]);
/* if buffer is empty, just let this go through (i.e. so that dots will work) */
- if (p->gpd->runtime.sbuffer_size == 0)
+ if (p->gpd->runtime.sbuffer_size == 0) {
return true;
- /* check if mouse moved at least certain distance on both axes (best case)
- * - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand
- */
- else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX))
+ /* check if mouse moved at least certain distance on both axes (best case)
+ * - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand
+ */
+ }
+ else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) {
return true;
- /* check if the distance since the last point is significant enough
- * - prevents points being added too densely
- * - distance here doesn't use sqrt to prevent slowness... we should still be safe from overflows though
- */
- else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX)
+ /* Check if the distance since the last point is significant enough:
+ * - Prevents points being added too densely
+ * - Distance here doesn't use sqrt to prevent slowness.
+ * We should still be safe from overflows though.
+ */
+ }
+ else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) {
return true;
- /* mouse 'didn't move' */
- else
+ /* mouse 'didn't move' */
+ }
+ else {
return false;
+ }
}
/* convert screen-coordinates to buffer-coordinates */
@@ -465,8 +473,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */
/* check if still room in buffer */
- if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX)
+ if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) {
return GP_STROKEADD_OVERFLOW;
+ }
/* get pointer to destination point */
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
@@ -488,10 +497,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* check if another operation can still occur */
- if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX)
+ if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) {
return GP_STROKEADD_FULL;
- else
+ }
+ else {
return GP_STROKEADD_NORMAL;
+ }
}
else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
/* get pointer to destination point */
@@ -546,8 +557,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* increment counters */
- if (gpd->runtime.sbuffer_size == 0)
+ if (gpd->runtime.sbuffer_size == 0) {
gpd->runtime.sbuffer_size++;
+ }
return GP_STROKEADD_NORMAL;
}
@@ -569,12 +581,14 @@ static void gp_stroke_simplify(tGPsdata *p)
short i, j;
/* only simplify if simplification is enabled, and we're not doing a straight line */
- if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT))
+ if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) {
return;
+ }
/* don't simplify if less than 4 points in buffer */
- if ((num_points <= 4) || (old_points == NULL))
+ if ((num_points <= 4) || (old_points == NULL)) {
return;
+ }
/* clear buffer (but don't free mem yet) so that we can write to it
* - firstly set sbuffer to NULL, so a new one is allocated
@@ -646,22 +660,26 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
ToolSettings *ts = p->scene->toolsettings;
int i, totelem;
- /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
+ /* Since strokes are so fine, when using their depth we need a margin
+ * otherwise they might get missed. */
int depth_margin = (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0;
/* get total number of points to allocate space for
* - drawing straight-lines only requires the endpoints
*/
- if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)
+ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size;
- else
+ }
+ else {
totelem = gpd->runtime.sbuffer_size;
+ }
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
gpd->runtime.sbuffer_size);
+ }
return;
}
@@ -770,8 +788,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (found_depth == false) {
/* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--)
+ for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
depth_arr[i] = 0.9999f;
+ }
}
else {
if (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) {
@@ -780,20 +799,23 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
int last_valid = 0;
for (i = 0; i < gpd->runtime.sbuffer_size; i++) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
first_valid = i;
for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
last_valid = i;
/* invalidate non-endpoints, so only blend between first and last */
- for (i = first_valid + 1; i < last_valid; i++)
+ for (i = first_valid + 1; i < last_valid; i++) {
depth_arr[i] = FLT_MAX;
+ }
interp_depth = true;
}
@@ -819,8 +841,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
pt->time = ptc->time;
}
- if (depth_arr)
+ if (depth_arr) {
MEM_freeN(depth_arr);
+ }
}
/* add stroke to frame */
@@ -946,8 +969,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
pt2 = gps->points + i + 1;
/* only process if it hasn't been masked out... */
- if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT))
+ if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) {
continue;
+ }
gp_point_to_xy(&p->gsc, gps, pt1, &pc1[0], &pc1[1]);
gp_point_to_xy(&p->gsc, gps, pt2, &pc2[0], &pc2[1]);
@@ -1058,8 +1082,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* make sure the active view (at the starting time) is a 3d-view */
if (curarea == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No active view for painting\n");
+ }
return 0;
}
@@ -1088,10 +1113,11 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
if (ar->regiondata == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf(
"Error: 3D-View active region doesn't have any region data, so cannot be "
"drawable\n");
+ }
return 0;
}
break;
@@ -1118,8 +1144,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* check that gpencil data is allowed to be drawn */
if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil\n");
+ }
return 0;
}
break;
@@ -1179,8 +1206,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* unsupported views */
default: {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Annotations are not supported in this editor\n");
+ }
return 0;
}
}
@@ -1189,8 +1217,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr);
if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Current context doesn't allow for any Annotation data\n");
+ }
return 0;
}
else {
@@ -1254,8 +1283,9 @@ static void gp_session_cleanup(tGPsdata *p)
bGPdata *gpd = (p) ? p->gpd : NULL;
/* error checking */
- if (gpd == NULL)
+ if (gpd == NULL) {
return;
+ }
/* free stroke buffer */
if (gpd->runtime.sbuffer) {
@@ -1288,13 +1318,15 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
p->gpd->flag |= GP_DATA_ANNOTATIONS;
p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("Note"), true);
- if (p->custom_color[3])
+ if (p->custom_color[3]) {
copy_v3_v3(p->gpl->color, p->custom_color);
+ }
}
if (p->gpl->flag & GP_LAYER_LOCKED) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Cannot paint on locked layer\n");
+ }
return;
}
@@ -1329,7 +1361,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
if (has_layer_to_erase == false) {
p->status = GP_STATUS_CAPTURE;
- //if (G.debug & G_DEBUG)
+ // if (G.debug & G_DEBUG)
printf("Error: Eraser will not be affecting anything (gpencil_paint_init)\n");
return;
}
@@ -1338,17 +1370,20 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
/* Drawing Modes - Add a new frame if needed on the active layer */
short add_frame_mode = GP_GETFRAME_ADD_NEW;
- if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST)
+ if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) {
add_frame_mode = GP_GETFRAME_ADD_COPY;
- else
+ }
+ else {
add_frame_mode = GP_GETFRAME_ADD_NEW;
+ }
p->gpf = BKE_gpencil_layer_getframe(p->gpl, CFRA, add_frame_mode);
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No frame created (gpencil_paint_init)\n");
+ }
return;
}
else {
@@ -1471,8 +1506,9 @@ static void gp_paint_cleanup(tGPsdata *p)
}
/* "unlock" frame */
- if (p->gpf)
+ if (p->gpf) {
p->gpf->flag &= ~GP_FRAME_PAINT;
+ }
}
/* ------------------------------- */
@@ -1508,14 +1544,13 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr)
immUniform1f("dash_width", 12.0f);
immUniform1f("dash_factor", 0.5f);
- imm_draw_circle_wire_2d(
- shdr_pos,
- x,
- y,
- p->radius,
- /* XXX Dashed shader gives bad results with sets of small segments currently,
- * temp hack around the issue. :( */
- max_ii(8, p->radius / 2)); /* was fixed 40 */
+ imm_draw_circle_wire_2d(shdr_pos,
+ x,
+ y,
+ p->radius,
+ /* XXX Dashed shader gives bad results with sets of small segments
+ * currently, temp hack around the issue. :( */
+ max_ii(8, p->radius / 2)); /* was fixed 40 */
immUnbindProgram();
@@ -1634,10 +1669,12 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
/* ensure that the correct cursor icon is set */
static void gpencil_draw_cursor_set(tGPsdata *p)
{
- if (p->paintmode == GP_PAINTMODE_ERASER)
+ if (p->paintmode == GP_PAINTMODE_ERASER) {
WM_cursor_modal_set(p->win, BC_CROSSCURSOR); /* XXX need a better cursor */
- else
+ }
+ else {
WM_cursor_modal_set(p->win, BC_PAINTBRUSHCURSOR);
+ }
}
/* update UI indicators of status, including cursor and header prints */
@@ -1718,7 +1755,8 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph
p->mvalo[1] = p->mval[1];
p->opressure = p->pressure;
}
- /* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */
+ /* Only add current point to buffer if mouse moved
+ * (even though we got an event, it might be just noise). */
else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) {
/* try to add point */
short ok = gp_stroke_addpoint(p, p->mval, p->pressure, p->curtime);
@@ -1747,8 +1785,9 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph
BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke");
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Grease-Pencil Paint - Add Point Invalid\n");
+ }
return;
}
@@ -1839,8 +1878,9 @@ static void annotation_draw_apply_event(
/* special exception here for too high pressure values on first touch in
* windows for some tablets, then we just skip first touch...
*/
- if (tablet && (p->pressure >= 0.99f))
+ if (tablet && (p->pressure >= 0.99f)) {
return;
+ }
}
/* check if alt key is pressed and limit to straight lines */
@@ -1886,13 +1926,15 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
/* try to initialize context data needed while drawing */
if (!gpencil_draw_init(C, op, NULL)) {
- if (op->customdata)
+ if (op->customdata) {
MEM_freeN(op->customdata);
+ }
/* printf("\tGP - no valid data\n"); */
return OPERATOR_CANCELLED;
}
- else
+ else {
p = op->customdata;
+ }
/* printf("\tGP - Start redrawing stroke\n"); */
@@ -1984,19 +2026,23 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
}
}
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("GPencil - Starting Drawing\n");
+ }
/* try to initialize context data needed while drawing */
if (!gpencil_draw_init(C, op, event)) {
- if (op->customdata)
+ if (op->customdata) {
MEM_freeN(op->customdata);
- if (G.debug & G_DEBUG)
+ }
+ if (G.debug & G_DEBUG) {
printf("\tGP - no valid data\n");
+ }
return OPERATOR_CANCELLED;
}
- else
+ else {
p = op->customdata;
+ }
/* if empty erase capture and finish */
if (p->status == GP_STATUS_CAPTURE) {
@@ -2068,8 +2114,9 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
/* XXX: watch it with the paintmode! in future,
* it'd be nice to allow changing paint-mode when in sketching-sessions */
- if (gp_session_initdata(C, p))
+ if (gp_session_initdata(C, p)) {
gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C));
+ }
if (p->status != GP_STATUS_ERROR) {
p->status = GP_STATUS_PAINTING;
@@ -2157,7 +2204,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
p->ar = ar;
}
- /* we don't pass on key events, GP is used with key-modifiers - prevents Dkey to insert drivers */
+ /* We don't pass on key events, GP is used with key-modifiers -
+ * prevents Dkey to insert drivers. */
if (ISKEYBOARD(event->type)) {
if (ELEM(event->type, LEFTARROWKEY, DOWNARROWKEY, RIGHTARROWKEY, UPARROWKEY, ZKEY)) {
/* allow some keys:
@@ -2185,10 +2233,12 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
- //printf("\tGP - handle modal event...\n");
+ // printf("\tGP - handle modal event...\n");
- /* exit painting mode (and/or end current stroke)
- * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) as that would break polyline [#32647]
+ /* Exit painting mode (and/or end current stroke)
+ *
+ * NOTE: cannot do RIGHTMOUSE (as is standard for canceling)
+ * as that would break polyline T32647.
*/
if (ELEM(event->type, RETKEY, PADENTER, ESCKEY, SPACEKEY, EKEY)) {
/* exit() ends the current stroke before cleaning up */
@@ -2286,8 +2336,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__);
+ }
}
}
else if (p->ar) {
@@ -2302,8 +2353,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("%s: No active region found in GP Paint session data\n", __func__);
+ }
}
if (in_bounds) {
@@ -2382,8 +2434,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
case PADMINUS:
p->radius -= 5;
- if (p->radius <= 0)
+ if (p->radius <= 0) {
p->radius = 1;
+ }
break;
}
@@ -2404,8 +2457,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
/* gpencil modal operator stores area, which can be removed while using it (like fullscreen) */
- if (0 == gpencil_area_exists(C, p->sa))
+ if (0 == gpencil_area_exists(C, p->sa)) {
estate = OPERATOR_CANCELLED;
+ }
else {
/* update status indicators - cursor, header, etc. */
gpencil_draw_status_indicators(C, p);
@@ -2429,7 +2483,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* event doesn't need to be handled */
#if 0
printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n",
- event->type, event->type == MIDDLEMOUSE, event->type==MOUSEMOVE);
+ event->type,
+ event->type == MIDDLEMOUSE,
+ event->type == MOUSEMOVE);
#endif
break;
}
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 24bdbcc4cba..ef74aa28b63 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -121,9 +121,15 @@ static void gp_set_point_uniform_color(const bGPDspoint *pt, const float ink[4])
immUniformColor3fvAlpha(ink, alpha);
}
-static void gp_set_point_varying_color(const bGPDspoint *pt, const float ink[4], uint attr_id)
+static void gp_set_point_varying_color(const bGPDspoint *pt,
+ const float ink[4],
+ uint attr_id,
+ bool fix_strength)
{
float alpha = ink[3] * pt->strength;
+ if ((fix_strength) && (alpha >= 0.1f)) {
+ alpha = 1.0f;
+ }
CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
immAttr4ub(attr_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
}
@@ -186,7 +192,7 @@ static void gp_draw_stroke_volumetric_2d(const bGPDspoint *points,
mul_v3_m4v3(fpt, diff_mat, &pt->x);
gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
- gp_set_point_varying_color(pt, ink, color);
+ gp_set_point_varying_color(pt, ink, color, false);
immAttr1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */
immVertex2f(pos, co[0], co[1]);
}
@@ -214,7 +220,7 @@ static void gp_draw_stroke_volumetric_3d(const bGPDspoint *points,
const bGPDspoint *pt = points;
for (int i = 0; i < totpoints && pt; i++, pt++) {
- gp_set_point_varying_color(pt, ink, color);
+ gp_set_point_varying_color(pt, ink, color, false);
/* TODO: scale based on view transform */
immAttr1f(size, pt->pressure * thickness);
/* we can adjust size in vertex shader based on view/projection! */
@@ -274,7 +280,8 @@ static void gp_calc_stroke_text_coordinates(
}
}
-/* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */
+/* Triangulate stroke for high quality fill
+ * (this is done only if cache is null or stroke was modified). */
static void gp_triangulate_stroke_fill(bGPDstroke *gps)
{
BLI_assert(gps->totpoints >= 3);
@@ -324,8 +331,9 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps)
}
else {
/* No triangles needed - Free anything allocated previously */
- if (gps->triangles)
+ if (gps->triangles) {
MEM_freeN(gps->triangles);
+ }
gps->triangles = NULL;
}
@@ -375,7 +383,7 @@ static int gp_set_filling_texture(Image *image, short flag)
ImBuf *ibuf;
uint *bind = &image->bindcode[TEXTARGET_TEXTURE_2D];
int error = GL_NO_ERROR;
- ImageUser iuser = { NULL };
+ ImageUser iuser = {NULL};
void *lock;
iuser.ok = true;
@@ -388,8 +396,7 @@ static int gp_set_filling_texture(Image *image, short flag)
}
GPU_create_gl_tex(
- bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D,
- false, false, image);
+ bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, false, false, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -448,11 +455,12 @@ static void gp_draw_stroke_fill(bGPdata *gpd,
immUniform2fv("texture_scale", gp_style->texture_scale);
immUniform2fv("texture_offset", gp_style->texture_offset);
immUniform1f("texture_opacity", gp_style->texture_opacity);
- immUniform1i("t_mix", (gp_style->flag & GP_STYLE_COLOR_TEX_MIX) != 0);
+ immUniform1i("t_mix", (gp_style->flag & GP_STYLE_FILL_TEX_MIX) != 0);
immUniform1i("t_flip", (gp_style->flag & GP_STYLE_COLOR_FLIP_FILL) != 0);
#if 0 /* GPXX disabled, not used in annotations */
/* image texture */
- if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) || (gp_style->flag & GP_STYLE_COLOR_TEX_MIX)) {
+ if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) ||
+ (gp_style->flag & GP_STYLE_COLOR_TEX_MIX)) {
gp_set_filling_texture(gp_style->ima, gp_style->flag);
}
#endif
@@ -574,7 +582,7 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4
for (int i = 0; i < totpoints; i++, pt++) {
/* first point for adjacency (not drawn) */
if (i == 0) {
- gp_set_point_varying_color(points, ink, attr_id.color);
+ gp_set_point_varying_color(points, ink, attr_id.color, (bool)tgpw->is_fill_stroke);
if ((cyclic) && (totpoints > 2)) {
immAttr1f(attr_id.thickness, max_ff((points + totpoints - 1)->pressure * thickness, 1.0f));
@@ -587,7 +595,7 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4
immVertex3fv(attr_id.pos, fpt);
}
/* set point */
- gp_set_point_varying_color(pt, ink, attr_id.color);
+ gp_set_point_varying_color(pt, ink, attr_id.color, (bool)tgpw->is_fill_stroke);
immAttr1f(attr_id.thickness, max_ff(pt->pressure * thickness, 1.0f));
mul_v3_m4v3(fpt, tgpw->diff_mat, &pt->x);
immVertex3fv(attr_id.pos, fpt);
@@ -606,7 +614,9 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4
}
/* last adjacency point (not drawn) */
else {
- gp_set_point_varying_color(points + totpoints - 2, ink, attr_id.color);
+ gp_set_point_varying_color(
+ points + totpoints - 2, ink, attr_id.color, (bool)tgpw->is_fill_stroke);
+
immAttr1f(attr_id.thickness, max_ff((points + totpoints - 2)->pressure * thickness, 1.0f));
mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + totpoints - 2)->x);
immVertex3fv(attr_id.pos, fpt);
@@ -643,8 +653,8 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
/* TODO: fancy++ with the magic of shaders */
- /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) with connection
- * edges rotated to minimize shrinking artifacts, and rounded endcaps
+ /* tessellation code - draw stroke as series of connected quads (triangle strips in fact)
+ * with connection edges rotated to minimize shrinking artifacts, and rounded endcaps.
*/
{
const bGPDspoint *pt1, *pt2;
@@ -675,7 +685,8 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
float mt[2], sc[2]; /* gradient for thickness, point for end-cap */
float pthick; /* thickness at segment point */
- /* get x and y coordinates from point2 (point1 has already been computed in previous iteration). */
+ /* Get x and y coordinates from point2
+ * (point1 has already been computed in previous iteration). */
mul_v3_m4v3(fpt, diff_mat, &pt2->x);
gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, s1);
@@ -690,7 +701,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
pthick = (pt1->pressure * thickness * scalefac);
/* color of point */
- gp_set_point_varying_color(pt1, ink, attr_id.color);
+ gp_set_point_varying_color(pt1, ink, attr_id.color, false);
/* if the first segment, start of segment is segment's normal */
if (i == 0) {
@@ -765,7 +776,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points,
pthick = (pt2->pressure * thickness * scalefac);
/* color of point */
- gp_set_point_varying_color(pt2, ink, attr_id.color);
+ gp_set_point_varying_color(pt2, ink, attr_id.color, false);
/* calculate points for end of segment */
mt[0] = m2[0] * pthick;
@@ -816,26 +827,33 @@ static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag)
{
/* skip stroke if it isn't in the right display space for this drawing context */
/* 1) 3D Strokes */
- if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE))
+ if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) {
return false;
+ }
/* 2) Screen Space 2D Strokes */
- if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE))
+ if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) {
return false;
+ }
/* 3) Image Space (2D) */
- if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
+ if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) {
return false;
- if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
+ }
+ if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) {
return false;
+ }
/* skip stroke if it doesn't have any valid data */
- if ((gps->points == NULL) || (gps->totpoints < 1))
+ if ((gps->points == NULL) || (gps->totpoints < 1)) {
return false;
+ }
/* stroke can be drawn */
return true;
@@ -851,7 +869,9 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
GPU_enable_program_point_size();
- for (bGPDstroke *gps = tgpw->t_gpf->strokes.first; gps; gps = gps->next) {
+ bGPDstroke *gps_init = (tgpw->gps) ? tgpw->gps : tgpw->t_gpf->strokes.first;
+
+ for (bGPDstroke *gps = gps_init; gps; gps = gps->next) {
/* check if stroke can be drawn */
if (gp_can_draw_stroke(gps, tgpw->dflag) == false) {
continue;
@@ -899,7 +919,7 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
}
/* 3D Fill */
- //if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) {
+ // if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) {
if ((gps->totpoints >= 3) && (tgpw->disable_fill != 1)) {
/* set color using material, tint color and opacity */
interp_v3_v3v3(tfill, gp_style->fill_rgba, tgpw->tintcolor, tgpw->tintcolor[3]);
@@ -945,6 +965,14 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
copy_v4_v4(ink, tcolor);
}
}
+
+ /* if used for fill, set opacity to 1 */
+ if (tgpw->is_fill_stroke) {
+ if (ink[3] >= GPENCIL_ALPHA_OPACITY_THRESH) {
+ ink[3] = 1.0f;
+ }
+ }
+
if (gp_style->mode == GP_STYLE_MODE_DOTS) {
/* volumetric stroke drawing */
if (tgpw->disable_fill != 1) {
@@ -1070,6 +1098,10 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
}
}
}
+ /* if only one stroke, exit from loop */
+ if (tgpw->gps) {
+ break;
+ }
}
GPU_disable_program_point_size();
@@ -1116,6 +1148,7 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
tgpw.gpl = tgpil->gpl;
tgpw.gpf = tgpil->interFrame;
tgpw.t_gpf = tgpil->interFrame;
+ tgpw.gps = NULL;
tgpw.lthick = tgpil->gpl->line_change;
tgpw.opacity = 1.0;
@@ -1141,8 +1174,9 @@ static void UNUSED_FUNCTION(gp_draw_status_text)(const bGPdata *gpd, ARegion *ar
rcti rect;
/* Cannot draw any status text when drawing OpenGL Renders */
- if (G.f & G_FLAG_RENDER_VIEWPORT)
+ if (G.f & G_FLAG_RENDER_VIEWPORT) {
return;
+ }
/* Get bounds of region - Necessary to avoid problems with region overlap */
ED_region_visible_rect(ar, &rect);
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c
index 4724dc068b6..d0f44314c95 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -61,14 +61,16 @@ bool ED_gplayer_frames_looper(bGPDlayer *gpl, Scene *scene, short (*gpf_cb)(bGPD
bGPDframe *gpf;
/* error checker */
- if (gpl == NULL)
+ if (gpl == NULL) {
return false;
+ }
/* do loop */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
/* execute callback */
- if (gpf_cb(gpf, scene))
+ if (gpf_cb(gpf, scene)) {
return true;
+ }
}
/* nothing to return */
@@ -85,8 +87,9 @@ void ED_gplayer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel)
CfraElem *ce;
/* error checking */
- if (ELEM(NULL, gpl, elems))
+ if (ELEM(NULL, gpl, elems)) {
return;
+ }
/* loop through gp-frames, adding */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
@@ -110,13 +113,15 @@ bool ED_gplayer_frame_select_check(bGPDlayer *gpl)
bGPDframe *gpf;
/* error checking */
- if (gpl == NULL)
+ if (gpl == NULL) {
return false;
+ }
/* stop at the first one found */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
- if (gpf->flag & GP_FRAME_SELECT)
+ if (gpf->flag & GP_FRAME_SELECT) {
return true;
+ }
}
/* not found */
@@ -126,8 +131,9 @@ bool ED_gplayer_frame_select_check(bGPDlayer *gpl)
/* helper function - select gp-frame based on SELECT_* mode */
static void gpframe_select(bGPDframe *gpf, short select_mode)
{
- if (gpf == NULL)
+ if (gpf == NULL) {
return;
+ }
switch (select_mode) {
case SELECT_ADD:
@@ -148,8 +154,9 @@ void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode)
bGPDframe *gpf;
/* error checking */
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
/* handle according to mode */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
@@ -161,8 +168,9 @@ void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode)
void ED_gplayer_frame_select_set(bGPDlayer *gpl, short mode)
{
/* error checking */
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
/* now call the standard function */
ED_gpencil_select_frames(gpl, mode);
@@ -173,8 +181,9 @@ void ED_gpencil_select_frame(bGPDlayer *gpl, int selx, short select_mode)
{
bGPDframe *gpf;
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
gpf = BKE_gpencil_layer_find_frame(gpl, selx);
@@ -188,13 +197,15 @@ void ED_gplayer_frames_select_box(bGPDlayer *gpl, float min, float max, short se
{
bGPDframe *gpf;
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
/* only select those frames which are in bounds */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
- if (IN_RANGE(gpf->framenum, min, max))
+ if (IN_RANGE(gpf->framenum, min, max)) {
gpframe_select(gpf, select_mode);
+ }
}
}
@@ -206,8 +217,9 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked,
{
bGPDframe *gpf;
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
/* only select frames which are within the region */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
@@ -220,13 +232,15 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked,
/* check the necessary regions */
if (tool == BEZT_OK_CHANNEL_LASSO) {
/* Lasso */
- if (keyframe_region_lasso_test(ked->data, pt))
+ if (keyframe_region_lasso_test(ked->data, pt)) {
gpframe_select(gpf, select_mode);
+ }
}
else if (tool == BEZT_OK_CHANNEL_CIRCLE) {
/* Circle */
- if (keyframe_region_circle_test(ked->data, pt))
+ if (keyframe_region_circle_test(ked->data, pt)) {
gpframe_select(gpf, select_mode);
+ }
}
}
}
@@ -241,8 +255,9 @@ bool ED_gplayer_frames_delete(bGPDlayer *gpl)
bool changed = false;
/* error checking */
- if (gpl == NULL)
+ if (gpl == NULL) {
return false;
+ }
/* check for frames to delete */
for (gpf = gpl->frames.first; gpf; gpf = gpfn) {
@@ -263,8 +278,9 @@ void ED_gplayer_frames_duplicate(bGPDlayer *gpl)
bGPDframe *gpf, *gpfn;
/* error checking */
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
/* duplicate selected frames */
for (gpf = gpl->frames.first; gpf; gpf = gpfn) {
@@ -290,8 +306,9 @@ void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type)
{
bGPDframe *gpf;
- if (gpl == NULL)
+ if (gpl == NULL) {
return;
+ }
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
if (gpf->flag & GP_FRAME_SELECT) {
@@ -301,12 +318,14 @@ void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type)
}
/* -------------------------------------- */
-/* Copy and Paste Tools */
-/* - The copy/paste buffer currently stores a set of GP_Layers, with temporary
+/* Copy and Paste Tools:
+ * - The copy/paste buffer currently stores a set of GP_Layers, with temporary
* GP_Frames with the necessary strokes
- * - Unless there is only one element in the buffer, names are also tested to check for compatibility.
- * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of
- * the current frame and the 'first keyframe' (i.e. the earliest one in all channels).
+ * - Unless there is only one element in the buffer,
+ * names are also tested to check for compatibility.
+ * - All pasted frames are offset by the same amount.
+ * This is calculated as the difference in the times of the current frame and the
+ * 'first keyframe' (i.e. the earliest one in all channels).
* - The earliest frame is calculated per copy operation.
*/
@@ -362,10 +381,12 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac)
BLI_addtail(&copied_frames, new_frame);
/* extend extents for keyframes encountered */
- if (gpf->framenum < gp_anim_copy_firstframe)
+ if (gpf->framenum < gp_anim_copy_firstframe) {
gp_anim_copy_firstframe = gpf->framenum;
- if (gpf->framenum > gp_anim_copy_lastframe)
+ }
+ if (gpf->framenum > gp_anim_copy_lastframe) {
gp_anim_copy_lastframe = gpf->framenum;
+ }
}
}
@@ -458,8 +479,9 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode)
}
/* this situation might occur! */
- if (gpls == NULL)
+ if (gpls == NULL) {
continue;
+ }
/* add frames from buffer */
for (gpfs = gpls->frames.first; gpfs; gpfs = gpfs->next) {
@@ -493,8 +515,9 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode)
}
/* if no strokes (i.e. new frame) added, free gpf */
- if (BLI_listbase_is_empty(&gpf->strokes))
+ if (BLI_listbase_is_empty(&gpf->strokes)) {
BKE_gpencil_layer_delframe(gpld, gpf);
+ }
}
/* unapply offset from buffer-frame */
@@ -522,23 +545,26 @@ static short snap_gpf_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene))
static short snap_gpf_nearestsec(bGPDframe *gpf, Scene *scene)
{
float secf = (float)FPS;
- if (gpf->flag & GP_FRAME_SELECT)
+ if (gpf->flag & GP_FRAME_SELECT) {
gpf->framenum = (int)(floorf(gpf->framenum / secf + 0.5f) * secf);
+ }
return 0;
}
static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene)
{
- if (gpf->flag & GP_FRAME_SELECT)
+ if (gpf->flag & GP_FRAME_SELECT) {
gpf->framenum = (int)CFRA;
+ }
return 0;
}
static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene)
{
- if (gpf->flag & GP_FRAME_SELECT)
+ if (gpf->flag & GP_FRAME_SELECT) {
gpf->framenum = (int)ED_markers_find_nearest_marker_time(&scene->markers,
(float)gpf->framenum);
+ }
return 0;
}
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c
index d6e068926dd..f6ff5ed4f13 100644
--- a/source/blender/editors/gpencil/gpencil_add_stroke.c
+++ b/source/blender/editors/gpencil/gpencil_add_stroke.c
@@ -210,7 +210,8 @@ static const ColorTemplate gp_stroke_material_grey = {
/* ***************************************************************** */
/* Stroke API */
-/* add a Simple stroke with colors (original design created by Daniel M. Lara and Matias Mendiola) */
+/* Add a Simple stroke with colors
+ * (original design created by Daniel M. Lara and Matias Mendiola). */
void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
{
Main *bmain = CTX_data_main(C);
diff --git a/source/blender/editors/gpencil/gpencil_armature.c b/source/blender/editors/gpencil/gpencil_armature.c
index d99a630a45c..6ad89d2e38d 100644
--- a/source/blender/editors/gpencil/gpencil_armature.c
+++ b/source/blender/editors/gpencil/gpencil_armature.c
@@ -287,8 +287,9 @@ static void gpencil_add_verts_to_dgroups(
/* count the number of skinnable bones */
numbones = gpencil_bone_looper(ob, arm->bonebase.first, &looper_data, gpencil_bone_skinnable_cb);
- if (numbones == 0)
+ if (numbones == 0) {
return;
+ }
/* create an array of pointer to bones that are skinnable
* and fill it with all of the skinnable bones */
@@ -366,13 +367,15 @@ static void gpencil_add_verts_to_dgroups(
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
BKE_gpencil_dvert_ensure(gps);
@@ -477,6 +480,8 @@ static void gpencil_object_vgroup_calc_from_armature(const bContext *C,
*/
gpencil_add_verts_to_dgroups(C, ob, ob_arm, ratio, decay);
}
+
+ DEG_relations_tag_update(CTX_data_main(C));
}
bool ED_gpencil_add_armature_weights(
@@ -564,8 +569,9 @@ static int gpencil_generate_weights_exec(bContext *C, wmOperator *op)
const float decay = RNA_float_get(op->ptr, "decay");
/* sanity checks */
- if (ELEM(NULL, ob, gpd))
+ if (ELEM(NULL, ob, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* get armature */
const int arm_idx = RNA_enum_get(op->ptr, "armature");
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index ef0ebd06d07..9777a8190c1 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -88,6 +88,7 @@ typedef struct tGP_BrushEditData {
/* Current editor/region/etc. */
/* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */
Depsgraph *depsgraph;
+ struct Main *bmain;
Scene *scene;
Object *object;
@@ -190,8 +191,7 @@ static void gpsculpt_compute_lock_axis(tGP_BrushEditData *gso,
break;
}
case GP_LOCKAXIS_CURSOR: {
- /* compute a plane with cursor normal and position of the point
- before do the sculpt */
+ /* Compute a plane with cursor normal and position of the point before do the sculpt. */
const float scale[3] = {1.0f, 1.0f, 1.0f};
float plane_normal[3] = {0.0f, 0.0f, 1.0f};
float plane[4];
@@ -303,7 +303,8 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c
/* ----------------------------------------------- */
/* Smooth Brush */
-/* A simple (but slower + inaccurate) smooth-brush implementation to test the algorithm for stroke smoothing */
+/* A simple (but slower + inaccurate)
+ * smooth-brush implementation to test the algorithm for stroke smoothing. */
static bool gp_brush_smooth_apply(
tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
{
@@ -352,7 +353,8 @@ static bool gp_brush_thickness_apply(
inf = gp_brush_influence_calc(gso, radius, co) / 10.0f;
/* apply */
- // XXX: this is much too strong, and it should probably do some smoothing with the surrounding stuff
+ /* XXX: this is much too strong,
+ * and it should probably do some smoothing with the surrounding stuff. */
if (gp_brush_invert_check(gso)) {
/* make line thinner - reduce stroke pressure */
pt->pressure -= inf;
@@ -367,8 +369,9 @@ static bool gp_brush_thickness_apply(
* the upper end of this range. Therefore, we don't actually clamp
* down on the upper end.
*/
- if (pt->pressure < 0.0f)
+ if (pt->pressure < 0.0f) {
pt->pressure = 0.0f;
+ }
return true;
}
@@ -802,7 +805,16 @@ static bool gp_brush_randomize_apply(
mul_v2_fl(svec, fac);
}
- //printf("%f %f (%f), nco = {%f %f}, co = %d %d\n", svec[0], svec[1], fac, nco[0], nco[1], co[0], co[1]);
+#if 0
+ printf("%f %f (%f), nco = {%f %f}, co = %d %d\n",
+ svec[0],
+ svec[1],
+ fac,
+ nco[0],
+ nco[1],
+ co[0],
+ co[1]);
+#endif
/* convert to dataspace */
if (gps->flag & GP_STROKE_3DSPACE) {
@@ -896,6 +908,7 @@ static bool gp_brush_weight_apply(
if (gso->vrgroup == -1) {
if (gso->object) {
BKE_object_defgroup_add(gso->object);
+ DEG_relations_tag_update(gso->bmain);
gso->vrgroup = 0;
}
}
@@ -927,8 +940,9 @@ static bool gp_brush_weight_apply(
}
/* weight should stay within [0.0, 1.0] */
- if (pt->pressure < 0.0f)
+ if (pt->pressure < 0.0f) {
pt->pressure = 0.0f;
+ }
return true;
}
@@ -957,7 +971,7 @@ typedef struct tGPSB_CloneBrushData {
/* for "stamp" mode, the currently pasted brushes */
bGPDstroke **new_strokes;
- /* mapping from colors referenced per stroke, to the new colours in the "pasted" strokes */
+ /** Mapping from colors referenced per stroke, to the new colors in the "pasted" strokes. */
GHash *new_colors;
} tGPSB_CloneBrushData;
@@ -1005,7 +1019,7 @@ static void gp_brush_clone_init(bContext *C, tGP_BrushEditData *gso)
}
/* Init colormap for mapping between the pasted stroke's source color (names)
- * and the final colours that will be used here instead.
+ * and the final colors that will be used here instead.
*/
data->new_colors = gp_copybuf_validate_colormap(C);
}
@@ -1107,7 +1121,8 @@ static void gp_brush_clone_adjust(tGP_BrushEditData *gso)
gp_brush_grab_calc_dvec(gso);
/* For each of the stored strokes, apply the offset to each point */
- /* NOTE: Again this assumes that in the 3D view, we only have 3d space and not screenspace strokes... */
+ /* NOTE: Again this assumes that in the 3D view,
+ * we only have 3d space and not screenspace strokes... */
for (snum = 0; snum < data->totitems; snum++) {
bGPDstroke *gps = data->new_strokes[snum];
bGPDspoint *pt;
@@ -1154,7 +1169,8 @@ static bool gpsculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso)
}
else {
/* Continuous - Just keep pasting everytime we move */
- /* TODO: The spacing of repeat should be controlled using a "stepsize" or similar property? */
+ /* TODO: The spacing of repeat should be controlled using a
+ * "stepsize" or similar property? */
gp_brush_clone_add(C, gso);
}
}
@@ -1206,6 +1222,7 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
op->customdata = gso;
gso->depsgraph = CTX_data_depsgraph(C);
+ gso->bmain = CTX_data_main(C);
/* store state */
gso->settings = gpsculpt_get_settings(scene);
gso->gp_brush = gpsculpt_get_brush(scene, is_weight_mode);
@@ -1309,7 +1326,7 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
gpsculpt_brush_header_set(C, gso);
/* setup cursor drawing */
- //WM_cursor_modal_set(CTX_wm_window(C), BC_CROSSCURSOR);
+ // WM_cursor_modal_set(CTX_wm_window(C), BC_CROSSCURSOR);
if (gso->sa->spacetype != SPACE_VIEW3D) {
ED_gpencil_toggle_brush_cursor(C, true, NULL);
}
@@ -1383,8 +1400,9 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
int cfra_eval = (int)DEG_get_ctime(gso->depsgraph);
/* only try to add a new frame if this is the first stroke, or the frame has changed */
- if ((gpd == NULL) || (cfra_eval == gso->cfra))
+ if ((gpd == NULL) || (cfra_eval == gso->cfra)) {
return;
+ }
/* go through each layer, and ensure that we've got a valid frame to use */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
@@ -1392,9 +1410,10 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
bGPDframe *gpf = gpl->actframe;
- /* Make a new frame to work on if the layer's frame and the current scene frame don't match up
+ /* Make a new frame to work on if the layer's frame
+ * and the current scene frame don't match up:
* - This is useful when animating as it saves that "uh-oh" moment when you realize you've
- * spent too much time editing the wrong frame...
+ * spent too much time editing the wrong frame.
*/
// XXX: should this be allowed when framelock is enabled?
if (gpf->framenum != cfra_eval) {
@@ -1454,7 +1473,8 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso,
pt1 = gps->points + i;
pt2 = gps->points + i + 1;
- /* Skip if neither one is selected (and we are only allowed to edit/consider selected points) */
+ /* Skip if neither one is selected
+ * (and we are only allowed to edit/consider selected points) */
if (gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) {
if (!(pt1->flag & GP_SPOINT_SELECT) && !(pt2->flag & GP_SPOINT_SELECT)) {
include_last = false;
@@ -1502,9 +1522,10 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso,
changed |= ok;
}
else if (include_last) {
- /* This case is for cases where for whatever reason the second vert (1st here) doesn't get included
- * because the whole edge isn't in bounds, but it would've qualified since it did with the
- * previous step (but wasn't added then, to avoid double-ups)
+ /* This case is for cases where for whatever reason the second vert (1st here)
+ * doesn't get included because the whole edge isn't in bounds,
+ * but it would've qualified since it did with the previous step
+ * (but wasn't added then, to avoid double-ups).
*/
changed |= apply(gso, gps, i, radius, pc1);
include_last = false;
@@ -1722,10 +1743,12 @@ static void gpsculpt_brush_apply(bContext *C, wmOperator *op, PointerRNA *itempt
gso->pressure = RNA_float_get(itemptr, "pressure");
- if (RNA_boolean_get(itemptr, "pen_flip"))
+ if (RNA_boolean_get(itemptr, "pen_flip")) {
gso->flag |= GP_SCULPT_FLAG_INVERT;
- else
+ }
+ else {
gso->flag &= ~GP_SCULPT_FLAG_INVERT;
+ }
/* Store coordinates as reference, if operator just started running */
if (gso->first) {
@@ -1825,8 +1848,9 @@ static void gpsculpt_brush_apply_event(bContext *C, wmOperator *op, const wmEven
/* reapply */
static int gpsculpt_brush_exec(bContext *C, wmOperator *op)
{
- if (!gpsculpt_brush_init(C, op))
+ if (!gpsculpt_brush_init(C, op)) {
return OPERATOR_CANCELLED;
+ }
RNA_BEGIN (op->ptr, itemptr, "stroke") {
gpsculpt_brush_apply(C, op, &itemptr);
@@ -1855,8 +1879,9 @@ static int gpsculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *eve
}
/* init painting data */
- if (!gpsculpt_brush_init(C, op))
+ if (!gpsculpt_brush_init(C, op)) {
return OPERATOR_CANCELLED;
+ }
gso = op->customdata;
@@ -1982,7 +2007,7 @@ static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *even
/* Painting mbut release = Stop painting (back to idle) */
case LEFTMOUSE:
- //BLI_assert(event->val == KM_RELEASE);
+ // BLI_assert(event->val == KM_RELEASE);
if (is_modal) {
/* go back to idling... */
gso->is_painting = false;
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c
index c1c797b15be..5afa379e04f 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -79,6 +79,7 @@
#include "ED_view3d.h"
#include "ED_clip.h"
#include "ED_keyframing.h"
+#include "ED_object.h"
#include "gpencil_intern.h"
@@ -328,9 +329,9 @@ static int gp_find_end_of_stroke_idx(tGpTimingData *gtd,
else {
float delta, min, max;
- /* This code ensures that if the first gaps have been shorter than average gap_duration,
- * next gaps will tend to be longer (i.e. try to recover the lateness), and vice-versa!
- */
+ /* This code ensures that if the first gaps
+ * have been shorter than average gap_duration, next gaps
+ * will tend to be longer (i.e. try to recover the lateness), and vice-versa! */
delta = delta_time - (gtd->gap_duration * (*nbr_done_gaps));
/* Clamp min between [-gap_randomness, 0.0], with lower delta giving higher min */
@@ -501,8 +502,9 @@ static void gp_stroke_path_animation(bContext *C,
PropertyRNA *prop = NULL;
int nbr_gaps = 0, i;
- if (gtd->mode == GP_STROKECONVERT_TIMING_NONE)
+ if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) {
return;
+ }
/* gap_duration and gap_randomness are in frames, but we need seconds!!! */
gtd->gap_duration = FRA2TIME(gtd->gap_duration);
@@ -693,8 +695,10 @@ static void gp_stroke_to_path(bContext *C,
* the last segment to get the first point (p1) position and timing.
* - If we do not have those (quite odd, but may happen), we linearly interpolate the last point
* with the first point of the current stroke.
- * The same goes for the second point, first segment of the current stroke is "negatively" extrapolated
- * if it exists, else (if the stroke is a single point), linear interpolation with last curve point...
+ *
+ * The same goes for the second point, first segment of the current stroke is "negatively"
+ * extrapolated if it exists, else (if the stroke is a single point),
+ * linear interpolation with last curve point.
*/
if (curnu && !stitch && old_nbp) {
float p1[3], p2[3], p[3], next_p[3];
@@ -774,8 +778,9 @@ static void gp_stroke_to_path(bContext *C,
dt = -GAP_DFAC; /* Rather arbitrary too! */
}
bp = &nu->bp[old_nbp];
- /* Note we can't give anything else than 0.0 as time here, since a negative one (which would be expected value)
- * would not work (it would be *before* gtd->inittime, which is not supported currently).
+ /* Note we can't give anything else than 0.0 as time here, since a negative one
+ * (which would be expected value) would not work
+ * (it would be *before* gtd->inittime, which is not supported currently).
*/
gp_stroke_to_path_add_point(
gtd, bp, p, p, do_gtd, gps->inittime, dt, 0.0f, rad_fac, minmax_weights);
@@ -907,9 +912,10 @@ static void gp_stroke_to_bezier(bContext *C,
/* create new 'nurb' or extend current one within the curve */
if (nu) {
old_nbezt = nu->pntsu;
- /* If we do stitch, first point of current stroke is assumed the same as last point of previous stroke,
- * so no need to add it.
- * If no stitch, we want to add two additional points to make a "zero-radius" link between both strokes.
+ /* If we do stitch, first point of current stroke is assumed the same as last point of
+ * previous stroke, so no need to add it.
+ * If no stitch, we want to add two additional points to make a "zero-radius"
+ * link between both strokes.
*/
BKE_nurb_bezierPoints_add(nu, gps->totpoints + ((stitch) ? -1 : 2) + add_start_end_points);
}
@@ -958,12 +964,15 @@ static void gp_stroke_to_bezier(bContext *C,
/* Create "link points" */
/* About "zero-radius" point interpolations:
- * - If we have at least two points in current curve (most common case), we linearly extrapolate
- * the last segment to get the first point (p1) position and timing.
- * - If we do not have those (quite odd, but may happen), we linearly interpolate the last point
- * with the first point of the current stroke.
- * The same goes for the second point, first segment of the current stroke is "negatively" extrapolated
- * if it exists, else (if the stroke is a single point), linear interpolation with last curve point...
+ * - If we have at least two points in current curve (most common case),
+ * we linearly extrapolate the last segment to get the first point (p1) position and timing.
+ * - If we do not have those (quite odd, but may happen),
+ * we linearly interpolate the last point with the first point of the current stroke.
+ *
+ * The same goes for the second point,
+ * first segment of the current stroke is "negatively" extrapolated
+ * if it exists, else (if the stroke is a single point),
+ * linear interpolation with last curve point.
*/
else {
float p1[3], p2[3];
@@ -1133,7 +1142,8 @@ static void gp_stroke_to_bezier(bContext *C,
/* The end point */
interp_v3_v3v3(h1, p, prev_bezt->vec[1], BEZT_HANDLE_FAC);
interp_v3_v3v3(h2, p, prev_bezt->vec[1], -BEZT_HANDLE_FAC);
- /* Note bezt has already been incremented in main loop above, so it points to the right place. */
+ /* Note bezt has already been incremented in main loop above,
+ * so it points to the right place. */
gp_stroke_to_bezier_add_point(gtd,
bezt,
p,
@@ -1206,10 +1216,12 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2
int i;
/* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */
- if (IS_EQF(delta, minmax_weights[1]))
+ if (IS_EQF(delta, minmax_weights[1])) {
fac = 1.0f;
- else
+ }
+ else {
fac = 1.0f / (minmax_weights[1] - delta);
+ }
for (nu = cu->nurb.first; nu; nu = nu->next) {
if (nu->bezt) {
@@ -1277,12 +1289,14 @@ static void gp_layer_to_curve(bContext *C,
rctf subrect, *subrect_ptr = NULL;
/* error checking */
- if (ELEM(NULL, gpd, gpl, gpf))
+ if (ELEM(NULL, gpd, gpl, gpf)) {
return;
+ }
/* only convert if there are any strokes on this layer's frame to convert */
- if (BLI_listbase_is_empty(&gpf->strokes))
+ if (BLI_listbase_is_empty(&gpf->strokes)) {
return;
+ }
/* initialize camera framing */
if (gp_camera_view_subrect(C, &subrect)) {
@@ -1382,9 +1396,7 @@ static void gp_layer_to_curve(bContext *C,
}
}
- /* set the layer and select */
- base_new->flag |= SELECT;
- BKE_scene_object_base_flag_sync_from_base(base_new);
+ ED_object_base_select(base_new, BA_SELECT);
}
/* --- */
@@ -1405,8 +1417,9 @@ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOpe
bool valid = true;
if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) ||
- !(gps = gpf->strokes.first))
+ !(gps = gpf->strokes.first)) {
return false;
+ }
do {
base_time = cur_time = gps->inittime;
@@ -1572,13 +1585,15 @@ static bool gp_convert_poll_property(const bContext *UNUSED(C),
}
/* Never show this prop */
- if (STREQ(prop_id, "use_timing_data"))
+ if (STREQ(prop_id, "use_timing_data")) {
return false;
+ }
if (link_strokes) {
/* Only show when link_stroke is true */
- if (STREQ(prop_id, "timing_mode"))
+ if (STREQ(prop_id, "timing_mode")) {
return true;
+ }
if (timing_mode != GP_STROKECONVERT_TIMING_NONE) {
/* Only show when link_stroke is true and stroke timing is enabled */
@@ -1587,25 +1602,30 @@ static bool gp_convert_poll_property(const bContext *UNUSED(C),
}
/* Only show if we have valid timing data! */
- if (valid_timing && STREQ(prop_id, "use_realtime"))
+ if (valid_timing && STREQ(prop_id, "use_realtime")) {
return true;
+ }
/* Only show if realtime or valid_timing is false! */
- if ((!realtime || !valid_timing) && STREQ(prop_id, "end_frame"))
+ if ((!realtime || !valid_timing) && STREQ(prop_id, "end_frame")) {
return true;
+ }
if (valid_timing && timing_mode == GP_STROKECONVERT_TIMING_CUSTOMGAP) {
/* Only show for custom gaps! */
- if (STREQ(prop_id, "gap_duration"))
+ if (STREQ(prop_id, "gap_duration")) {
return true;
+ }
/* Only show randomness for non-null custom gaps! */
- if (STREQ(prop_id, "gap_randomness") && (gap_duration > 0.0f))
+ if (STREQ(prop_id, "gap_randomness") && (gap_duration > 0.0f)) {
return true;
+ }
/* Only show seed for randomize action! */
- if (STREQ(prop_id, "seed") && (gap_duration > 0.0f) && (gap_randomness > 0.0f))
+ if (STREQ(prop_id, "seed") && (gap_duration > 0.0f) && (gap_randomness > 0.0f)) {
return true;
+ }
}
}
}
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index c91c543e746..f44c90001e1 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -124,7 +124,8 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
id_us_min(&gpd->id);
}
- /* add new datablock, with a single layer ready to use (so users don't have to perform an extra step) */
+ /* Add new datablock, with a single layer ready to use
+ * (so users don't have to perform an extra step). */
if (is_annotation) {
bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations"));
*gpd_ptr = gpd;
@@ -297,8 +298,9 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op)
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
/* sanity checks */
- if (ELEM(NULL, gpd, gpl))
+ if (ELEM(NULL, gpd, gpl)) {
return OPERATOR_CANCELLED;
+ }
if (gpl->flag & GP_LAYER_LOCKED) {
BKE_report(op->reports, RPT_ERROR, "Cannot delete locked layers");
@@ -309,10 +311,12 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op)
* - use the one after if this is the first
* - if this is the only layer, this naturally becomes NULL
*/
- if (gpl->prev)
+ if (gpl->prev) {
BKE_gpencil_layer_setactive(gpd, gpl->prev);
- else
+ }
+ else {
BKE_gpencil_layer_setactive(gpd, gpl->next);
+ }
/* delete the layer now... */
BKE_gpencil_layer_delete(gpd, gpl);
@@ -353,8 +357,9 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op)
const int direction = RNA_enum_get(op->ptr, "type") * -1;
/* sanity checks */
- if (ELEM(NULL, gpd, gpl))
+ if (ELEM(NULL, gpd, gpl)) {
return OPERATOR_CANCELLED;
+ }
BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) {
@@ -397,8 +402,9 @@ static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op))
bGPDlayer *new_layer;
/* sanity checks */
- if (ELEM(NULL, gpd, gpl))
+ if (ELEM(NULL, gpd, gpl)) {
return OPERATOR_CANCELLED;
+ }
/* make copy of layer, and add it immediately after the existing layer */
new_layer = BKE_gpencil_layer_duplicate(gpl);
@@ -445,19 +451,22 @@ static bool gp_layer_duplicate_object_poll(bContext *C)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = CTX_data_active_object(C);
- if ((ob == NULL) || (ob->type != OB_GPENCIL))
+ if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
+ }
bGPdata *gpd = (bGPdata *)ob->data;
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
- if (gpl == NULL)
+ if (gpl == NULL) {
return false;
+ }
/* check there are more grease pencil objects */
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
- if ((base->object != ob) && (base->object->type == OB_GPENCIL))
+ if ((base->object != ob) && (base->object->type == OB_GPENCIL)) {
return true;
+ }
}
return false;
@@ -590,8 +599,9 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op)
int mode = RNA_enum_get(op->ptr, "mode");
/* sanity checks */
- if (ELEM(NULL, gpd, gpl))
+ if (ELEM(NULL, gpd, gpl)) {
return OPERATOR_CANCELLED;
+ }
if (mode == 0) {
BKE_gpencil_frame_addcopy(gpl, cfra_eval);
@@ -655,16 +665,18 @@ static int gp_frame_clean_fill_exec(bContext *C, wmOperator *op)
if ((gpf == gpl->actframe) || (mode == GP_FRAME_CLEAN_FILL_ALL)) {
bGPDstroke *gps, *gpsn;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* simply delete strokes which are no fill */
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* free stroke */
if (gps->flag & GP_STROKE_NOFILL) {
@@ -737,16 +749,18 @@ static int gp_frame_clean_loose_exec(bContext *C, wmOperator *op)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* simply delete strokes which are no loose */
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* free stroke */
if (gps->totpoints <= limit) {
@@ -817,8 +831,9 @@ static int gp_hide_exec(bContext *C, wmOperator *op)
bool unselected = RNA_boolean_get(op->ptr, "unselected");
/* sanity checks */
- if (ELEM(NULL, gpd, layer))
+ if (ELEM(NULL, gpd, layer)) {
return OPERATOR_CANCELLED;
+ }
if (unselected) {
bGPDlayer *gpl;
@@ -897,8 +912,9 @@ static int gp_reveal_exec(bContext *C, wmOperator *op)
const bool select = RNA_boolean_get(op->ptr, "select");
/* sanity checks */
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
@@ -957,8 +973,9 @@ static int gp_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
bGPDlayer *gpl;
/* sanity checks */
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
/* make all layers non-editable */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
@@ -996,8 +1013,9 @@ static int gp_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
bGPDlayer *gpl;
/* sanity checks */
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
/* make all layers editable again */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
@@ -1036,8 +1054,9 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op)
int flags = GP_LAYER_LOCKED;
bool isolate = false;
- if (RNA_boolean_get(op->ptr, "affect_visibility"))
+ if (RNA_boolean_get(op->ptr, "affect_visibility")) {
flags |= GP_LAYER_HIDE;
+ }
if (ELEM(NULL, gpd, layer)) {
BKE_report(op->reports, RPT_ERROR, "No active layer to isolate");
@@ -1047,8 +1066,9 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op)
/* Test whether to isolate or clear all flags */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* Skip if this is the active layer */
- if (gpl == layer)
+ if (gpl == layer) {
continue;
+ }
/* If the flags aren't set, that means that the layer is
* not alone, so we have some layers to isolate still
@@ -1064,10 +1084,12 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op)
if (isolate) {
/* Set flags on all "other" layers */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- if (gpl == layer)
+ if (gpl == layer) {
continue;
- else
+ }
+ else {
gpl->flag |= flags;
+ }
}
}
else {
@@ -1424,18 +1446,21 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* only if selected */
if (gps->flag & GP_STROKE_SELECT) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
continue;
+ }
/* assign new color */
gps->mat_nr = idx;
@@ -1485,8 +1510,9 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
short *totcol = give_totcolp(ob);
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* first lock all colors */
for (short i = 0; i < *totcol; i++) {
@@ -1609,8 +1635,9 @@ static int gpencil_vertex_group_assign_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = CTX_data_active_object(C);
/* sanity checks */
- if (ELEM(NULL, ts, ob, ob->data))
+ if (ELEM(NULL, ts, ob, ob->data)) {
return OPERATOR_CANCELLED;
+ }
ED_gpencil_vgroup_assign(C, ob, ts->vgroup_weight);
@@ -1643,8 +1670,9 @@ static int gpencil_vertex_group_remove_from_exec(bContext *C, wmOperator *UNUSED
Object *ob = CTX_data_active_object(C);
/* sanity checks */
- if (ELEM(NULL, ob, ob->data))
+ if (ELEM(NULL, ob, ob->data)) {
return OPERATOR_CANCELLED;
+ }
ED_gpencil_vgroup_remove(C, ob);
@@ -1676,8 +1704,9 @@ static int gpencil_vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = CTX_data_active_object(C);
/* sanity checks */
- if (ELEM(NULL, ob, ob->data))
+ if (ELEM(NULL, ob, ob->data)) {
return OPERATOR_CANCELLED;
+ }
ED_gpencil_vgroup_select(C, ob);
@@ -1709,8 +1738,9 @@ static int gpencil_vertex_group_deselect_exec(bContext *C, wmOperator *UNUSED(op
Object *ob = CTX_data_active_object(C);
/* sanity checks */
- if (ELEM(NULL, ob, ob->data))
+ if (ELEM(NULL, ob, ob->data)) {
return OPERATOR_CANCELLED;
+ }
ED_gpencil_vgroup_deselect(C, ob);
@@ -2091,7 +2121,10 @@ typedef struct tJoinGPencil_AdtFixData {
GHash *names_map;
} tJoinGPencil_AdtFixData;
-/* Callback to pass to BKE_fcurves_main_cb() for RNA Paths attached to each F-Curve used in the AnimData */
+/**
+ * Callback to pass to #BKE_fcurves_main_cb()
+ * for RNA Paths attached to each F-Curve used in the #AnimData.
+ */
static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data)
{
tJoinGPencil_AdtFixData *afd = (tJoinGPencil_AdtFixData *)user_data;
@@ -2168,8 +2201,9 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
bool ok = false;
/* Ensure we're in right mode and that the active object is correct */
- if (!ob_active || ob_active->type != OB_GPENCIL)
+ if (!ob_active || ob_active->type != OB_GPENCIL) {
return OPERATOR_CANCELLED;
+ }
bGPdata *gpd = (bGPdata *)ob_active->data;
if ((!gpd) || GPENCIL_ANY_MODE(gpd)) {
@@ -2374,7 +2408,7 @@ static bool gpencil_active_color_poll(bContext *C)
return false;
}
-/* ******************* Lock and hide any color non used in current layer ************************** */
+/* **************** Lock and hide any color non used in current layer ************************** */
static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
@@ -2382,14 +2416,16 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
MaterialGPencilStyle *gp_style = NULL;
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* first lock and hide all colors */
Material *ma = NULL;
short *totcol = give_totcolp(ob);
- if (totcol == 0)
+ if (totcol == 0) {
return OPERATOR_CANCELLED;
+ }
for (short i = 0; i < *totcol; i++) {
ma = give_current_material(ob, i + 1);
@@ -2406,8 +2442,9 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
(gpl->flag & GP_LAYER_ACTIVE)) {
for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
ma = give_current_material(ob, gps->mat_nr + 1);
DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
@@ -2459,8 +2496,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
int flags = GP_STYLE_COLOR_LOCKED;
bool isolate = false;
- if (RNA_boolean_get(op->ptr, "affect_visibility"))
+ if (RNA_boolean_get(op->ptr, "affect_visibility")) {
flags |= GP_STYLE_COLOR_HIDE;
+ }
if (ELEM(NULL, gpd, active_color)) {
BKE_report(op->reports, RPT_ERROR, "No active color to isolate");
@@ -2473,8 +2511,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
for (short i = 0; i < *totcol; i++) {
ma = give_current_material(ob, i + 1);
/* Skip if this is the active one */
- if (ma == active_ma)
+ if (ma == active_ma) {
continue;
+ }
/* If the flags aren't set, that means that the color is
* not alone, so we have some colors to isolate still
@@ -2492,10 +2531,12 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
for (short i = 0; i < *totcol; i++) {
ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
- if (gp_style == active_color)
+ if (gp_style == active_color) {
continue;
- else
+ }
+ else {
gp_style->flag |= flags;
+ }
DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
}
}
@@ -2556,8 +2597,9 @@ static int gpencil_color_hide_exec(bContext *C, wmOperator *op)
Material *ma = NULL;
short *totcol = give_totcolp(ob);
- if (totcol == 0)
+ if (totcol == 0) {
return OPERATOR_CANCELLED;
+ }
if (unselected) {
/* hide unselected */
@@ -2616,8 +2658,9 @@ static int gpencil_color_reveal_exec(bContext *C, wmOperator *UNUSED(op))
Material *ma = NULL;
short *totcol = give_totcolp(ob);
- if (totcol == 0)
+ if (totcol == 0) {
return OPERATOR_CANCELLED;
+ }
/* make all colors visible */
MaterialGPencilStyle *gp_style = NULL;
@@ -2666,8 +2709,9 @@ static int gpencil_color_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
Material *ma = NULL;
short *totcol = give_totcolp(ob);
- if (totcol == 0)
+ if (totcol == 0) {
return OPERATOR_CANCELLED;
+ }
/* make all layers non-editable */
MaterialGPencilStyle *gp_style = NULL;
@@ -2716,8 +2760,9 @@ static int gpencil_color_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
Material *ma = NULL;
short *totcol = give_totcolp(ob);
- if (totcol == 0)
+ if (totcol == 0) {
return OPERATOR_CANCELLED;
+ }
/* make all layers editable again*/
MaterialGPencilStyle *gp_style = NULL;
@@ -2767,8 +2812,9 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op)
const bool deselected = RNA_boolean_get(op->ptr, "deselect");
/* sanity checks */
- if (ELEM(NULL, gpd, gp_style))
+ if (ELEM(NULL, gpd, gp_style)) {
return OPERATOR_CANCELLED;
+ }
/* read all strokes and select*/
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
@@ -2782,11 +2828,13 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op)
/* verify something to do */
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
continue;
+ }
/* select */
if (ob->actcol == gps->mat_nr + 1) {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 40e1e483f41..463c2144276 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -286,8 +286,9 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op)
is_object = true;
}
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
/* Just toggle paintmode flag... */
gpd->flag ^= GP_DATA_STROKE_PAINTMODE;
@@ -386,8 +387,9 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op)
is_object = true;
}
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
/* Just toggle sculptmode flag... */
gpd->flag ^= GP_DATA_STROKE_SCULPTMODE;
@@ -475,8 +477,9 @@ static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op)
is_object = true;
}
- if (gpd == NULL)
+ if (gpd == NULL) {
return OPERATOR_CANCELLED;
+ }
/* Just toggle weightmode flag... */
gpd->flag ^= GP_DATA_STROKE_WEIGHTMODE;
@@ -545,8 +548,9 @@ void GPENCIL_OT_weightmode_toggle(wmOperatorType *ot)
static int gpencil_hideselect_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
- if (v3d == NULL)
+ if (v3d == NULL) {
return OPERATOR_CANCELLED;
+ }
/* Just toggle alpha... */
if (v3d->vertex_opacity > 0.0f) {
@@ -615,7 +619,7 @@ static void gp_duplicate_points(const bGPDstroke *gps,
else if (i == gps->totpoints - 1) {
len = i - start_idx + 1;
}
- //printf("copying from %d to %d = %d\n", start_idx, i, len);
+ // printf("copying from %d to %d = %d\n", start_idx, i, len);
/* make copies of the relevant data */
if (len) {
@@ -685,8 +689,9 @@ static int gp_duplicate_exec(bContext *C, wmOperator *op)
bGPDframe *gpf = gpl->actframe;
bGPDstroke *gps;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* make copies of selected strokes, and deselect these once we're done */
for (gps = gpf->strokes.first; gps; gps = gps->next) {
@@ -931,13 +936,15 @@ static int gp_extrude_exec(bContext *C, wmOperator *op)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
if (gps->flag & GP_STROKE_SELECT) {
gpencil_add_move_points(gpf, gps);
@@ -1062,7 +1069,8 @@ void ED_gpencil_strokes_copybuf_free(void)
gp_strokes_copypastebuf.first = gp_strokes_copypastebuf.last = NULL;
}
-/* Ensure that destination datablock has all the colours the pasted strokes need
+/**
+ * Ensure that destination datablock has all the colors the pasted strokes need.
* Helper function for copy-pasting strokes
*/
GHash *gp_copybuf_validate_colormap(bContext *C)
@@ -1123,14 +1131,16 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op)
bGPDframe *gpf = gpl->actframe;
bGPDstroke *gps;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* make copies of selected strokes, and deselect these once we're done */
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
if (gps->flag & GP_STROKE_SELECT) {
if (gps->totpoints == 1) {
@@ -1202,7 +1212,7 @@ void GPENCIL_OT_copy(wmOperatorType *ot)
ot->poll = gp_stroke_edit_poll;
/* flags */
- //ot->flag = OPTYPE_REGISTER;
+ // ot->flag = OPTYPE_REGISTER;
}
/* --------------------- */
@@ -1212,8 +1222,9 @@ static bool gp_strokes_paste_poll(bContext *C)
{
/* 1) Must have GP datablock to paste to
* - We don't need to have an active layer though, as that can easily get added
- * - If the active layer is locked, we can't paste there, but that should prompt a warning instead
- * 2) Copy buffer must at least have something (though it may be the wrong sort...)
+ * - If the active layer is locked, we can't paste there,
+ * but that should prompt a warning instead.
+ * 2) Copy buffer must at least have something (though it may be the wrong sort...).
*/
return (ED_gpencil_data_get_active(C) != NULL) &&
(!BLI_listbase_is_empty(&gp_strokes_copypastebuf));
@@ -1273,13 +1284,16 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
}
if (ok == false) {
- /* XXX: this check is not 100% accurate (i.e. image editor is incompatible with normal 2D strokes),
- * but should be enough to give users a good idea of what's going on
+ /* XXX: this check is not 100% accurate
+ * (i.e. image editor is incompatible with normal 2D strokes),
+ * but should be enough to give users a good idea of what's going on.
*/
- if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D)
+ if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
BKE_report(op->reports, RPT_ERROR, "Cannot paste 2D strokes in 3D View");
- else
+ }
+ else {
BKE_report(op->reports, RPT_ERROR, "Cannot paste 3D strokes in 2D editors");
+ }
return OPERATOR_CANCELLED;
}
@@ -1442,16 +1456,18 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
bGPDstroke *gps, *gpsn;
/* skip if no frame with strokes, or if this is the layer we're moving strokes to */
- if ((gpl == target_layer) || (gpf == NULL))
+ if ((gpl == target_layer) || (gpf == NULL)) {
continue;
+ }
/* make copies of selected strokes, and deselect these once we're done */
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* TODO: Don't just move entire strokes - instead, only copy the selected portions... */
if (gps->flag & GP_STROKE_SELECT) {
@@ -1541,7 +1557,8 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op)
/* Initialise datablock and an active layer if nothing exists yet */
if (ELEM(NULL, gpd, active_gpl)) {
- /* let's just be lazy, and call the "Add New Layer" operator, which sets everything up as required */
+ /* Let's just be lazy, and call the "Add New Layer" operator,
+ * which sets everything up as required. */
WM_operator_name_call(C, "GPENCIL_OT_layer_add", WM_OP_EXEC_DEFAULT, NULL);
}
@@ -1676,8 +1693,9 @@ static int gp_actframe_delete_all_exec(bContext *C, wmOperator *op)
/* try to get the "active" frame - but only if it actually occurs on this frame */
bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* delete it... */
BKE_gpencil_layer_delframe(gpl, gpf);
@@ -1752,16 +1770,18 @@ static int gp_delete_selected_strokes(bContext *C)
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
bGPDstroke *gps, *gpsn;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* simply delete strokes which are selected */
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* free stroke if selected */
if (gps->flag & GP_STROKE_SELECT) {
@@ -1817,8 +1837,9 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
bGPDstroke *gps, *gpsn;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* simply delete points from selected strokes
* NOTE: we may still have to remove the stroke if it ends up having no points!
@@ -1827,11 +1848,13 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
continue;
+ }
/* the stroke must have at least one point selected for any operator */
if (gps->flag & GP_STROKE_SELECT) {
@@ -2189,7 +2212,8 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf,
/* Watch out for special case where No islands = All points selected = Delete Stroke only */
if (num_islands) {
- /* there are islands, so create a series of new strokes, adding them before the "next" stroke */
+ /* There are islands, so create a series of new strokes,
+ * adding them before the "next" stroke. */
int idx;
bGPDstroke *new_stroke = NULL;
@@ -2239,13 +2263,13 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf,
e++;
}
}
- /* Each island corresponds to a new stroke. We must adjust the
- * timings of these new strokes:
+ /* Each island corresponds to a new stroke.
+ * We must adjust the timings of these new strokes:
*
- * Each point's timing data is a delta from stroke's inittime, so as we erase some points from
- * the start of the stroke, we have to offset this inittime and all remaining points' delta values.
- * This way we get a new stroke with exactly the same timing as if user had started drawing from
- * the first non-removed point...
+ * Each point's timing data is a delta from stroke's inittime, so as we erase some points
+ * from the start of the stroke, we have to offset this inittime and all remaining points'
+ * delta values. This way we get a new stroke with exactly the same timing as if user had
+ * started drawing from the first non-removed point.
*/
{
bGPDspoint *pts;
@@ -2310,19 +2334,22 @@ static int gp_delete_selected_points(bContext *C)
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
bGPDstroke *gps, *gpsn;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* simply delete strokes which are selected */
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
continue;
+ }
if (gps->flag & GP_STROKE_SELECT) {
/* deselect old stroke, since it will be used as template for the new strokes */
@@ -2496,11 +2523,13 @@ static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op))
int i;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) {
continue;
+ }
// TODO: if entire stroke is selected, offset entire stroke by same amount?
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
@@ -2571,14 +2600,17 @@ static int gp_snap_to_cursor(bContext *C, wmOperator *op)
int i;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) {
continue;
+ }
/* only continue if this stroke is selected (editable doesn't guarantee this)... */
- if ((gps->flag & GP_STROKE_SELECT) == 0)
+ if ((gps->flag & GP_STROKE_SELECT) == 0) {
continue;
+ }
if (use_offset) {
float offset[3];
@@ -2666,14 +2698,17 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op))
int i;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* check if the color is editable */
- if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false)
+ if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) {
continue;
+ }
/* only continue if this stroke is selected (editable doesn't guarantee this)... */
- if ((gps->flag & GP_STROKE_SELECT) == 0)
+ if ((gps->flag & GP_STROKE_SELECT) == 0) {
continue;
+ }
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
if (pt->flag & GP_SPOINT_SELECT) {
@@ -2728,8 +2763,9 @@ static int gp_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(op))
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
/* sanity checks */
- if (ELEM(NULL, gpd, gpl, gpl->frames.first))
+ if (ELEM(NULL, gpd, gpl, gpl->frames.first)) {
return OPERATOR_CANCELLED;
+ }
/* loop all strokes */
for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
@@ -2782,24 +2818,28 @@ static int gp_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
const int type = RNA_enum_get(op->ptr, "type");
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* loop all selected strokes */
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
- if (gpl->actframe == NULL)
+ if (gpl->actframe == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
/* skip strokes that are not selected or invalid for current view */
- if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false)
+ if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
/* skip hidden or locked colors */
if (!gp_style || (gp_style->flag & GP_STYLE_COLOR_HIDE) ||
- (gp_style->flag & GP_STYLE_COLOR_LOCKED))
+ (gp_style->flag & GP_STYLE_COLOR_LOCKED)) {
continue;
+ }
switch (type) {
case GP_STROKE_CYCLIC_CLOSE:
@@ -2875,13 +2915,15 @@ static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
const int type = RNA_enum_get(op->ptr, "type");
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* loop all selected strokes */
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
- if (gpl->actframe == NULL)
+ if (gpl->actframe == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
@@ -3044,11 +3086,13 @@ static void gpencil_stroke_join_strokes(bGPDstroke *gps_a,
float deltatime = 0.0f;
/* sanity checks */
- if (ELEM(NULL, gps_a, gps_b))
+ if (ELEM(NULL, gps_a, gps_b)) {
return;
+ }
- if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0))
+ if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0)) {
return;
+ }
/* define start and end points of each stroke */
float sa[3], sb[3], ea[3], eb[3];
@@ -3109,11 +3153,13 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op)
const bool leave_gaps = RNA_boolean_get(op->ptr, "leave_gaps");
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
- if (activegpl->flag & GP_LAYER_LOCKED)
+ if (activegpl->flag & GP_LAYER_LOCKED) {
return OPERATOR_CANCELLED;
+ }
BLI_assert(ELEM(type, GP_STROKE_JOIN, GP_STROKE_JOINCOPY));
@@ -3121,8 +3167,9 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op)
bool first = false;
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *gpf = gpl->actframe;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
@@ -3193,8 +3240,9 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op)
if (type == GP_STROKE_JOINCOPY) {
if (new_stroke) {
/* Add a new frame if needed */
- if (activegpl->actframe == NULL)
+ if (activegpl->actframe == NULL) {
activegpl->actframe = BKE_gpencil_frame_addnew(activegpl, gpf_a->framenum);
+ }
BLI_addtail(&activegpl->actframe->strokes, new_stroke);
}
@@ -3244,14 +3292,16 @@ static int gp_stroke_flip_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = CTX_data_active_object(C);
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* read all selected strokes */
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *gpf = gpl->actframe;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
if (gps->flag & GP_STROKE_SELECT) {
@@ -3566,8 +3616,9 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
int i2;
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* Go through each editable + selected stroke */
GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
@@ -3728,8 +3779,9 @@ static int gp_stroke_simplify_exec(bContext *C, wmOperator *op)
float factor = RNA_float_get(op->ptr, "factor");
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* Go through each editable + selected stroke */
GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
@@ -3776,8 +3828,9 @@ static int gp_stroke_simplify_fixed_exec(bContext *C, wmOperator *op)
int steps = RNA_int_get(op->ptr, "step");
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* Go through each editable + selected stroke */
GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
@@ -3825,8 +3878,9 @@ static int gp_stroke_trim_exec(bContext *C, wmOperator *UNUSED(op))
bGPdata *gpd = ED_gpencil_data_get_active(C);
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
/* Go through each editable + selected stroke */
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
@@ -3841,15 +3895,17 @@ static int gp_stroke_trim_exec(bContext *C, wmOperator *UNUSED(op))
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
bGPDstroke *gps, *gpsn;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gpsn) {
gpsn = gps->next;
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
if (gps->flag & GP_STROKE_SELECT) {
BKE_gpencil_trim_stroke(gps);
@@ -4202,8 +4258,9 @@ static int gp_stroke_smooth_exec(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
/* sanity checks */
- if (ELEM(NULL, gpd))
+ if (ELEM(NULL, gpd)) {
return OPERATOR_CANCELLED;
+ }
gp_smooth_stroke(C, op);
@@ -4424,8 +4481,9 @@ static bool gpencil_cutter_poll(bContext *C)
bGPdata *gpd = ED_gpencil_data_get_active(C);
if (GPENCIL_PAINT_MODE(gpd)) {
- if (gpd->layers.first)
+ if (gpd->layers.first) {
return true;
+ }
}
return false;
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 8d3137ed3db..96f405fab2f 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -250,8 +250,9 @@ static void gp_draw_datablock(tGPDfill *tgpf, const float ink[4])
ED_gpencil_parent_location(tgpw.depsgraph, ob, gpd, gpl, tgpw.diff_mat);
/* do not draw layer if hidden */
- if (gpl->flag & GP_LAYER_HIDE)
+ if (gpl->flag & GP_LAYER_HIDE) {
continue;
+ }
/* if active layer and no keyframe, create a new one */
if (gpl == tgpf->gpl) {
@@ -262,8 +263,9 @@ static void gp_draw_datablock(tGPDfill *tgpf, const float ink[4])
/* get frame to draw */
bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* check if stroke can be drawn */
@@ -453,7 +455,7 @@ static void get_pixel(const ImBuf *ibuf, const int idx, float r_col[4])
/* set pixel data (rgba) at index */
static void set_pixel(ImBuf *ibuf, int idx, const float col[4])
{
- //BLI_assert(idx <= ibuf->x * ibuf->y);
+ // BLI_assert(idx <= ibuf->x * ibuf->y);
if (ibuf->rect) {
uint *rrect = &ibuf->rect[idx];
uchar ccol[4];
@@ -930,7 +932,8 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
view3d_region_operator_needs_opengl(tgpf->win, tgpf->ar);
ED_view3d_autodist_init(tgpf->depsgraph, tgpf->ar, tgpf->v3d, 0);
- /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
+ /* Since strokes are so fine, when using their depth we need a margin
+ * otherwise they might get missed. */
int depth_margin = 0;
/* get an array of depths, far depths are blended */
@@ -959,8 +962,9 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
if (found_depth == false) {
/* eeh... not much we can do.. :/, ignore depth in this case */
- for (i = totpoints - 1; i >= 0; i--)
+ for (i = totpoints - 1; i >= 0; i--) {
tgpf->depth_arr[i] = 0.9999f;
+ }
}
else {
if (interp_depth) {
@@ -1346,8 +1350,9 @@ static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
/* try to initialize context data needed */
if (!gpencil_fill_init(C, op)) {
gpencil_fill_exit(C, op);
- if (op->customdata)
+ if (op->customdata) {
MEM_freeN(op->customdata);
+ }
return OPERATOR_CANCELLED;
}
else {
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 5c9b9416330..d83cc7858bd 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -541,8 +541,9 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent
/* try to initialize context data needed */
if (!gpencil_interpolate_init(C, op)) {
- if (op->customdata)
+ if (op->customdata) {
MEM_freeN(op->customdata);
+ }
return OPERATOR_CANCELLED;
}
else {
@@ -1129,8 +1130,9 @@ static int gpencil_interpolate_reverse_exec(bContext *C, wmOperator *UNUSED(op))
bGPDframe *gpf, *gpfn;
/* Only continue if we're currently on a breakdown keyframe */
- if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN))
+ if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN)) {
continue;
+ }
/* Search left for "start_key" (i.e. the first breakdown to remove) */
gpf = gpl->actframe;
diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c
index 48c761919e5..9d3c2a6e271 100644
--- a/source/blender/editors/gpencil/gpencil_merge.c
+++ b/source/blender/editors/gpencil/gpencil_merge.c
@@ -66,10 +66,12 @@ static int gpencil_sort_points(const void *a1, const void *a2)
{
const tGPencilPointCache *ps1 = a1, *ps2 = a2;
- if (ps1->factor < ps2->factor)
+ if (ps1->factor < ps2->factor) {
return -1;
- else if (ps1->factor > ps2->factor)
+ }
+ else if (ps1->factor > ps2->factor) {
return 1;
+ }
return 0;
}
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index fce8fa79217..db4c601709c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -362,7 +362,7 @@ void ED_operatormacros_gpencil(void)
WM_operatortype_macro_define(ot, "GPENCIL_OT_duplicate");
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true);
- RNA_enum_set(otmacro->ptr, "proportional", 0);
+ RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
RNA_boolean_set(otmacro->ptr, "mirror", false);
/* Extrude + Move = Interactively add new points */
@@ -373,7 +373,7 @@ void ED_operatormacros_gpencil(void)
WM_operatortype_macro_define(ot, "GPENCIL_OT_extrude");
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true);
- RNA_enum_set(otmacro->ptr, "proportional", 0);
+ RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
RNA_boolean_set(otmacro->ptr, "mirror", false);
}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index bfdfe64ed54..b1b29356060 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -178,7 +178,8 @@ typedef struct tGPsdata {
/* These need to be doubles, as (at least under unix) they are in seconds since epoch,
* float (and its 7 digits precision) is definitively not enough here!
- * double, with its 15 digits precision, ensures us millisecond precision for a few centuries at least.
+ * double, with its 15 digits precision,
+ * ensures us millisecond precision for a few centuries at least.
*/
/** Used when converting to path. */
double inittime;
@@ -367,19 +368,23 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float mvalo[2
/* check if mouse moved at least certain distance on both axes (best case)
* - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand
*/
- else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX))
+ else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) {
return true;
- /* check if the distance since the last point is significant enough
- * - prevents points being added too densely
- * - distance here doesn't use sqrt to prevent slowness... we should still be safe from overflows though
- */
- else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX)
+ /* Check if the distance since the last point is significant enough:
+ * - Prevents points being added too densely
+ * - Distance here doesn't use sqrt to prevent slowness.
+ * We should still be safe from overflows though.
+ */
+ }
+ else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) {
return true;
- /* mouse 'didn't move' */
- else
+ /* mouse 'didn't move' */
+ }
+ else {
return false;
+ }
}
/* reproject stroke to plane locked to axis in 3d cursor location */
@@ -657,8 +662,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */
/* check if still room in buffer */
- if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX)
+ if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) {
return GP_STROKEADD_OVERFLOW;
+ }
/* get pointer to destination point */
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
@@ -793,10 +799,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* check if another operation can still occur */
- if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX)
+ if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) {
return GP_STROKEADD_FULL;
- else
+ }
+ else {
return GP_STROKEADD_NORMAL;
+ }
}
else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
@@ -881,8 +889,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* increment counters */
- if (gpd->runtime.sbuffer_size == 0)
+ if (gpd->runtime.sbuffer_size == 0) {
gpd->runtime.sbuffer_size++;
+ }
return GP_STROKEADD_NORMAL;
}
@@ -913,22 +922,26 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
(!is_depth);
int i, totelem;
- /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
+ /* Since strokes are so fine,
+ * when using their depth we need a margin otherwise they might get missed. */
int depth_margin = (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0;
/* get total number of points to allocate space for
* - drawing straight-lines only requires the endpoints
*/
- if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)
+ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size;
- else
+ }
+ else {
totelem = gpd->runtime.sbuffer_size;
+ }
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
gpd->runtime.sbuffer_size);
+ }
return;
}
@@ -1112,8 +1125,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (found_depth == false) {
/* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--)
+ for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
depth_arr[i] = 0.9999f;
+ }
}
else {
if ((ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) ||
@@ -1123,8 +1137,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
/* find first valid contact point */
for (i = 0; i < gpd->runtime.sbuffer_size; i++) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
first_valid = i;
@@ -1134,8 +1149,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
else {
for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
last_valid = i;
}
@@ -1189,10 +1205,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
gp_randomize_stroke(gps, brush, p->rng);
}
- /* smooth stroke after subdiv - only if there's something to do
- * for each iteration, the factor is reduced to get a better smoothing without changing too much
- * the original stroke
- */
+ /* Smooth stroke after subdiv - only if there's something to do for each iteration,
+ * the factor is reduced to get a better smoothing
+ * without changing too much the original stroke. */
if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_SETTINGS) &&
(brush->gpencil_settings->draw_smoothfac > 0.0f)) {
float reduce = 0.0f;
@@ -1223,8 +1238,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
ED_gpencil_project_stroke_to_view(p->C, p->gpl, gps);
}
- if (depth_arr)
+ if (depth_arr) {
MEM_freeN(depth_arr);
+ }
}
/* Save material index */
@@ -1233,9 +1249,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
/* calculate UVs along the stroke */
ED_gpencil_calc_stroke_uv(obact, gps);
- /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke is added on listbase head
- * because the drawing order is inverse and the head stroke is the first to draw. This is very useful for artist
- * when drawing the background
+ /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke
+ * is added on listbase head because the drawing order is inverse and the head stroke is the
+ * first to draw. This is very useful for artist when drawing the background.
*/
if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) &&
(p->paintmode != GP_PAINTMODE_DRAW_POLY)) {
@@ -1362,8 +1378,9 @@ static void gp_free_stroke(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps)
MEM_freeN(gps->dvert);
}
- if (gps->triangles)
+ if (gps->triangles) {
MEM_freeN(gps->triangles);
+ }
BLI_freelinkN(&gpf->strokes, gps);
gp_update_cache(gpd);
}
@@ -1458,8 +1475,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
for (i = 0; (i + 1) < gps->totpoints; i++) {
/* only process if it hasn't been masked out... */
- if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT))
+ if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) {
continue;
+ }
/* get points to work with */
pt1 = gps->points + i;
@@ -1510,8 +1528,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
pt2 = gps->points + i + 1;
/* only process if it hasn't been masked out... */
- if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT))
+ if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) {
continue;
+ }
bGPDspoint npt;
if (pt0) {
@@ -1881,8 +1900,9 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
/* make sure the active view (at the starting time) is a 3d-view */
if (curarea == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No active view for painting\n");
+ }
return 0;
}
@@ -1913,10 +1933,11 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
if (ar->regiondata == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf(
"Error: 3D-View active region doesn't have any region data, so cannot be "
"drawable\n");
+ }
return 0;
}
@@ -1941,8 +1962,9 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
/* unsupported views */
default: {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Active view not appropriate for Grease Pencil drawing\n");
+ }
return 0;
}
}
@@ -1951,14 +1973,16 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr);
if ((gpd_ptr == NULL) || ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Current context doesn't allow for any Grease Pencil data\n");
+ }
return 0;
}
else {
/* if no existing GPencil block exists, add one */
- if (*gpd_ptr == NULL)
+ if (*gpd_ptr == NULL) {
*gpd_ptr = BKE_gpencil_data_addnew(bmain, "GPencil");
+ }
p->gpd = *gpd_ptr;
}
@@ -2033,8 +2057,9 @@ static void gp_session_cleanup(tGPsdata *p)
bGPdata *gpd = (p) ? p->gpd : NULL;
/* error checking */
- if (gpd == NULL)
+ if (gpd == NULL) {
return;
+ }
/* free stroke buffer */
if (gpd->runtime.sbuffer) {
@@ -2076,8 +2101,9 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
}
if ((paintmode != GP_PAINTMODE_ERASER) && (p->gpl->flag & GP_LAYER_LOCKED)) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Cannot paint on locked layer\n");
+ }
return;
}
@@ -2092,8 +2118,9 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
for (bGPDlayer *gpl = p->gpd->layers.first; gpl; gpl = gpl->next) {
/* Skip if layer not editable */
- if (gpencil_layer_is_editable(gpl) == false)
+ if (gpencil_layer_is_editable(gpl) == false) {
continue;
+ }
/* Add a new frame if needed (and based off the active frame,
* as we need some existing strokes to erase)
@@ -2134,17 +2161,20 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
/* Drawing Modes - Add a new frame if needed on the active layer */
short add_frame_mode;
- if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST)
+ if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) {
add_frame_mode = GP_GETFRAME_ADD_COPY;
- else
+ }
+ else {
add_frame_mode = GP_GETFRAME_ADD_NEW;
+ }
p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode);
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: No frame created (gpencil_paint_init)\n");
+ }
return;
}
else {
@@ -2251,8 +2281,9 @@ static void gp_paint_cleanup(tGPsdata *p)
}
/* "unlock" frame */
- if (p->gpf)
+ if (p->gpf) {
p->gpf->flag &= ~GP_FRAME_PAINT;
+ }
}
/* ------------------------------- */
@@ -2288,14 +2319,13 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr)
immUniform1f("dash_width", 12.0f);
immUniform1f("dash_factor", 0.5f);
- imm_draw_circle_wire_2d(
- shdr_pos,
- x,
- y,
- p->radius,
- /* XXX Dashed shader gives bad results with sets of small segments currently,
- * temp hack around the issue. :( */
- max_ii(8, p->radius / 2)); /* was fixed 40 */
+ imm_draw_circle_wire_2d(shdr_pos,
+ x,
+ y,
+ p->radius,
+ /* XXX Dashed shader gives bad results with sets of small segments
+ * currently, temp hack around the issue. :( */
+ max_ii(8, p->radius / 2)); /* was fixed 40 */
immUnbindProgram();
@@ -2544,7 +2574,8 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
copy_v2_v2(p->mvalo, p->mval);
p->opressure = p->pressure;
}
- /* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */
+ /* Only add current point to buffer if mouse moved
+ * (even though we got an event, it might be just noise). */
else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) {
/* if lazy mouse, interpolate the last and current mouse positions */
@@ -2584,8 +2615,9 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke");
p->status = GP_STATUS_ERROR;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("Error: Grease-Pencil Paint - Add Point Invalid\n");
+ }
return;
}
@@ -2684,6 +2716,8 @@ static void gpencil_draw_apply_event(
PointerRNA itemptr;
float mousef[2];
int tablet = 0;
+ bool is_speed_guide = ((guide->use_guide) &&
+ (p->brush && (p->brush->gpencil_tool == GPAINT_TOOL_DRAW)));
/* convert from window-space to area-space mouse coordinates
* add any x,y override position for fake events
@@ -2693,7 +2727,7 @@ static void gpencil_draw_apply_event(
p->shift = event->shift;
/* verify direction for straight lines */
- if ((guide->use_guide) ||
+ if ((is_speed_guide) ||
((event->alt > 0) && (RNA_boolean_get(op->ptr, "disable_straight") == false))) {
if (p->straight == 0) {
int dx = (int)fabsf(p->mval[0] - p->mvali[0]);
@@ -2791,7 +2825,7 @@ static void gpencil_draw_apply_event(
/* special exception for grid snapping
* it requires direction which needs at least two points
*/
- if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP) && guide->use_guide &&
+ if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP) && is_speed_guide &&
guide->use_snapping && (guide->type == GP_GUIDE_GRID)) {
p->flags |= GP_PAINTFLAG_REQ_VECTOR;
}
@@ -2819,9 +2853,9 @@ static void gpencil_draw_apply_event(
}
/* check if stroke is straight or guided */
- if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (guide->use_guide))) {
+ if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (is_speed_guide))) {
/* guided stroke */
- if (guide->use_guide) {
+ if (is_speed_guide) {
switch (guide->type) {
default:
case GP_GUIDE_CIRCULAR: {
@@ -2943,8 +2977,9 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
/* printf("\tGP - no valid data\n"); */
return OPERATOR_CANCELLED;
}
- else
+ else {
p = op->customdata;
+ }
/* printf("\tGP - Start redrawing stroke\n"); */
@@ -3082,10 +3117,12 @@ static void gpencil_guide_event_handling(bContext *C,
add_notifier = true;
float angle = guide->angle;
float adjust = (float)M_PI / 180.0f;
- if (event->alt)
+ if (event->alt) {
adjust *= 45.0f;
- else if (!event->shift)
+ }
+ else if (!event->shift) {
adjust *= 15.0f;
+ }
angle += (event->type == JKEY) ? adjust : -adjust;
angle = angle_compat_rad(angle, M_PI);
guide->angle = angle;
@@ -3103,8 +3140,9 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = (bGPdata *)ob->data;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("GPencil - Starting Drawing\n");
+ }
/* support for tablets eraser pen */
if (gpencil_is_tablet_eraser_active(event)) {
@@ -3140,14 +3178,17 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
/* try to initialize context data needed while drawing */
if (!gpencil_draw_init(C, op, event)) {
- if (op->customdata)
+ if (op->customdata) {
MEM_freeN(op->customdata);
- if (G.debug & G_DEBUG)
+ }
+ if (G.debug & G_DEBUG) {
printf("\tGP - no valid data\n");
+ }
return OPERATOR_CANCELLED;
}
- else
+ else {
p = op->customdata;
+ }
/* TODO: set any additional settings that we can take from the events?
* TODO? if tablet is erasing, force eraser to be on? */
@@ -3237,8 +3278,9 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
/* XXX: watch it with the paintmode! in future,
* it'd be nice to allow changing paint-mode when in sketching-sessions */
- if (gp_session_initdata(C, op, p))
+ if (gp_session_initdata(C, op, p)) {
gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C));
+ }
if (p->status != GP_STATUS_ERROR) {
p->status = GP_STATUS_PAINTING;
@@ -3266,10 +3308,12 @@ static void gpencil_stroke_end(wmOperator *op)
p->gpf = NULL;
}
-/* Move last stroke in the listbase to the head to be drawn below all previous strokes in the layer */
+/* Move last stroke in the listbase to the head
+ * to be drawn below all previous strokes in the layer. */
static void gpencil_move_last_stroke_to_back(bContext *C)
{
- /* move last stroke (the polygon) to head of the listbase stroke to draw on back of all previous strokes */
+ /* Move last stroke (the polygon) to head of the listbase stroke
+ * to draw on back of all previous strokes. */
bGPdata *gpd = ED_gpencil_data_get_active(C);
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
@@ -3430,7 +3474,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
- /* we don't pass on key events, GP is used with key-modifiers - prevents Dkey to insert drivers */
+ /* We don't pass on key events, GP is used with key-modifiers -
+ * prevents Dkey to insert drivers. */
if (ISKEYBOARD(event->type)) {
if (ELEM(event->type, LEFTARROWKEY, DOWNARROWKEY, RIGHTARROWKEY, UPARROWKEY, ZKEY)) {
/* allow some keys:
@@ -3462,10 +3507,12 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
- //printf("\tGP - handle modal event...\n");
+ // printf("\tGP - handle modal event...\n");
- /* exit painting mode (and/or end current stroke)
- * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) as that would break polyline [#32647]
+ /* Exit painting mode (and/or end current stroke).
+ *
+ * NOTE: cannot do RIGHTMOUSE (as is standard for canceling)
+ * as that would break polyline T32647.
*/
/* if polyline and release shift must cancel */
if ((ELEM(event->type, RETKEY, PADENTER, ESCKEY, SPACEKEY, EKEY)) ||
@@ -3587,8 +3634,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__);
+ }
}
}
else if (p->ar) {
@@ -3603,8 +3651,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
p->status = GP_STATUS_ERROR;
estate = OPERATOR_CANCELLED;
- if (G.debug & G_DEBUG)
+ if (G.debug & G_DEBUG) {
printf("%s: No active region found in GP Paint session data\n", __func__);
+ }
}
if (in_bounds) {
@@ -3661,7 +3710,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* handle drawing event */
/* printf("\t\tGP - add point\n"); */
- if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) || (guide->use_guide)) {
+ if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0)) {
gpencil_add_missing_events(C, op, event, p);
}
@@ -3695,8 +3744,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
case PADMINUS:
p->radius -= 5;
- if (p->radius <= 0)
+ if (p->radius <= 0) {
p->radius = 1;
+ }
break;
}
@@ -3717,8 +3767,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
/* gpencil modal operator stores area, which can be removed while using it (like fullscreen) */
- if (0 == gpencil_area_exists(C, p->sa))
+ if (0 == gpencil_area_exists(C, p->sa)) {
estate = OPERATOR_CANCELLED;
+ }
else {
/* update status indicators - cursor, header, etc. */
gpencil_draw_status_indicators(C, p);
@@ -3748,7 +3799,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* event doesn't need to be handled */
#if 0
printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n",
- event->type, event->type == MIDDLEMOUSE, event->type == MOUSEMOVE);
+ event->type,
+ event->type == MIDDLEMOUSE,
+ event->type == MOUSEMOVE);
#endif
break;
}
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index f178d232376..08fee2bb393 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -129,8 +129,9 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
gpd->runtime.sbuffer_sflag = 0;
gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE;
- if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE))
+ if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) {
gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC;
+ }
}
static void gp_init_colors(tGPDprimitive *p)
@@ -174,16 +175,20 @@ static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const float x, cons
float w = fabsf(x);
float h = fabsf(y);
if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
- if (w > h)
+ if (w > h) {
tgpi->end[1] = tgpi->origin[1] + x;
- else
+ }
+ else {
tgpi->end[0] = tgpi->origin[0] + y;
+ }
}
else {
- if (w > h)
+ if (w > h) {
tgpi->end[1] = tgpi->origin[1] - x;
- else
+ }
+ else {
tgpi->end[0] = tgpi->origin[0] - y;
+ }
}
}
@@ -289,8 +294,9 @@ static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi)
tgpi->point_count += (tgpi->type == GP_STROKE_BOX) ? (MAX_EDGES * 4 + 1) : (MAX_EDGES + 1);
bGPDstroke *gpsf = tgpi->gpf->strokes.first;
gpsf->points = MEM_reallocN(gpsf->points, sizeof(bGPDspoint) * tgpi->point_count);
- if (gpsf->dvert != NULL)
+ if (gpsf->dvert != NULL) {
gpsf->dvert = MEM_reallocN(gpsf->dvert, sizeof(MDeformVert) * tgpi->point_count);
+ }
tgpi->points = MEM_reallocN(tgpi->points, sizeof(tGPspoint) * tgpi->point_count);
}
@@ -675,13 +681,16 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) &&
(tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth);
- if (tgpi->type == GP_STROKE_BOX)
+ if (tgpi->type == GP_STROKE_BOX) {
gps->totpoints = (tgpi->tot_edges * 4 + tgpi->tot_stored_edges);
- else
+ }
+ else {
gps->totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges);
+ }
- if (tgpi->tot_stored_edges)
+ if (tgpi->tot_stored_edges) {
gps->totpoints--;
+ }
tgpi->gpd->runtime.tot_cp_points = 0;
@@ -778,8 +787,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* find first valid contact point */
for (i = 0; i < gps->totpoints; i++) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
first_valid = i;
@@ -789,8 +799,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
else {
for (i = gps->totpoints - 1; i >= 0; i--) {
- if (depth_arr[i] != FLT_MAX)
+ if (depth_arr[i] != FLT_MAX) {
break;
+ }
}
last_valid = i;
}
@@ -1325,16 +1336,18 @@ static void gpencil_primitive_edit_event_handling(
float dy = (tgpi->mval[1] - tgpi->mvalo[1]);
tgpi->cp1[0] += dx;
tgpi->cp1[1] += dy;
- if (event->shift)
+ if (event->shift) {
copy_v2_v2(tgpi->cp2, tgpi->cp1);
+ }
}
else if (tgpi->sel_cp == SELECT_CP2) {
float dx = (tgpi->mval[0] - tgpi->mvalo[0]);
float dy = (tgpi->mval[1] - tgpi->mvalo[1]);
tgpi->cp2[0] += dx;
tgpi->cp2[1] += dy;
- if (event->shift)
+ if (event->shift) {
copy_v2_v2(tgpi->cp1, tgpi->cp2);
+ }
}
/* update screen */
gpencil_primitive_update(C, op, tgpi);
@@ -1344,12 +1357,15 @@ static void gpencil_primitive_edit_event_handling(
case LEFTMOUSE: {
if ((event->val == KM_PRESS)) {
/* find nearest cp based on stroke end points */
- if (move == MOVE_ENDS)
+ if (move == MOVE_ENDS) {
tgpi->sel_cp = (a < b) ? SELECT_START : SELECT_END;
- else if (move == MOVE_CP)
+ }
+ else if (move == MOVE_CP) {
tgpi->sel_cp = (c < d) ? SELECT_CP1 : SELECT_CP2;
- else
+ }
+ else {
tgpi->sel_cp = SELECT_NONE;
+ }
break;
}
else if ((event->val == KM_RELEASE) && (tgpi->flag == IN_PROGRESS)) {
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index ef7a198111b..ba806022d3e 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -74,8 +74,9 @@ static bool gpencil_select_poll(bContext *C)
/* we just need some visible strokes, and to be in editmode or other modes only to catch event */
if (GPENCIL_ANY_MODE(gpd)) {
/* TODO: include a check for visible strokes? */
- if (gpd->layers.first)
+ if (gpd->layers.first) {
return true;
+ }
}
return false;
@@ -291,8 +292,9 @@ typedef enum eGP_SelectGrouped {
/* Select strokes with the same color */
GP_SEL_SAME_MATERIAL = 1,
- /* TODO: All with same prefix - Useful for isolating all layers for a particular character for instance */
- /* TODO: All with same appearance - colour/opacity/volumetric/fills ? */
+ /* TODO: All with same prefix -
+ * Useful for isolating all layers for a particular character for instance. */
+ /* TODO: All with same appearance - color/opacity/volumetric/fills ? */
} eGP_SelectGrouped;
/* ----------------------------------- */
@@ -308,8 +310,9 @@ static void gp_select_same_layer(bContext *C)
bGPDstroke *gps;
bool found = false;
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
/* Search for a selected stroke */
for (gps = gpf->strokes.first; gps; gps = gps->next) {
@@ -621,7 +624,8 @@ static int gpencil_select_more_exec(bContext *C, wmOperator *UNUSED(op))
int i;
bool prev_sel;
- /* First Pass: Go in forward order, expanding selection if previous was selected (pre changes)...
+ /* First Pass: Go in forward order,
+ * expanding selection if previous was selected (pre changes).
* - This pass covers the "after" edges of selection islands
*/
prev_sel = false;
@@ -705,7 +709,8 @@ static int gpencil_select_less_exec(bContext *C, wmOperator *UNUSED(op))
int i;
bool prev_sel;
- /* First Pass: Go in forward order, shrinking selection if previous was not selected (pre changes)...
+ /* First Pass: Go in forward order, shrinking selection
+ * if previous was not selected (pre changes).
* - This pass covers the "after" edges of selection islands
*/
prev_sel = false;
@@ -776,9 +781,12 @@ void GPENCIL_OT_select_less(wmOperatorType *ot)
/** \name Circle Select Operator
* \{ */
-/* Helper to check if a given stroke is within the area */
-/* NOTE: Code here is adapted (i.e. copied directly) from gpencil_paint.c::gp_stroke_eraser_dostroke()
- * It would be great to de-duplicate the logic here sometime, but that can wait...
+/**
+ * Helper to check if a given stroke is within the area.
+ *
+ * \note Code here is adapted (i.e. copied directly)
+ * from gpencil_paint.c #gp_stroke_eraser_dostroke().
+ * It would be great to de-duplicate the logic here sometime, but that can wait.
*/
static bool gp_stroke_do_circle_sel(bGPDlayer *gpl,
bGPDstroke *gps,
@@ -1290,6 +1298,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
bool deselect = RNA_boolean_get(op->ptr, "deselect");
bool toggle = RNA_boolean_get(op->ptr, "toggle");
bool whole = RNA_boolean_get(op->ptr, "entire_strokes");
+ const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
int mval[2] = {0};
@@ -1352,15 +1361,18 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
/* Abort if nothing hit... */
if (ELEM(NULL, hit_stroke, hit_point)) {
+ if (deselect_all) {
+ /* since left mouse select change, deselect all if click outside any hit */
+ deselect_all_selected(C);
- /* since left mouse select change, deselect all if click outside any hit */
- deselect_all_selected(C);
+ /* copy on write tag is needed, or else no refresh happens */
+ DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
+ DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
+ WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
- /* copy on write tag is needed, or else no refresh happens */
- DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
- DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
- WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+ return OPERATOR_FINISHED;
+ }
return OPERATOR_CANCELLED;
}
@@ -1382,17 +1394,21 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
/* entire stroke's points */
for (i = 0, pt = hit_stroke->points; i < hit_stroke->totpoints; i++, pt++) {
- if (deselect == false)
+ if (deselect == false) {
pt->flag |= GP_SPOINT_SELECT;
- else
+ }
+ else {
pt->flag &= ~GP_SPOINT_SELECT;
+ }
}
/* stroke too... */
- if (deselect == false)
+ if (deselect == false) {
hit_stroke->flag |= GP_STROKE_SELECT;
- else
+ }
+ else {
hit_stroke->flag &= ~GP_STROKE_SELECT;
+ }
}
else {
/* just the point (and the stroke) */
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index d91977bc0da..7b57dacd3e4 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -68,7 +68,7 @@ int ED_undo_gpencil_step(bContext *C, int step, const char *name)
gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
if (step == 1) { /* undo */
- //printf("\t\tGP - undo step\n");
+ // printf("\t\tGP - undo step\n");
if (cur_node->prev) {
if (!name || STREQ(cur_node->name, name)) {
cur_node = cur_node->prev;
@@ -77,7 +77,7 @@ int ED_undo_gpencil_step(bContext *C, int step, const char *name)
}
}
else if (step == -1) {
- //printf("\t\tGP - redo step\n");
+ // printf("\t\tGP - redo step\n");
if (cur_node->next) {
if (!name || STREQ(cur_node->name, name)) {
cur_node = cur_node->next;
@@ -134,7 +134,7 @@ void gpencil_undo_push(bGPdata *gpd)
{
bGPundonode *undo_node;
- //printf("\t\tGP - undo push\n");
+ // printf("\t\tGP - undo push\n");
if (cur_node) {
/* remove all un-done nodes from stack */
@@ -154,7 +154,8 @@ void gpencil_undo_push(bGPdata *gpd)
* - to prevent running out of memory during **really**
* long drawing sessions (triggering swapping)
*/
- /* TODO: Undo-memory constraint is not respected yet, but can be added if we have any need for it */
+ /* TODO: Undo-memory constraint is not respected yet,
+ * but can be added if we have any need for it. */
if (U.undosteps && !BLI_listbase_is_empty(&undo_nodes)) {
/* remove anything older than n-steps before cur_node */
int steps = 0;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 858415061b1..129bd01574c 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -85,7 +85,9 @@
/* ******************************************************** */
/* Context Wrangling... */
-/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it,
+/**
+ * Get pointer to active Grease Pencil datablock,
+ * and an RNA-pointer to trace back to whatever owns it,
* when context info is not available.
*/
bGPdata **ED_gpencil_data_get_pointers_direct(
@@ -104,8 +106,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
{
if (ob && (ob->type == OB_GPENCIL)) {
/* GP Object */
- if (r_ptr)
+ if (r_ptr) {
RNA_id_pointer_create(&ob->id, r_ptr);
+ }
return (bGPdata **)&ob->data;
}
else {
@@ -120,15 +123,17 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
{
if (ob && (ob->type == OB_GPENCIL)) {
/* GP Object */
- if (r_ptr)
+ if (r_ptr) {
RNA_id_pointer_create(&ob->id, r_ptr);
+ }
return (bGPdata **)&ob->data;
}
else {
/* Annotations */
/* XXX: */
- if (r_ptr)
+ if (r_ptr) {
RNA_id_pointer_create(&scene->id, r_ptr);
+ }
return &scene->gpd;
}
@@ -142,8 +147,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
if (snode && snode->nodetree) {
/* for now, as long as there's an active node tree,
* default to using that in the Nodes Editor */
- if (r_ptr)
+ if (r_ptr) {
RNA_id_pointer_create(&snode->nodetree->id, r_ptr);
+ }
return &snode->nodetree->gpd;
}
@@ -154,10 +160,12 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
{
SpaceSeq *sseq = (SpaceSeq *)sl;
- /* for now, Grease Pencil data is associated with the space (actually preview region only) */
+ /* For now, Grease Pencil data is associated with the space
+ * (actually preview region only). */
/* XXX our convention for everything else is to link to data though... */
- if (r_ptr)
+ if (r_ptr) {
RNA_pointer_create(screen_id, &RNA_SpaceSequenceEditor, sseq, r_ptr);
+ }
return &sseq->gpd;
}
case SPACE_IMAGE: /* Image/UV Editor */
@@ -166,8 +174,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
/* for now, Grease Pencil data is associated with the space... */
/* XXX our convention for everything else is to link to data though... */
- if (r_ptr)
+ if (r_ptr) {
RNA_pointer_create(screen_id, &RNA_SpaceImageEditor, sima, r_ptr);
+ }
return &sima->gpd;
}
case SPACE_CLIP: /* Nodes Editor */
@@ -179,16 +188,19 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
MovieTrackingTrack *track = BKE_tracking_track_get_active(&clip->tracking);
- if (!track)
+ if (!track) {
return NULL;
+ }
- if (r_ptr)
+ if (r_ptr) {
RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, r_ptr);
+ }
return &track->gpd;
}
else {
- if (r_ptr)
+ if (r_ptr) {
RNA_id_pointer_create(&clip->id, r_ptr);
+ }
return &clip->gpd;
}
}
@@ -202,7 +214,8 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
return NULL;
}
-/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it */
+/* Get pointer to active Grease Pencil datablock,
+ * and an RNA-pointer to trace back to whatever owns it. */
bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr)
{
ID *screen_id = (ID *)CTX_wm_screen(C);
@@ -251,7 +264,11 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
Object *ob = CTX_data_active_object(C);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
- /* if (ob && ob->type == OB_GPENCIL) BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); */
+#if 0
+ if (ob && ob->type == OB_GPENCIL) {
+ BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data));
+ }
+#endif
return ED_gpencil_data_get_active_direct(screen_id, sa, scene_eval, ob_eval);
}
@@ -350,10 +367,12 @@ const EnumPropertyItem *ED_gpencil_layers_enum_itemf(bContext *C,
item_tmp.name = gpl->info;
item_tmp.value = i;
- if (gpl->flag & GP_LAYER_ACTIVE)
+ if (gpl->flag & GP_LAYER_ACTIVE) {
item_tmp.icon = ICON_GREASEPENCIL;
- else
+ }
+ else {
item_tmp.icon = ICON_NONE;
+ }
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
@@ -400,10 +419,12 @@ const EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(bContext *C,
item_tmp.name = gpl->info;
item_tmp.value = tot - i - 1;
- if (gpl->flag & GP_LAYER_ACTIVE)
+ if (gpl->flag & GP_LAYER_ACTIVE) {
item_tmp.icon = ICON_GREASEPENCIL;
- else
+ }
+ else {
item_tmp.icon = ICON_NONE;
+ }
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
@@ -450,8 +471,9 @@ bool gp_stroke_inside_circle(
bool ED_gpencil_stroke_can_use_direct(const ScrArea *sa, const bGPDstroke *gps)
{
/* sanity check */
- if (ELEM(NULL, sa, gps))
+ if (ELEM(NULL, sa, gps)) {
return false;
+ }
/* filter stroke types by flags + spacetype */
if (gps->flag & GP_STROKE_3DSPACE) {
@@ -486,10 +508,12 @@ bool ED_gpencil_stroke_color_use(Object *ob, const bGPDlayer *gpl, const bGPDstr
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
if (gp_style != NULL) {
- if (gp_style->flag & GP_STYLE_COLOR_HIDE)
+ if (gp_style->flag & GP_STYLE_COLOR_HIDE) {
return false;
- if (((gpl->flag & GP_LAYER_UNLOCK_COLOR) == 0) && (gp_style->flag & GP_STYLE_COLOR_LOCKED))
+ }
+ if (((gpl->flag & GP_LAYER_UNLOCK_COLOR) == 0) && (gp_style->flag & GP_STYLE_COLOR_LOCKED)) {
return false;
+ }
}
return true;
@@ -606,7 +630,8 @@ void gp_apply_parent_point(
* \param[out] r_x The screen-space x-coordinate of the point
* \param[out] r_y The screen-space y-coordinate of the point
*
- * \warning This assumes that the caller has already checked whether the stroke in question can be drawn.
+ * \warning This assumes that the caller has already checked
+ * whether the stroke in question can be drawn.
*/
void gp_point_to_xy(
const GP_SpaceConversion *gsc, const bGPDstroke *gps, const bGPDspoint *pt, int *r_x, int *r_y)
@@ -650,15 +675,17 @@ void gp_point_to_xy(
}
/**
- * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D)
+ * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D).
*
* Just like #gp_point_to_xy(), except the resulting coordinates are floats not ints.
- * Use this version to solve "stair-step" artifacts which may arise when roundtripping the calculations.
+ * Use this version to solve "stair-step" artifacts which may arise when
+ * roundtripping the calculations.
*
- * \param r_x: [out] The screen-space x-coordinate of the point.
- * \param r_y: [out] The screen-space y-coordinate of the point.
+ * \param r_x[out]: The screen-space x-coordinate of the point.
+ * \param r_y[out]: The screen-space y-coordinate of the point.
*
- * \warning This assumes that the caller has already checked whether the stroke in question can be drawn.
+ * \warning This assumes that the caller has already checked
+ * whether the stroke in question can be drawn.
*/
void gp_point_to_xy_fl(const GP_SpaceConversion *gsc,
const bGPDstroke *gps,
@@ -1079,7 +1106,9 @@ void ED_gp_project_point_to_plane(const Scene *scene,
/* ******************************************************** */
/* Stroke Operations */
-// XXX: Check if these functions duplicate stuff in blenkernel, and/or whether we should just deduplicate
+
+/* XXX: Check if these functions duplicate stuff in blenkernel,
+ * and/or whether we should just deduplicate. */
/**
* Subdivide a stroke once, by adding a point half way between each pair of existing points
@@ -1259,6 +1288,7 @@ void ED_gpencil_parent_location(const Depsgraph *depsgraph,
else {
if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+ add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
return;
}
else if (gpl->partype == PARBONE) {
@@ -1267,10 +1297,12 @@ void ED_gpencil_parent_location(const Depsgraph *depsgraph,
float tmp_mat[4][4];
mul_m4_m4m4(tmp_mat, obparent_eval->obmat, pchan->pose_mat);
mul_m4_m4m4(diff_mat, tmp_mat, gpl->inverse);
+ add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
}
else {
/* if bone not found use object (armature) */
mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+ add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
}
return;
}
@@ -1287,12 +1319,15 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata
int i;
float diff_mat[4][4];
float cur_mat[4][4];
+ float gpl_loc[3];
+ zero_v3(gpl_loc);
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if (gpl->parent != NULL) {
/* calculate new matrix */
if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
invert_m4_m4(cur_mat, gpl->parent->obmat);
+ copy_v3_v3(gpl_loc, obact->obmat[3]);
}
else if (gpl->partype == PARBONE) {
bPoseChannel *pchan = BKE_pose_channel_find_name(gpl->parent->pose, gpl->parsubstr);
@@ -1300,6 +1335,7 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata
float tmp_mat[4][4];
mul_m4_m4m4(tmp_mat, gpl->parent->obmat, pchan->pose_mat);
invert_m4_m4(cur_mat, tmp_mat);
+ copy_v3_v3(gpl_loc, obact->obmat[3]);
}
}
@@ -1307,6 +1343,9 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata
if (!equals_m4m4(gpl->inverse, cur_mat)) {
/* first apply current transformation to all strokes */
ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat);
+ /* undo local object */
+ sub_v3_v3(diff_mat[3], gpl_loc);
+
for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
@@ -1377,8 +1416,9 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight)
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const int def_nr = ob->actdef - 1;
- if (!BLI_findlink(&ob->defbase, def_nr))
+ if (!BLI_findlink(&ob->defbase, def_nr)) {
return;
+ }
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *init_gpf = gpl->actframe;
@@ -1389,14 +1429,16 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
if (gps->flag & GP_STROKE_SELECT) {
/* verify the weight array is created */
@@ -1431,8 +1473,9 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob)
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const int def_nr = ob->actdef - 1;
- if (!BLI_findlink(&ob->defbase, def_nr))
+ if (!BLI_findlink(&ob->defbase, def_nr)) {
return;
+ }
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *init_gpf = gpl->actframe;
@@ -1443,14 +1486,16 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
@@ -1484,8 +1529,9 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob)
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const int def_nr = ob->actdef - 1;
- if (!BLI_findlink(&ob->defbase, def_nr))
+ if (!BLI_findlink(&ob->defbase, def_nr)) {
return;
+ }
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *init_gpf = gpl->actframe;
@@ -1496,14 +1542,16 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
@@ -1535,8 +1583,9 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob)
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const int def_nr = ob->actdef - 1;
- if (!BLI_findlink(&ob->defbase, def_nr))
+ if (!BLI_findlink(&ob->defbase, def_nr)) {
return;
+ }
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *init_gpf = gpl->actframe;
@@ -1547,14 +1596,16 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob)
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
- if (gpf == NULL)
+ if (gpf == NULL) {
continue;
+ }
for (gps = gpf->strokes.first; gps; gps = gps->next) {
/* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
+ }
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
@@ -1638,14 +1689,13 @@ void ED_gpencil_brush_draw_eraser(Brush *brush, int x, int y)
immUniform1f("dash_width", 12.0f);
immUniform1f("dash_factor", 0.5f);
- imm_draw_circle_wire_2d(
- shdr_pos,
- x,
- y,
- radius,
- /* XXX Dashed shader gives bad results with sets of small segments currently,
- * temp hack around the issue. :( */
- max_ii(8, radius / 2)); /* was fixed 40 */
+ imm_draw_circle_wire_2d(shdr_pos,
+ x,
+ y,
+ radius,
+ /* XXX Dashed shader gives bad results with sets of small segments
+ * currently, temp hack around the issue. :( */
+ max_ii(8, radius / 2)); /* was fixed 40 */
immUnbindProgram();
@@ -2463,7 +2513,7 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
case SEL_SELECT:
pt->flag |= GP_SPOINT_SELECT;
break;
- //case SEL_DESELECT:
+ // case SEL_DESELECT:
// pt->flag &= ~GP_SPOINT_SELECT;
// break;
case SEL_INVERT:
@@ -2471,15 +2521,18 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
break;
}
- if (pt->flag & GP_SPOINT_SELECT)
+ if (pt->flag & GP_SPOINT_SELECT) {
selected = true;
+ }
}
/* Change status of stroke */
- if (selected)
+ if (selected) {
gps->flag |= GP_STROKE_SELECT;
- else
+ }
+ else {
gps->flag &= ~GP_STROKE_SELECT;
+ }
}
CTX_DATA_END;
}