[Bf-blender-cvs] [779826d] GPencil_EditStrokes: Code cleanup: Separated out selection syncing logic for strokes into an API Function
Joshua Leung
noreply at git.blender.org
Sat Oct 11 00:44:58 CEST 2014
Commit: 779826d2956c86991239f5b4b1b8a9c8544a999f
Author: Joshua Leung
Date: Sat Oct 11 11:43:43 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rB779826d2956c86991239f5b4b1b8a9c8544a999f
Code cleanup: Separated out selection syncing logic for strokes into an API Function
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 86c1116..8095d0f 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -35,6 +35,7 @@ struct ListBase;
struct bGPdata;
struct bGPDlayer;
struct bGPDframe;
+struct bGPDstroke;
/* ------------ Grease-Pencil API ------------------ */
@@ -43,6 +44,8 @@ void free_gpencil_frames(struct bGPDlayer *gpl);
void free_gpencil_layers(struct ListBase *list);
void BKE_gpencil_free(struct bGPdata *gpd);
+void gpencil_stroke_sync_selection(struct bGPDstroke *gps);
+
struct bGPDframe *gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
struct bGPDlayer *gpencil_layer_addnew(struct bGPdata *gpd, const char *name, int setactive);
struct bGPdata *gpencil_data_addnew(const char name[]);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index e226e9d..fc09400 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -300,6 +300,31 @@ bGPdata *gpencil_data_duplicate(bGPdata *src)
return dst;
}
+/* -------- GP-Stroke API --------- */
+
+/* ensure selection status of stroke is in sync with its points */
+void gpencil_stroke_sync_selection(bGPDstroke *gps)
+{
+ bGPDspoint *pt;
+ int i;
+
+ /* error checking */
+ if (gps == NULL)
+ return;
+
+ /* we'll stop when we find the first selected point,
+ * so initially, we must deselect
+ */
+ gps->flag &= ~GP_STROKE_SELECT;
+
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ if (pt->flag & GP_SPOINT_SELECT) {
+ gps->flag |= GP_STROKE_SELECT;
+ break;
+ }
+ }
+}
+
/* -------- GP-Frame API ---------- */
/* delete the last stroke of the given frame */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 6088c63..2d27f66 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -248,17 +248,8 @@ static bool gp_stroke_do_circle_sel(bGPDstroke *gps, ARegion *ar, View2D *v2d, r
}
}
- /* Do a second pass to sync up the stroke selection with the points selection
- * - We only need a single selected vert to have a selected stroke
- */
- gps->flag &= ~GP_STROKE_SELECT;
-
- for (i = 0, pt1 = gps->points; i < gps->totpoints; i++, pt1++) {
- if (pt1->flag & GP_SPOINT_SELECT) {
- gps->flag |= GP_STROKE_SELECT;
- break;
- }
- }
+ /* Ensure that stroke selection is in sync with its points */
+ gpencil_stroke_sync_selection(gps);
}
return changed;
@@ -514,21 +505,11 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
hit_stroke->flag |= GP_STROKE_SELECT;
}
else {
- bGPDspoint *pt;
- int i;
-
/* deselect point */
hit_point->flag &= ~GP_SPOINT_SELECT;
/* ensure that stroke is selected correctly */
- hit_stroke->flag &= ~GP_STROKE_SELECT;
-
- for (i = 0, pt = hit_stroke->points; i < hit_stroke->totpoints; i++, pt++) {
- if (pt->flag & GP_SPOINT_SELECT) {
- hit_stroke->flag |= GP_STROKE_SELECT;
- break;
- }
- }
+ gpencil_stroke_sync_selection(hit_stroke);
}
}
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 5069a62..9a474a1 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -161,9 +161,6 @@ static void rna_GPencil_stroke_point_select_set(PointerRNA *ptr, const int value
*/
gps = rna_GPencil_stroke_point_find_stroke(gpd, pt, NULL, NULL);
if (gps) {
- bGPDspoint *spt;
- int i;
-
/* Set the new selection state for the point */
if (value)
pt->flag |= GP_SPOINT_SELECT;
@@ -171,14 +168,7 @@ static void rna_GPencil_stroke_point_select_set(PointerRNA *ptr, const int value
pt->flag &= ~GP_SPOINT_SELECT;
/* Check if the stroke should be selected or not... */
- gps->flag &= ~GP_STROKE_SELECT;
-
- for (i = 0, spt = gps->points; i < gps->totpoints; i++, spt++) {
- if (spt->flag & GP_SPOINT_SELECT) {
- gps->flag |= GP_STROKE_SELECT;
- break;
- }
- }
+ gpencil_stroke_sync_selection(gps);
}
}
More information about the Bf-blender-cvs
mailing list