diff options
author | Antonioya <blendergit@gmail.com> | 2018-09-20 12:32:59 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2018-09-20 12:56:59 +0300 |
commit | 67a6cb665ec9460c4401a4fc450f18a28556d982 (patch) | |
tree | ecb7c84925bf7722122c444818e8f36ef5d2ec2f | |
parent | 12788906113c4f2b304b368001bd2ef68c4dc6b8 (diff) |
GP: New select mode
Now it's possible select points or strokes
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 4 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_select.c | 93 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 13 |
4 files changed, 106 insertions, 12 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index dee6203308c..a2e51045d34 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -82,6 +82,10 @@ class VIEW3D_HT_header(Header): text="Shapes" ) + if gpd.use_stroke_edit_mode: + row = layout.row(align=True) + row.prop(tool_settings, "gpencil_selectmode", text="", expand=True) + if gpd.use_stroke_edit_mode or gpd.is_stroke_sculpt_mode or gpd.is_stroke_weight_mode: row = layout.row(align=True) row.prop(gpd, "use_multiedit", text="", icon='FORCE_HARMONIC') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 38f0e85e1cb..ea60d30d94f 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -827,13 +827,13 @@ void GPENCIL_OT_select_less(wmOperatorType *ot) static bool gp_stroke_do_circle_sel( bGPDstroke *gps, GP_SpaceConversion *gsc, const int mx, const int my, const int radius, - const bool select, rcti *rect, float diff_mat[4][4]) + const bool select, rcti *rect, float diff_mat[4][4], const int selectmode) { bGPDspoint *pt1, *pt2; int x0 = 0, y0 = 0, x1 = 0, y1 = 0; int i; bool changed = false; - + if (gps->totpoints == 1) { bGPDspoint pt_temp; gp_point_to_parent_space(gps->points, diff_mat, &pt_temp); @@ -861,6 +861,7 @@ static bool gp_stroke_do_circle_sel( /* Loop over the points in the stroke, checking for intersections * - an intersection means that we touched the stroke */ + bool hit = false; for (i = 0; (i + 1) < gps->totpoints; i++) { /* get points to work with */ pt1 = gps->points + i; @@ -888,6 +889,7 @@ static bool gp_stroke_do_circle_sel( * (as the last point otherwise wouldn't get selected * as we only do n-1 loops through). */ + hit = true; if (select) { pt1->flag |= GP_SPOINT_SELECT; pt2->flag |= GP_SPOINT_SELECT; @@ -902,6 +904,22 @@ static bool gp_stroke_do_circle_sel( } } } + /* if stroke mode, don't check more points */ + if ((hit) && (selectmode == GP_SELECTMODE_STROKE)) { + break; + } + } + + /* if stroke mode expand selection */ + if ((hit) && (selectmode == GP_SELECTMODE_STROKE)) { + for (i = 0, pt1 = gps->points; i < gps->totpoints; i++, pt1++) { + if (select) { + pt1->flag |= GP_SPOINT_SELECT; + } + else { + pt1->flag &= ~GP_SPOINT_SELECT; + } + } } /* Ensure that stroke selection is in sync with its points */ @@ -915,6 +933,9 @@ static bool gp_stroke_do_circle_sel( static int gpencil_circle_select_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); + ToolSettings *ts = CTX_data_tool_settings(C); + const int selectmode = ts->gpencil_selectmode; + /* if not edit/sculpt mode, the event is catched but not processed */ if (GPENCIL_NONE_EDIT_MODE(gpd)) { return OPERATOR_CANCELLED; @@ -955,7 +976,7 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op) GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) { changed |= gp_stroke_do_circle_sel( - gps, &gsc, mx, my, radius, select, &rect, diff_mat); + gps, &gsc, mx, my, radius, select, &rect, diff_mat, selectmode); } GP_EDITABLE_STROKES_END; @@ -999,27 +1020,31 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot) static int gpencil_border_select_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); + ToolSettings *ts = CTX_data_tool_settings(C); ScrArea *sa = CTX_wm_area(C); const bool select = !RNA_boolean_get(op->ptr, "deselect"); - const bool extend = RNA_boolean_get(op->ptr, "extend") && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); + bool extend = RNA_boolean_get(op->ptr, "extend") && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); + const bool strokemode = (ts->gpencil_selectmode == GP_SELECTMODE_STROKE) && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); GP_SpaceConversion gsc = {NULL}; rcti rect = {0}; bool changed = false; - /* sanity checks */ if (sa == NULL) { BKE_report(op->reports, RPT_ERROR, "No active area"); return OPERATOR_CANCELLED; } + if (strokemode) { + extend = false; + } + /* init space conversion stuff */ gp_point_conversion_init(C, &gsc); - - + /* deselect all strokes first? */ if (select && !extend) { CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) @@ -1045,7 +1070,7 @@ static int gpencil_border_select_exec(bContext *C, wmOperator *op) bGPDspoint *pt; int i; - + bool hit = false; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { int x0, y0; @@ -1056,6 +1081,7 @@ static int gpencil_border_select_exec(bContext *C, wmOperator *op) /* test if in selection rect */ if ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(&rect, x0, y0)) { + hit = true; if (select) { pt->flag |= GP_SPOINT_SELECT; } @@ -1064,6 +1090,22 @@ static int gpencil_border_select_exec(bContext *C, wmOperator *op) } changed = true; + + /* if stroke mode, don't check more points */ + if ((hit) && (strokemode)) { + break; + } + } + } + /* if stroke mode expand selection */ + if ((hit) && (strokemode)) { + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + if (select) { + pt->flag |= GP_SPOINT_SELECT; + } + else { + pt->flag &= ~GP_SPOINT_SELECT; + } } } @@ -1120,12 +1162,13 @@ void GPENCIL_OT_select_border(wmOperatorType *ot) static int gpencil_lasso_select_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); + ToolSettings *ts = CTX_data_tool_settings(C); GP_SpaceConversion gsc = {NULL}; rcti rect = {0}; - const bool extend = RNA_boolean_get(op->ptr, "extend") && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); + bool extend = RNA_boolean_get(op->ptr, "extend") && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); const bool select = !RNA_boolean_get(op->ptr, "deselect"); - + const bool strokemode = (ts->gpencil_selectmode == GP_SELECTMODE_STROKE) && ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0); int mcords_tot; const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); @@ -1135,6 +1178,10 @@ static int gpencil_lasso_select_exec(bContext *C, wmOperator *op) if (mcords == NULL) return OPERATOR_PASS_THROUGH; + if (strokemode) { + extend = false; + } + /* compute boundbox of lasso (for faster testing later) */ BLI_lasso_boundbox(&rect, mcords, mcords_tot); @@ -1162,7 +1209,7 @@ static int gpencil_lasso_select_exec(bContext *C, wmOperator *op) { bGPDspoint *pt; int i; - + bool hit = false; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { int x0, y0; @@ -1174,6 +1221,7 @@ static int gpencil_lasso_select_exec(bContext *C, wmOperator *op) if ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(&rect, x0, y0) && BLI_lasso_is_point_inside(mcords, mcords_tot, x0, y0, INT_MAX)) { + hit = true; if (select) { pt->flag |= GP_SPOINT_SELECT; } @@ -1182,6 +1230,23 @@ static int gpencil_lasso_select_exec(bContext *C, wmOperator *op) } changed = true; + + /* if stroke mode, don't check more points */ + if ((hit) && (strokemode)) { + break; + } + } + } + + /* if stroke mode expand selection */ + if ((hit) && (strokemode)) { + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + if (select) { + pt->flag |= GP_SPOINT_SELECT; + } + else { + pt->flag &= ~GP_SPOINT_SELECT; + } } } @@ -1239,6 +1304,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) { ScrArea *sa = CTX_wm_area(C); bGPdata *gpd = ED_gpencil_data_get_active(C); + ToolSettings *ts = CTX_data_tool_settings(C); /* "radius" is simply a threshold (screen space) to make it easier to test with a tolerance */ const float radius = 0.75f * U.widget_unit; @@ -1263,6 +1329,11 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + /* if select mode is stroke, use whole stroke */ + if (ts->gpencil_selectmode == GP_SELECTMODE_STROKE) { + whole = true; + } + /* init space conversion stuff */ gp_point_conversion_init(C, &gsc); diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 1aff0ae877d..597f6096acc 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1276,7 +1276,7 @@ typedef struct ToolSettings { char annotate_v3d_align; /* stroke placement settings - 3D View */ short annotate_thickness; /* default stroke thickness for annotation strokes */ - char _pad3[2]; + short gpencil_selectmode; /* stroke selection mode */ /* Grease Pencil Sculpt */ struct GP_BrushEdit_Settings gp_sculpt; @@ -2106,6 +2106,12 @@ typedef enum eGPencil_Placement_Flags { GP_PROJECT_CURSOR = (1 << 5), } eGPencil_Placement_Flags; +/* ToolSettings.gpencil_selectmode */ +typedef enum eGPencil_Selectmode_types { + GP_SELECTMODE_POINT = 0, + GP_SELECTMODE_STROKE = 1 +} eGPencil_Selectmode_types; + /* ToolSettings.particle flag */ #define PE_KEEP_LENGTHS 1 #define PE_LOCK_FIRST 2 diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index aa103fccc53..166f0b4dd0f 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2156,6 +2156,12 @@ static void rna_def_tool_settings(BlenderRNA *brna) {0, NULL, 0, NULL, NULL} }; + static const EnumPropertyItem gpencil_selectmode_items[] = { + {GP_SELECTMODE_POINT, "POINT", ICON_VERTEXSEL, "Point", "Select only points"}, + {GP_SELECTMODE_STROKE, "STROKE", ICON_EDGESEL, "Stroke", "Select all stroke points" }, + {0, NULL, 0, NULL, NULL} + }; + static const EnumPropertyItem annotation_stroke_placement_items[] = { {GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR, "CURSOR", ICON_CURSOR, "3D Cursor", "Draw stroke at 3D cursor location" }, {0, "VIEW", ICON_VISIBLE_IPO_ON, "View", "Stick stroke to the view "}, /* weird, GP_PROJECT_VIEWALIGN is inverted */ @@ -2457,6 +2463,13 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Only Endpoints", "Only use the first and last parts of the stroke for snapping"); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL); + /* Grease Pencil - Select mode */ + prop = RNA_def_property(srna, "gpencil_selectmode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "gpencil_selectmode"); + RNA_def_property_enum_items(prop, gpencil_selectmode_items); + RNA_def_property_ui_text(prop, "Select Mode", ""); + RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0); + /* Annotations - 2D Views Stroke Placement */ prop = RNA_def_property(srna, "annotation_stroke_placement_view2d", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "gpencil_v2d_align"); |