Dopesheet: Keyframe size can be adjusted as part of theme settings
[blender.git] / source / blender / editors / space_action / action_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_action/action_ops.c
28  *  \ingroup spaction
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 #include "DNA_space_types.h"
37
38
39 #include "ED_anim_api.h"
40 #include "ED_markers.h"
41 #include "ED_transform.h"
42
43 #include "action_intern.h"
44
45 #include "RNA_access.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 /* ************************** registration - operator types **********************************/
51
52 void action_operatortypes(void)
53 {
54         /* view */
55         WM_operatortype_append(ACTION_OT_properties);
56         
57         /* keyframes */
58         /* selection */
59         WM_operatortype_append(ACTION_OT_clickselect);
60         WM_operatortype_append(ACTION_OT_select_all_toggle);
61         WM_operatortype_append(ACTION_OT_select_border);
62         WM_operatortype_append(ACTION_OT_select_lasso);
63         WM_operatortype_append(ACTION_OT_select_circle);
64         WM_operatortype_append(ACTION_OT_select_column);
65         WM_operatortype_append(ACTION_OT_select_linked);
66         WM_operatortype_append(ACTION_OT_select_more);
67         WM_operatortype_append(ACTION_OT_select_less);
68         WM_operatortype_append(ACTION_OT_select_leftright);
69         
70         /* editing */
71         WM_operatortype_append(ACTION_OT_snap);
72         WM_operatortype_append(ACTION_OT_mirror);
73         WM_operatortype_append(ACTION_OT_frame_jump);
74         WM_operatortype_append(ACTION_OT_handle_type);
75         WM_operatortype_append(ACTION_OT_interpolation_type);
76         WM_operatortype_append(ACTION_OT_extrapolation_type);
77         WM_operatortype_append(ACTION_OT_keyframe_type);
78         WM_operatortype_append(ACTION_OT_sample);
79         WM_operatortype_append(ACTION_OT_clean);
80         WM_operatortype_append(ACTION_OT_delete);
81         WM_operatortype_append(ACTION_OT_duplicate);
82         WM_operatortype_append(ACTION_OT_keyframe_insert);
83         WM_operatortype_append(ACTION_OT_copy);
84         WM_operatortype_append(ACTION_OT_paste);
85         
86         WM_operatortype_append(ACTION_OT_new);
87         WM_operatortype_append(ACTION_OT_unlink);
88         
89         WM_operatortype_append(ACTION_OT_push_down);
90         WM_operatortype_append(ACTION_OT_stash);
91         WM_operatortype_append(ACTION_OT_stash_and_create);
92         
93         WM_operatortype_append(ACTION_OT_layer_next);
94         WM_operatortype_append(ACTION_OT_layer_prev);
95         
96         WM_operatortype_append(ACTION_OT_previewrange_set);
97         WM_operatortype_append(ACTION_OT_view_all);
98         WM_operatortype_append(ACTION_OT_view_selected);
99         WM_operatortype_append(ACTION_OT_view_frame);
100
101         WM_operatortype_append(ACTION_OT_markers_make_local);
102 }
103
104 void ED_operatormacros_action(void)
105 {
106         wmOperatorType *ot;
107         wmOperatorTypeMacro *otmacro;
108         
109         ot = WM_operatortype_append_macro("ACTION_OT_duplicate_move", "Duplicate",
110                                           "Make a copy of all selected keyframes and move them",
111                                           OPTYPE_UNDO | OPTYPE_REGISTER);
112         WM_operatortype_macro_define(ot, "ACTION_OT_duplicate");
113         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform");
114         RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE);
115         RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF);
116 }
117
118 /* ************************** registration - keymaps **********************************/
119
120 static void action_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
121 {
122         wmKeyMapItem *kmi;
123         
124         /* action_select.c - selection tools */
125         /* click-select: keyframe (replace) */
126         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
127         RNA_boolean_set(kmi->ptr, "extend", false);
128         RNA_boolean_set(kmi->ptr, "column", false);
129         RNA_boolean_set(kmi->ptr, "channel", false);
130         /* click-select: all on same frame (replace) */
131         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
132         RNA_boolean_set(kmi->ptr, "extend", false);
133         RNA_boolean_set(kmi->ptr, "column", true);
134         RNA_boolean_set(kmi->ptr, "channel", false);
135         /* click-select: keyframe (add) */
136         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
137         RNA_boolean_set(kmi->ptr, "extend", true);
138         RNA_boolean_set(kmi->ptr, "column", false);
139         RNA_boolean_set(kmi->ptr, "channel", false);
140         /* click-select: all on same frame (add) */
141         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT | KM_SHIFT, 0);
142         RNA_boolean_set(kmi->ptr, "extend", true);
143         RNA_boolean_set(kmi->ptr, "column", true);
144         RNA_boolean_set(kmi->ptr, "channel", false);
145         /* click-select: all on same channel (replace) */
146         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
147         RNA_boolean_set(kmi->ptr, "extend", false);
148         RNA_boolean_set(kmi->ptr, "column", false);
149         RNA_boolean_set(kmi->ptr, "channel", true);
150         /* click-select: all on same channel (add) */
151         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT | KM_SHIFT, 0);
152         RNA_boolean_set(kmi->ptr, "extend", true);
153         RNA_boolean_set(kmi->ptr, "column", false);
154         RNA_boolean_set(kmi->ptr, "channel", true);
155                 
156         /* click-select: left/right */
157         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
158         RNA_boolean_set(kmi->ptr, "extend", false);
159         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
160         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
161         RNA_boolean_set(kmi->ptr, "extend", true);
162         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
163         
164         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
165         RNA_boolean_set(kmi->ptr, "extend", false);
166         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
167         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
168         RNA_boolean_set(kmi->ptr, "extend", false);
169         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
170         
171         /* deselect all */
172         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
173         RNA_boolean_set(kmi->ptr, "invert", false);
174         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0);
175         RNA_boolean_set(kmi->ptr, "invert", true);
176         
177         /* borderselect */
178         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
179         RNA_boolean_set(kmi->ptr, "axis_range", false);
180         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
181         RNA_boolean_set(kmi->ptr, "axis_range", true);
182         
183         /* region select */
184         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
185         RNA_boolean_set(kmi->ptr, "deselect", false);
186         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT, 0);
187         RNA_boolean_set(kmi->ptr, "deselect", true);
188         
189         WM_keymap_add_item(keymap, "ACTION_OT_select_circle", CKEY, KM_PRESS, 0, 0);
190         
191         /* column select */
192         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
193         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
194         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
195         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
196         
197         /* select more/less */
198         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
199         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
200         
201         /* select linked */
202         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
203         
204         
205         /* action_edit.c */
206         /* jump to selected keyframes */
207         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", GKEY, KM_PRESS, KM_CTRL, 0);
208                 
209         /* menu + single-step transform */
210         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
211         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
212         
213         /* menu + set setting */
214         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
215         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, 0, 0);
216         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
217         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
218         
219         /* destructive */
220         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
221         
222         WM_keymap_add_menu(keymap, "DOPESHEET_MT_delete", XKEY, KM_PRESS, 0, 0);
223         WM_keymap_add_menu(keymap, "DOPESHEET_MT_delete", DELKEY, KM_PRESS, 0, 0);
224         
225         WM_keymap_add_item(keymap, "ACTION_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
226         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
227         
228         /* copy/paste */
229         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
230         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
231         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
232         RNA_boolean_set(kmi->ptr, "flipped", true);
233 #ifdef __APPLE__
234         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
235         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
236         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY | KM_SHIFT, 0);
237         RNA_boolean_set(kmi->ptr, "flipped", true);
238 #endif
239
240         /* auto-set range */
241         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
242         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
243         WM_keymap_add_item(keymap, "ACTION_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
244         WM_keymap_add_item(keymap, "ACTION_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
245         WM_keymap_add_item(keymap, "ACTION_OT_view_frame", PAD0, KM_PRESS, 0, 0);
246
247         
248         /* animation module */
249         /* channels list
250          * NOTE: these operators were originally for the channels list, but are added here too for convenience...
251          */
252         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
253         
254         /* find (i.e. a shortcut for setting the name filter) */
255         WM_keymap_add_item(keymap, "ANIM_OT_channels_find", FKEY, KM_PRESS, KM_CTRL, 0);
256         
257         /* transform system */
258         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
259         
260         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", OKEY, KM_PRESS, 0, 0);
261         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_proportional_action");
262
263         /* special markers hotkeys for anim editors: see note in definition of this function */
264         ED_marker_keymap_animedit_conflictfree(keymap);
265 }
266
267 /* --------------- */
268
269 void action_keymap(wmKeyConfig *keyconf)
270 {
271         wmKeyMap *keymap;
272         
273         /* keymap for all regions */
274         keymap = WM_keymap_find(keyconf, "Dopesheet Generic", SPACE_ACTION, 0);
275         
276         /* region management... */
277         WM_keymap_add_item(keymap, "ACTION_OT_properties", NKEY, KM_PRESS, 0, 0);
278         
279         
280         /* channels */
281         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
282          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
283          * are all used for the Graph-Editor too.
284          */
285         
286         /* keyframes */
287         keymap = WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
288         action_keymap_keyframes(keyconf, keymap);
289 }
290