Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_select.c
| Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "gpencil_intern.h" | #include "gpencil_intern.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Shared Utilities | /** \name Shared Utilities | ||||
| * \{ */ | * \{ */ | ||||
| /* Convert sculpt mask mode to Select mode */ | |||||
| static int gpencil_select_mode_from_sculpt(eGP_Sculpt_SelectMaskFlag mode) | |||||
| { | |||||
| if (mode & GP_SCULPT_MASK_SELECTMODE_POINT) { | |||||
| return GP_SELECTMODE_POINT; | |||||
| } | |||||
| else if (mode & GP_SCULPT_MASK_SELECTMODE_STROKE) { | |||||
| return GP_SELECTMODE_STROKE; | |||||
| } | |||||
| else if (GP_SCULPT_MASK_SELECTMODE_SEGMENT) { | |||||
| return GP_SELECTMODE_SEGMENT; | |||||
| } | |||||
| else { | |||||
| return GP_SELECTMODE_POINT; | |||||
| } | |||||
| } | |||||
| static bool gpencil_select_poll(bContext *C) | static bool gpencil_select_poll(bContext *C) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| if (GPENCIL_SCULPT_MODE(gpd)) { | if (GPENCIL_SCULPT_MODE(gpd)) { | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| if ((ts->gp_sculpt.flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) == 0) { | if (!(GPENCIL_ANY_SCULPT_MASK(ts->gpencil_selectmode_sculpt))) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* we just need some visible strokes, and to be in editmode or other modes only to catch event */ | /* we just need some visible strokes, and to be in editmode or other modes only to catch event */ | ||||
| if (GPENCIL_ANY_MODE(gpd)) { | if (GPENCIL_ANY_MODE(gpd)) { | ||||
| /* TODO: include a check for visible strokes? */ | /* TODO: include a check for visible strokes? */ | ||||
| if (gpd->layers.first) { | if (gpd->layers.first) { | ||||
| ▲ Show 20 Lines • Show All 827 Lines • ▼ Show 20 Lines | static bool gp_stroke_do_circle_sel(bGPDlayer *gpl, | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| static int gpencil_circle_select_exec(bContext *C, wmOperator *op) | static int gpencil_circle_select_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| const int selectmode = ts->gpencil_selectmode; | Object *ob = CTX_data_active_object(C); | ||||
| const int selectmode = (ob && ob->mode == OB_MODE_SCULPT_GPENCIL) ? | |||||
| gpencil_select_mode_from_sculpt(ts->gpencil_selectmode_sculpt) : | |||||
| ts->gpencil_selectmode_edit; | |||||
| const float scale = ts->gp_sculpt.isect_threshold; | const float scale = ts->gp_sculpt.isect_threshold; | ||||
| /* if not edit/sculpt mode, the event is catched but not processed */ | /* if not edit/sculpt mode, the event is catched but not processed */ | ||||
| if (GPENCIL_NONE_EDIT_MODE(gpd)) { | if (GPENCIL_NONE_EDIT_MODE(gpd)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | typedef bool (*GPencilTestFn)(bGPDstroke *gps, | ||||
| const float diff_mat[4][4], | const float diff_mat[4][4], | ||||
| void *user_data); | void *user_data); | ||||
| static int gpencil_generic_select_exec(bContext *C, | static int gpencil_generic_select_exec(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| GPencilTestFn is_inside_fn, | GPencilTestFn is_inside_fn, | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | |||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| const bool strokemode = ((ts->gpencil_selectmode == GP_SELECTMODE_STROKE) && | |||||
| const short selectmode = (ob && ob->mode == OB_MODE_SCULPT_GPENCIL) ? | |||||
| gpencil_select_mode_from_sculpt(ts->gpencil_selectmode_sculpt) : | |||||
| ts->gpencil_selectmode_edit; | |||||
| const bool strokemode = ((selectmode == GP_SELECTMODE_STROKE) && | |||||
| ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)); | ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)); | ||||
| const bool segmentmode = ((ts->gpencil_selectmode == GP_SELECTMODE_SEGMENT) && | const bool segmentmode = ((selectmode == GP_SELECTMODE_SEGMENT) && | ||||
| ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)); | ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)); | ||||
| const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); | const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); | ||||
| const float scale = ts->gp_sculpt.isect_threshold; | const float scale = ts->gp_sculpt.isect_threshold; | ||||
| GP_SpaceConversion gsc = {NULL}; | GP_SpaceConversion gsc = {NULL}; | ||||
| bool changed = false; | bool changed = false; | ||||
| Show All 26 Lines | static int gpencil_generic_select_exec(bContext *C, | ||||
| GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { | GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { | ||||
| bGPDspoint *pt; | bGPDspoint *pt; | ||||
| int i; | int i; | ||||
| bool hit = false; | bool hit = false; | ||||
| for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { | for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { | ||||
| /* convert point coords to screenspace */ | /* convert point coords to screenspace */ | ||||
| const bool is_inside = is_inside_fn(gps, pt, &gsc, gpstroke_iter.diff_mat, user_data); | const bool is_inside = is_inside_fn(gps, pt, &gsc, gpstroke_iter.diff_mat, user_data); | ||||
| if (strokemode == false) { | if (strokemode == false) { | ||||
| const bool is_select = (pt->flag & GP_SPOINT_SELECT) != 0; | const bool is_select = (pt->flag & GP_SPOINT_SELECT) != 0; | ||||
| const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); | const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); | ||||
| if (sel_op_result != -1) { | if (sel_op_result != -1) { | ||||
| SET_FLAG_FROM_TEST(pt->flag, sel_op_result, GP_SPOINT_SELECT); | SET_FLAG_FROM_TEST(pt->flag, sel_op_result, GP_SPOINT_SELECT); | ||||
| changed = true; | changed = true; | ||||
| /* expand selection to segment */ | /* expand selection to segment */ | ||||
| ▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { | ||||
| } | } | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| } | } | ||||
| static int gpencil_select_exec(bContext *C, wmOperator *op) | static int gpencil_select_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| Object *ob = CTX_data_active_object(C); | |||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| const float scale = ts->gp_sculpt.isect_threshold; | const float scale = ts->gp_sculpt.isect_threshold; | ||||
| /* "radius" is simply a threshold (screen space) to make it easier to test with a tolerance */ | /* "radius" is simply a threshold (screen space) to make it easier to test with a tolerance */ | ||||
| const float radius = 0.50f * U.widget_unit; | const float radius = 0.50f * U.widget_unit; | ||||
| const int radius_squared = (int)(radius * radius); | const int radius_squared = (int)(radius * radius); | ||||
| Show All 14 Lines | static int gpencil_select_exec(bContext *C, wmOperator *op) | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (sa == NULL) { | if (sa == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No active area"); | BKE_report(op->reports, RPT_ERROR, "No active area"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* if select mode is stroke, use whole stroke */ | /* if select mode is stroke, use whole stroke */ | ||||
| if (ts->gpencil_selectmode == GP_SELECTMODE_STROKE) { | if ((ob) && (ob->mode == OB_MODE_SCULPT_GPENCIL)) { | ||||
| whole = true; | whole = (bool)(gpencil_select_mode_from_sculpt(ts->gpencil_selectmode_sculpt) == | ||||
| GP_SELECTMODE_STROKE); | |||||
| } | |||||
| else { | |||||
| whole = (bool)(ts->gpencil_selectmode_edit == GP_SELECTMODE_STROKE); | |||||
| } | } | ||||
| /* init space conversion stuff */ | /* init space conversion stuff */ | ||||
| gp_point_conversion_init(C, &gsc); | gp_point_conversion_init(C, &gsc); | ||||
| /* get mouse location */ | /* get mouse location */ | ||||
| RNA_int_get_array(op->ptr, "location", mval); | RNA_int_get_array(op->ptr, "location", mval); | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | static int gpencil_select_exec(bContext *C, wmOperator *op) | ||||
| else { | else { | ||||
| /* just the point (and the stroke) */ | /* just the point (and the stroke) */ | ||||
| if (deselect == false) { | if (deselect == false) { | ||||
| /* we're adding selection, so selection must be true */ | /* we're adding selection, so selection must be true */ | ||||
| hit_point->flag |= GP_SPOINT_SELECT; | hit_point->flag |= GP_SPOINT_SELECT; | ||||
| hit_stroke->flag |= GP_STROKE_SELECT; | hit_stroke->flag |= GP_STROKE_SELECT; | ||||
| /* expand selection to segment */ | /* expand selection to segment */ | ||||
| if (ts->gpencil_selectmode == GP_SELECTMODE_SEGMENT) { | const short selectmode = (ob && ob->mode == OB_MODE_SCULPT_GPENCIL) ? | ||||
| gpencil_select_mode_from_sculpt(ts->gpencil_selectmode_sculpt) : | |||||
| ts->gpencil_selectmode_edit; | |||||
| if (selectmode == GP_SELECTMODE_SEGMENT) { | |||||
| float r_hita[3], r_hitb[3]; | float r_hita[3], r_hitb[3]; | ||||
| bool hit_select = (bool)(hit_point->flag & GP_SPOINT_SELECT); | bool hit_select = (bool)(hit_point->flag & GP_SPOINT_SELECT); | ||||
| ED_gpencil_select_stroke_segment( | ED_gpencil_select_stroke_segment( | ||||
| hit_layer, hit_stroke, hit_point, hit_select, false, scale, r_hita, r_hitb); | hit_layer, hit_stroke, hit_point, hit_select, false, scale, r_hita, r_hitb); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* deselect point */ | /* deselect point */ | ||||
| ▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines | |||||