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...
This commit is contained in:
2009-04-06 12:07:33 +00:00
parent e430816cde
commit 51f6d6cbda
3 changed files with 89 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);