Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_clip/clip_editor.c
| Show First 20 Lines • Show All 321 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| BKE_movieclip_user_set_frame(&sc->user, cfra); | BKE_movieclip_user_set_frame(&sc->user, cfra); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static bool selected_tracking_boundbox(SpaceClip *sc, float min[2], float max[2]) | bool ED_clip_view_selection(const bContext *C, ARegion *UNUSED(region), bool fit) | ||||
| { | { | ||||
| MovieClip *clip = ED_space_clip_get_clip(sc); | float offset_x, offset_y; | ||||
| MovieTrackingTrack *track; | float zoom; | ||||
| int width, height; | if (!clip_view_calculate_view_selection(C, fit, &offset_x, &offset_y, &zoom)) { | ||||
| bool ok = false; | |||||
| ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); | |||||
| int framenr = ED_space_clip_get_clip_frame_number(sc); | |||||
| INIT_MINMAX2(min, max); | |||||
| ED_space_clip_get_size(sc, &width, &height); | |||||
| track = tracksbase->first; | |||||
| while (track) { | |||||
| if (TRACK_VIEW_SELECTED(sc, track)) { | |||||
| MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); | |||||
| if (marker) { | |||||
| float pos[3]; | |||||
| pos[0] = marker->pos[0] + track->offset[0]; | |||||
| pos[1] = marker->pos[1] + track->offset[1]; | |||||
| pos[2] = 0.0f; | |||||
| /* undistortion happens for normalized coords */ | |||||
| if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { | |||||
| /* undistortion happens for normalized coords */ | |||||
| ED_clip_point_undistorted_pos(sc, pos, pos); | |||||
| } | |||||
| pos[0] *= width; | |||||
| pos[1] *= height; | |||||
| mul_v3_m4v3(pos, sc->stabmat, pos); | |||||
| minmax_v2v2_v2(min, max, pos); | |||||
| ok = true; | |||||
| } | |||||
| } | |||||
| track = track->next; | |||||
| } | |||||
| return ok; | |||||
| } | |||||
| static bool selected_boundbox(const bContext *C, float min[2], float max[2]) | |||||
| { | |||||
| SpaceClip *sc = CTX_wm_space_clip(C); | |||||
| if (sc->mode == SC_MODE_TRACKING) { | |||||
| return selected_tracking_boundbox(sc, min, max); | |||||
| } | |||||
| if (ED_mask_selected_minmax(C, min, max)) { | |||||
| MovieClip *clip = ED_space_clip_get_clip(sc); | |||||
| int width, height; | |||||
| ED_space_clip_get_size(sc, &width, &height); | |||||
| BKE_mask_coord_to_movieclip(clip, &sc->user, min, min); | |||||
| BKE_mask_coord_to_movieclip(clip, &sc->user, max, max); | |||||
| min[0] *= width; | |||||
| min[1] *= height; | |||||
| max[0] *= width; | |||||
| max[1] *= height; | |||||
| return true; | |||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool ED_clip_view_selection(const bContext *C, ARegion *region, bool fit) | |||||
| { | |||||
| SpaceClip *sc = CTX_wm_space_clip(C); | SpaceClip *sc = CTX_wm_space_clip(C); | ||||
| int w, h, frame_width, frame_height; | sc->xof = offset_x; | ||||
| float min[2], max[2]; | sc->yof = offset_y; | ||||
| sc->zoom = zoom; | |||||
| ED_space_clip_get_size(sc, &frame_width, &frame_height); | |||||
| if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL)) { | |||||
| return false; | |||||
| } | |||||
| if (!selected_boundbox(C, min, max)) { | |||||
| return false; | |||||
| } | |||||
| /* center view */ | |||||
| clip_view_center_to_point( | |||||
| sc, (max[0] + min[0]) / (2 * frame_width), (max[1] + min[1]) / (2 * frame_height)); | |||||
| w = max[0] - min[0]; | |||||
| h = max[1] - min[1]; | |||||
| /* set zoom to see all selection */ | |||||
| if (w > 0 && h > 0) { | |||||
| int width, height; | |||||
| float zoomx, zoomy, newzoom, aspx, aspy; | |||||
| ED_space_clip_get_aspect(sc, &aspx, &aspy); | |||||
| width = BLI_rcti_size_x(®ion->winrct) + 1; | |||||
| height = BLI_rcti_size_y(®ion->winrct) + 1; | |||||
| zoomx = (float)width / w / aspx; | |||||
| zoomy = (float)height / h / aspy; | |||||
| newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)); | |||||
| if (fit || sc->zoom > newzoom) { | |||||
| sc->zoom = newzoom; | |||||
| } | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| void ED_clip_select_all(SpaceClip *sc, int action, bool *r_has_selection) | void ED_clip_select_all(SpaceClip *sc, int action, bool *r_has_selection) | ||||
| { | { | ||||
| MovieClip *clip = ED_space_clip_get_clip(sc); | MovieClip *clip = ED_space_clip_get_clip(sc); | ||||
| const int framenr = ED_space_clip_get_clip_frame_number(sc); | const int framenr = ED_space_clip_get_clip_frame_number(sc); | ||||
| ▲ Show 20 Lines • Show All 722 Lines • ▼ Show 20 Lines | void clip_start_prefetch_job(const bContext *C) | ||||
| WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0); | WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0); | ||||
| WM_jobs_callbacks(wm_job, prefetch_startjob, NULL, NULL, NULL); | WM_jobs_callbacks(wm_job, prefetch_startjob, NULL, NULL, NULL); | ||||
| G.is_break = false; | G.is_break = false; | ||||
| /* and finally start the job */ | /* and finally start the job */ | ||||
| WM_jobs_start(CTX_wm_manager(C), wm_job); | WM_jobs_start(CTX_wm_manager(C), wm_job); | ||||
| } | } | ||||
| void ED_clip_view_lock_state_store(const bContext *C, ClipViewLockState *state) | |||||
| { | |||||
| SpaceClip *space_clip = CTX_wm_space_clip(C); | |||||
| BLI_assert(space_clip != NULL); | |||||
| state->offset_x = space_clip->xof; | |||||
| state->offset_y = space_clip->yof; | |||||
| state->zoom = space_clip->zoom; | |||||
| state->lock_offset_x = 0.0f; | |||||
| state->lock_offset_y = 0.0f; | |||||
| if ((space_clip->flag & SC_LOCK_SELECTION) == 0) { | |||||
| return; | |||||
| } | |||||
| if (!clip_view_calculate_view_selection( | |||||
| C, false, &state->offset_x, &state->offset_y, &state->zoom)) { | |||||
| return; | |||||
| } | |||||
| state->lock_offset_x = space_clip->xlockof; | |||||
| state->lock_offset_y = space_clip->ylockof; | |||||
| } | |||||
| void ED_clip_view_lock_state_restore_no_jump(const bContext *C, const ClipViewLockState *state) | |||||
| { | |||||
| SpaceClip *space_clip = CTX_wm_space_clip(C); | |||||
| BLI_assert(space_clip != NULL); | |||||
| if ((space_clip->flag & SC_LOCK_SELECTION) == 0) { | |||||
| return; | |||||
| } | |||||
| float offset_x, offset_y; | |||||
| float zoom; | |||||
| if (!clip_view_calculate_view_selection(C, false, &offset_x, &offset_y, &zoom)) { | |||||
| return; | |||||
| } | |||||
| space_clip->xlockof = state->offset_x + state->lock_offset_x - offset_x; | |||||
| space_clip->ylockof = state->offset_y + state->lock_offset_y - offset_y; | |||||
| } | |||||