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