svn merge -r39930:39947 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->flag & TSE_CLOSED)==0) 
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->flag & TSE_CLOSED) {
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->flag & TSE_CLOSED)==0)
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->flag & TSE_CLOSED)==0) 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->flag & TSE_CLOSED)==0))
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->flag & TSE_CLOSED)==0) 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->flag & TSE_CLOSED)==0) 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->flag & TSE_CLOSED)==0) 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                                         case eModifierType_WeightVGEdit:
1012                                         case eModifierType_WeightVGMix:
1013                                         case eModifierType_WeightVGProximity:
1014                                                 UI_icon_draw(x, y, ICON_MOD_WEIGHTVG); break;
1015                                         default:
1016                                                 UI_icon_draw(x, y, ICON_DOT); break;
1017                                 }
1018                                 break;
1019                         }
1020                         case TSE_SCRIPT_BASE:
1021                                 UI_icon_draw(x, y, ICON_TEXT); break;
1022                         case TSE_POSE_BASE:
1023                                 UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
1024                         case TSE_POSE_CHANNEL:
1025                                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
1026                         case TSE_PROXY:
1027                                 UI_icon_draw(x, y, ICON_GHOST); break;
1028                         case TSE_R_LAYER_BASE:
1029                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1030                         case TSE_R_LAYER:
1031                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1032                         case TSE_LINKED_LAMP:
1033                                 UI_icon_draw(x, y, ICON_LAMP_DATA); break;
1034                         case TSE_LINKED_MAT:
1035                                 UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
1036                         case TSE_POSEGRP_BASE:
1037                                 UI_icon_draw(x, y, ICON_VERTEXSEL); break;
1038                         case TSE_SEQUENCE:
1039                                 if(te->idcode==SEQ_MOVIE)
1040                                         UI_icon_draw(x, y, ICON_SEQUENCE);
1041                                 else if(te->idcode==SEQ_META)
1042                                         UI_icon_draw(x, y, ICON_DOT);
1043                                 else if(te->idcode==SEQ_SCENE)
1044                                         UI_icon_draw(x, y, ICON_SCENE);
1045                                 else if(te->idcode==SEQ_SOUND)
1046                                         UI_icon_draw(x, y, ICON_SOUND);
1047                                 else if(te->idcode==SEQ_IMAGE)
1048                                         UI_icon_draw(x, y, ICON_IMAGE_COL);
1049                                 else
1050                                         UI_icon_draw(x, y, ICON_PARTICLES);
1051                                 break;
1052                         case TSE_SEQ_STRIP:
1053                                 UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
1054                                 break;
1055                         case TSE_SEQUENCE_DUP:
1056                                 UI_icon_draw(x, y, ICON_OBJECT_DATA);
1057                                 break;
1058                         case TSE_RNA_STRUCT:
1059                                 if(RNA_struct_is_ID(te->rnaptr.type)) {
1060                                         arg.id= (ID *)te->rnaptr.data;
1061                                         tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
1062                                 }
1063                                 else
1064                                         UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
1065                                 break;
1066                         default:
1067                                 UI_icon_draw(x, y, ICON_DOT); break;
1068                 }
1069         }
1070         else if (GS(tselem->id->name) == ID_OB) {
1071                 Object *ob= (Object *)tselem->id;
1072                 switch (ob->type) {
1073                         case OB_LAMP:
1074                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
1075                         case OB_MESH: 
1076                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
1077                         case OB_CAMERA: 
1078                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
1079                         case OB_CURVE: 
1080                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
1081                         case OB_MBALL: 
1082                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
1083                         case OB_LATTICE: 
1084                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
1085                         case OB_ARMATURE: 
1086                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
1087                         case OB_FONT: 
1088                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
1089                         case OB_SURF: 
1090                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
1091                         case OB_SPEAKER:
1092                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
1093                         case OB_EMPTY: 
1094                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY); break;
1095                 
1096                 }
1097         }
1098         else {
1099                 switch( GS(tselem->id->name)) {
1100                         case ID_SCE:
1101                                 tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
1102                         case ID_ME:
1103                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
1104                         case ID_CU:
1105                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
1106                         case ID_MB:
1107                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
1108                         case ID_LT:
1109                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
1110                         case ID_LA:
1111                         {
1112                                 Lamp *la= (Lamp *)tselem->id;
1113                                 
1114                                 switch(la->type) {
1115                                         case LA_LOCAL:
1116                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
1117                                         case LA_SUN:
1118                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
1119                                         case LA_SPOT:
1120                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
1121                                         case LA_HEMI:
1122                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
1123                                         case LA_AREA:
1124                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
1125                                         default:
1126                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
1127                                 }
1128                                 break;
1129                         }
1130                         case ID_MA:
1131                                 tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
1132                         case ID_TE:
1133                                 tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
1134                         case ID_IM:
1135                                 tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
1136                         case ID_SPK:
1137                         case ID_SO:
1138                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_SPEAKER); break;
1139                         case ID_AR:
1140                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
1141                         case ID_CA:
1142                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
1143                         case ID_KE:
1144                                 tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
1145                         case ID_WO:
1146                                 tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
1147                         case ID_AC:
1148                                 tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
1149                         case ID_NLA:
1150                                 tselem_draw_icon_uibut(&arg, ICON_NLA); break;
1151                         case ID_TXT:
1152                                 tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
1153                         case ID_GR:
1154                                 tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
1155                         case ID_LI:
1156                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT); break;
1157                 }
1158         }
1159 }
1160
1161 static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level, int xmax, int *offsx, int ys)
1162 {
1163         TreeElement *te;
1164         TreeStoreElem *tselem;
1165         int active;
1166
1167         for(te= lb->first; te; te= te->next) {
1168                 
1169                 /* exit drawing early */
1170                 if((*offsx) - UI_UNIT_X > xmax)
1171                         break;
1172
1173                 tselem= TREESTORE(te);
1174                 
1175                 /* object hierarchy always, further constrained on level */
1176                 if(level<1 || (tselem->type==0 && te->idcode==ID_OB)) {
1177
1178                         /* active blocks get white circle */
1179                         if(tselem->type==0) {
1180                                 if(te->idcode==ID_OB) active= (OBACT==(Object *)tselem->id);
1181                                 else if(scene->obedit && scene->obedit->data==tselem->id) active= 1;    // XXX use context?
1182                                 else active= tree_element_active(C, scene, soops, te, 0);
1183                         }
1184                         else active= tree_element_type_active(NULL, scene, soops, te, tselem, 0);
1185                         
1186                         if(active) {
1187                                 float ufac= UI_UNIT_X/20.0f;
1188
1189                                 uiSetRoundBox(15);
1190                                 glColor4ub(255, 255, 255, 100);
1191                                 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);
1192                                 glEnable(GL_BLEND); /* roundbox disables */
1193                         }
1194                         
1195                         tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
1196                         te->xs= (float)*offsx;
1197                         te->ys= (float)ys;
1198                         te->xend= (short)*offsx+UI_UNIT_X;
1199                         te->flag |= TE_ICONROW; // for click
1200                         
1201                         (*offsx) += UI_UNIT_X;
1202                 }
1203                 
1204                 /* this tree element always has same amount of branches, so dont draw */
1205                 if(tselem->type!=TSE_R_LAYER)
1206                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level+1, xmax, offsx, ys);
1207         }
1208         
1209 }
1210
1211 /* closed tree element */
1212 static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
1213 {
1214         TreeElement *ten;
1215         
1216         /* store coord and continue, we need coordinates for elements outside view too */
1217         te->xs= (float)startx;
1218         te->ys= (float)(*starty);
1219         
1220         for(ten= te->subtree.first; ten; ten= ten->next) {
1221                 outliner_set_coord_tree_element(soops, ten, startx+UI_UNIT_X, starty);
1222         }       
1223 }
1224
1225
1226 static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
1227 {
1228         TreeElement *ten;
1229         TreeStoreElem *tselem;
1230         float ufac= UI_UNIT_X/20.0f;
1231         int offsx= 0, active=0; // active=1 active obj, else active data
1232         
1233         tselem= TREESTORE(te);
1234
1235         if(*starty+2*UI_UNIT_Y >= ar->v2d.cur.ymin && *starty<= ar->v2d.cur.ymax) {
1236                 int xmax= ar->v2d.cur.xmax;
1237                 
1238                 /* icons can be ui buts, we dont want it to overlap with restrict */
1239                 if((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
1240                         xmax-= OL_TOGW+UI_UNIT_X;
1241                 
1242                 glEnable(GL_BLEND);
1243
1244                 /* colors for active/selected data */
1245                 if(tselem->type==0) {
1246                         if(te->idcode==ID_SCE) {
1247                                 if(tselem->id == (ID *)scene) {
1248                                         glColor4ub(255, 255, 255, 100);
1249                                         active= 2;
1250                                 }
1251                         }
1252                         else if(te->idcode==ID_GR) {
1253                                 Group *gr = (Group *)tselem->id;
1254                                 
1255                                 if(group_select_flag(gr)) {
1256                                         char col[4];
1257                                         UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1258                                         col[3]= 100;
1259                                         glColor4ubv((GLubyte *)col);
1260                                         
1261                                         active= 2;
1262                                 }
1263                         }
1264                         else if(te->idcode==ID_OB) {
1265                                 Object *ob= (Object *)tselem->id;
1266                                 
1267                                 if(ob==OBACT || (ob->flag & SELECT)) {
1268                                         char col[4]= {0, 0, 0, 0};
1269                                         
1270                                         /* outliner active ob: always white text, circle color now similar to view3d */
1271                                         
1272                                         active= 2; /* means it draws a color circle */
1273                                         if(ob==OBACT) {
1274                                                 if(ob->flag & SELECT) {
1275                                                         UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
1276                                                         col[3]= 100;
1277                                                 }
1278                                                 
1279                                                 active= 1; /* means it draws white text */
1280                                         }
1281                                         else if(ob->flag & SELECT) {
1282                                                 UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1283                                                 col[3]= 100;
1284                                         }
1285                                         
1286                                         glColor4ubv((GLubyte *)col);
1287                                 }
1288                         
1289                         }
1290                         else if(scene->obedit && scene->obedit->data==tselem->id) {
1291                                 glColor4ub(255, 255, 255, 100);
1292                                 active= 2;
1293                         }
1294                         else {
1295                                 if(tree_element_active(C, scene, soops, te, 0)) {
1296                                         glColor4ub(220, 220, 255, 100);
1297                                         active= 2;
1298                                 }
1299                         }
1300                 }
1301                 else {
1302                         if( tree_element_type_active(NULL, scene, soops, te, tselem, 0) ) active= 2;
1303                         glColor4ub(220, 220, 255, 100);
1304                 }
1305                 
1306                 /* active circle */
1307                 if(active) {
1308                         uiSetRoundBox(15);
1309                         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);
1310                         glEnable(GL_BLEND);     /* roundbox disables it */
1311                         
1312                         te->flag |= TE_ACTIVE; // for lookup in display hierarchies
1313                 }
1314                 
1315                 /* open/close icon, only when sublevels, except for scene */
1316                 if(te->subtree.first || (tselem->type==0 && te->idcode==ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
1317                         int icon_x;
1318                         if(tselem->type==0 && ELEM(te->idcode, ID_OB, ID_SCE))
1319                                 icon_x = startx;
1320                         else
1321                                 icon_x = startx+5*ufac;
1322                         
1323                                 // icons a bit higher
1324                         if(tselem->flag & TSE_CLOSED) 
1325                                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_RIGHT);
1326                         else
1327                                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_DOWN);
1328                 }
1329                 offsx+= UI_UNIT_X;
1330                 
1331                 /* datatype icon */
1332                 
1333                 if(!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
1334                         // icons a bit higher
1335                         tselem_draw_icon(block, xmax, (float)startx+offsx - 0.5f*ufac, (float)*starty+2.0f*ufac, tselem, te, 1.0f);
1336                         
1337                         offsx+= UI_UNIT_X;
1338                 }
1339                 else
1340                         offsx+= 2*ufac;
1341                 
1342                 if(tselem->type==0 && tselem->id->lib) {
1343                         glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
1344                         if(tselem->id->flag & LIB_INDIRECT)
1345                                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_INDIRECT);
1346                         else
1347                                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_DIRECT);
1348                         glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
1349                         offsx+= UI_UNIT_X;
1350                 }               
1351                 glDisable(GL_BLEND);
1352                 
1353                 /* name */
1354                 if(active==1) UI_ThemeColor(TH_TEXT_HI);
1355                 else if(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
1356                 else UI_ThemeColor(TH_TEXT);
1357                 
1358                 UI_DrawString(startx+offsx, *starty+5*ufac, te->name);
1359                 
1360                 offsx+= (int)(UI_UNIT_X + UI_GetStringWidth(te->name));
1361                 
1362                 /* closed item, we draw the icons, not when it's a scene, or master-server list though */
1363                 if(tselem->flag & TSE_CLOSED) {
1364                         if(te->subtree.first) {
1365                                 if(tselem->type==0 && te->idcode==ID_SCE);
1366                                 else if(tselem->type!=TSE_R_LAYER) { /* this tree element always has same amount of branches, so dont draw */
1367                                         int tempx= startx+offsx;
1368                                         
1369                                         // divider
1370                                         UI_ThemeColorShade(TH_BACK, -40);
1371                                         glRecti(tempx -10, *starty+4, tempx -8, *starty+UI_UNIT_Y-4);
1372                                         
1373                                         glEnable(GL_BLEND);
1374                                         glPixelTransferf(GL_ALPHA_SCALE, 0.5);
1375                                         
1376                                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty+2);
1377                                         
1378                                         glPixelTransferf(GL_ALPHA_SCALE, 1.0);
1379                                         glDisable(GL_BLEND);
1380                                 }
1381                         }
1382                 }
1383         }       
1384         /* store coord and continue, we need coordinates for elements outside view too */
1385         te->xs= (float)startx;
1386         te->ys= (float)*starty;
1387         te->xend= startx+offsx;
1388                 
1389         if((tselem->flag & TSE_CLOSED)==0) {
1390                 *starty-= UI_UNIT_Y;
1391                 
1392                 for(ten= te->subtree.first; ten; ten= ten->next)
1393                         outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx+UI_UNIT_X, starty);
1394         }       
1395         else {
1396                 for(ten= te->subtree.first; ten; ten= ten->next)
1397                         outliner_set_coord_tree_element(soops, te, startx, starty);
1398                 
1399                 *starty-= UI_UNIT_Y;
1400         }
1401 }
1402
1403 static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
1404 {
1405         TreeElement *te;
1406         TreeStoreElem *tselem;
1407         int y1, y2;
1408         
1409         if(lb->first==NULL) return;
1410         
1411         y1=y2= *starty; /* for vertical lines between objects */
1412         for(te=lb->first; te; te= te->next) {
1413                 y2= *starty;
1414                 tselem= TREESTORE(te);
1415                 
1416                 /* horizontal line? */
1417                 if(tselem->type==0 && (te->idcode==ID_OB || te->idcode==ID_SCE))
1418                         glRecti(startx, *starty, startx+UI_UNIT_X, *starty-1);
1419                         
1420                 *starty-= UI_UNIT_Y;
1421                 
1422                 if((tselem->flag & TSE_CLOSED)==0)
1423                         outliner_draw_hierarchy(soops, &te->subtree, startx+UI_UNIT_X, starty);
1424         }
1425         
1426         /* vertical line */
1427         te= lb->last;
1428         if(te->parent || lb->first!=lb->last) {
1429                 tselem= TREESTORE(te);
1430                 if(tselem->type==0 && te->idcode==ID_OB) {
1431                         
1432                         glRecti(startx, y1+UI_UNIT_Y, startx+1, y2);
1433                 }
1434         }
1435 }
1436
1437 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1438 {
1439         TreeElement *te;
1440         TreeStoreElem *tselem;
1441         
1442         for(te= lb->first; te; te= te->next) {
1443                 tselem= TREESTORE(te);
1444                 
1445                 /* selection status */
1446                 if((tselem->flag & TSE_CLOSED)==0)
1447                         if(tselem->type == TSE_RNA_STRUCT)
1448                                 glRecti(0, *starty+1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, *starty+UI_UNIT_Y-1);
1449
1450                 *starty-= UI_UNIT_Y;
1451                 if((tselem->flag & TSE_CLOSED)==0) {
1452                         outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
1453                         if(tselem->type == TSE_RNA_STRUCT)
1454                                 fdrawline(0, (float)*starty+UI_UNIT_Y, ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (float)*starty+UI_UNIT_Y);
1455                 }
1456         }
1457 }
1458
1459 static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1460 {
1461         TreeElement *te;
1462         TreeStoreElem *tselem;
1463         
1464         for(te= lb->first; te; te= te->next) {
1465                 tselem= TREESTORE(te);
1466                 
1467                 /* selection status */
1468                 if(tselem->flag & TSE_SELECTED) {
1469                         glRecti(0, *starty+1, (int)ar->v2d.cur.xmax, *starty+UI_UNIT_Y-1);
1470                 }
1471                 *starty-= UI_UNIT_Y;
1472                 if((tselem->flag & TSE_CLOSED)==0) outliner_draw_selection(ar, soops, &te->subtree, starty);
1473         }
1474 }
1475
1476
1477 static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops)
1478 {
1479         TreeElement *te;
1480         int starty, startx;
1481         float col[4];
1482                 
1483         glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
1484         
1485         if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1486                 /* struct marks */
1487                 UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1488                 //UI_ThemeColorShade(TH_BACK, -20);
1489                 starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1490                 outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
1491         }
1492         
1493         /* always draw selection fill before hierarchy */
1494         UI_GetThemeColor3fv(TH_BACK, col);
1495         glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
1496         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1497         outliner_draw_selection(ar, soops, &soops->tree, &starty);
1498         
1499         // grey hierarchy lines
1500         UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
1501         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y/2-OL_Y_OFFSET;
1502         startx= 6;
1503         outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
1504         
1505         // items themselves
1506         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
1507         startx= 0;
1508         for(te= soops->tree.first; te; te= te->next) {
1509                 outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty);
1510         }
1511 }
1512
1513
1514 static void outliner_back(ARegion *ar)
1515 {
1516         int ystart;
1517         
1518         UI_ThemeColorShade(TH_BACK, 6);
1519         ystart= (int)ar->v2d.tot.ymax;
1520         ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
1521         
1522         while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
1523                 glRecti(0, ystart, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, ystart+UI_UNIT_Y);
1524                 ystart-= 2*UI_UNIT_Y;
1525         }
1526 }
1527
1528 static void outliner_draw_restrictcols(ARegion *ar)
1529 {
1530         int ystart;
1531         
1532         /* background underneath */
1533         UI_ThemeColor(TH_BACK);
1534         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);
1535         
1536         UI_ThemeColorShade(TH_BACK, 6);
1537         ystart= (int)ar->v2d.tot.ymax;
1538         ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
1539         
1540         while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
1541                 glRecti((int)ar->v2d.cur.xmax-OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart+UI_UNIT_Y);
1542                 ystart-= 2*UI_UNIT_Y;
1543         }
1544         
1545         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1546
1547         /* view */
1548         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
1549                 ar->v2d.cur.ymax,
1550                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
1551                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1552
1553         /* render */
1554         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
1555                 ar->v2d.cur.ymax,
1556                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
1557                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1558
1559         /* render */
1560         fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
1561                 ar->v2d.cur.ymax,
1562                 ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
1563                 ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1564 }
1565
1566 /* ****************************************************** */
1567 /* Main Entrypoint - Draw contents of Outliner editor */
1568  
1569 void draw_outliner(const bContext *C)
1570 {
1571         Main *mainvar= CTX_data_main(C);
1572         Scene *scene= CTX_data_scene(C);
1573         ARegion *ar= CTX_wm_region(C);
1574         View2D *v2d= &ar->v2d;
1575         SpaceOops *soops= CTX_wm_space_outliner(C);
1576         uiBlock *block;
1577         int sizey= 0, sizex= 0, sizex_rna= 0;
1578         
1579         outliner_build_tree(mainvar, scene, soops); // always 
1580         
1581         /* get extents of data */
1582         outliner_height(soops, &soops->tree, &sizey);
1583
1584         if (ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP)) {
1585                 /* RNA has two columns:
1586                  *      - column 1 is (max_width + OL_RNA_COL_SPACEX) or
1587                  *                               (OL_RNA_COL_X), whichever is wider...
1588                  *      - column 2 is fixed at OL_RNA_COL_SIZEX
1589                  *
1590                  *  (*) XXX max width for now is a fixed factor of UI_UNIT_X*(max_indention+100)
1591                  */
1592                  
1593                 /* get actual width of column 1 */
1594                 outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
1595                 sizex_rna= MAX2(OL_RNA_COLX, sizex_rna+OL_RNA_COL_SPACEX);
1596                 
1597                 /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
1598                 if (soops->outlinevis == SO_KEYMAP) 
1599                         sizex= sizex_rna + OL_RNA_COL_SIZEX*3 + 50; // XXX this is only really a quick hack to make this wide enough...
1600                 else
1601                         sizex= sizex_rna + OL_RNA_COL_SIZEX + 50;
1602         }
1603         else {
1604                 /* width must take into account restriction columns (if visible) so that entries will still be visible */
1605                 //outliner_width(soops, &soops->tree, &sizex);
1606                 outliner_rna_width(soops, &soops->tree, &sizex, 0); // XXX should use outliner_width instead when te->xend will be set correctly...
1607                 
1608                 /* constant offset for restriction columns */
1609                 // XXX this isn't that great yet...
1610                 if ((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
1611                         sizex += OL_TOGW*3;
1612         }
1613         
1614         /* tweak to display last line (when list bigger than window) */
1615         sizey += V2D_SCROLL_HEIGHT;
1616         
1617         /* adds vertical offset */
1618         sizey += OL_Y_OFFSET;
1619
1620         /* update size of tot-rect (extents of data/viewable area) */
1621         UI_view2d_totRect_set(v2d, sizex, sizey);
1622
1623         /* force display to pixel coords */
1624         v2d->flag |= (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
1625         /* set matrix for 2d-view controls */
1626         UI_view2d_view_ortho(v2d);
1627
1628         /* draw outliner stuff (background, hierachy lines and names) */
1629         outliner_back(ar);
1630         block= uiBeginBlock(C, ar, "outliner buttons", UI_EMBOSS);
1631         outliner_draw_tree((bContext *)C, block, scene, ar, soops);
1632         
1633         if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1634                 /* draw rna buttons */
1635                 outliner_draw_rnacols(ar, sizex_rna);
1636                 outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
1637         }
1638         else if(soops->outlinevis == SO_KEYMAP) {
1639                 outliner_draw_keymapbuts(block, ar, soops, &soops->tree);
1640         }
1641         else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
1642                 /* draw restriction columns */
1643                 outliner_draw_restrictcols(ar);
1644                 outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
1645         }
1646
1647         /* draw edit buttons if nessecery */
1648         outliner_buttons(C, block, ar, soops, &soops->tree);    
1649
1650         uiEndBlock(C, block);
1651         uiDrawBlock(C, block);
1652         
1653         /* clear flag that allows quick redraws */
1654         soops->storeflag &= ~SO_TREESTORE_REDRAW;
1655