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