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