Cleanup: Split grease pencil selection index functions

This makes the code more readable.
This commit is contained in:
2021-02-20 10:16:51 +01:00
parent 37e6a1995a
commit 173b6b792c
11 changed files with 63 additions and 63 deletions

View File

@@ -103,9 +103,8 @@ void BKE_gpencil_batch_cache_free(struct bGPdata *gpd);
void BKE_gpencil_stroke_sync_selection(struct bGPdata *gpd, struct bGPDstroke *gps);
void BKE_gpencil_curve_sync_selection(struct bGPdata *gpd, struct bGPDstroke *gps);
void BKE_gpencil_stroke_select_index_set(struct bGPdata *gpd,
struct bGPDstroke *gps,
const bool reset);
void BKE_gpencil_stroke_select_index_set(struct bGPdata *gpd, struct bGPDstroke *gps);
void BKE_gpencil_stroke_select_index_reset(struct bGPDstroke *gps);
struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);

View File

@@ -1148,7 +1148,7 @@ void BKE_gpencil_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps)
* so initially, we must deselect
*/
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
if (pt->flag & GP_SPOINT_SELECT) {
@@ -1158,7 +1158,7 @@ void BKE_gpencil_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps)
}
if (gps->flag & GP_STROKE_SELECT) {
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
}
@@ -1170,7 +1170,7 @@ void BKE_gpencil_curve_sync_selection(bGPdata *gpd, bGPDstroke *gps)
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
gpc->flag &= ~GP_CURVE_SELECT;
bool is_selected = false;
@@ -1193,20 +1193,21 @@ void BKE_gpencil_curve_sync_selection(bGPdata *gpd, bGPDstroke *gps)
if (is_selected) {
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
}
/* Assign unique stroke ID for selection. */
void BKE_gpencil_stroke_select_index_set(bGPdata *gpd, bGPDstroke *gps, const bool reset)
void BKE_gpencil_stroke_select_index_set(bGPdata *gpd, bGPDstroke *gps)
{
if (!reset) {
gpd->select_last_index++;
gps->select_index = gpd->select_last_index;
}
else {
gps->select_index = 0;
}
gpd->select_last_index++;
gps->select_index = gpd->select_last_index;
}
/* Reset unique stroke ID for selection. */
void BKE_gpencil_stroke_select_index_reset(bGPDstroke *gps)
{
gps->select_index = 0;
}
/* ************************************************** */
@@ -2533,7 +2534,7 @@ bool BKE_gpencil_from_image(
}
if (gps->flag & GP_STROKE_SELECT) {
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
BKE_gpencil_stroke_geometry_update(gpd, gps);

View File

@@ -814,7 +814,7 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPdata *gpd, bGPDstroke *gps,
{
if (gpc->flag & GP_CURVE_SELECT) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
for (int i = 0; i < gpc->tot_curve_points - 1; i++) {
bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
@@ -868,7 +868,7 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPdata *gpd, bGPDstroke *gps,
}
else {
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
pt->flag &= ~GP_SPOINT_SELECT;
@@ -1093,7 +1093,7 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
/* deselect */
pt->flag &= ~GP_SPOINT_SELECT;
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
return;
}
@@ -1136,7 +1136,7 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
pt->flag &= ~GP_SPOINT_SELECT;
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
/* free temp data */
MEM_freeN(points);

View File

@@ -3444,7 +3444,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
if (select) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
/* Free the sample points. Important to use the mutable loop here because we are erasing the list

View File

@@ -3418,11 +3418,11 @@ static int gpencil_material_select_exec(bContext *C, wmOperator *op)
if (!deselected) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
else {
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
if (!deselected) {

View File

@@ -992,7 +992,7 @@ static int gpencil_duplicate_exec(bContext *C, wmOperator *op)
pt->flag &= ~GP_SPOINT_SELECT;
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
changed = true;
}
@@ -1194,7 +1194,7 @@ static void gpencil_add_move_points(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gp
/* if the stroke is not reused, deselect */
if (!do_stroke) {
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
@@ -1711,7 +1711,7 @@ static int gpencil_strokes_paste_exec(bContext *C, wmOperator *op)
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
CTX_DATA_END;
@@ -2551,7 +2551,7 @@ static bool gpencil_dissolve_selected_stroke_points(bContext *C,
/* deselect the stroke, since none of its selected points will still be selected */
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
pt->flag &= ~GP_SPOINT_SELECT;
}
@@ -2624,7 +2624,7 @@ static int gpencil_delete_selected_points(bContext *C)
if (gps->flag & GP_STROKE_SELECT) {
/* deselect old stroke, since it will be used as template for the new strokes */
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
if (is_curve_edit) {
bGPDcurve *gpc = gps->editcurve;
@@ -4579,7 +4579,7 @@ static int gpencil_stroke_separate_exec(bContext *C, wmOperator *op)
else if (mode == GP_SEPARATE_STROKE) {
/* deselect old stroke */
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
/* unlink from source frame */
BLI_remlink(&gpf->strokes, gps);
gps->prev = gps->next = NULL;
@@ -4988,7 +4988,7 @@ static int gpencil_cutter_lasso_select(bContext *C,
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
CTX_DATA_END;
@@ -5029,7 +5029,7 @@ static int gpencil_cutter_lasso_select(bContext *C,
changed = true;
pt->flag |= GP_SPOINT_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
float r_hita[3], r_hitb[3];
if (gps->totpoints > 1) {
ED_gpencil_select_stroke_segment(

View File

@@ -134,7 +134,7 @@ static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpo
/* stroke */
bGPDstroke *gps = BKE_gpencil_stroke_new(MAX2(ob->actcol - 1, 0), totpoints, brush->size);
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
if (cyclic) {
gps->flag |= GP_STROKE_CYCLIC;
@@ -243,7 +243,7 @@ static void gpencil_calc_points_factor(bContext *C,
}
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
}

View File

@@ -338,7 +338,7 @@ static void gpencil_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
ED_gpencil_fill_vertex_color_set(ts, brush, gps);
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
/* the polygon must be closed, so enabled cyclic */
if (ELEM(tgpi->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) {
gps->flag |= GP_STROKE_CYCLIC;

View File

@@ -174,7 +174,7 @@ static void deselect_all_selected(bContext *C)
/* deselect stroke itself too */
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
/* deselect curve and curve points */
@@ -211,12 +211,12 @@ static void select_all_curve_points(bGPdata *gpd, bGPDstroke *gps, bGPDcurve *gp
if (deselect == false) {
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
else {
gpc->flag &= ~GP_CURVE_SELECT;
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
@@ -570,7 +570,7 @@ static bool gpencil_select_same_layer(bContext *C)
}
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
changed = true;
}
@@ -587,7 +587,7 @@ static bool gpencil_select_same_layer(bContext *C)
}
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
changed = true;
}
@@ -632,7 +632,7 @@ static bool gpencil_select_same_material(bContext *C)
}
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
changed = true;
}
@@ -651,7 +651,7 @@ static bool gpencil_select_same_material(bContext *C)
}
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
changed = true;
}
@@ -768,7 +768,7 @@ static int gpencil_select_first_exec(bContext *C, wmOperator *op)
BEZT_SEL_ALL(&gpc->curve_points[0].bezt);
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
if ((extend == false) && (gps->totpoints > 1)) {
for (int i = 1; i < gpc->tot_curve_points; i++) {
@@ -783,7 +783,7 @@ static int gpencil_select_first_exec(bContext *C, wmOperator *op)
else {
gps->points->flag |= GP_SPOINT_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
/* deselect rest? */
if ((extend == false) && (gps->totpoints > 1)) {
@@ -878,7 +878,7 @@ static int gpencil_select_last_exec(bContext *C, wmOperator *op)
BEZT_SEL_ALL(&gpc->curve_points[gpc->tot_curve_points - 1].bezt);
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
if ((extend == false) && (gps->totpoints > 1)) {
for (int i = 0; i < gpc->tot_curve_points - 1; i++) {
bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
@@ -892,7 +892,7 @@ static int gpencil_select_last_exec(bContext *C, wmOperator *op)
else {
gps->points[gps->totpoints - 1].flag |= GP_SPOINT_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
/* deselect rest? */
if ((extend == false) && (gps->totpoints > 1)) {
@@ -1289,12 +1289,12 @@ static bool gpencil_stroke_do_circle_sel(bGPdata *gpd,
if (select) {
pt_active->flag |= GP_SPOINT_SELECT;
gps_active->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps_active, false);
BKE_gpencil_stroke_select_index_set(gpd, gps_active);
}
else {
pt_active->flag &= ~GP_SPOINT_SELECT;
gps_active->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps_active, true);
BKE_gpencil_stroke_select_index_reset(gps_active);
}
changed = true;
/* if stroke mode, don't check more points */
@@ -1832,7 +1832,7 @@ static bool gpencil_generic_stroke_select(bContext *C,
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
CTX_DATA_END;
@@ -2358,11 +2358,11 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
/* stroke too... */
if (deselect == false) {
hit_stroke->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke, false);
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke);
}
else {
hit_stroke->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, hit_stroke, true);
BKE_gpencil_stroke_select_index_reset(hit_stroke);
}
}
}
@@ -2374,13 +2374,13 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
BEZT_SEL_IDX(&hit_curve_point->bezt, hit_curve_handle);
hit_curve->flag |= GP_CURVE_SELECT;
hit_stroke->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke, false);
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke);
}
else {
/* we're adding selection, so selection must be true */
hit_point->flag |= GP_SPOINT_SELECT;
hit_stroke->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke, false);
BKE_gpencil_stroke_select_index_set(gpd, hit_stroke);
/* expand selection to segment */
int selectmode;
@@ -2602,7 +2602,7 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op)
if (gps_selected) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
/* Extend stroke selection. */
if (selectmode == GP_SELECTMODE_STROKE) {

View File

@@ -1167,7 +1167,7 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
if (keep_original) {
gps_active = BKE_gpencil_stroke_duplicate(gps, true, true);
gps_active->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps_active, true);
BKE_gpencil_stroke_select_index_reset(gps_active);
for (i = 0, pt = gps_active->points; i < gps_active->totpoints; i++, pt++) {
pt->flag &= ~GP_SPOINT_SELECT;
}
@@ -1692,7 +1692,7 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob)
}
if (gps->flag & GP_STROKE_SELECT) {
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
}
}
@@ -2616,7 +2616,7 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
}
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
}
@@ -2654,11 +2654,11 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
/* Change status of stroke */
if (selected) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
else {
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
CTX_DATA_END;
@@ -2695,7 +2695,7 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
}
gpc->flag &= ~GP_CURVE_SELECT;
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
GP_EDITABLE_CURVES_END(gps_iter);
}
@@ -2737,12 +2737,12 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
if (selected) {
gpc->flag |= GP_CURVE_SELECT;
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
else {
gpc->flag &= ~GP_CURVE_SELECT;
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
}
GP_EDITABLE_STROKES_END(gps_iter);

View File

@@ -941,11 +941,11 @@ static void rna_GPencil_stroke_select_set(PointerRNA *ptr, const bool value)
/* set new value */
if (value) {
gps->flag |= GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(gpd, gps, false);
BKE_gpencil_stroke_select_index_set(gpd, gps);
}
else {
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_set(NULL, gps, true);
BKE_gpencil_stroke_select_index_reset(gps);
}
/* ensure that the stroke's points are selected in the same way */