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