NLA SoC: Move Strips Up/Down Operators
[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 /* button events */
74 enum {
75         B_REDR  = 0,
76 } eActHeader_ButEvents;
77
78 /* ************************ header area region *********************** */
79
80
81 static void nla_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
82 {
83         bScreen *sc= CTX_wm_screen(C);
84         ScrArea *sa= CTX_wm_area(C);
85         Scene *scene= CTX_data_scene(C);
86         SpaceNla *snla= (SpaceNla*)CTX_wm_space_data(C);
87         PointerRNA spaceptr;
88         
89         /* retrieve state */
90         RNA_pointer_create(&sc->id, &RNA_SpaceNLA, snla, &spaceptr);
91         
92         /* create menu */
93         uiItemO(layout, NULL, ICON_MENU_PANEL, "NLAEDIT_OT_properties");
94         
95         uiItemS(layout);
96         
97         uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0);
98         
99         if (snla->flag & SNLA_DRAWTIME)
100                 uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
101         else
102                 uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle");
103
104         uiItemS(layout);
105         
106         if (scene->flag & SCE_NLA_EDIT_ON) 
107                 uiItemO(layout, NULL, 0, "NLAEDIT_OT_tweakmode_exit");
108         else
109                 uiItemO(layout, NULL, 0, "NLAEDIT_OT_tweakmode_enter");
110         
111         uiItemS(layout);
112         
113         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
114         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
115         
116         uiItemS(layout);
117         
118         //uiItemO(layout, NULL, 0, "NLA_OT_view_all");
119         
120         if (sa->full) 
121                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
122         else 
123                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow
124 }
125
126 static void nla_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
127 {
128         uiItemO(layout, NULL, 0, "NLAEDIT_OT_select_all_toggle");
129         uiItemBooleanO(layout, "Invert All", 0, "NLAEDIT_OT_select_all_toggle", "invert", 1);
130         
131         uiItemS(layout);
132         
133         uiItemO(layout, NULL, 0, "NLAEDIT_OT_select_border");
134         uiItemBooleanO(layout, "Border Axis Range", 0, "NLAEDIT_OT_select_border", "axis_range", 1);
135 }
136
137 static void nla_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unused)
138 {
139         // XXX these operators may change for NLA...
140         uiItemEnumO(layout, "Grab/Move", 0, "TFM_OT_transform", "mode", TFM_TIME_TRANSLATE);
141         uiItemEnumO(layout, "Extend", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
142         uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
143 }
144
145 static void nla_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
146 {
147         uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu);
148         
149         uiItemS(layout);
150         
151         uiItemO(layout, NULL, 0, "NLAEDIT_OT_duplicate");
152         uiItemO(layout, NULL, 0, "NLAEDIT_OT_split");
153         
154         uiItemS(layout);
155         
156         uiItemO(layout, NULL, 0, "NLAEDIT_OT_delete");
157         
158         uiItemS(layout);
159         
160         uiItemO(layout, NULL, 0, "NLAEDIT_OT_apply_scale");
161         uiItemO(layout, NULL, 0, "NLAEDIT_OT_clear_scale");
162         
163         uiItemS(layout);
164         
165         uiItemO(layout, NULL, 0, "NLAEDIT_OT_move_up");
166         uiItemO(layout, NULL, 0, "NLAEDIT_OT_move_down");
167 }
168
169 static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
170 {
171         uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_actionclip");
172         uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_transition");
173         
174         uiItemS(layout);
175         
176         uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
177         uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
178 }
179
180 /* ------------------ */
181
182 static void do_nla_buttons(bContext *C, void *arg, int event)
183 {
184         switch (event) {
185                 case B_REDR:
186                         ED_area_tag_redraw(CTX_wm_area(C));
187                         break;
188         }
189 }
190
191
192 void nla_header_buttons(const bContext *C, ARegion *ar)
193 {
194         SpaceNla *snla= (SpaceNla *)CTX_wm_space_data(C);
195         ScrArea *sa= CTX_wm_area(C);
196         uiBlock *block;
197         int xco, yco= 3;
198         
199         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
200         uiBlockSetHandleFunc(block, do_nla_buttons, NULL);
201         
202         xco= ED_area_header_standardbuttons(C, block, yco);
203         
204         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
205                 int xmax;
206                 
207                 xmax= GetButStringLength("View");
208                 uiDefMenuBut(block, nla_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
209                 xco+= xmax;
210                 
211                 xmax= GetButStringLength("Select");
212                 uiDefMenuBut(block, nla_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
213                 xco+= xmax;
214                 
215                 xmax= GetButStringLength("Edit");
216                 uiDefMenuBut(block, nla_editmenu, NULL, "Edit", xco, yco, xmax-3, 20, "");
217                 xco+= xmax;
218                 
219                 xmax= GetButStringLength("Add");
220                 uiDefMenuBut(block, nla_addmenu, NULL, "Add", xco, yco, xmax-3, 20, "");
221                 xco+= xmax;
222         }
223         
224         uiBlockSetEmboss(block, UI_EMBOSS);
225         
226         /* filtering buttons */
227         if (snla->ads) {
228                 uiBlockBeginAlign(block);
229                         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");
230                         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");
231                 uiBlockEndAlign(block);
232                 xco += 5;
233                 
234                 uiBlockBeginAlign(block);
235                         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");
236                         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");
237                         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");
238                         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");
239                         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");
240                         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");
241                         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");
242                 uiBlockEndAlign(block);
243                 xco += 15;
244         }
245         else {
246                 // XXX this case shouldn't happen at all... for now, just pad out same amount of space
247                 xco += 7*XIC + 15;
248         }
249         xco += (XIC + 8);
250         
251         /* auto-snap selector */
252         if (snla->flag & SNLA_DRAWTIME) {
253                 uiDefButS(block, MENU, B_REDR,
254                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Second %x2|Nearest Marker %x3", 
255                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
256                                 "Auto-snapping mode for times when transforming");
257         }
258         else {
259                 uiDefButS(block, MENU, B_REDR, 
260                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Frame %x2|Nearest Marker %x3", 
261                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
262                                 "Auto-snapping mode for times when transforming");
263         }
264         xco += 98;
265         
266         /* always as last  */
267         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
268         
269         uiEndBlock(C, block);
270         uiDrawBlock(C, block);
271 }
272
273