Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-03-15 13:03:04 +0300
committerCampbell Barton <campbell@blender.org>2022-03-16 06:48:25 +0300
commit5e5285baf621a0c225cb5fc06fcec6ffed8302d7 (patch)
treefcdc655a6b063d32a7630b648e126c20ade295f2 /source/blender/editors/curve
parent9a763d24f2b50ad38d22cad0a23d7344afe5f1c7 (diff)
View 3D: move picking arguments into a struct & minor refactor
- Add SelectPick_Params struct to make picking logic more straightforward and easier to extend. - Use `eSelectOp` instead of booleans (extend, deselect, toggle) which were used to represent 4 states (which wasn't obvious). - Handle deselect_all when pocking instead of view3d_select_exec, de-duplicate de-selection which was already needed in when replacing the selection in picking functions. - Handle outliner update & notifiers in the picking functions instead of view3d_select_exec. - Fix particle select deselect_all option which did nothing.
Diffstat (limited to 'source/blender/editors/curve')
-rw-r--r--source/blender/editors/curve/editcurve.c189
-rw-r--r--source/blender/editors/curve/editfont.c9
2 files changed, 108 insertions, 90 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 2dcddd01670..1c1783669c3 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -44,6 +44,7 @@
#include "ED_object.h"
#include "ED_outliner.h"
#include "ED_screen.h"
+#include "ED_select_utils.h"
#include "ED_transform.h"
#include "ED_transform_snap_object_context.h"
#include "ED_types.h"
@@ -4722,8 +4723,9 @@ void CURVE_OT_make_segment(wmOperatorType *ot)
/** \name Pick Select from 3D View
* \{ */
-bool ED_curve_editnurb_select_pick(
- bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
+bool ED_curve_editnurb_select_pick(bContext *C,
+ const int mval[2],
+ const struct SelectPick_Params *params)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc;
@@ -4732,129 +4734,144 @@ bool ED_curve_editnurb_select_pick(
BPoint *bp = NULL;
Base *basact = NULL;
short hand;
+ bool changed = false;
view3d_operator_needs_opengl(C);
ED_view3d_viewcontext_init(C, &vc, depsgraph);
copy_v2_v2_int(vc.mval, mval);
- if (ED_curve_pick_vert(&vc, 1, &nu, &bezt, &bp, &hand, &basact)) {
- Object *obedit = basact->object;
- Curve *cu = obedit->data;
- ListBase *editnurb = object_editcurve_get(obedit);
- const void *vert = BKE_curve_vert_active_get(cu);
+ const bool found = ED_curve_pick_vert(&vc, 1, &nu, &bezt, &bp, &hand, &basact);
- if (!extend && !deselect && !toggle) {
- uint objects_len = 0;
- Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
- vc.view_layer, vc.v3d, &objects_len);
- for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
- Object *ob_iter = objects[ob_index];
+ if ((params->sel_op == SEL_OP_SET) && (found || params->deselect_all)) {
+ /* Deselect everything. */
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
+ vc.view_layer, vc.v3d, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
- ED_curve_deselect_all(((Curve *)ob_iter->data)->editnurb);
+ ED_curve_deselect_all(((Curve *)ob_iter->data)->editnurb);
- DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
- }
- MEM_freeN(objects);
+ DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
}
+ MEM_freeN(objects);
+ changed = true;
+ }
- if (extend) {
- if (bezt) {
- if (hand == 1) {
- select_beztriple(bezt, SELECT, SELECT, HIDDEN);
- }
- else {
- if (hand == 0) {
- bezt->f1 |= SELECT;
+ if (found) {
+ Object *obedit = basact->object;
+ Curve *cu = obedit->data;
+ ListBase *editnurb = object_editcurve_get(obedit);
+ const void *vert = BKE_curve_vert_active_get(cu);
+
+ switch (params->sel_op) {
+ case SEL_OP_ADD: {
+ if (bezt) {
+ if (hand == 1) {
+ select_beztriple(bezt, SELECT, SELECT, HIDDEN);
}
else {
- bezt->f3 |= SELECT;
- }
- }
- BKE_curve_nurb_vert_active_set(cu, nu, bezt);
- }
- else {
- select_bpoint(bp, SELECT, SELECT, HIDDEN);
- BKE_curve_nurb_vert_active_set(cu, nu, bp);
- }
- }
- else if (deselect) {
- if (bezt) {
- if (hand == 1) {
- select_beztriple(bezt, DESELECT, SELECT, HIDDEN);
- if (bezt == vert) {
- cu->actvert = CU_ACT_NONE;
+ if (hand == 0) {
+ bezt->f1 |= SELECT;
+ }
+ else {
+ bezt->f3 |= SELECT;
+ }
}
- }
- else if (hand == 0) {
- bezt->f1 &= ~SELECT;
+ BKE_curve_nurb_vert_active_set(cu, nu, bezt);
}
else {
- bezt->f3 &= ~SELECT;
- }
- }
- else {
- select_bpoint(bp, DESELECT, SELECT, HIDDEN);
- if (bp == vert) {
- cu->actvert = CU_ACT_NONE;
+ select_bpoint(bp, SELECT, SELECT, HIDDEN);
+ BKE_curve_nurb_vert_active_set(cu, nu, bp);
}
+ break;
}
- }
- else if (toggle) {
- if (bezt) {
- if (hand == 1) {
- if (bezt->f2 & SELECT) {
+ case SEL_OP_SUB: {
+ if (bezt) {
+ if (hand == 1) {
select_beztriple(bezt, DESELECT, SELECT, HIDDEN);
if (bezt == vert) {
cu->actvert = CU_ACT_NONE;
}
}
+ else if (hand == 0) {
+ bezt->f1 &= ~SELECT;
+ }
else {
- select_beztriple(bezt, SELECT, SELECT, HIDDEN);
- BKE_curve_nurb_vert_active_set(cu, nu, bezt);
+ bezt->f3 &= ~SELECT;
}
}
- else if (hand == 0) {
- bezt->f1 ^= SELECT;
- }
else {
- bezt->f3 ^= SELECT;
- }
- }
- else {
- if (bp->f1 & SELECT) {
select_bpoint(bp, DESELECT, SELECT, HIDDEN);
if (bp == vert) {
cu->actvert = CU_ACT_NONE;
}
}
+ break;
+ }
+ case SEL_OP_XOR: {
+ if (bezt) {
+ if (hand == 1) {
+ if (bezt->f2 & SELECT) {
+ select_beztriple(bezt, DESELECT, SELECT, HIDDEN);
+ if (bezt == vert) {
+ cu->actvert = CU_ACT_NONE;
+ }
+ }
+ else {
+ select_beztriple(bezt, SELECT, SELECT, HIDDEN);
+ BKE_curve_nurb_vert_active_set(cu, nu, bezt);
+ }
+ }
+ else if (hand == 0) {
+ bezt->f1 ^= SELECT;
+ }
+ else {
+ bezt->f3 ^= SELECT;
+ }
+ }
else {
- select_bpoint(bp, SELECT, SELECT, HIDDEN);
- BKE_curve_nurb_vert_active_set(cu, nu, bp);
+ if (bp->f1 & SELECT) {
+ select_bpoint(bp, DESELECT, SELECT, HIDDEN);
+ if (bp == vert) {
+ cu->actvert = CU_ACT_NONE;
+ }
+ }
+ else {
+ select_bpoint(bp, SELECT, SELECT, HIDDEN);
+ BKE_curve_nurb_vert_active_set(cu, nu, bp);
+ }
}
+ break;
}
- }
- else {
- BKE_nurbList_flag_set(editnurb, SELECT, false);
+ case SEL_OP_SET: {
+ BKE_nurbList_flag_set(editnurb, SELECT, false);
- if (bezt) {
+ if (bezt) {
- if (hand == 1) {
- select_beztriple(bezt, SELECT, SELECT, HIDDEN);
- }
- else {
- if (hand == 0) {
- bezt->f1 |= SELECT;
+ if (hand == 1) {
+ select_beztriple(bezt, SELECT, SELECT, HIDDEN);
}
else {
- bezt->f3 |= SELECT;
+ if (hand == 0) {
+ bezt->f1 |= SELECT;
+ }
+ else {
+ bezt->f3 |= SELECT;
+ }
}
+ BKE_curve_nurb_vert_active_set(cu, nu, bezt);
+ }
+ else {
+ select_bpoint(bp, SELECT, SELECT, HIDDEN);
+ BKE_curve_nurb_vert_active_set(cu, nu, bp);
}
- BKE_curve_nurb_vert_active_set(cu, nu, bezt);
+ break;
}
- else {
- select_bpoint(bp, SELECT, SELECT, HIDDEN);
- BKE_curve_nurb_vert_active_set(cu, nu, bp);
+ case SEL_OP_AND: {
+ BLI_assert_unreachable(); /* Doesn't make sense for picking. */
+ break;
}
}
@@ -4876,10 +4893,10 @@ bool ED_curve_editnurb_select_pick(
DEG_id_tag_update(obedit->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
- return true;
+ changed = true;
}
- return false;
+ return changed || found;
}
/** \} */
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index fdd145ff8cf..0afb1c2f4af 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -2184,7 +2184,10 @@ void FONT_OT_unlink(wmOperatorType *ot)
}
bool ED_curve_editfont_select_pick(
- bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
+ bContext *C,
+ const int mval[2],
+ /* NOTE: `params->deselect_all` is ignored as only one text-box is active at once. */
+ const struct SelectPick_Params *params)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obedit = CTX_data_edit_object(C);
@@ -2203,9 +2206,7 @@ bool ED_curve_editfont_select_pick(
ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
/* currently only select active */
- (void)extend;
- (void)deselect;
- (void)toggle;
+ (void)params;
for (i_iter = 0; i_iter < cu->totbox; i_iter++) {
int i = (i_iter + i_actbox) % cu->totbox;