Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_snap.c
| Show All 35 Lines | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "SEQ_sequencer.h" | |||||
| #include "SEQ_time.h" | |||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_gizmo_library.h" | #include "ED_gizmo_library.h" | ||||
| #include "ED_markers.h" | #include "ED_markers.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_sequencer.h" | |||||
| #include "ED_transform_snap_object_context.h" | #include "ED_transform_snap_object_context.h" | ||||
| #include "ED_uvedit.h" | #include "ED_uvedit.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "SEQ_sequencer.h" | |||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_convert.h" | #include "transform_convert.h" | ||||
| #include "transform_snap.h" | #include "transform_snap.h" | ||||
| static bool doForceIncrementSnap(const TransInfo *t); | static bool doForceIncrementSnap(const TransInfo *t); | ||||
| /* this should be passed as an arg for use in snap functions */ | /* this should be passed as an arg for use in snap functions */ | ||||
| #undef BASACT | #undef BASACT | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | if (t->mode == TFM_RESIZE) { | ||||
| return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_SCALE) != 0; | return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_SCALE) != 0; | ||||
| } | } | ||||
| if (t->mode == TFM_VERT_SLIDE) { | if (t->mode == TFM_VERT_SLIDE) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (t->mode == TFM_EDGE_SLIDE) { | if (t->mode == TFM_EDGE_SLIDE) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (t->mode == TFM_SEQ_SLIDE) { | |||||
| return true; | |||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| static bool doForceIncrementSnap(const TransInfo *t) | static bool doForceIncrementSnap(const TransInfo *t) | ||||
| { | { | ||||
| return !transformModeUseSnap(t); | return !transformModeUseSnap(t); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | if (validSnap(t)) { | ||||
| ED_node_draw_snap(®ion->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder, pos); | ED_node_draw_snap(®ion->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder, pos); | ||||
| } | } | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| } | } | ||||
| else if (t->spacetype == SPACE_SEQ) { | |||||
| if (validSnap(t)) { | |||||
| const ARegion *region = CTX_wm_region(C); | |||||
| ED_sequencer_draw_snap(®ion->v2d, t->tsnap.snapPoint); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event) | eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event) | ||||
| { | { | ||||
| eRedrawFlag status = TREDRAW_NOTHING; | eRedrawFlag status = TREDRAW_NOTHING; | ||||
| #if 0 /* XXX need a proper selector for all snap mode */ | #if 0 /* XXX need a proper selector for all snap mode */ | ||||
| if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) { | if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) { | ||||
| ▲ Show 20 Lines • Show All 397 Lines • ▼ Show 20 Lines | if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) { | ||||
| t->modifiers |= MOD_SNAP; | t->modifiers |= MOD_SNAP; | ||||
| } | } | ||||
| t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) != 0); | t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) != 0); | ||||
| t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); | t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); | ||||
| t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) != 0); | t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) != 0); | ||||
| t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); | t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); | ||||
| } | } | ||||
| else if (t->spacetype == SPACE_SEQ) { // This is very bad:( | |||||
| const eSeqSnapFlag snap_flag = SEQ_tool_settings_snap_flag_get(t->scene); | |||||
| if (snap_flag & SEQ_USE_SNAPPING) { | |||||
| ts->snap_flag |= SCE_SNAP; | |||||
mano-wii: Changes in the state of scene properties are best located in `saveTransform` as this function… | |||||
| t->modifiers |= MOD_SNAP; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| t->tsnap.target = snap_target; | t->tsnap.target = snap_target; | ||||
| initSnappingMode(t); | initSnappingMode(t); | ||||
| } | } | ||||
| void freeSnapping(TransInfo *t) | void freeSnapping(TransInfo *t) | ||||
| ▲ Show 20 Lines • Show All 717 Lines • ▼ Show 20 Lines | switch (autosnap) { | ||||
| } | } | ||||
| case SACTSNAP_OFF: { | case SACTSNAP_OFF: { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| *r_val = (float)val; | *r_val = (float)val; | ||||
| } | } | ||||
| /*================================================================*/ | |||||
| void snapSequenceBounds(TransInfo *t, const int mval[2]) | |||||
| { | |||||
| /* Reuse increment, strictly speaking could be another snap mode, but leave as is. */ | |||||
| if (!(t->modifiers & MOD_SNAP_INVERT)) { | |||||
| return; | |||||
| } | |||||
| /* Convert to frame range. */ | |||||
| float xmouse, ymouse; | |||||
| UI_view2d_region_to_view(&t->region->v2d, mval[0], mval[1], &xmouse, &ymouse); | |||||
| const int frame_curr = round_fl_to_int(xmouse); | |||||
| /* Now find the closest sequence. */ | |||||
| const int frame_near = SEQ_time_find_next_prev_edit( | |||||
| t->scene, frame_curr, SEQ_SIDE_BOTH, true, false, true); | |||||
| const int frame_snap = transform_convert_sequencer_get_snap_bound(t); | |||||
| t->values[0] = frame_near - frame_snap; | |||||
| } | |||||
| static void snap_grid_apply( | static void snap_grid_apply( | ||||
| TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3]) | TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3]) | ||||
| { | { | ||||
| BLI_assert(max_index <= 2); | BLI_assert(max_index <= 2); | ||||
| snap_target_grid_ensure(t); | snap_target_grid_ensure(t); | ||||
| const float *center_global = t->tsnap.snapTargetGrid; | const float *center_global = t->tsnap.snapTargetGrid; | ||||
| const float *asp = t->aspect; | const float *asp = t->aspect; | ||||
| ▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines | |||||
Changes in the state of scene properties are best located in saveTransform as this function only runs on success and an undo step is appropriately added.