Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "MEM_guardedalloc.h"
33
34 #include "DNA_listBase.h"
35 #include "DNA_anim_types.h"
36 #include "DNA_action_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_windowmanager_types.h"
41
42 #include "BLI_blenlib.h"
43
44 #include "BKE_context.h"
45 #include "BKE_utildefines.h"
46
47 #include "UI_interface.h"
48 #include "UI_view2d.h"
49
50 #include "ED_transform.h"
51
52 #include "action_intern.h"
53
54 #include "RNA_access.h"
55 #include "RNA_define.h"
56
57 #include "WM_api.h"
58 #include "WM_types.h"
59
60 /* ************************** registration - operator types **********************************/
61
62 void action_operatortypes(void)
63 {
64         /* keyframes */
65                 /* selection */
66         WM_operatortype_append(ACT_OT_clickselect);
67         WM_operatortype_append(ACT_OT_select_all_toggle);
68         WM_operatortype_append(ACT_OT_select_border);
69         WM_operatortype_append(ACT_OT_select_column);
70         
71                 /* editing */
72         WM_operatortype_append(ACT_OT_snap);
73         WM_operatortype_append(ACT_OT_mirror);
74         WM_operatortype_append(ACT_OT_frame_jump);
75         WM_operatortype_append(ACT_OT_handle_type);
76         WM_operatortype_append(ACT_OT_interpolation_type);
77         WM_operatortype_append(ACT_OT_extrapolation_type);
78         WM_operatortype_append(ACT_OT_sample);
79         WM_operatortype_append(ACT_OT_clean);
80         WM_operatortype_append(ACT_OT_delete);
81         WM_operatortype_append(ACT_OT_duplicate);
82         WM_operatortype_append(ACT_OT_insert_keyframe);
83         WM_operatortype_append(ACT_OT_copy);
84         WM_operatortype_append(ACT_OT_paste);
85         
86         WM_operatortype_append(ACT_OT_previewrange_set);
87         WM_operatortype_append(ACT_OT_view_all);
88 }
89
90 /* ************************** registration - keymaps **********************************/
91
92 static void action_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
93 {
94         wmKeymapItem *kmi;
95         
96         /* action_select.c - selection tools */
97                 /* click-select */
98         WM_keymap_add_item(keymap, "ACT_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
99         kmi= WM_keymap_add_item(keymap, "ACT_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
100                 RNA_boolean_set(kmi->ptr, "column", 1);
101         kmi= WM_keymap_add_item(keymap, "ACT_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
102                 RNA_boolean_set(kmi->ptr, "extend", 1);
103         kmi= WM_keymap_add_item(keymap, "ACT_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
104                 RNA_boolean_set(kmi->ptr, "extend", 1);
105                 RNA_boolean_set(kmi->ptr, "column", 1);
106         kmi= WM_keymap_add_item(keymap, "ACT_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
107                 RNA_enum_set(kmi->ptr, "left_right", ACTKEYS_LRSEL_TEST);
108         
109                 /* deselect all */
110         WM_keymap_add_item(keymap, "ACT_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
111         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
112         
113                 /* borderselect */
114         WM_keymap_add_item(keymap, "ACT_OT_select_border", BKEY, KM_PRESS, 0, 0);
115         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
116         
117                 /* column select */
118         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
119         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
120         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
121         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
122         
123         /* action_edit.c */
124                 /* snap - current frame to selected keys */
125                 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
126         WM_keymap_add_item(keymap, "ACT_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
127                 
128                 /* menu + single-step transform */
129         WM_keymap_add_item(keymap, "ACT_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
130         WM_keymap_add_item(keymap, "ACT_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
131         
132                 /* menu + set setting */
133         WM_keymap_add_item(keymap, "ACT_OT_handle_type", HKEY, KM_PRESS, 0, 0);
134         WM_keymap_add_item(keymap, "ACT_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
135         WM_keymap_add_item(keymap, "ACT_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
136         
137                 /* destructive */
138         WM_keymap_add_item(keymap, "ACT_OT_clean", OKEY, KM_PRESS, 0, 0);
139         WM_keymap_add_item(keymap, "ACT_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
140         
141         WM_keymap_add_item(keymap, "ACT_OT_delete", XKEY, KM_PRESS, 0, 0);
142         WM_keymap_add_item(keymap, "ACT_OT_delete", DELKEY, KM_PRESS, 0, 0);
143         
144         WM_keymap_add_item(keymap, "ACT_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
145         WM_keymap_add_item(keymap, "ACT_OT_insert_keyframe", IKEY, KM_PRESS, 0, 0);
146         
147                 /* copy/paste */
148         WM_keymap_add_item(keymap, "ACT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
149         WM_keymap_add_item(keymap, "ACT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
150         
151                 /* auto-set range */
152         WM_keymap_add_item(keymap, "ACT_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
153         WM_keymap_add_item(keymap, "ACT_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
154         
155         /* transform system */
156         transform_keymap_for_space(wm, keymap, SPACE_ACTION);
157         
158                 /* test */
159         /* WM_keymap_add_item(keymap, "ACT_OT_test", QKEY, KM_PRESS, 0, 0); */
160 }
161
162 /* --------------- */
163
164 void action_keymap(wmWindowManager *wm)
165 {
166         ListBase *keymap;
167         
168         /* channels */
169         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
170          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
171          * are all used for the IPO-Editor too.
172          */
173         
174         /* keyframes */
175         keymap= WM_keymap_listbase(wm, "Action_Keys", SPACE_ACTION, 0);
176         action_keymap_keyframes(wm, keymap);
177 }
178