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