NLA SoC: Scale Operators - Clear (Alt-S) and Apply (Ctrl-A)
[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
164 static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
165 {
166         uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_actionclip");
167         uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_transition");
168         
169         uiItemS(layout);
170         
171         uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
172         uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
173 }
174
175 /* ------------------ */
176
177 static void do_nla_buttons(bContext *C, void *arg, int event)
178 {
179         switch (event) {
180                 case B_REDR:
181                         ED_area_tag_redraw(CTX_wm_area(C));
182                         break;
183         }
184 }
185
186
187 void nla_header_buttons(const bContext *C, ARegion *ar)
188 {
189         SpaceNla *snla= (SpaceNla *)CTX_wm_space_data(C);
190         ScrArea *sa= CTX_wm_area(C);
191         uiBlock *block;
192         int xco, yco= 3;
193         
194         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
195         uiBlockSetHandleFunc(block, do_nla_buttons, NULL);
196         
197         xco= ED_area_header_standardbuttons(C, block, yco);
198         
199         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
200                 int xmax;
201                 
202                 xmax= GetButStringLength("View");
203                 uiDefMenuBut(block, nla_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
204                 xco+= xmax;
205                 
206                 xmax= GetButStringLength("Select");
207                 uiDefMenuBut(block, nla_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
208                 xco+= xmax;
209                 
210                 xmax= GetButStringLength("Edit");
211                 uiDefMenuBut(block, nla_editmenu, NULL, "Edit", xco, yco, xmax-3, 20, "");
212                 xco+= xmax;
213                 
214                 xmax= GetButStringLength("Add");
215                 uiDefMenuBut(block, nla_addmenu, NULL, "Add", xco, yco, xmax-3, 20, "");
216                 xco+= xmax;
217         }
218         
219         uiBlockSetEmboss(block, UI_EMBOSS);
220         
221         /* filtering buttons */
222         if (snla->ads) {
223                 uiBlockBeginAlign(block);
224                         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");
225                         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");
226                 uiBlockEndAlign(block);
227                 xco += 5;
228                 
229                 uiBlockBeginAlign(block);
230                         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");
231                         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");
232                         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");
233                         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");
234                         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");
235                         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");
236                         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");
237                 uiBlockEndAlign(block);
238                 xco += 15;
239         }
240         else {
241                 // XXX this case shouldn't happen at all... for now, just pad out same amount of space
242                 xco += 7*XIC + 15;
243         }
244         xco += (XIC + 8);
245         
246         /* auto-snap selector */
247         if (snla->flag & SNLA_DRAWTIME) {
248                 uiDefButS(block, MENU, B_REDR,
249                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Second %x2|Nearest Marker %x3", 
250                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
251                                 "Auto-snapping mode for times when transforming");
252         }
253         else {
254                 uiDefButS(block, MENU, B_REDR, 
255                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Frame %x2|Nearest Marker %x3", 
256                                 xco,yco,90,YIC, &snla->autosnap, 0, 1, 0, 0, 
257                                 "Auto-snapping mode for times when transforming");
258         }
259         xco += 98;
260         
261         /* always as last  */
262         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
263         
264         uiEndBlock(C, block);
265         uiDrawBlock(C, block);
266 }
267
268