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