static int node_borderselect_exec(bContext *C, wmOperator *op) { SpaceNode *snode = CTX_wm_space_node(C); ARegion *ar = CTX_wm_region(C); bNode *node; rcti rect; rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); int extend = RNA_boolean_get(op->ptr, "extend"); WM_operator_properties_border_to_rcti(op, &rect); UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); 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 previewrange_define_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); float sfra, efra; rcti rect; /* get min/max values from border select rect (already in region coordinates, not screen) */ WM_operator_properties_border_to_rcti(op, &rect); /* convert min/max values to frames (i.e. region to 'tot' rect) */ sfra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmin); efra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmax); /* set start/end frames for preview-range * - must clamp within allowable limits * - end must not be before start (though this won't occur most of the time) */ FRAMENUMBER_MIN_CLAMP(sfra); FRAMENUMBER_MIN_CLAMP(efra); if (efra < sfra) efra = sfra; scene->r.flag |= SCER_PRV_RANGE; scene->r.psfra = iroundf(sfra); scene->r.pefra = iroundf(efra); /* send notifiers */ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; }
static int file_border_select_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); rcti rect; FileSelect ret; const bool select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); const bool extend = RNA_boolean_get(op->ptr, "extend"); WM_operator_properties_border_to_rcti(op, &rect); if (!extend) { SpaceFile *sfile = CTX_wm_space_file(C); file_deselect_all(sfile, SELECTED_FILE); } BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect); ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, false, false); if (FILE_SELECT_DIR == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } else if (FILE_SELECT_FILE == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } return OPERATOR_FINISHED; }
static int graphkeys_borderselect_exec(bContext *C, wmOperator *op) { bAnimContext ac; rcti rect; rctf rect_fl; short mode = 0, selectmode = 0; bool incl_handles; bool extend; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* clear all selection if not extending selection */ extend = RNA_boolean_get(op->ptr, "extend"); if (!extend) deselect_graph_keys(&ac, 1, SELECT_SUBTRACT, true); /* get select mode * - 'gesture_mode' from the operator specifies how to select * - 'include_handles' from the operator specifies whether to include handles in the selection */ if (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT) selectmode = SELECT_ADD; else selectmode = SELECT_SUBTRACT; incl_handles = RNA_boolean_get(op->ptr, "include_handles"); /* get settings from operator */ WM_operator_properties_border_to_rcti(op, &rect); /* selection 'mode' depends on whether borderselect region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { /* mode depends on which axis of the range is larger to determine which axis to use * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often * used for tweaking timing when "blocking", while channels is not that useful... */ if ((BLI_rcti_size_x(&rect)) >= (BLI_rcti_size_y(&rect))) mode = BEZT_OK_FRAMERANGE; else mode = BEZT_OK_VALUERANGE; } else mode = BEZT_OK_REGION; BLI_rctf_rcti_copy(&rect_fl, &rect); /* apply borderselect action */ borderselect_graphkeys(&ac, &rect_fl, mode, selectmode, incl_handles, NULL); /* send notifier that keyframe selection has changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; }
static int actkeys_borderselect_exec(bContext *C, wmOperator *op) { bAnimContext ac; rcti rect; short mode = 0, selectmode = 0; const bool select = !RNA_boolean_get(op->ptr, "deselect"); const bool extend = RNA_boolean_get(op->ptr, "extend"); /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* clear all selection if not extending selection */ if (!extend) { deselect_action_keys(&ac, 1, SELECT_SUBTRACT); } /* get settings from operator */ WM_operator_properties_border_to_rcti(op, &rect); if (select) { selectmode = SELECT_ADD; } else { selectmode = SELECT_SUBTRACT; } /* selection 'mode' depends on whether borderselect region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { /* mode depends on which axis of the range is larger to determine which axis to use * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often * used for tweaking timing when "blocking", while channels is not that useful... */ if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect)) mode = ACTKEYS_BORDERSEL_FRAMERANGE; else mode = ACTKEYS_BORDERSEL_CHANNELS; } else mode = ACTKEYS_BORDERSEL_ALLKEYS; /* apply borderselect action */ borderselect_action(&ac, rect, mode, selectmode); /* set notifier that keyframe selection have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; }
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; float xminf, xmaxf, yminf, ymaxf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); int extend = RNA_boolean_get(op->ptr, "extend"); rcti rect; WM_operator_properties_border_to_rcti(op, &rect); UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin, &xminf, &yminf); UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax, &xmaxf, &ymaxf); if (markers == NULL) return 0; /* XXX marker context */ for (marker = markers->first; marker; marker = marker->next) { if ((marker->frame > xminf) && (marker->frame <= xmaxf)) { 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; }
static int file_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *ar = CTX_wm_region(C); SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); FileSelection sel; rcti rect; int result; result = WM_border_select_modal(C, op, event); if (result == OPERATOR_RUNNING_MODAL) { WM_operator_properties_border_to_rcti(op, &rect); BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect); sel = file_selection_get(C, &rect, 0); if ( (sel.first != params->sel_first) || (sel.last != params->sel_last) ) { file_deselect_all(sfile, HILITED_FILE); filelist_select(sfile->files, &sel, FILE_SEL_ADD, HILITED_FILE, CHECK_ALL); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } params->sel_first = sel.first; params->sel_last = sel.last; } else { params->active_file = -1; params->sel_first = params->sel_last = -1; file_deselect_all(sfile, HILITED_FILE); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } return result; }
static int outliner_border_select_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); ARegion *ar = CTX_wm_region(C); TreeElement *te; rcti rect; rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); WM_operator_properties_border_to_rcti(op, &rect); UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); for (te = soops->tree.first; te; te = te->next) { outliner_item_border_select(scene, soops, &rectf, te, gesture_mode); } WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); ED_region_tag_redraw(ar); return OPERATOR_FINISHED; }
void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect) { rcti rect_i; WM_operator_properties_border_to_rcti(op, &rect_i); BLI_rctf_rcti_copy(rect, &rect_i); }
/* borderselect operator */ static int borderselect_exec(bContext *C, wmOperator *op) { SpaceInfo *sinfo = CTX_wm_space_info(C); ARegion *ar = CTX_wm_region(C); ReportList *reports = CTX_wm_reports(C); int report_mask = info_report_mask(sinfo); int extend = RNA_boolean_get(op->ptr, "extend"); Report *report_min, *report_max, *report; //View2D *v2d = UI_view2d_fromcontext(C); rcti rect; //rctf rectf, rq; short selecting = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); //int mval[2]; WM_operator_properties_border_to_rcti(op, &rect); #if 0 mval[0] = rect.xmin; mval[1] = rect.ymin; UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin); mval[0] = rect.xmax; mval[1] = rect.ymax; UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax); #endif if (!extend) { for (report = reports->list.first; report; report = report->next) { if ((report->type & report_mask) == 0) continue; report->flag &= ~SELECT; } } report_min = info_text_pick(sinfo, ar, reports, rect.ymax); report_max = info_text_pick(sinfo, ar, reports, rect.ymin); /* get the first report if none found */ if (report_min == NULL) { // printf("find_min\n"); for (report = reports->list.first; report; report = report->next) { if (report->type & report_mask) { report_min = report; break; } } } if (report_max == NULL) { // printf("find_max\n"); for (report = reports->list.last; report; report = report->prev) { if (report->type & report_mask) { report_max = report; break; } } } if (report_min == NULL || report_max == NULL) return OPERATOR_CANCELLED; for (report = report_min; (report != report_max->next); report = report->next) { if ((report->type & report_mask) == 0) continue; if (selecting) report->flag |= SELECT; else report->flag &= ~SELECT; } ED_area_tag_redraw(CTX_wm_area(C)); return OPERATOR_FINISHED; }
static int border_select_exec(bContext *C, wmOperator *op) { ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int i; rcti rect; rctf rectf; bool changed = false; const bool select = !RNA_boolean_get(op->ptr, "deselect"); const bool extend = RNA_boolean_get(op->ptr, "extend"); /* get rectangle from operator */ WM_operator_properties_border_to_rcti(op, &rect); ED_mask_point_pos(sa, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); ED_mask_point_pos(sa, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); /* do actual selection */ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { MaskSpline *spline; if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { continue; } for (spline = masklay->splines.first; spline; spline = spline->next) { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; MaskSplinePoint *point_deform = &points_array[i]; /* TODO: handles? */ /* TODO: uw? */ if (BLI_rctf_isect_pt_v(&rectf, point_deform->bezt.vec[1])) { BKE_mask_point_select_set(point, select); BKE_mask_point_select_set_handle(point, MASK_WHICH_HANDLE_BOTH, select); } else if (!extend) { BKE_mask_point_select_set(point, false); BKE_mask_point_select_set_handle(point, MASK_WHICH_HANDLE_BOTH, false); } changed = true; } } } if (changed) { ED_mask_select_flush_all(mask); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; }
static int border_select_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 *track; MovieTrackingPlaneTrack *plane_track; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); rcti rect; rctf rectf; bool changed = false; int mode, extend; int framenr = ED_space_clip_get_clip_frame_number(sc); /* get rectangle from operator */ WM_operator_properties_border_to_rcti(op, &rect); ED_clip_point_stable_pos(sc, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); ED_clip_point_stable_pos(sc, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); mode = RNA_int_get(op->ptr, "gesture_mode"); extend = RNA_boolean_get(op->ptr, "extend"); /* do actual selection */ track = tracksbase->first; while (track) { if ((track->flag & TRACK_HIDDEN) == 0) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); if (MARKER_VISIBLE(sc, track, marker)) { if (BLI_rctf_isect_pt_v(&rectf, marker->pos)) { if (mode == GESTURE_MODAL_SELECT) BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT); else BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); } else if (!extend) { BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); } changed = true; } } track = track->next; } for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); int i; for (i = 0; i < 4; i++) { if (BLI_rctf_isect_pt_v(&rectf, plane_marker->corners[i])) { if (mode == GESTURE_MODAL_SELECT) { plane_track->flag |= SELECT; } else { plane_track->flag &= ~SELECT; } } else if (!extend) { plane_track->flag &= ~SELECT; } } changed = true; } } if (changed) { BKE_tracking_dopesheet_tag_update(tracking); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; }