static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *ar = CTX_wm_region(C); SpaceFile *sfile = CTX_wm_space_file(C); FileSelect ret; rcti rect; const bool extend = RNA_boolean_get(op->ptr, "extend"); const bool fill = RNA_boolean_get(op->ptr, "fill"); const bool do_diropen = RNA_boolean_get(op->ptr, "open"); if (ar->regiontype != RGN_TYPE_WINDOW) return OPERATOR_CANCELLED; rect.xmin = rect.xmax = event->mval[0]; rect.ymin = rect.ymax = event->mval[1]; if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin)) return OPERATOR_CANCELLED; /* single select, deselect all selected first */ if (!extend) file_deselect_all(sfile, SELECTED_FILE); ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen); 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); WM_event_add_mousemove(C); /* for directory changes */ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); return OPERATOR_FINISHED; }
int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my) { View2D *v2d = &ar->v2d; FileSelectParams *params; int numfiles, origfile; if (sfile == NULL || sfile->files == NULL) return 0; numfiles = filelist_numfiles(sfile->files); params = ED_fileselect_get_params(sfile); origfile = params->active_file; mx -= ar->winrct.xmin; my -= ar->winrct.ymin; if (BLI_rcti_isect_pt(&ar->v2d.mask, mx, my)) { float fx, fy; int active_file; UI_view2d_region_to_view(v2d, mx, my, &fx, &fy); active_file = ED_fileselect_layout_offset(sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy)); if ((active_file >= 0) && (active_file < numfiles)) params->active_file = active_file; else params->active_file = -1; } else params->active_file = -1; return (params->active_file != origfile); }
static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves, short select) { SpaceNode *snode = CTX_wm_space_node(C); bNode *node; ARegion *ar = CTX_wm_region(C); rcti rect; bool changed = false; /* get rectangle from operator */ BLI_lasso_boundbox(&rect, mcords, moves); /* do actual selection */ for (node = snode->edittree->nodes.first; node; node = node->next) { int screen_co[2]; const float cent[2] = {BLI_rctf_cent_x(&node->totr), BLI_rctf_cent_y(&node->totr)}; /* marker in screen coords */ if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) && BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX)) { nodeSetSelected(node, select); changed = true; } } if (changed) { WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); } return changed; }
static int do_lasso_select_mask(bContext *C, const int mcords[][2], short moves, short select) { 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; int change = FALSE; /* get rectangle from operator */ BLI_lasso_boundbox(&rect, mcords, moves); /* 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? */ float screen_co[2]; /* marker in screen coords */ ED_mask_point_pos__reverse(sa, ar, point_deform->bezt.vec[1][0], point_deform->bezt.vec[1][1], &screen_co[0], &screen_co[1]); if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX)) { BKE_mask_point_select_set(point, select); BKE_mask_point_select_set_handle(point, select); } change = TRUE; } } } if (change) { ED_mask_select_flush_all(mask); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); } return change; }
static void datadropper_draw_cb(const struct bContext *C, ARegion *ar, void *arg) { DataDropper *ddr = arg; int width; const char *name = ddr->name; wmWindow *win = CTX_wm_window(C); int x = win->eventstate->x; int y = win->eventstate->y; if ((name[0] == '\0') || (BLI_rcti_isect_pt(&ar->winrct, x, y) == false)) { return; } width = UI_GetStringWidth(name); x = x - ar->winrct.xmin; y = y - ar->winrct.ymin; y += 20; glColor4ub(0, 0, 0, 50); uiSetRoundBox(UI_CNR_ALL | UI_RB_ALPHA); uiRoundBox(x, y, x + width + 8, y + 15, 4); glColor4ub(255, 255, 255, 255); UI_DrawString(x + 4, y + 4, name); }
ScrArea *BKE_screen_find_area_xy(bScreen *sc, const int spacetype, int x, int y) { ScrArea *sa, *sa_found = NULL; for (sa = sc->areabase.first; sa; sa = sa->next) { if (BLI_rcti_isect_pt(&sa->totrct, x, y)) { if ((spacetype == SPACE_TYPE_ANY) || (sa->spacetype == spacetype)) { sa_found = sa; } break; } } return sa_found; }
ARegion *BKE_area_find_region_xy(ScrArea *sa, const int regiontype, int x, int y) { ARegion *ar_found = NULL; if (sa) { ARegion *ar; for (ar = sa->regionbase.first; ar; ar = ar->next) { if ((regiontype == RGN_TYPE_ANY) || (ar->regiontype == regiontype)) { if (BLI_rcti_isect_pt(&ar->winrct, x, y)) { ar_found = ar; break; } } } } return ar_found; }
static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, const char *name) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; wmWindow *win = CTX_wm_window(C); int x = win->eventstate->x; int y = win->eventstate->y; const unsigned char fg[4] = {255, 255, 255, 255}; const unsigned char bg[4] = {0, 0, 0, 50}; if ((name[0] == '\0') || (BLI_rcti_isect_pt(&ar->winrct, x, y) == false)) { return; } x = x - ar->winrct.xmin; y = y - ar->winrct.ymin; y += U.widget_unit; UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg); }
/** * \brief get the ID from the screen. * */ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id) { /* we could use some clever */ wmWindow *win = CTX_wm_window(C); ScrArea *sa; ScrArea *area_prev = CTX_wm_area(C); ARegion *ar_prev = CTX_wm_region(C); ddr->name[0] = '\0'; for (sa = win->screen->areabase.first; sa; sa = sa->next) { if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { if (sa->spacetype == SPACE_VIEW3D) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { const int mval[2] = { mx - ar->winrct.xmin, my - ar->winrct.ymin}; Base *base; CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); /* grr, always draw else we leave stale text */ ED_region_tag_redraw(ar); base = ED_view3d_give_base_under_cursor(C, mval); if (base) { Object *ob = base->object; ID *id = NULL; if (ddr->idcode == ID_OB) { id = (ID *)ob; } else if (ob->data) { if (GS(((ID *)ob->data)->name) == ddr->idcode) { id = (ID *)ob->data; } else { BLI_snprintf(ddr->name, sizeof(ddr->name), "Incompatible, expected a %s", ddr->idcode_name); } } if (id) { BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", ddr->idcode_name, id->name + 2); *r_id = id; } break; } } } } } CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, ar_prev); }
static int do_lasso_select_marker(bContext *C, const int mcords[][2], const short moves, bool select) { 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; bool changed = false; int framenr = ED_space_clip_get_clip_frame_number(sc); /* get rectangle from operator */ BLI_lasso_boundbox(&rect, mcords, moves); /* 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)) { float screen_co[2]; /* marker in screen coords */ ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co); if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) { if (select) BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT); else 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++) { float screen_co[2]; /* marker in screen coords */ ED_clip_point_stable_pos__reverse(sc, ar, plane_marker->corners[i], screen_co); if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) { if (select) { plane_track->flag |= SELECT; } else { 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 changed; }