NLA SoC: Transform Code for NLA-Strips recoded (still buggy)
[blender.git] / source / blender / editors / space_nla / nla_header.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 <string.h>
30 #include <stdio.h>
31
32 #include "DNA_anim_types.h"
33 #include "DNA_action_types.h"
34 #include "DNA_nla_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44 #include "BLI_arithb.h"
45 #include "BLI_rand.h"
46
47 #include "BKE_animsys.h"
48 #include "BKE_nla.h"
49 #include "BKE_context.h"
50 #include "BKE_report.h"
51 #include "BKE_screen.h"
52 #include "ED_types.h"
53 #include "ED_util.h"
54
55 #include "ED_anim_api.h"
56 #include "ED_space_api.h"
57 #include "ED_screen.h"
58
59 #include "BIF_gl.h"
60 #include "BIF_transform.h"
61
62 #include "RNA_access.h"
63
64 #include "WM_api.h"
65 #include "WM_types.h"
66
67 #include "UI_interface.h"
68 #include "UI_resources.h"
69 #include "UI_view2d.h"
70
71 #include "ED_markers.h"
72
73 #include "nla_intern.h"
74
75 /* button events */
76 enum {
77         B_REDR  = 0,
78 } eActHeader_ButEvents;
79
80 /* ************************ header area region *********************** */
81
82
83 static void nla_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
84 {
85         bScreen *sc= CTX_wm_screen(C);
86         ScrArea *sa= CTX_wm_area(C);
87         Scene *scene= CTX_data_scene(C);
88         SpaceNla *snla= (SpaceNla*)CTX_wm_space_data(C);
89         PointerRNA spaceptr;
90         
91         /* retrieve state */
92         RNA_pointer_create(&sc->id, &RNA_SpaceNLA, snla, &spaceptr);
93         
94         /* create menu */
95         uiItemO(layout, NULL, ICON_MENU_PANEL, "NLA_OT_properties");
96         
97         uiItemS(layout);
98         
99         uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0);
100         
101         if (snla->flag & SNLA_DRAWTIME)
102                 uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
103         else
104                 uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle");
105
106         uiItemS(layout);
107         
108         if (scene->flag & SCE_NLA_EDIT_ON) 
109                 uiItemO(layout, NULL, 0, "NLA_OT_tweakmode_exit");
110         else
111                 uiItemO(layout, NULL, 0, "NLA_OT_tweakmode_enter");
112         
113         uiItemS(layout);
114         
115         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
116         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
117         
118         uiItemS(layout);
119         
120         //uiItemO(layout, NULL, 0, "NLA_OT_view_all");
121         
122         if (sa->full) 
123                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
124         else 
125                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow
126 }
127
128 static void nla_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
129 {
130         uiItemO(layout, NULL, 0, "NLA_OT_select_all_toggle");
131         uiItemBooleanO(layout, "Invert All", 0, "NLA_OT_select_all_toggle", "invert", 1);
132         
133         uiItemS(layout);
134         
135         uiItemO(layout, NULL, 0, "NLA_OT_select_border");
136         uiItemBooleanO(layout, "Border Axis Range", 0, "NLA_OT_select_border", "axis_range", 1);
137 }
138
139 static void nla_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unused)
140 {
141         // XXX these operators may change for NLA...
142         uiItemEnumO(layout, "Grab/Move", 0, "TFM_OT_transform", "mode", TFM_TRANSLATION);
143         uiItemEnumO(layout, "Extend", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
144         uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
145 }
146
147 static void nla_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
148 {
149         uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_CFRA);
150         uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_FRAME);
151         uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_SECOND);
152         uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_MARKER);
153 }
154
155 static void nla_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
156 {
157         uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu);
158         uiItemMenuF(layout, "Snap", 0, nla_edit_snapmenu);
159         
160         uiItemS(layout);
161         
162         uiItemO(layout, NULL, 0, "NLA_OT_duplicate");
163         uiItemO(layout, NULL, 0, "NLA_OT_split");
164         
165         uiItemS(layout);
166         
167         uiItemO(layout, NULL, 0, "NLA_OT_delete");
168         
169         uiItemS(layout);
170         
171         uiItemO(layout, NULL, 0, "NLA_OT_apply_scale");
172         uiItemO(layout, NULL, 0, "NLA_OT_clear_scale");
173         
174         uiItemS(layout);
175         
176         uiItemO(layout, NULL, 0, "NLA_OT_move_up");
177         uiItemO(layout, NULL, 0, "NLA_OT_move_down");
178 }
179
180 static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
181 {
182         uiItemO(layout, NULL, 0, "NLA_OT_add_actionclip");
183         uiItemO(layout, NULL, 0, "NLA_OT_add_transition");
184         
185         uiItemS(layout);
186         
187         uiItemO(layout, NULL, 0, "NLA_OT_add_meta");
188         uiItemO(layout, NULL, 0, "NLA_OT_remove_meta");
189         
190         uiItemS(layout);
191         
192         uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
193         uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
194 }
195
196 /* ------------------ */
197
198 static void do_nla_buttons(bContext *C, void *arg, int event)
199 {
200         switch (event) {
201                 case B_REDR:
202                         ED_area_tag_redraw(CTX_wm_area(C));
203                         break;
204         }
205 }
206
207
208 void nla_header_buttons(const bContext *C, ARegion *ar)
209 {
210         SpaceNla *snla= (SpaceNla *)CTX_wm_space_data(C);
211         ScrArea *sa= CTX_wm_area(C);
212         uiBlock *block;
213         int xco, yco= 3;
214         
215         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
216         uiBlockSetHandleFunc(block, do_nla_buttons, NULL);
217         
218         xco= ED_area_header_standardbuttons(C, block, yco);
219         
220         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
221                 int xmax;
222                 
223                 xmax= GetButStringLength("View");
224                 uiDefMenuBut(block, nla_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
225                 xco+= xmax;
226                 
227                 xmax= GetButStringLength("Select");
228                 uiDefMenuBut(block, nla_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
229                 xco+= xmax;
230                 
231                 xmax= GetButStringLength("Edit");
232                 uiDefMenuBut(block, nla_editmenu, NULL, "Edit", xco, yco, xmax-3, 20, "");
233                 xco+= xmax;
234                 
235                 xmax= GetButStringLength("Add");
236                 uiDefMenuBut(block, nla_addmenu, NULL, "Add", xco, yco, xmax-3, 20, "");
237                 xco+= xmax;
238         }
239         
240         uiBlockSetEmboss(block, UI_EMBOSS);
241         
242         /* filtering buttons */
243         if (snla->ads) {
244                 uiBlockBeginAlign(block);
245                         uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Only display selected Objects");
246                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NLA_NOACT, B_REDR, ICON_ACTION,        (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Include AnimData blocks with no NLA Data");
247                 uiBlockEndAlign(block);
248                 xco += 5;
249                 
250                 uiBlockBeginAlign(block);
251                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display Scene Animation");
252                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display World Animation");
253                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display ShapeKeys");
254                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL_DATA,     (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display Materials");
255                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display Lamps");
256                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display Cameras");
257                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(snla->ads->filterflag), 0, 0, 0, 0, "Display Curves");
258                 uiBlockEndAlign(block);
259                 xco += 15;
260         }
261         else {
262                 // XXX this case shouldn't happen at all... for now, just pad out same amount of space
263                 xco += 7*XIC + 15;
264         }
265         xco += (XIC + 8);
266         
267         /* auto-snap selector */
268         if (snla->flag & SNLA_DRAWTIME) {
269                 uiDefButS(block, MENU, B_REDR,
270                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Second %x2|Nearest Marker %x3", 
271                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
272                                 "Auto-snapping mode for times when transforming");
273         }
274         else {
275                 uiDefButS(block, MENU, B_REDR, 
276                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Frame %x2|Nearest Marker %x3", 
277                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
278                                 "Auto-snapping mode for times when transforming");
279         }
280         xco += 98;
281         
282         /* always as last  */
283         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
284         
285         uiEndBlock(C, block);
286         uiDrawBlock(C, block);
287 }
288
289