e82c26488b5ac2df7e0cab25f934a52fcb553b4e
[blender.git] / source / blender / editors / space_action / action_ops.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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. 
10  *
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.
15  *
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.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <math.h>
31
32
33 #include "DNA_space_types.h"
34
35 #include "BLI_blenlib.h"
36
37
38
39 #include "ED_transform.h"
40
41 #include "action_intern.h"
42
43 #include "RNA_access.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 /* ************************** registration - operator types **********************************/
49
50 void action_operatortypes(void)
51 {
52         /* keyframes */
53                 /* selection */
54         WM_operatortype_append(ACTION_OT_clickselect);
55         WM_operatortype_append(ACTION_OT_select_all_toggle);
56         WM_operatortype_append(ACTION_OT_select_border);
57         WM_operatortype_append(ACTION_OT_select_column);
58         WM_operatortype_append(ACTION_OT_select_linked);
59         WM_operatortype_append(ACTION_OT_select_more);
60         WM_operatortype_append(ACTION_OT_select_less);
61         WM_operatortype_append(ACTION_OT_select_leftright);
62         
63                 /* editing */
64         WM_operatortype_append(ACTION_OT_snap);
65         WM_operatortype_append(ACTION_OT_mirror);
66         WM_operatortype_append(ACTION_OT_frame_jump);
67         WM_operatortype_append(ACTION_OT_handle_type);
68         WM_operatortype_append(ACTION_OT_interpolation_type);
69         WM_operatortype_append(ACTION_OT_extrapolation_type);
70         WM_operatortype_append(ACTION_OT_keyframe_type);
71         WM_operatortype_append(ACTION_OT_sample);
72         WM_operatortype_append(ACTION_OT_clean);
73         WM_operatortype_append(ACTION_OT_delete);
74         WM_operatortype_append(ACTION_OT_duplicate);
75         WM_operatortype_append(ACTION_OT_keyframe_insert);
76         WM_operatortype_append(ACTION_OT_copy);
77         WM_operatortype_append(ACTION_OT_paste);
78         WM_operatortype_append(ACTION_OT_new);
79         
80         WM_operatortype_append(ACTION_OT_previewrange_set);
81         WM_operatortype_append(ACTION_OT_view_all);
82         
83         WM_operatortype_append(ACTION_OT_markers_make_local);
84 }
85
86 /* ************************** registration - keymaps **********************************/
87
88 static void action_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
89 {
90         wmKeyMapItem *kmi;
91         
92         /* action_select.c - selection tools */
93                 /* click-select */
94         WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
95         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
96                 RNA_boolean_set(kmi->ptr, "column", 1);
97         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
98                 RNA_boolean_set(kmi->ptr, "extend", 1);
99         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
100                 RNA_boolean_set(kmi->ptr, "extend", 1);
101                 RNA_boolean_set(kmi->ptr, "column", 1);
102                 
103                 /* select left/right */
104         WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
105         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
106                 RNA_boolean_set(kmi->ptr, "extend", 1);
107         
108         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
109                 RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
110         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
111                 RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
112         
113                 /* deselect all */
114         WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
115         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
116         
117                 /* borderselect */
118         WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
119         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
120         
121                 /* column select */
122         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
123         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
124         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
125         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
126         
127                 /* select more/less */
128         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
129         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
130         
131                 /* select linekd */
132         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
133         
134         
135         /* action_edit.c */
136                 /* snap - current frame to selected keys */
137                 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
138         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
139                 
140                 /* menu + single-step transform */
141         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
142         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
143         
144                 /* menu + set setting */
145         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
146         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
147         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
148         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
149         
150                 /* destructive */
151         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
152         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
153         
154         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
155         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
156         
157         WM_keymap_add_item(keymap, "ACTION_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
158         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
159         
160                 /* copy/paste */
161         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
162         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
163         
164                 /* auto-set range */
165         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
166         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
167         
168         /* animation module */
169                 /* channels list 
170                  * NOTE: these operators were originally for the channels list, but are added here too for convenience...
171                  */
172         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
173         
174         /* transform system */
175         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
176 }
177
178 /* --------------- */
179
180 void action_keymap(wmKeyConfig *keyconf)
181 {
182         wmKeyMap *keymap;
183         
184         /* channels */
185         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
186          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
187          * are all used for the Graph-Editor too.
188          */
189         
190         /* keyframes */
191         keymap= WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
192         action_keymap_keyframes(keyconf, keymap);
193 }
194