Merge with trunk up to r38584.
[blender.git] / source / blender / editors / space_outliner / outliner_draw.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2004 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): Joshua Leung
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_outliner/outliner_draw.c
29  *  \ingroup spoutliner
30  */
31
32 #include <string.h>
33 #include <stdlib.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "DNA_anim_types.h"
38 #include "DNA_armature_types.h"
39 #include "DNA_camera_types.h"
40 #include "DNA_group_types.h"
41 #include "DNA_key_types.h"
42 #include "DNA_lamp_types.h"
43 #include "DNA_material_types.h"
44 #include "DNA_mesh_types.h"
45 #include "DNA_meta_types.h"
46 #include "DNA_particle_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_world_types.h"
49 #include "DNA_sequence_types.h"
50 #include "DNA_object_types.h"
51
52 #include "BLI_blenlib.h"
53 #include "BLI_utildefines.h"
54
55 #include "BKE_animsys.h"
56 #include "BKE_context.h"
57 #include "BKE_deform.h"
58 #include "BKE_depsgraph.h"
59 #include "BKE_fcurve.h"
60 #include "BKE_global.h"
61 #include "BKE_group.h"
62 #include "BKE_library.h"
63 #include "BKE_main.h"
64 #include "BKE_modifier.h"
65 #include "BKE_report.h"
66 #include "BKE_scene.h"
67 #include "BKE_sequencer.h"
68
69 #include "ED_armature.h"
70 #include "ED_object.h"
71 #include "ED_screen.h"
72 #include "ED_util.h"
73
74 #include "WM_api.h"
75 #include "WM_types.h"
76
77 #include "BIF_gl.h"
78 #include "BIF_glutil.h"
79
80 #include "UI_interface.h"
81 #include "UI_interface_icons.h"
82 #include "UI_resources.h"
83 #include "UI_view2d.h"
84
85 #include "RNA_access.h"
86 #include "RNA_define.h"
87
88 #include "outliner_intern.h"
89
90 /* ****************************************************** */
91 /* Tree Size Functions */
92
93 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
94 {
95         TreeElement *te= lb->first;
96         while(te) {
97                 TreeStoreElem *tselem= TREESTORE(te);
98                 if((tselem->flag & TSE_CLOSED)==0) 
99                         outliner_height(soops, &te->subtree, h);
100                 (*h) += UI_UNIT_Y;
101                 te= te->next;
102         }
103 }
104
105 #if 0  // XXX this is currently disabled until te->xend is set correctly
106 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
107 {
108         TreeElement *te= lb->first;
109         while(te) {
110 //              TreeStoreElem *tselem= TREESTORE(te);
111                 
112                 // XXX fixme... te->xend is not set yet
113                 if(tselem->flag & TSE_CLOSED) {
114                         if (te->xend > *w)
115                                 *w = te->xend;
116                 }
117                 outliner_width(soops, &te->subtree, w);
118                 te= te->next;
119         }
120 }
121 #endif
122
123 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
124 {
125         TreeElement *te= lb->first;
126         while(te) {
127                 TreeStoreElem *tselem= TREESTORE(te);
128                         // XXX fixme... (currently, we're using a fixed length of 100)!
129                 /*if(te->xend) {
130                         if(te->xend > *w)
131                                 *w = te->xend;
132                 }*/
133                 if(startx+100 > *w)
134                         *w = startx+100;
135
136                 if((tselem->flag & TSE_CLOSED)==0)
137                         outliner_rna_width(soops, &te->subtree, w, startx+UI_UNIT_X);
138                 te= te->next;
139         }
140 }
141
142 /* ****************************************************** */
143
144 static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
145 {
146         Scene *scene = (Scene *)poin;
147         Object *ob = (Object *)poin2;
148
149         if(!common_restrict_check(C, ob)) return;
150         
151         /* deselect objects that are invisible */
152         if (ob->restrictflag & OB_RESTRICT_VIEW) {
153                 /* Ouch! There is no backwards pointer from Object to Base, 
154                  * so have to do loop to find it. */
155                 ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
156         }
157         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
158
159 }
160
161 static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
162 {
163         Scene *scene = (Scene *)poin;
164         Object *ob = (Object *)poin2;
165         
166         if(!common_restrict_check(C, ob)) return;
167         
168         /* if select restriction has just been turned on */
169         if (ob->restrictflag & OB_RESTRICT_SELECT) {
170                 /* Ouch! There is no backwards pointer from Object to Base, 
171                  * so have to do loop to find it. */
172                 ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
173         }
174         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
175
176 }
177
178 static void restrictbutton_rend_cb(bContext *C, void *poin, void *UNUSED(poin2))
179 {
180         WM_event_add_notifier(C, NC_SCENE|ND_OB_RENDER, poin);
181 }
182
183 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
184 {
185         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, poin);
186 }
187
188 static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *poin2)
189 {
190         Object *ob = (Object *)poin2;
191         
192         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
193
194         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
195 }
196
197 static void restrictbutton_bone_cb(bContext *C, void *UNUSED(poin), void *poin2)
198 {
199         Bone *bone= (Bone *)poin2;
200         if(bone && (bone->flag & BONE_HIDDEN_P))
201                 bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
202         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
203 }
204
205 static void restrictbutton_ebone_cb(bContext *C, void *UNUSED(poin), void *poin2)
206 {
207         EditBone *ebone= (EditBone *)poin2;
208         if(ebone && (ebone->flag & BONE_HIDDEN_A))
209                 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
210
211         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
212 }
213
214 static int group_restrict_flag(Group *gr, int flag)
215 {
216         GroupObject *gob;
217
218         for(gob= gr->gobject.first; gob; gob= gob->next) {
219                 if((gob->ob->restrictflag & flag) == 0)
220                         return 0;
221         }
222
223         return 1;
224 }
225
226 static int group_select_flag(Group *gr)
227 {
228         GroupObject *gob;
229
230         for(gob= gr->gobject.first; gob; gob= gob->next)
231                 if((gob->ob->flag & SELECT))
232                         return 1;
233
234         return 0;
235 }
236
237 static void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
238 {       
239         Scene *scene = (Scene *)poin;           
240         GroupObject *gob;
241         Group *gr = (Group *)poin2;     
242
243         if(group_restrict_flag(gr, flag)) {
244                 for(gob= gr->gobject.first; gob; gob= gob->next) {
245                         gob->ob->restrictflag &= ~flag;
246                         
247                         if(flag==OB_RESTRICT_VIEW)
248                                 if(gob->ob->flag & SELECT)
249                                         ED_base_object_select(object_in_scene(gob->ob, scene), BA_DESELECT);
250                 }
251         }
252         else {
253                 for(gob= gr->gobject.first; gob; gob= gob->next) {
254                         /* not in editmode */
255                         if(scene->obedit!=gob->ob) {
256                                 gob->ob->restrictflag |= flag;
257                                 
258                                 if(flag==OB_RESTRICT_VIEW)
259                                         if((gob->ob->flag & SELECT) == 0)
260                                                 ED_base_object_select(object_in_scene(gob->ob, scene), BA_SELECT);
261                         }
262                 }
263         }
264
265
266 static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
267 {
268         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
269         WM_event_add_notifier(C, NC_GROUP, NULL);
270 }
271 static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
272 {
273         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
274         WM_event_add_notifier(C, NC_GROUP, NULL);
275 }
276 static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
277 {
278         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
279         WM_event_add_notifier(C, NC_GROUP, NULL);
280 }
281
282
283 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
284 {
285         SpaceOops *soops= CTX_wm_space_outliner(C);
286         Scene *scene= CTX_data_scene(C);
287         Object *obedit= CTX_data_edit_object(C);
288         TreeStore *ts= soops->treestore;
289         TreeStoreElem *tselem= tsep;
290         
291         if(ts && tselem) {
292                 TreeElement *te= outliner_find_tse(soops, tselem);
293                 
294                 if(tselem->type==0) {
295                         test_idbutton(tselem->id->name+2);      // library.c, unique name and alpha sort
296                         
297                         switch(GS(tselem->id->name)) {
298                                 case ID_MA:
299                                         WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
300                                 case ID_TE:
301                                         WM_event_add_notifier(C, NC_TEXTURE, NULL); break;
302                                 case ID_IM:
303                                         WM_event_add_notifier(C, NC_IMAGE, NULL); break;
304                                 case ID_SCE:
305                                         WM_event_add_notifier(C, NC_SCENE, NULL); break;
306                                 default:
307                                         WM_event_add_notifier(C, NC_ID|NA_RENAME, NULL); break;
308                         }                                       
309                         /* Check the library target exists */
310                         if (te->idcode == ID_LI) {
311                                 char expanded[FILE_MAXDIR + FILE_MAXFILE];
312                                 BLI_strncpy(expanded, ((Library *)tselem->id)->name, FILE_MAXDIR + FILE_MAXFILE);
313                                 BLI_path_abs(expanded, G.main->name);
314                                 if (!BLI_exists(expanded)) {
315                                         BKE_report(CTX_wm_reports(C), RPT_ERROR, "This path does not exist, correct this before saving");
316                                 }
317                         }
318                 }
319                 else {
320                         switch(tselem->type) {
321                         case TSE_DEFGROUP:
322                                 defgroup_unique_name(te->directdata, (Object *)tselem->id); //  id = object
323                                 break;
324                         case TSE_NLA_ACTION:
325                                 test_idbutton(tselem->id->name+2);
326                                 break;
327                         case TSE_EBONE:
328                         {
329                                 bArmature *arm= (bArmature *)tselem->id;
330                                 if(arm->edbo) {
331                                         EditBone *ebone= te->directdata;
332                                         char newname[sizeof(ebone->name)];
333                                         
334                                         /* restore bone name */
335                                         BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
336                                         BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
337                                         ED_armature_bone_rename(obedit->data, oldname, newname);
338                                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, OBACT);
339                                 }
340                         }
341                                 break;
342
343                         case TSE_BONE:
344                                 {
345                                         Bone *bone= te->directdata;
346                                         Object *ob;
347                                         char newname[sizeof(bone->name)];
348                                         
349                                         // always make current object active
350                                         tree_element_active(C, scene, soops, te, 1); // was set_active_object()
351                                         ob= OBACT;
352                                         
353                                         /* restore bone name */
354                                         BLI_strncpy(newname, bone->name, sizeof(bone->name));
355                                         BLI_strncpy(bone->name, oldname, sizeof(bone->name));
356                                         ED_armature_bone_rename(ob->data, oldname, newname);
357                                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
358                                 }
359                                 break;
360                         case TSE_POSE_CHANNEL:
361                                 {
362                                         bPoseChannel *pchan= te->directdata;
363                                         Object *ob;
364                                         char newname[sizeof(pchan->name)];
365                                         
366                                         // always make current object active
367                                         tree_element_active(C, scene, soops, te, 1); // was set_active_object()
368                                         ob= OBACT;
369                                         
370                                         /* restore bone name */
371                                         BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
372                                         BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
373                                         ED_armature_bone_rename(ob->data, oldname, newname);
374                                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
375                                 }
376                                 break;
377                         case TSE_POSEGRP:
378                                 {
379                                         Object *ob= (Object *)tselem->id; // id = object
380                                         bActionGroup *grp= te->directdata;
381                                         
382                                         BLI_uniquename(&ob->pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), sizeof(grp->name));
383                                         WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
384                                 }
385                                 break;
386                         case TSE_R_LAYER:
387                                 break;
388                         }
389                 }
390                 tselem->flag &= ~TSE_TEXTBUT;
391         }
392 }
393
394 static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, ListBase *lb)
395 {       
396         uiBut *bt;
397         TreeElement *te;
398         TreeStoreElem *tselem;
399         Object *ob = NULL;
400         Group  *gr = NULL;
401
402         for(te= lb->first; te; te= te->next) {
403                 tselem= TREESTORE(te);
404                 if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {      
405                         /* objects have toggle-able restriction flags */
406                         if(tselem->type==0 && te->idcode==ID_OB) {
407                                 PointerRNA ptr;
408                                 
409                                 ob = (Object *)tselem->id;
410                                 RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ptr);
411                                 
412                                 uiBlockSetEmboss(block, UI_EMBOSSN);
413                                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF,
414                                                           (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
415                                                           &ptr, "hide", -1, 0, 0, -1, -1, NULL);
416                                 uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
417                                 
418                                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
419                                                                   (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
420                                                                   &ptr, "hide_select", -1, 0, 0, -1, -1, NULL);
421                                 uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
422                                 
423                                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
424                                                                   (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
425                                                                   &ptr, "hide_render", -1, 0, 0, -1, -1, NULL);
426                                 uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
427                                 
428                                 uiBlockSetEmboss(block, UI_EMBOSS);
429                                 
430                         }
431                         if(tselem->type==0 && te->idcode==ID_GR){ 
432                                 int restrict_bool;
433                                 gr = (Group *)tselem->id;
434                                 
435                                 uiBlockSetEmboss(block, UI_EMBOSSN);
436                                 
437                                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_VIEW);
438                                 bt = uiDefIconBut(block, BUT, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF, (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, NULL, 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
439                                 uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr);
440
441                                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_SELECT);
442                                 bt = uiDefIconBut(block, BUT, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF, (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, NULL, 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
443                                 uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr);
444         
445                                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_RENDER);
446                                 bt = uiDefIconBut(block, BUT, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF, (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, NULL, 0, 0, 0, 0, "Restrict/Allow renderability");
447                                 uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr);
448
449                                 uiBlockSetEmboss(block, UI_EMBOSS);
450                         }
451                         /* scene render layers and passes have toggle-able flags too! */
452                         else if(tselem->type==TSE_R_LAYER) {
453                                 uiBlockSetEmboss(block, UI_EMBOSSN);
454                                 
455                                 bt= uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT-1, 
456                                                                          (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, te->directdata, 0, 0, 0, 0, "Render this RenderLayer");
457                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
458                                 
459                                 uiBlockSetEmboss(block, UI_EMBOSS);
460                         }
461                         else if(tselem->type==TSE_R_PASS) {
462                                 int *layflag= te->directdata;
463                                 int passflag= 1<<tselem->nr;
464                                 
465                                 uiBlockSetEmboss(block, UI_EMBOSSN);
466                                 
467                                 
468                                 bt= uiDefIconButBitI(block, ICONTOG, passflag, 0, ICON_CHECKBOX_HLT-1, 
469                                                                          (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, layflag, 0, 0, 0, 0, "Render this Pass");
470                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
471                                 
472                                 layflag++;      /* is lay_xor */
473                                 if(ELEM8(passflag, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT, SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT))
474                                         bt= uiDefIconButBitI(block, TOG, passflag, 0, (*layflag & passflag)?ICON_DOT:ICON_BLANK1, 
475                                                                          (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, layflag, 0, 0, 0, 0, "Exclude this Pass from Combined");
476                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
477                                 
478                                 uiBlockSetEmboss(block, UI_EMBOSS);
479                         }
480                         else if(tselem->type==TSE_MODIFIER)  {
481                                 ModifierData *md= (ModifierData *)te->directdata;
482                                 ob = (Object *)tselem->id;
483                                 
484                                 uiBlockSetEmboss(block, UI_EMBOSSN);
485                                 bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF, 
486                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
487                                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
488                                 
489                                 bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF, 
490                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability");
491                                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
492                         }
493                         else if(tselem->type==TSE_POSE_CHANNEL)  {
494                                 bPoseChannel *pchan= (bPoseChannel *)te->directdata;
495                                 Bone *bone = pchan->bone;
496                                 
497                                 uiBlockSetEmboss(block, UI_EMBOSSN);
498                                 bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF, 
499                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
500                                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone);
501                                 
502                                 bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
503                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
504                                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
505                         }
506                         else if(tselem->type==TSE_EBONE)  {
507                                 EditBone *ebone= (EditBone *)te->directdata;
508                                 
509                                 uiBlockSetEmboss(block, UI_EMBOSSN);
510                                 bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF, 
511                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
512                                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone);
513                                 
514                                 bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
515                                                 (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
516                                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL);
517                         }
518                 }
519                 
520                 if((tselem->flag & TSE_CLOSED)==0) outliner_draw_restrictbuts(block, scene, ar, soops, &te->subtree);
521         }
522 }
523
524 static void outliner_draw_rnacols(ARegion *ar, int sizex)
525 {
526         View2D *v2d= &ar->v2d;
527
528         float miny = v2d->cur.ymin-V2D_SCROLL_HEIGHT;
529         if(miny<v2d->tot.ymin) miny = v2d->tot.ymin;
530
531         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
532
533         /* draw column separator lines */
534         fdrawline((float)sizex,
535                 v2d->cur.ymax,
536                 (float)sizex,
537                 miny);
538
539         fdrawline((float)sizex+OL_RNA_COL_SIZEX,
540                 v2d->cur.ymax,
541                 (float)sizex+OL_RNA_COL_SIZEX,
542                 miny);
543 }
544
545 static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
546 {       
547         TreeElement *te;
548         TreeStoreElem *tselem;
549         PointerRNA *ptr;
550         PropertyRNA *prop;
551         
552         uiBlockSetEmboss(block, UI_EMBOSST);
553
554         for(te= lb->first; te; te= te->next) {
555                 tselem= TREESTORE(te);
556                 if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {      
557                         if(tselem->type == TSE_RNA_PROPERTY) {
558                                 ptr= &te->rnaptr;
559                                 prop= te->directdata;
560                                 
561                                 if(!(RNA_property_type(prop) == PROP_POINTER && (tselem->flag & TSE_CLOSED)==0))
562                                         uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y-1);
563                         }
564                         else if(tselem->type == TSE_RNA_ARRAY_ELEM) {
565                                 ptr= &te->rnaptr;
566                                 prop= te->directdata;
567                                 
568                                 uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y-1);
569                         }
570                 }
571                 
572                 if((tselem->flag & TSE_CLOSED)==0) outliner_draw_rnabuts(block, scene, ar, soops, sizex, &te->subtree);
573         }
574 }
575
576 static void operator_call_cb(struct bContext *UNUSED(C), void *arg_kmi, void *arg2)
577 {
578         wmOperatorType *ot= arg2;
579         wmKeyMapItem *kmi= arg_kmi;
580         
581         if(ot)
582                 BLI_strncpy(kmi->idname, ot->idname, OP_MAX_TYPENAME);
583 }
584
585 static void operator_search_cb(const struct bContext *UNUSED(C), void *UNUSED(arg_kmi), const char *str, uiSearchItems *items)
586 {
587         wmOperatorType *ot = WM_operatortype_first();
588         
589         for(; ot; ot= ot->next) {
590                 
591                 if(BLI_strcasestr(ot->idname, str)) {
592                         char name[OP_MAX_TYPENAME];
593                         
594                         /* display name for menu */
595                         WM_operator_py_idname(name, ot->idname);
596                         
597                         if(0==uiSearchItemAdd(items, name, ot, 0))
598                                 break;
599                 }
600         }
601 }
602
603 /* operator Search browse menu, open */
604 static uiBlock *operator_search_menu(bContext *C, ARegion *ar, void *arg_kmi)
605 {
606         static char search[OP_MAX_TYPENAME];
607         wmEvent event;
608         wmWindow *win= CTX_wm_window(C);
609         wmKeyMapItem *kmi= arg_kmi;
610         wmOperatorType *ot= WM_operatortype_find(kmi->idname, 0);
611         uiBlock *block;
612         uiBut *but;
613         
614         /* clear initial search string, then all items show */
615         search[0]= 0;
616         
617         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
618         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
619         
620         /* fake button, it holds space for search items */
621         uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
622         
623         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, UI_UNIT_Y, 0, 0, "");
624         uiButSetSearchFunc(but, operator_search_cb, arg_kmi, operator_call_cb, ot);
625         
626         uiBoundsBlock(block, 6);
627         uiBlockSetDirection(block, UI_DOWN);    
628         uiEndBlock(C, block);
629         
630         event= *(win->eventstate);      /* XXX huh huh? make api call */
631         event.type= EVT_BUT_OPEN;
632         event.val= KM_PRESS;
633         event.customdata= but;
634         event.customdatafree= FALSE;
635         wm_event_add(win, &event);
636         
637         return block;
638 }
639
640 #define OL_KM_KEYBOARD          0
641 #define OL_KM_MOUSE                     1
642 #define OL_KM_TWEAK                     2
643 #define OL_KM_SPECIALS          3
644
645 static short keymap_menu_type(short type)
646 {
647         if(ISKEYBOARD(type)) return OL_KM_KEYBOARD;
648         if(ISTWEAK(type)) return OL_KM_TWEAK;
649         if(ISMOUSE(type)) return OL_KM_MOUSE;
650 //      return OL_KM_SPECIALS;
651         return 0;
652 }
653
654 static const char *keymap_type_menu(void)
655 {
656         static const char string[]=
657         "Event Type%t"
658         "|Keyboard%x" STRINGIFY(OL_KM_KEYBOARD)
659         "|Mouse%x" STRINGIFY(OL_KM_MOUSE)
660         "|Tweak%x" STRINGIFY(OL_KM_TWEAK)
661 //      "|Specials%x" STRINGIFY(OL_KM_SPECIALS)
662         ;
663
664         return string;
665 }
666
667 static const char *keymap_mouse_menu(void)
668 {
669         static const char string[]=
670         "Mouse Event%t"
671         "|Left Mouse%x" STRINGIFY(LEFTMOUSE)
672         "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
673         "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
674         "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
675         "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
676         "|Button4 Mouse%x" STRINGIFY(BUTTON4MOUSE)
677         "|Button5 Mouse%x" STRINGIFY(BUTTON5MOUSE)
678         "|Action Mouse%x" STRINGIFY(ACTIONMOUSE)
679         "|Select Mouse%x" STRINGIFY(SELECTMOUSE)
680         "|Mouse Move%x" STRINGIFY(MOUSEMOVE)
681         "|Wheel Up%x" STRINGIFY(WHEELUPMOUSE)
682         "|Wheel Down%x" STRINGIFY(WHEELDOWNMOUSE)
683         "|Wheel In%x" STRINGIFY(WHEELINMOUSE)
684         "|Wheel Out%x" STRINGIFY(WHEELOUTMOUSE)
685         "|Mouse/Trackpad Pan%x" STRINGIFY(MOUSEPAN)
686         "|Mouse/Trackpad Zoom%x" STRINGIFY(MOUSEZOOM)
687         "|Mouse/Trackpad Rotate%x" STRINGIFY(MOUSEROTATE)
688         ;
689
690         return string;
691 }
692
693 static const char *keymap_tweak_menu(void)
694 {
695         static const char string[]=
696         "Tweak Event%t"
697         "|Left Mouse%x" STRINGIFY(EVT_TWEAK_L)
698         "|Middle Mouse%x" STRINGIFY(EVT_TWEAK_M)
699         "|Right Mouse%x" STRINGIFY(EVT_TWEAK_R)
700         "|Action Mouse%x" STRINGIFY(EVT_TWEAK_A)
701         "|Select Mouse%x" STRINGIFY(EVT_TWEAK_S)
702         ;
703
704         return string;
705 }
706
707 static const char *keymap_tweak_dir_menu(void)
708 {
709         static const char string[]=
710         "Tweak Direction%t"
711         "|Any%x" STRINGIFY(KM_ANY)
712         "|North%x" STRINGIFY(EVT_GESTURE_N)
713         "|North-East%x" STRINGIFY(EVT_GESTURE_NE)
714         "|East%x" STRINGIFY(EVT_GESTURE_E)
715         "|Sout-East%x" STRINGIFY(EVT_GESTURE_SE)
716         "|South%x" STRINGIFY(EVT_GESTURE_S)
717         "|South-West%x" STRINGIFY(EVT_GESTURE_SW)
718         "|West%x" STRINGIFY(EVT_GESTURE_W)
719         "|North-West%x" STRINGIFY(EVT_GESTURE_NW)
720         ;
721
722         return string;
723 }
724
725
726 static void keymap_type_cb(bContext *C, void *kmi_v, void *UNUSED(arg_v))
727 {
728         wmKeyMapItem *kmi= kmi_v;
729         short maptype= keymap_menu_type(kmi->type);
730         
731         if(maptype!=kmi->maptype) {
732                 switch(kmi->maptype) {
733                         case OL_KM_KEYBOARD:
734                                 kmi->type= AKEY;
735                                 kmi->val= KM_PRESS;
736                                 break;
737                         case OL_KM_MOUSE:
738                                 kmi->type= LEFTMOUSE;
739                                 kmi->val= KM_PRESS;
740                                 break;
741                         case OL_KM_TWEAK:
742                                 kmi->type= EVT_TWEAK_L;
743                                 kmi->val= KM_ANY;
744                                 break;
745                         case OL_KM_SPECIALS:
746                                 kmi->type= AKEY;
747                                 kmi->val= KM_PRESS;
748                 }
749                 ED_region_tag_redraw(CTX_wm_region(C));
750         }
751 }
752
753 static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
754 {
755         TreeElement *te;
756         TreeStoreElem *tselem;
757         
758         uiBlockSetEmboss(block, UI_EMBOSST);
759         
760         for(te= lb->first; te; te= te->next) {
761                 tselem= TREESTORE(te);
762                 if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
763                         uiBut *but;
764                         const char *str;
765                         int xstart= 240;
766                         int butw1= UI_UNIT_X; /* operator */
767                         int butw2= 90; /* event type, menus */
768                         int butw3= 43; /* modifiers */
769
770                         if(tselem->type == TSE_KEYMAP_ITEM) {
771                                 wmKeyMapItem *kmi= te->directdata;
772                                 
773                                 /* modal map? */
774                                 if(kmi->propvalue);
775                                 else {
776                                         uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, (int)te->ys+1, butw1, UI_UNIT_Y-1, "Assign new Operator");
777                                 }
778                                 xstart+= butw1+10;
779                                 
780                                 /* map type button */
781                                 kmi->maptype= keymap_menu_type(kmi->type);
782                                 
783                                 str= keymap_type_menu();
784                                 but= uiDefButS(block, MENU, 0, str,     xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->maptype, 0, 0, 0, 0, "Event type");
785                                 uiButSetFunc(but, keymap_type_cb, kmi, NULL);
786                                 xstart+= butw2+5;
787                                 
788                                 /* edit actual event */
789                                 switch(kmi->maptype) {
790                                         case OL_KM_KEYBOARD:
791                                                 uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, "Key code");
792                                                 xstart+= butw2+5;
793                                                 break;
794                                         case OL_KM_MOUSE:
795                                                 str= keymap_mouse_menu();
796                                                 uiDefButS(block, MENU, 0, str, xstart,(int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, 0, 0, 0, 0,  "Mouse button");      
797                                                 xstart+= butw2+5;
798                                                 break;
799                                         case OL_KM_TWEAK:
800                                                 str= keymap_tweak_menu();
801                                                 uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, 0, 0, 0, 0,  "Tweak gesture");    
802                                                 xstart+= butw2+5;
803                                                 str= keymap_tweak_dir_menu();
804                                                 uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->val, 0, 0, 0, 0,  "Tweak gesture direction");   
805                                                 xstart+= butw2+5;
806                                                 break;
807                                 }
808                                 
809                                 /* modifiers */
810                                 uiDefButS(block, OPTION, 0, "Shift",    xstart, (int)te->ys+1, butw3+5, UI_UNIT_Y-1, &kmi->shift, 0, 0, 0, 0, "Modifier"); xstart+= butw3+5;
811                                 uiDefButS(block, OPTION, 0, "Ctrl",     xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->ctrl, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
812                                 uiDefButS(block, OPTION, 0, "Alt",      xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->alt, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
813                                 uiDefButS(block, OPTION, 0, "OS",       xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
814                                 xstart+= 5;
815                                 uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->keymodifier, "Key Modifier code");
816                                 xstart+= butw3+5;
817                                 
818                                 /* rna property */
819                                 if(kmi->ptr && kmi->ptr->data) {
820                                         uiDefBut(block, LABEL, 0, "(RNA property)",     xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->oskey, 0, 0, 0, 0, ""); xstart+= butw2;
821                                 }
822
823                                 (void)xstart;
824                         }
825                 }
826                 
827                 if((tselem->flag & TSE_CLOSED)==0) outliner_draw_keymapbuts(block, ar, soops, &te->subtree);
828         }
829 }
830
831
832 static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
833 {
834         uiBut *bt;
835         TreeElement *te;
836         TreeStoreElem *tselem;
837         int spx, dx, len;
838         
839         for(te= lb->first; te; te= te->next) {
840                 tselem= TREESTORE(te);
841                 if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
842                         
843                         if(tselem->flag & TSE_TEXTBUT) {
844                                 
845                                 /* If we add support to rename Sequence.
846                                  * need change this.
847                                  */
848                                 if(tselem->type == TSE_POSE_BASE) continue; // prevent crash when trying to rename 'pose' entry of armature
849                                 
850                                 if(tselem->type==TSE_EBONE) len = sizeof(((EditBone*) 0)->name);
851                                 else if (tselem->type==TSE_MODIFIER) len = sizeof(((ModifierData*) 0)->name);
852                                 else if(tselem->id && GS(tselem->id->name)==ID_LI) len = sizeof(((Library*) 0)->name);
853                                 else len= MAX_ID_NAME-2;
854                                 
855
856                                 dx= (int)UI_GetStringWidth(te->name);
857                                 if(dx<100) dx= 100;
858                                 spx=te->xs+2*UI_UNIT_X-4;
859                                 if(spx+dx+10>ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax-spx-10;
860
861                                 bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (int)te->ys, dx+10, UI_UNIT_Y-1, (void *)te->name, 1.0, (float)len, 0, 0, "");
862                                 uiButSetRenameFunc(bt, namebutton_cb, tselem);
863                                 
864                                 /* returns false if button got removed */
865                                 if( 0 == uiButActiveOnly(C, block, bt) )
866                                         tselem->flag &= ~TSE_TEXTBUT;
867                         }
868                 }
869                 
870                 if((tselem->flag & TSE_CLOSED)==0) outliner_buttons(C, block, ar, soops, &te->subtree);
871         }
872 }
873
874 /* ****************************************************** */
875 /* Normal Drawing... */
876
877 /* make function calls a bit compacter */
878 struct DrawIconArg {
879         uiBlock *block;
880         ID *id;
881         int xmax, x, y;
882         float alpha;
883 };
884
885 static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
886 {
887         /* restrict collumn clip... it has been coded by simply overdrawing, doesnt work for buttons */
888         if(arg->x >= arg->xmax) 
889                 UI_icon_draw(arg->x, arg->y, icon);
890         else {
891                 /* XXX investigate: button placement of icons is way different than UI_icon_draw? */
892                 float ufac= UI_UNIT_X/20.0f;
893                 uiBut *but= uiDefIconBut(arg->block, LABEL, 0, icon, arg->x-3.0f*ufac, arg->y, UI_UNIT_X-4.0f*ufac, UI_UNIT_Y-4.0f*ufac, NULL, 0.0, 0.0, 1.0, arg->alpha, (arg->id && arg->id->lib) ? arg->id->lib->name : "");
894                 
895                 if(arg->id)
896                         uiButSetDragID(but, arg->id);
897         }
898
899 }
900
901 static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeStoreElem *tselem, TreeElement *te, float alpha)
902 {
903         struct DrawIconArg arg;
904         
905         /* make function calls a bit compacter */
906         arg.block= block;
907         arg.id= tselem->id;
908         arg.xmax= xmax;
909         arg.x= x;
910         arg.y= y;
911         arg.alpha= alpha;
912         
913         if(tselem->type) {
914                 switch( tselem->type) {
915                         case TSE_ANIM_DATA:
916                                 UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
917                         case TSE_NLA:
918                                 UI_icon_draw(x, y, ICON_NLA); break;
919                         case TSE_NLA_TRACK:
920                                 UI_icon_draw(x, y, ICON_NLA); break; // XXX
921                         case TSE_NLA_ACTION:
922                                 UI_icon_draw(x, y, ICON_ACTION); break;
923                         case TSE_DRIVER_BASE:
924                                 UI_icon_draw(x, y, ICON_DRIVER); break;
925                         case TSE_DEFGROUP_BASE:
926                                 UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
927                         case TSE_BONE:
928                         case TSE_EBONE:
929                                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
930                         case TSE_CONSTRAINT_BASE:
931                                 UI_icon_draw(x, y, ICON_CONSTRAINT); break;
932                         case TSE_MODIFIER_BASE:
933                                 UI_icon_draw(x, y, ICON_MODIFIER); break;
934                         case TSE_LINKED_OB:
935                                 UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
936                         case TSE_LINKED_PSYS:
937                                 UI_icon_draw(x, y, ICON_PARTICLES); break;
938                         case TSE_MODIFIER:
939                         {
940                                 Object *ob= (Object *)tselem->id;
941                                 ModifierData *md= BLI_findlink(&ob->modifiers, tselem->nr);
942                                 switch(md->type) {
943                                         case eModifierType_Subsurf: 
944                                                 UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
945                                         case eModifierType_Armature: 
946                                                 UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
947                                         case eModifierType_Lattice: 
948                                                 UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
949                                         case eModifierType_Curve: 
950                                                 UI_icon_draw(x, y, ICON_MOD_CURVE); break;
951                                         case eModifierType_Build: 
952                                                 UI_icon_draw(x, y, ICON_MOD_BUILD); break;
953                                         case eModifierType_Mirror: 
954                                                 UI_icon_draw(x, y, ICON_MOD_MIRROR); break;
955                                         case eModifierType_Decimate: 
956                                                 UI_icon_draw(x, y, ICON_MOD_DECIM); break;
957                                         case eModifierType_Wave: 
958                                                 UI_icon_draw(x, y, ICON_MOD_WAVE); break;
959                                         case eModifierType_Hook: 
960                                                 UI_icon_draw(x, y, ICON_HOOK); break;
961                                         case eModifierType_Softbody: 
962                                                 UI_icon_draw(x, y, ICON_MOD_SOFT); break;
963                                         case eModifierType_Boolean: 
964                                                 UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
965                                         case eModifierType_ParticleSystem: 
966                                                 UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
967                                         case eModifierType_ParticleInstance:
968                                                 UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
969                                         case eModifierType_EdgeSplit:
970                                                 UI_icon_draw(x, y, ICON_MOD_EDGESPLIT); break;
971                                         case eModifierType_Array:
972                                                 UI_icon_draw(x, y, ICON_MOD_ARRAY); break;
973                                         case eModifierType_UVProject:
974                                                 UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
975                                         case eModifierType_Displace:
976                                                 UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
977                                         case eModifierType_Shrinkwrap:
978                                                 UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
979                                         case eModifierType_Cast:
980                                                 UI_icon_draw(x, y, ICON_MOD_CAST); break;
981                                         case eModifierType_MeshDeform:
982                                                 UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
983                                         case eModifierType_Bevel:
984                                                 UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
985                                         case eModifierType_Smooth:
986                                                 UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
987                                         case eModifierType_SimpleDeform:
988                                                 UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
989                                         case eModifierType_Mask:
990                                                 UI_icon_draw(x, y, ICON_MOD_MASK); break;
991                                         case eModifierType_Cloth:
992                                                 UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
993                                         case eModifierType_Explode:
994                                                 UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
995                                         case eModifierType_Collision:
996                                                 UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
997                                         case eModifierType_Fluidsim:
998                                                 UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
999                                         case eModifierType_Multires:
1000                                                 UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
1001                                         case eModifierType_Smoke:
1002                                                 UI_icon_draw(x, y, ICON_MOD_SMOKE); break;
1003                                         case eModifierType_Solidify:
1004                                                 UI_icon_draw(x, y, ICON_MOD_SOLIDIFY); break;
1005                                         case eModifierType_Screw:
1006                                                 UI_icon_draw(x, y, ICON_MOD_SCREW); break;
1007                                         default:
1008                                                 UI_icon_draw(x, y, ICON_DOT); break;
1009                                 }
1010                                 break;
1011                         }
1012                         case TSE_SCRIPT_BASE:
1013                                 UI_icon_draw(x, y, ICON_TEXT); break;
1014                         case TSE_POSE_BASE:
1015                                 UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
1016                         case TSE_POSE_CHANNEL:
1017                                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
1018                         case TSE_PROXY:
1019                                 UI_icon_draw(x, y, ICON_GHOST); break;
1020                         case TSE_R_LAYER_BASE:
1021                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1022                         case TSE_R_LAYER:
1023                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1024                         case TSE_LINKED_LAMP:
1025                                 UI_icon_draw(x, y, ICON_LAMP_DATA); break;
1026                         case TSE_LINKED_MAT:
1027                                 UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
1028                         case TSE_POSEGRP_BASE:
1029                                 UI_icon_draw(x, y, ICON_VERTEXSEL); break;
1030                         case TSE_SEQUENCE:
1031                                 if(te->idcode==SEQ_MOVIE)
1032                                         UI_icon_draw(x, y, ICON_SEQUENCE);
1033                                 else if(te->idcode==SEQ_META)
1034                                         UI_icon_draw(x, y, ICON_DOT);
1035                                 else if(te->idcode==SEQ_SCENE)
1036                                         UI_icon_draw(x, y, ICON_SCENE);
1037                                 else if(te->idcode==SEQ_SOUND)
1038                                         UI_icon_draw(x, y, ICON_SOUND);
1039                                 else if(te->idcode==SEQ_IMAGE)
1040                                         UI_icon_draw(x, y, ICON_IMAGE_COL);
1041                                 else
1042                                         UI_icon_draw(x, y, ICON_PARTICLES);
1043                                 break;
1044                         case TSE_SEQ_STRIP:
1045                                 UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
1046                                 break;
1047                         case TSE_SEQUENCE_DUP:
1048                                 UI_icon_draw(x, y, ICON_OBJECT_DATA);
1049                                 break;
1050                         case TSE_RNA_STRUCT:
1051                                 if(RNA_struct_is_ID(te->rnaptr.type)) {
1052                                         arg.id= (ID *)te->rnaptr.data;
1053                                         tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
1054                                 }
1055                                 else
1056                                         UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
1057                                 break;
1058                         default:
1059                                 UI_icon_draw(x, y, ICON_DOT); break;
1060                 }
1061         }
1062         else if (GS(tselem->id->name) == ID_OB) {
1063                 Object *ob= (Object *)tselem->id;
1064                 switch (ob->type) {
1065                         case OB_LAMP:
1066                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
1067                         case OB_MESH: 
1068                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
1069                         case OB_CAMERA: 
1070                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
1071                         case OB_CURVE: 
1072                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
1073                         case OB_MBALL: 
1074                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
1075                         case OB_LATTICE: 
1076                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
1077                         case OB_ARMATURE: 
1078                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
1079                         case OB_FONT: 
1080                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
1081                         case OB_SURF: 
1082                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
1083                         case OB_EMPTY: 
1084                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY); break;
1085                 
1086                 }
1087         }
1088         else {
1089                 switch( GS(tselem->id->name)) {
1090                         case ID_SCE:
1091                                 tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
1092                         case ID_ME:
1093                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
1094                         case ID_CU:
1095                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
1096                         case ID_MB:
1097                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
1098                         case ID_LT:
1099                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
1100                         case ID_LA:
1101                         {
1102                                 Lamp *la= (Lamp *)tselem->id;
1103                                 
1104                                 switch(la->type) {
1105                                         case LA_LOCAL:
1106                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
1107                                         case LA_SUN:
1108                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
1109                                         case LA_SPOT:
1110                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
1111                                         case LA_HEMI:
1112                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
1113                                         case LA_AREA:
1114                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
1115                                         default:
1116                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
1117                                 }
1118                                 break;
1119                         }
1120                         case ID_MA:
1121                                 tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
1122                         case ID_TE:
1123                                 tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
1124                         case ID_IM:
1125                                 tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
1126                         case ID_SO:
1127                                 tselem_draw_icon_uibut(&arg, ICON_SPEAKER); break;
1128                         case ID_AR:
1129                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
1130                         case ID_CA:
1131                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
1132                         case ID_KE:
1133                                 tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
1134                         case ID_WO:
1135                                 tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
1136                         case ID_AC:
1137                                 tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
1138                         case ID_NLA:
1139                                 tselem_draw_icon_uibut(&arg, ICON_NLA); break;
1140                         case ID_TXT:
1141                                 tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
1142                         case ID_GR:
1143                                 tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
1144                         case ID_LI:
1145                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT); break;
1146                 }
1147         }
1148 }
1149
1150 static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level, int xmax, int *offsx, int ys)
1151 {
1152         TreeElement *te;
1153         TreeStoreElem *tselem;
1154         int active;
1155
1156         for(te= lb->first; te; te= te->next) {
1157                 
1158                 /* exit drawing early */
1159                 if((*offsx) - UI_UNIT_X > xmax)
1160                         break;
1161
1162                 tselem= TREESTORE(te);
1163                 
1164                 /* object hierarchy always, further constrained on level */
1165                 if(level<1 || (tselem->type==0 && te->idcode==ID_OB)) {
1166
1167                         /* active blocks get white circle */
1168                         if(tselem->type==0) {
1169                                 if(te->idcode==ID_OB) active= (OBACT==(Object *)tselem->id);
1170                                 else if(scene->obedit && scene->obedit->data==tselem->id) active= 1;    // XXX use context?
1171                                 else active= tree_element_active(C, scene, soops, te, 0);
1172                         }
1173                         else active= tree_element_type_active(NULL, scene, soops, te, tselem, 0);
1174                         
1175                         if(active) {
1176                                 float ufac= UI_UNIT_X/20.0f;
1177
1178                                 uiSetRoundBox(15);
1179                                 glColor4ub(255, 255, 255, 100);
1180                                 uiRoundBox( (float)*offsx-0.5f*ufac, (float)ys-1.0f*ufac, (float)*offsx+UI_UNIT_Y-3.0f*ufac, (float)ys+UI_UNIT_Y-3.0f*ufac, UI_UNIT_Y/2.0f-2.0f*ufac);
1181                                 glEnable(GL_BLEND); /* roundbox disables */
1182                         }
1183                         
1184                         tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
1185                         te->xs= (float)*offsx;
1186                         te->ys= (float)ys;
1187                         te->xend= (short)*offsx+UI_UNIT_X;
1188                         te->flag |= TE_ICONROW; // for click
1189                         
1190                         (*offsx) += UI_UNIT_X;
1191                 }
1192                 
1193                 /* this tree element always has same amount of branches, so dont draw */
1194                 if(tselem->type!=TSE_R_LAYER)
1195                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level+1, xmax, offsx, ys);
1196         }
1197         
1198 }
1199
1200 /* closed tree element */
1201 static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
1202 {
1203         TreeElement *ten;
1204         
1205         /* store coord and continue, we need coordinates for elements outside view too */
1206         te->xs= (float)startx;
1207         te->ys= (float)(*starty);
1208         
1209         for(ten= te->subtree.first; ten; ten= ten->next) {
1210                 outliner_set_coord_tree_element(soops, ten, startx+UI_UNIT_X, starty);
1211         }       
1212 }
1213
1214
1215 static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
1216 {
1217         TreeElement *ten;
1218         TreeStoreElem *tselem;
1219         float ufac= UI_UNIT_X/20.0f;
1220         int offsx= 0, active=0; // active=1 active obj, else active data
1221         
1222         tselem= TREESTORE(te);
1223
1224         if(*starty+2*UI_UNIT_Y >= ar->v2d.cur.ymin && *starty<= ar->v2d.cur.ymax) {
1225                 int xmax= ar->v2d.cur.xmax;
1226                 
1227                 /* icons can be ui buts, we dont want it to overlap with restrict */
1228                 if((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
1229                         xmax-= OL_TOGW+UI_UNIT_X;
1230                 
1231                 glEnable(GL_BLEND);
1232
1233                 /* colors for active/selected data */
1234                 if(tselem->type==0) {
1235                         if(te->idcode==ID_SCE) {
1236                                 if(tselem->id == (ID *)scene) {
1237                                         glColor4ub(255, 255, 255, 100);
1238                                         active= 2;
1239                                 }
1240                         }
1241                         else if(te->idcode==ID_GR) {
1242                                 Group *gr = (Group *)tselem->id;
1243                                 
1244                                 if(group_select_flag(gr)) {
1245                                         char col[4];
1246                                         UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1247                                         col[3]= 100;
1248                                         glColor4ubv((GLubyte *)col);
1249                                         
1250                                         active= 2;
1251                                 }
1252                         }
1253                         else if(te->idcode==ID_OB) {
1254                                 Object *ob= (Object *)tselem->id;
1255                                 
1256                                 if(ob==OBACT || (ob->flag & SELECT)) {
1257                                         char col[4]= {0, 0, 0, 0};
1258                                         
1259                                         /* outliner active ob: always white text, circle color now similar to view3d */
1260                                         
1261                                         active= 2; /* means it draws a color circle */
1262                                         if(ob==OBACT) {
1263                                                 if(ob->flag & SELECT) {
1264                                                         UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
1265                                                         col[3]= 100;
1266                                                 }
1267                                                 
1268                                                 active= 1; /* means it draws white text */
1269                                         }
1270                                         else if(ob->flag & SELECT) {
1271                                                 UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1272                                                 col[3]= 100;
1273                                         }
1274                                         
1275                                         glColor4ubv((GLubyte *)col);
1276                                 }
1277                         
1278                         }
1279                         else if(scene->obedit && scene->obedit->data==tselem->id) {
1280                                 glColor4ub(255, 255, 255, 100);
1281                                 active= 2;
1282                         }
1283                         else {
1284                                 if(tree_element_active(C, scene, soops, te, 0)) {
1285                                         glColor4ub(220, 220, 255, 100);
1286                                         active= 2;
1287                                 }
1288                         }
1289                 }
1290                 else {
1291                         if( tree_element_type_active(NULL, scene, soops, te, tselem, 0) ) active= 2;
1292                         glColor4ub(220, 220, 255, 100);
1293                 }
1294                 
1295                 /* active circle */
1296                 if(active) {
1297                         uiSetRoundBox(15);
1298                         uiRoundBox( (float)startx+UI_UNIT_Y-1.5f*ufac, (float)*starty+2.0f*ufac, (float)startx+2.0f*UI_UNIT_Y-4.0f*ufac, (float)*starty+UI_UNIT_Y-1.0f*ufac, UI_UNIT_Y/2.0f-2.0f*ufac);
1299                         glEnable(GL_BLEND);     /* roundbox disables it */
1300                         
1301                         te->flag |= TE_ACTIVE; // for lookup in display hierarchies
1302                 }
1303                 
1304                 /* open/close icon, only when sublevels, except for scene */
1305                 if(te->subtree.first || (tselem->type==0 && te->idcode==ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
1306                         int icon_x;
1307                         if(tselem->type==0 && ELEM(te->idcode, ID_OB, ID_SCE))
1308                                 icon_x = startx;
1309                         else
1310                                 icon_x = startx+5*ufac;
1311                         
1312                                 // icons a bit higher
1313                         if(tselem->flag & TSE_CLOSED) 
1314                                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_RIGHT);
1315                         else
1316                                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_DOWN);
1317                 }
1318                 offsx+= UI_UNIT_X;
1319                 
1320                 /* datatype icon */
1321                 
1322                 if(!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
1323                         // icons a bit higher
1324                         tselem_draw_icon(block, xmax, (float)startx+offsx - 0.5f*ufac, (float)*starty+2.0f*ufac, tselem, te, 1.0f);
1325                         
1326                         offsx+= UI_UNIT_X;
1327                 }
1328                 else
1329                         offsx+= 2*ufac;
1330                 
1331                 if(tselem->type==0 && tselem->id->lib) {
1332                         glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
1333                         if(tselem->id->flag & LIB_INDIRECT)
1334                                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_INDIRECT);
1335                         else
1336                                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_DIRECT);
1337                         glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
1338                         offsx+= UI_UNIT_X;
1339                 }               
1340                 glDisable(GL_BLEND);
1341                 
1342                 /* name */
1343                 if(active==1) UI_ThemeColor(TH_TEXT_HI);
1344                 else if(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
1345                 else UI_ThemeColor(TH_TEXT);
1346                 
1347                 UI_DrawString(startx+offsx, *starty+5*ufac, te->name);
1348                 
1349                 offsx+= (int)(UI_UNIT_X + UI_GetStringWidth(te->name));
1350                 
1351                 /* closed item, we draw the icons, not when it's a scene, or master-server list though */
1352                 if(tselem->flag & TSE_CLOSED) {
1353                         if(te->subtree.first) {
1354                                 if(tselem->type==0 && te->idcode==ID_SCE);
1355                                 else if(tselem->type!=TSE_R_LAYER) { /* this tree element always has same amount of branches, so dont draw */
1356                                         int tempx= startx+offsx;
1357                                         
1358                                         // divider
1359                                         UI_ThemeColorShade(TH_BACK, -40);
1360                                         glRecti(tempx -10, *starty+4, tempx -8, *starty+UI_UNIT_Y-4);
1361                                         
1362                                         glEnable(GL_BLEND);
1363                                         glPixelTransferf(GL_ALPHA_SCALE, 0.5);
1364                                         
1365                                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty+2);
1366                                         
1367                                         glPixelTransferf(GL_ALPHA_SCALE, 1.0);
1368                                         glDisable(GL_BLEND);
1369                                 }
1370                         }
1371                 }
1372         }       
1373         /* store coord and continue, we need coordinates for elements outside view too */
1374         te->xs= (float)startx;
1375         te->ys= (float)*starty;
1376         te->xend= startx+offsx;
1377                 
1378         if((tselem->flag & TSE_CLOSED)==0) {
1379                 *starty-= UI_UNIT_Y;
1380                 
1381                 for(ten= te->subtree.first; ten; ten= ten->next)
1382                         outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx+UI_UNIT_X, starty);
1383         }       
1384         else {
1385                 for(ten= te->subtree.first; ten; ten= ten->next)
1386                         outliner_set_coord_tree_element(soops, te, startx, starty);
1387                 
1388                 *starty-= UI_UNIT_Y;
1389         }
1390 }
1391
1392 static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
1393 {
1394         TreeElement *te;
1395         TreeStoreElem *tselem;
1396         int y1, y2;
1397         
1398         if(lb->first==NULL) return;
1399         
1400         y1=y2= *starty; /* for vertical lines between objects */
1401         for(te=lb->first; te; te= te->next) {
1402                 y2= *starty;
1403                 tselem= TREESTORE(te);
1404                 
1405                 /* horizontal line? */
1406                 if(tselem->type==0 && (te->idcode==ID_OB || te->idcode==ID_SCE))
1407                         glRecti(startx, *starty, startx+UI_UNIT_X, *starty-1);
1408                         
1409                 *starty-= UI_UNIT_Y;
1410                 
1411                 if((tselem->flag & TSE_CLOSED)==0)
1412                         outliner_draw_hierarchy(soops, &te->subtree, startx+UI_UNIT_X, starty);
1413         }
1414         
1415         /* vertical line */
1416         te= lb->last;
1417         if(te->parent || lb->first!=lb->last) {
1418                 tselem= TREESTORE(te);
1419                 if(tselem->type==0 && te->idcode==ID_OB) {
1420                         
1421                         glRecti(startx, y1+UI_UNIT_Y, startx+1, y2);
1422                 }
1423         }
1424 }
1425
1426 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1427 {
1428         TreeElement *te;
1429         TreeStoreElem *tselem;
1430         
1431         for(te= lb->first; te; te= te->next) {
1432                 tselem= TREESTORE(te);
1433                 
1434                 /* selection status */
1435                 if((tselem->flag & TSE_CLOSED)==0)
1436                         if(tselem->type == TSE_RNA_STRUCT)
1437                                 glRecti(0, *starty+1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, *starty+UI_UNIT_Y-1);
1438
1439                 *starty-= UI_UNIT_Y;
1440                 if((tselem->flag & TSE_CLOSED)==0) {
1441                         outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
1442                         if(tselem->type == TSE_RNA_STRUCT)
1443                                 fdrawline(0, (float)*starty+UI_UNIT_Y, ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (float)*starty+UI_UNIT_Y);
1444                 }
1445         }
1446 }
1447
1448 static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1449 {
1450         TreeElement *te;
1451         TreeStoreElem *tselem;
1452         
1453         for(te= lb->first; te; te= te->next) {
1454                 tselem= TREESTORE(te);
1455                 
1456                 /* selection status */
1457                 if(tselem->flag & TSE_SELECTED) {
1458                         glRecti(0, *starty+1, (int)ar->v2d.cur.xmax, *starty+UI_UNIT_Y-1);
1459                 }
1460                 *starty-= UI_UNIT_Y;
1461                 if((tselem->flag & TSE_CLOSED)==0) outliner_draw_selection(ar, soops, &te->subtree, starty);
1462         }
1463 }
1464
1465
1466 static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops)
1467 {
1468         TreeElement *te;
1469         int starty, startx;
1470         float col[4];
1471                 
1472         glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
1473         
1474         if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1475                 /* struct marks */
1476                 UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1477                 //UI_ThemeColorShade(TH_BACK, -20);
1478                 starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1479                 outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
1480         }
1481         
1482         /* always draw selection fill before hierarchy */
1483         UI_GetThemeColor3fv(TH_BACK, col);
1484         glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
1485         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1486         outliner_draw_selection(ar, soops, &soops->tree, &starty);
1487         
1488         // grey hierarchy lines
1489         UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
1490         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y/2-OL_Y_OFFSET;
1491         startx= 6;
1492         outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
1493         
1494         // items themselves
1495         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1496         startx= 0;
1497         for(te= soops->tree.first; te; te= te->next) {
1498                 outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty);
1499         }
1500 }
1501
1502
1503 static void outliner_back(ARegion *ar)
1504 {
1505         int ystart;
1506         
1507         UI_ThemeColorShade(TH_BACK, 6);
1508         ystart= (int)ar->v2d.tot.ymax;
1509         ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
1510         
1511         while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
1512                 glRecti(0, ystart, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, ystart+UI_UNIT_Y);
1513                 ystart-= 2*UI_UNIT_Y;
1514         }
1515 }
1516
1517 static void outliner_draw_restrictcols(ARegion *ar)
1518 {
1519         int ystart;
1520         
1521         /* background underneath */
1522         UI_ThemeColor(TH_BACK);
1523         glRecti((int)ar->v2d.cur.xmax-OL_TOGW, (int)ar->v2d.cur.ymin-V2D_SCROLL_HEIGHT-1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (int)ar->v2d.cur.ymax);
1524         
1525         UI_ThemeColorShade(TH_BACK, 6);
1526         ystart= (int)ar->v2d.tot.ymax;
1527         ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
1528         
1529         while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
1530                 glRecti((int)ar->v2d.cur.xmax-OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart+UI_UNIT_Y);
1531                 ystart-= 2*UI_UNIT_Y;
1532         }
1533         
1534         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1535
1536         /* view */
1537         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
1538                 ar->v2d.cur.ymax,
1539                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
1540                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1541
1542         /* render */
1543         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
1544                 ar->v2d.cur.ymax,
1545                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
1546                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1547
1548         /* render */
1549         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
1550                 ar->v2d.cur.ymax,
1551                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
1552                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1553 }
1554
1555 /* ****************************************************** */
1556 /* Main Entrypoint - Draw contents of Outliner editor */
1557  
1558 void draw_outliner(const bContext *C)
1559 {
1560         Main *mainvar= CTX_data_main(C);
1561         Scene *scene= CTX_data_scene(C);
1562         ARegion *ar= CTX_wm_region(C);
1563         View2D *v2d= &ar->v2d;
1564         SpaceOops *soops= CTX_wm_space_outliner(C);
1565         uiBlock *block;
1566         int sizey= 0, sizex= 0, sizex_rna= 0;
1567         
1568         outliner_build_tree(mainvar, scene, soops); // always 
1569         
1570         /* get extents of data */
1571         outliner_height(soops, &soops->tree, &sizey);
1572
1573         if (ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP)) {
1574                 /* RNA has two columns:
1575                  *      - column 1 is (max_width + OL_RNA_COL_SPACEX) or
1576                  *                               (OL_RNA_COL_X), whichever is wider...
1577                  *      - column 2 is fixed at OL_RNA_COL_SIZEX
1578                  *
1579                  *  (*) XXX max width for now is a fixed factor of UI_UNIT_X*(max_indention+100)
1580                  */
1581                  
1582                 /* get actual width of column 1 */
1583                 outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
1584                 sizex_rna= MAX2(OL_RNA_COLX, sizex_rna+OL_RNA_COL_SPACEX);
1585                 
1586                 /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
1587                 if (soops->outlinevis == SO_KEYMAP) 
1588                         sizex= sizex_rna + OL_RNA_COL_SIZEX*3 + 50; // XXX this is only really a quick hack to make this wide enough...
1589                 else
1590                         sizex= sizex_rna + OL_RNA_COL_SIZEX + 50;
1591         }
1592         else {
1593                 /* width must take into account restriction columns (if visible) so that entries will still be visible */
1594                 //outliner_width(soops, &soops->tree, &sizex);
1595                 outliner_rna_width(soops, &soops->tree, &sizex, 0); // XXX should use outliner_width instead when te->xend will be set correctly...
1596                 
1597                 /* constant offset for restriction columns */
1598                 // XXX this isn't that great yet...
1599                 if ((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
1600                         sizex += OL_TOGW*3;
1601         }
1602         
1603         /* tweak to display last line (when list bigger than window) */
1604         sizey += V2D_SCROLL_HEIGHT;
1605         
1606         /* adds vertical offset */
1607         sizey += OL_Y_OFFSET;
1608
1609         /* update size of tot-rect (extents of data/viewable area) */
1610         UI_view2d_totRect_set(v2d, sizex, sizey);
1611
1612         /* force display to pixel coords */
1613         v2d->flag |= (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
1614         /* set matrix for 2d-view controls */
1615         UI_view2d_view_ortho(v2d);
1616
1617         /* draw outliner stuff (background, hierachy lines and names) */
1618         outliner_back(ar);
1619         block= uiBeginBlock(C, ar, "outliner buttons", UI_EMBOSS);
1620         outliner_draw_tree((bContext *)C, block, scene, ar, soops);
1621         
1622         if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1623                 /* draw rna buttons */
1624                 outliner_draw_rnacols(ar, sizex_rna);
1625                 outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
1626         }
1627         else if(soops->outlinevis == SO_KEYMAP) {
1628                 outliner_draw_keymapbuts(block, ar, soops, &soops->tree);
1629         }
1630         else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
1631                 /* draw restriction columns */
1632                 outliner_draw_restrictcols(ar);
1633                 outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
1634         }
1635
1636         /* draw edit buttons if nessecery */
1637         outliner_buttons(C, block, ar, soops, &soops->tree);    
1638
1639         uiEndBlock(C, block);
1640         uiDrawBlock(C, block);
1641         
1642         /* clear flag that allows quick redraws */
1643         soops->storeflag &= ~SO_TREESTORE_REDRAW;
1644