diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-04-06 16:07:33 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-04-06 16:07:33 +0400 |
commit | 51f6d6cbda947c30bdd457f78e742410186e470c (patch) | |
tree | 4d1d4a88d1523b119e5461bf0bc243c0ef81d5b8 /source/blender/editors | |
parent | e430816cde23a549e2779d815339bf685c54558f (diff) |
Graph Editor - Ctrl-LMB (Click Insert Keyframes) Operator
Now it is possible to add more keyframes to the 'active' F-Curve by simply Ctrl-LMB clicking in the graph space.
NOTE: more advanced polling callbacks are needed in the Graph Editor...
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 85 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 4 |
3 files changed, 89 insertions, 2 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index de020e8ce70..5d2098c366a 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -244,6 +244,89 @@ void GRAPHEDIT_OT_view_all (wmOperatorType *ot) // TODO: insertkey +/* ******************** Click-Insert Keyframes Operator ************************* */ + +static int graphkeys_click_insert_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + bAnimListElem *ale; + float frame, val; + + /* get animation context */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get active F-Curve 'anim-list-element' */ + ale= get_active_fcurve_channel(&ac); + if (ELEM(NULL, ale, ale->data)) { + if (ale) MEM_freeN(ale); + return OPERATOR_CANCELLED; + } + + /* get frame and value from props */ + frame= RNA_float_get(op->ptr, "frame"); + val= RNA_float_get(op->ptr, "value"); + + /* insert keyframe on the specified frame + value */ + insert_vert_fcurve((FCurve *)ale->data, frame, val, 0); + + /* free temp data */ + MEM_freeN(ale); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES); + + /* done */ + return OPERATOR_FINISHED; +} + +static int graphkeys_click_insert_invoke (bContext *C, wmOperator *op, wmEvent *evt) +{ + bAnimContext ac; + ARegion *ar; + View2D *v2d; + int mval[2]; + float x, y; + + /* get animation context */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* store mouse coordinates in View2D space, into the operator's properties */ + ar= ac.ar; + v2d= &ar->v2d; + + mval[0]= (evt->x - ar->winrct.xmin); + mval[1]= (evt->y - ar->winrct.ymin); + + UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); + + RNA_float_set(op->ptr, "frame", x); + RNA_float_set(op->ptr, "value", y); + + /* run exec now */ + return graphkeys_click_insert_exec(C, op); +} + +void GRAPHEDIT_OT_keyframes_click_insert (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Click-Insert Keyframes"; + ot->idname= "GRAPHEDIT_OT_keyframes_click_insert"; + + /* api callbacks */ + ot->invoke= graphkeys_click_insert_invoke; + ot->exec= graphkeys_click_insert_exec; + ot->poll= ED_operator_areaactive; // XXX active + editable poll + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_float(ot->srna, "frame", 1.0f, -FLT_MAX, FLT_MAX, "Frame Number", "Frame to insert keyframe on", 0, 100); + RNA_def_float(ot->srna, "value", 1.0f, -FLT_MAX, FLT_MAX, "Value", "Value for keyframe on", 0, 100); +} + /* ******************** Copy/Paste Keyframes Operator ************************* */ /* NOTE: the backend code for this is shared with the dopesheet editor */ @@ -302,7 +385,7 @@ static int graphkeys_copy_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* set notifier tha things have changed */ + /* set notifier that things have changed */ ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 06fda53fc67..a9d6cd125ca 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -82,6 +82,8 @@ enum { void GRAPHEDIT_OT_previewrange_set(struct wmOperatorType *ot); void GRAPHEDIT_OT_view_all(struct wmOperatorType *ot); +void GRAPHEDIT_OT_keyframes_click_insert(struct wmOperatorType *ot); + void GRAPHEDIT_OT_keyframes_copy(struct wmOperatorType *ot); void GRAPHEDIT_OT_keyframes_paste(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 4ff566489ae..016588167c3 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -125,6 +125,8 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPHEDIT_OT_keyframes_copy); WM_operatortype_append(GRAPHEDIT_OT_keyframes_paste); + WM_operatortype_append(GRAPHEDIT_OT_keyframes_click_insert); + //TODO: insertkey... /* F-Curve Modifiers */ @@ -189,7 +191,7 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap) WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); /* insertkey */ - // TODO.. + WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_click_insert", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); /* copy/paste */ WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0); |