RNA: particle wrapping is a bit more complete now.
[blender-staging.git] / source / blender / editors / space_outliner / outliner_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_ID.h"
33 #include "DNA_anim_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_windowmanager_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_animsys.h"
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_main.h"
47 #include "BKE_screen.h"
48
49 #include "ED_keyframing.h"
50 #include "ED_screen.h"
51 #include "ED_util.h"
52 #include "ED_types.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "BIF_gl.h"
58 #include "BIF_glutil.h"
59
60 #include "UI_interface.h"
61 #include "UI_resources.h"
62 #include "UI_view2d.h"
63
64 #include "outliner_intern.h"
65
66
67 /* ************************ header area region *********************** */
68
69 static void do_viewmenu(bContext *C, void *arg, int event)
70 {
71         ScrArea *curarea= CTX_wm_area(C);
72         SpaceOops *soops= curarea->spacedata.first;
73         
74         switch(event) {
75                 case 0: /* Shuffle Selected Blocks */
76                         //shuffle_oops();
77                         break;
78                 case 1: /* Shrink Selected Blocks */
79                         //shrink_oops();
80                         break;
81                 case 2: /* View All */
82                         //do_oops_buttons(B_OOPSHOME);
83                         break;
84                 case 3: /* View All */
85                         //do_oops_buttons(B_OOPSVIEWSEL);
86                         break;
87                 case 4: /* Maximize Window */
88                         /* using event B_FULL */
89                         break;
90                         break;
91                 case 14: /* show outliner viewer */
92                         soops->type= SO_OUTLINER;
93                         break;
94                 case 6:
95                         //outliner_toggle_visible(curarea);
96                         break;
97                 case 7:
98                         //outliner_show_hierarchy(curarea);
99                         break;
100                 case 8:
101                         //outliner_show_active(curarea);
102                         break;
103                 case 9:
104                         //outliner_one_level(curarea, 1);
105                         break;
106                 case 10:
107                         //outliner_one_level(curarea, -1);
108                         break;
109                 case 12:
110                         if (soops->flag & SO_HIDE_RESTRICTCOLS) soops->flag &= ~SO_HIDE_RESTRICTCOLS;
111                         else soops->flag |= SO_HIDE_RESTRICTCOLS;
112                         break;
113         }
114         ED_area_tag_redraw(curarea);
115 }
116
117 static uiBlock *outliner_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
118 {
119         ScrArea *curarea= CTX_wm_area(C);
120         SpaceOops *soops= curarea->spacedata.first;
121         uiBlock *block;
122         short yco= 0, menuwidth=120;
123         
124         block= uiBeginBlock(C, ar, "outliner_viewmenu", UI_EMBOSSP, UI_HELV);
125         uiBlockSetButmFunc(block, do_viewmenu, NULL);
126         
127         if(soops->type==SO_OUTLINER) {
128                 if (soops->flag & SO_HIDE_RESTRICTCOLS)
129                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Restriction Columns", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
130                 else
131                         uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Restriction Columns", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
132                 
133                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
134                 
135                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Expand One Level|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
136                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Collapse One Level|NumPad -", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
137                 
138                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");  
139                 
140                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show/Hide All", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
141                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hierarchy|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
142                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Active|NumPad .", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
143         }
144         
145 //      uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");  
146 //      if(!curarea->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
147 //      else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
148         
149         
150         if(curarea->headertype==HEADERTOP) {
151                 uiBlockSetDirection(block, UI_DOWN);
152         }
153         else {
154                 uiBlockSetDirection(block, UI_TOP);
155                 uiBlockFlipOrder(block);
156         }
157         
158         uiTextBoundsBlock(block, 50);
159         uiEndBlock(C, block);
160         
161         return block;
162 }
163
164 enum {
165         B_REDR  = 1,
166         
167         B_KEYINGSET_CHANGE,
168         B_KEYINGSET_REMOVE,
169 } eOutlinerHeader_Events;
170
171 static void do_outliner_buttons(bContext *C, void *arg, int event)
172 {
173         ScrArea *sa= CTX_wm_area(C);
174         Scene *scene= CTX_data_scene(C);
175         
176         switch(event) {
177                 case B_REDR:
178                         ED_area_tag_redraw(sa);
179                         break;
180                         
181                 case B_KEYINGSET_CHANGE:
182                         /* add a new KeyingSet if active is -1 */
183                         if (scene->active_keyingset == -1) {
184                                 // XXX the default settings have yet to evolve... need to keep this in sync with the 
185                                 BKE_keyingset_add(&scene->keyingsets, "KeyingSet", KEYINGSET_ABSOLUTE, 0);
186                                 scene->active_keyingset= BLI_countlist(&scene->keyingsets);
187                         }
188                         
189                         /* redraw regions with KeyingSet info */
190                         WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
191                         break;
192                         
193                 case B_KEYINGSET_REMOVE:
194                         /* remove the active KeyingSet */
195                         if (scene->active_keyingset) {
196                                 KeyingSet *ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
197                                 
198                                 /* firstly free KeyingSet's data, then free the KeyingSet itself */
199                                 if (ks) {
200                                         BKE_keyingset_free(ks);
201                                         BLI_freelinkN(&scene->keyingsets, ks);
202                                         scene->active_keyingset= 0;
203                                 }
204                         }
205                         
206                         /* redraw regions with KeyingSet info */
207                         WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
208                         break;
209         }
210 }
211
212
213 void outliner_header_buttons(const bContext *C, ARegion *ar)
214 {
215         ScrArea *sa= CTX_wm_area(C);
216         Scene *scene= CTX_data_scene(C);
217         SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
218         uiBlock *block;
219         int xco, yco= 3, xmax;
220         
221         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
222         uiBlockSetHandleFunc(block, do_outliner_buttons, NULL);
223         
224         xco= ED_area_header_standardbuttons(C, block, yco);
225         
226         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
227                 
228                 /* pull down menus */
229                 uiBlockSetEmboss(block, UI_EMBOSSP);
230                 
231                 xmax= GetButStringLength("View");
232                 uiDefPulldownBut(block, outliner_viewmenu, CTX_wm_area(C), 
233                                                  "View", xco, yco-2, xmax-3, 24, ""); 
234                 xco += xmax;
235                 
236                 /* header text */
237                 xco += XIC*2;
238                 
239                 uiBlockSetEmboss(block, UI_EMBOSS);
240         }
241         
242         //if (outliner->type==SO_OUTLINER) {
243                 /* data selector*/
244                 if(G.main->library.first) 
245                         uiDefButS(block, MENU, B_REDR, "Outliner Display%t|Libraries %x7|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12",     xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");
246                 else
247                         uiDefButS(block, MENU, B_REDR, "Outliner Display%t|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12",   xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");   
248                 xco += 120;
249                 
250                 /* KeyingSet editing buttons */
251                 if ((soutliner->flag & SO_HIDE_KEYINGSETINFO)==0 && (soutliner->outlinevis==SO_DATABLOCKS)) {
252                         KeyingSet *ks= NULL;
253                         char *menustr= NULL;
254                         
255                         xco+= (int)(XIC*1.5);
256                         
257                         if (scene->active_keyingset)
258                                 ks= (KeyingSet *)BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
259                         
260                         uiBlockBeginAlign(block);
261                                 /* currently 'active' KeyingSet */
262                                 menustr= ANIM_build_keyingsets_menu(&scene->keyingsets, 1);
263                                 uiDefButI(block, MENU, B_KEYINGSET_CHANGE, menustr, xco,yco, 18,20, &scene->active_keyingset, 0, 0, 0, 0, "Browse Keying Sets");
264                                 MEM_freeN(menustr);
265                                 xco += 18;
266                                 
267                                 /* currently 'active' KeyingSet - change name */
268                                 if (ks) {
269                                         /* active KeyingSet */
270                                         uiDefBut(block, TEX, B_KEYINGSET_CHANGE,"", xco,yco,120,20, ks->name, 0, 63, 0, 0, "Name of Active Keying Set");
271                                         xco += 120;
272                                         uiDefIconBut(block, BUT, B_KEYINGSET_REMOVE, VICON_X, xco, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove this Keying Set");
273                                         xco += 20;
274                                 }
275                                 else {
276                                         /* no active KeyingSet... so placeholder instead */
277                                         uiDefBut(block, LABEL, 0,"<No Keying Set Active>", xco,yco,140,20, NULL, 0, 63, 0, 0, "Name of Active Keying Set");
278                                         xco += 140;
279                                 }
280                         uiBlockEndAlign(block);
281                         
282                         /* current 'active' KeyingSet */
283                         if (ks) {
284                                 xco += 5;
285                                 
286                                 /* operator buttons to add/remove selected items from set */
287                                 uiBlockBeginAlign(block);
288                                                 // XXX the icons here are temporary
289                                         uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_remove_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMOUT, xco,yco,XIC,YIC, "Remove selected properties from active Keying Set (Alt-K)");
290                                         xco += XIC;
291                                         uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_add_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, xco,yco,XIC,YIC, "Add selected properties to active Keying Set (K)");
292                                         xco += XIC;
293                                 uiBlockEndAlign(block);
294                                 
295                                 xco += 10;
296                                 
297                                 /* operator buttons to insert/delete keyframes for the active set */
298                                 uiBlockBeginAlign(block);
299                                         uiDefIconButO(block, BUT, "ANIM_OT_delete_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_DEHLT, xco,yco,XIC,YIC, "Delete Keyframes for the Active Keying Set (Alt-I)");
300                                         xco+= XIC;
301                                         uiDefIconButO(block, BUT, "ANIM_OT_insert_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_HLT, xco,yco,XIC,YIC, "Insert Keyframes for the Active Keying Set (I)");
302                                         xco+= XIC;
303                                 uiBlockEndAlign(block);
304                         }
305                         
306                         xco += XIC*2;
307                 }
308         //}
309         
310         /* always as last  */
311         UI_view2d_totRect_set(&ar->v2d, xco+XIC+100, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
312         
313         uiEndBlock(C, block);
314         uiDrawBlock(C, block);
315 }
316
317