4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
33 #include "DNA_scene_types.h"
35 #include "BLI_blenlib.h"
37 #include "BKE_context.h"
38 #include "BKE_sound.h"
40 #include "UI_view2d.h"
42 #include "ED_screen.h"
43 #include "ED_transform.h"
45 #include "graph_intern.h"
47 #include "RNA_access.h"
48 #include "RNA_define.h"
53 /* ************************** view-based operators **********************************/
54 // XXX should these really be here?
56 /* Set Cursor --------------------------------------------------------------------- */
57 /* The 'cursor' in the Graph Editor consists of two parts:
58 * 1) Current Frame Indicator (as per ANIM_OT_change_frame)
59 * 2) Value Indicator (stored per Graph Editor instance)
62 /* Set the new frame number */
63 static void graphview_cursor_apply(bContext *C, wmOperator *op)
65 Scene *scene= CTX_data_scene(C);
66 SpaceIpo *sipo= CTX_wm_space_graph(C);
69 * NOTE: sync this part of the code with ANIM_OT_change_frame
71 CFRA= RNA_int_get(op->ptr, "frame");
75 /* set the cursor value */
76 sipo->cursorVal= RNA_float_get(op->ptr, "value");
78 /* send notifiers - notifiers for frame should force an update for both vars ok... */
79 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
84 /* Non-modal callback for running operator without user input */
85 static int graphview_cursor_exec(bContext *C, wmOperator *op)
87 graphview_cursor_apply(C, op);
88 return OPERATOR_FINISHED;
93 /* set the operator properties from the initial event */
94 static void graphview_cursor_setprops(bContext *C, wmOperator *op, wmEvent *event)
96 ARegion *ar= CTX_wm_region(C);
100 /* abort if not active region (should not really be possible) */
104 /* convert screen coordinates to region coordinates */
105 x= event->x - ar->winrct.xmin;
106 y= event->y - ar->winrct.ymin;
108 /* convert from region coordinates to View2D 'tot' space */
109 UI_view2d_region_to_view(&ar->v2d, x, y, &viewx, &viewy);
111 /* store the values in the operator properties */
112 /* frame is rounded to the nearest int, since frames are ints */
113 RNA_int_set(op->ptr, "frame", (int)floor(viewx+0.5f));
114 RNA_float_set(op->ptr, "value", viewy);
117 /* Modal Operator init */
118 static int graphview_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
120 /* Change to frame that mouse is over before adding modal handler,
121 * as user could click on a single frame (jump to frame) as well as
122 * click-dragging over a range (modal scrubbing).
124 graphview_cursor_setprops(C, op, event);
126 /* apply these changes first */
127 graphview_cursor_apply(C, op);
129 /* add temp handler */
130 WM_event_add_modal_handler(C, op);
131 return OPERATOR_RUNNING_MODAL;
134 /* Modal event handling of cursor changing */
135 static int graphview_cursor_modal(bContext *C, wmOperator *op, wmEvent *event)
137 /* execute the events */
138 switch (event->type) {
140 return OPERATOR_FINISHED;
143 /* set the new values */
144 graphview_cursor_setprops(C, op, event);
145 graphview_cursor_apply(C, op);
150 /* we check for either mouse-button to end, as checking for ACTIONMOUSE (which is used to init
151 * the modal op) doesn't work for some reason
153 if (event->val==KM_RELEASE)
154 return OPERATOR_FINISHED;
158 return OPERATOR_RUNNING_MODAL;
161 void GRAPH_OT_cursor_set(wmOperatorType *ot)
164 ot->name= "Set Cursor";
165 ot->idname= "GRAPH_OT_cursor_set";
166 ot->description= "Interactively set the current frame number and value cursor";
169 ot->exec= graphview_cursor_exec;
170 ot->invoke= graphview_cursor_invoke;
171 ot->modal= graphview_cursor_modal;
172 ot->poll= ED_operator_ipo_active;
175 ot->flag= OPTYPE_BLOCKING|OPTYPE_UNDO;
178 RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
179 RNA_def_float(ot->srna, "value", 0, FLT_MIN, FLT_MAX, "Value", "", -100.0f, 100.0f);
182 /* Toggle Handles ----------------------------------------------------------------- */
184 static int view_toggle_handles_exec (bContext *C, wmOperator *UNUSED(op))
186 SpaceIpo *sipo= CTX_wm_space_graph(C);
187 ARegion *ar= CTX_wm_region(C);
190 return OPERATOR_CANCELLED;
192 /* toggle flag to hide handles */
193 sipo->flag ^= SIPO_NOHANDLES;
195 /* request refresh of keys area */
196 ED_region_tag_redraw(ar);
198 return OPERATOR_FINISHED;
201 void GRAPH_OT_view_togglehandles (wmOperatorType *ot)
204 ot->name= "Show/Hide All Handles";
205 ot->idname= "GRAPH_OT_handles_view_toggle";
208 ot->exec= view_toggle_handles_exec;
209 ot->poll= ED_operator_ipo_active;
212 /* ************************** registration - operator types **********************************/
214 void graphedit_operatortypes(void)
217 WM_operatortype_append(GRAPH_OT_view_togglehandles);
218 WM_operatortype_append(GRAPH_OT_cursor_set);
220 WM_operatortype_append(GRAPH_OT_previewrange_set);
221 WM_operatortype_append(GRAPH_OT_view_all);
222 WM_operatortype_append(GRAPH_OT_properties);
224 WM_operatortype_append(GRAPH_OT_ghost_curves_create);
225 WM_operatortype_append(GRAPH_OT_ghost_curves_clear);
229 WM_operatortype_append(GRAPH_OT_clickselect);
230 WM_operatortype_append(GRAPH_OT_select_all_toggle);
231 WM_operatortype_append(GRAPH_OT_select_border);
232 WM_operatortype_append(GRAPH_OT_select_column);
233 WM_operatortype_append(GRAPH_OT_select_linked);
234 WM_operatortype_append(GRAPH_OT_select_more);
235 WM_operatortype_append(GRAPH_OT_select_less);
238 WM_operatortype_append(GRAPH_OT_snap);
239 WM_operatortype_append(GRAPH_OT_mirror);
240 WM_operatortype_append(GRAPH_OT_frame_jump);
241 WM_operatortype_append(GRAPH_OT_handle_type);
242 WM_operatortype_append(GRAPH_OT_interpolation_type);
243 WM_operatortype_append(GRAPH_OT_extrapolation_type);
244 WM_operatortype_append(GRAPH_OT_sample);
245 WM_operatortype_append(GRAPH_OT_bake);
246 WM_operatortype_append(GRAPH_OT_sound_bake);
247 WM_operatortype_append(GRAPH_OT_smooth);
248 WM_operatortype_append(GRAPH_OT_clean);
249 WM_operatortype_append(GRAPH_OT_delete);
250 WM_operatortype_append(GRAPH_OT_duplicate);
252 WM_operatortype_append(GRAPH_OT_copy);
253 WM_operatortype_append(GRAPH_OT_paste);
255 WM_operatortype_append(GRAPH_OT_keyframe_insert);
256 WM_operatortype_append(GRAPH_OT_click_insert);
258 /* F-Curve Modifiers */
259 WM_operatortype_append(GRAPH_OT_fmodifier_add);
260 WM_operatortype_append(GRAPH_OT_fmodifier_copy);
261 WM_operatortype_append(GRAPH_OT_fmodifier_paste);
264 /* ************************** registration - keymaps **********************************/
266 static void graphedit_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
271 WM_keymap_add_item(keymap, "GRAPH_OT_handles_view_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
272 /* NOTE: 'ACTIONMOUSE' not 'LEFTMOUSE', as user may have swapped mouse-buttons
273 * This keymap is supposed to override ANIM_OT_change_frame, which does the same except it doesn't do y-values
275 WM_keymap_add_item(keymap, "GRAPH_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
278 /* graph_select.c - selection tools */
280 WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
281 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
282 RNA_boolean_set(kmi->ptr, "column", 1);
283 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
284 RNA_boolean_set(kmi->ptr, "extend", 1);
285 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
286 RNA_boolean_set(kmi->ptr, "extend", 1);
287 RNA_boolean_set(kmi->ptr, "column", 1);
288 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
289 RNA_enum_set(kmi->ptr, "left_right", GRAPHKEYS_LRSEL_TEST);
290 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
291 RNA_boolean_set(kmi->ptr, "curves", 1);
292 kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0);
293 RNA_boolean_set(kmi->ptr, "curves", 1);
294 RNA_boolean_set(kmi->ptr, "extend", 1);
297 WM_keymap_add_item(keymap, "GRAPH_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
298 RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
301 kmi = WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, 0, 0);
302 kmi = WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
303 RNA_boolean_set(kmi->ptr, "axis_range", 1);
305 kmi = WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, KM_CTRL, 0);
306 RNA_boolean_set(kmi->ptr, "include_handles", 1);
307 kmi = WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
308 RNA_boolean_set(kmi->ptr, "axis_range", 1);
309 RNA_boolean_set(kmi->ptr, "include_handles", 1);
312 RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_KEYS);
313 RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_CFRA);
314 RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN);
315 RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN);
317 /* select more/less */
318 WM_keymap_add_item(keymap, "GRAPH_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
319 WM_keymap_add_item(keymap, "GRAPH_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
322 WM_keymap_add_item(keymap, "GRAPH_OT_select_linked", LKEY, KM_PRESS, 0, 0);
326 /* snap - current frame to selected keys */
327 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
328 WM_keymap_add_item(keymap, "GRAPH_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
330 /* menu + single-step transform */
331 WM_keymap_add_item(keymap, "GRAPH_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
332 WM_keymap_add_item(keymap, "GRAPH_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
334 WM_keymap_add_item(keymap, "GRAPH_OT_handle_type", HKEY, KM_PRESS, 0, 0);
335 WM_keymap_add_item(keymap, "GRAPH_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
336 WM_keymap_add_item(keymap, "GRAPH_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0);
340 WM_keymap_add_item(keymap, "GRAPH_OT_clean", OKEY, KM_PRESS, 0, 0);
341 WM_keymap_add_item(keymap, "GRAPH_OT_smooth", OKEY, KM_PRESS, KM_ALT, 0);
342 WM_keymap_add_item(keymap, "GRAPH_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
344 WM_keymap_add_item(keymap, "GRAPH_OT_bake", CKEY, KM_PRESS, KM_ALT, 0);
346 WM_keymap_add_item(keymap, "GRAPH_OT_delete", XKEY, KM_PRESS, 0, 0);
347 WM_keymap_add_item(keymap, "GRAPH_OT_delete", DELKEY, KM_PRESS, 0, 0);
349 WM_keymap_add_item(keymap, "GRAPH_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
352 WM_keymap_add_item(keymap, "GRAPH_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
353 WM_keymap_add_item(keymap, "GRAPH_OT_click_insert", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
356 WM_keymap_add_item(keymap, "GRAPH_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
357 WM_keymap_add_item(keymap, "GRAPH_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
360 WM_keymap_add_item(keymap, "GRAPH_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
361 WM_keymap_add_item(keymap, "GRAPH_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
364 RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "only_active", 0);
366 /* animation module */
368 * NOTE: these operators were originally for the channels list, but are added here too for convenience...
370 WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
372 /* transform system */
373 transform_keymap_for_space(keyconf, keymap, SPACE_IPO);
376 /* --------------- */
378 void graphedit_keymap(wmKeyConfig *keyconf)
382 /* keymap for all regions */
383 keymap= WM_keymap_find(keyconf, "Graph Editor Generic", SPACE_IPO, 0);
384 WM_keymap_add_item(keymap, "GRAPH_OT_properties", NKEY, KM_PRESS, 0, 0);
387 /* Channels are not directly handled by the Graph Editor module, but are inherited from the Animation module.
388 * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
389 * are all used for the Graph Editor too.
393 keymap= WM_keymap_find(keyconf, "Graph Editor", SPACE_IPO, 0);
394 graphedit_keymap_keyframes(keyconf, keymap);