2.5 - Action Editor
[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_action_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_context.h"
44 #include "BKE_utildefines.h"
45
46 #include "UI_interface.h"
47 #include "UI_view2d.h"
48
49 #include "BIF_transform.h"
50
51 #include "action_intern.h"
52
53 #include "RNA_access.h"
54 #include "RNA_define.h"
55
56 #include "WM_api.h"
57 #include "WM_types.h"
58
59
60 /* ************************** registration - operator types **********************************/
61
62 void action_operatortypes(void)
63 {
64         /* keyframes */
65                 /* selection */
66         WM_operatortype_append(ACT_OT_keyframes_clickselect);
67         WM_operatortype_append(ACT_OT_keyframes_deselectall);
68         WM_operatortype_append(ACT_OT_keyframes_borderselect);
69         WM_operatortype_append(ACT_OT_keyframes_columnselect);
70         
71                 /* editing */
72         WM_operatortype_append(ACT_OT_keyframes_snap);
73         WM_operatortype_append(ACT_OT_keyframes_mirror);
74         WM_operatortype_append(ACT_OT_keyframes_cfrasnap);
75         WM_operatortype_append(ACT_OT_keyframes_handletype);
76         WM_operatortype_append(ACT_OT_keyframes_ipotype);
77         WM_operatortype_append(ACT_OT_keyframes_expotype);
78         WM_operatortype_append(ACT_OT_keyframes_sample);
79         WM_operatortype_append(ACT_OT_keyframes_clean);
80         WM_operatortype_append(ACT_OT_keyframes_delete);
81         WM_operatortype_append(ACT_OT_keyframes_copy);
82         WM_operatortype_append(ACT_OT_keyframes_paste);
83         
84         WM_operatortype_append(ACT_OT_set_previewrange);
85         WM_operatortype_append(ACT_OT_view_all);
86 }
87
88 /* ************************** registration - keymaps **********************************/
89
90 static void action_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
91 {
92         /* action_select.c - selection tools */
93                 /* click-select */
94         WM_keymap_add_item(keymap, "ACT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
95         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "column_select", 1);
96         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend_select", 1);
97         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "left_right", ACTKEYS_LRSEL_TEST);
98         
99                 /* deselect all */
100         WM_keymap_add_item(keymap, "ACT_OT_keyframes_deselectall", AKEY, KM_PRESS, 0, 0);
101         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_deselectall", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
102         
103                 /* borderselect */
104         WM_keymap_add_item(keymap, "ACT_OT_keyframes_borderselect", BKEY, KM_PRESS, 0, 0);
105         RNA_boolean_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_borderselect", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
106         
107                 /* column select */
108         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_columnselect", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
109         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
110         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
111         RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
112         
113         /* action_edit.c */
114                 /* snap - current frame to selected keys */
115         WM_keymap_add_item(keymap, "ACT_OT_keyframes_cfrasnap", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
116                 
117                 /* menu + single-step transform */
118         WM_keymap_add_item(keymap, "ACT_OT_keyframes_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
119         WM_keymap_add_item(keymap, "ACT_OT_keyframes_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
120         
121                 /* menu + set setting */
122         WM_keymap_add_item(keymap, "ACT_OT_keyframes_handletype", HKEY, KM_PRESS, 0, 0);
123         WM_keymap_add_item(keymap, "ACT_OT_keyframes_ipotype", TKEY, KM_PRESS, KM_SHIFT, 0);
124         WM_keymap_add_item(keymap, "ACT_OT_keyframes_expotype", EKEY, KM_PRESS, KM_SHIFT, 0); // temp...
125         
126                 /* destructive */
127         WM_keymap_add_item(keymap, "ACT_OT_keyframes_clean", OKEY, KM_PRESS, 0, 0);
128         WM_keymap_add_item(keymap, "ACT_OT_keyframes_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
129         
130         WM_keymap_add_item(keymap, "ACT_OT_keyframes_delete", XKEY, KM_PRESS, 0, 0);
131         WM_keymap_add_item(keymap, "ACT_OT_keyframes_delete", DELKEY, KM_PRESS, 0, 0);
132         
133                 /* copy/paste */
134                 // XXX - should we keep these?
135         WM_keymap_add_item(keymap, "ACT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);
136         WM_keymap_add_item(keymap, "ACT_OT_keyframes_paste", VKEY, KM_PRESS, KM_CTRL, 0);
137         
138                 /* auto-set range */
139         WM_keymap_add_item(keymap, "ACT_OT_set_previewrange", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
140         WM_keymap_add_item(keymap, "ACT_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
141                 
142         /* transform system */
143         transform_keymap_for_space(wm, keymap, SPACE_ACTION);
144 }
145
146 /* --------------- */
147
148 void action_keymap(wmWindowManager *wm)
149 {
150         ListBase *keymap;
151         
152         /* channels */
153         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
154          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
155          * are all used for the IPO-Editor too.
156          */
157         
158         /* keyframes */
159         keymap= WM_keymap_listbase(wm, "Action_Keys", SPACE_ACTION, 0);
160         action_keymap_keyframes(wm, keymap);
161 }
162