static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); float co[2]; const bool extend = RNA_boolean_get(op->ptr, "extend"); if (!extend) { MovieTrackingTrack *track = tracking_marker_check_slide(C, event, NULL, NULL, NULL); if (track) { MovieClip *clip = ED_space_clip_get_clip(sc); clip->tracking.act_track = track; WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); return OPERATOR_PASS_THROUGH; } } ED_clip_mouse_pos(sc, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); return select_exec(C, op); }
/* takes event->mval */ void ED_mask_mouse_pos(ScrArea *sa, ARegion *ar, const int mval[2], float co[2]) { if (sa) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; ED_clip_mouse_pos(sc, ar, mval, co); BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); break; } case SPACE_SEQ: { UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &co[0], &co[1]); break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; ED_image_mouse_pos(sima, ar, mval, co); BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); zero_v2(co); break; } } else { BLI_assert(0); zero_v2(co); } }
static MovieTrackingPlaneTrack *tracking_plane_marker_check_slide( bContext *C, const wmEvent *event, int *corner_r) { const float distance_clip_squared = 12.0f * 12.0f; 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; int width, height; float co[2]; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); int framenr = ED_space_clip_get_clip_frame_number(sc); ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) { return NULL; } ED_clip_mouse_pos(sc, ar, event->mval, co); float min_distance_squared = FLT_MAX; int min_corner = -1; MovieTrackingPlaneTrack *min_plane_track = NULL; for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL; plane_track = plane_track->next) { if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); for (int i = 0; i < 4; i++) { float distance_squared = mouse_to_plane_slide_zone_distance_squared( co, plane_marker->corners[i], width, height); if (distance_squared < min_distance_squared) { min_distance_squared = distance_squared; min_corner = i; min_plane_track = plane_track; } } } } if (min_distance_squared < distance_clip_squared / sc->zoom) { if (corner_r != NULL) { *corner_r = min_corner; } return min_plane_track; } return NULL; }
static int clip_set_2d_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *ar = CTX_wm_region(C); SpaceClip *sclip = CTX_wm_space_clip(C); float location[2]; ED_clip_mouse_pos(sclip, ar, event->mval, location); RNA_float_set_array(op->ptr, "location", location); return clip_set_2d_cursor_exec(C, op); }
static int view_zoom_out_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); float location[2]; ED_clip_mouse_pos(sc, ar, event->mval, location); RNA_float_set_array(op->ptr, "location", location); return view_zoom_out_exec(C, op); }
/* Returns color in the display space, matching ED_space_image_color_sample(). */ bool ED_space_clip_color_sample(Scene *scene, SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3]) { const char *display_device = scene->display_settings.display_device; struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device); ImBuf *ibuf; float fx, fy, co[2]; bool ret = false; ibuf = ED_space_clip_get_buffer(sc); if (!ibuf) { return false; } /* map the mouse coords to the backdrop image space */ ED_clip_mouse_pos(sc, ar, mval, co); fx = co[0]; fy = co[1]; if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { const float *fp; unsigned char *cp; int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); CLAMP(y, 0, ibuf->y - 1); if (ibuf->rect_float) { fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); copy_v3_v3(r_col, fp); ret = true; } else if (ibuf->rect) { cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); rgb_uchar_to_float(r_col, cp); IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace); ret = true; } } if (ret) { IMB_colormanagement_scene_linear_to_display_v3(r_col, display); } IMB_freeImBuf(ibuf); return ret; }
static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor) { ARegion *ar = CTX_wm_region(C); float location[2], *mpos = NULL; if (event) { SpaceClip *sc = CTX_wm_space_clip(C); ED_clip_mouse_pos(sc, ar, event->mval, location); mpos = location; } sclip_zoom_set_factor(C, factor, mpos); ED_region_tag_redraw(ar); }
static void *slide_plane_marker_customdata(bContext *C, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); MovieTrackingPlaneTrack *plane_track; int width, height; float co[2]; SlidePlaneMarkerData *customdata = NULL; int framenr = ED_space_clip_get_clip_frame_number(sc); int corner; ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) { return NULL; } ED_clip_mouse_pos(sc, ar, event->mval, co); plane_track = tracking_plane_marker_check_slide(C, event, &corner); if (plane_track) { MovieTrackingPlaneMarker *plane_marker; customdata = MEM_callocN(sizeof(SlidePlaneMarkerData), "slide plane marker data"); customdata->event_type = event->type; plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr); customdata->plane_track = plane_track; customdata->plane_marker = plane_marker; customdata->width = width; customdata->height = height; customdata->previous_mval[0] = event->mval[0]; customdata->previous_mval[1] = event->mval[1]; customdata->corner_index = corner; customdata->corner = plane_marker->corners[corner]; copy_v2_v2(customdata->previous_corner, customdata->corner); copy_v2_v2(customdata->old_corner, customdata->corner); } return customdata; }
static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); ViewZoomData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData"); WM_cursor_modal(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR); vpd->x = event->x; vpd->y = event->y; vpd->zoom = sc->zoom; vpd->event_type = event->type; ED_clip_mouse_pos(sc, ar, event->mval, vpd->location); WM_event_add_modal_handler(C, op); }
/* matching ED_space_image_color_sample() */ bool ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3]) { ImBuf *ibuf; float fx, fy, co[2]; bool ret = false; ibuf = ED_space_clip_get_buffer(sc); if (!ibuf) { return false; } /* map the mouse coords to the backdrop image space */ ED_clip_mouse_pos(sc, ar, mval, co); fx = co[0]; fy = co[1]; if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { float *fp; unsigned char *cp; int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); CLAMP(y, 0, ibuf->y - 1); if (ibuf->rect_float) { fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); linearrgb_to_srgb_v3_v3(r_col, fp); ret = true; } else if (ibuf->rect) { cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); rgb_uchar_to_float(r_col, cp); ret = true; } } return ret; }
static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); ViewZoomData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData"); WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR); if (U.viewzoom == USER_ZOOM_CONT) { /* needs a timer to continue redrawing */ vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); vpd->timer_lastdraw = PIL_check_seconds_timer(); } vpd->x = event->x; vpd->y = event->y; vpd->zoom = sc->zoom; vpd->event_type = event->type; ED_clip_mouse_pos(sc, ar, event->mval, vpd->location); WM_event_add_modal_handler(C, op); }