Tool System: use set/add/subtract for all circle select operators
This applies changes from the 3D view circle select to other operators.
This commit is contained in:
parent
0ae6747300
commit
8d8d113b73
Notes:
blender-bot
2023-09-08 04:55:43 +02:00
Referenced by issue #58025, Circle Select stays with either Select or deselect entire time it's open.
|
@ -5141,12 +5141,7 @@ def km_image_editor_tool_uv_select_circle(params):
|
|||
return (
|
||||
"Image Editor Tool: Uv, Select Circle",
|
||||
{"space_type": 'IMAGE_EDITOR', "region_type": 'WINDOW'},
|
||||
{"items": [
|
||||
("uv.select_circle", {"type": params.tool_mouse, "value": 'PRESS'},
|
||||
{"properties": [("wait_for_input", False), ("deselect", False)]}),
|
||||
("uv.select_circle", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("wait_for_input", False), ("deselect", True)]}),
|
||||
]},
|
||||
{"items": _template_items_tool_select_actions_circle("uv.select_circle", type=params.tool_mouse, value='PRESS')},
|
||||
)
|
||||
|
||||
|
||||
|
@ -5885,11 +5880,7 @@ def km_3d_view_tool_edit_gpencil_select_circle(params):
|
|||
return (
|
||||
"3D View Tool: Edit Gpencil, Select Circle",
|
||||
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
|
||||
{"items": [
|
||||
("gpencil.select_circle", {"type": params.tool_tweak, "value": 'ANY'}, None),
|
||||
("gpencil.select_circle", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("deselect", True)]}),
|
||||
]},
|
||||
{"items": _template_items_tool_select_actions_circle("gpencil.select_circle", type=params.tool_mouse, value='PRESS')},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1073,6 +1073,7 @@ class _defs_image_uv_select:
|
|||
def circle():
|
||||
def draw_settings(context, layout, tool):
|
||||
props = tool.operator_properties("uv.select_circle")
|
||||
layout.prop(props, "mode", expand=True)
|
||||
layout.prop(props, "radius")
|
||||
return dict(
|
||||
text="Select Circle",
|
||||
|
@ -1223,6 +1224,9 @@ class _defs_gpencil_edit:
|
|||
@ToolDef.from_fn
|
||||
def circle_select():
|
||||
def draw_settings(context, layout, tool):
|
||||
props = tool.operator_properties("gpencil.select_circle")
|
||||
layout.prop(props, "mode", expand=True)
|
||||
layout.prop(props, "radius")
|
||||
layout.prop(context.tool_settings.gpencil_sculpt, "intersection_threshold")
|
||||
return dict(
|
||||
text="Select Circle",
|
||||
|
|
|
@ -906,8 +906,6 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
|
|||
const int my = RNA_int_get(op->ptr, "y");
|
||||
const int radius = RNA_int_get(op->ptr, "radius");
|
||||
|
||||
bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
|
||||
GP_SpaceConversion gsc = {NULL};
|
||||
/* for bounding rect around circle (for quicky intersection testing) */
|
||||
rcti rect = {0};
|
||||
|
@ -921,6 +919,14 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const bool select = (sel_op != SEL_OP_SUB);
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
ED_gpencil_select_toggle_all(C, SEL_DESELECT);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
/* init space conversion stuff */
|
||||
gp_point_conversion_init(C, &gsc);
|
||||
|
||||
|
@ -973,7 +979,8 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -56,4 +56,7 @@ int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select,
|
|||
|
||||
int ED_select_similar_compare_float(const float delta, const float thresh, const int compare);
|
||||
bool ED_select_similar_compare_float_tree(const struct KDTree *tree, const float length, const float thresh, const int compare);
|
||||
|
||||
eSelectOp ED_select_op_modal(const eSelectOp sel_op, const bool is_first);
|
||||
|
||||
#endif /* __ED_SELECT_UTILS_H__ */
|
||||
|
|
|
@ -612,8 +612,6 @@ static int circle_select_exec(bContext *C, wmOperator *op)
|
|||
const int y = RNA_int_get(op->ptr, "y");
|
||||
const int radius = RNA_int_get(op->ptr, "radius");
|
||||
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
|
||||
/* compute ellipse and position in unified coordinates */
|
||||
ED_mask_get_size(sa, &width, &height);
|
||||
ED_mask_zoom(sa, ar, &zoomx, &zoomy);
|
||||
|
@ -624,6 +622,15 @@ static int circle_select_exec(bContext *C, wmOperator *op)
|
|||
|
||||
ED_mask_point_pos(sa, ar, x, y, &offset[0], &offset[1]);
|
||||
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const bool select = (sel_op != SEL_OP_SUB);
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
ED_mask_select_toggle_all(mask, SEL_DESELECT);
|
||||
ED_mask_select_flush_all(mask);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
/* do actual selection */
|
||||
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
|
||||
MaskSpline *spline;
|
||||
|
@ -677,7 +684,8 @@ void MASK_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
static int mask_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
|
|
@ -610,8 +610,6 @@ void ACTION_OT_select_lasso(wmOperatorType *ot)
|
|||
static int action_circle_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
bAnimContext ac;
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
const short selectmode = select ? SELECT_ADD : SELECT_SUBTRACT;
|
||||
|
||||
KeyframeEdit_CircleData data = {0};
|
||||
rctf rect_fl;
|
||||
|
@ -624,6 +622,13 @@ static int action_circle_select_exec(bContext *C, wmOperator *op)
|
|||
if (ANIM_animdata_get_context(C, &ac) == 0)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const short selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT;
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
deselect_action_keys(&ac, 0, SELECT_SUBTRACT);
|
||||
}
|
||||
|
||||
data.mval[0] = x;
|
||||
data.mval[1] = y;
|
||||
data.radius_squared = radius * radius;
|
||||
|
@ -659,7 +664,8 @@ void ACTION_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/* ******************** Column Select Operator **************************** */
|
||||
|
|
|
@ -698,7 +698,13 @@ static int circle_select_exec(bContext *C, wmOperator *op)
|
|||
const int y = RNA_int_get(op->ptr, "y");
|
||||
const int radius = RNA_int_get(op->ptr, "radius");
|
||||
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const bool select = (sel_op != SEL_OP_SUB);
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
ED_clip_select_all(sc, SEL_DESELECT, NULL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
/* compute ellipse and position in unified coordinates */
|
||||
ED_space_clip_get_size(sc, &width, &height);
|
||||
|
@ -782,7 +788,8 @@ void CLIP_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/********************** select all operator *********************/
|
||||
|
|
|
@ -505,8 +505,6 @@ void GRAPH_OT_select_lasso(wmOperatorType *ot)
|
|||
static int graph_circle_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
bAnimContext ac;
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
const short selectmode = select ? SELECT_ADD : SELECT_SUBTRACT;
|
||||
bool incl_handles = false;
|
||||
|
||||
KeyframeEdit_CircleData data = {0};
|
||||
|
@ -520,6 +518,13 @@ static int graph_circle_select_exec(bContext *C, wmOperator *op)
|
|||
if (ANIM_animdata_get_context(C, &ac) == 0)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const short selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT;
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
deselect_graph_keys(&ac, 0, SELECT_SUBTRACT, true);
|
||||
}
|
||||
|
||||
data.mval[0] = x;
|
||||
data.mval[1] = y;
|
||||
data.radius_squared = radius * radius;
|
||||
|
@ -566,7 +571,8 @@ void GRAPH_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/* ******************** Column Select Operator **************************** */
|
||||
|
|
|
@ -619,7 +619,12 @@ static int node_circleselect_exec(bContext *C, wmOperator *op)
|
|||
|
||||
float zoom = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur));
|
||||
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const bool select = (sel_op != SEL_OP_SUB);
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT);
|
||||
}
|
||||
|
||||
/* get operator properties */
|
||||
x = RNA_int_get(op->ptr, "x");
|
||||
|
@ -657,7 +662,8 @@ void NODE_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/* ****** Lasso Select ****** */
|
||||
|
|
|
@ -3351,17 +3351,12 @@ static bool object_circle_select(ViewContext *vc, const eSelectOp sel_op, const
|
|||
static int view3d_circle_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ViewContext vc;
|
||||
const bool is_first = (op->customdata && (((wmGesture *)op->customdata)->is_active_prev == false));
|
||||
const int radius = RNA_int_get(op->ptr, "radius");
|
||||
eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
|
||||
const int mval[2] = {RNA_int_get(op->ptr, "x"),
|
||||
RNA_int_get(op->ptr, "y")};
|
||||
|
||||
if (is_first == false) {
|
||||
if (sel_op == SEL_OP_SET) {
|
||||
sel_op = SEL_OP_ADD;
|
||||
}
|
||||
}
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
|
||||
ED_view3d_viewcontext_init(C, &vc);
|
||||
|
||||
|
|
|
@ -69,6 +69,19 @@ int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select,
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to use for selection operations that run multiple times (circle select).
|
||||
*/
|
||||
eSelectOp ED_select_op_modal(const eSelectOp sel_op, const bool is_first)
|
||||
{
|
||||
if (sel_op == SEL_OP_SET) {
|
||||
if (is_first == false) {
|
||||
return SEL_OP_ADD;
|
||||
}
|
||||
}
|
||||
return sel_op;
|
||||
}
|
||||
|
||||
int ED_select_similar_compare_float(const float delta, const float thresh, const int compare)
|
||||
{
|
||||
switch (compare) {
|
||||
|
|
|
@ -3339,6 +3339,7 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
||||
SpaceImage *sima = CTX_wm_space_image(C);
|
||||
Image *ima = CTX_data_edit_image(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
|
@ -3349,7 +3350,6 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
|
|||
MLoopUV *luv;
|
||||
int x, y, radius, width, height;
|
||||
float zoomx, zoomy, offset[2], ellipse[2];
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
|
||||
const bool use_face_center = (
|
||||
(ts->uv_flag & UV_SYNC_SELECTION) ?
|
||||
|
@ -3376,6 +3376,14 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
|
|||
uint objects_len = 0;
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, ((View3D *)NULL), &objects_len);
|
||||
|
||||
const eSelectOp sel_op = ED_select_op_modal(
|
||||
RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata));
|
||||
const bool select = (sel_op != SEL_OP_SUB);
|
||||
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
||||
uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
|
||||
changed_multi = true;
|
||||
}
|
||||
|
||||
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
|
||||
Object *obedit = objects[ob_index];
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
|
@ -3454,7 +3462,8 @@ static void UV_OT_select_circle(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_gesture_circle_select(ot);
|
||||
WM_operator_properties_gesture_circle(ot);
|
||||
WM_operator_properties_select_operation_simple(ot);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -375,9 +375,7 @@ void WM_operator_properties_gesture_lasso_ex(struct wmOperatorType *ot, b
|
|||
void WM_operator_properties_gesture_lasso(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_gesture_lasso_select(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor);
|
||||
void WM_operator_properties_gesture_circle_ex(struct wmOperatorType *ot, bool deselect);
|
||||
void WM_operator_properties_gesture_circle(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_gesture_circle_select(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_mouse_select(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_select_all(struct wmOperatorType *ot);
|
||||
void WM_operator_properties_select_action(struct wmOperatorType *ot, int default_action);
|
||||
|
@ -483,6 +481,7 @@ void WM_gesture_straightline_cancel(struct bContext *C, struct wmOperator *op);
|
|||
struct wmGesture *WM_gesture_new(struct bContext *C, const struct wmEvent *event, int type);
|
||||
void WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
|
||||
void WM_gestures_remove(struct bContext *C);
|
||||
bool WM_gesture_is_modal_first(const struct wmGesture *gesture);
|
||||
|
||||
/* fileselecting support */
|
||||
void WM_event_add_fileselect(struct bContext *C, struct wmOperator *op);
|
||||
|
|
|
@ -116,6 +116,13 @@ void WM_gestures_remove(bContext *C)
|
|||
WM_gesture_end(C, win->gesture.first);
|
||||
}
|
||||
|
||||
bool WM_gesture_is_modal_first(const wmGesture *gesture)
|
||||
{
|
||||
if (gesture == NULL) {
|
||||
return true;
|
||||
}
|
||||
return (gesture->is_active_prev == false);
|
||||
}
|
||||
|
||||
/* tweak and line gestures */
|
||||
int wm_gesture_evaluate(wmGesture *gesture)
|
||||
|
|
|
@ -353,7 +353,7 @@ void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
|
|||
/**
|
||||
* Use with #WM_gesture_circle_invoke
|
||||
*/
|
||||
void WM_operator_properties_gesture_circle_ex(wmOperatorType *ot, bool deselect)
|
||||
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
const int radius_default = 25;
|
||||
|
@ -366,21 +366,6 @@ void WM_operator_properties_gesture_circle_ex(wmOperatorType *ot, bool deselect)
|
|||
|
||||
prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
if (deselect) {
|
||||
prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Deselect rather than select items");
|
||||
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
}
|
||||
|
||||
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
|
||||
{
|
||||
WM_operator_properties_gesture_circle_ex(ot, false);
|
||||
}
|
||||
|
||||
void WM_operator_properties_gesture_circle_select(wmOperatorType *ot)
|
||||
{
|
||||
WM_operator_properties_gesture_circle_ex(ot, true);
|
||||
}
|
||||
|
||||
void WM_operator_properties_mouse_select(wmOperatorType *ot)
|
||||
|
|
Loading…
Reference in New Issue