static int node_borderselect_exec(bContext *C, wmOperator *op) { SpaceNode *snode = CTX_wm_space_node(C); ARegion *ar = CTX_wm_region(C); bNode *node; rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); const bool extend = RNA_boolean_get(op->ptr, "extend"); WM_operator_properties_border_to_rctf(op, &rectf); UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); for (node = snode->edittree->nodes.first; node; node = node->next) { if (BLI_rctf_isect(&rectf, &node->totr, NULL)) { nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT)); } else if (!extend) { nodeSetSelected(node, false); } } ED_node_sort(snode->edittree); WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; }
static int border_select_graph_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); BorderSelectuserData userdata; rctf rect; if (act_track == NULL) { return OPERATOR_CANCELLED; } /* get rectangle from operator */ WM_operator_properties_border_to_rctf(op, &rect); UI_view2d_region_to_view_rctf(&ar->v2d, &rect, &userdata.rect); userdata.changed = false; userdata.mode = RNA_int_get(op->ptr, "gesture_mode"); userdata.extend = RNA_boolean_get(op->ptr, "extend"); clip_graph_tracking_values_iterate_track(sc, act_track, &userdata, border_select_cb, NULL, NULL); if (userdata.changed) { WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; }
/* ---------- FILE SELECTION ------------ */ static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect_region) { FileSelection sel; View2D *v2d = &ar->v2d; rcti rect_view; rctf rect_view_fl; rctf rect_region_fl; BLI_rctf_rcti_copy(&rect_region_fl, rect_region); UI_view2d_region_to_view_rctf(v2d, &rect_region_fl, &rect_view_fl); BLI_rcti_init(&rect_view, (int)(v2d->tot.xmin + rect_view_fl.xmin), (int)(v2d->tot.xmin + rect_view_fl.xmax), (int)(v2d->tot.ymax - rect_view_fl.ymin), (int)(v2d->tot.ymax - rect_view_fl.ymax)); sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view); return sel; }
static int ed_marker_border_select_exec(bContext *C, wmOperator *op) { View2D *v2d = UI_view2d_fromcontext(C); ListBase *markers = ED_context_get_markers(C); TimeMarker *marker; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); bool extend = RNA_boolean_get(op->ptr, "extend"); rctf rect; WM_operator_properties_border_to_rctf(op, &rect); UI_view2d_region_to_view_rctf(v2d, &rect, &rect); if (markers == NULL) return 0; /* XXX marker context */ for (marker = markers->first; marker; marker = marker->next) { if (BLI_rctf_isect_x(&rect, marker->frame)) { switch (gesture_mode) { case GESTURE_MODAL_SELECT: marker->flag |= SELECT; break; case GESTURE_MODAL_DESELECT: marker->flag &= ~SELECT; break; } } else if (!extend) { marker->flag &= ~SELECT; } } WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); return 1; }
/* Borderselect only selects keyframes now, as overshooting handles often get caught too, * which means that they may be inadvertently moved as well. However, incl_handles overrides * this, and allow handles to be considered independently too. * Also, for convenience, handles should get same status as keyframe (if it was within bounds). */ static void borderselect_graphkeys( bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, bool incl_handles, struct KeyframeEdit_LassoData *data_lasso) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter, mapping_flag; SpaceIpo *sipo = (SpaceIpo *)ac->sl; KeyframeEditData ked; KeyframeEditFunc ok_cb, select_cb; View2D *v2d = &ac->ar->v2d; rctf rectf, scaled_rectf; /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* get beztriple editing/validation funcs */ select_cb = ANIM_editkeyframes_select(selectmode); ok_cb = ANIM_editkeyframes_ok(mode); /* init editing data */ memset(&ked, 0, sizeof(KeyframeEditData)); if (data_lasso) { data_lasso->rectf_scaled = &scaled_rectf; ked.data = data_lasso; } else { ked.data = &scaled_rectf; } /* treat handles separately? */ if (incl_handles) { ked.iterflags |= KEYFRAME_ITER_INCL_HANDLES; mapping_flag = 0; } else mapping_flag = ANIM_UNITCONV_ONLYKEYS; mapping_flag |= ANIM_get_normalization_flags(ac); /* loop over data, doing border select */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag); /* apply NLA mapping to all the keyframes, since it's easier than trying to * guess when a callback might use something different */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0); scaled_rectf.xmin = rectf.xmin; scaled_rectf.xmax = rectf.xmax; scaled_rectf.ymin = rectf.ymin / unit_scale; scaled_rectf.ymax = rectf.ymax / unit_scale; /* set horizontal range (if applicable) * NOTE: these values are only used for x-range and y-range but not region * (which uses ked.data, i.e. rectf) */ if (mode != BEZT_OK_VALUERANGE) { ked.f1 = rectf.xmin; ked.f2 = rectf.xmax; } else { ked.f1 = rectf.ymin; ked.f2 = rectf.ymax; } /* firstly, check if any keyframes will be hit by this */ if (ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, ok_cb, NULL)) { /* select keyframes that are in the appropriate places */ ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL); /* only change selection of channel when the visibility of keyframes doesn't depend on this */ if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { /* select the curve too now that curve will be touched */ if (selectmode == SELECT_ADD) fcu->flag |= FCURVE_SELECTED; } } /* un-apply NLA mapping from all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0); } /* cleanup */ BLI_freelistN(&anim_data); }
static void region_select_action_keys(bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, void *data) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditData ked; KeyframeEditFunc ok_cb, select_cb; View2D *v2d = &ac->ar->v2d; rctf rectf, scaled_rectf; float ymin = 0, ymax = (float)(-ACHANNEL_HEIGHT_HALF(ac)); /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* get beztriple editing/validation funcs */ select_cb = ANIM_editkeyframes_select(selectmode); ok_cb = ANIM_editkeyframes_ok(mode); /* init editing data */ memset(&ked, 0, sizeof(KeyframeEditData)); if (mode == BEZT_OK_CHANNEL_LASSO) { KeyframeEdit_LassoData *data_lasso = data; data_lasso->rectf_scaled = &scaled_rectf; ked.data = data_lasso; } else if (mode == BEZT_OK_CHANNEL_CIRCLE) { KeyframeEdit_CircleData *data_circle = data; data_circle->rectf_scaled = &scaled_rectf; ked.data = data; } else { ked.data = &scaled_rectf; } /* loop over data, doing region select */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* get new vertical minimum extent of channel */ ymin = ymax - ACHANNEL_STEP(ac); /* compute midpoint of channel (used for testing if the key is in the region or not) */ ked.channel_y = ymin + ACHANNEL_HEIGHT_HALF(ac); /* if channel is mapped in NLA, apply correction * - Apply to the bounds being checked, not all the keyframe points, * to avoid having scaling everything * - Save result to the scaled_rect, which is all that these operators * will read from */ if (adt) { ked.iterflags &= ~(KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP); ked.f1 = BKE_nla_tweakedit_remap(adt, rectf.xmin, NLATIME_CONVERT_UNMAP); ked.f2 = BKE_nla_tweakedit_remap(adt, rectf.xmax, NLATIME_CONVERT_UNMAP); } else { ked.iterflags |= (KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP); /* for summary tracks */ ked.f1 = rectf.xmin; ked.f2 = rectf.xmax; } /* Update values for scaled_rectf - which is used to compute the mapping in the callbacks * NOTE: Since summary tracks need late-binding remapping, the callbacks may overwrite these * with the properly remapped ked.f1/f2 values, when needed */ scaled_rectf.xmin = ked.f1; scaled_rectf.xmax = ked.f2; scaled_rectf.ymin = ymin; scaled_rectf.ymax = ymax; /* perform vertical suitability check (if applicable) */ if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) || !((ymax < rectf.ymin) || (ymin > rectf.ymax))) { /* loop over data selecting */ switch (ale->type) { #if 0 /* XXX: Keyframes are not currently shown here */ case ANIMTYPE_GPDATABLOCK: { bGPdata *gpd = ale->data; bGPDlayer *gpl; for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode); } break; } #endif case ANIMTYPE_GPLAYER: { ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode); break; } case ANIMTYPE_MASKDATABLOCK: { Mask *mask = ale->data; MaskLayer *masklay; for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { ED_masklayer_frames_select_region(&ked, masklay, mode, selectmode); } break; } case ANIMTYPE_MASKLAYER: { ED_masklayer_frames_select_region(&ked, ale->data, mode, selectmode); break; } default: ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL); break; } } /* set minimum extent to be the maximum of the next channel */ ymax = ymin; } /* cleanup */ ANIM_animdata_freelist(&anim_data); }