[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19560] branches/blender2.5/blender/source /blender/editors/space_graph: Graph Editor - Ctrl-LMB ( Click Insert Keyframes) Operator
Joshua Leung
aligorith at gmail.com
Mon Apr 6 14:07:33 CEST 2009
Revision: 19560
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19560
Author: aligorith
Date: 2009-04-06 14:07:33 +0200 (Mon, 06 Apr 2009)
Log Message:
-----------
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...
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h
branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-04-06 11:21:47 UTC (rev 19559)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-04-06 12:07:33 UTC (rev 19560)
@@ -244,6 +244,89 @@
// 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 @@
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;
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h 2009-04-06 11:21:47 UTC (rev 19559)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h 2009-04-06 12:07:33 UTC (rev 19560)
@@ -82,6 +82,8 @@
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);
Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c 2009-04-06 11:21:47 UTC (rev 19559)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c 2009-04-06 12:07:33 UTC (rev 19560)
@@ -125,6 +125,8 @@
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 @@
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);
More information about the Bf-blender-cvs
mailing list