Animation: Snap Cursor Value operator
Add operator to snap the 2D Cursor value to selected keyframes. This is doing almost the same as the "Cursor to Selected" operator, except that it doesn't affect the current frame, just the Y-coordinate (the value) of the 2D cursor. The "snap cursor" operators are added to the Key → Snap menu and to the Snap pie menu. This means that these menus are now extended in meaning, to not only mean "snap the selected keyframes to the cursor", but also for some options "snap the cursor to selected keyframes". This fixes T76596.
This commit is contained in:
parent
df4a93aca0
commit
5ebdbcafcb
Notes:
blender-bot
2023-02-13 22:34:17 +01:00
Referenced by issue #76596, Cursor to selected missing in snap pie menu on the graph editor.
|
@ -262,8 +262,7 @@ class GRAPH_MT_key(Menu):
|
|||
layout = self.layout
|
||||
|
||||
layout.menu("GRAPH_MT_key_transform", text="Transform")
|
||||
|
||||
layout.operator_menu_enum("graph.snap", "type", text="Snap")
|
||||
layout.menu("GRAPH_MT_key_snap", text="Snap")
|
||||
layout.operator_menu_enum("graph.mirror", "type", text="Mirror")
|
||||
|
||||
layout.separator()
|
||||
|
@ -319,6 +318,23 @@ class GRAPH_MT_key_transform(Menu):
|
|||
layout.operator("transform.resize", text="Scale")
|
||||
|
||||
|
||||
class GRAPH_MT_key_snap(Menu):
|
||||
bl_label = "Snap"
|
||||
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("graph.snap", text="Current Frame").type = 'CFRA'
|
||||
layout.operator("graph.snap", text="Cursor Value").type = 'VALUE'
|
||||
layout.operator("graph.snap", text="Nearest Frame").type = 'NEAREST_FRAME'
|
||||
layout.operator("graph.snap", text="Nearest Second").type = 'NEAREST_SECOND'
|
||||
layout.operator("graph.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
|
||||
layout.operator("graph.snap", text="Flatten Handles").type = 'HORIZONTAL'
|
||||
layout.separator()
|
||||
layout.operator("graph.frame_jump", text="Cursor to Selection")
|
||||
layout.operator("graph.snap_cursor_value", text="Cursor Value to Selection")
|
||||
|
||||
|
||||
class GRAPH_MT_delete(Menu):
|
||||
bl_label = "Delete"
|
||||
|
||||
|
@ -389,6 +405,8 @@ class GRAPH_MT_snap_pie(Menu):
|
|||
pie.operator("graph.snap", text="Nearest Second").type = 'NEAREST_SECOND'
|
||||
pie.operator("graph.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
|
||||
pie.operator("graph.snap", text="Flatten Handles").type = 'HORIZONTAL'
|
||||
pie.operator("graph.frame_jump", text="Cursor to Selection")
|
||||
pie.operator("graph.snap_cursor_value", text="Cursor Value to Selection")
|
||||
|
||||
|
||||
class GRAPH_MT_channel_context_menu(Menu):
|
||||
|
@ -441,6 +459,7 @@ classes = (
|
|||
GRAPH_MT_channel,
|
||||
GRAPH_MT_key,
|
||||
GRAPH_MT_key_transform,
|
||||
GRAPH_MT_key_snap,
|
||||
GRAPH_MT_delete,
|
||||
GRAPH_MT_context_menu,
|
||||
GRAPH_MT_channel_context_menu,
|
||||
|
|
|
@ -161,6 +161,7 @@ static void graph_panel_cursor(const bContext *C, Panel *panel)
|
|||
|
||||
sub = uiLayoutColumn(col, true);
|
||||
uiItemO(sub, IFACE_("Cursor to Selection"), ICON_NONE, "GRAPH_OT_frame_jump");
|
||||
uiItemO(sub, IFACE_("Cursor Value to Selection"), ICON_NONE, "GRAPH_OT_snap_cursor_value");
|
||||
}
|
||||
|
||||
/* ******************* active F-Curve ************** */
|
||||
|
|
|
@ -2838,6 +2838,46 @@ void GRAPH_OT_frame_jump(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/* snap 2D cursor value to the average value of selected keyframe */
|
||||
static int graphkeys_snap_cursor_value_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
bAnimContext ac;
|
||||
|
||||
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
|
||||
const float sum_value = keyframe_sum.f2;
|
||||
const int num_keyframes = keyframe_sum.i1;
|
||||
|
||||
if (num_keyframes == 0) {
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
SpaceGraph *sipo = (SpaceGraph *)ac.sl;
|
||||
sipo->cursorVal = sum_value / (float)num_keyframes;
|
||||
// WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void GRAPH_OT_snap_cursor_value(wmOperatorType *ot)
|
||||
{
|
||||
/* Identifiers. */
|
||||
ot->name = "Snap Cursor Value to Selected";
|
||||
ot->idname = "GRAPH_OT_snap_cursor_value";
|
||||
ot->description = "Place the cursor value on the average value of selected keyframes";
|
||||
|
||||
/* API callbacks. */
|
||||
ot->exec = graphkeys_snap_cursor_value_exec;
|
||||
ot->poll = graphkeys_framejump_poll;
|
||||
|
||||
/* Flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/* ******************** Snap Keyframes Operator *********************** */
|
||||
|
||||
/* defines for snap keyframes tool */
|
||||
|
|
|
@ -113,6 +113,7 @@ void GRAPH_OT_extrapolation_type(struct wmOperatorType *ot);
|
|||
void GRAPH_OT_easing_type(struct wmOperatorType *ot);
|
||||
|
||||
void GRAPH_OT_frame_jump(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_snap_cursor_value(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_snap(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_mirror(struct wmOperatorType *ot);
|
||||
|
||||
|
|
|
@ -452,6 +452,7 @@ void graphedit_operatortypes(void)
|
|||
WM_operatortype_append(GRAPH_OT_snap);
|
||||
WM_operatortype_append(GRAPH_OT_mirror);
|
||||
WM_operatortype_append(GRAPH_OT_frame_jump);
|
||||
WM_operatortype_append(GRAPH_OT_snap_cursor_value);
|
||||
WM_operatortype_append(GRAPH_OT_handle_type);
|
||||
WM_operatortype_append(GRAPH_OT_interpolation_type);
|
||||
WM_operatortype_append(GRAPH_OT_extrapolation_type);
|
||||
|
|
Loading…
Reference in New Issue